diff --git "a/forward-construction.jsonl" "b/forward-construction.jsonl" new file mode 100644--- /dev/null +++ "b/forward-construction.jsonl" @@ -0,0 +1,80 @@ +{"id": "v10-duchi09a", "source": "Research-level", "targets": [{"label": "Theorem 6", "decls": ["theorem6"], "statement": "Theorem 6 Suppose that $\\| \\pmb{w}_{t}- \\pmb{w}^{\\star}\\| \\leq D$ holds at every iteration, and that G is an upper bound on the norms of the subgradient sets $\\partial f_{t}$ and $\\partial r$. Fix an arbitrary scalar $c > 0$. Then FoBoS run with step sizes $\\eta_{t}= c / \\sqrt{t}$ has a regret bound of the form\n\n$$\nR_{f+r}(T)\\leq 2GD+\\left({\\frac{D^{2}}{2c}}+7G^{2}c\\right)\\sqrt{T}.\n$$", "context_ids": ["v10-duchi09a:ctx1", "v10-duchi09a:ctx2", "v10-duchi09a:ctx3", "v10-duchi09a:ctx4", "v10-duchi09a:ctx5", "v10-duchi09a:ctx6", "v10-duchi09a:ctx7"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}, {"label": "Theorem 8", "decls": ["theorem8"], "statement": "Theorem 8 As in Theorem 6, suppose that $\\| \\pmb{w}_{t}- \\pmb{w}^{\\star}\\| \\leq D$ and that G bounds $\\partial f_{t}$ and $\\partial r$ from above. In addition, suppose that for every t the function $f_{t}+ r$ is H-strongly convex on the region $\\| \\pmb{w}- \\pmb{w}^{\\star}\\| \\leq D$. Then, with the step sizes $\\eta_{t}=1/(Ht)$, FoBoS has regret\n\n$$\nR_{f+r}(T)\\leq 2GD+HD^{2}+\\frac{7G^{2}}{2H}(1+\\log T).\n$$", "context_ids": ["v10-duchi09a:ctx1", "v10-duchi09a:ctx2", "v10-duchi09a:ctx3", "v10-duchi09a:ctx4", "v10-duchi09a:ctx5", "v10-duchi09a:ctx6", "v10-duchi09a:ctx7", "v10-duchi09a:ctx8", "v10-duchi09a:ctx14"], "sibling_refs": ["Theorem 6"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}, {"label": "Proposition 11", "decls": ["proposition11"], "statement": "Proposition 11 For $t=1,\\ldots,T$, solve one after another the T self-similar optimization problems\n\n$$\n\\mathcal{P}.1:~{\\pmb w}_{t}=\\operatorname*{argmin}_{{\\pmb w}}\\frac{1}{2}\\|{\\pmb w}-{\\pmb w}_{t-1}\\|^{2}+\\lambda_{t}\\|{\\pmb w}\\|_{q}\\enspace .\\tag{28}\n$$\n\nand let $\\pmb{w}_{T}$ be the vector obtained at the end. Denote by $\\pmb{w}^{\\star}$ the optimal solution of the problem\n\n$$\n\\mathcal{P}. 2:\\pmb{w}^{\\star}=\\underset{\\pmb{w}}{\\mathrm{argmin}}\\frac{1}{2}\\|\\pmb{w}-\\pmb{w}_{0}\\|^{2}+\\left(\\sum_{t=1}^{T}\\lambda_{t}\\right)\\|\\pmb{w}\\|_{q}.\n$$\n\nThen, for $q\\in\\{1,2,\\infty\\}$, the two vectors $\\pmb{w}_{T}$ and $\\pmb{w}^{\\star}$ coincide.", "context_ids": ["v10-duchi09a:ctx1", "v10-duchi09a:ctx2", "v10-duchi09a:ctx3", "v10-duchi09a:ctx9", "v10-duchi09a:ctx10", "v10-duchi09a:ctx11", "v10-duchi09a:ctx12", "v10-duchi09a:ctx13"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}], "nl_proof": "### Proof of Theorem 6\n\nProof of Theorem 6 When $\\| \\partial f \\|$ and $\\| \\partial r \\|$ are bounded by G, Lemma 1 gives at once\n\n$$\nf_{t}(\\boldsymbol{w}_{t})-f_{t}(\\boldsymbol{w}^{\\star})+r(\\boldsymbol{w}_{t+1})-r(\\boldsymbol{w}^{\\star})\\leq\\frac{1}{2\\eta_{t}}\\left(\\|\\boldsymbol{w}_{t}-\\boldsymbol{w}^{\\star}\\|^{2}-\\|\\boldsymbol{w}_{t+1}-\\boldsymbol{w}^{\\star}\\|^{2}\\right)+\\frac{7}{2}G^{2}\\eta_{t}.\\tag{36}\n$$\n\nApplying Eq. (36), we find\n\n$$\n\\begin{array}{r c l}{R_{f+r}(T)}&{=}&{\\displaystyle\\sum_{t=1}^{T}\\left(f_{t}(w_{t})-f_{t}(w^{\\star})+r(w_{t})-r(w^{\\star})\\right)+r(w_{T+1})-r(w^{\\star})-r(w_{1})+r(w^{\\star})}\\\\ &{\\le}&{\\displaystyle GD+\\displaystyle\\sum_{t=1}^{T}\\frac{1}{2\\eta_{t}}\\left(\\|w_{t}-w^{\\star}\\|^{2}-\\|w_{t+1}-w^{\\star}\\|^{2}\\right)+\\displaystyle\\frac{7G^{2}}{2}\\displaystyle\\sum_{t=1}^{T}\\eta_{t}}\\end{array}\n$$\n\nbecause $r(\\pmb{w})\\leq r(\\mathbf{0})+G\\|\\pmb{w}\\|\\leq GD$. Rearranging this bound gives\n\n$$\n\\begin{array}{r c l}{{R_{f+r}(T)}}&{{\\le}}&{{\\displaystyle GD+\\frac{1}{2\\eta_{1}}\\|w_{1}-w^{\\star}\\|^{2}+\\frac{1}{2}\\sum_{t=2}^{T}\\|w_{t}-w^{\\star}\\|^{2}\\left(\\frac{1}{\\eta_{t}}-\\frac{1}{\\eta_{t-1}}\\right)+\\frac{7G^{2}}{2}\\sum_{t=1}^{T}\\eta_{t}}}\\\\ {{}}&{{\\le}}&{{\\displaystyle GD+\\frac{D^{2}}{2\\eta_{1}}+\\frac{D^{2}}{2}\\sum_{t=2}^{T}\\left(\\frac{1}{\\eta_{t}}-\\frac{1}{\\eta_{t-1}}\\right)+\\frac{7G^{2}}{2}\\sum_{t=1}^{T}\\eta_{t}~,}}\\end{array}\n$$\n\nwhere the final inequality once more uses the bound on the distance from each ${\\pmb w}_{t}$ to $\\pmb{w}^{\\star}$. Finally, the sum $\\frac{1}{\\eta_{1}}+\\sum_{t=2}^{T}\\big(\\frac{1}{\\eta_{t}}-\\frac{1}{\\eta_{t-1}}\\big)$ telescopes, which yields\n\n$$\nR_{f+r}(T)\\leq GD+{\\frac{D^{2}}{2\\eta_{T}}}+{\\frac{7G^{2}}{2}}\\sum_{t=1}^{T}\\eta_{t}.\n$$\n\nThe proof is finished by taking $\\eta_{t}= c / \\sqrt{t}$ and noting that $\\sum_{t = 1}^{T}\\eta_{t}\\leq 2 c \\sqrt{T}$.\n\n### Proof of Theorem 8\n\nProof of Theorem 8 The argument is a direct extension of Theorem 1 of Hazan et al. (2006) together with our proof of Theorem 6. Adding up Eq. (17) over $t = 1$ to T, we get\n\n$$\n\\begin{array}{r c l}{{R_{f+r}(T)}}&{{\\le}}&{{\\displaystyle\\sum_{t=1}^{T}\\left(\\left\\langle g_{t}^{f}+g_{t}^{r},w_{t}-w^{\\star}\\right\\rangle-\\displaystyle\\frac{H}{2}\\|w_{t}-w^{\\star}\\|^{2}\\right)}}\\\\ {{}}&{{\\le}}&{{\\displaystyle 2GD+\\displaystyle\\frac{1}{2}\\sum_{t=1}^{T-1}\\left(\\displaystyle\\frac{1}{\\eta_{t}}\\|w_{t}-w^{\\star}\\|^{2}-\\displaystyle\\frac{1}{\\eta_{t}}\\|w_{t+1}-w^{\\star}\\|^{2}-H\\|w_{t}-w^{\\star}\\|^{2}\\right)+\\displaystyle\\frac{7G^{2}}{2}\\sum_{t=1}^{T-1}\\displaystyle\\eta_{t}}}\\\\ {{}}&{{\\le}}&{{\\displaystyle 2GD+\\displaystyle\\frac{1}{2}\\sum_{t=2}^{T-1}\\|w_{t}-w^{\\star}\\|^{2}\\left(\\displaystyle\\frac{1}{\\eta_{t}}-\\displaystyle\\frac{1}{\\eta_{t-1}}-H\\right)+\\displaystyle\\frac{1}{\\eta_{1}}\\|w_{1}-w^{\\star}\\|^{2}+\\displaystyle\\frac{7G^{2}}{2}\\sum_{t=1}^{T-1}\\displaystyle\\eta_{t}.}}\\end{array}\n$$\n\nEq. (36) gives the second inequality; the third comes from reordering the sum and discarding the negative term $\\big(1/\\eta_{T-1}\\big)\\big\\|\\pmb{w}_{T}-\\pmb{w}^{\\star}\\big\\|^{2}$. With the choice $\\eta_{t}= \\frac{1}{H t}$ we have $1/\\eta_{t}-1/\\eta_{t-1}-H=Ht-H(t-1)-H=0$, and therefore the regret is at most\n\n$$\nR_{f+r}(T)\\leq 2GD+HD^{2}+{\\frac{7G^{2}}{2}}\\sum_{t=1}^{T-1}{\\frac{1}{Ht}}\\leq 2GD+HD^{2}+{\\frac{7G^{2}}{2H}}(1+\\log T)=O\\left({\\frac{G^{2}}{H}}\\log T\\right)~.\n$$\n\n### Proof of Proposition 11\n\nProof Since the claim is trivially true for $T = 1$, it is enough to establish it for $T = 2$ and then argue by induction. For each norm we give a separate, direct proof, examining the updates derived in Sec. 5 and verifying that $\\pmb{w}_{2}= \\pmb{w}^{\\star}$.\n\nFor $q = 1$ the objectives are separable. Hence, for $\\ell_{1}$-regularization, proving the proposition for an arbitrary single component of the vector w suffices. Dropping the component index, we write $w_{0}, w_{1}, w_{2}, w_{3}, \\ldots$ for one coordinate of w across the iterations of P.1, and $w^{\\star}$ for the same coordinate of the solution of P.2. What must be shown is $w^{\\star}= w_{2}$. Unrolling the $\\ell_{1}$-update of Eq. (19) for two iterations gives\n\n$$\nw_{2}=\\mathrm{sign}(w_{1})\\left[\\left|w_{1}\\right| -\\lambda_{2}\\right]_{+}=\\mathrm{sign}(w_{1})\\left[\\left|\\mathrm{sign}(w_{0})\\left[\\left|w_{0}\\right| -\\lambda_{1}\\right]_{+}\\right| -\\lambda_{2}\\right]_{+}=\\mathrm{sign}(w_{0})\\left[\\left|w_{0}\\right| -\\lambda_{1}-\\lambda_{2}\\right]_{+}\\ ,\n$$\n\nwhere the positivity of | · | was used. Turning to P.2 and applying Eq. (19) once more,\n\n$$\nw^{\\star}=\\mathrm{sign}(w_{0})\\left[|w_{0}| -\\lambda_{1}-\\lambda_{2}\\right]_{+}~.\n$$\n\nConsequently $w^{\\star}= w_{2}$, as asserted.\n\nWe next prove the proposition for $\\ell_{2}$, now working with the whole vector rather than a single coordinate, by means of the explicit $\\ell_{2}$-update from Eq. (20); the norm of the vector ${\\pmb w}_{1}$ produced by program P.1 then expands as\n\n$$\n\\| \\pmb{w}_{1}\\| = \\bigg [ 1 - \\frac{\\lambda_{1}}{\\| \\pmb{w}_{0}\\|}\\bigg ]_{+}\\| \\pmb{w}_{0}\\| = \\big [ \\| \\pmb{w}_{0}\\| - \\lambda_{1}\\big ]_{+}.\n$$\n\nIn the same way, $\\| \\pmb{w}_{2}\\| = [ \\| \\pmb{w}_{1}\\| - \\lambda_{2}]_{+}$. Putting the two norm identities together, the norm of $\\pmb{w}_{2}$ obtained from the two successive updates is\n\n$$\n\\left\\| w_{2}\\right\\| = \\left[ \\left[ \\left\\| w_{0}\\right\\| - \\lambda_{1}\\right]_{+}- \\lambda_{2}\\right]_{+}= \\left[ \\left\\| w_{0}\\right\\| - \\lambda_{1}- \\lambda_{2}\\right]_{+}.\n$$\n\nOn the other hand, computing the norm of $\\pmb{w}^{\\star}$ directly from the update given by Eq. (20) gives\n\n$$\n\\| \\pmb{w}^{\\star}\\| = \\biggl [ 1 - \\frac{\\lambda_{1}+ \\lambda_{2}}{\\| \\pmb{w}_{0}\\|}\\biggr ]_{+}\\| \\pmb{w}_{0}\\| = [ \\| \\pmb{w}_{0}\\| - \\lambda_{1}- \\lambda_{2}]_{+}.\n$$\n\nHence $\\pmb{w}^{\\star}$ and ${\\pmb w}_{2}$ have equal norms. As the update keeps the direction of the original vector $\\pmb{w}_{0}$, we get that ${\\pmb w}^{\\star}={\\pmb w}_{2}$, which is what we needed.\n\nWe come now to the $\\ell_{\\infty}$ norm, whose update and proof are the most involved of the three norms. First we restate the programs P.1 and $\\mathcal{P}. 2$ for $T = 2$ and $q = \\infty$:\n\n$$\n\\mathcal{P}.1:\\quad\\pmb{w}_{1}\\ =\\ \\operatorname*{argmin}_{\\pmb{w}}\\left\\{\\frac{1}{2}\\|\\pmb{w}-\\pmb{w}_{0}\\|^{2}+\\lambda_{1}\\|\\pmb{w}\\|_{\\infty}\\right\\}\\tag{29}\n$$\n\n$$\n\\begin{array}{r c l}{{\\pmb w}_{2}}&{{=}}&{{\\displaystyle\\operatorname*{argmin}_{\\pmb{w}}\\left\\{\\frac{1}{2}\\|{\\pmb w}-{\\pmb w}_{1}\\|^{2}+\\lambda_{2}\\|{\\pmb w}\\|_{\\infty}\\right\\}\\ \\ ,}}\\end{array}\\tag{30}\n$$\n\n$$\n\\mathcal{P}.2:\\quad\\pmb{w}^{\\star}\\ =\\ \\operatorname*{argmin}_{\\pmb{w}}\\left\\{\\frac{1}{2}\\|\\pmb{w}-\\pmb{v}\\|_{2}^{2}+\\left(\\lambda_{1}+\\lambda_{2}\\right)\\|\\pmb{w}\\|_{\\infty}\\right\\}\\ .\\tag{31}\n$$\n\nThe equivalence of the two programs is established in two stages: we treat first the case $\\| \\pmb{w}_{0}\\|_{1}> \\lambda_{1}+ \\lambda_{2}$, and afterwards the complementary case $\\| \\pmb{w}_{0}\\|_{1}\\le \\lambda_{1}+ \\lambda_{2}$. To keep things concrete and simple we take ${\\pmb w}_{0}\\succeq{\\bf 0}$; this is clearly allowed because the objective is symmetric under replacing $\\pmb{w}_{0}$ by $-{\\pmb w}_{0}$. So every entry of $\\pmb{w}_{0}$ may be assumed non-negative. The proof uses the following operators: $[{\\pmb v}]_{+}$ now stands for the entrywise positive part of $v$; $\\min\\{v,\\theta\\}$ is the entrywise minimum of the elements of v and $\\theta$; and similarly $\\max\\{v,\\theta\\}$ is the entrywise maximum. We begin with the case $\\left\\| \\pmb{w}_{0}\\right\\|_{1}> \\lambda_{1}+ \\lambda_{2}$ and look at Eq. (29). Lagrange duality tells us that ${\\pmb w}_{1}={\\pmb w}_{0}-{\\pmb \\alpha}_{1}$, with $\\pmb{\\alpha}_{1}$ the solution of\n\n$$\n\\operatorname*{minimize}_{\\alpha}\\frac{1}{2}\\|\\alpha-\\pmb{w}_{0}\\|_{2}^{2}\\ \\mathrm{s . t .}\\ \\|\\pmb{\\alpha}\\|_{1}\\leq\\lambda_{1}.\n$$\n\nFollowing Duchi et al. (2008), as already reviewed in Sec. 5, $\\pmb{\\alpha}_{1}= [ \\pmb{w}_{0}- \\pmb{\\theta}_{1}]_{+}$ for some $\\theta_{1}\\in \\mathbb{R}_{+}$. This form of $\\pmb{\\alpha}_{1}$ translates directly into the form $\\pmb{w}_{1}= \\pmb{w}_{0}- \\pmb{\\alpha}_{1}= \\min\\{ \\pmb{w}_{0}, \\theta_{1}\\}$ for $\\pmb{w}_{1}$. The same reasoning applied to the second step of P.1 gives $\\pmb{w}_{2}= \\pmb{w}_{1}- \\pmb{\\alpha}_{2}= \\pmb{w}_{0}- \\pmb{\\alpha}_{1}- \\pmb{\\alpha}_{2}$, with $\\pmb{\\alpha}_{2}$ the minimizer of\n\n$$\n\\frac{1}{2}\\left\\|\\alpha-\\pmb{w}_{1}\\right\\|_{2}^{2}=\\frac{1}{2}\\left\\|\\alpha-\\left(\\pmb{w}_{0}-\\pmb{\\alpha}_{1}\\right)\\right\\|_{2}^{2}\\mathrm{s.t.}\\left\\|\\pmb{\\alpha}\\right\\|_{1}\\leq\\lambda_{2}\\mathrm{.}\n$$\n\nOnce again $\\pmb{\\alpha}_{2}= [ \\pmb{w}_{1}- \\pmb{\\theta}_{2}]_{+}= [ \\pmb{w}_{0}- \\pmb{\\alpha}_{1}- \\pmb{\\theta}_{2}]_{+}$ for some $\\theta_{2}\\in \\mathbb{R}_{+}$. Combining the two successive steps,\n\n$$\n{\\pmb w}_{2}=\\operatorname*{min}\\{{\\pmb w}_{1},{\\theta}_{2}\\}=\\operatorname*{min}\\left\\{\\operatorname*{min}\\{{\\pmb w}_{0},{\\theta}_{1}\\},{\\theta}_{2}\\right\\}\\mathrm{~.~}\n$$\n\nOur next claim is that $\\theta_{2}\\leq \\theta_{1}$, whatever the 1-norm of $w_{0}$. The intuition is that if $\\theta_{2}> \\theta_{1}$, the second minimization step of P.1 would apply no shrinkage to $\\pmb{w}_{1}$ in producing $\\pmb{w}_{2}$. To make this rigorous, suppose toward a contradiction that $\\theta_{2}> \\theta_{1}$. Then ${\\pmb w}_{2}=\\mathrm{min}\\{\\mathrm{min}\\{{\\pmb w}_{0},{\\pmb\\theta}_{1}\\},{\\pmb\\theta}_{2}\\}=\\mathrm{min}\\{{\\pmb w}_{0},{\\pmb\\theta}_{1}\\}={\\pmb w}_{1}$. It follows that the subgradient set of Eq. (30) at ${\\pmb w}={\\pmb w}_{1}$ contains 0, that is,\n\n$$\n\\mathbf{0}\\in{\\pmb w}_{1}-{\\pmb w}_{1}+ \\lambda_{2}\\partial \\left\\|{\\pmb w}_{1}\\right\\|_{\\infty}= \\lambda_{2}\\partial \\left\\|{\\pmb w}_{1}\\right\\|_{\\infty}.\n$$\n\nBut the set $\\partial \\| \\pmb{w}_{1}\\|_{\\infty}$ obviously contains 0 only if ${\\pmb w}_{1}={\\bf 0}$. Because we assumed $\\lambda_{1}< \\| w_{0}\\|_{1}$, so that $\\pmb{\\alpha}_{1}\\preceq{w_{0}}$ and $\\pmb{\\alpha}_{1}\\neq \\pmb{w}_{0}$, it follows that $\\pmb{w}_{1}= \\pmb{w}_{0}- \\pmb{\\alpha}_{1}\\neq \\pmb{0}$. This contradiction shows $\\theta_{2}\\leq \\theta_{1}$.\n\nConsider now $\\pmb{\\alpha}_{1}$ and $\\pmb{\\alpha}_{2}$, the solution vectors of the dual problems of $\\mathcal{P}. 1$. Since $\\| \\pmb{\\alpha}_{1}\\|_{1}= \\lambda_{1}$, we have $\\left\\| \\pmb{w}_{0}- \\pmb{\\alpha}_{1}\\right\\|_{1}> \\lambda_{2}$, and so $\\pmb{\\alpha}_{2}$ lies on the boundary, $\\| \\pmb{\\alpha}_{2}\\|_{1}= \\lambda_{2}$ (again see Duchi et al. 2008). In addition, these vectors add up to\n\n$$\n\\alpha_{1}+ \\alpha_{2}= \\left[{\\pmb w}_{0}-{\\pmb \\theta}_{1}\\right]_{+}+ \\left[{\\pmb w}_{0}- \\left[{\\pmb w}_{0}-{\\pmb \\theta}_{1}\\right]_{+}-{\\pmb \\theta}_{2}\\right]_{+}.\\tag{32}\n$$\n\nLet $v$ be any component of $\\pmb{w}_{0}$ exceeding $\\theta_{1}$. For such a component, the right-hand side of Eq. (32) equals\n\n$$\n\\left[v-(v-\\theta_{1})-\\theta_{2}\\right]_{+}+\\left[v-\\theta_{1}\\right]_{+}=\\left[\\theta_{1}-\\theta_{2}\\right]_{+}+v-\\theta_{1}=v-\\theta_{1}=\\left[v-\\theta_{1}\\right]_{+}\\ ,\n$$\n\nwhere the term $\\left[ \\theta_{1}- \\theta_{2}\\right]_{+}$ was removed using $\\theta_{2}\\leq \\theta_{1}$. Now let u be a component of $\\pmb{w}_{0}$ below $\\theta_{1}$. For such a component the right-hand side of Eq. (32) equals $[ u - 0 - \\theta_{2}]_{+}+ 0 = [ u - \\theta_{2}]_{+}$. To summarize, the vector sum $\\pmb{\\alpha}_{1}+ \\pmb{\\alpha}_{2}$ is equal to $[{\\pmb w}_{0}-{\\theta}_{2}]_{+}$. Furthermore, $\\pmb{\\alpha}_{1}$ and $\\pmb{\\alpha}_{2}$ lie in $\\mathbb{R}^{n}_{+}$ since we assumed ${\\pmb w}_{0}\\succeq{\\bf 0}$, and hence\n\n$$\n\\| \\left[{\\pmb w}_{0}-{\\pmb \\theta}_{2}\\right]_{+}\\|_{1}= \\|{\\pmb \\alpha}_{1}+{\\pmb \\alpha}_{2}\\|_{1}= \\lambda_{1}+ \\lambda_{2}\\enspace .\\tag{33}\n$$\n\nWe next verify that P.2 has the same dual solution as the sequential updates just analyzed. The dual of P.2 reads\n\n$$\n\\operatorname*{minimize}_{\\alpha}\\frac{1}{2}\\left\\|\\alpha-\\pmb{w}_{0}\\right\\|_{2}^{2}\\mathrm{s . t .}\\left\\|\\pmb{\\alpha}\\right\\|_{1}\\leq\\lambda_{1}+\\lambda_{2}.\n$$\n\nWriting $\\pmb{\\alpha}_{0}$ for the solution of this dual problem, we have $\\pmb{w}^{\\star}= \\pmb{w}_{0}- \\pmb{\\alpha}_{0}$ and $\\pmb{\\alpha}_{0}= [ \\pmb{w}_{0}- \\pmb{\\theta}]_{+}$ for some $\\theta \\in \\mathbb{R}_{+}$. Its norm satisfies\n\n$$\n\\| \\pmb{\\alpha}_{0}\\|_{1}= \\big \\| [ \\pmb{w}_{0}- \\pmb{\\theta}]_{+}\\big \\|_{1}= \\lambda_{1}+ \\lambda_{2}\\tag{34}\n$$\n\nas a consequence of the assumption $\\| \\pmb{w}_{0}\\|_{1}> \\lambda_{1}+ \\lambda_{2}$. Regard $\\left\\| \\left[{\\pmb w}_{0}-{\\pmb \\theta}_{2}\\right]_{+}\\right\\|_{1}$ in Eq. (33) as a function of $\\theta_{2}$, and $\\left\\| \\left[ \\pmb{w}_{0}- \\pmb{\\theta}\\right]_{+}\\right\\|_{1}$ in Eq. (34) as a function of θ. On the interval $[0,\\|\\pmb{w}_{0}\\|_{\\infty}]$ both are strictly decreasing functions of θ and $\\theta_{2}$, so they are invertible for $0 < \\lambda_{1}+ \\lambda_{2}< \\| \\pmb{w}_{0}\\|_{1}$. As $\\left\\| [ \\pmb{w}_{0}- \\pmb{\\theta}]_{+}\\right\\|_{1}= \\left\\| [ \\pmb{w}_{0}- \\pmb{\\theta}_{2}]_{+}\\right\\|_{1}$, necessarily $\\theta_{2}= \\theta$. Recall that Eq. (31) is solved by $w^{\\star}= \\min\\{w_{0}, \\theta \\}$, whereas the sequential update defined by Eq. (29) and Eq. (30) produces $\\min\\{ \\min\\{w_{0}, \\theta_{1}\\}, \\theta_{2}\\}= \\min\\{w_{0}, \\theta_{2}\\}$. Thus P.1 and P.2 lead to the same vector $\\min\\{w_{0}, \\theta_{2}\\}= \\min\\{w_{0}, \\theta \\}$, and the updates they induce are equivalent.\n\nIt remains to handle the case $\\lVert \\boldsymbol{w}_{0}\\rVert_{1}\\leq \\lambda_{1}+ \\lambda_{2}$. If moreover the 1-norm of $\\pmb{w}_{0}$ is below $\\lambda_{1}$, i.e. $\\| \\pmb{w}_{0}\\|_{1}\\le \\lambda_{1}$, then the dual solution of the first step of P.1 is $\\pmb{\\alpha}_{1}= \\pmb{w}_{0}$, so $\\pmb{w}_{1}= \\pmb{w}_{0}- \\pmb{\\alpha}_{1}= \\pmb{0}$ and consequently ${\\pmb w}_{2}={\\bf 0}$. For the combined problem the dual solution is clearly $\\pmb{\\alpha}_{0}= \\pmb{w}_{0}$, and once more $\\pmb{w}^{\\star}= \\pmb{w}_{0}- \\pmb{\\alpha}_{0}= \\pmb{0}$. What is left is the case $\\lambda_{1}< \\| \\pmb{w}_{0}\\|_{1}\\leq \\lambda_{1}+ \\lambda_{2}$. Here it is immediate that Eq. (31) is solved by $\\boldsymbol{w}^{\\star}= \\mathbf{0}$. We show that the iterated solution produced by P.1 is also the zero vector. Start with the dual solution $\\pmb{\\alpha}_{1}$, which minimizes $\\| \\pmb{\\alpha}- \\pmb{w}_{0}\\|^{2}$ under the constraint $\\| \\alpha \\|_{1}\\leq \\lambda_{1}$. As $\\pmb{\\alpha}_{1}= [ \\pmb{w}_{0}- \\pmb{\\theta}_{1}]_{+}$ for some $\\theta_{1}\\geq 0$, each entry of $\\pmb{\\alpha}_{1}$ lies between zero and the matching entry of $\\pmb{w}_{0}$; hence $\\| \\pmb{w}_{0}- \\pmb{\\alpha}_{1}\\|_{1}= \\| \\pmb{w}_{0}\\|_{1}- \\| \\pmb{\\alpha}\\|_{1}= \\| \\pmb{w}_{0}\\|_{1}- \\lambda_{1}\\leq \\lambda_{2}$. The dual of the second step of P.1 reduces to minimizing $\\frac{1}{2}\\|\\pmb{\\alpha}-\\big(\\pmb{w}_{0}-\\pmb{\\alpha}_{1}\\big)\\|^{2}$ under the constraint $\\left\\| \\alpha \\right\\|_{1}\\leq \\lambda_{2}$. Having shown $\\left\\| \\pmb{w}_{0}- \\pmb{\\alpha}\\right\\|_{1}\\le \\lambda_{2}$, we obtain $\\alpha_{2}={\\pmb w}_{0}-{\\pmb \\alpha}_{1}$, which means $\\theta_{2}= 0$. Recalling that the solution of $\\mathcal{P}. 1$ is $\\min\\{w_{0}, \\theta_{2}\\}$, this equals the zero vector when $\\theta_{2}= 0$. Both optimization problems therefore produce the zero vector, which establishes the equivalence of P.1 and P.2 for $q = \\infty$.", "context": [{"id": "v10-duchi09a:ctx1", "name": "Setup and notation: objective f + r, convex and nonnegative (Section 1)", "statement": "We first fix the notation used throughout the paper. Scalars are written as lower case letters and vectors as bold lower case letters, e.g. w. For two vectors u and v, $\\langle{\\pmb u},{\\pmb v}\\rangle$ is their inner product. The p-norm of a vector x is written $\\| \\pmb{x}\\|_{p}$, and ||x|| abbreviates $\\| \\pmb{x}\\|_{2}$.\n\nThe paper studies an algorithmic framework for regularized convex programming whose aim is to minimize a sum of two functions,\n\n$$\nf({\\pmb w})+r({\\pmb w}),\\tag{1}\n$$\n\nin which f and r are both convex and bounded below (so that, with no loss of generality, they are taken to map into $\\mathbb{R}_{+}$). Typically f is an empirical loss of the form $\\textstyle\\sum_{i\\in S}\\ell_{i}(w)$ built from loss functions $\\ell_{i}: \\mathbb{R}^{n}\\to \\mathbb{R}_{+}$, and $r(w)$ is a regularizer that penalizes overly complex vectors, e.g. $r(\\mathbf{w})=\\lambda\\|\\mathbf{w}\\|_{p}$. Such tasks are common in machine learning, where learning problems for decision and prediction are formulated as convex optimization problems. With this in mind, we study a general and intuitive algorithm called forward-backward splitting for minimizing Eq. (1), with particular emphasis on derivations for, and the use of, regularization functions that are not differentiable."}, {"id": "v10-duchi09a:ctx2", "name": "Definition: subgradient set", "statement": "For a function f and a point w, write $\\partial f ({\\boldsymbol{w}})$ for the subgradient set of f at w, that is,\n\n$$\n\\partial f(w)=\\{g\\mid\\forall v:f(v)\\geq f(w)+\\langle g,v-w\\rangle\\}.\n$$"}, {"id": "v10-duchi09a:ctx3", "name": "Algorithm: FoBoS update and forward-looking subgradient, Eqs. (2)-(5) (Section 2)", "statement": "Our version of Forward-Backward Splitting is driven by the wish that the iterates ${\\pmb w}_{t}$ be able to reach points where r is not differentiable. For problems such as $\\ell_{1}$-regularization, the method sidesteps the difficulties caused by non-differentiability by alternating subgradient steps with analytical minimization steps. Informally, FoBoS resembles the projected subgradient method, except that the projection step is replaced or augmented by an instantaneous minimization problem whose solution can be derived in closed form. The method is compact: every iteration is made of the two steps below,\n\n$$\n\\begin{array}{r l r}{{\\bf w}_{t + \\frac{1}{2}}}&{{}=}&{{\\bf w}_{t}- \\boldsymbol \\eta_{t}{\\bf g}_{t}^{f},}\\end{array}\\tag{2}\n$$\n\n$$\n\\begin{array}{r c l}{{\\pmb w}_{t+1}}&{=}&{\\displaystyle\\operatorname*{argmin}_{{\\pmb w}}\\left\\{\\frac{1}{2}\\left\\|{\\pmb w}-{\\pmb w}_{t+\\frac{1}{2}}\\right\\|^{2}+\\eta_{t+\\frac{1}{2}}r({\\pmb w})\\right\\}\\ .}\\end{array}\\tag{3}\n$$\n\nHere $g_{t}^{f}$ is an element of $\\partial f ({\\pmb w}_{t})$, and $\\eta_{t}$ denotes the step size used by the algorithm at time step t. What value $\\eta_{t}$ takes depends on the particular setting and analysis. The first step is thus nothing more than an unconstrained subgradient step for the function $f$. The second step produces a new vector that balances two aims: (i) remaining near the interim vector $w_{t + \\frac{1}{2}}$, and (ii) having small complexity as measured by r. Observe that r is multiplied by an interim step size, written $\\eta_{t + \\frac{1}{2}}$. The analyses later in the paper fix the particular value of $\\eta_{t + \\frac{1}{2}}$, which is either $\\eta_{t}$ or $\\eta_{t + 1}$.\n\nAn important property of the solution of Eq. (3), which also explains the name FoBoS, is the necessary optimality condition: at the optimum ${\\pmb w}_{t + 1}$, the subgradient set of the objective must contain the zero vector, i.e.\n\n$$\n\\mathbf{0}\\in\\partial\\left\\{\\frac{1}{2}\\left\\|w-w_{t+\\frac{1}{2}}\\right\\|^{2}+\\eta_{t+\\frac{1}{2}}r(w)\\right\\}\\bigg|_{w=w_{t+1}}.\n$$\n\nAs $\\pmb{w}_{t + \\frac{1}{2}}= \\pmb{w}_{t}- \\eta_{t}\\pmb{g}_{t}^{f}$, this condition reads\n\n$$\n\\mathbf{0}\\in\\pmb{w}_{t+1}-\\pmb{w}_{t}+\\eta_{t}\\pmb{g}_{t}^{f}+\\eta_{t+\\frac{1}{2}}\\partial r(\\pmb{w}_{t+1}).\\tag{4}\n$$\n\nFrom $\\mathbf{0}\\in\\pmb{w}_{t+1}-\\pmb{w}_{t}+\\eta_{t}\\pmb{g}_{t}^{f}+\\eta_{t+\\frac{1}{2}}\\partial r(\\pmb{w}_{t+1})$ it follows that, as long as ${\\pmb w}_{t + 1}$ is taken to be the minimizer of Eq. (3), there is guaranteed to be a vector $\\pmb{g}_{t+1}^{r}\\in\\partial r(\\pmb{w}_{t+1})$ with\n\n$$\n{\\bf 0}={\\pmb w}_{t + 1}-{\\pmb w}_{t}+ \\eta_{t}{\\pmb g}_{t}^{f}+ \\eta_{t + \\frac{1}{2}}{\\pmb g}_{t + 1}^{r}\\mathrm{~ . ~}\n$$\n\nThis identity may be read as an update rule in which the new weight vector ${\\pmb w}_{t + 1}$ is a linear combination of three vectors: the previous weight vector ${\\pmb w}_{t}$, an element of the subgradient set of $f$ at ${\\pmb w}_{t}$, and an element of the subgradient of r at the not-yet-known ${\\pmb w}_{t + 1}$; this is the origin of the name Forward-Looking Subgradient. In summary, ${\\pmb w}_{t + 1}$ can be written as\n\n$$\n\\pmb{w}_{t + 1}= \\pmb{w}_{t}- \\eta_{t}\\pmb{g}_{t}^{f}- \\eta_{t + \\frac{1}{2}}\\pmb{g}_{t + 1}^{r},\\tag{5}\n$$\n\nwith ${\\pmb g}_{t}^{f}\\in \\partial f ({\\pmb w}_{t})$ and $\\pmb{g}_{t+1}^{r}\\in\\partial r(\\pmb{w}_{t+1})$. Solving Eq. (3) with r as above brings two main advantages. First, algorithmically, it produces sparse solutions at almost no extra computational cost. Second, thanks to the forward-looking gradient we can reuse existing analyses and prove that the resulting framework inherits the formal convergence guarantees of many existing gradient-based and online convex programming algorithms."}, {"id": "v10-duchi09a:ctx4", "name": "Setup: choice of the interim step size eta_{t+1/2} (Section 3)", "statement": "At first sight FoBoS appears quite different from subgradient and online convex programming methods. Yet because FoBoS in fact uses a forward-looking subgradient of the regularizer, existing analyses carry over well. In this section we adapt known results, exploiting the forward-looking property of FoBoS, to obtain convergence rate analyses for FoBoS. This requires choosing $\\eta_{t + \\frac{1}{2}}$ appropriately. As shown below, to get convergence and low regret bounds it suffices to take $\\eta_{t + \\frac{1}{2}}$ equal to $\\eta_{t}$ or to $\\eta_{t + 1}$, according to whether the optimization is online or batch. We first analyze FoBoS in the batch setting. There we use the subgradient of $f$, put $\\eta_{t + \\frac{1}{2}}= \\eta_{t + 1}$, and move from ${\\pmb w}_{t}$ to ${\\pmb w}_{t + 1}$ as specified by Eq. (2) and Eq. (3)."}, {"id": "v10-duchi09a:ctx5", "name": "Assumption: bounded subgradients, Eq. (6)", "statement": "In this section $w^{\\star}$ always denotes the minimizer of $f ({\\pmb w}) + r ({\\pmb w})$. Below we set $\\begin{array}{r}{\\|\\partial f(\\pmb{w})\\|\\triangleq\\operatorname*{sup}_{\\pmb{g}\\in\\partial f(\\pmb{w})}\\|\\pmb{g}\\|}\\end{array}$. Our first convergence results are derived under the rather general assumption (see, for instance, Langford et al. 2008 or Shalev-Shwartz and Tewari 2009) that the subgradients obey the bounds\n\n$$\n\\begin{array}{r}{\\|\\partial f(\\pmb{w})\\|^{2}\\leq Af(\\pmb{w})+G^{2},\\quad\\|\\partial r(\\pmb{w})\\|^{2}\\leq Ar(\\pmb{w})+G^{2}.}\\end{array}\\tag{6}\n$$\n\nAs examples, every Lipschitz loss (for instance the logistic loss, or the hinge loss of support vector machines) meets this condition with $A = 0$ and G the Lipschitz constant, while least squares estimation meets Eq. (6) with $G = 0$ and $A = 4$. The following lemma is technical, but it is the central tool behind every convergence result in this paper."}, {"id": "v10-duchi09a:ctx6", "name": "Lemma 1 (Bounding Step Differences)", "statement": "Lemma 1 (Bounding Step Differences) Suppose the subgradient norms of f and r obey the bounds of Eq. (6):\n\n$$\n\\|\\partial f(\\pmb{w})\\|^{2}\\leq Af(\\pmb{w})+G^{2},\\quad\\|\\partial r(\\pmb{w})\\|^{2}\\leq Ar(\\pmb{w})+G^{2}.\n$$\n\nLet $\\eta_{t + 1}\\leq \\eta_{t + \\frac{1}{2}}\\leq \\eta_{t}$, and assume $\\eta_{t}\\le 2 \\eta_{t + \\frac{1}{2}}$. Then, when the FoBoS update of Eqs. (2) and (3) is used, for a constant $c \\leq 4$ and every vector $\\pmb{w}^{\\star}$,\n\n$$\n\\begin{array}{r l r}{{2\\boldsymbol\\eta_{t}\\big(1-cA\\boldsymbol\\eta_{t}\\big)f\\big(\\boldsymbol{w}_{t}\\big)+2\\boldsymbol\\eta_{t+\\frac{1}{2}}\\big(1-cA\\boldsymbol\\eta_{t+\\frac{1}{2}}\\big)\\boldsymbol{r}\\big(\\boldsymbol{w}_{t+1}\\big)}}\\\\ &{\\leq}&{2\\boldsymbol\\eta_{t}f\\big(\\boldsymbol{w}^{\\star}\\big)+2\\boldsymbol\\eta_{t+\\frac{1}{2}}\\boldsymbol{r}\\big(\\boldsymbol{w}^{\\star}\\big)+\\|\\boldsymbol{w}_{t}-\\boldsymbol{w}^{\\star}\\|^{2}-\\|\\boldsymbol{w}_{t+1}-\\boldsymbol{w}^{\\star}\\|^{2}+7\\boldsymbol\\eta_{t}\\boldsymbol\\eta_{t+\\frac{1}{2}}G^{2}\\quad .}\\end{array}\n$$"}, {"id": "v10-duchi09a:ctx7", "name": "Setup: online learning and regret R_{f+r}(T) (Section 4)", "statement": "This section gives a regret analysis of FoBoS in online settings. An online learning problem supplies a sequence of functions $f_{t}: \\mathbb{R}^{n}\\longrightarrow \\mathbb{R}$. The aim is that the predictions ${\\pmb w}_{t}$ incur low regret relative to one fixed optimal predictor $w^{\\star}$. Precisely, $f_{t}({\\boldsymbol{w}})$ is the loss incurred on the $t^{t h}$ input loss function by the predictor w. For an online algorithm whose predictors are $\\boldsymbol{w}_{1},\\ldots,\\boldsymbol{w}_{t},\\ldots$, the regret with respect to a fixed predictor $\\pmb{w}^{\\star}$ under a regularization function r is\n\n$$\nR_{f+r}(T)=\\sum_{t=1}^{T}\\left[f_{t}(\\pmb{w}_{t})+r(\\pmb{w}_{t})-\\left(f_{t}(\\pmb{w}^{\\star})+r(\\pmb{w}^{\\star})\\right)\\right].\n$$\n\nThe ideal would be zero regret against a stationary $\\pmb{w}^{\\star}$ for sequences of any length.\n\nTo get an online bound for a sequence of convex functions $f_{t}$, we adapt the arguments of Zinkevich (2003). With the bound of Lemma 1 at hand, a theorem on the online regret of FoBoS can be stated and proved directly. The boundedness assumptions in the proof could be dropped (yielding a regret analogue of the bound in Theorem 2), but we do not consider this notably more interesting. Apart from its use of Lemma 1, the proof closely follows Zinkevich's, and so it is postponed to Appendix A."}, {"id": "v10-duchi09a:ctx8", "name": "Definition: H-strong convexity and Eq. (17)", "statement": "FoBoS also admits an improved regret bound when the loss functions $f_{t}(\\cdot)$ or the function $r(\\cdot)$ are strongly convex. Hazan et al. (2006) showed that, for the projected gradient method with strongly convex functions, regret of order ${\\cal O}(\\log T)$ is attainable by exploiting the curvature of the functions $f_{t}$ instead of relying only on convexity and linearity as in Theorems 2 and 6. These results extend to FoBoS whenever $f_{t}({\\pmb w}) + r ({\\pmb w})$ is strongly convex, at least on the region $\\| \\pmb{w}- \\pmb{w}^{\\star}\\| \\leq D$. For the sake of completeness we restate some definitions and give the logarithmic regret bound for FoBoS. A function f is said to be H-strongly convex when\n\n$$\nf(\\pmb{w})\\geq f(\\pmb{w}_{t})+\\langle\\nabla f(\\pmb{w}_{t}),\\pmb{w}-\\pmb{w}_{t}\\rangle+\\frac{H}{2}\\|\\pmb{w}-\\pmb{w}_{t}\\|^{2}.\n$$\n\nHence, when r and the functions $f_{t}$ are strongly convex with constants $H_{r}\\geq 0$ and $H_{f}\\geq 0$ respectively, we get $H = H_{f}+ H_{r}$, and H-strong convexity yields\n\n$$\nf_{t}({\\boldsymbol{w}}_{t}) - f ({\\boldsymbol{w}}^{\\star}) + r ({\\boldsymbol{w}}_{t}) - r ({\\boldsymbol{w}}^{\\star}) \\leq \\left\\langle{\\boldsymbol{g}}_{t}^{f}+{\\boldsymbol{g}}_{t}^{r},{\\boldsymbol{w}}_{t}-{\\boldsymbol{w}}^{\\star}\\right\\rangle - \\frac{H}{2}\\|{\\boldsymbol{w}}_{t}-{\\boldsymbol{w}}^{\\star}\\|^{2}~ .\\tag{17}\n$$\n\nIt is not necessary for both $f_{t}$ and r to be strongly convex; it is enough that at least one of the two has a positive strong convexity constant. For instance, with $\\begin{array}{r}{r ({\\bf w}) = \\frac{\\lambda}{2}\\|{\\bf w}\\|^{2}}\\end{array}$ we have $H \\geq \\lambda$ provided the functions $f_{t}$ are convex. Using Eq. (17), we can build directly on Hazan et al. (2006) to prove a stronger regret bound for the online learning case. Because the proof resembles that of Hazan et al., it too is deferred to Appendix A."}, {"id": "v10-duchi09a:ctx9", "name": "Setup: proximal step notation, Eq. (18) and [z]_+ (Section 5)", "statement": "We begin by adjusting the notation. To make the derivations simpler, we write v for the vector $w_{t + \\frac{1}{2}}= w_{t}- \\eta_{t}g_{t}^{f}$ and write $\\tilde{\\lambda}$ for $\\eta_{t + \\frac{1}{2}}\\cdot \\lambda$. In this notation the problem of Eq. (3) becomes\n\n$$\n\\operatorname*{minimize}_{\\pmb{w}}\\frac{1}{2}\\|\\pmb{w}-\\pmb{v}\\|^{2}+\\widetilde{\\lambda}r(\\pmb{w}).\\tag{18}\n$$\n\nWe use $[ z ]_{+}$ for $\\max\\{0,z\\}$. Although full derivations are given for every regularization function we consider, to save space we do not formally state well-known technical lemmas. Many of the results below were stated implicitly by Wright et al. (2009)."}, {"id": "v10-duchi09a:ctx10", "name": "Update: l1 regularization (soft thresholding), Eq. (19) (Section 5.1)", "statement": "Taking $r(\\pmb{w})=\\lambda\\|\\pmb{w}\\|_{1}$ leads to a simple and intuitive update. To begin with, the objective decomposes, since Eq. (18) can be rewritten as\n\n$$\n\\operatorname*{minimize}_{\\boldsymbol{w}}\\ \\sum_{j=1}^{n}\\left(\\frac{1}{2}(w_{j}-v_{j})^{2}+\\tilde{\\lambda}|w_{j}|\\right).\n$$\n\nFix one coordinate of w and, to shorten notation, drop the index $j$. Let $w^{\\star}$ be the minimizer of $\\frac{1}{2}(w-v)^{2}+\\tilde{\\lambda}|w|$. Plainly $w^{\\star}\\cdot v \\geq 0$. Otherwise $w^{\\star}\\cdot v < 0$, but then ${\\scriptstyle{\\frac{1}{2}}}v^{2}<$ $\\begin{array}{r}{\\frac{1}{2}v^{2}-w^{\\star}\\cdot v+\\frac{1}{2}(w^{\\star})^{2}<\\frac{1}{2}(v-w^{\\star})^{2}+\\tilde{\\lambda}|w^{\\star}|}\\end{array}$, which contradicts the assumed optimality of $w^{\\star}$. Since the objective is symmetric in v, we may also take $v \\geq 0$; it then remains to minimize $\\frac{1}{2}\\left(w-v\\right)^{2}+\\tilde{\\lambda}w$ subject to $w \\ge 0$. Attaching a Lagrange multiplier $\\beta \\geq 0$ to this constraint gives the Lagrangian $\\frac{1}{2}(w-v)^{2}+\\tilde{\\lambda}w-\\beta w$. Differentiating the Lagrangian in w and equating to zero shows that the optimum is $w^{\\star}= v - \\tilde{\\lambda}+ \\beta$. When $w^{\\star}> 0$, complementary slackness, which requires the optimal pair $w^{\\star}$ and β to satisfy $w^{\\star}\\beta = 0$ (Boyd and Vandenberghe, 2004), forces $\\beta = 0$, hence $w^{\\star}= v - \\tilde{\\lambda}$. When $v < \\tilde{\\lambda}$, we have $v - \\tilde{\\lambda}< 0$, so β must be positive and, again by complementary slackness, $w^{\\star}= 0$. The case $v \\leq 0$ is the same up to a change of signs. Putting this together and returning to the full notation, the coordinates of the optimal solution $\\pmb{w}^{\\star}= \\pmb{w}_{t + 1}$ are obtained from $w_{t + \\frac{1}{2}}$ by\n\n$$\nw_{t+1,j}=\\mathrm{sign}\\Big(w_{t+\\frac{1}{2},j}\\Big)\\left[|w_{t+\\frac{1}{2},j}| -\\widetilde{\\lambda}\\right]_{+}=\\mathrm{sign}\\Big(w_{t,j}-\\eta_{t}g_{t,j}^{f}\\Big)\\left[\\Big|w_{t,j}-\\eta_{t}g_{t,j}^{f}\\Big| -\\eta_{t+\\frac{1}{2}}\\cdot\\lambda\\right]_{+}.\\tag{19}\n$$\n\nThis update can produce sparse solutions: any component of ${\\pmb w}_{t +{\\frac{1}{2}}}$ whose absolute value is below $\\tilde{\\lambda}$ yields a zero in the corresponding component of ${\\pmb w}_{t + 1}$. Eq. (19) therefore provides a simple online and offline method for minimizing a convex $f$ under $\\ell_{1}$ regularization."}, {"id": "v10-duchi09a:ctx11", "name": "Update: l2^2 regularization, Eq. (20) (Section 5.2)", "statement": "With $\\begin{array}{r}{r(\\pmb{w})=\\frac{\\lambda}{2}\\|\\pmb{w}\\|_{2}^{2}}\\end{array}$ the optimization problem is very simple:\n\n$$\n\\operatorname*{minimize}_{\\boldsymbol{w}}\\frac{1}{2}\\|\\boldsymbol{w}-\\boldsymbol{v}\\|^{2}+\\frac{1}{2}\\widetilde{\\lambda}\\|\\boldsymbol{w}\\|^{2},\n$$\n\nwhere, to make the solution more concise, $\\tilde{\\lambda}$ has been replaced by $\\frac{1}{2}\\tilde{\\lambda}$. Setting the derivative of this objective to zero gives $\\pmb{w}^{\\star}- v + \\tilde{\\lambda}\\pmb{w}^{\\star}= 0$, and in the original notation this is the update\n\n$$\n\\pmb{w}_{t + 1}= \\frac{\\pmb{w}_{t}- \\pmb{\\eta}_{t}\\pmb{g}_{t}^{f}}{1 + \\tilde{\\lambda}}.\\tag{20}\n$$"}, {"id": "v10-duchi09a:ctx12", "name": "Update: l2 regularization (Section 5.3)", "statement": "The $\\ell_{2}$ norm of the weight vector is a less commonly used choice of regularizer. Taking $r(\\boldsymbol{w})=\\tilde{\\lambda}\\|\\boldsymbol{w}\\|$, we arrive at the problem\n\n$$\n\\operatorname*{minimize}_{\\boldsymbol{w}}\\frac{1}{2}\\|\\boldsymbol{w}-\\boldsymbol{v}\\|^{2}+\\widetilde{\\lambda}\\|\\boldsymbol{w}\\|.\\tag{21}\n$$\n\nAny solution of Eq. (21) points in the direction of v, i.e. it has the form $\\pmb{w}^{\\star}= s \\pmb{v}$ with $s \\geq 0$. To verify this form, suppose for contradiction that $\\pmb{w}^{\\star}= s \\pmb{v}+ \\pmb{u}$, where u lies in the null space of v (should u have components parallel to v, these can be added to v, leaving an orthogonal $\\pmb{u}^{\\prime}$) and s is allowed to be negative. As u is orthogonal to $v$, the objective can be written in terms of $s$, $v$ and u as\n\n$$\n\\frac 12(1-s)^{2}\\|{\\pmb v}\\|^{2}+\\frac 12\\|{\\pmb u}\\|^{2}+\\widetilde{\\lambda}(\\|{\\pmb v}\\|+\\|{\\pmb u}\\|)\\ge\\frac 12(1-s)^{2}\\|{\\pmb v}\\|^{2}+\\widetilde{\\lambda}\\|{\\pmb v}\\|.\n$$\n\nSo u has to be the zero vector, ${\\pmb u}={\\bf 0}$, and the optimization problem can be written as\n\n$$\n\\operatorname*{minimize}_{s}\\frac{1}{2}(1-s)^{2}\\|\\pmb{v}\\|^{2}+\\widetilde{\\lambda}s\\|\\pmb{v}\\|\\enspace .\n$$\n\nMoreover, no negative s can be optimal. Indeed, when $s < 0$,\n\n$$\n\\frac{1}{2}(1-s)^{2}\\|\\pmb{v}\\|^{2}+\\tilde{\\lambda}s\\|\\pmb{v}\\|<\\frac{1}{2}\\|\\pmb{v}\\|^{2}.\n$$\n\nHence the choice $s = 0$ attains a smaller objective value, which rules out negative s as an optimal solution. We are thus led once more to a constrained scalar problem, $\\operatorname*{minimize}_{s\\geq 0}\\frac{1}{2}(1-s)^{2}\\|\\pmb{v}\\|^{2}+\\tilde{\\lambda}s\\|\\pmb{v}\\|$, whose Lagrangian is\n\n$$\n\\frac{1}{2}(1-s)^{2}\\|\\pmb{v}\\|^{2}+\\tilde{\\lambda}s\\|\\pmb{v}\\|-\\beta s\\ ,\n$$\n\nwith $\\beta \\geq 0$. Differentiating the Lagrangian in s and setting the derivative to zero gives $(s-1)\\|{\\pmb v}\\|^{2}+\\tilde{\\lambda}\\|{\\pmb v}\\|-{\\beta}=0$, and hence the closed form $s = 1 - \\tilde{\\lambda}/ \\| v \\| + \\beta / \\| v \\|^{2}$. If $s > 0$, complementary slackness gives $\\beta = 0$, and s simplifies to $s = 1 - \\tilde{\\lambda}/ \\| v \\|$. This quantity is positive if and only if $\\| v \\| > \\tilde{\\lambda}$. If $\\| v \\| < \\tilde{\\lambda}$, then β has to be positive and complementary slackness yields $s = 0$.\n\nIn summary, with $\\ell_{2}$ regularization the second step of the FoBoS update is\n\n$$\nw_{t+1}=\\left[1-\\frac{\\tilde{\\lambda}}{\\lVert w_{t+\\frac{1}{2}}\\rVert}\\right]_{+}w_{t+\\frac{1}{2}}=\\left[1-\\frac{\\tilde{\\lambda}}{\\lVert w_{t}-\\eta_{t}g_{t}^{f}\\rVert}\\right]_{+}(w_{t}-\\eta_{t}g_{t}^{f})\\ .\n$$\n\nConsequently, $\\ell_{2}$ regularization gives the zero weight vector exactly under the condition $\\| \\pmb{w}_{t}- \\pmb{\\eta}_{t}\\pmb{g}_{t}^{f}\\| \\le \\tilde{\\lambda}$. As a requirement for sparsity this is considerably stronger than the one for $\\ell_{1}$ (there a single weight becomes sparse depending only on its own value, whereas here sparsity occurs only when the whole weight vector has $\\ell_{2}$-norm below $\\tilde{\\lambda}$), so in high dimensions it is unlikely to be met. It is nonetheless a key building block when a mixed $\\ell_{1}/ \\ell_{2}$-norm serves as the regularizer, as shown later."}, {"id": "v10-duchi09a:ctx13", "name": "Update: l-infinity regularization via its dual (l1-ball projection), Eqs. (22)-(25) (Section 5.4)", "statement": "Next we consider a regularizer that has received less attention, the $\\ell_{\\infty}$ norm of w. On its own this regularizer cannot offer a strong guarantee against overfitting, because many of the weights of w may go unpenalized. There are, however, settings in which one wants to treat blocks of variables as a group, as in $\\ell_{1}/ \\ell_{\\infty}$ regularization. We postpone the discussion of mixed norms once more and concentrate on the $\\ell_{\\infty}$ norm alone, since it is a building block. Concretely, we want an efficient solution of the problem\n\n$$\n\\operatorname*{minimize}_{\\boldsymbol{w}}\\frac{1}{2}\\|\\boldsymbol{w}-\\boldsymbol{v}\\|^{2}+\\tilde{\\lambda}\\|\\boldsymbol{w}\\|_{\\infty}\\textrm{.}\\tag{22}\n$$\n\nAn efficient algorithm for the minimizer of Eq. (22) could be derived from properties of the subgradient set of $\\| \\boldsymbol{w}\\|_{\\infty}$. The dual form of Eq. (22), however, has a well-known solution. Since the conjugate of a quadratic function is quadratic and the conjugate of the $\\ell_{\\infty}$ norm is the $\\ell_{1}$ barrier function, the dual of the problem in Eq. (22) is immediately seen to be\n\n$$\n\\operatorname*{maximize}_{\\alpha}-\\frac{1}{2}\\left\\|\\alpha-\\pmb{v}\\right\\|_{2}^{2}\\mathrm{s . t .}\\left\\|\\pmb{\\alpha}\\right\\|_{1}\\leq\\tilde{\\lambda}\\mathrm{~.~}\\tag{23}\n$$\n\nIn addition, the dual variables $\\pmb{\\alpha}$ are related to the primal by ${\\pmb{\\alpha}}={\\pmb{v}}-{\\pmb{w}}$. Solving the dual form in Eq. (23) therefore readily gives a solution of Eq. (22). Problem Eq. (23) is the same as Euclidean projection onto the $\\ell_{1}$ ball, which many authors have studied. The solution summarized here follows recent work of Duchi et al. (2008). The maximizer of Eq. (23), written $\\alpha^{\\star}$, has the form\n\n$$\n\\alpha_{j}^{\\star}=\\mathrm{sign}(v_{j})\\left[|v_{j}| -\\theta\\right]_{+}\\ ,\\tag{24}\n$$\n\nwith θ a non-negative scalar. A linear-time algorithm for computing θ is given by Duchi et al. (2008). We therefore do not analyze that algorithm and instead concentrate on the core properties that affect the solution of the problem in Eq. (22). Computing θ requires finding a pivot element of v, namely the $\\rho^{t h}$ order statistic $v_{(\\rho)}$ (with $v_{(1)}$ the entry of v of largest magnitude), characterized as follows: $v_{(\\rho)}$ is the element of v of smallest magnitude for which\n\n$$\n\\sum_{j: |v_{j}| > |v_{(\\rho)}|}\\bigl(|v_{j}| - |v_{(\\rho)}|\\bigr)<\\tilde{\\lambda}\\ .\n$$\n\nWhen every element of v (with an extra element equal to 0 appended to take care of the smallest entry) satisfies this requirement, θ = 0 is the optimal choice. In the remaining case,\n\n$$\n\\theta=\\frac{1}{\\rho}\\left(\\sum_{j: |v_{j}| > |v_{(\\rho)}|}|v_{j}| -\\tilde{\\lambda}\\right).\n$$\n\nSo θ = 0 is optimal exactly when $\\sum_{j = 1}^{n}| v_{j}| \\leq \\tilde{\\lambda}$ (not by coincidence, this is just the subgradient optimality condition for the zero vector in Eq. (22)).\n\nCombining the linear relation $\\pmb{\\alpha}= \\pmb{v}- \\pmb{w}\\Rightarrow \\pmb{w}= \\pmb{v}- \\pmb{\\alpha}$ with the dual solution provided by Eq. (24), the solution of Eq. (22) is\n\n$$\nw_{t+1,j}=\\mathrm{sign}\\Big(w_{t+\\frac{1}{2},j}\\Big)\\operatorname*{min}\\left\\{\\Big|w_{t+\\frac{1}{2},j}\\Big|\\ ,\\ \\theta\\right\\}\\ .\\tag{25}\n$$\n\nAs noted above, $\\theta = 0$ if and only if $\\| \\pmb{w}_{t + \\frac{1}{2}}\\|_{1}\\leq \\tilde{\\lambda}$, and otherwise $\\theta > 0$ and θ can be computed in $O(n)$ steps. Put in words, the components of ${\\pmb w}_{t + 1}$ are obtained by capping every component of ${\\pmb w}_{t}$ at θ, with θ equal to zero when the 1-norm of $w_{t + \\frac{1}{2}}$ is below $\\tilde{\\lambda}$. This property mirrors, through duality, the $\\ell_{2}$-regularized update, which gives a zero weight vector when the 2-norm (which is self-dual) of v is below $\\tilde{\\lambda}$. These properties can be used with mixed-norm regularization to obtain sparse solutions for complex prediction problems; this is described later, and preliminary results are given in Sec. 7. Before turning to it, we present one further norm-related regularizer."}, {"id": "v10-duchi09a:ctx14", "name": "Eq. (36), from the proof of Theorem 6", "statement": "Proof of Theorem 6 When $\\| \\partial f \\|$ and $\\| \\partial r \\|$ are bounded by G, Lemma 1 gives at once\n\n$$\nf_{t}(\\boldsymbol{w}_{t})-f_{t}(\\boldsymbol{w}^{\\star})+r(\\boldsymbol{w}_{t+1})-r(\\boldsymbol{w}^{\\star})\\leq\\frac{1}{2\\eta_{t}}\\left(\\|\\boldsymbol{w}_{t}-\\boldsymbol{w}^{\\star}\\|^{2}-\\|\\boldsymbol{w}_{t+1}-\\boldsymbol{w}^{\\star}\\|^{2}\\right)+\\frac{7}{2}G^{2}\\eta_{t}.\\tag{36}\n$$"}], "lean": "import Mathlib\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]\n\ndef HasSubgradientAt (f : E → ℝ) (g x : E) : Prop :=\n ∀ y, f y ≥ f x + @inner ℝ _ _ g (y - x)\n\ndef IsFoBoSRun (f r : E → ℝ) (w gf gr : ℕ → E) (η ηhalf : ℕ → ℝ) : Prop :=\n (∀ t, HasSubgradientAt f (gf t) (w t)) ∧\n (∀ t, HasSubgradientAt r (gr t) (w t)) ∧\n (∀ t, w (t + 1) = w t - η t • gf t - ηhalf t • gr (t + 1))\n\ndef IsFoBoSOnlineRun (f : ℕ → E → ℝ) (r : E → ℝ) (w gf gr : ℕ → E) (η : ℕ → ℝ) :\n Prop :=\n (∀ t, HasSubgradientAt (f t) (gf t) (w t)) ∧\n (∀ t, HasSubgradientAt r (gr t) (w t)) ∧\n (∀ t, w (t + 1) = w t - η t • gf t - η t • gr (t + 1))\n\ndef Regret (f : ℕ → E → ℝ) (r : E → ℝ) (w : ℕ → E) (wstar : E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 1 T, (f t (w t) + r (w t) - (f t wstar + r wstar))\n\ndef sqL2 {n : ℕ} (x : Fin n → ℝ) : ℝ := ∑ i, (x i) ^ 2\n\nnoncomputable def linftyNorm {n : ℕ} (x : Fin n → ℝ) : ℝ := ⨆ i, |x i|\n\ndef l1Norm {n : ℕ} (x : Fin n → ℝ) : ℝ := ∑ i, |x i|\n\nnoncomputable def l2Norm {n : ℕ} (x : Fin n → ℝ) : ℝ := Real.sqrt (sqL2 x)\n\ndef IsProxNorm {n : ℕ} (N : (Fin n → ℝ) → ℝ) (lam : ℝ) (x xm : Fin n → ℝ) : Prop :=\n IsMinOn (fun u => sqL2 (u - x) / 2 + lam * N u) Set.univ xm\n\ntheorem theorem6\n (f : ℕ → E → ℝ) (r : E → ℝ) (w gf gr : ℕ → E) (η : ℕ → ℝ) (D G c : ℝ)\n (wstar : E)\n (hconvf : ∀ t, ConvexOn ℝ Set.univ (f t)) (hconvr : ConvexOn ℝ Set.univ r)\n (hfnn : ∀ t x, 0 ≤ f t x) (hrnn : ∀ x, 0 ≤ r x)\n (hrun : IsFoBoSOnlineRun f r w gf gr η)\n (hD : ∀ t, 1 ≤ t → ‖w t - wstar‖ ≤ D) (hDnn : 0 ≤ D)\n (hGf : ∀ t x g, HasSubgradientAt (f t) g x → ‖g‖ ≤ G)\n (hGr : ∀ x g, HasSubgradientAt r g x → ‖g‖ ≤ G) (hGnn : 0 ≤ G)\n (hc : 0 < c)\n (hη : ∀ t, 1 ≤ t → η t = c / Real.sqrt t)\n (T : ℕ) (hT : 0 < T) :\n Regret f r w wstar T ≤ 2 * G * D + (D ^ 2 / (2 * c) + 7 * G ^ 2 * c) * Real.sqrt T := by\n sorry\n\ntheorem theorem8\n (f : ℕ → E → ℝ) (r : E → ℝ) (w gf gr : ℕ → E) (η : ℕ → ℝ) (D G H : ℝ)\n (wstar : E)\n (hconvf : ∀ t, ConvexOn ℝ Set.univ (f t)) (hconvr : ConvexOn ℝ Set.univ r)\n (hfnn : ∀ t x, 0 ≤ f t x) (hrnn : ∀ x, 0 ≤ r x)\n (hrun : IsFoBoSOnlineRun f r w gf gr η)\n (hD : ∀ t, 1 ≤ t → ‖w t - wstar‖ ≤ D) (hDnn : 0 ≤ D)\n (hGf : ∀ t x g, HasSubgradientAt (f t) g x → ‖g‖ ≤ G)\n (hGr : ∀ x g, HasSubgradientAt r g x → ‖g‖ ≤ G) (hGnn : 0 ≤ G)\n (hH : 0 < H)\n (hsc : ∀ t, StrongConvexOn (Metric.closedBall wstar D) H (fun x => f t x + r x))\n (hη : ∀ t, 1 ≤ t → η t = 1 / (H * t))\n (T : ℕ) (hT : 0 < T) :\n Regret f r w wstar T\n ≤ 2 * G * D + H * D ^ 2 + (7 * G ^ 2 / (2 * H)) * (1 + Real.log T) := by\n sorry\n\ntheorem proposition11\n {n : ℕ} (T : ℕ) (hT : 0 < T) (w0 wstar : Fin n → ℝ) (w : ℕ → Fin n → ℝ)\n (lam : ℕ → ℝ) (hlam : ∀ t ∈ Finset.Icc 1 T, 0 ≤ lam t)\n (hw0 : w 0 = w0)\n (N : (Fin n → ℝ) → ℝ)\n (hN : N = l1Norm ∨ N = l2Norm ∨ N = linftyNorm)\n (hseq : ∀ t ∈ Finset.Icc 1 T, IsProxNorm N (lam t) (w (t - 1)) (w t))\n (hbatch : IsProxNorm N (∑ t ∈ Finset.Icc 1 T, lam t) w0 wstar) :\n w T = wstar := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]\n\ndef HasSubgradientAt (f : E → ℝ) (g x : E) : Prop :=\n ∀ y, f y ≥ f x + @inner ℝ _ _ g (y - x)\n\ndef IsFoBoSRun (f r : E → ℝ) (w gf gr : ℕ → E) (η ηhalf : ℕ → ℝ) : Prop :=\n (∀ t, HasSubgradientAt f (gf t) (w t)) ∧\n (∀ t, HasSubgradientAt r (gr t) (w t)) ∧\n (∀ t, w (t + 1) = w t - η t • gf t - ηhalf t • gr (t + 1))\n\ndef IsFoBoSOnlineRun (f : ℕ → E → ℝ) (r : E → ℝ) (w gf gr : ℕ → E) (η : ℕ → ℝ) :\n Prop :=\n (∀ t, HasSubgradientAt (f t) (gf t) (w t)) ∧\n (∀ t, HasSubgradientAt r (gr t) (w t)) ∧\n (∀ t, w (t + 1) = w t - η t • gf t - η t • gr (t + 1))\n\ndef Regret (f : ℕ → E → ℝ) (r : E → ℝ) (w : ℕ → E) (wstar : E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 1 T, (f t (w t) + r (w t) - (f t wstar + r wstar))\n\ndef sqL2 {n : ℕ} (x : Fin n → ℝ) : ℝ := ∑ i, (x i) ^ 2\n\nnoncomputable def linftyNorm {n : ℕ} (x : Fin n → ℝ) : ℝ := ⨆ i, |x i|\n\ndef l1Norm {n : ℕ} (x : Fin n → ℝ) : ℝ := ∑ i, |x i|\n\nnoncomputable def l2Norm {n : ℕ} (x : Fin n → ℝ) : ℝ := Real.sqrt (sqL2 x)\n\ndef IsProxNorm {n : ℕ} (N : (Fin n → ℝ) → ℝ) (lam : ℝ) (x xm : Fin n → ℝ) : Prop :=\n IsMinOn (fun u => sqL2 (u - x) / 2 + lam * N u) Set.univ xm\n\n\n/-! ### Auxiliary machinery (helper lemmas, proved from Mathlib) -/\n\nsection AuxFoBoS\nvariable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]\n\n/-- The subgradient inequality, rewritten as `φ x - φ y ≤ ⟪g, x - y⟫`. -/\nlemma subgrad_bound {φ : F → ℝ} {g x : F} (h : HasSubgradientAt φ g x) (y : F) :\n φ x - φ y ≤ inner ℝ g (x - y) := by\n have h1 := h y\n have h2 : inner ℝ g (y - x) = -(inner ℝ g (x - y) : ℝ) := by simp [inner_sub_right]\n rw [h2] at h1\n linarith\n\n/-- The sum of subgradients is a subgradient of the sum. -/\nlemma subgrad_add {φ ψ : F → ℝ} {g h x : F} (hφ : HasSubgradientAt φ g x)\n (hψ : HasSubgradientAt ψ h x) : HasSubgradientAt (fun z => φ z + ψ z) (g + h) x := by\n intro y\n have h1 := hφ y\n have h2 := hψ y\n have h3 : (inner ℝ (g + h) (y - x) : ℝ) = inner ℝ g (y-x) + inner ℝ h (y-x) := by\n rw [inner_add_left]\n show φ y + ψ y ≥ (φ x + ψ x) + (inner ℝ (g + h) (y - x) : ℝ)\n rw [h3]\n simp only [ge_iff_le] at h1 h2\n linarith\n\nlemma core_id_aux (d a b : F) (η : ℝ) (hη : η ≠ 0) :\n (inner ℝ a d : ℝ) + inner ℝ b (d - η • (a + b))\n = (1/(2*η)) * (‖d‖^2 - ‖d - η • (a+b)‖^2) + (η/2) * (‖a‖^2 - ‖b‖^2) := by\n rw [norm_sub_sq_real, norm_smul, mul_pow, norm_add_sq_real]\n simp only [inner_sub_right, real_inner_smul_right, inner_add_right,\n real_inner_self_eq_norm_sq, Real.norm_eq_abs, sq_abs]\n rw [real_inner_comm b a, real_inner_comm a d, real_inner_comm b d]\n field_simp\n ring\n\n/-- The exact algebraic identity underlying the analysis of a forward-backward splitting step. -/\nlemma core_id (wt wt1 wst a b : F) (η : ℝ) (hη : η ≠ 0)\n (hupd : wt1 = wt - η • a - η • b) :\n (inner ℝ a (wt - wst) : ℝ) + inner ℝ b (wt1 - wst)\n = (1/(2*η)) * (‖wt - wst‖^2 - ‖wt1 - wst‖^2) + (η/2) * (‖a‖^2 - ‖b‖^2) := by\n have hd : wt1 - wst = (wt - wst) - η • (a + b) := by rw [hupd, smul_add]; abel\n rw [hd]\n exact core_id_aux (wt - wst) a b η hη\n\n/-- Strong convexity upgrades the subgradient inequality by a quadratic term. -/\nlemma strongconvex_subgrad {φ : F → ℝ} {s : Set F} {H : ℝ} (hH : 0 ≤ H)\n (hsc : StrongConvexOn s H φ) {g x : F} (hg : HasSubgradientAt φ g x) (hx : x ∈ s)\n {y : F} (hy : y ∈ s) :\n φ x - φ y ≤ (inner ℝ g (x - y) : ℝ) - (H/2) * ‖x - y‖^2 := by\n set K : ℝ := (H/2) * ‖x - y‖^2 with hK\n have hK0 : 0 ≤ K := by rw [hK]; positivity\n have main : ∀ l : ℝ, 0 < l → l ≤ 1 → φ x - φ y ≤ (inner ℝ g (x - y) : ℝ) - (1 - l) * K := by\n intro l hl hl1\n have h0 : (0:ℝ) ≤ 1 - l := by linarith\n have hcv := hsc.2 hx hy h0 hl.le (by ring)\n have hpt : (1-l) • x + l • y - x = l • (y - x) := by\n rw [smul_sub, sub_smul, one_smul]; abel\n have hsub := hg ((1-l) • x + l • y)\n rw [hpt] at hsub\n have hin : (inner ℝ g (l • (y - x)) : ℝ) = - (l * (inner ℝ g (x - y) : ℝ)) := by\n rw [real_inner_smul_right]\n have h9 : (inner ℝ g (y - x) : ℝ) = -(inner ℝ g (x - y) : ℝ) := by simp [inner_sub_right]\n rw [h9]; ring\n rw [hin] at hsub\n simp only [smul_eq_mul] at hcv\n rw [hK]\n nlinarith [hcv, hsub]\n apply le_of_forall_pos_le_add\n intro ε hε\n have hlt : (0:ℝ) < ε / (K + 1) := by positivity\n set l : ℝ := min 1 (ε / (K+1)) with hlv\n have hl0 : 0 < l := lt_min one_pos hlt\n have hl1 : l ≤ 1 := min_le_left _ _\n have hle : l ≤ ε / (K+1) := min_le_right _ _\n have hm := main l hl0 hl1\n have hKε : l * K ≤ ε := by\n have h1 : l * K ≤ (ε/(K+1)) * K := mul_le_mul_of_nonneg_right hle hK0\n have h2 : (ε/(K+1)) * K ≤ ε := by\n rw [div_mul_eq_mul_div, div_le_iff₀ (by linarith)]\n nlinarith\n linarith\n nlinarith\n\nend AuxFoBoS\n\nlemma sum_Icc_one_eq_range (g : ℕ → ℝ) (T : ℕ) :\n ∑ t ∈ Finset.Icc 1 T, g t = ∑ i ∈ Finset.range T, g (i+1) := by\n induction T with\n | zero => simp\n | succ n ih => rw [Finset.sum_Icc_succ_top (by omega), Finset.sum_range_succ, ih]\n\nlemma tele (u : ℕ → ℝ) (T : ℕ) :\n ∑ t ∈ Finset.Icc 1 T, (u t - u (t+1)) = u 1 - u (T+1) := by\n induction T with\n | zero => simp\n | succ n ih => rw [Finset.sum_Icc_succ_top (by omega), ih]; ring\n\n/-- Abel-summation bound for a nonincreasing-in-value / nondecreasing-in-weight telescoping sum. -/\nlemma abel_bound (a b : ℕ → ℝ) (D2 : ℝ)\n (haD : ∀ t, 1 ≤ t → a t ≤ D2) (hb0 : ∀ t, 0 ≤ b t) (hbm : Monotone b) :\n ∀ T, 1 ≤ T → ∑ t ∈ Finset.Icc 1 T, b t * (a t - a (t+1)) ≤ D2 * b T - b T * a (T+1) := by\n intro T hT\n induction T, hT using Nat.le_induction with\n | base =>\n simp only [Finset.Icc_self, Finset.sum_singleton]\n have h1 : a 1 ≤ D2 := haD 1 le_rfl\n have h2 : 0 ≤ b 1 := hb0 1\n nlinarith\n | succ n hn ih =>\n rw [Finset.sum_Icc_succ_top (by omega)]\n have hbn : b n ≤ b (n+1) := hbm (Nat.le_succ n)\n have h1 : a (n+1) ≤ D2 := haD _ (by omega)\n nlinarith [ih]\n\nlemma sum_inv_sqrt_le (T : ℕ) :\n ∑ t ∈ Finset.Icc 1 T, (1:ℝ)/Real.sqrt t ≤ 2 * Real.sqrt T := by\n induction T with\n | zero => simp\n | succ n ih =>\n rw [Finset.sum_Icc_succ_top (by omega)]\n have hs : Real.sqrt n ≤ Real.sqrt (n+1) := by apply Real.sqrt_le_sqrt; linarith\n have hpos : (0:ℝ) < Real.sqrt (n+1) := by apply Real.sqrt_pos.mpr; positivity\n have key : (1:ℝ)/Real.sqrt ((n:ℝ)+1) ≤ 2 * Real.sqrt ((n:ℝ)+1) - 2 * Real.sqrt n := by\n rw [div_le_iff₀ hpos]\n have h1 : Real.sqrt ((n:ℝ)+1) * Real.sqrt ((n:ℝ)+1) = (n:ℝ)+1 :=\n Real.mul_self_sqrt (by positivity)\n have h2 : Real.sqrt (n:ℝ) * Real.sqrt (n:ℝ) = (n:ℝ) :=\n Real.mul_self_sqrt (by positivity)\n nlinarith [hs, Real.sqrt_nonneg ((n:ℝ)), Real.sqrt_nonneg ((n:ℝ)+1)]\n push_cast\n push_cast at ih\n linarith\n\nlemma sum_inv_le_log (T : ℕ) :\n ∑ t ∈ Finset.Icc 1 T, (1:ℝ)/t ≤ 1 + Real.log T := by\n have h1 : ∑ t ∈ Finset.Icc 1 T, (1:ℝ)/t = ((harmonic T : ℚ) : ℝ) := by\n rw [sum_Icc_one_eq_range]\n simp [harmonic, Rat.cast_sum]\n rw [h1]\n exact harmonic_le_one_add_log T\n\ntheorem theorem6\n (f : ℕ → E → ℝ) (r : E → ℝ) (w gf gr : ℕ → E) (η : ℕ → ℝ) (D G c : ℝ)\n (wstar : E)\n (hconvf : ∀ t, ConvexOn ℝ Set.univ (f t)) (hconvr : ConvexOn ℝ Set.univ r)\n (hfnn : ∀ t x, 0 ≤ f t x) (hrnn : ∀ x, 0 ≤ r x)\n (hrun : IsFoBoSOnlineRun f r w gf gr η)\n (hD : ∀ t, 1 ≤ t → ‖w t - wstar‖ ≤ D) (hDnn : 0 ≤ D)\n (hGf : ∀ t x g, HasSubgradientAt (f t) g x → ‖g‖ ≤ G)\n (hGr : ∀ x g, HasSubgradientAt r g x → ‖g‖ ≤ G) (hGnn : 0 ≤ G)\n (hc : 0 < c)\n (hη : ∀ t, 1 ≤ t → η t = c / Real.sqrt t)\n (T : ℕ) (hT : 0 < T) :\n Regret f r w wstar T ≤ 2 * G * D + (D ^ 2 / (2 * c) + 7 * G ^ 2 * c) * Real.sqrt T := by\n obtain ⟨hsf, hsr, hupd⟩ := hrun\n set A : ℕ → ℝ := fun t => ‖w t - wstar‖^2 with hA\n set B : ℕ → ℝ := fun t => Real.sqrt t / (2*c) with hB\n -- per-step bound\n have hstep : ∀ t ∈ Finset.Icc 1 T,\n f t (w t) - f t wstar + (r (w (t+1)) - r wstar)\n ≤ B t * (A t - A (t+1)) + (c / Real.sqrt t / 2) * G^2 := by\n intro t ht\n rw [Finset.mem_Icc] at ht\n have h1 : 1 ≤ t := ht.1\n have hst : (0:ℝ) < Real.sqrt t := by\n apply Real.sqrt_pos.mpr\n exact_mod_cast h1\n have hηt : η t = c / Real.sqrt t := hη t h1\n have hηpos : 0 < η t := by rw [hηt]; positivity\n have hkey := core_id (w t) (w (t+1)) wstar (gf t) (gr (t+1)) (η t) (ne_of_gt hηpos) (hupd t)\n have hf1 : f t (w t) - f t wstar ≤ inner ℝ (gf t) (w t - wstar) := subgrad_bound (hsf t) wstar\n have hr1 : r (w (t+1)) - r wstar ≤ inner ℝ (gr (t+1)) (w (t+1) - wstar) :=\n subgrad_bound (hsr (t+1)) wstar\n have hG1 : ‖gf t‖ ≤ G := hGf t (w t) (gf t) (hsf t)\n have hBeq : (1:ℝ)/(2*η t) = B t := by\n rw [hηt, hB]\n field_simp\n have hηeq : η t / 2 = c / Real.sqrt t / 2 := by rw [hηt]\n have hsq : ‖gf t‖^2 ≤ G^2 := by nlinarith [norm_nonneg (gf t)]\n have hsq2 : (0:ℝ) ≤ ‖gr (t+1)‖^2 := sq_nonneg _\n have : (η t / 2) * (‖gf t‖^2 - ‖gr (t+1)‖^2) ≤ (c / Real.sqrt t / 2) * G^2 := by\n rw [← hηeq]\n have hh : (0:ℝ) ≤ η t / 2 := by linarith\n nlinarith\n rw [hBeq] at hkey\n have hAeq : A t = ‖w t - wstar‖^2 := rfl\n have hAeq1 : A (t+1) = ‖w (t+1) - wstar‖^2 := rfl\n rw [hAeq, hAeq1]\n linarith [hkey, hf1, hr1, this]\n -- regret decomposition\n have hreg : Regret f r w wstar T\n = (∑ t ∈ Finset.Icc 1 T, (f t (w t) - f t wstar + (r (w (t+1)) - r wstar)))\n + (r (w 1) - r (w (T+1))) := by\n rw [Regret, ← tele (fun t => r (w t)) T, ← Finset.sum_add_distrib]\n apply Finset.sum_congr rfl\n intro t _\n ring\n -- bound the main sum\n have hsum : (∑ t ∈ Finset.Icc 1 T, (f t (w t) - f t wstar + (r (w (t+1)) - r wstar)))\n ≤ ∑ t ∈ Finset.Icc 1 T, (B t * (A t - A (t+1)) + (c / Real.sqrt t / 2) * G^2) :=\n Finset.sum_le_sum hstep\n have hsplit : ∑ t ∈ Finset.Icc 1 T, (B t * (A t - A (t+1)) + (c / Real.sqrt t / 2) * G^2)\n = (∑ t ∈ Finset.Icc 1 T, B t * (A t - A (t+1)))\n + ∑ t ∈ Finset.Icc 1 T, (c / Real.sqrt t / 2) * G^2 := Finset.sum_add_distrib\n rw [hsplit] at hsum\n -- the harmonic-type sum\n have hsum2 : (∑ t ∈ Finset.Icc 1 T, (c / Real.sqrt t / 2) * G^2) ≤ c * G^2 * Real.sqrt T := by\n have he : (∑ t ∈ Finset.Icc 1 T, (c / Real.sqrt t / 2) * G^2)\n = (c * G^2/2) * ∑ t ∈ Finset.Icc 1 T, (1:ℝ)/Real.sqrt t := by\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro t _\n ring\n rw [he]\n have h1 := sum_inv_sqrt_le T\n have hnn : (0:ℝ) ≤ c * G^2/2 := by positivity\n calc (c * G^2/2) * ∑ t ∈ Finset.Icc 1 T, (1:ℝ)/Real.sqrt t\n ≤ (c * G^2/2) * (2 * Real.sqrt T) := by exact mul_le_mul_of_nonneg_left h1 hnn\n _ = c * G^2 * Real.sqrt T := by ring\n -- the Abel sum\n have hB0 : ∀ t, 0 ≤ B t := by\n intro t; rw [hB]; positivity\n have hBm : Monotone B := by\n intro x y hxy\n simp only [hB]\n apply div_le_div_of_nonneg_right ?_ (by positivity)\n exact Real.sqrt_le_sqrt (by exact_mod_cast hxy)\n have hAD : ∀ t, 1 ≤ t → A t ≤ D^2 := by\n intro t ht\n have := hD t ht\n have h0 := norm_nonneg (w t - wstar)\n simp only [hA]\n nlinarith\n have habel := abel_bound A B (D^2) hAD hB0 hBm T hT\n have hA0 : (0:ℝ) ≤ A (T+1) := by simp only [hA]; positivity\n have hBT : (0:ℝ) ≤ B T := hB0 T\n have hsum3 : (∑ t ∈ Finset.Icc 1 T, B t * (A t - A (t+1))) ≤ D^2 * (Real.sqrt T/(2*c)) := by\n have : B T = Real.sqrt T/(2*c) := rfl\n nlinarith [habel]\n -- last term\n have hlast : r (w 1) - r (w (T+1)) ≤ 2*G*D := by\n have h1 : r (w 1) - r (w (T+1)) ≤ inner ℝ (gr 1) (w 1 - w (T+1)) :=\n subgrad_bound (hsr 1) (w (T+1))\n have h2 : (inner ℝ (gr 1) (w 1 - w (T+1)) : ℝ) ≤ ‖gr 1‖ * ‖w 1 - w (T+1)‖ :=\n real_inner_le_norm _ _\n have h3 : ‖gr 1‖ ≤ G := hGr (w 1) (gr 1) (hsr 1)\n have h4 : ‖w 1 - w (T+1)‖ ≤ ‖w 1 - wstar‖ + ‖w (T+1) - wstar‖ := by\n have he : w 1 - w (T+1) = (w 1 - wstar) - (w (T+1) - wstar) := by abel\n rw [he]; exact norm_sub_le _ _\n have h5 : ‖w 1 - wstar‖ ≤ D := hD 1 le_rfl\n have h6 : ‖w (T+1) - wstar‖ ≤ D := hD (T+1) (by omega)\n nlinarith [norm_nonneg (w 1 - w (T+1)), norm_nonneg (gr 1)]\n rw [hreg]\n have hfin : D^2 * (Real.sqrt T/(2*c)) + c * G^2 * Real.sqrt T\n ≤ (D ^ 2 / (2 * c) + 7 * G ^ 2 * c) * Real.sqrt T := by\n have hs : (0:ℝ) ≤ Real.sqrt T := Real.sqrt_nonneg _\n have : D^2 * (Real.sqrt T/(2*c)) = D^2/(2*c) * Real.sqrt T := by ring\n rw [this]\n have h6 : (0:ℝ) ≤ 6 * G^2 * c * Real.sqrt T := by positivity\n nlinarith [h6]\n linarith\n\n\ntheorem theorem8\n (f : ℕ → E → ℝ) (r : E → ℝ) (w gf gr : ℕ → E) (η : ℕ → ℝ) (D G H : ℝ)\n (wstar : E)\n (hconvf : ∀ t, ConvexOn ℝ Set.univ (f t)) (hconvr : ConvexOn ℝ Set.univ r)\n (hfnn : ∀ t x, 0 ≤ f t x) (hrnn : ∀ x, 0 ≤ r x)\n (hrun : IsFoBoSOnlineRun f r w gf gr η)\n (hD : ∀ t, 1 ≤ t → ‖w t - wstar‖ ≤ D) (hDnn : 0 ≤ D)\n (hGf : ∀ t x g, HasSubgradientAt (f t) g x → ‖g‖ ≤ G)\n (hGr : ∀ x g, HasSubgradientAt r g x → ‖g‖ ≤ G) (hGnn : 0 ≤ G)\n (hH : 0 < H)\n (hsc : ∀ t, StrongConvexOn (Metric.closedBall wstar D) H (fun x => f t x + r x))\n (hη : ∀ t, 1 ≤ t → η t = 1 / (H * t))\n (T : ℕ) (hT : 0 < T) :\n Regret f r w wstar T\n ≤ 2 * G * D + H * D ^ 2 + (7 * G ^ 2 / (2 * H)) * (1 + Real.log T) := by\n obtain ⟨hsf, hsr, hupd⟩ := hrun\n set A : ℕ → ℝ := fun t => ‖w t - wstar‖^2 with hA\n set u : ℕ → ℝ := fun t => (inner ℝ (gr t) (w t - wstar) : ℝ) with hu\n set v : ℕ → ℝ := fun t => (H/2) * ((t:ℝ) - 1) * A t with hv\n have hwmem : ∀ t, 1 ≤ t → w t ∈ Metric.closedBall wstar D := by\n intro t ht\n rw [Metric.mem_closedBall, dist_eq_norm]\n exact hD t ht\n have hwsmem : wstar ∈ Metric.closedBall wstar D := by\n rw [Metric.mem_closedBall]; simpa using hDnn\n have hstep : ∀ t ∈ Finset.Icc 1 T,\n f t (w t) + r (w t) - (f t wstar + r wstar)\n ≤ (u t - u (t+1)) + (v t - v (t+1)) + (1/(H*(t:ℝ))/2)*G^2 := by\n intro t ht\n rw [Finset.mem_Icc] at ht\n have h1 : 1 ≤ t := ht.1\n have htR : (1:ℝ) ≤ (t:ℝ) := by exact_mod_cast h1\n have hηt : η t = 1/(H*(t:ℝ)) := hη t h1\n have hηpos : 0 < η t := by rw [hηt]; positivity\n have hsg : HasSubgradientAt (fun z => f t z + r z) (gf t + gr t) (w t) :=\n subgrad_add (hsf t) (hsr t)\n have hscb := strongconvex_subgrad hH.le (hsc t) hsg (hwmem t h1) hwsmem\n simp only [] at hscb\n have hinadd : (inner ℝ (gf t + gr t) (w t - wstar) : ℝ)\n = (inner ℝ (gf t) (w t - wstar) : ℝ) + u t := by\n rw [inner_add_left]\n rw [hinadd] at hscb\n have hkey := core_id (w t) (w (t+1)) wstar (gf t) (gr (t+1)) (η t) (ne_of_gt hηpos) (hupd t)\n have hcoef : (1:ℝ)/(2*η t) = H*(t:ℝ)/2 := by\n rw [hηt]; field_simp\n rw [hcoef] at hkey\n have hG1 : ‖gf t‖ ≤ G := hGf t (w t) (gf t) (hsf t)\n have hsq : ‖gf t‖^2 ≤ G^2 := by nlinarith [norm_nonneg (gf t)]\n have hsq2 : (0:ℝ) ≤ ‖gr (t+1)‖^2 := sq_nonneg _\n have hlast : (η t / 2) * (‖gf t‖^2 - ‖gr (t+1)‖^2) ≤ (1/(H*(t:ℝ))/2)*G^2 := by\n have hh : (0:ℝ) ≤ η t / 2 := by linarith\n have : (1:ℝ)/(H*(t:ℝ))/2 = η t / 2 := by rw [hηt]\n rw [this]\n nlinarith\n have hvv : v t - v (t+1) = (H*(t:ℝ)/2) * (A t - A (t+1)) - (H/2) * A t := by\n simp only [hv]\n push_cast\n ring\n have hAt : A t = ‖w t - wstar‖^2 := rfl\n have hAt1 : A (t+1) = ‖w (t+1) - wstar‖^2 := rfl\n have hut1 : u (t+1) = (inner ℝ (gr (t+1)) (w (t+1) - wstar) : ℝ) := rfl\n rw [hAt, hAt1] at hvv\n rw [hut1]\n linarith [hkey, hscb, hlast, hvv]\n have hsum : Regret f r w wstar T\n ≤ ∑ t ∈ Finset.Icc 1 T, ((u t - u (t+1)) + (v t - v (t+1)) + (1/(H*(t:ℝ))/2)*G^2) :=\n Finset.sum_le_sum hstep\n have hsplit : ∑ t ∈ Finset.Icc 1 T, ((u t - u (t+1)) + (v t - v (t+1)) + (1/(H*(t:ℝ))/2)*G^2)\n = (∑ t ∈ Finset.Icc 1 T, (u t - u (t+1))) + (∑ t ∈ Finset.Icc 1 T, (v t - v (t+1)))\n + (∑ t ∈ Finset.Icc 1 T, (1/(H*(t:ℝ))/2)*G^2) := by\n rw [Finset.sum_add_distrib, Finset.sum_add_distrib]\n rw [hsplit, tele u T, tele v T] at hsum\n -- bound u 1 - u (T+1)\n have hu1 : u 1 - u (T+1) ≤ 2*G*D := by\n have e1 : u 1 ≤ ‖gr 1‖ * ‖w 1 - wstar‖ := real_inner_le_norm _ _\n have e2 : |u (T+1)| ≤ ‖gr (T+1)‖ * ‖w (T+1) - wstar‖ := abs_real_inner_le_norm _ _\n have e3 : ‖gr 1‖ ≤ G := hGr (w 1) (gr 1) (hsr 1)\n have e4 : ‖gr (T+1)‖ ≤ G := hGr (w (T+1)) (gr (T+1)) (hsr (T+1))\n have e5 : ‖w 1 - wstar‖ ≤ D := hD 1 le_rfl\n have e6 : ‖w (T+1) - wstar‖ ≤ D := hD (T+1) (by omega)\n have e7 : -u (T+1) ≤ |u (T+1)| := neg_le_abs _\n nlinarith [norm_nonneg (gr 1), norm_nonneg (gr (T+1)), norm_nonneg (w 1 - wstar),\n norm_nonneg (w (T+1) - wstar)]\n -- bound v 1 - v (T+1)\n have hv1 : v 1 - v (T+1) ≤ 0 := by\n have e1 : v 1 = 0 := by simp [hv]\n have e2 : (0:ℝ) ≤ v (T+1) := by\n have he : v (T+1) = (H/2) * (T:ℝ) * ‖w (T+1) - wstar‖^2 := by\n simp only [hv, hA]; push_cast; ring\n rw [he]\n exact mul_nonneg (mul_nonneg (by linarith) (Nat.cast_nonneg T)) (sq_nonneg _)\n linarith\n -- bound the log sum\n have hlog : (∑ t ∈ Finset.Icc 1 T, (1/(H*(t:ℝ))/2)*G^2) ≤ (G^2/(2*H))*(1 + Real.log T) := by\n have he : (∑ t ∈ Finset.Icc 1 T, (1/(H*(t:ℝ))/2)*G^2)\n = (G^2/(2*H)) * ∑ t ∈ Finset.Icc 1 T, (1:ℝ)/t := by\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro t ht\n rw [Finset.mem_Icc] at ht\n have hne : (t:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (by omega)\n field_simp\n rw [he]\n have h1 := sum_inv_le_log T\n have hnn : (0:ℝ) ≤ G^2/(2*H) := by positivity\n exact mul_le_mul_of_nonneg_left h1 hnn\n have hlogT : (0:ℝ) ≤ Real.log T := Real.log_nonneg (by exact_mod_cast hT)\n have hfin : (G^2/(2*H))*(1 + Real.log T) ≤ (7 * G ^ 2 / (2 * H)) * (1 + Real.log T) := by\n have hnn : (0:ℝ) ≤ 1 + Real.log T := by linarith\n have : G^2/(2*H) ≤ 7 * G^2/(2*H) := by\n apply div_le_div_of_nonneg_right ?_ (by positivity)\n nlinarith [sq_nonneg G]\n exact mul_le_mul_of_nonneg_right this hnn\n have hHD : (0:ℝ) ≤ H * D^2 := by positivity\n linarith\n\n\n/-! ### Machinery for Proposition 11 -/\n\nsection Prox\nvariable {n : ℕ}\n\n/-- Euclidean inner product on `Fin n → ℝ`. -/\ndef dotp (a b : Fin n → ℝ) : ℝ := ∑ i, a i * b i\n\nlemma dotp_comm (a b : Fin n → ℝ) : dotp a b = dotp b a := by\n simp only [dotp]; exact Finset.sum_congr rfl fun i _ => mul_comm _ _\n\nlemma dotp_self (a : Fin n → ℝ) : dotp a a = sqL2 a := by simp only [dotp, sqL2, sq]\n\nlemma dotp_sub_right (a b c : Fin n → ℝ) : dotp a (b - c) = dotp a b - dotp a c := by\n simp only [dotp, Pi.sub_apply, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n\nlemma dotp_neg_right (a b : Fin n → ℝ) : dotp a (-b) = -dotp a b := by\n simp only [dotp, Pi.neg_apply, ← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n\nlemma sqL2_nonneg (x : Fin n → ℝ) : 0 ≤ sqL2 x := by\n apply Finset.sum_nonneg; intro i _; positivity\n\nlemma sqL2_eq_zero {x : Fin n → ℝ} (h : sqL2 x = 0) : x = 0 := by\n funext i\n have := (Finset.sum_eq_zero_iff_of_nonneg (fun i _ => sq_nonneg (x i))).mp h i (Finset.mem_univ i)\n simpa using pow_eq_zero_iff (n := 2) (by norm_num) |>.mp this\n\nlemma sqL2_expand (u z x : Fin n → ℝ) :\n sqL2 (u - x) = sqL2 (u - z) + 2 * dotp (u - z) (z - x) + sqL2 (z - x) := by\n simp only [sqL2, dotp, Pi.sub_apply, Finset.mul_sum, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n\nlemma sqL2_add (a b : Fin n → ℝ) : sqL2 (a + b) = sqL2 a + 2 * dotp a b + sqL2 b := by\n simp only [sqL2, dotp, Pi.add_apply]\n rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n\nlemma sqL2_add_smul (a b : Fin n → ℝ) (s : ℝ) :\n sqL2 (a + s • b) = sqL2 a + 2*s*dotp a b + s^2 * sqL2 b := by\n simp only [sqL2, dotp, Pi.add_apply, Pi.smul_apply, smul_eq_mul]\n rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n\nlemma sqL2_midpoint (a b : Fin n → ℝ) :\n sqL2 ((1/2 : ℝ) • (a + b)) = (sqL2 a + sqL2 b)/2 - sqL2 (a - b)/4 := by\n simp only [sqL2, Pi.smul_apply, Pi.add_apply, Pi.sub_apply, smul_eq_mul]\n rw [← Finset.sum_add_distrib, Finset.sum_div, Finset.sum_div, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n\n/-- Sufficient optimality condition for the prox problem. -/\nlemma prox_suff (N : (Fin n → ℝ) → ℝ) (lam : ℝ) (x z : Fin n → ℝ)\n (h1 : ∀ u, dotp (x - z) u ≤ lam * N u)\n (h2 : dotp (x - z) z = lam * N z) : IsProxNorm N lam x z := by\n rw [IsProxNorm, isMinOn_iff]\n intro u _\n have he := sqL2_expand u z x\n have h3 : dotp (u - z) (z - x) = dotp (x - z) z - dotp (x - z) u := by\n simp only [dotp, Pi.sub_apply, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n have h4 := h1 u\n have h5 := sqL2_nonneg (u - z)\n show sqL2 (z - x) / 2 + lam * N z ≤ sqL2 (u - x) / 2 + lam * N u\n rw [he, h3, h2]\n linarith\n\n/-- The variational inequality satisfied by a prox point. -/\nlemma prox_VI (N : (Fin n → ℝ) → ℝ) (lam : ℝ) (hlam : 0 ≤ lam) (x y : Fin n → ℝ)\n (hconv : ∀ (a b : Fin n → ℝ) (s : ℝ), 0 ≤ s → s ≤ 1 →\n N ((1-s) • a + s • b) ≤ (1-s) * N a + s * N b)\n (h : IsProxNorm N lam x y) :\n ∀ u, dotp (x - y) (u - y) ≤ lam * (N u - N y) := by\n intro u\n rw [IsProxNorm, isMinOn_iff] at h\n set K : ℝ := sqL2 (u - y) / 2 with hK\n have hK0 : 0 ≤ K := by rw [hK]; have := sqL2_nonneg (u - y); linarith\n have main : ∀ s : ℝ, 0 < s → s ≤ 1 →\n dotp (x - y) (u - y) ≤ lam * (N u - N y) + s * K := by\n intro s hs hs1\n have hpt : (1-s) • y + s • u - x = (y - x) + s • (u - y) := by\n funext i; simp only [Pi.sub_apply, Pi.add_apply, Pi.smul_apply, smul_eq_mul]; ring\n have hmin := h ((1-s) • y + s • u) (Set.mem_univ _)\n simp only [] at hmin\n rw [hpt, sqL2_add_smul] at hmin\n have hcv := hconv y u s hs.le hs1\n have hdd : dotp (y - x) (u - y) = - dotp (x - y) (u - y) := by\n simp only [dotp, Pi.sub_apply, ← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n rw [hdd] at hmin\n rw [hK]\n nlinarith [hmin, hcv, sqL2_nonneg (u - y)]\n apply le_of_forall_pos_le_add\n intro ε hε\n have hlt : (0:ℝ) < ε / (K + 1) := by positivity\n set s : ℝ := min 1 (ε / (K+1)) with hsv\n have hs0 : 0 < s := lt_min one_pos hlt\n have hs1 : s ≤ 1 := min_le_left _ _\n have hle : s ≤ ε / (K+1) := min_le_right _ _\n have hm := main s hs0 hs1\n have hKε : s * K ≤ ε := by\n have ha : s * K ≤ (ε/(K+1)) * K := mul_le_mul_of_nonneg_right hle hK0\n have hb : (ε/(K+1)) * K ≤ ε := by\n rw [div_mul_eq_mul_div, div_le_iff₀ (by linarith)]\n nlinarith\n linarith\n linarith\n\nlemma prox_dual {N : (Fin n → ℝ) → ℝ} {lam : ℝ} {x y : Fin n → ℝ} (hlam : 0 ≤ lam)\n (htri : ∀ a b, N (a + b) ≤ N a + N b)\n (hVI : ∀ u, dotp (x - y) (u - y) ≤ lam * (N u - N y)) :\n ∀ v, dotp (x - y) v ≤ lam * N v := by\n intro v\n have h1 := hVI (y + v)\n have h2 : (y + v) - y = v := by abel\n rw [h2] at h1\n have h3 : N (y + v) ≤ N y + N v := htri y v\n nlinarith\n\nlemma prox_align {N : (Fin n → ℝ) → ℝ} {lam : ℝ} {x y : Fin n → ℝ}\n (hN0 : N 0 = 0)\n (hVI : ∀ u, dotp (x - y) (u - y) ≤ lam * (N u - N y))\n (hdual : ∀ v, dotp (x - y) v ≤ lam * N v) :\n dotp (x - y) y = lam * N y := by\n have h1 := hVI 0\n have h2 : (0 : Fin n → ℝ) - y = -y := by abel\n rw [h2, hN0, dotp_neg_right] at h1\n have h3 := hdual y\n linarith\n\nlemma prox_unique {N : (Fin n → ℝ) → ℝ} {lam : ℝ} (hlam : 0 ≤ lam)\n (hmid : ∀ a b : Fin n → ℝ, N ((1/2 : ℝ) • (a + b)) ≤ (N a + N b)/2)\n {x z1 z2 : Fin n → ℝ} (h1 : IsProxNorm N lam x z1) (h2 : IsProxNorm N lam x z2) :\n z1 = z2 := by\n rw [IsProxNorm, isMinOn_iff] at h1 h2\n have e1 := h1 z2 (Set.mem_univ _)\n have e2 := h2 z1 (Set.mem_univ _)\n simp only [] at e1 e2\n set m : Fin n → ℝ := (1/2 : ℝ) • (z1 + z2) with hm\n have hmx : m - x = (1/2 : ℝ) • ((z1 - x) + (z2 - x)) := by\n funext i\n simp only [hm, Pi.sub_apply, Pi.add_apply, Pi.smul_apply, smul_eq_mul]\n ring\n have e3 := h1 m (Set.mem_univ _)\n simp only [] at e3\n rw [hmx, sqL2_midpoint] at e3\n have hd : (z1 - x) - (z2 - x) = z1 - z2 := by abel\n rw [hd] at e3\n have hmn : N m ≤ (N z1 + N z2)/2 := hmid z1 z2\n have hs : sqL2 (z1 - z2) ≤ 0 := by nlinarith\n have hnn := sqL2_nonneg (z1 - z2)\n exact sub_eq_zero.mp (sqL2_eq_zero (le_antisymm hs hnn))\n\n/-- The prox map does not increase `N`. -/\nlemma prox_norm_le {N : (Fin n → ℝ) → ℝ} {lam : ℝ} (hlam : 0 ≤ lam) {x z : Fin n → ℝ}\n (h : IsProxNorm N lam x z) : N z ≤ N x := by\n rw [IsProxNorm, isMinOn_iff] at h\n have e := h x (Set.mem_univ _)\n simp only [] at e\n have h0 : sqL2 (x - x) = 0 := by simp [sqL2]\n rw [h0] at e\n have hnn := sqL2_nonneg (z - x)\n rcases eq_or_lt_of_le hlam with h1 | h1\n · have hz : sqL2 (z - x) ≤ 0 := by rw [← h1] at e; linarith\n have : z = x := sub_eq_zero.mp (sqL2_eq_zero (le_antisymm hz hnn))\n rw [this]\n · nlinarith\n\nend Prox\n\nsection NormFacts\nvariable {n : ℕ}\n\nlemma conv_of_tri_hom {N : (Fin n → ℝ) → ℝ} (htri : ∀ a b, N (a + b) ≤ N a + N b)\n (hhom : ∀ (c : ℝ) (a : Fin n → ℝ), 0 ≤ c → N (c • a) = c * N a) :\n ∀ (a b : Fin n → ℝ) (s : ℝ), 0 ≤ s → s ≤ 1 →\n N ((1-s) • a + s • b) ≤ (1-s) * N a + s * N b := by\n intro a b s h0 h1\n calc N ((1-s) • a + s • b) ≤ N ((1-s) • a) + N (s • b) := htri _ _\n _ = (1-s) * N a + s * N b := by rw [hhom _ _ (by linarith), hhom _ _ h0]\n\nlemma mid_of_conv {N : (Fin n → ℝ) → ℝ}\n (hconv : ∀ (a b : Fin n → ℝ) (s : ℝ), 0 ≤ s → s ≤ 1 →\n N ((1-s) • a + s • b) ≤ (1-s) * N a + s * N b) (a b : Fin n → ℝ) :\n N ((1/2 : ℝ) • (a + b)) ≤ (N a + N b)/2 := by\n have h := hconv a b (1/2) (by norm_num) (by norm_num)\n have he : ((1:ℝ)-1/2) • a + (1/2:ℝ) • b = (1/2:ℝ) • (a + b) := by\n funext i\n simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul]\n ring\n rw [he] at h\n linarith\n\n/-! #### ℓ¹ -/\n\nlemma l1_nonneg (x : Fin n → ℝ) : 0 ≤ l1Norm x :=\n Finset.sum_nonneg fun i _ => abs_nonneg _\n\nlemma l1_zero : l1Norm (0 : Fin n → ℝ) = 0 := by simp [l1Norm]\n\nlemma l1_tri (a b : Fin n → ℝ) : l1Norm (a + b) ≤ l1Norm a + l1Norm b := by\n simp only [l1Norm, Pi.add_apply, ← Finset.sum_add_distrib]\n exact Finset.sum_le_sum fun i _ => abs_add_le _ _\n\nlemma l1_hom (c : ℝ) (a : Fin n → ℝ) (hc : 0 ≤ c) : l1Norm (c • a) = c * l1Norm a := by\n simp only [l1Norm, Pi.smul_apply, smul_eq_mul, abs_mul, abs_of_nonneg hc, Finset.mul_sum]\n\n/-! #### ℓ² -/\n\nlemma l2_nonneg (x : Fin n → ℝ) : 0 ≤ l2Norm x := Real.sqrt_nonneg _\n\nlemma l2_sq (x : Fin n → ℝ) : (l2Norm x)^2 = sqL2 x := Real.sq_sqrt (sqL2_nonneg x)\n\nlemma l2_zero : l2Norm (0 : Fin n → ℝ) = 0 := by simp [l2Norm, sqL2]\n\nlemma dotp_le_l2 (a b : Fin n → ℝ) : dotp a b ≤ l2Norm a * l2Norm b := by\n have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ a b\n have h2 : (dotp a b)^2 ≤ sqL2 a * sqL2 b := by simpa [dotp, sqL2] using h\n have h3 : dotp a b ≤ |dotp a b| := le_abs_self _\n have h4 : |dotp a b| ≤ l2Norm a * l2Norm b := by\n rw [l2Norm, l2Norm, ← Real.sqrt_mul (sqL2_nonneg a)]\n rw [show |dotp a b| = Real.sqrt ((dotp a b)^2) from (Real.sqrt_sq_eq_abs _).symm]\n exact Real.sqrt_le_sqrt h2\n linarith\n\nlemma l2_tri (a b : Fin n → ℝ) : l2Norm (a + b) ≤ l2Norm a + l2Norm b := by\n have h1 : (l2Norm (a+b))^2 = sqL2 a + 2 * dotp a b + sqL2 b := by rw [l2_sq, sqL2_add]\n have h2 := dotp_le_l2 a b\n have h3 : (l2Norm (a+b))^2 ≤ (l2Norm a + l2Norm b)^2 := by\n rw [h1, ← l2_sq a, ← l2_sq b]; nlinarith\n have h4 : 0 ≤ l2Norm a + l2Norm b := by\n have := l2_nonneg a; have := l2_nonneg b; linarith\n nlinarith [l2_nonneg (a+b)]\n\nlemma l2_hom (c : ℝ) (a : Fin n → ℝ) (hc : 0 ≤ c) : l2Norm (c • a) = c * l2Norm a := by\n have h : sqL2 (c • a) = c^2 * sqL2 a := by\n simp only [sqL2, Pi.smul_apply, smul_eq_mul, Finset.mul_sum]\n exact Finset.sum_congr rfl fun i _ => by ring\n rw [l2Norm, h, Real.sqrt_mul (by positivity), Real.sqrt_sq hc, l2Norm]\n\n/-! #### ℓ^∞ -/\n\nlemma linfty_nonneg (x : Fin n → ℝ) : 0 ≤ linftyNorm x := by\n rcases isEmpty_or_nonempty (Fin n) with he | hne\n · rw [linftyNorm, Real.iSup_of_isEmpty]\n · obtain ⟨i⟩ := hne\n show (0:ℝ) ≤ ⨆ j, |x j|\n exact le_trans (abs_nonneg (x i)) (le_ciSup (Finite.bddAbove_range fun j => |x j|) i)\n\nlemma linfty_ge (x : Fin n → ℝ) (i : Fin n) : |x i| ≤ linftyNorm x :=\n le_ciSup (Finite.bddAbove_range fun j => |x j|) i\n\nlemma linfty_le {x : Fin n → ℝ} {c : ℝ} (hc : 0 ≤ c) (h : ∀ i, |x i| ≤ c) :\n linftyNorm x ≤ c := by\n rcases isEmpty_or_nonempty (Fin n) with he | hne\n · rw [linftyNorm, Real.iSup_of_isEmpty]; exact hc\n · exact ciSup_le h\n\nlemma linfty_zero : linftyNorm (0 : Fin n → ℝ) = 0 :=\n le_antisymm (linfty_le le_rfl (by simp)) (linfty_nonneg _)\n\nlemma linfty_tri (a b : Fin n → ℝ) : linftyNorm (a + b) ≤ linftyNorm a + linftyNorm b := by\n apply linfty_le\n · have := linfty_nonneg a; have := linfty_nonneg b; linarith\n · intro i\n calc |(a + b) i| = |a i + b i| := rfl\n _ ≤ |a i| + |b i| := abs_add_le _ _\n _ ≤ linftyNorm a + linftyNorm b := add_le_add (linfty_ge a i) (linfty_ge b i)\n\nlemma linfty_hom (c : ℝ) (a : Fin n → ℝ) (hc : 0 ≤ c) :\n linftyNorm (c • a) = c * linftyNorm a := by\n apply le_antisymm\n · apply linfty_le (by have := linfty_nonneg a; positivity)\n intro i\n calc |(c • a) i| = c * |a i| := by\n simp only [Pi.smul_apply, smul_eq_mul, abs_mul, abs_of_nonneg hc]\n _ ≤ c * linftyNorm a := mul_le_mul_of_nonneg_left (linfty_ge a i) hc\n · rcases eq_or_lt_of_le hc with h | h\n · rw [← h]; simp [linfty_nonneg]\n · have hb : linftyNorm a ≤ (linftyNorm (c • a))/c := by\n apply linfty_le (by have := linfty_nonneg (c • a); positivity)\n intro i\n rw [le_div_iff₀ h]\n calc |a i| * c = |(c • a) i| := by\n simp only [Pi.smul_apply, smul_eq_mul, abs_mul, abs_of_nonneg hc]; ring\n _ ≤ linftyNorm (c • a) := linfty_ge _ i\n rw [le_div_iff₀ h] at hb\n linarith [hb]\n\n/-! #### The alignment (★) inequalities -/\n\nlemma dotp_single (a : Fin n → ℝ) (i : Fin n) (c : ℝ) :\n dotp a (fun j => if j = i then c else 0) = a i * c := by\n simp [dotp, mul_ite, Finset.sum_ite_eq']\n\nlemma l1_single (i : Fin n) (c : ℝ) : l1Norm (fun j => if j = i then c else 0) = |c| := by\n simp [l1Norm, apply_ite (fun t : ℝ => |t|), Finset.sum_ite_eq']\n\nlemma coord_bound {l : ℝ} {p : Fin n → ℝ}\n (hd : ∀ v, dotp p v ≤ l * l1Norm v) (i : Fin n) : |p i| ≤ l := by\n rcases le_or_gt 0 (p i) with h | h\n · have hx := hd (fun j => if j = i then 1 else 0)\n rw [dotp_single, l1_single] at hx\n rw [abs_of_nonneg h]\n simpa using hx\n · have hx := hd (fun j => if j = i then -1 else 0)\n rw [dotp_single, l1_single] at hx\n rw [abs_of_neg h]\n simp at hx\n linarith\n\nlemma termwise_eq_l1 {l : ℝ} {p yv : Fin n → ℝ}\n (hb : ∀ i, |p i| ≤ l) (ha : dotp p yv = l * l1Norm yv) :\n ∀ i, p i * yv i = l * |yv i| := by\n have hnn : ∀ i ∈ (Finset.univ : Finset (Fin n)), 0 ≤ l * |yv i| - p i * yv i := by\n intro i _\n have h1 : p i * yv i ≤ |p i * yv i| := le_abs_self _\n have h2 : |p i * yv i| = |p i| * |yv i| := abs_mul _ _\n have h3 : |p i| * |yv i| ≤ l * |yv i| := mul_le_mul_of_nonneg_right (hb i) (abs_nonneg _)\n linarith\n have hsum : ∑ i, (l * |yv i| - p i * yv i) = 0 := by\n have he : ∑ i, (l * |yv i| - p i * yv i) = l * l1Norm yv - dotp p yv := by\n simp only [l1Norm, dotp, Finset.mul_sum, ← Finset.sum_sub_distrib]\n rw [he, ha]; ring\n intro i\n have := (Finset.sum_eq_zero_iff_of_nonneg hnn).mp hsum i (Finset.mem_univ i)\n linarith\n\nlemma star_l1 {l1 l2 : ℝ} (hl1 : 0 ≤ l1) (hl2 : 0 ≤ l2) {x y z : Fin n → ℝ}\n (hd1 : ∀ v, dotp (x - y) v ≤ l1 * l1Norm v)\n (ha1 : dotp (x - y) y = l1 * l1Norm y)\n (hd2 : ∀ v, dotp (y - z) v ≤ l2 * l1Norm v)\n (ha2 : dotp (y - z) z = l2 * l1Norm z) :\n l1 * l1Norm z ≤ dotp (x - y) z := by\n have hb1 : ∀ i, |(x - y) i| ≤ l1 := coord_bound hd1\n have hb2 : ∀ i, |(y - z) i| ≤ l2 := coord_bound hd2\n have k1 : ∀ i, (x - y) i * y i = l1 * |y i| := termwise_eq_l1 hb1 ha1\n have k2 : ∀ i, (y - z) i * z i = l2 * |z i| := termwise_eq_l1 hb2 ha2\n have main : ∀ i, l1 * |z i| ≤ (x - y) i * z i := by\n intro i\n have e1 := k1 i\n have e2 := k2 i\n simp only [Pi.sub_apply] at e1 e2 ⊢\n rcases lt_trichotomy (z i) 0 with h | h | h\n · rw [abs_of_neg h] at e2\n have hz0 : z i ≠ 0 := ne_of_lt h\n have hfac : (y i - z i + l2) * z i = 0 := by nlinarith [e2]\n have hy : y i = z i - l2 := by\n rcases mul_eq_zero.mp hfac with h' | h'\n · linarith\n · exact absurd h' hz0\n rw [hy, abs_of_neg (show z i - l2 < 0 by linarith)] at e1\n have hfac2 : (x i - (z i - l2) + l1) * (z i - l2) = 0 := by nlinarith [e1]\n have hzl : z i - l2 ≠ 0 := by intro hc; linarith\n have ha : x i - (z i - l2) = -l1 := by\n rcases mul_eq_zero.mp hfac2 with h' | h'\n · linarith\n · exact absurd h' hzl\n rw [hy, ha, abs_of_neg h]\n nlinarith\n · rw [h]; simp\n · rw [abs_of_pos h] at e2\n have hz0 : z i ≠ 0 := ne_of_gt h\n have hfac : (y i - z i - l2) * z i = 0 := by nlinarith [e2]\n have hy : y i = z i + l2 := by\n rcases mul_eq_zero.mp hfac with h' | h'\n · linarith\n · exact absurd h' hz0\n rw [hy, abs_of_pos (show (0:ℝ) < z i + l2 by linarith)] at e1\n have hfac2 : (x i - (z i + l2) - l1) * (z i + l2) = 0 := by nlinarith [e1]\n have hzl : z i + l2 ≠ 0 := by intro hc; linarith\n have ha : x i - (z i + l2) = l1 := by\n rcases mul_eq_zero.mp hfac2 with h' | h'\n · linarith\n · exact absurd h' hzl\n rw [hy, ha, abs_of_pos h]\n calc l1 * l1Norm z = ∑ i, l1 * |z i| := by simp only [l1Norm, Finset.mul_sum]\n _ ≤ ∑ i, (x - y) i * z i := Finset.sum_le_sum (fun i _ => main i)\n _ = dotp (x - y) z := rfl\n\nlemma star_l2 {l1 l2 : ℝ} (hl1 : 0 ≤ l1) (hl2 : 0 ≤ l2) {x y z : Fin n → ℝ}\n (hd1 : ∀ v, dotp (x - y) v ≤ l1 * l2Norm v)\n (ha1 : dotp (x - y) y = l1 * l2Norm y)\n (hd2 : ∀ v, dotp (y - z) v ≤ l2 * l2Norm v)\n (ha2 : dotp (y - z) z = l2 * l2Norm z) :\n l1 * l2Norm z ≤ dotp (x - y) z := by\n have hp : l2Norm (x - y) ≤ l1 := by\n have h := hd1 (x - y)\n rw [dotp_self, ← l2_sq] at h\n rcases eq_or_lt_of_le (l2_nonneg (x-y)) with hh | hh\n · rw [← hh]; exact hl1\n · nlinarith\n have hq : l2Norm (y - z) ≤ l2 := by\n have h := hd2 (y - z)\n rw [dotp_self, ← l2_sq] at h\n rcases eq_or_lt_of_le (l2_nonneg (y-z)) with hh | hh\n · rw [← hh]; exact hl2\n · nlinarith\n rcases eq_or_lt_of_le (l2_nonneg z) with hz | hz\n · have hs : sqL2 z = 0 := by rw [← l2_sq, ← hz]; ring\n have hz0 : z = 0 := sqL2_eq_zero hs\n rw [← hz, hz0]\n simp [dotp]\n · have hq2 : l2 ≤ l2Norm (y - z) := by\n have h := dotp_le_l2 (y - z) z\n rw [ha2] at h\n nlinarith\n have hqe : l2Norm (y - z) = l2 := le_antisymm hq hq2\n have hyzq : y = z + (y - z) := by funext i; simp\n have hny : (l2Norm y)^2 = (l2Norm z + l2)^2 := by\n rw [l2_sq]\n nth_rewrite 1 [hyzq]\n rw [sqL2_add, ← l2_sq z, ← l2_sq (y - z), hqe, dotp_comm z (y - z), ha2]\n ring\n have hnyv : l2Norm y = l2Norm z + l2 := by\n nlinarith [l2_nonneg y, l2_nonneg z]\n have hsplit : dotp (x - y) z = dotp (x - y) y - dotp (x - y) (y - z) := by\n rw [← dotp_sub_right]\n congr 1\n funext i; simp\n have hpq : dotp (x - y) (y - z) ≤ l2Norm (x - y) * l2Norm (y - z) := dotp_le_l2 _ _\n rw [hsplit, ha1, hnyv]\n rw [hqe] at hpq\n nlinarith [hp, l2_nonneg z, hl1, hl2]\n\nlemma l1Norm_le_of_dual {l : ℝ} (hl : 0 ≤ l) {p : Fin n → ℝ}\n (hd : ∀ v, dotp p v ≤ l * linftyNorm v) : l1Norm p ≤ l := by\n set v : Fin n → ℝ := fun j => if 0 ≤ p j then (1:ℝ) else -1 with hv\n have hdv : dotp p v = l1Norm p := by\n simp only [dotp, l1Norm, hv]\n apply Finset.sum_congr rfl\n intro i _\n by_cases h : 0 ≤ p i\n · simp [h, abs_of_nonneg h]\n · rw [if_neg h, abs_of_neg (not_le.mp h)]; ring\n have hlv : linftyNorm v ≤ 1 := by\n apply linfty_le zero_le_one\n intro i\n by_cases h : 0 ≤ p i <;> simp [hv, h]\n have hfin := hd v\n rw [hdv] at hfin\n nlinarith [hfin, hlv, hl]\n\nlemma termwise_linfty {l M : ℝ} {p yv : Fin n → ℝ} (hM : M = linftyNorm yv) (hMpos : 0 < M)\n (hp1 : l1Norm p ≤ l) (ha : dotp p yv = l * M) :\n (∀ i, p i * yv i = |p i| * M) ∧ l1Norm p = l := by\n have hnn : ∀ i ∈ (Finset.univ : Finset (Fin n)), 0 ≤ |p i| * M - p i * yv i := by\n intro i _\n have h1 : p i * yv i ≤ |p i * yv i| := le_abs_self _\n have h2 : |p i * yv i| = |p i| * |yv i| := abs_mul _ _\n have h3 : |yv i| ≤ M := hM ▸ linfty_ge yv i\n nlinarith [abs_nonneg (p i)]\n have he : ∑ i, (|p i| * M - p i * yv i) = l1Norm p * M - dotp p yv := by\n simp only [l1Norm, dotp, Finset.sum_mul, ← Finset.sum_sub_distrib]\n rw [ha] at he\n have hge : 0 ≤ ∑ i, (|p i| * M - p i * yv i) := Finset.sum_nonneg hnn\n have hl1eq : l1Norm p = l := by\n rw [he] at hge\n nlinarith\n have hzero : ∑ i, (|p i| * M - p i * yv i) = 0 := by rw [he, hl1eq]; ring\n refine ⟨fun i => ?_, hl1eq⟩\n have := (Finset.sum_eq_zero_iff_of_nonneg hnn).mp hzero i (Finset.mem_univ i)\n linarith\n\nlemma star_linfty {l1 l2 : ℝ} (hl1 : 0 ≤ l1) (hl2 : 0 ≤ l2) {x y z : Fin n → ℝ}\n (hd1 : ∀ v, dotp (x - y) v ≤ l1 * linftyNorm v)\n (ha1 : dotp (x - y) y = l1 * linftyNorm y)\n (hd2 : ∀ v, dotp (y - z) v ≤ l2 * linftyNorm v)\n (ha2 : dotp (y - z) z = l2 * linftyNorm z)\n (hmono : linftyNorm z ≤ linftyNorm y) :\n l1 * linftyNorm z ≤ dotp (x - y) z := by\n have hp1 : l1Norm (x - y) ≤ l1 := l1Norm_le_of_dual hl1 hd1\n have hq1 : l1Norm (y - z) ≤ l2 := l1Norm_le_of_dual hl2 hd2\n rcases eq_or_lt_of_le (linfty_nonneg z) with hth | hth\n · have hz0 : z = 0 := by\n funext i\n have h1 : |z i| ≤ linftyNorm z := linfty_ge z i\n rw [← hth] at h1\n have h2 := abs_nonneg (z i)\n have h3 : |z i| = 0 := le_antisymm h1 h2\n simpa using abs_eq_zero.mp h3\n rw [← hth, hz0]\n simp [dotp]\n · have hMpos : 0 < linftyNorm y := lt_of_lt_of_le hth hmono\n obtain ⟨k1, hl1eq⟩ := termwise_linfty (rfl) hMpos hp1 ha1\n obtain ⟨k2, hl2eq⟩ := termwise_linfty (rfl) hth hq1 ha2\n have main : ∀ i, (x - y) i * z i = |(x - y) i| * linftyNorm z := by\n intro i\n set p := (x - y) i with hp\n set q := (y - z) i with hq\n have hpy : p * y i = |p| * linftyNorm y := k1 i\n have hqz : q * z i = |q| * linftyNorm z := k2 i\n have hqdef : q = y i - z i := rfl\n by_cases hp0 : p = 0\n · rw [hp0]; simp\n · by_cases hq0 : q = 0\n · have hzy : z i = y i := by rw [hqdef] at hq0; linarith\n have hpabs : 0 < |p| := abs_pos.mpr hp0\n have habs : |p| * linftyNorm y ≤ |p| * |y i| := by\n have h0 : p * y i ≤ |p| * |y i| := by\n calc p * y i ≤ |p * y i| := le_abs_self _\n _ = |p| * |y i| := abs_mul _ _\n rw [hpy] at h0\n exact h0\n have hyM : linftyNorm y ≤ |y i| := le_of_mul_le_mul_left habs hpabs\n have hyM2 : |y i| ≤ linftyNorm y := linfty_ge y i\n have hyeq : |y i| = linftyNorm y := le_antisymm hyM2 hyM\n have hzi : |z i| ≤ linftyNorm z := linfty_ge z i\n rw [hzy] at hzi\n have hMth : linftyNorm y = linftyNorm z := by\n rw [hyeq] at hzi; linarith\n rw [hzy, ← hMth]\n exact hpy\n · have hqabs : 0 < |q| := abs_pos.mpr hq0\n rcases lt_or_gt_of_ne hq0 with hqneg | hqpos\n · have hzi : z i = -linftyNorm z := by\n rw [abs_of_neg hqneg] at hqz\n have hh : q * (z i + linftyNorm z) = 0 := by nlinarith [hqz]\n rcases mul_eq_zero.mp hh with h | h\n · exact absurd h hq0\n · linarith\n have hyi : y i = -linftyNorm z + q := by rw [hqdef] at *; linarith\n have hyneg : y i < 0 := by\n rw [hyi]; have := linfty_nonneg z; linarith\n have hpneg : p < 0 := by\n rcases lt_trichotomy p 0 with h | h | h\n · exact h\n · exact absurd h hp0\n · exfalso\n have h1 : 0 < |p| * linftyNorm y := by positivity\n nlinarith [hpy]\n rw [hzi, abs_of_neg hpneg]\n ring\n · have hzi : z i = linftyNorm z := by\n rw [abs_of_pos hqpos] at hqz\n have hh : q * (z i - linftyNorm z) = 0 := by nlinarith [hqz]\n rcases mul_eq_zero.mp hh with h | h\n · exact absurd h hq0\n · linarith\n have hyi : y i = linftyNorm z + q := by rw [hqdef] at *; linarith\n have hypos : 0 < y i := by\n rw [hyi]; have := linfty_nonneg z; linarith\n have hppos : 0 < p := by\n rcases lt_trichotomy p 0 with h | h | h\n · exfalso\n have h1 : 0 < |p| * linftyNorm y := by\n have : 0 < |p| := abs_pos.mpr hp0\n positivity\n nlinarith [hpy]\n · exact absurd h hp0\n · exact h\n rw [hzi, abs_of_pos hppos]\n have heq : l1 * linftyNorm z = dotp (x - y) z := by\n calc l1 * linftyNorm z = l1Norm (x - y) * linftyNorm z := by rw [hl1eq]\n _ = ∑ i, |(x - y) i| * linftyNorm z := by simp only [l1Norm, Finset.sum_mul]\n _ = ∑ i, (x - y) i * z i := Finset.sum_congr rfl (fun i _ => (main i).symm)\n _ = dotp (x - y) z := rfl\n exact le_of_eq heq\n\nend NormFacts\n\nsection Compose\nvariable {n : ℕ}\n\nlemma norm_pack {N : (Fin n → ℝ) → ℝ} (hN : N = l1Norm ∨ N = l2Norm ∨ N = linftyNorm) :\n (∀ a b, N (a + b) ≤ N a + N b) ∧\n (∀ (c : ℝ) (a : Fin n → ℝ), 0 ≤ c → N (c • a) = c * N a) ∧ N 0 = 0 := by\n rcases hN with h | h | h <;> subst h\n · exact ⟨l1_tri, l1_hom, l1_zero⟩\n · exact ⟨l2_tri, l2_hom, l2_zero⟩\n · exact ⟨linfty_tri, linfty_hom, linfty_zero⟩\n\nlemma prox_facts {N : (Fin n → ℝ) → ℝ} {lam : ℝ} (hlam : 0 ≤ lam)\n (htri : ∀ a b, N (a + b) ≤ N a + N b)\n (hhom : ∀ (c : ℝ) (a : Fin n → ℝ), 0 ≤ c → N (c • a) = c * N a)\n (hN0 : N 0 = 0) {x y : Fin n → ℝ} (h : IsProxNorm N lam x y) :\n (∀ v, dotp (x - y) v ≤ lam * N v) ∧ dotp (x - y) y = lam * N y := by\n have hconv := conv_of_tri_hom htri hhom\n have hVI := prox_VI N lam hlam x y hconv h\n have hd := prox_dual hlam htri hVI\n exact ⟨hd, prox_align hN0 hVI hd⟩\n\nlemma dotp_split (x y z u : Fin n → ℝ) :\n dotp (x - z) u = dotp (x - y) u + dotp (y - z) u := by\n simp only [dotp, Pi.sub_apply, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n\nlemma prox_compose {N : (Fin n → ℝ) → ℝ} {l1 l2 : ℝ} (hl1 : 0 ≤ l1) (hl2 : 0 ≤ l2)\n (htri : ∀ a b, N (a + b) ≤ N a + N b)\n (hhom : ∀ (c : ℝ) (a : Fin n → ℝ), 0 ≤ c → N (c • a) = c * N a)\n (hN0 : N 0 = 0) {x y z : Fin n → ℝ}\n (hy : IsProxNorm N l1 x y) (hz : IsProxNorm N l2 y z)\n (hstar : l1 * N z ≤ dotp (x - y) z) : IsProxNorm N (l1 + l2) x z := by\n obtain ⟨hd1, ha1⟩ := prox_facts hl1 htri hhom hN0 hy\n obtain ⟨hd2, ha2⟩ := prox_facts hl2 htri hhom hN0 hz\n apply prox_suff\n · intro u\n rw [dotp_split x y z u]\n have hr : (l1 + l2) * N u = l1 * N u + l2 * N u := by ring\n rw [hr]\n linarith [hd1 u, hd2 u]\n · rw [dotp_split x y z z, ha2]\n have hxy : dotp (x - y) z = l1 * N z := le_antisymm (hd1 z) hstar\n rw [hxy]; ring\n\nlemma star_all {N : (Fin n → ℝ) → ℝ} (hN : N = l1Norm ∨ N = l2Norm ∨ N = linftyNorm)\n {l1 l2 : ℝ} (hl1 : 0 ≤ l1) (hl2 : 0 ≤ l2) {x y z : Fin n → ℝ}\n (hd1 : ∀ v, dotp (x - y) v ≤ l1 * N v) (ha1 : dotp (x - y) y = l1 * N y)\n (hd2 : ∀ v, dotp (y - z) v ≤ l2 * N v) (ha2 : dotp (y - z) z = l2 * N z)\n (hmono : N z ≤ N y) : l1 * N z ≤ dotp (x - y) z := by\n rcases hN with h | h | h <;> subst h\n · exact star_l1 hl1 hl2 hd1 ha1 hd2 ha2\n · exact star_l2 hl1 hl2 hd1 ha1 hd2 ha2\n · exact star_linfty hl1 hl2 hd1 ha1 hd2 ha2 hmono\n\nend Compose\n\ntheorem proposition11\n {n : ℕ} (T : ℕ) (hT : 0 < T) (w0 wstar : Fin n → ℝ) (w : ℕ → Fin n → ℝ)\n (lam : ℕ → ℝ) (hlam : ∀ t ∈ Finset.Icc 1 T, 0 ≤ lam t)\n (hw0 : w 0 = w0)\n (N : (Fin n → ℝ) → ℝ)\n (hN : N = l1Norm ∨ N = l2Norm ∨ N = linftyNorm)\n (hseq : ∀ t ∈ Finset.Icc 1 T, IsProxNorm N (lam t) (w (t - 1)) (w t))\n (hbatch : IsProxNorm N (∑ t ∈ Finset.Icc 1 T, lam t) w0 wstar) :\n w T = wstar := by\n obtain ⟨htri, hhom, hN0⟩ := norm_pack hN\n have hconv := conv_of_tri_hom htri hhom\n have hmid := mid_of_conv hconv\n have hlamsum : ∀ t, t ≤ T → 0 ≤ ∑ s ∈ Finset.Icc 1 t, lam s := by\n intro t ht\n apply Finset.sum_nonneg\n intro s hs\n rw [Finset.mem_Icc] at hs\n exact hlam s (by rw [Finset.mem_Icc]; omega)\n have key : ∀ t, 1 ≤ t → t ≤ T → IsProxNorm N (∑ s ∈ Finset.Icc 1 t, lam s) w0 (w t) := by\n intro t h1\n induction t, h1 using Nat.le_induction with\n | base =>\n intro _\n have h := hseq 1 (by rw [Finset.mem_Icc]; omega)\n simp only [Finset.Icc_self, Finset.sum_singleton]\n rw [show (1:ℕ) - 1 = 0 from rfl, hw0] at h\n exact h\n | succ m hm ih =>\n intro hmT\n have ihm := ih (by omega)\n have hstep := hseq (m+1) (by rw [Finset.mem_Icc]; omega)\n rw [Nat.add_sub_cancel] at hstep\n have hl1 : 0 ≤ ∑ s ∈ Finset.Icc 1 m, lam s := hlamsum m (by omega)\n have hl2 : 0 ≤ lam (m+1) := hlam (m+1) (by rw [Finset.mem_Icc]; omega)\n obtain ⟨hd1, ha1⟩ := prox_facts hl1 htri hhom hN0 ihm\n obtain ⟨hd2, ha2⟩ := prox_facts hl2 htri hhom hN0 hstep\n have hmono : N (w (m+1)) ≤ N (w m) := prox_norm_le hl2 hstep\n have hstar := star_all hN hl1 hl2 hd1 ha1 hd2 ha2 hmono\n have hres := prox_compose hl1 hl2 htri hhom hN0 ihm hstep hstar\n rw [Finset.sum_Icc_succ_top (by omega)]\n exact hres\n have hfin := key T hT le_rfl\n exact prox_unique (hlamsum T le_rfl) hmid hfin hbatch\n\n\nend ResearchLevel\n"} +{"id": "v23-20-411", "source": "Research-level", "targets": [{"label": "Lemma 5", "decls": ["lemma5_oblivious", "lemma5_adaptive"], "statement": "Lemma 5 (Weighted-Regret Bound for EXP3). Let $\\{\\eta_{t}\\}$ be a non-increasing step-size sequence such that $\\eta_{t}\\leq\\frac 12e^{-2}$ for all t. Let $\\left\\{l_{t}^{\\left(i\\right)}\\right\\}$ be a cost sequence such that $l_{t}^{(i)}\\in [0,1]$ for every $t,i.$ Let $\\{d_{t}\\}$ be a delay sequence such that the cost from round t is received at round $t + d_{t}$ . Define the set $\\mathcal{M}^{\\ast}$ of all samples that are not received before round T or that were delayed by $\\begin{array}{r}{d_{t}\\geq \\frac{1}{e^{2}\\eta_{t}}- 1}\\end{array}$ . Then using EXP3 (Algorithm 3) guarantees:\n\n1. With an oblivious adversary and $\\gamma_{t}= 0$ for all t:\n\n$$\n\\mathbb{E}\\left\\{\\sum_{t=1}^{T}\\eta_{t}l_{t}^{(a_{t})}-\\operatorname*{min}_{i}\\sum_{t=1}^{T}\\eta_{t}l_{t}^{(i)}\\right\\}\\leq\\log K+\\frac{e^{2}}{2}K\\sum_{t=1}^{T}\\eta_{t}^{2}+4\\sum_{t\\notin\\mathcal{M}^{*}}\\eta_{t}^{2}d_{t}+\\sum_{t\\in\\mathcal{M}^{*}}\\eta_{t}.\\tag{42}\n$$\n\n2. With an adaptive adversary and $\\gamma_{t}= \\eta_{t}$ for all t:\n\n$$\n\\mathbb{E}\\left\\{\\sum_{t=1}^{T}\\eta_{t}l_{t}^{(a_{t})}-\\operatorname*{min}_{i}\\sum_{t=1}^{T}\\eta_{t}l_{t}^{(i)}\\right\\}\\leq 2+2\\log K+(1+\\frac{e^{2}}{2})K\\sum_{t=1}^{T}\\eta_{t}^{2}+4 e^{2}K\\sum_{t\\notin\\mathcal{M}^{*}}\\eta_{t}^{2}d_{t}+\\sum_{t\\in\\mathcal{M}^{*}}\\eta_{t}.\\tag{43}\n$$", "context_ids": ["v23-20-411:ctx1", "v23-20-411:ctx2", "v23-20-411:ctx5", "v23-20-411:ctx6", "v23-20-411:ctx8", "v23-20-411:ctx9", "v23-20-411:ctx10", "v23-20-411:ctx11"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}, {"label": "Theorem 6", "decls": ["theorem6_regretBound"], "statement": "Theorem 6. Let $\\left\\{l_{t}^{\\left(i\\right)}\\right\\}$ be a cost sequence such that $l_{t}^{(i)}\\in [0,1]$ for every $t,i$ Let $\\{d_{t}\\}$ be a delay sequence such that the cost from round t is received at round $t + d_{t}$ . Define the set $\\mathcal{M}=$ $\\{t|t+d_{t}>T,t\\in [1,T]\\}$ of all samples that are not received before round T. Let us choose the fixed step-size $\\begin{array}{r}{\\eta = \\frac{e^{- 2}}{2}\\sqrt{\\frac{\\log K}{K T + \\sum_{t \\notin \\mathcal{M}}d_{t}}}}\\end{array}$ . Then the expected regret of EXP3 (Algorithm 3 with $\\gamma_{t}= 0$ for all t) against an oblivious adversary satisfies\n\n$$\n\\mathbb{E}\\left\\{R\\left(T\\right)\\right\\}=\\mathbb{E}\\left\\{\\sum_{t=1}^{T}\\langle l_{t},p_{t}\\rangle-\\operatorname*{min}_{i}\\sum_{t=1}^{T}l_{t}^{\\left(i\\right)}\\right\\}=O\\left(\\sqrt{\\log K\\left(K T+\\sum_{t\\notin\\mathcal{M}}d_{t}\\right)}+\\left|\\mathcal{M}\\right|\\right).\\tag{46}\n$$", "context_ids": ["v23-20-411:ctx1", "v23-20-411:ctx2", "v23-20-411:ctx3", "v23-20-411:ctx5", "v23-20-411:ctx6"], "sibling_refs": ["Lemma 5"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}, {"label": "Lemma 6", "decls": ["lemma6_noWeightedRegret"], "statement": "Lemma 6. EXP3 (Algorithm 3 with $\\gamma_{t}= \\eta_{t}$ for all t, against an adaptive adversary) with a non-increasing and positive step-size sequence $\\{\\eta_{t}\\}$ such that $\\eta_{t}\\leq\\frac 12e^{-2}$ for all t has no weighted-regret with respect to the sequence of delays $\\{d_{t}\\}$ and $\\{\\eta_{t}\\}$ as the weight sequence, if the following two conditions hold:\n\n1. $\\textstyle \\sum_{t = 1}^{\\infty}\\eta_{t}= \\infty .$\n\n2. $\\operatorname*{lim}_{t\\to\\infty}\\eta_{t}d_{t}<\\infty$ and $\\textstyle \\sum_{t = 1}^{\\infty}\\eta_{t}^{2}d_{t}< \\infty$", "context_ids": ["v23-20-411:ctx1", "v23-20-411:ctx2", "v23-20-411:ctx4", "v23-20-411:ctx5", "v23-20-411:ctx6", "v23-20-411:ctx7"], "sibling_refs": ["Lemma 5"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}], "nl_proof": "### Proof of Lemma 5\n\n## 13. Proof of Lemma 6: Weighted-Regret of EXP3 with Delays\n\nRecall that $\\mathcal{M}^{\\ast}$ is the set of missing or discarded samples. Let $s_{-}, s_{+}$ as the step a moment before and a moment after the algorithm uses the feedback from round s, which updates the mixed action from $\\pmb{p}_{s_{-}}$ to $\\pmb{p}_{s_{+}}$ . Both $s_{-}$ and $s_{+}$ are algorithm update steps that take place in round t of the game if $s \\in S_{t}$ Let $s_{T}$ be the last feedback to be updated.\n\nWe begin by the standard EXP3 analysis for arbitrary $\\tilde{l}_{s}$ (Lattimore and Szepesvári, 2020), but with careful consideration to both the interleaved arrivals and the weight $\\eta_{s}$ Recall that $\\begin{array}{r}{\\tilde{L}_{t}^{(i)}=\\sum_{t\\notin\\mathcal{M}^{*}}\\eta_{t}\\frac{l_{t}^{(i)}1_{\\{a_{t}=i\\}}}{p_{t}^{(i)}+\\gamma_{t}}}\\end{array}$ , as defined in Algorithm 3. Define $\\begin{array}{r}{\\Phi\\left(t\\right)= -\\log\\left(\\sum_{i=1}^{K}e^{-\\tilde{L}_{t}^{(i)}}\\right)}\\end{array}$ and $\\begin{array}{r}{\\tilde{l}_{t}=\\left(0,...,\\frac{l_{t}^{(a_{t})}}{p_{t}^{(a_{t})}+\\gamma_{t}},...,0\\right)}\\end{array}$ . Then\n\n$$\n\\begin{array}{rl}\n\\Phi\\left(s_{+}\\right)-\\Phi\\left(s_{-}\\right) & =-\\log\\left(\\frac{\\sum_{i=1}^{K}e^{-\\tilde{L}_{s_{-}}^{(i)}}e^{-\\eta_{s}\\tilde{l}_{s}^{(i)}}}{\\sum_{j=1}^{K}e^{-\\tilde{L}_{s_{-}}^{(j)}}}\\right)=-\\log\\left(\\sum_{i=1}^{K}p_{s_{-}}^{(i)}e^{-\\eta_{s}\\tilde{l}_{s}^{(i)}}\\right)\\\\\n & \\underset{(a)}{\\ge}-\\log\\left(\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(1-\\eta_{s}\\tilde{l}_{s}^{(i)}+\\frac{1}{2}\\eta_{s}^{2}\\left(\\tilde{l}_{s}^{(i)}\\right)^{2}\\right)\\right)\\\\\n & =-\\log\\left(1-\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(\\eta_{s}\\tilde{l}_{s}^{(i)}-\\frac{1}{2}\\eta_{s}^{2}\\left(\\tilde{l}_{s}^{(i)}\\right)^{2}\\right)\\right)\\\\\n & \\underset{(b)}{\\ge}\\eta_{s}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\tilde{l}_{s}^{(i)}-\\frac{\\eta_{s}^{2}}{2}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(\\tilde{l}_{s}^{(i)}\\right)^{2}\n\\end{array}\\tag{83}\n$$\n\nwhere (a) is $e^{- x}\\leq 1 - x +{\\textstyle{\\frac{1}{2}}}x^{2}$ and (b) is $\\log{(1-x)}\\leq-x$ Hence, iterating (83) over s yields\n\n$$\n\\Phi\\left(s_{T}^{+}\\right)-\\Phi\\left(1\\right)=\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\left(\\Phi\\left(s_{+}\\right)-\\Phi\\left(s_{-}\\right)\\right)\\geq\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\tilde{l}_{s}^{(i)}-\\frac{1}{2}\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}^{2}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(\\tilde{l}_{s}^{(i)}\\right)^{2}.\\tag{84}\n$$\n\nNext we upper bound $\\Phi\\left(s_{T}^{+}\\right)-\\Phi\\left(1\\right)$ . We have for $i^{*}\\triangleq\\arg\\operatorname*{min}_{i}\\sum_{t=1}^{T}\\eta_{t}l_{t}^{(i)}$ that\n\n$$\n\\Phi\\left(s_{T}^{+}\\right)-\\Phi\\left(1\\right)= -\\log\\left(\\sum_{j=1}^{K}e^{-\\tilde{L}_{s_{T}^{+}}^{(j)}}\\right)+\\log K\\underset{(a)}{\\leq}\\tilde{L}_{s_{T}^{+}}^{(i^{*})}+\\log K=\\sum_{t=1}^{T}\\sum_{s\\in S_{t}}\\eta_{s}\\tilde{l}_{s}^{(i^{*})}+\\log K\\tag{85}\n$$\n\nwhere (a) omits positive terms from $\\Sigma_{j=1}^{K}e^{-\\tilde{L}_{s_{T}^{+}}^{(j)}}$ . We conclude from (84) and (85) that\n\n$$\n\\sum_{t=1}^{T}\\sum_{s\\in S_{t}}\\eta_{s}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\tilde{l}_{s}^{(i)}-\\sum_{t=1}^{T}\\sum_{s\\in S_{t}}\\eta_{s}\\tilde{l}_{s}^{(i^{*})}\\leq\\log K+\\frac{1}{2}\\sum_{t=1}^{T}\\sum_{s\\in S_{t}}\\eta_{s}^{2}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(\\tilde{l}_{s}^{(i)}\\right)^{2}.\\tag{86}\n$$\n\nNow observe that\n\n$$\n\\begin{array}{rl}\n\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\tilde{l}_{s}^{(i)} & =\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\frac{l_{s}^{(i)}1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}+\\gamma_{s}}=\\sum_{i=1}^{K}\\left(p_{s}^{(i)}+\\gamma_{s}\\right)\\frac{l_{s}^{(i)}1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}+\\gamma_{s}}-\\sum_{i=1}^{K}\\left(p_{s}^{(i)}+\\gamma_{s}-p_{s_{-}}^{(i)}\\right)\\frac{l_{s}^{(i)}1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}+\\gamma_{s}}\\\\\n & =l_{s}^{(a_{s})}-\\gamma_{s}\\sum_{i=1}^{K}\\tilde{l}_{s}^{(i)}+\\sum_{i=1}^{K}\\left(p_{s_{-}}^{(i)}-p_{s}^{(i)}\\right)\\tilde{l}_{s}^{(i)}.\n\\end{array}\\tag{87}\n$$\n\nUsing $\\frac{p_{s_{-}}^{(i)}}{p_{s}^{(i)}}\\leq e^{2}$ from Lemma 9, we obtain\n\n$$\n\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(\\tilde{l}_{s}^{(i)}\\right)^{2}=\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(\\frac{l_{s}^{(i)}1_{\\left\\{a_{s}=i\\right\\}}}{p_{s}^{(i)}+\\gamma_{s}}\\right)^{2}\\leq e^{2}\\sum_{i=1}^{K}\\frac{p_{s}^{(i)}}{p_{s}^{(i)}+\\gamma_{s}}\\frac{l_{s}^{(i)}1_{\\left\\{a_{s}=i\\right\\}}}{p_{s}^{(i)}+\\gamma_{s}}\\leq e^{2}\\sum_{i=1}^{K}\\tilde{l}_{s}^{(i)}.\\tag{88}\n$$\n\nTaking the weighted sum of (87) over $t \\notin{\\mathcal{M}}^{*}$ and subtracting $\\begin{array}{r}{\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\tilde{l}_{s}^{(i^{*})}}\\end{array}$ from both sides:\n\n$$\n\\begin{array}{rl}\n & \\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}l_{s}^{(a_{s})}-\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\gamma_{s}\\eta_{s}\\sum_{i=1}^{K}\\tilde{l}_{s}^{(i)}+\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\sum_{i=1}^{K}\\left(p_{s_{-}}^{(i)}-p_{s}^{(i)}\\right)\\tilde{l}_{s}^{(i)}-\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\tilde{l}_{s}^{(i^{*})}\\\\\n & =\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\tilde{l}_{s}^{(i)}-\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\tilde{l}_{s}^{(i^{*})}\\\\\n & \\underset{(a)}{\\le}\\log K+\\frac{1}{2}\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}^{2}\\sum_{i=1}^{K}p_{s_{-}}^{(i)}\\left(\\tilde{l}_{s}^{(i)}\\right)^{2}\\\\\n & \\underset{(b)}{\\le}\\log K+\\frac{1}{2}\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}e^{2}\\eta_{s}^{2}\\sum_{i=1}^{K}\\tilde{l}_{s}^{(i)}\n\\end{array}\\tag{89}\n$$\n\nwhere (a) uses (86) and (b) uses (88). Rearranging (89) and subtracting $\\begin{array}{r}{\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}l_{s}^{(i^{*})}}\\end{array}$ from both sides gives\n\n$$\n\\begin{array}{l}\n\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left(l_{s}^{(a_{s})}-l_{s}^{(i^{*})}\\right)\\leq\\\\\n\\underbrace{\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\sum_{i=1}^{K}\\left(p_{s}^{(i)}-p_{s_{-}}^{(i)}\\right)\\tilde{l}_{s}^{(i)}}_{A}+\\log K+\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left(\\tilde{l}_{s}^{(i^{*})}-l_{s}^{(i^{*})}\\right)+\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\left(\\gamma_{s}\\eta_{s}+\\frac{e^{2}}{2}\\eta_{s}^{2}\\right)\\sum_{i=1}^{K}\\tilde{l}_{s}^{(i)}.\n\\end{array}\\tag{90}\n$$\n\n## 13.1 Adaptive Adversary with $\\gamma_{t}= \\eta_{t}$\n\n## 13.1.1 Taking the Expectation\n\nDefine $\\begin{array}{r}{W_{1}^{(i)}=\\sum_{t=1}^{T}\\sum_{s\\in{\\cal S}_{t}}\\eta_{s}\\left(\\tilde{l}_{s}^{(i)}-l_{s}^{(i)}\\right)-\\log K}\\end{array}$ . From Lemma 11 with $\\delta \\leftarrow \\frac{\\delta}{K}$ and $\\alpha_{s}^{(i)}=\\eta_{s}$ and $\\alpha_{s}^{(j)}=0$ for all $j \\neq i$ we get by using the union bound that\n\n$$\n\\mathbb{P}\\left(\\operatorname*{max}_{i}W_{1}^{(i)}\\geq\\log\\frac{1}{\\delta}\\right)\\leq K\\mathbb{P}\\left(\\sum_{{t=1}}^{T}\\sum_{s\\in S_{t}}\\eta_{s}\\left(\\tilde{l}_{s}^{(i)}-l_{s}^{(i)}\\right)\\geq\\log\\frac{K}{\\delta}\\right)\\leq\\delta\\tag{91}\n$$\n\nso by substituting $\\begin{array}{r}{x = \\log{\\frac{1}{\\delta}}}\\end{array}$ so $\\begin{array}{r}{d x = - \\frac{d \\delta}{\\delta}}\\end{array}$\n\n$$\n\\mathbb E\\left\\{\\operatorname*{max}_{i}W_{1}^{(i)}\\right\\}\\leq\\int_{0}^{\\infty}\\mathbb P\\left(\\operatorname*{max}_{i}W_{1}^{(i)}\\geq x\\right)d x=\\int_{0}^{1}\\frac 1\\delta\\mathbb P\\left(\\operatorname*{max}_{i}W_{1}^{(i)}\\geq\\log\\frac 1\\delta\\right)d\\delta\\leq 1 .\\tag{92}\n$$\n\nDefine $\\begin{array}{r}{W_{2}=\\sum_{t=1}^{T}\\sum_{s\\in{{\\mathcal{S}}}_{t}}\\left(\\gamma_{s}\\eta_{s}+\\frac{e^{2}}{2}\\eta_{s}^{2}\\right)\\sum_{i=1}^{K}\\left(\\tilde{l}_{s}^{(i)}-l_{s}^{(i)}\\right)}\\end{array}$ . From Lemma 11 with $\\alpha_{s}^{(i)}=\\gamma_{s}\\eta_{s}+$ $\\begin{array}{r}{\\frac{e^{2}}{2}\\eta_{s}^{2}\\leq 2 \\eta_{s}}\\end{array}$ for all i we get $\\mathbb{P}\\left(W_{2}\\geq\\log\\frac{1}{\\delta}\\right)\\leq\\delta$ ,so using (92) on $W_{2}$ we obtain $\\mathbb{E}\\left\\{W_{2}\\right\\}\\le 1 .$\n\nFrom $\\mathbb{E}\\left\\{\\operatorname*{max}_{i}W_{1}^{(i)}\\right\\}\\le 1$ and $\\mathbb{E}\\left\\{W_{2}\\right\\}\\le 1$ we conclude that\n\n$$\n\\begin{array}{r l r}{{\\mathbb{E}\\{\\operatorname*{max}_{i}\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}(\\tilde{l}_{s}^{(i)}-l_{s}^{(i)})+\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}(\\gamma_{s}\\eta_{s}+\\frac{e^{2}}{2}\\eta_{s}^{2})\\sum_{i=1}^{K}\\tilde{l}_{s}^{(i)}\\}\\leq}}\\\\ &{}&{\\log K+2+\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}(\\gamma_{s}\\eta_{s}+\\frac{e^{2}}{2}\\eta_{s}^{2})\\sum_{i=1}^{K}l_{s}^{(i)}\\leq\\log K+2+K\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}(\\gamma_{s}\\eta_{s}+\\frac{e^{2}}{2}\\eta_{s}^{2}).}\\end{array}\\tag{93}\n$$\n\n## 13.1.2 The Effect of Delays\n\nNext we bound the A term in (90), which quantifies the effect of the delays. Let $s \\in S_{t}$ , and let q be a round for which the feedback is used after or at round s, but before the feedback from round s is used. Define $\\begin{array}{r}{h_{i}\\left(\\tilde{L}_{q_{-}}\\right)\\triangleq p_{q_{-}}^{(i)}=\\frac{e^{-\\tilde{L}_{q_{-}}^{(i)}}}{\\sum_{j=1}^{K}e^{-\\tilde{L}_{q_{-}}^{(j)}}},\\text{ so } p_{q_{+}}^{(i)}=h_{i}\\left(\\tilde{\\pmb{L}}_{q_{-}}+\\eta_{q}\\tilde{\\pmb{l}}_{q}\\right)}\\end{array}$ . Using Lemma 10 with $\\pmb{x}= \\tilde{\\pmb{L}}_{q_{-}}$ and $\\Delta = \\eta_{q}\\tilde{l}_{q}$ (so $\\pmb{h}(\\pmb{x})=\\pmb{p}_{q_{-}})$ yields\n\n$$\n\\begin{array}{rl}\n\\left\\Vert \\pmb{p}_{q_{-}}-\\pmb{p}_{q_{+}}\\right\\Vert _{1} & \\le2\\eta_{q}\\sum_{i=1}^{K}p_{q_{-}}^{(i)}\\tilde{l}_{q}^{(i)}=2\\eta_{q}\\sum_{i=1}^{K}p_{q_{-}}^{(i)}\\frac{l_{q}^{(i)}1_{\\{a_{q}=i\\}}}{p_{q}^{(i)}+\\gamma_{q}}\\\\\n & \\underset{(a)}{\\le}2e^{2}\\eta_{q}\\sum_{i=1}^{K}p_{q}^{(i)}\\frac{l_{q}^{(i)}1_{\\{a_{q}=i\\}}}{p_{q}^{(i)}+\\gamma_{q}}\\le2e^{2}\\eta_{q}\\sum_{i=1}^{K}l_{q}^{(i)}1_{\\{a_{q}=i\\}}=2e^{2}\\eta_{q}l_{q}^{(a_{q})}\\le2e^{2}\\eta_{q}\n\\end{array}\\tag{94}\n$$\n\nwhere (a) uses $\\frac{p_{q_{-}}^{(i)}}{p_{q}^{(i)}}\\leq e^{2}$ from Lemma 9. Hence\n\n$$\n\\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{q_{-}}-\\pmb{p}_{q_{+}}\\right\\rangle =\\sum_{i=1}^{K}\\left(p_{q_{-}}^{(i)}-p_{q_{+}}^{(i)}\\right)\\frac{l_{s}^{(i)}1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}+\\gamma_{s}}\\underset{(a)}{\\le}2e^{2}\\eta_{q}\\sum_{i=1}^{K}\\frac{l_{s}^{(i)}1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}+\\gamma_{s}}\\le2e^{2}\\eta_{q}\\sum_{i=1}^{K}\\frac{1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}+\\gamma_{s}}\\tag{95}\n$$\n\nwhere (a) follows since $p_{q_{-}}^{(i)}-p_{q_{+}}^{(i)}\\leq\\left|p_{q_{-}}^{(i)}-p_{q_{+}}^{(i)}\\right|\\leq\\left\\|p_{q_{-}}-p_{q_{+}}\\right\\|_{1}\\leq 2e^{2}\\eta_{q}$ . Using (95) we can write\n\n$$\n\\mathbb{E}\\left\\{ \\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{q_{-}}-\\pmb{p}_{q_{+}}\\right\\rangle \\mid\\mathcal{F}_{s}\\right\\} \\le2e^{2}\\eta_{q}\\sum_{i=1}^{K}\\mathbb{E}\\left\\{ \\frac{1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}+\\gamma_{s}}\\mid\\mathcal{F}_{s}\\right\\} \\underset{(a)}{=}2e^{2}\\eta_{q}\\sum_{i=1}^{K}\\frac{p_{s}^{(i)}}{p_{s}^{(i)}+\\gamma_{s}}\\le2e^{2}\\eta_{q}K\\tag{96}\n$$\n\nwhere (a) uses that $p_{s}^{(i)}$ is $\\mathcal{F}_{s}$ -measurable and that $a_{s}= i$ with probability $p_{s}^{(i)}$ . Hence the A term in (90) can be bounded as\n\n$$\n\\begin{array}{rl}\n & \\mathbb{E}\\left\\{ \\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{s}-\\pmb{p}_{s_{-}}\\right\\rangle \\right\\} \\\\\n & =\\mathbb{E}\\left\\{ \\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left(\\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{t}-\\pmb{p}_{s_{-}}\\right\\rangle +\\sum_{r=s}^{t-1}\\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{r}-\\pmb{p}_{r+1}\\right\\rangle \\right)\\right\\} \\\\\n & =\\mathbb{E}\\left\\{ \\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left(\\sum_{q\\in\\mathcal{S}_{t},q s$ is not a random variable that depends on $a_{q}$ , which the adversary observes already at the end of round $q .$ Then for every $q \\in S_{r}$ for $r < t$ or $q \\in \\mathcal{S}_{t}$ such that $q < s$ we have\n\n$$\n\\begin{array}{rl}\n\\mathbb{E}\\left\\{ \\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{q_{-}}-\\pmb{p}_{q_{+}}\\right\\rangle \\right\\} & =\\mathbb{E}\\left\\{ \\mathbb{E}\\left\\{ \\sum_{i=1}^{K}\\left(p_{q_{-}}^{(i)}-p_{q_{+}}^{(i)}\\right)\\frac{l_{s}^{(i)}1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}}\\mid\\mathcal{F}_{s_{-}}\\right\\} \\right\\} \\\\\n & =\\mathbb{E}\\left\\{ \\sum_{i=1}^{K}\\left(p_{q_{-}}^{(i)}-p_{q_{+}}^{(i)}\\right)\\mathbb{E}\\left\\{ \\frac{l_{s}^{(i)}1_{\\{a_{s}=i\\}}}{p_{s}^{(i)}}\\mid\\mathcal{F}_{s_{-}}\\right\\} \\right\\} \\\\\n & =\\mathbb{E}\\left\\{ \\sum_{i=1}^{K}\\left(p_{q_{-}}^{(i)}-p_{q_{+}}^{(i)}\\right)l_{s}^{(i)}\\right\\} \\\\\n & =\\mathbb{E}\\left\\{ \\left\\langle \\pmb{l}_{s},\\pmb{p}_{q_{-}}-\\pmb{p}_{q_{+}}\\right\\rangle \\right\\} \\underset{(a)}{\\le}\\mathbb{E}\\left\\{ \\left\\Vert \\pmb{l}_{s}\\right\\Vert _{\\infty}\\left\\Vert \\pmb{p}_{q_{-}}-\\pmb{p}_{q_{+}}\\right\\Vert _{1}\\right\\} \\\\\n & \\underset{(b)}{\\le}\\mathbb{E}\\left\\{ \\left\\Vert \\pmb{p}_{q_{-}}-\\pmb{p}_{q_{+}}\\right\\Vert _{1}\\right\\} \\underset{(c)}{\\le}2\\eta_{q}\n\\end{array}\\tag{101}\n$$\n\nwhere (a) is Hölder's inequality, (b) uses $0\\leq l_{t}^{(i)}\\leq 1$ and (c) uses (100) and the tower rule. Therefore\n\n$$\n\\begin{array}{rl}\n & \\mathbb{E}\\left\\{ \\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{s}-\\pmb{p}_{s_{-}}\\right\\rangle \\right\\} \\\\\n & =\\mathbb{E}\\left\\{ \\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left(\\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{t}-\\pmb{p}_{s_{-}}\\right\\rangle +\\sum_{r=s}^{t-1}\\left\\langle \\tilde{\\pmb{l}}_{s},\\pmb{p}_{r}-\\pmb{p}_{r+1}\\right\\rangle \\right)\\right\\} \\\\\n & =\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left(\\sum_{q\\in\\mathcal{S}_{t},q - 1$ and $0 \\leq x \\leq 1$ , since $\\alpha_{t}^{(i)}\\leq 2\\gamma_{t}$ Inequality (b) uses that $1_{\\{a_{t}= i \\}}1_{\\{a_{t}= j \\}}= 0$ for all $i \\neq j$ ,and (c) uses that $p_{t}^{(i)}$ and $l_{t}^{(i)}$ are $\\mathcal{G}_{t}$ -measurable and that given $\\mathcal{G}_{t}, a_{t}= i$ with probability $p_{t}^{(i)}$\n\nSince $l_{t}^{(i)}$ is $\\mathcal{G}_{t}$ -measurable then (113) yields $\\mathbb{E}\\left\\{e^{\\sum_{i=1}^{K}\\alpha_{t}^{(i)}\\left(\\tilde{l}_{t}^{(i)}-l_{t}^{(i)}\\right)}|\\mathcal{G}_{t}\\right\\}\\leq 1$ for all i. Let $S =$ $\\textstyle \\sum_{t = 1}^{T}| S_{t}|$ . Let $\\tau_{l}$ be l-th round for which the feedback is not missing or discarded, so $\\tau_{1}\\leq \\tau_{2}\\leq$ $\\dots \\le \\tau_{S}$ . Then\n\n$$\n\\begin{array}{r l}&{\\mathbb{E}\\left\\{e^{\\sum_{l=1}^{S}\\sum_{i=1}^{K}\\alpha_{\\tau_{l}}^{(i)}\\left(\\tilde{l}_{\\tau_{l}}^{(i)}-l_{\\tau_{l}}^{(i)}\\right)}\\right\\}=\\mathbb{E}\\left\\{\\mathbb{E}\\left\\{e^{\\sum_{l=1}^{S}\\sum_{i=1}^{K}\\alpha_{\\tau_{l}}^{(i)}\\left(\\tilde{l}_{\\tau_{l}}^{(i)}-l_{\\tau_{l}}^{(i)}\\right)}|\\mathcal{G}_{\\tau_{S}}\\right\\}\\right\\}\\underset{(a)}{=}}\\\\ &{\\quad\\mathbb{E}\\left\\{e^{\\sum_{l=1}^{S-1}\\sum_{i=1}^{K}\\alpha_{\\tau_{l}}^{(i)}\\left(\\tilde{l}_{\\tau_{l}}^{(i)}-l_{\\tau_{l}}^{(i)}\\right)}\\mathbb{E}\\left\\{e^{\\sum_{i=1}^{K}\\alpha_{\\tau_{S}}^{(i)}\\left(\\tilde{l}_{\\tau_{S}}^{(i)}-l_{\\tau_{S}}^{(i)}\\right)}|\\mathcal{G}_{\\tau_{S}}\\right\\}\\right\\}\\leq\\mathbb{E}\\left\\{e^{\\sum_{l=1}^{S-1}\\sum_{i=1}^{K}\\alpha_{\\tau_{l}}^{(i)}\\left(\\tilde{l}_{\\tau_{l}}^{(i)}-l_{\\tau_{l}}^{(i)}\\right)}\\right\\}}\\end{array}\\tag{114}\n$$\n\nwhere (a) uses that $a_{\\tau_{1}},l_{\\tau_{1}},{p_{\\tau_{1}}},\\dotsc,a_{\\tau_{S-1}},l_{\\tau_{S-1}},{p_{\\tau_{S-1}}}$ are $\\mathcal{G}_{\\tau_{S}}$ -measurable.\n\nIterating over (114) yields $\\mathbb{E}\\left\\{e^{\\sum_{t\\notin\\mathcal{M}^{\\ast}}\\sum_{i=1}^{K}\\alpha_{t}^{(i)}\\left(\\tilde{l}_{t}^{(i)}-l_{t}^{(i)}\\right)}\\right\\}\\leq 1$ , so by Markov's inequality\n\n$$\n\\begin{array}{ r }{\\mathbb{P}\\left(\\displaystyle\\sum_{t\\notin\\mathcal{M}^{*}}\\sum_{i=1}^{K}\\alpha_{t}^{(i)}\\left(\\tilde{l}_{t}^{(i)}-l_{t}^{(i)}\\right)>\\log\\frac{1}{\\delta}\\right)=\\mathbb{P}\\left(e^{\\sum_{t\\notin\\mathcal{M}^{*}}\\sum_{i=1}^{K}\\alpha_{t}^{(i)}\\left(\\tilde{l}_{t}^{(i)}-l_{t}^{(i)}\\right)}>\\frac{1}{\\delta}\\right)}\\\\ {\\leq\\delta\\mathbb{E}\\left\\{e^{\\sum_{t\\notin\\mathcal{M}^{*}}\\sum_{i=1}^{K}\\alpha_{t}^{(i)}\\left(\\tilde{l}_{t}^{(i)}-l_{t}^{(i)}\\right)}\\right\\}\\leq\\delta .}\\end{array}\\tag{115}\n$$\n\n### Proof of Theorem 6\n\nProof We choose $\\eta_{t}= \\eta$ in (42) of Lemma 5 and define $\\mathcal{D}= \\left\\{t | d_{t}\\geq \\frac{1}{e^{2}\\eta}- 1 \\text{ and } t + d_{t}\\leq T \\right\\}$ so $\\mathcal{M}^{\\ast}= \\mathcal{M}\\cup \\mathcal{D}$ in the statement of Lemma 5. Now divide both sides by η:\n\n$$\n\\mathbb{E}\\left\\{\\sum_{t=1}^{T}l_{t}^{(a_{t})}-\\operatorname*{min}_{i}\\sum_{t=1}^{T}l_{t}^{(i)}\\right\\}\\leq\\frac{\\log K}{\\eta}+\\frac{e^{2}}{2}\\eta K T+4\\eta\\sum_{t\\notin\\mathcal{M}^{*}}d_{t}+\\left|\\mathcal{M}\\right| +\\left|\\mathcal{D}\\right|.\\tag{47}\n$$\n\nThen, choosing $\\begin{array}{r}{\\eta = \\frac{e^{- 2}}{2}\\sqrt{\\frac{\\log K}{K T + \\sum_{t \\notin \\mathcal{M}}d_{t}}}}\\end{array}$ yields (46). Note that for this choice $\\begin{array}{r}{|\\mathcal{D}|\\leq\\frac{\\sum_{t\\notin\\mathcal{M}}d_{t}}{e^{-2}\\eta^{-1}-1}\\leq\\sqrt{\\left(\\sum_{t\\notin\\mathcal{M}}d_{t}\\right)\\log K}}\\end{array}$ , since $\\begin{array}{r}{\\sum_{t\\not\\in\\mathcal{M}}d_{t}\\geq\\left(\\frac{1}{e^{2}\\eta}-1\\right)|\\mathcal{D}|}\\end{array}$ (discarded samples in D are not missing).\n\n### Proof of Lemma 6\n\nProof Define the set of missing samples $\\mathcal{M}= \\{t | t + d_{t}> T \\}$ and the set of discarded samples ${\\mathcal{D}}_{T}= \\left\\{t | d_{t}\\eta_{t}> e^{- 2}- \\eta_{t}\\right\\}$ . Define $t^{*}\\left(T\\right)=\\operatorname*{min}_{t\\in\\mathcal{M}}t$ , and note that $t^{*}(T)\\to\\infty$ as $T \\to \\infty$ since $t + d_{t}\\geq t$ ,and $f\\left(t\\right)=t$ is increasing. Since $\\eta_{t}$ is non-increasing then\n\n$$\n\\sum_{t\\in\\mathcal{M}}\\eta_{t}\\le\\left|\\mathcal{M}\\right|\\eta_{t^{\\ast}\\left(T\\right)}\\le\\left(T-t^{\\ast}\\left(T\\right)+1\\right)\\eta_{t^{\\ast}\\left(T\\right)}\\le d_{t^{\\ast}\\left(T\\right)}\\eta_{t^{\\ast}\\left(T\\right)}.\\tag{51}\n$$\n\nGiven $\\textstyle \\sum_{t = 1}^{\\infty}\\eta_{t}^{2}d_{t}~ < ~ \\infty$ and $\\textstyle \\sum_{t = 1}^{\\infty}\\eta_{t}\\ = \\ \\infty$ we must have $\\operatorname*{lim}_{t\\to\\infty}\\eta_{t}d_{t}=0$ if this limit exists, so $\\operatorname*{lim}_{T\\to\\infty}|\\mathcal{D}_{T}| <\\infty$ . Therefore for the optimal arm $i^{*}$\n\n$$\n\\operatorname*{lim}_{T\\to\\infty}\\frac{\\mathbb{E}\\left\\{\\sum_{t=1}^{T}\\eta_{t}\\left(l_{t}^{(a_{t})}-l_{t}^{(i^{*})}\\right)\\right\\}}{\\sum_{t=1}^{T}\\eta_{t}}\\underset{(a)}{\\le}\\operatorname*{lim}_{T\\to\\infty}\\frac{\\eta_{1}\\left|\\mathcal{D}_{T}\\right| +d_{t^{*}(T)}\\eta_{t^{*}(T)}+4\\log K+5 K\\sum_{t=1}^{T}\\eta_{t}^{2}\\left(1+6 d_{t}\\right)}{\\sum_{t=1}^{T}\\eta_{t}}\\underset{(b)}{=}0\\tag{52}\n$$\n\nwhere (a) is Lemma 5 and (51), and (b) uses $d_{t}\\eta_{t}\\to 0$ as $\\begin{array}{r}{t\\to\\infty,\\sum_{t=1}^{\\infty}\\eta_{t}=\\infty}\\end{array}$ and $\\textstyle \\sum_{t = 1}^{\\infty}d_{t}\\eta_{t}^{2}< \\infty .$", "context": [{"id": "v23-20-411:ctx1", "name": "Setup: problem formulation, adversaries, delays, missing samples (Section 2)", "statement": "Consider a player that in each round t from 1 to $T$ picks an action $\\pmb{a}_{t}\\in \\mathcal{K}$ from a set $\\mathcal{K}$ . The cost at round t from playing $\\pmb{a}_{t}$ is $l_{t}\\left(\\boldsymbol{a}_{t}\\right)\\in\\left[0,1\\right]$ . We consider two types of adversaries:\n\n1. Oblivious Adversary: chooses the cost functions $l_{1},...,l_{T}$ before the game starts.\n\n2. Adaptive Adversary: chooses the cost function $l_{t}$ after observing $\\{a_{1}, \\ldots a_{t - 1}\\}$ , for each t.\n\nWith full information and no delays, the player gets to know the function $l_{t}$ immediately after playing $\\pmb{a}_{t}$ . In the bandit delayed feedback scenario, the player only gets to know the value of ${l}_{t}\\left(\\pmb{a}_{t}\\right)$ at the beginning of round $t + d_{t}$ . (i.e., after a delay of $d_{t}\\geq 1$ rounds). The adversary (oblivious or adaptive) chooses the delay sequence $\\{d_{t}\\}$ before the game starts.\n\nWe assume that the cost feedback includes the timestamp of the action that incurred this cost. This is indeed the case in many applications, such as when robots take physical actions, a recommendation is made to a customer or a treatment is given to a patient. If the delays are bounded by d, Cesa-Bianchi et al. (2018) have shown that EXP3 can still be implemented even with no timestamps, with expected regret $O(\\sqrt{dTK\\log K})$ instead of $O\\left({\\sqrt{\\left(d+K\\right)T\\log K}}\\right)$ . For our unbounded delays case, it is not clear if FKM or EXP3 can be implemented without timestamps.\n\nThe set of costs (feedback samples) received and used at round t is denoted $\\mathcal{S}_{t}$ , so $s \\in \\mathcal{S}_{t}$ means that the cost of $\\pmb{a}_{s}$ from round s is received and used at round t. Since the game lasts for $T$ rounds, all costs for which $t + d_{t}> T$ are never received. Of course, the value of $d_{t}$ does not matter as long as $t + d_{t}> T$ , and these are just samples that the adversary chose to prevent the player from receiving. We name these costs the missing samples and denote their set by $\\mathcal{M}$ .\n\nWhile the rounds of the game are indexed by t, it will be useful to our analysis to index a finer time scale that counts the steps of the algorithm for every such t. We define $s_{-}, s_{+}$ as the steps a moment before and after the algorithm uses the feedback from round s, respectively. These steps are taking place in round t if $s \\in S_{t}$"}, {"id": "v23-20-411:ctx2", "name": "Setup: multi-armed bandit special case (Section 2)", "statement": "We analyze two widely applied algorithms for the two central special cases of the scenario above:\n\n2. Multi-Armed Bandit - $\\mathcal{K}=\\{1,...,K\\},\\ l_{t}:\\{1,...,K\\}\\to [0,1].$ With no delays, the EXP3 algorithm (Auer et al., 2002) achieves an expected regret of $O \\left({\\sqrt{T K \\log K}}\\right)$ for this problem."}, {"id": "v23-20-411:ctx3", "name": "Definition 1 (expected regret, eq. 1)", "statement": "The player wants to have a learning algorithm that uses past observations to make good decisions over time. The performance of the player's algorithm is measured using the regret. The expected regret is the total expected cost over a horizon of $T$ rounds, compared to the total expected cost that results from playing the best fixed action in hindsight in all rounds:\n\nDefinition 1. Let $\\begin{array}{r}{\\pmb{a}^{*}=\\underset{\\pmb{a}\\in\\mathcal{K}}{\\arg\\operatorname*{min}}\\sum_{t=1}^{T}l_{t}\\left(\\pmb{a}\\right)}\\end{array}$ . The expected regret is defined as\n\n$$\n\\mathbb{E}\\left\\{R\\left(T\\right)\\right\\}\\triangleq\\sum_{t=1}^{T}\\mathbb{E}\\left\\{l_{t}\\left(\\pmb{a}_{t}\\right)-l_{t}\\left(\\pmb{a}^{*}\\right)\\right\\}\\tag{1}\n$$\n\nwhere $\\mathbb{E}$ is the expectation over the (possibly) random actions $\\pmb{a}_{1},\\ldots,\\pmb{a}_{T}$ of the player."}, {"id": "v23-20-411:ctx4", "name": "Definition 2 (no weighted-regret, eq. 2) and remarks", "statement": "Our key observation is that with delayed feedback, it is not the regret that matters for the game dynamics but rather what we call the weighted-regret. The weighted-regret weighs the costs in different rounds according to a given non-increasing sequence $\\eta_{t}$ so it coincides with the regret when $\\eta_{t}=\\eta,\\forall t$ . We define \"no weighted-regret\" to replace the traditional no-regret property:\n\nDefinition 2. Let $\\{l_{t}:\\mathcal{K}\\to [0,1]\\}_{t}$ be a sequence of cost functions, chosen by an adaptive adversary. Let $\\pmb{a}^{*}=\\arg\\operatorname*{min}_{\\pmb{a}\\in\\mathcal{K}}\\sum_{t=1}^{T}\\eta_{t}l_{t}\\left(\\pmb{a}\\right)$ . Let $\\{d_{t}\\}$ be a delay sequence such that the cost from round t is received at round $t + d_{t}$ . We say that an algorithm that produces the random sequence of (single-agent) actions $\\left\\{\\pmb{a}_{t}\\right\\}$ has no weighted-regret with respect to $\\{d_{t}\\}$ and the non-increasing weight\n\nsequence $\\{\\eta_{t}\\}$ if\n\n$$\n\\operatorname*{lim}_{T\\to\\infty}\\mathbb{E}\\left\\{\\frac{\\sum_{t=1}^{T}\\eta_{t}\\left(l_{t}\\left(\\pmb{a}_{t}\\right)-l_{t}\\left(\\pmb{a}^{*}\\right)\\right)}{\\sum_{t=1}^{T}\\eta_{t}}\\right\\}=0\\tag{2}\n$$\n\nwhere the expectation is with respect to the random $\\left\\{\\pmb{a}_{t}\\right\\}$ generated by the algorithm.\n\nHaving no weighted-regret is only non-trivial when $\\textstyle \\sum_{t = 1}^{\\infty}\\eta_{t}\\ = \\infty$ When $\\textstyle\\sum_{t=1}^{\\infty}\\eta_{t}<\\infty,$ the feedback from the last $\\textstyle{\\frac{T}{2}}$ rounds can be discarded without affecting (2). When $\\textstyle \\sum_{t = 1}^{\\infty}\\eta_{t}= \\infty$ ,there is no round t after which we can discard all feedback and still maintain (2).\n\nWe define no weighted-regret with respect to an adaptive adversary since, in a non-cooperative game with cost functions $\\{u_{n}\\}$ , the \"adversarial\" cost function of player n is $l_{t}({\\bf{a}}_{n})=u_{n}({\\bf{a}}_{n},{\\bf{a}}_{-n,t})$ so it is determined by the actions of the other players. In turn, the actions of the other players depend on the past actions of player n. Hence, the cost function of player n depends on her past actions, as with an adaptive adversary. In general, the equilibrium does not consist of absolute strategies such as \"min-max\" in zero-sum games. Hence, regret guarantees against an adaptive adversary allow proving convergence to the set of CCE for general non-cooperative games.\n\nWhen taking the limit $T\\to\\infty,$ it is important to emphasize that we do not change the infinite sequence of delays $\\{d_{t}\\}$ , but only reveal more elements in this sequence. In other words, we are looking at the same game but over a longer time horizon. Therefore, while $\\begin{array}{r}{d_{t}= \\frac{T}{2}}\\end{array}$ makes sense for a constant $T,$ it is misleading when taking $T \\to \\infty$ since it represents a delay that occurred at time t but changes with the limit, so the limit is no longer of the \"same game\"."}, {"id": "v23-20-411:ctx5", "name": "Setup: EXP3 with delays, mixed actions and the filtration F_t (eq. 41, Section 6)", "statement": "Consider a player that at each round t picks one out of K arms. Let $a_{t}$ be the arm the player chooses at round t. The cost at round t of playing arm i is $l_{t}^{(i)}\\in [0,1]$ , and let $l_{t}=\\left(l_{t}^{(1)},...,l_{t}^{(K)}\\right)$ be the cost vector. At round t, the EXP3 algorithm, detailed in Algorithm 3, chooses an arm at random using a distribution that depends on the history of the game. The variant when $\\gamma_{t}\\neq 0$ , as we use against an adaptive adversary, is known as EXP3-IX (see Neu (2015)). We denote the vector of probabilities of the player for choosing arms at round t by $\\pmb{p}_{t}\\in \\Delta^{K}$ , where $\\Delta^{K}$ denotes the K-simplex. This is also known as the mixed action of the player. We also define the following filtration\n\n$$\n\\mathcal{F}_{t}=\\sigma\\left(\\left\\{a_{s}\\vert s+d_{s}\\le t\\right\\}\\cup\\left\\{l_{s}\\vert s\\le t\\right\\}\\right)\\tag{41}\n$$\n\nwhich is generated from all the actions for which the feedback was received up to round t and all cost functions up to round t. Note that the mixed action $\\pmb{p}_{t}$ is a $\\mathcal{F}_{t}$ -measurable random variable since $\\mathcal{F}_{t}$ includes everything that could affect the algorithm up to round t. With a slight abuse of notation, we use $\\mathcal{F}_{s_{-}}$ to denote the filtration induced from all actions for which the feedback has been received and used up to step $s_{-}$ and all the cost functions up to round t."}, {"id": "v23-20-411:ctx6", "name": "Algorithm 3 (EXP3 with delays, eqs. 44-45)", "statement": "Algorithm 3 EXP3 with delays \nInitialization: Let $\\{\\eta_{t}\\}$ and $\\{\\gamma_{t}\\}$ be non-negative non-increasing sequences such that $\\eta_{1}\\leq \\frac{e^{- 2}}{2}$ and \nset $\\tilde{L}_{1}^{(i)}=0$ and $\\begin{array}{r}{p_{1}^{(i)}=\\frac{1}{K}}\\end{array}$ for $i=1,...,K.$ \nFor $t=1,...,T$ do \n1. Choose an arm $a_{t}$ at random according to the distribution $\\pmb{p}_{t}$ . \n2. Collect in $S_{t}$ all the rounds s for which $l_{s}^{(a_{s})}$ arrived at round t after a delay of $\\begin{array}{r}{d_{s}\\le \\frac{1}{e^{2}\\eta_{s}}- 1}\\end{array}$ \n3. Set $\\tilde{L}_{t}^{(i)}=\\tilde{L}_{t-1}^{(i)}$ for all i. Update the weights of arm $a_{s}$ for all $s \\in S_{t}$ using \n$\\tilde{L}_{t}^{(a_{s})}=\\tilde{L}_{t}^{(a_{s})}+\\eta_{s}\\frac{l_{s}^{(a_{s})}}{p_{s}^{(a_{s})}+\\gamma_{s}}.$ (44) \n4. Update the mixed action for $i=1,\\ldots,K$ using \n$p_{t+1}^{(i)}=\\frac{e^{-\\tilde{L}_{t}^{(i)}}}{\\sum_{j=1}^{K}e^{-\\tilde{L}_{t}^{(j)}}}.$ (45) \nEnd"}, {"id": "v23-20-411:ctx7", "name": "Section 6.2 introduction (conditions for no weighted-regret)", "statement": "In this subsection, we provide conditions for EXP3 to have no weighted-regret with respect to the delay sequence and its step-size sequence as the weight sequence of Section 3. As discussed in Section 3, $\\textstyle \\sum_{t = 1}^{\\infty}\\eta_{t}= \\infty$ , is necessary for the no weighted-regret property to be non-trivial. All other conditions of Lemma 6 are as tight as the bound of Lemma 5."}, {"id": "v23-20-411:ctx8", "name": "Lemma 8 (effect of delays, eq. 66)", "statement": "Lemma 8. Let $\\{\\eta_{t}\\}$ be a non-increasing step-size sequence. Let $\\{d_{t}\\}$ be a delay such that the cost from round t is received at round $t + d_{t}$ . Let $S_{t}$ be the set of feedback samples received and used at round t. Define the set $\\mathcal{M}^{\\ast}$ of all samples that are not received and used before round T. Then\n\n$$\n\\sum_{t=1}^{T}\\sum_{s\\in\\mathcal{S}_{t}}\\eta_{s}\\left(\\sum_{r=s}^{t-1}\\sum_{q\\in\\mathcal{S}_{r}}\\eta_{q}+\\sum_{q\\in\\mathcal{S}_{t},q\\log\\frac{1}{\\delta}\\right)\\leq\\delta .\\tag{111}\n$$"}], "lean": "import Mathlib\n\nnamespace ResearchLevel\n\nopen scoped Classical\nopen MeasureTheory Filter Topology\n\ndef missedRounds (T : ℕ) (d : ℕ → ℕ) : Finset ℕ :=\n (Finset.Icc 1 T).filter (fun t => T < t + d t)\n\nnoncomputable def MStar (T : ℕ) (d : ℕ → ℕ) (η : ℕ → ℝ) : Finset ℕ :=\n (Finset.Icc 1 T).filter (fun t => T < t + d t ∨ (d t : ℝ) ≥ 1 / (Real.exp 2 * η t) - 1)\n\nnoncomputable def weightedExpReg {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (T K : ℕ) (hK : 0 < K) (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (a : ℕ → Ω → Fin K) : ℝ :=\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n ∫ ω, (∑ t ∈ Finset.Icc 1 T, η t * l t ω (a t ω) -\n (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l t ω i)) ∂μ\n\nnoncomputable def expReg {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (T K : ℕ) (hK : 0 < K) (l0 : ℕ → Fin K → ℝ) (a : ℕ → Ω → Fin K) : ℝ :=\n weightedExpReg μ T K hK (fun _ => 1) (fun t _ i => l0 t i) a\n\nnoncomputable def NoWeightedRegret {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (K : ℕ) (hK : 0 < K) (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (a : ℕ → Ω → Fin K) : Prop :=\n limsup (fun T : ℕ => weightedExpReg μ T K hK η l a / ∑ t ∈ Finset.Icc 1 T, η t)\n atTop ≤ 0\n\nstructure Exp3Delayed {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) (K : ℕ) (hK : 0 < K)\n (l : ℕ → Ω → Fin K → ℝ) (d : ℕ → ℕ) (η γ : ℕ → ℝ) where\n 𝓕 : ℕ → MeasurableSpace Ω\n 𝓕_le : ∀ t, 𝓕 t ≤ ‹MeasurableSpace Ω›\n 𝓕_mono : Monotone 𝓕\n a : ℕ → Ω → Fin K\n p : ℕ → Ω → Fin K → ℝ\n Lhat : ℕ → Ω → Fin K → ℝ\n measurable_a : ∀ t, Measurable (a t)\n 𝓕_eq : ∀ t, 𝓕 t =\n (⨆ s, ⨆ (_ : 1 ≤ s ∧ s + d s ≤ t), MeasurableSpace.comap (a s) inferInstance)\n ⊔ (⨆ s, ⨆ (_ : 1 ≤ s ∧ s ≤ t), MeasurableSpace.comap (l s) inferInstance)\n measurable_p : ∀ t i, @Measurable Ω ℝ (𝓕 t) _ (fun ω => p t ω i)\n p_isProb : ∀ t ω, (∀ i, 0 ≤ p t ω i) ∧ ∑ i, p t ω i = 1\n p_init : ∀ ω i, p 1 ω i = 1 / (K : ℝ)\n a_law : ∀ t i,\n (μ[(fun ω => if a t ω = i then (1 : ℝ) else 0) | 𝓕 t]) =ᵐ[μ] (fun ω => p t ω i)\n Lhat_init : ∀ ω i, Lhat 0 ω i = 0\n Lhat_step : ∀ t ω i, 1 ≤ t →\n Lhat t ω i = Lhat (t - 1) ω i +\n ∑ s ∈ (Finset.Icc 1 t).filter\n (fun s => s + d s = t ∧ (d s : ℝ) ≤ 1 / (Real.exp 2 * η s) - 1 ∧ a s ω = i),\n η s * l s ω i / (p s ω i + γ s)\n p_update : ∀ t ω i,\n p (t + 1) ω i = Real.exp (- Lhat t ω i) / ∑ j, Real.exp (- Lhat t ω j)\n\ntheorem lemma5_oblivious {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (K T : ℕ) (hK : 0 < K) (hT : 0 < T)\n (η : ℕ → ℝ) (l0 : ℕ → Fin K → ℝ) (d : ℕ → ℕ) (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hη_pos : ∀ t, 0 < η t) (hη_dec : ∀ t, η (t + 1) ≤ η t)\n (hη_bound : ∀ t, η t ≤ (1 / 2) * Real.exp (-2))\n (hl : ∀ t i, l0 t i ∈ Set.Icc (0 : ℝ) 1)\n (E : Exp3Delayed μ K hK (fun t _ i => l0 t i) d η (fun _ => 0))\n\n \n \n \n \n \n \n (a_fresh : ∀ t t' i, t ≤ t' → t' < t + d t →\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n E.𝓕 t' ⊔ ⨆ s ∈ {s : ℕ | s + d s < t + d t ∨ (s + d s = t + d t ∧ s < t)},\n MeasurableSpace.comap (E.a s) inferInstance]) =ᵐ[μ] (fun ω => E.p t ω i)) :\n weightedExpReg μ T K hK η (fun t _ i => l0 t i) E.a ≤\n Real.log K + (Real.exp 2 / 2) * K * (∑ t ∈ Finset.Icc 1 T, (η t) ^ 2)\n + 4 * (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t) ^ 2 * (d t : ℝ))\n + (∑ t ∈ MStar T d η, η t) := by\n sorry\n\ntheorem lemma5_adaptive {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (K T : ℕ) (hK : 0 < K) (hT : 0 < T)\n (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (d : ℕ → ℕ) (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hη_pos : ∀ t, 0 < η t) (hη_dec : ∀ t, η (t + 1) ≤ η t)\n (hη_bound : ∀ t, η t ≤ (1 / 2) * Real.exp (-2))\n (hl : ∀ t ω i, l t ω i ∈ Set.Icc (0 : ℝ) 1)\n (E : Exp3Delayed μ K hK l d η η)\n (hl_adapted : ∀ t i, @Measurable Ω ℝ\n (⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance) _\n (fun ω => l t ω i))\n\n (a_law_adaptive : ∀ t i,\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n ⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance]) =ᵐ[μ]\n (fun ω => E.p t ω i)) :\n weightedExpReg μ T K hK η l E.a ≤\n 2 + 2 * Real.log K\n + (1 + Real.exp 2 / 2) * K * (∑ t ∈ Finset.Icc 1 T, (η t) ^ 2)\n + 4 * Real.exp 2 * K * (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t) ^ 2 * (d t : ℝ))\n + (∑ t ∈ MStar T d η, η t) := by\n sorry\n\ntheorem theorem6_regretBound :\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (K T : ℕ) (hK : 0 < K) (hT : 0 < T) (l0 : ℕ → Fin K → ℝ) (d : ℕ → ℕ)\n (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hl : ∀ t i, l0 t i ∈ Set.Icc (0 : ℝ) 1) (η : ℕ → ℝ)\n (hη_pos : ∀ t ≥ 1, 0 < η t)\n (hη : η = fun _ =>\n (Real.exp (-2) / 2) *\n Real.sqrt (Real.log K /\n ((K : ℝ) * T + ∑ t ∈ (Finset.Icc 1 T) \\ missedRounds T d, (d t : ℝ))))\n (E : Exp3Delayed μ K hK (fun t _ i => l0 t i) d η (fun _ => 0))\n (a_fresh : ∀ t t' i, t ≤ t' → t' < t + d t →\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n E.𝓕 t' ⊔ ⨆ s ∈ {s : ℕ | s + d s < t + d t ∨ (s + d s = t + d t ∧ s < t)},\n MeasurableSpace.comap (E.a s) inferInstance]) =ᵐ[μ] (fun ω => E.p t ω i)),\n expReg μ T K hK l0 E.a ≤\n C * (Real.sqrt (Real.log K *\n ((K : ℝ) * T + ∑ t ∈ (Finset.Icc 1 T) \\ missedRounds T d, (d t : ℝ)))\n + (missedRounds T d).card) := by\n sorry\n\ntheorem lemma6_noWeightedRegret {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (K : ℕ) (hK : 0 < K)\n (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (d : ℕ → ℕ) (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hη_pos : ∀ t ≥ 1, 0 < η t) (hη_dec : ∀ t ≥ 1, η (t + 1) ≤ η t)\n (hη_bound : ∀ t ≥ 1, η t ≤ (1 / 2) * Real.exp (-2))\n (hl : ∀ t ≥ 1, ∀ ω i, l t ω i ∈ Set.Icc (0 : ℝ) 1)\n (E : Exp3Delayed μ K hK l d η η)\n (hl_adapted : ∀ t i, @Measurable Ω ℝ\n (⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance) _\n (fun ω => l t ω i))\n (a_law_adaptive : ∀ t i,\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n ⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance]) =ᵐ[μ]\n (fun ω => E.p t ω i))\n (h1 : Tendsto (fun T : ℕ => ∑ t ∈ Finset.Icc 1 T, η t) atTop atTop)\n (h2 : ∃ L : ℝ, Tendsto (fun t : ℕ => η t * (d t : ℝ)) atTop (nhds L))\n (h3 : Summable (fun t : ℕ => (η t) ^ 2 * (d t : ℝ))) :\n NoWeightedRegret μ K hK η l E.a := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnamespace ResearchLevel\n\nopen scoped Classical\nopen MeasureTheory Filter Topology\n\ndef missedRounds (T : ℕ) (d : ℕ → ℕ) : Finset ℕ :=\n (Finset.Icc 1 T).filter (fun t => T < t + d t)\n\nnoncomputable def MStar (T : ℕ) (d : ℕ → ℕ) (η : ℕ → ℝ) : Finset ℕ :=\n (Finset.Icc 1 T).filter (fun t => T < t + d t ∨ (d t : ℝ) ≥ 1 / (Real.exp 2 * η t) - 1)\n\nnoncomputable def weightedExpReg {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (T K : ℕ) (hK : 0 < K) (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (a : ℕ → Ω → Fin K) : ℝ :=\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n ∫ ω, (∑ t ∈ Finset.Icc 1 T, η t * l t ω (a t ω) -\n (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l t ω i)) ∂μ\n\nnoncomputable def expReg {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (T K : ℕ) (hK : 0 < K) (l0 : ℕ → Fin K → ℝ) (a : ℕ → Ω → Fin K) : ℝ :=\n weightedExpReg μ T K hK (fun _ => 1) (fun t _ i => l0 t i) a\n\nnoncomputable def NoWeightedRegret {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (K : ℕ) (hK : 0 < K) (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (a : ℕ → Ω → Fin K) : Prop :=\n limsup (fun T : ℕ => weightedExpReg μ T K hK η l a / ∑ t ∈ Finset.Icc 1 T, η t)\n atTop ≤ 0\n\nstructure Exp3Delayed {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) (K : ℕ) (hK : 0 < K)\n (l : ℕ → Ω → Fin K → ℝ) (d : ℕ → ℕ) (η γ : ℕ → ℝ) where\n 𝓕 : ℕ → MeasurableSpace Ω\n 𝓕_le : ∀ t, 𝓕 t ≤ ‹MeasurableSpace Ω›\n 𝓕_mono : Monotone 𝓕\n a : ℕ → Ω → Fin K\n p : ℕ → Ω → Fin K → ℝ\n Lhat : ℕ → Ω → Fin K → ℝ\n measurable_a : ∀ t, Measurable (a t)\n 𝓕_eq : ∀ t, 𝓕 t =\n (⨆ s, ⨆ (_ : 1 ≤ s ∧ s + d s ≤ t), MeasurableSpace.comap (a s) inferInstance)\n ⊔ (⨆ s, ⨆ (_ : 1 ≤ s ∧ s ≤ t), MeasurableSpace.comap (l s) inferInstance)\n measurable_p : ∀ t i, @Measurable Ω ℝ (𝓕 t) _ (fun ω => p t ω i)\n p_isProb : ∀ t ω, (∀ i, 0 ≤ p t ω i) ∧ ∑ i, p t ω i = 1\n p_init : ∀ ω i, p 1 ω i = 1 / (K : ℝ)\n a_law : ∀ t i,\n (μ[(fun ω => if a t ω = i then (1 : ℝ) else 0) | 𝓕 t]) =ᵐ[μ] (fun ω => p t ω i)\n Lhat_init : ∀ ω i, Lhat 0 ω i = 0\n Lhat_step : ∀ t ω i, 1 ≤ t →\n Lhat t ω i = Lhat (t - 1) ω i +\n ∑ s ∈ (Finset.Icc 1 t).filter\n (fun s => s + d s = t ∧ (d s : ℝ) ≤ 1 / (Real.exp 2 * η s) - 1 ∧ a s ω = i),\n η s * l s ω i / (p s ω i + γ s)\n p_update : ∀ t ω i,\n p (t + 1) ω i = Real.exp (- Lhat t ω i) / ∑ j, Real.exp (- Lhat t ω j)\n\n-- ############ MACHINERY ############\n\n\nnoncomputable def sfm {K : ℕ} (x : Fin K → ℝ) (i : Fin K) : ℝ :=\n Real.exp (- x i) / ∑ j, Real.exp (- x j)\n\nlemma sfm_denom_pos {K : ℕ} (hK : 0 < K) (x : Fin K → ℝ) :\n 0 < ∑ j, Real.exp (- x j) := by\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n exact Finset.sum_pos (fun j _ => Real.exp_pos _) Finset.univ_nonempty\n\nlemma sfm_pos {K : ℕ} (hK : 0 < K) (x : Fin K → ℝ) (i : Fin K) : 0 < sfm x i :=\n div_pos (Real.exp_pos _) (sfm_denom_pos hK x)\n\nlemma sfm_sum {K : ℕ} (hK : 0 < K) (x : Fin K → ℝ) : ∑ i, sfm x i = 1 := by\n unfold sfm\n rw [← Finset.sum_div, div_self (ne_of_gt (sfm_denom_pos hK x))]\n\n-- Lemma 10\nlemma sfm_l1 {K : ℕ} (hK : 0 < K) (x D : Fin K → ℝ) (hD : ∀ i, 0 ≤ D i) :\n ∑ i, |sfm x i - sfm (fun j => x j + D j) i| ≤ 2 * ∑ i, sfm x i * D i := by\n set Z := ∑ j, Real.exp (- x j) with hZ\n set Z' := ∑ j, Real.exp (- (x j + D j)) with hZ'\n have hZpos : 0 < Z := sfm_denom_pos hK x\n have hZ'pos : 0 < Z' := sfm_denom_pos hK (fun j => x j + D j)\n have hZle : Z' ≤ Z := by\n apply Finset.sum_le_sum\n intro j _\n exact Real.exp_le_exp.2 (by linarith [hD j])\n set S := ∑ j, sfm x j * D j with hS\n have hSnn : 0 ≤ S := Finset.sum_nonneg (fun j _ => mul_nonneg (le_of_lt (sfm_pos hK x j)) (hD j))\n have hA : ∀ i, sfm x i - sfm (fun j => x j + D j) i ≤ D i * sfm x i := by\n intro i\n have h1 : sfm x i * Real.exp (-(D i)) ≤ sfm (fun j => x j + D j) i := by\n show Real.exp (-x i) / Z * Real.exp (-(D i)) ≤ Real.exp (-(x i + D i)) / Z'\n rw [div_mul_eq_mul_div, div_le_div_iff₀ hZpos hZ'pos]\n have h : Real.exp (-x i) * Real.exp (-(D i)) = Real.exp (-(x i + D i)) := by\n rw [← Real.exp_add]; ring_nf\n rw [h]\n exact mul_le_mul_of_nonneg_left hZle (le_of_lt (Real.exp_pos _))\n have h2 : 1 - D i ≤ Real.exp (-(D i)) := by\n have := Real.add_one_le_exp (-(D i)); linarith\n nlinarith [sfm_pos hK x i]\n have hSform : S = (∑ j, Real.exp (-x j) * D j) / Z := by\n rw [hS, Finset.sum_div]\n exact Finset.sum_congr rfl (fun j _ => by show sfm x j * D j = _; unfold sfm; ring)\n have hZZ' : Z - Z' ≤ ∑ j, Real.exp (-x j) * D j := by\n rw [hZ, hZ', ← Finset.sum_sub_distrib]\n apply Finset.sum_le_sum\n intro j _\n have h : Real.exp (-(x j + D j)) = Real.exp (-x j) * Real.exp (-(D j)) := by\n rw [← Real.exp_add]; ring_nf\n rw [h]\n have h2 : 1 - D j ≤ Real.exp (-(D j)) := by\n have := Real.add_one_le_exp (-(D j)); linarith\n nlinarith [Real.exp_pos (-x j)]\n have hB : ∀ i, sfm (fun j => x j + D j) i - sfm x i ≤ sfm (fun j => x j + D j) i * S := by\n intro i\n have h1 : sfm (fun j => x j + D j) i - sfm x i\n ≤ sfm (fun j => x j + D j) i * ((Z - Z')/Z) := by\n show Real.exp (-(x i + D i)) / Z' - Real.exp (-x i) / Z\n ≤ Real.exp (-(x i + D i)) / Z' * ((Z - Z')/Z)\n have hle : Real.exp (-(x i + D i)) ≤ Real.exp (-x i) := by\n apply Real.exp_le_exp.2; linarith [hD i]\n have heq : Real.exp (-(x i + D i)) / Z' * ((Z - Z')/Z)\n = Real.exp (-(x i + D i))/Z' - Real.exp (-(x i+D i))/Z := by\n field_simp\n rw [heq]\n have : Real.exp (-(x i + D i))/Z ≤ Real.exp (-x i)/Z := by gcongr\n linarith\n refine h1.trans ?_\n apply mul_le_mul_of_nonneg_left _ (le_of_lt (sfm_pos hK _ i))\n rw [hSform]\n gcongr\n calc ∑ i, |sfm x i - sfm (fun j => x j + D j) i|\n ≤ ∑ i, (D i * sfm x i + sfm (fun j => x j + D j) i * S) := by\n apply Finset.sum_le_sum\n intro i _\n rw [abs_le]\n constructor\n · have := hB i\n have h1 : 0 ≤ D i * sfm x i := mul_nonneg (hD i) (le_of_lt (sfm_pos hK x i))\n linarith\n · have := hA i\n have h2 : 0 ≤ sfm (fun j => x j + D j) i * S :=\n mul_nonneg (le_of_lt (sfm_pos hK _ i)) hSnn\n linarith\n _ = 2 * S := by\n rw [Finset.sum_add_distrib, ← Finset.sum_mul, sfm_sum hK]\n have : ∑ i, D i * sfm x i = S := by\n rw [hS]; exact Finset.sum_congr rfl (fun i _ => mul_comm _ _)\n rw [this]; ring\n\n/-- A nonnegative loss update can decrease coordinate `i` by at most its old\nprobability times the increment of that coordinate. -/\nprivate lemma sfm_drop_le {K : ℕ} (hK : 0 < K) (x D : Fin K → ℝ)\n (hD : ∀ i, 0 ≤ D i) (i : Fin K) :\n max (sfm x i - sfm (fun j => x j + D j) i) 0 ≤ sfm x i * D i := by\n set Z := ∑ j, Real.exp (-x j) with hZ\n set Z' := ∑ j, Real.exp (-(x j + D j)) with hZ'\n have hZpos : 0 < Z := sfm_denom_pos hK x\n have hZ'pos : 0 < Z' := sfm_denom_pos hK (fun j => x j + D j)\n have hZle : Z' ≤ Z := by\n refine Finset.sum_le_sum (fun j _ => Real.exp_le_exp.2 ?_)\n linarith [hD j]\n have hmul : sfm x i * Real.exp (-(D i)) ≤ sfm (fun j => x j + D j) i := by\n show Real.exp (-x i) / Z * Real.exp (-(D i)) ≤ Real.exp (-(x i + D i)) / Z'\n rw [div_mul_eq_mul_div, div_le_div_iff₀ hZpos hZ'pos]\n have he : Real.exp (-x i) * Real.exp (-(D i)) = Real.exp (-(x i + D i)) := by\n rw [← Real.exp_add]\n ring_nf\n rw [he]\n exact mul_le_mul_of_nonneg_left hZle (le_of_lt (Real.exp_pos _))\n have hexp : 1 - D i ≤ Real.exp (-(D i)) := by\n have := Real.add_one_le_exp (-(D i))\n linarith\n have hdiff : sfm x i - sfm (fun j => x j + D j) i ≤ sfm x i * D i := by\n nlinarith [sfm_pos hK x i]\n exact max_le hdiff (mul_nonneg (le_of_lt (sfm_pos hK x i)) (hD i))\n\nlemma exp_neg_quad (u : ℝ) (hu : 0 ≤ u) : Real.exp (-u) ≤ 1 - u + u^2/2 := by\n have h1 : (1:ℝ) + u + u^2/2 ≤ Real.exp u := Real.quadratic_le_exp_of_nonneg hu\n have h2 : (0:ℝ) < 1 + u + u^2/2 := by nlinarith\n have h3 : Real.exp (-u) = 1 / Real.exp u := by rw [Real.exp_neg]; ring\n rw [h3]\n refine (one_div_le_one_div_of_le h2 h1).trans ?_\n rw [div_le_iff₀ h2]\n nlinarith [sq_nonneg u, sq_nonneg (u^2)]\n\nnoncomputable def pot {K : ℕ} (x : Fin K → ℝ) : ℝ := - Real.log (∑ j, Real.exp (- x j))\n\nlemma pot_le {K : ℕ} (hK : 0 < K) (x : Fin K → ℝ) (i : Fin K) : pot x ≤ x i := by\n unfold pot\n have h1 : Real.exp (- x i) ≤ ∑ j, Real.exp (- x j) :=\n Finset.single_le_sum (f := fun j => Real.exp (- x j)) (fun j _ => le_of_lt (Real.exp_pos _))\n (Finset.mem_univ i)\n have := Real.log_le_log (Real.exp_pos _) h1\n rw [Real.log_exp] at this\n linarith\n\nlemma pot_zero {K : ℕ} (hK : 0 < K) : pot (fun _ : Fin K => (0:ℝ)) = - Real.log K := by\n unfold pot\n simp\n\nlemma pot_step {K : ℕ} (hK : 0 < K) (x D : Fin K → ℝ) (hD : ∀ i, 0 ≤ D i) :\n (∑ i, sfm x i * D i) - (1/2) * ∑ i, sfm x i * (D i)^2\n ≤ pot (fun j => x j + D j) - pot x := by\n set Z := ∑ j, Real.exp (- x j) with hZ\n set Z' := ∑ j, Real.exp (- (x j + D j)) with hZ'\n have hZpos : 0 < Z := sfm_denom_pos hK x\n have hZ'pos : 0 < Z' := sfm_denom_pos hK (fun j => x j + D j)\n set W := Z' / Z with hW\n have hWpos : 0 < W := div_pos hZ'pos hZpos\n have hpotdiff : pot (fun j => x j + D j) - pot x = - Real.log W := by\n unfold pot\n rw [hW, Real.log_div (ne_of_gt hZ'pos) (ne_of_gt hZpos)]\n ring\n have hlog : 1 - W ≤ - Real.log W := by\n have := Real.log_le_sub_one_of_pos hWpos; linarith\n have hWeq : W = ∑ j, sfm x j * Real.exp (- D j) := by\n rw [hW, hZ']\n rw [Finset.sum_div]\n apply Finset.sum_congr rfl\n intro j _\n unfold sfm\n rw [div_mul_eq_mul_div, ← Real.exp_add]\n ring_nf\n rw [hZ]\n have key : (∑ i, sfm x i * D i) - (1/2) * ∑ i, sfm x i * (D i)^2 ≤ 1 - W := by\n rw [hWeq]\n have h1 : ∑ j, sfm x j * Real.exp (- D j)\n ≤ ∑ j, sfm x j * (1 - D j + (D j)^2/2) := by\n apply Finset.sum_le_sum\n intro j _\n exact mul_le_mul_of_nonneg_left (exp_neg_quad (D j) (hD j)) (le_of_lt (sfm_pos hK x j))\n have h2 : ∑ j, sfm x j * (1 - D j + (D j)^2/2)\n = 1 - ((∑ i, sfm x i * D i) - (1/2) * ∑ i, sfm x i * (D i)^2) := by\n have : ∀ j, sfm x j * (1 - D j + (D j)^2/2)\n = sfm x j - sfm x j * D j + (1/2) * (sfm x j * (D j)^2) := by intro j; ring\n simp_rw [this]\n rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, sfm_sum hK, ← Finset.mul_sum]\n ring\n linarith\n linarith\n\nlemma cond_pull {Ω : Type*} {m : MeasurableSpace Ω} [mΩ : MeasurableSpace Ω] (hm : m ≤ mΩ)\n (μ : Measure Ω) [IsFiniteMeasure μ]\n {f g h : Ω → ℝ} (hf : Measurable[m] f) (hf0 : ∀ ω, 0 ≤ f ω)\n (hg : Measurable[mΩ] g) (hg0 : ∀ ω, 0 ≤ g ω) (hgb : ∀ ω, g ω ≤ 1)\n (hh : Measurable[m] h) (hh0 : ∀ ω, 0 ≤ h ω)\n (hcond : μ[g|m] =ᵐ[μ] h)\n (hfh : Integrable (fun ω => f ω * h ω) μ) :\n Integrable (fun ω => f ω * g ω) μ ∧ ∫ ω, f ω * g ω ∂μ = ∫ ω, f ω * h ω ∂μ := by\n haveI : SigmaFinite (μ.trim hm) := by infer_instance\n set fn : ℕ → Ω → ℝ := fun n ω => min (f ω) (n : ℝ) with hfn\n have hfnm : ∀ n, Measurable[m] (fn n) := fun n => hf.min measurable_const\n have hfnM : ∀ n, Measurable[mΩ] (fn n) := fun n => (hfnm n).mono hm le_rfl\n have hfM : Measurable[mΩ] f := hf.mono hm le_rfl\n have hhM : Measurable[mΩ] h := hh.mono hm le_rfl\n have hfn0 : ∀ n ω, 0 ≤ fn n ω := fun n ω => le_min (hf0 ω) (Nat.cast_nonneg n)\n have hfnle : ∀ n ω, fn n ω ≤ f ω := fun n ω => min_le_left _ _\n have hgint : Integrable g μ := by\n refine (integrable_const (1:ℝ)).mono' hg.aestronglyMeasurable (Filter.Eventually.of_forall ?_)\n intro ω; rw [Real.norm_eq_abs, abs_of_nonneg (hg0 ω)]; exact hgb ω\n -- step: for each n, the integrals agree\n have key : ∀ n, ∫ ω, fn n ω * g ω ∂μ = ∫ ω, fn n ω * h ω ∂μ := by\n intro n\n have hb : ∀ᵐ ω ∂μ, ‖fn n ω‖ ≤ (n:ℝ) := by\n refine Filter.Eventually.of_forall (fun ω => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg (hfn0 n ω)]\n exact min_le_right _ _\n have h1 : μ[(fn n) * g|m] =ᵐ[μ] (fn n) * (μ[g|m]) :=\n condExp_stronglyMeasurable_mul_of_bound (μ := μ) hm (hfnm n).stronglyMeasurable hgint (n:ℝ) hb\n have h2 : μ[(fn n) * g|m] =ᵐ[μ] fun ω => fn n ω * h ω := by\n filter_upwards [h1, hcond] with ω hω1 hω2\n simp only [Pi.mul_apply] at hω1 ⊢\n rw [hω1, hω2]\n calc ∫ ω, fn n ω * g ω ∂μ = ∫ ω, (μ[(fn n) * g|m]) ω ∂μ := (integral_condExp hm).symm\n _ = ∫ ω, fn n ω * h ω ∂μ := integral_congr_ae h2\n -- integrability of fn n * h\n have hfnh_int : ∀ n, Integrable (fun ω => fn n ω * h ω) μ := by\n intro n\n refine hfh.mono' ((hfnM n).mul hhM).aestronglyMeasurable (Filter.Eventually.of_forall ?_)\n intro ω\n rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg (hfn0 n ω) (hh0 ω))]\n exact mul_le_mul_of_nonneg_right (hfnle n ω) (hh0 ω)\n have hfnh_le : ∀ n, ∫ ω, fn n ω * h ω ∂μ ≤ ∫ ω, f ω * h ω ∂μ := by\n intro n\n refine integral_mono (hfnh_int n) hfh ?_\n intro ω\n exact mul_le_mul_of_nonneg_right (hfnle n ω) (hh0 ω)\n -- integrability of fn n * g\n have hfng_int : ∀ n, Integrable (fun ω => fn n ω * g ω) μ := by\n intro n\n refine (hgint.const_mul (n:ℝ)).mono' ((hfnM n).mul hg).aestronglyMeasurable\n (Filter.Eventually.of_forall ?_)\n intro ω\n rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg (hfn0 n ω) (hg0 ω))]\n have : fn n ω ≤ (n:ℝ) := min_le_right _ _\n exact mul_le_mul_of_nonneg_right this (hg0 ω)\n -- lintegral bound\n have hlint : ∫⁻ ω, ENNReal.ofReal (f ω * g ω) ∂μ ≤ ENNReal.ofReal (∫ ω, f ω * h ω ∂μ) := by\n have hmono : Monotone (fun n : ℕ => fun ω => ENNReal.ofReal (fn n ω * g ω)) := by\n intro a b hab ω\n simp only\n apply ENNReal.ofReal_le_ofReal\n apply mul_le_mul_of_nonneg_right _ (hg0 ω)\n exact min_le_min_left _ (by exact_mod_cast Nat.cast_le.2 hab)\n have hmeas : ∀ n : ℕ, Measurable (fun ω => ENNReal.ofReal (fn n ω * g ω)) :=\n fun n => ((hfnM n).mul hg).ennreal_ofReal\n have hsup : (fun ω => ⨆ n : ℕ, ENNReal.ofReal (fn n ω * g ω))\n = fun ω => ENNReal.ofReal (f ω * g ω) := by\n funext ω\n apply le_antisymm\n · exact iSup_le (fun n => ENNReal.ofReal_le_ofReal\n (mul_le_mul_of_nonneg_right (hfnle n ω) (hg0 ω)))\n · obtain ⟨n, hn⟩ := exists_nat_ge (f ω)\n refine le_iSup_of_le n ?_\n have : fn n ω = f ω := min_eq_left hn\n rw [this]\n rw [← hsup, lintegral_iSup hmeas hmono]\n refine iSup_le (fun n => ?_)\n rw [← ofReal_integral_eq_lintegral_ofReal (hfng_int n)\n (Filter.Eventually.of_forall (fun ω => mul_nonneg (hfn0 n ω) (hg0 ω)))]\n exact ENNReal.ofReal_le_ofReal ((key n) ▸ hfnh_le n)\n have hfg_int : Integrable (fun ω => f ω * g ω) μ := by\n refine ⟨(hfM.mul hg).aestronglyMeasurable, ?_⟩\n rw [hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall\n (fun ω => mul_nonneg (hf0 ω) (hg0 ω)))]\n exact lt_of_le_of_lt hlint ENNReal.ofReal_lt_top\n refine ⟨hfg_int, ?_⟩\n have lim1 : Filter.Tendsto (fun n => ∫ ω, fn n ω * g ω ∂μ) Filter.atTop\n (nhds (∫ ω, f ω * g ω ∂μ)) := by\n refine tendsto_integral_of_dominated_convergence (fun ω => f ω * g ω)\n (fun n => ((hfnM n).mul hg).aestronglyMeasurable) hfg_int ?_ ?_\n · intro n\n refine Filter.Eventually.of_forall (fun ω => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg (hfn0 n ω) (hg0 ω))]\n exact mul_le_mul_of_nonneg_right (hfnle n ω) (hg0 ω)\n · refine Filter.Eventually.of_forall (fun ω => ?_)\n obtain ⟨N, hN⟩ := exists_nat_ge (f ω)\n apply Filter.Tendsto.congr' _ tendsto_const_nhds\n filter_upwards [Filter.eventually_ge_atTop N] with n hn\n have : fn n ω = f ω := min_eq_left (hN.trans (by exact_mod_cast Nat.cast_le.2 hn))\n rw [this]\n have lim2 : Filter.Tendsto (fun n => ∫ ω, fn n ω * h ω ∂μ) Filter.atTop\n (nhds (∫ ω, f ω * h ω ∂μ)) := by\n refine tendsto_integral_of_dominated_convergence (fun ω => f ω * h ω)\n (fun n => ((hfnM n).mul hhM).aestronglyMeasurable) hfh ?_ ?_\n · intro n\n refine Filter.Eventually.of_forall (fun ω => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg (hfn0 n ω) (hh0 ω))]\n exact mul_le_mul_of_nonneg_right (hfnle n ω) (hh0 ω)\n · refine Filter.Eventually.of_forall (fun ω => ?_)\n obtain ⟨N, hN⟩ := exists_nat_ge (f ω)\n apply Filter.Tendsto.congr' _ tendsto_const_nhds\n filter_upwards [Filter.eventually_ge_atTop N] with n hn\n have : fn n ω = f ω := min_eq_left (hN.trans (by exact_mod_cast Nat.cast_le.2 hn))\n rw [this]\n have : Filter.Tendsto (fun n => ∫ ω, fn n ω * g ω ∂μ) Filter.atTop\n (nhds (∫ ω, f ω * h ω ∂μ)) := by\n simpa only [key] using lim2\n exact tendsto_nhds_unique lim1 this\n\nsection Keys\n\ndef kkey (T : ℕ) (d : ℕ → ℕ) (q : ℕ) : ℕ := (q + d q) * (T+1) + q\n\nlemma nat_lex_lt {T x y a b : ℕ} (ha : a < T+1) (hb : b < T+1) :\n x*(T+1)+a < y*(T+1)+b ↔ (x < y ∨ (x = y ∧ a < b)) := by\n constructor\n · intro h\n rcases lt_trichotomy x y with hxy | hxy | hxy\n · exact Or.inl hxy\n · subst hxy; right; exact ⟨rfl, by omega⟩\n · exfalso\n have : y*(T+1) + (T+1) ≤ x*(T+1) := by\n have : (y+1)*(T+1) ≤ x*(T+1) := Nat.mul_le_mul_right _ hxy\n simpa [add_mul] using this\n omega\n · rintro (hxy | ⟨rfl, hab⟩)\n · have : (x+1)*(T+1) ≤ y*(T+1) := Nat.mul_le_mul_right _ hxy\n rw [add_mul, one_mul] at this\n omega\n · omega\n\nlemma kkey_lt_iff {T : ℕ} {d : ℕ → ℕ} {q q' : ℕ} (hq : q ≤ T) (hq' : q' ≤ T) :\n kkey T d q < kkey T d q' ↔\n ((q + d q < q' + d q') ∨ (q + d q = q' + d q' ∧ q < q')) := by\n unfold kkey\n exact nat_lex_lt (by omega) (by omega)\n\nlemma kkey_inj {T : ℕ} {d : ℕ → ℕ} {q q' : ℕ} (hq : q ≤ T) (hq' : q' ≤ T)\n (h : kkey T d q = kkey T d q') : q = q' := by\n by_contra hne\n rcases lt_or_gt_of_ne hne with hlt | hlt\n · have := (kkey_lt_iff (T := T) (d := d) hq hq').2 (by\n rcases lt_trichotomy (q + d q) (q' + d q') with h1|h1|h1\n · exact Or.inl h1\n · exact Or.inr ⟨h1, hlt⟩\n · exfalso\n have := (kkey_lt_iff (T := T) (d := d) hq' hq).2 (Or.inl h1)\n omega)\n omega\n · have := (kkey_lt_iff (T := T) (d := d) hq' hq).2 (by\n rcases lt_trichotomy (q' + d q') (q + d q) with h1|h1|h1\n · exact Or.inl h1\n · exact Or.inr ⟨h1, hlt⟩\n · exfalso\n have := (kkey_lt_iff (T := T) (d := d) hq hq').2 (Or.inl h1)\n omega)\n omega\n\nlemma kkey_lt_time {T : ℕ} {d : ℕ → ℕ} {q t : ℕ} (hq : q ≤ T) :\n kkey T d q < (t+1)*(T+1) ↔ q + d q ≤ t := by\n unfold kkey\n constructor\n · intro h\n by_contra hc\n push_neg at hc\n have : (t+1)*(T+1) ≤ (q + d q)*(T+1) := Nat.mul_le_mul_right _ hc\n omega\n · intro h\n have : (q+d q)*(T+1) ≤ t*(T+1) := Nat.mul_le_mul_right _ h\n have h2 : (t+1)*(T+1) = t*(T+1) + (T+1) := by ring\n omega\n\nend Keys\n\n\nstructure AlgData (Ω : Type*) (K : ℕ) where\n T : ℕ\n d : ℕ → ℕ\n η : ℕ → ℝ\n γ : ℕ → ℝ\n a : ℕ → Ω → Fin K\n l : ℕ → Ω → Fin K → ℝ\n p : ℕ → Ω → Fin K → ℝ\n\nnoncomputable def bset {Ω : Type*} {K : ℕ} (A : AlgData Ω K) : Finset ℕ :=\n (Finset.Icc 1 A.T).filter\n (fun q => q + A.d q ≤ A.T ∧ (A.d q : ℝ) ≤ 1/(Real.exp 2 * A.η q) - 1)\n\nnoncomputable def ltil {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (q : ℕ) (ω : Ω) (i : Fin K) : ℝ :=\n A.l q ω i * (if A.a q ω = i then (1:ℝ) else 0) / (A.p q ω i + A.γ q)\n\nnoncomputable def GG {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (n : ℕ) (ω : Ω) (i : Fin K) : ℝ :=\n ∑ q ∈ (bset A).filter (fun q => kkey A.T A.d q < n), A.η q * ltil A q ω i\n\nlemma mem_bset {Ω : Type*} {K : ℕ} {A : AlgData Ω K} {q : ℕ} :\n q ∈ bset A ↔ (1 ≤ q ∧ q ≤ A.T) ∧ (q + A.d q ≤ A.T ∧\n (A.d q : ℝ) ≤ 1/(Real.exp 2 * A.η q) - 1) := by\n unfold bset\n simp [Finset.mem_filter, Finset.mem_Icc, and_assoc]\n\nlemma bset_le_T {Ω : Type*} {K : ℕ} {A : AlgData Ω K} {q : ℕ} (h : q ∈ bset A) : q ≤ A.T :=\n (mem_bset.1 h).1.2\n\nlemma filter_split {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (n : ℕ) :\n (bset A).filter (fun q => kkey A.T A.d q < n+1)\n = (bset A).filter (fun q => kkey A.T A.d q < n)\n ∪ (bset A).filter (fun q => kkey A.T A.d q = n) := by\n rw [← Finset.filter_or]\n apply Finset.filter_congr\n intro x _\n simp [Nat.lt_succ_iff_lt_or_eq]\n\nlemma GG_succ_mem {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (n q : ℕ) (hq : q ∈ bset A)\n (hkq : kkey A.T A.d q = n) (ω : Ω) (i : Fin K) :\n GG A (n+1) ω i = GG A n ω i + A.η q * ltil A q ω i := by\n unfold GG\n rw [filter_split A n]\n rw [Finset.sum_union (by\n simp only [Finset.disjoint_left, Finset.mem_filter]\n rintro x ⟨-, h1⟩ ⟨-, h2⟩; omega)]\n congr 1\n have : (bset A).filter (fun x => kkey A.T A.d x = n) = {q} := by\n apply Finset.eq_singleton_iff_unique_mem.2\n refine ⟨Finset.mem_filter.2 ⟨hq, hkq⟩, ?_⟩\n intro x hx\n rw [Finset.mem_filter] at hx\n exact kkey_inj (bset_le_T hx.1) (bset_le_T hq) (by rw [hx.2, hkq])\n rw [this, Finset.sum_singleton]\n\nlemma GG_succ_not {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (n : ℕ)\n (h : ∀ q ∈ bset A, kkey A.T A.d q ≠ n) (ω : Ω) (i : Fin K) :\n GG A (n+1) ω i = GG A n ω i := by\n unfold GG\n rw [filter_split A n]\n rw [Finset.sum_union (by\n simp only [Finset.disjoint_left, Finset.mem_filter]\n rintro x ⟨-, h1⟩ ⟨-, h2⟩; omega)]\n have : (bset A).filter (fun x => kkey A.T A.d x = n) = ∅ := by\n apply Finset.filter_false_of_mem\n intro x hx; exact h x hx\n rw [this, Finset.sum_empty, add_zero]\n\nlemma kkey_lt_N {Ω : Type*} {K : ℕ} {A : AlgData Ω K} {q : ℕ} (hq : q ∈ bset A) :\n kkey A.T A.d q < (A.T+1)*(A.T+1) := by\n rw [mem_bset] at hq\n have h1 : q + A.d q ≤ A.T := hq.2.1\n have h2 : q ≤ A.T := hq.1.2\n unfold kkey\n have : (q + A.d q)*(A.T+1) ≤ A.T*(A.T+1) := Nat.mul_le_mul_right _ h1\n have h3 : (A.T+1)*(A.T+1) = A.T*(A.T+1) + (A.T+1) := by ring\n omega\n\n/-- Sum over `n < N` of a function that vanishes off the image of `kkey` equals the sum over\n`bset`. -/\nlemma sum_range_eq_sum_bset {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (F : ℕ → ℝ)\n (hF : ∀ n, (∀ q ∈ bset A, kkey A.T A.d q ≠ n) → F n = 0) :\n ∑ n ∈ Finset.range ((A.T+1)*(A.T+1)), F n = ∑ q ∈ bset A, F (kkey A.T A.d q) := by\n rw [← Finset.sum_image (f := F) (g := kkey A.T A.d)\n (by intro x hx y hy h; exact kkey_inj (bset_le_T hx) (bset_le_T hy) h)]\n symm\n apply Finset.sum_subset\n · intro x hx\n rw [Finset.mem_image] at hx\n obtain ⟨q, hq, rfl⟩ := hx\n exact Finset.mem_range.2 (kkey_lt_N hq)\n · intro x _ hx\n apply hF\n intro q hq hcon\n exact hx (Finset.mem_image.2 ⟨q, hq, hcon⟩)\n\nnoncomputable def PP {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (n : ℕ) (ω : Ω) (i : Fin K) : ℝ :=\n sfm (GG A n ω) i\n\nstructure AlgOK {Ω : Type*} {K : ℕ} (A : AlgData Ω K) : Prop where\n hK : 0 < K\n hd : ∀ t, 1 ≤ t → 1 ≤ A.d t\n hηpos : ∀ t, 0 < A.η t\n hηdec : ∀ t, A.η (t+1) ≤ A.η t\n hηb : ∀ t, A.η t ≤ (1/2) * Real.exp (-2)\n hl0 : ∀ t ω i, 0 ≤ A.l t ω i\n hl1 : ∀ t ω i, A.l t ω i ≤ 1\n hγ : ∀ t, 0 ≤ A.γ t\n hp : ∀ t ω i, 1 ≤ t → t ≤ A.T + 1 → A.p t ω i = sfm (GG A (t * (A.T+1)) ω) i\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma eta_anti (hA : AlgOK A) : ∀ {s t : ℕ}, s ≤ t → A.η t ≤ A.η s := by\n intro s t h\n exact antitone_nat_of_succ_le (fun n => hA.hηdec n) h\n\nlemma p_pos (hA : AlgOK A) {t : ℕ} (h1 : 1 ≤ t) (h2 : t ≤ A.T + 1) (ω : Ω) (i : Fin K) :\n 0 < A.p t ω i := by\n rw [hA.hp t ω i h1 h2]; exact sfm_pos hA.hK _ _\n\nlemma p_pos_bset (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) (i : Fin K) :\n 0 < A.p q ω i := by\n rw [mem_bset] at hq\n exact hA.p_pos hq.1.1 (by omega) ω i\n\nlemma pg_pos (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) (i : Fin K) :\n 0 < A.p q ω i + A.γ q :=\n add_pos_of_pos_of_nonneg (hA.p_pos_bset hq ω i) (hA.hγ q)\n\nlemma ltil_nonneg (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) (i : Fin K) :\n 0 ≤ ltil A q ω i := by\n unfold ltil\n apply div_nonneg _ (le_of_lt (hA.pg_pos hq ω i))\n exact mul_nonneg (hA.hl0 _ _ _) (by positivity)\n\nlemma sum_ltil (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) :\n ∑ i, ltil A q ω i = A.l q ω (A.a q ω) / (A.p q ω (A.a q ω) + A.γ q) := by\n unfold ltil\n rw [Finset.sum_eq_single (A.a q ω)]\n · simp\n · intro b _ hb\n simp [Ne.symm hb]\n · intro h; exact absurd (Finset.mem_univ _) h\n\nlemma sum_p_ltil (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) :\n ∑ i, A.p q ω i * ltil A q ω i\n = A.l q ω (A.a q ω) - A.γ q * ∑ i, ltil A q ω i := by\n have h1 : ∑ i, A.p q ω i * ltil A q ω i\n = A.p q ω (A.a q ω) * ltil A q ω (A.a q ω) := by\n rw [Finset.sum_eq_single (A.a q ω)]\n · intro b _ hb\n unfold ltil\n simp [Ne.symm hb]\n · intro h; exact absurd (Finset.mem_univ _) h\n rw [h1, hA.sum_ltil hq ω]\n have hpg := hA.pg_pos hq ω (A.a q ω)\n have hlt : ltil A q ω (A.a q ω) = A.l q ω (A.a q ω) / (A.p q ω (A.a q ω) + A.γ q) := by\n unfold ltil; simp\n rw [hlt]\n field_simp\n ring\n\nlemma GG_mono (hA : AlgOK A) {n n' : ℕ} (h : n ≤ n') (ω : Ω) (i : Fin K) :\n GG A n ω i ≤ GG A n' ω i := by\n unfold GG\n apply Finset.sum_le_sum_of_subset_of_nonneg\n · intro x hx\n rw [Finset.mem_filter] at hx ⊢\n exact ⟨hx.1, lt_of_lt_of_le hx.2 h⟩\n · intro x hx _\n rw [Finset.mem_filter] at hx\n exact mul_nonneg (le_of_lt (hA.hηpos x)) (hA.ltil_nonneg hx.1 ω i)\n\nlemma GG_zero (A : AlgData Ω K) (ω : Ω) (i : Fin K) : GG A 0 ω i = 0 := by\n unfold GG\n rw [Finset.filter_false_of_mem (fun x _ => by omega), Finset.sum_empty]\n\nlemma GG_full (A : AlgData Ω K) (ω : Ω) (i : Fin K) :\n GG A ((A.T+1)*(A.T+1)) ω i = ∑ q ∈ bset A, A.η q * ltil A q ω i := by\n unfold GG\n congr 1\n apply Finset.filter_true_of_mem\n intro x hx\n exact kkey_lt_N hx\n\nend AlgOK\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma p_ltil_sq_le (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) (i : Fin K) :\n A.p q ω i * (ltil A q ω i)^2 ≤ ltil A q ω i := by\n set u := ltil A q ω i with hu\n have hu0 : 0 ≤ u := hA.ltil_nonneg hq ω i\n have hpg := hA.pg_pos hq ω i\n have hp0 : 0 ≤ A.p q ω i := le_of_lt (hA.p_pos_bset hq ω i)\n have hlx : A.l q ω i * (if A.a q ω = i then (1:ℝ) else 0) ≤ 1 := by\n by_cases h : A.a q ω = i\n · rw [if_pos h, mul_one]; exact hA.hl1 _ _ _\n · rw [if_neg h]; simp\n have hlx0 : 0 ≤ A.l q ω i * (if A.a q ω = i then (1:ℝ) else 0) :=\n mul_nonneg (hA.hl0 _ _ _) (by positivity)\n have hpu : A.p q ω i * u ≤ 1 := by\n rw [hu]\n unfold ltil\n rw [mul_div_assoc'] at *\n rw [div_le_one hpg]\n nlinarith [hA.hγ q]\n nlinarith\n\nlemma quad_bound (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) (n : ℕ)\n (hr : ∀ i, PP A n ω i ≤ Real.exp 2 * A.p q ω i) :\n ∑ i, PP A n ω i * (ltil A q ω i)^2 ≤ Real.exp 2 * ∑ i, ltil A q ω i := by\n rw [Finset.mul_sum]\n apply Finset.sum_le_sum\n intro i _\n have h1 : PP A n ω i * (ltil A q ω i)^2\n ≤ (Real.exp 2 * A.p q ω i) * (ltil A q ω i)^2 :=\n mul_le_mul_of_nonneg_right (hr i) (sq_nonneg _)\n have h2 : (Real.exp 2 * A.p q ω i) * (ltil A q ω i)^2\n ≤ Real.exp 2 * ltil A q ω i := by\n rw [mul_assoc]\n exact mul_le_mul_of_nonneg_left (hA.p_ltil_sq_le hq ω i) (le_of_lt (Real.exp_pos 2))\n linarith\n\nlemma core_pathwise (hA : AlgOK A) (ω : Ω) (istar : Fin K)\n (hratio : ∀ q ∈ bset A, ∀ i, PP A (kkey A.T A.d q) ω i ≤ Real.exp 2 * A.p q ω i) :\n ∑ q ∈ bset A, A.η q * A.l q ω (A.a q ω)\n ≤ Real.log K + ∑ q ∈ bset A, A.η q * ltil A q ω istar\n + ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i\n + ∑ q ∈ bset A, A.η q * ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i)\n * ltil A q ω i := by\n set N := (A.T+1)*(A.T+1) with hN\n set F : ℕ → ℝ := fun n => (∑ i, PP A n ω i * (GG A (n+1) ω i - GG A n ω i))\n - (1/2) * ∑ i, PP A n ω i * (GG A (n+1) ω i - GG A n ω i)^2 with hF\n have hstep : ∀ n, F n ≤ pot (GG A (n+1) ω) - pot (GG A n ω) := by\n intro n\n have hD : ∀ i, 0 ≤ GG A (n+1) ω i - GG A n ω i := by\n intro i; have := hA.GG_mono (Nat.le_succ n) ω i; linarith\n have := pot_step hA.hK (GG A n ω) (fun i => GG A (n+1) ω i - GG A n ω i) hD\n have heq : (fun j => GG A n ω j + (GG A (n+1) ω j - GG A n ω j)) = GG A (n+1) ω := by\n funext j; ring\n rw [heq] at this\n exact this\n have hsumF : ∑ n ∈ Finset.range N, F n ≤ pot (GG A N ω) - pot (GG A 0 ω) := by\n calc ∑ n ∈ Finset.range N, F n\n ≤ ∑ n ∈ Finset.range N, (pot (GG A (n+1) ω) - pot (GG A n ω)) :=\n Finset.sum_le_sum (fun n _ => hstep n)\n _ = pot (GG A N ω) - pot (GG A 0 ω) :=\n Finset.sum_range_sub (fun n => pot (GG A n ω)) N\n have hFzero : ∀ n, (∀ q ∈ bset A, kkey A.T A.d q ≠ n) → F n = 0 := by\n intro n h\n have := GG_succ_not A n h ω\n simp only [hF]\n have h2 : ∀ i, GG A (n+1) ω i - GG A n ω i = 0 := by\n intro i; rw [this i]; ring\n simp [h2]\n have hFkey : ∀ q ∈ bset A, F (kkey A.T A.d q)\n = A.η q * (∑ i, PP A (kkey A.T A.d q) ω i * ltil A q ω i)\n - (1/2) * (A.η q)^2 * (∑ i, PP A (kkey A.T A.d q) ω i * (ltil A q ω i)^2) := by\n intro q hq\n have hg : ∀ i, GG A (kkey A.T A.d q + 1) ω i - GG A (kkey A.T A.d q) ω i\n = A.η q * ltil A q ω i := by\n intro i\n rw [GG_succ_mem A (kkey A.T A.d q) q hq rfl ω i]; ring\n have e1 : ∑ i, PP A (kkey A.T A.d q) ω i\n * (GG A (kkey A.T A.d q + 1) ω i - GG A (kkey A.T A.d q) ω i)\n = A.η q * ∑ i, PP A (kkey A.T A.d q) ω i * ltil A q ω i := by\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun i _ => by rw [hg i]; ring)\n have e2 : ∑ i, PP A (kkey A.T A.d q) ω i\n * (GG A (kkey A.T A.d q + 1) ω i - GG A (kkey A.T A.d q) ω i)^2\n = (A.η q)^2 * ∑ i, PP A (kkey A.T A.d q) ω i * (ltil A q ω i)^2 := by\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun i _ => by rw [hg i]; ring)\n simp only [hF]\n rw [e1, e2]\n ring\n have hpot0 : pot (GG A 0 ω) = - Real.log K := by\n have : GG A 0 ω = fun _ : Fin K => (0:ℝ) := by funext i; exact AlgOK.GG_zero A ω i\n rw [this, pot_zero hA.hK]\n have hpotN : pot (GG A N ω) ≤ ∑ q ∈ bset A, A.η q * ltil A q ω istar := by\n have := pot_le hA.hK (GG A N ω) istar\n rw [AlgOK.GG_full A ω istar] at this\n exact this\n have h5 : ∑ q ∈ bset A, (A.η q * (∑ i, PP A (kkey A.T A.d q) ω i * ltil A q ω i)\n - (1/2) * (A.η q)^2 * (∑ i, PP A (kkey A.T A.d q) ω i * (ltil A q ω i)^2))\n ≤ Real.log K + ∑ q ∈ bset A, A.η q * ltil A q ω istar := by\n rw [← Finset.sum_congr rfl hFkey, ← sum_range_eq_sum_bset A F hFzero]\n rw [hpot0] at hsumF\n linarith\n have h6 : ∀ q ∈ bset A, A.η q * A.l q ω (A.a q ω)\n ≤ (A.η q * (∑ i, PP A (kkey A.T A.d q) ω i * ltil A q ω i)\n - (1/2) * (A.η q)^2 * (∑ i, PP A (kkey A.T A.d q) ω i * (ltil A q ω i)^2))\n + (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (∑ i, ltil A q ω i)\n + A.η q * ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i) * ltil A q ω i := by\n intro q hq\n have hsplit : ∑ i, A.p q ω i * ltil A q ω i\n = (∑ i, PP A (kkey A.T A.d q) ω i * ltil A q ω i)\n + ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i) * ltil A q ω i := by\n rw [← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n have hL := hA.sum_p_ltil hq ω\n have hqb := hA.quad_bound hq ω (kkey A.T A.d q) (hratio q hq)\n have hc0 : 0 ≤ ∑ i, ltil A q ω i :=\n Finset.sum_nonneg (fun i _ => hA.ltil_nonneg hq ω i)\n have hη0 : 0 ≤ A.η q := le_of_lt (hA.hηpos q)\n nlinarith [sq_nonneg (A.η q)]\n calc ∑ q ∈ bset A, A.η q * A.l q ω (A.a q ω)\n ≤ ∑ q ∈ bset A, ((A.η q * (∑ i, PP A (kkey A.T A.d q) ω i * ltil A q ω i)\n - (1/2) * (A.η q)^2 * (∑ i, PP A (kkey A.T A.d q) ω i * (ltil A q ω i)^2))\n + (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (∑ i, ltil A q ω i)\n + A.η q * ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i) * ltil A q ω i) :=\n Finset.sum_le_sum h6\n _ = (∑ q ∈ bset A, (A.η q * (∑ i, PP A (kkey A.T A.d q) ω i * ltil A q ω i)\n - (1/2) * (A.η q)^2 * (∑ i, PP A (kkey A.T A.d q) ω i * (ltil A q ω i)^2)))\n + (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (∑ i, ltil A q ω i))\n + (∑ q ∈ bset A, A.η q * ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i)\n * ltil A q ω i) := by\n rw [Finset.sum_add_distrib, Finset.sum_add_distrib]\n _ ≤ _ := by linarith\n\nend AlgOK\n\nlemma sfm_step_ratio {K : ℕ} (hK : 0 < K) (x D : Fin K → ℝ) (hD : ∀ i, 0 ≤ D i)\n (c : ℝ) (hc : c < 1) (hS : ∑ j, sfm x j * D j ≤ c) (i : Fin K) :\n sfm (fun j => x j + D j) i ≤ (1 - c)⁻¹ * sfm x i := by\n set Z := ∑ j, Real.exp (- x j) with hZ\n set Z' := ∑ j, Real.exp (- (x j + D j)) with hZ'\n have hZpos : 0 < Z := sfm_denom_pos hK x\n have hZ'pos : 0 < Z' := sfm_denom_pos hK (fun j => x j + D j)\n have hc1 : 0 < 1 - c := by linarith\n have hSform : ∑ j, sfm x j * D j = (∑ j, Real.exp (-x j) * D j) / Z := by\n rw [Finset.sum_div]\n exact Finset.sum_congr rfl (fun j _ => by show sfm x j * D j = _; unfold sfm; ring)\n have hlow : Z * (1 - c) ≤ Z' := by\n have h1 : Z - (∑ j, Real.exp (-x j) * D j) ≤ Z' := by\n rw [hZ, hZ', ← Finset.sum_sub_distrib]\n apply Finset.sum_le_sum\n intro j _\n have h : Real.exp (-(x j + D j)) = Real.exp (-x j) * Real.exp (-(D j)) := by\n rw [← Real.exp_add]; ring_nf\n rw [h]\n have h2 : 1 - D j ≤ Real.exp (-(D j)) := by\n have := Real.add_one_le_exp (-(D j)); linarith\n nlinarith [Real.exp_pos (-x j)]\n have h3 : (∑ j, Real.exp (-x j) * D j) ≤ Z * c := by\n rw [hSform] at hS\n rw [div_le_iff₀ hZpos] at hS\n linarith\n nlinarith\n have hZc : 0 < Z * (1 - c) := mul_pos hZpos hc1\n have hnum : Real.exp (-(x i + D i)) ≤ Real.exp (- x i) := by\n apply Real.exp_le_exp.2; linarith [hD i]\n show Real.exp (-(x i + D i)) / Z' ≤ (1-c)⁻¹ * (Real.exp (-x i) / Z)\n have : (1-c)⁻¹ * (Real.exp (-x i) / Z) = Real.exp (-x i) / (Z * (1-c)) := by\n field_simp\n rw [this]\n rw [div_le_div_iff₀ hZ'pos hZc]\n nlinarith [Real.exp_pos (-(x i + D i)), Real.exp_pos (-x i)]\n\nlemma pow_inv_le_exp1 {η : ℝ} {D c : ℕ} (hηp : 0 < η) (hD : 1 ≤ D)\n (h : (D:ℝ) ≤ 1/(Real.exp 2 * η) - 1) (hc : c ≤ D) :\n ((1 - Real.exp 2 * η)⁻¹)^c ≤ Real.exp 1 := by\n have hD1 : (1:ℝ) ≤ (D:ℝ) := by exact_mod_cast hD\n have hDp : (0:ℝ) < (D:ℝ) := by linarith\n have he2 : 0 < Real.exp 2 * η := mul_pos (Real.exp_pos 2) hηp\n have h1 : Real.exp 2 * η ≤ 1/((D:ℝ)+1) := by\n have h' : (D:ℝ) + 1 ≤ 1/(Real.exp 2 * η) := by linarith\n rw [le_div_iff₀ he2] at h'\n rw [le_div_iff₀ (by linarith : (0:ℝ) < (D:ℝ)+1)]\n linarith\n have hfrac : (1:ℝ)/((D:ℝ)+1) ≤ 1/2 := by\n apply one_div_le_one_div_of_le (by norm_num) (by linarith)\n have h2 : 0 < 1 - Real.exp 2 * η := by linarith\n have h3 : (D:ℝ)/((D:ℝ)+1) ≤ 1 - Real.exp 2 * η := by\n have hh : (D:ℝ)/((D:ℝ)+1) = 1 - 1/((D:ℝ)+1) := by\n field_simp\n ring\n linarith [hh]\n have h4 : (1 - Real.exp 2 * η)⁻¹ ≤ ((D:ℝ)+1)/(D:ℝ) := by\n have hpos : (0:ℝ) < (D:ℝ)/((D:ℝ)+1) := by positivity\n have := one_div_le_one_div_of_le hpos h3\n rw [one_div, one_div, inv_div] at this\n exact this\n have h5 : ((D:ℝ)+1)/(D:ℝ) ≤ Real.exp (1/(D:ℝ)) := by\n have hh : ((D:ℝ)+1)/(D:ℝ) = 1/(D:ℝ) + 1 := by\n field_simp\n ring\n rw [hh]\n exact Real.add_one_le_exp _\n have h6 : (1 - Real.exp 2 * η)⁻¹ ≤ Real.exp (1/(D:ℝ)) := le_trans h4 h5\n calc ((1 - Real.exp 2 * η)⁻¹)^c ≤ (Real.exp (1/(D:ℝ)))^c := by\n gcongr\n _ = Real.exp ((c:ℝ) * (1/(D:ℝ))) := (Real.exp_nat_mul _ _).symm\n _ ≤ Real.exp 1 := by\n apply Real.exp_le_exp.2\n rw [mul_one_div, div_le_one hDp]\n exact_mod_cast hc\n\nnoncomputable def Fprod {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (m₁ m₂ : ℕ) : ℝ :=\n ∏ r ∈ (bset A).filter (fun r => m₁ ≤ kkey A.T A.d r ∧ kkey A.T A.d r < m₂),\n (1 - Real.exp 2 * A.η r)⁻¹\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma e2eta_le_half (hA : AlgOK A) (t : ℕ) : Real.exp 2 * A.η t ≤ 1/2 := by\n have h := hA.hηb t\n have h2 : Real.exp 2 * ((1/2) * Real.exp (-2)) = 1/2 := by\n rw [← mul_assoc, mul_comm (Real.exp 2), mul_assoc, ← Real.exp_add]\n norm_num\n calc Real.exp 2 * A.η t ≤ Real.exp 2 * ((1/2) * Real.exp (-2)) := by\n exact mul_le_mul_of_nonneg_left h (le_of_lt (Real.exp_pos 2))\n _ = 1/2 := h2\n\nlemma one_sub_pos (hA : AlgOK A) (t : ℕ) : 0 < 1 - Real.exp 2 * A.η t := by\n have := hA.e2eta_le_half t; linarith\n\nlemma inv_one_sub_nonneg (hA : AlgOK A) (t : ℕ) : 0 ≤ (1 - Real.exp 2 * A.η t)⁻¹ :=\n le_of_lt (inv_pos.2 (hA.one_sub_pos t))\n\nlemma Fprod_self (A : AlgData Ω K) (m : ℕ) : Fprod A m m = 1 := by\n unfold Fprod\n rw [Finset.filter_false_of_mem (fun x _ => by omega), Finset.prod_empty]\n\nlemma Fprod_nonneg (hA : AlgOK A) (m₁ m₂ : ℕ) : 0 ≤ Fprod A m₁ m₂ :=\n Finset.prod_nonneg (fun r _ => hA.inv_one_sub_nonneg r)\n\nlemma Fprod_succ_mem (A : AlgData Ω K) {m₁ m₂ : ℕ} (hm : m₁ ≤ m₂) {r : ℕ}\n (hr : r ∈ bset A) (hkr : kkey A.T A.d r = m₂) :\n Fprod A m₁ (m₂+1) = Fprod A m₁ m₂ * (1 - Real.exp 2 * A.η r)⁻¹ := by\n unfold Fprod\n have hsplit : (bset A).filter (fun x => m₁ ≤ kkey A.T A.d x ∧ kkey A.T A.d x < m₂+1)\n = (bset A).filter (fun x => m₁ ≤ kkey A.T A.d x ∧ kkey A.T A.d x < m₂)\n ∪ (bset A).filter (fun x => kkey A.T A.d x = m₂) := by\n rw [← Finset.filter_or]\n apply Finset.filter_congr\n intro x _\n constructor\n · rintro ⟨ha, hb⟩\n rcases Nat.lt_or_ge (kkey A.T A.d x) m₂ with h | h\n · exact Or.inl ⟨ha, h⟩\n · exact Or.inr (by omega)\n · rintro (⟨ha, hb⟩ | h)\n · exact ⟨ha, by omega⟩\n · exact ⟨by omega, by omega⟩\n rw [hsplit, Finset.prod_union (by\n simp only [Finset.disjoint_left, Finset.mem_filter]\n rintro x ⟨-, -, h1��� ⟨-, h2⟩; omega)]\n congr 1\n have : (bset A).filter (fun x => kkey A.T A.d x = m₂) = {r} := by\n apply Finset.eq_singleton_iff_unique_mem.2\n refine ⟨Finset.mem_filter.2 ⟨hr, hkr⟩, ?_⟩\n intro x hx\n rw [Finset.mem_filter] at hx\n exact kkey_inj (bset_le_T hx.1) (bset_le_T hr) (by rw [hx.2, hkr])\n rw [this, Finset.prod_singleton]\n\nlemma Fprod_succ_not (A : AlgData Ω K) {m₁ m₂ : ℕ} (hm : m₁ ≤ m₂)\n (h : ∀ r ∈ bset A, kkey A.T A.d r ≠ m₂) :\n Fprod A m₁ (m₂+1) = Fprod A m₁ m₂ := by\n unfold Fprod\n apply Finset.prod_congr _ (fun _ _ => rfl)\n apply Finset.filter_congr\n intro x hx\n constructor\n · rintro ⟨ha, hb⟩\n refine ⟨ha, ?_⟩\n rcases Nat.lt_or_ge (kkey A.T A.d x) m₂ with h1 | h1\n · exact h1\n · exact absurd (by omega : kkey A.T A.d x = m₂) (h x hx)\n · rintro ⟨ha, hb⟩; exact ⟨ha, by omega⟩\n\nlemma PP_eq_of_GG_eq (A : AlgData Ω K) {n n' : ℕ} (ω : Ω)\n (h : ∀ i, GG A n ω i = GG A n' ω i) (i : Fin K) : PP A n ω i = PP A n' ω i := by\n unfold PP\n congr 1\n funext j\n exact h j\n\nlemma prod_ratio (hA : AlgOK A) (ω : Ω) (m₁ n₀ : ℕ)\n (H : ∀ m, m < n₀ → ∀ r ∈ bset A, kkey A.T A.d r = m → ∀ i,\n PP A (m+1) ω i ≤ (1 - Real.exp 2 * A.η r)⁻¹ * PP A m ω i) :\n ∀ m₂, m₁ ≤ m₂ → m₂ ≤ n₀ → ∀ i, PP A m₂ ω i ≤ (Fprod A m₁ m₂) * PP A m₁ ω i := by\n intro m₂\n induction m₂ with\n | zero =>\n intro h1 h2 i\n have : m₁ = 0 := by omega\n subst this\n rw [AlgOK.Fprod_self A, one_mul]\n | succ n ih =>\n intro h1 h2 i\n rcases Nat.eq_or_lt_of_le h1 with heq | hlt\n · rw [← heq, AlgOK.Fprod_self A, one_mul]\n · have hmn : m₁ ≤ n := by omega\n have hstep := ih hmn (by omega) i\n by_cases hex : ∃ r ∈ bset A, kkey A.T A.d r = n\n · obtain ⟨r, hr, hkr⟩ := hex\n have h3 := H n (by omega) r hr hkr i\n rw [AlgOK.Fprod_succ_mem A hmn hr hkr]\n have hc : 0 ≤ (1 - Real.exp 2 * A.η r)⁻¹ := hA.inv_one_sub_nonneg r\n calc PP A (n+1) ω i ≤ (1 - Real.exp 2 * A.η r)⁻¹ * PP A n ω i := h3\n _ ≤ (1 - Real.exp 2 * A.η r)⁻¹ * ((Fprod A m₁ n) * PP A m₁ ω i) :=\n mul_le_mul_of_nonneg_left hstep hc\n _ = Fprod A m₁ n * (1 - Real.exp 2 * A.η r)⁻¹ * PP A m₁ ω i := by ring\n · push_neg at hex\n rw [AlgOK.Fprod_succ_not A hmn hex]\n have : PP A (n+1) ω i = PP A n ω i :=\n AlgOK.PP_eq_of_GG_eq A ω (fun j => GG_succ_not A n hex ω j) i\n rw [this]\n exact hstep\n\nend AlgOK\n\nlemma prod_le_pow_card_nonneg {ι : Type*} (s : Finset ι) (f : ι → ℝ) (n : ℝ)\n (h0 : ∀ x ∈ s, 0 ≤ f x) (h : ∀ x ∈ s, f x ≤ n) : ∏ x ∈ s, f x ≤ n ^ s.card := by\n calc ∏ x ∈ s, f x ≤ ∏ _x ∈ s, n := Finset.prod_le_prod h0 h\n _ = n ^ s.card := Finset.prod_const n\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma inv_mono (hA : AlgOK A) {r s : ℕ} (h : A.η r ≤ A.η s) :\n (1 - Real.exp 2 * A.η r)⁻¹ ≤ (1 - Real.exp 2 * A.η s)⁻¹ := by\n have h1 := hA.one_sub_pos r\n have h2 := hA.one_sub_pos s\n have hmul : Real.exp 2 * A.η r ≤ Real.exp 2 * A.η s :=\n mul_le_mul_of_nonneg_left h (le_of_lt (Real.exp_pos 2))\n have h3 : 1 - Real.exp 2 * A.η s ≤ 1 - Real.exp 2 * A.η r := by linarith\n have h4 := one_div_le_one_div_of_le h2 h3\n rwa [one_div, one_div] at h4\n\nlemma Fprod_bound (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) :\n Fprod A (q*(A.T+1)) (kkey A.T A.d q) ≤ Real.exp 2 := by\n classical\n set R := (bset A).filter\n (fun r => q*(A.T+1) ≤ kkey A.T A.d r ∧ kkey A.T A.d r < kkey A.T A.d q) with hR\n have hqT : q ≤ A.T := bset_le_T hq\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hd_q : 1 ≤ A.d q := hA.hd q hq1\n have hbq : (A.d q : ℝ) ≤ 1/(Real.exp 2 * A.η q) - 1 := (mem_bset.1 hq).2.2\n have hsplit : Fprod A (q*(A.T+1)) (kkey A.T A.d q)\n = (∏ r ∈ R.filter (fun r => q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹)\n * (∏ r ∈ R.filter (fun r => ¬ q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹) := by\n unfold Fprod\n rw [← hR]\n exact (Finset.prod_filter_mul_prod_filter_not R _ _).symm\n -- part 1\n have hsub1 : R.filter (fun r => q ≤ r) ⊆ Finset.Ioo q (q + A.d q) := by\n intro r hr\n rw [Finset.mem_filter, hR, Finset.mem_filter] at hr\n obtain ⟨⟨hrb, hlo, hhi⟩, hqr⟩ := hr\n have hrT := bset_le_T hrb\n have hne : r ≠ q := by rintro rfl; omega\n have hqlt : q < r := lt_of_le_of_ne hqr (Ne.symm hne)\n rcases (kkey_lt_iff (T := A.T) (d := A.d) hrT hqT).1 hhi with h | ⟨h1, h2⟩\n · exact Finset.mem_Ioo.2 ⟨hqlt, by omega⟩\n · omega\n have hcard1 : (R.filter (fun r => q ≤ r)).card ≤ A.d q := by\n have h := Finset.card_le_card hsub1\n rw [Nat.card_Ioo] at h\n omega\n have hprod1 : (∏ r ∈ R.filter (fun r => q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹)\n ≤ Real.exp 1 := by\n have hb : ∀ r ∈ R.filter (fun r => q ≤ r),\n (1 - Real.exp 2 * A.η r)⁻¹ ≤ (1 - Real.exp 2 * A.η q)⁻¹ := by\n intro r hr\n rw [Finset.mem_filter] at hr\n exact hA.inv_mono (hA.eta_anti hr.2)\n calc (∏ r ∈ R.filter (fun r => q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹)\n ≤ ((1 - Real.exp 2 * A.η q)⁻¹)^((R.filter (fun r => q ≤ r)).card) :=\n prod_le_pow_card_nonneg _ _ _ (fun r _ => hA.inv_one_sub_nonneg r) hb\n _ ≤ Real.exp 1 := pow_inv_le_exp1 (hA.hηpos q) hd_q hbq hcard1\n -- part 2\n have hprod2 : (∏ r ∈ R.filter (fun r => ¬ q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹)\n ≤ Real.exp 1 := by\n by_cases hemp : (R.filter (fun r => ¬ q ≤ r)).Nonempty\n · set r₀ := (R.filter (fun r => ¬ q ≤ r)).min' hemp with hr0\n have hr0mem : r₀ ∈ R.filter (fun r => ¬ q ≤ r) := Finset.min'_mem _ hemp\n rw [Finset.mem_filter, hR, Finset.mem_filter] at hr0mem\n obtain ⟨⟨hr0b, hr0lo, hr0hi⟩, hr0q⟩ := hr0mem\n have hr0T := bset_le_T hr0b\n have hr01 : 1 ≤ r₀ := (mem_bset.1 hr0b).1.1\n have hd_r0 : 1 ≤ A.d r₀ := hA.hd r₀ hr01\n have hbr0 : (A.d r₀ : ℝ) ≤ 1/(Real.exp 2 * A.η r₀) - 1 := (mem_bset.1 hr0b).2.2\n have hqle : q ≤ r₀ + A.d r₀ := by\n by_contra hc\n push_neg at hc\n have hkt := (kkey_lt_time (T := A.T) (d := A.d) (q := r₀) (t := q-1) hr0T).2 (by omega)\n have hqq : (q-1)+1 = q := by omega\n rw [hqq] at hkt\n omega\n have hsub2 : R.filter (fun r => ¬ q ≤ r) ⊆ Finset.Ico r₀ q := by\n intro r hr\n have hmin : r₀ ≤ r := Finset.min'_le _ _ hr\n rw [Finset.mem_filter] at hr\n exact Finset.mem_Ico.2 ⟨hmin, by omega⟩\n have hcard2 : (R.filter (fun r => ¬ q ≤ r)).card ≤ A.d r₀ := by\n have h := Finset.card_le_card hsub2\n rw [Nat.card_Ico] at h\n omega\n have hb : ∀ r ∈ R.filter (fun r => ¬ q ≤ r),\n (1 - Real.exp 2 * A.η r)⁻¹ ≤ (1 - Real.exp 2 * A.η r₀)⁻¹ := by\n intro r hr\n exact hA.inv_mono (hA.eta_anti (Finset.min'_le _ _ hr))\n calc (∏ r ∈ R.filter (fun r => ¬ q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹)\n ≤ ((1 - Real.exp 2 * A.η r₀)⁻¹)^((R.filter (fun r => ¬ q ≤ r)).card) :=\n prod_le_pow_card_nonneg _ _ _ (fun r _ => hA.inv_one_sub_nonneg r) hb\n _ ≤ Real.exp 1 := pow_inv_le_exp1 (hA.hηpos r₀) hd_r0 hbr0 hcard2\n · rw [Finset.not_nonempty_iff_eq_empty] at hemp\n rw [hemp, Finset.prod_empty]\n have := Real.add_one_le_exp (0:ℝ)\n simp at this\n linarith [Real.one_le_exp (by norm_num : (0:ℝ) ≤ 1)]\n have hnn1 : 0 ≤ (∏ r ∈ R.filter (fun r => q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹) :=\n Finset.prod_nonneg (fun r _ => hA.inv_one_sub_nonneg r)\n have hnn2 : 0 ≤ (∏ r ∈ R.filter (fun r => ¬ q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹) :=\n Finset.prod_nonneg (fun r _ => hA.inv_one_sub_nonneg r)\n rw [hsplit]\n calc (∏ r ∈ R.filter (fun r => q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹)\n * (∏ r ∈ R.filter (fun r => ¬ q ≤ r), (1 - Real.exp 2 * A.η r)⁻¹)\n ≤ Real.exp 1 * Real.exp 1 := by\n apply mul_le_mul hprod1 hprod2 hnn2 (le_of_lt (Real.exp_pos 1))\n _ = Real.exp 2 := by rw [← Real.exp_add]; norm_num\n\nprivate lemma prod_mono_subset_of_one_le {s t : Finset ℕ} {f : ℕ → ℝ}\n (hst : s ⊆ t) (hf : ∀ i ∈ t, 1 ≤ f i) :\n (∏ i ∈ s, f i) ≤ ∏ i ∈ t, f i := by\n classical\n induction t using Finset.induction_on generalizing s with\n | empty =>\n have : s = ∅ := Finset.eq_empty_iff_forall_not_mem.2 (fun i hi => by\n exact (Finset.not_mem_empty i) (hst hi))\n simp [this]\n | @insert a t ha ih =>\n by_cases has : a ∈ s\n · have hsub : s.erase a ⊆ t := by\n intro i hi\n have his : i ∈ s := Finset.mem_of_mem_erase hi\n have hit := hst his\n rw [Finset.mem_insert] at hit\n exact hit.resolve_left (fun hia => (Finset.ne_of_mem_erase hi) hia)\n have hfa0 : 0 ≤ f a := le_trans (by norm_num) (hf a (Finset.mem_insert_self a t))\n rw [← Finset.insert_erase has, Finset.prod_insert (Finset.not_mem_erase a s),\n Finset.prod_insert ha]\n exact mul_le_mul_of_nonneg_left\n (ih hsub (fun i hi => hf i (Finset.mem_insert_of_mem hi))) hfa0\n · have hsub : s ⊆ t := by\n intro i hi\n have hit := hst hi\n rw [Finset.mem_insert] at hit\n exact hit.resolve_left (fun hia => has (hia ▸ hi))\n have hprod0 : 0 ≤ ∏ i ∈ t, f i := Finset.prod_nonneg (fun i hi =>\n le_trans (by norm_num) (hf i (Finset.mem_insert_of_mem hi)))\n rw [Finset.prod_insert ha]\n calc\n (∏ i ∈ s, f i) ≤ ∏ i ∈ t, f i :=\n ih hsub (fun i hi => hf i (Finset.mem_insert_of_mem hi))\n _ ≤ f a * ∏ i ∈ t, f i := by\n have hfa := hf a (Finset.mem_insert_self a t)\n nlinarith\n\nprivate lemma Fprod_partial_bound (hA : AlgOK A) {q n : ℕ} (hq : q ∈ bset A)\n (hn0 : q * (A.T + 1) ≤ n) (hn1 : n ≤ kkey A.T A.d q) :\n Fprod A (q * (A.T + 1)) n ≤ Real.exp 2 := by\n have hsub : (bset A).filter\n (fun r => q * (A.T + 1) ≤ kkey A.T A.d r ∧ kkey A.T A.d r < n)\n ⊆ (bset A).filter\n (fun r => q * (A.T + 1) ≤ kkey A.T A.d r ∧\n kkey A.T A.d r < kkey A.T A.d q) := by\n intro r hr\n rw [Finset.mem_filter] at hr ⊢\n exact ⟨hr.1, hr.2.1, lt_of_lt_of_le hr.2.2 hn1⟩\n have hprod : Fprod A (q * (A.T + 1)) n\n ≤ Fprod A (q * (A.T + 1)) (kkey A.T A.d q) := by\n unfold Fprod\n apply prod_mono_subset_of_one_le hsub\n intro r hr\n exact (one_le_inv₀ (hA.one_sub_pos r)).2 (by\n have hp : 0 < Real.exp 2 * A.η r := mul_pos (Real.exp_pos 2) (hA.hηpos r)\n linarith)\n exact hprod.trans (hA.Fprod_bound hq)\n\nend AlgOK\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma ratio_star (hA : AlgOK A) (ω : Ω) (n : ℕ)\n (H : ∀ m, m < n → ∀ r ∈ bset A, kkey A.T A.d r = m → ∀ i,\n PP A (m+1) ω i ≤ (1 - Real.exp 2 * A.η r)⁻¹ * PP A m ω i)\n {r : ℕ} (hr : r ∈ bset A) (hkr : kkey A.T A.d r = n) (i : Fin K) :\n PP A n ω i ≤ Real.exp 2 * A.p r ω i := by\n have hrT := bset_le_T hr\n have hr1 : 1 ≤ r := (mem_bset.1 hr).1.1\n have hple : r*(A.T+1) ≤ n := by\n rw [← hkr]\n show r*(A.T+1) ≤ (r + A.d r)*(A.T+1) + r\n exact le_trans (Nat.mul_le_mul_right (A.T+1) (Nat.le_add_right r (A.d r)))\n (Nat.le_add_right _ _)\n have h1 := hA.prod_ratio ω (r*(A.T+1)) n H n hple le_rfl i\n have h2 : Fprod A (r*(A.T+1)) n ≤ Real.exp 2 := by rw [← hkr]; exact hA.Fprod_bound hr\n have h3 : A.p r ω i = PP A (r*(A.T+1)) ω i := by\n rw [hA.hp r ω i hr1 (by omega)]; rfl\n have h4 : 0 ≤ PP A (r*(A.T+1)) ω i := le_of_lt (sfm_pos hA.hK _ _)\n calc PP A n ω i ≤ Fprod A (r*(A.T+1)) n * PP A (r*(A.T+1)) ω i := h1\n _ ≤ Real.exp 2 * PP A (r*(A.T+1)) ω i := mul_le_mul_of_nonneg_right h2 h4\n _ = Real.exp 2 * A.p r ω i := by rw [h3]\n\nlemma sum_PP_ltil_le (hA : AlgOK A) (ω : Ω) (n : ℕ) {r : ℕ} (hr : r ∈ bset A)\n (hstar : ∀ j, PP A n ω j ≤ Real.exp 2 * A.p r ω j) :\n ∑ j, PP A n ω j * ltil A r ω j ≤ Real.exp 2 := by\n have h1 : ∑ j, PP A n ω j * ltil A r ω j\n ≤ ∑ j, (Real.exp 2 * A.p r ω j) * ltil A r ω j := by\n apply Finset.sum_le_sum\n intro j _\n exact mul_le_mul_of_nonneg_right (hstar j) (hA.ltil_nonneg hr ω j)\n have h2 : ∑ j, (Real.exp 2 * A.p r ω j) * ltil A r ω j\n = Real.exp 2 * ∑ j, A.p r ω j * ltil A r ω j := by\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun j _ => by ring)\n rw [h2, hA.sum_p_ltil hr ω] at h1\n have h3 : 0 ≤ A.γ r * ∑ i, ltil A r ω i :=\n mul_nonneg (hA.hγ r) (Finset.sum_nonneg (fun i _ => hA.ltil_nonneg hr ω i))\n have h4 : A.l r ω (A.a r ω) ≤ 1 := hA.hl1 _ _ _\n nlinarith [Real.exp_pos 2]\n\nlemma ratio_step (hA : AlgOK A) (ω : Ω) (n : ℕ) {r : ℕ} (hr : r ∈ bset A)\n (hkr : kkey A.T A.d r = n)\n (hstar : ∀ j, PP A n ω j ≤ Real.exp 2 * A.p r ω j) (i : Fin K) :\n PP A (n+1) ω i ≤ (1 - Real.exp 2 * A.η r)⁻¹ * PP A n ω i := by\n have hη0 : 0 ≤ A.η r := le_of_lt (hA.hηpos r)\n have hD : ∀ j, 0 ≤ A.η r * ltil A r ω j := fun j =>\n mul_nonneg hη0 (hA.ltil_nonneg hr ω j)\n have hc : Real.exp 2 * A.η r < 1 := by have := hA.one_sub_pos r; linarith\n have hS : ∑ j, sfm (GG A n ω) j * (A.η r * ltil A r ω j) ≤ Real.exp 2 * A.η r := by\n have he : ∑ j, sfm (GG A n ω) j * (A.η r * ltil A r ω j)\n = A.η r * ∑ j, PP A n ω j * ltil A r ω j := by\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun j _ => by unfold PP; ring)\n rw [he]\n have := hA.sum_PP_ltil_le ω n hr hstar\n nlinarith\n have hgg : GG A (n+1) ω = fun j => GG A n ω j + A.η r * ltil A r ω j := by\n funext j\n exact GG_succ_mem A n r hr hkr ω j\n have := sfm_step_ratio hA.hK (GG A n ω) (fun j => A.η r * ltil A r ω j) hD\n (Real.exp 2 * A.η r) hc hS i\n unfold PP\n rw [hgg]\n exact this\n\nlemma ratio_main (hA : AlgOK A) (ω : Ω) : ∀ n, ∀ r ∈ bset A, kkey A.T A.d r = n → ∀ i,\n PP A (n+1) ω i ≤ (1 - Real.exp 2 * A.η r)⁻¹ * PP A n ω i := by\n intro n\n induction n using Nat.strong_induction_on with\n | _ n IH =>\n intro r hr hkr i\n exact hA.ratio_step ω n hr hkr (hA.ratio_star ω n (fun m hm => IH m hm) hr hkr) i\n\nlemma key_ratio (hA : AlgOK A) (ω : Ω) : ∀ q ∈ bset A, ∀ i,\n PP A (kkey A.T A.d q) ω i ≤ Real.exp 2 * A.p q ω i := by\n intro q hq i\n exact hA.ratio_star ω (kkey A.T A.d q) (fun m _ => hA.ratio_main ω m) hq rfl i\n\nprivate lemma PP_partial_le (hA : AlgOK A) (ω : Ω) {q n : ℕ} (hq : q ∈ bset A)\n (hn0 : q * (A.T + 1) ≤ n) (hn1 : n ≤ kkey A.T A.d q) (i : Fin K) :\n PP A n ω i ≤ Fprod A (q * (A.T + 1)) n * A.p q ω i := by\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n have hpq : A.p q ω i = PP A (q * (A.T + 1)) ω i := by\n rw [hA.hp q ω i hq1 (by omega)]\n rfl\n have h := hA.prod_ratio ω (q * (A.T + 1)) n\n (fun m _ => hA.ratio_main ω m) n hn0 le_rfl i\n rwa [← hpq] at h\n\nprivate lemma PP_partial_exp_le (hA : AlgOK A) (ω : Ω) {q n : ℕ} (hq : q ∈ bset A)\n (hn0 : q * (A.T + 1) ≤ n) (hn1 : n ≤ kkey A.T A.d q) (i : Fin K) :\n PP A n ω i ≤ Real.exp 2 * A.p q ω i := by\n have h := PP_partial_le hA ω hq hn0 hn1 i\n have hf := Fprod_partial_bound hA hq hn0 hn1\n exact h.trans (mul_le_mul_of_nonneg_right hf (le_of_lt (hA.p_pos_bset hq ω i)))\n\nend AlgOK\n\nnoncomputable def Rset {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (q : ℕ) : Finset ℕ :=\n (bset A).filter (fun r => q*(A.T+1) ≤ kkey A.T A.d r ∧ kkey A.T A.d r < kkey A.T A.d q)\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma mem_Rset {q r : ℕ} : r ∈ Rset A q ↔\n r ∈ bset A ∧ (q*(A.T+1) ≤ kkey A.T A.d r ∧ kkey A.T A.d r < kkey A.T A.d q) := by\n unfold Rset; simp [Finset.mem_filter]\n\nlemma Rset_ge (hA : AlgOK A) {q r : ℕ} (hq : q ∈ bset A) (hr : r ∈ Rset A q) (h : q ≤ r) :\n q < r ∧ r < q + A.d q := by\n rw [mem_Rset] at hr\n obtain ⟨hrb, hlo, hhi⟩ := hr\n have hrT := bset_le_T hrb\n have hqT := bset_le_T hq\n have hne : r ≠ q := by rintro rfl; omega\n have hqlt : q < r := lt_of_le_of_ne h (Ne.symm hne)\n rcases (kkey_lt_iff (T := A.T) (d := A.d) hrT hqT).1 hhi with h1 | ⟨h1, h2⟩\n · exact ⟨hqlt, by omega⟩\n · omega\n\nlemma Rset_lt (hA : AlgOK A) {q r : ℕ} (hq : q ∈ bset A) (hr : r ∈ Rset A q) (h : r < q) :\n q ≤ r + A.d r := by\n rw [mem_Rset] at hr\n obtain ⟨hrb, hlo, hhi⟩ := hr\n have hrT := bset_le_T hrb\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n by_contra hc\n push_neg at hc\n have hkt := (kkey_lt_time (T := A.T) (d := A.d) (q := r) (t := q-1) hrT).2 (by omega)\n have hqq : (q-1)+1 = q := by omega\n rw [hqq] at hkt\n omega\n\nlemma eta_sq_nonneg (hA : AlgOK A) (q : ℕ) : 0 ≤ (A.η q)^2 := sq_nonneg _\n\nlemma bound_ge (hA : AlgOK A) :\n ∑ q ∈ bset A, ∑ r ∈ (Rset A q).filter (fun r => q ≤ r), A.η q * A.η r\n ≤ ∑ q ∈ bset A, (A.d q : ℝ) * (A.η q)^2 := by\n apply Finset.sum_le_sum\n intro q hq\n have hsub : (Rset A q).filter (fun r => q ≤ r) ⊆ Finset.Ioo q (q + A.d q) := by\n intro r hr\n rw [Finset.mem_filter] at hr\n obtain ⟨h1, h2⟩ := hA.Rset_ge hq hr.1 hr.2\n exact Finset.mem_Ioo.2 ⟨h1, h2⟩\n have hcard : ((Rset A q).filter (fun r => q ≤ r)).card ≤ A.d q := by\n have h := Finset.card_le_card hsub\n rw [Nat.card_Ioo] at h\n omega\n have hterm : ∀ r ∈ (Rset A q).filter (fun r => q ≤ r), A.η q * A.η r ≤ (A.η q)^2 := by\n intro r hr\n rw [Finset.mem_filter] at hr\n have := hA.eta_anti hr.2\n nlinarith [hA.hηpos q]\n calc ∑ r ∈ (Rset A q).filter (fun r => q ≤ r), A.η q * A.η r\n ≤ (((Rset A q).filter (fun r => q ≤ r)).card : ℝ) * (A.η q)^2 := by\n have := Finset.sum_le_card_nsmul _ _ _ hterm\n simpa [nsmul_eq_mul] using this\n _ ≤ (A.d q : ℝ) * (A.η q)^2 := by\n apply mul_le_mul_of_nonneg_right _ (sq_nonneg _)\n exact_mod_cast hcard\n\nlemma bound_lt (hA : AlgOK A) :\n ∑ q ∈ bset A, ∑ r ∈ (Rset A q).filter (fun r => ¬ q ≤ r), A.η q * A.η r\n ≤ ∑ r ∈ bset A, (A.d r : ℝ) * (A.η r)^2 := by\n have hrw : ∀ q ∈ bset A, ∑ r ∈ (Rset A q).filter (fun r => ¬ q ≤ r), A.η q * A.η r\n = ∑ r ∈ bset A, (if ((q*(A.T+1) ≤ kkey A.T A.d r ∧ kkey A.T A.d r < kkey A.T A.d q)\n ∧ ¬ q ≤ r) then A.η q * A.η r else 0) := by\n intro q _\n rw [← Finset.sum_filter]\n congr 1\n unfold Rset\n rw [Finset.filter_filter]\n rw [Finset.sum_congr rfl hrw, Finset.sum_comm]\n apply Finset.sum_le_sum\n intro r hr\n rw [← Finset.sum_filter]\n have hsub : (bset A).filter (fun q => (q*(A.T+1) ≤ kkey A.T A.d r\n ∧ kkey A.T A.d r < kkey A.T A.d q) ∧ ¬ q ≤ r) ⊆ Finset.Ioc r (r + A.d r) := by\n intro q hq\n rw [Finset.mem_filter] at hq\n obtain ⟨hqb, hcond, hnq⟩ := hq\n have hrmem : r ∈ Rset A q := mem_Rset.2 ⟨hr, hcond⟩\n have := hA.Rset_lt hqb hrmem (by omega)\n exact Finset.mem_Ioc.2 ⟨by omega, by omega⟩\n have hcard : ((bset A).filter (fun q => (q*(A.T+1) ≤ kkey A.T A.d r\n ∧ kkey A.T A.d r < kkey A.T A.d q) ∧ ¬ q ≤ r)).card ≤ A.d r := by\n have h := Finset.card_le_card hsub\n rw [Nat.card_Ioc] at h\n omega\n have hterm : ∀ q ∈ (bset A).filter (fun q => (q*(A.T+1) ≤ kkey A.T A.d r\n ∧ kkey A.T A.d r < kkey A.T A.d q) ∧ ¬ q ≤ r), A.η q * A.η r ≤ (A.η r)^2 := by\n intro q hq\n rw [Finset.mem_filter] at hq\n have hqr : r ≤ q := by omega\n have := hA.eta_anti hqr\n nlinarith [hA.hηpos r]\n calc ∑ q ∈ (bset A).filter (fun q => (q*(A.T+1) ≤ kkey A.T A.d r\n ∧ kkey A.T A.d r < kkey A.T A.d q) ∧ ¬ q ≤ r), A.η q * A.η r\n ≤ (((bset A).filter (fun q => (q*(A.T+1) ≤ kkey A.T A.d r\n ∧ kkey A.T A.d r < kkey A.T A.d q) ∧ ¬ q ≤ r)).card : ℝ) * (A.η r)^2 := by\n have := Finset.sum_le_card_nsmul _ _ _ hterm\n simpa [nsmul_eq_mul] using this\n _ ≤ (A.d r : ℝ) * (A.η r)^2 := by\n apply mul_le_mul_of_nonneg_right _ (sq_nonneg _)\n exact_mod_cast hcard\n\nlemma eta_pair_bound (hA : AlgOK A) :\n ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * A.η r\n ≤ 2 * ∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ) := by\n have hsplit : ∀ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * A.η r\n = (∑ r ∈ (Rset A q).filter (fun r => q ≤ r), A.η q * A.η r)\n + (∑ r ∈ (Rset A q).filter (fun r => ¬ q ≤ r), A.η q * A.η r) := by\n intro q _\n exact (Finset.sum_filter_add_sum_filter_not (Rset A q) _ _).symm\n rw [Finset.sum_congr rfl hsplit, Finset.sum_add_distrib]\n have h1 := hA.bound_ge\n have h2 := hA.bound_lt\n have h3 : ∑ q ∈ bset A, (A.d q : ℝ) * (A.η q)^2 = ∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ) :=\n Finset.sum_congr rfl (fun q _ => mul_comm _ _)\n rw [h3] at h1 h2\n linarith\n\nend AlgOK\n\nprivate noncomputable def laterHi {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (s : ℕ) : Finset ℕ :=\n (Rset A s).filter (fun u => s ≤ u)\n\nprivate noncomputable def laterLo {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (s : ℕ) : Finset ℕ :=\n (bset A).filter (fun u => s ∈ Rset A u ∧ s < u)\n\n/-- Every unordered pair of overlapping feedback intervals occurs in exactly one arrival order.\nCharging it to its earlier round removes the factor two in `eta_pair_bound`. -/\nprivate lemma eta_pair_bound_one {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n (hA : AlgOK A) :\n ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * A.η r\n ≤ ∑ s ∈ bset A, (A.η s)^2 * (A.d s : ℝ) := by\n classical\n have hsplit : ∀ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * A.η r\n = (∑ r ∈ laterHi A q, A.η q * A.η r)\n + (∑ r ∈ (Rset A q).filter (fun r => ¬ q ≤ r), A.η q * A.η r) := by\n intro q _\n exact (Finset.sum_filter_add_sum_filter_not (Rset A q) _ _).symm\n rw [Finset.sum_congr rfl hsplit, Finset.sum_add_distrib]\n have hlt_reindex :\n (∑ q ∈ bset A, ∑ r ∈ (Rset A q).filter (fun r => ¬ q ≤ r), A.η q * A.η r)\n = ∑ s ∈ bset A, ∑ u ∈ laterLo A s, A.η s * A.η u := by\n have hrw : ∀ q ∈ bset A,\n (∑ r ∈ (Rset A q).filter (fun r => ¬ q ≤ r), A.η q * A.η r)\n = ∑ r ∈ bset A,\n if r ∈ Rset A q ∧ r < q then A.η q * A.η r else 0 := by\n intro q _\n rw [← Finset.sum_filter]\n apply Finset.sum_congr\n · ext r\n simp only [Finset.mem_filter]\n constructor\n · rintro ⟨hrR, hnqr⟩\n exact ⟨(AlgOK.mem_Rset.1 hrR).1, hrR, Nat.lt_of_not_ge hnqr⟩\n · rintro ⟨_, hrR, hrq⟩\n exact ⟨hrR, by omega⟩\n · intro r hr\n rfl\n rw [Finset.sum_congr rfl hrw, Finset.sum_comm]\n apply Finset.sum_congr rfl\n intro s hs\n unfold laterLo\n rw [← Finset.sum_filter]\n apply Finset.sum_congr rfl\n intro u hu\n exact mul_comm _ _\n rw [hlt_reindex, ← Finset.sum_add_distrib]\n refine Finset.sum_le_sum (fun s hs => ?_)\n have hdisj : Disjoint (laterHi A s) (laterLo A s) := by\n rw [Finset.disjoint_left]\n intro u huhi hulo\n rw [laterHi, Finset.mem_filter] at huhi\n rw [laterLo, Finset.mem_filter] at hulo\n have hku : kkey A.T A.d u < kkey A.T A.d s := (AlgOK.mem_Rset.1 huhi.1).2.2\n have hks : kkey A.T A.d s < kkey A.T A.d u := (AlgOK.mem_Rset.1 hulo.2.1).2.2\n omega\n have hsub : laterHi A s ∪ laterLo A s ⊆ Finset.Ioc s (s + A.d s) := by\n intro u hu\n rw [Finset.mem_union] at hu\n rcases hu with hu | hu\n · rw [laterHi, Finset.mem_filter] at hu\n obtain ⟨hsu, huend⟩ := hA.Rset_ge hs hu.1 hu.2\n exact Finset.mem_Ioc.2 ⟨hsu, by omega⟩\n · rw [laterLo, Finset.mem_filter] at hu\n have huend := hA.Rset_lt hu.1 hu.2.1 hu.2.2\n exact Finset.mem_Ioc.2 ⟨hu.2.2, huend⟩\n have hcard : (laterHi A s ∪ laterLo A s).card ≤ A.d s := by\n have hc := Finset.card_le_card hsub\n rw [Nat.card_Ioc] at hc\n simpa using hc\n have hterm : ∀ u ∈ laterHi A s ∪ laterLo A s,\n A.η s * A.η u ≤ (A.η s)^2 := by\n intro u hu\n have hsu : s ≤ u := (Finset.mem_Ioc.1 (hsub hu)).1.le\n have heta := hA.eta_anti hsu\n nlinarith [hA.hηpos s]\n rw [← Finset.sum_union hdisj]\n calc\n ∑ u ∈ laterHi A s ∪ laterLo A s, A.η s * A.η u\n ≤ (((laterHi A s ∪ laterLo A s).card : ℕ) : ℝ) * (A.η s)^2 := by\n have h := Finset.sum_le_card_nsmul _ _ _ hterm\n simpa [nsmul_eq_mul] using h\n _ ≤ (A.d s : ℝ) * (A.η s)^2 := by\n exact mul_le_mul_of_nonneg_right (by exact_mod_cast hcard) (sq_nonneg _)\n _ = (A.η s)^2 * (A.d s : ℝ) := mul_comm _ _\n\nlemma sum_Ico_telescope (f : ℕ → ℝ) {m₁ m₂ : ℕ} (h : m₁ ≤ m₂) :\n ∑ n ∈ Finset.Ico m₁ m₂, (f n - f (n+1)) = f m₁ - f m₂ := by\n induction m₂, h using Nat.le_induction with\n | base => simp\n | succ n hn ih => rw [Finset.sum_Ico_succ_top hn, ih]; ring\n\nlemma sum_Ico_eq_sum_bset {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (F : ℕ → ℝ) (m₁ m₂ : ℕ)\n (hF : ∀ n, (∀ q ∈ bset A, kkey A.T A.d q ≠ n) → F n = 0) :\n ∑ n ∈ Finset.Ico m₁ m₂, F n\n = ∑ r ∈ (bset A).filter (fun r => m₁ ≤ kkey A.T A.d r ∧ kkey A.T A.d r < m₂),\n F (kkey A.T A.d r) := by\n rw [← Finset.sum_image (f := F) (g := kkey A.T A.d)\n (by\n intro x hx y hy hxy\n simp only [Finset.mem_coe, Finset.mem_filter] at hx hy\n exact kkey_inj (bset_le_T hx.1) (bset_le_T hy.1) hxy)]\n symm\n apply Finset.sum_subset\n · intro x hx\n rw [Finset.mem_image] at hx\n obtain ⟨r, hr, rfl⟩ := hx\n rw [Finset.mem_filter] at hr\n exact Finset.mem_Ico.2 ⟨hr.2.1, hr.2.2⟩\n · intro x hxIco hx\n apply hF\n intro q hq hcon\n have hIco := Finset.mem_Ico.1 hxIco\n refine hx (Finset.mem_image.2 ⟨q, ?_, hcon⟩)\n rw [Finset.mem_filter]\n exact ⟨hq, by omega, by omega⟩\n\nnoncomputable def dpos {Ω : Type*} {K : ℕ} (A : AlgData Ω K) (r : ℕ) (ω : Ω) (i : Fin K) : ℝ :=\n max (PP A (kkey A.T A.d r) ω i - PP A (kkey A.T A.d r + 1) ω i) 0\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma dpos_nonneg (A : AlgData Ω K) (r : ℕ) (ω : Ω) (i : Fin K) : 0 ≤ dpos A r ω i :=\n le_max_right _ _\n\nprivate lemma dpos_le_update (hA : AlgOK A) {r : ℕ} (hr : r ∈ bset A)\n (ω : Ω) (i : Fin K) :\n dpos A r ω i ≤ PP A (kkey A.T A.d r) ω i * (A.η r * ltil A r ω i) := by\n have hD : ∀ j, 0 ≤ A.η r * ltil A r ω j := fun j =>\n mul_nonneg (le_of_lt (hA.hηpos r)) (hA.ltil_nonneg hr ω j)\n have hgg : GG A (kkey A.T A.d r + 1) ω\n = fun j => GG A (kkey A.T A.d r) ω j + A.η r * ltil A r ω j := by\n funext j\n exact GG_succ_mem A (kkey A.T A.d r) r hr rfl ω j\n unfold dpos PP\n rw [hgg]\n exact sfm_drop_le hA.hK _ _ hD i\n\nprivate lemma dpos_le_indicator (hA : AlgOK A) {r : ℕ} (hr : r ∈ bset A)\n (ω : Ω) (i : Fin K) :\n dpos A r ω i ≤ Real.exp 2 * A.η r *\n (if A.a r ω = i then (1 : ℝ) else 0) := by\n have h0 : 0 ≤ A.η r * ltil A r ω i :=\n mul_nonneg (le_of_lt (hA.hηpos r)) (hA.ltil_nonneg hr ω i)\n have h1 := dpos_le_update hA hr ω i\n have h2 := mul_le_mul_of_nonneg_right (hA.key_ratio ω r hr i) h0\n refine h1.trans (h2.trans ?_)\n by_cases hi : A.a r ω = i\n · rw [if_pos hi]\n have hpg := hA.pg_pos hr ω i\n have hrat : A.p r ω i * A.l r ω i / (A.p r ω i + A.γ r) ≤ 1 := by\n rw [div_le_one hpg]\n nlinarith [hA.hl1 r ω i, hA.p_pos_bset hr ω i, hA.hγ r]\n unfold ltil\n rw [if_pos hi]\n have hc : 0 ≤ Real.exp 2 * A.η r :=\n mul_nonneg (le_of_lt (Real.exp_pos 2)) (le_of_lt (hA.hηpos r))\n calc\n (Real.exp 2 * A.p r ω i) *\n (A.η r * (A.l r ω i * 1 / (A.p r ω i + A.γ r)))\n = (Real.exp 2 * A.η r) *\n (A.p r ω i * A.l r ω i / (A.p r ω i + A.γ r)) := by ring\n _ ≤ (Real.exp 2 * A.η r) * 1 := mul_le_mul_of_nonneg_left hrat hc\n _ = Real.exp 2 * A.η r * 1 := by ring\n · unfold ltil\n rw [if_neg hi]\n norm_num\n\nlemma delay_decomp (hA : AlgOK A) (ω : Ω) {q : ℕ} (hq : q ∈ bset A) (i : Fin K) :\n A.p q ω i - PP A (kkey A.T A.d q) ω i\n = ∑ r ∈ Rset A q, (PP A (kkey A.T A.d r) ω i - PP A (kkey A.T A.d r + 1) ω i) := by\n have hqT := bset_le_T hq\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hple : q*(A.T+1) ≤ kkey A.T A.d q := by\n show q*(A.T+1) ≤ (q + A.d q)*(A.T+1) + q\n exact le_trans (Nat.mul_le_mul_right (A.T+1) (Nat.le_add_right q (A.d q)))\n (Nat.le_add_right _ _)\n have hpq : A.p q ω i = PP A (q*(A.T+1)) ω i := by\n rw [hA.hp q ω i hq1 (by omega)]; rfl\n rw [hpq, ← sum_Ico_telescope (fun n => PP A n ω i) hple]\n rw [sum_Ico_eq_sum_bset A (fun n => PP A n ω i - PP A (n+1) ω i) _ _ ?_]\n · rfl\n · intro n hn\n have hgg := GG_succ_not A n hn ω\n show PP A n ω i - PP A (n+1) ω i = 0\n rw [AlgOK.PP_eq_of_GG_eq A ω (fun j => (hgg j).symm) i]\n ring\n\nlemma dpos_sum_le (hA : AlgOK A) (ω : Ω) {r : ℕ} (hr : r ∈ bset A) :\n ∑ i, dpos A r ω i ≤ 2 * A.η r * ∑ i, PP A (kkey A.T A.d r) ω i * ltil A r ω i := by\n have hD : ∀ j, 0 ≤ A.η r * ltil A r ω j := fun j =>\n mul_nonneg (le_of_lt (hA.hηpos r)) (hA.ltil_nonneg hr ω j)\n have hgg : GG A (kkey A.T A.d r + 1) ω\n = fun j => GG A (kkey A.T A.d r) ω j + A.η r * ltil A r ω j := by\n funext j\n exact GG_succ_mem A (kkey A.T A.d r) r hr rfl ω j\n have h1 := sfm_l1 hA.hK (GG A (kkey A.T A.d r) ω) (fun j => A.η r * ltil A r ω j) hD\n have h2 : ∑ i, |PP A (kkey A.T A.d r) ω i - PP A (kkey A.T A.d r + 1) ω i|\n ≤ 2 * ∑ i, PP A (kkey A.T A.d r) ω i * (A.η r * ltil A r ω i) := by\n have heq : ∀ i, PP A (kkey A.T A.d r + 1) ω i\n = sfm (fun j => GG A (kkey A.T A.d r) ω j + A.η r * ltil A r ω j) i := by\n intro i; unfold PP; rw [hgg]\n calc ∑ i, |PP A (kkey A.T A.d r) ω i - PP A (kkey A.T A.d r + 1) ω i|\n = ∑ i, |sfm (GG A (kkey A.T A.d r) ω) i\n - sfm (fun j => GG A (kkey A.T A.d r) ω j + A.η r * ltil A r ω j) i| := by\n exact Finset.sum_congr rfl (fun i _ => by rw [heq i]; rfl)\n _ ≤ 2 * ∑ i, sfm (GG A (kkey A.T A.d r) ω) i * (A.η r * ltil A r ω i) := h1\n _ = 2 * ∑ i, PP A (kkey A.T A.d r) ω i * (A.η r * ltil A r ω i) := rfl\n have h3 : ∑ i, dpos A r ω i\n ≤ ∑ i, |PP A (kkey A.T A.d r) ω i - PP A (kkey A.T A.d r + 1) ω i| := by\n apply Finset.sum_le_sum\n intro i _\n unfold dpos\n exact max_le (le_abs_self _) (abs_nonneg _)\n have hin : ∑ i, PP A (kkey A.T A.d r) ω i * (A.η r * ltil A r ω i)\n = A.η r * ∑ i, PP A (kkey A.T A.d r) ω i * ltil A r ω i := by\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [hin] at h2\n linarith\n\nlemma core_final (hA : AlgOK A) (ω : Ω) (istar : Fin K) :\n ∑ q ∈ bset A, A.η q * A.l q ω (A.a q ω)\n ≤ Real.log K + ∑ q ∈ bset A, A.η q * ltil A q ω istar\n + ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i\n + ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i := by\n have hcore := hA.core_pathwise ω istar (fun q hq i => hA.key_ratio ω q hq i)\n refine le_trans hcore ?_\n have hle : ∀ q ∈ bset A, A.η q * ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i) * ltil A q ω i\n ≤ ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i := by\n intro q hq\n have hdec : ∀ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i) * ltil A q ω i\n ≤ ∑ r ∈ Rset A q, dpos A r ω i * ltil A q ω i := by\n intro i\n rw [hA.delay_decomp ω hq i, Finset.sum_mul]\n apply Finset.sum_le_sum\n intro r _\n exact mul_le_mul_of_nonneg_right (le_max_left _ _) (hA.ltil_nonneg hq ω i)\n have h2 : ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i) * ltil A q ω i\n ≤ ∑ i, ∑ r ∈ Rset A q, dpos A r ω i * ltil A q ω i :=\n Finset.sum_le_sum (fun i _ => hdec i)\n have h3 : ∑ i, ∑ r ∈ Rset A q, dpos A r ω i * ltil A q ω i\n = ∑ r ∈ Rset A q, ∑ i, dpos A r ω i * ltil A q ω i := Finset.sum_comm\n have h4 : A.η q * ∑ i, (A.p q ω i - PP A (kkey A.T A.d q) ω i) * ltil A q ω i\n ≤ A.η q * ∑ r ∈ Rset A q, ∑ i, dpos A r ω i * ltil A q ω i := by\n rw [← h3]\n exact mul_le_mul_of_nonneg_left h2 (le_of_lt (hA.hηpos q))\n rw [Finset.mul_sum (s := Rset A q)] at h4\n exact h4\n have := Finset.sum_le_sum hle\n linarith\n\nend AlgOK\n\nnamespace AlgOK\nvariable {Ω : Type*} {K : ℕ} {A : AlgData Ω K}\n\nlemma ltil_meas (A : AlgData Ω K) (m : MeasurableSpace Ω) {q : ℕ}\n (ha : Measurable[m] (A.a q)) (hp : ∀ i, Measurable[m] (fun ω => A.p q ω i))\n (hl : ∀ i, Measurable[m] (fun ω => A.l q ω i)) (i : Fin K) :\n Measurable[m] (fun ω => ltil A q ω i) := by\n unfold ltil\n have hset : MeasurableSet[m] {ω | A.a q ω = i} := ha (measurableSet_singleton i)\n exact ((hl i).mul (Measurable.ite hset measurable_const measurable_const)).div\n ((hp i).add measurable_const)\n\nlemma GG_meas (A : AlgData Ω K) (m : MeasurableSpace Ω) (n : ℕ)\n (ha : ∀ q ∈ bset A, kkey A.T A.d q < n → Measurable[m] (A.a q))\n (hp : ∀ q ∈ bset A, kkey A.T A.d q < n → ∀ i, Measurable[m] (fun ω => A.p q ω i))\n (hl : ∀ q i, Measurable[m] (fun ω => A.l q ω i)) (i : Fin K) :\n Measurable[m] (fun ω => GG A n ω i) := by\n unfold GG\n apply Finset.measurable_sum\n intro q hq\n rw [Finset.mem_filter] at hq\n exact ((ltil_meas A m (ha q hq.1 hq.2) (hp q hq.1 hq.2) (fun i => hl q i) i)).const_mul _\n\nlemma PP_meas (A : AlgData Ω K) (m : MeasurableSpace Ω) (n : ℕ)\n (ha : ∀ q ∈ bset A, kkey A.T A.d q < n → Measurable[m] (A.a q))\n (hp : ∀ q ∈ bset A, kkey A.T A.d q < n → ∀ i, Measurable[m] (fun ω => A.p q ω i))\n (hl : ∀ q i, Measurable[m] (fun ω => A.l q ω i)) (i : Fin K) :\n Measurable[m] (fun ω => PP A n ω i) := by\n unfold PP sfm\n exact ((GG_meas A m n ha hp hl i).neg.exp).div\n (Finset.measurable_sum _ (fun j _ => (GG_meas A m n ha hp hl j).neg.exp))\n\nlemma dpos_meas (A : AlgData Ω K) (m : MeasurableSpace Ω) (r : ℕ)\n (ha : ∀ q ∈ bset A, kkey A.T A.d q < kkey A.T A.d r + 1 → Measurable[m] (A.a q))\n (hp : ∀ q ∈ bset A, kkey A.T A.d q < kkey A.T A.d r + 1 → ∀ i,\n Measurable[m] (fun ω => A.p q ω i))\n (hl : ∀ q i, Measurable[m] (fun ω => A.l q ω i)) (i : Fin K) :\n Measurable[m] (fun ω => dpos A r ω i) := by\n unfold dpos\n refine Measurable.max (Measurable.sub ?_ ?_) measurable_const\n · exact PP_meas A m _ (fun q hq h => ha q hq (by omega)) (fun q hq h => hp q hq (by omega)) hl i\n · exact PP_meas A m _ ha hp hl i\n\nlemma PP_nonneg (hA : AlgOK A) (n : ℕ) (ω : Ω) (i : Fin K) : 0 ≤ PP A n ω i :=\n le_of_lt (sfm_pos hA.hK _ _)\n\nlemma PP_le_one (hA : AlgOK A) (n : ℕ) (ω : Ω) (i : Fin K) : PP A n ω i ≤ 1 := by\n have h1 : ∑ j, PP A n ω j = 1 := sfm_sum hA.hK _\n have h2 : PP A n ω i ≤ ∑ j, PP A n ω j :=\n Finset.single_le_sum (fun j _ => hA.PP_nonneg n ω j) (Finset.mem_univ i)\n linarith\n\nlemma dpos_le_one (hA : AlgOK A) (r : ℕ) (ω : Ω) (i : Fin K) : dpos A r ω i ≤ 1 := by\n unfold dpos\n apply max_le\n · have := hA.PP_le_one (kkey A.T A.d r) ω i\n have := hA.PP_nonneg (kkey A.T A.d r + 1) ω i\n linarith\n · norm_num\n\nend AlgOK\n\nsection Build\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} {K : ℕ} {hK : 0 < K}\n {l : ℕ → Ω → Fin K → ℝ} {d : ℕ → ℕ} {η γ : ℕ → ℝ}\n\n/-- The `AlgData` recording a run of `Exp3Delayed` up to horizon `T`. -/\nnoncomputable def toAlg (T : ℕ) (d : ℕ → ℕ) (η γ : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ)\n (E : Exp3Delayed μ K hK l d η γ) : AlgData Ω K :=\n { T := T, d := d, η := η, γ := γ, a := E.a, l := l, p := E.p }\n\n@[simp] lemma toAlg_T (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n (toAlg T d η γ l E).T = T := rfl\n@[simp] lemma toAlg_d (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n (toAlg T d η γ l E).d = d := rfl\n@[simp] lemma toAlg_eta (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n (toAlg T d η γ l E).η = η := rfl\n@[simp] lemma toAlg_gamma (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n (toAlg T d η γ l E).γ = γ := rfl\n@[simp] lemma toAlg_a (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n (toAlg T d η γ l E).a = E.a := rfl\n@[simp] lemma toAlg_l (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n (toAlg T d η γ l E).l = l := rfl\n@[simp] lemma toAlg_p (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n (toAlg T d η γ l E).p = E.p := rfl\n\n/-- The set of rounds whose feedback has arrived by time `m`. -/\nnoncomputable def arrived (T : ℕ) (d : ℕ → ℕ) (η : ℕ → ℝ) (m : ℕ) : Finset ℕ :=\n (Finset.Icc 1 T).filter (fun q => q + d q ≤ m ∧ (d q : ℝ) ≤ 1/(Real.exp 2 * η q) - 1)\n\nlemma bset_filter_eq_arrived (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) {m : ℕ} (hm : m ≤ T) :\n (bset (toAlg T d η γ l E)).filter (fun q => kkey T d q < (m+1)*(T+1))\n = arrived T d η m := by\n ext q\n simp only [Finset.mem_filter, mem_bset, arrived, toAlg_T, toAlg_d, toAlg_eta]\n constructor\n · rintro ⟨⟨⟨h1, h2⟩, h3, h4⟩, h5⟩\n exact ⟨Finset.mem_Icc.2 ⟨h1, h2⟩, (kkey_lt_time (T := T) (d := d) h2).1 h5, h4⟩\n · rintro ⟨hq, h1, h2⟩\n rw [Finset.mem_Icc] at hq\n refine ⟨⟨⟨hq.1, hq.2⟩, by omega, h2⟩, ?_⟩\n exact (kkey_lt_time (T := T) (d := d) hq.2).2 h1\n\nlemma Lhat_eq_sum (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) (hd : ∀ t, 1 ≤ t → 1 ≤ d t)\n (m : ℕ) (hm : m ≤ T) (ω : Ω) (i : Fin K) :\n E.Lhat m ω i = ∑ q ∈ arrived T d η m, η q * ltil (toAlg T d η γ l E) q ω i := by\n induction m with\n | zero =>\n rw [E.Lhat_init]\n have : arrived T d η 0 = ∅ := by\n apply Finset.filter_false_of_mem\n intro x hx\n rw [Finset.mem_Icc] at hx\n rintro ⟨h1, -⟩\n have := hd x hx.1\n omega\n rw [this, Finset.sum_empty]\n | succ n ih =>\n have hn : n ≤ T := by omega\n rw [E.Lhat_step (n+1) ω i (by omega)]\n simp only [Nat.add_sub_cancel]\n rw [ih hn]\n have hsplit : arrived T d η (n+1)\n = arrived T d η n ∪ (Finset.Icc 1 T).filter\n (fun q => q + d q = n+1 ∧ (d q : ℝ) ≤ 1/(Real.exp 2 * η q) - 1) := by\n rw [arrived, arrived, ← Finset.filter_or]\n apply Finset.filter_congr\n intro x _\n constructor\n · rintro ⟨h1, h2⟩\n rcases Nat.lt_or_ge (x + d x) (n+1) with h | h\n · exact Or.inl ⟨by omega, h2⟩\n · exact Or.inr ⟨by omega, h2⟩\n · rintro (⟨h1, h2⟩ | ⟨h1, h2⟩) <;> exact ⟨by omega, h2⟩\n rw [hsplit, Finset.sum_union (by\n simp only [Finset.disjoint_left, Finset.mem_filter, arrived]\n rintro x ⟨-, hx1, -⟩ ⟨-, hx2, -⟩; omega)]\n congr 1\n -- now match the second sum with the Lhat_step sum\n have hkey : ∀ q, η q * ltil (toAlg T d η γ l E) q ω i\n = if E.a q ω = i then η q * l q ω i / (E.p q ω i + γ q) else 0 := by\n intro q\n unfold ltil\n simp only [toAlg_a, toAlg_l, toAlg_p, toAlg_gamma]\n by_cases h : E.a q ω = i\n · simp [h, mul_div_assoc]\n · simp [h]\n rw [Finset.sum_congr rfl (fun q _ => hkey q), ← Finset.sum_filter]\n apply Finset.sum_congr _ (fun _ _ => rfl)\n ext q\n simp only [Finset.mem_filter, Finset.mem_Icc]\n constructor\n · intro h\n obtain ⟨hIcc, he, hbd, hai⟩ := h\n exact ⟨⟨⟨hIcc.1, by omega⟩, he, hbd⟩, hai⟩\n · intro h\n obtain ⟨⟨hIcc, he, hbd⟩, hai⟩ := h\n exact ⟨⟨hIcc.1, by omega⟩, he, hbd, hai⟩\n\nend Build\n\nsection Build2\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} {K : ℕ} {hK : 0 < K}\n {l : ℕ → Ω → Fin K → ℝ} {d : ℕ → ℕ} {η γ : ℕ → ℝ}\n\nlemma GG_eq_arrived (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) {m : ℕ} (hm : m ≤ T)\n (ω : Ω) (i : Fin K) :\n GG (toAlg T d η γ l E) ((m+1)*(T+1)) ω i\n = ∑ q ∈ arrived T d η m, η q * ltil (toAlg T d η γ l E) q ω i := by\n unfold GG\n simp only [toAlg_T, toAlg_d, toAlg_eta]\n rw [bset_filter_eq_arrived T E hm]\n\nlemma toAlg_hp (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) (hd : ∀ t, 1 ≤ t → 1 ≤ d t)\n (t : ℕ) (ω : Ω) (i : Fin K) (h1 : 1 ≤ t) (h2 : t ≤ T + 1) :\n E.p t ω i = sfm (GG (toAlg T d η γ l E) (t * (T+1)) ω) i := by\n obtain ⟨m, rfl⟩ : ∃ m, t = m + 1 := ⟨t - 1, by omega⟩\n have hm : m ≤ T := by omega\n have hL : ∀ j, E.Lhat m ω j = GG (toAlg T d η γ l E) ((m+1)*(T+1)) ω j := by\n intro j\n rw [GG_eq_arrived T E hm ω j]\n exact Lhat_eq_sum T E hd m hm ω j\n rw [E.p_update m ω i]\n unfold sfm\n rw [hL i]\n congr 1\n exact Finset.sum_congr rfl (fun j _ => by rw [hL j])\n\nlemma toAlg_ok (T : ℕ) (E : Exp3Delayed μ K hK l d η γ)\n (hd : ∀ t, 1 ≤ t → 1 ≤ d t)\n (hηpos : ∀ t, 0 < η t) (hηdec : ∀ t, η (t+1) ≤ η t)\n (hηb : ∀ t, η t ≤ (1/2) * Real.exp (-2))\n (hl0 : ∀ t ω i, 0 ≤ l t ω i) (hl1 : ∀ t ω i, l t ω i ≤ 1)\n (hγ : ∀ t, 0 ≤ γ t) :\n AlgOK (toAlg T d η γ l E) where\n hK := hK\n hd := hd\n hηpos := hηpos\n hηdec := hηdec\n hηb := hηb\n hl0 := hl0\n hl1 := hl1\n hγ := hγ\n hp := fun t ω i h1 h2 => toAlg_hp T E hd t ω i h1 h2\n\nend Build2\n\nsection Meas\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\n\n/-- The σ-algebra generated by the actions of all *used* rounds with key `< n`. -/\nnoncomputable def Mact (A : AlgData Ω K) (n : ℕ) : MeasurableSpace Ω :=\n ⨆ u, ⨆ (_ : u ∈ bset A ∧ kkey A.T A.d u < n), MeasurableSpace.comap (A.a u) inferInstance\n\nlemma comap_le_Mact {u n : ℕ} (hu : u ∈ bset A) (hk : kkey A.T A.d u < n) :\n MeasurableSpace.comap (A.a u) inferInstance ≤ Mact A n := by\n unfold Mact\n exact le_iSup_of_le u (le_iSup_of_le ⟨hu, hk⟩ le_rfl)\n\nlemma a_meas_Mact {u n : ℕ} (hu : u ∈ bset A) (hk : kkey A.T A.d u < n) :\n Measurable[Mact A n] (A.a u) :=\n measurable_iff_comap_le.2 (comap_le_Mact hu hk)\n\nlemma Mact_mono (A : AlgData Ω K) {n n' : ℕ} (h : n ≤ n') : Mact A n ≤ Mact A n' := by\n unfold Mact\n refine iSup_le (fun u => iSup_le (fun hu => ?_))\n exact comap_le_Mact hu.1 (lt_of_lt_of_le hu.2 h)\n\nlemma Mact_le (A : AlgData Ω K) (n : ℕ) (ha : ∀ u, Measurable (A.a u)) :\n Mact A n ≤ mΩ := by\n unfold Mact\n refine iSup_le (fun u => iSup_le (fun _ => ?_))\n exact (measurable_iff_comap_le.1 (ha u))\n\nlemma GG_meas_Mact (hA : AlgOK A) (hlc : ∀ q i, ∃ c : ℝ, ∀ ω, A.l q ω i = c) :\n ∀ n, ∀ i, Measurable[Mact A n] (fun ω => GG A n ω i) := by\n intro n\n induction n using Nat.strong_induction_on with\n | _ n IH =>\n intro i\n refine AlgOK.GG_meas A (Mact A n) n (fun q hq hk => a_meas_Mact hq hk) ?_ ?_ i\n · intro q hq hk j\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n have hlt : q * (A.T+1) < n := by\n refine lt_of_le_of_lt ?_ hk\n show q * (A.T+1) ≤ (q + A.d q)*(A.T+1) + q\n exact le_trans (Nat.mul_le_mul_right (A.T+1) (Nat.le_add_right q (A.d q)))\n (Nat.le_add_right _ _)\n have hmono : Mact A (q*(A.T+1)) ≤ Mact A n := Mact_mono A (le_of_lt hlt)\n have hIH : ∀ j', Measurable[Mact A n] (fun ω => GG A (q*(A.T+1)) ω j') := by\n intro j'\n exact (IH _ hlt j').mono hmono le_rfl\n have hpe : (fun ω => A.p q ω j) = fun ω => sfm (GG A (q*(A.T+1)) ω) j := by\n funext ω; exact hA.hp q ω j hq1 (by omega)\n rw [hpe]\n unfold sfm\n exact ((hIH j).neg.exp).div (Finset.measurable_sum _ (fun j' _ => (hIH j').neg.exp))\n · intro q j\n obtain ⟨c, hc⟩ := hlc q j\n have : (fun ω => A.l q ω j) = fun _ => c := funext hc\n rw [this]\n exact measurable_const\n\nlemma PP_meas_Mact (hA : AlgOK A) (hlc : ∀ q i, ∃ c : ℝ, ∀ ω, A.l q ω i = c)\n (n : ℕ) (i : Fin K) : Measurable[Mact A n] (fun ω => PP A n ω i) := by\n unfold PP sfm\n exact ((GG_meas_Mact hA hlc n i).neg.exp).div\n (Finset.measurable_sum _ (fun j _ => (GG_meas_Mact hA hlc n j).neg.exp))\n\nlemma dpos_meas_Mact (hA : AlgOK A) (hlc : ∀ q i, ∃ c : ℝ, ∀ ω, A.l q ω i = c)\n (r : ℕ) (i : Fin K) : Measurable[Mact A (kkey A.T A.d r + 1)] (fun ω => dpos A r ω i) := by\n unfold dpos\n refine Measurable.max (Measurable.sub ?_ ?_) measurable_const\n · exact (PP_meas_Mact hA hlc (kkey A.T A.d r) i).mono\n (Mact_mono A (by omega)) le_rfl\n · exact PP_meas_Mact hA hlc (kkey A.T A.d r + 1) i\n\nlemma p_meas_Mact (hA : AlgOK A) (hlc : ∀ q i, ∃ c : ℝ, ∀ ω, A.l q ω i = c)\n {q : ℕ} (hq : q ∈ bset A) (i : Fin K) :\n Measurable[Mact A (kkey A.T A.d q)] (fun ω => A.p q ω i) := by\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n have hle : q * (A.T+1) ≤ kkey A.T A.d q := by\n show q * (A.T+1) ≤ (q + A.d q)*(A.T+1) + q\n exact le_trans (Nat.mul_le_mul_right (A.T+1) (Nat.le_add_right q (A.d q)))\n (Nat.le_add_right _ _)\n have hpe : (fun ω => A.p q ω i) = fun ω => sfm (GG A (q*(A.T+1)) ω) i := by\n funext ω; exact hA.hp q ω i hq1 (by omega)\n rw [hpe]\n unfold sfm\n have hIH : ∀ j', Measurable[Mact A (kkey A.T A.d q)] (fun ω => GG A (q*(A.T+1)) ω j') :=\n fun j' => (GG_meas_Mact hA hlc _ j').mono (Mact_mono A hle) le_rfl\n exact ((hIH i).neg.exp).div (Finset.measurable_sum _ (fun j' _ => (hIH j').neg.exp))\n\nend Meas\n\nsection Expect\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\n\n/-- Unbiasedness of the importance-weighted loss estimator, against a weight `F` that is\nmeasurable for a σ-algebra `m` for which the action still has conditional law `p`. -/\nlemma expect_ltil (hA : AlgOK A) (μ : Measure Ω) [IsProbabilityMeasure μ]\n (hγ0 : ∀ t, A.γ t = 0)\n (m : MeasurableSpace Ω) (hm : m ≤ mΩ)\n {q : ℕ} (hq : q ∈ bset A) (i : Fin K)\n (hpm : Measurable[m] (fun ω => A.p q ω i))\n (hai : @Measurable Ω (Fin K) mΩ _ (A.a q))\n (hcond : (μ[(fun ω => if A.a q ω = i then (1:ℝ) else 0) | m]) =ᵐ[μ] (fun ω => A.p q ω i))\n (F : Ω → ℝ) (hF : Measurable[m] F) (hF0 : ∀ ω, 0 ≤ F ω) (hFb : ∀ ω, F ω ≤ 1)\n (hlm : Measurable[m] (fun ω => A.l q ω i)) :\n Integrable (fun ω => F ω * ltil A q ω i) μ ∧\n ∫ ω, F ω * ltil A q ω i ∂μ = ∫ ω, F ω * A.l q ω i ∂μ := by\n set f : Ω → ℝ := fun ω => F ω * A.l q ω i / A.p q ω i with hfdef\n set g : Ω → ℝ := fun ω => if A.a q ω = i then (1:ℝ) else 0 with hgdef\n set h : Ω → ℝ := fun ω => A.p q ω i with hhdef\n have hppos : ∀ ω, 0 < A.p q ω i := fun ω => hA.p_pos_bset hq ω i\n have hfg : (fun ω => f ω * g ω) = fun ω => F ω * ltil A q ω i := by\n funext ω\n simp only [hfdef, hgdef, ltil, hγ0, add_zero]\n ring\n have hfh : (fun ω => f ω * h ω) = fun ω => F ω * A.l q ω i := by\n funext ω\n simp only [hfdef, hhdef]\n rw [div_mul_eq_mul_div, mul_div_assoc, div_self (ne_of_gt (hppos ω)), mul_one]\n have hFl0 : ∀ ω, 0 ≤ F ω * A.l q ω i := fun ω => mul_nonneg (hF0 ω) (hA.hl0 _ _ _)\n have hFl1 : ∀ ω, F ω * A.l q ω i ≤ 1 := by\n intro ω\n have := hA.hl1 q ω i\n have := hA.hl0 q ω i\n nlinarith [hF0 ω, hFb ω]\n have hFlmeas : Measurable[mΩ] (fun ω => F ω * A.l q ω i) :=\n (hF.mono hm le_rfl).mul (hlm.mono hm le_rfl)\n have hFlint : Integrable (fun ω => F ω * A.l q ω i) μ := by\n refine (integrable_const (1:ℝ)).mono' hFlmeas.aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hFl0 ω)]\n exact hFl1 ω\n have hres := @cond_pull Ω m mΩ hm μ _ f g h\n ((hF.mul hlm).div hpm)\n (fun ω => div_nonneg (hFl0 ω) (le_of_lt (hppos ω)))\n (by\n have hs : MeasurableSet[mΩ] {ω | A.a q ω = i} := hai (measurableSet_singleton i)\n exact @Measurable.ite Ω ℝ _ _ mΩ _ _ _ hs measurable_const measurable_const)\n (fun ω => by simp only [hgdef]; split <;> norm_num)\n (fun ω => by simp only [hgdef]; split <;> norm_num)\n hpm (fun ω => le_of_lt (hppos ω)) hcond (by rw [hfh]; exact hFlint)\n rw [hfg, hfh] at hres\n exact hres\n\nend Expect\n\nsection Master\n\nlemma master_bound {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} (A : AlgData Ω K) (hA : AlgOK A)\n (L0 : ℕ → Fin K → ℝ) (hlc : ∀ q ω i, A.l q ω i = L0 q i)\n (hγ0 : ∀ t, A.γ t = 0)\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (m : ℕ → MeasurableSpace Ω)\n (hmle : ∀ q, m q ≤ mΩ)\n (hMm : ∀ q ∈ bset A, Mact A (kkey A.T A.d q) ≤ m q)\n (ha : ∀ q, @Measurable Ω (Fin K) mΩ _ (A.a q))\n (hcond : ∀ q ∈ bset A, ∀ i,\n (μ[(fun ω => if A.a q ω = i then (1:ℝ) else 0) | m q]) =ᵐ[μ] (fun ω => A.p q ω i))\n (istar : Fin K) :\n ∫ ω, (∑ t ∈ Finset.Icc 1 A.T, A.η t * L0 t (A.a t ω)) ∂μ\n ≤ (∑ t ∈ Finset.Icc 1 A.T, A.η t * L0 t istar)\n + Real.log K + (Real.exp 2/2) * K * (∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2)\n + 4 * (∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ))\n + (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) := by\n classical\n haveI : Nonempty (Fin K) := ⟨⟨0, hA.hK⟩⟩\n haveI hne : Nonempty Ω := by\n by_contra hcon\n rw [not_nonempty_iff] at hcon\n have h0 : (μ Set.univ) = 0 := by\n rw [Set.univ_eq_empty_iff.2 hcon, measure_empty]\n rw [measure_univ] at h0\n exact one_ne_zero h0\n have hlc' : ∀ q (i : Fin K), ∃ c : ℝ, ∀ ω, A.l q ω i = c :=\n fun q i => ⟨L0 q i, fun ω => hlc q ω i⟩\n have hL00 : ∀ q i, 0 ≤ L0 q i := by\n intro q i; rw [← hlc q (Classical.arbitrary Ω) i]; exact hA.hl0 _ _ _\n have hL01 : ∀ q i, L0 q i ≤ 1 := by\n intro q i; rw [← hlc q (Classical.arbitrary Ω) i]; exact hA.hl1 _ _ _\n have hlfun : ∀ q (i : Fin K), (fun ω => A.l q ω i) = fun _ => L0 q i :=\n fun q i => funext (fun ω => hlc q ω i)\n -- integrability of bounded nonnegative measurable functions\n have hFintC : ∀ (F : Ω → ℝ) (C : ℝ), Measurable[mΩ] F → (∀ ω, 0 ≤ F ω) → (∀ ω, F ω ≤ C) →\n Integrable F μ := by\n intro F C hF hF0 hFb\n refine (integrable_const C).mono' hF.aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hF0 ω)]; exact hFb ω\n -- Step 1 : unbiasedness of the estimator against a weight\n have hltil : ∀ q ∈ bset A, ∀ (i : Fin K) (F : Ω → ℝ), Measurable[m q] F →\n (∀ ω, 0 ≤ F ω) → (∀ ω, F ω ≤ 1) →\n Integrable (fun ω => F ω * ltil A q ω i) μ ∧\n ∫ ω, F ω * ltil A q ω i ∂μ = ∫ ω, F ω * A.l q ω i ∂μ := by\n intro q hq i F hF hF0 hFb\n refine expect_ltil hA μ hγ0 (m q) (hmle q) hq i\n ((p_meas_Mact hA hlc' hq i).mono (hMm q hq) le_rfl) (ha q) (hcond q hq i) F hF hF0 hFb ?_\n rw [hlfun q i]; exact measurable_const\n have hltilF_le : ∀ q ∈ bset A, ∀ (i : Fin K) (F : Ω → ℝ), Measurable[m q] F →\n (∀ ω, 0 ≤ F ω) → (∀ ω, F ω ≤ 1) →\n ∫ ω, F ω * ltil A q ω i ∂μ ≤ ∫ ω, F ω ∂μ := by\n intro q hq i F hF hF0 hFb\n rw [(hltil q hq i F hF hF0 hFb).2]\n have hFM : Measurable[mΩ] F := hF.mono (hmle q) le_rfl\n have h1 : Integrable F μ := hFintC F 1 hFM hF0 hFb\n have h2 : Integrable (fun ω => F ω * A.l q ω i) μ := by\n refine hFintC _ 1 (hFM.mul (by rw [hlfun q i]; exact measurable_const)) ?_ ?_\n · exact fun ω => mul_nonneg (hF0 ω) (hA.hl0 _ _ _)\n · intro ω; nlinarith [hA.hl0 q ω i, hA.hl1 q ω i, hF0 ω, hFb ω]\n refine integral_mono h2 h1 (fun ω => ?_)\n nlinarith [hA.hl1 q ω i, hF0 ω, hA.hl0 q ω i]\n have hltil1 : ∀ q ∈ bset A, ∀ i : Fin K,\n Integrable (fun ω => ltil A q ω i) μ ∧ ∫ ω, ltil A q ω i ∂μ = L0 q i := by\n intro q hq i\n have h := hltil q hq i (fun _ => 1) measurable_const (fun _ => zero_le_one) (fun _ => le_rfl)\n refine ⟨by simpa using h.1, ?_⟩\n have h2 := h.2\n simp only [one_mul] at h2\n rw [h2, hlfun q i]\n simp\n have hsumltil : ∀ q ∈ bset A,\n Integrable (fun ω => ∑ i, ltil A q ω i) μ ∧\n ∫ ω, (∑ i, ltil A q ω i) ∂μ = ∑ i, L0 q i := by\n intro q hq\n refine ⟨integrable_finset_sum _ (fun i _ => (hltil1 q hq i).1), ?_⟩\n rw [integral_finset_sum _ (fun i _ => (hltil1 q hq i).1)]\n exact Finset.sum_congr rfl (fun i _ => (hltil1 q hq i).2)\n -- Step 2 : the delayed-drift terms\n have hPPm : ∀ r ∈ bset A, ∀ i, Measurable[m r] (fun ω => PP A (kkey A.T A.d r) ω i) :=\n fun r hr i => (PP_meas_Mact hA hlc' _ i).mono (hMm r hr) le_rfl\n have hPPltil : ∀ r ∈ bset A,\n ∫ ω, (∑ i, PP A (kkey A.T A.d r) ω i * ltil A r ω i) ∂μ ≤ 1 := by\n intro r hr\n have hint : ∀ i, Integrable (fun ω => PP A (kkey A.T A.d r) ω i * ltil A r ω i) μ :=\n fun i => (hltil r hr i _ (hPPm r hr i) (fun ω => hA.PP_nonneg _ ω i)\n (fun ω => hA.PP_le_one _ ω i)).1\n rw [integral_finset_sum _ (fun i _ => hint i)]\n have hb : ∀ i ∈ (Finset.univ : Finset (Fin K)),\n ∫ ω, PP A (kkey A.T A.d r) ω i * ltil A r ω i ∂μ\n ≤ ∫ ω, PP A (kkey A.T A.d r) ω i ∂μ :=\n fun i _ => hltilF_le r hr i _ (hPPm r hr i) (fun ω => hA.PP_nonneg _ ω i)\n (fun ω => hA.PP_le_one _ ω i)\n refine le_trans (Finset.sum_le_sum hb) ?_\n have hPPint : ∀ i, Integrable (fun ω => PP A (kkey A.T A.d r) ω i) μ :=\n fun i => hFintC _ 1 ((hPPm r hr i).mono (hmle r) le_rfl)\n (fun ω => hA.PP_nonneg _ ω i) (fun ω => hA.PP_le_one _ ω i)\n rw [← integral_finset_sum _ (fun i _ => hPPint i)]\n have he : (fun ω => ∑ i, PP A (kkey A.T A.d r) ω i) = fun _ => (1:ℝ) :=\n funext (fun ω => sfm_sum hA.hK _)\n rw [he]\n simp\n have hdpos_int : ∀ r i, Integrable (fun ω => dpos A r ω i) μ :=\n fun r i => hFintC _ 1 ((dpos_meas_Mact hA hlc' r i).mono (Mact_le A _ ha) le_rfl)\n (fun ω => AlgOK.dpos_nonneg A r ω i) (fun ω => hA.dpos_le_one r ω i)\n have hdpos_bound : ∀ r ∈ bset A, ∫ ω, (∑ i, dpos A r ω i) ∂μ ≤ 2 * A.η r := by\n intro r hr\n have hpath : ∀ ω, ∑ i, dpos A r ω i\n ≤ 2 * A.η r * ∑ i, PP A (kkey A.T A.d r) ω i * ltil A r ω i :=\n fun ω => hA.dpos_sum_le ω hr\n have hint2 : Integrable\n (fun ω => 2 * A.η r * ∑ i, PP A (kkey A.T A.d r) ω i * ltil A r ω i) μ := by\n refine Integrable.const_mul ?_ _\n exact integrable_finset_sum _ (fun i _ => (hltil r hr i _ (hPPm r hr i)\n (fun ω => hA.PP_nonneg _ ω i) (fun ω => hA.PP_le_one _ ω i)).1)\n have h1 := integral_mono (integrable_finset_sum _ (fun i (_ : i ∈ Finset.univ) =>\n hdpos_int r i)) hint2 hpath\n rw [integral_const_mul] at h1\n have h2 := hPPltil r hr\n have h3 : (0:ℝ) ≤ 2 * A.η r := by linarith [hA.hηpos r]\n nlinarith\n have hdposltil_meas : ∀ q ∈ bset A, ∀ r ∈ Rset A q, ∀ i,\n Measurable[m q] (fun ω => dpos A r ω i) := by\n intro q hq r hr i\n have hk : kkey A.T A.d r + 1 ≤ kkey A.T A.d q := (AlgOK.mem_Rset.1 hr).2.2\n exact (dpos_meas_Mact hA hlc' r i).mono\n (le_trans (Mact_mono A hk) (hMm q hq)) le_rfl\n have hdposltil_bd : ∀ q ∈ bset A, ∀ r ∈ Rset A q,\n Integrable (fun ω => ∑ i, dpos A r ω i * ltil A q ω i) μ ∧\n ∫ ω, (∑ i, dpos A r ω i * ltil A q ω i) ∂μ ≤ 2 * A.η r := by\n intro q hq r hr\n have hint : ∀ i, Integrable (fun ω => dpos A r ω i * ltil A q ω i) μ :=\n fun i => (hltil q hq i _ (hdposltil_meas q hq r hr i)\n (fun ω => AlgOK.dpos_nonneg A r ω i) (fun ω => hA.dpos_le_one r ω i)).1\n refine ⟨integrable_finset_sum _ (fun i _ => hint i), ?_⟩\n rw [integral_finset_sum _ (fun i _ => hint i)]\n have hb : ∀ i ∈ (Finset.univ : Finset (Fin K)),\n ∫ ω, dpos A r ω i * ltil A q ω i ∂μ ≤ ∫ ω, dpos A r ω i ∂μ :=\n fun i _ => hltilF_le q hq i _ (hdposltil_meas q hq r hr i)\n (fun ω => AlgOK.dpos_nonneg A r ω i) (fun ω => hA.dpos_le_one r ω i)\n refine le_trans (Finset.sum_le_sum hb) ?_\n rw [← integral_finset_sum _ (fun i (_ : i ∈ Finset.univ) => hdpos_int r i)]\n exact hdpos_bound r ((AlgOK.mem_Rset.1 hr).1)\n -- Step 3 : pathwise bound\n have hbsub : bset A ⊆ Finset.Icc 1 A.T := Finset.filter_subset _ _\n have hpath : ∀ ω, (∑ t ∈ Finset.Icc 1 A.T, A.η t * L0 t (A.a t ω))\n ≤ (Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t)\n + (∑ q ∈ bset A, A.η q * ltil A q ω istar)\n + (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i)\n + (∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i) := by\n intro ω\n have hcore := hA.core_final ω istar\n have hsplit : ∑ t ∈ Finset.Icc 1 A.T, A.η t * L0 t (A.a t ω)\n = (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t * L0 t (A.a t ω))\n + ∑ q ∈ bset A, A.η q * L0 q (A.a q ω) :=\n (Finset.sum_sdiff hbsub).symm\n have hb1 : (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t * L0 t (A.a t ω))\n ≤ ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t := by\n refine Finset.sum_le_sum (fun t _ => ?_)\n nlinarith [hA.hηpos t, hL01 t (A.a t ω), hL00 t (A.a t ω)]\n have hb2 : ∑ q ∈ bset A, A.η q * L0 q (A.a q ω)\n = ∑ q ∈ bset A, A.η q * A.l q ω (A.a q ω) :=\n Finset.sum_congr rfl (fun q _ => by rw [hlc q ω (A.a q ω)])\n rw [hsplit, hb2]\n linarith\n -- Step 4 : integrability and integration\n have hS1int : Integrable (fun ω => ∑ q ∈ bset A, A.η q * ltil A q ω istar) μ :=\n integrable_finset_sum _ (fun q hq => ((hltil1 q hq istar).1).const_mul _)\n have hS1val : ∫ ω, (∑ q ∈ bset A, A.η q * ltil A q ω istar) ∂μ\n = ∑ q ∈ bset A, A.η q * L0 q istar := by\n rw [integral_finset_sum _ (fun q hq => ((hltil1 q hq istar).1).const_mul _)]\n refine Finset.sum_congr rfl (fun q hq => ?_)\n rw [integral_const_mul, (hltil1 q hq istar).2]\n have hS2int : Integrable (fun ω => ∑ q ∈ bset A,\n (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i) μ :=\n integrable_finset_sum _ (fun q hq => ((hsumltil q hq).1).const_mul _)\n have hS2val : ∫ ω, (∑ q ∈ bset A,\n (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i) ∂μ\n = ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (∑ i, L0 q i) := by\n rw [integral_finset_sum _ (fun q hq => ((hsumltil q hq).1).const_mul _)]\n refine Finset.sum_congr rfl (fun q hq => ?_)\n rw [integral_const_mul, (hsumltil q hq).2]\n have hS3int : Integrable (fun ω => ∑ q ∈ bset A, ∑ r ∈ Rset A q,\n A.η q * ∑ i, dpos A r ω i * ltil A q ω i) μ :=\n integrable_finset_sum _ (fun q hq => integrable_finset_sum _\n (fun r hr => ((hdposltil_bd q hq r hr).1).const_mul _))\n have hS3val : ∫ ω, (∑ q ∈ bset A, ∑ r ∈ Rset A q,\n A.η q * ∑ i, dpos A r ω i * ltil A q ω i) ∂μ\n ≤ ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * (2 * A.η r) := by\n rw [integral_finset_sum _ (fun q hq => integrable_finset_sum _\n (fun r hr => ((hdposltil_bd q hq r hr).1).const_mul _))]\n refine Finset.sum_le_sum (fun q hq => ?_)\n rw [integral_finset_sum _ (fun r hr => ((hdposltil_bd q hq r hr).1).const_mul _)]\n refine Finset.sum_le_sum (fun r hr => ?_)\n rw [integral_const_mul]\n exact mul_le_mul_of_nonneg_left (hdposltil_bd q hq r hr).2 (le_of_lt (hA.hηpos q))\n have hLHSint : Integrable (fun ω => ∑ t ∈ Finset.Icc 1 A.T, A.η t * L0 t (A.a t ω)) μ := by\n refine hFintC _ (∑ t ∈ Finset.Icc 1 A.T, A.η t) ?_ ?_ ?_\n · refine Finset.measurable_sum _ (fun t _ => ?_)\n exact (Measurable.comp (measurable_of_countable (L0 t)) (ha t)).const_mul _\n · exact fun ω => Finset.sum_nonneg (fun t _ =>\n mul_nonneg (le_of_lt (hA.hηpos t)) (hL00 t _))\n · intro ω\n refine Finset.sum_le_sum (fun t _ => ?_)\n nlinarith [hA.hηpos t, hL01 t (A.a t ω)]\n have hI0 : Integrable (fun _ω : Ω => (Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t)) μ := integrable_const _\n have hI1 : Integrable (fun ω => (Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar)) μ := hI0.add hS1int\n have hI2 : Integrable (fun ω => (Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar) + (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i)) μ := hI1.add hS2int\n have hRHSint : Integrable (fun ω => (Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar) + (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i) + (∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i)) μ := hI2.add hS3int\n have hmain := integral_mono hLHSint hRHSint hpath\n have e1 : ∫ ω, ((Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar) + (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i) + (∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i)) ∂μ\n = (∫ ω, ((Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar) + (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i)) ∂μ) + (∫ ω, (∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i) ∂μ) := integral_add hI2 hS3int\n have e2 : ∫ ω, ((Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar) + (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i)) ∂μ\n = (∫ ω, ((Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar)) ∂μ) + (∫ ω, (∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i) ∂μ) := integral_add hI1 hS2int\n have e3 : ∫ ω, ((Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (∑ q ∈ bset A, A.η q * ltil A q ω istar)) ∂μ\n = (∫ _ω : Ω, ((Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t)) ∂μ) + (∫ ω, (∑ q ∈ bset A, A.η q * ltil A q ω istar) ∂μ) := integral_add hI0 hS1int\n have e4 : ∫ _ω : Ω, ((Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t)) ∂μ = (Real.log K + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) := by simp\n rw [e1, e2, e3, e4, hS1val, hS2val] at hmain\n -- Step 5 : final arithmetic\n have hA1 : ∑ q ∈ bset A, A.η q * L0 q istar\n ≤ ∑ t ∈ Finset.Icc 1 A.T, A.η t * L0 t istar :=\n Finset.sum_le_sum_of_subset_of_nonneg hbsub\n (fun t _ _ => mul_nonneg (le_of_lt (hA.hηpos t)) (hL00 t istar))\n have hB1 : ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (∑ i, L0 q i)\n ≤ (Real.exp 2/2) * K * (∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2) := by\n have hstep : ∀ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (∑ i, L0 q i)\n ≤ (Real.exp 2/2) * K * (A.η q)^2 := by\n intro q _\n rw [hγ0 q]\n have hsum : ∑ i, L0 q i ≤ (K:ℝ) := by\n calc ∑ i, L0 q i ≤ ∑ _i : Fin K, (1:ℝ) := Finset.sum_le_sum (fun i _ => hL01 q i)\n _ = K := by simp\n have h0 : (0:ℝ) ≤ (Real.exp 2/2) * (A.η q)^2 := by positivity\n nlinarith [Finset.sum_nonneg (fun (i : Fin K) (_ : i ∈ Finset.univ) => hL00 q i)]\n calc ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (∑ i, L0 q i)\n ≤ ∑ q ∈ bset A, (Real.exp 2/2) * K * (A.η q)^2 := Finset.sum_le_sum hstep\n _ ≤ ∑ t ∈ Finset.Icc 1 A.T, (Real.exp 2/2) * K * (A.η t)^2 :=\n Finset.sum_le_sum_of_subset_of_nonneg hbsub (fun t _ _ => by positivity)\n _ = (Real.exp 2/2) * K * (∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2) := by\n rw [Finset.mul_sum]\n have hC1 : ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * (2 * A.η r)\n ≤ 4 * (∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ)) := by\n have he : ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * (2 * A.η r)\n = 2 * ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * A.η r := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl (fun q _ => ?_)\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun r _ => by ring)\n rw [he]\n have h2 := hA.eta_pair_bound\n linarith\n linarith [hS3val]\n\nend Master\n\nsection SetArith\n\nlemma exp_two_ge_four : (4:ℝ) ≤ Real.exp 2 := by\n have h : (2:ℝ) < Real.exp 1 := by\n have := Real.exp_one_gt_d9\n linarith\n have he : Real.exp 2 = Real.exp 1 * Real.exp 1 := by\n rw [← Real.exp_add]; norm_num\n nlinarith [Real.exp_pos 1]\n\n/-- Rounds actually used by the algorithm up to horizon `T`. -/\nnoncomputable def Bset (T : ℕ) (d : ℕ → ℕ) (η : ℕ → ℝ) : Finset ℕ :=\n (Finset.Icc 1 T).filter (fun q => q + d q ≤ T ∧ (d q : ℝ) ≤ 1/(Real.exp 2 * η q) - 1)\n\nlemma mem_Bset {T : ℕ} {d : ℕ → ℕ} {η : ℕ → ℝ} {q : ℕ} :\n q ∈ Bset T d η ↔ q ∈ Finset.Icc 1 T ∧ (q + d q ≤ T ∧ (d q : ℝ) ≤ 1/(Real.exp 2 * η q) - 1) := by\n unfold Bset; simp [Finset.mem_filter]\n\nlemma mem_MStar {T : ℕ} {d : ℕ → ℕ} {η : ℕ → ℝ} {t : ℕ} :\n t ∈ MStar T d η ↔ t ∈ Finset.Icc 1 T ∧ (T < t + d t ∨ (d t : ℝ) ≥ 1/(Real.exp 2 * η t) - 1) := by\n unfold MStar; simp [Finset.mem_filter]\n\nlemma set_arith (T : ℕ) (d : ℕ → ℕ) (η : ℕ → ℝ) (hηpos : ∀ t, 0 < η t) :\n 4 * (∑ q ∈ Bset T d η, (η q)^2 * (d q : ℝ))\n + (∑ t ∈ (Finset.Icc 1 T) \\ Bset T d η, η t)\n ≤ 4 * (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t)^2 * (d t : ℝ))\n + ∑ t ∈ MStar T d η, η t := by\n classical\n have hBsub : Bset T d η ⊆ Finset.Icc 1 T := Finset.filter_subset _ _\n have hcompl : (Bset T d η).filter (fun q => q ∉ MStar T d η)\n = (Finset.Icc 1 T) \\ MStar T d η := by\n ext q\n rw [Finset.mem_filter, Finset.mem_sdiff]\n constructor\n · rintro ⟨hqB, hnm⟩\n exact ⟨hBsub hqB, hnm⟩\n · rintro ⟨hIcc, hnm⟩\n refine ⟨mem_Bset.2 ⟨hIcc, ?_, ?_⟩, hnm⟩\n · by_contra hc\n exact hnm (mem_MStar.2 ⟨hIcc, Or.inl (by omega)⟩)\n · by_contra hc\n push_neg at hc\n exact hnm (mem_MStar.2 ⟨hIcc, Or.inr (le_of_lt hc)⟩)\n have hsplit : ∑ q ∈ Bset T d η, (η q)^2 * (d q : ℝ)\n = (∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η), (η q)^2 * (d q : ℝ))\n + ∑ q ∈ (Finset.Icc 1 T) \\ MStar T d η, (η q)^2 * (d q : ℝ) := by\n rw [← hcompl]\n exact (Finset.sum_filter_add_sum_filter_not (Bset T d η)\n (fun q => q ∈ MStar T d η) _).symm\n have hkey : ∀ q ∈ Bset T d η, 4 * ((η q)^2 * (d q : ℝ)) ≤ η q := by\n intro q hq\n obtain ⟨-, -, hdq⟩ := mem_Bset.1 hq\n have hp := hηpos q\n have he2 : (0:ℝ) < Real.exp 2 * η q := mul_pos (Real.exp_pos 2) hp\n have h1 : (η q)^2 * (d q : ℝ) ≤ (η q)^2 * (1/(Real.exp 2 * η q) - 1) :=\n mul_le_mul_of_nonneg_left hdq (sq_nonneg _)\n have h2 : (η q)^2 * (1/(Real.exp 2 * η q) - 1) = η q / Real.exp 2 - (η q)^2 := by\n field_simp\n have h4 := exp_two_ge_four\n have h3 : 4 * (η q / Real.exp 2) ≤ η q := by\n rw [← mul_div_assoc, div_le_iff₀ (Real.exp_pos 2)]\n nlinarith\n nlinarith [sq_nonneg (η q)]\n have hbd1 : 4 * (∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η), (η q)^2 * (d q : ℝ))\n ≤ ∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η), η q := by\n rw [Finset.mul_sum]\n exact Finset.sum_le_sum (fun q hq => hkey q (Finset.mem_filter.1 hq).1)\n have hUdisj : Disjoint ((Finset.Icc 1 T) \\ Bset T d η)\n ((Bset T d η).filter (fun q => q ∈ MStar T d η)) := by\n rw [Finset.disjoint_left]\n intro x hx hx2\n rw [Finset.mem_sdiff] at hx\n exact hx.2 (Finset.mem_filter.1 hx2).1\n have hUsub : ((Finset.Icc 1 T) \\ Bset T d η)\n ∪ ((Bset T d η).filter (fun q => q ∈ MStar T d η)) ⊆ MStar T d η := by\n intro x hx\n rw [Finset.mem_union] at hx\n rcases hx with hx | hx\n · rw [Finset.mem_sdiff] at hx\n obtain ⟨hIcc, hnb⟩ := hx\n rw [mem_Bset] at hnb\n push_neg at hnb\n rw [mem_MStar]\n refine ⟨hIcc, ?_⟩\n by_cases hle : T < x + d x\n · exact Or.inl hle\n · exact Or.inr (le_of_lt (hnb hIcc (by omega)))\n · exact (Finset.mem_filter.1 hx).2\n have hbd2 : (∑ t ∈ (Finset.Icc 1 T) \\ Bset T d η, η t)\n + (∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η), η q)\n ≤ ∑ t ∈ MStar T d η, η t := by\n rw [← Finset.sum_union hUdisj]\n exact Finset.sum_le_sum_of_subset_of_nonneg hUsub (fun t _ _ => le_of_lt (hηpos t))\n rw [hsplit, mul_add]\n linarith\n\nprivate lemma set_arith_adaptive (T K : ℕ) (d : ℕ → ℕ) (η : ℕ → ℝ)\n (hK : 0 < K) (hηpos : ∀ t, 0 < η t) :\n Real.exp 2 * (∑ q ∈ Bset T d η, (η q)^2 * (d q : ℝ))\n + (∑ t ∈ (Finset.Icc 1 T) \\ Bset T d η, η t)\n ≤ 4 * Real.exp 2 * (K : ℝ) *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t)^2 * (d t : ℝ))\n + ∑ t ∈ MStar T d η, η t := by\n classical\n have hBsub : Bset T d η ⊆ Finset.Icc 1 T := Finset.filter_subset _ _\n have hcompl : (Bset T d η).filter (fun q => q ∉ MStar T d η)\n = (Finset.Icc 1 T) \\ MStar T d η := by\n ext q\n rw [Finset.mem_filter, Finset.mem_sdiff]\n constructor\n · rintro ⟨hqB, hnm⟩\n exact ⟨hBsub hqB, hnm⟩\n · rintro ⟨hIcc, hnm⟩\n refine ⟨mem_Bset.2 ⟨hIcc, ?_, ?_⟩, hnm⟩\n · by_contra hc\n exact hnm (mem_MStar.2 ⟨hIcc, Or.inl (by omega)⟩)\n · by_contra hc\n push_neg at hc\n exact hnm (mem_MStar.2 ⟨hIcc, Or.inr (le_of_lt hc)⟩)\n have hsplit : ∑ q ∈ Bset T d η, (η q)^2 * (d q : ℝ)\n = (∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η),\n (η q)^2 * (d q : ℝ))\n + ∑ q ∈ (Finset.Icc 1 T) \\ MStar T d η, (η q)^2 * (d q : ℝ) := by\n rw [← hcompl]\n exact (Finset.sum_filter_add_sum_filter_not (Bset T d η)\n (fun q => q ∈ MStar T d η) _).symm\n have hkey : ∀ q ∈ Bset T d η,\n Real.exp 2 * ((η q)^2 * (d q : ℝ)) ≤ η q := by\n intro q hq\n obtain ⟨-, -, hdq⟩ := mem_Bset.1 hq\n have hp := hηpos q\n have he2 : (0 : ℝ) < Real.exp 2 := Real.exp_pos 2\n have heη : (0 : ℝ) < Real.exp 2 * η q := mul_pos he2 hp\n have h1 : (η q)^2 * (d q : ℝ)\n ≤ (η q)^2 * (1 / (Real.exp 2 * η q) - 1) :=\n mul_le_mul_of_nonneg_left hdq (sq_nonneg _)\n have h2 : (η q)^2 * (1 / (Real.exp 2 * η q) - 1)\n = η q / Real.exp 2 - (η q)^2 := by\n field_simp\n calc\n Real.exp 2 * ((η q)^2 * (d q : ℝ))\n ≤ Real.exp 2 * ((η q)^2 * (1 / (Real.exp 2 * η q) - 1)) :=\n mul_le_mul_of_nonneg_left h1 he2.le\n _ = η q - Real.exp 2 * (η q)^2 := by\n rw [h2]\n field_simp\n _ ≤ η q := by\n have hn : 0 ≤ Real.exp 2 * (η q)^2 :=\n mul_nonneg (Real.exp_pos 2).le (sq_nonneg _)\n linarith\n have hbd1 : Real.exp 2 *\n (∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η),\n (η q)^2 * (d q : ℝ))\n ≤ ∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η), η q := by\n rw [Finset.mul_sum]\n exact Finset.sum_le_sum (fun q hq => hkey q (Finset.mem_filter.1 hq).1)\n have hUdisj : Disjoint ((Finset.Icc 1 T) \\ Bset T d η)\n ((Bset T d η).filter (fun q => q ∈ MStar T d η)) := by\n rw [Finset.disjoint_left]\n intro x hx hx2\n rw [Finset.mem_sdiff] at hx\n exact hx.2 (Finset.mem_filter.1 hx2).1\n have hUsub : ((Finset.Icc 1 T) \\ Bset T d η)\n ∪ ((Bset T d η).filter (fun q => q ∈ MStar T d η)) ⊆ MStar T d η := by\n intro x hx\n rw [Finset.mem_union] at hx\n rcases hx with hx | hx\n · rw [Finset.mem_sdiff] at hx\n obtain ⟨hIcc, hnb⟩ := hx\n rw [mem_Bset] at hnb\n push_neg at hnb\n rw [mem_MStar]\n refine ⟨hIcc, ?_⟩\n by_cases hle : T < x + d x\n · exact Or.inl hle\n · exact Or.inr (le_of_lt (hnb hIcc (by omega)))\n · exact (Finset.mem_filter.1 hx).2\n have hbd2 : (∑ t ∈ (Finset.Icc 1 T) \\ Bset T d η, η t)\n + (∑ q ∈ (Bset T d η).filter (fun q => q ∈ MStar T d η), η q)\n ≤ ∑ t ∈ MStar T d η, η t := by\n rw [← Finset.sum_union hUdisj]\n exact Finset.sum_le_sum_of_subset_of_nonneg hUsub\n (fun t _ _ => (hηpos t).le)\n have hgood0 : 0 ≤ ∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η,\n (η t)^2 * (d t : ℝ) := Finset.sum_nonneg (fun t _ => by positivity)\n have hK1 : (1 : ℝ) ≤ (K : ℝ) := by exact_mod_cast hK\n have hgood : Real.exp 2 *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t)^2 * (d t : ℝ))\n ≤ 4 * Real.exp 2 * (K : ℝ) *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t)^2 * (d t : ℝ)) := by\n have hcoef : (1 : ℝ) ≤ 4 * (K : ℝ) := by nlinarith\n have hnon : 0 ≤ Real.exp 2 *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t)^2 * (d t : ℝ)) :=\n mul_nonneg (Real.exp_pos 2).le hgood0\n calc\n Real.exp 2 *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t)^2 * (d t : ℝ))\n = 1 * (Real.exp 2 *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η,\n (η t)^2 * (d t : ℝ))) := by ring\n _ ≤ (4 * (K : ℝ)) * (Real.exp 2 *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η,\n (η t)^2 * (d t : ℝ))) :=\n mul_le_mul_of_nonneg_right hcoef hnon\n _ = 4 * Real.exp 2 * (K : ℝ) *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η,\n (η t)^2 * (d t : ℝ)) := by ring\n rw [hsplit, mul_add]\n linarith\n\nend SetArith\n\nsection Obl\n\nlemma bset_toAlg {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {K : ℕ} {hK : 0 < K}\n {l : ℕ → Ω → Fin K → ℝ} {d : ℕ → ℕ} {η γ : ℕ → ℝ}\n (T : ℕ) (E : Exp3Delayed μ K hK l d η γ) :\n bset (toAlg T d η γ l E) = Bset T d η := rfl\n\nend Obl\n\n-- ############ END MACHINERY ############\n\ntheorem lemma5_oblivious {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (K T : ℕ) (hK : 0 < K) (hT : 0 < T)\n (η : ℕ → ℝ) (l0 : ℕ → Fin K → ℝ) (d : ℕ → ℕ) (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hη_pos : ∀ t, 0 < η t) (hη_dec : ∀ t, η (t + 1) ≤ η t)\n (hη_bound : ∀ t, η t ≤ (1 / 2) * Real.exp (-2))\n (hl : ∀ t i, l0 t i ∈ Set.Icc (0 : ℝ) 1)\n (E : Exp3Delayed μ K hK (fun t _ i => l0 t i) d η (fun _ => 0))\n\n \n \n \n \n \n \n (a_fresh : ∀ t t' i, t ≤ t' → t' < t + d t →\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n E.𝓕 t' ⊔ ⨆ s ∈ {s : ℕ | s + d s < t + d t ∨ (s + d s = t + d t ∧ s < t)},\n MeasurableSpace.comap (E.a s) inferInstance]) =ᵐ[μ] (fun ω => E.p t ω i)) :\n weightedExpReg μ T K hK η (fun t _ i => l0 t i) E.a ≤\n Real.log K + (Real.exp 2 / 2) * K * (∑ t ∈ Finset.Icc 1 T, (η t) ^ 2)\n + 4 * (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t) ^ 2 * (d t : ℝ))\n + (∑ t ∈ MStar T d η, η t) := by\n classical\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n have hA : AlgOK (toAlg T d η (fun _ => 0) (fun t _ i => l0 t i) E) :=\n toAlg_ok T E hd hη_pos hη_dec hη_bound\n (fun t ω i => (hl t i).1) (fun t ω i => (hl t i).2) (fun _ => le_rfl)\n have hmle : ∀ q : ℕ, (E.𝓕 q ⊔ ⨆ s ∈ {s : ℕ | s + d s < q + d q ∨ (s + d s = q + d q ∧ s < q)},\n MeasurableSpace.comap (E.a s) inferInstance) ≤ (inferInstance : MeasurableSpace Ω) := by\n intro q\n refine sup_le (E.𝓕_le q) (iSup_le (fun s => iSup_le (fun _ => ?_)))\n exact measurable_iff_comap_le.1 (E.measurable_a s)\n have hMm : ∀ q ∈ bset (toAlg T d η (fun _ => 0) (fun t _ i => l0 t i) E),\n Mact (toAlg T d η (fun _ => 0) (fun t _ i => l0 t i) E)\n (kkey (toAlg T d η (fun _ => 0) (fun t _ i => l0 t i) E).T\n (toAlg T d η (fun _ => 0) (fun t _ i => l0 t i) E).d q)\n ≤ (E.𝓕 q ⊔ ⨆ s ∈ {s : ℕ | s + d s < q + d q ∨ (s + d s = q + d q ∧ s < q)},\n MeasurableSpace.comap (E.a s) inferInstance) := by\n intro q hq\n refine iSup_le (fun u => iSup_le (fun hu => ?_))\n obtain ⟨hub, huk⟩ := hu\n have huT : u ≤ T := bset_le_T hub\n have hqT : q ≤ T := bset_le_T hq\n have hcase : (u + d u < q + d q) ∨ (u + d u = q + d q ∧ u < q) :=\n (kkey_lt_iff (T := T) (d := d) huT hqT).1 huk\n exact le_sup_of_le_right (le_iSup_of_le u (le_iSup_of_le hcase le_rfl))\n have hcond : ∀ q ∈ bset (toAlg T d η (fun _ => 0) (fun t _ i => l0 t i) E), ∀ i,\n (μ[(fun ω => if E.a q ω = i then (1:ℝ) else 0) |\n (E.𝓕 q ⊔ ⨆ s ∈ {s : ℕ | s + d s < q + d q ∨ (s + d s = q + d q ∧ s < q)},\n MeasurableSpace.comap (E.a s) inferInstance)]) =ᵐ[μ] (fun ω => E.p q ω i) := by\n intro q hq i\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hdq : 1 ≤ d q := hd q hq1\n exact a_fresh q q i le_rfl (by omega)\n obtain ⟨istar, -, hstar⟩ := Finset.exists_mem_eq_inf' (Finset.univ_nonempty (α := Fin K))\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l0 t i)\n have hmb := master_bound (toAlg T d η (fun _ => 0) (fun t _ i => l0 t i) E) hA l0\n (fun q ω i => rfl) (fun t => rfl) μ\n (fun q => E.𝓕 q ⊔ ⨆ s ∈ {s : ℕ | s + d s < q + d q ∨ (s + d s = q + d q ∧ s < q)},\n MeasurableSpace.comap (E.a s) inferInstance)\n hmle hMm E.measurable_a hcond istar\n simp only [toAlg_T, toAlg_eta, toAlg_a, toAlg_d, bset_toAlg] at hmb\n -- integrability of the realized loss\n have hLHSint : Integrable (fun ω => ∑ t ∈ Finset.Icc 1 T, η t * l0 t (E.a t ω)) μ := by\n refine (integrable_const (∑ t ∈ Finset.Icc 1 T, η t)).mono' ?_ ?_\n · refine (Finset.measurable_sum _ (fun t _ =>\n (Measurable.comp (measurable_of_countable (l0 t)) (E.measurable_a t)).const_mul _)).aestronglyMeasurable\n · refine Filter.Eventually.of_forall (fun ω => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg\n (Finset.sum_nonneg (fun t _ => mul_nonneg (le_of_lt (hη_pos t)) (hl t _).1))]\n refine Finset.sum_le_sum (fun t _ => ?_)\n nlinarith [hη_pos t, (hl t (E.a t ω)).2, (hl t (E.a t ω)).1]\n have hCeq : (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l0 t i)\n = ∑ t ∈ Finset.Icc 1 T, η t * l0 t istar := hstar\n have esub : ∫ ω, ((∑ t ∈ Finset.Icc 1 T, η t * l0 t (E.a t ω))\n - (∑ t ∈ Finset.Icc 1 T, η t * l0 t istar)) ∂μ\n = (∫ ω, (∑ t ∈ Finset.Icc 1 T, η t * l0 t (E.a t ω)) ∂μ)\n - (∫ _ω : Ω, (∑ t ∈ Finset.Icc 1 T, η t * l0 t istar) ∂μ) :=\n integral_sub hLHSint (integrable_const _)\n have econst : (∫ _ω : Ω, (∑ t ∈ Finset.Icc 1 T, η t * l0 t istar) ∂μ)\n = ∑ t ∈ Finset.Icc 1 T, η t * l0 t istar := by simp\n have hval : weightedExpReg μ T K hK η (fun t _ i => l0 t i) E.a\n = (∫ ω, (∑ t ∈ Finset.Icc 1 T, η t * l0 t (E.a t ω)) ∂μ)\n - (∑ t ∈ Finset.Icc 1 T, η t * l0 t istar) := by\n show (∫ ω, ((∑ t ∈ Finset.Icc 1 T, η t * l0 t (E.a t ω))\n - (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l0 t i)) ∂μ) = _\n rw [hCeq, esub, econst]\n rw [hval]\n have hsa := set_arith T d η hη_pos\n linarith\nsection Thm6Prep\n\nlemma inf'_const_mul {ι : Type*} (s : Finset ι) (H : s.Nonempty) (c : ℝ) (hc : 0 ≤ c)\n (f : ι → ℝ) : s.inf' H (fun i => c * f i) = c * s.inf' H f := by\n apply le_antisymm\n · obtain ⟨j, hj, hje⟩ := Finset.exists_mem_eq_inf' H f\n rw [hje]\n exact Finset.inf'_le (fun i => c * f i) hj\n · exact Finset.le_inf' H _ (fun i hi => mul_le_mul_of_nonneg_left (Finset.inf'_le f hi) hc)\n\nlemma weightedExpReg_const {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) (T K : ℕ)\n (hK : 0 < K) (c : ℝ) (hc : 0 ≤ c) (l0 : ℕ → Fin K → ℝ) (a : ℕ → Ω → Fin K) :\n weightedExpReg μ T K hK (fun _ => c) (fun t _ i => l0 t i) a\n = c * expReg μ T K hK l0 a := by\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n show (∫ ω, ((∑ t ∈ Finset.Icc 1 T, c * l0 t (a t ω))\n - (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, c * l0 t i)) ∂μ)\n = c * ∫ ω, ((∑ t ∈ Finset.Icc 1 T, (1:ℝ) * l0 t (a t ω))\n - (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, (1:ℝ) * l0 t i)) ∂μ\n rw [← integral_const_mul]\n refine integral_congr_ae (Filter.Eventually.of_forall (fun ω => ?_))\n dsimp only\n have h1 : ∀ i : Fin K, (∑ t ∈ Finset.Icc 1 T, c * l0 t i)\n = c * ∑ t ∈ Finset.Icc 1 T, (1:ℝ) * l0 t i := by\n intro i\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun t _ => by ring)\n have h2 : (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, c * l0 t i)\n = c * (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, (1:ℝ) * l0 t i) := by\n have hf : (fun i => ∑ t ∈ Finset.Icc 1 T, c * l0 t i)\n = (fun i => c * ∑ t ∈ Finset.Icc 1 T, (1:ℝ) * l0 t i) := funext h1\n rw [hf, inf'_const_mul _ _ c hc]\n have h3 : (∑ t ∈ Finset.Icc 1 T, c * l0 t (a t ω))\n = c * ∑ t ∈ Finset.Icc 1 T, (1:ℝ) * l0 t (a t ω) := by\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun t _ => by ring)\n rw [h2, h3]\n ring\n\nlemma exp_neg_two_le : Real.exp (-2) ≤ 1/4 := by\n have h := exp_two_ge_four\n have hpos : (0:ℝ) < Real.exp 2 := Real.exp_pos 2\n rw [Real.exp_neg]\n rw [inv_le_comm₀ hpos (by norm_num)]\n linarith\n\nend Thm6Prep\n\n-- ############ ADAPTIVE MACHINERY ############\nsection AdaptiveScalar\n\n/-- `z/(1+z) ≤ log (1+z)` for `z ≥ 0`. -/\nlemma log_one_add_ge' (z : ℝ) (hz : 0 ≤ z) : z / (1 + z) ≤ Real.log (1 + z) := by\n have h1 : (0:ℝ) < 1 + z := by linarith\n have h2 : Real.log (1/(1+z)) ≤ 1/(1+z) - 1 := Real.log_le_sub_one_of_pos (by positivity)\n rw [Real.log_div one_ne_zero (ne_of_gt h1), Real.log_one] at h2\n have h3 : (1:ℝ)/(1+z) - 1 = -(z/(1+z)) := by field_simp; ring\n rw [h3] at h2\n linarith\n\n/-- `x * log (1+y) ≤ log (1 + x*y)` for `x ∈ [0,1]`, `y ≥ 0`. -/\nlemma mul_log_one_add_le (x y : ℝ) (hx0 : 0 ≤ x) (hx1 : x ≤ 1) (hy : 0 ≤ y) :\n x * Real.log (1 + y) ≤ Real.log (1 + x * y) := by\n have hcc := (strictConcaveOn_log_Ioi).concaveOn\n have h1 : (1 + y) ∈ Set.Ioi (0:ℝ) := by simp only [Set.mem_Ioi]; linarith\n have h2 : (1:ℝ) ∈ Set.Ioi (0:ℝ) := by simp\n have hres := hcc.2 h1 h2 hx0 (by linarith : (0:ℝ) ≤ 1 - x) (by ring)\n simp only [smul_eq_mul, Real.log_one, mul_zero, add_zero, mul_one] at hres\n have heq : x * (1+y) + (1-x) = 1 + x*y := by ring\n rw [heq] at hres\n exact hres\n\n/-- The key scalar inequality behind Neu's implicit-exploration bound. -/\nlemma exp_ltil_scalar {a g l p : ℝ} (hg : 0 < g) (ha0 : 0 ≤ a) (hag : a ≤ g)\n (hl0 : 0 ≤ l) (hl1 : l ≤ 1) (hp : 0 < p) :\n Real.exp (a * l / (p + g)) ≤ 1 + a * l / p := by\n have hpgl : 0 < p + g * l := by nlinarith\n have hx0 : 0 ≤ a / g := by positivity\n have hx1 : a / g ≤ 1 := by rw [div_le_one hg]; exact hag\n have hz0 : 0 ≤ g * l / p := by positivity\n have h1z : (0:ℝ) < 1 + g * l / p := by linarith\n have hxz : (a/g) * (g*l/p) = a * l / p := by field_simp\n have hzz : (a/g) * ((g*l/p) / (1 + g*l/p)) = a * l / (p + g * l) := by\n rw [eq_div_iff (ne_of_gt hpgl)]\n field_simp\n have step1 : a * l / (p + g) ≤ (a/g) * ((g*l/p) / (1 + g*l/p)) := by\n rw [hzz]\n apply div_le_div_of_nonneg_left (by positivity) hpgl\n nlinarith\n have step2 : (a/g) * ((g*l/p) / (1 + g*l/p)) ≤ (a/g) * Real.log (1 + g*l/p) :=\n mul_le_mul_of_nonneg_left (log_one_add_ge' _ hz0) hx0\n have step3 : (a/g) * Real.log (1 + g*l/p) ≤ Real.log (1 + a*l/p) := by\n have h := mul_log_one_add_le (a/g) (g*l/p) hx0 hx1 hz0\n rwa [hxz] at h\n have hfin : a * l / (p+g) ≤ Real.log (1 + a*l/p) := by linarith\n have hpos : (0:ℝ) < 1 + a*l/p := by positivity\n calc Real.exp (a * l / (p+g)) ≤ Real.exp (Real.log (1 + a*l/p)) := Real.exp_le_exp.2 hfin\n _ = 1 + a*l/p := Real.exp_log hpos\n\nend AdaptiveScalar\n\nsection AdaptiveMeas\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\n\n/-- The plain (exploration-free) importance-weighted estimator. -/\nnoncomputable def lhat (A : AlgData Ω K) (q : ℕ) (ω : Ω) (i : Fin K) : ℝ :=\n A.l q ω i * (if A.a q ω = i then (1:ℝ) else 0) / A.p q ω i\n\nlemma sum_alpha_ltil (A : AlgData Ω K) (α : Fin K → ℝ) (q : ℕ) (ω : Ω) :\n ∑ i, α i * ltil A q ω i\n = α (A.a q ω) * A.l q ω (A.a q ω) / (A.p q ω (A.a q ω) + A.γ q) := by\n rw [Finset.sum_eq_single (A.a q ω)]\n · unfold ltil; rw [if_pos rfl]; ring\n · intro b _ hb; unfold ltil; rw [if_neg (Ne.symm hb)]; ring\n · intro h; exact absurd (Finset.mem_univ _) h\n\nlemma sum_alpha_lhat (A : AlgData Ω K) (α : Fin K → ℝ) (q : ℕ) (ω : Ω) :\n ∑ i, α i * lhat A q ω i\n = α (A.a q ω) * A.l q ω (A.a q ω) / A.p q ω (A.a q ω) := by\n rw [Finset.sum_eq_single (A.a q ω)]\n · unfold lhat; rw [if_pos rfl]; ring\n · intro b _ hb; unfold lhat; rw [if_neg (Ne.symm hb)]; ring\n · intro h; exact absurd (Finset.mem_univ _) h\n\nlemma lhat_nonneg (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω) (i : Fin K) :\n 0 ≤ lhat A q ω i := by\n unfold lhat\n refine div_nonneg (mul_nonneg (hA.hl0 _ _ _) (by positivity)) ?_\n exact le_of_lt (hA.p_pos_bset hq ω i)\n\n/-- Pathwise exponential bound: the heart of Neu's implicit-exploration argument. -/\nlemma exp_sum_alpha_ltil_le (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (ω : Ω)\n (α : Fin K → ℝ) (hα0 : ∀ i, 0 ≤ α i) (hαγ : ∀ i, α i ≤ A.γ q) (hγ : 0 < A.γ q) :\n Real.exp (∑ i, α i * ltil A q ω i) ≤ 1 + ∑ i, α i * lhat A q ω i := by\n rw [sum_alpha_ltil, sum_alpha_lhat]\n exact exp_ltil_scalar hγ (hα0 _) (hαγ _) (hA.hl0 _ _ _) (hA.hl1 _ _ _)\n (hA.p_pos_bset hq ω _)\n\n/-- `p t` is measurable with respect to an \"action filtration\". -/\nlemma p_meas_filt (hA : AlgOK A) (G : ℕ → MeasurableSpace Ω) (hGmono : Monotone G)\n (hGa : ∀ u t : ℕ, 1 ≤ u → u < t → MeasurableSpace.comap (A.a u) inferInstance ≤ G t)\n (hGl : ∀ q i, Measurable[G q] (fun ω => A.l q ω i)) :\n ∀ t : ℕ, 1 ≤ t → t ≤ A.T + 1 → ∀ i, Measurable[G t] (fun ω => A.p t ω i) := by\n intro t\n induction t using Nat.strong_induction_on with\n | _ t IH =>\n intro ht1 ht2 i\n have hGG : ∀ j, Measurable[G t] (fun ω => GG A (t*(A.T+1)) ω j) := by\n intro j\n unfold GG\n refine Finset.measurable_sum _ (fun q hq => ?_)\n rw [Finset.mem_filter] at hq\n obtain ⟨hqb, hqk⟩ := hq\n have hq1 : 1 ≤ q := (mem_bset.1 hqb).1.1\n have hqT : q ≤ A.T := bset_le_T hqb\n have hqlt : q < t := by\n by_contra hc\n push_neg at hc\n have h1 : t * (A.T+1) ≤ q * (A.T+1) := Nat.mul_le_mul_right _ hc\n have h2 : q * (A.T+1) ≤ (q + A.d q)*(A.T+1) :=\n Nat.mul_le_mul_right _ (Nat.le_add_right _ _)\n have h3 : (q + A.d q)*(A.T+1) ≤ kkey A.T A.d q := by\n show (q + A.d q)*(A.T+1) ≤ (q + A.d q)*(A.T+1) + q\n omega\n exact absurd hqk (not_lt.2 (h1.trans (h2.trans h3)))\n refine Measurable.const_mul ?_ _\n exact AlgOK.ltil_meas A (G t) (measurable_iff_comap_le.2 (hGa q t hq1 hqlt))\n (fun j' => (IH q hqlt hq1 (by omega) j').mono (hGmono (le_of_lt hqlt)) le_rfl)\n (fun j' => (hGl q j').mono (hGmono (le_of_lt hqlt)) le_rfl) j\n have hpe : (fun ω => A.p t ω i) = fun ω => sfm (GG A (t*(A.T+1)) ω) i :=\n funext (fun ω => hA.hp t ω i ht1 ht2)\n rw [hpe]\n unfold sfm\n exact ((hGG i).neg.exp).div (Finset.measurable_sum _ (fun j _ => (hGG j).neg.exp))\n\nlemma ltil_meas_filt (hA : AlgOK A) (G : ℕ → MeasurableSpace Ω) (hGmono : Monotone G)\n (hGa : ∀ u t : ℕ, 1 ≤ u → u < t → MeasurableSpace.comap (A.a u) inferInstance ≤ G t)\n (hGl : ∀ q i, Measurable[G q] (fun ω => A.l q ω i))\n {q n : ℕ} (hq : q ∈ bset A) (hqn : q < n) (i : Fin K) :\n Measurable[G n] (fun ω => ltil A q ω i) := by\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n exact AlgOK.ltil_meas A (G n) (measurable_iff_comap_le.2 (hGa q n hq1 hqn))\n (fun j => (p_meas_filt hA G hGmono hGa hGl q hq1 (by omega) j).mono\n (hGmono (le_of_lt hqn)) le_rfl)\n (fun j => (hGl q j).mono (hGmono (le_of_lt hqn)) le_rfl) i\n\nlemma ltil_le_inv_gamma (hA : AlgOK A) {q : ℕ} (hq : q ∈ bset A) (hγ : 0 < A.γ q)\n (ω : Ω) (i : Fin K) : ltil A q ω i ≤ 1 / A.γ q := by\n unfold ltil\n rw [div_le_div_iff₀ (hA.pg_pos hq ω i) hγ]\n have h1 : A.l q ω i * (if A.a q ω = i then (1:ℝ) else 0) ≤ 1 := by\n by_cases h : A.a q ω = i\n · rw [if_pos h, mul_one]; exact hA.hl1 _ _ _\n · rw [if_neg h]; simp\n have h2 : 0 ≤ A.p q ω i := le_of_lt (hA.p_pos_bset hq ω i)\n nlinarith\n\nend AdaptiveMeas\nsection AdaptiveMGF\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\n\n/-- Partial exponent: the sum of the centred estimator increments over the rounds\n`q ∈ bset A` with `q < n`. -/\nnoncomputable def Phi (A : AlgData Ω K) (α : ℕ → Fin K → ℝ) (n : ℕ) (ω : Ω) : ℝ :=\n ∑ q ∈ (bset A).filter (fun q => q < n), ∑ i, α q i * (ltil A q ω i - A.l q ω i)\n\nlemma Phi_meas (hA : AlgOK A) (G : ℕ → MeasurableSpace Ω) (hGmono : Monotone G)\n (hGa : ∀ u t : ℕ, 1 ≤ u → u < t → MeasurableSpace.comap (A.a u) inferInstance ≤ G t)\n (hGl : ∀ q i, Measurable[G q] (fun ω => A.l q ω i))\n (α : ℕ → Fin K → ℝ) (n : ℕ) : Measurable[G n] (Phi A α n) := by\n unfold Phi\n refine Finset.measurable_sum _ (fun q hq => ?_)\n rw [Finset.mem_filter] at hq\n refine Finset.measurable_sum _ (fun i _ => ?_)\n refine Measurable.const_mul (Measurable.sub ?_ ?_) _\n · exact ltil_meas_filt hA G hGmono hGa hGl hq.1 hq.2 i\n · exact (hGl q i).mono (hGmono (le_of_lt hq.2)) le_rfl\n\nlemma Phi_le (hA : AlgOK A) (hγpos : ∀ q, 0 < A.γ q) (α : ℕ → Fin K → ℝ)\n (hα0 : ∀ q i, 0 ≤ α q i) (hαγ : ∀ q i, α q i ≤ A.γ q) (n : ℕ) (ω : Ω) :\n Phi A α n ω ≤ ((bset A).card : ℝ) * (K : ℝ) := by\n unfold Phi\n have hterm : ∀ q ∈ (bset A).filter (fun q => q < n),\n ∑ i, α q i * (ltil A q ω i - A.l q ω i) ≤ (K : ℝ) := by\n intro q hq\n rw [Finset.mem_filter] at hq\n have hqb := hq.1\n have hg := hγpos q\n have hinv : A.γ q * (1 / A.γ q) = 1 := by field_simp\n have hstep : ∀ i : Fin K, α q i * (ltil A q ω i - A.l q ω i) ≤ 1 := by\n intro i\n have h1 : 0 ≤ ltil A q ω i := hA.ltil_nonneg hqb ω i\n have h2 : ltil A q ω i ≤ 1 / A.γ q := ltil_le_inv_gamma hA hqb hg ω i\n have h3 : 0 ≤ A.l q ω i := hA.hl0 _ _ _\n nlinarith [hα0 q i, hαγ q i]\n calc ∑ i, α q i * (ltil A q ω i - A.l q ω i) ≤ ∑ _i : Fin K, (1:ℝ) :=\n Finset.sum_le_sum (fun i _ => hstep i)\n _ = (K : ℝ) := by simp\n calc ∑ q ∈ (bset A).filter (fun q => q < n), ∑ i, α q i * (ltil A q ω i - A.l q ω i)\n ≤ ∑ _q ∈ (bset A).filter (fun q => q < n), (K:ℝ) := Finset.sum_le_sum hterm\n _ = (((bset A).filter (fun q => q < n)).card : ℝ) * (K:ℝ) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n _ ≤ ((bset A).card : ℝ) * (K:ℝ) := by\n have : (((bset A).filter (fun q => q < n)).card : ℝ) ≤ ((bset A).card : ℝ) := by\n exact_mod_cast Finset.card_filter_le _ _\n have hK0 : (0:ℝ) ≤ (K:ℝ) := Nat.cast_nonneg _\n exact mul_le_mul_of_nonneg_right this hK0\n\n/-- The exponential supermartingale bound (Neu's lemma), in integral form. -/\nlemma mgf_le_one (hA : AlgOK A) (μ : Measure Ω) [IsProbabilityMeasure μ]\n (G : ℕ → MeasurableSpace Ω) (hGle : ∀ t, G t ≤ mΩ) (hGmono : Monotone G)\n (hGa : ∀ u t : ℕ, 1 ≤ u → u < t → MeasurableSpace.comap (A.a u) inferInstance ≤ G t)\n (hGl : ∀ q i, Measurable[G q] (fun ω => A.l q ω i))\n (ha : ∀ q, Measurable (A.a q))\n (hcond : ∀ q ∈ bset A, ∀ i,\n (μ[(fun ω => if A.a q ω = i then (1:ℝ) else 0) | G q]) =ᵐ[μ] (fun ω => A.p q ω i))\n (hγpos : ∀ q, 0 < A.γ q)\n (α : ℕ → Fin K → ℝ) (hα0 : ∀ q i, 0 ≤ α q i) (hαγ : ∀ q i, α q i ≤ A.γ q) :\n ∀ n, ∫ ω, Real.exp (Phi A α n ω) ∂μ ≤ 1 := by\n classical\n set UB : ℝ := ((bset A).card : ℝ) * (K : ℝ) with hUB\n have hPhiM : ∀ m, Measurable (Phi A α m) := fun m =>\n (Phi_meas hA G hGmono hGa hGl α m).mono (hGle m) le_rfl\n have hPhiB : ∀ m ω, Phi A α m ω ≤ UB := fun m ω => Phi_le hA hγpos α hα0 hαγ m ω\n have hexpint : ∀ m, Integrable (fun ω => Real.exp (Phi A α m ω)) μ := by\n intro m\n refine (integrable_const (Real.exp UB)).mono' (hPhiM m).exp.aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (le_of_lt (Real.exp_pos _))]\n exact Real.exp_le_exp.2 (hPhiB m ω)\n intro n\n induction n with\n | zero =>\n have h0 : ∀ ω, Real.exp (Phi A α 0 ω) = 1 := by\n intro ω\n unfold Phi\n rw [Finset.filter_false_of_mem (fun x _ => by omega), Finset.sum_empty, Real.exp_zero]\n simp only [h0]\n simp\n | succ n ih =>\n by_cases hn : n ∈ bset A\n · -- the substantial step\n have hn1 : 1 ≤ n := (mem_bset.1 hn).1.1\n have hnT : n ≤ A.T := bset_le_T hn\n have hnotmem : n ∉ (bset A).filter (fun q => q < n) := by simp\n have hsplit : (bset A).filter (fun q => q < n+1)\n = insert n ((bset A).filter (fun q => q < n)) := by\n ext x\n simp only [Finset.mem_filter, Finset.mem_insert]\n constructor\n · rintro ⟨hx, hlt⟩\n rcases Nat.lt_succ_iff_lt_or_eq.1 hlt with h | h\n · exact Or.inr ⟨hx, h⟩\n · exact Or.inl h\n · rintro (rfl | ⟨hx, hlt⟩)\n · exact ⟨hn, Nat.lt_succ_self _⟩\n · exact ⟨hx, by omega⟩\n have hPhirec : ∀ ω, Phi A α (n+1) ω\n = Phi A α n ω + ∑ i, α n i * (ltil A n ω i - A.l n ω i) := by\n intro ω\n unfold Phi\n rw [hsplit, Finset.sum_insert hnotmem]\n ring\n -- the G n-measurable prefactor\n set Lsum : Ω → ℝ := fun ω => ∑ i, α n i * A.l n ω i with hLsum\n set F : Ω → ℝ := fun ω => Real.exp (Phi A α n ω) * Real.exp (- Lsum ω) with hFdef\n have hL0 : ∀ ω, 0 ≤ Lsum ω := fun ω =>\n Finset.sum_nonneg (fun i _ => mul_nonneg (hα0 n i) (hA.hl0 _ _ _))\n have hLmeasG : Measurable[G n] Lsum :=\n Finset.measurable_sum _ (fun i _ => (hGl n i).const_mul _)\n have hFmeasG : Measurable[G n] F :=\n ((Phi_meas hA G hGmono hGa hGl α n).exp).mul (hLmeasG.neg.exp)\n have hFmeas : Measurable F := hFmeasG.mono (hGle n) le_rfl\n have hF0 : ∀ ω, 0 ≤ F ω := fun ω => by\n simp only [hFdef]; positivity\n have hFb : ∀ ω, F ω ≤ Real.exp UB := by\n intro ω\n have h1 : Real.exp (Phi A α n ω) ≤ Real.exp UB := Real.exp_le_exp.2 (hPhiB n ω)\n have h2 : Real.exp (- Lsum ω) ≤ 1 := by\n rw [Real.exp_le_one_iff]; linarith [hL0 ω]\n have h3 : (0:ℝ) < Real.exp (- Lsum ω) := Real.exp_pos _\n calc F ω = Real.exp (Phi A α n ω) * Real.exp (- Lsum ω) := rfl\n _ ≤ Real.exp UB * Real.exp (- Lsum ω) :=\n mul_le_mul_of_nonneg_right h1 (le_of_lt h3)\n _ ≤ Real.exp UB * 1 := by\n exact mul_le_mul_of_nonneg_left h2 (le_of_lt (Real.exp_pos _))\n _ = Real.exp UB := by ring\n have hFint : Integrable F μ := by\n refine (integrable_const (Real.exp UB)).mono' hFmeas.aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hF0 ω)]\n exact hFb ω\n -- p is measurable for G n\n have hpn : ∀ i, Measurable[G n] (fun ω => A.p n ω i) :=\n fun i => p_meas_filt hA G hGmono hGa hGl n hn1 (by omega) i\n have hppos : ∀ ω i, 0 < A.p n ω i := fun ω i => hA.p_pos_bset hn ω i\n have hg0 : ∀ (i : Fin K) (ω : Ω), (0:ℝ) ≤ (if A.a n ω = i then (1:ℝ) else 0) := by\n intro i ω; split <;> norm_num\n have hgb : ∀ (i : Fin K) (ω : Ω), (if A.a n ω = i then (1:ℝ) else 0) ≤ 1 := by\n intro i ω; split <;> norm_num\n have hFl0 : ∀ (i : Fin K) (ω : Ω), 0 ≤ F ω * A.l n ω i :=\n fun i ω => mul_nonneg (hF0 ω) (hA.hl0 _ _ _)\n have hFlint : ∀ i : Fin K, Integrable (fun ω => F ω * A.l n ω i) μ := by\n intro i\n refine (integrable_const (Real.exp UB)).mono'\n (hFmeas.mul ((hGl n i).mono (hGle n) le_rfl)).aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hFl0 i ω)]\n nlinarith [hFb ω, hF0 ω, hA.hl0 n ω i, hA.hl1 n ω i, Real.exp_pos UB]\n -- unbiasedness for each arm\n have hunb : ∀ i : Fin K,\n Integrable (fun ω => F ω * lhat A n ω i) μ ∧\n ∫ ω, F ω * lhat A n ω i ∂μ = ∫ ω, F ω * A.l n ω i ∂μ := by\n intro i\n have hfg : (fun ω => (F ω * A.l n ω i / A.p n ω i)\n * (if A.a n ω = i then (1:ℝ) else 0)) = fun ω => F ω * lhat A n ω i := by\n funext ω\n simp only [lhat]\n field_simp\n have hfh : (fun ω => (F ω * A.l n ω i / A.p n ω i) * A.p n ω i)\n = fun ω => F ω * A.l n ω i := by\n funext ω\n rw [div_mul_cancel₀ _ (ne_of_gt (hppos ω i))]\n have hres := @cond_pull Ω (G n) mΩ (hGle n) μ _\n (fun ω => F ω * A.l n ω i / A.p n ω i)\n (fun ω => if A.a n ω = i then (1:ℝ) else 0)\n (fun ω => A.p n ω i)\n ((hFmeasG.mul (hGl n i)).div (hpn i))\n (fun ω => div_nonneg (hFl0 i ω) (le_of_lt (hppos ω i)))\n (by\n have hs : MeasurableSet[mΩ] {ω | A.a n ω = i} := ha n (measurableSet_singleton i)\n exact @Measurable.ite Ω ℝ _ _ mΩ _ _ _ hs measurable_const measurable_const)\n (hg0 i) (hgb i)\n (hpn i) (fun ω => le_of_lt (hppos ω i)) (hcond n hn i)\n (by rw [hfh]; exact hFlint i)\n rw [hfg, hfh] at hres\n exact hres\n -- pathwise bound\n have hpath : ∀ ω, Real.exp (Phi A α (n+1) ω)\n ≤ F ω + ∑ i, α n i * (F ω * lhat A n ω i) := by\n intro ω\n have hsum : ∑ i, α n i * (ltil A n ω i - A.l n ω i)\n = (∑ i, α n i * ltil A n ω i) - Lsum ω := by\n simp only [hLsum]\n rw [← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n have he : Real.exp (Phi A α (n+1) ω)\n = F ω * Real.exp (∑ i, α n i * ltil A n ω i) := by\n rw [hPhirec ω, hsum, hFdef]\n simp only\n rw [mul_assoc, ← Real.exp_add, ← Real.exp_add]\n congr 1\n ring\n have hb := exp_sum_alpha_ltil_le hA hn ω (α n) (fun i => hα0 n i)\n (fun i => hαγ n i) (hγpos n)\n have h1 : F ω * Real.exp (∑ i, α n i * ltil A n ω i)\n ≤ F ω * (1 + ∑ i, α n i * lhat A n ω i) := mul_le_mul_of_nonneg_left hb (hF0 ω)\n have h2 : F ω * (1 + ∑ i, α n i * lhat A n ω i)\n = F ω + ∑ i, α n i * (F ω * lhat A n ω i) := by\n rw [mul_add, mul_one, Finset.mul_sum]\n congr 1\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [he]\n linarith\n -- integrate\n have hsumint : Integrable (fun ω => ∑ i, α n i * (F ω * lhat A n ω i)) μ :=\n integrable_finset_sum _ (fun i _ => ((hunb i).1).const_mul _)\n have hRHSint : Integrable (fun ω => F ω + ∑ i, α n i * (F ω * lhat A n ω i)) μ :=\n hFint.add hsumint\n have hmain := integral_mono (hexpint (n+1)) hRHSint hpath\n have hval : ∫ ω, (F ω + ∑ i, α n i * (F ω * lhat A n ω i)) ∂μ\n = (∫ ω, F ω ∂μ) + ∑ i, α n i * ∫ ω, F ω * A.l n ω i ∂μ := by\n rw [integral_add hFint hsumint]\n congr 1\n rw [integral_finset_sum _ (fun i _ => ((hunb i).1).const_mul _)]\n exact Finset.sum_congr rfl (fun i _ => by rw [integral_const_mul, (hunb i).2])\n have e1 : (fun ω => F ω * (1 + Lsum ω))\n = fun ω => F ω + ∑ i, α n i * (F ω * A.l n ω i) := by\n funext ω\n simp only [hLsum]\n rw [mul_add, mul_one, Finset.mul_sum]\n congr 1\n exact Finset.sum_congr rfl (fun i _ => by ring)\n have hsumint2 : Integrable (fun ω => ∑ i, α n i * (F ω * A.l n ω i)) μ :=\n integrable_finset_sum _ (fun i _ => ((hFlint i)).const_mul _)\n have hFLint : Integrable (fun ω => F ω * (1 + Lsum ω)) μ := by\n rw [e1]; exact hFint.add hsumint2\n have hval2 : (∫ ω, F ω ∂μ) + ∑ i, α n i * ∫ ω, F ω * A.l n ω i ∂μ\n = ∫ ω, (F ω * (1 + Lsum ω)) ∂μ := by\n rw [e1, integral_add hFint hsumint2]\n congr 1\n rw [integral_finset_sum _ (fun i _ => ((hFlint i)).const_mul _)]\n exact Finset.sum_congr rfl (fun i _ => by rw [integral_const_mul])\n have hfinpt : ∀ ω, F ω * (1 + Lsum ω) ≤ Real.exp (Phi A α n ω) := by\n intro ω\n have h1 : 1 + Lsum ω ≤ Real.exp (Lsum ω) := by\n linarith [Real.add_one_le_exp (Lsum ω)]\n have h2 : F ω * (1 + Lsum ω) ≤ F ω * Real.exp (Lsum ω) :=\n mul_le_mul_of_nonneg_left h1 (hF0 ω)\n have h3 : F ω * Real.exp (Lsum ω) = Real.exp (Phi A α n ω) := by\n simp only [hFdef]\n rw [mul_assoc, ← Real.exp_add]\n simp\n linarith\n have hfin := integral_mono hFLint (hexpint n) hfinpt\n linarith\n · -- vacuous step\n have hfe : (bset A).filter (fun q => q < n+1) = (bset A).filter (fun q => q < n) := by\n apply Finset.filter_congr\n intro x hx\n constructor\n · intro h\n rcases Nat.lt_succ_iff_lt_or_eq.1 h with h' | h'\n · exact h'\n · exact absurd (h' ▸ hx) hn\n · intro h; omega\n have : ∀ ω, Phi A α (n+1) ω = Phi A α n ω := by\n intro ω; unfold Phi; rw [hfe]\n simp only [this]\n exact ih\n\nend AdaptiveMGF\nsection AdaptiveExpect\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\n\n/-- Bundled hypotheses: `G` is the filtration generated by the past actions, the losses are\npredictable for it, and the action at round `q` has conditional law `p q` given `G q`. -/\nstructure ActFilt (A : AlgData Ω K) (μ : Measure Ω) (G : ℕ → MeasurableSpace Ω) : Prop where\n le : ∀ t, G t ≤ mΩ\n mono' : Monotone G\n act : ∀ u t : ℕ, 1 ≤ u → u < t → MeasurableSpace.comap (A.a u) inferInstance ≤ G t\n loss : ∀ q i, Measurable[G q] (fun ω => A.l q ω i)\n meas_a : ∀ q, Measurable (A.a q)\n cond : ∀ q i,\n (μ[(fun ω => if A.a q ω = i then (1:ℝ) else 0) | G q]) =ᵐ[μ] (fun ω => A.p q ω i)\n\nvariable {μ : Measure Ω} {G : ℕ → MeasurableSpace Ω}\n\nlemma ltil_meas_top (hA : AlgOK A) (hF : ActFilt A μ G) {q : ℕ} (hq : q ∈ bset A) (i : Fin K) :\n Measurable (fun ω => ltil A q ω i) :=\n (ltil_meas_filt hA G hF.mono' hF.act hF.loss hq (Nat.lt_succ_self q) i).mono\n (hF.le (q+1)) le_rfl\n\nlemma l_meas_top (hF : ActFilt A μ G) (q : ℕ) (i : Fin K) :\n Measurable (fun ω => A.l q ω i) := (hF.loss q i).mono (hF.le q) le_rfl\n\nlemma l_int (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ] (q : ℕ) (i : Fin K) :\n Integrable (fun ω => A.l q ω i) μ := by\n refine (integrable_const (1:ℝ)).mono' (l_meas_top hF q i).aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hA.hl0 _ _ _)]\n exact hA.hl1 _ _ _\n\nlemma l_int_le (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ] (q : ℕ) (i : Fin K) :\n ∫ ω, A.l q ω i ∂μ ≤ 1 := by\n have h := integral_mono (l_int hA hF q i) (integrable_const (1:ℝ))\n (fun ω => hA.hl1 q ω i)\n simpa using h\n\n/-- The estimator is unbiased-from-above: its integral is at most that of the true loss. -/\nlemma int_ltil_le (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ]\n (hγpos : ∀ q, 0 < A.γ q) {q : ℕ} (hq : q ∈ bset A) (i : Fin K) :\n Integrable (fun ω => ltil A q ω i) μ ∧ ∫ ω, ltil A q ω i ∂μ ≤ ∫ ω, A.l q ω i ∂μ := by\n have hppos : ∀ ω, 0 < A.p q ω i := fun ω => hA.p_pos_bset hq ω i\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n have hpq : Measurable[G q] (fun ω => A.p q ω i) :=\n p_meas_filt hA G hF.mono' hF.act hF.loss q hq1 (by omega) i\n have hg0 : ∀ ω, (0:ℝ) ≤ (if A.a q ω = i then (1:ℝ) else 0) := by intro ω; split <;> norm_num\n have hgb : ∀ ω, (if A.a q ω = i then (1:ℝ) else 0) ≤ 1 := by intro ω; split <;> norm_num\n have hfg : (fun ω => (A.l q ω i / A.p q ω i) * (if A.a q ω = i then (1:ℝ) else 0))\n = fun ω => lhat A q ω i := by\n funext ω; simp only [lhat]; field_simp\n have hfh : (fun ω => (A.l q ω i / A.p q ω i) * A.p q ω i) = fun ω => A.l q ω i := by\n funext ω; rw [div_mul_cancel₀ _ (ne_of_gt (hppos ω))]\n have hres := @cond_pull Ω (G q) mΩ (hF.le q) μ _\n (fun ω => A.l q ω i / A.p q ω i)\n (fun ω => if A.a q ω = i then (1:ℝ) else 0)\n (fun ω => A.p q ω i)\n ((hF.loss q i).div hpq)\n (fun ω => div_nonneg (hA.hl0 _ _ _) (le_of_lt (hppos ω)))\n (by\n have hs : MeasurableSet[mΩ] {ω | A.a q ω = i} := hF.meas_a q (measurableSet_singleton i)\n exact @Measurable.ite Ω ℝ _ _ mΩ _ _ _ hs measurable_const measurable_const)\n hg0 hgb hpq (fun ω => le_of_lt (hppos ω)) (hF.cond q i)\n (by rw [hfh]; exact l_int hA hF q i)\n rw [hfg, hfh] at hres\n have hltilint : Integrable (fun ω => ltil A q ω i) μ := by\n refine (integrable_const (1 / A.γ q)).mono'\n (ltil_meas_top hA hF hq i).aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hA.ltil_nonneg hq ω i)]\n exact ltil_le_inv_gamma hA hq (hγpos q) ω i\n refine ⟨hltilint, ?_⟩\n have hle : ∀ ω, ltil A q ω i ≤ lhat A q ω i := by\n intro ω\n unfold ltil lhat\n apply div_le_div_of_nonneg_left _ (hppos ω) _\n · exact mul_nonneg (hA.hl0 _ _ _) (hg0 ω)\n · linarith [hA.hγ q]\n calc ∫ ω, ltil A q ω i ∂μ ≤ ∫ ω, lhat A q ω i ∂μ :=\n integral_mono hltilint hres.1 hle\n _ = ∫ ω, A.l q ω i ∂μ := hres.2\n\nlemma int_sum_ltil_le (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ]\n (hγpos : ∀ q, 0 < A.γ q) {q : ℕ} (hq : q ∈ bset A) :\n Integrable (fun ω => ∑ i, ltil A q ω i) μ ∧\n ∫ ω, (∑ i, ltil A q ω i) ∂μ ≤ (K : ℝ) := by\n refine ⟨integrable_finset_sum _ (fun i _ => (int_ltil_le hA hF hγpos hq i).1), ?_⟩\n rw [integral_finset_sum _ (fun i _ => (int_ltil_le hA hF hγpos hq i).1)]\n calc ∑ i, ∫ ω, ltil A q ω i ∂μ ≤ ∑ _i : Fin K, (1:ℝ) := by\n refine Finset.sum_le_sum (fun i _ => ?_)\n exact le_trans (int_ltil_le hA hF hγpos hq i).2 (l_int_le hA hF q i)\n _ = (K:ℝ) := by simp\n\n/-- The total-variation of one softmax update is at most `2 e² η`. -/\nlemma dpos_le_eta (hA : AlgOK A) {r : ℕ} (hr : r ∈ bset A) (ω : Ω) (i : Fin K) :\n dpos A r ω i ≤ 2 * Real.exp 2 * A.η r := by\n have h1 : ∑ j, dpos A r ω j ≤ 2 * A.η r * ∑ j, PP A (kkey A.T A.d r) ω j * ltil A r ω j :=\n hA.dpos_sum_le ω hr\n have h2 : ∑ j, PP A (kkey A.T A.d r) ω j * ltil A r ω j ≤ Real.exp 2 :=\n hA.sum_PP_ltil_le ω _ hr (fun j => hA.key_ratio ω r hr j)\n have h3 : dpos A r ω i ≤ ∑ j, dpos A r ω j :=\n Finset.single_le_sum (fun j _ => AlgOK.dpos_nonneg A r ω j) (Finset.mem_univ i)\n have h4 : (0:ℝ) ≤ 2 * A.η r := by linarith [hA.hηpos r]\n nlinarith\n\nend AdaptiveExpect\nsection AdaptiveMaster\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\nvariable {μ : Measure Ω} {G : ℕ → MeasurableSpace Ω}\n\n/-- The centred estimator sum for a fixed arm. -/\nnoncomputable def Xj (A : AlgData Ω K) (j : Fin K) (ω : Ω) : ℝ :=\n ∑ q ∈ bset A, A.η q * (ltil A q ω j - A.l q ω j)\n\n/-- Log-sum-exp majorant of `max_j Xj`. -/\nnoncomputable def Vfun (A : AlgData Ω K) (ω : Ω) : ℝ :=\n Real.log (∑ j, Real.exp (Xj A j ω))\n\nlemma Phi_eq_Xj (A : AlgData Ω K) (j : Fin K) (ω : Ω) :\n Phi A (fun q i => if i = j then A.η q else 0) (A.T+1) ω = Xj A j ω := by\n unfold Phi Xj\n have hfe : (bset A).filter (fun q => q < A.T + 1) = bset A := by\n apply Finset.filter_true_of_mem\n intro x hx\n have := bset_le_T hx\n omega\n rw [hfe]\n refine Finset.sum_congr rfl (fun q _ => ?_)\n rw [Finset.sum_eq_single j]\n · simp\n · intro b _ hb; simp [hb]\n · intro h; exact absurd (Finset.mem_univ _) h\n\nlemma Phi_ge (hA : AlgOK A) (α : ℕ → Fin K → ℝ)\n (hα0 : ∀ q i, 0 ≤ α q i) (hα1 : ∀ q i, α q i ≤ 1) (n : ℕ) (ω : Ω) :\n -(((bset A).card : ℝ) * (K : ℝ)) ≤ Phi A α n ω := by\n unfold Phi\n have hterm : ∀ q ∈ (bset A).filter (fun q => q < n),\n -(K:ℝ) ≤ ∑ i, α q i * (ltil A q ω i - A.l q ω i) := by\n intro q hq\n rw [Finset.mem_filter] at hq\n have hstep : ∀ i : Fin K, (-1:ℝ) ≤ α q i * (ltil A q ω i - A.l q ω i) := by\n intro i\n have h1 : 0 ≤ ltil A q ω i := hA.ltil_nonneg hq.1 ω i\n have h2 : A.l q ω i ≤ 1 := hA.hl1 _ _ _\n nlinarith [hα0 q i, hα1 q i]\n calc (-(K:ℝ)) = ∑ _i : Fin K, (-1:ℝ) := by simp\n _ ≤ ∑ i, α q i * (ltil A q ω i - A.l q ω i) := Finset.sum_le_sum (fun i _ => hstep i)\n calc -(((bset A).card : ℝ) * (K:ℝ))\n ≤ -((((bset A).filter (fun q => q < n)).card : ℝ) * (K:ℝ)) := by\n have h1 : (((bset A).filter (fun q => q < n)).card : ℝ) ≤ ((bset A).card : ℝ) := by\n exact_mod_cast Finset.card_filter_le _ _\n have hK0 : (0:ℝ) ≤ (K:ℝ) := Nat.cast_nonneg _\n nlinarith\n _ = ∑ _q ∈ (bset A).filter (fun q => q < n), (-(K:ℝ)) := by\n rw [Finset.sum_const, nsmul_eq_mul]; ring\n _ ≤ ∑ q ∈ (bset A).filter (fun q => q < n), ∑ i, α q i * (ltil A q ω i - A.l q ω i) :=\n Finset.sum_le_sum hterm\n\nlemma p_meas_top (hA : AlgOK A) (hF : ActFilt A μ G) {q : ℕ} (hq : q ∈ bset A) (i : Fin K) :\n Measurable (fun ω => A.p q ω i) := by\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n exact (p_meas_filt hA G hF.mono' hF.act hF.loss q hq1 (by omega) i).mono (hF.le q) le_rfl\n\nlemma dpos_meas_top (hA : AlgOK A) (hF : ActFilt A μ G) (r : ℕ) (i : Fin K) :\n Measurable (fun ω => dpos A r ω i) :=\n AlgOK.dpos_meas A mΩ r (fun q _ _ => hF.meas_a q)\n (fun q hq _ i' => p_meas_top hA hF hq i') (fun q i' => l_meas_top hF q i') i\n\nlemma l_at_a_meas (hF : ActFilt A μ G) (t : ℕ) : Measurable (fun ω => A.l t ω (A.a t ω)) := by\n have he : (fun ω => A.l t ω (A.a t ω))\n = fun ω => ∑ i, (if A.a t ω = i then A.l t ω i else 0) := by\n funext ω\n rw [Finset.sum_eq_single (A.a t ω)]\n · rw [if_pos rfl]\n · intro b _ hb; rw [if_neg (Ne.symm hb)]\n · intro h; exact absurd (Finset.mem_univ _) h\n rw [he]\n refine Finset.measurable_sum _ (fun i _ => ?_)\n exact Measurable.ite (hF.meas_a t (measurableSet_singleton i)) (l_meas_top hF t i)\n measurable_const\n\nend AdaptiveMaster\nsection AdaptiveMaster2\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\nvariable {μ : Measure Ω} {G : ℕ → MeasurableSpace Ω}\n\nlemma Xj_meas (hA : AlgOK A) (hF : ActFilt A μ G) (j : Fin K) : Measurable (Xj A j) := by\n unfold Xj\n refine Finset.measurable_sum _ (fun q hq => ?_)\n exact ((ltil_meas_top hA hF hq j).sub (l_meas_top hF q j)).const_mul _\n\nlemma eta_le_one (hA : AlgOK A) (q : ℕ) : A.η q ≤ 1 := by\n have h1 : Real.exp (-2) ≤ 1 := by rw [Real.exp_le_one_iff]; norm_num\n have := hA.hηb q\n linarith\n\nlemma Xj_le (hA : AlgOK A) (hγη : ∀ t, A.γ t = A.η t) (j : Fin K) (ω : Ω) :\n Xj A j ω ≤ ((bset A).card : ℝ) * (K:ℝ) := by\n rw [← Phi_eq_Xj A j ω]\n exact Phi_le hA (fun q => by rw [hγη q]; exact hA.hηpos q) _\n (fun q i => by by_cases h : i = j <;> simp [h, (hA.hηpos q).le])\n (fun q i => by rw [hγη q]; by_cases h : i = j <;> simp [h, (hA.hηpos q).le])\n _ _\n\nlemma Xj_ge (hA : AlgOK A) (j : Fin K) (ω : Ω) :\n -(((bset A).card : ℝ) * (K:ℝ)) ≤ Xj A j ω := by\n rw [← Phi_eq_Xj A j ω]\n exact Phi_ge hA _\n (fun q i => by by_cases h : i = j <;> simp [h, (hA.hηpos q).le])\n (fun q i => by by_cases h : i = j <;> simp [h, eta_le_one hA q]) _ _\n\n/-- The log-sum-exp majorant has integral at most `log K`. -/\nlemma int_Vfun_le (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ]\n (hγη : ∀ t, A.γ t = A.η t) :\n Integrable (Vfun A) μ ∧ ∫ ω, Vfun A ω ∂μ ≤ Real.log (K:ℝ) := by\n classical\n haveI : Nonempty (Fin K) := ⟨⟨0, hA.hK⟩⟩\n set UB : ℝ := ((bset A).card : ℝ) * (K:ℝ) with hUB\n have hK0 : (0:ℝ) < (K:ℝ) := by exact_mod_cast hA.hK\n -- mgf bound for each arm\n have hmgf : ∀ j : Fin K, ∫ ω, Real.exp (Xj A j ω) ∂μ ≤ 1 := by\n intro j\n have h := mgf_le_one hA μ G hF.le hF.mono' hF.act hF.loss hF.meas_a\n (fun q _ i => hF.cond q i) (fun q => by rw [hγη q]; exact hA.hηpos q)\n (fun q i => if i = j then A.η q else 0)\n (fun q i => by by_cases h : i = j <;> simp [h, (hA.hηpos q).le])\n (fun q i => by rw [hγη q]; by_cases h : i = j <;> simp [h, (hA.hηpos q).le])\n (A.T+1)\n simp only [Phi_eq_Xj] at h\n exact h\n -- boundedness / integrability of the exponentials\n have hexpint : ∀ j : Fin K, Integrable (fun ω => Real.exp (Xj A j ω)) μ := by\n intro j\n refine (integrable_const (Real.exp UB)).mono' (Xj_meas hA hF j).exp.aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (le_of_lt (Real.exp_pos _))]\n exact Real.exp_le_exp.2 (Xj_le hA hγη j ω)\n set S : Ω → ℝ := fun ω => ∑ j, Real.exp (Xj A j ω) with hS\n have hSint : Integrable S μ := integrable_finset_sum _ (fun j _ => hexpint j)\n have hSpos : ∀ ω, 0 < S ω := by\n intro ω\n refine Finset.sum_pos (fun j _ => Real.exp_pos _) ?_\n exact Finset.univ_nonempty\n have hSlow : ∀ ω, (K:ℝ) * Real.exp (-UB) ≤ S ω := by\n intro ω\n have : ∀ j : Fin K, Real.exp (-UB) ≤ Real.exp (Xj A j ω) :=\n fun j => Real.exp_le_exp.2 (by have := Xj_ge hA j ω; linarith)\n calc (K:ℝ) * Real.exp (-UB) = ∑ _j : Fin K, Real.exp (-UB) := by\n rw [Finset.sum_const, nsmul_eq_mul]; simp\n _ ≤ S ω := Finset.sum_le_sum (fun j _ => this j)\n have hShigh : ∀ ω, S ω ≤ (K:ℝ) * Real.exp UB := by\n intro ω\n calc S ω ≤ ∑ _j : Fin K, Real.exp UB :=\n Finset.sum_le_sum (fun j _ => Real.exp_le_exp.2 (Xj_le hA hγη j ω))\n _ = (K:ℝ) * Real.exp UB := by rw [Finset.sum_const, nsmul_eq_mul]; simp\n have hSmeas : Measurable S :=\n Finset.measurable_sum _ (fun j _ => (Xj_meas hA hF j).exp)\n -- V is measurable and bounded\n have hVmeas : Measurable (Vfun A) := Real.measurable_log.comp hSmeas\n have hVlow : ∀ ω, Real.log ((K:ℝ) * Real.exp (-UB)) ≤ Vfun A ω := by\n intro ω\n exact Real.log_le_log (by positivity) (hSlow ω)\n have hVhigh : ∀ ω, Vfun A ω ≤ Real.log ((K:ℝ) * Real.exp UB) := by\n intro ω\n exact Real.log_le_log (hSpos ω) (hShigh ω)\n have hVint : Integrable (Vfun A) μ := by\n set C : ℝ := |Real.log ((K:ℝ) * Real.exp (-UB))| + |Real.log ((K:ℝ) * Real.exp UB)| with hC\n refine (integrable_const C).mono' hVmeas.aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_le]\n constructor\n · have := hVlow ω\n have h2 := abs_nonneg (Real.log ((K:ℝ) * Real.exp UB))\n have h3 := neg_abs_le (Real.log ((K:ℝ) * Real.exp (-UB)))\n rw [hC]; linarith\n · have := hVhigh ω\n have h2 := abs_nonneg (Real.log ((K:ℝ) * Real.exp (-UB)))\n have h3 := le_abs_self (Real.log ((K:ℝ) * Real.exp UB))\n rw [hC]; linarith\n refine ⟨hVint, ?_⟩\n -- the shift trick\n have hkey : ∀ ω, Vfun A ω - Real.log (K:ℝ) ≤ S ω / (K:ℝ) - 1 := by\n intro ω\n have hVS : Vfun A ω = Real.log (S ω) := rfl\n have he : Real.exp (Vfun A ω - Real.log (K:ℝ)) = S ω / (K:ℝ) := by\n rw [hVS, Real.exp_sub, Real.exp_log (hSpos ω), Real.exp_log hK0]\n have := Real.add_one_le_exp (Vfun A ω - Real.log (K:ℝ))\n rw [he] at this\n linarith\n have h1 : Integrable (fun ω => Vfun A ω - Real.log (K:ℝ)) μ := hVint.sub (integrable_const _)\n have h2 : Integrable (fun ω => S ω / (K:ℝ) - 1) μ :=\n (hSint.div_const _).sub (integrable_const _)\n have h3 := integral_mono h1 h2 hkey\n have e1 : ∫ ω, (Vfun A ω - Real.log (K:ℝ)) ∂μ = (∫ ω, Vfun A ω ∂μ) - Real.log (K:ℝ) := by\n rw [integral_sub hVint (integrable_const _)]\n simp\n have e2 : ∫ ω, (S ω / (K:ℝ) - 1) ∂μ = (∫ ω, S ω ∂μ)/(K:ℝ) - 1 := by\n rw [integral_sub (hSint.div_const _) (integrable_const _), integral_div]\n simp\n rw [e1, e2] at h3\n have h4 : ∫ ω, S ω ∂μ ≤ (K:ℝ) := by\n rw [hS, integral_finset_sum _ (fun j _ => hexpint j)]\n calc ∑ j, ∫ ω, Real.exp (Xj A j ω) ∂μ ≤ ∑ _j : Fin K, (1:ℝ) :=\n Finset.sum_le_sum (fun j _ => hmgf j)\n _ = (K:ℝ) := by simp\n have h5 : (∫ ω, S ω ∂μ) / (K:ℝ) ≤ 1 := by\n rw [div_le_one hK0]; exact h4\n linarith\n\nend AdaptiveMaster2\nsection AdaptiveMaster3\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\nvariable {μ : Measure Ω} {G : ℕ → MeasurableSpace Ω}\n\nprivate lemma pull_action_indicator (hA : AlgOK A) (hF : ActFilt A μ G)\n [IsProbabilityMeasure μ] {t : ℕ} (ht : t ∈ bset A) (i : Fin K)\n (f : Ω → ℝ) (hf : Measurable[G t] f) (hf0 : ∀ ω, 0 ≤ f ω)\n (hfp : Integrable (fun ω => f ω * A.p t ω i) μ) :\n Integrable (fun ω => f ω * (if A.a t ω = i then (1 : ℝ) else 0)) μ ∧\n ∫ ω, f ω * (if A.a t ω = i then (1 : ℝ) else 0) ∂μ\n = ∫ ω, f ω * A.p t ω i ∂μ := by\n have ht1 : 1 ≤ t := (mem_bset.1 ht).1.1\n have htT : t ≤ A.T := bset_le_T ht\n have hp : Measurable[G t] (fun ω => A.p t ω i) :=\n p_meas_filt hA G hF.mono' hF.act hF.loss t ht1 (by omega) i\n exact @cond_pull Ω (G t) mΩ (hF.le t) μ _ f\n (fun ω => if A.a t ω = i then (1 : ℝ) else 0)\n (fun ω => A.p t ω i) hf hf0\n (Measurable.ite (hF.meas_a t (measurableSet_singleton i)) measurable_const measurable_const)\n (fun ω => by by_cases h : A.a t ω = i <;> simp [h])\n (fun ω => by by_cases h : A.a t ω = i <;> simp [h])\n hp (fun ω => le_of_lt (hA.p_pos_bset ht ω i)) (hF.cond t i) hfp\n\nlemma sum_ltil_meas (hA : AlgOK A) (hF : ActFilt A μ G) {q : ℕ} (hq : q ∈ bset A) :\n Measurable (fun ω => ∑ i, ltil A q ω i) :=\n Finset.measurable_sum _ (fun i _ => ltil_meas_top hA hF hq i)\n\n/-- Expected value of the delay-drift inner product for one pair `(q,r)`. -/\nlemma int_dpos_ltil_le (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ]\n (hγpos : ∀ q, 0 < A.γ q) {q r : ℕ} (hq : q ∈ bset A) (hr : r ∈ bset A) :\n Integrable (fun ω => ∑ i, dpos A r ω i * ltil A q ω i) μ ∧\n ∫ ω, (∑ i, dpos A r ω i * ltil A q ω i) ∂μ ≤ 2 * Real.exp 2 * A.η r * (K:ℝ) := by\n have hsum := int_sum_ltil_le hA hF hγpos hq\n have hmeas : Measurable (fun ω => ∑ i, dpos A r ω i * ltil A q ω i) :=\n Finset.measurable_sum _ (fun i _ =>\n (dpos_meas_top hA hF r i).mul (ltil_meas_top hA hF hq i))\n have hnn : ∀ ω, 0 ≤ ∑ i, dpos A r ω i * ltil A q ω i := fun ω =>\n Finset.sum_nonneg (fun i _ =>\n mul_nonneg (AlgOK.dpos_nonneg A r ω i) (hA.ltil_nonneg hq ω i))\n have hle : ∀ ω, ∑ i, dpos A r ω i * ltil A q ω i\n ≤ (2 * Real.exp 2 * A.η r) * ∑ i, ltil A q ω i := by\n intro ω\n rw [Finset.mul_sum]\n refine Finset.sum_le_sum (fun i _ => ?_)\n exact mul_le_mul_of_nonneg_right (dpos_le_eta hA hr ω i) (hA.ltil_nonneg hq ω i)\n have hc0 : (0:ℝ) ≤ 2 * Real.exp 2 * A.η r := by\n have := hA.hηpos r; have := Real.exp_pos 2; positivity\n have hint : Integrable (fun ω => ∑ i, dpos A r ω i * ltil A q ω i) μ := by\n refine (hsum.1.const_mul (2 * Real.exp 2 * A.η r)).mono' hmeas.aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hnn ω)]\n exact hle ω\n refine ⟨hint, ?_⟩\n calc ∫ ω, (∑ i, dpos A r ω i * ltil A q ω i) ∂μ\n ≤ ∫ ω, ((2 * Real.exp 2 * A.η r) * ∑ i, ltil A q ω i) ∂μ :=\n integral_mono hint (hsum.1.const_mul _) hle\n _ = (2 * Real.exp 2 * A.η r) * ∫ ω, (∑ i, ltil A q ω i) ∂μ := integral_const_mul _ _\n _ ≤ (2 * Real.exp 2 * A.η r) * (K:ℝ) := mul_le_mul_of_nonneg_left hsum.2 hc0\n\nprivate lemma int_dpos_ltil_of_r_lt_q (hA : AlgOK A) (hF : ActFilt A μ G)\n [IsProbabilityMeasure μ] (hγpos : ∀ q, 0 < A.γ q)\n {q r : ℕ} (hq : q ∈ bset A) (hr : r ∈ bset A) (hrq : r < q) :\n ∫ ω, (∑ i, dpos A r ω i * ltil A q ω i) ∂μ ≤ Real.exp 2 * A.η r := by\n classical\n set c : ℝ := Real.exp 2 * A.η r with hc\n have hc0 : 0 ≤ c := by\n simp only [c]\n exact mul_nonneg (Real.exp_pos 2).le (hA.hηpos r).le\n have hr1 : 1 ≤ r := (mem_bset.1 hr).1.1\n have haq : Measurable[G q] (A.a r) :=\n Measurable.of_comap_le (hF.act r q hr1 hrq)\n have hpq : ∀ i, Measurable[G q] (fun ω => A.p q ω i) := by\n intro i\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n exact p_meas_filt hA G hF.mono' hF.act hF.loss q hq1 (by omega) i\n let f : Fin K → Ω → ℝ := fun i ω =>\n c * (if A.a r ω = i then (1 : ℝ) else 0) * A.l q ω i /\n (A.p q ω i + A.γ q)\n have hfmeas : ∀ i, Measurable[G q] (f i) := by\n intro i\n have hI : Measurable[G q] (fun ω => if A.a r ω = i then (1 : ℝ) else 0) :=\n Measurable.ite (haq (measurableSet_singleton i)) measurable_const measurable_const\n exact ((measurable_const.mul hI).mul (hF.loss q i)).div ((hpq i).add measurable_const)\n have hf0 : ∀ i ω, 0 ≤ f i ω := by\n intro i ω\n unfold f\n exact div_nonneg (mul_nonneg (mul_nonneg hc0 (by positivity)) (hA.hl0 q ω i))\n (le_of_lt (hA.pg_pos hq ω i))\n have hfp_le : ∀ i ω, f i ω * A.p q ω i\n ≤ c * (if A.a r ω = i then (1 : ℝ) else 0) := by\n intro i ω\n by_cases hi : A.a r ω = i\n · rw [if_pos hi]\n have hrat : A.l q ω i * A.p q ω i / (A.p q ω i + A.γ q) ≤ 1 := by\n rw [div_le_one (hA.pg_pos hq ω i)]\n nlinarith [hA.hl1 q ω i, hA.p_pos_bset hq ω i, hA.hγ q]\n unfold f\n rw [if_pos hi]\n calc\n (c * 1 * A.l q ω i / (A.p q ω i + A.γ q)) * A.p q ω i\n = c * (A.l q ω i * A.p q ω i / (A.p q ω i + A.γ q)) := by ring\n _ ≤ c * 1 := mul_le_mul_of_nonneg_left hrat hc0\n · unfold f\n rw [if_neg hi]\n norm_num\n have hfp0 : ∀ i ω, 0 ≤ f i ω * A.p q ω i := fun i ω =>\n mul_nonneg (hf0 i ω) (le_of_lt (hA.p_pos_bset hq ω i))\n have hfpint : ∀ i, Integrable (fun ω => f i ω * A.p q ω i) μ := by\n intro i\n refine (integrable_const c).mono'\n (((hfmeas i).mul (hpq i)).mono (hF.le q) le_rfl).aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hfp0 i ω)]\n have hI : (if A.a r ω = i then (1 : ℝ) else 0) ≤ 1 := by\n by_cases h : A.a r ω = i <;> simp [h]\n exact (hfp_le i ω).trans (by\n simpa using mul_le_mul_of_nonneg_left hI hc0)\n have hpull : ∀ i,\n Integrable (fun ω => f i ω * (if A.a q ω = i then (1 : ℝ) else 0)) μ ∧\n ∫ ω, f i ω * (if A.a q ω = i then (1 : ℝ) else 0) ∂μ\n = ∫ ω, f i ω * A.p q ω i ∂μ := by\n intro i\n exact pull_action_indicator hA hF hq i (f i) (hfmeas i) (hf0 i) (hfpint i)\n have hpoint : ∀ ω,\n (∑ i, dpos A r ω i * ltil A q ω i)\n ≤ ∑ i, f i ω * (if A.a q ω = i then (1 : ℝ) else 0) := by\n intro ω\n refine Finset.sum_le_sum (fun i _ => ?_)\n calc\n dpos A r ω i * ltil A q ω i\n ≤ (c * (if A.a r ω = i then (1 : ℝ) else 0)) * ltil A q ω i :=\n mul_le_mul_of_nonneg_right\n (by simpa [c] using AlgOK.dpos_le_indicator hA hr ω i)\n (hA.ltil_nonneg hq ω i)\n _ = f i ω * (if A.a q ω = i then (1 : ℝ) else 0) := by\n unfold f ltil\n ring\n have hleft := (int_dpos_ltil_le hA hF hγpos hq hr).1\n have huint : Integrable\n (fun ω => ∑ i, f i ω * (if A.a q ω = i then (1 : ℝ) else 0)) μ :=\n integrable_finset_sum _ (fun i _ => (hpull i).1)\n have hmain := integral_mono hleft huint hpoint\n have hur :\n ∫ ω, (∑ i, f i ω * (if A.a q ω = i then (1 : ℝ) else 0)) ∂μ\n = ∫ ω, (∑ i, f i ω * A.p q ω i) ∂μ := by\n rw [integral_finset_sum _ (fun i _ => (hpull i).1),\n integral_finset_sum _ (fun i _ => hfpint i)]\n exact Finset.sum_congr rfl (fun i _ => (hpull i).2)\n have hrhsint : Integrable (fun ω => ∑ i, f i ω * A.p q ω i) μ :=\n integrable_finset_sum _ (fun i _ => hfpint i)\n have hrhsle : ∀ ω, (∑ i, f i ω * A.p q ω i) ≤ c := by\n intro ω\n calc\n (∑ i, f i ω * A.p q ω i)\n ≤ ∑ i, c * (if A.a r ω = i then (1 : ℝ) else 0) :=\n Finset.sum_le_sum (fun i _ => hfp_le i ω)\n _ = c := by\n rw [Finset.sum_eq_single (A.a r ω)]\n · simp\n · intro i _ hi\n rw [if_neg (Ne.symm hi)]\n ring\n · intro h\n exact absurd (Finset.mem_univ _) h\n have hrhs := integral_mono hrhsint (integrable_const c) hrhsle\n rw [hur] at hmain\n simpa [c] using hmain.trans (by simpa using hrhs)\n\nprivate lemma int_dpos_ltil_of_q_lt_r (hA : AlgOK A) (hF : ActFilt A μ G)\n [IsProbabilityMeasure μ] (hγpos : ∀ q, 0 < A.γ q)\n {q r : ℕ} (hq : q ∈ bset A) (hqr : r ∈ Rset A q) (hqrlt : q < r) :\n ∫ ω, (∑ i, dpos A r ω i * ltil A q ω i) ∂μ ≤ Real.exp 2 * A.η r := by\n classical\n have hr : r ∈ bset A := (AlgOK.mem_Rset.1 hqr).1\n have hkey0 : q * (A.T + 1) ≤ kkey A.T A.d r := (AlgOK.mem_Rset.1 hqr).2.1\n have hkey1 : kkey A.T A.d r ≤ kkey A.T A.d q :=\n le_of_lt (AlgOK.mem_Rset.1 hqr).2.2\n set C : ℝ := Fprod A (q * (A.T + 1)) (kkey A.T A.d r) with hC\n set c : ℝ := C * A.η r with hc\n have hC0 : 0 ≤ C := by simp only [C]; exact hA.Fprod_nonneg _ _\n have hc0 : 0 ≤ c := mul_nonneg hC0 (le_of_lt (hA.hηpos r))\n have hCle : C ≤ Real.exp 2 := by\n simp only [C]\n exact AlgOK.Fprod_partial_bound hA hq hkey0 hkey1\n have hpq : ∀ i, Measurable[G r] (fun ω => A.p q ω i) := by\n intro i\n have hq1 : 1 ≤ q := (mem_bset.1 hq).1.1\n have hqT : q ≤ A.T := bset_le_T hq\n exact (p_meas_filt hA G hF.mono' hF.act hF.loss q hq1 (by omega) i).mono\n (hF.mono' (le_of_lt hqrlt)) le_rfl\n have hpr : ∀ i, Measurable[G r] (fun ω => A.p r ω i) := by\n intro i\n have hr1 : 1 ≤ r := (mem_bset.1 hr).1.1\n have hrT : r ≤ A.T := bset_le_T hr\n exact p_meas_filt hA G hF.mono' hF.act hF.loss r hr1 (by omega) i\n have hlq : ∀ i, Measurable[G r] (fun ω => ltil A q ω i) := fun i =>\n ltil_meas_filt hA G hF.mono' hF.act hF.loss hq hqrlt i\n let f : Fin K → Ω → ℝ := fun i ω =>\n c * A.p q ω i * ltil A q ω i * A.l r ω i /\n (A.p r ω i + A.γ r)\n have hfmeas : ∀ i, Measurable[G r] (f i) := by\n intro i\n exact ((((measurable_const.mul (hpq i)).mul (hlq i)).mul (hF.loss r i)).div\n ((hpr i).add measurable_const))\n have hf0 : ∀ i ω, 0 ≤ f i ω := by\n intro i ω\n unfold f\n exact div_nonneg\n (mul_nonneg (mul_nonneg (mul_nonneg hc0 (le_of_lt (hA.p_pos_bset hq ω i)))\n (hA.ltil_nonneg hq ω i)) (hA.hl0 r ω i))\n (le_of_lt (hA.pg_pos hr ω i))\n have hsumq : ∀ ω, ∑ i, A.p q ω i * ltil A q ω i ≤ 1 := by\n intro ω\n have he := hA.sum_p_ltil hq ω\n have hnon : 0 ≤ A.γ q * ∑ i, ltil A q ω i :=\n mul_nonneg (hA.hγ q) (Finset.sum_nonneg (fun i _ => hA.ltil_nonneg hq ω i))\n linarith [hA.hl1 q ω (A.a q ω)]\n have hfp_base : ∀ i ω,\n f i ω * A.p r ω i ≤ c * (A.p q ω i * ltil A q ω i) := by\n intro i ω\n have hrat : A.l r ω i * A.p r ω i / (A.p r ω i + A.γ r) ≤ 1 := by\n rw [div_le_one (hA.pg_pos hr ω i)]\n nlinarith [hA.hl1 r ω i, hA.p_pos_bset hr ω i, hA.hγ r]\n have hcoef : 0 ≤ c * (A.p q ω i * ltil A q ω i) :=\n mul_nonneg hc0 (mul_nonneg (hA.p_pos_bset hq ω i).le\n (hA.ltil_nonneg hq ω i))\n unfold f\n calc\n (c * A.p q ω i * ltil A q ω i * A.l r ω i /\n (A.p r ω i + A.γ r)) * A.p r ω i\n = (c * (A.p q ω i * ltil A q ω i)) *\n (A.l r ω i * A.p r ω i / (A.p r ω i + A.γ r)) := by ring\n _ ≤ (c * (A.p q ω i * ltil A q ω i)) * 1 :=\n mul_le_mul_of_nonneg_left hrat hcoef\n _ = c * (A.p q ω i * ltil A q ω i) := by ring\n have hfp0 : ∀ i ω, 0 ≤ f i ω * A.p r ω i := fun i ω =>\n mul_nonneg (hf0 i ω) (le_of_lt (hA.p_pos_bset hr ω i))\n have hfp_le_c : ∀ i ω, f i ω * A.p r ω i ≤ c := by\n intro i ω\n have hone : A.p q ω i * ltil A q ω i ≤ 1 := by\n refine le_trans (Finset.single_le_sum\n (fun j _ => mul_nonneg (le_of_lt (hA.p_pos_bset hq ω j))\n (hA.ltil_nonneg hq ω j)) (Finset.mem_univ i)) (hsumq ω)\n exact (hfp_base i ω).trans (by simpa using mul_le_mul_of_nonneg_left hone hc0)\n have hfpint : ∀ i, Integrable (fun ω => f i ω * A.p r ω i) μ := by\n intro i\n refine (integrable_const c).mono'\n (((hfmeas i).mul (hpr i)).mono (hF.le r) le_rfl).aestronglyMeasurable\n (Filter.Eventually.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (hfp0 i ω)]\n exact hfp_le_c i ω\n have hpull : ∀ i,\n Integrable (fun ω => f i ω * (if A.a r ω = i then (1 : ℝ) else 0)) μ ∧\n ∫ ω, f i ω * (if A.a r ω = i then (1 : ℝ) else 0) ∂μ\n = ∫ ω, f i ω * A.p r ω i ∂μ := by\n intro i\n exact pull_action_indicator hA hF hr i (f i) (hfmeas i) (hf0 i) (hfpint i)\n have hpoint : ∀ ω,\n (∑ i, dpos A r ω i * ltil A q ω i)\n ≤ ∑ i, f i ω * (if A.a r ω = i then (1 : ℝ) else 0) := by\n intro ω\n refine Finset.sum_le_sum (fun i _ => ?_)\n have hinc : 0 ≤ A.η r * ltil A r ω i :=\n mul_nonneg (le_of_lt (hA.hηpos r)) (hA.ltil_nonneg hr ω i)\n have hpbound := AlgOK.PP_partial_le hA ω hq hkey0 hkey1 i\n calc\n dpos A r ω i * ltil A q ω i\n ≤ (PP A (kkey A.T A.d r) ω i * (A.η r * ltil A r ω i)) *\n ltil A q ω i := mul_le_mul_of_nonneg_right\n (AlgOK.dpos_le_update hA hr ω i) (hA.ltil_nonneg hq ω i)\n _ ≤ ((C * A.p q ω i) * (A.η r * ltil A r ω i)) * ltil A q ω i := by\n exact mul_le_mul_of_nonneg_right\n (mul_le_mul_of_nonneg_right (by simpa [C] using hpbound) hinc)\n (hA.ltil_nonneg hq ω i)\n _ = f i ω * (if A.a r ω = i then (1 : ℝ) else 0) := by\n unfold f ltil\n simp only [c, C]\n ring\n have hleft := (int_dpos_ltil_le hA hF hγpos hq hr).1\n have huint : Integrable\n (fun ω => ∑ i, f i ω * (if A.a r ω = i then (1 : ℝ) else 0)) μ :=\n integrable_finset_sum _ (fun i _ => (hpull i).1)\n have hmain := integral_mono hleft huint hpoint\n have hur :\n ∫ ω, (∑ i, f i ω * (if A.a r ω = i then (1 : ℝ) else 0)) ∂μ\n = ∫ ω, (∑ i, f i ω * A.p r ω i) ∂μ := by\n rw [integral_finset_sum _ (fun i _ => (hpull i).1),\n integral_finset_sum _ (fun i _ => hfpint i)]\n exact Finset.sum_congr rfl (fun i _ => (hpull i).2)\n have hrhsint : Integrable (fun ω => ∑ i, f i ω * A.p r ω i) μ :=\n integrable_finset_sum _ (fun i _ => hfpint i)\n have hrhsle : ∀ ω, (∑ i, f i ω * A.p r ω i) ≤ c := by\n intro ω\n calc\n (∑ i, f i ω * A.p r ω i)\n ≤ ∑ i, c * (A.p q ω i * ltil A q ω i) :=\n Finset.sum_le_sum (fun i _ => hfp_base i ω)\n _ = c * ∑ i, A.p q ω i * ltil A q ω i := by rw [Finset.mul_sum]\n _ ≤ c * 1 := mul_le_mul_of_nonneg_left (hsumq ω) hc0\n _ = c := by ring\n have hrhs := integral_mono hrhsint (integrable_const c) hrhsle\n rw [hur] at hmain\n have hc_le : c ≤ Real.exp 2 * A.η r := by\n simp only [c]\n exact mul_le_mul_of_nonneg_right hCle (le_of_lt (hA.hηpos r))\n have hrhs' : ∫ ω, (∑ i, f i ω * A.p r ω i) ∂μ ≤ c := by\n simpa using hrhs\n exact hmain.trans (hrhs'.trans hc_le)\n\nprivate lemma int_dpos_ltil_le_sharp (hA : AlgOK A) (hF : ActFilt A μ G)\n [IsProbabilityMeasure μ] (hγpos : ∀ q, 0 < A.γ q)\n {q r : ℕ} (hq : q ∈ bset A) (hqr : r ∈ Rset A q) :\n Integrable (fun ω => ∑ i, dpos A r ω i * ltil A q ω i) μ ∧\n ∫ ω, (∑ i, dpos A r ω i * ltil A q ω i) ∂μ\n ≤ Real.exp 2 * A.η r := by\n have hr : r ∈ bset A := (AlgOK.mem_Rset.1 hqr).1\n refine ⟨(int_dpos_ltil_le hA hF hγpos hq hr).1, ?_⟩\n have hne : q ≠ r := by\n intro h\n subst r\n exact (Nat.lt_irrefl (kkey A.T A.d q)) (AlgOK.mem_Rset.1 hqr).2.2\n by_cases hlt : q < r\n · exact int_dpos_ltil_of_q_lt_r hA hF hγpos hq hqr hlt\n · have hrq : r < q := by omega\n exact int_dpos_ltil_of_r_lt_q hA hF hγpos hq hr hrq\n\nend AdaptiveMaster3\nsection AdaptiveMaster4\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {K : ℕ} {A : AlgData Ω K}\nvariable {μ : Measure Ω} {G : ℕ → MeasurableSpace Ω}\n\nnoncomputable def S2fun (A : AlgData Ω K) (ω : Ω) : ℝ :=\n ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i\n\nnoncomputable def S3fun (A : AlgData Ω K) (ω : Ω) : ℝ :=\n ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i\n\nlemma S2_int_le (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ]\n (hγpos : ∀ q, 0 < A.γ q) :\n Integrable (S2fun A) μ ∧ ∫ ω, S2fun A ω ∂μ\n ≤ ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (K:ℝ) := by\n have hc0 : ∀ q, (0:ℝ) ≤ A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2 := by\n intro q\n have h1 := hA.hγ q\n have h2 := (hA.hηpos q).le\n have h3 : (0:ℝ) ≤ Real.exp 2 / 2 := by positivity\n nlinarith [sq_nonneg (A.η q)]\n have hint : Integrable (S2fun A) μ :=\n integrable_finset_sum _ (fun q hq => ((int_sum_ltil_le hA hF hγpos hq).1).const_mul _)\n refine ⟨hint, ?_⟩\n simp only [S2fun]\n rw [integral_finset_sum _ (fun q hq => ((int_sum_ltil_le hA hF hγpos hq).1).const_mul _)]\n refine Finset.sum_le_sum (fun q hq => ?_)\n rw [integral_const_mul]\n exact mul_le_mul_of_nonneg_left (int_sum_ltil_le hA hF hγpos hq).2 (hc0 q)\n\nlemma S3_int_le (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ]\n (hγpos : ∀ q, 0 < A.γ q) :\n Integrable (S3fun A) μ ∧ ∫ ω, S3fun A ω ∂μ\n ≤ ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * (2 * Real.exp 2 * A.η r * (K:ℝ)) := by\n have hint : Integrable (S3fun A) μ :=\n integrable_finset_sum _ (fun q hq => integrable_finset_sum _ (fun r hr =>\n ((int_dpos_ltil_le hA hF hγpos hq (AlgOK.mem_Rset.1 hr).1).1).const_mul _))\n refine ⟨hint, ?_⟩\n simp only [S3fun]\n rw [integral_finset_sum _ (fun q hq => integrable_finset_sum _ (fun r hr =>\n ((int_dpos_ltil_le hA hF hγpos hq (AlgOK.mem_Rset.1 hr).1).1).const_mul _))]\n refine Finset.sum_le_sum (fun q hq => ?_)\n rw [integral_finset_sum _ (fun r hr =>\n ((int_dpos_ltil_le hA hF hγpos hq (AlgOK.mem_Rset.1 hr).1).1).const_mul _)]\n refine Finset.sum_le_sum (fun r hr => ?_)\n rw [integral_const_mul]\n exact mul_le_mul_of_nonneg_left\n (int_dpos_ltil_le hA hF hγpos hq (AlgOK.mem_Rset.1 hr).1).2 (hA.hηpos q).le\n\nprivate lemma S3_int_le_sharp (hA : AlgOK A) (hF : ActFilt A μ G)\n [IsProbabilityMeasure μ] (hγpos : ∀ q, 0 < A.γ q) :\n Integrable (S3fun A) μ ∧ ∫ ω, S3fun A ω ∂μ\n ≤ Real.exp 2 * (∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ)) := by\n have hint : Integrable (S3fun A) μ :=\n integrable_finset_sum _ (fun q hq => integrable_finset_sum _ (fun r hr =>\n ((int_dpos_ltil_le_sharp hA hF hγpos hq hr).1).const_mul _))\n refine ⟨hint, ?_⟩\n have hraw : ∫ ω, S3fun A ω ∂μ\n ≤ ∑ q ∈ bset A, ∑ r ∈ Rset A q,\n A.η q * (Real.exp 2 * A.η r) := by\n simp only [S3fun]\n rw [integral_finset_sum _ (fun q hq => integrable_finset_sum _ (fun r hr =>\n ((int_dpos_ltil_le_sharp hA hF hγpos hq hr).1).const_mul _))]\n refine Finset.sum_le_sum (fun q hq => ?_)\n rw [integral_finset_sum _ (fun r hr =>\n ((int_dpos_ltil_le_sharp hA hF hγpos hq hr).1).const_mul _)]\n refine Finset.sum_le_sum (fun r hr => ?_)\n rw [integral_const_mul]\n exact mul_le_mul_of_nonneg_left\n (int_dpos_ltil_le_sharp hA hF hγpos hq hr).2 (hA.hηpos q).le\n calc\n ∫ ω, S3fun A ω ∂μ\n ≤ ∑ q ∈ bset A, ∑ r ∈ Rset A q,\n A.η q * (Real.exp 2 * A.η r) := hraw\n _ = Real.exp 2 *\n (∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * A.η r) := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl (fun q _ => ?_)\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun r _ => by ring)\n _ ≤ Real.exp 2 * (∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ)) :=\n mul_le_mul_of_nonneg_left (eta_pair_bound_one hA) (Real.exp_pos 2).le\n\n/-- The adaptive-adversary master bound. -/\nlemma master_bound_adaptive (hA : AlgOK A) (hF : ActFilt A μ G) [IsProbabilityMeasure μ]\n (hγη : ∀ t, A.γ t = A.η t) (hne : (Finset.univ : Finset (Fin K)).Nonempty) :\n ∫ ω, ((∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω (A.a t ω))\n - (Finset.univ : Finset (Fin K)).inf' hne\n (fun i => ∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω i)) ∂μ\n ≤ 2 * Real.log (K:ℝ)\n + (1 + Real.exp 2/2) * (K:ℝ) * (∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2)\n + Real.exp 2 * (∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ))\n + (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) := by\n classical\n haveI : Nonempty (Fin K) := ⟨⟨0, hA.hK⟩⟩\n have hγpos : ∀ q, 0 < A.γ q := fun q => by rw [hγη q]; exact hA.hηpos q\n have hK1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hA.hK\n have hK0 : (0:ℝ) ≤ (K:ℝ) := by linarith\n have hlogK : 0 ≤ Real.log (K:ℝ) := Real.log_nonneg hK1\n have hbsub : bset A ⊆ Finset.Icc 1 A.T := Finset.filter_subset _ _\n have hCnn : 0 ≤ ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t :=\n Finset.sum_nonneg (fun t _ => (hA.hηpos t).le)\n have hsq : 0 ≤ ∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2 :=\n Finset.sum_nonneg (fun t _ => sq_nonneg _)\n have hdd : 0 ≤ ∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ) :=\n Finset.sum_nonneg (fun q _ => by positivity)\n have he2 : (0:ℝ) < Real.exp 2 := Real.exp_pos 2\n by_cases hYint : Integrable (fun ω => (∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω (A.a t ω))\n - (Finset.univ : Finset (Fin K)).inf' hne\n (fun i => ∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω i)) μ\n · -- the substantive case\n obtain ⟨hVint, hVle⟩ := int_Vfun_le hA hF hγη\n obtain ⟨hS2int, hS2le⟩ := S2_int_le hA hF hγpos\n obtain ⟨hS3int, hS3le⟩ := S3_int_le_sharp hA hF hγpos\n have hVS2int : Integrable (fun ω => Vfun A ω + S2fun A ω) μ := hVint.add hS2int\n have hZint : Integrable (fun ω => Vfun A ω + S2fun A ω + S3fun A ω) μ :=\n hVS2int.add hS3int\n have hRint : Integrable (fun ω => (Real.log (K:ℝ)\n + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t) + (Vfun A ω + S2fun A ω + S3fun A ω)) μ :=\n (integrable_const _).add hZint\n have hpath : ∀ ω, ((∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω (A.a t ω))\n - (Finset.univ : Finset (Fin K)).inf' hne\n (fun i => ∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω i))\n ≤ (Real.log (K:ℝ) + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t)\n + (Vfun A ω + S2fun A ω + S3fun A ω) := by\n intro ω\n obtain ⟨j0, -, hj0⟩ := Finset.exists_mem_eq_inf' hne\n (fun i => ∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω i)\n have hcore := hA.core_final ω j0\n have e2 : S2fun A ω\n = ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * ∑ i, ltil A q ω i := rfl\n have e3 : S3fun A ω\n = ∑ q ∈ bset A, ∑ r ∈ Rset A q, A.η q * ∑ i, dpos A r ω i * ltil A q ω i := rfl\n rw [← e2, ← e3] at hcore\n have hs1 : ∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω (A.a t ω)\n = (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t * A.l t ω (A.a t ω))\n + ∑ q ∈ bset A, A.η q * A.l q ω (A.a q ω) := (Finset.sum_sdiff hbsub).symm\n have hs2 : ∑ t ∈ Finset.Icc 1 A.T, A.η t * A.l t ω j0\n = (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t * A.l t ω j0)\n + ∑ q ∈ bset A, A.η q * A.l q ω j0 := (Finset.sum_sdiff hbsub).symm\n have hb1 : (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t * A.l t ω (A.a t ω))\n - (∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t * A.l t ω j0)\n ≤ ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t := by\n rw [← Finset.sum_sub_distrib]\n refine Finset.sum_le_sum (fun t _ => ?_)\n nlinarith [(hA.hηpos t).le, hA.hl1 t ω (A.a t ω), hA.hl0 t ω j0]\n have hXeq : (∑ q ∈ bset A, A.η q * ltil A q ω j0)\n - (∑ q ∈ bset A, A.η q * A.l q ω j0) = Xj A j0 ω := by\n rw [Xj, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun q _ => by ring)\n have hVge : Xj A j0 ω ≤ Vfun A ω := by\n have h1 : Real.exp (Xj A j0 ω) ≤ ∑ j, Real.exp (Xj A j ω) :=\n Finset.single_le_sum (f := fun j => Real.exp (Xj A j ω))\n (fun j _ => (Real.exp_pos _).le) (Finset.mem_univ j0)\n have h2 : (0:ℝ) < Real.exp (Xj A j0 ω) := Real.exp_pos _\n calc Xj A j0 ω = Real.log (Real.exp (Xj A j0 ω)) := (Real.log_exp _).symm\n _ ≤ Real.log (∑ j, Real.exp (Xj A j ω)) := Real.log_le_log h2 h1\n rw [hj0, hs1, hs2]\n linarith\n have hmain := integral_mono hYint hRint hpath\n have hval1 : ∫ ω, (Vfun A ω + S2fun A ω + S3fun A ω) ∂μ\n = (∫ ω, Vfun A ω ∂μ) + (∫ ω, S2fun A ω ∂μ) + (∫ ω, S3fun A ω ∂μ) := by\n rw [integral_add hVS2int hS3int, integral_add hVint hS2int]\n have hval : ∫ ω, ((Real.log (K:ℝ) + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t)\n + (Vfun A ω + S2fun A ω + S3fun A ω)) ∂μ\n = (Real.log (K:ℝ) + ∑ t ∈ (Finset.Icc 1 A.T) \\ bset A, A.η t)\n + ((∫ ω, Vfun A ω ∂μ) + (∫ ω, S2fun A ω ∂μ) + (∫ ω, S3fun A ω ∂μ)) := by\n rw [integral_add (integrable_const _) hZint, hval1]\n simp\n rw [hval] at hmain\n -- arithmetic for the S2 term\n have hS2arith : ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (K:ℝ)\n ≤ (1 + Real.exp 2/2) * (K:ℝ) * (∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2) := by\n have hstep : ∀ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (K:ℝ)\n = (1 + Real.exp 2/2) * (K:ℝ) * (A.η q)^2 := by\n intro q _\n rw [hγη q]; ring\n calc ∑ q ∈ bset A, (A.γ q * A.η q + (Real.exp 2/2) * (A.η q)^2) * (K:ℝ)\n = ∑ q ∈ bset A, (1 + Real.exp 2/2) * (K:ℝ) * (A.η q)^2 :=\n Finset.sum_congr rfl hstep\n _ ≤ ∑ t ∈ Finset.Icc 1 A.T, (1 + Real.exp 2/2) * (K:ℝ) * (A.η t)^2 :=\n Finset.sum_le_sum_of_subset_of_nonneg hbsub (fun t _ _ => by positivity)\n _ = (1 + Real.exp 2/2) * (K:ℝ) * (∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2) := by\n rw [Finset.mul_sum]\n linarith\n · rw [integral_undef hYint]\n have h1 : (0:ℝ) ≤ (1 + Real.exp 2/2) * (K:ℝ) * (∑ t ∈ Finset.Icc 1 A.T, (A.η t)^2) := by\n have : (0:ℝ) ≤ 1 + Real.exp 2/2 := by linarith\n positivity\n have h2 : (0:ℝ) ≤ Real.exp 2 * (∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ)) := by\n positivity\n linarith\n\nend AdaptiveMaster4\nsection Shift\n\nvariable {Ω : Type*} [mΩ : MeasurableSpace Ω] {μ : Measure Ω} {K : ℕ} {hK : 0 < K}\n {l : ℕ → Ω → Fin K → ℝ} {d : ℕ → ℕ} {η γ : ℕ → ℝ}\n\n/-- Reindex a real sequence so that index `0` copies index `1`. -/\nnoncomputable def shR (η : ℕ → ℝ) : ℕ → ℝ := fun t => η (max t 1)\n/-- Reindex a natural sequence so that index `0` copies index `1`. -/\ndef shN (d : ℕ → ℕ) : ℕ → ℕ := fun t => d (max t 1)\n/-- Reindex a loss sequence so that index `0` copies index `1`. -/\nnoncomputable def shL {Ω : Type*} {K : ℕ} (l : ℕ → Ω → Fin K → ℝ) : ℕ → Ω → Fin K → ℝ :=\n fun t => l (max t 1)\n\nlemma shR_eq (η : ℕ → ℝ) {t : ℕ} (ht : 1 ≤ t) : shR η t = η t := by\n simp [shR, max_eq_left ht]\nlemma shN_eq (d : ℕ → ℕ) {t : ℕ} (ht : 1 ≤ t) : shN d t = d t := by\n simp [shN, max_eq_left ht]\nlemma shL_eq {Ω : Type*} {K : ℕ} (l : ℕ → Ω → Fin K → ℝ) {t : ℕ} (ht : 1 ≤ t) :\n shL l t = l t := by\n simp [shL, max_eq_left ht]\n\n/-- The same run of the algorithm, recorded with reindexed parameter sequences. -/\nnoncomputable def shiftExp3 (E : Exp3Delayed μ K hK l d η γ) :\n Exp3Delayed μ K hK (shL l) (shN d) (shR η) (shR γ) where\n 𝓕 := E.𝓕\n 𝓕_le := E.𝓕_le\n 𝓕_mono := E.𝓕_mono\n a := E.a\n p := E.p\n Lhat := E.Lhat\n measurable_a := E.measurable_a\n 𝓕_eq := by\n intro t\n rw [E.𝓕_eq t]\n congr 1\n · refine iSup_congr (fun s => ?_)\n rcases Nat.eq_zero_or_pos s with rfl | hs\n · simp\n · rw [shN_eq d hs]\n · refine iSup_congr (fun s => ?_)\n rcases Nat.eq_zero_or_pos s with rfl | hs\n · simp\n · rw [shL_eq l hs]\n measurable_p := E.measurable_p\n p_isProb := E.p_isProb\n p_init := E.p_init\n a_law := E.a_law\n Lhat_init := E.Lhat_init\n Lhat_step := by\n intro t ω i ht\n rw [E.Lhat_step t ω i ht]\n congr 1\n refine Finset.sum_congr ?_ ?_\n · refine Finset.filter_congr (fun s hs => ?_)\n rw [Finset.mem_Icc] at hs\n rw [shN_eq d hs.1, shR_eq η hs.1]\n · intro s hs\n rw [Finset.mem_filter, Finset.mem_Icc] at hs\n rw [shR_eq η hs.1.1, shL_eq l hs.1.1, shR_eq γ hs.1.1]\n p_update := E.p_update\n\n@[simp] lemma shiftExp3_a (E : Exp3Delayed μ K hK l d η γ) : (shiftExp3 E).a = E.a := rfl\n\nend Shift\nsection AdaptiveConcrete\n\nlemma shR_pos (η : ℕ → ℝ) (h : ∀ t ≥ 1, 0 < η t) : ∀ t, 0 < shR η t :=\n fun t => h (max t 1) (le_max_right t 1)\n\nlemma shR_bd (η : ℕ → ℝ) (c : ℝ) (h : ∀ t ≥ 1, η t ≤ c) : ∀ t, shR η t ≤ c :=\n fun t => h (max t 1) (le_max_right t 1)\n\nlemma shR_dec (η : ℕ → ℝ) (h : ∀ t ≥ 1, η (t+1) ≤ η t) : ∀ t, shR η (t+1) ≤ shR η t := by\n intro t\n rcases Nat.eq_zero_or_pos t with rfl | ht\n · simp [shR]\n · rw [shR_eq η (by omega : 1 ≤ t+1), shR_eq η ht]\n exact h t ht\n\nlemma shN_ge (d : ℕ → ℕ) (h : ∀ t ≥ 1, 1 ≤ d t) : ∀ t, 1 ≤ t → 1 ≤ shN d t := by\n intro t ht; rw [shN_eq d ht]; exact h t ht\n\nlemma shL_mem {Ω : Type*} {K : ℕ} (l : ℕ → Ω → Fin K → ℝ)\n (h : ∀ t ≥ 1, ∀ ω i, l t ω i ∈ Set.Icc (0:ℝ) 1) :\n ∀ t ω i, shL l t ω i ∈ Set.Icc (0:ℝ) 1 :=\n fun t ω i => h (max t 1) (le_max_right t 1) ω i\n\n/-- The regret bound for the adaptive adversary, at a fixed horizon `T`. -/\nlemma adaptive_regret_bound {Ω : Type*} [mΩ : MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (K T : ℕ) (hK : 0 < K)\n (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (d : ℕ → ℕ) (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hη_pos : ∀ t ≥ 1, 0 < η t) (hη_dec : ∀ t ≥ 1, η (t + 1) ≤ η t)\n (hη_bound : ∀ t ≥ 1, η t ≤ (1 / 2) * Real.exp (-2))\n (hl : ∀ t ≥ 1, ∀ ω i, l t ω i ∈ Set.Icc (0 : ℝ) 1)\n (E : Exp3Delayed μ K hK l d η η)\n (hl_adapted : ∀ t i, @Measurable Ω ℝ\n (⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance) _\n (fun ω => l t ω i))\n (a_law_adaptive : ∀ t i,\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n ⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance]) =ᵐ[μ]\n (fun ω => E.p t ω i)) :\n weightedExpReg μ T K hK η l E.a ≤\n 2 * Real.log (K:ℝ)\n + (1 + Real.exp 2 / 2) * (K:ℝ) * (∑ t ∈ Finset.Icc 1 T, (η t) ^ 2)\n + Real.exp 2 * (∑ q ∈ Bset T d η, (η q) ^ 2 * (d q : ℝ))\n + (∑ t ∈ (Finset.Icc 1 T) \\ Bset T d η, η t) := by\n classical\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n set E' := shiftExp3 E with hE'\n set A : AlgData Ω K := toAlg T (shN d) (shR η) (shR η) (shL l) E' with hAdef\n have hA : AlgOK A := toAlg_ok T E' (shN_ge d hd) (shR_pos η hη_pos) (shR_dec η hη_dec)\n (shR_bd η _ hη_bound) (fun t ω i => (shL_mem l hl t ω i).1)\n (fun t ω i => (shL_mem l hl t ω i).2) (fun t => le_of_lt (shR_pos η hη_pos t))\n set G : ℕ → MeasurableSpace Ω :=\n fun t => ⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance with hGdef\n have hGmono : Monotone G := by\n intro s t hst\n refine iSup_le (fun τ => iSup_le (fun hτ => ?_))\n rw [Finset.mem_Ico] at hτ\n exact le_iSup_of_le τ (le_iSup_of_le (Finset.mem_Ico.2 ⟨hτ.1, by omega⟩) le_rfl)\n have hGle : ∀ t, G t ≤ mΩ := by\n intro t\n refine iSup_le (fun τ => iSup_le (fun _ => ?_))\n exact measurable_iff_comap_le.1 (E.measurable_a τ)\n have hG10 : G 1 ≤ G 0 := by\n refine iSup_le (fun τ => iSup_le (fun hτ => ?_))\n simp at hτ\n have hGmax : ∀ q, G (max q 1) ≤ G q := by\n intro q\n rcases Nat.eq_zero_or_pos q with rfl | hq\n · simpa using hG10\n · rw [max_eq_left hq]\n have hF : ActFilt A μ G := by\n refine ⟨hGle, hGmono, ?_, ?_, E.measurable_a, ?_⟩\n · intro u t hu hut\n exact le_iSup_of_le u (le_iSup_of_le (Finset.mem_Ico.2 ⟨hu, hut⟩) le_rfl)\n · intro q i\n exact (hl_adapted (max q 1) i).mono (hGmax q) le_rfl\n · intro q i\n exact a_law_adaptive q i\n have hmb := master_bound_adaptive hA hF (fun t => rfl) (Finset.univ_nonempty)\n -- identify the pieces\n have hbs : bset A = Bset T d η := by\n show Bset T (shN d) (shR η) = Bset T d η\n apply Finset.filter_congr\n intro q hq\n rw [Finset.mem_Icc] at hq\n rw [shN_eq d hq.1, shR_eq η hq.1]\n have hsq : ∑ t ∈ Finset.Icc 1 T, (A.η t)^2 = ∑ t ∈ Finset.Icc 1 T, (η t)^2 := by\n refine Finset.sum_congr rfl (fun t ht => ?_)\n rw [Finset.mem_Icc] at ht\n show (shR η t)^2 = (η t)^2\n rw [shR_eq η ht.1]\n have hdd : ∑ q ∈ bset A, (A.η q)^2 * (A.d q : ℝ)\n = ∑ q ∈ Bset T d η, (η q)^2 * (d q : ℝ) := by\n rw [hbs]\n refine Finset.sum_congr rfl (fun q hq => ?_)\n have hq1 : 1 ≤ q := (Finset.mem_Icc.1 (mem_Bset.1 hq).1).1\n show (shR η q)^2 * ((shN d q : ℕ) : ℝ) = _\n rw [shR_eq η hq1, shN_eq d hq1]\n have hsd : ∑ t ∈ (Finset.Icc 1 T) \\ bset A, A.η t\n = ∑ t ∈ (Finset.Icc 1 T) \\ Bset T d η, η t := by\n rw [hbs]\n refine Finset.sum_congr rfl (fun t ht => ?_)\n have ht1 : 1 ≤ t := (Finset.mem_Icc.1 (Finset.mem_sdiff.1 ht).1).1\n show shR η t = η t\n rw [shR_eq η ht1]\n have hwe : weightedExpReg μ T K hK η l E.a\n = ∫ ω, ((∑ t ∈ Finset.Icc 1 T, A.η t * A.l t ω (A.a t ω))\n - (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, A.η t * A.l t ω i)) ∂μ := by\n unfold weightedExpReg\n refine integral_congr_ae (Filter.Eventually.of_forall (fun ω => ?_))\n dsimp only\n have e1 : (∑ t ∈ Finset.Icc 1 T, A.η t * A.l t ω (A.a t ω))\n = ∑ t ∈ Finset.Icc 1 T, η t * l t ω (E.a t ω) := by\n refine Finset.sum_congr rfl (fun t ht => ?_)\n rw [Finset.mem_Icc] at ht\n show shR η t * shL l t ω (E.a t ω) = _\n rw [shR_eq η ht.1, shL_eq l ht.1]\n have e2 : (fun i => ∑ t ∈ Finset.Icc 1 T, A.η t * A.l t ω i)\n = (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l t ω i) := by\n funext i\n refine Finset.sum_congr rfl (fun t ht => ?_)\n rw [Finset.mem_Icc] at ht\n show shR η t * shL l t ω i = _\n rw [shR_eq η ht.1, shL_eq l ht.1]\n rw [e1, e2]\n have hAT : A.T = T := rfl\n rw [hAT] at hmb\n rw [hwe]\n rw [hsq, hdd, hsd] at hmb\n exact hmb\n\nend AdaptiveConcrete\n\nprivate lemma weightedExpReg_one_arm {Ω : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) (T : ℕ) (η : ℕ → ℝ) (l : ℕ → Ω → Fin 1 → ℝ)\n (a : ℕ → Ω → Fin 1) :\n weightedExpReg μ T 1 (by omega) η l a = 0 := by\n unfold weightedExpReg\n have ha (t : ℕ) (ω : Ω) : a t ω = (0 : Fin 1) := Subsingleton.elim _ _\n simp_rw [ha]\n simp\n\ntheorem lemma5_adaptive {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (K T : ℕ) (hK : 0 < K) (hT : 0 < T)\n (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (d : ℕ → ℕ) (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hη_pos : ∀ t, 0 < η t) (hη_dec : ∀ t, η (t + 1) ≤ η t)\n (hη_bound : ∀ t, η t ≤ (1 / 2) * Real.exp (-2))\n (hl : ∀ t ω i, l t ω i ∈ Set.Icc (0 : ℝ) 1)\n (E : Exp3Delayed μ K hK l d η η)\n (hl_adapted : ∀ t i, @Measurable Ω ℝ\n (⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance) _\n (fun ω => l t ω i))\n\n (a_law_adaptive : ∀ t i,\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n ⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance]) =ᵐ[μ]\n (fun ω => E.p t ω i)) :\n weightedExpReg μ T K hK η l E.a ≤\n 2 + 2 * Real.log K\n + (1 + Real.exp 2 / 2) * K * (∑ t ∈ Finset.Icc 1 T, (η t) ^ 2)\n + 4 * Real.exp 2 * K * (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t) ^ 2 * (d t : ℝ))\n + (∑ t ∈ MStar T d η, η t) := by\n have hb := adaptive_regret_bound μ K T hK η l d hd\n (fun t _ => hη_pos t) (fun t _ => hη_dec t) (fun t _ => hη_bound t)\n (fun t _ ω i => hl t ω i) E hl_adapted a_law_adaptive\n have hs := set_arith_adaptive T K d η hK hη_pos\n linarith\n\nset_option maxHeartbeats 1000000 in\ntheorem theorem6_regretBound :\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (K T : ℕ) (hK : 0 < K) (hT : 0 < T) (l0 : ℕ → Fin K → ℝ) (d : ℕ → ℕ)\n (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hl : ∀ t i, l0 t i ∈ Set.Icc (0 : ℝ) 1) (η : ℕ → ℝ)\n (hη_pos : ∀ t ≥ 1, 0 < η t)\n (hη : η = fun _ =>\n (Real.exp (-2) / 2) *\n Real.sqrt (Real.log K /\n ((K : ℝ) * T + ∑ t ∈ (Finset.Icc 1 T) \\ missedRounds T d, (d t : ℝ))))\n (E : Exp3Delayed μ K hK (fun t _ i => l0 t i) d η (fun _ => 0))\n (a_fresh : ∀ t t' i, t ≤ t' → t' < t + d t →\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n E.𝓕 t' ⊔ ⨆ s ∈ {s : ℕ | s + d s < t + d t ∨ (s + d s = t + d t ∧ s < t)},\n MeasurableSpace.comap (E.a s) inferInstance]) =ᵐ[μ] (fun ω => E.p t ω i)),\n expReg μ T K hK l0 E.a ≤\n C * (Real.sqrt (Real.log K *\n ((K : ℝ) * T + ∑ t ∈ (Finset.Icc 1 T) \\ missedRounds T d, (d t : ℝ)))\n + (missedRounds T d).card) := by\n classical\n refine ⟨2 * Real.exp 2 + 2, by positivity, ?_⟩\n intro Ω _ μ _ K T hK hT l0 d hd hl η hη_pos hη E a_fresh\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n set D : ℝ := ∑ t ∈ (Finset.Icc 1 T) \\ missedRounds T d, (d t : ℝ) with hDdef\n set L : ℝ := Real.log K with hLdef\n set W : ℝ := (K:ℝ) * (T:ℝ) + D with hWdef\n set s : ℝ := Real.sqrt (L / W) with hsdef\n set c : ℝ := (Real.exp (-2) / 2) * s with hcdef\n set R : ℝ := Real.sqrt (L * W) with hRdef\n clear_value R c s W L D\n have hee : Real.exp 2 * Real.exp (-2) = 1 := by rw [← Real.exp_add]; norm_num\n have hcpos : 0 < c := by\n have h := hη_pos 1 le_rfl\n rw [hη] at h\n exact h\n have he2n : (0:ℝ) < Real.exp (-2)/2 := by positivity\n have hcpos' : 0 < (Real.exp (-2)/2) * s := by rw [← hcdef]; exact hcpos\n have hs0 : 0 < s := by nlinarith [hcpos', he2n]\n have hD0 : 0 ≤ D := by\n rw [hDdef]; exact Finset.sum_nonneg (fun t _ => by positivity)\n have hK1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have hT1 : (1:ℝ) ≤ (T:ℝ) := by exact_mod_cast hT\n have hKT : (1:ℝ) ≤ (K:ℝ)*(T:ℝ) := by nlinarith\n have hW0 : 0 < W := by rw [hWdef]; linarith\n have hLWpos : 0 < L / W := Real.sqrt_pos.1 (by rw [← hsdef]; exact hs0)\n have hL0 : 0 < L := by\n have h := mul_pos hLWpos hW0\n rwa [div_mul_cancel₀ _ (ne_of_gt hW0)] at h\n have hLleW : L ≤ W := by\n have h1 : L ≤ (K:ℝ) - 1 := by\n rw [hLdef]; exact Real.log_le_sub_one_of_pos (by linarith)\n rw [hWdef]; nlinarith\n have hs1 : s ≤ 1 := by\n have h : L/W ≤ 1 := by rw [div_le_one hW0]; exact hLleW\n calc s = Real.sqrt (L/W) := hsdef\n _ ≤ Real.sqrt 1 := Real.sqrt_le_sqrt h\n _ = 1 := Real.sqrt_one\n have hs2 : s^2 = L/W := by rw [hsdef]; exact Real.sq_sqrt (le_of_lt hLWpos)\n have hsW : s * W = R := by\n have hsq : L * W = (s*W)^2 := by rw [mul_pow, hs2]; field_simp\n rw [hRdef, hsq, Real.sqrt_sq (mul_nonneg (le_of_lt hs0) (le_of_lt hW0))]\n have hR0 : 0 < R := by rw [← hsW]; exact mul_pos hs0 hW0\n have hLsR : L = s * R := by\n rw [← hsW, ← mul_assoc, ← pow_two, hs2]\n field_simp\n have hDW : D ≤ W := by rw [hWdef]; linarith\n -- apply the oblivious regret bound\n have hbnd : ∀ t : ℕ, c ≤ (1/2) * Real.exp (-2) := by\n intro t; rw [hcdef]; nlinarith [hs1, he2n, hs0]\n have hηc : ∀ t, η t = c := fun t => by rw [hη]\n have h5 := lemma5_oblivious μ K T hK hT η l0 d hd (fun t => by rw [hηc t]; exact hcpos)\n (fun t => by rw [hηc t, hηc (t+1)]) (fun t => by rw [hηc t]; exact hbnd t) hl E a_fresh\n obtain ⟨a, ha⟩ : ∃ a : ℕ → Ω → Fin K, E.a = a := ⟨E.a, rfl⟩\n rw [ha] at h5 ⊢\n rw [hη] at h5\n dsimp only at h5\n rw [weightedExpReg_const μ T K hK c (le_of_lt hcpos) l0 a] at h5\n -- simplify the three sums\n have hcardIcc : (Finset.Icc 1 T).card = T := by rw [Nat.card_Icc]; omega\n have hsum1 : (∑ _t ∈ Finset.Icc 1 T, c^2) = (T:ℝ) * c^2 := by\n rw [Finset.sum_const, hcardIcc, nsmul_eq_mul]\n have hsum2 : (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d (fun _ => c), c^2 * (d t : ℝ))\n = c^2 * ∑ t ∈ (Finset.Icc 1 T) \\ MStar T d (fun _ => c), (d t : ℝ) := by\n rw [Finset.mul_sum]\n have hsum3 : (∑ _t ∈ MStar T d (fun _ => c), c)\n = ((MStar T d (fun _ => c)).card : ℝ) * c := by\n rw [Finset.sum_const, nsmul_eq_mul]\n rw [hsum1, hsum2, hsum3, ← hLdef] at h5\n set D' : ℝ := ∑ t ∈ (Finset.Icc 1 T) \\ MStar T d (fun _ => c), (d t : ℝ) with hD'def\n -- D' ≤ D\n have hmissedsub : missedRounds T d ⊆ MStar T d (fun _ => c) := by\n intro t ht\n rw [missedRounds, Finset.mem_filter] at ht\n exact mem_MStar.2 ⟨ht.1, Or.inl ht.2⟩\n have hsdiffsub : (Finset.Icc 1 T) \\ MStar T d (fun _ => c)\n ⊆ (Finset.Icc 1 T) \\ missedRounds T d :=\n Finset.sdiff_subset_sdiff (Finset.Subset.refl _) hmissedsub\n have hD'le : D' ≤ D := by\n rw [hD'def, hDdef]\n exact Finset.sum_le_sum_of_subset_of_nonneg hsdiffsub (fun t _ _ => by positivity)\n -- cardinality of MStar\n have hNcard : ((MStar T d (fun _ => c)).card : ℝ)\n ≤ ((missedRounds T d).card : ℝ) + R := by\n set N := (Finset.Icc 1 T).filter (fun t => ¬ (T < t + d t)\n ∧ ((d t : ℝ) ≥ 1/(Real.exp 2 * c) - 1)) with hNdef\n have hsub : MStar T d (fun _ => c) ⊆ missedRounds T d ∪ N := by\n intro t ht\n rw [mem_MStar] at ht\n obtain ⟨hIcc, hor⟩ := ht\n by_cases hc2 : T < t + d t\n · exact Finset.mem_union_left _ (by rw [missedRounds, Finset.mem_filter]; exact ⟨hIcc, hc2⟩)\n · refine Finset.mem_union_right _ ?_\n rw [hNdef, Finset.mem_filter]\n refine ⟨hIcc, hc2, ?_⟩\n rcases hor with h | h\n · exact absurd h hc2\n · exact h\n have hcard : (MStar T d (fun _ => c)).card ≤ (missedRounds T d).card + N.card :=\n le_trans (Finset.card_le_card hsub) (Finset.card_union_le _ _)\n have hNsub : N ⊆ (Finset.Icc 1 T) \\ missedRounds T d := by\n intro t ht\n rw [hNdef, Finset.mem_filter] at ht\n rw [Finset.mem_sdiff]\n refine ⟨ht.1, ?_⟩\n rw [missedRounds, Finset.mem_filter]\n rintro ⟨-, h⟩\n exact ht.2.1 h\n have hdlow : ∀ t ∈ N, 1/s ≤ (d t : ℝ) := by\n intro t ht\n rw [hNdef, Finset.mem_filter] at ht\n have h := ht.2.2\n have he : Real.exp 2 * c = s/2 := by\n rw [hcdef]; linear_combination (s/2) * hee\n rw [he] at h\n have hh : (1:ℝ)/(s/2) = 2/s := by field_simp\n rw [hh] at h\n have hinv : (1:ℝ) ≤ 1/s := by rw [le_div_iff₀ hs0]; linarith\n have h2s : (2:ℝ)/s = 1/s + 1/s := by ring\n linarith\n have hNcard1 : (N.card : ℝ) * (1/s) ≤ ∑ t ∈ N, (d t : ℝ) := by\n have h := Finset.card_nsmul_le_sum N (fun t => (d t : ℝ)) (1/s) hdlow\n simpa [nsmul_eq_mul] using h\n have hNsum : (∑ t ∈ N, (d t : ℝ)) ≤ D := by\n rw [hDdef]\n exact Finset.sum_le_sum_of_subset_of_nonneg hNsub (fun t _ _ => by positivity)\n have hNle : (N.card : ℝ) ≤ D * s := by\n have h1 : (N.card:ℝ) * (1/s) ≤ D := le_trans hNcard1 hNsum\n have h2 := mul_le_mul_of_nonneg_right h1 (le_of_lt hs0)\n rw [mul_assoc, one_div, inv_mul_cancel₀ (ne_of_gt hs0), mul_one] at h2\n exact h2\n have hDsR : D * s ≤ R := by\n calc D * s ≤ W * s := mul_le_mul_of_nonneg_right hDW (le_of_lt hs0)\n _ = s * W := mul_comm _ _\n _ = R := hsW\n have hcast := (Nat.cast_le (α := ℝ)).2 hcard\n push_cast at hcast\n linarith\n -- termwise bounds\n have hi : L = c * (2 * Real.exp 2 * R) := by\n rw [hcdef, hLsR]\n linear_combination (-(s*R)) * hee\n have hii : (Real.exp 2/2) * (K:ℝ) * ((T:ℝ) * c^2) ≤ c * ((1/4) * R) := by\n have hKTW : (K:ℝ)*(T:ℝ) ≤ W := by rw [hWdef]; linarith\n have h1 : (K:ℝ)*(T:ℝ)*s ≤ R := by\n calc (K:ℝ)*(T:ℝ)*s ≤ W*s := mul_le_mul_of_nonneg_right hKTW (le_of_lt hs0)\n _ = s*W := mul_comm _ _\n _ = R := hsW\n have heq : (Real.exp 2/2) * (K:ℝ) * ((T:ℝ) * c^2)\n = c * ((1/4) * ((K:ℝ)*(T:ℝ)*s)) := by\n rw [hcdef]\n linear_combination ((K:ℝ)*(T:ℝ)*s^2/8*Real.exp (-2)) * hee\n rw [heq]\n exact mul_le_mul_of_nonneg_left (by linarith) (le_of_lt hcpos)\n have hiii : 4 * (c^2 * D') ≤ c * (2 * Real.exp (-2) * R) := by\n have hsD' : s * D' ≤ R := by\n have h1 : D' ≤ W := le_trans hD'le hDW\n calc s*D' ≤ s*W := mul_le_mul_of_nonneg_left h1 (le_of_lt hs0)\n _ = R := hsW\n have heq : 4 * (c^2 * D') = c * (2 * Real.exp (-2) * (s * D')) := by\n rw [hcdef]; ring\n rw [heq]\n refine mul_le_mul_of_nonneg_left ?_ (le_of_lt hcpos)\n have hpos : (0:ℝ) ≤ 2 * Real.exp (-2) := by positivity\n exact mul_le_mul_of_nonneg_left hsD' hpos\n have hiv : ((MStar T d (fun _ => c)).card : ℝ) * c\n ≤ c * (((missedRounds T d).card : ℝ) + R) := by\n rw [mul_comm]\n exact mul_le_mul_of_nonneg_left hNcard (le_of_lt hcpos)\n -- final numeric combination\n have hXY : 2 * Real.exp 2 * R + (1/4) * R + 2 * Real.exp (-2) * R\n + (((missedRounds T d).card : ℝ) + R)\n ≤ (2 * Real.exp 2 + 2) * (R + ((missedRounds T d).card : ℝ)) := by\n have hen := exp_neg_two_le\n have hR0' : (0:ℝ) ≤ R := le_of_lt hR0\n have hcm : (0:ℝ) ≤ ((missedRounds T d).card : ℝ) := Nat.cast_nonneg _\n have he2p : (0:ℝ) < Real.exp 2 := Real.exp_pos 2\n have h1 : 2 * Real.exp (-2) * R ≤ (1/2) * R :=\n mul_le_mul_of_nonneg_right (by linarith) hR0'\n have h2 : (0:ℝ) ≤ 2 * Real.exp 2 * ((missedRounds T d).card : ℝ) :=\n mul_nonneg (by linarith) hcm\n linarith\n have hfinal : c * (2 * Real.exp 2 * R) + c * ((1/4) * R)\n + c * (2 * Real.exp (-2) * R) + c * (((missedRounds T d).card : ℝ) + R)\n ≤ c * ((2 * Real.exp 2 + 2) * (R + ((missedRounds T d).card : ℝ))) := by\n calc c * (2 * Real.exp 2 * R) + c * ((1/4) * R)\n + c * (2 * Real.exp (-2) * R) + c * (((missedRounds T d).card : ℝ) + R)\n = c * (2 * Real.exp 2 * R + (1/4) * R + 2 * Real.exp (-2) * R\n + (((missedRounds T d).card : ℝ) + R)) := by ring\n _ ≤ c * ((2 * Real.exp 2 + 2) * (R + ((missedRounds T d).card : ℝ))) :=\n mul_le_mul_of_nonneg_left hXY (le_of_lt hcpos)\n have hcomb : c * expReg μ T K hK l0 a\n ≤ c * ((2 * Real.exp 2 + 2) * (R + ((missedRounds T d).card : ℝ))) := by\n linarith\n exact le_of_mul_le_mul_left hcomb hcpos\n\nprivate lemma weightedExpReg_congr_of_pos\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (T K : ℕ) (hK : 0 < K) (η η' : ℕ → ℝ)\n (l l' : ℕ → Ω → Fin K → ℝ) (a : ℕ → Ω → Fin K)\n (hη : ∀ t, 1 ≤ t → η t = η' t)\n (hl : ∀ t, 1 ≤ t → l t = l' t) :\n weightedExpReg μ T K hK η l a = weightedExpReg μ T K hK η' l' a := by\n letI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n unfold weightedExpReg\n congr 1\n funext ω\n congr 1\n · apply Finset.sum_congr rfl\n intro t ht\n have ht1 : 1 ≤ t := (Finset.mem_Icc.mp ht).1\n rw [hη t ht1, hl t ht1]\n · apply Finset.inf'_congr Finset.univ_nonempty rfl\n intro i hi\n apply Finset.sum_congr rfl\n intro t ht\n have ht1 : 1 ≤ t := (Finset.mem_Icc.mp ht).1\n rw [hη t ht1, hl t ht1]\n\nprivate lemma MStar_congr_of_pos (T : ℕ) (d : ℕ → ℕ) (η η' : ℕ → ℝ)\n (hη : ∀ t, 1 ≤ t → η t = η' t) : MStar T d η = MStar T d η' := by\n ext t\n simp only [MStar, Finset.mem_filter]\n constructor\n · rintro ⟨ht, hcond⟩\n exact ⟨ht, by simpa [hη t (Finset.mem_Icc.mp ht).1] using hcond⟩\n · rintro ⟨ht, hcond⟩\n exact ⟨ht, by simpa [hη t (Finset.mem_Icc.mp ht).1] using hcond⟩\n\nprivate lemma missed_sum_bound\n (η : ℕ → ℝ) (d : ℕ → ℕ)\n (hηpos : ∀ t, 0 < η t) (hηanti : Antitone η)\n (B : ℝ) (hB : 0 ≤ B) (hq : ∀ t, η t * (d t : ℝ) ≤ B)\n (n T : ℕ) (hn : 2 ≤ n) (hT : n ≤ T) :\n (∑ t ∈ missedRounds T d, η t) ≤\n 2 * (n : ℝ) * B + (1 / ((n - 1 : ℕ) : ℝ)) *\n (∑ t ∈ Finset.Icc 1 T, η t) := by\n let u : ℕ := T / n\n let c : ℕ := T - u\n let A : Finset ℕ := (missedRounds T d).filter (fun t => t ≤ c)\n let Z : Finset ℕ := (missedRounds T d).filter (fun t => ¬t ≤ c)\n have hn0 : 0 < n := by omega\n have hu0 : 0 < u := by\n dsimp [u]\n exact Nat.div_pos hT hn0\n have huT : u ≤ T := by\n dsimp [u]\n exact Nat.div_le_self _ _\n have hcu : c + u = T := by\n dsimp [c]\n exact Nat.sub_add_cancel huT\n have hsplit :\n (∑ t ∈ A, η t) + (∑ t ∈ Z, η t) = ∑ t ∈ missedRounds T d, η t := by\n simpa [A, Z] using\n (Finset.sum_filter_add_sum_filter_not (missedRounds T d) (fun t => t ≤ c) η)\n have hA_point : ∀ t ∈ A, η t ≤ B / (u : ℝ) := by\n intro t ht\n have ht' := (Finset.mem_filter.mp ht)\n have htM := (Finset.mem_filter.mp ht'.1)\n have hutu : u ≤ T - t := by omega\n have hud : u < d t := by omega\n have hudR : (u : ℝ) ≤ d t := by exact_mod_cast hud.le\n rw [le_div_iff₀ (by exact_mod_cast hu0)]\n calc\n η t * (u : ℝ) ≤ η t * (d t : ℝ) :=\n mul_le_mul_of_nonneg_left hudR (hηpos t).le\n _ ≤ B := hq t\n have hcardA : (A.card : ℝ) ≤ T := by\n have hAsub : A ⊆ Finset.Icc 1 T := by\n intro t ht\n exact (Finset.mem_filter.mp (Finset.mem_filter.mp ht).1).1\n have hcA := Finset.card_le_card hAsub\n rw [Nat.card_Icc] at hcA\n norm_num at hcA\n exact_mod_cast hcA\n have hT_two_nu : (T : ℝ) ≤ 2 * (n : ℝ) * (u : ℝ) := by\n have hmod : T % n < n := Nat.mod_lt _ hn0\n have hnu : n ≤ n * u := by\n have : 1 ≤ u := hu0\n nlinarith\n have hnat : T ≤ 2 * n * u := by\n calc\n T = n * u + T % n := by\n dsimp [u]\n exact (Nat.div_add_mod T n).symm\n _ ≤ n * u + n := by omega\n _ ≤ n * u + n * u := by omega\n _ = 2 * n * u := by ring\n exact_mod_cast hnat\n have hA_sum : (∑ t ∈ A, η t) ≤ 2 * (n : ℝ) * B := by\n calc\n (∑ t ∈ A, η t) ≤ (A.card : ℝ) * (B / (u : ℝ)) := by\n simpa only [nsmul_eq_mul] using Finset.sum_le_card_nsmul A η (B / (u : ℝ)) hA_point\n _ ≤ (T : ℝ) * (B / (u : ℝ)) := by\n exact mul_le_mul_of_nonneg_right hcardA (div_nonneg hB (by positivity))\n _ ≤ 2 * (n : ℝ) * B := by\n have huR : 0 < (u : ℝ) := by exact_mod_cast hu0\n rw [← mul_div_assoc]\n rw [div_le_iff₀ huR]\n nlinarith [mul_le_mul_of_nonneg_right hT_two_nu hB]\n have hZsub : Z ⊆ Finset.Icc (c + 1) T := by\n intro t ht\n have ht' := Finset.mem_filter.mp ht\n have htM := Finset.mem_filter.mp ht'.1\n rw [Finset.mem_Icc]\n exact ⟨Nat.lt_iff_add_one_le.mp (lt_of_not_ge ht'.2), (Finset.mem_Icc.mp htM.1).2⟩\n have hcardZ : (Z.card : ℝ) ≤ u := by\n have hz := Finset.card_le_card hZsub\n rw [Nat.card_Icc] at hz\n have hcard : T + 1 - (c + 1) = u := by omega\n rw [hcard] at hz\n exact_mod_cast hz\n have hZ_point : ∀ t ∈ Z, η t ≤ η (c + 1) := by\n intro t ht\n exact hηanti (Finset.mem_Icc.mp (hZsub ht)).1\n have hZ_sum : (∑ t ∈ Z, η t) ≤ (u : ℝ) * η (c + 1) := by\n calc\n (∑ t ∈ Z, η t) ≤ (Z.card : ℝ) * η (c + 1) := by\n simpa only [nsmul_eq_mul] using\n Finset.sum_le_card_nsmul Z η (η (c + 1)) hZ_point\n _ ≤ (u : ℝ) * η (c + 1) :=\n mul_le_mul_of_nonneg_right hcardZ (hηpos (c + 1)).le\n have hc1T : c + 1 ≤ T := by omega\n have hprefix_sub : Finset.Icc 1 (c + 1) ⊆ Finset.Icc 1 T := by\n intro t ht\n rw [Finset.mem_Icc] at ht ⊢\n omega\n have hS_nonneg : 0 ≤ ∑ t ∈ Finset.Icc 1 T, η t := by\n exact Finset.sum_nonneg fun t ht => (hηpos t).le\n have hprefix : ((c + 1 : ℕ) : ℝ) * η (c + 1) ≤\n ∑ t ∈ Finset.Icc 1 T, η t := by\n have hlow : ((c + 1 : ℕ) : ℝ) * η (c + 1) ≤\n ∑ t ∈ Finset.Icc 1 (c + 1), η t := by\n calc\n ((c + 1 : ℕ) : ℝ) * η (c + 1) =\n ∑ _t ∈ Finset.Icc 1 (c + 1), η (c + 1) := by\n simp [Nat.card_Icc]\n _ ≤ ∑ t ∈ Finset.Icc 1 (c + 1), η t := by\n apply Finset.sum_le_sum\n intro t ht\n exact hηanti (Finset.mem_Icc.mp ht).2\n exact hlow.trans\n (Finset.sum_le_sum_of_subset_of_nonneg hprefix_sub (fun t ht hnot => (hηpos t).le))\n have hnsub0 : 0 < ((n - 1 : ℕ) : ℝ) := by\n exact_mod_cast (show 0 < n - 1 by omega)\n have hnu_c : ((n - 1 : ℕ) : ℝ) * (u : ℝ) ≤ (c + 1 : ℕ) := by\n have hmul : (n - 1) * u ≤ c + 1 := by\n have hbase : n * u ≤ T := by\n dsimp [u]\n simpa [Nat.mul_comm] using Nat.div_mul_le_self T n\n calc\n (n - 1) * u = n * u - u := by\n rw [Nat.sub_mul]\n simp\n _ ≤ T - u := Nat.sub_le_sub_right hbase u\n _ ≤ c + 1 := by simp [c]\n exact_mod_cast hmul\n have hZ_ratio : (u : ℝ) * η (c + 1) ≤\n (1 / ((n - 1 : ℕ) : ℝ)) * (∑ t ∈ Finset.Icc 1 T, η t) := by\n calc\n (u : ℝ) * η (c + 1) ≤\n (1 / ((n - 1 : ℕ) : ℝ)) * (((c + 1 : ℕ) : ℝ) * η (c + 1)) := by\n rw [one_div, inv_mul_eq_div]\n rw [le_div_iff₀ hnsub0]\n nlinarith [hnu_c, (hηpos (c + 1)).le]\n _ ≤ (1 / ((n - 1 : ℕ) : ℝ)) * (∑ t ∈ Finset.Icc 1 T, η t) := by\n exact mul_le_mul_of_nonneg_left hprefix (by positivity)\n rw [← hsplit]\n exact add_le_add hA_sum (hZ_sum.trans hZ_ratio)\n\nprivate lemma missed_ratio_tendsto_zero\n (η : ℕ → ℝ) (d : ℕ → ℕ)\n (hηpos : ∀ t, 0 < η t) (hηanti : Antitone η)\n (hS : Tendsto (fun T : ℕ => ∑ t ∈ Finset.Icc 1 T, η t) atTop atTop)\n {L : ℝ} (hq : Tendsto (fun t : ℕ => η t * (d t : ℝ)) atTop (nhds L)) :\n Tendsto (fun T : ℕ =>\n (∑ t ∈ missedRounds T d, η t) / (∑ t ∈ Finset.Icc 1 T, η t))\n atTop (nhds 0) := by\n let q : ℕ → ℝ := fun t => η t * (d t : ℝ)\n have hq' : Tendsto q atTop (nhds L) := hq\n obtain ⟨B, hBrange⟩ :=\n (Metric.isBounded_range_of_tendsto q hq').subset_closedBall (0 : ℝ)\n have hq_abs : ∀ t, |q t| ≤ B := by\n intro t\n have ht := hBrange (Set.mem_range_self t)\n simpa only [Metric.mem_closedBall, Real.dist_eq, sub_zero] using ht\n have hB : 0 ≤ B := (abs_nonneg (q 0)).trans (hq_abs 0)\n have hq_le : ∀ t, η t * (d t : ℝ) ≤ B := by\n intro t\n exact (le_abs_self (q t)).trans (hq_abs t)\n rw [Metric.tendsto_atTop]\n intro ε hε\n obtain ⟨k, hk⟩ := exists_nat_one_div_lt (show 0 < ε / 4 by positivity)\n let n : ℕ := k + 2\n have hn : 2 ≤ n := by simp [n]\n have hn0 : 0 < n := by omega\n have hcoeff : 1 / (((n - 1 : ℕ) : ℝ)) < ε / 4 := by\n simpa [n] using hk\n have hevS : ∀ᶠ T : ℕ in atTop,\n 4 * (n : ℝ) * B / ε < ∑ t ∈ Finset.Icc 1 T, η t :=\n hS.eventually_gt_atTop _\n obtain ⟨N, hN⟩ := Filter.eventually_atTop.mp hevS\n refine ⟨max N n, ?_⟩\n intro T hTmax\n have hST := hN T ((le_max_left N n).trans hTmax)\n have hT : n ≤ T := (le_max_right N n).trans hTmax\n let ST : ℝ := ∑ t ∈ Finset.Icc 1 T, η t\n let MT : ℝ := ∑ t ∈ missedRounds T d, η t\n have hthreshold_nonneg : 0 ≤ 4 * (n : ℝ) * B / ε := by positivity\n have hSTpos : 0 < ST := hthreshold_nonneg.trans_lt hST\n have hMTnonneg : 0 ≤ MT := by\n exact Finset.sum_nonneg fun t ht => (hηpos t).le\n have hbound : MT ≤\n 2 * (n : ℝ) * B + (1 / (((n - 1 : ℕ) : ℝ))) * ST := by\n exact missed_sum_bound η d hηpos hηanti B hB hq_le n T hn hT\n have hratio : MT / ST ≤\n (2 * (n : ℝ) * B) / ST + 1 / (((n - 1 : ℕ) : ℝ)) := by\n calc\n MT / ST ≤\n (2 * (n : ℝ) * B + (1 / (((n - 1 : ℕ) : ℝ))) * ST) / ST := by\n exact div_le_div_of_nonneg_right hbound hSTpos.le\n _ = (2 * (n : ℝ) * B) / ST + 1 / (((n - 1 : ℕ) : ℝ)) := by\n field_simp\n have hfirst : (2 * (n : ℝ) * B) / ST < ε / 2 := by\n have hcross : 4 * (n : ℝ) * B < ST * ε := by\n exact (div_lt_iff₀ hε).mp hST\n rw [div_lt_iff₀ hSTpos]\n nlinarith\n rw [Real.dist_eq, sub_zero, abs_of_nonneg (div_nonneg hMTnonneg hSTpos.le)]\n exact hratio.trans_lt (by nlinarith)\n\nprivate noncomputable def Exp3Delayed.ratesCongr\n {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {K : ℕ} {hK : 0 < K}\n {l : ℕ → Ω → Fin K → ℝ} {d : ℕ → ℕ} {η γ η' γ' : ℕ → ℝ}\n (E : Exp3Delayed μ K hK l d η γ)\n (hη : ∀ s, 1 ≤ s → η' s = η s) (hγ : ∀ s, 1 ≤ s → γ' s = γ s) :\n Exp3Delayed μ K hK l d η' γ' where\n 𝓕 := E.𝓕\n 𝓕_le := E.𝓕_le\n 𝓕_mono := E.𝓕_mono\n a := E.a\n p := E.p\n Lhat := E.Lhat\n measurable_a := E.measurable_a\n 𝓕_eq := E.𝓕_eq\n measurable_p := E.measurable_p\n p_isProb := E.p_isProb\n p_init := E.p_init\n a_law := E.a_law\n Lhat_init := E.Lhat_init\n Lhat_step := by\n intro t ω i ht\n rw [E.Lhat_step t ω i ht]\n congr 1\n apply Finset.sum_congr\n · ext s\n simp only [Finset.mem_filter]\n constructor\n · rintro ⟨hs, harr, hbound, ha⟩\n have hs1 : 1 ≤ s := (Finset.mem_Icc.mp hs).1\n exact ⟨hs, harr, by simpa [hη s hs1] using hbound, ha⟩\n · rintro ⟨hs, harr, hbound, ha⟩\n have hs1 : 1 ≤ s := (Finset.mem_Icc.mp hs).1\n exact ⟨hs, harr, by simpa [hη s hs1] using hbound, ha⟩\n · intro s hs\n have hs1 : 1 ≤ s := (Finset.mem_Icc.mp (Finset.mem_filter.mp hs).1).1\n rw [hη s hs1, hγ s hs1]\n p_update := E.p_update\n\nprivate noncomputable def Exp3Delayed.lossCongr\n {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {K : ℕ} {hK : 0 < K}\n {l l' : ℕ → Ω → Fin K → ℝ} {d : ℕ → ℕ} {η γ : ℕ → ℝ}\n (E : Exp3Delayed μ K hK l d η γ)\n (hl : ∀ s, 1 ≤ s → l' s = l s) : Exp3Delayed μ K hK l' d η γ where\n 𝓕 := E.𝓕\n 𝓕_le := E.𝓕_le\n 𝓕_mono := E.𝓕_mono\n a := E.a\n p := E.p\n Lhat := E.Lhat\n measurable_a := E.measurable_a\n 𝓕_eq := by\n intro t\n rw [E.𝓕_eq]\n congr 1\n apply iSup_congr\n intro s\n apply iSup_congr_Prop Iff.rfl\n intro hs\n rw [hl s hs.1]\n measurable_p := E.measurable_p\n p_isProb := E.p_isProb\n p_init := E.p_init\n a_law := E.a_law\n Lhat_init := E.Lhat_init\n Lhat_step := by\n intro t ω i ht\n rw [E.Lhat_step t ω i ht]\n congr 1\n apply Finset.sum_congr rfl\n intro s hs\n have hs1 : 1 ≤ s := (Finset.mem_Icc.mp (Finset.mem_filter.mp hs).1).1\n rw [hl s hs1]\n p_update := E.p_update\n\ntheorem lemma6_noWeightedRegret {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (K : ℕ) (hK : 0 < K)\n (η : ℕ → ℝ) (l : ℕ → Ω → Fin K → ℝ) (d : ℕ → ℕ) (hd : ∀ t ≥ 1, 1 ≤ d t)\n (hη_pos : ∀ t ≥ 1, 0 < η t) (hη_dec : ∀ t ≥ 1, η (t + 1) ≤ η t)\n (hη_bound : ∀ t ≥ 1, η t ≤ (1 / 2) * Real.exp (-2))\n (hl : ∀ t ≥ 1, ∀ ω i, l t ω i ∈ Set.Icc (0 : ℝ) 1)\n (E : Exp3Delayed μ K hK l d η η)\n (hl_adapted : ∀ t i, @Measurable Ω ℝ\n (⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance) _\n (fun ω => l t ω i))\n (a_law_adaptive : ∀ t i,\n (μ[(fun ω => if E.a t ω = i then (1 : ℝ) else 0) |\n ⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E.a τ) inferInstance]) =ᵐ[μ]\n (fun ω => E.p t ω i))\n (h1 : Tendsto (fun T : ℕ => ∑ t ∈ Finset.Icc 1 T, η t) atTop atTop)\n (h2 : ∃ L : ℝ, Tendsto (fun t : ℕ => η t * (d t : ℝ)) atTop (nhds L))\n (h3 : Summable (fun t : ℕ => (η t) ^ 2 * (d t : ℝ))) :\n NoWeightedRegret μ K hK η l E.a := by\n let η' : ℕ → ℝ := fun t => if t = 0 then η 1 else η t\n let l' : ℕ → Ω → Fin K → ℝ := fun t => if t = 0 then fun _ _ => 0 else l t\n have hηeq : ∀ t, 1 ≤ t → η' t = η t := by\n intro t ht\n simp [η', Nat.ne_of_gt ht]\n have hleq : ∀ t, 1 ≤ t → l' t = l t := by\n intro t ht\n simp [l', Nat.ne_of_gt ht]\n let Eη : Exp3Delayed μ K hK l d η' η' :=\n E.ratesCongr (fun t ht => hηeq t ht) (fun t ht => hηeq t ht)\n let E' : Exp3Delayed μ K hK l' d η' η' := Eη.lossCongr hleq\n have hη'_pos : ∀ t, 0 < η' t := by\n intro t\n by_cases ht : t = 0\n · subst t\n simpa [η'] using hη_pos 1 (by omega)\n · simpa [η', ht] using hη_pos t (Nat.one_le_iff_ne_zero.mpr ht)\n have hη'_dec : ∀ t, η' (t + 1) ≤ η' t := by\n intro t\n by_cases ht : t = 0\n · subst t\n simp [η']\n · simpa [η', ht] using hη_dec t (Nat.one_le_iff_ne_zero.mpr ht)\n have hη'_bound : ∀ t, η' t ≤ (1 / 2) * Real.exp (-2) := by\n intro t\n by_cases ht : t = 0\n · subst t\n simpa [η'] using hη_bound 1 (by omega)\n · simpa [η', ht] using hη_bound t (Nat.one_le_iff_ne_zero.mpr ht)\n have hl' : ∀ t ω i, l' t ω i ∈ Set.Icc (0 : ℝ) 1 := by\n intro t ω i\n by_cases ht : t = 0\n · subst t\n simp [l']\n · simpa [l', ht] using hl t (Nat.one_le_iff_ne_zero.mpr ht) ω i\n have hl'_adapted : ∀ t i, @Measurable Ω ℝ\n (⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E'.a τ) inferInstance) _\n (fun ω => l' t ω i) := by\n intro t i\n by_cases ht : t = 0\n · subst t\n simp only [l', if_pos]\n exact measurable_const\n · simpa only [l', if_neg ht, E', Eη, Exp3Delayed.lossCongr,\n Exp3Delayed.ratesCongr] using hl_adapted t i\n have ha'_law : ∀ t i,\n (μ[(fun ω => if E'.a t ω = i then (1 : ℝ) else 0) |\n ⨆ τ ∈ Finset.Ico 1 t, MeasurableSpace.comap (E'.a τ) inferInstance]) =ᵐ[μ]\n (fun ω => E'.p t ω i) := by\n simpa only [E', Eη, Exp3Delayed.lossCongr, Exp3Delayed.ratesCongr] using\n a_law_adaptive\n have finite_bound : ∀ T : ℕ, 0 < T →\n weightedExpReg μ T K hK η l E.a ≤\n 2 + 2 * Real.log K\n + (1 + Real.exp 2 / 2) * K * (∑ t ∈ Finset.Icc 1 T, (η t) ^ 2)\n + 4 * Real.exp 2 * K *\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t) ^ 2 * (d t : ℝ))\n + (∑ t ∈ MStar T d η, η t) := by\n intro T hT\n have HB := lemma5_adaptive μ K T hK hT η' l' d hd hη'_pos hη'_dec\n hη'_bound hl' E' hl'_adapted ha'_law\n have hw := weightedExpReg_congr_of_pos μ T K hK η η' l l' E.a\n (fun t ht => (hηeq t ht).symm) (fun t ht => (hleq t ht).symm)\n change weightedExpReg μ T K hK η' l' E.a ≤ _ at HB\n rw [← hw] at HB\n have hM : MStar T d η' = MStar T d η :=\n MStar_congr_of_pos T d η' η hηeq\n rw [hM] at HB\n have hsquare : (∑ t ∈ Finset.Icc 1 T, (η' t) ^ 2) =\n ∑ t ∈ Finset.Icc 1 T, (η t) ^ 2 := by\n apply Finset.sum_congr rfl\n intro t ht\n rw [hηeq t (Finset.mem_Icc.mp ht).1]\n have hdelay :\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η' t) ^ 2 * (d t : ℝ)) =\n ∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t) ^ 2 * (d t : ℝ) := by\n apply Finset.sum_congr rfl\n intro t ht\n rw [hηeq t (Finset.mem_Icc.mp (Finset.mem_sdiff.mp ht).1).1]\n have hbad : (∑ t ∈ MStar T d η, η' t) = ∑ t ∈ MStar T d η, η t := by\n apply Finset.sum_congr rfl\n intro t ht\n rw [hηeq t (Finset.mem_Icc.mp (Finset.mem_filter.mp ht).1).1]\n simpa only [hsquare, hdelay, hbad, E', Eη, Exp3Delayed.lossCongr,\n Exp3Delayed.ratesCongr] using HB\n have hsum_eq : ∀ T : ℕ,\n (∑ t ∈ Finset.Icc 1 T, η' t) = ∑ t ∈ Finset.Icc 1 T, η t := by\n intro T\n apply Finset.sum_congr rfl\n intro t ht\n rw [hηeq t (Finset.mem_Icc.mp ht).1]\n have hmiss_sum_eq : ∀ T : ℕ,\n (∑ t ∈ missedRounds T d, η' t) = ∑ t ∈ missedRounds T d, η t := by\n intro T\n apply Finset.sum_congr rfl\n intro t ht\n rw [hηeq t (Finset.mem_Icc.mp (Finset.mem_filter.mp ht).1).1]\n have h1' : Tendsto (fun T : ℕ => ∑ t ∈ Finset.Icc 1 T, η' t) atTop atTop := by\n exact Filter.Tendsto.congr' (Eventually.of_forall fun T => (hsum_eq T).symm) h1\n obtain ⟨L, hq⟩ := h2\n have hq' : Tendsto (fun t : ℕ => η' t * (d t : ℝ)) atTop (nhds L) := by\n apply Filter.Tendsto.congr' _ hq\n filter_upwards [Filter.eventually_ge_atTop 1] with t ht\n rw [hηeq t ht]\n have hη'_anti : Antitone η' := antitone_nat_of_succ_le hη'_dec\n have hmiss' := missed_ratio_tendsto_zero η' d hη'_pos hη'_anti h1' hq'\n have hmiss : Tendsto (fun T : ℕ =>\n (∑ t ∈ missedRounds T d, η t) / (∑ t ∈ Finset.Icc 1 T, η t))\n atTop (nhds 0) := by\n apply Filter.Tendsto.congr' _ hmiss'\n exact Eventually.of_forall fun T => by\n change (∑ t ∈ missedRounds T d, η' t) / (∑ t ∈ Finset.Icc 1 T, η' t) = _\n rw [hmiss_sum_eq T, hsum_eq T]\n have h3shift : Summable (fun n : ℕ =>\n (η (n + 1)) ^ 2 * (d (n + 1) : ℝ)) :=\n (summable_nat_add_iff 1).2 h3\n have heta_sq_shift : Summable (fun n : ℕ => (η (n + 1)) ^ 2) := by\n apply h3shift.of_nonneg_of_le\n · intro n\n positivity\n · intro n\n have hdR : (1 : ℝ) ≤ d (n + 1) := by\n exact_mod_cast hd (n + 1) (by omega)\n calc\n (η (n + 1)) ^ 2 = (η (n + 1)) ^ 2 * 1 := by ring\n _ ≤ (η (n + 1)) ^ 2 * (d (n + 1) : ℝ) :=\n mul_le_mul_of_nonneg_left hdR (sq_nonneg _)\n have heta_sq : Summable (fun n : ℕ => (η n) ^ 2) :=\n (summable_nat_add_iff 1).1 heta_sq_shift\n let b : ℕ → ℝ := fun t => Real.exp 2 * ((η t) ^ 2 * (d t : ℝ) + (η t) ^ 2)\n have hb_nonneg : ∀ t, 0 ≤ b t := by\n intro t\n dsimp [b]\n positivity\n have hb_sum : Summable b := by\n dsimp [b]\n exact (h3.add heta_sq).mul_left (Real.exp 2)\n let Hset : ℕ → Finset ℕ := fun T => (Finset.Icc 1 T).filter\n (fun t => (d t : ℝ) ≥ 1 / (Real.exp 2 * η t) - 1)\n have hthreshold_point : ∀ T t, t ∈ Hset T → η t ≤ b t := by\n intro T t ht\n have ht' := Finset.mem_filter.mp ht\n have ht1 : 1 ≤ t := (Finset.mem_Icc.mp ht'.1).1\n have hthreshold :\n (1 : ℝ) / (Real.exp 2 * η t) ≤ (d t : ℝ) + 1 := by\n linarith\n have hx : 0 < Real.exp 2 * η t := mul_pos (Real.exp_pos _) (hη_pos t ht1)\n have hone : (1 : ℝ) ≤ (Real.exp 2 * η t) * ((d t : ℝ) + 1) := by\n calc\n (1 : ℝ) = (Real.exp 2 * η t) * (1 / (Real.exp 2 * η t)) := by\n exact (mul_div_cancel₀ 1 hx.ne').symm\n _ ≤ (Real.exp 2 * η t) * ((d t : ℝ) + 1) :=\n mul_le_mul_of_nonneg_left hthreshold hx.le\n calc\n η t = η t * 1 := by ring\n _ ≤ η t * ((Real.exp 2 * η t) * ((d t : ℝ) + 1)) :=\n mul_le_mul_of_nonneg_left hone (hη_pos t ht1).le\n _ = b t := by\n dsimp [b]\n ring\n have hH_sum : ∀ T : ℕ, (∑ t ∈ Hset T, η t) ≤ ∑' t : ℕ, b t := by\n intro T\n calc\n (∑ t ∈ Hset T, η t) ≤ ∑ t ∈ Hset T, b t := by\n exact Finset.sum_le_sum fun t ht => hthreshold_point T t ht\n _ ≤ ∑' t : ℕ, b t := hb_sum.sum_le_tsum (Hset T) (fun t ht => hb_nonneg t)\n have hM_sub : ∀ T : ℕ, MStar T d η ⊆ missedRounds T d ∪ Hset T := by\n intro T t ht\n have ht' := Finset.mem_filter.mp ht\n rcases ht'.2 with harr | hthreshold\n · apply Finset.mem_union_left\n rw [missedRounds, Finset.mem_filter]\n exact ⟨ht'.1, harr⟩\n · apply Finset.mem_union_right\n dsimp [Hset]\n rw [Finset.mem_filter]\n exact ⟨ht'.1, hthreshold⟩\n have hM_sum : ∀ T : ℕ,\n (∑ t ∈ MStar T d η, η t) ≤\n (∑ t ∈ missedRounds T d, η t) + ∑' t : ℕ, b t := by\n intro T\n have hunion :\n (∑ t ∈ missedRounds T d ∪ Hset T, η t) ≤\n (∑ t ∈ missedRounds T d, η t) + (∑ t ∈ Hset T, η t) := by\n have hi := Finset.sum_union_inter (s₁ := missedRounds T d) (s₂ := Hset T)\n (f := η)\n have hinter : 0 ≤ ∑ t ∈ missedRounds T d ∩ Hset T, η t := by\n exact Finset.sum_nonneg fun t ht =>\n (hη_pos t (Finset.mem_Icc.mp (Finset.mem_filter.mp\n (Finset.mem_inter.mp ht).1).1).1).le\n linarith\n calc\n (∑ t ∈ MStar T d η, η t) ≤\n ∑ t ∈ missedRounds T d ∪ Hset T, η t := by\n exact Finset.sum_le_sum_of_subset_of_nonneg (hM_sub T)\n (fun t ht hnot => by\n rcases Finset.mem_union.mp ht with ht | ht\n · exact (hη_pos t (Finset.mem_Icc.mp (Finset.mem_filter.mp ht).1).1).le\n · exact (hη_pos t (Finset.mem_Icc.mp (Finset.mem_filter.mp ht).1).1).le)\n _ ≤ (∑ t ∈ missedRounds T d, η t) + (∑ t ∈ Hset T, η t) := hunion\n _ ≤ (∑ t ∈ missedRounds T d, η t) + ∑' t : ℕ, b t :=\n add_le_add_right (hH_sum T) _\n have hS_nonneg : ∀ T : ℕ, 0 ≤ ∑ t ∈ Finset.Icc 1 T, η t := by\n intro T\n exact Finset.sum_nonneg fun t ht => (hη_pos t (Finset.mem_Icc.mp ht).1).le\n have hMratio_le : ∀ T : ℕ,\n (∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t) ≤\n (∑ t ∈ missedRounds T d, η t) / (∑ t ∈ Finset.Icc 1 T, η t) +\n (∑' t : ℕ, b t) / (∑ t ∈ Finset.Icc 1 T, η t) := by\n intro T\n calc\n (∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t) ≤\n ((∑ t ∈ missedRounds T d, η t) + ∑' t : ℕ, b t) /\n (∑ t ∈ Finset.Icc 1 T, η t) :=\n div_le_div_of_nonneg_right (hM_sum T) (hS_nonneg T)\n _ = (∑ t ∈ missedRounds T d, η t) / (∑ t ∈ Finset.Icc 1 T, η t) +\n (∑' t : ℕ, b t) / (∑ t ∈ Finset.Icc 1 T, η t) := by rw [add_div]\n have hupper : Tendsto (fun T : ℕ =>\n (∑ t ∈ missedRounds T d, η t) / (∑ t ∈ Finset.Icc 1 T, η t) +\n (∑' t : ℕ, b t) / (∑ t ∈ Finset.Icc 1 T, η t)) atTop (nhds 0) := by\n simpa using hmiss.add (h1.const_div_atTop (∑' t : ℕ, b t))\n have hMratio : Tendsto (fun T : ℕ =>\n (∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t))\n atTop (nhds 0) := by\n apply squeeze_zero\n · intro T\n exact div_nonneg\n (Finset.sum_nonneg fun t ht =>\n (hη_pos t (Finset.mem_Icc.mp (Finset.mem_filter.mp ht).1).1).le)\n (hS_nonneg T)\n · exact hMratio_le\n · exact hupper\n have hlog_nonneg : 0 ≤ Real.log (K : ℝ) := by\n apply Real.log_nonneg\n exact_mod_cast (show 1 ≤ K by omega)\n have heta_part : ∀ T : ℕ,\n (∑ t ∈ Finset.Icc 1 T, (η t) ^ 2) ≤ ∑' t : ℕ, (η t) ^ 2 := by\n intro T\n exact heta_sq.sum_le_tsum (Finset.Icc 1 T) (fun t ht => sq_nonneg _)\n have hr_part : ∀ T : ℕ,\n (∑ t ∈ (Finset.Icc 1 T) \\ MStar T d η, (η t) ^ 2 * (d t : ℝ)) ≤\n ∑' t : ℕ, (η t) ^ 2 * (d t : ℝ) := by\n intro T\n exact h3.sum_le_tsum ((Finset.Icc 1 T) \\ MStar T d η)\n (fun t ht => by positivity)\n let C0 : ℝ :=\n 2 + 2 * Real.log K\n + (1 + Real.exp 2 / 2) * K * (∑' t : ℕ, (η t) ^ 2)\n + 4 * Real.exp 2 * K * (∑' t : ℕ, (η t) ^ 2 * (d t : ℝ))\n have hC0 : 0 ≤ C0 := by\n dsimp [C0]\n have hsquare_tsum : 0 ≤ ∑' t : ℕ, (η t) ^ 2 := tsum_nonneg fun t => sq_nonneg _\n have hr_tsum : 0 ≤ ∑' t : ℕ, (η t) ^ 2 * (d t : ℝ) :=\n tsum_nonneg fun t => by positivity\n positivity\n have hR_bound : ∀ T : ℕ,\n weightedExpReg μ T K hK η l E.a ≤ C0 + ∑ t ∈ MStar T d η, η t := by\n intro T\n rcases T with _ | T\n · simp [weightedExpReg, MStar, C0]\n exact hC0\n · calc\n weightedExpReg μ (T + 1) K hK η l E.a ≤\n 2 + 2 * Real.log K\n + (1 + Real.exp 2 / 2) * K *\n (∑ t ∈ Finset.Icc 1 (T + 1), (η t) ^ 2)\n + 4 * Real.exp 2 * K *\n (∑ t ∈ (Finset.Icc 1 (T + 1)) \\ MStar (T + 1) d η,\n (η t) ^ 2 * (d t : ℝ))\n + (∑ t ∈ MStar (T + 1) d η, η t) :=\n finite_bound (T + 1) (by omega)\n _ ≤ C0 + ∑ t ∈ MStar (T + 1) d η, η t := by\n dsimp [C0]\n gcongr\n · exact heta_part (T + 1)\n · exact hr_part (T + 1)\n have hRratio_le : ∀ T : ℕ,\n weightedExpReg μ T K hK η l E.a / (∑ t ∈ Finset.Icc 1 T, η t) ≤\n C0 / (∑ t ∈ Finset.Icc 1 T, η t) +\n (∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t) := by\n intro T\n calc\n weightedExpReg μ T K hK η l E.a / (∑ t ∈ Finset.Icc 1 T, η t) ≤\n (C0 + ∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t) :=\n div_le_div_of_nonneg_right (hR_bound T) (hS_nonneg T)\n _ = C0 / (∑ t ∈ Finset.Icc 1 T, η t) +\n (∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t) := by\n rw [add_div]\n have hRupper : Tendsto (fun T : ℕ =>\n C0 / (∑ t ∈ Finset.Icc 1 T, η t) +\n (∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t))\n atTop (nhds 0) := by\n simpa using (h1.const_div_atTop C0).add hMratio\n have hR_lower : ∀ T : ℕ,\n -(∑ t ∈ Finset.Icc 1 T, η t) ≤ weightedExpReg μ T K hK η l E.a := by\n intro T\n letI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n let ST : ℝ := ∑ t ∈ Finset.Icc 1 T, η t\n let F : Ω → ℝ := fun ω =>\n (∑ t ∈ Finset.Icc 1 T, η t * l t ω (E.a t ω)) -\n (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l t ω i)\n change -ST ≤ ∫ ω, F ω ∂μ\n have hpoint : ∀ ω, -ST ≤ F ω := by\n intro ω\n have hactual : 0 ≤ ∑ t ∈ Finset.Icc 1 T, η t * l t ω (E.a t ω) := by\n apply Finset.sum_nonneg\n intro t ht\n exact mul_nonneg (hη_pos t (Finset.mem_Icc.mp ht).1).le\n (hl t (Finset.mem_Icc.mp ht).1 ω (E.a t ω)).1\n let i0 : Fin K := ⟨0, hK⟩\n have hcomp :\n (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l t ω i) ≤ ST := by\n calc\n (Finset.univ : Finset (Fin K)).inf' Finset.univ_nonempty\n (fun i => ∑ t ∈ Finset.Icc 1 T, η t * l t ω i) ≤\n ∑ t ∈ Finset.Icc 1 T, η t * l t ω i0 :=\n Finset.inf'_le _ (Finset.mem_univ i0)\n _ ≤ ST := by\n dsimp [ST]\n apply Finset.sum_le_sum\n intro t ht\n simpa only [mul_one] using mul_le_mul_of_nonneg_left\n (hl t (Finset.mem_Icc.mp ht).1 ω i0).2\n (hη_pos t (Finset.mem_Icc.mp ht).1).le\n dsimp [F]\n linarith\n by_cases hF : Integrable F μ\n · have hconst : Integrable (fun _ : Ω => -ST) μ := integrable_const _\n calc\n -ST = ∫ _ : Ω, -ST ∂μ := by simp\n _ ≤ ∫ ω, F ω ∂μ := integral_mono hconst hF hpoint\n · rw [integral_undef hF]\n exact neg_nonpos.mpr (hS_nonneg T)\n have hratio_lower : ∀ T : ℕ, (-1 : ℝ) ≤\n weightedExpReg μ T K hK η l E.a / (∑ t ∈ Finset.Icc 1 T, η t) := by\n intro T\n rcases T with _ | T\n · simp [weightedExpReg]\n · have hSTpos : 0 < ∑ t ∈ Finset.Icc 1 (T + 1), η t := by\n apply Finset.sum_pos\n · intro t ht\n exact hη_pos t (Finset.mem_Icc.mp ht).1\n · exact ⟨1, by simp⟩\n calc\n (-1 : ℝ) = (-(∑ t ∈ Finset.Icc 1 (T + 1), η t)) /\n (∑ t ∈ Finset.Icc 1 (T + 1), η t) := by field_simp\n _ ≤ weightedExpReg μ (T + 1) K hK η l E.a /\n (∑ t ∈ Finset.Icc 1 (T + 1), η t) :=\n div_le_div_of_nonneg_right (hR_lower (T + 1)) hSTpos.le\n have hRcobounded : IsCoboundedUnder (fun x₁ x₂ : ℝ => x₁ ≤ x₂) atTop\n (fun T : ℕ => weightedExpReg μ T K hK η l E.a /\n ∑ t ∈ Finset.Icc 1 T, η t) :=\n isCoboundedUnder_le_of_le atTop hratio_lower\n unfold NoWeightedRegret\n calc\n limsup (fun T : ℕ =>\n weightedExpReg μ T K hK η l E.a / ∑ t ∈ Finset.Icc 1 T, η t) atTop ≤\n limsup (fun T : ℕ =>\n C0 / (∑ t ∈ Finset.Icc 1 T, η t) +\n (∑ t ∈ MStar T d η, η t) / (∑ t ∈ Finset.Icc 1 T, η t)) atTop :=\n Filter.limsup_le_limsup (Eventually.of_forall hRratio_le) hRcobounded\n hRupper.isBoundedUnder_le\n _ = 0 := hRupper.limsup_eq\n\nend ResearchLevel\n"} +{"id": "v23-21-1027", "source": "Research-level", "targets": [{"label": "Theorem 3", "decls": ["theorem3"], "statement": "Theorem 3 (Regret bound for dual-stabilized OMD) Assume we have $\\eta_{t}\\geq \\eta_{t + 1}>$ 0 for each $t > 1$ . Define $\\gamma_{t}=\\eta_{t+1}/\\eta_{t}\\in(0,1]$ for all $t \\geq 1$ . Let $\\{f_{t}\\}_{t \\ge 1}$ be a sequence of convex functions with $f_{t}\\colon \\mathcal{X}\\to \\mathbb{R}$ for each $t \\geq 1$ . Let $\\{x_{t}\\}_{t \\ge 1}$ and $\\{\\hat{w}_{t}\\}_{t \\ge 2}$ be as in Algorithm 2. Then, for all $T > 0$ and $z \\in \\mathcal{X}$ ,\n\n$$\n\\mathrm{Regret}(T,z)\\ \\leq\\ \\sum_{t=1}^{T}\\frac{D_{\\Phi}\\bigl({}_{x_{t+1}}^{x_{t}};w_{t+1}\\bigr)}{\\eta_{t}}+\\frac{D_{\\Phi}\\bigl(z,x_{1}\\bigr)}{\\eta_{T+1}}.\\tag{8}\n$$", "context_ids": ["v23-21-1027:ctx1", "v23-21-1027:ctx2", "v23-21-1027:ctx3", "v23-21-1027:ctx4", "v23-21-1027:ctx5", "v23-21-1027:ctx6", "v23-21-1027:ctx7", "v23-21-1027:ctx8", "v23-21-1027:ctx9", "v23-21-1027:ctx16"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}, {"label": "Theorem 5", "decls": ["theorem5"], "statement": "Theorem 5 (Regret bound for primal-stabilized OMD) Assume $\\eta_{t}\\geq \\eta_{t + 1}> 0$ for each $t > 1$ . Define $\\gamma_{t}=\\eta_{t+1}/\\eta_{t}\\in(0,1]$ for all $t \\geq 1$ . Let $\\{x_{t}\\}_{t \\ge 1}$ be the sequence of iterates generated by Algorithm 3. Furthermore, assume that\n\nfor all $z \\in \\mathcal{X}$ , the map $x\\mapsto D_{\\Phi}(z,x)$ is convex on $\\mathcal{X}.$\n\n(15)\n\nThen for any sequence of convex functions $\\{f_{t}\\}_{t \\ge 1}$ with each $f_{t}: \\mathcal{X}\\to \\mathbb{R}$ ,\n\n$$\n\\mathrm{Regret}(T,z)\\ \\leq\\ \\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{y_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\frac{D_{\\Phi}\\big(z,x_{1}\\big)}{\\eta_{T+1}}\\quad\\forall T>0 .\\tag{16}\n$$", "context_ids": ["v23-21-1027:ctx1", "v23-21-1027:ctx2", "v23-21-1027:ctx3", "v23-21-1027:ctx4", "v23-21-1027:ctx5", "v23-21-1027:ctx6", "v23-21-1027:ctx7", "v23-21-1027:ctx9", "v23-21-1027:ctx10", "v23-21-1027:ctx16"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}, {"label": "Theorem 8", "decls": ["theorem8"], "statement": "Theorem 8 (Regret bound for dual averaging) Assume we have $\\eta_{t}\\geq \\eta_{t + 1}> 0$ for each $t \\geq 1$ . Let $\\{x_{t}\\}_{t \\ge 1}$ be the sequence of iterates generated by Algorithm 4. Then for any sequence of convex functions $\\{f_{t}\\}_{t \\ge 1}$ with each $f_{t}: \\mathcal{X}\\to \\mathbb{R}$ ,\n\n$$\n\\mathrm{Regret}(T,z)~\\le~\\sum_{t=1}^{T}\\frac{D_{\\Phi}\\bigl({{}_{x_{t+1}}^{x_{t}};\\nabla\\Phi^{*}(\\hat{x}_{t}-\\eta_{t}\\hat{g}_{t})\\bigr)}}{\\eta_{t}}+\\frac{D_{\\Phi}\\bigl(z,x_{1}\\bigr)}{\\eta_{T+1}}~\\forall T>0 .\\tag{20}\n$$", "context_ids": ["v23-21-1027:ctx1", "v23-21-1027:ctx2", "v23-21-1027:ctx3", "v23-21-1027:ctx4", "v23-21-1027:ctx5", "v23-21-1027:ctx6", "v23-21-1027:ctx8", "v23-21-1027:ctx9", "v23-21-1027:ctx11", "v23-21-1027:ctx12", "v23-21-1027:ctx13", "v23-21-1027:ctx14", "v23-21-1027:ctx15", "v23-21-1027:ctx16"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}], "nl_proof": "### Proof of Theorem 3\n\nProof [of Theorem 3]\n\nLet $z \\in \\mathcal{X}$ . The first step is the same as in the standard OMD proof.\n\n$$\n\\begin{array}{r l l}\nf_{t}(x_{t})-f_{t}(z)&\\leq\\ \\langle\\hat{g}_{t},x_{t}-z\\rangle&\\text{(subgradient ineq.)}\\\\\n&=\\ \\frac{1}{\\eta_{t}}\\langle\\hat{x}_{t}-\\hat{w}_{t+1},x_{t}-z\\rangle&\\text{(by (5))}\\\\\n&=\\ \\frac{1}{\\eta_{t}}\\big(D_{\\Phi}(x_{t},w_{t+1})-D_{\\Phi}(z,w_{t+1})+D_{\\Phi}(z,x_{t})\\big)&\\text{(by Prop. 38).}\n\\end{array}\\tag{9}\n$$\n\nThe next step exhibits the main point of stabilization. Without stabilization, we would have $x_{t+1}=\\Pi_{\\mathcal{X}}^{\\Phi}(w_{t+1})$ and $D_{\\Phi}(z,w_{t+1})\\geq D_{\\Phi}(z,x_{t+1})+D_{\\Phi}(x_{t+1},w_{t+1})$ by Proposition 40, so (9) would lead to a telescoping sum involving $D_{\\Phi}(z,\\cdot)$ if the learning rate were fixed. With a dynamic learning rate the analysis is trickier: we need a claim that leads to telescoping terms by relating $D_{\\Phi}(z,w_{t+1})$ to $D_{\\Phi}\\big(z,x_{t+1}\\big)$\n\nClaim 4 Assume that $\\gamma_{t}=\\eta_{t+1}/\\eta_{t}\\in(0,1]$ . Then\n\n$$\n(9)~\\le~\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\underbrace{\\Big(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\Big)}_{telescopes}D_{\\Phi}(z,x_{1})+\\underbrace{\\frac{D_{\\Phi}(z,x_{t})}{\\eta_{t}}-\\frac{D_{\\Phi}(z,x_{t+1})}{\\eta_{t+1}}}_{telescopes}.\n$$\n\nProof First we derive the inequality\n\n$$\n\\begin{array}{r l l}\n&\\gamma_{t}\\big(D_{\\Phi}(z,w_{t+1})-D_{\\Phi}(x_{t+1},w_{t+1})\\big)\\ +\\ (1-\\gamma_{t})D_{\\Phi}(z,x_{1})&\\\\\n\\ge&\\gamma_{t}D_{\\Phi}({}_{x_{t+1}}^{z};w_{t+1})\\ +\\ (1-\\gamma_{t})D_{\\Phi}({}_{x_{t+1}}^{z};x_{1})&\\text{(since } D_{\\Phi}(x_{t+1},x_{1})\\ge 0 \\text{ and }\\gamma_{t}\\le 1)\\\\\n=&D_{\\Phi}({}_{x_{t+1}}^{z};y_{t+1})&\\text{(by Proposition 39 and (6))}\\\\\n\\ge&D_{\\Phi}(z,x_{t+1})&\\text{(by Proposition 40 and (7)).}\n\\end{array}\n$$\n\nRearranging and using $\\gamma_{t}> 0$ yields\n\n$$\nD_{\\Phi}(z,w_{t+1})\\ \\geq\\ D_{\\Phi}(x_{t+1},w_{t+1})-\\Big(\\frac{1}{\\gamma_{t}}-1\\Big)D_{\\Phi}(z,x_{1})+\\frac{1}{\\gamma_{t}}D_{\\Phi}(z,x_{t+1}).\\tag{10}\n$$\n\nPlugging this into (9) yields\n\n$$\n\\begin{array}{r l r}{{(9)\\ =\\ \\frac{1}{\\eta_{t}}\\Big(D_{\\Phi}\\big(x_{t},w_{t+1}\\big)-D_{\\Phi}\\big(z,w_{t+1}\\big)+D_{\\Phi}\\big(z,x_{t}\\big)\\Big)}}\\\\ &{}&\\\\ &{}&{\\leq\\ \\frac{1}{\\eta_{t}}\\Bigg(D_{\\Phi}\\big(x_{t},w_{t+1}\\big)-D_{\\Phi}\\big(x_{t+1},w_{t+1}\\big)\\ +}\\\\ &{}&\\\\ &{}&{\\Big(\\frac{1}{\\gamma_{t}}-1\\Big)D_{\\Phi}\\big(z,x_{1}\\big)-\\frac{1}{\\gamma_{t}}D_{\\Phi}\\big(z,x_{t+1}\\big)+D_{\\Phi}\\big(z,x_{t}\\big)\\Bigg).}\\end{array}\\tag{by (10)}\n$$\n\nThe claim follows by the definition of $\\gamma_{t}$\n\nThe final step is very similar to the standard OMD proof. Summing (9) over t and using Claim 4 leads to the desired telescoping sum.\n\n$$\n\\begin{array}{r l}&{\\displaystyle\\sum_{t=1}^{T}\\left(f_{t}(x_{t})-f_{t}(z)\\right)}\\\\ {\\le}&{\\displaystyle\\sum_{t=1}^{T}\\left(\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\Big(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\Big)D_{\\Phi}(z,x_{1})+\\frac{D_{\\Phi}(z,x_{t})}{\\eta_{t}}-\\frac{D_{\\Phi}(z,x_{t+1})}{\\eta_{t+1}}\\right)}\\\\ {\\le}&{\\displaystyle\\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\Bigg(\\frac{1}{\\eta_{1}}+\\sum_{t=1}^{T}\\left(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\right)\\Bigg)D_{\\Phi}(z,x_{1})}\\\\ {=}&{\\displaystyle\\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\frac{D_{\\Phi}(z,x_{1})}{\\eta_{T+1}}.}\\end{array}\n$$\n\n### Proof of Theorem 5\n\nLet $z \\in \\mathcal{X}$ . The first step is identical to the proof of Theorem 3 since the update rule in (11) is exactly the same as (5). Therefore, we have that (9) holds, that is,\n\n$$\nf_{t}(x_{t})-f_{t}(z)\\ \\leq\\ \\frac{1}{\\eta_{t}}\\big(D_{\\Phi}(x_{t},w_{t+1})-D_{\\Phi}(z,w_{t+1})+D_{\\Phi}(z,x_{t})\\big).\n$$\n\nNow instead of Claim 4 we use the next claim, which is similar to Claim 4 but replaces $D_{\\Phi}({}_{x_{t + 1}}^{x_{t}}; w_{t + 1})$ with $D_{\\Phi}({}_{y_{t + 1}}^{x_{t}}; w_{t + 1})$.\n\nClaim 6 Assume that $\\gamma_{t}=\\eta_{t+1}/\\eta_{t}\\in(0,1]$ . Then\n\n$$\n(9)~\\le~\\frac{D_{\\Phi}\\big({}_{y_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\underbrace{\\Big(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\Big)}_{telescopes}D_{\\Phi}(z,x_{1})+\\underbrace{\\frac{D_{\\Phi}(z,x_{t})}{\\eta_{t}}-\\frac{D_{\\Phi}(z,x_{t+1})}{\\eta_{t+1}}}_{telescopes}.\n$$\n\nProof First, we derive the inequality\n\n$$\n\\begin{array}{r l r}&{\\gamma_{t}\\big(D_{\\Phi}(z,w_{t+1})-D_{\\Phi}(y_{t+1},w_{t+1})\\big)+(1-\\gamma_{t})D_{\\Phi}(z,x_{1})}\\\\ {=}&{\\gamma_{t}D_{\\Phi}({}_{y_{t+1}}^{z};w_{t+1})+(1-\\gamma_{t})D_{\\Phi}(z,x_{1})}\\\\ {\\geq}&{\\gamma_{t}D_{\\Phi}(z,y_{t+1})+(1-\\gamma_{t})D_{\\Phi}(z,x_{1})}&{\\mathrm{~(by~Prop.~40~and~(13))}}\\\\ {\\geq}&{D_{\\Phi}(z,x_{t+1})}&{\\mathrm{~(by~(14)~and~(15)).}}\\end{array}\n$$\n\nRearranging and using $\\gamma_{t}> 0$ yields\n\n$$\nD_{\\Phi}(z,w_{t+1})\\ \\ge\\ D_{\\Phi}\\big(y_{t+1},w_{t+1}\\big)-\\Big(\\frac{1}{\\gamma_{t}}-1\\Big)D_{\\Phi}\\big(z,x_{1}\\big)+\\frac{1}{\\gamma_{t}}D_{\\Phi}\\big(z,x_{t+1}\\big).\\tag{17}\n$$\n\nPlugging this into (9) yields\n\n$$\n\\begin{array}{r l r}{{(9)\\ =\\ \\frac{1}{\\eta_{t}}\\Big(D_{\\Phi}\\big(x_{t},w_{t+1}\\big)-D_{\\Phi}\\big(z,w_{t+1}\\big)+D_{\\Phi}\\big(z,x_{t}\\big)\\Big)}}\\\\ &{}&{\\quad\\leq\\ \\frac{1}{\\eta_{t}}\\Bigg(D_{\\Phi}\\big(x_{t},w_{t+1}\\big)-D_{\\Phi}\\big(y_{t+1},w_{t+1}\\big)\\ +\\ }\\\\ &{}&{\\qquad\\Big(\\frac{1}{\\gamma_{t}}-1\\Big)D_{\\Phi}\\big(z,x_{1}\\big)-\\frac{1}{\\gamma_{t}}D_{\\Phi}\\big(z,x_{t+1}\\big)+D_{\\Phi}\\big(z,x_{t}\\big)\\Bigg).}\\end{array}\\tag{by (17)}\n$$\n\nThe claim follows by the definition of $\\gamma_{t}$ .\n\nThe final step is very similar to the proof of Theorem 3. The only differences are that we are using Claim 6 instead of Claim 4 and that we replace $D_{\\Phi}({}_{x_{t + 1}}^{x_{t}}; w_{t + 1})$ with $D_{\\Phi}({}_{y_{t + 1}}^{x_{t}}; w_{t + 1})$ . Formally, summing (9) over t and using Claim 6 leads to the desired telescoping sum, that is,\n\n$$\n\\begin{array}{r l}&{\\sum_{t=1}^{T}\\left(f_{t}(x_{t})-f_{t}(z)\\right)}\\\\ {\\leq}&{\\sum_{t=1}^{T}\\left(\\frac{D_{\\Phi}\\big({}_{y_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\Big(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\Big)D_{\\Phi}(z,x_{1})+\\frac{D_{\\Phi}(z,x_{t})}{\\eta_{t}}-\\frac{D_{\\Phi}\\big(z,x_{t+1}\\big)}{\\eta_{t+1}}\\right)}\\\\ {\\leq}&{\\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{y_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\Bigg(\\frac{1}{\\eta_{1}}+\\sum_{t=1}^{T}\\left(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\right)\\Bigg)D_{\\Phi}(z,x_{1})}\\\\ {=}&{\\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{y_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\frac{D_{\\Phi}(z,x_{1})}{\\eta_{T+1}}.}\\end{array}\n$$\n\n### Proof of Theorem 8\n\nProof [of Theorem 8]\n\nLet $z \\in \\mathcal{X}$ . The first step is very similar to the proof of Theorem 3.\n\n$$\n\\begin{array}{r l l}\nf_{t}(x_{t})-f_{t}(z)&\\leq\\ \\langle\\hat{g}_{t},x_{t}-z\\rangle&\\text{(subgradient ineq.)}\\\\\n&=\\ \\frac{1}{\\eta_{t}}\\langle\\hat{y}_{t}-\\hat{w}_{t+1},x_{t}-z\\rangle&\\text{(by (18))}\\\\\n&=\\ \\frac{1}{\\eta_{t}}\\Big(D_{\\Phi}(x_{t},w_{t+1})-D_{\\Phi}(z,w_{t+1})+D_{\\Phi}\\big({}_{x_{t}}^{z};y_{t}\\big)\\Big),\n\\end{array}\\tag{21}\n$$\n\nwhere in the last equation we have used Proposition 37 instead of Proposition 38.\n\nAs in the proof of Theorem 3, the next step is to relate $D_{\\Phi}(z,w_{t+1})$ to $D_{\\Phi}({}_{x_{t + 1}}^{z}; y_{t + 1})$ so that (21) can be bounded using a telescoping sum. The following claim is similar to Claim 4.\n\nClaim 9 Assume that $\\gamma_{t}=\\eta_{t+1}/\\eta_{t}\\in(0,1]$ . Then\n\n$$\n(21)~\\le~\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\underbrace{\\left(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\right)}_{telescopes}D_{\\Phi}(z,x_{1})+\\underbrace{\\frac{D_{\\Phi}\\big({}_{x_{t}}^{z};y_{t}\\big)}{\\eta_{t}}-\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{z};y_{t+1}\\big)}{\\eta_{t+1}}}_{telescopes}.\n$$\n\nProof The first two steps are identical to the proof of Claim 4.\n\n$$\n\\begin{array}{r l}&{\\gamma_{t}\\big(D_{\\Phi}(z,w_{t+1})-D_{\\Phi}(x_{t+1},w_{t+1})\\big)\\ : +\\ :(1-\\gamma_{t})D_{\\Phi}(z,x_{1})}\\\\ {\\ge}&{\\gamma_{t}D_{\\Phi}\\big({}_{x_{t+1}}^{z};w_{t+1}\\big)\\ : +\\ :(1-\\gamma_{t})D_{\\Phi}\\big({}_{x_{t+1}}^{z};x_{1}\\big)\\qquad\\mathrm{(since~}D_{\\Phi}(x_{t+1},x_{1})\\ge 0\\mathrm{~and~}\\gamma_{t}\\le 1\\big)}\\\\ {=}&{D_{\\Phi}\\big({}_{x_{t+1}}^{z};y_{t+1}\\big)\\qquad\\quad\\mathrm{(by~Proposition~39~and~(19)).}}\\end{array}\n$$\n\nRearranging and using $\\gamma_{t}> 0$ yields\n\n$$\nD_{\\Phi}(z,w_{t+1})\\ \\ge\\ D_{\\Phi}(x_{t+1},w_{t+1})\\ -\\ \\Big(\\frac{1}{\\gamma_{t}}-1\\Big)D_{\\Phi}(z,x_{1})\\ +\\ \\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{z};y_{t+1}\\big)}{\\gamma_{t}}.\\tag{22}\n$$\n\nPlugging this into (21) yields\n\n$$\n\\begin{array}{r c l}{(21)}&{=}&{\\displaystyle\\frac{1}{\\eta_{t}}\\Big(D_{\\Phi}\\big(x_{t},w_{t+1}\\big)-D_{\\Phi}\\big(z,w_{t+1}\\big)+D_{\\Phi}\\big({}_{x_{t}}^{z};y_{t}\\big)\\Big)}\\\\ &{\\leq}&{\\displaystyle\\frac{1}{\\eta_{t}}\\Bigg(D_{\\Phi}\\big(x_{t},w_{t+1}\\big)-D_{\\Phi}\\big(x_{t+1},w_{t+1}\\big)+}\\\\ &&{\\displaystyle\\qquad\\Big(\\frac{1}{\\gamma_{t}}-1\\Big)D_{\\Phi}\\big(z,x_{1}\\big)-\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{z};y_{t+1}\\big)}{\\gamma_{t}}+D_{\\Phi}\\big({}_{x_{t}}^{z};y_{t}\\big)\\Bigg),}\\end{array}\\tag{by (22).}\n$$\n\nThe claim follows by the definition of $\\gamma_{t}$\n\nAgain the final step is very similar to the proof of Theorem 3. Summing (21) over t and using Claim 9 leads to the desired telescoping sum.\n\n$$\n\\begin{array}{r l}&{\\displaystyle\\sum_{t=1}^{T}\\left(f_{t}(x_{t})-f_{t}(z)\\right)}\\\\ {\\le}&{\\displaystyle\\sum_{t=1}^{T}\\left(\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\Big(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\Big)D_{\\Phi}(z,x_{1})+\\frac{D_{\\Phi}\\big({}_{x_{t}}^{z};y_{t}\\big)}{\\eta_{t}}-\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{z};y_{t+1}\\big)}{\\eta_{t+1}}\\right)}\\\\ {\\le}&{\\displaystyle\\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\left(\\frac{1}{\\eta_{1}}+\\displaystyle\\sum_{t=1}^{T}\\left(\\frac{1}{\\eta_{t+1}}-\\frac{1}{\\eta_{t}}\\right)\\right)D_{\\Phi}(z,x_{1})}\\\\ {=}&{\\displaystyle\\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\frac{D_{\\Phi}(z,x_{1})}{\\eta_{T+1}},}\\end{array}\n$$\n\nwhere for the second inequality we have also used that $D_{\\Phi}({}_{x_{1}}^{z};y_{1})=D_{\\Phi}(z,x_{1})$ since $x_{1}= y_{1}$ . Thus, the above shows that\n\n$$\n\\mathrm{Regret}(T,z)\\ \\leq\\ \\sum_{t=1}^{T}\\frac{D_{\\Phi}\\big({}_{x_{t+1}}^{x_{t}};w_{t+1}\\big)}{\\eta_{t}}+\\frac{D_{\\Phi}\\big(z,x_{1}\\big)}{\\eta_{T+1}}\\quad\\forall T>0 .\\tag{23}\n$$\n\nNotice that (23) is syntactically identical to (8); the only difference is the definition of $w_{t + 1}$ in these two settings. However, in this section the definition of $x_{t}$ has not yet been used! Doing so will provide an upper bound on (23), which is the conclusion of this theorem. To control $D_{\\Phi}({}_{x_{t + 1}}^{x_{t}}; w_{t + 1})$ , we will apply Proposition 41 as follows. Taking $p = y_{t}$ , $\\pi=x_{t}=\\Pi_{\\mathcal{X}}^{\\Phi}(y_{t}),v=x_{t+1}$ and $\\hat{q}= \\eta_{t}g_{t}$ , we obtain\n\n$$\n\\begin{array}{r l}{D_{\\Phi}({}_{x_{t+1}}^{x_{t}};w_{t+1})=}&{-D_{\\Phi}({}_{\\pi}^{v};\\nabla\\Phi^{*}(\\hat{p}-\\hat{q}))\\qquad\\mathrm{(since~}\\hat{w}_{t+1}=\\hat{y}_{t}-\\eta_{t}\\hat{g}_{t}=\\hat{p}-\\hat{q})}\\\\ {\\le}&{-D_{\\Phi}({}_{\\pi}^{v};\\nabla\\Phi^{*}(\\hat{\\pi}-\\hat{q}))\\qquad\\mathrm{(by~Proposition~41)}}\\\\ {=}&{D_{\\Phi}({}_{x_{t+1}}^{x_{t}};\\nabla\\Phi^{*}(\\hat{x}_{t}-\\eta_{t}\\hat{g}_{t})).}\\end{array}\n$$\n\nPlugging this into (23) completes the proof.", "context": [{"id": "v23-21-1027:ctx1", "name": "Setup: online convex optimization and regret (Section 3)", "statement": "We consider the online convex optimization problem with unknown time horizon. For each time step $t\\in\\{1,2,\\ldots\\}$ the algorithm proposes a point $x_{t}$ from a closed convex set ${\\mathcal{X}}\\subseteq \\mathbb{R}^{n}$ and an adversary simultaneously picks a convex cost function $f_{t}$ which the algorithm has access to via a first-order oracle, that is, for any $x \\in \\mathcal{X}$ the algorithm can compute $f_{t}(x)$ and a subgradient $\\hat{g}\\in\\partial f_{t}(x): =\\{\\hat{g}\\in\\mathbb{R}^{n}\\mid f_{t}(z)\\geq f_{t}(x)+\\langle\\hat{g},z-x\\rangle\\forall z\\in\\mathcal{X}\\}$ . We will assume1 that all cost functions $f_{t}$ in this text are subdifferentiable on $\\mathcal{X}$ , that is, meaning that the subdifferential $\\partial f_{t}(x)$ is non-empty for all $x \\in \\mathcal{X}$\n\nThe cost of the iteration at time t is defined as $f_{t}(x_{t})$ . In this setting the goal is to produce a sequence of proposals $\\{x_{t}\\}_{t \\ge 1}$ that minimizes the regret against an unknown comparison point $z \\in \\mathcal{X}$ that has accrued up until time $T$:\n\n$$\n\\mathrm{Regret}(T,z): =\\ \\sum_{t=1}^{T}f_{t}(x_{t})-\\sum_{t=1}^{T}f_{t}(z).\n$$"}, {"id": "v23-21-1027:ctx2", "name": "Standing assumptions on the mirror map Φ and hat notation (1) (Section 3)", "statement": "Both dual averaging and online mirror descent are parameterized by a special convex function $\\Phi,$ often referred as a regularizer or a mirror map (for D and X), which among other properties needs$^{2}$ to be of Legendre type (Rockafellar, 1970, Chapter 26). Formally, throughout the paper we assume that the function $\\Phi\\colon \\bar{\\mathcal{D}}\\to \\mathbb{R}$ is a closed convex function whose conjugate is differentiable on $\\mathbb{R}^{n}$ and such that $\\bar{\\mathcal{D}}$ satisfies $\\mathcal{X}\\subseteq \\bar{\\mathcal{D}}$ and $\\mathrm{int}\\,\\bar{\\mathcal{D}}\\cap \\mathrm{ri}\\,\\mathcal{X}\\neq \\varnothing$ (where $\\mathrm{ri}\\,\\mathcal{X}$ denotes the relative interior of $\\mathcal{X}$). Moreover, we also suppose that $\\Phi$ is of Legendre type, which means that $\\Phi$ is strictly convex on its domain$^{3}$ and essentially smooth, that is, for $\\mathcal{D}: =\\mathrm{int}\\bar{\\mathcal{D}}$ we have\n\n$\\mathcal{D}$ is nonempty,\n\n$\\Phi$ is differentiable on $\\mathcal{D}$, and\n\n$\\lim_{x\\to\\partial\\mathcal{D}}\\|\\nabla\\Phi(x)\\|= +\\infty$ , where ∂D is the boundary of $\\mathcal{D},\\mathrm{i.e.,}\\partial\\mathcal{D}: =\\mathrm{cl}\\mathcal{D}\\backslash\\mathcal{D}$\n\nThe gradient of the mirror map $\\nabla \\Phi :{\\mathcal{D}}\\to \\mathbb{R}^{n}$ and the gradient of its conjugate $\\nabla \\Phi^{*}: \\mathbb{R}^{n}\\to \\mathcal{D}$ are mutually inverse bijections between the primal space $\\mathcal{D}$ and the dual space $\\mathbb{R}^{n}$ . We will adopt the following notational convention. Any vector in the primal space will be written without a hat, such as $x \\in \\mathcal{D}$ . The same letter with a hat, namely $\\hat{x}$, will denote the corresponding dual vector:\n\n$$\n{\\hat{x}}: =\\nabla\\Phi(x)\\qquad{\\mathrm{and}}\\qquad x: =\\nabla\\Phi^{*}({\\hat{x}})\\qquad{\\mathrm{f o r~a l l~l e t t e r s~}}x .\\tag{1}\n$$"}, {"id": "v23-21-1027:ctx3", "name": "Essential smoothness and well-posedness of the Bregman projection (Section 3)", "statement": "Essential smoothness ensures not only that $\\Phi$ is differentiable on the interior of its domain, but also that the slope of $\\Phi$ increases arbitrarily fast near the boundary of its domain. The latter guarantees, at least intuitively, that the function is increasing near and in the direction of the boundary of its domain. This property is fundamental for mirror descent to be well-defined (although not essential for dual averaging) since it ensures that the Bregman projection onto $\\mathcal{X}$ is attained by a point on $\\mathcal{D}$ where Φ is differentiable (we give more details on this on Section 7), and uniqueness is a consequence of the strict convexity of Φ. Some mirror maps we shall look at are classical cases of the OCO literature such as the negative entropy $x \\in \\mathbb{R}_{+}^{n}\\mapsto \\sum_{i = 1}^{n} x_{i}\\ln x_{i}$ and the squared 2-norm ${\\frac{1}{2}}\\|\\cdot\\|_{2}^{2}$ , and details on the reasons they are mirror maps can be found in the works of Shalev-Shwartz (2012); Bubeck (2011) and Bubeck (2015) (in particular, Bubeck, 2011, Section 5.2 discusses the properties of functions of Legendre type and why requiring the conjugate of the mirror map to be differentiable on the whole space is not necessary for mirror descent to be well-defined if one restricts the gradient steps in the dual space in some way)."}, {"id": "v23-21-1027:ctx4", "name": "Definition: Bregman divergence (2), difference notation (3) and Bregman projection", "statement": "Given a mirror map $\\Phi,$ the Bregman divergence with respect to $\\Phi$ is defined as\n\n$$\nD_{\\Phi}(x,y)\\ : =\\ \\Phi(x)-\\Phi(y)-\\langle\\nabla\\Phi(y),x-y\\rangle,\\qquad\\forall x\\in\\bar{\\mathcal{D}},\\forall y\\in\\mathcal{D}.\\tag{2}\n$$\n\nThroughout this paper it will be convenient to use the notation\n\n$$\nD_{\\Phi}({}_{b}^{a};c): =D_{\\Phi}(a,c)-D_{\\Phi}(b,c)=\\Phi(a)-\\Phi(b)-\\langle\\nabla\\Phi(c),a-b\\rangle .\\tag{3}\n$$\n\nIn the important special case where $\\begin{array}{r}{\\Phi(x)=\\frac{1}{2}\\|x\\|_{2}^{2}}\\end{array}$ , the Bregman divergence relates to the Euclidean distance, i.e., $\\begin{array}{r}{D_{\\Phi}(x,y)=\\frac 12\\|x-y\\|_{2}^{2}}\\end{array}$ When $\\begin{array}{r}{\\Phi(x)=\\sum_{i=1}^{n}x_{i}\\log x_{i}}\\end{array}$ , the Bregman divergence becomes the generalized Kullback-Leibler (KL) divergence. The projection operator induced by the Bregman divergence is $\\Pi_{\\mathcal{X}}^{\\Phi}$ given by $\\{\\Pi_{\\mathcal{X}}^{\\Phi}\\}(y): =\\arg\\min\\{D_{\\Phi}(x,y)\\mid x\\in\\mathcal{X}\\}$ for any $y \\in \\mathcal{X}\\cap \\mathcal{D}$"}, {"id": "v23-21-1027:ctx5", "name": "Algorithm 1: generic OMD / DA template", "statement": "A general template for optimization in the mirror descent framework is shown in Algorithm 1. The two classical algorithms, online mirror descent and dual averaging, are incarnations of this, differing only in how the dual variable $\\hat{y}_{t}$ is updated.\n\nIn this work, for a given initial point $x_{1}\\in{\\mathcal{X}}$ of the player, we are interested in the case when $\\begin{array}{r}{\\operatorname*{sup}_{z\\in\\mathcal{X}}D_{\\Phi}(z,x_{1})}\\end{array}$ is bounded, which still allows $\\sup_{z,x\\in{\\mathcal{X}}}D_{\\Phi}(z,x)$ to be unbounded. In fact, in the Euclidean setting $\\begin{array}{r}{(\\mathrm{i . e .,}\\Phi=\\frac{1}{2}\\|\\cdot\\|_{2}^{2}),\\operatorname*{sup}_{z\\in\\mathcal{X}}D_{\\Phi}(z,x_{1})}\\end{array}$ is bounded if and only if the diameter of X given by $\\sup_{x,y\\in\\mathcal{X}}\\frac{1}{2}\\Vert x-y\\Vert_{2}^{2}$ is also bounded. However, for a general mirror map $\\Phi$, assuming $\\begin{array}{r}{\\operatorname*{sup}_{z\\in\\mathcal{X}}D_{\\Phi}(z,x_{1})}\\end{array}$ is bounded is strictly weaker than assuming $\\scriptstyle\\operatorname*{sup}_{x,y\\in{\\mathcal{X}}}D_{\\Phi}(x,y)$ is bounded. This is the case for the well-known experts' problem, where Φ is the negative entropy, $D_{\\Phi}$ is the KL-divergence, X is the unit simplex $\\Delta_{n}: =\\{p\\in [0,1]^{n}:\\textstyle\\sum_{i=1}^{n}p_{i}=1\\}$ , and $\\begin{array}{r}{x_{1}: = \\frac{1}{n}\\vec{1},}\\end{array}$ where $\\vec{1}$ is the vector in $\\mathbb{R}^{n}$ with entries all set to 1. In this case, we have $\\sup_{z\\in\\mathcal{X}}D_{\\Phi}(z,x_{1})\\leq\\ln n$ while $\\begin{array}{r}{\\operatorname*{sup}_{z,x\\in\\mathcal{X}}D_{\\Phi}(z,x)= +\\infty}\\end{array}$ .\n\nTo conclude, throughout the paper we shall try to stick to the following naming convention: greek letters will denote scalars, lower-case roman letters will denote vectors, $\\mathrm{e.g.},x,y$ ,and capital calligraphic letters shall denote sets, $\\mathrm{e . g .}, \\mathcal{X}, \\mathcal{Y}$ . Any deviations from this convention (or the hat notation as in (1)) are intended to follow other conventions in the literature.\n\nAlgorithm 1 Pseudocode for both online mirror descent and dual averaging with adaptive \nlearning rate given by $\\eta_{t}$ on iteration t. These methods differ only in how the iterate $\\hat{y}_{t + 1}$ is \nupdated. \nInput: $x_{1}\\in \\mathcal{X}\\cap \\mathcal{D}, \\eta : \\mathbb{N}\\to \\mathbb{R}_{> 0}$ \nfor $t=1,2,\\dots$ do \nIncur cost $f_{t}(x_{t})$ and receive $\\hat{g}_{t}\\in\\partial f_{t}(x_{t})$ \n$\\hat{x}_{t}=\\nabla\\Phi(x_{t})$ \n[OMD update] $\\hat{y}_{t + 1}= \\hat{x}_{t}- \\eta_{t}\\hat{g}_{t}$ \n[DA update] $\\begin{array}{r}{\\hat{y}_{t + 1}= \\hat{x}_{1}- \\eta_{t}\\sum_{i \\leq t}\\hat{g}_{i}}\\end{array}$ \n$\\boldsymbol{y}_{t+1}=\\nabla\\Phi^{*}(\\hat{\\boldsymbol{y}}_{t+1})$ \n$x_{t+1}=\\Pi_{\\mathcal{X}}^{\\Phi}(y_{t+1})$ \nend for"}, {"id": "v23-21-1027:ctx6", "name": "Algorithm 2: dual-stabilized OMD, eqs. (5)-(7)", "statement": "Algorithm 2 Dual-stabilized OMD (DS-OMD). The parameters $\\gamma_{t}$ control the amount of \nstabilization. \nInput: $x_{1}\\in\\mathcal{X}\\cap\\mathcal{D},\\eta:\\mathbb{N}\\to\\mathbb{R}_{+},\\ \\gamma:\\mathbb{N}\\to(0,1]$ \nfor $t=1,2,\\dots$ do \nIncur cost $f_{t}(x_{t})$ and receive $\\hat{g}_{t}\\in\\partial f_{t}(x_{t})$ \n$\\hat{x}_{t}=\\nabla\\Phi(x_{t})$ map primal iterate to dual space \n$\\hat{w}_{t + 1}= \\hat{x}_{t}- \\eta_{t}\\hat{g}_{t}$ gradient step in dual space (5) \n$\\hat{y}_{t+1}=\\gamma_{t}\\hat{w}_{t+1}+(1-\\gamma_{t})\\hat{x}_{1}$ stabilization in dual space (6) \n$\\boldsymbol{y}_{t+1}=\\nabla\\Phi^{*}(\\hat{\\boldsymbol{y}}_{t+1})$ map dual iterate to primal space \n$x_{t+1}=\\Pi_{\\mathcal{X}}^{\\Phi}(y_{t+1})$ project onto feasible region (7) \nend for"}, {"id": "v23-21-1027:ctx7", "name": "Proposition 38 (generalized triangle inequality)", "statement": "An immediate consequence is the \"generalized triangle inequality for Bregman divergence\", such as in Bubeck (2015, Eq. (4.1)) or in Beck and Teboulle (2003, Lemma 4.1).\n\nProposition 38 For all $a,b,d\\in{\\mathcal{D}}$\n\n$$\nD_{\\Phi}(a,d)-D_{\\Phi}(b,d)+D_{\\Phi}(b,a)\\ =\\ \\langle\\hat{a}-\\hat{d},a-b\\rangle\n$$"}, {"id": "v23-21-1027:ctx8", "name": "Proposition 39", "statement": "Proposition 39 Let $a,b,c,u,v\\in\\mathbb{R}^{n}$ satisfy $\\gamma\\hat{a}+(1-\\gamma)\\hat{b}=\\hat{c}$ for some $\\gamma \\in \\mathbb{R}$ . Then\n\n$$\n\\gamma D_{\\Phi}({}_{v}^{u};a)\\ : +\\ :(1-\\gamma)D_{\\Phi}({}_{v}^{u};b)\\ : =\\ :D_{\\Phi}({}_{v}^{u};c).\n$$"}, {"id": "v23-21-1027:ctx9", "name": "Proposition 40 (Pythagorean theorem for Bregman divergence)", "statement": "The following proposition is the \"Pythagorean theorem for Bregman divergence\". Recall that $\\Pi_{\\mathcal{X}}^{\\Phi}(y)=\\arg\\operatorname*{min}_{u\\in\\mathcal{X}}D_{\\Phi}(u,y)$ . A proof may be found in Bubeck (2015, Lemma 4.1).\n\nProposition 40 Let $\\mathcal{X}\\subset \\mathbb{R}^{n}$ be a convex set. Let $p \\in \\mathbb{R}^{n}$ and $\\pi=\\Pi_{\\mathcal{X}}^{\\Phi}(p)$ . Then\n\n$$\nD_{\\Phi}({}_{\\pi}^{z};p)\\geq D_{\\Phi}({}_{\\pi}^{z};\\pi)=D_{\\Phi}(z,\\pi)\\forall z\\in\\mathcal{X}.\n$$"}, {"id": "v23-21-1027:ctx10", "name": "Algorithm 3: primal-stabilized OMD, eqs. (11)-(14)", "statement": "Algorithm 3 Online mirror descent with primal stabilization. \nInput: $x_{1}\\in \\mathcal{X}\\cap \\mathcal{D}, \\eta : \\mathbb{N}\\to \\mathbb{R}, \\gamma : \\mathbb{N}\\to \\mathbb{R}.$ \nfor $t=1,2,\\dots$ do \nIncur cost $f_{t}(x_{t})$ and receive $\\hat{\\boldsymbol g}_{t}\\in\\partial f_{t}(\\boldsymbol x_{t})$ \n$\\hat{x}_{t}=\\nabla\\Phi(x_{t})$ map primal iterate to dual space \n$\\hat{w}_{t + 1}= \\hat{x}_{t}- \\eta_{t}\\hat{g}_{t}$ gradient step in dual space (11) \n$\\boldsymbol{w}_{t+1}=\\nabla\\Phi^{*}(\\hat{\\boldsymbol{w}}_{t+1})$ map dual iterate to primal space (12) \n$y_{t+1}=\\Pi_{\\mathcal{X}}^{\\Phi}(w_{t+1})$ project onto feasible region (13) \n$x_{t+1}=\\gamma_{t}y_{t+1}+(1-\\gamma_{t})x_{1}$ stabilization in primal space (14) \nend for"}, {"id": "v23-21-1027:ctx11", "name": "Setup: lazy gradient step (18), stabilization (19) and Claim 7 (Section 5.3)", "statement": "In this section, we show that Nesterov's dual averaging algorithm can be obtained from a small modification to dual-stabilized online mirror descent. Furthermore, our proof of Theorem 3 can be adapted to analyze DA.\n\nThe main difference between DS-OMD and dual averaging is in the gradient step, as we now explain. In iteration t of DS-OMD, the gradient step in (5) is taken from $\\hat{x}_{t}$ ,the dual counterpart of the iterate $x_{t}\\colon$\n\n$$\n\\mathrm{D S - O M D \\ g r a d i e n t \\ s t e p}: \\quad \\hat{w}_{t + 1}= \\hat{x}_{t}- \\eta_{t}\\hat{g}_{t}.\n$$\n\nSuppose that the algorithm is modified so that the gradient step is taken from $\\hat{y}_{t}$ , the dual point from iteration t before projection onto the feasible region. (Here $\\hat{y}_{1}$ is defined to be $\\hat{x}_{1}$.) The resulting gradient step is:\n\n$$\n\\mathrm{L a z y ~ g r a d i e n t ~ s t e p}\\colon \\hat{w}_{t + 1}= \\hat{y}_{t}- \\eta_{t}\\hat{g}_{t}.\\tag{18}\n$$\n\nAs before, we set\n\n$$\n\\hat{y}_{t+1}~=~\\gamma_{t}\\hat{w}_{t+1}+(1-\\gamma_{t})\\hat{x}_{1}\\tag{19}\n$$\n\nwhere $\\gamma_{t}= \\eta_{t + 1}/ \\eta_{t}$ . Then a simple inductive proof yields the following claim.\n\nClaim 7 $\\hat{w}_{t}= \\hat{x}_{1}- \\eta_{t - 1}\\sum_{i < t}\\hat{g}_{i}$ and $\\hat{y}_{t}= \\hat{x}_{1}- \\eta_{t}\\sum_{i < t}\\hat{g}_{i}$ for all $t > 1$.\n\nThus, the algorithm with the lazy gradient step can be written as in Algorithm 4. This is equivalent to Algorithm 1 with the DA update, except that $\\eta_{t}$ in Algorithm 1 corresponds to $\\eta_{t + 1}$ in Algorithm 4. In the next theorem we analyze DA with similar techniques to the ones used in Theorems 3 and 5."}, {"id": "v23-21-1027:ctx12", "name": "Algorithm 4: dual averaging with re-indexed learning rate", "statement": "Algorithm 4 Dual averaging with learning rate re-indexed as $\\eta_{2}, \\eta_{3}, \\ldots$ \nInput: $x_{1}\\in\\mathcal{X}\\cap\\mathcal{D},~\\eta:\\mathbb{N}\\to\\mathbb{R}_{+},~\\gamma:\\mathbb{N}\\to(0,1]$ \n$\\hat{y}_{1}=\\nabla\\Phi(x_{1})$ \nfor $t=1,2,\\dots$ do \nIncur cost $f_{t}(x_{t})$ and receive $\\hat{g}_{t}\\in\\partial f_{t}(x_{t})$ \n$\\begin{array}{r}{\\hat{y}_{t + 1}= \\hat{x}_{1}- \\eta_{t + 1}\\sum_{i \\leq t}\\hat{g}_{i}}\\end{array}$ dual averaging update \n$\\boldsymbol{y}_{t+1}=\\nabla\\Phi^{*}(\\hat{\\boldsymbol{y}}_{t+1})$ map dual iterate to primal space \n$x_{t+1}=\\Pi_{\\mathcal{X}}^{\\Phi}(y_{t+1})$ project onto feasible region \nend for"}, {"id": "v23-21-1027:ctx13", "name": "Proposition 36 (linearity of D_Φ(^a_b; p) in p̂)", "statement": "Recall that in (3) we defined the notation\n\n$$\nD_{\\Phi}({}_{b}^{a};c): =D_{\\Phi}(a,c)-D_{\\Phi}(b,c)=\\Phi(a)-\\Phi(b)-\\langle\\nabla\\Phi(c),a-b\\rangle .\n$$\n\nThis has several useful properties, which we now discuss.\n\nProposition 36 $D_{\\Phi}({}_{b}^{a}; p)$ is linear in $\\hat{p}$. In particular,\n\n$$\nD_{\\Phi}\\big({}_{b}^{a};\\nabla\\Phi^{*}(\\widehat{p}-\\widehat{q})\\big)\\ =\\ D_{\\Phi}\\big({}_{b}^{a};p\\big)+\\big\\langle\\widehat{q},a-b\\big\\rangle\\qquad\\forall\\widehat{q}\\in\\mathbb{R}^{n}.\n$$"}, {"id": "v23-21-1027:ctx14", "name": "Proposition 37", "statement": "Proposition 37 For all $a,b,c,d\\in\\mathcal{D}$\n\n$$\nD_{\\Phi}\\big({}_{b}^{a};d\\big)-D_{\\Phi}\\big({}_{b}^{a};c\\big)=\\langle\\hat{c}-\\hat{d},a-b\\rangle=D_{\\Phi}\\big({}_{b}^{a};d\\big)+D_{\\Phi}\\big({}_{a}^{b};c\\big).\n$$"}, {"id": "v23-21-1027:ctx15", "name": "Proposition 41", "statement": "A generalization of the previous proposition can be obtained by using linearity.\n\nProposition 41 Let $\\mathcal{X}\\subset \\mathbb{R}^{n}$ be a convex set. Let $p \\in \\mathbb{R}^{n}$ and $\\pi=\\Pi_{\\mathcal{X}}^{\\Phi}(p)$ . Then\n\n$$\nD_{\\Phi}\\big({}_{\\pi}^{v};\\nabla\\Phi^{*}({\\widehat{p}}-{\\widehat{q}})\\big)\\ \\geq\\ D_{\\Phi}\\big({}_{\\pi}^{v};\\nabla\\Phi^{*}({\\widehat{\\pi}}-{\\widehat{q}})\\big)\\qquad\\forall v\\in\\mathcal{X},{\\widehat{q}}\\in\\mathbb{R}^{n}.\n$$"}, {"id": "v23-21-1027:ctx16", "name": "Lemma 34 (basic properties of the mirror map and Bregman divergence)", "statement": "The following lemma collects basic facts regarding the a mirror map Φ (or simply a function of Legendre type) and the Bregman divergence it induces. See Cesa-Bianchi and Lugosi (2006, Lemma 11.5 and Proposition 11.1).\n\nLemma 34 The mirror map $\\Phi$ and the Bregman divergence it induces satisfy the following properties:\n\n$D_{\\Phi}(x,y)$ is convex in x.\n\n$\\nabla\\Phi(\\nabla\\Phi^{*}(z))=z$ and $\\nabla^{*}\\Phi(\\nabla\\Phi(x))=x$ for all x and z.\n\n$D_{\\Phi}(x,y)=D_{\\Phi^{*}}\\bigl(\\nabla\\Phi(y),\\nabla\\Phi(x)\\bigr)$ for all x and $y$"}], "lean": "import Mathlib\n\nopen scoped RealInnerProductSpace BigOperators\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]\n\nnoncomputable def bregman (Φ : E → ℝ) (gΦ : E → E) (x y : E) : ℝ :=\n Φ x - Φ y - (@inner ℝ E _ (gΦ y) (x - y))\n\nnoncomputable def regret (f : ℕ → E → ℝ) (x : ℕ → E) (z : E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 1 T, (f t (x t) - f t z)\n\nstructure PaperNorm (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] where\n nrm : E → ℝ\n nonneg : ∀ x, 0 ≤ nrm x\n eq_zero_iff : ∀ x, nrm x = 0 ↔ x = 0\n smul : ∀ (c : ℝ) (x : E), nrm (c • x) = |c| * nrm x\n triangle : ∀ x y, nrm (x + y) ≤ nrm x + nrm y\n\nnoncomputable def dualNorm (N : PaperNorm E) (z : E) : ℝ :=\n sSup {v : ℝ | ∃ x : E, N.nrm x ≤ 1 ∧ v = (@inner ℝ E _ z x)}\n\ntheorem theorem3\n (Φ : E → ℝ) (gΦ gΦs : E → E)\n (X : Set E)\n (D : Set E) (hDconv : Convex ℝ D)\n (hXD : X ⊆ closure D)\n (hDX : (D ∩ intrinsicInterior ℝ X).Nonempty)\n (hΦstrict : StrictConvexOn ℝ D Φ)\n (hΦgrad : ∀ a ∈ D, HasGradientWithinAt Φ (gΦ a) D a)\n (η : ℕ → ℝ) (hηpos : ∀ t, 1 ≤ t → 0 < η t) (hηmono : ∀ t, 1 ≤ t → η (t + 1) ≤ η t)\n (f : ℕ → E → ℝ)\n (x w : ℕ → E) (g : ℕ → E)\n (proj : E → E)\n\n (hXconv : Convex ℝ X)\n\n (hfsubdiff : ∀ t, 1 ≤ t → ∀ u ∈ X, ∃ gu : E, ∀ v ∈ X, f t v ≥ f t u + (@inner ℝ E _ gu (v - u)))\n\n (hXclosed : IsClosed X)\n\n (hfconv : ∀ t, 1 ≤ t → ConvexOn ℝ X (f t))\n\n (hinv : ∀ v : E, gΦ (gΦs v) = v)\n (hinvD : ∀ a ∈ D, gΦs (gΦ a) = a)\n\n (hΦconv : ConvexOn ℝ X Φ)\n (hΦsub : ∀ a ∈ D, ∀ b ∈ X, Φ b ≥ Φ a + (@inner ℝ E _ (gΦ a) (b - a)))\n (hgΦsD : ∀ v : E, gΦs v ∈ D)\n\n (hprojX : ∀ y : E, proj y ∈ X) (hprojD : ∀ y : E, proj y ∈ D)\n\n (hprojDef : ∀ v ∈ D, ∀ u ∈ X, bregman Φ gΦ (proj v) v ≤ bregman Φ gΦ u v)\n\n (hx1 : x 1 ∈ X) (hx1D : x 1 ∈ D)\n\n (hsub : ∀ t, 1 ≤ t → ∀ u ∈ X, f t (x t) - f t u ≤ (@inner ℝ E _ (g t) (x t - u)))\n\n (hw : ∀ t, 1 ≤ t → w (t + 1) = gΦs (gΦ (x t) - η t • g t))\n\n (hx : ∀ t, 1 ≤ t →\n x (t + 1) =\n proj (gΦs ((η (t + 1) / η t) • (gΦ (x t) - η t • g t)\n + (1 - η (t + 1) / η t) • gΦ (x 1))))\n\n (hpyth : ∀ z ∈ X, ∀ y ∈ D,\n bregman Φ gΦ z (proj y) ≤ bregman Φ gΦ z y - bregman Φ gΦ (proj y) y)\n (T : ℕ) (hT : 1 ≤ T) (z : E) (hz : z ∈ X) :\n regret f x z T\n ≤ (∑ t ∈ Finset.Icc 1 T,\n (bregman Φ gΦ (x t) (w (t + 1)) - bregman Φ gΦ (x (t + 1)) (w (t + 1))) / η t)\n + bregman Φ gΦ z (x 1) / η (T + 1) := by\n sorry\n\ntheorem theorem5\n (Φ : E → ℝ) (gΦ gΦs : E → E)\n (X : Set E)\n (D : Set E) (hDconv : Convex ℝ D)\n (hXD : X ⊆ closure D)\n (hDX : (D ∩ intrinsicInterior ℝ X).Nonempty)\n (hΦstrict : StrictConvexOn ℝ D Φ)\n (hΦgrad : ∀ a ∈ D, HasGradientWithinAt Φ (gΦ a) D a)\n (η : ℕ → ℝ) (hηpos : ∀ t, 1 ≤ t → 0 < η t) (hηmono : ∀ t, 1 ≤ t → η (t + 1) ≤ η t)\n (f : ℕ → E → ℝ)\n (x y w : ℕ → E) (g : ℕ → E)\n (proj : E → E)\n\n (hXconv : Convex ℝ X)\n\n (hfsubdiff : ∀ t, 1 ≤ t → ∀ u ∈ X, ∃ gu : E, ∀ v ∈ X, f t v ≥ f t u + (@inner ℝ E _ gu (v - u)))\n\n (hinv : ∀ v : E, gΦ (gΦs v) = v)\n (hinvD : ∀ a ∈ D, gΦs (gΦ a) = a)\n\n (hΦconv : ConvexOn ℝ X Φ)\n (hΦsub : ∀ a ∈ D, ∀ b ∈ X, Φ b ≥ Φ a + (@inner ℝ E _ (gΦ a) (b - a)))\n (hgΦsD : ∀ v : E, gΦs v ∈ D)\n\n (hXclosed : IsClosed X)\n\n (hprojX : ∀ v : E, proj v ∈ X) (hprojD : ∀ v : E, proj v ∈ D)\n\n (hprojDef : ∀ v ∈ D, ∀ u ∈ X, bregman Φ gΦ (proj v) v ≤ bregman Φ gΦ u v)\n\n (hfconv : ∀ t, 1 ≤ t → ConvexOn ℝ X (f t))\n\n (hx1 : x 1 ∈ X) (hx1D : x 1 ∈ D)\n\n (hsub : ∀ t, 1 ≤ t → ∀ u ∈ X, f t (x t) - f t u ≤ (@inner ℝ E _ (g t) (x t - u)))\n\n (hw : ∀ t, 1 ≤ t → w (t + 1) = gΦs (gΦ (x t) - η t • g t))\n\n (hy : ∀ t, 1 ≤ t → y (t + 1) = proj (w (t + 1)))\n\n (hx : ∀ t, 1 ≤ t →\n x (t + 1) = (η (t + 1) / η t) • y (t + 1) + (1 - η (t + 1) / η t) • x 1)\n\n (hpyth : ∀ z ∈ X, ∀ v ∈ D,\n bregman Φ gΦ z (proj v) ≤ bregman Φ gΦ z v - bregman Φ gΦ (proj v) v)\n\n (hDconvex : ∀ z ∈ X, ConvexOn ℝ (X ∩ D) (fun u => bregman Φ gΦ z u))\n (T : ℕ) (hT : 1 ≤ T) (z : E) (hz : z ∈ X) :\n regret f x z T\n ≤ (∑ t ∈ Finset.Icc 1 T,\n (bregman Φ gΦ (x t) (w (t + 1)) - bregman Φ gΦ (y (t + 1)) (w (t + 1))) / η t)\n + bregman Φ gΦ z (x 1) / η (T + 1) := by\n sorry\n\ntheorem theorem8\n (Φ : E → ℝ) (gΦ gΦs : E → E)\n (X : Set E)\n (D : Set E) (hDconv : Convex ℝ D)\n (hXD : X ⊆ closure D)\n (hDX : (D ∩ intrinsicInterior ℝ X).Nonempty)\n (hΦstrict : StrictConvexOn ℝ D Φ)\n (hΦgrad : ∀ a ∈ D, HasGradientWithinAt Φ (gΦ a) D a)\n (η : ℕ → ℝ) (hηpos : ∀ t, 1 ≤ t → 0 < η t) (hηmono : ∀ t, 1 ≤ t → η (t + 1) ≤ η t)\n (f : ℕ → E → ℝ)\n (x y : ℕ → E) (g : ℕ → E)\n (proj : E → E)\n\n (hXconv : Convex ℝ X)\n\n (hfsubdiff : ∀ t, 1 ≤ t → ∀ u ∈ X, ∃ gu : E, ∀ v ∈ X, f t v ≥ f t u + (@inner ℝ E _ gu (v - u)))\n\n (hinv : ∀ v : E, gΦ (gΦs v) = v)\n (hinvD : ∀ a ∈ D, gΦs (gΦ a) = a)\n\n (hΦconv : ConvexOn ℝ X Φ)\n (hΦsub : ∀ a ∈ D, ∀ b ∈ X, Φ b ≥ Φ a + (@inner ℝ E _ (gΦ a) (b - a)))\n (hgΦsD : ∀ v : E, gΦs v ∈ D)\n\n (hXclosed : IsClosed X)\n (hprojX : ∀ v : E, proj v ∈ X) (hprojD : ∀ v : E, proj v ∈ D)\n\n (hprojDef : ∀ v ∈ D, ∀ u ∈ X, bregman Φ gΦ (proj v) v ≤ bregman Φ gΦ u v)\n\n (hfconv : ∀ t, 1 ≤ t → ConvexOn ℝ X (f t))\n (hx1 : x 1 ∈ X) (hx1D : x 1 ∈ D)\n (hsub : ∀ t, 1 ≤ t → ∀ u ∈ X, f t (x t) - f t u ≤ (@inner ℝ E _ (g t) (x t - u)))\n\n (hy1 : y 1 = x 1)\n\n (hyupdate : ∀ t, 1 ≤ t →\n y (t + 1) = gΦs (gΦ (x 1) - η (t + 1) • (∑ i ∈ Finset.Icc 1 t, g i)))\n\n (hxupdate : ∀ t, 1 ≤ t → x (t + 1) = proj (y (t + 1)))\n\n (hpyth : ∀ z ∈ X, ∀ v ∈ D,\n bregman Φ gΦ z (proj v) ≤ bregman Φ gΦ z v - bregman Φ gΦ (proj v) v)\n (T : ℕ) (hT : 1 ≤ T) (z : E) (hz : z ∈ X) :\n regret f x z T\n ≤ (∑ t ∈ Finset.Icc 1 T,\n (bregman Φ gΦ (x t) (gΦs (gΦ (x t) - η t • g t))\n - bregman Φ gΦ (x (t + 1)) (gΦs (gΦ (x t) - η t • g t))) / η t)\n + bregman Φ gΦ z (x 1) / η (T + 1) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen scoped RealInnerProductSpace BigOperators\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]\n\nnoncomputable def bregman (Φ : E → ℝ) (gΦ : E → E) (x y : E) : ℝ :=\n Φ x - Φ y - (@inner ℝ E _ (gΦ y) (x - y))\n\nnoncomputable def regret (f : ℕ → E → ℝ) (x : ℕ → E) (z : E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 1 T, (f t (x t) - f t z)\n\nstructure PaperNorm (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] where\n nrm : E → ℝ\n nonneg : ∀ x, 0 ≤ nrm x\n eq_zero_iff : ∀ x, nrm x = 0 ↔ x = 0\n smul : ∀ (c : ℝ) (x : E), nrm (c • x) = |c| * nrm x\n triangle : ∀ x y, nrm (x + y) ≤ nrm x + nrm y\n\nnoncomputable def dualNorm (N : PaperNorm E) (z : E) : ℝ :=\n sSup {v : ℝ | ∃ x : E, N.nrm x ≤ 1 ∧ v = (@inner ℝ E _ z x)}\n\nprivate lemma tele_sum (G : ℕ → ℝ) (T : ℕ) :\n ∑ t ∈ Finset.Icc 1 T, (G t - G (t+1)) = G 1 - G (T+1) := by\n induction T with\n | zero => simp\n | succ n ih =>\n rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ n + 1), ih]; ring\n\nprivate lemma sum_bound {a c : ℕ → ℝ} {G : ℕ → ℝ} {K : ℝ} {T : ℕ}\n (hstep : ∀ t ∈ Finset.Icc 1 T, a t ≤ c t + (G t - G (t+1)))\n (hG1 : G 1 = 0) (hGT : -G (T+1) ≤ K) :\n ∑ t ∈ Finset.Icc 1 T, a t ≤ (∑ t ∈ Finset.Icc 1 T, c t) + K := by\n have h1 := Finset.sum_le_sum hstep\n rw [Finset.sum_add_distrib, tele_sum, hG1] at h1\n linarith\n\nnoncomputable def dgap (Φ : E → ℝ) (a b d : E) : ℝ :=\n Φ a - Φ b - (@inner ℝ E _ d (a - b))\n\nprivate lemma dgap_breg (Φ : E → ℝ) (gΦ : E → E) (a b c : E) :\n dgap Φ a b (gΦ c) = bregman Φ gΦ a c - bregman Φ gΦ b c := by\n simp only [dgap, bregman, inner_sub_right]; ring\n\nprivate lemma dgap_self (Φ : E → ℝ) (gΦ : E → E) (a b : E) :\n dgap Φ a b (gΦ b) = bregman Φ gΦ a b := by\n simp only [dgap, bregman]\n\nprivate lemma dgap_add (Φ : E → ℝ) (a b c d : E) :\n dgap Φ a b d + dgap Φ b c d = dgap Φ a c d := by\n simp only [dgap, inner_sub_right]; ring\n\nprivate lemma dgap_mix (Φ : E → ℝ) (γ : ℝ) (a b d₁ d₂ : E) :\n γ * dgap Φ a b d₁ + (1 - γ) * dgap Φ a b d₂ = dgap Φ a b (γ • d₁ + (1 - γ) • d₂) := by\n simp only [dgap, inner_add_left, real_inner_smul_left]; ring\n\nprivate lemma breg_step (Φ : E → ℝ) (gΦ : E → E) (xt z wv gt : E) (e : ℝ)\n (h : gΦ wv = gΦ xt - e • gt) :\n e * (@inner ℝ E _ gt (xt - z)) =\n bregman Φ gΦ xt wv - bregman Φ gΦ z wv + bregman Φ gΦ z xt := by\n simp only [bregman, h, inner_sub_left, inner_sub_right, real_inner_smul_left]\n ring\n\nprivate lemma breg_mix (Φ : E → ℝ) (gΦ : E → E) (γ : ℝ) (a b p q v : E)\n (h : gΦ v = γ • gΦ p + (1 - γ) • gΦ q) :\n γ * (bregman Φ gΦ a p - bregman Φ gΦ b p)\n + (1 - γ) * (bregman Φ gΦ a q - bregman Φ gΦ b q)\n = bregman Φ gΦ a v - bregman Φ gΦ b v := by\n simp only [bregman, h, inner_add_left, inner_sub_left, inner_sub_right, real_inner_smul_left]\n ring\n\nprivate lemma breg_nonneg (Φ : E → ℝ) (gΦ : E → E) (D X : Set E)\n (hΦsub : ∀ a ∈ D, ∀ b ∈ X, Φ b ≥ Φ a + (@inner ℝ E _ (gΦ a) (b - a)))\n {a b : E} (ha : a ∈ D) (hb : b ∈ X) : 0 ≤ bregman Φ gΦ b a := by\n have := hΦsub a ha b hb\n simp only [bregman]; linarith\n\ntheorem theorem3\n (Φ : E → ℝ) (gΦ gΦs : E → E)\n (X : Set E)\n (D : Set E) (hDconv : Convex ℝ D)\n (hXD : X ⊆ closure D)\n (hDX : (D ∩ intrinsicInterior ℝ X).Nonempty)\n (hΦstrict : StrictConvexOn ℝ D Φ)\n (hΦgrad : ∀ a ∈ D, HasGradientWithinAt Φ (gΦ a) D a)\n (η : ℕ → ℝ) (hηpos : ∀ t, 1 ≤ t → 0 < η t) (hηmono : ∀ t, 1 ≤ t → η (t + 1) ≤ η t)\n (f : ℕ → E → ℝ)\n (x w : ℕ → E) (g : ℕ → E)\n (proj : E → E)\n\n (hXconv : Convex ℝ X)\n\n (hfsubdiff : ∀ t, 1 ≤ t → ∀ u ∈ X, ∃ gu : E, ∀ v ∈ X, f t v ≥ f t u + (@inner ℝ E _ gu (v - u)))\n\n (hXclosed : IsClosed X)\n\n (hfconv : ∀ t, 1 ≤ t → ConvexOn ℝ X (f t))\n\n (hinv : ∀ v : E, gΦ (gΦs v) = v)\n (hinvD : ∀ a ∈ D, gΦs (gΦ a) = a)\n\n (hΦconv : ConvexOn ℝ X Φ)\n (hΦsub : ∀ a ∈ D, ∀ b ∈ X, Φ b ≥ Φ a + (@inner ℝ E _ (gΦ a) (b - a)))\n (hgΦsD : ∀ v : E, gΦs v ∈ D)\n\n (hprojX : ∀ y : E, proj y ∈ X) (hprojD : ∀ y : E, proj y ∈ D)\n\n (hprojDef : ∀ v ∈ D, ∀ u ∈ X, bregman Φ gΦ (proj v) v ≤ bregman Φ gΦ u v)\n\n (hx1 : x 1 ∈ X) (hx1D : x 1 ∈ D)\n\n (hsub : ∀ t, 1 ≤ t → ∀ u ∈ X, f t (x t) - f t u ≤ (@inner ℝ E _ (g t) (x t - u)))\n\n (hw : ∀ t, 1 ≤ t → w (t + 1) = gΦs (gΦ (x t) - η t • g t))\n\n (hx : ∀ t, 1 ≤ t →\n x (t + 1) =\n proj (gΦs ((η (t + 1) / η t) • (gΦ (x t) - η t • g t)\n + (1 - η (t + 1) / η t) • gΦ (x 1))))\n\n (hpyth : ∀ z ∈ X, ∀ y ∈ D,\n bregman Φ gΦ z (proj y) ≤ bregman Φ gΦ z y - bregman Φ gΦ (proj y) y)\n (T : ℕ) (hT : 1 ≤ T) (z : E) (hz : z ∈ X) :\n regret f x z T\n ≤ (∑ t ∈ Finset.Icc 1 T,\n (bregman Φ gΦ (x t) (w (t + 1)) - bregman Φ gΦ (x (t + 1)) (w (t + 1))) / η t)\n + bregman Φ gΦ z (x 1) / η (T + 1) := by\n simp only [regret]\n have hane : ∀ s : ℕ, 1 ≤ s → η s ≠ 0 := fun s hs => ne_of_gt (hηpos s hs)\n refine sum_bound (a := fun t => f t (x t) - f t z)\n (c := fun t => (bregman Φ gΦ (x t) (w (t+1)) - bregman Φ gΦ (x (t+1)) (w (t+1))) / η t)\n (G := fun t => (bregman Φ gΦ z (x t) - bregman Φ gΦ z (x 1)) / η t) ?_ ?_ ?_\n · intro t ht\n rw [Finset.mem_Icc] at ht\n have h1 : 1 ≤ t := ht.1\n have ha : 0 < η t := hηpos t h1\n have hbp : 0 < η (t+1) := hηpos (t+1) (by omega)\n have ha' : η t ≠ 0 := ne_of_gt ha\n have hb' : η (t+1) ≠ 0 := ne_of_gt hbp\n have hba : η (t+1) ≤ η t := hηmono t h1\n have hγ1 : η (t+1) / η t ≤ 1 := (div_le_one ha).mpr hba\n have hgw : gΦ (w (t+1)) = gΦ (x t) - η t • g t := by\n rw [hw t h1]; exact hinv _\n have hxt1 : x (t+1) = proj (gΦs ((η (t + 1) / η t) • (gΦ (x t) - η t • g t)\n + (1 - η (t + 1) / η t) • gΦ (x 1))) := hx t h1\n set v := gΦs ((η (t + 1) / η t) • (gΦ (x t) - η t • g t)\n + (1 - η (t + 1) / η t) • gΦ (x 1)) with hvdef\n have hvD : v ∈ D := hgΦsD _\n have hgv : gΦ v = (η (t+1) / η t) • gΦ (w (t+1)) + (1 - η (t+1) / η t) • gΦ (x 1) := by\n rw [hvdef, hinv, hgw]\n have hxX : x (t+1) ∈ X := by rw [hxt1]; exact hprojX _\n have hnn : 0 ≤ bregman Φ gΦ (x (t+1)) (x 1) := breg_nonneg Φ gΦ D X hΦsub hx1D hxX\n have hp := hpyth z hz v hvD\n rw [← hxt1] at hp\n have hmix := breg_mix Φ gΦ (η (t+1) / η t) z (x (t+1)) (w (t+1)) (x 1) v hgv\n have hprod : 0 ≤ (1 - η (t+1) / η t) * bregman Φ gΦ (x (t+1)) (x 1) :=\n mul_nonneg (by linarith) hnn\n have hH : bregman Φ gΦ z (x (t+1))\n ≤ (η (t+1) / η t) * (bregman Φ gΦ z (w (t+1)) - bregman Φ gΦ (x (t+1)) (w (t+1)))\n + (1 - η (t+1) / η t) * bregman Φ gΦ z (x 1) := by nlinarith [hmix, hp, hprod]\n have hm := mul_le_mul_of_nonneg_right hH (le_of_lt (inv_pos.mpr hbp))\n have he : ((η (t+1) / η t) * (bregman Φ gΦ z (w (t+1)) - bregman Φ gΦ (x (t+1)) (w (t+1)))\n + (1 - η (t+1) / η t) * bregman Φ gΦ z (x 1)) * (η (t+1))⁻¹\n = (bregman Φ gΦ z (w (t+1)) - bregman Φ gΦ (x (t+1)) (w (t+1))) * (η t)⁻¹\n + bregman Φ gΦ z (x 1) * (η (t+1))⁻¹ - bregman Φ gΦ z (x 1) * (η t)⁻¹ := by\n field_simp\n ring\n rw [he] at hm\n have h3 := breg_step Φ gΦ (x t) z (w (t+1)) (g t) (η t) hgw\n have hs := hsub t h1 z hz\n have hI : (@inner ℝ E _ (g t) (x t - z))\n = (bregman Φ gΦ (x t) (w (t+1)) - bregman Φ gΦ z (w (t+1)) + bregman Φ gΦ z (x t))\n * (η t)⁻¹ := by\n rw [← h3]; field_simp\n rw [hI] at hs\n dsimp only\n simp only [div_eq_mul_inv]\n linarith [hs, hm]\n · dsimp only; simp\n · dsimp only\n have hxTD : x (T+1) ∈ D := by rw [hx T hT]; exact hprojD _\n have hnnT : 0 ≤ bregman Φ gΦ z (x (T+1)) := breg_nonneg Φ gΦ D X hΦsub hxTD hz\n have hηT : 0 < η (T+1) := hηpos (T+1) (by omega)\n have h0 : 0 ≤ bregman Φ gΦ z (x (T+1)) / η (T+1) := div_nonneg hnnT (le_of_lt hηT)\n have e : -((bregman Φ gΦ z (x (T+1)) - bregman Φ gΦ z (x 1)) / η (T+1))\n = bregman Φ gΦ z (x 1) / η (T+1) - bregman Φ gΦ z (x (T+1)) / η (T+1) := by ring\n rw [e]; linarith\n\ntheorem theorem5\n (Φ : E → ℝ) (gΦ gΦs : E → E)\n (X : Set E)\n (D : Set E) (hDconv : Convex ℝ D)\n (hXD : X ⊆ closure D)\n (hDX : (D ∩ intrinsicInterior ℝ X).Nonempty)\n (hΦstrict : StrictConvexOn ℝ D Φ)\n (hΦgrad : ∀ a ∈ D, HasGradientWithinAt Φ (gΦ a) D a)\n (η : ℕ → ℝ) (hηpos : ∀ t, 1 ≤ t → 0 < η t) (hηmono : ∀ t, 1 ≤ t → η (t + 1) ≤ η t)\n (f : ℕ → E → ℝ)\n (x y w : ℕ → E) (g : ℕ → E)\n (proj : E → E)\n\n (hXconv : Convex ℝ X)\n\n (hfsubdiff : ∀ t, 1 ≤ t → ∀ u ∈ X, ∃ gu : E, ∀ v ∈ X, f t v ≥ f t u + (@inner ℝ E _ gu (v - u)))\n\n (hinv : ∀ v : E, gΦ (gΦs v) = v)\n (hinvD : ∀ a ∈ D, gΦs (gΦ a) = a)\n\n (hΦconv : ConvexOn ℝ X Φ)\n (hΦsub : ∀ a ∈ D, ∀ b ∈ X, Φ b ≥ Φ a + (@inner ℝ E _ (gΦ a) (b - a)))\n (hgΦsD : ∀ v : E, gΦs v ∈ D)\n\n (hXclosed : IsClosed X)\n\n (hprojX : ∀ v : E, proj v ∈ X) (hprojD : ∀ v : E, proj v ∈ D)\n\n (hprojDef : ∀ v ∈ D, ∀ u ∈ X, bregman Φ gΦ (proj v) v ≤ bregman Φ gΦ u v)\n\n (hfconv : ∀ t, 1 ≤ t → ConvexOn ℝ X (f t))\n\n (hx1 : x 1 ∈ X) (hx1D : x 1 ∈ D)\n\n (hsub : ∀ t, 1 ≤ t → ∀ u ∈ X, f t (x t) - f t u ≤ (@inner ℝ E _ (g t) (x t - u)))\n\n (hw : ∀ t, 1 ≤ t → w (t + 1) = gΦs (gΦ (x t) - η t • g t))\n\n (hy : ∀ t, 1 ≤ t → y (t + 1) = proj (w (t + 1)))\n\n (hx : ∀ t, 1 ≤ t →\n x (t + 1) = (η (t + 1) / η t) • y (t + 1) + (1 - η (t + 1) / η t) • x 1)\n\n (hpyth : ∀ z ∈ X, ∀ v ∈ D,\n bregman Φ gΦ z (proj v) ≤ bregman Φ gΦ z v - bregman Φ gΦ (proj v) v)\n\n (hDconvex : ∀ z ∈ X, ConvexOn ℝ (X ∩ D) (fun u => bregman Φ gΦ z u))\n (T : ℕ) (hT : 1 ≤ T) (z : E) (hz : z ∈ X) :\n regret f x z T\n ≤ (∑ t ∈ Finset.Icc 1 T,\n (bregman Φ gΦ (x t) (w (t + 1)) - bregman Φ gΦ (y (t + 1)) (w (t + 1))) / η t)\n + bregman Φ gΦ z (x 1) / η (T + 1) := by\n simp only [regret]\n refine sum_bound (a := fun t => f t (x t) - f t z)\n (c := fun t => (bregman Φ gΦ (x t) (w (t+1)) - bregman Φ gΦ (y (t+1)) (w (t+1))) / η t)\n (G := fun t => (bregman Φ gΦ z (x t) - bregman Φ gΦ z (x 1)) / η t) ?_ ?_ ?_\n · intro t ht\n rw [Finset.mem_Icc] at ht\n have h1 : 1 ≤ t := ht.1\n have ha : 0 < η t := hηpos t h1\n have hbp : 0 < η (t+1) := hηpos (t+1) (by omega)\n have ha' : η t ≠ 0 := ne_of_gt ha\n have hb' : η (t+1) ≠ 0 := ne_of_gt hbp\n have hba : η (t+1) ≤ η t := hηmono t h1\n have hγ1 : η (t+1) / η t ≤ 1 := (div_le_one ha).mpr hba\n have hγ0 : 0 ≤ η (t+1) / η t := le_of_lt (div_pos hbp ha)\n have hgw : gΦ (w (t+1)) = gΦ (x t) - η t • g t := by\n rw [hw t h1]; exact hinv _\n have hwD : w (t+1) ∈ D := by rw [hw t h1]; exact hgΦsD _\n have hyX : y (t+1) ∈ X := by rw [hy t h1]; exact hprojX _\n have hyD : y (t+1) ∈ D := by rw [hy t h1]; exact hprojD _\n have hp := hpyth z hz (w (t+1)) hwD\n rw [← hy t h1] at hp\n have hconv := (hDconvex z hz).2 (Set.mem_inter hyX hyD) (Set.mem_inter hx1 hx1D)\n hγ0 (by linarith : (0:ℝ) ≤ 1 - η (t+1) / η t) (by ring)\n rw [← hx t h1] at hconv\n have hH : bregman Φ gΦ z (x (t+1))\n ≤ (η (t+1) / η t) * (bregman Φ gΦ z (w (t+1)) - bregman Φ gΦ (y (t+1)) (w (t+1)))\n + (1 - η (t+1) / η t) * bregman Φ gΦ z (x 1) := by\n have h5 : (η (t+1) / η t) * bregman Φ gΦ z (y (t+1))\n ≤ (η (t+1) / η t) * (bregman Φ gΦ z (w (t+1)) - bregman Φ gΦ (y (t+1)) (w (t+1))) :=\n mul_le_mul_of_nonneg_left hp hγ0\n simp only [smul_eq_mul] at hconv\n linarith\n have hm := mul_le_mul_of_nonneg_right hH (le_of_lt (inv_pos.mpr hbp))\n have he : ((η (t+1) / η t) * (bregman Φ gΦ z (w (t+1)) - bregman Φ gΦ (y (t+1)) (w (t+1)))\n + (1 - η (t+1) / η t) * bregman Φ gΦ z (x 1)) * (η (t+1))⁻¹\n = (bregman Φ gΦ z (w (t+1)) - bregman Φ gΦ (y (t+1)) (w (t+1))) * (η t)⁻¹\n + bregman Φ gΦ z (x 1) * (η (t+1))⁻¹ - bregman Φ gΦ z (x 1) * (η t)⁻¹ := by\n field_simp\n ring\n rw [he] at hm\n have h3 := breg_step Φ gΦ (x t) z (w (t+1)) (g t) (η t) hgw\n have hs := hsub t h1 z hz\n have hI : (@inner ℝ E _ (g t) (x t - z))\n = (bregman Φ gΦ (x t) (w (t+1)) - bregman Φ gΦ z (w (t+1)) + bregman Φ gΦ z (x t))\n * (η t)⁻¹ := by\n rw [← h3]; field_simp\n rw [hI] at hs\n dsimp only\n simp only [div_eq_mul_inv]\n linarith [hs, hm]\n · dsimp only; simp\n · dsimp only\n have hyTX : y (T+1) ∈ X := by rw [hy T hT]; exact hprojX _\n have hyTD : y (T+1) ∈ D := by rw [hy T hT]; exact hprojD _\n have haT : 0 < η T := hηpos T hT\n have hbT : 0 < η (T+1) := hηpos (T+1) (by omega)\n have hγ1 : η (T+1) / η T ≤ 1 := (div_le_one haT).mpr (hηmono T hT)\n have hγ0 : 0 ≤ η (T+1) / η T := le_of_lt (div_pos hbT haT)\n have hxTD : x (T+1) ∈ D := by\n rw [hx T hT]\n exact hDconv hyTD hx1D hγ0 (by linarith : (0:ℝ) ≤ 1 - η (T+1) / η T) (by ring)\n have hnnT : 0 ≤ bregman Φ gΦ z (x (T+1)) := breg_nonneg Φ gΦ D X hΦsub hxTD hz\n have h0 : 0 ≤ bregman Φ gΦ z (x (T+1)) / η (T+1) := div_nonneg hnnT (le_of_lt hbT)\n have e : -((bregman Φ gΦ z (x (T+1)) - bregman Φ gΦ z (x 1)) / η (T+1))\n = bregman Φ gΦ z (x 1) / η (T+1) - bregman Φ gΦ z (x (T+1)) / η (T+1) := by ring\n rw [e]; linarith\n\nprivate lemma dgap_step (Φ : E → ℝ) (a b c : E) (yh gt : E) (e : ℝ) :\n e * (@inner ℝ E _ gt (b - a)) =\n dgap Φ a b yh - dgap Φ a c (yh - e • gt) - dgap Φ c b (yh - e • gt) := by\n simp only [dgap, inner_sub_left, inner_sub_right, real_inner_smul_left]\n ring\n\ntheorem theorem8\n (Φ : E → ℝ) (gΦ gΦs : E → E)\n (X : Set E)\n (D : Set E) (hDconv : Convex ℝ D)\n (hXD : X ⊆ closure D)\n (hDX : (D ∩ intrinsicInterior ℝ X).Nonempty)\n (hΦstrict : StrictConvexOn ℝ D Φ)\n (hΦgrad : ∀ a ∈ D, HasGradientWithinAt Φ (gΦ a) D a)\n (η : ℕ → ℝ) (hηpos : ∀ t, 1 ≤ t → 0 < η t) (hηmono : ∀ t, 1 ≤ t → η (t + 1) ≤ η t)\n (f : ℕ → E → ℝ)\n (x y : ℕ → E) (g : ℕ → E)\n (proj : E → E)\n\n (hXconv : Convex ℝ X)\n\n (hfsubdiff : ∀ t, 1 ≤ t → ∀ u ∈ X, ∃ gu : E, ∀ v ∈ X, f t v ≥ f t u + (@inner ℝ E _ gu (v - u)))\n\n (hinv : ∀ v : E, gΦ (gΦs v) = v)\n (hinvD : ∀ a ∈ D, gΦs (gΦ a) = a)\n\n (hΦconv : ConvexOn ℝ X Φ)\n (hΦsub : ∀ a ∈ D, ∀ b ∈ X, Φ b ≥ Φ a + (@inner ℝ E _ (gΦ a) (b - a)))\n (hgΦsD : ∀ v : E, gΦs v ∈ D)\n\n (hXclosed : IsClosed X)\n (hprojX : ∀ v : E, proj v ∈ X) (hprojD : ∀ v : E, proj v ∈ D)\n\n (hprojDef : ∀ v ∈ D, ∀ u ∈ X, bregman Φ gΦ (proj v) v ≤ bregman Φ gΦ u v)\n\n (hfconv : ∀ t, 1 ≤ t → ConvexOn ℝ X (f t))\n (hx1 : x 1 ∈ X) (hx1D : x 1 ∈ D)\n (hsub : ∀ t, 1 ≤ t → ∀ u ∈ X, f t (x t) - f t u ≤ (@inner ℝ E _ (g t) (x t - u)))\n\n (hy1 : y 1 = x 1)\n\n (hyupdate : ∀ t, 1 ≤ t →\n y (t + 1) = gΦs (gΦ (x 1) - η (t + 1) • (∑ i ∈ Finset.Icc 1 t, g i)))\n\n (hxupdate : ∀ t, 1 ≤ t → x (t + 1) = proj (y (t + 1)))\n\n (hpyth : ∀ z ∈ X, ∀ v ∈ D,\n bregman Φ gΦ z (proj v) ≤ bregman Φ gΦ z v - bregman Φ gΦ (proj v) v)\n (T : ℕ) (hT : 1 ≤ T) (z : E) (hz : z ∈ X) :\n regret f x z T\n ≤ (∑ t ∈ Finset.Icc 1 T,\n (bregman Φ gΦ (x t) (gΦs (gΦ (x t) - η t • g t))\n - bregman Φ gΦ (x (t + 1)) (gΦs (gΦ (x t) - η t • g t))) / η t)\n + bregman Φ gΦ z (x 1) / η (T + 1) := by\n simp only [regret]\n have hyhat : ∀ s : ℕ, gΦ (y (s+1)) = gΦ (x 1) - η (s+1) • (∑ i ∈ Finset.Icc 1 s, g i) := by\n intro s\n rcases Nat.eq_zero_or_pos s with hs | hs\n · subst hs; simp [hy1]\n · rw [hyupdate s hs, hinv]\n refine sum_bound (a := fun t => f t (x t) - f t z)\n (c := fun t => (bregman Φ gΦ (x t) (gΦs (gΦ (x t) - η t • g t))\n - bregman Φ gΦ (x (t+1)) (gΦs (gΦ (x t) - η t • g t))) / η t)\n (G := fun t => (dgap Φ z (x t) (gΦ (y t)) - bregman Φ gΦ z (x 1)) / η t) ?_ ?_ ?_\n · intro t ht\n rw [Finset.mem_Icc] at ht\n have h1 : 1 ≤ t := ht.1\n obtain ⟨s, rfl⟩ : ∃ s, t = s + 1 := ⟨t - 1, by omega⟩\n have ha : 0 < η (s+1) := hηpos (s+1) (by omega)\n have hbp : 0 < η (s+1+1) := hηpos (s+1+1) (by omega)\n have ha' : η (s+1) ≠ 0 := ne_of_gt ha\n have hb' : η (s+1+1) ≠ 0 := ne_of_gt hbp\n have hba : η (s+1+1) ≤ η (s+1) := hηmono (s+1) (by omega)\n have hγ1 : η (s+1+1) / η (s+1) ≤ 1 := (div_le_one ha).mpr hba\n have hγ0 : 0 ≤ η (s+1+1) / η (s+1) := le_of_lt (div_pos hbp ha)\n have hxX : x (s+1+1) ∈ X := by rw [hxupdate (s+1) (by omega)]; exact hprojX _\n have hyDt : y (s+1) ∈ D := by\n rcases Nat.eq_zero_or_pos s with hs | hs\n · subst hs; rw [hy1]; exact hx1D\n · rw [hyupdate s hs]; exact hgΦsD _\n have hgw' : gΦ (gΦs (gΦ (x (s+1)) - η (s+1) • g (s+1)))\n = gΦ (x (s+1)) - η (s+1) • g (s+1) := hinv _\n have hkey : (@inner ℝ E _ (gΦ (y (s+1)) - gΦ (x (s+1))) (x (s+1+1) - x (s+1))) ≤ 0 := by\n rcases Nat.eq_zero_or_pos s with hs | hs\n · subst hs; rw [hy1]; simp\n · have hxt : x (s+1) = proj (y (s+1)) := hxupdate s hs\n have hp := hpyth (x (s+1+1)) hxX (y (s+1)) hyDt\n rw [← hxt] at hp\n rw [← dgap_self Φ gΦ (x (s+1+1)) (x (s+1)), ← dgap_breg Φ gΦ] at hp\n simp only [dgap, inner_sub_left] at hp ⊢\n linarith\n have hBd : dgap Φ (x (s+1+1)) (x (s+1)) (gΦ (gΦs (gΦ (x (s+1)) - η (s+1) • g (s+1))))\n ≤ dgap Φ (x (s+1+1)) (x (s+1)) (gΦ (y (s+1)) - η (s+1) • g (s+1)) := by\n have e2 : dgap Φ (x (s+1+1)) (x (s+1)) (gΦ (y (s+1)) - η (s+1) • g (s+1))\n - dgap Φ (x (s+1+1)) (x (s+1)) (gΦ (gΦs (gΦ (x (s+1)) - η (s+1) • g (s+1))))\n = -(@inner ℝ E _ (gΦ (y (s+1)) - gΦ (x (s+1))) (x (s+1+1) - x (s+1))) := by\n simp only [dgap, hgw', inner_sub_left]; ring\n linarith\n have hSsucc : (∑ i ∈ Finset.Icc 1 (s+1), g i) = (∑ i ∈ Finset.Icc 1 s, g i) + g (s+1) :=\n Finset.sum_Icc_succ_top (by omega) _\n have hmixd : (η (s+1+1) / η (s+1)) • (gΦ (y (s+1)) - η (s+1) • g (s+1))\n + (1 - η (s+1+1) / η (s+1)) • gΦ (x 1) = gΦ (y (s+1+1)) := by\n rw [hyhat s, hyhat (s+1), hSsucc]\n match_scalars <;> (field_simp; try ring)\n have hnn : 0 ≤ bregman Φ gΦ (x (s+1+1)) (x 1) := breg_nonneg Φ gΦ D X hΦsub hx1D hxX\n have hdb := dgap_breg Φ gΦ z (x (s+1+1)) (x 1)\n have hClaim : dgap Φ z (x (s+1+1)) (gΦ (y (s+1+1)))\n ≤ (η (s+1+1) / η (s+1)) * dgap Φ z (x (s+1+1)) (gΦ (y (s+1)) - η (s+1) • g (s+1))\n + (1 - η (s+1+1) / η (s+1)) * bregman Φ gΦ z (x 1) := by\n have hmx := dgap_mix Φ (η (s+1+1) / η (s+1)) z (x (s+1+1))\n (gΦ (y (s+1)) - η (s+1) • g (s+1)) (gΦ (x 1))\n rw [hmixd] at hmx\n have hpp : 0 ≤ (1 - η (s+1+1) / η (s+1)) * bregman Φ gΦ (x (s+1+1)) (x 1) :=\n mul_nonneg (by linarith) hnn\n nlinarith [hmx, hdb, hpp]\n have hm := mul_le_mul_of_nonneg_right hClaim (le_of_lt (inv_pos.mpr hbp))\n have he : ((η (s+1+1) / η (s+1))\n * dgap Φ z (x (s+1+1)) (gΦ (y (s+1)) - η (s+1) • g (s+1))\n + (1 - η (s+1+1) / η (s+1)) * bregman Φ gΦ z (x 1)) * (η (s+1+1))⁻¹\n = dgap Φ z (x (s+1+1)) (gΦ (y (s+1)) - η (s+1) • g (s+1)) * (η (s+1))⁻¹\n + bregman Φ gΦ z (x 1) * (η (s+1+1))⁻¹\n - bregman Φ gΦ z (x 1) * (η (s+1))⁻¹ := by\n field_simp\n ring\n rw [he] at hm\n have h3 := dgap_step Φ z (x (s+1)) (x (s+1+1)) (gΦ (y (s+1))) (g (s+1)) (η (s+1))\n have hs2 := hsub (s+1) (by omega) z hz\n have hI : (@inner ℝ E _ (g (s+1)) (x (s+1) - z))\n = (dgap Φ z (x (s+1)) (gΦ (y (s+1)))\n - dgap Φ z (x (s+1+1)) (gΦ (y (s+1)) - η (s+1) • g (s+1))\n - dgap Φ (x (s+1+1)) (x (s+1)) (gΦ (y (s+1)) - η (s+1) • g (s+1))) * (η (s+1))⁻¹ := by\n rw [← h3]; field_simp\n rw [hI] at hs2\n have hCd := dgap_breg Φ gΦ (x (s+1+1)) (x (s+1)) (gΦs (gΦ (x (s+1)) - η (s+1) • g (s+1)))\n have hBdmul := mul_le_mul_of_nonneg_right hBd (le_of_lt (inv_pos.mpr ha))\n dsimp only\n simp only [div_eq_mul_inv]\n rw [hCd] at hBdmul\n linarith [hs2, hm, hBdmul]\n · dsimp only\n rw [hy1, dgap_self]\n simp\n · dsimp only\n have hbT : 0 < η (T+1) := hηpos (T+1) (by omega)\n have hyTD : y (T+1) ∈ D := by rw [hyupdate T hT]; exact hgΦsD _\n have hxTD : x (T+1) ∈ D := by rw [hxupdate T hT]; exact hprojD _\n have hp := hpyth z hz (y (T+1)) hyTD\n rw [← hxupdate T hT, ← dgap_breg Φ gΦ] at hp\n have hnnT : 0 ≤ bregman Φ gΦ z (x (T+1)) := breg_nonneg Φ gΦ D X hΦsub hxTD hz\n have h0 : 0 ≤ dgap Φ z (x (T+1)) (gΦ (y (T+1))) / η (T+1) :=\n div_nonneg (by linarith) (le_of_lt hbT)\n have e : -((dgap Φ z (x (T+1)) (gΦ (y (T+1))) - bregman Φ gΦ z (x 1)) / η (T+1))\n = bregman Φ gΦ z (x 1) / η (T+1) - dgap Φ z (x (T+1)) (gΦ (y (T+1))) / η (T+1) := by ring\n rw [e]; linarith\n\nend ResearchLevel\n"} +{"id": "v24-19-980", "source": "Research-level", "targets": [{"label": "Lemma 6", "decls": ["lemma6"], "statement": "Lemma 6 For an MDP with rewards $r^{k}(s,a)$ and transition probability $\\tilde{P}(s^{\\prime}|s,a)$ such that $\\|\\tilde{P}(\\cdot|s,a)-P(\\cdot|s,a)\\|_{1}\\leq\\epsilon_{s,a},$ the Bellman error $B_{\\pi_{e}}^{\\tilde{P},k}(s,a)$ for state-action pair s, a is upper bounded as\n\n$$\n\\begin{array}{r}{B_{\\pi}^{\\tilde{P},k}(s,a)\\leq\\left\\|\\tilde{P}(\\cdot|s,a)-P(\\cdot|s,a)\\right\\|_{1}\\|h_{\\pi}^{\\tilde{P},k}(\\cdot)\\|_{\\infty},\\quad|B_{\\pi}^{\\tilde{P},k}(s,a)|\\leq\\tilde{D}\\operatorname*{min}\\left\\{\\epsilon_{s,a},2\\right\\},}\\end{array}\\tag{28}\n$$\n\nwhere $\\tilde{D}\\geq 0$ is an upper bound on the diameter of the MDP with transition probability $\\tilde{P}$ and on the span of the bias, $h_{\\pi}^{\\tilde{P},k}(s)-h_{\\pi}^{\\tilde{P},k}(s^{\\prime})\\leq\\tilde{D}$ for all $s,s^{\\prime}$", "context_ids": ["v24-19-980:ctx1", "v24-19-980:ctx2", "v24-19-980:ctx3", "v24-19-980:ctx4", "v24-19-980:ctx5", "v24-19-980:ctx6", "v24-19-980:ctx7"], "sibling_refs": ["Lemma 11"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Reinforcement Learning"}, {"label": "Lemma 11", "decls": ["lemma11"], "statement": "Lemma 11 (Bounded Span of MDP) For an MDP $\\mathcal{M}$ with rewards $r^{k}(s,a)$ and transition probabilities P, for any stationary policy π with average reward $\\lambda_{\\pi}^{k}$ , the difference of bias of any two states $s,$ and $s^{\\prime},$ is upper bounded by the diameter of the MDP D as:\n\n$$\nh_{\\pi}^{P,k}(s)-h_{\\pi}^{P,k}(s^{\\prime})\\leq D~\\forall~s,s^{\\prime}\\in\\mathcal{S}.\\tag{102}\n$$", "context_ids": ["v24-19-980:ctx1", "v24-19-980:ctx2", "v24-19-980:ctx5", "v24-19-980:ctx6"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Reinforcement Learning"}, {"label": "Lemma 7", "decls": ["lemma7"], "statement": "Lemma 7 For any $1 \\leq t \\leq T$ , the probability that the event $\\mathcal{E}_{t}$ fails to occur us upper bounded by $\\frac{1}{20t^{6}}$", "context_ids": ["v24-19-980:ctx1", "v24-19-980:ctx8", "v24-19-980:ctx9"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Reinforcement Learning"}], "nl_proof": "### Proof of Lemma 6\n\nProof Starting with the definition of Bellman error in Equation (26), we get\n\n$$\n\\begin{array}{r l}&{B_{\\pi}^{\\tilde{P},k}(s,a)=\\underset{\\gamma\\to 1}{\\operatorname*{lim}}(Q_{\\gamma,\\pi}^{\\tilde{P},k}(s,a)-(r(s,a)+\\gamma\\sum_{s^{\\prime}\\in\\mathcal{S}}P(s^{\\prime}|s,a)V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime})))}\\\\ &{\\quad\\quad\\quad\\quad=\\underset{\\gamma\\to 1}{\\operatorname*{lim}}((r(s,a)+\\gamma\\sum_{s^{\\prime}\\in\\mathcal{S}}\\tilde{P}(s^{\\prime}|s,a)V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime}))-(r(s,a)+\\gamma\\sum_{s^{\\prime}\\in\\mathcal{S}}P(s^{\\prime}|s,a)V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime})))}\\end{array}\\tag{128}\n$$\n\n$$\n=\\operatorname*{lim}_{\\gamma\\to 1}\\gamma\\sum_{s^{\\prime}\\in\\mathcal{S}}(\\tilde{P}(s^{\\prime}|s,a)-P(s^{\\prime}|s,a))V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime})\\tag{129}\n$$\n\n$$\n=\\operatorname*{lim}_{\\gamma\\to 1}\\gamma(\\sum_{s^{\\prime}\\in\\mathcal{S}}(\\tilde{P}(s^{\\prime}|s,a)-P(s^{\\prime}|s,a))V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime})+V_{\\gamma,\\pi}^{\\tilde{P},k}(s)-V_{\\gamma,\\pi}^{\\tilde{P},k}(s))\\tag{130}\n$$\n\n$$\n=\\operatorname*{lim}_{\\gamma\\to 1}\\gamma\\Bigg(\\sum_{s^{\\prime}\\in\\mathcal{S}}(\\tilde{P}(s^{\\prime}|s,a)-P(s^{\\prime}|s,a))V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime})-\\sum_{s^{\\prime}\\in\\mathcal{S}}\\tilde{P}(s^{\\prime}|s,a)V_{\\gamma,\\pi}^{\\tilde{P},k}(s)\n$$\n\n$$\n+\\sum_{s^{\\prime}\\in\\mathcal{S}}P(s^{\\prime}|s,a)V_{\\gamma,\\pi}^{\\tilde{P},k}(s)\\bigg)\\tag{131}\n$$\n\n$$\n=\\operatorname*{lim}_{\\gamma\\to 1}\\gamma(\\sum_{s^{\\prime}\\in\\mathcal{S}}(\\tilde{P}(s^{\\prime}|s,a)-P(s^{\\prime}|s,a))(V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime})-V_{\\gamma,\\pi}^{\\tilde{P},k}(s)))\\tag{132}\n$$\n\n$$\n=\\left(\\sum_{s^{\\prime}\\in\\mathcal{S}}\\left(\\tilde{P}(s^{\\prime}|s,a)-P(s^{\\prime}|s,a)\\right)\\operatorname*{lim}_{\\gamma\\to 1}\\gamma\\left(V_{\\gamma,\\pi}^{\\tilde{P},k}(s^{\\prime})-V_{\\gamma,\\pi}^{\\tilde{P},k}(s)\\right)\\right)\\tag{133}\n$$\n\n$$\n=\\left(\\sum_{s^{\\prime}\\in\\mathcal{S}}\\left(\\tilde{P}(s^{\\prime}|s,a)-P(s^{\\prime}|s,a)\\right)h_{\\pi}^{\\tilde{P},k}(s^{\\prime})\\right)\\tag{134}\n$$\n\n$$\n\\leq\\left\\|\\tilde{P}(\\cdot|s,a)-P(\\cdot|s,a)\\right\\|_{1}\\|h_{\\pi}^{\\tilde{P},k}(\\cdot)\\|_{\\infty}\\tag{135}\n$$\n\n$$\n\\le\\epsilon_{s,a}\\tilde{D}\\tag{136}\n$$\n\nwhere Equation (129) comes from the assumption that the rewards are known to the agent. Equation (133) follows from the fact that the difference between value function at two states is bounded. Equation (134) comes from the definition of bias term Puterman (1994) where h is the bias of the policy π when run on the sampled MDP. Equation (135) follows from Hölder's inequality. In Equation (136), $\\|h(\\cdot)\\|_{\\infty}$ is bounded by the diameter $\\tilde{D}$ of the sampled MDP(from Lemma 11). Also, the $\\ell_{1}$ norm of probability vector difference is bounded from the definition.\n\nAdditionally, note that the $\\ell_{1}$ norm in Equation (135) is bounded by 2. Thus the Bellman error is loose upper bounded by $2 \\tilde{D}$ for all state-action pairs.\n\n### Proof of Lemma 11\n\nProof Consider two states $s,s^{\\prime}\\in\\mathcal{S}$ . Also, let $\\tau$ be a random variable defined as:\n\n$$\n\\tau=\\operatorname*{min}\\{t\\geq 1:S_{t}=s^{\\prime},S_{1}=s\\}\\tag{103}\n$$\n\nThen, for any policy π, we have the following Bellman operator\n\n$$\n\\begin{array}{c}{{h_{\\pi}^{P,k}(s)=r_{\\pi}^{k}(s)-\\lambda_{\\pi}^{k}+ }}\\\\ {{=Th_{\\pi}^{P,k}(s)(s)}}\\end{array}\\tag{104}\n$$\n\nwhere $\\begin{array}{r}{P_{\\pi}(s^{\\prime}|s)=\\sum_{a}\\pi(a|s)P(s^{\\prime}|s,a)}\\end{array}$ and $\\begin{array}{r}{r_{\\pi}^{k}(s)=\\sum_{a}\\pi(a|s)r^{k}(s,a)}\\end{array}$\n\nWe also define another operator,\n\n$$\n\\bar{T}h(s)=\\left\\{\\begin{array}{l l}{\\operatorname*{min}_{s,a}r^{k}(s,a)-\\lambda_{\\pi}^{k}+ ,}&{s\\neq s^{\\prime}}\\\\ {h_{\\pi}^{P,k}(s^{\\prime}),}&{s=s^{\\prime}}\\end{array}\\right.\\tag{105}\n$$\n\nNote that $\\begin{array}{r}{(T-\\bar{T})h_{\\pi}^{P,k}(s)=r_{\\pi}^{k}(s,a)-\\operatorname*{min}_{s,a}r^{k}(s,a)\\geq 0}\\end{array}$ ,for all s. Hence, we have $\\bar{T}h(s)\\leq Th(s)=h_{\\pi}^{P,k}(s)$ , for all s. Further, for any two vectors $u,v,$ where all the elements of u are not smaller than w we have $\\bar{T}u \\geq \\bar{T}w$ . Hence, we have ${\\bar{T}}^{n}h_{\\pi}^{P,k}(s)\\leq h_{\\pi}^{P,k}(s)$ for all s. Unrolling the recurrence, we have\n\n$$\nh_{\\pi}^{P,k}(s)\\geq\\bar{T}^{n}h_{\\pi}^{P,k}(s)=\\mathbb{E}\\left[-(\\lambda_{\\pi}^{k}-\\operatorname*{min}_{s,a}r^{k}(s,a))(n\\wedge\\tau)+h_{\\pi}^{P,k}(S_{n\\wedge\\tau})\\right]\\tag{106}\n$$\n\nFor lim $n \\to \\infty$ , we have $h_{\\pi}^{P,k}(s)\\geq h_{\\pi}^{P,k}(s^{\\prime})-D$ , completing the proof.\n\n### Proof of Lemma 7\n\nProof From the result of Weissman et al. (2003), the $\\ell_{1}$ distance of a probability distribution over S events with n samples is bounded as:\n\n$$\n\\begin{array}{r l r}&{}&{\\mathbb{P}\\left(\\|P(\\cdot|s,a)-\\hat{P}(\\cdot|s,a)\\|_{1}\\geq\\epsilon\\right)\\leq(2^{S}-2)\\exp\\left(-\\displaystyle\\frac{n(s,a)\\epsilon^{2}}{2}\\right)}\\\\ &{}&{\\leq(2^{S})\\exp\\left(-\\displaystyle\\frac{n(s,a)\\epsilon^{2}}{2}\\right)~}\\end{array}\\tag{137}\n$$\n\nThus, for $\\begin{array}{r}{\\epsilon=\\sqrt{\\frac{2}{n(s,a)}\\log(2^{S}20SAt^{7})}\\le\\sqrt{\\frac{14S}{n(s,a)}\\log(2At)}\\le\\sqrt{\\frac{14S}{n(s,a)}\\log(2AT)}}\\end{array}$ , we have\n\n$$\n\\mathbb{P}\\left(\\|P(\\cdot|s,a)-\\hat{P}(\\cdot|s,a)\\|_{1}\\geq\\sqrt{\\frac{14S}{n(s,a)}\\log(2At)}\\right)\\leq(2^{S})\\exp\\left(-\\frac{n(s,a)}{2}\\frac{2}{n(s,a)}\\log(2^{S}20SAt^{7})\\right)\\tag{138}\n$$\n\n$$\n=2^{S}\\frac{1}{2^{S}20SAt^{7}}\\tag{139}\n$$\n\n$$\n={\\frac{1}{20ASt^{7}}}\\tag{140}\n$$\n\nWe sum over the all the possible values of $n(s,a)$ till t time-step to bound the probability that the event $\\mathcal{E}_{t}$ does not occur as:\n\n$$\n\\sum_{n(s,a)=1}^{t}{\\frac{1}{20SAt^{7}}}\\leq{\\frac{1}{20SAt^{6}}}\\tag{141}\n$$\n\nFinally, summing over all the $s,a,$ we get\n\n$$\n\\mathbb{P}\\left(\\|P(\\cdot|s,a)-\\hat{P}(\\cdot|s,a)\\|_{1}\\geq\\sqrt{\\frac{14S}{n(s,a)}\\log(2At)}\\ \\forall s,a\\right)\\leq\\frac{1}{20t^{6}}\\tag{142}\n$$", "context": [{"id": "v24-19-980:ctx1", "name": "Setup: MDP, rewards, policy and average reward (Section 3)", "statement": "We consider an infinite horizon discounted Markov decision process (MDP) $\\mathcal{M}$ defined by the tuple $\\left(\\mathcal{S},\\mathcal{A},P,r^{1},r^{2},\\cdot\\cdot\\cdot,r^{K},\\rho_{0}\\right)$ . $\\mathcal{S}$ denotes a finite set of state space of size S, and $\\mathcal{A}$ denotes a finite set of A actions. $P:\\mathcal{S}\\times\\mathcal{A}\\to [0,1]^{S}$ denotes the probability transition distribution. K denotes the number of objectives and $[K]=\\{1,2,\\cdots,K\\}$ is the set of K objectives. Let $r^{k}:\\mathcal{S}\\times\\mathcal{A}\\to [0,1]$ be the bounded reward function for objective $k \\in [ K ]$. Lastly, $\\rho_{0}:\\mathcal{S}\\to [0,1]$ is the distribution of initial state. We motivate our choice of bounds on rewards from the fact that many problems in practice require explicit reward shaping. Hence, the controller or the learner is aware of the bounds on the rewards. We consider the bounds to be [0, 1] for our case which is easy to satisfy by reward shaping.\n\nWe use a stochastic policy $\\pi:\\mathcal{S}\\times\\mathcal{A}\\to [0,1]$ which returns the probability of selecting action $a \\in{\\mathcal{A}}$ for any given state $s \\in{\\mathcal{S}}$. Following policy π on the MDP, the agent observes a sequence of random variables $\\{S_{t}, A_{t}\\}_{t}$ where $S_{t}$ denotes the state of the agent at time t and $A_{t}$ denotes the action taken by the agent at time t. The expected discounted long term reward and expected per step reward of the objective k are given by $J_{\\pi}^{P,k}$ and $\\lambda_{\\pi}^{P,k}$ , respectively, when the joint policy π is followed. Formally, for discount factor $\\gamma\\in(0,1)$ , $J_{\\pi}^{P,k}$ and $\\lambda_{\\pi}^{P,k}$ are defined as\n\n$$\nJ_{\\pi}^{P,k}=\\mathbb{E}_{S_{0},A_{0},S_{1},A_{1},\\cdots}[\\operatorname*{lim}_{\\tau\\to\\infty}\\sum_{t=0}^{\\tau}\\gamma^{t}r^{k}(S_{t},A_{t})]\\tag{1}\n$$\n\n$$\nS_{0}\\sim\\rho_{0}(S_{0}),\\ A_{t}\\sim\\pi(A_{t}|S_{t}),\\ S_{t+1}\\sim P(\\cdot|S_{t},A_{t})\n$$\n\n$$\n\\lambda_{\\pi}^{P,k}=\\mathbb{E}_{S_{0},A_{0},S_{1},A_{1},\\cdots}[\\operatorname*{lim}_{\\tau\\to\\infty}\\frac{1}{\\tau}\\sum_{t=0}^{\\tau}r^{k}(S_{t},A_{t})]\\tag{2}\n$$\n\n$$\n=\\operatorname*{lim}_{\\gamma\\to 1}(1-\\gamma)J_{\\pi}^{P,k}\\tag{3}\n$$"}, {"id": "v24-19-980:ctx2", "name": "Bias Bellman equation, eq. (4)", "statement": "Equation (3) follows from the Laurent series expansion of $J_{\\pi}^{k}$ (Puterman, 1994). For brevity, in the rest of the paper $\\mathbb{E}_{S_{t}, A_{t}, S_{t + 1}; t \\geq 0}[ \\cdot ]$ will be denoted as $\\mathbb{E}_{\\rho,\\pi,P}[\\cdot]$ , where $S_{0}\\sim \\rho_{0}, \\ A_{t}\\sim$ $\\pi(\\cdot|S_{t}),\\ S_{t+1}\\sim P(\\cdot|S_{t},A_{t})$ . The expected per step reward satisfies the following Bellman equation\n\n$$\nh_{\\pi}^{P,k}(s)+\\lambda_{\\pi}^{P,k}=\\mathbb{E}_{a\\sim\\pi}\\left[r^{k}(s,a)\\right]+\\mathbb{E}_{a\\sim\\pi}\\left[\\sum_{s^{\\prime}}P(s^{\\prime}|s,a)h_{\\pi}^{P,k}(s^{\\prime})\\right]\\tag{4}\n$$\n\nwhere $h_{\\pi}^{k}(s)$ is the bias of policy π for state s."}, {"id": "v24-19-980:ctx3", "name": "Discounted value and Q-functions, eqs. (5)-(6)", "statement": "We also define the discounted value function $V_{\\gamma,\\pi}^{P,k}(s)$ and Q-value functions $Q_{\\gamma,\\pi}^{P,k}(s,a)$ as follows:\n\n$$\nV_{\\gamma,\\pi}^{P,k}(s)=\\mathbb{E}_{A_{0},S_{1},A_{1},\\cdots}[\\operatorname*{lim}_{\\tau\\to\\infty}\\sum_{t=0}^{\\tau}\\gamma^{t}r^{k}(S_{t},A_{t})|S_{0}=s]\\tag{5}\n$$\n\n$$\n\\begin{array}{l}{{Q_{\\gamma,\\pi}^{P,k}(s,a)=\\mathbb{E}_{S_{1},A_{1},\\cdots}[\\displaystyle\\operatorname*{lim}_{\\tau\\to\\infty}\\sum_{t=0}^{\\tau}\\gamma^{t}r^{k}(S_{t},A_{t})\\vert S_{0}=s,A_{0}=a]}}\\\\ {{\\mathrm{~}=r^{k}(s,a)+\\mathbb{E}_{a\\sim\\pi}[\\displaystyle\\sum_{s^{\\prime}}P(s^{\\prime}\\vert s,a)V_{\\gamma,\\pi}^{P,k}(s^{\\prime})]}}\\end{array}\\tag{6}\n$$"}, {"id": "v24-19-980:ctx4", "name": "Bias vs. discounted value, eq. (7)", "statement": "Further, the bias $h_{\\pi}^{P,k}(s)$ and the value function $V_{\\gamma,\\pi}^{P,k}$ are related as\n\n$$\nh_{\\pi}^{P,k}(s_{1})-h_{\\pi}^{P,k}(s_{2})=\\operatorname*{lim}_{\\gamma\\to 1}(V_{\\gamma,\\pi}^{P,k}(s_{1})-V_{\\gamma,\\pi}^{P,k}(s_{2})),{\\mathrm{~w h e r e~}}s_{1},s_{2}\\in{\\mathcal{S}}.\\tag{7}\n$$\n\nFor notation simplicity, we may drop the superscript P when discussing about variables for the true MDP."}, {"id": "v24-19-980:ctx5", "name": "Induced Markov chain and Definition 1 (Diameter), eq. (8)", "statement": "Note that each policy induces a Markov Chain on the states $\\mathcal{S}$ with transition probabilities $\\begin{array}{r}{P_{\\pi,s}(s^{\\prime})=\\sum_{a\\in\\mathcal{A}}\\pi(a|s)P(s^{\\prime}|s,a)}\\end{array}$ . After defining a policy, we can now define the diameter of the MDP $\\mathcal{M}$ as:\n\nDefinition 1 (Diameter) Consider the Markov Chain induced by the policy π on the MDP $\\mathcal{M}$. Let $T(s^{\\prime}|\\mathcal{M},\\pi,s)$ be a random variable that denotes the first time step when this Markov Chain enters state s' starting from state s. Then, the diameter of the MDP $\\mathcal{M}$ is defined as:\n\n$$\nD(\\mathcal{M})=\\operatorname*{max}_{\\pi}\\operatorname*{max}_{s^{\\prime}\\neq s}\\mathbb{E}\\left[T(s^{\\prime}|\\mathcal{M},\\pi,s)\\right]\\tag{8}\n$$"}, {"id": "v24-19-980:ctx6", "name": "Assumption 1 (ergodic MDP), eq. (9)", "statement": "Further, starting from an arbitrary initial state distribution, the state distribution may take a while to converge to the steady state distribution. For any policy π, let $P_{\\pi,s}^{t}=(P_{\\pi,s})^{t}$ be the t-step probability distribution of the states when policy π is applied to MDP with transition probabilities P starting from state s.\n\nWe are now ready to state our first assumption on the MDP. We assume that the Markov Decision Process is ergodic. This implies that: 1. for any policy all states, $s \\in{\\mathcal{S}}$ communicate with each other; 2. for any policy, the process converges to the steady state distribution exponentially fast. Formally, we have\n\nAssumption 1 The Markov Decision Process, $\\mathcal{M}$, is ergodic. Then, we have,\n\n1. The diameter, D, of $\\mathcal{M}$ is finite.\n\n2. For any policy π, for some $C > 0$ and $0 \\leq \\rho < 1$ , we have\n\n$$\n\\|P_{\\pi,s}^{t}-d_{\\pi}\\|_{TV}\\leq C\\rho^{t}\\tag{9}\n$$\n\nwhere $d_{\\pi}$ is the steady state distribution induced by policy π on the MDP."}, {"id": "v24-19-980:ctx7", "name": "Bellman error, eq. (26)", "statement": "To compute the regret incurred by the optimal policy $\\pi_{e}$ for the sampled MDP on the true MDP ${\\mathcal{M}},$ we use Bellman error. For some policy $\\pi,$ we define Bellman error $B_{\\pi}^{\\tilde{P},k}(s,a)$ for the infinite horizon MDPs as the difference between the cumulative expected rewards obtained for deviating from the system model with transition $\\tilde{P}$ for one step by taking action a in state s and then following policy π. We have:\n\n$$\n\\begin{array}{r l}&{B_{\\gamma,\\pi}^{\\tilde{P},k}(s,a)=\\left(Q_{\\gamma,\\pi}^{\\tilde{P},k}(s,a)-r(s,a)-\\gamma\\sum_{s^{\\prime}\\in\\mathcal{S}}P(s^{\\prime}|s,a)V_{\\gamma,\\pi}^{\\tilde{P},k}(s,a)\\right)}\\\\ &{B_{\\pi}^{\\tilde{P},k}(s,a)=\\underset{\\gamma\\to 1}{\\operatorname*{lim}}B_{\\gamma,\\pi}^{\\tilde{P},k}(s,a)}\\end{array}\\tag{26}\n$$"}, {"id": "v24-19-980:ctx8", "name": "Good event E_t, eq. (29), and empirical estimates", "statement": "A major part of the regret analysis is how well the learned model estimates the true system model. For that, bound the deviation of the estimates of the estimated transition probabilities of the Markov Decision Processes $\\mathcal{M}$. For that we use $\\ell_{1}$ deviation bounds from (Weissman et al., 2003). Consider, the following event,\n\n$$\n\\mathcal{E}_{t}=\\left\\{\\|\\bar{P}_{t}(\\cdot|s,a)-P(\\cdot|s,a)\\|_{1}\\leq\\sqrt{\\frac{14S\\log(2AT)}{\\operatorname*{max}\\{1,n_{t}(s,a)\\}}}\\forall(s,a)\\in\\mathcal{S}\\times\\mathcal{A}\\right\\}\\tag{29}\n$$\n\nwhere $\\begin{array}{r}{n_{t}(s,a)=\\sum_{t^{\\prime}=1}^{t}\\mathbf{1}_{\\{S_{t^{\\prime}}=s,a_{t^{\\prime}}=a\\}}}\\end{array}$ and $\\begin{array}{r}{\\bar{P}(s^{\\prime}|s,a)=\\left(\\sum_{t^{\\prime}=1}^{t}\\mathbf{1}_{\\{S_{t^{\\prime}}=s,a_{t^{\\prime}}=a,S_{t^{\\prime}+1}=s^{\\prime}\\}}\\right)/n_{t}(s,a)}\\end{array}$ of the empirical estimate of the transition probabilities."}, {"id": "v24-19-980:ctx9", "name": "Algorithm 1 (Model-Based Joint Decision Making) and its description (Section 5.1)", "statement": "Algorithm 1 Model-Based Joint Decision Making Algorithm \n1: procedure Model Based Online($\\mathcal{S},\\mathcal{A},[K],f,r$) \n2: Initialize $N(s,a,s^{\\prime})=1\\forall(s,a,s^{\\prime})\\in\\mathcal{S}\\times\\mathcal{A}\\times\\mathcal{S}$ \n3: Initialize $\\nu_{0}(s,a)=0~\\forall~(s,a)\\in\\mathcal{S}\\times\\mathcal{A}$ \n4: Initialize $\\textstyle\\pi_{1}(a|s)={\\frac{1}{|{\\mathcal{A}}|}}\\forall(a,s)\\in{\\mathcal{A}}\\times{\\mathcal{S}}$ \n5: Initialize $e = 1$ \n6: for time steps $t=1,2,\\cdots$ do \n7: Observe current state $S_{t}$ \n8: Sample action to play $A_{t}\\sim\\pi_{e}(\\cdot|S_{t})$ \n9: Play $A_{t},$ obtain reward $r_{t}\\in [0,1]^{K}$ and observe next state $S_{t + 1}$ \n10: Update $N(S_{t},A_{t},S_{t+1})\\gets N(S_{t},A_{t},S_{t+1})+1,\\nu_{e}(S_{t},A_{t})\\gets\\nu_{e}(S_{t},A_{t})+1$ \n11: if $\\begin{array}{r}{\\nu_{e}(S_{t},A_{t})\\ge\\operatorname*{max}\\{1,\\sum_{e^{\\prime} |h s'|)\n\nnoncomputable def hitTime {S Ω : Type*} (X : ℕ → Ω → S) (s' : S) (ω : Ω) : ℕ :=\n sInf {t : ℕ | 1 ≤ t ∧ X t ω = s'}\n\ndef IsDiameterBoundOfChain {S Ω : Type*} [Fintype S] [MeasurableSpace Ω]\n (μ : Measure Ω) (X : S → ℕ → Ω → S) (D : ℝ) : Prop :=\n ∀ s s' : S, s ≠ s' →\n (∀ᵐ ω ∂μ, ∃ t : ℕ, 1 ≤ t ∧ X s t ω = s') ∧\n Integrable (fun ω => (hitTime (X s) s' ω : ℝ)) μ ∧\n ∫ ω, (hitTime (X s) s' ω : ℝ) ∂μ ≤ D\n\ndef IsDiameterUpperBound (Ω : Type*) {S A : Type*} [Fintype S] [MeasurableSpace S]\n [Fintype A] [MeasurableSpace Ω] (P : S → A → S → ℝ) (D : ℝ) : Prop :=\n ∀ (μ₂ : Measure Ω), IsProbabilityMeasure μ₂ →\n ∀ π₂ : S → A → ℝ, (∀ s, (∀ a, 0 ≤ π₂ s a) ∧ ∑ a, π₂ s a = 1) →\n ∀ (X₂ : S → ℕ → Ω → S) (F₂ : ℕ → MeasurableSpace Ω),\n (∀ s₀ t, Measurable (X₂ s₀ t)) →\n (∀ s₀ : S, μ₂ {ω | X₂ s₀ 1 ω = s₀} = 1) →\n Monotone F₂ → (∀ t, F₂ t ≤ (inferInstance : MeasurableSpace Ω)) →\n (∀ s₀ : S, ∀ t t' : ℕ, t ≤ t' → Measurable[F₂ t'] (X₂ s₀ t)) →\n (∀ s₀ : S, ∀ t : ℕ, 1 ≤ t → ∀ H : Set Ω, MeasurableSet[F₂ t] H →\n ∀ x y : S, μ₂ (H ∩ {ω | X₂ s₀ t ω = x}) ≠ 0 →\n μ₂ (H ∩ {ω | X₂ s₀ t ω = x} ∩ {ω | X₂ s₀ (t + 1) ω = y})\n = ENNReal.ofReal (∑ a : A, π₂ x a * P x a y)\n * μ₂ (H ∩ {ω | X₂ s₀ t ω = x})) →\n IsDiameterBoundOfChain μ₂ X₂ D\n\ndef IsDiameterBound (Ω : Type*) {S A : Type*} [Fintype S] [MeasurableSpace S]\n [Fintype A] [MeasurableSpace Ω] (P : S → A → S → ℝ) (D : ℝ) : Prop :=\n IsDiameterUpperBound Ω P D ∧ ∀ D' : ℝ, IsDiameterUpperBound Ω P D' → D ≤ D'\n\n\ntheorem lemma6 {Ω : Type*} [MeasurableSpace Ω] [Fintype S] [Nonempty S] [DecidableEq S] [MeasurableSpace S] [MeasurableSingletonClass S] [Fintype A]\n (Pt P : S → A → S → ℝ) (h : S → ℝ) (s : S) (a : A) (Dt ε : ℝ)\n (hD : 0 ≤ Dt)\n (hP_nonneg : ∀ s', 0 ≤ P s a s') (hP_sum : ∑ s', P s a s' = 1)\n (hPt_nonneg : ∀ s', 0 ≤ Pt s a s') (hPt_sum : ∑ s', Pt s a s' = 1)\n (hP_prob : ∀ x b, (∀ y, 0 ≤ P x b y) ∧ ∑ y, P x b y = 1)\n (hPt_prob : ∀ x b, (∀ y, 0 ≤ Pt x b y) ∧ ∑ y, Pt x b y = 1)\n (hε : transL1 Pt P s a ≤ ε)\n (hspan : ∀ x y : S, h x - h y ≤ Dt)\n (hDiam : IsDiameterUpperBound Ω Pt Dt)\n (π : S → A → ℝ) (hπ_prob : ∀ x, (∀ a', 0 ≤ π x a') ∧ ∑ a', π x a' = 1)\n (r : S → A → ℝ) (hr_bound : ∀ x b, r x b ∈ Set.Icc (0:ℝ) 1)\n (Pπ : S → S → ℝ) (hPπ_def : ∀ x y, Pπ x y = ∑ a' : A, π x a' * Pt x a' y)\n (hPπ_prob : ∀ x, (∀ y, 0 ≤ Pπ x y) ∧ ∑ y, Pπ x y = 1)\n (rπ : S → ℝ) (hrπ_def : ∀ x, rπ x = ∑ a' : A, π x a' * r x a')\n (lam : ℝ)\n (hBellman : ∀ x, h x = rπ x - lam + ∑ y, Pπ x y * h y)\n (hErgodic : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∃ (d : S → ℝ) (C ρ : ℝ), 0 ≤ C ∧ 0 ≤ ρ ∧ ρ < 1 ∧\n ∀ t : ℕ, ∀ x : S,\n ∑ y, |((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y - d y|\n ≤ C * ρ ^ t)\n (hCommunicate : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∀ x y : S, ∃ t : ℕ,\n 0 < ((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y) :\n bellmanError Pt P h s a ≤ transL1 Pt P s a * biasSupNorm h\n ∧ |bellmanError Pt P h s a| ≤ Dt * min ε 2 := by\n sorry\n\ntheorem lemma11 {S A Ω : Type*} [Fintype S] [Nonempty S] [DecidableEq S]\n [MeasurableSpace S] [MeasurableSingletonClass S] [Fintype A]\n [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (r : S → A → ℝ) (hr_bound : ∀ s a, r s a ∈ Set.Icc (0 : ℝ) 1)\n (P : S → A → S → ℝ) (hP_prob : ∀ s a, (∀ s', 0 ≤ P s a s') ∧ ∑ s', P s a s' = 1)\n (π : S → A → ℝ)\n (hπ_prob : ∀ s, (∀ a, 0 ≤ π s a) ∧ ∑ a, π s a = 1)\n (hPπ : S → S → ℝ) (hPπ_def : ∀ s s', hPπ s s' = ∑ a : A, π s a * P s a s')\n (hPπ_prob : ∀ s, (∀ s', 0 ≤ hPπ s s') ∧ ∑ s', hPπ s s' = 1)\n (rπ : S → ℝ) (hrπ_def : ∀ s, rπ s = ∑ a : A, π s a * r s a)\n (lamPi : ℝ) (h : S → ℝ)\n (hBellman : ∀ s, h s = rπ s - lamPi + ∑ s', hPπ s s' * h s')\n (D : ℝ) (hD0 : 0 ≤ D)\n (X : S → ℕ → Ω → S) (hXmeas : ∀ s₀ t, Measurable (X s₀ t))\n (hXstart : ∀ s₀ : S, μ {ω | X s₀ 1 ω = s₀} = 1)\n (F : ℕ → MeasurableSpace Ω)\n (hFmono : Monotone F) (hFle : ∀ t, F t ≤ (inferInstance : MeasurableSpace Ω))\n (hXAdapted : ∀ s₀ : S, ∀ t t' : ℕ, t ≤ t' → Measurable[F t'] (X s₀ t))\n (hMarkov : ∀ s₀ : S, ∀ t : ℕ, 1 ≤ t → ∀ H : Set Ω, MeasurableSet[F t] H →\n ∀ x y : S, μ (H ∩ {ω | X s₀ t ω = x}) ≠ 0 →\n μ (H ∩ {ω | X s₀ t ω = x} ∩ {ω | X s₀ (t + 1) ω = y})\n = ENNReal.ofReal (hPπ x y) * μ (H ∩ {ω | X s₀ t ω = x}))\n (hD : IsDiameterUpperBound Ω P D)\n (hErgodic : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∃ (d : S → ℝ) (C ρ : ℝ), 0 ≤ C ∧ 0 ≤ ρ ∧ ρ < 1 ∧\n ∀ t : ℕ, ∀ x : S,\n ∑ y, |((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y - d y|\n ≤ C * ρ ^ t)\n (s s' : S) :\n h s - h s' ≤ D := by\n sorry\n\nnoncomputable def visitCount {S A Ω : Type*} [DecidableEq S] [DecidableEq A]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (t : ℕ) (s : S) (a : A) (ω : Ω) : ℕ :=\n ∑ t' ∈ Finset.Icc 1 t, if Sp t' ω = s ∧ Ap t' ω = a then 1 else 0\n\nnoncomputable def empTrans {S A Ω : Type*} [DecidableEq S] [DecidableEq A]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (t : ℕ) (s : S) (a : A) (s' : S) (ω : Ω) : ℝ :=\n (∑ t' ∈ Finset.Icc 1 t, if Sp t' ω = s ∧ Ap t' ω = a ∧ Sp (t' + 1) ω = s'\n then (1 : ℝ) else 0) / (visitCount Sp Ap t s a ω : ℝ)\n\ndef goodEvent {S A Ω : Type*} [Fintype S] [Fintype A] [DecidableEq S] [DecidableEq A]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (P : S → A → S → ℝ) (t T : ℕ) (ω : Ω) : Prop :=\n ∀ s : S, ∀ a : A,\n transL1 (fun s a s' => empTrans Sp Ap t s a s' ω) P s a\n ≤ Real.sqrt (14 * (Fintype.card S : ℝ) * Real.log (2 * (Fintype.card A : ℝ) * T)\n / max 1 (visitCount Sp Ap t s a ω : ℝ))\n\ntheorem lemma7 {S A Ω : Type*} [Fintype S] [Nonempty S] [Fintype A] [Nonempty A]\n [DecidableEq S] [DecidableEq A] [MeasurableSpace S] [MeasurableSpace A]\n [MeasurableSingletonClass S] [MeasurableSingletonClass A]\n [MeasurableSpace Ω]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A)\n (hSpmeas : ∀ t', Measurable (Sp t')) (hApmeas : ∀ t', Measurable (Ap t'))\n (ℱ : ℕ → MeasurableSpace Ω)\n (hFmono : Monotone ℱ) (hFle : ∀ t', ℱ t' ≤ (inferInstance : MeasurableSpace Ω))\n (hSpAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[ℱ t''] (Sp t'))\n (hApAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[ℱ t''] (Ap t'))\n (P : S → A → S → ��)\n (hP_prob : ∀ s a, (∀ s', 0 ≤ P s a s') ∧ ∑ s', P s a s' = 1)\n (hErgodic : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∃ (d : S → ℝ) (C ρ : ℝ), 0 ≤ C ∧ 0 ≤ ρ ∧ ρ < 1 ∧\n ∀ t : ℕ, ∀ x : S,\n ∑ y, |((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y - d y|\n ≤ C * ρ ^ t)\n (hCommunicate : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∀ x y : S, ∃ t : ℕ,\n 0 < ((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y)\n (hMarkov : ∀ t' : ℕ, ∀ H : Set Ω, MeasurableSet[ℱ t'] H →\n ∀ x : S, ∀ y1 : A, ∀ y2 : S,\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}) ≠ 0 →\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1} ∩ {ω | Sp (t' + 1) ω = y2})\n = ENNReal.ofReal (P x y1 y2) * μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}))\n (t T : ℕ) (ht : 1 ≤ t) (hT : t ≤ T) :\n μ {ω | ¬ goodEvent Sp Ap P t T ω} ≤ ENNReal.ofReal (1 / (20 * (t : ℝ) ^ 6)) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen scoped BigOperators\nopen MeasureTheory\n\nnamespace ResearchLevel\n\nvariable {S : Type*} {A : Type*}\n\nnoncomputable def bellmanError (Pt P : S → A → S → ℝ) (h : S → ℝ)\n [Fintype S] (s : S) (a : A) : ℝ :=\n ∑ s' : S, (Pt s a s' - P s a s') * h s'\n\nnoncomputable def transL1 (Pt P : S → A → S → ℝ)\n [Fintype S] (s : S) (a : A) : ℝ :=\n ∑ s' : S, |Pt s a s' - P s a s'|\n\nnoncomputable def biasSupNorm [Fintype S] [Nonempty S] (h : S → ℝ) : ℝ :=\n Finset.univ.sup' Finset.univ_nonempty (fun s' => |h s'|)\n\nnoncomputable def hitTime {S Ω : Type*} (X : ℕ → Ω → S) (s' : S) (ω : Ω) : ℕ :=\n sInf {t : ℕ | 1 ≤ t ∧ X t ω = s'}\n\ndef IsDiameterBoundOfChain {S Ω : Type*} [Fintype S] [MeasurableSpace Ω]\n (μ : Measure Ω) (X : S → ℕ → Ω → S) (D : ℝ) : Prop :=\n ∀ s s' : S, s ≠ s' →\n (∀ᵐ ω ∂μ, ∃ t : ℕ, 1 ≤ t ∧ X s t ω = s') ∧\n Integrable (fun ω => (hitTime (X s) s' ω : ℝ)) μ ∧\n ∫ ω, (hitTime (X s) s' ω : ℝ) ∂μ ≤ D\n\ndef IsDiameterUpperBound (Ω : Type*) {S A : Type*} [Fintype S] [MeasurableSpace S]\n [Fintype A] [MeasurableSpace Ω] (P : S → A → S → ℝ) (D : ℝ) : Prop :=\n ∀ (μ₂ : Measure Ω), IsProbabilityMeasure μ₂ →\n ∀ π₂ : S → A → ℝ, (∀ s, (∀ a, 0 ≤ π₂ s a) ∧ ∑ a, π₂ s a = 1) →\n ∀ (X₂ : S → ℕ → Ω → S) (F₂ : ℕ → MeasurableSpace Ω),\n (∀ s₀ t, Measurable (X₂ s₀ t)) →\n (∀ s₀ : S, μ₂ {ω | X₂ s₀ 1 ω = s₀} = 1) →\n Monotone F₂ → (∀ t, F₂ t ≤ (inferInstance : MeasurableSpace Ω)) →\n (∀ s₀ : S, ∀ t t' : ℕ, t ≤ t' → Measurable[F₂ t'] (X₂ s₀ t)) →\n (∀ s₀ : S, ∀ t : ℕ, 1 ≤ t → ∀ H : Set Ω, MeasurableSet[F₂ t] H →\n ∀ x y : S, μ₂ (H ∩ {ω | X₂ s₀ t ω = x}) ≠ 0 →\n μ₂ (H ∩ {ω | X₂ s₀ t ω = x} ∩ {ω | X₂ s₀ (t + 1) ω = y})\n = ENNReal.ofReal (∑ a : A, π₂ x a * P x a y)\n * μ₂ (H ∩ {ω | X₂ s₀ t ω = x})) →\n IsDiameterBoundOfChain μ₂ X₂ D\n\ndef IsDiameterBound (Ω : Type*) {S A : Type*} [Fintype S] [MeasurableSpace S]\n [Fintype A] [MeasurableSpace Ω] (P : S → A → S → ℝ) (D : ℝ) : Prop :=\n IsDiameterUpperBound Ω P D ∧ ∀ D' : ℝ, IsDiameterUpperBound Ω P D' → D ≤ D'\n\n\ntheorem lemma6 {Ω : Type*} [MeasurableSpace Ω] [Fintype S] [Nonempty S] [DecidableEq S] [MeasurableSpace S] [MeasurableSingletonClass S] [Fintype A]\n (Pt P : S → A → S → ℝ) (h : S → ℝ) (s : S) (a : A) (Dt ε : ℝ)\n (hD : 0 ≤ Dt)\n (hP_nonneg : ∀ s', 0 ≤ P s a s') (hP_sum : ∑ s', P s a s' = 1)\n (hPt_nonneg : ∀ s', 0 ≤ Pt s a s') (hPt_sum : ∑ s', Pt s a s' = 1)\n (hP_prob : ∀ x b, (∀ y, 0 ≤ P x b y) ∧ ∑ y, P x b y = 1)\n (hPt_prob : ∀ x b, (∀ y, 0 ≤ Pt x b y) ∧ ∑ y, Pt x b y = 1)\n (hε : transL1 Pt P s a ≤ ε)\n (hspan : ∀ x y : S, h x - h y ≤ Dt)\n (hDiam : IsDiameterUpperBound Ω Pt Dt)\n (π : S → A → ℝ) (hπ_prob : ∀ x, (∀ a', 0 ≤ π x a') ∧ ∑ a', π x a' = 1)\n (r : S → A → ℝ) (hr_bound : ∀ x b, r x b ∈ Set.Icc (0:ℝ) 1)\n (Pπ : S → S → ℝ) (hPπ_def : ∀ x y, Pπ x y = ∑ a' : A, π x a' * Pt x a' y)\n (hPπ_prob : ∀ x, (∀ y, 0 ≤ Pπ x y) ∧ ∑ y, Pπ x y = 1)\n (rπ : S → ℝ) (hrπ_def : ∀ x, rπ x = ∑ a' : A, π x a' * r x a')\n (lam : ℝ)\n (hBellman : ∀ x, h x = rπ x - lam + ∑ y, Pπ x y * h y)\n (hErgodic : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∃ (d : S → ℝ) (C ρ : ℝ), 0 ≤ C ∧ 0 ≤ ρ ∧ ρ < 1 ∧\n ∀ t : ℕ, ∀ x : S,\n ∑ y, |((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y - d y|\n ≤ C * ρ ^ t)\n (hCommunicate : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∀ x y : S, ∃ t : ℕ,\n 0 < ((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y) :\n bellmanError Pt P h s a ≤ transL1 Pt P s a * biasSupNorm h\n ∧ |bellmanError Pt P h s a| ≤ Dt * min ε 2 := by\n have hB0 : 0 ≤ biasSupNorm h := by\n have := Finset.le_sup' (fun s' => |h s'|) (Finset.mem_univ (Classical.arbitrary S))\n exact le_trans (abs_nonneg _) this\n have hL0 : 0 ≤ transL1 Pt P s a := Finset.sum_nonneg (fun i _ => abs_nonneg _)\n have hL2 : transL1 Pt P s a ≤ 2 := by\n have hkey : ∑ s' : S, |Pt s a s' - P s a s'| ≤ ∑ s' : S, (Pt s a s' + P s a s') := by\n refine Finset.sum_le_sum (fun i _ => ?_)\n calc |Pt s a i - P s a i| ≤ |Pt s a i| + |P s a i| := abs_sub _ _\n _ = Pt s a i + P s a i := by\n rw [abs_of_nonneg (hPt_nonneg i), abs_of_nonneg (hP_nonneg i)]\n rw [Finset.sum_add_distrib, hPt_sum, hP_sum] at hkey\n simpa [transL1] using hkey.trans (by norm_num)\n constructor\n · unfold bellmanError transL1 biasSupNorm\n rw [Finset.sum_mul]\n refine (Finset.sum_le_sum ?_)\n intro i _\n calc (Pt s a i - P s a i) * h i ≤ |(Pt s a i - P s a i) * h i| := le_abs_self _\n _ = |Pt s a i - P s a i| * |h i| := abs_mul _ _\n _ ≤ |Pt s a i - P s a i| * (Finset.univ.sup' Finset.univ_nonempty (fun s' => |h s'|)) := by\n apply mul_le_mul_of_nonneg_left _ (abs_nonneg _)\n exact Finset.le_sup' (fun s' => |h s'|) (Finset.mem_univ i)\n · -- The step the paper elides. Both kernels are probability distributions, so\n -- `∑ (Pt - P) = 0` and the Bellman error is unchanged by shifting h by a\n -- constant; that invariance is what lets the SPAN bound of Lemma 11 carry\n -- the estimate, and it is why a sup-norm bound is neither needed nor true.\n have hzero : ∑ s' : S, (Pt s a s' - P s a s') = 0 := by\n rw [Finset.sum_sub_distrib, hPt_sum, hP_sum, sub_self]\n have hshift : bellmanError Pt P h s a\n = ∑ s' : S, (Pt s a s' - P s a s') * (h s' - h s) := by\n unfold bellmanError\n have hsplit : ∑ s' : S, (Pt s a s' - P s a s') * (h s' - h s)\n = (∑ s' : S, (Pt s a s' - P s a s') * h s')\n - (∑ s' : S, (Pt s a s' - P s a s')) * h s := by\n rw [Finset.sum_mul, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [hsplit, hzero, zero_mul, sub_zero]\n have habs : |bellmanError Pt P h s a| ≤ transL1 Pt P s a * Dt := by\n rw [hshift]\n refine le_trans (Finset.abs_sum_le_sum_abs _ _) ?_\n unfold transL1\n rw [Finset.sum_mul]\n refine Finset.sum_le_sum (fun i _ => ?_)\n rw [abs_mul]\n refine mul_le_mul_of_nonneg_left ?_ (abs_nonneg _)\n exact abs_le.2 ⟨by linarith [hspan s i], hspan i s⟩\n have hmin : transL1 Pt P s a ≤ min ε 2 := le_min hε hL2\n calc |bellmanError Pt P h s a| ≤ transL1 Pt P s a * Dt := habs\n _ ≤ (min ε 2) * Dt := mul_le_mul_of_nonneg_right hmin hD\n _ = Dt * min ε 2 := mul_comm _ _\ndef avoidSet {S Ω : Type*} (Y : ℕ → Ω → S) (s' : S) : ℕ → Set Ω\n | 0 => Set.univ\n | (n+1) => avoidSet Y s' n ∩ {ω | Y (n+1) ω ≠ s'}\n\nlemma measure_split {Ω S : Type*} [MeasurableSpace Ω] [Fintype S] [MeasurableSpace S]\n [MeasurableSingletonClass S] (μ : Measure Ω) (f : Ω → S) (hf : Measurable f)\n (A : Set Ω) (hA : MeasurableSet A) :\n μ A = ∑ x : S, μ (A ∩ {ω | f ω = x}) := by\n have hcover : A = ⋃ x : S, (A ∩ {ω | f ω = x}) := by ext ω; simp\n have hdisj : Pairwise (Function.onFun Disjoint (fun x : S => A ∩ {ω | f ω = x})) := by\n intro x y hxy\n simp only [Function.onFun]\n rw [Set.disjoint_left]\n rintro ω ⟨-, hx⟩ ⟨-, hy⟩\n exact hxy (hx ▸ hy ▸ rfl)\n have hmeas : ∀ x : S, MeasurableSet (A ∩ {ω | f ω = x}) :=\n fun x => hA.inter (hf (measurableSet_singleton x))\n conv_lhs => rw [hcover]\n rw [measure_iUnion hdisj hmeas, tsum_fintype]\n\nlemma avoidSet_meas' {S Ω : Type*} [MeasurableSpace Ω] [MeasurableSpace S]\n [MeasurableSingletonClass S] (Y : ℕ → Ω → S) (hY : ∀ t, Measurable (Y t)) (s' : S) (n : ℕ) :\n MeasurableSet (avoidSet Y s' n) := by\n induction n with\n | zero => simp [avoidSet]\n | succ n ih =>\n refine MeasurableSet.inter ih ?_\n have h1 : MeasurableSet ((Y (n+1)) ⁻¹' {s'}) := (hY (n+1)) (measurableSet_singleton s')\n have h2 : {ω | Y (n+1) ω ≠ s'} = ((Y (n+1)) ⁻¹' {s'})ᶜ := by ext ω; simp\n rw [h2]; exact h1.compl\n\nlemma avoidSet_measF {S Ω : Type*} [MeasurableSpace Ω] [MeasurableSpace S]\n [MeasurableSingletonClass S] (Y : ℕ → Ω → S) (s' : S)\n (F : ℕ → MeasurableSpace Ω) (hAd : ∀ t t' : ℕ, t ≤ t' → Measurable[F t'] (Y t))\n (n t : ℕ) (hnt : n ≤ t) : MeasurableSet[F t] (avoidSet Y s' n) := by\n induction n with\n | zero => simp [avoidSet]\n | succ n ih =>\n refine MeasurableSet.inter (ih (by omega)) ?_\n have h1 : MeasurableSet[F t] ((Y (n+1)) ⁻¹' {s'}) :=\n hAd (n+1) t hnt (measurableSet_singleton s')\n have h2 : {ω | Y (n+1) ω ≠ s'} = ((Y (n+1)) ⁻¹' {s'})ᶜ := by ext ω; simp\n rw [h2]\n exact MeasurableSet.compl h1\n\nnoncomputable def qfun {S Ω : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) (Y : ℕ → Ω → S) (s' : S) (n : ℕ) (x : S) : ℝ :=\n (μ (avoidSet Y s' n ∩ {ω | Y n ω = x})).toReal\n\n\nlemma qfun_nonneg {S Ω : Type*} [Fintype S] [DecidableEq S] [MeasurableSpace S]\n [MeasurableSingletonClass S] [MeasurableSpace Ω] (μ : Measure Ω) (Y : ℕ → Ω → S) (s' : S) (n : ℕ) (x : S) :\n 0 ≤ qfun μ Y s' n x := ENNReal.toReal_nonneg\n\nlemma qfun_at_s' {S Ω : Type*} [Fintype S] [DecidableEq S] [MeasurableSpace S]\n [MeasurableSingletonClass S] [MeasurableSpace Ω] (μ : Measure Ω) (Y : ℕ → Ω → S) (s' : S) (n : ℕ) (hn : 1 ≤ n) :\n qfun μ Y s' n s' = 0 := by\n obtain ⟨m, rfl⟩ : ∃ m, n = m + 1 := ⟨n - 1, by omega⟩\n have : avoidSet Y s' (m+1) ∩ {ω | Y (m+1) ω = s'} = ∅ := by\n ext ω\n simp only [avoidSet, Set.mem_inter_iff, Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]\n rintro ⟨⟨-, h1⟩, h2⟩\n exact h1 h2\n simp [qfun, this]\n\nlemma qfun_one {S Ω : Type*} [Fintype S] [DecidableEq S] [MeasurableSpace S]\n [MeasurableSingletonClass S] [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (Y : ℕ → Ω → S)\n (hY : ∀ t, Measurable (Y t)) (s s' : S) (hss : s ≠ s') (hstart : μ {ω | Y 1 ω = s} = 1)\n (x : S) : qfun μ Y s' 1 x = if x = s then 1 else 0 := by\n by_cases hx : x = s\n · have hset : avoidSet Y s' 1 ∩ {ω | Y 1 ω = x} = {ω | Y 1 ω = s} := by\n ext ω\n simp only [avoidSet, Set.univ_inter, Set.mem_inter_iff, Set.mem_setOf_eq]\n constructor\n · rintro ⟨-, h⟩; rw [← hx]; exact h\n · intro h; rw [hx]; exact ⟨by rw [h]; exact hss, h⟩\n rw [qfun, hset, hstart, if_pos hx, ENNReal.toReal_one]\n · have hzero : μ {ω | Y 1 ω = x} = 0 := by\n have hsub : {ω | Y 1 ω = x} ⊆ {ω | Y 1 ω = s}ᶜ := by\n intro ω hω\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq]\n intro hc\n exact hx (by rw [← hω, hc])\n have hm : MeasurableSet {ω | Y 1 ω = s} := (hY 1) (measurableSet_singleton s)\n have hc : μ ({ω | Y 1 ω = s}ᶜ) = 0 := by\n rw [measure_compl hm (measure_ne_top μ _), hstart]\n simp\n exact le_antisymm (le_trans (measure_mono hsub) (le_of_eq hc)) (zero_le _)\n have : μ (avoidSet Y s' 1 ∩ {ω | Y 1 ω = x}) = 0 :=\n le_antisymm (le_trans (measure_mono Set.inter_subset_right) (le_of_eq hzero)) (zero_le _)\n simp [qfun, this, hx]\n\nlemma qfun_sum {S Ω : Type*} [Fintype S] [DecidableEq S] [MeasurableSpace S]\n [MeasurableSingletonClass S] [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (Y : ℕ → Ω → S)\n (hY : ∀ t, Measurable (Y t)) (s' : S) (n : ℕ) :\n ∑ x : S, qfun μ Y s' n x = (μ (avoidSet Y s' n)).toReal := by\n simp only [qfun]\n rw [measure_split μ (Y n) (hY n) _ (avoidSet_meas' Y hY s' n)]\n rw [ENNReal.toReal_sum (fun x _ => measure_ne_top μ _)]\n\n\nlemma qfun_rec {S Ω : Type*} [Fintype S] [DecidableEq S] [MeasurableSpace S]\n [MeasurableSingletonClass S] [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (Y : ℕ → Ω → S)\n (hY : ∀ t, Measurable (Y t)) (s' : S)\n (F : ℕ → MeasurableSpace Ω) (hAd : ∀ t t' : ℕ, t ≤ t' → Measurable[F t'] (Y t))\n (Pp : S → S → ℝ) (hPp0 : ∀ x y, 0 ≤ Pp x y)\n (hMarkov : ∀ t : ℕ, 1 ≤ t → ∀ H : Set Ω, MeasurableSet[F t] H → ∀ x y : S,\n μ (H ∩ {ω | Y t ω = x}) ≠ 0 →\n μ (H ∩ {ω | Y t ω = x} ∩ {ω | Y (t+1) ω = y})\n = ENNReal.ofReal (Pp x y) * μ (H ∩ {ω | Y t ω = x}))\n (n : ℕ) (hn : 1 ≤ n) (x : S) :\n qfun μ Y s' (n+1) x\n = ∑ y : S, (if y = s' ∨ x = s' then 0 else Pp y x) * qfun μ Y s' n y := by\n by_cases hx : x = s'\n · rw [hx, qfun_at_s' μ Y s' (n+1) (by omega)]\n rw [Finset.sum_eq_zero]\n intro y _\n rw [if_pos (Or.inr rfl), zero_mul]\n · have hstep : ∀ y : S,\n μ ((avoidSet Y s' n ∩ {ω | Y n ω = y}) ∩ {ω | Y (n+1) ω = x})\n = ENNReal.ofReal (Pp y x) * μ (avoidSet Y s' n ∩ {ω | Y n ω = y}) := by\n intro y\n by_cases hz : μ (avoidSet Y s' n ∩ {ω | Y n ω = y}) = 0\n · rw [hz, mul_zero]\n exact le_antisymm (le_trans (measure_mono Set.inter_subset_left) (le_of_eq hz)) (zero_le _)\n · exact hMarkov n hn (avoidSet Y s' n) (avoidSet_measF Y s' F hAd n n le_rfl) y x hz\n have hset1 : avoidSet Y s' (n+1) ∩ {ω | Y (n+1) ω = x}\n = avoidSet Y s' n ∩ {ω | Y (n+1) ω = x} := by\n ext ω\n simp only [avoidSet, Set.mem_inter_iff, Set.mem_setOf_eq]\n constructor\n · rintro ⟨⟨h1, -⟩, h2⟩; exact ⟨h1, h2⟩\n · rintro ⟨h1, h2⟩; exact ⟨⟨h1, by rw [h2]; exact hx⟩, h2⟩\n have hEN : μ (avoidSet Y s' (n+1) ∩ {ω | Y (n+1) ω = x})\n = ∑ y : S, ENNReal.ofReal (Pp y x) * μ (avoidSet Y s' n ∩ {ω | Y n ω = y}) := by\n rw [hset1]\n rw [measure_split μ (Y n) (hY n) (avoidSet Y s' n ∩ {ω | Y (n+1) ω = x})\n ((avoidSet_meas' Y hY s' n).inter ((hY (n+1)) (measurableSet_singleton x)))]\n refine Finset.sum_congr rfl (fun y _ => ?_)\n rw [← hstep y]\n congr 1\n ext ω\n simp only [Set.mem_inter_iff]\n tauto\n rw [qfun, hEN, ENNReal.toReal_sum (fun y _ => by\n exact ENNReal.mul_ne_top ENNReal.ofReal_ne_top (measure_ne_top μ _))]\n refine Finset.sum_congr rfl (fun y _ => ?_)\n rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal (hPp0 y x)]\n by_cases hy : y = s'\n · rw [if_pos (Or.inl hy), zero_mul]\n have hz : (μ (avoidSet Y s' n ∩ {ω | Y n ω = y})).toReal = 0 := by\n rw [hy]; exact qfun_at_s' μ Y s' n hn\n rw [hz, mul_zero]\n · rw [if_neg (by tauto)]\n rfl\n\n\nlemma avoidSet_mem {S Ω : Type*} (Y : ℕ → Ω → S) (s' : S) (n : ℕ) (ω : Ω) :\n ω ∈ avoidSet Y s' n ↔ ∀ i, 1 ≤ i → i ≤ n → Y i ω ≠ s' := by\n induction n with\n | zero => simp [avoidSet]; omega\n | succ n ih =>\n simp only [avoidSet, Set.mem_inter_iff, Set.mem_setOf_eq, ih]\n constructor\n · rintro ⟨h1, h2⟩ i hi1 hi2\n rcases Nat.lt_or_ge i (n+1) with h | h\n · exact h1 i hi1 (by omega)\n · have : i = n + 1 := by omega\n subst this; exact h2\n · intro h\n exact ⟨fun i hi1 hi2 => h i hi1 (by omega), h (n+1) (by omega) le_rfl⟩\n\nlemma abstract_span {S : Type*} [Fintype S] [DecidableEq S]\n (Q : S → S → ℝ) (k c : S → ℝ) (hfix : ∀ x, k x = c x + ∑ y, Q x y * k y)\n (hc : ∀ x, c x ≤ 1)\n (qr : ℕ → S → ℝ) (hq0 : ∀ n x, 0 ≤ qr n x)\n (s : S) (hq1 : ∀ x, qr 1 x = if x = s then 1 else 0)\n (hrec : ∀ n, 1 ≤ n → ∀ x, qr (n+1) x = ∑ y, Q y x * qr n y)\n (D : ℝ) (hD : ∀ n : ℕ, ∑ i ∈ Finset.range n, (∑ y, qr (i+1) y) ≤ D) :\n k s ≤ D := by\n haveI : Nonempty S := ⟨s⟩\n set M : ℝ := Finset.univ.sup' Finset.univ_nonempty (fun y => |k y|) with hMdef\n have hMk' : ∀ y, |k y| ≤ M := by\n intro y; rw [hMdef]; exact Finset.le_sup' (fun y => |k y|) (Finset.mem_univ y)\n have hM0 : 0 ≤ M := le_trans (abs_nonneg (k s)) (hMk' s)\n have hMk : ∀ y, k y ≤ M := fun y => le_trans (le_abs_self _) (hMk' y)\n set b : ℕ → ℝ := fun n => ∑ y, qr (n+1) y * k y with hbdef\n set a : ℕ → ℝ := fun n => ∑ y, qr (n+1) y * c y with hadef\n set ρ : ℕ → ℝ := fun n => ∑ y, qr (n+1) y with hρdef\n have hb0 : b 0 = k s := by\n simp only [hbdef, hq1]\n rw [Finset.sum_congr rfl (fun x _ => by rw [ite_mul, one_mul, zero_mul] :\n ∀ x ∈ Finset.univ, (if x = s then (1:ℝ) else 0) * k x = if x = s then k x else 0)]\n simp\n have hstep : ∀ n, b n = a n + b (n+1) := by\n intro n\n have h1 : b n = a n + ∑ y, ∑ x, (qr (n+1) y * Q y x) * k x := by\n simp only [hbdef, hadef, ← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl (fun y _ => ?_)\n rw [hfix y, mul_add, Finset.mul_sum]\n congr 1\n exact Finset.sum_congr rfl (fun x _ => by ring)\n rw [h1]\n congr 1\n rw [Finset.sum_comm]\n simp only [hbdef]\n refine Finset.sum_congr rfl (fun x _ => ?_)\n rw [hrec (n+1) (by omega) x, Finset.sum_mul]\n refine Finset.sum_congr rfl (fun y _ => by ring)\n have hmain : ∀ n, k s = (∑ i ∈ Finset.range n, a i) + b n := by\n intro n\n induction n with\n | zero => simp [hb0]\n | succ n ih => rw [Finset.sum_range_succ, ih, hstep n]; ring\n have haρ : ∀ i, a i ≤ ρ i := by\n intro i\n simp only [hadef, hρdef]\n refine Finset.sum_le_sum (fun y _ => ?_)\n calc qr (i+1) y * c y ≤ qr (i+1) y * 1 := by\n exact mul_le_mul_of_nonneg_left (hc y) (hq0 _ _)\n _ = qr (i+1) y := mul_one _\n have hbρ : ∀ n, b n ≤ M * ρ n := by\n intro n\n simp only [hbdef, hρdef, Finset.mul_sum]\n refine Finset.sum_le_sum (fun y _ => ?_)\n rw [mul_comm M]\n exact mul_le_mul_of_nonneg_left (hMk y) (hq0 _ _)\n have hρ0 : ∀ n, 0 ≤ ρ n := fun n => Finset.sum_nonneg (fun y _ => hq0 _ _)\n have key : ∀ ε : ℝ, 0 < ε → k s ≤ D + M * ε := by\n intro ε hε\n obtain ⟨n, hn⟩ : ∃ n, ρ n ≤ ε := by\n by_contra hcon\n push_neg at hcon\n obtain ⟨N, hN⟩ := exists_nat_gt ((|D|+1)/ε)\n have h1 : (N:ℝ) * ε ≤ ∑ i ∈ Finset.range N, ρ i := by\n calc (N:ℝ) * ε = ∑ _i ∈ Finset.range N, ε := by\n rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul]\n _ ≤ ∑ i ∈ Finset.range N, ρ i :=\n Finset.sum_le_sum (fun i _ => le_of_lt (hcon i))\n have h2 : ∑ i ∈ Finset.range N, ρ i ≤ D := hD N\n have h3 : (|D|+1)/ε < N := hN\n have h4 : |D| + 1 < N * ε := by\n rw [div_lt_iff₀ hε] at h3; linarith\n have : D < D := by\n have := le_trans h1 h2\n have hD' : D ≤ |D| := le_abs_self D\n linarith\n exact lt_irrefl _ this\n calc k s = (∑ i ∈ Finset.range n, a i) + b n := hmain n\n _ ≤ (∑ i ∈ Finset.range n, ρ i) + M * ρ n :=\n add_le_add (Finset.sum_le_sum (fun i _ => haρ i)) (hbρ n)\n _ ≤ D + M * ε := by\n have := hD n\n have : M * ρ n ≤ M * ε := mul_le_mul_of_nonneg_left hn hM0\n linarith [hD n]\n by_contra hcon\n push_neg at hcon\n have hM1 : (0:ℝ) < M + 1 := by linarith\n have h5 := key ((k s - D)/(M+1)) (div_pos (by linarith) hM1)\n have : M * ((k s - D)/(M+1)) < (k s - D) := by\n rw [mul_div_assoc']\n rw [div_lt_iff₀ hM1]\n nlinarith\n linarith\n\n\n-- the integral bound\nlemma sum_avoid_le {S Ω : Type*} [MeasurableSpace Ω] [MeasurableSpace S]\n [MeasurableSingletonClass S] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (Y : ℕ → Ω → S) (hY : ∀ t, Measurable (Y t)) (s' : S)\n (hae : ∀ᵐ ω ∂μ, ∃ t : ℕ, 1 ≤ t ∧ Y t ω = s')\n (hint : Integrable (fun ω => (hitTime Y s' ω : ℝ)) μ)\n (D : ℝ) (hD : ∫ ω, (hitTime Y s' ω : ℝ) ∂μ ≤ D) (n : ℕ) :\n ∑ i ∈ Finset.range n, (μ (avoidSet Y s' (i+1))).toReal ≤ D := by\n set g : Ω → ℝ := fun ω => ∑ i ∈ Finset.range n,\n Set.indicator (avoidSet Y s' (i+1)) (fun _ => (1:ℝ)) ω with hg\n have hmeasA : ∀ i, MeasurableSet (avoidSet Y s' i) := avoidSet_meas' Y hY s'\n have hintg : Integrable g μ := by\n refine integrable_finset_sum _ (fun i _ => ?_)\n exact (integrable_const (1:ℝ)).indicator (hmeasA (i+1))\n have hgint : ∫ ω, g ω ∂μ = ∑ i ∈ Finset.range n, (μ (avoidSet Y s' (i+1))).toReal := by\n rw [hg]\n rw [integral_finset_sum _ (fun i _ => (integrable_const (1:ℝ)).indicator (hmeasA (i+1)))]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [integral_indicator_const (1:ℝ) (hmeasA (i+1))]\n simp [measureReal_def]\n have hle : g ≤ᵐ[μ] fun ω => (hitTime Y s' ω : ℝ) := by\n filter_upwards [hae] with ω hω\n have hne : {t : ℕ | 1 ≤ t ∧ Y t ω = s'}.Nonempty := hω\n have hmem : hitTime Y s' ω ∈ {t : ℕ | 1 ≤ t ∧ Y t ω = s'} := Nat.sInf_mem hne\n set τ := hitTime Y s' ω with hτ\n have hτ1 : 1 ≤ τ := hmem.1\n have hτ2 : Y τ ω = s' := hmem.2\n have hstep : ∀ i, ω ∈ avoidSet Y s' (i+1) → i < τ := by\n intro i hi\n rw [avoidSet_mem] at hi\n by_contra hcon\n push_neg at hcon\n exact hi τ hτ1 (by omega) hτ2\n calc g ω ≤ ∑ i ∈ Finset.range n, (if i < τ then (1:ℝ) else 0) := by\n refine Finset.sum_le_sum (fun i _ => ?_)\n by_cases hmem2 : ω ∈ avoidSet Y s' (i+1)\n · rw [Set.indicator_of_mem hmem2, if_pos (hstep i hmem2)]\n · rw [Set.indicator_of_notMem hmem2]\n positivity\n _ ≤ (τ : ℝ) := by\n rw [Finset.sum_boole]\n have hsub : (Finset.range n).filter (fun i => i < τ) ⊆ Finset.range τ := by\n intro i hi\n simp only [Finset.mem_filter, Finset.mem_range] at hi ⊢\n exact hi.2\n have := Finset.card_le_card hsub\n rw [Finset.card_range] at this\n exact_mod_cast this\n calc ∑ i ∈ Finset.range n, (μ (avoidSet Y s' (i+1))).toReal = ∫ ω, g ω ∂μ := hgint.symm\n _ ≤ ∫ ω, (hitTime Y s' ω : ℝ) ∂μ := integral_mono_ae hintg hint hle\n _ ≤ D := hD\n\n\n\nlemma span_core {S Ω : Type*} [Fintype S] [DecidableEq S] [MeasurableSpace S]\n [MeasurableSingletonClass S] [MeasurableSpace Ω]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (Y : ℕ → Ω → S) (hY : ∀ t, Measurable (Y t))\n (F : ℕ → MeasurableSpace Ω) (hAd : ∀ t t' : ℕ, t ≤ t' → Measurable[F t'] (Y t))\n (Pp : S → S → ℝ) (hPp0 : ∀ x y, 0 ≤ Pp x y) (hPp1 : ∀ x, ∑ y, Pp x y = 1)\n (hMarkov : ∀ t : ℕ, 1 ≤ t → ∀ H : Set Ω, MeasurableSet[F t] H → ∀ x y : S,\n μ (H ∩ {ω | Y t ω = x}) ≠ 0 →\n μ (H ∩ {ω | Y t ω = x} ∩ {ω | Y (t+1) ω = y})\n = ENNReal.ofReal (Pp x y) * μ (H ∩ {ω | Y t ω = x}))\n (s s' : S) (hss : s ≠ s') (hstart : μ {ω | Y 1 ω = s} = 1)\n (hae : ∀ᵐ ω ∂μ, ∃ t : ℕ, 1 ≤ t ∧ Y t ω = s')\n (hint : Integrable (fun ω => (hitTime Y s' ω : ℝ)) μ)\n (D : ℝ) (hD : ∫ ω, (hitTime Y s' ω : ℝ) ∂μ ≤ D)\n (k c : S → ℝ) (hks' : k s' = 0) (hc1 : ∀ x, c x ≤ 1)\n (hfix : ∀ x, x ≠ s' → k x = c x + ∑ y, Pp x y * k y) :\n k s ≤ D := by\n classical\n refine abstract_span (fun x y => if x = s' ∨ y = s' then 0 else Pp x y) k\n (fun x => if x = s' then 0 else c x) ?_ ?_ (qfun μ Y s') (qfun_nonneg μ Y s') s ?_ ?_ D ?_\n · -- fixed point\n intro x\n dsimp only\n by_cases hx : x = s'\n · rw [if_pos hx, hx, hks', zero_add, Finset.sum_eq_zero]\n intro y _\n rw [if_pos (Or.inl rfl), zero_mul]\n · rw [if_neg hx, hfix x hx]\n congr 1\n refine Finset.sum_congr rfl (fun y _ => ?_)\n by_cases hy : y = s'\n · rw [if_pos (Or.inr hy), zero_mul, hy, hks', mul_zero]\n · rw [if_neg (by tauto)]\n · -- c ≤ 1\n intro x\n dsimp only\n by_cases hx : x = s'\n · rw [if_pos hx]; norm_num\n · rw [if_neg hx]; exact hc1 x\n · exact qfun_one μ Y hY s s' hss hstart\n · intro n hn x\n exact qfun_rec μ Y hY s' F hAd Pp hPp0 hMarkov n hn x\n · intro n\n have : ∀ i ∈ Finset.range n, (∑ y, qfun μ Y s' (i+1) y) = (μ (avoidSet Y s' (i+1))).toReal :=\n fun i _ => qfun_sum μ Y hY s' (i+1)\n rw [Finset.sum_congr rfl this]\n exact sum_avoid_le μ Y hY s' hae hint D hD n\n\n\ntheorem lemma11 {S A Ω : Type*} [Fintype S] [Nonempty S] [DecidableEq S]\n [MeasurableSpace S] [MeasurableSingletonClass S] [Fintype A]\n [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (r : S → A → ℝ) (hr_bound : ∀ s a, r s a ∈ Set.Icc (0 : ℝ) 1)\n (P : S → A → S → ℝ) (hP_prob : ∀ s a, (∀ s', 0 ≤ P s a s') ∧ ∑ s', P s a s' = 1)\n (π : S → A → ℝ)\n (hπ_prob : ∀ s, (∀ a, 0 ≤ π s a) ∧ ∑ a, π s a = 1)\n (hPπ : S → S → ℝ) (hPπ_def : ∀ s s', hPπ s s' = ∑ a : A, π s a * P s a s')\n (hPπ_prob : ∀ s, (∀ s', 0 ≤ hPπ s s') ∧ ∑ s', hPπ s s' = 1)\n (rπ : S → ℝ) (hrπ_def : ∀ s, rπ s = ∑ a : A, π s a * r s a)\n (lamPi : ℝ) (h : S → ℝ)\n (hBellman : ∀ s, h s = rπ s - lamPi + ∑ s', hPπ s s' * h s')\n (D : ℝ) (hD0 : 0 ≤ D)\n (X : S → ℕ → Ω → S) (hXmeas : ∀ s₀ t, Measurable (X s₀ t))\n (hXstart : ∀ s₀ : S, μ {ω | X s₀ 1 ω = s₀} = 1)\n (F : ℕ → MeasurableSpace Ω)\n (hFmono : Monotone F) (hFle : ∀ t, F t ≤ (inferInstance : MeasurableSpace Ω))\n (hXAdapted : ∀ s₀ : S, ∀ t t' : ℕ, t ≤ t' → Measurable[F t'] (X s₀ t))\n (hMarkov : ∀ s₀ : S, ∀ t : ℕ, 1 ≤ t → ∀ H : Set Ω, MeasurableSet[F t] H →\n ∀ x y : S, μ (H ∩ {ω | X s₀ t ω = x}) ≠ 0 →\n μ (H ∩ {ω | X s₀ t ω = x} ∩ {ω | X s₀ (t + 1) ω = y})\n = ENNReal.ofReal (hPπ x y) * μ (H ∩ {ω | X s₀ t ω = x}))\n (hD : IsDiameterUpperBound Ω P D)\n (hErgodic : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∃ (d : S → ℝ) (C ρ : ℝ), 0 ≤ C ∧ 0 ≤ ρ ∧ ρ < 1 ∧\n ∀ t : ℕ, ∀ x : S,\n ∑ y, |((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y - d y|\n ≤ C * ρ ^ t)\n (s s' : S) :\n h s - h s' ≤ D := by\n classical\n by_cases hss : s = s'\n · rw [hss]; simpa using hD0\n -- lamPi ≥ 0\n obtain ⟨x₀, -, hx₀⟩ := Finset.exists_min_image (Finset.univ : Finset S) h Finset.univ_nonempty\n have hlam0 : 0 ≤ lamPi := by\n have h1 : h x₀ ≤ ∑ y, hPπ x₀ y * h y := by\n calc h x₀ = ∑ y, hPπ x₀ y * h x₀ := by\n rw [← Finset.sum_mul, (hPπ_prob x₀).2, one_mul]\n _ ≤ ∑ y, hPπ x₀ y * h y :=\n Finset.sum_le_sum (fun y _ =>\n mul_le_mul_of_nonneg_left (hx₀ y (Finset.mem_univ y)) ((hPπ_prob x₀).1 y))\n have h2 := hBellman x₀\n have h3 : 0 ≤ rπ x₀ := by\n rw [hrπ_def]\n exact Finset.sum_nonneg (fun a _ => mul_nonneg ((hπ_prob x₀).1 a) (hr_bound x₀ a).1)\n linarith\n have hrπ1 : ∀ x, rπ x ≤ 1 := by\n intro x\n rw [hrπ_def]\n calc ∑ a, π x a * r x a ≤ ∑ a : A, π x a * 1 :=\n Finset.sum_le_sum (fun a _ => mul_le_mul_of_nonneg_left (hr_bound x a).2 ((hπ_prob x).1 a))\n _ = 1 := by rw [← Finset.sum_mul, (hπ_prob x).2, one_mul]\n -- the chain bound\n have hchain : IsDiameterBoundOfChain μ X D := by\n refine hD μ inferInstance π hπ_prob X F hXmeas hXstart hFmono hFle hXAdapted ?_\n intro s₀ t ht H hH x y hne\n rw [← hPπ_def]\n exact hMarkov s₀ t ht H hH x y hne\n obtain ⟨hae, hint, hDle⟩ := hchain s s' hss\n refine span_core μ (X s) (hXmeas s) F (hXAdapted s) hPπ (fun x y => (hPπ_prob x).1 y)\n (fun x => (hPπ_prob x).2) (hMarkov s) s s' hss (hXstart s) hae hint D hDle\n (fun x => h x - h s') (fun x => rπ x - lamPi) (by ring) ?_ ?_\n · intro x; have := hrπ1 x; linarith\n · intro x _\n have hb := hBellman x\n have : ∑ y, hPπ x y * (h y - h s') = (∑ y, hPπ x y * h y) - h s' := by\n have : ∑ y, hPπ x y * (h y - h s') = (∑ y, hPπ x y * h y) - (∑ y, hPπ x y) * h s' := by\n rw [Finset.sum_mul, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun y _ => by ring)\n rw [this, (hPπ_prob x).2, one_mul]\n rw [this]\n linarith [hBellman x]\n\n\nsection ConcAux\nset_option linter.unusedSectionVars false\n\nnoncomputable def dmeas {S : Type*} [Fintype S] [MeasurableSpace S] (p : S → ℝ) : Measure S :=\n ∑ x : S, (ENNReal.ofReal (p x)) • Measure.dirac x\n\nlemma dmeas_apply {S : Type*} [Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S]\n (p : S → ℝ) (A : Set S) :\n dmeas p A = ∑ x : S, (ENNReal.ofReal (p x)) * A.indicator (fun _ => (1:ENNReal)) x := by\n classical\n rw [dmeas, Measure.coe_finset_sum]\n simp only [Finset.sum_apply, Measure.smul_apply, smul_eq_mul]\n refine Finset.sum_congr rfl (fun x _ => ?_)\n rw [Measure.dirac_apply']\n · rfl\n · exact MeasurableSet.of_discrete\n\nlemma dmeas_prob {S : Type*} [Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S]\n (p : S → ℝ) (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1) : IsProbabilityMeasure (dmeas p) := by\n constructor\n rw [dmeas_apply]\n simp only [Set.indicator_univ, mul_one]\n rw [← ENNReal.ofReal_sum_of_nonneg (fun x _ => hp0 x), hp1, ENNReal.ofReal_one]\n\nlemma dmeas_integral {S : Type*} [Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S]\n (p : S → ℝ) (hp0 : ∀ x, 0 ≤ p x) (f : S → ℝ) :\n ∫ x, f x ∂(dmeas p) = ∑ x : S, p x * f x := by\n classical\n rw [dmeas, integral_finset_sum_measure (fun i _ => by\n refine Integrable.smul_measure ?_ (by simp)\n exact (integrable_dirac (f := f) (a := i)) (by simp [enorm_eq_nnnorm]) )]\n refine Finset.sum_congr rfl (fun x _ => ?_)\n rw [integral_smul_measure, integral_dirac, ENNReal.toReal_ofReal (hp0 x), smul_eq_mul]\n\n/-- Hoeffding's lemma for a finitely supported distribution. -/\nlemma finite_hoeffding {S : Type*} [Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S]\n (p : S → ℝ) (hp0 : ∀ x, 0 ≤ p x) (hp1 : ∑ x, p x = 1)\n (f : S → ℝ) (a b : ℝ) (hab : ∀ x, f x ∈ Set.Icc a b) (hmean : ∑ x, p x * f x = 0)\n (lam : ℝ) (hlam : 0 < lam) :\n ∑ x, p x * Real.exp (lam * f x) ≤ Real.exp ((b - a) ^ 2 * lam ^ 2 / 8) := by\n classical\n haveI : IsProbabilityMeasure (dmeas p) := dmeas_prob p hp0 hp1\n haveI : Nonempty S := by\n by_contra hc\n rw [not_nonempty_iff] at hc\n simp at hp1\n have hba : a ≤ b := le_trans (hab (Classical.arbitrary S)).1 (hab (Classical.arbitrary S)).2\n have key := ProbabilityTheory.mgf_le_of_mem_Icc_of_integral_eq_zero\n (μ := dmeas p) (X := f) (a := a) (b := b) (t := lam)\n (Measurable.of_discrete).aemeasurable\n (Filter.Eventually.of_forall hab)\n (by rw [dmeas_integral p hp0]; exact hmean) hlam\n rw [ProbabilityTheory.mgf] at key\n rw [dmeas_integral p hp0] at key\n refine le_trans key (le_of_eq ?_)\n congr 1\n have hn : ‖b - a‖ = b - a := by\n rw [Real.norm_eq_abs]\n exact abs_of_nonneg (by linarith)\n push_cast\n rw [hn]\n ring\n\n\nsection Hist\nvariable {S A Ω : Type*} [Fintype S] [Nonempty S] [Fintype A] [Nonempty A]\n [MeasurableSpace S] [MeasurableSpace A]\n [MeasurableSingletonClass S] [MeasurableSingletonClass A] [MeasurableSpace Ω]\n\nnoncomputable def SpH {n : ℕ} (h : Fin n → S × A) (i : ℕ) : S :=\n if hi : i - 1 < n then (h ⟨i - 1, hi⟩).1 else Classical.arbitrary S\n\nnoncomputable def ApH {n : ℕ} (h : Fin n → S × A) (i : ℕ) : A :=\n if hi : i - 1 < n then (h ⟨i - 1, hi⟩).2 else Classical.arbitrary A\n\nlemma SpH_snoc {n : ℕ} (h : Fin n → S × A) (y : S × A) (i : ℕ) (hi : i - 1 < n) :\n SpH (Fin.snoc h y) i = SpH h i := by\n have hi' : i - 1 < n + 1 := by omega\n rw [SpH, SpH, dif_pos hi', dif_pos hi]\n congr 1\n have : (⟨i - 1, hi'⟩ : Fin (n+1)) = Fin.castSucc ⟨i - 1, hi⟩ := rfl\n rw [this, Fin.snoc_castSucc]\n\nlemma ApH_snoc {n : ℕ} (h : Fin n → S × A) (y : S × A) (i : ℕ) (hi : i - 1 < n) :\n ApH (Fin.snoc h y) i = ApH h i := by\n have hi' : i - 1 < n + 1 := by omega\n rw [ApH, ApH, dif_pos hi', dif_pos hi]\n congr 1\n have : (⟨i - 1, hi'⟩ : Fin (n+1)) = Fin.castSucc ⟨i - 1, hi⟩ := rfl\n rw [this, Fin.snoc_castSucc]\n\nlemma SpH_snoc_last {n : ℕ} (h : Fin n → S × A) (y : S × A) :\n SpH (Fin.snoc h y) (n + 1) = y.1 := by\n have hi' : (n + 1) - 1 < n + 1 := by omega\n rw [SpH, dif_pos hi']\n congr 1\n have : (⟨(n+1) - 1, hi'⟩ : Fin (n+1)) = Fin.last n := by apply Fin.ext; simp\n rw [this, Fin.snoc_last]\n\nlemma ApH_snoc_last {n : ℕ} (h : Fin n → S × A) (y : S × A) :\n ApH (Fin.snoc h y) (n + 1) = y.2 := by\n have hi' : (n + 1) - 1 < n + 1 := by omega\n rw [ApH, dif_pos hi']\n congr 1\n have : (⟨(n+1) - 1, hi'⟩ : Fin (n+1)) = Fin.last n := by apply Fin.ext; simp\n rw [this, Fin.snoc_last]\n\nlemma sum_snoc {M : Type*} [AddCommMonoid M] {α : Type*} [Fintype α] (n : ℕ)\n (F : (Fin (n+1) → α) → M) :\n ∑ h : Fin (n+1) → α, F h = ∑ h' : Fin n → α, ∑ y : α, F (Fin.snoc h' y) := by\n rw [← Equiv.sum_comp (Fin.snocEquiv (fun _ => α)) F, Fintype.sum_prod_type, Finset.sum_comm]\n rfl\n\nvariable (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A)\n\ndef cyl {n : ℕ} (h : Fin n → S × A) : Set Ω :=\n {ω | ∀ i ∈ Finset.Icc 1 n, Sp i ω = SpH h i ∧ Ap i ω = ApH h i}\n\nlemma cyl_zero (h : Fin 0 → S × A) : cyl Sp Ap h = Set.univ := by\n ext ω; simp [cyl]\n\nlemma cyl_snoc {n : ℕ} (h : Fin n → S × A) (y : S × A) :\n cyl Sp Ap (Fin.snoc h y) =\n (cyl Sp Ap h ∩ {ω | Sp (n+1) ω = y.1}) ∩ {ω | Ap (n+1) ω = y.2} := by\n ext ω\n simp only [cyl, Set.mem_inter_iff, Set.mem_setOf_eq, Finset.mem_Icc]\n constructor\n · intro hh\n refine ⟨⟨fun i hi => ?_, ?_⟩, ?_⟩\n · have hi' : i - 1 < n := by omega\n have := hh i (by omega)\n rw [SpH_snoc h y i hi', ApH_snoc h y i hi'] at this\n exact this\n · have := (hh (n+1) (by omega)).1\n rwa [SpH_snoc_last] at this\n · have := (hh (n+1) (by omega)).2\n rwa [ApH_snoc_last] at this\n · rintro ⟨⟨h1, h2⟩, h3⟩ i hi\n rcases Nat.lt_or_ge i (n+1) with hlt | hge\n · have hi' : i - 1 < n := by omega\n rw [SpH_snoc h y i hi', ApH_snoc h y i hi']\n exact h1 i (by omega)\n · have : i = n + 1 := by omega\n subst this\n rw [SpH_snoc_last, ApH_snoc_last]\n exact ⟨h2, h3⟩\n\nlemma cyl_meas (F : ℕ → MeasurableSpace Ω)\n (hSpAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Sp t'))\n (hApAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Ap t'))\n {n : ℕ} (h : Fin n → S × A) (m : ℕ) (hnm : n ≤ m) :\n MeasurableSet[F m] (cyl Sp Ap h) := by\n have : cyl Sp Ap h = ⋂ i ∈ ((Finset.Icc 1 n : Finset ℕ) : Set ℕ),\n ({ω | Sp i ω = SpH h i} ∩ {ω | Ap i ω = ApH h i}) := by\n ext ω; simp [cyl, Set.mem_iInter]\n rw [this]\n refine MeasurableSet.biInter ((Finset.Icc 1 n).finite_toSet.countable) (fun i hi => ?_)\n simp only [Finset.mem_coe, Finset.mem_Icc] at hi\n refine MeasurableSet.inter ?_ ?_\n · exact hSpAdapted i m (by omega) (measurableSet_singleton _)\n · exact hApAdapted i m (by omega) (measurableSet_singleton _)\n\nlemma cyl_meas' (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n {n : ℕ} (h : Fin n → S × A) : MeasurableSet (cyl Sp Ap h) := by\n have : cyl Sp Ap h = ⋂ i ∈ ((Finset.Icc 1 n : Finset ℕ) : Set ℕ),\n ({ω | Sp i ω = SpH h i} ∩ {ω | Ap i ω = ApH h i}) := by\n ext ω; simp [cyl, Set.mem_iInter]\n rw [this]\n refine MeasurableSet.biInter ((Finset.Icc 1 n).finite_toSet.countable) (fun i hi => ?_)\n exact ((hSp i) (measurableSet_singleton _)).inter ((hAp i) (measurableSet_singleton _))\n\nlemma mem_cyl_self {n : ℕ} (ω : Ω) :\n ω ∈ cyl Sp Ap (fun i : Fin n => (Sp (i.1 + 1) ω, Ap (i.1 + 1) ω)) := by\n intro i hi\n simp only [Finset.mem_Icc] at hi\n have hi' : i - 1 < n := by omega\n rw [SpH, dif_pos hi', ApH, dif_pos hi']\n simp only\n constructor\n · congr 1; omega\n · congr 1; omega\n\n\n\nlemma measure_split' {Ω S : Type*} [MeasurableSpace Ω] [Fintype S] [MeasurableSpace S]\n [MeasurableSingletonClass S] (μ : Measure Ω) (f : Ω → S) (hf : Measurable f)\n (A : Set Ω) (hA : MeasurableSet A) :\n μ A = ∑ x : S, μ (A ∩ {ω | f ω = x}) := by\n have hcover : A = ⋃ x : S, (A ∩ {ω | f ω = x}) := by ext ω; simp\n have hdisj : Pairwise (Function.onFun Disjoint (fun x : S => A ∩ {ω | f ω = x})) := by\n intro x y hxy\n simp only [Function.onFun]\n rw [Set.disjoint_left]\n rintro ω ⟨-, hx⟩ ⟨-, hy⟩\n exact hxy (hx ▸ hy ▸ rfl)\n have hmeas : ∀ x : S, MeasurableSet (A ∩ {ω | f ω = x}) :=\n fun x => hA.inter (hf (measurableSet_singleton x))\n conv_lhs => rw [hcover]\n rw [measure_iUnion hdisj hmeas, tsum_fintype]\n\nvariable (μ : Measure Ω)\n\nlemma split_pair (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n (k : ℕ) (B : Set Ω) (hB : MeasurableSet B) :\n ∑ y : S × A, μ ((B ∩ {ω | Sp k ω = y.1}) ∩ {ω | Ap k ω = y.2}) = μ B := by\n rw [Fintype.sum_prod_type]\n have : ∀ x : S, ∑ b : A, μ ((B ∩ {ω | Sp k ω = x}) ∩ {ω | Ap k ω = b})\n = μ (B ∩ {ω | Sp k ω = x}) := by\n intro x\n exact (measure_split' μ (Ap k) (hAp k) _ (hB.inter ((hSp k) (measurableSet_singleton x)))).symm\n simp_rw [this]\n exact (measure_split' μ (Sp k) (hSp k) B hB).symm\n\n\nlemma cyl_total (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n [IsProbabilityMeasure μ] (n : ℕ) :\n ∑ h : Fin n → S × A, μ (cyl Sp Ap h) = 1 := by\n induction n with\n | zero =>\n rw [Fintype.sum_unique]\n rw [cyl_zero]\n exact measure_univ\n | succ n ih =>\n rw [sum_snoc]\n have : ∀ h' : Fin n → S × A, ∑ y : S × A, μ (cyl Sp Ap (Fin.snoc h' y))\n = μ (cyl Sp Ap h') := by\n intro h'\n simp_rw [cyl_snoc]\n exact split_pair Sp Ap μ hSp hAp (n+1) _ (cyl_meas' Sp Ap hSp hAp h')\n simp_rw [this]\n exact ih\n\n/-- The Markov step for cylinders. -/\nlemma cyl_markov (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n (F : ℕ → MeasurableSpace Ω)\n (hSpAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Sp t'))\n (hApAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Ap t'))\n (P : S → A → S → ℝ)\n (hMarkov : ∀ t' : ℕ, ∀ H : Set Ω, MeasurableSet[F t'] H →\n ∀ x : S, ∀ y1 : A, ∀ y2 : S,\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}) ≠ 0 →\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1} ∩ {ω | Sp (t' + 1) ω = y2})\n = ENNReal.ofReal (P x y1 y2) * μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}))\n {n : ℕ} (hn : 1 ≤ n) (h : Fin n → S × A) (x : S) :\n μ (cyl Sp Ap h ∩ {ω | Sp (n+1) ω = x})\n = ENNReal.ofReal (P (SpH h n) (ApH h n) x) * μ (cyl Sp Ap h) := by\n set H := cyl Sp Ap h with hH\n have hsub : H ∩ {ω | Sp n ω = SpH h n} ∩ {ω | Ap n ω = ApH h n} = H := by\n ext ω\n simp only [Set.mem_inter_iff, Set.mem_setOf_eq]\n constructor\n · rintro ⟨⟨hh, -⟩, -⟩; exact hh\n · intro hh\n exact ⟨⟨hh, (hh n (by simp [Finset.mem_Icc]; omega)).1⟩,\n (hh n (by simp [Finset.mem_Icc]; omega)).2⟩\n by_cases hz : μ H = 0\n · rw [hz, mul_zero]\n exact le_antisymm (le_trans (measure_mono Set.inter_subset_left) (le_of_eq hz)) (zero_le _)\n · have hmk := hMarkov n H (cyl_meas Sp Ap F hSpAdapted hApAdapted h n le_rfl)\n (SpH h n) (ApH h n) x (by rw [hsub]; exact hz)\n rw [hsub] at hmk\n exact hmk\n\nlemma cyl_total_real (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n [IsProbabilityMeasure μ] (n : ℕ) :\n ∑ h : Fin n → S × A, (μ (cyl Sp Ap h)).toReal = 1 := by\n rw [← ENNReal.toReal_sum (fun h _ => measure_ne_top μ _), cyl_total Sp Ap μ hSp hAp n,\n ENNReal.toReal_one]\n\nlemma cyl_snoc_sum (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n (F : ℕ → MeasurableSpace Ω)\n (hSpAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Sp t'))\n (hApAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Ap t'))\n (P : S → A → S → ℝ) (hP0 : ∀ x b y, 0 ≤ P x b y)\n (hMarkov : ∀ t' : ℕ, ∀ H : Set Ω, MeasurableSet[F t'] H →\n ∀ x : S, ∀ y1 : A, ∀ y2 : S,\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}) ≠ 0 →\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1} ∩ {ω | Sp (t' + 1) ω = y2})\n = ENNReal.ofReal (P x y1 y2) * μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}))\n [IsProbabilityMeasure μ]\n {n : ℕ} (hn : 1 ≤ n) (h : Fin n → S × A) (x : S) :\n ∑ b : A, (μ (cyl Sp Ap (Fin.snoc h (x, b)))).toReal\n = P (SpH h n) (ApH h n) x * (μ (cyl Sp Ap h)).toReal := by\n have hE : ∑ b : A, μ (cyl Sp Ap (Fin.snoc h (x, b)))\n = ENNReal.ofReal (P (SpH h n) (ApH h n) x) * μ (cyl Sp Ap h) := by\n have h1 : ∀ b : A, cyl Sp Ap (Fin.snoc h (x, b))\n = (cyl Sp Ap h ∩ {ω | Sp (n+1) ω = x}) ∩ {ω | Ap (n+1) ω = b} := by\n intro b; rw [cyl_snoc]\n simp_rw [h1]\n rw [← measure_split' μ (Ap (n+1)) (hAp (n+1)) (cyl Sp Ap h ∩ {ω | Sp (n+1) ω = x})\n ((cyl_meas' Sp Ap hSp hAp h).inter ((hSp (n+1)) (measurableSet_singleton x)))]\n exact cyl_markov Sp Ap μ hSp hAp F hSpAdapted hApAdapted P hMarkov hn h x\n rw [← ENNReal.toReal_sum (fun b _ => measure_ne_top μ _), hE, ENNReal.toReal_mul,\n ENNReal.toReal_ofReal (hP0 _ _ _)]\n\nend Hist\n\nsection Mart\nvariable {S A Ω : Type*} [Fintype S] [Nonempty S] [Fintype A] [Nonempty A]\n [DecidableEq S] [DecidableEq A]\n [MeasurableSpace S] [MeasurableSpace A]\n [MeasurableSingletonClass S] [MeasurableSingletonClass A] [MeasurableSpace Ω]\n\nvariable (P : S → A → S → ℝ) (s : S) (a : A) (g : S → ℝ) (lam : ℝ)\n\n/-- one-step exponential weight -/\nnoncomputable def ee (x : S) (b : A) (y : S) : ℝ :=\n if x = s ∧ b = a then Real.exp (lam * (g y - ∑ z, P s a z * g z) - lam ^ 2 / 2) else 1\n\nlemma ee_pos (x : S) (b : A) (y : S) : 0 < ee P s a g lam x b y := by\n rw [ee]; split\n · exact Real.exp_pos _\n · norm_num\n\n/-- the product weight along a history -/\nnoncomputable def phi (k : ℕ) (h : Fin (k+1) → S × A) : ℝ :=\n ∏ t' ∈ Finset.Icc 1 k, ee P s a g lam (SpH h t') (ApH h t') (SpH h (t'+1))\n\nlemma phi_pos (k : ℕ) (h : Fin (k+1) → S × A) : 0 < phi P s a g lam k h :=\n Finset.prod_pos (fun i _ => ee_pos P s a g lam _ _ _)\n\nlemma phi_zero (h : Fin 1 → S × A) : phi P s a g lam 0 h = 1 := by\n simp [phi]\n\nlemma phi_snoc (k : ℕ) (h : Fin (k+1) → S × A) (y : S × A) :\n phi P s a g lam (k+1) (Fin.snoc h y)\n = phi P s a g lam k h * ee P s a g lam (SpH h (k+1)) (ApH h (k+1)) y.1 := by\n rw [phi, phi, Finset.prod_Icc_succ_top (by omega)]\n congr 1\n · refine Finset.prod_congr rfl (fun t' ht' => ?_)\n simp only [Finset.mem_Icc] at ht'\n rw [SpH_snoc h y t' (by omega), ApH_snoc h y t' (by omega),\n SpH_snoc h y (t'+1) (by omega)]\n · rw [SpH_snoc h y (k+1) (by omega), ApH_snoc h y (k+1) (by omega),\n SpH_snoc_last h y]\n\n/-- The key one-step estimate coming from Hoeffding's lemma. -/\nlemma ee_step (hP0 : ∀ x b y, 0 ≤ P x b y) (hP1 : ∀ x b, ∑ y, P x b y = 1)\n (hg : ∀ y, g y = 1 ∨ g y = -1) (hlam : 0 < lam) (x : S) (b : A) :\n ∑ y : S, ee P s a g lam x b y * P x b y ≤ 1 := by\n by_cases hxb : x = s ∧ b = a\n · obtain ⟨rfl, rfl⟩ := hxb\n set m := ∑ z, P x b z * g z with hm\n have hkey : ∑ y, P x b y * Real.exp (lam * (g y - m)) ≤ Real.exp (lam ^ 2 / 2) := by\n have := finite_hoeffding (p := fun y => P x b y) (hP0 x b) (hP1 x b)\n (f := fun y => g y - m) (a := -1 - m) (b := 1 - m)\n (fun y => by\n simp only [Set.mem_Icc]\n rcases hg y with h1 | h1 <;> rw [h1] <;> constructor <;> linarith)\n (by\n simp_rw [mul_sub]\n rw [Finset.sum_sub_distrib, ← Finset.sum_mul, hP1 x b, one_mul, ← hm]\n ring) lam hlam\n refine le_trans this (le_of_eq ?_)\n congr 1\n ring\n calc ∑ y : S, ee P x b g lam x b y * P x b y\n = ∑ y : S, Real.exp (-(lam^2/2)) * (P x b y * Real.exp (lam * (g y - m))) := by\n refine Finset.sum_congr rfl (fun y _ => ?_)\n rw [ee, if_pos ⟨rfl, rfl⟩, ← hm,\n show lam * (g y - m) - lam ^ 2 / 2 = lam * (g y - m) + (-(lam ^ 2 / 2)) by ring,\n Real.exp_add]\n ring\n _ = Real.exp (-(lam^2/2)) * ∑ y : S, P x b y * Real.exp (lam * (g y - m)) := by\n rw [Finset.mul_sum]\n _ ≤ Real.exp (-(lam^2/2)) * Real.exp (lam^2/2) := by\n exact mul_le_mul_of_nonneg_left hkey (le_of_lt (Real.exp_pos _))\n _ = 1 := by rw [← Real.exp_add]; simp\n · have : ∀ y : S, ee P s a g lam x b y = 1 := fun y => by rw [ee, if_neg hxb]\n simp_rw [this, one_mul]\n exact le_of_eq (hP1 x b)\n\nlemma Psi_le (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (μ : Measure Ω) [IsProbabilityMeasure μ]\n (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n (F : ℕ → MeasurableSpace Ω)\n (hSpAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Sp t'))\n (hApAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Ap t'))\n (hMarkov : ∀ t' : ℕ, ∀ H : Set Ω, MeasurableSet[F t'] H →\n ∀ x : S, ∀ y1 : A, ∀ y2 : S,\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}) ≠ 0 →\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1} ∩ {ω | Sp (t' + 1) ω = y2})\n = ENNReal.ofReal (P x y1 y2) * μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}))\n (hP0 : ∀ x b y, 0 ≤ P x b y) (hP1 : ∀ x b, ∑ y, P x b y = 1)\n (hg : ∀ y, g y = 1 ∨ g y = -1) (hlam : 0 < lam) (k : ℕ) :\n ∑ h : Fin (k+1) → S × A, phi P s a g lam k h * (μ (cyl Sp Ap h)).toReal ≤ 1 := by\n induction k with\n | zero =>\n have hz : ∀ h : Fin 1 → S × A, phi P s a g lam 0 h * (μ (cyl Sp Ap h)).toReal\n = (μ (cyl Sp Ap h)).toReal := by intro h; rw [phi_zero, one_mul]\n simp_rw [hz]\n rw [cyl_total_real Sp Ap μ hSp hAp 1]\n | succ k ih =>\n rw [sum_snoc]\n refine le_trans (Finset.sum_le_sum (fun h'' _ => ?_)) ih\n set x' := SpH h'' (k+1) with hx'\n set b' := ApH h'' (k+1) with hb'\n set c := phi P s a g lam k h'' with hc\n set v := (μ (cyl Sp Ap h'')).toReal with hv\n have hc0 : 0 ≤ c := le_of_lt (phi_pos P s a g lam k h'')\n have hv0 : 0 ≤ v := ENNReal.toReal_nonneg\n calc ∑ y : S × A, phi P s a g lam (k+1) (Fin.snoc h'' y)\n * (μ (cyl Sp Ap (Fin.snoc h'' y))).toReal\n = ∑ x : S, ∑ b : A, (c * ee P s a g lam x' b' x)\n * (μ (cyl Sp Ap (Fin.snoc h'' (x, b)))).toReal := by\n rw [Fintype.sum_prod_type]\n refine Finset.sum_congr rfl (fun x _ => Finset.sum_congr rfl (fun b _ => ?_))\n rw [phi_snoc]\n _ = ∑ x : S, (c * ee P s a g lam x' b' x)\n * (∑ b : A, (μ (cyl Sp Ap (Fin.snoc h'' (x, b)))).toReal) := by\n refine Finset.sum_congr rfl (fun x _ => ?_)\n rw [Finset.mul_sum]\n _ = ∑ x : S, (c * ee P s a g lam x' b' x) * (P x' b' x * v) := by\n refine Finset.sum_congr rfl (fun x _ => ?_)\n rw [cyl_snoc_sum Sp Ap μ hSp hAp F hSpAdapted hApAdapted P hP0 hMarkov\n (by omega : 1 ≤ k+1) h'' x]\n _ = (c * v) * (∑ x : S, ee P s a g lam x' b' x * P x' b' x) := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl (fun x _ => by ring)\n _ ≤ (c * v) * 1 := by\n refine mul_le_mul_of_nonneg_left (ee_step P s a g lam hP0 hP1 hg hlam x' b')\n (mul_nonneg hc0 hv0)\n _ = c * v := mul_one _\n\nnoncomputable def NNf (k : ℕ) (h : Fin (k+1) → S × A) : ℝ :=\n ∑ t' ∈ Finset.Icc 1 k, (if SpH h t' = s ∧ ApH h t' = a then (1:ℝ) else 0)\n\nnoncomputable def MMf (k : ℕ) (h : Fin (k+1) → S × A) : ℝ :=\n ∑ t' ∈ Finset.Icc 1 k, (if SpH h t' = s ∧ ApH h t' = a then (1:ℝ) else 0)\n * (g (SpH h (t'+1)) - ∑ z, P s a z * g z)\n\nlemma phi_eq (k : ℕ) (h : Fin (k+1) → S × A) :\n phi P s a g lam k h\n = Real.exp (lam * MMf P s a g k h - lam ^ 2 / 2 * NNf s a k h) := by\n rw [phi, MMf, NNf, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, Real.exp_sum]\n refine Finset.prod_congr rfl (fun t' _ => ?_)\n rw [ee]\n by_cases hh : SpH h t' = s ∧ ApH h t' = a\n · rw [if_pos hh, if_pos hh]\n congr 1\n ring\n · rw [if_neg hh, if_neg hh]\n simp\n\nlemma chernoff (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (μ : Measure Ω) [IsProbabilityMeasure μ]\n (hSp : ∀ t', Measurable (Sp t')) (hAp : ∀ t', Measurable (Ap t'))\n (F : ℕ → MeasurableSpace Ω)\n (hSpAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Sp t'))\n (hApAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[F t''] (Ap t'))\n (hMarkov : ∀ t' : ℕ, ∀ H : Set Ω, MeasurableSet[F t'] H →\n ∀ x : S, ∀ y1 : A, ∀ y2 : S,\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}) ≠ 0 →\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1} ∩ {ω | Sp (t' + 1) ω = y2})\n = ENNReal.ofReal (P x y1 y2) * μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}))\n (hP0 : ∀ x b y, 0 ≤ P x b y) (hP1 : ∀ x b, ∑ y, P x b y = 1)\n (hg : ∀ y, g y = 1 ∨ g y = -1) (hlam : 0 < lam) (k : ℕ)\n (nr θ : ℝ) (B : Finset (Fin (k+1) → S × A))\n (hB : ∀ h ∈ B, NNf s a k h = nr ∧ θ ≤ MMf P s a g k h) :\n ∑ h ∈ B, (μ (cyl Sp Ap h)).toReal ≤ Real.exp (-(lam * θ) + lam ^ 2 / 2 * nr) := by\n set K := Real.exp (-(lam * θ) + lam ^ 2 / 2 * nr) with hK\n have hK0 : 0 < K := Real.exp_pos _\n have hstep : ∀ h ∈ B, (μ (cyl Sp Ap h)).toReal\n ≤ K * (phi P s a g lam k h * (μ (cyl Sp Ap h)).toReal) := by\n intro h hh\n obtain ⟨h1, h2⟩ := hB h hh\n have hge : 1 ≤ K * phi P s a g lam k h := by\n rw [phi_eq, hK, ← Real.exp_add, h1]\n rw [show -(lam * θ) + lam ^ 2 / 2 * nr + (lam * MMf P s a g k h - lam ^ 2 / 2 * nr)\n = lam * (MMf P s a g k h - θ) by ring]\n rw [← Real.exp_zero]\n exact Real.exp_le_exp.2 (mul_nonneg (le_of_lt hlam) (by linarith))\n have hv0 : (0:ℝ) ≤ (μ (cyl Sp Ap h)).toReal := ENNReal.toReal_nonneg\n calc (μ (cyl Sp Ap h)).toReal = 1 * (μ (cyl Sp Ap h)).toReal := (one_mul _).symm\n _ ≤ (K * phi P s a g lam k h) * (μ (cyl Sp Ap h)).toReal :=\n mul_le_mul_of_nonneg_right hge hv0\n _ = K * (phi P s a g lam k h * (μ (cyl Sp Ap h)).toReal) := by ring\n calc ∑ h ∈ B, (μ (cyl Sp Ap h)).toReal\n ≤ ∑ h ∈ B, K * (phi P s a g lam k h * (μ (cyl Sp Ap h)).toReal) :=\n Finset.sum_le_sum hstep\n _ = K * ∑ h ∈ B, phi P s a g lam k h * (μ (cyl Sp Ap h)).toReal := by rw [Finset.mul_sum]\n _ ≤ K * ∑ h : Fin (k+1) → S × A, phi P s a g lam k h * (μ (cyl Sp Ap h)).toReal := by\n refine mul_le_mul_of_nonneg_left ?_ (le_of_lt hK0)\n refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ B) (fun h _ _ => ?_)\n exact mul_nonneg (le_of_lt (phi_pos P s a g lam k h)) ENNReal.toReal_nonneg\n _ ≤ K * 1 := by\n refine mul_le_mul_of_nonneg_left ?_ (le_of_lt hK0)\n exact Psi_le P s a g lam Sp Ap μ hSp hAp F hSpAdapted hApAdapted hMarkov hP0 hP1 hg hlam k\n _ = K := mul_one _\n\nend Mart\n\n\nend ConcAux\n\n\nnoncomputable def visitCount {S A Ω : Type*} [DecidableEq S] [DecidableEq A]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (t : ℕ) (s : S) (a : A) (ω : Ω) : ℕ :=\n ∑ t' ∈ Finset.Icc 1 t, if Sp t' ω = s ∧ Ap t' ω = a then 1 else 0\n\nnoncomputable def empTrans {S A Ω : Type*} [DecidableEq S] [DecidableEq A]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (t : ℕ) (s : S) (a : A) (s' : S) (ω : Ω) : ℝ :=\n (∑ t' ∈ Finset.Icc 1 t, if Sp t' ω = s ∧ Ap t' ω = a ∧ Sp (t' + 1) ω = s'\n then (1 : ℝ) else 0) / (visitCount Sp Ap t s a ω : ℝ)\n\ndef goodEvent {S A Ω : Type*} [Fintype S] [Fintype A] [DecidableEq S] [DecidableEq A]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (P : S → A → S → ℝ) (t T : ℕ) (ω : Ω) : Prop :=\n ∀ s : S, ∀ a : A,\n transL1 (fun s a s' => empTrans Sp Ap t s a s' ω) P s a\n ≤ Real.sqrt (14 * (Fintype.card S : ℝ) * Real.log (2 * (Fintype.card A : ℝ) * T)\n / max 1 (visitCount Sp Ap t s a ω : ℝ))\n\nsection ConcTransfer\nset_option linter.unusedSectionVars false\n-- ===================== transfer =====================\nsection Transfer\nvariable {S A Ω : Type*} [Fintype S] [Nonempty S] [Fintype A] [Nonempty A]\n [DecidableEq S] [DecidableEq A] [MeasurableSpace S] [MeasurableSpace A]\n [MeasurableSingletonClass S] [MeasurableSingletonClass A] [MeasurableSpace Ω]\n\nlemma SpH_hist {n : ℕ} (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (ω : Ω) (i : ℕ)\n (h1 : 1 ≤ i) (h2 : i ≤ n) :\n SpH (fun j : Fin n => (Sp (j.1+1) ω, Ap (j.1+1) ω)) i = Sp i ω := by\n have hi : i - 1 < n := by omega\n rw [SpH, dif_pos hi]\n simp only\n congr 1\n omega\n\nlemma ApH_hist {n : ℕ} (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (ω : Ω) (i : ℕ)\n (h1 : 1 ≤ i) (h2 : i ≤ n) :\n ApH (fun j : Fin n => (Sp (j.1+1) ω, Ap (j.1+1) ω)) i = Ap i ω := by\n have hi : i - 1 < n := by omega\n rw [ApH, dif_pos hi]\n simp only\n congr 1\n omega\n\nlemma NNf_hist (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (ω : Ω) (s : S) (a : A) (t : ℕ) :\n NNf s a t (fun j : Fin (t+1) => (Sp (j.1+1) ω, Ap (j.1+1) ω))\n = (visitCount Sp Ap t s a ω : ℝ) := by\n rw [NNf, visitCount]\n push_cast\n refine Finset.sum_congr rfl (fun t' ht' => ?_)\n simp only [Finset.mem_Icc] at ht'\n rw [SpH_hist Sp Ap ω t' (by omega) (by omega), ApH_hist Sp Ap ω t' (by omega) (by omega)]\n\nlemma MMf_hist (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (ω : Ω) (s : S) (a : A)\n (g : S → ℝ) (P : S → A → S → ℝ) (t : ℕ) :\n MMf P s a g t (fun j : Fin (t+1) => (Sp (j.1+1) ω, Ap (j.1+1) ω))\n = ∑ t' ∈ Finset.Icc 1 t, (if Sp t' ω = s ∧ Ap t' ω = a then (1:ℝ) else 0)\n * (g (Sp (t'+1) ω) - ∑ z, P s a z * g z) := by\n rw [MMf]\n refine Finset.sum_congr rfl (fun t' ht' => ?_)\n simp only [Finset.mem_Icc] at ht'\n rw [SpH_hist Sp Ap ω t' (by omega) (by omega), ApH_hist Sp Ap ω t' (by omega) (by omega),\n SpH_hist Sp Ap ω (t'+1) (by omega) (by omega)]\n\nlemma cnt2_eq (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (ω : Ω) (s : S) (a : A) (t : ℕ) (y : S) :\n (∑ t' ∈ Finset.Icc 1 t,\n if Sp t' ω = s ∧ Ap t' ω = a ∧ Sp (t'+1) ω = y then (1:ℝ) else 0)\n = (visitCount Sp Ap t s a ω : ℝ) * empTrans Sp Ap t s a y ω := by\n set c2 : ℝ := ∑ t' ∈ Finset.Icc 1 t,\n (if Sp t' ω = s ∧ Ap t' ω = a ∧ Sp (t'+1) ω = y then (1:ℝ) else 0) with hc2\n by_cases hz : (visitCount Sp Ap t s a ω : ℝ) = 0\n · rw [hz, zero_mul]\n have hle : c2 ≤ (visitCount Sp Ap t s a ω : ℝ) := by\n rw [hc2, visitCount]\n push_cast\n refine Finset.sum_le_sum (fun t' _ => ?_)\n by_cases hh : Sp t' ω = s ∧ Ap t' ω = a ∧ Sp (t'+1) ω = y\n · rw [if_pos hh, if_pos ⟨hh.1, hh.2.1⟩]\n · rw [if_neg hh]\n split <;> norm_num\n have hge : 0 ≤ c2 := Finset.sum_nonneg (fun t' _ => by split <;> norm_num)\n linarith\n · rw [empTrans, mul_div_cancel₀ _ hz]\n\nlemma MM_formula (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (ω : Ω) (s : S) (a : A) (g : S → ℝ)\n (P : S → A → S → ℝ) (t : ℕ) :\n ∑ t' ∈ Finset.Icc 1 t, (if Sp t' ω = s ∧ Ap t' ω = a then (1:ℝ) else 0)\n * (g (Sp (t'+1) ω) - ∑ z, P s a z * g z)\n = (visitCount Sp Ap t s a ω : ℝ)\n * (∑ y, g y * (empTrans Sp Ap t s a y ω - P s a y)) := by\n set N : ℝ := (visitCount Sp Ap t s a ω : ℝ) with hN\n set m : ℝ := ∑ z, P s a z * g z with hm\n have hNdef : N = ∑ t' ∈ Finset.Icc 1 t,\n (if Sp t' ω = s ∧ Ap t' ω = a then (1:ℝ) else 0) := by\n rw [hN, visitCount]; push_cast; rfl\n have hsplit : ∑ t' ∈ Finset.Icc 1 t, (if Sp t' ω = s ∧ Ap t' ω = a then (1:ℝ) else 0)\n * (g (Sp (t'+1) ω) - m)\n = (∑ t' ∈ Finset.Icc 1 t, (if Sp t' ω = s ∧ Ap t' ω = a then (1:ℝ) else 0)\n * g (Sp (t'+1) ω)) - N * m := by\n rw [hNdef, Finset.sum_mul, ← Finset.sum_sub_distrib]\n refine Finset.sum_congr rfl (fun t' _ => by ring)\n have hA : (∑ t' ∈ Finset.Icc 1 t, (if Sp t' ω = s ∧ Ap t' ω = a then (1:ℝ) else 0)\n * g (Sp (t'+1) ω))\n = ∑ y : S, g y * (N * empTrans Sp Ap t s a y ω) := by\n have hstep : ∀ t' : ℕ, (if Sp t' ω = s ∧ Ap t' ω = a then (1:ℝ) else 0) * g (Sp (t'+1) ω)\n = ∑ y : S, g y * (if Sp t' ω = s ∧ Ap t' ω = a ∧ Sp (t'+1) ω = y then (1:ℝ) else 0) := by\n intro t'\n by_cases hh : Sp t' ω = s ∧ Ap t' ω = a\n · rw [if_pos hh, one_mul]\n rw [Finset.sum_eq_single (Sp (t'+1) ω)]\n · rw [if_pos ⟨hh.1, hh.2, rfl⟩, mul_one]\n · intro y _ hy\n rw [if_neg (by rintro ⟨-, -, h3⟩; exact hy h3.symm), mul_zero]\n · intro hcon; exact absurd (Finset.mem_univ _) hcon\n · rw [if_neg hh, zero_mul]\n refine (Finset.sum_eq_zero (fun y _ => ?_)).symm\n rw [if_neg (by rintro ⟨h1, h2, -⟩; exact hh ⟨h1, h2⟩), mul_zero]\n simp_rw [hstep]\n rw [Finset.sum_comm]\n refine Finset.sum_congr rfl (fun y _ => ?_)\n rw [← Finset.mul_sum, cnt2_eq Sp Ap ω s a t y]\n rw [hsplit, hA]\n have hR : ∑ y : S, g y * (empTrans Sp Ap t s a y ω - P s a y)\n = (∑ y : S, g y * empTrans Sp Ap t s a y ω) - m := by\n rw [hm]\n rw [← Finset.sum_sub_distrib]\n refine Finset.sum_congr rfl (fun y _ => by ring)\n rw [hR, mul_sub]\n congr 1\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl (fun y _ => by ring)\n\nend Transfer\n\nend ConcTransfer\n\n\n\n\nlemma visitCount_le {S A Ω : Type*} [DecidableEq S] [DecidableEq A]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A) (t : ℕ) (s : S) (a : A) (ω : Ω) :\n visitCount Sp Ap t s a ω ≤ t := by\n rw [visitCount]\n calc ∑ t' ∈ Finset.Icc 1 t, (if Sp t' ω = s ∧ Ap t' ω = a then 1 else 0)\n ≤ ∑ _t' ∈ Finset.Icc 1 t, 1 := Finset.sum_le_sum (fun i _ => by split <;> omega)\n _ = t := by simp\n\nlemma nat_20 : ∀ n : ℕ, 20 * n ≤ 2 ^ (6 * n) := by\n intro n\n induction n with\n | zero => simp\n | succ k ih =>\n have h1 : (1:ℕ) ≤ 2 ^ (6 * k) := Nat.one_le_two_pow\n have h2 : 2 ^ (6 * (k + 1)) = 2 ^ (6 * k) * 64 := by\n rw [show 6 * (k+1) = 6 * k + 6 by ring, pow_add]\n norm_num\n rw [h2]\n set X := 2 ^ (6 * k) with hX\n omega\n\nlemma nat_arith (S₀ A₀ t T : ℕ) (hS : 1 ≤ S₀) (hA : 1 ≤ A₀) (ht : 1 ≤ t) (hT : t ≤ T) :\n 20 * t ^ 6 * (S₀ * (A₀ * (t * 2 ^ S₀))) ≤ (2 * A₀ * T) ^ (7 * S₀) := by\n have hT1 : 1 ≤ T := le_trans ht hT\n have e1 : (20 * S₀) * 2 ^ S₀ ≤ 2 ^ (7 * S₀) := by\n have := nat_20 S₀\n calc (20 * S₀) * 2 ^ S₀ ≤ 2 ^ (6 * S₀) * 2 ^ S₀ := Nat.mul_le_mul_right _ this\n _ = 2 ^ (7 * S₀) := by rw [← pow_add]; congr 1; ring\n have e2 : A₀ ≤ A₀ ^ (7 * S₀) := Nat.le_self_pow (by omega) _\n have e3 : t ^ 7 ≤ T ^ (7 * S₀) := by\n calc t ^ 7 ≤ T ^ 7 := Nat.pow_le_pow_left hT 7\n _ ≤ T ^ (7 * S₀) := Nat.pow_le_pow_right hT1 (by omega)\n calc 20 * t ^ 6 * (S₀ * (A₀ * (t * 2 ^ S₀)))\n = ((20 * S₀) * 2 ^ S₀) * A₀ * t ^ 7 := by ring\n _ ≤ 2 ^ (7 * S₀) * A₀ ^ (7 * S₀) * T ^ (7 * S₀) := by\n exact Nat.mul_le_mul (Nat.mul_le_mul e1 e2) e3\n _ = (2 * A₀ * T) ^ (7 * S₀) := by rw [mul_pow, mul_pow]\n\n\ntheorem lemma7 {S A Ω : Type*} [Fintype S] [Nonempty S] [Fintype A] [Nonempty A]\n [DecidableEq S] [DecidableEq A] [MeasurableSpace S] [MeasurableSpace A]\n [MeasurableSingletonClass S] [MeasurableSingletonClass A]\n [MeasurableSpace Ω]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (Sp : ℕ → Ω → S) (Ap : ℕ → Ω → A)\n (hSpmeas : ∀ t', Measurable (Sp t')) (hApmeas : ∀ t', Measurable (Ap t'))\n (ℱ : ℕ → MeasurableSpace Ω)\n (hFmono : Monotone ℱ) (hFle : ∀ t', ℱ t' ≤ (inferInstance : MeasurableSpace Ω))\n (hSpAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[ℱ t''] (Sp t'))\n (hApAdapted : ∀ t' t'' : ℕ, t' ≤ t'' → Measurable[ℱ t''] (Ap t'))\n (P : S → A → S → ℝ)\n (hP_prob : ∀ s a, (∀ s', 0 ≤ P s a s') ∧ ∑ s', P s a s' = 1)\n (hErgodic : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∃ (d : S → ℝ) (C ρ : ℝ), 0 ≤ C ∧ 0 ≤ ρ ∧ ρ < 1 ∧\n ∀ t : ℕ, ∀ x : S,\n ∑ y, |((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y - d y|\n ≤ C * ρ ^ t)\n (hCommunicate : ∀ π₂ : S → A → ℝ, (∀ x, (∀ a, 0 ≤ π₂ x a) ∧ ∑ a, π₂ x a = 1) →\n ∀ x y : S, ∃ t : ℕ,\n 0 < ((Matrix.of fun u v => ∑ a, π₂ u a * P u a v) ^ t) x y)\n (hMarkov : ∀ t' : ℕ, ∀ H : Set Ω, MeasurableSet[ℱ t'] H →\n ∀ x : S, ∀ y1 : A, ∀ y2 : S,\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}) ≠ 0 →\n μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1} ∩ {ω | Sp (t' + 1) ω = y2})\n = ENNReal.ofReal (P x y1 y2) * μ (H ∩ {ω | Sp t' ω = x} ∩ {ω | Ap t' ω = y1}))\n (t T : ℕ) (ht : 1 ≤ t) (hT : t ≤ T) :\n μ {ω | ¬ goodEvent Sp Ap P t T ω} ≤ ENNReal.ofReal (1 / (20 * (t : ℝ) ^ 6)) := by\n classical\n have hP0 : ∀ x b y, 0 ≤ P x b y := fun x b y => (hP_prob x b).1 y\n have hP1 : ∀ x b, ∑ y, P x b y = 1 := fun x b => (hP_prob x b).2\n have hS1 : 1 ≤ Fintype.card S := Fintype.card_pos\n have hA1 : 1 ≤ Fintype.card A := Fintype.card_pos\n have hT1 : 1 ≤ T := le_trans ht hT\n have hS1R : (1:ℝ) ≤ (Fintype.card S : ℝ) := by exact_mod_cast hS1\n have hA1R : (1:ℝ) ≤ (Fintype.card A : ℝ) := by exact_mod_cast hA1\n have hT1R : (1:ℝ) ≤ (T:ℝ) := by exact_mod_cast hT1\n set c : ℝ := 14 * (Fintype.card S : ℝ) * Real.log (2 * (Fintype.card A : ℝ) * (T:ℝ)) with hcdef\n have hQ2 : (2:ℝ) ≤ 2 * (Fintype.card A : ℝ) * (T:ℝ) := by nlinarith\n have hlog2 : (0.6931471803:ℝ) < Real.log 2 := Real.log_two_gt_d9\n have hL : Real.log 2 ≤ Real.log (2 * (Fintype.card A : ℝ) * (T:ℝ)) :=\n Real.log_le_log (by norm_num) hQ2\n have hc1 : (1:ℝ) ≤ c := by rw [hcdef]; nlinarith\n have hc0 : (0:ℝ) ≤ c := le_trans zero_le_one hc1\n set gfun : (S → Bool) → S → ℝ := fun gb y => if gb y = true then (1:ℝ) else -1 with hgfun\n have hgpm : ∀ gb : S → Bool, ∀ y, gfun gb y = 1 ∨ gfun gb y = -1 := by\n intro gb y\n rw [hgfun]\n by_cases hb : gb y = true\n · left; simp [hb]\n · right; simp [hb]\n set Bad : S × A × Fin t × (S → Bool) → Finset (Fin (t+1) → S × A) := fun i =>\n Finset.univ.filter (fun h =>\n NNf i.1 i.2.1 t h = ((i.2.2.1.val + 1 : ℕ) : ℝ) ∧\n (((i.2.2.1.val + 1 : ℕ) : ℝ) * Real.sqrt (c / ((i.2.2.1.val + 1 : ℕ) : ℝ)))\n ≤ MMf P i.1 i.2.1 (gfun i.2.2.2) t h) with hBaddef\n set W : S × A × Fin t × (S → Bool) → Set Ω := fun i => ⋃ h ∈ Bad i, cyl Sp Ap h with hWdef\n have hcover : {ω | ¬ goodEvent Sp Ap P t T ω} ⊆ ⋃ i, W i := by\n intro ω hω\n have hω' : ¬ ∀ (s : S) (a : A), transL1 (fun s a s' => empTrans Sp Ap t s a s' ω) P s a\n ≤ Real.sqrt (c / max 1 (visitCount Sp Ap t s a ω : ℝ)) := by\n rw [hcdef]\n exact hω\n push_neg at hω'\n obtain ⟨s, a, hsa⟩ := hω'\n set N : ℕ := visitCount Sp Ap t s a ω with hNdef\n have hNle : N ≤ t := visitCount_le Sp Ap t s a ω\n set d : S → ℝ := fun y => empTrans Sp Ap t s a y ω - P s a y with hddef\n have htr : transL1 (fun s a s' => empTrans Sp Ap t s a s' ω) P s a = ∑ y, |d y| := rfl\n by_cases hN0 : N = 0\n · exfalso\n have hv0 : ((visitCount Sp Ap t s a ω : ℕ) : ℝ) = 0 := by\n rw [← hNdef, hN0]; norm_num\n have he0 : ∀ y, empTrans Sp Ap t s a y ω = 0 := by\n intro y; rw [empTrans, hv0, div_zero]\n have htr1 : transL1 (fun s a s' => empTrans Sp Ap t s a s' ω) P s a = 1 := by\n rw [htr]\n have : ∀ y : S, |d y| = P s a y := by\n intro y\n rw [hddef]\n simp only [he0, zero_sub, abs_neg]\n exact abs_of_nonneg (hP0 s a y)\n rw [Finset.sum_congr rfl (fun y _ => this y)]\n exact hP1 s a\n have hmax : max (1:ℝ) ((visitCount Sp Ap t s a ω : ℕ) : ℝ) = 1 := by\n rw [hv0]; simp\n rw [htr1, hmax, div_one] at hsa\n have h1s : (1:ℝ) ≤ Real.sqrt c := Real.one_le_sqrt.2 hc1\n linarith\n · have hN1 : 1 ≤ N := Nat.one_le_iff_ne_zero.2 hN0\n have hNlt : N - 1 < t := by omega\n set gb : S → Bool := fun y => if 0 ≤ d y then true else false with hgbdef\n refine Set.mem_iUnion.2 ⟨(s, a, ⟨N - 1, hNlt⟩, gb), ?_⟩\n have hnv : ((⟨N - 1, hNlt⟩ : Fin t).val + 1 : ℕ) = N := by simp; omega\n have hmaxN : max (1:ℝ) ((visitCount Sp Ap t s a ω : ℕ) : ℝ)\n = ((visitCount Sp Ap t s a ω : ℕ) : ℝ) := by\n refine max_eq_right ?_\n rw [← hNdef]\n exact_mod_cast hN1\n have hgd : ∀ y, gfun gb y * d y = |d y| := by\n intro y\n rw [hgfun, hgbdef]\n by_cases hy : 0 ≤ d y\n · simp only [hy, if_true, if_pos]\n rw [one_mul, abs_of_nonneg hy]\n · simp only [hy, if_neg, not_false_iff]\n push_neg at hy\n rw [abs_of_neg hy]\n norm_num\n set hist : Fin (t+1) → S × A := fun j => (Sp (j.1 + 1) ω, Ap (j.1 + 1) ω) with hhist\n have hmemcyl : ω ∈ cyl Sp Ap hist := by\n rw [hhist]; exact mem_cyl_self Sp Ap ω\n have hNN : NNf s a t hist = (N : ℝ) := by\n rw [hhist, NNf_hist, hNdef]\n have hMM : MMf P s a (gfun gb) t hist = (N:ℝ) * (∑ y, |d y|) := by\n rw [hhist, MMf_hist, MM_formula, ← hNdef]\n congr 1\n refine Finset.sum_congr rfl (fun y _ => ?_)\n rw [← hgd y, hddef]\n have hkey : ((N:ℝ)) * Real.sqrt (c / (N:ℝ)) ≤ MMf P s a (gfun gb) t hist := by\n rw [hMM]\n refine mul_le_mul_of_nonneg_left ?_ (by positivity)\n rw [← htr]\n rw [hmaxN, ← hNdef] at hsa\n exact le_of_lt hsa\n refine Set.mem_iUnion₂.2 ⟨hist, ?_, hmemcyl⟩\n rw [hBaddef]\n simp only [Finset.mem_filter, Finset.mem_univ, true_and]\n refine ⟨?_, ?_⟩\n · rw [hNN, hnv]\n · rw [hnv]\n exact hkey\n have hWbound : ∀ i, μ (W i) ≤ ENNReal.ofReal (Real.exp (-(c/2))) := by\n rintro ⟨s, a, n', gb⟩\n set n : ℕ := n'.val + 1 with hndef\n have hn1 : 1 ≤ n := by omega\n have hnR : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn1\n set eps : ℝ := Real.sqrt (c / (n:ℝ)) with hepsdef\n have hcn : (0:ℝ) < c / (n:ℝ) := div_pos (by linarith) hnR\n have heps0 : 0 < eps := Real.sqrt_pos.2 hcn\n have hepssq : eps ^ 2 = c / (n:ℝ) := Real.sq_sqrt (le_of_lt hcn)\n have hBmem : ∀ h ∈ Bad (s, a, n', gb),\n NNf s a t h = (n:ℝ) ∧ (n:ℝ) * eps ≤ MMf P s a (gfun gb) t h := by\n intro h hh\n rw [hBaddef] at hh\n simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hh\n exact hh\n have hch := chernoff P s a (gfun gb) eps Sp Ap μ hSpmeas hApmeas ℱ hSpAdapted hApAdapted\n hMarkov hP0 hP1 (hgpm gb) heps0 t (n:ℝ) ((n:ℝ) * eps) (Bad (s, a, n', gb)) hBmem\n have hne : (n:ℝ) * eps ^ 2 = c := by\n rw [hepssq]; field_simp\n have hexpeq : -(eps * ((n:ℝ) * eps)) + eps ^ 2 / 2 * (n:ℝ) = -(c/2) := by\n linear_combination (-1/2 : ℝ) * hne\n rw [hexpeq] at hch\n have hfin : (∑ h ∈ Bad (s, a, n', gb), μ (cyl Sp Ap h)) ≠ ⊤ :=\n ENNReal.sum_ne_top.2 (fun h _ => measure_ne_top μ _)\n calc μ (W (s, a, n', gb)) ≤ ∑ h ∈ Bad (s, a, n', gb), μ (cyl Sp Ap h) := by\n rw [hWdef]\n exact measure_biUnion_finset_le _ _\n _ = ENNReal.ofReal ((∑ h ∈ Bad (s, a, n', gb), μ (cyl Sp Ap h)).toReal) :=\n (ENNReal.ofReal_toReal hfin).symm\n _ ≤ ENNReal.ofReal (Real.exp (-(c/2))) := by\n refine ENNReal.ofReal_le_ofReal ?_\n rw [ENNReal.toReal_sum (fun h _ => measure_ne_top μ _)]\n exact hch\n have ht0R : (0:ℝ) < (t:ℝ) := by exact_mod_cast ht\n have harith : ((Fintype.card S * (Fintype.card A * (t * 2 ^ (Fintype.card S))) : ℕ) : ℝ)\n * Real.exp (-(c/2)) ≤ 1 / (20 * (t:ℝ)^6) := by\n have hQpos : (0:ℝ) < 2 * (Fintype.card A : ℝ) * (T:ℝ) := by linarith\n have hexp : Real.exp (c/2)\n = (2 * (Fintype.card A : ℝ) * (T:ℝ)) ^ (7 * Fintype.card S) := by\n have hh : c / 2\n = ((7 * Fintype.card S : ℕ) : ℝ) * Real.log (2 * (Fintype.card A : ℝ) * (T:ℝ)) := by\n rw [hcdef]; push_cast; ring\n rw [hh, Real.exp_nat_mul, Real.exp_log hQpos]\n have hD : (0:ℝ) < (2 * (Fintype.card A : ℝ) * (T:ℝ)) ^ (7 * Fintype.card S) := by positivity\n have ht6 : (0:ℝ) < 20 * (t:ℝ)^6 := by\n have := pow_pos ht0R 6\n linarith\n have hnat := nat_arith (Fintype.card S) (Fintype.card A) t T hS1 hA1 ht hT\n have hcast : 20 * (t:ℝ)^6\n * ((Fintype.card S * (Fintype.card A * (t * 2 ^ (Fintype.card S))) : ℕ) : ℝ)\n ≤ (2 * (Fintype.card A : ℝ) * (T:ℝ)) ^ (7 * Fintype.card S) := by\n have h2 := (Nat.cast_le (α := ℝ)).2 hnat\n push_cast at h2 ⊢\n linarith\n rw [Real.exp_neg, hexp, ← div_eq_mul_inv, div_le_div_iff₀ hD ht6, one_mul]\n linarith\n have hcard : Fintype.card (S × A × Fin t × (S → Bool))\n = Fintype.card S * (Fintype.card A * (t * 2 ^ (Fintype.card S))) := by\n simp [Fintype.card_prod, Fintype.card_fin, Fintype.card_fun]\n calc μ {ω | ¬ goodEvent Sp Ap P t T ω} ≤ μ (⋃ i, W i) := measure_mono hcover\n _ ≤ ∑' i, μ (W i) := measure_iUnion_le _\n _ = ∑ i : S × A × Fin t × (S → Bool), μ (W i) := tsum_fintype _\n _ ≤ ∑ _i : S × A × Fin t × (S → Bool), ENNReal.ofReal (Real.exp (-(c/2))) :=\n Finset.sum_le_sum (fun i _ => hWbound i)\n _ = (Fintype.card (S × A × Fin t × (S → Bool)) : ENNReal)\n * ENNReal.ofReal (Real.exp (-(c/2))) := by\n rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]\n _ = ENNReal.ofReal (((Fintype.card S * (Fintype.card A * (t * 2 ^ (Fintype.card S))) : ℕ) : ℝ)\n * Real.exp (-(c/2))) := by\n rw [hcard, ← ENNReal.ofReal_natCast, ← ENNReal.ofReal_mul (by positivity)]\n _ ≤ ENNReal.ofReal (1 / (20 * (t:ℝ)^6)) := ENNReal.ofReal_le_ofReal harith\n\nend ResearchLevel\n"} +{"id": "v24-22-0881", "source": "Research-level", "targets": [{"label": "Theorem 7", "decls": ["theorem7"], "statement": "Theorem 7 For any $\\mathcal{H}$ with $vc(\\mathcal{H}) = d$ and $\\mathcal{U}(P)=\\{Q\\ll P:D_{2}(Q\\|P)\\leq\\rho\\},\\rho>0,\\forall\\varepsilon,\\delta\\in(0,1)$ (the constant hidden in $O(\\cdot)$ may depend on $\\rho$)\n\n$$\n\\mathcal{M}_{AG}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})=O\\left(\\frac{d}{\\varepsilon^{4}}\\log\\left(\\frac{d}{\\varepsilon^{4}}\\right)+\\frac{1}{\\varepsilon^{4}}\\Big(\\frac{1}{c_{2}(\\rho)-1}\\vee 1\\Big)+\\frac{d}{\\varepsilon^{4}}\\log\\left(\\frac{e}{d}\\right)+\\frac{\\log(2/\\delta)}{\\varepsilon^{4}}\\right).\\tag{3}\n$$", "context_ids": ["v24-22-0881:ctx1", "v24-22-0881:ctx2", "v24-22-0881:ctx3", "v24-22-0881:ctx4", "v24-22-0881:ctx7", "v24-22-0881:ctx8", "v24-22-0881:ctx9", "v24-22-0881:ctx10", "v24-22-0881:ctx11", "v24-22-0881:ctx12", "v24-22-0881:ctx16", "v24-22-0881:ctx17", "v24-22-0881:ctx19", "v24-22-0881:ctx20", "v24-22-0881:ctx21"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}, {"label": "Theorem 9", "decls": ["theorem9"], "statement": "Theorem 9 For any $\\mathcal{H}$ with $vc(\\mathcal{H})=d$ and $\\mathcal{U}(P)=\\{Q\\ll P:D_{2}(Q\\|P)\\leq\\rho\\}$ with $\\rho \\in$ $\\begin{array}{r}{\\left(0,\\frac{3-2\\sqrt{2}}{2}\\right),\\forall\\varepsilon\\in(0,\\frac{1}{8\\sqrt{2}}),\\forall\\delta\\in(0,\\frac{1}{8})}\\end{array}$\n\n$$\n\\mathcal{M}_{AG}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})=\\Omega\\Bigg(\\frac{\\left(\\frac{1}{2}-\\frac{\\sqrt{2}}{16}\\rho^{1/2}\\right)^{2}d+\\log(1/\\delta)}{\\varepsilon^{2}}\\Bigg).\\tag{4}\n$$", "context_ids": ["v24-22-0881:ctx1", "v24-22-0881:ctx2", "v24-22-0881:ctx3", "v24-22-0881:ctx4", "v24-22-0881:ctx6", "v24-22-0881:ctx7", "v24-22-0881:ctx9", "v24-22-0881:ctx10", "v24-22-0881:ctx13", "v24-22-0881:ctx22", "v24-22-0881:ctx23", "v24-22-0881:ctx24", "v24-22-0881:ctx25", "v24-22-0881:ctx26"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Statistical Estimation & Minimax Theory"}, {"label": "Theorem 12", "decls": ["theorem12"], "statement": "Theorem 12 Let $\\mathcal{H}\\subseteq \\mathcal{Y}^{\\mathcal{X}}$ with $vc(\\mathcal{H})=d$ and $\\mathcal{U}(P)=\\{Q\\ll P:D_{2}(Q\\|P)\\leq\\rho\\}$ . $\\forall\\varepsilon\\in(0,1),\\forall\\delta\\in(0,1/4)$ , we have\n\n$$\n\\begin{array}{r l}&{\\mathcal{M}_{RE}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})=O\\Bigg(\\frac{16(1+2\\rho)d}{\\varepsilon^{2}}\\log\\left(\\frac{8(1+2\\rho)d}{\\varepsilon^{2}}\\right)}\\\\ &{\\qquad+\\frac{8(1+2\\rho)}{\\varepsilon^{2}}\\left(d\\log\\left(\\frac{2e}{d}\\right)+\\log\\left(\\frac{2}{\\delta}\\right)\\right)\\Bigg).}\\end{array}\\tag{6}\n$$", "context_ids": ["v24-22-0881:ctx1", "v24-22-0881:ctx2", "v24-22-0881:ctx3", "v24-22-0881:ctx5", "v24-22-0881:ctx6", "v24-22-0881:ctx7", "v24-22-0881:ctx9", "v24-22-0881:ctx10", "v24-22-0881:ctx14", "v24-22-0881:ctx15", "v24-22-0881:ctx18", "v24-22-0881:ctx21", "v24-22-0881:ctx27"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "### Proof of Theorem 7\n\nTo prove (3), it suffices to show that applying the DRERM with a sample size m of the same order as in (3) yields an ε, δ-learner for $\\mathcal{H}$.\n\nProof [Proof of Lemma 5] By definition, $g_{2}(\\eta,P)=\\eta$ for $\\eta \\geq 1$ , and\n\n$$\n\\begin{array}{c}{{g_{2}\\left(-\\displaystyle\\frac{1}{c_{2}-1},P\\right)\\ge\\displaystyle\\frac{c_{2}}{c_{2}-1}-\\displaystyle\\frac{1}{c_{2}-1}}}\\\\ {{=1=g_{2}(1,P).}}\\end{array}\n$$\n\nSince $\\eta\\mapsto g_{2}(\\eta,P)$ is convex, this implies the result.\n\nProof [Proof of Theorem 7] The proof is a modification of the techniques utilized by Koltchinskii and Panchenko (2002). Let $(x_{1},y_{1}),\\dots,(x_{m},y_{m})$ be a classification training set, $P_{m}$ denote the corresponding empirical distribution and $h^{*}\\in\\mathop{\\mathrm{argmin}}_{h\\in\\mathcal{H}}R_{2}(h;P)$ . We begin by decomposing the excess risk:\n\n$$\n\\begin{array}{r}{R_{2}(\\hat{h};P)-R_{2}(h^{*};P)\\le R_{2}(\\hat{h};P)-R_{2}(\\hat{h};P_{m})+R_{2}(h^{*};P_{m})-R_{2}(h^{*};P),}\\end{array}\n$$\n\nwhere the last step follows from the definition of $\\hat{h}$ Define\n\n$$\n\\hat{\\eta}: =\\underset{\\eta\\in\\mathbb{R}}{\\mathrm{argmin}}\\left\\{c_{2}\\mathbb{E}_{P_{m}}\\left[\\left(\\varphi_{\\eta,\\hat{h}}(x,y)\\right)_{+}^{2}\\right]^{1/2}+\\eta\\right\\},\n$$\n\n$$\n\\eta^{*}: =\\underset{\\eta\\in\\mathbb{R}}{\\mathrm{argmin}}\\left\\{c_{2}\\mathbb{E}_{P}\\left[\\left(\\varphi_{\\eta,h^{*}}(x,y)\\right)_{+}^{2}\\right]^{1/2}+\\eta\\right\\}.\n$$\n\nWe can then write\n\n$$\n\\begin{array}{r l}&{R_{2}(\\hat{h};P)-R_{2}(\\hat{h};P_{m})=\\underset{\\eta\\in\\mathbb{R}}{\\operatorname*{min}}\\left\\{c_{2}\\mathbb{E}_{P}\\left[\\left(\\varphi_{\\eta,\\hat{h}}(x,y)\\right)_{+}^{2}\\right]^{\\frac{1}{2}}+\\eta\\right\\}-\\left(c_{2}\\mathbb{E}_{P_{m}}\\left[\\left(\\varphi_{\\hat{\\eta},\\hat{h}}(x,y)\\right)_{+}^{2}\\right]^{\\frac{1}{2}}+\\hat{\\eta}\\right)}\\\\ &{\\leq c_{2}\\left(\\mathbb{E}_{P}\\left[\\left(\\varphi_{\\hat{\\eta},\\hat{h}}(x,y)\\right)_{+}^{2}\\right]^{\\frac{1}{2}}-\\mathbb{E}_{P_{m}}\\left[\\left(\\varphi_{\\hat{\\eta},\\hat{h}}(x,y)\\right)_{+}^{2}\\right]^{\\frac{1}{2}}\\right)}\\\\ &{\\leq c_{2}\\left|\\int\\left(\\varphi_{\\hat{\\eta},\\hat{h}}(x,y)\\right)_{+}^{2}\\left(P_{m}-P\\right)\\left(d x d y\\right)\\right|^{\\frac{1}{2}}.}\\end{array}\n$$\n\nFollowing the same logic,\n\n$$\nR_{2}(h^{\\ast};P_{m})-R_{2}(h^{\\ast};P)\\leq c_{2}\\left|\\int\\left(\\varphi_{\\eta^{\\ast},h^{\\ast}}(x,y)\\right)_{+}^{2}\\left(P_{m}-P\\right)(dxdy)\\right|^{\\frac{1}{2}}.\\tag{15}\n$$\n\nBy Lemma 5, $\\hat{\\eta}\\in \\left[ - \\frac{1}{c_{2}- 1}, 1 \\right]$ . We now define $\\begin{array}{r}{\\Phi=\\left\\{\\varphi_{\\eta,h}:h\\in\\mathcal{H},\\eta\\in\\left[-\\frac{1}{c_{2}-1},1\\right]\\right\\},\\psi(t)=t_{+}^{2}}\\end{array}$ and $\\psi \\circ \\Phi = \\{\\psi \\circ \\varphi: \\varphi \\in \\Phi\\}$ , where $\\circ$ denotes the composition of functions. Thus, we can write\n\n$$\nR_{2}(\\hat{h};P)-R_{2}(\\hat{h};P_{m})\\leq c_{2}\\left(\\operatorname*{sup}_{\\varphi\\in\\psi\\circ\\Phi}\\left[\\int\\varphi(x,y)\\left(P-P_{m}\\right)(d x d y)\\right]\\right)^{\\frac{1}{2}}.\n$$\n\nSince $\\mathbb{1}\\left[h(x)\\neq y\\right]\\in\\left[0,1\\right]$ for any $h \\in \\mathcal H$ and $\\begin{array}{r}{\\eta \\in \\left[ - \\frac{1}{c_{k}- 1}, 1 \\right]}\\end{array}$ , then for any $\\varphi \\in \\psi \\circ \\Phi$ , we have $\\begin{array}{r}{\\|\\varphi\\|_{\\infty}\\le\\left(\\frac{c_{2}}{c_{2}-1}\\right)^{2}}\\end{array}$\n\nBy a standard symmetrization argument, with probability of at least $1 - \\delta / 2$\n\n$$\nR_{2}({\\hat{h}};P)-R_{2}({\\hat{h}};P_{m})\\leq c_{2}\\left(2\\mathcal{R}_{m}(\\psi\\circ\\Phi)+\\left(\\frac{c_{2}}{c_{2}-1}\\right)^{2}\\sqrt{\\frac{2\\log(2/\\delta)}{m}}\\right)^{\\frac 12}\n$$\n\nMoreover, from (15) and Hoeffding's inequality, it follows that\n\n$$\nR_{2}(h^{\\ast};P_{m})-R_{2}(h^{\\ast};P)\\leq\\frac{c_{2}}{c_{2}-1}\\left(\\frac{\\log(2/\\delta)}{2m}\\right)^{\\frac{1}{4}},\\tag{16}\n$$\n\nwith probability of at least $1 - \\delta / 2$\n\nCombining these results, with probability of at least $1 - \\delta .$\n\n$$\n\\begin{array}{r l}&{R_{2}(\\hat{h};P)-R_{2}(h^{*};P)\\leq c_{2}\\left[\\left(2\\mathcal{R}_{m}(\\psi\\circ\\Phi)+\\left(\\frac{c_{2}}{c_{2}-1}\\right)^{2}\\sqrt{\\frac{2\\log(2/\\delta)}{m}}\\right)^{\\frac{1}{2}}+\\frac{c_{2}}{c_{2}-1}\\left(\\frac{\\log(2/\\delta)}{2m}\\right)^{\\frac{1}{4}}\\right]}\\\\ &{\\qquad\\leq c_{2}\\left[2\\left(\\mathcal{R}_{m}(\\psi\\circ\\Phi)\\right)^{\\frac{1}{2}}+\\frac{3c_{2}}{c_{2}-1}\\left(\\frac{\\log(2/\\delta)}{2m}\\right)^{\\frac{1}{4}}\\right].}\\end{array}\\tag{17}\n$$\n\nTherefore, it suffices to bound $\\mathcal{R}_{m}(\\psi\\circ\\Phi)$ . It can be readily observed that $t \\mapsto t_{+}^{2}$ is $\\displaystyle \\frac{2 c_{2}}{c_{2}- 1}$ -Lipschitz on $\\textstyle\\left[-1,{\\frac{c_{2}}{c_{2}-1}}\\right]$ ; thus, by invoking Lemma 21, we get:\n\n$$\n\\mathcal{R}_{m}(\\psi\\circ\\Phi)\\leq\\frac{2c_{2}}{c_{2}-1}\\mathcal{R}_{m}(\\Phi).\\tag{18}\n$$\n\nMore specifically,\n\n$$\n\\begin{array}{r l}\\mathcal{R}_{m}(\\Phi)&=\\mathbb{E}\\left[\\frac{1}{m}\\sup_{h\\in\\mathcal{H},\\eta\\in\\left[-\\frac{1}{c_{2}-1},1\\right]}\\sum_{i=1}^{m}\\sigma_{i}\\left(\\mathbb{1}[h(x)\\neq y]-\\eta\\right)\\right]\\\\ &\\le\\mathbb{E}\\left[\\sup_{h\\in\\mathcal{H}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_{i}\\mathbb{1}[h(x)\\neq y]\\right]+\\mathbb{E}\\left[\\sup_{\\eta\\in\\left[-\\frac{1}{c_{2}-1},1\\right]}\\frac{1}{m}\\left|\\sum_{i=1}^{m}\\eta\\sigma_{i}\\right|\\right]\\\\ &\\le\\mathcal{R}_{m}(\\mathcal{L}_{\\mathcal{H}})+\\frac{1}{m}\\left(\\frac{1}{c_{2}-1}\\vee 1\\right)\\mathbb{E}\\left[\\left|\\sum_{i=1}^{m}\\sigma_{i}\\right|\\right]\\\\ &\\le\\mathcal{R}_{m}(\\mathcal{L}_{\\mathcal{H}})+\\frac{1}{m}\\left(\\frac{1}{c_{2}-1}\\vee 1\\right)\\mathbb{E}\\left[\\left(\\sum_{i=1}^{m}\\sigma_{i}\\right)^{2}\\right]^{1/2}\\\\ &\\le\\mathcal{R}_{m}(\\mathcal{L}_{\\mathcal{H}})+\\frac{1}{\\sqrt{m}}\\left(\\frac{1}{c_{2}-1}\\vee 1\\right).\\end{array}\\tag{19}\n$$\n\nTo bound $\\mathcal{R}_{m}(\\mathcal{L}_{\\mathcal{H}})$ , we define $\\begin{array}{r}{R(A)=\\mathbb{E}_{\\sigma}\\left[\\operatorname*{sup}_{h\\in\\mathcal{H}}\\sum_{i=1}^{m}\\sigma_{i}\\mathbb{1}\\left[h(x_{i})\\neq y_{i}\\right]\\right]}\\end{array}$\n\nRecall that the Sauer-Shelah lemma (Shalev-Shwartz and Ben-David, 2014, Lemma 6.10) tells us that if $\\operatorname{vc}(\\mathcal{H})=d.$ then\n\n$$\n|\\{(h(x_{1}),\\ldots,h(x_{m})):h\\in\\mathcal{H}\\}|\\leq\\left(\\frac{em}{d}\\right)^{d}.\n$$\n\nBy the Massart Lemma (Shalev-Shwartz and Ben-David, 2014, Lemma 26.8), we have:\n\n$$\n\\mathcal{R}_{m}(\\mathcal{L}_{\\mathcal{H}})\\leq\\sqrt{\\frac{2d\\log(em/d)}{m}}\\tag{20}\n$$\n\nCombining (17), (18), (19) and (20), the following holds:\n\n$$\nR_{2}({\\hat{h}};P)-R_{2}(h^{*};P)\\leq C\\left({\\frac{2d\\log(em/d)+\\left({\\frac{1}{c_{2}-1}}\\vee 1\\right)^{2}+\\log(2/\\delta)}{m}}\\right)^{1/4}\\tag{21}\n$$\n\nfor some constant C. To ensure that the right-hand side of (21) is smaller than ε, we need:\n\n$$\nm\\geq\\frac{C}{\\varepsilon^{4}}\\left(d\\log(m)+d\\log(e/d)+\\left(\\frac{1}{c_{2}-1}\\vee 1\\right)^{2}+\\log(2/\\delta)\\right).\n$$\n\nUsing Lemma 22, a sufficient condition for the inequality to hold is that\n\n$$\nm\\geq\\frac{4Cd}{\\varepsilon^{4}}\\log(\\frac{2Cd}{\\varepsilon^{4}})+\\frac{2C}{\\varepsilon^{4}}\\left(\\left(\\frac{1}{c_{2}-1}\\vee 1\\right)^{2}+d\\log(e/d)+\\log(2/\\delta)\\right),\n$$\n\nwhich concludes our proof.\n\n### Proof of Theorem 9\n\nProof [Proof of Theorem 9] We will prove the lower bound in two parts. First, we will show that $\\mathcal{M}_{\\mathrm{AG}}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})\\ge\\log(\\frac{1}{4\\delta})/(2\\varepsilon^{2})$ ; second, we will show that for every $\\delta \\leq 1 / 8$ ,we have that $\\begin{array}{r}{\\mathcal{M}_{\\mathrm{AG}}(\\varepsilon,1/8;\\mathcal{H},\\mathcal{U})\\ge\\frac{\\left(\\frac{1}{2}-\\frac{\\sqrt{2}}{16}\\rho^{1/2}\\right)^{2}d}{128\\varepsilon^{2}}}\\end{array}$ These two bounds will conclude the proof.\n\nWe first demonstrate that $\\mathcal{M}_{\\mathrm{AG}}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})\\ge\\log(\\frac{1}{4\\delta})/(2\\varepsilon^{2})$\n\nTo do so, we show that for a sample with size $\\begin{array}{r}{m\\leq\\log(\\frac{1}{4\\delta})/(2\\varepsilon^{2})}\\end{array}$ , $\\mathcal{H}$ is not learnable for any $\\varepsilon\\in\\left(0,{\\frac{1}{\\sqrt{2}}}\\right)$ and $\\delta\\in(0,1)$\n\nLet us choose one example that is shattered by $\\mathcal{H}$. That is, let c be an example such that there are $h_{+}, h_{-}\\in \\mathcal{H}$ for which $h_{+}(c)=1$ and $h_{-}(c)= -1$ . Define two distributions, $P_{+}$ and $P_{-}$ , such that for $b\\in\\{+1,-1\\}$ , we have\n\n$$\nP_{b}(x,y)=\\left\\{\\begin{array}{l l}{\\displaystyle\\frac{1+yb\\varepsilon}{2},\\quad\\mathrm{if}\\quad x=c,}\\\\ {\\displaystyle~0\\quad,\\quad\\mathrm{otherwise}.}\\end{array}\\right.\n$$\n\nAny training set sampled from $P_{b}$ has the form $S=((c,y_{1}),\\dots,(c,y_{m}))$ . Let $\\mathcal{A}$ be an arbitrary algorithm. Therefore, the hypothesis that $\\mathcal{A}$ outputs receiving sample $S$ is fully characterized by the vector $\\mathbf{y}=(y_{1},\\dots,y_{m})\\in\\{+1,-1\\}^{m}$ . Upon receiving a training set $S,$ the algorithm $\\mathcal{A}$ returns a hypothesis $h_{S}:\\mathcal{X}\\to\\{+1,-1\\}$ . Since the error of $h_{S}$ w.r.t. $P_{b}$ depends only on $h(c)$ , we can think of $\\mathcal{A}$ as a mapping from $\\{+1,-1\\}^{m}$ into $\\{+1,-1\\}$\n\nTherefore, we denote by $\\mathcal{A}(\\mathbf{y})$ the value in $\\{+1,-1\\}$ corresponding to the prediction $h_{S}(c)$ ; here, $h_{S}$ is the hypothesis that $\\mathcal{A}$ outputs upon receiving the training set $S =$ $((c,y_{1}),\\dots,(c,y_{m}))$ . Claim 1. The hypothesis $h_{b}(c)=b$ has optimal distributionally robust risk on $P_{b}$\n\nNote that for any hypothesis h, we have\n\n$$\n\\begin{array}{r l}R_{2}(h;P_{b})&=\\sup\\big\\{\\mathbb{E}_{P}\\big [\\mathbb{1}[h(x)\\neq y]\\big]:P\\ll P_{b},D_{2}(P\\|P_{b})\\le\\rho\\big\\}\\\\ &=\\inf_{\\eta\\in\\mathbb{R}}\\Big\\{c_{2}(\\rho)\\mathbb{E}_{P_{b}}\\Big [(\\mathbb{1}[h(x)\\neq y]-\\eta)_{+}^{2}\\Big]^{1/2}+\\eta\\Big\\}\\\\ &=\\inf_{\\eta\\in\\mathbb{R}}\\Big\\{c_{2}(\\rho)\\Big(\\frac{1+\\varepsilon}{2}(\\mathbb{1}[h(c)\\neq b]-\\eta)_{+}^{2}+\\frac{1-\\varepsilon}{2}(\\mathbb{1}[h(c)\\neq-b]-\\eta)^{2}\\Big)^{1/2}+\\eta\\Big\\}.\\end{array}\n$$\n\nSubstituting $h_{b}$ into the above formulation, we obtain:\n\n$$\nR_{2}(h_{b};P_{b})=\\operatorname*{inf}_{\\eta\\in\\mathbb{R}}\\Big\\{c_{2}(\\rho)\\Big(\\frac{1+\\varepsilon}{2}(-\\eta)_{+}^{2}+\\frac{1-\\varepsilon}{2}(1-\\eta)_{+}^{2}\\Big)^{1/2}+\\eta\\Big\\}.\n$$\n\nNoting that $(-\\eta)_{+}^{2}\\leq(1-\\eta)_{+}^{2}$ , we get $R_{2}(h_{b};P_{b})\\le R_{2}(h;P_{b})$ for any $h \\in \\mathcal H$\n\nInvoking Lemma 23, we have\n\n$$\nR_{2}(\\mathcal{A}(\\mathbf{y});P_{b})-\\inf_{h\\in\\mathcal{H}}R_{2}(h;P_{b})=\\begin{cases}\\varepsilon,&\\text{if }\\mathcal{A}(\\mathbf{y})(c)\\neq b,\\\\ 0,&\\text{otherwise.}\\end{cases}\n$$\n\nFix $\\mathcal{A}$. For $b\\in\\{+1,-1\\}$ , let $Y^{b}=\\{\\mathbf{y}\\in\\{+1,-1\\}^{m}:\\mathcal{A}(\\mathbf{y})\\neq b\\}$ . The distribution $P_{b}$ induces a probability $\\mathcal{D}_{b}$ over $\\{+1,-1\\}^{m}$ Hence,\n\n$$\n\\mathbb{P}\\left[R_{2}(\\mathcal{A}(\\mathbf{y});P_{b})-R_{2}(h_{b};P_{b})=\\varepsilon\\right]=P_{b}(Y^{b})=\\sum_{\\mathbf{y}}\\mathcal{D}_{b}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq b].\n$$\n\nDenote $N^{+}= \\{\\mathbf{y}: | \\{i : y_{i}= + 1 \\}| \\geq m / 2 \\}$ and $N^{-}=\\{+1,-1\\}^{m}\\backslash N^{+}$ . Note that for any $\\mathbf{y}\\in N^{+}$ , we have ${\\mathcal{D}}_{+}[ \\mathbf{y}]{\\geq}{\\mathcal{D}}_{-}[ \\mathbf{y}]$ , while for any $\\mathbf{y}\\in N^{-}$ , we have ${\\mathcal{D}}_{-}[ \\mathbf{y}]{\\geq}{\\mathcal{D}}_{+}[ \\mathbf{y}]$ . Therefore,\n\n$$\n\\begin{array}{r l}\\max_{b\\in\\{+1,-1\\}}\\mathbb{P}\\left[R_{2}(\\mathcal{A}(\\mathbf{y});P_{b})-R_{2}(h_{b};P_{b})=\\varepsilon\\right]&=\\max_{b\\in\\{+1,-1\\}}\\sum_{\\mathbf{y}}\\mathcal{D}_{b}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq b]\\\\ &\\geq\\frac{1}{2}\\sum_{\\mathbf{y}}\\mathcal{D}_{+}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq+1]+\\frac{1}{2}\\sum_{\\mathbf{y}}\\mathcal{D}_{-}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq-1]\\\\ &=\\frac{1}{2}\\sum_{\\mathbf{y}\\in N^{+}}\\left(\\mathcal{D}_{+}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq+1]+\\mathcal{D}_{-}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq-1]\\right)\\\\ &\\quad+\\frac{1}{2}\\sum_{\\mathbf{y}\\in N^{-}}\\left(\\mathcal{D}_{+}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq+1]+\\mathcal{D}_{-}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq-1]\\right)\\\\ &\\geq\\frac{1}{2}\\sum_{\\mathbf{y}\\in N^{+}}\\left(\\mathcal{D}_{-}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq+1]+\\mathcal{D}_{-}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq-1]\\right)\\\\ &\\quad+\\frac{1}{2}\\sum_{\\mathbf{y}\\in N^{-}}\\left(\\mathcal{D}_{+}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq+1]+\\mathcal{D}_{+}[\\mathbf{y}]\\mathbb{1}[\\mathcal{A}(\\mathbf{y})\\neq-1]\\right)\\\\ &=\\frac{1}{2}\\sum_{\\mathbf{y}\\in N^{+}}\\mathcal{D}_{-}[\\mathbf{y}]+\\frac{1}{2}\\sum_{\\mathbf{y}\\in N^{-}}\\mathcal{D}_{+}[\\mathbf{y}].\\end{array}\n$$\n\nNext, note that $\\begin{array}{r}{\\sum_{\\mathbf{y}\\in N^{+}}\\mathcal{D}_{-}[ \\mathbf{y}] = \\sum_{\\mathbf{y}\\in N^{-}}\\mathcal{D}_{+}[ \\mathbf{y}]}\\end{array}$ , and both values are the probability that a Binomial $(m,(1-\\varepsilon)/2)$ random variable will have a value greater than $m / 2$ . Using Lemma 24, this probability is lower bounded by\n\n$$\n\\frac{1}{2}\\left(1-\\sqrt{1-\\exp(-m\\varepsilon^{2}/(1-\\varepsilon^{2})}\\right)\\geq\\frac{1}{2}\\left(1-\\sqrt{1-\\exp(-2m\\varepsilon^{2})}\\right),\n$$\n\nwhere we derive under the assumption that $\\varepsilon^{2}\\leq 1 / 2$ It follows that if $m\\leq 0.5\\log(1/(4\\delta))/\\varepsilon^{2}$ then there exists b such that\n\n$$\n\\mathbb{P}[R_{2}(\\mathcal{A}(\\mathbf{y});P_{b})-R_{2}(h_{b};P_{b})=\\varepsilon]\\ge\\frac{1}{2}\\left(1-\\sqrt{1-\\sqrt{4\\delta}}\\right)\\ge\\delta,\n$$\n\nwhere the last inequality can be obtained through standard algebraic manipulations. This concludes our proof.\n\nNext, we demonstrate that $\\begin{array}{r}{\\mathcal{M}_{\\mathrm{AG}}(\\varepsilon,1/8;\\mathcal{H},\\mathcal{U})\\geq\\frac{\\left(\\frac{1}{2}-\\frac{\\sqrt{2}}{16}\\rho^{1/2}\\right)^{2}d}{128\\varepsilon^{2}}.}\\end{array}$\n\nWe shall now prove that for every $\\varepsilon < \\frac{1}{8 \\sqrt{2}}$ we have that $\\begin{array}{r}{\\mathcal{M}_{\\mathrm{AG}}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})\\ge\\frac{\\left(\\frac{1}{2}-\\frac{\\sqrt{2}}{16}\\rho^{1/2}\\right)^{2}d}{128\\varepsilon^{2}}}\\end{array}$ Let $r = 8 \\varepsilon$ , and note that $r\\in(0,1/\\sqrt{2})$ . We will construct a family of distributions as follows. First, let $C=\\{c_{1},\\ldots,c_{d}\\}$ be a set of d instances that are shattered by $\\mathcal{H}$. Second, for each vector $\\mathbf{b}=(b_{1},\\ldots,b_{d})\\in\\{+1,-1\\}^{d}$ , define a distribution $P_{\\mathbf{b}}$ such that\n\n$$\nP_{\\mathbf{b}}(x,y)=\\left\\{\\begin{array}{l l}{\\displaystyle\\frac{1}{d}\\cdot\\frac{1+yb_{i}r}{2}}&{,\\mathrm{if}\\ \\exists i:x=c_{i}}\\\\ {\\qquad 0}&{,\\mathrm{otherwise.}}\\end{array}\\right.\n$$\n\nThat is, to sample an example according to $P_{\\mathbf{b}}$ , we first sample an element $c_{i}\\in C$ uniformly at random, then set the label to be $b_{i}$ with probability $(1+r)/2$ or $- b_{i}$ with probability $(1-r)/2$\n\nClaim 2. The hypothesis $h_{\\mathbf{b}}$ satisfying $h(c_{i})=b_{i},\\forall i\\in [d]$ , has the optimal distributionally robust risk on $P_{\\mathbf{b}}$\n\nRecalling the dual formulation (2), $R_{2}(h;{P_{\\bf{b}}})$ can be rewritten as follows:\n\n$$\nR_{2}(h;P_{\\mathbf{b}})=\\operatorname*{inf}_{\\eta\\in\\mathbb{R}}\\left\\{c_{2}\\left[\\frac{1}{d}\\sum_{i=1}^{d}\\left(\\frac{1+r}{2}(\\mathbb{1}[h(c_{i})\\neq b_{i}]-\\eta)_{+}^{2}+\\frac{1-r}{2}(\\mathbb{1}[h(c_{i})\\neq-b_{i}]-\\eta)_{+}^{2}\\right)\\right]^{1/2}+\\eta\\right\\}.\n$$\n\nFor each $i\\in [d],h_{\\mathbf{b}}(c_{i})=b_{i}$ , the summand above can be written as $\\begin{array}{r}{\\frac{1+r}{2}(-\\eta)_{+}^{2}{+}\\frac{1-r}{2}(1-\\eta)_{+}^{2}}\\end{array}$ \nfor $h(c_{i})\\neq b_{i}$ , the summand is $\\textstyle\\frac{1+r}{2}(1-\\eta)_{+}^{2}+\\frac{1-r}{2}(-\\eta)_{+}^{2}$ . Combining $r > 0$ and $(-\\eta)_{+}^{2}\\leq(1-\\eta)_{+}^{2}$ \nwe have $\\begin{array}{r}{\\frac{1+r}{2}(-\\eta)_{+}^{2}+\\frac{1-r}{2}(1-\\eta)_{+}^{2}\\leq\\frac{1+r}{2}(1-\\eta)_{+}^{2}+\\frac{1-r}{2}(-\\eta)_{+}^{2}}\\end{array}$ , which concludes our claim. We denote $d_{+}= |\\{i\\in [d]:\\mathcal{A}(S)(c_{i})=b_{i}\\}|$ and $d_{-}= |\\{i\\in [d]:{\\cal A}(S)(c_{i})\\neq b_{i}\\}|$ , therefore $d_{+}+ d_{-}= d$. Next, we will simplify the distributionally robust risk as follows:\n\n$$\n\\begin{array}{r l}R_{2}(\\mathcal{A}(S);P_{\\mathbf{b}})&=\\inf_{\\eta\\in\\mathbb{R}}\\Bigg\\{c_{2}\\Bigg[\\frac{d_{+}}{d}\\left(\\frac{1+r}{2}(-\\eta)_{+}^{2}+\\frac{1-r}{2}(1-\\eta)_{+}^{2}\\right)+\\\\ &\\qquad\\frac{d_{-}}{d}\\left(\\frac{1+r}{2}(1-\\eta)_{+}^{2}+\\frac{1-r}{2}(-\\eta)_{+}^{2}\\right)\\Bigg]^{1/2}+\\eta\\Bigg\\}\\\\ &=\\inf_{\\eta\\in\\mathbb{R}}\\left\\{c_{2}\\left[\\left(\\frac{1}{2}+\\frac{r}{2}\\cdot\\frac{d_{+}-d_{-}}{d}\\right)(-\\eta)_{+}^{2}+\\left(\\frac{1}{2}-\\frac{r}{2}\\cdot\\frac{d_{+}-d_{-}}{d}\\right)(1-\\eta)_{+}^{2}\\right]^{1/2}+\\eta\\right\\}.\\end{array}\n$$\n\nTherefore, $R_{2}(A(S);P_{\\mathbf{b}})$ can be viewed as the distributionally robust risk of the classifier $h^{\\prime}(x)\\equiv 1$ on distribution $Q$ ,with\n\n$$\nQ(x,y)=\\left\\{\\begin{array}{c l}{\\frac{1+yr(d_{+}-d_{-})/d}{2}\\quad}&{\\mathrm{,if}x=c}\\\\ {0}&{\\mathrm{,otherwise.}}\\end{array}\\right.\n$$\n\nInvoking Lemma 23, we obtain\n\n$$\nR_{2}(A(S);P_{\\bf b})=\\frac{1}{2}\\left(1-r\\cdot\\frac{d_{+}-d_{-}}{d}+\\sqrt{2\\rho\\left(1-r^{2}\\cdot\\frac{(d_{+}-d_{-})^{2}}{d^{2}}\\right)}\\right).\n$$\n\nFollowing the same logic, we have $\\begin{array}{r}{R_{2}(h_{\\mathbf{b}};P_{\\mathbf{b}})=\\frac{1}{2}\\left(1-r+\\sqrt{2\\rho\\left(1-r^{2}\\right)}\\right)}\\end{array}$\n\nThen, after some algebraic manipulations, we have:\n\n$$\n\\begin{array}{r l}&{R_{2}(A(S);P_{\\mathbf{b}})-\\underset{h\\in\\mathcal{H}}{\\operatorname*{inf}}R_{2}(h;P_{\\mathbf{b}})=R_{2}(A(S);P_{\\mathbf{b}})-R_{2}(h_{\\mathbf{b}};P_{\\mathbf{b}})}\\\\ &{\\qquad=r\\cdot\\frac{d_{-}}{d}+\\frac{1}{2}\\left(\\sqrt{2\\rho(1-r^{2}(d_{+}-d_{-})^{2}/d^{2})}-\\sqrt{2\\rho(1-r^{2})}\\right)}\\\\ &{\\qquad\\geq r\\cdot\\frac{d_{-}}{d},}\\end{array}\\tag{9}\n$$\n\nwhere the last line follows from $(d_{+}-d_{-})^{2}/d^{2}\\leq 1$\n\nNext, fix some learning algorithm A, we have that:\n\n$$\n\\operatorname*{max}_{P_{\\mathbf{b}}:\\mathbf{b}\\in\\{+1,-1\\}^{d}}\\underset{S\\sim P_{\\mathbf{b}}^{m}}{\\mathbb{E}}\\left[R_{2}(A(S);P_{\\mathbf{b}})-\\operatorname*{inf}_{h\\in\\mathcal{H}}R_{2}(h;P_{\\mathbf{b}})\\right]\\tag{10}\n$$\n\n$$\n\\geq\\underset{P_{\\mathbf{b}}:\\mathbf{b}\\sim U(\\{+1,-1\\}^{d})}{\\mathbb{E}}\\underset{S\\sim P_{\\mathbf{b}}^{m}}{\\mathbb{E}}\\left[R_{2}(A(S);P_{\\mathbf{b}})-\\underset{h\\in\\mathcal{H}}{\\operatorname*{inf}}\\ R_{2}(h;P_{\\mathbf{b}})\\right]\\tag{11}\n$$\n\n$$\n\\geq\\underset{P_{\\mathbf{b}}:\\mathbf{b}\\sim U(\\{+1,-1\\}^{d})}{\\mathbb{E}}\\underset{S\\sim P_{\\mathbf{b}}^{m}}{\\mathbb{E}}\\left[r\\cdot{\\frac{|\\{i\\in [d]:A(S)(c_{i})\\neq b_{i}\\}|}{d}}\\right]\\tag{12}\n$$\n\n$$\n=\\frac{r}{d}\\sum_{i=1}^{d}\\underset{P_{\\mathbf{b}}:\\mathbf{b}\\sim U(\\{+1,-1\\}^{d})}{\\mathbb{E}}\\underset{S\\sim P_{\\mathbf{b}}^{m}}{\\mathbb{E}}\\mathbb{1}[A(S)(c_{i})\\neq b_{i}],\\tag{13}\n$$\n\nwhere the second inequality follows from (9). In addition, using the definition of $P_{\\mathbf{b}}$ , in order to sample $S \\sim P_{\\mathbf{b}}$ , we can first sample $(j_{1},\\ldots,j_{m})\\sim U([d])^{m}$ , set $x_{i}= c_{j_{i}}$ , and finally sample $y_{i}$ such that $\\mathbb{P}[y_{i}=b_{j_{i}}]=(1+r)/2$ Let us simplify the notation and use $y \\sim b$ to denote sampling according to $\\mathbb{P}[y=b]=(1+r)/2$ . Therefore, the right-hand side of (13) equals\n\n$$\n\\frac{r}{d}\\sum_{i=1}^{d}\\underset{j\\sim U([d])^{m}}{\\mathbb{E}}\\underset{\\mathbf{b}\\sim U(\\{+1,-1\\}^{d})}{\\mathbb{E}}\\underset{\\forall k,y_{k}\\sim b_{j_{k}}}{\\mathbb{E}}\\mathbb{1}[A(S)(c_{i})\\neq b_{i}].\\tag{14}\n$$\n\nWe now proceed in two steps. First, in Lemma 25, we show that among all learning algorithms, A, the one that minimizes (14) is the Maximum-Likelihood learning rule, denoted as $\\mathcal{A}_{\\mathrm{ML}}$ . Formally, for each $i,\\ \\mathcal{A}_{\\mathrm{ML}}(S)(c_{i})$ is the majority vote among the set $\\{y_{k}: k \\in$ $[m],x_{k}=c_{i}\\}$ . Second, we lower bound (14) for $\\mathcal{A}_{\\mathrm{ML}}$\n\nFix i. For every $\\mathbf{j}\\in [ d ]^{m}$ , let $n_{i}(\\mathbf{j})= |\\{k:\\mathbf{j}_{k}=i\\}|$ be the number of instances in which the instance is $c_{i}$ . For the Maximum-Likelihood rule, we have that the quantity\n\n$$\n\\underset{\\mathbf{b}\\sim U(\\{+1,-1\\}^{d})}{\\mathbb{E}}\\underset{\\forall k,y_{k}\\sim b_{j_{k}}}{\\mathbb{E}}\\mathbb{1}[A(S)(c_{i})\\neq b_{i}]\n$$\n\nis exactly equal to the probability that a binomial $(n_{i}(\\mathbf{j}),(1-r)/2)$ random variable will be larger than $n_{i}(\\mathbf{j})/2$ . Using Lemma 24, and the assumption $r^{2}\\leq 1 / 2$ , we have that\n\n$$\n\\mathbb{P}[B\\ge n_{i}(\\mathbf{j})/2]\\ge\\frac{1}{2}\\left(1-\\sqrt{1-\\exp\\big(-2n_{i}(\\mathbf{j})r^{2}\\big)}\\right).\n$$\n\nWe have thus demonstrated that\n\n$$\n\\frac{r}{d}\\sum_{i=1}^{d}\\underset{j\\sim U([d])^{m}}{\\mathbb{E}}\\underset{\\mathbf{b}\\sim U(\\{+1,-1\\}^{d})}{\\mathbb{E}}\\underset{\\forall k,y_{k}\\sim b_{j_{k}}}{\\mathbb{E}}\\mathbb{1}[A(S)(c_{i})\\neq b_{i}]\n$$\n\n$$\n\\geq\\frac{r}{2d}\\sum_{i=1}^{d}\\underset{\\mathbf{j}\\sim U([d])^{m}}{\\mathbb{E}}\\left(1-\\sqrt{1-\\exp\\big(-2n_{i}(\\mathbf{j})r^{2}\\big)}\\right)\n$$\n\n$$\n\\geq\\frac{r}{2d}\\sum_{i=1}^{d}\\underset{\\mathbf{j}\\sim U([d])^{m}}{\\mathbb{E}}\\left(1-\\sqrt{2n_{i}(\\mathbf{j})r^{2}}\\right),\n$$\n\nwhere the last inequality follows from the fact that $1 - e^{- a}\\leq a$\n\nSince the square root function is concave, we can apply Jensen's inequality to obtain that the above is lower bounded by\n\n$$\n\\begin{array}{l}{\\displaystyle\\frac{r}{2d}\\sum_{i=1}^{d}\\left(1-\\sqrt{2r^{2}\\underset{\\mathbf{j}\\sim U([d])^{m}}{\\mathbb{E}}n_{i}(\\mathbf{j})}\\right)}\\\\ {\\displaystyle\\quad=\\frac{r}{2d}\\sum_{i=1}^{d}\\left(1-\\sqrt{2r^{2}m/d}\\right)}\\\\ {\\displaystyle=\\frac{r}{2}\\left(1-\\sqrt{2r^{2}m/d}\\right).}\\end{array}\n$$\n\nAs long as $m<\\frac{{\\left(\\frac{1}{2}-\\frac{\\sqrt{2}}{16}\\rho^{1/2}\\right)}^{2}d}{2r^{2}}$ , this term will be larger than $\\begin{array}{r}{\\frac{r}{4}+\\frac{\\sqrt{2}r\\rho^{1/2}}{32}}\\end{array}$\n\nIn summary, we have shown that if $\\begin{array}{r}{m<{\\frac{\\left(\\frac{1}{2}-\\frac{\\sqrt{2}}{16}\\rho^{1/2}\\right)^{2}d}{2r^{2}}}}\\end{array}$ then for any algorithm, there exists a distribution $P_{\\mathbf{b}}$ such that\n\n$$\n\\underset{S\\sim P^{m}}{\\mathbb{E}}\\left[R_{2}(\\mathcal{A}(S);P_{\\mathbf{b}})-\\underset{h\\in\\mathcal{H}}{\\operatorname*{inf}}R_{2}(h;P_{\\mathbf{b}})\\right]\\geq\\frac{r}{4}+\\frac{\\sqrt{2}r\\rho^{1/2}}{32}.\n$$\n\nFinally, let $\\begin{array}{r}{\\Delta=\\frac{1}{r}\\Big(R_{2}(A(S);P_{\\mathbf{b}})-\\operatorname*{inf}_{h\\in\\mathcal{H}}R_{2}(h;P_{\\mathbf{b}})\\Big)}\\end{array}$ ; we proof that $\\Delta\\in [0,1+\\sqrt{2}\\rho^{1/2}/4]$ in Lemma 26. Therefore, using Lemma 27, we obtain that\n\n$$\n\\begin{array}{r l}&{\\mathbb{P}\\left[R_{2}(\\mathcal{A}(S);P_{\\mathbf{b}})-\\underset{h\\in\\mathcal{H}}{\\operatorname*{inf}}R_{2}(h;P_{\\mathbf{b}})\\geq\\epsilon\\right]=\\mathbb{P}\\left[\\Delta>\\frac{\\varepsilon}{r}\\right]\\geq\\left(1+\\sqrt{2}\\rho^{1/2}/4\\right)^{-1}\\left(\\mathbb{E}[\\Delta]-\\frac{\\varepsilon}{r}\\right)}\\\\ &{\\qquad\\geq\\left(1+\\sqrt{2}\\rho^{1/2}/4\\right)^{-1}\\left(\\frac{1}{4}+\\frac{\\sqrt{2}\\rho^{1/2}}{32}-\\frac{\\varepsilon}{r}\\right).}\\end{array}\n$$\n\nChoosing $r = 8 \\varepsilon$ , we conclude that if $m<\\frac{{\\left(\\frac{1}{2}-\\frac{\\sqrt{2}}{16}\\rho^{1/2}\\right)}^{2}d}{2r^{2}}$ , then with probability of at least $1 / 8 .$ ,we will have that $\\begin{array}{r}{R_{2}(A(S);P_{\\mathbf{b}})-\\operatorname*{inf}_{h\\in\\mathcal{H}}R_{2}(h;P_{\\mathbf{b}})\\geq\\epsilon}\\end{array}$\n\nProof Recall the definition of $R_{2}(h;P_{b})=\\operatorname*{sup}\\big\\{\\mathbb{E}_{P}\\big [\\mathbb{1}[h(x)\\neq y]\\big]:P\\ll P_{b},D_{2}(P\\|P_{b})\\le\\rho\\big\\}$\n\nWe write P as\n\n$$\nP(x,y)=\\left\\{{\\begin{array}{l l}{\\displaystyle{\\frac{1+\\xi}{2}},}&{\\text{if } x=c \\text{ and } y=b,}\\\\ {\\displaystyle{\\frac{1-\\xi}{2}},}&{\\text{if } x=c \\text{ and } y= -b,}\\\\ {\\displaystyle 0}&{,\\mathrm{otherwise}.}\\end{array}}\\right.\n$$\n\nThus, $R_{2}(h;P_{b})$ can be rewritten as\n\n$$\nR_{2}(h;P_{b})=\\operatorname*{sup}_{\\xi}\\left\\{\\frac{1+\\xi}{2}\\mathbb{1}[h(c)\\neq b]+\\frac{1-\\xi}{2}\\mathbb{1}[h(c)\\neq-b]:\\xi^{2}-2\\varepsilon\\xi+\\varepsilon^{2}-2\\rho(1-\\varepsilon^{2})\\leq 0,\\ -1\\leq\\xi\\leq 1\\right\\}.\n$$\n\nSolving the quadratic inequality in the above formulation, we get $\\varepsilon-\\sqrt{2\\rho(1-\\varepsilon^{2})}\\le\\xi\\le$ $\\varepsilon+\\sqrt{2\\rho(1-\\varepsilon^{2})}$ . Since we assume $\\textstyle\\rho\\in\\left(0,{\\frac{3-2{\\sqrt{2}}}{2}}\\right)$ and $\\rho\\in\\left(0,\\frac{1}{\\sqrt{2}}\\right)$ , the left-hand and right-hand sides can both be achieved.\n\nWhen $h(c)=b$ ,we have $\\begin{array}{r}{\\operatorname{er}(h;P)=\\frac{1-\\xi}{2}}\\end{array}$ , and thus $\\begin{array}{r}{R_{2}(h;P_{b})=\\frac{1-\\varepsilon+\\sqrt{2\\rho(1-\\varepsilon^{2})}}{2}}\\end{array}$ ; following the same logic, when $h(c)= -b$ ,we have $\\begin{array}{r}{R_{2}(h;P_{b})=\\frac{1+\\varepsilon+\\sqrt{2\\rho(1-\\varepsilon^{2})}}{2}}\\end{array}$\n\nThus, we obtain the desired result.\n\nProof Fix some $\\mathbf{j}\\in [ d ]^{m}$ . Note that, given j and $\\mathbf{y}\\in\\{+1,-1\\}^{m}$ , the training set S is fully determined; we can therefore write $\\mathcal{A}(\\mathbf{j},\\mathbf{y})$ instead of $\\mathcal{A}(S)$ . Let us also fix $i \\in [ d ]$ . Denote by $\\mathbf{b}^{\\lnot i}$ the sequence $( b_{1}, \\hdots , b_{i - 1}, b_{i + 1}, \\hdots , b_{m})$ . Also, for any $\\mathbf{b}\\in\\{+1,-1\\}^{m}$ , let $\\mathbf{y}^{I}$ denote the elements of y corresponding to indices for which $j_{k}=i,$ ,and let $\\mathbf{y}^{\\lnot I}$ be the rest of the elements of y. We therefore have\n\n$$\n\\begin{array}{r l}&\\underset{\\mathbf{b}\\sim U(\\{+1,-1\\}^{d})}{\\mathbb{E}}\\underset{\\forall k,y_{k}\\sim b_{j_{k}}}{\\mathbb{E}}\\mathbb{1}[\\mathcal{A}(S)(c_{i})\\neq b_{i}]\\\\ &=\\frac{1}{2}\\sum_{b_{i}\\in\\{+1,-1\\}}\\underset{\\mathbf{b}^{\\neg i}\\sim U(\\{+1,-1\\}^{d-1})}{\\mathbb{E}}\\sum_{\\mathbf{y}}P[\\mathbf{y}|\\mathbf{b}^{\\neg i},b_{i}]\\mathbb{1}[\\mathcal{A}(\\mathbf{j},\\mathbf{y})(c_{i})\\neq b_{i}]\\\\ &=\\underset{\\mathbf{b}^{\\neg i}\\sim U(\\{+1,-1\\}^{d-1})}{\\mathbb{E}}\\sum_{\\mathbf{y}^{\\neg I}}P[\\mathbf{y}^{\\neg I}|\\mathbf{b}^{\\neg i}]\\frac{1}{2}\\sum_{\\mathbf{y}^{I}}\\left(\\sum_{b_{i}\\in\\{+1,-1\\}}P[\\mathbf{y}^{I}|\\mathbf{b}_{i}]\\mathbb{1}[\\mathcal{A}(\\mathbf{j},\\mathbf{y})(c_{i})\\neq b_{i}]\\right).\\end{array}\n$$\n\nThe sum within the parentheses is minimized when $\\mathcal{A}(\\mathbf{j},\\mathbf{y})(c_{i})$ is the maximizer of $P [ \\mathbf{y}^{I}| b_{i}]$ over $b_{i}\\in\\{+1,-1\\}$ , which is exactly the Maximum-Likelihood rule. Repeating the same argument for all i we conclude our proof.\n\nProof Recalling (9), we have\n\n$$\n\\begin{array}{r l}&{R_{2}(\\mathcal{A}(S);P_{\\mathbf{b}})-\\underset{h\\in\\mathcal{H}}{\\operatorname*{inf}}R_{2}(h;P_{\\mathbf{b}})=R_{2}(\\mathcal{A}(S);P_{\\mathbf{b}})-R_{2}(h_{\\mathbf{b}};P_{\\mathbf{b}})}\\\\ &{\\qquad=r\\cdot\\frac{d_{-}}{d}+\\frac{1}{2}\\left(\\sqrt{2\\rho(1-r^{2}(d_{+}-d_{-})^{2}/d^{2})}-\\sqrt{2\\rho(1-r^{2})}\\right).}\\end{array}\\tag{29}\n$$\n\nNext, we upper bound the second term in (29),\n\n$$\n\\begin{array}{r l}&{\\frac{1}{2}\\left(\\sqrt{2\\rho\\left(1-r^{2}(d_{+}-d_{-})^{2}/d^{2}\\right)}-\\sqrt{2\\rho(1-r^{2})}\\right)}\\\\ &{\\quad\\leq\\frac{1}{2}\\rho\\left(2\\rho(1-r^{2})\\right)^{-1/2}r^{2}\\left(1-\\frac{(d_{+}-d_{-})^{2}}{d^{2}}\\right)}\\\\ &{\\quad\\leq\\frac{1}{2}\\rho^{1/2}r^{2},}\\end{array}\n$$\n\nwhere the first inequality follows from $\\begin{array}{r}{\\sqrt{x}\\leq\\frac{1}{2}(\\sqrt{x}+\\sqrt{y}),\\forall x\\leq y}\\end{array}$ ,while the second follows from the fact that $r^{2}\\le 1 / 2$ Thus, $\\Delta \\le \\rho^{1 / 2}r / 2 \\le \\sqrt{2}\\rho^{1 / 2}/ 4$\n\nProof\n\n$$\n\\begin{array}{r l}&{\\mathbb{E}[Z]=\\mathbb{E}\\left[Z\\cdot\\mathbb{1}[0\\leq Z\\leq a]\\right]+\\mathbb{E}\\left[Z\\cdot\\mathbb{1}[aa]\\right)+c\\mathbb{P}[Z>a].}\\end{array}\n$$\n\nFollowing rearrangement, we obtain the desired result.\n\n### Proof of Theorem 12\n\nOur proof is organized as follows: we first show that, for a hypothesis class $\\mathcal{H}$ with finite VC dimension, given sufficient samples (the magnitude is provided in Theorem 12), the samples form a Distributionally Robust ε-net for $\\mathcal{H}$; subsequently, we prove that such samples is sufficient for distributionally robust learning.\n\nProposition 18 Let $\\mathcal{H}\\subseteq \\mathcal{Y}^{\\mathcal{X}}$ with $v c ({\\mathcal{H}}) = d .$ Fix $\\varepsilon\\in(0,1),\\delta\\in(0,1/4)$ and let\n\n$$\nm\\geq\\frac{16(1+2\\rho)d}{\\varepsilon^{2}}\\log\\left(\\frac{8(1+2\\rho)d}{\\varepsilon^{2}}\\right)+\\frac{8(1+2\\rho)}{\\varepsilon^{2}}\\left(d\\log\\left(\\frac{2e}{d}\\right)+\\log\\left(\\frac{2}{\\delta}\\right)\\right).\\tag{22}\n$$\n\nThen, with probability of at least $1 - \\delta$ over a choice of $S \\sim P^{m}$ , we can conclude that $S$ is a Distributionally Robust ε-net for $\\mathcal{H}$.\n\nProof Let $B: =\\{S\\subseteq\\mathcal{X}: |S| =m,\\exists h\\in\\mathcal{H},R_{2}(h;P)\\geq\\varepsilon,\\mathcal{C}_{h}\\cap S=\\emptyset\\}$ be the set of sets that are not a Distributionally Robust ε-net. We need to bound $\\mathbb{P}[ S \\in B ]$\n\nDefine\n\n$$\nB^{\\prime}: =\\left\\{\\left(S,T\\right)\\subseteq\\mathcal{X}:\\left|S\\right| =\\left|T\\right| =m,\\exists h\\in\\mathcal{H},R_{2}(h;P)\\geq\\varepsilon,\\mathcal{C}_{h}\\cap S=\\varnothing,\\left|T\\cap\\mathcal{C}_{h}\\right| >\\frac{m\\varepsilon^{2}}{2(1+2\\rho)}\\right\\}.\n$$\n\nClaim 1. $\\mathbb{P}[S\\in B]\\le 2\\cdot\\mathbb{P}[(S,T)\\in B^{\\prime}]$\n\nSince S and T are chosen independently, we can write\n\n$$\n\\begin{array}{r l}&{\\mathbb{P}[(S,T)\\in B^{\\prime}]=\\underset{(S,T)\\sim P^{2m}}{\\mathbb{E}}\\mathbb{1}[(S,T)\\in B^{\\prime}]}\\\\ &{\\qquad=\\underset{S\\sim P^{m}}{\\mathbb{E}}\\underset{T\\sim P^{m}}{\\mathbb{E}}\\mathbb{1}[(S,T)\\in B^{\\prime}].}\\end{array}\n$$\n\nNote that $(S,T)\\in B^{\\prime}$ implies $S \\in B$ , and therefore $\\mathbb{1}[(S,T)\\in B^{\\prime}]=\\mathbb{1}[(S,T)\\in B^{\\prime}]\\cdot\\mathbb{1}[S\\in$ $B ]$ , which yields\n\n$$\n\\begin{array}{r l}&{\\mathbb{P}[(S,T)\\in B^{\\prime}]=\\underset{(S,T)\\sim P^{2m}}{\\mathbb{E}}\\mathbb{1}[(S,T)\\in B^{\\prime}]\\cdot\\mathbb{1}[S\\in B]}\\\\ &{\\qquad\\underset{S\\sim P^{m}}{\\mathbb{E}}\\mathbb{1}[S\\in B]\\underset{T\\sim P^{m}}{\\mathbb{E}}\\mathbb{1}[(S,T)\\in B^{\\prime}].}\\end{array}\\tag{23}\n$$\n\nFix some S. Then, either $\\mathbb{1}[S\\in B]=0,{\\mathrm{or~}}S\\in B$ and then $\\exists h_{S}$ such that $R_{2}(h_{S};P)\\ge\\varepsilon$ and $|{\\mathcal{C}}_{h_{S}}\\cap S | = 0$ . It follows that a sufficient condition for $(S,T)\\in B^{\\prime}$ is that $| T \\cap \\mathcal{C}_{h_{S}}| >$ $\\frac{m\\varepsilon^{2}}{2(1{+}2\\rho)}$ . Therefore, whenever $S \\in B$ ,we have\n\n$$\n\\underset{T\\sim P^{m}}{\\mathbb{E}}\\mathbb{1}\\left[\\left(S,T\\right)\\in B^{\\prime}\\right]\\geq\\underset{T\\sim P^{m}}{\\mathbb{P}}\\left[\\left|T\\cap\\mathcal{C}_{h_{S}}\\right| >\\frac{m\\varepsilon^{2}}{2(1+2\\rho)}\\right].\\tag{24}\n$$\n\nHowever, since we now assume $S \\in B$ , we know that $R_{2}(h_{S};P)\\ge\\varepsilon;$ accordingly, by Lemma 28, we have $\\mathrm{er}(h_{S};P)=p\\ge\\frac{\\varepsilon^{2}}{1+2\\rho}$.\n\nTherefore, $| T \\cap{\\mathcal{C}}_{h_{S}}|$ is a binomial random variable with parameters p (probability of success for a single try) and m (number of tries). Chernoff's inequality implies\n\n$$\n\\begin{array}{r l}{{\\mathbb{P}[|T\\cap\\mathcal{C}_{h_{S}}|\\le\\frac{pm}{2}]=\\mathbb{P}[|T\\cap\\mathcal{C}_{h_{S}}| -pm\\le-pm/2]}}\\\\ &{\\le\\exp(-mp/2)\\le\\exp(-\\frac{m\\varepsilon^{2}}{2(1+2\\rho)})}\\\\ &{\\le\\exp(-d\\log(1/\\delta)/2)=\\delta^{d/2}\\le 1/2,}\\end{array}\n$$\n\nwhere the first inequality is obtained via Chernoff's inequality and the penultimate inequality follows from our choice of $m$\n\nThus,\n\n$$\n\\begin{array}{r}{\\mathbb{P}\\left[|T\\cap\\mathcal{C}_{h_{S}}| >\\frac{m\\varepsilon^{2}}{2\\left(1+2\\rho\\right)}\\right]=1-\\mathbb{P}\\left[|T\\cap\\mathcal{C}_{h_{S}}|\\leq\\frac{m\\varepsilon^{2}}{2\\left(1+2\\rho\\right)}\\right]}\\\\ {\\geq 1-\\mathbb{P}\\left[|T\\cap\\mathcal{C}_{h_{S}}|\\leq\\frac{mp}{2}\\right]\\geq 1/2.}\\end{array}\\tag{25}\n$$\n\nCombining (23), (24) and (25), we conclude our proof of Claim 1.\n\nClaim 2.(Symmetrization) $\\begin{array}{r}{\\mathbb{P}\\left[(S,T)\\in B^{\\prime}\\right]\\leq\\exp\\left(-\\frac{m\\varepsilon^{2}}{4(1+2\\rho)}\\right)\\cdot\\tau_{\\mathcal{H}}(2m)}\\end{array}$\n\nFor ease of notation, let $\\begin{array}{r}{\\alpha=\\frac{m\\varepsilon^{2}}{2(1+2\\rho)}}\\end{array}$ , and for a sequence $A=(x_{1},\\dots,x_{2m})$ , let $A_{0}=$ $(x_{1},\\ldots,x_{m})$ . Using the definition of $B^{\\prime}$ we get\n\n$$\n\\begin{array}{r l}\\mathbb{P}\\left[A\\in B^{\\prime}\\right]&=\\underset{A\\sim P^{2m}}{\\mathbb{E}}\\max_{h\\in\\mathcal{H}}\\left\\{\\mathbb{1}\\left[R_{2}(h;P)\\geq\\varepsilon\\right]\\cdot\\mathbb{1}\\left[\\left|\\mathcal{C}_{h}\\cap A_{0}\\right| =0\\right]\\cdot\\mathbb{1}\\left[\\left|\\mathcal{C}_{h}\\cap A\\right|\\geq\\alpha\\right]\\right\\}\\\\ &\\leq\\underset{A\\sim P^{2m}}{\\mathbb{E}}\\max_{h\\in\\mathcal{H}}\\left\\{\\mathbb{1}\\left[\\left|\\mathcal{C}_{h}\\cap A_{0}\\right| =0\\right]\\cdot\\mathbb{1}\\left[\\left|\\mathcal{C}_{h}\\cap A\\right|\\geq\\alpha\\right]\\right\\}.\\end{array}\n$$\n\nNow let us denote by $\\mathcal{H}_{A}$ the effective number of different hypotheses on $A,$ namely, $\\mathcal{H}_{A}: = \\{\\mathcal{C}_{h}\\cap A : h \\in \\mathcal{H}\\}$ . It follows that\n\n$$\n\\mathbb{P}[ A \\in B^{\\prime}] \\le \\underset{A \\sim P^{2 m}}{\\mathbb{E}}\\max_{\\mathcal{C}_{h}\\in \\mathcal{H}_{A}}\\left\\{{\\mathbb{1}}\\left[ |{\\mathcal{C}}_{h}\\cap A_{0}| = 0 \\right] \\cdot{\\mathbb{1}}\\left[ |{\\mathcal{C}}_{h}\\cap A | \\ge \\alpha \\right] \\right\\}.\n$$\n\nLet $J = \\{\\mathbf{j}\\subseteq [ 2 m ] : | \\mathbf{j}| = m \\}$ . For any $\\textbf{j}\\in \\ J$ and $A=(x_{1},\\dots,x_{2m}) $ , define $A_{\\mathbf{j}}=$ $( x_{\\mathbf{j}_{1}}, \\hdots , x_{\\mathbf{j}_{m}})$ Since the elements of A are chosen i.i.d., for any $\\mathbf{j}\\in J$ and any function $f(A,A_{0})$ , it holds that $\\underset{A\\sim P^{2m}}{\\mathbb{E}}[f(A,A_{0})]=\\underset{A\\sim P^{2m}}{\\mathbb{E}}[f(A,A_{\\mathbf{j}})]$ . Since this holds for any j, it also holds for the expectation of j chosen at random from J. In particular, it holds for the function $\\begin{array}{r}{f(A,A_{0})=\\sum_{\\mathcal{C}_{h}\\in\\mathcal{H}_{A}}\\mathbb{1}\\big [\\vert\\mathcal{C}_{h}\\cap A_{0}\\vert=0\\big]\\cdot\\mathbb{1}\\big [\\vert\\mathcal{C}_{h}\\cap A\\vert\\ge\\alpha\\big]}\\end{array}$ . We therefore obtain that\n\n$$\n\\begin{array}{r l}\\mathbb{P}[A\\in B^{\\prime}]&\\leq\\underset{A\\sim P^{2m}}{\\mathbb{E}}\\underset{\\mathbf{j}\\sim U(J)}{\\mathbb{E}}\\sum_{\\mathcal{C}_{h}\\in\\mathcal{H}_{A}}\\mathbb{1}[|\\mathcal{C}_{h}\\cap A_{\\mathbf{j}}| =0]\\cdot\\mathbb{1}[|\\mathcal{C}_{h}\\cap A|\\geq\\alpha]\\\\ &=\\underset{A\\sim P^{2m}}{\\mathbb{E}}\\sum_{\\mathcal{C}_{h}\\in\\mathcal{H}_{A}}\\mathbb{1}[|\\mathcal{C}_{h}\\cap A|\\geq\\alpha]\\underset{\\mathbf{j}\\sim U(J)}{\\mathbb{E}}\\mathbb{1}[|\\mathcal{C}_{h}\\cap A_{\\mathbf{j}}| =0].\\end{array}\n$$\n\nNow fix some $A,$ such that $|{\\mathcal{C}}_{h}\\cap A | \\geq \\alpha$ Thus, $\\operatorname{\\mathbb{E}}_{j\\sim U(J)}\\mathbb{1}[|\\mathcal{C}_{h}\\cap A_{\\mathbf{j}}| =0]$ represents the probability that when choosing m balls from a bag containing at least α red balls, we will never choose a red ball. This probability is at most\n\n$$\n\\left(1-\\frac{\\alpha}{2m}\\right)^{2}=\\left(1-\\frac{\\varepsilon^{2}}{4(1+2\\rho)}\\right)^{m}\\leq\\exp\\left(-\\frac{m\\varepsilon^{2}}{4(1+2\\rho)}\\right).\n$$\n\nWe therefore have\n\n$$\n\\begin{array}{r l r}{{\\mathbb{P}[A\\in B^{\\prime}]\\le\\underset{A\\sim P^{2m}}{\\mathbb{E}}\\sum_{\\mathcal{C}_{h}\\in\\mathcal{H}_{A}}\\exp(-\\frac{m\\varepsilon^{2}}{4(1+2\\rho)})}}\\\\ &{}&{\\le\\exp(-\\frac{m\\varepsilon^{2}}{4(1+2\\rho)})\\underset{A\\sim P^{2m}}{\\mathbb{E}}|\\mathcal{H}_{A}|}\\\\ &{}&{\\le\\exp(-\\frac{m\\varepsilon^{2}}{4(1+2\\rho)})\\cdot\\tau_{\\mathcal{H}}(2m).}\\end{array}\n$$\n\nBy Sauer's lemma, we know that $\\tau_{\\mathcal{H}}\\leq(2em/d)^{d};$ combining this with the above two claims, we obtain that\n\n$$\n\\mathbb{P}[S\\in B]\\leq 2(2em/d)^{d}\\exp\\left(-\\frac{m\\varepsilon^{2}}{4(1+2\\rho)}\\right).\n$$\n\nWe would like the right-hand side of the inequality to be at most $\\delta ;$ that is,\n\n$$\n2(2em/d)^{d}\\exp\\left(-\\frac{m\\varepsilon^{2}}{4(1+2\\rho)}\\right)\\leq\\delta .\n$$\n\nThrough rearrangement, we arrive at\n\n$$\nm\\geq\\frac{4(1+2\\rho)d}{\\varepsilon^{2}}\\log(m)+\\frac{4(1+2\\rho)d}{\\varepsilon^{2}}\\log\\left(\\frac{2e}{d}\\right)+\\frac{4(1+2\\rho)}{\\varepsilon^{2}}\\log\\left(\\frac{2}{\\delta}\\right).\n$$\n\nUsing Lemma 22, a sufficient condition for the preceding to hold is that\n\n$$\nm\\geq\\frac{16(1+2\\rho)d}{\\varepsilon^{2}}\\log\\left(\\frac{8(1+2\\rho)d}{\\varepsilon^{2}}\\right)+\\frac{8(1+2\\rho)}{\\varepsilon^{2}}\\left(d\\log\\left(\\frac{2e}{d}\\right)+\\log\\left(\\frac{2}{\\delta}\\right)\\right).\n$$\n\nNext, we derive distributionally robust PAC learnability from the definition of distributionally robust ε-net.\n\nProposition 19 Let $\\mathcal{H}$ be a hypothesis class over $\\mathcal{X}$ with $vc(\\mathcal{H})$ . Let P be a distribution over $\\mathcal{X}$ and let $h^{*}$ be a target hypothesis. Fix $\\varepsilon,\\delta\\in(0,1)$ and let m be as defined in Proposition 18; then, with probability of at least $1 - \\delta$ over a choice of m i.i.d. instances from $\\mathcal{X}$ with labels according to $h^{*},$ , we have that any DRERM hypothesis has a true error of at most ε.\n\nProof Define the class $\\mathcal{H}^{h^{*}}= \\{\\mathcal{C}_{h^{*}}\\triangle \\mathcal{C}_{h}: h \\in \\mathcal{H}\\}$ , where $\\mathcal{C}_{h^{*}}\\triangle\\mathcal{C}_{h}=(\\mathcal{C}_{h}\\backslash\\mathcal{C}_{h^{*}})\\cup(\\mathcal{C}_{h^{*}}\\backslash\\mathcal{C}_{h})$ It can be readily verified that if some $A \\subseteq{\\mathcal{X}}$ is shattered by $\\mathcal{H}$ then it is also shattered by $\\mathcal{H}^{h^{*}}$ , and vice versa. Hence, $\\mathrm{vc}(\\mathcal{H})=\\mathrm{vc}\\left(\\mathcal{H}^{h^{*}}\\right)$ . Therefore, using Proposition 18, we can determine that with probability of at least $1 - \\delta$ , the sample S is a distributionally robust ε-net for $\\mathcal{H}^{h^{*}}$ , note that\n\n$$\nR_{2}(h;P)=\\operatorname*{sup}\\left\\{\\mathbb{E}_{Q}[\\mathbb{1}[h(x)\\neq y]]:Q\\ll P,D_{2}(Q\\|P)\\right\\}.\n$$\n\nSince $h^{*}$ is the target hypothesis, we have that\n\n$$\n\\mathbb{E}_{P}[\\mathbb{1}[h^{*}(x)\\neq y]]=0.\n$$\n\nThus, $R_{2}(h^{*};P)=\\operatorname*{inf}_{\\eta\\in\\mathbb{R}}\\left\\{c_{2}\\mathbb{E}_{P}[\\left(\\mathbb{1}[h^{(}(x)\\neq y]-\\eta\\right)_{+}^{2}]^{1/2}+\\eta\\right\\}\\leq c_{2}\\mathbb{E}_{P}[(\\mathbb{1}[h^{*}(x)\\neq y])_{+}^{2}]^{1/2}=0$, which means that for any $Q \\ll P$ with $D_{2}(Q\\|P)\\leq\\rho .$ we have $Q[y=h^{\\ast}(x)]=1$\n\nTherefore,\n\n$$\n\\begin{array}{r l}&{R_{2}(h;P)=\\operatorname*{sup}\\left\\{\\mathbb{E}_{Q}[\\mathbb{1}[h(x)\\neq y]:Q\\ll P,D_{2}(Q\\|P)\\leq\\rho\\right\\}}\\\\ &{\\quad\\quad\\quad=\\operatorname*{sup}\\left\\{\\mathbb{E}_{Q}[\\mathbb{1}[h(x)\\neq h^{*}(x)]:Q\\ll P,D_{2}(Q\\|P)\\leq\\rho\\right\\}}\\\\ &{\\quad\\quad\\quad=R_{2}(h\\triangle h^{*};P),}\\end{array}\n$$\n\nwhere $h \\triangle{h^{*}}$ is the hypothesis that satisfies $\\mathcal C_{h \\triangle h^{*}}= \\mathcal C_{h^{*}}\\triangle \\mathcal C_{h}$ . Therefore, for any $h \\in \\mathcal H$ with $R_{2}(h;P)\\ge\\varepsilon$ , we have that $|{\\mathcal{C}}_{h^{*}\\triangle h}\\cap S | > 0 ;$ this which implies that h cannot be a DRERM hypothesis, which concludes our proof.\n\nProof Recalling the dual formulation of $R_{2}(h;P)$ (Proposition 4), we have\n\n$$\n\\begin{array}{l}{{R_{2}(h;P)=\\operatorname*{inf}_{\\eta\\in\\mathbb{R}}\\{c_{2}(\\rho)\\mathbb{E}_{P}[(\\mathbb{1}[h(x)\\neq y]-\\eta)_{+}^{2}]^{1/2}+\\eta\\}}}\\\\ {\\quad\\le c_{2}(\\rho)\\mathbb{E}_{P}[(\\mathbb{1}[h(x)\\neq y])_{+}^{2}]^{1/2}}\\\\ {\\quad=c_{2}(\\rho)\\mathrm{er}(h;P)^{1/2},}\\end{array}\n$$\n\nwhere the first inequality follows by setting $\\eta = 0$ and the last line follows from the fact that the indicator $\\mathbb{1}\\left[h(x)\\neq y\\right]$ is a 0-1-valued function.", "context": [{"id": "v24-22-0881:ctx1", "name": "Setup: robust risk Eq. (1) and DRERM (Section 1)", "statement": "Concretely, let $\\mathcal{X}$ be the instance space, while $\\mathcal{Y}=\\{+1,-1\\}$ denotes the label space. We formalize the distributional shift that we would like to protect against as an uncertainty set $\\mathcal{U}(P)$ containing distributions with certain constraints, such as moment condition (Delage and Ye, 2010), Wasserstein distance (Gao, 2020) and f-divergence (Duchi and Namkoong, 2021). For a distribution P over $\\mathcal{X}\\times\\mathcal{Y}=\\{(x,y):x\\in\\mathcal{X},y\\in\\mathcal{Y}\\}$ , we observe m i.i.d. samples $S \\sim P^{m}$ , and distributionally robust learning attempts to learn a predictor $h : \\mathcal{X}\\to \\mathcal{Y}$ having small distributionally robust risk,\n\n$$\nR_{\\mathcal{U}}(h;P): =\\operatorname*{sup}_{Q\\in\\mathcal{U}(P)}\\mathbb{E}_{(x,y)\\sim Q}[\\mathbb{1}[h(x)\\neq y]].\\tag{1}\n$$\n\nThe common approach to distributionally robust learning involves selecting a hypothesis class $\\mathcal{H}\\subseteq \\mathcal{Y}^{\\mathcal{X}}$ and learning a predictor $\\hat{h}: \\mathcal{X}\\to \\mathcal{Y}$ from $\\mathcal{H}$ through Distributionally Robust Empirical Risk Minimization:\n\n$$\n\\begin{array}{r}{\\hat{h}\\in\\mathrm{DRERM}_{\\mathcal{H}}(S): =\\underset{h\\in\\mathcal{H}}{\\mathrm{argmin}}\\hat{R}_{\\mathcal{U}}(h;S),}\\end{array}\n$$\n\nwhere $\\begin{array}{r}{\\hat{R}_{\\mathcal{U}}(h;S): =\\operatorname*{sup}_{Q\\in\\mathcal{U}(P_{m})}\\mathbb{E}_{(x,y)\\sim Q}[\\mathbb{1}\\left[h(x)\\neq y\\right]]}\\end{array}$ and $P_{m}$ denotes the empirical distribution over samples S."}, {"id": "v24-22-0881:ctx2", "name": "Uncertainty set and chi^2-divergence D_2 (Section 1)", "statement": "Namely, we consider the distributional shift as follows:\n\n$$\n\\mathcal{U}(P)=\\{Q\\ll P:D_{2}(Q\\|P)\\leq\\rho\\},\n$$\n\nwhere $\\begin{array}{r}{D_{2}(Q\\|P): =\\frac{1}{2}\\int\\left(\\frac{dQ}{dP}-1\\right)^{2}dP}\\end{array}$ and $Q \\ll P$ indicates that distribution Q is absolutely continuous with respect to $P .$ The $\\chi^{2}$-divergence is a commonly explored concept in the distributionally robust optimization (DRO) literature (Duchi and Namkoong, 2019). Moreover, it is also a crucial concept in a variety of fields such as information theory, statistics, learning, signal processing, and various branches of mathematics (Park et al., 2011; Saraswat, 2014; Nishiyama and Sason, 2020). The $\\chi^{2}$-divergence plays a fundamental role in problems related to source and channel coding, combinatorics, large deviation theory, goodness-of-fit, and independence tests in statistics, as demonstrated by Csiszár et al. (2004). Additionally, it is widely recognized for its computational feasibility and statistical properties, as noted in Tsybakov (2009)."}, {"id": "v24-22-0881:ctx3", "name": "Problem setup (Section 2)", "statement": "Given a hypothesis class $\\mathcal{H}\\subseteq \\mathcal{Y}^{\\mathcal{X}}$ , our goal is to design a learning rule $\\mathcal{A}:(\\mathcal{X}\\times\\mathcal{Y})^{*}\\mapsto\\mathcal{Y}^{\\mathcal{X}}$ such that for any distribution P over $\\mathcal{X}\\times \\mathcal{Y}$ , the rule $\\mathcal{A}$ will find a predictor that can compete with the best predictor $h^{\\ast}\\in \\mathcal{H}$ in terms of the distributionally robust risk using a number of samples that is independent of the distribution P. In this paper, we use $(\\mathcal{X}\\times\\mathcal{Y})^{*}$ to denote the set of all sequences in the space $\\mathcal{X}\\times \\mathcal{Y}$ . The following definitions formalize the notion of distributionally robust PAC learning under the realizable case and agnostic settings."}, {"id": "v24-22-0881:ctx4", "name": "Definition 1 (Agnostic Distributionally Robust PAC Learnability)", "statement": "Definition 1 (Agnostic Distributionally Robust PAC Learnability) For any $\\varepsilon,\\delta\\in$ (0, 1), the sample complexity of agnostic distributionally robust $(\\varepsilon,\\delta)$-PAC learning of $\\mathcal{H}$ with respect to the distributional shift $\\mathcal{U}$, denoted by $\\mathcal{M}_{AG}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})$ , is defined as the smallest $m \\in \\mathbb{N}\\cup \\{0 \\}$ for which there exists a learning rule $\\mathcal{A}:(\\mathcal{X}\\times\\mathcal{Y})^{*}\\mapsto\\mathcal{Y}^{\\mathcal{X}}$ such that, for every data distribution P over $\\mathcal{X}\\times \\mathcal{Y}$ , with probability of at least $1 - \\delta$ over $S \\sim P^{m}$ ,\n\n$$\nR_{\\mathcal{U}}(\\mathcal{A}(S);P)\\leq\\operatorname*{inf}_{h\\in\\mathcal{H}}R_{\\mathcal{U}}(h;P)+\\varepsilon .\n$$\n\nIf no such m exists, define $\\mathcal{M}_{AG}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})=\\infty$ . We say that $\\mathcal{H}$ is distributionally robustly PAC-learnable in the agnostic setting with respect to the distributional shift $\\mathcal{U}$ if $\\forall\\varepsilon,\\delta\\in(0,1)$ , $\\mathcal{M}_{AG}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})$ scales polynomially with $1 / \\varepsilon$ and $1 / \\delta$"}, {"id": "v24-22-0881:ctx5", "name": "Definition 2 (Realizable Distributionally Robust PAC Learnability)", "statement": "Definition 2 (Realizable Distributionally Robust PAC Learnability) For any $\\varepsilon,\\delta\\in(0,1)$, the sample complexity of realizable distributionally robust $(\\varepsilon,\\delta)$-PAC learning of $\\mathcal{H}$ with respect to the distributional shift $\\mathcal{U}$, denoted by $\\mathcal{M}_{RE}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})$ , is defined as the smallest $m \\in \\mathbb{N}\\cup \\{0 \\}$ for which there exists a learning rule $\\mathcal{A}:(\\mathcal{X}\\times\\mathcal{Y})^{*}\\mapsto\\mathcal{Y}^{\\mathcal{X}}$ such that, for every data distribution P over $\\mathcal{X}\\times \\mathcal{Y}$ where there exists a predictor $h^{\\ast}\\in \\mathcal{H}$ with zero distributionally robust risk, $R_{{\\mathcal U}}(h^{*};P)=0$ , with probability of at least $1 - \\delta$ over $S \\sim P^{m}$ ,\n\n$$\nR_{\\mathcal{U}}(\\mathcal{A}(S);P)\\leq\\varepsilon .\n$$\n\nIf no such m exists, define $\\mathcal{M}_{RE}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})=\\infty$ . We say that $\\mathcal{H}$ is distributionally robustly PAC-learnable in the realizable setting with respect to the distributional shift $\\mathcal{U}$ if $\\forall\\varepsilon,\\delta\\in(0,1)$ , $\\mathcal{M}_{RE}(\\varepsilon,\\delta;\\mathcal{H},\\mathcal{U})$ scales polynomially with $1 / \\varepsilon$ and $1 / \\delta$"}, {"id": "v24-22-0881:ctx6", "name": "Notation: error rate er(h;P) and empirical error", "statement": "We also denote $\\mathrm{er}(h;P)=P(h(x)\\neq y)$ , the (non-robust) error rate under 0-1 loss, and $\\begin{array}{r}{\\hat{\\mathrm{er}}(h;S)=\\frac{1}{|S|}\\sum_{(x,y)\\in S}\\mathbb{1}[h(x)\\neq y]}\\end{array}$ , the empirical error rate; here, |S| denotes the cardinality of set S, while $\\mathbb{1}[\\cdot]$ is the indicator function that takes 1 when the statement in the square brackets is true and 0 otherwise. The definition of Vapnik-Chervonenkis dimension (VC dimension) is provided below."}, {"id": "v24-22-0881:ctx7", "name": "Definition 3 (VC dimension)", "statement": "Definition 3 (VC dimension) We say that a sequence $\\{x_{1},\\ldots,x_{k}\\}\\subseteq{\\mathcal{X}}$ is shattered by $\\mathcal{H}$ if $\\forall y_{1},\\ldots,y_{k}\\in\\mathcal{Y},\\exists h\\in\\mathcal{H}$ such that $\\forall i\\in [k],h(x_{i})=y_{i}$ . The VC dimension of $\\mathcal{H}$ (denoted as $vc(\\mathcal{H}))$ is then defined as the largest integer k for which there exists $\\{x_{1},\\ldots,x_{k}\\}\\subseteq{\\mathcal{X}}$ that is shattered by $\\mathcal{H}$. If no such k exists, then $vc(\\mathcal{H})$ is said to be infinite."}, {"id": "v24-22-0881:ctx8", "name": "Loss class L_H", "statement": "Denote the loss class of $\\mathcal{H}$ by $\\mathcal{L}_{\\mathcal{H}}$ , where\n\n$$\n\\mathcal{L}_{\\mathcal{H}}=\\Big\\{(x,y)\\mapsto\\mathbb{1}[h(x)\\neq y]:h\\in\\mathcal{H}\\Big\\}.\n$$"}, {"id": "v24-22-0881:ctx9", "name": "Notation R_2(h;P) (Section 3)", "statement": "We use $R_{2}(h;P)$ to denote the distributionally robust risk under distributional shift\n\n$$\n\\begin{array}{r}{\\mathcal{U}(P)=\\left\\{Q\\ll P:D_{2}(Q\\|P)\\leq\\rho\\right\\}.}\\end{array}\n$$"}, {"id": "v24-22-0881:ctx10", "name": "Proposition 4 (Duality Formulation), Eq. (2) (Shapiro 2017)", "statement": "We recall the following duality formulation (Shapiro, 2017, Section 3.2) for distributionally robust risk, which is essential in our derivation.\n\nProposition 4 (Duality Formulation) For any probability P on $\\mathcal{X}\\times \\mathcal{Y}$ , any $\\rho > 0$ , and $c_{2}(\\rho): =\\sqrt{1+2\\rho},$ for all $h \\in \\mathcal H$ , we have\n\n$$\nR_{2}(h;P)=\\operatorname*{inf}_{\\eta\\in\\mathbb{R}}\\Big\\{c_{2}(\\rho)\\mathbb{E}_{P}\\Big [(\\mathbb{1}[h(x)\\neq y]-\\eta)_{+}^{2}\\Big]^{1/2}+\\eta\\Big\\},\\tag{2}\n$$\n\nwhere $a_{+}: =\\operatorname*{max}\\left(a,0\\right)$"}, {"id": "v24-22-0881:ctx11", "name": "g_2 and Lemma 5 (compact range for eta), Remark 6", "statement": "To bring the above proposition into effect, we need the following lemma. In the interests of simplicity, for any fixed $h \\in \\mathcal H$ , let\n\n$$\n\\begin{array}{r}{g_{2}(\\eta,P): =c_{2}(\\rho)\\mathbb{E}_{P}\\left[(\\mathbb{1}\\left[h(x)\\neq y\\right]-\\eta)_{+}^{2}\\right]^{1/2}+\\eta .}\\end{array}\n$$\n\nLemma 5 For any distribution $P$ ,\n\n$$\n\\operatorname*{inf}_{\\eta\\in\\mathbb{R}}g_{2}(\\eta,P)=\\operatorname*{inf}_{\\eta}\\left\\{g_{2}(\\eta,P):\\eta\\in\\left[-\\frac{1}{c_{2}(\\rho)-1},1\\right]\\right\\}.\n$$\n\nRemark 6 The above lemma restricts the domain of η to a compact set, which is crucial to our uniform convergence result."}, {"id": "v24-22-0881:ctx12", "name": "Remark 8 (dependence on 1/(c_2(rho)-1))", "statement": "Remark 8 The dependence on $\\frac{1}{c_{2}(\\rho)-1}$ is due to the lower bound for η in Lemma 5. While more advanced techniques could potentially yield a better dependence on $\\rho,$ it is worth noting that the upper bound shows that the finite VC dimension is sufficient for distributionally robust PAC learnability for finite non-zero values of ρ."}, {"id": "v24-22-0881:ctx13", "name": "Remark 10 (range of rho in Theorem 9)", "statement": "Remark 10 We derive the result under the assumption that the perturbation size $\\rho \\in$ $\\textstyle\\left(0,{\\frac{3-2{\\sqrt{2}}}{2}}\\right)$ . Intuitively, if the perturbation size is prohibitively large, the learning problem can become \"easier\", since the benchmark in $\\inf_{h\\in\\mathcal{H}}R_{2}(h;P)$ may increase too much. When $\\rho$ approaches 0, the lower bound recovers that of the classical statistical learning (Mohri et al., 2012; Shalev-Shwartz and Ben-David, 2014)."}, {"id": "v24-22-0881:ctx14", "name": "Realizable case setup: C_h and R_2 in primal form (Section 4)", "statement": "To study the upper bound of the sample complexity under the realizable case, it is necessary to introduce the definition of Distributionally Robust ε-net, which is similar to the definition in (Shalev-Shwartz and Ben-David, 2014, Definition 28.2). In the realizable case, we have a target hypothesis $h^{*}$ that generates the label. We will frequently refer $\\mathcal{C}_{h}$ to the set $\\{x\\in\\mathcal{X}:h(x)\\neq h^{*}(x)\\}$ , where h is a predictor in hypothesis class $\\mathcal{H}$. The distributionally robust risk has the following form:\n\n$$\nR_{2}(h;P)=\\operatorname*{sup}_{Q\\ll P}\\left\\{\\mathbb{E}_{x\\sim Q}[\\mathbb{1}[h(x)\\neq h^{\\ast}(x)]]:D_{2}(Q\\|P)\\leq\\rho\\right\\}.\n$$"}, {"id": "v24-22-0881:ctx15", "name": "Definition 11 (Distributionally Robust eps-net), Eq. (5)", "statement": "Definition 11 (Distributionally Robust ε-net) Let $\\mathcal{X}$ be a domain. $S \\subseteq{\\mathcal{X}}$ is a Distributionally Robust ε-net for $\\mathcal{H}\\subseteq \\mathcal{Y}^{\\mathcal{X}}$ with respect to a distribution P over $\\mathcal{X}$ if:\n\n$$\n\\forall h\\in{\\mathcal{H}}:R_{2}(h;P)\\geq\\varepsilon\\implies\\mathcal{C}_{h}\\cap S\\neq\\emptyset .\\tag{5}\n$$"}, {"id": "v24-22-0881:ctx16", "name": "Notation phi_{eta,h} (Appendix A.1)", "statement": "We use $\\varphi_{\\eta,h}(x,y)$ to denote $\\mathbb{1}[h(x)\\neq y]-\\eta$ and $c_{2}$ as the shorthand of $c_{2}(\\rho)$ when there is no ambiguity."}, {"id": "v24-22-0881:ctx17", "name": "Definition 16 (Rademacher Complexity)", "statement": "Moreover, we introduce the definition of Rademacher Complexity and Growth Function in order to bound the excess risk in terms of VC dimension.\n\nDefinition 16 (Rademacher Complexity) We define the empirical Rademacher Complexity of a hypothesis class $\\mathcal{F}$ for a given sample $z_{i}=(x_{i},y_{i}),i=1,\\dots,m$ as follows :\n\n$$\n\\hat{\\mathcal{R}}_{m}(\\mathcal{F}): =\\mathbb{E}_{\\sigma}\\left[\\operatorname*{sup}_{f\\in\\mathcal{F}}\\frac{1}{m}\\sum_{i=1}^{m}\\sigma_{i}f(z_{i})\\right],\n$$\n\nwhere $\\sigma=(\\sigma_{1},\\ldots,\\sigma_{m}) $ is a vector of i.i.d. Rademacher variables. The Rademacher Complexity is defined as the expectation of this quantity:\n\n$$\n\\mathcal{R}_{m}(\\mathcal{F}): =\\mathbb{E}_{(z_{1},\\ldots,z_{m})\\sim P^{m}}\\left[\\hat{\\mathcal{R}}_{m}(\\mathcal{F})\\right].\n$$"}, {"id": "v24-22-0881:ctx18", "name": "Definition 17 (Growth Function)", "statement": "Definition 17 (Growth Function) Let $\\mathcal{H}$ be a hypothesis class. The growth function of $\\mathcal{H}$ ,denoted as $\\tau_{\\mathcal{H}}: \\mathbb{N}\\to \\mathbb{N}$ , is defined as follows:\n\n$$\n\\tau_{\\mathcal{H}}(m): =\\underset{C\\subset\\mathcal{X}: |C| =m}{max}\\left|\\mathcal{H}_{C}\\right|,\n$$\n\nwhere $\\mathcal{H}_{C}: =\\left\\{(h(x_{1}),\\cdot\\cdot\\cdot,h(x_{|C|})):h\\in\\mathcal{H}\\right\\}$ for $C = \\{x_{i}: 1 \\leq i \\leq | C | \\}$"}, {"id": "v24-22-0881:ctx19", "name": "Lemma 20 (Hoeffding's Inequality; Shalev-Shwartz & Ben-David Lemma 4.5)", "statement": "The following Hoeffding's lemma can be found in (Shalev-Shwartz and Ben-David, 2014, Lemma 4.5).\n\nLemma 20 (Hoeffding's Inequality) Let $\\theta_{1},\\ldots,\\theta_{m}$ be a sequence of i.i.d. random variables, and assume that for all $i,\\mathbb{E}[\\theta_{i}]=\\mu$ and $\\mathbb{P}[ a \\leq \\theta_{i}\\leq b ] = 1$ . Then, for any $\\varepsilon > 0$ ,\n\n$$\n\\mathbb{P}\\left[\\left|\\frac{1}{m}\\sum_{i=1}^{m}\\theta_{i}-\\mu\\right| >\\varepsilon\\right]\\leq 2\\exp{(-2m\\varepsilon^{2}/(b-a)^{2})}.\n$$"}, {"id": "v24-22-0881:ctx20", "name": "Lemma 21 (Talagrand's Lemma; Mohri et al. Lemma 4.2)", "statement": "We next recall an important lemma that is useful for bounding the Rademacher complexity and can be found in (Mohri et al., 2012, Lemma 4.2).\n\nLemma 21 (Talagrand's Lemma) Let ψ be a ρ-Lipschitz function. For any function class $\\mathcal{H}$, we have:\n\n$$\n\\mathcal{R}_{m}(\\psi\\circ\\mathcal{H})\\leq\\rho\\mathcal{R}_{m}(\\mathcal{H}).\n$$"}, {"id": "v24-22-0881:ctx21", "name": "Lemma 22 (Shalev-Shwartz & Ben-David Lemma A.1)", "statement": "The following lemma is fundamental and can be found in (Shalev-Shwartz and Ben-David, 2014, Lemma A.1).\n\nLemma 22 Let $a > 1$ and $b > 0$ Then: $x\\geq 4a\\log(2a)+2b\\implies x\\geq a\\log(x)+b.$"}, {"id": "v24-22-0881:ctx22", "name": "Lemma 23 (closed form of R_2 on two-point distributions)", "statement": "Lemma 23 For $P_{b}(x,y)=\\begin{cases}\\frac{1+yb\\varepsilon}{2},&\\text{if } x=c,\\\\ 0,&\\text{otherwise.}\\end{cases}$ and $\\rho\\in\\left(0,{\\frac{3-2{\\sqrt{2}}}{2}}\\right)$ , we have $R_{2}(h;P_{b})=$ $\\left[1-h(c)b\\varepsilon+\\sqrt{2\\rho(1-\\varepsilon^{2})}\\right]/2.$"}, {"id": "v24-22-0881:ctx23", "name": "Lemma 24 (Slud's Inequality; Slud 1977)", "statement": "We frequently employ the following estimate on the binomial random variable probability (Slud, 1977):\n\nLemma 24 (Slud's Inequality) Let X be $a\\ (m,p)$ binomial random variable and assume that $p=(1-\\varepsilon)/2$ . Then,\n\n$$\n\\mathbb{P}[X\\ge m/2]\\ge\\frac{1}{2}\\left(1-\\sqrt{1-\\exp(-m\\varepsilon^{2}/(1-\\varepsilon^{2}))}\\right).\n$$"}, {"id": "v24-22-0881:ctx24", "name": "Lemma 25 (Maximum-Likelihood rule minimizes (14))", "statement": "Lemma 25 Among all algorithms, (14) is minimized for $\\mathcal{A}$ being the Maximum-Likelihood algorithm, $\\mathcal{A}_{M L}$ , defined as\n\n$$\n\\forall i,\\quad\\mathcal{A}_{ML}(S)(c_{i})=sign\\left(\\sum_{k:x_{k}=c_{i}}y_{k}\\right).\n$$"}, {"id": "v24-22-0881:ctx25", "name": "Lemma 26 (range of Delta)", "statement": "Lemma 26 Let $\\Delta=\\frac{1}{r}\\left(R_{2}(\\mathcal{A}(S);P)-\\operatorname*{inf}_{h\\in\\mathcal{H}}R_{2}(h;P)\\right)$ , where r is defined in the proof of Theorem 9. We have $\\Delta\\in [0,1+\\sqrt{2}\\rho^{1/2}/4]$"}, {"id": "v24-22-0881:ctx26", "name": "Lemma 27 (reverse Markov inequality)", "statement": "Lemma 27 Let Z be a random variable that takes values in $[0,c],c>1$ . Assume that $\\mathbb{E}[ Z ] = \\mu$ . Then, for any $a\\in(0,c)$ ,\n\n$$\n\\mathbb{P}[ Z > a ] \\geq \\frac{\\mu - a}{c - a}.\n$$"}, {"id": "v24-22-0881:ctx27", "name": "Lemma 28 (R_2 <= c_2(rho) er^{1/2})", "statement": "Lemma 28 For any probability distribution P and predictor $h \\in \\mathcal H$ , we have\n\n$$\nR_{2}(h;P)\\leq c_{2}(\\rho)er(h;P)^{1/2}.\n$$"}], "lean": "import Mathlib\n\nnamespace ResearchLevel\n\nopen MeasureTheory\n\nstructure Predictor (𝒳 𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] where\n\n f : 𝒳 → 𝒴'\n\n hf : Measurable f\n\nabbrev HypothesisClass (𝒳 𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] :=\n Set (Predictor 𝒳 𝒴')\n\nvariable {𝒳 : Type*} [MeasurableSpace 𝒳]\n\ndef Shatters (H : HypothesisClass 𝒳 Bool) (S : Finset 𝒳) : Prop :=\n ∀ b : S → Bool, ∃ h ∈ H, ∀ x : S, h.f x.val = b x\n\nnoncomputable def VCDim (H : HypothesisClass 𝒳 Bool) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : Shatters H S), (S.card : ℕ∞)\n\nnoncomputable def c2 (ρ : ℝ) : ℝ := Real.sqrt (1 + 2 * ρ)\n\nnoncomputable def etaDomain (ρ : ℝ) : Set ℝ :=\n if ρ = 0 then Set.Iic 1 else Set.Icc (-(1 / (c2 ρ - 1))) 1\n\nnoncomputable def robustRisk {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) (ρ : ℝ) : ℝ :=\n ⨅ η : etaDomain ρ,\n c2 ρ * Real.sqrt\n ((P {z : 𝒳 × Bool | h.f z.1 ≠ z.2}).toReal * (max (1 - (η : ℝ)) 0) ^ 2\n + (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal * (max (0 - (η : ℝ)) 0) ^ 2)\n + (η : ℝ)\n\ndef AgnosticPACAtSize {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) (n : ℕ) : Prop :=\n ∃ A : (Fin n → 𝒳 × Bool) → Predictor 𝒳 Bool,\n ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (Measure.pi fun _ : Fin n => P)\n {S : Fin n → 𝒳 × Bool |\n (⨅ h : ↥H, robustRisk (h : Predictor 𝒳 Bool) P ρ) + ε < robustRisk (A S) P ρ}\n ≤ ENNReal.ofReal δ\n\nnoncomputable def agnosticSampleComplexity {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) : ℕ∞ :=\n sInf {n : ℕ∞ | ∃ m : ℕ, n = (m : ℕ∞) ∧ AgnosticPACAtSize H ρ ε δ m}\n\ndef RealizablePACAtSize {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) (n : ℕ) : Prop :=\n ∃ A : (Fin n → 𝒳 × Bool) → Predictor 𝒳 Bool,\n ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (∃ hstar ∈ H, robustRisk hstar P ρ = 0) →\n (Measure.pi fun _ : Fin n => P)\n {S : Fin n → 𝒳 × Bool | ε < robustRisk (A S) P ρ}\n ≤ ENNReal.ofReal δ\n\nnoncomputable def realizableSampleComplexity {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) : ℕ∞ :=\n sInf {n : ℕ∞ | ∃ m : ℕ, n = (m : ℕ∞) ∧ RealizablePACAtSize H ρ ε δ m}\n\ntheorem theorem7 :\n ∀ ρ : ℝ, 0 < ρ →\n ∃ C : ℝ, 0 < C ∧\n ∀ {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty →\n (∃ H₀ ⊆ H, H₀.Countable ∧ ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool,\n (∀ i, s i ∈ H₀) ∧ ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x) →\n ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d →\n ∀ ε ∈ Set.Ioo (0 : ℝ) 1, ∀ δ ∈ Set.Ioo (0 : ℝ) 1,\n ∃ n : ℕ, agnosticSampleComplexity H ρ ε δ ≤ (n : ℕ∞) ∧\n (n : ℝ) ≤ C * ((d / ε ^ 4) * Real.log (d / ε ^ 4)\n + (1 / ε ^ 4) * max (1 / (c2 ρ - 1)) 1\n + (d / ε ^ 4) * Real.log (Real.exp 1 / d)\n + Real.log (2 / δ) / ε ^ 4) := by\n sorry\n\ntheorem theorem9 :\n ∃ c : ℝ, 0 < c ∧\n ∀ {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty → ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d →\n ∀ ρ : ℝ, 0 < ρ → ρ < (3 - 2 * Real.sqrt 2) / 2 →\n ∀ ε ∈ Set.Ioo (0 : ℝ) (1 / (8 * Real.sqrt 2)), ∀ δ ∈ Set.Ioo (0 : ℝ) (1 / 8), ∀ n : ℕ,\n agnosticSampleComplexity H ρ ε δ ≤ (n : ℕ∞) →\n c * (((1 / 2 - (Real.sqrt 2 / 16) * Real.sqrt ρ) ^ 2 * d + Real.log (1 / δ)) / ε ^ 2)\n ≤ (n : ℝ) := by\n sorry\n\ntheorem theorem12 :\n ∃ C : ℝ, 0 < C ∧\n ∀ {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty →\n (∃ H₀ ⊆ H, H₀.Countable ∧ ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool,\n (∀ i, s i ∈ H₀) ∧ ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x) →\n ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d → ∀ ρ : ℝ, 0 ≤ ρ →\n ∀ ε ∈ Set.Ioo (0 : ℝ) 1, ∀ δ ∈ Set.Ioo (0 : ℝ) (1 / 4),\n ∃ n : ℕ, realizableSampleComplexity H ρ ε δ ≤ (n : ℕ∞) ∧\n (n : ℝ) ≤ C * ((16 * (1 + 2 * ρ) * d / ε ^ 2) * Real.log (8 * (1 + 2 * ρ) * d / ε ^ 2)\n + (8 * (1 + 2 * ρ) / ε ^ 2)\n * (d * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ))) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnamespace ResearchLevel\n\nopen MeasureTheory\n\nstructure Predictor (𝒳 𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] where\n\n f : 𝒳 → 𝒴'\n\n hf : Measurable f\n\nabbrev HypothesisClass (𝒳 𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] :=\n Set (Predictor 𝒳 𝒴')\n\nvariable {𝒳 : Type*} [MeasurableSpace 𝒳]\n\ndef Shatters (H : HypothesisClass 𝒳 Bool) (S : Finset 𝒳) : Prop :=\n ∀ b : S → Bool, ∃ h ∈ H, ∀ x : S, h.f x.val = b x\n\nnoncomputable def VCDim (H : HypothesisClass 𝒳 Bool) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : Shatters H S), (S.card : ℕ∞)\n\nnoncomputable def c2 (ρ : ℝ) : ℝ := Real.sqrt (1 + 2 * ρ)\n\nnoncomputable def etaDomain (ρ : ℝ) : Set ℝ :=\n if ρ = 0 then Set.Iic 1 else Set.Icc (-(1 / (c2 ρ - 1))) 1\n\nnoncomputable def robustRisk {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) (ρ : ℝ) : ℝ :=\n ⨅ η : etaDomain ρ,\n c2 ρ * Real.sqrt\n ((P {z : 𝒳 × Bool | h.f z.1 ≠ z.2}).toReal * (max (1 - (η : ℝ)) 0) ^ 2\n + (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal * (max (0 - (η : ℝ)) 0) ^ 2)\n + (η : ℝ)\n\ndef AgnosticPACAtSize {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) (n : ℕ) : Prop :=\n ∃ A : (Fin n → 𝒳 × Bool) → Predictor 𝒳 Bool,\n ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (Measure.pi fun _ : Fin n => P)\n {S : Fin n → 𝒳 × Bool |\n (⨅ h : ↥H, robustRisk (h : Predictor 𝒳 Bool) P ρ) + ε < robustRisk (A S) P ρ}\n ≤ ENNReal.ofReal δ\n\nnoncomputable def agnosticSampleComplexity {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) : ℕ∞ :=\n sInf {n : ℕ∞ | ∃ m : ℕ, n = (m : ℕ∞) ∧ AgnosticPACAtSize H ρ ε δ m}\n\ndef RealizablePACAtSize {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) (n : ℕ) : Prop :=\n ∃ A : (Fin n → 𝒳 × Bool) → Predictor 𝒳 Bool,\n ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (∃ hstar ∈ H, robustRisk hstar P ρ = 0) →\n (Measure.pi fun _ : Fin n => P)\n {S : Fin n → 𝒳 × Bool | ε < robustRisk (A S) P ρ}\n ≤ ENNReal.ofReal δ\n\nnoncomputable def realizableSampleComplexity {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) : ℕ∞ :=\n sInf {n : ℕ∞ | ∃ m : ℕ, n = (m : ℕ∞) ∧ RealizablePACAtSize H ρ ε δ m}\n\n/-! ### Helper machinery (added) -/\n\nsection Helpers\n\nopen scoped ENNReal\nopen Finset\n\n/-! #### Elementary real analysis -/\n\ntheorem le_of_sq_le_sq' {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) (hxy : x^2 ≤ y^2) : x ≤ y := by\n have h := Real.sqrt_le_sqrt hxy\n rwa [Real.sqrt_sq hx, Real.sqrt_sq hy] at h\n\ntheorem one_lt_c2 {ρ : ℝ} (hρ : 0 < ρ) : 1 < c2 ρ := by\n have h1 : Real.sqrt 1 < Real.sqrt (1+2*ρ) := Real.sqrt_lt_sqrt (by norm_num) (by linarith)\n rwa [Real.sqrt_one] at h1\n\ntheorem c2_sq {ρ : ℝ} (hρ : 0 ≤ ρ) : (c2 ρ)^2 = 1 + 2*ρ := Real.sq_sqrt (by linarith)\n\n/-- The value of the distributionally robust risk as a function of the error probability. -/\nnoncomputable def psi (ρ a : ℝ) : ℝ := a + Real.sqrt (2*ρ*a*(1-a))\n\ntheorem psi_nonneg {ρ a : ℝ} (ha0 : 0 ≤ a) : 0 ≤ psi ρ a := by\n unfold psi; have := Real.sqrt_nonneg (2*ρ*a*(1-a)); linarith\n\ntheorem psi_le_one {ρ a : ℝ} (hρ : 0 ≤ ρ) (ha0 : 0 ≤ a) (ha1 : a * (1+2*ρ) ≤ 1) :\n psi ρ a ≤ 1 := by\n have ha : a ≤ 1 := by nlinarith\n have h1 : Real.sqrt (2*ρ*a*(1-a)) ≤ Real.sqrt ((1-a)^2) := by\n apply Real.sqrt_le_sqrt; nlinarith\n rw [Real.sqrt_sq (by linarith)] at h1\n unfold psi; linarith\n\ntheorem psi_le_c2_sqrt {ρ a : ℝ} (hρ : 0 ≤ ρ) (ha0 : 0 ≤ a) (ha1 : a ≤ 1) :\n psi ρ a ≤ c2 ρ * Real.sqrt a := by\n have hnn : 0 ≤ 2*ρ*a*(1-a) :=\n mul_nonneg (mul_nonneg (by linarith : (0:ℝ) ≤ 2*ρ) ha0) (by linarith : (0:ℝ) ≤ 1-a)\n have h2 : (psi ρ a)^2 ≤ (c2 ρ * Real.sqrt a)^2 := by\n have hs : Real.sqrt (2*ρ*a*(1-a)) ^ 2 = 2*ρ*a*(1-a) := Real.sq_sqrt hnn\n have hc : (c2 ρ)^2 = 1 + 2*ρ := Real.sq_sqrt (by linarith)\n have hsa : (Real.sqrt a)^2 = a := Real.sq_sqrt ha0\n have key : Real.sqrt (2*ρ*a*(1-a)) = Real.sqrt (2*ρ*a) * Real.sqrt (1-a) := by\n rw [← Real.sqrt_mul (by positivity)]\n have h1 : Real.sqrt (2*ρ*a) ^2 = 2*ρ*a := Real.sq_sqrt (by positivity)\n have h3 : Real.sqrt (1-a)^2 = 1-a := Real.sq_sqrt (by linarith)\n unfold psi\n rw [key, mul_pow, hc, hsa]\n nlinarith [sq_nonneg (Real.sqrt (1-a) - Real.sqrt (2*ρ*a)), Real.sqrt_nonneg (2*ρ*a),\n Real.sqrt_nonneg (1-a), Real.sqrt_nonneg a]\n have hpos : 0 ≤ c2 ρ * Real.sqrt a := by unfold c2; positivity\n nlinarith [psi_nonneg (ρ := ρ) ha0, h2, hpos]\n\ntheorem key_neg {ρ a t : ℝ} (hρ : 0 ≤ ρ) (ha0 : 0 ≤ a) (ha1 : a ≤ 1) (ht : 0 ≤ t) :\n psi ρ a + t ≤ c2 ρ * Real.sqrt (a*(1+t)^2 + (1-a)*t^2) := by\n set u := Real.sqrt (2*ρ) with hu_def\n set v := Real.sqrt a with hv_def\n set w := Real.sqrt (1-a) with hw_def\n have hu : u^2 = 2*ρ := Real.sq_sqrt (by linarith)\n have hv : v^2 = a := Real.sq_sqrt ha0\n have hw : w^2 = 1-a := Real.sq_sqrt (by linarith)\n have hun : 0 ≤ u := Real.sqrt_nonneg _\n have hvn : 0 ≤ v := Real.sqrt_nonneg _\n have hwn : 0 ≤ w := Real.sqrt_nonneg _\n have hpsi : psi ρ a = v^2 + u*v*w := by\n unfold psi\n rw [hv]\n congr 1\n rw [show 2*ρ*a*(1-a) = (u*v*w)^2 by rw [mul_pow, mul_pow, hu, hv, hw]]\n exact Real.sqrt_sq (by positivity)\n have hXeq : a*(1+t)^2 + (1-a)*t^2 = v^2*(1+t)^2 + w^2*t^2 := by rw [hv, hw]\n have hc2 : c2 ρ * Real.sqrt (v^2*(1+t)^2 + w^2*t^2)\n = Real.sqrt ((1+u^2) * (v^2*(1+t)^2 + w^2*t^2)) := by\n rw [c2, Real.sqrt_mul (by nlinarith)]\n congr 2\n linarith [hu]\n rw [hXeq, hc2, hpsi]\n have hid : (1+u^2)*(v^2*(1+t)^2+w^2*t^2) - (v^2+u*v*w+t)^2 = (u*t-v*w+u*v^2)^2 := by\n linear_combination (-((1+u^2)*(v^2-t^2))) * hw + (-((1+u^2)*(v^2-t^2))) * hv\n have hnn : 0 ≤ v^2 + u*v*w + t := by positivity\n rw [show v^2 + u*v*w + t = Real.sqrt ((v^2+u*v*w+t)^2) from (Real.sqrt_sq hnn).symm]\n apply Real.sqrt_le_sqrt\n nlinarith [sq_nonneg (u*t-v*w+u*v^2), hid]\n\ntheorem opt_val {ρ a : ℝ} (hρ : 0 < ρ) (ha0 : 0 ≤ a) (ha1 : a ≤ 1) :\n c2 ρ * Real.sqrt (a*(1+(Real.sqrt (a*(1-a)/(2*ρ)) - a))^2\n + (1-a)*(Real.sqrt (a*(1-a)/(2*ρ)) - a)^2) - (Real.sqrt (a*(1-a)/(2*ρ)) - a) = psi ρ a := by\n set s := Real.sqrt (a*(1-a)/(2*ρ)) with hs_def\n have hnn : 0 ≤ a*(1-a)/(2*ρ) := by\n apply div_nonneg (mul_nonneg ha0 (by linarith)) (by linarith)\n have hs2 : s^2 = a*(1-a)/(2*ρ) := Real.sq_sqrt hnn\n have hsn : 0 ≤ s := Real.sqrt_nonneg _\n set t := s - a with ht_def\n have hXeq : a*(1+t)^2 + (1-a)*t^2 = (1+2*ρ)/(2*ρ) * (a*(1-a)) := by\n have h0 : a*(1+t)^2 + (1-a)*t^2 = (t+a)^2 + a - a^2 := by ring\n rw [h0, ht_def]\n have h1 : s - a + a = s := by ring\n rw [h1, hs2]\n field_simp\n ring\n rw [hXeq]\n have h1 : Real.sqrt ((1+2*ρ)/(2*ρ) * (a*(1-a))) = Real.sqrt (1+2*ρ) * s := by\n rw [hs_def, ← Real.sqrt_mul (by positivity)]\n congr 1\n field_simp\n rw [h1, c2, ← mul_assoc, Real.mul_self_sqrt (by linarith : (0:ℝ) ≤ 1+2*ρ)]\n have hq : (2*ρ*s)^2 = 2*ρ*a*(1-a) := by\n have h3 : (2*ρ*s)^2 = 4*ρ^2*s^2 := by ring\n rw [h3, hs2]; field_simp; ring\n have h2 : 2*ρ*s = Real.sqrt (2*ρ*a*(1-a)) := by\n rw [← hq, Real.sqrt_sq (mul_nonneg (by linarith) hsn)]\n unfold psi\n linarith [h2]\n\ntheorem psi_mono {ρ a₀ a : ℝ} (hρ : 0 ≤ ρ) (h0 : 0 ≤ a₀) (hle : a₀ ≤ a) (hsum : a + a₀ ≤ 1) :\n psi ρ a₀ + (a - a₀) ≤ psi ρ a := by\n have hx : 0 ≤ 2*ρ*((a-a₀)*(1-a-a₀)) :=\n mul_nonneg (by linarith) (mul_nonneg (by linarith) (by linarith))\n have h1 : Real.sqrt (2*ρ*a₀*(1-a₀)) ≤ Real.sqrt (2*ρ*a*(1-a)) := by\n apply Real.sqrt_le_sqrt\n nlinarith [hx]\n unfold psi\n linarith\n\n/-! #### The objective function of the robust risk -/\n\ntheorem obj_lb {ρ a η : ℝ} (hρ : 0 < ρ) (ha0 : 0 ≤ a) (ha1 : a*(1+2*ρ) ≤ 1) (hη : η ≤ 1) :\n psi ρ a ≤ c2 ρ * Real.sqrt (a * (max (1-η) 0)^2 + (1-a) * (max (0-η) 0)^2) + η := by\n have haa : a ≤ 1 := by nlinarith\n rcases le_or_gt η 0 with hc | hc\n · have h1 : max (1-η) 0 = 1 - η := max_eq_left (by linarith)\n have h2 : max (0-η) 0 = -η := by rw [max_eq_left (by linarith)]; ring\n rw [h1, h2]\n have hkey := key_neg (ρ := ρ) (a := a) (t := -η) (by linarith) ha0 haa (by linarith)\n have he : a*(1+(-η))^2 + (1-a)*(-η)^2 = a*(1-η)^2 + (1-a)*(-η)^2 := by ring_nf\n rw [he] at hkey\n linarith\n · have h2 : max (0-η) 0 = 0 := max_eq_right (by linarith)\n have h1 : max (1-η) 0 = 1 - η := max_eq_left (by linarith)\n rw [h1, h2]\n have he : a*(1-η)^2 + (1-a)*0^2 = a*(1-η)^2 := by ring\n rw [he]\n have hsq : Real.sqrt (a*(1-η)^2) = Real.sqrt a * (1-η) := by\n rw [Real.sqrt_mul ha0, Real.sqrt_sq (by linarith)]\n rw [hsq]\n have hcs := psi_le_c2_sqrt (ρ := ρ) (a := a) (by linarith) ha0 haa\n have hpo := psi_le_one (ρ := ρ) (a := a) (by linarith) ha0 ha1\n nlinarith [hcs, hpo, hc, hη]\n\ntheorem meas_eq_set {𝒳 : Type*} [MeasurableSpace 𝒳] (h : Predictor 𝒳 Bool) :\n MeasurableSet {z : 𝒳 × Bool | h.f z.1 = z.2} := by\n have he : {z : 𝒳 × Bool | h.f z.1 = z.2}\n = (h.f ⁻¹' {true}) ×ˢ ({true} : Set Bool) ∪ (h.f ⁻¹' {false}) ×ˢ ({false} : Set Bool) := by\n ext ⟨x, y⟩\n cases y <;> cases hh : h.f x <;> simp [hh]\n rw [he]\n exact ((h.hf (by trivial)).prod (by trivial)).union ((h.hf (by trivial)).prod (by trivial))\n\ntheorem meas_ne_set {𝒳 : Type*} [MeasurableSpace 𝒳] (h : Predictor 𝒳 Bool) :\n MeasurableSet {z : 𝒳 × Bool | h.f z.1 ≠ z.2} := by\n have he : {z : 𝒳 × Bool | h.f z.1 ≠ z.2} = {z : 𝒳 × Bool | h.f z.1 = z.2}ᶜ := by\n ext z; simp\n rw [he]; exact (meas_eq_set h).compl\n\n/-- Closed form for the χ²-distributionally robust risk of a predictor with error probability `a`,\nvalid as long as `a (1 + 2ρ) ≤ 1`. -/\ntheorem robustRisk_eq {𝒳 : Type*} [MeasurableSpace 𝒳] (h : Predictor 𝒳 Bool)\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P] {ρ a : ℝ}\n (hρ : 0 < ρ) (hρ8 : ρ ≤ 8) (ha : (P {z : 𝒳 × Bool | h.f z.1 ≠ z.2}).toReal = a)\n (ha0 : 0 ≤ a) (ha1 : a*(1+2*ρ) ≤ 1) :\n robustRisk h P ρ = psi ρ a := by\n have haa : a ≤ 1 := by nlinarith\n have hcorr : (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal = 1 - a := by\n have hc : {z : 𝒳 × Bool | h.f z.1 = z.2} = {z : 𝒳 × Bool | h.f z.1 ≠ z.2}ᶜ := by\n ext z; simp\n have hsum := measure_add_measure_compl (μ := P) (meas_ne_set h)\n rw [hc]\n have h1 : P {z : 𝒳 × Bool | h.f z.1 ≠ z.2} ≠ ⊤ := measure_ne_top _ _\n have h2 : P ({z : 𝒳 × Bool | h.f z.1 ≠ z.2}ᶜ) ≠ ⊤ := measure_ne_top _ _\n have h3 := congrArg ENNReal.toReal hsum\n rw [ENNReal.toReal_add h1 h2, ha] at h3\n simp at h3\n linarith\n set s := Real.sqrt (a*(1-a)/(2*ρ)) with hs_def\n have hsn : 0 ≤ s := Real.sqrt_nonneg _\n have hnn2 : 0 ≤ a*(1-a)/(2*ρ) :=\n div_nonneg (mul_nonneg ha0 (by linarith)) (by linarith)\n have hs2 : s^2 = a*(1-a)/(2*ρ) := Real.sq_sqrt hnn2\n have hs2' : s^2 * (2*ρ) = a*(1-a) := by rw [hs2]; field_simp\n set η₀ : ℝ := -(s - a) with hη₀_def\n have hta : a ≤ s := by\n refine le_of_sq_le_sq' ha0 hsn ?_\n nlinarith [hs2', mul_nonneg ha0 (by linarith : (0:ℝ) ≤ 1 - a - 2*ρ*a), hρ]\n have hs_le : s ≤ 1/ρ := by\n have h1 : s^2 ≤ (1/ρ)^2 := by\n rw [hs2, div_pow, one_pow, div_le_div_iff₀ (by linarith) (by positivity)]\n nlinarith [sq_nonneg (a - 1/2), hρ8, hρ]\n exact le_of_sq_le_sq' hsn (by positivity) h1\n have hmem : η₀ ∈ etaDomain ρ := by\n rw [etaDomain, if_neg (ne_of_gt hρ)]\n have hc2 : 1 < c2 ρ := one_lt_c2 hρ\n have hc2le : c2 ρ ≤ 1 + ρ := by nlinarith [c2_sq (le_of_lt hρ), hc2]\n have hfin : 1/ρ ≤ 1/(c2 ρ - 1) := by\n apply one_div_le_one_div_of_le (by linarith) (by linarith)\n constructor\n · simp only [hη₀_def]; linarith\n · simp only [hη₀_def]; linarith\n haveI : Nonempty ↥(etaDomain ρ) := ⟨⟨η₀, hmem⟩⟩\n have hlb : ∀ η : ↥(etaDomain ρ), psi ρ a ≤\n c2 ρ * Real.sqrt (a * (max (1 - (η:ℝ)) 0)^2 + (1-a) * (max (0 - (η:ℝ)) 0)^2) + (η:ℝ) := by\n rintro ⟨η, hη⟩\n apply obj_lb hρ ha0 ha1\n rw [etaDomain, if_neg (ne_of_gt hρ)] at hη\n exact hη.2\n rw [robustRisk, ha, hcorr]\n apply le_antisymm\n · have hbdd : BddBelow (Set.range fun η : ↥(etaDomain ρ) =>\n c2 ρ * Real.sqrt (a * (max (1 - (η:ℝ)) 0)^2 + (1-a) * (max (0 - (η:ℝ)) 0)^2) + (η:ℝ)) := by\n refine ⟨psi ρ a, ?_⟩\n rintro _ ⟨η, rfl⟩\n exact hlb η\n have hci := ciInf_le hbdd (⟨η₀, hmem⟩ : ↥(etaDomain ρ))\n refine le_trans hci (le_of_eq ?_)\n show c2 ρ * Real.sqrt (a * (max (1 - η₀) 0)^2 + (1-a) * (max (0 - η₀) 0)^2) + η₀ = psi ρ a\n have h1 : max (1 - η₀) 0 = 1 + (s - a) := by\n rw [hη₀_def]; rw [max_eq_left (by linarith)]; ring\n have h2 : max (0 - η₀) 0 = s - a := by\n rw [hη₀_def]; rw [max_eq_left (by linarith)]; ring\n rw [h1, h2, hη₀_def]\n have hov := opt_val (ρ := ρ) (a := a) hρ ha0 haa\n rw [← hs_def] at hov\n linarith [hov]\n · exact le_ciInf hlb\n\n\nnoncomputable def droMeas {W : Type*} [Fintype W] [MeasurableSpace W] (w : W → ℝ≥0∞) : Measure W :=\n ∑ v : W, w v • Measure.dirac v\n\ntheorem droMeas_apply {W : Type*} [Fintype W] [MeasurableSpace W] [MeasurableSingletonClass W]\n (w : W → ℝ≥0∞) (A : Set W) [DecidablePred (· ∈ A)] :\n droMeas w A = ∑ v ∈ Finset.univ.filter (· ∈ A), w v := by\n classical\n simp only [droMeas, Measure.coe_finset_sum, Finset.sum_apply, Measure.smul_apply, smul_eq_mul,\n Measure.dirac_apply' _ (by measurability : MeasurableSet A)]\n rw [Finset.sum_filter]\n refine Finset.sum_congr rfl (fun v _ => ?_)\n by_cases hv : v ∈ A <;> simp [hv]\n\ntheorem droMeas_singleton {W : Type*} [Fintype W] [MeasurableSpace W] [MeasurableSingletonClass W]\n [DecidableEq W] (w : W → ℝ≥0∞) (u : W) : droMeas w {u} = w u := by\n rw [droMeas_apply]\n rw [show (Finset.univ.filter (· ∈ ({u} : Set W))) = ({u} : Finset W) by ext v; simp]\n simp\n\ntheorem droMeas_prob {W : Type*} [Fintype W] [MeasurableSpace W] [MeasurableSingletonClass W]\n (w : W → ℝ≥0∞) (h : ∑ v : W, w v = 1) : IsProbabilityMeasure (droMeas w) := by\n classical\n constructor\n rw [droMeas_apply]\n simpa using h\n\n\ntheorem dro_discrete_lb {W X : Type*} [Fintype W] [MeasurableSpace W] [MeasurableSingletonClass W]\n [MeasurableSpace X]\n (q : Measure W) [IsProbabilityMeasure q] (g : W → X) (hg : Measurable g) (m : ℕ)\n (E : Set (Fin m → X)) (T : Finset (Fin m → W))\n (hT : ∀ S ∈ T, (fun k => g (S k)) ∈ E) :\n ∑ S ∈ T, ∏ k, q {S k} ≤ (Measure.pi fun _ : Fin m => q.map g) E := by\n haveI : IsProbabilityMeasure (q.map g) := Measure.isProbabilityMeasure_map hg.aemeasurable\n have hpi : Measure.pi (fun _ : Fin m => q.map g)\n = (Measure.pi (fun _ : Fin m => q)).map (fun S i => g (S i)) := by\n refine Measure.pi_eq (μ := fun _ : Fin m => q.map g) ?_\n intro s hs\n rw [Measure.map_apply (by fun_prop) (MeasurableSet.univ_pi hs)]\n have : (fun (S : Fin m → W) (i : Fin m) => g (S i)) ⁻¹' (Set.pi Set.univ s)\n = Set.pi Set.univ (fun i => g ⁻¹' (s i)) := by\n ext S; simp [Set.mem_pi]\n rw [this, Measure.pi_pi]\n exact Finset.prod_congr rfl (fun i _ => (Measure.map_apply hg (hs i)).symm)\n rw [hpi]\n refine le_trans ?_ (Measure.le_map_apply (Measurable.aemeasurable (by measurability)) E)\n have hsub : (↑T : Set (Fin m → W)) ⊆ (fun (S : Fin m → W) (i : Fin m) => g (S i)) ⁻¹' E := by\n intro S hS; exact hT S hS\n refine le_trans ?_ (measure_mono hsub)\n rw [← sum_measure_singleton]\n exact le_of_eq (Finset.sum_congr rfl (fun S _ => (Measure.pi_singleton _ _).symm))\n\n\ntheorem dro_min_eq_half {x y : ℝ} : min x y = (x + y - |x - y|)/2 := by\n rcases le_total x y with h | h\n · rw [min_eq_left h, abs_of_nonpos (by linarith)]; ring\n · rw [min_eq_right h, abs_of_nonneg (by linarith)]; ring\n\ntheorem dro_minsum_1 {Ω : Type*} [Fintype Ω] (F₁ F₂ : Ω → ℝ)\n (h1 : ∀ S, 0 ≤ F₁ S) (h2 : ∀ S, 0 ≤ F₂ S)\n (hs1 : ∑ S, F₁ S = 1) (hs2 : ∑ S, F₂ S = 1) :\n (∑ S, Real.sqrt (F₁ S * F₂ S))^2 ≤ 2 * ∑ S, min (F₁ S) (F₂ S) := by\n have key : ∀ S, Real.sqrt (F₁ S * F₂ S)\n = Real.sqrt (min (F₁ S) (F₂ S)) * Real.sqrt (max (F₁ S) (F₂ S)) := by\n intro S\n rw [← Real.sqrt_mul (le_min (h1 S) (h2 S))]\n congr 1\n rcases le_total (F₁ S) (F₂ S) with h | h\n · rw [min_eq_left h, max_eq_right h]\n · rw [min_eq_right h, max_eq_left h]; ring\n have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ\n (fun S => Real.sqrt (min (F₁ S) (F₂ S))) (fun S => Real.sqrt (max (F₁ S) (F₂ S)))\n have hmin : ∀ S, Real.sqrt (min (F₁ S) (F₂ S))^2 = min (F₁ S) (F₂ S) :=\n fun S => Real.sq_sqrt (le_min (h1 S) (h2 S))\n have hmax : ∀ S, Real.sqrt (max (F₁ S) (F₂ S))^2 = max (F₁ S) (F₂ S) :=\n fun S => Real.sq_sqrt (le_max_of_le_left (h1 S))\n simp only [hmin, hmax] at hcs\n have hsum : ∑ S, max (F₁ S) (F₂ S) = 2 - ∑ S, min (F₁ S) (F₂ S) := by\n have : ∀ S, max (F₁ S) (F₂ S) = F₁ S + F₂ S - min (F₁ S) (F₂ S) := by\n intro S; rcases le_total (F₁ S) (F₂ S) with h | h\n · rw [min_eq_left h, max_eq_right h]; ring\n · rw [min_eq_right h, max_eq_left h]; ring\n rw [Finset.sum_congr rfl (fun S _ => this S)]\n rw [Finset.sum_sub_distrib, Finset.sum_add_distrib, hs1, hs2]\n ring\n have hmnn : 0 ≤ ∑ S, min (F₁ S) (F₂ S) :=\n Finset.sum_nonneg (fun S _ => le_min (h1 S) (h2 S))\n rw [Finset.sum_congr rfl (fun S _ => key S)]\n nlinarith [hcs, hsum, hmnn]\n\ntheorem dro_minsum_2 {Ω : Type*} [Fintype Ω] (F₁ F₂ : Ω → ℝ)\n (h1 : ∀ S, 0 < F₁ S) (h2 : ∀ S, 0 ≤ F₂ S)\n (hs1 : ∑ S, F₁ S = 1) (hs2 : ∑ S, F₂ S = 1) :\n 1 - (1/2) * Real.sqrt ((∑ S, (F₂ S)^2/(F₁ S)) - 1) ≤ ∑ S, min (F₁ S) (F₂ S) := by\n have hminabs : ∑ S, min (F₁ S) (F₂ S) = 1 - (1/2) * ∑ S, |F₁ S - F₂ S| := by\n rw [Finset.sum_congr rfl (fun S _ => dro_min_eq_half (x := F₁ S) (y := F₂ S))]\n rw [← Finset.sum_div, Finset.sum_sub_distrib, Finset.sum_add_distrib, hs1, hs2]\n ring\n have hchi : ∑ S, (F₁ S - F₂ S)^2/(F₁ S) = (∑ S, (F₂ S)^2/(F₁ S)) - 1 := by\n have : ∀ S : Ω, (F₁ S - F₂ S)^2/(F₁ S) = F₁ S - 2 * F₂ S + (F₂ S)^2/(F₁ S) := by\n intro S; have hne := (h1 S).ne'; field_simp; ring\n rw [Finset.sum_congr rfl (fun S _ => this S)]\n rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, hs1, hs2]\n ring\n have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ\n (fun S => Real.sqrt (F₁ S)) (fun S => |F₁ S - F₂ S| / Real.sqrt (F₁ S))\n have hab : ∀ S : Ω, Real.sqrt (F₁ S) * (|F₁ S - F₂ S| / Real.sqrt (F₁ S)) = |F₁ S - F₂ S| := by\n intro S\n rw [mul_div_cancel₀]\n exact ne_of_gt (Real.sqrt_pos.mpr (h1 S))\n have hb2 : ∀ S : Ω, (|F₁ S - F₂ S| / Real.sqrt (F₁ S))^2 = (F₁ S - F₂ S)^2/(F₁ S) := by\n intro S\n rw [div_pow, sq_abs, Real.sq_sqrt (le_of_lt (h1 S))]\n have ha2 : ∀ S : Ω, Real.sqrt (F₁ S)^2 = F₁ S := fun S => Real.sq_sqrt (le_of_lt (h1 S))\n simp only [hab, hb2, ha2] at hcs\n rw [hs1, one_mul, hchi] at hcs\n have habs_nn : 0 ≤ ∑ S, |F₁ S - F₂ S| := Finset.sum_nonneg (fun S _ => abs_nonneg _)\n have hle : ∑ S, |F₁ S - F₂ S| ≤ Real.sqrt ((∑ S, (F₂ S)^2/(F₁ S)) - 1) := by\n exact Real.le_sqrt_of_sq_le hcs\n linarith [hminabs, hle]\n\n\nopen Finset in\ntheorem dro_sum_prod_pow {W : Type*} [Fintype W] [DecidableEq W] (m : ℕ) (f : W → ℝ) :\n ∑ S : Fin m → W, ∏ k, f (S k) = (∑ w, f w)^m := by\n have := Finset.sum_prod_piFinset (ι := Fin m) (Finset.univ : Finset W) (fun _ w => f w)\n rw [Fintype.piFinset_univ] at this\n rw [this]\n simp\n\ntheorem dro_sqrt_prod_eq {W : Type*} [Fintype W] (m : ℕ) (u : Fin m → W) (f₁ f₂ : W → ℝ)\n (h1 : ∀ w, 0 ≤ f₁ w) (h2 : ∀ w, 0 ≤ f₂ w) :\n Real.sqrt ((∏ k, f₁ (u k)) * (∏ k, f₂ (u k))) = ∏ k, Real.sqrt (f₁ (u k) * f₂ (u k)) := by\n rw [show (∏ k, f₁ (u k)) * (∏ k, f₂ (u k)) = ∏ k, (f₁ (u k) * f₂ (u k)) from\n (Finset.prod_mul_distrib).symm]\n rw [show (∏ k, (f₁ (u k) * f₂ (u k))) = (∏ k, Real.sqrt (f₁ (u k) * f₂ (u k)))^2 by\n rw [← Finset.prod_pow]\n exact Finset.prod_congr rfl (fun k _ => (Real.sq_sqrt (mul_nonneg (h1 _) (h2 _))).symm)]\n exact Real.sqrt_sq (Finset.prod_nonneg (fun k _ => Real.sqrt_nonneg _))\n\n\ntheorem dro_prodmin_1 {W : Type*} [Fintype W] [DecidableEq W] (m : ℕ) (f₁ f₂ : W → ℝ)\n (h1 : ∀ w, 0 ≤ f₁ w) (h2 : ∀ w, 0 ≤ f₂ w)\n (hs1 : ∑ w, f₁ w = 1) (hs2 : ∑ w, f₂ w = 1) :\n (1/2) * ((∑ w, Real.sqrt (f₁ w * f₂ w))^m)^2\n ≤ ∑ S : Fin m → W, min (∏ k, f₁ (S k)) (∏ k, f₂ (S k)) := by\n have hp1 : ∑ S : Fin m → W, (∏ k, f₁ (S k)) = 1 := by rw [dro_sum_prod_pow, hs1, one_pow]\n have hp2 : ∑ S : Fin m → W, (∏ k, f₂ (S k)) = 1 := by rw [dro_sum_prod_pow, hs2, one_pow]\n have key := dro_minsum_1 (Ω := Fin m → W) (fun S => ∏ k, f₁ (S k)) (fun S => ∏ k, f₂ (S k))\n (fun S => Finset.prod_nonneg (fun k _ => h1 _)) (fun S => Finset.prod_nonneg (fun k _ => h2 _))\n hp1 hp2\n have hsq : ∑ S : Fin m → W, Real.sqrt ((∏ k, f₁ (S k)) * (∏ k, f₂ (S k)))\n = (∑ w, Real.sqrt (f₁ w * f₂ w))^m := by\n rw [← dro_sum_prod_pow m (fun w => Real.sqrt (f₁ w * f₂ w))]\n exact Finset.sum_congr rfl (fun S _ => dro_sqrt_prod_eq m S f₁ f₂ h1 h2)\n rw [hsq] at key\n linarith\n\ntheorem dro_prodmin_2 {W : Type*} [Fintype W] [DecidableEq W] (m : ℕ) (f₁ f₂ : W → ℝ)\n (h1 : ∀ w, 0 < f₁ w) (h2 : ∀ w, 0 ≤ f₂ w)\n (hs1 : ∑ w, f₁ w = 1) (hs2 : ∑ w, f₂ w = 1) :\n 1 - (1/2) * Real.sqrt ((∑ w, (f₂ w)^2/(f₁ w))^m - 1)\n ≤ ∑ S : Fin m → W, min (∏ k, f₁ (S k)) (∏ k, f₂ (S k)) := by\n have hp1 : ∑ S : Fin m → W, (∏ k, f₁ (S k)) = 1 := by rw [dro_sum_prod_pow, hs1, one_pow]\n have hp2 : ∑ S : Fin m → W, (∏ k, f₂ (S k)) = 1 := by rw [dro_sum_prod_pow, hs2, one_pow]\n have key := dro_minsum_2 (Ω := Fin m → W) (fun S => ∏ k, f₁ (S k)) (fun S => ∏ k, f₂ (S k))\n (fun S => Finset.prod_pos (fun k _ => h1 _)) (fun S => Finset.prod_nonneg (fun k _ => h2 _))\n hp1 hp2\n have hchi : ∑ S : Fin m → W, (∏ k, f₂ (S k))^2/(∏ k, f₁ (S k))\n = (∑ w, (f₂ w)^2/(f₁ w))^m := by\n rw [← dro_sum_prod_pow m (fun w => (f₂ w)^2/(f₁ w))]\n refine Finset.sum_congr rfl (fun S _ => ?_)\n rw [Finset.prod_div_distrib, Finset.prod_pow]\n rw [hchi] at key\n exact key\n\n\nnoncomputable def droW (D : ℕ) (r : ℝ) (b : Fin D → Bool) : Fin D × Bool → ℝ :=\n fun v => (1/(D:ℝ)) * (if v.2 = b v.1 then (1+r)/2 else (1-r)/2)\n\ndef droFlip {D : ℕ} (i : Fin D) (b : Fin D → Bool) : Fin D → Bool :=\n fun j => if j = i then !(b j) else b j\n\ntheorem droFlip_inv {D : ℕ} (i : Fin D) : Function.Involutive (droFlip i) := by\n intro b; funext j; simp only [droFlip]; by_cases h : j = i <;> simp [h]\n\ntheorem dro_sum_bool_if {A B : ℝ} (β : Bool) : (∑ y : Bool, if y = β then A else B) = A + B := by\n cases β <;> simp <;> ring\n\ntheorem droW_pos {D : ℕ} {r : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : -1 < r) (b : Fin D → Bool)\n (v : Fin D × Bool) : 0 < droW D r b v := by\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n simp only [droW]\n apply mul_pos (by positivity)\n by_cases h : v.2 = b v.1 <;> simp [h] <;> linarith\n\ntheorem droW_sum {D : ℕ} {r : ℝ} (hD : 0 < D) (b : Fin D → Bool) :\n ∑ v : Fin D × Bool, droW D r b v = 1 := by\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n rw [Fintype.sum_prod_type]\n have : ∀ i : Fin D, ∑ y : Bool, droW D r b (i, y) = 1/(D:ℝ) := by\n intro i\n simp only [droW, ← Finset.mul_sum, dro_sum_bool_if (b i)]\n ring\n rw [Finset.sum_congr rfl (fun i _ => this i)]\n simp\n field_simp\n\ntheorem dro_bool_prod (β y : Bool) (A B : ℝ) :\n (if y = β then A else B) * (if y = !β then A else B) = A * B := by\n cases β <;> cases y <;> simp <;> ring\n\ntheorem dro_bool_chi (β : Bool) (A B : ℝ) :\n (∑ y : Bool, (if y = !β then A else B)^2/(if y = β then A else B)) = A^2/B + B^2/A := by\n cases β <;> simp <;> ring\n\ntheorem droFlip_ne {D : ℕ} {i j : Fin D} (h : j ≠ i) (b : Fin D → Bool) : droFlip i b j = b j := by\n simp [droFlip, h]\n\ntheorem droW_sqrt_sum {D : ℕ} {r : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : -1 < r)\n (b : Fin D → Bool) (i : Fin D) :\n ∑ v : Fin D × Bool, Real.sqrt (droW D r b v * droW D r (droFlip i b) v)\n = (((D:ℝ)-1) + Real.sqrt (1-r^2))/(D:ℝ) := by\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n rw [Fintype.sum_prod_type, ← Finset.add_sum_erase _ _ (Finset.mem_univ i)]\n have hpiece1 : ∑ y : Bool, Real.sqrt (droW D r b (i, y) * droW D r (droFlip i b) (i, y))\n = Real.sqrt (1-r^2)/(D:ℝ) := by\n have hval : ∀ y : Bool, droW D r b (i, y) * droW D r (droFlip i b) (i, y)\n = ((1/(D:ℝ)) * (Real.sqrt (1-r^2)/2))^2 := by\n intro y\n simp only [droW, droFlip, eq_self_iff_true, if_true]\n rw [show (1/(D:ℝ) * (if y = b i then (1+r)/2 else (1-r)/2)) *\n (1/(D:ℝ) * (if y = !(b i) then (1+r)/2 else (1-r)/2))\n = (1/(D:ℝ))^2 * ((if y = b i then (1+r)/2 else (1-r)/2) *\n (if y = !(b i) then (1+r)/2 else (1-r)/2)) by ring]\n rw [dro_bool_prod (b i) y ((1+r)/2) ((1-r)/2)]\n have hsq : (Real.sqrt (1-r^2)/2)^2 = (1-r^2)/4 := by\n rw [div_pow, Real.sq_sqrt (by nlinarith : (0:ℝ) ≤ 1 - r^2)]; norm_num\n rw [mul_pow, hsq]; ring\n rw [Finset.sum_congr rfl (fun y _ => by rw [hval y])]\n rw [Real.sqrt_sq (by positivity)]\n simp [Fintype.sum_bool]\n ring\n have hpiece2 : ∀ j ∈ Finset.univ.erase i,\n ∑ y : Bool, Real.sqrt (droW D r b (j, y) * droW D r (droFlip i b) (j, y)) = 1/(D:ℝ) := by\n intro j hj\n have hjne : j ≠ i := (Finset.mem_erase.mp hj).1\n have : ∀ y : Bool, Real.sqrt (droW D r b (j, y) * droW D r (droFlip i b) (j, y)) = droW D r b (j,y) := by\n intro y\n have h2 : droW D r (droFlip i b) (j,y) = droW D r b (j,y) := by simp only [droW]; rw [droFlip_ne hjne]\n rw [h2]\n exact Real.sqrt_mul_self (le_of_lt (droW_pos hD hr hr0 b (j,y)))\n rw [Finset.sum_congr rfl (fun y _ => this y)]\n simp only [droW, ← Finset.mul_sum, dro_sum_bool_if (b j)]\n ring\n rw [hpiece1, Finset.sum_congr rfl hpiece2]\n rw [Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ i)]\n have hcast : ((D - 1 : ℕ) : ℝ) = (D:ℝ) - 1 := by\n have : (1:ℕ) ≤ D := hD\n push_cast [Nat.cast_sub this]\n ring\n simp only [Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, hcast]\n field_simp\n try ring\n\ntheorem droW_chi_sum {D : ℕ} {r : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : -1 < r)\n (b : Fin D → Bool) (i : Fin D) :\n ∑ v : Fin D × Bool, (droW D r (droFlip i b) v)^2/(droW D r b v)\n = (((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ) := by\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n have hDne : (D:ℝ) ≠ 0 := ne_of_gt hDpos\n rw [Fintype.sum_prod_type, ← Finset.add_sum_erase _ _ (Finset.mem_univ i)]\n have hpiece1 : ∑ y : Bool, (droW D r (droFlip i b) (i, y))^2/(droW D r b (i, y))\n = (1+3*r^2)/((1-r^2)*(D:ℝ)) := by\n have hval : ∀ y : Bool, (droW D r (droFlip i b) (i, y))^2/(droW D r b (i, y))\n = (1/(D:ℝ)) * ((if y = !(b i) then (1+r)/2 else (1-r)/2)^2\n / (if y = b i then (1+r)/2 else (1-r)/2)) := by\n intro y\n simp only [droW, droFlip, eq_self_iff_true, if_true]\n have hy : (0:ℝ) < (if y = b i then (1+r)/2 else (1-r)/2) := by\n by_cases h : y = b i <;> simp [h] <;> linarith\n field_simp\n try ring\n rw [Finset.sum_congr rfl (fun y _ => hval y), ← Finset.mul_sum,\n dro_bool_chi (b i) ((1+r)/2) ((1-r)/2)]\n have h1 : (0:ℝ) < 1 + r := by linarith\n have h2 : (0:ℝ) < 1 - r := by linarith\n have h3 : (1:ℝ) - r^2 ≠ 0 := by nlinarith\n field_simp\n ring\n have hpiece2 : ∀ j ∈ Finset.univ.erase i,\n ∑ y : Bool, (droW D r (droFlip i b) (j, y))^2/(droW D r b (j, y)) = 1/(D:ℝ) := by\n intro j hj\n have hjne : j ≠ i := (Finset.mem_erase.mp hj).1\n have : ∀ y : Bool, (droW D r (droFlip i b) (j, y))^2/(droW D r b (j, y)) = droW D r b (j,y) := by\n intro y\n have h2 : droW D r (droFlip i b) (j,y) = droW D r b (j,y) := by simp only [droW]; rw [droFlip_ne hjne]\n rw [h2, sq, mul_div_assoc, div_self (ne_of_gt (droW_pos hD hr hr0 b (j,y))), mul_one]\n rw [Finset.sum_congr rfl (fun y _ => this y)]\n simp only [droW, ← Finset.mul_sum, dro_sum_bool_if (b j)]\n ring\n rw [hpiece1, Finset.sum_congr rfl hpiece2]\n rw [Finset.sum_const, Finset.card_erase_of_mem (Finset.mem_univ i)]\n have hcast : ((D - 1 : ℕ) : ℝ) = (D:ℝ) - 1 := by\n have h1 : (1:ℕ) ≤ D := hD\n push_cast [Nat.cast_sub h1]\n ring\n have hr2 : (0:ℝ) < 1 - r^2 := by nlinarith\n simp only [Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, hcast]\n field_simp\n try ring\n\n/-! #### The hard family of distributions -/\n\n/-- Embedding of the finite index set into the sample space. -/\ndef droG {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} (c : Fin D → 𝒳) :\n Fin D × Bool → 𝒳 × Bool := fun v => (c v.1, v.2)\n\ntheorem droG_meas {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} (c : Fin D → 𝒳) :\n Measurable (droG c) := by\n unfold droG\n measurability\n\n/-- The finite measure on the index set. -/\nnoncomputable def droQ (D : ℕ) (r : ℝ) (b : Fin D → Bool) : Measure (Fin D × Bool) :=\n droMeas (fun v => ENNReal.ofReal (droW D r b v))\n\n/-- The hard distribution associated with a labelling `b`. -/\nnoncomputable def droP {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} (c : Fin D → 𝒳) (r : ℝ)\n (b : Fin D → Bool) : Measure (𝒳 × Bool) :=\n Measure.map (droG c) (droQ D r b)\n\ntheorem droQ_prob {D : ℕ} {r : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : -1 < r) (b : Fin D → Bool) :\n IsProbabilityMeasure (droQ D r b) := by\n apply droMeas_prob\n rw [← ENNReal.ofReal_sum_of_nonneg (fun v _ => le_of_lt (droW_pos hD hr hr0 b v))]\n rw [droW_sum hD b]\n simp\n\ntheorem droP_prob {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} {r : ℝ} (hD : 0 < D) (hr : r < 1)\n (hr0 : -1 < r) (c : Fin D → 𝒳) (b : Fin D → Bool) :\n IsProbabilityMeasure (droP c r b) := by\n haveI := droQ_prob hD hr hr0 b\n exact Measure.isProbabilityMeasure_map (droG_meas c).aemeasurable\n\ntheorem dro_bool_err (β γ : Bool) (A B : ℝ) :\n (∑ y : Bool, if γ ≠ y then (if y = β then A else B) else 0) = (if γ ≠ β then A else B) := by\n cases β <;> cases γ <;> simp\n\ntheorem dro_sum_ite_card {ι : Type*} [Fintype ι] (P : ι → Prop) [DecidablePred P] (A B : ℝ) :\n (∑ i, if P i then A else B)\n = ((Finset.univ.filter P).card : ℝ) * (A - B) + (Fintype.card ι : ℝ) * B := by\n have h1 : ∀ i : ι, (if P i then A else B) = B + (if P i then (A - B) else 0) := by\n intro i; by_cases h : P i <;> simp [h]\n rw [Finset.sum_congr rfl (fun i _ => h1 i), Finset.sum_add_distrib, ← Finset.sum_filter,\n Finset.sum_const, Finset.sum_const]\n simp [Finset.card_univ]\n ring\n\ntheorem droP_err {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} {r : ℝ} (hD : 0 < D) (hr : r < 1)\n (hr0 : -1 < r) (c : Fin D → 𝒳) (b : Fin D → Bool) (h : Predictor 𝒳 Bool) :\n ((droP c r b) {z : 𝒳 × Bool | h.f z.1 ≠ z.2}).toReal\n = (1-r)/2 + r * ((Finset.univ.filter (fun i => h.f (c i) ≠ b i)).card : ℝ)/(D:ℝ) := by\n classical\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n have hpre : (droG c) ⁻¹' {z : 𝒳 × Bool | h.f z.1 ≠ z.2}\n = {v : Fin D × Bool | h.f (c v.1) ≠ v.2} := by\n ext v; simp [droG]\n rw [droP, Measure.map_apply (droG_meas c) (meas_ne_set h), hpre, droQ,\n droMeas_apply _ {v : Fin D × Bool | h.f (c v.1) ≠ v.2}]\n rw [← ENNReal.ofReal_sum_of_nonneg (fun v _ => le_of_lt (droW_pos hD hr hr0 b v)),\n ENNReal.toReal_ofReal (Finset.sum_nonneg (fun v _ => le_of_lt (droW_pos hD hr hr0 b v)))]\n rw [Finset.sum_filter, Fintype.sum_prod_type]\n have hin : ∀ i : Fin D, (∑ y : Bool, if (i, y) ∈ {v : Fin D × Bool | h.f (c v.1) ≠ v.2}\n then droW D r b (i, y) else 0)\n = (1/(D:ℝ)) * (if h.f (c i) ≠ b i then (1+r)/2 else (1-r)/2) := by\n intro i\n have hstep : ∀ y : Bool, (if (i, y) ∈ {v : Fin D × Bool | h.f (c v.1) ≠ v.2}\n then droW D r b (i, y) else 0)\n = (1/(D:ℝ)) * (if h.f (c i) ≠ y then (if y = b i then (1+r)/2 else (1-r)/2) else 0) := by\n intro y\n by_cases hy : h.f (c i) ≠ y\n · simp only [Set.mem_setOf_eq, hy, if_pos, droW]\n simp [hy]\n · simp only [Set.mem_setOf_eq, hy, if_neg, droW]\n simp [hy]\n rw [Finset.sum_congr rfl (fun y _ => hstep y), ← Finset.mul_sum,\n dro_bool_err (b i) (h.f (c i)) ((1+r)/2) ((1-r)/2)]\n rw [Finset.sum_congr rfl (fun i _ => hin i), ← Finset.mul_sum,\n dro_sum_ite_card (fun i => h.f (c i) ≠ b i) ((1+r)/2) ((1-r)/2)]\n simp only [Fintype.card_fin]\n field_simp\n ring\n\n/-- The number of points on which a predictor disagrees with the labelling `b`. -/\nnoncomputable def droN {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} (c : Fin D → 𝒳)\n (b : Fin D → Bool) (h : Predictor 𝒳 Bool) : ℕ := by\n classical\n exact (Finset.univ.filter (fun i => h.f (c i) ≠ b i)).card\n\ntheorem droN_le {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} (c : Fin D → 𝒳)\n (b : Fin D → Bool) (h : Predictor 𝒳 Bool) : droN c b h ≤ D := by\n classical\n simpa [droN] using (Finset.card_filter_le (Finset.univ : Finset (Fin D))\n (fun i => h.f (c i) ≠ b i)).trans_eq (by simp)\n\ntheorem droP_risk {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} {r ρ : ℝ} (hD : 0 < D) (hr : r < 1)\n (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8) (hcomp : (1+r)*(1+2*ρ) ≤ 2)\n (c : Fin D → 𝒳) (b : Fin D → Bool) (h : Predictor 𝒳 Bool) :\n robustRisk h (droP c r b) ρ = psi ρ ((1-r)/2 + r * (droN c b h : ℝ)/(D:ℝ)) := by\n classical\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n haveI := droP_prob hD hr (by linarith) c b\n have hNle : ((droN c b h : ℕ) : ℝ) ≤ (D:ℝ) := by\n exact_mod_cast Nat.cast_le.mpr (droN_le c b h)\n have hNnn : (0:ℝ) ≤ ((droN c b h : ℕ) : ℝ) := Nat.cast_nonneg _\n have hrN : (0:ℝ) ≤ r * (droN c b h : ℝ)/(D:ℝ) := by positivity\n have ha0 : 0 ≤ (1-r)/2 + r * (droN c b h : ℝ)/(D:ℝ) := by linarith\n have hle : (1-r)/2 + r * (droN c b h : ℝ)/(D:ℝ) ≤ (1+r)/2 := by\n have : r * (droN c b h : ℝ)/(D:ℝ) ≤ r := by\n rw [div_le_iff₀ hDpos]\n nlinarith\n linarith\n have ha1 : ((1-r)/2 + r * (droN c b h : ℝ)/(D:ℝ)) * (1+2*ρ) ≤ 1 := by\n nlinarith [hle, hρ]\n refine robustRisk_eq h (droP c r b) hρ hρ8 ?_ ha0 ha1\n rw [droP_err hD hr (by linarith) c b h]\n simp [droN]\n\n/-- Lower bound on the excess robust risk in terms of the number of mistakes. -/\ntheorem droP_excess {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} {r ρ : ℝ} (hD : 0 < D) (hr : r < 1)\n (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8) (hcomp : (1+r)*(1+2*ρ) ≤ 2)\n (c : Fin D → 𝒳) (b : Fin D → Bool) (h : Predictor 𝒳 Bool) :\n psi ρ ((1-r)/2) + r * (droN c b h : ℝ)/(D:ℝ) ≤ robustRisk h (droP c r b) ρ := by\n classical\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n have hNle : ((droN c b h : ℕ) : ℝ) ≤ (D:ℝ) := by\n exact_mod_cast Nat.cast_le.mpr (droN_le c b h)\n have hNnn : (0:ℝ) ≤ ((droN c b h : ℕ) : ℝ) := Nat.cast_nonneg _\n have hstep : r * (droN c b h : ℝ)/(D:ℝ) ≤ r := by\n rw [div_le_iff₀ hDpos]; nlinarith\n rw [droP_risk hD hr hr0 hρ hρ8 hcomp c b h]\n have := psi_mono (ρ := ρ) (a₀ := (1-r)/2) (a := (1-r)/2 + r * (droN c b h : ℝ)/(D:ℝ))\n (le_of_lt hρ) (by linarith) (by nlinarith [(by positivity : (0:ℝ) ≤ r * (droN c b h : ℝ)/(D:ℝ))])\n (by linarith)\n linarith\n\ntheorem droP_inf_le {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool} {D : ℕ}\n {r ρ : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8)\n (hcomp : (1+r)*(1+2*ρ) ≤ 2) (c : Fin D → 𝒳) (b : Fin D → Bool)\n (hb : ∃ h ∈ H, ∀ i, h.f (c i) = b i) :\n (⨅ h : ↥H, robustRisk (h : Predictor 𝒳 Bool) (droP c r b) ρ) ≤ psi ρ ((1-r)/2) := by\n classical\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n obtain ⟨h0, hh0, hh0f⟩ := hb\n have hrisk : ∀ h : Predictor 𝒳 Bool, robustRisk h (droP c r b) ρ\n = psi ρ ((1-r)/2 + r * (droN c b h : ℝ)/(D:ℝ)) :=\n fun h => droP_risk hD hr hr0 hρ hρ8 hcomp c b h\n have hbdd : BddBelow (Set.range fun h : ↥H =>\n robustRisk (h : Predictor 𝒳 Bool) (droP c r b) ρ) := by\n refine ⟨0, ?_⟩\n rintro _ ⟨h, rfl⟩\n simp only []\n rw [hrisk]\n refine psi_nonneg ?_\n have : (0:ℝ) ≤ r * (droN c b (h : Predictor 𝒳 Bool) : ℝ)/(D:ℝ) := by positivity\n linarith\n have hci := ciInf_le hbdd (⟨h0, hh0⟩ : ↥H)\n refine le_trans hci (le_of_eq ?_)\n rw [hrisk]\n have hN0 : droN c b h0 = 0 := by\n simp only [droN, Finset.card_eq_zero, Finset.filter_eq_empty_iff]\n intro i _\n simp [hh0f i]\n rw [hN0]\n norm_num\n\ntheorem droP_bad {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool} {D : ℕ}\n {r ρ ε : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8)\n (hcomp : (1+r)*(1+2*ρ) ≤ 2) (c : Fin D → 𝒳) (b : Fin D → Bool)\n (hb : ∃ h ∈ H, ∀ i, h.f (c i) = b i) (g : Predictor 𝒳 Bool)\n (hlt : ε < r * (droN c b g : ℝ)/(D:ℝ)) :\n (⨅ h : ↥H, robustRisk (h : Predictor 𝒳 Bool) (droP c r b) ρ) + ε\n < robustRisk g (droP c r b) ρ := by\n have h1 := droP_inf_le hD hr hr0 hρ hρ8 hcomp c b hb\n have h2 := droP_excess hD hr hr0 hρ hρ8 hcomp c b g\n linarith\n\ntheorem dro_transfer {𝒳 : Type*} [MeasurableSpace 𝒳] {D m : ℕ} {r δ : ℝ} (hD : 0 < D)\n (hr : r < 1) (hr0 : -1 < r) (hδ : 0 ≤ δ) (c : Fin D → 𝒳) (b : Fin D → Bool)\n (E : Set (Fin m → 𝒳 × Bool))\n (hPAC : (Measure.pi fun _ : Fin m => droP c r b) E ≤ ENNReal.ofReal δ)\n (T : Finset (Fin m → Fin D × Bool))\n (hT : ∀ S ∈ T, (fun k => droG c (S k)) ∈ E) :\n ∑ S ∈ T, ∏ k, droW D r b (S k) ≤ δ := by\n haveI := droQ_prob hD hr hr0 b\n have key := dro_discrete_lb (droQ D r b) (droG c) (droG_meas c) m E T hT\n rw [← droP] at key\n have h2 : ∑ S ∈ T, ∏ k, (droQ D r b) {S k} ≤ ENNReal.ofReal δ := le_trans key hPAC\n have h3 : ∀ S : Fin m → Fin D × Bool,\n (∏ k, (droQ D r b) {S k}) = ENNReal.ofReal (∏ k, droW D r b (S k)) := by\n intro S\n rw [ENNReal.ofReal_prod_of_nonneg (fun k _ => le_of_lt (droW_pos hD hr hr0 b (S k)))]\n exact Finset.prod_congr rfl (fun k _ => by rw [droQ, droMeas_singleton])\n rw [Finset.sum_congr rfl (fun S _ => h3 S),\n ← ENNReal.ofReal_sum_of_nonneg\n (fun S _ => Finset.prod_nonneg (fun k _ => le_of_lt (droW_pos hD hr hr0 b (S k))))] at h2\n exact (ENNReal.ofReal_le_ofReal_iff hδ).mp h2\n\n/-- From the PAC guarantee at sample size `m`, the probability (computed in the finite model)\nthat the algorithm makes more than `εD/r` mistakes on the `D` shattered points is at most `δ`. -/\ntheorem dro_master {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool} {D m : ℕ}\n {r ρ ε δ : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8)\n (hcomp : (1+r)*(1+2*ρ) ≤ 2) (hδ : 0 ≤ δ) (c : Fin D → 𝒳)\n (hshat : ∀ b : Fin D → Bool, ∃ h ∈ H, ∀ i, h.f (c i) = b i)\n (A : (Fin m → 𝒳 × Bool) → Predictor 𝒳 Bool)\n (hA : ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (Measure.pi fun _ : Fin m => P)\n {S : Fin m → 𝒳 × Bool |\n (⨅ h : ↥H, robustRisk (h : Predictor 𝒳 Bool) P ρ) + ε < robustRisk (A S) P ρ}\n ≤ ENNReal.ofReal δ) (b : Fin D → Bool) :\n ∑ S ∈ Finset.univ.filter (fun S : Fin m → Fin D × Bool =>\n ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ)),\n ∏ k, droW D r b (S k) ≤ δ := by\n classical\n haveI := droP_prob hD hr (by linarith) c b\n refine dro_transfer hD hr (by linarith) hδ c b _ (hA (droP c r b)) _ ?_\n intro S hS\n have hlt : ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ) :=\n (Finset.mem_filter.mp hS).2\n exact droP_bad hD hr hr0 hρ hρ8 hcomp c b (hshat b) _ hlt\n\ntheorem dro_pair_split {Ω : Type*} [Fintype Ω] (F₁ F₂ : Ω → ℝ) (P : Ω → Prop)\n [DecidablePred P] :\n ∑ S, min (F₁ S) (F₂ S)\n ≤ (∑ S ∈ Finset.univ.filter P, F₁ S)\n + ∑ S ∈ Finset.univ.filter (fun S => ¬ P S), F₂ S := by\n rw [← Finset.sum_filter_add_sum_filter_not Finset.univ P (fun S => min (F₁ S) (F₂ S))]\n gcongr with S hS S hS\n · exact min_le_left _ _\n · exact min_le_right _ _\n\ntheorem droN_fin_one {𝒳 : Type*} [MeasurableSpace 𝒳] (c : Fin 1 → 𝒳) (b : Fin 1 → Bool)\n (g : Predictor 𝒳 Bool) :\n ((droN c b g : ℕ) : ℝ) = if g.f (c 0) ≠ b 0 then 1 else 0 := by\n classical\n simp only [droN]\n rw [show (Finset.univ : Finset (Fin 1)) = {0} from rfl, Finset.filter_singleton]\n by_cases hh : g.f (c 0) ≠ b 0 <;> simp [hh]\n\ntheorem droFlip_fin_one (b : Fin 1 → Bool) (j : Fin 1) : droFlip 0 b j = !(b j) := by\n simp [droFlip, Subsingleton.elim j 0]\n\n/-- **Part 1 of the lower bound**: two-point argument. -/\ntheorem dro_part1 {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool} {m : ℕ}\n {r ρ ε δ : ℝ} (hr : r < 1) (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8)\n (hcomp : (1+r)*(1+2*ρ) ≤ 2) (hδ : 0 ≤ δ) (hε : 0 < ε) (hεr : ε < r) (x : 𝒳)\n (hshat : ∀ y : Bool, ∃ h ∈ H, h.f x = y)\n (hPAC : AgnosticPACAtSize H ρ ε δ m) :\n (1/4) * (1-r^2)^m ≤ δ := by\n classical\n obtain ⟨A, hA⟩ := hPAC\n set c : Fin 1 → 𝒳 := fun _ => x with hc\n have hc0 : c 0 = x := rfl\n set bt : Fin 1 → Bool := fun _ => true with hbt\n set bf : Fin 1 → Bool := fun _ => false with hbf\n have hshat' : ∀ b : Fin 1 → Bool, ∃ h ∈ H, ∀ i, h.f (c i) = b i := by\n intro b\n obtain ⟨h, hh, hf⟩ := hshat (b 0)\n exact ⟨h, hh, fun i => by rw [Subsingleton.elim i 0]; exact hf⟩\n have h1 := dro_master (D := 1) (by norm_num) hr hr0 hρ hρ8 hcomp hδ c hshat' A hA bt\n have h2 := dro_master (D := 1) (by norm_num) hr hr0 hρ hρ8 hcomp hδ c hshat' A hA bf\n have hfilt : ∀ (b : Fin 1 → Bool) (S : Fin m → Fin 1 × Bool),\n (ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/((1:ℕ):ℝ))\n ↔ ((A (fun k => droG c (S k))).f x ≠ b 0) := by\n intro b S\n rw [droN_fin_one, hc0]\n by_cases hh : (A (fun k => droG c (S k))).f x ≠ b 0\n · rw [if_pos hh]\n constructor\n · intro _; exact hh\n · intro _; push_cast; rw [mul_one, div_one]; exact hεr\n · rw [if_neg hh]\n constructor\n · intro hcon; exfalso; rw [mul_zero, zero_div] at hcon; linarith\n · intro hcon; exact absurd hcon hh\n rw [Finset.filter_congr (fun S _ => by rw [hfilt bt S])] at h1\n rw [Finset.filter_congr (fun S _ => by rw [hfilt bf S])] at h2\n have hsplit := dro_pair_split (Ω := Fin m → Fin 1 × Bool)\n (fun S => ∏ k, droW 1 r bt (S k)) (fun S => ∏ k, droW 1 r bf (S k))\n (fun S => (A (fun k => droG c (S k))).f x ≠ bt 0)\n have hcongr : (Finset.univ.filter\n (fun S : Fin m → Fin 1 × Bool => ¬ ((A (fun k => droG c (S k))).f x ≠ bt 0)))\n = Finset.univ.filter\n (fun S : Fin m → Fin 1 × Bool => (A (fun k => droG c (S k))).f x ≠ bf 0) := by\n apply Finset.filter_congr\n intro S _\n show ¬ ((A (fun k => droG c (S k))).f x ≠ true) ↔ ((A (fun k => droG c (S k))).f x ≠ false)\n cases hv : (A (fun k => droG c (S k))).f x <;> simp\n rw [hcongr] at hsplit\n have hsum : ∑ S : Fin m → Fin 1 × Bool,\n min (∏ k, droW 1 r bt (S k)) (∏ k, droW 1 r bf (S k)) ≤ 2 * δ := by\n refine le_trans hsplit ?_\n linarith\n have hfl : droFlip 0 bt = bf := by\n funext j; rw [droFlip_fin_one]; simp [hbt, hbf]\n have hsq := droW_sqrt_sum (D := 1) (r := r) (by norm_num) hr (by linarith) bt 0\n rw [hfl] at hsq\n norm_num at hsq\n have hpm := dro_prodmin_1 m (droW 1 r bt) (droW 1 r bf)\n (fun w => le_of_lt (droW_pos (by norm_num) hr (by linarith) bt w))\n (fun w => le_of_lt (droW_pos (by norm_num) hr (by linarith) bf w))\n (droW_sum (by norm_num) bt) (droW_sum (by norm_num) bf)\n rw [hsq] at hpm\n have hpow : ((Real.sqrt (1-r^2))^m)^2 = (1-r^2)^m := by\n rw [← pow_mul, mul_comm, pow_mul, Real.sq_sqrt (by nlinarith)]\n rw [hpow] at hpm\n linarith\n\ntheorem dro_pairing {D : ℕ} (Q : (Fin D → Bool) → ℝ) (i : Fin D) (μ2 : ℝ)\n (hpair : ∀ b, μ2 ≤ Q b + Q (droFlip i b)) :\n (2:ℝ)^D * μ2 ≤ 2 * ∑ b : Fin D → Bool, Q b := by\n classical\n have hbij : ∑ b : Fin D → Bool, Q (droFlip i b) = ∑ b : Fin D → Bool, Q b := by\n refine Fintype.sum_equiv ((droFlip_inv i).toPerm) _ _ (fun b => ?_)\n rfl\n have hsum : ∑ b : Fin D → Bool, (Q b + Q (droFlip i b)) = 2 * ∑ b : Fin D → Bool, Q b := by\n rw [Finset.sum_add_distrib, hbij]; ring\n have hlb : ∑ b : Fin D → Bool, μ2 ≤ ∑ b : Fin D → Bool, (Q b + Q (droFlip i b)) :=\n Finset.sum_le_sum (fun b _ => hpair b)\n rw [Finset.sum_const, hsum] at hlb\n simpa [Finset.card_univ, Fintype.card_fun] using hlb\n\ntheorem droFlip_self {D : ℕ} (i : Fin D) (b : Fin D → Bool) : droFlip i b i = !(b i) := by\n simp [droFlip]\n\ntheorem dro_index_bound {𝒳 : Type*} [MeasurableSpace 𝒳] {D m : ℕ} {r : ℝ} (hD : 0 < D)\n (hr : r < 1) (hr0 : 0 < r) (G : (Fin m → Fin D × Bool) → Predictor 𝒳 Bool)\n (c : Fin D → 𝒳) (i : Fin D) :\n (2:ℝ)^D * (1 - (1/2) * Real.sqrt (((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ))^m - 1))\n ≤ 2 * ∑ b : Fin D → Bool,\n ∑ S ∈ Finset.univ.filter (fun S => (G S).f (c i) ≠ b i), ∏ k, droW D r b (S k) := by\n classical\n refine dro_pairing _ i _ (fun b => ?_)\n have hsplit := dro_pair_split (Ω := Fin m → Fin D × Bool)\n (fun S => ∏ k, droW D r b (S k)) (fun S => ∏ k, droW D r (droFlip i b) (S k))\n (fun S => (G S).f (c i) ≠ b i)\n have hcongr : (Finset.univ.filter\n (fun S : Fin m → Fin D × Bool => ¬ ((G S).f (c i) ≠ b i)))\n = Finset.univ.filter\n (fun S : Fin m → Fin D × Bool => (G S).f (c i) ≠ (droFlip i b) i) := by\n apply Finset.filter_congr\n intro S _\n rw [droFlip_self]\n cases hv : (G S).f (c i) <;> cases hb : b i <;> simp\n rw [hcongr] at hsplit\n have hpm := dro_prodmin_2 m (droW D r b) (droW D r (droFlip i b))\n (fun w => droW_pos hD hr (by linarith) b w)\n (fun w => le_of_lt (droW_pos hD hr (by linarith) (droFlip i b) w))\n (droW_sum hD b) (droW_sum hD (droFlip i b))\n rw [droW_chi_sum hD hr (by linarith) b i] at hpm\n linarith\n\ntheorem droN_eq_sum {𝒳 : Type*} [MeasurableSpace 𝒳] {D : ℕ} (c : Fin D → 𝒳)\n (b : Fin D → Bool) (g : Predictor 𝒳 Bool) :\n ((droN c b g : ℕ) : ℝ) = ∑ i, (if g.f (c i) ≠ b i then (1:ℝ) else 0) := by\n classical\n simp only [droN, Finset.card_filter]\n push_cast\n simp\n\ntheorem dro_sumN {𝒳 : Type*} [MeasurableSpace 𝒳] {D m : ℕ} {r : ℝ} (c : Fin D → 𝒳)\n (b : Fin D → Bool) (G : (Fin m → Fin D × Bool) → Predictor 𝒳 Bool) :\n ∑ i, (∑ S ∈ Finset.univ.filter (fun S => (G S).f (c i) ≠ b i), ∏ k, droW D r b (S k))\n = ∑ S : Fin m → Fin D × Bool, (∏ k, droW D r b (S k)) * (droN c b (G S) : ℝ) := by\n classical\n have h1 : ∀ S : Fin m → Fin D × Bool, (∏ k, droW D r b (S k)) * (droN c b (G S) : ℝ)\n = ∑ i, (if (G S).f (c i) ≠ b i then (∏ k, droW D r b (S k)) else 0) := by\n intro S\n rw [droN_eq_sum, Finset.mul_sum]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n by_cases hh : (G S).f (c i) ≠ b i <;> simp [hh]\n rw [Finset.sum_congr rfl (fun S _ => h1 S), Finset.sum_comm]\n exact Finset.sum_congr rfl (fun i _ => Finset.sum_filter _ _)\n\nend Helpers\n\nsection Helpers2\n\nopen scoped ENNReal\nopen Finset\n\n/-- Expected number of mistakes on the shattered set, under the PAC guarantee. -/\ntheorem dro_expected_mistakes {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool}\n {D m : ℕ} {r ρ ε δ : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8)\n (hcomp : (1+r)*(1+2*ρ) ≤ 2) (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (c : Fin D → 𝒳)\n (hshat : ∀ b : Fin D → Bool, ∃ h ∈ H, ∀ i, h.f (c i) = b i)\n (A : (Fin m → 𝒳 × Bool) → Predictor 𝒳 Bool)\n (hA : ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (Measure.pi fun _ : Fin m => P)\n {S : Fin m → 𝒳 × Bool |\n (⨅ h : ↥H, robustRisk (h : Predictor 𝒳 Bool) P ρ) + ε < robustRisk (A S) P ρ}\n ≤ ENNReal.ofReal δ) (b : Fin D → Bool) :\n ∑ S : Fin m → Fin D × Bool, (∏ k, droW D r b (S k))\n * (droN c b (A (fun k => droG c (S k))) : ℝ)\n ≤ (D:ℝ)*(ε/r) + (D:ℝ)*δ := by\n classical\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n have hwnn : ∀ S : Fin m → Fin D × Bool, 0 ≤ ∏ k, droW D r b (S k) :=\n fun S => Finset.prod_nonneg (fun k _ => le_of_lt (droW_pos hD hr (by linarith) b (S k)))\n have hwsum : ∑ S : Fin m → Fin D × Bool, (∏ k, droW D r b (S k)) = 1 := by\n rw [dro_sum_prod_pow, droW_sum hD, one_pow]\n have hmaster := dro_master hD hr hr0 hρ hρ8 hcomp hδ c hshat A hA b\n rw [← Finset.sum_filter_add_sum_filter_not Finset.univ\n (fun S : Fin m → Fin D × Bool =>\n ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ))]\n have h1 : ∑ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool =>\n ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ)),\n (∏ k, droW D r b (S k)) * (droN c b (A (fun k => droG c (S k))) : ℝ) ≤ (D:ℝ)*δ := by\n have hstep : ∀ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool =>\n ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ)),\n (∏ k, droW D r b (S k)) * (droN c b (A (fun k => droG c (S k))) : ℝ)\n ≤ (∏ k, droW D r b (S k)) * (D:ℝ) := by\n intro S _\n refine mul_le_mul_of_nonneg_left ?_ (hwnn S)\n exact_mod_cast Nat.cast_le.mpr (droN_le c b _)\n refine le_trans (Finset.sum_le_sum hstep) ?_\n rw [← Finset.sum_mul]\n calc (∑ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool =>\n ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ)),\n ∏ k, droW D r b (S k)) * (D:ℝ)\n ≤ δ * (D:ℝ) := mul_le_mul_of_nonneg_right hmaster (le_of_lt hDpos)\n _ = (D:ℝ)*δ := by ring\n have h2 : ∑ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool =>\n ¬ (ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ))),\n (∏ k, droW D r b (S k)) * (droN c b (A (fun k => droG c (S k))) : ℝ)\n ≤ (D:ℝ)*(ε/r) := by\n have hstep : ∀ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool =>\n ¬ (ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ))),\n (∏ k, droW D r b (S k)) * (droN c b (A (fun k => droG c (S k))) : ℝ)\n ≤ (∏ k, droW D r b (S k)) * ((D:ℝ)*(ε/r)) := by\n intro S hS\n have hcon := (Finset.mem_filter.mp hS).2\n push_neg at hcon\n refine mul_le_mul_of_nonneg_left ?_ (hwnn S)\n have h3 : r * (droN c b (A (fun k => droG c (S k))) : ℝ) ≤ ε * (D:ℝ) :=\n (div_le_iff₀ hDpos).mp hcon\n rw [show (D:ℝ)*(ε/r) = ε*(D:ℝ)/r by ring, le_div_iff₀ hr0]\n nlinarith [h3]\n refine le_trans (Finset.sum_le_sum hstep) ?_\n rw [← Finset.sum_mul]\n have hle1 : (∑ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool =>\n ¬ (ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ))),\n ∏ k, droW D r b (S k)) ≤ 1 := by\n rw [← hwsum]\n exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _)\n (fun S _ _ => hwnn S)\n have hnn : (0:ℝ) ≤ (D:ℝ)*(ε/r) := by positivity\n have hX0 : (0:ℝ) ≤ (∑ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool =>\n ¬ (ε < r * (droN c b (A (fun k => droG c (S k))) : ℝ)/(D:ℝ))),\n ∏ k, droW D r b (S k)) := Finset.sum_nonneg (fun S _ => hwnn S)\n nlinarith [hle1, hnn, hX0]\n linarith\n\n/-- **Part 2 of the lower bound**: the `d`-dependent term, via Assouad-type pairing. -/\ntheorem dro_part2 {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool}\n {D m : ℕ} {r ρ ε δ : ℝ} (hD : 0 < D) (hr : r < 1) (hr0 : 0 < r) (hρ : 0 < ρ) (hρ8 : ρ ≤ 8)\n (hcomp : (1+r)*(1+2*ρ) ≤ 2) (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (c : Fin D → 𝒳)\n (hshat : ∀ b : Fin D → Bool, ∃ h ∈ H, ∀ i, h.f (c i) = b i)\n (hPAC : AgnosticPACAtSize H ρ ε δ m) :\n (1:ℝ) - (1/2) * Real.sqrt (((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ))^m - 1)\n ≤ 2*(ε/r + δ) := by\n classical\n obtain ⟨A, hA⟩ := hPAC\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n set K : ℝ := (1:ℝ) - (1/2) * Real.sqrt (((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ))^m - 1)\n with hKdef\n have hidx : ∀ i : Fin D, (2:ℝ)^D * K ≤ 2 * ∑ b : Fin D → Bool,\n ∑ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool => (A (fun k => droG c (S k))).f (c i) ≠ b i),\n ∏ k, droW D r b (S k) :=\n fun i => dro_index_bound hD hr hr0 (fun S => A (fun k => droG c (S k))) c i\n have hsum1 := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset (Fin D))) => hidx i)\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hsum1\n have hswap : ∑ i : Fin D, (2 * ∑ b : Fin D → Bool,\n ∑ S ∈ Finset.univ.filter\n (fun S : Fin m → Fin D × Bool => (A (fun k => droG c (S k))).f (c i) ≠ b i),\n ∏ k, droW D r b (S k))\n = 2 * ∑ b : Fin D → Bool, ∑ S : Fin m → Fin D × Bool,\n (∏ k, droW D r b (S k)) * (droN c b (A (fun k => droG c (S k))) : ℝ) := by\n rw [← Finset.mul_sum, Finset.sum_comm]\n congr 1\n exact Finset.sum_congr rfl\n (fun b _ => dro_sumN c b (fun S => A (fun k => droG c (S k))))\n rw [hswap] at hsum1\n have hbnd : ∑ b : Fin D → Bool, ∑ S : Fin m → Fin D × Bool,\n (∏ k, droW D r b (S k)) * (droN c b (A (fun k => droG c (S k))) : ℝ)\n ≤ (2:ℝ)^D * ((D:ℝ)*(ε/r) + (D:ℝ)*δ) := by\n have hstep := Finset.sum_le_sum (fun b (_ : b ∈ (Finset.univ : Finset (Fin D → Bool))) =>\n dro_expected_mistakes hD hr hr0 hρ hρ8 hcomp hδ hε c hshat A hA b)\n refine le_trans hstep (le_of_eq ?_)\n rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]\n congr 1\n simp [Fintype.card_fun]\n have hfin : (D:ℝ) * ((2:ℝ)^D * K) ≤ 2 * ((2:ℝ)^D * ((D:ℝ)*(ε/r) + (D:ℝ)*δ)) := by\n refine le_trans hsum1 ?_\n exact mul_le_mul_of_nonneg_left hbnd (by norm_num)\n have hp : (0:ℝ) < (D:ℝ) * (2:ℝ)^D := by positivity\n rw [hKdef] at *\n nlinarith [hfin, hp, hDpos]\n\nsection Helpers3\n\nopen scoped ENNReal\nopen Finset\n\ntheorem dro_sqrt2_sq : (Real.sqrt 2)^2 = 2 := Real.sq_sqrt (by norm_num)\n\ntheorem dro_sqrt2_pos : (0:ℝ) < Real.sqrt 2 := Real.sqrt_pos.mpr (by norm_num)\n\ntheorem dro_sqrt2_lt : Real.sqrt 2 < 1.4143 := by\n nlinarith [dro_sqrt2_sq, dro_sqrt2_pos]\n\ntheorem dro_sqrt2_gt : (1.414:ℝ) < Real.sqrt 2 := by\n nlinarith [dro_sqrt2_sq, dro_sqrt2_pos]\n\n/-- The `d/ε²` lower bound. -/\ntheorem dro_lb_d {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool}\n {D m : ℕ} {ρ ε δ : ℝ} (hD : 0 < D) (hρ : 0 < ρ) (hρ' : ρ < (3 - 2*Real.sqrt 2)/2)\n (hε0 : 0 < ε) (hε : ε < 1/(8*Real.sqrt 2)) (hδ0 : 0 < δ) (hδ : δ < 1/8)\n (c : Fin D → 𝒳)\n (hshat : ∀ b : Fin D → Bool, ∃ h ∈ H, ∀ i, h.f (c i) = b i)\n (hPAC : AgnosticPACAtSize H ρ ε δ m) :\n (D:ℝ) ≤ 1024 * m * ε^2 := by\n have hs2 := dro_sqrt2_sq\n have hs0 := dro_sqrt2_pos\n have hslt := dro_sqrt2_lt\n have hsgt := dro_sqrt2_gt\n have hDpos : (0:ℝ) < D := Nat.cast_pos.mpr hD\n have hrw : (1:ℝ)/(8*Real.sqrt 2) = Real.sqrt 2/16 := by\n rw [div_eq_div_iff (by positivity) (by norm_num)]\n nlinarith [hs2]\n rw [hrw] at hε\n have hεb : 8*ε < Real.sqrt 2 / 2 := by linarith\n have hε2 : ε^2 < 1/128 := by nlinarith [hεb, hε0, hs2]\n set r : ℝ := 8*ε with hrdef\n have hr0 : 0 < r := by simp [hrdef]; linarith\n have hr : r < 1 := by rw [hrdef]; linarith\n have hrsq : r^2 = 64*ε^2 := by rw [hrdef]; ring\n have hr2 : r^2 < 1/2 := by rw [hrsq]; linarith\n have hρ8 : ρ ≤ 8 := by linarith\n have hcomp : (1+r)*(1+2*ρ) ≤ 2 := by\n have h1 : 1 + 2*ρ < 4 - 2*Real.sqrt 2 := by linarith\n have h2 : 1 + r < 1 + Real.sqrt 2/2 := by linarith\n have h3 : (0:ℝ) < 1 + 2*ρ := by linarith\n have h4 : (0:ℝ) < 1 + Real.sqrt 2/2 := by linarith\n nlinarith [h1, h2, h3, h4, hs2]\n have hkey := dro_part2 hD hr hr0 hρ hρ8 hcomp (le_of_lt hδ0) (le_of_lt hε0) c hshat hPAC\n have hεr : ε / r = 1/8 := by rw [hrdef]; field_simp\n rw [hεr] at hkey\n -- Hence the square root exceeds 1\n have hsq1 : (1:ℝ) < Real.sqrt (((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ))^m - 1) := by\n by_contra hcon\n push_neg at hcon\n linarith\n have hbig : (2:ℝ) < ((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ))^m := by\n by_contra hcon\n push_neg at hcon\n have : Real.sqrt (((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ))^m - 1) ≤ Real.sqrt 1 :=\n Real.sqrt_le_sqrt (by linarith)\n rw [Real.sqrt_one] at this\n linarith\n -- Compare the base with 1 + 512 ε² / D\n have hone : (0:ℝ) < 1 - r^2 := by linarith\n have hbase_nn : (0:ℝ) ≤ ((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ)) := by\n have hD1 : (0:ℝ) ≤ (D:ℝ) - 1 := by\n have : (1:ℕ) ≤ D := hD\n have := Nat.one_le_cast (α := ℝ) |>.mpr this\n linarith\n have : (0:ℝ) ≤ (1+3*r^2)/(1-r^2) := by positivity\n positivity\n have hbase_le : ((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ)) ≤ 1 + 512*ε^2/(D:ℝ) := by\n rw [div_le_iff₀ hDpos]\n have hfrac : (1+3*r^2)/(1-r^2) ≤ 1 + 512*ε^2 := by\n rw [div_le_iff₀ hone, hrsq]\n nlinarith [hε2, hε0, sq_nonneg ε]\n have : (1 + 512*ε^2/(D:ℝ)) * (D:ℝ) = (D:ℝ) + 512*ε^2 := by field_simp\n rw [this]\n linarith\n have hpow : ((((D:ℝ)-1) + (1+3*r^2)/(1-r^2))/(D:ℝ))^m ≤ (1 + 512*ε^2/(D:ℝ))^m :=\n pow_le_pow_left₀ hbase_nn hbase_le m\n have hgt2 : (2:ℝ) < (1 + 512*ε^2/(D:ℝ))^m := lt_of_lt_of_le hbig hpow\n have hxpos : (0:ℝ) < 512*ε^2/(D:ℝ) := by positivity\n have hlog : Real.log 2 ≤ (m:ℝ) * Real.log (1 + 512*ε^2/(D:ℝ)) := by\n have h1 : Real.log 2 ≤ Real.log ((1 + 512*ε^2/(D:ℝ))^m) :=\n Real.log_le_log (by norm_num) (le_of_lt hgt2)\n rwa [Real.log_pow] at h1\n have hlog2 : Real.log (1 + 512*ε^2/(D:ℝ)) ≤ 512*ε^2/(D:ℝ) := by\n have := Real.log_le_sub_one_of_pos (show (0:ℝ) < 1 + 512*ε^2/(D:ℝ) by linarith)\n linarith\n have hmnn : (0:ℝ) ≤ (m:ℝ) := Nat.cast_nonneg m\n have hfinal : (1:ℝ)/2 < (m:ℝ) * (512*ε^2/(D:ℝ)) := by\n have hl2 := Real.log_two_gt_d9\n have h5 : (m:ℝ) * Real.log (1 + 512*ε^2/(D:ℝ)) ≤ (m:ℝ) * (512*ε^2/(D:ℝ)) :=\n mul_le_mul_of_nonneg_left hlog2 hmnn\n linarith\n rw [mul_div_assoc'] at hfinal\n rw [lt_div_iff₀ hDpos] at hfinal\n linarith\n\ntheorem dro_delta_num {m : ℕ} {ε δ : ℝ} (hε0 : 0 < ε) (hε2 : ε^2 < 1/128)\n (hδ0 : 0 < δ) (hδ : δ < 1/8) (hp1 : (1/4) * (1-(8*ε)^2)^m ≤ δ) :\n Real.log (1/δ) ≤ 384 * m * ε^2 := by\n set y : ℝ := 64*ε^2 with hydef\n have hy0 : 0 < y := by rw [hydef]; positivity\n have hy2 : y < 1/2 := by rw [hydef]; linarith\n have hpowle : (1-y)^m ≤ 4*δ := by\n have h0 : (8*ε)^2 = y := by rw [hydef]; ring\n rw [h0] at hp1\n linarith\n have hexpb : Real.exp (-(2*y)) ≤ 1 - y := by\n have h1 : (1:ℝ) ≤ (1-y)*(1+2*y) := by nlinarith\n have h2 : (1+2*y) ≤ Real.exp (2*y) := by linarith [Real.add_one_le_exp (2*y)]\n have h4 : Real.exp (-(2*y)) * Real.exp (2*y) = 1 := by\n rw [← Real.exp_add]; simp\n have h5 : (1-y)*(1+2*y) ≤ (1-y)*Real.exp (2*y) :=\n mul_le_mul_of_nonneg_left h2 (by linarith)\n have h6 : Real.exp (-(2*y)) * Real.exp (2*y) ≤ (1-y)*Real.exp (2*y) := by\n rw [h4]; linarith\n exact le_of_mul_le_mul_right h6 (Real.exp_pos (2*y))\n have hexppow : Real.exp (-(2*y)*(m:ℝ)) ≤ 4*δ := by\n have h6 : (Real.exp (-(2*y)))^m ≤ (1-y)^m :=\n pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) hexpb m\n have h7 : (Real.exp (-(2*y)))^m = Real.exp (-(2*y)*(m:ℝ)) := by\n rw [← Real.exp_nat_mul]; ring_nf\n rw [h7] at h6\n linarith\n have hlogle : -(2*y)*(m:ℝ) ≤ Real.log (4*δ) := by\n have := Real.log_le_log (Real.exp_pos (-(2*y)*(m:ℝ))) hexppow\n rwa [Real.log_exp] at this\n have hsplit : Real.log (4*δ) = Real.log 4 + Real.log δ :=\n Real.log_mul (by norm_num) (ne_of_gt hδ0)\n have hinv : Real.log (1/δ) = -Real.log δ := by\n rw [one_div, Real.log_inv]\n have hlog4 : Real.log 4 = 2 * Real.log 2 := by\n rw [show (4:ℝ) = 2^2 by norm_num, Real.log_pow]; norm_num\n have hlog8 : Real.log 8 = 3 * Real.log 2 := by\n rw [show (8:ℝ) = 2^3 by norm_num, Real.log_pow]; norm_num\n have h8lt : Real.log 8 < Real.log (1/δ) := by\n refine Real.log_lt_log (by norm_num) ?_\n rw [lt_div_iff₀ hδ0]; linarith\n rw [hlog8] at h8lt\n have hgoal : Real.log (1/δ) ≤ Real.log 4 + 2*y*(m:ℝ) := by\n rw [hsplit] at hlogle\n rw [hinv]\n linarith\n rw [hlog4, hydef] at hgoal\n linarith\n\n/-- The `log(1/δ)/ε²` lower bound. -/\ntheorem dro_lb_delta {𝒳 : Type*} [MeasurableSpace 𝒳] {H : HypothesisClass 𝒳 Bool}\n {m : ℕ} {ρ ε δ : ℝ} (hρ : 0 < ρ) (hρ' : ρ < (3 - 2*Real.sqrt 2)/2)\n (hε0 : 0 < ε) (hε : ε < 1/(8*Real.sqrt 2)) (hδ0 : 0 < δ) (hδ : δ < 1/8)\n (x : 𝒳) (hshat : ∀ y : Bool, ∃ h ∈ H, h.f x = y)\n (hPAC : AgnosticPACAtSize H ρ ε δ m) :\n Real.log (1/δ) ≤ 384 * m * ε^2 := by\n have hs2 := dro_sqrt2_sq\n have hs0 := dro_sqrt2_pos\n have hslt := dro_sqrt2_lt\n have hsgt := dro_sqrt2_gt\n have hrw : (1:ℝ)/(8*Real.sqrt 2) = Real.sqrt 2/16 := by\n rw [div_eq_div_iff (by positivity) (by norm_num)]\n nlinarith [hs2]\n rw [hrw] at hε\n have hεb : 8*ε < Real.sqrt 2 / 2 := by linarith\n have hε2 : ε^2 < 1/128 := by nlinarith [hεb, hε0, hs2]\n have hr0 : (0:ℝ) < 8*ε := by linarith\n have hr : (8*ε) < 1 := by linarith\n have hρ8 : ρ ≤ 8 := by linarith\n have hcomp : (1+8*ε)*(1+2*ρ) ≤ 2 := by\n have h1 : 1 + 2*ρ < 4 - 2*Real.sqrt 2 := by linarith\n have h2 : 1 + 8*ε < 1 + Real.sqrt 2/2 := by linarith\n have h3 : (0:ℝ) < 1 + 2*ρ := by linarith\n have h4 : (0:ℝ) < 1 + Real.sqrt 2/2 := by linarith\n nlinarith [h1, h2, h3, h4, hs2]\n have hεr : ε < 8*ε := by linarith\n have hp1 := dro_part1 hr hr0 hρ hρ8 hcomp (le_of_lt hδ0) hε0 hεr x hshat hPAC\n exact dro_delta_num hε0 hε2 hδ0 hδ hp1\n\nend Helpers3\nsection Helpers4\n\nopen scoped ENNReal\n\n/-- If the VC dimension equals `d > 0`, some set of exactly `d` points is shattered. -/\ntheorem vc_shattered {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d:ℕ∞)) (hd : 0 < d) :\n ∃ c : Fin d → 𝒳, ∀ b : Fin d → Bool, ∃ h ∈ H, ∀ i, h.f (c i) = b i := by\n classical\n have hex : ∃ S : Finset 𝒳, Shatters H S ∧ S.card = d := by\n by_contra hcon\n push_neg at hcon\n have hle : VCDim H ≤ ((d-1 : ℕ) : ℕ∞) := by\n refine iSup_le (fun S => iSup_le (fun hS => ?_))\n have hcard_le : (S.card : ℕ∞) ≤ (d : ℕ∞) := by\n rw [← hvc]\n exact le_iSup₂ (f := fun (S : Finset 𝒳) (_ : Shatters H S) => (S.card : ℕ∞)) S hS\n have h1 : S.card ≤ d := by exact_mod_cast hcard_le\n have hne : S.card ≠ d := hcon S hS\n have h2 : S.card ≤ d - 1 := by omega\n exact_mod_cast Nat.cast_le.mpr h2\n rw [hvc] at hle\n have : d ≤ d - 1 := by exact_mod_cast hle\n omega\n obtain ⟨S, hS, hcard⟩ := hex\n let e : ↥S ≃ Fin d := S.equivFinOfCardEq hcard\n refine ⟨fun i => ((e.symm i : ↥S) : 𝒳), fun b => ?_⟩\n obtain ⟨h, hh, hf⟩ := hS (fun x => b (e x))\n refine ⟨h, hh, fun i => ?_⟩\n have := hf (e.symm i)\n simpa using this\n\n/-- Turning a bound valid for every admissible sample size into a bound on `n`. -/\ntheorem sample_complexity_lb {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n (ρ ε δ : ℝ) (n : ℕ) (L : ℝ)\n (hle : agnosticSampleComplexity H ρ ε δ ≤ (n : ℕ∞))\n (hbound : ∀ m : ℕ, AgnosticPACAtSize H ρ ε δ m → L ≤ (m:ℝ)) : L ≤ (n:ℝ) := by\n by_contra hcon\n push_neg at hcon\n have hlb : ((n+1 : ℕ) : ℕ∞) ≤ agnosticSampleComplexity H ρ ε δ := by\n refine le_sInf ?_\n rintro x ⟨m, rfl, hm⟩\n have hLm := hbound m hm\n have hnm : n < m := by\n have : (n:ℝ) < (m:ℝ) := lt_of_lt_of_le hcon hLm\n exact_mod_cast this\n exact_mod_cast Nat.cast_le.mpr (by omega : n+1 ≤ m)\n have h2 : ((n+1:ℕ) : ℕ∞) ≤ (n : ℕ∞) := le_trans hlb hle\n have h3 : n+1 ≤ n := by exact_mod_cast h2\n omega\n\nend Helpers4\n\n/-! ### Reduction of the upper bounds to ordinary finite-VC learning\n\nThe robust-risk arguments below are independent of the statistical learning theorem.\nThey isolate the sole remaining issue as an ordinary finite-VC PAC theorem with the\nsame outer-measure convention as `Measure` uses on arbitrary sets.\n-/\n\nnamespace Upper\n\nnoncomputable def ordinaryError {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) : ℝ :=\n (P {z : 𝒳 × Bool | h.f z.1 ≠ z.2}).toReal\n\nlemma error_correct_sum_one {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P] :\n ordinaryError h P + (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal = 1 := by\n have hsum := measure_add_measure_compl (μ := P) (meas_ne_set h)\n have hc : {z : 𝒳 × Bool | h.f z.1 = z.2} =\n {z : 𝒳 × Bool | h.f z.1 ≠ z.2}ᶜ := by\n ext z\n simp\n rw [hc]\n have h1 : P {z : 𝒳 × Bool | h.f z.1 ≠ z.2} ≠ ⊤ := measure_ne_top _ _\n have h2 : P ({z : 𝒳 × Bool | h.f z.1 ≠ z.2}ᶜ) ≠ ⊤ := measure_ne_top _ _\n have h3 := congrArg ENNReal.toReal hsum\n rw [ENNReal.toReal_add h1 h2] at h3\n simpa [ordinaryError] using h3\n\nlemma c2_ge_one (ρ : ℝ) (hρ : 0 ≤ ρ) : 1 ≤ c2 ρ := by\n rw [c2]\n have hs := Real.sq_sqrt (by linarith : (0 : ℝ) ≤ 1 + 2 * ρ)\n have hn := Real.sqrt_nonneg (1 + 2 * ρ)\n nlinarith\n\nlemma c2_gt_one (ρ : ℝ) (hρ : 0 < ρ) : 1 < c2 ρ := by\n exact one_lt_c2 hρ\n\nlemma zero_mem_etaDomain (ρ : ℝ) (hρ : 0 ≤ ρ) : 0 ∈ etaDomain ρ := by\n by_cases hρ0 : ρ = 0\n · simp [etaDomain, hρ0]\n · have hp : 0 < ρ := lt_of_le_of_ne hρ (Ne.symm hρ0)\n have hc : 0 < c2 ρ - 1 := sub_pos.mpr (c2_gt_one ρ hp)\n simp only [etaDomain, if_neg hρ0, Set.mem_Icc]\n constructor\n · have : 0 ≤ 1 / (c2 ρ - 1) := one_div_nonneg.mpr hc.le\n linarith\n · norm_num\n\nlemma eta_le_one (ρ : ℝ) (η : etaDomain ρ) : (η : ℝ) ≤ 1 := by\n by_cases hρ0 : ρ = 0\n · simpa [etaDomain, hρ0] using η.property\n · exact (by simpa [etaDomain, hρ0] using η.property :\n -(1 / (c2 ρ - 1)) ≤ (η : ℝ) ∧ (η : ℝ) ≤ 1).2\n\nlemma eta_lower {ρ : ℝ} (hρ : 0 < ρ) (η : etaDomain ρ) :\n -(1 / (c2 ρ - 1)) ≤ (η : ℝ) := by\n exact (by simpa [etaDomain, ne_of_gt hρ] using η.property :\n -(1 / (c2 ρ - 1)) ≤ (η : ℝ) ∧ (η : ℝ) ≤ 1).1\n\nlemma scalar_rms_add_eta_ge (p q η c : ℝ)\n (hp : 0 ≤ p) (hq : 0 ≤ q) (hpq : p + q = 1) (hc : 1 ≤ c) (hη : η ≤ 1) :\n p ≤ c * Real.sqrt\n (p * (max (1 - η) 0) ^ 2 + q * (max (0 - η) 0) ^ 2) + η := by\n have hp1 : p ≤ 1 := by linarith\n have hsqrt_nonneg :\n 0 ≤ Real.sqrt (p * (max (1 - η) 0) ^ 2 + q * (max (0 - η) 0) ^ 2) :=\n Real.sqrt_nonneg _\n have hc_mul :\n Real.sqrt (p * (max (1 - η) 0) ^ 2 + q * (max (0 - η) 0) ^ 2) ≤\n c * Real.sqrt (p * (max (1 - η) 0) ^ 2 + q * (max (0 - η) 0) ^ 2) := by\n nlinarith\n suffices p ≤ Real.sqrt\n (p * (max (1 - η) 0) ^ 2 + q * (max (0 - η) 0) ^ 2) + η by\n linarith\n by_cases hη0 : 0 ≤ η\n · rw [max_eq_left (sub_nonneg.mpr hη), max_eq_right (by linarith)]\n by_cases hpη : p ≤ η\n · linarith [Real.sqrt_nonneg (p * (1 - η) ^ 2 + q * 0 ^ 2)]\n · have hηp : η ≤ p := le_of_not_ge hpη\n have hηsq : η ^ 2 ≤ p := by nlinarith [sq_nonneg (p - η)]\n have hsquare : (p - η) ^ 2 ≤ p * (1 - η) ^ 2 := by\n nlinarith [mul_nonneg (sub_nonneg.mpr hp1) (sub_nonneg.mpr hηsq)]\n have hsqrt : p - η ≤ Real.sqrt (p * (1 - η) ^ 2 + q * 0 ^ 2) := by\n rw [Real.le_sqrt (by linarith) (by positivity)]\n simpa using hsquare\n linarith\n · have hηneg : η < 0 := lt_of_not_ge hη0\n rw [max_eq_left (by linarith), max_eq_left (by linarith)]\n have hsquare : (p - η) ^ 2 ≤ p * (1 - η) ^ 2 + q * (0 - η) ^ 2 := by\n nlinarith [mul_nonneg hp (by linarith : 0 ≤ 1 - p)]\n have hsqrt : p - η ≤ Real.sqrt (p * (1 - η) ^ 2 + q * (0 - η) ^ 2) := by\n rw [Real.le_sqrt (by linarith) (by positivity)]\n exact hsquare\n linarith\n\nlemma robustRisk_ge_error {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (ρ : ℝ) (hρ : 0 ≤ ρ) : ordinaryError h P ≤ robustRisk h P ρ := by\n let p : ℝ := ordinaryError h P\n let q : ℝ := (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal\n have hp : 0 ≤ p := ENNReal.toReal_nonneg\n have hq : 0 ≤ q := ENNReal.toReal_nonneg\n have hpq : p + q = 1 := error_correct_sum_one h P\n let η0 : etaDomain ρ := ⟨0, zero_mem_etaDomain ρ hρ⟩\n letI : Nonempty (etaDomain ρ) := ⟨η0⟩\n rw [robustRisk]\n apply le_ciInf\n intro η\n exact scalar_rms_add_eta_ge p q (η : ℝ) (c2 ρ) hp hq hpq\n (c2_ge_one ρ hρ) (eta_le_one ρ η)\n\nnoncomputable def scalarRobustRisk (ρ p : ℝ) : ℝ :=\n ⨅ η : etaDomain ρ,\n c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2\n + (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ)\n\nlemma robustRisk_eq_scalar {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (ρ : ℝ) : robustRisk h P ρ = scalarRobustRisk ρ (ordinaryError h P) := by\n have hsum := error_correct_sum_one h P\n have hcorrect :\n (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal = 1 - ordinaryError h P := by\n linarith\n unfold robustRisk scalarRobustRisk ordinaryError\n congr 1\n funext η\n rw [hcorrect]\n simp [ordinaryError]\n\nlemma scalarObjective_bddBelow {ρ p : ℝ} (hρ : 0 < ρ) :\n BddBelow (Set.range fun η : etaDomain ρ =>\n c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2\n + (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ)) := by\n refine ⟨-(1 / (c2 ρ - 1)), ?_⟩\n rintro _ ⟨η, rfl⟩\n have hs : 0 ≤ c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2 +\n (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2) := by\n exact mul_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _)\n linarith [eta_lower hρ η]\n\nlemma scalarRobustRisk_le_objective {ρ p : ℝ} (hρ : 0 < ρ)\n (η : etaDomain ρ) :\n scalarRobustRisk ρ p ≤\n c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2\n + (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ) := by\n exact ciInf_le (scalarObjective_bddBelow hρ) η\n\nlemma le_scalarRobustRisk {ρ p a : ℝ} (hρ : 0 < ρ)\n (ha : ∀ η : etaDomain ρ,\n a ≤ c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2\n + (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ)) :\n a ≤ scalarRobustRisk ρ p := by\n let η0 : etaDomain ρ := ⟨0, zero_mem_etaDomain ρ hρ.le⟩\n letI : Nonempty (etaDomain ρ) := ⟨η0⟩\n exact le_ciInf ha\n\nnoncomputable def robustLip (ρ : ℝ) : ℝ :=\n c2 ρ * (1 + 1 / (c2 ρ - 1))\n\nlemma robustLip_pos {ρ : ℝ} (hρ : 0 < ρ) : 0 < robustLip ρ := by\n have hc : 1 < c2 ρ := c2_gt_one ρ hρ\n have hc0 : 0 < c2 ρ := lt_trans zero_lt_one hc\n have hden : 0 < c2 ρ - 1 := sub_pos.mpr hc\n have hinv : 0 < 1 / (c2 ρ - 1) := one_div_pos.mpr hden\n unfold robustLip\n exact mul_pos hc0 (by linarith)\n\nlemma one_lt_robustLip {ρ : ℝ} (hρ : 0 < ρ) : 1 < robustLip ρ := by\n have hc : 1 < c2 ρ := c2_gt_one ρ hρ\n have hden : 0 < c2 ρ - 1 := sub_pos.mpr hc\n have hinv : 0 < 1 / (c2 ρ - 1) := one_div_pos.mpr hden\n have hb : 1 < 1 + 1 / (c2 ρ - 1) := by linarith\n have hmul : 1 * (1 + 1 / (c2 ρ - 1)) <\n c2 ρ * (1 + 1 / (c2 ρ - 1)) :=\n mul_lt_mul_of_pos_right hc (by linarith)\n unfold robustLip\n linarith\n\nlemma sqrt_add_le' (x y : ℝ) (hx : 0 ≤ x) (hy : 0 ≤ y) :\n Real.sqrt (x + y) ≤ Real.sqrt x + Real.sqrt y := by\n rw [Real.sqrt_le_iff]\n refine ⟨by positivity, ?_⟩\n have h1 : Real.sqrt x ^ 2 = x := Real.sq_sqrt hx\n have h2 : Real.sqrt y ^ 2 = y := Real.sq_sqrt hy\n have h3 : (0 : ℝ) ≤ Real.sqrt x * Real.sqrt y := by positivity\n nlinarith\n\nlemma objective_mono_lip {ρ p q : ℝ} (hρ : 0 < ρ)\n (hp0 : 0 ≤ p) (hpq : p ≤ q) (hq1 : q ≤ 1) (η : etaDomain ρ) :\n c2 ρ * Real.sqrt\n (q * (max (1 - (η : ℝ)) 0) ^ 2\n + (1 - q) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ)\n ≤\n c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2\n + (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ)\n + robustLip ρ * Real.sqrt (q - p) := by\n have hc : 0 ≤ c2 ρ := Real.sqrt_nonneg _\n have hc1 : 1 < c2 ρ := c2_gt_one ρ hρ\n have hL0 : 0 ≤ 1 / (c2 ρ - 1) := one_div_nonneg.mpr (by linarith)\n obtain ⟨hηlo, hηhi⟩ := (by\n simpa [etaDomain, ne_of_gt hρ] using η.property :\n -(1 / (c2 ρ - 1)) ≤ (η : ℝ) ∧ (η : ℝ) ≤ 1)\n set A : ℝ := (max (1 - (η : ℝ)) 0) ^ 2 with hA\n set B : ℝ := (max (0 - (η : ℝ)) 0) ^ 2 with hB\n have hA0 : 0 ≤ A := sq_nonneg _\n have hB0 : 0 ≤ B := sq_nonneg _\n have hBA : B ≤ A := by\n rcases le_or_gt 0 (η : ℝ) with hη0 | hη0\n · have hBz : max (0 - (η : ℝ)) 0 = 0 := max_eq_right (by linarith)\n rw [hA, hB, hBz]\n simpa using sq_nonneg (max (1 - (η : ℝ)) 0)\n · have hBv : max (0 - (η : ℝ)) 0 = -(η : ℝ) := by\n rw [zero_sub, max_eq_left (by linarith)]\n have hAv : max (1 - (η : ℝ)) 0 = 1 - (η : ℝ) :=\n max_eq_left (by linarith)\n rw [hA, hB, hAv, hBv]\n nlinarith\n have hmaxA : max (1 - (η : ℝ)) 0 ≤ 1 + 1 / (c2 ρ - 1) := by\n rcases max_cases (1 - (η : ℝ)) 0 with ⟨h, _⟩ | ⟨h, _⟩ <;> rw [h] <;> linarith\n have hmaxA0 : 0 ≤ max (1 - (η : ℝ)) 0 := le_max_right _ _\n have hA_bound : A ≤ (1 + 1 / (c2 ρ - 1)) ^ 2 := by\n rw [hA]\n nlinarith\n set X : ℝ := p * A + (1 - p) * B with hX\n set Y : ℝ := q * A + (1 - q) * B with hY\n have hX0 : 0 ≤ X := by\n rw [hX]\n exact add_nonneg (mul_nonneg hp0 hA0) (mul_nonneg (by linarith) hB0)\n have hdiff0 : 0 ≤ (q - p) * (A - B) :=\n mul_nonneg (sub_nonneg.mpr hpq) (sub_nonneg.mpr hBA)\n have hYX : Y = X + (q - p) * (A - B) := by\n rw [hX, hY]\n ring\n have hsqrt : Real.sqrt Y ≤ Real.sqrt X + Real.sqrt ((q - p) * (A - B)) := by\n rw [hYX]\n exact sqrt_add_le' _ _ hX0 hdiff0\n have hdiff_bound : (q - p) * (A - B) ≤\n (1 + 1 / (c2 ρ - 1)) ^ 2 * (q - p) := by\n have hqp0 : 0 ≤ q - p := sub_nonneg.mpr hpq\n nlinarith\n have hsqrt_bound : Real.sqrt ((q - p) * (A - B)) ≤\n (1 + 1 / (c2 ρ - 1)) * Real.sqrt (q - p) := by\n calc\n Real.sqrt ((q - p) * (A - B))\n ≤ Real.sqrt ((1 + 1 / (c2 ρ - 1)) ^ 2 * (q - p)) :=\n Real.sqrt_le_sqrt hdiff_bound\n _ = (1 + 1 / (c2 ρ - 1)) * Real.sqrt (q - p) := by\n rw [Real.sqrt_mul (sq_nonneg _), Real.sqrt_sq (by linarith)]\n unfold robustLip\n rw [hX, hY] at hsqrt\n nlinarith [mul_le_mul_of_nonneg_left hsqrt_bound hc]\n\nlemma scalarRobustRisk_mono {ρ p q : ℝ} (hρ : 0 < ρ)\n (hp0 : 0 ≤ p) (hpq : p ≤ q) (hq1 : q ≤ 1) :\n scalarRobustRisk ρ p ≤ scalarRobustRisk ρ q := by\n have hc : 0 ≤ c2 ρ := Real.sqrt_nonneg _\n apply le_scalarRobustRisk hρ\n intro η\n have hB_le_A : (max (0 - (η : ℝ)) 0) ^ 2 ≤\n (max (1 - (η : ℝ)) 0) ^ 2 := by\n rcases le_or_gt 0 (η : ℝ) with hη0 | hη0\n · rw [max_eq_right (by linarith : 0 - (η : ℝ) ≤ 0)]\n simpa using sq_nonneg (max (1 - (η : ℝ)) 0)\n · rw [max_eq_left (by linarith : 0 ≤ 0 - (η : ℝ)),\n max_eq_left (by linarith : 0 ≤ 1 - (η : ℝ))]\n nlinarith\n have hinside :\n p * (max (1 - (η : ℝ)) 0) ^ 2 +\n (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2 ≤\n q * (max (1 - (η : ℝ)) 0) ^ 2 +\n (1 - q) * (max (0 - (η : ℝ)) 0) ^ 2 := by\n nlinarith\n calc\n scalarRobustRisk ρ p ≤\n c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2 +\n (1 - p) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ) :=\n scalarRobustRisk_le_objective hρ η\n _ ≤ c2 ρ * Real.sqrt\n (q * (max (1 - (η : ℝ)) 0) ^ 2 +\n (1 - q) * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ) := by\n nlinarith [mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hinside) hc]\n\nlemma scalarRobustRisk_lip {ρ p q : ℝ} (hρ : 0 < ρ)\n (hp0 : 0 ≤ p) (hpq : p ≤ q) (hq1 : q ≤ 1) :\n scalarRobustRisk ρ q ≤\n scalarRobustRisk ρ p + robustLip ρ * Real.sqrt (q - p) := by\n have hq0 : 0 ≤ q := hp0.trans hpq\n have hshift : scalarRobustRisk ρ q - robustLip ρ * Real.sqrt (q - p) ≤\n scalarRobustRisk ρ p := by\n apply le_scalarRobustRisk hρ\n intro η\n have hqobj := scalarRobustRisk_le_objective (ρ := ρ) (p := q) hρ η\n have hlip := objective_mono_lip hρ hp0 hpq hq1 η\n linarith\n linarith\n\nlemma ordinaryError_le_one {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P] :\n ordinaryError h P ≤ 1 := by\n have hm : P {z : 𝒳 × Bool | h.f z.1 ≠ z.2} ≤ P Set.univ :=\n measure_mono (Set.subset_univ _)\n rw [measure_univ] at hm\n have ht := ENNReal.toReal_mono ENNReal.one_ne_top hm\n simpa [ordinaryError] using ht\n\ndef OrdinaryAgnosticPACAtSize {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ε δ : ℝ) (n : ℕ) : Prop :=\n ∃ A : (Fin n → 𝒳 × Bool) → Predictor 𝒳 Bool,\n ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (Measure.pi fun _ : Fin n => P)\n {S : Fin n → 𝒳 × Bool |\n (⨅ h : ↥H, ordinaryError (h : Predictor 𝒳 Bool) P) + ε <\n ordinaryError (A S) P} ≤ ENNReal.ofReal δ\n\ndef OrdinaryRealizablePACAtSize {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ε δ : ℝ) (n : ℕ) : Prop :=\n ∃ A : (Fin n → 𝒳 × Bool) → Predictor 𝒳 Bool,\n ∀ (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P],\n (∃ hstar ∈ H, ordinaryError hstar P = 0) →\n (Measure.pi fun _ : Fin n => P)\n {S : Fin n → 𝒳 × Bool | ε < ordinaryError (A S) P} ≤ ENNReal.ofReal δ\n\n/-- A fully degenerate finite-class case of the ordinary learning theorem: a\nsingleton class needs no samples, both agnostically and realizably. Notice that\nthis also avoids any measurability issue for the failure event: it is empty. -/\nlemma ordinary_singleton_PAC\n {𝒳 : Type*} [MeasurableSpace 𝒳] (h₀ : Predictor 𝒳 Bool)\n {γ δ : ℝ} (hγ : 0 ≤ γ) :\n OrdinaryAgnosticPACAtSize ({h₀} : HypothesisClass 𝒳 Bool) γ δ 0 ∧\n OrdinaryRealizablePACAtSize ({h₀} : HypothesisClass 𝒳 Bool) γ δ 0 := by\n constructor\n · refine ⟨fun _ => h₀, ?_⟩\n intro P _\n have hinf :\n (⨅ h : ↥({h₀} : HypothesisClass 𝒳 Bool),\n ordinaryError (h : Predictor 𝒳 Bool) P) = ordinaryError h₀ P := by\n simp\n have hempty :\n {S : Fin 0 → 𝒳 × Bool |\n (⨅ h : ↥({h₀} : HypothesisClass 𝒳 Bool),\n ordinaryError (h : Predictor 𝒳 Bool) P) + γ <\n ordinaryError h₀ P} = ∅ := by\n apply Set.eq_empty_iff_forall_not_mem.mpr\n intro S hS\n simp only [Set.mem_setOf_eq] at hS\n rw [hinf] at hS\n linarith\n rw [hempty, measure_empty]\n exact bot_le\n · refine ⟨fun _ => h₀, ?_⟩\n intro P _ hreal\n rcases hreal with ⟨hstar, hhstar, hz⟩\n have heq : hstar = h₀ := by simpa using hhstar\n subst hstar\n have hempty :\n {S : Fin 0 → 𝒳 × Bool | γ < ordinaryError h₀ P} = ∅ := by\n apply Set.eq_empty_iff_forall_not_mem.mpr\n intro S hS\n simp only [Set.mem_setOf_eq] at hS\n rw [hz] at hS\n exact (not_lt_of_ge hγ) hS\n rw [hempty, measure_empty]\n exact bot_le\n\n/-! The same idea extends to every genuinely finite hypothesis class. These\nlemmas are intentionally phrased without a VC estimate: their purpose is to\nrecord the complete measure-theoretic finite-union argument which survives\nwithout any class-level measurability assumption. -/\n\nnoncomputable def finiteConsistentLearner\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (F : Finset (Predictor 𝒳 Bool)) (hdefault : Predictor 𝒳 Bool)\n {n : ℕ} (S : Fin n → 𝒳 × Bool) : Predictor 𝒳 Bool :=\n if hex : ∃ h ∈ F, ∀ i, h.f (S i).1 = (S i).2 then Classical.choose hex else hdefault\n\nlemma finiteConsistentLearner_mem\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (F : Finset (Predictor 𝒳 Bool)) (hdefault : Predictor 𝒳 Bool)\n {n : ℕ} (S : Fin n → 𝒳 × Bool)\n (hex : ∃ h ∈ F, ∀ i, h.f (S i).1 = (S i).2) :\n finiteConsistentLearner F hdefault S ∈ F := by\n rw [finiteConsistentLearner, dif_pos hex]\n exact (Classical.choose_spec hex).1\n\nlemma finiteConsistentLearner_correct\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (F : Finset (Predictor 𝒳 Bool)) (hdefault : Predictor 𝒳 Bool)\n {n : ℕ} (S : Fin n → 𝒳 × Bool)\n (hex : ∃ h ∈ F, ∀ i, h.f (S i).1 = (S i).2) :\n ∀ i, (finiteConsistentLearner F hdefault S).f (S i).1 = (S i).2 := by\n rw [finiteConsistentLearner, dif_pos hex]\n exact (Classical.choose_spec hex).2\n\ndef finiteAllCorrect\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (h : Predictor 𝒳 Bool) : Set (Fin n → 𝒳 × Bool) :=\n {S | ∀ i, h.f (S i).1 = (S i).2}\n\nlemma finiteAllCorrect_eq_pi\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (h : Predictor 𝒳 Bool) :\n finiteAllCorrect (n := n) h = Set.univ.pi fun _ : Fin n =>\n {z : 𝒳 × Bool | h.f z.1 = z.2} := by\n ext S\n simp [finiteAllCorrect, Set.mem_pi]\n\nlemma measure_finiteAllCorrect\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (h : Predictor 𝒳 Bool) :\n (Measure.pi fun _ : Fin n => P) (finiteAllCorrect (n := n) h) =\n (P {z : 𝒳 × Bool | h.f z.1 = z.2}) ^ n := by\n rw [finiteAllCorrect_eq_pi, Measure.pi_pi]\n simp\n\nlemma measure_finiteAllCorrect_compl_zero\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (h : Predictor 𝒳 Bool)\n (hz : P {z : 𝒳 × Bool | h.f z.1 ≠ z.2} = 0) :\n (Measure.pi fun _ : Fin n => P) (finiteAllCorrect (n := n) h)ᶜ = 0 := by\n have hcorrect : P {z : 𝒳 × Bool | h.f z.1 = z.2} = 1 := by\n have hc : {z : 𝒳 × Bool | h.f z.1 = z.2} =\n {z : 𝒳 × Bool | h.f z.1 ≠ z.2}ᶜ := by\n ext z\n simp\n rw [hc, measure_compl (meas_ne_set h) (measure_ne_top _ _), hz, measure_univ]\n simp\n have hall :\n (Measure.pi fun _ : Fin n => P) (finiteAllCorrect (n := n) h) = 1 := by\n rw [measure_finiteAllCorrect, hcorrect]\n simp\n rw [measure_compl]\n · rw [hall, measure_univ]\n simp\n · rw [finiteAllCorrect_eq_pi]\n exact MeasurableSet.univ_pi fun _ => meas_eq_set h\n · exact measure_ne_top _ _\n\nlemma finite_realizable_failure_subset\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (F : Finset (Predictor 𝒳 Bool)) (hdefault hstar : Predictor 𝒳 Bool)\n (hhstar : hstar ∈ F) (P : Measure (𝒳 × Bool)) (α : ℝ) :\n {S | α < ordinaryError (finiteConsistentLearner F hdefault S) P} ⊆\n (finiteAllCorrect (n := n) hstar)ᶜ ∪\n ⋃ h ∈ (F.filter fun h => α < ordinaryError h P),\n finiteAllCorrect (n := n) h := by\n intro S hS\n by_cases hg : S ∈ finiteAllCorrect (n := n) hstar\n · right\n have hex : ∃ h ∈ F, ∀ i, h.f (S i).1 = (S i).2 := ⟨hstar, hhstar, hg⟩\n let h := finiteConsistentLearner F hdefault S\n have hhF : h ∈ F := finiteConsistentLearner_mem F hdefault S hex\n have hhbad : h ∈ F.filter fun h => α < ordinaryError h P := by\n simp only [Finset.mem_filter]\n exact ⟨hhF, hS⟩\n exact Set.mem_iUnion.mpr ⟨h, Set.mem_iUnion.mpr\n ⟨hhbad, finiteConsistentLearner_correct F hdefault S hex⟩⟩\n · exact Or.inl hg\n\nlemma finite_bad_union_measure_le\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (F : Finset (Predictor 𝒳 Bool))\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n {α : ℝ} (hα0 : 0 ≤ α) :\n (Measure.pi fun _ : Fin n => P)\n (⋃ h ∈ (F.filter fun h => α < ordinaryError h P),\n finiteAllCorrect (n := n) h) ≤\n F.card * (ENNReal.ofReal (1 - α)) ^ n := by\n classical\n let G := F.filter fun h => α < ordinaryError h P\n calc\n (Measure.pi fun _ : Fin n => P) (⋃ h ∈ G, finiteAllCorrect (n := n) h)\n ≤ ∑ h ∈ G, (Measure.pi fun _ : Fin n => P)\n (finiteAllCorrect (n := n) h) := measure_biUnion_finset_le G _\n _ ≤ ∑ _h ∈ G, (ENNReal.ofReal (1 - α)) ^ n := by\n gcongr with h hh\n rw [measure_finiteAllCorrect]\n apply pow_le_pow_left'\n have hbad : α < ordinaryError h P := (Finset.mem_filter.mp hh).2\n have hsum := error_correct_sum_one h P\n have herr_le_one := ordinaryError_le_one h P\n have hcorrectR :\n (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal < 1 - α := by\n linarith\n have hcorrecttop : P {z : 𝒳 × Bool | h.f z.1 = z.2} ≠ ⊤ := measure_ne_top _ _\n apply (ENNReal.toReal_le_toReal hcorrecttop ENNReal.ofReal_ne_top).mp\n rw [ENNReal.toReal_ofReal (by linarith : 0 ≤ 1 - α)]\n exact hcorrectR.le\n _ = G.card * (ENNReal.ofReal (1 - α)) ^ n := by simp\n _ ≤ F.card * (ENNReal.ofReal (1 - α)) ^ n := by\n gcongr\n exact Finset.filter_subset _ _\n\nlemma finite_class_realizable_at_size\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (F : Finset (Predictor 𝒳 Bool))\n (hdefault : Predictor 𝒳 Bool) (hdefault_mem : hdefault ∈ F)\n {α δ : ℝ} (hα0 : 0 ≤ α)\n (hn : F.card * (ENNReal.ofReal (1 - α)) ^ n ≤ ENNReal.ofReal δ) :\n OrdinaryRealizablePACAtSize (↑F : HypothesisClass 𝒳 Bool) α δ n := by\n refine ⟨finiteConsistentLearner F hdefault, ?_⟩\n intro P _ hreal\n obtain ⟨hstar, hhstar, hz⟩ := hreal\n have hz' : P {z : 𝒳 × Bool | hstar.f z.1 ≠ z.2} = 0 := by\n have hor := (ENNReal.toReal_eq_zero_iff _).mp (by\n simpa [ordinaryError] using hz)\n exact hor.resolve_right (measure_ne_top _ _)\n calc\n (Measure.pi fun _ : Fin n => P)\n {S | α < ordinaryError (finiteConsistentLearner F hdefault S) P}\n ≤ (Measure.pi fun _ : Fin n => P)\n ((finiteAllCorrect (n := n) hstar)ᶜ ∪\n ⋃ h ∈ (F.filter fun h => α < ordinaryError h P),\n finiteAllCorrect (n := n) h) :=\n measure_mono (finite_realizable_failure_subset F hdefault hstar hhstar P α)\n _ ≤ (Measure.pi fun _ : Fin n => P) (finiteAllCorrect (n := n) hstar)ᶜ +\n (Measure.pi fun _ : Fin n => P)\n (⋃ h ∈ (F.filter fun h => α < ordinaryError h P),\n finiteAllCorrect (n := n) h) := measure_union_le _ _\n _ ≤ 0 + F.card * (ENNReal.ofReal (1 - α)) ^ n := by\n gcongr\n · exact (measure_finiteAllCorrect_compl_zero P hstar hz').le\n · exact finite_bad_union_measure_le F P hα0\n _ ≤ ENNReal.ofReal δ := by simpa using hn\n\n/-- Every nonempty finite class is realizably PAC learnable, with no\nmeasurability or separability assumption on the class as a family. -/\nlemma finite_class_ordinary_realizable_PAC\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (hfin : H.Finite) (hH : H.Nonempty)\n {α δ : ℝ} (hα0 : 0 < α) (hα1 : α < 1) (hδ0 : 0 < δ) :\n ∃ n : ℕ, OrdinaryRealizablePACAtSize H α δ n := by\n classical\n let F : Finset (Predictor 𝒳 Bool) := hfin.toFinset\n let hdefault : Predictor 𝒳 Bool := Classical.choose hH\n have hdefault_mem : hdefault ∈ F := by\n simpa [F, hdefault] using Classical.choose_spec hH\n have hq : ENNReal.ofReal (1 - α) < 1 := ENNReal.ofReal_lt_one.mpr (by linarith)\n have hd : 0 < ENNReal.ofReal δ := ENNReal.ofReal_pos.mpr hδ0\n have ht : Filter.Tendsto\n (fun n : ℕ => (F.card : ℝ≥0∞) * (ENNReal.ofReal (1 - α)) ^ n)\n Filter.atTop (nhds 0) := by\n simpa using ENNReal.Tendsto.const_mul (a := (F.card : ℝ≥0∞))\n (ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hq)\n (Or.inr (by simp : (F.card : ℝ≥0∞) ≠ ⊤))\n have hev : Filter.Eventually\n (fun n => (F.card : ℝ≥0∞) * (ENNReal.ofReal (1 - α)) ^ n <\n ENNReal.ofReal δ) Filter.atTop :=\n (tendsto_order.1 ht).2 _ hd\n obtain ⟨N, hN⟩ := Filter.eventually_atTop.1 hev\n refine ⟨N, ?_⟩\n rw [← hfin.coe_toFinset]\n apply finite_class_realizable_at_size F hdefault hdefault_mem hα0.le\n exact (hN N le_rfl).le\n\nnoncomputable def zeroOneLoss\n {𝒳 : Type*} [MeasurableSpace 𝒳] (h : Predictor 𝒳 Bool) :\n 𝒳 × Bool → ℝ :=\n {z : 𝒳 × Bool | h.f z.1 ≠ z.2}.indicator fun _ => 1\n\nlemma zeroOneLoss_measurable\n {𝒳 : Type*} [MeasurableSpace 𝒳] (h : Predictor 𝒳 Bool) :\n Measurable (zeroOneLoss h) := by\n exact measurable_const.indicator (meas_ne_set h)\n\nlemma zeroOneLoss_nonneg\n {𝒳 : Type*} [MeasurableSpace 𝒳] (h : Predictor 𝒳 Bool)\n (z : 𝒳 × Bool) : 0 ≤ zeroOneLoss h z := by\n by_cases hz : h.f z.1 ≠ z.2 <;> simp [zeroOneLoss, hz]\n\nlemma zeroOneLoss_le_one\n {𝒳 : Type*} [MeasurableSpace 𝒳] (h : Predictor 𝒳 Bool)\n (z : 𝒳 × Bool) : zeroOneLoss h z ≤ 1 := by\n by_cases hz : h.f z.1 ≠ z.2 <;> simp [zeroOneLoss, hz]\n\nlemma integral_zeroOneLoss\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) :\n ∫ z, zeroOneLoss h z ∂P = ordinaryError h P := by\n simpa [zeroOneLoss, ordinaryError, Measure.real] using\n (integral_indicator_one (μ := P) (meas_ne_set h))\n\nnoncomputable def finiteERM\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (F : Finset (Predictor 𝒳 Bool)) (hdefault : Predictor 𝒳 Bool)\n {n : ℕ} (S : Fin n ��� 𝒳 × Bool) : Predictor 𝒳 Bool :=\n if hF : F.Nonempty then\n Classical.choose (Finset.exists_min_image F\n (fun h => ∑ i, zeroOneLoss h (S i)) hF)\n else hdefault\n\nlemma finiteERM_mem\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (F : Finset (Predictor 𝒳 Bool)) (hdefault : Predictor 𝒳 Bool)\n {n : ℕ} (S : Fin n → 𝒳 × Bool) (hF : F.Nonempty) :\n finiteERM F hdefault S ∈ F := by\n rw [finiteERM, dif_pos hF]\n exact (Classical.choose_spec (Finset.exists_min_image F\n (fun h => ∑ i, zeroOneLoss h (S i)) hF)).1\n\nlemma finiteERM_le\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (F : Finset (Predictor 𝒳 Bool)) (hdefault : Predictor 𝒳 Bool)\n {n : ℕ} (S : Fin n → 𝒳 × Bool) (hF : F.Nonempty)\n (g : Predictor 𝒳 Bool) (hg : g ∈ F) :\n (∑ i, zeroOneLoss (finiteERM F hdefault S) (S i)) ≤\n ∑ i, zeroOneLoss g (S i) := by\n rw [finiteERM, dif_pos hF]\n exact (Classical.choose_spec (Finset.exists_min_image F\n (fun h => ∑ i, zeroOneLoss h (S i)) hF)).2 g hg\n\nlemma bounded_sum_upper\n {Z : Type*} [MeasurableSpace Z] (P : Measure Z) [IsProbabilityMeasure P]\n {n : ℕ} (f : Z → ℝ) (hf : Measurable f) (p t : ℝ)\n (hp0 : 0 ≤ p) (hp1 : p ≤ 1) (ht : 0 ≤ t)\n (hf0 : ∀ z, 0 ≤ f z) (hf1 : ∀ z, f z ≤ 1)\n (hint : ∫ z, f z ∂P = p) :\n (Measure.pi fun _ : Fin n => P).real\n {S | (n : ℝ) * t ≤ (∑ i, f (S i)) - (n : ℝ) * p} ≤\n Real.exp (-((n : ℝ) * t) ^ 2 / (2 * n)) := by\n let X : Fin n → (Fin n → Z) → ℝ := fun i S => f (S i) - p\n have hXm (i : Fin n) : Measurable (X i) :=\n (hf.comp (measurable_pi_apply i)).sub measurable_const\n have hindep : ProbabilityTheory.iIndepFun X (Measure.pi fun _ : Fin n => P) := by\n exact ProbabilityTheory.iIndepFun_pi (X := fun _ z => f z - p)\n (fun _ => (hf.sub measurable_const).aemeasurable)\n have hsub (i : Fin n) : ProbabilityTheory.HasSubgaussianMGF (X i) 1\n (Measure.pi fun _ : Fin n => P) := by\n have hb : ∀ᵐ S ∂(Measure.pi fun _ : Fin n => P), X i S ∈ Set.Icc (-1 : ℝ) 1 :=\n Filter.Eventually.of_forall fun S => by\n dsimp [X]\n exact ⟨by linarith [hf0 (S i)], by linarith [hf1 (S i)]⟩\n have hcenter := ProbabilityTheory.hasSubgaussianMGF_of_mem_Icc\n (hXm i).aemeasurable hb\n have hfint : Integrable f P :=\n Integrable.of_mem_Icc 0 1 hf.aemeasurable\n (Filter.Eventually.of_forall fun z => ⟨hf0 z, hf1 z⟩)\n have hXi : ∫ S, X i S ∂(Measure.pi fun _ : Fin n => P) = 0 := by\n rw [show X i = fun S => f (S i) - p by rfl, integral_sub]\n · rw [integral_comp_eval hf.aestronglyMeasurable, hint]\n simp\n · exact integrable_comp_eval hfint\n · exact integrable_const _\n convert hcenter using 1 <;> simp [hXi] <;> norm_num\n have h := ProbabilityTheory.HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun\n (s := Finset.univ) (ε := (n : ℝ) * t) hindep (c := fun _ => 1)\n (fun i _ => hsub i) (mul_nonneg (Nat.cast_nonneg n) ht)\n simpa [X, Finset.sum_sub_distrib] using h\n\ndef finiteDeviation\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) (t : ℝ) :\n Set (Fin n → 𝒳 × Bool) :=\n {S | (n : ℝ) * t ≤\n (∑ i, zeroOneLoss h (S i)) - (n : ℝ) * ordinaryError h P} ∪\n {S | (n : ℝ) * t ≤\n (∑ i, (1 - zeroOneLoss h (S i))) -\n (n : ℝ) * (1 - ordinaryError h P)}\n\nlemma finiteDeviation_measurable\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) (t : ℝ) :\n MeasurableSet (finiteDeviation (n := n) h P t) := by\n unfold finiteDeviation\n have hsum : Measurable (fun S : Fin n → 𝒳 × Bool =>\n ∑ i, zeroOneLoss h (S i)) := by\n apply Finset.measurable_sum\n intro i _\n exact (zeroOneLoss_measurable h).comp (measurable_pi_apply i)\n have hsumc : Measurable (fun S : Fin n → 𝒳 × Bool =>\n ∑ i, (1 - zeroOneLoss h (S i))) := by\n apply Finset.measurable_sum\n intro i _\n exact measurable_const.sub\n ((zeroOneLoss_measurable h).comp (measurable_pi_apply i))\n exact (measurableSet_le measurable_const (hsum.sub measurable_const)).union\n (measurableSet_le measurable_const (hsumc.sub measurable_const))\n\nlemma measure_finiteDeviation_le\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (h : Predictor 𝒳 Bool) (t : ℝ) (hn : 0 < n) (ht : 0 ≤ t) :\n (Measure.pi fun _ : Fin n => P) (finiteDeviation (n := n) h P t) ≤\n 2 * (ENNReal.ofReal (Real.exp (-t ^ 2 / 2))) ^ n := by\n let p : ℝ := ordinaryError h P\n let f : 𝒳 × Bool → ℝ := zeroOneLoss h\n let g : 𝒳 × Bool → ℝ := fun z => 1 - zeroOneLoss h z\n let Epos : Set (Fin n → 𝒳 × Bool) :=\n {S | (n : ℝ) * t ≤ (∑ i, f (S i)) - (n : ℝ) * p}\n let Eneg : Set (Fin n → 𝒳 × Bool) :=\n {S | (n : ℝ) * t ≤ (∑ i, g (S i)) - (n : ℝ) * (1 - p)}\n have hp0 : 0 ≤ p := ENNReal.toReal_nonneg\n have hp1 : p ≤ 1 := ordinaryError_le_one h P\n have hfmeas : Measurable f := zeroOneLoss_measurable h\n have hgmeas : Measurable g := measurable_const.sub (zeroOneLoss_measurable h)\n have hf0 : ∀ z, 0 ≤ f z := zeroOneLoss_nonneg h\n have hf1 : ∀ z, f z ≤ 1 := zeroOneLoss_le_one h\n have hg0 : ∀ z, 0 ≤ g z := fun z => by dsimp [g]; linarith [hf1 z]\n have hg1 : ∀ z, g z ≤ 1 := fun z => by dsimp [g]; linarith [hf0 z]\n have hfint : Integrable f P :=\n Integrable.of_mem_Icc 0 1 hfmeas.aemeasurable\n (Filter.Eventually.of_forall fun z => ⟨hf0 z, hf1 z⟩)\n have hintf : ∫ z, f z ∂P = p := integral_zeroOneLoss h P\n have hintg : ∫ z, g z ∂P = 1 - p := by\n dsimp [g]\n rw [integral_sub (integrable_const _) hfint, integral_const, hintf]\n simp\n have hposR :\n (Measure.pi fun _ : Fin n => P).real Epos ≤\n Real.exp (-((n : ℝ) * t) ^ 2 / (2 * n)) := by\n exact bounded_sum_upper P f hfmeas p t hp0 hp1 ht hf0 hf1 hintf\n have hnegR :\n (Measure.pi fun _ : Fin n => P).real Eneg ≤\n Real.exp (-((n : ℝ) * t) ^ 2 / (2 * n)) := by\n exact bounded_sum_upper P g hgmeas (1 - p) t (by linarith) (by linarith)\n ht hg0 hg1 hintg\n let r : ℝ := Real.exp (-((n : ℝ) * t) ^ 2 / (2 * n))\n have hr0 : 0 ≤ r := (Real.exp_pos _).le\n have hpos : (Measure.pi fun _ : Fin n => P) Epos ≤ ENNReal.ofReal r := by\n apply (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).mp\n rw [ENNReal.toReal_ofReal hr0]\n exact hposR\n have hneg : (Measure.pi fun _ : Fin n => P) Eneg ≤ ENNReal.ofReal r := by\n apply (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).mp\n rw [ENNReal.toReal_ofReal hr0]\n exact hnegR\n have hdev : finiteDeviation (n := n) h P t = Epos ∪ Eneg := by\n rfl\n rw [hdev]\n calc\n (Measure.pi fun _ : Fin n => P) (Epos ∪ Eneg)\n ≤ (Measure.pi fun _ : Fin n => P) Epos +\n (Measure.pi fun _ : Fin n => P) Eneg := measure_union_le _ _\n _ ≤ ENNReal.ofReal r + ENNReal.ofReal r := add_le_add hpos hneg\n _ = 2 * ENNReal.ofReal r := by ring\n _ = 2 * (ENNReal.ofReal (Real.exp (-t ^ 2 / 2))) ^ n := by\n congr 1\n have hnR : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn)\n have hexp : -((n : ℝ) * t) ^ 2 / (2 * n) =\n (n : ℝ) * (-t ^ 2 / 2) := by\n field_simp\n dsimp [r]\n rw [hexp, Real.exp_nat_mul,\n ENNReal.ofReal_pow (Real.exp_pos _).le]\n\nlemma abs_empirical_sub_lt_of_not_mem_finiteDeviation\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) (t : ℝ)\n (S : Fin n → 𝒳 × Bool) (hS : S ∉ finiteDeviation h P t) :\n |∑ i, zeroOneLoss h (S i) - (n : ℝ) * ordinaryError h P| <\n (n : ℝ) * t := by\n have hpair :\n ¬((n : ℝ) * t ≤\n (∑ i, zeroOneLoss h (S i)) - (n : ℝ) * ordinaryError h P) ∧\n ¬((n : ℝ) * t ≤\n (∑ i, (1 - zeroOneLoss h (S i))) -\n (n : ℝ) * (1 - ordinaryError h P)) := by\n simpa only [finiteDeviation, Set.mem_union, Set.mem_setOf_eq, not_or] using hS\n rw [abs_lt]\n constructor\n · have hsecond := lt_of_not_ge hpair.2\n simp only [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_fin,\n nsmul_eq_mul] at hsecond\n linarith\n · exact lt_of_not_ge hpair.1\n\nlemma finite_class_agnostic_at_size\n {𝒳 : Type*} [MeasurableSpace 𝒳] {n : ℕ}\n (F : Finset (Predictor 𝒳 Bool))\n (hdefault : Predictor 𝒳 Bool) (hdefault_mem : hdefault ∈ F)\n {γ δ : ℝ} (hγ0 : 0 < γ) (hn : 0 < n)\n (hbound : F.card * 2 *\n (ENNReal.ofReal (Real.exp (-(γ / 2) ^ 2 / 2))) ^ n ≤ ENNReal.ofReal δ) :\n OrdinaryAgnosticPACAtSize (↑F : HypothesisClass 𝒳 Bool) γ δ n := by\n classical\n have hF : F.Nonempty := ⟨hdefault, hdefault_mem⟩\n refine ⟨finiteERM F hdefault, ?_⟩\n intro P _\n obtain ⟨hopt, hoptF, hoptmin⟩ :=\n Finset.exists_min_image F (fun h => ordinaryError h P) hF\n letI : Nonempty ↥(↑F : Set (Predictor 𝒳 Bool)) :=\n ⟨⟨hdefault, hdefault_mem⟩⟩\n have hbdd : BddBelow (Set.range fun h : ↥(↑F : Set (Predictor 𝒳 Bool)) =>\n ordinaryError (h : Predictor 𝒳 Bool) P) := by\n refine ⟨0, ?_⟩\n rintro _ ⟨h, rfl⟩\n exact ENNReal.toReal_nonneg\n have hinf :\n (⨅ h : ↥(↑F : Set (Predictor 𝒳 Bool)),\n ordinaryError (h : Predictor 𝒳 Bool) P) = ordinaryError hopt P := by\n apply le_antisymm\n · exact ciInf_le hbdd ⟨hopt, hoptF⟩\n · apply le_ciInf\n intro h\n exact hoptmin h h.property\n have hsubset :\n {S : Fin n → 𝒳 × Bool |\n (⨅ h : ↥(↑F : Set (Predictor 𝒳 Bool)),\n ordinaryError (h : Predictor 𝒳 Bool) P) + γ <\n ordinaryError (finiteERM F hdefault S) P} ⊆\n ⋃ h ∈ F, finiteDeviation (n := n) h P (γ / 2) := by\n intro S hbad\n by_contra hnot\n have hgood (h : Predictor 𝒳 Bool) (hh : h ∈ F) :\n S ∉ finiteDeviation (n := n) h P (γ / 2) := by\n intro hmem\n exact hnot (Set.mem_iUnion.mpr ⟨h, Set.mem_iUnion.mpr ⟨hh, hmem⟩⟩)\n have hAF : finiteERM F hdefault S ∈ F := finiteERM_mem F hdefault S hF\n have hAdev := abs_empirical_sub_lt_of_not_mem_finiteDeviation\n (finiteERM F hdefault S) P (γ / 2) S (hgood _ hAF)\n have hOdev := abs_empirical_sub_lt_of_not_mem_finiteDeviation\n hopt P (γ / 2) S (hgood _ hoptF)\n have hAle := finiteERM_le F hdefault S hF hopt hoptF\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n rw [hinf] at hbad\n rcases (abs_lt.mp hAdev) with ⟨hAlo, hAhi⟩\n rcases (abs_lt.mp hOdev) with ⟨hOlo, hOhi⟩\n have hscaled := mul_lt_mul_of_pos_left hbad hnR\n nlinarith\n calc\n (Measure.pi fun _ : Fin n => P)\n {S : Fin n → 𝒳 × Bool |\n (⨅ h : ↥(↑F : Set (Predictor 𝒳 Bool)),\n ordinaryError (h : Predictor 𝒳 Bool) P) + γ <\n ordinaryError (finiteERM F hdefault S) P}\n ≤ (Measure.pi fun _ : Fin n => P)\n (⋃ h ∈ F, finiteDeviation (n := n) h P (γ / 2)) := measure_mono hsubset\n _ ≤ ∑ h ∈ F, (Measure.pi fun _ : Fin n => P)\n (finiteDeviation (n := n) h P (γ / 2)) := measure_biUnion_finset_le F _\n _ ≤ ∑ _h ∈ F,\n 2 * (ENNReal.ofReal (Real.exp (-(γ / 2) ^ 2 / 2))) ^ n := by\n gcongr with h hh\n exact measure_finiteDeviation_le P h (γ / 2) hn (by linarith)\n _ = F.card * 2 *\n (ENNReal.ofReal (Real.exp (-(γ / 2) ^ 2 / 2))) ^ n := by\n simp\n ring\n _ ≤ ENNReal.ofReal δ := hbound\n\n/-- Every nonempty finite class is agnostically PAC learnable. Together with\n`finite_class_ordinary_realizable_PAC`, this is the strongest completely finite\nspecial case of `ordinary_finite_vc_bounds`; all failure events are finite\nunions of measurable deviation events. -/\nlemma finite_class_ordinary_agnostic_PAC\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (hfin : H.Finite) (hH : H.Nonempty)\n {γ δ : ℝ} (hγ0 : 0 < γ) (hδ0 : 0 < δ) :\n ∃ n : ℕ, OrdinaryAgnosticPACAtSize H γ δ n := by\n classical\n let F : Finset (Predictor 𝒳 Bool) := hfin.toFinset\n let hdefault : Predictor 𝒳 Bool := Classical.choose hH\n have hdefault_mem : hdefault ∈ F := by\n simpa [F, hdefault] using Classical.choose_spec hH\n let q : ℝ≥0∞ := ENNReal.ofReal (Real.exp (-(γ / 2) ^ 2 / 2))\n have harg : -(γ / 2) ^ 2 / 2 < 0 := by\n have hs : 0 < (γ / 2) ^ 2 := sq_pos_of_pos (by linarith)\n linarith\n have hq : q < 1 := by\n change ENNReal.ofReal (Real.exp (-(γ / 2) ^ 2 / 2)) < 1\n rw [ENNReal.ofReal_lt_one]\n exact Real.exp_lt_one_iff.mpr harg\n have hd : 0 < ENNReal.ofReal δ := ENNReal.ofReal_pos.mpr hδ0\n have ht : Filter.Tendsto\n (fun n : ℕ => (F.card : ℝ≥0∞) * 2 * q ^ n)\n Filter.atTop (nhds 0) := by\n have hpow := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hq\n simpa [mul_assoc] using ENNReal.Tendsto.const_mul\n (a := (F.card : ℝ≥0∞) * 2) hpow\n (Or.inr (ENNReal.mul_ne_top (by simp) (by norm_num)))\n have hev : Filter.Eventually\n (fun n => (F.card : ℝ≥0∞) * 2 * q ^ n < ENNReal.ofReal δ)\n Filter.atTop :=\n (tendsto_order.1 ht).2 _ hd\n obtain ⟨N, hN⟩ := Filter.eventually_atTop.1 hev\n let n := max N 1\n have hnN : N ≤ n := Nat.le_max_left _ _\n have hn : 0 < n := lt_of_lt_of_le Nat.zero_lt_one (Nat.le_max_right _ _)\n refine ⟨n, ?_⟩\n rw [← hfin.coe_toFinset]\n apply finite_class_agnostic_at_size F hdefault hdefault_mem hγ0 hn\n simpa [q] using (hN n hnN).le\n\n/-- On a finite instance type every class of measurable Boolean predictors is\nfinite, so both ordinary learning problems are completely solved without a VC\nor family-measurability assumption. -/\nlemma finite_domain_ordinary_PAC\n {𝒳 : Type*} [MeasurableSpace 𝒳] [Finite 𝒳]\n (H : HypothesisClass 𝒳 Bool) (hH : H.Nonempty)\n {γ α δ : ℝ} (hγ0 : 0 < γ) (hα0 : 0 < α) (hα1 : α < 1)\n (hδ0 : 0 < δ) :\n (∃ n : ℕ, OrdinaryAgnosticPACAtSize H γ δ n) ∧\n ∃ n : ℕ, OrdinaryRealizablePACAtSize H α δ n := by\n classical\n letI : Finite (Predictor 𝒳 Bool) :=\n Finite.of_injective Predictor.f (fun h g hfg => by\n cases h\n cases g\n cases hfg\n rfl)\n have hfin : H.Finite := Set.toFinite H\n exact ⟨finite_class_ordinary_agnostic_PAC H hfin hH hγ0 hδ0,\n finite_class_ordinary_realizable_PAC H hfin hH hα0 hα1 hδ0⟩\n\n/-! The combinatorial reduction used in the usual infinite-class proof is valid\nwithout any measurability assumption on the class. For a fixed tuple of\ninstances, `vcTrace H x` is the genuinely finite family of dichotomies induced\nby `H`. -/\n\nnoncomputable def vcTrace\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {n : ℕ} (x : Fin n → 𝒳) : Finset (Finset (Fin n)) := by\n classical\n exact Finset.univ.filter fun t =>\n ∃ h ∈ H, ∀ i, i ∈ t ↔ h.f (x i) = true\n\nlemma mem_vcTrace\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {n : ℕ} (x : Fin n → 𝒳) (t : Finset (Fin n)) :\n t ∈ vcTrace H x ↔ ∃ h ∈ H, ∀ i, i ∈ t ↔ h.f (x i) = true := by\n classical\n simp [vcTrace]\n\nlemma vcTrace_injOn_of_shatters\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {n : ℕ} (x : Fin n → 𝒳) {s : Finset (Fin n)}\n (hs : (vcTrace H x).Shatters s) : Set.InjOn x (s : Set (Fin n)) := by\n classical\n intro i hi j hj hijx\n by_contra hij\n have hisub : ({i} : Finset (Fin n)) ⊆ s := Finset.singleton_subset_iff.mpr hi\n obtain ⟨t, ht, hst⟩ := hs hisub\n obtain ⟨h, hh, hvals⟩ := (mem_vcTrace H x t).mp ht\n have hit : i ∈ t := by\n have : i ∈ s ∩ t := by rw [hst]; simp\n exact (Finset.mem_inter.mp this).2\n have hjt : j ∉ t := by\n intro hjt\n have : j ∈ s ∩ t := Finset.mem_inter.mpr ⟨hj, hjt⟩\n rw [hst] at this\n exact hij (Finset.mem_singleton.mp this).symm\n have heqmem : (i ∈ t ↔ j ∈ t) := by\n rw [hvals i, hvals j, hijx]\n exact hjt (heqmem.mp hit)\n\nlemma vcTrace_image_shattered\n {𝒳 : Type*} [MeasurableSpace 𝒳] [DecidableEq 𝒳]\n (H : HypothesisClass 𝒳 Bool)\n {n : ℕ} (x : Fin n → 𝒳) {s : Finset (Fin n)}\n (hs : (vcTrace H x).Shatters s) : ResearchLevel.Shatters H (s.image x) := by\n classical\n intro b\n let bx : Fin n → Bool := fun i =>\n if hi : i ∈ s then\n b ⟨x i, Finset.mem_image.mpr ⟨i, hi, rfl⟩⟩\n else false\n let t : Finset (Fin n) := s.filter fun i => bx i = true\n have hts : t ⊆ s := Finset.filter_subset _ _\n obtain ⟨u, hu, hsu⟩ := hs hts\n obtain ⟨h, hh, hvals⟩ := (mem_vcTrace H x u).mp hu\n refine ⟨h, hh, ?_⟩\n rintro ⟨z, hz⟩\n obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hz\n have hiu_iff : i ∈ u ↔ i ∈ t := by\n constructor\n · intro hiu\n have : i ∈ s ∩ u := Finset.mem_inter.mpr ⟨hi, hiu⟩\n rwa [hsu] at this\n · intro hit\n have : i ∈ s ∩ u := by rwa [hsu]\n exact (Finset.mem_inter.mp this).2\n have htrue_iff : h.f (x i) = true ↔\n b ⟨x i, Finset.mem_image.mpr ⟨i, hi, rfl⟩⟩ = true := by\n rw [← hvals i, hiu_iff]\n simp [t, bx, hi]\n cases hhf : h.f (x i) <;>\n cases hhb : b ⟨x i, Finset.mem_image.mpr ⟨i, hi, rfl⟩⟩ <;>\n simp_all\n\nlemma vcTrace_shattered_card_le\n {𝒳 : Type*} [MeasurableSpace 𝒳] [DecidableEq 𝒳]\n (H : HypothesisClass 𝒳 Bool)\n {n d : ℕ} (x : Fin n → 𝒳) (hvc : VCDim H = (d : ℕ∞))\n {s : Finset (Fin n)} (hs : (vcTrace H x).Shatters s) : s.card ≤ d := by\n classical\n have hinj := vcTrace_injOn_of_shatters H x hs\n have hcard : (s.image x).card = s.card := Finset.card_image_of_injOn hinj\n have hsh := vcTrace_image_shattered H x hs\n have hle : (((s.image x).card : ℕ) : ℕ∞) ≤ VCDim H := by\n exact le_iSup₂\n (f := fun (S : Finset 𝒳) (_ : Shatters H S) => (S.card : ℕ∞))\n (s.image x) hsh\n rw [hvc] at hle\n have : (s.image x).card ≤ d := by exact_mod_cast hle\n omega\n\nlemma vcTrace_vcDim_le\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {n d : ℕ} (x : Fin n → 𝒳) (hvc : VCDim H = (d : ℕ∞)) :\n (vcTrace H x).vcDim ≤ d := by\n classical\n unfold Finset.vcDim\n apply Finset.sup_le\n intro s hs\n exact vcTrace_shattered_card_le H x hvc (Finset.mem_shatterer.mp hs)\n\n/-- Sauer--Shelah for the trace of the given class on an arbitrary finite\ntuple. Repetitions in the tuple are handled by the injectivity argument above. -/\ntheorem vcTrace_card_le_sauer\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {n d : ℕ} (x : Fin n → 𝒳) (hvc : VCDim H = (d : ℕ∞)) :\n (vcTrace H x).card ≤ ∑ k ∈ Finset.Iic d, n.choose k := by\n classical\n calc\n (vcTrace H x).card ≤ (vcTrace H x).shatterer.card :=\n Finset.card_le_card_shatterer _\n _ ≤ ∑ k ∈ Finset.Iic (vcTrace H x).vcDim, n.choose k := by\n simpa using (Finset.card_shatterer_le_sum_vcDim\n (𝒜 := vcTrace H x))\n _ ≤ ∑ k ∈ Finset.Iic d, n.choose k := by\n exact Finset.sum_le_sum_of_subset\n (Finset.Iic_subset_Iic.mpr (vcTrace_vcDim_le H x hvc))\n\nlemma robust_excess_le_of_ordinary {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (hH : H.Nonempty)\n (A : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n {ρ γ : ℝ} (hρ : 0 < ρ) (hγ : 0 ≤ γ)\n (hord : ordinaryError A P ≤\n (⨅ h : ↥H, ordinaryError (h : Predictor 𝒳 Bool) P) + γ) :\n robustRisk A P ρ ≤\n (⨅ h : ↥H, robustRisk (h : Predictor 𝒳 Bool) P ρ) +\n robustLip ρ * Real.sqrt γ := by\n letI : Nonempty ↥H := hH.to_subtype\n have hbddOrd : BddBelow (Set.range fun h : ↥H =>\n ordinaryError (h : Predictor 𝒳 Bool) P) := by\n refine ⟨0, ?_⟩\n rintro _ ⟨h, rfl⟩\n exact ENNReal.toReal_nonneg\n have hInf_le (h : ↥H) :\n (⨅ g : ↥H, ordinaryError (g : Predictor 𝒳 Bool) P) ≤\n ordinaryError (h : Predictor 𝒳 Bool) P :=\n ciInf_le hbddOrd h\n simp_rw [robustRisk_eq_scalar]\n have hbase :\n scalarRobustRisk ρ (ordinaryError A P) - robustLip ρ * Real.sqrt γ ≤\n ⨅ h : ↥H, scalarRobustRisk ρ\n (ordinaryError (h : Predictor 𝒳 Bool) P) := by\n apply le_ciInf\n intro h\n have hpA0 : 0 ≤ ordinaryError A P := ENNReal.toReal_nonneg\n have hpA1 := ordinaryError_le_one A P\n have hph0 : 0 ≤ ordinaryError (h : Predictor 𝒳 Bool) P := ENNReal.toReal_nonneg\n have hph1 := ordinaryError_le_one (h : Predictor 𝒳 Bool) P\n by_cases hle : ordinaryError A P ≤ ordinaryError (h : Predictor 𝒳 Bool) P\n · have hm := scalarRobustRisk_mono hρ hpA0 hle hph1\n have hterm : 0 ≤ robustLip ρ * Real.sqrt γ :=\n mul_nonneg (robustLip_pos hρ).le (Real.sqrt_nonneg _)\n linarith\n · have hha : ordinaryError (h : Predictor 𝒳 Bool) P ≤ ordinaryError A P :=\n le_of_not_ge hle\n have hdiff : ordinaryError A P - ordinaryError (h : Predictor 𝒳 Bool) P ≤ γ := by\n have := hInf_le h\n linarith\n have hlip := scalarRobustRisk_lip hρ hph0 hha hpA1\n have hsqrt : Real.sqrt\n (ordinaryError A P - ordinaryError (h : Predictor 𝒳 Bool) P) ≤\n Real.sqrt γ := Real.sqrt_le_sqrt hdiff\n have hmul := mul_le_mul_of_nonneg_left hsqrt (robustLip_pos hρ).le\n linarith\n linarith\n\nlemma ordinaryAgnosticPAC_lifts_to_robust\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (hH : H.Nonempty)\n (ρ ε δ γ : ℝ) (n : ℕ) (hρ : 0 < ρ) (hγ : 0 ≤ γ)\n (hscale : robustLip ρ * Real.sqrt γ ≤ ε)\n (hPAC : OrdinaryAgnosticPACAtSize H γ δ n) :\n AgnosticPACAtSize H ρ ε δ n := by\n rcases hPAC with ⟨A, hA⟩\n refine ⟨A, ?_⟩\n intro P _\n apply le_trans (measure_mono ?_) (hA P)\n intro S hfail\n by_contra hnordinary\n simp only [Set.mem_setOf_eq] at hfail hnordinary ⊢\n have hord : ordinaryError (A S) P ≤\n (⨅ h : ↥H, ordinaryError (h : Predictor 𝒳 Bool) P) + γ :=\n le_of_not_gt hnordinary\n have hrob := robust_excess_le_of_ordinary H hH (A S) P hρ hγ hord\n linarith\n\nlemma agnosticSampleComplexity_le_of_ordinaryPAC\n {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (hH : H.Nonempty)\n (ρ ε δ γ : ℝ) (n : ℕ) (hρ : 0 < ρ) (hγ : 0 ≤ γ)\n (hscale : robustLip ρ * Real.sqrt γ ≤ ε)\n (hPAC : OrdinaryAgnosticPACAtSize H γ δ n) :\n agnosticSampleComplexity H ρ ε δ ≤ (n : ℕ∞) := by\n unfold agnosticSampleComplexity\n apply sInf_le\n exact ⟨n, rfl,\n ordinaryAgnosticPAC_lifts_to_robust H hH ρ ε δ γ n hρ hγ hscale hPAC⟩\n\nlemma robustRisk_zero_error_zero {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (ρ : ℝ) (hρ : 0 ≤ ρ) (hz : robustRisk h P ρ = 0) : ordinaryError h P = 0 := by\n have hle := robustRisk_ge_error h P ρ hρ\n rw [hz] at hle\n exact le_antisymm hle ENNReal.toReal_nonneg\n\nlemma robustRisk_le_c2_sqrt_error {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (ρ : ℝ) (hρ : 0 ≤ ρ) :\n robustRisk h P ρ ≤ c2 ρ * Real.sqrt (ordinaryError h P) := by\n let p : ℝ := ordinaryError h P\n let q : ℝ := (P {z : 𝒳 × Bool | h.f z.1 = z.2}).toReal\n have hp : 0 ≤ p := ENNReal.toReal_nonneg\n have hq : 0 ≤ q := ENNReal.toReal_nonneg\n have hpq : p + q = 1 := error_correct_sum_one h P\n let η0 : etaDomain ρ := ⟨0, zero_mem_etaDomain ρ hρ⟩\n let F : etaDomain ρ → ℝ := fun η =>\n c2 ρ * Real.sqrt\n (p * (max (1 - (η : ℝ)) 0) ^ 2 + q * (max (0 - (η : ℝ)) 0) ^ 2) + (η : ℝ)\n have hbelow : BddBelow (Set.range F) := by\n refine ⟨p, ?_⟩\n rintro _ ⟨η, rfl⟩\n exact scalar_rms_add_eta_ge p q (η : ℝ) (c2 ρ) hp hq hpq\n (c2_ge_one ρ hρ) (eta_le_one ρ η)\n rw [robustRisk]\n change iInf F ≤ c2 ρ * Real.sqrt p\n calc\n iInf F ≤ F η0 := ciInf_le hbelow η0\n _ = c2 ρ * Real.sqrt p := by simp [F, η0]\n\nlemma robust_failure_implies_error {𝒳 : Type*} [MeasurableSpace 𝒳]\n (h : Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (ρ ε : ℝ) (hρ : 0 ≤ ρ) (hε : 0 < ε)\n (hfail : ε < robustRisk h P ρ) :\n ε ^ 2 / (1 + 2 * ρ) < ordinaryError h P := by\n have hupper := robustRisk_le_c2_sqrt_error h P ρ hρ\n have hp : 0 ≤ ordinaryError h P := ENNReal.toReal_nonneg\n have hden : 0 < 1 + 2 * ρ := by linarith\n have hc : 0 ≤ c2 ρ := Real.sqrt_nonneg _\n have hcsq : (c2 ρ) ^ 2 = 1 + 2 * ρ := by\n simp [c2, Real.sq_sqrt (le_of_lt hden)]\n have hsqrt_sq : (Real.sqrt (ordinaryError h P)) ^ 2 = ordinaryError h P :=\n Real.sq_sqrt hp\n apply (div_lt_iff₀ hden).2\n nlinarith [Real.sqrt_nonneg (ordinaryError h P)]\n\nlemma ordinaryPAC_lifts_to_robust {𝒳 : Type*} [MeasurableSpace 𝒳]\n (H : HypothesisClass 𝒳 Bool) (ρ ε δ : ℝ) (n : ℕ)\n (hρ : 0 ≤ ρ) (hε : 0 < ε)\n (hPAC : OrdinaryRealizablePACAtSize H (ε ^ 2 / (1 + 2 * ρ)) δ n) :\n RealizablePACAtSize H ρ ε δ n := by\n rcases hPAC with ⟨A, hA⟩\n refine ⟨A, ?_⟩\n intro P _ hreal\n apply le_trans (measure_mono ?_) (hA P ?_)\n · intro S hS\n exact robust_failure_implies_error (A S) P ρ ε hρ hε hS\n · rcases hreal with ⟨hstar, hhstar, hz⟩\n exact ⟨hstar, hhstar, robustRisk_zero_error_zero hstar P ρ hρ hz⟩\n\nlemma realizableSampleComplexity_le_of_ordinaryPAC\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n (ρ ε δ : ℝ) (n : ℕ) (hρ : 0 ≤ ρ) (hε : 0 < ε)\n (hPAC : OrdinaryRealizablePACAtSize H (ε ^ 2 / (1 + 2 * ρ)) δ n) :\n realizableSampleComplexity H ρ ε δ ≤ (n : ℕ∞) := by\n unfold realizableSampleComplexity\n apply sInf_le\n exact ⟨n, rfl, ordinaryPAC_lifts_to_robust H ρ ε δ n hρ hε hPAC⟩\n\nlemma theorem7_rhs_lower {d : ℕ} (hd : 0 < d)\n {ρ ε δ : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) :\n (((d : ℝ) + 1 + Real.log (2 / δ)) / ε ^ 4) ≤\n ((d / ε ^ 4) * Real.log (d / ε ^ 4)\n + (1 / ε ^ 4) * max (1 / (c2 ρ - 1)) 1\n + (d / ε ^ 4) * Real.log (Real.exp 1 / d)\n + Real.log (2 / δ) / ε ^ 4) := by\n have hdR : 0 < (d : ℝ) := by exact_mod_cast hd\n have he4 : 0 < ε ^ 4 := by positivity\n have hdne : (d : ℝ) ≠ 0 := ne_of_gt hdR\n have he4ne : ε ^ 4 ≠ 0 := ne_of_gt he4\n have hAne : (d : ℝ) / ε ^ 4 ≠ 0 := div_ne_zero hdne he4ne\n have hBne : Real.exp 1 / (d : ℝ) ≠ 0 :=\n div_ne_zero (Real.exp_ne_zero _) hdne\n have hprod : ((d : ℝ) / ε ^ 4) * (Real.exp 1 / (d : ℝ)) =\n Real.exp 1 / ε ^ 4 := by\n field_simp\n have hlogsum : Real.log ((d : ℝ) / ε ^ 4) +\n Real.log (Real.exp 1 / (d : ℝ)) = 1 - Real.log (ε ^ 4) := by\n rw [← Real.log_mul hAne hBne, hprod,\n Real.log_div (Real.exp_ne_zero _) he4ne, Real.log_exp]\n have he2lt : ε ^ 2 < 1 := by\n nlinarith [mul_pos hε0 (sub_pos.mpr hε1)]\n have he4le : ε ^ 4 ≤ 1 := by\n have hm : 0 ≤ ε ^ 2 * (1 - ε ^ 2) :=\n mul_nonneg (sq_nonneg ε) (sub_nonneg.mpr he2lt.le)\n nlinarith\n have hloge : Real.log (ε ^ 4) ≤ 0 := Real.log_nonpos (by positivity) he4le\n have hlog_ge : 1 ≤ Real.log ((d : ℝ) / ε ^ 4) +\n Real.log (Real.exp 1 / (d : ℝ)) := by\n rw [hlogsum]\n linarith\n have hfactor0 : 0 ≤ (d : ℝ) / ε ^ 4 := by positivity\n have hfirst :\n (d / ε ^ 4) * Real.log (d / ε ^ 4) +\n (d / ε ^ 4) * Real.log (Real.exp 1 / d) ≥ (d : ℝ) / ε ^ 4 := by\n rw [← mul_add]\n simpa using mul_le_mul_of_nonneg_left hlog_ge hfactor0\n have hsecond : (1 : ℝ) / ε ^ 4 ≤\n (1 / ε ^ 4) * max (1 / (c2 ρ - 1)) 1 := by\n have hcoef : 0 ≤ (1 : ℝ) / ε ^ 4 := by positivity\n have hm : (1 : ℝ) ≤ max (1 / (c2 ρ - 1)) 1 := le_max_right _ _\n nlinarith\n have hid : (((d : ℝ) + 1 + Real.log (2 / δ)) / ε ^ 4) =\n (d : ℝ) / ε ^ 4 + 1 / ε ^ 4 + Real.log (2 / δ) / ε ^ 4 := by\n ring\n rw [hid]\n linarith\n\n/-! ### VC packing bound -/\n\nnoncomputable def disagree {𝒳 : Type*} [MeasurableSpace 𝒳]\n (Q : Measure 𝒳) (h g : Predictor 𝒳 Bool) : ℝ :=\n (Q {x | h.f x ≠ g.f x}).toReal\n\nlemma measurableSet_agree {𝒳 : Type*} [MeasurableSpace 𝒳] (h g : Predictor 𝒳 Bool) :\n MeasurableSet {x : 𝒳 | h.f x = g.f x} := by\n have he : {x : 𝒳 | h.f x = g.f x}\n = (h.f ⁻¹' {true} ∩ g.f ⁻¹' {true}) ∪ (h.f ⁻¹' {false} ∩ g.f ⁻¹' {false}) := by\n ext x\n cases hh : h.f x <;> cases hg : g.f x <;> simp [hh, hg]\n rw [he]\n exact ((h.hf (by trivial)).inter (g.hf (by trivial))).union\n ((h.hf (by trivial)).inter (g.hf (by trivial)))\n\nlemma disagree_nonneg {𝒳 : Type*} [MeasurableSpace 𝒳] (Q : Measure 𝒳)\n (h g : Predictor 𝒳 Bool) : 0 ≤ disagree Q h g := ENNReal.toReal_nonneg\n\nlemma disagree_le_one {𝒳 : Type*} [MeasurableSpace 𝒳] (Q : Measure 𝒳) [IsProbabilityMeasure Q]\n (h g : Predictor 𝒳 Bool) : disagree Q h g ≤ 1 := by\n have hm : Q {x : 𝒳 | h.f x ≠ g.f x} ≤ Q Set.univ := measure_mono (Set.subset_univ _)\n rw [measure_univ] at hm\n have := ENNReal.toReal_mono ENNReal.one_ne_top hm\n simpa [disagree] using this\n\nlemma measure_agree_eq {𝒳 : Type*} [MeasurableSpace 𝒳] (Q : Measure 𝒳) [IsProbabilityMeasure Q]\n (h g : Predictor 𝒳 Bool) :\n Q {x | h.f x = g.f x} = ENNReal.ofReal (1 - disagree Q h g) := by\n have hcompl : {x : 𝒳 | h.f x ≠ g.f x} = {x : 𝒳 | h.f x = g.f x}ᶜ := by\n ext x; simp\n have hsum := measure_add_measure_compl (μ := Q) (measurableSet_agree h g)\n have h1 : Q {x : 𝒳 | h.f x = g.f x} ≠ ⊤ := measure_ne_top _ _\n have h2 : Q ({x : 𝒳 | h.f x = g.f x}ᶜ) ≠ ⊤ := measure_ne_top _ _\n have h3 := congrArg ENNReal.toReal hsum\n rw [ENNReal.toReal_add h1 h2] at h3\n simp only [measure_univ, ENNReal.toReal_one] at h3\n have hd : disagree Q h g = (Q ({x : 𝒳 | h.f x = g.f x}ᶜ)).toReal := by\n rw [disagree, hcompl]\n rw [hd, ← ENNReal.ofReal_toReal h1]\n congr 1\n linarith\n\n\n/-- **VC packing bound.** If `F` is a family of members of a class of VC dimension `d`\nthat are pairwise at disagreement-distance at least `α` under the instance distribution\n`Q`, and if `m` is large enough that `|F|² (1-α)^m < 1`, then `|F|` is at most the\nSauer--Shelah bound at `m`. No measurability assumption is made on the class: only\nfinitely many fixed measurable predictors are ever handled at once. -/\ntheorem vc_packing_card_le\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d : ℕ∞))\n (Q : Measure 𝒳) [IsProbabilityMeasure Q] {α : ℝ} (hα0 : 0 ≤ α) (hα1 : α ≤ 1)\n (F : Finset (Predictor 𝒳 Bool)) (hFH : ∀ h ∈ F, h ∈ H)\n (hsep : ∀ h ∈ F, ∀ g ∈ F, h ≠ g → α ≤ disagree Q h g)\n (m : ℕ) (hm : ((F.card : ℝ))^2 * (1 - α)^m < 1) :\n F.card ≤ ∑ k ∈ Finset.Iic d, m.choose k := by\n classical\n set μ : Measure (Fin m → 𝒳) := Measure.pi (fun _ => Q) with hμ\n haveI : IsProbabilityMeasure μ := by rw [hμ]; infer_instance\n set Pairs : Finset (Predictor 𝒳 Bool × Predictor 𝒳 Bool) :=\n (F ×ˢ F).filter (fun p => p.1 ≠ p.2) with hPairs\n set E : Predictor 𝒳 Bool × Predictor 𝒳 Bool → Set (Fin m → 𝒳) :=\n fun p => Set.univ.pi (fun _ : Fin m => {y : 𝒳 | p.1.f y = p.2.f y}) with hE\n have hEle : ∀ p ∈ Pairs, μ (E p) ≤ ENNReal.ofReal ((1-α)^m) := by\n intro p hp\n have hp' : p.1 ∈ F ∧ p.2 ∈ F ∧ p.1 ≠ p.2 := by\n have := Finset.mem_filter.mp hp\n exact ⟨(Finset.mem_product.mp this.1).1, (Finset.mem_product.mp this.1).2, this.2⟩\n have hsep' : α ≤ disagree Q p.1 p.2 := hsep _ hp'.1 _ hp'.2.1 hp'.2.2\n have : μ (E p) = (Q {y : 𝒳 | p.1.f y = p.2.f y})^m := by\n rw [hE, hμ]\n simp only\n rw [Measure.pi_pi]\n simp\n have hd1 : disagree Q p.1 p.2 ≤ 1 := disagree_le_one Q _ _\n rw [this, measure_agree_eq]\n rw [← ENNReal.ofReal_pow (by linarith)]\n apply ENNReal.ofReal_le_ofReal\n gcongr <;> linarith\n have hunion : μ (⋃ p ∈ Pairs, E p) < 1 := by\n calc μ (⋃ p ∈ Pairs, E p) ≤ ∑ p ∈ Pairs, μ (E p) := measure_biUnion_finset_le _ _\n _ ≤ ∑ _p ∈ Pairs, ENNReal.ofReal ((1-α)^m) := Finset.sum_le_sum hEle\n _ = (Pairs.card : ℝ≥0∞) * ENNReal.ofReal ((1-α)^m) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n _ ≤ ((F.card * F.card : ℕ) : ℝ≥0∞) * ENNReal.ofReal ((1-α)^m) := by\n have hcard : Pairs.card ≤ F.card * F.card := by\n have h1 : Pairs ⊆ F ×ˢ F := Finset.filter_subset _ _\n have h2 := Finset.card_le_card h1\n simpa [Finset.card_product] using h2\n gcongr\n _ = ENNReal.ofReal (((F.card : ℝ))^2 * (1-α)^m) := by\n rw [ENNReal.ofReal_mul (by positivity)]\n congr 1\n rw [show ((F.card : ℝ))^2 = ((F.card * F.card : ℕ) : ℝ) by push_cast; ring]\n exact (ENNReal.ofReal_natCast _).symm\n _ < 1 := ENNReal.ofReal_lt_one.mpr hm\n have hne : (⋃ p ∈ Pairs, E p) ≠ Set.univ := by\n intro hcon\n rw [hcon, measure_univ] at hunion\n exact lt_irrefl _ hunion\n obtain ⟨x, hx⟩ : ∃ x : Fin m → 𝒳, x ∉ ⋃ p ∈ Pairs, E p := by\n by_contra hcon\n push_neg at hcon\n exact hne (Set.eq_univ_of_forall hcon)\n set φ : Predictor 𝒳 Bool → Finset (Fin m) :=\n fun h => Finset.univ.filter (fun i => h.f (x i) = true) with hφ\n have hmemtrace : ∀ h ∈ F, φ h ∈ vcTrace H x := by\n intro h hh\n rw [mem_vcTrace]\n exact ⟨h, hFH h hh, by intro i; simp [hφ]⟩\n have hinj : Set.InjOn φ (F : Set (Predictor 𝒳 Bool)) := by\n intro h hh g hg hfg\n by_contra hne'\n have hpair : (h, g) ∈ Pairs := by\n rw [hPairs, Finset.mem_filter]\n exact ⟨Finset.mem_product.mpr ⟨hh, hg⟩, hne'⟩\n have hxE : x ∉ E (h, g) := by\n intro hmem\n exact hx (Set.mem_biUnion hpair hmem)\n apply hxE\n rw [hE]\n intro i _\n simp only [Set.mem_setOf_eq]\n have hiff : (i ∈ φ h) ↔ (i ∈ φ g) := by rw [hfg]\n simp only [hφ, Finset.mem_filter, Finset.mem_univ, true_and] at hiff\n by_cases hb : h.f (x i) = true\n · have hb2 : g.f (x i) = true := hiff.mp hb\n rw [hb, hb2]\n · have hb' : h.f (x i) = false := by\n cases hc : h.f (x i) with\n | false => rfl\n | true => exact absurd hc hb\n have hg' : g.f (x i) = false := by\n cases hc : g.f (x i) with\n | false => rfl\n | true => exact absurd (hiff.mpr hc) hb\n rw [hb', hg']\n calc F.card = (F.image φ).card := (Finset.card_image_of_injOn hinj).symm\n _ ≤ (vcTrace H x).card := by\n apply Finset.card_le_card\n intro t ht\n obtain ⟨h, hh, rfl⟩ := Finset.mem_image.mp ht\n exact hmemtrace h hh\n _ ≤ ∑ k ∈ Finset.Iic d, m.choose k := vcTrace_card_le_sauer H x hvc\n\n\n\n/-! ### Sauer sum numeric bound -/\n\nsection SauerNum\nopen Finset\n\n/-- `∑_{k ≤ d} C(n,k) ≤ (e n / d)^d` for `0 < d ≤ n`. -/\nlemma sum_Iic_choose_le_exp (n d : ℕ) (hd : 0 < d) (hdn : d ≤ n) :\n ((∑ k ∈ Finset.Iic d, n.choose k : ℕ) : ℝ) ≤ (Real.exp 1 * n / d) ^ d := by\n have hn : 0 < n := lt_of_lt_of_le hd hdn\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n have hdR : (0:ℝ) < d := by exact_mod_cast hd\n set x : ℝ := (d : ℝ) / n with hxdef\n have hx0 : 0 < x := div_pos hdR hnR\n have hx1 : x ≤ 1 := by\n rw [hxdef, div_le_one hnR]\n exact_mod_cast hdn\n have hxinv : (0:ℝ) < 1 / x := by positivity\n -- step 1 : each term is at most C(n,k) x^k (1/x)^d\n have step1 : ((∑ k ∈ Finset.Iic d, n.choose k : ℕ) : ℝ)\n ≤ ∑ k ∈ Finset.Iic d, ((n.choose k : ℝ) * x ^ k) * (1/x) ^ d := by\n push_cast\n apply Finset.sum_le_sum\n intro k hk\n have hkd : k ≤ d := Finset.mem_Iic.mp hk\n have hxk : x ^ d ≤ x ^ k := pow_le_pow_of_le_one hx0.le hx1 hkd\n have hc : (0:ℝ) ≤ (n.choose k : ℝ) := by positivity\n have : (1:ℝ) ≤ x ^ k * (1/x) ^ d := by\n have hrw : x ^ k * (1/x) ^ d = x ^ k / x ^ d := by\n rw [one_div, inv_pow, ← div_eq_mul_inv]\n rw [hrw, le_div_iff₀ (pow_pos hx0 d)]\n simpa using hxk\n calc (n.choose k : ℝ) = (n.choose k : ℝ) * 1 := by ring\n _ ≤ (n.choose k : ℝ) * (x ^ k * (1/x) ^ d) := by\n exact mul_le_mul_of_nonneg_left this hc\n _ = ((n.choose k : ℝ) * x ^ k) * (1/x) ^ d := by ring\n -- step 2 : extend the sum to the whole range and use the binomial theorem\n have step2 : ∑ k ∈ Finset.Iic d, ((n.choose k : ℝ) * x ^ k)\n ≤ ∑ k ∈ Finset.range (n+1), ((n.choose k : ℝ) * x ^ k) := by\n apply Finset.sum_le_sum_of_subset_of_nonneg\n · intro k hk\n have := Finset.mem_Iic.mp hk\n exact Finset.mem_range.mpr (by omega)\n · intro k _ _\n positivity\n have hbin : ∑ k ∈ Finset.range (n+1), ((n.choose k : ℝ) * x ^ k) = (x + 1) ^ n := by\n rw [add_pow]\n apply Finset.sum_congr rfl\n intro k hk\n rw [one_pow]\n ring\n have hexp : (x + 1) ^ n ≤ Real.exp 1 ^ d := by\n have h1 : (x + 1) ^ n ≤ (Real.exp x) ^ n :=\n pow_le_pow_left₀ (by positivity) (Real.add_one_le_exp x) n\n have h2 : (Real.exp x) ^ n = Real.exp 1 ^ d := by\n rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]\n congr 1\n rw [hxdef]\n field_simp\n linarith [h1, h2.le, h2.ge]\n have hfin : ((∑ k ∈ Finset.Iic d, n.choose k : ℕ) : ℝ)\n ≤ (Real.exp 1) ^ d * (1/x) ^ d := by\n calc ((∑ k ∈ Finset.Iic d, n.choose k : ℕ) : ℝ)\n ≤ ∑ k ∈ Finset.Iic d, ((n.choose k : ℝ) * x ^ k) * (1/x) ^ d := step1\n _ = (∑ k ∈ Finset.Iic d, ((n.choose k : ℝ) * x ^ k)) * (1/x) ^ d := by\n rw [Finset.sum_mul]\n _ ≤ ((x + 1) ^ n) * (1/x) ^ d := by\n apply mul_le_mul_of_nonneg_right (le_trans step2 (le_of_eq hbin))\n positivity\n _ ≤ (Real.exp 1) ^ d * (1/x) ^ d := by\n apply mul_le_mul_of_nonneg_right hexp\n positivity\n have hxx : (1:ℝ)/x = (n:ℝ)/d := by\n rw [hxdef]; field_simp\n rw [hxx] at hfin\n calc ((∑ k ∈ Finset.Iic d, n.choose k : ℕ) : ℝ)\n ≤ (Real.exp 1) ^ d * ((n:ℝ)/d) ^ d := hfin\n _ = (Real.exp 1 * n / d) ^ d := by\n rw [← mul_pow]; congr 1; field_simp\n\nend SauerNum\n\n\n/-! ### The combinatorial core of the symmetrisation argument -/\n\nsection Counting\nopen Finset\n\n/-- If `T` is a set of indices at which we exchange the two halves of a paired sample,\n`a i` records whether a fixed predictor errs at the first member of the `i`-th pair and\n`b i` whether it errs at the second one. The number of exchange patterns which make the\npredictor consistent on the first half and produce at least `r` errors on the second half\nis at most `2 ^ (m - r)`. -/\ndef swapGood {m : ℕ} (a b : Fin m → Bool) (r : ℕ) : Finset (Finset (Fin m)) :=\n (Finset.univ : Finset (Finset (Fin m))).filter (fun T =>\n (∀ i, (if i ∈ T then b i else a i) = false) ∧\n r ≤ (Finset.univ.filter (fun i => (if i ∈ T then a i else b i) = true)).card)\n\nlemma mem_swapGood {m : ℕ} (a b : Fin m → Bool) (r : ℕ) (T : Finset (Fin m)) :\n T ∈ swapGood a b r ↔\n ((∀ i, (if i ∈ T then b i else a i) = false) ∧\n r ≤ (Finset.univ.filter (fun i => (if i ∈ T then a i else b i) = true)).card) := by\n rw [swapGood, Finset.mem_filter]\n exact ⟨fun h => h.2, fun h => ⟨Finset.mem_univ _, h⟩⟩\n\nlemma card_swap_good_le {m : ℕ} (a b : Fin m → Bool) (r : ℕ) :\n (swapGood a b r).card ≤ 2 ^ (m - r) := by\n classical\n set G := swapGood a b r with hGdef\n rcases Finset.eq_empty_or_nonempty G with hemp | ⟨T₀, hT₀⟩\n �� simp [hemp]\n · have hmemG : ∀ T, T ∈ G ↔ ((∀ i, (if i ∈ T then b i else a i) = false) ∧\n r ≤ (Finset.univ.filter (fun i => (if i ∈ T then a i else b i) = true)).card) := by\n intro T; rw [hGdef]; exact mem_swapGood a b r T\n have hT₀' := (hmemG T₀).mp hT₀\n -- no index can be an error on both sides\n have hnotboth : ∀ i, ¬ (a i = true ∧ b i = true) := by\n intro i ⟨ha, hb⟩\n have := hT₀'.1 i\n by_cases hi : i ∈ T₀\n · rw [if_pos hi] at this; rw [hb] at this; exact Bool.noConfusion this\n · rw [if_neg hi] at this; rw [ha] at this; exact Bool.noConfusion this\n set D : Finset (Fin m) := Finset.univ.filter (fun i => a i = true ∨ b i = true) with hDdef\n have hmemD : ∀ i, i ∈ D ↔ (a i = true ∨ b i = true) := by\n intro i; rw [hDdef]; simp\n -- membership in `T` is forced on `D`\n have hforced : ∀ T ∈ G, ∀ i ∈ D, (i ∈ T ↔ a i = true) := by\n intro T hT i hi\n have hcond := ((hmemG T).mp hT).1 i\n rcases (hmemD i).mp hi with ha | hb\n · have hb : b i = false := by\n cases hbb : b i\n · rfl\n · exact absurd ⟨ha, hbb⟩ (hnotboth i)\n constructor\n · intro _; exact ha\n · intro _\n by_contra hiT\n rw [if_neg hiT] at hcond\n rw [ha] at hcond; exact Bool.noConfusion hcond\n · have ha : a i = false := by\n cases haa : a i\n · rfl\n · exact absurd ⟨haa, hb⟩ (hnotboth i)\n constructor\n · intro hiT\n rw [if_pos hiT] at hcond\n rw [hb] at hcond; exact Bool.noConfusion hcond\n · intro h; rw [ha] at h; exact Bool.noConfusion h\n -- the set of second-half errors is exactly `D`\n have hDeq : ∀ T ∈ G,\n (Finset.univ.filter (fun i => (if i ∈ T then a i else b i) = true)) = D := by\n intro T hT\n ext i\n simp only [Finset.mem_filter, Finset.mem_univ, true_and]\n constructor\n · intro hv\n rw [hmemD]\n by_cases hi : i ∈ T\n · rw [if_pos hi] at hv; exact Or.inl hv\n · rw [if_neg hi] at hv; exact Or.inr hv\n · intro hi\n have hfor := hforced T hT i hi\n rcases (hmemD i).mp hi with ha | hb\n · have hiT : i ∈ T := hfor.mpr ha\n rw [if_pos hiT]; exact ha\n · have ha : a i = false := by\n cases haa : a i\n · rfl\n · exact absurd ⟨haa, hb⟩ (hnotboth i)\n have hiT : i ∉ T := by\n intro hc\n have := hfor.mp hc\n rw [ha] at this; exact Bool.noConfusion this\n rw [if_neg hiT]; exact hb\n have hrD : r ≤ D.card := by\n have := ((hmemG T₀).mp hT₀).2\n rwa [hDeq T₀ hT₀] at this\n -- the map `T ↦ T \\ D` is injective on `G`\n have hinj : Set.InjOn (fun T => T \\ D) (G : Set (Finset (Fin m))) := by\n intro T hT T' hT' hEq\n dsimp only at hEq\n have hTdec : ∀ (U : Finset (Fin m)), U ∈ G →\n U = (U \\ D) ∪ (D.filter (fun i => a i = true)) := by\n intro U hU\n ext i\n simp only [Finset.mem_union, Finset.mem_sdiff, Finset.mem_filter]\n constructor\n · intro hiU\n by_cases hiD : i ∈ D\n · exact Or.inr ⟨hiD, (hforced U hU i hiD).mp hiU⟩\n · exact Or.inl ⟨hiU, hiD⟩\n · rintro (⟨h1, _⟩ | ⟨h1, h2⟩)\n · exact h1\n · exact (hforced U hU i h1).mpr h2\n rw [hTdec T hT, hTdec T' hT', hEq]\n have hmaps : Set.MapsTo (fun T => T \\ D) (↑G : Set (Finset (Fin m)))\n (↑(((Finset.univ : Finset (Fin m)) \\ D).powerset) : Set (Finset (Fin m))) := by\n intro T _\n simp only [Finset.mem_coe, Finset.mem_powerset]\n intro i hi\n simp only [Finset.mem_sdiff] at hi ⊢\n exact ⟨Finset.mem_univ i, hi.2⟩\n have hcard := Finset.card_le_card_of_injOn (fun T => T \\ D) hmaps hinj\n have hpow : ((Finset.univ : Finset (Fin m)) \\ D).powerset.card\n = 2 ^ (m - D.card) := by\n rw [Finset.card_powerset, ← Finset.compl_eq_univ_sdiff, Finset.card_compl,\n Fintype.card_fin]\n rw [hpow] at hcard\n refine hcard.trans ?_\n exact Nat.pow_le_pow_right (by norm_num) (by omega)\n\nend Counting\n\n\n/-! ### Symmetrisation -/\n\nsection Symmetrization\nopen Finset\n\n/-- Exchange the two members of the `i`-th pair exactly for `i ∈ T`. -/\ndef swapPairs {Z : Type*} {m : ℕ} (T : Finset (Fin m)) (w : Fin m → Z × Z) : Fin m → Z × Z :=\n fun i => (if i ∈ T then (Prod.swap : Z × Z → Z × Z) else id) (w i)\n\nlemma swapPairs_apply {Z : Type*} {m : ℕ} (T : Finset (Fin m))\n (w : Fin m → Z × Z) (i : Fin m) :\n swapPairs T w i = if i ∈ T then (w i).swap else w i := by\n unfold swapPairs\n by_cases h : i ∈ T <;> simp [h]\n\nlemma measurable_swapPairs {Z : Type*} [MeasurableSpace Z] {m : ℕ} (T : Finset (Fin m)) :\n Measurable (swapPairs T : (Fin m → Z × Z) → (Fin m → Z × Z)) := by\n apply measurable_pi_lambda\n intro i\n by_cases h : i ∈ T\n · simp only [swapPairs, h, if_true]\n exact measurable_swap.comp (measurable_pi_apply i)\n · simp only [swapPairs, h, if_false]\n exact measurable_pi_apply i\n\nlemma measurePreserving_swapPairs {Z : Type*} [MeasurableSpace Z]\n (P : Measure Z) [IsProbabilityMeasure P] {m : ℕ} (T : Finset (Fin m)) :\n MeasurePreserving (swapPairs T : (Fin m → Z × Z) → (Fin m → Z × Z))\n (Measure.pi fun _ : Fin m => P.prod P) (Measure.pi fun _ : Fin m => P.prod P) := by\n have hrw : (swapPairs T : (Fin m → Z × Z) → (Fin m → Z × Z)) =\n fun a i => (if i ∈ T then (Prod.swap : Z × Z → Z × Z) else id) (a i) := rfl\n rw [hrw]\n refine measurePreserving_pi _ _ ?_\n intro i\n by_cases h : i ∈ T\n · rw [if_pos h]\n exact Measure.measurePreserving_swap\n · rw [if_neg h]\n exact MeasurePreserving.id _\n\n/-- The symmetrisation inequality: if every paired sample admits at most `N` exchange\npatterns landing in `E`, then `2 ^ m · μ E ≤ N`. -/\nlemma symmetrization_le {Z : Type*} [MeasurableSpace Z]\n (P : Measure Z) [IsProbabilityMeasure P] {m : ℕ}\n (E : Set (Fin m → Z × Z)) (hE : MeasurableSet E) (N : ℕ)\n (hcount : ∀ w : Fin m → Z × Z,\n ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' E) (1 : (Fin m → Z × Z) → ℝ≥0∞) w ≤ (N : ℝ≥0∞)) :\n 2 ^ m * (Measure.pi fun _ : Fin m => P.prod P) E ≤ (N : ℝ≥0∞) := by\n classical\n set ν : Measure (Fin m → Z × Z) := Measure.pi fun _ : Fin m => P.prod P with hν\n haveI : IsProbabilityMeasure ν := by rw [hν]; infer_instance\n have hmeas : ∀ T : Finset (Fin m), MeasurableSet (swapPairs T ⁻¹' E) :=\n fun T => (measurable_swapPairs T) hE\n have hpre : ∀ T : Finset (Fin m), ν (swapPairs T ⁻¹' E) = ν E := by\n intro T\n exact (measurePreserving_swapPairs P T).measure_preimage hE.nullMeasurableSet\n have hsum : ∑ _T ∈ (Finset.univ : Finset (Finset (Fin m))), ν E = 2 ^ m * ν E := by\n rw [Finset.sum_const, nsmul_eq_mul]\n congr 1\n rw [Finset.card_univ, Fintype.card_finset, Fintype.card_fin]\n simp\n have hint : ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))), ν (swapPairs T ⁻¹' E)\n = ∫⁻ w, ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' E) 1 w ∂ν := by\n rw [lintegral_finset_sum]\n · exact Finset.sum_congr rfl fun T _ => (lintegral_indicator_one (hmeas T)).symm\n · intro T _\n exact measurable_one.indicator (hmeas T)\n have hptw := hcount\n calc 2 ^ m * ν E = ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))), ν (swapPairs T ⁻¹' E) := by\n rw [Finset.sum_congr rfl fun T _ => hpre T, hsum]\n _ = ∫⁻ w, ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' E) 1 w ∂ν := hint\n _ ≤ ∫⁻ _w, (N : ℝ≥0∞) ∂ν := lintegral_mono hptw\n _ = (N : ℝ≥0∞) := by simp\n\nend Symmetrization\n\n\n/-! ### The ghost-sample event and its symmetrisation estimate -/\n\nsection Ghost\nopen Finset\n\nvariable {𝒳 : Type*} [MeasurableSpace 𝒳]\n\n/-- Number of mistakes of `h` on the second members of the pairs. -/\ndef sndErrCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) : ℕ :=\n (Finset.univ.filter (fun i => h.f ((w i).2).1 ≠ ((w i).2).2)).card\n\n/-- The paired sample is *bad* if some member of the (countable) family is consistent with\nall first members and errs on at least `r` second members. -/\ndef ghostEvent {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (e : ℕ → Predictor 𝒳 Bool) (r : ℕ) : Set (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n {w | ∃ k, (∀ i, (e k).f ((w i).1).1 = ((w i).1).2) ∧ r ≤ sndErrCount (e k) w}\n\ndef patA {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ} (p : Fin (m+m) → Bool)\n (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) : Fin m → Bool :=\n fun i => decide (p (Fin.castAdd m i) ≠ ((w i).1).2)\n\ndef patB {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ} (p : Fin (m+m) → Bool)\n (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) : Fin m → Bool :=\n fun i => decide (p (Fin.natAdd m i) ≠ ((w i).2).2)\n\nlemma measurableSet_ghostEvent {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (e : ℕ → Predictor 𝒳 Bool) (r : ℕ) :\n MeasurableSet (ghostEvent (m := m) e r) := by\n classical\n have hfst : ∀ i : Fin m, Measurable\n (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => (w i).1) :=\n fun i => measurable_fst.comp (measurable_pi_apply i)\n have hsnd : ∀ i : Fin m, Measurable\n (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => (w i).2) :=\n fun i => measurable_snd.comp (measurable_pi_apply i)\n have hA : ∀ h : Predictor 𝒳 Bool, MeasurableSet\n {w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) | ∀ i, h.f ((w i).1).1 = ((w i).1).2} := by\n intro h\n have : {w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) | ∀ i, h.f ((w i).1).1 = ((w i).1).2}\n = ⋂ i : Fin m, (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => (w i).1) ⁻¹'\n {z : 𝒳 × Bool | h.f z.1 = z.2} := by\n ext w; simp [Set.mem_iInter]\n rw [this]\n exact MeasurableSet.iInter fun i => (hfst i) (meas_eq_set h)\n have hB : ∀ h : Predictor 𝒳 Bool, MeasurableSet\n {w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) | r ≤ sndErrCount h w} := by\n intro h\n have hrep : {w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) | r ≤ sndErrCount h w}\n = ⋃ S ∈ (Finset.univ.filter (fun S : Finset (Fin m) => r ≤ S.card)),\n ⋂ i ∈ S, (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => (w i).2) ⁻¹'\n {z : 𝒳 × Bool | h.f z.1 ≠ z.2} := by\n ext w\n simp only [Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_iInter, Set.mem_preimage,\n Finset.mem_filter, Finset.mem_univ, true_and]\n constructor\n · intro hw\n refine ⟨Finset.univ.filter (fun i => h.f ((w i).2).1 ≠ ((w i).2).2), hw, ?_⟩\n intro i hi\n exact (Finset.mem_filter.mp hi).2\n · rintro ⟨S, hS, hmem⟩\n have hsub : S ⊆ Finset.univ.filter (fun i => h.f ((w i).2).1 ≠ ((w i).2).2) := by\n intro i hi\n exact Finset.mem_filter.mpr ⟨Finset.mem_univ i, hmem i hi⟩\n exact le_trans hS (Finset.card_le_card hsub)\n rw [hrep]\n refine Finset.measurableSet_biUnion _ ?_\n intro S _\n exact Finset.measurableSet_biInter _ (fun i _ => (hsnd i) (meas_ne_set h))\n have hrep : ghostEvent (m := m) e r =\n ⋃ k : ℕ, ({w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) |\n ∀ i, (e k).f ((w i).1).1 = ((w i).1).2} ∩\n {w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) | r ≤ sndErrCount (e k) w}) := by\n ext w\n simp [ghostEvent, Set.mem_iUnion]\n rw [hrep]\n exact MeasurableSet.iUnion fun k => (hA (e k)).inter (hB (e k))\n\n/-- The pointwise (in the paired sample) estimate feeding the symmetrisation lemma. -/\nlemma ghost_indicator_sum_le {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d : ℕ∞)) (e : ℕ → Predictor 𝒳 Bool) (he : ∀ k, e k ∈ H)\n {m : ℕ} (r : ℕ) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :\n ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' (ghostEvent e r))\n (1 : (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) → ℝ≥0∞) w\n ≤ (((∑ j ∈ Finset.Iic d, (m+m).choose j) * 2 ^ (m - r) : ℕ) : ℝ≥0∞) := by\n classical\n set x : Fin (m+m) → 𝒳 :=\n Fin.append (fun i => ((w i).1).1) (fun i => ((w i).2).1) with hx\n have hxl : ∀ i : Fin m, x (Fin.castAdd m i) = ((w i).1).1 := by\n intro i; rw [hx]; exact Fin.append_left _ _ i\n have hxr : ∀ i : Fin m, x (Fin.natAdd m i) = ((w i).2).1 := by\n intro i; rw [hx]; exact Fin.append_right _ _ i\n have hind : ∀ T : Finset (Fin m),\n Set.indicator (swapPairs T ⁻¹' (ghostEvent e r))\n (1 : (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) → ℝ≥0∞) w\n = if swapPairs T w ∈ ghostEvent e r then 1 else 0 := by\n intro T\n by_cases hT : swapPairs T w ∈ ghostEvent e r\n · have hmem : w ∈ swapPairs T ⁻¹' ghostEvent e r := hT\n rw [if_pos hT, Set.indicator_of_mem hmem]\n rfl\n · have hmem : w ∉ swapPairs T ⁻¹' ghostEvent e r := hT\n rw [if_neg hT, Set.indicator_of_notMem hmem]\n rw [Finset.sum_congr rfl (fun T _ => hind T), Finset.sum_boole]\n have hsub : (Finset.univ.filter (fun T : Finset (Fin m) => swapPairs T w ∈ ghostEvent e r))\n ⊆ (vcTrace H x).biUnion\n (fun t => swapGood (patA (fun j => decide (j ∈ t)) w)\n (patB (fun j => decide (j ∈ t)) w) r) := by\n intro T hT\n obtain ⟨k, hcons, hcnt⟩ := (Finset.mem_filter.mp hT).2\n set h := e k with hh\n set t : Finset (Fin (m+m)) := Finset.univ.filter (fun j => h.f (x j) = true) with ht\n have hpt : ∀ j, (decide (j ∈ t)) = h.f (x j) := by\n intro j\n rw [ht]\n simp\n have htmem : t ∈ vcTrace H x := by\n rw [mem_vcTrace]\n refine ⟨h, ?_, ?_⟩\n · rw [hh]; exact he k\n · intro j; rw [ht]; simp\n refine Finset.mem_biUnion.mpr ⟨t, htmem, ?_⟩\n rw [mem_swapGood]\n constructor\n · intro i\n have hci := hcons i\n rw [swapPairs_apply] at hci\n by_cases hi : i ∈ T\n · rw [if_pos hi] at hci ⊢\n rw [patB, hpt, hxr]\n simp only [decide_eq_false_iff_not, not_not]\n exact hci\n · rw [if_neg hi] at hci ⊢\n rw [patA, hpt, hxl]\n simp only [decide_eq_false_iff_not, not_not]\n exact hci\n · refine le_trans hcnt (le_of_eq ?_)\n rw [sndErrCount]\n apply congrArg\n apply Finset.filter_congr\n intro i _\n by_cases hi : i ∈ T\n · rw [swapPairs_apply, if_pos hi, if_pos hi, patA, hpt, hxl]\n simp only [decide_eq_true_eq]\n exact Iff.rfl\n · rw [swapPairs_apply, if_neg hi, if_neg hi, patB, hpt, hxr]\n simp only [decide_eq_true_eq]\n have hcard : (Finset.univ.filter\n (fun T : Finset (Fin m) => swapPairs T w ∈ ghostEvent e r)).card\n ≤ (∑ j ∈ Finset.Iic d, (m+m).choose j) * 2 ^ (m - r) := by\n calc (Finset.univ.filter\n (fun T : Finset (Fin m) => swapPairs T w ∈ ghostEvent e r)).card\n ≤ ((vcTrace H x).biUnion\n (fun t => swapGood (patA (fun j => decide (j ∈ t)) w)\n (patB (fun j => decide (j ∈ t)) w) r)).card :=\n Finset.card_le_card hsub\n _ ≤ ∑ t ∈ vcTrace H x, (swapGood (patA (fun j => decide (j ∈ t)) w)\n (patB (fun j => decide (j ∈ t)) w) r).card :=\n Finset.card_biUnion_le\n _ ≤ ∑ _t ∈ vcTrace H x, 2 ^ (m - r) :=\n Finset.sum_le_sum fun t _ => card_swap_good_le _ _ _\n _ = (vcTrace H x).card * 2 ^ (m - r) := by\n rw [Finset.sum_const, smul_eq_mul]\n _ ≤ (∑ j ∈ Finset.Iic d, (m+m).choose j) * 2 ^ (m - r) :=\n Nat.mul_le_mul_right _ (vcTrace_card_le_sauer H x hvc)\n exact_mod_cast Nat.cast_le.mpr hcard\n\nend Ghost\n\n\n/-! ### A Chebyshev lower bound for the number of mistakes on a fresh sample -/\n\nsection Cheb\nopen Finset ProbabilityTheory\n\nlemma half_le_measure_many_errors {Z : Type*} [MeasurableSpace Z]\n (P : Measure Z) [IsProbabilityMeasure P] {m : ℕ}\n (f : Z → ℝ) (hf : Measurable f) (hf0 : ∀ z, 0 ≤ f z) (hf1 : ∀ z, f z ≤ 1)\n {p α : ℝ} (hint : ∫ z, f z ∂P = p) (hα0 : 0 < α) (hαp : α ≤ p)\n (hm : 8 ≤ α * m) :\n ENNReal.ofReal (1/2) ≤\n (Measure.pi fun _ : Fin m => P) {S | α * m / 2 ≤ ∑ i, f (S i)} := by\n classical\n set μ : Measure (Fin m → Z) := Measure.pi fun _ : Fin m => P with hμ\n haveI : IsProbabilityMeasure μ := by rw [hμ]; infer_instance\n have hp0 : 0 < p := lt_of_lt_of_le hα0 hαp\n have hmR : (0:ℝ) < m := by nlinarith\n have hfint : Integrable f P :=\n Integrable.of_mem_Icc 0 1 hf.aemeasurable\n (Filter.Eventually.of_forall fun z => ⟨hf0 z, hf1 z⟩)\n have hp1 : p ≤ 1 := by\n rw [← hint]\n have := integral_mono hfint (integrable_const (1:ℝ)) (fun z => hf1 z)\n simpa using this\n set Xi : Fin m → (Fin m → Z) → ℝ := fun i S => f (S i) with hXi\n have hXim : ∀ i, Measurable (Xi i) := fun i => hf.comp (measurable_pi_apply i)\n have hmemLp : ∀ i, MemLp (Xi i) 2 μ := by\n intro i\n refine MemLp.of_bound (hXim i).aestronglyMeasurable 1 ?_\n refine Filter.Eventually.of_forall fun S => ?_\n rw [Real.norm_eq_abs, abs_of_nonneg (hf0 _)]\n exact hf1 _\n have hEi : ∀ i, ∫ S, Xi i S ∂μ = p := by\n intro i\n rw [hμ, hXi]\n rw [integral_comp_eval hf.aestronglyMeasurable]\n exact hint\n have hindep : iIndepFun Xi μ := by\n rw [hμ, hXi]\n exact iIndepFun_pi (fun _ => hf.aemeasurable)\n have hvari : ∀ i, variance (Xi i) μ ≤ p := by\n intro i\n have hb := variance_le_sub_mul_sub (μ := μ) (X := Xi i) (a := 0) (b := 1)\n (Filter.Eventually.of_forall fun S => ⟨hf0 _, hf1 _⟩) (hXim i).aemeasurable\n rw [hEi i] at hb\n nlinarith [hb, hp0, hp1]\n set X : (Fin m → Z) → ℝ := ∑ i, Xi i with hX\n have hXapp : ∀ S, X S = ∑ i, f (S i) := by\n intro S\n rw [hX]\n simp [hXi]\n have hMemX : MemLp X 2 μ := by\n rw [hX]\n exact memLp_finset_sum' _ (fun i _ => hmemLp i)\n have hEX : ∫ S, X S ∂μ = m * p := by\n simp only [hX, Finset.sum_apply]\n rw [integral_finset_sum _ (fun i _ => (hmemLp i).integrable (by norm_num))]\n simp [hEi]\n have hVarX : variance X μ ≤ m * p := by\n rw [hX]\n rw [ProbabilityTheory.IndepFun.variance_sum (fun i _ => hmemLp i)\n (fun i _ j _ hij => hindep.indepFun hij)]\n calc ∑ i : Fin m, variance (Xi i) μ ≤ ∑ _i : Fin m, p :=\n Finset.sum_le_sum fun i _ => hvari i\n _ = m * p := by simp [mul_comm]\n set c : ℝ := (m : ℝ) * p / 2 with hc\n have hc0 : 0 < c := by rw [hc]; positivity\n have hcheb := ProbabilityTheory.meas_ge_le_variance_div_sq (μ := μ) hMemX hc0\n rw [hEX] at hcheb\n -- the bad set\n have hsub : {S : Fin m → Z | ¬ (α * m / 2 ≤ ∑ i, f (S i))}\n ⊆ {S | c ≤ |X S - (m : ℝ) * p|} := by\n intro S hS\n simp only [Set.mem_setOf_eq, not_le] at hS\n have h1 : X S < α * m / 2 := by rw [hXapp]; exact hS\n have h2 : α * m / 2 ≤ c := by\n rw [hc]\n have : α * (m:ℝ) ≤ (m:ℝ) * p := by nlinarith\n linarith\n have h3 : X S < c := lt_of_lt_of_le h1 h2\n have h4 : (m:ℝ) * p - X S ≥ c := by rw [hc] at h3 ⊢; linarith\n rw [Set.mem_setOf_eq, abs_sub_comm, abs_of_nonneg (by linarith)]\n linarith\n have hbadle : μ {S : Fin m → Z | ¬ (α * m / 2 ≤ ∑ i, f (S i))} ≤ ENNReal.ofReal (1/2) := by\n refine le_trans (measure_mono hsub) (le_trans hcheb ?_)\n apply ENNReal.ofReal_le_ofReal\n rw [div_le_iff₀ (by positivity)]\n have hmp : (8:ℝ) ≤ (m:ℝ) * p := by nlinarith\n have hcsq : c^2 = ((m:ℝ)*p)^2/4 := by rw [hc]; ring\n rw [hcsq]\n nlinarith [hVarX, hmp]\n -- conclude\n have hGmeas : MeasurableSet {S : Fin m → Z | α * m / 2 ≤ ∑ i, f (S i)} := by\n have : Measurable (fun S : Fin m → Z => ∑ i, f (S i)) := by\n apply Finset.measurable_sum\n intro i _\n exact hf.comp (measurable_pi_apply i)\n exact measurableSet_le measurable_const this\n have hcompl : {S : Fin m → Z | α * m / 2 ≤ ∑ i, f (S i)}ᶜ\n = {S : Fin m → Z | ¬ (α * m / 2 ≤ ∑ i, f (S i))} := rfl\n have hadd := measure_add_measure_compl (μ := μ) hGmeas\n rw [hcompl, measure_univ] at hadd\n have hhalf : ENNReal.ofReal (1/2) + ENNReal.ofReal (1/2) = 1 := by\n rw [← ENNReal.ofReal_add (by norm_num) (by norm_num)]\n norm_num\n have hfin : ENNReal.ofReal (1/2) + ENNReal.ofReal (1/2)\n ≤ μ {S : Fin m → Z | α * m / 2 ≤ ∑ i, f (S i)} + ENNReal.ofReal (1/2) := by\n rw [hhalf, ← hadd]\n exact add_le_add le_rfl hbadle\n exact (ENNReal.add_le_add_iff_right (by simp)).mp hfin\n\nend Cheb\n\n\n/-! ### The ghost-sample step -/\n\nsection GhostLow\nopen Finset\n\ndef errCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ} (h : Predictor 𝒳 Bool)\n (S : Fin m → 𝒳 × Bool) : ℕ :=\n (Finset.univ.filter (fun i => h.f (S i).1 ≠ (S i).2)).card\n\nlemma errCount_eq_sum {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ} (h : Predictor 𝒳 Bool)\n (S : Fin m → 𝒳 × Bool) :\n ((errCount h S : ℕ) : ℝ) = ∑ i, zeroOneLoss h (S i) := by\n rw [errCount]\n rw [← Finset.sum_boole]\n apply Finset.sum_congr rfl\n intro i _\n by_cases hi : h.f (S i).1 = (S i).2\n · rw [if_neg (by simpa using hi)]\n simp [zeroOneLoss, hi]\n · rw [if_pos (by simpa using hi)]\n simp [zeroOneLoss, hi]\n\nlemma measurableSet_errCount_ge {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) (r : ℕ) :\n MeasurableSet {S : Fin m → 𝒳 × Bool | r ≤ errCount h S} := by\n classical\n have hrep : {S : Fin m → 𝒳 × Bool | r ≤ errCount h S}\n = ⋃ S₀ ∈ (Finset.univ.filter (fun S₀ : Finset (Fin m) => r ≤ S₀.card)),\n ⋂ i ∈ S₀, (fun S : Fin m → 𝒳 × Bool => S i) ⁻¹'\n {z : 𝒳 × Bool | h.f z.1 ≠ z.2} := by\n ext S\n simp only [Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_iInter, Set.mem_preimage,\n Finset.mem_filter, Finset.mem_univ, true_and]\n constructor\n · intro hS\n refine ⟨Finset.univ.filter (fun i => h.f (S i).1 ≠ (S i).2), hS, ?_⟩\n intro i hi\n exact (Finset.mem_filter.mp hi).2\n · rintro ⟨S₀, hS₀, hmem⟩\n have hsub : S₀ ⊆ Finset.univ.filter (fun i => h.f (S i).1 ≠ (S i).2) := by\n intro i hi\n exact Finset.mem_filter.mpr ⟨Finset.mem_univ i, hmem i hi⟩\n exact le_trans hS₀ (Finset.card_le_card hsub)\n rw [hrep]\n refine Finset.measurableSet_biUnion _ ?_\n intro S₀ _\n exact Finset.measurableSet_biInter _\n (fun i _ => (measurable_pi_apply i) (meas_ne_set h))\n\nlemma measurableSet_allCorrect {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) :\n MeasurableSet {S : Fin m → 𝒳 × Bool | ∀ i, h.f (S i).1 = (S i).2} := by\n have hrep : {S : Fin m → 𝒳 × Bool | ∀ i, h.f (S i).1 = (S i).2}\n = ⋂ i : Fin m, (fun S : Fin m → 𝒳 × Bool => S i) ⁻¹' {z : 𝒳 × Bool | h.f z.1 = z.2} := by\n ext S; simp [Set.mem_iInter]\n rw [hrep]\n exact MeasurableSet.iInter fun i => (measurable_pi_apply i) (meas_eq_set h)\n\n/-- The two halves of a paired sample are independent. -/\nlemma pi_prod_inter {Z : Type*} [MeasurableSpace Z] (P : Measure Z) [IsProbabilityMeasure P]\n {m : ℕ} {U V : Set (Fin m → Z)} (hU : MeasurableSet U) (hV : MeasurableSet V) :\n (Measure.pi fun _ : Fin m => P.prod P)\n ({w : Fin m → Z × Z | (fun i => (w i).1) ∈ U} ∩\n {w : Fin m → Z × Z | (fun i => (w i).2) ∈ V})\n = (Measure.pi fun _ : Fin m => P) U * (Measure.pi fun _ : Fin m => P) V := by\n have hmp := measurePreserving_arrowProdEquivProdArrow Z Z (Fin m)\n (fun _ => P) (fun _ => P)\n have hset : ({w : Fin m → Z × Z | (fun i => (w i).1) ∈ U} ∩\n {w : Fin m → Z × Z | (fun i => (w i).2) ∈ V})\n = (MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin m)) ⁻¹' (U ×ˢ V) := by\n ext w\n simp [MeasurableEquiv.arrowProdEquivProdArrow, Equiv.arrowProdEquivProdArrow,\n Set.mem_prod]\n rw [hset, hmp.measure_preimage (hU.prod hV).nullMeasurableSet, Measure.prod_prod]\n\nlemma ghost_lower {𝒳 : Type*} [MeasurableSpace 𝒳]\n (e : ℕ → Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n {α : ℝ} (hα0 : 0 < α) {m : ℕ} (hm : 8 ≤ α * m) :\n ENNReal.ofReal (1/2) *\n (Measure.pi fun _ : Fin m => P)\n {S | ∃ k, (∀ i, (e k).f (S i).1 = (S i).2) ∧ α < ordinaryError (e k) P}\n ≤ (Measure.pi fun _ : Fin m => P.prod P) (ghostEvent e ⌈α * m / 2⌉₊) := by\n classical\n set r : ℕ := ⌈α * (m:ℝ) / 2���₊ with hr\n set Pm : Measure (Fin m → 𝒳 × Bool) := Measure.pi fun _ : Fin m => P with hPm\n set ν : Measure (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n Measure.pi fun _ : Fin m => P.prod P with hν\n set C : ℕ → Set (Fin m → 𝒳 × Bool) :=\n fun k => {S | ∀ i, (e k).f (S i).1 = (S i).2} with hC\n set g : ℕ → Set (Fin m → 𝒳 × Bool) :=\n fun k => if α < ordinaryError (e k) P then C k else ∅ with hg\n set G : ℕ → Set (Fin m → 𝒳 × Bool) :=\n fun k => {S | r ≤ errCount (e k) S} with hG\n have hCmeas : ∀ k, MeasurableSet (C k) := fun k => measurableSet_allCorrect (e k)\n have hgmeas : ∀ k, MeasurableSet (g k) := by\n intro k\n rw [hg]\n by_cases hk : α < ordinaryError (e k) P\n · simp only [hk, if_true]; exact hCmeas k\n · simp only [hk, if_false]; exact MeasurableSet.empty\n have hGmeas : ∀ k, MeasurableSet (G k) :=\n fun k => measurableSet_errCount_ge (e k) r\n set D : ℕ → Set (Fin m → 𝒳 × Bool) := disjointed g with hD\n have hDmeas : ∀ k, MeasurableSet (D k) := fun k => MeasurableSet.disjointed hgmeas k\n have hDle : ∀ k, D k ⊆ g k := fun k => disjointed_le g k\n set F : ℕ → Set (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n fun k => {w | (fun i => (w i).1) ∈ D k} ∩ {w | (fun i => (w i).2) ∈ G k} with hF\n have hFmeas : ∀ k, MeasurableSet (F k) := by\n intro k\n refine MeasurableSet.inter ?_ ?_\n · exact (measurable_pi_lambda _ (fun i => measurable_fst.comp (measurable_pi_apply i)))\n (hDmeas k)\n · exact (measurable_pi_lambda _ (fun i => measurable_snd.comp (measurable_pi_apply i)))\n (hGmeas k)\n have hFdisj : Pairwise (Function.onFun Disjoint F) := by\n intro i j hij\n have hd := disjoint_disjointed g hij\n refine Set.disjoint_left.mpr ?_\n intro w hw1 hw2\n exact Set.disjoint_left.mp hd hw1.1 hw2.1\n have hFsub : (⋃ k, F k) ⊆ ghostEvent e r := by\n intro w hw\n obtain ⟨k, hk⟩ := Set.mem_iUnion.mp hw\n have hk1 : (fun i => (w i).1) ∈ D k := hk.1\n have hk2 : (fun i => (w i).2) ∈ G k := hk.2\n have hkg : (fun i => (w i).1) ∈ g k := hDle k hk1\n by_cases hc : α < ordinaryError (e k) P\n · have hkC : (fun i => (w i).1) ∈ C k := by\n rw [hg] at hkg; simpa [hc] using hkg\n refine ⟨k, ?_, ?_⟩\n · intro i; exact hkC i\n · exact hk2\n · rw [hg] at hkg\n simp only [hc, if_false] at hkg\n exact absurd hkg (Set.notMem_empty _)\n have hstep2 : ∀ k, ENNReal.ofReal (1/2) * Pm (D k) ≤ ν (F k) := by\n intro k\n have hprod : ν (F k) = Pm (D k) * Pm (G k) := by\n rw [hF, hν, hPm]\n exact pi_prod_inter P (hDmeas k) (hGmeas k)\n rw [hprod]\n by_cases hc : α < ordinaryError (e k) P\n · have hhalf : ENNReal.ofReal (1/2) ≤ Pm (G k) := by\n have hGeq : G k = {S : Fin m → 𝒳 × Bool |\n α * (m:ℝ) / 2 ≤ ∑ i, zeroOneLoss (e k) (S i)} := by\n ext S\n rw [hG]\n simp only [Set.mem_setOf_eq]\n rw [← errCount_eq_sum, hr]\n exact Nat.ceil_le\n rw [hGeq, hPm]\n exact half_le_measure_many_errors P (zeroOneLoss (e k))\n (zeroOneLoss_measurable (e k)) (zeroOneLoss_nonneg (e k)) (zeroOneLoss_le_one (e k))\n (integral_zeroOneLoss (e k) P) hα0 (le_of_lt hc) hm\n calc ENNReal.ofReal (1/2) * Pm (D k) = Pm (D k) * ENNReal.ofReal (1/2) := by ring\n _ ≤ Pm (D k) * Pm (G k) := by exact mul_le_mul_left' hhalf _\n · have hDempty : D k = ∅ := by\n have : g k = ∅ := by rw [hg]; simp [hc]\n exact Set.eq_empty_of_subset_empty (this ▸ hDle k)\n rw [hDempty]\n simp\n have hAeq : {S : Fin m → 𝒳 × Bool |\n ∃ k, (∀ i, (e k).f (S i).1 = (S i).2) ∧ α < ordinaryError (e k) P} = ⋃ k, g k := by\n ext S\n simp only [Set.mem_setOf_eq, Set.mem_iUnion]\n constructor\n · rintro ⟨k, hcons, hgt⟩\n exact ⟨k, by rw [hg]; simp only [hgt, if_true]; exact hcons⟩\n · rintro ⟨k, hk⟩\n by_cases hc : α < ordinaryError (e k) P\n · rw [hg] at hk\n simp only [hc, if_true] at hk\n exact ⟨k, hk, hc⟩\n · rw [hg] at hk\n simp only [hc, if_false] at hk\n exact absurd hk (Set.notMem_empty _)\n rw [hAeq, ← iUnion_disjointed (f := g), ← hD]\n rw [measure_iUnion (disjoint_disjointed g) hDmeas]\n calc ENNReal.ofReal (1/2) * ∑' k, Pm (D k)\n = ∑' k, ENNReal.ofReal (1/2) * Pm (D k) := ENNReal.tsum_mul_left.symm\n _ ≤ ∑' k, ν (F k) := ENNReal.tsum_le_tsum hstep2\n _ = ν (⋃ k, F k) := (measure_iUnion hFdisj hFmeas).symm\n _ ≤ ν (ghostEvent e r) := measure_mono hFsub\n\nend GhostLow\n\n\n/-! ### The master VC estimate in the realizable case -/\n\nsection Master\nopen Finset\n\ntheorem realizable_vc_master {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d : ℕ∞)) (e : ℕ → Predictor 𝒳 Bool) (he : ∀ k, e k ∈ H)\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n {α : ℝ} (hα0 : 0 < α) (hα1 : α ≤ 1) {m : ℕ} (hm : 8 ≤ α * m) :\n (2 : ℝ≥0∞) ^ (⌈α * (m:ℝ) / 2⌉₊) *\n (Measure.pi fun _ : Fin m => P)\n {S | ∃ k, (∀ i, (e k).f (S i).1 = (S i).2) ∧ α < ordinaryError (e k) P}\n ≤ 2 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ≥0∞) := by\n classical\n set r : ℕ := ⌈α * (m:ℝ) / 2⌉₊ with hr\n set Γ : ℕ := ∑ j ∈ Finset.Iic d, (m+m).choose j with hΓ\n set a : ℝ≥0∞ := (Measure.pi fun _ : Fin m => P)\n {S | ∃ k, (∀ i, (e k).f (S i).1 = (S i).2) ∧ α < ordinaryError (e k) P} with ha\n set ν : Measure (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n Measure.pi fun _ : Fin m => P.prod P with hν\n have hmR : (0:ℝ) ≤ (m:ℝ) := Nat.cast_nonneg m\n have hrm : r ≤ m := by\n rw [hr]\n apply Nat.ceil_le.mpr\n nlinarith\n have hsym : 2 ^ m * ν (ghostEvent e r) ≤ ((Γ * 2 ^ (m - r) : ℕ) : ℝ≥0∞) := by\n rw [hν]\n exact symmetrization_le P (ghostEvent e r) (measurableSet_ghostEvent e r) _\n (ghost_indicator_sum_le H hvc e he r)\n have hgl : ENNReal.ofReal (1/2) * a ≤ ν (ghostEvent e r) := by\n rw [ha, hν, hr]\n exact ghost_lower e P hα0 hm\n have hchain : 2 ^ m * (ENNReal.ofReal (1/2) * a) ≤ (Γ : ℝ≥0∞) * 2 ^ (m - r) := by\n have h1 : (2:ℝ≥0∞) ^ m * (ENNReal.ofReal (1/2) * a) ≤ 2 ^ m * ν (ghostEvent e r) :=\n mul_le_mul_left' hgl _\n have h2 : ((Γ * 2 ^ (m - r) : ℕ) : ℝ≥0∞) = (Γ : ℝ≥0∞) * 2 ^ (m - r) := by\n push_cast; ring\n rw [← h2]\n exact le_trans h1 hsym\n have hmul : 2 ^ r * (2 ^ m * (ENNReal.ofReal (1/2) * a))\n ≤ 2 ^ r * ((Γ : ℝ≥0∞) * 2 ^ (m - r)) := by gcongr\n have hpow : (2:ℝ≥0∞) ^ r * ((Γ : ℝ≥0∞) * 2 ^ (m - r)) = 2 ^ m * (Γ : ℝ≥0∞) := by\n have : (2:ℝ≥0∞) ^ r * 2 ^ (m - r) = 2 ^ m := by\n rw [← pow_add]\n congr 1\n omega\n calc (2:ℝ≥0∞) ^ r * ((Γ : ℝ≥0∞) * 2 ^ (m - r))\n = ((2:ℝ≥0∞) ^ r * 2 ^ (m - r)) * (Γ : ℝ≥0∞) := by ring\n _ = 2 ^ m * (Γ : ℝ≥0∞) := by rw [this]\n have hleft : (2:ℝ≥0∞) ^ r * (2 ^ m * (ENNReal.ofReal (1/2) * a))\n = 2 ^ m * (2 ^ r * (ENNReal.ofReal (1/2) * a)) := by ring\n rw [hleft, hpow] at hmul\n have hcancel : (2:ℝ≥0∞) ^ r * (ENNReal.ofReal (1/2) * a) ≤ (Γ : ℝ≥0∞) := by\n have h2 : ((2:ℝ≥0∞) ^ m) ≠ 0 := by positivity\n have h2' : ((2:ℝ≥0∞) ^ m) ≠ ⊤ := by\n exact ENNReal.pow_ne_top (by norm_num)\n exact (ENNReal.mul_le_mul_left h2 h2').mp hmul\n have hof : ENNReal.ofReal (1/2) * 2 = 1 := by\n rw [show (2:ℝ≥0∞) = ENNReal.ofReal 2 by simp, ← ENNReal.ofReal_mul (by norm_num)]\n norm_num\n calc (2:ℝ≥0∞) ^ r * a = 2 * (2 ^ r * (ENNReal.ofReal (1/2) * a)) := by\n rw [show (2:ℝ≥0∞) * (2 ^ r * (ENNReal.ofReal (1/2) * a))\n = (ENNReal.ofReal (1/2) * 2) * (2 ^ r * a) by ring, hof, one_mul]\n _ ≤ 2 * (Γ : ℝ≥0∞) := by gcongr\n\nend Master\n\n\n/-! ### The consistent learner over a countable dense subfamily -/\n\nsection PAC\nopen Finset\n\nopen Classical in\n/-- The first member of the enumerated family which is consistent with the sample. -/\nnoncomputable def firstConsistent {𝒳 : Type*} [MeasurableSpace 𝒳]\n (e : ℕ → Predictor 𝒳 Bool) {n : ℕ} (S : Fin n → 𝒳 × Bool) : Predictor 𝒳 Bool :=\n if h : ∃ k, ∀ i, (e k).f (S i).1 = (S i).2 then e (Nat.find h) else e 0\n\nlemma firstConsistent_spec {𝒳 : Type*} [MeasurableSpace 𝒳]\n (e : ℕ → Predictor 𝒳 Bool) {n : ℕ} (S : Fin n → 𝒳 × Bool)\n (h : ∃ k, ∀ i, (e k).f (S i).1 = (S i).2) :\n ∃ k, (∀ i, (e k).f (S i).1 = (S i).2) ∧ e k = firstConsistent e S := by\n classical\n refine ⟨Nat.find h, Nat.find_spec h, ?_⟩\n rw [firstConsistent, dif_pos h]\n\nlemma realizable_PAC_at_size {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d : ℕ∞))\n (H₀ : Set (Predictor 𝒳 Bool)) (hH₀ : H₀ ⊆ H)\n (e : ℕ → Predictor 𝒳 Bool) (hrange : H₀ = Set.range e)\n (hdense : ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool, (∀ i, s i ∈ H₀) ∧\n ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x)\n {α δ : ℝ} (hα0 : 0 < α) (hα1 : α ≤ 1) (hδ0 : 0 < δ) {m : ℕ} (hm : 8 ≤ α * m)\n (hbound : 2 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n ≤ 2 ^ (⌈α * (m:ℝ) / 2⌉₊) * δ) :\n OrdinaryRealizablePACAtSize H α δ m := by\n classical\n have he : ∀ k, e k ∈ H := by\n intro k\n apply hH₀\n rw [hrange]\n exact ⟨k, rfl⟩\n refine ⟨fun S => firstConsistent e S, ?_⟩\n intro P _ hreal\n obtain ⟨hstar, hstarH, hstar0⟩ := hreal\n set r : ℕ := ⌈α * (m:ℝ) / 2⌉₊ with hr\n set Γ : ℕ := ∑ j ∈ Finset.Iic d, (m+m).choose j with hΓ\n set Pm : Measure (Fin m → 𝒳 × Bool) := Measure.pi fun _ : Fin m => P with hPm\n set N : Set (Fin m → 𝒳 × Bool) :=\n {S | ¬ ∃ k, ∀ i, (e k).f (S i).1 = (S i).2} with hN\n set A : Set (Fin m → 𝒳 × Bool) :=\n {S | ∃ k, (∀ i, (e k).f (S i).1 = (S i).2) ∧ α < ordinaryError (e k) P} with hA\n have hsub : {S : Fin m → 𝒳 × Bool | α < ordinaryError (firstConsistent e S) P} ⊆ N ∪ A := by\n intro S hS\n by_cases hex : ∃ k, ∀ i, (e k).f (S i).1 = (S i).2\n · right\n obtain ⟨k, hcons, hk⟩ := firstConsistent_spec e S hex\n exact ⟨k, hcons, by rw [hk]; exact hS⟩\n · exact Or.inl hex\n -- the sample is almost surely consistent with some member of the family\n have hstarz : P {z : 𝒳 × Bool | hstar.f z.1 ≠ z.2} = 0 := by\n have hor := (ENNReal.toReal_eq_zero_iff _).mp (by simpa [ordinaryError] using hstar0)\n exact hor.resolve_right (measure_ne_top _ _)\n have hN0 : Pm N = 0 := by\n have hNsub : N ⊆ ⋃ j : Fin m, {S : Fin m → 𝒳 × Bool | hstar.f (S j).1 ≠ (S j).2} := by\n intro S hS\n by_contra hcon\n apply hS\n have hall : ∀ j : Fin m, hstar.f (S j).1 = (S j).2 := by\n intro j\n by_contra hj\n exact hcon (Set.mem_iUnion.mpr ⟨j, hj⟩)\n obtain ⟨s, hsH₀, hslim⟩ := hdense hstar hstarH\n have hev : ∀ᶠ i in Filter.atTop, ∀ j : Fin m, (s i).f (S j).1 = hstar.f (S j).1 := by\n rw [Filter.eventually_all]\n intro j\n exact hslim (S j).1\n obtain ⟨i₀, hi₀⟩ := hev.exists\n obtain ⟨k, hk⟩ : ∃ k, e k = s i₀ := by\n have := hsH₀ i₀\n rw [hrange] at this\n obtain ⟨k, hk⟩ := this\n exact ⟨k, hk⟩\n refine ⟨k, ?_⟩\n intro j\n rw [hk, hi₀ j, hall j]\n refine measure_mono_null hNsub ?_\n have hz : ∀ j : Fin m, Pm {S : Fin m → 𝒳 × Bool | hstar.f (S j).1 ≠ (S j).2} = 0 := by\n intro j\n have hpre : {S : Fin m → 𝒳 × Bool | hstar.f (S j).1 ≠ (S j).2}\n = (fun S : Fin m → 𝒳 × Bool => S j) ⁻¹' {z : 𝒳 × Bool | hstar.f z.1 ≠ z.2} := rfl\n rw [hpre, hPm]\n rw [(measurePreserving_eval (fun _ : Fin m => P) j).measure_preimage\n (meas_ne_set hstar).nullMeasurableSet]\n exact hstarz\n exact measure_iUnion_null hz\n -- the VC bound on the remaining event\n have hmaster := realizable_vc_master H hvc e he P hα0 hα1 hm\n have hΓpos : (0:ℝ) < (Γ : ℝ) := by\n rw [hΓ]\n have : (0:ℕ) < ∑ j ∈ Finset.Iic d, (m+m).choose j := by\n apply Finset.sum_pos'\n · intro j _; exact Nat.zero_le _\n · exact ⟨0, Finset.mem_Iic.mpr (Nat.zero_le d), by simp⟩\n exact_mod_cast this\n have hcast : 2 * ((Γ : ℕ) : ℝ≥0∞) ≤ (2:ℝ≥0∞) ^ r * ENNReal.ofReal δ := by\n have h1 : 2 * ((Γ : ℕ) : ℝ≥0∞) = ENNReal.ofReal (2 * (Γ : ℝ)) := by\n rw [ENNReal.ofReal_mul (by norm_num)]\n simp\n have h2 : (2:ℝ≥0∞) ^ r * ENNReal.ofReal δ = ENNReal.ofReal (2 ^ r * δ) := by\n rw [ENNReal.ofReal_mul (by positivity)]\n congr 1\n rw [ENNReal.ofReal_pow (by norm_num)]\n simp\n rw [h1, h2]\n exact ENNReal.ofReal_le_ofReal hbound\n have hAle : Pm A ≤ ENNReal.ofReal δ := by\n have hkey : (2:ℝ≥0∞) ^ r * Pm A ≤ (2:ℝ≥0∞) ^ r * ENNReal.ofReal δ := by\n refine le_trans ?_ hcast\n rw [hPm, hA, hr]\n exact hmaster\n have h2 : ((2:ℝ≥0∞) ^ r) ≠ 0 := by positivity\n have h2' : ((2:ℝ≥0∞) ^ r) ≠ ⊤ := ENNReal.pow_ne_top (by norm_num)\n exact (ENNReal.mul_le_mul_left h2 h2').mp hkey\n calc Pm {S : Fin m → 𝒳 × Bool | α < ordinaryError (firstConsistent e S) P}\n ≤ Pm (N ∪ A) := measure_mono hsub\n _ ≤ Pm N + Pm A := measure_union_le _ _\n _ = Pm A := by rw [hN0, zero_add]\n _ ≤ ENNReal.ofReal δ := hAle\n\nend PAC\n\n\n/-! ### Choice of the sample size -/\n\nsection Numerics\nopen Finset\n\nlemma numeric_core {D E L t s u : ℝ}\n (hD1 : 1 ≤ D) (hE0 : 0 ≤ E) (hL1 : 0.693 ≤ L) (hL2 : L ≤ 0.694)\n (ht : 16 * (D + E) ≤ t) (hs : s ≤ t/8 + 2.8 * D) (hu : u ≤ E) :\n L + s + u ≤ (t/2) * L := by\n have ht0 : 0 ≤ t := by linarith\n have hmul : t * 0.693 ≤ t * L := mul_le_mul_of_nonneg_left hL1 ht0\n linarith\n\nlemma realizable_numeric {d : ℕ} (hd : 0 < d) {α δ : ℝ} (hα0 : 0 < α) (hα1 : α < 1)\n (hδ0 : 0 < δ) (hδ1 : δ < 1/4) (m : ℕ)\n (hm : 16 * ((d:ℝ) * (1 + Real.log (1/α)) + Real.log (2/δ)) / α ≤ m) :\n 8 ≤ α * m ∧ d ≤ m + m ∧\n 2 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n ≤ 2 ^ (⌈α * (m:ℝ) / 2⌉₊) * δ := by\n have hdR : (1:ℝ) ≤ (d:ℝ) := by exact_mod_cast hd\n have hdpos : (0:ℝ) < (d:ℝ) := by linarith\n have hd0 : (0:ℝ) ≤ (d:ℝ) := le_of_lt hdpos\n have hlogα : 0 ≤ Real.log (1/α) := Real.log_nonneg (by rw [le_div_iff₀ hα0]; linarith)\n have hD1 : (1:ℝ) ≤ (d:ℝ) * (1 + Real.log (1/α)) := by nlinarith\n have hE0 : (0:ℝ) ≤ Real.log (2/δ) := Real.log_nonneg (by rw [le_div_iff₀ hδ0]; linarith)\n have hB1 : (1:ℝ) ≤ (d:ℝ) * (1 + Real.log (1/α)) + Real.log (2/δ) := by linarith\n have hMpos : (0:ℝ) < (m:ℝ) := by\n have hq : (0:ℝ) < 16 * ((d:ℝ) * (1 + Real.log (1/α)) + Real.log (2/δ)) / α := by\n apply div_pos (by linarith) hα0\n linarith\n have ht : 16 * ((d:ℝ) * (1 + Real.log (1/α)) + Real.log (2/δ)) ≤ α * (m:ℝ) := by\n rw [div_le_iff₀ hα0] at hm\n linarith\n have hαm8 : 8 ≤ α * (m:ℝ) := by linarith\n have hdm : d ≤ m + m := by\n have hle : (d:ℝ) ≤ (m:ℝ) := by nlinarith\n have : d ≤ m := by exact_mod_cast hle\n omega\n refine ⟨hαm8, hdm, ?_⟩\n have hL1 : (0.693:ℝ) ≤ Real.log 2 := le_of_lt (by linarith [Real.log_two_gt_d9])\n have hL2 : Real.log 2 ≤ 0.694 := le_of_lt (by linarith [Real.log_two_lt_d9])\n obtain ⟨X, hX⟩ : ∃ X : ℝ, X = Real.exp 1 * ((m:ℝ)+(m:ℝ)) / (d:ℝ) := ⟨_, rfl⟩\n have hXpos : 0 < X := by rw [hX]; positivity\n have hsauer' : ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ) ≤ X ^ d := by\n have h := sum_Iic_choose_le_exp (m+m) d hd hdm\n rw [hX]\n refine le_trans h (le_of_eq ?_)\n norm_num\n -- logarithm of X\n have hlogX : Real.log X = 1 + Real.log 2 + Real.log (m:ℝ) - Real.log (d:ℝ) := by\n rw [hX, Real.log_div (by positivity) (ne_of_gt hdpos),\n Real.log_mul (by positivity) (by positivity), Real.log_exp,\n show ((m:ℝ)+(m:ℝ)) = 2 * (m:ℝ) by ring,\n Real.log_mul (by norm_num) (ne_of_gt hMpos)]\n ring\n -- an upper bound for `log m`\n have hEq : (m:ℝ)*α/(8*(d:ℝ)) = (m:ℝ) / (8*(d:ℝ)/α) := by field_simp\n have h1 := Real.log_le_sub_one_of_pos\n (show (0:ℝ) < (m:ℝ)/(8*(d:ℝ)/α) by positivity)\n rw [Real.log_div (ne_of_gt hMpos) (by positivity), ← hEq] at h1\n have hlog8d : Real.log (8*(d:ℝ)/α) = 3*Real.log 2 + Real.log (d:ℝ) + Real.log (1/α) := by\n rw [Real.log_div (by positivity) (ne_of_gt hα0),\n Real.log_mul (by norm_num) (ne_of_gt hdpos),\n show (8:ℝ) = 2^3 by norm_num, Real.log_pow, one_div, Real.log_inv]\n push_cast\n ring\n have hlogXle : Real.log X ≤ 4*Real.log 2 + (m:ℝ)*α/(8*(d:ℝ)) + Real.log (1/α) := by\n rw [hlogX]\n rw [hlog8d] at h1\n linarith\n have hmul := mul_le_mul_of_nonneg_left hlogXle hd0\n have hexp : (d:ℝ) * (4*Real.log 2 + (m:ℝ)*α/(8*(d:ℝ)) + Real.log (1/α))\n = 4*Real.log 2*(d:ℝ) + α*(m:ℝ)/8 + (d:ℝ)*Real.log (1/α) := by\n field_simp\n rw [hexp] at hmul\n have h4 : 4*Real.log 2*(d:ℝ) ≤ 2.776*(d:ℝ) := by nlinarith\n have hpos2 : 0 ≤ (d:ℝ)*Real.log (1/α) := mul_nonneg hd0 hlogα\n have hdlogX : (d:ℝ) * Real.log X\n ≤ (α*(m:ℝ))/8 + 2.8 * ((d:ℝ) * (1 + Real.log (1/α))) := by\n have hDexp : (d:ℝ) * (1 + Real.log (1/α)) = (d:ℝ) + (d:ℝ)*Real.log (1/α) := by ring\n rw [hDexp]\n linarith\n have hlogδ : Real.log (1/δ) ≤ Real.log (2/δ) := by\n apply Real.log_le_log (by positivity)\n rw [div_le_div_iff_of_pos_right hδ0]\n linarith\n have hkey : Real.log 2 + (d:ℝ) * Real.log X + Real.log (1/δ)\n ≤ (α * (m:ℝ) / 2) * Real.log 2 :=\n numeric_core hD1 hE0 hL1 hL2 ht hdlogX hlogδ\n -- exponentiate\n have hrge : α * (m:ℝ) / 2 ≤ (⌈α * (m:ℝ) / 2⌉₊ : ℝ) := Nat.le_ceil _\n have hpow : Real.exp ((α * (m:ℝ) / 2) * Real.log 2) ≤ 2 ^ (⌈α * (m:ℝ) / 2⌉₊) := by\n have hstep : Real.exp ((α * (m:ℝ) / 2) * Real.log 2)\n ≤ Real.exp ((⌈α * (m:ℝ) / 2⌉₊ : ℝ) * Real.log 2) := by\n apply Real.exp_le_exp.mpr\n exact mul_le_mul_of_nonneg_right hrge (by linarith)\n have h2 : Real.exp ((⌈α * (m:ℝ) / 2⌉₊ : ℝ) * Real.log 2) = 2 ^ (⌈α * (m:ℝ) / 2⌉₊) := by\n rw [Real.exp_nat_mul, Real.exp_log (by norm_num)]\n linarith [hstep, h2.le, h2.ge]\n have hmain : 2 * X ^ d ≤ Real.exp ((α * (m:ℝ) / 2) * Real.log 2) * δ := by\n have hlogL : Real.log (2 * X ^ d) = Real.log 2 + (d:ℝ) * Real.log X := by\n rw [Real.log_mul (by norm_num) (by positivity), Real.log_pow]\n have hlogR : Real.log (Real.exp ((α * (m:ℝ) / 2) * Real.log 2) * δ)\n = (α * (m:ℝ) / 2) * Real.log 2 + Real.log δ := by\n rw [Real.log_mul (by positivity) (ne_of_gt hδ0), Real.log_exp]\n have hlogδ' : Real.log (1/δ) = - Real.log δ := by rw [one_div, Real.log_inv]\n have hineq : Real.log (2 * X ^ d)\n ≤ Real.log (Real.exp ((α * (m:ℝ) / 2) * Real.log 2) * δ) := by\n rw [hlogL, hlogR]\n linarith [hkey, hlogδ'.le, hlogδ'.ge]\n calc 2 * X ^ d = Real.exp (Real.log (2 * X ^ d)) := (Real.exp_log (by positivity)).symm\n _ ≤ Real.exp (Real.log (Real.exp ((α * (m:ℝ) / 2) * Real.log 2) * δ)) :=\n Real.exp_le_exp.mpr hineq\n _ = Real.exp ((α * (m:ℝ) / 2) * Real.log 2) * δ := Real.exp_log (by positivity)\n calc 2 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ) ≤ 2 * X ^ d := by linarith\n _ ≤ Real.exp ((α * (m:ℝ) / 2) * Real.log 2) * δ := hmain\n _ ≤ 2 ^ (⌈α * (m:ℝ) / 2⌉₊) * δ := mul_le_mul_of_nonneg_right hpow (le_of_lt hδ0)\n\nend Numerics\n\n/-! ### Uniform convergence and the agnostic VC bound -/\n\nsection AgnosticUC\nopen Finset\nopen scoped ENNReal\n\n\n/-- The Rademacher moment-generating function identity: summing over all subsets `T`\nof a finite index type, `exp (l * ∑ ± w i)` factorises. -/\nlemma rad_mgf {m : ℕ} (w : Fin m → ℝ) (l : ℝ) :\n ∑ T : Finset (Fin m), Real.exp (l * ∑ i, (if i ∈ T then w i else -w i))\n = ∏ i, (Real.exp (l * w i) + Real.exp (-(l * w i))) := by\n classical\n rw [Fintype.prod_add]\n refine Finset.sum_congr rfl ?_\n intro T _\n have h1 : l * ∑ i, (if i ∈ T then w i else -w i)\n = ∑ i, (if i ∈ T then l * w i else -(l * w i)) := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl ?_\n intro i _\n by_cases hi : i ∈ T <;> simp [hi, mul_neg]\n rw [h1, Real.exp_sum]\n have h2 : ∀ i, Real.exp (if i ∈ T then l * w i else -(l * w i))\n = if i ∈ T then Real.exp (l * w i) else Real.exp (-(l * w i)) := by\n intro i; by_cases hi : i ∈ T <;> simp [hi]\n rw [Finset.prod_congr rfl (fun i _ => h2 i)]\n rw [← Finset.prod_sdiff (Finset.subset_univ T)]\n rw [Finset.compl_eq_univ_sdiff]\n rw [mul_comm]\n congr 1\n · exact Finset.prod_congr rfl (fun i hi => by rw [if_pos hi])\n · refine Finset.prod_congr rfl (fun i hi => ?_)\n rw [if_neg (Finset.mem_sdiff.mp hi).2]\n\n/-- One-sided Hoeffding tail bound, in the purely combinatorial \"counting subsets\" form. -/\nlemma card_signSum_ge_le {m : ℕ} (w : Fin m → ℝ) (hw : ∀ i, |w i| ≤ 1) {t : ℝ} (ht : 0 ≤ t) :\n ((Finset.univ.filter (fun T : Finset (Fin m) =>\n t ≤ ∑ i, (if i ∈ T then w i else -w i))).card : ℝ)\n ≤ 2 ^ m * Real.exp (- (t ^ 2) / (2 * m)) := by\n classical\n rcases Nat.eq_zero_or_pos m with hm | hm\n · subst hm\n have hcard : ((Finset.univ.filter (fun T : Finset (Fin 0) =>\n t ≤ ∑ i, (if i ∈ T then w i else -w i))).card : ℝ) ≤ 1 := by\n have := Finset.card_filter_le (Finset.univ : Finset (Finset (Fin 0)))\n (fun T => t ≤ ∑ i, (if i ∈ T then w i else -w i))\n have h2 : (Finset.univ : Finset (Finset (Fin 0))).card = 1 := by simp\n rw [h2] at this\n exact_mod_cast this\n simpa using hcard\n · have hmR : (0:ℝ) < m := by exact_mod_cast hm\n set l : ℝ := t / m with hl\n have hl0 : 0 ≤ l := by positivity\n set F := Finset.univ.filter (fun T : Finset (Fin m) =>\n t ≤ ∑ i, (if i ∈ T then w i else -w i)) with hF\n -- step 1: card F ≤ ∑ over all T of exp (l * (X T - t))\n have step1 : (F.card : ℝ) ≤ ∑ T : Finset (Fin m),\n Real.exp (l * ((∑ i, (if i ∈ T then w i else -w i)) - t)) := by\n have hsub : ∑ T ∈ F, (1:ℝ) ≤ ∑ T ∈ F,\n Real.exp (l * ((∑ i, (if i ∈ T then w i else -w i)) - t)) := by\n refine Finset.sum_le_sum ?_\n intro T hT\n have hTt : t ≤ ∑ i, (if i ∈ T then w i else -w i) := (Finset.mem_filter.mp hT).2\n have : (0:ℝ) ≤ l * ((∑ i, (if i ∈ T then w i else -w i)) - t) := by\n apply mul_nonneg hl0; linarith\n calc (1:ℝ) = Real.exp 0 := by simp\n _ ≤ _ := Real.exp_le_exp.mpr this\n have hall : ∑ T ∈ F, Real.exp (l * ((∑ i, (if i ∈ T then w i else -w i)) - t))\n ≤ ∑ T : Finset (Fin m), Real.exp (l * ((∑ i, (if i ∈ T then w i else -w i)) - t)) := by\n refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) ?_\n intro T _ _\n exact (Real.exp_pos _).le\n have hc : ∑ T ∈ F, (1:ℝ) = (F.card : ℝ) := by simp\n linarith [hc.symm.trans_le (hsub.trans hall)]\n -- step 2: factorise\n have step2 : ∑ T : Finset (Fin m),\n Real.exp (l * ((∑ i, (if i ∈ T then w i else -w i)) - t))\n = Real.exp (-(l*t)) * ∏ i, (Real.exp (l * w i) + Real.exp (-(l * w i))) := by\n rw [← rad_mgf w l, Finset.mul_sum]\n refine Finset.sum_congr rfl ?_\n intro T _\n rw [← Real.exp_add]\n congr 1\n ring\n -- step 3: bound each factor\n have step3 : ∀ i : Fin m, Real.exp (l * w i) + Real.exp (-(l * w i))\n ≤ 2 * Real.exp (l ^ 2 / 2) := by\n intro i\n have hcosh : Real.exp (l * w i) + Real.exp (-(l * w i))\n = 2 * Real.cosh (l * w i) := by\n rw [Real.cosh_eq]; ring\n rw [hcosh]\n have h1 : Real.cosh (l * w i) ≤ Real.cosh l := by\n rw [Real.cosh_le_cosh]\n rw [abs_mul, abs_of_nonneg hl0]\n nlinarith [abs_nonneg (w i), hw i, hl0]\n have h2 : Real.cosh l ≤ Real.exp (l ^ 2 / 2) := Real.cosh_le_exp_half_sq l\n linarith\n have step4 : ∏ i, (Real.exp (l * w i) + Real.exp (-(l * w i)))\n ≤ (2 * Real.exp (l ^ 2 / 2)) ^ m := by\n calc ∏ i, (Real.exp (l * w i) + Real.exp (-(l * w i)))\n ≤ ∏ _i : Fin m, (2 * Real.exp (l ^ 2 / 2)) := by\n refine Finset.prod_le_prod ?_ ?_\n · intro i _; positivity\n · intro i _; exact step3 i\n _ = (2 * Real.exp (l ^ 2 / 2)) ^ m := by simp\n have hfin : Real.exp (-(l*t)) * ((2 * Real.exp (l ^ 2 / 2)) ^ m)\n = 2 ^ m * Real.exp (- (t ^ 2) / (2 * m)) := by\n rw [mul_pow, ← Real.exp_nat_mul]\n rw [show Real.exp (-(l*t)) * (2 ^ m * Real.exp ((m:ℝ) * (l^2/2)))\n = (2:ℝ) ^ m * (Real.exp (-(l*t)) * Real.exp ((m:ℝ) * (l^2/2))) by ring,\n ← Real.exp_add]\n congr 2\n rw [hl]\n field_simp\n ring\n calc (F.card : ℝ) ≤ Real.exp (-(l*t)) * ∏ i, (Real.exp (l * w i) + Real.exp (-(l * w i))) := by\n rw [← step2]; exact step1\n _ ≤ Real.exp (-(l*t)) * ((2 * Real.exp (l ^ 2 / 2)) ^ m) := by\n exact mul_le_mul_of_nonneg_left step4 (Real.exp_pos _).le\n _ = 2 ^ m * Real.exp (- (t ^ 2) / (2 * m)) := hfin\n\n/-- Signed difference between the number of first-half and second-half mistakes after\nexchanging the pairs indexed by `T`. -/\nnoncomputable def swapDiff {m : ℕ} (a b : Fin m → Bool) (T : Finset (Fin m)) : ℝ :=\n ((Finset.univ.filter (fun i => (if i ∈ T then b i else a i) = true)).card : ℝ)\n - ((Finset.univ.filter (fun i => (if i ∈ T then a i else b i) = true)).card : ℝ)\n\n/-- The weight attached to index `i`. -/\nnoncomputable def swapW {m : ℕ} (a b : Fin m → Bool) (i : Fin m) : ℝ :=\n (if b i = true then (1:ℝ) else 0) - (if a i = true then (1:ℝ) else 0)\n\nlemma swapW_abs_le {m : ℕ} (a b : Fin m → Bool) (i : Fin m) : |swapW a b i| ≤ 1 := by\n rw [swapW]\n by_cases hb : b i = true <;> by_cases ha : a i = true <;> simp [hb, ha]\n\nlemma swapDiff_eq {m : ℕ} (a b : Fin m → Bool) (T : Finset (Fin m)) :\n swapDiff a b T = ∑ i, (if i ∈ T then swapW a b i else -(swapW a b i)) := by\n classical\n rw [swapDiff, ← Finset.sum_boole, ← Finset.sum_boole, ← Finset.sum_sub_distrib]\n refine Finset.sum_congr rfl ?_\n intro i _\n by_cases hi : i ∈ T <;> simp [hi, swapW] <;> ring\n\nlemma swapDiff_swap {m : ℕ} (a b : Fin m → Bool) (T : Finset (Fin m)) :\n swapDiff b a T = - swapDiff a b T := by\n rw [swapDiff, swapDiff]; ring\n\nlemma card_swapDiff_ge_le {m : ℕ} (a b : Fin m → Bool) {t : ℝ} (ht : 0 ≤ t) :\n ((Finset.univ.filter (fun T : Finset (Fin m) => t ≤ swapDiff a b T)).card : ℝ)\n ≤ 2 ^ m * Real.exp (- (t ^ 2) / (2 * m)) := by\n classical\n have := card_signSum_ge_le (swapW a b) (swapW_abs_le a b) ht\n refine le_trans (le_of_eq ?_) this\n congr 2\n apply Finset.filter_congr\n intro T _\n rw [swapDiff_eq]\n\nlemma card_swapDiff_abs_le {m : ℕ} (a b : Fin m → Bool) {t : ℝ} (ht : 0 ≤ t) :\n ((Finset.univ.filter (fun T : Finset (Fin m) => t ≤ |swapDiff a b T|)).card : ℝ)\n ≤ 2 ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m)) := by\n classical\n have hsub : (Finset.univ.filter (fun T : Finset (Fin m) => t ≤ |swapDiff a b T|))\n ⊆ (Finset.univ.filter (fun T : Finset (Fin m) => t ≤ swapDiff a b T))\n ∪ (Finset.univ.filter (fun T : Finset (Fin m) => t ≤ swapDiff b a T)) := by\n intro T hT\n have h := (Finset.mem_filter.mp hT).2\n rw [Finset.mem_union, Finset.mem_filter, Finset.mem_filter]\n rcases abs_cases (swapDiff a b T) with ⟨he, _⟩ | ⟨he, _⟩\n · left; exact ⟨Finset.mem_univ _, by rw [he] at h; exact h⟩\n · right\n refine ⟨Finset.mem_univ _, ?_⟩\n rw [swapDiff_swap, ← he]\n exact h\n have hcard := Finset.card_le_card hsub\n have hun := Finset.card_union_le\n (Finset.univ.filter (fun T : Finset (Fin m) => t ≤ swapDiff a b T))\n (Finset.univ.filter (fun T : Finset (Fin m) => t ≤ swapDiff b a T))\n have h1 := card_swapDiff_ge_le a b ht\n have h2 := card_swapDiff_ge_le b a ht\n have hR : ((Finset.univ.filter (fun T : Finset (Fin m) => t ≤ |swapDiff a b T|)).card : ℝ)\n ≤ ((Finset.univ.filter (fun T : Finset (Fin m) => t ≤ swapDiff a b T)).card : ℝ)\n + ((Finset.univ.filter (fun T : Finset (Fin m) => t ≤ swapDiff b a T)).card : ℝ) := by\n exact_mod_cast le_trans hcard hun\n have : (2:ℝ) ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m))\n = 2 ^ m * Real.exp (- (t ^ 2) / (2 * m)) + 2 ^ m * Real.exp (- (t ^ 2) / (2 * m)) := by\n rw [pow_succ]; ring\n rw [this]\n linarith\n\nsection AgnGhost\nopen Finset\n\n/-- Number of mistakes of `h` on the first members of the pairs. -/\ndef fstErrCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) : ℕ :=\n (Finset.univ.filter (fun i => h.f ((w i).1).1 ≠ ((w i).1).2)).card\n\n/-- The paired sample is *bad* if some member of the family has very different\nmistake counts on the two halves. -/\ndef agnEvent {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (e : ℕ → Predictor 𝒳 Bool) (t : ℝ) : Set (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n {w | ∃ k, t ≤ |((fstErrCount (e k) w : ℕ) : ℝ) - ((sndErrCount (e k) w : ℕ) : ℝ)|}\n\nlemma fstErrCount_eq_sum {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :\n ((fstErrCount h w : ℕ) : ℝ) = ∑ i, zeroOneLoss h ((w i).1) := by\n classical\n rw [fstErrCount, ← Finset.sum_boole]\n refine Finset.sum_congr rfl ?_\n intro i _\n by_cases hi : h.f ((w i).1).1 = ((w i).1).2\n · rw [if_neg (by simpa using hi)]\n simp [zeroOneLoss, hi]\n · rw [if_pos (by simpa using hi)]\n simp [zeroOneLoss, hi]\n\nlemma sndErrCount_eq_sum {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :\n ((sndErrCount h w : ℕ) : ℝ) = ∑ i, zeroOneLoss h ((w i).2) := by\n classical\n rw [sndErrCount, ← Finset.sum_boole]\n refine Finset.sum_congr rfl ?_\n intro i _\n by_cases hi : h.f ((w i).2).1 = ((w i).2).2\n · rw [if_neg (by simpa using hi)]\n simp [zeroOneLoss, hi]\n · rw [if_pos (by simpa using hi)]\n simp [zeroOneLoss, hi]\n\nlemma measurable_fstErrCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) :\n Measurable (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => ((fstErrCount h w : ℕ) : ℝ)) := by\n have : (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => ((fstErrCount h w : ℕ) : ℝ))\n = fun w => ∑ i, zeroOneLoss h ((w i).1) := by\n funext w; exact fstErrCount_eq_sum h w\n rw [this]\n refine Finset.measurable_sum _ ?_\n intro i _\n exact (zeroOneLoss_measurable h).comp (measurable_fst.comp (measurable_pi_apply i))\n\nlemma measurable_sndErrCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) :\n Measurable (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => ((sndErrCount h w : ℕ) : ℝ)) := by\n have : (fun w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) => ((sndErrCount h w : ℕ) : ℝ))\n = fun w => ∑ i, zeroOneLoss h ((w i).2) := by\n funext w; exact sndErrCount_eq_sum h w\n rw [this]\n refine Finset.measurable_sum _ ?_\n intro i _\n exact (zeroOneLoss_measurable h).comp (measurable_snd.comp (measurable_pi_apply i))\n\nlemma measurableSet_agnEvent {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (e : ℕ → Predictor 𝒳 Bool) (t : ℝ) :\n MeasurableSet (agnEvent (m := m) e t) := by\n have hrep : agnEvent (m := m) e t\n = ⋃ k : ℕ, {w : Fin m → (𝒳 × Bool) × (𝒳 × Bool) |\n t ≤ |((fstErrCount (e k) w : ℕ) : ℝ) - ((sndErrCount (e k) w : ℕ) : ℝ)|} := by\n ext w; simp [agnEvent, Set.mem_iUnion]\n rw [hrep]\n refine MeasurableSet.iUnion fun k => ?_\n exact measurableSet_le measurable_const\n (((measurable_fstErrCount (e k)).sub (measurable_sndErrCount (e k))).abs)\n\n/-- The pointwise (in the paired sample) counting estimate feeding the symmetrisation\nlemma, agnostic version. -/\nlemma agn_indicator_sum_le {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d : ℕ∞)) (e : ℕ → Predictor 𝒳 Bool) (he : ∀ k, e k ∈ H)\n {m : ℕ} {t : ℝ} (ht : 0 ≤ t) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :\n ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' (agnEvent e t))\n (1 : (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) → ℝ≥0∞) w\n ≤ ENNReal.ofReal (((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n * (2 ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m)))) := by\n classical\n set x : Fin (m+m) → 𝒳 :=\n Fin.append (fun i => ((w i).1).1) (fun i => ((w i).2).1) with hx\n have hxl : ∀ i : Fin m, x (Fin.castAdd m i) = ((w i).1).1 := by\n intro i; rw [hx]; exact Fin.append_left _ _ i\n have hxr : ∀ i : Fin m, x (Fin.natAdd m i) = ((w i).2).1 := by\n intro i; rw [hx]; exact Fin.append_right _ _ i\n have hind : ∀ T : Finset (Fin m),\n Set.indicator (swapPairs T ⁻¹' (agnEvent e t))\n (1 : (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) → ℝ≥0∞) w\n = if swapPairs T w ∈ agnEvent e t then 1 else 0 := by\n intro T\n by_cases hT : swapPairs T w ∈ agnEvent e t\n · have hmem : w ∈ swapPairs T ⁻¹' agnEvent e t := hT\n rw [if_pos hT, Set.indicator_of_mem hmem]\n rfl\n · have hmem : w ∉ swapPairs T ⁻¹' agnEvent e t := hT\n rw [if_neg hT, Set.indicator_of_notMem hmem]\n rw [Finset.sum_congr rfl (fun T _ => hind T), Finset.sum_boole]\n set FF := (Finset.univ.filter\n (fun T : Finset (Fin m) => swapPairs T w ∈ agnEvent e t)) with hFF\n have hsub : FF ⊆ (vcTrace H x).biUnion\n (fun τ => Finset.univ.filter (fun T : Finset (Fin m) =>\n t ≤ |swapDiff (patA (fun j => decide (j ∈ τ)) w)\n (patB (fun j => decide (j ∈ τ)) w) T|)) := by\n intro T hT\n obtain ⟨k, hcnt⟩ := (Finset.mem_filter.mp hT).2\n set h := e k with hh\n set τ : Finset (Fin (m+m)) := Finset.univ.filter (fun j => h.f (x j) = true) with hτ\n have hpt : ∀ j, (decide (j ∈ τ)) = h.f (x j) := by\n intro j; rw [hτ]; simp\n have hτmem : τ ∈ vcTrace H x := by\n rw [mem_vcTrace]\n refine ⟨h, ?_, ?_⟩\n · rw [hh]; exact he k\n · intro j; rw [hτ]; simp\n refine Finset.mem_biUnion.mpr ⟨τ, hτmem, ?_⟩\n refine Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩\n have hA : ∀ i : Fin m,\n (patA (fun j => decide (j ∈ τ)) w i = true) ↔ (h.f ((w i).1).1 ≠ ((w i).1).2) := by\n intro i\n rw [patA, hpt, hxl]\n simp\n have hB : ∀ i : Fin m,\n (patB (fun j => decide (j ∈ τ)) w i = true) ↔ (h.f ((w i).2).1 ≠ ((w i).2).2) := by\n intro i\n rw [patB, hpt, hxr]\n simp\n have hfst : fstErrCount h (swapPairs T w)\n = (Finset.univ.filter (fun i => (if i ∈ T then patB (fun j => decide (j ∈ τ)) w i\n else patA (fun j => decide (j ∈ τ)) w i) = true)).card := by\n rw [fstErrCount]\n congr 1\n apply Finset.filter_congr\n intro i _\n by_cases hi : i ∈ T\n · rw [swapPairs_apply, if_pos hi, if_pos hi]\n simpa using (hB i).symm\n · rw [swapPairs_apply, if_neg hi, if_neg hi]\n simpa using (hA i).symm\n have hsnd : sndErrCount h (swapPairs T w)\n = (Finset.univ.filter (fun i => (if i ∈ T then patA (fun j => decide (j ∈ τ)) w i\n else patB (fun j => decide (j ∈ τ)) w i) = true)).card := by\n rw [sndErrCount]\n congr 1\n apply Finset.filter_congr\n intro i _\n by_cases hi : i ∈ T\n · rw [swapPairs_apply, if_pos hi, if_pos hi]\n simpa using (hA i).symm\n · rw [swapPairs_apply, if_neg hi, if_neg hi]\n simpa using (hB i).symm\n have hdiff : swapDiff (patA (fun j => decide (j ∈ τ)) w)\n (patB (fun j => decide (j ∈ τ)) w) T\n = ((fstErrCount h (swapPairs T w) : ℕ) : ℝ)\n - ((sndErrCount h (swapPairs T w) : ℕ) : ℝ) := by\n rw [swapDiff, hfst, hsnd]\n rw [hdiff]\n exact hcnt\n have hcard : (FF.card : ℝ) ≤ ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n * (2 ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m))) := by\n have h1 : FF.card ≤ ∑ τ ∈ vcTrace H x, (Finset.univ.filter\n (fun T : Finset (Fin m) => t ≤ |swapDiff (patA (fun j => decide (j ∈ τ)) w)\n (patB (fun j => decide (j ∈ τ)) w) T|)).card :=\n le_trans (Finset.card_le_card hsub) Finset.card_biUnion_le\n have h1R : (FF.card : ℝ) ≤ ∑ τ ∈ vcTrace H x, ((Finset.univ.filter\n (fun T : Finset (Fin m) => t ≤ |swapDiff (patA (fun j => decide (j ∈ τ)) w)\n (patB (fun j => decide (j ∈ τ)) w) T|)).card : ℝ) := by\n exact_mod_cast h1\n have h2 : ∑ τ ∈ vcTrace H x, ((Finset.univ.filter\n (fun T : Finset (Fin m) => t ≤ |swapDiff (patA (fun j => decide (j ∈ τ)) w)\n (patB (fun j => decide (j ∈ τ)) w) T|)).card : ℝ)\n ≤ ∑ _τ ∈ vcTrace H x, ((2:ℝ) ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m))) := by\n refine Finset.sum_le_sum ?_\n intro τ _\n exact card_swapDiff_abs_le _ _ ht\n have h3 : ∑ _τ ∈ vcTrace H x, ((2:ℝ) ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m)))\n = ((vcTrace H x).card : ℝ) * ((2:ℝ) ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m))) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n have h4 : ((vcTrace H x).card : ℝ) ≤ ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ) := by\n exact_mod_cast vcTrace_card_le_sauer H x hvc\n have hpos : (0:ℝ) ≤ (2:ℝ) ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m)) := by positivity\n calc (FF.card : ℝ) ≤ ((vcTrace H x).card : ℝ)\n * ((2:ℝ) ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m))) := by\n rw [← h3]; linarith\n _ ≤ ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n * ((2:ℝ) ^ (m+1) * Real.exp (- (t ^ 2) / (2 * m))) :=\n mul_le_mul_of_nonneg_right h4 hpos\n have hcast : ((FF.card : ℕ) : ℝ≥0∞) = ENNReal.ofReal ((FF.card : ℕ) : ℝ) := by\n simp [ENNReal.ofReal_natCast]\n rw [hcast]\n exact ENNReal.ofReal_le_ofReal hcard\n\nend AgnGhost\n\nsection SymReal\nopen Finset\n\n/-- The symmetrisation inequality with a real-valued (extended) bound. -/\nlemma symmetrization_le' {Z : Type*} [MeasurableSpace Z]\n (P : Measure Z) [IsProbabilityMeasure P] {m : ℕ}\n (E : Set (Fin m → Z × Z)) (hE : MeasurableSet E) (N : ℝ≥0∞)\n (hcount : ∀ w : Fin m → Z × Z,\n ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' E) (1 : (Fin m → Z × Z) → ℝ≥0∞) w ≤ N) :\n 2 ^ m * (Measure.pi fun _ : Fin m => P.prod P) E ≤ N := by\n classical\n set ν : Measure (Fin m → Z × Z) := Measure.pi fun _ : Fin m => P.prod P with hν\n haveI : IsProbabilityMeasure ν := by rw [hν]; infer_instance\n have hmeas : ∀ T : Finset (Fin m), MeasurableSet (swapPairs T ⁻¹' E) :=\n fun T => (measurable_swapPairs T) hE\n have hpre : ∀ T : Finset (Fin m), ν (swapPairs T ⁻¹' E) = ν E := by\n intro T\n exact (measurePreserving_swapPairs P T).measure_preimage hE.nullMeasurableSet\n have hsum : ∑ _T ∈ (Finset.univ : Finset (Finset (Fin m))), ν E = 2 ^ m * ν E := by\n rw [Finset.sum_const, nsmul_eq_mul]\n congr 1\n rw [Finset.card_univ, Fintype.card_finset, Fintype.card_fin]\n simp\n have hint : ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))), ν (swapPairs T ⁻¹' E)\n = ∫⁻ w, ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' E) 1 w ∂ν := by\n rw [lintegral_finset_sum]\n · exact Finset.sum_congr rfl fun T _ => (lintegral_indicator_one (hmeas T)).symm\n · intro T _\n exact measurable_one.indicator (hmeas T)\n calc 2 ^ m * ν E = ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))), ν (swapPairs T ⁻¹' E) := by\n rw [Finset.sum_congr rfl fun T _ => hpre T, hsum]\n _ = ∫⁻ w, ∑ T ∈ (Finset.univ : Finset (Finset (Fin m))),\n Set.indicator (swapPairs T ⁻¹' E) 1 w ∂ν := hint\n _ ≤ ∫⁻ _w, N ∂ν := lintegral_mono hcount\n _ = N := by simp\n\nend SymReal\n\nsection Cheb2\nopen Finset ProbabilityTheory\n\n/-- A two-sided Chebyshev bound: as soon as `m ≤ 2 c ^ 2`, at least half of the samples\nhave their number of \"successes\" within `c` of the mean. -/\nlemma half_le_measure_close {Z : Type*} [MeasurableSpace Z]\n (P : Measure Z) [IsProbabilityMeasure P] {m : ℕ}\n (f : Z → ℝ) (hf : Measurable f) (hf0 : ∀ z, 0 ≤ f z) (hf1 : ∀ z, f z ≤ 1)\n {p c : ℝ} (hint : ∫ z, f z ∂P = p) (hc0 : 0 < c) (hcm : (m:ℝ) ≤ 2 * c ^ 2) :\n ENNReal.ofReal (1/2) ≤\n (Measure.pi fun _ : Fin m => P) {S | |(∑ i, f (S i)) - (m:ℝ) * p| < c} := by\n classical\n set μ : Measure (Fin m → Z) := Measure.pi fun _ : Fin m => P with hμ\n haveI : IsProbabilityMeasure μ := by rw [hμ]; infer_instance\n have hfint : Integrable f P :=\n Integrable.of_mem_Icc 0 1 hf.aemeasurable\n (Filter.Eventually.of_forall fun z => ⟨hf0 z, hf1 z⟩)\n have hp0 : 0 ≤ p := by\n rw [← hint]\n exact integral_nonneg hf0\n have hp1 : p ≤ 1 := by\n rw [← hint]\n have := integral_mono hfint (integrable_const (1:ℝ)) (fun z => hf1 z)\n simpa using this\n set Xi : Fin m → (Fin m → Z) → ℝ := fun i S => f (S i) with hXi\n have hXim : ∀ i, Measurable (Xi i) := fun i => hf.comp (measurable_pi_apply i)\n have hmemLp : ∀ i, MemLp (Xi i) 2 μ := by\n intro i\n refine MemLp.of_bound (hXim i).aestronglyMeasurable 1 ?_\n refine Filter.Eventually.of_forall fun S => ?_\n rw [Real.norm_eq_abs, abs_of_nonneg (hf0 _)]\n exact hf1 _\n have hEi : ∀ i, ∫ S, Xi i S ∂μ = p := by\n intro i\n rw [hμ, hXi]\n rw [integral_comp_eval hf.aestronglyMeasurable]\n exact hint\n have hindep : iIndepFun Xi μ := by\n rw [hμ, hXi]\n exact iIndepFun_pi (fun _ => hf.aemeasurable)\n have hvari : ∀ i, variance (Xi i) μ ≤ 1/4 := by\n intro i\n have hb := variance_le_sub_mul_sub (μ := μ) (X := Xi i) (a := 0) (b := 1)\n (Filter.Eventually.of_forall fun S => ⟨hf0 _, hf1 _⟩) (hXim i).aemeasurable\n rw [hEi i] at hb\n nlinarith [hb, sq_nonneg (p - 1/2)]\n set X : (Fin m → Z) → ℝ := ∑ i, Xi i with hX\n have hXapp : ∀ S, X S = ∑ i, f (S i) := by\n intro S\n rw [hX]\n simp [hXi]\n have hMemX : MemLp X 2 μ := by\n rw [hX]\n exact memLp_finset_sum' _ (fun i _ => hmemLp i)\n have hEX : ∫ S, X S ∂μ = m * p := by\n simp only [hX, Finset.sum_apply]\n rw [integral_finset_sum _ (fun i _ => (hmemLp i).integrable (by norm_num))]\n simp [hEi]\n have hVarX : variance X μ ≤ (m:ℝ)/4 := by\n rw [hX]\n rw [ProbabilityTheory.IndepFun.variance_sum (fun i _ => hmemLp i)\n (fun i _ j _ hij => hindep.indepFun hij)]\n calc ∑ i : Fin m, variance (Xi i) μ ≤ ∑ _i : Fin m, (1/4 : ℝ) :=\n Finset.sum_le_sum fun i _ => hvari i\n _ = (m:ℝ)/4 := by simp; ring\n have hcheb := ProbabilityTheory.meas_ge_le_variance_div_sq (μ := μ) hMemX hc0\n rw [hEX] at hcheb\n have hbadle : μ {S : Fin m → Z | c ≤ |X S - (m:ℝ) * p|} ≤ ENNReal.ofReal (1/2) := by\n refine le_trans hcheb ?_\n apply ENNReal.ofReal_le_ofReal\n rw [div_le_iff₀ (by positivity)]\n nlinarith [hVarX, hcm]\n have hGmeas : MeasurableSet {S : Fin m → Z | |(∑ i, f (S i)) - (m:ℝ) * p| < c} := by\n have hms : Measurable (fun S : Fin m → Z => ∑ i, f (S i)) := by\n apply Finset.measurable_sum\n intro i _\n exact hf.comp (measurable_pi_apply i)\n exact measurableSet_lt ((hms.sub measurable_const).abs) measurable_const\n have hcompl : {S : Fin m → Z | |(∑ i, f (S i)) - (m:ℝ) * p| < c}ᶜ\n = {S : Fin m → Z | c ≤ |X S - (m:ℝ) * p|} := by\n ext S\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_lt, hXapp S]\n have hadd := measure_add_measure_compl (μ := μ) hGmeas\n rw [hcompl, measure_univ] at hadd\n have hhalf : ENNReal.ofReal (1/2) + ENNReal.ofReal (1/2) = 1 := by\n rw [← ENNReal.ofReal_add (by norm_num) (by norm_num)]\n norm_num\n have hfin : ENNReal.ofReal (1/2) + ENNReal.ofReal (1/2)\n ≤ μ {S : Fin m → Z | |(∑ i, f (S i)) - (m:ℝ) * p| < c} + ENNReal.ofReal (1/2) := by\n rw [hhalf, ← hadd]\n exact add_le_add le_rfl hbadle\n exact (ENNReal.add_le_add_iff_right (by simp)).mp hfin\n\nend Cheb2\n\nsection AgnGhostLow\nopen Finset\n\nlemma measurable_errCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ} (h : Predictor 𝒳 Bool) :\n Measurable (fun S : Fin m → 𝒳 × Bool => ((errCount h S : ℕ) : ℝ)) := by\n have : (fun S : Fin m → 𝒳 × Bool => ((errCount h S : ℕ) : ℝ))\n = fun S => ∑ i, zeroOneLoss h (S i) := by\n funext S; exact errCount_eq_sum h S\n rw [this]\n refine Finset.measurable_sum _ ?_\n intro i _\n exact (zeroOneLoss_measurable h).comp (measurable_pi_apply i)\n\nlemma fstErrCount_eq_errCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :\n fstErrCount h w = errCount h (fun i => (w i).1) := rfl\n\nlemma sndErrCount_eq_errCount {𝒳 : Type*} [MeasurableSpace 𝒳] {m : ℕ}\n (h : Predictor 𝒳 Bool) (w : Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :\n sndErrCount h w = errCount h (fun i => (w i).2) := rfl\n\n/-- The ghost-sample step in the agnostic case. -/\nlemma agn_ghost_lower {𝒳 : Type*} [MeasurableSpace 𝒳]\n (e : ℕ → Predictor 𝒳 Bool) (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n {γ : ℝ} (hγ0 : 0 < γ) {m : ℕ} (hm : 2 ≤ γ ^ 2 * m) :\n ENNReal.ofReal (1/2) *\n (Measure.pi fun _ : Fin m => P)\n {S | ∃ k, γ * m < |((errCount (e k) S : ℕ) : ℝ)\n - (m:ℝ) * ordinaryError (e k) P|}\n ≤ (Measure.pi fun _ : Fin m => P.prod P) (agnEvent e (γ * m / 2)) := by\n classical\n have hmpos : 0 < (m:ℝ) := by nlinarith [sq_nonneg γ]\n set Pm : Measure (Fin m → 𝒳 × Bool) := Measure.pi fun _ : Fin m => P with hPm\n set ν : Measure (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n Measure.pi fun _ : Fin m => P.prod P with hν\n set g : ℕ → Set (Fin m → 𝒳 × Bool) :=\n fun k => {S | γ * m < |((errCount (e k) S : ℕ) : ℝ)\n - (m:ℝ) * ordinaryError (e k) P|} with hg\n set G : ℕ → Set (Fin m → 𝒳 × Bool) :=\n fun k => {S | |((errCount (e k) S : ℕ) : ℝ)\n - (m:ℝ) * ordinaryError (e k) P| < γ * m / 2} with hG\n have hgmeas : ∀ k, MeasurableSet (g k) := by\n intro k\n rw [hg]\n exact measurableSet_lt measurable_const\n (((measurable_errCount (e k)).sub measurable_const).abs)\n have hGmeas : ∀ k, MeasurableSet (G k) := by\n intro k\n rw [hG]\n exact measurableSet_lt (((measurable_errCount (e k)).sub measurable_const).abs)\n measurable_const\n set D : ℕ → Set (Fin m → 𝒳 × Bool) := disjointed g with hD\n have hDmeas : ∀ k, MeasurableSet (D k) := fun k => MeasurableSet.disjointed hgmeas k\n have hDle : ∀ k, D k ⊆ g k := fun k => disjointed_le g k\n set F : ℕ → Set (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n fun k => {w | (fun i => (w i).1) ∈ D k} ∩ {w | (fun i => (w i).2) ∈ G k} with hF\n have hFmeas : ∀ k, MeasurableSet (F k) := by\n intro k\n refine MeasurableSet.inter ?_ ?_\n · exact (measurable_pi_lambda _ (fun i => measurable_fst.comp (measurable_pi_apply i)))\n (hDmeas k)\n · exact (measurable_pi_lambda _ (fun i => measurable_snd.comp (measurable_pi_apply i)))\n (hGmeas k)\n have hFdisj : Pairwise (Function.onFun Disjoint F) := by\n intro i j hij\n have hd := disjoint_disjointed g hij\n refine Set.disjoint_left.mpr ?_\n intro w hw1 hw2\n exact Set.disjoint_left.mp hd hw1.1 hw2.1\n have hFsub : (⋃ k, F k) ⊆ agnEvent e (γ * m / 2) := by\n intro w hw\n obtain ⟨k, hk⟩ := Set.mem_iUnion.mp hw\n have hk1 : (fun i => (w i).1) ∈ g k := hDle k hk.1\n have hk2 : (fun i => (w i).2) ∈ G k := hk.2\n rw [hg] at hk1\n rw [hG] at hk2\n simp only [Set.mem_setOf_eq] at hk1 hk2\n refine ⟨k, ?_⟩\n rw [fstErrCount_eq_errCount, sndErrCount_eq_errCount]\n set A := ((errCount (e k) (fun i => (w i).1) : ℕ) : ℝ)\n set B := ((errCount (e k) (fun i => (w i).2) : ℕ) : ℝ)\n set q := (m:ℝ) * ordinaryError (e k) P\n have h1 : |A - B| ≥ |A - q| - |B - q| := by\n have := abs_sub_abs_le_abs_sub (A - q) (B - q)\n have heq : (A - q) - (B - q) = A - B := by ring\n rw [heq] at this\n linarith\n linarith\n have hhalfG : ∀ k, ENNReal.ofReal (1/2) ≤ Pm (G k) := by\n intro k\n have hGeq : G k = {S : Fin m → 𝒳 × Bool |\n |(∑ i, zeroOneLoss (e k) (S i)) - (m:ℝ) * ordinaryError (e k) P| < γ * m / 2} := by\n ext S\n rw [hG]\n simp only [Set.mem_setOf_eq]\n rw [errCount_eq_sum]\n rw [hGeq, hPm]\n refine half_le_measure_close P (zeroOneLoss (e k))\n (zeroOneLoss_measurable (e k)) (zeroOneLoss_nonneg (e k)) (zeroOneLoss_le_one (e k))\n (integral_zeroOneLoss (e k) P) (by positivity) ?_\n have : (γ * m / 2) ^ 2 = γ ^ 2 * (m:ℝ) * (m:ℝ) / 4 := by ring\n rw [this]\n nlinarith [hm, hmpos]\n have hstep2 : ∀ k, ENNReal.ofReal (1/2) * Pm (D k) ≤ ν (F k) := by\n intro k\n have hprod : ν (F k) = Pm (D k) * Pm (G k) := by\n rw [hF, hν, hPm]\n exact pi_prod_inter P (hDmeas k) (hGmeas k)\n rw [hprod]\n calc ENNReal.ofReal (1/2) * Pm (D k) = Pm (D k) * ENNReal.ofReal (1/2) := by ring\n _ ≤ Pm (D k) * Pm (G k) := mul_le_mul_left' (hhalfG k) _\n have hAeq : {S : Fin m → 𝒳 × Bool | ∃ k, γ * m < |((errCount (e k) S : ℕ) : ℝ)\n - (m:ℝ) * ordinaryError (e k) P|} = ⋃ k, g k := by\n ext S\n simp only [Set.mem_setOf_eq, Set.mem_iUnion, hg]\n rw [hAeq, ← iUnion_disjointed (f := g), ← hD]\n rw [measure_iUnion (disjoint_disjointed g) hDmeas]\n calc ENNReal.ofReal (1/2) * ∑' k, Pm (D k)\n = ∑' k, ENNReal.ofReal (1/2) * Pm (D k) := ENNReal.tsum_mul_left.symm\n _ ≤ ∑' k, ν (F k) := ENNReal.tsum_le_tsum hstep2\n _ = ν (⋃ k, F k) := (measure_iUnion hFdisj hFmeas).symm\n _ ≤ ν (agnEvent e (γ * m / 2)) := measure_mono hFsub\n\nend AgnGhostLow\n\nsection AgnMaster\nopen Finset\n\n/-- The master VC estimate in the agnostic case: uniform deviation of empirical from true\nerror over the whole countable family. -/\ntheorem agnostic_vc_master {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d : ℕ∞)) (e : ℕ → Predictor 𝒳 Bool) (he : ∀ k, e k ∈ H)\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n {γ : ℝ} (hγ0 : 0 < γ) {m : ℕ} (hm : 2 ≤ γ ^ 2 * m) :\n (Measure.pi fun _ : Fin m => P)\n {S | ∃ k, γ * m < |((errCount (e k) S : ℕ) : ℝ)\n - (m:ℝ) * ordinaryError (e k) P|}\n ≤ ENNReal.ofReal (4 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n * Real.exp (- (γ ^ 2 * (m:ℝ)) / 8)) := by\n classical\n have hmpos : 0 < (m:ℝ) := by nlinarith [sq_nonneg γ]\n set Γ : ℝ := ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ) with hΓ\n have hΓ0 : 0 ≤ Γ := by rw [hΓ]; positivity\n set E : ℝ := Real.exp (- (γ ^ 2 * (m:ℝ)) / 8) with hE\n have hE0 : 0 < E := Real.exp_pos _\n set t : ℝ := γ * m / 2 with ht\n have ht0 : 0 ≤ t := by rw [ht]; positivity\n set ν : Measure (Fin m → (𝒳 × Bool) × (𝒳 × Bool)) :=\n Measure.pi fun _ : Fin m => P.prod P with hν\n set Bad : Set (Fin m → 𝒳 × Bool) :=\n {S | ∃ k, γ * m < |((errCount (e k) S : ℕ) : ℝ)\n - (m:ℝ) * ordinaryError (e k) P|} with hBad\n -- the exponential simplifies\n have hexp : Real.exp (- (t ^ 2) / (2 * m)) = E := by\n rw [hE, ht]\n congr 1\n field_simp\n ring\n -- symmetrisation\n have hsym : (2:ℝ≥0∞) ^ m * ν (agnEvent e t) ≤ ENNReal.ofReal (Γ * (2 ^ (m+1) * E)) := by\n rw [hν]\n refine symmetrization_le' P (agnEvent e t) (measurableSet_agnEvent e t) _ ?_\n intro w\n have := agn_indicator_sum_le H hvc e he ht0 w\n rw [hexp] at this\n exact this\n have hsplit : ENNReal.ofReal (Γ * (2 ^ (m+1) * E))\n = (2:ℝ≥0∞) ^ m * ENNReal.ofReal (2 * Γ * E) := by\n have h1 : Γ * (2 ^ (m+1) * E) = (2:ℝ) ^ m * (2 * Γ * E) := by\n rw [pow_succ]; ring\n rw [h1, ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_pow (by norm_num)]\n congr 2\n simp\n have hcancel : ν (agnEvent e t) ≤ ENNReal.ofReal (2 * Γ * E) := by\n rw [hsplit] at hsym\n have h2 : ((2:ℝ≥0∞) ^ m) ≠ 0 := by positivity\n have h2' : ((2:ℝ≥0∞) ^ m) ≠ ⊤ := ENNReal.pow_ne_top (by norm_num)\n exact (ENNReal.mul_le_mul_left h2 h2').mp hsym\n have hlow := agn_ghost_lower e P hγ0 hm\n rw [← hBad, ← hν, ← ht] at hlow\n have hhalf : ENNReal.ofReal (1/2) * 2 = 1 := by\n rw [show (2:ℝ≥0∞) = ENNReal.ofReal 2 by simp, ← ENNReal.ofReal_mul (by norm_num)]\n norm_num\n have hfin : (Measure.pi fun _ : Fin m => P) Bad ≤ 2 * ENNReal.ofReal (2 * Γ * E) := by\n calc (Measure.pi fun _ : Fin m => P) Bad\n = 2 * (ENNReal.ofReal (1/2) * (Measure.pi fun _ : Fin m => P) Bad) := by\n rw [show (2:ℝ≥0∞) * (ENNReal.ofReal (1/2) * (Measure.pi fun _ : Fin m => P) Bad)\n = (ENNReal.ofReal (1/2) * 2) * (Measure.pi fun _ : Fin m => P) Bad by ring,\n hhalf, one_mul]\n _ ≤ 2 * ν (agnEvent e t) := by gcongr\n _ ≤ 2 * ENNReal.ofReal (2 * Γ * E) := by gcongr\n refine le_trans hfin (le_of_eq ?_)\n rw [show (2:ℝ≥0∞) = ENNReal.ofReal 2 by simp, ← ENNReal.ofReal_mul (by norm_num)]\n congr 1\n ring\n\nend AgnMaster\n\nsection AgnPAC\nopen Finset\n\nlemma erm_exists {𝒳 : Type*} [MeasurableSpace 𝒳] (e : ℕ → Predictor 𝒳 Bool) {m : ℕ}\n (S : Fin m → 𝒳 × Bool) :\n ∃ k, ∀ j, errCount (e k) S ≤ errCount (e j) S := by\n classical\n obtain ⟨k, hk⟩ := Nat.sInf_mem (s := Set.range fun j => errCount (e j) S)\n (Set.range_nonempty _)\n refine ⟨k, fun j => ?_⟩\n simp only at hk\n rw [hk]\n exact Nat.sInf_le ⟨j, rfl⟩\n\n/-- Empirical risk minimisation over the enumerated family (the minimum is attained\nbecause the empirical error takes finitely many values). -/\nnoncomputable def ermPred {𝒳 : Type*} [MeasurableSpace 𝒳] (e : ℕ → Predictor 𝒳 Bool) {m : ℕ}\n (S : Fin m → 𝒳 × Bool) : Predictor 𝒳 Bool :=\n e (Classical.choose (erm_exists e S))\n\nlemma ermPred_eq {𝒳 : Type*} [MeasurableSpace 𝒳] (e : ℕ → Predictor 𝒳 Bool) {m : ℕ}\n (S : Fin m → 𝒳 × Bool) : ∃ k, ermPred e S = e k :=\n ⟨Classical.choose (erm_exists e S), rfl⟩\n\nlemma ermPred_le {𝒳 : Type*} [MeasurableSpace 𝒳] (e : ℕ → Predictor 𝒳 Bool) {m : ℕ}\n (S : Fin m → 𝒳 × Bool) (j : ℕ) : errCount (ermPred e S) S ≤ errCount (e j) S :=\n Classical.choose_spec (erm_exists e S) j\n\n/-- Pointwise convergence of predictors forces convergence of their error probabilities. -/\nlemma ordinaryError_tendsto {𝒳 : Type*} [MeasurableSpace 𝒳]\n (P : Measure (𝒳 × Bool)) [IsProbabilityMeasure P]\n (s : ℕ → Predictor 𝒳 Bool) (h : Predictor 𝒳 Bool)\n (hlim : ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x) :\n Filter.Tendsto (fun i => ordinaryError (s i) P) Filter.atTop\n (nhds (ordinaryError h P)) := by\n have hconv : ∀ᵐ z ∂P, Filter.Tendsto (fun i => zeroOneLoss (s i) z) Filter.atTop\n (nhds (zeroOneLoss h z)) := by\n refine Filter.Eventually.of_forall fun z => ?_\n have hev : (fun i => zeroOneLoss (s i) z) =ᶠ[Filter.atTop] (fun _ => zeroOneLoss h z) := by\n filter_upwards [hlim z.1] with i hi\n unfold zeroOneLoss\n rw [Set.indicator_apply, Set.indicator_apply]\n simp only [Set.mem_setOf_eq, hi]\n exact Filter.Tendsto.congr' hev.symm tendsto_const_nhds\n have hT := MeasureTheory.tendsto_integral_of_dominated_convergence\n (μ := P) (F := fun i => zeroOneLoss (s i)) (f := zeroOneLoss h) (fun _ => (1:ℝ))\n (fun i => (zeroOneLoss_measurable (s i)).aestronglyMeasurable)\n (integrable_const 1)\n (fun i => Filter.Eventually.of_forall fun z => by\n rw [Real.norm_eq_abs, abs_of_nonneg (zeroOneLoss_nonneg _ _)]\n exact zeroOneLoss_le_one _ _)\n hconv\n simpa only [integral_zeroOneLoss] using hT\n\n/-- The agnostic PAC guarantee at a given sample size. -/\nlemma agnostic_PAC_at_size {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n {d : ℕ} (hvc : VCDim H = (d : ℕ∞))\n (H₀ : Set (Predictor 𝒳 Bool)) (hH₀ : H₀ ⊆ H)\n (e : ℕ → Predictor 𝒳 Bool) (hrange : H₀ = Set.range e)\n (hdense : ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool, (∀ i, s i ∈ H₀) ∧\n ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x)\n (hHne : H.Nonempty)\n {γ δ : ℝ} (hγ0 : 0 < γ) {m : ℕ} (hm : 2 ≤ (γ/2) ^ 2 * m)\n (hbound : 4 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n * Real.exp (- ((γ/2) ^ 2 * (m:ℝ)) / 8) ≤ δ) :\n OrdinaryAgnosticPACAtSize H γ δ m := by\n classical\n have he : ∀ k, e k ∈ H := by\n intro k\n apply hH₀\n rw [hrange]\n exact ⟨k, rfl⟩\n have hγ20 : 0 < γ / 2 := by linarith\n have hmpos : 0 < (m:ℝ) := by nlinarith [sq_nonneg (γ/2)]\n haveI : Nonempty ↥H := by\n obtain ⟨h, hh⟩ := hHne\n exact ⟨⟨h, hh⟩⟩\n refine ⟨fun S => ermPred e S, ?_⟩\n intro P _\n set Bad : Set (Fin m → 𝒳 × Bool) :=\n {S | ∃ k, (γ/2) * m < |((errCount (e k) S : ℕ) : ℝ)\n - (m:ℝ) * ordinaryError (e k) P|} with hBad\n have hsub : {S : Fin m → 𝒳 × Bool |\n (⨅ h : ↥H, ordinaryError (h : Predictor 𝒳 Bool) P) + γ < ordinaryError (ermPred e S) P}\n ⊆ Bad := by\n intro S hS\n by_contra hnb\n simp only [hBad, Set.mem_setOf_eq, not_exists, not_lt] at hnb\n obtain ⟨k₀, hk₀⟩ := ermPred_eq e S\n -- uniform convergence gives the ERM comparison\n have hcomp : ∀ k, ordinaryError (ermPred e S) P ≤ ordinaryError (e k) P + γ := by\n intro k\n have h1 := hnb k₀\n have h2 := hnb k\n have h3 : errCount (ermPred e S) S ≤ errCount (e k) S := ermPred_le e S k\n have h3R : ((errCount (e k₀) S : ℕ) : ℝ) ≤ ((errCount (e k) S : ℕ) : ℝ) := by\n rw [← hk₀]\n exact_mod_cast h3\n have hb1 : (m:ℝ) * ordinaryError (e k₀) P\n ≤ ((errCount (e k₀) S : ℕ) : ℝ) + (γ/2) * m := by\n have := abs_le.mp h1\n linarith [this.1, this.2]\n have hb2 : ((errCount (e k) S : ℕ) : ℝ)\n ≤ (m:ℝ) * ordinaryError (e k) P + (γ/2) * m := by\n have := abs_le.mp h2\n linarith [this.1, this.2]\n have hmm : (m:ℝ) * ordinaryError (e k₀) P\n ≤ (m:ℝ) * ordinaryError (e k) P + γ * m := by linarith\n have hfin : ordinaryError (e k₀) P ≤ ordinaryError (e k) P + γ := by\n have := (div_le_div_iff_of_pos_right hmpos).mpr hmm\n nlinarith [hmm, hmpos]\n rw [hk₀]\n exact hfin\n -- pass to the closure\n have hall : ∀ h : ↥H, ordinaryError (ermPred e S) P - γ\n ≤ ordinaryError (h : Predictor 𝒳 Bool) P := by\n rintro ⟨h, hh⟩\n obtain ⟨s, hsH₀, hslim⟩ := hdense h hh\n have hs : ∀ i, ordinaryError (ermPred e S) P - γ ≤ ordinaryError (s i) P := by\n intro i\n have := hsH₀ i\n rw [hrange] at this\n obtain ⟨k, hk⟩ := this\n have := hcomp k\n rw [hk] at this\n linarith\n have hlim := ordinaryError_tendsto P s h hslim\n exact ge_of_tendsto' hlim hs\n have hinf : ordinaryError (ermPred e S) P - γ\n ≤ ⨅ h : ↥H, ordinaryError (h : Predictor 𝒳 Bool) P := le_ciInf hall\n simp only [Set.mem_setOf_eq] at hS\n linarith\n calc (Measure.pi fun _ : Fin m => P) {S : Fin m → 𝒳 × Bool |\n (⨅ h : ↥H, ordinaryError (h : Predictor 𝒳 Bool) P) + γ\n < ordinaryError (ermPred e S) P}\n ≤ (Measure.pi fun _ : Fin m => P) Bad := measure_mono hsub\n _ ≤ ENNReal.ofReal (4 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n * Real.exp (- ((γ/2) ^ 2 * (m:ℝ)) / 8)) := by\n rw [hBad]\n exact agnostic_vc_master H hvc e he P hγ20 hm\n _ ≤ ENNReal.ofReal δ := ENNReal.ofReal_le_ofReal hbound\n\nend AgnPAC\n\nsection AgnNumerics\nopen Finset\n\nset_option maxHeartbeats 1000000 in\nlemma agnostic_numeric {d : ℕ} (hd : 0 < d) {γ δ : ℝ} (hγ0 : 0 < γ) (hγ1 : γ < 1)\n (hδ0 : 0 < δ) (hδ1 : δ < 1) (m : ℕ)\n (hm : 400 * ((d:ℝ) * (1 + Real.log (1/γ)) + Real.log (2/δ)) / γ ^ 2 ≤ m) :\n 2 ≤ (γ/2) ^ 2 * m ∧ d ≤ m + m ∧\n 4 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ)\n * Real.exp (- ((γ/2) ^ 2 * (m:ℝ)) / 8) ≤ δ := by\n have hdR : (1:ℝ) ≤ (d:ℝ) := by exact_mod_cast hd\n have hdpos : (0:ℝ) < (d:ℝ) := by linarith\n have hd0 : (0:ℝ) ≤ (d:ℝ) := le_of_lt hdpos\n have hγ2 : (0:ℝ) < γ ^ 2 := by positivity\n have hγ2le : γ ^ 2 ≤ 1 := by nlinarith\n have hL : 0 ≤ Real.log (1/γ) := Real.log_nonneg (by rw [le_div_iff₀ hγ0]; linarith)\n set D : ℝ := (d:ℝ) * (1 + Real.log (1/γ)) with hDdef\n have hD1 : (1:ℝ) ≤ D := by rw [hDdef]; nlinarith\n set E : ℝ := Real.log (2/δ) with hEdef\n have hE0 : (0:ℝ) ≤ E := Real.log_nonneg (by rw [le_div_iff₀ hδ0]; linarith)\n have hB1 : (1:ℝ) ≤ D + E := by linarith\n have hmpos : (0:ℝ) < (m:ℝ) := by\n have hq : (0:ℝ) < 400 * (D + E) / γ ^ 2 := by\n apply div_pos (by linarith) hγ2\n linarith\n have ht : 400 * (D + E) ≤ γ ^ 2 * (m:ℝ) := by\n rw [div_le_iff₀ hγ2] at hm\n linarith\n have h8 : (8:ℝ) ≤ γ ^ 2 * (m:ℝ) := by nlinarith\n have hdm : d ≤ m + m := by\n have hDd : (d:ℝ) ≤ D := by rw [hDdef]; nlinarith\n have h1 : 400 * (d:ℝ) ≤ γ ^ 2 * (m:ℝ) := by linarith\n have h2 : γ ^ 2 * (m:ℝ) ≤ (m:ℝ) := by nlinarith\n have hle : (d:ℝ) ≤ (m:ℝ) := by linarith\n have : d ≤ m := by exact_mod_cast hle\n omega\n refine ⟨by nlinarith, hdm, ?_⟩\n have hL1 : (0.693:ℝ) ≤ Real.log 2 := le_of_lt (by linarith [Real.log_two_gt_d9])\n have hL2 : Real.log 2 ≤ 0.694 := le_of_lt (by linarith [Real.log_two_lt_d9])\n obtain ⟨X, hX⟩ : ∃ X : ℝ, X = Real.exp 1 * ((m:ℝ)+(m:ℝ)) / (d:ℝ) := ⟨_, rfl⟩\n have hXpos : 0 < X := by rw [hX]; positivity\n have hsauer' : ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ) ≤ X ^ d := by\n have h := sum_Iic_choose_le_exp (m+m) d hd hdm\n rw [hX]\n refine le_trans h (le_of_eq ?_)\n norm_num\n have hlogX : Real.log X = 1 + Real.log 2 + Real.log (m:ℝ) - Real.log (d:ℝ) := by\n rw [hX, Real.log_div (by positivity) (ne_of_gt hdpos),\n Real.log_mul (by positivity) (by positivity), Real.log_exp,\n show ((m:ℝ)+(m:ℝ)) = 2 * (m:ℝ) by ring,\n Real.log_mul (by norm_num) (ne_of_gt hmpos)]\n ring\n -- bound `log m`\n have hEq : (m:ℝ)*γ^2/(64*(d:ℝ)) = (m:ℝ) / (64*(d:ℝ)/γ^2) := by field_simp\n have h1 := Real.log_le_sub_one_of_pos\n (show (0:ℝ) < (m:ℝ)/(64*(d:ℝ)/γ^2) by positivity)\n rw [Real.log_div (ne_of_gt hmpos) (by positivity), ← hEq] at h1\n have hlog64 : Real.log (64*(d:ℝ)/γ^2)\n = 6*Real.log 2 + Real.log (d:ℝ) + 2 * Real.log (1/γ) := by\n rw [Real.log_div (by positivity) (ne_of_gt hγ2),\n Real.log_mul (by norm_num) (ne_of_gt hdpos),\n show (64:ℝ) = 2^6 by norm_num, Real.log_pow, Real.log_pow, one_div, Real.log_inv]\n push_cast\n ring\n rw [hlog64] at h1\n have hlogXle : Real.log X\n ≤ 7*Real.log 2 + 2 * Real.log (1/γ) + (m:ℝ)*γ^2/(64*(d:ℝ)) := by\n rw [hlogX]; linarith\n have hmul := mul_le_mul_of_nonneg_left hlogXle hd0\n have hexp : (d:ℝ) * (7*Real.log 2 + 2 * Real.log (1/γ) + (m:ℝ)*γ^2/(64*(d:ℝ)))\n = 7*Real.log 2*(d:ℝ) + 2*(d:ℝ)*Real.log (1/γ) + γ^2*(m:ℝ)/64 := by\n field_simp\n rw [hexp] at hmul\n have hdlogX : (d:ℝ) * Real.log X ≤ γ^2*(m:ℝ)/64 + 4.858 * D := by\n have hDexp : D = (d:ℝ) + (d:ℝ)*Real.log (1/γ) := by rw [hDdef]; ring\n rw [hDexp]\n have h7 : 7*Real.log 2*(d:ℝ) ≤ 4.858*(d:ℝ) := by nlinarith\n have hpos2 : 0 ≤ (d:ℝ)*Real.log (1/γ) := mul_nonneg hd0 hL\n linarith\n have hlogδ : Real.log (1/δ) ≤ E := by\n rw [hEdef]\n apply Real.log_le_log (by positivity)\n rw [div_le_div_iff_of_pos_right hδ0]\n linarith\n have hlog4 : Real.log 4 = 2 * Real.log 2 := by\n rw [show (4:ℝ) = 2^2 by norm_num, Real.log_pow]; push_cast; ring\n have hkey : Real.log 4 + (d:ℝ) * Real.log X + Real.log (1/δ)\n ≤ γ^2*(m:ℝ)/32 := by\n rw [hlog4]\n linarith [hD1, hE0, ht, hdlogX, hlogδ, hL2]\n have hmain : 4 * X ^ d ≤ Real.exp (γ^2*(m:ℝ)/32) * δ := by\n have hlogL : Real.log (4 * X ^ d) = Real.log 4 + (d:ℝ) * Real.log X := by\n rw [Real.log_mul (by norm_num) (by positivity), Real.log_pow]\n have hlogR : Real.log (Real.exp (γ^2*(m:ℝ)/32) * δ)\n = γ^2*(m:ℝ)/32 + Real.log δ := by\n rw [Real.log_mul (by positivity) (ne_of_gt hδ0), Real.log_exp]\n have hlogδ' : Real.log (1/δ) = - Real.log δ := by rw [one_div, Real.log_inv]\n have hineq : Real.log (4 * X ^ d) ≤ Real.log (Real.exp (γ^2*(m:ℝ)/32) * δ) := by\n rw [hlogL, hlogR]\n linarith [hkey, hlogδ'.le, hlogδ'.ge]\n calc 4 * X ^ d = Real.exp (Real.log (4 * X ^ d)) := (Real.exp_log (by positivity)).symm\n _ ≤ Real.exp (Real.log (Real.exp (γ^2*(m:ℝ)/32) * δ)) := Real.exp_le_exp.mpr hineq\n _ = Real.exp (γ^2*(m:ℝ)/32) * δ := Real.exp_log (by positivity)\n have hEeq : (- ((γ/2) ^ 2 * (m:ℝ)) / 8) = - (γ^2*(m:ℝ)/32) := by ring\n rw [hEeq]\n have hexp0 : (0:ℝ) < Real.exp (- (γ^2*(m:ℝ)/32)) := Real.exp_pos _\n calc 4 * ((∑ j ∈ Finset.Iic d, (m+m).choose j : ℕ) : ℝ) * Real.exp (- (γ^2*(m:ℝ)/32))\n ≤ (4 * X ^ d) * Real.exp (- (γ^2*(m:ℝ)/32)) := by\n apply mul_le_mul_of_nonneg_right _ hexp0.le\n linarith\n _ ≤ (Real.exp (γ^2*(m:ℝ)/32) * δ) * Real.exp (- (γ^2*(m:ℝ)/32)) := by\n exact mul_le_mul_of_nonneg_right hmain hexp0.le\n _ = δ := by\n rw [mul_comm (Real.exp (γ^2*(m:ℝ)/32)) δ, mul_assoc, ← Real.exp_add]\n simp\n\nend AgnNumerics\n\nend AgnosticUC\n\nuniverse u\n\n/-- The separable-class ordinary agnostic finite-VC theorem. -/\ntheorem ordinary_agnostic_vc_bound_sep :\n ∃ K : ℝ, 0 < K ∧\n ∀ {𝒳 : Type u} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty →\n (∃ H₀ ⊆ H, H₀.Countable ∧ ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool,\n (∀ i, s i ∈ H₀) ∧ ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x) →\n ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d →\n ∀ γ ∈ Set.Ioo (0 : ℝ) 1, ∀ δ ∈ Set.Ioo (0 : ℝ) 1,\n ∃ n : ℕ, OrdinaryAgnosticPACAtSize H γ δ n ∧\n (n : ℝ) ≤ K * (((d : ℝ) * (1 + Real.log (1 / γ)) + Real.log (2 / δ)) / γ ^ 2) := by\n refine ⟨500, by norm_num, ?_⟩\n intro 𝒳 _ H hH hsep d hvc hd γ hγ δ hδ\n obtain ⟨hγ0, hγ1⟩ := hγ\n obtain ⟨hδ0, hδ1⟩ := hδ\n obtain ⟨H₀, hH₀sub, hH₀cnt, hdense⟩ := hsep\n have hH₀ne : H₀.Nonempty := by\n obtain ⟨h, hh⟩ := hH\n obtain ⟨s, hs, _⟩ := hdense h hh\n exact ⟨s 0, hs 0⟩\n obtain ⟨e, he⟩ := hH₀cnt.exists_eq_range hH₀ne\n have hdR : (1:ℝ) ≤ (d:ℝ) := by exact_mod_cast hd\n have hγ2 : (0:ℝ) < γ ^ 2 := by positivity\n have hγ2le : γ ^ 2 ≤ 1 := by nlinarith\n have hL : 0 ≤ Real.log (1/γ) := Real.log_nonneg (by rw [le_div_iff₀ hγ0]; linarith)\n have hE0 : (0:ℝ) ≤ Real.log (2/δ) := Real.log_nonneg (by rw [le_div_iff₀ hδ0]; linarith)\n have hB1 : (1:ℝ) ≤ (d:ℝ) * (1 + Real.log (1/γ)) + Real.log (2/δ) := by nlinarith\n set B : ℝ := (d:ℝ) * (1 + Real.log (1/γ)) + Real.log (2/δ) with hB\n set m : ℕ := ⌈400 * B / γ ^ 2⌉₊ with hmdef\n have hBγ : (1:ℝ) ≤ B / γ ^ 2 := by\n rw [le_div_iff₀ hγ2]\n nlinarith\n have hm : 400 * B / γ ^ 2 ≤ (m:ℝ) := Nat.le_ceil _\n obtain ⟨h2, hdm, hbound⟩ := agnostic_numeric hd hγ0 hγ1 hδ0 hδ1 m hm\n refine ⟨m, agnostic_PAC_at_size H hvc H₀ hH₀sub e he hdense hH hγ0 h2 hbound, ?_⟩\n have hub : (m:ℝ) < 400 * B / γ ^ 2 + 1 := Nat.ceil_lt_add_one (by positivity)\n have : 400 * B / γ ^ 2 + 1 ≤ 500 * (B / γ ^ 2) := by\n rw [show 400 * B / γ ^ 2 = 400 * (B / γ ^ 2) by ring]\n linarith\n linarith\n\n/-- The separable-class ordinary realizable finite-VC theorem. -/\ntheorem ordinary_realizable_vc_bound_sep :\n ∃ K : ℝ, 0 < K ∧\n ∀ {𝒳 : Type u} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty →\n (∃ H₀ ⊆ H, H₀.Countable ∧ ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool,\n (∀ i, s i ∈ H₀) ∧ ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x) →\n ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d →\n ∀ α ∈ Set.Ioo (0 : ℝ) 1, ∀ δ ∈ Set.Ioo (0 : ℝ) (1 / 4),\n ∃ n : ℕ, OrdinaryRealizablePACAtSize H α δ n ∧\n (n : ℝ) ≤ K * (((d : ℝ) * (1 + Real.log (1 / α)) + Real.log (2 / δ)) / α) := by\n refine ⟨100, by norm_num, ?_⟩\n intro 𝒳 _ H hH hsep d hvc hd α hα δ hδ\n obtain ⟨hα0, hα1⟩ := hα\n obtain ⟨hδ0, hδ1⟩ := hδ\n obtain ⟨H₀, hH₀sub, hH₀cnt, hdense⟩ := hsep\n have hH₀ne : H₀.Nonempty := by\n obtain ⟨h, hh⟩ := hH\n obtain ⟨s, hs, _⟩ := hdense h hh\n exact ⟨s 0, hs 0⟩\n obtain ⟨e, he⟩ := hH₀cnt.exists_eq_range hH₀ne\n have hdR : (1:ℝ) ≤ (d:ℝ) := by exact_mod_cast hd\n have hlogα : 0 ≤ Real.log (1/α) := Real.log_nonneg (by rw [le_div_iff₀ hα0]; linarith)\n have hE0 : (0:ℝ) ≤ Real.log (2/δ) := Real.log_nonneg (by rw [le_div_iff₀ hδ0]; linarith)\n have hB1 : (1:ℝ) ≤ (d:ℝ) * (1 + Real.log (1/α)) + Real.log (2/δ) := by nlinarith\n set B : ℝ := (d:ℝ) * (1 + Real.log (1/α)) + Real.log (2/δ) with hB\n set m : ℕ := ⌈16 * B / α⌉₊ with hmdef\n have hBα : (1:ℝ) ≤ B / α := by\n rw [le_div_iff₀ hα0]\n nlinarith\n have hm : 16 * B / α ≤ (m:ℝ) := Nat.le_ceil _\n obtain ⟨h8, hdm, hbound⟩ := realizable_numeric hd hα0 hα1 hδ0 hδ1 m hm\n refine ⟨m, realizable_PAC_at_size H hvc H₀ hH₀sub e he hdense hα0 (le_of_lt hα1) hδ0 h8 hbound,\n ?_⟩\n have hub : (m:ℝ) < 16 * B / α + 1 := Nat.ceil_lt_add_one (by positivity)\n have : 16 * B / α + 1 ≤ 100 * (B / α) := by\n rw [show 16 * B / α = 16 * (B/α) by ring]\n linarith\n linarith\n\n/-- Sharpened form of the `theorem7` right-hand side lower bound. -/\nlemma theorem7_rhs_lower2 {d : ℕ} (hd : 0 < d)\n {ρ ε δ : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) :\n (((d : ℝ) * (1 + 4 * Real.log (1 / ε)) + 1 + Real.log (2 / δ)) / ε ^ 4) ≤\n ((d / ε ^ 4) * Real.log (d / ε ^ 4)\n + (1 / ε ^ 4) * max (1 / (c2 ρ - 1)) 1\n + (d / ε ^ 4) * Real.log (Real.exp 1 / d)\n + Real.log (2 / δ) / ε ^ 4) := by\n have hdR : 0 < (d : ℝ) := by exact_mod_cast hd\n have he4 : 0 < ε ^ 4 := by positivity\n have hdne : (d : ℝ) ≠ 0 := ne_of_gt hdR\n have he4ne : ε ^ 4 ≠ 0 := ne_of_gt he4\n have hAne : (d : ℝ) / ε ^ 4 ≠ 0 := div_ne_zero hdne he4ne\n have hBne : Real.exp 1 / (d : ℝ) ≠ 0 :=\n div_ne_zero (Real.exp_ne_zero _) hdne\n have hprod : ((d : ℝ) / ε ^ 4) * (Real.exp 1 / (d : ℝ)) =\n Real.exp 1 / ε ^ 4 := by\n field_simp\n have hlogsum : Real.log ((d : ℝ) / ε ^ 4) +\n Real.log (Real.exp 1 / (d : ℝ)) = 1 - Real.log (ε ^ 4) := by\n rw [← Real.log_mul hAne hBne, hprod,\n Real.log_div (Real.exp_ne_zero _) he4ne, Real.log_exp]\n have hlog4 : Real.log (ε ^ 4) = 4 * Real.log ε := by\n rw [Real.log_pow]; norm_num\n have hloginv : Real.log (1 / ε) = - Real.log ε := by\n rw [one_div, Real.log_inv]\n have hlog_ge : 1 + 4 * Real.log (1 / ε) = Real.log ((d : ℝ) / ε ^ 4) +\n Real.log (Real.exp 1 / (d : ℝ)) := by\n rw [hlogsum, hlog4, hloginv]; ring\n have hfactor0 : 0 ≤ (d : ℝ) / ε ^ 4 := by positivity\n have hfirst :\n (d / ε ^ 4) * Real.log (d / ε ^ 4) +\n (d / ε ^ 4) * Real.log (Real.exp 1 / d) =\n ((d : ℝ) / ε ^ 4) * (1 + 4 * Real.log (1 / ε)) := by\n rw [← mul_add, ← hlog_ge]\n have hsecond : (1 : ℝ) / ε ^ 4 ≤\n (1 / ε ^ 4) * max (1 / (c2 ρ - 1)) 1 := by\n have hcoef : 0 ≤ (1 : ℝ) / ε ^ 4 := by positivity\n have hm : (1 : ℝ) ≤ max (1 / (c2 ρ - 1)) 1 := le_max_right _ _\n nlinarith\n have hid : ((((d : ℝ) * (1 + 4 * Real.log (1 / ε))) + 1 + Real.log (2 / δ)) / ε ^ 4) =\n ((d : ℝ) / ε ^ 4) * (1 + 4 * Real.log (1 / ε)) + 1 / ε ^ 4\n + Real.log (2 / δ) / ε ^ 4 := by\n field_simp\n rw [hid]\n linarith [hfirst, hsecond]\n\nend Upper\n\ntheorem theorem7 :\n ∀ ρ : ℝ, 0 < ρ →\n ∃ C : ℝ, 0 < C ∧\n ∀ {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty →\n (∃ H₀ ⊆ H, H₀.Countable ∧ ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool,\n (∀ i, s i ∈ H₀) ∧ ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x) →\n ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d →\n ∀ ε ∈ Set.Ioo (0 : ℝ) 1, ∀ δ ∈ Set.Ioo (0 : ℝ) 1,\n ∃ n : ℕ, agnosticSampleComplexity H ρ ε δ ≤ (n : ℕ∞) ∧\n (n : ℝ) ≤ C * ((d / ε ^ 4) * Real.log (d / ε ^ 4)\n + (1 / ε ^ 4) * max (1 / (c2 ρ - 1)) 1\n + (d / ε ^ 4) * Real.log (Real.exp 1 / d)\n + Real.log (2 / δ) / ε ^ 4) := by\n intro ρ hρ\n obtain ⟨K, hK, hbound⟩ := Upper.ordinary_agnostic_vc_bound_sep\n set L : ℝ := Upper.robustLip ρ with hLdef\n have hLpos : 0 < L := Upper.robustLip_pos hρ\n have hLone : 1 < L := Upper.one_lt_robustLip hρ\n have hlogL : 0 ≤ Real.log L := Real.log_nonneg hLone.le\n refine ⟨K * L ^ 4 * (2 + 2 * Real.log L), by positivity, ?_⟩\n intro 𝒳 _ H hH hsep d hvc hd ε hε δ hδ\n set γ : ℝ := (ε / L) ^ 2 with hγdef\n have hε0 : 0 < ε := hε.1\n have hε1 : ε < 1 := hε.2\n have hrpos : 0 < ε / L := div_pos hε0 hLpos\n have hrlt : ε / L < 1 := by\n apply (div_lt_one hLpos).2\n exact hε1.trans hLone\n have hγ0 : 0 < γ := by positivity\n have hγ1 : γ < 1 := by\n rw [hγdef]\n nlinarith [mul_pos hrpos (sub_pos.mpr hrlt)]\n obtain ⟨n, hnPAC, hn⟩ := hbound (𝒳 := 𝒳) H hH hsep d hvc hd γ ⟨hγ0, hγ1⟩ δ hδ\n have hsqrtγ : Real.sqrt γ = ε / L := by\n rw [hγdef]\n exact Real.sqrt_sq (div_nonneg hε0.le hLpos.le)\n have hLcancel : L * (ε / L) = ε := by field_simp\n have hscale : Upper.robustLip ρ * Real.sqrt γ ≤ ε := by\n rw [hsqrtγ, ← hLdef, hLcancel]\n refine ⟨n, Upper.agnosticSampleComplexity_le_of_ordinaryPAC\n H hH ρ ε δ γ n hρ hγ0.le hscale hnPAC, ?_⟩\n -- turn the `γ`-bound into an `ε`-bound\n have hlogγ : Real.log (1 / γ) = 2 * Real.log L + 2 * Real.log (1 / ε) := by\n have h1 : (1:ℝ) / γ = (L / ε) ^ 2 := by rw [hγdef]; field_simp\n rw [h1, Real.log_pow, Real.log_div (ne_of_gt hLpos) (ne_of_gt hε0), one_div, Real.log_inv]\n push_cast\n ring\n have hγsq : γ ^ 2 = ε ^ 4 / L ^ 4 := by\n rw [hγdef]; field_simp\n have hlogε : 0 ≤ Real.log (1 / ε) := by\n apply Real.log_nonneg\n rw [le_div_iff₀ hε0]; linarith\n have hlogδ : 0 ≤ Real.log (2 / δ) := by\n apply Real.log_nonneg\n rw [le_div_iff₀ hδ.1]; linarith [hδ.2]\n have hdR : (1:ℝ) ≤ (d : ℝ) := by exact_mod_cast hd\n have key : (d : ℝ) * (1 + (2 * Real.log L + 2 * Real.log (1 / ε))) + Real.log (2 / δ)\n ≤ (2 + 2 * Real.log L) * ((d : ℝ) * (1 + 4 * Real.log (1 / ε)) + 1 + Real.log (2 / δ)) := by\n nlinarith [mul_nonneg hlogL hlogε, mul_nonneg hlogL hlogδ,\n mul_nonneg (sub_nonneg.mpr hdR) hlogε, mul_nonneg (sub_nonneg.mpr hdR) hlogL,\n mul_nonneg (mul_nonneg (sub_nonneg.mpr hdR) hlogL) hlogε, hlogε, hlogL, hlogδ]\n have e1 : ((d : ℝ) * (1 + Real.log (1 / γ)) + Real.log (2 / δ)) / γ ^ 2\n = L ^ 4 * (((d : ℝ) * (1 + (2 * Real.log L + 2 * Real.log (1 / ε)))\n + Real.log (2 / δ)) / ε ^ 4) := by\n rw [hγsq, hlogγ]\n field_simp\n have hKL : (0:ℝ) ≤ K * L ^ 4 := by positivity\n have hfin : K * (((d : ℝ) * (1 + Real.log (1 / γ)) + Real.log (2 / δ)) / γ ^ 2)\n ≤ (K * L ^ 4 * (2 + 2 * Real.log L)) *\n (((d : ℝ) * (1 + 4 * Real.log (1 / ε)) + 1 + Real.log (2 / δ)) / ε ^ 4) := by\n rw [e1]\n have hdiv : ((d : ℝ) * (1 + (2 * Real.log L + 2 * Real.log (1 / ε)))\n + Real.log (2 / δ)) / ε ^ 4\n ≤ ((2 + 2 * Real.log L) * ((d : ℝ) * (1 + 4 * Real.log (1 / ε)) + 1\n + Real.log (2 / δ))) / ε ^ 4 :=\n div_le_div_of_nonneg_right key (by positivity)\n calc K * (L ^ 4 * (((d : ℝ) * (1 + (2 * Real.log L + 2 * Real.log (1 / ε)))\n + Real.log (2 / δ)) / ε ^ 4))\n = (K * L ^ 4) * (((d : ℝ) * (1 + (2 * Real.log L + 2 * Real.log (1 / ε)))\n + Real.log (2 / δ)) / ε ^ 4) := by ring\n _ ≤ (K * L ^ 4) * (((2 + 2 * Real.log L) * ((d : ℝ) * (1 + 4 * Real.log (1 / ε)) + 1\n + Real.log (2 / δ))) / ε ^ 4) := by\n exact mul_le_mul_of_nonneg_left hdiv hKL\n _ = (K * L ^ 4 * (2 + 2 * Real.log L)) *\n (((d : ℝ) * (1 + 4 * Real.log (1 / ε)) + 1 + Real.log (2 / δ)) / ε ^ 4) := by\n ring\n refine hn.trans (hfin.trans ?_)\n have := Upper.theorem7_rhs_lower2 (d := d) hd (ρ := ρ) (δ := δ) hε0 hε1\n have hCpos : (0:ℝ) ≤ K * L ^ 4 * (2 + 2 * Real.log L) := by positivity\n exact mul_le_mul_of_nonneg_left this hCpos\n\ntheorem theorem9 :\n ∃ c : ℝ, 0 < c ∧\n ∀ {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty → ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d →\n ∀ ρ : ℝ, 0 < ρ → ρ < (3 - 2 * Real.sqrt 2) / 2 →\n ∀ ε ∈ Set.Ioo (0 : ℝ) (1 / (8 * Real.sqrt 2)), ∀ δ ∈ Set.Ioo (0 : ℝ) (1 / 8), ∀ n : ℕ,\n agnosticSampleComplexity H ρ ε δ ≤ (n : ℕ∞) →\n c * (((1 / 2 - (Real.sqrt 2 / 16) * Real.sqrt ρ) ^ 2 * d + Real.log (1 / δ)) / ε ^ 2)\n ≤ (n : ℝ) := by\n refine ⟨1/4000, by norm_num, ?_⟩\n intro 𝒳 _ H hH d hvc hd ρ hρ hρ' ε hεmem δ hδmem n hn\n obtain ⟨hε0, hε1⟩ := hεmem\n obtain ⟨hδ0, hδ1⟩ := hδmem\n obtain ⟨c, hshat⟩ := vc_shattered H hvc hd\n refine sample_complexity_lb H ρ ε δ n _ hn ?_\n intro m hPAC\n have h1 : (d:ℝ) ≤ 1024 * m * ε^2 := dro_lb_d hd hρ hρ' hε0 hε1 hδ0 hδ1 c hshat hPAC\n have hpt : ∀ y : Bool, ∃ h ∈ H, h.f (c ⟨0, hd⟩) = y := by\n intro y\n obtain ⟨h, hh, hf⟩ := hshat (fun _ => y)\n exact ⟨h, hh, hf ⟨0, hd⟩⟩\n have h2 : Real.log (1/δ) ≤ 384 * m * ε^2 :=\n dro_lb_delta hρ hρ' hε0 hε1 hδ0 hδ1 (c ⟨0, hd⟩) hpt hPAC\n have hsr0 : (0:ℝ) ≤ Real.sqrt ρ := Real.sqrt_nonneg _\n have hsr : Real.sqrt ρ < 1 := by\n have : Real.sqrt ρ < Real.sqrt 1 := Real.sqrt_lt_sqrt (le_of_lt hρ) (by\n nlinarith [dro_sqrt2_gt])\n rwa [Real.sqrt_one] at this\n have hK0 : (0:ℝ) ≤ (1/2 - (Real.sqrt 2/16)*Real.sqrt ρ)^2 := sq_nonneg _\n have ht0 : (0:ℝ) ≤ (Real.sqrt 2/16)*Real.sqrt ρ := by positivity\n have ht1 : (Real.sqrt 2/16)*Real.sqrt ρ ≤ 1 := by\n have hstep : Real.sqrt 2/16 * Real.sqrt ρ ≤ (1.4143/16) * 1 :=\n mul_le_mul (by linarith [dro_sqrt2_lt]) (le_of_lt hsr) hsr0 (by norm_num)\n linarith\n have hK4 : (1/2 - (Real.sqrt 2/16)*Real.sqrt ρ)^2 ≤ 1/4 := by\n have hprod : (0:ℝ) ≤ ((Real.sqrt 2/16)*Real.sqrt ρ) * (1 - (Real.sqrt 2/16)*Real.sqrt ρ) :=\n mul_nonneg ht0 (by linarith)\n nlinarith [hprod]\n have hdnn : (0:ℝ) ≤ (d:ℝ) := Nat.cast_nonneg d\n have hcomb : (1/2 - (Real.sqrt 2/16)*Real.sqrt ρ)^2 * (d:ℝ) + Real.log (1/δ)\n ≤ 640 * m * ε^2 := by\n have hstep : (1/2 - (Real.sqrt 2/16)*Real.sqrt ρ)^2 * (d:ℝ) ≤ (1/4) * (d:ℝ) :=\n mul_le_mul_of_nonneg_right hK4 hdnn\n linarith\n have hdiv : ((1/2 - (Real.sqrt 2/16)*Real.sqrt ρ)^2 * (d:ℝ) + Real.log (1/δ))/ε^2\n ≤ 640*(m:ℝ) := by\n rw [div_le_iff₀ (by positivity)]\n linarith [hcomb]\n have hmnn : (0:ℝ) ≤ (m:ℝ) := Nat.cast_nonneg m\n linarith\n\ntheorem theorem12 :\n ∃ C : ℝ, 0 < C ∧\n ∀ {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool),\n H.Nonempty →\n (∃ H₀ ⊆ H, H₀.Countable ∧ ∀ h ∈ H, ∃ s : ℕ → Predictor 𝒳 Bool,\n (∀ i, s i ∈ H₀) ∧ ∀ x, ∀ᶠ i in Filter.atTop, (s i).f x = h.f x) →\n ∀ d : ℕ, VCDim H = (d : ℕ∞) → 0 < d → ∀ ρ : ℝ, 0 ≤ ρ →\n ∀ ε ∈ Set.Ioo (0 : ℝ) 1, ∀ δ ∈ Set.Ioo (0 : ℝ) (1 / 4),\n ∃ n : ℕ, realizableSampleComplexity H ρ ε δ ≤ (n : ℕ∞) ∧\n (n : ℝ) ≤ C * ((16 * (1 + 2 * ρ) * d / ε ^ 2) * Real.log (8 * (1 + 2 * ρ) * d / ε ^ 2)\n + (8 * (1 + 2 * ρ) / ε ^ 2)\n * (d * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ))) := by\n obtain ⟨K, hK, hbound⟩ := Upper.ordinary_realizable_vc_bound_sep\n refine ⟨K, hK, ?_⟩\n intro 𝒳 _ H hH hsep d hvc hd ρ hρ ε hε δ hδ\n set α : ℝ := ε ^ 2 / (1 + 2 * ρ) with hαdef\n have hεpos : 0 < ε := hε.1\n have hεone : ε < 1 := hε.2\n have hden : 0 < 1 + 2 * ρ := by linarith\n have hαpos : 0 < α := div_pos (by positivity) hden\n have hαone : α < 1 := by\n rw [hαdef]\n apply (div_lt_one hden).2\n nlinarith [sq_nonneg (ε - 1), sq_nonneg ε]\n obtain ⟨n, hnPAC, hn⟩ := hbound (𝒳 := 𝒳) H hH hsep d hvc hd α ⟨hαpos, hαone⟩ δ hδ\n refine ⟨n, Upper.realizableSampleComplexity_le_of_ordinaryPAC\n H ρ ε δ n hρ hεpos ?_, ?_⟩\n · rw [← hαdef]; exact hnPAC\n · -- transform the α-bound into the required shape\n have hdR : (1:ℝ) ≤ (d : ℝ) := by exact_mod_cast hd\n have hdpos : (0:ℝ) < (d : ℝ) := by linarith\n have hlogd : 0 ≤ Real.log d := Real.log_nonneg hdR\n have hlogα : 0 ≤ Real.log (1 / α) := by\n apply Real.log_nonneg\n rw [le_div_iff₀ hαpos]; linarith\n have hlogδ : 0 ≤ Real.log (2 / δ) := by\n apply Real.log_nonneg\n rw [le_div_iff₀ hδ.1]; linarith [hδ.2]\n -- the target, rewritten in terms of α\n have hform :\n ((16 * (d : ℝ) / α) * Real.log (8 * (d : ℝ) / α)\n + (8 / α) * ((d : ℝ) * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ))) =\n ((16 * (1 + 2 * ρ) * d / ε ^ 2) *\n Real.log (8 * (1 + 2 * ρ) * d / ε ^ 2)\n + (8 * (1 + 2 * ρ) / ε ^ 2) *\n (d * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ))) := by\n rw [hαdef]\n have h1 : (8 : ℝ) * d / (ε ^ 2 / (1 + 2 * ρ)) = 8 * (1 + 2 * ρ) * d / ε ^ 2 := by\n field_simp\n rw [h1]\n have hne : ε ^ 2 ≠ 0 := by positivity\n have hne2 : (1 + 2 * ρ) ≠ 0 := ne_of_gt hden\n field_simp\n rw [← hform]\n refine hn.trans ?_\n -- K * ((d(1+log(1/α)) + log(2/δ))/α) ≤ K * (16d/α * log(8d/α) + (8/α)(d log(2e/d) + log(2/δ)))\n have hlogcomb : 2 * Real.log (8 * (d : ℝ) / α) + Real.log (2 * Real.exp 1 / d)\n = Real.log (128 * Real.exp 1 * d / α ^ 2) := by\n have e8 : (8 : ℝ) * d / α > 0 := by positivity\n have e2 : (2 : ℝ) * Real.exp 1 / d > 0 := by positivity\n rw [show (2:ℝ) * Real.log (8 * (d : ℝ) / α) = Real.log ((8 * (d:ℝ) / α) ^ 2) by\n rw [Real.log_pow]; norm_num]\n rw [← Real.log_mul (by positivity) (by positivity)]\n congr 1\n field_simp\n ring\n have hbig : (d : ℝ) * (1 + Real.log (1 / α)) + Real.log (2 / δ)\n ≤ 16 * (d:ℝ) * Real.log (8 * (d : ℝ) / α)\n + 8 * ((d:ℝ) * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ)) := by\n have hrw : 16 * (d:ℝ) * Real.log (8 * (d : ℝ) / α)\n + 8 * ((d:ℝ) * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ))\n = 8 * (d:ℝ) * (2 * Real.log (8 * (d : ℝ) / α) + Real.log (2 * Real.exp 1 / d))\n + 8 * Real.log (2 / δ) := by ring\n rw [hrw, hlogcomb]\n have hlow : 1 + Real.log (1 / α) ≤ 8 * Real.log (128 * Real.exp 1 * d / α ^ 2) := by\n have hsplit : Real.log (128 * Real.exp 1 * d / α ^ 2)\n = Real.log 128 + 1 + Real.log d + 2 * Real.log (1 / α) := by\n rw [Real.log_div (by positivity) (by positivity),\n Real.log_mul (by positivity) (by positivity),\n Real.log_mul (by norm_num) (by positivity), Real.log_exp,\n Real.log_pow, one_div, Real.log_inv]\n push_cast\n ring\n rw [hsplit]\n have h128 : (0:ℝ) ≤ Real.log 128 := Real.log_nonneg (by norm_num)\n linarith\n nlinarith [mul_le_mul_of_nonneg_left hlow (le_of_lt hdpos)]\n have hstep : ((d : ℝ) * (1 + Real.log (1 / α)) + Real.log (2 / δ)) / α\n ≤ (16 * (d : ℝ) / α) * Real.log (8 * (d : ℝ) / α)\n + (8 / α) * ((d : ℝ) * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ)) := by\n rw [div_le_iff₀ hαpos]\n have : (16 * (d : ℝ) / α) * Real.log (8 * (d : ℝ) / α)\n + (8 / α) * ((d : ℝ) * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ))\n = (16 * (d:ℝ) * Real.log (8 * (d : ℝ) / α)\n + 8 * ((d:ℝ) * Real.log (2 * Real.exp 1 / d) + Real.log (2 / δ))) / α := by\n field_simp\n rw [this, div_mul_cancel₀ _ (ne_of_gt hαpos)]\n exact hbig\n exact mul_le_mul_of_nonneg_left hstep hK.le\n\nend Helpers2\n\nend ResearchLevel\n"} +{"id": "v24-22-1210", "source": "Research-level", "targets": [{"label": "Lemma 11", "decls": ["lemma11"], "statement": "Lemma 11 Letting $\\mathbf{x}_{t}, \\mathbf{y}_{t}, \\mathbf{s}_{t}$ be generated by Algorithm 3 with $\\eta=1/(2L)$ , it holds that\n\n$$\nV_{t+1}\\leq(1-\\alpha)V_{t}+\\frac{13\\eta}{m}\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+\\frac{20M^{2}\\eta+10\\eta^{-1}+(1+8/\\alpha^{3})M^{2}/L}{m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}.\\tag{25}\n$$", "context_ids": ["v24-22-1210:ctx1", "v24-22-1210:ctx2", "v24-22-1210:ctx3", "v24-22-1210:ctx4", "v24-22-1210:ctx5", "v24-22-1210:ctx7", "v24-22-1210:ctx8", "v24-22-1210:ctx11", "v24-22-1210:ctx12", "v24-22-1210:ctx13", "v24-22-1210:ctx14", "v24-22-1210:ctx15", "v24-22-1210:ctx16", "v24-22-1210:ctx17", "v24-22-1210:ctx18", "v24-22-1210:ctx19"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}, {"label": "Lemma 27", "decls": ["lemma27"], "statement": "Lemma 27 Letting $V_{t}$ be the Lyapunov function defined in $E q .$ (17) associated to Algorithm 1 with $\\eta = 1 / L$ , then it satisfies the following property\n\n$$\nV_{t+1}\\leq\\left(1-\\frac{3}{4}\\alpha\\right)V_{t}+\\left(1+\\frac{8}{\\alpha^{3}}\\right)\\cdot\\frac{M^{2}}{L}\\cdot\\frac{1}{m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}.\\tag{72}\n$$", "context_ids": ["v24-22-1210:ctx1", "v24-22-1210:ctx2", "v24-22-1210:ctx3", "v24-22-1210:ctx4", "v24-22-1210:ctx5", "v24-22-1210:ctx6", "v24-22-1210:ctx7", "v24-22-1210:ctx9", "v24-22-1210:ctx10", "v24-22-1210:ctx12", "v24-22-1210:ctx16", "v24-22-1210:ctx17", "v24-22-1210:ctx18", "v24-22-1210:ctx20", "v24-22-1210:ctx21"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}, {"label": "Lemma 10", "decls": ["lemma10"], "statement": "Lemma 10 Matrix A defined in $E q .$ (23) satisfies that\n\n$$\n0<\\lambda_{1}(\\mathbf{A})\\qquad and\\qquad|\\lambda_{3}(\\mathbf{A})|\\leq|\\lambda_{2}(\\mathbf{A})| <\\lambda_{1}(\\mathbf{A})\n$$\n\nwith $\\lambda_{i}(\\mathbf{A})$ being the i-th largest eigenvalue of A.Letting $\\eta=1/(2L)$ and $\\rho\\le L^{3}/(1280M^{3})$ , then it holds that\n\n$$\n\\lambda_{1}(\\mathbf{A})\\leq\\frac{1}{2},\n$$\n\nand the eigenvector v associated with $\\lambda_{1}(\\mathbf{A})$ is positive and its entries satisfy\n\n$$\n0<{\\bf v}(1)\\leq\\frac{8{\\bf v}(3)}{\\sqrt{\\rho}},\\qquad 0<{\\bf v}(2)\\leq 3{\\bf v}(3)\\qquad and\\quad 0<{\\bf v}(3),\\tag{24}\n$$\n\nwhere $\\mathbf{v}(i)$ is i-th entry of v.", "context_ids": ["v24-22-1210:ctx1", "v24-22-1210:ctx3", "v24-22-1210:ctx4", "v24-22-1210:ctx22"], "sibling_refs": [], "topic_domain": "Others", "topic_subtopic": "Matrix & Tensor Analysis"}], "nl_proof": "### Proof of Lemma 11\n\nBefore proving Lemma 11, we first give several important lemmas which are closely related to the convergence rate of Algorithm 3.\n\nLemma 21 Letting $\\mathbf x_{t}, \\mathbf y_{t}, \\mathbf s_{t}$ be generated by Algorithm 3, it holds that\n\n$$\n\\begin{array}{l}{{\\displaystyle h(\\bar{x}_{t+1})-h(x^{*})\\le(1-\\alpha)(h(\\bar{x}_{t})-h(x^{*}))-\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle}}\\\\ {{\\displaystyle~-\\eta\\left(\\frac 34-\\frac{\\eta L}2\\right)\\left\\|\\bar{G}_{t}\\right\\|^{2}-\\frac{\\mu\\alpha}2\\left\\|x^{*}-\\bar{y}_{t}\\right\\|^{2}}}\\\\ {{\\displaystyle~+\\frac{13\\eta}m\\left\\|\\mathbf s_{t}-\\mathbf 1\\bar{s}_{t}\\right\\|^{2}+\\frac{20M^{2}\\eta+10\\eta^{-1}}m\\left\\|\\mathbf y_{t}-\\mathbf 1\\bar{y}_{t}\\right\\|^{2}}.}\\end{array}\\tag{56}\n$$\n\nProof By µ-strong convexity , L-smoothness of $f(x)$ and the property of proximal operator, we have\n\n$$\n\\begin{array}{l}{h(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})))=f(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})))+r(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})))}\\\\ {=f(\\mathbf{y}_{t}^{(i)}+\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})-\\mathbf{y}_{t}^{(i)})+r(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})))}\\\\ {\\leq f(\\mathbf{y}_{t}^{(i)})+\\nabla f(\\mathbf{y}_{t}^{(i)})^{\\top}\\left(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})-\\mathbf{y}_{t}^{(i)}\\right)+\\frac{L}{2}\\left\\|\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}}\\\\ {\\quad+r(z)+\\frac{1}{\\eta}(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})-\\mathbf{y}_{t}^{(i)}+\\eta\\mathbf{s}_{t}^{(i)})^{\\top}(z-\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)}))}\\\\ {\\leq h(z)-\\nabla f(\\mathbf{y}_{t}^{(i)})^{\\top}(z-\\mathbf{y}_{t}^{(i)})-\\frac{\\mu}{2}\\left\\|z-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}+\\nabla f(\\mathbf{y}_{t}^{(i)})^{\\top}\\left(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})-\\mathbf{y}_{t}^{(i)}\\right)}\\\\ {\\quad+\\frac{L}{2}\\left\\|\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}+\\frac{1}{\\eta}(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})-\\mathbf{y}_{t}^{(i)}+\\eta\\mathbf{s}_{t}^{(i)})^{\\top}(z-\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)}))}\\\\ {=h(z)-\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)}),z-\\mathbf{y}_{t}^{(i)}\\right\\rangle-\\frac{\\mu}{2}\\left\\|z-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}-\\eta\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)}),G_{t}^{(i)}\\right\\rangle+\\frac{\\eta^{2}L}{2}\\left\\|G_{t}^{(i)}\\right\\|^{2}}\\\\ {\\quad+\\left\\langle\\mathbf{s}_{t}^{(i)}-G_{t}^{(i)},z-\\mathbf{y}_{t}^{(i)}+\\eta G_{t}^{(i)}\\right\\rangle}\\\\ {=h(z)-\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}+G_{t}^{(i)},z-\\mathbf{y}_{t}^{(i)}\\right\\rangle-\\frac{\\mu}{2}\\left\\|z-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}}\\\\ {\\quad-\\eta\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)},G_{t}^{(i)}\\right\\rangle-\\eta\\left(1-\\frac{\\eta L}{2}\\right)\\left\\|G_{t}^{i}\\right\\|^{2}}\\end{array}\\tag{57}\n$$\n\nfor any given $z \\in \\mathbb{R}^{d}$. Multiplying $1 - \\alpha$ on both sides of Eq. (57) and setting $z = \\bar{x}_{t}$ , we get\n\n$$\n\\begin{array}{r l}&{\\quad(1-\\alpha)h(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)}))}\\\\ &{\\leq(1-\\alpha)h(\\bar{x}_{t})-(1-\\alpha)\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}+G_{t}^{(i)},\\bar{x}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\rangle-\\frac{\\mu(1-\\alpha)}{2}\\left\\|\\bar{x}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}}\\\\ &{\\quad-(1-\\alpha)\\eta\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)},G_{t}^{(i)}\\right\\rangle-(1-\\alpha)\\eta\\left(1-\\frac{\\eta L}{2}\\right)\\left\\|G_{t}^{i}\\right\\|^{2}.}\\end{array}\n$$\n\nSimilarly, multiplying α on both sides of Eq. (57) and setting $z = x^{*}$ , we obtain that\n\n$$\n\\begin{array}{r l}&{\\quad\\alpha h(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)}))}\\\\ &{\\leq\\alpha h(x^{*})-\\alpha\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}+G_{t}^{(i)},x^{*}-\\mathbf{y}_{t}^{(i)}\\right\\rangle-\\displaystyle\\frac{\\mu\\alpha}{2}\\left\\|x^{*}-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}}\\\\ &{\\quad-\\alpha\\eta\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)},G_{t}^{(i)}\\right\\rangle-\\alpha\\eta\\left(1-\\displaystyle\\frac{\\eta L}{2}\\right)\\left\\|G_{t}^{i}\\right\\|^{2}.}\\end{array}\n$$\n\nAdding above two inequalities, we have\n\n$$\n\\begin{array}{r l}&{\\quad h(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)}))-h(x^{*})}\\\\ &{\\leq(1-\\alpha)\\left(h(\\bar{x}_{t})-h(x^{*})\\right)-\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}+G_{t}^{(i)},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\\\ &{\\quad-\\eta\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)},G_{t}^{(i)}\\right\\rangle-\\eta\\left(1-\\displaystyle\\frac{\\eta L}{2}\\right)\\left\\|G_{t}^{i}\\right\\|^{2}-\\displaystyle\\frac{\\mu\\alpha}{2}\\left\\|x^{*}-\\mathbf{y}_{t}^{i}\\right\\|^{2}.}\\end{array}\\tag{58}\n$$\n\nNote that by Jensen's inequality, we can get that\n\n$$\n\\left\\|x^{*}-{\\bar{y}}_{t}\\right\\|=\\left\\|x^{*}-{\\frac{1}{m}}\\sum_{i=1}^{m}\\mathbf{y}_{t}^{(i)}\\right\\|\\leq{\\sqrt{{\\frac{1}{m}}\\sum_{i=1}^{m}\\left\\|x^{*}-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}}}.\\tag{59}\n$$\n\nThen averaging Eq. (58) from $i = 1$ to m and using the convexity of $h(x)$ , we have\n\n$$\n\\begin{array}{l}{h(\\bar{x}_{t+1})-h(x^{*})}\\\\ {\\leq\\frac{1}{m}\\sum_{i=1}^{m}h(\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})))-h(x^{*})}\\\\ {\\overset{(58)}{\\leq}(1-\\alpha)(h(\\bar{x}_{t})-h(x^{*}))-\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}+G_{t}^{(i)},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\\\ {\\quad-\\frac{\\eta}{m}\\sum_{i=1}^{m}\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)},G_{t}^{(i)}\\right\\rangle-\\eta\\left(1-\\frac{\\eta L}{2}\\right)\\sum_{i=1}^{m}\\left\\|G_{t}^{i}\\right\\|^{2}-\\frac{\\mu\\alpha}{2}\\frac{1}{m}\\sum_{i=1}^{m}\\left\\|x^{*}-\\mathbf{y}_{t}^{i}\\right\\|^{2}}\\\\ {\\overset{(59)}{\\leq}(1-\\alpha)(h(\\bar{x}_{t})-h(x^{*}))-\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}+G_{t}^{(i)},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\\\ {\\quad-\\frac{\\eta}{m}\\sum_{i=1}^{m}\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)},G_{t}^{(i)}\\right\\rangle-\\eta\\left(1-\\frac{\\eta L}{2}\\right)\\frac{1}{m}\\sum_{i=1}^{m}\\left\\|G_{t}^{i}\\right\\|^{2}-\\frac{\\mu\\alpha}{2}\\left\\|x^{*}-\\bar{y}_{t}\\right\\|^{2}.}\\end{array}\\tag{60}\n$$\n\nFurthermore, we have\n\n$$\n\\begin{array}{c}{\\displaystyle\\frac{1}{m}\\sum_{i=1}^{m}\\left(\\mathbf{s}_{t}^{(i)}-G_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)})\\right)^{\\top}\\left((1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\mathbf{y}_{t}^{(i)}\\right)}\\\\ {\\displaystyle=\\frac{1}{m}\\sum_{i=1}^{m}\\left(\\mathbf{s}_{t}^{(i)}-G_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)})\\right)^{\\top}\\left((1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}+\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right)}\\\\ {\\displaystyle\\stackrel{(21)}{=}-\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle+\\displaystyle\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\mathbf{s}_{t}^{(i)}-G_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)}),\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\end{array}\n$$\n\nand\n\n$$\n\\begin{array}{r l}&{\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\mathbf{s}_{t}^{(i)}-G_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)}),\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\\\ {=}&{\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\mathbf{s}_{t}^{(i)}-G_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)})+\\bar{G}_{t},\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\\\ {=}&{\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\mathbf{s}_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)}),\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\rangle+\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\bar{G}_{t}-G_{t}^{(i)},\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\\\ {\\leq}&{\\sqrt{\\frac{1}{m}\\sum_{i=1}^{m}\\left\\|\\mathbf{s}_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)})\\right\\|^{2}}\\cdot\\sqrt{\\frac{1}{m}\\sum_{i=1}^{m}\\left\\|\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}}}\\\\ &{\\quad+\\sqrt{\\frac{1}{m}\\sum_{i=1}^{m}\\left\\|G_{t}^{(i)}-\\bar{G}_{t}\\right\\|^{2}}\\cdot\\sqrt{\\frac{1}{m}\\sum_{i=1}^{m}\\left\\|\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\|^{2}}}\\\\ {\\leq}&{\\frac{\\eta}{m}\\cdot\\frac{\\sum_{i=1}^{m}\\left\\|\\mathbf{s}_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)})\\right\\|^{2}+\\sum_{i=1}^{m}\\left\\|G_{t}^{(i)}-\\bar{G}_{t}\\right\\|^{2}}{2}+\\frac{1}{m\\eta}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}}\\\\ {\\overset{(44),(45)}{\\leq}}&{\\frac{\\eta}{m}\\left(9\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+4M^{2}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}+9\\eta^{-2}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}\\right)+\\frac{1}{\\eta m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}}\\\\ {=}&{\\frac{9\\eta}{m}\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+\\frac{4M^{2}\\eta+10\\eta^{-1}}{m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2},}\\end{array}\n$$\n\nwhere the first inequality is because of Cauchy's inequality and the second inequality is because of $2 a b \\le \\eta a^{2}+ b^{2}/ \\eta$\n\nCombining above two inequalities, we can obtain that\n\n$$\n\\begin{array}{l}{\\displaystyle\\frac{1}{m}\\sum_{i=1}^{m}\\left\\langle\\mathbf{s}_{t}^{(i)}-G_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)}),\\bar{y}_{t}-\\mathbf{y}_{t}^{(i)}\\right\\rangle}\\\\ {\\displaystyle\\leq-\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle+\\frac{9\\eta}{m}\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+\\frac{4M^{2}\\eta+10\\eta^{-1}}{m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}.}\\end{array}\\tag{61}\n$$\n\nMoreover, we have\n\n$$\n\\begin{array}{r l}&{\\quad-\\displaystyle\\frac{\\eta}{m}\\displaystyle\\sum_{i=1}^{m}\\left\\langle\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)},G_{t}^{(i)}\\right\\rangle}\\\\ &{\\le\\displaystyle\\frac{\\eta}{m}\\displaystyle\\sum_{i=1}^{m}\\left\\|\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}\\right\\|\\left\\|G_{t}^{(i)}\\right\\|}\\\\ &{\\le\\displaystyle\\frac{\\eta}{m}\\displaystyle\\sum_{i=1}^{m}\\left(2\\left\\|\\nabla f(\\mathbf{y}_{t}^{(i)})-\\mathbf{s}_{t}^{(i)}\\right\\|^{2}+\\frac{1}{4}\\left\\|G_{t}^{(i)}\\right\\|^{2}\\right)}\\\\ &{\\overset{(44)}{\\le}\\displaystyle\\frac{4\\eta}{m}\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+\\displaystyle\\frac{16M^{2}\\eta}{m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}+\\displaystyle\\frac{\\eta}{4m}\\displaystyle\\sum_{i=1}^{m}\\left\\|G_{t}^{(i)}\\right\\|^{2}.}\\end{array}\\tag{62}\n$$\n\nCombining Eqs. (60), (61) and (62), we can obtain that\n\n$$\n\\begin{array}{r l}&{h(\\bar{x}_{t+1})-h(x^{*})}\\\\ &{\\leq(1-\\alpha)(h(\\bar{x}_{t})-h(x^{*}))-\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle}\\\\ &{\\quad-\\eta\\left(\\frac{3}{4}-\\frac{\\eta L}{2}\\right)\\frac{1}{m}\\sum_{i=1}^{m}\\left\\|G_{t}^{(i)}\\right\\|^{2}-\\frac{\\mu\\alpha}{2}\\left\\|x^{*}-\\bar{y}_{t}\\right\\|^{2}}\\\\ &{\\quad+\\frac{13\\eta}{m}\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+\\frac{20M^{2}\\eta+10\\eta^{-1}}{m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}}\\\\ &{\\leq(1-\\alpha)(h(\\bar{x}_{t})-h(x^{*}))-\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle}\\\\ &{\\quad-\\eta\\left(\\frac{3}{4}-\\frac{\\eta L}{2}\\right)\\left\\|\\bar{G}_{t}\\right\\|^{2}-\\frac{\\mu\\alpha}{2}\\left\\|x^{*}-\\bar{y}_{t}\\right\\|^{2}}\\\\ &{\\quad+\\frac{13\\eta}{m}\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+\\frac{20M^{2}\\eta+10\\eta^{-1}}{m}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2},}\\end{array}\n$$\n\nwhere the last inequality is because of Jensen's inequality.\n\nLemma 22 Letting $\\mathbf x_{t}, \\mathbf y_{t}, \\mathbf s_{t}$ be generated by Algorithm 3, it holds that\n\n$$\n\\begin{array}{l}{\\displaystyle\\frac{\\mu}{2}\\left\\|\\bar{v}_{t+1}-x^{*}\\right\\|^{2}\\leq\\frac{(1-\\alpha)\\mu}{2}\\left\\|\\bar{v}_{t}-x^{*}\\right\\|^{2}+\\displaystyle\\frac{\\alpha\\mu}{2}\\left\\|\\bar{y}_{t}-x^{*}\\right\\|^{2}}\\\\ {\\displaystyle\\qquad+\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle+\\displaystyle\\frac{\\eta}{2}\\left\\|\\bar{G}_{t}\\right\\|^{2}.}\\end{array}\\tag{63}\n$$\n\nProof We have\n\n$$\n\\begin{array}{l}{\\frac{\\mu}{2}\\left\\|\\bar{v}_{t+1}-x^{*}\\right\\|^{2}}\\\\ {\\overset{(38)}{=}\\frac{\\mu}{2}\\left\\|(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-\\frac{\\eta}{\\alpha}\\bar{G}_{t}-x^{*}\\right\\|^{2}}\\\\ {=\\frac{\\mu}{2}\\left\\|(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\|^{2}-\\frac{\\mu\\eta}{\\alpha}\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\rangle+\\frac{\\mu\\eta^{2}}{2\\alpha^{2}}\\left\\|\\bar{G}_{t}\\right\\|^{2}}\\\\ {\\overset{\\alpha=\\sqrt{\\mu\\eta}}{=}\\frac{\\mu}{2}\\left\\|(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\|^{2}-\\alpha\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\rangle+\\frac{\\eta}{2}\\left\\|\\bar{G}_{t}\\right\\|^{2}.}\\end{array}\n$$\n\nFurthermore, by Eq. (36), we have $\\begin{array}{r}{\\bar{v}_{t}=\\bar{y}_{t}+\\frac{1}{\\alpha}(\\bar{y}_{t}-\\bar{x}_{t})}\\end{array}$ which implies that\n\n$$\n(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}=\\bar{y}_{t}+\\frac{1-\\alpha}{\\alpha}(\\bar{y}_{t}-\\bar{x}_{t}).\n$$\n\nThus, it holds that\n\n$$\n-\\alpha\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\rangle=\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle .\n$$\n\nIt also holds that\n\n$$\n\\begin{array}{r l}&{\\quad\\left\\|(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\|^{2}}\\\\ &{\\leq\\left((1-\\alpha)\\left\\|\\bar{v}_{t}-x^{*}\\right\\|+\\alpha\\left\\|\\bar{y}_{t}-x^{*}\\right\\|\\right)^{2}}\\\\ &{\\leq(1-\\alpha)\\left\\|\\bar{v}_{t}-x^{*}\\right\\|^{2}+\\alpha\\left\\|\\bar{y}_{t}-x^{*}\\right\\|^{2}.}\\end{array}\n$$\n\nTherefore, it holds that\n\n$$\n\\frac{\\mu}{2}\\left\\|\\bar{v}_{t+1}-x^{*}\\right\\|^{2}\\leq\\frac{(1-\\alpha)\\mu}{2}\\left\\|\\bar{v}_{t}-x^{*}\\right\\|^{2}+\\frac{\\alpha\\mu}{2}\\left\\|\\bar{y}_{t}-x^{*}\\right\\|^{2}+\\left\\langle\\bar{G}_{t},(1-\\alpha)\\bar{x}_{t}+\\alpha x^{*}-\\bar{y}_{t}\\right\\rangle+\\frac{\\eta}{2}\\left\\|\\bar{G}_{t}\\right\\|^{2}.\n$$\n\nCombining above two lemmas, we can obtain the following result.\n\nProof [Proof of Lemma 11] Using the definition of $V_{t}$ ,we have\n\n$$\n\\begin{array}{r l r}{{V_{t+1}=h({\\bar{x}}_{t+1})-h(x^{*})+\\frac{\\mu}{2}\\|{\\bar{v}}_{t+1}-x^{*}\\|^{2}}}\\\\ &{}&{\\overset{(56),(63)}{\\leq}(1-\\alpha)V_{t}-\\eta(\\frac{1}{4}-\\frac{\\eta L}{2})\\|{\\bar{G}}_{t}\\|^{2}+\\frac{13\\eta}{m}\\|{\\mathbf{s}}_{t}-\\mathbf{1}\\bar{s}_{t}\\|^{2}+\\frac{20M^{2}\\eta+10\\eta^{-1}}{m}\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\|^{2}}\\\\ &{}&{\\leq(1-\\alpha)V_{t}+\\frac{13\\eta}{m}\\|{\\mathbf{s}}_{t}-\\mathbf{1}\\bar{s}_{t}\\|^{2}+\\frac{20M^{2}\\eta+10\\eta^{-1}}{m}\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\|^{2},}\\end{array}\n$$\n\nwhere the last inequality is because of $\\eta=1/(2L)$\n\n### Proof of Lemma 27\n\nProof When $r(x)=0,h(x)$ equals to $f(x)$ . Thus, we use $f(x)$ directly instead of $h(x)$ . By the update procedure of Algorithm 1, we have\n\n$$\n\\begin{array}{l}{f(\\bar{x}_{t+1})\\leq f(\\bar{y}_{t})-\\eta\\left\\langle\\nabla f(\\bar{y}_{t}),\\bar{g}_{t}\\right\\rangle+\\displaystyle\\frac{L\\eta^{2}}2\\left\\|\\bar{g}_{t}\\right\\|^{2}}\\\\ {\\displaystyle=f(\\bar{y}_{t})-\\eta\\left\\langle\\bar{g}_{t},\\bar{g}_{t}\\right\\rangle+\\eta\\left\\langle\\bar{g}_{t},\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\right\\rangle+\\displaystyle\\frac{L\\eta^{2}}2\\left\\|\\bar{g}_{t}\\right\\|^{2}}\\\\ {\\displaystyle=f(\\bar{y}_{t})-\\displaystyle\\frac 1{2L}\\left\\|\\bar{g}_{t}\\right\\|^{2}+\\displaystyle\\frac 1L\\left\\langle\\bar{g}_{t},\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\right\\rangle,}\\end{array}\\tag{73}\n$$\n\nwhere the last equation is because $\\eta = 1 / L$ . Furthermore, by the definition of $V_{t},$ we have\n\n$$\n\\begin{array}{l}{{V_{t+1}=\\displaystyle\\frac{\\mu}{2}\\left\\|\\bar{v}_{t+1}-x^{*}\\right\\|^{2}+f(\\bar{x}_{t+1})-f(x^{*})}}\\\\ {{\\displaystyle\\overset{(38)}{=}\\displaystyle\\frac{\\mu}{2}\\left\\|(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\|^{2}-\\displaystyle\\frac{\\mu}{L\\alpha}\\left\\langle\\bar{g}_{t},(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\rangle}}\\\\ {{\\displaystyle\\qquad+\\frac{\\mu}{2L^{2}\\alpha^{2}}\\left\\|\\bar{g}_{t}\\right\\|^{2}+f(\\bar{x}_{t+1})-f(x^{*})}}\\\\ {{\\displaystyle\\overset{(73)}{\\leq}\\displaystyle\\frac{\\mu}{2}\\left\\|(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\|^{2}-\\alpha\\left\\langle\\bar{g}_{t},(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\rangle}}\\\\ {{\\displaystyle\\qquad+f(\\bar{y}_{t})-f(x^{*})+\\displaystyle\\frac{1}{L}\\left\\langle\\bar{g}_{t},\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\right\\rangle .}}\\end{array}\n$$\n\nFurthermore, by Eq. (37), we can obtain that $\\begin{array}{r}{\\bar{v}_{t}=\\bar{y}_{t}+\\frac{1}{\\alpha}(\\bar{y}_{t}-\\bar{x}_{t})}\\end{array}$ . Then we can obtain\n\n$$\n(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}=\\bar{y}_{t}+\\frac{1-\\alpha}{\\alpha}(\\bar{y}_{t}-\\bar{x}_{t}).\n$$\n\nHence, we have\n\n$$\n\\begin{array}{r l}&{\\quad f(\\bar{y}_{t})-\\alpha\\left\\langle\\bar{g}_{t},(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\rangle-f(x^{*})}\\\\ &{=f(\\bar{y}_{t})+\\left\\langle\\bar{g}_{t},\\alpha x^{*}+(1-\\alpha)\\bar{x}_{t}-\\bar{y}_{t}\\right\\rangle-f(x^{*})}\\\\ &{=(\\alpha+1-\\alpha)f(\\bar{y}_{t})+\\left\\langle\\nabla f(\\bar{y}_{t}),\\alpha(x^{*}-\\bar{y}_{t})+(1-\\alpha)(\\bar{x}_{t}-\\bar{y}_{t})\\right\\rangle-f(x^{*})}\\\\ &{\\quad+\\left\\langle\\bar{g}_{t}-\\nabla f(\\bar{y}_{t}),\\alpha x^{*}+(1-\\alpha)\\bar{x}_{t}-\\bar{y}_{t}\\right\\rangle}\\\\ &{\\leq(1-\\alpha)(f(\\bar{x}_{t})-f(x^{*}))-\\frac{\\alpha\\mu}{2}\\left\\|x^{*}-\\bar{y}_{t}\\right\\|^{2}+\\left\\langle\\bar{g}_{t}-\\nabla f(\\bar{y}_{t}),\\alpha x^{*}+(1-\\alpha)\\bar{x}_{t}-\\bar{y}_{t}\\right\\rangle,}\\end{array}\n$$\n\nwhere the last inequality is because $f(x)$ is µ-strongly convex. Therefore, we can obtain that\n\n$$\n\\begin{array}{l}{{V_{t+1}\\leq\\displaystyle\\frac{\\mu}{2}\\left\\|(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\|^{2}+\\displaystyle\\frac{1}{L}\\left\\langle\\bar{g}_{t},\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\right\\rangle}}\\\\ {{+\\left(1-\\alpha\\right)(f(\\bar{x}_{t})-f(x^{*}))-\\displaystyle\\frac{\\alpha\\mu}{2}\\left\\|x^{*}-\\bar{y}_{t}\\right\\|^{2}+\\left\\langle\\bar{g}_{t}-\\nabla f(\\bar{y}_{t}),\\alpha x^{*}+(1-\\alpha)\\bar{x}_{t}-\\bar{y}_{t}\\right\\rangle}}\\\\ {{\\leq\\displaystyle\\frac{\\mu(1-\\alpha)}{2}\\left\\|\\bar{v}_{t}-x^{*}\\right\\|^{2}+\\displaystyle\\frac{\\mu\\alpha}{2}\\left\\|\\bar{y}_{t}-x^{*}\\right\\|^{2}+\\left(1-\\alpha\\right)(f(\\bar{x}_{t})-f(x^{*}))}}\\\\ {{-\\displaystyle\\frac{\\alpha\\mu}{2}\\left\\|x^{*}-\\bar{y}_{t}\\right\\|^{2}+\\left\\langle\\bar{g}_{t}-\\nabla f(\\bar{y}_{t}),\\alpha x^{*}+(1-\\alpha)\\bar{x}_{t}-\\bar{y}_{t}+\\displaystyle\\frac{1}{L}\\bar{g}_{t}\\right\\rangle}}\\\\ {{=(1-\\alpha)V_{t}+\\displaystyle\\langle\\bar{g}_{t}-\\nabla f(\\bar{y}_{t}),\\alpha x^{*}+(1-\\alpha)\\bar{x}_{t}-\\bar{y}_{t}\\rangle+\\displaystyle\\frac{1}{L}\\left\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\right\\|\\left\\|\\bar{g}_{t}\\right\\|,}}\\end{array}\n$$\n\nwhere the second inequality is because of\n\n$$\n\\begin{array}{r}{\\left\\|\\left(1-\\alpha\\right)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-x^{*}\\right\\|^{2}\\leq\\left(\\left(1-\\alpha\\right)\\left\\|\\bar{v}_{t}-x^{*}\\right\\|+\\alpha\\left\\|\\bar{y}_{t}-x^{*}\\right\\|\\right)^{2}\\leq\\left(1-\\alpha\\right)\\left\\|\\bar{v}_{t}-x^{*}\\right\\|^{2}+\\alpha\\left\\|\\bar{y}_{t}-x^{*}\\right\\|^{2}.}\\end{array}\n$$\n\nFurthermore, we have\n\n$$\n\\|\\alpha x^{*}+(1-\\alpha)\\bar{x}_{t}-\\bar{y}_{t}\\|\\leq(1-\\alpha)\\|\\bar{x}_{t}-x^{*}\\|+\\alpha\\|\\bar{y}_{t}-x^{*}\\|\\leq\\operatorname*{max}\\bigg\\{\\sqrt{\\frac{2}{\\mu}V_{t}},\\sqrt{\\frac{2}{\\mu}V_{t}}\\bigg\\}\\leq\\sqrt{\\frac{2 V_{t}}{\\mu}}.\n$$\n\nTherefore, we have\n\n$$\n\\begin{array}{r l}&{V_{t+1}\\leq(1-\\alpha)V_{t}+\\displaystyle\\frac{1}{L}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|\\|\\bar{g}_{t}\\|+\\sqrt{\\displaystyle\\frac{2V_{t}}{\\mu}}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|}\\\\ &{\\qquad\\leq(1-\\alpha)V_{t}+\\displaystyle\\frac{1}{L}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|^{2}+\\displaystyle\\frac{1}{L}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|\\|\\nabla f(\\bar{y}_{t})\\|+\\sqrt{\\displaystyle\\frac{2V_{t}}{\\mu}}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|}\\\\ &{\\qquad\\leq(1-\\alpha)V_{t}+\\displaystyle\\frac{1}{L}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|^{2}+2\\sqrt{\\displaystyle\\frac{2V_{t}}{\\mu}}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|}\\\\ &{\\qquad\\leq(1-\\alpha)V_{t}+\\displaystyle\\frac{1}{L}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|^{2}+\\displaystyle\\frac{\\alpha}{4}V_{t}+\\displaystyle\\frac{8}{\\alpha^{3}}\\cdot\\frac{1}{L}\\|\\bar{g}_{t}-\\nabla f(\\bar{y}_{t})\\|^{2}}\\\\ &{\\qquad\\overset{(34)}{\\leq}\\Big(1-\\frac{3}{4}\\alpha\\Big)V_{t}+\\Big(1+\\displaystyle\\frac{8}{\\alpha^{3}}\\Big)\\cdot\\displaystyle\\frac{M^{2}}{L}\\cdot\\frac{1}{m}\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\|^{2}.}\\end{array}\n$$\n\n### Proof of Lemma 10\n\nProof It is easy to check that A is non-negative and irreducible. Furthermore, every diagonal entry of A is not zero. Thus, by Perron-Frobenius theorem and Corollary 8.4.7 of Horn and Johnson (2012), A has a real-valued positive number $\\lambda_{1}(\\mathbf{A})$ which is algebraically simple and associated with a strictly positive eigenvector v. It also holds that $\\lambda_{1}(\\mathbf{A})$ is strictly larger than $|\\lambda_{i}(\\mathbf{A})|$ with $i=2,3$\n\nWe write down the characteristic polynomial $p(\\zeta)$ of A, that is\n\n$$\np(\\zeta)=\\zeta p_{0}(\\zeta)-32(M/L)^{2}\\rho^{2}+20\\rho^{2}M/L,\n$$\n\nwhere\n\n$$\np_{0}(\\zeta)=\\zeta^{2}-\\rho\\left(4+5M/L\\right)\\zeta-4\\rho\\left(8\\rho(M/L)^{2}+5M/L+1-5\\rho M/L\\right).\n$$\n\nLet us denote\n\n$$\n\\Delta=16\\rho\\left(8\\rho(M/L)^{2}+5M/L+1-5\\rho M/L\\right).\\tag{50}\n$$\n\nIt is easy to check that $\\Delta > 0$ Thus, two roots of $p_{0}(\\zeta)$ are\n\n$$\n\\zeta_{1}=\\frac{\\rho(4+5M/L)+\\sqrt{(4+5M/L)^{2}\\rho^{2}+\\Delta}}{2}\n$$\n\nand\n\n$$\n\\zeta_{2}=\\frac{\\rho(4+5M/L)-\\sqrt{(4+5M/L)^{2}\\rho^{2}+\\Delta}}{2}.\n$$\n\nBy letting\n\n$$\n\\zeta^{*}=\\frac{2\\rho\\cdot\\left(32(M/L)^{2}+2\\right)\\left(4+5M/L\\right)+\\sqrt{\\operatorname*{max}\\{\\Delta,\\frac{1}{4}\\}}}{2},\n$$\n\nwe have\n\n$$\n\\begin{array}{l}{p(\\zeta^{*})+32(M/L)^{2}\\rho^{2}-20\\rho^{2}M/L}\\\\ {=\\frac{2\\rho\\left(32(M/L)^{2}+2\\right)(4+5M/L)+\\sqrt{\\max\\{\\Delta,\\frac{1}{4}\\}}}{2}}\\\\ {\\quad\\cdot\\frac{2\\rho\\left(32(M/L)^{2}+2\\right)(4+5M/L)+\\sqrt{\\max\\{\\Delta,\\frac{1}{4}\\}}-\\rho(4+5M/L)-\\sqrt{(4+5M/L)^{2}\\rho^{2}+\\Delta}}{2}}\\\\ {\\quad\\cdot\\frac{2\\rho\\left(32(M/L)^{2}+2\\right)(4+5M/L)+\\sqrt{\\max\\{\\Delta,\\frac{1}{4}\\}}-\\rho(4+5M/L)+\\sqrt{(4+5M/L)^{2}\\rho^{2}+\\Delta}}{2}}\\\\ {\\geq\\frac{2\\rho\\left(32(M/L)^{2}+2\\right)(4+5M/L)+\\sqrt{\\max\\{\\Delta,\\frac{1}{4}\\}}}{2}}\\\\ {\\quad\\cdot\\frac{\\left(2\\rho\\left(32(M/L)^{2}+1\\right)(4+5M/L)+\\sqrt{\\max\\{\\Delta,\\frac{1}{4}\\}}\\right)^{2}-\\left(\\sqrt{(4+5M/L)^{2}\\rho^{2}+\\Delta}\\right)^{2}}{2}}\\\\ {=\\frac{2\\rho\\left(32(M/L)^{2}+2\\right)(4+5M/L)+\\sqrt{\\max\\{\\Delta,\\frac{1}{4}\\}}}{2}}\\\\ {\\quad\\cdot\\left(\\frac{\\left(2\\rho\\left(32(M/L)^{2}+1\\right)(4+5M/L)\\right)^{2}+\\max\\{\\Delta,\\frac{1}{4}\\}-((4+5M/L)^{2}\\rho^{2}+\\Delta)}{2}\\right.}\\\\ {\\quad\\left.+\\left(2\\rho\\left(32(M/L)^{2}+1\\right)(4+5M/L)\\right)\\sqrt{\\max\\left\\{\\Delta,\\frac{1}{4}\\right\\}}\\right)}\\\\ {\\geq\\frac{2\\rho\\left(32(M/L)^{2}+2\\right)(4+5M/L)+\\sqrt{\\max\\{\\Delta,\\frac{1}{4}\\}}}{2}}\\\\ {\\quad\\cdot\\left(2\\rho\\left(32(M/L)^{2}+1\\right)(4+5M/L)\\right)\\sqrt{\\max\\left\\{\\Delta,\\frac{1}{4}\\right\\}}}\\\\ {>\\frac{\\left(2\\rho\\left(32(M/L)^{2}+1\\right)(4+5M/L)\\right)\\cdot\\max\\{\\Delta,\\frac{1}{4}\\}}{2}}\\\\ {\\geq\\frac{2\\rho(32(M/L)^{2}+1)\\cdot 5}{8}.}\\end{array}\n$$\n\nThus, we can obtain that\n\n$$\np\\left(\\zeta^{*}\\right)>\\frac{2\\rho(32(M/L)^{2}+1)\\cdot 5}{8}-32(M/L)^{2}\\rho^{2}+20\\rho^{2}M/L>0.\n$$\n\nNote that $p(\\zeta)$ is monotonely increasing in the range $\\lbrack \\zeta^{*}, \\infty ]$ .Thus, $p(\\zeta)$ does not have real roots in this range. This implies $\\lambda_{1}(\\mathbf{A})\\leq\\zeta^{*}$ . By Eq. (50), we can obtain that if $\\rho$ satisfies the condition that\n\n$$\n\\rho\\leq{\\frac{1}{64(8(M/L)^{2}+5M/L+1)}},\\tag{51}\n$$\n\nthen it holds that $\\Delta \\le \\frac{1}{4}$. If $\\rho$ also satisfies the condition that\n\n$$\n\\rho\\leq{\\frac{1}{4\\left(32(M/L)^{2}+2\\right)\\left(4+5M/L\\right)}},\\tag{52}\n$$\n\nthen we can obtain that\n\n$$\n\\lambda_{1}(\\mathbf{A})\\leq\\zeta^{*}\\leq\\frac{\\frac{1}{2}+\\sqrt{\\operatorname*{max}\\{\\Delta,\\frac{1}{4}\\}}}{2}=\\frac{1}{2}.\n$$\n\nIt is easy to check that if $\\rho\\le L^{3}/(1280M^{3})$ , inequalities (51) and (52) hold.\n\nNow, we begin to prove that ${\\sqrt{\\rho}}<\\lambda_{1}(\\mathbf{A})$ . We can conclude this result once it holds $p ({\\sqrt{\\rho}}) < 0$ This is because $p(\\zeta)$ will have a root between $\\sqrt{\\rho}$ and $1 / 2$ and $\\lambda_{1}(\\mathbf{A})$ must be no less than this root. We have\n\n$$\n\\begin{array}{r l}&{\\quad p(\\sqrt{\\rho})}\\\\ &{=\\sqrt{\\rho}p_{0}(\\sqrt{\\rho})-32\\rho^{2}(M/L)^{2}+20\\rho^{2}M/L}\\\\ &{=\\rho\\left(\\sqrt{\\rho}-\\rho(4+5M/L)-4\\sqrt{\\rho}\\left(8\\rho(M/L)^{2}+5M/L+1-5\\rho M/L\\right)-32\\rho(M/L)^{2}+20\\rho M/L\\right)}\\\\ &{=\\rho\\left(-(20M/L+3)\\sqrt{\\rho}-\\rho(4+5M/L)-4\\rho^{3/2}\\left(8(M/L)^{2}-5M/L\\right)-\\rho\\left(32(M/L)^{2}-15M/L\\right)\\right)}\\\\ &{<\\rho\\left(-(20M/L+3)\\sqrt{\\rho}-\\rho(4+5M/L)\\right)}\\\\ &{<0,}\\end{array}\n$$\n\nwhere the first inequality is because of $M / L \\geq 1$\n\nSince v is the eigenvector associated with $\\lambda_{1}(\\mathbf{A})$ , we can obtain that $\\mathbf{A}\\mathbf{v}=\\lambda_{1}(\\mathbf{A})\\mathbf{v}$ and have the following equations\n\n$$\n2{\\bf v}(2)+2{\\bf v}(3)=\\lambda_{1}({\\bf A}){\\bf v}(1),\\tag{53}\n$$\n\n$$\n2\\rho\\mathbf{v}(1)+4\\rho\\mathbf{v}(2)+4\\rho\\mathbf{v}(3)=\\lambda_{1}(\\mathbf{A})\\mathbf{v}(2),\\tag{54}\n$$\n\n$$\n\\rho\\frac{M}{L}\\mathbf{v}(1)+8\\rho\\left(\\frac{M}{L}\\right)^{2}\\mathbf{v}(2)+5\\rho\\frac{M}{L}\\mathbf{v}(3)=\\lambda_{1}(\\mathbf{A})\\mathbf{v}(3).\\tag{55}\n$$\n\nBy Eqs. (53) and (54), we can obtain that\n\n$$\n2\\rho\\mathbf{v}(1)=\\lambda_{1}(\\mathbf{A})\\mathbf{v}(2)-2\\rho\\lambda_{1}(\\mathbf{A})\\mathbf{v}(1),\n$$\n\nwhich implies that\n\n$$\n\\mathbf{v}(1)=\\frac{\\lambda_{1}(\\mathbf{A})\\mathbf{v}(2)}{2\\rho(1+\\lambda_{1}(\\mathbf{A}))}.\n$$\n\nReplacing above equation to Eq. (55), we can obtain that\n\n$$\n\\frac{M\\lambda_{1}(\\mathbf{A})\\mathbf{v}(2)}{2L(1+\\lambda_{1}(\\mathbf{A}))}=\\lambda_{1}(\\mathbf{A})\\mathbf{v}(3)-\\left(8\\rho\\left(\\frac{M}{L}\\right)^{2}\\mathbf{v}(2)+\\frac{5\\rho M}{L}\\mathbf{v}(3)\\right)<\\lambda_{1}(\\mathbf{A})\\mathbf{v}(3),\n$$\n\nwhich implies that\n\n$$\n\\mathbf{v}(2)\\leq\\frac{2L(1+\\lambda_{1}(\\mathbf A))\\mathbf{v}(3)}{M}\\leq\\frac{3L\\mathbf{v}(3)}{M}\\leq 3\\mathbf{v}(3),\n$$\n\nwhere the second inequality is because of $\\rho \\le 1 / 2$ Combining Eq. (53), we can obtain that\n\n$$\n\\mathbf{v}(1)\\leq\\frac{2\\left(3\\mathbf{v}(3)+\\mathbf{v}(3)\\right)}{\\lambda_{1}(\\mathbf{A})}\\leq\\frac{8\\mathbf{v}(3)}{\\sqrt{\\rho}},\n$$\n\nwhere the last inequality is because of $\\lambda_{1}(\\mathbf{A})\\geq{\\sqrt{\\rho}}.$", "context": [{"id": "v24-22-1210:ctx1", "name": "Setup: decentralized composite problem (Section 1, eq. (1))", "statement": "In this paper, we consider the decentralized optimization problem, where the objective function is composed of m local functions $f_{i}(x)$ that are located on m different agents. The agents form a connected and undirected network and each of them only accesses its local function and communicates\n\nwith its neighbors. All of the agents target to cooperatively solve the convex optimization problem\n\n$$\n\\operatorname*{min}_{x\\in\\mathbb{R}^{d}}h(x)\\triangleq f(x)+r(x)\\quad\\mathrm{with}\\quad f(x)\\triangleq\\frac{1}{m}\\sum_{i=1}^{m}f_{i}(x),\\tag{1}\n$$\n\nwhere $f(x)$ is L-smooth and $\\mu$-strongly convex, $r(x)$ is convex but may be non-differentiable."}, {"id": "v24-22-1210:ctx2", "name": "Notation: aggregate variables, averages, prox and generalized gradients (Section 3, eqs. (2)-(6))", "statement": "## 3. Preliminaries\n\nWe let $x_{i}\\in \\mathbb{R}^{d}$ be the local copy of the variable of x for agent i and we introduce the aggregate variable $\\mathbf{x}\\in \\mathbb{R}^{m \\times d}$ , aggregate objective function $F(\\mathbf{x})$ and aggregate gradient $\\nabla F(\\mathbf{x})\\in\\mathbb{R}^{m\\times d}$ as\n\n$$\n\\mathbf{x}=\\left[\\begin{array}{l}{x_{1}^{\\top}}\\\\ {\\vdots}\\\\ {x_{m}^{\\top}}\\end{array}\\right],\\quad F(\\mathbf{x})=\\frac{1}{m}\\sum_{i=1}^{m}f_{i}(x_{i})\\quad\\mathrm{and}\\quad\\nabla F(\\mathbf{x})=\\left[\\begin{array}{l}{\\nabla f_{1}(x_{1})^{\\top}}\\\\ {\\vdots}\\\\ {\\nabla f_{m}(x_{m})^{\\top}}\\end{array}\\right].\\tag{2}\n$$\n\nWe denote that\n\n$$\n\\bar{\\boldsymbol{x}}_{t}=\\frac{1}{m}\\sum_{i=0}^{m}\\mathbf{x}_{t}^{(i)},\\quad\\bar{y}_{t}=\\frac{1}{m}\\sum_{i=0}^{m}\\mathbf{y}_{t}^{(i)}\\quad\\mathrm{and}\\quad\\bar{g}_{t}=\\frac{1}{m}\\sum_{i=0}^{m}\\nabla f_{i}(\\mathbf{y}_{t}^{(i)}),\\tag{3}\n$$\n\nwhere $\\mathbf{x}^{(i)}$ means the i-th row of matrix x. Moreover, we use $\\lVert \\cdot \\rVert$ to denote the Frobenius norm of vector or matrix and use $\\langle x,y\\rangle$ to denote the inner product of vectors x and y.\n\nFurthermore, we denote\n\n$$\nR(\\mathbf{x})=\\frac{1}{m}\\sum_{i=1}^{m}r(x_{i}).\n$$\n\nAccordingly, we introduce the proximal operator and aggregated proximal operator with respect to $r(\\cdot)$ and $R(\\cdot)$ as\n\n$$\n\\mathbf{prox}_{\\eta,r}(x)=\\operatorname*{argmin}_{z\\in\\mathbb{R}^{d}}\\left(r(z)+\\frac{1}{2\\eta}\\|z-x\\|^{2}\\right)\\mathrm{~a n d~}\\mathbf{prox}_{m\\eta,R}(\\mathbf{x})=\\operatorname*{argmin}_{z\\in\\mathbb{R}^{m\\times d}}\\left(R(\\mathbf{z})+\\frac{1}{2 m\\eta}\\|\\mathbf{z}-\\mathbf{x}\\|^{2}\\right).\\tag{4}\n$$\n\nUsing above notations, we define the (aggregated) generalized gradients as\n\n$$\nG_{t}=\\eta^{-1}\\left(\\mathbf{y}_{t}-\\mathbf{prox}_{\\eta m,R}(\\mathbf{y}_{t}-\\eta\\mathbf{s}_{t})\\right)\\ \\mathrm{~a n d~}\\ G_{t}^{(i)}=\\eta^{-1}\\left(\\mathbf{y}_{t}^{(i)}-\\mathbf{prox}_{\\eta,r}(\\mathbf{y}_{t}^{(i)}-\\eta\\mathbf{s}_{t}^{(i)})\\right)\\tag{5}\n$$\n\nWe also denote\n\n$$\n\\bar{G}_{t}=\\frac{1}{m}\\sum_{i=1}^{m}G_{t}^{(i)}.\\tag{6}\n$$"}, {"id": "v24-22-1210:ctx3", "name": "Definitions: L-smoothness, strong convexity, local smoothness, condition numbers (eqs. (7)-(9))", "statement": "Then we introduce the following definitions that will be used in the whole paper:\n\nWe say $f(x)$ is L-smooth if for all $x,y\\in\\mathbb{R}^{d}$ , it holds that\n\n$$\nf(y)\\leq f(x)+\\langle\\nabla f(x),y-x\\rangle+{\\frac{L}{2}}\\left\\|y-x\\right\\|^{2}.\n$$\n\nWe say $f(x)$ is µ-strongly convex, if for all $x,y\\in\\mathbb{R}^{d}$ , it holds that\n\n$$\nf(y)\\geq f(x)+\\langle\\nabla f(x),y-x\\rangle+{\\frac{\\mu}{2}}\\left\\|y-x\\right\\|^{2}.\n$$\n\nWe say $f_{i}(x)$ is locally Mi-smooth if for all $x,y\\in\\mathbb{R}^{d}$ , it holds that\n\n$$\nf_{i}(y)\\leq f_{i}(x)+\\langle\\nabla f_{i}(x),y-x\\rangle+{\\frac{M_{i}}{2}}\\left\\|y-x\\right\\|^{2}.\n$$\n\nWe say $f_{i}(x)$ is locally νi-strongly convex if for all $x,y\\in\\mathbb{R}^{d}$ ,it holds that\n\n$$\nf_{i}(y)\\geq f_{i}(x)+\\langle\\nabla f_{i}(x),y-x\\rangle+{\\frac{\\nu_{i}}{2}}\\left\\|y-x\\right\\|^{2}.\n$$\n\nBased on the smoothness and strong convexity, we can define global and local condition numbers of the objective function as\n\n$$\n\\kappa_{g}=\\frac{L}{\\mu},\\qquad\\hat{\\kappa}_{g}=\\frac{M}{\\mu}\\qquad\\mathrm{and}\\qquad\\kappa_{\\ell}=\\frac{M}{\\nu},\\tag{7}\n$$\n\nwhere\n\n$$\nM=\\operatorname*{max}_{i\\in\\{1,...,m\\}}M_{i}\\mathrm{~a n d~}\\nu=\\operatorname*{min}_{i\\in\\{1,...,m\\}}\\nu_{i}.\\tag{8}\n$$\n\nIt is easy to verify that\n\n$$\nL\\leq M\\qquad\\mathrm{and}\\qquad\\kappa_{g}\\leq\\hat{\\kappa}_{g}\\leq\\kappa_{\\ell}.\\tag{9}\n$$"}, {"id": "v24-22-1210:ctx4", "name": "Assumption: properties of the weight matrix W", "statement": "For the topology of the network, we let W be the weight matrix associated with the network, indicating how agents are connected to each other. We assume that the weight matrix W has the following properties:\n\n1. W is symmetric with $W_{i,j}\\neq 0$ if and if only agents i and j are connected or $i = j ;$\n\n$$\n2 .\\ \\mathbf{0}\\preceq W\\preceq I,W\\mathbf{1}=\\mathbf{1},\\mathrm{null}(I-W)=\\mathrm{span}(\\mathbf{1});\n$$\n\nwhere we use I to denote the $m \\times m$ identity matrix and $\\mathbf{1}=[1,\\ldots,1]^{\\top}\\in\\mathbb{R}^{m}$ denotes the vector with all ones. The weight matrix has an important property that $\\begin{array}{r}{W^{\\infty}= \\frac{1}{m}\\mathbf{1}\\mathbf{1}^{\\top}}\\end{array}$ (Xiao and Boyd, 2004). Thus, one can achieve the effect of averaging local $x_{i}$ on different agents by using Wx for iterations. Instead of directly multiplying W, Liu and Morse (2011) proposed a more efficient way to achieve averaging described in Algorithm 2, which has the following important proposition."}, {"id": "v24-22-1210:ctx5", "name": "Proposition 1 (FastMix averaging and contraction)", "statement": "Proposition 1 Let $\\mathbf{x}^{K}$ be the output of Algorithm 2 with $\\eta_{w}=1/(1+\\sqrt{1-\\lambda_{2}^{2}(W)})$ and we denote $\\begin{array}{r}{\\bar{\\boldsymbol{x}}= \\frac{1}{m}\\mathbf{1}^{\\top}\\mathbf{x}^{0}}\\end{array}$ Then it holds that\n\n$$\n\\bar{x}=\\frac{1}{m}\\mathbf{1}^{\\mathsf{T}}\\mathbf{x}^{K}\\quad and\\quad\\|\\mathbf{x}_{K}-\\mathbf{1}\\bar{x}\\|\\leq\\sqrt{14}\\left(1-\\left(1-\\frac{1}{\\sqrt{2}}\\right)\\sqrt{1-\\lambda_{2}(W)}\\right)^{K}\\|\\mathbf{x}_{0}-\\mathbf{1}\\bar{x}\\|,\n$$\n\nwhere $\\lambda_{2}(W)$ is the second largest eigenvalue of W."}, {"id": "v24-22-1210:ctx6", "name": "Algorithm 1 (Mudag)", "statement": "Algorithm 1 Mudag \n1: Input: $x_{0},\\eta,\\alpha$ , and K \n2: Initialization: $\\mathbf{x}_{0}= \\mathbf{1}x_{0}, \\mathbf{y}_{0}= \\mathbf{x}_{0}$ \n3: $\\mathbf{x}_{1}=\\mathrm{FastMix}(\\mathbf{y}_{0}-\\eta\\nabla F(\\mathbf{y}_{0}))$ \n4: $\\begin{array}{r}{\\mathbf{y}_{1}=\\mathbf{x}_{1}+\\frac{1-\\alpha}{1+\\alpha}(\\mathbf{x}_{1}-\\mathbf{x}_{0})}\\end{array}$ \n5: for $t=1,\\dots,T$ do \n6: $\\mathbf{x}_{t+1}={\\mathrm{FastMix}}(\\mathbf{y}_{t}+(\\mathbf{x}_{t}-\\mathbf{y}_{t-1})-\\eta(\\nabla F(\\mathbf{y}_{t})-\\nabla F(\\mathbf{y}_{t-1})),\\ K)$ \n7: $\\begin{array}{r}{\\mathbf{y}_{t+1}=\\mathbf{x}_{t+1}+\\frac{1-\\alpha}{1+\\alpha}\\left(\\mathbf{x}_{t+1}-\\mathbf{x}_{t}\\right)}\\end{array}$ \n8: end for \n9: Output: $\\mathbf{x}_{T}$"}, {"id": "v24-22-1210:ctx7", "name": "Algorithm 2 (FastMix)", "statement": "Algorithm 2 FastMix \n1: Input: $\\mathbf{x}^{0},K,W$ and $\\eta_{w}$ \n2: $\\mathbf{x}^{- 1}= \\mathbf{x}^{0}$ \n3: for $k=0,\\ldots,K$ do \n4: $\\mathbf{x}^{k+1}=(1+\\eta_{w})W\\mathbf{x}^{k}-\\eta_{w}\\mathbf{x}^{k-1}$ \n5: end for \n6: Output: $\\mathbf{x}^{K}$"}, {"id": "v24-22-1210:ctx8", "name": "ProxMudag updates (eqs. (10)-(12)) and Algorithm 3", "statement": "Our algorithms are based on the multi-consensus, gradient-tracking and Nesterov's acceleration technique. We first introduce ProxMudag (Algorithm 3) for solving the problem with $r(x)\\neq 0$ It has the following algorithmic procedure:\n\n$$\n\\begin{array}{r}{{\\bf x}_{t+1}={\\bf prox}_{\\eta m,R}({\\bf y}_{t}-\\eta{\\bf s}_{t}),}\\end{array}\\tag{10}\n$$\n\n$$\n\\mathbf{y}_{t+1}=\\mathrm{FastMix}\\left(\\mathbf{x}_{t+1}+\\frac{1-\\alpha}{1+\\alpha}(\\mathbf{x}_{t+1}-\\mathbf{x}_{t}),K\\right),\\tag{11}\n$$\n\n$$\n\\begin{array}{r}{\\mathbf{s}_{t+1}=\\mathrm{FastMix}(\\mathbf{s}_{t}+\\nabla F(\\mathbf{y}_{t+1})-\\nabla F(\\mathbf{y}_{t}),\\ K),}\\end{array}\\tag{12}\n$$\n\nwhere η is the step size and K is the step number in multi-consensus. We can observe that Eqs. (10) and (11) belong to the algorithmic framework of accelerated proximal gradient descent since $\\mathbf{s}_{t}$ can approximate the average gradient. In Eq. (12), we introduce $\\mathbf{s}_{t}$ to track the gradient by using history information and the gradient difference. Thus, $\\mathbf{s}_{t}$ can well approximate the average gradient ${\\bf 1}\\bar{g}_{t}$ (defined in Eq. (3)). Furthermore, the variable $\\mathbf{y}_{t}$ can also approximate $\\mathbf{1}\\bar{y}_{t}$ well by the \"FastMix\" operator. Since both $\\bar{y}_{t}$ and $\\bar{g}_{t}$ well approximate the averages, then we can obtain that $\\bar{g}_{t}\\approx\\nabla f(\\bar{y}_{t})$ Thus, the convergence properties of our algorithm are similar to the centralized accelerated proximal gradient descent, which is the main idea behind our approach to the decentralized optimization. In other words, we combine multi-consensus with gradient-tracking to approximate the centralized accelerated proximal gradient descent. As we will show, this seemingly simple idea leads to establishing a near optimal algorithm for the decentralized optimization. Note that Algorithm 3 only takes two multi-consensus steps at each iteration. In contrast, the algorithm in conference version (Ye et al., 2020, Algorithm 1) of this paper requires three multi-consensus steps at each round.\n\nAlgorithm 3 ProxMudag \n1: Input: $x_{0},\\eta,\\alpha,K$ \n2: Initialization: $\\mathbf{x}_{0}=\\mathbf{1}x_{0},\\mathbf{y}_{0}=\\mathbf{x}_{0},\\mathbf{s}_{0}=\\nabla F(\\mathbf{x}_{0})$ \n3: for $t=0,\\ldots,T$ do \n4: $\\mathbf{x}_{t+1}=\\mathbf{prox}_{\\eta m,R}(\\mathbf{y}_{t}-\\eta\\mathbf{s}_{t})$ \n5: $\\begin{array}{r}{\\mathbf{y}_{t+1}=\\mathrm{FastMix}\\left(\\mathbf{x}_{t+1}+\\frac{1-\\alpha}{1+\\alpha}(\\mathbf{x}_{t+1}-\\mathbf{x}_{t}),K\\right)}\\end{array}$ \n6: $\\mathbf{s}_{t+1}=\\mathrm{FastMix}(\\mathbf{s}_{t}+\\nabla F(\\mathbf{y}_{t+1})-\\nabla F(\\mathbf{y}_{t}),\\ K)$ \n7: end for \n8: Output: $\\mathbf{x}_{T}$"}, {"id": "v24-22-1210:ctx9", "name": "Mudag updates (eqs. (13)-(16))", "statement": "In the case of $r(x)=0$ , we propose Mudag (Algorithm 1) that only needs one multi-consensus step for each iteration. The Mudag has the following algorithmic procedure:\n\n$$\n\\begin{array}{r l}&{\\mathbf{x}_{t+1}=\\mathrm{FastMix}(\\mathbf{y}_{t}+(\\mathbf{x}_{t}-\\mathbf{y}_{t-1})-\\eta(\\nabla F(\\mathbf{y}_{t})-\\nabla F(\\mathbf{y}_{t-1})),\\ K),}\\\\ &{\\mathbf{y}_{t+1}=\\mathbf{x}_{t+1}+\\displaystyle\\frac{1-\\alpha}{1+\\alpha}\\left(\\mathbf{x}_{t+1}-\\mathbf{x}_{t}\\right).}\\end{array}\\tag{13}\n$$\n\nTo understand Mudag from perspective of gradient tracking, we can reformulate the above procedure in a form similar to Eqs. (10) to (12) as follows (The reformulation is proved in Lemma 23)\n\n$$\n\\mathbf{x}_{t+1}=\\mathrm{FastMix}\\left(\\mathbf{y}_{t}-\\eta\\mathbf{s}_{t},K\\right),\\tag{14}\n$$\n\n$$\n{\\bf y}_{t+1}={\\bf x}_{t+1}+\\frac{1-\\alpha}{1+\\alpha}({\\bf x}_{t+1}-{\\bf x}_{t}),\\tag{15}\n$$\n\n$$\n\\mathbf{s}_{t+1}=\\mathrm{FastMix}(\\mathbf{s}_{t},K)+(\\nabla F(\\mathbf{y}_{t+1})-\\nabla F(\\mathbf{y}_{t}))-\\eta^{-1}(\\mathrm{FastMix}(\\mathbf{y}_{t},K)-\\mathbf{y}_{t}).\\tag{16}\n$$"}, {"id": "v24-22-1210:ctx10", "name": "Theorem 2 (parameter setting for Algorithm 1)", "statement": "Theorem 2 Let $f(x)$ be L-smooth and µ-strongly convex. Assume each $f_{i}(x)$ is M-smooth. We set $\\eta = 1 / L$ and $\\alpha = \\sqrt{\\mu \\eta}$ in Algorithm 1. Letting K in Algorithm 1 satisfy that\n\n$$\nK=\\frac{\\sqrt{2}}{\\sqrt{2}-1}\\sqrt{\\frac{1}{1-\\lambda_{2}(W)}}\\log\\left(\\frac{\\sqrt{14}}{\\rho}\\right)\\qquad with\\qquad\\rho\\leq\\frac{1}{4^{3}\\cdot 9\\cdot 288}\\cdot\\left(\\frac{L}{M}\\right)^{4}\\kappa_{g}^{-3},\n$$\n\nthen the sequence $\\left\\{\\bar{x}_{t}\\right\\}$ satisfies that\n\n$$\nf(\\bar{x}_{T})-f(x^{*})\\leq\\left(1-\\frac{\\alpha}{2}\\right)^{T}\\left(f(\\bar{x}_{0})-f(x^{*})+\\frac{\\mu\\|\\bar{x}_{0}-x^{*}\\|^{2}}{2}+\\frac{\\mu}{288m}\\sum_{i=1}^{m}\\|\\nabla f_{i}(\\bar{x}_{0})-\\nabla f(\\bar{x}_{0})\\|^{2}\\right),\n$$\n\nwhere $x^{*}$ is the global minimum of $f(x)$ To achieve $\\mathbf{x}_{T}$ such that $\\|\\mathbf{x}_{T}-\\mathbf{1}x^{*}\\|^{2}={\\mathcal{O}}(m\\epsilon/\\mu)$ and $f({\\bar{x}}_{T})-f(x^{*})\\leq\\epsilon,$ the computation and communication complexities of Algorithm 1 are at most\n\n$$\nT=\\mathcal{O}\\left(\\sqrt{\\kappa_{g}}\\log\\left(\\frac{1}{\\epsilon}\\right)\\right)\\qquad and\\qquad Q=\\mathcal{O}\\left(\\sqrt{\\frac{\\kappa_{g}}{1-\\lambda_{2}(W)}}\\log\\left(\\frac{M\\kappa_{g}}{L}\\right)\\log\\left(\\frac{1}{\\epsilon}\\right)\\right)\n$$\n\nrespectively."}, {"id": "v24-22-1210:ctx11", "name": "Theorem 3 (parameter setting for Algorithm 3)", "statement": "Theorem 3 Let $f(x)$ be L-smooth and µ-strongly convex. Assume each $f_{i}(x)$ is M-smooth. We set $\\eta=1/(2L)$ and $\\alpha = \\sqrt{\\mu \\eta}$ in Algorithm 3. Letting K in Algorithm 3 satisfy that\n\n$$\nK=\\frac{\\sqrt{2}}{\\sqrt{2}-1}\\sqrt{\\frac{1}{1-\\lambda_{2}(W)}}\\log{\\left(\\frac{\\sqrt{14}}{\\rho}\\right)}\\qquad with\\qquad\\rho\\leq\\frac{1}{5.5\\cdot 10^{8}}\\cdot\\left(\\frac{L}{M}\\right)^{6}\\kappa_{g}^{-3/2},\n$$\n\nthen sequence $\\{\\bar{x}_{t}\\}$ generated by Algorithm 3 satisfies that\n\n$$\nh(\\bar{x}_{T})-h(x^{*})\\leq\\left(1-\\frac{\\alpha}{2}\\right)^{T}\\left(h(\\bar{x}_{0})-h(x^{*})+\\frac{\\mu\\|\\bar{x}_{0}-x^{*}\\|^{2}}{2}+\\frac{52L}{m}\\sum_{i}^{m}\\|\\nabla f_{i}(\\bar{x}_{0})-\\nabla f(\\bar{x}_{0})\\|^{2}\\right),\n$$\n\nwhere $x^{*}$ is the global minimum of $h(x)$ . To achieve $\\mathbf{x}_{T}$ such that $\\|\\mathbf{x}_{T}-\\mathbf{1}x^{*}\\|^{2}={\\mathcal{O}}(m\\epsilon/\\mu)$ and $h(\\bar{x}_{T})-h(x^{*})\\leq\\epsilon,$ , the computation and communication complexities of Algorithm 1 are at most\n\n$$\nT=\\mathcal{O}\\left(\\sqrt{\\kappa_{g}}\\log\\left(\\frac{1}{\\epsilon}\\right)\\right)\\qquad and\\qquad Q=\\mathcal{O}\\left(\\sqrt{\\frac{\\kappa_{g}}{1-\\lambda_{2}(W)}}\\log\\left(\\frac{M\\kappa_{g}}{L}\\right)\\log\\left(\\frac{1}{\\epsilon}\\right)\\right)\n$$\n\nrespectively."}, {"id": "v24-22-1210:ctx12", "name": "Lyapunov function V_t and v_bar_t (eqs. (17)-(18))", "statement": "We first introduce the Lyapunov function as follows\n\n$$\nV_{t}=h(\\bar{x}_{t})-h(x^{*})+\\frac{\\mu}{2}\\left\\|\\bar{v}_{t}-x^{*}\\right\\|^{2},\\tag{17}\n$$\n\nwhere $\\bar{v}_{t}$ is defined as\n\n$$\n\\bar{v}_{t}=\\bar{x}_{t-1}+\\frac{1}{\\alpha}\\big(\\bar{x}_{t}-\\bar{x}_{t-1}\\big)\\quad\\mathrm{with}\\qquad\\alpha=\\sqrt{\\mu\\eta}.\\tag{18}\n$$"}, {"id": "v24-22-1210:ctx13", "name": "Lemma 8", "statement": "Lemma 8 Let $\\bar{x}_{t}, \\bar{y}_{t}, \\bar{g}_{t}$ and $\\bar{G}_{t}$ (defined in Eqs. (3) and (6)) be generated by Algorithm 3. By setting $\\begin{array}{r}{\\bar{s}_{t}= \\frac{1}{m}\\mathbf{1}^{\\top}\\mathbf{s}_{t}}\\end{array}$ with $\\mathbf{s}_{t}$ defined in Eq. (12), it satisfies:\n\n$$\n\\bar{x}_{t + 1}= \\bar{y}_{t}- \\eta \\bar{G}_{t},\\tag{19}\n$$\n\n$$\n\\bar{y}_{t+1}=\\bar{x}_{t+1}+\\frac{1-\\alpha}{1+\\alpha}(\\bar{x}_{t+1}-\\bar{x}_{t}),\\tag{20}\n$$\n\n$$\n\\bar{s}_{t + 1}= \\bar{s}_{t}+ \\bar{g}_{t + 1}- \\bar{g}_{t}= \\bar{g}_{t + 1}.\\tag{21}\n$$"}, {"id": "v24-22-1210:ctx14", "name": "Lemma 17 (row-wise prox)", "statement": "Lemma 17 Letting $\\mathbf{prox}_{\\eta m,R}^{(i)}(\\mathbf{x})$ denote the i-th row of the matrix $\\mathbf{prox}_{\\eta m,R}(\\mathbf{x})$ (defined in Eqn. (4)), we have the following equation\n\n$$\n\\begin{array}{r}{\\mathbf{prox}_{\\eta m,R}^{(i)}(\\mathbf{x})=\\mathbf{prox}_{\\eta,r}(\\mathbf{x}^{(i)}),}\\end{array}\n$$\n\nwhich implies that $G_{t}^{(i)}$ equals to the i-th row of $G_{t}$ defined in Eq. (5)."}, {"id": "v24-22-1210:ctx15", "name": "Lemma 19", "statement": "Lemma 19 Letting $\\mathbf{s}_{t}^{(i)}$ be the i-th row of $\\mathbf{s}_{t}$ and $G_{t}^{(i)},\\bar{G}_{t}$ (defined in Eqs. (5), (6)) generated by Algorithm 3, we have\n\n$$\n\\sum_{i=1}^{m}\\left\\|\\mathbf{s}_{t}^{(i)}-\\nabla f(\\mathbf{y}_{t}^{(i)})\\right\\|^{2}\\leq 2\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}+8M^{2}\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}\\tag{44}\n$$\n\nand\n\n$$\n\\eta^{2}\\sum_{i=1}^{m}\\left\\|G_{t}^{(i)}-\\bar{G}_{t}\\right\\|^{2}\\leq 18\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|^{2}+16\\eta^{2}\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|^{2}.\\tag{45}\n$$"}, {"id": "v24-22-1210:ctx16", "name": "Lemma 14", "statement": "Lemma 14 For $\\textstyle{\\bar{x}}_{t},{\\bar{y}}_{t}$ and $\\bar{v}_{t}$ defined in Eqs. (3) and (18), then we can obtain that\n\n$$\n\\bar{y}_{t}-\\bar{x}_{t}=\\alpha(\\bar{v}_{t}-\\bar{y}_{t}),\\tag{36}\n$$\n\n$$\n\\bar{y}_{t + 1}= \\frac{\\bar{x}_{t + 1}+ \\alpha \\bar{v}_{t + 1}}{1 + \\alpha},\\tag{37}\n$$\n\nand\n\n$$\n\\bar{v}_{t+1}=\\left\\{\\begin{array}{l l}{(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-\\displaystyle\\frac{\\eta}{\\alpha}\\bar{G}_{t}\\quad}&{r(x),isconvex,}\\\\ {(1-\\alpha)\\bar{v}_{t}+\\alpha\\bar{y}_{t}-\\displaystyle\\frac{\\eta}{\\alpha}\\bar{g}_{t},\\quad}&{r(x)=0.}\\end{array}\\right.\\tag{38}\n$$"}, {"id": "v24-22-1210:ctx17", "name": "Lemma 13", "statement": "Lemma 13 We have\n\n$$\n\\|\\nabla F(\\mathbf{y})-\\nabla F(\\mathbf{x})\\|\\leq M\\|\\mathbf{y}-\\mathbf{x}\\|\\tag{33}\n$$\n\nand\n\n$$\n\\left\\|{\\bar{g}}_{t}- \\nabla f ({\\bar{y}}_{t}) \\right\\| \\leq{\\frac{M}{\\sqrt{m}}}\\left\\| \\mathbf{y}_{t}- \\mathbf{1}{\\bar{y}}_{t}\\right\\| .\\tag{34}\n$$\n\nFurthermore, we have the $\\left(L+2/\\eta\\right)$ -smooth property for the generalized gradient $\\tilde{\\nabla}h(\\cdot)$ (defined in Eq. (42)), i.e.,\n\n$$\n\\left\\|\\tilde{\\nabla}h(x)-\\tilde{\\nabla}h(y)\\right\\|\\leq\\left(\\frac{2}{\\eta}+L\\right)\\|x-y\\|.\\tag{35}\n$$"}, {"id": "v24-22-1210:ctx18", "name": "Lemma 15", "statement": "Lemma 15 Let $f(x)$ be µ-strongly convex. For $\\bar{y}_{t},$ and $V_{t}$ defined in Eqs. (3) and (17) and $x^{*}$ being the optimum, we have the following inequality,\n\n$$\n\\|{\\bar{y}}_{t}- x^{*}\\| \\leq \\sqrt{\\frac{2 V_{t}}{\\mu}}.\\tag{39}\n$$"}, {"id": "v24-22-1210:ctx19", "name": "Lemma 16 (generalized gradient, eq. (42))", "statement": "Lemma 16 (Nesterov (2018)) Letting $\\tilde{\\nabla}h(x)$ the generalized gradient of $h(x)$ (refer to Eq. (1)) be defined as\n\n$$\n\\tilde{\\nabla}h(x)\\triangleq\\frac{x-\\mathbf{prox}_{\\eta,r}(x-\\eta\\nabla f(x))}{\\eta},w i t h\\eta b e i n g t h e s t e p s i z e,\\tag{42}\n$$\n\nthen it holds that $\\tilde{\\nabla}h(x^{*})=0$ if $x^{*}$ minimizes $h(x)$"}, {"id": "v24-22-1210:ctx20", "name": "Lemma 23 (reformulation of Algorithm 1)", "statement": "Lemma 23 The update procedure of Algorithm 1 can be represented as\n\n$$\n\\mathbf{x}_{t+1}=\\mathrm{FastMix}\\left(\\mathbf{y}_{t}-\\eta\\mathbf{s}_{t},K\\right),\\tag{64}\n$$\n\n$$\n{\\bf y}_{t+1}={\\bf x}_{t+1}+\\frac{1-\\alpha}{1+\\alpha}({\\bf x}_{t+1}-{\\bf x}_{t}),\\tag{65}\n$$\n\n$$\n\\mathbf{s}_{t+1}=\\mathrm{FastMix}(\\mathbf{s}_{t},K)+(\\nabla F(\\mathbf{y}_{t+1})-\\nabla F(\\mathbf{y}_{t}))-\\eta^{-1}(\\mathrm{FastMix}(\\mathbf{y}_{t},K)-\\mathbf{y}_{t}),\\tag{66}\n$$\n\nwith ${\\bf s}_{0}= \\nabla F ({\\bf y}_{0})$"}, {"id": "v24-22-1210:ctx21", "name": "Lemma 24", "statement": "Lemma 24 Let $\\bar{x}_{t}, \\bar{y}_{t}, \\bar{g}_{t}$ (defined in Eq. (3)) be generated by Algorithm 1. Then they satisfy the following equalities:\n\n$$\n\\begin{array}{l l}{\\bar{x}_{t+1}=\\bar{y}_{t}-\\eta\\bar{g}_{t},}\\\\ {\\bar{y}_{t+1}=\\bar{x}_{t+1}+\\displaystyle\\frac{1-\\alpha}{1+\\alpha}(\\bar{x}_{t+1}-\\bar{x}_{t}),}\\\\ {\\bar{s}_{t+1}=\\bar{s}_{t}+\\bar{g}_{t+1}-\\bar{g}_{t}=\\bar{g}_{t+1}.}\\end{array}\\tag{68}\n$$"}, {"id": "v24-22-1210:ctx22", "name": "Lemma 9 and the matrix A (eqs. (22)-(23))", "statement": "Lemma 9 Let $\\mathbf{z}_{t}\\ =\\ \\left[\\left\\|\\mathbf{x}_{t}-\\mathbf{1}\\bar{x}_{t}\\right\\|,\\left\\|\\mathbf{y}_{t}-\\mathbf{1}\\bar{y}_{t}\\right\\|,\\eta\\left\\|\\mathbf{s}_{t}-\\mathbf{1}\\bar{s}_{t}\\right\\|\\right]^{\\top}$ with $\\mathbf x_{t}, \\ \\mathbf y_{t}$ and st generated by Algorithm 3, then it holds that\n\n$$\n\\mathbf{z}_{t+1}\\leq\\mathbf{A}\\mathbf{z}_{t}+\\frac{4\\rho\\sqrt{m}M}{L}\\left[0,0,\\sqrt{\\frac{2V_{t}}{\\mu}}\\right]^{\\top},\\tag{22}\n$$\n\nwhere $\\rho$ and $\\mathbf{A}$ are defined as\n\n$$\n\\rho=\\left(1-\\sqrt{1-\\lambda_{2}(W)}\\right)^{K}\\quad and\\quad\\mathbf{A}=\\left[\\begin{array}{c c c}{0}&{2}&{2}\\\\ {2\\rho}&{4\\rho}&{4\\rho}\\\\ {\\rho M/L}&{8\\rho M^{2}/L^{2}}&{5\\rho M/L}\\end{array}\\right].\\tag{23}\n$$"}], "lean": "import Mathlib\n\nnamespace ResearchLevel\n\nopen scoped BigOperators\nopen Polynomial\n\nnoncomputable def rowAvg {m d : ℕ} (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n EuclideanSpace ℝ (Fin d) :=\n (1 / (m : ℝ)) • ∑ i, x i\n\nnoncomputable def Wapply {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) : Fin m → EuclideanSpace ℝ (Fin d) :=\n fun i => ∑ j, W i j • x j\n\nnoncomputable def fastMixAux {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (x0 : Fin m → EuclideanSpace ℝ (Fin d)) :\n ℕ → (Fin m → EuclideanSpace ℝ (Fin d)) × (Fin m → EuclideanSpace ℝ (Fin d))\n | 0 => (x0, x0)\n | (k+1) =>\n ((fun i => (1 + ηw) • Wapply W (fastMixAux W ηw x0 k).1 i\n - ηw • (fastMixAux W ηw x0 k).2 i),\n (fastMixAux W ηw x0 k).1)\n\nnoncomputable def FastMix {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (x0 : Fin m → EuclideanSpace ℝ (Fin d)) (K : ℕ) : Fin m → EuclideanSpace ℝ (Fin d) :=\n (fastMixAux W ηw x0 K).1\n\ntheorem Wapply_sum {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (hW : ∀ j, ∑ i, W i j = 1)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n ∑ i, Wapply W x i = ∑ i, x i := by\n simp only [Wapply]\n rw [Finset.sum_comm]\n refine Finset.sum_congr rfl (fun j _ => ?_)\n rw [← Finset.sum_smul, hW j, one_smul]\n\ntheorem fastMixAux_sum {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (hW : ∀ j, ∑ i, W i j = 1) (x0 : Fin m → EuclideanSpace ℝ (Fin d)) (K : ℕ) :\n (∑ i, (fastMixAux W ηw x0 K).1 i = ∑ i, x0 i) ∧\n (∑ i, (fastMixAux W ηw x0 K).2 i = ∑ i, x0 i) := by\n induction K with\n | zero => simp [fastMixAux]\n | succ k ih =>\n obtain ⟨ih1, ih2⟩ := ih\n constructor\n · simp only [fastMixAux]\n rw [Finset.sum_sub_distrib, ← Finset.smul_sum, ← Finset.smul_sum,\n Wapply_sum W hW, ih1, ih2, ← sub_smul,\n show (1 + ηw) - ηw = (1 : ℝ) from by ring, one_smul]\n · simpa only [fastMixAux] using ih1\n\ntheorem FastMix_rowAvg {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (hW : ∀ j, ∑ i, W i j = 1) (x0 : Fin m → EuclideanSpace ℝ (Fin d)) (K : ℕ) :\n rowAvg (FastMix W ηw x0 K) = rowAvg x0 := by\n unfold rowAvg FastMix\n rw [(fastMixAux_sum W ηw hW x0 K).1]\n\ndef IsSmooth {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (L : ℝ) (f : E → ℝ) (g : E → E) : Prop :=\n ∀ x y, f y ≤ f x + (inner (𝕜 := ℝ) (g x) (y - x)) + (L / 2) * ‖y - x‖ ^ 2\n\ndef IsProxStep {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (c : ℝ) (R : E → ℝ) (a xplus : E) : Prop :=\n ∀ u, R xplus + (1 / (2 * c)) * ‖xplus - a‖ ^ 2 ≤ R u + (1 / (2 * c)) * ‖u - a‖ ^ 2\n\ntheorem lemma11 {d m : ℕ} (hm : 0 < m) (μ L M η α : ℝ)\n (hμ : 0 < μ) (hL : 0 < L) (hM : 0 < M)\n (hLM : L ≤ M) (hη : 0 < η) (hηeq : η = 1 / (2 * L))\n (hα : α = Real.sqrt (μ * η)) (hα1 : α ≤ 1)\n (R : EuclideanSpace ℝ (Fin d) → ℝ) (hRconv : ConvexOn ℝ Set.univ R)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hfsmooth : IsSmooth L f gradf) (hfconv : StrongConvexOn Set.univ μ f)\n (Fi : Fin m → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradFi : Fin m → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hFismooth : ∀ i, IsSmooth M (Fi i) (gradFi i))\n\n (hFiLip : ∀ i x y, ‖gradFi i x - gradFi i y‖ ≤ M * ‖x - y‖)\n (hfavg : f = fun x => (1 / (m : ℝ)) * ∑ i, Fi i x)\n (hgradf_avg : gradf = fun x => (1 / (m : ℝ)) • ∑ i, gradFi i x)\n (xstar : EuclideanSpace ℝ (Fin d)) (hxstar : ∀ x, f xstar + R xstar ≤ f x + R x)\n (xtprev xt xt1 yt yt1 st st1 : Fin m → EuclideanSpace ℝ (Fin d))\n (K : ℕ)\n (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ) (hW : ∀ j, ∑ i, W i j = 1)\n (adj : Fin m → Fin m → Prop) (hWsupp : ∀ i j, W i j ≠ 0 ↔ adj i j ∨ i = j)\n (hWsymm : W.IsSymm) (hWpsd : W.PosSemidef) (hWle : (1 - W).PosSemidef)\n (hWnull : ∀ v : Fin m → ℝ, (1 - W).mulVec v = 0 ↔ ∃ c : ℝ, v = fun _ => c)\n (lam2 : ℝ)\n (hlam2 : IsGreatest {μ : ℝ | ∃ v : Fin m → ℝ, v ≠ 0 ∧ (∑ i, v i = 0) ∧ W.mulVec v = μ • v} lam2)\n (hηw : ηw = 1 / (1 + Real.sqrt (1 - lam2 ^ 2)))\n (hyt : yt = FastMix W ηw (fun i => xt i + ((1 - α) / (1 + α)) • (xt i - xtprev i)) K)\n (hxt1 : ∀ i, IsProxStep η R (yt i - η • st i) (xt1 i))\n (hyt1 : yt1 = FastMix W ηw (fun i => xt1 i + ((1 - α) / (1 + α)) • (xt1 i - xt i)) K)\n (hst1 : st1 = FastMix W ηw (fun i => st i + gradFi i (yt1 i) - gradFi i (yt i)) K)\n (hgtrack : rowAvg st = (1 / (m : ℝ)) • ∑ i, gradFi i (yt i))\n (Vt Vt1 : ℝ)\n (hVt : Vt = (f (rowAvg xt) + R (rowAvg xt) - (f xstar + R xstar))\n + (μ / 2) * ‖(rowAvg xtprev + (1 / α) • (rowAvg xt - rowAvg xtprev)) - xstar‖ ^ 2)\n (hVt1 : Vt1 = (f (rowAvg xt1) + R (rowAvg xt1) - (f xstar + R xstar))\n + (μ / 2) * ‖(rowAvg xt + (1 / α) • (rowAvg xt1 - rowAvg xt)) - xstar‖ ^ 2) :\n Vt1 ≤ (1 - α) * Vt + (13 * η / m) * (∑ i, ‖st i - rowAvg st‖ ^ 2)\n + ((20 * M ^ 2 * η + 10 * η⁻¹ + (1 + 8 / α ^ 3) * M ^ 2 / L) / m) * (∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n sorry\n\ntheorem lemma27 {d m : ℕ} (hm : 0 < m) (μ L M η α : ℝ)\n (hμ : 0 < μ) (hL : 0 < L) (hM : 0 < M)\n (hLM : L ≤ M) (hη : 0 < η) (hηeq : η = 1 / L)\n (hα : α = Real.sqrt (μ * η))\n (hα1 : α ≤ 1)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hfsmooth : IsSmooth L f gradf) (hfconv : StrongConvexOn Set.univ μ f)\n (Fi : Fin m → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradFi : Fin m → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hFismooth : ∀ i, IsSmooth M (Fi i) (gradFi i))\n\n (hFiLip : ∀ i x y, ‖gradFi i x - gradFi i y‖ ≤ M * ‖x - y‖)\n (hfavg : f = fun x => (1 / (m : ℝ)) * ∑ i, Fi i x)\n (hgradf_avg : gradf = fun x => (1 / (m : ℝ)) • ∑ i, gradFi i x)\n (xstar : EuclideanSpace ℝ (Fin d)) (hxstar : ∀ x, f xstar ≤ f x)\n (xtprev ytprev xt yt xt1 : Fin m → EuclideanSpace ℝ (Fin d))\n (K : ℕ)\n (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ) (hW : ∀ j, ∑ i, W i j = 1)\n (adj : Fin m → Fin m → Prop) (hWsupp : ∀ i j, W i j ≠ 0 ↔ adj i j ∨ i = j)\n (hWsymm : W.IsSymm) (hWpsd : W.PosSemidef) (hWle : (1 - W).PosSemidef)\n (hWnull : ∀ v : Fin m → ℝ, (1 - W).mulVec v = 0 ↔ ∃ c : ℝ, v = fun _ => c)\n (lam2 : ℝ)\n (hlam2 : IsGreatest {μ : ℝ | ∃ v : Fin m → ℝ, v ≠ 0 ∧ (∑ i, v i = 0) ∧ W.mulVec v = μ • v} lam2)\n (hηw : ηw = 1 / (1 + Real.sqrt (1 - lam2 ^ 2)))\n (hyt : yt = fun i => xt i + ((1 - α) / (1 + α)) • (xt i - xtprev i))\n (hprevavg : rowAvg xt = rowAvg ytprev\n - η • ((1 / (m : ℝ)) • ∑ i, gradFi i (ytprev i)))\n (hxt1 : xt1 = FastMix W ηw (fun i => yt i + (xt i - ytprev i)\n - η • (gradFi i (yt i) - gradFi i (ytprev i))) K)\n (Vt Vt1 : ℝ)\n (hVt : Vt = (f (rowAvg xt) - f xstar)\n + (μ / 2) * ‖(rowAvg xtprev + (1 / α) • (rowAvg xt - rowAvg xtprev)) - xstar‖ ^ 2)\n (hVt1 : Vt1 = (f (rowAvg xt1) - f xstar)\n + (μ / 2) * ‖(rowAvg xt + (1 / α) • (rowAvg xt1 - rowAvg xt)) - xstar‖ ^ 2) :\n Vt1 ≤ (1 - (3 / 4) * α) * Vt\n + (1 + 8 / α ^ 3) * (M ^ 2 / L) * (1 / m) * (∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n sorry\n\ntheorem lemma10 (L M ρ : ℝ) (hL : 0 < L) (η : ℝ) (hηeq : η = 1 / (2 * L)) (hM : 0 < M) (hLM : L ≤ M) (hρpos : 0 < ρ)\n (hρ : ρ ≤ L ^ 3 / (1280 * M ^ 3))\n (A : Matrix (Fin 3) (Fin 3) ℝ)\n (hA : A = !![0, 2, 2; 2 * ρ, 4 * ρ, 4 * ρ; ρ * M / L, 8 * ρ * M ^ 2 / L ^ 2, 5 * ρ * M / L]) :\n ∃ l1 l2 l3 : ℝ, A.charpoly = (X - C l1) * (X - C l2) * (X - C l3) ∧\n 0 < l1 ∧ |l3| ≤ |l2| ∧ |l2| < l1 ∧ l1 ≤ 1 / 2 ∧\n ∃ v : Fin 3 → ℝ, A.mulVec v = l1 • v ∧\n 0 < v 0 ∧ v 0 ≤ 8 * v 2 / Real.sqrt ρ ∧\n 0 < v 1 ∧ v 1 ≤ 3 * v 2 ∧\n 0 < v 2 := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnamespace ResearchLevel\n\nopen scoped BigOperators\nopen Polynomial\n\nnoncomputable def rowAvg {m d : ℕ} (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n EuclideanSpace ℝ (Fin d) :=\n (1 / (m : ℝ)) • ∑ i, x i\n\nnoncomputable def Wapply {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) : Fin m → EuclideanSpace ℝ (Fin d) :=\n fun i => ∑ j, W i j • x j\n\nnoncomputable def fastMixAux {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (x0 : Fin m → EuclideanSpace ℝ (Fin d)) :\n ℕ → (Fin m → EuclideanSpace ℝ (Fin d)) × (Fin m → EuclideanSpace ℝ (Fin d))\n | 0 => (x0, x0)\n | (k+1) =>\n ((fun i => (1 + ηw) • Wapply W (fastMixAux W ηw x0 k).1 i\n - ηw • (fastMixAux W ηw x0 k).2 i),\n (fastMixAux W ηw x0 k).1)\n\nnoncomputable def FastMix {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (x0 : Fin m → EuclideanSpace ℝ (Fin d)) (K : ℕ) : Fin m → EuclideanSpace ℝ (Fin d) :=\n (fastMixAux W ηw x0 K).1\n\ntheorem Wapply_sum {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (hW : ∀ j, ∑ i, W i j = 1)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n ∑ i, Wapply W x i = ∑ i, x i := by\n simp only [Wapply]\n rw [Finset.sum_comm]\n refine Finset.sum_congr rfl (fun j _ => ?_)\n rw [← Finset.sum_smul, hW j, one_smul]\n\ntheorem fastMixAux_sum {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (hW : ∀ j, ∑ i, W i j = 1) (x0 : Fin m → EuclideanSpace ℝ (Fin d)) (K : ℕ) :\n (∑ i, (fastMixAux W ηw x0 K).1 i = ∑ i, x0 i) ∧\n (∑ i, (fastMixAux W ηw x0 K).2 i = ∑ i, x0 i) := by\n induction K with\n | zero => simp [fastMixAux]\n | succ k ih =>\n obtain ⟨ih1, ih2⟩ := ih\n constructor\n · simp only [fastMixAux]\n rw [Finset.sum_sub_distrib, ← Finset.smul_sum, ← Finset.smul_sum,\n Wapply_sum W hW, ih1, ih2, ← sub_smul,\n show (1 + ηw) - ηw = (1 : ℝ) from by ring, one_smul]\n · simpa only [fastMixAux] using ih1\n\ntheorem FastMix_rowAvg {m d : ℕ} (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ)\n (hW : ∀ j, ∑ i, W i j = 1) (x0 : Fin m → EuclideanSpace ℝ (Fin d)) (K : ℕ) :\n rowAvg (FastMix W ηw x0 K) = rowAvg x0 := by\n unfold rowAvg FastMix\n rw [(fastMixAux_sum W ηw hW x0 K).1]\n\ndef IsSmooth {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (L : ℝ) (f : E → ℝ) (g : E → E) : Prop :=\n ∀ x y, f y ≤ f x + (inner (𝕜 := ℝ) (g x) (y - x)) + (L / 2) * ‖y - x‖ ^ 2\n\ndef IsProxStep {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (c : ℝ) (R : E → ℝ) (a xplus : E) : Prop :=\n ∀ u, R xplus + (1 / (2 * c)) * ‖xplus - a‖ ^ 2 ≤ R u + (1 / (2 * c)) * ‖u - a‖ ^ 2\n\nsection AGDHelpers\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n\nprivate lemma nsq (a b : ℝ) (p q : E) :\n ‖a • p + b • q‖^2 = a^2*‖p‖^2 + 2*a*b*(inner (𝕜 := ℝ) p q) + b^2*‖q‖^2 := by\n rw [norm_add_sq_real, norm_smul, norm_smul, real_inner_smul_left, real_inner_smul_right]\n simp only [Real.norm_eq_abs, mul_pow, sq_abs]\n ring\n\nprivate lemma nsq_sub (c : ℝ) (u g : E) :\n ‖u - c • g‖^2 = ‖u‖^2 - 2*c*(inner (𝕜 := ℝ) u g) + c^2*‖g‖^2 := by\n have h : u - c • g = (1:ℝ) • u + (-c) • g := by module\n rw [h, nsq]; ring\n\nprivate lemma nsq_conv (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) (p q : E) :\n ‖a • p + b • q‖^2 ≤ a*‖p‖^2 + b*‖q‖^2 := by\n rw [nsq]\n have h := real_inner_le_norm p q\n have h2 : (inner (𝕜 := ℝ) p q) ≤ (‖p‖^2 + ‖q‖^2)/2 := by\n nlinarith [sq_nonneg (‖p‖ - ‖q‖), h]\n have key : 2*a*b*(inner (𝕜 := ℝ) p q) ≤ a*b*(‖p‖^2+‖q‖^2) := by\n nlinarith [mul_le_mul_of_nonneg_left h2 (mul_nonneg ha hb)]\n have hb' : b = 1 - a := by linarith\n subst hb'\n nlinarith [key]\n\nprivate lemma strong_subgrad\n (L μ : ℝ) (hL : 0 < L) (hμ : 0 ≤ μ) (f : E → ℝ) (g : E → E)\n (hs : IsSmooth L f g) (hc : StrongConvexOn Set.univ μ f) (x y : E) :\n f x + (inner (𝕜 := ℝ) (g x) (y - x)) + (μ/2) * ‖y - x‖^2 ≤ f y := by\n set N : ℝ := ‖y - x‖^2 with hN\n have hNnn : 0 ≤ N := by positivity\n set I : ℝ := (inner (𝕜 := ℝ) (g x) (y - x)) with hI\n have key : ∀ t : ℝ, 0 < t → f x + I + (μ/2) * N ≤ f y + (L/2) * t * N := by\n intro t ht\n have h1t : (0:ℝ) < 1 + t := by linarith\n set w : E := x + t • (x - y) with hw\n have hab : t/(1+t) + 1/(1+t) = 1 := by field_simp; ring\n have hcomb : (t/(1+t)) • y + (1/(1+t)) • w = x := by\n rw [hw]; match_scalars <;> field_simp <;> ring\n have hsc := hc.2 (Set.mem_univ y) (Set.mem_univ w) (by positivity) (by positivity) hab\n rw [hcomb] at hsc\n have hyw : ‖y - w‖ = (1+t) * ‖y - x‖ := by\n have h : y - w = (1+t) • (y - x) := by rw [hw]; module\n rw [h, norm_smul]\n simp [abs_of_pos h1t]\n rw [hyw] at hsc\n have hsm := hs x w\n have hwx : w - x = t • (x - y) := by rw [hw]; module\n rw [hwx, norm_smul, real_inner_smul_right] at hsm\n have hxy : ‖x - y‖ = ‖y - x‖ := norm_sub_rev x y\n rw [hxy] at hsm\n have hinn : (inner (𝕜 := ℝ) (g x) (x - y)) = - I := by\n rw [hI, ← inner_neg_right]; congr 1; abel\n rw [hinn] at hsm\n simp only [smul_eq_mul, Real.norm_eq_abs, abs_of_pos ht] at hsc hsm\n have hA : t / (1 + t) * (1 / (1 + t)) * (μ / 2 * ((1 + t) * ‖y - x‖) ^ 2)\n = t * (μ/2) * N := by rw [hN]; field_simp\n rw [hA] at hsc\n have hclean : (1+t) * f x ≤ t * f y + f w - (1+t) * (t * (μ/2) * N) := by\n have h2 := mul_le_mul_of_nonneg_left hsc h1t.le\n have h3 : (1+t) * (t / (1 + t) * f y + 1 / (1 + t) * f w - t * (μ / 2) * N)\n = t * f y + f w - (1+t) * (t * (μ/2) * N) := by field_simp\n linarith [h2, h3.le, h3.ge]\n have hsm2 : f w ≤ f x + t * (-I) + L / 2 * (t * ‖y - x‖) ^ 2 := hsm\n have hsq : L / 2 * (t * ‖y - x‖) ^ 2 = (L/2) * t^2 * N := by rw [hN]; ring\n rw [hsq] at hsm2\n have hmain : t * (f x + I + (μ/2) * N) ≤ t * (f y + (L/2) * t * N) := by\n nlinarith [hclean, hsm2, mul_nonneg (mul_nonneg (sq_nonneg t) hμ) hNnn]\n exact le_of_mul_le_mul_left hmain ht\n by_cases h : N = 0\n · have h1 := key 1 one_pos\n rw [h] at h1 ⊢\n simpa using h1\n · have hpos : 0 < N := lt_of_le_of_ne hNnn (Ne.symm h)\n refine le_of_forall_pos_le_add ?_\n intro ε hε\n have ht : 0 < ε / ((L/2) * N) := by positivity\n have h1 := key _ ht\n have heq : (L/2) * (ε / ((L/2) * N)) * N = ε := by field_simp\n linarith [h1, heq.le, heq.ge]\n\nprivate lemma grad_sq_le (L : ℝ) (hL : 0 < L) (f : E → ℝ) (G : E → E)\n (hs : IsSmooth L f G) (xs : E) (hxs : ∀ x, f xs ≤ f x) (y : E) :\n ‖G y‖^2 ≤ 2*L*(f y - f xs) := by\n have h := hs y (y - (1/L) • G y)\n have e1 : y - (1/L) • G y - y = -((1/L) • G y) := by module\n rw [e1, inner_neg_right, real_inner_smul_right, real_inner_self_eq_norm_sq,\n norm_neg, norm_smul] at h\n simp only [Real.norm_eq_abs, mul_pow, sq_abs, div_pow, one_pow] at h\n have hy := hxs (y - (1/L) • G y)\n have hLne : (L:ℝ) ≠ 0 := ne_of_gt hL\n have hkey : f xs ≤ f y - (1/(2*L)) * ‖G y‖^2 := by\n refine le_trans hy (le_trans h (le_of_eq ?_))\n field_simp\n ring\n have h4 : (1/(2*L)) * ‖G y‖^2 ≤ f y - f xs := by linarith\n have h2 : 0 < 2*L := by linarith\n rw [div_mul_eq_mul_div, one_mul, div_le_iff₀ h2] at h4\n linarith [h4]\n\nprivate lemma grad_zero_at_min (L : ℝ) (hL : 0 < L) (f : E → ℝ) (G : E → E)\n (hs : IsSmooth L f G) (xs : E) (hxs : ∀ x, f xs ≤ f x) : G xs = 0 := by\n have h := grad_sq_le L hL f G hs xs hxs xs\n rw [sub_self, mul_zero] at h\n have h2 : ‖G xs‖ = 0 := by\n have h3 : ‖G xs‖^2 = 0 := le_antisymm h (sq_nonneg _)\n exact pow_eq_zero_iff (two_ne_zero) |>.mp h3\n exact norm_eq_zero.mp h2\n\nset_option maxHeartbeats 2000000 in\nprivate lemma agd_core\n (μ L α : ℝ) (hμ : 0 < μ) (hL : 0 < L) (hα : 0 < α) (hα1 : α ≤ 1)\n (hμL : μ = α^2 * L)\n (f : E → ℝ) (G : E → E) (hs : IsSmooth L f G) (hc : StrongConvexOn Set.univ μ f)\n (xs : E) (hxs : ∀ x, f xs ≤ f x)\n (xb z yb x1b z1 g : E)\n (hyb : yb = (1/(1+α)) • xb + (α/(1+α)) • z)\n (hx1b : x1b = yb - (1/L) • g)\n (hz1 : z1 = (1-α) • z + α • yb - (α/μ) • g)\n (Er : ℝ) (hEr : ‖g - G yb‖^2 ≤ Er) :\n (f x1b - f xs) + (μ/2)*‖z1 - xs‖^2\n ≤ (1 - (3/4)*α) * ((f xb - f xs) + (μ/2)*‖z - xs‖^2) + (1 + 8/α^3) * Er / L := by\n subst hμL\n have h1a : (0:ℝ) < 1 + α := by linarith\n have hLne : (L:ℝ) ≠ 0 := ne_of_gt hL\n have hαne : (α:ℝ) ≠ 0 := ne_of_gt hα\n have hsub := strong_subgrad L (α^2*L) hL (by positivity) f G hs hc\n have hGxs : G xs = 0 := grad_zero_at_min L hL f G hs xs hxs\n obtain ⟨Gy, hGyd⟩ : ∃ w : E, w = G yb := ⟨_, rfl⟩\n obtain ⟨e, hed⟩ : ∃ w : E, w = g - Gy := ⟨_, rfl⟩\n obtain ⟨u, hud⟩ : ∃ w : E, w = (1-α) • (z - xs) + α • (yb - xs) := ⟨_, rfl⟩\n rw [← hGyd] at hEr\n rw [← hed] at hEr\n -- vector identities\n have hz1u : z1 - xs = u - (α/(α^2*L)) • g := by rw [hz1, hud]; module\n have hnormz1 : ‖z1 - xs‖^2\n = ‖u‖^2 - 2*(α/(α^2*L))*(inner (𝕜 := ℝ) u g) + (α/(α^2*L))^2*‖g‖^2 := by\n rw [hz1u]; exact nsq_sub _ _ _\n have hybxs : yb - xs = (1/(1+α)) • (xb - xs) + (α/(1+α)) • (z - xs) := by\n rw [hyb]; match_scalars <;> (field_simp; try ring)\n have hzy : z - yb = (1/α) • (yb - xb) := by\n rw [hyb]; match_scalars <;> (field_simp; try ring)\n -- inner product decompositions\n have hgGe : g = Gy + e := by rw [hed]; abel\n have hIug : (inner (𝕜 := ℝ) u g) = (inner (𝕜 := ℝ) u Gy) + (inner (𝕜 := ℝ) u e) := by\n nth_rewrite 1 [hgGe]; rw [inner_add_right]\n have hzxs : z - xs = (1/α) • (yb - xb) + (yb - xs) := by rw [← hzy]; abel\n have hIzG : (inner (𝕜 := ℝ) (z - xs) Gy)\n = (1/α) * (inner (𝕜 := ℝ) (yb - xb) Gy) + (inner (𝕜 := ℝ) (yb - xs) Gy) := by\n rw [hzxs, inner_add_left, real_inner_smul_left]\n have hIuG : (inner (𝕜 := ℝ) u Gy)\n = ((1-α)/α) * (inner (𝕜 := ℝ) (yb - xb) Gy) + (inner (𝕜 := ℝ) (yb - xs) Gy) := by\n rw [hud, inner_add_left, real_inner_smul_left, real_inner_smul_left, hIzG]\n field_simp\n ring\n have hconvu : ‖u‖^2 ≤ (1-α)*‖z - xs‖^2 + α*‖yb - xs‖^2 := by\n rw [hud]; exact nsq_conv (1-α) α (by linarith) hα.le (by ring) _ _\n -- subgradient inequalities\n have hsub1 : f yb - f xb ≤ (inner (𝕜 := ℝ) (yb - xb) Gy) := by\n have h := hsub yb xb\n rw [← hGyd] at h\n have hcomm : (inner (𝕜 := ℝ) Gy (xb - yb)) = -(inner (𝕜 := ℝ) (yb - xb) Gy) := by\n rw [real_inner_comm, ← inner_neg_left]; congr 1; abel\n rw [hcomm] at h\n have hnn : 0 ≤ α^2*L/2 * ‖xb - yb‖^2 := by positivity\n linarith\n have hsub2 : f yb - f xs + (α^2*L/2)*‖yb - xs‖^2 ≤ (inner (𝕜 := ℝ) (yb - xs) Gy) := by\n have h := hsub yb xs\n rw [← hGyd] at h\n have hcomm : (inner (𝕜 := ℝ) Gy (xs - yb)) = -(inner (𝕜 := ℝ) (yb - xs) Gy) := by\n rw [real_inner_comm, ← inner_neg_left]; congr 1; abel\n have hn : ‖xs - yb‖ = ‖yb - xs‖ := norm_sub_rev _ _\n rw [hcomm, hn] at h\n linarith\n -- smoothness step\n have hsm : f x1b ≤ f yb - (1/L)*(‖g‖^2/2) + (1/L)*(inner (𝕜 := ℝ) e g) := by\n have h := hs yb x1b\n rw [← hGyd] at h\n have e1 : x1b - yb = -((1/L) • g) := by rw [hx1b]; module\n rw [e1, inner_neg_right, real_inner_smul_right, norm_neg, norm_smul] at h\n have hGyg : (inner (𝕜 := ℝ) Gy g) = ‖g‖^2 - (inner (𝕜 := ℝ) e g) := by\n have hg2 : Gy = g - e := by rw [hed]; abel\n rw [hg2, inner_sub_left, real_inner_self_eq_norm_sq]\n rw [hGyg] at h\n have habs : ‖(1/L : ℝ)‖ = 1/L := by\n rw [Real.norm_eq_abs, abs_of_pos]; positivity\n rw [habs] at h\n have hq : L/2 * (1/L*‖g‖)^2 = (1/L)*(‖g‖^2/2) := by field_simp; try ring\n rw [hq] at h\n linarith\n -- master inequality\n have hstep : (α^2*L/2)*‖z1 - xs‖^2 = (α^2*L/2)*‖u‖^2\n - (1-α)*(inner (𝕜 := ℝ) (yb - xb) Gy)\n - α*(inner (𝕜 := ℝ) (yb - xs) Gy) - α*(inner (𝕜 := ℝ) u e)\n + (1/L)*(‖g‖^2/2) := by\n rw [hnormz1, hIug, hIuG]\n field_simp\n ring\n have hmaster : (f x1b - f xs) + (α^2*L/2)*‖z1 - xs‖^2\n ≤ (1-α)*((f xb - f xs) + (α^2*L/2)*‖z - xs‖^2)\n + (1/L)*(inner (𝕜 := ℝ) e g) - α*(inner (𝕜 := ℝ) u e) := by\n have m1 := mul_le_mul_of_nonneg_left hsub1 (by linarith : (0:ℝ) ≤ 1 - α)\n have m2 := mul_le_mul_of_nonneg_left hsub2 hα.le\n have m3 := mul_le_mul_of_nonneg_left hconvu (by positivity : (0:ℝ) ≤ α^2*L/2)\n rw [hstep]\n nlinarith [hsm, m1, m2, m3]\n -- ===== phase 2 : absorbing the error terms =====\n have hA0 : 0 ≤ f xb - f xs := by linarith [hxs xb]\n have hAy0 : 0 ≤ f yb - f xs := by linarith [hxs yb]\n have hPnn : (0:ℝ) ≤ ‖z - xs‖^2 := sq_nonneg _\n have hfz : f z - f xs ≤ (L/2)*‖z - xs‖^2 := by\n have h := hs xs z\n rw [hGxs, inner_zero_left] at h\n linarith\n have hconvf : f yb ≤ (1/(1+α))*f xb + (α/(1+α))*f z := by\n have hab : 1/(1+α) + α/(1+α) = 1 := by field_simp\n have h := hc.2 (Set.mem_univ xb) (Set.mem_univ z) (by positivity) (by positivity) hab\n rw [← hyb] at h\n simp only [smul_eq_mul] at h\n have hnn : 0 ≤ (1/(1+α))*(α/(1+α))*(α^2*L/2*‖xb - z‖^2) := by positivity\n linarith\n have hmul : (1+α) * (f yb - f xs) ≤ (f xb - f xs) + α * (f z - f xs) := by\n have h2 := mul_le_mul_of_nonneg_left hconvf h1a.le\n have h3 : (1+α) * ((1/(1+α))*f xb + (α/(1+α))*f z) = f xb + α * f z := by field_simp\n linarith [h2, h3.le, h3.ge]\n have hAyV : α*(f yb - f xs) ≤ (f xb - f xs) + (α^2*L/2)*‖z - xs‖^2 := by\n have h4 := mul_le_mul_of_nonneg_left hmul hα.le\n have h5 := mul_le_mul_of_nonneg_left hfz (by positivity : (0:ℝ) ≤ α^2)\n linarith [h4, h5, mul_nonneg (sq_nonneg α) hAy0,\n mul_nonneg (by linarith : (0:ℝ) ≤ 1-α) hA0]\n have hxbxs : (α^2*L/2)*‖xb - xs‖^2 ≤ f xb - f xs := by\n have h := hsub xs xb\n rw [hGxs, inner_zero_left] at h\n linarith\n have hQconv : ‖yb - xs‖^2 ≤ (1/(1+α))*‖xb - xs‖^2 + (α/(1+α))*‖z - xs‖^2 := by\n rw [hybxs]\n exact nsq_conv (1/(1+α)) (α/(1+α)) (by positivity) (by positivity) (by field_simp) _ _\n have hQV : (α^2*L/2)*‖yb - xs‖^2 ≤ (f xb - f xs) + (α^2*L/2)*‖z - xs‖^2 := by\n have hm := mul_le_mul_of_nonneg_left hQconv\n (by positivity : (0:ℝ) ≤ (1+α)*(α^2*L/2))\n have heq : (1+α)*(α^2*L/2)*((1/(1+α))*‖xb - xs‖^2 + (α/(1+α))*‖z - xs‖^2)\n = (α^2*L/2)*‖xb - xs‖^2 + α*((α^2*L/2)*‖z - xs‖^2) := by field_simp; try ring\n have hn1 : 0 ≤ α*((α^2*L/2)*‖yb - xs‖^2) := by positivity\n have hn2 : 0 ≤ (1-α)*((α^2*L/2)*‖z - xs‖^2) := by\n apply mul_nonneg (by linarith); positivity\n linarith [hm, heq.le, heq.ge, hxbxs, hn1, hn2]\n have hUV : (α^2*L/2)*‖u‖^2 ≤ (f xb - f xs) + (α^2*L/2)*‖z - xs‖^2 := by\n have hm := mul_le_mul_of_nonneg_left hconvu (by positivity : (0:ℝ) ≤ α^2*L/2)\n have h6 := mul_le_mul_of_nonneg_left hQV hα.le\n linarith [hm, h6, mul_nonneg (by linarith : (0:ℝ) ≤ 1-α) hA0]\n have hNG : ‖Gy‖^2 ≤ 2*L*(f yb - f xs) := by\n rw [hGyd]; exact grad_sq_le L hL f G hs xs hxs yb\n have hNGV : α*‖Gy‖^2 ≤ 2*L*((f xb - f xs) + (α^2*L/2)*‖z - xs‖^2) := by\n have h7 := mul_le_mul_of_nonneg_left hNG hα.le\n have h8 := mul_le_mul_of_nonneg_left hAyV (by positivity : (0:ℝ) ≤ 2*L)\n linarith\n have hIeg : (inner (𝕜 := ℝ) e g) = (inner (𝕜 := ℝ) e Gy) + ‖e‖^2 := by\n nth_rewrite 1 [hgGe]\n rw [inner_add_right, real_inner_self_eq_norm_sq]\n have hCS1 : (inner (𝕜 := ℝ) e Gy) ≤ ‖e‖*‖Gy‖ := real_inner_le_norm _ _\n have hCS2 : -(inner (𝕜 := ℝ) u e) ≤ ‖u‖*‖e‖ :=\n le_trans (neg_le_abs _) (abs_real_inner_le_norm u e)\n have hne2 : (0:ℝ) ≤ ‖e‖^2 := sq_nonneg _\n set V : ℝ := (f xb - f xs) + (α^2*L/2)*‖z - xs‖^2 with hVdef\n have hVnn : 0 ≤ V := by rw [hVdef]; have : (0:ℝ) ≤ (α^2*L/2)*‖z - xs‖^2 := by positivity\n linarith\n have hB1 : (1/L)*(inner (𝕜 := ℝ) e g) ≤ (α/8)*V + (1/L + 4/(α^2*L))*‖e‖^2 := by\n have hy1 : ‖e‖*‖Gy‖ ≤ (4/α^2)*‖e‖^2 + (α^2/16)*‖Gy‖^2 := by\n have heq : (4/α^2)*‖e‖^2 + (α^2/16)*‖Gy‖^2 - ‖e‖*‖Gy‖\n = (4/α^2)*(‖e‖ - (α^2/8)*‖Gy‖)^2 := by field_simp; try ring\n have hnn : (0:ℝ) ≤ (4/α^2)*(‖e‖ - (α^2/8)*‖Gy‖)^2 := by positivity\n linarith [heq.le, heq.ge, hnn]\n have h1 : (1/L)*(inner (𝕜 := ℝ) e Gy) ≤ (1/L)*(‖e‖*‖Gy‖) :=\n mul_le_mul_of_nonneg_left hCS1 (by positivity)\n have h2 : (1/L)*(‖e‖*‖Gy‖) ≤ (1/L)*((4/α^2)*‖e‖^2 + (α^2/16)*‖Gy‖^2) :=\n mul_le_mul_of_nonneg_left hy1 (by positivity)\n have h3 : (α/(16*L))*(α*‖Gy‖^2) ≤ (α/(16*L))*(2*L*V) :=\n mul_le_mul_of_nonneg_left hNGV (by positivity)\n have h4 : (α/(16*L))*(2*L*V) = (α/8)*V := by field_simp; try ring\n have h5 : (1/L)*((4/α^2)*‖e‖^2 + (α^2/16)*‖Gy‖^2)\n = (4/(α^2*L))*‖e‖^2 + (α/(16*L))*(α*‖Gy‖^2) := by field_simp; try ring\n rw [hIeg]\n linarith [h1, h2, h3, h4.le, h4.ge, h5.le, h5.ge]\n have hB2 : -(α*(inner (𝕜 := ℝ) u e)) ≤ (α/8)*V + (4/(α*L))*‖e‖^2 := by\n have hy2 : ‖u‖*‖e‖ ≤ (4/(α^2*L))*‖e‖^2 + ((α^2*L)/16)*‖u‖^2 := by\n have heq : (4/(α^2*L))*‖e‖^2 + ((α^2*L)/16)*‖u‖^2 - ‖u‖*‖e‖\n = (4/(α^2*L))*(‖e‖ - ((α^2*L)/8)*‖u‖)^2 := by field_simp; try ring\n have hnn : (0:ℝ) ≤ (4/(α^2*L))*(‖e‖ - ((α^2*L)/8)*‖u‖)^2 := by positivity\n linarith [heq.le, heq.ge, hnn]\n have h7 := mul_le_mul_of_nonneg_left hCS2 hα.le\n have h8 := mul_le_mul_of_nonneg_left hy2 hα.le\n have h9 := mul_le_mul_of_nonneg_left hUV (by positivity : (0:ℝ) ≤ α/8)\n have h10 : α*((4/(α^2*L))*‖e‖^2 + ((α^2*L)/16)*‖u‖^2)\n = (4/(α*L))*‖e‖^2 + (α/8)*((α^2*L/2)*‖u‖^2) := by field_simp; try ring\n linarith [h7, h8, h9, h10.le, h10.ge]\n have hCle : (1/L + 4/(α^2*L) + 4/(α*L)) ≤ (1+8/α^3)/L := by\n have hd : (1+8/α^3)/L - (1/L + 4/(α^2*L) + 4/(α*L))\n = (8 - 4*α - 4*α^2)/(α^3*L) := by field_simp; try ring\n have hnn : (0:ℝ) ≤ (8 - 4*α - 4*α^2)/(α^3*L) := by\n apply div_nonneg (by nlinarith) (by positivity)\n linarith [hd.le, hd.ge, hnn]\n have hDnn : (0:ℝ) ≤ (1+8/α^3)/L := by positivity\n have hC : (1/L + 4/(α^2*L) + 4/(α*L))*‖e‖^2 ≤ (1 + 8/α^3)*Er/L := by\n have s1 : (1/L + 4/(α^2*L) + 4/(α*L))*‖e‖^2 ≤ ((1+8/α^3)/L)*‖e‖^2 :=\n mul_le_mul_of_nonneg_right hCle hne2\n have s2 : ((1+8/α^3)/L)*‖e‖^2 ≤ ((1+8/α^3)/L)*Er :=\n mul_le_mul_of_nonneg_left hEr hDnn\n have s3 : ((1+8/α^3)/L)*Er = (1 + 8/α^3)*Er/L := by ring\n linarith [s1, s2, s3.le, s3.ge]\n linarith [hmaster, hB1, hB2, hC]\n\n\nprivate lemma young2 (c x y : ℝ) (hc : 0 < c) : x*y ≤ c*x^2 + (1/(4*c))*y^2 := by\n have hnn := mul_nonneg hc.le (sq_nonneg (x - y/(2*c)))\n have e : c*(x - y/(2*c))^2 = c*x^2 - x*y + (1/(4*c))*y^2 := by field_simp; ring\n linarith [hnn, e.le, e.ge]\n\nset_option maxHeartbeats 2000000 in\nprivate lemma prox_agd_core\n (μ L η α : ℝ) (hL : 0 < L) (hηeq : η = 1/(2*L)) (hα : 0 < α)\n (hμeq : μ = α^2/η) (hα1 : α + α^2/4 ≤ 1)\n (h : E → ℝ) (xs : E)\n (hstr : ∀ x, (μ/2)*‖x - xs‖^2 ≤ h x - h xs)\n (xb v yb v1 qb Gb D : E)\n (hyb : yb = (1/(1+α)) • xb + (α/(1+α)) • v)\n (hv1 : v1 = (1-α) • v + α • yb - (α/μ) • Gb)\n (Errv : ℝ)\n (key : ∀ z : E, h qb ≤ h z - (inner (𝕜 := ℝ) (D + Gb) (z - yb))\n - η*(inner (𝕜 := ℝ) D Gb)\n - η*(1 - η*L/2)*‖Gb‖^2 - (μ/2)*‖z - yb‖^2 + Errv) :\n (h qb - h xs) + (μ/2)*‖v1 - xs‖^2\n ≤ (1-α)*((h xb - h xs) + (μ/2)*‖v - xs‖^2)\n + (2*η + 1/(2*μ) + 2*(α+α^2/4)^2/(μ*α^2))*‖D‖^2 + Errv := by\n have hηpos : 0 < η := by rw [hηeq]; positivity\n have hηne : η ≠ 0 := ne_of_gt hηpos\n have hαne : α ≠ 0 := ne_of_gt hα\n have hμpos : 0 < μ := by rw [hμeq]; positivity\n have hμne : μ ≠ 0 := ne_of_gt hμpos\n have h1a : (0:ℝ) < 1 + α := by linarith\n have hηL : η*L = 1/2 := by rw [hηeq]; field_simp\n have hα2 : α^2 = μ*η := by rw [hμeq]; field_simp\n obtain ⟨β, hβ⟩ : ∃ b:ℝ, b = α^2/4 := ⟨_, rfl⟩\n have hβpos : 0 < β := by rw [hβ]; positivity\n have hβne : β ≠ 0 := ne_of_gt hβpos\n have hA'pos : (0:ℝ) < α + β := by linarith\n have hA'1 : α + β ≤ 1 := by rw [hβ]; linarith\n have hβη : β = η*μ/4 := by rw [hβ, hα2]; ring\n -- expand key\n have key' : ∀ z : E, h qb ≤ h z - (inner (𝕜 := ℝ) D (z - yb))\n - (inner (𝕜 := ℝ) Gb (z - yb)) - η*(inner (𝕜 := ℝ) D Gb)\n - (3*η/4)*‖Gb‖^2 - (μ/2)*‖z - yb‖^2 + Errv := by\n intro z\n have hk := key z\n rw [inner_add_left] at hk\n have hc : η*(1 - η*L/2) = 3*η/4 := by\n have hh : η*L/2 = 1/4 := by rw [show η*L/2 = (η*L)/2 from by ring, hηL]; norm_num\n rw [hh]; ring\n rw [hc] at hk\n linarith\n -- Lemma-22 part\n have hL22 : (μ/2)*‖v1 - xs‖^2 ≤ (1-α)*((μ/2)*‖v - xs‖^2) + α*((μ/2)*‖xs - yb‖^2)\n + ((1-α)*(inner (𝕜 := ℝ) Gb (xb - yb)) + α*(inner (𝕜 := ℝ) Gb (xs - yb)))\n + (η/2)*‖Gb‖^2 := by\n obtain ⟨U, hU⟩ : ∃ w : E, w = (1-α) • (v - xs) + α • (yb - xs) := ⟨_, rfl⟩\n have hv1u : v1 - xs = U - (α/μ) • Gb := by rw [hv1, hU]; module\n have hnorm : ‖v1 - xs‖^2 = ‖U‖^2 - 2*(α/μ)*(inner (𝕜 := ℝ) U Gb) + (α/μ)^2*‖Gb‖^2 := by\n rw [hv1u]; exact nsq_sub _ _ _\n have hconv : ‖U‖^2 ≤ (1-α)*‖v - xs‖^2 + α*‖yb - xs‖^2 := by\n rw [hU]; exact nsq_conv (1-α) α (by linarith) hα.le (by ring) _ _\n have hnegU : (-α) • U = (1-α) • (xb - yb) + α • (xs - yb) := by\n rw [hU, hyb]; match_scalars <;> (field_simp; try ring)\n have hUG : (-α)*(inner (𝕜 := ℝ) U Gb)\n = (1-α)*(inner (𝕜 := ℝ) Gb (xb - yb)) + α*(inner (𝕜 := ℝ) Gb (xs - yb)) := by\n have e1 : (inner (𝕜 := ℝ) ((-α) • U) Gb) = (-α)*(inner (𝕜 := ℝ) U Gb) :=\n real_inner_smul_left _ _ _\n rw [← e1, hnegU, inner_add_left, real_inner_smul_left, real_inner_smul_left,\n real_inner_comm (xb - yb) Gb, real_inner_comm (xs - yb) Gb]\n have hnr : ‖yb - xs‖ = ‖xs - yb‖ := norm_sub_rev _ _\n rw [hnr] at hconv\n have hcoef : (μ/2)*(α/μ)^2 = η/2 := by field_simp; linarith [hα2]\n have hexp : (μ/2)*‖v1 - xs‖^2\n = (μ/2)*‖U‖^2 + (-α)*(inner (𝕜 := ℝ) U Gb) + ((μ/2)*(α/μ)^2)*‖Gb‖^2 := by\n rw [hnorm]; field_simp; ring\n rw [hexp, hcoef, hUG]\n have hm := mul_le_mul_of_nonneg_left hconv (by positivity : (0:ℝ) ≤ μ/2)\n linarith\n have m1 := mul_le_mul_of_nonneg_left (key' xb) (by linarith : (0:ℝ) ≤ 1 - (α+β))\n have m2 := mul_le_mul_of_nonneg_left (key' xs) hA'pos.le\n have hGxs : (inner (𝕜 := ℝ) Gb (xb - yb)) - (inner (𝕜 := ℝ) Gb (xs - yb))\n = (inner (𝕜 := ℝ) Gb (xb - xs)) := by\n rw [← inner_sub_right]; congr 1; abel\n have hA := hstr xb\n have hAnn : 0 ≤ h xb - h xs := le_trans (by positivity) hA\n -- (a)\n have habs1 : β*(inner (𝕜 := ℝ) Gb (xb - yb)) - β*(inner (𝕜 := ℝ) Gb (xs - yb))\n ≤ (η/8)*‖Gb‖^2 + β*(h xb - h xs) := by\n have hsplit : β*(inner (𝕜 := ℝ) Gb (xb - yb)) - β*(inner (𝕜 := ℝ) Gb (xs - yb))\n = β*(inner (𝕜 := ℝ) Gb (xb - xs)) := by rw [← hGxs]; ring\n rw [hsplit]\n have hCS1 : (inner (𝕜 := ℝ) Gb (xb - xs)) ≤ ‖Gb‖*‖xb - xs‖ := real_inner_le_norm _ _\n have hy : ‖Gb‖*‖xb - xs‖ ≤ (η/(8*β))*‖Gb‖^2 + (2*β/η)*‖xb - xs‖^2 := by\n have hyy := young2 (η/(8*β)) ‖Gb‖ ‖xb - xs‖ (by positivity)\n have e : (1/(4*(η/(8*β)))) = 2*β/η := by field_simp; try ring\n rw [e] at hyy; exact hyy\n have h1 := mul_le_mul_of_nonneg_left (le_trans hCS1 hy) hβpos.le\n have e2 : β*((η/(8*β))*‖Gb‖^2 + (2*β/η)*‖xb - xs‖^2)\n = (η/8)*‖Gb‖^2 + β*((μ/2)*‖xb - xs‖^2) := by\n rw [hβη]; field_simp; try ring\n have h5 := mul_le_mul_of_nonneg_left hA hβpos.le\n linarith [h1, e2.le, e2.ge, h5]\n -- (b)\n have habs2 : -(η*(inner (𝕜 := ℝ) D Gb)) ≤ (η/8)*‖Gb‖^2 + 2*η*‖D‖^2 := by\n have hCS : -(inner (𝕜 := ℝ) D Gb) ≤ ‖Gb‖*‖D‖ := by\n have hb := abs_real_inner_le_norm D Gb\n have h2 : -(inner (𝕜 := ℝ) D Gb) ≤ |inner (𝕜 := ℝ) D Gb| := neg_le_abs _\n calc -(inner (𝕜 := ℝ) D Gb) ≤ ‖D‖*‖Gb‖ := le_trans h2 hb\n _ = ‖Gb‖*‖D‖ := by ring\n have hy : ‖Gb‖*‖D‖ ≤ (1/8)*‖Gb‖^2 + 2*‖D‖^2 := by\n have hyy := young2 (1/8) ‖Gb‖ ‖D‖ (by norm_num)\n norm_num at hyy; linarith\n have h1 := mul_le_mul_of_nonneg_left (le_trans hCS hy) hηpos.le\n linarith [h1]\n -- (c1)\n have habs3 : -((1-(α+β))*(inner (𝕜 := ℝ) D (xb - yb)))\n ≤ (1-(α+β))*((μ/2)*‖xb - yb‖^2) + (1/(2*μ))*‖D‖^2 := by\n have hCS : -(inner (𝕜 := ℝ) D (xb - yb)) ≤ ‖xb - yb‖*‖D‖ := by\n have hb := abs_real_inner_le_norm D (xb - yb)\n have h2 : -(inner (𝕜 := ℝ) D (xb - yb)) ≤ |inner (𝕜 := ℝ) D (xb - yb)| := neg_le_abs _\n calc -(inner (𝕜 := ℝ) D (xb - yb)) ≤ ‖D‖*‖xb - yb‖ := le_trans h2 hb\n _ = ‖xb - yb‖*‖D‖ := by ring\n have hy : ‖xb - yb‖*‖D‖ ≤ (μ/2)*‖xb - yb‖^2 + (1/(2*μ))*‖D‖^2 := by\n have hyy := young2 (μ/2) ‖xb - yb‖ ‖D‖ (by positivity)\n have e : (1/(4*(μ/2))) = 1/(2*μ) := by field_simp; try ring\n rw [e] at hyy; exact hyy\n have h1 := mul_le_mul_of_nonneg_left (le_trans hCS hy) (by linarith : (0:ℝ) ≤ 1 - (α+β))\n have h2 : (1-(α+β))*((1/(2*μ))*‖D‖^2) ≤ (1/(2*μ))*‖D‖^2 := by\n nlinarith [mul_nonneg hA'pos.le (show (0:ℝ) ≤ (1/(2*μ))*‖D‖^2 by positivity)]\n nlinarith [h1, h2]\n -- (c2)\n have habs4 : -((α+β)*(inner (𝕜 := ℝ) D (xs - yb)))\n ≤ (μ*β/2)*‖xs - yb‖^2 + (2*(α+α^2/4)^2/(μ*α^2))*‖D‖^2 := by\n have hCS : -(inner (𝕜 := ℝ) D (xs - yb)) ≤ ‖xs - yb‖*‖D‖ := by\n have hb := abs_real_inner_le_norm D (xs - yb)\n have h2 : -(inner (𝕜 := ℝ) D (xs - yb)) ≤ |inner (𝕜 := ℝ) D (xs - yb)| := neg_le_abs _\n calc -(inner (𝕜 := ℝ) D (xs - yb)) ≤ ‖D‖*‖xs - yb‖ := le_trans h2 hb\n _ = ‖xs - yb‖*‖D‖ := by ring\n have hy : ‖xs - yb‖*‖D‖ ≤ (μ*β/(2*(α+β)))*‖xs - yb‖^2 + ((α+β)/(2*μ*β))*‖D‖^2 := by\n have hyy := young2 (μ*β/(2*(α+β))) ‖xs - yb‖ ‖D‖ (by positivity)\n have e : (1/(4*(μ*β/(2*(α+β))))) = (α+β)/(2*μ*β) := by field_simp; try ring\n rw [e] at hyy; exact hyy\n have h1 := mul_le_mul_of_nonneg_left (le_trans hCS hy) hA'pos.le\n have e2 : (α+β)*((μ*β/(2*(α+β)))*‖xs - yb‖^2 + ((α+β)/(2*μ*β))*‖D‖^2)\n = (μ*β/2)*‖xs - yb‖^2 + (2*(α+α^2/4)^2/(μ*α^2))*‖D‖^2 := by\n rw [hβ]; field_simp; try ring\n linarith [h1, e2.le, e2.ge]\n linarith [m1, m2, hL22, habs1, habs2, habs3, habs4]\n\nend AGDHelpers\n\nprivate lemma strong_smooth_mu_le_fin_succ {n : ℕ} (μ L : ℝ)\n (hμ : 0 < μ) (hL : 0 < L)\n (f : EuclideanSpace ℝ (Fin (n + 1)) → ℝ)\n (g : EuclideanSpace ℝ (Fin (n + 1)) → EuclideanSpace ℝ (Fin (n + 1)))\n (hs : IsSmooth L f g) (hc : StrongConvexOn Set.univ μ f) : μ ≤ L := by\n let e : EuclideanSpace ℝ (Fin (n + 1)) :=\n EuclideanSpace.single (0 : Fin (n + 1)) (1 : ℝ)\n have hlo := strong_subgrad L μ hL hμ.le f g hs hc (0 : EuclideanSpace ℝ (Fin (n + 1))) e\n have hup := hs (0 : EuclideanSpace ℝ (Fin (n + 1))) e\n have he : ‖e - (0 : EuclideanSpace ℝ (Fin (n + 1)))‖ ^ 2 = 1 := by\n simp [e, EuclideanSpace.norm_single]\n rw [he] at hlo hup\n nlinarith\n\nprivate lemma alpha_quarter_small (μ L η α : ℝ)\n (hL : 0 < L) (hμL : μ ≤ L) (hηeq : η = 1/(2*L))\n (hαsq : α^2 = μ*η) (hα : 0 ≤ α) :\n α + α^2/4 ≤ 1 := by\n have hs : α^2 ≤ (1/2:ℝ) := by\n calc\n α^2 = μ/(2*L) := by rw [hαsq, hηeq]; ring\n _ ≤ L/(2*L) := (div_le_div_iff_of_pos_right (by positivity)).2 hμL\n _ = 1/2 := by field_simp\n nlinarith\n\nprivate lemma sum_centered {m d : ℕ} (hm : 0 < m)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n ∑ i, (x i - rowAvg x) = 0 := by\n have hmR : (m : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hm)\n simp only [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ,\n Fintype.card_fin, rowAvg]\n rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul]\n match_scalars\n field_simp\n ring\n\nprivate lemma rowAvg_sub {m d : ℕ}\n (x y : Fin m → EuclideanSpace ℝ (Fin d)) :\n rowAvg (fun i => x i - y i) = rowAvg x - rowAvg y := by\n simp [rowAvg, Finset.sum_sub_distrib, smul_sub]\n\nprivate lemma rowAvg_add {m d : ℕ}\n (x y : Fin m → EuclideanSpace ℝ (Fin d)) :\n rowAvg (fun i => x i + y i) = rowAvg x + rowAvg y := by\n simp [rowAvg, Finset.sum_add_distrib, smul_add]\n\nprivate lemma rowAvg_smul {m d : ℕ} (c : ℝ)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n rowAvg (fun i => c • x i) = c • rowAvg x := by\n simp [rowAvg, ← Finset.smul_sum, smul_smul, mul_comm]\n\nprivate lemma avg_inner_left {m d : ℕ}\n (x : Fin m → EuclideanSpace ℝ (Fin d)) (z : EuclideanSpace ℝ (Fin d)) :\n (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) (x i) z = inner (𝕜 := ℝ) (rowAvg x) z := by\n rw [rowAvg, real_inner_smul_left, sum_inner]\n\nprivate lemma avg_inner_right {m d : ℕ}\n (x : Fin m → EuclideanSpace ℝ (Fin d)) (z : EuclideanSpace ℝ (Fin d)) :\n (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) z (x i) = inner (𝕜 := ℝ) z (rowAvg x) := by\n rw [rowAvg, real_inner_smul_right, inner_sum]\n\nprivate lemma rowAvg_centered {m d : ℕ} (hm : 0 < m)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n rowAvg (fun i => x i - rowAvg x) = 0 := by\n rw [rowAvg, sum_centered hm, smul_zero]\n\nprivate lemma variance_identity {m d : ℕ} (hm : 0 < m)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n (1/(m:ℝ)) * ∑ i, ‖x i‖^2 =\n ‖rowAvg x‖^2 + (1/(m:ℝ)) * ∑ i, ‖x i - rowAvg x‖^2 := by\n have hmR : (m:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hm)\n have hinner : (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) (x i) (rowAvg x)\n = ‖rowAvg x‖^2 := by\n rw [avg_inner_left, real_inner_self_eq_norm_sq]\n have hinner2 : (1/(m:ℝ)) * ∑ i, 2 * inner (𝕜 := ℝ) (x i) (rowAvg x)\n = 2 * ‖rowAvg x‖^2 := by\n rw [← Finset.mul_sum]\n nlinarith\n simp_rw [norm_sub_sq_real]\n simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib, Finset.sum_const,\n Finset.card_univ, Fintype.card_fin]\n rw [nsmul_eq_mul]\n have hs : (1/(m:ℝ)) * ((m:ℝ) * ‖rowAvg x‖^2) = ‖rowAvg x‖^2 := by field_simp\n linear_combination hinner2 - hs\n\nprivate theorem prox_first_order\n {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n {c : ℝ} (hc : 0 < c) {R : E → ℝ} (hR : ConvexOn ℝ Set.univ R)\n {a xp : E} (hp : IsProxStep c R a xp) (z : E) :\n R xp ≤ R z + inner (𝕜 := ℝ) ((1 / c) • (xp - a)) (z - xp) := by\n apply le_of_forall_pos_le_add\n intro eps heps\n let C : ℝ := (1 / (2 * c)) * ‖z - xp‖ ^ 2\n have hC : 0 ≤ C := by\n dsimp [C]\n positivity\n let t : ℝ := eps / (eps + C + 1)\n have hden : 0 < eps + C + 1 := by positivity\n have ht : 0 < t := by\n dsimp [t]\n positivity\n have ht1 : t < 1 := by\n dsimp [t]\n exact (div_lt_one hden).2 (by linarith [hC])\n let u : E := (1 - t) • xp + t • z\n have hconv : R u ≤ (1 - t) * R xp + t * R z := by\n dsimp [u]\n exact hR.2 (Set.mem_univ xp) (Set.mem_univ z)\n (by linarith) ht.le (by ring)\n have hobj := hp u\n have hobj' :\n R xp + (1 / (2 * c)) * ‖xp - a‖ ^ 2 ≤\n ((1 - t) * R xp + t * R z) +\n (1 / (2 * c)) * ‖u - a‖ ^ 2 :=\n hobj.trans (add_le_add hconv le_rfl)\n have hu : u - a = (xp - a) + t • (z - xp) := by\n dsimp [u]\n module\n rw [hu, norm_add_sq_real, real_inner_smul_right, norm_smul] at hobj'\n rw [Real.norm_eq_abs, abs_of_pos ht] at hobj'\n have hmain :\n R xp ≤ R z + inner (𝕜 := ℝ) ((1 / c) • (xp - a)) (z - xp) + C * t := by\n rw [real_inner_smul_left]\n dsimp [C]\n have hcne : c ≠ 0 := ne_of_gt hc\n field_simp [hcne] at hobj' ⊢\n nlinarith [sq_nonneg t]\n have hratio : C / (eps + C + 1) ≤ 1 := by\n exact (div_le_one hden).2 (by linarith)\n have hCt : C * t ≤ eps := by\n calc\n C * t = eps * (C / (eps + C + 1)) := by\n dsimp [t]\n ring\n _ ≤ eps * 1 := mul_le_mul_of_nonneg_left hratio heps.le\n _ = eps := by ring\n linarith\n\nprivate lemma convex_rowAvg {m d : ℕ} (hm : 0 < m)\n (R : EuclideanSpace ℝ (Fin d) → ℝ) (hR : ConvexOn ℝ Set.univ R)\n (x : Fin m → EuclideanSpace ℝ (Fin d)) :\n R (rowAvg x) ≤ (1/(m:ℝ)) * ∑ i, R (x i) := by\n have hmR : (m:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hm)\n have hweights : ∑ i : Fin m, (1/(m:ℝ)) = 1 := by\n simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n have h := hR.map_sum_le\n (t := (Finset.univ : Finset (Fin m))) (w := fun _ => (1/(m:ℝ))) (p := x)\n (fun _ _ => by positivity) hweights (fun _ _ => Set.mem_univ _)\n simpa only [rowAvg, ← Finset.smul_sum, smul_eq_mul, ← Finset.mul_sum] using h\n\nprivate lemma rowAvg_const {m d : ℕ} (hm : 0 < m)\n (z : EuclideanSpace ℝ (Fin d)) :\n rowAvg (fun _ : Fin m => z) = z := by\n have hmR : (m:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hm)\n simp only [rowAvg, Finset.sum_const, Finset.card_univ, Fintype.card_fin]\n rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul]\n match_scalars\n field_simp\n\nprivate lemma avg_inner_covariance {m d : ℕ} (hm : 0 < m)\n (a b : Fin m → EuclideanSpace ℝ (Fin d)) :\n (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) (a i) (b i) =\n inner (𝕜 := ℝ) (rowAvg a) (rowAvg b) +\n (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ)\n (a i - rowAvg a) (b i - rowAvg b) := by\n have hmR : (m:ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hm)\n have hpoint : ∀ i, inner (𝕜 := ℝ) (a i) (b i) =\n inner (𝕜 := ℝ) (rowAvg a) (rowAvg b) +\n inner (𝕜 := ℝ) (a i - rowAvg a) (b i - rowAvg b) +\n inner (𝕜 := ℝ) (a i - rowAvg a) (rowAvg b) +\n inner (𝕜 := ℝ) (rowAvg a) (b i - rowAvg b) := by\n intro i\n simp only [inner_sub_left, inner_sub_right]\n ring\n have hcross1 : ∑ i, inner (𝕜 := ℝ) (a i - rowAvg a) (rowAvg b) = 0 := by\n rw [← sum_inner, sum_centered hm, inner_zero_left]\n have hcross2 : ∑ i, inner (𝕜 := ℝ) (rowAvg a) (b i - rowAvg b) = 0 := by\n rw [← inner_sum, sum_centered hm, inner_zero_right]\n simp_rw [hpoint]\n simp only [Finset.sum_add_distrib]\n rw [hcross1, hcross2]\n simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, add_zero]\n rw [nsmul_eq_mul]\n field_simp\n\nprivate lemma avg_sum_add_mul {m : ℕ} (η : ℝ) (a b : Fin m → ℝ) :\n (1/(m:ℝ)) * ∑ i, a i + η * ((1/(m:ℝ)) * ∑ i, b i) =\n (1/(m:ℝ)) * ∑ i, (a i + η * b i) := by\n rw [Finset.sum_add_distrib, ← Finset.mul_sum]\n ring\n\nprivate lemma avg_prox_inner_decomp {m d : ℕ} (hm : 0 < m) (η : ℝ)\n (y s G : Fin m → EuclideanSpace ℝ (Fin d)) (z : EuclideanSpace ℝ (Fin d)) :\n (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) (s i - G i) (z - (y i - η • G i)) =\n inner (𝕜 := ℝ) (rowAvg s - rowAvg G) (z - rowAvg y)\n + η * inner (𝕜 := ℝ) (rowAvg s) (rowAvg G) - η * ‖rowAvg G‖^2\n + (1/(m:ℝ)) * ∑ i,\n (- inner (𝕜 := ℝ) (s i - rowAvg s) (y i - rowAvg y)\n + inner (𝕜 := ℝ) (G i - rowAvg G) (y i - rowAvg y)\n + η * inner (𝕜 := ℝ) (s i - rowAvg s) (G i - rowAvg G)\n - η * ‖G i - rowAvg G‖^2) := by\n have hsplit :\n (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) (s i - G i) (z - (y i - η • G i)) =\n (1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) (s i - G i) (z - y i)\n + η * ((1/(m:ℝ)) * ∑ i, inner (𝕜 := ℝ) (s i - G i) (G i)) := by\n have hp : ∀ i, z - (y i - η • G i) = (z - y i) + η • G i := by\n intro i\n module\n simp_rw [hp, inner_add_right, real_inner_smul_right, Finset.sum_add_distrib]\n rw [← Finset.mul_sum]\n ring\n have hcov1 := avg_inner_covariance hm (fun i => s i - G i) (fun i => z - y i)\n have hcov2 := avg_inner_covariance hm (fun i => s i - G i) G\n have havgSG : rowAvg (fun i => s i - G i) = rowAvg s - rowAvg G :=\n rowAvg_sub s G\n have havgZY : rowAvg (fun i => z - y i) = z - rowAvg y := by\n rw [rowAvg_sub, rowAvg_const hm]\n have hcSG : ∀ i, (s i - G i) - rowAvg (fun j => s j - G j) =\n (s i - rowAvg s) - (G i - rowAvg G) := by\n intro i\n rw [havgSG]\n abel\n have hcZY : ∀ i, (z - y i) - rowAvg (fun j => z - y j) =\n -(y i - rowAvg y) := by\n intro i\n rw [havgZY]\n abel\n have hterm1 : ∀ i,\n inner (𝕜 := ℝ)\n ((s i - G i) - rowAvg (fun j => s j - G j))\n ((z - y i) - rowAvg (fun j => z - y j)) =\n - inner (𝕜 := ℝ) (s i - rowAvg s) (y i - rowAvg y)\n + inner (𝕜 := ℝ) (G i - rowAvg G) (y i - rowAvg y) := by\n intro i\n rw [hcSG, hcZY, inner_neg_right, inner_sub_left]\n ring\n have hterm2 : ∀ i,\n inner (𝕜 := ℝ)\n ((s i - G i) - rowAvg (fun j => s j - G j))\n (G i - rowAvg G) =\n inner (𝕜 := ℝ) (s i - rowAvg s) (G i - rowAvg G)\n - ‖G i - rowAvg G‖^2 := by\n intro i\n rw [hcSG, inner_sub_left, real_inner_self_eq_norm_sq]\n have hcombine :\n (1/(m:ℝ)) * ∑ i,\n (- inner (𝕜 := ℝ) (s i - rowAvg s) (y i - rowAvg y)\n + inner (𝕜 := ℝ) (G i - rowAvg G) (y i - rowAvg y))\n + η * ((1/(m:ℝ)) * ∑ i,\n (inner (𝕜 := ℝ) (s i - rowAvg s) (G i - rowAvg G)\n - ‖G i - rowAvg G‖^2)) =\n (1/(m:ℝ)) * ∑ i,\n (- inner (𝕜 := ℝ) (s i - rowAvg s) (y i - rowAvg y)\n + inner (𝕜 := ℝ) (G i - rowAvg G) (y i - rowAvg y)\n + η * inner (𝕜 := ℝ) (s i - rowAvg s) (G i - rowAvg G)\n - η * ‖G i - rowAvg G‖^2) := by\n calc\n _ = (1/(m:ℝ)) * ∑ i,\n ((- inner (𝕜 := ℝ) (s i - rowAvg s) (y i - rowAvg y)\n + inner (𝕜 := ℝ) (G i - rowAvg G) (y i - rowAvg y))\n + η * (inner (𝕜 := ℝ) (s i - rowAvg s) (G i - rowAvg G)\n - ‖G i - rowAvg G‖^2)) :=\n avg_sum_add_mul η _ _\n _ = _ := by\n apply congrArg\n apply Finset.sum_congr rfl\n intro i hi\n ring\n have hcentral :\n inner (𝕜 := ℝ) (rowAvg s - rowAvg G) (rowAvg G) =\n inner (𝕜 := ℝ) (rowAvg s) (rowAvg G) - ‖rowAvg G‖^2 := by\n rw [inner_sub_left, real_inner_self_eq_norm_sq]\n rw [hsplit, hcov1, hcov2]\n simp_rw [hterm1, hterm2]\n rw [havgSG, havgZY]\n rw [hcentral]\n linear_combination hcombine\n\n#check avg_prox_inner_decomp\n\nprivate lemma young_real (c x y : ℝ) (hc : 0 < c) :\n x*y ≤ c*x^2 + (1/(4*c))*y^2 := by\n have hnn := mul_nonneg hc.le (sq_nonneg (x - y/(2*c)))\n have he : c*(x - y/(2*c))^2 =\n c*x^2 - x*y + (1/(4*c))*y^2 := by\n field_simp\n ring\n linarith [hnn, he.le, he.ge]\n\nprivate lemma prox_center_error_bound {d : ℕ} (η : ℝ) (hη : 0 < η)\n (s g y : EuclideanSpace ℝ (Fin d)) :\n - inner (𝕜 := ℝ) s y + inner (𝕜 := ℝ) g y\n + η * inner (𝕜 := ℝ) s g - η * ‖g‖^2\n ≤ 2*η*‖s‖^2 + 2*η⁻¹*‖y‖^2 := by\n have hsy0 : - inner (𝕜 := ℝ) s y ≤ ‖s‖ * ‖y‖ :=\n le_trans (neg_le_abs _) (abs_real_inner_le_norm _ _)\n have hsy1 := young_real (η/2) ‖s‖ ‖y‖ (by positivity)\n have hsy : - inner (𝕜 := ℝ) s y ≤\n (η/2)*‖s‖^2 + (1/(2*η))*‖y‖^2 := by\n have hc : 1 / (4 * (η / 2)) = 1/(2*η) := by\n field_simp\n ring\n rw [hc] at hsy1\n exact hsy0.trans hsy1\n have hgy0 : inner (𝕜 := ℝ) g y ≤ ‖g‖ * ‖y‖ :=\n real_inner_le_norm _ _\n have hgy1 := young_real (η/4) ‖g‖ ‖y‖ (by positivity)\n have hgy : inner (𝕜 := ℝ) g y ≤\n (η/4)*‖g‖^2 + (1/η)*‖y‖^2 := by\n have hc : 1 / (4 * (η / 4)) = 1/η := by field_simp\n rw [hc] at hgy1\n exact hgy0.trans hgy1\n have hsg0 : inner (𝕜 := ℝ) s g ≤ ‖s‖ * ‖g‖ :=\n real_inner_le_norm _ _\n have hsg1 := young_real (1/4) ‖g‖ ‖s‖ (by norm_num)\n have hsg : η * inner (𝕜 := ℝ) s g ≤\n (η/4)*‖g‖^2 + η*‖s‖^2 := by\n have h0 := mul_le_mul_of_nonneg_left hsg0 hη.le\n have h1 := mul_le_mul_of_nonneg_left hsg1 hη.le\n norm_num at h1\n nlinarith\n have hs0 : 0 ≤ η*‖s‖^2 := by positivity\n have hy0 : 0 ≤ η⁻¹*‖y‖^2 := by positivity\n have hg0 : 0 ≤ η*‖g‖^2 := by positivity\n ring_nf at hsy hgy hsg ⊢\n nlinarith [hsy, hgy, hsg, hs0, hy0, hg0]\n\n#check prox_center_error_bound\nprivate theorem prox_average_key {m d : ℕ} (hm : 0 < m)\n (L μ η : ℝ) (hL : 0 < L) (hμ : 0 ≤ μ) (hη : 0 < η)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (R : EuclideanSpace ℝ (Fin d) → ℝ)\n (hfsmooth : IsSmooth L f gradf)\n (hfstrong : ∀ x y, f x + inner (𝕜 := ℝ) (gradf x) (y - x)\n + (μ/2)*‖y-x‖^2 ≤ f y)\n (hRconv : ConvexOn ℝ Set.univ R)\n (y x s G : Fin m → EuclideanSpace ℝ (Fin d))\n (hG : ∀ i, x i = y i - η • G i)\n (hprox : ∀ i, IsProxStep η R (y i - η • s i) (x i))\n (z : EuclideanSpace ℝ (Fin d)) :\n f (rowAvg x) + R (rowAvg x) ≤\n f z + R z\n - inner (𝕜 := ℝ)\n ((gradf (rowAvg y) - rowAvg s) + rowAvg G) (z - rowAvg y)\n - η * inner (𝕜 := ℝ) (gradf (rowAvg y) - rowAvg s) (rowAvg G)\n - η * (1 - η*L/2) * ‖rowAvg G‖^2\n - (μ/2)*‖z-rowAvg y‖^2\n + (2*η/(m:ℝ))*∑ i, ‖s i-rowAvg s‖^2\n + (2*η⁻¹/(m:ℝ))*∑ i, ‖y i-rowAvg y‖^2 := by\n have hmR : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n have hηne : η ≠ 0 := ne_of_gt hη\n have hGi : ∀ i, (1/η) • (x i - (y i - η • s i)) = s i - G i := by\n intro i\n calc\n (1/η) • (x i - (y i - η • s i)) =\n (1/η) • (η • (s i - G i)) := by\n rw [hG i]\n congr 1\n module\n _ = s i - G i := by\n rw [smul_smul]\n have he : (1/η)*η = 1 := by field_simp\n rw [he, one_smul]\n have hRi : ∀ i, R (x i) ≤\n R z + inner (𝕜 := ℝ) (s i - G i) (z - (y i - η • G i)) := by\n intro i\n have hp := prox_first_order hη hRconv (hprox i) z\n rw [hGi i] at hp\n calc\n R (x i) ≤ R z + inner (𝕜 := ℝ) (s i - G i) (z - x i) := hp\n _ = R z + inner (𝕜 := ℝ) (s i - G i) (z - (y i - η • G i)) := by\n rw [hG i]\n have hRavg := convex_rowAvg hm R hRconv x\n have hRsum := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => hRi i)\n have hRsum' := mul_le_mul_of_nonneg_left hRsum (by positivity : (0:ℝ) ≤ 1/(m:ℝ))\n have hRstep : R (rowAvg x) ≤\n R z + (1/(m:ℝ))*∑ i,\n inner (𝕜 := ℝ) (s i - G i) (z - (y i - η • G i)) := by\n calc\n R (rowAvg x) ≤ (1/(m:ℝ))*∑ i, R (x i) := hRavg\n _ ≤ (1/(m:ℝ))*∑ i,\n (R z + inner (𝕜 := ℝ) (s i-G i) (z-(y i-η • G i))) := hRsum'\n _ = R z + (1/(m:ℝ))*∑ i,\n inner (𝕜 := ℝ) (s i-G i) (z-(y i-η • G i)) := by\n simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ,\n Fintype.card_fin, nsmul_eq_mul]\n field_simp\n rw [avg_prox_inner_decomp hm η y s G z] at hRstep\n have hxavg : rowAvg x = rowAvg y - η • rowAvg G := by\n rw [show x = fun i => y i - η • G i from funext hG, rowAvg_sub, rowAvg_smul]\n have hfstep0 := hfsmooth (rowAvg y) (rowAvg x)\n have hdiff : rowAvg x - rowAvg y = (-η) • rowAvg G := by\n rw [hxavg]\n module\n rw [hdiff, real_inner_smul_right, norm_smul, Real.norm_eq_abs, abs_neg,\n abs_of_pos hη] at hfstep0\n have hfstep : f (rowAvg x) ≤\n f (rowAvg y) - η * inner (𝕜 := ℝ) (gradf (rowAvg y)) (rowAvg G)\n + (L/2)*(η^2*‖rowAvg G‖^2) := by\n nlinarith [hfstep0]\n have hfstr := hfstrong (rowAvg y) z\n have herri : ∀ i,\n (- inner (𝕜 := ℝ) (s i-rowAvg s) (y i-rowAvg y)\n + inner (𝕜 := ℝ) (G i-rowAvg G) (y i-rowAvg y)\n + η * inner (𝕜 := ℝ) (s i-rowAvg s) (G i-rowAvg G)\n - η * ‖G i-rowAvg G‖^2)\n ≤ 2*η*‖s i-rowAvg s‖^2 + 2*η⁻¹*‖y i-rowAvg y‖^2 :=\n fun i => prox_center_error_bound η hη _ _ _\n have herrsum0 := Finset.sum_le_sum\n (fun i (_ : i ∈ Finset.univ) => herri i)\n have herrsum := mul_le_mul_of_nonneg_left herrsum0\n (by positivity : (0:ℝ) ≤ 1/(m:ℝ))\n have herr :\n (1/(m:ℝ))*∑ i,\n (- inner (𝕜 := ℝ) (s i-rowAvg s) (y i-rowAvg y)\n + inner (𝕜 := ℝ) (G i-rowAvg G) (y i-rowAvg y)\n + η * inner (𝕜 := ℝ) (s i-rowAvg s) (G i-rowAvg G)\n - η * ‖G i-rowAvg G‖^2)\n ≤ (2*η/(m:ℝ))*∑ i, ‖s i-rowAvg s‖^2\n + (2*η⁻¹/(m:ℝ))*∑ i, ‖y i-rowAvg y‖^2 := by\n calc\n _ ≤ (1/(m:ℝ))*∑ i,\n (2*η*‖s i-rowAvg s‖^2 + 2*η⁻¹*‖y i-rowAvg y‖^2) := herrsum\n _ = _ := by\n rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum]\n ring\n have hsum := add_le_add hfstep hRstep\n have hmain := add_le_add hsum herr\n simp only [inner_add_left, inner_sub_left] at hmain ⊢\n nlinarith [hfstr]\n\n\nprivate theorem composite_growth\n {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]\n (μ : ℝ) (hμ : 0 ≤ μ) (f R : E → ℝ)\n (hf : StrongConvexOn Set.univ μ f) (hR : ConvexOn ℝ Set.univ R)\n (xs : E) (hmin : ∀ x, f xs + R xs ≤ f x + R x) (x : E) :\n (μ/2)*‖x-xs‖^2 ≤ (f x + R x) - (f xs + R xs) := by\n apply le_of_forall_pos_le_add\n intro eps heps\n let A : ℝ := (μ/2)*‖x-xs‖^2\n have hA : 0 ≤ A := by dsimp [A]; positivity\n let t : ℝ := eps/(eps+A+1)\n have hden : 0 < eps+A+1 := by positivity\n have ht : 0 < t := by dsimp [t]; positivity\n have ht1 : t < 1 := by\n dsimp [t]\n exact (div_lt_one hden).2 (by linarith [hA])\n have hw0 : 0 ≤ 1-t := by linarith\n have hcombF := hf.2 (Set.mem_univ xs) (Set.mem_univ x)\n hw0 ht.le (by ring)\n have hcombR := hR.2 (Set.mem_univ xs) (Set.mem_univ x)\n hw0 ht.le (by ring)\n simp only [smul_eq_mul] at hcombF hcombR\n have hnorm : ‖xs-x‖ = ‖x-xs‖ := norm_sub_rev _ _\n rw [hnorm] at hcombF\n have hminimum := hmin ((1-t) • xs + t • x)\n have hmain : (1-t)*A ≤ (f x + R x) - (f xs + R xs) := by\n dsimp only [A]\n nlinarith [hcombF, hcombR, hminimum]\n have hratio : A/(eps+A+1) ≤ 1 := by\n exact (div_le_one hden).2 (by linarith)\n have htA : t*A ≤ eps := by\n calc\n t*A = eps*(A/(eps+A+1)) := by dsimp [t]; ring\n _ ≤ eps*1 := mul_le_mul_of_nonneg_left hratio heps.le\n _ = eps := by ring\n dsimp only [A] at hmain htA\n nlinarith\n\n\nprivate lemma prox_core_error_coeff (μ L η α : ℝ)\n (hL : 0 < L) (hη : 0 < η) (hα : 0 < α)\n (hηeq : η = 1/(2*L)) (hμeq : μ = α^2/η) (hα1 : α ≤ 1) :\n 2*η + 1/(2*μ) + 2*(α+α^2/4)^2/(μ*α^2)\n ≤ (1+8/α^3)/L := by\n have hμ : 0 < μ := by rw [hμeq]; positivity\n have hα2 : α^2 ≤ 1 := by nlinarith\n have hα3 : α^3 ≤ 1 := by\n have hh := mul_le_mul_of_nonneg_left hα2 hα.le\n nlinarith\n rw [hηeq, hμeq, hηeq]\n field_simp\n nlinarith [mul_nonneg hα.le (sub_nonneg.mpr hα1),\n mul_nonneg hα.le (sub_nonneg.mpr hα2),\n mul_nonneg hα.le (sub_nonneg.mpr hα3)]\n\n\n\nprivate theorem avg_lipschitz_error {m : ℕ} (hm : 0 < m)\n {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]\n (M : ℝ) (hM : 0 ≤ M) (g : Fin m → E → E) (y : Fin m → E) (yb : E)\n (hLip : ∀ i x z, ‖g i x - g i z‖ ≤ M * ‖x - z‖) :\n ‖(1 / (m : ��)) • ∑ i, g i (y i) - (1 / (m : ℝ)) • ∑ i, g i yb‖ ^ 2 ≤\n (M ^ 2 / (m : ℝ)) * ∑ i, ‖y i - yb‖ ^ 2 := by\n have hmR : 0 < (m : ℝ) := by exact_mod_cast hm\n let u : Fin m → E := fun i => g i (y i) - g i yb\n have hsumid : (∑ i, g i (y i)) - ∑ i, g i yb = ∑ i, u i := by\n dsimp only [u]\n rw [Finset.sum_sub_distrib]\n have hvec : (1 / (m : ℝ)) • ∑ i, g i (y i) -\n (1 / (m : ℝ)) • ∑ i, g i yb = (1 / (m : ℝ)) • ∑ i, u i := by\n rw [← smul_sub, hsumid]\n have hnormSum := norm_sum_le Finset.univ u\n have hterm : ∀ i, ‖u i‖ ≤ M * ‖y i - yb‖ := by\n intro i\n exact hLip i (y i) yb\n have hsumTerm : (∑ i, ‖u i‖) ≤ M * ∑ i, ‖y i - yb‖ := by\n calc\n (∑ i, ‖u i‖) ≤ ∑ i, M * ‖y i - yb‖ := Finset.sum_le_sum fun i _ => hterm i\n _ = M * ∑ i, ‖y i - yb‖ := by rw [Finset.mul_sum]\n have hsumNorm : ‖∑ i, u i‖ ≤ M * ∑ i, ‖y i - yb‖ := hnormSum.trans hsumTerm\n have hnorm : ‖(1 / (m : ℝ)) • ∑ i, u i‖ ≤\n (1 / (m : ℝ)) * M * ∑ i, ‖y i - yb‖ := by\n rw [norm_smul]\n simp only [Real.norm_eq_abs, abs_of_pos (one_div_pos.mpr hmR)]\n have hh := mul_le_mul_of_nonneg_left hsumNorm (one_div_nonneg.mpr hmR.le)\n simpa only [mul_assoc] using hh\n have hrhs0 : 0 ≤ (1 / (m : ℝ)) * M * ∑ i, ‖y i - yb‖ := by positivity\n have hnormsq : ‖(1 / (m : ℝ)) • ∑ i, u i‖ ^ 2 ≤\n ((1 / (m : ℝ)) * M * ∑ i, ‖y i - yb‖) ^ 2 :=\n (sq_le_sq₀ (norm_nonneg _) hrhs0).2 hnorm\n have hcs : (∑ i, ‖y i - yb‖) ^ 2 ≤\n (m : ℝ) * ∑ i, ‖y i - yb‖ ^ 2 := by\n simpa using (sq_sum_le_card_mul_sum_sq\n (s := Finset.univ) (f := fun i : Fin m => ‖y i - yb‖))\n rw [hvec]\n have hw := mul_le_mul_of_nonneg_left hcs\n (sq_nonneg ((1 / (m : ℝ)) * M))\n calc\n ‖(1 / (m : ℝ)) • ∑ i, u i‖ ^ 2 ≤\n ((1 / (m : ℝ)) * M * ∑ i, ‖y i - yb‖) ^ 2 := hnormsq\n _ ≤ ((1 / (m : ℝ)) * M) ^ 2 *\n ((m : ℝ) * ∑ i, ‖y i - yb‖ ^ 2) := by\n convert hw using 1 <;> ring\n _ = (M ^ 2 / (m : ℝ)) * ∑ i, ‖y i - yb‖ ^ 2 := by\n field_simp [ne_of_gt hmR]\n\nprivate lemma sq_avg_le {m : ℕ} (hm : 0 < m) (a : Fin m → ℝ) (ha : ∀ i, 0 ≤ a i) :\n ((1/(m:ℝ)) * ∑ i, a i)^2 ≤ (1/(m:ℝ)) * ∑ i, (a i)^2 := by\n have hmR : (0:ℝ) < m := by exact_mod_cast hm\n have h := sq_sum_le_card_mul_sum_sq (s := (Finset.univ : Finset (Fin m))) (f := a)\n simp only [Finset.card_univ, Fintype.card_fin] at h\n rw [mul_pow, div_pow, one_pow, div_mul_eq_mul_div, one_mul, div_le_iff₀ (by positivity)]\n calc (∑ i, a i)^2 ≤ (m:ℝ) * ∑ i, (a i)^2 := h\n _ = 1/(m:ℝ) * (∑ i, (a i)^2) * (m:ℝ)^2 := by field_simp\n\n\ntheorem lemma11 {d m : ℕ} (hm : 0 < m) (μ L M η α : ℝ)\n (hμ : 0 < μ) (hL : 0 < L) (hM : 0 < M)\n (hLM : L ≤ M) (hη : 0 < η) (hηeq : η = 1 / (2 * L))\n (hα : α = Real.sqrt (μ * η)) (hα1 : α ≤ 1)\n (R : EuclideanSpace ℝ (Fin d) → ℝ) (hRconv : ConvexOn ℝ Set.univ R)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hfsmooth : IsSmooth L f gradf) (hfconv : StrongConvexOn Set.univ μ f)\n (Fi : Fin m → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradFi : Fin m → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hFismooth : ∀ i, IsSmooth M (Fi i) (gradFi i))\n\n (hFiLip : ∀ i x y, ‖gradFi i x - gradFi i y‖ ≤ M * ‖x - y‖)\n (hfavg : f = fun x => (1 / (m : ℝ)) * ∑ i, Fi i x)\n (hgradf_avg : gradf = fun x => (1 / (m : ℝ)) • ∑ i, gradFi i x)\n (xstar : EuclideanSpace ℝ (Fin d)) (hxstar : ∀ x, f xstar + R xstar ≤ f x + R x)\n (xtprev xt xt1 yt yt1 st st1 : Fin m → EuclideanSpace ℝ (Fin d))\n (K : ℕ)\n (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ) (hW : ∀ j, ∑ i, W i j = 1)\n (adj : Fin m → Fin m → Prop) (hWsupp : ∀ i j, W i j ≠ 0 ↔ adj i j ∨ i = j)\n (hWsymm : W.IsSymm) (hWpsd : W.PosSemidef) (hWle : (1 - W).PosSemidef)\n (hWnull : ∀ v : Fin m → ℝ, (1 - W).mulVec v = 0 ↔ ∃ c : ℝ, v = fun _ => c)\n (lam2 : ℝ)\n (hlam2 : IsGreatest {μ : ℝ | ∃ v : Fin m → ℝ, v ≠ 0 ∧ (∑ i, v i = 0) ∧ W.mulVec v = μ • v} lam2)\n (hηw : ηw = 1 / (1 + Real.sqrt (1 - lam2 ^ 2)))\n (hyt : yt = FastMix W ηw (fun i => xt i + ((1 - α) / (1 + α)) • (xt i - xtprev i)) K)\n (hxt1 : ∀ i, IsProxStep η R (yt i - η • st i) (xt1 i))\n (hyt1 : yt1 = FastMix W ηw (fun i => xt1 i + ((1 - α) / (1 + α)) • (xt1 i - xt i)) K)\n (hst1 : st1 = FastMix W ηw (fun i => st i + gradFi i (yt1 i) - gradFi i (yt i)) K)\n (hgtrack : rowAvg st = (1 / (m : ℝ)) • ∑ i, gradFi i (yt i))\n (Vt Vt1 : ℝ)\n (hVt : Vt = (f (rowAvg xt) + R (rowAvg xt) - (f xstar + R xstar))\n + (μ / 2) * ‖(rowAvg xtprev + (1 / α) • (rowAvg xt - rowAvg xtprev)) - xstar‖ ^ 2)\n (hVt1 : Vt1 = (f (rowAvg xt1) + R (rowAvg xt1) - (f xstar + R xstar))\n + (μ / 2) * ‖(rowAvg xt + (1 / α) • (rowAvg xt1 - rowAvg xt)) - xstar‖ ^ 2) :\n Vt1 ≤ (1 - α) * Vt + (13 * η / m) * (∑ i, ‖st i - rowAvg st‖ ^ 2)\n + ((20 * M ^ 2 * η + 10 * η⁻¹ + (1 + 8 / α ^ 3) * M ^ 2 / L) / m) * (∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n cases d with\n | zero =>\n have hzero (x : EuclideanSpace ℝ (Fin 0)) : x = 0 := Subsingleton.elim _ _\n have hVt0 : Vt = 0 := by\n rw [hVt]\n simp [hzero]\n have hVt10 : Vt1 = 0 := by\n rw [hVt1]\n simp [hzero]\n have hs0 : (∑ i, ‖st i - rowAvg st‖ ^ 2) = 0 := by\n apply Finset.sum_eq_zero\n intro i hi\n rw [hzero (st i - rowAvg st)]\n simp\n have hy0 : (∑ i, ‖yt i - rowAvg yt‖ ^ 2) = 0 := by\n apply Finset.sum_eq_zero\n intro i hi\n rw [hzero (yt i - rowAvg yt)]\n simp\n rw [hVt0, hVt10, hs0, hy0]\n simp\n | succ n =>\n have hmR : (0 : ℝ) < (m : ℝ) := by exact_mod_cast hm\n have hαpos : 0 < α := by\n rw [hα]\n exact Real.sqrt_pos.mpr (mul_pos hμ hη)\n have hαsq : α ^ 2 = μ * η := by\n rw [hα, Real.sq_sqrt (mul_nonneg hμ.le hη.le)]\n have hμeq : μ = α ^ 2 / η := by\n rw [hαsq]\n field_simp\n have hμL' : μ ≤ L :=\n strong_smooth_mu_le_fin_succ μ L hμ hL f gradf hfsmooth hfconv\n have hαquarter : α + α ^ 2 / 4 ≤ 1 :=\n alpha_quarter_small μ L η α hL hμL' hηeq hαsq hαpos.le\n let G : Fin m → EuclideanSpace ℝ (Fin (n + 1)) :=\n fun i => (1 / η) • (yt i - xt1 i)\n have hG : ∀ i, xt1 i = yt i - η • G i := by\n intro i\n dsimp [G]\n rw [smul_smul]\n have hc : η * (1 / η) = 1 := by field_simp\n rw [hc, one_smul]\n abel\n let v : EuclideanSpace ℝ (Fin (n + 1)) :=\n rowAvg xtprev + (1 / α) • (rowAvg xt - rowAvg xtprev)\n let v1 : EuclideanSpace ℝ (Fin (n + 1)) :=\n rowAvg xt + (1 / α) • (rowAvg xt1 - rowAvg xt)\n let D : EuclideanSpace ℝ (Fin (n + 1)) := gradf (rowAvg yt) - rowAvg st\n let Errv : ℝ :=\n (2 * η / (m : ℝ)) * (∑ i, ‖st i - rowAvg st‖ ^ 2) +\n (2 * η⁻¹ / (m : ℝ)) * (∑ i, ‖yt i - rowAvg yt‖ ^ 2)\n have hyavg : rowAvg yt = rowAvg xt +\n ((1 - α) / (1 + α)) • (rowAvg xt - rowAvg xtprev) := by\n rw [hyt, FastMix_rowAvg W ηw hW, rowAvg_add, rowAvg_smul, rowAvg_sub]\n have hyb : rowAvg yt =\n (1 / (1 + α)) • rowAvg xt + (α / (1 + α)) • v := by\n rw [hyavg]\n dsimp [v]\n match_scalars <;> (field_simp; try ring)\n have hxavg : rowAvg xt1 = rowAvg yt - η • rowAvg G := by\n rw [show xt1 = fun i => yt i - η • G i from funext hG,\n rowAvg_sub, rowAvg_smul]\n have hv1eq : v1 = (1 - α) • v + α • rowAvg yt - (α / μ) • rowAvg G := by\n dsimp only [v1]\n rw [hxavg, hyb, hμeq]\n match_scalars <;> (field_simp; try ring)\n have hfstrong : ∀ x y,\n f x + inner (𝕜 := ℝ) (gradf x) (y - x) + (μ / 2) * ‖y - x‖ ^ 2 ≤ f y := by\n intro x y\n exact strong_subgrad L μ hL hμ.le f gradf hfsmooth hfconv x y\n have hstr : ∀ x, (μ / 2) * ‖x - xstar‖ ^ 2 ≤\n (f x + R x) - (f xstar + R xstar) := by\n intro x\n exact composite_growth μ hμ.le f R hfconv hRconv xstar hxstar x\n have hkey : ∀ z : EuclideanSpace ℝ (Fin (n + 1)),\n f (rowAvg xt1) + R (rowAvg xt1) ≤\n f z + R z - inner (𝕜 := ℝ) (D + rowAvg G) (z - rowAvg yt)\n - η * inner (𝕜 := ℝ) D (rowAvg G)\n - η * (1 - η * L / 2) * ‖rowAvg G‖ ^ 2\n - (μ / 2) * ‖z - rowAvg yt‖ ^ 2 + Errv := by\n intro z\n have hk := prox_average_key hm L μ η hL hμ.le hη f gradf R hfsmooth\n hfstrong hRconv yt xt1 st G hG hxt1 z\n simpa [D, Errv, add_assoc] using hk\n have hcore := prox_agd_core μ L η α hL hηeq hαpos hμeq hαquarter\n (fun x => f x + R x) xstar hstr\n (rowAvg xt) v (rowAvg yt) v1 (rowAvg xt1) (rowAvg G) D\n hyb hv1eq Errv hkey\n have hcoreV : Vt1 ≤ (1 - α) * Vt +\n (2 * η + 1 / (2 * μ) +\n 2 * (α + α ^ 2 / 4) ^ 2 / (μ * α ^ 2)) * ‖D‖ ^ 2 + Errv := by\n rw [hVt, hVt1]\n simpa [v, v1] using hcore\n have hcoeff :\n 2 * η + 1 / (2 * μ) +\n 2 * (α + α ^ 2 / 4) ^ 2 / (μ * α ^ 2)\n ≤ (1 + 8 / α ^ 3) / L :=\n prox_core_error_coeff μ L η α hL hη hαpos hηeq hμeq hα1\n have hD : ‖D‖ ^ 2 ≤\n (M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2 := by\n dsimp only [D]\n rw [hgradf_avg, hgtrack]\n calc\n ‖(1 / (m : ℝ)) • ∑ i, gradFi i (rowAvg yt) -\n (1 / (m : ℝ)) • ∑ i, gradFi i (yt i)‖ ^ 2 =\n ‖(1 / (m : ℝ)) • ∑ i, gradFi i (yt i) -\n (1 / (m : ℝ)) • ∑ i, gradFi i (rowAvg yt)‖ ^ 2 := by\n rw [norm_sub_rev]\n _ ≤ (M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2 :=\n avg_lipschitz_error hm M hM.le gradFi yt (rowAvg yt) hFiLip\n have hcoef_nonneg : 0 ≤\n 2 * η + 1 / (2 * μ) +\n 2 * (α + α ^ 2 / 4) ^ 2 / (μ * α ^ 2) := by\n positivity\n have hDterm :\n (2 * η + 1 / (2 * μ) +\n 2 * (α + α ^ 2 / 4) ^ 2 / (μ * α ^ 2)) * ‖D‖ ^ 2 ≤\n ((1 + 8 / α ^ 3) / L) *\n ((M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n calc\n _ ≤ (2 * η + 1 / (2 * μ) +\n 2 * (α + α ^ 2 / 4) ^ 2 / (μ * α ^ 2)) *\n ((M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2) :=\n mul_le_mul_of_nonneg_left hD hcoef_nonneg\n _ ≤ ((1 + 8 / α ^ 3) / L) *\n ((M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n exact mul_le_mul_of_nonneg_right hcoeff (by positivity)\n have hs_slack :\n 0 ≤ (11 * η / (m : ℝ)) * ∑ i, ‖st i - rowAvg st‖ ^ 2 := by\n positivity\n have hy_slack :\n 0 ≤ ((20 * M ^ 2 * η + 8 * η⁻¹) / (m : ℝ)) *\n ∑ i, ‖yt i - rowAvg yt‖ ^ 2 := by\n positivity\n have hstep : Vt1 ≤ (1 - α) * Vt +\n ((1 + 8 / α ^ 3) / L) *\n ((M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2) + Errv := by\n exact hcoreV.trans (add_le_add (add_le_add le_rfl hDterm) le_rfl)\n calc\n Vt1 ≤ (1 - α) * Vt +\n ((1 + 8 / α ^ 3) / L) *\n ((M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2) + Errv := hstep\n _ ≤ ((1 - α) * Vt +\n ((1 + 8 / α ^ 3) / L) *\n ((M ^ 2 / (m : ℝ)) * ∑ i, ‖yt i - rowAvg yt‖ ^ 2) + Errv) +\n ((11 * η / (m : ℝ)) * ∑ i, ‖st i - rowAvg st‖ ^ 2 +\n ((20 * M ^ 2 * η + 8 * η⁻¹) / (m : ℝ)) *\n ∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n exact le_add_of_nonneg_right (add_nonneg hs_slack hy_slack)\n _ = (1 - α) * Vt + (13 * η / m) * (∑ i, ‖st i - rowAvg st‖ ^ 2)\n + ((20 * M ^ 2 * η + 10 * η⁻¹ + (1 + 8 / α ^ 3) * M ^ 2 / L) / m) *\n (∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n dsimp only [Errv]\n ring\n\nset_option maxHeartbeats 4000000 in\ntheorem lemma27 {d m : ℕ} (hm : 0 < m) (μ L M η α : ℝ)\n (hμ : 0 < μ) (hL : 0 < L) (hM : 0 < M)\n (hLM : L ≤ M) (hη : 0 < η) (hηeq : η = 1 / L)\n (hα : α = Real.sqrt (μ * η))\n (hα1 : α ≤ 1)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hfsmooth : IsSmooth L f gradf) (hfconv : StrongConvexOn Set.univ μ f)\n (Fi : Fin m → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradFi : Fin m → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hFismooth : ∀ i, IsSmooth M (Fi i) (gradFi i))\n\n (hFiLip : ∀ i x y, ‖gradFi i x - gradFi i y‖ ≤ M * ‖x - y‖)\n (hfavg : f = fun x => (1 / (m : ℝ)) * ∑ i, Fi i x)\n (hgradf_avg : gradf = fun x => (1 / (m : ℝ)) • ∑ i, gradFi i x)\n (xstar : EuclideanSpace ℝ (Fin d)) (hxstar : ∀ x, f xstar ≤ f x)\n (xtprev ytprev xt yt xt1 : Fin m → EuclideanSpace ℝ (Fin d))\n (K : ℕ)\n (W : Matrix (Fin m) (Fin m) ℝ) (ηw : ℝ) (hW : ∀ j, ∑ i, W i j = 1)\n (adj : Fin m → Fin m → Prop) (hWsupp : ∀ i j, W i j ≠ 0 ↔ adj i j ∨ i = j)\n (hWsymm : W.IsSymm) (hWpsd : W.PosSemidef) (hWle : (1 - W).PosSemidef)\n (hWnull : ∀ v : Fin m → ℝ, (1 - W).mulVec v = 0 ↔ ∃ c : ℝ, v = fun _ => c)\n (lam2 : ℝ)\n (hlam2 : IsGreatest {μ : ℝ | ∃ v : Fin m → ℝ, v ≠ 0 ∧ (∑ i, v i = 0) ∧ W.mulVec v = μ • v} lam2)\n (hηw : ηw = 1 / (1 + Real.sqrt (1 - lam2 ^ 2)))\n (hyt : yt = fun i => xt i + ((1 - α) / (1 + α)) • (xt i - xtprev i))\n (hprevavg : rowAvg xt = rowAvg ytprev\n - η • ((1 / (m : ℝ)) • ∑ i, gradFi i (ytprev i)))\n (hxt1 : xt1 = FastMix W ηw (fun i => yt i + (xt i - ytprev i)\n - η • (gradFi i (yt i) - gradFi i (ytprev i))) K)\n (Vt Vt1 : ℝ)\n (hVt : Vt = (f (rowAvg xt) - f xstar)\n + (μ / 2) * ‖(rowAvg xtprev + (1 / α) • (rowAvg xt - rowAvg xtprev)) - xstar‖ ^ 2)\n (hVt1 : Vt1 = (f (rowAvg xt1) - f xstar)\n + (μ / 2) * ‖(rowAvg xt + (1 / α) • (rowAvg xt1 - rowAvg xt)) - xstar‖ ^ 2) :\n Vt1 ≤ (1 - (3 / 4) * α) * Vt\n + (1 + 8 / α ^ 3) * (M ^ 2 / L) * (1 / m) * (∑ i, ‖yt i - rowAvg yt‖ ^ 2) := by\n -- ===== scalar preliminaries =====\n have hmR : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n have hLne : (L:ℝ) ≠ 0 := ne_of_gt hL\n have hαpos : (0:ℝ) < α := by\n rw [hα]; exact Real.sqrt_pos.mpr (by positivity)\n have hμL : �� = α^2 * L := by\n rw [hα, Real.sq_sqrt (by positivity : (0:ℝ) ≤ μ * η), hηeq]\n field_simp\n have h1a : (0:ℝ) < 1 + α := by linarith\n -- ===== averaged iterates =====\n set gp : EuclideanSpace ℝ (Fin d) := (1 / (m:ℝ)) • ∑ i, gradFi i (ytprev i) with hgpdef\n set gv : EuclideanSpace ℝ (Fin d) := (1 / (m:ℝ)) • ∑ i, gradFi i (yt i) with hgvdef\n obtain ⟨zt, hztdef⟩ : ∃ w : EuclideanSpace ℝ (Fin d),\n w = rowAvg xtprev + (1/α) • (rowAvg xt - rowAvg xtprev) := ⟨_, rfl⟩\n have hyavg : rowAvg yt = rowAvg xt + ((1-α)/(1+α)) • (rowAvg xt - rowAvg xtprev) := by\n rw [hyt]\n have hsum : (∑ i, (xt i + ((1-α)/(1+α)) • (xt i - xtprev i)))\n = (∑ i, xt i) + ((1-α)/(1+α)) • ((∑ i, xt i) - (∑ i, xtprev i)) := by\n simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.smul_sum]\n simp only [rowAvg, hsum]\n module\n have hyavg' : rowAvg yt = (1/(1+α)) • rowAvg xt + (α/(1+α)) • zt := by\n rw [hyavg, hztdef]\n match_scalars <;> (field_simp; try ring)\n have hx1avg : rowAvg xt1 = rowAvg yt - (1/L) • gv := by\n rw [hxt1, FastMix_rowAvg W ηw hW]\n have hsum : (∑ i, (yt i + (xt i - ytprev i)\n - η • (gradFi i (yt i) - gradFi i (ytprev i))))\n = (∑ i, yt i) + ((∑ i, xt i) - (∑ i, ytprev i))\n - η • ((∑ i, gradFi i (yt i)) - (∑ i, gradFi i (ytprev i))) := by\n simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.smul_sum]\n have hstep : rowAvg (fun i => yt i + (xt i - ytprev i)\n - η • (gradFi i (yt i) - gradFi i (ytprev i)))\n = rowAvg yt + (rowAvg xt - rowAvg ytprev) - η • (gv - gp) := by\n simp only [rowAvg, hsum, hgvdef, hgpdef]\n module\n rw [hstep, hprevavg, hηeq]\n module\n have hz1' : rowAvg xt + (1/α) • (rowAvg xt1 - rowAvg xt)\n = (1-α) • zt + α • (rowAvg yt) - (α/μ) • gv := by\n rw [hx1avg, hyavg', hμL]\n match_scalars <;> (field_simp; try ring)\n -- ===== gradient error =====\n have hgradf_yb : gradf (rowAvg yt) = (1 / (m:ℝ)) • ∑ i, gradFi i (rowAvg yt) := by\n rw [hgradf_avg]\n have hnormle : ‖gv - (1 / (m:ℝ)) • ∑ i, gradFi i (rowAvg yt)‖\n ≤ M * ((1 / (m:ℝ)) * ∑ i, ‖yt i - rowAvg yt‖) := by\n have hdiff : gv - (1 / (m:ℝ)) • ∑ i, gradFi i (rowAvg yt)\n = (1 / (m:ℝ)) • ∑ i, (gradFi i (yt i) - gradFi i (rowAvg yt)) := by\n rw [hgvdef, Finset.sum_sub_distrib, smul_sub]\n rw [hdiff, norm_smul]\n have h1 : ‖∑ i, (gradFi i (yt i) - gradFi i (rowAvg yt))‖\n ≤ ∑ i, ‖gradFi i (yt i) - gradFi i (rowAvg yt)‖ := norm_sum_le _ _\n have h2 : ∑ i, ‖gradFi i (yt i) - gradFi i (rowAvg yt)‖\n ≤ ∑ i, M * ‖yt i - rowAvg yt‖ :=\n Finset.sum_le_sum (fun i _ => hFiLip i (yt i) (rowAvg yt))\n have h3 : ∑ i, M * ‖yt i - rowAvg yt‖ = M * ∑ i, ‖yt i - rowAvg yt‖ := by\n rw [Finset.mul_sum]\n have hnn : ‖(1 / (m:ℝ))‖ = 1 / (m:ℝ) := by\n rw [Real.norm_eq_abs, abs_of_pos]; positivity\n rw [hnn]\n have hmain : ‖∑ i, (gradFi i (yt i) - gradFi i (rowAvg yt))‖\n ≤ M * ∑ i, ‖yt i - rowAvg yt‖ := by linarith [h1, h2, h3.le, h3.ge]\n have := mul_le_mul_of_nonneg_left hmain (by positivity : (0:ℝ) ≤ 1 / (m:ℝ))\n calc (1 / (m:ℝ)) * ‖∑ i, (gradFi i (yt i) - gradFi i (rowAvg yt))‖\n ≤ (1 / (m:ℝ)) * (M * ∑ i, ‖yt i - rowAvg yt‖) := this\n _ = M * ((1 / (m:ℝ)) * ∑ i, ‖yt i - rowAvg yt‖) := by ring\n have herr : ‖gv - gradf (rowAvg yt)‖^2\n ≤ M^2 * ((1 / (m:ℝ)) * ∑ i, ‖yt i - rowAvg yt‖^2) := by\n rw [hgradf_yb]\n have hcs := sq_avg_le hm (fun i => ‖yt i - rowAvg yt‖) (fun i => norm_nonneg _)\n have hnn0 : (0:ℝ) ≤ M * ((1 / (m:ℝ)) * ∑ i, ‖yt i - rowAvg yt‖) := by positivity\n have hsq : ‖gv - (1 / (m:ℝ)) • ∑ i, gradFi i (rowAvg yt)‖^2\n ≤ (M * ((1 / (m:ℝ)) * ∑ i, ‖yt i - rowAvg yt‖))^2 := by\n nlinarith [hnormle, norm_nonneg (gv - (1 / (m:ℝ)) • ∑ i, gradFi i (rowAvg yt)), hnn0]\n nlinarith [hsq, hcs, sq_nonneg M, mul_le_mul_of_nonneg_left hcs (sq_nonneg M)]\n -- ===== apply the core AGD estimate =====\n have main := agd_core μ L α hμ hL hαpos hα1 hμL f gradf hfsmooth hfconv xstar hxstar\n (rowAvg xt) zt (rowAvg yt) (rowAvg xt1)\n (rowAvg xt + (1/α) • (rowAvg xt1 - rowAvg xt)) gv\n hyavg' hx1avg hz1' (M^2 * ((1 / (m:ℝ)) * ∑ i, ‖yt i - rowAvg yt‖^2)) herr\n rw [← hztdef] at hVt\n rw [hVt, hVt1]\n have heq : (1 + 8/α^3) * (M^2 * ((1 / (m:ℝ)) * ∑ i, ‖yt i - rowAvg yt‖^2)) / L\n = (1 + 8/α^3) * (M^2/L) * (1/(m:ℝ)) * (∑ i, ‖yt i - rowAvg yt‖^2) := by ring\n linarith [main, heq.le, heq.ge]\n\n\n\nprivate lemma charpoly_fin_three (a11 a12 a13 a21 a22 a23 a31 a32 a33 p q s : ℝ)\n (hp : p = -(a11+a22+a33))\n (hq : q = a11*a22 - a12*a21 + a11*a33 - a13*a31 + a22*a33 - a23*a32)\n (hs : s = -(a11*a22*a33 - a11*a23*a32 - a12*a21*a33 + a12*a23*a31\n + a13*a21*a32 - a13*a22*a31)) :\n (!![a11,a12,a13; a21,a22,a23; a31,a32,a33] : Matrix (Fin 3) (Fin 3) ℝ).charpoly\n = X^3 + C p * X^2 + C q * X + C s := by\n subst hp; subst hq; subst hs\n simp [Matrix.charpoly, Matrix.det_fin_three, Matrix.charmatrix]\n ring\n\nprivate lemma cubic_expand (p q r : ℝ) :\n (X - C p)*(X - C q)*(X - C r)\n = X^3 - C (p+q+r) * X^2 + C (p*q+p*r+q*r) * X - C (p*q*r) := by\n simp only [map_add, map_mul]\n ring\n\nprivate lemma cubic_factor_of (a b c p q r : ℝ) (h1 : p+q+r = -a)\n (h2 : p*q+p*r+q*r = b) (h3 : p*q*r = -c) :\n (X^3 + C a*X^2 + C b*X + C c : ℝ[X]) = (X - C p)*(X - C q)*(X - C r) := by\n rw [cubic_expand, h1, h2, h3, map_neg, map_neg]\n ring\n\nset_option maxHeartbeats 1000000 in\nprivate lemma cubic_split (a b c x0 : ℝ) (ha : a < 0) (hb : b < 0) (hc : c < 0)\n (ha2 : -a ≤ 1/2)\n (hhalf : 0 < (1/2:ℝ)^3 + a*(1/2)^2 + b*(1/2) + c)\n (hx0 : x0 < 0) (hpx0 : 0 < x0^3 + a*x0^2 + b*x0 + c) :\n ∃ l1 l2 l3 : ℝ,\n (X^3 + C a * X^2 + C b * X + C c : ℝ[X]) = (X - C l1)*(X - C l2)*(X - C l3)\n ∧ 0 < l1 ∧ |l3| ≤ |l2| ∧ |l2| < l1 ∧ l1 ≤ 1/2\n ∧ l1^3 + a*l1^2 + b*l1 + c = 0 ∧ 0 < l1^2 + b := by\n have hcont : ContinuousOn (fun x : ℝ => x^3 + a*x^2 + b*x + c) (Set.Icc (-a) (1/2)) := by\n apply Continuous.continuousOn; fun_prop\n have hfa : (fun x : ℝ => x^3 + a*x^2 + b*x + c) (-a) < 0 := by\n have e : (-a)^3 + a*(-a)^2 + b*(-a) + c = c - a*b := by ring\n show (-a)^3 + a*(-a)^2 + b*(-a) + c < 0\n rw [e]\n nlinarith [mul_pos (neg_pos.mpr ha) (neg_pos.mpr hb)]\n have hfhalf : 0 < (fun x : ℝ => x^3 + a*x^2 + b*x + c) (1/2) := hhalf\n obtain ⟨l1, hl1mem, hl1⟩ := intermediate_value_Icc ha2 hcont ⟨hfa.le, hfhalf.le⟩\n obtain ⟨hl1a, hl1half⟩ := hl1mem\n have hl1pos : 0 < l1 := lt_of_lt_of_le (neg_pos.mpr ha) hl1a\n have hproot : l1^3 + a*l1^2 + b*l1 + c = 0 := hl1\n obtain ⟨B, hBdef⟩ : ∃ B : ℝ, B = a + l1 := ⟨_, rfl⟩\n obtain ⟨Cc, hCdef⟩ : ∃ Cc : ℝ, Cc = l1^2 + a*l1 + b := ⟨_, rfl⟩\n have hBnn : 0 ≤ B := by rw [hBdef]; linarith\n have hl1C : l1 * Cc = -c := by rw [hCdef]; linear_combination hproot\n have hCpos : 0 < Cc := by\n by_contra h\n push_neg at h\n have : l1 * Cc ≤ 0 := mul_nonpos_of_nonneg_of_nonpos hl1pos.le h\n rw [hl1C] at this; linarith\n -- l1^2 + b > 0\n have hl1b : 0 < l1^2 + b := by\n by_contra h\n push_neg at h\n have h2 : l1 * (l1^2 + b) ≤ 0 := mul_nonpos_of_nonneg_of_nonpos hl1pos.le h\n have h3 : l1 * (l1^2 + b) = -a*l1^2 - c := by linear_combination hproot\n rw [h3] at h2\n nlinarith [mul_pos (neg_pos.mpr ha) (mul_pos hl1pos hl1pos)]\n have hq0 : x0^2 + B*x0 + Cc < 0 := by\n have h2 : 0 < (x0 - l1) * (x0^2 + B*x0 + Cc) := by\n have e : (x0 - l1) * (x0^2 + B*x0 + Cc) = x0^3 + a*x0^2 + b*x0 + c := by\n rw [hBdef, hCdef]; linear_combination (-1 : ℝ) * hproot\n rw [e]; exact hpx0\n by_contra h\n push_neg at h\n have hneg : 0 ≤ (l1 - x0) * (x0^2 + B*x0 + Cc) := mul_nonneg (by linarith) h\n nlinarith [h2, hneg]\n have hDpos : 0 < B^2 - 4*Cc := by nlinarith [sq_nonneg (x0 + B/2)]\n obtain ⟨s, hsdef⟩ : ∃ s : ℝ, s = Real.sqrt (B^2 - 4*Cc) := ⟨_, rfl⟩\n have hs2 : s^2 = B^2 - 4*Cc := by rw [hsdef]; exact Real.sq_sqrt hDpos.le\n have hsnn : 0 ≤ s := by rw [hsdef]; exact Real.sqrt_nonneg _\n have hsum : l1 + ((-B - s)/2) + ((-B + s)/2) = -a := by rw [hBdef]; ring\n have hpair : l1*((-B - s)/2) + l1*((-B + s)/2) + ((-B - s)/2)*((-B + s)/2) = b := by\n have e : l1*((-B - s)/2) + l1*((-B + s)/2) + ((-B - s)/2)*((-B + s)/2)\n = -l1*B + (B^2 - s^2)/4 := by ring\n rw [e, hs2, hBdef, hCdef]; ring\n have hprod : l1*((-B - s)/2)*((-B + s)/2) = -c := by\n have e : l1*((-B - s)/2)*((-B + s)/2) = l1 * ((B^2 - s^2)/4) := by ring\n rw [e, hs2]\n have e2 : (B^2 - (B^2 - 4*Cc))/4 = Cc := by ring\n rw [e2]; exact hl1C\n refine ⟨l1, (-B - s)/2, (-B + s)/2, cubic_factor_of a b c _ _ _ hsum hpair hprod,\n hl1pos, ?_, ?_, hl1half, hproot, hl1b⟩\n · have hsB : s < B := by nlinarith\n rw [abs_of_nonpos (by linarith : (-B + s)/2 ≤ 0),\n abs_of_nonpos (by linarith : (-B - s)/2 ≤ 0)]\n linarith\n · have hlt : s < l1 - a := by\n have h1 : 0 < l1 - a := by linarith\n have h4 : s^2 < (l1 - a)^2 := by\n rw [hs2, hBdef, hCdef]; nlinarith\n nlinarith\n rw [abs_of_nonpos (by linarith : (-B - s)/2 ≤ 0), hBdef]\n linarith\n\n\nset_option maxHeartbeats 1000000 in\ntheorem lemma10 (L M ρ : ℝ) (hL : 0 < L) (η : ℝ) (hηeq : η = 1 / (2 * L)) (hM : 0 < M) (hLM : L ≤ M) (hρpos : 0 < ρ)\n (hρ : ρ ≤ L ^ 3 / (1280 * M ^ 3))\n (A : Matrix (Fin 3) (Fin 3) ℝ)\n (hA : A = !![0, 2, 2; 2 * ρ, 4 * ρ, 4 * ρ; ρ * M / L, 8 * ρ * M ^ 2 / L ^ 2, 5 * ρ * M / L]) :\n ∃ l1 l2 l3 : ℝ, A.charpoly = (X - C l1) * (X - C l2) * (X - C l3) ∧\n 0 < l1 ∧ |l3| ≤ |l2| ∧ |l2| < l1 ∧ l1 ≤ 1 / 2 ∧\n ∃ v : Fin 3 → ℝ, A.mulVec v = l1 • v ∧\n 0 < v 0 ∧ v 0 ≤ 8 * v 2 / Real.sqrt ρ ∧\n 0 < v 1 ∧ v 1 ≤ 3 * v 2 ∧\n 0 < v 2 := by\n \n have hLne : L ≠ 0 := ne_of_gt hL\n obtain ⟨r, hrdef⟩ : ∃ r : ℝ, r = M / L := ⟨_, rfl⟩\n have hr1 : 1 ≤ r := by rw [hrdef]; exact (one_le_div hL).mpr hLM\n have hrpos : 0 < r := lt_of_lt_of_le one_pos hr1\n have hkey : ρ * r^3 ≤ 1/1280 := by\n have h : ρ * r^3 ≤ (L^3/(1280*M^3)) * r^3 :=\n mul_le_mul_of_nonneg_right hρ (by positivity)\n have h2 : (L^3/(1280*M^3)) * r^3 = 1/1280 := by\n rw [hrdef]; field_simp\n linarith [h, h2.le, h2.ge]\n have hb2 : ρ * r^2 ≤ 1/1280 := by nlinarith\n have hb1 : ρ * r ≤ 1/1280 := by nlinarith\n have hb0 : ρ ≤ 1/1280 := by nlinarith\n have hAr : A = !![0,2,2; 2*ρ,4*ρ,4*ρ; ρ*r, 8*ρ*r^2, 5*ρ*r] := by\n rw [hA]\n have h1 : ρ * M / L = ρ * r := by rw [hrdef]; ring\n have h2 : 8 * ρ * M ^ 2 / L ^ 2 = 8*ρ*r^2 := by rw [hrdef]; field_simp\n have h3 : 5 * ρ * M / L = 5*ρ*r := by rw [hrdef]; ring\n rw [h1, h2, h3]\n obtain ⟨a, hadef⟩ : ∃ a : ℝ, a = -(ρ*(4+5*r)) := ⟨_, rfl⟩\n obtain ⟨b, hbdef⟩ : ∃ b : ℝ, b = -(4*ρ) - 2*ρ*r + 20*ρ^2*r - 32*ρ^2*r^2 := ⟨_, rfl⟩\n obtain ⟨c, hcdef⟩ : ∃ c : ℝ, c = 20*ρ^2*r - 32*ρ^2*r^2 := ⟨_, rfl⟩\n have hchar : A.charpoly = X^3 + C a * X^2 + C b * X + C c := by\n rw [hAr, hadef, hbdef, hcdef]; apply charpoly_fin_three <;> ring\n have ha : a < 0 := by rw [hadef]; nlinarith\n have hb : b < 0 := by\n rw [hbdef]\n nlinarith [mul_pos (show (0:ℝ) < ρ^2*r by positivity) (show (0:ℝ) < 32*r-20 by linarith)]\n have hc : c < 0 := by\n rw [hcdef]\n nlinarith [mul_pos (show (0:ℝ) < ρ^2*r by positivity) (show (0:ℝ) < 32*r-20 by linarith)]\n have ha2 : -a ≤ 1/2 := by rw [hadef]; nlinarith\n have hhalf : 0 < (1/2:ℝ)^3 + a*(1/2)^2 + b*(1/2) + c := by\n rw [hadef, hbdef, hcdef]\n nlinarith [mul_le_mul hb1 hb1 (by positivity) (by norm_num : (0:ℝ) ≤ 1/1280),\n mul_pos (mul_pos hρpos hρpos) hrpos]\n have hpx0 : 0 < (-(16*ρ*r))^3 + a*(-(16*ρ*r))^2 + b*(-(16*ρ*r)) + c := by\n have e : (-(16*ρ*r))^3 + a*(-(16*ρ*r))^2 + b*(-(16*ρ*r)) + c\n = ρ^2*r*(84 - 4864*(ρ*r^2) - 1344*(ρ*r)) := by\n rw [hadef, hbdef, hcdef]; ring\n rw [e]\n exact mul_pos (by positivity) (by nlinarith)\n obtain ⟨l1, l2, l3, hfact, hl1pos, habs1, habs2, hl1half, hproot, hl1b⟩ :=\n cubic_split a b c (-(16*ρ*r)) ha hb hc ha2 hhalf (by nlinarith) hpx0\n refine ⟨l1, l2, l3, by rw [hchar, hfact], hl1pos, habs1, habs2, hl1half, ?_⟩\n obtain ⟨W, hWdef⟩ : ∃ W : ℝ, W = l1^2 - 4*ρ*(1+l1) := ⟨_, rfl⟩\n have hl16 : 6*ρ < l1^2 := by\n rw [hbdef] at hl1b\n nlinarith [mul_pos (show (0:ℝ) < ρ^2*r by positivity) (show (0:ℝ) < 32*r-20 by linarith),\n mul_le_mul_of_nonneg_left hr1 hρpos.le]\n have hWpos : 0 < W := by rw [hWdef]; nlinarith\n rw [hadef, hbdef, hcdef] at hproot\n have hv3 : l1 * (W - 2*ρ*r) = 32*ρ^2*r^2*(1+l1) + 5*ρ*r*W := by\n rw [hWdef]; linear_combination hproot\n have hW2 : 2*ρ*r < W := by\n by_contra hcon\n push_neg at hcon\n have h1 : l1 * (W - 2*ρ*r) ≤ 0 :=\n mul_nonpos_of_nonneg_of_nonpos hl1pos.le (by linarith)\n rw [hv3] at h1\n have p1 : (0:ℝ) < 32*ρ^2*r^2*(1+l1) := mul_pos (by positivity) (by linarith)\n have p2 : (0:ℝ) < 5*ρ*r*W := by positivity\n linarith\n have hrr : ρ ≤ ρ * r := by nlinarith\n have hv12 : 4*ρ*(1+l1) ≤ 3*W := by nlinarith\n have e0 : (![2*l1, 4*ρ*(1+l1), W] : Fin 3 → ℝ) 0 = 2*l1 := rfl\n have e1 : (![2*l1, 4*ρ*(1+l1), W] : Fin 3 → ℝ) 1 = 4*ρ*(1+l1) := rfl\n have e2 : (![2*l1, 4*ρ*(1+l1), W] : Fin 3 → ℝ) 2 = W := rfl\n refine ⟨![2*l1, 4*ρ*(1+l1), W], ?_, ?_, ?_, ?_, ?_, ?_⟩\n · rw [hAr]\n funext i\n fin_cases i\n · simp [Matrix.mulVec, dotProduct, Fin.sum_univ_three]\n rw [hWdef]; ring\n · simp [Matrix.mulVec, dotProduct, Fin.sum_univ_three]\n rw [hWdef]; ring\n · simp [Matrix.mulVec, dotProduct, Fin.sum_univ_three]\n rw [hWdef]\n linear_combination (-1:ℝ) * hproot\n · rw [e0]; linarith\n · rw [e0, e2, le_div_iff₀ (Real.sqrt_pos.mpr hρpos)]\n have hsq : Real.sqrt ρ ≤ l1 := by\n rw [show l1 = Real.sqrt (l1^2) from (Real.sqrt_sq hl1pos.le).symm]\n exact Real.sqrt_le_sqrt (by nlinarith)\n have h1 : 2*l1^2 ≤ 8*W := by rw [hWdef] at hv12 ⊢; nlinarith\n have h2 : 2*l1*Real.sqrt ρ ≤ 2*l1*l1 :=\n mul_le_mul_of_nonneg_left hsq (by linarith)\n linarith\n · rw [e1]; exact mul_pos (by positivity) (by linarith)\n · rw [e1, e2]; linarith\n · rw [e2]; exact hWpos\n\nend ResearchLevel\n"} +{"id": "v7-evendar06a", "source": "Research-level", "targets": [{"label": "Theorem 6", "decls": ["naive_PAC"], "statement": "Theorem 6 Naive(ε,δ) is an (ε, δ)-PAC algorithm, and its arm sample complexity is $O\\left((n/\\varepsilon^{2})\\log(n/\\delta)\\right)$.", "context_ids": ["v7-evendar06a:ctx1", "v7-evendar06a:ctx2", "v7-evendar06a:ctx3", "v7-evendar06a:ctx4"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}, {"label": "Theorem 8", "decls": ["successive_elimination_PAC"], "statement": "Theorem 8 Assume $\\Delta_{i} > 0$ for every $i = 2, 3, \\ldots, n$. Let the constant $c$ in Algorithm 3 be any value with $c > 4$, and let $0 < \\delta < 1$. Then the Successive Elimination algorithm (Algorithm 3) is (0, δ)-PAC in the following sense: with probability no less than $1 - \\delta$, there exists a time from which on the set of surviving arms consists exactly of the best arm, and the number of samples drawn before that time is at most (where the constant hidden in the O depends on c alone)\n\n$$\nO\\left(\\sum_{i=2}^{n}\\frac{\\ln(\\frac{n}{\\delta\\Delta_{i}})}{\\Delta_{i}^{2}}\\right).\n$$", "context_ids": ["v7-evendar06a:ctx1", "v7-evendar06a:ctx2", "v7-evendar06a:ctx3", "v7-evendar06a:ctx5", "v7-evendar06a:ctx6"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}, {"label": "Theorem 10", "decls": ["median_elimination_PAC"], "statement": "Theorem 10 Median Elimination(ε,δ) is an (ε, δ)-PAC algorithm, with sample complexity\n\n$$\nO\\left(\\frac{n}{\\varepsilon^{2}}\\log\\left(\\frac{1}{\\delta}\\right)\\right).\n$$", "context_ids": ["v7-evendar06a:ctx1", "v7-evendar06a:ctx2", "v7-evendar06a:ctx3", "v7-evendar06a:ctx7"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}], "nl_proof": "### Proof of Theorem 6\n\nProof The bound on the sample complexity follows directly from how the algorithm is defined. It remains to show the (ε, δ)-PAC property. Fix an arm $a^{\\prime}$ with $\\mathbb{E}(R(a^{\\prime})) \\hat{p}_{a^{*}}$:\n\n$$\n\\begin{array}{r c l}{P\\left(\\hat{p}_{a^{\\prime}}>\\hat{p}_{a^{*}}\\right)}&{\\leq}&{P\\left(\\hat{p}_{a^{\\prime}}>\\mathbb{E}[R(a^{\\prime})]+\\varepsilon/2 \\text{ or }\\hat{p}_{a^{*}}\\mathbb{E}[R(a^{\\prime})]+\\varepsilon/2\\right)+P\\left(\\hat{p}_{a^{*}}\\hat{p}_{a^{*}}\\right)\\leq\\delta/n$. A sum over all candidate arms $a^{\\prime}$ then shows that the probability of failure does not exceed $(n-1)(\\delta/n)<\\delta .$\n\n### Proof of Theorem 8\n\nProof The core of the argument is that, for every time t and every action a, the empirical probability $\\hat{p}_{a}^{t}$ lies within $\\alpha_{t}$ of the true probability $p_{a}$. Indeed, for each time t and each action $a \\in S_{t}$,\n\n$$\n\\mathbf{P}[ | \\hat{p}_{a}^{t}- p_{a}| \\geq \\alpha_{t}] \\leq 2 e^{- 2 \\alpha_{t}^{2}t}\\leq \\frac{2 \\delta}{c n t^{2}}.\n$$\n\nChoosing the constant c larger than 4 and applying the union bound, we get that with probability at least $1 - \\delta / n$, simultaneously for all times t and all actions $a \\in S_{t}$, $| \\hat{p}_{a}^{t}- p_{a}| \\leq \\alpha_{t}$. Consequently, with probability $1 - \\delta$ the best arm is never removed. Moreover, because $\\alpha_{t}$ tends to zero as t grows, every non-best arm is removed at some point. Hence the algorithm is (0, δ)-PAC.\n\nWe now turn to the arm sample complexity. For a non-best arm $a_{i}$ to be removed, we must arrive at a time $t_{i}$ satisfying\n\n$$\n\\hat{\\Delta}_{t_{i}}= \\hat{p}_{a_{1}}^{t_{i}}- \\hat{p}_{a_{i}}^{t_{i}}\\geq 2 \\alpha_{t_{i}}.\n$$\n\nCombining the definition of $\\alpha_{t}$ with the assumption $| \\hat{p}_{a}^{t}- p_{a}| \\leq \\alpha_{t}$ gives\n\n$$\n\\Delta_{i}-2\\alpha_{t}=\\left(p_{1}-\\alpha_{t}\\right)-\\left(p_{i}+\\alpha_{t}\\right)\\geq\\hat{p}_{1}-\\hat{p}_{i}\\geq 2\\alpha_{t},\n$$\n\nand this is valid with probability no less than $1 - \\frac{\\delta}{n}$ when\n\n$$\nt_{i}=O\\left(\\frac{\\ln\\left(n/\\delta\\Delta_{i}\\right)}{\\Delta_{i}^{2}}\\right).\n$$\n\nIn conclusion, with probability at least $1 - \\delta$ the total number of arm samples equals $2 t_{2}+ \\sum_{i = 3}^{n}t_{i}$, and the proof is complete.\n\n### Proof of Theorem 10\n\nWe begin by showing that during the $\\ell$-th phase, the expected reward of the best arm in $S_{\\ell}$ decreases by no more than $\\varepsilon_{\\ell}$.\n\nLemma 11 For the Median Elimination(ε, δ) algorithm, every phase $\\ell$ satisfies\n\n$$\n\\mathbf{P}[ \\max_{j \\in S_{\\ell}}p_{j}\\leq \\max_{i \\in S_{\\ell + 1}}p_{i}+ \\varepsilon_{\\ell}] \\geq 1 - \\delta_{\\ell}.\n$$\n\nProof We may assume, without loss of generality, that we are in the first round and that $p_{1}$ denotes the reward of the best arm. To bound the probability of failure, consider the event $E_{1}= \\{\\hat{p}_{1}< p_{1}- \\varepsilon_{1}/ 2 \\}$, i.e., the event that the empirical estimate for the best arm is pessimistic. Because the sampling is sufficient, $\\mathbf{P}[ E_{1}] \\le \\delta_{1}/ 3$.\n\nSuppose $E_{1}$ fails to hold. We compute the probability that a given arm $j$ that is not $\\varepsilon_{1}$-optimal appears empirically better than the best arm:\n\n$$\n\\mathbf{P}\\left[ \\hat{p}_{j}\\geq \\hat{p}_{1}\\mid \\hat{p}_{1}\\geq p_{1}- \\varepsilon_{1}/ 2 \\right] \\leq \\mathbf{P}\\left[ \\hat{p}_{j}\\geq p_{j}+ \\varepsilon_{1}/ 2 \\mid \\hat{p}_{1}\\geq p_{1}- \\varepsilon_{1}/ 2 \\right] \\leq \\delta_{1}/ 3\n$$\n\nWrite #bad for the number of arms that fail to be $\\varepsilon_{1}$-optimal yet are empirically better than the best arm. Then $\\mathbf{E}[\\#\\mathrm{bad} \\mid \\hat{p}_{1}\\ge p_{1}- \\varepsilon_{1}/ 2 ] \\le n \\delta_{1}/ 3$. Applying Markov's inequality yields\n\n$$\n\\mathbf{P}[ \\# \\mathrm{bad}\\geq n / 2 \\mid \\hat{p}_{1}\\geq p_{1}- \\varepsilon_{1}/ 2 ] \\leq \\frac{n \\delta_{1}/ 3}{n / 2}= 2 \\delta_{1}/ 3 .\n$$\n\nA union bound now shows that the failure probability is at most $\\delta_{1}$.\n\nWe next show that the arm sample complexity is at most $O((n/\\varepsilon^{2})\\log(1/\\delta))$.\n\nLemma 12 Median Elimination(ε, δ) has sample complexity $O\\left((n/\\varepsilon^{2})\\log(1/\\delta)\\right)$.\n\nProof In round $\\ell$ the algorithm draws $4n_{\\ell}\\log(3/\\delta_{\\ell})/\\varepsilon_{\\ell}^{2}$ arm samples. The definitions give\n\n1. $\\delta_{1}= \\delta / 2 \\ ; \\ \\delta_{\\ell}= \\delta_{\\ell - 1}/ 2 = \\delta / 2^{\\ell}$\n\n2. $n_{1}= n ~ ; ~ n_{\\ell}= n_{\\ell - 1}/ 2 = n / 2^{\\ell - 1}$\n\n3. $\\varepsilon_{1}=\\varepsilon/4\\ ;\\ \\varepsilon_{\\ell}=\\frac{3}{4}\\varepsilon_{\\ell-1}=\\left(\\frac{3}{4}\\right)^{\\ell-1}\\varepsilon/4$\n\nHence\n\n$$\n\\begin{array}{r c l}{\\displaystyle\\sum_{\\ell=1}^{\\log_{2}(n)}\\frac{n_{\\ell}\\log(3/\\delta_{\\ell})}{(\\varepsilon_{\\ell}/2)^{2}}}&{=}&{\\displaystyle 4\\sum_{\\ell=1}^{\\log_{2}(n)}\\frac{n/2^{\\ell-1}\\log(2^{\\ell}3/\\delta)}{\\big((\\frac 34)^{\\ell-1}\\varepsilon/4\\big)^{2}}}\\\\ &{=}&{\\displaystyle 64\\sum_{\\ell=1}^{\\log_{2}(n)}n(\\frac 89)^{\\ell-1}(\\frac{\\log(1/\\delta)}{\\varepsilon^{2}}+\\frac{\\log(3)}{\\varepsilon^{2}}+\\frac{\\ell\\log(2)}{\\varepsilon^{2}})}\\\\ &{\\leq}&{\\displaystyle 64\\frac{n\\log(1/\\delta)}{\\varepsilon^{2}}\\sum_{\\ell=1}^{\\infty}(\\frac 89)^{\\ell-1}(\\ell C^{\\prime}+C)=O(\\frac{n\\log(1/\\delta)}{\\varepsilon^{2}})}\\end{array}\n$$\n\nWe are now ready to prove Theorem 10.\n\nProof Lemma 12 gives a bound of $O\\left(n\\log(1/\\delta)/\\varepsilon^{2}\\right)$ on the sample complexity. Lemma 11 says that in each round the algorithm fails with probability $\\delta_{i}$, so the failure probability over all rounds is at most $\\sum_{i=1}^{\\log_{2}(n)}\\delta_{i}\\leq\\delta$. Each round lowers the optimal reward among the surviving arms by no more than $\\varepsilon_{i}$, so the overall error is at most $\\sum_{i=1}^{\\log_{2}(n)}\\varepsilon_{i}\\leq\\varepsilon.$", "context": [{"id": "v7-evendar06a:ctx1", "name": "Setup: multi-armed bandit model (Section 2.1)", "statement": "The model consists of a set A of arms, where $n = \\left| A \\right|$. Sampling an arm $a \\in A$ yields a reward given by a random variable $R(a)$. Rewards are assumed binary: for each arm $a \\in A$, $R(a)\\in\\{0,1\\}$ (every result holds unchanged when the reward is bounded in [0, 1], and, with suitable modifications, more generally whenever the reward is bounded). We write $a_{1},\\cdots,a_{n}$ for the arms and set $p_{i}=\\mathbb{E}[R(a_{i})]$. To simplify notation, the arms are indexed in order of expected reward, $p_{1}> p_{2}> \\ldots > p_{n}$.\n\nThe best arm, denoted $a^{*}$, is an arm whose expected reward is highest; its expected reward $r^{*}$ is called the optimal reward. A non-best arm is an arm with expected reward strictly smaller than $r^{*}$, the expected reward of the best arm. An arm a is ε-optimal if its expected reward is within ε of the optimal reward, that is, $\\mathbb{E}[R(a)]\\geq r^{*}-\\varepsilon$.\n\nAt every time step t, an algorithm for the MAB problem samples some arm $a_{t}$ and obtains a reward $r_{t}$ (whose distribution is $R(a_{t})$). Its choice may depend on the history (that is, the actions taken and rewards received) up to time t − 1. In the end, the algorithm has to commit to one arm and select it."}, {"id": "v7-evendar06a:ctx2", "name": "Definition 1 ((ε,δ)-PAC algorithm) and Remark 2 (worst-case sample complexity)", "statement": "Definition 1 An algorithm for the multi armed bandit is an $(\\varepsilon,\\delta)$-PAC algorithm with sample complexity T if, upon termination, it outputs an ε-optimal arm a' with probability at least 1 − δ, and the number of time steps it executes before terminating is at most T.\n\nRemark 2 The MAB algorithm is allowed to terminate before T steps have elapsed. The sample complexity used here is that of the worst trajectory. Mannor and Tsitsiklis (2004) studied the expected sample complexity (with expectation over both the model and the algorithm), which behaves as $\\Omega((n+\\log(1/\\delta))/\\varepsilon^{2})$; this differs from the complexity established below in Theorem 10. Note also that the algorithm of Mannor and Tsitsiklis (2004) does not have a worst-case bound on its running time."}, {"id": "v7-evendar06a:ctx3", "name": "Lemma 4 (Hoeffding, 1963)", "statement": "Large deviation bounds are used repeatedly in this paper. Since boundedness is assumed, Hoeffding's inequality is available.\n\nLemma 4 (Hoeffding, 1963) Let X be a set, let D be a probability distribution on X, and let $f_{1},\\ldots,f_{m}$ be real-valued functions on X with $f_{i}: X \\longrightarrow [ a_{i}, b_{i}]$ for $i=1,\\ldots,m$, where $a_{i}$ and $b_{i}$ are real numbers with $a_{i}< b_{i}$. Let $x_{1},\\ldots,x_{m}$ be samples drawn independently and identically from D. Then\n\n$$\n\\begin{array}{r l r}{\\mathbf{P}\\left[\\frac{1}{m}\\displaystyle\\sum_{i=1}^{m}f_{i}(x_{i})-\\left(\\frac{1}{m}\\displaystyle\\sum_{i=1}^{m}\\int_{a_{i}}^{b_{i}}f_{i}(x)D(x)\\right)\\ge\\varepsilon\\right]}&{\\le}&{e^{-\\frac{2\\varepsilon^{2}m^{2}}{\\sum_{i=1}^{m}(b_{i}-a_{i})^{2}}}}\\\\ {\\mathbf{P}\\left[\\frac{1}{m}\\displaystyle\\sum_{i=1}^{m}f_{i}(x_{i})-\\left(\\frac{1}{m}\\displaystyle\\sum_{i=1}^{m}\\int_{a_{i}}^{b_{i}}f_{i}(x)D(x)\\right)\\le-\\varepsilon\\right]}&{\\le}&{e^{-\\frac{2\\varepsilon^{2}m^{2}}{\\sum_{i=1}^{m}(b_{i}-a_{i})^{2}}}.}\\end{array}\n$$"}, {"id": "v7-evendar06a:ctx4", "name": "Naive algorithm: Section 3 overview and Algorithm 1", "statement": "This section studies (ε, δ)-PAC algorithms for the MAB problem, i.e., algorithms that must, with probability 1 − δ, output an ε-optimal arm. The starting point is a naive approach: sample every arm $1/(\\varepsilon/2)^{2}\\ln(2n/\\delta)$ times and return the arm whose empirical reward is largest. This naive algorithm has sample complexity $O(n/\\varepsilon^{2}\\log(n/\\delta))$, and it is given as Algorithm 1. Section 3.1 treats an algorithm that removes arms one at a time, and Section 3.2 ends with the Median Elimination algorithm, which attains worst-case optimal sample complexity.\n\nAlgorithm 1 (Naive Algorithm).\nGiven: accuracy $\\varepsilon > 0$ and confidence $\\delta > 0$. Returns: one arm.\n1. For each arm $a \\in A$: draw $\\ell = \\frac{4}{\\varepsilon^{2}}\\ln (\\frac{2 n}{\\delta})$ samples of $a$, and record their mean reward as $\\hat{p}_{a}$.\n2. Return $a^{\\prime}= \\arg \\max_{a \\in A}\\{\\hat{p}_{a}\\}$."}, {"id": "v7-evendar06a:ctx5", "name": "Gap Δ_i (Section 3.1)", "statement": "Define $\\Delta_{i}= p_{1}- p_{i}> 0$."}, {"id": "v7-evendar06a:ctx6", "name": "Algorithm 3: Successive elimination with unknown biases", "statement": "We now drop the assumption that the arms' expected rewards are known beforehand, and present the Successive Elimination algorithm, which handles an arbitrary set of biases. Algorithm 3 below identifies the best arm (not merely an ε-best one) with high probability; Remark 9 later describes how to turn it into an (ε, δ)-PAC algorithm.\n\nAlgorithm 3 (Successive elimination with unknown biases).\nGiven: $\\delta > 0$. Returns: one arm.\n1. Initialise $t = 1$ and $S = A$, and put $\\hat{p}_{a}^{1}= 0$ for each arm a.\n2. Draw one sample from each arm $a \\in S$; write $\\hat{p}_{a}^{t}$ for the mean reward of arm a up to time $t$.\n3. Loop body:\n (a) compute $\\hat{p}_{max}^{t}= \\max_{a \\in S}\\hat{p}_{a}^{t}$ and $\\alpha_{t}=\\sqrt{\\ln(cnt^{2}/\\delta)/t}$, with c a constant;\n (b) remove from $S$ (i.e. $S = S \\backslash \\{a \\}$) every arm $a \\in S$ for which $\\hat{p}_{max}^{t}- \\hat{p}_{a}^{t}\\geq 2 \\alpha_{t}$;\n (c) increase $t$ by one ($t = t + 1$).\n4. Repeat step 3 until $| S | > 1$ (termination condition exactly as printed in the paper)."}, {"id": "v7-evendar06a:ctx7", "name": "Algorithm 4: Median Elimination", "statement": "The algorithm below replaces the ${\\cal O}(\\log(n/\\delta))$ term of the naive bound by ${\\cal O}(\\log(1/\\delta))$. Its idea is to discard the worse half of the arms in every iteration. The best arm need not come out empirically \"the best\"; all that is required is that some ε-optimal arm lies above the median.\n\nAlgorithm 4 (Median Elimination).\nGiven: $\\varepsilon > 0$ and $\\delta > 0$. Returns: one arm.\n1. Initialise $S_{1}= A$, $\\varepsilon_{1}= \\varepsilon/ 4$, $\\delta_{1}= \\delta / 2$, $\\ell = 1$.\n2. Loop body:\n (a) draw $1/(\\varepsilon_{\\ell}/2)^{2}\\log(3/\\delta_{\\ell})$ samples from each arm $a \\in S_{\\ell}$, writing $\\hat{p}_{a}^{\\ell}$ for its empirical value;\n (b) let $m_{\\ell}$ be the median of the values $\\hat{p}_{a}^{\\ell}$;\n (c) set $S_{\\ell + 1}= S_{\\ell}\\backslash \\{a : \\hat{p}_{a}^{\\ell}< m_{\\ell}\\}$;\n (d) update $\\varepsilon_{\\ell + 1}= \\frac{3}{4}\\varepsilon_{\\ell}$ and $\\delta_{\\ell + 1}= \\delta_{\\ell}/ 2$, then $\\ell = \\ell + 1$.\n3. Repeat step 2 until $| S_{\\ell}| = 1$."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace ResearchLevel\n\ndef epsOptimal {n : ℕ} (p : Fin n → ℝ) (pmax ε : ℝ) (a : Fin n) : Prop :=\n pmax - p a ≤ ε\n\nnoncomputable def empMean {n ℓ : ℕ} {Ω : Type*} (X : Fin n → Fin ℓ → Ω → ℝ)\n (ω : Ω) (a : Fin n) : ℝ :=\n (∑ k, X a k ω) / ��\n\nopen Classical in\n\nnoncomputable def naiveOutput {n ℓ : ℕ} [NeZero n] {Ω : Type*}\n (X : Fin n → Fin ℓ → Ω → ℝ) (ω : Ω) : Fin n :=\n (Finite.exists_max (empMean X ω)).choose\n\nnoncomputable def empMeanT {n : ℕ} {Ω : Type*} (X : Fin n → ℕ → Ω → ℝ)\n (a : Fin n) (t : ℕ) (ω : Ω) : ℝ :=\n (∑ k ∈ Finset.range t, X a k ω) / t\n\nnoncomputable def confRadiusSE (c : ℝ) (n t : ℕ) (δ : ℝ) : ℝ :=\n Real.sqrt (Real.log (c * n * (t : ℝ) ^ 2 / δ) / t)\n\nnoncomputable def phaseEps (ε : ℝ) : ℕ → ℝ\n | 0 => ε / 4\n | (ℓ + 1) => (3 / 4) * phaseEps ε ℓ\n\nnoncomputable def phaseDelta (δ : ℝ) : ℕ → ℝ\n | 0 => δ / 2\n | (ℓ + 1) => phaseDelta δ ℓ / 2\n\nnoncomputable def empMeanPhase {n : ℕ} {Ω : Type*} (X : Fin n → ℕ → ℕ → Ω → ℝ)\n (a : Fin n) (ℓ m : ℕ) (ω : Ω) : ℝ :=\n (∑ k ∈ Finset.range m, X a ℓ k ω) / m\n\ntheorem naive_PAC :\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} [NeZero n] (p : Fin n → ℝ)\n (astar : Fin n) (hopt : ∀ a, p a ≤ p astar)\n (ε δ : ℝ) (hε : 0 < ε) (hδ : 0 < δ) (hδ1 : δ < 1)\n (ℓ : ℕ) (hℓ : (2 / ε ^ 2) * Real.log (2 * n / δ) ≤ ℓ)\n (hℓ_le : (ℓ : ℝ) ≤ (2 / ε ^ 2) * Real.log (2 * n / δ) + 1)\n (X : Fin n → Fin ℓ → Ω → ℝ)\n (hX_meas : ∀ a k, Measurable (X a k))\n (hX_bound : ∀ a k, ∀ᵐ ω ∂P, X a k ω ∈ Set.Icc (0 : ℝ) 1)\n (hX_mean : ∀ a k, ∫ ω, X a k ω ∂P = p a)\n (hX_indep : iIndepFun (fun q : Fin n × Fin ℓ => X q.1 q.2) P)\n (hX_ident : ∀ a (k k' : Fin ℓ), ProbabilityTheory.IdentDistrib (X a k) (X a k') P P),\n (1 - δ ≤ P.real {ω | epsOptimal p (p astar) ε (naiveOutput X ω)}) ∧\n ((n : ℝ) * ℓ ≤ C * ((n / ε ^ 2) * Real.log (2 * n / δ) + n)) := by\n sorry\n\ntheorem successive_elimination_PAC :\n ∀ (c : ℝ), 4 < c →\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} [NeZero n] (p : Fin n → ℝ)\n (astar : Fin n) (hopt : ∀ a, p a ≤ p astar)\n (hgap : ∀ a, a ≠ astar → p a < p astar)\n (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ < 1)\n (X : Fin n → ℕ → Ω → ℝ)\n (hX_meas : ∀ a k, Measurable (X a k))\n (hX_bound : ∀ a k, ∀ᵐ ω ∂P, X a k ω ∈ Set.Icc (0 : ℝ) 1)\n (hX_mean : ∀ a k, ∫ ω, X a k ω ∂P = p a)\n (hX_indep : iIndepFun (fun q : Fin n × ℕ => X q.1 q.2) P)\n (hX_ident : ∀ a k, IdentDistrib (X a k) (X a 0) P P)\n (S : ℕ → Ω → Finset (Fin n))\n (hS0 : ∀ ω, S 0 ω = Finset.univ)\n (hSsub : ∀ t ω, S (t + 1) ω ⊆ S t ω)\n (hSrule : ∀ t ω a, a ∈ S t ω →\n (a ∈ S (t + 1) ω ↔\n ∀ b ∈ S t ω, empMeanT X b (t + 1) ω - empMeanT X a (t + 1) ω <\n 2 * confRadiusSE c n (t + 1) δ)),\n 1 - δ ≤ P.real {ω | ∃ T : ℕ,\n (∑ t ∈ Finset.range T, (S t ω).card : ℝ) ≤\n C * ∑ a ∈ Finset.univ.erase astar,\n Real.log (n / (δ * (p astar - p a))) / (p astar - p a) ^ 2\n ∧ ∀ t, T ≤ t → S t ω = {astar}} := by\n sorry\n\ntheorem median_elimination_PAC :\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} (hn : 0 < n) (p : Fin n → ℝ)\n (astar : Fin n) (hopt : ∀ a, p a ≤ p astar)\n (ε δ : ℝ) (hε : 0 < ε) (hδ : 0 < δ) (hδ1 : δ < 1)\n (L : ℕ) (hL : L = Nat.clog 2 n)\n (m : ℕ → ℕ)\n (hm : ∀ ℓ, ℓ < L →\n (1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ) ≤ m ℓ)\n (hm_le : ∀ ℓ, ℓ < L →\n (m ℓ : ℝ) ≤ (1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ) + 1)\n (X : Fin n → ℕ → ℕ → Ω → ℝ)\n (hX_meas : ∀ a ℓ k, Measurable (X a ℓ k))\n (hX_bound : ∀ a ℓ k, ∀ᵐ ω ∂P, X a ℓ k ω ∈ Set.Icc (0 : ℝ) 1)\n (hX_mean : ∀ a ℓ k, ∫ ω, X a ℓ k ω ∂P = p a)\n (hX_indep : iIndepFun (fun q : Fin n × ℕ × ℕ => X q.1 q.2.1 q.2.2) P)\n (hX_ident : ∀ a ℓ k, IdentDistrib (X a ℓ k) (X a 0 0) P P)\n (S : ℕ → Ω → Finset (Fin n)) (hS_meas : ∀ ℓ s, MeasurableSet {ω | S ℓ ω = s})\n (hS0 : ∀ ω, S 0 ω = Finset.univ)\n (hSnonempty : ∀ ℓ ω, (S ℓ ω).Nonempty)\n (hScard : ∀ ℓ ω, 2 * (S (ℓ + 1) ω).card ≤ (S ℓ ω).card + 1)\n (hScard_lo : ∀ ℓ ω, (S ℓ ω).card ≤ 2 * (S (ℓ + 1) ω).card)\n (median : ℕ → Ω → ℝ) (hmedian_meas : ∀ ℓ, Measurable (median ℓ))\n (hmedian_ge : ∀ ℓ ω, 2 * ((S ℓ ω).filter\n (fun a => median ℓ ω ≤ empMeanPhase X a ℓ (m ℓ) ω)).card ≥ (S ℓ ω).card)\n (hmedian_le : ∀ ℓ ω, 2 * ((S ℓ ω).filter\n (fun a => empMeanPhase X a ℓ (m ℓ) ω ≤ median ℓ ω)).card ≥ (S ℓ ω).card)\n (hSstep_lo : ∀ ℓ ω, (S ℓ ω).filter\n (fun a => median ℓ ω < empMeanPhase X a ℓ (m ℓ) ω) ⊆ S (ℓ + 1) ω)\n (hSstep_hi : ∀ ℓ ω, S (ℓ + 1) ω ⊆ (S ℓ ω).filter\n (fun a => median ℓ ω ≤ empMeanPhase X a ℓ (m ℓ) ω))\n (hS_adapted : ∀ ℓ ω ω',\n (∀ a j k, j ≤ ℓ → X a j k ω = X a j k ω') → S (ℓ + 1) ω = S (ℓ + 1) ω')\n (hmedian_adapted : ∀ ℓ ω ω',\n (∀ a j k, j ≤ ℓ → X a j k ω = X a j k ω') → median ℓ ω = median ℓ ω'),\n (1 - δ ≤ P.real {ω | ∀ a ∈ S L ω, epsOptimal p (p astar) ε a}) ∧\n (∀ ω, (∑ ℓ ∈ Finset.range L, (S ℓ ω).card * m ℓ : ℝ) ≤\n C * ((n / ε ^ 2) * Real.log (3 / δ) + n)) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace ResearchLevel\n\ndef epsOptimal {n : ℕ} (p : Fin n → ℝ) (pmax ε : ℝ) (a : Fin n) : Prop :=\n pmax - p a ≤ ε\n\nnoncomputable def empMean {n ℓ : ℕ} {Ω : Type*} (X : Fin n → Fin ℓ → Ω → ℝ)\n (ω : Ω) (a : Fin n) : ℝ :=\n (∑ k, X a k ω) / ℓ\n\nopen Classical in\n\nnoncomputable def naiveOutput {n ℓ : ℕ} [NeZero n] {Ω : Type*}\n (X : Fin n → Fin ℓ → Ω → ℝ) (ω : Ω) : Fin n :=\n (Finite.exists_max (empMean X ω)).choose\n\nnoncomputable def empMeanT {n : ℕ} {Ω : Type*} (X : Fin n → ℕ → Ω → ℝ)\n (a : Fin n) (t : ℕ) (ω : Ω) : ℝ :=\n (∑ k ∈ Finset.range t, X a k ω) / t\n\nnoncomputable def confRadiusSE (c : ℝ) (n t : ℕ) (δ : ℝ) : ℝ :=\n Real.sqrt (Real.log (c * n * (t : ℝ) ^ 2 / δ) / t)\n\nnoncomputable def phaseEps (ε : ℝ) : ℕ → ℝ\n | 0 => ε / 4\n | (ℓ + 1) => (3 / 4) * phaseEps ε ℓ\n\nnoncomputable def phaseDelta (δ : ℝ) : ℕ → ℝ\n | 0 => δ / 2\n | (ℓ + 1) => phaseDelta δ ℓ / 2\n\nnoncomputable def empMeanPhase {n : ℕ} {Ω : Type*} (X : Fin n → ℕ → ℕ → Ω → ℝ)\n (a : Fin n) (ℓ m : ℕ) (ω : Ω) : ℝ :=\n (∑ k ∈ Finset.range m, X a ℓ k ω) / m\n\nsection Helpers\n\nvariable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P]\n\n/-- Hoeffding's inequality for a sum of independent `[0,1]`-valued random variables with\ncommon mean `μ`. -/\ntheorem hoeffding_sum {ι : Type*} (Y : ι → Ω → ℝ) (μ : ℝ) (s : Finset ι)\n (hmeas : ∀ i, AEMeasurable (Y i) P)\n (hbound : ∀ i, ∀ᵐ ω ∂P, Y i ω ∈ Set.Icc (0:ℝ) 1)\n (hmean : ∀ i, ∫ ω, Y i ω ∂P = μ)\n (hindep : iIndepFun Y P) {η : ℝ} (hη : 0 ≤ η) :\n P.real {ω | η ≤ ∑ i ∈ s, (Y i ω - μ)} ≤ Real.exp (- (2 * η^2) / s.card) := by\n have hsub : ∀ i ∈ s, HasSubgaussianMGF (fun ω => Y i ω - μ) (1/4 : NNReal) P := by\n intro i _\n have := hasSubgaussianMGF_of_mem_Icc (X := Y i) (μ := P) (a := 0) (b := 1) (hmeas i) (hbound i)\n rw [hmean i] at this\n convert this using 2\n norm_num\n have hind2 : iIndepFun (fun i => fun ω => Y i ω - μ) P :=\n hindep.comp (fun (_ : ι) (x : ℝ) => x - μ) (fun i => by fun_prop)\n have := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hind2 hsub hη\n refine this.trans_eq ?_\n congr 1\n rw [Finset.sum_const]\n push_cast\n rw [nsmul_eq_mul]\n rcases eq_or_ne (s.card : ℝ) 0 with h | h\n · simp [h]\n · field_simp\n ring\n\n/-- Upper deviation bound for an empirical mean. -/\ntheorem emp_dev_upper {ι : Type*} (Y : ι → Ω → ℝ) (μ : ℝ) (s : Finset ι) (hs : s.Nonempty)\n (hmeas : ∀ i, AEMeasurable (Y i) P)\n (hbound : ∀ i, ∀ᵐ ω ∂P, Y i ω ∈ Set.Icc (0:ℝ) 1)\n (hmean : ∀ i, ∫ ω, Y i ω ∂P = μ)\n (hindep : iIndepFun Y P) {η : ℝ} (hη : 0 ≤ η) :\n P.real {ω | η ≤ (∑ i ∈ s, Y i ω) / s.card - μ} ≤ Real.exp (-2 * η^2 * s.card) := by\n have hc : (0:ℝ) < s.card := by exact_mod_cast Finset.card_pos.2 hs\n have hset : {ω | η ≤ (∑ i ∈ s, Y i ω) / s.card - μ}\n = {ω | (s.card : ℝ) * η ≤ ∑ i ∈ s, (Y i ω - μ)} := by\n ext ω\n simp only [Set.mem_setOf_eq, Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul]\n rw [le_sub_iff_add_le, le_div_iff₀ hc]\n constructor\n · intro h; nlinarith\n · intro h; nlinarith\n rw [hset]\n refine (hoeffding_sum Y μ s hmeas hbound hmean hindep (by positivity)).trans_eq ?_\n congr 1\n field_simp\n\n/-- Lower deviation bound for an empirical mean. -/\ntheorem emp_dev_lower {ι : Type*} (Y : ι → Ω → ℝ) (μ : ℝ) (s : Finset ι) (hs : s.Nonempty)\n (hmeas : ∀ i, AEMeasurable (Y i) P)\n (hbound : ∀ i, ∀ᵐ ω ∂P, Y i ω ∈ Set.Icc (0:ℝ) 1)\n (hmean : ∀ i, ∫ ω, Y i ω ∂P = μ)\n (hindep : iIndepFun Y P) {η : ℝ} (hη : 0 ≤ η) :\n P.real {ω | η ≤ μ - (∑ i ∈ s, Y i ω) / s.card} ≤ Real.exp (-2 * η^2 * s.card) := by\n have hc : (0:ℝ) < s.card := by exact_mod_cast Finset.card_pos.2 hs\n have key := emp_dev_upper (fun i ω => 1 - Y i ω) (1 - μ) s hs\n (fun i => (hmeas i).const_sub 1)\n (fun i => by\n filter_upwards [hbound i] with ω hω\n constructor <;> [linarith [hω.2]; linarith [hω.1]])\n (fun i => by\n have hint : Integrable (Y i) P := Integrable.of_mem_Icc 0 1 (hmeas i) (hbound i)\n rw [integral_sub (integrable_const 1) hint, hmean i, integral_const]\n simp)\n (hindep.comp (fun (_ : ι) (x : ℝ) => 1 - x) (fun i => by fun_prop)) hη\n refine le_trans (le_of_eq ?_) key\n congr 1\n ext ω\n simp only [Set.mem_setOf_eq, Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul, mul_one]\n rw [sub_div]\n field_simp\n constructor <;> intro h <;> nlinarith\n\ntheorem markov_count {ι : Type*} [Fintype ι] (q : ι → Ω → Prop) [∀ i ω, Decidable (q i ω)]\n (hA : ∀ i, MeasurableSet {ω | q i ω}) (k : ℝ) :\n k * P.real {ω | k ≤ (((Finset.univ : Finset ι).filter (fun i => q i ω)).card : ℝ)}\n ≤ ∑ i, P.real {ω | q i ω} := by\n set A : ι → Set Ω := fun i => {ω | q i ω} with hAdef\n set f : Ω → ℝ := fun ω => ∑ i, (A i).indicator (fun _ => (1:ℝ)) ω with hf\n have hfe : ∀ ω, f ω = (((Finset.univ : Finset ι).filter (fun i => q i ω)).card : ℝ) := by\n intro ω\n rw [hf]\n simp only [Set.indicator_apply]\n rw [Finset.card_filter]\n push_cast\n rfl\n have hnn : 0 ≤ᵐ[P] f := by\n filter_upwards with ω\n rw [hfe]\n positivity\n have hint : Integrable f P := by\n apply integrable_finset_sum\n intro i _\n exact (integrable_const (1:ℝ)).indicator (hA i)\n have hmk := mul_meas_ge_le_integral_of_nonneg hnn hint k\n have hI : ∫ ω, f ω ∂P = ∑ i, P.real (A i) := by\n rw [hf, integral_finset_sum]\n · refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [show A i = {ω | q i ω} from rfl, integral_indicator_const (1:ℝ) (hA i)]\n simp [smul_eq_mul]\n · intro i _\n exact (integrable_const (1:ℝ)).indicator (hA i)\n rw [hI] at hmk\n refine le_trans (le_of_eq ?_) hmk\n congr 2\n ext ω\n simp only [Set.mem_setOf_eq, hfe ω]\n\nend Helpers\n\n/-- `log x ≤ x / y + log y - 1` for positive `x, y`. -/\ntheorem log_le_div_add (x y : ℝ) (hx : 0 < x) (hy : 0 < y) :\n Real.log x ≤ x / y + Real.log y - 1 := by\n have h := Real.log_le_sub_one_of_pos (x := x / y) (by positivity)\n rw [Real.log_div (ne_of_gt hx) (ne_of_gt hy)] at h\n linarith\n\ntheorem sum_inv_sq_le (N : ℕ) : ∑ t ∈ Finset.range N, (1:ℝ)/((t:ℝ)+1)^2 ≤ 2 := by\n have key : ∀ M : ℕ, ∑ t ∈ Finset.range (M+1), (1:ℝ)/((t:ℝ)+1)^2 ≤ 2 - 1/((M:ℝ)+1) := by\n intro M\n induction M with\n | zero => norm_num\n | succ M ih =>\n rw [Finset.sum_range_succ]\n have hM : (0:ℝ) < (M:ℝ)+1 := by positivity\n have hM2 : (0:ℝ) < (M:ℝ)+2 := by positivity\n have hstep : (1:ℝ)/(((M:ℝ)+1)+1)^2 ≤ 1/((M:ℝ)+1) - 1/(((M:ℝ)+1)+1) := by\n have e : (1:ℝ)/((M:ℝ)+1) - 1/(((M:ℝ)+1)+1) = 1/(((M:ℝ)+1)*(((M:ℝ)+1)+1)) := by\n field_simp; ring\n rw [e]\n apply one_div_le_one_div_of_le (by positivity)\n nlinarith\n push_cast\n push_cast at ih\n linarith [ih, hstep]\n cases N with\n | zero => norm_num\n | succ M =>\n have := key M\n have h : (0:ℝ) < (M:ℝ)+1 := by positivity\n have : (0:ℝ) < 1/((M:ℝ)+1) := by positivity\n linarith [key M]\n\ntheorem key_time (c : ℝ) (hc : 4 < c) (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ < 1)\n (n : ℕ) (hn : 2 ≤ n) (Δ : ℝ) (hΔ : 0 < Δ) (hΔ1 : Δ ≤ 1) (u : ℕ)\n (hulb : (1000 * (1 + c)) * Real.log ((n:ℝ) / (δ * Δ)) / Δ ^ 2 ≤ (u:ℝ))\n (huub : (u:ℝ) ≤ (1000 * (1 + c)) * Real.log ((n:ℝ) / (δ * Δ)) / Δ ^ 2 + 1) :\n 1 ≤ u ∧ confRadiusSE c n u δ ≤ Δ / 4 ∧\n (u : ℝ) ≤ (1000 * (1 + c) + 2) * Real.log ((n:ℝ) / (δ * Δ)) / Δ ^ 2 := by\n have hlog2 : (0.6931471803 : ℝ) < Real.log 2 := Real.log_two_gt_d9\n have hlog2' : Real.log 2 < 0.6931471808 := Real.log_two_lt_d9\n have hn2 : (2:ℝ) ≤ (n:ℝ) := by exact_mod_cast hn\n have hnpos : (0:ℝ) < (n:ℝ) := by linarith\n have hΔ2 : (0:ℝ) < Δ^2 := by positivity\n have hΔ2le : Δ^2 ≤ 1 := by nlinarith\n set A : ℝ := -Real.log Δ with hA\n set B : ℝ := Real.log (n:ℝ) - Real.log δ with hB\n set L : ℝ := Real.log ((n:ℝ) / (δ * Δ)) with hLdef\n have hApos : 0 ≤ A := by\n rw [hA, neg_nonneg]; exact Real.log_nonpos (le_of_lt hΔ) hΔ1\n have hBpos : Real.log 2 ≤ B := by\n have h1 : Real.log 2 ≤ Real.log (n:ℝ) := Real.log_le_log (by norm_num) hn2\n have h2 : Real.log δ < 0 := Real.log_neg hδ hδ1\n rw [hB]; linarith\n have hLeq : L = A + B := by\n rw [hLdef, hA, hB, Real.log_div (by positivity) (by positivity),\n Real.log_mul (by positivity) (by positivity)]\n ring\n have hLpos : Real.log 2 ≤ L := by rw [hLeq]; linarith\n have hL0 : (0.69:ℝ) ≤ L := by linarith\n have hmain : (1:ℝ) ≤ (1000 * (1 + c)) * L / Δ^2 := by\n rw [le_div_iff₀ hΔ2]\n have h1 : (5000:ℝ) ≤ 1000*(1+c) := by linarith\n have h3 : (5000:ℝ) * 0.69 ≤ (1000*(1+c)) * L :=\n mul_le_mul h1 hL0 (by norm_num) (by linarith)\n linarith\n have hu1 : 1 ≤ u := by\n have : (1:ℝ) ≤ (u:ℝ) := le_trans hmain hulb\n exact_mod_cast this\n have hupos : (0:ℝ) < (u:ℝ) := by\n have : (1:ℝ) ≤ (u:ℝ) := le_trans hmain hulb\n linarith\n have hDu : (1000 * (1 + c)) * L ≤ Δ^2 * (u:ℝ) := by\n have h := (div_le_iff₀ hΔ2).1 hulb\n linarith\n refine ⟨hu1, ?_, ?_⟩\n · have hlogW : Real.log (c * (n:ℝ) * (u:ℝ)^2 / δ) = Real.log c + B + 2 * Real.log u := by\n rw [Real.log_div (by positivity) (by positivity), Real.log_mul (by positivity) (by positivity),\n Real.log_mul (by positivity) (by positivity), Real.log_pow]\n rw [hB]; push_cast; ring\n have hlogc : Real.log c ≤ c - 1 := Real.log_le_sub_one_of_pos (by linarith)\n have hlog64 : Real.log 64 < 4.16 := by\n have h64 : Real.log 64 = 6 * Real.log 2 := by\n rw [show (64:ℝ) = 2^(6:ℕ) by norm_num, Real.log_pow]; push_cast; ring\n rw [h64]; linarith\n have hlogu : Real.log u ≤ (u:ℝ) * Δ^2/64 + Real.log 64 + 2*A - 1 := by\n have h := log_le_div_add (u:ℝ) (64/Δ^2) hupos (by positivity)\n have h2 : Real.log (64/Δ^2) = Real.log 64 + 2*A := by\n rw [Real.log_div (by norm_num) (by positivity), Real.log_pow, hA]; push_cast; ring\n have h3 : (u:ℝ)/(64/Δ^2) = (u:ℝ)*Δ^2/64 := by field_simp\n rw [h2, h3] at h\n linarith\n have step1 : 32 * Real.log u ≤ Δ^2 * (u:ℝ) / 2 + 32 * Real.log 64 + 64 * A - 32 := by\n linarith only [hlogu]\n have stepA : 64 * A ≤ (500 * (1 + c)) * A := by\n have : (0:ℝ) ≤ (500 * (1+c) - 64) * A := mul_nonneg (by linarith) hApos\n linarith only [this]\n have stepB : 16 * Real.log c + 16 * B + 32 * Real.log 64 ≤ (500 * (1 + c)) * B := by\n have hB0 : (0.6931471803:ℝ) ≤ B := by linarith\n have hprod : (500*(1+c) - 16) * (0.6931471803:ℝ) ≤ (500*(1+c) - 16) * B :=\n mul_le_mul_of_nonneg_left hB0 (by linarith)\n linarith only [hprod, hlogc, hlog64, hc]\n have half : (500 * (1 + c)) * (A + B) ≤ Δ^2 * (u:ℝ) / 2 := by\n rw [hLeq] at hDu; linarith\n have hgoal : 16 * Real.log (c * (n:ℝ) * (u:ℝ)^2 / δ) ≤ Δ^2 * (u:ℝ) := by\n rw [hlogW]\n linarith only [step1, stepA, stepB, half]\n unfold confRadiusSE\n rw [show Δ/4 = Real.sqrt ((Δ/4)^2) by rw [Real.sqrt_sq (by positivity)]]\n apply Real.sqrt_le_sqrt\n rw [div_le_iff₀ hupos]\n linarith only [hgoal]\n · have h2 : (1:ℝ) ≤ 2 * L / Δ^2 := by\n rw [le_div_iff₀ hΔ2]\n linarith\n have heq : (1000 * (1 + c) + 2) * L / Δ^2 = (1000*(1+c))*L/Δ^2 + 2*L/Δ^2 := by ring\n rw [heq]\n linarith\n\ntheorem conf_prob (c : ℝ) (hc : 4 < c) (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ < 1)\n (n : ℕ) (hn : 1 ≤ n) (t : ℕ) (ht : 1 ≤ t) :\n Real.exp (-2 * (confRadiusSE c n t δ)^2 * t) ≤ δ / (c * n * (t:ℝ)^2) := by\n have hn1 : (1:ℝ) ≤ (n:ℝ) := by exact_mod_cast hn\n have ht1 : (1:ℝ) ≤ (t:ℝ) := by exact_mod_cast ht\n have htpos : (0:ℝ) < (t:ℝ) := by linarith\n set Z : ℝ := c * (n:ℝ) * (t:ℝ)^2 / δ with hZ\n have hZ1 : (1:ℝ) < Z := by\n rw [hZ, lt_div_iff₀ hδ]\n have ht2 : (1:ℝ) ≤ (t:ℝ)^2 := by nlinarith\n have h4 : (4:ℝ) * 1 * 1 ≤ c * (n:ℝ) * (t:ℝ)^2 :=\n mul_le_mul (mul_le_mul (le_of_lt hc) hn1 (by norm_num) (by linarith)) ht2 (by norm_num)\n (by positivity)\n linarith\n have hZpos : (0:ℝ) < Z := by linarith\n have hlogZ : 0 ≤ Real.log Z := Real.log_nonneg (le_of_lt hZ1)\n have hsq : (confRadiusSE c n t δ)^2 = Real.log Z / t := by\n unfold confRadiusSE\n rw [Real.sq_sqrt (by positivity)]\n rw [hsq]\n have harg : -2 * (Real.log Z / (t:ℝ)) * (t:ℝ) = -(Real.log Z + Real.log Z) := by\n field_simp; ring\n rw [harg, Real.exp_neg, Real.exp_add, Real.exp_log hZpos]\n rw [show δ / (c * (n:ℝ) * (t:ℝ)^2) = Z⁻¹ by rw [hZ]; field_simp]\n rw [inv_le_inv₀ (by positivity) hZpos]\n nlinarith\n\n\ntheorem phaseEps_eq (ε : ℝ) (ℓ : ℕ) : phaseEps ε ℓ = (3/4)^ℓ * (ε/4) := by\n induction ℓ with\n | zero => simp [phaseEps]\n | succ ℓ ih => rw [phaseEps, ih]; ring\n\ntheorem phaseDelta_eq (δ : ℝ) (ℓ : ℕ) : phaseDelta δ ℓ = δ / 2^(ℓ+1) := by\n induction ℓ with\n | zero => simp [phaseDelta]\n | succ ℓ ih => rw [phaseDelta, ih]; ring\n\ntheorem sum_phaseEps_le (ε : ℝ) (hε : 0 ≤ ε) (N : ℕ) :\n ∑ ℓ ∈ Finset.range N, phaseEps ε ℓ ≤ ε := by\n have key : ∀ N : ℕ, ∑ ℓ ∈ Finset.range N, phaseEps ε ℓ = ε * (1 - (3/4)^N) := by\n intro N\n induction N with\n | zero => simp\n | succ N ih =>\n rw [Finset.sum_range_succ, ih, phaseEps_eq]\n ring\n rw [key N]\n nlinarith [pow_nonneg (by norm_num : (0:ℝ) ≤ 3/4) N]\n\ntheorem geom_sum_89 (N : ℕ) : ∑ ℓ ∈ Finset.range N, ((8:ℝ)/9)^ℓ ≤ 9 := by\n have key : ∀ N : ℕ, ∑ ℓ ∈ Finset.range N, ((8:ℝ)/9)^ℓ = 9 - 9 * (8/9)^N := by\n intro N\n induction N with\n | zero => simp\n | succ N ih => rw [Finset.sum_range_succ, ih]; ring\n rw [key N]\n nlinarith [pow_nonneg (by norm_num : (0:ℝ) ≤ 8/9) N]\n\ntheorem geom_sum_89' (N : ℕ) : ∑ ℓ ∈ Finset.range N, ((ℓ:ℝ)+1) * ((8:ℝ)/9)^ℓ ≤ 81 := by\n have key : ∀ N : ℕ, ∑ ℓ ∈ Finset.range N, ((ℓ:ℝ)+1) * ((8:ℝ)/9)^ℓ\n ≤ 81 - (9*(N:ℝ)+81) * (8/9)^N := by\n intro N\n induction N with\n | zero => simp\n | succ N ih =>\n rw [Finset.sum_range_succ]\n have h : (81:ℝ) - (9*(N:ℝ)+81) * (8/9)^N + ((N:ℝ)+1) * (8/9)^N\n = 81 - (9*((N:ℝ)+1)+81) * (8/9)^(N+1) := by\n rw [pow_succ]; ring\n push_cast\n linarith [ih, h]\n have h2 := key N\n nlinarith [pow_nonneg (by norm_num : (0:ℝ) ≤ 8/9) N, Nat.cast_nonneg (α := ℝ) N]\n\ntheorem geom_sum_half (N : ℕ) : ∑ ℓ ∈ Finset.range N, ((1:ℝ)/2)^ℓ ≤ 2 := by\n have key : ∀ N : ℕ, ∑ ℓ ∈ Finset.range N, ((1:ℝ)/2)^ℓ = 2 - 2 * (1/2)^N := by\n intro N\n induction N with\n | zero => simp\n | succ N ih => rw [Finset.sum_range_succ, ih]; ring\n rw [key N]\n nlinarith [pow_nonneg (by norm_num : (0:ℝ) ≤ 1/2) N]\n\n/-- The purely combinatorial core of the median-elimination analysis. -/\ntheorem median_comb {n : ℕ} (p : Fin n → ℝ) (astar : Fin n) (ε : ℝ) (hε : 0 < ε)\n (L : ℕ) (Sc : ℕ → Finset (Fin n)) (med : ℕ → ℝ) (pm : Fin n → ℕ → ℝ)\n (hSnonempty : ∀ ℓ, (Sc ℓ).Nonempty)\n (hScard : ∀ ℓ, 2 * (Sc (ℓ+1)).card ≤ (Sc ℓ).card + 1)\n (hScard_lo : ∀ ℓ, (Sc ℓ).card ≤ 2 * (Sc (ℓ+1)).card)\n (hSstep_lo : ∀ ℓ, (Sc ℓ).filter (fun a => med ℓ < pm a ℓ) ⊆ Sc (ℓ+1))\n (hSstep_hi : ∀ ℓ, Sc (ℓ+1) ⊆ (Sc ℓ).filter (fun a => med ℓ ≤ pm a ℓ))\n (hcard_lo : ∀ ℓ, n ≤ 2^ℓ * (Sc ℓ).card)\n (hSLcard : (Sc L).card = 1)\n (hstar0 : astar ∈ Sc 0)\n (h1 : ∀ ℓ, ℓ < L → ¬ (phaseEps ε ℓ/2 ≤ p astar - pm astar ℓ))\n (h2 : ∀ ℓ, ℓ < L → (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ pm a ℓ - p a)).card : ℝ) < (n:ℝ)/(8*2^ℓ))\n (h3 : ∀ ℓ, ℓ < L → (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ p a - pm a ℓ)).card : ℝ) < (n:ℝ)/(8*2^ℓ)) :\n ∀ a ∈ Sc L, p astar - p a ≤ ε := by\n classical\n have hepsnn : ∀ ℓ, (0:ℝ) ≤ phaseEps ε ℓ := by\n intro ℓ; rw [phaseEps_eq]; positivity\n set σ : ℕ → ℝ := fun ℓ => ∑ j ∈ Finset.range ℓ, phaseEps ε j with hσdef\n have hσsucc : ∀ ℓ, σ (ℓ+1) = σ ℓ + phaseEps ε ℓ := by\n intro ℓ; simp [hσdef, Finset.sum_range_succ]\n have hσ0 : ∀ ℓ, (0:ℝ) ≤ σ ℓ := by\n intro ℓ\n exact Finset.sum_nonneg (fun j _ => hepsnn j)\n set Bs : ℕ → Finset (Fin n) := fun ℓ => (Sc ℓ).filter (fun a => ¬ (p astar - p a ≤ σ ℓ))\n with hBsdef\n have hsub : ∀ ℓ, Sc (ℓ+1) ⊆ Sc ℓ := fun ℓ => (hSstep_hi ℓ).trans (Finset.filter_subset _ _)\n have hNle : ∀ ℓ, (n:ℝ)/(8*2^ℓ) ≤ ((Sc ℓ).card : ℝ)/8 := by\n intro ℓ\n have h := hcard_lo ℓ\n have hR : (n:ℝ) ≤ 2^ℓ * ((Sc ℓ).card : ℝ) := by exact_mod_cast h\n have hp : (0:ℝ) < 2^ℓ := by positivity\n rw [div_le_div_iff₀ (by positivity) (by norm_num)]\n nlinarith\n have inv : ∀ ℓ, ℓ ≤ L → (astar ∈ Sc ℓ ∨ 4 * (Bs ℓ).card ≤ (Sc ℓ).card) := by\n intro ℓ\n induction ℓ with\n | zero => intro _; exact Or.inl hstar0\n | succ ℓ ih =>\n intro hle\n have hℓL : ℓ < L := by omega\n have ihh := ih (by omega)\n by_cases hstar : astar ∈ Sc (ℓ+1)\n · exact Or.inl hstar\n right\n have hs'pos : 1 ≤ (Sc (ℓ+1)).card := Finset.card_pos.2 (hSnonempty (ℓ+1))\n by_cases hA : ∃ g, g ∈ Sc ℓ ∧ g ∉ Sc (ℓ+1) ∧ (p astar - p g ≤ σ ℓ) ∧\n ¬ (phaseEps ε ℓ/2 ≤ p g - pm g ℓ)\n · -- Case A : an eliminated good arm which did not deviate downwards\n obtain ⟨g, hgS, hgout, hggood, hgdev⟩ := hA\n have hmedg : pm g ℓ ≤ med ℓ := by\n by_contra hcon\n push_neg at hcon\n exact hgout (hSstep_lo ℓ (Finset.mem_filter.2 ⟨hgS, hcon⟩))\n have hgd : p g - pm g ℓ < phaseEps ε ℓ/2 := not_le.1 hgdev\n have hBsub : Bs (ℓ+1) ⊆ (Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ pm a ℓ - p a) := by\n intro b hb\n rw [hBsdef] at hb\n simp only [Finset.mem_filter] at hb\n obtain ⟨hbS, hbbad⟩ := hb\n refine Finset.mem_filter.2 ⟨Finset.mem_univ _, ?_⟩\n by_contra hcon\n push_neg at hcon\n apply hbbad\n have hmedb : med ℓ ≤ pm b ℓ := (Finset.mem_filter.1 (hSstep_hi ℓ hbS)).2\n rw [hσsucc]\n linarith\n have hc1 : ((Bs (ℓ+1)).card : ℝ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ pm a ℓ - p a)).card : ℝ) := by\n exact_mod_cast Finset.card_le_card hBsub\n have hc2 := (hc1.trans_lt (h2 ℓ hℓL)).trans_le (hNle ℓ)\n have hc3 : ((Sc ℓ).card : ℝ) ≤ 2 * ((Sc (ℓ+1)).card : ℝ) := by\n exact_mod_cast hScard_lo ℓ\n have : (4 * (Bs (ℓ+1)).card : ℝ) ≤ ((Sc (ℓ+1)).card : ℝ) := by\n push_cast\n linarith\n exact_mod_cast this\n · -- Case B : every eliminated good arm deviated downwards\n push_neg at hA\n have hastar : astar ∉ Sc ℓ := by\n intro hmem\n exact h1 ℓ hℓL (hA astar hmem hstar (by simp [hσ0 ℓ]))\n have ihh' : 4 * (Bs ℓ).card ≤ (Sc ℓ).card := ihh.resolve_left hastar\n set H : Finset (Fin n) := (Sc ℓ).filter (fun a => p astar - p a ≤ σ ℓ) with hHdef\n have hHcard : H.card + (Bs ℓ).card = (Sc ℓ).card := by\n rw [hHdef, hBsdef]\n exact Finset.card_filter_add_card_filter_not _\n set E : Finset (Fin n) := H.filter (fun a => a ∉ Sc (ℓ+1)) with hEdef\n set H' : Finset (Fin n) := H.filter (fun a => a ∈ Sc (ℓ+1)) with hH'def\n have hHsplit : H'.card + E.card = H.card := by\n rw [hH'def, hEdef]\n exact Finset.card_filter_add_card_filter_not _\n have hEsub : E ⊆ (Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ p a - pm a ℓ) := by\n intro g hg\n rw [hEdef, hHdef] at hg\n simp only [Finset.mem_filter] at hg\n exact Finset.mem_filter.2 ⟨Finset.mem_univ _, hA g hg.1.1 hg.2 hg.1.2⟩\n have hdisj : Disjoint H' (Bs (ℓ+1)) := by\n rw [Finset.disjoint_left]\n intro a ha hb\n rw [hH'def, hHdef] at ha\n rw [hBsdef] at hb\n simp only [Finset.mem_filter] at ha hb\n exact hb.2 (le_trans ha.1.2 (by rw [hσsucc]; linarith [hepsnn ℓ]))\n have hunion : H' ∪ Bs (ℓ+1) ⊆ Sc (ℓ+1) := by\n refine Finset.union_subset ?_ ?_\n · intro a ha; rw [hH'def] at ha; exact (Finset.mem_filter.1 ha).2\n · intro a ha; rw [hBsdef] at ha; exact (Finset.mem_filter.1 ha).1\n have hcard3 : H'.card + (Bs (ℓ+1)).card ≤ (Sc (ℓ+1)).card := by\n have := Finset.card_le_card hunion\n rwa [Finset.card_union_of_disjoint hdisj] at this\n have hEcard : ((E).card : ℝ) ≤ ((Sc ℓ).card : ℝ)/8 := by\n have h := (Nat.cast_le (α := ℝ)).2 (Finset.card_le_card hEsub)\n exact (h.trans_lt (h3 ℓ hℓL)).le.trans (hNle ℓ)\n -- real arithmetic\n have e1 : (H.card : ℝ) + ((Bs ℓ).card : ℝ) = ((Sc ℓ).card : ℝ) := by exact_mod_cast hHcard\n have e2 : (H'.card : ℝ) + (E.card : ℝ) = (H.card : ℝ) := by exact_mod_cast hHsplit\n have e3 : (H'.card : ℝ) + ((Bs (ℓ+1)).card : ℝ) ≤ ((Sc (ℓ+1)).card : ℝ) := by\n exact_mod_cast hcard3\n have e4 : 4 * ((Bs ℓ).card : ℝ) ≤ ((Sc ℓ).card : ℝ) := by exact_mod_cast ihh'\n have e5 : 2 * ((Sc (ℓ+1)).card : ℝ) ≤ ((Sc ℓ).card : ℝ) + 1 := by\n exact_mod_cast hScard ℓ\n have e6 : (1:ℝ) ≤ ((Sc (ℓ+1)).card : ℝ) := by exact_mod_cast hs'pos\n have hzero : ((Bs (ℓ+1)).card : ℝ) < 1 := by linarith\n have : (Bs (ℓ+1)).card = 0 := by\n have : (Bs (ℓ+1)).card < 1 := by exact_mod_cast hzero\n omega\n rw [this]\n omega\n -- conclusion\n intro a ha\n have hεL : σ L ≤ ε := sum_phaseEps_le ε (le_of_lt hε) L\n rcases inv L le_rfl with hstar | hcard\n · have hae : a = astar := Finset.card_le_one.1 (le_of_eq hSLcard) a ha astar hstar\n rw [hae]\n simp\n linarith\n · have hB0 : (Bs L).card = 0 := by rw [hSLcard] at hcard; omega\n have hanot : a ∉ Bs L := by\n rw [Finset.card_eq_zero] at hB0\n rw [hB0]; simp\n rw [hBsdef] at hanot\n simp only [Finset.mem_filter, not_and, not_not] at hanot\n have := hanot ha\n linarith\n\n/-- Correctness of median elimination. The analysis uses only (i) deviation bounds for the\nfixed optimal arm `astar` and (ii) Markov bounds on the *number* of arms whose empirical mean\ndeviates; no conditioning on the (adaptively chosen) active set is required. -/\ntheorem median_correct {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} (hn : 0 < n) (p : Fin n → ℝ) (astar : Fin n)\n (ε δ : ℝ) (hε : 0 < ε) (hδ : 0 < δ) (hδ1 : δ < 1)\n (L : ℕ) (hL : L = Nat.clog 2 n) (m : ℕ → ℕ)\n (hm : ∀ ℓ, ℓ < L →\n (1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ) ≤ m ℓ)\n (X : Fin n → ℕ → ℕ → Ω → ℝ)\n (hX_meas : ∀ a ℓ k, Measurable (X a ℓ k))\n (hX_bound : ∀ a ℓ k, ∀ᵐ ω ∂P, X a ℓ k ω ∈ Set.Icc (0 : ℝ) 1)\n (hX_mean : ∀ a ℓ k, ∫ ω, X a ℓ k ω ∂P = p a)\n (hX_indep : iIndepFun (fun q : Fin n × ℕ × ℕ => X q.1 q.2.1 q.2.2) P)\n (S : ℕ → Ω → Finset (Fin n))\n (hS0 : ∀ ω, S 0 ω = Finset.univ)\n (hSnonempty : ∀ ℓ ω, (S ℓ ω).Nonempty)\n (hScard : ∀ ℓ ω, 2 * (S (ℓ + 1) ω).card ≤ (S ℓ ω).card + 1)\n (hScard_lo : ∀ ℓ ω, (S ℓ ω).card ≤ 2 * (S (ℓ + 1) ω).card)\n (median : ℕ → Ω → ℝ)\n (hSstep_lo : ∀ ℓ ω, (S ℓ ω).filter\n (fun a => median ℓ ω < empMeanPhase X a ℓ (m ℓ) ω) ⊆ S (ℓ + 1) ω)\n (hSstep_hi : ∀ ℓ ω, S (ℓ + 1) ω ⊆ (S ℓ ω).filter\n (fun a => median ℓ ω ≤ empMeanPhase X a ℓ (m ℓ) ω)) :\n 1 - δ ≤ P.real {ω | ∀ a ∈ S L ω, epsOptimal p (p astar) ε a} := by\n have hnR : (1:ℝ) ≤ (n:ℝ) := by exact_mod_cast hn\n have hnpos : (0:ℝ) < (n:ℝ) := by linarith\n have hepspos : ∀ ℓ, 0 < phaseEps ε ℓ := by\n intro ℓ; rw [phaseEps_eq]; positivity\n have hdeltapos : ∀ ℓ, 0 < phaseDelta δ ℓ := by\n intro ℓ; rw [phaseDelta_eq]; positivity\n have hdeltalt : ∀ ℓ, phaseDelta δ ℓ < 1 := by\n intro ℓ\n rw [phaseDelta_eq]\n have h1 : (1:ℝ) ≤ 2^(ℓ+1) := one_le_pow₀ (by norm_num)\n rw [div_lt_one (by positivity)]\n linarith\n have hlogpos : ∀ ℓ, 0 < Real.log (3 / phaseDelta δ ℓ) := by\n intro ℓ\n apply Real.log_pos\n rw [lt_div_iff₀ (hdeltapos ℓ)]\n linarith [hdeltalt ℓ]\n have hmpos : ∀ ℓ, ℓ < L → 0 < m ℓ := by\n intro ℓ hℓ\n have h := hm ℓ hℓ\n have h2 : (0:ℝ) < (1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ) := by\n have := hepspos ℓ\n have := hlogpos ℓ\n positivity\n have : (0:ℝ) < (m ℓ : ℝ) := lt_of_lt_of_le h2 h\n exact_mod_cast this\n have hcard_lo : ∀ ℓ ω, n ≤ 2^ℓ * (S ℓ ω).card := by\n intro ℓ ω\n induction ℓ with\n | zero => simp [hS0 ω]\n | succ ℓ ih =>\n have h1 : (S ℓ ω).card ≤ 2 * (S (ℓ+1) ω).card := hScard_lo ℓ ω\n have h2 : 2^ℓ * (S ℓ ω).card ≤ 2^ℓ * (2 * (S (ℓ+1) ω).card) := Nat.mul_le_mul_left _ h1\n have h3 : (2:ℕ)^(ℓ+1) * (S (ℓ+1) ω).card = 2^ℓ * (2 * (S (ℓ+1) ω).card) := by ring\n omega\n have hcard_hi : ∀ ℓ ω, 2^ℓ * (S ℓ ω).card + 1 ≤ n + 2^ℓ := by\n intro ℓ ω\n induction ℓ with\n | zero => simp [hS0 ω]\n | succ ℓ ih =>\n have h1 : 2 * (S (ℓ+1) ω).card ≤ (S ℓ ω).card + 1 := hScard ℓ ω\n have h2 : 2^ℓ * (2 * (S (ℓ+1) ω).card) ≤ 2^ℓ * ((S ℓ ω).card + 1) := Nat.mul_le_mul_left _ h1\n have h3 : (2:ℕ)^(ℓ+1) * (S (ℓ+1) ω).card = 2^ℓ * (2 * (S (ℓ+1) ω).card) := by ring\n have h4 : (2:ℕ)^ℓ * ((S ℓ ω).card + 1) = 2^ℓ * (S ℓ ω).card + 2^ℓ := by ring\n have h5 : (2:ℕ)^(ℓ+1) = 2 * 2^ℓ := by ring\n omega\n have hSLcard : ∀ ω, (S L ω).card = 1 := by\n intro ω\n have h1 := hcard_hi L ω\n have h2 : n ≤ 2^L := by rw [hL]; exact Nat.le_pow_clog (by norm_num) n\n have h3 : 0 < (S L ω).card := Finset.card_pos.2 (hSnonempty L ω)\n have h4 : (0:ℕ) < 2^L := Nat.two_pow_pos L\n nlinarith [h1, h2, h3, h4]\n -- measurability / independence\n have hmeasEMP : ∀ (a : Fin n) (ℓ : ℕ), Measurable (fun ω => empMeanPhase X a ℓ (m ℓ) ω) := by\n intro a ℓ\n unfold empMeanPhase\n exact (Finset.measurable_sum _ (fun k _ => hX_meas a ℓ k)).div_const _\n have hindepX : ∀ (a : Fin n) (ℓ : ℕ), iIndepFun (fun k : ℕ => X a ℓ k) P := by\n intro a ℓ\n have hinj : Function.Injective (fun k : ℕ => ((a, (ℓ, k)) : Fin n × ℕ × ℕ)) := by\n intro k k' h; simpa using h\n exact iIndepFun.precomp (g := fun k : ℕ => ((a, (ℓ, k)) : Fin n × ℕ × ℕ)) hinj hX_indep\n have hexpb : ∀ ℓ, ℓ < L →\n Real.exp (-2 * (phaseEps ε ℓ/2)^2 * ((m ℓ : ℕ):ℝ)) ≤ (phaseDelta δ ℓ/3)^2 := by\n intro ℓ hℓ\n have hd := hdeltapos ℓ\n have he := hepspos ℓ\n have hep : (0:ℝ) < (phaseEps ε ℓ/2)^2 := by positivity\n have h := hm ℓ hℓ\n have h2 : 2 * Real.log (3/phaseDelta δ ℓ) ≤ 2*(phaseEps ε ℓ/2)^2*((m ℓ:ℕ):ℝ) := by\n have hmul := mul_le_mul_of_nonneg_left h\n (le_of_lt (show (0:ℝ) < 2*(phaseEps ε ℓ/2)^2 by linarith))\n have he2 : 2*(phaseEps ε ℓ/2)^2 * ((1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ))\n = 2 * Real.log (3/phaseDelta δ ℓ) := by\n field_simp\n rw [he2] at hmul\n linarith\n have hpos3 : (0:ℝ) < 3 / phaseDelta δ ℓ := by positivity\n calc Real.exp (-2 * (phaseEps ε ℓ/2)^2 * ((m ℓ:ℕ):ℝ))\n ≤ Real.exp (-(Real.log (3/phaseDelta δ ℓ) + Real.log (3/phaseDelta δ ℓ))) := by\n apply Real.exp_le_exp.2; linarith\n _ = (phaseDelta δ ℓ/3)^2 := by\n rw [Real.exp_neg, Real.exp_add, Real.exp_log hpos3]\n field_simp\n have hdevU : ∀ ℓ, ℓ < L → ∀ a : Fin n,\n P.real {ω | phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a}\n ≤ (phaseDelta δ ℓ/3)^2 := by\n intro ℓ hℓ a\n have hmne : (Finset.range (m ℓ)).Nonempty := ⟨0, by simp [hmpos ℓ hℓ]⟩\n have h := emp_dev_upper (P := P) (fun k : ℕ => X a ℓ k) (p a) (Finset.range (m ℓ)) hmne\n (fun k => (hX_meas a ℓ k).aemeasurable) (fun k => hX_bound a ℓ k)\n (fun k => hX_mean a ℓ k) (hindepX a ℓ) (η := phaseEps ε ℓ/2)\n (by have := hepspos ℓ; linarith)\n simp only [Finset.card_range] at h\n exact h.trans (hexpb ℓ hℓ)\n have hdevL : ∀ ℓ, ℓ < L → ∀ a : Fin n,\n P.real {ω | phaseEps ε ℓ/2 ≤ p a - empMeanPhase X a ℓ (m ℓ) ω}\n ≤ (phaseDelta δ ℓ/3)^2 := by\n intro ℓ hℓ a\n have hmne : (Finset.range (m ℓ)).Nonempty := ⟨0, by simp [hmpos ℓ hℓ]⟩\n have h := emp_dev_lower (P := P) (fun k : ℕ => X a ℓ k) (p a) (Finset.range (m ℓ)) hmne\n (fun k => (hX_meas a ℓ k).aemeasurable) (fun k => hX_bound a ℓ k)\n (fun k => hX_mean a ℓ k) (hindepX a ℓ) (η := phaseEps ε ℓ/2)\n (by have := hepspos ℓ; linarith)\n simp only [Finset.card_range] at h\n exact h.trans (hexpb ℓ hℓ)\n -- Markov bounds on the number of deviating arms\n have hMarkovP : ∀ ℓ, ℓ < L →\n P.real {ω | (n:ℝ)/(8*2^ℓ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a)).card : ℝ)}\n ≤ 8*2^ℓ * (phaseDelta δ ℓ/3)^2 := by\n intro ℓ hℓ\n have hk : (0:ℝ) < (n:ℝ)/(8*2^ℓ) := by positivity\n have h1 := markov_count (P := P)\n (fun (a : Fin n) ω => phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a)\n (fun a => measurableSet_le measurable_const ((hmeasEMP a ℓ).sub_const _))\n ((n:ℝ)/(8*2^ℓ))\n have h2 : ∑ a : Fin n, P.real {ω | phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a}\n ≤ (n:ℝ) * (phaseDelta δ ℓ/3)^2 := by\n refine (Finset.sum_le_sum (fun a _ => hdevU ℓ hℓ a)).trans ?_\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n have h3 := h1.trans h2\n have heq : (n:ℝ)/(8*2^ℓ) * (8*2^ℓ * (phaseDelta δ ℓ/3)^2) = (n:ℝ) * (phaseDelta δ ℓ/3)^2 := by\n field_simp\n exact le_of_mul_le_mul_left (by rw [heq]; exact h3) hk\n have hMarkovM : ∀ ℓ, ℓ < L →\n P.real {ω | (n:ℝ)/(8*2^ℓ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ p a - empMeanPhase X a ℓ (m ℓ) ω)).card : ℝ)}\n ≤ 8*2^ℓ * (phaseDelta δ ℓ/3)^2 := by\n intro ℓ hℓ\n have hk : (0:ℝ) < (n:ℝ)/(8*2^ℓ) := by positivity\n have h1 := markov_count (P := P)\n (fun (a : Fin n) ω => phaseEps ε ℓ/2 ≤ p a - empMeanPhase X a ℓ (m ℓ) ω)\n (fun a => measurableSet_le measurable_const (measurable_const.sub (hmeasEMP a ℓ)))\n ((n:ℝ)/(8*2^ℓ))\n have h2 : ∑ a : Fin n, P.real {ω | phaseEps ε ℓ/2 ≤ p a - empMeanPhase X a ℓ (m ℓ) ω}\n ≤ (n:ℝ) * (phaseDelta δ ℓ/3)^2 := by\n refine (Finset.sum_le_sum (fun a _ => hdevL ℓ hℓ a)).trans ?_\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n have h3 := h1.trans h2\n have heq : (n:ℝ)/(8*2^ℓ) * (8*2^ℓ * (phaseDelta δ ℓ/3)^2) = (n:ℝ) * (phaseDelta δ ℓ/3)^2 := by\n field_simp\n exact le_of_mul_le_mul_left (by rw [heq]; exact h3) hk\n -- the bad event\n set W : ℕ → Set Ω := fun ℓ =>\n ({ω | phaseEps ε ℓ/2 ≤ p astar - empMeanPhase X astar ℓ (m ℓ) ω} ∪\n {ω | (n:ℝ)/(8*2^ℓ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a)).card : ℝ)}) ∪\n {ω | (n:ℝ)/(8*2^ℓ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ p a - empMeanPhase X a ℓ (m ℓ) ω)).card : ℝ)} with hWdef\n have hterm : ∀ ℓ : ℕ,\n (phaseDelta δ ℓ/3)^2 + 8*2^ℓ*(phaseDelta δ ℓ/3)^2 + 8*2^ℓ*(phaseDelta δ ℓ/3)^2\n ≤ (17/36)*δ^2*((1:ℝ)/2)^ℓ := by\n intro ℓ\n have hu : (1:ℝ) ≤ (2:ℝ)^ℓ := one_le_pow₀ (by norm_num)\n have hupos : (0:ℝ) < (2:ℝ)^ℓ := by positivity\n have hpd : (phaseDelta δ ℓ/3)^2 = δ^2/(36*((2:ℝ)^ℓ)^2) := by\n rw [phaseDelta_eq]\n field_simp\n ring\n have hhalf : ((1:ℝ)/2)^ℓ = 1/(2:ℝ)^ℓ := by rw [div_pow]; norm_num\n rw [hpd, hhalf]\n have expand : δ^2/(36*((2:ℝ)^ℓ)^2) + 8*2^ℓ*(δ^2/(36*((2:ℝ)^ℓ)^2))\n + 8*2^ℓ*(δ^2/(36*((2:ℝ)^ℓ)^2))\n = δ^2*(1+16*(2:ℝ)^ℓ)/(36*((2:ℝ)^ℓ)^2) := by\n field_simp\n ring\n rw [expand, div_le_iff₀ (by positivity)]\n have hrhs : 17/36*δ^2*(1/(2:ℝ)^ℓ)*(36*((2:ℝ)^ℓ)^2) = 17*δ^2*(2:ℝ)^ℓ := by\n field_simp\n rw [hrhs]\n nlinarith [mul_nonneg (sq_nonneg δ) (sub_nonneg.2 hu)]\n have hBadBound : P.real (⋃ ℓ ∈ Finset.range L, W ℓ) ≤ (17/18)*δ^2 := by\n refine (measureReal_biUnion_finset_le _ _).trans ?_\n have hstep : ∀ ℓ ∈ Finset.range L, P.real (W ℓ) ≤ (17/36)*δ^2*((1:ℝ)/2)^ℓ := by\n intro ℓ hℓ\n rw [Finset.mem_range] at hℓ\n have hu1 := measureReal_union_le\n (μ := P) ({ω | phaseEps ε ℓ/2 ≤ p astar - empMeanPhase X astar ℓ (m ℓ) ω} ∪\n {ω | (n:ℝ)/(8*2^ℓ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a)).card : ℝ)})\n ({ω | (n:ℝ)/(8*2^ℓ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ p a - empMeanPhase X a ℓ (m ℓ) ω)).card : ℝ)})\n have hu2 := measureReal_union_le\n (μ := P) ({ω | phaseEps ε ℓ/2 ≤ p astar - empMeanPhase X astar ℓ (m ℓ) ω})\n ({ω | (n:ℝ)/(8*2^ℓ) ≤ (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a)).card : ℝ)})\n have hA := hdevL ℓ hℓ astar\n have hB := hMarkovP ℓ hℓ\n have hC := hMarkovM ℓ hℓ\n have hT := hterm ℓ\n rw [hWdef]\n simp only\n linarith\n refine (Finset.sum_le_sum hstep).trans ?_\n rw [← Finset.mul_sum]\n have hg := geom_sum_half L\n nlinarith [sq_nonneg δ]\n have hcover : (Set.univ : Set Ω) ⊆\n {ω | ∀ a ∈ S L ω, epsOptimal p (p astar) ε a} ∪ (⋃ ℓ ∈ Finset.range L, W ℓ) := by\n intro ω _\n by_cases hb : ω ∈ (⋃ ℓ ∈ Finset.range L, W ℓ)\n · exact Or.inr hb\n left\n have hb' : ∀ ℓ, ℓ < L → ω ∉ W ℓ := by\n intro ℓ hℓ hmem\n exact hb (Set.mem_biUnion (Finset.mem_range.2 hℓ) hmem)\n have hb1 : ∀ ℓ, ℓ < L →\n ¬ (phaseEps ε ℓ/2 ≤ p astar - empMeanPhase X astar ℓ (m ℓ) ω) := by\n intro ℓ hℓ hcon\n exact hb' ℓ hℓ (Or.inl (Or.inl hcon))\n have hb2 : ∀ ℓ, ℓ < L → (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ empMeanPhase X a ℓ (m ℓ) ω - p a)).card : ℝ)\n < (n:ℝ)/(8*2^ℓ) := by\n intro ℓ hℓ\n exact not_le.1 (fun hcon => hb' ℓ hℓ (Or.inl (Or.inr hcon)))\n have hb3 : ∀ ℓ, ℓ < L → (((Finset.univ : Finset (Fin n)).filter\n (fun a => phaseEps ε ℓ/2 ≤ p a - empMeanPhase X a ℓ (m ℓ) ω)).card : ℝ)\n < (n:ℝ)/(8*2^ℓ) := by\n intro ℓ hℓ\n exact not_le.1 (fun hcon => hb' ℓ hℓ (Or.inr hcon))\n intro a ha\n exact median_comb p astar ε hε L (fun ℓ => S ℓ ω) (fun ℓ => median ℓ ω)\n (fun a ℓ => empMeanPhase X a ℓ (m ℓ) ω)\n (fun ℓ => hSnonempty ℓ ω) (fun ℓ => hScard ℓ ω) (fun ℓ => hScard_lo ℓ ω)\n (fun ℓ => hSstep_lo ℓ ω) (fun ℓ => hSstep_hi ℓ ω) (fun ℓ => hcard_lo ℓ ω)\n (hSLcard ω) (by show astar ∈ S 0 ω; rw [hS0 ω]; exact Finset.mem_univ _) hb1 hb2 hb3 a ha\n have huniv : (1:ℝ) ≤ P.real ({ω | ∀ a ∈ S L ω, epsOptimal p (p astar) ε a}\n ∪ (⋃ ℓ ∈ Finset.range L, W ℓ)) := by\n have := measureReal_mono (μ := P) hcover\n rwa [probReal_univ] at this\n have hsum := measureReal_union_le (μ := P)\n {ω | ∀ a ∈ S L ω, epsOptimal p (p astar) ε a} (⋃ ℓ ∈ Finset.range L, W ℓ)\n nlinarith [hBadBound, huniv, hsum]\n\n/-- The sample-complexity bound for median elimination. -/\ntheorem median_complexity {n : ℕ} (hn : 0 < n) (ε δ : ℝ) (hε : 0 < ε) (hδ : 0 < δ) (hδ1 : δ < 1)\n (L : ℕ) (hL : L = Nat.clog 2 n) (m : ℕ → ℕ)\n (hm_le : ∀ ℓ, ℓ < L →\n (m ℓ : ℝ) ≤ (1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ) + 1)\n (c : ℕ → ℕ) (hc0 : c 0 = n) (hcstep : ∀ ℓ, 2 * c (ℓ + 1) ≤ c ℓ + 1) :\n (∑ ℓ ∈ Finset.range L, (c ℓ : ℝ) * (m ℓ : ℝ))\n ≤ 20000 * (((n : ℝ) / ε ^ 2) * Real.log (3 / δ) + n) := by\n have hnR : (1:ℝ) ≤ (n:ℝ) := by exact_mod_cast hn\n have hnpos : (0:ℝ) < (n:ℝ) := by linarith\n have hcard_hi : ∀ ℓ, 2^ℓ * c ℓ + 1 ≤ n + 2^ℓ := by\n intro ℓ\n induction ℓ with\n | zero => simp [hc0]\n | succ ℓ ih =>\n have h1 : 2 * c (ℓ+1) ≤ c ℓ + 1 := hcstep ℓ\n have h2 : 2^ℓ * (2 * c (ℓ+1)) ≤ 2^ℓ * (c ℓ + 1) := Nat.mul_le_mul_left _ h1\n have h3 : (2:ℕ)^(ℓ+1) * c (ℓ+1) = 2^ℓ * (2 * c (ℓ+1)) := by ring\n have h4 : (2:ℕ)^ℓ * (c ℓ + 1) = 2^ℓ * c ℓ + 2^ℓ := by ring\n have h5 : (2:ℕ)^(ℓ+1) = 2 * 2^ℓ := by ring\n omega\n have hlog2 : (0.69:ℝ) < Real.log 2 := by linarith [Real.log_two_gt_d9]\n have hlog2' : Real.log 2 < 0.7 := by linarith [Real.log_two_lt_d9]\n have hAgt : Real.log 2 < Real.log (3/δ) := by\n apply Real.log_lt_log (by norm_num)\n rw [lt_div_iff₀ hδ]; linarith\n set A := Real.log (3/δ) with hAdef\n have hApos : (0.69:ℝ) < A := by linarith\n have hε2 : (0:ℝ) < ε^2 := by positivity\n have hne : (0:ℝ) ≤ (n:ℝ)/ε^2 := by positivity\n have hterm : ∀ ℓ ∈ Finset.range L,\n (c ℓ : ℝ) * (m ℓ : ℝ)\n ≤ 128 * ((n:ℝ)/ε^2) * A * (8/9)^ℓ\n + 128 * ((n:ℝ)/ε^2) * Real.log 2 * (((ℓ:ℝ)+1) * (8/9)^ℓ)\n + 2*(n:ℝ)*(1/2)^ℓ := by\n intro ℓ hℓ\n rw [Finset.mem_range] at hℓ\n have hn2 : 1 < n := by\n by_contra hcon\n have : n = 1 := by omega\n rw [hL, this, Nat.clog_one_right] at hℓ\n omega\n have hpow : (2:ℕ)^ℓ ≤ n := by\n have h1 : (2:ℕ)^(Nat.clog 2 n - 1) < n := Nat.pow_pred_clog_lt_self (by norm_num) hn2\n have h2 : ℓ ≤ Nat.clog 2 n - 1 := by omega\n have h3 : (2:ℕ)^ℓ ≤ 2^(Nat.clog 2 n - 1) := Nat.pow_le_pow_right (by norm_num) h2\n omega\n have hpowR : (0:ℝ) < (2:ℝ)^ℓ := by positivity\n have hcN : 2^ℓ * c ℓ ≤ 2*n := by\n have := hcard_hi ℓ\n omega\n have hc : (c ℓ : ℝ) ≤ 2*(n:ℝ)/2^ℓ := by\n rw [le_div_iff₀ hpowR]\n have : ((2:ℕ)^ℓ * c ℓ : ℕ) ≤ ((2*n : ℕ)) := hcN\n have h2 := (Nat.cast_le (α := ℝ)).2 this\n push_cast at h2\n linarith\n have hepsL : (1:ℝ) / (phaseEps ε ℓ / 2)^2 = (64/ε^2) * (16/9)^ℓ := by\n have h34 : (((3:ℝ)/4)^ℓ)^2 = ((9:ℝ)/16)^ℓ := by\n rw [← pow_mul, mul_comm ℓ 2, pow_mul]; norm_num\n have h169 : ((16:ℝ)/9)^ℓ = 1 / ((9:ℝ)/16)^ℓ := by\n rw [eq_div_iff (by positivity), ← mul_pow]; norm_num\n rw [phaseEps_eq, h169,\n show ((3:ℝ)/4)^ℓ * (ε/4)/2 = ((3:ℝ)/4)^ℓ * ε/8 by ring, div_pow, mul_pow, h34]\n have hpos : (0:ℝ) < ((9:ℝ)/16)^ℓ := by positivity\n field_simp\n norm_num\n have hlogL : Real.log (3 / phaseDelta δ ℓ) = A + ((ℓ:ℝ)+1) * Real.log 2 := by\n rw [phaseDelta_eq]\n have he : (3:ℝ) / (δ / 2^(ℓ+1)) = (3/δ) * 2^(ℓ+1) := by\n field_simp\n rw [he, Real.log_mul (by positivity) (by positivity), Real.log_pow, hAdef]\n push_cast\n ring\n have hmm : (m ℓ : ℝ) ≤ (64/ε^2) * (16/9)^ℓ * (A + ((ℓ:ℝ)+1)*Real.log 2) + 1 := by\n have h := hm_le ℓ hℓ\n rw [hepsL, hlogL] at h\n exact h\n have hcnn : (0:ℝ) ≤ (c ℓ : ℝ) := by positivity\n have hmnn : (0:ℝ) ≤ (m ℓ : ℝ) := by positivity\n have hrhs : (0:ℝ) ≤ (64/ε^2) * (16/9)^ℓ * (A + ((ℓ:ℝ)+1)*Real.log 2) + 1 := by\n have h1 : (0:ℝ) ≤ (64/ε^2) * (16/9)^ℓ := by positivity\n have h2 : (0:ℝ) ≤ A + ((ℓ:ℝ)+1)*Real.log 2 := by\n have : (0:ℝ) ≤ ((ℓ:ℝ)+1)*Real.log 2 := by positivity\n linarith\n nlinarith\n have hprod := mul_le_mul hc hmm hmnn (by positivity)\n refine hprod.trans (le_of_eq ?_)\n rw [show ((8:ℝ)/9)^ℓ = ((16:ℝ)/9)^ℓ / 2^ℓ by rw [← div_pow]; norm_num,\n show ((1:ℝ)/2)^ℓ = 1/2^ℓ by rw [div_pow]; norm_num]\n have hεne : ε ≠ 0 := ne_of_gt hε\n have h2ne : ((2:ℝ)^ℓ) ≠ 0 := by positivity\n field_simp\n ring\n calc (∑ ℓ ∈ Finset.range L, (c ℓ : ℝ) * (m ℓ : ℝ))\n ≤ ∑ ℓ ∈ Finset.range L, (128 * ((n:ℝ)/ε^2) * A * (8/9)^ℓ\n + 128 * ((n:ℝ)/ε^2) * Real.log 2 * (((ℓ:ℝ)+1) * (8/9)^ℓ)\n + 2*(n:ℝ)*(1/2)^ℓ) := Finset.sum_le_sum hterm\n _ = 128 * ((n:ℝ)/ε^2) * A * (∑ ℓ ∈ Finset.range L, ((8:ℝ)/9)^ℓ)\n + 128 * ((n:ℝ)/ε^2) * Real.log 2 * (∑ ℓ ∈ Finset.range L, (((ℓ:ℝ)+1) * ((8:ℝ)/9)^ℓ))\n + 2*(n:ℝ)*(∑ ℓ ∈ Finset.range L, ((1:ℝ)/2)^ℓ) := by\n rw [Finset.mul_sum, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib,\n ← Finset.sum_add_distrib]\n _ ≤ 128 * ((n:ℝ)/ε^2) * A * 9\n + 128 * ((n:ℝ)/ε^2) * Real.log 2 * 81\n + 2*(n:ℝ)*2 := by\n have g1 := geom_sum_89 L\n have g2 := geom_sum_89' L\n have g3 := geom_sum_half L\n have c1 : (0:ℝ) ≤ 128 * ((n:ℝ)/ε^2) * A := by nlinarith [hne, hApos]\n have c2 : (0:ℝ) ≤ 128 * ((n:ℝ)/ε^2) * Real.log 2 := by nlinarith [hne, hlog2]\n have c3 : (0:ℝ) ≤ 2*(n:ℝ) := by positivity\n linarith [mul_le_mul_of_nonneg_left g1 c1, mul_le_mul_of_nonneg_left g2 c2,\n mul_le_mul_of_nonneg_left g3 c3]\n _ ≤ 20000 * (((n:ℝ)/ε^2) * A + (n:ℝ)) := by\n have k1 : (0:ℝ) ≤ ((n:ℝ)/ε^2) * (A - 0.69) := mul_nonneg hne (by linarith)\n have k2 : (0:ℝ) ≤ ((n:ℝ)/ε^2) * (0.7 - Real.log 2) := mul_nonneg hne (by linarith)\n nlinarith [k1, k2, hne, hnpos]\n\ntheorem naive_PAC :\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} [NeZero n] (p : Fin n → ℝ)\n (astar : Fin n) (hopt : ∀ a, p a ≤ p astar)\n (ε δ : ℝ) (hε : 0 < ε) (hδ : 0 < δ) (hδ1 : δ < 1)\n (ℓ : ℕ) (hℓ : (2 / ε ^ 2) * Real.log (2 * n / δ) ≤ ℓ)\n (hℓ_le : (ℓ : ℝ) ≤ (2 / ε ^ 2) * Real.log (2 * n / δ) + 1)\n (X : Fin n → Fin ℓ → Ω → ℝ)\n (hX_meas : ∀ a k, Measurable (X a k))\n (hX_bound : ∀ a k, ∀ᵐ ω ∂P, X a k ω ∈ Set.Icc (0 : ℝ) 1)\n (hX_mean : ∀ a k, ∫ ω, X a k ω ∂P = p a)\n (hX_indep : iIndepFun (fun q : Fin n × Fin ℓ => X q.1 q.2) P)\n (hX_ident : ∀ a (k k' : Fin ℓ), ProbabilityTheory.IdentDistrib (X a k) (X a k') P P),\n (1 - δ ≤ P.real {ω | epsOptimal p (p astar) ε (naiveOutput X ω)}) ∧\n ((n : ℝ) * ℓ ≤ C * ((n / ε ^ 2) * Real.log (2 * n / δ) + n)) := by\n refine ⟨2, by norm_num, ?_⟩\n intro Ω _ P _ n _ p astar hopt ε δ hε hδ hδ1 ℓ hℓ hℓ_le X hX_meas hX_bound hX_mean hX_indep\n hX_ident\n have hn1 : (1:ℝ) ≤ (n:ℝ) := by\n have : 1 ≤ n := Nat.one_le_iff_ne_zero.2 (NeZero.ne n)\n exact_mod_cast this\n have hnpos : (0:ℝ) < (n:ℝ) := by linarith\n have hL : 0 < Real.log (2 * (n:ℝ) / δ) := by\n apply Real.log_pos\n rw [lt_div_iff₀ hδ]\n nlinarith\n have hε2 : (0:ℝ) < ε^2 := by positivity\n have hℓpos : (0:ℝ) < (ℓ:ℝ) := lt_of_lt_of_le (by positivity) hℓ\n have hℓ0 : 0 < ℓ := by exact_mod_cast hℓpos\n constructor\n · -- probability part\n have hne : (Finset.univ : Finset (Fin ℓ)).Nonempty := ⟨⟨0, hℓ0⟩, Finset.mem_univ _⟩\n have hexp : Real.exp (-2 * (ε/2)^2 * ((Finset.univ : Finset (Fin ℓ)).card : ℝ))\n ≤ δ/(2*(n:ℝ)) := by\n have hcard : ((Finset.univ : Finset (Fin ℓ)).card : ℝ) = (ℓ:ℝ) := by simp\n rw [hcard]\n have hid : Real.log (2 * (n:ℝ)/δ) = ((2/ε^2) * Real.log (2*(n:ℝ)/δ)) * (ε^2/2) := by\n field_simp\n have h1 : Real.log (2*(n:ℝ)/δ) ≤ 2*(ε/2)^2*(ℓ:ℝ) := by\n rw [hid]; nlinarith\n calc Real.exp (-2*(ε/2)^2*(ℓ:ℝ)) ≤ Real.exp (-Real.log (2*(n:ℝ)/δ)) := by\n apply Real.exp_le_exp.2; linarith\n _ = δ/(2*(n:ℝ)) := by\n rw [Real.exp_neg, Real.exp_log (by positivity), inv_div]\n have hdevU : ∀ a : Fin n, P.real {ω | ε/2 ≤ empMean X ω a - p a} ≤ δ/(2*(n:ℝ)) := by\n intro a\n have hinj : Function.Injective (fun k : Fin ℓ => ((a, k) : Fin n × Fin ℓ)) := by\n intro k k' h; simpa using h\n have hindep : iIndepFun (fun k : Fin ℓ => X a k) P :=\n iIndepFun.precomp (g := fun k : Fin ℓ => ((a, k) : Fin n × Fin ℓ)) hinj hX_indep\n have := emp_dev_upper (P := P) (fun k : Fin ℓ => X a k) (p a) Finset.univ hne\n (fun k => (hX_meas a k).aemeasurable) (fun k => hX_bound a k) (fun k => hX_mean a k)\n hindep (η := ε/2) (by positivity)\n refine le_trans (le_of_eq ?_) (this.trans hexp)\n congr 1\n ext ω\n simp [empMean]\n have hdevL : ∀ a : Fin n, P.real {ω | ε/2 ≤ p a - empMean X ω a} ≤ δ/(2*(n:ℝ)) := by\n intro a\n have hinj : Function.Injective (fun k : Fin ℓ => ((a, k) : Fin n × Fin ℓ)) := by\n intro k k' h; simpa using h\n have hindep : iIndepFun (fun k : Fin ℓ => X a k) P :=\n iIndepFun.precomp (g := fun k : Fin ℓ => ((a, k) : Fin n × Fin ℓ)) hinj hX_indep\n have := emp_dev_lower (P := P) (fun k : Fin ℓ => X a k) (p a) Finset.univ hne\n (fun k => (hX_meas a k).aemeasurable) (fun k => hX_bound a k) (fun k => hX_mean a k)\n hindep (η := ε/2) (by positivity)\n refine le_trans (le_of_eq ?_) (this.trans hexp)\n congr 1\n ext ω\n simp [empMean]\n set B : Set Ω := ⋃ a : Fin n,\n ({ω | ε/2 ≤ empMean X ω a - p a} ∪ {ω | ε/2 ≤ p a - empMean X ω a}) with hBdef\n have hBle : P.real B ≤ δ := by\n refine (measureReal_iUnion_fintype_le _).trans ?_\n have hterm : ∀ a : Fin n,\n P.real ({ω | ε/2 ≤ empMean X ω a - p a} ∪ {ω | ε/2 ≤ p a - empMean X ω a})\n ≤ δ/(n:ℝ) := by\n intro a\n refine (measureReal_union_le _ _).trans ?_\n have heq : δ/(2*(n:ℝ)) + δ/(2*(n:ℝ)) = δ/(n:ℝ) := by field_simp; ring\n linarith [hdevU a, hdevL a]\n refine (Finset.sum_le_sum (fun a _ => hterm a)).trans ?_\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n norm_num\n have hgood : Bᶜ ⊆ {ω | epsOptimal p (p astar) ε (naiveOutput X ω)} := by\n intro ω hω\n simp only [hBdef, Set.mem_compl_iff, Set.mem_iUnion, Set.mem_union, Set.mem_setOf_eq,\n not_exists, not_or, not_le] at hω\n have hmax : ∀ x, empMean X ω x ≤ empMean X ω (naiveOutput X ω) :=\n (Finite.exists_max (empMean X ω)).choose_spec\n have h1 := (hω astar).2\n have h2 := (hω (naiveOutput X ω)).1\n have h3 := hmax astar\n show p astar - p (naiveOutput X ω) ≤ ε\n linarith\n have hcompl : {ω | epsOptimal p (p astar) ε (naiveOutput X ω)}ᶜ ⊆ B :=\n Set.compl_subset_comm.1 hgood\n have hmono : P.real {ω | epsOptimal p (p astar) ε (naiveOutput X ω)}ᶜ ≤ P.real B :=\n measureReal_mono hcompl (measure_ne_top _ _)\n have huniv : P.real (Set.univ : Set Ω) ≤\n P.real {ω | epsOptimal p (p astar) ε (naiveOutput X ω)} +\n P.real ({ω | epsOptimal p (p astar) ε (naiveOutput X ω)}ᶜ) := by\n rw [← Set.union_compl_self {ω | epsOptimal p (p astar) ε (naiveOutput X ω)}]\n exact measureReal_union_le _ _\n rw [probReal_univ] at huniv\n linarith\n · -- complexity part\n have hid : (n:ℝ)*((2/ε^2)*Real.log (2*(n:ℝ)/δ)) = 2*(((n:ℝ)/ε^2)*Real.log (2*(n:ℝ)/δ)) := by\n field_simp\n nlinarith [mul_le_mul_of_nonneg_left hℓ_le (le_of_lt hnpos)]\n\ntheorem successive_elimination_PAC :\n ∀ (c : ℝ), 4 < c →\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} [NeZero n] (p : Fin n → ℝ)\n (astar : Fin n) (hopt : ∀ a, p a ≤ p astar)\n (hgap : ∀ a, a ≠ astar → p a < p astar)\n (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ < 1)\n (X : Fin n → ℕ → Ω → ℝ)\n (hX_meas : ∀ a k, Measurable (X a k))\n (hX_bound : ∀ a k, ∀ᵐ ω ∂P, X a k ω ∈ Set.Icc (0 : ℝ) 1)\n (hX_mean : ∀ a k, ∫ ω, X a k ω ∂P = p a)\n (hX_indep : iIndepFun (fun q : Fin n × ℕ => X q.1 q.2) P)\n (hX_ident : ∀ a k, IdentDistrib (X a k) (X a 0) P P)\n (S : ℕ → Ω → Finset (Fin n))\n (hS0 : ∀ ω, S 0 ω = Finset.univ)\n (hSsub : ∀ t ω, S (t + 1) ω ⊆ S t ω)\n (hSrule : ∀ t ω a, a ∈ S t ω →\n (a ∈ S (t + 1) ω ↔\n ∀ b ∈ S t ω, empMeanT X b (t + 1) ω - empMeanT X a (t + 1) ω <\n 2 * confRadiusSE c n (t + 1) δ)),\n 1 - δ ≤ P.real {ω | ∃ T : ℕ,\n (∑ t ∈ Finset.range T, (S t ω).card : ℝ) ≤\n C * ∑ a ∈ Finset.univ.erase astar,\n Real.log (n / (δ * (p astar - p a))) / (p astar - p a) ^ 2\n ∧ ∀ t, T ≤ t → S t ω = {astar}} := by\n intro c hc\n refine ⟨2 * (1000 * (1 + c) + 2), by nlinarith, ?_⟩\n intro Ω _ P _ n _ p astar hopt hgap δ hδ hδ1 X hX_meas hX_bound hX_mean hX_indep hX_ident\n S hS0 hSsub hSrule\n have hn1 : 1 ≤ n := Nat.one_le_iff_ne_zero.2 (NeZero.ne n)\n have hnR : (1:ℝ) ≤ (n:ℝ) := by exact_mod_cast hn1\n have hint : ∀ a k, Integrable (X a k) P := fun a k =>\n Integrable.of_mem_Icc 0 1 (hX_meas a k).aemeasurable (hX_bound a k)\n have hp0 : ∀ a, 0 ≤ p a := by\n intro a\n rw [← hX_mean a 0]\n exact integral_nonneg_of_ae (by filter_upwards [hX_bound a 0] with ω hω using hω.1)\n have hp1 : ∀ a, p a ≤ 1 := by\n intro a\n rw [← hX_mean a 0]\n have h := integral_mono_ae (hint a 0) (integrable_const (1:ℝ))\n (by filter_upwards [hX_bound a 0] with ω hω using hω.2)\n simpa using h\n have hindep : ∀ a : Fin n, iIndepFun (fun k : ℕ => X a k) P := by\n intro a\n have hinj : Function.Injective (fun k : ℕ => ((a, k) : Fin n × ℕ)) := by\n intro k k' h; simpa using h\n exact iIndepFun.precomp (g := fun k : ℕ => ((a, k) : Fin n × ℕ)) hinj hX_indep\n -- deviation bound for a single (t,a)\n have hBbound : ∀ (t : ℕ) (a : Fin n),\n P.real ({ω | confRadiusSE c n (t+1) δ ≤ empMeanT X a (t+1) ω - p a} ∪\n {ω | confRadiusSE c n (t+1) δ ≤ p a - empMeanT X a (t+1) ω})\n ≤ 2 * δ / (c * n * ((t:ℝ)+1)^2) := by\n intro t a\n have hne : (Finset.range (t+1)).Nonempty := ⟨0, by simp⟩\n have hη : 0 ≤ confRadiusSE c n (t+1) δ := Real.sqrt_nonneg _\n have hU := emp_dev_upper (P := P) (fun k : ℕ => X a k) (p a) (Finset.range (t+1)) hne\n (fun k => (hX_meas a k).aemeasurable) (fun k => hX_bound a k) (fun k => hX_mean a k)\n (hindep a) hη\n have hLo := emp_dev_lower (P := P) (fun k : ℕ => X a k) (p a) (Finset.range (t+1)) hne\n (fun k => (hX_meas a k).aemeasurable) (fun k => hX_bound a k) (fun k => hX_mean a k)\n (hindep a) hη\n simp only [Finset.card_range] at hU hLo\n have hcp := conf_prob c hc δ hδ hδ1 n hn1 (t+1) (by omega)\n push_cast at hcp\n refine (measureReal_union_le _ _).trans ?_\n have e1 : {ω | confRadiusSE c n (t+1) δ ≤ empMeanT X a (t+1) ω - p a}\n = {ω | confRadiusSE c n (t+1) δ ≤ (∑ i ∈ Finset.range (t+1), X a i ω) / ((t+1 : ℕ):ℝ)\n - p a} := rfl\n have e2 : {ω | confRadiusSE c n (t+1) δ ≤ p a - empMeanT X a (t+1) ω}\n = {ω | confRadiusSE c n (t+1) δ ≤ p a\n - (∑ i ∈ Finset.range (t+1), X a i ω) / ((t+1 : ℕ):ℝ)} := rfl\n rw [e1, e2]\n have hexp : Real.exp (-2 * (confRadiusSE c n (t+1) δ)^2 * ((t+1 : ℕ):ℝ))\n ≤ δ / (c * n * ((t:ℝ)+1)^2) := by push_cast; exact hcp\n have hU' := hU.trans hexp\n have hLo' := hLo.trans hexp\n have : 2 * δ / (c * (n:ℝ) * ((t:ℝ)+1)^2)\n = δ / (c * (n:ℝ) * ((t:ℝ)+1)^2) + δ / (c * (n:ℝ) * ((t:ℝ)+1)^2) := by ring\n rw [this]\n have hcast : ((t+1 : ℕ):ℝ) = (t:ℝ)+1 := by push_cast; ring\n rw [hcast] at hU' hLo'\n linarith [hU', hLo']\n -- union bound\n set Bs : ℕ → Fin n → Set Ω := fun t a =>\n ({ω | confRadiusSE c n (t+1) δ ≤ empMeanT X a (t+1) ω - p a} ∪\n {ω | confRadiusSE c n (t+1) δ ≤ p a - empMeanT X a (t+1) ω}) with hBsdef\n set Apart : ℕ → Set Ω := fun N => ⋃ t ∈ Finset.range N, ⋃ a : Fin n, Bs t a with hApartdef\n have hAmono : Monotone Apart := by\n intro N M hNM x hx\n simp only [hApartdef, Set.mem_iUnion, Finset.mem_range] at hx ⊢\n obtain ⟨t, htN, a, ha⟩ := hx\n exact ⟨t, lt_of_lt_of_le htN hNM, a, ha⟩\n have hcpos : (0:ℝ) < c := by linarith\n have hAb : ∀ N, P.real (Apart N) ≤ 4 * δ / c := by\n intro N\n have h1 : P.real (Apart N) ≤ ∑ t ∈ Finset.range N, P.real (⋃ a : Fin n, Bs t a) :=\n measureReal_biUnion_finset_le _ _\n have h2 : ∀ t : ℕ, P.real (⋃ a : Fin n, Bs t a) ≤ 2 * δ / (c * ((t:ℝ)+1)^2) := by\n intro t\n refine (measureReal_iUnion_fintype_le _).trans ?_\n refine (Finset.sum_le_sum (fun a _ => hBbound t a)).trans ?_\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n have hnne : (n:ℝ) ≠ 0 := by linarith\n have htne : ((t:ℝ)+1) ≠ 0 := by positivity\n field_simp\n norm_num\n have h3 : ∑ t ∈ Finset.range N, (2 * δ / (c * ((t:ℝ)+1)^2))\n = (2*δ/c) * ∑ t ∈ Finset.range N, (1:ℝ)/((t:ℝ)+1)^2 := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl (fun t _ => ?_)\n have htne : ((t:ℝ)+1) ≠ 0 := by positivity\n field_simp\n have h4 : (2*δ/c) * ∑ t ∈ Finset.range N, (1:ℝ)/((t:ℝ)+1)^2 ≤ (2*δ/c) * 2 :=\n mul_le_mul_of_nonneg_left (sum_inv_sq_le N) (by positivity)\n have h5 := (Finset.sum_le_sum (fun t (_ : t ∈ Finset.range N) => h2 t))\n rw [h3] at h5\n have : (2*δ/c)*2 = 4*δ/c := by ring\n linarith\n set Bad : Set Ω := ⋃ N, Apart N with hBaddef\n have hBadb : P.real Bad ≤ 4 * δ / c := by\n have hmu : P Bad = ⨆ N, P (Apart N) := hAmono.measure_iUnion\n have hle : ∀ N, P (Apart N) ≤ ENNReal.ofReal (4*δ/c) := by\n intro N\n exact (ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) (by positivity)).2 (hAb N)\n have hb : P Bad ≤ ENNReal.ofReal (4*δ/c) := by rw [hmu]; exact iSup_le hle\n have := ENNReal.toReal_mono (by finiteness) hb\n rwa [ENNReal.toReal_ofReal (by positivity)] at this\n -- deterministic part\n set u : Fin n → ℕ := fun a =>\n ⌈(1000*(1+c)) * Real.log ((n:ℝ)/(δ*(p astar - p a))) / (p astar - p a)^2⌉₊ with hudef\n have hkey : ∀ a : Fin n, a ≠ astar → 1 ≤ u a ∧\n confRadiusSE c n (u a) δ ≤ (p astar - p a)/4 ∧\n (u a : ℝ) ≤ (1000*(1+c)+2) * Real.log ((n:ℝ)/(δ*(p astar - p a))) / (p astar - p a)^2 := by\n intro a hne\n have hΔ : 0 < p astar - p a := by linarith [hgap a hne]\n have hΔ1 : p astar - p a ≤ 1 := by linarith [hp0 a, hp1 astar]\n have hn2 : 2 ≤ n := by\n have hnt : Nontrivial (Fin n) := ⟨⟨a, astar, hne⟩⟩\n have h := Fintype.one_lt_card (α := Fin n)\n simpa using h\n have hLpos : 0 < Real.log ((n:ℝ)/(δ*(p astar - p a))) := by\n apply Real.log_pos\n rw [lt_div_iff₀ (by positivity)]\n have : (2:ℝ) ≤ (n:ℝ) := by exact_mod_cast hn2\n nlinarith\n have hnn : (0:ℝ) ≤ (1000*(1+c)) * Real.log ((n:ℝ)/(δ*(p astar - p a))) / (p astar - p a)^2 := by\n have : (0:ℝ) < 1000*(1+c) := by linarith\n positivity\n exact key_time c hc δ hδ hδ1 n hn2 _ hΔ hΔ1 (u a) (Nat.le_ceil _)\n (Nat.ceil_lt_add_one hnn).le\n have hdet : Badᶜ ⊆ {ω | ∃ T : ℕ,\n (∑ t ∈ Finset.range T, (S t ω).card : ℝ) ≤\n (2 * (1000 * (1 + c) + 2)) * ∑ a ∈ Finset.univ.erase astar,\n Real.log (n / (δ * (p astar - p a))) / (p astar - p a) ^ 2\n ∧ ∀ t, T ≤ t → S t ω = {astar}} := by\n intro ω hω\n have hdev : ∀ (t : ℕ) (a : Fin n),\n empMeanT X a (t+1) ω - p a < confRadiusSE c n (t+1) δ ∧\n p a - empMeanT X a (t+1) ω < confRadiusSE c n (t+1) δ := by\n intro t a\n have hnot : ω ∉ Bs t a := by\n intro hmem\n refine hω ?_\n simp only [hBaddef, Set.mem_iUnion]\n refine ⟨t+1, ?_⟩\n simp only [hApartdef, Set.mem_iUnion, Finset.mem_range]\n exact ⟨t, Nat.lt_succ_self t, a, hmem⟩\n simp only [hBsdef, Set.mem_union, Set.mem_setOf_eq, not_or, not_le] at hnot\n exact hnot\n have hstar : ∀ t, astar ∈ S t ω := by\n intro t\n induction t with\n | zero => rw [hS0]; exact Finset.mem_univ _\n | succ t ih =>\n rw [hSrule t ω astar ih]\n intro b hb\n have h1 := (hdev t b).1\n have h2 := (hdev t astar).2\n have h3 := hopt b\n linarith\n have hSmono : ∀ t t', t ≤ t' → S t' ω ⊆ S t ω := by\n have key : ∀ (t d : ℕ), S (t+d) ω ⊆ S t ω := by\n intro t d\n induction d with\n | zero => exact subset_rfl\n | succ d ih =>\n have he : t + (d+1) = (t+d)+1 := by ring\n rw [he]\n exact (hSsub (t+d) ω).trans ih\n intro t t' h\n obtain ⟨d, rfl⟩ := Nat.exists_eq_add_of_le h\n exact key t d\n have hout : ∀ a : Fin n, a ≠ astar → ∀ t, u a ≤ t → a ∉ S t ω := by\n intro a hne t ht\n obtain ⟨k1, hk2, hk3⟩ := hkey a hne\n obtain ⟨v, hv⟩ : ∃ v, u a = v + 1 := ⟨u a - 1, by omega⟩\n rw [hv] at hk2\n have hnotin : a ∉ S (v+1) ω := by\n by_cases hmem : a ∈ S v ω\n · intro hcon\n have h := (hSrule v ω a hmem).1 hcon astar (hstar v)\n have h1 := (hdev v astar).2\n have h2 := (hdev v a).1\n linarith\n · exact fun hcon => hmem (hSsub v ω hcon)\n rw [hv] at ht\n intro hcon\n exact hnotin (hSmono (v+1) t ht hcon)\n refine ⟨(Finset.univ.erase astar).sup u, ?_, ?_⟩\n · set T : ℕ := (Finset.univ.erase astar).sup u with hTdef\n have e1 : ∀ t, (S t ω).card = ∑ a : Fin n, (if a ∈ S t ω then 1 else 0) := by\n intro t; simp [Finset.sum_ite_mem]\n have e2 : ∑ t ∈ Finset.range T, (S t ω).card\n = ∑ a : Fin n, ((Finset.range T).filter (fun t => a ∈ S t ω)).card := by\n simp_rw [e1]\n rw [Finset.sum_comm]\n exact Finset.sum_congr rfl (fun a _ => (Finset.card_filter _ _).symm)\n have e3 : ∀ a : Fin n, a ≠ astar →\n ((Finset.range T).filter (fun t => a ∈ S t ω)).card ≤ u a := by\n intro a hne\n have hsub : (Finset.range T).filter (fun t => a ∈ S t ω) ⊆ Finset.range (u a) := by\n intro t htt\n simp only [Finset.mem_filter, Finset.mem_range] at htt ⊢\n by_contra hcon\n exact hout a hne t (by omega) htt.2\n calc ((Finset.range T).filter (fun t => a ∈ S t ω)).card\n ≤ (Finset.range (u a)).card := Finset.card_le_card hsub\n _ = u a := Finset.card_range _\n have e4 : ((Finset.range T).filter (fun t => astar ∈ S t ω)).card ≤ T := by\n calc ((Finset.range T).filter (fun t => astar ∈ S t ω)).card\n ≤ (Finset.range T).card := Finset.card_le_card (Finset.filter_subset _ _)\n _ = T := Finset.card_range _\n have e5 : T ≤ ∑ a ∈ Finset.univ.erase astar, u a := by\n apply Finset.sup_le\n intro a ha\n exact Finset.single_le_sum (fun i _ => Nat.zero_le _) ha\n have e6 : ∑ a ∈ Finset.univ.erase astar,\n ((Finset.range T).filter (fun t => a ∈ S t ω)).card\n ≤ ∑ a ∈ Finset.univ.erase astar, u a :=\n Finset.sum_le_sum (fun a ha => e3 a (Finset.mem_erase.1 ha).1)\n have eNat : ∑ t ∈ Finset.range T, (S t ω).card\n ≤ 2 * ∑ a ∈ Finset.univ.erase astar, u a := by\n rw [e2, ← Finset.add_sum_erase Finset.univ _ (Finset.mem_univ astar)]\n omega\n have hfin : ∑ a ∈ Finset.univ.erase astar, ((u a : ℝ))\n ≤ ∑ a ∈ Finset.univ.erase astar,\n ((1000*(1+c)+2) * Real.log ((n:ℝ)/(δ*(p astar - p a))) / (p astar - p a)^2) :=\n Finset.sum_le_sum (fun a ha => (hkey a (Finset.mem_erase.1 ha).1).2.2)\n have hpull : ∑ a ∈ Finset.univ.erase astar,\n ((1000*(1+c)+2) * Real.log ((n:ℝ)/(δ*(p astar - p a))) / (p astar - p a)^2)\n = (1000*(1+c)+2) * ∑ a ∈ Finset.univ.erase astar,\n (Real.log ((n:ℝ)/(δ*(p astar - p a))) / (p astar - p a)^2) := by\n rw [Finset.mul_sum]; exact Finset.sum_congr rfl (fun a _ => by ring)\n have eR : (∑ t ∈ Finset.range T, ((S t ω).card : ℝ))\n ≤ 2 * ∑ a ∈ Finset.univ.erase astar, ((u a : ℝ)) := by\n have := (Nat.cast_le (α := ℝ)).2 eNat\n push_cast at this\n exact this\n rw [hpull] at hfin\n calc (∑ t ∈ Finset.range T, ((S t ω).card : ℝ))\n ≤ 2 * ∑ a ∈ Finset.univ.erase astar, ((u a : ℝ)) := eR\n _ ≤ 2 * ((1000*(1+c)+2) * ∑ a ∈ Finset.univ.erase astar,\n (Real.log ((n:ℝ)/(δ*(p astar - p a))) / (p astar - p a)^2)) := by linarith\n _ = (2 * (1000 * (1 + c) + 2)) * ∑ a ∈ Finset.univ.erase astar,\n Real.log ((n:ℝ) / (δ * (p astar - p a))) / (p astar - p a) ^ 2 := by ring\n · intro t ht\n apply Finset.eq_singleton_iff_unique_mem.2\n refine ⟨hstar t, ?_⟩\n intro x hx\n by_contra hne\n exact hout x hne t\n (le_trans (Finset.le_sup (Finset.mem_erase.2 ⟨hne, Finset.mem_univ _⟩)) ht) hx\n -- conclusion\n set G : Set Ω := {ω | ∃ T : ℕ,\n (∑ t ∈ Finset.range T, (S t ω).card : ℝ) ≤\n (2 * (1000 * (1 + c) + 2)) * ∑ a ∈ Finset.univ.erase astar,\n Real.log (n / (δ * (p astar - p a))) / (p astar - p a) ^ 2\n ∧ ∀ t, T ≤ t → S t ω = {astar}} with hGdef\n have hcompl : Gᶜ ⊆ Bad := Set.compl_subset_comm.1 hdet\n have hmono2 : P.real Gᶜ ≤ P.real Bad := measureReal_mono hcompl (measure_ne_top _ _)\n have huniv : P.real (Set.univ : Set Ω) ≤ P.real G + P.real Gᶜ := by\n rw [← Set.union_compl_self G]\n exact measureReal_union_le _ _\n rw [probReal_univ] at huniv\n have hlast : 4*δ/c ≤ δ := by rw [div_le_iff₀ hcpos]; nlinarith\n linarith\n\n\ntheorem median_elimination_PAC :\n ∃ C : ℝ, 0 < C ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} (hn : 0 < n) (p : Fin n → ℝ)\n (astar : Fin n) (hopt : ∀ a, p a ≤ p astar)\n (ε δ : ℝ) (hε : 0 < ε) (hδ : 0 < δ) (hδ1 : δ < 1)\n (L : ℕ) (hL : L = Nat.clog 2 n)\n (m : ℕ → ℕ)\n (hm : ∀ ℓ, ℓ < L →\n (1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ) ≤ m ℓ)\n (hm_le : ∀ ℓ, ℓ < L →\n (m ℓ : ℝ) ≤ (1 / (phaseEps ε ℓ / 2) ^ 2) * Real.log (3 / phaseDelta δ ℓ) + 1)\n (X : Fin n → ℕ → ℕ → Ω → ℝ)\n (hX_meas : ∀ a ℓ k, Measurable (X a ℓ k))\n (hX_bound : ∀ a ℓ k, ∀ᵐ ω ∂P, X a ℓ k ω ∈ Set.Icc (0 : ℝ) 1)\n (hX_mean : ∀ a ℓ k, ∫ ω, X a ℓ k ω ∂P = p a)\n (hX_indep : iIndepFun (fun q : Fin n × ℕ × ℕ => X q.1 q.2.1 q.2.2) P)\n (hX_ident : ∀ a ℓ k, IdentDistrib (X a ℓ k) (X a 0 0) P P)\n (S : ℕ → Ω → Finset (Fin n)) (hS_meas : ∀ ℓ s, MeasurableSet {ω | S ℓ ω = s})\n (hS0 : ∀ ω, S 0 ω = Finset.univ)\n (hSnonempty : ∀ ℓ ω, (S ℓ ω).Nonempty)\n (hScard : ∀ ℓ ω, 2 * (S (ℓ + 1) ω).card ≤ (S ℓ ω).card + 1)\n (hScard_lo : ∀ ℓ ω, (S ℓ ω).card ≤ 2 * (S (ℓ + 1) ω).card)\n (median : ℕ → Ω → ℝ) (hmedian_meas : ∀ ℓ, Measurable (median ℓ))\n (hmedian_ge : ∀ ℓ ω, 2 * ((S ℓ ω).filter\n (fun a => median ℓ ω ≤ empMeanPhase X a ℓ (m ℓ) ω)).card ≥ (S ℓ ω).card)\n (hmedian_le : ∀ ℓ ω, 2 * ((S ℓ ω).filter\n (fun a => empMeanPhase X a ℓ (m ℓ) ω ≤ median ℓ ω)).card ≥ (S ℓ ω).card)\n (hSstep_lo : ∀ ℓ ω, (S ℓ ω).filter\n (fun a => median ℓ ω < empMeanPhase X a ℓ (m ℓ) ω) ⊆ S (ℓ + 1) ω)\n (hSstep_hi : ∀ ℓ ω, S (ℓ + 1) ω ⊆ (S ℓ ω).filter\n (fun a => median ℓ ω ≤ empMeanPhase X a ℓ (m ℓ) ω))\n (hS_adapted : ∀ ℓ ω ω',\n (∀ a j k, j ≤ ℓ → X a j k ω = X a j k ω') → S (ℓ + 1) ω = S (ℓ + 1) ω')\n (hmedian_adapted : ∀ ℓ ω ω',\n (∀ a j k, j ≤ ℓ → X a j k ω = X a j k ω') → median ℓ ω = median ℓ ω'),\n (1 - δ ≤ P.real {ω | ∀ a ∈ S L ω, epsOptimal p (p astar) ε a}) ∧\n (∀ ω, (∑ ℓ ∈ Finset.range L, (S ℓ ω).card * m ℓ : ℝ) ≤\n C * ((n / ε ^ 2) * Real.log (3 / δ) + n)) := by\n refine ⟨20000, by norm_num, ?_⟩\n intro Ω _ P _ n hn p astar hopt ε δ hε hδ hδ1 L hL m hm hm_le X hX_meas hX_bound hX_mean\n hX_indep hX_ident S hS_meas hS0 hSnonempty hScard hScard_lo median hmedian_meas\n hmedian_ge hmedian_le hSstep_lo hSstep_hi hS_adapted hmedian_adapted\n refine ⟨median_correct P hn p astar ε δ hε hδ hδ1 L hL m hm X hX_meas hX_bound hX_mean\n hX_indep S hS0 hSnonempty hScard hScard_lo median hSstep_lo hSstep_hi, ?_⟩\n intro ω\n exact median_complexity hn ε δ hε hδ hδ1 L hL m hm_le (fun ℓ => (S ℓ ω).card)\n (by show (S 0 ω).card = n; rw [hS0 ω]; simp) (fun ℓ => hScard ℓ ω)\n\nend ResearchLevel\n"} +{"id": "v25-23-0422", "source": "Research-level", "targets": [{"label": "Lemma 3.1", "decls": ["lemma3_1"], "statement": "Lemma 3.1 (Key self-boundedness properties). Consider the setup of Section 2 and let Assumptions 1-2 hold. Further assume the loss is self-bounded as per Assumption 4. Then, the objective satisfies the following self-boundedness properties for its Gradient and Hessian:\n\n1. Self-bounded gradient: $\\begin{array}{r}{\\left\\|\\nabla\\widehat{F}_{i}(w)\\right\\|\\leq\\ell R\\widehat{F}_{i}(w),\\forall i\\in [n].}\\end{array}$\n\n2. Self-bounded weak convexity: $\\begin{array}{r}{\\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}\\widehat{F}(w)\\right)\\geq-\\frac{L R^{2}}{\\sqrt{m}}\\widehat{F}(w)}\\end{array}$", "context_ids": ["v25-23-0422:ctx1", "v25-23-0422:ctx2", "v25-23-0422:ctx3", "v25-23-0422:ctx4", "v25-23-0422:ctx5", "v25-23-0422:ctx6", "v25-23-0422:ctx7", "v25-23-0422:ctx9", "v25-23-0422:ctx10", "v25-23-0422:ctx11", "v25-23-0422:ctx13"], "sibling_refs": [], "topic_domain": "Deep Learning Theory", "topic_subtopic": "Training Dynamics & Implicit Bias"}, {"label": "Theorem 3.2", "decls": ["thm3_2"], "statement": "Theorem 3.2 (Training loss – General bound). Suppose Assumptions $1 \\mathrm{-}\\mathit{4}$ hold. Fix any training horizon $T \\geq 0$ and any step-size $\\eta \\leq 1 / L_{\\widehat{F}}$ where $L_{\\widehat{F}}$ is the objective's smoothness parameter. Assume any w $\\in \\mathbb{R}^{d^{\\prime}}$ and hidden-layer width m such that $\\| w - w_{0}\\|^{2}\\ge$ max $\\{\\eta T\\widehat{F}(w),\\eta\\widehat{F}(w_{0})\\}$ and $m\\geq 18^{2}L^{2}R^{4}\\Vert w-w_{0}\\Vert^{4}$. Then, the training loss and the parameters' norm satisfy\n\n$$\n\\begin{array}{r l}&{\\widehat{F}(w_{T})\\ \\leq\\ \\displaystyle\\frac{1}{T}\\sum_{t=1}^{T}\\widehat{F}(w_{t})\\ \\leq\\ 2\\widehat{F}(w)+\\frac{5\\|w-w_{0}\\|^{2}}{2\\eta T},}\\\\ &{\\forall t\\in [T]\\ :\\ \\|w_{t}-w_{0}\\|\\ \\leq\\ 4\\|w-w_{0}\\|.}\\end{array}\\tag{5}\n$$", "context_ids": ["v25-23-0422:ctx1", "v25-23-0422:ctx2", "v25-23-0422:ctx3", "v25-23-0422:ctx4", "v25-23-0422:ctx5", "v25-23-0422:ctx6", "v25-23-0422:ctx7", "v25-23-0422:ctx8", "v25-23-0422:ctx9", "v25-23-0422:ctx11", "v25-23-0422:ctx13", "v25-23-0422:ctx14", "v25-23-0422:ctx15"], "sibling_refs": [], "topic_domain": "Deep Learning Theory", "topic_subtopic": "Training Dynamics & Implicit Bias"}, {"label": "Theorem 3.3", "decls": ["thm3_3"], "statement": "Theorem 3.3 (Training loss under interpolation). Let Assumptions 1-5 hold. Let $\\eta \\leq$ min $\\begin{array}{r}{\\{\\frac{1}{L_{\\widehat{F}}},g(1)^{2},\\frac{g(1)^{2}}{\\widehat{F}(w_{0})}\\}}\\end{array}$ and assume the width satisfies $m\\geq 18^{2}L^{2}R^{4}g(\\frac{1}{T})^{4}$ for a fixed training horizon T such that $\\varepsilon = 1 / T$ is small enough for Assumption 5 to apply. Then,\n\n$$\n\\widehat{F}(w_{T})\\leq\\frac{2}{T}+\\frac{5g(\\frac{1}{T})^{2}}{2\\eta T},\\tag{6}\n$$\n\n$$\n\\forall t\\in [T]\\ :\\ \\|w_{t}-w_{0}\\|\\ \\leq\\ 4g(\\frac{1}{T}).\n$$", "context_ids": ["v25-23-0422:ctx1", "v25-23-0422:ctx2", "v25-23-0422:ctx3", "v25-23-0422:ctx4", "v25-23-0422:ctx5", "v25-23-0422:ctx6", "v25-23-0422:ctx7", "v25-23-0422:ctx8", "v25-23-0422:ctx11", "v25-23-0422:ctx12", "v25-23-0422:ctx13", "v25-23-0422:ctx14", "v25-23-0422:ctx15", "v25-23-0422:ctx16", "v25-23-0422:ctx17"], "sibling_refs": ["Theorem 3.2"], "topic_domain": "Deep Learning Theory", "topic_subtopic": "Training Dynamics & Implicit Bias"}], "nl_proof": "### Proof of Lemma 3.1\n\nLemma D.1. The following are true for the model (50) under Assumption 2.\n\n1. $\\begin{array}{r}{\\|\\nabla_{1}\\Phi(w,x)\\|\\le\\ell R.}\\end{array}$\n\n2. $\\begin{array}{r}{\\|\\nabla_{1}^{2}\\Phi(w,x)\\|\\le\\frac{LR^{2}}{\\sqrt{m}}}\\end{array}$\n\nProof Direct calculation yields that,\n\n$$\n\\nabla_{1}\\Phi(w,x)=\\frac{1}{\\sqrt{m}}\\left[\\begin{array}{c}{a_{1}\\sigma^{\\prime}(\\langle w_{1},x\\rangle)x}\\\\ {.}\\\\ {.}\\\\ {a_{m}\\sigma^{\\prime}(\\langle w_{m},x\\rangle)x}\\end{array}\\right]\n$$\n\nNoting that $\\sigma^{\\prime}(\\cdot)\\leq\\ell,$\n\n$$\n\\begin{array}{r l r}{{\\|\\nabla_{1}\\Phi(w,x)\\|^{2}=\\frac{1}{m}\\sum_{j=1}^{m}\\sum_{i=1}^{d}(x(i)\\sigma^{\\prime}(\\langle w_{j},x\\rangle))^{2}}}\\\\ &{}&{\\leq\\ell^{2}\\|x\\|^{2}}\\\\ &{}&{\\leq\\ell^{2}R^{2}.}\\end{array}\\tag{53}\n$$\n\nFor the Hessian,\n\n$$\n\\frac{\\partial^{2}\\Phi(w,x)}{\\partial w_{ij}\\partial w_{k\\ell}}=\\frac{1}{\\sqrt{m}}x(j)x(\\ell)a_{i}\\sigma^{\\prime\\prime}(\\langle w_{i},x\\rangle)\\mathbf{1}_{\\{i=k\\}}.\\tag{54}\n$$\n\nThus,\n\n$$\n\\nabla_{1}^{2}\\Phi(w,x)=\\frac{1}{\\sqrt{m}}\\mathrm{diag}\\left(a_{1}\\sigma^{\\prime\\prime}(\\langle w_{1},x\\rangle)x x^{T},\\dots,a_{m}\\sigma^{\\prime\\prime}(\\langle w_{m},x\\rangle)x x^{T}\\right)\n$$\n\nfor any unit norm vector $u \\in \\mathbb{R}^{m d}$ , define $\\bar{u}_{i}: =[u_{(i-1)m+1}:u_{im}]\\in\\mathbb{R}^{d}$ . Moreover, define the matrix $\\nabla_{w_{i}}^{2}\\Phi(w,x)\\in\\mathbb{R}^{d\\times d}$ such that $\\begin{array}{r}{[\\nabla_{w_{i}}^{2}\\Phi(w,x)]_{j\\ell}=\\frac{\\partial^{2}\\Phi(w,x)}{\\partial w_{ij}\\partial w_{i\\ell}}}\\end{array}$\n\n$$\n\\begin{array}{r l}{\\left\\|u^{\\top}\\nabla_{1}^{2}\\Phi(w,x)\\right\\|^{2}}&{=\\displaystyle\\sum_{i=1}^{m}\\left\\|u_{i}^{\\top}\\nabla_{w_{i}}^{2}\\Phi(w,x)\\right\\|^{2}}\\\\ &{\\leq\\displaystyle\\sum_{i=1}^{m}\\left\\|\\nabla_{w_{i}}^{2}\\Phi(w,x)\\right\\|^{2}\\|\\bar{u}_{i}\\|^{2}}\\\\ &{\\leq\\displaystyle\\sum_{i=1}^{m}\\frac{L^{2}}{m}\\|x\\|^{4}\\|\\bar{u}_{i}\\|^{2}}\\\\ &{\\leq\\displaystyle\\frac{L^{2}R^{4}}{m}.}\\end{array}\n$$\n\nThis completes the proof.\n\nLemma D.2. Let Assumption 2 hold. Then, the following are true for the loss gradient and Hessian:\n\n$$\n\\begin{array}{r}{1.\\|\\nabla\\widehat{F}(w)\\|\\le\\ell R\\widehat{F}^{\\prime}(w).}\\end{array}\n$$\n\n$$\n\\begin{array}{r}{2.\\|\\nabla^{2}\\widehat{F}(w)\\|\\le\\ell^{2}R^{2}\\widehat{F}^{\\prime\\prime}(w)+\\frac{LR^{2}}{\\sqrt{m}}\\widehat{F}^{\\prime}(w).}\\end{array}\n$$\n\n$$\n\\begin{array}{r}{3.\\ \\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}\\widehat{F}(w)\\right)\\geq-\\frac{L R^{2}}{\\sqrt{m}}\\widehat{F}^{\\prime}(w).}\\end{array}\n$$\n\nProof The loss gradient is derived as follows,\n\n$$\n\\nabla\\widehat{F}(w)=\\frac{1}{n}\\sum_{i=1}^{n}f^{\\prime}(y_{i}\\Phi(w,x_{i}))y_{i}\\nabla_{1}\\Phi(w,x_{i})\n$$\n\nRecalling that $y_{i}\\in \\{\\pm 1 \\}$ , we can write\n\n$$\n\\begin{array}{r l}{{\\Big\\|\\nabla\\widehat{F}(w)\\Big\\|=\\frac{1}{n}\\Big\\|\\displaystyle\\sum_{i=1}^{n}f^{\\prime}(y_{i}\\Phi(w,x_{i}))y_{i}\\nabla_{1}\\Phi(w,x_{i})\\Big\\|}}\\\\ &{\\leq\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}\\vert f^{\\prime}(y_{i}\\Phi(w,x_{i}))\\vert\\Big\\|\\nabla_{1}\\Phi(w,x_{i})\\Big\\|.}\\\\ &{\\leq\\ell RF^{\\prime}(w).}\\end{array}\\tag{55}\n$$\n\nFor the Hessian of loss, note that\n\n$$\n\\nabla^{2}\\widehat{F}(w)=\\frac{1}{n}\\sum_{i=1}^{n}f^{\\prime\\prime}(y_{i}\\Phi(w,x_{i}))\\nabla_{1}\\Phi(w,x_{i})\\nabla_{1}\\Phi(w,x_{i})^{\\top}+f^{\\prime}(y_{i}\\Phi(w,x_{i}))y_{i}\\nabla_{1}^{2}\\Phi(w,x_{i}).\\tag{56}\n$$\n\nIt follows that\n\n$$\n\\begin{array}{l}{\\displaystyle\\left\\|{\\nabla^{2}\\widehat{F}(w)}\\right\\|=\\left\\|\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}f^{\\prime}(y_{i}\\Phi(w,x_{i}))y_{i}{\\nabla_{1}^{2}\\Phi}(w,x_{i})+f^{\\prime\\prime}(y_{i}\\Phi(w,x_{i}))\\nabla_{1}\\Phi(w,x_{i})\\nabla_{1}\\Phi(w,x_{i})^{\\top}\\right\\|}\\\\ {\\displaystyle\\leq\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}{|f^{\\prime}(y_{i}\\Phi(w,x_{i}))|}\\left\\|{\\nabla_{1}^{2}\\Phi}(w,x_{i})\\right\\|+ |f^{\\prime\\prime}(y_{i}\\Phi(w,x_{i}))|\\left\\|\\nabla_{1}\\Phi(w,x_{i})\\nabla_{1}\\Phi(w,x_{i})^{\\top}\\right\\|}\\\\ {\\displaystyle\\leq\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}|f^{\\prime}(y_{i}\\Phi(w,x_{i}))|\\left\\|{\\nabla_{1}^{2}\\Phi}(w,x_{i})\\right\\|+ |f^{\\prime\\prime}(y_{i}\\Phi(w,x_{i}))|\\left\\|\\nabla_{1}\\Phi(w,x_{i})\\right\\|^{2}}\\\\ {\\displaystyle\\leq\\frac{LR^{2}}{\\sqrt{m}}F^{\\prime}(w)+\\ell^{2}R^{2}F^{\\prime\\prime}(w).}\\end{array}\\tag{57}\n$$\n\nTo lower-bound the minimum eigenvalue of Hessian, note that f is convex and thus $f^{\\prime\\prime}(\\cdot)\\geq 0$ Therefore the first term in (56) is positive semi-definite and the second term can be lowerbounded as follows,\n\n$$\n\\begin{array}{r l}&{\\lambda_{\\operatorname*{min}}(\\nabla^{2}\\widehat{F}(w))\\geq-\\left\\|\\displaystyle\\frac{1}{n}\\sum_{i=1}^{n}y_{i}f^{\\prime}\\big(y_{i}\\Phi(w,x_{i})\\big)\\nabla_{1}^{2}\\Phi(w,x_{i})\\right\\|}\\\\ &{\\qquad\\geq-\\displaystyle\\frac{1}{n}\\sum_{i=1}^{n}|y_{i}f^{\\prime}\\big(y_{i}\\Phi(w,x_{i})\\big)|\\left\\|\\nabla_{1}^{2}\\Phi(w,x_{i})\\right\\|}\\\\ &{\\qquad\\geq-\\displaystyle\\frac{L R^{2}}{\\sqrt{m}}F^{\\prime}(w).}\\end{array}\n$$\n\nCorollary D.2.1 (Self-boundedness of Objective). Let Assumption 2 hold. If the loss satisfies Assumptions 4 (with $\\beta_{f}=1)$ and 8, then\n\n1. $\\lVert\\nabla\\widehat{F}(w)\\rVert\\leq\\ell R\\widehat{F}(w)$\n\n$$\n\\begin{array}{r}{2.\\|\\nabla^{2}\\widehat{F}(w)\\|{\\le}\\left(\\ell^{2}R^{2}+\\frac{LR^{2}}{\\sqrt{m}}\\right)\\widehat{F}(w).}\\end{array}\n$$\n\n3. $\\begin{array}{r}{\\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}\\widehat{F}(w)\\right)\\geq-\\frac{L R^{2}}{\\sqrt{m}}\\widehat{F}(w).}\\end{array}$\n\nIf in addition the loss satisfies Assumptions 3.A and 3.B with $L_{f}= G_{f}= 1$ , then\n\n6. $\\lVert\\nabla\\widehat{F}(w)\\rVert\\leq\\ell R.$\n\n$$\n\\begin{array}{r}{7.\\ \\|\\nabla^{2}\\widehat{F}(w)\\|\\le\\ell^{2}R^{2}+\\frac{LR^{2}}{\\sqrt{m}}.}\\end{array}\n$$\n\nProof For self-bounded losses we have $\\widehat{F}^{\\prime}(w)\\leq\\widehat{F}(w)$ and $\\widehat{F}^{\\prime\\prime}(w)\\leq\\widehat{F}(w)$ . If the loss is 1-Lipschitz and 1-smooth we have $\\widehat{F}^{\\prime}(w)\\leq 1$ and $\\widehat{F}^{\\prime\\prime}(w)\\leq 1$ . Thus, the claims immediately follow from Lemma D.2.\n\n### Proof of Theorem 3.2\n\nBecause of smoothness and Lipschitz Assumption 3 of $f,$ it turns out that the training objective is $L_{\\widehat{F}}$-smooth. Hence, by the descent lemma of GD for smooth functions, the same upper bound holds in Eq. (5) for the value of the loss at time $T$, as well.\n\n## A.1 Proof of Theorem 3.2\n\nWe begin with proving the general train-loss and parameter-norm bounds of Theorem 3.2. In fact, we state and prove a slightly more general statement of the theorem which includes non-smooth and non-Lipschitz losses (such as expoential loss) that satisfy a second order self-bounded property described below.\n\nAssumption 8 (2nd order self-boundedness). The convex loss function $f : \\mathbb{R}\\to \\mathbb{R}_{+}$ satisfies the 2nd order self-boundedness property, i.e.\n\n$$\nf^{\\prime\\prime}(u)\\leq f(u),\\forall u\\in\\mathbb{R}.\n$$\n\nTheorem A.1 (General statement of Theorem 3.2). Let Assumptions 1-2 hold. Assume the loss function satisfies self-bounded Assumption 4. Moreover, suppose either Assumption 3 or Assumption 8 hold. Fix any $T \\geq 0$ . Let the step-size satisfy the assumptions of the descent lemma (Lemma A.2). Assume any w and m such that $\\| w - w_{0}\\|^{2}\\ge$ max $\\left\\{\\eta T\\widehat{F}(w),\\eta\\widehat{F}(w_{0})\\right\\}$ and $m\\geq 18^{2}L^{2}R^{4}\\|w-w_{0}\\|^{4}$ . Then, the training loss and the parameters' norm satisfy\n\n$$\n\\begin{array}{r l r}{{\\frac{1}{T}\\sum_{t=1}^{T}\\widehat{F}(w_{t})\\leq 2\\widehat{F}(w)+\\frac{5\\|w-w_{0}\\|^{2}}{2\\eta T},}}\\\\ &{}&{\\forall t\\in [T]\\ :\\ \\|w_{t}-w_{0}\\|\\leq 4\\|w-w_{0}\\|.}\\end{array}\\tag{16}\n$$\n\nTo prove Theorem A.1, we first state our descent lemma for both self-bounded losses and lipschitz-smooth losses.\n\nLemma A.2 (Descent lemma). Let Assumptions 1-2 hold. Assume the loss function satisfies self-boundedness Assumptions 4, 8. Then, for any $\\begin{array}{r}{\\eta<\\frac{1}{R^{2}\\widehat{F}(w_{t})}\\operatorname*{min}\\{\\frac{1}{\\ell^{2}+L},\\frac{1}{\\sqrt{L}\\ell}\\}}\\end{array}$ the descent property holds, i.e.,\n\n$$\n\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w_{t})-\\frac{\\eta}{2}\\|\\nabla\\widehat{F}(w_{t})\\|^{2}.\n$$\n\nMoreover, if f satisfies Assumption 3 then the descent property holds for any $\\eta \\leq 1 / L_{\\widehat{F}}$ where $\\begin{array}{r}{L_{\\widehat{F}}: = \\ell^{2}R^{2}+ \\frac{L R^{2}}{\\sqrt{m}}}\\end{array}$ is the smoothness parameter of the training objective.\n\nProof Due to self-boundedness Assumption 8, as well as Assumptions 1-2 the objective is also self-bounded according to Corollary D.2.1, i.e., $\\begin{array}{r}{\\|\\nabla^{2}\\widehat{F}(w)\\|\\le\\left(\\ell^{2}R^{2}+\\frac{LR^{2}}{\\sqrt{m}}\\right)\\widehat{F}(w),\\|\\nabla\\widehat{F}(w)\\|\\le}\\end{array}$ $\\ell R\\widehat{F}(w)$\n\nBy Taylor's expansion, there exists a $w^{\\prime}\\in [ w_{t}, w_{t + 1}]$ such that,\n\n$$\n\\begin{array}{r l}&{\\widehat{F}(w_{t+1})=\\widehat{F}(w_{t})+\\left\\langle\\nabla\\widehat{F}(w_{t}),w_{t+1}-w_{t}\\right\\rangle+\\displaystyle\\frac{1}{2}\\left\\langle w_{t+1}-w_{t},\\nabla^{2}\\widehat{F}(w^{\\prime})\\left(w_{t+1}-w_{t}\\right)\\right\\rangle}\\\\ &{\\qquad\\leq\\widehat{F}(w_{t})+\\left\\langle\\nabla\\widehat{F}(w_{t}),w_{t+1}-w_{t}\\right\\rangle+\\displaystyle\\frac{1}{2}\\operatorname*{max}_{v\\in [w_{t},w_{t+1}]}\\left\\|\\nabla^{2}\\widehat{F}(v)\\right\\|\\cdot\\|w_{t+1}-w_{t}\\|^{2}}\\\\ &{\\qquad\\leq\\widehat{F}(w_{t})-\\eta\\|\\nabla\\widehat{F}(w_{t})\\|^{2}+\\displaystyle\\frac{\\eta^{2}\\left(\\ell^{2}R^{2}+\\frac{L R^{2}}{\\sqrt{m}}\\right)}{2}\\operatorname*{max}_{v\\in [w_{t},w_{t+1}]}\\widehat{F}(v)\\cdot\\left\\|\\nabla\\widehat{F}(w_{t})\\right\\|^{2}.}\\end{array}\n$$\n\nBy Corollary A.7.1, for $\\sqrt{m}\\ge\\eta^{2}L\\ell^{2}R^{4}\\widehat{F}^{2}(w_{t})\\ge LR^{2}\\|\\eta\\nabla\\widehat{F}(w_{t})\\|^{2}=LR^{2}\\|w_{t+1}-w_{t}\\|^{2}$ it holds that\n\n$$\n\\operatorname*{max}_{v\\in [w_{t},w_{t+1}]}\\widehat F(v)\\leq 2\\operatorname*{max}\\{\\widehat F(w_{t}),\\widehat F(w_{t+1})\\},\n$$\n\nwhich yields\n\n$$\n\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w_{t})-\\eta\\|\\nabla\\widehat{F}(w_{t})\\|^{2}+\\eta^{2}\\bigg(\\ell^{2}R^{2}+\\frac{L R^{2}}{\\sqrt{m}}\\bigg)\\operatorname*{max}\\Big\\{\\widehat{F}(w_{t}),\\widehat{F}(w_{t+1})\\Big\\}\\cdot\\|\\nabla\\widehat{F}(w_{t})\\|^{2}.\\tag{17}\n$$\n\nWe note that the condition on m simplifies to $\\begin{array}{r}{m\\geq 1\\mathrm{~if~}\\eta\\leq\\frac{1}{\\sqrt{L}\\ell R^{2}}\\frac{1}{\\widehat{F}(w_{t})}}\\end{array}$\n\nBack to (17), if $\\widehat{F}(w_{t+1})\\geq\\widehat{F}(w_{t})$ by our condition $\\begin{array}{r}{\\eta<\\frac{1}{\\ell^{2}R^{2}+LR^{2}/\\sqrt{m}}\\frac{1}{\\widehat{F}(w_{t})}}\\end{array}$ it holds that\n\n$$\n\\begin{array}{r l r}{{\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w_{t})+\\eta\\|\\nabla\\widehat{F}(w_{t})\\|^{2}(\\frac{\\widehat{F}(w_{t+1})}{\\widehat{F}(w_{t})}-1)}}\\\\ &{}&{\\leq\\widehat{F}(w_{t})+\\eta\\ell^{2}R^{2}\\widehat{F}^{2}(w_{t})(\\frac{\\widehat{F}(w_{t+1})}{\\widehat{F}(w_{t})}-1).}\\end{array}\n$$\n\nSince $\\begin{array}{r}{\\eta<\\frac{1}{\\ell^{2}R^{2}}\\frac{1}{\\widehat{F}(w_{t})}}\\end{array}$\n\n$$\n\\begin{array}{l}{\\displaystyle{\\widehat F(w_{t+1})<\\widehat F(w_{t})+\\widehat F(w_{t})\\left(\\frac{\\widehat F(w_{t+1})}{\\widehat F(w_{t})}-1\\right)}}\\\\ {\\displaystyle{=\\widehat F(w_{t+1}),}}\\end{array}\n$$\n\nwhich is a contradiction. Thus it holds that $\\widehat{F}(w_{t+1})<\\widehat{F}(w_{t})$ . Continuing from Eq. (17) with the assumption $\\begin{array}{r}{\\eta<\\frac{1}{\\ell^{2}R^{2}+LR^{2}/\\sqrt{m}}\\frac{1}{\\widehat{F}(w_{t})}}\\end{array}$ , we conclude that\n\n$$\n\\begin{array}{r l}&{\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w_{t})-\\eta\\|\\nabla\\widehat{F}(w_{t})\\|^{2}+\\frac{1}{2}\\eta^{2}\\bigg(\\ell^{2}R^{2}+\\frac{LR^{2}}{\\sqrt{m}}\\bigg)\\widehat{F}(w_{t})\\cdot\\|\\nabla\\widehat{F}(w_{t})\\|^{2}}\\\\ &{\\qquad\\leq\\widehat{F}(w_{t})-\\frac{\\eta}{2}\\|\\nabla\\widehat{F}(w_{t})\\|^{2}.}\\end{array}\n$$\n\nThis completes the proof for self-bounded losses.\n\nNext, suppose $f$ is 1-smooth and 1-Lipschitz. Then, as per Corollary D.2.1, $\\widehat F$ is smooth with the constant\n\n$$\nL_{\\widehat{F}}: = \\ell^{2}R^{2}+ \\frac{L R^{2}}{\\sqrt{m}}.\n$$\n\nFollowing similar steps as in the beginning of proof and assuming step-size $\\eta \\leq 1 / L_{\\widehat{F}}$ we immediately conclude that,\n\n$$\n\\begin{array}{r l}&{\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w_{t})-\\eta\\|\\nabla\\widehat{F}(w_{t})\\|^{2}+\\frac{\\eta^{2}L_{\\widehat{F}}}{2}\\|\\nabla\\widehat{F}(w_{t})\\|^{2}}\\\\ &{\\qquad\\leq\\widehat{F}(w_{t})-\\displaystyle\\frac{\\eta}{2}\\|\\nabla\\widehat{F}(w_{t})\\|^{2}.}\\end{array}\n$$\n\nThis completes the proof.\n\nAs a remark, the descent property implies that the loss decreases by each step, i.e., ${\\widehat F}(w_{t})\\leq{\\widehat F}(w_{0})$ . Thus for self-bounded losses the condition $\\begin{array}{r}{\\eta<\\frac{1}{R^{2}\\widehat{F}(w_{0})}\\operatorname*{min}\\{\\frac{1}{\\ell^{2}+L},\\frac{1}{\\sqrt{L}\\ell}\\}}\\end{array}$ is sufficient. We also note that the Lipschitz-smoothness and 2nd order self-bounded assumptions are only required for the descent lemma above, which results in conditions on the step-size based on the properties of loss. In the rest of the proof we only use the self-bounded Assumption 4 in order to use the self-bounded weak convexity property of the objective (see Def. 1).\n\nNext lemma finds a general relation for the training loss in terms of an arbitrary point $w \\in \\mathbb{R}^{d^{\\prime}}$ and the fluctuations of loss between w and GD iterates $w_{t}$\n\nLemma A.3. Let Assumptions 1-2 hold. Assume the loss function satisfies the self-bounded Assumption 4. Moreover, suppose $\\widehat F$ and step-size η are such that the following descent condition is satisfied for all $t \\geq 0$:\n\n$$\n\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w_{t})-\\frac{\\eta}{2}\\|\\nabla\\widehat{F}(w_{t})\\|^{2}.\\tag{18}\n$$\n\nThen, for any w $\\in \\mathbb{R}^{d^{\\prime}}$ it holds that\n\n$$\n\\frac{1}{T}\\sum_{t=1}^{T}\\widehat{F}(w_{t})\\leq\\widehat{F}(w)+\\frac{\\|w-w_{0}\\|^{2}}{\\eta T}+\\frac{1}{2}\\frac{L R^{2}}{\\sqrt{m}}\\frac{1}{T}\\sum_{t=0}^{T-1}\\operatorname*{max}_{\\alpha\\in [0,1]}\\widehat{F}(w_{\\alpha t})\\|w-w_{t}\\|^{2},\n$$\n\nwhere we set $w_{\\alpha t}: =\\alpha w_{t}+(1-\\alpha)w$\n\n## Proof\n\nFix any w. By Taylor, there exists $w_{\\alpha t},\\alpha\\in [0,1]$ such that\n\n$$\n\\begin{array}{r l}&{\\widehat{F}(w)=\\widehat{F}(w_{t})+\\left\\langle\\nabla\\widehat{F}(w_{t}),w-w_{t}\\right\\rangle+\\displaystyle\\frac{1}{2}\\left\\langle w-w_{t},\\nabla^{2}\\widehat{F}(w_{\\alpha t})\\left(w-w_{t}\\right)\\right\\rangle}\\\\ &{\\qquad\\geq\\widehat{F}(w_{t})+\\left\\langle\\nabla\\widehat{F}(w_{t}),w-w_{t}\\right\\rangle+\\displaystyle\\frac{1}{2}\\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}\\widehat{F}(w_{\\alpha t})\\right)\\|w-w_{t}\\|^{2}}\\\\ &{\\qquad\\geq\\widehat{F}(w_{t})+\\left\\langle\\nabla\\widehat{F}(w_{t}),w-w_{t}\\right\\rangle-\\displaystyle\\frac{1}{2}\\frac{L R^{2}}{\\sqrt{m}}\\widehat{F}(w_{\\alpha t})\\|w-w_{t}\\|^{2}.}\\end{array}\n$$\n\nThe last line is true by Corollary D.2.1. Thus, for any w,\n\n$$\n\\widehat{F}(w)\\geq\\widehat{F}(w_{t})+\\Big\\langle\\nabla\\widehat{F}(w_{t}),w-w_{t}\\Big\\rangle-\\frac{1}{2}\\frac{L R^{2}}{\\sqrt{m}}\\operatorname*{max}_{\\alpha\\in [0,1]}\\widehat{F}(w_{\\alpha t})\\|w-w_{t}\\|^{2}.\n$$\n\nPlugging this in (18) gives\n\n$$\n\\begin{array}{r l r}&{}&{\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w)-\\left\\langle\\nabla\\widehat{F}(w_{t}),w-w_{t}\\right\\rangle-\\displaystyle\\frac{\\eta}{2}\\left\\|\\nabla\\widehat{F}(w_{t})\\right\\|^{2}+\\displaystyle\\frac{1}{2}\\frac{L R^{2}}{\\sqrt{m}}\\displaystyle\\operatorname*{max}_{\\alpha\\in [0,1]}\\widehat{F}(w_{\\alpha t})\\|w-w_{t}\\|^{2}}\\\\ &{}&{\\displaystyle=\\widehat{F}(w)+\\frac{1}{\\eta}\\left(\\|w-w_{t}\\|^{2}-\\|w-w_{t+1}\\|^{2}\\right)+\\frac{1}{2}\\frac{L R^{2}}{\\sqrt{m}}\\displaystyle\\operatorname*{max}_{\\alpha\\in [0,1]}\\widehat{F}(w_{\\alpha t})\\|w-w_{t}\\|^{2}.\\qquad(19)}\\end{array}\n$$\n\nwhere the second line follows by completion of squares using $w_{t+1}-w_{t}= -\\eta\\nabla\\widehat{F}(w_{t})$\n\nTelescoping the above display for $t=0,\\ldots,T-1$ , we arrive at the desired.\n\nNext, when m is large enough so that we can invoke the generalized-local quasiconvexity property, the bound of Lemma A.3 takes the following convenient form\n\nLemma A.4. Let the assumptions of Lemma A.3 hold. Assume w and m such that $\\sqrt{m}\\geq 2 L R^{2}\\Vert w - w_{t}\\Vert^{2}$ for all $t \\in [ T - 1 ]$ then\n\n$$\n\\frac{1}{T}\\sum_{t=1}^{T}\\widehat{F}(w_{t})\\leq 2\\widehat{F}(w)+\\frac{2\\|w-w_{0}\\|^{2}}{\\eta T}+\\frac{\\widehat{F}(w_{0})}{2T}.\\tag{20}\n$$\n\nProof We invoke Corollary A.7.1 with $\\lambda = 4$ to deduce that for all $t \\in [ T - 1 ]$\n\n$$\n\\operatorname*{max}_{\\alpha\\in [0,1]}\\widehat{F}(w_{\\alpha t})\\leq\\frac{4}{3}\\operatorname*{max}\\{\\widehat{F}(w),\\widehat{F}(w_{t})\\}<\\frac{4}{3}\\widehat{F}(w_{t})+\\frac{4}{3}\\widehat{F}(w).\\tag{21}\n$$\n\nNoting the assumption on m and recalling Lemma A.3,\n\n$$\n\\begin{array}{r l r}{{\\frac{1}{T}\\sum_{t=1}^{T}\\widehat{F}(w_{t})\\leq\\widehat{F}(w)+\\frac{\\|w-w_{0}\\|^{2}}{\\eta T}+\\frac{1}{2}\\frac{L R^{2}}{\\sqrt{m}}\\frac{1}{T}\\sum_{t=0}^{T-1}\\underset{\\alpha\\in [0,1]}{\\operatorname*{max}}\\widehat{F}(w_{\\alpha t})\\|w-w_{t}\\|^{2}}}\\\\ &{}&{\\leq\\frac{4}{3}\\widehat{F}(w)+\\frac{\\|w-w_{0}\\|^{2}}{\\eta T}+\\frac{1}{3 T}\\sum_{t=0}^{T-1}\\widehat{F}(w_{t})}\\\\ &{}&{\\leq\\frac{4}{3}\\widehat{F}(w)+\\frac{\\|w-w_{0}\\|^{2}}{\\eta T}+\\frac{1}{3 T}\\sum_{t=0}^{T}\\widehat{F}(w_{t}).}\\end{array}\n$$\n\nArranging terms yields the desired result.\n\nFinally, using the about bounds on the training loss, we can bound the parameter-norm using a recursive argument presented in the lemma below.\n\nLemma A.5 (Iterates-norm bound). Suppose the assumptions of Lemma A.3 hold. Fix any $T \\geq 0$ and assume any w and m such that\n\n$$\n\\begin{array}{r}{\\|w-w_{0}\\|^{2}{\\ge}\\operatorname*{max}\\{\\eta T\\widehat F(w),\\eta\\widehat F(w_{0})\\}.}\\end{array}\\tag{22}\n$$\n\nand\n\n$$\n\\sqrt{m}\\geq 18LR^{2}\\Vert w-w_{0}\\Vert^{2},\\tag{23}\n$$\n\nThen, for all $t \\in [ T ]$\n\n$$\n\\| w_{t}- w \\| \\leq 3 \\| w - w_{0}\\| .\\tag{24}\n$$\n\nProof Denote $A_{t}= \\| w_{t}- w \\|$ . Start by recalling from (19) that for all t:\n\n$$\nA_{t+1}^{2}\\leq A_{t}^{2}+\\eta\\widehat{F}(w)-\\eta\\widehat{F}(w_{t+1})+\\eta\\frac{L R^{2}}{2\\sqrt{m}}\\operatorname*{max}_{\\alpha\\in [0,1]}\\widehat{F}(w_{\\alpha t})A_{t}^{2}.\\tag{25}\n$$\n\nWe will prove the desired statement (24) using induction. For $t=0,A_{0}=\\|w-w_{0}\\|$ Thus, the assumption of induction holds. Now assume (24) is correct for $t \\in [ T - 1 ]$ , i.e. $A_{t}\\leq 3\\|w-w_{0}\\|,\\forall t\\in [T-1]$ . We will then prove it holds for $t = T$\n\nThe first observation is that by induction hypothesis $\\sqrt{m}\\geq 18LR^{2}\\|w-w_{0}\\|^{2}{\\geq}2LR^{2}A_{t}^{2}$ for all $t \\in [ T - 1 ]$ . Thus, for all $t \\in [ T - 1 ]$ , the condition of the generalized local quasi-convexity Corollary 5.1.1 holds for $\\lambda = 4$ implying (see also (21))\n\n$$\n\\forall t\\in [T-1]:\\ \\operatorname*{max}_{\\alpha\\in [0,1]}{\\widehat{F}}(w_{\\alpha t})\\leq{\\frac{4}{3}}{\\widehat{F}}(w_{t})+{\\frac{4}{3}}{\\widehat{F}}(w).\n$$\n\nUsing this in (25) we find for all $t \\in [ T - 1 ]$ that\n\n$$\n\\begin{array}{r l}&{A_{t+1}^{2}\\leq A_{t}^{2}+\\eta\\widehat{F}(w)-\\eta\\widehat{F}(w_{t+1})+\\eta\\frac{LR^{2}\\cdot A_{t}^{2}}{2\\sqrt{m}}\\left(\\frac 43\\widehat{F}(w_{t})+\\frac 43\\widehat{F}(w)\\right)}\\\\ &{\\qquad\\leq A_{t}^{2}+\\eta\\widehat{F}(w)-\\eta\\widehat{F}(w_{t+1})+\\eta\\left(\\frac 13\\widehat{F}(w_{t})+\\frac 13\\widehat{F}(w)\\right)}\\end{array}\n$$\n\nwhere in the second inequality we used again that $\\sqrt{m}\\geq 2 L R^{2}A_{t}^{2}$ . We proceed by telescoping the above display over $t=0,1,\\dots,T-1$ to get\n\n$$\n\\begin{array}{r l}&{A_{T}^{2}\\le A_{0}^{2}+\\displaystyle\\frac{4}{3}\\eta T\\widehat F(w)+\\displaystyle\\frac{1}{3}\\eta\\widehat F(w_{0})+\\displaystyle\\frac{1}{3}\\eta\\displaystyle\\sum_{t=0}^{T-1}\\widehat F(w_{t})-\\eta\\widehat F(w_{T})}\\\\ &{\\qquad\\le A_{0}^{2}+\\displaystyle\\frac{4}{3}\\eta T\\widehat F(w)+\\displaystyle\\frac{2}{3}\\eta\\widehat F(w_{0})+\\displaystyle\\frac{1}{3}\\eta\\displaystyle\\sum_{t=1}^{T}\\widehat F(w_{t}),}\\end{array}\n$$\n\nwhere the second line follows by nonegativity of the loss.\n\nNow, to bound the last term above, observe that the condition of Lemma A.4 holds since $\\sqrt{m}\\geq 2 L R^{2}A_{t}^{2}$ for all $t \\in [ T - 1 ]$ by induction hypothesis. Hence, using (20), we conclude that\n\n$$\n\\begin{array}{r l r}{{A_{T}^{2}\\le A_{0}^{2}+\\frac 43\\eta T\\widehat F(w)+\\frac 23\\eta\\widehat F(w_{0})+\\frac 13\\eta T(2\\widehat F(w)+\\frac{2A_{0}^{2}}{\\eta T}+\\frac{\\widehat F(w_{0})}{2T})}}\\\\ &{}&{=\\frac 53A_{0}^{2}+2\\eta T\\widehat F(w)+\\frac 56\\eta\\widehat F(w_{0})}\\\\ &{}&{\\le\\frac 53\\|w-w_{0}\\|^{2}+2\\|w-w_{0}\\|^{2}+\\frac 56\\|w-w_{0}\\|^{2}=\\frac 92\\|w-w_{0}\\|^{2}\\qquad\\Longrightarrow\\ A_{T}\\le 3\\|w-w_{0}\\|.}\\end{array}\\tag{26}\n$$\n\nIn the last inequality, we used the assumptions of the lemma on $\\lVert w - w_{0}\\rVert$ and $A_{0}= \\| w - w_{0}\\|$ This completes the proof.\n\n## Completing the proof of Theorem A.1.\n\nThe proof follows from combining the bounds on the training loss and parameters' growth from Lemmas $\\mathrm{{A . 4 – A . 5}}$ and noting that with condition on $\\| w - w_{0}\\|^{2}$ from Lemma $\\mathrm{A . 5}$ we have ${\\widehat F}(w_{0})\\leq\\|w-w_{0}\\|^{2}/\\eta$ to derive (16). Moreover, we have $\\lVert w_{t}- w_{0}\\rVert \\leq \\lVert w_{t}- w \\rVert + \\lVert w - w_{0}\\rVert \\leq$ $4 \\lVert w - w_{0}\\rVert$\n\n## A.3 Generalized local quasi-convexity property\n\nIn the remainder of this section, we prove the generalized local quasi-convexity property.\n\nProposition A.7 (Restatement of Proposition 5.1). Suppose $\\widehat{F}: \\mathbb{R}^{d^{\\prime}}\\to \\mathbb{R}$ satisfies the self-bounded weak convexity property in Eq. 4 with parameter κ. Let $w_{1}, w_{2}\\in \\mathbb{R}^{d^{\\prime}}$ be two arbitrary points with distance $\\| w_{1}- w_{2}\\| \\leq D < \\sqrt{2 / \\kappa}$ . Set $\\tau: =\\left(1-\\kappa D^{2}/2\\right)^{-1}$ . Then,\n\n$$\n\\operatorname*{max}_{v\\in [w_{1},w_{2}]}\\widehat{F}(v)\\leq\\tau\\cdot\\operatorname*{max}\\{\\widehat{F}(w_{1}),\\widehat{F}(w_{2})\\}.\\tag{27}\n$$\n\nProof Assume the claim of the proposition is incorrect, then\n\n$$\n\\operatorname*{max}_{v\\in [w_{1},w_{2}]}\\widehat{F}(v)>\\tau\\cdot\\operatorname*{max}\\{\\widehat{F}(w_{1}),\\widehat{F}(w_{2})\\}>\\operatorname*{max}\\{\\widehat{F}(w_{1}),\\widehat{F}(w_{2})\\}.\\tag{28}\n$$\n\nDefine $\\begin{array}{r}{w_{\\star}: =\\arg\\operatorname*{max}_{v\\in [w_{1},w_{2}]}\\widehat{F}(v)}\\end{array}$ . Note that $w_{\\star}$ is an interior point. Thus by the optimality condition it holds\n\n$$\n\\left\\langle\\nabla\\widehat{F}(w_{\\star}),w_{1}-w_{2}\\right\\rangle=0.\\tag{29}\n$$\n\nBy Taylor's approximation theorem for two points w1, $w \\in \\mathbb{R}^{d^{\\prime}}$ , there exists a $w_{\\beta}\\in [w,w_{1}]$ such that\n\n$$\n\\widehat{F}(w_{1})=\\widehat{F}(w)+\\left\\langle\\nabla\\widehat{F}(w),w_{1}-w\\right\\rangle+\\frac{1}{2}\\left\\langle w-w_{1},\\nabla^{2}\\widehat{F}(w_{\\beta})\\left(w-w_{1}\\right)\\right\\rangle\\tag{30}\n$$\n\nPick $w=w_{\\star}=\\alpha_{\\star}w_{1}+(1-\\alpha_{\\star})w_{2}$ in Eq. (30), and note that\n\n$$\n\\begin{array}{r}{\\Big\\langle\\nabla\\widehat{F}(w_{\\star}),w_{1}-w_{\\star}\\Big\\rangle= -(1-\\alpha_{\\star})\\Big\\langle\\nabla\\widehat{F}(w_{\\star}),w_{1}-w_{2}\\Big\\rangle=0.}\\end{array}\n$$\n\nTherefore,\n\n$$\n\\begin{array}{r l}&{\\widehat{F}(w_{1})=\\widehat{F}(w_{\\star})+\\displaystyle\\frac{1}{2}\\left\\langle w_{\\star}-w_{1},\\nabla^{2}\\widehat{F}(w_{\\beta})\\left(w_{\\star}-w_{1}\\right)\\right\\rangle}\\\\ &{\\qquad\\quad\\geq\\widehat{F}(w_{\\star})+\\displaystyle\\frac{1}{2}\\lambda_{\\mathrm{min}}(\\nabla^{2}\\widehat{F}(w_{\\beta}))\\left\\|w_{\\star}-w_{1}\\right\\|^{2}}\\\\ &{\\qquad\\quad\\geq\\widehat{F}(w_{\\star})-\\displaystyle\\frac{1}{2}\\kappa\\widehat{F}(w_{\\beta})\\Big\\Vert w_{\\star}-w_{1}\\Big\\Vert^{2}.}\\end{array}\n$$\n\nwhere in the last line we used the self-bounded weak convexity property i.e., $\\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}\\widehat{F}(\\boldsymbol{w}_{\\beta})\\right)\\geq-\\kappa\\widehat{F}(w_{\\beta})$\n\nThis leads to\n\n$$\n\\begin{array}{l}{\\displaystyle\\widehat{F}(w_{1})\\geq\\widehat{F}(w_{\\star})-\\frac{(1-\\alpha_{\\star})^{2}}{2}\\kappa\\widehat{F}(w_{\\beta})\\Big\\|w_{1}-w_{2}\\Big\\|^{2}}\\\\ {\\displaystyle>\\widehat{F}(w_{\\star})-\\frac{1}{2}\\kappa\\widehat{F}(w_{\\beta})\\Big\\|w_{1}-w_{2}\\Big\\|^{2}.}\\end{array}\n$$\n\nNote that $w_{\\beta}\\in [ w_{\\star}, w_{1}] \\subset [ w_{1}, w_{2}]$ , thus $\\widehat{F}(w_{\\beta})\\leq\\widehat{F}(w_{\\star})$ by definition of $w_{\\star}$. Therefore,\n\n$$\n\\begin{array}{r l}&{\\widehat{F}(w_{\\star})<\\displaystyle\\frac{1}{1-\\frac{1}{2}\\kappa\\|w_{1}-w_{2}\\|^{2}}\\widehat{F}(w_{1})}\\\\ &{\\qquad\\le\\displaystyle\\frac{1}{1-\\frac{1}{2}\\kappa D^{2}}\\widehat{F}(w_{1}),}\\end{array}\n$$\n\nwhich is in contradiction with (28). This proves the statement of the proposition.\n\nSpecializing this property to two-layer neural networks yields the following.\n\nCorollary A.7.1 (Restatement of Corollary 5.1.1). Let Assumptions 1,2, 4 hold. Fix arbitrary w1, $w_{2}\\in \\mathbb{R}^{d^{\\prime}}$ , any constant $\\lambda > 1$ , and m large enough such that $\\sqrt{m}\\geq \\lambda \\frac{L R^{2}}{2}\\Vert w_{1}-$ $w_{2}\\|^{2}$ . Then,\n\n$$\n\\operatorname*{max}_{v\\in [w_{1},w_{2}]}\\widehat{F}(v)\\leq(1-1/\\lambda)^{-1}\\cdot\\operatorname*{max}\\{\\widehat{F}(w_{1}),\\widehat{F}(w_{2})\\}.\\tag{31}\n$$\n\nProof By our assumptions and Corollary D.2.1 the objective's Hessian satisfies\n\n$$\n\\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}\\widehat{F}(w)\\right)\\geq-\\frac{L R^{2}}{\\sqrt{m}}\\widehat{F}(w).\n$$\n\nInvoking Proposition A.7 with $\\begin{array}{r}{\\kappa : = \\frac{L R^{2}}{\\sqrt{m}}}\\end{array}$ concludes the claim.\n\n### Proof of Theorem 3.3\n\n## A.2 Proof of Theorem 3.3\n\nHere we prove training loss bound for interpolating NN as asserted by Theorem 3.3. Similar to the previous section, we prove a more general result where the loss is not necessarily Lipschitz or smooth. We are now ready to prove Theorem 3.3 for general self-bounded losses. In particular, Theorem 3.3 follows directly from the next result by choosing f to be Lipschitz and smooth.\n\nTheorem A.6 (General statement of Theorem 3.3). Suppose Assumptions 1-2, 4 hold. Moreover, assume the objective and data satisfy the Assumption 5. Let the step-size satisfy the assumptions of Descent Lemma A.2. Moreover, assume $\\begin{array}{r}{\\eta\\le\\operatorname*{min}\\{g(1)^{2},\\frac{1}{L_{\\widehat{F}}},\\frac{g(1)^{2}}{\\widehat{F}(w_{0})}\\}}\\end{array}$ and $m\\geq 18^{2}L^{2}R^{4}g(\\frac{1}{T})^{4}$ for a fixed training horizon T. Then,\n\n$$\n\\widehat{F}(w_{T})\\leq\\frac{2}{T}+\\frac{5g(\\frac{1}{T})^{2}}{2\\eta T},\n$$\n\n$$\n\\forall t\\in [T]\\ :\\ \\|w_{t}-w_{0}\\|\\ \\leq\\ 4g(\\frac{1}{T}).\n$$\n\nProof According to Assumption 5, for any sufficiently small $\\varepsilon > 0$ , there exists a $w^{(\\varepsilon)}$ such that $\\widehat{F}(w^{(\\varepsilon)})\\leq\\varepsilon$ and $\\lVert\\boldsymbol{w}^{(\\varepsilon)}-\\boldsymbol{w}_{0}\\rVert=g(\\varepsilon)$ . Pick $\\varepsilon = 1 / T$ . With the condition $\\eta \\leq$ min $\\{g(1)^{2},g(1)^{2}/\\widehat{F}(w_{0})\\}$ we have\n\n$$\n\\operatorname*{max}\\left\\{\\eta T\\widehat{F}(w^{(1/T)}),\\eta\\widehat{F}(w_{0})\\right\\}\\leq g(1)^{2}\\leq g(\\frac{1}{T})^{2}=\\|w^{(1/T)}-w_{0}\\|^{2},\n$$\n\nwhere in the second inequality we used the fact that $g$ is a decreasing function. The desired result is obtained by Theorem A.1.", "context": [{"id": "v25-23-0422:ctx1", "name": "Notation", "statement": "## Notation\n\nWe define $[n]: =\\{1,2,\\cdots,n\\}$. We use the standard notation $O(\\cdot),\\Omega(\\cdot)$ and use $\\tilde{O}(\\cdot),\\tilde{\\Omega}(\\cdot)$ to hide polylogarithmic factors. Occasionally we use $\\lesssim$ to hide numerical constants. The Gradient and Hessian of a function $\\Phi : \\mathbb{R}^{d_{1}\\times d_{2}}\\to \\mathbb{R}$ with respect to the ith input $(i=1,2)$ are denoted by $\\nabla_{i}\\Phi$ and $\\nabla_{i}^{2}\\Phi$ , respectively. All logarithms are in base e. We use $\\| \\cdot \\|$ for the $\\ell_{2}$ norm of vectors and the operator norm of matrices. We denote $[ w_{1}, w_{2}] : = \\{w \\ : \\ w =$ $\\alpha w_{1}+(1-\\alpha)w_{2},\\alpha\\in [0,1]\\}$ the line segment between w1, $w_{2}\\in \\mathbb{R}^{d^{\\prime}}$ ."}, {"id": "v25-23-0422:ctx2", "name": "Setup: empirical risk objective (Section 2, eqs. (1)-(2))", "statement": "## 2. Problem Setup\n\nGiven n i.i.d. samples $(x_{i},y_{i})\\sim\\mathcal{D},i\\in [n]$ from data distribution D, we study unconstrained empirical risk minimization with objective $\\widehat{F}: \\mathbb{R}^{d^{\\prime}}\\to \\mathbb{R}$:\n\n$$\n\\operatorname*{min}_{w\\in\\mathbb{R}^{d^{\\prime}}}\\Big\\{\\widehat{F}(w): =\\frac{1}{n}\\sum_{i=1}^{n}\\widehat{F}_{i}(w)=\\frac{1}{n}\\sum_{i=1}^{n}f\\left(y_{i}\\Phi\\left(w,x_{i}\\right)\\right)\\Big\\}.\\tag{1}\n$$\n\nThis serves as a proxy for minimizing the test loss $F : \\mathbb{R}^{d^{\\prime}}\\to \\mathbb{R}$:\n\n$$\nF(w): =\\mathbb{E}_{(x,y)\\sim\\mathcal{D}}\\left[f\\left(y\\Phi(w,x)\\right)\\right].\\tag{2}\n$$\n\nWe introduce our assumptions on the data $(x,y)$ , the model $\\Phi(\\cdot,x)$ , and the loss function $f(\\cdot)$ , below. We start by imposing the following mild assumption on the data distribution."}, {"id": "v25-23-0422:ctx3", "name": "Assumption 1 (Bounded features)", "statement": "Assumption 1 (Bounded features). Assume any $(x,y)\\sim\\mathcal{D}$ has almost surely bounded features, i.e. $\\| x \\| \\leq R$ , and binary label $y \\in \\{\\pm 1 \\}$."}, {"id": "v25-23-0422:ctx4", "name": "Setup: two-layer network model (eq. (3)) and second-layer weights", "statement": "The model $\\Phi:\\mathbb{R}^{d^{\\prime}}\\times\\mathbb{R}^{d}\\to\\mathbb{R}$ is parameterized by trainable weights $w\\in\\mathbb{R}^{d^{\\prime}}$ and takes input $x\\in\\mathbb{R}^{d}$ . For our main results, we assume $\\Phi$ is a one-hidden layer neural-net of m neurons, i.e.\n\n$$\n\\Phi(w,x): =\\frac{1}{\\sqrt{m}}\\sum_{j=1}^{m}a_{j}\\sigma(\\langle w_{j},x\\rangle),\\tag{3}\n$$\n\nwhere $\\sigma:\\mathbb{R}\\to\\mathbb{R}$ is the activation function, $w_{j}\\in\\mathbb{R}^{d}$ denotes the weight vector of the jth hidden neuron and $\\textstyle{\\frac{a_{j}}{\\sqrt{m}}},j\\in [m]$ are the second-layer weights. For the second layer weights, we assume that they are fixed during training taking values $a_{j}\\in\\{\\pm 1\\}$ . We assume that for half of second layer weights $a_{j}=1$ and for the other half $a_{j}= -1$ . On the other hand, all the first-layer weights are updated during training. Thus, the total number of trainable parameters is $d^{\\prime}=m d$ and we denote $w=[w_{1};w_{2};\\ldots;w_{m}]\\in\\mathbb{R}^{d^{\\prime}}$ the vector of trainable weights. Throughout, we make the following assumptions on the activation function."}, {"id": "v25-23-0422:ctx5", "name": "Assumption 2 (Lipschitz and smooth activation)", "statement": "Assumption 2 (Lipschitz and smooth activation). The activation function $\\sigma : \\mathbb{R}\\to \\mathbb{R}$ satisfies the following for non-negative constants $\\ell,L$:\n\n$$\n|\\sigma^{\\prime}(u)|\\leq\\ell,\\quad|\\sigma^{\\prime\\prime}(u)|\\leq L,\\qquad\\forall u\\in\\mathbb{R}.\n$$"}, {"id": "v25-23-0422:ctx6", "name": "Loss class and Assumption 3 (Lipschitz and smooth loss)", "statement": "Next, we discuss conditions on the loss function. Of primal interest is the commonly used logistic loss function $f(u)=\\log(1+e^{-u})$ . However, our results hold for a broader class of convex, non-negative and monotonically decreasing functions $(\\operatorname*{lim}_{u\\to\\infty}f(u)=0)$ that satisfy the following:\n\nAssumption 3 (Lipschitz and smooth loss). The convex loss function $f : \\mathbb{R}\\to \\mathbb{R_{+}}$ satisfies for all $u \\in \\mathbb{R}$\n\n3.A: Lipschitzness: $|f^{\\prime}(u)|\\leq G_{f}$\n\n3.B: Smoothness: $f^{\\prime\\prime}(u)\\leq L_{f}$"}, {"id": "v25-23-0422:ctx7", "name": "Assumption 4 (Self-bounded loss) and normalization G_f = L_f = beta_f = 1", "statement": "Assumption 4 (Self-bounded loss). The convex loss function $f : \\mathbb{R}\\to \\mathbb{R}_{+}$ is self-bounded with some constant $\\beta_{f}>0,\\ i.e.,\\ |f^{\\prime}(u)|\\leq\\beta_{f}f(u),\\forall u\\in\\mathbb{R}$\n\nThe self-boundedness Assumption 4 is the key property of the loss that drives our analysis and justifies the polylogarithmic width requirement, as will become evident. Note that the logistic loss naturally satisfies Assumptions 3.A and 3.B (with $G_{f}=1,L_{f}=1/4)$ , as well as, Assumption 4 with $\\beta_{f}= 1$ . Other interesting examples of loss functions satisfying those assumptions include polynomial losses, with the tail behavior $f(u)=1/u^{\\beta}$ for $\\beta > 0$, which we discuss in Remark 2. To lighten the notation and without loss of generality, we set $G_{f}= L_{f}= \\beta_{f}= 1$ for the rest of the paper. We remark that our training-loss results also hold for the exponential loss $e^{- u}$ . The exponential loss is self-bounded and while it is not Lipschitz or smooth it satisfies a second-order self-bounded property $f^{\\prime\\prime}(u)\\leq f(u)$ , which we can leverage instead; see Appendix A for details."}, {"id": "v25-23-0422:ctx8", "name": "Gradient descent update", "statement": "We present bounds on the train loss and generalization gap of gradient-descent (GD) under the setting of Section 2. Formally, GD with step-size $\\eta > 0$ optimizes (1) by performing the following updates starting from an initialization w0:\n\n$$\n\\forall t\\geq 0:w_{t+1}=w_{t}-\\eta\\nabla\\widehat{F}(w_{t}).\n$$"}, {"id": "v25-23-0422:ctx9", "name": "Definition 1 (Self-bounded weak convexity, eq. (4))", "statement": "Definition 1 (Self-bounded weak convexity). We say a function $\\widehat{F}: \\mathbb{R}^{d^{\\prime}}\\to \\mathbb{R}$ is self-bounded weakly convex if there exists constant $\\kappa > 0$ such that for all w,\n\n$$\n\\lambda_{\\mathrm{min}}\\left(\\nabla^{2}{\\widehat F}(w)\\right)\\geq-\\kappa{\\widehat F}(w).\\tag{4}\n$$\n\nRecall a function $G : \\mathbb{R}^{d^{\\prime}}\\to \\mathbb{R}$ is weakly convex if $\\exists \\kappa \\geq 0$ such that uniformly over all $w\\in\\mathbb{R}^{d^{\\prime}},\\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}G(w)\\right)\\geq-\\kappa$ . If $\\kappa = 0$ , the function is convex. Instead, property (4) lower bounds the curvature by $-\\kappa G(w)$ that changes proportionally with the function value $G(w)$. We explain below how this is exploited in our setting."}, {"id": "v25-23-0422:ctx10", "name": "Definitions for the gradient/Hessian calculations (Appendix D.1, eqs. (50)-(52b))", "statement": "## D.1 Definitions\n\nAssume IID data $(x,y)\\sim\\mathcal{D},x\\in\\mathbb{R}^{d},y\\in\\{\\pm 1\\}$ . Denote for convenience $z : = y x$ . Suppose two-layer neural network model\n\n$$\n\\Phi(w,x_{i})=\\frac{1}{\\sqrt{m}}\\sum_{j\\in [m]}a_{j}\\sigma(\\langle w_{j},x\\rangle)\\tag{50}\n$$\n\n$a_{j}\\in \\{\\pm 1 \\}, j \\in [ m ]$ and first-layer weights trained by GD on\n\n$$\n\\widehat F(w)=\\frac{1}{n}\\sum_{i\\in [n]}f(y_{i}\\Phi(w,x_{i}))= :\\frac{1}{n}\\sum_{i\\in [n]}f(w,z_{i}).\\tag{51}\n$$\n\nfor loss function $f : \\mathbb{R}\\to \\mathbb{R}$\n\nFor convenience define\n\n$$\n\\widehat{F}^{\\prime}(w)=\\frac{1}{n}\\sum_{i\\in [n]}\\vert f^{\\prime}(y_{i}\\Phi(w,x_{i}))\\vert\\tag{52a}\n$$\n\n$$\n\\widehat{F}^{\\prime\\prime}(w)=\\frac{1}{n}\\sum_{i\\in [n]}|f^{\\prime\\prime}\\left(y_{i}\\Phi(w,x_{i})\\right)|\\tag{52b}\n$$"}, {"id": "v25-23-0422:ctx11", "name": "Corollary D.2.1 (Self-boundedness of Objective)", "statement": "Corollary D.2.1 (Self-boundedness of Objective). Let Assumption 2 hold. If the loss satisfies Assumptions 4 (with $\\beta_{f}=1)$ and 8, then\n\n1. $\\lVert\\nabla\\widehat{F}(w)\\rVert\\leq\\ell R\\widehat{F}(w)$\n\n$$\n\\begin{array}{r}{2.\\|\\nabla^{2}\\widehat{F}(w)\\|{\\le}\\left(\\ell^{2}R^{2}+\\frac{LR^{2}}{\\sqrt{m}}\\right)\\widehat{F}(w).}\\end{array}\n$$\n\n3. $\\begin{array}{r}{\\lambda_{\\operatorname*{min}}\\left(\\nabla^{2}\\widehat{F}(w)\\right)\\geq-\\frac{L R^{2}}{\\sqrt{m}}\\widehat{F}(w).}\\end{array}$\n\nIf in addition the loss satisfies Assumptions 3.A and 3.B with $L_{f}= G_{f}= 1$ , then\n\n6. $\\lVert\\nabla\\widehat{F}(w)\\rVert\\leq\\ell R.$\n\n$$\n\\begin{array}{r}{7.\\ \\|\\nabla^{2}\\widehat{F}(w)\\|\\le\\ell^{2}R^{2}+\\frac{LR^{2}}{\\sqrt{m}}.}\\end{array}\n$$"}, {"id": "v25-23-0422:ctx12", "name": "Assumption 5 (NN-Realizability)", "statement": "Assumption 5 (NN-Realizability). There exists a decreasing function $g : \\mathbb{R}_{+}\\to \\mathbb{R}_{+}$ which measures the norm of deviations from initialization of models that achieve arbitrarily small training error.\n\nFormally, for almost surely all n training samples and for any sufficiently small $\\varepsilon > 0$ there exists $\\boldsymbol{w}^{(\\varepsilon)}\\in\\mathbb{R}^{d^{\\prime}}$ such that\n\n$$\n{\\widehat F}(w^{(\\varepsilon)})\\leq\\varepsilon,\\ and\\ g(\\varepsilon)=\\Big\\|w^{(\\varepsilon)}-w_{0}\\Big\\|.\n$$\n\nSince Assumption 5 holds for arbitrarily small ε, it guarantees that the model has enough capacity to interpolate the data, i.e., attain train error that is arbitrarily small (ε). Additionally, this is accomplished for model weights whose distance from initialization is managed by the function $g(\\varepsilon)$ . By using these model weights to select w in Theorem 3.2 we obtain train loss bounds for interpolating models."}, {"id": "v25-23-0422:ctx13", "name": "Assumption 8 (2nd order self-boundedness)", "statement": "Assumption 8 (2nd order self-boundedness). The convex loss function $f : \\mathbb{R}\\to \\mathbb{R}_{+}$ satisfies the 2nd order self-boundedness property, i.e.\n\n$$\nf^{\\prime\\prime}(u)\\leq f(u),\\forall u\\in\\mathbb{R}.\n$$"}, {"id": "v25-23-0422:ctx14", "name": "Theorem A.1 (General statement of Theorem 3.2)", "statement": "Theorem A.1 (General statement of Theorem 3.2). Let Assumptions 1-2 hold. Assume the loss function satisfies self-bounded Assumption 4. Moreover, suppose either Assumption 3 or Assumption 8 hold. Fix any $T \\geq 0$ . Let the step-size satisfy the assumptions of the descent lemma (Lemma A.2). Assume any w and m such that $\\| w - w_{0}\\|^{2}\\ge$ max $\\left\\{\\eta T\\widehat{F}(w),\\eta\\widehat{F}(w_{0})\\right\\}$ and $m\\geq 18^{2}L^{2}R^{4}\\|w-w_{0}\\|^{4}$ . Then, the training loss and the parameters' norm satisfy\n\n$$\n\\begin{array}{r l r}{{\\frac{1}{T}\\sum_{t=1}^{T}\\widehat{F}(w_{t})\\leq 2\\widehat{F}(w)+\\frac{5\\|w-w_{0}\\|^{2}}{2\\eta T},}}\\\\ &{}&{\\forall t\\in [T]\\ :\\ \\|w_{t}-w_{0}\\|\\leq 4\\|w-w_{0}\\|.}\\end{array}\\tag{16}\n$$"}, {"id": "v25-23-0422:ctx15", "name": "Lemma A.2 (Descent lemma)", "statement": "Lemma A.2 (Descent lemma). Let Assumptions 1-2 hold. Assume the loss function satisfies self-boundedness Assumptions 4, 8. Then, for any $\\begin{array}{r}{\\eta<\\frac{1}{R^{2}\\widehat{F}(w_{t})}\\operatorname*{min}\\{\\frac{1}{\\ell^{2}+L},\\frac{1}{\\sqrt{L}\\ell}\\}}\\end{array}$ the descent property holds, i.e.,\n\n$$\n\\widehat{F}(w_{t+1})\\leq\\widehat{F}(w_{t})-\\frac{\\eta}{2}\\|\\nabla\\widehat{F}(w_{t})\\|^{2}.\n$$\n\nMoreover, if f satisfies Assumption 3 then the descent property holds for any $\\eta \\leq 1 / L_{\\widehat{F}}$ where $\\begin{array}{r}{L_{\\widehat{F}}: = \\ell^{2}R^{2}+ \\frac{L R^{2}}{\\sqrt{m}}}\\end{array}$ is the smoothness parameter of the training objective."}, {"id": "v25-23-0422:ctx16", "name": "Remark 1 (Example: linearly-separable data)", "statement": "Remark 1 (Example: Linearly-separable data). Consider logistic-loss minimization, tanh activation $\\begin{array}{r}{\\sigma(u)=\\frac{e^{u}-e^{-u}}{e^{u}+e^{-u}}}\\end{array}$ and data distribution that is linearly separable with margin γ, $i . e .$ , for almost surely all n samples there exists unit-norm vector $v^{\\star}\\in \\mathbb{R}^{d}$ such that $\\mathrm{min}_{i\\in [n]}y_{i}\\langle v^{\\star},x_{i}\\rangle=\\gamma$. We initialize the weights to zero, i.e. $w_{0}~ = ~ 0$ and show that the realizability Assumption 5 naturally holds in this setting. To see this, for any fixed $\\varepsilon > 0$ , set $\\alpha=2\\log(1/\\varepsilon)/\\gamma\\sqrt{m}$ and assume m $\\geq 4\\log^{2}(1/\\varepsilon)$ . With this choice, select weights $\\begin{array}{r}{w_{j}^{(\\varepsilon)}: =\\alpha v^{\\star},a_{j}=\\frac{1}{\\sqrt{m}}\\ for\\ j\\in [1,\\cdot\\cdot\\cdot,\\frac{m}{2}]}\\end{array}$ and $\\begin{array}{r}{w_{j}^{(\\varepsilon)}: = -\\alpha v^{\\star},a_{j}=\\frac{-1}{\\sqrt{m}}\\ for\\ j\\in\\{\\frac{m}{2}+1,\\cdot\\cdot\\cdot,m\\}}\\end{array}$ Then, the model output for any sample $(x_{i},y_{i})$ satisfies\n\n$$\n\\begin{array}{r l}&{y_{i}\\Phi(w^{(\\varepsilon)},x_{i})=\\displaystyle\\frac{y_{i}\\sqrt{m}}{2}\\left(\\sigma(\\alpha\\langle v^{\\star},x_{i}\\rangle)-\\sigma(-\\alpha\\langle v^{\\star},x_{i}\\rangle)\\right)}\\\\ &{\\quad\\quad\\quad=y_{i}\\sqrt{m}\\sigma(\\alpha\\langle v^{\\star},x_{i}\\rangle)\\ge\\sqrt{m}\\sigma(\\alpha\\gamma)\\ge\\displaystyle\\frac{\\sqrt{m}}{2}\\alpha\\gamma=\\log(1/\\varepsilon),}\\end{array}\n$$\n\nwhere the second equality uses the fact that tanh is odd, the first inequality follows by the increasing nature of tanh and data separability, and the last inequality follows since $\\alpha \\gamma \\leq 1$ and $\\sigma(u)\\geq u/2$ for all $u\\in [0,1]$ . Thus, the loss satisfies $\\widehat{F}(w^{(\\varepsilon)})\\leq\\varepsilon$ since for the logistic function log $\\left(1+e^{u}\\right)\\leq e^{u}$ . Moreover, our choice of α implies $g(\\varepsilon)=\\|w^{(\\varepsilon)}-w_{0}\\|=$ $\\|w^{(\\varepsilon)}\\|{=}\\alpha\\sqrt{m}=2\\log(1/\\varepsilon)/\\gamma$ . To conclude, the NN-Realizability Assumption 5 holds with $g(\\varepsilon)=2\\log(1/\\varepsilon)/\\gamma$ and thus applying Theorems 3.3 and 3.5 shows that with $m=\\Omega(\\log^{4}(T))$ neurons, the training loss and generalization gap are respectively bounded by $\\begin{array}{r}{{\\tilde{O}}(\\frac{1}{\\gamma^{2}T})}\\end{array}$ and $\\begin{array}{r}{{\\cal\\tilde{O}}(\\frac{1}{\\gamma^{2}n})}\\end{array}$ , which are known to be optimal under this data assumption. We note that the same conclusion as above holds for other smooth activations such as Softmax or GELU."}, {"id": "v25-23-0422:ctx17", "name": "Section 4: NTK separability, initialization bound, Proposition 4.1 (eq. (9))", "statement": "In this section, we interpret our results for NTK-separable data by showing that our realizability condition holds for this class. We recall the definition of NTK-separability below Nitanda et al. (2019); Chen et al. (2020); Cao and Gu (2020).\n\nAssumption 6 (Separability by NTK). For almost surely all n training samples from the data distribution there exists $w^{\\star}\\in \\mathbb{R}^{d^{\\prime}}$ and $\\gamma > 0$ such that $\\| w^{\\star}\\| = 1$ and for all $i \\in [ n ]$ ,\n\n$$\n\\begin{array}{r}{y_{i}\\Bigl\\langle\\nabla_{1}\\Phi(w_{0},x_{i}),w^{\\star}\\Bigr\\rangle\\geq\\gamma .}\\end{array}\\tag{8}\n$$\n\nWe also assume a bound on the model's output at initialization. Similar assumptions, but for the value of the loss, also appear in prior works that study generalization using the algorithmic stability framework Richards and Kuzborskij (2021); Lei et al. (2022).\n\nAssumption 7 (Initialization bound). There exists parameter C such that $\\forall i \\in [ n ] \\ :$ $|\\Phi(w_{0},x_{i})|\\leq C,$ for almost surely all n training samples from the data distribution\n\nThe next proposition relates the NTK-separability assumption to our realizability assumption. The proofs for this section are given in Appendix C.\n\nProposition 4.1 (Realizability of NTK-separable data). Let Assumptions $1-2,6-7$ hold. Assume f (·) to be the logistic loss. Fix $\\varepsilon > 0$ and let $\\begin{array}{r}{m\\geq\\frac{L^{2}R^{4}}{4\\gamma^{4}C^{2}}(2C+\\log(1/\\varepsilon))^{4}}\\end{array}$ . Then the realizability Assumption 5 holds with $\\begin{array}{r}{g(\\varepsilon)=\\frac{1}{\\gamma}(2C+\\log(1/\\varepsilon))}\\end{array}$ . In other words, there exists $w^{(\\varepsilon)}$ such that\n\n$$\n\\widehat{F}(w^{(\\varepsilon)})\\leq\\varepsilon,\\quad and\\quad\\left\\|w^{(\\varepsilon)}-w_{0}\\right\\|=\\frac{1}{\\gamma}\\left(2C+\\log(1/\\varepsilon)\\right).\\tag{9}\n$$"}], "lean": "import Mathlib\n\nopen scoped RealInnerProductSpace BigOperators\n\nnamespace ResearchLevel\n\nabbrev Params (m d : ℕ) := PiLp 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d))\n\nnoncomputable def phi {m d : ℕ} (a : Fin m → ℝ) (σ : ℝ → ℝ)\n (w : Params m d) (x : EuclideanSpace ℝ (Fin d)) : ℝ :=\n (1 / Real.sqrt (m : ℝ)) * ∑ j : Fin m, a j * σ (inner ℝ (w j) x)\n\nnoncomputable def Fhat {m d n : ℕ} (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (w : Params m d) : ℝ :=\n (1 / (n : ℝ)) * ∑ i : Fin n, f (ys i * phi a σ w (xs i))\n\nnoncomputable def FhatI {m d n : ℕ} (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (i : Fin n) (w : Params m d) : ℝ :=\n f (ys i * phi a σ w (xs i))\n\nnoncomputable def gdSeq {m d n : ℕ} (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (η : ℝ) (w0 : Params m d) : ℕ → Params m d\n | 0 => w0\n | (t + 1) =>\n gdSeq a σ f xs ys η w0 t - η • gradient (Fhat a σ f xs ys) (gdSeq a σ f xs ys η w0 t)\n\ntheorem lemma3_1 {m d n : ℕ} (hm : 0 < m) (hn : 0 < n)\n (R ℓ L : ℝ) (hR : 0 ≤ R) (hℓ : 0 ≤ ℓ) (hL : 0 ≤ L)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hbal : (∑ j, a j) = 0)\n (σ f : ℝ → ℝ)\n (hσ : Differentiable ℝ σ) (hσd : Differentiable ℝ (deriv σ)) (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (hσ'' : ∀ u, |deriv (deriv σ) u| ≤ L)\n (hf : Differentiable ℝ f) (hfd : Differentiable ℝ (deriv f)) (hfpos : ∀ u, 0 ≤ f u)\n\n (hfconv : ConvexOn ℝ Set.univ f)\n (hfsb : ∀ u, |deriv f u| ≤ f u)\n (hfdec : Antitone f)\n (hflim : Filter.Tendsto f Filter.atTop (nhds 0))\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (w : Params m d) :\n (∀ i, ‖gradient (FhatI a σ f xs ys i) w‖ ≤ ℓ * R * FhatI a σ f xs ys i w)\n ∧ (∀ v : Params m d,\n -(L * R ^ 2 / Real.sqrt (m : ℝ)) * Fhat a σ f xs ys w * ‖v‖ ^ 2\n ≤ iteratedFDeriv ℝ 2 (Fhat a σ f xs ys) w (fun _ => v)) := by\n sorry\n\ntheorem thm3_2 {m d n : ℕ} (hm : 0 < m) (hn : 0 < n) (T : ℕ) (hT : 0 < T)\n (R ℓ L LF η : ℝ) (hR : 0 ≤ R) (hℓ : 0 ≤ ℓ) (hL : 0 ≤ L)\n (hLF : 0 < LF) (hη0 : 0 < η) (hη : η ≤ 1 / LF)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hbal : (∑ j, a j) = 0)\n (σ f : ℝ → ℝ)\n (hσ : Differentiable ℝ σ) (hσd : Differentiable ℝ (deriv σ)) (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (hσ'' : ∀ u, |deriv (deriv σ) u| ≤ L)\n (hf : Differentiable ℝ f) (hfd : Differentiable ℝ (deriv f)) (hfpos : ∀ u, 0 ≤ f u)\n (hfconv : ConvexOn ℝ Set.univ f) (hf' : ∀ u, |deriv f u| ≤ 1)\n (hf'' : ∀ u, deriv (deriv f) u ≤ 1) (hfsb : ∀ u, |deriv f u| ≤ f u)\n (hfdec : Antitone f)\n (hflim : Filter.Tendsto f Filter.atTop (nhds 0))\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (w0 w : Params m d)\n (hsmooth : ∀ u v, ‖gradient (Fhat a σ f xs ys) u - gradient (Fhat a σ f xs ys) v‖\n ≤ LF * ‖u - v‖)\n (hnorm : ‖w - w0‖ ^ 2 ≥ max (η * T * Fhat a σ f xs ys w) (η * Fhat a σ f xs ys w0))\n (hwidth : (m : ℝ) ≥ 18 ^ 2 * L ^ 2 * R ^ 4 * ‖w - w0‖ ^ 4) :\n let ws := gdSeq a σ f xs ys η w0\n Fhat a σ f xs ys (ws T)\n ≤ (1 / (T : ℝ)) * ∑ t ∈ Finset.Icc 1 T, Fhat a σ f xs ys (ws t)\n ∧ (1 / (T : ℝ)) * ∑ t ∈ Finset.Icc 1 T, Fhat a σ f xs ys (ws t)\n ≤ 2 * Fhat a σ f xs ys w + 5 * ‖w - w0‖ ^ 2 / (2 * η * (T : ℝ))\n ∧ ∀ t, 1 ≤ t → t ≤ T → ‖ws t - w0‖ ≤ 4 * ‖w - w0‖ := by\n sorry\n\ntheorem thm3_3 {m d n : ℕ} (hm : 0 < m) (hn : 0 < n) (T : ℕ) (hT : 0 < T)\n (R ℓ L LF η : ���) (hR : 0 ≤ R) (hℓ : 0 ≤ ℓ) (hL : 0 ≤ L)\n (hLF : 0 < LF) (hη0 : 0 < η)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hbal : (∑ j, a j) = 0)\n (σ f : ℝ → ℝ)\n (hσ : Differentiable ℝ σ) (hσd : Differentiable ℝ (deriv σ)) (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (hσ'' : ∀ u, |deriv (deriv σ) u| ≤ L)\n (hf : Differentiable ℝ f) (hfd : Differentiable ℝ (deriv f)) (hfpos : ∀ u, 0 ≤ f u)\n (hfconv : ConvexOn ℝ Set.univ f) (hf' : ∀ u, |deriv f u| ≤ 1)\n (hf'' : ∀ u, deriv (deriv f) u ≤ 1) (hfsb : ∀ u, |deriv f u| ≤ f u)\n (hfdec : Antitone f)\n (hflim : Filter.Tendsto f Filter.atTop (nhds 0))\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (w0 : Params m d)\n (hsmooth : ∀ u v, ‖gradient (Fhat a σ f xs ys) u - gradient (Fhat a σ f xs ys) v‖\n ≤ LF * ‖u - v‖)\n (g : ℝ → ℝ) (hgpos : ∀ ε, 0 < ε → 0 < g ε)\n (hgdec : ∀ ε₁ ε₂, 0 < ε₁ → ε₁ ≤ ε₂ → g ε₂ ≤ g ε₁)\n\n (ε₀ : ℝ) (hε₀ : 0 < ε₀)\n (hreal : ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ wε : Params m d,\n Fhat a σ f xs ys wε ≤ ε ∧ ‖wε - w0‖ = g ε)\n (hTsmall : 1 / (T : ℝ) ≤ ε₀)\n (hFw0 : 0 < Fhat a σ f xs ys w0)\n (hη : η ≤ min (1 / LF) (min (g 1 ^ 2) (g 1 ^ 2 / Fhat a σ f xs ys w0)))\n (hwidth : (m : ℝ) ≥ 18 ^ 2 * L ^ 2 * R ^ 4 * g (1 / (T : ℝ)) ^ 4) :\n let ws := gdSeq a σ f xs ys η w0\n Fhat a σ f xs ys (ws T)\n ≤ 2 / (T : ℝ) + 5 * g (1 / (T : ℝ)) ^ 2 / (2 * η * (T : ℝ))\n ∧ ∀ t, 1 ≤ t → t ≤ T → ‖ws t - w0‖ ≤ 4 * g (1 / (T : ℝ)) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen scoped RealInnerProductSpace BigOperators\n\nnamespace ResearchLevel\n\nabbrev Params (m d : ℕ) := PiLp 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d))\n\nnoncomputable def phi {m d : ℕ} (a : Fin m → ℝ) (σ : ℝ → ℝ)\n (w : Params m d) (x : EuclideanSpace ℝ (Fin d)) : ℝ :=\n (1 / Real.sqrt (m : ℝ)) * ∑ j : Fin m, a j * σ (inner ℝ (w j) x)\n\nnoncomputable def Fhat {m d n : ℕ} (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (w : Params m d) : ℝ :=\n (1 / (n : ℝ)) * ∑ i : Fin n, f (ys i * phi a σ w (xs i))\n\nnoncomputable def FhatI {m d n : ℕ} (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (i : Fin n) (w : Params m d) : ℝ :=\n f (ys i * phi a σ w (xs i))\n\nnoncomputable def gdSeq {m d n : ℕ} (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (η : ℝ) (w0 : Params m d) : ℕ → Params m d\n | 0 => w0\n | (t + 1) =>\n gdSeq a σ f xs ys η w0 t - η • gradient (Fhat a σ f xs ys) (gdSeq a σ f xs ys η w0 t)\n\nsection Abstract\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E]\n\nlemma hasDerivAt_lineE (u v : E) (t : ℝ) : HasDerivAt (fun s : ℝ => u + s • v) v t := by\n have h : HasDerivAt (fun s : ℝ => s • v) v t := by\n simpa using (hasDerivAt_id t).smul_const v\n simpa using h.const_add u\n\nlemma fderiv_apply_eq_inner {F : E → ℝ} {x : E} (hF : DifferentiableAt ℝ F x) (v : E) :\n fderiv ℝ F x v = inner ℝ (gradient F x) v := by\n have h := hF.hasGradientAt.hasFDerivAt\n rw [h.fderiv]\n rfl\n\nlemma hasDerivAt_line_gradient {F : E → ℝ} (hF : Differentiable ℝ F) (u v : E) (t : ℝ) :\n HasDerivAt (fun s : ℝ => F (u + s • v)) (inner ℝ (gradient F (u + t • v)) v) t := by\n have h := (hF (u + t • v)).hasFDerivAt.comp_hasDerivAt t (hasDerivAt_lineE u v t)\n rw [← fderiv_apply_eq_inner (hF _) v]\n exact h\n\n/-- If `ψ'' ≥ -C` on `[0,b]` then `ψ b ≥ ψ 0 + ψ' 0 * b - C b²/2`. -/\nlemma taylor_lower_bound (ψ ψ' ψ'' : ℝ → ℝ) (b C : ℝ) (hb : 0 ≤ b)\n (h1 : ∀ t, HasDerivAt ψ (ψ' t) t) (h2 : ∀ t, HasDerivAt ψ' (ψ'' t) t)\n (h3 : ∀ t ∈ Set.Icc (0:ℝ) b, -C ≤ ψ'' t) :\n ψ 0 + ψ' 0 * b - C * b^2/2 ≤ ψ b := by\n set g : ℝ → ℝ := fun t => ψ t - ψ 0 - ψ' 0 * t + C * t^2/2 with hgdef\n set g' : ℝ → ℝ := fun t => ψ' t - ψ' 0 + C * t with hg'def\n have hgd : ∀ t, HasDerivAt g (g' t) t := by\n intro t\n have e1 : HasDerivAt (fun s : ℝ => ψ s - ψ 0 - ψ' 0 * s) (ψ' t - ψ' 0) t := by\n have := ((h1 t).sub_const (ψ 0)).sub ((hasDerivAt_id t).const_mul (ψ' 0))\n simpa using this\n have e2 : HasDerivAt (fun s : ℝ => C * s^2/2) (C * t) t := by\n have := ((hasDerivAt_pow 2 t).const_mul C).div_const 2\n simp at this\n convert this using 1\n ring\n simpa [hgdef, hg'def] using e1.add e2\n have hg'd : ∀ t, HasDerivAt g' (ψ'' t + C) t := by\n intro t\n have := ((h2 t).sub_const (ψ' 0)).add ((hasDerivAt_id t).const_mul C)\n simpa using this\n have hmono' : MonotoneOn g' (Set.Icc 0 b) := by\n apply monotoneOn_of_deriv_nonneg (convex_Icc 0 b)\n · exact fun t _ => ((hg'd t).continuousAt).continuousWithinAt\n · exact fun t _ => (hg'd t).differentiableAt.differentiableWithinAt\n · intro t ht\n rw [(hg'd t).deriv]\n rw [interior_Icc] at ht\n have := h3 t ⟨le_of_lt ht.1, le_of_lt ht.2⟩\n linarith\n have hg'0 : g' 0 = 0 := by simp [hg'def]\n have hg'nonneg : ∀ t ∈ Set.Icc (0:ℝ) b, 0 ≤ g' t := by\n intro t ht\n have := hmono' (Set.left_mem_Icc.mpr hb) ht ht.1\n rw [hg'0] at this\n exact this\n have hmono : MonotoneOn g (Set.Icc 0 b) := by\n apply monotoneOn_of_deriv_nonneg (convex_Icc 0 b)\n · exact fun t _ => ((hgd t).continuousAt).continuousWithinAt\n · exact fun t _ => (hgd t).differentiableAt.differentiableWithinAt\n · intro t ht\n rw [(hgd t).deriv]\n rw [interior_Icc] at ht\n exact hg'nonneg t ⟨le_of_lt ht.1, le_of_lt ht.2⟩\n have h0 : g 0 = 0 := by simp [hgdef]\n have := hmono (Set.left_mem_Icc.mpr hb) (Set.right_mem_Icc.mpr hb) hb\n rw [h0] at this\n simp only [hgdef] at this\n linarith\n\n/-- Along every line, `F` has first and second derivatives, with the second derivative bounded\nbelow by `-κ ‖v‖² F`. -/\ndef LineSecondDeriv (F : E → ℝ) (κ : ℝ) : Prop :=\n ∀ u v : E, ∃ G' G'' : ℝ → ℝ,\n (∀ t, HasDerivAt (fun s : ℝ => F (u + s • v)) (G' t) t) ∧\n (∀ t, HasDerivAt G' (G'' t) t) ∧\n (∀ t, -(κ * ‖v‖^2 * F (u + t • v)) ≤ G'' t)\n\nlemma quasi_convex {F : E → ℝ} {κ : ℝ} (hκ : 0 ≤ κ) (hFpos : ∀ x, 0 ≤ F x)\n (hLS : LineSecondDeriv F κ) (u v : E) (hd : κ * ‖v - u‖^2 ≤ 1/2)\n (t : ℝ) (ht : t ∈ Set.Icc (0:ℝ) 1) :\n F (u + t • (v - u)) ≤ (4/3) * max (F u) (F v) := by\n obtain ⟨G', G'', hG1, hG2, hG3⟩ := hLS u (v - u)\n set ψ : ℝ → ℝ := fun s => F (u + s • (v - u)) with hψdef\n have hcont : ContinuousOn ψ (Set.Icc 0 1) :=\n fun s _ => ((hG1 s).continuousAt).continuousWithinAt\n obtain ⟨α, hα, hmax⟩ :=\n (isCompact_Icc (a := (0:ℝ)) (b := 1)).exists_isMaxOn ⟨0, by norm_num⟩ hcont\n have hψ0 : ψ 0 = F u := by simp [hψdef]\n have hψ1 : ψ 1 = F v := by simp [hψdef]\n have hMnn : 0 ≤ ψ α := hFpos _\n have hmaxnn : 0 ≤ max (F u) (F v) := le_trans (hFpos u) (le_max_left _ _)\n have hkey : ψ α ≤ (4/3) * max (F u) (F v) := by\n rcases eq_or_lt_of_le hα.1 with h0 | h0\n · rw [← h0, hψ0]\n have : F u ≤ max (F u) (F v) := le_max_left _ _\n linarith\n rcases eq_or_lt_of_le hα.2 with h1 | h1\n · rw [h1, hψ1]\n have : F v ≤ max (F u) (F v) := le_max_right _ _\n linarith\n -- interior case\n have hnbhd : Set.Icc (0:ℝ) 1 ∈ nhds α := by\n apply Icc_mem_nhds h0 h1\n have hlocmax : IsLocalMax ψ α := hmax.isLocalMax hnbhd\n have hG'α : G' α = 0 := by\n rw [← (hG1 α).deriv]\n exact hlocmax.deriv_eq_zero\n have hsub : ∀ s : ℝ, HasDerivAt (fun r : ℝ => α - r) (-1) s := by\n intro s\n simpa using (hasDerivAt_id s).const_sub α\n have hχ1 : ∀ s : ℝ, HasDerivAt (fun r : ℝ => ψ (α - r)) (-G' (α - s)) s := by\n intro s\n have h := (hG1 (α - s)).comp s (hsub s)\n simpa using h\n have hχ2 : ∀ s : ℝ, HasDerivAt (fun r : ℝ => -G' (α - r)) (G'' (α - s)) s := by\n intro s\n have h := ((hG2 (α - s)).comp s (hsub s)).neg\n simpa using h\n set C : ℝ := κ * ‖v - u‖^2 * ψ α with hCdef\n have hbound : ∀ s ∈ Set.Icc (0:ℝ) α, -C ≤ G'' (α - s) := by\n intro s hs\n have hmem : α - s ∈ Set.Icc (0:ℝ) 1 := by\n constructor\n · linarith [hs.2]\n · linarith [hs.1, hα.2]\n have h1' : ψ (α - s) ≤ ψ α := hmax hmem\n have h2' := hG3 (α - s)\n have hkκ : 0 ≤ κ * ‖v - u‖^2 := by positivity\n have : κ * ‖v - u‖^2 * ψ (α - s) ≤ κ * ‖v - u‖^2 * ψ α :=\n mul_le_mul_of_nonneg_left h1' hkκ\n have h3' : -(κ * ‖v - u‖^2 * ψ α) ≤ -(κ * ‖v - u‖^2 * ψ (α - s)) := by linarith\n exact le_trans h3' h2'\n have htay := taylor_lower_bound (fun r : ℝ => ψ (α - r)) (fun s => -G' (α - s))\n (fun s => G'' (α - s)) α C hα.1 hχ1 hχ2 hbound\n simp only [sub_zero, sub_self] at htay\n rw [hG'α] at htay\n have hα2 : α^2 ≤ 1 := by nlinarith [hα.1, hα.2]\n have hkκ : 0 ≤ κ * ‖v - u‖^2 := by positivity\n have hCα : C * α^2/2 ≤ ψ α / 4 := by\n rw [hCdef]\n have a2 : 0 ≤ κ * ‖v - u‖^2 * ψ α := mul_nonneg hkκ hMnn\n have step1 : κ * ‖v - u‖^2 * ψ α * α^2 ≤ κ * ‖v - u‖^2 * ψ α := by nlinarith\n have step2 : κ * ‖v - u‖^2 * ψ α ≤ (1/2) * ψ α := mul_le_mul_of_nonneg_right hd hMnn\n linarith\n have hFu : F u ≤ max (F u) (F v) := le_max_left _ _\n rw [hψ0] at htay\n linarith\n exact le_trans (hmax ht) hkey\n\nlemma key_lower {F : E → ℝ} {κ : ℝ} (hκ : 0 ≤ κ) (hFpos : ∀ x, 0 �� F x)\n (hFdiff : Differentiable ℝ F) (hLS : LineSecondDeriv F κ) (u v : E)\n (hd : κ * ‖v - u‖^2 ≤ 1/2) :\n F u + inner ℝ (gradient F u) (v - u) - (1/3) * (F u + F v) ≤ F v := by\n obtain ⟨G', G'', hG1, hG2, hG3⟩ := hLS u (v - u)\n have hψ0 : F (u + (0:ℝ) • (v - u)) = F u := by simp\n have hψ1 : F (u + (1:ℝ) • (v - u)) = F v := by simp\n have hG'0 : G' 0 = inner ℝ (gradient F u) (v - u) := by\n have h1 : HasDerivAt (fun s : ℝ => F (u + s • (v - u)))\n (inner ℝ (gradient F (u + (0:ℝ) • (v - u))) (v - u)) 0 :=\n hasDerivAt_line_gradient hFdiff u (v - u) 0\n have h2 := (hG1 0).unique h1\n rw [h2]\n simp\n have hkκ : 0 ≤ κ * ‖v - u‖^2 := by positivity\n have hbound : ∀ s ∈ Set.Icc (0:ℝ) 1,\n -(κ * ‖v - u‖^2 * ((4/3) * max (F u) (F v))) ≤ G'' s := by\n intro s hs\n have h1 := hG3 s\n have h2 : F (u + s • (v - u)) ≤ (4/3) * max (F u) (F v) :=\n quasi_convex hκ hFpos hLS u v hd s hs\n have h3 : κ * ‖v - u‖^2 * F (u + s • (v - u))\n ≤ κ * ‖v - u‖^2 * ((4/3) * max (F u) (F v)) := mul_le_mul_of_nonneg_left h2 hkκ\n linarith\n have htay := taylor_lower_bound (fun s : ℝ => F (u + s • (v - u))) G' G'' 1\n (κ * ‖v - u‖^2 * ((4/3) * max (F u) (F v))) (by norm_num) hG1 hG2 hbound\n simp only [one_pow, mul_one] at htay\n rw [hψ0, hψ1, hG'0] at htay\n have hmax : max (F u) (F v) ≤ F u + F v := by\n rcases max_cases (F u) (F v) with ⟨h, _⟩ | ⟨h, _⟩ <;> rw [h] <;> linarith [hFpos u, hFpos v]\n have hmaxnn : 0 ≤ max (F u) (F v) := le_trans (hFpos u) (le_max_left _ _)\n have hCle : κ * ‖v - u‖^2 * ((4/3) * max (F u) (F v)) / 2 ≤ (1/3) * (F u + F v) := by\n have h1 : κ * ‖v - u‖^2 * ((4/3) * max (F u) (F v))\n ≤ (1/2) * ((4/3) * max (F u) (F v)) :=\n mul_le_mul_of_nonneg_right hd (by linarith)\n linarith\n linarith\n\nlemma smooth_upper {F : E → ℝ} (hFdiff : Differentiable ℝ F) {LF : ℝ} (hLF : 0 ≤ LF)\n (hsmooth : ∀ u v : E, ‖gradient F u - gradient F v‖ ≤ LF * ‖u - v‖) (x y : E) :\n F y ≤ F x + inner ℝ (gradient F x) (y - x) + LF/2 * ‖y - x‖^2 := by\n set δ : E := y - x with hδ\n set c : ℝ := inner ℝ (gradient F x) δ with hc\n set h : ℝ → ℝ := fun t => F x + t * c + LF/2 * t^2 * ‖δ‖^2 - F (x + t • δ) with hhdef\n set h' : ℝ → ℝ := fun t => c + LF * t * ‖δ‖^2 - inner ℝ (gradient F (x + t • δ)) δ with hh'def\n have hhd : ∀ t, HasDerivAt h (h' t) t := by\n intro t\n have e1 : HasDerivAt (fun s : ℝ => F x + s * c) c t := by\n simpa using ((hasDerivAt_id t).mul_const c).const_add (F x)\n have e2 : HasDerivAt (fun s : ℝ => LF/2 * s^2 * ‖δ‖^2) (LF * t * ‖δ‖^2) t := by\n have := (((hasDerivAt_pow 2 t).const_mul (LF/2)).mul_const (‖δ‖^2))\n simp only [Nat.cast_ofNat, pow_one, Nat.add_one_sub_one] at this\n convert this using 1\n ring\n have e3 : HasDerivAt (fun s : ℝ => F (x + s • δ))\n (inner ℝ (gradient F (x + t • δ)) δ) t := hasDerivAt_line_gradient hFdiff x δ t\n have := (e1.add e2).sub e3\n simpa [hhdef, hh'def] using this\n have hnn : ∀ t ∈ Set.Icc (0:ℝ) 1, 0 ≤ h' t := by\n intro t ht\n have hip : inner ℝ (gradient F (x + t • δ) - gradient F x) δ\n ≤ ‖gradient F (x + t • δ) - gradient F x‖ * ‖δ‖ := real_inner_le_norm _ _\n have hsm : ‖gradient F (x + t • δ) - gradient F x‖ ≤ LF * (t * ‖δ‖) := by\n have := hsmooth (x + t • δ) x\n have he : ‖x + t • δ - x‖ = t * ‖δ‖ := by\n rw [add_sub_cancel_left, norm_smul, Real.norm_eq_abs, abs_of_nonneg ht.1]\n rwa [he] at this\n have hexp : inner ℝ (gradient F (x + t • δ) - gradient F x) δ\n = inner ℝ (gradient F (x + t • δ)) δ - c := by\n rw [hc, inner_sub_left]\n have hd0 : 0 ≤ ‖δ‖ := norm_nonneg _\n have : inner ℝ (gradient F (x + t • δ)) δ - c ≤ LF * (t * ‖δ‖) * ‖δ‖ := by\n rw [← hexp]\n exact le_trans hip (mul_le_mul_of_nonneg_right hsm hd0)\n simp only [hh'def]\n nlinarith\n have hmono : MonotoneOn h (Set.Icc 0 1) := by\n apply monotoneOn_of_deriv_nonneg (convex_Icc 0 1)\n · exact fun t _ => ((hhd t).continuousAt).continuousWithinAt\n · exact fun t _ => (hhd t).differentiableAt.differentiableWithinAt\n · intro t ht\n rw [(hhd t).deriv]\n rw [interior_Icc] at ht\n exact hnn t ⟨le_of_lt ht.1, le_of_lt ht.2⟩\n have h0 : h 0 = 0 := by simp [hhdef]\n have h1 := hmono (Set.left_mem_Icc.mpr (by norm_num : (0:ℝ) ≤ 1))\n (Set.right_mem_Icc.mpr (by norm_num : (0:ℝ) ≤ 1)) (by norm_num)\n rw [h0] at h1\n simp only [hhdef] at h1\n have hy : x + (1:ℝ) • δ = y := by rw [hδ]; simp\n rw [hy] at h1\n linarith\n\nlemma descent {F : E → ℝ} (hFdiff : Differentiable ℝ F) {LF η : ℝ} (hLF : 0 < LF)\n (hη : 0 < η) (hηLF : η ≤ 1/LF)\n (hsmooth : ∀ u v : E, ‖gradient F u - gradient F v‖ ≤ LF * ‖u - v‖) (x : E) :\n F (x - η • gradient F x) ≤ F x - (η/2) * ‖gradient F x‖^2 := by\n have h := smooth_upper hFdiff (le_of_lt hLF) hsmooth x (x - η • gradient F x)\n have hd : x - η • gradient F x - x = -(η • gradient F x) := by abel\n rw [hd] at h\n have h1 : inner ℝ (gradient F x) (-(η • gradient F x)) = -(η * ‖gradient F x‖^2) := by\n rw [inner_neg_right, real_inner_smul_right, real_inner_self_eq_norm_sq]\n have h2 : ‖-(η • gradient F x)‖^2 = η^2 * ‖gradient F x‖^2 := by\n rw [norm_neg, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hη), mul_pow]\n rw [h1, h2] at h\n have hLFη : LF * η ≤ 1 := by\n rw [le_div_iff₀ hLF] at hηLF\n linarith\n have hgnn : (0:ℝ) ≤ ‖gradient F x‖^2 := sq_nonneg _\n nlinarith\n\nlemma gd_step {F : E → ℝ} {κ η : ℝ} (hκ : 0 ≤ κ) (hη : 0 < η)\n (hFpos : ∀ x, 0 ≤ F x) (hFdiff : Differentiable ℝ F) (hLS : LineSecondDeriv F κ)\n (hdesc : ∀ x : E, F (x - η • gradient F x) ≤ F x - (η/2) * ‖gradient F x‖^2)\n (x w : E) (hd : κ * ‖x - w‖^2 ≤ 1/2) :\n ‖x - η • gradient F x - w‖^2\n ≤ ‖x - w‖^2 + 2*η*F w - 2*η*F (x - η • gradient F x) + (2*η/3)*(F x + F w) := by\n set g : E := gradient F x with hg\n have hkl : F x + inner ℝ g (w - x) - (1/3)*(F x + F w) ≤ F w :=\n key_lower hκ hFpos hFdiff hLS x w (by rwa [norm_sub_rev])\n have hde := hdesc x\n have hinner : (inner ℝ (x - w) g : ℝ) = - inner ℝ g (w - x) := by\n have h1 : (inner ℝ g (w - x) : ℝ) = inner ℝ (w - x) g := real_inner_comm _ _\n have h2 : (inner ℝ (w - x) g : ℝ) = - inner ℝ (x - w) g := by\n rw [show w - x = -(x - w) from by abel, inner_neg_left]\n rw [h1, h2]; ring\n have hexp : ‖x - η • g - w‖^2\n = ‖x - w‖^2 + 2*η*(inner ℝ g (w - x) : ℝ) + η^2*‖g‖^2 := by\n have he : x - η • g - w = (x - w) - η • g := by abel\n rw [he, norm_sub_sq_real, real_inner_smul_right, norm_smul, Real.norm_eq_abs,\n abs_of_nonneg (le_of_lt hη), mul_pow, hinner]\n ring\n have m1 : 2*η*(inner ℝ g (w - x) : ℝ)\n ≤ 2*η*(F w - F x + (1/3)*(F x + F w)) := by\n apply mul_le_mul_of_nonneg_left _ (by positivity : (0:ℝ) ≤ 2*η)\n linarith\n have m2 : η*(η*‖g‖^2) ≤ η*(2*(F x - F (x - η • g))) := by\n apply mul_le_mul_of_nonneg_left _ (le_of_lt hη)\n linarith\n rw [hexp]\n nlinarith [m1, m2]\n\ntheorem abstract_gd {F : E → ℝ} {κ η : ℝ} (hκ : 0 ≤ κ) (hη : 0 < η)\n (hFpos : ∀ x, 0 ≤ F x) (hFdiff : Differentiable ℝ F)\n (hLS : LineSecondDeriv F κ)\n (hdesc : ∀ x : E, F (x - η • gradient F x) ≤ F x - (η/2) * ‖gradient F x‖^2)\n (w0 : E) (ws : ℕ → E) (hws0 : ws 0 = w0)\n (hwsS : ∀ t, ws (t+1) = ws t - η • gradient F (ws t))\n (T : ℕ) (w : E)\n (hnorm1 : η * T * F w ≤ ‖w - w0‖^2) (hnorm2 : η * F w0 ≤ ‖w - w0‖^2)\n (hwidth : 18 * κ * ‖w - w0‖^2 ≤ 1) :\n (∀ t, t ≤ T → ‖ws t - w‖ ≤ 3 * ‖w - w0‖)\n ∧ (∑ t ∈ Finset.Icc 1 T, F (ws t) ≤ 2 * (T:ℝ) * F w + (5/4) * ‖w - w0‖^2 / η) := by\n have hA0nn : (0:ℝ) ≤ ‖w - w0‖ := norm_nonneg _\n have hAt0 : ‖ws 0 - w‖ = ‖w - w0‖ := by rw [hws0, norm_sub_rev]\n have hFwnn : 0 ≤ F w := hFpos w\n have hsub0 : ∀ t : ℕ, (∑ s ∈ Finset.range t, F (ws s))\n ≤ F w0 + ∑ s ∈ Finset.Icc 1 t, F (ws s) := by\n intro t\n have hsubset : Finset.range t ⊆ insert 0 (Finset.Icc 1 t) := by\n intro s hs\n rw [Finset.mem_range] at hs\n rcases Nat.eq_zero_or_pos s with h | h\n · simp [h]\n · exact Finset.mem_insert_of_mem (Finset.mem_Icc.mpr ⟨h, le_of_lt hs⟩)\n have := Finset.sum_le_sum_of_subset_of_nonneg hsubset (fun i _ _ => hFpos (ws i))\n calc (∑ s ∈ Finset.range t, F (ws s))\n ≤ ∑ s ∈ insert 0 (Finset.Icc 1 t), F (ws s) := this\n _ = F w0 + ∑ s ∈ Finset.Icc 1 t, F (ws s) := by\n rw [Finset.sum_insert (by simp)]\n rw [hws0]\n have main : ∀ t, t ≤ T → ‖ws t - w‖^2 + 2*η*(∑ s ∈ Finset.Icc 1 t, F (ws s))\n ≤ ‖w - w0‖^2 + (8/3)*η*(t:ℝ)*F w + (2/3)*η*(∑ s ∈ Finset.range t, F (ws s)) := by\n intro t\n induction t with\n | zero =>\n intro _\n simp only [Finset.Icc_self, Nat.cast_zero, Finset.range_zero, Finset.sum_empty,\n Finset.Icc_eq_empty_of_lt, mul_zero, add_zero]\n rw [hAt0]\n simp\n | succ k ih =>\n intro hk\n have hk' : k ≤ T := Nat.le_of_succ_le hk\n have ihk := ih hk'\n have hS1nn : 0 ≤ ∑ s ∈ Finset.Icc 1 k, F (ws s) :=\n Finset.sum_nonneg (fun i _ => hFpos (ws i))\n have hkT : η * (k:ℝ) * F w ≤ ‖w - w0‖^2 := by\n have hkTc : (k:ℝ) ≤ (T:ℝ) := by exact_mod_cast hk'\n nlinarith [hnorm1, mul_nonneg (le_of_lt hη) hFwnn]\n have hnormk : ‖ws k - w‖^2 ≤ 9 * ‖w - w0‖^2 := by\n have h1 := hsub0 k\n nlinarith [ihk, h1, hS1nn, hnorm2, hkT, mul_nonneg (le_of_lt hη) hFwnn]\n have hdk : κ * ‖ws k - w‖^2 ≤ 1/2 := by\n nlinarith [hnormk, hwidth, hκ, sq_nonneg (‖w - w0‖)]\n have hstep := gd_step hκ hη hFpos hFdiff hLS hdesc (ws k) w hdk\n rw [← hwsS k] at hstep\n rw [Finset.sum_Icc_succ_top (by omega : 1 ≤ k + 1), Finset.sum_range_succ]\n push_cast\n linarith [hstep, ihk]\n constructor\n · intro t ht\n have hmt := main t ht\n have h1 := hsub0 t\n have hS1nn : 0 ≤ ∑ s ∈ Finset.Icc 1 t, F (ws s) :=\n Finset.sum_nonneg (fun i _ => hFpos (ws i))\n have htT : η * (t:ℝ) * F w ≤ ‖w - w0‖^2 := by\n have htTc : (t:ℝ) ≤ (T:ℝ) := by exact_mod_cast ht\n nlinarith [hnorm1, mul_nonneg (le_of_lt hη) hFwnn]\n have hsq : ‖ws t - w‖^2 ≤ 9 * ‖w - w0‖^2 := by\n nlinarith [hmt, h1, hS1nn, hnorm2, htT]\n nlinarith [norm_nonneg (ws t - w), hA0nn, hsq]\n · have hmt := main T le_rfl\n have h1 := hsub0 T\n have hsqnn : (0:ℝ) ≤ ‖ws T - w‖^2 := sq_nonneg _\n have hkey : η * (∑ t ∈ Finset.Icc 1 T, F (ws t))\n ≤ η * (2 * (T:ℝ) * F w + (5/4) * ‖w - w0‖^2 / η) := by\n have hcancel : η * ((5/4) * ‖w - w0‖^2 / η) = (5/4) * ‖w - w0‖^2 := by\n field_simp\n rw [mul_add, hcancel]\n nlinarith [hmt, h1, hsqnn, hnorm2]\n exact le_of_mul_le_mul_left hkey hη\n\nlemma F_antitone {F : E → ℝ} {η : ℝ}\n (hdesc : ∀ x : E, F (x - η • gradient F x) ≤ F x - (η/2) * ‖gradient F x‖^2)\n (hηnn : 0 ≤ η)\n (ws : ℕ → E) (hwsS : ∀ t, ws (t+1) = ws t - η • gradient F (ws t)) :\n ∀ s t : ℕ, s ≤ t → F (ws t) ≤ F (ws s) := by\n have hstep : ∀ t : ℕ, F (ws (t+1)) ≤ F (ws t) := by\n intro t\n have h := hdesc (ws t)\n rw [← hwsS t] at h\n have : 0 ≤ (η/2) * ‖gradient F (ws t)‖^2 := by positivity\n linarith\n intro s t hst\n induction t with\n | zero => simp_all\n | succ k ih =>\n rcases Nat.lt_or_ge s (k+1) with h | h\n · have hsk : s ≤ k := Nat.lt_succ_iff.mp h\n exact le_trans (hstep k) (ih hsk)\n · have : s = k + 1 := le_antisymm hst h\n rw [this]\n\nend Abstract\n\nsection Helpers\n\nvariable {m d n : ℕ}\n\n/-- Explicit gradient (as a vector in `Params m d`) of `w ↦ phi a σ w x`. -/\nnoncomputable def gphi (a : Fin m → ℝ) (σ : ℝ → ℝ) (x : EuclideanSpace ℝ (Fin d))\n (w : Params m d) : Params m d :=\n WithLp.toLp 2 (fun j => ((1 / Real.sqrt (m:ℝ)) * (a j * deriv σ (inner ℝ (w j) x))) • x)\n\nlemma gphi_apply (a : Fin m → ℝ) (σ : ℝ → ℝ) (x : EuclideanSpace ℝ (Fin d))\n (w : Params m d) (j : Fin m) :\n gphi a σ x w j = ((1 / Real.sqrt (m:ℝ)) * (a j * deriv σ (inner ℝ (w j) x))) • x := rfl\n\nlemma inner_gphi (a : Fin m → ℝ) (σ : ℝ → ℝ) (x : EuclideanSpace ℝ (Fin d))\n (w v : Params m d) :\n inner ℝ (gphi a σ x w) v\n = (1 / Real.sqrt (m:ℝ)) * ∑ j, a j * deriv σ (inner ℝ (w j) x) * inner ℝ (v j) x := by\n rw [PiLp.inner_apply, Finset.mul_sum]\n refine Finset.sum_congr rfl (fun j _ => ?_)\n rw [show (gphi a σ x w).ofLp j = gphi a σ x w j from rfl, gphi_apply, real_inner_smul_left,\n real_inner_comm x (v.ofLp j)]\n ring\n\nlemma hasFDerivAt_phi {σ : ℝ → ℝ} (hσ : Differentiable ℝ σ) (a : Fin m → ℝ)\n (x : EuclideanSpace ℝ (Fin d)) (w : Params m d) :\n HasFDerivAt (fun w : Params m d => phi a σ w x) (innerSL ℝ (gphi a σ x w)) w := by\n have key : ∀ j : Fin m, HasFDerivAt (fun w : Params m d => σ (inner ℝ (w j) x))\n ((deriv σ (inner ℝ (w j) x)) •\n ((innerSL ℝ x).comp (PiLp.proj 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d)) j))) w := by\n intro j\n have h1 : HasFDerivAt (fun w : Params m d => (inner ℝ (w j) x : ℝ))\n ((innerSL ℝ x).comp (PiLp.proj 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d)) j)) w := by\n have he : (fun w : Params m d => (inner ℝ (w j) x : ℝ))\n = fun w => ((innerSL ℝ x).comp\n (PiLp.proj 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d)) j)) w := by\n funext w; simp [real_inner_comm]\n rw [he]\n exact ContinuousLinearMap.hasFDerivAt _\n exact (hσ _).hasDerivAt.comp_hasFDerivAt w h1\n have hsum : HasFDerivAt (fun w : Params m d => ∑ j, a j * σ (inner ℝ (w j) x))\n (∑ j, a j • ((deriv σ (inner ℝ (w j) x)) •\n ((innerSL ℝ x).comp (PiLp.proj 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d)) j)))) w :=\n by\n have h := HasFDerivAt.sum\n (fun j (_ : j ∈ (Finset.univ : Finset (Fin m))) => (key j).const_mul (a j))\n have he : (∑ j : Fin m, fun (y : Params m d) => a j * σ (inner ℝ (y j) x))\n = fun y : Params m d => ∑ j, a j * σ (inner ℝ (y j) x) := by\n funext y; simp [Finset.sum_apply]\n rwa [he] at h\n have h2 := hsum.const_mul (1 / Real.sqrt (m:ℝ))\n have : (fun w : Params m d => phi a σ w x)\n = fun w : Params m d => (1 / Real.sqrt (m:ℝ)) * ∑ j, a j * σ (inner ℝ (w j) x) := rfl\n rw [this]\n convert h2 using 1\n ext v\n simp only [ContinuousLinearMap.smul_apply, ContinuousLinearMap.sum_apply,\n ContinuousLinearMap.coe_comp', Function.comp_apply, innerSL_apply_apply, PiLp.proj_apply,\n smul_eq_mul]\n rw [inner_gphi, Finset.mul_sum, Finset.mul_sum]\n refine Finset.sum_congr rfl (fun j _ => ?_)\n rw [real_inner_comm x (v.ofLp j)]\n ring\n\nlemma norm_sq_params (w : Params m d) : ‖w‖^2 = ∑ j, ‖w j‖^2 := by\n rw [PiLp.norm_eq_of_L2, Real.sq_sqrt]\n positivity\n\nlemma norm_gphi_le {σ : ℝ → ℝ} {ℓ R : ℝ} (hm : 0 < m) (hℓ : 0 ≤ ℓ) (hR : 0 ≤ R)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (x : EuclideanSpace ℝ (Fin d)) (hx : ‖x‖ ≤ R) (w : Params m d) :\n ‖gphi a σ x w‖ ≤ ℓ * R := by\n have hmR : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n have hsm : Real.sqrt (m:ℝ) > 0 := Real.sqrt_pos.mpr hmR\n have hb : ∀ j : Fin m, ‖gphi a σ x w j‖^2 ≤ (ℓ*R)^2 / (m:ℝ) := by\n intro j\n rw [gphi_apply, norm_smul]\n have h1 : |a j| = 1 := by rcases ha j with h | h <;> simp [h]\n have h2 : |deriv σ (inner ℝ (w j) x)| ≤ ℓ := hσ' _\n have h3 : ‖(1 / Real.sqrt (m:ℝ)) * (a j * deriv σ (inner ℝ (w j) x))‖\n ≤ ℓ / Real.sqrt (m:ℝ) := by\n rw [Real.norm_eq_abs, abs_mul, abs_mul, h1, one_mul, abs_of_nonneg (by positivity : (0:ℝ) ≤ 1 / Real.sqrt (m:ℝ))]\n rw [one_div]\n rw [inv_mul_eq_div, div_le_div_iff_of_pos_right hsm]\n exact h2\n have hxn : ‖x‖ ≤ R := hx\n have : ‖(1 / Real.sqrt (m:ℝ)) * (a j * deriv σ (inner ℝ (w j) x))‖ * ‖x‖\n ≤ (ℓ / Real.sqrt (m:ℝ)) * R := by\n apply mul_le_mul h3 hxn (norm_nonneg _) (by positivity)\n calc (‖(1 / Real.sqrt (m:ℝ)) * (a j * deriv σ (inner ℝ (w j) x))‖ * ‖x‖)^2\n ≤ ((ℓ / Real.sqrt (m:ℝ)) * R)^2 := by\n apply pow_le_pow_left₀ (by positivity) this\n _ = (ℓ*R)^2 / (m:ℝ) := by\n rw [div_mul_eq_mul_div, div_pow, Real.sq_sqrt (le_of_lt hmR)]\n have hsum : ‖gphi a σ x w‖^2 ≤ (ℓ*R)^2 := by\n rw [norm_sq_params]\n calc ∑ j : Fin m, ‖gphi a σ x w j‖^2 ≤ ∑ _j : Fin m, (ℓ*R)^2 / (m:ℝ) :=\n Finset.sum_le_sum (fun j _ => hb j)\n _ = (ℓ*R)^2 := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n nlinarith [norm_nonneg (gphi a σ x w), mul_nonneg hℓ hR]\n\nlemma hasGradientAt_of_hasFDerivAt {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n [CompleteSpace E] {F : E → ℝ} {y x : E} (h : HasFDerivAt F (innerSL ℝ y) x) :\n HasGradientAt F y x := by\n rw [hasGradientAt_iff_hasFDerivAt]\n convert h using 1\n\nlemma innerSL_smul_real {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (c : ℝ) (y : E) : innerSL ℝ (c • y) = c • innerSL ℝ y := by\n ext z; simp\n\n/-- Explicit gradient of the `i`-th sample loss. -/\nnoncomputable def gFhatI (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) (i : Fin n)\n (w : Params m d) : Params m d :=\n (deriv f (ys i * phi a σ w (xs i)) * ys i) • gphi a σ (xs i) w\n\n/-- Explicit gradient of the empirical loss. -/\nnoncomputable def gF (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (w : Params m d) : Params m d :=\n (1/(n:ℝ)) • ∑ i, gFhatI a σ f xs ys i w\n\nlemma hasFDerivAt_FhatI {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f)\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) (i : Fin n)\n (w : Params m d) :\n HasFDerivAt (FhatI a σ f xs ys i) (innerSL ℝ (gFhatI a σ f xs ys i w)) w := by\n have h1 : HasFDerivAt (fun w : Params m d => ys i * phi a σ w (xs i))\n ((ys i) • innerSL ℝ (gphi a σ (xs i) w)) w :=\n (hasFDerivAt_phi hσ a (xs i) w).const_mul (ys i)\n have h2 := (hf _).hasDerivAt.comp_hasFDerivAt w h1\n have he : (deriv f (ys i * phi a σ w (xs i))) • ((ys i) • innerSL ℝ (gphi a σ (xs i) w))\n = innerSL ℝ (gFhatI a σ f xs ys i w) := by\n rw [gFhatI, innerSL_smul_real, smul_smul]\n rw [← he]\n exact h2\n\nlemma gradient_FhatI {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f)\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) (i : Fin n)\n (w : Params m d) :\n gradient (FhatI a σ f xs ys i) w = gFhatI a σ f xs ys i w :=\n (hasGradientAt_of_hasFDerivAt (hasFDerivAt_FhatI hσ hf a xs ys i w)).gradient\n\nlemma hasFDerivAt_Fhat {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f)\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (w : Params m d) :\n HasFDerivAt (Fhat a σ f xs ys) (innerSL ℝ (gF a σ f xs ys w)) w := by\n have hsum : HasFDerivAt (fun w : Params m d => ∑ i, FhatI a σ f xs ys i w)\n (∑ i, innerSL ℝ (gFhatI a σ f xs ys i w)) w := by\n have h := HasFDerivAt.sum\n (fun i (_ : i ∈ (Finset.univ : Finset (Fin n))) => hasFDerivAt_FhatI hσ hf a xs ys i w)\n have he : (∑ i : Fin n, fun (y : Params m d) => FhatI a σ f xs ys i y)\n = fun y : Params m d => ∑ i, FhatI a σ f xs ys i y := by\n funext y; simp [Finset.sum_apply]\n rwa [he] at h\n have h2 := hsum.const_mul (1/(n:ℝ))\n have he : (fun w : Params m d => Fhat a σ f xs ys w)\n = fun w : Params m d => (1/(n:ℝ)) * ∑ i, FhatI a σ f xs ys i w := rfl\n have he2 : (1/(n:ℝ)) • (∑ i, innerSL ℝ (gFhatI a σ f xs ys i w))\n = innerSL ℝ (gF a σ f xs ys w) := by\n rw [gF, innerSL_smul_real]\n congr 1\n ext z\n simp [PiLp.inner_apply, Finset.sum_apply]\n rw [show Fhat a σ f xs ys = fun w : Params m d => (1/(n:ℝ)) * ∑ i, FhatI a σ f xs ys i w from rfl,\n ← he2]\n exact h2\n\nlemma gradient_Fhat {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f)\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (w : Params m d) :\n gradient (Fhat a σ f xs ys) w = gF a σ f xs ys w :=\n (hasGradientAt_of_hasFDerivAt (hasFDerivAt_Fhat hσ hf a xs ys w)).gradient\n\nlemma norm_gradient_FhatI_le {σ f : ℝ → ℝ} {ℓ R : ℝ} (hm : 0 < m) (hℓ : 0 ≤ ℓ) (hR : 0 ≤ R)\n (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f) (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (hfsb : ∀ u, |deriv f u| ≤ f u)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1) (i : Fin n) (w : Params m d) :\n ‖gradient (FhatI a σ f xs ys i) w‖ ≤ ℓ * R * FhatI a σ f xs ys i w := by\n rw [gradient_FhatI hσ hf, gFhatI, norm_smul]\n have h1 : |ys i| = 1 := by rcases hy i with h | h <;> simp [h]\n have hq : |deriv f (ys i * phi a σ w (xs i))| ≤ f (ys i * phi a σ w (xs i)) := hfsb _\n have hqnn : 0 ≤ f (ys i * phi a σ w (xs i)) := le_trans (abs_nonneg _) hq\n have h2 : ‖gphi a σ (xs i) w‖ ≤ ℓ * R := norm_gphi_le hm hℓ hR a ha hσ' (xs i) (hx i) w\n have h3 : ‖deriv f (ys i * phi a σ w (xs i)) * ys i‖\n ≤ f (ys i * phi a σ w (xs i)) := by\n rw [Real.norm_eq_abs, abs_mul, h1, mul_one]\n exact hq\n calc ‖deriv f (ys i * phi a σ w (xs i)) * ys i‖ * ‖gphi a σ (xs i) w‖\n ≤ f (ys i * phi a σ w (xs i)) * (ℓ * R) :=\n mul_le_mul h3 h2 (norm_nonneg _) hqnn\n _ = ℓ * R * FhatI a σ f xs ys i w := by rw [FhatI]; ring\n\n/-- Derivative along a line of the network output. -/\nnoncomputable def Pt1 (a : Fin m → ℝ) (σ : ℝ → ℝ) (x : EuclideanSpace ℝ (Fin d))\n (u v : Params m d) (t : ℝ) : ℝ :=\n (1 / Real.sqrt (m:ℝ)) *\n ∑ j, a j * deriv σ (inner ℝ (u j) x + t * inner ℝ (v j) x) * inner ℝ (v j) x\n\n/-- Second derivative along a line of the network output. -/\nnoncomputable def Pt2 (a : Fin m → ℝ) (σ : ℝ → ℝ) (x : EuclideanSpace ℝ (Fin d))\n (u v : Params m d) (t : ℝ) : ℝ :=\n (1 / Real.sqrt (m:ℝ)) *\n ∑ j, a j * deriv (deriv σ) (inner ℝ (u j) x + t * inner ℝ (v j) x) *\n (inner ℝ (v j) x)^2\n\nlemma inner_line_apply (x : EuclideanSpace ℝ (Fin d)) (u v : Params m d) (t : ℝ) (j : Fin m) :\n inner ℝ ((u + t • v) j) x = inner ℝ (u j) x + t * inner ℝ (v j) x := by\n show inner ℝ (u j + t • v j) x = _\n rw [inner_add_left, real_inner_smul_left]\n\nlemma inner_gphi_line (a : Fin m → ℝ) (σ : ℝ → ℝ) (x : EuclideanSpace ℝ (Fin d))\n (u v : Params m d) (t : ℝ) :\n inner ℝ (gphi a σ x (u + t • v)) v = Pt1 a σ x u v t := by\n rw [inner_gphi, Pt1]\n congr 1\n refine Finset.sum_congr rfl (fun j _ => ?_)\n rw [inner_line_apply]\n\nlemma hasDerivAt_finsum {ι : Type*} (s : Finset ι) (F : ι → ℝ → ℝ) (F' : ι → ℝ) (t : ℝ)\n (h : ∀ i ∈ s, HasDerivAt (F i) (F' i) t) :\n HasDerivAt (fun y => ∑ i ∈ s, F i y) (∑ i ∈ s, F' i) t := by\n have h2 := HasDerivAt.sum h\n have he : (∑ i ∈ s, fun y : ℝ => F i y) = fun y : ℝ => ∑ i ∈ s, F i y := by\n funext y; simp [Finset.sum_apply]\n rwa [he] at h2\n\nlemma hasDerivAt_line {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (u v : E) (t : ℝ) :\n HasDerivAt (fun s : ℝ => u + s • v) v t := by\n have h : HasDerivAt (fun s : ℝ => s • v) v t := by\n simpa using (hasDerivAt_id t).smul_const v\n simpa using h.const_add u\n\nlemma hasDerivAt_phi_line {σ : ℝ → ℝ} (hσ : Differentiable ℝ σ) (a : Fin m → ℝ)\n (x : EuclideanSpace ℝ (Fin d)) (u v : Params m d) (t : ℝ) :\n HasDerivAt (fun s : ℝ => phi a σ (u + s • v) x) (Pt1 a σ x u v t) t := by\n have h := (hasFDerivAt_phi hσ a x (u + t • v)).comp_hasDerivAt t (hasDerivAt_line u v t)\n rw [← inner_gphi_line]\n exact h\n\nlemma hasDerivAt_Pt1 {σ : ℝ → ℝ} (hσd : Differentiable ℝ (deriv σ)) (a : Fin m → ℝ)\n (x : EuclideanSpace ℝ (Fin d)) (u v : Params m d) (t : ℝ) :\n HasDerivAt (Pt1 a σ x u v) (Pt2 a σ x u v t) t := by\n have key : ∀ j : Fin m,\n HasDerivAt (fun s : ℝ => a j * deriv σ (inner ℝ (u j) x + s * inner ℝ (v j) x)\n * inner ℝ (v j) x)\n (a j * deriv (deriv σ) (inner ℝ (u j) x + t * inner ℝ (v j) x)\n * (inner ℝ (v j) x)^2) t := by\n intro j\n have h0 : HasDerivAt (fun s : ℝ => inner ℝ (u j) x + s * inner ℝ (v j) x)\n (inner ℝ (v j) x) t := by\n simpa using ((hasDerivAt_id t).mul_const (inner ℝ (v j) x : ℝ)).const_add\n (inner ℝ (u j) x : ℝ)\n have h1 := (hσd _).hasDerivAt.comp t h0\n have h2 := (h1.const_mul (a j)).mul_const (inner ℝ (v j) x : ℝ)\n convert h2 using 1\n ring\n have hsum : HasDerivAt (fun s : ℝ => ∑ j, a j * deriv σ (inner ℝ (u j) x + s * inner ℝ (v j) x)\n * inner ℝ (v j) x)\n (∑ j, a j * deriv (deriv σ) (inner ℝ (u j) x + t * inner ℝ (v j) x)\n * (inner ℝ (v j) x)^2) t :=\n hasDerivAt_finsum _ _ _ _ (fun j _ => key j)\n exact hsum.const_mul _\n\nlemma abs_Pt2_le {σ : ℝ → ℝ} {L R : ℝ} (hm : 0 < m) (hL : 0 ≤ L) (hR : 0 ≤ R)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hσ'' : ∀ y, |deriv (deriv σ) y| ≤ L)\n (x : EuclideanSpace ℝ (Fin d)) (hx : ‖x‖ ≤ R)\n (u v : Params m d) (t : ℝ) :\n |Pt2 a σ x u v t| ≤ (1 / Real.sqrt (m:ℝ)) * (L * R^2 * ‖v‖^2) := by\n have hmR : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n have hsm : (0:ℝ) < Real.sqrt (m:ℝ) := Real.sqrt_pos.mpr hmR\n rw [Pt2, abs_mul, abs_of_nonneg (by positivity : (0:ℝ) ≤ 1 / Real.sqrt (m:ℝ))]\n apply mul_le_mul_of_nonneg_left _ (by positivity)\n calc |∑ j, a j * deriv (deriv σ) (inner ℝ (u j) x + t * inner ℝ (v j) x)\n * (inner ℝ (v j) x)^2|\n ≤ ∑ j, |a j * deriv (deriv σ) (inner ℝ (u j) x + t * inner ℝ (v j) x)\n * (inner ℝ (v j) x)^2| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ j, L * (R^2 * ‖v j‖^2) := by\n refine Finset.sum_le_sum (fun j _ => ?_)\n rw [abs_mul, abs_mul]\n have h1 : |a j| = 1 := by rcases ha j with h | h <;> simp [h]\n have h2 : |(inner ℝ (v j) x : ℝ)^2| = (inner ℝ (v j) x : ℝ)^2 := abs_of_nonneg (by positivity)\n rw [h1, one_mul, h2]\n have h3 : (inner ℝ (v j) x : ℝ)^2 ≤ R^2 * ‖v j‖^2 := by\n have h4 : |(inner ℝ (v j) x : ℝ)| ≤ ‖v j‖ * ‖x‖ := abs_real_inner_le_norm _ _\n have h5 : ‖v j‖ * ‖x‖ ≤ ‖v j‖ * R := by\n exact mul_le_mul_of_nonneg_left hx (norm_nonneg _)\n nlinarith [abs_nonneg (inner ℝ (v j) x : ℝ), sq_abs (inner ℝ (v j) x : ℝ),\n norm_nonneg (v j), hR]\n exact mul_le_mul (hσ'' _) h3 (by positivity) hL\n _ = L * R^2 * ‖v‖^2 := by\n rw [← Finset.mul_sum, ← Finset.mul_sum, norm_sq_params]\n ring\n\n/-- First derivative of the empirical loss along the line `s ↦ u + s • v`. -/\nnoncomputable def dF1 (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (u v : Params m d) (t : ℝ) : ℝ :=\n (1/(n:ℝ)) * ∑ i, deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt1 a σ (xs i) u v t)\n\n/-- Second derivative of the empirical loss along the line `s ↦ u + s • v`. -/\nnoncomputable def dF2 (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (u v : Params m d) (t : ℝ) : ℝ :=\n (1/(n:ℝ)) * ∑ i, (deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt1 a σ (xs i) u v t)^2\n + deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t))\n\nlemma hasDerivAt_q {σ : ℝ → ℝ} (hσ : Differentiable ℝ σ) (a : Fin m → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) (i : Fin n)\n (u v : Params m d) (t : ℝ) :\n HasDerivAt (fun s : ℝ => ys i * phi a σ (u + s • v) (xs i))\n (ys i * Pt1 a σ (xs i) u v t) t :=\n (hasDerivAt_phi_line hσ a (xs i) u v t).const_mul (ys i)\n\nlemma hasDerivAt_Fhat_line {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f)\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (u v : Params m d) (t : ℝ) :\n HasDerivAt (fun s : ℝ => Fhat a σ f xs ys (u + s • v)) (dF1 a σ f xs ys u v t) t := by\n have key : ∀ i : Fin n, HasDerivAt (fun s : ℝ => f (ys i * phi a σ (u + s • v) (xs i)))\n (deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt1 a σ (xs i) u v t)) t :=\n fun i => (hf _).hasDerivAt.comp t (hasDerivAt_q hσ a xs ys i u v t)\n have hsum := hasDerivAt_finsum (Finset.univ : Finset (Fin n))\n (fun i s => f (ys i * phi a σ (u + s • v) (xs i)))\n (fun i => deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt1 a σ (xs i) u v t))\n t (fun i _ => key i)\n exact hsum.const_mul _\n\nlemma hasDerivAt_dF1 {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hσd : Differentiable ℝ (deriv σ))\n (hf : Differentiable ℝ f) (hfd : Differentiable ℝ (deriv f))\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (u v : Params m d) (t : ℝ) :\n HasDerivAt (dF1 a σ f xs ys u v) (dF2 a σ f xs ys u v t) t := by\n have key : ∀ i : Fin n, HasDerivAt\n (fun s : ℝ => deriv f (ys i * phi a σ (u + s • v) (xs i)) * (ys i * Pt1 a σ (xs i) u v s))\n (deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt1 a σ (xs i) u v t)^2\n + deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t)) t := by\n intro i\n have h1 : HasDerivAt (fun s : ℝ => deriv f (ys i * phi a σ (u + s • v) (xs i)))\n (deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt1 a σ (xs i) u v t)) t :=\n (hfd _).hasDerivAt.comp t (hasDerivAt_q hσ a xs ys i u v t)\n have h2 : HasDerivAt (fun s : ℝ => ys i * Pt1 a σ (xs i) u v s)\n (ys i * Pt2 a σ (xs i) u v t) t :=\n (hasDerivAt_Pt1 hσd a (xs i) u v t).const_mul (ys i)\n have h3 := h1.mul h2\n convert h3 using 1\n ring\n have hsum := hasDerivAt_finsum (Finset.univ : Finset (Fin n))\n (fun i s => deriv f (ys i * phi a σ (u + s • v) (xs i)) * (ys i * Pt1 a σ (xs i) u v s))\n (fun i => deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt1 a σ (xs i) u v t)^2\n + deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t))\n t (fun i _ => key i)\n exact hsum.const_mul _\n\nlemma deriv_deriv_nonneg {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hfconv : ConvexOn ℝ Set.univ f)\n (y : ℝ) : 0 ≤ deriv (deriv f) y := by\n have hmono : Monotone (deriv f) := by\n have h := hfconv.monotoneOn_deriv (fun x _ => hf x)\n intro p q hpq\n exact h (Set.mem_univ p) (Set.mem_univ q) hpq\n exact hmono.deriv_nonneg\n\nlemma dF2_lower {σ f : ℝ → ℝ} {L R : ℝ} (hm : 0 < m) (hL : 0 ≤ L) (hR : 0 ≤ R)\n (hf : Differentiable ℝ f) (hfconv : ConvexOn ℝ Set.univ f)\n (hfsb : ∀ y, |deriv f y| ≤ f y)\n (hσ'' : ∀ y, |deriv (deriv σ) y| ≤ L)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (u v : Params m d) (t : ℝ) :\n -(L * R^2 / Real.sqrt (m:ℝ) * ‖v‖^2) * Fhat a σ f xs ys (u + t • v)\n ≤ dF2 a σ f xs ys u v t := by\n have hmR : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n have hsm : (0:ℝ) < Real.sqrt (m:ℝ) := Real.sqrt_pos.mpr hmR\n set κ : ℝ := L * R^2 / Real.sqrt (m:ℝ) * ‖v‖^2 with hκdef\n have hterm : ∀ i : Fin n,\n -κ * f (ys i * phi a σ (u + t • v) (xs i))\n ≤ deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt1 a σ (xs i) u v t)^2\n + deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t) := by\n intro i\n have hfq : 0 ≤ f (ys i * phi a σ (u + t • v) (xs i)) :=\n le_trans (abs_nonneg _) (hfsb _)\n have h1 : 0 ≤ deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt1 a σ (xs i) u v t)^2 :=\n mul_nonneg (deriv_deriv_nonneg hf hfconv _) (sq_nonneg _)\n have hy1 : |ys i| = 1 := by rcases hy i with h | h <;> simp [h]\n have hb := abs_Pt2_le hm hL hR a ha hσ'' (xs i) (hx i) u v t\n have h2 : |deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t)|\n ≤ κ * f (ys i * phi a σ (u + t • v) (xs i)) := by\n rw [abs_mul, abs_mul, hy1, one_mul]\n calc |deriv f (ys i * phi a σ (u + t • v) (xs i))| * |Pt2 a σ (xs i) u v t|\n ≤ f (ys i * phi a σ (u + t • v) (xs i))\n * ((1 / Real.sqrt (m:ℝ)) * (L * R^2 * ‖v‖^2)) :=\n mul_le_mul (hfsb _) hb (abs_nonneg _) hfq\n _ = κ * f (ys i * phi a σ (u + t • v) (xs i)) := by rw [hκdef]; ring\n have h3 := neg_abs_le (deriv f (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt2 a σ (xs i) u v t))\n linarith\n have hsum : ∑ i, (-κ * f (ys i * phi a σ (u + t • v) (xs i)))\n ≤ ∑ i, (deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt1 a σ (xs i) u v t)^2\n + deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t)) :=\n Finset.sum_le_sum (fun i _ => hterm i)\n have hsum2 : -κ * ∑ i, f (ys i * phi a σ (u + t • v) (xs i))\n ≤ ∑ i, (deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt1 a σ (xs i) u v t)^2\n + deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t)) := by\n rw [Finset.mul_sum]; exact hsum\n have hnn : (0:ℝ) ≤ 1 / (n:ℝ) := by positivity\n calc -κ * Fhat a σ f xs ys (u + t • v)\n = (1/(n:ℝ)) * (-κ * ∑ i, f (ys i * phi a σ (u + t • v) (xs i))) := by\n rw [Fhat]; ring\n _ ≤ (1/(n:��)) * ∑ i, (deriv (deriv f) (ys i * phi a σ (u + t • v) (xs i))\n * (ys i * Pt1 a σ (xs i) u v t)^2\n + deriv f (ys i * phi a σ (u + t • v) (xs i)) * (ys i * Pt2 a σ (xs i) u v t)) :=\n mul_le_mul_of_nonneg_left hsum2 hnn\n _ = dF2 a σ f xs ys u v t := rfl\n\n/-- The constant continuous-linear functional `w ↦ ⟪xs i, w j⟫`. -/\nnoncomputable def Kmap (xs : Fin n → EuclideanSpace ℝ (Fin d)) (i : Fin n) (j : Fin m) :\n Params m d →L[ℝ] ℝ :=\n (innerSL ℝ (xs i)).comp (PiLp.proj 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d)) j)\n\nlemma Kmap_apply (xs : Fin n → EuclideanSpace ℝ (Fin d)) (i : Fin n) (j : Fin m)\n (w : Params m d) : Kmap xs i j w = inner ℝ (xs i) (w j) := rfl\n\nlemma differentiable_inner_proj (x : EuclideanSpace ℝ (Fin d)) (j : Fin m) :\n Differentiable ℝ (fun w : Params m d => (inner ℝ (w j) x : ℝ)) := by\n have he : (fun w : Params m d => (inner ℝ (w j) x : ℝ))\n = fun w : Params m d =>\n ((innerSL ℝ x).comp (PiLp.proj 2 (fun _ : Fin m => EuclideanSpace ℝ (Fin d)) j)) w := by\n funext w; simp [real_inner_comm]\n rw [he]\n exact (ContinuousLinearMap.differentiable _)\n\nlemma differentiable_phi {σ : ℝ → ℝ} (hσ : Differentiable ℝ σ) (a : Fin m → ℝ)\n (x : EuclideanSpace ℝ (Fin d)) : Differentiable ℝ (fun w : Params m d => phi a σ w x) :=\n fun w => (hasFDerivAt_phi hσ a x w).differentiableAt\n\n/-- Coefficient appearing in the explicit formula for the Fréchet derivative. -/\nnoncomputable def cco (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) (i : Fin n) (j : Fin m)\n (w : Params m d) : ℝ :=\n (1/(n:ℝ)) * (deriv f (ys i * phi a σ w (xs i)) * ys i)\n * ((1 / Real.sqrt (m:ℝ)) * (a j * deriv σ (inner ℝ (w j) (xs i))))\n\n/-- Explicit Fréchet derivative of the empirical loss. -/\nnoncomputable def DF (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (w : Params m d) : Params m d →L[ℝ] ℝ :=\n ∑ i, ∑ j, (cco a σ f xs ys i j w) • Kmap xs i j\n\nlemma innerSL_gF_eq_DF (a : Fin m → ℝ) (σ f : ℝ → ℝ)\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) (w : Params m d) :\n innerSL ℝ (gF a σ f xs ys w) = DF a σ f xs ys w := by\n ext z\n rw [DF]\n simp only [ContinuousLinearMap.sum_apply, ContinuousLinearMap.smul_apply, smul_eq_mul,\n Kmap_apply, innerSL_apply_apply]\n rw [gF]\n rw [show (inner ℝ ((1/(n:ℝ)) • ∑ i, gFhatI a σ f xs ys i w) z : ℝ)\n = (1/(n:ℝ)) * inner ℝ (∑ i, gFhatI a σ f xs ys i w) z from real_inner_smul_left _ _ _]\n rw [show (inner ℝ (∑ i, gFhatI a σ f xs ys i w) z : ℝ)\n = ∑ i, (inner ℝ (gFhatI a σ f xs ys i w) z : ℝ) from\n sum_inner (𝕜 := ℝ) Finset.univ (fun i => gFhatI a σ f xs ys i w) z, Finset.mul_sum]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [gFhatI, real_inner_smul_left, inner_gphi]\n rw [Finset.mul_sum]\n rw [Finset.mul_sum]\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl (fun j _ => ?_)\n rw [cco, real_inner_comm (xs i) (z.ofLp j)]\n ring\n\nlemma differentiable_cco {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ)\n (hσd : Differentiable ℝ (deriv σ)) (hf : Differentiable ℝ f)\n (hfd : Differentiable ℝ (deriv f))\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (i : Fin n) (j : Fin m) : Differentiable ℝ (cco a σ f xs ys i j) := by\n have h1 : Differentiable ℝ (fun w : Params m d => deriv f (ys i * phi a σ w (xs i))) :=\n hfd.comp (((differentiable_phi hσ a (xs i)).const_mul (ys i)))\n have h2 : Differentiable ℝ (fun w : Params m d => deriv σ (inner ℝ (w j) (xs i))) :=\n hσd.comp (differentiable_inner_proj (xs i) j)\n exact (((h1.mul_const (ys i)).const_mul (1/(n:ℝ)))).mul\n ((h2.const_mul (a j)).const_mul (1 / Real.sqrt (m:ℝ)))\n\nlemma fderiv_Fhat_eq {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f)\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) :\n fderiv ℝ (Fhat a σ f xs ys) = DF a σ f xs ys := by\n funext w\n rw [(hasFDerivAt_Fhat hσ hf a xs ys w).fderiv, innerSL_gF_eq_DF]\n\nlemma differentiable_DF {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ)\n (hσd : Differentiable ℝ (deriv σ)) (hf : Differentiable ℝ f)\n (hfd : Differentiable ℝ (deriv f))\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ) :\n Differentiable ℝ (DF a σ f xs ys) := by\n intro w\n refine DifferentiableAt.fun_sum (fun i _ => ?_)\n refine DifferentiableAt.fun_sum (fun j _ => ?_)\n exact ((differentiable_cco hσ hσd hf hfd a xs ys i j).smul_const (Kmap xs i j)) w\n\nlemma iteratedFDeriv_two_line {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]\n (F : E → ℝ) (hF2 : Differentiable ℝ (fderiv ℝ F)) (w v : E) :\n iteratedFDeriv ℝ 2 F w (fun _ => v) = deriv (fun t : ℝ => fderiv ℝ F (w + t • v) v) 0 := by\n have h1 : iteratedFDeriv ℝ 2 F w (fun _ => v) = (fderiv ℝ (fderiv ℝ F) w v) v := by\n rw [iteratedFDeriv_succ_apply_right]\n simp [iteratedFDeriv_one_apply, Fin.init]\n have h2 : HasFDerivAt (fun y => fderiv ℝ F y v) ((fderiv ℝ (fderiv ℝ F) w).flip v) w := by\n have h := (hF2 w).hasFDerivAt.clm_apply (hasFDerivAt_const v w)\n simpa using h\n have h2' : HasFDerivAt (fun y => fderiv ℝ F y v) ((fderiv ℝ (fderiv ℝ F) w).flip v)\n ((fun s : ℝ => w + s • v) 0) := by simpa using h2\n have h3 : HasDerivAt (fun t : ℝ => fderiv ℝ F (w + t • v) v)\n (((fderiv ℝ (fderiv ℝ F) w).flip v) v) 0 := by\n have h := h2'.comp_hasDerivAt 0 (hasDerivAt_line w v 0)\n exact h\n rw [h1, h3.deriv, ContinuousLinearMap.flip_apply]\n\nlemma dF1_eq_fderiv {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ) (hf : Differentiable ℝ f)\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (u v : Params m d) (t : ℝ) :\n dF1 a σ f xs ys u v t = fderiv ℝ (Fhat a σ f xs ys) (u + t • v) v := by\n have h1 := hasDerivAt_Fhat_line hσ hf a xs ys u v t\n have h2 : HasDerivAt (fun s : ℝ => Fhat a σ f xs ys (u + s • v))\n (fderiv ℝ (Fhat a σ f xs ys) (u + t • v) v) t := by\n have h := (hasFDerivAt_Fhat hσ hf a xs ys (u + t • v)).comp_hasDerivAt t\n (hasDerivAt_line u v t)\n rw [(hasFDerivAt_Fhat hσ hf a xs ys (u + t • v)).fderiv]\n exact h\n exact h1.unique h2\n\nlemma iteratedFDeriv_two_Fhat {σ f : ℝ → ℝ} (hσ : Differentiable ℝ σ)\n (hσd : Differentiable ℝ (deriv σ)) (hf : Differentiable ℝ f)\n (hfd : Differentiable ℝ (deriv f))\n (a : Fin m → ℝ) (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (w v : Params m d) :\n iteratedFDeriv ℝ 2 (Fhat a σ f xs ys) w (fun _ => v) = dF2 a σ f xs ys w v 0 := by\n have hF2 : Differentiable ℝ (fderiv ℝ (Fhat a σ f xs ys)) := by\n rw [fderiv_Fhat_eq hσ hf a xs ys]\n exact differentiable_DF hσ hσd hf hfd a xs ys\n rw [iteratedFDeriv_two_line _ hF2 w v]\n have he : (fun t : ℝ => fderiv ℝ (Fhat a σ f xs ys) (w + t • v) v)\n = dF1 a σ f xs ys w v := by\n funext t; rw [dF1_eq_fderiv hσ hf]\n rw [he]\n exact (hasDerivAt_dF1 hσ hσd hf hfd a xs ys w v 0).deriv\n\nend Helpers\n\ntheorem lemma3_1 {m d n : ℕ} (hm : 0 < m) (hn : 0 < n)\n (R ℓ L : ℝ) (hR : 0 ≤ R) (hℓ : 0 ≤ ℓ) (hL : 0 ≤ L)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hbal : (∑ j, a j) = 0)\n (σ f : ℝ → ℝ)\n (hσ : Differentiable ℝ σ) (hσd : Differentiable ℝ (deriv σ)) (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (hσ'' : ∀ u, |deriv (deriv σ) u| ≤ L)\n (hf : Differentiable ℝ f) (hfd : Differentiable ℝ (deriv f)) (hfpos : ∀ u, 0 ≤ f u)\n\n (hfconv : ConvexOn ℝ Set.univ f)\n (hfsb : ∀ u, |deriv f u| ≤ f u)\n (hfdec : Antitone f)\n (hflim : Filter.Tendsto f Filter.atTop (nhds 0))\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (w : Params m d) :\n (∀ i, ‖gradient (FhatI a σ f xs ys i) w‖ ≤ ℓ * R * FhatI a σ f xs ys i w)\n ∧ (∀ v : Params m d,\n -(L * R ^ 2 / Real.sqrt (m : ℝ)) * Fhat a σ f xs ys w * ‖v‖ ^ 2\n ≤ iteratedFDeriv ℝ 2 (Fhat a σ f xs ys) w (fun _ => v)) := by\n constructor\n · intro i\n exact norm_gradient_FhatI_le hm hℓ hR hσ hf hσ' hfsb a ha xs ys hx hy i w\n · intro v\n rw [iteratedFDeriv_two_Fhat hσ hσd hf hfd a xs ys w v]\n have h := dF2_lower (σ := σ) hm hL hR hf hfconv hfsb hσ'' a ha xs ys hx hy w v 0\n rw [show w + (0:ℝ) • v = w by simp] at h\n calc -(L * R ^ 2 / Real.sqrt (m : ℝ)) * Fhat a σ f xs ys w * ‖v‖ ^ 2\n = -(L * R^2 / Real.sqrt (m:ℝ) * ‖v‖^2) * Fhat a σ f xs ys w := by ring\n _ ≤ dF2 a σ f xs ys w v 0 := h\n\ntheorem thm3_2 {m d n : ℕ} (hm : 0 < m) (hn : 0 < n) (T : ℕ) (hT : 0 < T)\n (R ℓ L LF η : ℝ) (hR : 0 ≤ R) (hℓ : 0 ≤ ℓ) (hL : 0 ≤ L)\n (hLF : 0 < LF) (hη0 : 0 < η) (hη : η ≤ 1 / LF)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hbal : (∑ j, a j) = 0)\n (σ f : ℝ → ℝ)\n (hσ : Differentiable ℝ σ) (hσd : Differentiable ℝ (deriv σ)) (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (hσ'' : ∀ u, |deriv (deriv σ) u| ≤ L)\n (hf : Differentiable ℝ f) (hfd : Differentiable ℝ (deriv f)) (hfpos : ∀ u, 0 ≤ f u)\n (hfconv : ConvexOn ℝ Set.univ f) (hf' : ∀ u, |deriv f u| ≤ 1)\n (hf'' : ∀ u, deriv (deriv f) u ≤ 1) (hfsb : ∀ u, |deriv f u| ≤ f u)\n (hfdec : Antitone f)\n (hflim : Filter.Tendsto f Filter.atTop (nhds 0))\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (w0 w : Params m d)\n (hsmooth : ∀ u v, ‖gradient (Fhat a σ f xs ys) u - gradient (Fhat a σ f xs ys) v‖\n ≤ LF * ‖u - v‖)\n (hnorm : ‖w - w0‖ ^ 2 ≥ max (η * T * Fhat a σ f xs ys w) (η * Fhat a σ f xs ys w0))\n (hwidth : (m : ℝ) ≥ 18 ^ 2 * L ^ 2 * R ^ 4 * ‖w - w0‖ ^ 4) :\n let ws := gdSeq a σ f xs ys η w0\n Fhat a σ f xs ys (ws T)\n ≤ (1 / (T : ℝ)) * ∑ t ∈ Finset.Icc 1 T, Fhat a σ f xs ys (ws t)\n ∧ (1 / (T : ℝ)) * ∑ t ∈ Finset.Icc 1 T, Fhat a σ f xs ys (ws t)\n ≤ 2 * Fhat a σ f xs ys w + 5 * ‖w - w0‖ ^ 2 / (2 * η * (T : ℝ))\n ∧ ∀ t, 1 ≤ t → t ≤ T → ‖ws t - w0‖ ≤ 4 * ‖w - w0‖ := by\n intro ws\n have hmR : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n have hsm : (0:ℝ) < Real.sqrt (m:ℝ) := Real.sqrt_pos.mpr hmR\n have hTT : (0:ℝ) < (T:ℝ) := by exact_mod_cast hT\n have hFpos : ∀ x : Params m d, 0 ≤ Fhat a σ f xs ys x := by\n intro x\n rw [Fhat]\n exact mul_nonneg (by positivity) (Finset.sum_nonneg (fun i _ => hfpos _))\n have hFdiff : Differentiable ℝ (Fhat a σ f xs ys) :=\n fun x => (hasFDerivAt_Fhat hσ hf a xs ys x).differentiableAt\n have hκ : (0:ℝ) ≤ L * R^2 / Real.sqrt (m:ℝ) := by positivity\n have hLS : LineSecondDeriv (Fhat a σ f xs ys) (L * R^2 / Real.sqrt (m:ℝ)) := by\n intro u v\n refine ⟨dF1 a σ f xs ys u v, dF2 a σ f xs ys u v,\n fun t => hasDerivAt_Fhat_line hσ hf a xs ys u v t,\n fun t => hasDerivAt_dF1 hσ hσd hf hfd a xs ys u v t, fun t => ?_⟩\n have h := dF2_lower hm hL hR hf hfconv hfsb hσ'' a ha xs ys hx hy u v t\n linarith\n have hdesc : ∀ x : Params m d, Fhat a σ f xs ys (x - η • gradient (Fhat a σ f xs ys) x)\n ≤ Fhat a σ f xs ys x - (η/2) * ‖gradient (Fhat a σ f xs ys) x‖^2 :=\n fun x => descent hFdiff hLF hη0 hη hsmooth x\n have hws0 : ws 0 = w0 := rfl\n have hwsS : ∀ t, ws (t+1) = ws t - η • gradient (Fhat a σ f xs ys) (ws t) := fun t => rfl\n have hwid : 18 * (L * R^2 / Real.sqrt (m:ℝ)) * ‖w - w0‖^2 ≤ 1 := by\n have hc : (0:ℝ) ≤ 18 * L * R^2 * ‖w - w0‖^2 := by positivity\n have hsq : (18 * L * R^2 * ‖w - w0‖^2)^2 ≤ (m:ℝ) := by nlinarith [hwidth]\n have hle : 18 * L * R^2 * ‖w - w0‖^2 ≤ Real.sqrt (m:ℝ) := by\n have h2 := Real.sqrt_le_sqrt hsq\n rwa [Real.sqrt_sq hc] at h2\n rw [show 18 * (L * R^2 / Real.sqrt (m:ℝ)) * ‖w - w0‖^2\n = (18 * L * R^2 * ‖w - w0‖^2) / Real.sqrt (m:ℝ) by ring, div_le_one hsm]\n exact hle\n have hnorm1 : η * (T:ℝ) * Fhat a σ f xs ys w ≤ ‖w - w0‖^2 := le_trans (le_max_left _ _) hnorm\n have hnorm2 : η * Fhat a σ f xs ys w0 ≤ ‖w - w0‖^2 := le_trans (le_max_right _ _) hnorm\n obtain ⟨hAbound, hSum⟩ := abstract_gd hκ hη0 hFpos hFdiff hLS hdesc w0 ws hws0 hwsS T w\n hnorm1 hnorm2 hwid\n have hA2 : (0:ℝ) ≤ ‖w - w0‖^2 := sq_nonneg _\n refine ⟨?_, ?_, ?_⟩\n · have hanti := F_antitone hdesc (le_of_lt hη0) ws hwsS\n have hcard : (Finset.Icc 1 T).card = T := by rw [Nat.card_Icc]; omega\n have hlow : (T:ℝ) * Fhat a σ f xs ys (ws T)\n ≤ ∑ t ∈ Finset.Icc 1 T, Fhat a σ f xs ys (ws t) := by\n have h := Finset.card_nsmul_le_sum (Finset.Icc 1 T) (fun t => Fhat a σ f xs ys (ws t))\n (Fhat a σ f xs ys (ws T)) (fun i hi => hanti i T (Finset.mem_Icc.mp hi).2)\n rw [hcard, nsmul_eq_mul] at h\n exact h\n have h2 : (1/(T:ℝ)) * ((T:ℝ) * Fhat a σ f xs ys (ws T))\n ≤ (1/(T:ℝ)) * (∑ t ∈ Finset.Icc 1 T, Fhat a σ f xs ys (ws t)) :=\n mul_le_mul_of_nonneg_left hlow (by positivity)\n rw [show (1/(T:ℝ)) * ((T:ℝ) * Fhat a σ f xs ys (ws T)) = Fhat a σ f xs ys (ws T) by\n field_simp] at h2\n exact h2\n · have step : (1/(T:ℝ)) * (∑ t ∈ Finset.Icc 1 T, Fhat a σ f xs ys (ws t))\n ≤ (1/(T:ℝ)) * (2*(T:ℝ)*Fhat a σ f xs ys w + (5/4)*‖w - w0‖^2/η) :=\n mul_le_mul_of_nonneg_left hSum (by positivity)\n have eqn : (1/(T:ℝ)) * (2*(T:ℝ)*Fhat a σ f xs ys w + (5/4)*‖w - w0‖^2/η)\n = 2*Fhat a σ f xs ys w + (5/4)*‖w - w0‖^2/(η*(T:ℝ)) := by\n field_simp\n have fin : (5/4)*‖w - w0‖^2/(η*(T:ℝ)) ≤ 5*‖w - w0‖^2/(2*η*(T:ℝ)) := by\n rw [div_le_div_iff₀ (by positivity) (by positivity)]\n nlinarith [mul_nonneg (mul_nonneg hA2 (le_of_lt hη0)) (le_of_lt hTT)]\n linarith\n · intro t _ htT\n have h := hAbound t htT\n have htri : ‖ws t - w0‖ ≤ ‖ws t - w‖ + ‖w - w0‖ := by\n calc ‖ws t - w0‖ = ‖(ws t - w) + (w - w0)‖ := by congr 1; abel\n _ ≤ ‖ws t - w‖ + ‖w - w0‖ := norm_add_le _ _\n linarith\n\ntheorem thm3_3 {m d n : ℕ} (hm : 0 < m) (hn : 0 < n) (T : ℕ) (hT : 0 < T)\n (R ℓ L LF η : ℝ) (hR : 0 ≤ R) (hℓ : 0 ≤ ℓ) (hL : 0 ≤ L)\n (hLF : 0 < LF) (hη0 : 0 < η)\n (a : Fin m → ℝ) (ha : ∀ j, a j = 1 ∨ a j = -1)\n (hbal : (∑ j, a j) = 0)\n (σ f : ℝ → ℝ)\n (hσ : Differentiable ℝ σ) (hσd : Differentiable ℝ (deriv σ)) (hσ' : ∀ u, |deriv σ u| ≤ ℓ)\n (hσ'' : ∀ u, |deriv (deriv σ) u| ≤ L)\n (hf : Differentiable ℝ f) (hfd : Differentiable ℝ (deriv f)) (hfpos : ∀ u, 0 ≤ f u)\n (hfconv : ConvexOn ℝ Set.univ f) (hf' : ∀ u, |deriv f u| ≤ 1)\n (hf'' : ∀ u, deriv (deriv f) u ≤ 1) (hfsb : ∀ u, |deriv f u| ≤ f u)\n (hfdec : Antitone f)\n (hflim : Filter.Tendsto f Filter.atTop (nhds 0))\n (xs : Fin n → EuclideanSpace ℝ (Fin d)) (ys : Fin n → ℝ)\n (hx : ∀ i, ‖xs i‖ ≤ R) (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (w0 : Params m d)\n (hsmooth : ∀ u v, ‖gradient (Fhat a σ f xs ys) u - gradient (Fhat a σ f xs ys) v‖\n ≤ LF * ‖u - v‖)\n (g : ℝ → ℝ) (hgpos : ∀ ε, 0 < ε → 0 < g ε)\n (hgdec : ∀ ε₁ ε₂, 0 < ε₁ → ε₁ ≤ ε₂ → g ε₂ ≤ g ε₁)\n\n (ε₀ : ℝ) (hε₀ : 0 < ε₀)\n (hreal : ∀ ε, 0 < ε → ε ≤ ε₀ → ∃ wε : Params m d,\n Fhat a σ f xs ys wε ≤ ε ∧ ‖wε - w0‖ = g ε)\n (hTsmall : 1 / (T : ℝ) ≤ ε₀)\n (hFw0 : 0 < Fhat a σ f xs ys w0)\n (hη : η ≤ min (1 / LF) (min (g 1 ^ 2) (g 1 ^ 2 / Fhat a σ f xs ys w0)))\n (hwidth : (m : ℝ) ≥ 18 ^ 2 * L ^ 2 * R ^ 4 * g (1 / (T : ℝ)) ^ 4) :\n let ws := gdSeq a σ f xs ys η w0\n Fhat a σ f xs ys (ws T)\n ≤ 2 / (T : ℝ) + 5 * g (1 / (T : ℝ)) ^ 2 / (2 * η * (T : ℝ))\n ∧ ∀ t, 1 ≤ t → t ≤ T → ‖ws t - w0‖ ≤ 4 * g (1 / (T : ℝ)) := by\n \n intro ws\n have hTT : (0:ℝ) < (T:ℝ) := by exact_mod_cast hT\n have hT1 : (1:ℝ)/(T:ℝ) ≤ 1 := by\n rw [div_le_one hTT]\n exact_mod_cast hT\n have hεpos : (0:ℝ) < 1/(T:ℝ) := by positivity\n obtain ⟨wε, hwε1, hwε2⟩ := hreal (1/(T:ℝ)) hεpos hTsmall\n have hηLF : η ≤ 1/LF := le_trans hη (min_le_left _ _)\n have hηg1 : η ≤ g 1 ^ 2 := le_trans hη (le_trans (min_le_right _ _) (min_le_left _ _))\n have hηg2 : η ≤ g 1 ^ 2 / Fhat a σ f xs ys w0 :=\n le_trans hη (le_trans (min_le_right _ _) (min_le_right _ _))\n have hg1pos : 0 < g 1 := hgpos 1 one_pos\n have hgmono : g 1 ≤ g (1/(T:ℝ)) := hgdec (1/(T:ℝ)) 1 hεpos hT1\n have hgsq : g 1 ^ 2 ≤ g (1/(T:ℝ))^2 := by nlinarith\n have hFpos : ∀ x : Params m d, 0 ≤ Fhat a σ f xs ys x := by\n intro x\n rw [Fhat]\n exact mul_nonneg (by positivity) (Finset.sum_nonneg (fun i _ => hfpos _))\n have hnorm' : ‖wε - w0‖ ^ 2 ≥ max (η * T * Fhat a σ f xs ys wε) (η * Fhat a σ f xs ys w0) := by\n rw [ge_iff_le, hwε2]\n apply max_le\n · have hstep : η * (T:ℝ) * Fhat a σ f xs ys wε ≤ η * (T:ℝ) * (1/(T:ℝ)) := by\n apply mul_le_mul_of_nonneg_left hwε1 (by positivity)\n have heq : η * (T:ℝ) * (1/(T:ℝ)) = η := by field_simp\n rw [heq] at hstep\n linarith\n · have hstep : η * Fhat a σ f xs ys w0\n ≤ (g 1 ^ 2 / Fhat a σ f xs ys w0) * Fhat a σ f xs ys w0 :=\n mul_le_mul_of_nonneg_right hηg2 (le_of_lt hFw0)\n have heq : (g 1 ^ 2 / Fhat a σ f xs ys w0) * Fhat a σ f xs ys w0 = g 1 ^ 2 := by\n field_simp\n rw [heq] at hstep\n linarith\n have hwidth' : (m : ℝ) ≥ 18 ^ 2 * L ^ 2 * R ^ 4 * ‖wε - w0‖ ^ 4 := by\n rw [hwε2]; exact hwidth\n have hmain := thm3_2 hm hn T hT R ℓ L LF η hR hℓ hL hLF hη0 hηLF a ha hbal σ f\n hσ hσd hσ' hσ'' hf hfd hfpos hfconv hf' hf'' hfsb hfdec hflim xs ys hx hy w0 wε hsmooth\n hnorm' hwidth'\n obtain ⟨h1, h2, h3⟩ := hmain\n constructor\n · have hb : Fhat a σ f xs ys (ws T)\n ≤ 2 * Fhat a σ f xs ys wε + 5 * ‖wε - w0‖ ^ 2 / (2 * η * (T:ℝ)) := le_trans h1 h2\n rw [hwε2] at hb\n have : 2 * Fhat a σ f xs ys wε ≤ 2 * (1/(T:ℝ)) := by linarith\n have h2T : 2 * (1/(T:ℝ)) = 2/(T:ℝ) := by ring\n linarith [hb, this, h2T.le, h2T.ge]\n · intro t ht1 ht2\n have := h3 t ht1 ht2\n rwa [hwε2] at this\n\nend ResearchLevel\n"} +{"id": "v24-22-0339", "source": "Research-level", "targets": [{"label": "Lemma 11 (minimax strong duality)", "decls": ["lemma11_strongDuality"], "statement": "Lemma 11 Let U be an uncertainty set given by (4) that satisfies R1 or R2. For any h $\\in T(\\mathcal{X},\\mathcal{Y})$ , we have that\n\n$$\n\\operatorname*{sup}_{\\mathbf{p}\\in\\mathcal{U}}\\ell(\\mathbf{h},\\mathbf{p})=\\operatorname*{min}_{\\mu\\in\\mathbb{R}^{m}}1-\\tau^{T}\\pmb{\\mu}+\\operatorname*{sup}_{x\\in\\mathcal{X},y\\in\\mathcal{Y}}\\left\\{\\Phi(x,y)^{T}\\pmb{\\mu}-\\mathrm{h}(y|x)\\right\\}+\\lambda^{T}|\\mu|\\tag{37}\n$$", "context_ids": ["v24-22-0339:ctx1", "v24-22-0339:ctx2", "v24-22-0339:ctx3", "v24-22-0339:ctx4", "v24-22-0339:ctx5", "v24-22-0339:ctx6", "v24-22-0339:fix:1"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}, {"label": "Theorem 5", "decls": ["theorem5"], "statement": "Theorem 5 Let U be an uncertainty set given by (4), h be any classification rule, and $\\underline{{R}}(\\mathcal{U},\\mathrm{h})$ and $\\overline{{R}}(\\mathcal{U},\\mathrm{h})$ be given by\n\n$$\n\\underline{{R}}(\\mathcal{U},\\mathrm{h})=\\operatorname*{sup}_{\\mu}\\ 1-{\\tau^{T}}\\mu+\\operatorname*{inf}_{x\\in\\mathcal{X},y\\in\\mathcal{Y}}\\{\\Phi(x,y)^{T}\\mu-\\mathrm{h}(y|x)\\}-{\\lambda^{T}}|\\mu|\\tag{20}\n$$\n\n$$\n\\overline{{R}}(\\mathcal{U},\\mathrm{h})=\\operatorname*{inf}_{\\mu}\\ 1-\\tau^{T}\\pmb{\\mu}+\\operatorname*{sup}_{x\\in\\mathcal{X},y\\in\\mathcal{Y}}\\{\\Phi(x,y)^{T}\\pmb{\\mu}-\\mathrm{h}(y|x)\\}+\\pmb{\\lambda}^{T}|\\pmb{\\mu}|.\\tag{21}\n$$\n\nThen, for any ${\\mathrm{p}}\\in \\mathcal{U}$ we have that $\\underline{{R}}(\\mathcal{U},\\mathrm{h})\\le\\ell(\\mathrm{h},\\mathrm{p})\\le\\overline{{R}}(\\mathcal{U},\\mathrm{h})$ . In addition, if U satisfies R1 or R2 the optimal values in (20) and (21) are attained.", "context_ids": ["v24-22-0339:ctx1", "v24-22-0339:ctx2", "v24-22-0339:ctx3", "v24-22-0339:ctx4", "v24-22-0339:ctx5", "v24-22-0339:ctx6", "v24-22-0339:fix:1"], "sibling_refs": ["Lemma 11 (minimax strong duality)"], "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}, {"label": "Theorem 4 (Hoeffding case, eq. 17)", "decls": ["theorem4_hoeffding"], "statement": "Theorem 4 Let the mean vector be given by $\\tau = \\tau_{n}$ as in (5) for n training samples, and $\\mathcal{F}$ be a family of bounded scalar features, that is $|\\psi(x)|\\leq C$ for all $\\psi \\in{\\mathcal{F}}$ and $x \\in \\mathcal{X}$\n\nIf $\\left| \\mathcal{F}\\right| < \\infty$ and $\\Phi$ is given by (16) using all $D = |\\mathcal{F}|$ scalar features of $\\mathcal{F}$ (so that $m = |\\mathcal{F}||\\mathcal{Y}|$), $\\lambda_{\\delta}^{(i)}$ for $i=1,2,\\ldots,m$ can be taken as\n\n$$\n\\lambda_{\\delta}^{(i)}=C\\sqrt{\\frac{2\\log 2\\vert\\mathcal{F}\\vert\\vert\\mathcal{Y}\\vert/\\delta}{n}}.\\tag{17}\n$$", "context_ids": ["v24-22-0339:ctx1", "v24-22-0339:ctx2", "v24-22-0339:ctx4", "v24-22-0339:ctx5", "v24-22-0339:ctx7", "v24-22-0339:ctx8", "v24-22-0339:ctx9", "v24-22-0339:ctx10"], "sibling_refs": [], "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "### Proof of Lemma 11 (minimax strong duality)\n\nIn the first step of the proof we show that the right hand side of (36) is equivalent to the Fenchel dual of the left hand side, then the second step of the proof shows that strong duality holds if U satisfies R1 or R2.\n\nLet $0 \\leq r \\leq m$ be the number of non-zero components of λ (without loss of generality we assume such components are the r first components of λ), and $M(\\mathcal{X}\\times\\mathcal{Y})$ be the set of signed Borel measures over $\\mathcal{X}\\times \\mathcal{Y}$ with bounded total variation. The set $M(\\mathcal{X}\\times\\mathcal{Y})$ is a Banach space with the total variation norm (see e.g., Chapter 10 in Aliprantis and Border (1994)).\n\nIf A is the linear mapping\n\n$$\n\\begin{array}{r l}{A:}&{M(\\mathcal{X}\\times\\mathcal{Y})\\ \\to\\ \\mathbb{R}^{r+m+1}}\\\\ &{\\qquad \\textrm{p}\\mapsto [\\int\\Phi_{1}(x,y)d\\mathrm{p}(x,y),-\\int\\Phi_{1}(x,y)d\\mathrm{p}(x,y),\\int\\Phi_{2}(x,y)d\\mathrm{p}(x,y),\\int d\\mathrm{p}(x,y)]}\\end{array}\\tag{38}\n$$\n\nwhere $\\Phi_{1}(x,y)\\in\\mathbb{R}^{r}$ denotes the first r components of $\\Phi(x,y)$ and $\\Phi_{2}(x,y)\\in\\mathbb{R}^{m-r}$ denotes the last $m - r$ components of $\\Phi(x,y)$ . A is bounded and its adjoint operator is\n\n$$\n\\begin{array}{r}{\\begin{array}{l c l l}{A^{*}:}&{\\mathbb{R}^{r+m+1}}&{\\to}&{F({\\mathcal X}\\times{\\mathcal Y})\\subseteq(M({\\mathcal X}\\times{\\mathcal Y}))^{*}}\\\\ &{\\mu_{1},\\mu_{2},\\mu_{3},\\nu}&{\\mapsto}&{\\Phi_{1}(\\cdot,\\cdot)^{\\mathrm{T}}(\\mu_{1}-\\mu_{2})+\\Phi_{2}(\\cdot,\\cdot)^{\\mathrm{T}}\\mu_{3}+\\nu .}\\end{array}}\\end{array}\\tag{39}\n$$\n\nwhere $F(\\mathcal{X}\\times\\mathcal{Y})$ is the set of bounded Borel measurable functions over $\\mathcal{X}\\times \\mathcal{Y}$.\n\nThen, we have that\n\n$$\n\\operatorname*{sup}_{\\mathbf{p}\\in\\mathcal{U}}\\ell(\\mathrm{h,p})=\\operatorname*{sup}_{\\mathbf{p}\\in\\mathcal{U}}1-\\int\\mathrm{h}(y|x)d\\mathbf{p}(x,y)=1-\\operatorname*{inf}_{\\mathbf{p}\\in M(\\mathcal{X}\\times\\mathcal{Y})}f(\\mathbf{p})+g(A(\\mathbf{p}))\\tag{40}\n$$\n\nwhere f and g are the lower semi-continuous convex functions\n\n$$\n\\begin{array}{rlcl}g:&\\mathbb{R}^{r+m+1}&\\to&\\mathbb{R}\\cup\\{\\infty\\}\\\\ &({\\bf a}_{1},{\\bf a}_{2},{\\bf a}_{3},b)&\\mapsto&\\left\\{\\begin{array}{ll}0&\\mathrm{if}\\ \\ {\\bf a}_{1}\\preceq\\tau_{1}+\\lambda_{1},\\ {\\bf a}_{2}\\preceq-\\tau_{1}+\\lambda_{1},{\\bf a}_{3}=\\tau_{2},b=1\\\\ \\infty&\\mathrm{otherwise}\\end{array}\\right.\\end{array}\\tag{41}\n$$\n\nfor $\\tau_{1},\\lambda_{1}\\in\\mathbb{R}^{r}\\ (\\mathrm{resp.}\\ \\tau_{2},\\lambda_{2}\\in\\mathbb{R}^{m-r})$ given by the first r (resp. last $m-r)$ components of $\\tau$ and λ, and\n\n$$\n\\begin{array}{rlcl}f\\colon&M(\\mathcal{X}\\times\\mathcal{Y})&\\to&\\mathbb{R}\\cup\\{\\infty\\}\\\\ &\\mathrm{p}&\\mapsto&\\left\\{\\begin{array}{ll}\\int\\mathrm{h}(y|x)d\\mathrm{p}(x,y)&\\mathrm{if}\\ \\mathrm{p}\\ \\text{is nonnegative}\\\\ \\infty&\\mathrm{otherwise}.\\end{array}\\right.\\end{array}\\tag{42}\n$$\n\nThen, the Fenchel dual (see e.g., Borwein and Zhu (2004)) of (40) is\n\n$$\n1-\\operatorname*{sup}_{\\mu_{1},\\mu_{2},\\mu_{3},\\nu}-f^{*}(A^{*}(\\mu_{1},\\mu_{2},\\mu_{3},\\nu))-g^{*}(-\\mu_{1},-\\mu_{2},-\\mu_{3},-\\nu)\\tag{43}\n$$\n\nwhere $f^{*}$ and $g^{*}$ are the conjugate functions of f and g. If $w\\in F(\\mathcal{X}\\times\\mathcal{Y})$ , we have that\n\n$$\n\\begin{array}{rl}f^{*}(w)&=\\sup_{\\mathrm{p}\\succeq 0}\\int(w(x,y)-\\mathrm{h}(y|x))d\\mathrm{p}(x,y)\\\\ &=\\left\\{\\begin{array}{lll}0&\\mathrm{if}&w(x,y)\\leq\\mathrm{h}(y|x),\\ \\forall x,y\\in\\mathcal{X}\\times\\mathcal{Y}\\\\ \\infty&\\mathrm{otherwise}&\\end{array}\\right.\\end{array}\n$$\n\nand $g^{*}(-{\\pmb\\mu}_{1},-{\\pmb\\mu}_{2},-{\\pmb\\mu}_{3},-\\nu)$ is given by\n\n$$\n\\begin{array}{rl}\\sup&-\\mathbf{a}_{1}^{\\mathrm{T}}\\mu_{1}-\\mathbf{a}_{2}^{\\mathrm{T}}\\mu_{2}-\\tau_{2}^{\\mathrm{T}}\\mu_{3}-\\nu\\\\ \\mathrm{s.t.}&\\mathbf{a}_{1}\\preceq\\tau_{1}+\\lambda_{1},\\ \\mathbf{a}_{2}\\preceq-\\tau_{1}+\\lambda_{1}\\\\ =&\\left\\{\\begin{array}{ll}-(\\tau_{1}+\\lambda_{1})^{\\mathrm{T}}\\mu_{1}+(\\tau_{1}-\\lambda_{1})^{\\mathrm{T}}\\mu_{2}-\\tau_{2}^{\\mathrm{T}}\\mu_{3}-\\nu&\\mathrm{if}\\ -\\mu_{1}\\succeq\\mathbf{0},-\\mu_{2}\\succeq\\mathbf{0}\\\\ \\infty&\\mathrm{otherwise.}\\end{array}\\right.\\end{array}\n$$\n\nHence, the dual problem (43) becomes\n\n$$\n\\begin{array}{rll}\\inf_{\\mu_{1},\\mu_{2},\\mu_{3},\\nu}&1-(\\tau_{1}+\\lambda_{1})^{\\mathrm{T}}\\mu_{1}-(-\\tau_{1}+\\lambda_{1})^{\\mathrm{T}}\\mu_{2}-\\tau_{2}^{\\mathrm{T}}\\mu_{3}-\\nu&\\\\ \\mathrm{s.t.}&\\Phi_{1}(x,y)^{\\mathrm{T}}(\\mu_{1}-\\mu_{2})+\\Phi_{2}(x,y)^{\\mathrm{T}}\\mu_{3}+\\nu\\leq\\mathrm{h}(y|x),\\ \\forall(x,y)\\in\\mathcal{X}\\times\\mathcal{Y}&\\\\ &-\\mu_{1}\\succeq\\mathbf{0},-\\mu_{2}\\succeq\\mathbf{0}&\\\\ =\\inf_{\\mu_{1},\\mu_{2},\\mu_{3},\\nu}&1+(\\tau_{1}+\\lambda_{1})^{\\mathrm{T}}\\mu_{1}+(-\\tau_{1}+\\lambda_{1})^{\\mathrm{T}}\\mu_{2}-\\tau_{2}\\mu_{3}-\\nu&\\\\ \\mathrm{s.t.}&\\Phi_{1}(x,y)^{\\mathrm{T}}(\\mu_{2}-\\mu_{1})+\\Phi_{2}(x,y)^{\\mathrm{T}}\\mu_{3}+\\nu\\leq\\mathrm{h}(y|x),\\ \\forall(x,y)\\in\\mathcal{X}\\times\\mathcal{Y}&(44)\\\\ &\\mu_{1}\\succeq\\mathbf{0},\\mu_{2}\\succeq\\mathbf{0}&\\\\ =\\inf_{\\mu,\\nu}&1-\\tau^{\\mathrm{T}}\\mu+\\lambda^{\\mathrm{T}}|\\mu| -\\nu&\\\\ \\mathrm{s.t.}&\\Phi(x,y)^{\\mathrm{T}}\\mu+\\nu\\leq\\mathrm{h}(y|x),\\ \\forall(x,y)\\in\\mathcal{X}\\times\\mathcal{Y}&(45)\\\\ =\\inf_{\\mu}&1-\\tau^{\\mathrm{T}}\\mu+\\sup_{(x,y)\\in\\mathcal{X}\\times\\mathcal{Y}}\\left\\{\\Phi(x,y)^{\\mathrm{T}}\\mu-\\mathrm{h}(y|x)\\right\\}+\\lambda^{\\mathrm{T}}|\\mu|.&(46)\\end{array}\n$$\n\nThe expression in (45) is obtained taking ${\\pmb \\mu}= [ ({\\pmb \\mu}_{2}-{\\pmb \\mu}_{1})^{\\mathrm{T}},{\\pmb \\mu}_{3}^{\\mathrm{T}}]^{\\mathrm{T}}$ . Firstly, in (44) we can consider only pairs $\\pmb{\\mu}_{1}, \\pmb{\\mu}_{2}$ such that $\\pmb{\\mu}_{1}+ \\pmb{\\mu}_{2}= | \\pmb{\\mu}_{1}- \\pmb{\\mu}_{2}|$ because for any pair $\\pmb{\\mu}_{1}, \\pmb{\\mu}_{2}$ feasible in (44), we have that $\\tilde{\\pmb{\\mu}}_{1}=(\\pmb{\\mu}_{2}-\\pmb{\\mu}_{1})_{+},\\tilde{\\pmb{\\mu}}_{2}=(\\pmb{\\mu}_{1}-\\pmb{\\mu}_{2})_{+}$ is a feasible pair because $\\tilde{\\pmb{\\mu}}_{1}- \\tilde{\\pmb{\\mu}}_{2}= \\pmb{\\mu}_{1}- \\pmb{\\mu}_{2}$ , and we also have that $\\lambda_{1}^{\\mathrm{T}}|\\tilde{{\\pmb\\mu}}_{1}-\\tilde{{\\pmb\\mu}}_{2}| =\\lambda_{1}^{\\mathrm{T}}(\\tilde{{\\pmb\\mu}}_{1}+\\tilde{{\\pmb\\mu}}_{2})\\leq\\lambda_{1}^{\\mathrm{T}}({\\pmb\\mu}_{1}+{\\pmb\\mu}_{2})$ Then, we obtain (45) from (44) because\n\n$$\n\\begin{array}{c}{{\\tau_{1}^{\\mathrm{T}}(\\mu_{2}-\\mu_{1})+\\tau_{2}^{\\mathrm{T}}\\mu_{3}=\\tau^{\\mathrm{T}}\\mu}}\\\\ {{\\lambda_{1}^{\\mathrm{T}}|\\mu_{2}-\\mu_{1}| =\\lambda^{\\mathrm{T}}|\\mu|,\\mathrm{~since~}\\lambda_{2}=0}}\\\\ {{\\Phi_{1}(x,y)^{\\mathrm{T}}(\\mu_{2}-\\mu_{1})+\\Phi_{2}(x,y)^{\\mathrm{T}}\\mu_{3}=\\Phi(x,y)^{\\mathrm{T}}\\mu .}}\\end{array}\n$$\n\nThe expression in (46) is obtained since for any feasible $(\\mu,\\nu)$ in (45) we have that $(\\mu,\\tilde{\\nu})$ is feasible if\n\n$$\n\\tilde{\\nu}=\\operatorname*{inf}_{(x,y)\\in\\mathcal{X}\\times\\mathcal{Y}}\\{\\mathrm{h}(y|x)-\\Phi(x,y)^{\\mathrm{T}}\\pmb{\\mu}\\}\n$$\n\nand $\\tilde{\\nu}\\geq \\nu .$ Then, the inequality in (36) follows by weak duality.\n\nFor the second step of the proof, if U satisfies R1, we have that strong duality holds because the dual becomes the Lagrange dual and the constraints in (40) are linear affine (see e.g., Chapter 5 in Boyd and Vandenberghe (2004)). If U satisfies R2, we show in the following that strong duality holds because $\\mathbf{0}\\in\\operatorname{int}(\\operatorname{dom}g-A\\operatorname{dom}f)$ (see e.g., Chapter 4 in Borwein and Zhu (2004)), where dom denotes the set where an extended-valued function takes finite values, and int denotes the interior of a set.\n\nIf U satisfies R2.1, there exists $R > 0$ such that $R<\\lambda^{(i)}- |\\mathbb{E}_{\\mathrm{p}}\\Phi^{(i)}(x,y)-\\tau^{(i)}|$ for $i=1,2,\\dots,m$ . Then, the second step of the proof is obtained by showing that if $0 < \\varepsilon <$ $R/(R+1+\\|\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}\\|_{2})<1$ , we have that the ball with radius ε centered in $\\mathbf{0}\\in \\mathbb{R}^{r + m + 1}$, $B(\\mathbf{0},\\varepsilon)$ satisfies $B(\\mathbf{0},\\varepsilon)\\subset(\\operatorname{dom}g-A\\operatorname{dom}f)\\subset\\mathbb{R}^{r+m+1}$.\n\nWe have that for any $\\mathbf{z}\\in B(\\mathbf{0},\\varepsilon)\\subset\\mathbb{R}^{2m+1}$ , there exist $\\pmb{\\xi}_{1},\\pmb{\\xi}_{2}\\in B(\\mathbf{0},R)\\subset\\mathbb{R}^{m}$ such that\n\n$$\n\\begin{array}{c}{{\\left(z^{(1)},z^{(2)},\\ldots,z^{(m)}\\right)=\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}+\\xi_{1}-(1-z^{(2m+1)})\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}}}\\\\ {{\\left(z^{(m+1)},z^{(m+2)},\\ldots,z^{(2m)}\\right)= -\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}+\\xi_{2}+(1-z^{(2m+1)})\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}}}\\\\ {{z^{(2m+1)}=1-(1-z^{(2m+1)})}}\\end{array}\n$$\n\nbecause we have that\n\n$$\n\\|\\big(z^{(1)},z^{(2)},\\ldots,z^{(m)}\\big)-z^{(2m+1)}\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}\\|_{2}\\leq\\varepsilon(1+\\|\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}\\|_{2}) 0$ be such that\n\n$$\n\\begin{array}{r}{1 .\\ R<\\lambda^{(i)}- |\\mathbb{E}_{\\mathrm{p}}\\Phi^{(i)}(x,y)-\\tau^{(i)}|\\ \\mathrm{for}\\ i=1,2,\\dots,r,\\ \\mathrm{and}}\\end{array}\n$$\n\n2. for any $\\boldsymbol{\\xi}$ in the Euclidean ball of $\\mathbb{R}^{m}$ centered at 0 with radius $R,B(\\mathbf{0},R)$ , we have that $\\mathbb{E}_{\\mathrm{p}}\\{\\Phi\\}+\\pmb{\\xi}\\in\\mathrm{Conv}S .$ that is, there exists $\\mathrm{p}_{\\xi}\\in\\Delta(\\mathcal{X}\\times\\mathcal{Y})$ such that ${\\mathbb E}_{\\mathrm{p}_{\\xi}}\\{\\Phi \\}={\\mathbb E}_{\\mathrm{p}}\\{\\Phi \\}+ \\xi$\n\nAs in the previous case, the second step of the proof is obtained by showing that if $0<\\varepsilon0$ and\n\nR2.1 $\\lambda^{(i)}>0$ for all $i\\in\\{1,2,\\dots,m\\}$ or\n\nR2.2 the support of the r.v. $\\Phi(x,y)$ for $(x,y)\\sim\\mathrm{p}$ is not contained in a proper affine subspace of $\\mathbb{R}^{m}$"}, {"id": "v24-22-0339:ctx6", "name": "Role of the regularity conditions (Section 2.2)", "statement": "These regularity conditions are utilized to ensure strong duality holds for the inner maximization in the minimax problems, and they are satisfied with wide generality."}, {"id": "v24-22-0339:ctx7", "name": "Mean vector estimate tau_n, eq. (5) (Section 2.2)", "statement": "The mean vector $\\tau \\in \\mathbb{R}^{m}$ in (4) is an estimate of the feature mapping expectation $\\mathbb{E}_{\\mathrm{p}^{*}}\\{\\Phi \\}$ with respect to the underlying distribution. In this paper, we consider expectation estimates obtained as the sample average\n\n$$\n\\tau_{n}=\\frac{1}{n}\\sum_{i=1}^{n}\\Phi(x_{i},y_{i})\\tag{5}\n$$\n\nobtained from the n training samples $(x_{1},y_{1}),(x_{2},y_{2}),\\dotsc,(x_{n},y_{n})$ that are assumed to be independent samples from the underlying distribution $\\mathrm{p}^{\\ast}$ . Nevertheless, it is important to note that most of the results presented in the paper as well as the general methodology proposed can be utilized with general types of expectation estimates. Alternative estimators for the expectation can be preferred in several practical scenarios including cases with different distributions at training and test (Mohri and Medina, 2012; Mazuelas and Perez, 2020; Álvarez et al., 2022) and cases where the distribution of features has heavy tails (Lugosi and Mendelson, 2019; Hsu and Sabato, 2016)."}, {"id": "v24-22-0339:ctx8", "name": "Confidence vector lambda (Section 2.2)", "statement": "The confidence vector $\\pmb{\\lambda}\\in \\mathbb{R}^{m}$ in (4) is an estimate of the mean vector component-wise accuracy $\\left| \\mathbb{E}_{\\mathrm{p}^{*}}\\{\\Phi \\}- \\tau \\right|$ , and controls the size of the uncertainty set considered. In particular, if λ corresponds to the length of confidence intervals at level $1 - \\delta$ centered at $\\tau$, then the true underlying distribution is included in the uncertainty set (4) with probability at least $1 - \\delta$. Section 3.2 describes how to choose such confidence vectors for different feature mappings."}, {"id": "v24-22-0339:ctx9", "name": "Feature mapping (16): one-hot label blocks of scalar features (Section 3.1)", "statement": "Most of the results presented in the paper are valid for general feature mappings $\\Phi : \\mathcal{X}\\times \\mathcal{Y}\\to \\mathbb{R}^{m}$. In this section we describe feature mappings that are common in supervised classification and will be used later in the paper. Such feature mappings are given by real-valued functions over the set of instances $\\psi : \\mathcal{X}\\to \\mathbb{R}$ , referred to as scalar features. The most common and simple way to define feature mappings over $\\mathcal{X}$ and $\\mathcal{Y}$ is to use multiple scalar features over $\\mathcal{X}$ together with a one-hot encoding of the elements of $\\mathcal{Y}$ (Tsochantaridis et al., 2005; Crammer et al., 2006; Mohri et al., 2018) as follows\n\n$$\n\\Phi(x,y)=[\\mathbb{I}\\{y=1\\}\\Psi(x)^{\\mathrm{T}},\\mathbb{I}\\{y=2\\}\\Psi(x)^{\\mathrm{T}},\\ldots,\\mathbb{I}\\{y= |\\mathcal{Y}|\\}\\Psi(x)^{\\mathrm{T}}]^{\\mathrm{T}}=\\mathbf{e}_{y}\\otimes\\Psi(x)\\tag{16}\n$$\n\nwhere $\\Psi(x)=[\\psi_{1}(x),\\psi_{2}(x),\\ldots,\\psi_{D}(x)]^{\\mathrm{T}}$ for D scalar features $\\psi_{1},\\psi_{2},\\ldots,\\psi_{D},\\mathbf{e}_{y}$ is the $y \\mathrm{- t h}$ vector in the standard basis of $\\mathbb{R}^{| \\mathcal{Y}|}$ , and $\\otimes$ denotes the Kronecker product. The feature mapping $\\Phi$ represents each instance-label pair $(x,y)$ by an m-dimensional real vector with $m = | \\mathcal{Y}| D$ , so that $\\Phi(x,y)$ is composed by $|\\mathcal{Y}|$ $D$-dimensional blocks with values $\\Psi(x)$ in the block corresponding to y and zero otherwise. Other feature mappings can exploit relationships among classes as described for instance in Bakir et al. (2007); Caponnetto et al. (2008)."}, {"id": "v24-22-0339:ctx10", "name": "Section 3.2 setup and coverage definition of lambda_delta", "statement": "In this section, we describe conditions for confidence vectors λ that lead to uncertainty sets given by (4) that contain the true underlying distribution with high probability. Specifically, we consider uncertainty sets U given by feature mappings defined by (16) using scalar features in a family $\\mathcal{F}$ together with mean vectors obtained as in (5) using the sample average of n independent samples from the underlying distribution $\\mathrm{p}^{\\ast}$\n\nWe denote by $\\lambda_{\\delta}$ any confidence vector that has coverage probability at least $1-\\delta,$ $\\begin{array}{r}{\\mathrm{i.e.,}\\operatorname{\\mathbb{P}}\\{|{\\mathbb{E}}_{\\mathrm{p}^{*}}\\{\\Phi\\}-\\pmb{\\tau}|\\preceq\\lambda_{\\delta}\\}\\geq 1-\\delta,}\\end{array}$ so that the underlying distribution $\\mathrm{p}^{\\ast}$ is included with probability at least $1 - \\delta$ in the uncertainty set given by $\\lambda_{\\delta}$ . The following result describes such confidence vectors in terms of the cardinality $|\\mathcal{F}|$, the empirical variance of the feature mapping, and the Rademacher complexity $\\mathcal{R}_{n}(\\mathcal{F})$ . In most of the results in the paper, we utilize feature mappings given by scalar features chosen before the training samples are observed. In such cases, appropriate confidence vectors are given in terms of the cardinality $| \\mathcal F |$ , i.e., the number of scalar features used. However, the methods proposed can also be used with data-dependent feature mappings. In such cases, appropriate confidence vectors are given in terms of the Rademacher complexity $\\mathcal{R}_{n}(\\mathcal{F})$ where $\\mathcal{F}$ is the family of candidate scalar features. For instance, $\\mathcal{F}$ can be family of all decision stumps and the feature mapping can be defined using the decision stumps found by one-dimensional decision trees learned using the training samples, as in Mazuelas et al. (2020)."}, {"id": "v24-22-0339:fix:1", "name": "Lemma 11, display (36) (weak duality bound, Appendix A)", "statement": "Lemma 11 Let U be an uncertainty set given by (4). For any h $\\in T(\\mathcal{X},\\mathcal{Y})$ , we have that\n\n$$\n\\operatorname*{sup}_{\\mathbf{p}\\in\\mathcal{U}}\\ell(\\mathbf{h},\\mathbf{p})\\le\\operatorname*{inf}_{\\mu\\in\\mathbb{R}^{m}}1-\\tau^{T}\\pmb{\\mu}+\\operatorname*{sup}_{x\\in\\mathcal{X},y\\in\\mathcal{Y}}\\left\\{\\Phi(x,y)^{T}\\pmb{\\mu}-\\mathrm{h}(y|x)\\right\\}+\\lambda^{T}|\\mu|\\tag{36}\n$$"}], "lean": "import Mathlib\n\nopen MeasureTheory\n\nnamespace ResearchLevel\n\nnoncomputable def lambdaDelta (C δ : ℝ) (m n : ℕ) : ℝ :=\n C * Real.sqrt (2 * Real.log (2 * (m : ℝ) / δ) / (n : ℝ))\n\nnoncomputable def featExpectM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ)\n (p : Measure (𝒳 × 𝒴)) (i : Fin m) : ℝ :=\n ∫ z, Φ z.1 z.2 i ∂p\n\ndef inUncertaintySetM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ)\n (p : Measure (𝒳 × 𝒴)) : Prop :=\n IsProbabilityMeasure p ∧ (∀ i, |featExpectM Φ p i - τ i| ≤ lam i)\n\nnoncomputable def expectedLossM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] (h : 𝒳 → 𝒴 → ℝ) (p : Measure (𝒳 × 𝒴)) : ℝ :=\n ∫ z, (1 - h z.1 z.2) ∂p\n\nnoncomputable def RunderM {𝒳 𝒴 : Type*} {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ)\n (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) : ℝ :=\n ⨆ μ : Fin m → ℝ, (1 - (∑ i, τ i * μ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n - (∑ i, lam i * |μ i|))\n\nnoncomputable def RoverM {𝒳 𝒴 : Type*} {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ)\n (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) : ℝ :=\n ⨅ μ : Fin m → ℝ, (1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n + (∑ i, lam i * |μ i|))\n\nnoncomputable def worstCaseRiskM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ)\n (h : 𝒳 → 𝒴 → ℝ) : ℝ :=\n sSup {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p}\n\ndef R1 {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*} [MeasurableSpace 𝒴] {m : ℕ}\n (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) : Prop :=\n Finite 𝒳 ∧ ∃ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p\n\ndef R2 {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*} [MeasurableSpace 𝒴] {m : ℕ}\n (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) : Prop :=\n ∃ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p ∧\n (∀ i, 0 < lam i → |featExpectM Φ p i - τ i| < lam i) ∧\n ((∀ i, 0 < lam i) ∨\n ¬ ∃ (α : Fin m → ℝ) (c : ℝ), α ≠ 0 ∧ ∀ᵐ z ∂p, (∑ i, α i * Φ z.1 z.2 i) = c)\n\ntheorem theorem5 {𝒳 : Type*} [MeasurableSpace 𝒳] [StandardBorelSpace 𝒳] {𝒴 : Type*} [Fintype 𝒴]\n [MeasurableSpace 𝒴] [MeasurableSingletonClass 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ)\n (h : 𝒳 → 𝒴 → ℝ) (p : Measure (𝒳 × 𝒴))\n\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∃ B : ℝ, ∀ x y i, |Φ x y i| ≤ B)\n\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hrule_nonneg : ∀ x y, 0 ≤ h x y) (hrule_sum : ∀ x, ∑ y, h x y = 1)\n (hp : inUncertaintySetM Φ τ lam p)\n (hba : BddAbove (Set.range (fun μ : Fin m → ℝ => 1 - (∑ i, τ i * μ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) - (∑ i, lam i * |μ i|))))\n (hbb : BddBelow (Set.range (fun μ : Fin m → ℝ => 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|)))) :\n (RunderM Φ τ lam h ≤ expectedLossM h p ∧ expectedLossM h p ≤ RoverM Φ τ lam h)\n ∧ ((R1 Φ τ lam ∨ R2 Φ τ lam) →\n (∃ μ : Fin m → ℝ, 1 - (∑ i, τ i * μ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n - (∑ i, lam i * |μ i|) = RunderM Φ τ lam h)\n ∧ (∃ μ : Fin m → ℝ, 1 - (∑ i, τ i * μ i)\n + (⨆ q : ���� × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n + (∑ i, lam i * |μ i|) = RoverM Φ τ lam h)) := by\n sorry\n\ntheorem lemma11_strongDuality {𝒳 : Type*} [MeasurableSpace 𝒳] [StandardBorelSpace 𝒳]\n {𝒴 : Type*} [Fintype 𝒴] [MeasurableSpace 𝒴] [MeasurableSingletonClass 𝒴]\n [Nonempty 𝒳] [Nonempty 𝒴] {m : ℕ}\n (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ)\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∃ B : ℝ, ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hrule_nonneg : ∀ x y, 0 ≤ h x y) (hrule_sum : ∀ x, ∑ y, h x y = 1)\n (hlam : ∀ i, 0 ≤ lam i)\n (hreg : R1 Φ τ lam ∨ R2 Φ τ lam) :\n worstCaseRiskM Φ τ lam h = RoverM Φ τ lam h\n ∧ ∃ μ : Fin m → ℝ, RoverM Φ τ lam h = 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n + (∑ i, lam i * |μ i|) := by\n sorry\n\ntheorem theorem4_hoeffding {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)\n [IsProbabilityMeasure P] (m n : ℕ) (C δ : ℝ)\n (τ : Fin m → ℝ) (Z : Fin n → Ω → Fin m → ℝ)\n (hm : 0 < m) (hn : 0 < n) (hC : 0 ≤ C) (hδ : 0 < δ) (hδ1 : δ < 1)\n (nY : ℕ) (hnY : 0 < nY) (labelOf : Fin m → Fin nY)\n (D : ℕ) (hD : 0 < D)\n (hblocks : ∀ y : Fin nY, (Finset.univ.filter fun i => labelOf i = y).card = D)\n (hlabelOnto : Function.Surjective labelOf)\n (honehot : ∀ k ω, ∃ y : Fin nY, ∀ i, labelOf i ≠ y → Z k ω i = 0)\n (hbdd : ∀ k i ω, |Z k ω i| ≤ C)\n (hmeas : ∀ k, Measurable (Z k))\n (hindep : ProbabilityTheory.iIndepFun Z P)\n (hident : ∀ k l, ProbabilityTheory.IdentDistrib (Z k) (Z l) P P)\n (hmean : ∀ k i, ∫ ω, Z k ω i ∂P = τ i) :\n ENNReal.ofReal (1 - δ)\n ≤ P {ω | ∀ i : Fin m, |τ i - (∑ k, Z k ω i) / (n : ℝ)| ≤ lambdaDelta C δ m n} := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory\n\nnamespace ResearchLevel\n\nnoncomputable def lambdaDelta (C δ : ℝ) (m n : ℕ) : ℝ :=\n C * Real.sqrt (2 * Real.log (2 * (m : ℝ) / δ) / (n : ℝ))\n\nnoncomputable def featExpectM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ)\n (p : Measure (𝒳 × 𝒴)) (i : Fin m) : ℝ :=\n ∫ z, Φ z.1 z.2 i ∂p\n\ndef inUncertaintySetM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ)\n (p : Measure (𝒳 × 𝒴)) : Prop :=\n IsProbabilityMeasure p ∧ (∀ i, |featExpectM Φ p i - τ i| ≤ lam i)\n\nnoncomputable def expectedLossM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] (h : 𝒳 → 𝒴 → ℝ) (p : Measure (𝒳 × 𝒴)) : ℝ :=\n ∫ z, (1 - h z.1 z.2) ∂p\n\nnoncomputable def RunderM {𝒳 𝒴 : Type*} {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ)\n (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) : ℝ :=\n ⨆ μ : Fin m → ℝ, (1 - (∑ i, τ i * μ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n - (∑ i, lam i * |μ i|))\n\nnoncomputable def RoverM {𝒳 𝒴 : Type*} {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ)\n (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) : ℝ :=\n ⨅ μ : Fin m → ℝ, (1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n + (∑ i, lam i * |μ i|))\n\nnoncomputable def worstCaseRiskM {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*}\n [MeasurableSpace 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ)\n (h : 𝒳 → 𝒴 → ℝ) : ℝ :=\n sSup {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p}\n\ndef R1 {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*} [MeasurableSpace 𝒴] {m : ℕ}\n (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) : Prop :=\n Finite 𝒳 ∧ ∃ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p\n\ndef R2 {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*} [MeasurableSpace 𝒴] {m : ℕ}\n (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) : Prop :=\n ∃ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p ∧\n (∀ i, 0 < lam i → |featExpectM Φ p i - τ i| < lam i) ∧\n ((∀ i, 0 < lam i) ∨\n ¬ ∃ (α : Fin m → ℝ) (c : ℝ), α ≠ 0 ∧ ∀ᵐ z ∂p, (∑ i, α i * Φ z.1 z.2 i) = c)\n\nsection Weak\n\nvariable {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*} [Fintype 𝒴] [MeasurableSpace 𝒴]\n {m : ℕ}\n\nlemma aux_h_le_one (h : 𝒳 → 𝒴 → ℝ) (hnn : ∀ x y, 0 ≤ h x y)\n (hsum : ∀ x, ∑ y, h x y = 1) (x : 𝒳) (y : 𝒴) : h x y ≤ 1 := by\n rw [← hsum x]\n exact Finset.single_le_sum (fun j _ => hnn x j) (Finset.mem_univ y)\n\nlemma aux_integrable_of_bdd (p : Measure (𝒳 × 𝒴)) [IsFiniteMeasure p]\n (f : 𝒳 × 𝒴 → ℝ) (hf : Measurable f) (K : ℝ) (hK : ∀ z, |f z| ≤ K) :\n Integrable f p := by\n refine (integrable_const K).mono' hf.aestronglyMeasurable ?_\n filter_upwards with z\n simpa using hK z\n\nlemma aux_bdd_lin (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (B : ℝ) (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (μ : Fin m → ℝ) (z : 𝒳 × 𝒴) :\n |∑ i, Φ z.1 z.2 i * μ i| ≤ B * ∑ i, |μ i| := by\n calc |∑ i, Φ z.1 z.2 i * μ i| ≤ ∑ i, |Φ z.1 z.2 i * μ i| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ i, B * |μ i| := by\n refine Finset.sum_le_sum (fun i _ => ?_)\n rw [abs_mul]\n exact mul_le_mul_of_nonneg_right (hΦbdd _ _ i) (abs_nonneg _)\n _ = B * ∑ i, |μ i| := by rw [Finset.mul_sum]\n\n\nvariable (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) (B : ℝ)\n\nlemma aux_integral_f (p : Measure (𝒳 × 𝒴)) [IsFiniteMeasure p]\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hrule_nonneg : ∀ x y, 0 ≤ h x y) (hrule_sum : ∀ x, ∑ y, h x y = 1)\n (μ : Fin m → ℝ) :\n ∫ z, ((∑ i, Φ z.1 z.2 i * μ i) - h z.1 z.2) ∂p\n = (∑ i, featExpectM Φ p i * μ i) - ∫ z, h z.1 z.2 ∂p := by\n have hiΦ : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p := fun i =>\n aux_integrable_of_bdd p _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hih : Integrable (fun z : 𝒳 × 𝒴 => h z.1 z.2) p :=\n aux_integrable_of_bdd p _ hhmeas 1 (fun z => by\n rw [abs_of_nonneg (hrule_nonneg _ _)]\n exact aux_h_le_one h hrule_nonneg hrule_sum _ _)\n have hisum : Integrable (fun z : 𝒳 × 𝒴 => ∑ i, Φ z.1 z.2 i * μ i) p :=\n integrable_finset_sum _ (fun i _ => (hiΦ i).mul_const _)\n rw [integral_sub hisum hih]\n congr 1\n rw [integral_finset_sum _ (fun i _ => (hiΦ i).mul_const _)]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [integral_mul_const]\n rfl\n\nlemma aux_weak_upper (τ lam : Fin m → ℝ) (p : Measure (𝒳 × 𝒴))\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hrule_nonneg : ∀ x y, 0 ≤ h x y) (hrule_sum : ∀ x, ∑ y, h x y = 1)\n (hp : inUncertaintySetM Φ τ lam p) (μ : Fin m → ℝ) :\n expectedLossM h p ≤ 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|) := by\n obtain ⟨hprob, hcon⟩ := hp\n have hbddabove : BddAbove (Set.range (fun q : 𝒳 × 𝒴 =>\n (∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) := by\n refine ⟨B * ∑ i, |μ i|, ?_⟩\n rintro _ ⟨q, rfl⟩\n have h1 := aux_bdd_lin Φ B hΦbdd μ q\n have h2 := hrule_nonneg q.1 q.2\n have := (abs_le.mp h1).2\n linarith\n have hle : ∀ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)\n ≤ (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) := fun q => le_ciSup hbddabove q\n have hiΦ : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p := fun i =>\n aux_integrable_of_bdd p _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hih : Integrable (fun z : 𝒳 × 𝒴 => h z.1 z.2) p :=\n aux_integrable_of_bdd p _ hhmeas 1 (fun z => by\n rw [abs_of_nonneg (hrule_nonneg _ _)]\n exact aux_h_le_one h hrule_nonneg hrule_sum _ _)\n have hif : Integrable (fun z : 𝒳 × 𝒴 => (∑ i, Φ z.1 z.2 i * μ i) - h z.1 z.2) p :=\n (integrable_finset_sum _ (fun i _ => (hiΦ i).mul_const _)).sub hih\n have hint_le : ∫ z, ((∑ i, Φ z.1 z.2 i * μ i) - h z.1 z.2) ∂p\n ≤ (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) := by\n have := integral_mono hif (integrable_const _) hle\n simpa using this\n rw [aux_integral_f Φ h B p hΦmeas hΦbdd hhmeas hrule_nonneg hrule_sum μ] at hint_le\n have hEL : expectedLossM h p = 1 - ∫ z, h z.1 z.2 ∂p := by\n rw [expectedLossM, integral_sub (integrable_const _) hih]\n simp\n have hcon2 : |∑ i, (featExpectM Φ p i - τ i) * μ i| ≤ ∑ i, lam i * |μ i| := by\n calc |∑ i, (featExpectM Φ p i - τ i) * μ i|\n ≤ ∑ i, |(featExpectM Φ p i - τ i) * μ i| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ i, lam i * |μ i| := Finset.sum_le_sum (fun i _ => by\n rw [abs_mul]; exact mul_le_mul_of_nonneg_right (hcon i) (abs_nonneg _))\n have hsplit : (∑ i, (featExpectM Φ p i - τ i) * μ i)\n = (∑ i, featExpectM Φ p i * μ i) - (∑ i, τ i * μ i) := by\n rw [← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [hEL]\n rw [hsplit] at hcon2\n have hc := abs_le.mp hcon2\n linarith [hc.1, hc.2]\n\nlemma aux_weak_lower (τ lam : Fin m → ℝ) (p : Measure (𝒳 × 𝒴))\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hrule_nonneg : ∀ x y, 0 ≤ h x y) (hrule_sum : ∀ x, ∑ y, h x y = 1)\n (hp : inUncertaintySetM Φ τ lam p) (μ : Fin m → ℝ) :\n 1 - (∑ i, τ i * μ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) - (∑ i, lam i * |μ i|)\n ≤ expectedLossM h p := by\n obtain ⟨hprob, hcon⟩ := hp\n have hbddbelow : BddBelow (Set.range (fun q : 𝒳 × 𝒴 =>\n (∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) := by\n refine ⟨-(B * ∑ i, |μ i|) - 1, ?_⟩\n rintro _ ⟨q, rfl⟩\n have h1 := aux_bdd_lin Φ B hΦbdd μ q\n have h2 := aux_h_le_one h hrule_nonneg hrule_sum q.1 q.2\n have := (abs_le.mp h1).1\n linarith\n have hle : ∀ q : 𝒳 × 𝒴, (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n ≤ ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2) := fun q => ciInf_le hbddbelow q\n have hiΦ : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p := fun i =>\n aux_integrable_of_bdd p _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hih : Integrable (fun z : 𝒳 × 𝒴 => h z.1 z.2) p :=\n aux_integrable_of_bdd p _ hhmeas 1 (fun z => by\n rw [abs_of_nonneg (hrule_nonneg _ _)]\n exact aux_h_le_one h hrule_nonneg hrule_sum _ _)\n have hif : Integrable (fun z : 𝒳 × 𝒴 => (∑ i, Φ z.1 z.2 i * μ i) - h z.1 z.2) p :=\n (integrable_finset_sum _ (fun i _ => (hiΦ i).mul_const _)).sub hih\n have hint_le : (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n ≤ ∫ z, ((∑ i, Φ z.1 z.2 i * μ i) - h z.1 z.2) ∂p := by\n have := integral_mono (integrable_const _) hif hle\n simpa using this\n rw [aux_integral_f Φ h B p hΦmeas hΦbdd hhmeas hrule_nonneg hrule_sum μ] at hint_le\n have hEL : expectedLossM h p = 1 - ∫ z, h z.1 z.2 ∂p := by\n rw [expectedLossM, integral_sub (integrable_const _) hih]\n simp\n have hcon2 : |∑ i, (featExpectM Φ p i - τ i) * μ i| ≤ ∑ i, lam i * |μ i| := by\n calc |∑ i, (featExpectM Φ p i - τ i) * μ i|\n ≤ ∑ i, |(featExpectM Φ p i - τ i) * μ i| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ i, lam i * |μ i| := Finset.sum_le_sum (fun i _ => by\n rw [abs_mul]; exact mul_le_mul_of_nonneg_right (hcon i) (abs_nonneg _))\n have hsplit : (∑ i, (featExpectM Φ p i - τ i) * μ i)\n = (∑ i, featExpectM Φ p i * μ i) - (∑ i, τ i * μ i) := by\n rw [← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [hEL]\n rw [hsplit] at hcon2\n have hc := abs_le.mp hcon2\n linarith [hc.1, hc.2]\n\nend Weak\n\nlemma aux_coercive_min {m : ℕ} (Ψ : (Fin m → ℝ) → ℝ) (hcont : Continuous Ψ)\n (α β : ℝ) (hα : 0 < α) (hlb : ∀ μ, α * (∑ i, |μ i|) + β ≤ Ψ μ) :\n ∃ μ₀, ∀ μ, Ψ μ₀ ≤ Ψ μ := by\n set r : ℝ := (Ψ 0 - β) / α with hrdef\n have hβ : β ≤ Ψ 0 := by\n have := hlb 0\n simpa using this\n have hr : 0 ≤ r := div_nonneg (by linarith) hα.le\n have hcomp : IsCompact (Metric.closedBall (0 : Fin m → ℝ) r) := isCompact_closedBall _ _\n have hne : (Metric.closedBall (0 : Fin m → ℝ) r).Nonempty := ⟨0, by simp [hr]⟩\n obtain ⟨μ₀, hμ₀mem, hμ₀⟩ := hcomp.exists_isMinOn hne hcont.continuousOn\n refine ⟨μ₀, fun μ => ?_⟩\n by_cases hμ : μ ∈ Metric.closedBall (0 : Fin m → ℝ) r\n · exact isMinOn_iff.mp hμ₀ μ hμ\n · have h1 : r < ‖μ‖ := by\n simpa [Metric.mem_closedBall, dist_zero_right] using hμ\n have h2 : ‖μ‖ ≤ ∑ i, |μ i| := by\n refine (pi_norm_le_iff_of_nonneg ?_).2 (fun i => ?_)\n · exact Finset.sum_nonneg (fun i _ => abs_nonneg _)\n · exact Finset.single_le_sum (f := fun i => |μ i|) (fun j _ => abs_nonneg _)\n (Finset.mem_univ i)\n have h3 : Ψ μ₀ ≤ Ψ 0 := isMinOn_iff.mp hμ₀ 0 (by simp [hr])\n have h4 := hlb μ\n have h5 : α * r + β ≤ α * (∑ i, |μ i|) + β := by nlinarith\n have h6 : α * r = Ψ 0 - β := by\n rw [hrdef]\n field_simp\n linarith\n\n\nlemma aux_coercive_min_on {m : ℕ} (Ψ : (Fin m → ℝ) → ℝ) (hcont : Continuous Ψ)\n (T : Set (Fin m → ℝ)) (hTc : IsClosed T) (hT0 : (0 : Fin m → ℝ) ∈ T)\n (α β : ℝ) (hα : 0 < α) (hlb : ∀ μ ∈ T, α * (∑ i, |μ i|) + β ≤ Ψ μ) :\n ∃ μ₀ ∈ T, ∀ μ ∈ T, Ψ μ₀ ≤ Ψ μ := by\n set r : ℝ := (Ψ 0 - β) / α with hrdef\n have hβ : β ≤ Ψ 0 := by simpa using hlb 0 hT0\n have hr : 0 ≤ r := div_nonneg (by linarith) hα.le\n have hcomp : IsCompact (T ∩ Metric.closedBall (0 : Fin m → ℝ) r) :=\n (isCompact_closedBall _ _).inter_left hTc\n have hne : (T ∩ Metric.closedBall (0 : Fin m → ℝ) r).Nonempty := ⟨0, hT0, by simp [hr]⟩\n obtain ⟨μ₀, hμ₀mem, hμ₀⟩ := hcomp.exists_isMinOn hne hcont.continuousOn\n refine ⟨μ₀, hμ₀mem.1, fun μ hμT => ?_⟩\n by_cases hμ : μ ∈ Metric.closedBall (0 : Fin m → ℝ) r\n · exact isMinOn_iff.mp hμ₀ μ ⟨hμT, hμ⟩\n · have h1 : r < ‖μ‖ := by simpa [Metric.mem_closedBall, dist_zero_right] using hμ\n have h2 : ‖μ‖ ≤ ∑ i, |μ i| := by\n refine (pi_norm_le_iff_of_nonneg ?_).2 (fun i => ?_)\n · exact Finset.sum_nonneg (fun i _ => abs_nonneg _)\n · exact Finset.single_le_sum (f := fun i => |μ i|) (fun j _ => abs_nonneg _)\n (Finset.mem_univ i)\n have h3 : Ψ μ₀ ≤ Ψ 0 := isMinOn_iff.mp hμ₀ 0 ⟨hT0, by simp [hr]⟩\n have h4 := hlb μ hμT\n have h5 : α * r + β ≤ α * (∑ i, |μ i|) + β := by nlinarith\n have h6 : α * r = Ψ 0 - β := by rw [hrdef]; field_simp\n linarith\n\n\nlemma aux_sup'_smul {J : Type*} (T : Finset J) (hT : T.Nonempty) (σ : ℝ) (hσ : 0 ≤ σ)\n (f : J → ℝ) : T.sup' hT (fun j => σ * f j) = σ * T.sup' hT f :=\n (Finset.comp_sup'_eq_sup'_comp hT (fun x : ℝ => σ * x)\n (fun x y => mul_max_of_nonneg x y hσ)).symm\n\nlemma aux_sup'_add_const {J : Type*} (T : Finset J) (hT : T.Nonempty) (a : ℝ)\n (f : J → ℝ) : T.sup' hT (fun j => f j + a) = T.sup' hT f + a :=\n (Finset.comp_sup'_eq_sup'_comp hT (fun x : ℝ => x + a)\n (fun x y => (max_add_add_right x y a).symm)).symm\n\nlemma aux_VS_closed {m : ℕ} (S : Finset (Fin m)) :\n IsClosed {e : Fin m → ℝ | ∀ i, i ∉ S → e i = 0} := by\n have hEq : {e : Fin m → ℝ | ∀ i, i ∉ S → e i = 0}\n = ⋂ i ∈ {i : Fin m | i ∉ S}, {e : Fin m → ℝ | e i = 0} := by\n ext e\n simp only [Set.mem_setOf_eq, Set.mem_iInter]\n rw [hEq]\n exact isClosed_biInter (fun i _ => isClosed_eq (continuous_apply i) continuous_const)\n\nlemma aux_poly_min {m : ℕ} {J : Type*} [Fintype J] [DecidableEq J]\n (c : J → Fin m → ℝ) (d : J → ℝ) :\n ∀ (k : ℕ) (S : Finset (Fin m)), S.card = k →\n ∀ (T : Finset J) (hT : T.Nonempty) (lb : ℝ),\n (∀ μ : Fin m → ℝ, (∀ i, i ∉ S → μ i = 0) →\n lb ≤ T.sup' hT (fun j => (∑ i, c j i * μ i) + d j)) →\n ∃ μ₀ : Fin m → ℝ, (∀ i, i ∉ S → μ₀ i = 0) ∧\n ∀ μ : Fin m → ℝ, (∀ i, i ∉ S → μ i = 0) →\n T.sup' hT (fun j => (∑ i, c j i * μ₀ i) + d j)\n ≤ T.sup' hT (fun j => (∑ i, c j i * μ i) + d j) := by\n intro k\n induction k with\n | zero =>\n intro S hS T hT lb _\n have hSempty : S = ∅ := Finset.card_eq_zero.mp hS\n refine ⟨0, fun i _ => rfl, fun μ hμ => ?_⟩\n have hμ0 : μ = 0 := by\n funext i\n exact hμ i (by simp [hSempty])\n rw [hμ0]\n | succ k ih =>\n intro S hS T hT lb hlb\n classical\n have hlbD : lb ≤ T.sup' hT d := by\n have := hlb 0 (fun i _ => rfl)\n simpa using this\n by_cases hA : ∃ e : Fin m → ℝ, (∀ i, i ∉ S → e i = 0) ∧ e ≠ 0 ∧\n ∀ j ∈ T, (∑ i, c j i * e i) ≤ 0\n · obtain ⟨e, heS, hene, hele⟩ := hA\n set T' : Finset J := T.filter (fun j => (∑ i, c j i * e i) = 0) with hT'def\n have hT'sub : T' ⊆ T := Finset.filter_subset _ _\n obtain ⟨i₀, hi₀e⟩ : ∃ i, e i ≠ 0 := by\n by_contra hcon\n push_neg at hcon\n exact hene (funext hcon)\n have hi₀S : i₀ ∈ S := by\n by_contra hcon\n exact hi₀e (heS i₀ hcon)\n have hT'ne : T'.Nonempty := by\n by_contra hemp\n rw [Finset.not_nonempty_iff_eq_empty] at hemp\n have hneg : ∀ j ∈ T, (∑ i, c j i * e i) < 0 := by\n intro j hj\n rcases lt_or_eq_of_le (hele j hj) with hlt | heq\n · exact hlt\n · exfalso\n have hmem : j ∈ T' := by\n rw [hT'def]; exact Finset.mem_filter.2 ⟨hj, heq⟩\n rw [hemp] at hmem\n exact absurd hmem (Finset.notMem_empty j)\n have hκneg : T.sup' hT (fun j => (∑ i, c j i * e i)) < 0 :=\n (Finset.sup'_lt_iff hT).2 hneg\n set κ : ℝ := T.sup' hT (fun j => (∑ i, c j i * e i)) with hκ\n set D : ℝ := T.sup' hT d with hD\n set t : ℝ := (lb - D - 1) / κ with ht\n have htpos : 0 < t := by\n rw [ht]\n apply div_pos_of_neg_of_neg\n · linarith\n · exact hκneg\n have hmem : ∀ i, i ∉ S → (fun i => t * e i) i = 0 := by\n intro i hi; simp only; rw [heS i hi]; ring\n have hlow := hlb (fun i => t * e i) hmem\n have hbound : T.sup' hT (fun j => (∑ i, c j i * (t * e i)) + d j) ≤ t * κ + D := by\n refine Finset.sup'_le hT _ (fun j hj => ?_)\n have h1 : (∑ i, c j i * (t * e i)) = t * (∑ i, c j i * e i) := by\n rw [Finset.mul_sum]; exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [h1]\n have h2 : (∑ i, c j i * e i) ≤ κ := by\n rw [hκ]; exact Finset.le_sup' (fun j => ∑ i, c j i * e i) hj\n have h3 : d j ≤ D := by rw [hD]; exact Finset.le_sup' d hj\n nlinarith\n have hκne : κ ��� 0 := ne_of_lt hκneg\n have htκ : t * κ = lb - D - 1 := by\n rw [ht]; field_simp\n linarith\n have hGF : ∀ μ : Fin m → ℝ,\n T'.sup' hT'ne (fun j => (∑ i, c j i * μ i) + d j)\n ≤ T.sup' hT (fun j => (∑ i, c j i * μ i) + d j) :=\n fun μ => Finset.sup'_mono _ hT'sub hT'ne\n have hGinv : ∀ (μ : Fin m → ℝ) (s : ℝ),\n T'.sup' hT'ne (fun j => (∑ i, c j i * (μ i + s * e i)) + d j)\n = T'.sup' hT'ne (fun j => (∑ i, c j i * μ i) + d j) := by\n intro μ s\n refine Finset.sup'_congr hT'ne rfl (fun j hj => ?_)\n have hj0 : (∑ i, c j i * e i) = 0 := by\n rw [hT'def] at hj\n exact (Finset.mem_filter.mp hj).2\n have hexp : (∑ i, c j i * (μ i + s * e i))\n = (∑ i, c j i * μ i) + s * (∑ i, c j i * e i) := by\n rw [Finset.mul_sum, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [hexp, hj0]\n ring\n have hFt : ∀ μ : Fin m → ℝ, ∃ t : ℝ,\n T.sup' hT (fun j => (∑ i, c j i * (μ i + t * e i)) + d j)\n ≤ T'.sup' hT'ne (fun j => (∑ i, c j i * μ i) + d j) := by\n intro μ\n set G : ℝ := T'.sup' hT'ne (fun j => (∑ i, c j i * μ i) + d j) with hG\n refine ⟨∑ j ∈ T.filter (fun j => (∑ i, c j i * e i) ≠ 0),\n |(G - ((∑ i, c j i * μ i) + d j)) / (∑ i, c j i * e i)|, ?_⟩\n set t : ℝ := ∑ j ∈ T.filter (fun j => (∑ i, c j i * e i) ≠ 0),\n |(G - ((∑ i, c j i * μ i) + d j)) / (∑ i, c j i * e i)| with htdef\n refine Finset.sup'_le hT _ (fun j hj => ?_)\n have hlin : (∑ i, c j i * (μ i + t * e i)) + d j\n = ((∑ i, c j i * μ i) + d j) + t * (∑ i, c j i * e i) := by\n rw [show (∑ i, c j i * (μ i + t * e i))\n = (∑ i, c j i * μ i) + t * (∑ i, c j i * e i) from by\n rw [Finset.mul_sum, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)]\n ring\n rw [hlin]\n by_cases hj0 : (∑ i, c j i * e i) = 0\n · rw [hj0, mul_zero, add_zero]\n have hmem : j ∈ T' := by\n rw [hT'def]; exact Finset.mem_filter.2 ⟨hj, hj0⟩\n exact Finset.le_sup' (fun j => (∑ i, c j i * μ i) + d j) hmem\n · have hlt : (∑ i, c j i * e i) < 0 := lt_of_le_of_ne (hele j hj) hj0\n have hjmem : j ∈ T.filter (fun j => (∑ i, c j i * e i) ≠ 0) :=\n Finset.mem_filter.2 ⟨hj, hj0⟩\n have hterm : |(G - ((∑ i, c j i * μ i) + d j)) / (∑ i, c j i * e i)| ≤ t := by\n rw [htdef]\n exact Finset.single_le_sum\n (f := fun j => |(G - ((∑ i, c j i * μ i) + d j)) / (∑ i, c j i * e i)|)\n (fun _ _ => abs_nonneg _) hjmem\n have h1 : (G - ((∑ i, c j i * μ i) + d j)) / (∑ i, c j i * e i) ≤ t :=\n le_trans (le_abs_self _) hterm\n have h2 := (div_le_iff_of_neg hlt).mp h1\n linarith\n set S' : Finset (Fin m) := S.erase i₀ with hS'\n have hS'card : S'.card = k := by\n rw [hS', Finset.card_erase_of_mem hi₀S, hS]\n omega\n have hlb' : ∀ μ : Fin m → ℝ, (∀ i, i ∉ S' → μ i = 0) →\n lb ≤ T'.sup' hT'ne (fun j => (∑ i, c j i * μ i) + d j) := by\n intro μ hμ\n obtain ⟨t, ht⟩ := hFt μ\n have hmem : ∀ i, i ∉ S → (fun i => μ i + t * e i) i = 0 := by\n intro i hi\n have h1 : μ i = 0 := hμ i (fun hh => hi (Finset.mem_of_mem_erase hh))\n simp only\n rw [h1, heS i hi]; ring\n exact le_trans (hlb _ hmem) ht\n obtain ⟨ν, hνS', hνmin⟩ := ih S' hS'card T' hT'ne lb hlb'\n have hνminS : ∀ μ : Fin m → ℝ, (∀ i, i ∉ S → μ i = 0) →\n T'.sup' hT'ne (fun j => (∑ i, c j i * ν i) + d j)\n ≤ T'.sup' hT'ne (fun j => (∑ i, c j i * μ i) + d j) := by\n intro μ hμ\n set sc : ℝ := -(μ i₀ / e i₀) with hsc\n have hmem : ∀ i, i ∉ S' → (fun i => μ i + sc * e i) i = 0 := by\n intro i hi\n simp only\n rcases eq_or_ne i i₀ with rfl | hne\n · rw [hsc]; field_simp; ring\n · have hiS : i ∉ S := by\n intro hh; exact hi (Finset.mem_erase.2 ⟨hne, hh⟩)\n rw [hμ i hiS, heS i hiS]; ring\n have hres := hνmin _ hmem\n rwa [hGinv μ sc] at hres\n obtain ⟨t, ht⟩ := hFt ν\n refine ⟨fun i => ν i + t * e i, ?_, ?_⟩\n · intro i hi\n have hν0 : ν i = 0 := hνS' i (fun hh => hi (Finset.mem_of_mem_erase hh))\n simp only\n rw [hν0, heS i hi]; ring\n · intro μ hμ\n calc T.sup' hT (fun j => (∑ i, c j i * (ν i + t * e i)) + d j)\n ≤ T'.sup' hT'ne (fun j => (∑ i, c j i * ν i) + d j) := ht\n _ ≤ T'.sup' hT'ne (fun j => (∑ i, c j i * μ i) + d j) := hνminS μ hμ\n _ ≤ T.sup' hT (fun j => (∑ i, c j i * μ i) + d j) := hGF μ\n · push_neg at hA\n obtain ⟨i₁, hi₁⟩ : S.Nonempty := Finset.card_pos.mp (by rw [hS]; omega)\n set A : Set (Fin m → ℝ) := {e | (∀ i, i ∉ S → e i = 0) ∧ (∑ i, |e i|) = 1} with hAdef\n have hAeq : A = {e : Fin m → ℝ | ∀ i, i ∉ S → e i = 0}\n ∩ {e : Fin m → ℝ | (∑ i, |e i|) = 1} := rfl\n have hAcl : IsClosed A := by\n rw [hAeq]\n exact (aux_VS_closed S).inter (isClosed_eq (by fun_prop) continuous_const)\n have hAsub : A ⊆ Metric.closedBall (0 : Fin m → ℝ) 1 := by\n intro e he\n simp only [Metric.mem_closedBall, dist_zero_right]\n refine (pi_norm_le_iff_of_nonneg zero_le_one).2 (fun i => ?_)\n have h1 : |e i| ≤ ∑ j, |e j| :=\n Finset.single_le_sum (f := fun j => |e j|) (fun j _ => abs_nonneg _)\n (Finset.mem_univ i)\n rw [he.2] at h1\n simpa using h1\n have hAcomp : IsCompact A :=\n Metric.isCompact_of_isClosed_isBounded hAcl\n (Metric.isBounded_closedBall.subset hAsub)\n have hAne : A.Nonempty := by\n refine ⟨fun i => if i = i₁ then 1 else 0, ?_, ?_⟩\n · intro i hi\n have : i ≠ i₁ := by rintro rfl; exact hi hi₁\n simp [this]\n · have habs : ∀ x : Fin m, |if x = i₁ then (1:ℝ) else 0|\n = if x = i₁ then (1:ℝ) else 0 := by\n intro x; split <;> simp\n simp_rw [habs]\n simp\n have hgcont : Continuous\n (fun μ : Fin m → ℝ => T.sup' hT (fun j => ∑ i, c j i * μ i)) :=\n Continuous.finset_sup'_apply hT (fun j _ => by fun_prop)\n obtain ⟨e₀, he₀A, he₀min⟩ := hAcomp.exists_isMinOn hAne hgcont.continuousOn\n set α : ℝ := T.sup' hT (fun j => ∑ i, c j i * e₀ i) with hαdef\n have he₀ne : e₀ ≠ 0 := by\n intro hcon\n have := he₀A.2\n rw [hcon] at this\n simp at this\n have hαpos : 0 < α := by\n obtain ⟨j, hjT, hj⟩ := hA e₀ he₀A.1 he₀ne\n exact lt_of_lt_of_le (by linarith) (Finset.le_sup' (fun j => ∑ i, c j i * e₀ i) hjT)\n have hhom : ∀ (σ : ℝ), 0 ≤ σ → ∀ (μ : Fin m → ℝ),\n T.sup' hT (fun j => ∑ i, c j i * (σ * μ i))\n = σ * T.sup' hT (fun j => ∑ i, c j i * μ i) := by\n intro σ hσ μ\n have h1 : ∀ j, (∑ i, c j i * (σ * μ i)) = σ * (∑ i, c j i * μ i) := by\n intro j; rw [Finset.mul_sum]; exact Finset.sum_congr rfl (fun i _ => by ring)\n simp_rw [h1]\n exact aux_sup'_smul T hT σ hσ _\n have hglb : ∀ μ : Fin m → ℝ, (∀ i, i ∉ S → μ i = 0) →\n α * (∑ i, |μ i|) ≤ T.sup' hT (fun j => ∑ i, c j i * μ i) := by\n intro μ hμ\n rcases eq_or_lt_of_le (Finset.sum_nonneg\n (fun i (_ : i ∈ (Finset.univ : Finset (Fin m))) => abs_nonneg (μ i))) with hz | hpos\n · have hμ0 : μ = 0 := by\n funext i\n have := (Finset.sum_eq_zero_iff_of_nonneg\n (fun i (_ : i ∈ (Finset.univ : Finset (Fin m))) => abs_nonneg (μ i))).mp hz.symm\n i (Finset.mem_univ i)\n exact abs_eq_zero.mp this\n rw [hμ0]\n simp\n · set σ : ℝ := ∑ i, |μ i| with hσdef\n have hσ : 0 < σ := hpos\n have heeA : (fun i => σ⁻¹ * μ i) ∈ A := by\n refine ⟨fun i hi => by simp [hμ i hi], ?_⟩\n have habs : ∀ i, |σ⁻¹ * μ i| = σ⁻¹ * |μ i| := by\n intro i; rw [abs_mul, abs_of_pos (inv_pos.2 hσ)]\n simp_rw [habs]\n rw [← Finset.mul_sum, ← hσdef]\n field_simp\n have h1 : α ≤ T.sup' hT (fun j => ∑ i, c j i * (σ⁻¹ * μ i)) :=\n isMinOn_iff.mp he₀min _ heeA\n have hmid : σ * T.sup' hT (fun j => ∑ i, c j i * (σ⁻¹ * μ i))\n = T.sup' hT (fun j => ∑ i, c j i * μ i) := by\n rw [← hhom σ hσ.le]\n exact Finset.sup'_congr hT rfl (fun j _ =>\n Finset.sum_congr rfl (fun i _ => by\n rw [show σ * (σ⁻¹ * μ i) = μ i from by field_simp]))\n calc α * σ = σ * α := by ring\n _ ≤ σ * T.sup' hT (fun j => ∑ i, c j i * (σ⁻¹ * μ i)) := by nlinarith\n _ = T.sup' hT (fun j => ∑ i, c j i * μ i) := hmid\n set dmin : ℝ := T.inf' hT d with hdmin\n have hFlb : ∀ μ ∈ {e : Fin m → ℝ | ∀ i, i ∉ S → e i = 0},\n α * (∑ i, |μ i|) + dmin ≤ T.sup' hT (fun j => (∑ i, c j i * μ i) + d j) := by\n intro μ hμ\n have h1 := hglb μ hμ\n have h2 : T.sup' hT (fun j => ∑ i, c j i * μ i) + dmin\n ≤ T.sup' hT (fun j => (∑ i, c j i * μ i) + d j) := by\n rw [← aux_sup'_add_const T hT dmin (fun j => ∑ i, c j i * μ i)]\n refine Finset.sup'_le hT _ (fun j hj => ?_)\n have hd : dmin ≤ d j := Finset.inf'_le _ hj\n exact le_trans (by linarith : (∑ i, c j i * μ i) + dmin ≤ (∑ i, c j i * μ i) + d j)\n (Finset.le_sup' (fun j => (∑ i, c j i * μ i) + d j) hj)\n linarith\n obtain ⟨μ₀, hμ₀mem, hμ₀⟩ := aux_coercive_min_on\n (fun μ : Fin m → ℝ => T.sup' hT (fun j => (∑ i, c j i * μ i) + d j))\n (Continuous.finset_sup'_apply hT (fun j _ => by fun_prop))\n {e : Fin m → ℝ | ∀ i, i ∉ S → e i = 0} (aux_VS_closed S) (fun i _ => rfl)\n α dmin hαpos hFlb\n exact ⟨μ₀, hμ₀mem, hμ₀⟩\n\nsection CiSup\n\nvariable {Q : Type*} [Nonempty Q] {m : ℕ}\n\nlemma aux_ciSup_bddAbove (a : Q → Fin m → ℝ) (b : Q → ℝ) (B Kb : ℝ)\n (hB : ∀ q i, |a q i| ≤ B) (hKb : ∀ q, |b q| ≤ Kb) (μ : Fin m → ℝ) :\n BddAbove (Set.range (fun q : Q => (∑ i, a q i * μ i) + b q)) := by\n refine ⟨B * (∑ i, |μ i|) + Kb, ?_⟩\n rintro _ ⟨q, rfl⟩\n have h1 : |∑ i, a q i * μ i| ≤ B * ∑ i, |μ i| := by\n calc |∑ i, a q i * μ i| ≤ ∑ i, |a q i * μ i| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ i, B * |μ i| := Finset.sum_le_sum (fun i _ => by\n rw [abs_mul]; exact mul_le_mul_of_nonneg_right (hB q i) (abs_nonneg _))\n _ = B * ∑ i, |μ i| := by rw [Finset.mul_sum]\n have h2 := (abs_le.mp h1).2\n have h3 := (abs_le.mp (hKb q)).2\n linarith\n\nlemma aux_ciSup_shift (a : Q → Fin m → ℝ) (b : Q → ℝ) (B Kb : ℝ) (hB0 : 0 ≤ B)\n (hB : ∀ q i, |a q i| ≤ B) (hKb : ∀ q, |b q| ≤ Kb) (μ ν : Fin m → ℝ) :\n (⨆ q : Q, ((∑ i, a q i * μ i) + b q))\n ≤ (⨆ q : Q, ((∑ i, a q i * ν i) + b q)) + B * ∑ i, |μ i - ν i| := by\n refine ciSup_le (fun q => ?_)\n have hsplit : (∑ i, a q i * μ i) + b q\n = ((∑ i, a q i * ν i) + b q) + (∑ i, a q i * (μ i - ν i)) := by\n have hh : (∑ i, a q i * ν i) + (∑ i, a q i * (μ i - ν i)) = ∑ i, a q i * μ i := by\n rw [← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n linarith\n have h1 : (∑ i, a q i * (μ i - ν i)) ≤ B * ∑ i, |μ i - ν i| := by\n calc (∑ i, a q i * (μ i - ν i)) ≤ ∑ i, |a q i * (μ i - ν i)| :=\n Finset.sum_le_sum (fun i _ => le_abs_self _)\n _ ≤ ∑ i, B * |μ i - ν i| := Finset.sum_le_sum (fun i _ => by\n rw [abs_mul]; exact mul_le_mul_of_nonneg_right (hB q i) (abs_nonneg _))\n _ = B * ∑ i, |μ i - ν i| := by rw [Finset.mul_sum]\n have h2 : ((∑ i, a q i * ν i) + b q) ≤ ⨆ q : Q, ((∑ i, a q i * ν i) + b q) :=\n le_ciSup (aux_ciSup_bddAbove a b B Kb hB hKb ν) q\n rw [hsplit]\n linarith\n\nlemma aux_ciSup_cont (a : Q → Fin m → ℝ) (b : Q → ℝ) (B Kb : ℝ) (hB0 : 0 ≤ B)\n (hB : ∀ q i, |a q i| ≤ B) (hKb : ∀ q, |b q| ≤ Kb) :\n Continuous (fun μ : Fin m → ℝ => ⨆ q : Q, ((∑ i, a q i * μ i) + b q)) := by\n rw [Metric.continuous_iff]\n intro ν ε hε\n refine ⟨ε / (B * m + 1), by positivity, fun μ hd => ?_⟩\n have hsum : (∑ i, |μ i - ν i|) ≤ (m : ℝ) * dist μ ν := by\n have hb : ∀ i : Fin m, |μ i - ν i| ≤ dist μ ν := by\n intro i\n have := dist_le_pi_dist μ ν i\n simpa [Real.dist_eq] using this\n calc (∑ i, |μ i - ν i|) ≤ ∑ _i : Fin m, dist μ ν := Finset.sum_le_sum (fun i _ => hb i)\n _ = (m : ℝ) * dist μ ν := by simp [mul_comm]\n have h1 := aux_ciSup_shift a b B Kb hB0 hB hKb μ ν\n have h2 := aux_ciSup_shift a b B Kb hB0 hB hKb ν μ\n have habs : (∑ i, |ν i - μ i|) = ∑ i, |μ i - ν i| :=\n Finset.sum_congr rfl (fun i _ => abs_sub_comm _ _)\n rw [habs] at h2\n have hkey : B * (∑ i, |μ i - ν i|) ≤ B * ((m:ℝ) * dist μ ν) :=\n mul_le_mul_of_nonneg_left hsum hB0\n have hdd : dist μ ν < ε / (B * m + 1) := hd\n have hpos : (0:ℝ) < B * m + 1 := by positivity\n have hfin : B * ((m:ℝ) * dist μ ν) < ε := by\n have : B * (m:ℝ) * dist μ ν < B * (m:ℝ) * (ε / (B * m + 1)) ∨ B * (m:ℝ) = 0 := by\n rcases eq_or_lt_of_le (by positivity : (0:ℝ) ≤ B * (m:ℝ)) with h | h\n · right; exact h.symm\n · left; exact mul_lt_mul_of_pos_left hdd h\n rcases this with h | h\n · have h2' : B * (m:ℝ) * (ε / (B * m + 1)) ≤ ε := by\n rw [mul_div_assoc']\n rw [div_le_iff₀ hpos]\n nlinarith [hε.le]\n calc B * ((m:ℝ) * dist μ ν) = B * (m:ℝ) * dist μ ν := by ring\n _ < B * (m:ℝ) * (ε / (B * m + 1)) := h\n _ ≤ ε := h2'\n · calc B * ((m:ℝ) * dist μ ν) = B * (m:ℝ) * dist μ ν := by ring\n _ = 0 * dist μ ν := by rw [h]\n _ = 0 := by ring\n _ < ε := hε\n rw [Real.dist_eq, abs_lt]\n constructor <;> linarith\n\nlemma aux_ciSup_smul (a : Q → Fin m → ℝ) (B : ℝ)\n (hB : ∀ q i, |a q i| ≤ B) (σ : ℝ) (hσ : 0 ≤ σ) (μ : Fin m → ℝ) :\n (⨆ q : Q, (∑ i, a q i * (σ * μ i))) = σ * ⨆ q : Q, (∑ i, a q i * μ i) := by\n have hbdd : ∀ ν : Fin m → ℝ, BddAbove (Set.range (fun q : Q => ∑ i, a q i * ν i)) := by\n intro ν\n have := aux_ciSup_bddAbove a (fun _ => (0:ℝ)) B 0 hB (fun q => by simp) ν\n simpa using this\n have hrw : ∀ (ν : Fin m → ℝ) (q : Q), (∑ i, a q i * (σ * ν i)) = σ * (∑ i, a q i * ν i) := by\n intro ν q\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n simp_rw [hrw]\n exact (Real.mul_iSup_of_nonneg hσ _).symm\n\nend CiSup\n\nlemma aux_homog_min {m : ℕ} (hm : 0 < m) (D : (Fin m → ℝ) → ℝ) (hcont : Continuous D)\n (hhom : ∀ (σ : ℝ), 0 ≤ σ → ∀ μ, D (fun i => σ * μ i) = σ * D μ)\n (hpos : ∀ μ : Fin m → ℝ, μ ≠ 0 → 0 < D μ) :\n ∃ α : ℝ, 0 < α ∧ ∀ μ, α * (∑ i, |μ i|) ≤ D μ := by\n classical\n set A : Set (Fin m → ℝ) := {e | (∑ i, |e i|) = 1} with hAdef\n have hAcl : IsClosed A := isClosed_eq (by fun_prop) continuous_const\n have hAsub : A ⊆ Metric.closedBall (0 : Fin m → ℝ) 1 := by\n intro e he\n simp only [Metric.mem_closedBall, dist_zero_right]\n refine (pi_norm_le_iff_of_nonneg zero_le_one).2 (fun i => ?_)\n have h1 : |e i| ≤ ∑ j, |e j| :=\n Finset.single_le_sum (f := fun j => |e j|) (fun j _ => abs_nonneg _) (Finset.mem_univ i)\n rw [he] at h1\n simpa using h1\n have hAcomp : IsCompact A :=\n Metric.isCompact_of_isClosed_isBounded hAcl (Metric.isBounded_closedBall.subset hAsub)\n have hAne : A.Nonempty := by\n refine ⟨fun i => if i = ⟨0, hm⟩ then 1 else 0, ?_⟩\n have habs : ∀ x : Fin m, |if x = (⟨0, hm⟩ : Fin m) then (1:ℝ) else 0|\n = if x = (⟨0, hm⟩ : Fin m) then (1:ℝ) else 0 := by\n intro x; split <;> simp\n show (∑ i, |if i = (⟨0, hm⟩ : Fin m) then (1:ℝ) else 0|) = 1\n simp_rw [habs]\n simp\n obtain ⟨e₀, he₀A, he₀min⟩ := hAcomp.exists_isMinOn hAne hcont.continuousOn\n have he₀ne : e₀ ≠ 0 := by\n intro hcon\n have := he₀A\n rw [hAdef] at this\n simp only [Set.mem_setOf_eq] at this\n rw [hcon] at this\n simp at this\n refine ⟨D e₀, hpos e₀ he₀ne, fun μ => ?_⟩\n rcases eq_or_lt_of_le (Finset.sum_nonneg\n (fun i (_ : i ∈ (Finset.univ : Finset (Fin m))) => abs_nonneg (μ i))) with hz | hpz\n · have hμ0 : μ = 0 := by\n funext i\n have := (Finset.sum_eq_zero_iff_of_nonneg\n (fun i (_ : i ∈ (Finset.univ : Finset (Fin m))) => abs_nonneg (μ i))).mp hz.symm\n i (Finset.mem_univ i)\n exact abs_eq_zero.mp this\n have hD0 : D 0 = 0 := by\n have := hhom 0 le_rfl 0\n simpa using this\n rw [← hz, hμ0, hD0]\n simp\n · set σ : ℝ := ∑ i, |μ i| with hσdef\n have hσ : 0 < σ := hpz\n have heeA : (fun i => σ⁻¹ * μ i) ∈ A := by\n show (∑ i, |σ⁻¹ * μ i|) = 1\n have habs : ∀ i, |σ⁻¹ * μ i| = σ⁻¹ * |μ i| := by\n intro i; rw [abs_mul, abs_of_pos (inv_pos.2 hσ)]\n simp_rw [habs]\n rw [← Finset.mul_sum, ← hσdef]\n field_simp\n have h1 : D e₀ ≤ D (fun i => σ⁻¹ * μ i) := isMinOn_iff.mp he₀min _ heeA\n have h2 : D (fun i => σ * (σ⁻¹ * μ i)) = σ * D (fun i => σ⁻¹ * μ i) :=\n hhom σ hσ.le _\n have h3 : (fun i => σ * (σ⁻¹ * μ i)) = μ := by\n funext i; field_simp\n rw [h3] at h2\n rw [h2]\n nlinarith\n\n\nsection Attain\n\nvariable {𝒳 : Type*} [MeasurableSpace 𝒳] {𝒴 : Type*} [Fintype 𝒴] [MeasurableSpace 𝒴]\n {m : ℕ}\n\nlemma aux_integral_lin (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (B : ℝ) (p : Measure (𝒳 × 𝒴))\n [IsFiniteMeasure p]\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B) (μ : Fin m → ℝ) :\n ∫ z, (∑ i, Φ z.1 z.2 i * μ i) ∂p = ∑ i, featExpectM Φ p i * μ i := by\n have hiΦ : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p := fun i =>\n aux_integrable_of_bdd p _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n rw [integral_finset_sum _ (fun i _ => (hiΦ i).mul_const _)]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [integral_mul_const]\n rfl\n\nlemma aux_lin_le_sup (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (B : ℝ) [Nonempty (𝒳 × 𝒴)]\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B) (μ : Fin m → ℝ) (q : 𝒳 × 𝒴) :\n (∑ i, Φ q.1 q.2 i * μ i) ≤ ⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i) := by\n have hbd := aux_ciSup_bddAbove (Q := 𝒳 × 𝒴) (fun q i => Φ q.1 q.2 i) (fun _ => (0:ℝ))\n B 0 (fun q i => hΦbdd _ _ i) (fun q => by simp) μ\n simp only [add_zero] at hbd\n exact le_ciSup hbd q\n\nlemma aux_int_le_sup (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (B : ℝ) (p : Measure (𝒳 × 𝒴))\n [IsProbabilityMeasure p] [Nonempty (𝒳 × 𝒴)]\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B) (μ : Fin m → ℝ) :\n (∑ i, featExpectM Φ p i * μ i) ≤ ⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i) := by\n rw [← aux_integral_lin Φ B p hΦmeas hΦbdd μ]\n have hiΦ : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p := fun i =>\n aux_integrable_of_bdd p _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hint : Integrable (fun z : 𝒳 × 𝒴 => ∑ i, Φ z.1 z.2 i * μ i) p :=\n integrable_finset_sum _ (fun i _ => (hiΦ i).mul_const _)\n have := integral_mono hint (integrable_const _)\n (fun q => aux_lin_le_sup Φ B hΦbdd μ q)\n simpa using this\n\nlemma aux_ciSup_bddAbove' {Q : Type*} [Nonempty Q] (a : Q → Fin m → ℝ) (b : Q → ℝ) (B Kb : ℝ)\n (hB : ∀ q i, |a q i| ≤ B) (hKb : ∀ q, |b q| ≤ Kb) (μ : Fin m → ℝ) :\n BddAbove (Set.range (fun q : Q => (∑ i, a q i * μ i) - b q)) := by\n have h := aux_ciSup_bddAbove a (fun q => -(b q)) B Kb hB\n (fun q => by rw [abs_neg]; exact hKb q) μ\n simpa [sub_eq_add_neg] using h\n\nlemma aux_ciSup_cont' {Q : Type*} [Nonempty Q] (a : Q → Fin m → ℝ) (b : Q → ℝ) (B Kb : ℝ)\n (hB0 : 0 ≤ B) (hB : ∀ q i, |a q i| ≤ B) (hKb : ∀ q, |b q| ≤ Kb) :\n Continuous (fun μ : Fin m → ℝ => ⨆ q : Q, ((∑ i, a q i * μ i) - b q)) := by\n have h := aux_ciSup_cont a (fun q => -(b q)) B Kb hB0 hB\n (fun q => by rw [abs_neg]; exact hKb q)\n simpa [sub_eq_add_neg] using h\n\nlemma aux_lin_cont (τ : Fin m → ℝ) : Continuous (fun μ : Fin m → ℝ => ∑ i, τ i * μ i) :=\n continuous_finset_sum _ (fun i _ => continuous_const.mul (continuous_apply i))\n\nlemma aux_abs_cont (lam : Fin m → ℝ) : Continuous (fun μ : Fin m → ℝ => ∑ i, lam i * |μ i|) :=\n continuous_finset_sum _ (fun i _ => continuous_const.mul ((continuous_apply i).abs))\n\nlemma aux_D_pos (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (B : ℝ)\n [Nonempty (𝒳 × 𝒴)]\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hreg2 : R2 Φ τ lam) (μ : Fin m → ℝ) (hμ : μ ≠ 0) :\n 0 < -(∑ i, τ i * μ i) + (⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i)) + (∑ i, lam i * |μ i|) := by\n obtain ⟨p, ⟨hprob, hcon⟩, hstrict, hdisj⟩ := hreg2\n haveI := hprob\n set SΦ : ℝ := ⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i) with hSΦ\n have h1 : (∑ i, featExpectM Φ p i * μ i) ≤ SΦ :=\n aux_int_le_sup Φ B p hΦmeas hΦbdd μ\n have h2 : (∑ i, (featExpectM Φ p i - τ i) * μ i) + (∑ i, lam i * |μ i|)\n = ∑ i, ((featExpectM Φ p i - τ i) * μ i + lam i * |μ i|) := by\n rw [Finset.sum_add_distrib]\n have hterm : ∀ i, 0 ≤ (featExpectM Φ p i - τ i) * μ i + lam i * |μ i| := by\n intro i\n have hb : |(featExpectM Φ p i - τ i) * μ i| ≤ lam i * |μ i| := by\n rw [abs_mul]\n exact mul_le_mul_of_nonneg_right (hcon i) (abs_nonneg _)\n have := (abs_le.mp hb).1\n linarith\n have hsplit : -(∑ i, τ i * μ i) + SΦ + (∑ i, lam i * |μ i|)\n = (SΦ - (∑ i, featExpectM Φ p i * μ i))\n + ((∑ i, (featExpectM Φ p i - τ i) * μ i) + (∑ i, lam i * |μ i|)) := by\n have : (∑ i, (featExpectM Φ p i - τ i) * μ i)\n = (∑ i, featExpectM Φ p i * μ i) - (∑ i, τ i * μ i) := by\n rw [← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [this]; ring\n rw [hsplit]\n rcases hdisj with hall | hnoaff\n · -- all lam i > 0\n obtain ⟨i₀, hi₀⟩ : ∃ i, μ i ≠ 0 := by\n by_contra hcon2\n push_neg at hcon2\n exact hμ (funext hcon2)\n have hstr := hstrict i₀ (hall i₀)\n have hpos0 : 0 < (featExpectM Φ p i₀ - τ i₀) * μ i₀ + lam i₀ * |μ i₀| := by\n have hb : |(featExpectM Φ p i₀ - τ i₀) * μ i₀| < lam i₀ * |μ i₀| := by\n rw [abs_mul]\n exact mul_lt_mul_of_pos_right hstr (abs_pos.2 hi₀)\n have := (abs_lt.mp hb).1\n linarith\n have hsum : 0 < ∑ i, ((featExpectM Φ p i - τ i) * μ i + lam i * |μ i|) := by\n refine lt_of_lt_of_le hpos0 ?_\n exact Finset.single_le_sum\n (f := fun i => (featExpectM Φ p i - τ i) * μ i + lam i * |μ i|)\n (fun i _ => hterm i) (Finset.mem_univ i₀)\n rw [h2]\n linarith\n · -- no affine relation\n have hsumnn : 0 ≤ ∑ i, ((featExpectM Φ p i - τ i) * μ i + lam i * |μ i|) :=\n Finset.sum_nonneg (fun i _ => hterm i)\n rw [h2]\n have hstrictpos : 0 < SΦ - (∑ i, featExpectM Φ p i * μ i) := by\n rcases lt_or_eq_of_le h1 with hlt | heq\n · linarith\n · exfalso\n apply hnoaff\n refine ⟨μ, SΦ, hμ, ?_⟩\n have hiΦ : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p := fun i =>\n aux_integrable_of_bdd p _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hint : Integrable (fun z : 𝒳 × 𝒴 => ∑ i, Φ z.1 z.2 i * μ i) p :=\n integrable_finset_sum _ (fun i _ => (hiΦ i).mul_const _)\n have hfint : Integrable (fun z : 𝒳 × 𝒴 => SΦ - ∑ i, Φ z.1 z.2 i * μ i) p :=\n (integrable_const _).sub hint\n have hfnn : (0 : (𝒳 × 𝒴) → ℝ) ≤ fun z => SΦ - ∑ i, Φ z.1 z.2 i * μ i := by\n intro z\n simp only [Pi.zero_apply, sub_nonneg]\n exact aux_lin_le_sup Φ B hΦbdd μ z\n have hfzero : ∫ z, (SΦ - ∑ i, Φ z.1 z.2 i * μ i) ∂p = 0 := by\n rw [integral_sub (integrable_const _) hint]\n rw [aux_integral_lin Φ B p hΦmeas hΦbdd μ]\n simp [← heq]\n have hae := (integral_eq_zero_iff_of_nonneg hfnn hfint).mp hfzero\n filter_upwards [hae] with z hz\n simp only [Pi.zero_apply, sub_eq_zero] at hz\n rw [show (∑ i, μ i * Φ z.1 z.2 i) = ∑ i, Φ z.1 z.2 i * μ i from\n Finset.sum_congr rfl (fun i _ => mul_comm _ _)]\n exact hz.symm\n linarith\n\nlemma aux_attain [MeasurableSingletonClass 𝒴]\n (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (B : ℝ) (hB0 : 0 ≤ B)\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (cst : ℝ) (g : 𝒳 × 𝒴 → ℝ) (Kg : ℝ) (hKg0 : 0 ≤ Kg)\n (hgbdd : ∀ z, |g z| ≤ Kg)\n (hlam : ∀ i, 0 ≤ lam i)\n (hne : Nonempty (𝒳 × 𝒴))\n (hreg : R1 Φ τ lam ∨ R2 Φ τ lam)\n (lb : ℝ)\n (hlb : ∀ μ : Fin m → ℝ, lb ≤ cst - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q)) + (∑ i, lam i * |μ i|)) :\n ∃ μ₀ : Fin m → ℝ, ∀ μ : Fin m → ℝ,\n cst - (∑ i, τ i * μ₀ i) + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ₀ i) - g q))\n + (∑ i, lam i * |μ₀ i|)\n ≤ cst - (∑ i, τ i * μ i) + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q))\n + (∑ i, lam i * |μ i|) := by\n classical\n have hΨcont : Continuous (fun μ : Fin m → ℝ => cst - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q)) + (∑ i, lam i * |μ i|)) := by\n have h1 := aux_lin_cont (m := m) τ\n have h2 := aux_ciSup_cont' (Q := 𝒳 × 𝒴) (fun q i => Φ q.1 q.2 i) g B Kg hB0\n (fun q i => hΦbdd _ _ i) hgbdd\n have h3 := aux_abs_cont (m := m) lam\n exact ((continuous_const.sub h1).add h2).add h3\n rcases Nat.eq_zero_or_pos m with hm0 | hmpos\n · subst hm0\n exact ⟨0, fun μ => by rw [Subsingleton.elim μ (0 : Fin 0 → ℝ)]⟩\n rcases hreg with hreg1 | hreg2\n · -- R1 : polyhedral\n obtain ⟨hfin, p, hpU⟩ := hreg1\n haveI : Fintype 𝒳 := Fintype.ofFinite 𝒳\n haveI hneJ : Nonempty ((𝒳 × 𝒴) × (Fin m → Bool)) :=\n ⟨⟨Classical.choice hne, fun _ => true⟩⟩\n set cc : ((𝒳 × 𝒴) × (Fin m → Bool)) → Fin m → ℝ :=\n fun j i => Φ j.1.1 j.1.2 i - τ i + lam i * (if j.2 i then (1:ℝ) else -1) with hcc\n set dd : ((𝒳 × 𝒴) × (Fin m → Bool)) → ℝ := fun j => cst - g j.1 with hdd\n have hterm : ∀ (q : 𝒳 × 𝒴) (sg : Fin m → Bool) (μ : Fin m → ℝ),\n (∑ i, cc (q, sg) i * μ i) + dd (q, sg)\n = ((∑ i, Φ q.1 q.2 i * μ i) - g q) + (cst - (∑ i, τ i * μ i))\n + (∑ i, lam i * ((if sg i then (1:ℝ) else -1) * μ i)) := by\n intro q sg μ\n have hexp : (∑ i, cc (q, sg) i * μ i)\n = (∑ i, Φ q.1 q.2 i * μ i) - (∑ i, τ i * μ i)\n + (∑ i, lam i * ((if sg i then (1:ℝ) else -1) * μ i)) := by\n rw [← Finset.sum_sub_distrib, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun i _ => by simp only [hcc]; ring)\n rw [hexp]\n simp only [hdd]\n ring\n have hsign : ∀ (μ : Fin m → ℝ) (sg : Fin m → Bool),\n (∑ i, lam i * ((if sg i then (1:ℝ) else -1) * μ i)) ≤ ∑ i, lam i * |μ i| := by\n intro μ sg\n refine Finset.sum_le_sum (fun i _ => ?_)\n refine mul_le_mul_of_nonneg_left ?_ (hlam i)\n rcases Bool.eq_false_or_eq_true (sg i) with hb | hb <;> rw [hb]\n · simpa using le_abs_self (μ i)\n · simpa using neg_le_abs (μ i)\n have hsigneq : ∀ μ : Fin m → ℝ, ∃ sg : Fin m → Bool,\n (∑ i, lam i * ((if sg i then (1:ℝ) else -1) * μ i)) = ∑ i, lam i * |μ i| := by\n intro μ\n refine ⟨fun i => decide (0 ≤ μ i), Finset.sum_congr rfl (fun i _ => ?_)⟩\n by_cases hpos : 0 ≤ μ i\n · simp [hpos, abs_of_nonneg hpos]\n · push_neg at hpos\n simp [hpos.not_ge, abs_of_neg hpos]\n have hbddJ : ∀ μ : Fin m → ℝ, BddAbove (Set.range\n (fun j : (𝒳 × 𝒴) × (Fin m → Bool) => (∑ i, cc j i * μ i) + dd j)) :=\n fun μ => Set.Finite.bddAbove (Set.finite_range _)\n have hbddQ : ∀ μ : Fin m → ℝ, BddAbove (Set.range\n (fun q : 𝒳 × 𝒴 => (∑ i, Φ q.1 q.2 i * μ i) - g q)) :=\n fun μ => aux_ciSup_bddAbove' (Q := 𝒳 × ���) (fun q i => Φ q.1 q.2 i) g B Kg\n (fun q i => hΦbdd _ _ i) hgbdd μ\n have hkey : ∀ μ : Fin m → ℝ,\n cst - (∑ i, τ i * μ i) + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q))\n + (∑ i, lam i * |μ i|)\n = ⨆ j : (𝒳 × 𝒴) × (Fin m → Bool), ((∑ i, cc j i * μ i) + dd j) := by\n intro μ\n refine le_antisymm ?_ ?_\n · obtain ⟨sg, hsg⟩ := hsigneq μ\n have hq : ∀ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q)\n ≤ (⨆ j : (𝒳 × 𝒴) × (Fin m → Bool), ((∑ i, cc j i * μ i) + dd j))\n - (cst - (∑ i, τ i * μ i)) - (∑ i, lam i * |μ i|) := by\n intro q\n have h1 : (∑ i, cc (q, sg) i * μ i) + dd (q, sg)\n ≤ ⨆ j : (𝒳 × 𝒴) × (Fin m → Bool), ((∑ i, cc j i * μ i) + dd j) :=\n le_ciSup (hbddJ μ) (q, sg)\n rw [hterm q sg μ, hsg] at h1\n linarith\n have h2 := ciSup_le hq\n linarith\n · refine ciSup_le (fun j => ?_)\n obtain ⟨q, sg⟩ := j\n rw [hterm q sg μ]\n have h1 : ((∑ i, Φ q.1 q.2 i * μ i) - g q)\n ≤ ⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q) := le_ciSup (hbddQ μ) q\n have h2 := hsign μ sg\n linarith\n have hlb' : ∀ μ : Fin m → ℝ, (∀ i, i ∉ (Finset.univ : Finset (Fin m)) → μ i = 0) →\n lb ≤ (Finset.univ : Finset ((𝒳 × 𝒴) × (Fin m → Bool))).sup'\n Finset.univ_nonempty (fun j => (∑ i, cc j i * μ i) + dd j) := by\n intro μ _\n rw [Finset.sup'_univ_eq_ciSup, ← hkey μ]\n exact hlb μ\n obtain ⟨μ₀, _, hmin⟩ := aux_poly_min cc dd (Finset.univ : Finset (Fin m)).card\n Finset.univ rfl (Finset.univ : Finset ((𝒳 × 𝒴) × (Fin m → Bool)))\n Finset.univ_nonempty lb hlb'\n refine ⟨μ₀, fun μ => ?_⟩\n have h := hmin μ (fun i hi => absurd (Finset.mem_univ i) hi)\n rw [Finset.sup'_univ_eq_ciSup, Finset.sup'_univ_eq_ciSup, ← hkey μ₀, ← hkey μ] at h\n exact h\n · -- R2 : coercive\n set D : (Fin m → ℝ) → ℝ := fun μ => -(∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i)) + (∑ i, lam i * |μ i|) with hD\n have hDcont : Continuous D := by\n have h1 := aux_lin_cont (m := m) τ\n have h2 := aux_ciSup_cont (Q := 𝒳 × 𝒴) (fun q i => Φ q.1 q.2 i) (fun _ => (0:ℝ))\n B 0 hB0 (fun q i => hΦbdd _ _ i) (fun q => by simp)\n simp only [add_zero] at h2\n exact ((h1.neg).add h2).add (aux_abs_cont (m := m) lam)\n have hDhom : ∀ (σ : ℝ), 0 ≤ σ → ∀ μ, D (fun i => σ * μ i) = σ * D μ := by\n intro σ hσ μ\n have e1 : (∑ i, τ i * (σ * μ i)) = σ * ∑ i, τ i * μ i := by\n rw [Finset.mul_sum]; exact Finset.sum_congr rfl (fun i _ => by ring)\n have e2 : (⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * (σ * μ i)))\n = σ * ⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i) :=\n aux_ciSup_smul (Q := 𝒳 × 𝒴) (fun q i => Φ q.1 q.2 i) B\n (fun q i => hΦbdd _ _ i) σ hσ μ\n have e3 : (∑ i, lam i * |σ * μ i|) = σ * ∑ i, lam i * |μ i| := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [abs_mul, abs_of_nonneg hσ]; ring\n simp only [hD]\n rw [e1, e2, e3]\n ring\n have hDpos : ∀ μ : Fin m → ℝ, μ ≠ 0 → 0 < D μ := by\n intro μ hμ\n exact aux_D_pos Φ τ lam B hΦmeas hΦbdd hreg2 μ hμ\n obtain ⟨α, hαpos, hα⟩ := aux_homog_min hmpos D hDcont hDhom hDpos\n refine aux_coercive_min _ hΨcont α (cst - Kg) hαpos (fun μ => ?_)\n have hSge : (⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i))\n ≤ (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q)) + Kg := by\n refine ciSup_le (fun q => ?_)\n have h1 : ((∑ i, Φ q.1 q.2 i * μ i) - g q)\n ≤ ⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - g q) :=\n le_ciSup (aux_ciSup_bddAbove' (Q := 𝒳 × 𝒴) (fun q i => Φ q.1 q.2 i) g B Kg\n (fun q i => hΦbdd _ _ i) hgbdd μ) q\n have h2 := (abs_le.mp (hgbdd q)).2\n linarith\n have hα' := hα μ\n simp only [hD] at hα'\n linarith\n\nlemma aux_iInf_neg {ι : Sort*} [Nonempty ι] (f : ι → ℝ) (hbdd : BddAbove (Set.range f)) :\n (⨅ i, -f i) = -(⨆ i, f i) := by\n have hbb : BddBelow (Set.range (fun i => -f i)) := by\n obtain ⟨ub, hub⟩ := hbdd\n refine ⟨-ub, ?_⟩\n rintro _ ⟨i, rfl⟩\n have : f i ≤ ub := hub ⟨i, rfl⟩\n simpa using this\n refine le_antisymm ?_ ?_\n · have h1 : (⨆ i, f i) ≤ -(⨅ i, -f i) := by\n refine ciSup_le (fun i => ?_)\n have : (⨅ j, -f j) ≤ -f i := ciInf_le hbb i\n linarith\n linarith\n · refine le_ciInf (fun i => ?_)\n have : f i ≤ ⨆ j, f j := le_ciSup hbdd i\n linarith\n\nlemma aux_GΨ (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) (B : ℝ)\n [Nonempty (𝒳 × 𝒴)] (hΦbdd : ∀ x y i, |Φ x y i| ≤ B) (hhbdd : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1)\n (ν : Fin m → ℝ) :\n 1 - (∑ i, τ i * -ν i) + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * -ν i) - h q.1 q.2))\n - (∑ i, lam i * |-ν i|)\n = -((-1) - (∑ i, τ i * ν i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * ν i) - -(h q.1 q.2)))\n + (∑ i, lam i * |ν i|)) := by\n have e1 : (∑ i, τ i * -ν i) = -(∑ i, τ i * ν i) := by\n rw [← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n have e2 : (∑ i, lam i * |-ν i|) = ∑ i, lam i * |ν i| :=\n Finset.sum_congr rfl (fun i _ => by rw [abs_neg])\n have hbdd : BddAbove (Set.range (fun q : 𝒳 × 𝒴 =>\n (∑ i, Φ q.1 q.2 i * ν i) - -(h q.1 q.2))) :=\n aux_ciSup_bddAbove' (Q := 𝒳 × 𝒴) (fun q i => Φ q.1 q.2 i) (fun q => -(h q.1 q.2)) B 1\n (fun q i => hΦbdd _ _ i) (fun q => by rw [abs_neg]; exact hhbdd q) ν\n have e3 : (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * -ν i) - h q.1 q.2))\n = -(⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * ν i) - -(h q.1 q.2))) := by\n rw [← aux_iInf_neg _ hbdd]\n refine iInf_congr (fun q => ?_)\n have : (∑ i, Φ q.1 q.2 i * -ν i) = -(∑ i, Φ q.1 q.2 i * ν i) := by\n rw [← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [this]\n ring\n rw [e1, e2, e3]\n ring\n\nend Attain\n\n\ntheorem theorem5 {𝒳 : Type*} [MeasurableSpace 𝒳] [StandardBorelSpace 𝒳] {𝒴 : Type*} [Fintype 𝒴]\n [MeasurableSpace 𝒴] [MeasurableSingletonClass 𝒴] {m : ℕ} (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ)\n (h : 𝒳 → 𝒴 → ℝ) (p : Measure (𝒳 × 𝒴))\n\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∃ B : ℝ, ∀ x y i, |Φ x y i| ≤ B)\n\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hrule_nonneg : ∀ x y, 0 ≤ h x y) (hrule_sum : ∀ x, ∑ y, h x y = 1)\n (hp : inUncertaintySetM Φ τ lam p)\n (hba : BddAbove (Set.range (fun μ : Fin m → ℝ => 1 - (∑ i, τ i * μ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) - (∑ i, lam i * |μ i|))))\n (hbb : BddBelow (Set.range (fun μ : Fin m → ℝ => 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|)))) :\n (RunderM Φ τ lam h ≤ expectedLossM h p ∧ expectedLossM h p ≤ RoverM Φ τ lam h)\n ∧ ((R1 Φ τ lam ∨ R2 Φ τ lam) →\n (∃ μ : Fin m → ℝ, 1 - (∑ i, τ i * μ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n - (∑ i, lam i * |μ i|) = RunderM Φ τ lam h)\n ∧ (∃ μ : Fin m → ℝ, 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n + (∑ i, lam i * |μ i|) = RoverM Φ τ lam h)) := by\n obtain ⟨B, hB⟩ := hΦbdd\n refine ⟨⟨?_, ?_⟩, ?_⟩\n · exact ciSup_le (fun μ => aux_weak_lower Φ h B τ lam p hΦmeas hB hhmeas hrule_nonneg hrule_sum hp μ)\n · exact le_ciInf (fun μ => aux_weak_upper Φ h B τ lam p hΦmeas hB hhmeas hrule_nonneg hrule_sum hp μ)\n · intro hreg\n obtain ⟨hprob, hcon⟩ := hp\n haveI := hprob\n have hne : Nonempty (𝒳 × 𝒴) := by\n by_contra hcon2\n rw [not_nonempty_iff] at hcon2\n have h1 : (p Set.univ) = 1 := measure_univ\n rw [Set.univ_eq_empty_iff.2 hcon2] at h1\n simp at h1\n haveI := hne\n have hlam : ∀ i, 0 ≤ lam i := fun i => le_trans (abs_nonneg _) (hcon i)\n have hB0 : (0:ℝ) ≤ |B| := abs_nonneg B\n have hB' : ∀ x y i, |Φ x y i| ≤ |B| := fun x y i => le_trans (hB x y i) (le_abs_self B)\n have hh1 : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1 := fun z => by\n rw [abs_of_nonneg (hrule_nonneg _ _)]\n exact aux_h_le_one h hrule_nonneg hrule_sum _ _\n constructor\n · -- lower bound attained\n obtain ⟨ub, hub⟩ := id hba\n have hlbΨ : ∀ ν : Fin m → ℝ, -ub ≤ (-1) - (∑ i, τ i * ν i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * ν i) - -(h q.1 q.2)))\n + (∑ i, lam i * |ν i|) := by\n intro ν\n have h1 : 1 - (∑ i, τ i * -ν i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * -ν i) - h q.1 q.2))\n - (∑ i, lam i * |-ν i|) ≤ ub := hub (Set.mem_range_self (fun i => -ν i))\n rw [aux_GΨ Φ τ lam h |B| hB' hh1 ν] at h1\n linarith\n obtain ⟨μ₀, hμ₀⟩ := aux_attain Φ τ lam |B| hB0 hΦmeas hB' (-1)\n (fun z => -(h z.1 z.2)) 1 zero_le_one (fun z => by rw [abs_neg]; exact hh1 z)\n hlam hne hreg (-ub) hlbΨ\n refine ⟨fun i => -μ₀ i, ?_⟩\n have hmax : ∀ μ : Fin m → ℝ,\n 1 - (∑ i, τ i * μ i) + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n - (∑ i, lam i * |μ i|)\n ≤ 1 - (∑ i, τ i * -μ₀ i)\n + (⨅ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * -μ₀ i) - h q.1 q.2))\n - (∑ i, lam i * |-μ₀ i|) := by\n intro μ\n have e1 := aux_GΨ Φ τ lam h |B| hB' hh1 (fun i => -μ i)\n simp only [neg_neg] at e1\n have e2 := aux_GΨ Φ τ lam h |B| hB' hh1 μ₀\n have e3 := hμ₀ (fun i => -μ i)\n linarith\n exact le_antisymm (le_ciSup hba _) (ciSup_le hmax)\n · -- upper bound attained\n obtain ⟨lb0, hlb0⟩ := id hbb\n have hlbF : ∀ μ : Fin m → ℝ, lb0 ≤ 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n + (∑ i, lam i * |μ i|) := fun μ => hlb0 (Set.mem_range_self μ)\n obtain ⟨μ₀, hμ₀⟩ := aux_attain Φ τ lam |B| hB0 hΦmeas hB' 1\n (fun z => h z.1 z.2) 1 zero_le_one hh1 hlam hne hreg lb0 hlbF\n exact ⟨μ₀, le_antisymm (le_ciInf hμ₀) (ciInf_le hbb μ₀)⟩\n\n\nsection StrongDual\n\nopen Pointwise\n\nset_option linter.unusedSectionVars false\n\nvariable {𝒳 : Type*} [MeasurableSpace 𝒳] [MeasurableSingletonClass 𝒳]\n {𝒴 : Type*} [Fintype 𝒴] [MeasurableSpace 𝒴] [MeasurableSingletonClass 𝒴] {m : ℕ}\n\nlemma sd_mix_prob (p₁ p₂ : Measure (𝒳 × 𝒴)) [IsProbabilityMeasure p₁] [IsProbabilityMeasure p₂]\n {θ₁ θ₂ : ℝ} (h1 : 0 ≤ θ₁) (h2 : 0 ≤ θ₂) (hsum : θ₁ + θ₂ = 1) :\n IsProbabilityMeasure (ENNReal.ofReal θ₁ • p₁ + ENNReal.ofReal θ₂ • p₂) := by\n constructor\n rw [Measure.add_apply, Measure.smul_apply, Measure.smul_apply, measure_univ, measure_univ,\n smul_eq_mul, smul_eq_mul, mul_one, mul_one, ← ENNReal.ofReal_add h1 h2, hsum,\n ENNReal.ofReal_one]\n\nlemma sd_mix_integral (p₁ p₂ : Measure (𝒳 × 𝒴))\n {θ₁ θ₂ : ℝ} (h1 : 0 ≤ θ₁) (h2 : 0 ≤ θ₂) (f : 𝒳 × 𝒴 → ℝ)\n (hf1 : Integrable f p₁) (hf2 : Integrable f p₂) :\n ∫ z, f z ∂(ENNReal.ofReal θ₁ • p₁ + ENNReal.ofReal θ₂ • p₂)\n = θ₁ * (∫ z, f z ∂p₁) + θ₂ * (∫ z, f z ∂p₂) := by\n rw [integral_add_measure (hf1.smul_measure ENNReal.ofReal_ne_top)\n (hf2.smul_measure ENNReal.ofReal_ne_top),\n integral_smul_measure, integral_smul_measure, ENNReal.toReal_ofReal h1,\n ENNReal.toReal_ofReal h2, smul_eq_mul, smul_eq_mul]\n\n/-- The set of pairs `(w, t)` such that some probability measure `p` has feature expectations\nwithin `lam` of `w + τ` and mean loss at most `t`. -/\ndef sdSet (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) :\n Set ((Fin m → ℝ) × ℝ) :=\n {z | ∃ p : Measure (𝒳 × 𝒴), IsProbabilityMeasure p ∧\n (∀ i, |z.1 i - (featExpectM Φ p i - τ i)| ≤ lam i) ∧ (∫ q, h q.1 q.2 ∂p) ≤ z.2}\n\nvariable (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) (B : ℝ)\n\nlemma sd_convex\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hhbdd : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1) :\n Convex ℝ (sdSet Φ τ lam h) := by\n rintro z ⟨p₁, hp₁, hc₁, hl₁⟩ z' ⟨p₂, hp₂, hc₂, hl₂⟩ θ₁ θ₂ hθ₁ hθ₂ hθ\n haveI := hp₁; haveI := hp₂\n have hiΦ1 : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p₁ := fun i =>\n aux_integrable_of_bdd p₁ _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hiΦ2 : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p₂ := fun i =>\n aux_integrable_of_bdd p₂ _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hih1 : Integrable (fun z : 𝒳 × 𝒴 => h z.1 z.2) p₁ :=\n aux_integrable_of_bdd p₁ _ hhmeas 1 hhbdd\n have hih2 : Integrable (fun z : 𝒳 × 𝒴 => h z.1 z.2) p₂ :=\n aux_integrable_of_bdd p₂ _ hhmeas 1 hhbdd\n refine ⟨ENNReal.ofReal θ₁ • p₁ + ENNReal.ofReal θ₂ • p₂,\n sd_mix_prob p₁ p₂ hθ₁ hθ₂ hθ, ?_, ?_⟩\n · intro i\n have hfe : featExpectM Φ (ENNReal.ofReal θ₁ • p₁ + ENNReal.ofReal θ₂ • p₂) i\n = θ₁ * featExpectM Φ p₁ i + θ₂ * featExpectM Φ p₂ i :=\n sd_mix_integral p₁ p₂ hθ₁ hθ₂ _ (hiΦ1 i) (hiΦ2 i)\n have hz : (θ₁ • z + θ₂ • z').1 i = θ₁ * z.1 i + θ₂ * z'.1 i := rfl\n rw [hz, hfe]\n have e : θ₁ * z.1 i + θ₂ * z'.1 i - (θ₁ * featExpectM Φ p₁ i + θ₂ * featExpectM Φ p₂ i - τ i)\n = θ₁ * (z.1 i - (featExpectM Φ p₁ i - τ i))\n + θ₂ * (z'.1 i - (featExpectM Φ p₂ i - τ i)) := by\n have : τ i = θ₁ * τ i + θ₂ * τ i := by rw [← add_mul, hθ, one_mul]\n nlinarith [this]\n rw [e]\n calc |θ₁ * (z.1 i - (featExpectM Φ p₁ i - τ i))\n + θ₂ * (z'.1 i - (featExpectM Φ p₂ i - τ i))|\n ≤ |θ₁ * (z.1 i - (featExpectM Φ p₁ i - τ i))|\n + |θ₂ * (z'.1 i - (featExpectM Φ p₂ i - τ i))| := abs_add_le _ _\n _ = θ₁ * |z.1 i - (featExpectM Φ p₁ i - τ i)|\n + θ₂ * |z'.1 i - (featExpectM Φ p₂ i - τ i)| := by\n rw [abs_mul, abs_mul, abs_of_nonneg hθ₁, abs_of_nonneg hθ₂]\n _ ≤ θ₁ * lam i + θ₂ * lam i := by\n exact add_le_add (mul_le_mul_of_nonneg_left (hc₁ i) hθ₁)\n (mul_le_mul_of_nonneg_left (hc₂ i) hθ₂)\n _ = lam i := by rw [← add_mul, hθ, one_mul]\n · have hint : (∫ q, h q.1 q.2 ∂(ENNReal.ofReal θ₁ • p₁ + ENNReal.ofReal θ₂ • p₂))\n = θ₁ * (∫ q, h q.1 q.2 ∂p₁) + θ₂ * (∫ q, h q.1 q.2 ∂p₂) :=\n sd_mix_integral p₁ p₂ hθ₁ hθ₂ _ hih1 hih2\n rw [hint]\n have hz : (θ₁ • z + θ₂ • z').2 = θ₁ * z.2 + θ₂ * z'.2 := rfl\n rw [hz]\n exact add_le_add (mul_le_mul_of_nonneg_left hl₁ hθ₁) (mul_le_mul_of_nonneg_left hl₂ hθ₂)\n\nlemma sd_up (z : (Fin m → ℝ) × ℝ) (hz : z ∈ sdSet Φ τ lam h) (s : ℝ) (hs : 0 ≤ s) :\n (z.1, z.2 + s) ∈ sdSet Φ τ lam h := by\n obtain ⟨p, hp, hc, hl⟩ := hz\n exact ⟨p, hp, hc, by simpa using hl.trans (by linarith)⟩\n\nlemma sd_mem_of_point (q : 𝒳 × 𝒴) (v : Fin m → ℝ)\n (hv : ∀ i, |v i| ≤ lam i) (t : ℝ) (ht : h q.1 q.2 ≤ t) :\n ((fun i => Φ q.1 q.2 i - τ i + v i), t) ∈ sdSet Φ τ lam h := by\n refine ⟨Measure.dirac q, inferInstance, ?_, ?_⟩\n · intro i\n have : featExpectM Φ (Measure.dirac q) i = Φ q.1 q.2 i := by\n simpa [featExpectM] using integral_dirac (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) q\n simp only [this]\n have : Φ q.1 q.2 i - τ i + v i - (Φ q.1 q.2 i - τ i) = v i := by ring\n rw [this]\n exact hv i\n · simpa using (integral_dirac (fun z : 𝒳 × 𝒴 => h z.1 z.2) q).le.trans ht\n\nlemma sd_dual_repr (f : ((Fin m → ℝ) × ℝ) →L[ℝ] ℝ) :\n ∃ (μ : Fin m → ℝ) (c : ℝ), ∀ z : (Fin m → ℝ) × ℝ,\n f z = (∑ i, μ i * z.1 i) + c * z.2 := by\n classical\n set L : (Fin m → ℝ) →ₗ[ℝ] ℝ :=\n (f : ((Fin m → ℝ) × ℝ) →ₗ[ℝ] ℝ).comp (LinearMap.inl ℝ (Fin m → ℝ) ℝ) with hL\n refine ⟨fun i => L (fun j => if i = j then (1:ℝ) else 0), f (0, 1), fun z => ?_⟩\n have h1 : f z = f ((z.1, (0:ℝ)) : (Fin m → ℝ) × ℝ) + f ((0 : Fin m → ℝ), z.2) := by\n rw [← map_add]\n congr 1\n ext <;> simp\n have h2 : f ((0 : Fin m → ℝ), z.2) = z.2 * f (0, 1) := by\n have he : ((0 : Fin m → ℝ), z.2) = z.2 • ((0 : Fin m → ℝ), (1:ℝ)) := by\n ext <;> simp\n rw [he, map_smul, smul_eq_mul]\n have h3 : f (z.1, (0:ℝ)) = L z.1 := rfl\n rw [h1, h2, h3, LinearMap.pi_apply_eq_sum_univ L z.1]\n rw [mul_comm (f (0,1)) z.2]\n congr 1\n exact Finset.sum_congr rfl (fun i _ => by rw [smul_eq_mul, mul_comm])\n\nlemma sd_RoverM_le [Nonempty (𝒳 × 𝒴)] (hlam : ∀ i, 0 ≤ lam i)\n (hbb : BddBelow (Set.range (fun μ : Fin m → ℝ => 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|))))\n (α : ℝ) (ν : Fin m → ℝ)\n (hν : ∀ (q : 𝒳 × 𝒴) (v : Fin m → ℝ), (∀ i, |v i| ≤ lam i) →\n (∑ i, ν i * (Φ q.1 q.2 i - τ i + v i)) - h q.1 q.2 ≤ α - 1) :\n RoverM Φ τ lam h ≤ α := by\n classical\n set v : Fin m → ℝ := fun i => if 0 ≤ ν i then lam i else -lam i with hv\n have hvbdd : ∀ i, |v i| ≤ lam i := by\n intro i\n by_cases hi : 0 ≤ ν i\n · simp [hv, hi, abs_of_nonneg (hlam i)]\n · simp [hv, hi, abs_neg, abs_of_nonneg (hlam i)]\n have hvid : ∀ i, ν i * v i = lam i * |ν i| := by\n intro i\n by_cases hi : 0 ≤ ν i\n · simp [hv, hi, abs_of_nonneg hi]; ring\n · push_neg at hi\n simp [hv, hi.not_ge, abs_of_neg hi]; ring\n have key : ∀ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * ν i) - h q.1 q.2\n ≤ (α - 1) + (∑ i, τ i * ν i) - (∑ i, lam i * |ν i|) := by\n intro q\n have h1 := hν q v hvbdd\n have hexp : (∑ i, ν i * (Φ q.1 q.2 i - τ i + v i))\n = (∑ i, Φ q.1 q.2 i * ν i) - (∑ i, τ i * ν i) + (∑ i, lam i * |ν i|) := by\n rw [← Finset.sum_sub_distrib, ← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [← hvid i]; ring\n rw [hexp] at h1\n linarith\n have hsup : (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * ν i) - h q.1 q.2))\n ≤ (α - 1) + (∑ i, τ i * ν i) - (∑ i, lam i * |ν i|) := ciSup_le key\n have := ciInf_le hbb ν\n simp only [RoverM]\n calc (⨅ μ : Fin m → ℝ, (1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|)))\n ≤ 1 - (∑ i, τ i * ν i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * ν i) - h q.1 q.2)) + (∑ i, lam i * |ν i|) := this\n _ ≤ α := by linarith\n\nlemma sd_separate_open (E : Set ((Fin m → ℝ) × ℝ)) (hconv : Convex ℝ E)\n (hup : ∀ z ∈ E, ∀ s : ℝ, 0 ≤ s → (z.1, z.2 + s) ∈ E)\n (hint : (interior E).Nonempty) (β : ℝ) (hx₀ : ((0 : Fin m → ℝ), β) ∉ E) :\n ∃ (μ : Fin m → ℝ) (γ : ℝ), 0 ≤ γ ∧ (γ ≠ 0 ∨ μ ≠ 0) ∧\n ∀ z ∈ E, (∑ i, μ i * z.1 i) - γ * z.2 ≤ -(γ * β) := by\n obtain ⟨f, hf⟩ := geometric_hahn_banach_open_point (hconv.interior) isOpen_interior\n (fun hc => hx₀ (interior_subset hc))\n obtain ⟨z₀, hz₀⟩ := hint\n have hfE : ∀ z ∈ E, f z ≤ f ((0 : Fin m → ℝ), β) := by\n have hcl : E ⊆ closure (interior E) := by\n rw [hconv.closure_interior_eq_closure_of_nonempty_interior ⟨z₀, hz₀⟩]\n exact subset_closure\n have hclosed : IsClosed {y : (Fin m → ℝ) × ℝ | f y ≤ f ((0 : Fin m → ℝ), β)} :=\n isClosed_le f.continuous continuous_const\n intro z hz\n exact hclosed.closure_subset_iff.mpr (fun y hy => (hf y hy).le) (hcl hz)\n obtain ⟨μ, c, hrepr⟩ := sd_dual_repr f\n have hx0v : f ((0 : Fin m → ℝ), β) = c * β := by\n rw [hrepr]; simp\n have hmain : ∀ z ∈ E, (∑ i, μ i * z.1 i) + c * z.2 ≤ c * β := by\n intro z hz\n have := hfE z hz\n rwa [hrepr, hx0v] at this\n have hc : c ≤ 0 := by\n by_contra hcpos\n push_neg at hcpos\n set A : ℝ := (∑ i, μ i * z₀.1 i) with hA\n set s : ℝ := max 0 ((c * β - A - c * z₀.2) / c + 1) with hs\n have hs0 : 0 ≤ s := le_max_left _ _\n have hzE : z₀ ∈ E := interior_subset hz₀\n have h1 := hmain (z₀.1, z₀.2 + s) (hup z₀ hzE s hs0)\n simp only at h1\n have h2 : (c * β - A - c * z₀.2) / c + 1 ≤ s := le_max_right _ _\n have h3 : c * ((c * β - A - c * z₀.2) / c + 1) ≤ c * s :=\n mul_le_mul_of_nonneg_left h2 hcpos.le\n rw [mul_add, mul_div_cancel₀ _ (ne_of_gt hcpos), mul_one] at h3\n nlinarith [h1, h3]\n refine ⟨μ, -c, by linarith, ?_, ?_⟩\n · by_contra hcon\n push_neg at hcon\n obtain ⟨hc0, hμ0⟩ := hcon\n have hc0' : c = 0 := by linarith [neg_eq_zero.mp hc0]\n have : ∀ z : (Fin m → ℝ) × ℝ, f z = 0 := by\n intro z\n rw [hrepr, hc0', hμ0]\n simp\n have hlt := hf z₀ hz₀\n rw [this z₀, this ((0 : Fin m → ℝ), β)] at hlt\n exact lt_irrefl 0 hlt\n · intro z hz\n have := hmain z hz\n linarith [this]\n\nlemma sd_separate_closed (E : Set ((Fin m → ℝ) × ℝ)) (hconv : Convex ℝ E)\n (hup : ∀ z ∈ E, ∀ s : ℝ, 0 ≤ s → (z.1, z.2 + s) ∈ E)\n (hEne : E.Nonempty) (hclosed : IsClosed E) (β : ℝ)\n (hx₀ : ((0 : Fin m → ℝ), β) ∉ E) :\n ∃ (μ : Fin m → ℝ) (γ u : ℝ), 0 ≤ γ ∧ 0 < u ∧\n ∀ z ∈ E, (∑ i, μ i * z.1 i) - γ * z.2 ≤ -(γ * β) - u := by\n obtain ⟨f, u, hfu, hfE⟩ := geometric_hahn_banach_point_closed hconv hclosed hx₀\n obtain ⟨μ, c, hrepr⟩ := sd_dual_repr f\n obtain ⟨z₀, hz₀⟩ := hEne\n have hx0v : f ((0 : Fin m → ℝ), β) = c * β := by rw [hrepr]; simp\n have hmain : ∀ z ∈ E, u ≤ (∑ i, μ i * z.1 i) + c * z.2 := by\n intro z hz\n have := hfE z hz\n rw [hrepr] at this\n linarith\n have hcβ : c * β < u := by rw [← hx0v]; exact hfu\n have hc : 0 ≤ c := by\n by_contra hcneg\n push_neg at hcneg\n set A : ℝ := (∑ i, μ i * z₀.1 i) with hA\n set s : ℝ := max 0 ((u - A - c * z₀.2) / c + 1) with hs\n have hs0 : 0 ≤ s := le_max_left _ _\n have h1 := hmain (z₀.1, z₀.2 + s) (hup z₀ hz₀ s hs0)\n simp only at h1\n have h2 : (u - A - c * z₀.2) / c + 1 ≤ s := le_max_right _ _\n have h3 : c * s ≤ c * ((u - A - c * z₀.2) / c + 1) :=\n mul_le_mul_of_nonpos_left h2 hcneg.le\n rw [mul_add, mul_div_cancel₀ _ (ne_of_lt hcneg), mul_one] at h3\n rw [mul_add] at h1\n linarith [h1, h3]\n refine ⟨fun i => -μ i, c, u - c * β, hc, by linarith, ?_⟩\n intro z hz\n have h1 := hmain z hz\n have h2 : (∑ i, (fun i => -μ i) i * z.1 i) = -(∑ i, μ i * z.1 i) := by\n rw [← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [h2]\n linarith\n\n\nlemma sd_sign_vec (hlam : ∀ i, 0 ≤ lam i) (μ : Fin m → ℝ) :\n ∃ v : Fin m → ℝ, (∀ i, |v i| ≤ lam i) ∧ (∑ i, μ i * v i) = ∑ i, lam i * |μ i| := by\n classical\n refine ⟨fun i => if 0 ≤ μ i then lam i else -lam i, fun i => ?_, ?_⟩\n · by_cases hi : 0 ≤ μ i\n · simp [hi, abs_of_nonneg (hlam i)]\n · simp [hi, abs_neg, abs_of_nonneg (hlam i)]\n · refine Finset.sum_congr rfl (fun i _ => ?_)\n by_cases hi : 0 ≤ μ i\n · simp only [hi, if_true, abs_of_nonneg hi]; ring\n · push_neg at hi\n simp only [hi.not_ge, if_false, abs_of_neg hi]; ring\n\nlemma sd_x0_not_mem\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hhbdd : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1) (α : ℝ)\n (hW : ∀ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p → expectedLossM h p < α) :\n ((0 : Fin m → ℝ), 1 - α) ∉ sdSet Φ τ lam h := by\n rintro ⟨p, hp, hc, hl⟩\n haveI := hp\n have hih : Integrable (fun z : 𝒳 × 𝒴 => h z.1 z.2) p := aux_integrable_of_bdd p _ hhmeas 1 hhbdd\n have hfeas : inUncertaintySetM Φ τ lam p := by\n refine ⟨hp, fun i => ?_⟩\n have hci := hc i\n have he : |featExpectM Φ p i - τ i| = |(0 : Fin m → ℝ) i - (featExpectM Φ p i - τ i)| := by\n simp only [Pi.zero_apply, zero_sub, abs_neg]\n rw [he]\n exact hci\n have hEL : expectedLossM h p = 1 - ∫ z, h z.1 z.2 ∂p := by\n rw [expectedLossM, integral_sub (integrable_const _) hih]; simp\n have hlt := hW p hfeas\n rw [hEL] at hlt\n simp only at hl\n linarith\n\nlemma sd_gamma_zero_R2 [Nonempty (𝒳 × 𝒴)]\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hreg2 : R2 Φ τ lam) (hlam : ∀ i, 0 ≤ lam i)\n (μ : Fin m → ℝ) (hμ : μ ≠ 0)\n (hsep : ∀ (q : 𝒳 × 𝒴) (v : Fin m → ℝ), (∀ i, |v i| ≤ lam i) →\n (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) ≤ 0) : False := by\n obtain ⟨v, hvb, hvs⟩ := sd_sign_vec lam hlam μ\n have key : ∀ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i)\n ≤ (∑ i, τ i * μ i) - (∑ i, lam i * |μ i|) := by\n intro q\n have h1 := hsep q v hvb\n have hexp : (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i))\n = (∑ i, Φ q.1 q.2 i * μ i) - (∑ i, τ i * μ i) + (∑ i, μ i * v i) := by\n rw [← Finset.sum_sub_distrib, ← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [hexp, hvs] at h1\n linarith\n have hsup : (⨆ q : 𝒳 × 𝒴, (∑ i, Φ q.1 q.2 i * μ i))\n ≤ (∑ i, τ i * μ i) - (∑ i, lam i * |μ i|) := ciSup_le key\n have hD := aux_D_pos Φ τ lam B hΦmeas hΦbdd hreg2 μ hμ\n linarith\n\nlemma sd_gamma_zero_R1\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B) (hlam : ∀ i, 0 ≤ lam i)\n (p : Measure (𝒳 × 𝒴)) (hp : inUncertaintySetM Φ τ lam p)\n (μ : Fin m → ℝ) (u : ℝ) (hu : 0 < u)\n (hsep : ∀ (q : 𝒳 × 𝒴) (v : Fin m → ℝ), (∀ i, |v i| ≤ lam i) →\n (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) ≤ -u) : False := by\n obtain ⟨hprob, hcon⟩ := hp\n haveI := hprob\n obtain ⟨v, hvb, hvs⟩ := sd_sign_vec lam hlam μ\n have hiΦ : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p := fun i =>\n aux_integrable_of_bdd p _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hint : Integrable (fun z : 𝒳 × 𝒴 => ∑ i, μ i * (Φ z.1 z.2 i - τ i)) p :=\n integrable_finset_sum _ (fun i _ => ((hiΦ i).sub (integrable_const _)).const_mul _)\n have key : ∀ q : 𝒳 × 𝒴, (∑ i, μ i * (Φ q.1 q.2 i - τ i)) ≤ -u - (∑ i, lam i * |μ i|) := by\n intro q\n have h1 := hsep q v hvb\n have hexp : (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i))\n = (∑ i, μ i * (Φ q.1 q.2 i - τ i)) + (∑ i, μ i * v i) := by\n rw [← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [hexp, hvs] at h1\n linarith\n have hmono : (∫ z, (∑ i, μ i * (Φ z.1 z.2 i - τ i)) ∂p) ≤ -u - (∑ i, lam i * |μ i|) := by\n have := integral_mono hint (integrable_const _) key\n simpa using this\n have hg : (∫ z, (∑ i, μ i * (Φ z.1 z.2 i - τ i)) ∂p)\n = ∑ i, μ i * (featExpectM Φ p i - τ i) := by\n rw [integral_finset_sum (f := fun i => fun z : 𝒳 × 𝒴 => μ i * (Φ z.1 z.2 i - τ i))\n Finset.univ (fun i _ => ((hiΦ i).sub (integrable_const _)).const_mul _)]\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [integral_const_mul, integral_sub (hiΦ i) (integrable_const _)]\n simp [featExpectM]\n rw [hg] at hmono\n have hb : |∑ i, μ i * (featExpectM Φ p i - τ i)| ≤ ∑ i, lam i * |μ i| := by\n calc |∑ i, μ i * (featExpectM Φ p i - τ i)|\n ≤ ∑ i, |μ i * (featExpectM Φ p i - τ i)| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ i, lam i * |μ i| := Finset.sum_le_sum (fun i _ => by\n rw [abs_mul, mul_comm]\n exact mul_le_mul_of_nonneg_right (hcon i) (abs_nonneg _))\n have := (abs_le.mp hb).1\n linarith\n\ndef sdLam (lam : Fin m → ℝ) : Set (Fin m → ℝ) := {v | ∀ i, |v i| ≤ lam i}\n\nlemma sdLam_convex : Convex ℝ (sdLam lam) := by\n intro v hv w hw θ₁ θ₂ hθ₁ hθ₂ hθ i\n have h1 : (θ₁ • v + θ₂ • w) i = θ₁ * v i + θ₂ * w i := rfl\n rw [h1]\n calc |θ₁ * v i + θ₂ * w i| ≤ |θ₁ * v i| + |θ₂ * w i| := abs_add_le _ _\n _ = θ₁ * |v i| + θ₂ * |w i| := by\n rw [abs_mul, abs_mul, abs_of_nonneg hθ₁, abs_of_nonneg hθ₂]\n _ ≤ θ₁ * lam i + θ₂ * lam i :=\n add_le_add (mul_le_mul_of_nonneg_left (hv i) hθ₁)\n (mul_le_mul_of_nonneg_left (hw i) hθ₂)\n _ = lam i := by rw [← add_mul, hθ, one_mul]\n\nlemma sdLam_eq_pi : sdLam lam = Set.univ.pi (fun i => Set.Icc (-lam i) (lam i)) := by\n ext v\n simp only [sdLam, Set.mem_setOf_eq, Set.mem_pi, Set.mem_univ, forall_true_left, Set.mem_Icc]\n constructor\n · intro hv i; exact abs_le.mp (hv i)\n · intro hv i; exact abs_le.mpr (hv i)\n\nlemma sdLam_compact : IsCompact (sdLam lam) := by\n rw [sdLam_eq_pi]\n exact isCompact_univ_pi (fun i => isCompact_Icc)\n\ndef sdBase (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) :\n Set ((Fin m → ℝ) × ℝ) :=\n Set.range (fun q : 𝒳 × 𝒴 => (((fun i => Φ q.1 q.2 i - τ i) : Fin m → ℝ), h q.1 q.2))\n\ndef sdPoly (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ) :\n Set ((Fin m → ℝ) × ℝ) :=\n (convexHull ℝ (sdBase Φ τ h + (sdLam lam) ×ˢ ({0} : Set ℝ)))\n + (({0} : Set (Fin m → ℝ)) ×ˢ Set.Ici (0:ℝ))\n\nlemma sdPoly_convex : Convex ℝ (sdPoly Φ τ lam h) :=\n (convex_convexHull ℝ _).add ((convex_singleton _).prod (convex_Ici _))\n\nlemma sdPoly_closed [Finite 𝒳] : IsClosed (sdPoly Φ τ lam h) := by\n haveI : Finite (𝒳 × 𝒴) := by infer_instance\n have hK : IsCompact (convexHull ℝ (sdBase Φ τ h + (sdLam lam) ×ˢ ({0} : Set ℝ))) := by\n rw [convexHull_add, ((sdLam_convex (lam := lam)).prod (convex_singleton (0:ℝ))).convexHull_eq]\n exact ((Set.finite_range _).isCompact_convexHull).add\n (IsCompact.prod (sdLam_compact (lam := lam)) isCompact_singleton)\n exact IsClosed.add_left_of_isCompact (isClosed_singleton.prod isClosed_Ici) hK\n\nlemma sdPoly_up (z : (Fin m → ℝ) × ℝ) (hz : z ∈ sdPoly Φ τ lam h) (s : ℝ) (hs : 0 ≤ s) :\n (z.1, z.2 + s) ∈ sdPoly Φ τ lam h := by\n obtain ⟨y, hy, w, hw, hyw⟩ := hz\n have hw1 : w.1 = (0 : Fin m → ℝ) := by simpa using hw.1\n have hw2 : (0:ℝ) ≤ w.2 := hw.2\n have h1 : y.1 + w.1 = z.1 := congrArg Prod.fst hyw\n have h2 : y.2 + w.2 = z.2 := congrArg Prod.snd hyw\n refine ⟨y, hy, ((0 : Fin m → ℝ), w.2 + s), Set.mem_prod.mpr ⟨rfl, add_nonneg hw2 hs⟩, ?_⟩\n refine Prod.ext ?_ ?_\n · show y.1 + (0 : Fin m → ℝ) = z.1\n rw [← h1, hw1]\n · show y.2 + (w.2 + s) = z.2 + s\n rw [← h2]; ring\n\nlemma sdPoly_mem (q : 𝒳 × 𝒴) (v : Fin m → ℝ) (hv : ∀ i, |v i| ≤ lam i) (t : ℝ)\n (ht : h q.1 q.2 ≤ t) :\n (((fun i => Φ q.1 q.2 i - τ i + v i) : Fin m → ℝ), t) ∈ sdPoly Φ τ lam h := by\n refine ⟨(((fun i => Φ q.1 q.2 i - τ i + v i) : Fin m → ℝ), h q.1 q.2), ?_,\n ((0 : Fin m → ℝ), t - h q.1 q.2), ⟨rfl, by simpa using ht⟩, ?_⟩\n · refine subset_convexHull ℝ _ ?_\n refine ⟨(((fun i => Φ q.1 q.2 i - τ i) : Fin m → ℝ), h q.1 q.2), ⟨q, rfl⟩, (v, 0), ⟨hv, rfl⟩, ?_⟩\n refine Prod.ext ?_ ?_\n · funext i; simp\n · simp\n · refine Prod.ext ?_ ?_\n · simp\n · simp\n\nlemma sdPoly_subset (B : ℝ)\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hhbdd : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1) :\n sdPoly Φ τ lam h ⊆ sdSet Φ τ lam h := by\n have hconv : Convex ℝ (sdSet Φ τ lam h) := sd_convex Φ τ lam h B hΦmeas hΦbdd hhmeas hhbdd\n have hbase : sdBase Φ τ h + (sdLam lam) ×ˢ ({0} : Set ℝ) ⊆ sdSet Φ τ lam h := by\n rintro z ⟨y, ⟨q, rfl⟩, w, hw, hyw⟩\n have hw1 : w.1 ∈ sdLam lam := hw.1\n have hw2 : w.2 = 0 := by simpa using hw.2\n have hz : z = (((fun i => Φ q.1 q.2 i - τ i + w.1 i) : Fin m → ℝ), h q.1 q.2) := by\n rw [← hyw]\n refine Prod.ext ?_ ?_\n · funext i; simp\n · simp [hw2]\n rw [hz]\n exact sd_mem_of_point Φ τ lam h q w.1 hw1 (h q.1 q.2) le_rfl\n intro z hz\n obtain ⟨y, hy, w, hw, hyw⟩ := hz\n obtain ⟨hw1, hw2⟩ := hw\n have hy' : y ∈ sdSet Φ τ lam h := convexHull_min hbase hconv hy\n have hw1' : w.1 = (0 : Fin m → ℝ) := by simpa using hw1\n have hz' : z = (y.1, y.2 + w.2) := by\n refine Prod.ext ?_ ?_\n · rw [← hyw]; simp [hw1']\n · rw [← hyw]; simp\n rw [hz']\n exact sd_up Φ τ lam h y hy' w.2 (by simpa using hw2)\n\ndef sdBary (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ : Fin m → ℝ) : Set (Fin m → ℝ) :=\n {w | ∃ p : Measure (𝒳 × 𝒴), IsProbabilityMeasure p ∧ ∀ i, w i = featExpectM Φ p i - τ i}\n\ndef sdAval (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ : Fin m → ℝ) : Set (Fin m → ℝ) :=\n Set.range (fun q : 𝒳 × 𝒴 => ((fun i => Φ q.1 q.2 i - τ i) : Fin m → ℝ))\n\nlemma sdBary_convex (B : ℝ)\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B) :\n Convex ℝ (sdBary Φ τ) := by\n rintro w ⟨p₁, hp₁, hw₁⟩ w' ⟨p₂, hp₂, hw₂⟩ θ₁ θ₂ hθ₁ hθ₂ hθ\n haveI := hp₁; haveI := hp₂\n have hiΦ1 : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p₁ := fun i =>\n aux_integrable_of_bdd p₁ _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n have hiΦ2 : ∀ i, Integrable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) p₂ := fun i =>\n aux_integrable_of_bdd p₂ _ (hΦmeas i) B (fun z => hΦbdd _ _ i)\n refine ⟨ENNReal.ofReal θ₁ • p₁ + ENNReal.ofReal θ₂ • p₂,\n sd_mix_prob p₁ p₂ hθ₁ hθ₂ hθ, fun i => ?_⟩\n have hfe : featExpectM Φ (ENNReal.ofReal θ₁ • p₁ + ENNReal.ofReal θ₂ • p₂) i\n = θ₁ * featExpectM Φ p₁ i + θ₂ * featExpectM Φ p₂ i :=\n sd_mix_integral p₁ p₂ hθ₁ hθ₂ _ (hiΦ1 i) (hiΦ2 i)\n have hlhs : (θ₁ • w + θ₂ • w') i = θ₁ * w i + θ₂ * w' i := rfl\n rw [hlhs, hfe, hw₁ i, hw₂ i]\n linear_combination (-(τ i)) * hθ\n\nlemma sdAval_subset_bary : sdAval Φ τ ⊆ sdBary Φ τ := by\n rintro w ⟨q, rfl⟩\n refine ⟨Measure.dirac q, inferInstance, fun i => ?_⟩\n have : featExpectM Φ (Measure.dirac q) i = Φ q.1 q.2 i := by\n simpa [featExpectM] using integral_dirac (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) q\n rw [this]\n\nlemma sd_span_top\n (p : Measure (𝒳 × 𝒴)) [IsProbabilityMeasure p] (q₀ : 𝒳 × 𝒴)\n (hno : ¬ ∃ (α : Fin m → ℝ) (c : ℝ), α ≠ 0 ∧ ∀ᵐ z ∂p, (∑ i, α i * Φ z.1 z.2 i) = c) :\n Submodule.span ℝ ((fun w : Fin m → ℝ => w - (fun i => Φ q₀.1 q₀.2 i - τ i)) ''\n (sdAval Φ τ)) = ⊤ := by\n classical\n set w₀ : Fin m → ℝ := fun i => Φ q₀.1 q₀.2 i - τ i with hw₀\n set V := Submodule.span ℝ ((fun w : Fin m → ℝ => w - w₀) '' (sdAval Φ τ)) with hV\n by_contra hne\n obtain ⟨f, hf0, hfker⟩ := Submodule.exists_le_ker_of_lt_top V (lt_top_iff_ne_top.mpr hne)\n set α : Fin m → ℝ := fun i => f (fun j => if i = j then (1:ℝ) else 0) with hα\n have hfx : ∀ x : Fin m → ℝ, f x = ∑ i, x i * α i := by\n intro x\n rw [LinearMap.pi_apply_eq_sum_univ f x]\n exact Finset.sum_congr rfl (fun i _ => by rw [smul_eq_mul])\n have hα0 : α ≠ 0 := by\n intro hcon\n apply hf0\n refine LinearMap.ext (fun x => ?_)\n rw [hfx x, hcon]\n simp\n refine hno ⟨α, (∑ i, w₀ i * α i) + ∑ i, τ i * α i, hα0, Filter.Eventually.of_forall ?_⟩\n intro z\n have hmem : ((fun i => Φ z.1 z.2 i - τ i) : Fin m → ℝ) - w₀ ∈ V :=\n Submodule.subset_span ⟨(fun i => Φ z.1 z.2 i - τ i), ⟨z, rfl⟩, rfl⟩\n have hker : f (((fun i => Φ z.1 z.2 i - τ i) : Fin m → ℝ) - w₀) = 0 := hfker hmem\n rw [map_sub, hfx, hfx] at hker\n have hexp : (∑ i, ((fun i => Φ z.1 z.2 i - τ i) : Fin m → ℝ) i * α i)\n = (∑ i, α i * Φ z.1 z.2 i) - ∑ i, τ i * α i := by\n rw [← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl (fun i _ => by simp; ring)\n rw [hexp] at hker\n linarith\n\nlemma sd_hull_interior_nonempty [Nonempty (𝒳 × 𝒴)] (B : ℝ)\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (p : Measure (𝒳 × 𝒴)) [IsProbabilityMeasure p]\n (hno : ¬ ∃ (α : Fin m → ℝ) (c : ℝ), α ≠ 0 ∧ ∀ᵐ z ∂p, (∑ i, α i * Φ z.1 z.2 i) = c) :\n (interior (convexHull ℝ (sdAval Φ τ))).Nonempty := by\n classical\n obtain ⟨q₀⟩ : Nonempty (𝒳 × 𝒴) := inferInstance\n set w₀ : Fin m → ℝ := fun i => Φ q₀.1 q₀.2 i - τ i with hw₀def\n have hV := sd_span_top Φ τ p q₀ hno\n have haff : affineSpan ℝ (sdAval Φ τ) = ⊤ := by\n rw [eq_top_iff]\n rintro x -\n have hw₀ : w₀ ∈ affineSpan ℝ (sdAval Φ τ) := subset_affineSpan ℝ _ ⟨q₀, rfl⟩\n have hxV : x - w₀ ∈ Submodule.span ℝ\n ((fun w : Fin m → ℝ => w - w₀) '' (sdAval Φ τ)) := by\n rw [hV]; trivial\n have hle : Submodule.span ℝ ((fun w : Fin m → ℝ => w - w₀) '' (sdAval Φ τ))\n ≤ vectorSpan ℝ (sdAval Φ τ) := by\n rw [vectorSpan_def]\n refine Submodule.span_le.mpr ?_\n rintro _ ⟨w, hw, rfl⟩\n exact Submodule.subset_span (Set.vsub_mem_vsub hw ⟨q₀, rfl⟩)\n have hdir : x - w₀ ∈ (affineSpan ℝ (sdAval Φ τ)).direction := by\n rw [direction_affineSpan]\n exact hle hxV\n have := AffineSubspace.vadd_mem_of_mem_direction hdir hw₀\n simpa using this\n refine ((convex_convexHull ℝ (sdAval Φ τ)).interior_nonempty_iff_affineSpan_eq_top).mpr ?_\n rw [affineSpan_convexHull]\n exact haff\n\nlemma sd_featExpect_dirac (q : 𝒳 × 𝒴) (i : Fin m) :\n featExpectM Φ (Measure.dirac q) i = Φ q.1 q.2 i := by\n simpa [featExpectM] using integral_dirac (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i) q\n\nlemma sd_int_h_le_one (p : Measure (𝒳 × 𝒴)) [IsProbabilityMeasure p]\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hhbdd : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1) :\n (∫ q, h q.1 q.2 ∂p) ≤ 1 := by\n have hih : Integrable (fun z : 𝒳 × 𝒴 => h z.1 z.2) p := aux_integrable_of_bdd p _ hhmeas 1 hhbdd\n have := integral_mono hih (integrable_const (1:ℝ)) (fun z => (abs_le.mp (hhbdd z)).2)\n simpa using this\n\nlemma sd_interior_nonempty [Nonempty (𝒳 × 𝒴)] (B : ℝ)\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hhbdd : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1)\n (hlam : ∀ i, 0 ≤ lam i) (hreg2 : R2 Φ τ lam) :\n (interior (sdSet Φ τ lam h)).Nonempty := by\n obtain ⟨p, ⟨hprob, hcon⟩, hstrict, hdisj⟩ := hreg2\n haveI := hprob\n obtain ⟨q₀⟩ : Nonempty (𝒳 × 𝒴) := inferInstance\n rcases hdisj with hall | hno\n · set U : Set ((Fin m → ℝ) × ℝ) :=\n (⋂ i : Fin m, {z : (Fin m → ℝ) × ℝ | |z.1 i - (Φ q₀.1 q₀.2 i - τ i)| < lam i})\n ∩ {z : (Fin m → ℝ) × ℝ | 1 < z.2} with hUdef\n have hUopen : IsOpen U := by\n refine IsOpen.inter (isOpen_iInter_of_finite (fun i => ?_)) ?_\n · exact isOpen_lt\n ((((continuous_apply i).comp continuous_fst).sub continuous_const).abs)\n continuous_const\n · exact isOpen_lt continuous_const continuous_snd\n have hUsub : U ⊆ sdSet Φ τ lam h := by\n intro z hz\n refine ⟨Measure.dirac q₀, inferInstance, fun i => ?_, ?_⟩\n · rw [sd_featExpect_dirac Φ q₀ i]\n have := Set.mem_iInter.mp hz.1 i\n exact le_of_lt this\n · rw [integral_dirac (fun z : 𝒳 × 𝒴 => h z.1 z.2) q₀]\n have h1 := (abs_le.mp (hhbdd q₀)).2\n have h2 : (1:ℝ) < z.2 := hz.2\n linarith\n refine ⟨(((fun i => Φ q₀.1 q₀.2 i - τ i) : Fin m → ℝ), (2:ℝ)), ?_⟩\n refine interior_maximal hUsub hUopen ?_\n refine ⟨Set.mem_iInter.mpr (fun i => ?_), ?_⟩\n · show |(Φ q₀.1 q₀.2 i - τ i) - (Φ q₀.1 q₀.2 i - τ i)| < lam i\n simpa using hall i\n · show (1:ℝ) < (2:ℝ)\n norm_num\n · obtain ⟨w₁, hw₁⟩ := sd_hull_interior_nonempty Φ τ B hΦmeas hΦbdd p hno\n set U : Set ((Fin m → ℝ) × ℝ) :=\n {z : (Fin m → ℝ) × ℝ | z.1 ∈ interior (convexHull ℝ (sdAval Φ τ))}\n ∩ {z : (Fin m → ℝ) × ℝ | 1 < z.2} with hUdef\n have hUopen : IsOpen U :=\n IsOpen.inter (isOpen_interior.preimage continuous_fst)\n (isOpen_lt continuous_const continuous_snd)\n have hUsub : U ⊆ sdSet Φ τ lam h := by\n intro z hz\n have h1 : z.1 ∈ convexHull ℝ (sdAval Φ τ) := interior_subset hz.1\n have h2 : z.1 ∈ sdBary Φ τ :=\n convexHull_min (sdAval_subset_bary Φ τ) (sdBary_convex Φ τ B hΦmeas hΦbdd) h1\n obtain ⟨p', hp', hw⟩ := h2\n haveI := hp'\n refine ⟨p', hp', fun i => ?_, ?_⟩\n · rw [← hw i, sub_self, abs_zero]\n exact hlam i\n · have h3 := sd_int_h_le_one h p' hhmeas hhbdd\n have h4 : (1:ℝ) < z.2 := hz.2\n linarith\n exact ⟨(w₁, (2:ℝ)), interior_maximal hUsub hUopen ⟨hw₁, by norm_num⟩⟩\n\n\nlemma sd_strong [Nonempty (𝒳 × 𝒴)]\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hhbdd : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1)\n (hlam : ∀ i, 0 ≤ lam i) (hreg : R1 Φ τ lam ∨ R2 Φ τ lam)\n (hbb : BddBelow (Set.range (fun μ : Fin m → ℝ => 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|))))\n (α : ℝ)\n (hW : ∀ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p → expectedLossM h p < α) :\n RoverM Φ τ lam h ≤ α := by\n have hx₀ : ((0 : Fin m → ℝ), 1 - α) ∉ sdSet Φ τ lam h :=\n sd_x0_not_mem Φ τ lam h hhmeas hhbdd α hW\n obtain ⟨q₀⟩ : Nonempty (𝒳 × 𝒴) := inferInstance\n have hv0 : ∀ i, |(0 : Fin m → ℝ) i| ≤ lam i := fun i => by simpa using hlam i\n rcases hreg with hreg1 | hreg2\n · obtain ⟨hfin, p₀, hp₀⟩ := hreg1\n haveI : Finite 𝒳 := hfin\n have hx₀' : ((0 : Fin m → ℝ), 1 - α) ∉ sdPoly Φ τ lam h := fun hc =>\n hx₀ (sdPoly_subset Φ τ lam h B hΦmeas hΦbdd hhmeas hhbdd hc)\n obtain ⟨μ, γ, u, hγ, hu, hsep⟩ := sd_separate_closed (sdPoly Φ τ lam h)\n (sdPoly_convex Φ τ lam h) (sdPoly_up Φ τ lam h)\n ⟨_, sdPoly_mem Φ τ lam h q₀ 0 hv0 (h q₀.1 q₀.2) le_rfl⟩\n (sdPoly_closed Φ τ lam h) (1 - α) hx₀'\n have hsep' : ∀ (q : 𝒳 × 𝒴) (v : Fin m → ℝ), (∀ i, |v i| ≤ lam i) →\n (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) - γ * h q.1 q.2 ≤ -(γ * (1 - α)) - u :=\n fun q v hv => hsep _ (sdPoly_mem Φ τ lam h q v hv (h q.1 q.2) le_rfl)\n rcases eq_or_lt_of_le hγ with hγ0 | hγpos\n · exfalso\n refine sd_gamma_zero_R1 Φ τ lam B hΦmeas hΦbdd hlam p₀ hp₀ μ u hu (fun q v hv => ?_)\n have hthis := hsep' q v hv\n rw [← hγ0] at hthis\n simpa using hthis\n · refine sd_RoverM_le Φ τ lam h hlam hbb α (fun i => μ i / γ) (fun q v hv => ?_)\n have h1 := hsep' q v hv\n have h2 : (∑ i, (fun i => μ i / γ) i * (Φ q.1 q.2 i - τ i + v i))\n = (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) / γ := by\n rw [Finset.sum_div]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [h2]\n have h3 : (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) / γ ≤ h q.1 q.2 + (α - 1) := by\n rw [div_le_iff₀ hγpos]\n nlinarith [h1, hu, hγpos]\n linarith\n · have hint := sd_interior_nonempty Φ τ lam h B hΦmeas hΦbdd hhmeas hhbdd hlam hreg2\n obtain ⟨μ, γ, hγ, hnz, hsep⟩ := sd_separate_open (sdSet Φ τ lam h)\n (sd_convex Φ τ lam h B hΦmeas hΦbdd hhmeas hhbdd) (sd_up Φ τ lam h) hint (1 - α) hx₀\n have hsep' : ∀ (q : 𝒳 × 𝒴) (v : Fin m → ℝ), (∀ i, |v i| ≤ lam i) →\n (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) - γ * h q.1 q.2 ≤ -(γ * (1 - α)) :=\n fun q v hv => hsep _ (sd_mem_of_point Φ τ lam h q v hv (h q.1 q.2) le_rfl)\n rcases eq_or_lt_of_le hγ with hγ0 | hγpos\n · exfalso\n have hμ : μ ≠ 0 := by\n rcases hnz with h1 | h2\n · exact absurd hγ0.symm h1\n · exact h2\n refine sd_gamma_zero_R2 Φ τ lam B hΦmeas hΦbdd hreg2 hlam μ hμ (fun q v hv => ?_)\n have hthis := hsep' q v hv\n rw [← hγ0] at hthis\n simpa using hthis\n · refine sd_RoverM_le Φ τ lam h hlam hbb α (fun i => μ i / γ) (fun q v hv => ?_)\n have h1 := hsep' q v hv\n have h2 : (∑ i, (fun i => μ i / γ) i * (Φ q.1 q.2 i - τ i + v i))\n = (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) / γ := by\n rw [Finset.sum_div]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n rw [h2]\n have h3 : (∑ i, μ i * (Φ q.1 q.2 i - τ i + v i)) / γ ≤ h q.1 q.2 + (α - 1) := by\n rw [div_le_iff₀ hγpos]\n nlinarith [h1, hγpos]\n linarith\nend StrongDual\n\ntheorem lemma11_strongDuality {𝒳 : Type*} [MeasurableSpace 𝒳] [StandardBorelSpace 𝒳]\n {𝒴 : Type*} [Fintype 𝒴] [MeasurableSpace 𝒴] [MeasurableSingletonClass 𝒴]\n [Nonempty 𝒳] [Nonempty 𝒴] {m : ℕ}\n (Φ : 𝒳 → 𝒴 → Fin m → ℝ) (τ lam : Fin m → ℝ) (h : 𝒳 → 𝒴 → ℝ)\n (hΦmeas : ∀ i, Measurable (fun z : 𝒳 × 𝒴 => Φ z.1 z.2 i))\n (hΦbdd : ∃ B : ℝ, ∀ x y i, |Φ x y i| ≤ B)\n (hhmeas : Measurable (fun z : 𝒳 × 𝒴 => h z.1 z.2))\n (hrule_nonneg : ∀ x y, 0 ≤ h x y) (hrule_sum : ∀ x, ∑ y, h x y = 1)\n (hlam : ∀ i, 0 ≤ lam i)\n (hreg : R1 Φ τ lam ∨ R2 Φ τ lam) :\n worstCaseRiskM Φ τ lam h = RoverM Φ τ lam h\n ∧ ∃ μ : Fin m → ℝ, RoverM Φ τ lam h = 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2))\n + (∑ i, lam i * |μ i|) := by\n obtain ⟨B, hB⟩ := hΦbdd\n haveI hne : Nonempty (𝒳 × 𝒴) := inferInstance\n have hB' : ∀ x y i, |Φ x y i| ≤ |B| := fun x y i => le_trans (hB x y i) (le_abs_self B)\n have hB0 : (0:ℝ) ≤ |B| := abs_nonneg B\n have hh1 : ∀ z : 𝒳 × 𝒴, |h z.1 z.2| ≤ 1 := fun z => by\n rw [abs_of_nonneg (hrule_nonneg _ _)]\n exact aux_h_le_one h hrule_nonneg hrule_sum _ _\n obtain ⟨p₀, hp₀⟩ : ∃ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p := by\n rcases hreg with ⟨_, p, hp⟩ | ⟨p, hp, _, _⟩\n · exact ⟨p, hp⟩\n · exact ⟨p, hp⟩\n have hFge : ∀ μ : Fin m → ℝ, expectedLossM h p₀ ≤ 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|) :=\n fun μ => aux_weak_upper Φ h |B| τ lam p₀ hΦmeas hB' hhmeas hrule_nonneg hrule_sum hp₀ μ\n have hbb : BddBelow (Set.range (fun μ : Fin m → ℝ => 1 - (∑ i, τ i * μ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ i) - h q.1 q.2)) + (∑ i, lam i * |μ i|))) := by\n refine ⟨expectedLossM h p₀, ?_⟩\n rintro _ ⟨μ, rfl⟩\n exact hFge μ\n obtain ⟨μ₀, hμ₀⟩ := aux_attain Φ τ lam |B| hB0 hΦmeas hB' 1\n (fun z => h z.1 z.2) 1 zero_le_one hh1 hlam hne hreg (expectedLossM h p₀) hFge\n have hattain : RoverM Φ τ lam h = 1 - (∑ i, τ i * μ₀ i)\n + (⨆ q : 𝒳 × 𝒴, ((∑ i, Φ q.1 q.2 i * μ₀ i) - h q.1 q.2)) + (∑ i, lam i * |μ₀ i|) :=\n le_antisymm (ciInf_le hbb μ₀) (le_ciInf hμ₀)\n have hWne : {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p}.Nonempty :=\n ⟨expectedLossM h p₀, p₀, hp₀, rfl⟩\n have hWub : ∀ r ∈ {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p},\n r ≤ RoverM Φ τ lam h := by\n rintro r ⟨p, hp, rfl⟩\n exact le_ciInf (fun μ =>\n aux_weak_upper Φ h |B| τ lam p hΦmeas hB' hhmeas hrule_nonneg hrule_sum hp μ)\n have hbdA : BddAbove {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p} :=\n ⟨RoverM Φ τ lam h, hWub⟩\n have hle : sSup {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p}\n ≤ RoverM Φ τ lam h := csSup_le hWne hWub\n have hge : RoverM Φ τ lam h\n ≤ sSup {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p} := by\n by_contra hcon\n push_neg at hcon\n set α : ℝ := (sSup {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p}\n + RoverM Φ τ lam h) / 2 with hαdef\n have h1 : sSup {r : ℝ | ∃ p, inUncertaintySetM Φ τ lam p ∧ r = expectedLossM h p} < α := by\n rw [hαdef]; linarith\n have h2 : α < RoverM Φ τ lam h := by rw [hαdef]; linarith\n have hW' : ∀ p : Measure (𝒳 × 𝒴), inUncertaintySetM Φ τ lam p → expectedLossM h p < α := by\n intro p hp\n exact lt_of_le_of_lt (le_csSup hbdA ⟨p, hp, rfl⟩) h1\n have := sd_strong Φ τ lam h |B| hΦmeas hB' hhmeas hh1 hlam hreg hbb α hW'\n linarith\n exact ⟨le_antisymm hle hge, μ₀, hattain⟩\n\nlemma hoeff_one_sided {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)\n [IsProbabilityMeasure P] {n : ℕ} (C : ℝ) (hC : 0 ≤ C)\n (X : Fin n → Ω → ℝ) (a : ℝ)\n (hbdd : ∀ k ω, |X k ω| ≤ C)\n (hmeas : ∀ k, Measurable (X k))\n (hindep : ProbabilityTheory.iIndepFun X P)\n (hmean : ∀ k, ∫ ω, X k ω ∂P = a)\n {ε : ℝ} (hε : 0 ≤ ε) :\n P.real {ω | ε ≤ ∑ k, (X k ω - a)} ≤ Real.exp (-ε ^ 2 / (2 * ((n:ℝ) * C^2))) := by\n set c : NNReal := (‖C + C‖₊ / 2) ^ 2 with hc\n have hindep' : ProbabilityTheory.iIndepFun (fun k => fun ω => X k ω - a) P := by\n have := hindep.comp (fun _ => fun x : ℝ => x - a) (fun _ => measurable_id.sub_const a)\n exact this\n have hsub : ∀ k : Fin n, ProbabilityTheory.HasSubgaussianMGF (fun ω => X k ω - a) c P := by\n intro k\n have h := ProbabilityTheory.hasSubgaussianMGF_of_mem_Icc (X := X k) (μ := P) (a := -C) (b := C)\n (hmeas k).aemeasurable (Filter.Eventually.of_forall (fun ω => by\n simpa [Set.mem_Icc] using abs_le.mp (hbdd k ω)))\n simpa [hmean k, sub_neg_eq_add] using h\n have key := ProbabilityTheory.HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun\n hindep' (c := fun _ => c) (s := Finset.univ) (fun k _ => hsub k) hε\n have hcoe : ((∑ _k : Fin n, c : NNReal) : ℝ) = (n:ℝ) * C^2 := by\n simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul,\n NNReal.coe_mul, NNReal.coe_natCast, hc, NNReal.coe_pow, NNReal.coe_div,\n coe_nnnorm, Real.norm_eq_abs]\n rw [abs_of_nonneg (by linarith : (0:ℝ) ≤ C + C)]\n push_cast\n ring\n rwa [hcoe] at key\n\nlemma hoeff_two_sided {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)\n [IsProbabilityMeasure P] {n : ℕ} (C : ℝ) (hC : 0 ≤ C)\n (X : Fin n → Ω → ℝ) (a : ℝ)\n (hbdd : ∀ k ω, |X k ω| ≤ C)\n (hmeas : ∀ k, Measurable (X k))\n (hindep : ProbabilityTheory.iIndepFun X P)\n (hmean : ∀ k, ∫ ω, X k ω ∂P = a)\n {ε : ℝ} (hε : 0 ≤ ε) :\n P.real {ω | ε ≤ |∑ k, (X k ω - a)|} ≤ 2 * Real.exp (-ε ^ 2 / (2 * ((n:ℝ) * C^2))) := by\n have h1 := hoeff_one_sided P C hC X a hbdd hmeas hindep hmean hε\n have h2 := hoeff_one_sided P C hC (fun k => fun ω => -(X k ω)) (-a)\n (fun k ω => by simpa using hbdd k ω) (fun k => (hmeas k).neg)\n (hindep.comp (fun _ => fun x : ℝ => -x) (fun _ => measurable_neg))\n (fun k => by rw [integral_neg, hmean k]) hε\n have hsub : {ω | ε ≤ |∑ k, (X k ω - a)|} ⊆\n {ω | ε ≤ ∑ k, (X k ω - a)} ∪ {ω | ε ≤ ∑ k, (-(X k ω) - -a)} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω\n rcases abs_cases (∑ k, (X k ω - a)) with ⟨he, _⟩ | ⟨he, _⟩\n · left; simp only [Set.mem_setOf_eq]; linarith [hω, he.symm]\n · right\n simp only [Set.mem_setOf_eq]\n have : ∑ k, (-(X k ω) - -a) = -∑ k, (X k ω - a) := by\n rw [← Finset.sum_neg_distrib]; congr 1; ext k; ring\n rw [this]; linarith [hω, he.symm]\n calc P.real {ω | ε ≤ |∑ k, (X k ω - a)|}\n ≤ P.real ({ω | ε ≤ ∑ k, (X k ω - a)} ∪ {ω | ε ≤ ∑ k, (-(X k ω) - -a)}) :=\n measureReal_mono hsub\n _ ≤ P.real {ω | ε ≤ ∑ k, (X k ω - a)} + P.real {ω | ε ≤ ∑ k, (-(X k ω) - -a)} :=\n measureReal_union_le _ _\n _ ≤ Real.exp (-ε ^ 2 / (2 * ((n:ℝ) * C^2))) + Real.exp (-ε ^ 2 / (2 * ((n:ℝ) * C^2))) := by\n exact add_le_add h1 h2\n _ = 2 * Real.exp (-ε ^ 2 / (2 * ((n:ℝ) * C^2))) := by ring\n\ntheorem theorem4_hoeffding {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)\n [IsProbabilityMeasure P] (m n : ℕ) (C δ : ℝ)\n (τ : Fin m → ℝ) (Z : Fin n → Ω → Fin m → ℝ)\n (hm : 0 < m) (hn : 0 < n) (hC : 0 ≤ C) (hδ : 0 < δ) (hδ1 : δ < 1)\n (nY : ℕ) (hnY : 0 < nY) (labelOf : Fin m → Fin nY)\n (D : ℕ) (hD : 0 < D)\n (hblocks : ∀ y : Fin nY, (Finset.univ.filter fun i => labelOf i = y).card = D)\n (hlabelOnto : Function.Surjective labelOf)\n (honehot : ∀ k ω, ∃ y : Fin nY, ∀ i, labelOf i ≠ y → Z k ω i = 0)\n (hbdd : ∀ k i ω, |Z k ω i| ≤ C)\n (hmeas : ∀ k, Measurable (Z k))\n (hindep : ProbabilityTheory.iIndepFun Z P)\n (hident : ∀ k l, ProbabilityTheory.IdentDistrib (Z k) (Z l) P P)\n (hmean : ∀ k i, ∫ ω, Z k ω i ∂P = τ i) :\n ENNReal.ofReal (1 - δ)\n ≤ P {ω | ∀ i : Fin m, |τ i - (∑ k, Z k ω i) / (n : ℝ)| ≤ lambdaDelta C δ m n} := by\n set S : Set Ω := {ω | ∀ i : Fin m, |τ i - (∑ k, Z k ω i) / (n : ℝ)| ≤ lambdaDelta C δ m n}\n with hS\n set lam := lambdaDelta C δ m n with hlamdef\n have hnpos : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn\n have hmpos : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n -- main real-valued bound\n have hmain : 1 - δ ≤ P.real S := by\n rcases eq_or_lt_of_le hC with hC0 | hCpos\n · -- C = 0\n have hZ : ∀ k ω i, Z k ω i = 0 := by\n intro k ω i\n have h := hbdd k i ω\n rw [← hC0] at h\n exact abs_eq_zero.mp (le_antisymm h (abs_nonneg _))\n have hτ : ∀ i, τ i = 0 := by\n intro i\n have := hmean ⟨0, hn⟩ i\n rw [← this]\n simp [hZ]\n have hlam0 : lam = 0 := by\n rw [hlamdef, lambdaDelta, ← hC0]; ring\n have hSuniv : S = Set.univ := by\n ext ω\n simp [hS, hτ, hZ, ← hlamdef, hlam0]\n rw [hSuniv]\n simp only [measureReal_univ_eq_one]\n linarith\n · -- 0 < C\n set L := Real.log (2 * (m:ℝ) / δ) with hL\n have hone : (1:ℝ) < 2 * (m:ℝ) / δ := by\n rw [lt_div_iff₀ hδ]\n have : (1:ℝ) ≤ (m:ℝ) := by exact_mod_cast hm\n nlinarith\n have hLpos : 0 < L := Real.log_pos hone\n have hlamnonneg : 0 ≤ lam := by\n rw [hlamdef, lambdaDelta]\n have : (0:ℝ) ≤ 2 * L / (n:ℝ) := by positivity\n positivity\n have hlamsq : lam ^ 2 = C ^ 2 * (2 * L / (n:ℝ)) := by\n rw [hlamdef, lambdaDelta, mul_pow, Real.sq_sqrt (by positivity)]\n -- per-component bound\n have hcomp : ∀ i : Fin m,\n P.real {ω | (n:ℝ) * lam ≤ |∑ k, (Z k ω i - τ i)|} ≤ δ / (m:ℝ) := by\n intro i\n have hb := hoeff_two_sided P C hC (fun k => fun ω => Z k ω i) (τ i)\n (fun k ω => hbdd k i ω) (fun k => (measurable_pi_apply i).comp (hmeas k))\n (hindep.comp (fun _ => fun v : Fin m → ℝ => v i) (fun _ => measurable_pi_apply i))\n (fun k => hmean k i) (by positivity : (0:ℝ) ≤ (n:ℝ) * lam)\n have hexp : -((n:ℝ) * lam) ^ 2 / (2 * ((n:ℝ) * C ^ 2)) = -L := by\n rw [mul_pow, hlamsq]\n field_simp\n rw [hexp] at hb\n have hval : Real.exp (-L) = δ / (2 * (m:ℝ)) := by\n rw [Real.exp_neg, hL, Real.exp_log (by positivity)]\n field_simp\n rw [hval] at hb\n have h2 : 2 * (δ / (2 * (m:ℝ))) = δ / (m:ℝ) := by field_simp\n linarith [hb, h2.le, h2.ge]\n -- union bound\n have hsubset : Sᶜ ⊆ ⋃ i : Fin m, {ω | (n:ℝ) * lam ≤ |∑ k, (Z k ω i - τ i)|} := by\n intro ω hω\n simp only [hS, Set.mem_compl_iff, Set.mem_setOf_eq, not_forall, not_le] at hω\n obtain ⟨i, hi⟩ := hω\n refine Set.mem_iUnion.2 ⟨i, ?_⟩\n simp only [Set.mem_setOf_eq]\n have hsplit : ∑ k, (Z k ω i - τ i) = (∑ k, Z k ω i) - (n:ℝ) * τ i := by\n rw [Finset.sum_sub_distrib]\n simp [mul_comm]\n have hstep : (n:ℝ) * lam ≤ (n:ℝ) * |τ i - (∑ k, Z k ω i) / (n:ℝ)| :=\n mul_le_mul_of_nonneg_left hi.le (le_of_lt hnpos)\n have heq : |∑ k, (Z k ω i - τ i)| = (n:ℝ) * |τ i - (∑ k, Z k ω i) / (n:ℝ)| := by\n have hrw : τ i - (∑ k, Z k ω i) / (n:ℝ) = (-(∑ k, (Z k ω i - τ i))) / (n:ℝ) := by\n rw [hsplit]; field_simp; ring\n rw [hrw, abs_div, abs_neg, abs_of_pos hnpos]\n field_simp\n rw [heq]\n exact hstep\n have hcompl : P.real Sᶜ ≤ δ := by\n calc P.real Sᶜ ≤ P.real (⋃ i : Fin m, {ω | (n:ℝ) * lam ≤ |∑ k, (Z k ω i - τ i)|}) :=\n measureReal_mono hsubset\n _ ≤ ∑ i : Fin m, P.real {ω | (n:ℝ) * lam ≤ |∑ k, (Z k ω i - τ i)|} :=\n measureReal_iUnion_fintype_le _\n _ ≤ ∑ _i : Fin m, δ / (m:ℝ) := Finset.sum_le_sum (fun i _ => hcomp i)\n _ = δ := by\n simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n have hcover : (1:ℝ) ≤ P.real S + P.real Sᶜ := by\n have := measureReal_union_le (μ := P) S Sᶜ\n rw [Set.union_compl_self] at this\n simpa using this\n linarith\n -- conclude\n have hstep := ENNReal.ofReal_le_ofReal hmain\n rw [MeasureTheory.Measure.real, ENNReal.ofReal_toReal (measure_ne_top P S)] at hstep\n exact hstep\n\nend ResearchLevel\n"} +{"id": "v23-20-1353", "source": "Research-level", "targets": [{"label": "Lemma 16", "decls": ["lemma16"], "statement": "Lemma 16 Let $G:\\{-1,1\\}^{k}\\to\\{-1,1\\}$ and let ${\\mathcal{F}}_{1},\\ldots,{\\mathcal{F}}_{k}\\subseteq\\{-1,1\\}^{\\mathcal{X}}$ be hypothesis classes with $\\operatorname{VC}(\\mathcal{F}_{j})~=~d_{j}$ Denote $\\begin{array}{r}{\\bar{d}: = \\frac{1}{k}\\sum_{i = 1}^{k}d_{j}}\\end{array}$ . Define the function class $G\\left({\\mathcal{F}}_{1},\\ldots,{\\mathcal{F}}_{k}\\right)= :$ $\\{\\mathcal{X}\\ni x\\mapsto G\\left(f_{1}(x),\\ldots,f_{k}(x)\\right):f_{i}\\in\\mathcal{F}_{i}\\}$ . Then,\n\n$$\n\\mathrm{VC}\\left(G\\left(\\mathcal{F}_{1},\\ldots,\\mathcal{F}_{k}\\right)\\right)\\leq 2k\\log_2(3k)\\bar{d}\n$$", "context_ids": ["v23-20-1353:ctx3", "v23-20-1353:ctx5"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}, {"label": "Lemma 1", "decls": ["lemma1"], "statement": "Lemma 1 For any class $\\mathcal{H}$ of VC dimension d, and any adversary $\\rho : \\mathcal{X}\\to 2^{\\mathcal{X}}$ such that $|\\rho(x)|\\leq$ $k,$ the VC-dimension of the zero-one robust loss class $L_{\\mathcal{H}}^{\\rho}=\\left\\{(x,y)\\mapsto\\operatorname*{max}_{z\\in\\rho(x)}\\mathbb{I}\\left[h(z)\\neq y\\right]:h\\in\\mathcal{H}\\right\\}$ is at most ${\\mathcal{O}}(d\\log k)$", "context_ids": ["v23-20-1353:ctx1", "v23-20-1353:ctx2", "v23-20-1353:ctx3", "v23-20-1353:ctx5"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}, {"label": "Lemma 14", "decls": ["lemma14"], "statement": "Lemma 14 For all $\\mathcal{F}\\subseteq \\mathbb{R}^{\\mathcal{X}}$ and $\\gamma > 0$ ,we have\n\n$$\n\\mathrm{fat}_{\\gamma}(\\mathcal{F})=\\operatorname*{max}_{r\\in\\mathbb{R}^{\\mathcal{X}}}\\mathrm{fat}_{\\gamma}^{0}(\\mathcal{F}-r),\\tag{7}\n$$\n\nwhere ${\\mathcal{F}}- r ~ = ~ \\{f - r : f \\in{\\mathcal{F}}\\}$ is the r-shifted class; in particular, the maximum is always achieved.", "context_ids": ["v23-20-1353:ctx3", "v23-20-1353:ctx4", "v23-20-1353:ctx6"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "### Proof of Lemma 16\n\nProof We adapt the argument of Blumer et al. (1989, Lemma 3.2.3), which is stated therein for k-fold unions and intersections. The $k = 1$ case is trivial, so assume $k \\geq 2$ For any $S \\subseteq{\\mathcal{X}}$ ,define\n\n$G\\left({\\mathcal{F}}_{1},\\ldots,{\\mathcal{F}}_{k}\\right)(S)\\subseteq\\{-1,1\\}^{S}$ to be the restriction of $G\\left(\\mathcal{F}_{1},\\ldots,\\mathcal{F}_{k}\\right)$ to $S .$ The key observation is that\n\n$$\n\\begin{array}{r c l}{|G\\left(\\mathcal{F}_{1},\\dots,\\mathcal{F}_{k}\\right)(S)|}&{\\le}&{\\displaystyle\\prod_{j=1}^{k}|\\mathcal{F}_{j}(S)|}\\\\ &{\\le}&{\\displaystyle\\prod_{j=1}^{k}(e|S| /d_{j})^{d_{j}}}\\\\ &{\\le}&{\\displaystyle(e|S| /\\bar{d})^{\\bar{d}k}.}\\end{array}\n$$\n\nThe last inequality requires proof. After taking logarithms and dividing both sides by $k,$ it is equivalent to the claim that\n\n$$\n\\bar{d}\\log \\bar{d}\\leq \\frac{1}{k}\\sum_{j = 1}^{k}d_{j}\\log d_{j}\\ ,\n$$\n\nan immediate consequence of Jensen's inequality applied to the convex function $f(x)=x\\log x$\n\nThe rest of the argument is identical that of Blumer et al.: one readily verifies that for $m =$ $|S| =2\\bar{d}k\\log(3k)$ , we have $(em/\\bar{d})^{\\bar{d}k}<2^{m}$\n\n### Proof of Lemma 1\n\nProof [of Lemma 1] Take an arbitrary sample $S=\\{(x_{1},y_{1}),....,(x_{n},y_{n})\\}$ . Construct the set that contains all possible corrupted examples on inputs from $\\begin{array}{r}{S,S_{\\rho}=\\bigcup_{i\\in [n]}\\left\\{z:z\\in\\rho(x_{i})\\right\\}}\\end{array}$ , the size of $S_{\\rho}$ is at most nk. Denote by $L_{\\mathcal{H}}^{\\rho}(S)$ the set of all possible behaviors on $S$ using functions in $L_{\\mathcal{H}}^{\\rho},$ and by $\\mathcal{H}(S_{\\rho})$ , the set of all possible behaviors on $S_{\\rho}$ using functions in $\\mathcal{H}$. Namely, $L_{\\mathcal{H}}^{\\rho}(S)=\\{(\\ell(x_{1},y_{1}),\\ldots,\\ell(x_{n},y_{n})):\\ell\\in L_{\\mathcal{H}}^{\\rho}\\}$ and ${\\mathcal{H}}(S_{\\rho})~=~\\{(h(z_{1}),\\ldots,h(z_{m})):h\\in{\\mathcal{H}}\\}$ Observe that each pattern in the set $L_{\\mathcal{H}}^{\\rho}(S)$ will map to at least one pattern in $\\mathcal{H}(S_{\\rho})$ , implying that the size of $L_{\\mathcal{H}}^{\\rho}(S)$ is at most the size of $\\mathcal{H}(S_{\\rho})$ . Using Sauer's lemma, the size of $\\mathcal{H}(S_{\\rho})$ is at most $(nk)^{d}$ , solving for n such that $(nk)^{d}<2^{n}$ yields the stated bound.\n\n### Proof of Lemma 14\n\nProof Fix $\\mathcal{F}$ and $\\gamma .$ For any choice of $r\\in \\mathbb{R}^{\\mathcal{X}}$ , if ${\\mathcal{F}}- r$ γ-shatters some set $S \\subseteq{\\mathcal{X}}$ at zero, then then $\\mathcal{F}$ $\\gamma$-shatters $S$ in the usual sense with shift $r_{S}\\in \\mathbb{R}^{S}$ (i.e., the restriction of r to S). This proves that the left-hand side of Eq. (7) is at least as large as the right-hand side. Conversely, suppose that $\\mathcal{F}$ $\\gamma$-shatters some $S \\subseteq{\\mathcal{X}}$ in the usual sense, with some shift $r\\in \\mathbb{R}^{S}$ . Choosing $r^{\\prime}\\in \\mathbb{R}^{\\mathcal{X}}$ by $r_{S}^{\\prime}= r$ and $r_{\\mathcal{X}\\backslash S}^{\\prime}= 0$ , we see that ${\\mathcal{F}}- r^{\\prime}$ γ-shatters S at zero. This proves the other direction and hence the claim.", "context": [{"id": "v23-20-1353:ctx1", "name": "Model: domain, labels, adversary rho with |rho(x)| <= k (Section 2)", "statement": "There is an unknown distribution D over some domain $\\mathcal{X}$ of uncorrupted examples and a finite domain of corrupted examples $\\mathcal{Z}$ , possibly the same as $\\mathcal{X}$. Our setting is the agnostic PAC-learning framework in a deterministic scenario. The label of each input is uniquely determined by an arbitrary unknown target function $c : \\mathcal{X}\\to \\mathcal{Y}$ . The function c maps each uncorrupted input $x \\in \\mathcal{X}$ to a label $c(x)=y$ , where the set of labels $\\mathcal{Y}$ can be $\\{1,\\ldots,l\\}$ or $\\mathbb{R}$.\n\nThe adversary is able to corrupt an input by mapping an uncorrupted input $x \\in \\mathcal{X}$ to a corrupted one $z \\in{\\mathcal{Z}}$ . There is a mapping $\\rho$ which for every $x \\in \\mathcal{X}$ defines a set $\\rho(x)\\subseteq{\\mathcal{Z}}$ ,such that $|\\rho(x)|\\le k$ The adversary can map an uncorrupted input x to any corrupted input $z\\in\\rho(x)$ . We assume that the learner has an access to $\\rho(\\cdot)$ during the training phase."}, {"id": "v23-20-1353:ctx2", "name": "Zero-one robust loss, eq. (2) (Section 1.1)", "statement": "Montasser et al. (2019, 2020b) defined a loss function $\\ell:\\mathcal{H}\\times\\mathcal{X}\\times\\mathcal{Y}\\to\\{0,1\\}$ as follows\n\n$$\n\\ell_{2}(h,x,y)=\\operatorname*{max}_{z\\in\\rho(x)}\\mathbb{I}\\left[h(z)\\neq y\\right],\\tag{2}\n$$\n\nwhich we refer to as the zero-one robust loss."}, {"id": "v23-20-1353:ctx3", "name": "Notation (Section 1.3)", "statement": "Notation. d denotes the VC dimension, $d^{*}$ denote the dual dual-VC dimension, $\\mathrm{fat}_{\\gamma}(\\cdot)$ is the γ—fat shattering dimension, and k is the size of possible corruptions for each input. $\\tilde{\\mathcal{O}}(\\cdot)$ stands for for omitting poly-logarithmic factors of $d,d^{*},1/\\epsilon,1/\\delta$"}, {"id": "v23-20-1353:ctx4", "name": "Fat-shattering dimension and shift (Section 3.1)", "statement": "Fat-Shattering Dimension. For $\\mathcal{F}\\subset \\mathbb{R}^{\\mathcal{X}}$ and $\\gamma ~ > ~ 0$ , we say that $\\mathcal{F}$ $\\gamma$-shatters a set $S \\ =$ $\\{x_{1},\\ldots,x_{m}\\}\\subset\\mathcal{X}$ if there exists an $r=(r_{1},\\ldots,r_{m})\\in\\mathbb{R}^{m}$ such that for each $b\\in\\{-1,1\\}^{m}$ there is a function $f_{b}\\in \\mathcal{F}$ such that\n\n$$\n\\forall i\\in [m]:\\begin{cases}f_{b}(x_{i})\\geq r_{i}+\\gamma&\\text{if } b_{i}=1\\\\ f_{b}(x_{i})\\leq r_{i}-\\gamma&\\text{if } b_{i}= -1\\end{cases}.\n$$\n\nWe refer to r as the shift. The γ-fat-shattering dimension, denoted by $\\mathrm{fat}_{\\gamma}(\\mathcal{F})$ , is the size of the largest γ-shattered set (possibly ∞)."}, {"id": "v23-20-1353:ctx5", "name": "Growth function and VC-dimension (Section 3.1)", "statement": "Growth Function. The growth function $\\Pi_{\\mathcal{H}}: \\mathbb{N}\\mapsto \\mathbb{N}$ for a binary function class $\\mathcal{H}:\\mathcal{X}\\mapsto\\{0,1\\}$ is defined by\n\n$$\n\\forall m\\in\\mathbb{N},\\ \\Pi_{\\mathcal{H}}(m)=\\operatorname*{max}_{\\{x_{1},\\ldots,x_{m}\\}\\subseteq\\mathcal{X}}|\\left\\{(h(x_{1}),\\ldots,h(x_{m})):h\\in\\mathcal{H}\\right\\}|\n$$\n\nAnd the VC-dimension of $\\mathcal{H}$ is defined by\n\n$$\n\\mathrm{VC}(\\mathcal{H})=\\operatorname*{max}\\left\\{m:\\Pi_{\\mathcal{H}}(m)=2^{m}\\right\\}.\n$$"}, {"id": "v23-20-1353:ctx6", "name": "Shattering at zero, fat^0_gamma (Section 6.1)", "statement": "Before presenting the proof, we introduce some auxiliary notions. We say that $\\mathcal{F}$ “$\\gamma$-shatters a set $S$ at zero” if the shift $r$ is constrained to be 0 in the the usual γ-shattering definition (has appeared previously in Gottlieb et al. (2014)). The analogous dimension will be denoted by $\\mathrm{fat}_{\\gamma}^{0}(\\mathcal{F})$."}], "lean": "import Mathlib\n\nnamespace ResearchLevel\n\nvariable {𝒳 : Type*}\n\ndef ShattersF (H : Set (𝒳 → Bool)) (S : Finset 𝒳) : Prop :=\n ∀ b : S → Bool, ∃ h ∈ H, ∀ x : S, h x.val = b x\n\nnoncomputable def VCDimF (H : Set (𝒳 → Bool)) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : ShattersF H S), (S.card : ℕ∞)\n\ndef combinedClass {k : ℕ} (G : (Fin k → Bool) → Bool)\n (F : Fin k → Set (𝒳 → Bool)) : Set (𝒳 → Bool) :=\n { g | ∃ f : Fin k → (𝒳 → Bool), (∀ j, f j ∈ F j) ∧ ∀ x, g x = G (fun j => f j x) }\n\ndef robustLossClass (H : Set (𝒳 → Bool)) (ρ : 𝒳 → Finset 𝒳) :\n Set (𝒳 × Bool → Bool) :=\n { g | ∃ h ∈ H, ∀ xy : 𝒳 × Bool,\n g xy = (ρ xy.1).sup (fun z => decide (h z ≠ xy.2)) }\n\ndef GammaShatters (γ : ℝ) (F : Set (𝒳 → ℝ)) (S : Finset 𝒳) : Prop :=\n ∃ r : 𝒳 → ℝ, ∀ b : 𝒳 → Bool, ∃ f ∈ F, ∀ x ∈ S,\n (b x = true → f x ≥ r x + γ) ∧ (b x = false → f x ≤ r x - γ)\n\ndef GammaShattersZero (γ : ℝ) (F : Set (𝒳 → ℝ)) (S : Finset 𝒳) : Prop :=\n ∀ b : 𝒳 → Bool, ∃ f ∈ F, ∀ x ∈ S,\n (b x = true → f x ≥ γ) ∧ (b x = false → f x ≤ - γ)\n\nnoncomputable def fatDim (γ : ℝ) (F : Set (𝒳 → ℝ)) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : GammaShatters γ F S), (S.card : ℕ∞)\n\nnoncomputable def fatDimZero (γ : ℝ) (F : Set (𝒳 → ℝ)) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : GammaShattersZero γ F S), (S.card : ℕ∞)\n\ndef shiftClass (F : Set (𝒳 → ℝ)) (r : 𝒳 → ℝ) : Set (𝒳 → ℝ) :=\n { g | ∃ f ∈ F, g = fun x => f x - r x }\n\ntheorem lemma16 {k : ℕ} (hk : 1 ≤ k) (G : (Fin k → Bool) → Bool)\n (F : Fin k → Set (𝒳 → Bool)) (d : Fin k → ℕ)\n (hd : ∀ j, VCDimF (F j) = (d j : ℕ∞)) :\n ∃ D : ℕ, VCDimF (combinedClass G F) = (D : ℕ∞) ∧\n (D : ℝ) ≤ 2 * (k : ℝ) * Real.logb 2 (3 * k) * ((∑ j, (d j : ℝ)) / k) := by\n sorry\n\ntheorem lemma1 :\n ∃ C : ℝ, 0 < C ∧\n ∀ (k d : ℕ) (H : Set (𝒳 → Bool)) (ρ : 𝒳 → Finset 𝒳),\n 2 ≤ k → (∀ x, (ρ x).Nonempty) → (∀ x, (ρ x).card ≤ k) → VCDimF H = (d : ℕ∞) →\n ∃ D : ℕ, VCDimF (robustLossClass H ρ) = (D : ℕ∞) ∧\n (D : ℝ) ≤ C * (d : ℝ) * Real.log (k : ℝ) := by\n sorry\n\ntheorem lemma14 {γ : ℝ} (hγ : 0 < γ) (F : Set (𝒳 → ℝ)) :\n ∃ r₀ : 𝒳 → ℝ, fatDim γ F = fatDimZero γ (shiftClass F r₀) ∧\n ∀ r : 𝒳 → ℝ, fatDimZero γ (shiftClass F r) ≤ fatDim γ F := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnamespace ResearchLevel\n\nvariable {𝒳 : Type*}\n\ndef ShattersF (H : Set (𝒳 → Bool)) (S : Finset 𝒳) : Prop :=\n ∀ b : S → Bool, ∃ h ∈ H, ∀ x : S, h x.val = b x\n\nnoncomputable def VCDimF (H : Set (𝒳 → Bool)) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : ShattersF H S), (S.card : ℕ∞)\n\ndef combinedClass {k : ℕ} (G : (Fin k → Bool) → Bool)\n (F : Fin k → Set (𝒳 → Bool)) : Set (𝒳 → Bool) :=\n { g | ∃ f : Fin k → (𝒳 → Bool), (∀ j, f j ∈ F j) ∧ ∀ x, g x = G (fun j => f j x) }\n\ndef robustLossClass (H : Set (𝒳 → Bool)) (ρ : 𝒳 → Finset 𝒳) :\n Set (𝒳 × Bool → Bool) :=\n { g | ∃ h ∈ H, ∀ xy : 𝒳 × Bool,\n g xy = (ρ xy.1).sup (fun z => decide (h z ≠ xy.2)) }\n\ndef GammaShatters (γ : ℝ) (F : Set (𝒳 → ℝ)) (S : Finset 𝒳) : Prop :=\n ∃ r : 𝒳 → ℝ, ∀ b : 𝒳 → Bool, ∃ f ∈ F, ∀ x ∈ S,\n (b x = true → f x ≥ r x + γ) ∧ (b x = false → f x ≤ r x - γ)\n\ndef GammaShattersZero (γ : ℝ) (F : Set (𝒳 → ℝ)) (S : Finset 𝒳) : Prop :=\n ∀ b : 𝒳 → Bool, ∃ f ∈ F, ∀ x ∈ S,\n (b x = true → f x ≥ γ) ∧ (b x = false → f x ≤ - γ)\n\nnoncomputable def fatDim (γ : ℝ) (F : Set (𝒳 → ℝ)) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : GammaShatters γ F S), (S.card : ℕ∞)\n\nnoncomputable def fatDimZero (γ : ℝ) (F : Set (𝒳 → ℝ)) : ℕ∞ :=\n ⨆ (S : Finset 𝒳) (_ : GammaShattersZero γ F S), (S.card : ℕ∞)\n\ndef shiftClass (F : Set (𝒳 → ℝ)) (r : 𝒳 → ℝ) : Set (𝒳 → ℝ) :=\n { g | ∃ f ∈ F, g = fun x => f x - r x }\n\nprivate lemma gammaShatters_mono {γ : ℝ} {F : Set (𝒳 → ℝ)}\n {S T : Finset 𝒳} (hT : GammaShatters γ F T) (hST : S ⊆ T) :\n GammaShatters γ F S := by\n rcases hT with ⟨r, hr⟩\n refine ⟨r, fun b => ?_⟩\n obtain ⟨f, hf, hfb⟩ := hr b\n exact ⟨f, hf, fun x hx => hfb x (hST hx)⟩\n\nprivate lemma gammaShattersZero_shift_iff {γ : ℝ} {F : Set (𝒳 → ℝ)}\n {S : Finset 𝒳} (r : 𝒳 → ℝ) :\n GammaShattersZero γ (shiftClass F r) S ↔\n ∀ b : 𝒳 → Bool, ∃ f ∈ F, ∀ x ∈ S,\n (b x = true → f x ≥ r x + γ) ∧\n (b x = false → f x ≤ r x - γ) := by\n constructor\n · intro h b\n obtain ⟨g, ⟨f, hf, rfl⟩, hgb⟩ := h b\n refine ⟨f, hf, fun x hx => ?_⟩\n have hx' := hgb x hx\n constructor\n · intro hb\n have hx'' := hx'.1 hb\n dsimp only at hx''\n linarith\n · intro hb\n have hx'' := hx'.2 hb\n dsimp only at hx''\n linarith\n · intro h b\n obtain ⟨f, hf, hfb⟩ := h b\n refine ⟨fun x => f x - r x, ⟨f, hf, rfl⟩, fun x hx => ?_⟩\n have hx' := hfb x hx\n constructor\n · intro hb\n have hx'' := hx'.1 hb\n dsimp only\n linarith\n · intro hb\n have hx'' := hx'.2 hb\n dsimp only\n linarith\n\nprivate lemma fatDimZero_shift_le {γ : ℝ} (F : Set (𝒳 → ℝ)) (r : 𝒳 → ℝ) :\n fatDimZero γ (shiftClass F r) ≤ fatDim γ F := by\n rw [fatDimZero, fatDim]\n refine iSup_le fun S => iSup_le fun hS => ?_\n have hS' : GammaShatters γ F S :=\n ⟨r, (gammaShattersZero_shift_iff r).mp hS⟩\n exact le_iSup_of_le S (le_iSup_of_le hS' (le_refl _))\n\nprivate lemma exists_shift_of_fatDim_ne_top {γ : ℝ} (F : Set (𝒳 → ℝ))\n (hfin : fatDim γ F ≠ ⊤) :\n ∃ r : 𝒳 → ℝ, fatDimZero γ (shiftClass F r) = fatDim γ F := by\n classical\n let I := {S : Finset 𝒳 // GammaShatters γ F S}\n have hrewrite : fatDim γ F = ⨆ i : I, (i.1.card : ℕ∞) := by\n rw [fatDim, iSup_subtype']\n cases isEmpty_or_nonempty I with\n | inl hempty =>\n let r : 𝒳 → ℝ := fun _ => 0\n have hdim : fatDim γ F = 0 := by\n rw [hrewrite]\n apply le_antisymm\n · refine iSup_le fun i => ?_\n exact isEmptyElim i\n · exact bot_le\n refine ⟨r, le_antisymm (fatDimZero_shift_le F r) ?_⟩\n rw [hdim]\n exact bot_le\n | inr hnonempty =>\n have hlt : (⨆ i : I, (i.1.card : ℕ∞)) < ⊤ := by\n rw [← hrewrite]\n exact lt_top_iff_ne_top.mpr hfin\n obtain ⟨i, hi⟩ := ENat.exists_eq_iSup_of_lt_top hlt\n obtain ⟨r, hr⟩ := i.2\n have hi0 : GammaShattersZero γ (shiftClass F r) i.1 :=\n (gammaShattersZero_shift_iff r).mpr hr\n refine ⟨r, le_antisymm (fatDimZero_shift_le F r) ?_⟩\n rw [hrewrite, ← hi]\n exact le_iSup_of_le i.1 (le_iSup_of_le hi0 (le_refl _))\n\nprivate lemma exists_disjoint_gammaShattered_of_top {γ : ℝ}\n (F : Set (𝒳 → ℝ)) (hinf : fatDim γ F = ⊤)\n (U : Finset 𝒳) (n : ℕ) :\n ∃ S : Finset 𝒳,\n GammaShatters γ F S ∧ Disjoint S U ∧ S.card = n := by\n classical\n have hlt : (↑(U.card + n) : ℕ∞) < fatDim γ F := by\n rw [hinf]\n exact ENat.coe_lt_top _\n rw [fatDim, lt_iSup_iff] at hlt\n obtain ⟨T, hlt⟩ := hlt\n rw [lt_iSup_iff] at hlt\n obtain ⟨hT, hcard⟩ := hlt\n have hcard' : U.card + n < T.card := ENat.coe_lt_coe.mp hcard\n have hinter : (U ∩ T).card ≤ U.card :=\n Finset.card_le_card Finset.inter_subset_left\n have hdiff : n ≤ (T \\ U).card := by\n rw [Finset.card_sdiff]\n omega\n obtain ⟨S, hST, hScard⟩ := Finset.exists_subset_card_eq hdiff\n refine ⟨S, gammaShatters_mono hT (hST.trans Finset.sdiff_subset), ?_, hScard⟩\n rw [Finset.disjoint_left]\n intro x hxS hxU\n exact (Finset.mem_sdiff.mp (hST hxS)).2 hxU\n\nprivate lemma exists_shift_of_fatDim_eq_top {γ : ℝ} (F : Set (𝒳 → ℝ))\n (hinf : fatDim γ F = ⊤) :\n ∃ r : 𝒳 → ℝ, fatDimZero γ (shiftClass F r) = fatDim γ F := by\n classical\n let pick (U : Finset 𝒳) (n : ℕ) : Finset 𝒳 :=\n Classical.choose (exists_disjoint_gammaShattered_of_top F hinf U n)\n have hpick (U : Finset 𝒳) (n : ℕ) :\n GammaShatters γ F (pick U n) ∧\n Disjoint (pick U n) U ∧ (pick U n).card = n :=\n Classical.choose_spec (exists_disjoint_gammaShattered_of_top F hinf U n)\n let A : ℕ → Finset 𝒳 := fun n =>\n Nat.rec ∅ (fun m U => U ∪ pick U (m + 1)) n\n let B : ℕ → Finset 𝒳 := fun n => pick (A n) (n + 1)\n have hA_succ (n : ℕ) : A (n + 1) = A n ∪ B n := by\n simp only [A, B, Nat.rec_add_one]\n have hB (n : ℕ) :\n GammaShatters γ F (B n) ∧\n Disjoint (B n) (A n) ∧ (B n).card = n + 1 := by\n exact hpick (A n) (n + 1)\n have hA_step (n : ℕ) : A n ⊆ A (n + 1) := by\n rw [hA_succ]\n exact Finset.subset_union_left\n have hA_mono : Monotone A := monotone_nat_of_le_succ hA_step\n have hB_subset_A {m n : ℕ} (hmn : m < n) : B m ⊆ A n := by\n have hm : B m ⊆ A (m + 1) := by\n rw [hA_succ]\n exact Finset.subset_union_right\n exact hm.trans (hA_mono (Nat.succ_le_iff.mpr hmn))\n have hB_pairwise : Pairwise fun m n => Disjoint (B m) (B n) := by\n intro m n hmn\n rcases Nat.lt_or_gt_of_ne hmn with hlt | hgt\n · exact (Finset.disjoint_of_subset_right (hB_subset_A hlt) (hB n).2.1).symm\n · exact Finset.disjoint_of_subset_right (hB_subset_A hgt) (hB m).2.1\n let q : ℕ → 𝒳 → ℝ := fun n => Classical.choose (hB n).1\n have hq (n : ℕ) :\n ∀ b : 𝒳 → Bool, ∃ f ∈ F, ∀ x ∈ B n,\n (b x = true → f x ≥ q n x + γ) ∧\n (b x = false → f x ≤ q n x - γ) :=\n Classical.choose_spec (hB n).1\n let idx : 𝒳 → ℕ := fun x =>\n if hx : ∃ n, x ∈ B n then Nat.find hx else 0\n have hidx (n : ℕ) {x : 𝒳} (hx : x ∈ B n) : idx x = n := by\n have hex : ∃ m, x ∈ B m := ⟨n, hx⟩\n have hmem : x ∈ B (Nat.find hex) := Nat.find_spec hex\n have heq : Nat.find hex = n := by\n by_contra hne\n exact (Finset.disjoint_left.mp (hB_pairwise hne)) hmem hx\n simpa only [idx, dif_pos hex] using heq\n let r : 𝒳 → ℝ := fun x => q (idx x) x\n have hzero (n : ℕ) :\n GammaShattersZero γ (shiftClass F r) (B n) := by\n apply (gammaShattersZero_shift_iff r).mpr\n intro b\n obtain ⟨f, hf, hfb⟩ := hq n b\n refine ⟨f, hf, fun x hx => ?_⟩\n simpa only [r, hidx n hx] using hfb x hx\n have hztop : fatDimZero γ (shiftClass F r) = ⊤ := by\n by_contra hne\n obtain ⟨m, hm⟩ := ENat.ne_top_iff_exists.mp hne\n have hle : (↑((B m).card) : ℕ∞) ≤\n fatDimZero γ (shiftClass F r) :=\n le_iSup_of_le (B m) (le_iSup_of_le (hzero m) (le_refl _))\n rw [(hB m).2.2, ← hm] at hle\n have hbad : m + 1 ≤ m := ENat.coe_le_coe.mp hle\n omega\n exact ⟨r, hztop.trans hinf.symm⟩\n\nprivate noncomputable def boolTrace (H : Set (𝒳 → Bool)) (S : Finset 𝒳) :\n Finset (Finset S) := by\n classical\n exact Finset.univ.filter fun T =>\n ∃ h ∈ H, ∀ x : S, (x ∈ T ↔ h x.1 = true)\n\nprivate lemma mem_boolTrace (H : Set (𝒳 → Bool)) (S : Finset 𝒳) (T : Finset S) :\n T ∈ boolTrace H S ↔ ∃ h ∈ H, ∀ x : S, (x ∈ T ↔ h x.1 = true) := by\n classical\n simp [boolTrace]\n\nprivate lemma shattersF_of_trace_shatters [DecidableEq 𝒳]\n (H : Set (𝒳 → Bool)) (S : Finset 𝒳)\n (T : Finset S) (hT : (boolTrace H S).Shatters T) :\n ShattersF H (T.map ⟨Subtype.val, Subtype.val_injective⟩) := by\n classical\n intro b\n let c : S → Bool := fun x =>\n if hx : x ∈ T then\n b ⟨x.1, Finset.mem_map.mpr ⟨x, hx, rfl⟩⟩\n else false\n let P : Finset S := T.filter fun x => c x = true\n have hPT : P ⊆ T := Finset.filter_subset _ _\n obtain ⟨V, hV, hinter⟩ := hT hPT\n obtain ⟨h, hh, hreal⟩ := (mem_boolTrace H S V).mp hV\n refine ⟨h, hh, fun y => ?_⟩\n obtain ⟨x, hxT, hxy⟩ := Finset.mem_map.mp y.2\n let xu : ↥(T.map ⟨Subtype.val, Subtype.val_injective⟩) :=\n ⟨x.1, Finset.mem_map.mpr ⟨x, hxT, rfl⟩⟩\n have hxuy : xu = y := Subtype.ext hxy\n subst y\n have hmem : x ∈ V ↔ c x = true := by\n have heq := congrArg (fun W : Finset S => x ∈ W) hinter\n apply iff_of_eq\n simpa only [Finset.mem_inter, hxT, true_and, P, Finset.mem_filter] using heq\n have hb : h x.1 = true ↔ b xu = true := by\n rw [← hreal x, hmem]\n simp only [c, dif_pos hxT]\n have harg :\n (⟨x.1, Finset.mem_map.mpr ⟨x, hxT, rfl⟩⟩ :\n ↥(T.map ⟨Subtype.val, Subtype.val_injective⟩)) = xu := by\n apply Subtype.ext\n rfl\n rw [harg]\n cases hhx : h x.1 <;> cases hbx : b xu <;> simp_all\n\nprivate lemma trace_vcDim_le [DecidableEq 𝒳]\n (H : Set (𝒳 → Bool)) (S : Finset 𝒳) (d : ℕ)\n (hd : VCDimF H = (d : ℕ∞)) : (boolTrace H S).vcDim ≤ d := by\n unfold Finset.vcDim\n apply Finset.sup_le\n intro T hT\n have hsh := shattersF_of_trace_shatters H S T (Finset.mem_shatterer.mp hT)\n have hle :\n (↑((T.map ⟨Subtype.val, Subtype.val_injective⟩).card) : ℕ∞) ≤\n VCDimF H :=\n le_iSup_of_le (T.map ⟨Subtype.val, Subtype.val_injective⟩)\n (le_iSup_of_le hsh (le_refl _))\n rw [hd] at hle\n rw [Finset.card_map] at hle\n exact ENat.coe_le_coe.mp hle\n\nprivate lemma sum_choose_le_exp (N d : ℕ) (hd : 1 ≤ d) (hdN : d ≤ N) :\n ((∑ i ∈ Finset.Iic d, N.choose i : ℕ) : ℝ) ≤\n (Real.exp 1 * (N : ℝ) / (d : ℝ)) ^ d := by\n have hdR : 0 < (d : ℝ) := by positivity\n have hN : 1 ≤ N := hd.trans hdN\n have hNR : 0 < (N : ℝ) := by positivity\n let x : ℝ := (d : ℝ) / (N : ℝ)\n have hx : 0 < x := div_pos hdR hNR\n have hxle : x ≤ 1 := (div_le_one hNR).2 (by exact_mod_cast hdN)\n have hfirst :\n (∑ i ∈ Finset.Iic d, (N.choose i : ℝ)) ≤\n x⁻¹ ^ d * ∑ i ∈ Finset.Iic d, (N.choose i : ℝ) * x ^ i := by\n rw [Finset.mul_sum]\n apply Finset.sum_le_sum\n intro i hi\n have hid : i ≤ d := Finset.mem_Iic.mp hi\n have hpow : x ^ d ≤ x ^ i :=\n pow_le_pow_of_le_one hx.le hxle hid\n have hone : 1 ≤ x⁻¹ ^ d * x ^ i := by\n calc\n 1 = x⁻¹ ^ d * x ^ d := by\n rw [← mul_pow, inv_mul_cancel₀ hx.ne']\n simp\n _ ≤ x⁻¹ ^ d * x ^ i :=\n mul_le_mul_of_nonneg_left hpow (by positivity)\n calc\n (N.choose i : ℝ) = 1 * (N.choose i : ℝ) := by ring\n _ ≤ (x⁻¹ ^ d * x ^ i) * (N.choose i : ℝ) :=\n mul_le_mul_of_nonneg_right hone (by positivity)\n _ = x⁻¹ ^ d * ((N.choose i : ℝ) * x ^ i) := by ring\n have hsubset : Finset.Iic d ⊆ Finset.range (N + 1) := by\n intro i hi\n rw [Finset.mem_range]\n exact Nat.lt_succ_of_le ((Finset.mem_Iic.mp hi).trans hdN)\n have hsecond :\n (∑ i ∈ Finset.Iic d, (N.choose i : ℝ) * x ^ i) ≤\n ∑ i ∈ Finset.range (N + 1), (N.choose i : ℝ) * x ^ i := by\n exact Finset.sum_le_sum_of_subset_of_nonneg hsubset (by\n intro i hi hit\n positivity)\n have hbinom :\n (∑ i ∈ Finset.range (N + 1), (N.choose i : ℝ) * x ^ i) =\n (x + 1) ^ N := by\n simpa [mul_comm] using (add_pow x 1 N).symm\n have hexp : (x + 1) ^ N ≤ Real.exp (N * x) := by\n calc\n (x + 1) ^ N ≤ (Real.exp x) ^ N :=\n pow_le_pow_left₀ (by linarith [hx]) (Real.add_one_le_exp x) N\n _ = Real.exp (N * x) := (Real.exp_nat_mul x N).symm\n rw [Nat.cast_sum]\n calc\n (∑ i ∈ Finset.Iic d, (N.choose i : ℝ))\n ≤ x⁻¹ ^ d * ∑ i ∈ Finset.Iic d, (N.choose i : ℝ) * x ^ i := hfirst\n _ ≤ x⁻¹ ^ d * ∑ i ∈ Finset.range (N + 1), (N.choose i : ℝ) * x ^ i := by\n gcongr\n _ = x⁻¹ ^ d * (x + 1) ^ N := by rw [hbinom]\n _ ≤ x⁻¹ ^ d * Real.exp (N * x) := by gcongr\n _ = (Real.exp 1 * (N : ℝ) / (d : ℝ)) ^ d := by\n have hNx : (N : ℝ) * x = d := by\n dsimp [x]\n field_simp\n rw [hNx, ← Real.exp_one_pow]\n rw [← mul_pow]\n congr 1\n dsimp [x]\n field_simp\n\nprivate lemma growth_lt_two_pow (k m s : ℕ) (hk : 1 ≤ k) (hs : 1 ≤ s)\n (hlarge : 2 * Real.logb 2 (3 * (k : ℝ)) * (s : ℝ) < (m : ℝ)) :\n (Real.exp 1 * ((k * m : ℕ) : ℝ) / (s : ℝ)) ^ s < (2 : ℝ) ^ m := by\n have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk\n have hkpos : (0 : ℝ) < k := lt_of_lt_of_le zero_lt_one hkR\n have hsR : (0 : ℝ) < s := by positivity\n have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num)\n have h3k : 0 < (3 : ℝ) * k := mul_pos (by norm_num) hkpos\n let L : ℝ := Real.logb 2 (3 * (k : ℝ))\n have hL : 0 < L := by\n dsimp [L, Real.logb]\n exact div_pos (Real.log_pos (by nlinarith)) hlog2\n let a0 : ℝ := 2 * L\n let a : ℝ := (m : ℝ) / (s : ℝ)\n have ha : a0 < a := by\n apply (lt_div_iff₀ hsR).2\n simpa only [a0, a] using hlarge\n have ha0 : 0 < a0 := by dsimp [a0]; positivity\n have ha_pos : 0 < a := ha0.trans ha\n have hpowL : (2 : ℝ) ^ L = 3 * (k : ℝ) := by\n exact Real.rpow_logb (by norm_num) (by norm_num) h3k\n have hpow_a0 : (2 : ℝ) ^ a0 = (3 * (k : ℝ)) ^ 2 := by\n rw [show a0 = L + L by simp [a0]; ring, Real.rpow_add (by norm_num), hpowL]\n ring\n have helog : Real.exp 1 * Real.log (3 * (k : ℝ)) ≤ 3 * (k : ℝ) := by\n have h := Real.exp_one_mul_le_exp (x := Real.log (3 * (k : ℝ)))\n rwa [Real.exp_log h3k] at h\n have hlog2lower : (2 : ℝ) / 3 < Real.log 2 := by\n nlinarith [Real.log_two_gt_d9]\n have hbase_num : Real.exp 1 * (k : ℝ) * a0 < (3 * (k : ℝ)) ^ 2 := by\n have hleft :\n 2 * (k : ℝ) * (Real.exp 1 * Real.log (3 * (k : ℝ))) ≤\n 2 * (k : ℝ) * (3 * (k : ℝ)) :=\n mul_le_mul_of_nonneg_left helog (by positivity)\n have hright :\n 6 * (k : ℝ) ^ 2 < 9 * (k : ℝ) ^ 2 * Real.log 2 := by\n have hk2 : 0 < 9 * (k : ℝ) ^ 2 := by positivity\n nlinarith [mul_lt_mul_of_pos_left hlog2lower hk2]\n have hdiv :\n (2 * Real.exp 1 * (k : ℝ) * Real.log (3 * (k : ℝ))) /\n Real.log 2 < 9 * (k : ℝ) ^ 2 := by\n apply (div_lt_iff₀ hlog2).2\n nlinarith\n dsimp [a0, L, Real.logb]\n convert hdiv using 1 <;> ring\n have hbase : Real.exp 1 * (k : ℝ) * a0 < (2 : ℝ) ^ a0 := by\n rwa [hpow_a0]\n let t : ℝ := a / a0\n have ht : 1 < t := (lt_div_iff₀ ha0).2 (by simpa [t] using ha)\n have htpos : 0 < t := zero_lt_one.trans ht\n have ha0log : 1 ≤ a0 * Real.log 2 := by\n have hlogmono : Real.log 2 ≤ Real.log (3 * (k : ℝ)) := by\n apply Real.log_le_log (by norm_num)\n nlinarith\n have htwo : 1 < 2 * Real.log 2 := by\n nlinarith [Real.log_two_gt_d9]\n dsimp [a0, L, Real.logb]\n field_simp\n nlinarith\n have hlogt : Real.log t < a0 * Real.log 2 * (t - 1) := by\n have h₁ := Real.log_lt_sub_one_of_pos htpos ht.ne'\n have h₂ : t - 1 ≤ a0 * Real.log 2 * (t - 1) :=\n (le_mul_iff_one_le_left (by linarith)).2 ha0log\n exact h₁.trans_le h₂\n have ht_rpow : t < (2 : ℝ) ^ (a - a0) := by\n calc\n t = Real.exp (Real.log t) := (Real.exp_log htpos).symm\n _ < Real.exp (a0 * Real.log 2 * (t - 1)) := Real.exp_lt_exp.mpr hlogt\n _ = (2 : ℝ) ^ (a - a0) := by\n rw [Real.rpow_def_of_pos (by norm_num)]\n congr 1\n dsimp [t]\n field_simp\n have hmain : Real.exp 1 * (k : ℝ) * a < (2 : ℝ) ^ a := by\n have ha_eq : a = a0 * t := by\n dsimp [t]\n field_simp\n rw [ha_eq]\n calc\n Real.exp 1 * (k : ℝ) * (a0 * t) =\n (Real.exp 1 * (k : ℝ) * a0) * t := by ring\n _ < (2 : ℝ) ^ a0 * (2 : ℝ) ^ (a - a0) :=\n mul_lt_mul hbase ht_rpow.le htpos (Real.rpow_pos_of_pos (by norm_num) _).le\n _ = (2 : ℝ) ^ (a0 + (a - a0)) :=\n (Real.rpow_add (by norm_num) _ _).symm\n _ = (2 : ℝ) ^ (a0 * t) := by rw [← ha_eq]; ring\n have hbase_eq :\n Real.exp 1 * (((k * m : ℕ) : ℝ)) / (s : ℝ) =\n Real.exp 1 * (k : ℝ) * a := by\n dsimp [a]\n push_cast\n ring\n rw [hbase_eq]\n have hp := pow_lt_pow_left₀ hmain (by positivity) (by omega : s ≠ 0)\n calc\n (Real.exp 1 * (k : ℝ) * a) ^ s < ((2 : ℝ) ^ a) ^ s := hp\n _ = (2 : ℝ) ^ (a * (s : ℝ)) := by\n rw [Real.rpow_mul (by norm_num), Real.rpow_natCast]\n _ = (2 : ℝ) ^ m := by\n rw [show a * (s : ℝ) = (m : ℝ) by dsimp [a]; field_simp]\n exact Real.rpow_natCast 2 m\n\nprivate lemma labels_le_prod_trace {k : ℕ}\n (G : (Fin k → Bool) → Bool) (F : Fin k → Set (𝒳 → Bool))\n (S : Finset 𝒳) (hS : ShattersF (combinedClass G F) S) :\n 2 ^ S.card ≤ ∏ j, (boolTrace (F j) S).card := by\n classical\n let P := (j : Fin k) → ↥(boolTrace (F j) S)\n have hex (b : S → Bool) :\n ∃ p : P, ∀ x : S,\n b x = G (fun j => decide (x ∈ (p j).1)) := by\n obtain ⟨g, hg, hgb⟩ := hS b\n obtain ⟨f, hf, hgf⟩ := hg\n let p : P := fun j =>\n ⟨Finset.univ.filter fun x : S => f j x.1 = true,\n (mem_boolTrace (F j) S _).mpr ⟨f j, hf j, by simp⟩⟩\n refine ⟨p, fun x => ?_⟩\n rw [← hgb x, hgf x]\n congr 2\n funext j\n dsimp [p]\n simp only [Finset.mem_filter, Finset.mem_univ, true_and]\n cases hfx : f j x.1 <;> simp_all\n let φ : (S → Bool) → P := fun b => Classical.choose (hex b)\n have hφ (b : S → Bool) :\n ∀ x : S, b x = G (fun j => decide (x ∈ (φ b j).1)) :=\n Classical.choose_spec (hex b)\n have hφinj : Function.Injective φ := by\n intro b c hbc\n funext x\n rw [hφ b x, hφ c x, hbc]\n have hc := Fintype.card_le_of_injective φ hφinj\n simpa only [P, Fintype.card_fun, Fintype.card_bool, Fintype.card_coe,\n Fintype.card_pi] using hc\n\nprivate lemma prod_shatterer_le_sum_choose [DecidableEq 𝒳] {k : ℕ}\n (F : Fin k → Set (𝒳 → Bool)) (d : Fin k → ℕ)\n (hd : ∀ j, VCDimF (F j) = (d j : ℕ∞)) (S : Finset 𝒳) :\n (∏ j, (boolTrace (F j) S).shatterer.card) ≤\n ∑ i ∈ Finset.Iic (∑ j, d j), (k * S.card).choose i := by\n classical\n let A : Fin k → Finset (Finset S) := fun j => (boolTrace (F j) S).shatterer\n let P := (j : Fin k) → ↥(A j)\n let tag : P → Finset ((j : Fin k) × S) := fun p =>\n Finset.univ.sigma fun j => (p j).1\n have htag_inj : Function.Injective tag := by\n intro p q hpq\n funext j\n apply Subtype.ext\n ext x\n have hx := congrArg (fun W : Finset ((j : Fin k) × S) => Sigma.mk j x ∈ W) hpq\n apply iff_of_eq\n simpa only [tag, Finset.mem_sigma, Finset.mem_univ, true_and] using hx\n let J : Finset (Finset ((j : Fin k) × S)) := Finset.univ.image tag\n have hJcard : J.card = ∏ j, (A j).card := by\n calc\n J.card = (Finset.univ : Finset P).card := by\n exact Finset.card_image_of_injective _ htag_inj\n _ = Fintype.card P := Finset.card_univ\n _ = ∏ j, (A j).card := by simp only [P, Fintype.card_pi, Fintype.card_coe]\n have htag_card (p : P) : (tag p).card = ∑ j, ((p j).1.card) := by\n simp [tag]\n have hJmem (T : Finset ((j : Fin k) × S)) (hT : T ∈ J) :\n T.card ≤ ∑ j, d j := by\n simp only [J, Finset.mem_image] at hT\n obtain ⟨p, hp, rfl⟩ := hT\n rw [htag_card]\n apply Finset.sum_le_sum\n intro j hj\n exact (Finset.mem_shatterer.mp (p j).2).card_le_vcDim.trans\n (trace_vcDim_le (F j) S (d j) (hd j))\n have hJvc : J.vcDim ≤ ∑ j, d j := by\n unfold Finset.vcDim\n apply Finset.sup_le\n intro T hT\n obtain ⟨U, hUJ, hTU⟩ := (Finset.mem_shatterer.mp hT).exists_superset\n exact (Finset.card_le_card hTU).trans (hJmem U hUJ)\n calc\n (∏ j, (boolTrace (F j) S).shatterer.card) = J.card := by\n rw [hJcard]\n _ ≤ J.shatterer.card := Finset.card_le_card_shatterer J\n _ ≤ ∑ i ∈ Finset.Iic J.vcDim,\n (Fintype.card ((j : Fin k) × S)).choose i :=\n Finset.card_shatterer_le_sum_vcDim\n _ ≤ ∑ i ∈ Finset.Iic (∑ j, d j),\n (Fintype.card ((j : Fin k) × S)).choose i := by\n exact Finset.sum_le_sum_of_subset (Finset.Iic_subset_Iic.mpr hJvc)\n _ = ∑ i ∈ Finset.Iic (∑ j, d j), (k * S.card).choose i := by\n simp [Fintype.card_sigma]\n\nprivate lemma combined_shattered_card_count {k : ℕ}\n (G : (Fin k → Bool) → Bool) (F : Fin k → Set (𝒳 → Bool))\n (d : Fin k → ℕ) (hd : ∀ j, VCDimF (F j) = (d j : ℕ∞))\n (S : Finset 𝒳) (hS : ShattersF (combinedClass G F) S) :\n 2 ^ S.card ≤\n ∑ i ∈ Finset.Iic (∑ j, d j), (k * S.card).choose i := by\n classical\n calc\n 2 ^ S.card ≤ ∏ j, (boolTrace (F j) S).card :=\n labels_le_prod_trace G F S hS\n _ ≤ ∏ j, (boolTrace (F j) S).shatterer.card := by\n apply Finset.prod_le_prod\n · intro j hj\n exact Nat.zero_le _\n · intro j hj\n exact Finset.card_le_card_shatterer _\n _ ≤ ∑ i ∈ Finset.Iic (∑ j, d j), (k * S.card).choose i :=\n prod_shatterer_le_sum_choose F d hd S\n\nprivate lemma card_real_le_of_two_pow_le_sum_choose (k m s : ℕ) (hk : 1 ≤ k)\n (hcount : 2 ^ m ≤ ∑ i ∈ Finset.Iic s, (k * m).choose i) :\n (m : ℝ) ≤ 2 * Real.logb 2 (3 * (k : ℝ)) * (s : ℝ) := by\n by_cases hs0 : s = 0\n · subst s\n have hm0 : m = 0 := by\n by_contra hm\n have hmpos : 0 < m := Nat.pos_of_ne_zero hm\n have htwo : 2 ≤ 2 ^ m := Nat.le_pow hmpos\n have hiic : Finset.Iic (0 : ℕ) = {0} := by\n ext i\n simp\n rw [hiic] at hcount\n simp only [Finset.sum_singleton, Nat.choose_zero_right] at hcount\n omega\n subst m\n norm_num\n have hs : 1 ≤ s := Nat.one_le_iff_ne_zero.mpr hs0\n have hkpos : 0 < k := lt_of_lt_of_le Nat.zero_lt_one hk\n have hmkm : m ≤ k * m := Nat.le_mul_of_pos_left m hkpos\n have hlogb : 1 ≤ Real.logb 2 (3 * (k : ℝ)) := by\n calc\n 1 = Real.logb 2 2 := (Real.logb_self_eq_one (by norm_num)).symm\n _ ≤ Real.logb 2 (3 * (k : ℝ)) := by\n apply Real.logb_le_logb_of_le (by norm_num) (by norm_num)\n have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk\n nlinarith\n by_cases hskm : s ≤ k * m\n · have hbinom := sum_choose_le_exp (k * m) s hs hskm\n have hp : (2 : ℝ) ^ m ≤\n ((∑ i ∈ Finset.Iic s, (k * m).choose i : ℕ) : ℝ) := by\n exact_mod_cast hcount\n have hp' : (2 : ℝ) ^ m ≤\n (Real.exp 1 * ((k * m : ℕ) : ℝ) / (s : ℝ)) ^ s :=\n hp.trans hbinom\n by_contra hnot\n have hlarge :\n 2 * Real.logb 2 (3 * (k : ℝ)) * (s : ℝ) < (m : ℝ) :=\n lt_of_not_ge hnot\n exact (not_lt_of_ge hp') (growth_lt_two_pow k m s hk hs hlarge)\n · have hms : m < s := hmkm.trans_lt (lt_of_not_ge hskm)\n have hC : 1 ≤ 2 * Real.logb 2 (3 * (k : ℝ)) := by nlinarith\n have hmsR : (m : ℝ) ≤ (s : ℝ) := by exact_mod_cast hms.le\n nlinarith [mul_nonneg (sub_nonneg.mpr hC) (Nat.cast_nonneg s)]\n\nprivate lemma combined_shattered_card_real_le {k : ℕ} (hk : 1 ≤ k)\n (G : (Fin k → Bool) → Bool) (F : Fin k → Set (𝒳 → Bool))\n (d : Fin k → ℕ) (hd : ∀ j, VCDimF (F j) = (d j : ℕ∞))\n (S : Finset 𝒳) (hS : ShattersF (combinedClass G F) S) :\n (S.card : ℝ) ≤\n 2 * (k : ℝ) * Real.logb 2 (3 * k) * ((∑ j, (d j : ℝ)) / k) := by\n have hsimple : (S.card : ℝ) ≤\n 2 * Real.logb 2 (3 * (k : ℝ)) * ((∑ j, d j : ℕ) : ℝ) :=\n card_real_le_of_two_pow_le_sum_choose k S.card (∑ j, d j) hk\n (combined_shattered_card_count G F d hd S hS)\n have hkR : (k : ℝ) ≠ 0 := by positivity\n rw [Nat.cast_sum] at hsimple\n convert hsimple using 1 <;> field_simp <;> ring\n\ntheorem lemma16 {k : ℕ} (hk : 1 ≤ k) (G : (Fin k → Bool) → Bool)\n (F : Fin k → Set (𝒳 → Bool)) (d : Fin k → ℕ)\n (hd : ∀ j, VCDimF (F j) = (d j : ℕ∞)) :\n ∃ D : ℕ, VCDimF (combinedClass G F) = (D : ℕ∞) ∧\n (D : ℝ) ≤ 2 * (k : ℝ) * Real.logb 2 (3 * k) * ((∑ j, (d j : ℝ)) / k) := by\n classical\n let B : ℝ :=\n 2 * (k : ℝ) * Real.logb 2 (3 * k) * ((∑ j, (d j : ℝ)) / k)\n have hB : 0 ≤ B := by\n have hkone : (1 : ℝ) ≤ k := by exact_mod_cast hk\n have hkR : (0 : ℝ) < k := by positivity\n have hlog : 0 ≤ Real.logb 2 (3 * (k : ℝ)) := by\n exact Real.logb_nonneg (by norm_num) (by nlinarith)\n dsimp [B]\n positivity\n have hcard (S : Finset 𝒳) (hS : ShattersF (combinedClass G F) S) :\n (S.card : ℝ) ≤ B := by\n exact combined_shattered_card_real_le hk G F d hd S hS\n have hdimle : VCDimF (combinedClass G F) ≤ (⌈B⌉₊ : ℕ∞) := by\n rw [VCDimF]\n refine iSup_le fun S => iSup_le fun hS => ?_\n apply ENat.coe_le_coe.mpr\n exact_mod_cast (hcard S hS).trans (Nat.le_ceil B)\n have hfin : VCDimF (combinedClass G F) ≠ ⊤ :=\n (hdimle.trans_lt (ENat.coe_lt_top _)).ne\n obtain ⟨D, hD⟩ := ENat.ne_top_iff_exists.mp hfin\n let I := {S : Finset 𝒳 // ShattersF (combinedClass G F) S}\n have hrewrite : VCDimF (combinedClass G F) =\n ⨆ i : I, (i.1.card : ℕ∞) := by\n rw [VCDimF, iSup_subtype']\n refine ⟨D, hD.symm, ?_⟩\n cases isEmpty_or_nonempty I with\n | inl hempty =>\n have hdim0 : VCDimF (combinedClass G F) = 0 := by\n rw [hrewrite]\n apply le_antisymm\n · refine iSup_le fun i => isEmptyElim i\n · exact bot_le\n have hD0 : D = 0 := by\n apply ENat.coe_inj.mp\n simpa using hD.trans hdim0\n rw [hD0]\n norm_num\n simpa only [B] using hB\n | inr hnonempty =>\n have hlt : (⨆ i : I, (i.1.card : ℕ∞)) < ⊤ := by\n rw [← hrewrite]\n exact lt_top_iff_ne_top.mpr hfin\n obtain ⟨i, hi⟩ := ENat.exists_eq_iSup_of_lt_top hlt\n have hDi : D = i.1.card := by\n apply ENat.coe_inj.mp\n rw [hD, hrewrite, ← hi]\n rw [hDi]\n exact hcard i.1 i.2\n\nprivate lemma robust_labels_le_trace [DecidableEq 𝒳]\n (H : Set (𝒳 → Bool)) (ρ : 𝒳 → Finset 𝒳)\n (S : Finset (𝒳 × Bool)) (hS : ShattersF (robustLossClass H ρ) S) :\n let Z := S.biUnion fun xy => ρ xy.1\n 2 ^ S.card ≤ (boolTrace H Z).card := by\n classical\n let Z : Finset 𝒳 := S.biUnion fun xy => ρ xy.1\n let P := ↥(boolTrace H Z)\n let recon : P → 𝒳 → Bool := fun p z =>\n if hz : z ∈ Z then decide (⟨z, hz⟩ ∈ p.1) else false\n have hex (b : S → Bool) :\n ∃ p : P, ∀ xy : S,\n b xy = (ρ xy.1.1).sup (fun z => decide (recon p z ≠ xy.1.2)) := by\n obtain ⟨g, hg, hgb⟩ := hS b\n obtain ⟨h, hh, hgdef⟩ := hg\n let p : P :=\n ⟨Finset.univ.filter fun z : Z => h z.1 = true,\n (mem_boolTrace H Z _).mpr ⟨h, hh, by simp⟩⟩\n refine ⟨p, fun xy => ?_⟩\n rw [← hgb xy, hgdef xy.1]\n apply Finset.sup_congr rfl\n intro z hz\n have hzZ : z ∈ Z := Finset.mem_biUnion.mpr ⟨xy.1, xy.2, hz⟩\n have hr : recon p z = h z := by\n dsimp [recon, p]\n simp only [dif_pos hzZ, Finset.mem_filter, Finset.mem_univ, true_and]\n cases hhz : h z <;> simp_all\n rw [hr]\n let φ : (S → Bool) → P := fun b => Classical.choose (hex b)\n have hφ (b : S → Bool) :\n ∀ xy : S,\n b xy = (ρ xy.1.1).sup (fun z => decide (recon (φ b) z ≠ xy.1.2)) :=\n Classical.choose_spec (hex b)\n have hφinj : Function.Injective φ := by\n intro b c hbc\n funext xy\n rw [hφ b xy, hφ c xy, hbc]\n have hc := Fintype.card_le_of_injective φ hφinj\n simpa only [P, Fintype.card_fun, Fintype.card_bool, Fintype.card_coe] using hc\n\nprivate lemma robust_shattered_card_count [DecidableEq 𝒳]\n (k d : ℕ) (H : Set (𝒳 → Bool)) (ρ : 𝒳 → Finset 𝒳)\n (hρ : ∀ x, (ρ x).card ≤ k) (hd : VCDimF H = (d : ℕ∞))\n (S : Finset (𝒳 × Bool)) (hS : ShattersF (robustLossClass H ρ) S) :\n 2 ^ S.card ≤ ∑ i ∈ Finset.Iic d, (k * S.card).choose i := by\n classical\n let Z : Finset 𝒳 := S.biUnion fun xy => ρ xy.1\n have hZ : Z.card ≤ k * S.card := by\n calc\n Z.card ≤ ∑ xy ∈ S, (ρ xy.1).card := Finset.card_biUnion_le\n _ ≤ ∑ xy ∈ S, k := by\n apply Finset.sum_le_sum\n intro xy hxy\n exact hρ xy.1\n _ = k * S.card := by simp [mul_comm]\n calc\n 2 ^ S.card ≤ (boolTrace H Z).card := robust_labels_le_trace H ρ S hS\n _ ≤ (boolTrace H Z).shatterer.card := Finset.card_le_card_shatterer _\n _ ≤ ∑ i ∈ Finset.Iic (boolTrace H Z).vcDim,\n (Fintype.card Z).choose i := Finset.card_shatterer_le_sum_vcDim\n _ ≤ ∑ i ∈ Finset.Iic d, (Fintype.card Z).choose i := by\n exact Finset.sum_le_sum_of_subset\n (Finset.Iic_subset_Iic.mpr (trace_vcDim_le H Z d hd))\n _ ≤ ∑ i ∈ Finset.Iic d, (k * S.card).choose i := by\n apply Finset.sum_le_sum\n intro i hi\n rw [Fintype.card_coe]\n exact Nat.choose_le_choose i hZ\n\nprivate lemma two_logb_three_mul_le_ten_log (k : ℕ) (hk : 2 ≤ k) :\n 2 * Real.logb 2 (3 * (k : ℝ)) ≤ 10 * Real.log (k : ℝ) := by\n have hkR : (2 : ℝ) ≤ k := by exact_mod_cast hk\n have hkpos : (0 : ℝ) < k := by positivity\n have hlogk : 0 < Real.log (k : ℝ) := Real.log_pos (by linarith)\n have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num)\n have hthree : Real.log 3 ≤ 2 * Real.log (k : ℝ) := by\n calc\n Real.log 3 ≤ Real.log ((k : ℝ) ^ 2) := by\n apply Real.log_le_log (by norm_num)\n nlinarith\n _ = 2 * Real.log (k : ℝ) := by rw [Real.log_pow]; norm_num\n have hmul : Real.log (3 * (k : ℝ)) ≤ 3 * Real.log (k : ℝ) := by\n rw [Real.log_mul (by norm_num) hkpos.ne']\n linarith\n have hlog2lower : (3 : ℝ) / 5 ≤ Real.log 2 := by\n nlinarith [Real.log_two_gt_d9]\n dsimp [Real.logb]\n rw [show 2 * (Real.log (3 * (k : ℝ)) / Real.log 2) =\n (2 * Real.log (3 * (k : ℝ))) / Real.log 2 by ring]\n apply (div_le_iff₀ hlog2).2\n have hleft : 2 * Real.log (3 * (k : ℝ)) ≤\n 6 * Real.log (k : ℝ) := by linarith\n have hright : 6 * Real.log (k : ℝ) ≤\n 10 * Real.log (k : ℝ) * Real.log 2 := by\n nlinarith [mul_nonneg (sub_nonneg.mpr hlog2lower) hlogk.le]\n linarith\n\nprivate lemma robust_shattered_card_real_le (k d : ℕ) (hk : 2 ≤ k)\n (H : Set (𝒳 → Bool)) (ρ : 𝒳 → Finset 𝒳)\n (hρ : ∀ x, (ρ x).card ≤ k) (hd : VCDimF H = (d : ℕ∞))\n (S : Finset (𝒳 × Bool)) (hS : ShattersF (robustLossClass H ρ) S) :\n (S.card : ℝ) ≤ 10 * (d : ℝ) * Real.log (k : ℝ) := by\n classical\n have hbasic : (S.card : ℝ) ≤\n 2 * Real.logb 2 (3 * (k : ℝ)) * (d : ℝ) :=\n card_real_le_of_two_pow_le_sum_choose k S.card d (hk.trans' (by omega))\n (robust_shattered_card_count k d H ρ hρ hd S hS)\n calc\n (S.card : ℝ) ≤ 2 * Real.logb 2 (3 * (k : ℝ)) * (d : ℝ) := hbasic\n _ ≤ (10 * Real.log (k : ℝ)) * (d : ℝ) :=\n mul_le_mul_of_nonneg_right (two_logb_three_mul_le_ten_log k hk)\n (Nat.cast_nonneg d)\n _ = 10 * (d : ℝ) * Real.log (k : ℝ) := by ring\n\ntheorem lemma1 :\n ∃ C : ℝ, 0 < C ∧\n ∀ (k d : ℕ) (H : Set (𝒳 → Bool)) (ρ : 𝒳 → Finset 𝒳),\n 2 ≤ k → (∀ x, (ρ x).Nonempty) → (∀ x, (ρ x).card ≤ k) → VCDimF H = (d : ℕ∞) →\n ∃ D : ℕ, VCDimF (robustLossClass H ρ) = (D : ℕ∞) ∧\n (D : ℝ) ≤ C * (d : ℝ) * Real.log (k : ℝ) := by\n refine ⟨10, by norm_num, ?_⟩\n intro k d H ρ hk hρ_nonempty hρ hd\n classical\n let B : ℝ := 10 * (d : ℝ) * Real.log (k : ℝ)\n have hkR : (1 : ℝ) < k := by exact_mod_cast hk\n have hB : 0 ≤ B := by\n dsimp [B]\n positivity\n have hcard (S : Finset (𝒳 × Bool))\n (hS : ShattersF (robustLossClass H ρ) S) : (S.card : ℝ) ≤ B := by\n exact robust_shattered_card_real_le k d hk H ρ hρ hd S hS\n have hdimle : VCDimF (robustLossClass H ρ) ≤ (⌈B⌉₊ : ℕ∞) := by\n rw [VCDimF]\n refine iSup_le fun S => iSup_le fun hS => ?_\n apply ENat.coe_le_coe.mpr\n exact_mod_cast (hcard S hS).trans (Nat.le_ceil B)\n have hfin : VCDimF (robustLossClass H ρ) ≠ ⊤ :=\n (hdimle.trans_lt (ENat.coe_lt_top _)).ne\n obtain ⟨D, hD⟩ := ENat.ne_top_iff_exists.mp hfin\n let I := {S : Finset (𝒳 × Bool) // ShattersF (robustLossClass H ρ) S}\n have hrewrite : VCDimF (robustLossClass H ρ) =\n ⨆ i : I, (i.1.card : ℕ∞) := by\n rw [VCDimF, iSup_subtype']\n refine ⟨D, hD.symm, ?_⟩\n cases isEmpty_or_nonempty I with\n | inl hempty =>\n have hdim0 : VCDimF (robustLossClass H ρ) = 0 := by\n rw [hrewrite]\n apply le_antisymm\n · refine iSup_le fun i => isEmptyElim i\n · exact bot_le\n have hD0 : D = 0 := by\n apply ENat.coe_inj.mp\n simpa using hD.trans hdim0\n rw [hD0]\n norm_num\n simpa only [B] using hB\n | inr hnonempty =>\n have hlt : (⨆ i : I, (i.1.card : ℕ∞)) < ⊤ := by\n rw [← hrewrite]\n exact lt_top_iff_ne_top.mpr hfin\n obtain ⟨i, hi⟩ := ENat.exists_eq_iSup_of_lt_top hlt\n have hDi : D = i.1.card := by\n apply ENat.coe_inj.mp\n rw [hD, hrewrite, ← hi]\n rw [hDi]\n exact hcard i.1 i.2\n\ntheorem lemma14 {γ : ℝ} (hγ : 0 < γ) (F : Set (𝒳 → ℝ)) :\n ∃ r₀ : 𝒳 → ℝ, fatDim γ F = fatDimZero γ (shiftClass F r₀) ∧\n ∀ r : 𝒳 → ℝ, fatDimZero γ (shiftClass F r) ≤ fatDim γ F := by\n have hle : ∀ r : 𝒳 → ℝ,\n fatDimZero γ (shiftClass F r) ≤ fatDim γ F := fun r =>\n fatDimZero_shift_le F r\n by_cases htop : fatDim γ F = ⊤\n · obtain ⟨r₀, hr₀⟩ := exists_shift_of_fatDim_eq_top F htop\n exact ⟨r₀, hr₀.symm, hle⟩\n · obtain ⟨r₀, hr₀⟩ := exists_shift_of_fatDim_ne_top F htop\n exact ⟨r₀, hr₀.symm, hle⟩\n\nend ResearchLevel\n"} +{"id": "v23-21-0152", "source": "Research-level", "targets": [{"label": "Theorem 1", "decls": ["asymptotic_bias_one_node"], "statement": "Theorem 1 (Asymptotic Bias of the Posterior Mode of 1-Node BNN+LV) Fix any $W \\in \\mathbb{R}$ and any bounded prior $p_{W}(W)$ on W. Suppose that inputs $\\{x_{1},\\ldots,x_{N}\\}$ are sampled i.i.d from $p_{x}$ with finite first and second moments (mean $\\mu_{x}$ and variance $\\sigma_{x}^{2}$ ) , and that $\\{z_{1},\\dots,z_{N}\\}$ are sampled i.i.d from $\\mathcal{N}(0,\\sigma_{z}^{2})$ , where $\\mu_{x}^{2}+ \\sigma_{x}^{2}> \\sigma_{z}^{2}$ . Suppose $p_{W}(W)>0$ . For every $C$ with $\\frac{\\sigma_{x}^{2}+ \\mu_{x}^{2}- \\sigma_{z}^{2}}{\\sigma_{x}^{2}+ \\mu_{x}^{2}+ \\sigma_{z}^{2}}< C < 1$ such that $p_{W}(\\widehat{W}^{(C)})>0$ , the probability that the scaled values $(\\widehat{W}^{(C)},\\{\\widehat{z}_{n}^{(C)}\\}_{n=1}^{N})$ are more likely than $\\left(W,\\{z_{n}\\}_{n=1}^{N}\\right)$ under the posterior approaches 1 as $N \\to \\infty$", "context_ids": ["v23-21-0152:ctx1", "v23-21-0152:ctx2", "v23-21-0152:ctx3", "v23-21-0152:ctx4", "v23-21-0152:ctx5", "v23-21-0152:ctx8"], "sibling_refs": [], "topic_domain": "Deep Learning Theory", "topic_subtopic": "Bayesian Neural Networks"}, {"label": "Theorem 2", "decls": ["asymptotic_bias_one_layer"], "statement": "Theorem 2 (Asymptotic Bias of the Posterior Mode of 1-Layer BNN+LV) Fix any set of parameters W and any bounded prior $p_{W}(W)$ on W with $p_{W}(W)>0$ . Suppose that $\\{x_{1},\\ldots,x_{N}\\}$ is sampled i.i.d from $p_{x}$ , with finite first and second moments (the dth marginal having mean $\\mu_{x_{d}}$ and variance $\\sigma_{x_{d}}^{2}$ ), and that $\\{z_{1},\\dots,z_{N}\\}$ are sampled i.i.d from $\\mathcal{N}(0,\\sigma_{z}^{2}\\cdot I)$ . There exists an alternate set of parameters $\\left(\\widehat{W},\\{\\widehat{z}_{n}\\}_{n=1}^{N}\\right)$ with $p_{W}(\\widehat{W})>0$ and $\\widehat{z}_{n}= T z_{n}- T x_{n}$ , where $T=\\mathrm{diag}(t)$ with $0 < | t_{d}| < \\sqrt{\\frac{\\sigma_{z}^{2}}{\\mu_{x_{d}}^{2}+ \\sigma_{x_{d}}^{2}+ \\sigma_{z}^{2}}}$ for every $d$ , such that the probability that these alternative parameters are valued as more likely than $\\left(W,\\{z_{n}\\}_{n=1}^{N}\\right)$ under the posterior approaches 1 as $N \\to \\infty$", "context_ids": ["v23-21-0152:ctx1", "v23-21-0152:ctx2", "v23-21-0152:ctx3", "v23-21-0152:ctx6", "v23-21-0152:ctx7", "v23-21-0152:ctx8"], "sibling_refs": [], "topic_domain": "Deep Learning Theory", "topic_subtopic": "Bayesian Neural Networks"}, {"label": "Concentration crux (Cantelli step, Appendix B.1/B.2)", "decls": ["bias_concentration_cantelli"], "statement": "Concentration crux of Theorems 1 and 2 (Appendix B.1/B.2, the step where Cantelli's inequality is applied), for the concrete per-sample log-prior-ratio average $R_N$. Throughout, $p_z$ is the Gaussian latent prior and $z$ is independent of $x$. (Theorem 1, 1-node model, Appendix B.1.) Suppose that inputs $x_1, x_2, \\ldots$ are sampled i.i.d. from $p_x$ with finite first and second moments $\\mu_x, \\sigma_x^2$, and that $z_1, z_2, \\ldots$ are sampled i.i.d. from $\\mathcal{N}(0, \\sigma_z^2)$, where $\\mu_x^2 + \\sigma_x^2 > \\sigma_z^2$. Let $C$ satisfy $0 < \\frac{\\sigma_x^2 + \\mu_x^2 - \\sigma_z^2}{\\sigma_x^2 + \\mu_x^2 + \\sigma_z^2} < C < 1$, let $\\widehat{z}_n^{(C)} = (C-1)x_n + C z_n$, and let $R_N^{(C)} = \\frac{1}{N} \\sum_{n=1}^{N} \\big(\\log p_z(\\widehat{z}_n^{(C)}) - \\log p_z(z_n)\\big)$. Then $\\Pr[R_N^{(C)} > 0] \\to 1$ as $N \\to \\infty$. (Theorem 2, 1-layer model, Appendix B.2.) Suppose that $x_1, x_2, \\ldots \\in \\mathbb{R}^D$ are sampled i.i.d. from $p_x$ with finite first and second moments, the $d$th marginal of $x$ having mean $\\mu_{x_d}$ and variance $\\sigma_{x_d}^2$, and that $z_1, z_2, \\ldots$ are sampled i.i.d. from $\\mathcal{N}(0, \\sigma_z^2 \\cdot I)$. Let $T = \\mathrm{diag}(t)$ with $0 < |t_d| < \\sqrt{\\frac{\\sigma_z^2}{\\mu_{x_d}^2 + \\sigma_{x_d}^2 + \\sigma_z^2}}$ for every $d$, let $\\widehat{z}_n = T z_n - T x_n$, and let $R_N = \\frac{1}{N} \\sum_{n=1}^{N} \\big(\\log p_z(\\widehat{z}_n) - \\log p_z(z_n)\\big)$. Then $\\Pr[R_N > 0] \\to 1$ as $N \\to \\infty$. (In the paper, the condition on $C$, resp. on $t_d$, is what makes $\\mathbb{E}[R_N] > 0$, after which Cantelli's inequality gives $\\Pr[R_N < 0] \\to 0$.)", "context_ids": ["v23-21-0152:ctx1", "v23-21-0152:ctx2", "v23-21-0152:ctx3", "v23-21-0152:ctx4", "v23-21-0152:ctx5", "v23-21-0152:ctx6", "v23-21-0152:ctx7", "v23-21-0152:ctx8", "v23-21-0152:ctx9"], "sibling_refs": [], "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "### Proof of Theorem 1\n\nWe assume the model in Equation 15. We denote the prior on $W$ as $p_{W}$ and suppose that it is bounded, we denote the prior on $z$ as $p_{z}$ , and we suppose that $p_{x}$, the distribution over the input $x$, has bounded first and second moments $\\mu_{x}$ and $\\sigma_{x}^{2}.$ For any non-zero constant $0 < C < 1$ , we define\n\n$$\n\\widehat W^{(C)}=W/C,~\\widehat z_{n}^{(C)}=(C-1)x_{n}+Cz_{n},\n$$\n\nand we define $D_{N}^{(C)}$ to be the difference between the scaled parameters $(\\widehat{W}^{(C)},\\widehat{z}_{1}^{(C)},\\dots\\widehat{z}_{N}^{(C)})$ and the ground-truth parameters $(W,z_{1},\\dots z_{N})$ under the joint posterior log $p(W,Z|\\mathcal{D})$\n\nFor any set of parameters $(W,z_{1},\\dots z_{N})$ , we show that we can find alternate parameters $(\\widehat{W}^{(C)},\\widehat{z}_{1}^{(C)},\\ldots\\widehat{z}_{N}^{(C)})$ , that are scored as more likely under the log-posterior log $p(W,\\{z_{n}\\}|\\mathcal{D})$ To do this, we first show that the alternative parameters are scored as equally likely under the log-likelihood, and then we show that the alternate parameters are scored as more likely under the log-prior.\n\nSince we have that\n\n$$\n\\operatorname*{max}\\left\\{W^{\\mathrm{true}}(x+z_{n}^{\\mathrm{true}}),\\alpha W^{\\mathrm{true}}(x+z_{n}^{\\mathrm{true}})\\right\\}=\\operatorname*{max}\\left\\{\\widehat{W}^{(C)}(x+\\widehat{z}_{n}^{(C)}),\\alpha\\widehat{W}^{(C)}(x+\\widehat{z}_{n}^{(C)})\\right\\},\n$$\n\nwe see that the alternate parameters are as likely as the original parameters under the likelihood; that is,\n\n$$\n\\prod_{n}p(y_{n}|x_{n},z_{n}^{\\mathrm{true}},W^{\\mathrm{true}})=\\prod_{n}p\\left(y_{n}|x_{n},\\widehat{z}_{n}^{(C)},\\widehat{W}^{(C)}\\right).\n$$\n\nSince the likelihood under both sets of parameters is equal, the difference between the log-posterior, $D_{N}^{(C)}$ , is simply the difference of the two sets of parameters under the log-prior:\n\n$$\nD_{N}^{(C)}=\\log p_{W}(\\widehat{W}^{(C)})-\\log p_{W}(W)+\\sum_{n=1}^{N}\\log p_{z}(\\widehat{z}_{n}^{(C)})-\\log p_{z}(z_{n}).\n$$\n\nWe now show that as $N \\to \\infty$ , the probability that $(\\widehat{W}^{(C)},\\widehat{z}_{1}^{(C)},\\dots\\widehat{z}_{N}^{(C)})$ is valued higher than $(W,z_{1},\\dots z_{N})$ in the posterior approaches 1. That is,\n\n$$\n\\operatorname*{lim}_{N\\to\\infty}\\operatorname*{Pr}\\left[D_{N}^{(C)}>0\\right]=\\operatorname*{lim}_{N\\to\\infty}\\mathbb{E}_{p_{x}p_{z}}\\left[\\mathbb{I}(D_{N}^{(C)}>0)\\right]=1.\n$$\n\nSince we are only interested in the sign of $D_{N}^{(C)}$ , we demonstrate, equivalently, that\n\n$$\n\\operatorname*{lim}_{N\\to\\infty}\\mathbb{E}_{p_{x}p_{z}}[\\mathbb{I}(\\frac{1}{N}\\cdot D_{N}^{(C)}>0)]=1 .\n$$\n\nExpanding $\\frac{1}{N}\\cdot D_{N}^{(C)}$ , we obtain\n\n$$\n\\frac{1}{N}\\cdot D_{N}^{(C)}=\\underbrace{\\frac{1}{N}\\cdot\\left(\\log p_{W}(\\widehat{W}^{(C)})-\\log p_{W}(W)\\right)}_{L_{N}^{(C)}}+\\underbrace{\\frac{1}{N}\\sum_{n=1}^{N}\\log p_{z}(\\widehat{z}_{n}^{(C)})-\\log p_{z}(z_{n})}_{R_{N}^{(C)}}.\n$$\n\nWe note that as $N \\to \\infty$ , the term $L_{N}^{(C)}$ approaches 0. Thus, it suffices to analyze the sign of $R_{N}^{(C)}$ ; that is, we compute $\\mathrm{Pr}[R_{N}^{(C)}>0]$\n\nLet $\\mathbb{E}\\left[R_{N}^{(C)}\\right]$ and $\\mathbb{V}\\left[R_{N}^{(C)}\\right]$ denote the mean and variance of the random variable $R_{N}^{(C)}$ We next show that $\\mathbb{E}\\left[R_{N}^{(C)}\\right]$ is positive, allowing us to use Cantelli's Inequality to bound the probability that $R_{N}^{(C)}$ is negative under $p_{x}$ and $p_{z}$ as follows:\n\n$$\n\\begin{array}{r l}&{\\operatorname*{Pr}\\left[R_{N}^{(C)}<0\\right]=\\operatorname*{Pr}\\left[R_{N}^{(C)}-\\mathbb{E}\\left[R_{N}^{(C)}\\right]< -\\mathbb{E}\\left[R_{N}^{(C)}\\right]\\right]}\\\\ &{\\qquad=1-\\operatorname*{Pr}\\left[R_{N}^{(C)}-\\mathbb{E}\\left[R_{N}^{(C)}\\right]\\geq-\\mathbb{E}\\left[R_{N}^{(C)}\\right]\\right]}\\\\ &{\\qquad\\leq\\frac{\\mathbb{V}\\left[R_{N}^{(C)}\\right]}{\\mathbb{V}\\left[R_{N}^{(C)}\\right]+\\mathbb{E}\\left[R_{N}^{(C)}\\right]^{2}}.}\\end{array}\n$$\n\nAs $N \\to \\infty$ , we show that this upper bound on $\\mathrm{Pr}\\left[R_{N}^{(C)}<0\\right]$ approaches 0.\n\nWe start by expanding $R_{N}^{(C)}$ as follows:\n\n$$\n\\begin{aligned}\nR_{N}^{(C)}&=\\frac{1}{N}\\sum_{n=1}^{N}\\log p_{z}(\\widehat{z}_{n}^{(C)})-\\log p_{z}(z_{n})\\\\\n&= -\\frac{1}{2\\sigma_{z}^{2}}\\cdot\\frac{1}{N}\\sum_{n=1}^{N}(\\widehat{z}_{n}^{(C)})^{2}-z_{n}^{2}\\\\\n&=\\frac{1}{2\\sigma_{z}^{2}}\\cdot\\frac{1}{N}\\sum_{n=1}^{N}z_{n}^{2}-(\\widehat{z}_{n}^{(C)})^{2}\\\\\n2\\sigma_{z}^{2}\\cdot R_{N}^{(C)}&=\\frac{1}{N}\\sum_{n=1}^{N}z_{n}^{2}-(\\widehat{z}_{n}^{(C)})^{2}\\\\\n&=\\frac{1}{N}\\sum_{n=1}^{N}z_{n}^{2}-((C-1)x_{n}+Cz_{n})^{2}\\\\\n&=\\frac{1}{N}\\sum_{n=1}^{N}(2C-C^{2}-1)\\cdot x_{n}^{2}+(1-C^{2})\\cdot z_{n}^{2}+(2C-2C^{2})\\cdot x_{n}z_{n}\\\\\n&=(2C-C^{2}-1)\\cdot\\frac{1}{N}\\sum_{n=1}^{N}x_{n}^{2}+(1-C^{2})\\cdot\\frac{1}{N}\\sum_{n=1}^{N}z_{n}^{2}+(2C-2C^{2})\\cdot\\frac{1}{N}\\sum_{n=1}^{N}x_{n}z_{n}\n\\end{aligned}\n$$\n\nThe variance of $R_{N}^{(C)}$ can be computed as follows:\n\n$$\n\\mathbb{V}\\left[R_{N}^{(C)}\\right]=\\frac{\\mathbb{V}\\left[R_{1}^{(C)}\\right]}{N}.\n$$\n\nTherefore, as N increases, the variance approaches 0 at a rate of $1 / N$\n\nThe mean of $R_{N}^{(C)}$ can be written as:\n\n$$\n\\begin{array}{r l}&{2\\sigma_{z}^{2}\\cdot\\mathbb{E}\\left[R_{N}^{(C)}\\right]=(2C-C^{2}-1)\\cdot\\mathbb{E}_{p_{x}}\\left[x^{2}\\right]+(1-C^{2})\\cdot\\mathbb{E}_{p_{z}}\\left[z^{2}\\right]+(2C-2C^{2})\\cdot\\mathbb{E}_{p_{x}p_{z}}\\left[xz\\right]}\\\\ &{\\qquad=(2C-C^{2}-1)\\cdot(\\sigma_{x}^{2}+\\mu_{x}^{2})+(1-C^{2})\\cdot\\sigma_{z}^{2}+(2C-2C^{2})\\cdot\\mu_{x}\\cdot 0}\\\\ &{\\qquad=(2C-C^{2}-1)\\cdot(\\sigma_{x}^{2}+\\mu_{x}^{2})+(1-C^{2})\\cdot\\sigma_{z}^{2}}\\end{array}\n$$\n\nThus, the mean is positive when\n\n$$\n0<\\frac{\\sigma_{x}^{2}+\\mu_{x}^{2}-\\sigma_{z}^{2}}{\\sigma_{x}^{2}+\\mu_{x}^{2}+\\sigma_{z}^{2}} \\sigma_{z}^{2}$\n\nNow, by Cantelli's Inequality, we have that:\n\n$$\n\\operatorname*{Pr}\\left[R_{N}^{(C)}<0\\right]\\leq\\frac{\\mathbb{V}\\left[R_{N}^{(C)}\\right]}{\\mathbb{V}\\left[R_{N}^{(C)}\\right]+\\mathbb{E}\\left[R_{N}^{(C)}\\right]^{2}}=\\frac{\\mathbb{V}\\left[R_{1}^{(C)}\\right]}{\\mathbb{V}\\left[R_{1}^{(C)}\\right]+N\\cdot\\mathbb{E}\\left[R_{N}^{(C)}\\right]^{2}},\n$$\n\nwhich shows that $\\mathrm{Pr}\\left[R_{N}^{(C)}<0\\right]$ approaches 0 as $N \\to \\infty$\n\n### Proof of Theorem 2\n\nThe proof follows in the same fashion as the one for Theorem 1. We assume the model in Equation 16. For a given $W$ ,let $\\widehat{W}$ denote the set $\\{\\widehat{W}^{x},\\widehat{W}^{z},W^{\\mathrm{out}},\\widehat{b}^{\\mathrm{hidden}},b^{\\mathrm{out}}\\}$ , where\n\n$$\n\\widehat{W}^{x}=W^{x}+W^{z}S,\\widehat{W}^{z}=R,\\widehat{z}=T z-T S x-U,\\widehat{b}^{\\mathrm{hidden}}=b+R U,\n$$\n\nfor any choice of diagonal matrix $S \\in \\mathbb{R}^{D \\times D}$ , vector $U \\in \\mathbb{R}^{D}$ , and any factorization $W^{z}= R T$ where $T \\in \\mathbb{R}^{D \\times D}$\n\nFor any set of parameters $(W,z_{1},\\dots z_{N})$ , we show that we can find alternate parameters $(\\widehat{W},\\widehat{z}_{1}\\ldots\\widehat{z}_{N})$ , that are scored as more likely under the log-posterior log $p(W,\\{z_{n}\\}|\\mathcal{D})$ . We define $D_{N}$ to be the difference between the scaled parameters $(\\widehat{W},\\widehat{z}_{1},\\ldots\\widehat{z}_{N})$ and the ground-truth parameters $(W,z_{1},\\dots z_{N})$ under the joint posterior log $p(W,Z|\\mathcal{D})$ . Since $f(x_{n},z_{n};W)=$ $f(x_{n},{\\widehat{z}}_{n};{\\widehat{W}})$ by construction, the alternate parameters are equally as likely as the original parameters under the likelihood: $p(y_{n}|x_{n},z_{n},W)=p(y_{n}|x_{n},\\widehat{z}_{n},\\widehat{W})$ . As such, $D_{N}$ is simply the difference of the two sets of parameters under the log-prior:\n\n$$\nD_{N}=\\log p_{W}(\\widehat{W})-\\log p_{W}(W)+\\sum_{n=1}^{N}\\log p_{z}(\\widehat{z}_{n})-\\log p_{z}(z_{n}).\n$$\n\nWe now show that as $N \\to \\infty$ , the probability that $(\\widehat{W},\\widehat{z}_{1},\\ldots\\widehat{z}_{N})$ is valued higher than $(W,z_{1},\\dots z_{N})$ in the posterior approaches 1. That is,\n\n$$\n\\operatorname*{lim}_{N\\to\\infty}\\operatorname*{Pr}\\left[D_{N}>0\\right]=\\operatorname*{lim}_{N\\to\\infty}\\mathbb{E}_{p_{x}p_{z}}\\left[\\mathbb{I}(D_{N}>0)\\right]=1.\n$$\n\nSince we are only interested in the sign of $D_{N}$ , we demonstrate, equivalently, that\n\n$$\n\\operatorname*{lim}_{N\\to\\infty}\\mathbb{E}_{p_{x}p_{z}}[\\mathbb{I}(\\frac{1}{N}\\cdot D_{N}>0)]=1 .\n$$\n\nExpanding $\\frac{1}{N}\\cdot D_{N}$ , we obtain\n\n$$\n\\frac{1}{N}\\cdot D_{N}=\\underbrace{\\frac{1}{N}\\cdot\\Big(\\log p_{W}(\\widehat{W})-\\log p_{W}(W)\\Big)}_{L_{N}}+\\underbrace{\\frac{1}{N}\\sum_{n=1}^{N}\\log p_{z}(\\widehat{z}_{n})-\\log p_{z}(z_{n})}_{R_{N}}.\n$$\n\nWe note that as $N \\to \\infty$ , the term $L_{N}$ approaches 0. Thus, it suffices to analyze the sign of $R_{N};$ that is, we compute $\\mathrm{Pr}[R_{N}>0]$\n\nLet diag(t) represent a diagonal matrix with diagonal elements $t_{1},\\ldots,t_{D}$ . For simplicity, we set $U=0,S=I,R=W^{z}T^{-1}$ and $T=\\mathrm{diag}(t)$ (where $t_{d}\\neq 0)$ , giving us:\n\n$$\n\\widehat{W}^{x}=W^{x}+W^{z},\\quad\\widehat{W}^{z}=W^{z}T^{-1},\\quad\\widehat{z}=T\\cdot z-T\\cdot x,\\quad\\widehat{b}^{\\mathrm{hidden}}=b .\n$$\n\nFollowing the proof for Theorem 1, it suffices to show that the mean of $R_{N}$ is positive and that the its variance approaches 0 at a rate of $1 / N$ in order to prove that $\\mathrm{Pr}\\left[R_{N}<0\\right]$ approaches 0 as $N \\to \\infty$\n\nFor this model, $R_{N}$ is defined as:\n\n$$\n\\begin{array}{c l}{\\displaystyle{R_{N}=\\frac{1}{N}\\sum_{n=1}^{N}\\log p_{z}(\\hat{z}_{n})-\\log p_{z}(z_{n})}}\\\\ {\\displaystyle{2\\sigma_{z}^{2}\\cdot R_{N}=\\frac{1}{N}\\sum_{n=1}^{N}z_{n}^{\\top}z_{n}-(Tz_{n}-Tx_{n})^{\\top}(Tz_{n}-Tx_{n})}}\\\\ {\\displaystyle{=\\frac{1}{N}\\sum_{n=1}^{N}\\sum_{d=1}^{D}-t_{d}^{2}\\cdot x_{n,d}^{2}+2t_{d}^{2}\\cdot x_{n,d}\\cdot z_{n,d}-t_{d}^{2}z_{n,d}^{2}+z_{n,d}^{2}}}\\\\ {\\displaystyle{=\\frac{1}{N}\\sum_{n=1}^{N}\\sum_{d=1}^{D}-t_{d}^{2}\\cdot x_{n,d}^{2}+2t_{d}^{2}\\cdot x_{n,d}\\cdot z_{n,d}+(1-t_{d}^{2})\\cdot z_{n,d}^{2}}}\\end{array}\n$$\n\nThe mean of $R_{N}$ can be computed as follows:\n\n$$\n\\begin{array}{l}{{\\displaystyle\\mathbb{E}\\left[R_{N}\\right]=\\sum_{d=1}^{D}-t_{d}^{2}\\cdot\\mathbb{E}_{p_{x_{d}}}\\left[x^{2}\\right]+2t_{d}^{2}\\cdot\\mathbb{E}_{p_{x_{d}}}\\left[x\\right]\\cdot\\mathbb{E}_{p_{z_{d}}}\\left[z\\right]+\\left(1-t_{d}^{2}\\right)\\cdot\\mathbb{E}_{p_{z_{d}}}\\left[z^{2}\\right]}}\\\\ {~}\\\\ {{\\displaystyle=\\sum_{d=1}^{D}-t_{d}^{2}\\cdot\\mathbb{E}_{p_{x_{d}}}\\left[x^{2}\\right]+2t_{d}^{2}\\cdot\\mathbb{E}_{p_{x_{d}}}\\left[x\\right]\\cdot 0+\\left(1-t_{d}^{2}\\right)\\cdot\\mathbb{E}_{p_{z_{d}}}\\left[z^{2}\\right]}}\\\\ {{\\displaystyle~}}\\\\ {{\\displaystyle=\\sum_{d=1}^{D}-t_{d}^{2}\\cdot\\left(\\mu_{x_{d}}^{2}+\\sigma_{x_{d}}^{2}\\right)+\\left(1-t_{d}^{2}\\right)\\cdot\\sigma_{z_{d}}^{2}}}\\end{array}\n$$\n\nwhere $p_{x_{d}}, p_{z_{d}}$ are the dth marginals of $p_{x}, p_{z}$ , and $\\mu_{x_{d}}, \\sigma_{x_{d}}^{2}$ are the mean and variance of the dth marginal of x. As such, for any $t_{d}$ that satisfies the following conditions,\n\n$$\n0 < | t_{d}| < \\sqrt{\\frac{\\sigma_{z}^{2}}{\\mu_{x_{d}}^{2}+ \\sigma_{x_{d}}^{2}+ \\sigma_{z}^{2}}},\n$$\n\n$\\mathbb{E}\\left[ R_{N}\\right]$ is positive. Just as in the proof for the 1-Node $\\mathrm{B N N + L V}$ , the variance of $R_{N}$ can be computed as follows:\n\n$$\n\\mathbb{V}\\left[ R_{N}\\right] = \\frac{\\mathbb{V}\\left[ R_{1}\\right]}{N}.\n$$\n\nTherefore, as N increases, the variance approaches 0 at a rate of $1 / N$ . Now, by Cantelli's Inequality, we have that:\n\n$$\n\\operatorname*{Pr}\\left[R_{N}<0\\right]\\leq\\frac{\\mathbb{V}\\left[R_{N}\\right]}{\\mathbb{V}\\left[R_{N}\\right]+\\mathbb{E}\\left[R_{N}\\right]^{2}}=\\frac{\\mathbb{V}\\left[R_{1}\\right]}{\\mathbb{V}\\left[R_{1}\\right]+N\\cdot\\mathbb{E}\\left[R_{N}\\right]^{2}},\n$$\n\nwhich shows that $\\mathrm{Pr}\\left[R_{N}^{(C)}<0\\right]$ approaches 0 as $N \\to \\infty$", "context": [{"id": "v23-21-0152:ctx1", "name": "Setup: data, BNN and BNN+LV model, joint posterior (Section 3, Eqs. 1-3)", "statement": "Let $\\mathcal{D}=\\{(x_{1},y_{1}),...(x_{N},y_{N})\\}$ be a data-set of N observations from the true data distribution $p(y|x)p(x)$ , in which each input $\\boldsymbol{x}_{n}\\in \\mathbb{R}^{D}$ is a D-dimensional vector and each output $y_{n}\\in \\mathbb{R}^{L}$ is L-dimensional. Let I denote the identity matrix and let capital letters denote sets of variables, e.g. $X = \\{x_{n}\\}_{n = 1}^{N}, Y = \\{y_{n}\\}_{n = 1}^{N}, Z = \\{z_{n}\\}_{n = 1}^{N}$ . See Appendix A for a summary of the notation.\n\nA Bayesian Neural Network (BNN). A BNN assumes a predictor of the form $y =$ $f(x;W)+\\epsilon$ , where f is a neural network parametrized by W and $\\epsilon\\sim\\mathcal{N}(0,\\sigma_{\\epsilon}^{2}\\cdot I)$ is a normally distributed noise variable. It places a prior p(W ) on the network parameters; given a data-set $\\mathcal{D},$ we can apply Bayesian inference to compute the posterior distribution $p(W|\\mathcal{D})$ over W or the posterior predictive distribution $p(\\boldsymbol{y}^{*}|\\boldsymbol{x}^{*},\\mathcal{D})$ of over outputs $y^{*}$ given a new input $x^{*}$ . As commonly done, we assume $p(W)=\\mathcal{N}(0,\\sigma_{w}^{2}\\cdot I)$\n\nA Bayesian Neural Network with Latent Variables (BNN+LV). A BNN+LV enables more flexible noise distributions for BNNs by introducing a latent variable $z_{n}\\sim\\mathcal{N}(0,\\sigma_{z}^{2}\\cdot I)$ for each observation $(x_{n},y_{n})$ (Depeweg et al., 2018). It assumes the following data generation process (Figure 1):\n\n$$\n\\begin{array}{l}{{W\\sim p(W),\\quad z_{n}\\sim p(z),\\quad\\epsilon_{n}\\sim\\mathcal{N}(0,\\sigma_{\\epsilon}^{2}\\cdot I),}}\\\\ {{y_{n}=f(x_{n},z_{n};W)+\\epsilon_{n},\\quad n=1,\\ldots,N.}}\\end{array}\\tag{1}\n$$\n\nIn this model, z is independent from $x,$ and can represent either white noise or meaningful latent explanatory variables. When $f$ is non-linear, BNN+LV is able to model heteroscedastic noise by transforming $z .$ Inference for BNN+LVs involves approximating the posterior distribution,\n\n$$\np(W,Z|\\mathcal D)\\propto p(W)\\cdot\\prod_{n}p(y_{n}|x_{n},z_{n},W)p(z_{n}),\\tag{2}\n$$\n\n(where $Z=\\{z_{1},\\ldots,z_{N}\\})$ , over both network weights W and the latent input $z_{n}$ for each observation $x_{n}$. When Z represents meaningful latent variables, we may infer the latent information $z_{n}$ for each input $x_{n}$ by marginalizing $p(W,Z|\\mathcal{D})$ over W. For a new input $x^{*}$ the posterior predictive is given by the expected likelihood under the posterior of $W$, and the prior of $z$ (Depeweg et al., 2018):\n\n$$\n\\begin{array}{l}{{p(y^{*}|x^{*},\\mathcal{D})=\\displaystyle\\int p(y^{*}|x^{*},W)p(W|\\mathcal{D})dW}}\\\\ {{\\displaystyle\\qquad=\\int\\int p(y^{*}|x^{*},z^{*},W)p(z^{*})dz^{*}p(W|\\mathcal{D})dW.}}\\end{array}\\tag{3}\n$$"}, {"id": "v23-21-0152:ctx2", "name": "Notation (Appendix A)", "statement": "
SymbolDefinition
NNumber of observations (or training points)
$(x_{n},y_{n})$ The nth observed input and output, where $x_{n}\\in$ $\\mathbb{R}^{D}, y_{n}\\in \\mathbb{R}^{L}$
$(x^{*},y^{*})$ A point from the test-set.
$z_{n}$ The latent code corresponding to the nth observation. Since the latent variables are sampled i.i.d from the prior, $p(z_{n})=p(z)$.
$z^{*}$ The latent code corresponding to $x^{*}$ . Again, $p(z^{*})=$ $p(z)$
$\\mathcal{D}$ $\\{(x_{n},y_{n})\\}_{n=1}^{N}$
$X$ $\\{x_{n}\\}_{n = 1}^{N}$
$Y$ $\\{y_{n}\\}_{n = 1}^{N}$
$Z$ $\\{z_{n}\\}_{n = 1}^{N}$
$p(y|x)p(x)$ or $p(y|x;W^{\\mathrm{true}})p(x)$ The ground-truth data-generating distribution (that generated $\\mathcal{D}$).
$f(\\cdot,\\cdot;W)$ A neural network $f$ parameterized by weights $W .$
$W$ The set of all neural network weights $w_{i}$
$p(W,Z|\\mathcal{D})$ The BNN+LV joint posterior (Equation 2).
$p(W|\\mathcal{D})$ The marginal posterior of the weights, $\\begin{array}{r}{\\int_{Z}p(W,Z|\\mathcal{D})dZ}\\end{array}$ (intractable).
$q_{\\phi}(Z,W|\\mathcal D)=q_{\\phi}(Z|\\mathcal D)q_{\\phi}(W|\\mathcal D)$ The mean-field variational approximation of the joint posterior (Equation 4), parameterized by φ.
$Z^{\\mathrm{MAP}},W^{\\mathrm{MAP}}$ The MAP of the true joint posterior: $Z^{\\mathrm{MAP}},W^{\\mathrm{MAP}}=$ $\\operatorname{argmax}_{Z,W}p(Z,W|\\mathcal{D})$
$Z^{\\mathrm{true}},W^{\\mathrm{true}}$ The ground-truth data-generating weights $W^{\\mathrm{true}}$ and latent codes $Z^{\\mathrm{true}}=\\{z_{n}^{\\mathrm{true}}\\}_{n=1}^{N}$ that produced the observed data.
$\\widehat{Z}, \\widehat{W}$ The alternative set of latent variables $\\widehat{Z}\\ = \\ \\{\\widehat{z}_{n}\\}_{n = 1}^{N}$ and weights, defined in Equation 8, that have a higher probability under the joint posterior.
$q_{\\phi}(z)$ The aggregated posterior (Equation 11).
$q_{\\phi}(z|x)$ The approximate posterior marginalized over y: $\\begin{array}{r}{\\int_{y}q_{\\phi}(z|x,y)p(y|x)dy}\\end{array}$ . Since we only observe one y for every x, we cannot obtain unbiased estimates of this distribution in practice.
"}, {"id": "v23-21-0152:ctx3", "name": "Section 4 preamble: well-specified model", "statement": "For intuition and clarity, we begin by characterizing likelihood non-identifiability and posterior bias for a single node of a BNN+LV and then generalize these results to a 1-layer $\\mathrm{B N N + L V}$ . We assume the model is well-specified."}, {"id": "v23-21-0152:ctx4", "name": "1-node non-identifiability: W/C and (C-1)x+Cz (Section 4.1)", "statement": "Non-Identifiability. Consider univariate output generated by a single hidden-node neural network with LeakyReLU activation. For simplicity, we study a case with zero network biases, unit output weights, and additive input noise:\n\n$$\nf(x,z;W)=\\operatorname*{max}\\left\\{W(x+z),\\alpha W(x+z)\\right\\},\n$$\n\nwhere $0 < \\alpha < 1$ . For any non-zero constant $C,$ the pair $\\widehat W^{(C)}=W/C,\\widehat z^{(C)}=(C-1)x+Cz$ reconstructs the observed data equally well:\n\n$$\n\\operatorname*{max}\\left\\{W(x+z),\\alpha W(x+z)\\right\\}=\\operatorname*{max}\\left\\{\\widehat{W}^{(C)}\\left(x+\\widehat{z}^{(C)}\\right),\\alpha\\widehat{W}^{(C)}\\left(x+\\widehat{z}^{(C)}\\right)\\right\\}.\n$$\n\nNow, suppose that the output is observed with Gaussian noise: $\\displaystyle y\\sim\\mathcal{N}(f(x,z;W),\\sigma_{\\epsilon}^{2})$ . Then the true values of the parameter W and the latent input noise z are equally likely as $\\widehat{W}^{(C)}$ and $\\widehat{z}^{(C)}$ under the likelihood: $p(y|f(x,z,W),\\sigma_{\\epsilon}^{2})=p(y|f(x,\\widehat{z}^{(C)},\\widehat{W}^{(C)}),\\sigma_{\\epsilon}^{2})$ . We show in Theorem 1 that for this model, the posterior over the model parameter and latent inputs W, Z is biased away from the ground-truth towards parameters that generalize poorly as the sample size grows, regardless of the choice of W prior."}, {"id": "v23-21-0152:ctx5", "name": "1-node model (Appendix B.1, Eq. 15)", "statement": "Consider univariate output generated by a single hidden-node neural network with LeakyReLU activation:\n\n$$\n\\begin{array}{l}{z\\sim\\mathcal{N}(0,\\sigma_{z}^{2})}\\\\ {\\epsilon\\sim\\mathcal{N}(0,\\sigma_{\\epsilon}^{2})}\\\\ {y=\\operatorname*{max}\\left\\{W(x+z),\\alpha W(x+z)\\right\\}+\\epsilon}\\end{array}\\tag{15}\n$$\n\nwhere α is a fixed constant in (0, 1)."}, {"id": "v23-21-0152:ctx6", "name": "1-layer non-identifiability (Section 4.2, Eq. 8)", "statement": "Non-Identifiability. Sources of non-identifiability increase when f is a neural network. Consider a single-output neural network, f, that takes as input x and z (represented as a concatenated vector in $\\mathbb{R}^{2 D})$ and has a single hidden layer containing H hidden nodes. At the output node, we fix the activation to be the identity. Thus, the activation of the output node is computed as\n\n$$\na^{\\mathrm{out}}=(a^{\\mathrm{hidden}})^{\\top}W^{\\mathrm{out}}+b^{\\mathrm{out}},\n$$\n\nwhere $W^{\\mathrm{out}}$ is a H-dimensional weight vector, $b^{\\mathrm{out}}$ is the bias and $a^{\\mathrm{hidden}}$ is the H-dimensional vector of activations of the hidden nodes. We can further expand $a^{\\mathrm{hidden}}$ as\n\n$$\na^{\\mathrm{hidden}}=g\\left(W^{x}x+W^{z}z+b^{\\mathrm{hidden}}\\right),\n$$\n\nwhere $W^{x}$ and $W^{z}$ are weight matrices in $\\mathbb{R}^{H \\times D}$ , $b^{\\mathrm{hidden}}$ is a H-dimensional bias vector and $g$ is the activation function, applied element-wise. We characterize ways that the models parameters and the latent input variables z are non-identifiable given a set of observed data. For any choice of diagonal matrix $S \\in \\mathbb{R}^{D \\times D}$ , vector $U \\in \\mathbb{R}^{D}$ , and any factorization $W^{z}= R T$ where T is in $\\mathbb{R}^{D \\times D}$ , we can express $a^{\\mathrm{hidden}}$ in two equivalent ways:\n\n$$\na^{\\mathrm{hidden}}=g\\left(W^{x}x+W^{z}z+b^{\\mathrm{hidden}}\\right)=g\\left(\\widehat{W}^{x}x+\\widehat{W}^{z}\\widehat{z}+\\widehat{b}^{\\mathrm{hidden}}\\right)\n$$\n\nby setting:\n\n$$\n\\widehat{W}^{x}=W^{x}+W^{z}S,\\widehat{W}^{z}=R,\\widehat{z}=T z-T S x-U,\\widehat{b}^{\\mathrm{hidden}}=b+R U .\\tag{8}\n$$\n\nSuppose that the output is observed with Gaussian noise: $\\displaystyle y\\sim\\mathcal{N}(f(x,z;W),\\sigma_{\\epsilon}^{2})$ , where W denotes the set of weights $(W^{\\mathrm{out}},W^{x},W^{z},b^{\\mathrm{out}},b^{\\mathrm{hidden}})$ . Then, by only observing outputs generated by this network given observed input, one cannot identify ground-truth parameter and latent variable values under the likelihood: $p(y|f(x,z,W),\\sigma_{\\epsilon}^{2})=p(y|f(x,\\widehat{z},\\widehat{W}),\\sigma_{\\epsilon}^{2})$ . Just like in the case of a network with a single node, we show in Theorem 2 that the joint posterior is biased away from the ground-truth parameters, regardless of the choice of weight prior."}, {"id": "v23-21-0152:ctx7", "name": "1-layer model (Appendix B.2, Eq. 16)", "statement": "Let W be the set of network weights $\\{W^{x},W^{z},W^{\\mathrm{out}},b^{\\mathrm{hidden}},b^{\\mathrm{out}}\\}$ . Consider a data-set generated from the following model:\n\n$$\n\\begin{array}{r}{\\begin{array}{c}{W\\sim p(W)}\\\\ {z\\sim\\mathcal{N}(0,\\sigma_{z}^{2}\\cdot I)}\\\\ {\\epsilon\\sim N(0,\\sigma_{\\epsilon}^{2})}\\\\ {a^{\\mathrm{hidden}}=g\\left(W^{x}x+W^{z}z+b^{\\mathrm{hidden}}\\right),}\\\\ {y=(a^{\\mathrm{hidden}})^{\\top}W^{\\mathrm{out}}+b^{\\mathrm{out}}+\\epsilon}\\end{array}}\\end{array}\\tag{16}\n$$"}, {"id": "v23-21-0152:ctx8", "name": "Generative modeling assumptions 1-2 (Section 4.3)", "statement": "Generally, when assuming a probabilistic model, we hope that in the limit of infinite data, inference recovers model parameters that satisfy our generative modeling assumptions. For example, when assuming a BNN, we hope that in the limit of infinite data, the MLE and MAP over the weights parameterize the true function that generated the data. For the BNN+LV model, however, the parameters given by the MAP of the joint posterior $W^{\\mathrm{MAP}},Z^{\\mathrm{MAP}}$ do not satisfy our generative modeling assumptions. To illustrate this, we compare $W^{\\mathrm{MAP}},Z^{\\mathrm{MAP}}$ with the ground-truth data generating parameters, $W^{\\mathrm{true}},Z^{\\mathrm{true}}$ ; under our ground-truth data-generating process from Equation 1, $Z^{\\mathrm{true}}$ satisfies two modeling assumptions:\n\nAssumption 1: $z^{\\mathrm{true}}$ is independent of x—that is, $p(z,x)$ factorizes.\n\nAssumption 2: $z^{\\mathrm{true}}$ is distributed like the prior $p(z)$"}, {"id": "v23-21-0152:ctx9", "name": "From the proof of Theorem 1 (the priors p_W, p_z and the quantity D_N^(C))", "statement": "We assume the model in Equation 15. We denote the prior on $W$ as $p_{W}$ and suppose that it is bounded, we denote the prior on $z$ as $p_{z}$ , and we suppose that $p_{x}$, the distribution over the input $x$, has bounded first and second moments $\\mu_{x}$ and $\\sigma_{x}^{2}.$ For any non-zero constant $0 < C < 1$ , we define\n\n$$\n\\widehat W^{(C)}=W/C,~\\widehat z_{n}^{(C)}=(C-1)x_{n}+Cz_{n},\n$$\n\nand we define $D_{N}^{(C)}$ to be the difference between the scaled parameters $(\\widehat{W}^{(C)},\\widehat{z}_{1}^{(C)},\\dots\\widehat{z}_{N}^{(C)})$ and the ground-truth parameters $(W,z_{1},\\dots z_{N})$ under the joint posterior log $p(W,Z|\\mathcal{D})$\n\nFor any set of parameters $(W,z_{1},\\dots z_{N})$ , we show that we can find alternate parameters $(\\widehat{W}^{(C)},\\widehat{z}_{1}^{(C)},\\ldots\\widehat{z}_{N}^{(C)})$ , that are scored as more likely under the log-posterior log $p(W,\\{z_{n}\\}|\\mathcal{D})$ To do this, we first show that the alternative parameters are scored as equally likely under the log-likelihood, and then we show that the alternate parameters are scored as more likely under the log-prior.\n\nSince we have that\n\n$$\n\\operatorname*{max}\\left\\{W^{\\mathrm{true}}(x+z_{n}^{\\mathrm{true}}),\\alpha W^{\\mathrm{true}}(x+z_{n}^{\\mathrm{true}})\\right\\}=\\operatorname*{max}\\left\\{\\widehat{W}^{(C)}(x+\\widehat{z}_{n}^{(C)}),\\alpha\\widehat{W}^{(C)}(x+\\widehat{z}_{n}^{(C)})\\right\\},\n$$\n\nwe see that the alternate parameters are as likely as the original parameters under the likelihood; that is,\n\n$$\n\\prod_{n}p(y_{n}|x_{n},z_{n}^{\\mathrm{true}},W^{\\mathrm{true}})=\\prod_{n}p\\left(y_{n}|x_{n},\\widehat{z}_{n}^{(C)},\\widehat{W}^{(C)}\\right).\n$$\n\nSince the likelihood under both sets of parameters is equal, the difference between the log-posterior, $D_{N}^{(C)}$ , is simply the difference of the two sets of parameters under the log-prior:\n\n$$\nD_{N}^{(C)}=\\log p_{W}(\\widehat{W}^{(C)})-\\log p_{W}(W)+\\sum_{n=1}^{N}\\log p_{z}(\\widehat{z}_{n}^{(C)})-\\log p_{z}(z_{n}).\n$$"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Filter Topology\n\nnamespace ResearchLevel\n\nnoncomputable def logPriorRatioZ (σz C x z : ℝ) : ℝ :=\n (z ^ 2 - ((C - 1) * x + C * z) ^ 2) / (2 * σz ^ 2)\n\nnoncomputable def Dseq1 {Ω : Type*} (Δw σz C : ℝ) (X Z : ℕ → Ω → ℝ)\n (N : ℕ) (ω : Ω) : ℝ :=\n Δw + ∑ n ∈ Finset.range N, logPriorRatioZ σz C (X n ω) (Z n ω)\n\nnoncomputable def logPriorRatioZ2 {D : ℕ} (σz : ℝ) (t x z : Fin D → ℝ) : ℝ :=\n (∑ d, ((z d) ^ 2 - (t d * (z d - x d)) ^ 2)) / (2 * σz ^ 2)\n\nnoncomputable def Dseq2 {Ω : Type*} {D : ℕ} (Δw σz : ℝ) (t : Fin D → ℝ)\n (X Z : ℕ → Ω → (Fin D → ℝ)) (N : ℕ) (ω : Ω) : ℝ :=\n Δw + ∑ n ∈ Finset.range N, logPriorRatioZ2 σz t (X n ω) (Z n ω)\n\ntheorem asymptotic_bias_one_node\n {Ω : Type*} [MeasureSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n (X Z : ℕ → Ω → ℝ)\n (μx σx σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X P) (hXid : ∀ n, IdentDistrib (X n) (X 0) P P)\n\n (hXint1 : Integrable (X 0) P) (hXint2 : Integrable (fun ω => (X 0 ω) ^ 2) P)\n (hμx : ∫ ω, X 0 ω ∂P = μx) (hσx : ∫ ω, (X 0 ω) ^ 2 ∂P = σx ^ 2 + μx ^ 2)\n\n (hZindep : iIndepFun Z P)\n (hZgauss : ∀ n, Measure.map (Z n) P = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) P)\n\n (hcond : σz ^ 2 < μx ^ 2 + σx ^ 2)\n\n (Δw : ℝ)\n\n (W : ℝ) (pW : ℝ → ℝ) (hpWbdd : ∃ M, ∀ w, pW w ≤ M) (hpWposW : 0 < pW W)\n (C : ℝ)\n (hClo : (σx ^ 2 + μx ^ 2 - σz ^ 2) / (σx ^ 2 + μx ^ 2 + σz ^ 2) < C)\n (hChi : C < 1)\n (hpWposWC : 0 < pW (W / C)) (hΔw : Δw = Real.log (pW (W / C)) - Real.log (pW W)) :\n Tendsto (fun N => P {ω | 0 < Dseq1 Δw σz C X Z N ω}) atTop (𝓝 1) := by\n sorry\n\ntheorem asymptotic_bias_one_layer\n {Ω : Type*} [MeasureSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {D : ℕ} (hD : 0 < D)\n (X Z : ℕ → Ω → (Fin D → ℝ))\n (μx σx : Fin D → ℝ) (σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X P) (hXid : ∀ n, IdentDistrib (X n) (X 0) P P)\n\n (hXint : ∀ d, Integrable (fun ω => X 0 ω d) P ∧\n Integrable (fun ω => (X 0 ω d) ^ 2) P)\n (hμx : ∀ d, ∫ ω, X 0 ω d ∂P = μx d)\n (hσx : ∀ d, ∫ ω, (X 0 ω d) ^ 2 ∂P = (σx d) ^ 2 + (μx d) ^ 2)\n\n (hZindep : iIndepFun Z P)\n (hZcoord : ∀ n, iIndepFun (fun d ω => Z n ω d) P)\n (hZgauss : ∀ n d, Measure.map (fun ω => Z n ω d) P = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) P)\n\n (pW : (Fin D → ℝ) → ℝ) (hpWbdd2 : ∃ M, ∀ v, pW v ≤ M) (W : Fin D → ℝ) (hpWposW : 0 < pW W) :\n ∃ (t : Fin D → ℝ) (Ŵ : Fin D → ℝ),\n (∀ d, 0 < |t d| ∧ |t d| < Real.sqrt (σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2))) ∧\n 0 < pW Ŵ ∧\n Tendsto (fun N => P {ω | 0 < Dseq2 (Real.log (pW Ŵ) - Real.log (pW W)) σz t X Z N ω}) atTop (𝓝 1) := by\n sorry\n\nnoncomputable def RavgZ1 {Ω : Type*} (σz C : ℝ) (X Z : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) : ℝ :=\n (1 / (N : ℝ)) * ∑ n ∈ Finset.range N, logPriorRatioZ σz C (X n ω) (Z n ω)\n\nnoncomputable def RavgZ2 {Ω : Type*} {D : ℕ} (σz : ℝ) (t : Fin D → ℝ)\n (X Z : ℕ → Ω → (Fin D → ℝ)) (N : ℕ) (ω : Ω) : ℝ :=\n (1 / (N : ℝ)) * ∑ n ∈ Finset.range N, logPriorRatioZ2 σz t (X n ω) (Z n ω)\n\ntheorem bias_concentration_cantelli\n {Ω : Type*} [MeasureSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] :\n (∀ (X Z : ℕ → Ω → ℝ)\n (μx σx σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X μ) (hXid : ∀ n, IdentDistrib (X n) (X 0) μ μ)\n\n (hXint1 : Integrable (X 0) μ) (hXint2 : Integrable (fun ω => (X 0 ω) ^ 2) μ)\n (hμx : ∫ ω, X 0 ω ∂μ = μx) (hσx : ∫ ω, (X 0 ω) ^ 2 ∂μ = σx ^ 2 + μx ^ 2)\n\n (hZindep : iIndepFun Z μ)\n (hZgauss : ∀ n, Measure.map (Z n) μ = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) μ)\n\n (hcond : σz ^ 2 < μx ^ 2 + σx ^ 2)\n (C : ℝ)\n (hClo : (σx ^ 2 + μx ^ 2 - σz ^ 2) / (σx ^ 2 + μx ^ 2 + σz ^ 2) < C)\n (hChi : C < 1),\n Tendsto (fun N => μ {ω | 0 < RavgZ1 σz C X Z N ω}) atTop (𝓝 1)) ∧\n (∀ {D : ℕ} (hD : 0 < D)\n (X Z : ℕ → Ω → (Fin D → ℝ))\n (μx σx : Fin D → ℝ) (σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X μ) (hXid : ∀ n, IdentDistrib (X n) (X 0) μ μ)\n\n (hXint : ∀ d, Integrable (fun ω => X 0 ω d) μ ∧\n Integrable (fun ω => (X 0 ω d) ^ 2) μ)\n (hμx : ∀ d, ∫ ω, X 0 ω d ∂μ = μx d)\n (hσx : ∀ d, ∫ ω, (X 0 ω d) ^ 2 ∂μ = (σx d) ^ 2 + (μx d) ^ 2)\n\n (hZindep : iIndepFun Z μ)\n (hZcoord : ∀ n, iIndepFun (fun d ω => Z n ω d) μ)\n (hZgauss : ∀ n d, Measure.map (fun ω => Z n ω d) μ = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) μ)\n\n (t : Fin D → ℝ)\n (ht : ∀ d, 0 < |t d| ∧ |t d| < Real.sqrt (σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2))),\n Tendsto (fun N => μ {ω | 0 < RavgZ2 σz t X Z N ω}) atTop (𝓝 1)) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Filter Topology\n\nnamespace ResearchLevel\n\nnoncomputable def logPriorRatioZ (σz C x z : ℝ) : ℝ :=\n (z ^ 2 - ((C - 1) * x + C * z) ^ 2) / (2 * σz ^ 2)\n\nnoncomputable def Dseq1 {Ω : Type*} (Δw σz C : ℝ) (X Z : ℕ → Ω → ℝ)\n (N : ℕ) (ω : Ω) : ℝ :=\n Δw + ∑ n ∈ Finset.range N, logPriorRatioZ σz C (X n ω) (Z n ω)\n\nnoncomputable def logPriorRatioZ2 {D : ℕ} (σz : ℝ) (t x z : Fin D → ℝ) : ℝ :=\n (∑ d, ((z d) ^ 2 - (t d * (z d - x d)) ^ 2)) / (2 * σz ^ 2)\n\nnoncomputable def Dseq2 {Ω : Type*} {D : ℕ} (Δw σz : ℝ) (t : Fin D → ℝ)\n (X Z : ℕ → Ω → (Fin D → ℝ)) (N : ℕ) (ω : Ω) : ℝ :=\n Δw + ∑ n ∈ Finset.range N, logPriorRatioZ2 σz t (X n ω) (Z n ω)\n\nprivate def pairShuffle {α β : Type*} (p : (α × α) × (β × β)) :\n (α × β) × (α × β) :=\n ((p.1.1, p.2.1), (p.1.2, p.2.2))\n\nprivate lemma measurable_pairShuffle {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :\n Measurable (@pairShuffle α β) := by\n fun_prop\n\nprivate lemma measurePreserving_pairShuffle\n {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]\n (A B : Measure α) (C D : Measure β)\n [SFinite A] [SFinite B] [SFinite C] [SFinite D] :\n MeasurePreserving pairShuffle ((A.prod B).prod (C.prod D))\n ((A.prod C).prod (B.prod D)) := by\n let h₁ := measurePreserving_prodAssoc A B (C.prod D)\n let h₂inner :=\n (measurePreserving_prodAssoc B C D).symm MeasurableEquiv.prodAssoc\n let h₂ := (MeasurePreserving.id A).prod h₂inner\n let h₃inner :=\n (Measure.measurePreserving_swap (μ := B) (ν := C)).prod (MeasurePreserving.id D)\n let h₃ := (MeasurePreserving.id A).prod h₃inner\n let h₄inner := measurePreserving_prodAssoc C B D\n let h₄ := (MeasurePreserving.id A).prod h₄inner\n let h₅ :=\n (measurePreserving_prodAssoc A C (B.prod D)).symm MeasurableEquiv.prodAssoc\n have h := h₅.comp (h₄.comp (h₃.comp (h₂.comp h₁)))\n convert h using 1 <;> rfl\n\nprivate lemma pairwise_indep_prodMk\n {Ω α β : Type*} [MeasurableSpace Ω] [MeasurableSpace α] [MeasurableSpace β]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (X : ℕ → Ω → α) (Z : ℕ → Ω → β)\n (hX : iIndepFun X P) (hZ : iIndepFun Z P)\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) P)\n (hXae : ∀ n, AEMeasurable (X n) P) (hZae : ∀ n, AEMeasurable (Z n) P) :\n Pairwise fun i j =>\n IndepFun (fun ω => (X i ω, Z i ω)) (fun ω => (X j ω, Z j ω)) P := by\n intro i j hij\n have hXX : IndepFun (X i) (X j) P := hX.indepFun hij\n have hZZ : IndepFun (Z i) (Z j) P := hZ.indepFun hij\n have hblock :\n IndepFun (fun ω => (X i ω, X j ω)) (fun ω => (Z i ω, Z j ω)) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → α => (x i, x j))\n (ψ := fun z : ℕ → β => (z i, z j)) (by fun_prop) (by fun_prop)\n have hXiZi : IndepFun (X i) (Z i) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → α => x i) (ψ := fun z : ℕ → β => z i)\n (by fun_prop) (by fun_prop)\n have hXjZj : IndepFun (X j) (Z j) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → α => x j) (ψ := fun z : ℕ → β => z j)\n (by fun_prop) (by fun_prop)\n have hXXmap :=\n (indepFun_iff_map_prod_eq_prod_map_map (hXae i) (hXae j)).mp hXX\n have hZZmap :=\n (indepFun_iff_map_prod_eq_prod_map_map (hZae i) (hZae j)).mp hZZ\n have hblockmap :=\n (indepFun_iff_map_prod_eq_prod_map_map\n ((hXae i).prodMk (hXae j)) ((hZae i).prodMk (hZae j))).mp hblock\n have hXZiMap :=\n (indepFun_iff_map_prod_eq_prod_map_map (hXae i) (hZae i)).mp hXiZi\n have hXZjMap :=\n (indepFun_iff_map_prod_eq_prod_map_map (hXae j) (hZae j)).mp hXjZj\n apply (indepFun_iff_map_prod_eq_prod_map_map\n ((hXae i).prodMk (hZae i)) ((hXae j).prodMk (hZae j))).mpr\n let q : Ω → (α × α) × (β × β) :=\n fun ω => ((X i ω, X j ω), (Z i ω, Z j ω))\n have hq : AEMeasurable q P :=\n ((hXae i).prodMk (hXae j)).prodMk ((hZae i).prodMk (hZae j))\n change P.map (pairShuffle ∘ q) = _\n rw [← AEMeasurable.map_map_of_aemeasurable measurable_pairShuffle.aemeasurable hq]\n rw [hblockmap, hXXmap, hZZmap]\n rw [(measurePreserving_pairShuffle (P.map (X i)) (P.map (X j))\n (P.map (Z i)) (P.map (Z j))).map_eq]\n rw [hXZiMap, hXZjMap]\n\nprivate lemma tendsto_measure_pos_of_ae_tendsto\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsFiniteMeasure P]\n (f : ℕ → Ω → ℝ) (hf : ∀ n, AEStronglyMeasurable (f n) P)\n (a : ℝ) (ha : 0 < a)\n (hlim : ∀ᵐ ω ∂P, Tendsto (fun n => f n ω) atTop (𝓝 a)) :\n Tendsto (fun n => P {ω | 0 < f n ω}) atTop (𝓝 (P Set.univ)) := by\n let g : ℕ → Ω → ℝ := fun n => (hf n).mk (f n)\n have hgmeas : ∀ n, Measurable (g n) := fun n => (hf n).measurable_mk\n have hfg : ∀ᵐ ω ∂P, ∀ n, f n ω = g n ω := by\n rw [ae_all_iff]\n exact fun n => (hf n).ae_eq_mk\n have hmeasure : ∀ n, P {ω | 0 < f n ω} = P {ω | 0 < g n ω} := by\n intro n\n apply measure_congr\n filter_upwards [(hf n).ae_eq_mk] with ω hω\n change (0 < f n ω) = (0 < g n ω)\n rw [hω]\n have hgind : Tendsto (fun n => P {ω | 0 < g n ω}) atTop (𝓝 (P Set.univ)) := by\n apply tendsto_measure_of_ae_tendsto_indicator_of_isFiniteMeasure atTop\n MeasurableSet.univ (fun n => measurableSet_lt measurable_const (hgmeas n))\n filter_upwards [hlim, hfg] with ω hω hfgω\n have hevent : ∀ᶠ n in atTop, 0 < f n ω := hω.eventually (Ioi_mem_nhds ha)\n filter_upwards [hevent] with n hn\n change (0 < g n ω) ↔ True\n simp only [iff_true]\n rwa [← hfgω n]\n refine hgind.congr' (Eventually.of_forall fun n => ?_)\n exact (hmeasure n).symm\n\ntheorem asymptotic_bias_one_node\n {Ω : Type*} [MeasureSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n (X Z : ℕ → Ω → ℝ)\n (μx σx σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X P) (hXid : ∀ n, IdentDistrib (X n) (X 0) P P)\n\n (hXint1 : Integrable (X 0) P) (hXint2 : Integrable (fun ω => (X 0 ω) ^ 2) P)\n (hμx : ∫ ω, X 0 ω ∂P = μx) (hσx : ∫ ω, (X 0 ω) ^ 2 ∂P = σx ^ 2 + μx ^ 2)\n\n (hZindep : iIndepFun Z P)\n (hZgauss : ∀ n, Measure.map (Z n) P = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) P)\n\n (hcond : σz ^ 2 < μx ^ 2 + σx ^ 2)\n\n (Δw : ℝ)\n\n (W : ℝ) (pW : ℝ → ℝ) (hpWbdd : ∃ M, ∀ w, pW w ≤ M) (hpWposW : 0 < pW W)\n (C : ��)\n (hClo : (σx ^ 2 + μx ^ 2 - σz ^ 2) / (σx ^ 2 + μx ^ 2 + σz ^ 2) < C)\n (hChi : C < 1)\n (hpWposWC : 0 < pW (W / C)) (hΔw : Δw = Real.log (pW (W / C)) - Real.log (pW W)) :\n Tendsto (fun N => P {ω | 0 < Dseq1 Δw σz C X Z N ω}) atTop (𝓝 1) := by\n let G : Measure ℝ := gaussianReal 0 (Real.toNNReal (σz ^ 2))\n have hXae : ∀ n, AEMeasurable (X n) P := fun n => (hXid n).aemeasurable_fst\n have hZae : ∀ n, AEMeasurable (Z n) P := by\n intro n\n apply AEMeasurable.of_map_ne_zero\n rw [hZgauss n]\n exact IsProbabilityMeasure.ne_zero G\n have hZlaw : ∀ n, IdentDistrib (Z n) id P G := by\n intro n\n exact ⟨hZae n, measurable_id.aemeasurable, by simpa [G] using hZgauss n⟩\n have hXLp0 : MemLp (X 0) 2 P :=\n (memLp_two_iff_integrable_sq hXint1.1).mpr hXint2\n have hXLp : ∀ n, MemLp (X n) 2 P := fun n => (hXid n).memLp_iff.mpr hXLp0\n have hZLp : ∀ n, MemLp (Z n) 2 P := by\n intro n\n have hid : MemLp id 2 (P.map (Z n)) := by\n rw [hZgauss n]\n exact memLp_id_gaussianReal' 2 (by simp)\n simpa [Function.comp_def] using hid.comp_of_map (hZae n)\n have hZmean : ∀ n, ∫ ω, Z n ω ∂P = 0 := by\n intro n\n simpa [G] using (hZlaw n).integral_eq\n have hZvar : ∀ n, variance (Z n) P = σz ^ 2 := by\n intro n\n calc\n variance (Z n) P = variance id G := (hZlaw n).variance_eq\n _ = (Real.toNNReal (σz ^ 2) : ℝ) := variance_id_gaussianReal\n _ = σz ^ 2 := by simp [sq_nonneg]\n have hZsecond : ∀ n, ∫ ω, (Z n ω) ^ 2 ∂P = σz ^ 2 := by\n intro n\n have hv := variance_eq_sub (hZLp n)\n rw [hZvar n, hZmean n] at hv\n norm_num at hv ⊢\n linarith\n have hpair : Pairwise fun i j =>\n IndepFun (fun ω => (X i ω, Z i ω)) (fun ω => (X j ω, Z j ω)) P :=\n pairwise_indep_prodMk P X Z hXindep hZindep hXZ hXae hZae\n have hpairid : ∀ n,\n IdentDistrib (fun ω => (X n ω, Z n ω)) (fun ω => (X 0 ω, Z 0 ω)) P P := by\n intro n\n have hn : IndepFun (X n) (Z n) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → ℝ => x n) (ψ := fun z : ℕ → ℝ => z n)\n (by fun_prop) (by fun_prop)\n have h0 : IndepFun (X 0) (Z 0) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → ℝ => x 0) (ψ := fun z : ℕ → ℝ => z 0)\n (by fun_prop) (by fun_prop)\n refine ⟨(hXae n).prodMk (hZae n), (hXae 0).prodMk (hZae 0), ?_⟩\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae n) (hZae n)).mp hn]\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae 0) (hZae 0)).mp h0]\n rw [(hXid n).map_eq, hZgauss n, hZgauss 0]\n let Y : ℕ → Ω → ℝ := fun n ω => logPriorRatioZ σz C (X n ω) (Z n ω)\n have hlogmeas : Measurable (fun p : ℝ × ℝ => logPriorRatioZ σz C p.1 p.2) := by\n unfold logPriorRatioZ\n fun_prop\n have hYid : ∀ n, IdentDistrib (Y n) (Y 0) P P := by\n intro n\n simpa [Y, Function.comp_def] using (hpairid n).comp hlogmeas\n have hYpair : Pairwise fun i j => IndepFun (Y i) (Y j) P := by\n intro i j hij\n simpa [Y, Function.comp_def] using (hpair hij).comp hlogmeas hlogmeas\n have hcrossInd : IndepFun (X 0) (Z 0) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → ℝ => x 0) (ψ := fun z : ℕ → ℝ => z 0)\n (by fun_prop) (by fun_prop)\n have hZint0 : Integrable (Z 0) P := (hZLp 0).integrable one_le_two\n have hcrossInt : Integrable (fun ω => X 0 ω * Z 0 ω) P :=\n hcrossInd.integrable_mul hXint1 hZint0\n have hcrossMean : ∫ ω, X 0 ω * Z 0 ω ∂P = 0 := by\n rw [hcrossInd.integral_fun_mul_eq_mul_integral hXint1.1 hZint0.1]\n rw [hμx, hZmean 0, mul_zero]\n have hlinLp : MemLp (fun ω => (C - 1) * X 0 ω + C * Z 0 ω) 2 P :=\n (hXLp0.const_mul (C - 1)).add ((hZLp 0).const_mul C)\n have hlinInt : Integrable (fun ω => ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2) P :=\n hlinLp.integrable_sq\n have hlinMean :\n ∫ ω, ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2 ∂P =\n (C - 1) ^ 2 * (σx ^ 2 + μx ^ 2) + C ^ 2 * σz ^ 2 := by\n have heq : (fun ω => ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2) =\n fun ω => ((C - 1) ^ 2 * (X 0 ω) ^ 2 +\n (2 * (C - 1) * C) * (X 0 ω * Z 0 ω)) + C ^ 2 * (Z 0 ω) ^ 2 := by\n funext ω\n ring\n rw [heq]\n let Aterm : Ω → ℝ := fun ω => (C - 1) ^ 2 * (X 0 ω) ^ 2\n let Bterm : Ω → ℝ := fun ω => (2 * (C - 1) * C) * (X 0 ω * Z 0 ω)\n let Eterm : Ω → ℝ := fun ω => C ^ 2 * (Z 0 ω) ^ 2\n have hA : Integrable Aterm P := hXint2.const_mul ((C - 1) ^ 2)\n have hB : Integrable Bterm P := hcrossInt.const_mul (2 * (C - 1) * C)\n have hE : Integrable Eterm P := (hZLp 0).integrable_sq.const_mul (C ^ 2)\n have hsum :\n (∫ ω, (Aterm ω + Bterm ω) + Eterm ω ∂P) =\n (∫ ω, Aterm ω ∂P) + (∫ ω, Bterm ω ∂P) + (∫ ω, Eterm ω ∂P) := by\n calc\n _ = (∫ ω, Aterm ω + Bterm ω ∂P) + ∫ ω, Eterm ω ∂P :=\n integral_add (hA.add hB) hE\n _ = _ := by rw [integral_add hA hB]\n rw [show (∫ ω, (C - 1) ^ 2 * X 0 ω ^ 2 + 2 * (C - 1) * C *\n (X 0 ω * Z 0 ω) + C ^ 2 * Z 0 ω ^ 2 ∂P) =\n (∫ ω, Aterm ω ∂P) + (∫ ω, Bterm ω ∂P) + (∫ ω, Eterm ω ∂P) by\n simpa [Aterm, Bterm, Eterm] using hsum]\n simp only [Aterm, Bterm, Eterm, integral_const_mul]\n rw [hσx, hcrossMean, hZsecond 0]\n ring\n let mY : ℝ :=\n (σz ^ 2 - ((C - 1) ^ 2 * (σx ^ 2 + μx ^ 2) + C ^ 2 * σz ^ 2)) /\n (2 * σz ^ 2)\n have hYint0 : Integrable (Y 0) P := by\n have hi := ((hZLp 0).integrable_sq.sub hlinInt).div_const (2 * σz ^ 2)\n simpa [Y, logPriorRatioZ] using hi\n have hYmean : ∫ ω, Y 0 ω ∂P = mY := by\n change (∫ ω, (Z 0 ω ^ 2 - ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2) /\n (2 * σz ^ 2) ∂P) = mY\n rw [integral_div, integral_sub (hZLp 0).integrable_sq hlinInt]\n rw [hZsecond 0, hlinMean]\n have hABpos : 0 < (σx ^ 2 + μx ^ 2) + σz ^ 2 := by\n nlinarith [sq_pos_of_pos hσz]\n have hlo := (div_lt_iff₀ hABpos).mp hClo\n have hbracket :\n 0 < C * ((σx ^ 2 + μx ^ 2) + σz ^ 2) -\n ((σx ^ 2 + μx ^ 2) - σz ^ 2) := by\n linarith\n have hnum :\n 0 < σz ^ 2 - ((C - 1) ^ 2 * (σx ^ 2 + μx ^ 2) + C ^ 2 * σz ^ 2) := by\n have hp := mul_pos (sub_pos.mpr hChi) hbracket\n nlinarith [hp]\n have hmY : 0 < mY := by\n dsimp [mY]\n exact div_pos hnum (mul_pos zero_lt_two (sq_pos_of_pos hσz))\n have hslln := strong_law_ae Y hYint0 hYpair hYid\n let F : ℕ → Ω → ℝ := fun N ω => (N : ℝ)⁻¹ * Dseq1 Δw σz C X Z N ω\n have hYint : ∀ n, Integrable (Y n) P := fun n => (hYid n).integrable_iff.mpr hYint0\n have hFint : ∀ N, Integrable (F N) P := by\n intro N\n have hsum : Integrable (fun ω => ∑ n ∈ Finset.range N, Y n ω) P := by\n fun_prop\n have hbase : Integrable (fun ω => Δw + ∑ n ∈ Finset.range N, Y n ω) P := by\n fun_prop\n have hscaled := hbase.const_mul (N : ℝ)⁻¹\n simpa [F, Dseq1, Y] using hscaled\n have hFlim : ∀ᵐ ω ∂P, Tendsto (fun N => F N ω) atTop (𝓝 mY) := by\n filter_upwards [hslln] with ω hω\n rw [hYmean] at hω\n have hc : Tendsto (fun N : ℕ => Δw / (N : ℝ)) atTop (𝓝 0) :=\n tendsto_const_div_atTop_nhds_zero_nat Δw\n have hadd := hc.add hω\n simpa [F, Dseq1, Y, div_eq_mul_inv, smul_eq_mul, mul_add, mul_comm] using hadd\n have hposF : Tendsto (fun N => P {ω | 0 < F N ω}) atTop (𝓝 1) := by\n simpa using tendsto_measure_pos_of_ae_tendsto P F (fun N => (hFint N).1) mY hmY hFlim\n refine hposF.congr' ?_\n filter_upwards [eventually_atTop.2 ⟨1, fun _ hn => hn⟩] with N hN\n congr 1\n ext ω\n change (0 < F N ω) ↔ (0 < Dseq1 Δw σz C X Z N ω)\n dsimp [F]\n have hNpos : 0 < (N : ℝ)⁻¹ := inv_pos.mpr (by exact_mod_cast hN)\n constructor\n · intro h\n rcases mul_pos_iff.mp h with hp | hn\n · exact hp.2\n · exact (not_lt_of_ge hNpos.le hn.1).elim\n · exact fun h => mul_pos hNpos h\n\ntheorem asymptotic_bias_one_layer\n {Ω : Type*} [MeasureSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {D : ℕ} (hD : 0 < D)\n (X Z : ℕ → Ω → (Fin D → ℝ))\n (μx σx : Fin D → ℝ) (σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X P) (hXid : ∀ n, IdentDistrib (X n) (X 0) P P)\n\n (hXint : ∀ d, Integrable (fun ω => X 0 ω d) P ∧\n Integrable (fun ω => (X 0 ω d) ^ 2) P)\n (hμx : ∀ d, ∫ ω, X 0 ω d ∂P = μx d)\n (hσx : ∀ d, ∫ ω, (X 0 ω d) ^ 2 ∂P = (σx d) ^ 2 + (μx d) ^ 2)\n\n (hZindep : iIndepFun Z P)\n (hZcoord : ∀ n, iIndepFun (fun d ω => Z n ω d) P)\n (hZgauss : ∀ n d, Measure.map (fun ω => Z n ω d) P = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) P)\n\n (pW : (Fin D → ℝ) → ℝ) (hpWbdd2 : ∃ M, ∀ v, pW v ≤ M) (W : Fin D → ℝ) (hpWposW : 0 < pW W) :\n ∃ (t : Fin D → ℝ) (Ŵ : Fin D → ℝ),\n (∀ d, 0 < |t d| ∧ |t d| < Real.sqrt (σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2))) ∧\n 0 < pW Ŵ ∧\n Tendsto (fun N => P {ω | 0 < Dseq2 (Real.log (pW Ŵ) - Real.log (pW W)) σz t X Z N ω}) atTop (𝓝 1) := by\n let K : Fin D → ℝ := fun d => (μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2\n have hKpos : ∀ d, 0 < K d := by\n intro d\n dsimp [K]\n nlinarith [sq_nonneg (μx d), sq_nonneg (σx d), sq_pos_of_pos hσz]\n let t : Fin D → ℝ := fun d => Real.sqrt (σz ^ 2 / K d) / 2\n have htpos : ∀ d, 0 < t d := by\n intro d\n dsimp [t]\n exact div_pos (Real.sqrt_pos.2 (div_pos (sq_pos_of_pos hσz) (hKpos d))) zero_lt_two\n have htBounds : ∀ d,\n 0 < |t d| ∧\n |t d| < Real.sqrt (σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2)) := by\n intro d\n have hsqrt : 0 < Real.sqrt (σz ^ 2 / K d) :=\n Real.sqrt_pos.2 (div_pos (sq_pos_of_pos hσz) (hKpos d))\n rw [abs_of_pos (htpos d)]\n constructor\n · exact htpos d\n · dsimp [t, K] at hsqrt ⊢\n linarith\n refine ⟨t, W, htBounds, hpWposW, ?_⟩\n let G : Measure ℝ := gaussianReal 0 (Real.toNNReal (σz ^ 2))\n have hXae : ∀ n, AEMeasurable (X n) P := fun n => (hXid n).aemeasurable_fst\n have hZcoordAe : ∀ n d, AEMeasurable (fun ω => Z n ω d) P := by\n intro n d\n apply AEMeasurable.of_map_ne_zero\n rw [hZgauss n d]\n exact IsProbabilityMeasure.ne_zero G\n have hZae : ∀ n, AEMeasurable (Z n) P := fun n =>\n aemeasurable_pi_lambda _ (hZcoordAe n)\n have hZcoordLaw : ∀ n d, IdentDistrib (fun ω => Z n ω d) id P G := by\n intro n d\n exact ⟨hZcoordAe n d, measurable_id.aemeasurable,\n by simpa [G] using hZgauss n d⟩\n have hXLp : ∀ d, MemLp (fun ω => X 0 ω d) 2 P := by\n intro d\n exact (memLp_two_iff_integrable_sq (hXint d).1.1).mpr (hXint d).2\n have hZLp : ∀ n d, MemLp (fun ω => Z n ω d) 2 P := by\n intro n d\n have hid : MemLp id 2 (P.map (fun ω => Z n ω d)) := by\n rw [hZgauss n d]\n exact memLp_id_gaussianReal' 2 (by simp)\n simpa [Function.comp_def] using hid.comp_of_map (hZcoordAe n d)\n have hZmean : ∀ n d, ∫ ω, Z n ω d ∂P = 0 := by\n intro n d\n simpa [G] using (hZcoordLaw n d).integral_eq\n have hZvar : ∀ n d, variance (fun ω => Z n ω d) P = σz ^ 2 := by\n intro n d\n calc\n variance (fun ω => Z n ω d) P = variance id G := (hZcoordLaw n d).variance_eq\n _ = (Real.toNNReal (σz ^ 2) : ℝ) := variance_id_gaussianReal\n _ = σz ^ 2 := by simp [sq_nonneg]\n have hZsecond : ∀ n d, ∫ ω, (Z n ω d) ^ 2 ∂P = σz ^ 2 := by\n intro n d\n have hv := variance_eq_sub (hZLp n d)\n rw [hZvar n d, hZmean n d] at hv\n norm_num at hv ⊢\n linarith\n have hZvecid : ∀ n, IdentDistrib (Z n) (Z 0) P P := by\n intro n\n have hn := (iIndepFun_iff_map_fun_eq_pi_map (hZcoordAe n)).mp (hZcoord n)\n have h0 := (iIndepFun_iff_map_fun_eq_pi_map (hZcoordAe 0)).mp (hZcoord 0)\n change P.map (Z n) = Measure.pi (fun d => P.map (fun ω => Z n ω d)) at hn\n change P.map (Z 0) = Measure.pi (fun d => P.map (fun ω => Z 0 ω d)) at h0\n refine ⟨hZae n, hZae 0, ?_⟩\n rw [hn, h0]\n congr 1\n funext d\n rw [hZgauss n d, hZgauss 0 d]\n have hpair : Pairwise fun i j =>\n IndepFun (fun ω => (X i ω, Z i ω)) (fun ω => (X j ω, Z j ω)) P :=\n pairwise_indep_prodMk P X Z hXindep hZindep hXZ hXae hZae\n have hpairid : ∀ n,\n IdentDistrib (fun ω => (X n ω, Z n ω)) (fun ω => (X 0 ω, Z 0 ω)) P P := by\n intro n\n have hn : IndepFun (X n) (Z n) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → (Fin D → ℝ) => x n)\n (ψ := fun z : ℕ → (Fin D → ℝ) => z n) (by fun_prop) (by fun_prop)\n have h0 : IndepFun (X 0) (Z 0) P := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → (Fin D → ℝ) => x 0)\n (ψ := fun z : ℕ → (Fin D → ℝ) => z 0) (by fun_prop) (by fun_prop)\n refine ⟨(hXae n).prodMk (hZae n), (hXae 0).prodMk (hZae 0), ?_⟩\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae n) (hZae n)).mp hn]\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae 0) (hZae 0)).mp h0]\n rw [(hXid n).map_eq, (hZvecid n).map_eq]\n let Y : ℕ → Ω → ℝ := fun n ω => logPriorRatioZ2 σz t (X n ω) (Z n ω)\n have hlogmeas : Measurable\n (fun p : (Fin D → ℝ) × (Fin D → ℝ) => logPriorRatioZ2 σz t p.1 p.2) := by\n unfold logPriorRatioZ2\n fun_prop\n have hYid : ∀ n, IdentDistrib (Y n) (Y 0) P P := by\n intro n\n simpa [Y, Function.comp_def] using (hpairid n).comp hlogmeas\n have hYpair : Pairwise fun i j => IndepFun (Y i) (Y j) P := by\n intro i j hij\n simpa [Y, Function.comp_def] using (hpair hij).comp hlogmeas hlogmeas\n have hXZcoord : ∀ d,\n IndepFun (fun ω => X 0 ω d) (fun ω => Z 0 ω d) P := by\n intro d\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → (Fin D → ℝ) => x 0 d)\n (ψ := fun z : ℕ → (Fin D → ℝ) => z 0 d) (by fun_prop) (by fun_prop)\n have hZint : ∀ d, Integrable (fun ω => Z 0 ω d) P := fun d =>\n (hZLp 0 d).integrable one_le_two\n have hcrossInt : ∀ d, Integrable (fun ω => X 0 ω d * Z 0 ω d) P := by\n intro d\n exact (hXZcoord d).integrable_mul (hXint d).1 (hZint d)\n have hcrossMean : ∀ d, ∫ ω, X 0 ω d * Z 0 ω d ∂P = 0 := by\n intro d\n rw [(hXZcoord d).integral_fun_mul_eq_mul_integral (hXint d).1.1 (hZint d).1]\n rw [hμx d, hZmean 0 d, mul_zero]\n have hdiffLp : ∀ d, MemLp (fun ω => Z 0 ω d - X 0 ω d) 2 P := fun d =>\n (hZLp 0 d).sub (hXLp d)\n have hdiffInt : ∀ d, Integrable (fun ω => (Z 0 ω d - X 0 ω d) ^ 2) P :=\n fun d => (hdiffLp d).integrable_sq\n have hdiffMean : ∀ d,\n ∫ ω, (Z 0 ω d - X 0 ω d) ^ 2 ∂P =\n σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2) := by\n intro d\n have heq : (fun ω => (Z 0 ω d - X 0 ω d) ^ 2) = fun ω =>\n (Z 0 ω d) ^ 2 + (-2 : ℝ) * (X 0 ω d * Z 0 ω d) + (X 0 ω d) ^ 2 := by\n funext ω\n ring\n rw [heq]\n let Aterm : Ω → ℝ := fun ω => (Z 0 ω d) ^ 2\n let Bterm : Ω → ℝ := fun ω => (-2 : ℝ) * (X 0 ω d * Z 0 ω d)\n let Eterm : Ω → ℝ := fun ω => (X 0 ω d) ^ 2\n have hA : Integrable Aterm P := (hZLp 0 d).integrable_sq\n have hB : Integrable Bterm P := (hcrossInt d).const_mul (-2)\n have hE : Integrable Eterm P := (hXint d).2\n have hsum :\n (∫ ω, (Aterm ω + Bterm ω) + Eterm ω ∂P) =\n (∫ ω, Aterm ω ∂P) + (∫ ω, Bterm ω ∂P) + (∫ ω, Eterm ω ∂P) := by\n calc\n _ = (∫ ω, Aterm ω + Bterm ω ∂P) + ∫ ω, Eterm ω ∂P :=\n integral_add (hA.add hB) hE\n _ = _ := by rw [integral_add hA hB]\n rw [show (∫ ω, Z 0 ω d ^ 2 + (-2 : ℝ) * (X 0 ω d * Z 0 ω d) +\n X 0 ω d ^ 2 ∂P) =\n (∫ ω, Aterm ω ∂P) + (∫ ω, Bterm ω ∂P) + (∫ ω, Eterm ω ∂P) by\n simpa [Aterm, Bterm, Eterm] using hsum]\n simp only [Aterm, Bterm, Eterm, integral_const_mul]\n rw [hZsecond 0 d, hcrossMean d, hσx d]\n ring\n have hscaledLp : ∀ d, MemLp (fun ω => t d * (Z 0 ω d - X 0 ω d)) 2 P :=\n fun d => (hdiffLp d).const_mul (t d)\n have hscaledInt : ∀ d,\n Integrable (fun ω => (t d * (Z 0 ω d - X 0 ω d)) ^ 2) P :=\n fun d => (hscaledLp d).integrable_sq\n have hscaledMean : ∀ d,\n ∫ ω, (t d * (Z 0 ω d - X 0 ω d)) ^ 2 ∂P =\n (t d) ^ 2 * (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)) := by\n intro d\n have heq : (fun ω => (t d * (Z 0 ω d - X 0 ω d)) ^ 2) =\n fun ω => (t d) ^ 2 * (Z 0 ω d - X 0 ω d) ^ 2 := by\n funext ω\n ring\n rw [heq, integral_const_mul, hdiffMean d]\n have htermInt : ∀ d, Integrable (fun ω =>\n (Z 0 ω d) ^ 2 - (t d * (Z 0 ω d - X 0 ω d)) ^ 2) P := by\n intro d\n exact (hZLp 0 d).integrable_sq.sub (hscaledInt d)\n have htermMean : ∀ d, ∫ ω,\n ((Z 0 ω d) ^ 2 - (t d * (Z 0 ω d - X 0 ω d)) ^ 2) ∂P =\n σz ^ 2 - (t d) ^ 2 * (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)) := by\n intro d\n rw [integral_sub (hZLp 0 d).integrable_sq (hscaledInt d)]\n rw [hZsecond 0 d, hscaledMean d]\n let mY : ℝ :=\n (∑ d, (σz ^ 2 - (t d) ^ 2 *\n (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)))) / (2 * σz ^ 2)\n have hYint0 : Integrable (Y 0) P := by\n have hsum : Integrable (fun ω => ∑ d, ((Z 0 ω d) ^ 2 -\n (t d * (Z 0 ω d - X 0 ω d)) ^ 2)) P :=\n integrable_finset_sum Finset.univ (fun d _ => htermInt d)\n have hi := hsum.div_const (2 * σz ^ 2)\n simpa [Y, logPriorRatioZ2] using hi\n have hYmean : ∫ ω, Y 0 ω ∂P = mY := by\n change (∫ ω, (∑ d, ((Z 0 ω d) ^ 2 -\n (t d * (Z 0 ω d - X 0 ω d)) ^ 2)) / (2 * σz ^ 2) ∂P) = mY\n rw [integral_div]\n rw [integral_finset_sum Finset.univ (fun d _ => htermInt d)]\n simp_rw [htermMean]\n rfl\n have hnumPos : ∀ d,\n 0 < σz ^ 2 - (t d) ^ 2 *\n (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)) := by\n intro d\n have hratio : 0 ≤ σz ^ 2 / K d := (div_pos (sq_pos_of_pos hσz) (hKpos d)).le\n have hsqrt := Real.sq_sqrt hratio\n have hKne : K d ≠ 0 := (hKpos d).ne'\n have htprod : (t d) ^ 2 * K d = σz ^ 2 / 4 := by\n dsimp [t]\n rw [div_pow, hsqrt]\n field_simp [hKne]\n <;> ring\n have horder : σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2) = K d := by\n dsimp [K]\n ring\n rw [horder, htprod]\n nlinarith [sq_pos_of_pos hσz]\n have huniv : (Finset.univ : Finset (Fin D)).Nonempty :=\n ⟨⟨0, hD⟩, Finset.mem_univ _⟩\n have hsumPos : 0 < ∑ d, (σz ^ 2 - (t d) ^ 2 *\n (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2))) :=\n Finset.sum_pos (fun d _ => hnumPos d) huniv\n have hmY : 0 < mY := by\n dsimp [mY]\n exact div_pos hsumPos (mul_pos zero_lt_two (sq_pos_of_pos hσz))\n have hslln := strong_law_ae Y hYint0 hYpair hYid\n let Δ : ℝ := Real.log (pW W) - Real.log (pW W)\n let F : ℕ → Ω → ℝ := fun N ω => (N : ℝ)⁻¹ * Dseq2 Δ σz t X Z N ω\n have hYint : ∀ n, Integrable (Y n) P := fun n => (hYid n).integrable_iff.mpr hYint0\n have hFint : ∀ N, Integrable (F N) P := by\n intro N\n have hsum : Integrable (fun ω => ∑ n ∈ Finset.range N, Y n ω) P := by\n fun_prop\n have hbase : Integrable (fun ω => Δ + ∑ n ∈ Finset.range N, Y n ω) P := by\n fun_prop\n have hscaled := hbase.const_mul (N : ℝ)⁻¹\n simpa [F, Dseq2, Y] using hscaled\n have hFlim : ∀ᵐ ω ∂P, Tendsto (fun N => F N ω) atTop (𝓝 mY) := by\n filter_upwards [hslln] with ω hω\n rw [hYmean] at hω\n have hc : Tendsto (fun N : ℕ => Δ / (N : ℝ)) atTop (𝓝 0) :=\n tendsto_const_div_atTop_nhds_zero_nat Δ\n have hadd := hc.add hω\n simpa [F, Dseq2, Y, div_eq_mul_inv, smul_eq_mul, mul_add, mul_comm] using hadd\n have hposF : Tendsto (fun N => P {ω | 0 < F N ω}) atTop (𝓝 1) := by\n simpa using tendsto_measure_pos_of_ae_tendsto P F (fun N => (hFint N).1) mY hmY hFlim\n refine hposF.congr' ?_\n filter_upwards [eventually_atTop.2 ⟨1, fun _ hn => hn⟩] with N hN\n congr 1\n ext ω\n change (0 < F N ω) ↔\n (0 < Dseq2 (Real.log (pW W) - Real.log (pW W)) σz t X Z N ω)\n change (0 < (N : ℝ)⁻¹ * Dseq2 Δ σz t X Z N ω) ↔\n (0 < Dseq2 Δ σz t X Z N ω)\n have hNpos : 0 < (N : ℝ)⁻¹ := inv_pos.mpr (by exact_mod_cast hN)\n constructor\n · intro h\n rcases mul_pos_iff.mp h with hp | hn\n · exact hp.2\n · exact (not_lt_of_ge hNpos.le hn.1).elim\n · exact fun h => mul_pos hNpos h\n\nnoncomputable def RavgZ1 {Ω : Type*} (σz C : ℝ) (X Z : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) : ℝ :=\n (1 / (N : ℝ)) * ∑ n ∈ Finset.range N, logPriorRatioZ σz C (X n ω) (Z n ω)\n\nnoncomputable def RavgZ2 {Ω : Type*} {D : ℕ} (σz : ℝ) (t : Fin D → ℝ)\n (X Z : ℕ → Ω → (Fin D → ℝ)) (N : ℕ) (ω : Ω) : ℝ :=\n (1 / (N : ℝ)) * ∑ n ∈ Finset.range N, logPriorRatioZ2 σz t (X n ω) (Z n ω)\n\ntheorem bias_concentration_cantelli\n {Ω : Type*} [MeasureSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] :\n (∀ (X Z : ℕ → Ω → ℝ)\n (μx σx σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X μ) (hXid : ∀ n, IdentDistrib (X n) (X 0) μ μ)\n\n (hXint1 : Integrable (X 0) μ) (hXint2 : Integrable (fun ω => (X 0 ω) ^ 2) μ)\n (hμx : ∫ ω, X 0 ω ∂μ = μx) (hσx : ∫ ω, (X 0 ω) ^ 2 ∂μ = σx ^ 2 + μx ^ 2)\n\n (hZindep : iIndepFun Z μ)\n (hZgauss : ∀ n, Measure.map (Z n) μ = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) μ)\n\n (hcond : σz ^ 2 < μx ^ 2 + σx ^ 2)\n (C : ℝ)\n (hClo : (σx ^ 2 + μx ^ 2 - σz ^ 2) / (σx ^ 2 + μx ^ 2 + σz ^ 2) < C)\n (hChi : C < 1),\n Tendsto (fun N => μ {ω | 0 < RavgZ1 σz C X Z N ω}) atTop (𝓝 1)) ∧\n (∀ {D : ℕ} (hD : 0 < D)\n (X Z : ℕ → Ω → (Fin D → ℝ))\n (μx σx : Fin D → ℝ) (σz : ℝ) (hσz : 0 < σz)\n\n (hXindep : iIndepFun X μ) (hXid : ∀ n, IdentDistrib (X n) (X 0) μ μ)\n\n (hXint : ∀ d, Integrable (fun ω => X 0 ω d) μ ∧\n Integrable (fun ω => (X 0 ω d) ^ 2) μ)\n (hμx : ∀ d, ∫ ω, X 0 ω d ∂μ = μx d)\n (hσx : ∀ d, ∫ ω, (X 0 ω d) ^ 2 ∂μ = (σx d) ^ 2 + (μx d) ^ 2)\n\n (hZindep : iIndepFun Z μ)\n (hZcoord : ∀ n, iIndepFun (fun d ω => Z n ω d) μ)\n (hZgauss : ∀ n d, Measure.map (fun ω => Z n ω d) μ = gaussianReal 0 (Real.toNNReal (σz ^ 2)))\n\n (hXZ : IndepFun (fun ω n => X n ω) (fun ω n => Z n ω) μ)\n\n (t : Fin D → ℝ)\n (ht : ∀ d, 0 < |t d| ∧ |t d| < Real.sqrt (σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2))),\n Tendsto (fun N => μ {ω | 0 < RavgZ2 σz t X Z N ω}) atTop (𝓝 1)) := by\n refine ⟨?_, ?_⟩\n · intro X Z μx σx σz hσz hXindep hXid hXint1 hXint2 hμx hσx hZindep hZgauss hXZ hcond C hClo hChi\n let G : Measure ℝ := gaussianReal 0 (Real.toNNReal (σz ^ 2))\n have hXae : ∀ n, AEMeasurable (X n) μ := fun n => (hXid n).aemeasurable_fst\n have hZae : ∀ n, AEMeasurable (Z n) μ := by\n intro n\n apply AEMeasurable.of_map_ne_zero\n rw [hZgauss n]\n exact IsProbabilityMeasure.ne_zero G\n have hZlaw : ∀ n, IdentDistrib (Z n) id μ G := by\n intro n\n exact ⟨hZae n, measurable_id.aemeasurable, by simpa [G] using hZgauss n⟩\n have hXLp0 : MemLp (X 0) 2 μ :=\n (memLp_two_iff_integrable_sq hXint1.1).mpr hXint2\n have hXLp : ∀ n, MemLp (X n) 2 μ := fun n => (hXid n).memLp_iff.mpr hXLp0\n have hZLp : ∀ n, MemLp (Z n) 2 μ := by\n intro n\n have hid : MemLp id 2 (μ.map (Z n)) := by\n rw [hZgauss n]\n exact memLp_id_gaussianReal' 2 (by simp)\n simpa [Function.comp_def] using hid.comp_of_map (hZae n)\n have hZmean : ∀ n, ∫ ω, Z n ω ∂μ = 0 := by\n intro n\n simpa [G] using (hZlaw n).integral_eq\n have hZvar : ∀ n, variance (Z n) μ = σz ^ 2 := by\n intro n\n calc\n variance (Z n) μ = variance id G := (hZlaw n).variance_eq\n _ = (Real.toNNReal (σz ^ 2) : ℝ) := variance_id_gaussianReal\n _ = σz ^ 2 := by simp [sq_nonneg]\n have hZsecond : ∀ n, ∫ ω, (Z n ω) ^ 2 ∂μ = σz ^ 2 := by\n intro n\n have hv := variance_eq_sub (hZLp n)\n rw [hZvar n, hZmean n] at hv\n norm_num at hv ⊢\n linarith\n have hpair : Pairwise fun i j =>\n IndepFun (fun ω => (X i ω, Z i ω)) (fun ω => (X j ω, Z j ω)) μ :=\n pairwise_indep_prodMk μ X Z hXindep hZindep hXZ hXae hZae\n have hpairid : ∀ n,\n IdentDistrib (fun ω => (X n ω, Z n ω)) (fun ω => (X 0 ω, Z 0 ω)) μ μ := by\n intro n\n have hn : IndepFun (X n) (Z n) μ := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → ℝ => x n) (ψ := fun z : ℕ → ℝ => z n)\n (by fun_prop) (by fun_prop)\n have h0 : IndepFun (X 0) (Z 0) μ := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → ℝ => x 0) (ψ := fun z : ℕ → ℝ => z 0)\n (by fun_prop) (by fun_prop)\n refine ⟨(hXae n).prodMk (hZae n), (hXae 0).prodMk (hZae 0), ?_⟩\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae n) (hZae n)).mp hn]\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae 0) (hZae 0)).mp h0]\n rw [(hXid n).map_eq, hZgauss n, hZgauss 0]\n let Y : ℕ → Ω → ℝ := fun n ω => logPriorRatioZ σz C (X n ω) (Z n ω)\n have hlogmeas : Measurable (fun p : ℝ × ℝ => logPriorRatioZ σz C p.1 p.2) := by\n unfold logPriorRatioZ\n fun_prop\n have hYid : ∀ n, IdentDistrib (Y n) (Y 0) μ μ := by\n intro n\n simpa [Y, Function.comp_def] using (hpairid n).comp hlogmeas\n have hYpair : Pairwise fun i j => IndepFun (Y i) (Y j) μ := by\n intro i j hij\n simpa [Y, Function.comp_def] using (hpair hij).comp hlogmeas hlogmeas\n have hcrossInd : IndepFun (X 0) (Z 0) μ := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → ℝ => x 0) (ψ := fun z : ℕ → ℝ => z 0)\n (by fun_prop) (by fun_prop)\n have hZint0 : Integrable (Z 0) μ := (hZLp 0).integrable one_le_two\n have hcrossInt : Integrable (fun ω => X 0 ω * Z 0 ω) μ :=\n hcrossInd.integrable_mul hXint1 hZint0\n have hcrossMean : ∫ ω, X 0 ω * Z 0 ω ∂μ = 0 := by\n rw [hcrossInd.integral_fun_mul_eq_mul_integral hXint1.1 hZint0.1]\n rw [hμx, hZmean 0, mul_zero]\n have hlinLp : MemLp (fun ω => (C - 1) * X 0 ω + C * Z 0 ω) 2 μ :=\n (hXLp0.const_mul (C - 1)).add ((hZLp 0).const_mul C)\n have hlinInt : Integrable (fun ω => ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2) μ :=\n hlinLp.integrable_sq\n have hlinMean :\n ∫ ω, ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2 ∂μ =\n (C - 1) ^ 2 * (σx ^ 2 + μx ^ 2) + C ^ 2 * σz ^ 2 := by\n have heq : (fun ω => ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2) =\n fun ω => ((C - 1) ^ 2 * (X 0 ω) ^ 2 +\n (2 * (C - 1) * C) * (X 0 ω * Z 0 ω)) + C ^ 2 * (Z 0 ω) ^ 2 := by\n funext ω\n ring\n rw [heq]\n let Aterm : Ω → ℝ := fun ω => (C - 1) ^ 2 * (X 0 ω) ^ 2\n let Bterm : Ω → ℝ := fun ω => (2 * (C - 1) * C) * (X 0 ω * Z 0 ω)\n let Eterm : Ω → ℝ := fun ω => C ^ 2 * (Z 0 ω) ^ 2\n have hA : Integrable Aterm μ := hXint2.const_mul ((C - 1) ^ 2)\n have hB : Integrable Bterm μ := hcrossInt.const_mul (2 * (C - 1) * C)\n have hE : Integrable Eterm μ := (hZLp 0).integrable_sq.const_mul (C ^ 2)\n have hsum :\n (∫ ω, (Aterm ω + Bterm ω) + Eterm ω ∂μ) =\n (∫ ω, Aterm ω ∂μ) + (∫ ω, Bterm ω ∂μ) + (∫ ω, Eterm ω ∂μ) := by\n calc\n _ = (∫ ω, Aterm ω + Bterm ω ∂μ) + ∫ ω, Eterm ω ∂μ :=\n integral_add (hA.add hB) hE\n _ = _ := by rw [integral_add hA hB]\n rw [show (∫ ω, (C - 1) ^ 2 * X 0 ω ^ 2 + 2 * (C - 1) * C *\n (X 0 ω * Z 0 ω) + C ^ 2 * Z 0 ω ^ 2 ∂μ) =\n (∫ ω, Aterm ω ∂μ) + (∫ ω, Bterm ω ∂μ) + (∫ ω, Eterm ω ∂μ) by\n simpa [Aterm, Bterm, Eterm] using hsum]\n simp only [Aterm, Bterm, Eterm, integral_const_mul]\n rw [hσx, hcrossMean, hZsecond 0]\n ring\n let mY : ℝ :=\n (σz ^ 2 - ((C - 1) ^ 2 * (σx ^ 2 + μx ^ 2) + C ^ 2 * σz ^ 2)) /\n (2 * σz ^ 2)\n have hYint0 : Integrable (Y 0) μ := by\n have hi := ((hZLp 0).integrable_sq.sub hlinInt).div_const (2 * σz ^ 2)\n simpa [Y, logPriorRatioZ] using hi\n have hYmean : ∫ ω, Y 0 ω ∂μ = mY := by\n change (∫ ω, (Z 0 ω ^ 2 - ((C - 1) * X 0 ω + C * Z 0 ω) ^ 2) /\n (2 * σz ^ 2) ∂μ) = mY\n rw [integral_div, integral_sub (hZLp 0).integrable_sq hlinInt]\n rw [hZsecond 0, hlinMean]\n have hABpos : 0 < (σx ^ 2 + μx ^ 2) + σz ^ 2 := by\n nlinarith [sq_pos_of_pos hσz]\n have hlo := (div_lt_iff₀ hABpos).mp hClo\n have hbracket :\n 0 < C * ((σx ^ 2 + μx ^ 2) + σz ^ 2) -\n ((σx ^ 2 + μx ^ 2) - σz ^ 2) := by\n linarith\n have hnum :\n 0 < σz ^ 2 - ((C - 1) ^ 2 * (σx ^ 2 + μx ^ 2) + C ^ 2 * σz ^ 2) := by\n have hp := mul_pos (sub_pos.mpr hChi) hbracket\n nlinarith [hp]\n have hmY : 0 < mY := by\n dsimp [mY]\n exact div_pos hnum (mul_pos zero_lt_two (sq_pos_of_pos hσz))\n have hslln := strong_law_ae Y hYint0 hYpair hYid\n have hYint : ∀ n, Integrable (Y n) μ := fun n => (hYid n).integrable_iff.mpr hYint0\n have hFint : ∀ N, Integrable (RavgZ1 σz C X Z N) μ := by\n intro N\n have hsum : Integrable (fun ω => ∑ n ∈ Finset.range N, Y n ω) μ := by\n fun_prop\n have hscaled := hsum.const_mul (1 / (N : ℝ))\n exact hscaled\n have hFlim : ∀ᵐ ω ∂μ, Tendsto (fun N => RavgZ1 σz C X Z N ω) atTop (𝓝 mY) := by\n filter_upwards [hslln] with ω hω\n rw [hYmean] at hω\n simpa [RavgZ1, Y, div_eq_mul_inv, smul_eq_mul, mul_comm] using hω\n simpa using tendsto_measure_pos_of_ae_tendsto μ (RavgZ1 σz C X Z)\n (fun N => (hFint N).1) mY hmY hFlim\n · intro D hD X Z μx σx σz hσz hXindep hXid hXint hμx hσx hZindep hZcoord hZgauss hXZ t ht\n let G : Measure ℝ := gaussianReal 0 (Real.toNNReal (σz ^ 2))\n have hXae : ∀ n, AEMeasurable (X n) μ := fun n => (hXid n).aemeasurable_fst\n have hZcoordAe : ∀ n d, AEMeasurable (fun ω => Z n ω d) μ := by\n intro n d\n apply AEMeasurable.of_map_ne_zero\n rw [hZgauss n d]\n exact IsProbabilityMeasure.ne_zero G\n have hZae : ∀ n, AEMeasurable (Z n) μ := fun n =>\n aemeasurable_pi_lambda _ (hZcoordAe n)\n have hZcoordLaw : ∀ n d, IdentDistrib (fun ω => Z n ω d) id μ G := by\n intro n d\n exact ⟨hZcoordAe n d, measurable_id.aemeasurable,\n by simpa [G] using hZgauss n d⟩\n have hXLp : ∀ d, MemLp (fun ω => X 0 ω d) 2 μ := by\n intro d\n exact (memLp_two_iff_integrable_sq (hXint d).1.1).mpr (hXint d).2\n have hZLp : ∀ n d, MemLp (fun ω => Z n ω d) 2 μ := by\n intro n d\n have hid : MemLp id 2 (μ.map (fun ω => Z n ω d)) := by\n rw [hZgauss n d]\n exact memLp_id_gaussianReal' 2 (by simp)\n simpa [Function.comp_def] using hid.comp_of_map (hZcoordAe n d)\n have hZmean : ∀ n d, ∫ ω, Z n ω d ∂μ = 0 := by\n intro n d\n simpa [G] using (hZcoordLaw n d).integral_eq\n have hZvar : ∀ n d, variance (fun ω => Z n ω d) μ = σz ^ 2 := by\n intro n d\n calc\n variance (fun ω => Z n ω d) μ = variance id G := (hZcoordLaw n d).variance_eq\n _ = (Real.toNNReal (σz ^ 2) : ℝ) := variance_id_gaussianReal\n _ = σz ^ 2 := by simp [sq_nonneg]\n have hZsecond : ∀ n d, ∫ ω, (Z n ω d) ^ 2 ∂μ = σz ^ 2 := by\n intro n d\n have hv := variance_eq_sub (hZLp n d)\n rw [hZvar n d, hZmean n d] at hv\n norm_num at hv ⊢\n linarith\n have hZvecid : ∀ n, IdentDistrib (Z n) (Z 0) μ μ := by\n intro n\n have hn := (iIndepFun_iff_map_fun_eq_pi_map (hZcoordAe n)).mp (hZcoord n)\n have h0 := (iIndepFun_iff_map_fun_eq_pi_map (hZcoordAe 0)).mp (hZcoord 0)\n change μ.map (Z n) = Measure.pi (fun d => μ.map (fun ω => Z n ω d)) at hn\n change μ.map (Z 0) = Measure.pi (fun d => μ.map (fun ω => Z 0 ω d)) at h0\n refine ⟨hZae n, hZae 0, ?_⟩\n rw [hn, h0]\n congr 1\n funext d\n rw [hZgauss n d, hZgauss 0 d]\n have hpair : Pairwise fun i j =>\n IndepFun (fun ω => (X i ω, Z i ω)) (fun ω => (X j ω, Z j ω)) μ :=\n pairwise_indep_prodMk μ X Z hXindep hZindep hXZ hXae hZae\n have hpairid : ∀ n,\n IdentDistrib (fun ω => (X n ω, Z n ω)) (fun ω => (X 0 ω, Z 0 ω)) μ μ := by\n intro n\n have hn : IndepFun (X n) (Z n) μ := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → (Fin D → ℝ) => x n)\n (ψ := fun z : ℕ → (Fin D → ℝ) => z n) (by fun_prop) (by fun_prop)\n have h0 : IndepFun (X 0) (Z 0) μ := by\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → (Fin D → ℝ) => x 0)\n (ψ := fun z : ℕ → (Fin D → ℝ) => z 0) (by fun_prop) (by fun_prop)\n refine ⟨(hXae n).prodMk (hZae n), (hXae 0).prodMk (hZae 0), ?_⟩\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae n) (hZae n)).mp hn]\n rw [(indepFun_iff_map_prod_eq_prod_map_map (hXae 0) (hZae 0)).mp h0]\n rw [(hXid n).map_eq, (hZvecid n).map_eq]\n let Y : ℕ → Ω → ℝ := fun n ω => logPriorRatioZ2 σz t (X n ω) (Z n ω)\n have hlogmeas : Measurable\n (fun p : (Fin D → ℝ) × (Fin D → ℝ) => logPriorRatioZ2 σz t p.1 p.2) := by\n unfold logPriorRatioZ2\n fun_prop\n have hYid : ∀ n, IdentDistrib (Y n) (Y 0) μ μ := by\n intro n\n simpa [Y, Function.comp_def] using (hpairid n).comp hlogmeas\n have hYpair : Pairwise fun i j => IndepFun (Y i) (Y j) μ := by\n intro i j hij\n simpa [Y, Function.comp_def] using (hpair hij).comp hlogmeas hlogmeas\n have hXZcoord : ∀ d,\n IndepFun (fun ω => X 0 ω d) (fun ω => Z 0 ω d) μ := by\n intro d\n simpa [Function.comp_def] using\n hXZ.comp (φ := fun x : ℕ → (Fin D → ℝ) => x 0 d)\n (ψ := fun z : ℕ → (Fin D → ℝ) => z 0 d) (by fun_prop) (by fun_prop)\n have hZint : ∀ d, Integrable (fun ω => Z 0 ω d) μ := fun d =>\n (hZLp 0 d).integrable one_le_two\n have hcrossInt : ∀ d, Integrable (fun ω => X 0 ω d * Z 0 ω d) μ := by\n intro d\n exact (hXZcoord d).integrable_mul (hXint d).1 (hZint d)\n have hcrossMean : ∀ d, ∫ ω, X 0 ω d * Z 0 ω d ∂μ = 0 := by\n intro d\n rw [(hXZcoord d).integral_fun_mul_eq_mul_integral (hXint d).1.1 (hZint d).1]\n rw [hμx d, hZmean 0 d, mul_zero]\n have hdiffLp : ∀ d, MemLp (fun ω => Z 0 ω d - X 0 ω d) 2 μ := fun d =>\n (hZLp 0 d).sub (hXLp d)\n have hdiffInt : ∀ d, Integrable (fun ω => (Z 0 ω d - X 0 ω d) ^ 2) μ :=\n fun d => (hdiffLp d).integrable_sq\n have hdiffMean : ∀ d,\n ∫ ω, (Z 0 ω d - X 0 ω d) ^ 2 ∂μ =\n σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2) := by\n intro d\n have heq : (fun ω => (Z 0 ω d - X 0 ω d) ^ 2) = fun ω =>\n (Z 0 ω d) ^ 2 + (-2 : ℝ) * (X 0 ω d * Z 0 ω d) + (X 0 ω d) ^ 2 := by\n funext ω\n ring\n rw [heq]\n let Aterm : Ω → ℝ := fun ω => (Z 0 ω d) ^ 2\n let Bterm : Ω → ℝ := fun ω => (-2 : ℝ) * (X 0 ω d * Z 0 ω d)\n let Eterm : Ω → ℝ := fun ω => (X 0 ω d) ^ 2\n have hA : Integrable Aterm μ := (hZLp 0 d).integrable_sq\n have hB : Integrable Bterm μ := (hcrossInt d).const_mul (-2)\n have hE : Integrable Eterm μ := (hXint d).2\n have hsum :\n (∫ ω, (Aterm ω + Bterm ω) + Eterm ω ∂μ) =\n (∫ ω, Aterm ω ∂μ) + (∫ ω, Bterm ω ∂μ) + (∫ ω, Eterm ω ∂μ) := by\n calc\n _ = (∫ ω, Aterm ω + Bterm ω ∂μ) + ∫ ω, Eterm ω ∂μ :=\n integral_add (hA.add hB) hE\n _ = _ := by rw [integral_add hA hB]\n rw [show (∫ ω, Z 0 ω d ^ 2 + (-2 : ℝ) * (X 0 ω d * Z 0 ω d) +\n X 0 ω d ^ 2 ∂μ) =\n (∫ ω, Aterm ω ∂μ) + (∫ ω, Bterm ω ∂μ) + (∫ ω, Eterm ω ∂μ) by\n simpa [Aterm, Bterm, Eterm] using hsum]\n simp only [Aterm, Bterm, Eterm, integral_const_mul]\n rw [hZsecond 0 d, hcrossMean d, hσx d]\n ring\n have hscaledLp : ∀ d, MemLp (fun ω => t d * (Z 0 ω d - X 0 ω d)) 2 μ :=\n fun d => (hdiffLp d).const_mul (t d)\n have hscaledInt : ∀ d,\n Integrable (fun ω => (t d * (Z 0 ω d - X 0 ω d)) ^ 2) μ :=\n fun d => (hscaledLp d).integrable_sq\n have hscaledMean : ∀ d,\n ∫ ω, (t d * (Z 0 ω d - X 0 ω d)) ^ 2 ∂μ =\n (t d) ^ 2 * (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)) := by\n intro d\n have heq : (fun ω => (t d * (Z 0 ω d - X 0 ω d)) ^ 2) =\n fun ω => (t d) ^ 2 * (Z 0 ω d - X 0 ω d) ^ 2 := by\n funext ω\n ring\n rw [heq, integral_const_mul, hdiffMean d]\n have htermInt : ∀ d, Integrable (fun ω =>\n (Z 0 ω d) ^ 2 - (t d * (Z 0 ω d - X 0 ω d)) ^ 2) μ := by\n intro d\n exact (hZLp 0 d).integrable_sq.sub (hscaledInt d)\n have htermMean : ∀ d, ∫ ω,\n ((Z 0 ω d) ^ 2 - (t d * (Z 0 ω d - X 0 ω d)) ^ 2) ∂μ =\n σz ^ 2 - (t d) ^ 2 * (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)) := by\n intro d\n rw [integral_sub (hZLp 0 d).integrable_sq (hscaledInt d)]\n rw [hZsecond 0 d, hscaledMean d]\n let mY : ℝ :=\n (∑ d, (σz ^ 2 - (t d) ^ 2 *\n (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)))) / (2 * σz ^ 2)\n have hYint0 : Integrable (Y 0) μ := by\n have hsum : Integrable (fun ω => ∑ d, ((Z 0 ω d) ^ 2 -\n (t d * (Z 0 ω d - X 0 ω d)) ^ 2)) μ :=\n integrable_finset_sum Finset.univ (fun d _ => htermInt d)\n have hi := hsum.div_const (2 * σz ^ 2)\n simpa [Y, logPriorRatioZ2] using hi\n have hYmean : ∫ ω, Y 0 ω ∂μ = mY := by\n change (∫ ω, (∑ d, ((Z 0 ω d) ^ 2 -\n (t d * (Z 0 ω d - X 0 ω d)) ^ 2)) / (2 * σz ^ 2) ∂μ) = mY\n rw [integral_div]\n rw [integral_finset_sum Finset.univ (fun d _ => htermInt d)]\n simp_rw [htermMean]\n rfl\n have hKpos : ∀ d, 0 < (μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2 := by\n intro d\n nlinarith [sq_nonneg (μx d), sq_nonneg (σx d), sq_pos_of_pos hσz]\n have hnumPos : ∀ d,\n 0 < σz ^ 2 - (t d) ^ 2 *\n (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2)) := by\n intro d\n have hK := hKpos d\n have hratio : 0 ≤ σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2) :=\n (div_pos (sq_pos_of_pos hσz) hK).le\n have hlt := (ht d).2\n have habs : 0 ≤ |t d| := abs_nonneg _\n have hsq : |t d| ^ 2 < σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2) := by\n have := Real.sq_sqrt hratio\n have h2 : |t d| ^ 2 < (Real.sqrt (σz ^ 2 / ((μx d) ^ 2 + (σx d) ^ 2 + σz ^ 2))) ^ 2 := by\n exact pow_lt_pow_left₀ hlt habs (by norm_num)\n linarith\n rw [sq_abs, lt_div_iff₀ hK] at hsq\n nlinarith [hsq]\n have huniv : (Finset.univ : Finset (Fin D)).Nonempty :=\n ⟨⟨0, hD⟩, Finset.mem_univ _⟩\n have hsumPos : 0 < ∑ d, (σz ^ 2 - (t d) ^ 2 *\n (σz ^ 2 + ((σx d) ^ 2 + (μx d) ^ 2))) :=\n Finset.sum_pos (fun d _ => hnumPos d) huniv\n have hmY : 0 < mY := by\n dsimp [mY]\n exact div_pos hsumPos (mul_pos zero_lt_two (sq_pos_of_pos hσz))\n have hslln := strong_law_ae Y hYint0 hYpair hYid\n have hYint : ∀ n, Integrable (Y n) μ := fun n => (hYid n).integrable_iff.mpr hYint0\n have hFint : ∀ N, Integrable (RavgZ2 σz t X Z N) μ := by\n intro N\n have hsum : Integrable (fun ω => ∑ n ∈ Finset.range N, Y n ω) μ := by\n fun_prop\n have hscaled := hsum.const_mul (1 / (N : ℝ))\n exact hscaled\n have hFlim : ∀ᵐ ω ∂μ, Tendsto (fun N => RavgZ2 σz t X Z N ��) atTop (𝓝 mY) := by\n filter_upwards [hslln] with ω hω\n rw [hYmean] at hω\n simpa [RavgZ2, Y, div_eq_mul_inv, smul_eq_mul, mul_comm] using hω\n simpa using tendsto_measure_pos_of_ae_tendsto μ (RavgZ2 σz t X Z)\n (fun N => (hFint N).1) mY hmY hFlim\n\nend ResearchLevel\n"} +{"id": "v24-22-1104", "source": "Research-level", "targets": [{"label": "Theorem 1", "decls": ["theorem1"], "statement": "Theorem 1 (Classification-calibration) Let L be the LHS loss. For any x such that $p(\\mathbf{x})\\in$ (0, 1) with $p(\\mathbf{x})\\neq 1/2$, a global minimizer of $\\operatorname{E}[L(\\mathbf{Y}f(\\mathbf{X}))\\mid\\mathbf{X}=\\mathbf{x}]$ uniquely exists and is\n\n$$\n\\bar{f}({\\bf x})=\\left\\{\\begin{array}{l l}{-(1-p({\\bf x}))(p({\\bf x}))^{-1},\\quad}&{ifp({\\bf x})<1/2,}\\\\ {+p({\\bf x})(1-p({\\bf x}))^{-1},\\quad}&{ifp({\\bf x})>1/2.}\\end{array}\\right.\n$$\n\nAlso, sgn $\\{{\\bar{f}}({\\bf x}) \\}= f^{*}({\\bf x})$ , where $f^{*}(\\mathbf{x})=\\mathrm{sgn}\\{p(\\mathbf{x})-1/2\\}$ is the Bayes rule.", "context_ids": ["v24-22-1104:ctx1", "v24-22-1104:ctx2", "v24-22-1104:ctx3", "v24-22-1104:ctx4", "v24-22-1104:ctx6"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}, {"label": "Theorem 2", "decls": ["theorem2"], "statement": "Theorem 2 (Existence of global solution) Let $(\\mathbf{x}_{i},y_{i})\\in\\mathbb{R}^{p}\\times\\{-1,+1\\}$ for $i=1,\\ldots,n$ be training data. Suppose there exist $i,j$ with $y_{i}= + 1$ and $y_{j}= - 1$ . Then, there exists a global solution to\n\n$$\n\\operatorname*{min}\\mathcal{L}(\\beta_{0},\\beta)=\\operatorname*{min}_{\\beta_{0},\\beta}\\left[\\sum_{i=1}^{n}L\\left(y_{i}(\\beta_{0}+\\mathbf{x}_{i}^{T}\\beta)\\right)/n+\\lambda\\beta^{T}\\beta\\right],\\tag{2}\n$$\n\nwhere L is the LHS loss and $\\lambda > 0$ is a tuning parameter.", "context_ids": ["v24-22-1104:ctx1", "v24-22-1104:ctx2", "v24-22-1104:ctx5", "v24-22-1104:ctx6"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}, {"label": "Theorem 6", "decls": ["theorem6"], "statement": "Theorem 6 (Classification-calibration) For any x such that $p(\\mathbf{x})\\in(0,1)$ with $p(\\mathbf{x})\\neq 1/2$ , a global minimizer of $\\operatorname{E}[L_{r}(\\mathbf{Y}f(\\mathbf{X}))\\mid\\mathbf{X}=\\mathbf{x}]$ uniquely exists and is\n\n$$\n\\begin{array}{r l}{-\\left\\{(1-p({\\bf x}))/p({\\bf x})\\right\\}^{r/(r-1)},}&{{}\\quad if~p({\\bf x})<1/2,}\\\\ {and+\\left\\{p({\\bf x})/(1-p({\\bf x}))\\right\\}^{r/(r-1)},}&{{}\\quad if~p({\\bf x})>1/2.}\\end{array}\n$$\n\nNote that sgn $\\{{\\bar{f}}({\\bf x}) \\}= f^{*}({\\bf x})$ , where $f^{*}$ is the Bayes rule.", "context_ids": ["v24-22-1104:ctx1", "v24-22-1104:ctx3", "v24-22-1104:ctx7"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "### Proof of Theorem 1\n\nFix x and let $\\alpha=f(\\mathbf{x})$ . We have\n\n$$\n\\begin{array}{r l}&{\\mathrm{E}[L(\\mathbf{Y}\\alpha)|\\mathbf{X}=\\mathbf{x}]=p(\\mathbf{x})L(\\alpha)+\\{1-p(\\mathbf{x})\\}L(-\\alpha)}\\\\ &{\\qquad=\\left\\{\\begin{array}{l l}{p(\\mathbf{x})(-\\log\\alpha)+(1-p(\\mathbf{x}))(1+\\alpha),}&{\\mathrm{if~}\\alpha>1,}\\\\ {p(\\mathbf{x})(1-\\alpha)+\\{1-p(\\mathbf{x})\\}(1+\\alpha),}&{\\mathrm{if~}-1\\leq\\alpha\\leq 1,}\\\\ {p(\\mathbf{x})(1-\\alpha)+(1-p(\\mathbf{x}))(-\\log(-\\alpha)),}&{\\mathrm{if~}\\alpha< -1.}\\end{array}\\right.}\\end{array}\n$$\n\nIf $01,}\\\\ {-p(\\mathbf{x})+\\{1-p(\\mathbf{x})\\},}&{\\mathrm{if~}-1\\leq\\alpha\\leq 1,}\\\\ {-p(\\mathbf{x})-\\{1-p(\\mathbf{x})\\}\\frac{1}{\\alpha},}&{\\mathrm{if~}\\alpha< -1.}\\end{array}\\right.\n$$\n\n$\\begin{array}{r}{\\frac{\\partial}{\\partial\\alpha}\\mathrm{E}[L(\\mathbf{Y}\\alpha)|\\mathbf{X}=\\mathbf{x}]=0}\\end{array}$ holds if and only if\n\n$$\n\\bar{f}(\\mathbf{x})=\\alpha=\\left\\{\\begin{array}{l l}{-\\frac{1-p(\\mathbf{x})}{p(\\mathbf{x})},}&{\\quad\\mathrm{if}p(\\mathbf{x})<\\frac{1}{2},}\\\\ {+\\frac{p(\\mathbf{x})}{1-p(\\mathbf{x})},}&{\\quad\\mathrm{if}p(\\mathbf{x})>\\frac{1}{2}.}\\end{array}\\right.\n$$\n\nα is the unique minimizer because $\\mathrm{E}[L({\\bf Y}\\alpha)|{\\bf X}={\\bf x}]$ is convex.\n\n### Proof of Theorem 2\n\nLet $(\\hat{\\beta}_{0},\\hat{\\pmb{\\beta}})$ be any minimizer if it exists. Without loss of generality, let's say that $p_{+}\\geq p_{-}$ where $p_{+}= \\# \\{i : y_{i}= + 1 \\}/ n > 0$ and $p_{-}= \\# \\{i : y_{i}= - 1 \\}/ n > 0$ Assume that,\n\n$$\n\\begin{array}{r}{\\left\\|(\\hat{\\beta}_{0}\\hat{\\pmb{\\beta}}^{T})^{T}\\right\\|^{2}>C_{1}^{2}+C_{2}^{2},}\\end{array}\n$$\n\nwhere,\n\n$$\nC_{1}=\\left(\\frac{p_{+}}{p_{-}}+\\frac{1}{\\sqrt{p_{-}}}+\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\sqrt{\\lambda p_{-}}}\\right)^{2}>1,\n$$\n\n$$\n\\mathrm{and}C_{2}=\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{\\lambda}+\\sqrt{\\frac{C_{1}}{\\lambda}}.\n$$\n\nSince $|L(a)-L(b)|\\leq|a-b|$ for any a, $b \\in \\mathbb{R}$\n\n$$\n\\begin{array}{r l}&{L\\left(y_{i}(\\boldsymbol{\\beta}_{0}+\\mathbf{x}_{i}^{T}\\boldsymbol{\\beta})\\right)\\geq L(y_{i}\\boldsymbol{\\beta}_{0})- |y_{i}\\mathbf{x}_{i}^{T}\\boldsymbol{\\beta}|}\\\\ &{\\qquad\\quad\\geq L(y_{i}\\boldsymbol{\\beta}_{0})- | |\\mathbf{x}_{i}| |\\cdot| |\\boldsymbol{\\beta}| |}\\\\ &{\\qquad\\quad\\geq L(y_{i}\\boldsymbol{\\beta}_{0})-\\underset{i}{\\operatorname*{max}}| |\\mathbf{x}_{i}| |\\cdot| |\\boldsymbol{\\beta}| |.}\\end{array}\n$$\n\nThen, we have\n\n$$\n\\begin{array}{l}{\\displaystyle\\mathcal{L}(\\boldsymbol{\\beta}_{0},\\boldsymbol{\\beta})\\geq\\frac{1}{n}\\sum_{i=1}^{n}L(y_{i}\\beta_{0})-\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |\\cdot| |\\boldsymbol{\\beta}| | +\\lambda| |\\boldsymbol{\\beta}| |^{2}}\\\\ {\\displaystyle\\ =\\frac{1}{n}\\sum_{i=1}^{n}L(y_{i}\\beta_{0})+\\lambda\\left(\\|\\boldsymbol{\\beta}\\|-\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}.}\\end{array}\n$$\n\n(Case 1) Suppose that $\\hat{\\beta}_{0}^{2}\\leq C_{1}^{2}$ . It implies that $| | \\hat{\\pmb{\\beta}}| |^{2}> C_{2}^{2}$ and we obtain that,\n\n$$\n\\begin{array}{r l}{\\mathcal{L}(\\hat{\\beta}_{0},\\hat{\\pmb{\\beta}})\\geq\\displaystyle\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}L(y_{i}\\hat{\\beta}_{0})+\\lambda\\left(| |\\hat{\\beta}| | -\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}&{}\\\\ {\\geq\\displaystyle\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}(1-y_{i}\\hat{\\beta}_{0})+\\lambda\\left(| |\\hat{\\beta}| | -\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}&{}\\\\ {>(1- |\\hat{\\beta}_{0}|)+\\lambda\\left(C_{2}-\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}&{}\\\\ {\\geq 1-C_{1}+\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}+\\sqrt{\\frac{C_{1}}{\\lambda}}\\right)^{2}-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}&{}\\\\ {>1=\\mathcal{L}(0,\\mathbf{0}),}\\end{array}\n$$\n\nwhich is a contradiction. The third inequality is because $\\begin{array}{r}{\\vert\\vert\\hat{\\pmb\\beta}\\vert\\vert>C_{2}>\\frac{\\operatorname*{max}_{i}\\vert\\vert\\mathbf{x}_{i}\\vert\\vert^{2}}{2\\lambda}}\\end{array}$\n\n(Case 2) Suppose ${\\hat{\\beta}}_{0}^{2}>C_{1}^{2}\\left(>1\\right)$ . log $| \\hat{\\beta}_{0}|$ is bounded by log $\\begin{array}{r}{| \\hat{\\beta}_{0}| \\le \\frac{| \\hat{\\beta}_{0}| - 1}{| \\hat{\\beta}_{0}|^{1 / 2}}}\\end{array}$ . Then we obtain that,\n\n$$\n\\begin{array}{r l}{\\mathcal{L}(\\hat{\\beta}_{0},\\hat{\\pmb{\\beta}})\\geq}&{\\displaystyle\\frac{1}{n}\\sum_{i=1}^{n}L(y_{i}\\hat{\\beta}_{0})+\\lambda\\left(| |\\hat{\\pmb{\\beta}}| | -\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}\\\\ {\\geq}&{p_{+}\\cdot(-\\log|\\hat{\\beta}_{0}|)+p_{-}\\cdot(1+ |\\hat{\\beta}_{0}|)-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}\\\\ {\\geq}&{p_{+}\\cdot\\left(-\\frac{|\\hat{\\beta}_{0}| -1}{|\\hat{\\beta}_{0}|^{1/2}}\\right)+p_{-}\\cdot(1+ |\\hat{\\beta}_{0}|)-\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}\\\\ {\\geq}&{-p_{+}|\\hat{\\beta}_{0}|^{1/2}+p_{-}|\\hat{\\beta}_{0}| -\\lambda\\left(\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\lambda}\\right)^{2}}\\\\ {=}&{p_{-}\\left(|\\hat{\\beta}_{0}|^{1/2}-\\frac{1}{2}\\frac{p_{+}}{p_{-}}\\right)^{2}-p_{-}\\left(\\frac{1}{2}\\frac{p_{+}}{p_{-}}\\right)^{2}-\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |^{2}}{4\\lambda}}\\\\ {>}&{p_{-}\\left(C_{1}^{1/2}-\\frac{1}{2}\\frac{p_{+}}{p_{-}}\\right)^{2}-p_{-}\\left(\\frac{1}{2}\\frac{p_{+}}{p_{-}}\\right)^{2}-\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |^{2}}{4\\lambda}}\\\\ {=}&{p_{-}\\left(\\frac{1}{2}\\frac{p_{+}}{p_{-}}+\\frac{1}{\\sqrt{p_{-}}}+\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |}{2\\sqrt{\\lambda p_{-}}}\\right)^{2}-p_{-}\\left(\\frac{1}{2}\\frac{p_{+}}{p_{-}}\\right)^{2}-\\frac{\\operatorname*{max}_{i}| |\\mathbf{x}_{i}| |^{2}}{4\\lambda}}\\\\ {>}&{1=\\mathcal{L}(0,\\mathbf{0}),}\\end{array}\n$$\n\nwhich is a contradiction.\n\nTherefore, we can conclude that,\n\n$$\n\\left\\|(\\hat{\\beta}_{0}\\hat{\\pmb{\\beta}}^{T})^{T}\\right\\|^{2}\\leq C_{1}^{2}+C_{2}^{2}.\n$$\n\nEventually, (2) is equivalent to minimizing a continuous function over a non-empty compact region. Therefore, there exists a global minimizer.\n\n### Proof of Theorem 6\n\nFix x and let $\\alpha=f(\\mathbf{x})$ . We have\n\n$$\n\\begin{array}{r l}&{\\mathrm{E}[L_{r}({\\mathbf Y}\\alpha)|{\\mathbf X}={\\mathbf x}]=p({\\mathbf x})L_{r}(\\alpha)+\\{1-p({\\mathbf x})\\}L_{r}(-\\alpha)}\\\\ &{\\qquad=\\left\\{\\begin{array}{l l}{p({\\mathbf x})r\\left(1-\\alpha^{1/r}\\right)+(1-p({\\mathbf x}))(1+\\alpha),}&{\\mathrm{if~}\\alpha>1,}\\\\ {p({\\mathbf x})(1-\\alpha)+(1-p({\\mathbf x}))(1+\\alpha),}&{\\mathrm{if~}-1\\le\\alpha\\le 1,}\\\\ {p({\\mathbf x})(1-\\alpha)+(1-p({\\mathbf x}))r\\left(1-(-\\alpha)^{1/r}\\right),}&{\\mathrm{if~}\\alpha< -1.}\\end{array}\\right.}\\end{array}\n$$\n\nIf $0\\frac{1}{2}.}\\end{array}\\right.\n$$\n\nα is the unique minimizer because $\\mathrm{E}[L_{r}({\\bf Y}\\alpha)|{\\bf X}={\\bf x}]$ is convex.", "context": [{"id": "v24-22-1104:ctx1", "name": "Setup: binary classification, p(x), Bayes rule (Section 1)", "statement": "This paper concerns binary classification, where the task is to predict an unobserved binary output value $y\\in\\{-1,1\\}$ based on an observed input vector $\\mathbf{x}\\in \\mathbb{R}^{p}$ . The classifier is a mapping from the input space $\\mathcal{X}$ to {−1, 1} via a classification function $\\hat{f}$, and the predicted y value is $\\mathrm{sgn}\\{\\hat{f}(\\mathbf{x})\\}$ . The decision boundary is the set $\\{\\mathbf{x}:{\\hat{f}}(\\mathbf{x})=0\\}$ . Suppose that data are generated from some underlying distribution $\\mathrm{pr}(\\mathbf{X},\\mathbf{Y})$ , and let $p(\\mathbf{x})=\\mathrm{pr}(\\mathbf{Y}=1\\mid$ $\\mathbf{X}= \\mathbf{x})$ Under the standard 0-1 loss, the optimal classification rule is sgn $[p(\\mathbf{x})-1/2]$ (a.k.a. Bayes rule). Throughout the paper, we assume that $p(\\mathbf{X})\\neq 1/2$ almost surely. The optimal decision boundary is $\\{\\mathbf{x}:p(\\mathbf{x})=1/2\\}$ Given training data, $\\{({\\bf x}_{i},y_{i}),i=$ $1,\\ldots,n\\}$ , one aims to develop a classifier that mimics the Bayes rule as closely as possible."}, {"id": "v24-22-1104:ctx2", "name": "LHS loss, eq. (1)", "statement": "In this paper, we provide an affirmative answer and the new function called the leaky hockey stick loss (LHS loss). The expression of the LHS loss is given in (1) and the picture of this loss function is displayed in Figure 1. We use the word 'hockey stick' because our loss function resembles it and is continuously differentiable. We use the term 'leaky' because the right side diverges to negative infinity motivated by the name of leaky ReLU.\n\n$$\nL(yf)=\\left\\{{\\begin{array}{l l}{-\\log yf,}&{yf>1,}\\\\ {1-yf,}&{yf\\leq 1,}\\end{array}}\\right.\\tag{1}\n$$"}, {"id": "v24-22-1104:ctx3", "name": "Classification-calibration and Fisher consistency (Section 2)", "statement": "Lin (2004) proposed Fisher consistency as a necessary condition on a loss function. It is defined to be that any global minimizer $\\check{f}$ (if it exists) of $\\operatorname{E}[L(\\mathbf{Y}f(\\mathbf{X}))]$ , generally referred to as a population minimizer, has the same sign function as the Bayes rule almost surely. Later, Bartlett et al. (2006) defined classification-calibration. A loss function L is called classification-calibrated if any global minimizer $\\bar{f}$ (if it exists) of $\\operatorname{E}[L(\\mathbf{Y}f(\\mathbf{X}))\\mid\\mathbf{X}=\\mathbf{x}]$ has the same sign as the Bayes rule almost surely. For example, the hinge loss is classification-calibrated, which can be directly shown by Theorem 2 of Bartlett et al. (2006).\n\nAn unspoken assumption in those two definitions is the existence of a global minimizer. When $\\bar{f}$ exists (which can be easily checked) and $|\\mathrm{E}[L({\\bf Y}\\bar{f}({\\bf X}))]| <\\infty .$ then a population minimizer $\\check{f}$ exists. We further see that loss function L is classification-calibrated if and only if it is Fisher consistent. The 'if' statement follows from the fact that any $\\bar{f}$ is also a population minimizer and the definition of Fisher consistency. The 'only if' statement comes from the fact that $\\operatorname{E}[L(\\mathbf{Y}{\\bar{f}}(\\mathbf{X}))\\mid\\mathbf{X}]=\\operatorname{E}[L(\\mathbf{Y}{\\check{f}}(\\mathbf{X}))\\mid\\mathbf{X}]$ almost surely and that for any $\\delta_{\\mathbf{X}}$ such that $\\operatorname{sgn}(\\delta_{\\mathbf{X}})\\neq\\operatorname{sgn}(p(\\mathbf{X})-1/2),\\operatorname{E}[L(\\mathbf{Y}{\\bar{f}}(\\mathbf{X}))\\mid\\mathbf{X}]<\\operatorname{E}[L(\\mathbf{Y}\\delta_{\\mathbf{X}})\\mid\\mathbf{X}]$ almost surely by the definition of classification-calibration.\n\nFor a non-negative loss function L, $\\operatorname{E}[L(\\mathbf{Y}\\bar{f}(\\mathbf{X}))]$ is always finite. However, the LHS loss does not guarantee the finiteness of $\\operatorname{E}[L(\\mathbf{Y}\\bar{f}(\\mathbf{X}))]$ (see Theorem 4 for further information), thereby not ensuring the existence of a global minimizer that Fisher consistency implicitly assumes. Instead, we verify that the LHS loss is classification-calibrated. The LHS loss is the first negatively divergent loss function proven to satisfy the classification-calibration property."}, {"id": "v24-22-1104:ctx4", "name": "Remark 1 (why p(x) in (0,1))", "statement": "Remark 1 In general, a global minimizer of $\\operatorname{E}[L(\\mathbf{Y}f(\\mathbf{X}))\\mid\\mathbf{X}=\\mathbf{x}]$ is allowed to take values $\\pm \\infty$ because what matters is only the sign of the minimizer $(Lin,~2004)$ If we allow the minimum objective to take values $\\pm \\infty$ , Theorem 1 can be extended to include $p(\\mathbf{x})$ equals to 0 and 1. It is because if $p(\\mathbf{x})=0$, then $\\operatorname{E}[L(\\mathbf{Y}\\alpha)\\mid\\mathbf{X}=\\mathbf{x}]=L(-\\alpha)\\to-\\infty$ as $\\alpha \\to - \\infty$. If $p ({\\bf x}) = 1$ , then $\\operatorname{E}[L(\\mathbf{Y}f(\\mathbf{X}))\\mid\\mathbf{X}=\\mathbf{x}]=L(\\alpha)\\to-\\infty$ as $\\alpha \\to \\infty$."}, {"id": "v24-22-1104:ctx5", "name": "Existence approach for the linear LHS classifier (Section 3.1)", "statement": "When L is a non-negative continuous loss function, there exists a global minimizer to the regularized ERM problem. Proving existence is considered well-understood. The sublevel set of the objective function L of the regularized ERM problem, $\\{\\beta:{\\mathcal{L}}(\\beta)\\leq c\\}$ , is compact for any $c \\in \\mathbb{R}$ , and the global minimizer of the continuous objective function on a compact set must exist by the extreme value theorem.\n\nIn contrast, it is not trivial to show the existence of a global minimizer of the linear LHS classifier. The loss term in the regularized ERM can diverge to negative infinity even though the LHS loss is convex and training data have finite samples. To show the existence, we find a specific compact set D of $\\beta,$ so that the objective function of the linear LHS classifier can have a global minimizer on D. Then, we show that the objective value at the global minimizer on D is always smaller than any objective value on $D^{c}$"}, {"id": "v24-22-1104:ctx6", "name": "Remark 2 (uniqueness of the linear LHS solution)", "statement": "Remark 2 (Uniqueness) The minimizer $\\hat{\\boldsymbol{\\beta}}$ is uniquely determined because the LHS loss is convex and the $\\ell_{2}$ regularizer is strictly convex. However, $\\hat{\\beta}_{0}$ may not. Here is an illustrative example. Let the data be\n\n$$\n\\begin{array}{r l r l r l}{y_{1}= -1,}&{{}y_{2}= -1,}&{}&{{}y_{3}=1,}&{}&{{}y_{4}=1,}\\\\ {x_{1}=1,}&{{}x_{2}= -1,}&{}&{{}x_{3}=1,}&{}&{{}x_{4}= -1.}\\end{array}\n$$\n\nThen both $(0,0)$ and $(1,0)$ are global minimizers. Non-uniqueness of the intercept term can also occur in the linear SVM."}, {"id": "v24-22-1104:ctx7", "name": "Loss family L_r, eq. (15) (Section 7.2)", "statement": "We define a negatively divergent loss functions $L_{r}$ as follows: with $r\\in(1,\\infty)$,\n\n$$\nL_{r}(yf)={\\left\\{\\begin{array}{l l}{r\\left(1-(yf)^{1/r}\\right),}&{yf>1,}\\\\ {1-yf,}&{yf\\leq 1.}\\end{array}\\right.}\\tag{15}\n$$\n\nFigure 3 illustrates (15) for various r values. Note the LHS loss is (15) with r diverging to ∞."}], "lean": "import Mathlib\n\nopen scoped BigOperators\n\nnamespace ResearchLevel\n\nnoncomputable def lhs (u : ℝ) : ℝ := if 1 < u then -Real.log u else 1 - u\n\nnoncomputable def condRisk (p α : ℝ) : ℝ := p * lhs α + (1 - p) * lhs (-α)\n\nnoncomputable def fbar (p : ℝ) : ℝ := if p < 1 / 2 then -(1 - p) / p else p / (1 - p)\n\nnoncomputable def objective {n p : ℕ} (xs : Fin n → (Fin p → ℝ)) (ys : Fin n → ℝ)\n (lam : ℝ) (b0 : ℝ) (b : Fin p → ℝ) : ℝ :=\n (∑ i, lhs (ys i * (b0 + ∑ k, xs i k * b k))) / n + lam * (∑ k, b k * b k)\n\nnoncomputable def lhsR (r u : ℝ) : ℝ := if 1 < u then r * (1 - u ^ (1 / r)) else 1 - u\n\nnoncomputable def condRiskR (r p α : ℝ) : ℝ := p * lhsR r α + (1 - p) * lhsR r (-α)\n\nnoncomputable def fbarR (r p : ℝ) : ℝ :=\n if p < 1 / 2 then -(((1 - p) / p) ^ (r / (r - 1))) else (p / (1 - p)) ^ (r / (r - 1))\n\ntheorem theorem1 {p : ℝ} (hp0 : 0 < p) (hp1 : p < 1) (hne : p ≠ 1 / 2) :\n (∀ α : ℝ, condRisk p (fbar p) ≤ condRisk p α) ∧\n (∀ α : ℝ, (∀ β : ℝ, condRisk p α ≤ condRisk p β) → α = fbar p) ∧\n Real.sign (fbar p) = Real.sign (p - 1 / 2) := by\n sorry\n\ntheorem theorem2 {n p : ℕ} (xs : Fin n → (Fin p → ℝ)) (ys : Fin n → ℝ)\n (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (hpos : ∃ i, ys i = 1) (hneg : ∃ j, ys j = -1)\n {lam : ℝ} (hlam : 0 < lam) :\n ∃ b0 : ℝ, ∃ b : Fin p → ℝ, ∀ c0 : ℝ, ∀ c : Fin p → ℝ,\n objective xs ys lam b0 b ≤ objective xs ys lam c0 c := by\n sorry\n\ntheorem theorem6 {r p : ℝ} (hr : 1 < r) (hp0 : 0 < p) (hp1 : p < 1) (hne : p ≠ 1 / 2) :\n (∀ α : ℝ, condRiskR r p (fbarR r p) ≤ condRiskR r p α) ∧\n (∀ α : ℝ, (∀ β : ℝ, condRiskR r p α ≤ condRiskR r p β) → α = fbarR r p) ∧\n Real.sign (fbarR r p) = Real.sign (p - 1 / 2) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen scoped BigOperators\n\nnamespace ResearchLevel\n\nnoncomputable def lhs (u : ℝ) : ℝ := if 1 < u then -Real.log u else 1 - u\n\nnoncomputable def condRisk (p α : ℝ) : ℝ := p * lhs α + (1 - p) * lhs (-α)\n\nnoncomputable def fbar (p : ℝ) : ℝ := if p < 1 / 2 then -(1 - p) / p else p / (1 - p)\n\nnoncomputable def objective {n p : ℕ} (xs : Fin n → (Fin p → ℝ)) (ys : Fin n → ℝ)\n (lam : ℝ) (b0 : ℝ) (b : Fin p → ℝ) : ℝ :=\n (∑ i, lhs (ys i * (b0 + ∑ k, xs i k * b k))) / n + lam * (∑ k, b k * b k)\n\nnoncomputable def lhsR (r u : ℝ) : ℝ := if 1 < u then r * (1 - u ^ (1 / r)) else 1 - u\n\nnoncomputable def condRiskR (r p α : ℝ) : ℝ := p * lhsR r α + (1 - p) * lhsR r (-α)\n\nnoncomputable def fbarR (r p : ℝ) : ℝ :=\n if p < 1 / 2 then -(((1 - p) / p) ^ (r / (r - 1))) else (p / (1 - p)) ^ (r / (r - 1))\n\nprivate lemma lhs_le' {u : ℝ} (h : u ≤ 1) : lhs u = 1 - u := by\n simp only [lhs, if_neg (not_lt.2 h)]\n\nprivate lemma lhs_gt' {u : ℝ} (h : 1 < u) : lhs u = -Real.log u := by\n simp only [lhs, if_pos h]\n\nprivate lemma lhsR_le' {r u : ℝ} (h : u ≤ 1) : lhsR r u = 1 - u := by\n simp only [lhsR, if_neg (not_lt.2 h)]\n\nprivate lemma lhsR_gt' {r u : ℝ} (h : 1 < u) : lhsR r u = r * (1 - u ^ (1/r)) := by\n simp only [lhsR, if_pos h]\n\nprivate lemma bern {s t : ℝ} (hs0 : 0 < s) (hs1 : s < 1) (ht : 0 < t) (hne : t ≠ 1) :\n t ^ s < 1 + s * (t - 1) := by\n have hlog : Real.log t ≠ 0 := by\n intro h; apply hne; rw [← Real.exp_log ht, h, Real.exp_zero]\n have hc := strictConvexOn_exp.2 (Set.mem_univ (Real.log t)) (Set.mem_univ (0:ℝ))\n hlog hs0 (by linarith : (0:ℝ) < 1 - s) (by ring)\n simp only [smul_eq_mul, mul_zero, add_zero, Real.exp_zero, mul_one, Real.exp_log ht] at hc\n rw [Real.rpow_def_of_pos ht, mul_comm (Real.log t) s]\n linarith\n\nprivate lemma main1 {p : ℝ} (hq0 : 0 < 1 - p) (hpq : 1 - p < p) (α : ℝ)\n (hne : α ≠ p / (1 - p)) : condRisk p (p / (1 - p)) < condRisk p α := by\n have hp0 : 0 < p := by linarith\n set q : ℝ := 1 - p with hqdef\n set a : ℝ := p / q with hadef\n have ha0 : 0 < a := div_pos hp0 hq0\n have ha1 : 1 < a := (one_lt_div hq0).2 hpq\n have hpa : p = q * a := by rw [hadef]; field_simp\n have hCa : condRisk p a = p * (-Real.log a) + q * (1 + a) := by\n simp only [condRisk, ← hqdef, lhs_gt' ha1, lhs_le' (by linarith : -a ≤ 1)] <;> ring\n -- main inequality for positive α\n have key : ∀ β : ℝ, 0 < β → β ≠ a →\n p * (-Real.log a) + q * (1 + a) < p * (-Real.log β) + q * (1 + β) := by\n intro β hβ hβa\n have hd : Real.log (β / a) < β / a - 1 :=\n Real.log_lt_sub_one_of_pos (div_pos hβ ha0) (by\n intro h; exact hβa (by field_simp at h; linarith))\n have hdiv : Real.log (β / a) = Real.log β - Real.log a :=\n Real.log_div (ne_of_gt hβ) (ne_of_gt ha0)\n have h3 : p * Real.log (β / a) < p * (β / a - 1) := by\n exact mul_lt_mul_of_pos_left hd hp0\n have h4 : p * (β / a - 1) = q * (β - a) := by\n rw [hpa]; field_simp\n rw [hdiv] at h3\n linarith\n have h2q : condRisk p a < 2 * q := by\n have h := key 1 one_pos (by intro h; rw [← h] at ha1; linarith)\n rw [Real.log_one] at h\n rw [hCa]\n linarith\n by_cases h1 : 1 < α\n · have hCα : condRisk p α = p * (-Real.log α) + q * (1 + α) := by\n simp only [condRisk, ← hqdef, lhs_gt' h1, lhs_le' (by linarith : -α ≤ 1)] <;> ring\n rw [hCa, hCα]\n exact key α (by linarith) hne\n · push_neg at h1\n by_cases h2 : -1 ≤ α\n · have hCα : condRisk p α = p * (1 - α) + q * (1 + α) := by\n simp only [condRisk, ← hqdef, lhs_le' h1, lhs_le' (by linarith : -α ≤ 1)]\n ring\n rw [hCα]\n nlinarith [h2q]\n · push_neg at h2\n have hCα : condRisk p α = p * (1 - α) + q * (-Real.log (-α)) := by\n simp only [condRisk, ← hqdef, lhs_le' h1, lhs_gt' (by linarith : (1:ℝ) < -α)] <;> ring\n have hl : Real.log (-α) ≤ -α - 1 := Real.log_le_sub_one_of_pos (by linarith)\n rw [hCα]\n nlinarith [h2q]\n\nprivate lemma sym1 (p α : ℝ) : condRisk p α = condRisk (1 - p) (-α) := by\n simp only [condRisk, neg_neg]\n ring\n\nprivate lemma main6 {r p : ℝ} (hr : 1 < r) (hq0 : 0 < 1 - p) (hpq : 1 - p < p) (α : ℝ)\n (hne : α ≠ (p / (1 - p)) ^ (r / (r - 1))) :\n condRiskR r p ((p / (1 - p)) ^ (r / (r - 1))) < condRiskR r p α := by\n have hp0 : 0 < p := by linarith\n have hr0 : 0 < r := by linarith\n have hr1 : 0 < r - 1 := by linarith\n have hrr : r * (1 / r) = 1 := by field_simp\n set q : ℝ := 1 - p with hqdef\n have hs0 : 0 < 1 / r := by positivity\n have hs1 : 1 / r < 1 := by rw [div_lt_one hr0]; linarith\n set x : ℝ := p / q with hxdef\n have hx0 : 0 < x := div_pos hp0 hq0\n have hx1 : 1 < x := (one_lt_div hq0).2 hpq\n set a : ℝ := x ^ (r / (r - 1)) with hadef\n have ha1 : 1 < a := by\n have h := (Real.rpow_lt_rpow_left_iff hx1).2 (show (0:ℝ) < r / (r-1) by positivity)\n rwa [Real.rpow_zero] at h\n have ha0 : 0 < a := by linarith\n have hA0 : 0 < a ^ (1 / r) := Real.rpow_pos_of_pos ha0 _\n have hpa : p * a ^ (1 / r) = q * a := by\n have e1 : a ^ (1 / r) = x ^ (1 / (r - 1)) := by\n rw [hadef, ← Real.rpow_mul hx0.le]\n congr 1\n field_simp\n have e2 : a = x ^ (1 / (r - 1)) * x := by\n rw [hadef, show r / (r - 1) = 1 / (r - 1) + 1 by field_simp; ring, Real.rpow_add hx0,\n Real.rpow_one]\n have hqx : q * x = p := by rw [hxdef]; field_simp\n rw [e1, e2, ← hqx]\n ring\n have hCa : condRiskR r p a = p * (r * (1 - a ^ (1/r))) + q * (1 + a) := by\n simp only [condRiskR, ← hqdef, lhsR_gt' ha1, lhsR_le' (by linarith : -a ≤ 1)] <;> ring\n have key : ∀ β : ℝ, 0 < β → β ≠ a →\n p * (r * (1 - a ^ (1/r))) + q * (1 + a) < p * (r * (1 - β ^ (1/r))) + q * (1 + β) := by\n intro β hβ hβa\n have hb : (β / a) ^ (1/r) < 1 + (1/r) * (β / a - 1) :=\n bern hs0 hs1 (div_pos hβ ha0) (by\n intro h\n apply hβa\n field_simp at h\n linarith)\n have hsplit : β ^ (1/r) = a ^ (1/r) * (β / a) ^ (1/r) := by\n rw [Real.div_rpow hβ.le ha0.le]\n field_simp\n have step : β ^ (1/r) - a ^ (1/r) < a ^ (1/r) * ((1/r) * (β / a - 1)) := by\n rw [hsplit]; nlinarith [hA0, hb]\n have step2 : p * r * (β ^ (1/r) - a ^ (1/r))\n < p * r * (a ^ (1/r) * ((1/r) * (β / a - 1))) :=\n mul_lt_mul_of_pos_left step (by positivity)\n have heq : p * r * (a ^ (1/r) * ((1/r) * (β / a - 1))) = q * (β - a) := by\n have h1 : p * r * (a ^ (1/r) * ((1/r) * (β / a - 1)))\n = (p * a ^ (1/r)) * ((β - a) / a) := by\n field_simp\n rw [h1, hpa]\n field_simp\n rw [heq] at step2\n nlinarith [step2]\n have h2q : condRiskR r p a < 2 * q := by\n have h := key 1 one_pos (by intro h; rw [← h] at ha1; linarith)\n rw [hCa]\n rw [Real.one_rpow] at h\n linarith\n by_cases h1 : 1 < α\n · have hCα : condRiskR r p α = p * (r * (1 - α ^ (1/r))) + q * (1 + α) := by\n simp only [condRiskR, ← hqdef, lhsR_gt' h1, lhsR_le' (by linarith : -α ≤ 1)] <;> ring\n rw [hCa, hCα]\n exact key α (by linarith) hne\n · push_neg at h1\n by_cases h2 : -1 ≤ α\n · have hCα : condRiskR r p α = p * (1 - α) + q * (1 + α) := by\n simp only [condRiskR, ← hqdef, lhsR_le' h1, lhsR_le' (by linarith : -α ≤ 1)]\n ring\n rw [hCα]\n nlinarith [h2q]\n · push_neg at h2\n have hCα : condRiskR r p α = p * (1 - α) + q * (r * (1 - (-α) ^ (1/r))) := by\n simp only [condRiskR, ← hqdef, lhsR_le' h1, lhsR_gt' (by linarith : (1:ℝ) < -α)] <;> ring\n have hb : (-α) ^ (1/r) < 1 + (1/r) * (-α - 1) :=\n bern hs0 hs1 (by linarith) (by intro h; linarith)\n have hmul := mul_lt_mul_of_pos_left hb hr0\n have hgt : α + 1 < r * (1 - (-α) ^ (1/r)) := by nlinarith [hmul, hrr]\n rw [hCα]\n nlinarith [h2q, hgt]\n\nprivate lemma sym6 (r p α : ℝ) : condRiskR r p α = condRiskR r (1 - p) (-α) := by\n simp only [condRiskR, neg_neg]\n ring\n\ntheorem theorem1 {p : ℝ} (hp0 : 0 < p) (hp1 : p < 1) (hne : p ≠ 1 / 2) :\n (∀ α : ℝ, condRisk p (fbar p) ≤ condRisk p α) ∧\n (∀ α : ℝ, (∀ β : ℝ, condRisk p α ≤ condRisk p β) → α = fbar p) ∧\n Real.sign (fbar p) = Real.sign (p - 1 / 2) := by\n have hstrict : ∀ α : ℝ, α ≠ fbar p → condRisk p (fbar p) < condRisk p α := by\n rcases lt_or_gt_of_ne hne with hlt | hgt\n · intro α hα\n have hf : fbar p = -((1 - p) / p) := by\n simp only [fbar, if_pos hlt, neg_div]\n have h := main1 (p := 1 - p) (by linarith) (by linarith)\n simp only [sub_sub_cancel] at h\n rw [hf] at hα ⊢\n rw [sym1 p, neg_neg, sym1 p α]\n exact h (-α) (by intro hc; exact hα (by linarith))\n · intro α hα\n have hf : fbar p = p / (1 - p) := by\n simp only [fbar, if_neg (by push_neg; linarith : ¬ p < 1 / 2)]\n rw [hf] at hα ⊢\n exact main1 (by linarith) (by linarith) α hα\n refine ⟨fun α => ?_, fun α hα => ?_, ?_⟩\n · rcases eq_or_ne α (fbar p) with h | h\n · rw [h]\n · exact (hstrict α h).le\n · by_contra hc\n exact absurd (hα (fbar p)) (not_le.2 (hstrict α hc))\n · rcases lt_or_gt_of_ne hne with hlt | hgt\n · have hf : fbar p = -((1 - p) / p) := by\n simp only [fbar, if_pos hlt, neg_div]\n rw [hf, Real.sign_of_neg (by\n have : 0 < (1 - p) / p := div_pos (by linarith) hp0\n linarith), Real.sign_of_neg (by linarith)]\n · have hf : fbar p = p / (1 - p) := by\n simp only [fbar, if_neg (by push_neg; linarith : ¬ p < 1 / 2)]\n rw [hf, Real.sign_of_pos (div_pos hp0 (by linarith)),\n Real.sign_of_pos (by linarith)]\n\ntheorem theorem6 {r p : ℝ} (hr : 1 < r) (hp0 : 0 < p) (hp1 : p < 1) (hne : p ≠ 1 / 2) :\n (∀ α : ℝ, condRiskR r p (fbarR r p) ≤ condRiskR r p α) ∧\n (∀ α : ℝ, (∀ β : ℝ, condRiskR r p α ≤ condRiskR r p β) → α = fbarR r p) ∧\n Real.sign (fbarR r p) = Real.sign (p - 1 / 2) := by\n have hstrict : ∀ α : ℝ, α ≠ fbarR r p → condRiskR r p (fbarR r p) < condRiskR r p α := by\n rcases lt_or_gt_of_ne hne with hlt | hgt\n · intro α hα\n have hf : fbarR r p = -(((1 - p) / p) ^ (r / (r - 1))) := by\n simp only [fbarR, if_pos hlt]\n have h := main6 (p := 1 - p) hr (by linarith) (by linarith)\n simp only [sub_sub_cancel] at h\n rw [hf] at hα ⊢\n rw [sym6 r p, neg_neg, sym6 r p α]\n exact h (-α) (by intro hc; exact hα (by linarith))\n · intro α hα\n have hf : fbarR r p = (p / (1 - p)) ^ (r / (r - 1)) := by\n simp only [fbarR, if_neg (by push_neg; linarith : ¬ p < 1 / 2)]\n rw [hf] at hα ⊢\n exact main6 hr (by linarith) (by linarith) α hα\n refine ⟨fun α => ?_, fun α hα => ?_, ?_⟩\n · rcases eq_or_ne α (fbarR r p) with h | h\n · rw [h]\n · exact (hstrict α h).le\n · by_contra hc\n exact absurd (hα (fbarR r p)) (not_le.2 (hstrict α hc))\n · rcases lt_or_gt_of_ne hne with hlt | hgt\n · have hf : fbarR r p = -(((1 - p) / p) ^ (r / (r - 1))) := by\n simp only [fbarR, if_pos hlt]\n rw [hf, Real.sign_of_neg (by\n have : 0 < ((1 - p) / p) ^ (r / (r - 1)) :=\n Real.rpow_pos_of_pos (div_pos (by linarith) hp0) _\n linarith), Real.sign_of_neg (by linarith)]\n · have hf : fbarR r p = (p / (1 - p)) ^ (r / (r - 1)) := by\n simp only [fbarR, if_neg (by push_neg; linarith : ¬ p < 1 / 2)]\n rw [hf, Real.sign_of_pos (Real.rpow_pos_of_pos (div_pos hp0 (by linarith)) _),\n Real.sign_of_pos (by linarith)]\n\nprivate lemma lhs_ge_lin (u : ℝ) : 1 - u ≤ lhs u := by\n by_cases h : 1 < u\n · rw [lhs_gt' h]\n have := Real.log_le_sub_one_of_pos (by linarith : (0:ℝ) < u)\n linarith\n · rw [lhs_le' (not_lt.1 h)]\n\nprivate lemma lhs_ge_log {u T : ℝ} (h : |u| ≤ T) : -Real.log (1 + T) ≤ lhs u := by\n have hT : 0 ≤ T := le_trans (abs_nonneg u) h\n by_cases h1 : 1 < u\n · rw [lhs_gt' h1]\n have h2 : u ≤ 1 + T := by\n have := le_abs_self u\n linarith\n have := Real.log_le_log (by linarith : (0:ℝ) < u) h2\n linarith\n · rw [lhs_le' (not_lt.1 h1)]\n have : 0 ≤ Real.log (1 + T) := Real.log_nonneg (by linarith)\n have h2 : u ≤ 1 := not_lt.1 h1\n linarith\n\nprivate lemma sum_lb {m : ℕ} (f : Fin m → ℝ) (i0 : Fin m) (A L : ℝ) (hA : A ≤ f i0)\n (hL : ∀ i, L ≤ f i) (hL0 : L ≤ 0) : A + (m : ℝ) * L ≤ ∑ i, f i := by\n rw [← Finset.add_sum_erase _ f (Finset.mem_univ i0)]\n have h1 : ((Finset.univ.erase i0).card : ℝ) * L ≤ ∑ i ∈ Finset.univ.erase i0, f i := by\n have := Finset.card_nsmul_le_sum (Finset.univ.erase i0) f L (fun i _ => hL i)\n simpa [nsmul_eq_mul] using this\n have h2 : ((Finset.univ.erase i0).card : ℝ) ≤ (m : ℝ) := by\n have := Finset.card_le_card (Finset.erase_subset i0 (Finset.univ : Finset (Fin m)))\n simp only [Finset.card_univ, Fintype.card_fin] at this\n exact_mod_cast this\n have h3 : (m : ℝ) * L ≤ ((Finset.univ.erase i0).card : ℝ) * L :=\n mul_le_mul_of_nonpos_right h2 hL0\n linarith\n\nprivate lemma log_scale_bound {y c : ℝ} (hy : 0 < y) (hc : 0 < c) :\n Real.log y ≤ y / c - 1 + Real.log c := by\n have h : Real.log y = Real.log (y / c) + Real.log c := by\n rw [Real.log_div (ne_of_gt hy) (ne_of_gt hc)]; ring\n have := Real.log_le_sub_one_of_pos (div_pos hy hc)\n linarith\n\nprivate lemma lhs_continuous : Continuous lhs := by\n have heq : lhs = fun u : ℝ => if u ≤ 1 then 1 - u else -Real.log (max u 1) := by\n funext u\n simp only [lhs]\n by_cases h : u ≤ 1\n · rw [if_neg (not_lt.2 h), if_pos h]\n · push_neg at h\n rw [if_pos h, if_neg (not_le.2 h), max_eq_left h.le]\n rw [heq]\n have hg : Continuous fun u : ℝ => -Real.log (max u 1) := by\n refine Continuous.neg (Real.continuousOn_log.comp_continuous\n (continuous_id.max continuous_const) ?_)\n intro x\n simp only [Set.mem_compl_iff, Set.mem_singleton_iff]\n have h1 : (1:ℝ) ≤ max x 1 := le_max_right _ _\n intro h\n rw [h] at h1\n linarith\n exact Continuous.if_le (continuous_const.sub continuous_id) hg continuous_id\n continuous_const (fun x hx => by rw [hx]; simp)\n\nset_option maxHeartbeats 2000000 in\ntheorem theorem2 {n p : ℕ} (xs : Fin n → (Fin p → ℝ)) (ys : Fin n → ℝ)\n (hy : ∀ i, ys i = 1 ∨ ys i = -1)\n (hpos : ∃ i, ys i = 1) (hneg : ∃ j, ys j = -1)\n {lam : ℝ} (hlam : 0 < lam) :\n ∃ b0 : ℝ, ∃ b : Fin p → ℝ, ∀ c0 : ℝ, ∀ c : Fin p → ℝ,\n objective xs ys lam b0 b ≤ objective xs ys lam c0 c := by\n obtain ⟨i0, hi0⟩ := hpos\n obtain ⟨j0, hj0⟩ := hneg\n have hn0 : 0 < n := i0.pos\n have hnR : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn0\n set M : ℝ := ∑ i, ∑ k, |xs i k| with hMdef\n have hM0 : 0 ≤ M := by\n rw [hMdef]; positivity\n have hlin : ∀ (b : Fin p → ℝ) (i : Fin n), |∑ k, xs i k * b k| ≤ M * ‖b‖ := by\n intro b i\n calc |∑ k, xs i k * b k| ≤ ∑ k, |xs i k * b k| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ k, |xs i k| * ‖b‖ := by\n refine Finset.sum_le_sum (fun k _ => ?_)\n rw [abs_mul]\n exact mul_le_mul_of_nonneg_left\n (by simpa [Real.norm_eq_abs] using norm_le_pi_norm b k) (abs_nonneg _)\n _ = (∑ k, |xs i k|) * ‖b‖ := by rw [Finset.sum_mul]\n _ ≤ M * ‖b‖ := by\n refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg b)\n rw [hMdef]\n exact Finset.single_le_sum (f := fun i => ∑ k, |xs i k|)\n (fun i _ => Finset.sum_nonneg (fun k _ => abs_nonneg _)) (Finset.mem_univ i)\n set c : ℝ := 2 * (n:ℝ) * (1 + M) + 1 with hcdef\n have hc0 : 0 < c := by rw [hcdef]; positivity\n set K : ℝ := (1 + M)^2 / (4 * (n:ℝ) * lam) with hKdef\n have hK0 : 0 ≤ K := by rw [hKdef]; positivity\n set R : ℝ := 2 * ((n:ℝ) + K + (n:ℝ) * Real.log c) + 2 with hRdef\n have hbig : ∀ z : ℝ × (Fin p → ℝ), R ≤ ‖z‖ → 1 ≤ objective xs ys lam z.1 z.2 := by\n rintro ⟨b0, b⟩ hz\n simp only at hz ⊢\n set N : ℝ := ‖(b0, b)‖ with hNdef\n have hb0 : |b0| ≤ N := by\n rw [hNdef, Prod.norm_def]\n exact le_trans (le_of_eq (Real.norm_eq_abs b0).symm) (le_max_left _ _)\n have hbn : ‖b‖ ≤ N := by\n rw [hNdef, Prod.norm_def]; exact le_max_right _ _\n have hbn0 : (0:ℝ) ≤ ‖b‖ := norm_nonneg b\n have hN : N ≤ |b0| + ‖b‖ := by\n rw [hNdef, Prod.norm_def, Real.norm_eq_abs]\n exact max_le (by linarith) (by linarith [abs_nonneg b0])\n set T : ℝ := |b0| + M * ‖b‖ with hTdef\n have hT0 : 0 ≤ T := by rw [hTdef]; positivity\n set L : ℝ := -Real.log (1 + T) with hLdef\n have hL0 : L ≤ 0 := by\n rw [hLdef]\n simp only [neg_nonpos]\n exact Real.log_nonneg (by linarith)\n have habs : ∀ i, |ys i * (b0 + ∑ k, xs i k * b k)| ≤ T := by\n intro i\n have h1 : |ys i| = 1 := by rcases hy i with h | h <;> rw [h] <;> simp\n rw [abs_mul, h1, one_mul]\n calc |b0 + ∑ k, xs i k * b k| ≤ |b0| + |∑ k, xs i k * b k| := abs_add_le _ _\n _ ≤ T := by have := hlin b i; rw [hTdef]; linarith\n have hLall : ∀ i, L ≤ lhs (ys i * (b0 + ∑ k, xs i k * b k)) := fun i =>\n lhs_ge_log (habs i)\n set A : ℝ := 1 + |b0| - M * ‖b‖ with hAdef\n have hex : ∃ i, A ≤ lhs (ys i * (b0 + ∑ k, xs i k * b k)) := by\n by_cases hb0s : 0 ≤ b0\n · refine ⟨j0, ?_⟩\n have h1 := lhs_ge_lin (ys j0 * (b0 + ∑ k, xs j0 k * b k))\n rw [hj0] at h1\n have h2 := hlin b j0\n have h3 : |b0| = b0 := abs_of_nonneg hb0s\n rw [hAdef, h3]\n have h4 := abs_le.1 h2\n rw [hj0]\n linarith [h4.1, h4.2]\n · push_neg at hb0s\n refine ⟨i0, ?_⟩\n have h1 := lhs_ge_lin (ys i0 * (b0 + ∑ k, xs i0 k * b k))\n rw [hi0] at h1\n have h2 := hlin b i0\n have h3 : |b0| = -b0 := abs_of_neg hb0s\n rw [hAdef, h3]\n have h4 := abs_le.1 h2\n rw [hi0]\n linarith [h4.1, h4.2]\n obtain ⟨istar, hstar⟩ := hex\n have hsum : A + (n:ℝ) * L ≤ ∑ i, lhs (ys i * (b0 + ∑ k, xs i k * b k)) :=\n sum_lb _ istar A L hstar hLall hL0\n have hnormsq : ‖b‖^2 ≤ ∑ k, b k * b k := by\n have hS : (0:ℝ) ≤ ∑ k, b k * b k := Finset.sum_nonneg (fun k _ => mul_self_nonneg _)\n have h1 : ‖b‖ ≤ Real.sqrt (∑ k, b k * b k) := by\n refine (pi_norm_le_iff_of_nonneg (Real.sqrt_nonneg _)).2 (fun k => ?_)\n rw [Real.norm_eq_abs, ← Real.sqrt_mul_self_eq_abs]\n exact Real.sqrt_le_sqrt\n (Finset.single_le_sum (f := fun k => b k * b k)\n (fun k _ => mul_self_nonneg _) (Finset.mem_univ k))\n have h2 := Real.sq_sqrt hS\n nlinarith [norm_nonneg b, Real.sqrt_nonneg (∑ k, b k * b k)]\n have hobj : (n:ℝ) * objective xs ys lam b0 b\n = (∑ i, lhs (ys i * (b0 + ∑ k, xs i k * b k))) + (n:ℝ) * lam * (∑ k, b k * b k) := by\n simp only [objective]\n field_simp\n have hKeq : 4 * (n:ℝ) * lam * K = (1 + M)^2 := by\n rw [hKdef]; field_simp\n have h5 : 1 + N - K ≤ A + (n:ℝ) * lam * ‖b‖^2 := by\n rw [hAdef]\n nlinarith [sq_nonneg (2 * (n:ℝ) * lam * ‖b‖ - (1 + M)), hKeq, hnR, hlam, hN, hbn0, hM0,\n mul_pos hnR hlam]\n have hN0 : 0 ≤ N := norm_nonneg _\n have hTN : T ≤ (1 + M) * N := by\n rw [hTdef]; nlinarith [hb0, hbn, hM0, abs_nonneg b0]\n have hlog1 : Real.log (1 + T) ≤ Real.log (1 + (1 + M) * N) :=\n Real.log_le_log (by linarith) (by linarith)\n have hlog2 : Real.log (1 + (1 + M) * N) ≤ (1 + (1 + M) * N) / c - 1 + Real.log c :=\n log_scale_bound (by nlinarith [mul_nonneg (by linarith : (0:ℝ) ≤ 1 + M) hN0]) hc0\n have hdiv : (n:ℝ) * ((1 + (1 + M) * N) / c) ≤ (n:ℝ) + N / 2 := by\n rw [← mul_div_assoc, div_le_iff₀ hc0, hcdef]\n nlinarith [hN0, hM0, hnR, mul_nonneg (mul_nonneg hnR.le hnR.le)\n (by linarith : (0:ℝ) ≤ 1 + M), mul_nonneg hnR.le (mul_nonneg hM0 hN0)]\n have h6 : -N / 2 - (n:ℝ) * Real.log c ≤ (n:ℝ) * L := by\n rw [hLdef]\n have := mul_le_mul_of_nonneg_left (le_trans hlog1 hlog2) (le_of_lt hnR)\n nlinarith [hdiv]\n have hfin : (n:ℝ) ≤ (n:ℝ) * objective xs ys lam b0 b := by\n rw [hobj]\n have h7 : (n:ℝ) * lam * ‖b‖^2 ≤ (n:ℝ) * lam * (∑ k, b k * b k) :=\n mul_le_mul_of_nonneg_left hnormsq (by positivity)\n have hRle : R ≤ N := hz\n rw [hRdef] at hRle\n linarith [hsum, h5, h6]\n nlinarith [hfin, hnR]\n have hz0 : objective xs ys lam 0 0 = 1 := by\n have h1 : lhs 0 = 1 := by rw [lhs_le' (by norm_num : (0:ℝ) ≤ 1)]; norm_num\n simp only [objective, Pi.zero_apply, mul_zero, Finset.sum_const_zero, add_zero, h1,\n Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one]\n field_simp\n have hcont : Continuous fun z : ℝ × (Fin p → ℝ) => objective xs ys lam z.1 z.2 := by\n simp only [objective]\n refine Continuous.add (Continuous.div_const ?_ _) (continuous_const.mul ?_)\n · refine continuous_finset_sum _ (fun i _ => lhs_continuous.comp ?_)\n exact continuous_const.mul (continuous_fst.add (continuous_finset_sum _ (fun k _ =>\n continuous_const.mul ((continuous_apply k).comp continuous_snd))))\n · exact continuous_finset_sum _ (fun k _ => ((continuous_apply k).comp continuous_snd).mul\n ((continuous_apply k).comp continuous_snd))\n have hev : ∀ᶠ z : ℝ × (Fin p → ℝ) in Filter.cocompact (ℝ × (Fin p → ℝ)),\n objective xs ys lam (0:ℝ) (0 : Fin p → ℝ) ≤ objective xs ys lam z.1 z.2 := by\n have h := (tendsto_norm_cocompact_atTop (E := ℝ × (Fin p → ℝ))).eventually_ge_atTop R\n filter_upwards [h] with z hz\n rw [hz0]\n exact hbig z hz\n obtain ⟨w, hw⟩ := hcont.exists_forall_le' ((0:ℝ), (0 : Fin p → ℝ)) hev\n exact ⟨w.1, w.2, fun c0 cc => hw (c0, cc)⟩\n\nend ResearchLevel\n"} +{"id": "v24-22-1149", "source": "Research-level", "targets": [{"label": "Eqs. (14)-(15) Hölder lower bound", "decls": ["powerball_lower"], "statement": "**Eqs. (14)–(15)**.\n$(\\langle x, \\sigma_\\gamma(x)\\rangle)^2 / \\|\\sigma_\\gamma(x)\\|^2 \\ge \\|x\\|_{1+\\gamma}^2 / \\|\\mathbb{1}\\|_p$, with $p = (1+\\gamma)/(1-\\gamma)$,\nfor $x \\in \\mathbb{R}^d$ with $0 < d$, $0 \\le \\gamma < 1$ (the paper's standing range for the power\ncoefficient, eq. (4)), and $\\sigma_\\gamma(x) \\neq 0$ so that the left denominator is nonzero.", "context_ids": ["v24-22-1149:ctx1", "v24-22-1149:ctx2", "v24-22-1149:ctx3", "v24-22-1149:ctx4", "v24-22-1149:ctx5"], "sibling_refs": [], "topic_domain": "Others", "topic_subtopic": "Analysis & Geometry"}, {"label": "Theorem 1 (PB-SVRGE, eq. 8)", "decls": ["theorem1"], "statement": "Theorem 1. Set $w^{*}=\\arg\\operatorname*{min}_{w}f(w)$ , and choose $S \\subseteq [ n ]$ with $| S | = b .$ Let T denote the number of total iterations, then, under Assumption 1 and Assumption 2 (used in the mini-batch form $\\mathbb{E}[\\nabla f_{S}(w)]=\\mathbb{E}[\\nabla f(w)]$ and $\\mathbb{E}[\\|\\nabla f_{S}(w)-\\nabla f(w)\\|^{2}]\\le\\hat{\\sigma}^{2}/b$ at $w = w_{k}^{s + 1}$ and at $w = \\tilde{w}^{s}$), for any $T \\geq 1$ , PB-SVRGE (Algorithm 1) with learning rate $\\eta_{k}=\\frac{\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})}{L\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}$ (where $\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\neq 0$) can lead to, for every $\\theta\\in(0,1)$ and with $p = \\frac{1 + \\gamma}{1 - \\gamma}$,\n\n$$\n\\mathbb{E}\\left[\\frac{1}{T}\\sum_{s=0}^{\\mathfrak{S}-1}\\sum_{k=0}^{K-1}\\lVert\\nabla f_{S}(w_{k}^{s+1})\\rVert_{1+\\gamma}^{2}\\right]\\leq\\frac{4L\\lVert\\mathbf{1}\\rVert_{p}}{T(1-\\theta)}\\mathbb{E}[f(\\tilde{w}^{0})-f(w^{*})]+\\frac{8\\lVert\\mathbf{1}\\rVert_{p}\\hat{\\sigma}^{2}}{b\\theta(1-\\theta)}.\\tag{8}\n$$", "context_ids": ["v24-22-1149:ctx1", "v24-22-1149:ctx2", "v24-22-1149:ctx3", "v24-22-1149:ctx4", "v24-22-1149:ctx5", "v24-22-1149:ctx6", "v24-22-1149:ctx7"], "sibling_refs": ["Eqs. (14)-(15) Hölder lower bound"], "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}, {"label": "Theorem 2 (PB-SVRGE-RSBB, eq. 27)", "decls": ["theorem2"], "statement": "Theorem 2. Set $w^{*}=\\arg\\operatorname*{min}_{w}f(w)$ , and choose $S \\subseteq [ n ]$ and $S_{H}\\subseteq [ n ]$ with $| S | = b$ and $| S_{H}| = b_{H}$ respectively. Let T denote the number of total iterations, then, under Assumption 1, Assumption 2 (used in the mini-batch form $\\mathbb{E}[\\nabla f_{S}(w)]=\\mathbb{E}[\\nabla f(w)]$ and $\\mathbb{E}[\\|\\nabla f_{S}(w)-\\nabla f(w)\\|^{2}]\\le\\hat{\\sigma}^{2}/b$ at $w = w_{k}^{s + 1}$ and at $w = \\tilde{w}^{s}$) and Lemma 1, for any $T \\geq 1$ , PB-SVRGE-RSBB (Algorithm 2), for any $\\theta > 0$ with $2 b_{H}- \\theta b_{H}- 1 > 0$, with $p = \\frac{1 + \\gamma}{1 - \\gamma}$, and assuming that for all $0 \\le k \\le K - 1$ and $0 \\le s \\le \\mathfrak{S}- 1$ the per-step bound $\\mathbb{E}[f(w_{k+1}^{s+1})-f(w_{k}^{s+1})]\\leq-\\frac{2b_{H}-\\theta b_{H}-1}{4Lb_{H}^{2}\\|\\mathbf{1}\\|_{p}}\\mathbb{E}[\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}]+\\frac{2\\hat{\\sigma}^{2}}{Lb_{H}b\\theta}$ (eq. (34)) holds, leads to\n\n$$\n\\mathbb{E}\\left[\\frac{1}{T}\\sum_{s=0}^{\\mathfrak{S}-1}\\sum_{k=0}^{K-1}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]\\leq\\frac{4b_{H}^{2}L\\|\\mathbf{1}\\|_{p}}{(2b_{H}-\\theta b_{H}-1)T}\\mathbb{E}[f(\\tilde{w}^{0})-f(w^{*})]+\\frac{8\\hat{\\sigma}^{2}b_{H}\\|\\mathbf{1}\\|_{p}}{(2b_{H}-\\theta b_{H}-1)b\\theta}.\\tag{27}\n$$", "context_ids": ["v24-22-1149:ctx1", "v24-22-1149:ctx2", "v24-22-1149:ctx3", "v24-22-1149:ctx4", "v24-22-1149:ctx5", "v24-22-1149:ctx6", "v24-22-1149:ctx7", "v24-22-1149:ctx8", "v24-22-1149:ctx9", "v24-22-1149:ctx10", "v24-22-1149:ctx11", "v24-22-1149:ctx12"], "sibling_refs": ["Eqs. (14)-(15) Hölder lower bound"], "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}], "nl_proof": "### Proof of Theorem 1 (PB-SVRGE, eq. 8)\n\nProof According to the results in the inequality (6) and $w_{k+1}^{s+1}=w_{k}^{s+1}-\\eta_{k}\\sigma_{\\gamma}(\\nu_{k}^{s+1})$ , we easily inferred\n\n$$\n\\begin{array}{r l}&{f(w_{k+1}^{s+1})\\leq f(w_{k}^{s+1})+\\nabla f(w_{k}^{s+1})\\cdot(w_{k+1}^{s+1}-w_{k}^{s+1})+\\displaystyle\\frac{L}{2}\\|w_{k+1}^{s+1}-w_{k}^{s+1}\\|^{2}}\\\\ &{\\qquad=f(w_{k}^{s+1})-\\eta_{k}\\nabla f(w_{k}^{s+1})\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})+\\displaystyle\\frac{L\\eta_{k}^{2}}{2}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}\\\\ &{\\qquad=f(w_{k}^{s+1})-\\eta_{k}\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})+\\displaystyle\\frac{L\\eta_{k}^{2}}{2}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}+\\eta_{k}(\\nu_{k}^{s+1}}\\\\ &{\\qquad-\\nabla f(w_{k}^{s+1}))\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}).}\\end{array}\\tag{9}\n$$\n\nSetting $\\begin{array}{r}{\\eta_{k}=\\frac{\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})}{L\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}}\\end{array}$ , we further obtained\n\n$$\nf(w_{k+1}^{s+1})\\leq f(w_{k}^{s+1})-\\frac{(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{2L\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}+\\eta_{k}(\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1}))\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}).\\tag{10}\n$$\n\nFor the last term in the right hand side of (10), we have\n\n$$\n\\begin{array}{r l}{\\eta_{k}\\big(\\nu_{k}^{s+1}-\\nabla f\\big(w_{k}^{s+1}\\big)\\big)\\cdot\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)=\\displaystyle\\frac{\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)}{L\\|\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)\\|^{2}}\\big(\\nu_{k}^{s+1}-\\nabla f\\big(w_{k}^{s+1}\\big)\\big)\\cdot\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)}&{}\\\\ {\\leq\\displaystyle\\frac{|\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)|}{L\\|\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)\\|^{2}}\\|\\nu_{k}^{s+1}-\\nabla f\\big(w_{k}^{s+1}\\big)\\|\\|\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)\\|}&{}\\\\ {=\\displaystyle\\frac{|\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)|}{L\\|\\sigma_{\\gamma}\\big(\\nu_{k}^{s+1}\\big)\\|}\\|\\nu_{k}^{s+1}-\\nabla f\\big(w_{k}^{s+1}\\big)\\|,}&{}\\end{array}\\tag{11}\n$$\n\nwhere the first inequality can be satisfied due to the Cauchy-Schwartz inequality.\n\nFurther, via utilizing the fact $\\textstyle 2 a b \\leq \\theta a^{2}+{\\frac{1}{\\theta}}b^{2}$ , where θ denotes any positive real number, and a and b are also two real numbers, we have the following result:\n\n$$\n\\eta_{k}(\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1}))\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\leq\\frac{1}{2L}\\Bigg(\\theta\\frac{(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}+\\frac{1}{\\theta}\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}\\Bigg).\\tag{12}\n$$\n\nCombining the inequalities (10) and (12), we obtain\n\n$$\nf(w_{k+1}^{s+1})\\leq f(w_{k}^{s+1})-\\frac{1-\\theta}{2L}\\frac{(\\boldsymbol{\\nu}_{k}^{s+1}\\cdot\\boldsymbol{\\sigma}_{\\gamma}(\\boldsymbol{\\nu}_{k}^{s+1}))^{2}}{\\|\\boldsymbol{\\sigma}_{\\gamma}(\\boldsymbol{\\nu}_{k}^{s+1})\\|^{2}}+\\frac{1}{2L\\theta}\\|\\boldsymbol{\\nu}_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}.\\tag{13}\n$$\n\nBased on the Hölder's inequality for $\\gamma\\in(0,1)$ with $\\begin{array}{r}{p = \\frac{1 + \\gamma}{1 - \\gamma}}\\end{array}$ and $\\begin{array}{r}{q = \\frac{1 + \\gamma}{2 \\gamma}}\\end{array}$ ,we have the fact\n\n$$\n\\begin{array}{r l r}{{\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}=\\displaystyle\\sum_{i=1}^{d}|(\\nu_{k}^{s+1})_{i}|^{2\\gamma}}}\\\\ &{}&{\\leq(\\displaystyle\\sum_{i=1}^{d}1^{p})^{\\frac{1}{p}}(\\displaystyle\\sum_{i=1}^{d}(|(\\nu_{k}^{s+1})_{i}|^{2\\gamma})^{q})^{\\frac{1}{q}}}\\\\ &{}&{=\\|\\mathbf{1}\\|_{p}(\\displaystyle\\sum_{i=1}^{d}|(\\nu_{k}^{s+1})_{i}|^{1+\\gamma})^{\\frac{2\\gamma}{1+\\gamma}}.}\\end{array}\\tag{14}\n$$\n\nTherefore, we have\n\n$$\n\\begin{array}{r l}&{\\frac{(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}\\geq\\frac{\\left(\\sum_{i=1}^{d}|(\\nu_{k}^{s+1})_{i}|^{1+\\gamma}\\right)^{2}}{\\|\\pmb{1}\\|_{p}\\left(\\sum_{i=1}^{d}|\\nu_{k}^{s+1}|^{1+\\gamma}\\right)^{\\frac{2\\gamma}{1+\\gamma}}}}\\\\ &{\\quad\\quad\\quad\\quad\\quad\\quad\\quad=\\frac{\\|\\nu_{k}^{s+1}\\|_{1+\\gamma}^{2}}{\\|\\pmb{1}\\|_{p}}.}\\end{array}\\tag{15}\n$$\n\nThe following results can be derived by utilizing the inequalities (13) and (15) simultaneously:\n\n$$\nf(w_{k+1}^{s+1})\\leq f(w_{k}^{s+1})-\\frac{1-\\theta}{2L}\\frac{\\|\\nu_{k}^{s+1}\\|_{1+\\gamma}^{2}}{\\|{\\mathbf{1}}\\|_{p}}+\\frac{1}{2L\\theta}\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}.\\tag{16}\n$$\n\nNow, we consider the second term and the third term of the right hand side of (16), respectively. First, considering $\\| \\nu_{k}^{s + 1}\\|_{1 + \\gamma}^{2},$ defining in PB-SVRGE (Algorithm 1), we have\n\n$$\n\\begin{array}{r l}&{\\|\\boldsymbol{\\nu}_{k}^{s+1}\\|_{1+\\gamma}^{2}=\\|\\nabla f_{S}(\\boldsymbol{w}_{k}^{s+1})-\\nabla f_{S}(\\tilde{\\boldsymbol{w}}^{s})+\\nabla f(\\tilde{\\boldsymbol{w}}^{s})\\|_{1+r}^{2}}\\\\ &{\\qquad\\ge\\displaystyle\\frac{1}{2}\\|\\nabla f_{S}(\\boldsymbol{w}_{k}^{s+1})\\|_{1+\\gamma}^{2}-\\|\\nabla f_{S}(\\tilde{\\boldsymbol{w}}^{s})-\\nabla f(\\tilde{\\boldsymbol{w}}^{s})\\|_{1+r}^{2},}\\end{array}\\tag{17}\n$$\n\nwhere the first inequality holds due to the fact $\\begin{array}{r}{\\| a \\|_{1 + \\gamma}^{2}\\geq \\frac{1}{2}\\| b \\|_{1 + \\gamma}^{2}- \\| b - a \\|_{1 + \\gamma}^{2}.}\\end{array}$\n\nSecond, considering $\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}$ , we further obtain\n\n$$\n\\begin{array}{r l}&{\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}=\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f_{S}(\\tilde{w}^{s})+\\nabla f(\\tilde{w}^{s})-\\nabla f(w_{k}^{s+1})\\|^{2}}\\\\ &{\\qquad\\le 2\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f(w_{k}^{s+1})\\|^{2}+2\\|\\nabla f_{S}(\\tilde{w}^{s})-\\nabla f(\\tilde{w}^{s})\\|^{2}}\\end{array}\\tag{18}\n$$\n\nwhere the first inequality can be satisfied since the fact $\\| a + b \\|^{2}\\leq 2 \\| a \\|^{2}+ 2 \\| b \\|^{2}$ holds.\n\nCombining (16), (17) and (18), we conclude that\n\n$$\n\\begin{array}{l}{\\displaystyle f(w_{k+1}^{s+1})\\le f(w_{k}^{s+1})-\\frac{1-\\theta}{4L\\|\\mathbf 1\\|_{p}}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}+\\frac{1-\\theta}{2L\\|\\mathbf 1\\|_{p}}\\|\\nabla f_{S}(\\tilde{w}^{s})-\\nabla f(\\tilde{w}^{s})\\|_{1+r}^{2}}\\\\ {\\displaystyle\\qquad+\\frac{1}{L\\theta}\\left[\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f(w_{k}^{s+1})\\|^{2}+\\|\\nabla f_{S}(\\tilde{w}^{s})-\\nabla f(\\tilde{w}^{s})\\|^{2}\\right].}\\end{array}\\tag{19}\n$$\n\nTo hold the inequality (19), it is appropriate to hold the following condition, that is\n\n$$\n\\begin{array}{l}{f(w_{k+1}^{s+1})\\le f(w_{k}^{s+1})-\\displaystyle\\frac{1-\\theta}{4L\\|\\mathbf{1}\\|_{p}}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}+\\displaystyle\\frac{1}{L\\theta}[\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f(w_{k}^{s+1})\\|^{2}}\\\\ {\\displaystyle\\qquad+\\|\\nabla f_{S}(\\tilde{w}^{s})-\\nabla f(\\tilde{w}^{s})\\|^{2}].}\\end{array}\\tag{20}\n$$\n\nTaking expectation on both sides of the inequality (20), we have\n\n$$\n\\mathbb{E}[f(w_{k+1}^{s+1})-f(w_{k}^{s+1})]\\leq\\mathbb{E}\\left[-\\frac{1-\\theta}{4L\\|\\mathbf{1}\\|_{p}}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]+\\frac{2\\hat{\\sigma}^{2}}{Lb\\theta},\\tag{21}\n$$\n\nwhere in this inequality, we took the fact in Assumption 2.\n\nBy telescoping sum (21) over $k=0,\\ldots,K-1$ , we have\n\n$$\n\\mathbb{E}[f(w_{K}^{s+1})-f(w_{0}^{s+1})]\\leq\\mathbb{E}\\left[-\\frac{1-\\theta}{4L\\|\\mathbf{1}\\|_{p}}\\sum_{k=0}^{K-1}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]+\\frac{2K\\hat{\\sigma}^{2}}{Lb\\theta}.\\tag{22}\n$$\n\nIn addition, according to $\\tilde{w}^{s + 1}= w_{K}^{s + 1}$ and $w_{0}^{s + 1}= w_{K}^{s}$ , defined in Algorithm 1, we further obtain\n\n$$\n\\mathbb{E}[f(\\tilde{w}^{s+1})-f(\\tilde{w}^{s})]\\leq\\mathbb{E}\\left[-\\frac{1-\\theta}{4L\\|\\mathbf{1}\\|_{p}}\\sum_{k=0}^{K-1}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]+\\frac{2K\\hat{\\sigma}^{2}}{Lb\\theta}.\\tag{23}\n$$\n\nBy telescoping (23) over $s=0,\\ldots,\\mathfrak{S}-1$ , we have\n\n$$\n\\begin{array}{r}{\\mathbb{E}\\left[\\displaystyle\\sum_{s=0}^{\\mathfrak{S}-1}\\displaystyle\\sum_{k=0}^{K-1}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]\\leq\\displaystyle\\frac{4L\\|\\mathbf{1}\\|_{p}}{1-\\theta}\\mathbb{E}[f(\\tilde{w}^{0})-f(w^{*})]+\\displaystyle\\frac{8K\\mathfrak{S}\\|\\mathbf{1}\\|_{p}\\hat{\\sigma}^{2}}{b\\theta(1-\\theta)}}\\\\ {=\\displaystyle\\frac{4L\\|\\mathbf{1}\\|_{p}}{1-\\theta}\\mathbb{E}[f(\\tilde{w}^{0})-f(w^{*})]+\\displaystyle\\frac{8T\\|\\mathbf{1}\\|_{p}\\hat{\\sigma}^{2}}{b\\theta(1-\\theta)},}\\end{array}\\tag{24}\n$$\n\nwhere the first inequality holds because of $w^{*}=\\mathrm{argmin}_{\\scriptscriptstyle w}f(w)$ and the first equality holds due to ${\\mathfrak{S}}= T / K$ , defined in Algorithm 1.\n\nBy dividing T on both sides of (24), the desired results in Theorem 1 was derived.\n\n### Proof of Theorem 2 (PB-SVRGE-RSBB, eq. 27)\n\nProof According to the results in the inequality (6) and $w_{k+1}^{s+1}=w_{k}^{s+1}-\\eta_{k}\\sigma_{\\gamma}(\\nu_{k}^{s+1})$ , we easily inferred\n\n$$\n\\begin{array}{l}{f(w_{k+1}^{s+1})\\le f(w_{k}^{s+1})+\\nabla f(w_{k}^{s+1})\\cdot(w_{k+1}^{s+1}-w_{k}^{s+1})+\\displaystyle\\frac{L}{2}\\|w_{k+1}^{s+1}-w_{k}^{s+1}\\|^{2}}\\\\ {\\displaystyle\\qquad=f(w_{k}^{s+1})-\\eta_{k}\\nabla f(w_{k}^{s+1})\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})+\\displaystyle\\frac{L\\eta_{k}^{2}}{2}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}\\\\ {\\displaystyle\\qquad\\le f(w_{k}^{s+1})-\\displaystyle\\frac{\\zeta}{b_{H}\\tau}\\nabla f(w_{k}^{s+1})\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})+\\displaystyle\\frac{L\\zeta^{2}}{2b_{H}^{2}\\tau^{2}}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}\\\\ {\\displaystyle\\qquad=f(w_{k}^{s+1})-\\displaystyle\\frac{\\zeta}{b_{H}\\tau}\\nu_{k}^{s+1}\\sigma_{\\gamma}(\\nu_{k}^{s+1})+\\displaystyle\\frac{L\\zeta^{2}}{2b_{H}^{2}\\tau^{2}}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}+\\displaystyle\\frac{\\zeta}{b_{H}\\tau}(\\nu_{k}^{s+1}}\\\\ {\\displaystyle\\qquad-\\nabla f(w_{k}^{s+1}))\\sigma_{\\gamma}(\\nu_{k}^{s+1}),}\\end{array}\\tag{28}\n$$\n\nwhere the second inequality utilized the fact in Lemma 1.\n\nWhen setting $\\begin{array}{r}{\\zeta=\\frac{\\tau\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})}{L\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}}\\end{array}$ , we have\n\n$$\n\\begin{array}{r l}&{f(w_{k+1}^{s+1})\\leq f(w_{k}^{s+1})-\\displaystyle\\frac{(2b_{H}-1)(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{2Lb_{H}^{2}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}+\\displaystyle\\frac{\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})}{b_{H}L\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}\\cdot(\\nu_{k}^{s+1}}\\\\ &{\\qquad-\\nabla f(w_{k}^{s+1}))\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})}\\\\ &{\\qquad\\leq f(w_{k}^{s+1})-\\displaystyle\\frac{(2b_{H}-1)(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{2Lb_{H}^{2}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}+\\displaystyle\\frac{|\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1})|}{b_{H}L\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|}\\cdot\\|\\nu_{k}^{s+1}}\\\\ &{\\qquad-\\nabla f(w_{k}^{s+1})\\|,}\\end{array}\\tag{29}\n$$\n\nwhere the last inequality took the Cauchy-Schwartz inequality.\n\nFurther, via the condition $2 a b \\leq \\theta a^{2}+{\\textstyle{\\frac{1}{\\theta}}}b^{2}$ , we have\n\n$$\n\\begin{array}{r l}&{f(w_{k+1}^{s+1})\\leq f(w_{k}^{s+1})-\\displaystyle\\frac{(2b_{H}-1)(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{2Lb_{H}^{2}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}+\\displaystyle\\frac{\\theta(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{2b_{H}L\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}}\\\\ &{\\qquad+\\displaystyle\\frac{\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}}{2b_{H}L\\theta}}\\\\ &{\\qquad=f(w_{k}^{s+1})-\\displaystyle\\frac{(2b_{H}-\\theta b_{H}-1)(\\nu_{k}^{s+1}\\cdot\\sigma_{\\gamma}(\\nu_{k}^{s+1}))^{2}}{2Lb_{H}^{2}\\|\\sigma_{\\gamma}(\\nu_{k}^{s+1})\\|^{2}}+\\displaystyle\\frac{\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}}{2b_{H}L\\theta}.}\\end{array}\\tag{30}\n$$\n\nAccording to the conclusion in the inequality (15), we derived:\n\n$$\nf(w_{k+1}^{s+1})\\leq f(w_{k}^{s+1})-\\frac{(2b_{H}-\\theta b_{H}-1)}{2Lb_{H}^{2}}\\cdot\\frac{\\|\\boldsymbol{\\nu}_{k}^{s+1}\\|_{1+\\gamma}^{2}}{\\|\\mathbf{1}\\|_{p}}+\\frac{\\|\\boldsymbol{\\nu}_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}}{2b_{H}L\\theta}\\tag{31}\n$$\n\nCombining (31), (17) and (18), the following conclusion was obtained\n\n$$\n\\begin{array}{r l}&{f(w_{k+1}^{s+1})\\le f(w_{k}^{s+1})-\\displaystyle\\frac{(2b_{H}-\\theta b_{H}-1)}{4Lb_{H}^{2}\\|{\\mathbf 1}\\|_{p}}\\cdot\\|\\nabla f(w_{k}^{s+1})\\|_{1+\\gamma}^{2}+\\displaystyle\\frac{(2b_{H}-\\theta b_{H}-1)}{2Lb_{H}^{2}\\|{\\mathbf 1}\\|_{p}}}\\\\ &{\\qquad\\cdot\\|\\nabla f_{S}(\\tilde{w}_{s})-\\nabla f(\\tilde{w}_{s})\\|_{1+\\gamma}^{2}+\\displaystyle\\frac{1}{b_{H}L\\theta}[\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f(w_{k}^{s+1})\\|^{2}}\\\\ &{\\qquad+\\|\\nabla f_{S}(\\tilde{w}^{s})-\\nabla f(\\tilde{w}^{s})\\|^{2}].}\\end{array}\\tag{32}\n$$\n\nTo make the inequality (19) be satisfied, we only keep the following condition\n\n$$\n\\begin{array}{r l r}{{f(w_{k+1}^{s+1})\\le f(w_{k}^{s+1})-\\frac{(2b_{H}-\\theta b_{H}-1)}{4Lb_{H}^{2}\\|{\\mathbf 1}\\|_{p}}\\cdot\\|\\nabla f(w_{k}^{s+1})\\|_{1+\\gamma}^{2}+\\frac{1}{b_{H}L\\theta}[\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f(w_{k}^{s+1})\\|^{2}}}\\\\ &{}&{\\qquad+\\|\\nabla f_{S}(\\tilde{w}^{s})-\\nabla f(\\tilde{w}^{s})\\|^{2}].}\\end{array}\\tag{33}\n$$\n\nTaking expectation on both sides of the inequality (33), we have\n\n$$\n\\mathbb{E}[f(w_{k+1}^{s+1})-f(w_{k}^{s+1})]\\leq\\mathbb{E}\\left[-\\frac{(2b_{H}-\\theta b_{H}-1)}{4Lb_{H}^{2}\\|{\\bf 1}\\|_{p}}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]+\\frac{2\\hat{\\sigma}^{2}}{Lb_{H}b\\theta},\\tag{34}\n$$\n\nwhere in this inequality, we took the fact in Assumption 2 simultaneously.\n\nWhen summing (34) over $k=0,\\ldots,K-1$ recursively, we have\n\n$$\n\\mathbb{E}[f(w_{K}^{s+1})-f(w_{0}^{s+1})]\\leq\\mathbb{E}\\left[-\\frac{(2b_{H}-\\theta b_{H}-1)}{4Lb_{H}^{2}\\|{\\bf 1}\\|_{p}}\\sum_{k=0}^{K-1}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]+\\frac{2K\\hat{\\sigma}^{2}}{Lb_{H}b\\theta}.\\tag{35}\n$$\n\nIn addition, according to $\\tilde{w}^{s + 1}= w_{K}^{s + 1}$ and $w_{0}^{s + 1}= w_{K}^{s}$ , defined in Algorithm 2, we further obtain\n\n$$\n\\mathbb{E}[f(\\tilde{w}^{s+1})-f(\\tilde{w}^{s})]\\leq\\mathbb{E}\\left[-\\frac{(2b_{H}-\\theta b_{H}-1)}{4Lb_{H}^{2}\\|{\\mathbf 1}\\|_{p}}\\sum_{k=0}^{K-1}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]+\\frac{2K\\hat{\\sigma}^{2}}{Lb_{H}b\\theta}.\\tag{36}\n$$\n\nIn addition, via telescoping (36) over $s=0,\\ldots,\\mathfrak{S}-1$ , we derive\n\n$$\n\\begin{array}{r}{\\mathbb{E}\\left[\\displaystyle\\sum_{s=0}^{\\mathfrak{S}-1}\\displaystyle\\sum_{k=0}^{K-1}\\|\\nabla f_{S}(w_{k}^{s+1})\\|_{1+\\gamma}^{2}\\right]\\leq\\displaystyle\\frac{4b_{H}^{2}L\\|\\mathbf{1}\\|_{p}}{2b_{H}-\\theta b_{H}-1}\\mathbb{E}[f(\\tilde{w}^{0})-f(w^{*})]+\\displaystyle\\frac{8b_{H}K\\mathfrak{S}\\|\\mathbf{1}\\|_{p}\\hat{\\sigma}^{2}}{(2b_{H}-\\theta b_{H}-1)b\\theta}}\\\\ {=\\displaystyle\\frac{4b_{H}^{2}L\\|\\mathbf{1}\\|_{p}}{2b_{H}-\\theta b_{H}-1}\\mathbb{E}[f(\\tilde{w}^{0})-f(w^{*})]+\\displaystyle\\frac{8\\hat{\\sigma}^{2}b_{H}T\\|\\mathbf{1}\\|_{p}}{(2b_{H}-\\theta b_{H}-1)b\\theta},}\\end{array}\\tag{37}\n$$\n\nwhere the first inequality holds because of $w^{*}=\\arg\\operatorname*{min}_{w}f(w)$ and the first equality uses ${\\mathfrak{S}}= T / K$ defined in Algorithm 2.\n\nFinally, by dividing T on both sides of (37), the desired results in Theorem 2 was obtained.", "context": [{"id": "v24-22-1149:ctx1", "name": "Setup: finite-sum problem (1) (Section 1)", "statement": "Large numbers of applications in machine learning (Le Thi et al., 2022), computer vision (Xu et al., 2021) and numerical optimization (Fehrman et al., 2020) are often implemented to be a finite-sum structure of the form\n\n$$\n\\operatorname*{min}_{w\\in\\mathbb{R}^{d}}f(w)=\\frac{1}{n}\\sum_{i=1}^{n}f_{i}(w),\\tag{1}\n$$\n\nwhere n denotes the total number of the instances, w defines the parameter to learn and $f_{i}(\\cdot):\\mathbb{R}^{d}\\to\\mathbb{R}$ represents a loss function corresponding to the i-th instance with d dimensions. In this work, we are mainly interested in each $f_{i}(w)$ and $f(w)$ that are L-smooth but may be non-convex. More concretely and vividly, the cases Problem (1) referred into logistic regression, eigenvector computation, multi-kernel learning, neural networks, to name a few."}, {"id": "v24-22-1149:ctx2", "name": "Notation (Section 1.2)", "statement": "Throughout this work, we take $\\mathbb{R}^{d}$ to define the set of d-dimensional real number vectors. For vectors, the mark w · v is used to denote their inner product. Additionally, we use [n] to define the set $\\{1,2,\\ldots,\\mathtt{n}\\}$ . The symbol $\\| \\cdot \\|$ and $\\| \\cdot \\|_{p}$ are chosen to represent the Euclidean norm and p-norm on $\\mathbb{R}^{d}$ respectively. Moreover, Denote by $\\nabla f(\\boldsymbol{w})$ the gradient of the loss function $f(w)$ . We adopt $\\mathbb{E}[ \\cdot ]$ to represent the expectation with respect to the underlying probability space. We use $(w)_{i}$ to represent the i-th element of vector $\\boldsymbol{w}\\in \\mathbb{R}^{d}$"}, {"id": "v24-22-1149:ctx3", "name": "SVRG update (3) and Powerball update (4); definition of σ_γ (Section 3)", "statement": "Since this work will delve into the theoretical and numerical characteristics of SVRGE in PSO algorithms, we offer some discussions about the updating scheme of the original SVRG algorithm, originally developed in (Johnson and Zhang, 2013). Comparing with the conventional SGD algorithm that worked with the update scheme:\n\n$$\nw_{k+1}=w_{k}-\\eta_{k}\\nabla f_{i}(w_{k}),\\tag{2}\n$$\n\nfor solving Problem (1), the update scheme of SVRG usually took the form:\n\n$$\nw_{k+1}=w_{k}-\\eta_{k}\\big(\\nabla f_{i}\\big(w_{k}\\big)-\\nabla f_{i}\\big(\\tilde{w}\\big)+\\nabla f\\big(\\tilde{w}\\big)\\big),\\tag{3}\n$$\n\nwhere $\\tilde{w}$ was a snapshot point and $\\eta_{k}> 0$ was the learning rate. In general, there were two loops in the SVRG-like approach, where the iterative rule (3) located in the inner loop. The outer loop was used to store the historical information, then transferred it into the inner loop.\n\nThe iterative scheme (3), utilizing historical information $(\\mathrm{i}.\\mathrm{e}.,\\nabla f_{i}(\\tilde{w})$ and $\\nabla f(\\tilde{w}))$ , made the stochastic optimization algorithms enjoy a lower variance than classical SGD, and resulted in a faster convergence rate and a better generalization in practice.\n\nIn contrast, when dealing with Problem (1), the classical iterative scheme of the PSO algorithm was:\n\n$$\nw_{k+1}=w_{k}-\\eta_{k}\\sigma_{\\gamma}(\\nabla f_{i}(w_{k})),\\tag{4}\n$$\n\nwhere the power coefficient $\\gamma\\in [0,1),\\sigma_{\\gamma}(\\nabla f_{i}(w_{k}))=\\mathrm{sign}(\\nabla f_{i}(w_{k}))|\\nabla f_{i}(w_{k})|^{\\gamma}$ Here $\\mathrm{sign}(x)$ backed to the sign of $x$, or 0 if $x = 0$. Also, it was noted that the operations sign(w) and $\\sigma_{\\gamma}(w)$ was applied to each element if the parameter $y \\in \\mathbb{R}^{d}$ was a vector. For example, $\\sigma_{\\gamma}(y)=(\\sigma_{\\gamma}((y)_{1}),\\sigma_{\\gamma}((y)_{2}),\\dots,\\sigma_{\\gamma}((y)_{d}))$"}, {"id": "v24-22-1149:ctx4", "name": "Algorithm 1: PB-SVRGE", "statement": "Naturally, it was asked whether SVRGE created a positive effect on PSO algorithms? In order to respond to this question, we first proposed the PB-SVRGE algorithm (Algorithm 1) and analyzed its theoretical and empirical properties in the upcoming sections.\n\nAlgorithm 1 PB-SVRGE \nInput: $\\widetilde{w}^{0}= w_{K}^{0}= w^{0}$ , epoch length $K,$ outer loop size ${\\mathfrak{S}}= T / K$ , mini-batch size $b$, learning rate \n$\\{\\eta_{j}\\}_{j = 0}^{K - 1}$ , power coefficient $\\gamma .$ \nfor $s=0,\\ldots,{\\mathfrak{S}}-1$ do \n$w_{0}^{s + 1}= w_{K}^{s}$ \n$g^{s+1}=\\nabla f(\\tilde{w}^{s})$ \nfor $k=0,\\ldots,K-1$ do \nRandomly choose $S \\subseteq [ n ]$ with $|S| =b,$ compute a new stochastic estimate $\\nabla f(w_{k}^{s})$ \n$\\nu_{k}^{s+1}=\\nabla f_{S}(w_{k}^{s+1})-\\nabla f_{S}(\\tilde{w}^{s})+g^{s+1}$ \n$w_{k+1}^{s+1}=w_{k}^{s+1}-\\eta_{k}\\sigma(\\nu_{k}^{s+1})$ \nend for \nSet $\\widetilde{w}^{s + 1}= w_{K}^{s + 1}$ \nend for"}, {"id": "v24-22-1149:ctx5", "name": "Remark 1(i): mini-batch estimators ∇f_S", "statement": "Remark 1: For PB-SVRGE, the following remarks were necessary to be demonstrated:\n\n(i) PR-SVRGE utilized the similar algorithm framework as SVRG-like algorithms. The main difference between these two approaches is that the introduction of the Powerball function in PB-SVRGE. Specifically, we can view the SVRG-like algorithm as an extension of PB-SVRGE when taking $\\gamma = 1$ . Moreover, we considered PSO algorithms in the mini-batching setting, where $\\begin{array}{r}{\\nu_{k}^{s+1}=\\frac{1}{b}\\sum_{i\\in S}\\nabla f_{i}(w_{k}^{s+1})-\\frac{1}{b}\\sum_{i\\in S}\\nabla f_{S}(\\tilde{w}^{s})+\\nabla f(\\tilde{w}^{s})\\ (S\\subseteq [n]}\\end{array}$ with b batch samples). Here, $\\begin{array}{r}{\\nabla f_{S}(w_{k}^{s+1})=\\frac{1}{b}\\sum_{i\\in S}\\nabla f_{i}(w_{k}^{s+1})}\\end{array}$ and $\\begin{array}{r}{\\nabla f_{S}(\\tilde{w}^{s})=\\frac{1}{b}\\sum_{i\\in S}\\nabla f_{i}(\\tilde{w}^{s})}\\end{array}$"}, {"id": "v24-22-1149:ctx6", "name": "Assumption 1 (L-smoothness) and inequality (6)", "statement": "This work considers the theoretical properties of PB-SVRGE on non-convex optimization problems. \nTo proceed the analysis, we make the following standard smoothness assumptions.\n\nAssumption 1. Each cost function $f_{i}(w)$ in Problem (1) is differential and has a L-Lipschitz gradient, that is,\n\n$$\n\\forall w,\\nu\\in\\mathbb{R}^{d},\\quad\\|\\nabla f_{i}(w)-\\nabla f_{i}(\\nu)\\|\\le L\\|w-\\nu\\|.\\tag{5}\n$$\n\nThe conclusion in Assumption 1 indicates that the average function $f(w)$ , presented in Problem (1), has a L-Lipschitz gradient as well.\n\nClearly, from the smooth property of the cost function, we have the following result:\n\n$$\nf(w)\\leq f(\\nu)+\\nabla f(\\nu)^{T}(w-\\nu)+\\frac{L}{2}\\parallel w-\\nu\\parallel^{2}.\\tag{6}\n$$"}, {"id": "v24-22-1149:ctx7", "name": "Assumption 2 (unbiased oracle, bounded variance) and the mini-batch variance bound σ̂²/b", "statement": "Assumption 2. The stochastic gradient oracle is an independent and unbiased estimator of the gradient and satisfies\n\n$$\n\\begin{array}{r l}&{\\mathbb{E}_{\\xi_{i}}[\\nabla f(w,\\xi_{i})]=\\nabla f(w),\\forall w\\in\\mathbb{R}^{d},}\\\\ &{\\mathbb{E}_{\\xi_{i}}[\\|\\nabla f(w,\\xi_{i})-\\nabla f(w)\\|^{2}]\\le\\hat{\\sigma}^{2},\\forall w\\in\\mathbb{R}^{d},}\\end{array}\\tag{7}\n$$\n\nwhere $\\nabla f_{i}(w)=\\nabla f(w,\\xi_{i})$ and $\\xi_{i}$ denotes a random variable.\n\nTwo assumptions mentioned above were very common in the most existing studies for finding a first-order stationary point of non-convex or convex loss functions (Ghadimi and Lan, 2013; Wei et al., 2021; Zhou et al., 2018). Observe that, by (5), the gradient of the loss function does not change arbitrary rapid, and by (7), the variance of the random variable $\\mathbb{E}[\\|\\nabla f_{i}(w)-\\nabla f(w)\\|^{2}]$ has an upper bound. Notice that, when taking b samples in vanilla SGD at each iterative step, we have $\\begin{array}{r}{\\mathbb{E}[\\|\\nabla f_{S}(w)-\\nabla f(w)\\|^{2}]\\le\\frac{\\hat{\\sigma}^{2}}{b}}\\end{array}$"}, {"id": "v24-22-1149:ctx8", "name": "RSBB learning rate (25) (Section 4)", "statement": "We here briefly discussed the RSBB method. In RSBB, it also employed the similar updating rule to SGD in (2), i.e., $w_{k+1}=w_{k}-\\eta_{k}\\nabla f_{i}\\big(w_{k}\\big)$ , but the learning rate\n\n$$\n\\eta_{k}= \\frac{\\zeta}{b_{H}}\\cdot \\frac{\\| s_{k}\\|^{2}}{s_{k}\\cdot y_{k}+ \\tau \\| s_{k}\\|^{2}},\\tag{25}\n$$\n\nwhere $s_{k}= w_{k}- w_{k - 1}$ and $y_{k}=\\nabla f_{S_{H}}(w_{k})-\\nabla f_{S_{H}}(w_{k-1})$ for $k \\geq 1$ . Note that, here, $S_{H}\\subseteq [ n ]$ with $b_{H}$ samples $(\\mathrm{i}.\\mathrm{e}.,|S_{H}| =b_{H})$ and $\\begin{array}{r}{\\nabla f_{S_{H}}(w_{k})=\\frac{1}{b_{H}}\\sum_{i\\in S_{H}}\\nabla f_{i}(w_{k})}\\end{array}$ . In addition, $\\zeta$ and $\\tau$ were two positive parameters. Specifically, $\\zeta$ was employed to control the convergence speed. The term $\\tau \\| s_{k}\\|^{2}$ was used to avoid the denominator of the original BB step size being zero. For the BB-type technique, it enjoyed a high-order information, resorting employing a simple but a low computational cost way to approximate the Hessian matrix unlike Newton or quasi-Newton type methods."}, {"id": "v24-22-1149:ctx9", "name": "Algorithm 2: PB-SVRGE-RSBB", "statement": "Algorithm 2 PB-SVRGE-RSBB\nInput: $\\widetilde{w}^{0}= w_{K}^{0}= w^{0},$ epoch length $K,$ outer loop size ${\\mathfrak{S}}= T / K$ ,mini-batch size $b$, initial\nlearning rate $\\eta_{0}$, power coefficient $\\gamma,$ positive parameters $\\zeta$ and $\\tau$.\nfor $s=0,\\ldots,\\mathfrak{S}-1$ do\n$w_{0}^{s + 1}= w_{K}^{s}$\n$\\boldsymbol{g}^{s+1}=\\nabla f(\\tilde{w}^{s})$\nfor $k=0,\\ldots,K-1$ do\nRandomly choose $S \\subseteq [ n ]$ with $|S| =b,$ compute a new stochastic estimate $\\nabla f(w_{k}^{s+1})$\n$\\nu_{k}^{s+1}=\\nabla f_{S}(w_{k}^{s+1})-\\nabla f_{S}(\\tilde{w}^{s})+g^{s+1}$\n$w_{k+1}^{s+1}=w_{k}^{s+1}-\\eta_{k}\\sigma_{\\gamma}(\\nu_{k}^{s+1})$\nRandomly choose $S_{H}\\subseteq [ n ]$ with $| S_{H}| = b_{H}$ and compute the learning rate\n$\\eta_{k+1}=\\frac{\\zeta}{b_{H}}\\cdot\\frac{\\|w_{k+1}^{s+1}-w_{k}^{s+1}\\|^{2}}{(w_{k+1}^{s+1}-w_{k}^{s+1})\\cdot(\\sigma_{\\gamma}(\\nabla f_{S_{H}}(w_{k+1}^{s+1}))-\\sigma_{\\gamma}(\\nabla f_{S_{H}}(w_{k}^{s+1})))+\\tau\\|w_{k+1}^{s+1}-w_{k}^{s+1}\\|^{2}}$\nend for\nSet $\\widetilde{w}^{s + 1}= w_{K}^{s + 1}$\nend for"}, {"id": "v24-22-1149:ctx10", "name": "Lemma 1 (step-size bound η_k ≤ ζ/(b_H τ))", "statement": "The boundary of the learning rate $\\eta_{k}$ was first established in the following lemma.\n\nLemma 1. From the definition of $\\eta_{k}$ in PB-SVRGE-RSBB (Algorithm 2), we have the following conclusion\n\n$$\n\\eta_{k}\\leq \\frac{\\zeta}{b_{H}\\tau}.\\tag{26}\n$$"}, {"id": "v24-22-1149:ctx11", "name": "Remark after Lemma 1: positivity of s_k·y_k", "statement": "Note that the original BB technique (Barzilai and Borwein, 1988) that used the iterative scheme $\\begin{array}{r}{\\eta_{k}= \\frac{\\| s_{k}\\|^{2}}{s_{k}^{T}y_{k}}}\\end{array}$ to update the learning rate usually kept such the learning rate positive under deterministic optimization background, which meant that the inner product of the vectors $s_{k}$ and $y_{k}$ was positive. Due to the introduction of the mini-batching and variance reduced techniques under stochastic optimization setting, it, here, still almost kept the inner product of the vectors $s_{k}$ and $y_{k}$ positive. This is indeed the case and can be easily confirmed through numerical experiments."}, {"id": "v24-22-1149:ctx12", "name": "Inequalities (17) and (18), from the proof of Theorem 1", "statement": "Now, we consider the second term and the third term of the right hand side of (16), respectively. First, considering $\\| \\nu_{k}^{s + 1}\\|_{1 + \\gamma}^{2},$ defining in PB-SVRGE (Algorithm 1), we have\n\n$$\n\\begin{array}{r l}&{\\|\\boldsymbol{\\nu}_{k}^{s+1}\\|_{1+\\gamma}^{2}=\\|\\nabla f_{S}(\\boldsymbol{w}_{k}^{s+1})-\\nabla f_{S}(\\tilde{\\boldsymbol{w}}^{s})+\\nabla f(\\tilde{\\boldsymbol{w}}^{s})\\|_{1+r}^{2}}\\\\ &{\\qquad\\ge\\displaystyle\\frac{1}{2}\\|\\nabla f_{S}(\\boldsymbol{w}_{k}^{s+1})\\|_{1+\\gamma}^{2}-\\|\\nabla f_{S}(\\tilde{\\boldsymbol{w}}^{s})-\\nabla f(\\tilde{\\boldsymbol{w}}^{s})\\|_{1+r}^{2},}\\end{array}\\tag{17}\n$$\n\nwhere the first inequality holds due to the fact $\\begin{array}{r}{\\| a \\|_{1 + \\gamma}^{2}\\geq \\frac{1}{2}\\| b \\|_{1 + \\gamma}^{2}- \\| b - a \\|_{1 + \\gamma}^{2}.}\\end{array}$\n\nSecond, considering $\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}$ , we further obtain\n\n$$\n\\begin{array}{r l}&{\\|\\nu_{k}^{s+1}-\\nabla f(w_{k}^{s+1})\\|^{2}=\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f_{S}(\\tilde{w}^{s})+\\nabla f(\\tilde{w}^{s})-\\nabla f(w_{k}^{s+1})\\|^{2}}\\\\ &{\\qquad\\le 2\\|\\nabla f_{S}(w_{k}^{s+1})-\\nabla f(w_{k}^{s+1})\\|^{2}+2\\|\\nabla f_{S}(\\tilde{w}^{s})-\\nabla f(\\tilde{w}^{s})\\|^{2}}\\end{array}\\tag{18}\n$$\n\nwhere the first inequality can be satisfied since the fact $\\| a + b \\|^{2}\\leq 2 \\| a \\|^{2}+ 2 \\| b \\|^{2}$ holds."}], "lean": "import Mathlib\n\nopen scoped RealInnerProductSpace\nopen MeasureTheory\n\nnamespace ResearchLevel\n\nnoncomputable def sigmaGamma {d : ℕ} (γ : ℝ) (x : EuclideanSpace ℝ (Fin d)) :\n EuclideanSpace ℝ (Fin d) :=\n (WithLp.equiv 2 (Fin d → ℝ)).symm (fun i => Real.sign (x i) * |x i| ^ γ)\n\nnoncomputable def lpNorm {d : ℕ} (r : ℝ) (x : EuclideanSpace ℝ (Fin d)) : ℝ :=\n (∑ i, |x i| ^ r) ^ (1 / r)\n\nnoncomputable def onesNorm (p : ℝ) (d : ℕ) : ℝ := (d : ℝ) ^ (1 / p)\n\nlemma powerball_lower {d : ℕ} (γ : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ < 1)\n (p : ℝ) (hp : p = (1 + γ) / (1 - γ)) (hd : 0 < d)\n (x : EuclideanSpace ℝ (Fin d)) (hx : sigmaGamma γ x ≠ 0) :\n (⟪x, sigmaGamma γ x⟫) ^ 2 / ‖sigmaGamma γ x‖ ^ 2\n ≥ (lpNorm (1 + γ) x) ^ 2 / onesNorm p d := by\n sorry\n\ntheorem theorem1 {d n K Sout T b : ℕ}\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (hT : T = K * Sout) (hT1 : 1 ≤ T) (hK : 0 < K) (hSout : 0 < Sout)\n (hb : 0 < b) (hbn : b ≤ n) (hd : 0 < d) (hn : 0 < n)\n (γ p L θ onesP σ2 : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ < 1) (hp : p = (1 + γ) / (1 - γ))\n (hL : 0 < L) (hθ0 : 0 < θ) (hθ1 : θ < 1) (hσ : 0 ≤ σ2)\n (honesP : onesP = onesNorm p d)\n (fi : Fin n → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradfi : Fin n → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hsmoothi : ∀ i, ∀ x y : EuclideanSpace ℝ (Fin d),\n ‖gradfi i x - gradfi i y‖ ≤ L * ‖x - y‖)\n (hdiff : ∀ i, ∀ x : EuclideanSpace ℝ (Fin d), HasGradientAt (fi i) (gradfi i x) x)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hf : f = fun w => (1 / (n : ℝ)) * ∑ i, fi i w)\n (hgradf : gradf = fun w => (1 / (n : ℝ)) • ∑ i, gradfi i w)\n (hsmooth : ∀ x y : EuclideanSpace ℝ (Fin d),\n f x ≤ f y + ⟪gradf y, x - y⟫ + L / 2 * ‖x - y‖ ^ 2)\n (wstar : EuclideanSpace ℝ (Fin d)) (hmin : ∀ x, f wstar ≤ f x)\n (W gS : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (gSt : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (nu : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d)) (eta : ℕ → ℕ → Ω → ℝ)\n (Sidx : ℕ → ℕ → Ω → Finset (Fin n))\n (hindepS : ProbabilityTheory.iIndepFun (ι := ℕ × ℕ)\n (m := fun _ => (⊤ : MeasurableSpace (Finset (Fin n))))\n (fun ks ω => Sidx ks.1 ks.2 ω) μ)\n (hScard : ∀ k s ω, (Sidx k s ω).card = b)\n (hgS : ∀ k s ω, gS k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W k (s + 1) ω))\n (hgSt : ∀ k s ω, gSt k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W K s ω))\n (hnu : ∀ k s ω, nu k s ω = gS k s ω - gSt k s ω + gradf (W K s ω))\n (heta : ∀ k s ω, eta k s ω\n = ⟪nu k s ω, sigmaGamma γ (nu k s ω)⟫ / (L * ‖sigmaGamma γ (nu k s ω)‖ ^ 2))\n (hsigmaNu : ∀ k < K, ∀ s < Sout, ∀ ω, sigmaGamma γ (nu k s ω) ≠ 0)\n (hupd : ∀ k s ω,\n W (k + 1) (s + 1) ω = W k (s + 1) ω - eta k s ω • sigmaGamma γ (nu k s ω))\n (hlink : ∀ s ω, W 0 (s + 1) ω = W K s ω)\n\n (hintGS : ∀ k s, Integrable (fun ω => gS k s ω) μ)\n (hintGSt : ∀ k s, Integrable (fun ω => gSt k s ω) μ)\n (hintGW : ∀ k s, Integrable (fun ω => gradf (W k (s + 1) ω)) μ)\n (hintGWt : ∀ s, Integrable (fun ω => gradf (W K s ω)) μ)\n (hunb1 : ∀ k s, ∫ ω, gS k s ω ∂μ = ∫ ω, gradf (W k (s + 1) ω) ∂μ)\n (hunb2 : ∀ k s, ∫ ω, gSt k s ω ∂μ = ∫ ω, gradf (W K s ω) ∂μ)\n\n (hintVar1 : ∀ k s, Integrable (fun ω => ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2) μ)\n (hintVar2 : ∀ k s, Integrable (fun ω => ‖gSt k s ω - gradf (W K s ω)‖ ^ 2) μ)\n (hvar1 : ∀ k s, ∫ ω, ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvar2 : ∀ k s, ∫ ω, ‖gSt k s ω - gradf (W K s ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvarPrim : ∀ w : EuclideanSpace ℝ (Fin d),\n (1 / (n : ℝ)) * ∑ i, ‖gradfi i w - gradf w‖ ^ 2 ≤ σ2)\n (hintSum : Integrable (fun ω => ∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) μ)\n (hintGap : Integrable (fun ω => f (W K 0 ω) - f wstar) μ) :\n (1 / (T : ℝ)) * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) ∂μ)\n ≤ (4 * L * onesP) / ((T : ℝ) * (1 - θ))\n * (∫ ω, (f (W K 0 ω) - f wstar) ∂μ)\n + 8 * onesP * σ2 / ((b : ℝ) * θ * (1 - θ)) := by\n sorry\n\ntheorem theorem2 {d n K Sout T b bH : ℕ}\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (hT : T = K * Sout) (hT1 : 1 ≤ T) (hK : 0 < K) (hSout : 0 < Sout)\n (hb : 0 < b) (hbHpos : 0 < bH) (hbn : b ≤ n) (hbHn : bH ≤ n) (hd : 0 < d) (hn : 0 < n)\n (γ p L θ onesP σ2 ζ τ : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ < 1) (hp : p = (1 + γ) / (1 - γ))\n (hL : 0 < L) (hθ0 : 0 < θ) (hσ : 0 ≤ σ2)\n (hτ : 0 < τ) (hζ : 0 < ζ)\n (hbH2 : 0 < 2 * (bH : ℝ) - θ * (bH : ℝ) - 1)\n (honesP : onesP = onesNorm p d)\n (fi : Fin n → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradfi : Fin n → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hsmoothi : ∀ i, ∀ x y : EuclideanSpace ℝ (Fin d),\n ‖gradfi i x - gradfi i y‖ ≤ L * ‖x - y‖)\n (hdiff : ∀ i, ∀ x : EuclideanSpace ℝ (Fin d), HasGradientAt (fi i) (gradfi i x) x)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hf : f = fun w => (1 / (n : ℝ)) * ∑ i, fi i w)\n (hgradf : gradf = fun w => (1 / (n : ℝ)) • ∑ i, gradfi i w)\n (hsmooth : ∀ x y : EuclideanSpace ℝ (Fin d),\n f x ≤ f y + ⟪gradf y, x - y⟫ + L / 2 * ‖x - y‖ ^ 2)\n (wstar : EuclideanSpace ℝ (Fin d)) (hmin : ∀ x, f wstar ≤ f x)\n (W gS : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (gSt : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (nu : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d)) (eta : ℕ → ℕ → Ω → ℝ)\n (Sidx : ℕ → ℕ → Ω → Finset (Fin n)) (SidxH : ℕ → ℕ → Ω → Finset (Fin n))\n (hindepS : ProbabilityTheory.iIndepFun (ι := ℕ × ℕ)\n (m := fun _ => (⊤ : MeasurableSpace (Finset (Fin n))))\n (fun ks ω => Sidx ks.1 ks.2 ω) μ)\n (hindepSH : ProbabilityTheory.iIndepFun (ι := ℕ × ℕ)\n (m := fun _ => (⊤ : MeasurableSpace (Finset (Fin n))))\n (fun ks ω => SidxH ks.1 ks.2 ω) μ)\n (gSHa gSHb : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (hScard : ∀ k s ω, (Sidx k s ω).card = b)\n (hSHcard : ∀ k s ω, (SidxH k s ω).card = bH)\n (hgS : ∀ k s ω, gS k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W k (s + 1) ω))\n (hgSt : ∀ k s ω, gSt k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W K s ω))\n (hgSHa : ∀ k s ω, gSHa k s ω = (1 / (bH : ℝ)) • ∑ i ∈ SidxH k s ω, gradfi i (W (k + 1) (s + 1) ω))\n (hgSHb : ∀ k s ω, gSHb k s ω = (1 / (bH : ℝ)) • ∑ i ∈ SidxH k s ω, gradfi i (W k (s + 1) ω))\n (hnu : ∀ k s ω, nu k s ω = gS k s ω - gSt k s ω + gradf (W K s ω))\n (eta0 : ℝ) (heta0 : ∀ s ω, eta 0 s ω = eta0)\n (heta : ∀ k s ω, eta (k + 1) s ω = (ζ / bH)\n * (‖W (k + 1) (s + 1) ω - W k (s + 1) ω‖ ^ 2\n / (⟪W (k + 1) (s + 1) ω - W k (s + 1) ω,\n sigmaGamma γ (gSHa k s ω) - sigmaGamma γ (gSHb k s ω)⟫\n + τ * ‖W (k + 1) (s + 1) ω - W k (s + 1) ω‖ ^ 2)))\n (hupd : ∀ k s ω,\n W (k + 1) (s + 1) ω = W k (s + 1) ω - eta k s ω • sigmaGamma γ (nu k s ω))\n (hlink : ∀ s ω, W 0 (s + 1) ω = W K s ω)\n\n (hΔW : ∀ k < K, ∀ s < Sout, ∀ ω, W (k + 1) (s + 1) ω - W k (s + 1) ω ≠ 0)\n\n (hbb_ip : ∀ k s ω, 0 ≤ ⟪W (k + 1) (s + 1) ω - W k (s + 1) ω,\n sigmaGamma γ (gSHa k s ω) - sigmaGamma γ (gSHb k s ω)⟫)\n (hLem1 : ∀ k s ω, eta k s ω ≤ ζ / ((bH : ℝ) * τ))\n\n (hintGS : ∀ k s, Integrable (fun ω => gS k s ω) μ)\n (hintGSt : ∀ k s, Integrable (fun ω => gSt k s ω) μ)\n (hintGW : ∀ k s, Integrable (fun ω => gradf (W k (s + 1) ω)) μ)\n (hintGWt : ∀ s, Integrable (fun ω => gradf (W K s ω)) μ)\n (hunb1 : ∀ k s, ∫ ω, gS k s ω ∂μ = ∫ ω, gradf (W k (s + 1) ω) ∂μ)\n (hunb2 : ∀ k s, ∫ ω, gSt k s ω ∂μ = ∫ ω, gradf (W K s ω) ∂μ)\n\n (hintVar1 : ∀ k s, Integrable (fun ω => ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2) μ)\n (hintVar2 : ∀ k s, Integrable (fun ω => ‖gSt k s ω - gradf (W K s ω)‖ ^ 2) μ)\n (hvar1 : ∀ k s, ∫ ω, ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvar2 : ∀ k s, ∫ ω, ‖gSt k s ω - gradf (W K s ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvarPrim : ∀ w : EuclideanSpace ℝ (Fin d),\n (1 / (n : ℝ)) * ∑ i, ‖gradfi i w - gradf w‖ ^ 2 ≤ σ2)\n (hintSum : Integrable (fun ω => ∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) μ)\n (hintGap : Integrable (fun ω => f (W K 0 ω) - f wstar) μ)\n (hintFgap : ∀ k s,\n Integrable (fun ω => f (W (k + 1) (s + 1) ω) - f (W k (s + 1) ω)) μ)\n (hdescent : ∀ k < K, ∀ s < Sout,\n (∫ ω, (f (W (k + 1) (s + 1) ω) - f (W k (s + 1) ω)) ∂μ)\n ≤ -((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) / (4 * L * (bH : ℝ) ^ 2 * onesP))\n * (∫ ω, (lpNorm (1 + γ) (gS k s ω)) ^ 2 ∂μ)\n + 2 * σ2 / (L * (bH : ℝ) * (b : ℝ) * θ)) :\n (1 / (T : ℝ)) * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) ∂μ)\n ≤ 4 * (bH : ℝ) ^ 2 * L * onesP\n / ((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) * (T : ℝ))\n * (∫ ω, (f (W K 0 ω) - f wstar) ∂μ)\n + 8 * σ2 * (bH : ℝ) * onesP\n / ((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) * (b : ℝ) * θ) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen scoped RealInnerProductSpace\nopen MeasureTheory\n\nnamespace ResearchLevel\n\nnoncomputable def sigmaGamma {d : ℕ} (γ : ℝ) (x : EuclideanSpace ℝ (Fin d)) :\n EuclideanSpace ℝ (Fin d) :=\n (WithLp.equiv 2 (Fin d → ℝ)).symm (fun i => Real.sign (x i) * |x i| ^ γ)\n\nnoncomputable def lpNorm {d : ℕ} (r : ℝ) (x : EuclideanSpace ℝ (Fin d)) : ℝ :=\n (∑ i, |x i| ^ r) ^ (1 / r)\n\nnoncomputable def onesNorm (p : ℝ) (d : ℕ) : ℝ := (d : ℝ) ^ (1 / p)\n\nprivate lemma continuous_lpNorm_sq {d : ℕ} {r : ℝ} (hr : 0 < r) :\n Continuous (fun x : EuclideanSpace ℝ (Fin d) => (lpNorm r x) ^ 2) := by\n apply Continuous.pow\n unfold lpNorm\n apply Continuous.rpow_const\n · exact continuous_finset_sum _ fun i _ =>\n (PiLp.continuous_apply (p := 2) (β := fun _ : Fin d => ℝ) i).abs.rpow_const\n (fun _ => Or.inr hr.le)\n · intro x\n exact Or.inr (one_div_nonneg.mpr hr.le)\n\nprivate lemma sigmaGamma_apply {d : ℕ} (γ : ℝ) (x : EuclideanSpace ℝ (Fin d))\n (i : Fin d) : sigmaGamma γ x i = Real.sign (x i) * |x i| ^ γ := by\n rfl\n\nprivate lemma inner_sigma_eq_sum {d : ℕ} (γ : ℝ) (x : EuclideanSpace ℝ (Fin d)) :\n ⟪x, sigmaGamma γ x⟫ = ∑ i, x i * (Real.sign (x i) * |x i| ^ γ) := by\n simp [PiLp.inner_apply, sigmaGamma, RCLike.inner_apply]\n apply Finset.sum_congr rfl\n intro i hi\n ring\n\nprivate lemma norm_sigma_sq_eq_sum {d : ℕ} (γ : ℝ) (x : EuclideanSpace ℝ (Fin d)) :\n ‖sigmaGamma γ x‖ ^ 2 =\n ∑ i, |Real.sign (x i) * |x i| ^ γ| ^ 2 := by\n rw [EuclideanSpace.norm_sq_eq]\n simp only [Real.norm_eq_abs]\n apply Finset.sum_congr rfl\n intro i hi\n congr 2\n\nprivate lemma scalar_inner (x γ : ℝ) (hγ : 0 ≤ γ) :\n x * (Real.sign x * |x| ^ γ) = |x| ^ (1 + γ) := by\n rcases lt_trichotomy x 0 with hx | rfl | hx\n · rw [Real.sign_of_neg hx, abs_of_neg hx]\n have hp : 0 < -x := neg_pos.mpr hx\n rw [show 1 + γ = γ + 1 by ring, Real.rpow_add_one hp.ne']\n ring\n · simp only [Real.sign_zero, zero_mul, abs_zero]\n rw [Real.zero_rpow]\n linarith\n · rw [Real.sign_of_pos hx, abs_of_pos hx]\n rw [show 1 + γ = γ + 1 by ring, Real.rpow_add_one hx.ne']\n ring\n\nprivate lemma scalar_norm_bound (x γ : ℝ) (_hγ : 0 ≤ γ) :\n |Real.sign x * |x| ^ γ| ^ 2 ≤ |x| ^ (2 * γ) := by\n by_cases hx : x = 0\n · subst x\n simp only [Real.sign_zero, zero_mul, abs_zero]\n rw [show (0 : ℝ) ^ 2 = 0 by norm_num]\n exact Real.rpow_nonneg (le_refl 0) _\n · have hs : |Real.sign x| = 1 := by\n rcases Real.sign_apply_eq_of_ne_zero x hx with h | h <;> rw [h] <;> norm_num\n rw [abs_mul, hs, one_mul,\n abs_of_nonneg (Real.rpow_nonneg (abs_nonneg x) γ)]\n calc\n (|x| ^ γ) ^ 2 = (|x| ^ γ) ^ (2 : ℝ) := (Real.rpow_two _).symm\n _ = |x| ^ (γ * 2) := (Real.rpow_mul (abs_nonneg x) γ 2).symm\n _ = |x| ^ (2 * γ) := by ring_nf\n _ ≤ |x| ^ (2 * γ) := le_rfl\n\nprivate lemma sum_rpow_le_card_factor {d : ℕ} (hd : 0 < d) (q : ℝ)\n (hq0 : 0 ≤ q) (hq1 : q ≤ 1) (a : Fin d → ℝ)\n (ha : ∀ i, 0 ≤ a i) :\n (∑ i, a i ^ q) ≤ (d : ℝ) ^ (1 - q) * (∑ i, a i) ^ q := by\n have hdR : 0 < (d : ℝ) := by exact_mod_cast hd\n have hw : ∑ _i : Fin d, (1 / (d : ℝ)) = 1 := by\n simp only [Finset.sum_const, Finset.card_fin, nsmul_eq_mul]\n field_simp\n have hJ := (Real.concaveOn_rpow hq0 hq1).le_map_sum\n (t := Finset.univ) (w := fun _ : Fin d => 1 / (d : ℝ)) (p := a)\n (fun _ _ => by positivity) hw (fun i _ => ha i)\n simp only [smul_eq_mul] at hJ\n have hscaled : (1 / (d : ℝ)) * (∑ i, a i ^ q) ≤\n ((1 / (d : ℝ)) * (∑ i, a i)) ^ q := by\n simpa only [Finset.mul_sum] using hJ\n have hmul := mul_le_mul_of_nonneg_left hscaled hdR.le\n have hsum_nonneg : 0 ≤ ∑ i, a i := Finset.sum_nonneg fun i _ => ha i\n calc\n (∑ i, a i ^ q) = (d : ℝ) * ((1 / (d : ℝ)) * (∑ i, a i ^ q)) := by\n field_simp\n _ ≤ (d : ℝ) * (((1 / (d : ℝ)) * (∑ i, a i)) ^ q) := hmul\n _ = (d : ℝ) ^ (1 - q) * (∑ i, a i) ^ q := by\n rw [show (1 / (d : ℝ)) * (∑ i, a i) = (∑ i, a i) / (d : ℝ) by ring]\n rw [Real.div_rpow hsum_nonneg hdR.le]\n rw [Real.rpow_sub hdR 1 q, Real.rpow_one]\n field_simp [ne_of_gt (Real.rpow_pos_of_pos hdR q)]\n\nlemma powerball_lower {d : ℕ} (γ : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ < 1)\n (p : ℝ) (hp : p = (1 + γ) / (1 - γ)) (hd : 0 < d)\n (x : EuclideanSpace ℝ (Fin d)) (hx : sigmaGamma γ x ≠ 0) :\n (⟪x, sigmaGamma γ x⟫) ^ 2 / ‖sigmaGamma γ x‖ ^ 2\n ≥ (lpNorm (1 + γ) x) ^ 2 / onesNorm p d := by\n let r : ℝ := 1 + γ\n let q : ℝ := 2 * γ / r\n let A : ℝ := ∑ i, |x i| ^ r\n let B : ℝ := ∑ i, |x i| ^ (2 * γ)\n have hr : 0 < r := by dsimp [r]; linarith\n have hdR : 0 < (d : ℝ) := by exact_mod_cast hd\n have hpR : 0 < p := by\n rw [hp]\n exact div_pos (by linarith) (by linarith)\n have hq0 : 0 ≤ q := by\n dsimp [q]\n positivity\n have hq1 : q ≤ 1 := by\n dsimp [q, r]\n apply (div_le_iff₀ (by linarith : 0 < 1 + γ)).2\n linarith\n have hex : ∃ i : Fin d, sigmaGamma γ x i ≠ 0 := by\n by_contra h\n push_neg at h\n apply hx\n ext i\n exact h i\n obtain ⟨i, hi⟩ := hex\n have hxi : x i ≠ 0 := by\n intro hxi\n apply hi\n rw [sigmaGamma_apply]\n simp only [hxi, Real.sign_zero, abs_zero, zero_mul]\n have hA : 0 < A := by\n apply Finset.sum_pos'\n · intro j hj\n exact Real.rpow_nonneg (abs_nonneg _) _\n · refine ⟨i, Finset.mem_univ i, Real.rpow_pos_of_pos (abs_pos.mpr hxi) r⟩\n have hinner : ⟪x, sigmaGamma γ x⟫ = A := by\n rw [inner_sigma_eq_sum]\n apply Finset.sum_congr rfl\n intro j hj\n exact scalar_inner (x j) γ hγ0\n have hnormB : ‖sigmaGamma γ x‖ ^ 2 ≤ B := by\n rw [norm_sigma_sq_eq_sum]\n apply Finset.sum_le_sum\n intro j hj\n exact scalar_norm_bound (x j) γ hγ0\n have hB : B ≤ (d : ℝ) ^ (1 - q) * A ^ q := by\n have hJ := sum_rpow_le_card_factor hd q hq0 hq1\n (fun j : Fin d => |x j| ^ r)\n (fun j => Real.rpow_nonneg (abs_nonneg _) _)\n calc\n B = ∑ j, (|x j| ^ r) ^ q := by\n apply Finset.sum_congr rfl\n intro j hj\n calc\n |x j| ^ (2 * γ) = |x j| ^ (r * q) := by\n congr 1\n dsimp [q, r]\n field_simp\n _ = (|x j| ^ r) ^ q := Real.rpow_mul (abs_nonneg (x j)) r q\n _ ≤ (d : ℝ) ^ (1 - q) * (∑ j, |x j| ^ r) ^ q := hJ\n _ = (d : ℝ) ^ (1 - q) * A ^ q := by rfl\n have hnorm : ‖sigmaGamma γ x‖ ^ 2 ≤ (d : ℝ) ^ (1 - q) * A ^ q :=\n hnormB.trans hB\n have hNpos : 0 < ‖sigmaGamma γ x‖ ^ 2 := pow_pos (norm_pos_iff.mpr hx) _\n have hDpos : 0 < (d : ℝ) ^ (1 / p) := Real.rpow_pos_of_pos hdR _\n have hexpD : 1 - q = 1 / p := by\n rw [hp]\n dsimp [q, r]\n field_simp [ne_of_gt (by linarith : 0 < 1 + γ),\n ne_of_gt (by linarith : 0 < 1 - γ)]\n ring\n have hfactor : (A ^ (1 / r)) ^ 2 * A ^ q = A ^ 2 := by\n rw [← Real.rpow_two, ← Real.rpow_mul hA.le]\n rw [← Real.rpow_add hA]\n have he : 1 / r * 2 + q = 2 := by\n dsimp [q, r]\n field_simp [ne_of_gt (by linarith : 0 < 1 + γ)]\n rw [he, Real.rpow_two]\n rw [hinner]\n change (lpNorm r x) ^ 2 / (d : ℝ) ^ (1 / p) ≤\n A ^ 2 / ‖sigmaGamma γ x‖ ^ 2\n apply (div_le_div_iff₀ hDpos hNpos).2\n unfold lpNorm\n change (A ^ (1 / r)) ^ 2 * ‖sigmaGamma γ x‖ ^ 2 ≤\n A ^ 2 * (d : ℝ) ^ (1 / p)\n calc\n _ ≤ (A ^ (1 / r)) ^ 2 * ((d : ℝ) ^ (1 - q) * A ^ q) :=\n mul_le_mul_of_nonneg_left hnorm (sq_nonneg _)\n _ = A ^ 2 * (d : ℝ) ^ (1 / p) := by\n rw [hexpD]\n calc\n (A ^ (1 / r)) ^ 2 * ((d : ℝ) ^ (1 / p) * A ^ q) =\n ((A ^ (1 / r)) ^ 2 * A ^ q) * (d : ℝ) ^ (1 / p) := by ring\n _ = _ := by rw [hfactor]\n\nprivate lemma lpNorm_sq_le_ones_mul_norm_sq {d : ℕ} (γ p : ℝ)\n (hγ0 : 0 ≤ γ) (hγ1 : γ < 1) (hp : p = (1 + γ) / (1 - γ))\n (x : EuclideanSpace ℝ (Fin d)) :\n (lpNorm (1 + γ) x) ^ 2 ≤ (d : ℝ) ^ (1 / p) * ‖x‖ ^ 2 := by\n let r : ℝ := 1 + γ\n let q : ℝ := 2 / r\n have hr : 0 < r := by dsimp [r]; linarith\n have hq : 1 ≤ q := by\n dsimp [q, r]\n apply (le_div_iff₀ (by linarith : 0 < 1 + γ)).2\n linarith\n have h := Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg\n (s := Finset.univ) (f := fun i : Fin d => |x i| ^ r) hq\n (fun i hi => Real.rpow_nonneg (abs_nonneg _) _)\n calc\n (lpNorm (1 + γ) x) ^ 2 = (∑ i, |x i| ^ r) ^ q := by\n unfold lpNorm\n let S : ℝ := ∑ i, |x i| ^ r\n have hS : 0 ≤ S := Finset.sum_nonneg fun i _ =>\n Real.rpow_nonneg (abs_nonneg _) _\n calc\n (S ^ (1 / (1 + γ))) ^ 2 = (S ^ (1 / (1 + γ))) ^ (2 : ℝ) :=\n (Real.rpow_two _).symm\n _ = S ^ ((1 / (1 + γ)) * 2) :=\n (Real.rpow_mul hS (1 / (1 + γ)) 2).symm\n _ = S ^ q := by\n congr 1\n dsimp [q, r]\n ring\n _ = _ := by rfl\n _ ≤ (d : ℝ) ^ (q - 1) * ∑ i, (|x i| ^ r) ^ q := by\n simpa only [Finset.card_univ, Fintype.card_fin] using h\n _ = (d : ℝ) ^ (1 / p) * ‖x‖ ^ 2 := by\n have he : q - 1 = 1 / p := by\n rw [hp]\n dsimp [q, r]\n field_simp [ne_of_gt (by linarith : 0 < 1 + γ),\n ne_of_gt (by linarith : 0 < 1 - γ)]\n ring\n rw [he, EuclideanSpace.norm_sq_eq]\n congr 1\n apply Finset.sum_congr rfl\n intro i hi\n calc\n (|x i| ^ r) ^ q = |x i| ^ (r * q) :=\n (Real.rpow_mul (abs_nonneg (x i)) r q).symm\n _ = |x i| ^ (2 : ℝ) := by\n congr 1\n dsimp [q]\n field_simp [ne_of_gt hr]\n _ = ‖x i‖ ^ 2 := by\n rw [Real.rpow_two, Real.norm_eq_abs]\n\nprivate lemma lpNorm_nonneg {d : ℕ} (r : ℝ) (x : EuclideanSpace ℝ (Fin d)) :\n 0 ≤ lpNorm r x := by\n unfold lpNorm\n exact Real.rpow_nonneg (Finset.sum_nonneg fun i _ =>\n Real.rpow_nonneg (abs_nonneg _) _) _\n\nprivate lemma lpNorm_add_le {d : ℕ} {r : ℝ} (hr : 1 ≤ r)\n (x y : EuclideanSpace ℝ (Fin d)) :\n lpNorm r (x + y) ≤ lpNorm r x + lpNorm r y := by\n unfold lpNorm\n simpa only [Finset.mem_univ, Pi.add_apply] using\n (Real.Lp_add_le Finset.univ (fun i : Fin d => x i) (fun i => y i) hr)\n\nprivate lemma normalized_lpNorm_le_norm {d : ℕ} (γ p : ℝ)\n (hγ0 : 0 ≤ γ) (hγ1 : γ < 1) (hp : p = (1 + γ) / (1 - γ))\n (hd : 0 < d) (x : EuclideanSpace ℝ (Fin d)) :\n lpNorm (1 + γ) x / Real.sqrt ((d : ℝ) ^ (1 / p)) ≤ ‖x‖ := by\n have hpR : 0 < p := by\n rw [hp]\n exact div_pos (by linarith) (by linarith)\n have hdR : 0 < (d : ℝ) := by exact_mod_cast hd\n have hD : 0 < (d : ℝ) ^ (1 / p) := Real.rpow_pos_of_pos hdR _\n have hs : 0 < Real.sqrt ((d : ℝ) ^ (1 / p)) := Real.sqrt_pos.2 hD\n apply (div_le_iff₀ hs).2\n apply (sq_le_sq₀ (lpNorm_nonneg _ _) (mul_nonneg (norm_nonneg _) hs.le)).mp\n calc\n (lpNorm (1 + γ) x) ^ 2 ≤ (d : ℝ) ^ (1 / p) * ‖x‖ ^ 2 :=\n lpNorm_sq_le_ones_mul_norm_sq γ p hγ0 hγ1 hp x\n _ = (‖x‖ * Real.sqrt ((d : ℝ) ^ (1 / p))) ^ 2 := by\n rw [mul_pow, Real.sq_sqrt hD.le]\n ring\n\nprivate lemma scalar_descent_half (t A U V G : ℝ)\n (ht0 : 0 < t) (hth : t ≤ 1 / 2)\n (hA : 0 ≤ A) (_hU : 0 ≤ U) (hV : 0 ≤ V) (hG : 0 ≤ G)\n (hGA : G ≤ A + V) :\n -(A ^ 2) / 2 + A * (U + V) ≤\n -(1 - t) / 4 * G ^ 2 + (U ^ 2 + V ^ 2) / t := by\n have hsqG : G ^ 2 ≤ (A + V) ^ 2 :=\n (sq_le_sq₀ hG (add_nonneg hA hV)).2 hGA\n have hnegG : -(1 - t) / 4 * (A + V) ^ 2 ≤\n -(1 - t) / 4 * G ^ 2 := by\n exact mul_le_mul_of_nonpos_left hsqG (by linarith)\n have hyoungU : A * U ≤ t / 4 * A ^ 2 + U ^ 2 / t := by\n rw [show t / 4 * A ^ 2 + U ^ 2 / t =\n (t ^ 2 / 4 * A ^ 2 + U ^ 2) / t by\n field_simp [ne_of_gt ht0]]\n apply (le_div_iff₀ ht0).2\n nlinarith [sq_nonneg (t / 2 * A - U)]\n have hrem : 0 ≤ 1 / t - (1 - t) / 4 - ((3 - t) / 2) ^ 2 := by\n have hsecond : 0 ≤ t ^ 2 - 6 * t + 4 := by\n nlinarith [sq_nonneg t]\n have hnum : 0 ≤ (1 - t) * (t ^ 2 - 6 * t + 4) :=\n mul_nonneg (by linarith) hsecond\n rw [show 1 / t - (1 - t) / 4 - ((3 - t) / 2) ^ 2 =\n ((1 - t) * (t ^ 2 - 6 * t + 4)) / (4 * t) by\n field_simp [ne_of_gt ht0]\n ring]\n positivity\n have hVpart :\n -(A ^ 2) / 2 + t / 4 * A ^ 2 + A * V ≤\n -(1 - t) / 4 * (A + V) ^ 2 + V ^ 2 / t := by\n apply sub_nonneg.mp\n rw [show\n (-(1 - t) / 4 * (A + V) ^ 2 + V ^ 2 / t) -\n (-(A ^ 2) / 2 + t / 4 * A ^ 2 + A * V) =\n (A / 2 - (3 - t) / 2 * V) ^ 2 +\n (1 / t - (1 - t) / 4 - ((3 - t) / 2) ^ 2) * V ^ 2 by\n field_simp [ne_of_gt ht0]\n ring]\n positivity\n calc\n -(A ^ 2) / 2 + A * (U + V) =\n (-(A ^ 2) / 2 + A * V) + A * U := by ring\n _ ≤ (-(A ^ 2) / 2 + A * V) + (t / 4 * A ^ 2 + U ^ 2 / t) := by\n gcongr\n _ ≤ (-(1 - t) / 4 * (A + V) ^ 2 + V ^ 2 / t) + U ^ 2 / t := by\n linarith\n _ ≤ -(1 - t) / 4 * G ^ 2 + (U ^ 2 + V ^ 2) / t := by\n calc\n _ ≤ (-(1 - t) / 4 * G ^ 2 + V ^ 2 / t) + U ^ 2 / t := by\n gcongr\n _ = _ := by ring\n\nprivate lemma inner_sigma_pos {d : ℕ} (γ : ℝ) (hγ0 : 0 ≤ γ)\n (x : EuclideanSpace ℝ (Fin d)) (hx : sigmaGamma γ x ≠ 0) :\n 0 < ⟪x, sigmaGamma γ x⟫ := by\n rw [inner_sigma_eq_sum]\n apply Finset.sum_pos'\n · intro i hi\n rw [scalar_inner (x i) γ hγ0]\n exact Real.rpow_nonneg (abs_nonneg _) _\n · have hex : ∃ i : Fin d, sigmaGamma γ x i ≠ 0 := by\n by_contra h\n push_neg at h\n apply hx\n ext i\n exact h i\n obtain ⟨i, hi⟩ := hex\n have hxi : x i ≠ 0 := by\n intro hxi\n apply hi\n rw [sigmaGamma_apply]\n simp only [hxi, Real.sign_zero, abs_zero, zero_mul]\n refine ⟨i, Finset.mem_univ i, ?_⟩\n rw [scalar_inner (x i) γ hγ0]\n exact Real.rpow_pos_of_pos (abs_pos.mpr hxi) _\n\nprivate lemma raw_powerball_descent {d : ℕ} (γ L : ℝ) (hγ0 : 0 ≤ γ) (hL : 0 < L)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hsmooth : ∀ x y : EuclideanSpace ℝ (Fin d),\n f x ≤ f y + ⟪gradf y, x - y⟫ + L / 2 * ‖x - y‖ ^ 2)\n (x ν xnext : EuclideanSpace ℝ (Fin d)) (η : ℝ)\n (hσ : sigmaGamma γ ν ≠ 0)\n (hη : η = ⟪ν, sigmaGamma γ ν⟫ /\n (L * ‖sigmaGamma γ ν‖ ^ 2))\n (hnext : xnext = x - η • sigmaGamma γ ν) :\n f xnext - f x ≤ (1 / L) *\n (-(⟪ν, sigmaGamma γ ν⟫ / ‖sigmaGamma γ ν‖) ^ 2 / 2 +\n (⟪ν, sigmaGamma γ ν⟫ / ‖sigmaGamma γ ν‖) * ‖ν - gradf x‖) := by\n let z := sigmaGamma γ ν\n let I : ℝ := ⟪ν, z⟫\n let N : ℝ := ‖z‖\n have hN : 0 < N := by\n dsimp [N, z]\n exact norm_pos_iff.mpr hσ\n have hI : 0 < I := by\n dsimp [I, z]\n exact inner_sigma_pos γ hγ0 ν hσ\n have hdiff : xnext - x = -η • z := by\n rw [hnext]\n module\n have hcs : ⟪ν - gradf x, z⟫ ≤ ‖ν - gradf x‖ * N := by\n exact real_inner_le_norm _ _\n have hη' : η = I / (L * N ^ 2) := by\n simpa only [I, N, z] using hη\n have hbase := hsmooth xnext x\n rw [hdiff] at hbase\n have hIz : ⟪gradf x, z⟫ = I - ⟪ν - gradf x, z⟫ := by\n dsimp [I]\n rw [inner_sub_left]\n ring\n have hform :\n ⟪gradf x, -η • z⟫ + L / 2 * ‖-η • z‖ ^ 2 =\n -(I ^ 2) / (2 * L * N ^ 2) +\n I / (L * N ^ 2) * ⟪ν - gradf x, z⟫ := by\n rw [hη']\n simp only [inner_smul_right, norm_smul, Real.norm_eq_abs, norm_neg]\n rw [show ‖z‖ = N by rfl]\n rw [abs_of_pos (div_pos hI (mul_pos hL (sq_pos_of_pos hN)))]\n rw [hIz]\n field_simp [ne_of_gt hL, ne_of_gt hN]\n ring\n have hcoef : 0 ≤ I / (L * N ^ 2) := by positivity\n have hupper :\n -(I ^ 2) / (2 * L * N ^ 2) +\n I / (L * N ^ 2) * ⟪ν - gradf x, z⟫ ≤\n -(I ^ 2) / (2 * L * N ^ 2) +\n I / (L * N ^ 2) * (‖ν - gradf x‖ * N) := by\n gcongr\n calc\n f xnext - f x ≤ ⟪gradf x, -η • z⟫ + L / 2 * ‖-η • z‖ ^ 2 := by\n linarith\n _ = -(I ^ 2) / (2 * L * N ^ 2) +\n I / (L * N ^ 2) * ⟪ν - gradf x, z⟫ := hform\n _ ≤ -(I ^ 2) / (2 * L * N ^ 2) +\n I / (L * N ^ 2) * (‖ν - gradf x‖ * N) := hupper\n _ = (1 / L) * (-(I / N) ^ 2 / 2 + (I / N) * ‖ν - gradf x‖) := by\n field_simp [ne_of_gt hL, ne_of_gt hN]\n _ = _ := by rfl\n\nprivate lemma powerball_descent_bound {d : ℕ}\n (γ p L t : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ < 1)\n (hp : p = (1 + γ) / (1 - γ)) (hd : 0 < d)\n (hL : 0 < L) (ht0 : 0 < t) (hth : t ≤ 1 / 2)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hsmooth : ∀ x y : EuclideanSpace ℝ (Fin d),\n f x ≤ f y + ⟪gradf y, x - y⟫ + L / 2 * ‖x - y‖ ^ 2)\n (x g ν xnext : EuclideanSpace ℝ (Fin d)) (η : ℝ)\n (hσ : sigmaGamma γ ν ≠ 0)\n (hη : η = ⟪ν, sigmaGamma γ ν⟫ /\n (L * ‖sigmaGamma γ ν‖ ^ 2))\n (hnext : xnext = x - η • sigmaGamma γ ν) :\n f xnext - f x ≤\n -(1 - t) / (4 * L * (d : ℝ) ^ (1 / p)) * (lpNorm (1 + γ) g) ^ 2 +\n 1 / (L * t) * (‖g - gradf x‖ ^ 2 + ‖ν - g‖ ^ 2) := by\n let D : ℝ := (d : ℝ) ^ (1 / p)\n let A : ℝ := ⟪ν, sigmaGamma γ ν⟫ / ‖sigmaGamma γ ν‖\n let U : ℝ := ‖g - gradf x‖\n let V : ℝ := ‖ν - g‖\n let G : ℝ := lpNorm (1 + γ) g / Real.sqrt D\n have hpR : 0 < p := by\n rw [hp]\n exact div_pos (by linarith) (by linarith)\n have hdR : 0 < (d : ℝ) := by exact_mod_cast hd\n have hD : 0 < D := by\n dsimp [D]\n exact Real.rpow_pos_of_pos hdR _\n have hsD : 0 < Real.sqrt D := Real.sqrt_pos.2 hD\n have hA : 0 < A := by\n dsimp [A]\n exact div_pos (inner_sigma_pos γ hγ0 ν hσ) (norm_pos_iff.mpr hσ)\n have hU : 0 ≤ U := by dsimp [U]; positivity\n have hV : 0 ≤ V := by dsimp [V]; positivity\n have hG : 0 ≤ G := by\n dsimp [G]\n exact div_nonneg (lpNorm_nonneg _ _) hsD.le\n have hdiff : ‖ν - gradf x‖ ≤ U + V := by\n calc\n ‖ν - gradf x‖ = ‖(ν - g) + (g - gradf x)‖ := by congr 1 <;> module\n _ ≤ ‖ν - g‖ + ‖g - gradf x‖ := norm_add_le _ _\n _ = U + V := by dsimp [U, V]; ring\n have hnuRatio : lpNorm (1 + γ) ν / Real.sqrt D ≤ A := by\n have hpb := powerball_lower γ hγ0 hγ1 p hp hd ν hσ\n have hleft : (lpNorm (1 + γ) ν / Real.sqrt D) ^ 2 =\n (lpNorm (1 + γ) ν) ^ 2 / D := by\n rw [div_pow, Real.sq_sqrt hD.le]\n have hright : A ^ 2 =\n (⟪ν, sigmaGamma γ ν⟫) ^ 2 / ‖sigmaGamma γ ν‖ ^ 2 := by\n dsimp [A]\n rw [div_pow]\n apply (sq_le_sq₀ (div_nonneg (lpNorm_nonneg _ _) hsD.le) hA.le).mp\n rw [hleft, hright]\n simpa only [D, onesNorm] using hpb\n have herrRatio : lpNorm (1 + γ) (g - ν) / Real.sqrt D ≤ ‖g - ν‖ := by\n simpa only [D] using\n normalized_lpNorm_le_norm γ p hγ0 hγ1 hp hd (g - ν)\n have hGA : G ≤ A + V := by\n have hlp : lpNorm (1 + γ) g ≤\n lpNorm (1 + γ) ν + lpNorm (1 + γ) (g - ν) := by\n calc\n lpNorm (1 + γ) g = lpNorm (1 + γ) (ν + (g - ν)) := by\n congr 2 <;> module\n _ ≤ _ := lpNorm_add_le (by linarith : 1 ≤ 1 + γ) _ _\n calc\n G ≤ (lpNorm (1 + γ) ν + lpNorm (1 + γ) (g - ν)) / Real.sqrt D :=\n (div_le_div_iff_of_pos_right hsD).2 hlp\n _ = lpNorm (1 + γ) ν / Real.sqrt D +\n lpNorm (1 + γ) (g - ν) / Real.sqrt D := by ring\n _ ≤ A + ‖g - ν‖ := add_le_add hnuRatio herrRatio\n _ = A + V := by dsimp [V]; rw [norm_sub_rev]\n have hscalar := scalar_descent_half t A U V G ht0 hth hA.le hU hV hG hGA\n have hraw := raw_powerball_descent γ L hγ0 hL f gradf hsmooth\n x ν xnext η hσ hη hnext\n calc\n f xnext - f x ≤ (1 / L) *\n (-(A ^ 2) / 2 + A * ‖ν - gradf x‖) := by\n simpa only [A] using hraw\n _ ≤ (1 / L) * (-(A ^ 2) / 2 + A * (U + V)) := by\n gcongr\n _ ≤ (1 / L) *\n (-(1 - t) / 4 * G ^ 2 + (U ^ 2 + V ^ 2) / t) := by\n gcongr\n _ = -(1 - t) / (4 * L * (d : ℝ) ^ (1 / p)) *\n (lpNorm (1 + γ) g) ^ 2 +\n 1 / (L * t) * (‖g - gradf x‖ ^ 2 + ‖ν - g‖ ^ 2) := by\n dsimp [G, U, V, D]\n rw [div_pow, Real.sq_sqrt hD.le]\n field_simp [ne_of_gt hL, ne_of_gt ht0, ne_of_gt hD]\n ring\n\nprivate lemma telescope_integral_bound\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n (K Sout T : ℕ) (hT : T = K * Sout) (a c : ℝ)\n (F X : ℕ → ℕ → Ω → ℝ) (fstar : ℝ)\n (hlink : ∀ s ω, F 0 (s + 1) ω = F K s ω)\n (hmin : ∀ ω, fstar ≤ F K Sout ω)\n (hXint : ∀ k s, k < K → s < Sout → Integrable (X k s) μ)\n (hDint : ∀ k s, Integrable (fun ω => F (k + 1) (s + 1) ω - F k (s + 1) ω) μ)\n (hintGap : Integrable (fun ω => F K 0 ω - fstar) μ)\n (hstep : ∀ k s,\n (∫ ω, (F (k + 1) (s + 1) ω - F k (s + 1) ω) ∂μ) ≤\n -a * (∫ ω, X k s ω ∂μ) + c) :\n a * (∫ ω, (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω) ∂μ) ≤\n (∫ ω, (F K 0 ω - fstar) ∂μ) + (T : ℝ) * c := by\n have hXsumInt :\n (∫ ω, (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω) ∂μ) =\n ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, (∫ ω, X k s ω ∂μ) := by\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (∫ ω, (∑ k ∈ Finset.range K, X k s ω) ∂μ) := by\n apply integral_finset_sum\n intro s hs\n apply integrable_finset_sum\n intro k hk\n exact hXint k s (Finset.mem_range.mp hk) (Finset.mem_range.mp hs)\n _ = _ := by\n apply Finset.sum_congr rfl\n intro s hs\n exact integral_finset_sum _ (fun k hk =>\n hXint k s (Finset.mem_range.mp hk) (Finset.mem_range.mp hs))\n let Dlt : ℕ → ℕ → Ω → ℝ := fun k s ω =>\n F (k + 1) (s + 1) ω - F k (s + 1) ω\n have hDsumInt : Integrable\n (fun ω => ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, Dlt k s ω) μ := by\n apply integrable_finset_sum\n intro s hs\n apply integrable_finset_sum\n intro k hk\n simpa only [Dlt] using hDint k s\n have hDtelescope : ∀ ω,\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, Dlt k s ω) =\n F K Sout ω - F K 0 ω := by\n intro ω\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (F K (s + 1) ω - F 0 (s + 1) ω) := by\n apply Finset.sum_congr rfl\n intro s hs\n simpa only [Dlt] using\n (Finset.sum_range_sub (fun k => F k (s + 1) ω) K)\n _ = ∑ s ∈ Finset.range Sout,\n (F K (s + 1) ω - F K s ω) := by\n apply Finset.sum_congr rfl\n intro s hs\n rw [hlink s ω]\n _ = _ := by\n simpa using (Finset.sum_range_sub (fun s => F K s ω) Sout)\n have hFinalInt : Integrable (fun ω => F K Sout ω - F K 0 ω) μ :=\n hDsumInt.congr (Filter.Eventually.of_forall hDtelescope)\n have hDsumIntegral :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, Dlt k s ω ∂μ)) =\n ∫ ω, (F K Sout ω - F K 0 ω) ∂μ := by\n calc\n _ = ∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, Dlt k s ω) ∂μ := by\n symm\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (∫ ω, (∑ k ∈ Finset.range K, Dlt k s ω) ∂μ) := by\n apply integral_finset_sum\n intro s hs\n apply integrable_finset_sum\n intro k hk\n simpa only [Dlt] using hDint k s\n _ = _ := by\n apply Finset.sum_congr rfl\n intro s hs\n exact integral_finset_sum _ (fun k hk => by\n simpa only [Dlt] using hDint k s)\n _ = _ := integral_congr_ae (Filter.Eventually.of_forall hDtelescope)\n have hgapLower :\n -(∫ ω, (F K 0 ω - fstar) ∂μ) ≤\n ∫ ω, (F K Sout ω - F K 0 ω) ∂μ := by\n rw [← integral_neg]\n apply integral_mono hintGap.neg hFinalInt\n intro ω\n simp only [Pi.neg_apply]\n linarith [hmin ω]\n have hsumStep :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, Dlt k s ω ∂μ)) ≤\n -a * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, X k s ω ∂μ)) + (K * Sout : ℕ) * c := by\n calc\n _ ≤ ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (-a * (∫ ω, X k s ω ∂μ) + c) := by\n exact Finset.sum_le_sum fun s _ =>\n Finset.sum_le_sum fun k _ => by\n simpa only [Dlt] using hstep k s\n _ = _ := by\n simp only [Finset.sum_add_distrib, Finset.mul_sum, Finset.sum_const,\n Finset.card_range, nsmul_eq_mul]\n push_cast\n ring\n have hmaster :\n -(∫ ω, (F K 0 ω - fstar) ∂μ) ≤\n -a * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) + (T : ℝ) * c := by\n calc\n _ ≤ ∫ ω, (F K Sout ω - F K 0 ω) ∂μ := hgapLower\n _ = ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, Dlt k s ω ∂μ) := hDsumIntegral.symm\n _ ≤ -a * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, X k s ω ∂μ)) + (K * Sout : ℕ) * c := hsumStep\n _ = -a * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) + (T : ℝ) * c := by\n rw [hXsumInt]\n rw [hT]\n linarith\n\ntheorem theorem1 {d n K Sout T b : ℕ}\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (hT : T = K * Sout) (hT1 : 1 ≤ T) (hK : 0 < K) (hSout : 0 < Sout)\n (hb : 0 < b) (hbn : b ≤ n) (hd : 0 < d) (hn : 0 < n)\n (γ p L θ onesP σ2 : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ < 1) (hp : p = (1 + γ) / (1 - γ))\n (hL : 0 < L) (hθ0 : 0 < θ) (hθ1 : θ < 1) (hσ : 0 ≤ σ2)\n (honesP : onesP = onesNorm p d)\n (fi : Fin n → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradfi : Fin n → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hsmoothi : ∀ i, ∀ x y : EuclideanSpace ℝ (Fin d),\n ‖gradfi i x - gradfi i y‖ ≤ L * ‖x - y‖)\n (hdiff : ∀ i, ∀ x : EuclideanSpace ℝ (Fin d), HasGradientAt (fi i) (gradfi i x) x)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hf : f = fun w => (1 / (n : ℝ)) * ∑ i, fi i w)\n (hgradf : gradf = fun w => (1 / (n : ℝ)) • ∑ i, gradfi i w)\n (hsmooth : ∀ x y : EuclideanSpace ℝ (Fin d),\n f x ≤ f y + ⟪gradf y, x - y⟫ + L / 2 * ‖x - y‖ ^ 2)\n (wstar : EuclideanSpace ℝ (Fin d)) (hmin : ∀ x, f wstar ≤ f x)\n (W gS : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (gSt : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (nu : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d)) (eta : ℕ → ℕ → Ω → ℝ)\n (Sidx : ℕ → ℕ → Ω → Finset (Fin n))\n (hindepS : ProbabilityTheory.iIndepFun (ι := ℕ × ℕ)\n (m := fun _ => (⊤ : MeasurableSpace (Finset (Fin n))))\n (fun ks ω => Sidx ks.1 ks.2 ω) μ)\n (hScard : ∀ k s ω, (Sidx k s ω).card = b)\n (hgS : ∀ k s ω, gS k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W k (s + 1) ω))\n (hgSt : ∀ k s ω, gSt k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W K s ω))\n (hnu : ∀ k s ω, nu k s ω = gS k s ω - gSt k s ω + gradf (W K s ω))\n (heta : ∀ k s ω, eta k s ω\n = ⟪nu k s ω, sigmaGamma γ (nu k s ω)⟫ / (L * ‖sigmaGamma γ (nu k s ω)‖ ^ 2))\n (hsigmaNu : ∀ k < K, ∀ s < Sout, ∀ ω, sigmaGamma γ (nu k s ω) ≠ 0)\n (hupd : ∀ k s ω,\n W (k + 1) (s + 1) ω = W k (s + 1) ω - eta k s ω • sigmaGamma γ (nu k s ω))\n (hlink : ∀ s ω, W 0 (s + 1) ω = W K s ω)\n\n (hintGS : ∀ k s, Integrable (fun ω => gS k s ω) μ)\n (hintGSt : ∀ k s, Integrable (fun ω => gSt k s ω) μ)\n (hintGW : ∀ k s, Integrable (fun ω => gradf (W k (s + 1) ω)) μ)\n (hintGWt : ∀ s, Integrable (fun ω => gradf (W K s ω)) μ)\n (hunb1 : ∀ k s, ∫ ω, gS k s ω ∂μ = ∫ ω, gradf (W k (s + 1) ω) ∂μ)\n (hunb2 : ∀ k s, ∫ ω, gSt k s ω ∂μ = ∫ ω, gradf (W K s ω) ∂μ)\n\n (hintVar1 : ∀ k s, Integrable (fun ω => ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2) μ)\n (hintVar2 : ∀ k s, Integrable (fun ω => ‖gSt k s ω - gradf (W K s ω)‖ ^ 2) μ)\n (hvar1 : ∀ k s, ∫ ω, ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvar2 : ∀ k s, ∫ ω, ‖gSt k s ω - gradf (W K s ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvarPrim : ∀ w : EuclideanSpace ℝ (Fin d),\n (1 / (n : ℝ)) * ∑ i, ‖gradfi i w - gradf w‖ ^ 2 ≤ σ2)\n (hintSum : Integrable (fun ω => ∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) μ)\n (hintGap : Integrable (fun ω => f (W K 0 ω) - f wstar) μ) :\n (1 / (T : ℝ)) * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) ∂μ)\n ≤ (4 * L * onesP) / ((T : ℝ) * (1 - θ))\n * (∫ ω, (f (W K 0 ω) - f wstar) ∂μ)\n + 8 * onesP * σ2 / ((b : ℝ) * θ * (1 - θ)) := by\n let X : ℕ → ℕ → Ω → ℝ := fun k s ω =>\n (lpNorm (1 + γ) (gS k s ω)) ^ 2\n let F : ℕ → ℕ → Ω → ℝ := fun k s ω => f (W k s ω)\n let t : ℝ := min θ (1 / 2)\n let a : ��� := (1 - t) / (4 * L * onesP)\n let c : ℝ := 2 * σ2 / (L * (b : ℝ) * t)\n have hr : 0 < 1 + γ := by linarith\n have hbR : 0 < (b : ℝ) := by exact_mod_cast hb\n have hTR : 0 < (T : ℝ) := by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one hT1)\n have hpR : 0 < p := by\n rw [hp]\n exact div_pos (by linarith) (by linarith)\n have hones : 0 < onesP := by\n rw [honesP, onesNorm]\n exact Real.rpow_pos_of_pos (by exact_mod_cast hd) _\n have ht0 : 0 < t := by\n dsimp [t]\n exact lt_min hθ0 (by norm_num)\n have hth : t ≤ 1 / 2 := by\n dsimp [t]\n exact min_le_right _ _\n have ht1 : t < 1 := lt_of_le_of_lt hth (by norm_num)\n have ha : 0 < a := by\n dsimp [a]\n exact div_pos (sub_pos.mpr ht1) (by positivity)\n have hXnonneg : ∀ k s ω, 0 ≤ X k s ω := by\n intro k s ω\n simp only [X]\n positivity\n have hXmeas : ∀ k s, AEStronglyMeasurable (X k s) μ := by\n intro k s\n exact (continuous_lpNorm_sq hr).comp_aestronglyMeasurable\n (hintGS k s).aestronglyMeasurable\n have hXint : ∀ k s, k < K → s < Sout → Integrable (X k s) μ := by\n intro k s hk hs\n apply hintSum.mono' (hXmeas k s)\n filter_upwards with ω\n rw [Real.norm_eq_abs, abs_of_nonneg (hXnonneg k s ω)]\n have hinner : X k s ω ≤ ∑ j ∈ Finset.range K, X j s ω :=\n Finset.single_le_sum\n (fun j _ => hXnonneg j s ω) (Finset.mem_range.mpr hk)\n have houter : (∑ j ∈ Finset.range K, X j s ω) ≤\n ∑ t ∈ Finset.range Sout, ∑ j ∈ Finset.range K, X j t ω :=\n Finset.single_le_sum\n (fun t _ => Finset.sum_nonneg (fun j _ => hXnonneg j t ω))\n (Finset.mem_range.mpr hs)\n simpa only [X] using hinner.trans houter\n let E1 : ℕ → ℕ → Ω → ℝ := fun k s ω =>\n ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2\n let E2 : ℕ → ℕ → Ω → ℝ := fun k s ω =>\n ‖gSt k s ω - gradf (W K s ω)‖ ^ 2\n have hpoint : ∀ k < K, ∀ s < Sout, ∀ ω,\n F (k + 1) (s + 1) ω - F k (s + 1) ω ≤\n -a * X k s ω + (1 / (L * t)) * (E1 k s ω + E2 k s ω) := by\n intro k hk s hs ω\n have hbase := powerball_descent_bound γ p L t hγ0 hγ1 hp hd hL ht0 hth\n f gradf hsmooth (W k (s + 1) ω) (gS k s ω) (nu k s ω)\n (W (k + 1) (s + 1) ω) (eta k s ω)\n (hsigmaNu k hk s hs ω) (heta k s ω) (hupd k s ω)\n have hv : ‖nu k s ω - gS k s ω‖ ^ 2 = E2 k s ω := by\n simp only [E2]\n rw [hnu]\n rw [show gS k s ω - gSt k s ω + gradf (W K s ω) - gS k s ω =\n -(gSt k s ω - gradf (W K s ω)) by module, norm_neg]\n rw [hv] at hbase\n simp only [F, X, E1, a, honesP, onesNorm]\n ring_nf at hbase ⊢\n exact hbase\n have htotalPoint : ∀ ω,\n a * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω) ≤\n f (W K 0 ω) - f wstar + (1 / (L * t)) *\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (E1 k s ω + E2 k s ω)) := by\n intro ω\n have hsummed :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (F (k + 1) (s + 1) ω - F k (s + 1) ω)) ≤\n ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (-a * X k s ω + (1 / (L * t)) * (E1 k s ω + E2 k s ω)) :=\n Finset.sum_le_sum fun s hs => Finset.sum_le_sum fun k hk =>\n hpoint k (Finset.mem_range.mp hk) s (Finset.mem_range.mp hs) ω\n have htel :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (F (k + 1) (s + 1) ω - F k (s + 1) ω)) =\n f (W K Sout ω) - f (W K 0 ω) := by\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (F K (s + 1) ω - F 0 (s + 1) ω) := by\n apply Finset.sum_congr rfl\n intro s hs\n simpa using (Finset.sum_range_sub (fun k => F k (s + 1) ω) K)\n _ = ∑ s ∈ Finset.range Sout,\n (F K (s + 1) ω - F K s ω) := by\n apply Finset.sum_congr rfl\n intro s hs\n simp only [F]\n rw [hlink s ω]\n _ = _ := by\n simp only [F]\n simpa using (Finset.sum_range_sub (fun s => f (W K s ω)) Sout)\n have hrhs :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (-a * X k s ω + (1 / (L * t)) * (E1 k s ω + E2 k s ω))) =\n -a * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω) +\n (1 / (L * t)) * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (E1 k s ω + E2 k s ω)) := by\n have hfac (r : ℝ) (E : ℕ → ℕ → Ω → ℝ) :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, r * E k s ω) =\n r * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, E k s ω) := by\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro s hs\n rw [Finset.mul_sum]\n simp only [mul_add, Finset.sum_add_distrib]\n rw [hfac (-a) X, hfac (1 / (L * t)) E1, hfac (1 / (L * t)) E2]\n rw [htel, hrhs] at hsummed\n linarith [hmin (W K Sout ω)]\n have hEint : Integrable\n (fun ω => ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (E1 k s ω + E2 k s ω)) μ := by\n apply integrable_finset_sum\n intro s hs\n apply integrable_finset_sum\n intro k hk\n have h1 : Integrable (E1 k s) μ := by simpa only [E1] using hintVar1 k s\n have h2 : Integrable (E2 k s) μ := by simpa only [E2] using hintVar2 k s\n exact h1.add h2\n have hEbound :\n (∫ ω, (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (E1 k s ω + E2 k s ω)) ∂μ) ≤\n (T : ℝ) * (2 * σ2 / (b : ℝ)) := by\n calc\n _ = ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, (E1 k s ω + E2 k s ω) ∂μ) := by\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (∫ ω, (∑ k ∈ Finset.range K, (E1 k s ω + E2 k s ω)) ∂μ) := by\n apply integral_finset_sum\n intro s hs\n apply integrable_finset_sum\n intro k hk\n have h1 : Integrable (E1 k s) μ := by\n simpa only [E1] using hintVar1 k s\n have h2 : Integrable (E2 k s) μ := by\n simpa only [E2] using hintVar2 k s\n exact h1.add h2\n _ = _ := by\n apply Finset.sum_congr rfl\n intro s hs\n exact integral_finset_sum _ (fun k hk => by\n have h1 : Integrable (E1 k s) μ := by\n simpa only [E1] using hintVar1 k s\n have h2 : Integrable (E2 k s) μ := by\n simpa only [E2] using hintVar2 k s\n exact h1.add h2)\n _ = ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n ((∫ ω, E1 k s ω ∂μ) + (∫ ω, E2 k s ω ∂μ)) := by\n apply Finset.sum_congr rfl\n intro s hs\n apply Finset.sum_congr rfl\n intro k hk\n rw [integral_add (by simpa only [E1] using hintVar1 k s)\n (by simpa only [E2] using hintVar2 k s)]\n _ ≤ ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (σ2 / (b : ℝ) + σ2 / (b : ℝ)) := by\n exact Finset.sum_le_sum fun s _ => Finset.sum_le_sum fun k _ =>\n add_le_add (by simpa only [E1] using hvar1 k s)\n (by simpa only [E2] using hvar2 k s)\n _ = (T : ℝ) * (2 * σ2 / (b : ℝ)) := by\n simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul]\n rw [hT]\n push_cast\n ring\n have hleftInt : Integrable\n (fun ω => a * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω)) μ := by\n simpa only [X] using hintSum.const_mul a\n have hrightInt : Integrable\n (fun ω => f (W K 0 ω) - f wstar + (1 / (L * t)) *\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (E1 k s ω + E2 k s ω))) μ :=\n hintGap.add (hEint.const_mul (1 / (L * t)))\n have hintIneq := integral_mono hleftInt hrightInt htotalPoint\n rw [integral_const_mul, integral_add hintGap (hEint.const_mul (1 / (L * t))),\n integral_const_mul] at hintIneq\n have hcoef : 0 ≤ 1 / (L * t) := by positivity\n have hprod :\n a * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) ≤\n (∫ ω, (f (W K 0 ω) - f wstar) ∂μ) + (T : ℝ) * c := by\n calc\n _ ≤ (∫ ω, (f (W K 0 ω) - f wstar) ∂μ) +\n (1 / (L * t)) * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (E1 k s ω + E2 k s ω)) ∂μ) := hintIneq\n _ ≤ (∫ ω, (f (W K 0 ω) - f wstar) ∂μ) +\n (1 / (L * t)) * ((T : ℝ) * (2 * σ2 / (b : ℝ))) := by\n gcongr\n _ = _ := by\n dsimp [c]\n ring\n have hobj :\n (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) ≤\n ((∫ ω, (f (W K 0 ω) - f wstar) ∂μ) + (T : ℝ) * c) / a := by\n apply (le_div_iff₀ ha).2\n simpa only [F, mul_comm] using hprod\n change (1 / (T : ℝ)) *\n (∫ ω, (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω) ∂μ) ≤ _\n calc\n _ ≤ (1 / (T : ℝ)) *\n (((∫ ω, (f (W K 0 ω) - f wstar) ∂μ) + (T : ℝ) * c) / a) :=\n mul_le_mul_of_nonneg_left hobj (by positivity)\n _ = (4 * L * onesP) / ((T : ℝ) * (1 - t))\n * (∫ ω, (f (W K 0 ω) - f wstar) ∂μ)\n + 8 * onesP * σ2 / ((b : ℝ) * t * (1 - t)) := by\n dsimp [a, c]\n field_simp [ne_of_gt hTR, ne_of_gt hL, ne_of_gt hbR, ne_of_gt ht0,\n ne_of_gt hones, ne_of_gt (sub_pos.mpr ht1)]\n ring\n _ ≤ (4 * L * onesP) / ((T : ℝ) * (1 - θ))\n * (∫ ω, (f (W K 0 ω) - f wstar) ∂μ)\n + 8 * onesP * σ2 / ((b : ℝ) * θ * (1 - θ)) := by\n have hgap0 : 0 ≤ ∫ ω, (f (W K 0 ω) - f wstar) ∂μ := by\n apply integral_nonneg\n intro ω\n exact sub_nonneg.mpr (hmin (W K 0 ω))\n have htθ : t ≤ θ := by\n dsimp [t]\n exact min_le_left _ _\n have hprodcomp : θ * (1 - θ) ≤ t * (1 - t) := by\n by_cases hθh : θ ≤ 1 / 2\n · have htEq : t = θ := by\n dsimp [t]\n exact min_eq_left hθh\n rw [htEq]\n · have hhalfθ : 1 / 2 ≤ θ := le_of_lt (lt_of_not_ge hθh)\n have htEq : t = 1 / 2 := by\n dsimp [t]\n exact min_eq_right hhalfθ\n rw [htEq]\n nlinarith [sq_nonneg (θ - 1 / 2)]\n have hdent : 0 < (T : ℝ) * (1 - t) :=\n mul_pos hTR (sub_pos.mpr ht1)\n have hdenθ : 0 < (T : ℝ) * (1 - θ) :=\n mul_pos hTR (sub_pos.mpr hθ1)\n have hgapcoef :\n (4 * L * onesP) / ((T : ℝ) * (1 - t)) ≤\n (4 * L * onesP) / ((T : ℝ) * (1 - θ)) := by\n apply (div_le_div_iff₀ hdent hdenθ).2\n apply mul_le_mul_of_nonneg_left _ (by positivity)\n exact mul_le_mul_of_nonneg_left (by linarith) hTR.le\n have hdentv : 0 < (b : ℝ) * t * (1 - t) :=\n mul_pos (mul_pos hbR ht0) (sub_pos.mpr ht1)\n have hdenθv : 0 < (b : ℝ) * θ * (1 - θ) :=\n mul_pos (mul_pos hbR hθ0) (sub_pos.mpr hθ1)\n have hdencomp :\n (b : ℝ) * θ * (1 - θ) ≤ (b : ℝ) * t * (1 - t) := by\n calc\n (b : ℝ) * θ * (1 - θ) = (b : ℝ) * (θ * (1 - θ)) := by ring\n _ ≤ (b : ℝ) * (t * (1 - t)) :=\n mul_le_mul_of_nonneg_left hprodcomp hbR.le\n _ = (b : ℝ) * t * (1 - t) := by ring\n have hvarcoef :\n 8 * onesP * σ2 / ((b : ℝ) * t * (1 - t)) ≤\n 8 * onesP * σ2 / ((b : ℝ) * θ * (1 - θ)) := by\n apply (div_le_div_iff₀ hdentv hdenθv).2\n exact mul_le_mul_of_nonneg_left hdencomp (by positivity)\n exact add_le_add (mul_le_mul_of_nonneg_right hgapcoef hgap0) hvarcoef\n\ntheorem theorem2 {d n K Sout T b bH : ℕ}\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (hT : T = K * Sout) (hT1 : 1 ≤ T) (hK : 0 < K) (hSout : 0 < Sout)\n (hb : 0 < b) (hbHpos : 0 < bH) (hbn : b ≤ n) (hbHn : bH ≤ n) (hd : 0 < d) (hn : 0 < n)\n (γ p L θ onesP σ2 ζ τ : ℝ) (hγ0 : 0 ≤ γ) (hγ1 : γ < 1) (hp : p = (1 + γ) / (1 - γ))\n (hL : 0 < L) (hθ0 : 0 < θ) (hσ : 0 ≤ σ2)\n (hτ : 0 < τ) (hζ : 0 < ζ)\n (hbH2 : 0 < 2 * (bH : ℝ) - θ * (bH : ℝ) - 1)\n (honesP : onesP = onesNorm p d)\n (fi : Fin n → EuclideanSpace ℝ (Fin d) → ℝ)\n (gradfi : Fin n → EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hsmoothi : ∀ i, ∀ x y : EuclideanSpace ℝ (Fin d),\n ‖gradfi i x - gradfi i y‖ ≤ L * ‖x - y‖)\n (hdiff : ∀ i, ∀ x : EuclideanSpace ℝ (Fin d), HasGradientAt (fi i) (gradfi i x) x)\n (f : EuclideanSpace ℝ (Fin d) → ℝ)\n (gradf : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin d))\n (hf : f = fun w => (1 / (n : ℝ)) * ∑ i, fi i w)\n (hgradf : gradf = fun w => (1 / (n : ℝ)) • ∑ i, gradfi i w)\n (hsmooth : ∀ x y : EuclideanSpace ℝ (Fin d),\n f x ≤ f y + ⟪gradf y, x - y⟫ + L / 2 * ‖x - y‖ ^ 2)\n (wstar : EuclideanSpace ℝ (Fin d)) (hmin : ∀ x, f wstar ≤ f x)\n (W gS : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (gSt : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (nu : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d)) (eta : ℕ → ℕ → Ω → ℝ)\n (Sidx : ℕ → ℕ → Ω → Finset (Fin n)) (SidxH : ℕ → ℕ → Ω → Finset (Fin n))\n (hindepS : ProbabilityTheory.iIndepFun (ι := ℕ × ℕ)\n (m := fun _ => (⊤ : MeasurableSpace (Finset (Fin n))))\n (fun ks ω => Sidx ks.1 ks.2 ω) μ)\n (hindepSH : ProbabilityTheory.iIndepFun (ι := ℕ × ℕ)\n (m := fun _ => (⊤ : MeasurableSpace (Finset (Fin n))))\n (fun ks ω => SidxH ks.1 ks.2 ω) μ)\n (gSHa gSHb : ℕ → ℕ → Ω → EuclideanSpace ℝ (Fin d))\n (hScard : ∀ k s ω, (Sidx k s ω).card = b)\n (hSHcard : ∀ k s ω, (SidxH k s ω).card = bH)\n (hgS : ∀ k s ω, gS k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W k (s + 1) ω))\n (hgSt : ∀ k s ω, gSt k s ω = (1 / (b : ℝ)) • ∑ i ∈ Sidx k s ω, gradfi i (W K s ω))\n (hgSHa : ∀ k s ω, gSHa k s ω = (1 / (bH : ℝ)) • ∑ i ∈ SidxH k s ω, gradfi i (W (k + 1) (s + 1) ω))\n (hgSHb : ∀ k s ω, gSHb k s ω = (1 / (bH : ℝ)) • ∑ i ∈ SidxH k s ω, gradfi i (W k (s + 1) ω))\n (hnu : ∀ k s ω, nu k s ω = gS k s ω - gSt k s ω + gradf (W K s ω))\n (eta0 : ℝ) (heta0 : ∀ s ω, eta 0 s ω = eta0)\n (heta : ∀ k s ω, eta (k + 1) s ω = (ζ / bH)\n * (‖W (k + 1) (s + 1) ω - W k (s + 1) ω‖ ^ 2\n / (⟪W (k + 1) (s + 1) ω - W k (s + 1) ω,\n sigmaGamma γ (gSHa k s ω) - sigmaGamma γ (gSHb k s ω)⟫\n + τ * ‖W (k + 1) (s + 1) ω - W k (s + 1) ω‖ ^ 2)))\n (hupd : ∀ k s ω,\n W (k + 1) (s + 1) ω = W k (s + 1) ω - eta k s ω • sigmaGamma γ (nu k s ω))\n (hlink : ∀ s ω, W 0 (s + 1) ω = W K s ω)\n\n (hΔW : ∀ k < K, ∀ s < Sout, ∀ ω, W (k + 1) (s + 1) ω - W k (s + 1) ω ≠ 0)\n\n (hbb_ip : ∀ k s ω, 0 ≤ ⟪W (k + 1) (s + 1) ω - W k (s + 1) ω,\n sigmaGamma γ (gSHa k s ω) - sigmaGamma γ (gSHb k s ω)⟫)\n (hLem1 : ∀ k s ω, eta k s ω ≤ ζ / ((bH : ℝ) * τ))\n\n (hintGS : ∀ k s, Integrable (fun ω => gS k s ω) μ)\n (hintGSt : ∀ k s, Integrable (fun ω => gSt k s ω) μ)\n (hintGW : ∀ k s, Integrable (fun ω => gradf (W k (s + 1) ω)) μ)\n (hintGWt : ∀ s, Integrable (fun ω => gradf (W K s ω)) μ)\n (hunb1 : ∀ k s, ∫ ω, gS k s ω ∂μ = ∫ ω, gradf (W k (s + 1) ω) ∂μ)\n (hunb2 : ∀ k s, ∫ ω, gSt k s ω ∂μ = ∫ ω, gradf (W K s ω) ∂μ)\n\n (hintVar1 : ∀ k s, Integrable (fun ω => ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2) μ)\n (hintVar2 : ∀ k s, Integrable (fun ω => ‖gSt k s ω - gradf (W K s ω)‖ ^ 2) μ)\n (hvar1 : ∀ k s, ∫ ω, ‖gS k s ω - gradf (W k (s + 1) ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvar2 : ∀ k s, ∫ ω, ‖gSt k s ω - gradf (W K s ω)‖ ^ 2 ∂μ ≤ σ2 / (b : ℝ))\n (hvarPrim : ∀ w : EuclideanSpace ℝ (Fin d),\n (1 / (n : ℝ)) * ∑ i, ‖gradfi i w - gradf w‖ ^ 2 ≤ σ2)\n (hintSum : Integrable (fun ω => ∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) μ)\n (hintGap : Integrable (fun ω => f (W K 0 ω) - f wstar) μ)\n (hintFgap : ∀ k s,\n Integrable (fun ω => f (W (k + 1) (s + 1) ω) - f (W k (s + 1) ω)) μ)\n (hdescent : ∀ k < K, ∀ s < Sout,\n (∫ ω, (f (W (k + 1) (s + 1) ω) - f (W k (s + 1) ω)) ∂μ)\n ≤ -((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) / (4 * L * (bH : ℝ) ^ 2 * onesP))\n * (∫ ω, (lpNorm (1 + γ) (gS k s ω)) ^ 2 ∂μ)\n + 2 * σ2 / (L * (bH : ℝ) * (b : ℝ) * θ)) :\n (1 / (T : ℝ)) * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, (lpNorm (1 + γ) (gS k s ω)) ^ 2) ∂μ)\n ≤ 4 * (bH : ℝ) ^ 2 * L * onesP\n / ((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) * (T : ℝ))\n * (∫ ω, (f (W K 0 ω) - f wstar) ∂μ)\n + 8 * σ2 * (bH : ℝ) * onesP\n / ((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) * (b : ℝ) * θ) := by\n let X : ℕ → ℕ → Ω → ℝ := fun k s ω =>\n (lpNorm (1 + γ) (gS k s ω)) ^ 2\n let Dlt : ℕ → ℕ → Ω → ℝ := fun k s ω =>\n f (W (k + 1) (s + 1) ω) - f (W k (s + 1) ω)\n let a : ℝ :=\n (2 * (bH : ℝ) - θ * (bH : ℝ) - 1) /\n (4 * L * (bH : ℝ) ^ 2 * onesP)\n let c : ℝ := 2 * σ2 / (L * (bH : ℝ) * (b : ℝ) * θ)\n\n have hr : 0 < 1 + γ := by linarith\n have hbR : 0 < (b : ℝ) := by exact_mod_cast hb\n have hbHR : 0 < (bH : ℝ) := by exact_mod_cast hbHpos\n have hTR : 0 < (T : ℝ) := by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one hT1)\n have hpR : 0 < p := by\n rw [hp]\n exact div_pos (by linarith) (by linarith)\n have hones : 0 < onesP := by\n rw [honesP, onesNorm]\n exact Real.rpow_pos_of_pos (by exact_mod_cast hd) _\n have ha : 0 < a := by\n dsimp [a]\n positivity\n\n have hXnonneg : ∀ k s ω, 0 ≤ X k s ω := by\n intro k s ω\n simp only [X]\n positivity\n have hXmeas : ∀ k s, AEStronglyMeasurable (X k s) μ := by\n intro k s\n exact (continuous_lpNorm_sq hr).comp_aestronglyMeasurable\n (hintGS k s).aestronglyMeasurable\n have hXint : ∀ k s, k < K → s < Sout → Integrable (X k s) μ := by\n intro k s hk hs\n apply hintSum.mono' (hXmeas k s)\n filter_upwards with ω\n rw [Real.norm_eq_abs, abs_of_nonneg (hXnonneg k s ω)]\n have hinner : X k s ω ≤ ∑ j ∈ Finset.range K, X j s ω :=\n Finset.single_le_sum\n (fun j _ => hXnonneg j s ω) (Finset.mem_range.mpr hk)\n have houter : (∑ j ∈ Finset.range K, X j s ω) ≤\n ∑ t ∈ Finset.range Sout, ∑ j ∈ Finset.range K, X j t ω :=\n Finset.single_le_sum\n (fun t _ => Finset.sum_nonneg (fun j _ => hXnonneg j t ω))\n (Finset.mem_range.mpr hs)\n simpa only [X] using hinner.trans houter\n\n have hXsumInt :\n (∫ ω, (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω) ∂μ) =\n ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, (∫ ω, X k s ω ∂μ) := by\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (∫ ω, (∑ k ∈ Finset.range K, X k s ω) ∂μ) := by\n apply integral_finset_sum\n intro s hs\n apply integrable_finset_sum\n intro k hk\n exact hXint k s (Finset.mem_range.mp hk) (Finset.mem_range.mp hs)\n _ = _ := by\n apply Finset.sum_congr rfl\n intro s hs\n exact integral_finset_sum _ (fun k hk =>\n hXint k s (Finset.mem_range.mp hk) (Finset.mem_range.mp hs))\n\n have hDint : ∀ k s, Integrable (Dlt k s) μ := by\n intro k s\n simpa only [Dlt] using hintFgap k s\n have hDsumInt : Integrable\n (fun ω => ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, Dlt k s ω) μ := by\n apply integrable_finset_sum\n intro s hs\n apply integrable_finset_sum\n intro k hk\n exact hDint k s\n have hDtelescope : ∀ ω,\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, Dlt k s ω) =\n f (W K Sout ω) - f (W K 0 ω) := by\n intro ω\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (f (W K (s + 1) ω) - f (W 0 (s + 1) ω)) := by\n apply Finset.sum_congr rfl\n intro s hs\n simpa only [Dlt] using\n (Finset.sum_range_sub (fun k => f (W k (s + 1) ω)) K)\n _ = ∑ s ∈ Finset.range Sout,\n (f (W K (s + 1) ω) - f (W K s ω)) := by\n apply Finset.sum_congr rfl\n intro s hs\n rw [hlink s ω]\n _ = _ := by\n simpa using (Finset.sum_range_sub (fun s => f (W K s ω)) Sout)\n have hFinalInt : Integrable\n (fun ω => f (W K Sout ω) - f (W K 0 ω)) μ :=\n hDsumInt.congr (Filter.Eventually.of_forall hDtelescope)\n have hDsumIntegral :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, Dlt k s ω ∂μ)) =\n ∫ ω, (f (W K Sout ω) - f (W K 0 ω)) ∂μ := by\n calc\n _ = ∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, Dlt k s ω) ∂μ := by\n symm\n calc\n _ = ∑ s ∈ Finset.range Sout,\n (∫ ω, (∑ k ∈ Finset.range K, Dlt k s ω) ∂μ) := by\n apply integral_finset_sum\n intro s hs\n exact integrable_finset_sum _ (fun k hk => hDint k s)\n _ = _ := by\n apply Finset.sum_congr rfl\n intro s hs\n exact integral_finset_sum _ (fun k hk => hDint k s)\n _ = _ := integral_congr_ae (Filter.Eventually.of_forall hDtelescope)\n\n have hgapLower :\n -(∫ ω, (f (W K 0 ω) - f wstar) ∂μ) ≤\n ∫ ω, (f (W K Sout ω) - f (W K 0 ω)) ∂μ := by\n rw [← integral_neg]\n apply integral_mono hintGap.neg hFinalInt\n intro ω\n simp only [Pi.neg_apply]\n have hm := hmin (W K Sout ω)\n linarith\n\n have hstep : ∀ k < K, ∀ s < Sout,\n (∫ ω, Dlt k s ω ∂μ) ≤ -a * (∫ ω, X k s ω ∂μ) + c := by\n intro k hk s hs\n simpa only [Dlt, X, a, c] using hdescent k hk s hs\n have hsumStep :\n (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, Dlt k s ω ∂μ)) ≤\n -a * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, X k s ω ∂μ)) + (K * Sout : ℕ) * c := by\n calc\n _ ≤ ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (-a * (∫ ω, X k s ω ∂μ) + c) := by\n exact Finset.sum_le_sum fun s hs =>\n Finset.sum_le_sum fun k hk =>\n hstep k (Finset.mem_range.mp hk) s (Finset.mem_range.mp hs)\n _ = _ := by\n simp only [Finset.sum_add_distrib, Finset.mul_sum, Finset.sum_const,\n Finset.card_range, nsmul_eq_mul]\n push_cast\n ring\n\n have hmaster :\n -(∫ ω, (f (W K 0 ω) - f wstar) ∂μ) ≤\n -a * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) + (T : ℝ) * c := by\n calc\n _ ≤ ∫ ω, (f (W K Sout ω) - f (W K 0 ω)) ∂μ := hgapLower\n _ = ∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, Dlt k s ω ∂μ) := hDsumIntegral.symm\n _ ≤ -a * (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K,\n (∫ ω, X k s ω ∂μ)) + (K * Sout : ℕ) * c := hsumStep\n _ = -a * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) + (T : ℝ) * c := by\n rw [hXsumInt]\n rw [hT]\n have hprod :\n a * (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) ≤\n (∫ ω, (f (W K 0 ω) - f wstar) ∂μ) + (T : ℝ) * c := by\n linarith\n have hobj :\n (∫ ω, (∑ s ∈ Finset.range Sout,\n ∑ k ∈ Finset.range K, X k s ω) ∂μ) ≤\n ((∫ ω, (f (W K 0 ω) - f wstar) ∂μ) + (T : ℝ) * c) / a :=\n (le_div_iff₀ ha).2 (by simpa only [mul_comm] using hprod)\n\n change (1 / (T : ℝ)) *\n (∫ ω, (∑ s ∈ Finset.range Sout, ∑ k ∈ Finset.range K, X k s ω) ∂μ) ≤ _\n calc\n _ ≤ (1 / (T : ℝ)) *\n (((∫ ω, (f (W K 0 ω) - f wstar) ∂μ) + (T : ℝ) * c) / a) :=\n mul_le_mul_of_nonneg_left hobj (by positivity)\n _ = 4 * (bH : ℝ) ^ 2 * L * onesP\n / ((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) * (T : ℝ))\n * (∫ ω, (f (W K 0 ω) - f wstar) ∂μ)\n + 8 * σ2 * (bH : ℝ) * onesP\n / ((2 * (bH : ℝ) - θ * (bH : ℝ) - 1) * (b : ℝ) * θ) := by\n dsimp [a, c]\n field_simp [ne_of_gt hTR, ne_of_gt hL, ne_of_gt hbHR, ne_of_gt hbR,\n ne_of_gt hθ0, ne_of_gt hones, ne_of_gt hbH2]\n ring\n\nend ResearchLevel\n"} +{"id": "v3-bartlett02a", "source": "Research-level", "targets": [{"label": "Theorem 8", "decls": ["thm8"], "statement": "Theorem 8 Let $\\mathcal{L}:\\mathcal{Y}\\times\\mathcal{A}\\longrightarrow[0,1]$ be a loss function, and let $\\phi:\\mathcal{Y}\\times\\mathcal{A}\\longrightarrow[0,1]$ be a cost function that dominates it. Take $F$ to be a class of functions from $\\mathcal{X}$ into $\\mathcal{A}$, and suppose the pairs $(X_{i},Y_{i})_{i=1}^{n}$ are drawn independently from the probability measure $P$. Then for every integer $n$ and every $0 < \\delta < 1$, the following holds with probability no less than $1 - \\delta$ over samples of size $n$: for all $f$ in $F$,\n\n$$\n\\mathbf{E}\\mathcal{L}(Y,f(X))\\leq\\hat{\\mathbf{E}}_{n}\\phi(Y,f(X))+R_{n}(\\tilde{\\phi}\\circ F)+\\sqrt{\\frac{8\\ln(2/\\delta)}{n}},\n$$\n\nwith $\\tilde{\\phi}\\circ F=\\{(x,y)\\mapsto\\phi(y,f(x))-\\phi(y,0):f\\in F\\}$", "context_ids": ["v3-bartlett02a:ctx1", "v3-bartlett02a:ctx3", "v3-bartlett02a:ctx5", "v3-bartlett02a:ctx6", "v3-bartlett02a:ctx7"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}, {"label": "Theorem 5(b)", "decls": ["theorem5b_rademacher_bound"], "statement": "Theorem 5 Suppose $P$ is a probability distribution on $\\mathcal{X}\\times \\left\\{\\pm 1 \\right\\}$, $F$ is a collection of functions on $\\mathcal{X}$ taking values in $\\{\\pm 1 \\}$, and the training sample $(X_{i},Y_{i})_{i=1}^{n}$ is distributed according to $P^{n}$\n\n(b) With probability no less than $1 - \\delta$, the following inequality holds simultaneously for all $f$ in $F$:\n\n$$\nP(Y\\neq f(X))\\leq\\hat{P}_{n}(Y\\neq f(X))+\\frac{R_{n}(F)}{2}+\\sqrt{\\frac{\\ln(1/\\delta)}{2n}}.\n$$", "context_ids": ["v3-bartlett02a:ctx1", "v3-bartlett02a:ctx2", "v3-bartlett02a:ctx3", "v3-bartlett02a:ctx4", "v3-bartlett02a:ctx5", "v3-bartlett02a:ctx6", "v3-bartlett02a:ctx7", "v3-bartlett02a:ctx9"], "sibling_refs": ["Theorem 8"], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}, {"label": "Theorem 11 (second bound)", "decls": ["thm11_rademacher_concentration"], "statement": "Theorem 11 Suppose $F$ is a class of functions taking values in $[-1, 1]$. Then for every integer $n$,\n\n$$\nP\\left\\{\\Big|R_{n}(F)-\\hat{R}_{n}(F)\\Big|\\geq\\epsilon\\right\\}\\leq 2\\exp\\left(\\frac{-\\epsilon^{2}n}{8}\\right),\n$$", "context_ids": ["v3-bartlett02a:ctx3", "v3-bartlett02a:ctx6", "v3-bartlett02a:ctx7", "v3-bartlett02a:ctx8"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "### Proof of Theorem 8\n\nProof (of Theorem 8) Because $\\phi$ dominates $\\mathcal{L}$, every $f \\in F$ satisfies\n\n$$\n\\begin{array}{r c l}{\\mathbf{E}\\mathcal{L}(Y,f(X))}&{\\leq}&{\\mathbf{E}\\phi(Y,f(X))}\\\\ &{\\leq}&{\\hat{\\mathbf{E}}_{n}\\phi(Y,f(X))+\\displaystyle\\operatorname*{sup}_{h\\in\\phi\\circ F}\\left(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\right)}\\\\ &{=}&{\\hat{\\mathbf{E}}_{n}\\phi(Y,f(X))+\\displaystyle\\operatorname*{sup}_{h\\in\\tilde{\\phi}\\circ F}\\left(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\right)}\\\\ &{}&{+\\mathbf{E}\\phi(Y,0)-\\hat{\\mathbf{E}}_{n}\\phi(Y,0).}\\end{array}\n$$\n\nReplacing a single pair $(X_{i},Y_{i})$ alters the random variable $\\begin{array}{r}{\\operatorname*{sup}_{h\\in\\tilde{\\phi}\\circ F}\\left({\\bf E}h-\\hat{\\bf E}_{n}h\\right)}\\end{array}$ by at most $2 / n$. Hence, by McDiarmid's inequality, with probability no less than $1 - \\delta / 2$,\n\n$$\n\\operatorname*{sup}\\Big(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\Big)\\leq\\mathbf{E}\\operatorname*{sup}\\Big(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\Big)+\\sqrt{2\\ln(2/\\delta)/n}.\n$$\n\nArguing in the same way, and using $\\mathbf{E}\\hat{\\mathbf{E}}_{n}\\phi(Y,0)=\\mathbf{E}\\phi(Y,0)$, we get that with probability no less than $1 - \\delta$,\n\n$$\n\\mathbf{E}\\mathcal{L}(Y,f(X))\\leq\\hat{\\mathbf{E}}_{n}\\phi(Y,f(X))+\\mathbf{E}\\operatorname*{sup}_{h\\in\\tilde{\\phi}\\circ F}\\Big(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\Big)+\\sqrt{\\frac{8\\ln(2/\\delta)}{n}}.\n$$\n\nWhat is left is to bound the second term on the right by $R_{n}(\\tilde{\\phi}\\circ F)$. Let $(X_{1}^{\\prime},Y_{1}^{\\prime}),\\dots,(X_{n}^{\\prime},Y_{n}^{\\prime})$ be independent random variables, each distributed as $(X,Y)$. Then\n\n$$\n\\begin{array}{r c l}{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\left(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\right)}&{=}&{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\mathbf{E}\\left[\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}h(X_{i}^{\\prime},Y_{i}^{\\prime})-\\hat{\\mathbf{E}}_{n}h\\,\\middle|\\,(X_{i},Y_{i})\\right]}\\\\ &{\\leq}&{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\left(\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}h(X_{i}^{\\prime},Y_{i}^{\\prime})-\\hat{\\mathbf{E}}_{n}h\\right)}\\\\ &{=}&{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}\\sigma_{i}\\left(h(X_{i}^{\\prime},Y_{i}^{\\prime})-h(X_{i},Y_{i})\\right)}\\\\ &{\\leq}&{2\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}\\sigma_{i}h(X_{i},Y_{i})}\\\\ &{\\leq}&{R_{n}(\\tilde{\\phi}\\circ F).}\\end{array}\n$$\n\n### Proof of Theorem 5(b)\n\n## Appendix B. Proof of Theorem 5\n\nTake ${\\mathcal{L}}(Y,f(X))=\\mathbf{1}(Y\\neq f(X))$ and follow the proof of Theorem 8. Every $f \\in F$ satisfies\n\n$$\nP(Y\\neq f(X))=\\mathbf{E}{\\mathcal{L}}(Y,f(X))\\leq{\\hat{\\mathbf{E}}}_{n}{\\mathcal{L}}(Y,f(X))+\\operatorname*{sup}_{h\\in{\\mathcal{L}}\\circ F}\\left(\\mathbf{E}h-{\\hat{\\mathbf{E}}}_{n}h\\right)\n$$\n\nHere, replacing $(X_{i},Y_{i})$ alters the supremum by at most $1 / n$; McDiarmid's inequality therefore gives that, with probability no less than $1 - \\delta$, all $f \\in F$ satisfy\n\n$$\n\\mathbf{E}\\mathcal{L}(Y,f(X))\\leq\\hat{\\mathbf{E}}_{n}\\mathcal{L}(Y,f(X))+\\mathbf{E}\\operatorname*{sup}_{h\\in\\mathcal{L}\\circ F}\\left(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\right)+\\sqrt{\\frac{\\ln(1/\\delta)}{2 n}}.\n$$\n\nRepeating the argument from the proof of Theorem 8 yields\n\n$$\n\\begin{array}{r c l}{\\displaystyle\\mathbf{E}\\operatorname*{sup}_{h\\in\\mathcal{L}\\circ F}\\Big(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\Big)}&{\\leq}&{\\displaystyle\\mathbf{E}\\operatorname*{sup}_{h\\in\\mathcal{L}\\circ F}\\frac{2}{n}\\sum_{i=1}^{n}\\sigma_{i}h(X_{i},Y_{i})}\\\\ &{=}&{\\displaystyle\\mathbf{E}\\operatorname*{sup}_{f\\in F}\\frac{2}{n}\\sum_{i=1}^{n}\\sigma_{i}\\mathbf{1}(Y_{i}\\neq f(X_{i}))}\\\\ &{=}&{\\displaystyle\\mathbf{E}\\operatorname*{sup}_{f\\in F}\\frac{2}{n}\\sum_{i=1}^{n}\\sigma_{i}(1-Y_{i}f(X_{i}))/2}\\\\ &{=}&{\\displaystyle\\mathbf{E}\\operatorname*{sup}_{f\\in F}\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}f(X_{i})}\\\\ &{=}&{\\displaystyle\\frac{R_{n}(F)}{2},}\\end{array}\n$$\n\nin which we relied on $Y_{i},f(X_{i})\\in\\{\\pm 1\\}$ and on the fact that, conditionally on $Y_{i}$, the variable $\\sigma_{i}Y_{i}$ has the same distribution as $\\sigma_{i}$\n\n### Proof of Theorem 11 (second bound)\n\n(No proof of this result appears in the source.)", "context": [{"id": "v3-bartlett02a:ctx1", "name": "Setup: decision-theoretic learning setting (Section 1)", "statement": "The following section presents a bound of this type that holds in a broader, decision-theoretic framework. In that framework there are an input space $\\mathcal{X}$, an action space $\\mathcal{A}$ and an output space $\\mathcal{Y}$. The $n$ training examples $(X_{1},Y_{1}),\\dots,(X_{n},Y_{n})$ are drawn independently from a probability measure $P$ on $\\mathcal{X}\\times \\mathcal{Y}$. A loss function $\\mathcal{L}:\\mathcal{Y}\\times\\mathcal{A}\\longrightarrow[0,1]$ is given, where $\\mathcal{L}(y,a)$ measures the cost incurred by choosing action $a \\in{\\mathcal{A}}$ when the outcome turns out to be $y \\in \\mathcal{Y}$. Learning seeks a function $f$ from $\\mathcal{X}$ to ${\\mathcal{A}}$ whose expected loss $\\mathbf{E}{\\mathcal{L}}(Y,f(X))$ is as small as possible."}, {"id": "v3-bartlett02a:ctx2", "name": "Notation: empirical frequency hat P_n (Theorem 1)", "statement": "here VCdim(F) stands for the Vapnik-Chervonenkis dimension of $F$,\n\n$$\n{\\hat{P}}_{n}(S)={\\frac{1}{n}}\\sum_{i=1}^{n}\\mathbf{1}_{S}(X_{i},Y_{i}),\n$$\n\nand ${\\bf 1}_{S}$ denotes the indicator function of $S$."}, {"id": "v3-bartlett02a:ctx3", "name": "Definition 2 (maximum discrepancy, Rademacher and Gaussian complexities)", "statement": "Definition 2 Suppose $\\mu$ is a probability distribution on a set $\\mathcal{X}$, and $X_{1},\\ldots,X_{n}$ are independent samples drawn from $\\mu$. Let $F$ be a class of functions from $\\mathcal{X}$ to $\\mathbb{R}$. The maximum discrepancy of $F$ is the random variable\n\n$$\n\\hat{D}_{n}(F)=\\operatorname*{sup}_{f\\in F}\\left(\\frac{2}{n}\\sum_{i=1}^{n/2}f(X_{i})-\\frac{2}{n}\\sum_{i=n/2+1}^{n}f(X_{i})\\right).\n$$\n\nIts expectation, the expected maximum discrepancy of $F$, is written $D_{n}(F)=\\mathbf{E}\\hat{D}_{n}(F)$\n\nNext, let\n\n$$\n{\\hat{R}}_{n}(F)=\\mathbf{E}[\\operatorname*{sup}_{f\\in F}|{\\frac{2}{n}}\\sum_{i=1}^{n}\\sigma_{i}f(X_{i})| |X_{1},\\ldots,X_{n}]\\ ,\n$$\n\nwith $\\sigma_{1},\\ldots,\\sigma_{n}$ independent random variables, each uniform on $\\{\\pm 1 \\}$. The Rademacher complexity of $F$ is then $R_{n}(F)=\\mathbf{E}\\hat{R}_{n}(F)$. In the same way, let\n\n$$\n\\hat{G}_{n}(F)=\\mathbf{E}[\\operatorname*{sup}_{f\\in F}|{\\frac{2}{n}}\\sum_{i=1}^{n}g_{i}f(X_{i})| |X_{1},\\ldots,X_{n}]\\ ,\n$$\n\nwith $g_{1},\\ldots,g_{n}$ independent Gaussian $N(0,1)$ random variables. The Gaussian complexity of $F$ is $G_{n}(F)=\\mathbf{E}\\hat{G}_{n}(F)$"}, {"id": "v3-bartlett02a:ctx4", "name": "Remark: Theorem 5(b) is proved via the argument of Theorem 8", "statement": "Part (b) is proved by a small sharpening of the proof of a more general statement, Theorem 8 below; the argument is given in Appendix B."}, {"id": "v3-bartlett02a:ctx5", "name": "Notation: empirical average hat E_n h", "statement": "Given a training sample $(X_{1},Y_{1}),\\dots,(X_{n},Y_{n})$ and a function $h : \\mathcal{X}\\times \\mathcal{Y}\\longrightarrow \\mathbb{R}$, we use the notation\n\n$$\n\\hat{\\mathbf{E}}_{n}h(X,Y)=(1/n)\\sum_{i=1}^{n}h(X_{i},Y_{i}).\n$$"}, {"id": "v3-bartlett02a:ctx6", "name": "Notation: dominating cost function, phi o F, function-class operations (Section 2)", "statement": "First, some notation. For an independent sample $(X_{i},Y_{i})_{i=1}^{n}$ with the distribution of $(X,Y)$, $P_{n}$ is the empirical measure supported on the sample, and $\\mu_{n}$ is the empirical measure supported on $(X_{i})_{i=1}^{n}$. A function $\\phi : \\mathcal{Y}\\times \\mathcal{A}\\to \\mathbb{R}$ is said to dominate a loss function $\\mathcal{L}$ when $\\phi(y,a)\\geq{\\mathcal{L}}(y,a)$ holds for every $y \\in \\mathcal{Y}$ and every $a \\in{\\mathcal{A}}$. Given a class of functions $F$: conv $F$ denotes the set of convex combinations of members of $F$; $- F = \\{- f : f \\in F \\}$; absconv $F$ denotes the set of convex combinations of members of $F \\cup{- F}$; and $c F = \\{c f : f \\in F \\}$. When $\\phi$ is defined on the range of the functions in $F$, we put $\\phi \\circ F = \\{\\phi \\circ f | f \\in F \\}$. The characteristic function of a set $A$ is written ${\\bf 1}_{A}$ or $\\mathbf{1}(A)$. Lastly, $C$ and $c$ denote constants whose values may differ from one line to the next, or even inside a single line."}, {"id": "v3-bartlett02a:ctx7", "name": "Theorem 9 (McDiarmid's Inequality)", "statement": "The argument relies on McDiarmid's inequality (McDiarmid, 1989).\n\nTheorem 9 (McDiarmid's Inequality) Suppose $X_{1},...,X_{n}$ are independent random variables with values in a set $A$, and $f : A^{n}\\to \\mathbb{R}$ is such that\n\n$$\n\\operatorname*{sup}_{x_{1},\\ldots,x_{n},x_{i}^{\\prime}\\in A}\\left|f(x_{1},...,x_{n})-f(x_{1},...,x_{i-1},x_{i}^{\\prime},x_{i+1},... x_{n})\\right|\\leq c_{i}\n$$\n\nholds for each $1 \\leq i \\leq n$. Then every $t > 0$ satisfies\n\n$$\nP\\left\\{f(X_{1},...,X_{n})-{\\bf E}f(X_{1},...,X_{n})\\geq t\\right\\}\\leq e^{-2t^{2}/\\sum_{i=1}^{n}c_{i}^{2}}.\n$$"}, {"id": "v3-bartlett02a:ctx8", "name": "Remark: Theorem 11 follows from McDiarmid's inequality", "statement": "The next result is a consequence of McDiarmid's inequality. An analogous statement holds for the Gaussian complexity."}, {"id": "v3-bartlett02a:ctx9", "name": "From the proof of Theorem 8 (the argument this proof repeats)", "statement": "What is left is to bound the second term on the right by $R_{n}(\\tilde{\\phi}\\circ F)$. Let $(X_{1}^{\\prime},Y_{1}^{\\prime}),\\dots,(X_{n}^{\\prime},Y_{n}^{\\prime})$ be independent random variables, each distributed as $(X,Y)$. Then\n\n$$\n\\begin{array}{r c l}{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\left(\\mathbf{E}h-\\hat{\\mathbf{E}}_{n}h\\right)}&{=}&{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\mathbf{E}\\left[\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}h(X_{i}^{\\prime},Y_{i}^{\\prime})-\\hat{\\mathbf{E}}_{n}h\\,\\middle|\\,(X_{i},Y_{i})\\right]}\\\\ &{\\leq}&{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\left(\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}h(X_{i}^{\\prime},Y_{i}^{\\prime})-\\hat{\\mathbf{E}}_{n}h\\right)}\\\\ &{=}&{\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}\\sigma_{i}\\left(h(X_{i}^{\\prime},Y_{i}^{\\prime})-h(X_{i},Y_{i})\\right)}\\\\ &{\\leq}&{2\\mathbf{E}\\underset{h\\in\\tilde{\\phi}\\circ F}{\\operatorname*{sup}}\\frac{1}{n}\\displaystyle\\sum_{i=1}^{n}\\sigma_{i}h(X_{i},Y_{i})}\\\\ &{\\leq}&{R_{n}(\\tilde{\\phi}\\circ F).}\\end{array}\n$$"}], "lean": "import Mathlib\n\nnamespace ResearchLevel\n\nnoncomputable section\n\nuniverse u v w\n\nopen MeasureTheory ProbabilityTheory Real\n\ndef Signs (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n : ℕ} : Fintype (Signs n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\ndef paperEmpRad {ι : Type v} {𝒮 : Type w} (n : ℕ) (f : ι → 𝒮 → ℝ) (S : Fin n → 𝒮) : ℝ :=\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, ⨆ i, |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * f i (S k)|\n\ndef paperRad {Ω : Type u} {ι : Type v} {𝒮 : Type w} [MeasurableSpace Ω]\n (n : ℕ) (f : ι → 𝒮 → ℝ) (μ : Measure Ω) (X : Ω → 𝒮) : ℝ :=\n ∫ ω : Fin n → Ω, paperEmpRad n f (fun k => X (ω k)) ∂(Measure.pi (fun _ => μ))\n\ndef centeredClass {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*} {ι : Type v} [Zero 𝒜]\n (φ : 𝒱 → 𝒜 → ℝ) (F : ι → 𝒳 → 𝒜) : ι → (𝒳 × 𝒱) → ℝ :=\n fun i p => φ p.2 (F i p.1) - φ p.2 0\n\ndef expectedLoss {Ω : Type u} {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) (X : Ω → 𝒳) (Y : Ω → 𝒱) (L : 𝒱 → 𝒜 → ℝ) (f : 𝒳 → 𝒜) : ℝ :=\n ∫ ω, L (Y ω) (f (X ω)) ∂μ\n\ndef empiricalCost {Ω : Type u} {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*}\n (n : ℕ) (X : Ω → 𝒳) (Y : Ω → 𝒱) (L : 𝒱 → 𝒜 → ℝ) (f : 𝒳 → 𝒜)\n (ω : Fin n → Ω) : ℝ :=\n (n : ℝ)⁻¹ * ∑ k : Fin n, L (Y (ω k)) (f (X (ω k)))\n\ndef zeroOneLoss (y a : ℝ) : ℝ := by\n classical exact if y = a then 0 else 1\n\ntheorem thm8 {Ω : Type u} {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*} {ι : Type v}\n [MeasurableSpace Ω] [Zero 𝒜] [Nonempty ι] [Countable ι]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (X : Ω → 𝒳) (Y : Ω → 𝒱)\n (L φ : 𝒱 → 𝒜 → ℝ)\n (hL01 : ∀ y a, L y a ∈ Set.Icc (0 : ℝ) 1)\n (hφ01 : ∀ y a, φ y a ∈ Set.Icc (0 : ℝ) 1)\n (hdom : ∀ y a, L y a ≤ φ y a)\n (F : ι → 𝒳 → 𝒜)\n (hLmeas : ∀ i, Measurable (fun ω => L (Y ω) (F i (X ω))))\n (hφmeas : ∀ i, Measurable (fun ω => φ (Y ω) (F i (X ω))))\n (hφ0meas : Measurable (fun ω => φ (Y ω) 0))\n (n : ℕ)\n (hRadInt : Integrable\n (fun ω : Fin n → Ω =>\n paperEmpRad n (centeredClass φ F) (fun k => (X (ω k), Y (ω k))))\n (Measure.pi (fun _ => μ)))\n (hDevMeas : Measurable\n (fun ω : Fin n → Ω =>\n ⨆ i : ι, ((∫ ω' : Ω, centeredClass φ F i (X ω', Y ω') ∂μ)\n - ((n : ℝ)⁻¹ * ∑ k : Fin n, centeredClass φ F i (X (ω k), Y (ω k))))))\n (hn : 0 < n) (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1) :\n 1 - δ ≤\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω : Fin n → Ω |\n ∀ i, expectedLoss μ X Y L (F i) ≤\n empiricalCost n X Y φ (F i) ω\n + paperRad n (centeredClass φ F) μ (fun ω' => (X ω', Y ω'))\n + Real.sqrt (8 * Real.log (2 / δ) / n)} := by\n sorry\n\ntheorem theorem5b_rademacher_bound {Ω : Type u} {𝒳 : Type*} {ι : Type v}\n [MeasurableSpace Ω] [Nonempty ι] [Countable ι]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (X : Ω → 𝒳) (Y : Ω → ℝ)\n (hY : ∀ ω, Y ω ∈ ({-1, 1} : Set ℝ))\n (F : ι → 𝒳 → ℝ) (hF : ∀ i x, F i x ∈ ({-1, 1} : Set ℝ))\n (hLmeas : ∀ i, Measurable (fun ω => zeroOneLoss (Y ω) (F i (X ω))))\n (n : ℕ)\n (hRadInt : Integrable\n (fun ω : Fin n → Ω => paperEmpRad n F (fun k => X (ω k)))\n (Measure.pi (fun _ => μ)))\n (hn : 0 < n) (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hEvt : MeasurableSet\n {ω : Fin n → Ω |\n ∀ i, expectedLoss μ X Y zeroOneLoss (F i) ≤\n empiricalCost n X Y zeroOneLoss (F i) ω\n + paperRad n F μ X / 2\n + Real.sqrt (Real.log (1 / δ) / (2 * n))}) :\n 1 - δ ≤\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω : Fin n → Ω |\n ∀ i, expectedLoss μ X Y zeroOneLoss (F i) ≤\n empiricalCost n X Y zeroOneLoss (F i) ω\n + paperRad n F μ X / 2\n + Real.sqrt (Real.log (1 / δ) / (2 * n))} := by\n sorry\n\ntheorem thm11_rademacher_concentration {Ω : Type u} {𝒮 : Type w} {ι : Type v}\n [MeasurableSpace Ω] [Nonempty ι]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (X : Ω → 𝒮)\n (F : ι → 𝒮 → ℝ) (hF : ∀ i s, F i s ∈ Set.Icc (-1 : ℝ) 1)\n (n : ℕ) (hn : 0 < n)\n (hRadInt : Integrable\n (fun ω : Fin n → Ω => paperEmpRad n F (fun k => X (ω k)))\n (Measure.pi (fun _ => μ)))\n (hMcD : ∀ (g : (Fin n → Ω) → ℝ) (c : ℝ), 0 ≤ c →\n Integrable g (Measure.pi (fun _ => μ)) →\n (∀ (ω ω' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → ω k = ω' k) → |g ω - g ω'| ≤ c) →\n ∀ t : ℝ, 0 < t →\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω | g ω - ∫ ω', g ω' ∂(Measure.pi (fun _ => μ)) ≥ t}\n ≤ Real.exp (-2 * t ^ 2 / (n * c ^ 2)))\n (ε : ℝ) (hε : 0 < ε) :\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω : Fin n → Ω |\n |paperRad n F μ X - paperEmpRad n F (fun k => X (ω k))| ≥ ε}\n ≤ 2 * Real.exp (-(ε ^ 2 * n) / 8) := by\n sorry\n\nend\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnamespace ResearchLevel\n\nnoncomputable section\n\nuniverse u v w\n\nopen MeasureTheory ProbabilityTheory Real\n\ndef Signs (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n : ℕ} : Fintype (Signs n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\ndef paperEmpRad {ι : Type v} {𝒮 : Type w} (n : ℕ) (f : ι → 𝒮 → ℝ) (S : Fin n → 𝒮) : ℝ :=\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, ⨆ i, |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * f i (S k)|\n\ndef paperRad {Ω : Type u} {ι : Type v} {𝒮 : Type w} [MeasurableSpace Ω]\n (n : ℕ) (f : ι → 𝒮 → ℝ) (μ : Measure Ω) (X : Ω → 𝒮) : ℝ :=\n ∫ ω : Fin n → Ω, paperEmpRad n f (fun k => X (ω k)) ∂(Measure.pi (fun _ => μ))\n\ndef centeredClass {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*} {ι : Type v} [Zero 𝒜]\n (φ : 𝒱 → 𝒜 → ℝ) (F : ι → �� → 𝒜) : ι → (𝒳 × 𝒱) → ℝ :=\n fun i p => φ p.2 (F i p.1) - φ p.2 0\n\ndef expectedLoss {Ω : Type u} {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) (X : Ω → 𝒳) (Y : Ω → 𝒱) (L : 𝒱 → 𝒜 → ℝ) (f : 𝒳 → 𝒜) : ℝ :=\n ∫ ω, L (Y ω) (f (X ω)) ∂μ\n\ndef empiricalCost {Ω : Type u} {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*}\n (n : ℕ) (X : Ω → 𝒳) (Y : Ω → 𝒱) (L : 𝒱 → 𝒜 → ℝ) (f : 𝒳 → 𝒜)\n (ω : Fin n → Ω) : ℝ :=\n (n : ℝ)⁻¹ * ∑ k : Fin n, L (Y (ω k)) (f (X (ω k)))\n\ndef zeroOneLoss (y a : ℝ) : ℝ := by\n classical exact if y = a then 0 else 1\n\nprivate lemma bartlett_centered_mgf {Ω : Type*} [MeasurableSpace Ω] [Nonempty Ω]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (q : Ω → ℝ) (hqmeas : Measurable q) (hqint : Integrable q μ)\n (c : ℝ) (hc : 0 ≤ c) (hdiam : ∀ x y, |q x - q y| ≤ c)\n (t : ℝ) (ht : 0 < t) :\n ∫ x, Real.exp (t * (q x - ∫ y, q y ∂μ)) ∂μ ≤\n Real.exp (c ^ 2 * t ^ 2 / 8) := by\n let a : ℝ := sInf (Set.range q)\n have hrange : (Set.range q).Nonempty := Set.range_nonempty q\n have hbdd : BddBelow (Set.range q) := by\n let x0 : Ω := Classical.choice inferInstance\n refine ⟨q x0 - c, ?_⟩\n rintro _ ⟨x, rfl⟩\n have hx := (abs_le.mp (hdiam x0 x)).2\n linarith\n have hqa (x : Ω) : a ≤ q x := by\n exact csInf_le hbdd ⟨x, rfl⟩\n have haq (x : Ω) : q x ≤ a + c := by\n have hx : q x - c ≤ a := by\n apply le_csInf hrange\n rintro _ ⟨y, rfl⟩\n have hxy := (abs_le.mp (hdiam x y)).2\n linarith\n linarith\n have hmem : ∀ x, q x - ∫ y, q y ∂μ ∈\n Set.Icc (a - ∫ y, q y ∂μ) (a + c - ∫ y, q y ∂μ) := by\n intro x\n exact ⟨sub_le_sub_right (hqa x) _, sub_le_sub_right (haq x) _⟩\n have hzero : ∫ x, (q x - ∫ y, q y ∂μ) ∂μ = 0 := by\n rw [integral_sub hqint (integrable_const _)]\n simp\n have h := ProbabilityTheory.mgf_le_of_mem_Icc_of_integral_eq_zero\n (μ := μ) (X := fun x => q x - ∫ y, q y ∂μ)\n (hqmeas.sub_const _).aemeasurable (ae_of_all _ hmem) hzero ht\n calc\n _ ≤ Real.exp ((c / 2) ^ 2 * t ^ 2 / 2) := by\n simpa [ProbabilityTheory.mgf, abs_of_nonneg hc] using h\n _ = Real.exp (c ^ 2 * t ^ 2 / 8) := by congr 1 <;> ring\n\nprivate theorem bartlett_mgf_pi {Ω : Type*} [MeasurableSpace Ω] [Nonempty Ω]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (n : ℕ) (g : (Fin n → Ω) → ℝ) (hgmeas : Measurable g)\n (hgint : Integrable g (Measure.pi (fun _ => μ)))\n (c : ℝ) (hc : 0 ≤ c)\n (hdiff : ∀ (x y : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → x k = y k) → |g x - g y| ≤ c)\n (t : ℝ) (ht : 0 < t) :\n Integrable (fun x => Real.exp (t * (g x -\n ∫ y, g y ∂(Measure.pi (fun _ => μ))))) (Measure.pi (fun _ => μ)) ∧\n (∫ x, Real.exp (t * (g x - ∫ y, g y ∂(Measure.pi (fun _ => μ))))\n ∂(Measure.pi (fun _ => μ))) ≤\n Real.exp ((n : ℝ) * c ^ 2 * t ^ 2 / 8) := by\n induction n with\n | zero =>\n let a : ℝ := g default\n have hgconst : g = fun _ => a := by\n funext x\n exact congrArg g (Subsingleton.elim _ _)\n rw [hgconst]\n simp\n | succ n ih =>\n let ν : Measure (Fin n → Ω) := Measure.pi (fun _ => μ)\n let e : (Fin (n + 1) → Ω) ≃ᵐ Ω × (Fin n → Ω) :=\n MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => Ω) 0\n let G : Ω × (Fin n → Ω) → ℝ := fun p => g (Fin.cons p.1 p.2)\n let h : (Fin n → Ω) → ℝ := fun z => ∫ x, G (x, z) ∂μ\n have he : MeasurePreserving e (Measure.pi (fun _ : Fin (n + 1) => μ)) (μ.prod ν) := by\n simpa [e, ν] using\n (measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => μ) 0)\n have heinv : ⇑e.symm = fun p => Fin.cons p.1 p.2 := by\n funext p\n ext k\n refine Fin.cases ?_ (fun l => ?_) k <;>\n simp [e, MeasurableEquiv.piFinSuccAbove_symm_apply]\n have hGmeas : Measurable G := by\n rw [show G = g ∘ e.symm by funext p; simp [G, heinv]]\n exact hgmeas.comp e.symm.measurable\n have hGint : Integrable G (μ.prod ν) := by\n rw [show G = g ∘ e.symm by funext p; simp [G, heinv]]\n exact (he.symm.integrable_comp hgmeas.aestronglyMeasurable).2 hgint\n have hhmeas : Measurable h := by\n exact hGmeas.stronglyMeasurable.integral_prod_left'.measurable\n have hhint : Integrable h ν := by\n exact hGint.integral_prod_right\n have hGcoord0 (x y : Ω) (z : Fin n → Ω) : |G (x, z) - G (y, z)| ≤ c := by\n apply hdiff _ _ 0\n intro k hk\n cases k using Fin.cases with\n | zero => exact (hk rfl).elim\n | succ l => simp [G]\n have hGsecint (z : Fin n → Ω) : Integrable (fun x => G (x, z)) μ := by\n let x0 : Ω := Classical.choice inferInstance\n apply Integrable.of_mem_Icc (G (x0, z) - c) (G (x0, z) + c)\n · exact (hGmeas.comp (by fun_prop)).aemeasurable\n · apply ae_of_all\n intro x\n have hx := abs_le.mp (hGcoord0 x x0 z)\n constructor <;> linarith\n have hGtail (x : Ω) (z z' : Fin n → Ω) (j : Fin n)\n (hzz' : ∀ k, k ≠ j → z k = z' k) : |G (x, z) - G (x, z')| ≤ c := by\n apply hdiff _ _ (Fin.succ j)\n intro k hk\n cases k using Fin.cases with\n | zero => simp [G]\n | succ l =>\n simp only [G, Fin.cons_succ]\n apply hzz' l\n intro hlj\n exact hk (congrArg Fin.succ hlj)\n have hhdiff : ∀ (z z' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → z k = z' k) → |h z - h z'| ≤ c := by\n intro z z' j hzz'\n rw [show h z - h z' = ∫ x, (G (x, z) - G (x, z')) ∂μ by\n exact (integral_sub (hGsecint z) (hGsecint z')).symm]\n have hb := norm_integral_le_of_norm_le_const\n (μ := μ) (f := fun x => G (x, z) - G (x, z'))\n (ae_of_all _ fun x => by simpa [Real.norm_eq_abs] using hGtail x z z' j hzz')\n simpa [Real.norm_eq_abs] using hb\n have hi := ih h hhmeas hhint hhdiff\n have hcenter (x : Ω) (z : Fin n → Ω) : |G (x, z) - h z| ≤ c := by\n rw [show G (x, z) - h z = ∫ y, (G (x, z) - G (y, z)) ∂μ by\n rw [integral_sub (integrable_const _) (hGsecint z)]\n simp [h]]\n have hb := norm_integral_le_of_norm_le_const\n (μ := μ) (f := fun y => G (x, z) - G (y, z))\n (ae_of_all _ fun y => by\n simpa [Real.norm_eq_abs] using hGcoord0 x y z)\n simpa [Real.norm_eq_abs] using hb\n let A : Ω × (Fin n → Ω) → ℝ :=\n fun p => Real.exp (t * (G p - h p.2))\n let B : (Fin n → Ω) → ℝ :=\n fun z => Real.exp (t * (h z - ∫ z', h z' ∂ν))\n let C : Ω × (Fin n → Ω) → ℝ := fun p => A p * B p.2\n have hAmeas : Measurable A := by\n dsimp [A]\n fun_prop\n have hBmeas : Measurable B := by\n dsimp [B]\n fun_prop\n have hBint : Integrable B ν := by\n simpa [B, ν] using hi.1\n have hAbound (p : Ω × (Fin n → Ω)) :\n A p ≤ Real.exp (|t| * c) := by\n apply Real.exp_le_exp.mpr\n calc\n t * (G p - h p.2) ≤ |t * (G p - h p.2)| := le_abs_self _\n _ = |t| * |G p - h p.2| := abs_mul _ _\n _ ≤ |t| * c := by gcongr; exact hcenter p.1 p.2\n have hCmeas : Measurable C := by\n dsimp [C]\n fun_prop\n have hCint : Integrable C (μ.prod ν) := by\n apply Integrable.mono ((hBint.comp_snd μ).const_mul (Real.exp (|t| * c)))\n hCmeas.aestronglyMeasurable\n apply ae_of_all\n intro p\n simp only [C, Real.norm_eq_abs, abs_mul, abs_exp]\n rw [abs_of_nonneg (Real.exp_nonneg _)]\n exact mul_le_mul_of_nonneg_right (hAbound p) (abs_nonneg _)\n have hAsection (z : Fin n → Ω) :\n ∫ x, A (x, z) ∂μ ≤ Real.exp (c ^ 2 * t ^ 2 / 8) := by\n simpa [A, h] using\n bartlett_centered_mgf μ (fun x => G (x, z))\n (hGmeas.comp (by fun_prop)) (hGsecint z) c hc\n (fun x y => hGcoord0 x y z) t ht\n have hmean_prod : ∫ p, G p ∂(μ.prod ν) = ∫ z, h z ∂ν := by\n simpa [h] using integral_prod_symm G hGint\n have hmean_orig :\n (∫ x, g x ∂(Measure.pi (fun _ : Fin (n + 1) => μ))) =\n ∫ p, G p ∂(μ.prod ν) := by\n have hm := he.symm.integral_comp' g\n simpa [G, heinv] using hm.symm\n have hcomp :\n (fun x => Real.exp (t * (g x -\n ∫ y, g y ∂(Measure.pi (fun _ : Fin (n + 1) => μ))))) ∘ e.symm = C := by\n funext p\n rw [hmean_orig, hmean_prod]\n simp only [Function.comp_apply, heinv]\n change Real.exp (t * (G p - ∫ z, h z ∂ν)) = A p * B p.2\n rw [← Real.exp_add]\n congr 1\n ring\n have hresult_int : Integrable (fun x => Real.exp (t * (g x -\n ∫ y, g y ∂(Measure.pi (fun _ : Fin (n + 1) => μ)))))\n (Measure.pi (fun _ : Fin (n + 1) => μ)) := by\n apply (he.symm.integrable_comp (by fun_prop)).mp\n rw [hcomp]\n exact hCint\n refine ⟨hresult_int, ?_⟩\n have horig_eq :\n (∫ x, Real.exp (t * (g x -\n ∫ y, g y ∂(Measure.pi (fun _ : Fin (n + 1) => μ))))\n ∂(Measure.pi (fun _ : Fin (n + 1) => μ))) =\n ∫ p, C p ∂(μ.prod ν) := by\n rw [← hcomp]\n exact (he.symm.integral_comp' _).symm\n rw [horig_eq]\n calc\n (∫ p, C p ∂(μ.prod ν)) = ∫ z, ∫ x, C (x, z) ∂μ ∂ν :=\n integral_prod_symm C hCint\n _ ≤ ∫ z, Real.exp (c ^ 2 * t ^ 2 / 8) * B z ∂ν := by\n apply integral_mono hCint.integral_prod_right\n (hBint.const_mul (Real.exp (c ^ 2 * t ^ 2 / 8)))\n intro z\n change (∫ x, C (x, z) ∂μ) ≤ Real.exp (c ^ 2 * t ^ 2 / 8) * B z\n rw [show (∫ x, C (x, z) ∂μ) = (∫ x, A (x, z) ∂μ) * B z by\n simp only [C]\n exact integral_mul_const (μ := μ) (B z) (fun x : Ω => A (x, z))]\n exact mul_le_mul_of_nonneg_right (hAsection z) (Real.exp_nonneg _)\n _ = Real.exp (c ^ 2 * t ^ 2 / 8) * ∫ z, B z ∂ν :=\n integral_const_mul _ _\n _ ≤ Real.exp (c ^ 2 * t ^ 2 / 8) *\n Real.exp ((n : ℝ) * c ^ 2 * t ^ 2 / 8) := by\n gcongr\n simpa [B, ν] using hi.2\n _ = Real.exp (((n + 1 : ℕ) : ℝ) * c ^ 2 * t ^ 2 / 8) := by\n rw [← Real.exp_add]\n congr 1\n push_cast\n ring\n\nprivate theorem bartlett_mcdiarmid_pi {Ω : Type*} [MeasurableSpace Ω] [Nonempty Ω]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (n : ℕ) (hn : 0 < n) (g : (Fin n → Ω) → ℝ) (hgmeas : Measurable g)\n (hgint : Integrable g (Measure.pi (fun _ => μ)))\n (c : ℝ) (hc : 0 < c)\n (hdiff : ∀ (x y : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → x k = y k) → |g x - g y| ≤ c)\n (ε : ℝ) (hε : 0 < ε) :\n (Measure.pi (fun _ : Fin n => μ)).real\n {x | g x - ∫ y, g y ∂(Measure.pi (fun _ => μ)) ≥ ε} ≤\n Real.exp (-2 * ε ^ 2 / ((n : ℝ) * c ^ 2)) := by\n let s : ℝ := 4 * ε / ((n : ℝ) * c ^ 2)\n have hs : 0 < s := by positivity\n have hm := bartlett_mgf_pi μ n g hgmeas hgint c hc.le hdiff s hs\n calc\n (Measure.pi (fun _ : Fin n => μ)).real\n {x | g x - ∫ y, g y ∂(Measure.pi (fun _ => μ)) ≥ ε} ≤\n Real.exp (-s * ε) * ProbabilityTheory.mgf\n (fun x => g x - ∫ y, g y ∂(Measure.pi (fun _ => μ)))\n (Measure.pi (fun _ => μ)) s := by\n exact ProbabilityTheory.measure_ge_le_exp_mul_mgf ε hs.le hm.1\n _ ≤ Real.exp (-s * ε) *\n Real.exp ((n : ℝ) * c ^ 2 * s ^ 2 / 8) := by\n rw [ProbabilityTheory.mgf]\n gcongr\n exact hm.2\n _ = Real.exp (-2 * ε ^ 2 / ((n : ℝ) * c ^ 2)) := by\n rw [← Real.exp_add]\n congr 1\n dsimp [s]\n have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn\n field_simp\n ring\n\nprivate lemma bartlett_iSup_lipschitz {ι : Type*} [Nonempty ι]\n (a b : ι → ℝ) (ha : BddAbove (Set.range a)) (hb : BddAbove (Set.range b))\n (c : ℝ) (h : ∀ i, |a i - b i| ≤ c) :\n |(⨆ i, a i) - ⨆ i, b i| ≤ c := by\n have hab : (⨆ i, a i) ≤ (⨆ i, b i) + c := by\n refine ciSup_le fun i => ?_\n have hi := (abs_le.mp (h i)).2\n have hib := le_ciSup hb i\n linarith\n have hba : (⨆ i, b i) ≤ (⨆ i, a i) + c := by\n refine ciSup_le fun i => ?_\n have hi := (abs_le.mp (h i)).1\n have hia := le_ciSup ha i\n linarith\n rw [abs_le]\n constructor <;> linarith\n\nprivate lemma bartlett_sign_abs {n : ℕ} (σ : Signs n) (k : Fin n) :\n |(σ k : ℝ)| = 1 := by\n have hk := (σ k).property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hk\n rcases hk with hk | hk <;> simp [hk]\n\nprivate lemma bartlett_inner_bddAbove {𝒮 : Type*} {ι : Type*}\n (n : ℕ) (F : ι → 𝒮 → ℝ) (hF : ∀ i s, F i s ∈ Set.Icc (-1 : ℝ) 1)\n (S : Fin n → 𝒮) (σ : Signs n) :\n BddAbove (Set.range fun i =>\n |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S k)|) := by\n classical\n refine ⟨|2 / (n : ℝ)| * (n : ℝ), ?_⟩\n rintro _ ⟨i, rfl⟩\n change |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S k)| ≤\n |2 / (n : ℝ)| * (n : ℝ)\n rw [abs_mul]\n apply mul_le_mul_of_nonneg_left _ (abs_nonneg _)\n calc\n |∑ k : Fin n, (σ k : ℝ) * F i (S k)| ≤\n ∑ k : Fin n, |(σ k : ℝ) * F i (S k)| :=\n Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ _k : Fin n, (1 : ℝ) := by\n gcongr with k\n rw [abs_mul, bartlett_sign_abs, one_mul]\n exact abs_le.mpr (hF i (S k))\n _ = (n : ℝ) := by simp\n\nprivate def bartlett_signSwap {Ω : Type*} [MeasurableSpace Ω]\n (s : ({-1, 1} : Finset ℤ)) : Ω × Ω ≃ᵐ Ω × Ω :=\n if (s : ℤ) = 1 then MeasurableEquiv.refl _ else MeasurableEquiv.prodComm\n\nprivate lemma bartlett_signSwap_diff {Ω : Type*} [MeasurableSpace Ω]\n (s : ({-1, 1} : Finset ℤ)) (p : Ω × Ω) (f : Ω → ℝ) :\n f (bartlett_signSwap s p).2 - f (bartlett_signSwap s p).1 =\n (s : ℝ) * (f p.2 - f p.1) := by\n have hs := s.property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hs\n rcases hs with hs | hs\n · simpa [bartlett_signSwap, hs, MeasurableEquiv.prodComm,\n Equiv.prodComm] using\n (show f p.1 - f p.2 = (-1 : ℝ) * (f p.2 - f p.1) by ring)\n · simp [bartlett_signSwap, hs]\n\nprivate lemma bartlett_signSwap_measurePreserving {Ω : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) [SigmaFinite μ] (s : ({-1, 1} : Finset ℤ)) :\n MeasurePreserving (bartlett_signSwap s) (μ.prod μ) (μ.prod μ) := by\n have hs := s.property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hs\n rcases hs with hs | hs\n · simpa [bartlett_signSwap, hs] using\n (Measure.measurePreserving_swap (μ := μ) (ν := μ))\n · simpa [bartlett_signSwap, hs] using MeasurePreserving.id (μ.prod μ)\n\nprivate def bartlett_signSwapPi {Ω : Type*} [MeasurableSpace Ω] {n : ℕ}\n (σ : Signs n) : (Fin n → Ω × Ω) ≃ᵐ (Fin n → Ω × Ω) :=\n MeasurableEquiv.piCongrRight (fun k => bartlett_signSwap (σ k))\n\nprivate lemma bartlett_signSwapPi_measurePreserving {Ω : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) [SigmaFinite μ] {n : ℕ} (σ : Signs n) :\n MeasurePreserving (bartlett_signSwapPi σ)\n (Measure.pi (fun _ : Fin n => μ.prod μ))\n (Measure.pi (fun _ : Fin n => μ.prod μ)) := by\n let e : (Fin n → Ω × Ω) ≃ᵐ (Fin n → Ω × Ω) :=\n bartlett_signSwapPi (Ω := Ω) σ\n letI (k : Fin n) : SigmaFinite\n ((μ.prod μ).map (bartlett_signSwap (σ k))) :=\n (bartlett_signSwap (σ k)).sigmaFinite_map\n refine ⟨e.measurable, ?_⟩\n change (Measure.pi (fun _ : Fin n => μ.prod μ)).map\n (fun z k => bartlett_signSwap (σ k) (z k)) = _\n rw [Measure.pi_map_pi (fun k =>\n (bartlett_signSwap (σ k)).measurable.aemeasurable)]\n congr 1\n funext k\n exact (bartlett_signSwap_measurePreserving μ (σ k)).map_eq\n\nprivate lemma bartlett_signSwapPi_sum_diff {Ω : Type*} [MeasurableSpace Ω]\n {n : ℕ} (σ : Signs n) (z : Fin n → Ω × Ω) (f : Ω → ℝ) :\n (∑ k : Fin n, f ((bartlett_signSwapPi σ z) k).2) -\n (∑ k : Fin n, f ((bartlett_signSwapPi σ z) k).1) =\n ∑ k : Fin n, (σ k : ℝ) * (f (z k).2 - f (z k).1) := by\n rw [← Finset.sum_sub_distrib]\n apply Finset.sum_congr rfl\n intro k _\n change f (bartlett_signSwap (σ k) (z k)).2 -\n f (bartlett_signSwap (σ k) (z k)).1 = _\n exact bartlett_signSwap_diff (σ k) (z k) f\n\nprivate lemma bartlett_integral_mem_Icc {Ω : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) [IsProbabilityMeasure μ] (f : Ω → ℝ)\n (hfmeas : Measurable f) (hf : ∀ x, f x ∈ Set.Icc (-1 : ℝ) 1) :\n (∫ x, f x ∂μ) ∈ Set.Icc (-1 : ℝ) 1 := by\n have hfint : Integrable f μ :=\n Integrable.of_mem_Icc (-1) 1 hfmeas.aemeasurable (ae_of_all _ hf)\n constructor\n · simpa using integral_mono (μ := μ) (integrable_const (-1 : ℝ)) hfint\n (fun x => (hf x).1)\n · simpa using integral_mono (μ := μ) hfint (integrable_const (1 : ℝ))\n (fun x => (hf x).2)\n\nprivate lemma bartlett_empirical_mem_Icc {Ω : Type*} (n : ℕ) (hn : 0 < n)\n (f : Ω → ℝ) (hf : ∀ x, f x ∈ Set.Icc (-1 : ℝ) 1)\n (S : Fin n → Ω) :\n (n : ℝ)⁻¹ * ∑ k : Fin n, f (S k) ∈ Set.Icc (-1 : ℝ) 1 := by\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n have hinv : 0 ≤ (n : ℝ)⁻¹ := (inv_pos.mpr hnR).le\n constructor\n · calc\n (-1 : ℝ) = (n : ℝ)⁻¹ * ∑ _k : Fin n, (-1 : ℝ) := by\n simp [ne_of_gt hnR]\n _ ≤ (n : ℝ)⁻¹ * ∑ k : Fin n, f (S k) := by\n gcongr with k\n exact (hf (S k)).1\n · calc\n (n : ℝ)⁻¹ * ∑ k : Fin n, f (S k) ≤\n (n : ℝ)⁻¹ * ∑ _k : Fin n, (1 : ℝ) := by\n gcongr with k\n exact (hf (S k)).2\n _ = 1 := by simp [ne_of_gt hnR]\n\nprivate lemma bartlett_empirical_change_le {Ω : Type*} (n : ℕ) (hn : 0 < n)\n (f : Ω → ℝ) (hf : ∀ x, f x ∈ Set.Icc (-1 : ℝ) 1)\n (S S' : Fin n → Ω) (j : Fin n) (hSS' : ∀ k, k ≠ j → S k = S' k) :\n |(n : ℝ)⁻¹ * ∑ k : Fin n, f (S k) -\n (n : ℝ)⁻¹ * ∑ k : Fin n, f (S' k)| ≤ 2 / (n : ℝ) := by\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n have hsum :\n (∑ k : Fin n, f (S k)) - ∑ k : Fin n, f (S' k) =\n f (S j) - f (S' j) := by\n rw [← Finset.sum_sub_distrib]\n apply Finset.sum_eq_single j\n · intro k _ hkj\n rw [hSS' k hkj]\n simp\n · simp\n rw [← mul_sub, hsum, abs_mul, abs_of_nonneg (inv_nonneg.mpr hnR.le)]\n have hd : |f (S j) - f (S' j)| ≤ 2 := by\n rw [abs_le]\n constructor <;> linarith [(hf (S j)).1, (hf (S j)).2,\n (hf (S' j)).1, (hf (S' j)).2]\n calc\n (n : ℝ)⁻¹ * |f (S j) - f (S' j)| ≤ (n : ℝ)⁻¹ * 2 := by gcongr\n _ = 2 / (n : ℝ) := by ring\n\nprivate lemma bartlett_empirical01_change_le {Ω : Type*} (n : ℕ) (hn : 0 < n)\n (f : Ω → ℝ) (hf : ∀ x, f x ∈ Set.Icc (0 : ℝ) 1)\n (S S' : Fin n → Ω) (j : Fin n) (hSS' : ∀ k, k ≠ j → S k = S' k) :\n |(n : ℝ)⁻¹ * ∑ k : Fin n, f (S k) -\n (n : ℝ)⁻¹ * ∑ k : Fin n, f (S' k)| ≤ 1 / (n : ℝ) := by\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n have hsum :\n (∑ k : Fin n, f (S k)) - ∑ k : Fin n, f (S' k) =\n f (S j) - f (S' j) := by\n rw [← Finset.sum_sub_distrib]\n apply Finset.sum_eq_single j\n · intro k _ hkj\n rw [hSS' k hkj]\n simp\n · simp\n rw [← mul_sub, hsum, abs_mul, abs_of_nonneg (inv_nonneg.mpr hnR.le)]\n have hd : |f (S j) - f (S' j)| ≤ 1 := by\n rw [abs_le]\n constructor <;> linarith [(hf (S j)).1, (hf (S j)).2,\n (hf (S' j)).1, (hf (S' j)).2]\n simpa [div_eq_mul_inv] using\n mul_le_mul_of_nonneg_left hd (inv_nonneg.mpr hnR.le)\n\nprivate lemma bartlett_iSup_sub_mem_Icc {ι : Type*} [Nonempty ι]\n (a b : ι → ℝ) (ha : ∀ i, a i ∈ Set.Icc (-1 : ℝ) 1)\n (hb : ∀ i, b i ∈ Set.Icc (-1 : ℝ) 1) :\n (⨆ i, a i - b i) ∈ Set.Icc (-2 : ℝ) 2 := by\n have hBdd : BddAbove (Set.range fun i => a i - b i) := by\n refine ⟨2, ?_⟩\n rintro _ ⟨i, rfl⟩\n linarith [(ha i).2, (hb i).1]\n constructor\n · let i : ι := Classical.choice inferInstance\n have hi := le_ciSup hBdd i\n dsimp [i] at hi\n linarith [(ha i).1, (hb i).2]\n · refine ciSup_le fun i => ?_\n linarith [(ha i).2, (hb i).1]\n\nprivate theorem bartlett_symmetrization_affine\n {Ω : Type*} {ι : Type*} [MeasurableSpace Ω] [Nonempty ι] [Countable ι]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (n : ℕ) (hn : 0 < n) (f q : ι → Ω → ℝ)\n (hfmeas : ∀ i, Measurable (f i))\n (hf : ∀ i x, f i x ∈ Set.Icc (-1 : ℝ) 1)\n (hq : ∀ i x, q i x ∈ Set.Icc (-1 : ℝ) 1)\n (a : ℝ) (haff : ∀ i x y, f i x - f i y = a * (q i x - q i y))\n (hDevMeas : Measurable\n (fun S : Fin n → Ω =>\n ⨆ i, (∫ x, f i x ∂μ) - (n : ℝ)⁻¹ * ∑ k : Fin n, f i (S k)))\n (hRadInt : Integrable (fun S : Fin n → Ω => paperEmpRad n q S)\n (Measure.pi (fun _ => μ))) :\n (∫ S : Fin n → Ω,\n (⨆ i, (∫ x, f i x ∂μ) - (n : ℝ)⁻¹ * ∑ k : Fin n, f i (S k))\n ∂(Measure.pi (fun _ => μ))) ≤\n |a| * paperRad n q μ id := by\n classical\n let ν : Measure (Fin n → Ω) := Measure.pi (fun _ => μ)\n let emp : ι → (Fin n → Ω) → ℝ :=\n fun i S => (n : ℝ)⁻¹ * ∑ k : Fin n, f i (S k)\n let dev : (Fin n → Ω) → ℝ :=\n fun S => ⨆ i, (∫ x, f i x ∂μ) - emp i S\n let D : ((Fin n → Ω) × (Fin n → Ω)) → ℝ :=\n fun p => ⨆ i, emp i p.2 - emp i p.1\n have hfint (i : ι) : Integrable (f i) μ :=\n Integrable.of_mem_Icc (-1) 1 (hfmeas i).aemeasurable\n (ae_of_all _ fun x => hf i x)\n have hmean (i : ι) : (∫ x, f i x ∂μ) ∈ Set.Icc (-1 : ℝ) 1 :=\n bartlett_integral_mem_Icc μ (f i) (hfmeas i) (hf i)\n have hemp (i : ι) (S : Fin n → Ω) : emp i S ∈ Set.Icc (-1 : ℝ) 1 := by\n exact bartlett_empirical_mem_Icc n hn (f i) (hf i) S\n have hdevmem (S : Fin n → Ω) : dev S ∈ Set.Icc (-2 : ℝ) 2 := by\n exact bartlett_iSup_sub_mem_Icc\n (fun i => ∫ x, f i x ∂μ) (fun i => emp i S) hmean (fun i => hemp i S)\n have hdevmeas : Measurable dev := by\n simpa [dev, emp] using hDevMeas\n have hdevint : Integrable dev ν := by\n exact Integrable.of_mem_Icc (-2) 2 hdevmeas.aemeasurable\n (ae_of_all _ hdevmem)\n have hDmeas : Measurable D := by\n dsimp [D, emp]\n apply Measurable.iSup\n intro i\n fun_prop\n have hDmem (p : (Fin n → Ω) × (Fin n → Ω)) :\n D p ∈ Set.Icc (-2 : ℝ) 2 := by\n exact bartlett_iSup_sub_mem_Icc (fun i => emp i p.2) (fun i => emp i p.1)\n (fun i => hemp i p.2) (fun i => hemp i p.1)\n have hDint : Integrable D (ν.prod ν) := by\n exact Integrable.of_mem_Icc (-2) 2 hDmeas.aemeasurable\n (ae_of_all _ hDmem)\n have hempint (i : ι) : Integrable (emp i) ν := by\n exact Integrable.of_mem_Icc (-1) 1\n ((((Finset.univ : Finset (Fin n)).measurable_sum fun k _ =>\n (hfmeas i).comp (measurable_pi_apply k)).const_mul _).aemeasurable)\n (ae_of_all _ fun S => hemp i S)\n have hmean_emp (i : ι) : (∫ x, f i x ∂μ) = ∫ S, emp i S ∂ν := by\n symm\n calc\n (∫ S, emp i S ∂ν) =\n (n : ℝ)⁻¹ * ∫ S, ∑ k : Fin n, f i (S k) ∂ν := by\n exact integral_const_mul _ _\n _ = (n : ℝ)⁻¹ * ∑ k : Fin n, ∫ S, f i (S k) ∂ν := by\n rw [integral_finset_sum]\n intro k _\n simpa [ν] using integrable_comp_eval (μ := fun _ : Fin n => μ) (i := k) (hfint i)\n _ = (n : ℝ)⁻¹ * ∑ _k : Fin n, ∫ x, f i x ∂μ := by\n congr 1\n apply Finset.sum_congr rfl\n intro k _\n simpa [ν] using integral_comp_eval\n (μ := fun _ : Fin n => μ) (i := k) (hfmeas i).aestronglyMeasurable\n _ = ∫ x, f i x ∂μ := by\n have hnR : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn\n simp [hnR]\n have hDBdd (p : (Fin n → Ω) × (Fin n → Ω)) :\n BddAbove (Set.range fun i => emp i p.2 - emp i p.1) := by\n refine ⟨2, ?_⟩\n rintro _ ⟨i, rfl⟩\n linarith [(hemp i p.2).2, (hemp i p.1).1]\n have hDsection (S : Fin n → Ω) : Integrable (fun T => D (S, T)) ν := by\n exact Integrable.of_mem_Icc (-2) 2\n (hDmeas.comp (by fun_prop)).aemeasurable\n (ae_of_all _ fun T => hDmem (S, T))\n have hpoint_ghost (S : Fin n → Ω) :\n dev S ≤ ∫ T, D (S, T) ∂ν := by\n refine ciSup_le fun i => ?_\n have hcompint : Integrable (fun T => emp i T - emp i S) ν :=\n (hempint i).sub (integrable_const _)\n have hcomp : (∫ x, f i x ∂μ) - emp i S =\n ∫ T, (emp i T - emp i S) ∂ν := by\n rw [integral_sub (hempint i) (integrable_const _), ← hmean_emp]\n simp\n rw [hcomp]\n apply integral_mono hcompint (hDsection S)\n intro T\n exact le_ciSup (hDBdd (S, T)) i\n have hghost : (∫ S, dev S ∂ν) ≤ ∫ p, D p ∂(ν.prod ν) := by\n rw [integral_prod D hDint]\n exact integral_mono hdevint hDint.integral_prod_left hpoint_ghost\n change (∫ S, dev S ∂ν) ≤ |a| * paperRad n q μ id\n apply hghost.trans\n let ρ : Measure (Fin n → Ω × Ω) := Measure.pi (fun _ => μ.prod μ)\n let ep : (Fin n → Ω × Ω) ≃ᵐ ((Fin n → Ω) × (Fin n → Ω)) :=\n MeasurableEquiv.arrowProdEquivProdArrow Ω Ω (Fin n)\n let H : (Fin n → Ω × Ω) → ℝ := fun z =>\n ⨆ i, emp i (fun k => (z k).2) - emp i (fun k => (z k).1)\n have hep : MeasurePreserving ep ρ (ν.prod ν) := by\n simpa [ep, ρ, ν] using\n (measurePreserving_arrowProdEquivProdArrow Ω Ω (Fin n)\n (fun _ => μ) (fun _ => μ))\n have hcompHD : D ∘ ep = H := by\n funext z\n rfl\n have hHint : Integrable H ρ := by\n rw [← hcompHD]\n exact (hep.integrable_comp hDmeas.aestronglyMeasurable).2 hDint\n have hD_eq_H : (∫ p, D p ∂(ν.prod ν)) = ∫ z, H z ∂ρ := by\n rw [← hcompHD]\n exact (hep.integral_comp' D).symm\n rw [hD_eq_H]\n have hsign (z : Fin n → Ω × Ω) (σ : Signs n) :\n H (bartlett_signSwapPi σ z) ≤\n |a| / 2 *\n ((⨆ i, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q i (z k).2|) +\n (⨆ i, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q i (z k).1|)) := by\n dsimp [H]\n refine ciSup_le fun i => ?_\n let U : ℝ := (2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q i (z k).2\n let V : ℝ := (2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q i (z k).1\n have hsum :\n (∑ k : Fin n, (σ k : ℝ) *\n (a * (q i (z k).2 - q i (z k).1))) =\n a * ((∑ k : Fin n, (σ k : ℝ) * q i (z k).2) -\n ∑ k : Fin n, (σ k : ℝ) * q i (z k).1) := by\n rw [mul_sub]\n simp_rw [mul_sub, show ∀ k : Fin n,\n (σ k : ℝ) * (a * q i (z k).2) =\n a * ((σ k : ℝ) * q i (z k).2) by intro k; ring,\n show ∀ k : Fin n,\n (σ k : ℝ) * (a * q i (z k).1) =\n a * ((σ k : ℝ) * q i (z k).1) by intro k; ring]\n rw [Finset.sum_sub_distrib, Finset.mul_sum, Finset.mul_sum]\n have hterm :\n emp i (fun k => ((bartlett_signSwapPi σ z) k).2) -\n emp i (fun k => ((bartlett_signSwapPi σ z) k).1) =\n (a / 2) * (U - V) := by\n dsimp [emp]\n rw [← mul_sub, bartlett_signSwapPi_sum_diff]\n have hreplace :\n (∑ k : Fin n, (σ k : ℝ) *\n (f i (z k).2 - f i (z k).1)) =\n ∑ k : Fin n, (σ k : ℝ) *\n (a * (q i (z k).2 - q i (z k).1)) := by\n apply Finset.sum_congr rfl\n intro k _\n rw [haff]\n rw [hreplace, hsum]\n dsimp [U, V]\n ring\n rw [hterm]\n have hU : |U| ≤\n ⨆ j, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q j (z k).2| := by\n exact le_ciSup\n (bartlett_inner_bddAbove n q hq (fun k => (z k).2) σ) i\n have hV : |V| ≤\n ⨆ j, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q j (z k).1| := by\n exact le_ciSup\n (bartlett_inner_bddAbove n q hq (fun k => (z k).1) σ) i\n calc\n (a / 2) * (U - V) ≤ |(a / 2) * (U - V)| := le_abs_self _\n _ = |a| / 2 * |U - V| := by rw [abs_mul, abs_div]; norm_num\n _ ≤ |a| / 2 * (|U| + |V|) := by\n gcongr\n exact abs_sub U V\n _ ≤ |a| / 2 *\n ((⨆ j, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q j (z k).2|) +\n (⨆ j, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q j (z k).1|)) := by\n gcongr\n letI : Nonempty (Signs n) :=\n ⟨fun _ => ⟨1, by simp [Signs]⟩⟩\n have hmpos : 0 < (Fintype.card (Signs n) : ℝ) := by\n exact_mod_cast Fintype.card_pos\n have hminv : 0 ≤ (Fintype.card (Signs n) : ℝ)⁻¹ :=\n (inv_pos.mpr hmpos).le\n have hHswap_int (σ : Signs n) :\n Integrable (fun z => H (bartlett_signSwapPi σ z)) ρ := by\n have heσ := bartlett_signSwapPi_measurePreserving μ σ\n have hc : (H ∘ bartlett_signSwapPi σ) =\n fun z => H (bartlett_signSwapPi σ z) := rfl\n rw [← hc]\n exact (heσ.integrable_comp hHint.aestronglyMeasurable).2 hHint\n have hHswap_eq (σ : Signs n) :\n (∫ z, H (bartlett_signSwapPi σ z) ∂ρ) = ∫ z, H z ∂ρ := by\n have heσ := bartlett_signSwapPi_measurePreserving μ σ\n simpa using heσ.integral_comp' H\n let Avg : (Fin n → Ω × Ω) → ℝ := fun z =>\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, H (bartlett_signSwapPi σ z)\n have hAvgInt : Integrable Avg ρ := by\n dsimp [Avg]\n exact (integrable_finset_sum Finset.univ fun σ _ => hHswap_int σ).const_mul _\n have hH_eq_Avg : (∫ z, H z ∂ρ) = ∫ z, Avg z ∂ρ := by\n calc\n (∫ z, H z ∂ρ) = (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ _σ : Signs n, ∫ z, H z ∂ρ := by\n simp [ne_of_gt hmpos]\n _ = (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, ∫ z, H (bartlett_signSwapPi σ z) ∂ρ := by\n congr 1\n apply Finset.sum_congr rfl\n intro σ _\n exact (hHswap_eq σ).symm\n _ = ∫ z, Avg z ∂ρ := by\n symm\n dsimp [Avg]\n rw [integral_const_mul, integral_finset_sum]\n intro σ _\n exact hHswap_int σ\n let R : (Fin n → Ω × Ω) → ℝ := fun z =>\n |a| / 2 *\n (paperEmpRad n q (fun k => (z k).2) +\n paperEmpRad n q (fun k => (z k).1))\n have hAvg_le_R (z : Fin n → Ω × Ω) : Avg z ≤ R z := by\n let Ay : Signs n → ℝ := fun σ =>\n ⨆ i, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q i (z k).2|\n let Ax : Signs n → ℝ := fun σ =>\n ⨆ i, |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * q i (z k).1|\n change (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, H (bartlett_signSwapPi σ z) ≤\n |a| / 2 *\n ((Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, Ay σ +\n (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, Ax σ)\n calc\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, H (bartlett_signSwapPi σ z) ≤\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, (|a| / 2 * (Ay σ + Ax σ)) := by\n gcongr with σ\n simpa [Ay, Ax] using hsign z σ\n _ = |a| / 2 *\n ((Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, Ay σ +\n (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, Ax σ) := by\n simp_rw [mul_add]\n rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum]\n ring\n let rad : (Fin n → Ω) → ℝ := fun S => paperEmpRad n q S\n let Rp : ((Fin n → Ω) × (Fin n → Ω)) → ℝ := fun p =>\n |a| / 2 * (rad p.2 + rad p.1)\n have hradint : Integrable rad ν := by\n simpa [rad, ν] using hRadInt\n have hRpint : Integrable Rp (ν.prod ν) := by\n exact ((hradint.comp_snd ν).add (hradint.comp_fst ν)).const_mul _\n have hRcomp : Rp ∘ ep = R := by\n funext z\n rfl\n have hRint : Integrable R ρ := by\n rw [← hRcomp]\n exact (hep.integrable_comp hRpint.aestronglyMeasurable).2 hRpint\n have hsnd : (∫ p, rad p.2 ∂(ν.prod ν)) = ∫ S, rad S ∂ν := by\n rw [integral_prod_symm _ (hradint.comp_snd ν)]\n simp\n have hfst : (∫ p, rad p.1 ∂(ν.prod ν)) = ∫ S, rad S ∂ν := by\n rw [integral_prod _ (hradint.comp_fst ν)]\n simp\n have hRp_integral : (∫ p, Rp p ∂(ν.prod ν)) =\n |a| * ∫ S, rad S ∂ν := by\n dsimp [Rp]\n rw [integral_const_mul,\n integral_add (hradint.comp_snd ν) (hradint.comp_fst ν), hsnd, hfst]\n ring\n have hR_integral : (∫ z, R z ∂ρ) = |a| * ∫ S, rad S ∂ν := by\n rw [← hRcomp]\n change (∫ z, Rp (ep z) ∂ρ) = _\n rw [hep.integral_comp' Rp, hRp_integral]\n calc\n (∫ z, H z ∂ρ) = ∫ z, Avg z ∂ρ := hH_eq_Avg\n _ ≤ ∫ z, R z ∂ρ := integral_mono hAvgInt hRint hAvg_le_R\n _ = |a| * ∫ S, rad S ∂ν := hR_integral\n _ = |a| * paperRad n q μ id := by rfl\n\ntheorem thm8 {Ω : Type u} {𝒳 : Type*} {𝒱 : Type*} {𝒜 : Type*} {ι : Type v}\n [MeasurableSpace Ω] [Zero 𝒜] [Nonempty ι] [Countable ι]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (X : Ω → 𝒳) (Y : Ω → 𝒱)\n (L φ : 𝒱 → 𝒜 → ℝ)\n (hL01 : ∀ y a, L y a ∈ Set.Icc (0 : ℝ) 1)\n (hφ01 : ∀ y a, φ y a ∈ Set.Icc (0 : ℝ) 1)\n (hdom : ∀ y a, L y a ≤ φ y a)\n (F : ι → 𝒳 → 𝒜)\n (hLmeas : ∀ i, Measurable (fun ω => L (Y ω) (F i (X ω))))\n (hφmeas : ∀ i, Measurable (fun ω => φ (Y ω) (F i (X ω))))\n (hφ0meas : Measurable (fun ω => φ (Y ω) 0))\n (n : ℕ)\n (hRadInt : Integrable\n (fun ω : Fin n → Ω =>\n paperEmpRad n (centeredClass φ F) (fun k => (X (ω k), Y (ω k))))\n (Measure.pi (fun _ => μ)))\n (hDevMeas : Measurable\n (fun ω : Fin n → Ω =>\n ⨆ i : ι, ((∫ ω' : Ω, centeredClass φ F i (X ω', Y ω') ∂μ)\n - ((n : ℝ)⁻¹ * ∑ k : Fin n, centeredClass φ F i (X (ω k), Y (ω k))))))\n (hn : 0 < n) (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1) :\n 1 - δ ≤\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω : Fin n → Ω |\n ∀ i, expectedLoss μ X Y L (F i) ≤\n empiricalCost n X Y φ (F i) ω\n + paperRad n (centeredClass φ F) μ (fun ω' => (X ω', Y ω'))\n + Real.sqrt (8 * Real.log (2 / δ) / n)} := by\n classical\n letI : Nonempty Ω := Measure.nonempty_of_neZero μ\n let ν : Measure (Fin n → Ω) := Measure.pi (fun _ => μ)\n let f : ι → Ω → ℝ := fun i ω =>\n centeredClass φ F i (X ω, Y ω)\n let f0 : Ω → ℝ := fun ω => φ (Y ω) 0\n let emp : ι → (Fin n → Ω) → ℝ := fun i S =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, f i (S k)\n let emp0 : (Fin n → Ω) → ℝ := fun S =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, f0 (S k)\n let g : (Fin n → Ω) → ℝ := fun S =>\n ⨆ i, (∫ x, f i x ∂μ) - emp i S\n let b : (Fin n → Ω) → ℝ := fun S => (∫ x, f0 x ∂μ) - emp0 S\n let R : ℝ := paperRad n (centeredClass φ F) μ\n (fun ω => (X ω, Y ω))\n have hfmeas (i : ι) : Measurable (f i) := by\n exact (hφmeas i).sub hφ0meas\n have hf (i : ι) (ω : Ω) : f i ω ∈ Set.Icc (-1 : ℝ) 1 := by\n dsimp [f, centeredClass]\n rcases hφ01 (Y ω) (F i (X ω)) with ⟨hlo, hhi⟩\n rcases hφ01 (Y ω) 0 with ⟨h0lo, h0hi⟩\n constructor <;> linarith\n have hf0 (ω : Ω) : f0 ω ∈ Set.Icc (0 : ℝ) 1 := hφ01 _ _\n have hf0meas : Measurable f0 := by simpa [f0] using hφ0meas\n have hsymm : (∫ S, g S ∂ν) ≤ R := by\n have h := bartlett_symmetrization_affine μ n hn f f hfmeas hf hf 1\n (by intro i x y; ring)\n (by simpa [g, emp, f] using hDevMeas)\n (by simpa [ν, f] using hRadInt)\n simpa [g, emp, ν, R, f, Function.id_def] using h\n have hmean (i : ι) : (∫ x, f i x ∂μ) ∈ Set.Icc (-1 : ℝ) 1 :=\n bartlett_integral_mem_Icc μ (f i) (hfmeas i) (hf i)\n have hemp (i : ι) (S : Fin n → Ω) : emp i S ∈ Set.Icc (-1 : ℝ) 1 :=\n bartlett_empirical_mem_Icc n hn (f i) (hf i) S\n have hgmem (S : Fin n → Ω) : g S ∈ Set.Icc (-2 : ℝ) 2 := by\n exact bartlett_iSup_sub_mem_Icc\n (fun i => ∫ x, f i x ∂μ) (fun i => emp i S) hmean (fun i => hemp i S)\n have hgmeas : Measurable g := by\n simpa [g, emp, f] using hDevMeas\n have hgint : Integrable g ν :=\n Integrable.of_mem_Icc (-2) 2 hgmeas.aemeasurable (ae_of_all _ hgmem)\n have hgBdd (S : Fin n → Ω) :\n BddAbove (Set.range fun i => (∫ x, f i x ∂μ) - emp i S) := by\n refine ⟨2, ?_⟩\n rintro _ ⟨i, rfl⟩\n linarith [(hmean i).2, (hemp i S).1]\n have hgchange : ∀ (S S' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → S k = S' k) → |g S - g S'| ≤ 2 / (n : ℝ) := by\n intro S S' j hSS'\n apply bartlett_iSup_lipschitz\n (fun i => (∫ x, f i x ∂μ) - emp i S)\n (fun i => (∫ x, f i x ∂μ) - emp i S')\n (hgBdd S) (hgBdd S') (2 / (n : ℝ))\n intro i\n rw [show ((∫ x, f i x ∂μ) - emp i S) -\n ((∫ x, f i x ∂μ) - emp i S') = -(emp i S - emp i S') by ring,\n abs_neg]\n exact bartlett_empirical_change_le n hn (f i) (hf i) S S' j hSS'\n have hf0int : Integrable f0 μ :=\n Integrable.of_mem_Icc 0 1 hf0meas.aemeasurable (ae_of_all _ hf0)\n have hmean0 : (∫ x, f0 x ∂μ) ∈ Set.Icc (0 : ℝ) 1 := by\n constructor\n · simpa using integral_mono (μ := μ) (integrable_const (0 : ℝ)) hf0int\n (fun x => (hf0 x).1)\n · simpa using integral_mono (μ := μ) hf0int (integrable_const (1 : ℝ))\n (fun x => (hf0 x).2)\n have hemp0 (S : Fin n → Ω) : emp0 S ∈ Set.Icc (0 : ℝ) 1 := by\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n have hinv : 0 ≤ (n : ℝ)⁻¹ := (inv_pos.mpr hnR).le\n constructor\n · exact mul_nonneg hinv (Finset.sum_nonneg fun k _ => (hf0 (S k)).1)\n · calc\n emp0 S ≤ (n : ℝ)⁻¹ * ∑ _k : Fin n, (1 : ℝ) := by\n dsimp [emp0]\n gcongr with k\n exact (hf0 (S k)).2\n _ = 1 := by simp [ne_of_gt hnR]\n have hbmeas : Measurable b := by\n dsimp [b, emp0]\n exact measurable_const.sub\n (((Finset.univ : Finset (Fin n)).measurable_sum fun k _ =>\n hf0meas.comp (measurable_pi_apply k)).const_mul _)\n have hbmem (S : Fin n → Ω) : b S ∈ Set.Icc (-1 : ℝ) 1 := by\n dsimp [b]\n constructor <;> linarith [hmean0.1, hmean0.2, (hemp0 S).1, (hemp0 S).2]\n have hbint : Integrable b ν :=\n Integrable.of_mem_Icc (-1) 1 hbmeas.aemeasurable (ae_of_all _ hbmem)\n have hbchange : ∀ (S S' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → S k = S' k) → |b S - b S'| ≤ 1 / (n : ℝ) := by\n intro S S' j hSS'\n rw [show b S - b S' = -(emp0 S - emp0 S') by simp [b], abs_neg]\n exact bartlett_empirical01_change_le n hn f0 hf0 S S' j hSS'\n let ℓ : ℝ := Real.log (2 / δ)\n let ε : ℝ := Real.sqrt (2 * ℓ / n)\n let T : ℝ := Real.sqrt (8 * ℓ / n)\n have hratio : 1 < (2 / δ : ℝ) := by\n have : δ < 2 := lt_trans hδ1 (by norm_num)\n rw [lt_div_iff₀ hδ0]\n simpa using this\n have hℓ : 0 < ℓ := Real.log_pos hratio\n have hε : 0 < ε := Real.sqrt_pos.2 (by positivity)\n have hεsq : ε ^ 2 = 2 * ℓ / n := Real.sq_sqrt (by positivity)\n have hTsq : T ^ 2 = 8 * ℓ / n := Real.sq_sqrt (by positivity)\n have hT : T = 2 * ε := by\n have hT0 : 0 ≤ T := Real.sqrt_nonneg _\n have hε0 : 0 ≤ ε := Real.sqrt_nonneg _\n have hsquares : T ^ 2 = 4 * ε ^ 2 := by\n calc\n T ^ 2 = 8 * ℓ / n := hTsq\n _ = 4 * (2 * ℓ / n) := by ring\n _ = 4 * ε ^ 2 := by rw [hεsq]\n nlinarith\n have htailg : ν.real {S | g S - ∫ T, g T ∂ν ��� ε} ≤ δ / 2 := by\n have hc : 0 < 2 / (n : ℝ) := by positivity\n have hmc := bartlett_mcdiarmid_pi μ n hn g hgmeas hgint\n (2 / (n : ℝ)) hc hgchange ε hε\n have hexp : -2 * ε ^ 2 / ((n : ℝ) * (2 / (n : ℝ)) ^ 2) = -ℓ := by\n rw [hεsq]\n have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn\n field_simp\n rw [hexp] at hmc\n calc\n _ ≤ Real.exp (-ℓ) := hmc\n _ = δ / 2 := by\n rw [Real.exp_neg]\n dsimp [ℓ]\n rw [Real.exp_log (by positivity : 0 < (2 / δ : ℝ))]\n field_simp\n have htailb : ν.real {S | b S - ∫ T, b T ∂ν ≥ ε} ≤ δ / 2 := by\n have hc : 0 < 1 / (n : ℝ) := by positivity\n have hmc := bartlett_mcdiarmid_pi μ n hn b hbmeas hbint\n (1 / (n : ℝ)) hc hbchange ε hε\n have hexp : -2 * ε ^ 2 / ((n : ℝ) * (1 / (n : ℝ)) ^ 2) = -4 * ℓ := by\n rw [hεsq]\n have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn\n field_simp\n ring\n rw [hexp] at hmc\n calc\n _ ≤ Real.exp (-4 * ℓ) := hmc\n _ ≤ Real.exp (-ℓ) := Real.exp_le_exp.mpr (by linarith)\n _ = δ / 2 := by\n rw [Real.exp_neg]\n dsimp [ℓ]\n rw [Real.exp_log (by positivity : 0 < (2 / δ : ℝ))]\n field_simp\n let A : Set (Fin n → Ω) := {S | g S - ∫ T, g T ∂ν ≥ ε}\n let B : Set (Fin n → Ω) := {S | b S - ∫ T, b T ∂ν ≥ ε}\n have hABmeas : MeasurableSet (A ∪ B) := by\n apply (measurableSet_Ici.preimage (hgmeas.sub_const _)).union\n (measurableSet_Ici.preimage (hbmeas.sub_const _))\n have hbad : ν.real (A ∪ B) ≤ δ := by\n calc\n ν.real (A ∪ B) ≤ ν.real A + ν.real B := measureReal_union_le _ _\n _ ≤ δ / 2 + δ / 2 := add_le_add (by simpa [A] using htailg)\n (by simpa [B] using htailb)\n _ = δ := by ring\n have hcomp : 1 - δ ≤ ν.real (A ∪ B)ᶜ := by\n rw [measureReal_compl hABmeas, probReal_univ]\n linarith\n apply hcomp.trans\n apply measureReal_mono ?_ (measure_ne_top ν _)\n intro S hS\n rw [Set.mem_compl_iff, Set.mem_union] at hS\n push_neg at hS\n rcases hS with ⟨hSg, hSb⟩\n intro i\n have hgi : (∫ x, f i x ∂μ) - emp i S ≤ g S :=\n le_ciSup (hgBdd S) i\n have hSg' : g S - (∫ T, g T ∂ν) < ε := by\n simpa [A, not_le] using hSg\n have hgdev : g S < (∫ T, g T ∂ν) + ε := by linarith\n have hbmean : (∫ T, b T ∂ν) = 0 := by\n have hemp0int : Integrable emp0 ν := by\n exact Integrable.of_mem_Icc 0 1\n ((((Finset.univ : Finset (Fin n)).measurable_sum fun k _ =>\n hf0meas.comp (measurable_pi_apply k)).const_mul _).aemeasurable)\n (ae_of_all _ hemp0)\n have hmean_emp0 : (∫ x, f0 x ∂μ) = ∫ S, emp0 S ∂ν := by\n symm\n calc\n (∫ S, emp0 S ∂ν) =\n (n : ℝ)⁻¹ * ∫ S, ∑ k : Fin n, f0 (S k) ∂ν := integral_const_mul _ _\n _ = (n : ℝ)⁻¹ * ∑ k : Fin n, ∫ S, f0 (S k) ∂ν := by\n rw [integral_finset_sum]\n intro k _\n simpa [ν] using integrable_comp_eval\n (μ := fun _ : Fin n => μ) (i := k) hf0int\n _ = (n : ℝ)⁻¹ * ∑ _k : Fin n, ∫ x, f0 x ∂μ := by\n congr 1\n apply Finset.sum_congr rfl\n intro k _\n simpa [ν] using integral_comp_eval\n (μ := fun _ : Fin n => μ) (i := k) hf0meas.aestronglyMeasurable\n _ = ∫ x, f0 x ∂μ := by\n have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn\n simp [hn0]\n rw [show b = fun S => (∫ x, f0 x ∂μ) - emp0 S by rfl,\n integral_sub (integrable_const _) hemp0int, ← hmean_emp0]\n simp\n have hSb' : b S - (∫ T, b T ∂ν) < ε := by\n simpa [B, not_le] using hSb\n have hbdev : b S < ε := by rw [hbmean] at hSb'; simpa using hSb'\n change (∫ x, f0 x ∂μ) - emp0 S < ε at hbdev\n have hEL : expectedLoss μ X Y L (F i) ≤ ∫ x, φ (Y x) (F i (X x)) ∂μ := by\n apply integral_mono\n · exact Integrable.of_mem_Icc 0 1 (hLmeas i).aemeasurable\n (ae_of_all _ fun x => hL01 _ _)\n · exact Integrable.of_mem_Icc 0 1 (hφmeas i).aemeasurable\n (ae_of_all _ fun x => hφ01 _ _)\n · exact fun x => hdom _ _\n have hcenter_int : (∫ x, φ (Y x) (F i (X x)) ∂μ) =\n (∫ x, f i x ∂μ) + ∫ x, f0 x ∂μ := by\n have hcint : Integrable (f i) μ :=\n Integrable.of_mem_Icc (-1) 1 (hfmeas i).aemeasurable (ae_of_all _ fun x => hf i x)\n rw [show (fun x => φ (Y x) (F i (X x))) = fun x => f i x + f0 x by\n funext x; simp [f, f0, centeredClass]]\n exact integral_add hcint hf0int\n have hemp_decomp : empiricalCost n X Y φ (F i) S = emp i S + emp0 S := by\n dsimp [empiricalCost, emp, emp0, f, f0, centeredClass]\n rw [← mul_add, ← Finset.sum_add_distrib]\n congr 1\n apply Finset.sum_congr rfl\n intro k _\n ring\n have hRmean : (∫ T, g T ∂ν) ≤ R := hsymm\n dsimp only [expectedLoss] at hEL\n rw [hcenter_int] at hEL\n rw [hemp_decomp]\n change (∫ ω, L (Y ω) (F i (X ω)) ∂μ) ≤ _\n change _ ≤ _ + R + Real.sqrt (8 * Real.log (2 / δ) / n)\n change _ ≤ _ + R + T\n rw [hT]\n linarith\n\nprivate lemma bartlett_sign_mul_mem (x y : ({-1, 1} : Finset ℤ)) :\n (x : ℤ) * (y : ℤ) ∈ ({-1, 1} : Finset ℤ) := by\n have hx := x.property\n have hy := y.property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hx hy ⊢\n rcases hx with hx | hx <;> rcases hy with hy | hy <;> simp [hx, hy]\n\nprivate lemma bartlett_sign_sq (x : ({-1, 1} : Finset ℤ)) :\n (x : ℤ) * (x : ℤ) = 1 := by\n have hx := x.property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hx\n rcases hx with hx | hx <;> simp [hx]\n\nprivate def bartlett_signMul {n : ℕ} (τ σ : Signs n) : Signs n :=\n fun k => ⟨(τ k : ℤ) * (σ k : ℤ), bartlett_sign_mul_mem (τ k) (σ k)⟩\n\nprivate def bartlett_signMulEquiv {n : ℕ} (τ : Signs n) : Signs n ≃ Signs n where\n toFun := bartlett_signMul τ\n invFun := bartlett_signMul τ\n left_inv σ := by\n funext k\n apply Subtype.ext\n change (τ k : ℤ) * ((τ k : ℤ) * (σ k : ℤ)) = (σ k : ℤ)\n rw [← mul_assoc, bartlett_sign_sq, one_mul]\n right_inv σ := by\n funext k\n apply Subtype.ext\n change (τ k : ℤ) * ((τ k : ℤ) * (σ k : ℤ)) = (σ k : ℤ)\n rw [← mul_assoc, bartlett_sign_sq, one_mul]\n\nprivate def bartlett_realSigns {n : ℕ} (y : Fin n → ℝ)\n (hy : ∀ k, y k ∈ ({-1, 1} : Set ℝ)) : Signs n :=\n fun k => if h : y k = -1 then ⟨-1, by simp⟩ else ⟨1, by simp⟩\n\nprivate lemma bartlett_realSigns_coe {n : ℕ} (y : Fin n → ℝ)\n (hy : ∀ k, y k ∈ ({-1, 1} : Set ℝ)) (k : Fin n) :\n ((bartlett_realSigns y hy k : ℤ) : ℝ) = y k := by\n have hk := hy k\n simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hk\n rcases hk with hk | hk\n · simp [bartlett_realSigns, hk]\n · norm_num [bartlett_realSigns, hk]\n\nprivate lemma paperEmpRad_mul_labels {𝒳 : Type*} {ι : Type*} [Nonempty ι]\n (n : ℕ) (F : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) (y : Fin n → ℝ)\n (hy : ∀ k, y k ∈ ({-1, 1} : Set ℝ)) :\n paperEmpRad n (fun i (p : 𝒳 × ℝ) => p.2 * F i p.1)\n (fun k => (S k, y k)) = paperEmpRad n F S := by\n classical\n let τ : Signs n := bartlett_realSigns y hy\n let e : Signs n ≃ Signs n := bartlett_signMulEquiv τ\n unfold paperEmpRad\n congr 1\n calc\n (∑ σ : Signs n, ⨆ i,\n |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * (y k * F i (S k))|) =\n ∑ σ : Signs n, ⨆ i,\n |(2 / (n : ℝ)) *\n ∑ k : Fin n, ((e σ) k : ℝ) * F i (S k)| := by\n apply Finset.sum_congr rfl\n intro σ _\n congr 1\n funext i\n congr 2\n apply Finset.sum_congr rfl\n intro k _\n dsimp [e, bartlett_signMulEquiv, bartlett_signMul, τ]\n rw [Int.cast_mul, bartlett_realSigns_coe y hy k]\n ring\n _ = ∑ σ : Signs n, ⨆ i,\n |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * F i (S k)| :=\n e.sum_comp (fun σ : Signs n => ⨆ i,\n |(2 / (n : ℝ)) *\n ∑ k : Fin n, (σ k : ℝ) * F i (S k)|)\n\nprivate lemma bartlett_zeroOne_eq (y a : ℝ)\n (hy : y ∈ ({-1, 1} : Set ℝ)) (ha : a ∈ ({-1, 1} : Set ℝ)) :\n zeroOneLoss y a = (1 - y * a) / 2 := by\n simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hy ha\n rcases hy with hy | hy <;> rcases ha with ha | ha <;>\n norm_num [zeroOneLoss, hy, ha]\n\ntheorem theorem5b_rademacher_bound {Ω : Type u} {𝒳 : Type*} {ι : Type v}\n [MeasurableSpace Ω] [Nonempty ι] [Countable ι]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (X : Ω → 𝒳) (Y : Ω → ℝ)\n (hY : ∀ ω, Y ω ∈ ({-1, 1} : Set ℝ))\n (F : ι → 𝒳 → ℝ) (hF : ∀ i x, F i x ∈ ({-1, 1} : Set ℝ))\n (hLmeas : ∀ i, Measurable (fun ω => zeroOneLoss (Y ω) (F i (X ω))))\n (n : ℕ)\n (hRadInt : Integrable\n (fun ω : Fin n → Ω => paperEmpRad n F (fun k => X (ω k)))\n (Measure.pi (fun _ => μ)))\n (hn : 0 < n) (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hEvt : MeasurableSet\n {ω : Fin n → Ω |\n ∀ i, expectedLoss μ X Y zeroOneLoss (F i) ≤\n empiricalCost n X Y zeroOneLoss (F i) ω\n + paperRad n F μ X / 2\n + Real.sqrt (Real.log (1 / δ) / (2 * n))}) :\n 1 - δ ≤\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω : Fin n → Ω |\n ∀ i, expectedLoss μ X Y zeroOneLoss (F i) ≤\n empiricalCost n X Y zeroOneLoss (F i) ω\n + paperRad n F μ X / 2\n + Real.sqrt (Real.log (1 / δ) / (2 * n))} := by\n classical\n letI : Nonempty Ω := Measure.nonempty_of_neZero μ\n let ν : Measure (Fin n → Ω) := Measure.pi (fun _ => μ)\n let f : ι → Ω → ℝ := fun i ω => zeroOneLoss (Y ω) (F i (X ω))\n let q : ι → Ω → ℝ := fun i ω => Y ω * F i (X ω)\n let emp : ι → (Fin n → Ω) → ℝ := fun i S =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, f i (S k)\n let g : (Fin n → Ω) → ℝ := fun S =>\n ⨆ i, (∫ x, f i x ∂μ) - emp i S\n let R : ℝ := paperRad n F μ X\n have hfmeas (i : ι) : Measurable (f i) := by simpa [f] using hLmeas i\n have hf01 (i : ι) (ω : Ω) : f i ω ∈ Set.Icc (0 : ℝ) 1 := by\n dsimp [f, zeroOneLoss]\n split <;> simp\n have hf (i : ι) (ω : Ω) : f i ω ∈ Set.Icc (-1 : ℝ) 1 := by\n rcases hf01 i ω with ⟨hlo, hhi⟩\n constructor <;> linarith\n have hq (i : ι) (ω : Ω) : q i ω ∈ Set.Icc (-1 : ℝ) 1 := by\n have hy := hY ω\n have ha := hF i (X ω)\n simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hy ha\n rcases hy with hy | hy <;> rcases ha with ha | ha <;>\n simp [q, hy, ha]\n have haff (i : ι) (x y : Ω) :\n f i x - f i y = (-1 / 2 : ℝ) * (q i x - q i y) := by\n rw [show f i x = (1 - q i x) / 2 by\n simpa [f, q] using bartlett_zeroOne_eq (Y x) (F i (X x)) (hY x) (hF i (X x)),\n show f i y = (1 - q i y) / 2 by\n simpa [f, q] using bartlett_zeroOne_eq (Y y) (F i (X y)) (hY y) (hF i (X y))]\n ring\n have hrad_eq (S : Fin n → Ω) :\n paperEmpRad n q S = paperEmpRad n F (fun k => X (S k)) := by\n have h := paperEmpRad_mul_labels n F (fun k => X (S k))\n (fun k => Y (S k)) (fun k => hY (S k))\n simpa [q] using h\n have hqRadInt : Integrable (fun S : Fin n → Ω => paperEmpRad n q S) ν := by\n rw [show (fun S : Fin n → Ω => paperEmpRad n q S) =\n fun S => paperEmpRad n F (fun k => X (S k)) by\n funext S; exact hrad_eq S]\n simpa [ν] using hRadInt\n have hqRad : paperRad n q μ id = R := by\n unfold paperRad\n rw [show (fun S : Fin n → Ω => paperEmpRad n q (fun k => id (S k))) =\n fun S => paperEmpRad n F (fun k => X (S k)) by\n funext S\n simpa using hrad_eq S]\n rfl\n have hempmeas (i : ι) : Measurable (emp i) := by\n dsimp [emp]\n exact ((Finset.univ : Finset (Fin n)).measurable_sum (fun k _ =>\n (hfmeas i).comp (measurable_pi_apply k))).const_mul _\n have hgmeas : Measurable g := by\n dsimp [g]\n apply Measurable.iSup\n intro i\n exact measurable_const.sub (hempmeas i)\n have hsymm : (∫ S, g S ∂ν) ≤ R / 2 := by\n have h := bartlett_symmetrization_affine μ n hn f q hfmeas hf hq\n (-1 / 2) haff hgmeas hqRadInt\n rw [hqRad] at h\n norm_num at h ⊢\n linarith\n have hfint (i : ι) : Integrable (f i) μ :=\n Integrable.of_mem_Icc 0 1 (hfmeas i).aemeasurable\n (ae_of_all _ fun x => hf01 i x)\n have hmean (i : ι) : (∫ x, f i x ∂μ) ∈ Set.Icc (0 : ℝ) 1 := by\n constructor\n · simpa using integral_mono (μ := μ) (integrable_const (0 : ℝ)) (hfint i)\n (fun x => (hf01 i x).1)\n · simpa using integral_mono (μ := μ) (hfint i) (integrable_const (1 : ℝ))\n (fun x => (hf01 i x).2)\n have hemp (i : ι) (S : Fin n → Ω) : emp i S ∈ Set.Icc (0 : ℝ) 1 := by\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n constructor\n · dsimp [emp]\n exact mul_nonneg (inv_nonneg.mpr hnR.le)\n (Finset.sum_nonneg fun k _ => (hf01 i (S k)).1)\n · calc\n emp i S ≤ (n : ℝ)⁻¹ * ∑ _k : Fin n, (1 : ℝ) := by\n dsimp [emp]\n gcongr with k\n exact (hf01 i (S k)).2\n _ = 1 := by simp [ne_of_gt hnR]\n have hgBdd (S : Fin n → Ω) :\n BddAbove (Set.range fun i => (∫ x, f i x ∂μ) - emp i S) := by\n refine ⟨1, ?_⟩\n rintro _ ⟨i, rfl⟩\n linarith [(hmean i).2, (hemp i S).1]\n have hgmem (S : Fin n → Ω) : g S ∈ Set.Icc (-1 : ℝ) 1 := by\n have hBdd := hgBdd S\n constructor\n · let i : ι := Classical.choice inferInstance\n have hi := le_ciSup hBdd i\n linarith [(hmean i).1, (hemp i S).2]\n · refine ciSup_le fun i => ?_\n linarith [(hmean i).2, (hemp i S).1]\n have hgint : Integrable g ν :=\n Integrable.of_mem_Icc (-1) 1 hgmeas.aemeasurable (ae_of_all _ hgmem)\n have hgchange : ∀ (S S' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → S k = S' k) → |g S - g S'| ≤ 1 / (n : ℝ) := by\n intro S S' j hSS'\n apply bartlett_iSup_lipschitz\n (fun i => (∫ x, f i x ∂μ) - emp i S)\n (fun i => (∫ x, f i x ∂μ) - emp i S')\n (hgBdd S) (hgBdd S') (1 / (n : ℝ))\n intro i\n rw [show ((∫ x, f i x ∂μ) - emp i S) -\n ((∫ x, f i x ∂μ) - emp i S') = -(emp i S - emp i S') by ring,\n abs_neg]\n exact bartlett_empirical01_change_le n hn (f i) (hf01 i) S S' j hSS'\n let ℓ : ℝ := Real.log (1 / δ)\n let ε : ℝ := Real.sqrt (ℓ / (2 * n))\n have hratio : 1 < (1 / δ : ℝ) := by\n rw [lt_div_iff₀ hδ0]\n simpa using hδ1\n have hℓ : 0 < ℓ := Real.log_pos hratio\n have hε : 0 < ε := Real.sqrt_pos.2 (by positivity)\n have hεsq : ε ^ 2 = ℓ / (2 * n) := Real.sq_sqrt (by positivity)\n have htail : ν.real {S | g S - ∫ T, g T ∂ν ≥ ε} ≤ δ := by\n have hc : 0 < 1 / (n : ℝ) := by positivity\n have hmc := bartlett_mcdiarmid_pi μ n hn g hgmeas hgint\n (1 / (n : ℝ)) hc hgchange ε hε\n have hexp : -2 * ε ^ 2 / ((n : ℝ) * (1 / (n : ℝ)) ^ 2) = -ℓ := by\n rw [hεsq]\n have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn\n field_simp\n rw [hexp] at hmc\n calc\n _ ≤ Real.exp (-ℓ) := hmc\n _ = δ := by\n rw [Real.exp_neg]\n dsimp [ℓ]\n rw [Real.exp_log (by positivity : 0 < (1 / δ : ℝ))]\n field_simp\n let A : Set (Fin n → Ω) := {S | g S - ∫ T, g T ∂ν ≥ ε}\n have hAmeas : MeasurableSet A := by\n exact measurableSet_Ici.preimage (hgmeas.sub_const _)\n have hcomp : 1 - δ ≤ ν.real Aᶜ := by\n rw [measureReal_compl hAmeas, probReal_univ]\n have : ν.real A ≤ δ := by simpa [A] using htail\n linarith\n apply hcomp.trans\n apply measureReal_mono ?_ (measure_ne_top ν _)\n intro S hS\n intro i\n have hS' : g S - (∫ T, g T ∂ν) < ε := by\n simpa [A, not_le] using hS\n have hgi : (∫ x, f i x ∂μ) - emp i S ≤ g S :=\n le_ciSup (hgBdd S) i\n have hgmean : (∫ T, g T ∂ν) ≤ R / 2 := hsymm\n change expectedLoss μ X Y zeroOneLoss (F i) ≤\n empiricalCost n X Y zeroOneLoss (F i) S + R / 2 + ε\n change (∫ x, f i x ∂μ) ≤ emp i S + R / 2 + ε\n linarith\n\nprivate lemma bartlett_finite_average_lipschitz {α : Type*} [Fintype α] [Nonempty α]\n (a b : α → ℝ) (c : ℝ) (hc : 0 ≤ c) (h : ∀ x, |a x - b x| ≤ c) :\n |(Fintype.card α : ℝ)⁻¹ * ∑ x, a x -\n (Fintype.card α : ℝ)⁻¹ * ∑ x, b x| ≤ c := by\n classical\n have hmpos : 0 < (Fintype.card α : ℝ) := by\n exact_mod_cast Fintype.card_pos\n have hinv : 0 ≤ (Fintype.card α : ℝ)⁻¹ := (inv_pos.mpr hmpos).le\n rw [← mul_sub, ← Finset.sum_sub_distrib, abs_mul,\n abs_of_pos (inv_pos.mpr hmpos)]\n calc\n (Fintype.card α : ℝ)⁻¹ * |∑ x, (a x - b x)| ≤\n (Fintype.card α : ℝ)⁻¹ * ∑ x, |a x - b x| := by\n gcongr\n exact Finset.abs_sum_le_sum_abs _ _\n _ ≤ (Fintype.card α : ℝ)⁻¹ * ∑ _x : α, c := by\n gcongr with x\n exact h x\n _ = c := by\n simp [ne_of_gt hmpos]\n\nprivate lemma bartlett_signed_sum_change_le {𝒮 : Type*} {ι : Type*}\n (n : ℕ) (F : ι → 𝒮 → ℝ) (hF : ∀ i s, F i s ∈ Set.Icc (-1 : ℝ) 1)\n (S S' : Fin n → 𝒮) (j : Fin n) (hSS' : ∀ k, k ≠ j → S k = S' k)\n (σ : Signs n) (i : ι) :\n |(∑ k : Fin n, (σ k : ℝ) * F i (S k)) -\n ∑ k : Fin n, (σ k : ℝ) * F i (S' k)| ≤ 2 := by\n classical\n have hsum :\n (∑ k : Fin n, (σ k : ℝ) * F i (S k)) -\n ∑ k : Fin n, (σ k : ℝ) * F i (S' k) =\n (σ j : ℝ) * (F i (S j) - F i (S' j)) := by\n rw [← Finset.sum_sub_distrib]\n calc\n ∑ k : Fin n, ((σ k : ℝ) * F i (S k) - (σ k : ℝ) * F i (S' k)) =\n ∑ k : Fin n, (σ k : ℝ) * (F i (S k) - F i (S' k)) := by\n apply Finset.sum_congr rfl\n intro k _\n ring\n _ = (σ j : ℝ) * (F i (S j) - F i (S' j)) := by\n apply Finset.sum_eq_single j\n · intro k _ hkj\n rw [hSS' k hkj]\n simp\n · simp\n rw [hsum, abs_mul, bartlett_sign_abs, one_mul, abs_le]\n rcases hF i (S j) with ⟨hSlo, hShi⟩\n rcases hF i (S' j) with ⟨hS'lo, hS'hi⟩\n constructor <;> linarith\n\nprivate lemma bartlett_inner_change_le {𝒮 : Type*} {ι : Type*} [Nonempty ι]\n (n : ℕ) (hn : 0 < n) (F : ι → 𝒮 → ℝ)\n (hF : ∀ i s, F i s ∈ Set.Icc (-1 : ℝ) 1)\n (S S' : Fin n → 𝒮) (j : Fin n) (hSS' : ∀ k, k ≠ j → S k = S' k)\n (σ : Signs n) :\n |(⨆ i, |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S k)|) -\n (⨆ i, |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S' k)|)| ≤\n 4 / (n : ℝ) := by\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n have hcoef : 0 ≤ 2 / (n : ℝ) := by positivity\n apply bartlett_iSup_lipschitz\n (fun i => |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S k)|)\n (fun i => |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S' k)|)\n (bartlett_inner_bddAbove n F hF S σ)\n (bartlett_inner_bddAbove n F hF S' σ)\n (4 / (n : ℝ))\n intro i\n calc\n abs (abs ((2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S k)) -\n abs ((2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S' k))) ≤\n |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S k) -\n (2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S' k)| :=\n abs_abs_sub_abs_le_abs_sub _ _\n _ = (2 / (n : ℝ)) *\n |(∑ k : Fin n, (σ k : ℝ) * F i (S k)) -\n ∑ k : Fin n, (σ k : ℝ) * F i (S' k)| := by\n rw [← mul_sub, abs_mul, abs_of_nonneg hcoef]\n _ ≤ (2 / (n : ℝ)) * 2 := by\n gcongr\n exact bartlett_signed_sum_change_le n F hF S S' j hSS' σ i\n _ = 4 / (n : ℝ) := by ring\n\nprivate lemma paperEmpRad_change_le {𝒮 : Type*} {ι : Type*} [Nonempty ι]\n (n : ℕ) (hn : 0 < n) (F : ι → 𝒮 → ℝ)\n (hF : ∀ i s, F i s ∈ Set.Icc (-1 : ℝ) 1)\n (S S' : Fin n → 𝒮) (j : Fin n)\n (hSS' : ∀ k, k ≠ j → S k = S' k) :\n |paperEmpRad n F S - paperEmpRad n F S'| ≤ 4 / (n : ℝ) := by\n letI : Nonempty (Signs n) :=\n ⟨fun _ => ⟨1, by simp [Signs]⟩⟩\n unfold paperEmpRad\n apply bartlett_finite_average_lipschitz\n (fun σ : Signs n =>\n ⨆ i, |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S k)|)\n (fun σ : Signs n =>\n ⨆ i, |(2 / (n : ℝ)) * ∑ k : Fin n, (σ k : ℝ) * F i (S' k)|)\n (4 / (n : ℝ)) (by positivity)\n intro σ\n exact bartlett_inner_change_le n hn F hF S S' j hSS' σ\n\nprivate lemma bartlett_two_sided_union {α : Type*} [MeasurableSpace α]\n (ν : Measure α) [IsFiniteMeasure ν] (g : α → ℝ) (ε b : ℝ)\n (hupper : ν.real {x | g x - ∫ y, g y ∂ν ≥ ε} ≤ b)\n (hlower : ν.real {x | (-g x) - ∫ y, -g y ∂ν ≥ ε} ≤ b) :\n ν.real {x | |(∫ y, g y ∂ν) - g x| ≥ ε} ≤ 2 * b := by\n calc\n ν.real {x | |(∫ y, g y ∂ν) - g x| ≥ ε} ≤\n ν.real ({x | g x - ∫ y, g y ∂ν ≥ ε} ∪\n {x | (-g x) - ∫ y, -g y ∂ν ≥ ε}) := by\n refine measureReal_mono ?_ (measure_ne_top ν _)\n intro x hx\n change ε ≤ |(∫ y, g y ∂ν) - g x| at hx\n rw [Set.mem_union, Set.mem_setOf_eq, Set.mem_setOf_eq]\n rcases (le_abs.mp hx) with hx | hx\n · right\n rw [integral_neg]\n linarith\n · left\n linarith\n _ ≤ ν.real {x | g x - ∫ y, g y ∂ν ≥ ε} +\n ν.real {x | (-g x) - ∫ y, -g y ∂ν ≥ ε} :=\n measureReal_union_le _ _\n _ ≤ b + b := add_le_add hupper hlower\n _ = 2 * b := by ring\n\ntheorem thm11_rademacher_concentration {Ω : Type u} {𝒮 : Type w} {ι : Type v}\n [MeasurableSpace Ω] [Nonempty ι]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (X : Ω → 𝒮)\n (F : ι → 𝒮 → ℝ) (hF : ∀ i s, F i s ∈ Set.Icc (-1 : ℝ) 1)\n (n : ℕ) (hn : 0 < n)\n (hRadInt : Integrable\n (fun ω : Fin n → Ω => paperEmpRad n F (fun k => X (ω k)))\n (Measure.pi (fun _ => μ)))\n (hMcD : ∀ (g : (Fin n → Ω) → ℝ) (c : ℝ), 0 ≤ c →\n Integrable g (Measure.pi (fun _ => μ)) →\n (∀ (ω ω' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → ω k = ω' k) → |g ω - g ω'| ≤ c) →\n ∀ t : ℝ, 0 < t →\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω | g ω - ∫ ω', g ω' ∂(Measure.pi (fun _ => μ)) ≥ t}\n ≤ Real.exp (-2 * t ^ 2 / (n * c ^ 2)))\n (ε : ℝ) (hε : 0 < ε) :\n (Measure.pi (fun _ : Fin n => μ)).real\n {ω : Fin n → Ω |\n |paperRad n F μ X - paperEmpRad n F (fun k => X (ω k))| ≥ ε}\n ≤ 2 * Real.exp (-(ε ^ 2 * n) / 8) := by\n let ν : Measure (Fin n → Ω) := Measure.pi (fun _ => μ)\n let g : (Fin n → Ω) → ℝ :=\n fun ω => paperEmpRad n F (fun k => X (ω k))\n have hc : 0 ≤ 4 / (n : ℝ) := by positivity\n have hchange : ∀ (ω ω' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → ω k = ω' k) → |g ω - g ω'| ≤ 4 / (n : ℝ) := by\n intro ω ω' j hω\n exact paperEmpRad_change_le n hn F hF _ _ j (fun k hk => congrArg X (hω k hk))\n have hgint : Integrable g (Measure.pi (fun _ : Fin n => μ)) := by\n simpa [g] using hRadInt\n have hexponent :\n -2 * ε ^ 2 / ((n : ℝ) * (4 / (n : ℝ)) ^ 2) =\n -(ε ^ 2 * n) / 8 := by\n have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn\n field_simp\n ring\n have hupper :\n ν.real {ω | g ω - ∫ ω', g ω' ∂ν ≥ ε} ≤\n Real.exp (-(ε ^ 2 * n) / 8) := by\n have h := hMcD g (4 / (n : ℝ)) hc hgint hchange ε hε\n rw [hexponent] at h\n simpa [ν] using h\n have hlower :\n ν.real {ω | (-g ω) - ∫ ω', -g ω' ∂ν ≥ ε} ≤\n Real.exp (-(ε ^ 2 * n) / 8) := by\n have hnegchange : ∀ (ω ω' : Fin n → Ω) (j : Fin n),\n (∀ k, k ≠ j → ω k = ω' k) →\n |(-g ω) - (-g ω')| ≤ 4 / (n : ℝ) := by\n intro ω ω' j hω\n rw [show (-g ω) - (-g ω') = -(g ω - g ω') by ring, abs_neg]\n exact hchange ω ω' j hω\n have h := hMcD (fun ω => -g ω) (4 / (n : ℝ)) hc hgint.neg\n hnegchange ε hε\n rw [hexponent] at h\n simpa [ν] using h\n simpa [ν, g, paperRad] using\n bartlett_two_sided_union ν g ε (Real.exp (-(ε ^ 2 * n) / 8)) hupper hlower\n\nend\n\nend ResearchLevel\n"} +{"id": "v25-21-0748", "source": "Research-level", "targets": [{"label": "Theorem 1", "decls": ["theorem1"], "statement": "Theorem 1. Suppose that the regularizer ψ $: \\mathcal{X}\\mapsto \\mathbb{R}$ is 1-strongly convex with respect to the norm $\\| \\cdot \\|$ , and let $\\| \\cdot \\|_{*}$ be the dual norm of $\\| \\cdot \\|$ . The dynamic regret of OpTIMISTIC OMD whose update rule is specified in (6) is bounded as follows:\n\n$$\n\\begin{array}{r}{\\displaystyle\\sum_{t=1}^{T}f_{t}(\\mathbf{x}_{t})-\\displaystyle\\sum_{t=1}^{T}f_{t}(\\mathbf{u}_{t})\\leq\\displaystyle\\sum_{t=1}^{T}\\eta_{t}\\|\\nabla f_{t}(\\mathbf{x}_{t})-M_{t}\\|_{*}^{2}+\\displaystyle\\sum_{t=1}^{T}\\frac{1}{\\eta_{t}}\\Big(\\mathcal{D}_{\\psi}(\\mathbf{u}_{t},\\widehat{\\mathbf{x}}_{t})-\\mathcal{D}_{\\psi}(\\mathbf{u}_{t},\\widehat{\\mathbf{x}}_{t+1})\\Big)}\\\\ {-\\displaystyle\\sum_{t=1}^{T}\\frac{1}{\\eta_{t}}\\Big(\\mathcal{D}_{\\psi}(\\widehat{\\mathbf{x}}_{t+1},\\mathbf{x}_{t})+\\mathcal{D}_{\\psi}(\\mathbf{x}_{t},\\widehat{\\mathbf{x}}_{t})\\Big),}\\end{array}\\tag{7}\n$$\n\nwhich holds for any comparator sequence $\\mathbf{u}_{1},\\dots,\\mathbf{u}_{T}\\in\\mathcal{X}$", "context_ids": ["v25-21-0748:ctx1", "v25-21-0748:ctx2", "v25-21-0748:ctx3", "v25-21-0748:ctx4", "v25-21-0748:ctx5", "v25-21-0748:ctx9"], "sibling_refs": ["Lemma 4"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}, {"label": "Lemma 4", "decls": ["lemma4_bregmanProximal"], "statement": "Lemma 4 (Bregman proximal inequality (Chen and Teboulle, 1993, Lemma 3.2)). Let X be a convex set in a Banach space. Let $f : \\mathcal{X}\\mapsto \\mathbb{R}$ be a closed proper convex function on X. Given a convex regularizer $\\psi : \\mathcal{X}\\mapsto \\mathbb{R}$ , we denote its induced Bregman divergence by $\\mathcal{D}_{\\psi}(\\cdot,\\cdot)$ . Then, any update of the form\n\n$$\n\\mathbf{x}_{k}=\\underset{\\mathbf{x}\\in\\mathcal{X}}{\\arg\\operatorname*{min}}\\{f(\\mathbf{x})+\\mathcal{D}_{\\psi}(\\mathbf{x},\\mathbf{x}_{k-1})\\}\n$$\n\nsatisfies the following inequality for any $\\mathbf{u}\\in \\mathcal{X}$\n\n$$\n\\begin{array}{r}{f ({\\mathbf x}_{k}) - f ({\\mathbf u}) \\le \\mathcal{D}_{\\psi}({\\mathbf u},{\\mathbf x}_{k - 1}) - \\mathcal{D}_{\\psi}({\\mathbf u},{\\mathbf x}_{k}) - \\mathcal{D}_{\\psi}({\\mathbf x}_{k},{\\mathbf x}_{k - 1}) .}\\end{array}\\tag{60}\n$$", "context_ids": ["v25-21-0748:ctx4"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}, {"label": "Lemma 1 (dynamic regret of OEGD)", "decls": ["lemma1_OEGD"], "statement": "Lemma 1. Under Assumptions 1, 2, and 3, by choosing $\\begin{array}{r}{\\eta \\le \\frac{1}{4 L}}\\end{array}$ , dynamic regret of OEGD (namely, OPTIMISTIC OMD with $\\begin{array}{r}{\\psi(\\mathbf{x})=\\frac{1}{2}\\|\\mathbf{x}\\|_{2}^{2}}\\end{array}$ and $M_{t}=\\nabla f_{t-1}(\\mathbf x_{t-1}))$ satisfies\n\n$$\n\\sum_{t=1}^{T}f_{t}(\\mathbf x_{t})-\\sum_{t=1}^{T}f_{t}(\\mathbf u_{t})\\leq\\eta(G^{2}+2V_{T})+\\frac{1}{2\\eta}(D^{2}+2DP_{T})\\tag{9}\n$$\n\nfor any comparator sequence $\\mathbf{u}_{1},\\dots,\\mathbf{u}_{T}\\in\\mathcal{X}$", "context_ids": ["v25-21-0748:ctx1", "v25-21-0748:ctx2", "v25-21-0748:ctx3", "v25-21-0748:ctx4", "v25-21-0748:ctx6", "v25-21-0748:ctx7", "v25-21-0748:ctx8", "v25-21-0748:ctx9", "v25-21-0748:ctx10", "v25-21-0748:ctx11", "v25-21-0748:ctx12"], "sibling_refs": ["Theorem 1"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}], "nl_proof": "### Proof of Theorem 1\n\nProof The instantaneous dynamic regret can be upper bounded and decomposed as\n\n$$\nf_{t}(\\mathbf{x}_{t})-f_{t}(\\mathbf{u}_{t})\\leq\\underbrace{\\langle\\nabla f_{t}(\\mathbf{x}_{t})-M_{t},\\mathbf{x}_{t}-\\widehat{\\mathbf{x}}_{t+1}\\rangle}_{\\mathrm{term~(a)}}+\\underbrace{\\langle M_{t},\\mathbf{x}_{t}-\\widehat{\\mathbf{x}}_{t+1}\\rangle}_{\\mathrm{term~(b)}}+\\underbrace{\\langle\\nabla f_{t}(\\mathbf{x}_{t}),\\widehat{\\mathbf{x}}_{t+1}-\\mathbf{u}_{t}\\rangle}_{\\mathrm{term~(c)}}.\n$$\n\nIn the following, we use the stability lemma (Lemma 5) to bound term (a) and appeal to the Bregman proximal inequality (Lemma 4) to bound term (b) and term (c).\n\nWe first investigate term (a). Intuitively, the prediction $\\mathbf{x}_{t}$ should be close the $\\widehat{\\mathbf{x}}_{t + 1}$ when the optimistic vector $M_{t}$ is close to the gradient of the next iteration $\\nabla f_{t}(\\mathbf{x}_{t})$ . The intuition is formalized in the stability lemma (Chiang et al., 2012, Propostion 7), as restated in Lemma 5 of Appendix C, which implies $\\|\\mathbf{x}_{t}-\\widehat{\\mathbf{x}}_{t+1}\\|\\leq\\eta_{t}\\|\\nabla f_{t}(\\mathbf{x}_{t})-M_{t}\\|_{*}$ and consequently,\n\n$$\n\\begin{array}{r}{\\mathbf{term}\\left(\\mathbf{a}\\right)\\leq\\|\\nabla f_{t}(\\mathbf{x}_{t})-M_{t}\\|_{*}\\|\\mathbf{x}_{t}-\\widehat{\\mathbf{x}}_{t+1}\\|\\leq\\eta_{t}\\|\\nabla f_{t}(\\mathbf{x}_{t})-M_{t}\\|_{*}^{2}.}\\end{array}\n$$\n\nWe now analyze term (b) and term (c). By the Bregman proximal inequality (Lemma 4) and the OPTIMISTIC OMD update step $\\mathbf{x}_{t}=\\arg\\operatorname*{min}_{\\mathbf{x}\\in\\mathcal{X}}\\{\\eta_{t}\\langle M_{t},\\mathbf{x}\\rangle+\\mathcal{D}_{\\psi}(\\mathbf{x},\\widehat{\\mathbf{x}}_{t})\\}$ , we have\n\n$$\n\\mathbf{term\\ (b)}=\\langle M_{t},\\mathbf{x}_{t}-\\widehat{\\mathbf{x}}_{t+1}\\rangle\\leq\\frac{1}{\\eta_{t}}\\Big(\\mathcal{D}_{\\psi}(\\widehat{\\mathbf{x}}_{t+1},\\widehat{\\mathbf{x}}_{t})-\\mathcal{D}_{\\psi}(\\widehat{\\mathbf{x}}_{t+1},\\mathbf{x}_{t})-\\mathcal{D}_{\\psi}(\\mathbf{x}_{t},\\widehat{\\mathbf{x}}_{t})\\Big).\n$$\n\nSimilarly, the update $\\begin{array}{r}{\\widehat{\\mathbf{x}}_{t+1}=\\arg\\operatorname*{min}_{\\mathbf{x}\\in\\mathcal{X}}\\{\\eta_{t}\\langle\\nabla f_{t}(\\mathbf{x}_{t}),\\mathbf{x}\\rangle+\\mathcal{D}_{\\psi}(\\mathbf{x},\\widehat{\\mathbf{x}}_{t})\\}}\\end{array}$ implies\n\n$$\n\\mathbf{term~}(\\mathbf{c})=\\langle\\nabla f_{t}(\\mathbf{x}_{t}),\\widehat{\\mathbf{x}}_{t+1}-\\mathbf{u}_{t}\\rangle\\leq\\frac{1}{\\eta_{t}}\\Big(\\mathcal{D}_{\\psi}(\\mathbf{u}_{t},\\widehat{\\mathbf{x}}_{t})-\\mathcal{D}_{\\psi}(\\mathbf{u}_{t},\\widehat{\\mathbf{x}}_{t+1})-\\mathcal{D}_{\\psi}(\\widehat{\\mathbf{x}}_{t+1},\\widehat{\\mathbf{x}}_{t})\\Big).\n$$\n\nCombining the three upper bounds completes the proof.\n\n### Proof of Lemma 4\n\n(The source gives no proof of this result.)\n\n### Proof of Lemma 1 (dynamic regret of OEGD)\n\nProof [of Lemma 1] We first show a general result for Optimistic OMD with an arbitrary optimistic vector $M_{t}\\in \\mathbb{R}^{d}$ and the regularizer $\\begin{array}{r}{\\psi(\\mathbf{x})=\\frac{1}{2}\\|\\mathbf{x}\\|_{2}^{2}}\\end{array}$ , and then prove Lemma 1 by simply substituting $M_{t}=\\nabla f_{t-1}(\\mathbf x_{t-1})$ into it.\n\nIt is well-known that $\\begin{array}{r}{\\psi(\\mathbf{x})=\\frac{1}{2}\\|\\mathbf{x}\\|_{2}^{2}}\\end{array}$ is 1-strongly convex with respect to the Euclidean norm $\\| \\cdot \\|_{2}$ and $\\begin{array}{r}{\\mathcal{D}_{\\psi}(\\mathbf{x},\\mathbf{y})=\\frac{1}{2}\\|\\mathbf{x}-\\mathbf{y}\\|_{2}^{2}}\\end{array}$ . Thus, Theorem 1 implies\n\n$$\n\\begin{array}{r}{\\displaystyle\\sum_{t=1}^{T}f_{t}(\\mathbf{x}_{t})-\\displaystyle\\sum_{t=1}^{T}f_{t}(\\mathbf{u}_{t})\\leq\\eta\\sum_{t=1}^{T}\\lVert\\nabla f_{t}(\\mathbf{x}_{t})-M_{t}\\rVert_{2}^{2}+\\displaystyle\\frac{1}{2\\eta}\\displaystyle\\sum_{t=1}^{T}\\left(\\lVert\\mathbf{u}_{t}-\\widehat{\\mathbf{x}}_{t}\\rVert_{2}^{2}-\\lVert\\mathbf{u}_{t}-\\widehat{\\mathbf{x}}_{t+1}\\rVert_{2}^{2}\\right)}\\\\ {\\displaystyle-\\displaystyle\\frac{1}{2\\eta}\\displaystyle\\sum_{t=1}^{T}\\left(\\lVert\\widehat{\\mathbf{x}}_{t+1}-\\mathbf{x}_{t}\\rVert_{2}^{2}+\\lVert\\widehat{\\mathbf{x}}_{t}-\\mathbf{x}_{t}\\rVert_{2}^{2}\\right).}\\end{array}\n$$\n\nNotice that the second term can be upper bounded as follows.\n\n$$\n\\sum_{t=1}^{T}\\left(\\lVert\\mathbf{u}_{t}-\\widehat{\\mathbf{x}}_{t}\\rVert_{2}^{2}-\\lVert\\mathbf{u}_{t}-\\widehat{\\mathbf{x}}_{t+1}\\rVert_{2}^{2}\\right)\\leq\\lVert\\mathbf{u}_{1}-\\widehat{\\mathbf{x}}_{1}\\rVert_{2}^{2}+\\sum_{t=2}^{T}\\left(\\lVert\\mathbf{u}_{t}-\\widehat{\\mathbf{x}}_{t}\\rVert_{2}^{2}-\\lVert\\mathbf{u}_{t-1}-\\widehat{\\mathbf{x}}_{t}\\rVert_{2}^{2}\\right)\n$$\n\n$$\n\\leq \\|{\\bf u}_{1}- \\widehat{{\\bf x}}_{1}\\|_{2}^{2}+ \\sum_{t = 2}^{T}\\|{\\bf u}_{t}-{\\bf u}_{t - 1}\\|_{2}\\|{\\bf u}_{t}- \\widehat{{\\bf x}}_{t}+{\\bf u}_{t - 1}- \\widehat{{\\bf x}}_{t}\\|_{2}\\leq D^{2}+ 2 D \\sum_{t = 2}^{T}\\|{\\bf u}_{t}-{\\bf u}_{t - 1}\\|_{2}.\n$$\n\nWe further evaluate the last term using the inequality of $a^{2}+b^{2}\\geq(a+b)^{2}/2$ and obtain\n\n$$\n\\sum_{t=1}^{T}\\left(\\lVert\\widehat{\\mathbf{x}}_{t+1}-\\mathbf{x}_{t}\\rVert_{2}^{2}+\\lVert\\widehat{\\mathbf{x}}_{t}-\\mathbf{x}_{t}\\rVert_{2}^{2}\\right)\\geq\\sum_{t=2}^{T}\\left(\\lVert\\widehat{\\mathbf{x}}_{t}-\\mathbf{x}_{t-1}\\rVert_{2}^{2}+\\lVert\\widehat{\\mathbf{x}}_{t}-\\mathbf{x}_{t}\\rVert_{2}^{2}\\right)\\geq\\frac{1}{2}\\sum_{t=2}^{T}\\lVert\\mathbf{x}_{t}-\\mathbf{x}_{t-1}\\rVert_{2}^{2}.\n$$\n\nHence, combining all the three inequalities, we get the following result:\n\n$$\n\\sum_{t=1}^{T}f_{t}(\\mathbf{x}_{t})-\\sum_{t=1}^{T}f_{t}(\\mathbf{u}_{t})\\leq\\eta\\sum_{t=1}^{T}\\lVert\\nabla f_{t}(\\mathbf{x}_{t})-M_{t}\\rVert_{2}^{2}+\\frac{1}{\\eta}(D^{2}+2DP_{T})-\\frac{1}{4\\eta}\\sum_{t=2}^{T}\\lVert\\mathbf{x}_{t}-\\mathbf{x}_{t-1}\\rVert_{2}^{2}.\n$$\n\nWhen choosing the optimism as the last-round gradient $M_{t}=\\nabla f_{t-1}(\\mathbf x_{t-1})$ , the adaptivity term $\\begin{array}{r}{\\sum_{t=1}^{T}\\lVert\\nabla f_{t}(\\mathbf x_{t})-M_{t}\\rVert_{2}^{2}}\\end{array}$ can be upper bounded in the following way:\n\n$$\n\\begin{array}{r l r}{{\\sum_{t=1}^{T}\\|\\nabla f_{t}(\\mathbf{x}_{t})-M_{t}\\|_{2}^{2}\\le G^{2}+2\\sum_{t=2}^{T}\\Big(\\|\\nabla f_{t}(\\mathbf{x}_{t})-\\nabla f_{t-1}(\\mathbf{x}_{t})\\|_{2}^{2}+\\|\\nabla f_{t-1}(\\mathbf{x}_{t})-\\nabla f_{t-1}(\\mathbf{x}_{t-1})\\|_{2}^{2}\\Big)}}\\\\ &{}&{\\le G^{2}+2\\sum_{t=2}^{T}\\underset{\\mathbf{x}\\in\\mathcal{X}}{\\operatorname*{sup}}\\|\\nabla f_{t}(\\mathbf{x})-\\nabla f_{t-1}(\\mathbf{x})\\|_{2}^{2}+2 L^{2}\\underset{t=2}{\\overset{T}{\\sum}}\\|\\mathbf{x}_{t}-\\mathbf{x}_{t-1}\\|_{2}^{2},}\\end{array}\n$$\n\nwhere the last step exploits L-smoothness of online functions. Therefore,\n\n$$\n\\begin{array}{l}{\\displaystyle\\sum_{t=1}^{T}f_{t}(\\mathbf x_{t})-\\sum_{t=1}^{T}f_{t}(\\mathbf u_{t})\\leq\\eta(G^{2}+2V_{T})+\\frac{1}{2\\eta}(D^{2}+2DP_{T})+\\left(2\\eta L^{2}-\\frac{1}{4\\eta}\\right)\\sum_{t=2}^{T}\\lVert\\mathbf x_{t}-\\mathbf x_{t-1}\\rVert_{2}^{2}}\\\\ {\\displaystyle\\qquad\\leq\\eta(G^{2}+2V_{T})+\\frac{1}{2\\eta}(D^{2}+2DP_{T}),}\\end{array}\n$$\n\nwhere $\\eta\\leq 1/(4L)$ ensures the last term to be non-positive. This ends the proof.", "context": [{"id": "v25-21-0748:ctx1", "name": "Setup: online convex optimization protocol (Introduction)", "statement": "At iteration t, the player chooses a decision vector $\\mathbf{x}_{t}$ from a convex set $\\boldsymbol{\\mathcal{X}}\\subseteq \\mathbb{R}^{d}$ . Subsequently, the adversary discloses a convex function $f_{t}: \\mathcal{X}\\mapsto \\mathbb{R}$ ,and the player incurs a loss denoted by $f_{t}(\\mathbf{x}_{t})$"}, {"id": "v25-21-0748:ctx2", "name": "Setup: problem setup and feedback models (Section 3.1)", "statement": "Online Convex Optimization (OCO) can be modeled as an iterated game between the player and the environments. At iteration $t \\in [ T ]$ , the player first chooses the decision $\\mathbf{x}_{t}$ from a convex feasible set $\\boldsymbol{\\mathcal{X}}\\subseteq \\mathbb{R}^{d}$ , then the environments reveal the loss function $f_{t}: \\mathcal{X}\\mapsto \\mathbb{R}$ and the player suffers the loss $f_{t}(\\mathbf{x}_{t})$ and observes a certain information about the function $f_{t}(\\cdot).$ 2 According to the revealed information, the online learning problems are typically classified into full-information online learning and partial-information online learning (or sometimes called bandit online learning). In this paper, we focus on the full-information one, which can be further categorized into the following two setups:\n\n(i) multi-gradient feedback: the player can access the entire gradient function $\\nabla f_{t}(\\cdot)$ and thus can evaluate the gradient multiple times at each round;\n\n(ii) one-gradient feedback: the player can observe the gradient information $\\nabla f_{t}(\\mathbf{x}_{t})$ after submitting the decision $\\mathbf{x}_{t}$ at each round.\n\nIn Section 4.2, we develop the Sword algorithm, which achieves the gradient-variation dynamic regret under the multi-gradient feedback model. In Section 4.3, we present an improved algorithm called Sword++ that can achieve the same dynamic regret guarantee (up to constants) under the more challenging one-gradient feedback model.\n\nTo handle non-stationary environments, we focus on the dynamic regret measure, which compares the online algorithm to a sequence of time-varying comparators $\\mathbf{u}_{1},\\dots,\\mathbf{u}_{T}\\in\\mathcal{X}$ as defined in (2). An upper bound of dynamic regret should be a function of comparators, and typically the bound depends on some regularities that measure the fluctuation of the comparator sequence, such as the path length $\\begin{array}{r}{P_{T}= \\sum_{t = 2}^{T}\\lVert \\mathbf{u}_{t}- \\mathbf{u}_{t - 1}\\rVert_{2}}\\end{array}$ Throughout the paper, we focus on the Euclidean norm for simplicity, and it is straightforward to extend our results to general primal-dual norms.\n\nIn addition to the regret measure, we further consider the gradient query complexity. Note that algorithms designed for the multi-gradient feedback model may query the gradients for multiple times at each round. However, most algorithms designed for the static regret minimization only require one gradient per iteration, namely, using $\\nabla f_{t}(\\mathbf{x}_{t})$ for the next update only. Therefore, it is more desirable to achieve the favorable regret guarantees under the one-gradient feedback model. In other words, our aim is to develop first-order methods for dynamic regret minimization that require only one gradient query per iteration."}, {"id": "v25-21-0748:ctx3", "name": "Dynamic regret, eq. (2)", "statement": "To address this limitation, dynamic regret is proposed to compete with changing comparators $\\mathbf{u}_{1},\\dots,\\mathbf{u}_{T}\\in\\mathcal{X}$\n\n$$\n\\mathrm{D-Regret}_{T}(\\mathbf{u}_{1},\\ldots,\\mathbf{u}_{T})=\\sum_{t=1}^{T}f_{t}(\\mathbf{x}_{t})-\\sum_{t=1}^{T}f_{t}(\\mathbf{u}_{t}),\\tag{2}\n$$"}, {"id": "v25-21-0748:ctx4", "name": "Optimistic OMD: update rule (6), Bregman divergence, strong convexity (Section 3.2)", "statement": "We employ the algorithmic framework of Optimistic Online Mirror Descent (OpTIMISTIC OMD) (Chiang et al., 2012; Rakhlin and Sridharan, 2013) as a general building block for designing algorithms for non-stationary online learning. Optimistic OMD is an algorithmic realization of optimistic online learning. Compared to the standard online learning setup, the player receives an additional element at each round: an optimistic vector $M_{t}\\in \\mathbb{R}^{d}$ This vector acts as a predictive hint or an optimistic estimate of the upcoming gradient, thereby called \"optimistic vector\" or simply \"optimism\". Optimistic OMD starts from the initial point $\\widehat{\\mathbf{x}}_{1}\\in \\mathcal{X}$ and performs the following two-step updates at each round:\n\n$$\n\\begin{array}{r l}&{\\mathbf{x}_{t}=\\underset{\\mathbf{x}\\in\\mathcal{X}}{\\arg\\operatorname*{min}}~\\big\\{\\eta_{t}\\langle M_{t},\\mathbf{x}\\rangle+\\mathcal{D}_{\\psi}(\\mathbf{x},\\widehat{\\mathbf{x}}_{t})\\big\\},}\\\\ &{\\widehat{\\mathbf{x}}_{t+1}=\\underset{\\mathbf{x}\\in\\mathcal{X}}{\\arg\\operatorname*{min}}~\\big\\{\\eta_{t}\\langle\\nabla f_{t}(\\mathbf{x}_{t}),\\mathbf{x}\\rangle+\\mathcal{D}_{\\psi}(\\mathbf{x},\\widehat{\\mathbf{x}}_{t})\\big\\},}\\end{array}\\tag{6}\n$$\n\nwhich firstly updates by the optimistic vector $M_{t}$ and then updates by the received gradient $\\nabla f_{t}(\\mathbf{x}_{t})$ . In above, $\\eta_{t}> 0$ is a (potentially) time-varying step size, and $\\mathcal{D}_{\\psi}(\\cdot,\\cdot)$ denotes the Bregman divergence associated with the regularizer $\\psi$ defined as $\\mathcal{D}_{\\psi}(\\mathbf{x},\\mathbf{y})=\\psi(\\mathbf{x})-\\psi(\\mathbf{y})-$ $\\langle\\nabla\\psi(\\mathbf{y}),\\mathbf{x}-\\mathbf{y}\\rangle$ . We may assume the regularizer to be σ-strongly convex with respect to the norm $\\begin{array}{r}{\\|\\cdot\\|,\\operatorname{i.e.,}\\psi(\\mathbf{y})\\geq\\psi(\\mathbf{x})+\\langle\\nabla\\psi(\\mathbf{x}),\\mathbf{y}-\\mathbf{x}\\rangle+\\frac{\\sigma}{2}\\|\\mathbf{y}-\\mathbf{x}\\|^{2}}\\end{array}$ holds for any $\\mathbf{x}, \\mathbf{y}\\in{\\mathcal{X}}$ . We have the following general result regarding dynamic regret of optimistic OMD."}, {"id": "v25-21-0748:ctx5", "name": "Lemma 5 (stability lemma, Chiang et al. 2012, Proposition 7)", "statement": "Lemma 5 (stability lemma (Chiang et al., 2012, Proposition 7)). Consider the following two updates: $\\begin{array}{r}{(i)\\mathbf{x}_{*}=\\arg\\operatorname*{min}_{\\mathbf{x}\\in\\mathcal{X}}\\langle\\mathbf{a},\\mathbf{x}\\rangle+\\mathcal{D}_{\\psi}(\\mathbf{x},\\mathbf{c})}\\end{array}$ , and $(i i)\\mathbf{x}_{*}^{\\prime}=\\arg\\operatorname*{min}_{\\mathbf{x}\\in\\mathcal{X}}\\langle\\mathbf{a}^{\\prime},\\mathbf{x}\\rangle+\\mathcal{D}_{\\psi}(\\mathbf{x},\\mathbf{c})$ When the regularizer $\\psi : \\mathcal{X}\\mapsto \\mathbb{R}$ is a 1-strongly convex function with respect to the norm $\\| \\cdot \\|$ , we have $\\| \\mathbf{x}_{*}- \\mathbf{x}_{*}^{\\prime}\\| \\leq \\| \\mathbf{a}- \\mathbf{a}^{\\prime}\\|_{*}$"}, {"id": "v25-21-0748:ctx6", "name": "Assumption 1 (bounded gradients)", "statement": "Assumption 1. The norm of the gradients of online functions over the domain $\\mathcal{X}$ is bounded by G, i.e., $\\|\\nabla f_{t}(\\mathbf{x})\\|_{2}\\leq G$ , for all $\\mathbf{x}\\in \\mathcal{X}$ and $t \\in [ T ]$ ."}, {"id": "v25-21-0748:ctx7", "name": "Assumption 2 (domain contains origin, diameter D)", "statement": "Assumption 2. The domain $\\mathcal{X}\\subseteq \\mathbb{R}^{d}$ contains the origin $\\mathbf{0}$, and the diameter of the domain $\\mathcal{X}$ is at most D, i.e., $\\| \\mathbf{x}- \\mathbf{x}^{\\prime}\\|_{2}\\leq D$ for any $\\mathbf{x}, \\mathbf{x}^{\\prime}\\in \\mathcal{X}$"}, {"id": "v25-21-0748:ctx8", "name": "Assumption 3 (L-smoothness)", "statement": "Assumption 3. All the online functions are L-smooth, i.e., $\\|\\nabla f_{t}(\\mathbf{x})-\\nabla f_{t}(\\mathbf{x}^{\\prime})\\|_{2}\\leq L\\|\\mathbf{x}-\\mathbf{x}^{\\prime}\\|_{2}$ for any $\\mathbf{x}, \\mathbf{x}^{\\prime}\\in \\mathbb{R}^{d}$ and $t \\in [ T ]$"}, {"id": "v25-21-0748:ctx9", "name": "Remark: Theorem 1 does not need smoothness", "statement": "We have the following remarks regarding the assumptions. The general dynamic regret analysis of Optimistic OMD (Theorem 1) does not require the smoothness assumption. Nevertheless, this assumption is crucial for achieving problem-dependent dynamic regret bounds."}, {"id": "v25-21-0748:ctx10", "name": "OEGD update (8) and its reduction to Optimistic OMD (Section 4.1)", "statement": "In the study of static regret, Chiang et al. (2012) propose the online extra-gradient descent (OEGD) algorithm and prove that the algorithm enjoys gradient-variation static regret. Specifically, OEGD starts from $\\widehat{\\mathbf{x}}_{1}\\in \\mathcal{X}$ and then updates by\n\n$$\n\\begin{array}{r}{\\mathbf{x}_{t}=\\Pi_{\\mathcal{X}}\\left[\\widehat{\\mathbf{x}}_{t}-\\eta\\nabla f_{t-1}(\\mathbf{x}_{t-1})\\right],\\widehat{\\mathbf{x}}_{t+1}=\\Pi_{\\mathcal{X}}\\left[\\widehat{\\mathbf{x}}_{t}-\\eta\\nabla f_{t}(\\mathbf{x}_{t})\\right],}\\end{array}\\tag{8}\n$$\n\nwhere we define $f_{0}(\\mathbf{x}_{0})=\\mathbf{0}$ and $\\Pi_{\\mathcal{X}}[ \\cdot ]$ the Euclidean projection onto the nearest point in $\\mathcal{X}.$ We consider a fixed step size $\\eta > 0$ for simplicity. For convex and smooth functions, Chiang et al. (2012) prove that OEGD enjoys an $\\mathcal{O}(\\sqrt{1+V_{T}})$ gradient-variation static regret.\n\nActually, OEGD can be viewed as a specialization of Optimistic OMD (6) presented in Section 3.2, by choosing the regularizer $\\begin{array}{r}{\\psi(\\mathbf{x})=\\frac{1}{2}\\|\\mathbf{x}\\|_{2}^{2}}\\end{array}$ and the optimistic vector $M_{t}=$ $\\nabla f_{t-1}\\big(\\mathbf{x}_{t-1}\\big)$ as well as a fixed step size $\\eta > 0$ Therefore, Theorem 1 directly implies the following dynamic regret upper bound for OEGD, with proof in Appendix A."}, {"id": "v25-21-0748:ctx11", "name": "Path length P_T, eq. (4)", "statement": "$$\nP_{T}= \\sum_{t = 2}^{T}\\lVert \\mathbf{u}_{t}- \\mathbf{u}_{t - 1}\\rVert_{2}\\tag{4}\n$$\n\nis the path length of comparators $\\mathbf{u}_{1},\\ldots,\\mathbf{u}_{T}$ and thus reflects the non-stationarity of environments."}, {"id": "v25-21-0748:ctx12", "name": "Gradient variation V_T, eq. (5)", "statement": "Specifically, we focus on the following two problem-dependent quantities: the gradient variation of online functions $V_{T}$ , and the cumulative loss of the comparator sequence $F_{T}$ , defined as\n\n$$\nV_{T}=\\sum_{t=2}^{T}\\operatorname*{sup}_{\\mathbf x\\in\\mathcal X}\\|\\nabla f_{t}(\\mathbf x)-\\nabla f_{t-1}(\\mathbf x)\\|_{2}^{2},~\\mathrm{and}~F_{T}=\\sum_{t=1}^{T}f_{t}(\\mathbf u_{t}).\\tag{5}\n$$"}], "lean": "import Mathlib\n\nnoncomputable section\n\nopen scoped BigOperators RealInnerProductSpace\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] [FiniteDimensional ℝ E]\n\ndef bregman (ψ : E → ℝ) (gradψ : E → E) (x y : E) : ℝ :=\n ψ x - ψ y - ⟪gradψ y, x - y⟫\n\ndef bregmanDual {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]\n (ψ : F → ℝ) (gradψ : F → (F →L[ℝ] ℝ)) (x y : F) : ℝ :=\n ψ x - ψ y - gradψ y (x - y)\n\ndef pathLength (u : ℕ → E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 2 T, ‖u t - u (t - 1)‖\n\ndef gradVarSup (X : Set E) (gradf : ℕ → E → E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 2 T, ⨆ x : X, ‖gradf t (x : E) - gradf (t - 1) (x : E)‖ ^ 2\n\ntheorem theorem1\n {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F]\n {T : ℕ} (X : Set F)\n (f : ℕ → F → ℝ) (gradf : ℕ → F → (F →L[ℝ] ℝ))\n (ψ : F → ℝ) (gradψ : F → (F →L[ℝ] ℝ))\n (x xhat u : ℕ → F) (M : ℕ → (F →L[ℝ] ℝ)) (η : ℕ → ℝ)\n\n (hXconv : Convex ℝ X)\n\n (hη : ∀ t ∈ Finset.Icc 1 T, 0 < η t)\n\n (hsc : ∀ a ∈ X, ∀ b ∈ X, ψ a + gradψ a (b - a) + (1 / 2) * ‖b - a‖ ^ 2 ≤ ψ b)\n\n (hψgrad : ∀ x ∈ X, HasFDerivAt ψ (gradψ x) x)\n\n (hfconv : ∀ t ∈ Finset.Icc 1 T, ConvexOn ℝ X (f t))\n\n (hfgrad : ∀ t ∈ Finset.Icc 1 T, HasFDerivAt (f t) (gradf t (x t)) (x t))\n\n (hu : ∀ t ∈ Finset.Icc 1 T, u t ∈ X)\n (hxX : ∀ t ∈ Finset.Icc 1 T, x t ∈ X)\n (hxhat1 : xhat 1 ∈ X)\n (hxhatX : ∀ t ∈ Finset.Icc 1 T, xhat (t + 1) ∈ X)\n\n (hx : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n η t * M t (x t) + bregmanDual ψ gradψ (x t) (xhat t)\n ≤ η t * M t z + bregmanDual ψ gradψ z (xhat t))\n\n (hxhat : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n η t * gradf t (x t) (xhat (t + 1)) + bregmanDual ψ gradψ (xhat (t + 1)) (xhat t)\n ≤ η t * gradf t (x t) z + bregmanDual ψ gradψ z (xhat t)) :\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n ≤ (∑ t ∈ Finset.Icc 1 T, η t * ‖gradf t (x t) - M t‖ ^ 2)\n + (∑ t ∈ Finset.Icc 1 T,\n (1 / η t) * (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1))))\n - (∑ t ∈ Finset.Icc 1 T,\n (1 / η t) * (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t))) := by\n sorry\n\ntheorem lemma4_bregmanProximal\n {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F]\n (X : Set F) (f ψ : F → ℝ) (gradψ : F → (F →L[ℝ] ℝ))\n (xk xkm1 u : F)\n\n (hXconv : Convex ℝ X)\n (hxkX : xk ∈ X) (hxkm1X : xkm1 ∈ X) (huX : u ∈ X)\n\n (hfconv : ConvexOn ℝ X f)\n (hflsc : LowerSemicontinuousOn f X)\n\n (hψconv : ConvexOn ℝ X ψ)\n\n (hψgrad : HasFDerivAt ψ (gradψ xk) xk)\n (hψgrad' : HasFDerivAt ψ (gradψ xkm1) xkm1)\n\n (hprox : ∀ z ∈ X,\n f xk + bregmanDual ψ gradψ xk xkm1 ≤ f z + bregmanDual ψ gradψ z xkm1) :\n f xk - f u\n ≤ bregmanDual ψ gradψ u xkm1 - bregmanDual ψ gradψ u xk\n - bregmanDual ψ gradψ xk xkm1 := by\n sorry\n\ntheorem lemma1_OEGD\n {T : ℕ} (X : Set E)\n (f : ℕ → E → ℝ) (gradf : ℕ → E → E)\n (x xhat u : ℕ → E) (η G D L : ℝ)\n (hη : 0 < η) (hL : 0 < L) (hηL : η ≤ 1 / (4 * L))\n (hXne : X.Nonempty)\n\n (hXconv : Convex ℝ X)\n\n (hG : ∀ t, ∀ a ∈ X, ‖gradf t a‖ ≤ G)\n (hgrad0 : ∀ a, gradf 0 a = 0)\n\n (h0X : (0 : E) ∈ X) (hD : ∀ a ∈ X, ∀ b ∈ X, ‖a - b‖ ≤ D)\n\n (hsmooth : ∀ t, ∀ a b, ‖gradf t a - gradf t b‖ ≤ L * ‖a - b‖)\n\n (hconv : ∀ t ∈ Finset.Icc 1 T, ∀ a ∈ X, ∀ b ∈ X,\n f t a + ⟪gradf t a, b - a⟫ ≤ f t b)\n\n (hfgrad : ∀ t ∈ Finset.Icc 1 T, ∀ a, HasGradientAt (f t) (gradf t a) a)\n\n (hu : ∀ t ∈ Finset.Icc 1 T, u t ∈ X)\n\n (hxX : ∀ t ∈ Finset.Icc 1 T, x t ∈ X)\n (hxhat1 : xhat 1 ∈ X)\n (hxhatX : ∀ t ∈ Finset.Icc 1 T, xhat (t + 1) ∈ X)\n\n (hx : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n (1 / 2) * ‖x t - xhat t‖ ^ 2 + η * ⟪gradf (t - 1) (x (t - 1)), x t⟫\n ≤ (1 / 2) * ‖z - xhat t‖ ^ 2 + η * ⟪gradf (t - 1) (x (t - 1)), z⟫)\n\n (hxhat : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n (1 / 2) * ‖xhat (t + 1) - xhat t‖ ^ 2 + η * ⟪gradf t (x t), xhat (t + 1)⟫\n ≤ (1 / 2) * ‖z - xhat t‖ ^ 2 + η * ⟪gradf t (x t), z⟫) :\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n ≤ η * (G ^ 2 + 2 * gradVarSup X gradf T)\n + (1 / (2 * η)) * (D ^ 2 + 2 * D * pathLength u T) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnoncomputable section\n\nopen scoped BigOperators RealInnerProductSpace\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] [FiniteDimensional ℝ E]\n\ndef bregman (ψ : E → ℝ) (gradψ : E → E) (x y : E) : ℝ :=\n ψ x - ψ y - ⟪gradψ y, x - y⟫\n\ndef bregmanDual {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]\n (ψ : F → ℝ) (gradψ : F → (F →L[ℝ] ℝ)) (x y : F) : ℝ :=\n ψ x - ψ y - gradψ y (x - y)\n\ndef pathLength (u : ℕ → E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 2 T, ‖u t - u (t - 1)‖\n\ndef gradVarSup (X : Set E) (gradf : ℕ → E → E) (T : ℕ) : ℝ :=\n ∑ t ∈ Finset.Icc 2 T, ⨆ x : X, ‖gradf t (x : E) - gradf (t - 1) (x : E)‖ ^ 2\n\nprivate theorem bregman_proximal_of_min\n {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]\n (X : Set F) (f ψ : F → ℝ) (gradψ : F → (F →L[ℝ] ℝ))\n (xk xkm1 u : F)\n (hXconv : Convex ℝ X) (hxkX : xk ∈ X) (huX : u ∈ X)\n (hfconv : ConvexOn ℝ X f)\n (hψgrad : HasFDerivAt ψ (gradψ xk) xk)\n (hprox : ∀ z ∈ X,\n f xk + bregmanDual ψ gradψ xk xkm1 ≤\n f z + bregmanDual ψ gradψ z xkm1) :\n f xk - f u\n ≤ bregmanDual ψ gradψ u xkm1 - bregmanDual ψ gradψ u xk\n - bregmanDual ψ gradψ xk xkm1 := by\n let d : F := u - xk\n have hlim : Filter.Tendsto\n (fun t : ℝ => t⁻¹ • (ψ (xk + t • d) - ψ xk) - gradψ xkm1 d)\n (nhdsWithin 0 (Set.Ioi 0))\n (nhds (gradψ xk d - gradψ xkm1 d)) :=\n (hψgrad.hasLineDerivAt d).tendsto_slope_zero_right.sub_const _\n have hev : ∀ᶠ t : ℝ in nhdsWithin 0 (Set.Ioi 0),\n f xk - f u ≤ t⁻¹ • (ψ (xk + t • d) - ψ xk) - gradψ xkm1 d := by\n filter_upwards [self_mem_nhdsWithin,\n (eventually_lt_nhds (show (0 : ℝ) < 1 by norm_num)).filter_mono inf_le_left]\n with t htpos htone\n have ht0 : 0 < t := htpos\n have ht1 : t ≤ 1 := le_of_lt htone\n have hzEq : xk + t • d = (1 - t) • xk + t • u := by\n dsimp [d]\n module\n have hzX : xk + t • d ∈ X := by\n rw [hzEq]\n exact hXconv hxkX huX (sub_nonneg.mpr ht1) ht0.le (by ring)\n have hfline : f (xk + t • d) ≤ (1 - t) * f xk + t * f u := by\n rw [hzEq]\n simpa only [smul_eq_mul] using\n hfconv.2 hxkX huX (sub_nonneg.mpr ht1) ht0.le (by ring)\n have hp := hprox (xk + t • d) hzX\n have hlin : gradψ xkm1 (xk + t • d - xkm1) =\n gradψ xkm1 (xk - xkm1) + t * gradψ xkm1 d := by\n have harg : xk + t • d - xkm1 = (xk - xkm1) + t • d := by module\n rw [harg, map_add, map_smul, smul_eq_mul]\n rw [bregmanDual, bregmanDual, hlin] at hp\n have hraw : t * (f xk - f u) ≤\n ψ (xk + t • d) - ψ xk - t * gradψ xkm1 d := by\n linarith\n simp only [smul_eq_mul]\n calc\n f xk - f u = t⁻¹ * (t * (f xk - f u)) := by\n rw [← mul_assoc, inv_mul_cancel₀ ht0.ne', one_mul]\n _ ≤ t⁻¹ * (ψ (xk + t • d) - ψ xk - t * gradψ xkm1 d) :=\n mul_le_mul_of_nonneg_left hraw (inv_nonneg.mpr ht0.le)\n _ = t⁻¹ * (ψ (xk + t • d) - ψ xk) - gradψ xkm1 d := by\n rw [mul_sub, ← mul_assoc, inv_mul_cancel₀ ht0.ne', one_mul]\n have hfirst : f xk - f u ≤ gradψ xk d - gradψ xkm1 d :=\n ge_of_tendsto hlim hev\n dsimp [bregmanDual, d] at hfirst ⊢\n simp only [map_sub] at hfirst ⊢\n linarith\n\nprivate theorem subgrad_of_convexOn_hasFDerivAt {F : Type*} [NormedAddCommGroup F]\n [NormedSpace ℝ F] {X : Set F} {g : F → ℝ} {g' : F →L[ℝ] ℝ} {a b : F}\n (hg : ConvexOn ℝ X g) (ha : a ∈ X) (hb : b ∈ X) (hd : HasFDerivAt g g' a) :\n g a + g' (b - a) ≤ g b := by\n have hline : HasDerivAt (fun s : ℝ => a + s • (b - a)) (b - a) 0 := by\n simpa using ((hasDerivAt_id (0 : ℝ)).smul_const (b - a)).const_add a\n have hd' : HasFDerivAt g g' (a + (0 : ℝ) • (b - a)) := by simpa using hd\n have hφ : HasDerivAt (fun s : ℝ => g (a + s • (b - a))) (g' (b - a)) 0 :=\n hd'.comp_hasDerivAt (0 : ℝ) hline\n have ht := hφ.tendsto_slope_zero_right\n have hev : ∀ᶠ s in nhdsWithin (0 : ℝ) (Set.Ioi 0),\n s⁻¹ • (g (a + (0 + s) • (b - a)) - g (a + (0 : ℝ) • (b - a))) ≤ g b - g a := by\n have hIoo : Set.Ioo (0 : ℝ) 1 ∈ nhdsWithin (0 : ℝ) (Set.Ioi 0) :=\n Ioo_mem_nhdsGT (by norm_num)\n filter_upwards [hIoo] with s hs\n obtain ⟨hs0, hs1⟩ := hs\n have hcv := hg.2 ha hb (by linarith : (0 : ℝ) ≤ 1 - s) hs0.le (by ring)\n have heq : (1 - s) • a + s • b = a + s • (b - a) := by\n rw [smul_sub, sub_smul, one_smul]; abel\n rw [heq] at hcv\n simp only [zero_add, zero_smul, add_zero, smul_eq_mul]\n rw [inv_mul_le_iff₀ hs0]\n simp only [smul_eq_mul] at hcv\n nlinarith\n have := le_of_tendsto ht hev\n linarith\n\ntheorem theorem1\n {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F]\n {T : ℕ} (X : Set F)\n (f : ℕ → F → ℝ) (gradf : ℕ → F → (F →L[ℝ] ℝ))\n (ψ : F → ℝ) (gradψ : F → (F →L[ℝ] ℝ))\n (x xhat u : ℕ → F) (M : ℕ → (F →L[ℝ] ℝ)) (η : ℕ → ℝ)\n\n (hXconv : Convex ℝ X)\n\n (hη : ∀ t ∈ Finset.Icc 1 T, 0 < η t)\n\n (hsc : ∀ a ∈ X, ∀ b ∈ X, ψ a + gradψ a (b - a) + (1 / 2) * ‖b - a‖ ^ 2 ≤ ψ b)\n\n (hψgrad : ∀ x ∈ X, HasFDerivAt ψ (gradψ x) x)\n\n (hfconv : ∀ t ∈ Finset.Icc 1 T, ConvexOn ℝ X (f t))\n\n (hfgrad : ∀ t ∈ Finset.Icc 1 T, HasFDerivAt (f t) (gradf t (x t)) (x t))\n\n (hu : ∀ t ∈ Finset.Icc 1 T, u t ∈ X)\n (hxX : ∀ t ∈ Finset.Icc 1 T, x t ∈ X)\n (hxhat1 : xhat 1 ∈ X)\n (hxhatX : ∀ t ∈ Finset.Icc 1 T, xhat (t + 1) ∈ X)\n\n (hx : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n η t * M t (x t) + bregmanDual ψ gradψ (x t) (xhat t)\n ≤ η t * M t z + bregmanDual ψ gradψ z (xhat t))\n\n (hxhat : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n η t * gradf t (x t) (xhat (t + 1)) + bregmanDual ψ gradψ (xhat (t + 1)) (xhat t)\n ≤ η t * gradf t (x t) z + bregmanDual ψ gradψ z (xhat t)) :\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n ≤ (∑ t ∈ Finset.Icc 1 T, η t * ‖gradf t (x t) - M t‖ ^ 2)\n + (∑ t ∈ Finset.Icc 1 T,\n (1 / η t) * (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1))))\n - (∑ t ∈ Finset.Icc 1 T,\n (1 / η t) * (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t))) := by\n have hxhat_cur : ∀ t ∈ Finset.Icc 1 T, xhat t ∈ X := by\n intro t ht\n rw [Finset.mem_Icc] at ht\n rcases eq_or_lt_of_le ht.1 with rfl | htlt\n · exact hxhat1\n · have hp : t - 1 ∈ Finset.Icc 1 T := by\n rw [Finset.mem_Icc]\n omega\n simpa only [Nat.sub_add_cancel (by omega : 1 ≤ t)] using hxhatX (t - 1) hp\n have hpoint : ∀ t ∈ Finset.Icc 1 T,\n f t (x t) - f t (u t)\n ≤ η t * ‖gradf t (x t) - M t‖ ^ 2\n + (1 / η t) * (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1)))\n - (1 / η t) * (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t)) := by\n intro t ht\n have hηt : 0 < η t := hη t ht\n have hxt : x t ∈ X := hxX t ht\n have hut : u t ∈ X := hu t ht\n have hyt : xhat (t + 1) ∈ X := hxhatX t ht\n have hct : xhat t ∈ X := hxhat_cur t ht\n have hconvM : ConvexOn ℝ X (fun z => η t * M t z) := by\n refine ⟨hXconv, ?_⟩\n intro a ha b hb α β hα hβ hab\n simp only [map_add, map_smul, smul_eq_mul]\n ring_nf\n exact le_rfl\n have hconvG : ConvexOn ℝ X (fun z => η t * gradf t (x t) z) := by\n refine ⟨hXconv, ?_⟩\n intro a ha b hb α β hα hβ hab\n simp only [map_add, map_smul, smul_eq_mul]\n ring_nf\n exact le_rfl\n have hpM := bregman_proximal_of_min X (fun z => η t * M t z) ψ gradψ\n (x t) (xhat t) (xhat (t + 1)) hXconv hxt hyt hconvM\n (hψgrad (x t) hxt) (hx t ht)\n have hpGx := bregman_proximal_of_min X\n (fun z => η t * gradf t (x t) z) ψ gradψ\n (xhat (t + 1)) (xhat t) (x t) hXconv hyt hxt hconvG\n (hψgrad (xhat (t + 1)) hyt) (hxhat t ht)\n have hpGu := bregman_proximal_of_min X\n (fun z => η t * gradf t (x t) z) ψ gradψ\n (xhat (t + 1)) (xhat t) (u t) hXconv hyt hut hconvG\n (hψgrad (xhat (t + 1)) hyt) (hxhat t ht)\n have hDyx : (1 / 2 : ℝ) * ‖xhat (t + 1) - x t‖ ^ 2 ≤\n bregmanDual ψ gradψ (xhat (t + 1)) (x t) := by\n have hs := hsc (x t) hxt (xhat (t + 1)) hyt\n rw [bregmanDual]\n linarith\n have hDxy : (1 / 2 : ℝ) * ‖x t - xhat (t + 1)‖ ^ 2 ≤\n bregmanDual ψ gradψ (x t) (xhat (t + 1)) := by\n have hs := hsc (xhat (t + 1)) hyt (x t) hxt\n rw [bregmanDual]\n linarith\n have hDsum : ‖x t - xhat (t + 1)‖ ^ 2 ≤\n bregmanDual ψ gradψ (xhat (t + 1)) (x t) +\n bregmanDual ψ gradψ (x t) (xhat (t + 1)) := by\n rw [norm_sub_rev (xhat (t + 1)) (x t)] at hDyx\n linarith\n have hproxsum :\n bregmanDual ψ gradψ (xhat (t + 1)) (x t) +\n bregmanDual ψ gradψ (x t) (xhat (t + 1))\n ≤ η t * ((gradf t (x t) - M t) (x t - xhat (t + 1))) := by\n simp only [ContinuousLinearMap.sub_apply, map_sub]\n linarith\n have hdistsq : ‖x t - xhat (t + 1)‖ ^ 2 ≤\n η t * ((gradf t (x t) - M t) (x t - xhat (t + 1))) :=\n hDsum.trans hproxsum\n have hdual : (gradf t (x t) - M t) (x t - xhat (t + 1)) ≤\n ‖gradf t (x t) - M t‖ * ‖x t - xhat (t + 1)‖ :=\n (Real.le_norm_self _).trans ((gradf t (x t) - M t).le_opNorm _)\n have hstab : ‖x t - xhat (t + 1)‖ ≤\n η t * ‖gradf t (x t) - M t‖ := by\n by_cases hz : ‖x t - xhat (t + 1)‖ = 0\n · rw [hz]\n exact mul_nonneg hηt.le (norm_nonneg _)\n · have hzpos : 0 < ‖x t - xhat (t + 1)‖ :=\n lt_of_le_of_ne (norm_nonneg _) (Ne.symm hz)\n have hmul : ‖x t - xhat (t + 1)‖ ^ 2 ≤\n η t * (‖gradf t (x t) - M t‖ * ‖x t - xhat (t + 1)‖) :=\n hdistsq.trans (mul_le_mul_of_nonneg_left hdual hηt.le)\n have hmul' : ‖x t - xhat (t + 1)‖ * ‖x t - xhat (t + 1)‖ ≤\n (η t * ‖gradf t (x t) - M t‖) * ‖x t - xhat (t + 1)‖ := by\n simpa only [pow_two, mul_assoc] using hmul\n exact le_of_mul_le_mul_right hmul' hzpos\n have htermA : (gradf t (x t) - M t) (x t - xhat (t + 1)) ≤\n η t * ‖gradf t (x t) - M t‖ ^ 2 := by\n calc\n (gradf t (x t) - M t) (x t - xhat (t + 1))\n ≤ ‖gradf t (x t) - M t‖ * ‖x t - xhat (t + 1)‖ := hdual\n _ ≤ ‖gradf t (x t) - M t‖ *\n (η t * ‖gradf t (x t) - M t‖) :=\n mul_le_mul_of_nonneg_left hstab (norm_nonneg _)\n _ = η t * ‖gradf t (x t) - M t‖ ^ 2 := by ring\n have hscaled : η t *\n (M t (x t - xhat (t + 1)) +\n gradf t (x t) (xhat (t + 1) - u t)) ≤\n bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1))\n - bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n - bregmanDual ψ gradψ (x t) (xhat t) := by\n simp only [map_sub]\n linarith\n have hbc :\n M t (x t - xhat (t + 1)) +\n gradf t (x t) (xhat (t + 1) - u t)\n ≤ (1 / η t) *\n (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1)))\n - (1 / η t) *\n (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t)) := by\n calc\n M t (x t - xhat (t + 1)) + gradf t (x t) (xhat (t + 1) - u t)\n = (1 / η t) * (η t *\n (M t (x t - xhat (t + 1)) +\n gradf t (x t) (xhat (t + 1) - u t))) := by\n field_simp\n _ ≤ (1 / η t) *\n (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1))\n - bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n - bregmanDual ψ gradψ (x t) (xhat t)) :=\n mul_le_mul_of_nonneg_left hscaled (one_div_pos.mpr hηt).le\n _ = (1 / η t) *\n (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1)))\n - (1 / η t) *\n (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t)) := by ring\n have hreg : f t (x t) - f t (u t) ≤ gradf t (x t) (x t - u t) := by\n have hc := subgrad_of_convexOn_hasFDerivAt (hfconv t ht) hxt hut (hfgrad t ht)\n simp only [map_sub] at hc ⊢\n linarith\n calc\n f t (x t) - f t (u t) ≤ gradf t (x t) (x t - u t) := hreg\n _ = (gradf t (x t) - M t) (x t - xhat (t + 1))\n + (M t (x t - xhat (t + 1))\n + gradf t (x t) (xhat (t + 1) - u t)) := by\n simp only [ContinuousLinearMap.sub_apply, map_sub]\n ring\n _ ≤ η t * ‖gradf t (x t) - M t‖ ^ 2\n + ((1 / η t) *\n (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1)))\n - (1 / η t) *\n (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t))) :=\n add_le_add htermA hbc\n _ = η t * ‖gradf t (x t) - M t‖ ^ 2\n + (1 / η t) * (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1)))\n - (1 / η t) * (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t)) := by ring\n calc\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n = ∑ t ∈ Finset.Icc 1 T, (f t (x t) - f t (u t)) := by\n rw [Finset.sum_sub_distrib]\n _ ≤ ∑ t ∈ Finset.Icc 1 T,\n (η t * ‖gradf t (x t) - M t‖ ^ 2\n + (1 / η t) * (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1)))\n - (1 / η t) * (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t))) :=\n Finset.sum_le_sum hpoint\n _ = (∑ t ∈ Finset.Icc 1 T, η t * ‖gradf t (x t) - M t‖ ^ 2)\n + (∑ t ∈ Finset.Icc 1 T,\n (1 / η t) * (bregmanDual ψ gradψ (u t) (xhat t)\n - bregmanDual ψ gradψ (u t) (xhat (t + 1))))\n - (∑ t ∈ Finset.Icc 1 T,\n (1 / η t) * (bregmanDual ψ gradψ (xhat (t + 1)) (x t)\n + bregmanDual ψ gradψ (x t) (xhat t))) := by\n rw [Finset.sum_sub_distrib, Finset.sum_add_distrib]\n\ntheorem lemma4_bregmanProximal\n {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F]\n (X : Set F) (f ψ : F → ℝ) (gradψ : F → (F →L[ℝ] ℝ))\n (xk xkm1 u : F)\n\n (hXconv : Convex ℝ X)\n (hxkX : xk ∈ X) (hxkm1X : xkm1 ∈ X) (huX : u ∈ X)\n\n (hfconv : ConvexOn ℝ X f)\n (hflsc : LowerSemicontinuousOn f X)\n\n (hψconv : ConvexOn ℝ X ψ)\n\n (hψgrad : HasFDerivAt ψ (gradψ xk) xk)\n (hψgrad' : HasFDerivAt ψ (gradψ xkm1) xkm1)\n\n (hprox : ∀ z ∈ X,\n f xk + bregmanDual ψ gradψ xk xkm1 ≤ f z + bregmanDual ψ gradψ z xkm1) :\n f xk - f u\n ≤ bregmanDual ψ gradψ u xkm1 - bregmanDual ψ gradψ u xk\n - bregmanDual ψ gradψ xk xkm1 := by\n let d : F := u - xk\n have hlim : Filter.Tendsto\n (fun t : ℝ => t⁻¹ • (ψ (xk + t • d) - ψ xk) - gradψ xkm1 d)\n (nhdsWithin 0 (Set.Ioi 0))\n (nhds (gradψ xk d - gradψ xkm1 d)) :=\n (hψgrad.hasLineDerivAt d).tendsto_slope_zero_right.sub_const _\n have hev : ∀ᶠ t : ℝ in nhdsWithin 0 (Set.Ioi 0),\n f xk - f u ≤ t⁻¹ • (ψ (xk + t • d) - ψ xk) - gradψ xkm1 d := by\n filter_upwards [self_mem_nhdsWithin,\n (eventually_lt_nhds (show (0 : ℝ) < 1 by norm_num)).filter_mono inf_le_left]\n with t htpos htone\n have ht0 : 0 < t := htpos\n have ht1 : t ≤ 1 := le_of_lt htone\n have hzEq : xk + t • d = (1 - t) • xk + t • u := by\n dsimp [d]\n module\n have hzX : xk + t • d ∈ X := by\n rw [hzEq]\n exact hXconv hxkX huX (sub_nonneg.mpr ht1) ht0.le (by ring)\n have hfline : f (xk + t • d) ≤ (1 - t) * f xk + t * f u := by\n rw [hzEq]\n simpa only [smul_eq_mul] using\n hfconv.2 hxkX huX (sub_nonneg.mpr ht1) ht0.le (by ring)\n have hp := hprox (xk + t • d) hzX\n have hlin : gradψ xkm1 (xk + t • d - xkm1) =\n gradψ xkm1 (xk - xkm1) + t * gradψ xkm1 d := by\n have harg : xk + t • d - xkm1 = (xk - xkm1) + t • d := by module\n rw [harg, map_add, map_smul, smul_eq_mul]\n rw [bregmanDual, bregmanDual, hlin] at hp\n have hraw : t * (f xk - f u) ≤\n ψ (xk + t • d) - ψ xk - t * gradψ xkm1 d := by\n linarith\n simp only [smul_eq_mul]\n calc\n f xk - f u = t⁻¹ * (t * (f xk - f u)) := by\n rw [← mul_assoc, inv_mul_cancel₀ ht0.ne', one_mul]\n _ ≤ t⁻¹ * (ψ (xk + t • d) - ψ xk - t * gradψ xkm1 d) :=\n mul_le_mul_of_nonneg_left hraw (inv_nonneg.mpr ht0.le)\n _ = t⁻¹ * (ψ (xk + t • d) - ψ xk) - gradψ xkm1 d := by\n rw [mul_sub, ← mul_assoc, inv_mul_cancel₀ ht0.ne', one_mul]\n have hfirst : f xk - f u ≤ gradψ xk d - gradψ xkm1 d :=\n ge_of_tendsto hlim hev\n dsimp [bregmanDual, d] at hfirst ⊢\n simp only [map_sub] at hfirst ⊢\n linarith\n\nprivate theorem bregmanDual_normSq (a b : E) :\n bregmanDual (fun z : E => (1 / 2 : ℝ) * ‖z‖ ^ 2)\n (fun z => innerSL ℝ z) a b = (1 / 2 : ℝ) * ‖a - b‖ ^ 2 := by\n rw [bregmanDual, innerSL_apply_apply, norm_sub_sq_real]\n simp only [inner_sub_right, real_inner_self_eq_norm_sq]\n rw [real_inner_comm b a]\n ring\n\nprivate theorem hasFDerivAt_half_normSq (z : E) :\n HasFDerivAt (fun z : E => (1 / 2 : ℝ) * ‖z‖ ^ 2) (innerSL ℝ z) z := by\n convert (hasStrictFDerivAt_norm_sq z).hasFDerivAt.const_mul (1 / 2 : ℝ) using 1\n ext v\n simp [innerSL_apply_apply]\n\nprivate theorem norm_innerSL_sub (a b : E) :\n ‖innerSL ℝ a - innerSL ℝ b‖ = ‖a - b‖ := by\n rw [← (innerSL ℝ).map_sub, innerSL_apply_norm]\n\nprivate theorem norm_add_sq_le_two (a b : E) :\n ‖a + b‖ ^ 2 ≤ 2 * (‖a‖ ^ 2 + ‖b‖ ^ 2) := by\n have hadd := norm_add_le a b\n have hsquare : ‖a + b‖ ^ 2 ≤ (‖a‖ + ‖b‖) ^ 2 :=\n (sq_le_sq₀ (norm_nonneg _) (add_nonneg (norm_nonneg _) (norm_nonneg _))).2 hadd\n nlinarith [sq_nonneg (‖a‖ - ‖b‖)]\n\ntheorem lemma1_OEGD\n {T : ℕ} (X : Set E)\n (f : ℕ → E → ℝ) (gradf : ℕ → E → E)\n (x xhat u : ℕ → E) (η G D L : ℝ)\n (hη : 0 < η) (hL : 0 < L) (hηL : η ≤ 1 / (4 * L))\n (hXne : X.Nonempty)\n\n (hXconv : Convex ℝ X)\n\n (hG : ∀ t, ∀ a ∈ X, ‖gradf t a‖ ≤ G)\n (hgrad0 : ∀ a, gradf 0 a = 0)\n\n (h0X : (0 : E) ∈ X) (hD : ∀ a ∈ X, ∀ b ∈ X, ‖a - b‖ ≤ D)\n\n (hsmooth : ∀ t, ∀ a b, ‖gradf t a - gradf t b‖ ≤ L * ‖a - b‖)\n\n (hconv : ∀ t ∈ Finset.Icc 1 T, ∀ a ∈ X, ∀ b ∈ X,\n f t a + ⟪gradf t a, b - a⟫ ≤ f t b)\n\n (hfgrad : ∀ t ∈ Finset.Icc 1 T, ∀ a, HasGradientAt (f t) (gradf t a) a)\n\n (hu : ∀ t ∈ Finset.Icc 1 T, u t ∈ X)\n\n (hxX : ∀ t ∈ Finset.Icc 1 T, x t ∈ X)\n (hxhat1 : xhat 1 ∈ X)\n (hxhatX : ∀ t ∈ Finset.Icc 1 T, xhat (t + 1) ∈ X)\n\n (hx : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n (1 / 2) * ‖x t - xhat t‖ ^ 2 + η * ⟪gradf (t - 1) (x (t - 1)), x t⟫\n ≤ (1 / 2) * ‖z - xhat t‖ ^ 2 + η * ⟪gradf (t - 1) (x (t - 1)), z⟫)\n\n (hxhat : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n (1 / 2) * ‖xhat (t + 1) - xhat t‖ ^ 2 + η * ⟪gradf t (x t), xhat (t + 1)⟫\n ≤ (1 / 2) * ‖z - xhat t‖ ^ 2 + η * ⟪gradf t (x t), z⟫) :\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n ≤ η * (G ^ 2 + 2 * gradVarSup X gradf T)\n + (1 / (2 * η)) * (D ^ 2 + 2 * D * pathLength u T) := by\n let gd : ℕ → E → (E →L[ℝ] ℝ) := fun t z => innerSL ℝ (gradf t z)\n let gψ : E → (E →L[ℝ] ℝ) := fun z => innerSL ℝ z\n let ψq : E → ℝ := fun z => (1 / 2 : ℝ) * ‖z‖ ^ 2\n let md : ℕ → (E →L[ℝ] ℝ) :=\n fun t => innerSL ℝ (gradf (t - 1) (x (t - 1)))\n let ηc : ℕ → ℝ := fun _ => η\n have hηc : ∀ t ∈ Finset.Icc 1 T, 0 < ηc t := by\n intro t ht\n exact hη\n have hscq : ∀ a ∈ X, ∀ b ∈ X,\n ψq a + gψ a (b - a) + (1 / 2) * ‖b - a‖ ^ 2 ≤ ψq b := by\n intro a ha b hb\n change (1 / 2 : ℝ) * ‖a‖ ^ 2 + (innerSL ℝ a) (b - a) +\n (1 / 2 : ℝ) * ‖b - a‖ ^ 2 ≤ (1 / 2 : ℝ) * ‖b‖ ^ 2\n apply le_of_eq\n rw [innerSL_apply_apply, norm_sub_sq_real]\n simp only [inner_sub_right, real_inner_self_eq_norm_sq]\n rw [real_inner_comm a b]\n ring\n have hψqgrad : ∀ z ∈ X, HasFDerivAt ψq (gψ z) z := by\n intro z hz\n exact hasFDerivAt_half_normSq z\n have hconvd : ∀ t ∈ Finset.Icc 1 T, ∀ a ∈ X, ∀ b ∈ X,\n f t a + gd t a (b - a) ≤ f t b := by\n intro t ht a ha b hb\n simpa only [gd, innerSL_apply_apply] using hconv t ht a ha b hb\n have hxd : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n ηc t * md t (x t) + bregmanDual ψq gψ (x t) (xhat t) ≤\n ηc t * md t z + bregmanDual ψq gψ z (xhat t) := by\n intro t ht z hz\n simpa only [ηc, md, ψq, gψ, innerSL_apply_apply, bregmanDual_normSq,\n add_comm] using hx t ht z hz\n have hxhatd : ∀ t ∈ Finset.Icc 1 T, ∀ z ∈ X,\n ηc t * gd t (x t) (xhat (t + 1)) +\n bregmanDual ψq gψ (xhat (t + 1)) (xhat t) ≤\n ηc t * gd t (x t) z + bregmanDual ψq gψ z (xhat t) := by\n intro t ht z hz\n simpa only [ηc, gd, ψq, gψ, innerSL_apply_apply, bregmanDual_normSq,\n add_comm] using hxhat t ht z hz\n have hfgradd : ∀ t ∈ Finset.Icc 1 T, HasFDerivAt (f t) (gd t (x t)) (x t) :=\n fun t ht => (hfgrad t ht (x t)).hasFDerivAt\n have hfconvd : ∀ t ∈ Finset.Icc 1 T, ConvexOn ℝ X (f t) := by\n intro t ht\n refine ⟨hXconv, ?_⟩\n intro a ha b hb θ φ hθ hφ hθφ\n have hc : θ • a + φ • b ∈ X := hXconv ha hb hθ hφ hθφ\n have h1 := hconvd t ht _ hc a ha\n have h2 := hconvd t ht _ hc b hb\n have hlin : θ * gd t (θ • a + φ • b) (a - (θ • a + φ • b))\n + φ * gd t (θ • a + φ • b) (b - (θ • a + φ • b)) = 0 := by\n have hv : θ • (a - (θ • a + φ • b)) + φ • (b - (θ • a + φ • b)) = 0 := by\n calc θ • (a - (θ • a + φ • b)) + φ • (b - (θ • a + φ • b))\n = (θ • a + φ • b) - (θ + φ) • (θ • a + φ • b) := by\n rw [smul_sub, smul_sub, add_smul]; abel\n _ = 0 := by rw [hθφ, one_smul, sub_self]\n have := congrArg (gd t (θ • a + φ • b)) hv\n rw [map_add, map_smul, map_smul, map_zero, smul_eq_mul, smul_eq_mul] at this\n exact this\n simp only [smul_eq_mul]\n have hsplit : f t (θ • a + φ • b) = θ * f t (θ • a + φ • b) + φ * f t (θ • a + φ • b) := by\n rw [← add_mul, hθφ, one_mul]\n nlinarith [mul_le_mul_of_nonneg_left h1 hθ, mul_le_mul_of_nonneg_left h2 hφ]\n have hconvp : ∀ t ∈ Finset.Icc 1 T, ∀ b ∈ X,\n f t (x t) + gd t (x t) (b - x t) ≤ f t b :=\n fun t ht b hb => hconvd t ht (x t) (hxX t ht) b hb\n have hmain := theorem1 (T := T) X f gd ψq gψ x xhat u md ηc\n hXconv hηc hscq hψqgrad hfconvd hfgradd hu hxX hxhat1 hxhatX hxd hxhatd\n simp only [ηc, gd, md, ψq, gψ, norm_innerSL_sub, bregmanDual_normSq] at hmain\n obtain ⟨x₀, hx₀⟩ := hXne\n have hG0 : 0 ≤ G := (norm_nonneg (gradf 0 x₀)).trans (hG 0 x₀ hx₀)\n have hD0 : 0 ≤ D := by\n have hd0 := hD 0 h0X 0 h0X\n simpa using hd0\n have hadapt : ∀ n ≤ T,\n (∑ t ∈ Finset.Icc 1 n,\n ‖gradf t (x t) - gradf (t - 1) (x (t - 1))‖ ^ 2)\n ≤ G ^ 2 + 2 * gradVarSup X gradf n\n + 2 * L ^ 2 * (∑ t ∈ Finset.Icc 2 n, ‖x t - x (t - 1)‖ ^ 2) := by\n intro n\n induction n with\n | zero =>\n intro hn\n simp [gradVarSup]\n positivity\n | succ n ih =>\n intro hn\n by_cases hn0 : n = 0\n · subst n\n have hx1 : x 1 ∈ X := hxX 1 (by\n rw [Finset.mem_Icc]\n omega)\n have hg1 := hG 1 (x 1) hx1\n have hg1sq : ‖gradf 1 (x 1)‖ ^ 2 ≤ G ^ 2 :=\n (sq_le_sq₀ (norm_nonneg _) hG0).2 hg1\n simpa [gradVarSup, hgrad0] using hg1sq\n · have hnpos : 1 ≤ n := by omega\n have ihn := ih (by omega)\n have hxn1 : x (n + 1) ∈ X := hxX (n + 1) (by\n rw [Finset.mem_Icc]\n omega)\n let qvar : X → ℝ := fun z =>\n ‖gradf (n + 1) (z : E) - gradf n (z : E)‖ ^ 2\n have hqvar_bdd : BddAbove (Set.range qvar) := by\n refine ⟨(2 * G) ^ 2, ?_⟩\n rintro y ⟨z, rfl⟩\n have hdiff : ‖gradf (n + 1) (z : E) - gradf n (z : E)‖ ≤ 2 * G := by\n calc\n ‖gradf (n + 1) (z : E) - gradf n (z : E)‖\n ≤ ‖gradf (n + 1) (z : E)‖ + ‖gradf n (z : E)‖ := norm_sub_le _ _\n _ ≤ G + G := add_le_add (hG (n + 1) z z.property) (hG n z z.property)\n _ = 2 * G := by ring\n exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg (by norm_num) hG0)).2 hdiff\n have hvar :\n ‖gradf (n + 1) (x (n + 1)) - gradf n (x (n + 1))‖ ^ 2\n ≤ ⨆ z : X, ‖gradf (n + 1) (z : E) - gradf n (z : E)‖ ^ 2 := by\n exact le_ciSup hqvar_bdd ⟨x (n + 1), hxn1⟩\n have hs0 := hsmooth n (x (n + 1)) (x n)\n have hsm : ‖gradf n (x (n + 1)) - gradf n (x n)‖ ^ 2\n ≤ L ^ 2 * ‖x (n + 1) - x n‖ ^ 2 := by\n have hs0sq := (sq_le_sq₀ (norm_nonneg _)\n (mul_nonneg hL.le (norm_nonneg _))).2 hs0\n nlinarith\n have hdec :\n gradf (n + 1) (x (n + 1)) - gradf n (x n) =\n (gradf (n + 1) (x (n + 1)) - gradf n (x (n + 1))) +\n (gradf n (x (n + 1)) - gradf n (x n)) := by abel\n have hnew :\n ‖gradf (n + 1) (x (n + 1)) - gradf n (x n)‖ ^ 2\n ≤ 2 * (⨆ z : X,\n ‖gradf (n + 1) (z : E) - gradf n (z : E)‖ ^ 2)\n + 2 * L ^ 2 * ‖x (n + 1) - x n‖ ^ 2 := by\n rw [hdec]\n calc\n ‖(gradf (n + 1) (x (n + 1)) - gradf n (x (n + 1))) +\n (gradf n (x (n + 1)) - gradf n (x n))‖ ^ 2\n ≤ 2 * (‖gradf (n + 1) (x (n + 1)) - gradf n (x (n + 1))‖ ^ 2\n + ‖gradf n (x (n + 1)) - gradf n (x n)‖ ^ 2) :=\n norm_add_sq_le_two _ _\n _ ≤ 2 * ((⨆ z : X,\n ‖gradf (n + 1) (z : E) - gradf n (z : E)‖ ^ 2)\n + L ^ 2 * ‖x (n + 1) - x n‖ ^ 2) := by\n gcongr\n _ = 2 * (⨆ z : X,\n ‖gradf (n + 1) (z : E) - gradf n (z : E)‖ ^ 2)\n + 2 * L ^ 2 * ‖x (n + 1) - x n‖ ^ 2 := by ring\n have hIcc1 : Finset.Icc 1 (n + 1) =\n insert (n + 1) (Finset.Icc 1 n) := by\n ext k\n simp\n omega\n have hIcc2 : Finset.Icc 2 (n + 1) =\n insert (n + 1) (Finset.Icc 2 n) := by\n ext k\n simp\n omega\n have hnmem1 : n + 1 ∉ Finset.Icc 1 n := by simp\n have hnmem2 : n + 1 ∉ Finset.Icc 2 n := by simp\n rw [hIcc1, Finset.sum_insert hnmem1, gradVarSup, hIcc2,\n Finset.sum_insert hnmem2, Finset.sum_insert hnmem2]\n rw [gradVarSup] at ihn\n simp only [Nat.add_sub_cancel] \n linarith\n have hcomp_strong : ∀ n, 1 ≤ n → n ≤ T →\n (∑ t ∈ Finset.Icc 1 n,\n (‖u t - xhat t‖ ^ 2 - ‖u t - xhat (t + 1)‖ ^ 2))\n ≤ D ^ 2 + 2 * D * pathLength u n - ‖u n - xhat (n + 1)‖ ^ 2 := by\n intro n\n induction n with\n | zero =>\n intro hn\n omega\n | succ n ih =>\n intro hn1 hnT\n by_cases hn0 : n = 0\n · subst n\n have hu1 : u 1 ∈ X := hu 1 (by\n rw [Finset.mem_Icc]\n omega)\n have hd1 := hD (u 1) hu1 (xhat 1) hxhat1\n have hd1sq : ‖u 1 - xhat 1‖ ^ 2 ≤ D ^ 2 :=\n (sq_le_sq₀ (norm_nonneg _) hD0).2 hd1\n simpa [pathLength] using\n sub_le_sub_right hd1sq (‖u 1 - xhat 2‖ ^ 2)\n · have hnpos : 1 ≤ n := by omega\n have ihn := ih hnpos (by omega)\n have hun : u n ∈ X := hu n (by\n rw [Finset.mem_Icc]\n omega)\n have hun1 : u (n + 1) ∈ X := hu (n + 1) (by\n rw [Finset.mem_Icc]\n omega)\n have hchat : xhat (n + 1) ∈ X := hxhatX n (by\n rw [Finset.mem_Icc]\n omega)\n have hdistn := hD (u n) hun (xhat (n + 1)) hchat\n have hdistn1 := hD (u (n + 1)) hun1 (xhat (n + 1)) hchat\n have hnormdiff :\n ‖u (n + 1) - xhat (n + 1)‖ - ‖u n - xhat (n + 1)‖\n ≤ ‖u (n + 1) - u n‖ := by\n have hh := norm_sub_norm_le\n (u (n + 1) - xhat (n + 1)) (u n - xhat (n + 1))\n convert hh using 1\n abel\n have hdiffsq :\n ‖u (n + 1) - xhat (n + 1)‖ ^ 2 -\n ‖u n - xhat (n + 1)‖ ^ 2\n ≤ 2 * D * ‖u (n + 1) - u n‖ := by\n calc\n ‖u (n + 1) - xhat (n + 1)‖ ^ 2 -\n ‖u n - xhat (n + 1)‖ ^ 2\n = (‖u (n + 1) - xhat (n + 1)‖ -\n ‖u n - xhat (n + 1)‖) *\n (‖u (n + 1) - xhat (n + 1)‖ +\n ‖u n - xhat (n + 1)‖) := by ring\n _ ≤ ‖u (n + 1) - u n‖ *\n (‖u (n + 1) - xhat (n + 1)‖ +\n ‖u n - xhat (n + 1)‖) :=\n mul_le_mul_of_nonneg_right hnormdiff\n (add_nonneg (norm_nonneg _) (norm_nonneg _))\n _ ≤ ‖u (n + 1) - u n‖ * (2 * D) := by\n gcongr\n linarith\n _ = 2 * D * ‖u (n + 1) - u n‖ := by ring\n have hIcc1 : Finset.Icc 1 (n + 1) =\n insert (n + 1) (Finset.Icc 1 n) := by\n ext k\n simp\n omega\n have hIcc2 : Finset.Icc 2 (n + 1) =\n insert (n + 1) (Finset.Icc 2 n) := by\n ext k\n simp\n omega\n have hnmem1 : n + 1 ∉ Finset.Icc 1 n := by simp\n have hnmem2 : n + 1 ∉ Finset.Icc 2 n := by simp\n rw [hIcc1, Finset.sum_insert hnmem1, pathLength, hIcc2,\n Finset.sum_insert hnmem2]\n rw [pathLength] at ihn\n simp only [Nat.add_sub_cancel]\n linarith\n have hnegative_strong : ∀ n, 1 ≤ n → n ≤ T →\n (1 / 2 : ℝ) * (∑ t ∈ Finset.Icc 2 n, ‖x t - x (t - 1)‖ ^ 2)\n + ‖xhat (n + 1) - x n‖ ^ 2\n ≤ ∑ t ∈ Finset.Icc 1 n,\n (‖xhat (t + 1) - x t‖ ^ 2 + ‖x t - xhat t‖ ^ 2) := by\n intro n\n induction n with\n | zero =>\n intro hn\n omega\n | succ n ih =>\n intro hn1 hnT\n by_cases hn0 : n = 0\n · subst n\n simpa using sq_nonneg ‖x 1 - xhat 1‖\n · have hnpos : 1 ≤ n := by omega\n have ihn := ih hnpos (by omega)\n have hdecomp : x (n + 1) - x n =\n (x (n + 1) - xhat (n + 1)) + (xhat (n + 1) - x n) := by abel\n have hpairsq : ‖x (n + 1) - x n‖ ^ 2 ≤\n 2 * (‖x (n + 1) - xhat (n + 1)‖ ^ 2 +\n ‖xhat (n + 1) - x n‖ ^ 2) := by\n rw [hdecomp]\n exact norm_add_sq_le_two _ _\n have hpair : (1 / 2 : ℝ) * ‖x (n + 1) - x n‖ ^ 2 ≤\n ‖xhat (n + 1) - x n‖ ^ 2 +\n ‖x (n + 1) - xhat (n + 1)‖ ^ 2 := by\n linarith\n have hIcc1 : Finset.Icc 1 (n + 1) =\n insert (n + 1) (Finset.Icc 1 n) := by\n ext k\n simp\n omega\n have hIcc2 : Finset.Icc 2 (n + 1) =\n insert (n + 1) (Finset.Icc 2 n) := by\n ext k\n simp\n omega\n have hnmem1 : n + 1 ∉ Finset.Icc 1 n := by simp\n have hnmem2 : n + 1 ∉ Finset.Icc 2 n := by simp\n rw [hIcc1, Finset.sum_insert hnmem1, hIcc2, Finset.sum_insert hnmem2]\n simp only [Nat.add_sub_cancel]\n linarith\n have hcoef_sub (a b : ℝ) :\n (1 / η) * ((1 / 2) * a - (1 / 2) * b) =\n (1 / (2 * η)) * (a - b) := by\n field_simp\n <;> ring\n have hcoef_add (a b : ℝ) :\n (1 / η) * ((1 / 2) * a + (1 / 2) * b) =\n (1 / (2 * η)) * (a + b) := by\n field_simp\n <;> ring\n have hmain' :\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n ≤ η * (∑ t ∈ Finset.Icc 1 T,\n ‖gradf t (x t) - gradf (t - 1) (x (t - 1))‖ ^ 2)\n + (1 / (2 * η)) * (∑ t ∈ Finset.Icc 1 T,\n (‖u t - xhat t‖ ^ 2 - ‖u t - xhat (t + 1)‖ ^ 2))\n - (1 / (2 * η)) * (∑ t ∈ Finset.Icc 1 T,\n (‖xhat (t + 1) - x t‖ ^ 2 + ‖x t - xhat t‖ ^ 2)) := by\n simp_rw [hcoef_sub, hcoef_add] at hmain\n rw [← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum] at hmain\n exact hmain\n by_cases hTzero : T = 0\n · subst T\n simp [gradVarSup, pathLength]\n positivity\n · have hTone : 1 ≤ T := Nat.one_le_iff_ne_zero.mpr hTzero\n have ha := hadapt T le_rfl\n have hbstrong := hcomp_strong T hTone le_rfl\n have hb :\n (∑ t ∈ Finset.Icc 1 T,\n (‖u t - xhat t‖ ^ 2 - ‖u t - xhat (t + 1)‖ ^ 2))\n ≤ D ^ 2 + 2 * D * pathLength u T := by\n linarith [sq_nonneg ‖u T - xhat (T + 1)‖]\n have hcstrong := hnegative_strong T hTone le_rfl\n have hc :\n (1 / 2 : ℝ) * (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2)\n ≤ ∑ t ∈ Finset.Icc 1 T,\n (‖xhat (t + 1) - x t‖ ^ 2 + ‖x t - xhat t‖ ^ 2) := by\n linarith [sq_nonneg ‖xhat (T + 1) - x T‖]\n have hetaA := mul_le_mul_of_nonneg_left ha hη.le\n have hweight0 : 0 ≤ (1 / (2 * η) : ℝ) :=\n (one_div_pos.mpr (mul_pos (by norm_num) hη)).le\n have hweightB := mul_le_mul_of_nonneg_left hb hweight0\n have hweightC := mul_le_mul_of_nonneg_left hc hweight0\n have hpre :\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n ≤ η * (G ^ 2 + 2 * gradVarSup X gradf T\n + 2 * L ^ 2 * (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2))\n + (1 / (2 * η)) * (D ^ 2 + 2 * D * pathLength u T)\n - (1 / (2 * η)) *\n ((1 / 2) * (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2)) := by\n linarith\n have hdenL : 0 < 4 * L := mul_pos (by norm_num) hL\n have hprod : η * (4 * L) ≤ 1 := (le_div_iff₀ hdenL).mp hηL\n have hprod0 : 0 ≤ η * (4 * L) := mul_nonneg hη.le hdenL.le\n have hprodsq : (η * (4 * L)) ^ 2 ≤ (1 : ℝ) ^ 2 :=\n (sq_le_sq₀ hprod0 zero_le_one).2 hprod\n have hcoefmove : 2 * η * L ^ 2 ≤ 1 / (4 * η) := by\n apply (le_div_iff₀ (mul_pos (by norm_num) hη)).2\n nlinarith [sq_nonneg (η * L)]\n have hsum0 : 0 ≤ ∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2 := by\n exact Finset.sum_nonneg fun i hi => sq_nonneg _\n have hmovement := mul_le_mul_of_nonneg_right hcoefmove hsum0\n have hfrac :\n (1 / (2 * η)) *\n ((1 / 2) * (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2)) =\n (1 / (4 * η)) * (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2) := by\n field_simp\n <;> ring\n calc\n (∑ t ∈ Finset.Icc 1 T, f t (x t)) - (∑ t ∈ Finset.Icc 1 T, f t (u t))\n ≤ η * (G ^ 2 + 2 * gradVarSup X gradf T\n + 2 * L ^ 2 * (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2))\n + (1 / (2 * η)) * (D ^ 2 + 2 * D * pathLength u T)\n - (1 / (2 * η)) *\n ((1 / 2) * (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2)) := hpre\n _ = η * (G ^ 2 + 2 * gradVarSup X gradf T)\n + (1 / (2 * η)) * (D ^ 2 + 2 * D * pathLength u T)\n + ((2 * η * L ^ 2) *\n (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2)\n - (1 / (4 * η)) *\n (∑ t ∈ Finset.Icc 2 T, ‖x t - x (t - 1)‖ ^ 2)) := by\n rw [hfrac]\n ring\n _ ≤ η * (G ^ 2 + 2 * gradVarSup X gradf T)\n + (1 / (2 * η)) * (D ^ 2 + 2 * D * pathLength u T) := by\n linarith\n\n\nend ResearchLevel\n"} +{"id": "v24-21-1250", "source": "Research-level", "targets": [{"label": "Theorem 4", "decls": ["strategic_agnostic_PAC"], "statement": "Theorem 4 Any strategic classification instance $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ is agnostic PAC learnable with sample complexity $m_{\\mathcal{H},R,c}(\\delta,\\epsilon)\\leq C\\epsilon^{-2}[d+\\log(\\frac{1}{\\delta})]$ by the SERM in Eq. (4), where $d=SVC(\\mathcal{H},R,c)$ is the strategic VC-dimension and $C$ is an absolute constant.", "context_ids": ["v24-21-1250:ctx1", "v24-21-1250:ctx2", "v24-21-1250:ctx3", "v24-21-1250:ctx4", "v24-21-1250:ctx5", "v24-21-1250:ctx6", "v24-21-1250:ctx7", "v24-21-1250:ctx8"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}, {"label": "Proposition 9", "decls": ["separable_SVC_le_two"], "statement": "Proposition 9 For any hypothesis class H, any preference set R satisfying $0\\notin R,$ and any separable cost function $c(z;\\pmb{x})$ , we have $SVC(\\mathcal{H},R,c)\\leq 2$", "context_ids": ["v24-21-1250:ctx1", "v24-21-1250:ctx2", "v24-21-1250:ctx3", "v24-21-1250:ctx4", "v24-21-1250:ctx5", "v24-21-1250:ctx6", "v24-21-1250:ctx9", "v24-21-1250:ctx10"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}, {"label": "Lemma 12", "decls": ["min_manipulation_cost_lower_bound"], "statement": "Lemma 12 For any seminorm $l : \\mathbb{R}^{d}\\to \\mathbb{R}_{\\ge 0}$ , and the cost function $c ({\\boldsymbol{z}};{\\pmb x}) = l ({\\boldsymbol{z}}-{\\pmb x})$ induced by l, the minimum manipulation cost for x to move to the hyperplane ${\\pmb w}\\cdot{\\pmb x}+ b = 0$ is given by the following:\n\n$$\n\\operatorname*{min}_{{\\pmb x}^{\\prime}}\\{c({\\pmb x}^{\\prime};{\\pmb x}):{\\pmb w}\\cdot{\\pmb x}^{\\prime}+b=0\\}=\\frac{|{\\pmb w}\\cdot{\\pmb x}+b|}{l^{*}({\\pmb w})}\n$$\n\nwhere $\\begin{array}{r}{l^{\\ast}(\\pmb{w})=\\operatorname*{sup}_{z\\in{\\cal B}}\\{\\pmb{w}\\cdot z\\}\\in\\mathbb{R}_{\\ge 0}\\cup\\{+\\infty\\}}\\end{array}$ , and $B=\\{z:l(z)\\leq 1\\}$ is the unit ball induced by l. Assume $l^{*}(\\pmb{w})>0$; when $l^{*}(\\pmb{w})= +\\infty$ the right-hand side is read as $0$.", "context_ids": ["v24-21-1250:ctx2", "v24-21-1250:ctx11", "v24-21-1250:ctx12", "v24-21-1250:ctx13"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}], "nl_proof": "### Proof of Theorem 4\n\nProof Let $\\mathcal{Y}=\\{+1,-1\\}$ . Define another binary hypothesis class $\\tilde{H}~=~\\{\\kappa_{c}(h)~:~h~\\in$ $H \\}$ , where $\\kappa_{c}~ : ~ ({\\mathcal X}~ \\to ~{\\mathcal Y}) ~ \\to ~ ({\\mathcal X}~ \\times ~ R ~ \\to ~{\\mathcal Y})$ is a mapping such that $\\kappa_{c}(h)({\\pmb x},r)~=$ $h(\\Delta_{c}({\\pmb x},r;h)),\\forall({\\pmb x},r)\\in\\mathcal{X}\\times R.$ Note that the input of classifier $\\kappa_{c}(h)$ consists of both the feature vector x and the preference r. By the definition of SVC, we have\n\n$$\n\\operatorname{VC}(\\tilde{H})=\\operatorname{SVC}(\\mathcal{H},R,c)=d.\n$$\n\nGiven any distribution D, cost function $c$, and $h \\in \\mathcal H$ , the strategic 0-1 loss of h is $L_{c}(h,\\mathcal{D})=\\mathbb{E}_{({\\pmb x},y,r)\\sim\\mathcal{D}}\\Big[\\mathbb{I}\\big [\\kappa_{c}(h)({\\pmb x},r)\\neq y\\big]\\Big]=L(\\kappa_{c}(h),\\mathcal{D})$ , where $L(\\tilde{h},\\mathcal{D})$ is the standard expected risk of the newly defined $\\tilde{h}\\in \\tilde{\\mathcal{H}}$ under the distribution D in the non-strategic setting. Therefore, studying the PAC sample complexity upper bound for H under the strategic setting $\\langle R,c\\rangle$ is equivalent to studying the sample complexity for $\\tilde{H}$ in the nonstrategic setting. The latter problem can be addressed by employing the standard PAC learning analysis. From the Fundamental Theorem of Statistical Learning (Theorem 6.8 in (Shalev-Shwartz and Ben-David, 2014)), we know $\\tilde{H}$ is agnostic PAC learnable with sample complexity $\\begin{array}{r}{O(\\epsilon^{-2}(\\operatorname{VC}(\\tilde{H})+\\log\\frac{1}{\\delta}))}\\end{array}$ , meaning that there exists a constant C such that for any $(\\delta,\\epsilon)\\in(0,1)^{2}$ and any distribution D for $(x,y,r)$ , as long as $\\begin{array}{r}{n\\geq C{\\cdot}\\epsilon^{-2}(\\operatorname{VC}(\\tilde{H}){+}\\log\\frac{1}{\\delta})}\\end{array}$ with at least probability $1 - \\delta$ ,we have\n\n$$\nL(\\tilde{h}^{*},\\mathcal{D})-\\operatorname*{inf}_{\\tilde{h}\\in\\tilde{H}}L(\\tilde{h},\\mathcal{D})\\leq\\epsilon,\n$$\n\nwhere $\\tilde{h}^{*}$ is the solution of ERM with n i.i.d. samples from D as input. Let $h^{*}$ be the solution of the corresponding SERM conditioned on the same n i.i.d. samples from D. By the definition of $\\tilde{H}$ and $L_{c},$ we have ${\\cal L}_{c}(h^{\\ast},{\\mathcal D})={\\cal L}(\\tilde{h}^{\\ast},{\\mathcal D})$ , and $\\begin{array}{r}{\\operatorname*{inf}_{h\\in\\mathcal{H}}L_{c}(h,\\mathcal{D})\\ =}\\end{array}$ $\\operatorname{inf}_{\\tilde{h}\\in\\tilde{H}}L(\\tilde{h},{\\mathcal{D}})$ . Therefore, with probability $1 - \\delta$ ,we have\n\n$$\nL_{c}(h^{*},\\mathcal{D})-\\operatorname*{inf}_{h\\in\\mathcal{H}}L_{c}(h,\\mathcal{D})\\leq\\epsilon,\n$$\n\nwhich implies $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ is agnostic PAC learnable with sample complexity $O(\\epsilon^{-2}[d+$ $\\log(\\frac{1}{\\delta})])$ by the SERM.\n\n### Proof of Proposition 9\n\nProof Define the adversarial region for an adversary $({\\pmb x},r)$ as $N(\\pmb{x},r)=\\{z\\in\\mathcal{X}:c_{2}(z)\\leq$ $c_{1}({\\pmb x}) + | r | \\}\\supseteq \\{{\\pmb x}\\}$ . Since staying with the same feature has no cost, this implies $c ({\\pmb x};{\\pmb x}) = 0$ or equivalently $c_{2}({\\pmb x}) \\leq c_{1}({\\pmb x})$ for any $\\mathbf{\\boldsymbol{x}}\\in \\mathcal{X}$ . Then, the best response function for $({\\pmb x},r)$ can be characterized by\n\n1. if $h(\\pmb{x})=\\mathrm{sgn}(r)$ , then $h(\\Delta(\\mathbf{\\boldsymbol{x}},r;h))=\\mathrm{sgn}(r)$\n\n2. if $h(\\pmb{x})= -\\mathrm{sgn}(r)$ , then\n\n$$\nh(\\Delta(\\mathbf{x},r;h))=\\begin{cases}-\\mathrm{sgn}(r),&\\forall z\\in N(\\mathbf{x},r):h(z)= -\\mathrm{sgn}(r)\\\\ \\mathrm{sgn}(r),&\\exists z\\in N(\\mathbf{x},r):h(z)=\\mathrm{sgn}(r)\\end{cases}\\tag{16}\n$$\n\nSuppose there are three points $\\{(x_{i},r_{i})\\}_{i=1}^{3}$ that can be shattered by H. Let $b_{i}\\ =$ $c_{1}({\\pmb x}_{i}) + r_{i}$ and w.l.o.g. let $b_{1}~ \\leq ~ b_{2}~ \\leq ~ b_{3}$ From $b_{1}~ \\leq ~ b_{2}~ \\leq ~ b_{3}$ we have $N(\\pmb{x}_{1},r_{1})\\subseteq$ $N ({\\pmb x}_{2}, r_{2}) \\subseteq N ({\\pmb x}_{3}, r_{3})$\n\nBy Pigeonhole principle, there must exists two elements in $\\{r_{1}, r_{2}, r_{3}\\}$ which have the same sign. Suppose these two elements are $r_{1}, r_{2}$ and consider the following two cases:\n\n1. $r_{1}>0,r_{2}>0$ . From Equation 16, for any $h\\in\\mathcal{H},\\ h(\\Delta({\\pmb x}_{2},r_{2};h))= -1$ means $h(z)= -1,\\forall z\\in N(x_{2},r_{2})$ . Note that $N(\\pmb{x}_{1},r_{1})\\subseteq N(\\pmb{x}_{2},r_{2})$ , we also have $h(z)=$ $-1,\\forall z\\ \\in\\ N(\\pmb{x}_{1},r_{1})$ . As a result, $h(\\Delta(\\pmb{x}_{1},r_{1};h))= -1$ , meaning the sign pattern $\\{+,-\\}$ cannot be achieved by any $h \\in \\mathcal H$ for $\\{({\\pmb x}_{1},r_{1}),({\\pmb x}_{2},r_{2})\\}$ .\n\n2. $r_{1}<0,r_{2}<0$ From Equation 16, for any $h\\in\\mathcal{H},\\ h(\\Delta({\\pmb x}_{2},r_{2};h))\\ =\\ 1$ means $h(z)=1,\\forall z\\in N(x_{2},r_{2})$ . Similarly, from $N(\\pmb{x}_{1},r_{1})\\subseteq N(\\pmb{x}_{2},r_{2})$ we conclude $h(z)=$ $1,\\forall z\\in N(\\pmb{x}_{1},r_{1})$ and $h(\\Delta(\\pmb{x}_{1},r_{1};h))=1$ , meaning the sign pattern $\\{-,+\\}$ cannot be achieved by any $h \\in \\mathcal H$ for $\\{(\\pmb{x}_{1},r_{1}),(\\pmb{x}_{2},r_{2})\\}$ .\n\nTherefore, $\\{(x_{i},r_{i})\\}_{i=1}^{3}$ cannot be shattered by H, which implies $\\mathrm{SVC}(\\mathcal{H},R,c)\\leq 2$\n\n### Proof of Lemma 12\n\n(The source gives no proof of this result.)", "context": [{"id": "v24-21-1250:ctx1", "name": "Setup: data points, preferences, classifiers (Section 2)", "statement": "Basic Setup. We consider binary classification, where each data point is characterized by a tuple $(x,y,r)$ . Like classic classification setups, $\\mathbf{\\boldsymbol{x}}\\in \\mathcal{X}$ is the feature vector and $y \\in$ $\\{+1,-1\\}$ is its label. The only difference of our setup from classic classification problems is the additional $r \\in R \\subseteq \\mathbb{R}$ , which is the data point's (positive or negative) preference/reward of being labeled as +1. The data point's reward for label −1 is, without loss of generality, normalized to be 0. A classifier is a mapping $h:\\mathcal{X}\\to\\{+1,-1\\}$ . Our model is essentially the same as that of (Hardt et al., 2016; Miller et al., 2019), except that the r in our model can be any real value from set R whereas the aforementioned works assume $r = 1$ for all data points. Notably, we also allow r to be negative, which means some data points prefer to be classified as label $-1$. This generalization is natural and very useful because it allows much richer agent preferences. For instance, it casts the adversarial/robust classification problem as a special case of our model as well (see discussions later). Intuitively, the set R captures the richness of agents' preferences. As we will prove, how rich it is will affect both the statistical learnability and computational tractability of the learning problem."}, {"id": "v24-21-1250:ctx2", "name": "Setup: strategic manipulation and cost functions (Section 2)", "statement": "The Strategic Manipulation of Test Data. We consider strategic behaviors during the test phase and assume that the training data is unaltered/uncontaminated. An illustration of the setup can be found in Figure 1. A generic test data point is denoted as $(x,y,r)$ . The test data point is strategic and may shift its feature to vector z with cost $c(z;\\pmb{x})$ where $c : \\mathcal{X}\\times \\mathcal{X}\\to \\mathbb{R}_{\\ge 0}$ . In general, function c can be an arbitrary non-negative cost function. In our study of strategic linear classification, we assume the cost functions are induced by seminorms. We will consider the following two types of cost functions, with increasing generality.\n\n1. Instance-invariant cost functions: A cost function c is instance-invariant if there is a common function l such that $c(z;\\pmb{x})=l(\\pmb{z}-\\pmb{x})$ for any point $(x,y,r)$ .\n\n2. Instance-wise cost functions: With instance-wise cost functions, each data point is allowed to possess its own loss function. To capture this situation, we need to augment each data point's representation from $(x,y,r)$ to $({\\pmb x},y,r,l)$ , where l is a function depending on x such that $c ({\\boldsymbol{z}};{\\pmb x}) = l ({\\boldsymbol{z}}-{\\pmb x})$ for some semi-norm l. For notational convenience, we often refer to function l associated with this data point as $l_{x}$ though we emphasize that this is a slight abuse of notation because $l_{x}$ is determined not just by the data point's feature x but rather by the data point itself.4\n\nBoth cases have been considered in previous works. For instance, the separable cost function studied in (Hardt et al., 2016) is instance-wise, and the cost function induced by a seminorm as assumed by the main theorem of (Cullina et al., 2018) is instance-invariant. We shall prove later that the choice among these two types of cost functions will largely affect the efficient learnability of the problem."}, {"id": "v24-21-1250:ctx3", "name": "Eq. (1): data point best response and tie-breaking", "statement": "Given a classifier h, the strategic test data point $(x,y,r)$ may shift its feature vector to z and would like to pick the best such z by solving the following optimization problem:\n\nData Point Best Response:\n\n$$\n\\Delta_{c}(\\pmb{x},r;h)=\\arg\\operatorname*{max}_{\\pmb{\\mathrm{z}}\\in\\mathcal{X}}\\big [\\mathbb{I}(h(\\pmb{z})=1)\\cdot r-c(\\pmb{z};\\pmb{x})\\big].\\tag{1}\n$$\n\nwhere $\\mathbb{I}(S)$ is the indicator function and $[\\mathbb{I}(h(z)=1)\\cdot r-c(z;\\pmb{x})]$ is the quasi-linear utility function of data point $(x,y,r)$ . We call $\\Delta_{c}({\\pmb x},r;h)$ the manipulated feature. When there are multiple best responses, we assume the data point may choose any best response and thus will adopt the standard worst-case analysis. Note that the test data's strategic behaviors do not change its true label. Such strategic gaming behaviors differ from strategic improvements (see (Miller et al., 2019) for more discussions on their differences). We also point out that the preference r is assumed to be known for any training data (though no need to be known for testing data). While this may appear a strong assumption at the first glance, we believe this parameter can be estimated in real applications (e.g., how much it matters to someone for being admitted to a university, for receiving a loan or for being tested COVID positive). An interesting future direction may be to understand how robust the strategic classifier is to the estimation error of r in the training data."}, {"id": "v24-21-1250:ctx4", "name": "StraC problem and Eq. (2): strategic 0-1 loss (Section 2.1)", "statement": "A STRAC problem is described by a hypothesis class H, the set of preferences R and a manipulation cost function c. We thus denote it as $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ . Adopting the standard statistical learning framework, the input to our learning task is n uncontaminated training data points $({\\pmb x}_{1},y_{1},r_{1}),\\dots,({\\pmb x}_{n},y_{n},r_{n})$ drawn independently and identically (i.i.d.) from distribution D. Given these training data, we look to learn a classifier $h \\in \\mathcal H$ which minimizes the basic 0-1 loss, defined as follows:\n\nStrategic 0-1 Loss of classifier h :\n\n$$\nL_{c}(h;\\mathcal{D})=\\operatorname*{Pr}_{(\\mathbf{x},y,r)\\sim\\mathcal{D}}\\big [h(\\Delta_{c}(\\mathbf{x},r;h))\\neq y\\big].\\tag{2}\n$$\n\nNotably, the classifier h in the above loss definition takes the manipulated feature $\\textstyle\\Delta_{c}({\\pmb x},r;h)\\big)$ as input and, nevertheless, looks to correctly predict the true label y. For notational convenience, we sometimes omit c when it is clear from the context and simply write $\\Delta({\\pmb x},r;h)$ and $L(h;\\mathcal{D})$ ."}, {"id": "v24-21-1250:ctx5", "name": "Definition 1 (Strategic Shattering Coefficients)", "statement": "In this section, we introduce the notion of strategic VC-dimension (SVC) and show that it properly captures the behaviors of a hypothesis class in the strategic setup introduced above. We then show the connection of SVC with previous studies on both strategic and adversarial learning. Before formally introducing SVC, we first define the shattering coefficients in strategic setups.\n\nDefinition 1 (Strategic Shattering Coefficients) The n-th shattering coefficient of any strategic classification problem $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ is defined as\n\n$$\n\\sigma_{n}(\\mathcal{H},R,c)=\\operatorname*{max}_{(\\boldsymbol{x},\\boldsymbol{r})\\in\\mathcal{X}^{n}\\times R^{n}}~|\\{(h(\\Delta_{c}(\\boldsymbol{x}_{1},\\boldsymbol{r}_{1};h)),\\cdots,h(\\Delta_{c}(\\boldsymbol{x}_{n},\\boldsymbol{r}_{n};h)):h\\in\\mathcal{H}\\}|,\n$$\n\nwhere $\\Delta_{c}(\\pmb{x}_{i},r_{i};h)$ defined in Eq. (1) is a best response of data point $({\\pmb x}_{i}, y_{i}, r_{i})$ to classifier h under cost function c.\n\nThat is, $\\sigma_{n}(\\mathcal{H},R,c)$ captures the maximum number of classification behaviors/outcomes (among all choices of data points) that classifiers in H can possibly induce by using manipulated features as input. Like classic definition of shattering coefficient, the $\\sigma_{n}(\\mathcal{H},R,c)$ here does not involve the labels of the data points at all. In contrast, in the shattering coefficient definition for adversarial VC-dimension of (Cullina et al., 2018), the \"max\" is allowed to be over data labels as well. This is an important difference compared to our setting. Given the definition of the strategic shattering coefficients, the definition of strategic VC-dimension is standard."}, {"id": "v24-21-1250:ctx6", "name": "Definition 2 (Strategic VC-dimension), Eq. (3)", "statement": "Definition 2 The Strategic VC-dimension (SVC) for strategic classification problem $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ is defined as\n\n$$\nS V C(\\mathcal{H},R,c)=\\operatorname*{sup}\\{n\\in\\mathbb{N}:\\sigma_{n}(\\mathcal{H},R,c)=2^{n}\\}.\\tag{3}\n$$"}, {"id": "v24-21-1250:ctx7", "name": "SERM, Eq. (4)", "statement": "We show that the SVC defined above correctly characterizes the learnability of any strategic classification problem $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ . We consider the standard Empirical risk minimization (ERM) paradigm for strategic classification, but take into account training data's manipulation behaviors. Specifically, given any cost function c, any n uncontaminated training data points $(\\mathbf{x}_{1},y_{1},r_{1}),\\cdot\\cdot\\cdot,(\\mathbf{x}_{n},y_{n},r_{n})$ drawn independently and identically (i.i.d.) from the same distribution $\\mathcal{D}.$ , the strategic empirical risk minimization (SERM) problem computes a classifier $h \\in \\mathcal H$ that minimizes the empirical strategic 0-1 loss in Eq. (2). Formally, the SERM for $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ is defined as follows:\n\n$$\n\\mathrm{SERM}:\\quad\\mathrm{argmin}_{h\\in\\mathcal{H}}\\ L_{c}(h,\\{(x_{i},y_{i},r_{i})\\}_{i=1}^{n})=\\sum_{i=1}^{n}\\mathbb{I}\\big [h(\\Delta_{c}(\\mathbf{x}_{i},r_{i};h))\\neq y_{i}\\big]\\tag{4}\n$$\n\nwhere $L_{c}(h,\\{(x_{i},y_{i},r_{i})\\}_{i=1}^{n})$ is the empirical loss (compared to the expected loss $L_{c}(h,\\mathcal{D})$ defined in Eq. (2)). Unlike the standard (non-strategic) ERM problem and similar in spirit to the \"incentive-aware ERM\" in (Zhang and Conitzer, 2021), classifiers in the SERM problem take each data point's strategic response $\\Delta_{c}~({\\bf x}_{i},r_{i};h)$ as input, while not the original feature vector $\\pmb{x}_{i}$"}, {"id": "v24-21-1250:ctx8", "name": "Definition 3 (PAC-Learnability)", "statement": "Given the definition of strategic VC-dimension and the SERM framework, we state the sample complexity result for PAC-learning in our strategic setup:\n\nDefinition 3 (PAC-Learnability) In a strategic classification problem $\\mathrm{STRAC}\\langle\\mathcal{H},R,c\\rangle$ the hypothesis class $\\mathcal{H}\\subseteq(\\mathcal{X}\\to\\{+1,-1\\})$ is Probably Approximately Correctly (PAC) learnable by an algorithm A if there is a function $m_{\\mathcal{H},R,c}:(0,1)^{2}\\to\\mathbb{N}$ such that $\\forall(\\delta,\\epsilon)\\in$ $(0,1)^{2}$ , for any $n\\ge m_{\\mathcal{H},R,c}(\\delta,\\epsilon)$ and any distribution D for $({\\pmb x},y,r)$ , with at least probability $1 - \\delta$ , we have $L_{c}(h^{\\ast},\\mathcal{D})\\leq\\epsilon$ where $h^{*}$ is the output of the algorithm A with n i.i.d. samples from D as input. The problem is agnostic PAC learnable if $\\begin{array}{r}{L_{c}(h^{*},\\mathcal{D})-\\operatorname*{inf}_{h\\in\\mathcal{H}}L_{c}(h,\\mathcal{D})\\leq\\epsilon}\\end{array}$"}, {"id": "v24-21-1250:ctx9", "name": "Separable cost functions (Section 3.2)", "statement": "Not only restricting the set R of preference values can reduce the SVC. This subsection shows that restricting to special classes of cost functions can also lead to a small SVC. One special class of cost functions studied in many previous works is the separable cost functions (Hardt et al., 2016; Milli et al., 2019; Hu et al., 2019a). Formally, a cost function $c(z;\\pmb{x})$ is separable if there exists function $c_{1}, c_{2}: \\mathcal{X}\\to \\mathbb{R}$ such that $c(\\pmb{z};\\pmb{x})=\\operatorname*{max}\\left\\{c_{2}(\\pmb{z})-c_{1}(\\pmb{x}),0\\right\\}$\n\nThe following Proposition 9 shows that when the cost function is separable, SVC is at most 2 for any hypothesis class H and any class of preference set $R .^{5}$ Therefore, separable cost function essentially reduces any classification problem to a problem in lower dimension. Together with Theorem 4, Proposition 9 also recovers the PAC-learnability result of (Hardt et al., 2016) in their strategic-robust learning model (specifically, Theorem 1.8 of (2016)) and, moreover, generalizes their learnability from homogeneous agent preferences to the case with arbitrary agent preference values."}, {"id": "v24-21-1250:ctx10", "name": "Remark after Proposition 9: role of 0 not in R", "statement": "The assumption $0 \\notin R$ implies that each agent must strictly prefer either label +1 or $- 1$ . This assumption is necessary since if $0\\in R,$ SVC will be at least the classic VC dimension of H and thus Proposition 9 cannot hold. We remark that the above SVC upper bound 2 holds for any hypothesis class H. This bound 2 is tight for some classes of hypothesis, e.g., linear classifiers."}, {"id": "v24-21-1250:ctx11", "name": "Setup: strategic linear classification (Section 4)", "statement": "This section instantiates our previous general framework in one of the most fundamental special cases, i.e., linear classification. We will study both the statistical and computational efficiency in strategic linear classification. Naturally, we will restrict $\\mathcal{X}\\subseteq \\mathbb{R}^{d}$ in this section. Moreover, the cost functions are always assumed to be induced by seminorms.6 A linear classifier is defined by a hyperplane ${\\pmb w}\\cdot{\\pmb x}+ b = 0$; feature vector x is classified as +1 if and only if ${\\pmb w}\\cdot{\\pmb x}+ b \\ge 0$ With slight abuse of notation, we sometimes also call $({\\boldsymbol{\\mathbf{\\mathit{w}}}},{\\boldsymbol{b}})$ a hyperplane or a linear classifier. Let $\\mathcal{H}_{d}$ denote the hypothesis set of all d-dimensional linear classifiers. For linear classifier $({\\boldsymbol{\\mathbf{\\mathit{w}}}},{\\boldsymbol{b}})$ , the data point's best response can be more explicitly expressed as:\n\n$$\n\\Delta_{c}(x,r;w,b)=\\arg\\operatorname*{max}_{z}\\left[\\mathbb{I}(w\\cdot z+b\\ge 0)\\cdot r-c(z;\\pmb{x})\\right].\n$$"}, {"id": "v24-21-1250:ctx12", "name": "Theorem 11 (statement; Lemma 12 is a tool in its proof)", "statement": "Theorem 11 Consider an instance of strategic linear classification $\\mathrm{STRAC}\\langle\\mathcal{H}_{d},R,c\\rangle$ . For any instance-invariant cost function $c ({\\boldsymbol{z}};{\\pmb x}) = l ({\\boldsymbol{z}}-{\\pmb x})$ where l is a seminorm, we have $S V C(\\mathcal{H}_{d},R,c)=d+1-\\mathrm{dim}(V_{l})$ for any bounded R, where $V_{l}$ is the largest linear space contained in the ball $B=\\{\\pmb{x}:l(\\pmb{x})\\leq 1\\}$\n\nIn particular, if l is a norm $(i . e .,l(\\pmb{x})=0\\operatorname{iff}\\pmb{x}=0)$ , then dim $(V_{l})=0$ and $SVC(\\mathcal{H},R,c)=$ $d + 1$"}, {"id": "v24-21-1250:ctx13", "name": "Facts about the seminorm unit ball and l* (proof of Theorem 11)", "statement": "For any seminorm l, it is known the set $B=\\{x:l(x)\\leq 1\\}$ is nonempty, closed, convex, and origin-symmetric. Let $l^{*}(\\pmb{w})=\\operatorname*{sup}_{z\\in B}\\{\\pmb{w}\\cdot\\pmb{z}\\}$ . We have $l^{*}(w)>0$ for all $\\pmb{w} \\neq \\mathbf{0}$ since 0 is an interior point of B."}], "lean": "import Mathlib\n\nnamespace ResearchLevel\n\ndef stratUtil {X : Type*} (c : X → X → ℝ) (h : X → Bool) (x : X) (r : ℝ) (z : X) : ℝ :=\n (if h z then r else 0) - c z x\n\ndef IsBestResponse {X : Type*} (c : X → X → ℝ) (h : X → Bool) (x : X) (r : ℝ) (z : X) :\n Prop :=\n ∀ z' : X, stratUtil c h x r z' ≤ stratUtil c h x r z\n\ndef StrategicShatters {X : Type*} (H : Set (X → Bool)) (R : Set ℝ) (c : X → X → ℝ)\n (Δ : (X → Bool) → X → ℝ → X) (n : ℕ) : Prop :=\n ∃ x : Fin n → X, ∃ r : Fin n → ℝ, (∀ i, r i ∈ R) ∧\n ∀ v : Fin n → Bool, ∃ h ∈ H, ∀ i, h (Δ h (x i) (r i)) = v i\n\nnoncomputable def SVC {X : Type*} (H : Set (X → Bool)) (R : Set ℝ) (c : X → X → ℝ)\n (Δ : (X → Bool) → X → ℝ → X) : ℕ∞ :=\n ⨆ (n : ℕ) (_ : StrategicShatters H R c Δ n), (n : ℕ∞)\n\nnoncomputable def strategicRisk {X : Type*} [MeasurableSpace X] (c : X → X → ℝ)\n (Δ : (X → Bool) → X → ℝ → X) (h : X → Bool)\n (D : MeasureTheory.Measure (X × Bool × ℝ)) : ℝ :=\n (D {p : X × Bool × ℝ | h (Δ h p.1 p.2.2) ≠ p.2.1}).toReal\n\ndef empStrategicLoss {X : Type*} (c : X → X → ℝ) (Δ : (X → Bool) → X → ℝ → X)\n (h : X → Bool) {n : ℕ} (s : Fin n → X × Bool × ℝ) : ℕ :=\n (Finset.univ.filter (fun i => h (Δ h (s i).1 (s i).2.2) ≠ (s i).2.1)).card\n\ndef IsSERM {X : Type*} (H : Set (X → Bool)) (c : X → X → ℝ) (Δ : (X → Bool) → X → ℝ → X)\n (hstar : X → Bool) {n : ℕ} (s : Fin n → X × Bool × ℝ) : Prop :=\n hstar ∈ H ∧ ∀ h ∈ H, empStrategicLoss c Δ hstar s ≤ empStrategicLoss c Δ h s\n\ndef SeparableCost {X : Type*} (c : X → X → ℝ) : Prop :=\n ∃ c₁ c₂ : X → ℝ, ∀ z x : X, c z x = max (c₂ z - c₁ x) 0\n\ndef dotp {d : ℕ} (w u : Fin d → ℝ) : ℝ := ∑ i, w i * u i\n\ntheorem strategic_agnostic_PAC :\n ∃ C : ℝ, 0 < C ∧\n ∀ (X : Type*) [MeasurableSpace X]\n (H : Set (X → Bool)) (_hH : H.Nonempty) (_hH_ctble : H.Countable)\n (R : Set ℝ) (c : X → X → ℝ) (_hc : ∀ x y : X, 0 ≤ c x y)\n (_hc0 : ∀ x : X, c x x = 0)\n (Δ : (X → Bool) → X → ℝ → X)\n (_hΔ : ∀ h ∈ H, ∀ x, ∀ r ∈ R, IsBestResponse c h x r (Δ h x r))\n (_hmeas : ∀ h ∈ H, Measurable (fun p : X × Bool × ℝ => h (Δ h p.1 p.2.2)))\n (d : ℕ) (_hd : SVC H R c Δ = (d : ℕ∞)),\n ∃ m : ℝ → ℝ → ℕ,\n (∀ δ ε : ℝ, 0 < δ → δ < 1 → 0 < ε → ε < 1 →\n (m δ ε : ℝ) ≤ C * (ε ^ 2)⁻¹ * ((d : ℝ) + Real.log (1 / δ))) ∧\n ∃ A : (N : ℕ) → (Fin N → X × Bool × ℝ) → (X → Bool),\n (∀ N s, IsSERM H c Δ (A N s) s) ∧\n ∀ δ ε : ℝ, 0 < δ → δ < 1 → 0 < ε → ε < 1 →\n ∀ n : ℕ, m δ ε ≤ n →\n ∀ D : MeasureTheory.Measure (X × Bool × ℝ), MeasureTheory.IsProbabilityMeasure D →\n\n D {p : X × Bool × ℝ | p.2.2 ∉ R} = 0 →\n 1 - δ ≤\n ((MeasureTheory.Measure.pi (fun _ : Fin n => D))\n {s : Fin n → X × Bool × ℝ |\n strategicRisk c Δ (A n s) D - ⨅ h : ↥H, strategicRisk c Δ (h : X → Bool) D\n ≤ ε}).toReal := by\n sorry\n\ntheorem separable_SVC_le_two\n {X : Type*} (H : Set (X → Bool)) (R : Set ℝ) (c : X → X → ℝ) (_hc : ∀ x y : X, 0 ≤ c x y)\n (Δ : (X → Bool) → X → ℝ → X)\n (hΔ : ∀ h ∈ H, ∀ (x : X), ∀ r ∈ R, IsBestResponse c h x r (Δ h x r))\n\n (htie : ∀ h ∈ H, ∀ (x : X), ∀ r ∈ R,\n (∃ z, IsBestResponse c h x r z ∧ h z = decide (0 < r)) →\n h (Δ h x r) = decide (0 < r))\n (hR : (0 : ℝ) ∉ R) (hsep : SeparableCost c) (hc0 : ∀ x : X, c x x = 0) :\n SVC H R c Δ ≤ 2 := by\n sorry\n\ntheorem min_manipulation_cost_lower_bound\n {d : ℕ} (l : (Fin d → ℝ) → ℝ) (w : Fin d → ℝ) (b : ℝ) (x : Fin d → ℝ)\n (lstar : EReal) (hlstar : 0 < lstar)\n (hnn : ∀ u : Fin d → ℝ, 0 ≤ l u)\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (htri : ∀ u v : Fin d → ℝ, l (fun i => u i + v i) ≤ l u + l v)\n (hlub : IsLUB {t : EReal | ∃ z : Fin d → ℝ, l z ≤ 1 ∧ t = ((dotp w z : ℝ) : EReal)} lstar) :\n IsLeast {t : EReal | ∃ x' : Fin d → ℝ, dotp w x' + b = 0 ∧\n t = ((l (fun i => x' i - x i) : ℝ) : EReal)}\n (((|dotp w x + b| : ℝ) : EReal) / lstar) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nnamespace ResearchLevel\n\ndef stratUtil {X : Type*} (c : X → X → ℝ) (h : X → Bool) (x : X) (r : ℝ) (z : X) : ℝ :=\n (if h z then r else 0) - c z x\n\ndef IsBestResponse {X : Type*} (c : X → X → ℝ) (h : X → Bool) (x : X) (r : ℝ) (z : X) :\n Prop :=\n ∀ z' : X, stratUtil c h x r z' ≤ stratUtil c h x r z\n\ndef StrategicShatters {X : Type*} (H : Set (X → Bool)) (R : Set ℝ) (c : X → X → ℝ)\n (Δ : (X → Bool) → X → ℝ → X) (n : ℕ) : Prop :=\n ∃ x : Fin n → X, ∃ r : Fin n → ℝ, (∀ i, r i ∈ R) ∧\n ∀ v : Fin n → Bool, ∃ h ∈ H, ∀ i, h (Δ h (x i) (r i)) = v i\n\nnoncomputable def SVC {X : Type*} (H : Set (X → Bool)) (R : Set ℝ) (c : X → X → ℝ)\n (Δ : (X → Bool) → X → ℝ → X) : ℕ∞ :=\n ⨆ (n : ℕ) (_ : StrategicShatters H R c Δ n), (n : ℕ∞)\n\nnoncomputable def strategicRisk {X : Type*} [MeasurableSpace X] (c : X → X → ℝ)\n (Δ : (X → Bool) → X → ℝ → X) (h : X → Bool)\n (D : MeasureTheory.Measure (X × Bool × ℝ)) : ℝ :=\n (D {p : X × Bool × ℝ | h (Δ h p.1 p.2.2) ≠ p.2.1}).toReal\n\ndef empStrategicLoss {X : Type*} (c : X → X → ℝ) (Δ : (X → Bool) → X → ℝ → X)\n (h : X → Bool) {n : ℕ} (s : Fin n → X × Bool × ℝ) : ℕ :=\n (Finset.univ.filter (fun i => h (Δ h (s i).1 (s i).2.2) ≠ (s i).2.1)).card\n\ndef IsSERM {X : Type*} (H : Set (X → Bool)) (c : X → X → ℝ) (Δ : (X → Bool) → X → ℝ → X)\n (hstar : X → Bool) {n : ℕ} (s : Fin n → X × Bool × ℝ) : Prop :=\n hstar ∈ H ∧ ∀ h ∈ H, empStrategicLoss c Δ hstar s ≤ empStrategicLoss c Δ h s\n\ndef SeparableCost {X : Type*} (c : X → X → ℝ) : Prop :=\n ∃ c₁ c₂ : X → ℝ, ∀ z x : X, c z x = max (c₂ z - c₁ x) 0\n\ndef dotp {d : ℕ} (w u : Fin d → ℝ) : ℝ := ∑ i, w i * u i\n\nset_option maxHeartbeats 8000000\n\n\nnamespace UCdev\n\nopen MeasureTheory ProbabilityTheory\nopen scoped ENNReal NNReal\n\n/-! ## The Rademacher (sign) measure -/\n\n/-- The uniform measure on `Bool`. -/\nnoncomputable def signMeasure : Measure Bool :=\n (1/2 : ℝ≥0∞) • (Measure.dirac true + Measure.dirac false)\n\ninstance : IsProbabilityMeasure signMeasure := by\n constructor\n simp [signMeasure]\n exact ENNReal.inv_two_add_inv_two\n\nlemma integral_signMeasure (g : Bool → ℝ) :\n ∫ b, g b ∂signMeasure = (g true + g false) / 2 := by\n rw [signMeasure]\n rw [integral_smul_measure, integral_add_measure (by simp) (by simp), integral_dirac,\n integral_dirac]\n simp\n ring\n\n/-- The uniform measure on sign vectors. -/\nnoncomputable def signPi (n : ℕ) : Measure (Fin n → Bool) :=\n Measure.pi (fun _ => signMeasure)\n\ninstance (n : ℕ) : IsProbabilityMeasure (signPi n) := by\n unfold signPi; infer_instance\n\n/-- `sgn b = 1` if `b = false` and `-1` if `b = true`. -/\ndef sgn (b : Bool) : ℝ := if b then -1 else 1\n\nlemma sgn_mem_Icc (b : Bool) : sgn b ∈ Set.Icc (-1:ℝ) 1 := by\n cases b <;> norm_num [sgn]\n\nlemma integral_sgn_mul (v : ℝ) : ∫ b, sgn b * v ∂signMeasure = 0 := by\n rw [integral_signMeasure]\n simp [sgn]\n\n/-! ## A general Hoeffding inequality for i.i.d. coordinates of a product measure -/\n\nlemma integral_pi_coord {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {n : ℕ} (j : Fin n) (g : Z → ℝ) (hg : Measurable g) :\n ∫ s, g (s j) ∂(Measure.pi (fun _ : Fin n => D)) = ∫ z, g z ∂D := by\n conv_rhs => rw [← (measurePreserving_eval (fun _ : Fin n => D) j).map_eq]\n rw [integral_map (measurable_pi_apply j).aemeasurable hg.aestronglyMeasurable]\n\n/-- Hoeffding's inequality for a sum of functions of independent coordinates. -/\nlemma pi_hoeffding {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n (n : ℕ) (φ : Fin n → Z → ℝ) (hφ : ∀ j, Measurable (φ j))\n (a b : Fin n → ℝ) (hab : ∀ j z, φ j z ∈ Set.Icc (a j) (b j)) (hab' : ∀ j, a j ≤ b j)\n (hmean : ∀ j, ∫ z, φ j z ∂D = 0) (u : ℝ) (hu : 0 ≤ u) :\n (Measure.pi (fun _ : Fin n => D)).real {s | u ≤ ∑ j, φ j (s j)}\n ≤ Real.exp (-u ^ 2 / (2 * ∑ j, ((b j - a j) / 2) ^ 2)) := by\n classical\n set μ := Measure.pi (fun _ : Fin n => D) with hμ\n set X : Fin n → (Fin n → Z) → ℝ := fun j s => φ j (s j) with hX\n have hindep : iIndepFun X μ :=\n iIndepFun_pi (μ := fun _ : Fin n => D) (X := fun (j : Fin n) (z : Z) => φ j z)\n (fun j => (hφ j).aemeasurable)\n have hsubG : ∀ j : Fin n, HasSubgaussianMGF (X j) ((‖b j - a j‖₊ / 2) ^ 2) μ := by\n intro j\n refine hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero (μ := μ) (X := X j)\n ((hφ j).comp (measurable_pi_apply j)).aemeasurable ?_ ?_\n · filter_upwards with s\n exact hab j (s j)\n · show ∫ s, φ j (s j) ∂μ = 0\n rw [hμ, integral_pi_coord D j (φ j) (hφ j)]\n exact hmean j\n have hmain := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hindep\n (c := fun j => (‖b j - a j‖₊ / 2) ^ 2) (s := Finset.univ) (fun j _ => hsubG j) hu\n have hcast : ((∑ j : Fin n, (‖b j - a j‖₊ / 2) ^ 2 : ℝ≥0) : ℝ)\n = ∑ j, ((b j - a j) / 2) ^ 2 := by\n push_cast\n refine Finset.sum_congr rfl fun j _ => ?_\n rw [Real.norm_eq_abs, abs_of_nonneg (by have := hab' j; linarith)]\n simpa [hcast] using hmain\n\nlemma integral_signPi_coord {n : ℕ} (j : Fin n) (g : Bool → ℝ) :\n ∫ σ, g (σ j) ∂(signPi n) = ∫ b, g b ∂signMeasure := by\n rw [← (measurePreserving_eval (fun _ : Fin n => signMeasure) j).map_eq,\n integral_map (measurable_pi_apply j).aemeasurable\n (Measurable.of_discrete (f := g)).aestronglyMeasurable]\n rfl\n\n/-- One-sided Hoeffding bound for Rademacher sums. -/\nlemma rademacher_tail {n : ℕ} (v : Fin n → ℝ) (u : ℝ) (hu : 0 ≤ u) :\n (signPi n).real {σ | u ≤ ∑ j, sgn (σ j) * v j}\n ≤ Real.exp (-u ^ 2 / (2 * ∑ j, (v j) ^ 2)) := by\n classical\n set X : Fin n → (Fin n → Bool) → ℝ := fun j σ => sgn (σ j) * v j with hX\n have hindep : iIndepFun X (signPi n) := by\n have := iIndepFun_pi (μ := fun _ : Fin n => signMeasure)\n (X := fun (j : Fin n) (b : Bool) => sgn b * v j)\n (fun j => (Measurable.of_discrete (f := fun b : Bool => sgn b * v j)).aemeasurable)\n exact this\n have hsubG : ∀ j : Fin n, HasSubgaussianMGF (X j) (‖v j‖₊ ^ 2) (signPi n) := by\n intro j\n have hmean : ∫ σ, X j σ ∂(signPi n) = 0 := by\n rw [hX]\n simp only\n rw [integral_signPi_coord j (fun b => sgn b * v j)]\n exact integral_sgn_mul (v j)\n have hbd : ∀ᵐ σ ∂(signPi n), X j σ ∈ Set.Icc (-|v j|) (|v j|) := by\n filter_upwards with σ\n rcases sgn_mem_Icc (σ j) with ⟨h1, h2⟩\n constructor\n · rcases le_or_lt 0 (v j) with h | h\n · nlinarith [abs_of_nonneg h]\n · nlinarith [abs_of_neg h]\n · rcases le_or_lt 0 (v j) with h | h\n · nlinarith [abs_of_nonneg h]\n · nlinarith [abs_of_neg h]\n have := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero\n (μ := signPi n) (X := X j)\n (Measurable.aemeasurable (by fun_prop)) hbd hmean\n have heq : (‖|v j| - -|v j|‖₊ / 2 : ℝ≥0) ^ 2 = ‖v j‖₊ ^ 2 := by\n have : |v j| - -|v j| = 2 * |v j| := by ring\n rw [this]\n congr 1\n rw [nnnorm_mul]\n simp [Real.nnnorm_abs]\n rwa [heq] at this\n have hmain := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hindep\n (c := fun j => ‖v j‖₊ ^ 2) (s := Finset.univ) (fun j _ => hsubG j) hu\n have hcast : ((∑ j : Fin n, ‖v j‖₊ ^ 2 : ℝ≥0) : ℝ) = ∑ j, (v j) ^ 2 := by\n push_cast\n refine Finset.sum_congr rfl fun j _ => ?_\n rw [Real.norm_eq_abs, sq_abs]\n rw [hcast] at hmain\n exact hmain\n\n/-- Two-sided version of `pi_hoeffding`. -/\nlemma pi_hoeffding_abs {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n (n : ℕ) (φ : Fin n → Z → ℝ) (hφ : ∀ j, Measurable (φ j))\n (a b : Fin n → ℝ) (hab : ∀ j z, φ j z ∈ Set.Icc (a j) (b j)) (hab' : ∀ j, a j ≤ b j)\n (hmean : ∀ j, ∫ z, φ j z ∂D = 0) (u : ℝ) (hu : 0 ≤ u) :\n (Measure.pi (fun _ : Fin n => D)).real {s | u ≤ |∑ j, φ j (s j)|}\n ≤ 2 * Real.exp (-u ^ 2 / (2 * ∑ j, ((b j - a j) / 2) ^ 2)) := by\n classical\n set μ := Measure.pi (fun _ : Fin n => D) with hμ\n have h1 := pi_hoeffding D n φ hφ a b hab hab' hmean u hu\n have h2 := pi_hoeffding D n (fun j z => -(φ j z)) (fun j => (hφ j).neg)\n (fun j => -(b j)) (fun j => -(a j))\n (fun j z => by\n rcases hab j z with ⟨h1, h2⟩\n exact ⟨by linarith, by linarith⟩)\n (fun j => by have := hab' j; linarith)\n (fun j => by rw [integral_neg, hmean j, neg_zero]) u hu\n have hsub : {s : Fin n → Z | u ≤ |∑ j, φ j (s j)|}\n ⊆ {s | u ≤ ∑ j, φ j (s j)} ∪ {s | u ≤ ∑ j, -(φ j (s j))} := by\n intro s hs\n simp only [Set.mem_setOf_eq] at hs\n rcases abs_cases (∑ j, φ j (s j)) with ⟨he, _⟩ | ⟨he, _⟩\n · left; simp only [Set.mem_setOf_eq]; linarith [hs, he.symm ▸ hs]\n · right\n simp only [Set.mem_setOf_eq, Finset.sum_neg_distrib]\n rw [he] at hs\n linarith\n have hle := measureReal_mono (μ := μ) hsub (by simp [hμ])\n have hunion : μ.real ({s : Fin n → Z | u ≤ ∑ j, φ j (s j)}\n ∪ {s | u ≤ ∑ j, -(φ j (s j))}) ≤ μ.real {s : Fin n → Z | u ≤ ∑ j, φ j (s j)}\n + μ.real {s : Fin n → Z | u ≤ ∑ j, -(φ j (s j))} := measureReal_union_le _ _\n have heq : ∑ j, ((-(a j) - -(b j)) / 2) ^ 2 = ∑ j, ((b j - a j) / 2) ^ 2 := by\n refine Finset.sum_congr rfl fun j _ => ?_\n ring_nf\n rw [heq] at h2\n linarith\n\n/-- Indicator of a Boolean test. -/\ndef ind (b : Bool) : ℝ := if b then 1 else 0\n\nlemma ind_mem_Icc (b : Bool) : ind b ∈ Set.Icc (0:ℝ) 1 := by\n cases b <;> norm_num [ind]\n\nlemma measurable_ind {Z : Type*} [MeasurableSpace Z] {g : Z → Bool} (hg : Measurable g) :\n Measurable (fun z => ind (g z)) :=\n (Measurable.of_discrete (f := ind)).comp hg\n\nlemma integral_ind {Z : Type*} [MeasurableSpace Z] (D : Measure Z) (g : Z → Bool)\n (hg : Measurable g) :\n ∫ z, ind (g z) ∂D = (D {z | g z = true}).toReal := by\n have hset : MeasurableSet {z | g z = true} := hg (measurableSet_singleton true)\n have h1 : (fun z => ind (g z)) = Set.indicator {z | g z = true} (fun _ => (1:ℝ)) := by\n funext z\n by_cases h : g z = true\n · simp [ind, h, Set.indicator_of_mem, Set.mem_setOf_eq]\n · simp only [Bool.not_eq_true] at h\n simp [ind, h, Set.indicator_of_notMem, Set.mem_setOf_eq]\n rw [h1, integral_indicator_const (1:ℝ) hset]\n simp [measureReal_def]\n\nlemma integrable_ind {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n (g : Z → Bool) (hg : Measurable g) : Integrable (fun z => ind (g z)) D := by\n refine Integrable.of_mem_Icc 0 1 (measurable_ind hg).aemeasurable ?_\n filter_upwards with z\n exact ind_mem_Icc (g z)\n\n/-- Hoeffding's inequality for the empirical count of a Boolean test. -/\nlemma emp_hoeffding {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n (g : Z → Bool) (hg : Measurable g) (n : ℕ) (u : ℝ) (hu : 0 ≤ u) :\n (Measure.pi (fun _ : Fin n => D)).real\n {s | u ≤ |∑ j, (ind (g (s j)) - (D {z | g z = true}).toReal)|}\n ≤ 2 * Real.exp (-u ^ 2 / (2 * ((n:ℝ) / 4))) := by\n classical\n set p := (D {z | g z = true}).toReal with hp\n have hp0 : 0 ≤ p := ENNReal.toReal_nonneg\n have hp1 : p ≤ 1 := by\n rw [hp]\n have h : D {z | g z = true} ≤ 1 := prob_le_one\n exact ENNReal.toReal_le_of_le_ofReal (by norm_num) (by simpa using h)\n have hmeas : ∀ _j : Fin n, Measurable (fun z : Z => ind (g z) - p) :=\n fun _ => (measurable_ind hg).sub measurable_const\n have hbd : ∀ (j : Fin n) (z : Z), (fun _ (z : Z) => ind (g z) - p) j z ∈\n Set.Icc ((fun _ : Fin n => -p) j) ((fun _ : Fin n => 1 - p) j) := by\n intro j z\n rcases ind_mem_Icc (g z) with ⟨h1, h2⟩\n exact ⟨by simpa using (by linarith : -p ≤ ind (g z) - p),\n by simpa using (by linarith : ind (g z) - p ≤ 1 - p)⟩\n have hab' : ∀ _j : Fin n, (-p : ℝ) ≤ 1 - p := fun _ => by linarith\n have hmean : ∀ _j : Fin n, ∫ z, (ind (g z) - p) ∂D = 0 := by\n intro j\n rw [integral_sub (integrable_ind D g hg) (integrable_const p), integral_ind D g hg, ← hp]\n simp\n have hmain := pi_hoeffding_abs D n (fun _ z => ind (g z) - p) hmeas\n (fun _ => -p) (fun _ => 1 - p) hbd hab' hmean u hu\n have heq : (∑ _j : Fin n, (((1 - p) - -p) / 2) ^ 2) = (n:ℝ) / 4 := by\n have : ∀ _j : Fin n, (((1 - p) - -p) / 2 : ℝ) ^ 2 = 1/4 := by\n intro j; ring_nf\n rw [Finset.sum_congr rfl (fun j _ => this j)]\n simp\n ring\n rw [heq] at hmain\n exact hmain\n\n/-! ## Symmetrization -/\n\n/-- Empirical average of a Boolean test on a sample. -/\nnoncomputable def empAvg {Z : Type*} {n : ℕ} (g : Z → Bool) (s : Fin n → Z) : ℝ :=\n (∑ j, ind (g (s j))) / n\n\n/-- True risk. -/\nnoncomputable def riskOf {Z : Type*} [MeasurableSpace Z] (D : Measure Z) (g : Z → Bool) : ℝ :=\n (D {z | g z = true}).toReal\n\nlemma measurable_empAvg {Z : Type*} [MeasurableSpace Z] {n : ℕ} (g : Z → Bool)\n (hg : Measurable g) : Measurable (fun s : Fin n → Z => empAvg g s) := by\n unfold empAvg\n refine Measurable.div_const ?_ _\n refine Finset.measurable_sum _ (fun j _ => ?_)\n exact (measurable_ind hg).comp (measurable_pi_apply j)\n\nlemma empAvg_bound {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n (g : Z → Bool) (hg : Measurable g) (n : ℕ) (hn : 0 < n) (t : ℝ) (ht : 0 < t)\n (hnt : 8 ≤ (n:ℝ) * t ^ 2) :\n (Measure.pi (fun _ : Fin n => D)) {s | t/2 < |empAvg g s - riskOf D g|}\n ≤ 1/2 := by\n classical\n set μ := Measure.pi (fun _ : Fin n => D) with hμ\n simp only [riskOf]\n obtain ⟨p, hp⟩ : ∃ p : ℝ, (D {z | g z = true}).toReal = p := ⟨_, rfl⟩\n rw [hp]\n have hn0 : (0:ℝ) < n := by exact_mod_cast hn\n have hsub : {s : Fin n → Z | t/2 < |empAvg g s - p|}\n ⊆ {s : Fin n → Z | (n:ℝ) * (t/2) ≤ |∑ j, (ind (g (s j)) - p)|} := by\n intro s hs\n simp only [Set.mem_setOf_eq] at hs ⊢\n have hsum : ∑ j, (ind (g (s j)) - p) = (n:ℝ) * (empAvg g s - p) := by\n rw [Finset.sum_sub_distrib]\n simp [empAvg]\n field_simp\n rw [hsum, abs_mul, abs_of_nonneg hn0.le]\n have := hs\n nlinarith [abs_nonneg (empAvg g s - p)]\n have hmeas : MeasurableSet {s : Fin n → Z | (n:ℝ) * (t/2) ≤ |∑ j, (ind (g (s j)) - p)|} := by\n refine measurableSet_le measurable_const ?_\n refine (Finset.measurable_sum _ (fun j _ => ?_)).abs\n exact ((measurable_ind hg).comp (measurable_pi_apply j)).sub measurable_const\n have hH := emp_hoeffding D g hg n ((n:ℝ) * (t/2)) (by positivity)\n rw [hp] at hH\n have hexp : 2 * Real.exp (-((n:ℝ) * (t/2)) ^ 2 / (2 * ((n:ℝ)/4))) ≤ 1/2 := by\n have hEq : (-((n:ℝ) * (t/2)) ^ 2 / (2 * ((n:ℝ)/4))) = -((n:ℝ) * t ^ 2)/2 := by\n field_simp\n ring\n rw [hEq]\n have h4 : (-((n:ℝ) * t ^ 2)/2) ≤ -4 := by linarith\n have := Real.exp_le_exp.mpr h4\n have he4 : Real.exp (-4) ≤ 1/4 := by\n rw [Real.exp_neg]\n rw [inv_le_comm₀ (by positivity) (by norm_num)]\n have : (4:ℝ) ≤ Real.exp 4 := by\n have h1 : (1:ℝ) + 4 ≤ Real.exp 4 := by\n have := Real.add_one_le_exp (4:ℝ)\n linarith\n linarith\n linarith\n linarith\n have hreal : μ.real {s : Fin n → Z | (n:ℝ) * (t/2) ≤ |∑ j, (ind (g (s j)) - p)|} ≤ 1/2 :=\n le_trans hH hexp\n have hfin : μ {s : Fin n → Z | (n:ℝ) * (t/2) ≤ |∑ j, (ind (g (s j)) - p)|} ≤ 1/2 := by\n have hne : μ {s : Fin n → Z | (n:ℝ) * (t/2) ≤ |∑ j, (ind (g (s j)) - p)|} ≠ ⊤ :=\n measure_ne_top _ _\n rw [← ENNReal.ofReal_toReal hne]\n calc ENNReal.ofReal (μ {s : Fin n → Z | (n:ℝ) * (t/2) ≤ |∑ j, (ind (g (s j)) - p)|}).toReal\n ≤ ENNReal.ofReal (1/2) := ENNReal.ofReal_le_ofReal hreal\n _ = 1/2 := by\n rw [ENNReal.ofReal_div_of_pos (by norm_num)]\n simp\n exact le_trans (measure_mono hsub) hfin\n\n/-- **Symmetrization**: the deviation of the empirical average from the true risk is\ncontrolled by the deviation between two independent samples. -/\nlemma symmetrization {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {ι : Type*} [Countable ι] (f : ι → Z → Bool) (hf : ∀ i, Measurable (f i))\n (n : ℕ) (hn : 0 < n) (t : ℝ) (ht : 0 < t) (hnt : 8 ≤ (n:ℝ) * t ^ 2) :\n (Measure.pi (fun _ : Fin n => D)) {s | ∃ i, t < |empAvg (f i) s - riskOf D (f i)|}\n ≤ 2 * ((Measure.pi (fun _ : Fin n => D)).prod (Measure.pi (fun _ : Fin n => D)))\n {q : (Fin n → Z) × (Fin n → Z) |\n ∃ i, t/2 < |empAvg (f i) q.1 - empAvg (f i) q.2|} := by\n classical\n set μ := Measure.pi (fun _ : Fin n => D) with hμ\n set Bad := {s : Fin n → Z | ∃ i, t < |empAvg (f i) s - riskOf D (f i)|} with hBad\n set Bad2 := {q : (Fin n → Z) × (Fin n → Z) |\n ∃ i, t/2 < |empAvg (f i) q.1 - empAvg (f i) q.2|} with hBad2\n have hBadm : MeasurableSet Bad := by\n have hEq : Bad = ⋃ i : ι, {s : Fin n → Z | t < |empAvg (f i) s - riskOf D (f i)|} := by\n ext s; simp [hBad]\n rw [hEq]\n exact MeasurableSet.iUnion (fun i => measurableSet_lt measurable_const\n (((measurable_empAvg (f i) (hf i)).sub measurable_const).abs))\n have hBad2m : MeasurableSet Bad2 := by\n have hEq : Bad2 = ⋃ i : ι, {q : (Fin n → Z) × (Fin n → Z) |\n t/2 < |empAvg (f i) q.1 - empAvg (f i) q.2|} := by\n ext q; simp [hBad2]\n rw [hEq]\n refine MeasurableSet.iUnion (fun i => measurableSet_lt measurable_const ?_)\n exact (((measurable_empAvg (f i) (hf i)).comp measurable_fst).sub\n ((measurable_empAvg (f i) (hf i)).comp measurable_snd)).abs\n have hkey : ∀ s ∈ Bad, (1:ℝ≥0∞)/2 ≤ μ (Prod.mk s ⁻¹' Bad2) := by\n intro s hs\n obtain ⟨i, hi⟩ := hs\n have hAm : MeasurableSet {s' : Fin n → Z | t/2 < |empAvg (f i) s' - riskOf D (f i)|} :=\n measurableSet_lt measurable_const\n (((measurable_empAvg (f i) (hf i)).sub measurable_const).abs)\n have hA : μ {s' : Fin n → Z | t/2 < |empAvg (f i) s' - riskOf D (f i)|} ≤ 1/2 :=\n empAvg_bound D (f i) (hf i) n hn t ht hnt\n have hcompl : (1:ℝ≥0∞)/2\n ≤ μ ({s' : Fin n → Z | t/2 < |empAvg (f i) s' - riskOf D (f i)|}ᶜ) := by\n rw [prob_compl_eq_one_sub hAm]\n have h2 : (1:ℝ≥0∞) - 1/2 = 1/2 := by\n rw [one_div]\n exact ENNReal.sub_eq_of_eq_add (by simp) ENNReal.inv_two_add_inv_two.symm\n calc (1:ℝ≥0∞)/2 = 1 - 1/2 := h2.symm\n _ ≤ 1 - μ {s' : Fin n → Z | t/2 < |empAvg (f i) s' - riskOf D (f i)|} :=\n tsub_le_tsub_left hA 1\n refine le_trans hcompl (measure_mono ?_)\n intro s' hs'\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_lt] at hs'\n refine ⟨i, ?_⟩\n have h1 : |empAvg (f i) s - riskOf D (f i)| - |empAvg (f i) s' - riskOf D (f i)|\n ≤ |empAvg (f i) s - empAvg (f i) s'| := by\n have h2 := abs_sub_abs_le_abs_sub (empAvg (f i) s - riskOf D (f i))\n (empAvg (f i) s' - riskOf D (f i))\n have h3 : (empAvg (f i) s - riskOf D (f i)) - (empAvg (f i) s' - riskOf D (f i))\n = empAvg (f i) s - empAvg (f i) s' := by ring\n rwa [h3] at h2\n simp only [Set.mem_setOf_eq]\n linarith\n have hprod : (μ.prod μ) Bad2 = ∫⁻ s, μ (Prod.mk s ⁻¹' Bad2) ∂μ := Measure.prod_apply hBad2m\n have hint : (1/2 : ℝ≥0∞) * μ Bad ≤ (μ.prod μ) Bad2 := by\n rw [hprod]\n calc (1/2 : ℝ≥0∞) * μ Bad\n = ∫⁻ s, Set.indicator Bad (fun _ => (1:ℝ≥0∞)/2) s ∂μ := by\n rw [lintegral_indicator hBadm]\n simp [mul_comm]\n _ ≤ ∫⁻ s, μ (Prod.mk s ⁻¹' Bad2) ∂μ := by\n refine lintegral_mono (fun s => ?_)\n by_cases h : s ∈ Bad\n · rw [Set.indicator_of_mem h]\n exact hkey s h\n · rw [Set.indicator_of_notMem h]\n exact zero_le _\n have h2half : (2:ℝ≥0∞) * (1/2) = 1 := by\n rw [one_div, ENNReal.mul_inv_cancel (by norm_num) (by norm_num)]\n calc μ Bad = 2 * ((1/2 : ℝ≥0∞) * μ Bad) := by rw [← mul_assoc, h2half, one_mul]\n _ ≤ 2 * ((μ.prod μ) Bad2) := by exact mul_le_mul_left' hint 2\n\n/-! ## Reindexing invariance of product measures -/\n\nlemma pi_map_reindex {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {J : Type*} [Fintype J] [DecidableEq J] (e : J ≃ J) :\n MeasurePreserving (fun w : J → Z => fun j => w (e j))\n (Measure.pi fun _ : J => D) (Measure.pi fun _ : J => D) := by\n have hmeas : Measurable (fun w : J → Z => fun j => w (e j)) :=\n measurable_pi_lambda _ (fun j => measurable_pi_apply (e j))\n refine ⟨hmeas, ?_⟩\n refine (Measure.pi_eq ?_).symm\n intro s hs\n have hpre : (fun w : J → Z => fun j => w (e j)) ⁻¹' (Set.pi Set.univ s)\n = Set.pi Set.univ (fun j => s (e.symm j)) := by\n ext w\n simp only [Set.mem_preimage, Set.mem_pi, Set.mem_univ, forall_true_left]\n constructor\n · intro h j\n have := h (e.symm j)\n simpa using this\n · intro h j\n have h2 := h (e j)\n rw [Equiv.symm_apply_apply] at h2\n exact h2\n rw [Measure.map_apply hmeas (MeasurableSet.univ_pi hs), hpre,\n Measure.pi_pi]\n exact Equiv.prod_comp e.symm (fun j => D (s j))\n\nend UCdev\n\nset_option maxHeartbeats 2000000\nopen scoped symmDiff\nopen Finset\n\nnamespace VCcomb\n\nvariable {α : Type*} [DecidableEq α] [Fintype α]\n\n/-- Restriction of a set along a list of coordinates. -/\ndef restr {m : ℕ} (φ : Fin m → α) (s : Finset α) : Finset (Fin m) :=\n Finset.univ.filter (fun j => φ j ∈ s)\n\n@[simp] lemma mem_restr {m : ℕ} (φ : Fin m → α) (s : Finset α) (j : Fin m) :\n j ∈ restr φ s ↔ φ j ∈ s := by simp [restr]\n\n/-- The VC dimension of a restricted family is at most that of the original family. -/\nlemma vcDim_image_restr_le {m : ℕ} (φ : Fin m → α) (Q : Finset (Finset α)) :\n (Q.image (restr φ)).vcDim ≤ Q.vcDim := by\n classical\n refine Finset.sup_le ?_\n intro S hS\n rw [Finset.mem_shatterer] at hS\n -- φ is injective on S\n have hinj : Set.InjOn φ S := by\n intro j hj j' hj' hjj'\n by_contra hne\n obtain ⟨u, hu, hSu⟩ := hS (show ({j} : Finset (Fin m)) ⊆ S by\n simpa using hj)\n rw [Finset.mem_image] at hu\n obtain ⟨s, hs, rfl⟩ := hu\n have h1 : j ∈ S ∩ restr φ s := by rw [hSu]; simp\n have h2 : j' ∉ S ∩ restr φ s := by\n rw [hSu, Finset.mem_singleton]; exact fun h => hne h.symm\n simp only [Finset.mem_inter, mem_restr] at h1 h2\n exact h2 ⟨hj', by rw [← hjj']; exact h1.2⟩\n -- Q shatters the image\n have hsh : Q.Shatters (S.image φ) := by\n intro U hU\n -- pull back U\n set T : Finset (Fin m) := S.filter (fun j => φ j ∈ U) with hT\n have hTS : T ⊆ S := Finset.filter_subset _ _\n obtain ⟨u, hu, hSu⟩ := hS hTS\n rw [Finset.mem_image] at hu\n obtain ⟨s, hs, rfl⟩ := hu\n refine ⟨s, hs, ?_⟩\n ext a\n simp only [Finset.mem_inter, Finset.mem_image]\n constructor\n · rintro ⟨⟨j, hj, rfl⟩, has⟩\n have : j ∈ S ∩ restr φ s := by simp [hj, has]\n rw [hSu, hT] at this\n simp only [Finset.mem_filter] at this\n exact this.2\n · intro haU\n have haS : a ∈ S.image φ := hU haU\n rw [Finset.mem_image] at haS\n obtain ⟨j, hj, rfl⟩ := haS\n have hjT : j ∈ T := by simp [hT, hj, haU]\n have : j ∈ S ∩ restr φ s := by rw [hSu]; exact hjT\n simp only [Finset.mem_inter, mem_restr] at this\n exact ⟨⟨j, hj, rfl⟩, this.2⟩\n have := hsh.card_le_vcDim\n rwa [Finset.card_image_of_injOn hinj] at this\n\n/-- Core counting step: if the family is well separated, some choice of `m` coordinates\nseparates all its members. -/\nlemma exists_injOn_restr [Nonempty α] (Q : Finset (Finset α)) (m : ℕ) (q : ℝ)\n (hq0 : 0 ≤ q)\n (hsep : ∀ s ∈ Q, ∀ t ∈ Q, s ≠ t →\n ((Fintype.card α - (s ∆ t).card : ℕ) : ℝ) ≤ q * Fintype.card α)\n (hlt : (Q.card : ℝ) * (Q.card : ℝ) * q ^ m < 1) :\n ∃ φ : Fin m → α, ∀ s ∈ Q, ∀ t ∈ Q, restr φ s = restr φ t → s = t := by\n classical\n set N := Fintype.card α with hN\n have hN0 : 0 < N := Fintype.card_pos\n set P : Finset ((Finset α) × (Finset α)) := (Q ×ˢ Q).filter (fun p => p.1 ≠ p.2) with hP\n set Bad : Finset (Fin m → α) :=\n P.biUnion (fun p => Fintype.piFinset (fun _ : Fin m => (p.1 ∆ p.2)ᶜ)) with hBad\n have hcardBad : (Bad.card : ℝ) < (N : ℝ) ^ m := by\n have h1 : Bad.card ≤ ∑ p ∈ P, (Fintype.piFinset (fun _ : Fin m => (p.1 ∆ p.2)ᶜ)).card :=\n Finset.card_biUnion_le\n have h2 : ∀ p ∈ P, ((Fintype.piFinset (fun _ : Fin m => (p.1 ∆ p.2)ᶜ)).card : ℝ)\n ≤ (q * N) ^ m := by\n intro p hp\n rw [Fintype.card_piFinset]\n simp only [Finset.prod_const, Finset.card_univ, Fintype.card_fin]\n rw [Finset.card_compl]\n push_cast\n refine pow_le_pow_left₀ (by positivity) ?_ m\n simp only [hP, Finset.mem_filter, Finset.mem_product] at hp\n exact hsep p.1 hp.1.1 p.2 hp.1.2 hp.2\n have h3 : ((∑ p ∈ P, (Fintype.piFinset (fun _ : Fin m => (p.1 ∆ p.2)ᶜ)).card : ℕ) : ℝ)\n ≤ (P.card : ℝ) * (q * N) ^ m := by\n push_cast\n calc ∑ p ∈ P, ((Fintype.piFinset (fun _ : Fin m => (p.1 ∆ p.2)ᶜ)).card : ℝ)\n ≤ ∑ _p ∈ P, (q * N) ^ m := Finset.sum_le_sum h2\n _ = (P.card : ℝ) * (q * N) ^ m := by rw [Finset.sum_const, nsmul_eq_mul]\n have h4 : (P.card : ℝ) ≤ (Q.card : ℝ) * (Q.card : ℝ) := by\n have : P.card ≤ (Q ×ˢ Q).card := Finset.card_filter_le _ _\n rw [Finset.card_product] at this\n exact_mod_cast this\n have h5 : (Bad.card : ℝ) ≤ (Q.card : ℝ) * (Q.card : ℝ) * (q * N) ^ m := by\n refine le_trans (by exact_mod_cast h1) (le_trans h3 ?_)\n exact mul_le_mul_of_nonneg_right h4 (by positivity)\n have h6 : (Q.card : ℝ) * (Q.card : ℝ) * (q * N) ^ m < (N:ℝ) ^ m := by\n rw [mul_pow, ← mul_assoc]\n have hNpow : (0:ℝ) < (N:ℝ) ^ m := by positivity\n calc (Q.card : ℝ) * (Q.card : ℝ) * q ^ m * (N:ℝ) ^ m\n < 1 * (N:ℝ) ^ m := by\n exact mul_lt_mul_of_pos_right hlt hNpow\n _ = (N:ℝ) ^ m := one_mul _\n linarith\n have hne : Bad ≠ (Finset.univ : Finset (Fin m → α)) := by\n intro h\n have : (Bad.card : ℝ) = (N:ℝ) ^ m := by\n rw [h]\n simp [Finset.card_univ, hN]\n linarith [hcardBad, this.ge, this.le]\n obtain ⟨φ, _, hφ⟩ : ∃ φ ∈ (Finset.univ : Finset (Fin m → α)), φ ∉ Bad := by\n by_contra hcon\n push_neg at hcon\n exact hne (Finset.eq_univ_of_forall (fun φ => hcon φ (Finset.mem_univ φ)))\n refine ⟨φ, fun s hs t ht hst => ?_⟩\n by_contra hne2\n apply hφ\n rw [hBad, Finset.mem_biUnion]\n refine ⟨(s, t), ?_, ?_⟩\n · simp [hP, hs, ht, hne2]\n · rw [Fintype.mem_piFinset]\n intro j\n simp only [Finset.mem_compl, Finset.mem_symmDiff]\n have : (j ∈ restr φ s) = (j ∈ restr φ t) := by rw [hst]\n simp only [mem_restr, eq_iff_iff] at this\n tauto\n\n\n/-- Sauer bound arithmetic: `∑_{k ≤ d} C(m,k) ≤ (e m / d)^d`. -/\nlemma sum_choose_le (d m : ℕ) (hd : 1 ≤ d) (hdm : d ≤ m) :\n ((∑ k ∈ Finset.Iic d, (m.choose k) : ℕ) : ℝ) ≤ (Real.exp 1 * m / d) ^ d := by\n have hm : 1 ≤ m := le_trans hd hdm\n have hd0 : (0:ℝ) < d := by exact_mod_cast hd\n have hm0 : (0:ℝ) < m := by exact_mod_cast hm\n set x : ℝ := (d:ℝ)/(m:ℝ) with hx\n have hx0 : 0 < x := by positivity\n have hx1 : x ≤ 1 := by\n rw [hx, div_le_one hm0]; exact_mod_cast hdm\n have step1 : ((∑ k ∈ Finset.Iic d, (m.choose k) : ℕ) : ℝ)\n ≤ ∑ k ∈ Finset.Iic d, ((m.choose k : ℝ) * x ^ k) / x ^ d := by\n push_cast\n refine Finset.sum_le_sum ?_\n intro k hk\n have hkd : k ≤ d := Finset.mem_Iic.mp hk\n have hpow : x ^ d ≤ x ^ k := pow_le_pow_of_le_one hx0.le hx1 hkd\n rw [le_div_iff₀ (by positivity)]\n have : (0:ℝ) ≤ (m.choose k : ℝ) := by positivity\n nlinarith [this, hpow]\n have step2 : ∑ k ∈ Finset.Iic d, ((m.choose k : ℝ) * x ^ k)\n ≤ ∑ k ∈ Finset.range (m+1), ((m.choose k : ℝ) * x ^ k) := by\n refine Finset.sum_le_sum_of_subset_of_nonneg ?_ ?_\n · intro k hk\n simp only [Finset.mem_Iic] at hk\n simp only [Finset.mem_range]\n omega\n · intro k _ _; positivity\n have step3 : ∑ k ∈ Finset.range (m+1), ((m.choose k : ℝ) * x ^ k) = (1 + x) ^ m := by\n rw [show (1:ℝ) + x = x + 1 by ring, add_pow]\n refine Finset.sum_congr rfl fun k hk => ?_\n rw [one_pow, mul_one]\n ring\n have step4 : (1 + x) ^ m ≤ Real.exp 1 ^ d := by\n have h1 : (1 + x) ^ m ≤ (Real.exp x) ^ m := by\n refine pow_le_pow_left₀ (by positivity) ?_ m\n have := Real.add_one_le_exp x\n linarith\n have h2 : (Real.exp x) ^ m = Real.exp 1 ^ d := by\n rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]\n congr 1\n rw [hx]\n field_simp\n linarith [h1, h2.le, h2.ge]\n have hfin : ((∑ k ∈ Finset.Iic d, (m.choose k) : ℕ) : ℝ) ≤ (Real.exp 1) ^ d / x ^ d := by\n calc ((∑ k ∈ Finset.Iic d, (m.choose k) : ℕ) : ℝ)\n ≤ ∑ k ∈ Finset.Iic d, ((m.choose k : ℝ) * x ^ k) / x ^ d := step1\n _ = (∑ k ∈ Finset.Iic d, ((m.choose k : ℝ) * x ^ k)) / x ^ d := by\n rw [Finset.sum_div]\n _ ≤ (Real.exp 1) ^ d / x ^ d := by\n apply div_le_div_of_nonneg_right _ (by positivity)\n linarith [step2, step3.le, step3.ge, step4]\n refine hfin.trans (le_of_eq ?_)\n rw [hx, div_pow, div_div_eq_mul_div, mul_div_assoc, div_pow, mul_pow, mul_div_assoc]\n\n/-- Sauer-Shelah in the form we need. -/\nlemma card_le_of_vcDim {β : Type*} [DecidableEq β] [Fintype β] (A : Finset (Finset β)) (d : ℕ)\n (hvc : A.vcDim ≤ d) : A.card ≤ ∑ k ∈ Finset.Iic d, (Fintype.card β).choose k := by\n refine le_trans A.card_le_card_shatterer ?_\n refine le_trans Finset.card_shatterer_le_sum_vcDim ?_\n exact Finset.sum_le_sum_of_subset (Finset.Iic_subset_Iic.mpr hvc)\n\n/-- **Packing bound** for families of bounded VC dimension. -/\nlemma packing_bound (Q : Finset (Finset α)) (d : ℕ) (hd : 1 ≤ d) (hvc : Q.vcDim ≤ d)\n (a : ℝ) (ha0 : 0 < a) (ha1 : a ≤ 1)\n (hsep : ∀ s ∈ Q, ∀ t ∈ Q, s ≠ t → a * (Fintype.card α) < ((s ∆ t).card : ℝ)) :\n (Q.card : ℝ) ≤ (3/a) ^ (4*d) := by\n classical\n by_contra hcon\n push_neg at hcon\n set B : ℝ := (3/a) ^ (4*d) with hBdef\n have hu1 : (1:ℝ) ≤ 3/a := by rw [le_div_iff₀ ha0]; linarith\n have h3a : (3:ℝ) ≤ 3/a := by rw [le_div_iff₀ ha0]; nlinarith\n have hB81 : (81:ℝ) ≤ B := by\n have h1 : (3:ℝ)^(4*d) ≤ (3/a)^(4*d) := by\n exact pow_le_pow_left₀ (by norm_num) h3a _\n have h2 : (81:ℝ) ≤ (3:ℝ)^(4*d) := by\n have : (3:ℝ)^(4*1) ≤ (3:ℝ)^(4*d) := by\n refine pow_le_pow_right₀ (by norm_num) (by omega)\n norm_num at this ⊢\n linarith\n linarith\n have hB0 : (0:ℝ) ≤ B := by linarith\n set M : ℕ := ⌊B⌋₊ + 1 with hMdef\n have hMle : M ≤ Q.card := by\n have := (Nat.floor_lt hB0).mpr hcon\n omega\n have hBM : B < (M:ℝ) := by\n rw [hMdef]; push_cast; exact Nat.lt_floor_add_one B\n have hMub : (M:ℝ) ≤ 2 * B := by\n have h1 : ((⌊B⌋₊ : ℕ) : ℝ) ≤ B := Nat.floor_le hB0\n rw [hMdef]; push_cast; linarith\n obtain ⟨T, hTQ, hTcard⟩ := Finset.le_card_iff_exists_subset_card.mp hMle\n have hM81 : (81:ℝ) ≤ (M:ℝ) := le_trans hB81 hBM.le\n have hM2 : 2 ≤ M := by\n have h2 : (2:ℝ) ≤ (M:ℝ) := by linarith\n exact_mod_cast h2\n -- α is nonempty\n have hαne : Nonempty α := by\n by_contra h\n rw [not_nonempty_iff] at h\n have hc : (Finset.univ : Finset (Finset α)).card = 1 := by\n rw [Finset.card_univ, Fintype.card_finset]\n have : Fintype.card α = 0 := Fintype.card_eq_zero\n rw [this]; norm_num\n have hle : T.card ≤ 1 := le_trans (Finset.card_le_univ T) (le_of_eq hc)\n omega\n -- basic facts about M\n have hM0 : (0:ℝ) < (M:ℝ) := by linarith\n have hlogM : 4 * (d:ℝ) * Real.log 3 ≤ Real.log M := by\n have h1 : Real.log B ≤ Real.log M := Real.log_le_log (by linarith) hBM.le\n have h2 : (4*d : ℕ) * Real.log 3 ≤ Real.log B := by\n rw [hBdef, Real.log_pow]\n have : Real.log 3 ≤ Real.log (3/a) := Real.log_le_log (by norm_num) h3a\n have h4 : (0:ℝ) ≤ ((4*d : ℕ):ℝ) := by positivity\n exact mul_le_mul_of_nonneg_left this h4\n push_cast at h2\n linarith\n have hlog3 : (1:ℝ) ≤ Real.log 3 := by\n have : Real.exp 1 ≤ 3 := by\n have := Real.exp_one_lt_d9\n linarith\n calc (1:ℝ) = Real.log (Real.exp 1) := by rw [Real.log_exp]\n _ ≤ Real.log 3 := Real.log_le_log (Real.exp_pos 1) this\n have hd0 : (0:ℝ) < (d:ℝ) := by exact_mod_cast hd\n have hlogM4 : 4 * (d:ℝ) ≤ Real.log M := by nlinarith\n -- choose the number of sampled coordinates\n set m : ℕ := ⌈2 * Real.log M / a⌉₊ + 1 with hmdef\n have hmlb : 2 * Real.log M / a + 1 ≤ (m:ℝ) := by\n have := Nat.le_ceil (2 * Real.log M / a)\n rw [hmdef]; push_cast; linarith\n have hmub : (m:ℝ) ≤ 2 * Real.log M / a + 2 := by\n have := Nat.ceil_lt_add_one (a := 2 * Real.log M / a)\n (by positivity)\n rw [hmdef]; push_cast; linarith\n have hdm : d ≤ m := by\n have h1 : (d:ℝ) ≤ (m:ℝ) := by\n have h2 : 2 * Real.log M / a ≥ 2 * Real.log M := by\n rw [ge_iff_le, le_div_iff₀ ha0]\n nlinarith [Real.log_nonneg (by linarith : (1:ℝ) ≤ (M:ℝ))]\n nlinarith\n exact_mod_cast h1\n -- the separated family restricted to `m` coordinates is injective\n set q : ℝ := 1 - a with hqdef\n have hq0 : 0 ≤ q := by rw [hqdef]; linarith\n have hqm : q ^ m ≤ Real.exp (-(a * m)) := by\n calc q ^ m ≤ (Real.exp (-a)) ^ m := by\n refine pow_le_pow_left₀ hq0 ?_ m\n have := Real.add_one_le_exp (-a)\n rw [hqdef]; linarith\n _ = Real.exp (-(a * m)) := by\n rw [← Real.exp_nat_mul]; congr 1; ring\n have hkey : (T.card : ℝ) * (T.card : ℝ) * q ^ m < 1 := by\n have hexp : Real.exp (-(a * m)) < (M:ℝ)⁻¹ * (M:ℝ)⁻¹ := by\n have h1 : 2 * Real.log M + a ≤ a * m := by\n have : a * (2 * Real.log M / a + 1) ≤ a * m := by\n exact mul_le_mul_of_nonneg_left hmlb ha0.le\n rw [mul_add, mul_div_cancel₀ _ (ne_of_gt ha0), mul_one] at this\n linarith\n have h2 : Real.exp (-(a*m)) ≤ Real.exp (-(2 * Real.log M + a)) := by\n apply Real.exp_le_exp.mpr; linarith\n have h3 : Real.exp (-(2 * Real.log M + a)) = (M:ℝ)⁻¹ * (M:ℝ)⁻¹ * Real.exp (-a) := by\n rw [show -(2 * Real.log M + a) = (-Real.log M) + (-Real.log M) + (-a) by ring]\n rw [Real.exp_add, Real.exp_add, Real.exp_neg, Real.exp_neg, Real.exp_log hM0]\n have h4 : Real.exp (-a) < 1 := by\n rw [Real.exp_lt_one_iff]; linarith\n have h5 : (0:���) < (M:ℝ)⁻¹ * (M:ℝ)⁻¹ := by positivity\n nlinarith\n have hTc : (T.card : ℝ) = (M:ℝ) := by rw [hTcard]\n rw [hTc]\n calc (M:ℝ) * (M:ℝ) * q ^ m ≤ (M:ℝ) * (M:ℝ) * Real.exp (-(a*m)) := by\n have : (0:ℝ) ≤ (M:ℝ) * (M:ℝ) := by positivity\n nlinarith\n _ < (M:ℝ) * (M:ℝ) * ((M:ℝ)⁻¹ * (M:ℝ)⁻¹) := by\n have : (0:ℝ) < (M:ℝ) * (M:ℝ) := by positivity\n exact mul_lt_mul_of_pos_left hexp this\n _ = 1 := by field_simp\n have hsepT : ∀ s ∈ T, ∀ t ∈ T, s ≠ t →\n ((Fintype.card α - (s ∆ t).card : ℕ) : ℝ) ≤ q * Fintype.card α := by\n intro s hs t ht hst\n have hlt := hsep s (hTQ hs) t (hTQ ht) hst\n have hle : (s ∆ t).card ≤ Fintype.card α :=\n (Finset.card_le_univ (s ∆ t)).trans_eq Finset.card_univ\n have hcast : ((Fintype.card α - (s ∆ t).card : ℕ) : ℝ)\n = (Fintype.card α : ℝ) - ((s ∆ t).card : ℝ) := by\n push_cast [hle]; ring\n have hring : q * (Fintype.card α : ℝ)\n = (Fintype.card α : ℝ) - a * (Fintype.card α : ℝ) := by rw [hqdef]; ring\n rw [hcast, hring]\n linarith\n obtain ⟨φ, hφ⟩ := exists_injOn_restr T m q hq0 hsepT hkey\n -- conclude by Sauer-Shelah on `Fin m`\n have hinj : Set.InjOn (restr φ) T := by\n intro s hs t ht h\n exact hφ s hs t ht h\n have hcardeq : (T.image (restr φ)).card = M := by\n rw [Finset.card_image_of_injOn hinj, hTcard]\n have hvcT : (T.image (restr φ)).vcDim ≤ d :=\n le_trans (vcDim_image_restr_le φ T) (le_trans (Finset.vcDim_mono hTQ) hvc)\n have hsauer : M ≤ ∑ k ∈ Finset.Iic d, m.choose k := by\n rw [← hcardeq]\n have := card_le_of_vcDim (T.image (restr φ)) d hvcT\n simpa using this\n have hMle2 : (M:ℝ) ≤ (Real.exp 1 * m / d) ^ d := by\n refine le_trans ?_ (sum_choose_le d m hd hdm)\n exact_mod_cast hsauer\n -- numeric contradiction\n have hexp1 : Real.exp 1 ≤ 2.7182818286 := le_of_lt Real.exp_one_lt_d9\n have hlog3u : Real.log 3 ≤ 2 := by\n have : Real.log 3 ≤ 3 - 1 := Real.log_le_sub_one_of_pos (by norm_num)\n linarith\n have hkeynum : Real.exp 1 * (m:ℝ) / d ≤ (3/a) ^ 4 := by\n have hloga : Real.log (3/a) ≤ 3/a - 1 := Real.log_le_sub_one_of_pos (by positivity)\n have hlogMub : Real.log M ≤ Real.log 2 + 4 * d * Real.log (3/a) := by\n have h1 : Real.log M ≤ Real.log (2*B) := Real.log_le_log hM0 hMub\n have h2 : Real.log (2*B) = Real.log 2 + Real.log B := by\n rw [Real.log_mul (by norm_num) (by linarith)]\n have h3 : Real.log B = (4*d : ℕ) * Real.log (3/a) := by\n rw [hBdef, Real.log_pow]\n rw [h2, h3] at h1\n push_cast at h1\n linarith\n have hlog2 : Real.log 2 ≤ 1 := by\n have : Real.log 2 ≤ 2 - 1 := Real.log_le_sub_one_of_pos (by norm_num)\n linarith\n have hd1 : (1:ℝ) ≤ (d:ℝ) := by exact_mod_cast hd\n have hainv : (1:ℝ) ≤ 1/a := by rw [le_div_iff₀ ha0]; linarith\n have h3ainv : 3/a = 3 * (1/a) := by ring\n -- m ≤ 2 (1 + 4 d (3/a)) / a + 2\n have hmb : (m:ℝ) ≤ 2 * (1 + 4 * d * (3/a)) * (1/a) + 2 := by\n have : 2 * Real.log M / a ≤ 2 * (1 + 4 * d * (3/a)) * (1/a) := by\n rw [div_eq_mul_one_div]\n refine mul_le_mul_of_nonneg_right ?_ (by positivity)\n nlinarith\n linarith\n set u : ℝ := 1/a with hu\n have hu1' : (1:ℝ) ≤ u := hainv\n have h3au : 3/a = 3*u := by rw [hu]; ring\n rw [h3au] at hmb ⊢\n have hfinal : Real.exp 1 * (m:ℝ) / d ≤ 80 * u^2 := by\n rw [div_le_iff₀ hd0]\n have hm2 : (m:ℝ) ≤ 2 * (1 + 12 * d * u) * u + 2 := by\n have h12 : 4 * (d:ℝ) * (3*u) = 12 * d * u := by ring\n linarith [hmb, h12]\n have he : Real.exp 1 * (m:ℝ) ≤ 2.7182818286 * (2 * (1 + 12 * d * u) * u + 2) := by\n have hmpos : (0:ℝ) ≤ (m:ℝ) := by positivity\n nlinarith [Real.exp_pos 1]\n have hA : u ≤ u^2 * d := by nlinarith\n have hB2 : (1:ℝ) ≤ u^2 * d := by nlinarith\n nlinarith [he, hA, hB2]\n have h81 : 80 * u^2 ≤ (3*u)^4 := by\n have he4 : (3*u:ℝ)^4 = 81 * u^4 := by ring\n rw [he4]\n have h1 : (1:ℝ) ≤ u^2 := by nlinarith\n have h2 : u^2 ≤ u^2 * u^2 := by nlinarith [sq_nonneg u]\n nlinarith [h2, sq_nonneg u]\n linarith\n have hfin2 : (M:ℝ) ≤ ((3/a)^4) ^ d := by\n refine le_trans hMle2 ?_\n refine pow_le_pow_left₀ (by positivity) hkeynum d\n have heqB : ((3/a)^4) ^ d = B := by rw [hBdef, ← pow_mul]\n rw [heqB] at hfin2\n linarith\n\n/-- **Covering number bound**: a family of VC dimension at most `d` admits an\n`a·N`-net of size at most `(3/a)^(4d)` in the Hamming metric. -/\nlemma exists_net (A : Finset (Finset α)) (d : ℕ) (hd : 1 ≤ d) (hvc : A.vcDim ≤ d)\n (a : ℝ) (ha0 : 0 < a) (ha1 : a ≤ 1) :\n ∃ T ⊆ A, (T.card : ℝ) ≤ (3/a) ^ (4*d) ∧\n ∀ s ∈ A, ∃ t ∈ T, ((s ∆ t).card : ℝ) ≤ a * Fintype.card α := by\n classical\n set S : Finset (Finset (Finset α)) :=\n A.powerset.filter (fun T => ∀ s ∈ T, ∀ t ∈ T, s ≠ t → a * (Fintype.card α) < ((s ∆ t).card : ℝ))\n with hS\n have hSne : S.Nonempty := by\n refine ⟨∅, ?_⟩\n rw [hS, Finset.mem_filter]\n exact ⟨Finset.empty_mem_powerset A, by simp⟩\n obtain ⟨T, hTS, hTmax⟩ := Finset.exists_max_image S Finset.card hSne\n rw [hS, Finset.mem_filter, Finset.mem_powerset] at hTS\n obtain ⟨hTA, hTsep⟩ := hTS\n refine ⟨T, hTA, packing_bound T d hd (le_trans (Finset.vcDim_mono hTA) hvc) a ha0 ha1 hTsep, ?_⟩\n intro s hs\n by_contra hcon\n push_neg at hcon\n have hsT : s ∉ T := by\n intro hsT\n have := hcon s hsT\n simp only [symmDiff_self, Finset.bot_eq_empty, Finset.card_empty, Nat.cast_zero] at this\n have hnn : (0:ℝ) ≤ a * (Fintype.card α) := by positivity\n linarith\n have hmem : insert s T ∈ S := by\n rw [hS, Finset.mem_filter, Finset.mem_powerset]\n refine ⟨Finset.insert_subset hs hTA, ?_⟩\n intro x hx y hy hxy\n rw [Finset.mem_insert] at hx hy\n rcases hx with rfl | hx\n · rcases hy with rfl | hy\n · exact absurd rfl hxy\n · exact hcon y hy\n · rcases hy with rfl | hy\n · have h := hcon x hx\n rwa [symmDiff_comm] at h\n · exact hTsep x hx y hy hxy\n have := hTmax _ hmem\n rw [Finset.card_insert_of_notMem hsT] at this\n omega\n\nend VCcomb\n\nopen MeasureTheory\nnamespace Chaining\n\nlemma geom_sum_le_inv (r : ℝ) (h0 : 0 ≤ r) (h1 : r < 1) (n : ℕ) :\n ∑ k ∈ Finset.range n, r^k ≤ (1-r)⁻¹ := by\n have h2 : (0:ℝ) < 1 - r := by linarith\n have hmul : (∑ k ∈ Finset.range n, r^k) * (r - 1) = r^n - 1 := geom_sum_mul r n\n have hpos : (0:ℝ) ≤ r^n := by positivity\n rw [inv_eq_one_div, le_div_iff₀ h2]\n nlinarith [hmul, hpos]\n\nlemma sqrt_le_of_sq_le (x y : ℝ) (hy : 0 ≤ y) (h : x ≤ y^2) : Real.sqrt x ≤ y :=\n (Real.sqrt_le_sqrt h).trans_eq (Real.sqrt_sq hy)\n\n/-- Triangle inequality for the Hamming distance. -/\nlemma card_symmDiff_triangle {α : Type*} [DecidableEq α] (s t u : Finset α) :\n (s ∆ u).card ≤ (s ∆ t).card + (t ∆ u).card := by\n have hsub : s ∆ u ⊆ (s ∆ t) ∪ (t ∆ u) := by\n intro a ha\n simp only [Finset.mem_symmDiff, Finset.mem_union] at ha ⊢\n tauto\n exact le_trans (Finset.card_le_card hsub) (Finset.card_union_le _ _)\n\nvariable {α : Type*} [DecidableEq α] [Fintype α]\n\ntheorem chaining_tail\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n (A : Finset (Finset α)) (u₀ : Finset α) (hu₀ : u₀ ∈ A)\n (d : ℕ) (hd : 1 ≤ d) (hvc : A.vcDim ≤ d)\n (hN : 1 ≤ Fintype.card α)\n (Y : Finset α → Ω → ℝ)\n (hsub : ∀ u ∈ A, ∀ v ∈ A, ∀ B : ℝ, 0 < B → ((u ∆ v).card : ℝ) ≤ B →\n ∀ x : ℝ, 0 ≤ x → P.real {ω | x ≤ Y u ω - Y v ω} ≤ Real.exp (-(x^2)/(4*B)))\n (lam : ℝ) (hlam : 0 ≤ lam) :\n P.real {ω | ∃ u ∈ A, 128 * Real.sqrt ((Fintype.card α : ℝ) * ((d:ℝ) + lam))\n < |Y u ω - Y u₀ ω|} ≤ Real.exp (-lam) := by\n classical\n set Nn := Fintype.card α with hNn\n have hNr : (1:ℝ) ≤ (Nn:ℝ) := by exact_mod_cast hN\n have hd1 : (1:ℝ) ≤ (d:ℝ) := by exact_mod_cast hd\n -- ## Step 1: nets at all dyadic scales\n have hnet : ∀ k : ℕ, ∃ (T : Finset (Finset α)) (p : Finset α → Finset α),\n T ⊆ A ∧ ((T.card : ℝ) ≤ (3 * 2^k)^(4*d)) ∧ (∀ s, p s ∈ T) ∧\n (∀ s ∈ A, ((s ∆ p s).card : ℝ) ≤ (Nn:ℝ) * (1/2)^k) ∧ (k = 0 → ∀ s, p s = u₀) := by\n intro k\n rcases Nat.eq_zero_or_pos k with rfl | hk\n · refine ⟨{u₀}, fun _ => u₀, ?_, ?_, ?_, ?_, ?_⟩\n · simpa using hu₀\n · simp only [Finset.card_singleton, Nat.cast_one, pow_zero, mul_one]\n exact one_le_pow₀ (by norm_num)\n · intro s; simp\n · intro s hs\n simp only [pow_zero, mul_one]\n exact_mod_cast (Finset.card_le_univ (s ∆ u₀)).trans_eq Finset.card_univ\n · intro _ _; rfl\n · have ha1 : ((1:ℝ)/2)^k ≤ 1 := pow_le_one₀ (by norm_num) (by norm_num)\n obtain ⟨T, hTA, hTcard, hTnet⟩ :=\n VCcomb.exists_net A d hd hvc ((1/2:ℝ)^k) (by positivity) ha1\n have hp : ∀ s : Finset α, ∃ t, t ∈ T ∧ (s ∈ A → ((s ∆ t).card:ℝ) ≤ (Nn:ℝ)*(1/2)^k) := by\n intro s\n by_cases hs : s ∈ A\n · obtain ⟨t, ht, hdist⟩ := hTnet s hs\n exact ⟨t, ht, fun _ => by rw [mul_comm] at hdist; exact hdist⟩\n · obtain ⟨t, ht, _⟩ := hTnet u₀ hu₀\n exact ⟨t, ht, fun h => absurd h hs⟩\n choose p hp1 hp2 using hp\n refine ⟨T, p, hTA, ?_, hp1, hp2, fun h => absurd h (by omega)⟩\n refine le_trans hTcard (le_of_eq ?_)\n congr 1\n rw [div_pow, one_pow, div_div_eq_mul_div, div_one]\n choose T p hTA hTcard hpT hpnet hp0 using hnet\n -- ## Step 2: parameters\n set bd : ℕ → ℝ := fun k => 3 * (Nn:ℝ) * (1/2)^(k+1) with hbd\n set xx : ℕ → ℝ := fun k => Real.sqrt (6 * (Nn:ℝ) * (1/2)^k * (lam + 8*(d:ℝ)*(k+2))) with hxx\n have hbd0 : ∀ k, 0 < bd k := by intro k; rw [hbd]; positivity\n have hxx0 : ∀ k, 0 ≤ xx k := by intro k; rw [hxx]; exact Real.sqrt_nonneg _\n have hxxsq : ∀ k, (xx k)^2 = 6 * (Nn:ℝ) * (1/2)^k * (lam + 8*(d:ℝ)*(k+2)) := by\n intro k\n rw [hxx]\n refine Real.sq_sqrt ?_\n positivity\n -- ## Step 3: the bad events\n set E : ℕ → Set Ω := fun k =>\n ⋃ t ∈ T k, ⋃ t' ∈ T (k+1),\n {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|} with hE\n have hpairbd : ∀ (k : ℕ) (t : Finset α), t ∈ T k → ∀ t' ∈ T (k+1),\n P.real {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|}\n ≤ 2 * Real.exp (-(lam + 8*(d:ℝ)*(k+2))) := by\n intro k t ht t' ht'\n by_cases hdist : ((t ∆ t').card : ℝ) ≤ bd k\n · have hexp : -(xx k)^2 / (4 * bd k) = -(lam + 8*(d:ℝ)*(k+2)) := by\n rw [hxxsq k, hbd]\n have h2 : (4:ℝ) * (3 * (Nn:ℝ) * (1/2)^(k+1)) = 6 * (Nn:ℝ) * (1/2)^k := by\n rw [pow_succ]\n ring\n rw [h2]\n field_simp\n have hs1 := hsub t' (hTA _ ht') t (hTA _ ht) (bd k) (hbd0 k) (by\n rwa [symmDiff_comm]) (xx k) (hxx0 k)\n have hs2 := hsub t (hTA _ ht) t' (hTA _ ht') (bd k) (hbd0 k) hdist (xx k) (hxx0 k)\n rw [hexp] at hs1 hs2\n have hsubset : {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|}\n ⊆ {ω | xx k ≤ Y t' ω - Y t ω} ∪ {ω | xx k ≤ Y t ω - Y t' ω} := by\n intro ω hω\n obtain ⟨-, hlt⟩ := hω\n rcases abs_cases (Y t' ω - Y t ω) with ⟨he, _⟩ | ⟨he, _⟩\n · left; simp only [Set.mem_setOf_eq]; rw [he] at hlt; linarith\n · right; simp only [Set.mem_setOf_eq]; rw [he] at hlt; linarith\n calc P.real {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|}\n ≤ P.real ({ω | xx k ≤ Y t' ω - Y t ω} ∪ {ω | xx k ≤ Y t ω - Y t' ω}) :=\n measureReal_mono hsubset\n _ ≤ P.real {ω | xx k ≤ Y t' ω - Y t ω} + P.real {ω | xx k ≤ Y t ω - Y t' ω} :=\n measureReal_union_le _ _\n _ ≤ 2 * Real.exp (-(lam + 8*(d:ℝ)*(k+2))) := by linarith\n · have : {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|} = ∅ := by\n ext ω; simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]\n rintro ⟨h, -⟩; exact hdist h\n rw [this]\n simp only [measureReal_empty]\n positivity\n -- ## Step 4: measure of each bad event\n have hl2' : (0:ℝ) ≤ Real.log 2 := Real.log_nonneg (by norm_num)\n have hl2 : Real.log 2 ≤ 0.6932 := by\n have := Real.log_two_lt_d9; linarith\n have hl3 : Real.log 3 ≤ 2 * Real.log 2 := by\n have h4 : Real.log 3 ≤ Real.log 4 := Real.log_le_log (by norm_num) (by norm_num)\n have h5 : Real.log 4 = 2 * Real.log 2 := by\n rw [show (4:ℝ) = 2^2 by norm_num, Real.log_pow]; push_cast; ring\n linarith\n have hEbd : ∀ k : ℕ, P.real (E k) ≤ Real.exp (-lam) * (1/2)^(k+2) := by\n intro k\n have h1 : P.real (E k) ≤ ∑ t ∈ T k, P.real (⋃ t' ∈ T (k+1),\n {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|}) := by\n rw [hE]; exact measureReal_biUnion_finset_le _ _\n have h2 : ∀ t ∈ T k, P.real (⋃ t' ∈ T (k+1),\n {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|})\n ≤ ((T (k+1)).card : ℝ) * (2 * Real.exp (-(lam + 8*(d:ℝ)*(k+2)))) := by\n intro t ht\n refine le_trans (measureReal_biUnion_finset_le _ _) ?_\n calc ∑ t' ∈ T (k+1), P.real {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|}\n ≤ ∑ _t' ∈ T (k+1), 2 * Real.exp (-(lam + 8*(d:ℝ)*(k+2))) :=\n Finset.sum_le_sum (fun t' ht' => hpairbd k t ht t' ht')\n _ = ((T (k+1)).card : ℝ) * (2 * Real.exp (-(lam + 8*(d:ℝ)*(k+2)))) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n have h3 : P.real (E k) ≤ ((T k).card : ℝ) *\n (((T (k+1)).card : ℝ) * (2 * Real.exp (-(lam + 8*(d:ℝ)*(k+2))))) := by\n refine le_trans h1 ?_\n calc ∑ t ∈ T k, P.real (⋃ t' ∈ T (k+1),\n {ω | ((t ∆ t').card : ℝ) ≤ bd k ∧ xx k < |Y t' ω - Y t ω|})\n ≤ ∑ _t ∈ T k, ((T (k+1)).card : ℝ) * (2 * Real.exp (-(lam + 8*(d:ℝ)*(k+2)))) :=\n Finset.sum_le_sum h2\n _ = _ := by rw [Finset.sum_const, nsmul_eq_mul]\n refine le_trans h3 ?_\n -- numeric bound\n set W : ℝ := 2 * (3 * 2^k)^(4*d) * (3 * 2^(k+1))^(4*d) * 2^(k+2) with hW\n have hW0 : (0:ℝ) < W := by rw [hW]; positivity\n have hlogW : Real.log W ≤ 8 * (d:ℝ) * (k+2) := by\n have e1 : Real.log W = Real.log 2 + (4*d : ℕ) * Real.log (3 * 2^k)\n + (4*d : ℕ) * Real.log (3 * 2^(k+1)) + (k+2 : ℕ) * Real.log 2 := by\n rw [hW]\n rw [Real.log_mul (by positivity) (by positivity), Real.log_mul (by positivity)\n (by positivity), Real.log_mul (by positivity) (by positivity),\n Real.log_pow, Real.log_pow, Real.log_pow]\n have e2 : Real.log (3 * 2^k) = Real.log 3 + k * Real.log 2 := by\n rw [Real.log_mul (by norm_num) (by positivity), Real.log_pow]\n have e3 : Real.log (3 * 2^(k+1)) = Real.log 3 + (k+1 : ℕ) * Real.log 2 := by\n rw [Real.log_mul (by norm_num) (by positivity), Real.log_pow]\n rw [e1, e2, e3]\n push_cast\n have hk0 : (0:ℝ) ≤ (k:ℝ) := by positivity\n nlinarith [hl2, hl2', hl3, hd1, hk0, mul_nonneg hk0 (sub_nonneg.mpr hd1)]\n have hWexp : W ≤ Real.exp (8 * (d:ℝ) * (k+2)) := by\n rw [← Real.log_le_iff_le_exp hW0]; exact hlogW\n have hTk : ((T k).card : ℝ) ≤ (3 * 2^k)^(4*d) := hTcard k\n have hTk1 : ((T (k+1)).card : ℝ) ≤ (3 * 2^(k+1))^(4*d) := hTcard (k+1)\n have hexpsplit : Real.exp (-(lam + 8*(d:ℝ)*(k+2)))\n = Real.exp (-lam) * (Real.exp (8*(d:ℝ)*((k:ℝ)+2)))⁻¹ := by\n rw [← Real.exp_neg, ← Real.exp_add]\n congr 1\n ring\n rw [hexpsplit]\n have hexppos : (0:ℝ) < Real.exp (8*(d:ℝ)*((k:ℝ)+2)) := Real.exp_pos _\n have hkey : ((T k).card : ℝ) * (((T (k+1)).card : ℝ) * 2) * (Real.exp (8*(d:ℝ)*((k:ℝ)+2)))⁻¹\n ≤ (1/2)^(k+2) := by\n rw [mul_inv_le_iff₀ hexppos]\n have hWW : ((T k).card : ℝ) * (((T (k+1)).card : ℝ) * 2) ≤ W * ((1/2)^(k+2)) := by\n rw [hW]\n have h2k : (2:ℝ)^(k+2) * (1/2)^(k+2) = 1 := by\n rw [← mul_pow]; norm_num\n have : 2 * (3 * (2:ℝ)^k)^(4*d) * (3 * 2^(k+1))^(4*d) * 2^(k+2) * (1/2)^(k+2)\n = 2 * (3 * (2:ℝ)^k)^(4*d) * (3 * 2^(k+1))^(4*d) := by\n rw [mul_assoc (2 * (3 * (2:ℝ)^k)^(4*d) * (3 * 2^(k+1))^(4*d)), h2k, mul_one]\n rw [this]\n have hn1 : (0:ℝ) ≤ ((T (k+1)).card : ℝ) := by positivity\n have hn2 : (0:ℝ) ≤ (3 * (2:ℝ)^(k+1))^(4*d) := by positivity\n nlinarith [hTk, hTk1, Nat.cast_nonneg (α := ℝ) (T k).card]\n have hpow : (0:ℝ) ≤ (1/2:ℝ)^(k+2) := by positivity\n calc ((T k).card : ℝ) * (((T (k+1)).card : ℝ) * 2) ≤ W * ((1/2)^(k+2)) := hWW\n _ ≤ Real.exp (8*(d:ℝ)*((k:ℝ)+2)) * (1/2)^(k+2) := by\n have : W ≤ Real.exp (8*(d:ℝ)*((k:ℝ)+2)) := by\n refine le_trans hWexp (le_of_eq ?_); norm_num\n nlinarith [hpow]\n _ = (1/2)^(k+2) * Real.exp (8*(d:ℝ)*((k:ℝ)+2)) := by ring\n have hexpnn : (0:ℝ) ≤ Real.exp (-lam) := (Real.exp_pos _).le\n calc ((T k).card : ℝ) * (((T (k+1)).card : ℝ) *\n (2 * (Real.exp (-lam) * (Real.exp (8*(d:ℝ)*((k:ℝ)+2)))⁻¹)))\n = Real.exp (-lam) * (((T k).card : ℝ) * (((T (k+1)).card : ℝ) * 2)\n * (Real.exp (8*(d:ℝ)*((k:ℝ)+2)))⁻¹) := by ring\n _ ≤ Real.exp (-lam) * (1/2)^(k+2) := by\n exact mul_le_mul_of_nonneg_left hkey hexpnn\n -- ## Step 5: total measure of the union of bad events\n have hUnion : P.real (⋃ k ∈ Finset.range Nn, E k) ≤ Real.exp (-lam) := by\n refine le_trans (measureReal_biUnion_finset_le _ _) ?_\n have h1 : ∑ k ∈ Finset.range Nn, P.real (E k)\n ≤ ∑ k ∈ Finset.range Nn, Real.exp (-lam) * (1/2:ℝ)^(k+2) :=\n Finset.sum_le_sum (fun k _ => hEbd k)\n have h2 : ∑ k ∈ Finset.range Nn, Real.exp (-lam) * (1/2:ℝ)^(k+2)\n = Real.exp (-lam) * (1/4) * ∑ k ∈ Finset.range Nn, (1/2:ℝ)^k := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl fun k _ => ?_\n rw [pow_add]\n ring\n have h3 : ∑ k ∈ Finset.range Nn, (1/2:ℝ)^k ≤ 2 := by\n have := geom_sum_le_inv (1/2 : ℝ) (by norm_num) (by norm_num) Nn\n norm_num at this\n linarith\n have hexpnn : (0:ℝ) ≤ Real.exp (-lam) := (Real.exp_pos _).le\n have h4 : Real.exp (-lam) * (1/4) * ∑ k ∈ Finset.range Nn, (1/2:ℝ)^k\n ≤ Real.exp (-lam) * (1/4) * 2 := by\n refine mul_le_mul_of_nonneg_left h3 (by positivity)\n linarith [h1, h2.le, h2.ge, h4]\n -- ## Step 6: the chaining bound\n have hxxbd : ∀ k : ℕ, xx k ≤ 15 * (27/32:ℝ)^k * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) := by\n intro k\n rw [hxx]\n refine sqrt_le_of_sq_le _ _ (by positivity) ?_\n have hNL : (0:ℝ) ≤ (Nn:ℝ) * ((d:ℝ) + lam) := by positivity\n have hsq : (15 * (27/32:ℝ)^k * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)))^2\n = 225 * (729/1024:ℝ)^k * ((Nn:ℝ) * ((d:ℝ) + lam)) := by\n rw [mul_pow, mul_pow, Real.sq_sqrt hNL, ← pow_mul, mul_comm k 2, pow_mul]\n norm_num\n rw [hsq]\n -- bound the argument\n have hb1 : lam + 8*(d:ℝ)*((k:ℝ)+2) ≤ ((d:ℝ) + lam) * (8*(k:ℝ)+17) := by\n have hk0 : (0:ℝ) ≤ (k:ℝ) := by positivity\n nlinarith [hlam, hd1, mul_nonneg hlam hk0]\n have hb2 : 8*(k:ℝ)+17 ≤ 36 * (81/64:ℝ)^k := by\n have hbern : (1:ℝ) + k * (17/64) ≤ (1 + 17/64)^k := by\n have := one_add_mul_le_pow (a := (17/64:ℝ)) (by norm_num) k\n linarith\n norm_num at hbern\n nlinarith [hbern]\n have hb3 : ((1:ℝ)/2)^k * (81/64:ℝ)^k = (81/128:ℝ)^k := by\n rw [← mul_pow]; norm_num\n have hb4 : (81/128:ℝ)^k ≤ (729/1024:ℝ)^k :=\n pow_le_pow_left₀ (by norm_num) (by norm_num) k\n have hN0 : (0:ℝ) ≤ (Nn:ℝ) := by positivity\n have hpow0 : (0:ℝ) < ((1:ℝ)/2)^k := by positivity\n have hDL : (0:ℝ) ≤ (d:ℝ) + lam := by linarith\n calc 6 * (Nn:ℝ) * (1/2)^k * (lam + 8*(d:ℝ)*((k:ℝ)+2))\n ≤ 6 * (Nn:ℝ) * (1/2)^k * (((d:ℝ) + lam) * (8*(k:ℝ)+17)) := by\n have : (0:ℝ) ≤ 6 * (Nn:ℝ) * (1/2)^k := by positivity\n nlinarith [hb1]\n _ ≤ 6 * (Nn:ℝ) * (1/2)^k * (((d:ℝ) + lam) * (36 * (81/64:ℝ)^k)) := by\n have h0 : (0:ℝ) ≤ 6 * (Nn:ℝ) * (1/2)^k * ((d:ℝ) + lam) := by positivity\n nlinarith [hb2, h0]\n _ = 216 * (Nn:ℝ) * ((d:ℝ) + lam) * ((81/128:ℝ)^k) := by\n rw [← hb3]; ring\n _ ≤ 216 * (Nn:ℝ) * ((d:ℝ) + lam) * ((729/1024:ℝ)^k) := by\n have h0 : (0:ℝ) ≤ 216 * (Nn:ℝ) * ((d:ℝ) + lam) := by positivity\n nlinarith [hb4, h0]\n _ ≤ 225 * (729/1024:ℝ)^k * ((Nn:ℝ) * ((d:ℝ) + lam)) := by\n have h0 : (0:ℝ) ≤ (Nn:ℝ) * ((d:ℝ) + lam) := hNL\n have h1 : (0:ℝ) < (729/1024:ℝ)^k := by positivity\n nlinarith [h0, h1]\n have hsumxx : ∑ k ∈ Finset.range Nn, xx k\n ≤ 128 * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) := by\n have h1 : ∑ k ∈ Finset.range Nn, xx k\n ≤ ∑ k ∈ Finset.range Nn, 15 * (27/32:ℝ)^k * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) :=\n Finset.sum_le_sum (fun k _ => hxxbd k)\n have h2 : ∑ k ∈ Finset.range Nn, 15 * (27/32:ℝ)^k * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam))\n = 15 * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) * ∑ k ∈ Finset.range Nn, (27/32:ℝ)^k := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl fun k _ => ?_\n ring\n have h3 : ∑ k ∈ Finset.range Nn, (27/32:ℝ)^k ≤ 32/5 := by\n have := geom_sum_le_inv (27/32 : ℝ) (by norm_num) (by norm_num) Nn\n norm_num at this\n linarith\n have hs0 : (0:ℝ) ≤ Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) := Real.sqrt_nonneg _\n have h4 : 15 * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) * ∑ k ∈ Finset.range Nn, (27/32:ℝ)^k\n ≤ 15 * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) * (32/5) :=\n mul_le_mul_of_nonneg_left h3 (by positivity)\n nlinarith [h1, h2.le, h2.ge, h4, hs0]\n -- ## Step 7: inclusion\n have hincl : {ω | ∃ u ∈ A, 128 * Real.sqrt ((Nn:ℝ) * ((d:ℝ) + lam)) < |Y u ω - Y u₀ ω|}\n ⊆ ⋃ k ∈ Finset.range Nn, E k := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω\n obtain ⟨u, huA, hlt⟩ := hω\n by_contra hnot\n simp only [Set.mem_iUnion, exists_prop, not_exists, not_and] at hnot\n -- distances along the chain\n have hdistchain : ∀ k : ℕ, ((p k u ∆ p (k+1) u).card : ℝ) ≤ bd k := by\n intro k\n have t1 := hpnet k u huA\n have t2 := hpnet (k+1) u huA\n have t3 : (p k u ∆ p (k+1) u).card ≤ (p k u ∆ u).card + (u ∆ p (k+1) u).card :=\n card_symmDiff_triangle _ _ _\n have t4 : (p k u ∆ u).card = (u ∆ p k u).card := by rw [symmDiff_comm]\n have t5 : ((p k u ∆ p (k+1) u).card : ℝ)\n ≤ ((u ∆ p k u).card : ℝ) + ((u ∆ p (k+1) u).card : ℝ) := by\n rw [← t4]; exact_mod_cast t3\n have t6 : (Nn:ℝ) * (1/2)^k + (Nn:ℝ) * (1/2)^(k+1) = bd k := by\n rw [hbd, pow_succ]; ring\n linarith\n have hincr : ∀ k ∈ Finset.range Nn, |Y (p (k+1) u) ω - Y (p k u) ω| ≤ xx k := by\n intro k hk\n by_contra hcon\n push_neg at hcon\n refine hnot k hk ?_\n rw [hE]\n simp only [Set.mem_iUnion, exists_prop]\n exact ⟨p k u, hpT k u, p (k+1) u, hpT (k+1) u, hdistchain k, hcon⟩\n -- termination of the chain\n have hterm : p Nn u = u := by\n have h1 := hpnet Nn u huA\n have h2 : (Nn:ℝ) * (1/2:ℝ)^Nn < 1 := by\n have h3 : (Nn:ℝ) < 2^Nn := by\n have := Nat.lt_two_pow_self (n := Nn)\n exact_mod_cast this\n rw [div_pow, one_pow] at h1 ⊢\n rw [mul_one_div, div_lt_one (by positivity)]\n exact h3\n have h4 : ((u ∆ p Nn u).card : ℝ) < 1 := lt_of_le_of_lt h1 h2\n have h5 : (u ∆ p Nn u).card = 0 := by\n by_contra h6\n have : (1:ℝ) ≤ ((u ∆ p Nn u).card : ℝ) := by\n have : 1 ≤ (u ∆ p Nn u).card := Nat.one_le_iff_ne_zero.mpr h6\n exact_mod_cast this\n linarith\n have h7 : u ∆ p Nn u = ∅ := Finset.card_eq_zero.mp h5\n have h8 : u = p Nn u := by\n rwa [← Finset.bot_eq_empty, symmDiff_eq_bot] at h7\n exact h8.symm\n -- telescoping\n have htel : Y u ω - Y u₀ ω\n = ∑ k ∈ Finset.range Nn, (Y (p (k+1) u) ω - Y (p k u) ω) := by\n rw [Finset.sum_range_sub (f := fun k => Y (p k u) ω) Nn]\n rw [hterm, hp0 0 rfl u]\n have hbound : |Y u ω - Y u₀ ω| ≤ ∑ k ∈ Finset.range Nn, xx k := by\n rw [htel]\n refine le_trans (Finset.abs_sum_le_sum_abs _ _) ?_\n exact Finset.sum_le_sum hincr\n linarith [hbound, hsumxx]\n exact le_trans (measureReal_mono hincl (measure_ne_top P _)) hUnion\n\nend Chaining\n\nset_option maxHeartbeats 1000000\nopen scoped symmDiff ENNReal NNReal\nopen Finset MeasureTheory ProbabilityTheory\n\nnamespace RadDev\n\n/-! ## The Rademacher (sign) measure -/\n\n/-- The uniform measure on `Bool`. -/\nnoncomputable def signMeasure : Measure Bool :=\n (1/2 : ℝ≥0∞) • (Measure.dirac true + Measure.dirac false)\n\ninstance : IsProbabilityMeasure signMeasure := by\n constructor\n simp [signMeasure]\n exact ENNReal.inv_two_add_inv_two\n\nlemma integral_signMeasure (g : Bool → ℝ) :\n ∫ b, g b ∂signMeasure = (g true + g false) / 2 := by\n rw [signMeasure]\n rw [integral_smul_measure, integral_add_measure (by simp) (by simp), integral_dirac,\n integral_dirac]\n simp\n ring\n\n/-- The uniform measure on sign vectors. -/\nnoncomputable def signPi (n : ℕ) : Measure (Fin n → Bool) :=\n Measure.pi (fun _ => signMeasure)\n\ninstance (n : ℕ) : IsProbabilityMeasure (signPi n) := by\n unfold signPi; infer_instance\n\n/-- `sgn b = 1` if `b = false` and `-1` if `b = true`. -/\ndef sgn (b : Bool) : ℝ := if b then -1 else 1\n\nlemma sgn_mem_Icc (b : Bool) : sgn b ∈ Set.Icc (-1:ℝ) 1 := by\n cases b <;> norm_num [sgn]\n\nlemma integral_sgn_mul (v : ℝ) : ∫ b, sgn b * v ∂signMeasure = 0 := by\n rw [integral_signMeasure]\n simp [sgn]\n\nlemma integral_signPi_coord {n : ℕ} (j : Fin n) (g : Bool → ℝ) :\n ∫ σ, g (σ j) ∂(signPi n) = ∫ b, g b ∂signMeasure := by\n rw [← (measurePreserving_eval (fun _ : Fin n => signMeasure) j).map_eq,\n integral_map (measurable_pi_apply j).aemeasurable\n (Measurable.of_discrete (f := g)).aestronglyMeasurable]\n rfl\n\n/-- One-sided Hoeffding bound for Rademacher sums. -/\nlemma rademacher_tail {n : ℕ} (v : Fin n → ℝ) (u : ℝ) (hu : 0 ≤ u) :\n (signPi n).real {σ | u ≤ ∑ j, sgn (σ j) * v j}\n ≤ Real.exp (-u ^ 2 / (2 * ∑ j, (v j) ^ 2)) := by\n classical\n set X : Fin n → (Fin n → Bool) → ℝ := fun j σ => sgn (σ j) * v j with hX\n have hindep : iIndepFun X (signPi n) := by\n have := iIndepFun_pi (μ := fun _ : Fin n => signMeasure)\n (X := fun (j : Fin n) (b : Bool) => sgn b * v j)\n (fun j => (Measurable.of_discrete (f := fun b : Bool => sgn b * v j)).aemeasurable)\n exact this\n have hsubG : ∀ j : Fin n, HasSubgaussianMGF (X j) (‖v j‖₊ ^ 2) (signPi n) := by\n intro j\n have hmean : ∫ σ, X j σ ∂(signPi n) = 0 := by\n rw [hX]\n simp only\n rw [integral_signPi_coord j (fun b => sgn b * v j)]\n exact integral_sgn_mul (v j)\n have hbd : ∀ᵐ σ ∂(signPi n), X j σ ∈ Set.Icc (-|v j|) (|v j|) := by\n filter_upwards with σ\n rcases sgn_mem_Icc (σ j) with ⟨h1, h2⟩\n constructor\n · rcases le_or_lt 0 (v j) with h | h\n · nlinarith [abs_of_nonneg h]\n · nlinarith [abs_of_neg h]\n · rcases le_or_lt 0 (v j) with h | h\n · nlinarith [abs_of_nonneg h]\n · nlinarith [abs_of_neg h]\n have := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero\n (μ := signPi n) (X := X j)\n (Measurable.aemeasurable (by fun_prop)) hbd hmean\n have heq : (‖|v j| - -|v j|‖₊ / 2 : ℝ≥0) ^ 2 = ‖v j‖₊ ^ 2 := by\n have : |v j| - -|v j| = 2 * |v j| := by ring\n rw [this]\n congr 1\n rw [nnnorm_mul]\n simp [Real.nnnorm_abs]\n rwa [heq] at this\n have hmain := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hindep\n (c := fun j => ‖v j‖₊ ^ 2) (s := Finset.univ) (fun j _ => hsubG j) hu\n have hcast : ((∑ j : Fin n, ‖v j‖₊ ^ 2 : ℝ≥0) : ℝ) = ∑ j, (v j) ^ 2 := by\n push_cast\n refine Finset.sum_congr rfl fun j _ => ?_\n rw [Real.norm_eq_abs, sq_abs]\n rw [hcast] at hmain\n exact hmain\n\n\n/-! ## The Rademacher process attached to a double sample -/\n\n/-- Coordinatewise difference of the two halves of a trace set. -/\ndef phi {n : ℕ} (u : Finset (Fin n ⊕ Fin n)) (j : Fin n) : ℝ :=\n (if Sum.inl j ∈ u then (1:ℝ) else 0) - (if Sum.inr j ∈ u then (1:ℝ) else 0)\n\n/-- The Rademacher process attached to a trace set. -/\ndef Yproc {n : ℕ} (u : Finset (Fin n ⊕ Fin n)) (σ : Fin n → Bool) : ℝ :=\n ∑ j, sgn (σ j) * phi u j\n\n@[simp] lemma Yproc_empty {n : ℕ} (σ : Fin n → Bool) : Yproc (∅ : Finset (Fin n ⊕ Fin n)) σ = 0 := by\n simp [Yproc, phi]\n\nlemma sq_diff_ind {β : Type*} [DecidableEq β] (u v : Finset β) (x : β) :\n ((if x ∈ u then (1:ℝ) else 0) - (if x ∈ v then (1:ℝ) else 0))^2\n = (if x ∈ u ∆ v then (1:ℝ) else 0) := by\n by_cases h1 : x ∈ u <;> by_cases h2 : x ∈ v <;>\n simp [h1, h2, Finset.mem_symmDiff]\n\nlemma card_sum_split {n : ℕ} (S : Finset (Fin n ⊕ Fin n)) :\n ((S.card : ℝ)) = ∑ j : Fin n, ((if Sum.inl j ∈ S then (1:ℝ) else 0)\n + (if Sum.inr j ∈ S then (1:ℝ) else 0)) := by\n classical\n have h1 : ∑ x : Fin n ⊕ Fin n, (if x ∈ S then (1:ℝ) else 0) = (S.card : ℝ) := by\n rw [Finset.sum_ite_mem]\n simp\n rw [← h1, Fintype.sum_sum_type]\n rw [Finset.sum_add_distrib]\n\nlemma sum_sq_phi_le {n : ℕ} (u v : Finset (Fin n ⊕ Fin n)) :\n ∑ j : Fin n, (phi u j - phi v j)^2 ≤ 2 * (((u ∆ v).card : ℝ)) := by\n classical\n rw [card_sum_split, Finset.mul_sum]\n refine Finset.sum_le_sum fun j _ => ?_\n have e1 := sq_diff_ind u v (Sum.inl j)\n have e2 := sq_diff_ind u v (Sum.inr j)\n set a : ℝ := (if Sum.inl j ∈ u then (1:ℝ) else 0) - (if Sum.inl j ∈ v then (1:ℝ) else 0) with ha\n set b : ℝ := (if Sum.inr j ∈ u then (1:ℝ) else 0) - (if Sum.inr j ∈ v then (1:ℝ) else 0) with hb\n have hphi : phi u j - phi v j = a - b := by rw [ha, hb, phi, phi]; ring\n rw [hphi]\n have h2 : (a - b)^2 ≤ 2 * (a^2 + b^2) := by nlinarith [sq_nonneg (a+b)]\n rw [e1, e2] at h2\n linarith\n\nlemma Yproc_sub {n : ℕ} (u v : Finset (Fin n ⊕ Fin n)) (σ : Fin n → Bool) :\n Yproc u σ - Yproc v σ = ∑ j, sgn (σ j) * (phi u j - phi v j) := by\n rw [Yproc, Yproc, ← Finset.sum_sub_distrib]\n refine Finset.sum_congr rfl fun j _ => by ring\n\n/-- The sub-Gaussian increment bound for the Rademacher process. -/\nlemma Yproc_tail {n : ℕ} (u v : Finset (Fin n ⊕ Fin n)) (B : ℝ) (hB : 0 < B)\n (hdist : (((u ∆ v).card : ℝ)) ≤ B) (x : ℝ) (hx : 0 ≤ x) :\n (signPi n).real {σ | x ≤ Yproc u σ - Yproc v σ} ≤ Real.exp (-x^2/(4*B)) := by\n classical\n set c : Fin n → ℝ := fun j => phi u j - phi v j with hc\n have hset : {σ : Fin n → Bool | x ≤ Yproc u σ - Yproc v σ}\n = {σ | x ≤ ∑ j, sgn (σ j) * c j} := by\n ext σ; simp only [Set.mem_setOf_eq, hc, ← Yproc_sub]\n have hsum : ∑ j, (c j)^2 ≤ 2 * B := by\n have := sum_sq_phi_le u v\n have h2 : (2:ℝ) * (((u ∆ v).card : ℝ)) ≤ 2 * B := by linarith\n simp only [hc]\n linarith\n have hsum0 : 0 ≤ ∑ j, (c j)^2 := Finset.sum_nonneg fun j _ => sq_nonneg _\n rcases eq_or_lt_of_le hsum0 with heq | hpos\n · -- degenerate: all coefficients vanish\n have hzero : ∀ j, c j = 0 := by\n intro j\n have := (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => sq_nonneg (c j))).mp heq.symm j\n (Finset.mem_univ j)\n exact pow_eq_zero_iff (n := 2) (by norm_num) |>.mp this\n rcases eq_or_lt_of_le hx with hx0 | hx0\n · have : Real.exp (-x^2/(4*B)) = 1 := by\n rw [← hx0]; norm_num\n rw [this]\n calc (signPi n).real {σ : Fin n → Bool | x ≤ Yproc u σ - Yproc v σ}\n ≤ (signPi n).real Set.univ := measureReal_mono (Set.subset_univ _)\n (measure_ne_top _ _)\n _ = 1 := by simp [measureReal_def]\n · have hempty : {σ : Fin n → Bool | x ≤ Yproc u σ - Yproc v σ} = ∅ := by\n ext σ\n simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false, not_le]\n rw [Yproc_sub]\n have : ∑ j, sgn (σ j) * (phi u j - phi v j) = 0 := by\n refine Finset.sum_eq_zero fun j _ => ?_\n have := hzero j\n simp only [hc] at this\n rw [this, mul_zero]\n rw [this]\n linarith\n rw [hempty]\n simp only [measureReal_empty]\n positivity\n · rw [hset]\n refine le_trans (rademacher_tail c x hx) ?_\n refine Real.exp_le_exp.mpr ?_\n rw [neg_div, neg_div, neg_le_neg_iff]\n refine div_le_div_of_nonneg_left (sq_nonneg x) (by positivity) ?_\n linarith\n\n\n/-! ## Stubs (proved elsewhere) -/\n\nlemma vcDim_le_of_no_shatter {β : Type*} [DecidableEq β] [Fintype β]\n (A : Finset (Finset β)) (d : ℕ)\n (h : ∀ S : Finset β, S.card = d + 1 → ¬ A.Shatters S) : A.vcDim ≤ d := by\n unfold Finset.vcDim\n refine Finset.sup_le ?_\n intro S hS\n rw [Finset.mem_shatterer] at hS\n by_contra hcard\n have hle : d + 1 ≤ S.card := by omega\n obtain ⟨T, hTS, hTcard⟩ := Finset.le_card_iff_exists_subset_card.mp hle\n exact h T hTcard (hS.mono_right hTS)\n\nlemma vcDim_insert_le {β : Type*} [DecidableEq β] [Fintype β] (u₁ : Finset β)\n (A : Finset (Finset β)) : (insert u₁ A).vcDim ≤ A.vcDim + 1 := by\n unfold Finset.vcDim\n refine Finset.sup_le ?_\n intro S hS\n rw [Finset.mem_shatterer] at hS\n by_cases hSA : A.Shatters S\n · exact hSA.card_le_vcDim.trans (Nat.le_add_right _ _)\n by_cases hS0 : S = ∅\n · subst S\n simp\n obtain ⟨a, ha⟩ := Finset.nonempty_iff_ne_empty.mpr hS0\n have hErase : A.Shatters (S.erase a) := by\n intro T hT\n have hTS : T ⊆ S := hT.trans (Finset.erase_subset _ _)\n have haT : a ∉ T := by\n intro haT\n exact (Finset.mem_erase.mp (hT haT)).1 rfl\n obtain ⟨u, hu, huEq⟩ := hS hTS\n rcases Finset.mem_insert.mp hu with rfl | huA\n · obtain ⟨v, hv, hvEq⟩ := hS (Finset.insert_subset ha hTS)\n have hvA : v ∈ A := by\n rcases Finset.mem_insert.mp hv with rfl | hvA\n · have hbad : T = insert a T := huEq.symm.trans hvEq\n have : a ∈ T := by rw [hbad]; simp\n exact absurd this haT\n · exact hvA\n refine ⟨v, hvA, ?_⟩\n ext x\n have hx := Finset.ext_iff.mp hvEq x\n simp only [Finset.mem_inter, Finset.mem_erase, Finset.mem_insert] at hx ⊢\n constructor\n · rintro ⟨⟨hxa, hxS⟩, hxv⟩\n rcases hx.mp ⟨hxS, hxv⟩ with hxa' | hxT\n · exact absurd hxa' hxa\n · exact hxT\n · intro hxT\n have hxvS := hx.mpr (Or.inr hxT)\n exact ⟨⟨fun hxa => haT (hxa ▸ hxT), hxvS.1⟩, hxvS.2⟩\n · refine ⟨u, huA, ?_⟩\n ext x\n have hx := Finset.ext_iff.mp huEq x\n simp only [Finset.mem_inter, Finset.mem_erase] at hx ⊢\n constructor\n · rintro ⟨⟨_, hxS⟩, hxu⟩\n exact hx.mp ⟨hxS, hxu⟩\n · intro hxT\n have hxuS := hx.mpr hxT\n exact ⟨⟨fun hxa => haT (hxa ▸ hxT), hxuS.1⟩, hxuS.2⟩\n have hcard := hErase.card_le_vcDim\n unfold Finset.vcDim at hcard\n rw [Finset.card_erase_of_mem ha] at hcard\n omega\n\ntheorem chaining_tail {α : Type*} [DecidableEq α] [Fintype α]\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n (A : Finset (Finset α)) (u₀ : Finset α) (hu₀ : u₀ ∈ A)\n (d : ℕ) (hd : 1 ≤ d) (hvc : A.vcDim ≤ d)\n (hN : 1 ≤ Fintype.card α)\n (Y : Finset α → Ω → ℝ)\n (hsub : ∀ u ∈ A, ∀ v ∈ A, ∀ B : ℝ, 0 < B → ((u ∆ v).card : ℝ) ≤ B →\n ∀ x : ℝ, 0 ≤ x → P.real {ω | x ≤ Y u ω - Y v ω} ≤ Real.exp (-(x^2)/(4*B)))\n (lam : ℝ) (hlam : 0 ≤ lam) :\n P.real {ω | ∃ u ∈ A, 128 * Real.sqrt ((Fintype.card α : ℝ) * ((d:ℝ) + lam))\n < |Y u ω - Y u₀ ω|} ≤ Real.exp (-lam) :=\n Chaining.chaining_tail P A u₀ hu₀ d hd hvc hN Y hsub lam hlam\n\n/-! ## The conditional (Rademacher) bound -/\n\nopen Classical in\n/-- The trace of hypothesis `i` on the double sample `w`. -/\nnoncomputable def trace {Z : Type*} {ι : Type*} (f : ι → Z → Bool) {n : ℕ}\n (w : (Fin n ⊕ Fin n) → Z) (i : ι) : Finset (Fin n ⊕ Fin n) :=\n Finset.univ.filter (fun x => f i (w x) = true)\n\nlemma mem_trace {Z : Type*} {ι : Type*} (f : ι → Z → Bool) {n : ℕ}\n (w : (Fin n ⊕ Fin n) → Z) (i : ι) (x : Fin n ⊕ Fin n) :\n x ∈ trace f w i ↔ f i (w x) = true := by\n classical\n simp [trace]\n\ntheorem cond_bound {Z : Type*} {ι : Type*} (f : ι → Z → Bool)\n (G : Set Z) (d : ℕ) (hd : 1 ≤ d)\n (hvc : ∀ z : Fin (d+1) → Z, (∀ j, z j ∈ G) →\n ¬ ∀ v : Fin (d+1) → Bool, ∃ i, ∀ j, f i (z j) = v j)\n (n : ℕ) (hn : 0 < n) (w : (Fin n ⊕ Fin n) → Z) (hw : ∀ x, w x ∈ G)\n (lam : ℝ) (hlam : 0 ≤ lam) (r : ℝ)\n (hr : 128 * Real.sqrt ((2*(n:ℝ)) * (((d:ℝ)+1) + lam)) ≤ r) :\n (signPi n).real {σ | ∃ i : ι, r < |Yproc (trace f w i) σ|} ≤ Real.exp (-lam) := by\n classical\n set Tr : Finset (Finset (Fin n ⊕ Fin n)) :=\n Finset.univ.filter (fun u => ∃ i : ι, u = trace f w i) with hTr\n set A : Finset (Finset (Fin n ⊕ Fin n)) := insert ∅ Tr with hA\n have hemp : (∅ : Finset (Fin n ⊕ Fin n)) ∈ A := Finset.mem_insert_self _ _\n -- the trace family has VC dimension at most `d`\n have hvcTr : Tr.vcDim ≤ d := by\n refine vcDim_le_of_no_shatter Tr d ?_\n intro S hScard hSsh\n -- enumerate `S`\n set g : Fin (d+1) → (Fin n ⊕ Fin n) :=\n fun j => (S.equivFin.symm (Fin.cast hScard.symm j) : Fin n ⊕ Fin n) with hg\n have hginj : Function.Injective g := by\n intro j j' hjj'\n have : S.equivFin.symm (Fin.cast hScard.symm j) = S.equivFin.symm (Fin.cast hScard.symm j') :=\n Subtype.ext hjj'\n have h2 := S.equivFin.symm.injective this\n exact Fin.cast_injective hScard.symm h2\n have hgS : ∀ j, g j ∈ S := fun j => (S.equivFin.symm (Fin.cast hScard.symm j)).2\n refine hvc (fun j => w (g j)) (fun j => hw _) ?_\n intro v\n set T : Finset (Fin n ⊕ Fin n) :=\n Finset.image g (Finset.univ.filter (fun j => v j = true)) with hT\n have hTS : T ⊆ S := by\n intro x hx\n rw [hT, Finset.mem_image] at hx\n obtain ⟨j, -, rfl⟩ := hx\n exact hgS j\n obtain ⟨u, hu, hu2⟩ := hSsh hTS\n rw [hTr, Finset.mem_filter] at hu\n obtain ⟨-, i, rfl⟩ := hu\n refine ⟨i, fun j => ?_⟩\n have hiff : g j ∈ trace f w i ↔ v j = true := by\n constructor\n · intro hmem\n have : g j ∈ S ∩ trace f w i := Finset.mem_inter.mpr ⟨hgS j, hmem⟩\n rw [hu2, hT, Finset.mem_image] at this\n obtain ⟨j', hj', hj'2⟩ := this\n have : j' = j := hginj hj'2\n subst this\n exact (Finset.mem_filter.mp hj').2\n · intro hv\n have hmemT : g j ∈ T := by\n rw [hT, Finset.mem_image]\n exact ⟨j, Finset.mem_filter.mpr ⟨Finset.mem_univ j, hv⟩, rfl⟩\n rw [← hu2] at hmemT\n exact (Finset.mem_inter.mp hmemT).2\n rw [mem_trace] at hiff\n show f i (w (g j)) = v j\n revert hiff\n cases f i (w (g j)) <;> cases v j <;> simp\n have hvcA : A.vcDim ≤ d + 1 := by\n rw [hA]\n exact le_trans (vcDim_insert_le _ _) (by omega)\n have hcard : Fintype.card (Fin n ⊕ Fin n) = 2 * n := by\n simp [Fintype.card_sum]; ring\n have hNge : 1 ≤ Fintype.card (Fin n ⊕ Fin n) := by rw [hcard]; omega\n have hmain := chaining_tail (signPi n) A ∅ hemp (d+1) (by omega) hvcA hNge\n Yproc\n (fun u _ v _ B hB hdist x hx => Yproc_tail u v B hB hdist x hx)\n lam hlam\n refine le_trans (measureReal_mono ?_ (measure_ne_top _ _)) hmain\n intro σ hσ\n obtain ⟨i, hi⟩ := hσ\n refine ⟨trace f w i, ?_, ?_⟩\n · rw [hA]\n refine Finset.mem_insert_of_mem ?_\n rw [hTr, Finset.mem_filter]\n exact ⟨Finset.mem_univ _, i, rfl⟩\n · simp only [Yproc_empty, sub_zero]\n refine lt_of_le_of_lt ?_ hi\n refine le_trans (le_of_eq ?_) hr\n congr 2\n rw [hcard]\n push_cast\n ring\n\nend RadDev\n\n\nnamespace PACBridge\n\nopen MeasureTheory ProbabilityTheory\nopen scoped ENNReal NNReal symmDiff\nopen Finset\n\n/-- Coordinate-swapping involution associated to a Rademacher sign vector. -/\ndef swp {n : ℕ} (σ : Fin n → Bool) : (Fin n ⊕ Fin n) ≃ (Fin n ⊕ Fin n) where\n toFun := fun x => Sum.elim (fun j => if σ j then Sum.inr j else Sum.inl j)\n (fun j => if σ j then Sum.inl j else Sum.inr j) x\n invFun := fun x => Sum.elim (fun j => if σ j then Sum.inr j else Sum.inl j)\n (fun j => if σ j then Sum.inl j else Sum.inr j) x\n left_inv := by\n intro x\n cases x with\n | inl j => by_cases h : σ j = true <;> simp [h]\n | inr j => by_cases h : σ j = true <;> simp [h]\n right_inv := by\n intro x\n cases x with\n | inl j => by_cases h : σ j = true <;> simp [h]\n | inr j => by_cases h : σ j = true <;> simp [h]\n\n@[simp] lemma swp_inl {n : ℕ} (σ : Fin n → Bool) (j : Fin n) :\n swp σ (Sum.inl j) = if σ j then Sum.inr j else Sum.inl j := rfl\n\n@[simp] lemma swp_inr {n : ℕ} (σ : Fin n → Bool) (j : Fin n) :\n swp σ (Sum.inr j) = if σ j then Sum.inl j else Sum.inr j := rfl\n\nlemma phi_trace {Z : Type*} {ι : Type*} (f : ι → Z → Bool) {n : ℕ}\n (w : (Fin n ⊕ Fin n) → Z) (i : ι) (j : Fin n) :\n RadDev.phi (RadDev.trace f w i) j =\n UCdev.ind (f i (w (Sum.inl j))) - UCdev.ind (f i (w (Sum.inr j))) := by\n classical\n unfold RadDev.phi UCdev.ind\n rw [if_congr (RadDev.mem_trace f w i (Sum.inl j)) rfl rfl,\n if_congr (RadDev.mem_trace f w i (Sum.inr j)) rfl rfl]\n\n/-- Swapping the double sample turns its empirical difference into the Rademacher process. -/\nlemma emp_swap_eq {Z : Type*} {ι : Type*} (f : ι → Z → Bool) {n : ℕ} (hn : 0 < n)\n (w : (Fin n ⊕ Fin n) → Z) (i : ι) (σ : Fin n → Bool) :\n UCdev.empAvg (f i) (fun j => w (swp σ (Sum.inl j)))\n - UCdev.empAvg (f i) (fun j => w (swp σ (Sum.inr j)))\n = RadDev.Yproc (RadDev.trace f w i) σ / n := by\n classical\n unfold UCdev.empAvg RadDev.Yproc\n rw [div_sub_div_same, ← Finset.sum_sub_distrib]\n congr 1\n refine Finset.sum_congr rfl fun j _ => ?_\n rw [phi_trace]\n by_cases h : σ j = true\n · simp only [swp_inl, swp_inr, h, if_true, RadDev.sgn]\n ring\n · simp only [Bool.not_eq_true] at h\n simp only [swp_inl, swp_inr, h, RadDev.sgn, Bool.false_eq_true, if_false]\n ring\n\nend PACBridge\n\nnamespace PACMain\n\nopen MeasureTheory ProbabilityTheory\nopen scoped ENNReal NNReal symmDiff\nopen Finset\n\nnoncomputable def cUC : ℝ := 2 ^ 40\n\nlemma cUC_pos : (0 : ℝ) < cUC := by unfold cUC; positivity\nlemma cUC_ge_one : (1 : ℝ) ≤ cUC := by unfold cUC; norm_num\n\ntheorem uniform_convergence\n {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {ι : Type*} [Countable ι] (f : ι → Z → Bool) (hf : ∀ i, Measurable (f i))\n (G : Set Z) (hG : D Gᶜ = 0)\n (d : ℕ) (hd1 : 1 ≤ d)\n (hvc : ∀ z : Fin (d+1) → Z, (∀ j, z j ∈ G) →\n ¬ ∀ v : Fin (d+1) → Bool, ∃ i, ∀ j, f i (z j) = v j)\n (n : ℕ) (t lam : ℝ) (ht : 0 < t) (hlam : 0 ≤ lam)\n (hn : cUC * ((d:ℝ) + lam) ≤ n * t ^ 2) :\n 1 - Real.exp (-lam) ≤\n ((Measure.pi (fun _ : Fin n => D))\n {s : Fin n → Z | ∀ i : ι,\n |(((Finset.univ.filter (fun j => f i (s j) = true)).card : ℝ)) / n\n - (D {z | f i z = true}).toReal| ≤ t}).toReal := by\n classical\n set μ : Measure (Fin n → Z) := Measure.pi (fun _ : Fin n => D) with hμ\n set P : Measure ((Fin n ⊕ Fin n) → Z) := Measure.pi (fun _ : Fin n ⊕ Fin n => D) with hP\n set S : Measure (Fin n → Bool) := RadDev.signPi n with hS\n letI : IsProbabilityMeasure μ := by rw [hμ]; infer_instance\n letI : IsProbabilityMeasure P := by rw [hP]; infer_instance\n letI : IsProbabilityMeasure S := by rw [hS]; infer_instance\n have hdR : (1 : ℝ) ≤ (d : ℝ) := by exact_mod_cast hd1\n have hdl1 : (1 : ℝ) ≤ (d : ℝ) + lam := by linarith\n have hlhs : 0 < cUC * ((d : ℝ) + lam) :=\n mul_pos cUC_pos (lt_of_lt_of_le zero_lt_one hdl1)\n have hnprod : 0 < (n : ℝ) * t ^ 2 := lt_of_lt_of_le hlhs hn\n have hnR : (0 : ℝ) < n := by\n by_contra hn'\n have : (n : ℝ) = 0 :=\n le_antisymm (le_of_not_gt hn') (Nat.cast_nonneg n)\n rw [this, zero_mul] at hnprod\n exact lt_irrefl 0 hnprod\n have hn0 : 0 < n := by exact_mod_cast hnR\n have hnt8 : (8 : ℝ) ≤ (n : ℝ) * t ^ 2 := by\n have hmul := mul_le_mul (by unfold cUC; norm_num : (8 : ℝ) ≤ cUC) hdl1 (by norm_num : (0 : ℝ) ≤ 1)\n (le_of_lt cUC_pos)\n norm_num at hmul\n exact hmul.trans hn\n set Bad : Set (Fin n → Z) :=\n {s | ∃ i : ι, t < |UCdev.empAvg (f i) s - UCdev.riskOf D (f i)|} with hBad\n set Bad2 : Set ((Fin n → Z) × (Fin n → Z)) :=\n {q | ∃ i : ι, t/2 < |UCdev.empAvg (f i) q.1 - UCdev.empAvg (f i) q.2|} with hBad2\n have hBadm : MeasurableSet Bad := by\n have heq : Bad = ⋃ i : ι, {s | t < |UCdev.empAvg (f i) s - UCdev.riskOf D (f i)|} := by\n ext s\n simp [hBad]\n rw [heq]\n exact MeasurableSet.iUnion (fun i => measurableSet_lt measurable_const\n (((UCdev.measurable_empAvg (f i) (hf i)).sub measurable_const).abs))\n have hBad2m : MeasurableSet Bad2 := by\n have heq : Bad2 = ⋃ i : ι,\n {q | t/2 < |UCdev.empAvg (f i) q.1 - UCdev.empAvg (f i) q.2|} := by\n ext q\n simp [hBad2]\n rw [heq]\n refine MeasurableSet.iUnion (fun i => measurableSet_lt measurable_const ?_)\n exact (((UCdev.measurable_empAvg (f i) (hf i)).comp measurable_fst).sub\n ((UCdev.measurable_empAvg (f i) (hf i)).comp measurable_snd)).abs\n have hsymm : μ Bad ≤ 2 * (μ.prod μ) Bad2 := by\n simpa only [hμ, hBad, hBad2] using\n UCdev.symmetrization D f hf n hn0 t ht hnt8\n let e := MeasurableEquiv.sumPiEquivProdPi\n (fun _ : Fin n ⊕ Fin n => Z)\n set B : Set ((Fin n ⊕ Fin n) → Z) :=\n {w | ∃ i : ι, t/2 <\n |UCdev.empAvg (f i) (fun j => w (Sum.inl j)) -\n UCdev.empAvg (f i) (fun j => w (Sum.inr j))|} with hB\n have hBpre : B = e ⁻¹' Bad2 := by\n ext w\n rfl\n have hmp : MeasurePreserving e P (μ.prod μ) := by\n simpa only [hP, hμ] using\n (measurePreserving_sumPiEquivProdPi\n (fun _ : Fin n ⊕ Fin n => D))\n have hBm : MeasurableSet B := by\n rw [hBpre]\n exact hmp.measurable hBad2m\n have hPB : P B = (μ.prod μ) Bad2 := by\n rw [hBpre]\n exact hmp.measure_preimage hBad2m.nullMeasurableSet\n set swapAll :\n (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) → ((Fin n ⊕ Fin n) → Z) :=\n fun q x => q.1 (PACBridge.swp q.2 x) with hswapAll\n have hswapAllm : Measurable swapAll := by\n rw [measurable_pi_iff]\n intro x\n cases x with\n | inl j =>\n have hj : MeasurableSet\n {q : (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) | q.2 j = true} :=\n by\n change MeasurableSet\n ((fun q : (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) => q.2 j) ⁻¹'\n ({true} : Set Bool))\n exact ((measurable_pi_apply j).comp measurable_snd)\n (measurableSet_singleton true)\n change Measurable (fun q :\n (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) =>\n q.1 (if q.2 j then Sum.inr j else Sum.inl j))\n have heq : (fun q :\n (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) =>\n q.1 (if q.2 j then Sum.inr j else Sum.inl j)) =\n (fun q => if q.2 j = true then q.1 (Sum.inr j) else q.1 (Sum.inl j)) := by\n funext q\n cases q.2 j <;> simp\n rw [heq]\n exact Measurable.ite hj\n ((measurable_pi_apply (Sum.inr j)).comp measurable_fst)\n ((measurable_pi_apply (Sum.inl j)).comp measurable_fst)\n | inr j =>\n have hj : MeasurableSet\n {q : (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) | q.2 j = true} :=\n by\n change MeasurableSet\n ((fun q : (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) => q.2 j) ⁻¹'\n ({true} : Set Bool))\n exact ((measurable_pi_apply j).comp measurable_snd)\n (measurableSet_singleton true)\n change Measurable (fun q :\n (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) =>\n q.1 (if q.2 j then Sum.inl j else Sum.inr j))\n have heq : (fun q :\n (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) =>\n q.1 (if q.2 j then Sum.inl j else Sum.inr j)) =\n (fun q => if q.2 j = true then q.1 (Sum.inl j) else q.1 (Sum.inr j)) := by\n funext q\n cases q.2 j <;> simp\n rw [heq]\n exact Measurable.ite hj\n ((measurable_pi_apply (Sum.inl j)).comp measurable_fst)\n ((measurable_pi_apply (Sum.inr j)).comp measurable_fst)\n set E : Set (((Fin n ⊕ Fin n) → Z) × (Fin n → Bool)) := swapAll ⁻¹' B with hE\n have hEm : MeasurableSet E := by\n rw [hE]\n exact hswapAllm hBm\n have hEeq : (P.prod S) E = P B := by\n rw [Measure.prod_apply_symm hEm]\n have hsec : ∀ σ : Fin n → Bool,\n P ((fun w => (w, σ)) ⁻¹' E) = P B := by\n intro σ\n have hreindex :\n MeasurePreserving\n (fun w : (Fin n ⊕ Fin n) → Z => fun x => w (PACBridge.swp σ x)) P P := by\n simpa only [hP] using\n (UCdev.pi_map_reindex D (PACBridge.swp σ))\n have hpre : (fun w => (w, σ)) ⁻¹' E =\n (fun w : (Fin n ⊕ Fin n) → Z => fun x => w (PACBridge.swp σ x)) ⁻¹' B := by\n ext w\n rfl\n rw [hpre]\n exact hreindex.measure_preimage hBm.nullMeasurableSet\n simp_rw [hsec]\n simp\n set lam' : ℝ := lam + 1 with hlam'\n set r : ℝ := (n : ℝ) * t / 2 with hrdef\n have hlam'0 : 0 ≤ lam' := by rw [hlam']; linarith\n have hthreshold :\n 128 * Real.sqrt ((2*(n:ℝ)) * (((d:ℝ)+1) + lam')) ≤ r := by\n have hK :\n ((d : ℝ) + 1) + lam' ≤ 3 * ((d : ℝ) + lam) := by\n rw [hlam']\n linarith\n have hc : (393216 : ℝ) ≤ cUC := by\n unfold cUC\n norm_num\n have hbig :\n 131072 * (((d : ℝ) + 1) + lam') ≤ (n : ℝ) * t ^ 2 := by\n calc\n 131072 * (((d : ℝ) + 1) + lam')\n ≤ 393216 * ((d : ℝ) + lam) := by nlinarith\n _ ≤ cUC * ((d : ℝ) + lam) :=\n mul_le_mul_of_nonneg_right hc (by linarith)\n _ ≤ (n : ℝ) * t ^ 2 := hn\n have harg : 0 ≤ (2*(n:ℝ)) * (((d:ℝ)+1) + lam') := by\n have : 0 ≤ ((d : ℝ) + 1) + lam' := by positivity\n positivity\n have hsqrt :\n (128 * Real.sqrt ((2*(n:ℝ)) * (((d:ℝ)+1) + lam'))) ^ 2\n = 32768 * (n : ℝ) * (((d : ℝ) + 1) + lam') := by\n rw [mul_pow, Real.sq_sqrt harg]\n ring\n have hscaled := mul_le_mul_of_nonneg_left hbig (show 0 ≤ (n : ℝ) / 4 by positivity)\n have hsq :\n (128 * Real.sqrt ((2*(n:ℝ)) * (((d:ℝ)+1) + lam'))) ^ 2\n ≤ r ^ 2 := by\n rw [hsqrt, hrdef]\n nlinarith\n have hleft :\n 0 ≤ 128 * Real.sqrt ((2*(n:ℝ)) * (((d:ℝ)+1) + lam')) := by positivity\n have hright : 0 ≤ r := by rw [hrdef]; positivity\n nlinarith [sq_nonneg\n (128 * Real.sqrt ((2*(n:ℝ)) * (((d:ℝ)+1) + lam')) + r)]\n have hDae : ∀ᵐ z ∂D, z ∈ G := by\n rw [ae_iff]\n exact hG\n have hPae : ∀ᵐ w ∂P, ∀ x, w x ∈ G := by\n rw [ae_all_iff]\n intro x\n have hx := (measurePreserving_eval\n (fun _ : Fin n ⊕ Fin n => D) x).quasiMeasurePreserving.ae hDae\n simpa only [hP] using hx\n have hcondAE : ∀ᵐ w ∂P,\n S (Prod.mk w ⁻¹' E) ≤ ENNReal.ofReal (Real.exp (-lam')) := by\n filter_upwards [hPae] with w hw\n have hsub : Prod.mk w ⁻¹' E ⊆\n {σ : Fin n → Bool | ∃ i : ι, r < |RadDev.Yproc (RadDev.trace f w i) σ|} := by\n intro σ hσ\n change swapAll (w, σ) ∈ B at hσ\n rw [hB] at hσ\n obtain ⟨i, hi⟩ := hσ\n refine ⟨i, ?_⟩\n rw [hswapAll, PACBridge.emp_swap_eq f hn0 w i σ, abs_div, abs_of_pos hnR] at hi\n rw [hrdef]\n have himul := (lt_div_iff₀ hnR).mp hi\n nlinarith\n have hcb := RadDev.cond_bound f G d hd1 hvc n hn0 w hw lam' hlam'0 r hthreshold\n have hreal : S.real (Prod.mk w ⁻¹' E) ≤ Real.exp (-lam') := by\n refine (measureReal_mono hsub (measure_ne_top S _)).trans ?_\n simpa only [hS] using hcb\n rw [← ENNReal.ofReal_toReal (measure_ne_top S _)]\n exact ENNReal.ofReal_le_ofReal hreal\n have hEupper : (P.prod S) E ≤ ENNReal.ofReal (Real.exp (-lam')) := by\n rw [Measure.prod_apply hEm]\n calc\n (∫⁻ w, S (Prod.mk w ⁻¹' E) ∂P)\n ≤ ∫⁻ _w, ENNReal.ofReal (Real.exp (-lam')) ∂P :=\n lintegral_mono_ae hcondAE\n _ = ENNReal.ofReal (Real.exp (-lam')) := by simp\n have hPBen : P B ≤ ENNReal.ofReal (Real.exp (-lam')) := by\n rw [← hEeq]\n exact hEupper\n have hPBreal : P.real B ≤ Real.exp (-lam') := by\n rw [measureReal_def]\n calc\n (P B).toReal ≤ (ENNReal.ofReal (Real.exp (-lam'))).toReal :=\n ENNReal.toReal_mono (by simp) hPBen\n _ = Real.exp (-lam') := ENNReal.toReal_ofReal (Real.exp_pos _).le\n have hsymmReal : μ.real Bad ≤ 2 * (μ.prod μ).real Bad2 := by\n rw [measureReal_def, measureReal_def]\n have htop : 2 * (μ.prod μ) Bad2 ≠ ∞ := by\n exact ENNReal.mul_ne_top (by norm_num) (measure_ne_top _ _)\n have hle := ENNReal.toReal_mono htop hsymm\n simpa using hle\n have hbad : μ.real Bad ≤ Real.exp (-lam) := by\n have hbad2 : (μ.prod μ).real Bad2 ≤ Real.exp (-lam') := by\n rw [measureReal_def, ← hPB]\n simpa only [measureReal_def] using hPBreal\n have he : (2 : ℝ) * Real.exp (-1) ≤ 1 := by\n rw [Real.exp_neg, mul_inv_le_iff₀ (Real.exp_pos 1)]\n have := Real.add_one_le_exp (1 : ℝ)\n linarith\n have hexp : 2 * Real.exp (-lam') ≤ Real.exp (-lam) := by\n rw [hlam', show -(lam + 1) = -lam + -1 by ring, Real.exp_add]\n have hnonneg : 0 ≤ Real.exp (-lam) := (Real.exp_pos _).le\n nlinarith\n linarith\n have hemp : ∀ (i : ι) (s : Fin n → Z),\n UCdev.empAvg (f i) s =\n (((Finset.univ.filter (fun j => f i (s j) = true)).card : ℝ)) / n := by\n intro i s\n unfold UCdev.empAvg\n congr 1\n calc\n ∑ j, UCdev.ind (f i (s j)) =\n ∑ j, if f i (s j) = true then (1 : ℝ) else 0 := by\n refine Finset.sum_congr rfl (fun j _ => ?_)\n cases f i (s j) <;> simp [UCdev.ind]\n _ = ((Finset.univ.filter (fun j => f i (s j) = true)).card : ℝ) := by\n simp\n set Good : Set (Fin n → Z) :=\n {s | ∀ i : ι,\n |(((Finset.univ.filter (fun j => f i (s j) = true)).card : ℝ)) / n\n - (D {z | f i z = true}).toReal| ≤ t} with hGood\n have hGoodBad : Good = Badᶜ := by\n ext s\n simp only [hGood, hBad, Set.mem_setOf_eq, Set.mem_compl_iff, not_exists, not_lt,\n UCdev.riskOf, hemp]\n change 1 - Real.exp (-lam) ≤ μ.real Good\n rw [hGoodBad, measureReal_compl hBadm, probReal_univ]\n linarith\n\nend PACMain\n\nvariable {X : Type*} [MeasurableSpace X]\n\n/-- Existence of an empirical risk minimiser. -/\nprivate lemma exists_serm {H : Set (X → Bool)} (hH : H.Nonempty) (c : X → X → ℝ)\n (Δ : (X → Bool) → X → ℝ → X) (N : ℕ) (s : Fin N → X × Bool × ℝ) :\n ∃ h, IsSERM H c Δ h s := by\n classical\n set S : Set ℕ := {k : ℕ | ∃ h ∈ H, empStrategicLoss c Δ h s = k} with hS\n obtain ⟨h0, hh0⟩ := hH\n have hSne : S.Nonempty := ⟨_, h0, hh0, rfl⟩\n obtain ⟨h, hh, hk⟩ := Nat.sInf_mem hSne\n refine ⟨h, hh, fun h' hh' => ?_⟩\n rw [hk]\n exact Nat.sInf_le ⟨h', hh', rfl⟩\n\n/-- If `SVC = 0`, all hypotheses induce the same strategic label at every valid point. -/\nprivate lemma svc_zero_const {H : Set (X → Bool)} {R : Set ℝ} {c : X → X → ℝ}\n {Δ : (X → Bool) → X → ℝ → X} (hd : SVC H R c Δ = 0)\n {h h' : X → Bool} (hh : h ∈ H) (hh' : h' ∈ H) {x : X} {r : ℝ} (hr : r ∈ R) :\n h (Δ h x r) = h' (Δ h' x r) := by\n by_contra hne\n have hshat : StrategicShatters H R c Δ 1 := by\n refine ⟨fun _ => x, fun _ => r, fun _ => hr, ?_⟩\n intro v\n by_cases hv : v 0 = h (Δ h x r)\n · exact ⟨h, hh, fun i => by rw [Subsingleton.elim i 0]; exact hv.symm⟩\n · refine ⟨h', hh', fun i => ?_⟩\n rw [Subsingleton.elim i 0]\n revert hv hne\n cases v 0 <;> cases h (Δ h x r) <;> cases h' (Δ h' x r) <;> simp\n have hle : ((1:ℕ) : ℕ∞) ≤ SVC H R c Δ :=\n le_iSup₂ (f := fun n (_ : StrategicShatters H R c Δ n) => (n : ℕ∞)) 1 hshat\n rw [hd] at hle\n simp at hle\n\n/-- If `SVC = 0`, all hypotheses have the same strategic risk. -/\nprivate lemma risk_eq_of_svc_zero {H : Set (X → Bool)} {R : Set ℝ} {c : X → X → ℝ}\n {Δ : (X → Bool) → X → ℝ → X} (hd : SVC H R c Δ = 0)\n {D : Measure (X × Bool × ℝ)} (hDR : D {p : X × Bool × ℝ | p.2.2 ∉ R} = 0)\n {h h' : X → Bool} (hh : h ∈ H) (hh' : h' ∈ H) :\n strategicRisk c Δ h D = strategicRisk c Δ h' D := by\n unfold strategicRisk\n congr 1\n refine measure_congr ?_\n have hae : ∀ᵐ p ∂D, p.2.2 ∈ R := by\n rw [ae_iff]\n exact hDR\n filter_upwards [hae] with p hp\n show (h (Δ h p.1 p.2.2) ≠ p.2.1) = (h' (Δ h' p.1 p.2.2) ≠ p.2.1)\n rw [svc_zero_const hd hh hh' hp]\n\ntheorem strategic_agnostic_PAC :\n ∃ C : ℝ, 0 < C ∧\n ∀ (X : Type*) [MeasurableSpace X]\n (H : Set (X → Bool)) (_hH : H.Nonempty) (_hH_ctble : H.Countable)\n (R : Set ℝ) (c : X → X → ℝ) (_hc : ∀ x y : X, 0 ≤ c x y)\n (_hc0 : ∀ x : X, c x x = 0)\n (Δ : (X → Bool) → X → ℝ → X)\n (_hΔ : ∀ h ∈ H, ∀ x, ∀ r ∈ R, IsBestResponse c h x r (Δ h x r))\n (_hmeas : ∀ h ∈ H, Measurable (fun p : X × Bool × ℝ => h (Δ h p.1 p.2.2)))\n (d : ℕ) (_hd : SVC H R c Δ = (d : ℕ∞)),\n ∃ m : ℝ → ℝ → ℕ,\n (∀ δ ε : ℝ, 0 < δ → δ < 1 → 0 < ε → ε < 1 →\n (m δ ε : ℝ) ≤ C * (ε ^ 2)⁻¹ * ((d : ℝ) + Real.log (1 / δ))) ∧\n ∃ A : (N : ℕ) → (Fin N → X × Bool × ℝ) → (X → Bool),\n (∀ N s, IsSERM H c Δ (A N s) s) ∧\n ∀ δ ε : ℝ, 0 < δ → δ < 1 → 0 < ε → ε < 1 →\n ∀ n : ℕ, m δ ε ≤ n →\n ∀ D : MeasureTheory.Measure (X × Bool × ℝ), MeasureTheory.IsProbabilityMeasure D →\n\n D {p : X × Bool × ℝ | p.2.2 ∉ R} = 0 →\n 1 - δ ≤\n ((MeasureTheory.Measure.pi (fun _ : Fin n => D))\n {s : Fin n → X × Bool × ℝ |\n strategicRisk c Δ (A n s) D - ⨅ h : ↥H, strategicRisk c Δ (h : X → Bool) D\n ≤ ε}).toReal := by\n classical\n refine ⟨8 * PACMain.cUC, by have := PACMain.cUC_pos; positivity, ?_⟩\n intro X _ H hH hHc R c _hc _hc0 Δ hΔ hmeas d hd\n choose A hA using (fun (N : ℕ) (s : Fin N → X × Bool × ℝ) => exists_serm hH c Δ N s)\n have hHne : Nonempty ↥H := hH.to_subtype\n -- nonnegativity of the sample-complexity expression\n have hcap : ∀ δ ε : ℝ, 0 < δ → δ < 1 → 0 < ε → ε < 1 →\n 0 ≤ 8 * PACMain.cUC * (ε ^ 2)⁻¹ * ((d : ℝ) + Real.log (1 / δ)) := by\n intro δ ε hδ0 hδ1 hε0 hε1\n have h1 : (1:ℝ) ≤ 1/δ := by rw [le_div_iff₀ hδ0]; linarith\n have hlog : 0 ≤ Real.log (1/δ) := Real.log_nonneg h1\n have := PACMain.cUC_pos\n positivity\n by_cases hd0 : d = 0\n · -- degenerate case: every hypothesis has the same strategic risk\n refine ⟨fun _ _ => 0, fun δ ε hδ0 hδ1 hε0 hε1 => ?_, A, hA, ?_⟩\n · simpa using hcap δ ε hδ0 hδ1 hε0 hε1\n · intro δ ε hδ0 hδ1 hε0 hε1 n _ D hD hDR\n have hd' : SVC H R c Δ = 0 := by rw [hd, hd0]; simp\n have hset : {s : Fin n → X × Bool × ℝ |\n strategicRisk c Δ (A n s) D - ⨅ h : ↥H, strategicRisk c Δ (h : X → Bool) D ≤ ε}\n = Set.univ := by\n ext s\n simp only [Set.mem_setOf_eq, Set.mem_univ, iff_true]\n have hle : strategicRisk c Δ (A n s) D\n ≤ ⨅ h : ↥H, strategicRisk c Δ (h : X → Bool) D := by\n refine le_ciInf fun h => ?_\n exact le_of_eq (risk_eq_of_svc_zero hd' hDR (hA n s).1 h.2)\n linarith\n rw [hset, measure_univ]\n simp\n linarith\n · -- main case\n have hd1 : 1 ≤ d := Nat.one_le_iff_ne_zero.mpr hd0\n refine ⟨fun δ ε => ⌊8 * PACMain.cUC * (ε ^ 2)⁻¹ * ((d : ℝ) + Real.log (1 / δ))⌋₊,\n fun δ ε hδ0 hδ1 hε0 hε1 => Nat.floor_le (hcap δ ε hδ0 hδ1 hε0 hε1), A, hA, ?_⟩\n intro δ ε hδ0 hδ1 hε0 hε1 n hn D hD hDR\n set lam : ℝ := Real.log (1 / δ) with hlamdef\n have hlam : 0 ≤ lam := Real.log_nonneg (by rw [le_div_iff₀ hδ0]; linarith)\n have hdR : (1:ℝ) ≤ (d:ℝ) := by exact_mod_cast hd1\n -- the induced family of Boolean tests\n set f : ↥H → (X × Bool × ℝ) → Bool :=\n fun i p => decide ((i : X → Bool) (Δ (i : X → Bool) p.1 p.2.2) ≠ p.2.1) with hfdef\n have hf : ∀ i : ↥H, Measurable (f i) := by\n intro i\n exact (Measurable.of_discrete (f := fun q : Bool × Bool => decide (q.1 ≠ q.2))).comp\n ((hmeas (i : X → Bool) i.2).prodMk (measurable_fst.comp measurable_snd))\n have hcount : Countable ↥H := hHc.to_subtype\n set G : Set (X × Bool × ℝ) := {p | p.2.2 ∈ R} with hGdef\n have hG : D Gᶜ = 0 := hDR\n -- VC dimension of the induced family is at most `d`\n have hvc : ∀ z : Fin (d+1) → (X × Bool × ℝ), (∀ j, z j ∈ G) →\n ¬ ∀ v : Fin (d+1) → Bool, ∃ i : ↥H, ∀ j, f i (z j) = v j := by\n intro z hz hshat\n have hstrat : StrategicShatters H R c Δ (d+1) := by\n refine ⟨fun j => (z j).1, fun j => (z j).2.2, fun j => hz j, ?_⟩\n intro v\n obtain ⟨i, hi⟩ := hshat (fun j => decide (v j ≠ (z j).2.1))\n refine ⟨(i : X → Bool), i.2, fun j => ?_⟩\n have := hi j\n simp only [hfdef, decide_eq_decide] at this\n revert this\n cases (i : X → Bool) (Δ (i : X → Bool) (z j).1 (z j).2.2) <;> cases v j <;>\n cases (z j).2.1 <;> simp\n have hle : ((d+1 : ℕ) : ℕ∞) ≤ SVC H R c Δ :=\n le_iSup₂ (f := fun k (_ : StrategicShatters H R c Δ k) => (k : ℕ∞)) (d+1) hstrat\n rw [hd] at hle\n have : d + 1 ≤ d := by exact_mod_cast hle\n omega\n -- the sample size is large enough\n have hcapge : (2:ℝ) ≤ 8 * PACMain.cUC * (ε ^ 2) ⁻¹ * ((d:ℝ) + lam) := by\n have h1 : (1:ℝ) ≤ (ε ^ 2)⁻¹ := by\n rw [le_inv_comm₀ one_pos (by positivity)]\n nlinarith\n have h2 : (1:ℝ) ≤ (d:ℝ) + lam := by linarith\n have h5 : (1:ℝ) ≤ PACMain.cUC := PACMain.cUC_ge_one\n have heq : 8 * PACMain.cUC * (ε ^ 2)⁻¹ * ((d:ℝ) + lam)\n = 8 * (PACMain.cUC * ((ε ^ 2)⁻¹ * ((d:ℝ) + lam))) := by ring\n rw [heq]\n have h6 : (1:ℝ) ≤ (ε ^ 2)⁻¹ * ((d:ℝ) + lam) := by nlinarith\n have h7 : (1:ℝ) ≤ PACMain.cUC * ((ε ^ 2)⁻¹ * ((d:ℝ) + lam)) := by nlinarith\n linarith\n have hnge : 8 * PACMain.cUC * (ε ^ 2)⁻¹ * ((d:ℝ) + lam) / 2 ≤ (n:ℝ) := by\n have h3 : ((⌊8 * PACMain.cUC * (ε ^ 2)⁻¹ * ((d:ℝ) + lam)⌋₊ : ℕ) : ℝ) ≤ (n:ℝ) := by\n exact_mod_cast hn\n have h4 := Nat.lt_floor_add_one (8 * PACMain.cUC * (ε ^ 2)⁻¹ * ((d:ℝ) + lam))\n linarith\n have hn0 : (0:ℝ) < (n:ℝ) := by linarith\n have hnt : PACMain.cUC * ((d:ℝ) + lam) ≤ (n:ℝ) * (ε/2) ^ 2 := by\n have hε2 : (0:ℝ) < ε ^ 2 := by positivity\n have key := mul_le_mul_of_nonneg_right hnge (by positivity : (0:ℝ) ≤ ε ^ 2 / 4)\n calc PACMain.cUC * ((d:ℝ) + lam)\n = (8 * PACMain.cUC * (ε ^ 2)⁻¹ * ((d:ℝ) + lam) / 2) * (ε ^ 2 / 4) := by\n field_simp; ring\n _ ≤ (n:ℝ) * (ε ^ 2 / 4) := key\n _ = (n:ℝ) * (ε/2) ^ 2 := by ring\n have huc := PACMain.uniform_convergence D f hf G hG d hd1 hvc n (ε/2) lam (by linarith) hlam hnt\n -- translate the conclusion\n have hcard : ∀ (i : ↥H) (s : Fin n → X × Bool × ℝ),\n (Finset.univ.filter (fun j => f i (s j) = true)).card\n = empStrategicLoss c Δ (i : X → Bool) s := by\n intro i s\n unfold empStrategicLoss\n apply congrArg\n apply Finset.filter_congr\n intro j _\n simp [hfdef]\n have hrisk : ∀ i : ↥H, (D {z | f i z = true}).toReal\n = strategicRisk c Δ (i : X → Bool) D := by\n intro i\n unfold strategicRisk\n congr 2\n ext p\n simp [hfdef]\n have hexp : Real.exp (-lam) = δ := by\n have h1 : -lam = Real.log δ := by\n rw [hlamdef, one_div, Real.log_inv]; ring\n rw [h1, Real.exp_log hδ0]\n have hsub : {s : Fin n → X × Bool × ℝ | ∀ i : ↥H,\n |(((Finset.univ.filter (fun j => f i (s j) = true)).card : ℝ)) / n\n - (D {z | f i z = true}).toReal| ≤ ε/2}\n ⊆ {s : Fin n → X × Bool × ℝ |\n strategicRisk c Δ (A n s) D - ⨅ h : ↥H, strategicRisk c Δ (h : X → Bool) D ≤ ε} := by\n intro s hs\n simp only [Set.mem_setOf_eq] at hs ⊢\n have key : ∀ h : ↥H,\n strategicRisk c Δ (A n s) D - ε ≤ strategicRisk c Δ (h : X → Bool) D := by\n intro h\n have h1 := hs ⟨A n s, (hA n s).1⟩\n have h2 := hs h\n rw [hcard, hrisk] at h1\n rw [hcard, hrisk] at h2\n rw [abs_le] at h1 h2\n have h3 : (empStrategicLoss c Δ (A n s) s : ℝ)\n ≤ (empStrategicLoss c Δ (h : X → Bool) s : ℝ) := by\n exact_mod_cast (hA n s).2 (h : X → Bool) h.2\n have h4 : (empStrategicLoss c Δ (A n s) s : ℝ) / n\n ≤ (empStrategicLoss c Δ (h : X → Bool) s : ℝ) / n := by\n apply div_le_div_of_nonneg_right h3 hn0.le\n simp only at h1 h2\n linarith [h1.1, h1.2, h2.1, h2.2]\n have := le_ciInf key\n linarith\n calc 1 - δ = 1 - Real.exp (-lam) := by rw [hexp]\n _ ≤ ((Measure.pi (fun _ : Fin n => D))\n {s : Fin n → X × Bool × ℝ | ∀ i : ↥H,\n |(((Finset.univ.filter (fun j => f i (s j) = true)).card : ℝ)) / n\n - (D {z | f i z = true}).toReal| ≤ ε/2}).toReal := huc\n _ ≤ _ := ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono hsub)\n\nprivate lemma sep_cost_le_abs {X : Type*} (c : X → X → ℝ)\n (hc0 : ∀ x : X, c x x = 0) (h : X → Bool) (x : X) (r : ℝ) (z : X)\n (hz : IsBestResponse c h x r z) (hlab : h z = decide (0 < r)) :\n c z x ≤ |r| := by\n have hx := hz x\n unfold stratUtil at hx\n rw [hc0] at hx\n by_cases hr : (0:ℝ) < r\n · rw [decide_eq_true hr] at hlab\n rw [hlab] at hx\n rw [abs_of_pos hr]\n have h0 : (0:ℝ) ≤ (if h x then r else 0) := by\n split\n · exact le_of_lt hr\n · exact le_refl 0\n simp only [if_true] at hx\n linarith\n · rw [decide_eq_false hr] at hlab\n rw [hlab] at hx\n have hr' : r ≤ 0 := not_lt.mp hr\n rw [abs_of_nonpos hr']\n have h0 : r ≤ (if h x then r else 0) := by\n split\n · exact le_refl r\n · exact hr'\n norm_num at hx\n linarith\n\n-- Lemma A : if the best response gets the *non*-preferred label, then every point within\n-- cost |r| also gets that non-preferred label.\nprivate lemma sep_nonpref_forces {X : Type*} (c : X → X → ℝ) (hc : ∀ x y : X, 0 ≤ c x y)\n (h : X → Bool) (x : X) (r : ℝ) (z : X)\n (hz : IsBestResponse c h x r z)\n (hne : h z ≠ decide (0 < r))\n (htie : (∃ z', IsBestResponse c h x r z' ∧ h z' = decide (0 < r)) → h z = decide (0 < r))\n (y : X) (hy : c y x ≤ |r|) : h y = h z := by\n by_contra hyz\n have hylab : h y = decide (0 < r) := by\n revert hyz hne\n generalize (decide (0 < r)) = p\n cases h y <;> cases h z <;> cases p <;> simp\n have hle : stratUtil c h x r z ≤ stratUtil c h x r y := by\n unfold stratUtil\n by_cases hr : (0:ℝ) < r\n · rw [decide_eq_true hr] at hylab\n rw [hylab]\n have hzf : h z = false := by\n rw [decide_eq_true hr] at hne\n exact Bool.not_eq_true _ |>.mp hne\n rw [hzf]\n rw [abs_of_pos hr] at hy\n have := hc z x\n norm_num\n linarith\n · rw [decide_eq_false hr] at hylab\n rw [hylab]\n have hzt : h z = true := by\n rw [decide_eq_false hr] at hne\n exact Bool.not_eq_false _ |>.mp hne\n rw [hzt]\n have hr' : r ≤ 0 := not_lt.mp hr\n rw [abs_of_nonpos hr'] at hy\n have := hc z x\n norm_num\n linarith\n have br : IsBestResponse c h x r y := fun z' => (hz z').trans hle\n exact hne (htie ⟨y, br, hylab⟩)\n\ntheorem separable_SVC_le_two\n {X : Type*} (H : Set (X → Bool)) (R : Set ℝ) (c : X → X → ℝ) (_hc : ∀ x y : X, 0 ≤ c x y)\n (Δ : (X → Bool) → X → ℝ → X)\n (hΔ : ∀ h ∈ H, ∀ (x : X), ∀ r ∈ R, IsBestResponse c h x r (Δ h x r))\n\n (htie : ∀ h ∈ H, ∀ (x : X), ∀ r ∈ R,\n (∃ z, IsBestResponse c h x r z ∧ h z = decide (0 < r)) →\n h (Δ h x r) = decide (0 < r))\n (hR : (0 : ℝ) ∉ R) (hsep : SeparableCost c) (hc0 : ∀ x : X, c x x = 0) :\n SVC H R c Δ ≤ 2 := by\n obtain ⟨c₁, c₂, hcdef⟩ := hsep\n apply iSup_le\n intro n\n apply iSup_le\n intro hn\n by_contra hlt\n have hn3 : 3 ≤ n := by\n by_contra hle\n push_neg at hle\n exact hlt (by exact_mod_cast Nat.lt_succ_iff.mp hle)\n obtain ⟨x, r, hrR, hsh⟩ := hn\n -- main pairwise claim\n have main : ∀ a b : Fin n, a ≠ b → (decide (0 < r a) = decide (0 < r b)) →\n c₁ (x a) + |r a| ≤ c₁ (x b) + |r b| → False := by\n intro a b hab hsign hle\n obtain ⟨h, hH, hv⟩ := hsh (fun i => if i = a then decide (0 < r b) else !(decide (0 < r b)))\n have hva : h (Δ h (x a) (r a)) = decide (0 < r b) := by\n have := hv a; simpa using this\n have hvb : h (Δ h (x b) (r b)) = !(decide (0 < r b)) := by\n have := hv b; simpa [hab.symm] using this\n -- cost of a's best response\n have hca : c (Δ h (x a) (r a)) (x a) ≤ |r a| :=\n sep_cost_le_abs c hc0 h (x a) (r a) _ (hΔ h hH (x a) (r a) (hrR a)) (by rw [hva, hsign])\n -- translate to b's neighbourhood\n have hcb : c (Δ h (x a) (r a)) (x b) ≤ |r b| := by\n rw [hcdef] at hca ⊢\n have h1 : c₂ (Δ h (x a) (r a)) - c₁ (x a) ≤ |r a| := le_trans (le_max_left _ _) hca\n have h2 : (0:ℝ) ≤ |r b| := abs_nonneg _\n exact max_le (by linarith) h2\n have hforce := sep_nonpref_forces c _hc h (x b) (r b) _ (hΔ h hH (x b) (r b) (hrR b))\n (by rw [hvb]; simp) (htie h hH (x b) (r b) (hrR b)) _ hcb\n rw [hva, hvb] at hforce\n simp at hforce\n have main2 : ∀ a b : Fin n, a ≠ b → (decide (0 < r a) = decide (0 < r b)) → False := by\n intro a b hab hs\n rcases le_total (c₁ (x a) + |r a|) (c₁ (x b) + |r b|) with hle | hle\n · exact main a b hab hs hle\n · exact main b a hab.symm hs.symm hle\n -- pigeonhole on three indices\n have h0 : (0:ℕ) < n := by omega\n have h1 : (1:ℕ) < n := by omega\n have h2 : (2:ℕ) < n := by omega\n set i0 : Fin n := ⟨0, h0⟩\n set i1 : Fin n := ⟨1, h1⟩\n set i2 : Fin n := ⟨2, h2⟩\n have e01 : i0 ≠ i1 := by simp [i0, i1, Fin.ext_iff]\n have e02 : i0 ≠ i2 := by simp [i0, i2, Fin.ext_iff]\n have e12 : i1 ≠ i2 := by simp [i1, i2, Fin.ext_iff]\n rcases Bool.eq_false_or_eq_true (decide (0 < r i0)) with p0 | p0 <;>\n rcases Bool.eq_false_or_eq_true (decide (0 < r i1)) with p1 | p1 <;>\n rcases Bool.eq_false_or_eq_true (decide (0 < r i2)) with p2 | p2\n · exact main2 i0 i1 e01 (by rw [p0, p1])\n · exact main2 i0 i1 e01 (by rw [p0, p1])\n · exact main2 i0 i2 e02 (by rw [p0, p2])\n · exact main2 i1 i2 e12 (by rw [p1, p2])\n · exact main2 i1 i2 e12 (by rw [p1, p2])\n · exact main2 i0 i2 e02 (by rw [p0, p2])\n · exact main2 i0 i1 e01 (by rw [p0, p1])\n · exact main2 i0 i1 e01 (by rw [p0, p1])\n\n\nprivate lemma dotp_smul {d : ℕ} (w u : Fin d → ℝ) (a : ℝ) :\n dotp w (fun i => a * u i) = a * dotp w u := by\n simp only [dotp, Finset.mul_sum]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n\nprivate lemma dotp_add {d : ℕ} (w u v : Fin d → ℝ) :\n dotp w (fun i => u i + v i) = dotp w u + dotp w v := by\n simp [dotp, Finset.sum_add_distrib, mul_add]\n\nprivate lemma l_zero {d : ℕ} {l : (Fin d → ℝ) → ℝ}\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u) :\n l 0 = 0 := by\n have := hhom 0 0\n simpa using this\n\nprivate lemma l_neg {d : ℕ} {l : (Fin d → ℝ) → ℝ}\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u) (u : Fin d → ℝ) :\n l (fun i => -u i) = l u := by\n have := hhom (-1) u\n simpa using this\n\nprivate lemma l_sum_le {d : ℕ} {l : (Fin d → ℝ) → ℝ}\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (htri : ∀ u v : Fin d → ℝ, l (fun i => u i + v i) ≤ l u + l v)\n (s : Finset (Fin d)) (f : Fin d → (Fin d → ℝ)) :\n l (∑ i ∈ s, f i) ≤ ∑ i ∈ s, l (f i) := by\n classical\n induction s using Finset.induction with\n | empty => simp [l_zero hhom]\n | insert a s ha ih =>\n rw [Finset.sum_insert ha, Finset.sum_insert ha]\n exact le_trans (htri (f a) (∑ i ∈ s, f i)) (by linarith)\n\nprivate lemma l_single {d : ℕ} {l : (Fin d → ℝ) → ℝ}\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (i : Fin d) (t : ℝ) :\n l (Pi.single i t) = |t| * l (Pi.single i 1) := by\n classical\n have h : (Pi.single i t : Fin d → ℝ) = fun j => t * ((Pi.single i (1:ℝ) : Fin d → ℝ) j) := by\n funext j\n by_cases hj : j = i\n · subst hj; simp\n · simp [Pi.single_apply, hj]\n rw [h, hhom]\n\nprivate lemma l_bound {d : ℕ} {l : (Fin d → ℝ) → ℝ}\n (hnn : ∀ u : Fin d → ℝ, 0 ≤ l u)\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (htri : ∀ u v : Fin d → ℝ, l (fun i => u i + v i) ≤ l u + l v) :\n ∃ C : ℝ, 0 ≤ C ∧ ∀ u : Fin d → ℝ, l u ≤ C * ‖u‖ := by\n classical\n refine ⟨∑ i, l (Pi.single i 1), Finset.sum_nonneg (fun i _ => hnn _), ?_⟩\n intro u\n have h1 : (∑ i, Pi.single i (u i)) = u := Finset.univ_sum_single u\n calc l u = l (∑ i, Pi.single i (u i)) := by rw [h1]\n _ ≤ ∑ i, l (Pi.single i (u i)) := l_sum_le hhom htri _ _\n _ ≤ ∑ i, ‖u‖ * l (Pi.single i 1) := by\n refine Finset.sum_le_sum (fun i _ => ?_)\n rw [l_single hhom]\n have h2 : |u i| ≤ ‖u‖ := by\n have := norm_le_pi_norm u i\n simpa using this\n exact mul_le_mul_of_nonneg_right h2 (hnn _)\n _ = (∑ i, l (Pi.single i 1)) * ‖u‖ := by\n rw [Finset.sum_mul]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n\nprivate lemma l_sub_le {d : ℕ} {l : (Fin d → ℝ) → ℝ}\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (htri : ∀ u v : Fin d → ℝ, l (fun i => u i + v i) ≤ l u + l v) (u v : Fin d → ℝ) :\n |l u - l v| ≤ l (u - v) := by\n have h1 : l u ≤ l (u - v) + l v := by\n have := htri (u - v) v\n have h2 : (fun i => (u - v) i + v i) = u := by funext i; simp\n rw [h2] at this\n exact this\n have h2 : l v ≤ l (u - v) + l u := by\n have := htri (v - u) u\n have h3 : (fun i => (v - u) i + u i) = v := by funext i; simp\n rw [h3] at this\n have h4 : l (v - u) = l (u - v) := by\n have := l_neg hhom (u - v)\n have h5 : (fun i => -((u - v) i)) = v - u := by funext i; simp\n rw [h5] at this\n exact this\n rw [h4] at this\n exact this\n rw [abs_sub_le_iff]\n constructor <;> linarith\n\nprivate lemma l_continuous {d : ℕ} {l : (Fin d → ℝ) → ℝ}\n (hnn : ∀ u : Fin d → ℝ, 0 ≤ l u)\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (htri : ∀ u v : Fin d → ℝ, l (fun i => u i + v i) ≤ l u + l v) :\n Continuous l := by\n obtain ⟨C, hC, hCb⟩ := l_bound hnn hhom htri\n have : LipschitzWith (Real.toNNReal C) l := by\n apply LipschitzWith.of_dist_le_mul\n intro u v\n rw [Real.dist_eq, Real.coe_toNNReal C hC, dist_eq_norm]\n exact le_trans (l_sub_le hhom htri u v) (hCb _)\n exact this.continuous\n\nprivate lemma dotp_continuous {d : ℕ} (w : Fin d → ℝ) : Continuous (fun z : Fin d → ℝ => dotp w z) := by\n unfold dotp\n exact continuous_finset_sum _ (fun i _ => continuous_const.mul (continuous_apply i))\n\nprivate lemma sup_attained {d : ℕ} {l : (Fin d → ℝ) → ℝ} {w : Fin d → ℝ} {lstar : ℝ}\n (hnn : ∀ u : Fin d → ℝ, 0 ≤ l u)\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (htri : ∀ u v : Fin d → ℝ, l (fun i => u i + v i) ≤ l u + l v)\n (hlstar : 0 < lstar)\n (hlub : IsLUB {t : ℝ | ∃ z : Fin d → ℝ, l z ≤ 1 ∧ t = dotp w z} lstar) :\n ∃ z : Fin d → ℝ, l z ≤ 1 ∧ dotp w z = lstar := by\n classical\n have hcont : Continuous l := l_continuous hnn hhom htri\n have hlsmul : ∀ (a : ℝ) (u : Fin d → ℝ), l (a • u) = |a| * l u := fun a u => hhom a u\n have hladd : ∀ (u v : Fin d → ℝ), l (u + v) ≤ l u + l v := fun u v => htri u v\n have hl0 : l (0 : Fin d → ℝ) = 0 := l_zero hhom\n have hub : ∀ z : Fin d → ℝ, l z ≤ 1 → dotp w z ≤ lstar := fun z hz => hlub.1 ⟨z, hz, rfl⟩\n -- the kernel functional vanishes on the kernel of l\n have hker : ∀ z : Fin d → ℝ, l z = 0 → dotp w z = 0 := by\n intro z hz\n by_contra hne\n set a : ℝ := (lstar + 1) / dotp w z with ha\n have h1 : l (a • z) ≤ 1 := by rw [hlsmul, hz]; simp\n have h2 : dotp w (a • z) = lstar + 1 := by\n have : dotp w (a • z) = a * dotp w z := dotp_smul w z a\n rw [this, ha]\n field_simp\n have := hub _ h1\n rw [h2] at this\n linarith\n -- the kernel as a submodule\n set K : Submodule ℝ (Fin d → ℝ) :=\n { carrier := {z : Fin d → ℝ | l z = 0}\n zero_mem' := hl0\n add_mem' := by\n intro u v hu hv\n simp only [Set.mem_setOf_eq] at *\n have := hladd u v\n rw [hu, hv] at this\n exact le_antisymm (by linarith) (hnn _)\n smul_mem' := by\n intro a u hu\n simp only [Set.mem_setOf_eq] at *\n rw [hlsmul, hu, mul_zero] } with hK\n have hKmem : ∀ z : Fin d → ℝ, z ∈ K ↔ l z = 0 := fun z => Iff.rfl\n obtain ⟨W, hcompl⟩ := K.exists_isCompl\n -- decomposition\n have hdecomp : ∀ z : Fin d → ℝ, ∃ v : Fin d → ℝ, v ∈ W ∧ l v = l z ∧ dotp w v = dotp w z := by\n intro z\n have hz : z ∈ K ⊔ W := by rw [hcompl.sup_eq_top]; trivial\n obtain ⟨y, hy, v, hv, hyv⟩ := Submodule.mem_sup.mp hz\n refine ⟨v, hv, ?_, ?_⟩\n · have hy0 : l y = 0 := (hKmem y).mp hy\n have h1 : l z ≤ l v := by\n have := hladd y v\n rw [hyv, hy0] at this\n linarith\n have h2 : l v ≤ l z := by\n have := hladd ((-1 : ℝ) • y) z\n have h3 : ((-1 : ℝ) • y) + z = v := by rw [← hyv]; module\n rw [h3, hlsmul, hy0] at this\n simpa using this\n linarith\n · have hy0 : dotp w y = 0 := hker y ((hKmem y).mp hy)\n have : dotp w z = dotp w y + dotp w v := by rw [← hyv]; exact dotp_add w y v\n rw [this, hy0, zero_add]\n -- W is closed\n have hWclosed : IsClosed (W : Set (Fin d → ℝ)) := W.closed_of_finiteDimensional\n -- coercivity of l on W\n obtain ⟨m, hm0, hmco⟩ : ∃ m : ℝ, 0 < m ∧ ∀ v : Fin d → ℝ, v ∈ W → m * ‖v‖ ≤ l v := by\n by_cases hA : ((W : Set (Fin d → ℝ)) ∩ Metric.sphere 0 1).Nonempty\n · have hAcompact : IsCompact ((W : Set (Fin d → ℝ)) ∩ Metric.sphere 0 1) := by\n apply Metric.isCompact_of_isClosed_isBounded\n · exact hWclosed.inter Metric.isClosed_sphere\n · exact Metric.isBounded_sphere.subset Set.inter_subset_right\n obtain ⟨v₀, hv₀, hv₀min⟩ := hAcompact.exists_isMinOn hA hcont.continuousOn\n have hv₀W : v₀ ∈ W := hv₀.1\n have hv₀n : ‖v₀‖ = 1 := by\n have := hv₀.2\n simpa [Metric.mem_sphere, dist_zero_right] using this\n have hlv₀ : 0 < l v₀ := by\n rcases (hnn v₀).lt_or_eq with h | h\n · exact h\n · exfalso\n have hK0 : v₀ ∈ K := (hKmem v₀).mpr h.symm\n have hv0 : v₀ = 0 := by\n have hbot := hcompl.inf_eq_bot\n have hmem : v₀ ∈ K ⊓ W := ⟨hK0, hv₀W⟩\n rw [hbot] at hmem\n simpa using hmem\n rw [hv0] at hv₀n\n simp at hv₀n\n refine ⟨l v₀, hlv₀, ?_⟩\n intro v hv\n rcases eq_or_ne v 0 with rfl | hv0\n · simp [hl0]\n · have hnv : 0 < ‖v‖ := norm_pos_iff.mpr hv0\n have hmemA : (‖v‖⁻¹ • v) ∈ ((W : Set (Fin d → ℝ)) ∩ Metric.sphere 0 1) := by\n refine ⟨W.smul_mem _ hv, ?_⟩\n simp only [Metric.mem_sphere, dist_zero_right, norm_smul, norm_inv, norm_norm]\n field_simp\n have hmin := isMinOn_iff.mp hv₀min _ hmemA\n rw [hlsmul, abs_of_pos (inv_pos.mpr hnv), inv_mul_eq_div] at hmin\n exact (le_div_iff₀ hnv).mp hmin\n · exfalso\n have hW0 : ∀ v : Fin d → ℝ, v ∈ W → v = 0 := by\n intro v hv\n by_contra hv0\n have hnv : 0 < ‖v‖ := norm_pos_iff.mpr hv0\n refine hA ⟨‖v‖⁻¹ • v, W.smul_mem _ hv, ?_⟩\n simp only [Metric.mem_sphere, dist_zero_right, norm_smul, norm_inv, norm_norm]\n field_simp\n have hzero : ∀ z : Fin d → ℝ, dotp w z = 0 := by\n intro z\n obtain ⟨v, hvW, _, hdv⟩ := hdecomp z\n rw [← hdv, hW0 v hvW]\n simp [dotp]\n have : lstar ≤ 0 := by\n apply hlub.2\n rintro t ⟨z, _, rfl⟩\n rw [hzero z]\n linarith\n -- the compact slice\n set S : Set (Fin d → ℝ) := {v : Fin d → ℝ | v ∈ W ∧ l v ≤ 1} with hS\n have hScompact : IsCompact S := by\n apply Metric.isCompact_of_isClosed_isBounded\n · exact hWclosed.inter (isClosed_le hcont continuous_const)\n · apply Bornology.IsBounded.subset (Metric.isBounded_closedBall (x := (0 : Fin d → ℝ)) (r := m⁻¹))\n intro v hv\n simp only [Metric.mem_closedBall, dist_zero_right]\n have := hmco v hv.1\n have h2 : m * ‖v‖ ≤ 1 := le_trans this hv.2\n rw [inv_eq_one_div, le_div_iff₀ hm0]\n linarith [mul_comm m ‖v‖]\n have hSne : S.Nonempty := ⟨0, W.zero_mem, by rw [hl0]; norm_num⟩\n obtain ⟨z₀, hz₀S, hz₀max⟩ := hScompact.exists_isMaxOn hSne (dotp_continuous w).continuousOn\n refine ⟨z₀, hz₀S.2, ?_⟩\n have hle : dotp w z₀ ≤ lstar := hub _ hz₀S.2\n have hge : lstar ≤ dotp w z₀ := by\n apply hlub.2\n rintro t ⟨z, hz, rfl⟩\n obtain ⟨v, hvW, hlv, hdv⟩ := hdecomp z\n rw [← hdv]\n exact hz₀max ⟨hvW, by rw [hlv]; exact hz⟩\n linarith\n\nprivate lemma abs_dotp_le {d : ℕ} {l : (Fin d → ℝ) → ℝ} {w : Fin d → ℝ} {lstar : ℝ}\n (hnn : ∀ u : Fin d → ℝ, 0 ≤ l u)\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (hlstar : 0 < lstar)\n (hub : ∀ z : Fin d → ℝ, l z ≤ 1 → dotp w z ≤ lstar) (u : Fin d → ℝ) :\n |dotp w u| ≤ lstar * l u := by\n have hlsmul : ∀ (a : ℝ) (v : Fin d → ℝ), l (a • v) = |a| * l v := fun a v => hhom a v\n have hdsmul : ∀ (a : ℝ) (v : Fin d → ℝ), dotp w (a • v) = a * dotp w v :=\n fun a v => dotp_smul w v a\n have main : ∀ v : Fin d → ℝ, dotp w v ≤ lstar * l v := by\n intro v\n rcases (hnn v).lt_or_eq with hv | hv\n · -- 0 < l v\n have h1 : l ((l v)⁻¹ • v) ≤ 1 := by\n rw [hlsmul, abs_of_pos (inv_pos.mpr hv), inv_mul_cancel₀ (ne_of_gt hv)]\n have h2 := hub _ h1\n rw [hdsmul] at h2\n calc dotp w v = (l v) * ((l v)⁻¹ * dotp w v) := by field_simp\n _ ≤ (l v) * lstar := by\n exact mul_le_mul_of_nonneg_left h2 (le_of_lt hv)\n _ = lstar * l v := by ring\n · -- l v = 0\n have hz : dotp w v = 0 := by\n by_contra hne\n set a : ℝ := (lstar + 1) / dotp w v with ha\n have h1 : l (a • v) ≤ 1 := by rw [hlsmul, ← hv]; simp\n have h2 := hub _ h1\n rw [hdsmul, ha] at h2\n field_simp at h2\n linarith\n rw [hz, ← hv]\n simp\n refine abs_le.mpr ⟨?_, main u⟩\n have h3 := main ((-1 : ℝ) • u)\n rw [hdsmul, hlsmul] at h3\n simp at h3\n linarith\n\nprivate lemma seminorm_add_null {E : Type*} [AddCommGroup E] [Module ℝ E]\n (p : Seminorm ℝ E) {u : E} (hu : p u = 0) (v : E) : p (u + v) = p v := by\n apply le_antisymm\n · simpa [hu] using map_add_le_add p u v\n · have h := map_add_le_add p (-u) (u + v)\n simpa [hu] using h\n\nprivate lemma seminorm_max_or_null {E : Type*} [AddCommGroup E] [Module ℝ E]\n [FiniteDimensional ℝ E] (p : Seminorm ℝ E) (f : E →ₗ[ℝ] ℝ) :\n (∃ u, p u = 0 ∧ f u ≠ 0) ∨\n ((∀ u, p u = 0 → f u = 0) ∧\n ∃ z, p z ≤ 1 ∧ ∀ u, p u ≤ 1 → f u ≤ f z) := by\n classical\n by_cases hn : ∃ u, p u = 0 ∧ f u ≠ 0\n · exact Or.inl hn\n right\n have hfnull : ∀ u, p u = 0 → f u = 0 := by\n intro u hu\n by_contra hf\n exact hn ⟨u, hu, hf⟩\n refine ⟨hfnull, ?_⟩\n let K : Submodule ℝ E :=\n { carrier := {u | p u = 0}\n zero_mem' := map_zero p\n add_mem' := by\n intro u v hu hv\n change p u = 0 at hu\n change p v = 0 at hv\n exact le_antisymm (by simpa [hu, hv] using map_add_le_add p u v)\n (apply_nonneg p (u + v))\n smul_mem' := by\n intro a u hu\n change p (a • u) = 0\n rw [map_smul_eq_mul, hu, mul_zero] }\n obtain ⟨V, hV⟩ := K.exists_isCompl\n let q : Seminorm ℝ V := p.comp V.subtype\n let n : AddGroupNorm V :=\n { q.toAddGroupSeminorm with\n eq_zero_of_map_eq_zero' := by\n intro u hu\n apply Subtype.ext\n exact Submodule.disjoint_def.mp hV.disjoint u hu u.property }\n letI : NormedAddCommGroup V := n.toNormedAddCommGroup\n letI : NormedSpace ℝ V :=\n { norm_smul_le := by\n intro a u\n exact (map_smul_eq_mul q a u).le }\n have hnorm (u : V) : ‖u‖ = p u := rfl\n obtain ⟨z, hz, hmax⟩ := (isCompact_closedBall (0 : V) 1).exists_isMaxOn\n (by exact ⟨0, by simp⟩) (f.comp V.subtype).continuous_of_finiteDimensional.continuousOn\n refine ⟨z, ?_, ?_⟩\n · simpa only [Metric.mem_closedBall, dist_zero_right, hnorm] using hz\n · intro u hu\n obtain ⟨k, v, hk, hv, hkv⟩ :=\n Submodule.codisjoint_iff_exists_add_eq.mp hV.codisjoint u\n have hk0 : p k = 0 := hk\n have hpv : p v ≤ 1 := by\n rw [← hkv, seminorm_add_null p hk0] at hu\n exact hu\n have hfv : f u = f v := by\n rw [← hkv, map_add, hfnull k hk0, zero_add]\n rw [hfv]\n exact hmax (by simpa only [Metric.mem_closedBall, dist_zero_right, hnorm] using hpv :\n (⟨v, hv⟩ : V) ∈ Metric.closedBall (0 : V) 1)\n\nprivate lemma seminorm_fiber_least {E : Type*} [AddCommGroup E] [Module ℝ E]\n [FiniteDimensional ℝ E] (p : Seminorm ℝ E) (f : E →ₗ[ℝ] ℝ)\n (c : ℝ) (s : EReal) (hs : 0 < s)\n (hS : IsLUB {t : EReal | ∃ z : E, p z ≤ 1 ∧ t = (f z : EReal)} s) :\n IsLeast {t : EReal | ∃ u : E, f u = c ∧ t = (p u : EReal)}\n ((|c| : ℝ) / s) := by\n rcases seminorm_max_or_null p f with ⟨v, hpv, hfv⟩ | ⟨hfnull, z, hpz, hmax⟩\n · have hfree (r : ℝ) : (r : EReal) ≤ s := by\n apply hS.1\n refine ⟨(r / f v) • v, ?_, ?_⟩\n · rw [map_smul_eq_mul, hpv, mul_zero]\n exact zero_le_one\n · rw [map_smul, smul_eq_mul, div_mul_cancel₀ _ hfv]\n have htop : s = ⊤ := by\n cases s using EReal.rec with\n | bot => exact (not_lt_bot hs).elim\n | coe r =>\n have h := hfree (r + 1)\n have h' : r + 1 ≤ r := EReal.coe_le_coe_iff.mp h\n linarith\n | top => rfl\n rw [htop, EReal.div_top]\n constructor\n · refine ⟨(c / f v) • v, ?_, ?_⟩\n · rw [map_smul, smul_eq_mul, div_mul_cancel₀ _ hfv]\n · rw [map_smul_eq_mul, hpv, mul_zero, EReal.coe_zero]\n · rintro t ⟨u, hu, rfl⟩\n exact_mod_cast apply_nonneg p u\n · have hsval : s = (f z : EReal) := by\n apply hS.unique\n apply IsGreatest.isLUB\n refine ⟨⟨z, hpz, rfl⟩, ?_⟩\n rintro t ⟨u, hu, rfl⟩\n exact EReal.coe_le_coe_iff.mpr (hmax u hu)\n have hpos : 0 < f z := by\n rw [hsval] at hs\n exact_mod_cast hs\n have hbound (u : E) : |f u| ≤ f z * p u := by\n by_cases hu0 : p u = 0\n · simp [hu0, hfnull u hu0]\n have hu : 0 < p u := lt_of_le_of_ne (apply_nonneg p u) (Ne.symm hu0)\n have hunit : p ((p u)⁻¹ • u) = 1 := by\n rw [map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hu),\n inv_mul_cancel₀ hu0]\n have hhi := hmax ((p u)⁻¹ • u) hunit.le\n have hlo := hmax (-((p u)⁻¹ • u)) (by simpa using hunit.le)\n have habs : |f ((p u)⁻¹ • u)| ≤ f z := by\n apply abs_le.mpr\n constructor\n · simpa using neg_le_neg hlo\n · exact hhi\n rw [map_smul, smul_eq_mul, abs_mul, abs_of_pos (inv_pos.mpr hu),\n ← div_eq_inv_mul] at habs\n exact (div_le_iff₀ hu).mp habs\n have hpzone : p z = 1 := by\n have hz := hbound z\n rw [abs_of_pos hpos] at hz\n nlinarith\n rw [hsval, ← EReal.coe_div]\n constructor\n · refine ⟨(c / f z) • z, ?_, ?_⟩\n · rw [map_smul, smul_eq_mul, div_mul_cancel₀ _ hpos.ne']\n · rw [map_smul_eq_mul, Real.norm_eq_abs, hpzone, mul_one,\n abs_div, abs_of_pos hpos]\n · rintro t ⟨u, hu, rfl⟩\n apply EReal.coe_le_coe_iff.mpr\n apply (div_le_iff₀ hpos).mpr\n rw [← hu, mul_comm]\n exact hbound u\n\ntheorem min_manipulation_cost_lower_bound\n {d : ℕ} (l : (Fin d → ℝ) → ℝ) (w : Fin d → ℝ) (b : ℝ) (x : Fin d → ℝ)\n (lstar : EReal) (hlstar : 0 < lstar)\n (hnn : ∀ u : Fin d → ℝ, 0 ≤ l u)\n (hhom : ∀ (a : ℝ) (u : Fin d → ℝ), l (fun i => a * u i) = |a| * l u)\n (htri : ∀ u v : Fin d → ℝ, l (fun i => u i + v i) ≤ l u + l v)\n (hlub : IsLUB {t : EReal | ∃ z : Fin d → ℝ, l z ≤ 1 ∧ t = ((dotp w z : ℝ) : EReal)} lstar) :\n IsLeast {t : EReal | ∃ x' : Fin d → ℝ, dotp w x' + b = 0 ∧\n t = ((l (fun i => x' i - x i) : ℝ) : EReal)}\n (((|dotp w x + b| : ℝ) : EReal) / lstar) := by\n let p : Seminorm ℝ (Fin d → ℝ) := Seminorm.ofSMulLE l\n (by\n apply le_antisymm\n · simpa using (hhom 0 (0 : Fin d → ℝ)).le\n · exact hnn 0)\n htri (by\n intro a u\n simpa only [Real.norm_eq_abs] using (hhom a u).le)\n let f : (Fin d → ℝ) →ₗ[ℝ] ℝ :=\n { toFun := dotp w\n map_add' := by\n intro u v\n simp [dotp, mul_add, Finset.sum_add_distrib]\n map_smul' := by\n intro a u\n simp [dotp, Finset.mul_sum, mul_left_comm] }\n have h := seminorm_fiber_least p f (-(dotp w x + b)) lstar hlstar hlub\n have hset : {t : EReal | ∃ u : Fin d → ℝ, f u = -(dotp w x + b) ∧\n t = (p u : EReal)} =\n {t : EReal | ∃ x' : Fin d → ℝ, dotp w x' + b = 0 ∧\n t = ((l (fun i => x' i - x i) : ℝ) : EReal)} := by\n ext t\n constructor\n · rintro ⟨u, hu, rfl⟩\n refine ⟨x + u, ?_, ?_⟩\n · change f (x + u) + b = 0\n rw [map_add, hu]\n change dotp w x + -(dotp w x + b) + b = 0\n ring\n · congr 1\n change l u = l (fun i => (x + u) i - x i)\n congr 1\n ext i\n simp\n · rintro ⟨x', hx', rfl⟩\n refine ⟨x' - x, ?_, rfl⟩\n rw [map_sub]\n change dotp w x' - dotp w x = -(dotp w x + b)\n linarith\n simpa only [abs_neg, hset] using h\n\nend ResearchLevel\n"} +{"id": "v24-22-0522", "source": "Research-level", "targets": [{"label": "Lemma 8", "decls": ["lemma8"], "statement": "Lemma 8 Suppose that Assumption 1 holds. Let $\\begin{array}{r}{\\eta \\le \\frac{1}{4 L}}\\end{array}$ and $0 \\leq \\theta \\leq 1$ . In each epoch of Algorithm 1 where the \"if condition\" triggers, when $\\begin{array}{r}{\\|\\nabla f(\\mathbf{y}^{\\mathcal{K}-1})\\|>\\frac{B}{\\eta}}\\end{array}$ , we have\n\n$$\nf(\\mathbf{x}^{\\mathcal{K}})-f(\\mathbf{x}^{0})\\leq-\\frac{B^{2}}{4\\eta}.\n$$", "context_ids": ["v24-22-0522:ctx1", "v24-22-0522:ctx2", "v24-22-0522:ctx3", "v24-22-0522:ctx4", "v24-22-0522:ctx6"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}, {"label": "Corollary 12", "decls": ["corollary12"], "statement": "Corollary 12 Suppose that Assumption 1 holds. Use the parameter settings in Theorem 1. In each epoch of Algorithm 1 where the \"if condition\" triggers, we have\n\n$$\nf(\\mathbf{x}^{\\mathcal{K}})-f(\\mathbf{x}^{0})\\leq-\\frac{7\\epsilon^{3/2}}{8\\sqrt{\\rho}}.\\tag{20}\n$$", "context_ids": ["v24-22-0522:ctx1", "v24-22-0522:ctx2", "v24-22-0522:ctx3", "v24-22-0522:ctx4", "v24-22-0522:ctx5", "v24-22-0522:ctx6", "v24-22-0522:ctx10"], "sibling_refs": ["Lemma 8"], "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}, {"label": "Lemma 13", "decls": ["lemma13"], "statement": "Lemma 13 Suppose that Assumption 1 holds. Use the parameter settings in Theorem 1. In the last epoch of Algorithm 1 where the \"if condition\" does not trigger, we have $\\|\\nabla f(\\hat{\\mathbf{y}})\\|\\leq 82\\epsilon$", "context_ids": ["v24-22-0522:ctx1", "v24-22-0522:ctx2", "v24-22-0522:ctx3", "v24-22-0522:ctx4", "v24-22-0522:ctx5", "v24-22-0522:ctx6", "v24-22-0522:ctx7", "v24-22-0522:ctx11"], "sibling_refs": [], "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}], "nl_proof": "### Proof of Lemma 8\n\nProof As the gradient is L-Lipschitz, we have\n\n$$\n\\begin{array}{r l}f({\\mathbf x}^{k+1})&\\le f({\\mathbf y}^{k})+\\Big\\langle\\nabla f({\\mathbf y}^{k}),{\\mathbf x}^{k+1}-{\\mathbf y}^{k}\\Big\\rangle+\\frac{L}{2}\\|{\\mathbf x}^{k+1}-{\\mathbf y}^{k}\\|^{2}\\\\ &=f({\\mathbf y}^{k})-\\eta\\|\\nabla f({\\mathbf y}^{k})\\|^{2}+\\frac{L\\eta^{2}}{2}\\|\\nabla f({\\mathbf y}^{k})\\|^{2}\\\\ &\\le f({\\mathbf y}^{k})-\\frac{7\\eta}{8}\\|\\nabla f({\\mathbf y}^{k})\\|^{2},\\end{array}\\tag{11}\n$$\n\nwhere we use the AGD iteration on line 4 of Algorithm 1 and $\\begin{array}{r}{\\eta \\le \\frac{1}{4 L}}\\end{array}$ . From the L-gradient Lipschitz, we also have\n\n$$\nf(\\mathbf{x}^{k})\\geq f(\\mathbf{y}^{k})+\\left\\langle\\nabla f(\\mathbf{y}^{k}),\\mathbf{x}^{k}-\\mathbf{y}^{k}\\right\\rangle-\\frac{L}{2}\\|\\mathbf{x}^{k}-\\mathbf{y}^{k}\\|^{2}.\n$$\n\nSo we have\n\n$$\n\\begin{array}{r l}&{\\quad f({\\mathbf x}^{k+1})-f({\\mathbf x}^{k})}\\\\ &{\\le-\\left\\langle\\nabla f({\\mathbf y}^{k}),{\\mathbf x}^{k}-{\\mathbf y}^{k}\\right\\rangle+\\frac{L}{2}\\|{\\mathbf x}^{k}-{\\mathbf y}^{k}\\|^{2}-\\frac{7\\eta}{8}\\|\\nabla f({\\mathbf y}^{k})\\|^{2}}\\\\ &{=\\frac{1}{\\eta}\\left\\langle{\\mathbf x}^{k+1}-{\\mathbf y}^{k},{\\mathbf x}^{k}-{\\mathbf y}^{k}\\right\\rangle+\\frac{L}{2}\\|{\\mathbf x}^{k}-{\\mathbf y}^{k}\\|^{2}-\\frac{7\\eta}{8}\\|\\nabla f({\\mathbf y}^{k})\\|^{2}}\\\\ &{=\\frac{1}{2\\eta}\\left(\\|{\\mathbf x}^{k+1}-{\\mathbf y}^{k}\\|^{2}+\\|{\\mathbf x}^{k}-{\\mathbf y}^{k}\\|^{2}-\\|{\\mathbf x}^{k+1}-{\\mathbf x}^{k}\\|^{2}\\right)+\\frac{L}{2}\\|{\\mathbf x}^{k}-{\\mathbf y}^{k}\\|^{2}-\\frac{7\\eta}{8}\\|\\nabla f({\\mathbf y}^{k})\\|^{2}}\\\\ &{\\stackrel{\\mathrm{a~}}{\\le}\\frac{5}{8\\eta}\\|{\\mathbf x}^{k}-{\\mathbf y}^{k}\\|^{2}-\\frac{1}{2\\eta}\\|{\\mathbf x}^{k+1}-{\\mathbf x}^{k}\\|^{2}-\\frac{3\\eta}{8}\\|\\nabla f({\\mathbf y}^{k})\\|^{2}}\\\\ &{\\stackrel{b}{\\le}\\frac{5}{8\\eta}\\|{\\mathbf x}^{k}-{\\mathbf x}^{k-1}\\|^{2}-\\frac{1}{2\\eta}\\|{\\mathbf x}^{k+1}-{\\mathbf x}^{k}\\|^{2}-\\frac{3\\eta}{8}\\|\\nabla f({\\mathbf y}^{k})\\|^{2},}\\end{array}\n$$\n\nwhere we use $\\begin{array}{r}{L \\leq \\frac{1}{4 \\eta}}\\end{array}$ in $\\overset{a}{\\leq}$ and $\\|{\\mathbf{x}}^{k}-{\\mathbf{y}}^{k}\\|=(1-\\theta)\\|{\\mathbf{x}}^{k}-{\\mathbf{x}}^{k-1}\\|\\leq\\|{\\mathbf{x}}^{k}-{\\mathbf{x}}^{k-1}\\|$ in $\\overset{b}{\\leq}$. Summing over $k=0,\\cdots,\\mathcal{K}-1$ and using $\\mathbf{x}^{0}= \\mathbf{x}^{- 1}$ , we have\n\n$$\nf(\\mathbf{x}^{\\mathcal{K}})-f(\\mathbf{x}^{0})\\leq\\frac{1}{8\\eta}\\sum_{k=0}^{\\mathcal{K}-2}\\|\\mathbf{x}^{k+1}-\\mathbf{x}^{k}\\|^{2}-\\frac{3\\eta}{8}\\sum_{k=0}^{\\mathcal{K}-1}\\|\\nabla f(\\mathbf{y}^{k})\\|^{2}\n$$\n\n$$\n\\overset{c}{\\leq}\\frac{B^{2}}{8\\eta}-\\frac{3\\eta}{8}\\|\\nabla f(\\mathbf{y}^{\\mathcal{K}-1})\\|^{2}\\overset{d}{\\leq}\\frac{B^{2}}{8\\eta}-\\frac{3B^{2}}{8\\eta}= -\\frac{B^{2}}{4\\eta},\n$$\n\nwhere we use (8b) in $\\overset{c}{\\leq}$ and $\\|\\nabla f(\\mathbf{y}^{\\mathcal{K}-1})\\|>\\frac{B}{\\eta}$ in $\\overset{d}{\\leq}$.\n\n### Proof of Corollary 12\n\nProof Since $g_{j}(x)$ is quadratic, we have\n\n$$\n\\begin{array}{r l}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k+1})&=g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})+\\left\\langle\\nabla g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k}),\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\right\\rangle+\\frac{\\lambda_{j}}{2}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}\\\\ &\\overset{a}{=}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})-\\frac{1}{\\eta}\\left\\langle\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k}+\\eta\\widetilde{\\delta}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\right\\rangle\\\\ &\\quad+\\left\\langle\\nabla g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})-\\nabla g_{j}(\\widetilde{\\mathbf{y}}_{j}^{k}),\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\right\\rangle+\\frac{\\lambda_{j}}{2}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}\\\\ &=g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})-\\frac{1}{\\eta}\\left\\langle\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\right\\rangle-\\left\\langle\\widetilde{\\delta}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\right\\rangle\\\\ &\\quad+\\lambda_{j}\\left\\langle\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{y}}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\right\\rangle+\\frac{\\lambda_{j}}{2}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}\\\\ &=g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})+\\frac{1}{2\\eta}\\left(|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}- |\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}- |\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}\\right)\\\\ &\\quad-\\left\\langle\\widetilde{\\delta}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\right\\rangle+\\frac{\\lambda_{j}}{2}\\left(|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}- |\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}\\right)\\\\ &\\le g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})+\\frac{1}{2\\eta}\\left(|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}- |\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}- |\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}\\right)\\\\ &\\quad+\\frac{1}{2\\alpha}|\\widetilde{\\delta}_{j}^{k}|^{2}+\\frac{\\alpha}{2}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\frac{\\lambda_{j}}{2}\\left(|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}- |\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}\\right),\\end{array}\n$$\n\nfor some positive constant α to be specified later, where we use (14b) in $\\overset{a}{=}$. Using $L \\geq \\lambda_{j}\\geq$ $- \\frac{\\theta}{\\eta}$ when $\\begin{array}{r}{j\\in{\\cal S}_{1}=\\left\\{j:\\lambda_{j}\\geq-\\frac{\\theta}{\\eta}\\right\\}\\mathrm{and}\\left(-\\frac{1}{2\\eta}+\\frac{\\lambda_{j}}{2}\\right)|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}\\leq\\left(-2 L+\\frac{L}{2}\\right)|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}\\leq 0}\\end{array}$, we have for each $j \\in S_{1}$\n\n$$\n\\begin{array}{r l r}{{g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k+1})\\le g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})+\\frac{1}{2\\eta}(|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}- |\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2})+\\frac{1}{2\\alpha}|\\widetilde{\\delta}_{j}^{k}|^{2}+\\frac{\\alpha}{2}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\frac{\\theta}{2\\eta}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{y}}_{j}^{k}|^{2}}}\\\\ &{}&{\\overset{b}{=}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})+\\frac{(1+\\theta)(1-\\theta)^{2}}{2\\eta}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1}|^{2}-(\\frac{1}{2\\eta}-\\frac{\\alpha}{2})|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\frac{1}{2\\alpha}|\\widetilde{\\delta}_{j}^{k}|^{2},\\qquad}\\end{array}\n$$\n\nwhere we use (14a) in $\\overset{b}{=}$ . Defining the potential function\n\n$$\n\\ell_{j}^{k+1}=g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k+1})+\\frac{(1+\\theta)(1-\\theta)^{2}}{2\\eta}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2},\n$$\n\nwe have\n\n$$\n\\begin{array}{r l}&{\\ell_{j}^{k+1}\\leq\\ell_{j}^{k}-\\left(\\displaystyle\\frac{1}{2\\eta}-\\displaystyle\\frac{\\alpha}{2}-\\displaystyle\\frac{(1+\\theta)(1-\\theta)^{2}}{2\\eta}\\right)|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\displaystyle\\frac{1}{2\\alpha}|\\widetilde{\\delta}_{j}^{k}|^{2}}\\\\ &{\\quad\\leq\\ell_{j}^{k}-\\displaystyle\\frac{3\\theta}{8\\eta}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\displaystyle\\frac{2\\eta}{\\theta}|\\widetilde{\\delta}_{j}^{k}|^{2},}\\end{array}\n$$\n\nwhere we let $\\begin{array}{r}{\\alpha = \\frac{\\theta}{4 \\eta}}\\end{array}$ in $\\overset{c}{\\leq}$ such that $\\begin{array}{r}{\\frac{1}{2\\eta}-\\frac{\\theta}{8\\eta}-\\frac{(1+\\theta)(1-\\theta)^{2}}{2\\eta}=\\frac{3\\theta}{8\\eta}+\\frac{\\theta^{2}}{2\\eta}-\\frac{\\theta^{3}}{2\\eta}\\geq\\frac{3\\theta}{8\\eta}}\\end{array}$ . Summing over $k=0,1,\\cdots,\\mathcal{K}-1$ and $j \\in S_{1}$ , using $\\mathbf{x}^{0}- \\mathbf{x}^{- 1}= 0$ ,we have\n\n$$\n\\begin{array}{r}{\\displaystyle\\sum_{j\\in S_{1}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{\\mathcal{K}})\\leq\\displaystyle\\sum_{j\\in S_{1}}\\ell_{j}^{\\mathcal{K}}\\leq\\displaystyle\\sum_{j\\in S_{1}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{0})-\\displaystyle\\sum_{j\\in S_{1}}\\frac{3\\theta}{8\\eta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}\\vert\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\vert^{2}+\\displaystyle\\frac{2\\eta}{\\theta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}\\|\\widetilde\\delta^{k}\\|^{2}}\\\\ {\\overset{d}{\\leq}\\displaystyle\\sum_{j\\in S_{1}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{0})-\\displaystyle\\sum_{j\\in S_{1}}\\frac{3\\theta}{8\\eta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}\\vert\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}\\vert^{2}+\\displaystyle\\frac{8\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta},}\\end{array}\n$$\n\nwhere we use (15) in $\\overset{d}{\\leq}$.\n\nProof Denoting $\\begin{array}{r}{\\mathbf{v}_{j}=\\widetilde{\\mathbf{x}}_{j}^{0}-\\frac{1}{\\lambda_{j}}\\widetilde{\\nabla}_{j}f(\\mathbf{x}^{0}),g_{j}(x)}\\end{array}$ can be rewritten as\n\n$$\n\\begin{array}{l}{{\\displaystyle g_{j}(x)=\\frac{\\lambda_{j}}{2}\\left(x-\\widetilde{\\mathbf{x}}_{j}^{0}+\\frac{1}{\\lambda_{j}}\\widetilde{\\nabla}_{j}f(\\mathbf{x}^{0})\\right)^{2}-\\frac{1}{2\\lambda_{j}}\\vert\\widetilde{\\nabla}_{j}f(\\mathbf{x}^{0})\\vert^{2}}}\\\\ {{\\displaystyle~=\\frac{\\lambda_{j}}{2}\\vert x-\\mathbf{v}_{j}\\vert^{2}-\\frac{1}{2\\lambda_{j}}\\vert\\widetilde{\\nabla}_{j}f(\\mathbf{x}^{0})\\vert^{2}.}}\\end{array}\n$$\n\nFor each $\\begin{array}{r}{j \\in \\mathcal{S}_{2}= \\{j : \\lambda_{j}< - \\frac{\\theta}{\\eta}\\}}\\end{array}$ , we have\n\n$$\n\\begin{array}{l}{{\\displaystyle g_{j}({\\widetilde{\\mathbf{x}}}_{j}^{k + 1}) - g_{j}({\\widetilde{\\mathbf{x}}}_{j}^{k}) = \\frac{\\lambda_{j}}{2}|{\\widetilde{\\mathbf{x}}}_{j}^{k + 1}- \\mathbf{v}_{j}|^{2}- \\frac{\\lambda_{j}}{2}|{\\widetilde{\\mathbf{x}}}_{j}^{k}- \\mathbf{v}_{j}|^{2}}\\ ~}\\\\ {{\\displaystyle ~ = \\frac{\\lambda_{j}}{2}|{\\widetilde{\\mathbf{x}}}_{j}^{k + 1}-{\\widetilde{\\mathbf{x}}}_{j}^{k}|^{2}+ \\lambda_{j}\\left\\langle{\\widetilde{\\mathbf{x}}}_{j}^{k + 1}-{\\widetilde{\\mathbf{x}}}_{j}^{k},{\\widetilde{\\mathbf{x}}}_{j}^{k}- \\mathbf{v}_{j}\\right\\rangle}\\ ~}\\\\ {{\\displaystyle ~ \\leq - \\frac{\\theta}{2 \\eta}|{\\widetilde{\\mathbf{x}}}_{j}^{k + 1}-{\\widetilde{\\mathbf{x}}}_{j}^{k}|^{2}+ \\lambda_{j}\\left\\langle{\\widetilde{\\mathbf{x}}}_{j}^{k + 1}-{\\widetilde{\\mathbf{x}}}_{j}^{k},{\\widetilde{\\mathbf{x}}}_{j}^{k}- \\mathbf{v}_{j}\\right\\rangle}.}\\end{array}\\tag{18}\n$$\n\nSo we only need to bound the second term. From (14b) and (14a), we have\n\n$$\n\\begin{array}{r l}&{\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}=\\widetilde{\\mathbf{y}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k}-\\eta\\nabla g_{j}(\\widetilde{\\mathbf{y}}_{j}^{k})-\\eta\\widetilde{\\delta}_{j}^{k}}\\\\ &{\\qquad=(1-\\theta)(\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1})-\\eta\\nabla g_{j}(\\widetilde{\\mathbf{y}}_{j}^{k})-\\eta\\widetilde{\\delta}_{j}^{k}}\\\\ &{\\qquad=(1-\\theta)(\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1})-\\eta\\lambda_{j}(\\widetilde{\\mathbf{y}}_{j}^{k}-\\mathbf{v}_{j})-\\eta\\widetilde{\\delta}_{j}^{k}}\\\\ &{\\qquad=(1-\\theta)(\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1})-\\eta\\lambda_{j}(\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}+(1-\\theta)(\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1}))-\\eta\\widetilde{\\delta}_{j}^{k}.}\\end{array}\n$$\n\nSo for each $j \\in S_{2}$ , we have\n\n$$\n\\begin{array}{r l}&{\\quad\\lambda_{j}\\Big\\langle\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}\\Big\\rangle}\\\\ &{=(1-\\theta)\\lambda_{j}\\Big\\langle\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1},\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}\\Big\\rangle-\\eta\\lambda_{j}^{2}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}|^{2}-\\eta\\lambda_{j}^{2}(1-\\theta)\\Big\\langle\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1},\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}\\Big\\rangle-\\eta\\lambda_{j}\\Big\\langle\\widetilde{\\delta}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}\\Big\\rangle}\\\\ &{\\leq(1-\\theta)\\lambda_{j}\\Big\\langle\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1},\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}\\Big\\rangle-\\eta\\lambda_{j}^{2}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}|^{2}}\\\\ &{\\quad+\\frac{\\eta\\lambda_{j}^{2}(1-\\theta)}{2}\\Big(|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1}|^{2}+ |\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}|^{2}\\Big)+\\frac{\\eta}{2(1+\\theta)}|\\widetilde{\\delta}_{j}^{k}|^{2}+\\frac{\\eta\\lambda_{j}^{2}(1+\\theta)}{2}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}|^{2}}\\\\ &{=(1-\\theta)\\lambda_{j}\\Big\\langle\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1},\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}\\Big\\rangle+\\frac{\\eta\\lambda_{j}^{2}(1-\\theta)}{2}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1}|^{2}+\\frac{\\eta}{2(1+\\theta)}|\\widetilde{\\delta}_{j}^{k}|^{2}}\\\\ &{=(1-\\theta)\\lambda_{j}\\Big\\langle\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1},\\widetilde{\\mathbf{x}}_{j}^{k-1}-\\mathbf{v}_{j}\\Big\\rangle+(1-\\theta)\\lambda_{j}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1}|^{2}+\\frac{\\eta\\lambda_{j}^{2}(1-\\theta)}{2}|\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1}|^{2}+\\frac{\\eta}{2(1+\\theta)}|\\widetilde{\\delta}_{j}^{k}|^{2}}\\\\ &{\\overset{a}{\\leq}(1-\\theta)\\lambda_{j}\\Big\\langle\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1},\\widetilde{\\mathbf{x}}_{j}^{k-1}-\\mathbf{v}_{j}\\Big\\rangle+\\frac{\\eta}{2}|\\widetilde{\\delta}_{j}^{k}|^{2},}\\end{array}\n$$\n\nwhere we use $\\begin{array}{r}{\\left(1+\\frac{\\eta\\lambda_{j}}{2}\\right)(1-\\theta)\\ge\\left(1-\\frac{\\eta L}{2}\\right)(1-\\theta)\\ge 0}\\end{array}$ and $\\lambda_{j}< 0$ when $j \\in{\\cal S}_{2}$ in $\\overset{a}{\\geq}$ So we have\n\n$$\n\\begin{array}{r l r}{{\\lambda_{j}\\left\\langle\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k},\\widetilde{\\mathbf{x}}_{j}^{k}-\\mathbf{v}_{j}\\right\\rangle\\le(1-\\theta)^{k}\\lambda_{j}\\left\\langle\\widetilde{\\mathbf{x}}_{j}^{1}-\\widetilde{\\mathbf{x}}_{j}^{0},\\widetilde{\\mathbf{x}}_{j}^{0}-\\mathbf{v}_{j}\\right\\rangle+\\displaystyle\\frac{\\eta}{2}\\sum_{t=1}^{k}(1-\\theta)^{k-t}|\\widetilde{\\delta}_{j}^{t}|^{2}}}\\\\ &{}&{\\overset{b}{=}-(1-\\theta)^{k}\\eta\\lambda_{j}^{2}|\\widetilde{\\mathbf{x}}_{j}^{0}-\\mathbf{v}_{j}|^{2}+\\displaystyle\\frac{\\eta}{2}\\sum_{t=1}^{k}(1-\\theta)^{k-t}|\\widetilde{\\delta}_{j}^{t}|^{2}}\\\\ &{}&{\\le\\displaystyle\\frac{\\eta}{2}\\sum_{t=1}^{k}(1-\\theta)^{k-t}|\\widetilde{\\delta}_{j}^{t}|^{2},}\\end{array}\n$$\n\nwhere we use\n\n$$\n\\begin{array}{c}{{{\\widetilde{\\bf x}}_{j}^{1}-{\\widetilde{\\bf x}}_{j}^{0}={\\widetilde{\\bf x}}_{j}^{1}-{\\widetilde{\\bf y}}_{j}^{0}= -\\eta\\widetilde\\nabla_{j}f({\\bf y}^{0})= -\\eta\\widetilde\\nabla_{j}f({\\bf x}^{0})}}\\\\ {{{\\mathrm{}}}}\\\\ {{{\\mathrm{}}= -\\eta\\nabla g_{j}(\\widetilde{\\bf x}_{j}^{0})= -\\eta\\lambda_{j}(\\widetilde{\\bf x}_{j}^{0}-{\\bf v}_{j})}}\\end{array}\n$$\n\nin $\\overset{b}{=}$. Plugging into (18), we have\n\n$$\ng_{j}(\\widetilde{\\mathbf{x}}_{j}^{k+1})-g_{j}(\\widetilde{\\mathbf{x}}_{j}^{k})\\leq-\\frac{\\theta}{2\\eta}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\frac{\\eta}{2}\\sum_{t=1}^{k}(1-\\theta)^{k-t}|\\widetilde\\delta_{j}^{t}|^{2}.\n$$\n\nSumming over $k=0,1,\\cdots,\\mathcal{K}-1$ and $j \\in S_{2}$ , we have\n\n$$\n\\begin{array}{r l}{\\displaystyle\\sum_{j\\in{\\mathcal{S}}_{2}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{\\mathcal{K}})-\\displaystyle\\sum_{j\\in{\\mathcal{S}}_{2}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{0})\\le-\\displaystyle\\sum_{j\\in{\\mathcal{S}}_{2}}\\frac{\\theta}{2\\eta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\displaystyle\\frac{\\eta}{2}\\sum_{k=0}^{\\mathcal{K}-1}\\sum_{t=1}^{k}(1-\\theta)^{k-t}\\|\\widetilde\\delta^{t}\\|^{2}}&{}\\\\ {\\overset{c}{\\le}-\\displaystyle\\sum_{j\\in{\\mathcal{S}}_{2}}\\frac{\\theta}{2\\eta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+2\\eta\\rho^{2}B^{4}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}\\sum_{t=1}^{k}(1-\\theta)^{k-t}}&{}\\\\ {\\le-\\displaystyle\\sum_{j\\in{\\mathcal{S}}_{2}}\\frac{\\theta}{2\\eta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\displaystyle\\frac{2\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta},}&{}\\end{array}\n$$\n\nwhere we use (15) in $\\overset{c}{\\leq}$.\n\nProof Summing over (16) and (17), we have\n\n$$\n\\begin{array}{r l}{g(\\widetilde{\\mathbf{x}}^{\\mathcal{K}})-g(\\widetilde{\\mathbf{x}}^{0})=\\displaystyle\\sum_{j\\in{\\cal S}_{1}\\cup{\\cal S}_{2}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{\\mathcal{K}})-g_{j}(\\widetilde{\\mathbf{x}}_{j}^{0})}&{}\\\\ {\\displaystyle\\leq-\\frac{3\\theta}{8\\eta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}\\|\\widetilde{\\mathbf{x}}^{k+1}-\\widetilde{\\mathbf{x}}^{k}\\|^{2}+\\frac{10\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta}}&{}\\\\ {\\displaystyle= -\\frac{3\\theta}{8\\eta}\\displaystyle\\sum_{k=0}^{\\mathcal{K}-1}\\|\\mathbf{x}^{k+1}-\\mathbf{x}^{k}\\|^{2}+\\frac{10\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta}}&{}\\\\ {\\displaystyle\\overset{a}{\\leq}-\\frac{3\\theta B^{2}}{8\\eta\\mathcal{K}}+\\frac{10\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta},}\\end{array}\n$$\n\nwhere we use (8a) in $\\overset{a}{\\leq}$. Plugging into (12) and using $\\mathcal{K} \\leq K$ , we have\n\n$$\n\\begin{array}{r}{f(\\mathbf{x}^{\\mathcal{K}})-f(\\mathbf{x}^{0})\\leq-\\displaystyle\\frac{3\\theta B^{2}}{8\\eta\\mathcal{K}}+\\frac{10\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta}+4.5\\rho B^{3}}\\\\ {\\leq-\\displaystyle\\frac{3\\theta B^{2}}{8\\eta\\mathcal{K}}+\\frac{10\\eta\\rho^{2}B^{4}K}{\\theta}+4.5\\rho B^{3}.}\\end{array}\n$$\n\nProof Combing Lemmas 8 and 11 and using the parameter settings, we have\n\n$$\nf({\\bf x}^{\\mathcal{K}})-f({\\bf x}^{0})\\le-\\operatorname*{min}\\Bigg\\{\\frac{3\\theta B^{2}}{8\\eta K}-\\frac{10\\eta\\rho^{2}B^{4}K}{\\theta}-4.5\\rho B^{3},\\frac{B^{2}}{4\\eta}\\Bigg\\}= -\\operatorname*{min}\\Bigg\\{\\frac{7\\epsilon^{3/2}}{8\\sqrt{\\rho}},\\frac{\\epsilon}{4\\eta\\rho}\\Bigg\\}.\n$$\n\nFrom $\\theta=4(\\epsilon\\rho\\eta^{2})^{1/4}\\leq 1$ , we have $\\begin{array}{r}{\\frac{7 \\epsilon^{3 / 2}}{8 \\sqrt{\\rho}}\\le \\frac{\\epsilon}{4 \\eta \\rho}}\\end{array}$\n\n### Proof of Lemma 13\n\nProof Denote $\\begin{array}{r}{\\widetilde{\\mathbf{y}}= \\mathbf{U}^{T}\\hat{\\mathbf{y}}= \\frac{1}{K_{0}+ 1}\\sum_{k = 0}^{K_{0}}\\mathbf{U}^{T}\\mathbf{y}^{k}= \\frac{1}{K_{0}+ 1}\\sum_{k = 0}^{K_{0}}\\widetilde{\\mathbf{y}}^{k}}\\end{array}$ . Since g is quadratic, we have\n\n$$\n\\begin{array}{r l}\\|\\nabla g(\\widetilde{\\mathbf{y}})\\|&=\\left\\|\\frac{1}{K_{0}+1}\\sum_{k=0}^{K_{0}}\\nabla g(\\widetilde{\\mathbf{y}}^{k})\\right\\|\\\\ &\\overset{a}{=}\\frac{1}{\\eta(K_{0}+1)}\\left\\|\\sum_{k=0}^{K_{0}}\\left(\\widetilde{\\mathbf{x}}^{k+1}-\\widetilde{\\mathbf{y}}^{k}+\\eta\\widetilde{\\delta}^{k}\\right)\\right\\|\\\\ &=\\frac{1}{\\eta(K_{0}+1)}\\left\\|\\sum_{k=0}^{K_{0}}\\left(\\widetilde{\\mathbf{x}}^{k+1}-\\widetilde{\\mathbf{x}}^{k}-(1-\\theta)(\\widetilde{\\mathbf{x}}^{k}-\\widetilde{\\mathbf{x}}^{k-1})+\\eta\\widetilde{\\delta}^{k}\\right)\\right\\|\\\\ &\\overset{b}{=}\\frac{1}{\\eta(K_{0}+1)}\\left\\|\\widetilde{\\mathbf{x}}^{K_{0}+1}-\\widetilde{\\mathbf{x}}^{0}-(1-\\theta)(\\widetilde{\\mathbf{x}}^{K_{0}}-\\widetilde{\\mathbf{x}}^{0})+\\eta\\sum_{k=0}^{K_{0}}\\widetilde{\\delta}^{k}\\right\\|\\\\ &=\\frac{1}{\\eta(K_{0}+1)}\\left\\|\\widetilde{\\mathbf{x}}^{K_{0}+1}-\\widetilde{\\mathbf{x}}^{K_{0}}+\\theta(\\widetilde{\\mathbf{x}}^{K_{0}}-\\widetilde{\\mathbf{x}}^{0})+\\eta\\sum_{k=0}^{K_{0}}\\widetilde{\\delta}^{k}\\right\\|\\\\ &\\le\\frac{1}{\\eta(K_{0}+1)}\\left(\\|\\widetilde{\\mathbf{x}}^{K_{0}+1}-\\widetilde{\\mathbf{x}}^{K_{0}}\\|+\\theta\\|\\widetilde{\\mathbf{x}}^{K_{0}}-\\widetilde{\\mathbf{x}}^{0}\\|+\\eta\\sum_{k=0}^{K_{0}}\\|\\widetilde{\\delta}^{k}\\|\\right)\\\\ &\\overset{c}{\\le}\\frac{2}{\\eta K}\\|\\widetilde{\\mathbf{x}}^{K_{0}+1}-\\widetilde{\\mathbf{x}}^{K_{0}}\\|+\\frac{2\\theta B}{\\eta K}+2\\rho B^{2},\\end{array}\\tag{21}\n$$\n\nwhere we use (14b) in $\\overset{a}{=}$, $\\mathbf{x}^{- 1}= \\mathbf{x}^{0}$ in $\\overset{b}{=}$, $K_{0}+ 1 \\geq \\frac{K}{2}$, (10a), (15), and (10b) in $\\overset{c}{\\leq}$. From $K_{0}=\\mathrm{argmin}_{\\lfloor\\frac{K}{2}\\rfloor\\leq k\\leq K-1}\\|\\mathbf{x}^{k+1}-\\mathbf{x}^{k}\\|$ , we have\n\n$$\n\\begin{array}{l}{\\displaystyle \\|{\\mathbf x}^{K_{0}+ 1}-{\\mathbf x}^{K_{0}}\\|^{2}\\leq \\frac{1}{K - \\lfloor K / 2 \\rfloor}\\displaystyle \\sum_{k = \\lfloor K / 2 \\rfloor}^{K - 1}\\|{\\mathbf x}^{k + 1}-{\\mathbf x}^{k}\\|^{2}}\\\\ {\\displaystyle \\leq \\frac{1}{K - \\lfloor K / 2 \\rfloor}\\displaystyle \\sum_{k = 0}^{K - 1}\\|{\\mathbf x}^{k + 1}-{\\mathbf x}^{k}\\|^{2}}\\\\ {\\displaystyle \\overset{d}{\\leq} \\frac{1}{K - \\lfloor K / 2 \\rfloor}\\displaystyle \\frac{B^{2}}{K}\\leq \\frac{2 B^{2}}{K^{2}},}\\end{array}\\tag{22}\n$$\n\nwhere we use (10a) in $\\overset{d}{\\leq}$. On the other hand, we also have\n\n$$\n\\begin{array}{r l}&{\\|\\nabla f(\\hat{\\mathbf{y}})\\|=\\|\\widetilde{\\nabla}f(\\hat{\\mathbf{y}})\\|\\leq\\|\\nabla g(\\widetilde{\\mathbf{y}})\\|+\\|\\widetilde{\\nabla}f(\\hat{\\mathbf{y}})-\\nabla g(\\widetilde{\\mathbf{y}})\\|}\\\\ &{\\qquad=\\|\\nabla g(\\widetilde{\\mathbf{y}})\\|+\\|\\widetilde{\\nabla}f(\\hat{\\mathbf{y}})-\\widetilde{\\nabla}f(\\mathbf{x}^{0})-\\pmb{\\Lambda}(\\widetilde{\\mathbf{y}}-\\widetilde{\\mathbf{x}}^{0})\\|}\\\\ &{\\qquad=\\|\\nabla g(\\widetilde{\\mathbf{y}})\\|+\\|\\nabla f(\\hat{\\mathbf{y}})-\\nabla f(\\mathbf{x}^{0})-\\mathbf{H}(\\hat{\\mathbf{y}}-\\mathbf{x}^{0})\\|}\\\\ &{\\qquad\\leq\\|\\nabla g(\\widetilde{\\mathbf{y}})\\|+\\frac{\\rho}{2}\\|\\hat{\\mathbf{y}}-\\mathbf{x}^{0}\\|^{2}\\overset{e}{\\leq}\\|\\nabla g(\\widetilde{\\mathbf{y}})\\|+2\\rho B^{2},}\\end{array}\n$$\n\nwhere we use $\\begin{array}{r}{\\| \\hat{\\mathbf{y}}- \\mathbf{x}^{0}\\| \\leq \\frac{1}{K_{0}+ 1}\\sum_{k = 0}^{K_{0}}\\| \\mathbf{y}^{k}- \\mathbf{x}^{0}\\| \\leq 2 B}\\end{array}$ from (10b) in $\\overset{e}{\\leq}$. So we have\n\n$$\n\\|\\nabla f(\\hat{\\mathbf{y}})\\|\\leq\\frac{2\\sqrt{2}B}{\\eta K^{2}}+\\frac{2\\theta B}{\\eta K}+4\\rho B^{2}\\leq 82\\epsilon .\n$$", "context": [{"id": "v24-22-0522:ctx1", "name": "Problem setup: problem (1) and approximate stationary point (Section 1)", "statement": "$$\n\\operatorname*{min}_{\\mathbf{x}\\in\\mathbb{R}^{d}}f(\\mathbf{x}),\\tag{1}\n$$\n\nwhere f (x) has Lipschitz continuous gradient and Hessian and it is bounded from below. Our goal is to find an $\\epsilon$-approximate first-order stationary point, defined as\n\n$$\n\\|\\nabla f(\\mathbf{x})\\|\\leq\\epsilon .\n$$"}, {"id": "v24-22-0522:ctx2", "name": "Notation and Assumption 1 (Section 1.4)", "statement": "We use lowercase bold letters to represent vectors, uppercase bold letters for matrices, and non-bold (both lowercase and uppercase) letters for scalars. Denote $\\mathbf{x}_{j}$ and $\\nabla_{j}f(\\mathbf{x})$ as the jth element of x and $\\nabla f(\\mathbf{x})$ , respectively. For the vectors produced in the iterative algorithms, for example, x, denote $\\mathbf{x}^{k}$ to be the value at the kth iteration. We denote $\\| \\cdot \\|$ to be the $\\ell_{2}$ Euclidean norm for vectors, $\\| \\cdot \\|_{2}$ as the spectral norm and $\\| \\cdot \\|_{F}$ as the Frobenius norm for matrices. We make the following standard assumptions in this paper.\n\nAssumption 1 1. f (x) is L-gradient Lipschitz: $\\|\\nabla f(\\mathbf{x})-\\nabla f(\\mathbf{y})\\|\\leq L\\|\\mathbf{x}-\\mathbf{y}\\|,\\forall\\mathbf{x},\\mathbf{y}\\in$ $\\mathbb{R}^{d}$ ,\n\n2. f (x) is ρ-Hessian Lipschitz: $\\begin{array}{r}{\\|\\nabla^{2}f(\\mathbf{x})-\\nabla^{2}f(\\mathbf{y})\\|_{2}\\leq\\rho\\|\\mathbf{x}-\\mathbf{y}\\|,\\forall\\mathbf{x},\\mathbf{y}\\in\\mathbb{R}^{d},}\\end{array}$\n\nwhich yield the following two well-known inequalities:\n\n$$\n\\begin{array}{r}{|f(\\mathbf{y})-f(\\mathbf{x})-\\langle\\nabla f(\\mathbf{x}),\\mathbf{y}-\\mathbf{x}\\rangle|\\leq\\frac{L}{2}\\|\\mathbf{y}-\\mathbf{x}\\|^{2},}\\end{array}\\tag{2}\n$$\n\n$$\n\\begin{array}{r}{\\big|f(\\mathbf{y})-f(\\mathbf{x})-\\langle\\nabla f(\\mathbf{x}),\\mathbf{y}-\\mathbf{x}\\rangle-(\\mathbf{y}-\\mathbf{x})^{T}\\nabla^{2}f(\\mathbf{x})(\\mathbf{y}-\\mathbf{x})\\big|\\leq\\frac{\\rho}{6}\\|\\mathbf{y}-\\mathbf{x}\\|^{3}.}\\end{array}\\tag{3}\n$$\n\nWe also assume that the objective function is lower bounded, that is, $\\min_{\\mathbf{x}}f(\\mathbf{x})> -\\infty$"}, {"id": "v24-22-0522:ctx3", "name": "Nesterov's AGD iteration (Section 2)", "statement": "Nesterov's classical AGD consists of the following iterations:\n\n$$\n\\begin{array}{r}{\\mathbf{y}^{k}=\\mathbf{x}^{k}+(1-\\theta)(\\mathbf{x}^{k}-\\mathbf{x}^{k-1}),\\quad\\mathbf{x}^{k+1}=\\mathbf{y}^{k}-\\eta\\nabla f(\\mathbf{y}^{k}),}\\end{array}\n$$"}, {"id": "v24-22-0522:ctx4", "name": "Algorithm 1 (RAGD-NC) and its description", "statement": "Algorithm 1 Restarted AGD for Nonconvex Optimization (RAGD-NC) \n1: Initialize ${\\bf x}^{- 1}={\\bf x}^{0}={\\bf x}_{i n t}, k = 0$ \n2: while $k < K$ do \n3: $\\mathbf{y}^{k}=\\mathbf{x}^{k}+(1-\\theta)(\\mathbf{x}^{k}-\\mathbf{x}^{k-1})$ \n4: $\\mathbf{x}^{k+1}=\\mathbf{y}^{k}-\\eta\\nabla f(\\mathbf{y}^{k})$ \n5: $k = k + 1$ \n6: if $k \\textstyle \\sum_{t = 0}^{k - 1}\\|{\\bf x}^{t + 1}-{\\bf x}^{t}\\|^{2}> B^{2}$ then \n7: $\\mathbf{x}^{- 1}= \\mathbf{x}^{0}= \\mathbf{x}^{k}, k = 0$ \n8: end if \n9: end while \n10: $K_{0}=\\mathrm{argmin}_{\\lfloor\\frac{K}{2}\\rfloor\\leq k\\leq K-1}\\|\\mathbf{x}^{k+1}-\\mathbf{x}^{k}\\|$ \n11: Output $\\begin{array}{r}{\\hat{\\mathbf{y}}= \\frac{1}{K_{0}+ 1}\\sum_{k = 0}^{K_{0}}\\mathbf{y}^{k}}\\end{array}$\n\nWe present our method in Algorithm 1. It runs Nesterov's classical AGD iterations until the \"if condition\" triggers. Then we reset $\\mathbf{x}^{0}$ and $\\mathbf{x}^{- 1}$ equal to $\\mathbf{x}^{k}$ and continue to the next round of AGD. The method terminates and outputs a specific average when the \"if condition\" does not trigger in K iterations. To simplify the description, we define one round of AGD between two successive restarts to be one \"epoch\". The restart trick, first proposed in (O'Donoghue and Candès, 2015), is motivated by (Fang et al., 2019), where a ball-mechanism is proposed as the stopping criteria to analyze SGD."}, {"id": "v24-22-0522:ctx5", "name": "Theorem 1 (parameter settings)", "statement": "Theorem 1 Suppose that Assumption 1 holds. Let $\\begin{array}{r}{\\eta=\\frac{1}{4L},B=\\sqrt{\\frac{\\epsilon}{\\rho}},\\theta=4(\\epsilon\\rho\\eta^{2})^{1/4}\\in(0,1].}\\end{array}$ and $\\begin{array}{r}{K = \\frac{1}{\\theta}}\\end{array}$ . Then Algorithm 1 terminates in at most $\\frac{\\triangle_{f}L^{1 / 2}\\rho^{1 / 4}}{\\epsilon^{7 / 4}}$ gradient computations and the output satisfies $\\|\\nabla f(\\hat{\\mathbf{y}})\\|\\leq 82\\epsilon$ , where $\\begin{array}{r}{\\triangle_{f}=f(\\mathbf{x}_{i n t})-\\operatorname*{min}_{\\mathbf{x}}f(\\mathbf{x})}\\end{array}$"}, {"id": "v24-22-0522:ctx6", "name": "Epoch quantities: trigger index (7), (8a), (8b), (9), (10a), (10b) (Section 4.1)", "statement": "We prove the convergence rate of Algorithm 1 in this section. Denote $\\mathcal{K}$ to be the iteration number when the \"if condition\" on line 6 of Algorithm 1 triggers, that is,\n\n$$\n\\mathcal{K}=\\operatorname*{min}_{k}\\left\\{k\\bigg|k\\sum_{t=0}^{k-1}\\|{\\bf x}^{t+1}-{\\bf x}^{t}\\|^{2}>B^{2}\\right\\}.\\tag{7}\n$$\n\nFor each epoch consisting of one round of AGD from iterations $k = 0$ to $k = \\mathcal{K}$ , we have\n\n$$\n1\\leq\\mathcal{K}\\leq K,\\qquad\\mathcal{K}\\sum_{t=0}^{\\mathcal{K}-1}\\|{\\bf x}^{t+1}-{\\bf x}^{t}\\|^{2}>B^{2},\\qquad\\mathrm{and}\\tag{8a}\n$$\n\n$$\n\\|{\\bf x}^{k}-{\\bf x}^{0}\\|^{2}=\\left\\|\\sum_{t=0}^{k-1}{\\bf x}^{t+1}-{\\bf x}^{t}\\right\\|^{2}\\leq k\\sum_{t=0}^{k-1}\\|{\\bf x}^{t+1}-{\\bf x}^{t}\\|^{2}\\leq B^{2},\\forall k<\\mathcal{K},\\tag{8b}\n$$\n\nwhere the last inequality comes from the definition of $\\mathcal{K}$. From the update of y on line 3 of Algorithm 1, we also have\n\n$$\n\\|\\mathbf{y}^{k}-\\mathbf{x}^{0}\\|\\leq\\|\\mathbf{x}^{k}-\\mathbf{x}^{0}\\|+\\|\\mathbf{x}^{k}-\\mathbf{x}^{k-1}\\|\\leq 2B,\\forall k<{\\mathcal{K}}.\\tag{9}\n$$\n\nOn the other hand, for the last epoch where the \"if condition\" does not trigger and the while loop breaks when k increases to $K$ ,we have\n\n$$\n\\|{\\mathbf{x}}^{k}-{\\mathbf{x}}^{0}\\|^{2}\\leq k\\sum_{t=0}^{k-1}\\|{\\mathbf{x}}^{t+1}-{\\mathbf{x}}^{t}\\|^{2}\\leq B^{2},\\forall k\\leq K,\\tag{10a}\n$$\n\n$$\n\\|\\mathbf{y}^{k}-\\mathbf{x}^{0}\\|\\leq 2B,\\forall k\\leq K.\\tag{10b}\n$$"}, {"id": "v24-22-0522:ctx7", "name": "Quadratic approximation setup: (12)-(15), S_1, S_2 (Section 4.1.2)", "statement": "If $\\|\\nabla f(\\mathbf{y}^{\\mathcal{K}-1})\\|\\leq\\frac{B}{\\eta}$ , then from the AGD iteration on line 4 and (9) we have\n\n$$\n\\begin{array}{r}{\\|{\\mathbf{x}}^{\\mathcal{K}}-{\\mathbf{x}}^{0}\\| \\leq \\|{\\mathbf{y}}^{\\mathcal{K} - 1}-{\\mathbf{x}}^{0}\\| + \\eta \\| \\nabla f ({\\mathbf{y}}^{\\mathcal{K} - 1}) \\| \\leq 3 B .}\\end{array}\n$$\n\nFor each epoch, denote $\\mathbf{H}=\\nabla^{2}f(\\mathbf{x}^{0})$ to be the Hessian matrix at the starting iterate and $\\mathbf{H}= \\mathbf{U}\\pmb{\\Lambda}\\mathbf{U}^{T}$ to be its eigenvalue decomposition with U, $\\pmb{\\Lambda}\\in \\mathbb{R}^{d \\times d}$ . Let $\\lambda_{j}$ be the jth eigenvalue. Define $\\widetilde{\\mathbf{x}}= \\mathbf{U}^{T}\\mathbf{x}, \\widetilde{\\mathbf{y}}= \\mathbf{U}^{T}\\mathbf{y}$ ,and $\\widetilde{\\nabla}f(\\mathbf{y})=\\mathbf{U}^{T}\\nabla f(\\mathbf{y})$ . As the Hessian is ρ-Lipschitz, we have\n\n$$\n\\begin{array}{l}{f({\\mathbf x}^{\\mathcal{K}})-f({\\mathbf x}^{0})\\le\\left\\langle\\nabla f({\\mathbf x}^{0}),{\\mathbf x}^{\\mathcal{K}}-{\\mathbf x}^{0}\\right\\rangle+\\displaystyle\\frac{1}{2}({\\mathbf x}^{\\mathcal{K}}-{\\mathbf x}^{0})^{T}{\\mathbf H}({\\mathbf x}^{\\mathcal{K}}-{\\mathbf x}^{0})+\\displaystyle\\frac{\\rho}{6}\\|{\\mathbf x}^{\\mathcal{K}}-{\\mathbf x}^{0}\\|^{3}}\\\\ {\\displaystyle=\\left\\langle\\widetilde\\nabla f({\\mathbf x}^{0}),\\widetilde{{\\mathbf x}}^{\\mathcal{K}}-\\widetilde{{\\mathbf x}}^{0}\\right\\rangle+\\displaystyle\\frac{1}{2}(\\widetilde{{\\mathbf x}}^{\\mathcal{K}}-\\widetilde{{\\mathbf x}}^{0})^{T}\\pmb{\\Lambda}(\\widetilde{{\\mathbf x}}^{\\mathcal{K}}-\\widetilde{{\\mathbf x}}^{0})+\\displaystyle\\frac{\\rho}{6}\\|{\\mathbf x}^{\\mathcal{K}}-{\\mathbf x}^{0}\\|^{3}}\\\\ {\\le g(\\widetilde{{\\mathbf x}}^{\\mathcal{K}})-g(\\widetilde{{\\mathbf x}}^{0})+4.5\\rho B^{3},}\\end{array}\\tag{12}\n$$\n\nwhere we denote\n\n$$\n\\begin{array}{l}{g({\\pmb x})=\\left\\langle\\widetilde{\\nabla}f({\\pmb x}^{0}),{\\pmb x}-\\widetilde{\\pmb x}^{0}\\right\\rangle+\\displaystyle\\frac{1}{2}({\\pmb x}-\\widetilde{\\pmb x}^{0})^{T}{\\pmb\\Lambda}({\\pmb x}-\\widetilde{\\pmb x}^{0})=\\sum_{j=1}^{d}g_{j}({\\pmb x}_{j}),}\\\\ {g_{j}(x)=\\left\\langle\\widetilde{\\nabla}_{j}f({\\pmb x}^{0}),x-\\widetilde{\\pmb x}_{j}^{0}\\right\\rangle+\\displaystyle\\frac{1}{2}\\lambda_{j}(x-\\widetilde{\\pmb x}_{j}^{0})^{2}.}\\end{array}\\tag{13}\n$$\n\nDenoting\n\n$$\n\\widetilde{\\delta}_{j}^{k}=\\widetilde{\\nabla}_{j}f(\\mathbf{y}^{k})-\\nabla g_{j}(\\widetilde{\\mathbf{y}}_{j}^{k}),\\qquad\\widetilde{\\delta}^{k}=\\widetilde{\\nabla}f(\\mathbf{y}^{k})-\\nabla g(\\widetilde{\\mathbf{y}}^{k}),\n$$\n\nthen the AGD iterations in Algorithm 1 can be rewritten as\n\n$$\n\\begin{array}{r l}&{\\widetilde{\\mathbf{y}}_{j}^{k}=\\widetilde{\\mathbf{x}}_{j}^{k}+(1-\\theta)(\\widetilde{\\mathbf{x}}_{j}^{k}-\\widetilde{\\mathbf{x}}_{j}^{k-1}),}\\\\ &{\\widetilde{\\mathbf{x}}_{j}^{k+1}=\\widetilde{\\mathbf{y}}_{j}^{k}-\\eta\\widetilde{\\nabla}_{j}f(\\mathbf{y}^{k})=\\widetilde{\\mathbf{y}}_{j}^{k}-\\eta\\nabla g_{j}(\\widetilde{\\mathbf{y}}_{j}^{k})-\\eta\\widetilde{\\delta}_{j}^{k},}\\end{array}\\tag{14a}\n$$\n\n(14b)\n\nand $\\lVert \\widetilde{\\delta}^{k}\\rVert$ can be bounded as\n\n$$\n\\begin{array}{r l r}{{\\|\\widetilde{\\delta}^{k}\\|=\\|\\widetilde{\\nabla}f(\\mathbf{y}^{k})-\\widetilde{\\nabla}f(\\mathbf{x}^{0})-\\pmb{\\Lambda}(\\widetilde{\\mathbf{y}}^{k}-\\widetilde{\\mathbf{x}}^{0})\\|}}\\\\ &{}&{=\\|\\nabla f(\\mathbf{y}^{k})-\\nabla f(\\mathbf{x}^{0})-\\mathbf{H}(\\mathbf{y}^{k}-\\mathbf{x}^{0})\\|}\\\\ &{}&{=\\|(\\int_{0}^{1}\\nabla^{2}f(\\mathbf{x}^{0}+t(\\mathbf{y}^{k}-\\mathbf{x}^{0}))-\\mathbf{H})(\\mathbf{y}^{k}-\\mathbf{x}^{0})dt\\|}\\\\ &{}&{\\leq\\frac{\\rho}{2}\\|\\mathbf{y}^{k}-\\mathbf{x}^{0}\\|^{2}\\leq 2\\rho B^{2}}\\end{array}\\tag{15}\n$$\n\nfor any $k < \\mathcal{K}$ , where we use the ρ-Lipschitz Hessian assumption and (9) in the last two inequalities, respectively.\n\nThanks to (12), to prove the decrease from $f(\\mathbf{x}^{0})$ to $f(\\mathbf{x}^{\\mathcal{K}})$ , we only need to study the decrease of g(x). Iterations (14a) and (14b) can be regarded as applying AGD to the quadratic approximation $g(\\mathbf{x})$ coordinately with the approximation error $\\widetilde{\\delta}^{k}$ , where the later can be controlled within $\\mathcal{O}(\\rho B^{2})$ . The quadratic approximation $g(\\mathbf{x})$ equals to the sum of d scalar functions $g_{j}(\\mathbf{x}_{j})$ . We decompose $g(\\mathbf{x})$ into $\\textstyle\\sum_{j\\in S_{1}}g_{j}(\\mathbf{x}_{j})$ and $\\textstyle\\sum_{j\\in S_{2}}g_{j}(\\mathbf{x}_{j})$ , where\n\n$$\n{\\mathcal{S}}_{1}=\\left\\{j:\\lambda_{j}\\geq-{\\frac{\\theta}{\\eta}}\\right\\}\\quad{\\mathrm{and}}\\quad{\\mathcal{S}}_{2}=\\left\\{j:\\lambda_{j}< -{\\frac{\\theta}{\\eta}}\\right\\}.\n$$\n\nWe see that $g_{j}(x)$ is approximate convex when $j \\in S_{1}$ , and strongly concave when $j \\in S_{2}$ We will prove the approximate decrease of $g_{j}(\\mathbf{x}_{j})$ in the above two cases. We first consider $\\textstyle\\sum_{j\\in S_{1}}g_{j}(\\mathbf{x}_{j})$ in the following lemma."}, {"id": "v24-22-0522:ctx8", "name": "Lemma 9", "statement": "Lemma 9 Suppose that Assumption 1 holds. Let $\\begin{array}{r}{\\eta \\le \\frac{1}{4 L}}\\end{array}$ and $0 < \\theta \\leq 1$ . In each epoch of Algorithm 1 where the \"if condition\" triggers, when $\\begin{array}{r}{\\|\\nabla f(\\mathbf{y}^{\\mathcal{K}-1})\\|\\le\\frac{B}{\\eta}}\\end{array}$ , we have\n\n$$\n\\sum_{j\\in{\\cal S}_{1}}g_{j}(\\widetilde{{\\bf x}}_{j}^{\\mathcal{K}})-\\sum_{j\\in{\\cal S}_{1}}g_{j}(\\widetilde{{\\bf x}}_{j}^{0})\\leq-\\sum_{j\\in{\\cal S}_{1}}\\frac{3\\theta}{8\\eta}\\sum_{k=0}^{\\mathcal{K}-1}|\\widetilde{{\\bf x}}_{j}^{k+1}-\\widetilde{{\\bf x}}_{j}^{k}|^{2}+\\frac{8\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta}.\\tag{16}\n$$"}, {"id": "v24-22-0522:ctx9", "name": "Lemma 10", "statement": "Lemma 10 Suppose that Assumption 1 holds. Let $\\begin{array}{r}{\\eta \\le \\frac{1}{4 L}}\\end{array}$ and $0 < \\theta \\leq 1$ . In each epoch of Algorithm 1 where the \"if condition\" triggers, when $\\begin{array}{r}{\\|\\nabla f(\\mathbf{y}^{\\mathcal{K}-1})\\|\\le\\frac{B}{\\eta}}\\end{array}$ , we have\n\n$$\n\\sum_{j\\in S_{2}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{\\mathcal{K}})-\\sum_{j\\in S_{2}}g_{j}(\\widetilde{\\mathbf{x}}_{j}^{0})\\leq-\\sum_{j\\in S_{2}}\\frac{\\theta}{2\\eta}\\sum_{k=0}^{\\mathcal{K}-1}|\\widetilde{\\mathbf{x}}_{j}^{k+1}-\\widetilde{\\mathbf{x}}_{j}^{k}|^{2}+\\frac{2\\eta\\rho^{2}B^{4}\\mathcal{K}}{\\theta}.\\tag{17}\n$$"}, {"id": "v24-22-0522:ctx10", "name": "Lemma 11", "statement": "Lemma 11 Suppose that Assumption 1 holds. Let $\\begin{array}{r}{\\eta \\le \\frac{1}{4 L}}\\end{array}$ and $0 < \\theta \\leq 1$ . In each epoch of Algorithm 1 where the \"if condition\" triggers, when $\\begin{array}{r}{\\|\\nabla f(\\mathbf{y}^{\\mathcal{K}-1})\\|\\le\\frac{B}{\\eta}}\\end{array}$ , we have\n\n$$\nf(\\mathbf{x}^{\\mathcal{K}})-f(\\mathbf{x}^{0})\\leq-\\frac{3\\theta B^{2}}{8\\eta K}+\\frac{10\\eta\\rho^{2}B^{4}K}{\\theta}+4.5\\rho B^{3}.\\tag{19}\n$$"}, {"id": "v24-22-0522:ctx11", "name": "Remark 14 (role of the averaged output in (22))", "statement": "Remark 14 The purpose of using the specific average as the output and $k \\sum_{t = 0}^{k - 1}\\| \\mathbf{x}^{t + 1}- \\mathbf{x}^{t}\\|^{2}> B^{2}$ in the \"if condition\" in Algorithm 1, rather than $\\| \\mathbf{x}^{k}- \\mathbf{x}^{0}\\| \\geq B$ , is to establish (22)."}], "lean": "import Mathlib\n\nopen scoped NNReal BigOperators\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E]\n\ntheorem lemma8 [FiniteDimensional ℝ E]\n {f : E → ℝ} {f' : E → E} {L ρ : ℝ≥0}\n (hflb : BddBelow (Set.range f))\n (hf' : ∀ x, HasGradientAt f (f' x) x) (hLip : LipschitzWith L f')\n (Hf : E → (E →L[ℝ] E)) (hf'' : ∀ x, HasFDerivAt f' (Hf x) x)\n (hHLip : LipschitzWith ρ Hf)\n (η θ B : ℝ) (hη : 0 < η) (hηL : η ≤ 1 / (4 * (L : ℝ)))\n (hL0 : 0 < (L : ℝ)) (hρ0 : 0 < (ρ : ℝ)) (hθ0 : 0 ≤ θ) (hθ1 : θ ≤ 1) (hB : 0 ≤ B)\n (K : ℕ) (hK : 1 ≤ K) (x y : ℕ → E)\n (hy : ∀ k, y k = x k + (1 - θ) • (x k - x (k - 1)))\n (hx : ∀ k, x (k + 1) = y k - η • f' (y k))\n (h8a : B ^ 2 < (K : ℝ) * ∑ t ∈ Finset.range K, ‖x (t + 1) - x t‖ ^ 2)\n (h8b : ∀ k, k < K → (k : ℝ) * ∑ t ∈ Finset.range k, ‖x (t + 1) - x t‖ ^ 2 ≤ B ^ 2)\n (hbig : ‖f' (y (K - 1))‖ > B / η) :\n f (x K) - f (x 0) ≤ -(B ^ 2 / (4 * η)) := by\n sorry\n\ntheorem corollary12 [FiniteDimensional ℝ E]\n {f : E → ℝ} {f' : E → E} {L ρ : ℝ≥0}\n (hflb : BddBelow (Set.range f))\n (hf' : ∀ x, HasGradientAt f (f' x) x) (hLip : LipschitzWith L f')\n (Hf : E → (E →L[ℝ] E)) (hf'' : ∀ x, HasFDerivAt f' (Hf x) x)\n (hHLip : LipschitzWith ρ Hf)\n (ε : ℝ) (hε : 0 < ε) (hL0 : 0 < (L : ℝ)) (hρ0 : 0 < (ρ : ℝ))\n (η θ B : ℝ)\n (hηv : η = 1 / (4 * (L : ℝ)))\n (hBv : B = Real.sqrt (ε / (ρ : ℝ)))\n (hθv : θ = 4 * (ε * (ρ : ℝ) * η ^ 2) ^ ((1 : ℝ) / 4))\n (hθ0 : 0 < θ) (hθ1 : θ ≤ 1)\n (K : ℕ) (hK : 1 ≤ K) (hKv : (K : ℝ) ≤ 1 / θ)\n (x y : ℕ → E)\n (hy : ∀ k, y k = x k + (1 - θ) • (x k - x (k - 1)))\n (hx : ∀ k, x (k + 1) = y k - η • f' (y k))\n (h8a : B ^ 2 < (K : ℝ) * ∑ t ∈ Finset.range K, ‖x (t + 1) - x t‖ ^ 2)\n (h8b : ∀ k, k < K → (k : ℝ) * ∑ t ∈ Finset.range k, ‖x (t + 1) - x t‖ ^ 2 ≤ B ^ 2) :\n f (x K) - f (x 0) ≤ -(7 * ε ^ ((3 : ℝ) / 2)) / (8 * Real.sqrt (ρ : ℝ)) := by\n sorry\n\ntheorem lemma13 [FiniteDimensional ℝ E]\n {f : E → ℝ} {f' : E → E} {L ρ : ℝ≥0}\n (hflb : BddBelow (Set.range f))\n (hf' : ∀ x, HasGradientAt f (f' x) x) (hLip : LipschitzWith L f')\n (Hf : E → (E →L[ℝ] E)) (hf'' : ∀ x, HasFDerivAt f' (Hf x) x)\n (hHLip : LipschitzWith ρ Hf)\n (ε : ℝ) (hε : 0 < ε) (hL0 : 0 < (L : ℝ)) (hρ0 : 0 < (ρ : ℝ))\n (η θ B : ℝ)\n (hηv : η = 1 / (4 * (L : ℝ)))\n (hBv : B = Real.sqrt (ε / (ρ : ℝ)))\n (hθv : θ = 4 * (ε * (ρ : ℝ) * η ^ 2) ^ ((1 : ℝ) / 4))\n (hθ0 : 0 < θ) (hθ1 : θ ≤ 1)\n (K : ℕ) (hK : 1 ≤ K) (hKv : (K : ℝ) = 1 / θ)\n (x y : ℕ → E)\n (hy : ∀ k, y k = x k + (1 - θ) • (x k - x (k - 1)))\n (hx : ∀ k, x (k + 1) = y k - η • f' (y k))\n (h10a : ∀ k, k ≤ K → (k : ℝ) * ∑ t ∈ Finset.range k, ‖x (t + 1) - x t‖ ^ 2 ≤ B ^ 2)\n (K₀ : ℕ) (hK₀lo : K / 2 ≤ K₀) (hK₀hi : K₀ < K)\n (hK₀min : ∀ k, K / 2 ≤ k → k < K → ‖x (K₀ + 1) - x K₀‖ ≤ ‖x (k + 1) - x k‖)\n (yhat : E)\n (hyhat : yhat = ((K₀ : ℝ) + 1)⁻¹ • ∑ k ∈ Finset.range (K₀ + 1), y k) :\n ‖f' yhat‖ ≤ 82 * ε := by\n sorry\ntheorem theorem1_complexity\n (ε ρ L Δ : ℝ) (hε : 0 < ε) (hρ : 0 < ρ) (hL : 0 < L) (hΔ : 0 ≤ Δ)\n (hK1 : (1 : ℝ) ≤ (1 : ℝ) / 2 * (L ^ 2 / (ε * ρ)) ^ ((1 : ℝ) / 4))\n (N : ℕ) (F : ℕ → ℝ) (Fmin : ℝ)\n (hdec : ∀ i, i < N →\n F (i + 1) ≤ F i - 7 * ε ^ ((3 : ℝ) / 2) / (8 * Real.sqrt ρ))\n (hlb : Fmin ≤ F N)\n (hΔf : F 0 - Fmin ≤ Δ) :\n (N : ℝ) * ((1 : ℝ) / 2 * (L ^ 2 / (ε * ρ)) ^ ((1 : ℝ) / 4))\n ≤ Δ * Real.sqrt L * ρ ^ ((1 : ℝ) / 4) / ε ^ ((7 : ℝ) / 4) := by\n set u : ℝ := ε ^ ((1:ℝ)/4) with hu\n set v : ℝ := ρ ^ ((1:ℝ)/4) with hv\n have hu0 : 0 < u := Real.rpow_pos_of_pos hε _\n have hv0 : 0 < v := Real.rpow_pos_of_pos hρ _\n have hsL0 : 0 < Real.sqrt L := Real.sqrt_pos.mpr hL\n have hε32 : ε ^ ((3:ℝ)/2) = u^6 := by\n rw [hu, ← Real.rpow_natCast (ε ^ ((1:ℝ)/4)) 6, ← Real.rpow_mul hε.le]\n norm_num\n have hε74 : ε ^ ((7:ℝ)/4) = u^7 := by\n rw [hu, ← Real.rpow_natCast (ε ^ ((1:ℝ)/4)) 7, ← Real.rpow_mul hε.le]\n norm_num\n have hρs : Real.sqrt ρ = v^2 := by\n rw [hv, ← Real.rpow_natCast (ρ ^ ((1:ℝ)/4)) 2, ← Real.rpow_mul hρ.le, Real.sqrt_eq_rpow]\n norm_num\n have hLrp : (L ^ 2 / (ε * ρ)) ^ ((1:ℝ)/4) = Real.sqrt L / (u * v) := by\n rw [Real.div_rpow (by positivity) (by positivity), Real.mul_rpow hε.le hρ.le]\n congr 1\n rw [← Real.rpow_natCast L 2, ← Real.rpow_mul hL.le, Real.sqrt_eq_rpow]\n norm_num\n -- descent chain\n set c : ℝ := 7 * ε ^ ((3:ℝ)/2) / (8 * Real.sqrt ρ) with hc\n have hc0 : 0 < c := by\n rw [hc]; positivity\n have hstep : ∀ m, m ≤ N → F m ≤ F 0 - (m:ℝ) * c := by\n intro m\n induction m with\n | zero => intro _; simp\n | succ k ih =>\n intro hk\n have h1 := ih (by omega)\n have h2 := hdec k (by omega)\n push_cast\n linarith\n have hNc : (N:ℝ) * c ≤ Δ := by\n have h := hstep N le_rfl\n linarith\n set R : ℝ := Real.sqrt L * v / u^7 with hR\n have hR0 : 0 ≤ R := by rw [hR]; positivity\n have hAeq : (1:ℝ)/2 * (L ^ 2 / (ε * ρ)) ^ ((1:ℝ)/4) = (4/7) * R * c := by\n rw [hLrp, hR, hc, hε32, hρs]\n field_simp\n ring\n have hgoal : Δ * Real.sqrt L * ρ ^ ((1:ℝ)/4) / ε ^ ((7:ℝ)/4) = Δ * R := by\n rw [hR, ← hv, hε74]\n ring\n rw [hAeq, hgoal]\n have : (N:ℝ) * ((4/7) * R * c) = (4/7) * R * ((N:ℝ) * c) := by ring\n rw [this]\n nlinarith [hR0, hNc, hΔ]\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen scoped NNReal BigOperators\n\nnamespace ResearchLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E]\n\nprivate lemma le_of_sq_le_sq' {a c : ℝ} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : a^2 ≤ c^2) : a ≤ c := by\n nlinarith\n\nprivate theorem norm_sum_sq_le {ι : Type*} (s : Finset ι) (v : ι → E) :\n ‖∑ i ∈ s, v i‖^2 ≤ (s.card : ℝ) * ∑ i ∈ s, ‖v i‖^2 := by\n have h1 : ‖∑ i ∈ s, v i‖ ≤ ∑ i ∈ s, ‖v i‖ := norm_sum_le s v\n have h2 : (∑ i ∈ s, ‖v i‖)^2 ≤ (s.card : ℝ) * ∑ i ∈ s, ‖v i‖^2 :=\n sq_sum_le_card_mul_sum_sq\n nlinarith [norm_nonneg (∑ i ∈ s, v i),\n Finset.sum_nonneg (fun i (_ : i ∈ s) => norm_nonneg (v i))]\n\nprivate theorem grad_taylor\n {f' : E → E} {Hf : E → (E →L[ℝ] E)} {ρ : ℝ}\n (hf'' : ∀ z, HasFDerivAt f' (Hf z) z)\n (hHLip : ∀ u v : E, ‖Hf u - Hf v‖ ≤ ρ * ‖u - v‖)\n (a b : E) : ‖f' b - f' a - (Hf a) (b - a)‖ ≤ ρ / 2 * ‖b - a‖ ^ 2 := by\n set v : E := b - a with hv\n set F : ℝ → E := fun t => f' (a + t • v) - f' a - t • (Hf a v) with hFdef\n have hc : ∀ t : ℝ, HasDerivAt (fun s : ℝ => a + s • v) v t := by\n intro t\n simpa using ((hasDerivAt_id t).smul_const v).const_add a\n have hFd : ∀ t : ℝ, HasDerivAt F ((Hf (a + t • v)) v - (Hf a) v) t := by\n intro t\n have h1 : HasDerivAt (fun s : ℝ => f' (a + s • v)) ((Hf (a + t • v)) v) t :=\n (hf'' (a + t • v)).comp_hasDerivAt t (hc t)\n have h2 : HasDerivAt (fun s : ℝ => s • ((Hf a) v)) ((Hf a) v) t := by\n simpa using (hasDerivAt_id t).smul_const ((Hf a) v)\n exact (h1.sub_const (f' a)).sub h2\n set Bd : ℝ → ℝ := fun t => ρ / 2 * t ^ 2 * ‖v‖ ^ 2 with hBdef\n have hB : ∀ t : ℝ, HasDerivAt Bd (ρ * t * ‖v‖ ^ 2) t := by\n intro t\n have : HasDerivAt (fun s : ℝ => ρ / 2 * s ^ 2 * ‖v‖ ^ 2) (ρ / 2 * (2 * t) * ‖v‖ ^ 2) t := by\n have h3 : HasDerivAt (fun s : ℝ => s ^ 2) (2 * t) t := by\n simpa using (hasDerivAt_pow 2 t)\n simpa using ((h3.const_mul (ρ/2)).mul_const (‖v‖ ^ 2))\n convert this using 1\n ring\n have key : ∀ t ∈ Set.Icc (0:ℝ) 1, ‖F t‖ ≤ Bd t := by\n apply image_norm_le_of_norm_deriv_right_le_deriv_boundary\n (f' := fun t => (Hf (a + t • v)) v - (Hf a) v)\n · exact fun t _ => (hFd t).continuousAt.continuousWithinAt\n · exact fun t _ => (hFd t).hasDerivWithinAt\n · simp [hFdef, hBdef]\n · exact hB\n · intro t ht\n have h1 : ‖(Hf (a + t • v)) v - (Hf a) v‖ ≤ ‖Hf (a + t • v) - Hf a‖ * ‖v‖ := by\n have : (Hf (a + t • v)) v - (Hf a) v = (Hf (a + t • v) - Hf a) v := by simp\n rw [this]\n exact ContinuousLinearMap.le_opNorm _ _\n have h2 : ‖Hf (a + t • v) - Hf a‖ ≤ ρ * (t * ‖v‖) := by\n have h := hHLip (a + t • v) a\n simp only [add_sub_cancel_left, norm_smul, Real.norm_eq_abs] at h\n rw [abs_of_nonneg ht.1] at h\n exact h\n calc ‖(Hf (a + t • v)) v - (Hf a) v‖ ≤ ‖Hf (a + t • v) - Hf a‖ * ‖v‖ := h1\n _ ≤ (ρ * (t * ‖v‖)) * ‖v‖ := mul_le_mul_of_nonneg_right h2 (norm_nonneg _)\n _ = ρ * t * ‖v‖ ^ 2 := by ring\n have hfin := key 1 (by norm_num)\n simp only [hFdef, hBdef, one_smul, one_mul] at hfin\n have hab : a + v = b := by simp [hv]\n rw [hab] at hfin\n simpa [hv] using hfin\n\nprivate theorem taylor_two_sided\n {f : E → ℝ} {f' : E → E} {L : ℝ}\n (hf' : ∀ z, HasGradientAt f (f' z) z)\n (hLip : ∀ u v : E, ‖f' u - f' v‖ ≤ L * ‖u - v‖)\n (a b : E) : |f b - f a - inner ℝ (f' a) (b - a)| ≤ L / 2 * ‖b - a‖ ^ 2 := by\n set v : E := b - a with hv\n set F : ℝ → ℝ := fun t => f (a + t • v) - f a - t * inner ℝ (f' a) v with hFdef\n have hc : ∀ t : ℝ, HasDerivAt (fun s : ℝ => a + s • v) v t := by\n intro t\n simpa using ((hasDerivAt_id t).smul_const v).const_add a\n have hFd : ∀ t : ℝ, HasDerivAt F ((inner ℝ (f' (a + t • v)) v : ℝ) - inner ℝ (f' a) v) t := by\n intro t\n have h1 : HasDerivAt (fun s : ℝ => f (a + s • v)) (inner ℝ (f' (a + t • v)) v : ℝ) t := by\n simpa using ((hf' (a + t • v)).hasFDerivAt).comp_hasDerivAt t (hc t)\n have h2 : HasDerivAt (fun s : ℝ => s * (inner ℝ (f' a) v : ℝ)) (inner ℝ (f' a) v : ℝ) t := by\n simpa using (hasDerivAt_id t).mul_const (inner ℝ (f' a) v : ℝ)\n exact (h1.sub_const (f a)).sub h2\n set B : ℝ → ℝ := fun t => L / 2 * t ^ 2 * ‖v‖ ^ 2 with hBdef\n have hB : ∀ t : ℝ, HasDerivAt B (L * t * ‖v‖ ^ 2) t := by\n intro t\n have : HasDerivAt (fun s : ℝ => L / 2 * s ^ 2 * ‖v‖ ^ 2) (L / 2 * (2 * t) * ‖v‖ ^ 2) t := by\n have h3 : HasDerivAt (fun s : ℝ => s ^ 2) (2 * t) t := by\n simpa using (hasDerivAt_pow 2 t)\n simpa using ((h3.const_mul (L/2)).mul_const (‖v‖ ^ 2))\n convert this using 1\n ring\n have key : ∀ t ∈ Set.Icc (0:ℝ) 1, ‖F t‖ ≤ B t := by\n apply image_norm_le_of_norm_deriv_right_le_deriv_boundary\n (f' := fun t => (inner ℝ (f' (a + t • v)) v : ℝ) - inner ℝ (f' a) v)\n · exact fun t _ => (hFd t).continuousAt.continuousWithinAt\n · exact fun t _ => (hFd t).hasDerivWithinAt\n · simp [hFdef, hBdef]\n · exact hB\n · intro t ht\n have h1 : |(inner ℝ (f' (a + t • v)) v : ℝ) - inner ℝ (f' a) v|\n ≤ ‖f' (a + t • v) - f' a‖ * ‖v‖ := by\n rw [← inner_sub_left]\n exact abs_real_inner_le_norm _ _\n have h2 : ‖f' (a + t • v) - f' a‖ ≤ L * (t * ‖v‖) := by\n have := hLip (a + t • v) a\n simp only [add_sub_cancel_left, norm_smul, Real.norm_eq_abs] at this\n rw [abs_of_nonneg ht.1] at this\n exact this\n calc ‖(inner ℝ (f' (a + t • v)) v : ℝ) - inner ℝ (f' a) v‖\n ≤ ‖f' (a + t • v) - f' a‖ * ‖v‖ := h1\n _ ≤ (L * (t * ‖v‖)) * ‖v‖ := by\n apply mul_le_mul_of_nonneg_right h2 (norm_nonneg _)\n _ = L * t * ‖v‖ ^ 2 := by ring\n have hfin := key 1 (by norm_num)\n simp only [hFdef, hBdef, one_smul, one_mul] at hfin\n have hab : a + v = b := by simp [hv]\n rw [hab] at hfin\n simpa [hv] using hfin\n\nprivate theorem step_ineq\n {f : E → ℝ} {f' : E → E} {L : ℝ}\n (hf' : ∀ z, HasGradientAt f (f' z) z)\n (hLip : ∀ u v : E, ‖f' u - f' v‖ ≤ L * ‖u - v‖)\n {η : ℝ} (hη : 0 < η) (hLη : L * η ≤ 1/4)\n (xk xk1 yk : E) (hxk1 : xk1 = yk - η • f' yk) :\n f xk1 - f xk ≤ 5/(8*η) * ‖xk - yk‖^2 - 1/(2*η) * ‖xk1 - xk‖^2 - 3*η/8 * ‖f' yk‖^2 := by\n have h1 := taylor_two_sided hf' hLip yk xk1\n have h2 := taylor_two_sided hf' hLip yk xk\n set g := f' yk with hgdef\n set u := xk - yk with hudef\n have e1 : xk1 - yk = -(η • g) := by rw [hxk1]; abel\n have e2 : xk1 - xk = -(u + η • g) := by rw [hxk1, hudef]; abel\n have hi1 : (inner ℝ g (xk1 - yk) : ℝ) = -(η * ‖g‖^2) := by\n rw [e1, inner_neg_right, real_inner_smul_right, real_inner_self_eq_norm_sq]\n have hn1 : ‖xk1 - yk‖^2 = η^2 * ‖g‖^2 := by\n rw [e1, norm_neg, norm_smul, Real.norm_eq_abs, abs_of_pos hη, mul_pow]\n have hi2 : (inner ℝ g (xk - yk) : ℝ) = (inner ℝ u g : ℝ) := by\n rw [← hudef, real_inner_comm]\n have hn2 : ‖xk1 - xk‖^2 = ‖u‖^2 + 2*η*(inner ℝ u g : ℝ) + η^2*‖g‖^2 := by\n rw [e2, norm_neg, norm_add_sq_real, real_inner_smul_right, norm_smul, Real.norm_eq_abs,\n abs_of_pos hη, mul_pow]\n ring\n rw [hi1, hn1] at h1\n rw [hi2] at h2\n rw [hn2]\n have hAnn : (0:ℝ) ≤ ‖u‖^2 := sq_nonneg _\n have hGnn : (0:ℝ) ≤ ‖g‖^2 := sq_nonneg _\n have hc1 : L/2 * ‖u‖^2 ≤ 1/(8*η) * ‖u‖^2 := by\n apply mul_le_mul_of_nonneg_right _ hAnn\n rw [le_div_iff₀ (by positivity)]\n nlinarith\n have hc2 : L/2 * (η^2 * ‖g‖^2) ≤ η/8 * ‖g‖^2 := by\n nlinarith [mul_nonneg hGnn (le_of_lt hη)]\n have h1' : f xk1 - f yk - -(η * ‖g‖^2) ≤ L/2 * (η^2 * ‖g‖^2) := (abs_le.mp h1).2\n have h2' : -(L/2 * ‖u‖^2) ≤ f xk - f yk - (inner ℝ u g : ℝ) := (abs_le.mp h2).1\n have expand : 5/(8*η) * ‖u‖^2 - 1/(2*η) * (‖u‖^2 + 2*η*(inner ℝ u g : ℝ) + η^2*‖g‖^2)\n - 3*η/8 * ‖g‖^2 = 1/(8*η)*‖u‖^2 - (inner ℝ u g : ℝ) - 7*η/8*‖g‖^2 := by\n field_simp\n ring\n rw [expand]\n linarith\n\ntheorem lemma8 [FiniteDimensional ℝ E]\n {f : E → ℝ} {f' : E → E} {L ρ : ℝ≥0}\n (hflb : BddBelow (Set.range f))\n (hf' : ∀ x, HasGradientAt f (f' x) x) (hLip : LipschitzWith L f')\n (Hf : E → (E →L[ℝ] E)) (hf'' : ∀ x, HasFDerivAt f' (Hf x) x)\n (hHLip : LipschitzWith ρ Hf)\n (η θ B : ℝ) (hη : 0 < η) (hηL : η ≤ 1 / (4 * (L : ℝ)))\n (hL0 : 0 < (L : ℝ)) (hρ0 : 0 < (ρ : ℝ)) (hθ0 : 0 ≤ θ) (hθ1 : θ ≤ 1) (hB : 0 ≤ B)\n (K : ℕ) (hK : 1 ≤ K) (x y : ℕ → E)\n (hy : ∀ k, y k = x k + (1 - θ) • (x k - x (k - 1)))\n (hx : ∀ k, x (k + 1) = y k - η • f' (y k))\n (h8a : B ^ 2 < (K : ℝ) * ∑ t ∈ Finset.range K, ‖x (t + 1) - x t‖ ^ 2)\n (h8b : ∀ k, k < K → (k : ℝ) * ∑ t ∈ Finset.range k, ‖x (t + 1) - x t‖ ^ 2 ≤ B ^ 2)\n (hbig : ‖f' (y (K - 1))‖ > B / η) :\n f (x K) - f (x 0) ≤ -(B ^ 2 / (4 * η)) := by\n have hLip' : ∀ u v : E, ‖f' u - f' v‖ ≤ (L:ℝ) * ‖u - v‖ := by\n intro u v\n have h := hLip.dist_le_mul u v\n simpa [dist_eq_norm] using h\n have h4L : (0:ℝ) < 4 * (L:ℝ) := by positivity\n have hLη : (L:ℝ) * η ≤ 1/4 := by\n have h := mul_le_mul_of_nonneg_right hηL h4L.le\n rw [one_div, inv_mul_cancel₀ (ne_of_gt h4L)] at h\n nlinarith\n have step : ∀ k, f (x (k+1)) - f (x k) ≤ 5/(8*η) * ‖x k - y k‖^2\n - 1/(2*η) * ‖x (k+1) - x k‖^2 - 3*η/8 * ‖f' (y k)‖^2 :=\n fun k => step_ineq hf' hLip' hη hLη (x k) (x (k+1)) (y k) (hx k)\n have hPk : ∀ k, ‖x k - y k‖^2 ≤ ‖x k - x (k-1)‖^2 := by\n intro k\n have hxy : x k - y k = -((1-θ) • (x k - x (k-1))) := by rw [hy k]; abel\n rw [hxy, norm_neg, norm_smul, Real.norm_eq_abs, mul_pow]\n have habs : |1-θ|^2 ≤ 1 := by\n have h1 : |1 - θ| ≤ 1 := by rw [abs_le]; constructor <;> linarith\n nlinarith [abs_nonneg (1-θ)]\n nlinarith [sq_nonneg ‖x k - x (k-1)‖]\n have step' : ∀ k, f (x (k+1)) - f (x k) ≤ 5/(8*η) * ‖x k - x (k-1)‖^2\n - 1/(2*η) * ‖x (k+1) - x k‖^2 - 3*η/8 * ‖f' (y k)‖^2 := by\n intro k\n have hc : (0:ℝ) < 5/(8*η) := by positivity\n have := mul_le_mul_of_nonneg_left (hPk k) hc.le\n linarith [step k]\n have key0 : f (x K) - f (x 0) ≤ ∑ k ∈ Finset.range K, (5/(8*η) * ‖x k - x (k-1)‖^2\n - 1/(2*η) * ‖x (k+1) - x k‖^2 - 3*η/8 * ‖f' (y k)‖^2) := by\n have h := Finset.sum_le_sum (s := Finset.range K)\n (f := fun k => f (x (k+1)) - f (x k))\n (g := fun k => 5/(8*η) * ‖x k - x (k-1)‖^2\n - 1/(2*η) * ‖x (k+1) - x k‖^2 - 3*η/8 * ‖f' (y k)‖^2)\n (fun k _ => step' k)\n rwa [Finset.sum_range_sub (fun k => f (x k))] at h\n have expand : ∑ k ∈ Finset.range K, (5/(8*η) * ‖x k - x (k-1)‖^2\n - 1/(2*η) * ‖x (k+1) - x k‖^2 - 3*η/8 * ‖f' (y k)‖^2)\n = 5/(8*η) * (∑ k ∈ Finset.range K, ‖x k - x (k-1)‖^2)\n - 1/(2*η) * (∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2)\n - 3*η/8 * (∑ k ∈ Finset.range K, ‖f' (y k)‖^2) := by\n rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.mul_sum,\n ← Finset.mul_sum]\n rw [expand] at key0\n have hshift : (∑ k ∈ Finset.range K, ‖x k - x (k-1)‖^2)\n = ∑ k ∈ Finset.range (K-1), ‖x (k+1) - x k‖^2 := by\n obtain ⟨m, rfl⟩ : ∃ m, K = m + 1 := ⟨K - 1, by omega⟩\n rw [Finset.sum_range_succ']\n simp\n rw [hshift] at key0\n set S' : ℝ := ∑ k ∈ Finset.range (K-1), ‖x (k+1) - x k‖^2 with hS'def\n set S : ℝ := ∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2 with hSdef\n have hS'S : S' ≤ S := by\n apply Finset.sum_le_sum_of_subset_of_nonneg\n · intro i hi\n simp only [Finset.mem_range] at *\n omega\n · intro i _ _; positivity\n have hS'0 : 0 ≤ S' := Finset.sum_nonneg (fun i _ => by positivity)\n have hQsum : ‖f' (y (K-1))‖^2 ≤ ∑ k ∈ Finset.range K, ‖f' (y k)‖^2 := by\n apply Finset.single_le_sum (f := fun k => ‖f' (y k)‖^2)\n · intro i _; positivity\n · simp only [Finset.mem_range]; omega\n have key2 : f (x K) - f (x 0) ≤ 5/(8*η) * S' - 1/(2*η) * S' - 3*η/8 * ‖f' (y (K-1))‖^2 := by\n have hc1 : (0:ℝ) < 1/(2*η) := by positivity\n have hc2 : (0:ℝ) < 3*η/8 := by positivity\n have t1 := mul_le_mul_of_nonneg_left hS'S hc1.le\n have t2 := mul_le_mul_of_nonneg_left hQsum hc2.le\n linarith\n have hS'B : S' ≤ B^2 := by\n rcases Nat.lt_or_ge 1 K with hK2 | hK2\n · have hb := h8b (K-1) (by omega)\n have hcast : (1:ℝ) ≤ ((K-1 : ℕ) : ℝ) := by\n have : 1 ≤ K - 1 := by omega\n exact_mod_cast this\n nlinarith\n · have : K = 1 := by omega\n subst this\n simp only [hS'def]\n norm_num\n positivity\n have hbn : (0:ℝ) ≤ B/η := div_nonneg hB (le_of_lt hη)\n have hQ2 : (B/η)^2 < ‖f' (y (K-1))‖^2 := by nlinarith\n have hQ3 : B^2/η^2 < ‖f' (y (K-1))‖^2 := by\n rw [div_pow] at hQ2; exact hQ2\n have e1 : 5/(8*η) * S' - 1/(2*η) * S' ≤ B^2/(8*η) := by\n have : 5/(8*η) * S' - 1/(2*η) * S' = 1/(8*η) * S' := by field_simp; ring\n rw [this]\n have hc : (0:ℝ) < 1/(8*η) := by positivity\n have := mul_le_mul_of_nonneg_left hS'B hc.le\n calc 1/(8*η) * S' ≤ 1/(8*η) * B^2 := this\n _ = B^2/(8*η) := by ring\n have e2 : 3*B^2/(8*η) ≤ 3*η/8 * ‖f' (y (K-1))‖^2 := by\n have hc : (0:ℝ) ≤ 3*η/8 := by positivity\n have h := mul_le_mul_of_nonneg_left hQ3.le hc\n have heq : 3*η/8 * (B^2/η^2) = 3*B^2/(8*η) := by field_simp\n linarith [heq ▸ h]\n have e3 : B^2/(8*η) - 3*B^2/(8*η) = -(B^2/(4*η)) := by\n field_simp\n ring\n linarith\n\nset_option maxHeartbeats 1000000 in\nprivate lemma scalar_step1 (η θ γ lam a b c w D : ℝ) (hη : 0 < η) (hθ0 : 0 < θ) (hθ1 : θ ≤ 1)\n (hlam1 : lam ≤ 1/(4*η)) (hlamlo : -(θ/η) ≤ lam)\n (hw : w = a + (1-θ)*(a-b)) (hc : c = w - η*(γ + lam*w + D)) :\n γ*c + (lam/2)*c^2 + ((1+θ)*(1-θ)^2/(2*η))*(c-a)^2\n ≤ γ*a + (lam/2)*a^2 + ((1+θ)*(1-θ)^2/(2*η))*(a-b)^2\n - (3*θ/(8*η))*(c-a)^2 + (2*η/θ)*D^2 := by\n have hgw : γ + lam*w = (w - c)/η - D := by\n rw [hc]; field_simp; ring\n have hA : γ*c + (lam/2)*c^2 - (γ*a + (lam/2)*a^2)\n = (γ + lam*w)*(c-a) + (lam/2)*(c-w)^2 - (lam/2)*(w-a)^2 := by ring\n have hB : (γ + lam*w)*(c-a)\n = (1/(2*η))*((w-a)^2 - (c-a)^2 - (c-w)^2) - D*(c-a) := by\n rw [hgw]; field_simp; ring\n have hdec : γ*c + (lam/2)*c^2 - (γ*a + (lam/2)*a^2)\n = (1/(2*η) - lam/2)*(w-a)^2 - (1/(2*η))*(c-a)^2 + (lam/2 - 1/(2*η))*(c-w)^2\n - D*(c-a) := by\n rw [hA, hB]; ring\n have hP : (1/(2*η) - lam/2)*(w-a)^2 ≤ ((1+θ)/(2*η))*(w-a)^2 := by\n have hgap : ((1+θ)/(2*η)) - (1/(2*η) - lam/2) = θ/(2*η) + lam/2 := by\n field_simp; ring\n have hnn : 0 ≤ θ/(2*η) + lam/2 := by\n have h2 : θ/(2*η) = (θ/η)/2 := by field_simp\n rw [h2]; linarith\n nlinarith [sq_nonneg (w-a)]\n have hQ : (lam/2 - 1/(2*η))*(c-w)^2 ≤ 0 := by\n have h1 : lam/2 - 1/(2*η) ≤ 0 := by\n have h2 : (1:ℝ)/(4*η) - 1/(2*η) = -(1/(4*η)) := by field_simp; ring\n have h3 : (0:ℝ) < 1/(4*η) := by positivity\n linarith [hlam1]\n nlinarith [sq_nonneg (c-w)]\n have hD : -(D*(c-a)) ≤ (2*η/θ)*D^2 + (θ/(8*η))*(c-a)^2 := by\n have hid : (θ/(8*η))*((c-a) + (4*η/θ)*D)^2\n = (θ/(8*η))*(c-a)^2 + D*(c-a) + (2*η/θ)*D^2 := by\n field_simp; ring\n have hp : 0 ≤ (θ/(8*η))*((c-a) + (4*η/θ)*D)^2 := by positivity\n linarith\n have hwa : (w-a)^2 = (1-θ)^2*(a-b)^2 := by rw [hw]; ring\n have hcoef : ((1+θ)/(2*η))*((1-θ)^2*(a-b)^2) = ((1+θ)*(1-θ)^2/(2*η))*(a-b)^2 := by\n field_simp\n rw [hwa] at hdec hP\n rw [hcoef] at hP\n have hfin : ((1+θ)*(1-θ)^2/(2*η)) + (3*θ/(8*η)) + (θ/(8*η)) - (1/(2*η)) ≤ 0 := by\n have hkey : ((1+θ)*(1-θ)^2/(2*η)) + (3*θ/(8*η)) + (θ/(8*η)) - (1/(2*η))\n = (θ^2*(θ-1))/(2*η) := by\n field_simp; ring\n rw [hkey]\n have h1 : θ^2*(θ-1) ≤ 0 := by nlinarith\n exact div_nonpos_of_nonpos_of_nonneg h1 (by positivity)\n have hlast : 0 ≤ (-(((1+θ)*(1-θ)^2/(2*η)) + (3*θ/(8*η)) + (θ/(8*η)) - (1/(2*η)))) * (c-a)^2 :=\n mul_nonneg (by linarith) (sq_nonneg _)\n linarith [hdec, hP, hQ, hD, hlast]\n\nset_option maxHeartbeats 1000000 in\nprivate lemma scalar_step2 (η θ lam v z0 z1 z2 w D : ℝ) (hη : 0 < η) (hθ0 : 0 < θ) (hθ1 : θ ≤ 1)\n (hlamneg : lam < 0) (hlamlo : -(1/(4*η)) ≤ lam)\n (hw : w = z1 + (1-θ)*(z1 - z0)) (hz2 : z2 = w - η*(lam*(w - v) + D)) :\n lam*(z2 - z1)*(z1 - v) ≤ (1-θ)*(lam*(z1-z0)*(z0-v)) + (η/2)*D^2 := by\n have hid : (1-θ)*(lam*(z1-z0)*(z0-v)) + (η/2)*D^2 - lam*(z2 - z1)*(z1 - v)\n = η*((1/2)*(D + lam*(z1-v))^2 + (1/2)*(lam*(z1-v) + (1-θ)*lam*(z1-z0))^2\n - (z1-z0)^2*(((1-θ)*lam)*((1-θ)*lam/2 + 1/η))) := by\n rw [hz2, hw]; field_simp; ring\n have hc1 : (1-θ)*lam ≤ 0 := mul_nonpos_of_nonneg_of_nonpos (by linarith) (le_of_lt hlamneg)\n have hc2 : 0 ≤ (1-θ)*lam/2 + 1/η := by\n have h1 : -(1/(4*η)) ≤ (1-θ)*lam := by\n nlinarith [hlamlo, hlamneg, hθ1, hθ0]\n have h2 : (1:ℝ)/(4*η) ≤ 1/η := by\n have : (1:ℝ)/(4*η) = (1/η)/4 := by field_simp\n rw [this]\n have : (0:ℝ) < 1/η := by positivity\n linarith\n linarith\n have hprod : ((1-θ)*lam)*((1-θ)*lam/2 + 1/η) ≤ 0 := mul_nonpos_of_nonpos_of_nonneg hc1 hc2\n have hneg : 0 ≤ -((z1-z0)^2*(((1-θ)*lam)*((1-θ)*lam/2 + 1/η))) := by\n have := mul_nonneg (sq_nonneg (z1-z0)) (neg_nonneg.mpr hprod)\n linarith [this]\n nlinarith [hid, hneg, sq_nonneg (D + lam*(z1-v)),\n sq_nonneg (lam*(z1-v) + (1-θ)*lam*(z1-z0)), hη]\n\nset_option maxHeartbeats 1000000 in\nprivate lemma scalar_descent (η θ γ lam : ℝ) (hη : 0 < η) (hθ0 : 0 < θ) (hθ1 : θ ≤ 1)\n (hlam1 : lam ≤ 1/(4*η)) (hlam2 : -(1/(4*η)) ≤ lam)\n (z d : ℕ → ℝ) (hz0 : z 0 = 0) (hd0 : d 0 = 0)\n (hrec : ∀ k : ℕ, z (k+1) = (z k + (1-θ)*(z k - z (k-1)))\n - η * (γ + lam * (z k + (1-θ)*(z k - z (k-1))) + d k))\n (K : ℕ) :\n γ * z K + (lam/2) * (z K)^2 ≤ -(3*θ/(8*η)) * ∑ k ∈ Finset.range K, (z (k+1) - z k)^2\n + (2*η/θ) * ∑ k ∈ Finset.range K, (d k)^2 := by\n rcases le_or_lt (-(θ/η)) lam with hcase | hcase\n · -- Case 1 : lam ≥ -θ/η\n have hβ0 : (0:ℝ) ≤ (1+θ)*(1-θ)^2/(2*η) := by positivity\n have hstep : ∀ k : ℕ,\n γ * z (k+1) + (lam/2)*(z (k+1))^2 + ((1+θ)*(1-θ)^2/(2*η))*(z (k+1) - z k)^2\n ≤ γ * z k + (lam/2)*(z k)^2 + ((1+θ)*(1-θ)^2/(2*η))*(z k - z (k-1))^2\n - (3*θ/(8*η))*(z (k+1) - z k)^2 + (2*η/θ)*(d k)^2 := fun k =>\n scalar_step1 η θ γ lam (z k) (z (k-1)) (z (k+1))\n (z k + (1-θ)*(z k - z (k-1))) (d k) hη hθ0 hθ1 hlam1 hcase rfl (hrec k)\n have hmain : ∀ n : ℕ, γ * z n + (lam/2)*(z n)^2 + ((1+θ)*(1-θ)^2/(2*η))*(z n - z (n-1))^2\n ≤ -(3*θ/(8*η)) * ∑ k ∈ Finset.range n, (z (k+1) - z k)^2\n + (2*η/θ) * ∑ k ∈ Finset.range n, (d k)^2 := by\n intro n\n induction n with\n | zero => simp [hz0]\n | succ m ih =>\n rw [Finset.sum_range_succ, Finset.sum_range_succ]\n have h := hstep m\n simp only [Nat.add_sub_cancel] at h ⊢\n linarith\n have h := hmain K\n have h2 : (0:ℝ) ≤ ((1+θ)*(1-θ)^2/(2*η))*(z K - z (K-1))^2 :=\n mul_nonneg hβ0 (sq_nonneg _)\n linarith\n · -- Case 2 : lam < -θ/η\n have hlamneg : lam < 0 := by\n have hp : (0:ℝ) < θ/η := by positivity\n linarith\n have hlne : lam ≠ 0 := ne_of_lt hlamneg\n obtain ⟨v, hv⟩ : ∃ v : ℝ, γ = -(lam*v) := ⟨-γ/lam, by field_simp⟩\n set A : ℕ → ℝ := fun k => lam*(z (k+1) - z k)*(z k - v) with hA\n have hz1 : z 1 = -(η*γ) := by\n have h := hrec 0\n simp only [Nat.zero_sub, hz0, hd0] at h\n rw [h]; ring\n have hA0 : A 0 ≤ 0 := by\n have : A 0 = -(η*lam^2*v^2) := by\n simp only [hA, hz1, hz0, hv]; ring\n rw [this]\n have : 0 ≤ η*lam^2*v^2 := by positivity\n linarith\n have hAstep : ∀ n : ℕ, A (n+1) ≤ (1-θ)*A n + (η/2)*(d (n+1))^2 := by\n intro n\n have hz2 : z (n+2) = (z (n+1) + (1-θ)*(z (n+1) - z n))\n - η*(lam*((z (n+1) + (1-θ)*(z (n+1) - z n)) - v) + d (n+1)) := by\n have h := hrec (n+1)\n simp only [Nat.add_sub_cancel] at h\n rw [h, hv]; ring\n exact scalar_step2 η θ lam v (z n) (z (n+1)) (z (n+2))\n (z (n+1) + (1-θ)*(z (n+1) - z n)) (d (n+1)) hη hθ0 hθ1 hlamneg hlam2 rfl hz2\n -- max-truncated sequence\n set M : ℕ → ℝ := fun n => max (A n) 0 with hM\n have hM0 : ∀ n, 0 ≤ M n := fun n => le_max_right _ _\n have hAM : ∀ n, A n ≤ M n := fun n => le_max_left _ _\n have hMstep : ∀ n, M (n+1) ≤ (1-θ)*M n + (η/2)*(d (n+1))^2 := by\n intro n\n apply max_le\n · have h1 := hAstep n\n have h2 : (1-θ)*A n ≤ (1-θ)*M n :=\n mul_le_mul_of_nonneg_left (hAM n) (by linarith)\n linarith\n · have h1 : 0 ≤ (1-θ)*M n := mul_nonneg (by linarith) (hM0 n)\n have h2 : (0:ℝ) ≤ (η/2)*(d (n+1))^2 := by positivity\n linarith\n have hP : ∀ n : ℕ, θ * (∑ k ∈ Finset.range n, A k) + M n\n ≤ ∑ k ∈ Finset.range (n+1), (η/2)*(d k)^2 := by\n intro n\n induction n with\n | zero =>\n simp only [Finset.range_zero, Finset.sum_empty, mul_zero, zero_add,\n Finset.sum_range_one]\n have : M 0 = 0 := by\n simp only [hM]\n exact max_eq_right hA0\n rw [this, hd0]\n norm_num\n | succ m ih =>\n rw [Finset.sum_range_succ (n := m+1)]\n rw [Finset.sum_range_succ (f := A) (n := m)]\n have h1 := hMstep m\n have h2 : θ * (∑ k ∈ Finset.range m, A k) + θ * A m + M (m+1)\n ≤ θ * (∑ k ∈ Finset.range m, A k) + θ * A m + (1-θ)*M m + (η/2)*(d (m+1))^2 := by\n linarith\n have h3 : θ * A m ≤ θ * M m := mul_le_mul_of_nonneg_left (hAM m) (le_of_lt hθ0)\n have : θ * (∑ k ∈ Finset.range m, A k) + θ * A m + (1-θ)*M m\n ≤ θ * (∑ k ∈ Finset.range m, A k) + M m := by linarith\n have hmul : θ * (∑ k ∈ Finset.range m, A k + A m)\n = θ * (∑ k ∈ Finset.range m, A k) + θ * A m := by ring\n rw [hmul]\n linarith\n have hAsum : θ * (∑ k ∈ Finset.range K, A k) ≤ ∑ k ∈ Finset.range K, (η/2)*(d k)^2 := by\n rcases Nat.eq_zero_or_pos K with rfl | hK\n · simp\n · obtain ⟨m, rfl⟩ : ∃ m, K = m + 1 := ⟨K - 1, by omega⟩\n have h := hP m\n rw [Finset.sum_range_succ (f := A) (n := m)]\n have h3 : θ * A m ≤ θ * M m := mul_le_mul_of_nonneg_left (hAM m) (le_of_lt hθ0)\n have h4 : θ * M m ≤ M m := by nlinarith [hM0 m]\n have hmul : θ * (∑ k ∈ Finset.range m, A k + A m)\n = θ * (∑ k ∈ Finset.range m, A k) + θ * A m := by ring\n rw [hmul]\n linarith\n -- telescoping identity\n have hGdiff : ∀ k : ℕ, γ * z (k+1) + (lam/2)*(z (k+1))^2 - (γ * z k + (lam/2)*(z k)^2)\n = (lam/2)*(z (k+1) - z k)^2 + A k := by\n intro k\n simp only [hA]\n rw [hv]; ring\n have hsumG : γ * z K + (lam/2)*(z K)^2\n = ∑ k ∈ Finset.range K, ((lam/2)*(z (k+1) - z k)^2 + A k) := by\n have h1 : ∑ k ∈ Finset.range K, ((lam/2)*(z (k+1) - z k)^2 + A k)\n = ∑ k ∈ Finset.range K,\n ((fun j => γ * z j + (lam/2)*(z j)^2) (k+1) - (fun j => γ * z j + (lam/2)*(z j)^2) k) := by\n refine Finset.sum_congr rfl (fun k _ => ?_)\n rw [← hGdiff k]\n rw [h1, Finset.sum_range_sub (fun j => γ * z j + (lam/2)*(z j)^2)]\n simp [hz0]\n rw [hsumG, Finset.sum_add_distrib, ← Finset.mul_sum]\n -- bound the quadratic part\n have hSnn : (0:ℝ) ≤ ∑ k ∈ Finset.range K, (z (k+1) - z k)^2 :=\n Finset.sum_nonneg (fun i _ => sq_nonneg _)\n have hDnn : (0:ℝ) ≤ ∑ k ∈ Finset.range K, (d k)^2 :=\n Finset.sum_nonneg (fun i _ => sq_nonneg _)\n have hq : lam/2 ≤ -(3*θ/(8*η)) := by\n have h1 : lam ≤ -(θ/η) := le_of_lt hcase\n have h2 : 3*θ/(8*η) = 3*(θ/η)/8 := by field_simp\n have h3 : (0:ℝ) < θ/η := by positivity\n rw [h2]; linarith\n have hb1 : (lam/2) * (∑ k ∈ Finset.range K, (z (k+1) - z k)^2)\n ≤ -(3*θ/(8*η)) * (∑ k ∈ Finset.range K, (z (k+1) - z k)^2) :=\n mul_le_mul_of_nonneg_right hq hSnn\n have hb2 : ∑ k ∈ Finset.range K, A k ≤ (2*η/θ) * (∑ k ∈ Finset.range K, (d k)^2) := by\n have h1 : ∑ k ∈ Finset.range K, (η/2)*(d k)^2 = (η/2) * (∑ k ∈ Finset.range K, (d k)^2) := by\n rw [Finset.mul_sum]\n rw [h1] at hAsum\n have key : θ * ((2*η/θ) * (∑ k ∈ Finset.range K, (d k)^2))\n = 2*η*(∑ k ∈ Finset.range K, (d k)^2) := by\n field_simp\n have h2 : (η/2)*(∑ k ∈ Finset.range K, (d k)^2)\n ≤ 2*η*(∑ k ∈ Finset.range K, (d k)^2) := by nlinarith [hDnn, hη]\n have h3 : θ * (∑ k ∈ Finset.range K, A k)\n ≤ θ * ((2*η/θ) * (∑ k ∈ Finset.range K, (d k)^2)) := by\n rw [key]; linarith\n exact le_of_mul_le_mul_left h3 hθ0\n linarith\n\nset_option maxHeartbeats 1000000 in\nprivate theorem third_taylor\n {f : E → ℝ} {f' : E → E} {Hf : E → (E →L[ℝ] E)} {ρ : ℝ}\n (hf' : ∀ z, HasGradientAt f (f' z) z)\n (hf'' : ∀ z, HasFDerivAt f' (Hf z) z)\n (hHLip : ∀ u v : E, ‖Hf u - Hf v‖ ≤ ρ * ‖u - v‖)\n (a b : E) :\n |f b - f a - (inner ℝ (f' a) (b - a) : ℝ) - (1/2) * (inner ℝ ((Hf a) (b-a)) (b-a) : ℝ)|\n ≤ ρ/6 * ‖b - a‖ ^ 3 := by\n set v : E := b - a with hv\n set F : ℝ → ℝ := fun t => f (a + t • v) - f a - t * (inner ℝ (f' a) v : ℝ)\n - (t^2/2) * (inner ℝ ((Hf a) v) v : ℝ) with hFdef\n have hc : ∀ t : ℝ, HasDerivAt (fun s : ℝ => a + s • v) v t := by\n intro t\n simpa using ((hasDerivAt_id t).smul_const v).const_add a\n have hFd : ∀ t : ℝ, HasDerivAt F\n ((inner ℝ (f' (a + t • v)) v : ℝ) - (inner ℝ (f' a) v : ℝ)\n - t * (inner ℝ ((Hf a) v) v : ℝ)) t := by\n intro t\n have h1 : HasDerivAt (fun s : ℝ => f (a + s • v)) (inner ℝ (f' (a + t • v)) v : ℝ) t := by\n simpa using ((hf' (a + t • v)).hasFDerivAt).comp_hasDerivAt t (hc t)\n have h2 : HasDerivAt (fun s : ℝ => s * (inner ℝ (f' a) v : ℝ)) (inner ℝ (f' a) v : ℝ) t := by\n simpa using (hasDerivAt_id t).mul_const (inner ℝ (f' a) v : ℝ)\n have h3 : HasDerivAt (fun s : ℝ => (s^2/2) * (inner ℝ ((Hf a) v) v : ℝ))\n (t * (inner ℝ ((Hf a) v) v : ℝ)) t := by\n have hp : HasDerivAt (fun s : ℝ => s ^ 2 / 2) t t := by\n simpa using ((hasDerivAt_pow 2 t).div_const 2)\n simpa using hp.mul_const (inner ℝ ((Hf a) v) v : ℝ)\n exact ((h1.sub_const (f a)).sub h2).sub h3\n set Bd : ℝ → ℝ := fun t => ρ/6 * t ^ 3 * ‖v‖ ^ 3 with hBdef\n have hB : ∀ t : ℝ, HasDerivAt Bd (ρ/2 * t ^ 2 * ‖v‖ ^ 3) t := by\n intro t\n have h3 : HasDerivAt (fun s : ℝ => s ^ 3) (3 * t^2) t := by\n simpa using (hasDerivAt_pow 3 t)\n have := ((h3.const_mul (ρ/6)).mul_const (‖v‖ ^ 3))\n convert this using 1\n ring\n have key : ∀ t ∈ Set.Icc (0:ℝ) 1, ‖F t‖ ≤ Bd t := by\n apply image_norm_le_of_norm_deriv_right_le_deriv_boundary\n (f' := fun t => (inner ℝ (f' (a + t • v)) v : ℝ) - (inner ℝ (f' a) v : ℝ)\n - t * (inner ℝ ((Hf a) v) v : ℝ))\n · exact fun t _ => (hFd t).continuousAt.continuousWithinAt\n · exact fun t _ => (hFd t).hasDerivWithinAt\n · simp [hFdef, hBdef]\n · exact hB\n · intro t ht\n have hsm : (Hf a) (t • v) = t • ((Hf a) v) := by rw [ContinuousLinearMap.map_smul]\n have hgt := grad_taylor hf'' hHLip a (a + t • v)\n have hred : a + t • v - a = t • v := by abel\n rw [hred] at hgt\n have h1 : (inner ℝ (f' (a + t • v)) v : ℝ) - (inner ℝ (f' a) v : ℝ)\n - t * (inner ℝ ((Hf a) v) v : ℝ)\n = (inner ℝ (f' (a + t • v) - f' a - (Hf a) (t • v)) v : ℝ) := by\n rw [inner_sub_left, inner_sub_left, hsm, real_inner_smul_left]\n rw [h1]\n have h2 : |(inner ℝ (f' (a + t • v) - f' a - (Hf a) (t • v)) v : ℝ)|\n ≤ ‖f' (a + t • v) - f' a - (Hf a) (t • v)‖ * ‖v‖ := abs_real_inner_le_norm _ _\n have h3 : ‖t • v‖ = t * ‖v‖ := by\n rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht.1]\n rw [h3] at hgt\n calc ‖(inner ℝ (f' (a + t • v) - f' a - (Hf a) (t • v)) v : ℝ)‖\n ≤ ‖f' (a + t • v) - f' a - (Hf a) (t • v)‖ * ‖v‖ := h2\n _ ≤ (ρ/2 * (t*‖v‖)^2) * ‖v‖ := mul_le_mul_of_nonneg_right hgt (norm_nonneg _)\n _ = ρ/2 * t^2 * ‖v‖^3 := by ring\n have hfin := key 1 (by norm_num)\n simp only [hFdef, hBdef, one_smul, one_mul, one_pow] at hfin\n have hab : a + v = b := by simp [hv]\n rw [hab] at hfin\n simpa using hfin\n\nset_option maxHeartbeats 1000000 in\nprivate theorem lemma11 [FiniteDimensional ℝ E]\n {f : E → ℝ} {f' : E → E} {L ρ : ℝ≥0}\n (hf' : ∀ x, HasGradientAt f (f' x) x) (hLip : LipschitzWith L f')\n (Hf : E → (E →L[ℝ] E)) (hf'' : ∀ x, HasFDerivAt f' (Hf x) x)\n (hHLip : LipschitzWith ρ Hf)\n (η θ B : ℝ) (hη : 0 < η) (hηL : η ≤ 1 / (4 * (L : ℝ)))\n (hL0 : 0 < (L : ℝ)) (hρ0 : 0 < (ρ : ℝ)) (hθ0 : 0 < θ) (hθ1 : θ ≤ 1) (hB : 0 < B)\n (K : ℕ) (hK : 1 ≤ K) (x y : ℕ → E)\n (hy : ∀ k, y k = x k + (1 - θ) • (x k - x (k - 1)))\n (hx : ∀ k, x (k + 1) = y k - η • f' (y k))\n (h8a : B ^ 2 < (K : ℝ) * ∑ t ∈ Finset.range K, ‖x (t + 1) - x t‖ ^ 2)\n (h8b : ∀ k, k < K → (k : ℝ) * ∑ t ∈ Finset.range k, ‖x (t + 1) - x t‖ ^ 2 ≤ B ^ 2)\n (hsmall : ‖f' (y (K - 1))‖ ≤ B / η) :\n f (x K) - f (x 0)\n ≤ -(3*θ*B^2/(8*η*(K:ℝ))) + 8*η*(ρ:ℝ)^2*B^4*(K:ℝ)/θ + (9/2)*(ρ:ℝ)*B^3 := by\n have hKr1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have hKr0 : (0:ℝ) < (K:ℝ) := by linarith\n have hLip' : ∀ u v : E, ‖f' u - f' v‖ ≤ (L:ℝ) * ‖u - v‖ := by\n intro u v; simpa [dist_eq_norm] using hLip.dist_le_mul u v\n have hHLip' : ∀ u v : E, ‖Hf u - Hf v‖ ≤ (ρ:ℝ) * ‖u - v‖ := by\n intro u v; simpa [dist_eq_norm] using hHLip.dist_le_mul u v\n set H : E →L[ℝ] E := Hf (x 0) with hHdef\n have hHnorm : ‖H‖ ≤ (L:ℝ) := (hf'' (x 0)).le_of_lipschitz hLip\n -- iterate bounds\n have hxx0 : ∀ k, k < K → ‖x k - x 0‖ ≤ B := by\n intro k hk\n have hsum : x k - x 0 = ∑ t ∈ Finset.range k, (x (t+1) - x t) :=\n (Finset.sum_range_sub (fun t => x t) k).symm\n have h1 : ‖x k - x 0‖^2 ≤ (k:ℝ) * ∑ t ∈ Finset.range k, ‖x (t+1) - x t‖^2 := by\n rw [hsum]\n simpa using norm_sum_sq_le (Finset.range k) (fun t => x (t+1) - x t)\n have h2 := h8b k hk\n nlinarith [norm_nonneg (x k - x 0), hB.le]\n have hdiff : ∀ k, k < K → ‖x k - x (k-1)‖ ≤ B := by\n intro k hk\n rcases Nat.eq_zero_or_pos k with rfl | hk1\n · simpa using hB.le\n · have hmem : k - 1 ∈ Finset.range k := by simp only [Finset.mem_range]; omega\n have h1 : ‖x k - x (k-1)‖^2 ≤ ∑ t ∈ Finset.range k, ‖x (t+1) - x t‖^2 := by\n have hs := Finset.single_le_sum (f := fun t => ‖x (t+1) - x t‖^2)\n (fun i _ => sq_nonneg _) hmem\n simpa [Nat.sub_add_cancel hk1] using hs\n have h2 := h8b k hk\n have hk1' : (1:ℝ) ≤ (k:ℝ) := by exact_mod_cast hk1\n have hs0 : 0 ≤ ∑ t ∈ Finset.range k, ‖x (t+1) - x t‖^2 :=\n Finset.sum_nonneg (fun i _ => sq_nonneg _)\n nlinarith [norm_nonneg (x k - x (k-1)), hB.le]\n have hy0 : ∀ k, k < K → ‖y k - x 0‖ ≤ 2*B := by\n intro k hk\n have he : y k - x 0 = (x k - x 0) + (1-θ) • (x k - x (k-1)) := by rw [hy k]; abel\n rw [he]\n have ht := norm_add_le (x k - x 0) ((1-θ) • (x k - x (k-1)))\n have h2 : ‖(1-θ) • (x k - x (k-1))‖ = |1-θ| * ‖x k - x (k-1)‖ := by\n rw [norm_smul, Real.norm_eq_abs]\n have h3 : |1-θ| ≤ 1 := by rw [abs_le]; constructor <;> linarith\n have h4 := hxx0 k hk\n have h5 := hdiff k hk\n nlinarith [norm_nonneg (x k - x (k-1))]\n have hxK : ‖x K - x 0‖ ≤ 3*B := by\n have hKe : K - 1 + 1 = K := by omega\n have he : x K - x 0 = (y (K-1) - x 0) - η • f' (y (K-1)) := by\n have := hx (K-1)\n rw [hKe] at this\n rw [this]; abel\n rw [he]\n have h1 := norm_sub_le (y (K-1) - x 0) (η • f' (y (K-1)))\n have h2 : ‖η • f' (y (K-1))‖ = η * ‖f' (y (K-1))‖ := by\n rw [norm_smul, Real.norm_eq_abs, abs_of_pos hη]\n have h3 : η * ‖f' (y (K-1))‖ ≤ B := by\n have := mul_le_mul_of_nonneg_left hsmall hη.le\n rw [mul_div_cancel₀ _ (ne_of_gt hη)] at this\n exact this\n have h4 := hy0 (K-1) (by omega)\n linarith\n -- the deviation\n set δ : ℕ → E := fun k => f' (y k) - f' (x 0) - H (y k - x 0) with hδdef\n have hy00 : y 0 = x 0 := by\n have := hy 0\n simpa using this\n have hδ0 : δ 0 = 0 := by\n simp [hδdef, hy00]\n have hδb : ∀ k, k < K → ‖δ k‖ ≤ 2*(ρ:ℝ)*B^2 := by\n intro k hk\n have h1 : ‖δ k‖ ≤ (ρ:ℝ)/2 * ‖y k - x 0‖^2 := by\n simpa [hδdef, hHdef] using grad_taylor hf'' hHLip' (x 0) (y k)\n have h2 := hy0 k hk\n have h3 : ‖y k - x 0‖^2 ≤ (2*B)^2 := by nlinarith [norm_nonneg (y k - x 0)]\n have h4 := mul_le_mul_of_nonneg_left h3 (by positivity : (0:ℝ) ≤ (ρ:ℝ)/2)\n nlinarith [h1, h4]\n -- Hessian is symmetric\n have hsymH : ∀ u v : E, (inner ℝ (H u) v : ℝ) = inner ℝ (H v) u := by\n intro u v\n set T : E ≃ₗᵢ[ℝ] (StrongDual ℝ E) := InnerProductSpace.toDual ℝ E with hT\n have hfd : ∀ z, HasFDerivAt f (T (f' z)) z := fun z => (hf' z).hasFDerivAt\n have hcomp : HasFDerivAt (fun z => T (f' z))\n ((T.toContinuousLinearEquiv.toContinuousLinearMap).comp (Hf (x 0))) (x 0) :=\n (T.toContinuousLinearEquiv.toContinuousLinearMap.hasFDerivAt).comp (x 0) (hf'' (x 0))\n exact second_derivative_symmetric (f := f) (f' := fun z => T (f' z)) hfd hcomp u v\n set n := Module.finrank ℝ E with hn\n have hS : (H : E →ₗ[ℝ] E).IsSymmetric := by\n intro u v\n show (inner ℝ (H u) v : ℝ) = inner ℝ u (H v)\n rw [hsymH u v, real_inner_comm]\n set bs : OrthonormalBasis (Fin n) ℝ E := hS.eigenvectorBasis (n := n) rfl with hbs\n set lam : Fin n → ℝ := hS.eigenvalues (n := n) rfl with hlam\n have hap : ∀ i, H (bs i) = lam i • bs i := by\n intro i\n have h := hS.apply_eigenvectorBasis (n := n) rfl i\n show H (bs i) = lam i • bs i\n rw [hbs, hlam]; exact h\n have hnormbs : ∀ i, ‖bs i‖ = 1 := fun i => bs.orthonormal.1 i\n have hparse : ∀ u v : E, ∑ i, (inner ℝ (bs i) u : ℝ) * (inner ℝ (bs i) v) = inner ℝ u v := by\n intro u v\n have h := bs.sum_inner_mul_inner u v\n simpa [real_inner_comm] using h\n have hnsq : ∀ u : E, ∑ i, (inner ℝ (bs i) u : ℝ)^2 = ‖u‖^2 := by\n intro u\n have h := hparse u u\n rw [real_inner_self_eq_norm_sq] at h\n rw [← h]\n exact Finset.sum_congr rfl (fun i _ => by ring)\n have hlamL : ∀ i, |lam i| ≤ (L:ℝ) := by\n intro i\n have h1 : ‖H (bs i)‖ ≤ ‖H‖ * ‖bs i‖ := H.le_opNorm _\n have h2 : ‖H (bs i)‖ = |lam i| := by\n rw [hap i, norm_smul, Real.norm_eq_abs, hnormbs i, mul_one]\n rw [h2, hnormbs i, mul_one] at h1\n linarith\n have hinnerH : ∀ (i : Fin n) (u : E),\n (inner ℝ (bs i) (H u) : ℝ) = lam i * (inner ℝ (bs i) u : ℝ) := by\n intro i u\n have h1 : (inner ℝ (bs i) (H u) : ℝ) = inner ℝ (H (bs i)) u := by\n rw [real_inner_comm (H u) (bs i), hsymH u (bs i)]\n rw [h1, hap i, real_inner_smul_left]\n have hLinv : (L:ℝ) ≤ 1/(4*η) := by\n rw [le_div_iff₀ (by positivity)]\n rw [le_div_iff₀ (by positivity)] at hηL\n linarith\n -- per-coordinate descent\n have hper : ∀ i : Fin n,\n (inner ℝ (bs i) (f' (x 0)) : ℝ) * (inner ℝ (bs i) (x K - x 0) : ℝ)\n + (lam i/2) * (inner ℝ (bs i) (x K - x 0) : ℝ)^2\n ≤ -(3*θ/(8*η)) * ∑ k ∈ Finset.range K,\n ((inner ℝ (bs i) (x (k+1) - x 0) : ℝ) - (inner ℝ (bs i) (x k - x 0) : ℝ))^2\n + (2*η/θ) * ∑ k ∈ Finset.range K, ((inner ℝ (bs i) (δ k) : ℝ))^2 := by\n intro i\n refine scalar_descent η θ ((inner ℝ (bs i) (f' (x 0)) : ℝ)) (lam i) hη hθ0 hθ1 ?_ ?_\n (fun k => (inner ℝ (bs i) (x k - x 0) : ℝ)) (fun k => (inner ℝ (bs i) (δ k) : ℝ)) ?_ ?_ ?_ K\n · have h := abs_le.mp (hlamL i)\n linarith [hLinv, h.2]\n · have h := abs_le.mp (hlamL i)\n linarith [hLinv, h.1]\n · simp\n · simp [hδ0]\n · intro k\n have hyv : y k - x 0 = (x k - x 0) + (1-θ) • ((x k - x 0) - (x (k-1) - x 0)) := by\n rw [hy k]; module\n have hw : (inner ℝ (bs i) (x k - x 0) : ℝ)\n + (1-θ)*((inner ℝ (bs i) (x k - x 0) : ℝ) - (inner ℝ (bs i) (x (k-1) - x 0) : ℝ))\n = (inner ℝ (bs i) (y k - x 0) : ℝ) := by\n simp only [hyv, inner_add_right, real_inner_smul_right, inner_sub_right]\n have hfy : f' (y k) = f' (x 0) + H (y k - x 0) + δ k := by\n simp only [hδdef]; abel\n have hxv : x (k+1) - x 0 = (y k - x 0) - η • f' (y k) := by\n rw [hx k]; abel\n show (inner ℝ (bs i) (x (k+1) - x 0) : ℝ) = _\n rw [hw, hxv, inner_sub_right, real_inner_smul_right, hfy, inner_add_right, inner_add_right,\n hinnerH i (y k - x 0)]\n have hsumall := Finset.sum_le_sum (fun (i : Fin n) (_ : i ∈ Finset.univ) => hper i)\n -- evaluate the left sum\n have hL1 : ∑ i : Fin n, ((inner ℝ (bs i) (f' (x 0)) : ℝ) * (inner ℝ (bs i) (x K - x 0) : ℝ)\n + (lam i/2) * (inner ℝ (bs i) (x K - x 0) : ℝ)^2)\n = (inner ℝ (f' (x 0)) (x K - x 0) : ℝ)\n + (1/2) * (inner ℝ (H (x K - x 0)) (x K - x 0) : ℝ) := by\n rw [Finset.sum_add_distrib]\n congr 1\n · exact hparse (f' (x 0)) (x K - x 0)\n · have h1 : ∀ i : Fin n, (lam i/2) * (inner ℝ (bs i) (x K - x 0) : ℝ)^2\n = (1/2) * ((inner ℝ (bs i) (H (x K - x 0)) : ℝ) * (inner ℝ (bs i) (x K - x 0) : ℝ)) := by\n intro i\n rw [hinnerH i (x K - x 0)]; ring\n rw [Finset.sum_congr rfl (fun i (_ : i ∈ Finset.univ) => h1 i), ← Finset.mul_sum,\n hparse (H (x K - x 0)) (x K - x 0)]\n -- evaluate the right sum\n have hR1 : ∑ i : Fin n, (-(3*θ/(8*η)) * ∑ k ∈ Finset.range K,\n ((inner ℝ (bs i) (x (k+1) - x 0) : ℝ) - (inner ℝ (bs i) (x k - x 0) : ℝ))^2\n + (2*η/θ) * ∑ k ∈ Finset.range K, ((inner ℝ (bs i) (δ k) : ℝ))^2)\n = -(3*θ/(8*η)) * (∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2)\n + (2*η/θ) * (∑ k ∈ Finset.range K, ‖δ k‖^2) := by\n rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum]\n congr 1\n · congr 1\n rw [Finset.sum_comm]\n refine Finset.sum_congr rfl (fun k _ => ?_)\n have h2 : ∀ i : Fin n,\n ((inner ℝ (bs i) (x (k+1) - x 0) : ℝ) - (inner ℝ (bs i) (x k - x 0) : ℝ))^2\n = (inner ℝ (bs i) (x (k+1) - x k) : ℝ)^2 := by\n intro i\n rw [← inner_sub_right]\n congr 2\n abel\n rw [Finset.sum_congr rfl (fun i (_ : i ∈ Finset.univ) => h2 i)]\n exact hnsq (x (k+1) - x k)\n · congr 1\n rw [Finset.sum_comm]\n exact Finset.sum_congr rfl (fun k _ => hnsq (δ k))\n rw [hL1, hR1] at hsumall\n -- delta sum bound\n have hδsum : ∑ k ∈ Finset.range K, ‖δ k‖^2 ≤ (K:ℝ) * (2*(ρ:ℝ)*B^2)^2 := by\n have h : ∀ k ∈ Finset.range K, ‖δ k‖^2 ≤ (2*(ρ:ℝ)*B^2)^2 := by\n intro k hk\n simp only [Finset.mem_range] at hk\n have h1 := hδb k hk\n nlinarith [norm_nonneg (δ k), hρ0, hB]\n calc ∑ k ∈ Finset.range K, ‖δ k‖^2 ≤ ∑ k ∈ Finset.range K, (2*(ρ:ℝ)*B^2)^2 :=\n Finset.sum_le_sum h\n _ = (K:ℝ) * (2*(ρ:ℝ)*B^2)^2 := by\n rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul]\n -- third order Taylor\n have htt := third_taylor hf' hf'' hHLip' (x 0) (x K)\n have htt2 : f (x K) - f (x 0) ≤ (inner ℝ (f' (x 0)) (x K - x 0) : ℝ)\n + (1/2)*(inner ℝ (H (x K - x 0)) (x K - x 0) : ℝ) + (ρ:ℝ)/6*‖x K - x 0‖^3 := by\n have h := (abs_le.mp htt).2\n linarith\n have hcube : (ρ:ℝ)/6*‖x K - x 0‖^3 ≤ (9/2)*(ρ:ℝ)*B^3 := by\n have h1 : ‖x K - x 0‖^3 ≤ (3*B)^3 := by\n have h0 : (0:ℝ) ≤ ‖x K - x 0‖ := norm_nonneg _\n have hfac : (0:ℝ) ≤ (3*B)^2 + (3*B)*‖x K - x 0‖ + ‖x K - x 0‖^2 := by positivity\n nlinarith [mul_nonneg (sub_nonneg.mpr hxK) hfac]\n have h2 := mul_le_mul_of_nonneg_left h1 (by positivity : (0:ℝ) ≤ (ρ:ℝ)/6)\n linarith [h2]\n -- final numeric bounds\n have hSpos : B^2/(K:ℝ) < ∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2 := by\n rw [div_lt_iff₀ hKr0]\n nlinarith [h8a]\n have hq1 : -(3*θ/(8*η)) * (∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2)\n ≤ -(3*θ*B^2/(8*η*(K:ℝ))) := by\n have hc : (0:ℝ) < 3*θ/(8*η) := by positivity\n have h1 : (3*θ/(8*η)) * (B^2/(K:ℝ))\n ≤ (3*θ/(8*η)) * (∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2) :=\n mul_le_mul_of_nonneg_left (le_of_lt hSpos) hc.le\n have h2 : (3*θ/(8*η)) * (B^2/(K:ℝ)) = 3*θ*B^2/(8*η*(K:ℝ)) := by\n field_simp\n linarith\n have hq2 : (2*η/θ) * (∑ k ∈ Finset.range K, ‖δ k‖^2) ≤ 8*η*(ρ:ℝ)^2*B^4*(K:ℝ)/θ := by\n have hc : (0:ℝ) < 2*η/θ := by positivity\n have h1 := mul_le_mul_of_nonneg_left hδsum hc.le\n have h2 : (2*η/θ) * ((K:ℝ) * (2*(ρ:ℝ)*B^2)^2) = 8*η*(ρ:ℝ)^2*B^4*(K:ℝ)/θ := by\n field_simp\n ring\n linarith\n linarith [htt2, hcube, hsumall, hq1, hq2]\n\nset_option maxHeartbeats 1000000 in\ntheorem corollary12 [FiniteDimensional ℝ E]\n {f : E → ℝ} {f' : E → E} {L ρ : ℝ≥0}\n (hflb : BddBelow (Set.range f))\n (hf' : ∀ x, HasGradientAt f (f' x) x) (hLip : LipschitzWith L f')\n (Hf : E → (E →L[ℝ] E)) (hf'' : ∀ x, HasFDerivAt f' (Hf x) x)\n (hHLip : LipschitzWith ρ Hf)\n (ε : ℝ) (hε : 0 < ε) (hL0 : 0 < (L : ���)) (hρ0 : 0 < (ρ : ℝ))\n (η θ B : ℝ)\n (hηv : η = 1 / (4 * (L : ℝ)))\n (hBv : B = Real.sqrt (ε / (ρ : ℝ)))\n (hθv : θ = 4 * (ε * (ρ : ℝ) * η ^ 2) ^ ((1 : ℝ) / 4))\n (hθ0 : 0 < θ) (hθ1 : θ ≤ 1)\n (K : ℕ) (hK : 1 ≤ K) (hKv : (K : ℝ) ≤ 1 / θ)\n (x y : ℕ → E)\n (hy : ∀ k, y k = x k + (1 - θ) • (x k - x (k - 1)))\n (hx : ∀ k, x (k + 1) = y k - η • f' (y k))\n (h8a : B ^ 2 < (K : ℝ) * ∑ t ∈ Finset.range K, ‖x (t + 1) - x t‖ ^ 2)\n (h8b : ∀ k, k < K → (k : ℝ) * ∑ t ∈ Finset.range k, ‖x (t + 1) - x t‖ ^ 2 ≤ B ^ 2) :\n f (x K) - f (x 0) ≤ -(7 * ε ^ ((3 : ℝ) / 2)) / (8 * Real.sqrt (ρ : ℝ)) := by\n have hη : 0 < η := by rw [hηv]; positivity\n have hB : 0 < B := by rw [hBv]; exact Real.sqrt_pos.mpr (by positivity)\n have hηL : η ≤ 1 / (4 * (L : ℝ)) := le_of_eq hηv\n have hKr1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have hKr0 : (0:ℝ) < (K:ℝ) := by linarith\n -- basic identities\n have hεργ : (0:ℝ) ≤ ε * (ρ:ℝ) * η^2 := by positivity\n have hq : ((ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/4))^2 = Real.sqrt (ε*(ρ:ℝ)) * η := by\n have h1 : ((ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/4))^(2:ℕ) = (ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/2) := by\n rw [← Real.rpow_natCast ((ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/4)) 2, ← Real.rpow_mul hεργ]\n norm_num\n rw [h1, ← Real.sqrt_eq_rpow, Real.sqrt_mul (by positivity : (0:ℝ) ≤ ε*(ρ:ℝ)),\n Real.sqrt_sq hη.le]\n have hθsq : θ^2 = 16 * (Real.sqrt (ε*(ρ:ℝ)) * η) := by\n rw [hθv, mul_pow, hq]; norm_num\n have hBs : B * Real.sqrt (ε*(ρ:ℝ)) = ε := by\n rw [hBv, ← Real.sqrt_mul (by positivity : (0:ℝ) ≤ ε/(ρ:ℝ))]\n rw [show ε/(ρ:ℝ) * (ε*(ρ:ℝ)) = ε^2 by field_simp]\n exact Real.sqrt_sq hε.le\n have hρB : (ρ:ℝ) * B^2 = ε := by\n rw [hBv, Real.sq_sqrt (by positivity : (0:ℝ) ≤ ε/(ρ:ℝ))]\n field_simp\n -- goal RHS rewrite\n have hεB : (0:ℝ) < ε * B := by positivity\n have hRHS : -(7 * ε ^ ((3 : ℝ) / 2)) / (8 * Real.sqrt (ρ : ℝ)) = -((7/8)*(ε*B)) := by\n have h1 : ε ^ ((3:ℝ)/2) = ε * Real.sqrt ε := by\n rw [Real.sqrt_eq_rpow, show (3:ℝ)/2 = 1 + 1/2 by norm_num, Real.rpow_add hε,\n Real.rpow_one]\n have h2 : B = Real.sqrt ε / Real.sqrt (ρ:ℝ) := by\n rw [hBv, Real.sqrt_div hε.le]\n have h3 : (0:ℝ) < Real.sqrt (ρ:ℝ) := Real.sqrt_pos.mpr hρ0\n rw [h1, h2]\n field_simp\n rw [hRHS]\n -- theta bound\n have hsr : Real.sqrt (ε*(ρ:ℝ)) * η ≤ 1/16 := by\n nlinarith [hθsq, hθ1, hθ0]\n rcases le_or_lt (‖f' (y (K - 1))‖) (B/η) with hcase | hcase\n · -- small gradient case\n have h11 := lemma11 (L := L) (ρ := ρ) hf' hLip Hf hf'' hHLip η θ B hη hηL hL0 hρ0\n hθ0 hθ1 hB K hK x y hy hx h8a h8b hcase\n -- numeric bounds\n have hKθ : θ*(K:ℝ) ≤ 1 := by\n rw [le_div_iff₀ hθ0] at hKv; linarith\n have hb1 : 3*θ*B^2/(8*η*(K:ℝ)) ≥ 3*θ^2*B^2/(8*η) := by\n rw [ge_iff_le, div_le_div_iff₀ (by positivity) (by positivity)]\n have h : 0 ≤ 24*η*θ*B^2*(1 - θ*(K:ℝ)) := by\n apply mul_nonneg _ (by linarith)\n positivity\n nlinarith [h]\n have hb2 : 8*η*(ρ:ℝ)^2*B^4*(K:ℝ)/θ ≤ 8*η*(ρ:ℝ)^2*B^4/θ^2 := by\n rw [div_le_div_iff₀ hθ0 (by positivity)]\n have h : 0 ≤ 8*η*(ρ:ℝ)^2*B^4*θ*(1 - θ*(K:ℝ)) := by\n apply mul_nonneg _ (by linarith)\n positivity\n nlinarith [h]\n have hv1 : 3*θ^2*B^2/(8*η) = 6*(ε*B) := by\n rw [hθsq, div_eq_iff (by positivity : (8:ℝ)*η ≠ 0)]\n linear_combination (48*η*B)*hBs\n have hv2 : 8*η*(ρ:ℝ)^2*B^4/θ^2 = (1/2)*(ε*B) := by\n rw [hθsq, div_eq_iff (by positivity : (16:ℝ) * (Real.sqrt (ε*(ρ:ℝ)) * η) ≠ 0)]\n linear_combination (8*η*((ρ:ℝ)*B^2 + ε))*hρB - (8*η*ε)*hBs\n have hv3 : (9/2)*(ρ:ℝ)*B^3 = (9/2)*(ε*B) := by\n linear_combination ((9:ℝ)/2*B)*hρB\n rw [hv1] at hb1\n rw [hv2] at hb2\n rw [hv3] at h11\n linarith\n · -- large gradient case\n have h8 := lemma8 (L := L) (ρ := ρ) hflb hf' hLip Hf hf'' hHLip η θ B hη hηL hL0 hρ0\n (le_of_lt hθ0) hθ1 hB.le K hK x y hy hx h8a h8b hcase\n have hkey : (7/8)*(ε*B) ≤ B^2/(4*η) := by\n have h1 : ε = B * Real.sqrt (ε*(ρ:ℝ)) := hBs.symm\n rw [le_div_iff₀ (by positivity)]\n rw [h1]\n nlinarith [mul_le_mul_of_nonneg_right hsr (sq_nonneg B), hB]\n linarith\n\nset_option maxHeartbeats 1000000 in\ntheorem lemma13 [FiniteDimensional ℝ E]\n {f : E → ℝ} {f' : E → E} {L ρ : ℝ≥0}\n (hflb : BddBelow (Set.range f))\n (hf' : ∀ x, HasGradientAt f (f' x) x) (hLip : LipschitzWith L f')\n (Hf : E → (E →L[ℝ] E)) (hf'' : ∀ x, HasFDerivAt f' (Hf x) x)\n (hHLip : LipschitzWith ρ Hf)\n (ε : ℝ) (hε : 0 < ε) (hL0 : 0 < (L : ℝ)) (hρ0 : 0 < (ρ : ℝ))\n (η θ B : ℝ)\n (hηv : η = 1 / (4 * (L : ℝ)))\n (hBv : B = Real.sqrt (ε / (ρ : ℝ)))\n (hθv : θ = 4 * (ε * (ρ : ℝ) * η ^ 2) ^ ((1 : ℝ) / 4))\n (hθ0 : 0 < θ) (hθ1 : θ ≤ 1)\n (K : ℕ) (hK : 1 ≤ K) (hKv : (K : ℝ) = 1 / θ)\n (x y : ℕ → E)\n (hy : ∀ k, y k = x k + (1 - θ) • (x k - x (k - 1)))\n (hx : ∀ k, x (k + 1) = y k - η • f' (y k))\n (h10a : ∀ k, k ≤ K → (k : ℝ) * ∑ t ∈ Finset.range k, ‖x (t + 1) - x t‖ ^ 2 ≤ B ^ 2)\n (K₀ : ℕ) (hK₀lo : K / 2 ≤ K₀) (hK₀hi : K₀ < K)\n (hK₀min : ∀ k, K / 2 ≤ k → k < K → ‖x (K₀ + 1) - x K₀‖ ≤ ‖x (k + 1) - x k‖)\n (yhat : E)\n (hyhat : yhat = ((K₀ : ℝ) + 1)⁻¹ • ∑ k ∈ Finset.range (K₀ + 1), y k) :\n ‖f' yhat‖ ≤ 82 * ε := by\n have hη : 0 < η := by rw [hηv]; positivity\n have hB : 0 < B := by rw [hBv]; exact Real.sqrt_pos.mpr (by positivity)\n have hKr1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have hKr0 : (0:ℝ) < (K:ℝ) := by linarith\n -- ‖x k - x 0‖ ≤ B\n have hxx0 : ∀ k, k ≤ K → ‖x k - x 0‖ ≤ B := by\n intro k hk\n have hsum : x k - x 0 = ∑ t ∈ Finset.range k, (x (t+1) - x t) :=\n (Finset.sum_range_sub (fun t => x t) k).symm\n have h1 : ‖x k - x 0‖^2 ≤ (k:ℝ) * ∑ t ∈ Finset.range k, ‖x (t+1) - x t‖^2 := by\n rw [hsum]\n simpa using norm_sum_sq_le (Finset.range k) (fun t => x (t+1) - x t)\n have h2 := h10a k hk\n nlinarith [norm_nonneg (x k - x 0), hB.le]\n -- ‖x k - x (k-1)‖ ≤ B\n have hdiff : ∀ k, k ≤ K → ‖x k - x (k-1)‖ ≤ B := by\n intro k hk\n rcases Nat.eq_zero_or_pos k with rfl | hk1\n · simpa using hB.le\n · have hmem : k - 1 ∈ Finset.range k := by simp only [Finset.mem_range]; omega\n have h1 : ‖x k - x (k-1)‖^2 ≤ ∑ t ∈ Finset.range k, ‖x (t+1) - x t‖^2 := by\n have hs := Finset.single_le_sum (f := fun t => ‖x (t+1) - x t‖^2)\n (fun i _ => sq_nonneg _) hmem\n simpa [Nat.sub_add_cancel hk1] using hs\n have h2 := h10a k hk\n have hk1' : (1:ℝ) ≤ (k:ℝ) := by exact_mod_cast hk1\n have hs0 : 0 ≤ ∑ t ∈ Finset.range k, ‖x (t+1) - x t‖^2 :=\n Finset.sum_nonneg (fun i _ => sq_nonneg _)\n nlinarith [norm_nonneg (x k - x (k-1)), hB.le]\n -- ‖y k - x 0‖ ≤ 2B\n have hy0 : ∀ k, k ≤ K → ‖y k - x 0‖ ≤ 2*B := by\n intro k hk\n have he : y k - x 0 = (x k - x 0) + (1-θ) • (x k - x (k-1)) := by rw [hy k]; abel\n rw [he]\n have ht := norm_add_le (x k - x 0) ((1-θ) • (x k - x (k-1)))\n have h2 : ‖(1-θ) • (x k - x (k-1))‖ = |1-θ| * ‖x k - x (k-1)‖ := by\n rw [norm_smul, Real.norm_eq_abs]\n have h3 : |1-θ| ≤ 1 := by rw [abs_le]; constructor <;> linarith\n have h4 := hxx0 k hk\n have h5 := hdiff k hk\n nlinarith [norm_nonneg (x k - x (k-1))]\n have hcpos : (0:ℝ) < (K₀:ℝ) + 1 := by positivity\n -- ‖yhat - x 0‖ ≤ 2B\n have hyhat0 : ‖yhat - x 0‖ ≤ 2*B := by\n have he : yhat - x 0 = ((K₀:ℝ)+1)⁻¹ • ∑ k ∈ Finset.range (K₀+1), (y k - x 0) := by\n rw [hyhat, Finset.sum_sub_distrib, Finset.sum_const, Finset.card_range, smul_sub,\n ← Nat.cast_smul_eq_nsmul ℝ]\n push_cast\n rw [smul_smul, inv_mul_cancel₀ (ne_of_gt hcpos), one_smul]\n rw [he, norm_smul, Real.norm_eq_abs, abs_of_pos (by positivity : (0:ℝ) < ((K₀:ℝ)+1)⁻¹)]\n have h1 : ‖∑ k ∈ Finset.range (K₀+1), (y k - x 0)‖ ≤ ∑ k ∈ Finset.range (K₀+1), ‖y k - x 0‖ :=\n norm_sum_le _ _\n have h2 : ∑ k ∈ Finset.range (K₀+1), ‖y k - x 0‖ ≤ ∑ k ∈ Finset.range (K₀+1), (2*B) := by\n apply Finset.sum_le_sum\n intro i hi\n simp only [Finset.mem_range] at hi\n exact hy0 i (by omega)\n rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul] at h2\n push_cast at h2\n rw [inv_mul_le_iff₀ hcpos]\n nlinarith [norm_nonneg (∑ k ∈ Finset.range (K₀+1), (y k - x 0))]\n -- minimal step bound\n have hdK0 : ‖x (K₀+1) - x K₀‖ ≤ (71/50) * B / (K:ℝ) := by\n have hcard : (Finset.Ico (K/2) K).card = K - K/2 := Nat.card_Ico _ _\n have hlow : ((K - K/2 : ℕ) : ℝ) * ‖x (K₀+1) - x K₀‖^2\n ≤ ∑ k ∈ Finset.Ico (K/2) K, ‖x (k+1) - x k‖^2 := by\n have h := Finset.card_nsmul_le_sum (Finset.Ico (K/2) K)\n (fun k => ‖x (k+1) - x k‖^2) (‖x (K₀+1) - x K₀‖^2) ?_\n · rw [hcard, nsmul_eq_mul] at h; exact_mod_cast h\n · intro i hi\n simp only [Finset.mem_Ico] at hi\n have hmin := hK₀min i hi.1 hi.2\n nlinarith [norm_nonneg (x (K₀+1) - x K₀), norm_nonneg (x (i+1) - x i)]\n have hsub : ∑ k ∈ Finset.Ico (K/2) K, ‖x (k+1) - x k‖^2\n ≤ ∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2 := by\n apply Finset.sum_le_sum_of_subset_of_nonneg\n · intro i hi\n simp only [Finset.mem_Ico, Finset.mem_range] at *\n omega\n · intro i _ _; positivity\n have htot := h10a K le_rfl\n have hKh : (K:ℝ) ≤ 2 * ((K - K/2 : ℕ) : ℝ) := by\n have hnn : (K:ℕ) ≤ 2 * (K - K/2) := by omega\n exact_mod_cast hnn\n have hdnn : (0:ℝ) ≤ ‖x (K₀+1) - x K₀‖^2 := sq_nonneg _\n have step1 : (K:ℝ) * (((K - K/2 : ℕ) : ℝ) * ‖x (K₀+1) - x K₀‖^2)\n ≤ (K:ℝ) * ∑ k ∈ Finset.range K, ‖x (k+1) - x k‖^2 :=\n mul_le_mul_of_nonneg_left (hlow.trans hsub) hKr0.le\n have step2 : (K:ℝ) * (((K - K/2 : ℕ) : ℝ) * ‖x (K₀+1) - x K₀‖^2) ≤ B^2 :=\n le_trans step1 htot\n have step3 : (0:ℝ) ≤ ((K:ℝ) * ‖x (K₀+1) - x K₀‖^2) * (2 * ((K - K/2 : ℕ) : ℝ) - (K:ℝ)) :=\n mul_nonneg (mul_nonneg hKr0.le hdnn) (by linarith)\n have hsq : ‖x (K₀+1) - x K₀‖^2 * (K:ℝ)^2 ≤ 2 * B^2 := by nlinarith [step2, step3, hdnn]\n rw [le_div_iff₀ hKr0]\n apply le_of_sq_le_sq' (by positivity) (by positivity)\n calc (‖x (K₀+1) - x K₀‖ * (K:ℝ))^2 = ‖x (K₀+1) - x K₀‖^2 * (K:ℝ)^2 := by ring\n _ ≤ 2*B^2 := hsq\n _ ≤ ((71/50)*B)^2 := by\n have hbb : ((71/50 : ℝ)*B)^2 = (5041/2500)*B^2 := by ring\n rw [hbb]\n linarith [sq_nonneg B]\n -- Hessian Lipschitz in plain form\n have hHLip' : ∀ u v : E, ‖Hf u - Hf v‖ ≤ (ρ:ℝ) * ‖u - v‖ := by\n intro u v\n have h := hHLip.dist_le_mul u v\n simpa [dist_eq_norm] using h\n -- the quadratic remainder\n have hδb : ∀ u : E, ‖f' u - f' (x 0) - (Hf (x 0)) (u - x 0)‖ ≤ (ρ:ℝ)/2 * ‖u - x 0‖^2 :=\n fun u => grad_taylor hf'' hHLip' (x 0) u\n have hδ2 : ∀ u : E, ‖u - x 0‖ ≤ 2*B →\n ‖f' u - f' (x 0) - (Hf (x 0)) (u - x 0)‖ ≤ 2*(ρ:ℝ)*B^2 := by\n intro u hu\n have h1 := hδb u\n have h2 : ‖u - x 0‖^2 ≤ (2*B)^2 := by nlinarith [norm_nonneg (u - x 0)]\n nlinarith [hρ0, sq_nonneg (‖u - x 0‖)]\n -- gradient in terms of iterates\n have hf'y : ∀ k, f' (y k) = η⁻¹ • (y k - x (k+1)) := by\n intro k\n rw [hx k]\n have hcc : y k - (y k - η • f' (y k)) = η • f' (y k) := by abel\n rw [hcc, smul_smul, inv_mul_cancel₀ (ne_of_gt hη), one_smul]\n have hAsum : ∑ k ∈ Finset.range (K₀+1), (x k - x (k+1)) = x 0 - x (K₀+1) :=\n Finset.sum_range_sub' (fun k => x k) (K₀+1)\n have hBsum : ∑ k ∈ Finset.range (K₀+1), (x k - x (k-1)) = x K₀ - x 0 := by\n rw [Finset.sum_range_succ']\n simp [Finset.sum_range_sub (fun k => x k) K₀]\n have hsumy : ∑ k ∈ Finset.range (K₀+1), (y k - x (k+1))\n = -((x (K₀+1) - x K₀) + θ • (x K₀ - x 0)) := by\n have hterm : ∀ k, y k - x (k+1) = (x k - x (k+1)) + (1-θ) • (x k - x (k-1)) := by\n intro k; rw [hy k]; abel\n simp only [hterm]\n rw [Finset.sum_add_distrib, ← Finset.smul_sum, hAsum, hBsum]\n module\n have hsumf : ∑ k ∈ Finset.range (K₀+1), f' (y k)\n = η⁻¹ • (-((x (K₀+1) - x K₀) + θ • (x K₀ - x 0))) := by\n simp only [hf'y]\n rw [← Finset.smul_sum, hsumy]\n -- the key decomposition\n have hAH : ∀ u : E, f' u - (f' u - f' (x 0) - (Hf (x 0)) (u - x 0))\n = (f' (x 0) - (Hf (x 0)) (x 0)) + (Hf (x 0)) u := by\n intro u\n simp only [map_sub]\n abel\n have hsum2 : ∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0)))\n = (K₀+1 : ℕ) • (f' (x 0) - (Hf (x 0)) (x 0))\n + (Hf (x 0)) (∑ k ∈ Finset.range (K₀+1), y k) := by\n simp only [hAH]\n rw [Finset.sum_add_distrib, Finset.sum_const, Finset.card_range, ← map_sum]\n have hkey : f' yhat = ((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1), f' (y k))\n - ((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0)))\n + (f' yhat - f' (x 0) - (Hf (x 0)) (yhat - x 0)) := by\n have h1 : ((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0))))\n = (f' (x 0) - (Hf (x 0)) (x 0)) + (Hf (x 0)) yhat := by\n rw [hsum2, smul_add, ← Nat.cast_smul_eq_nsmul ℝ, smul_smul]\n push_cast\n rw [inv_mul_cancel₀ (ne_of_gt hcpos), one_smul, ← ContinuousLinearMap.map_smul, ← hyhat]\n rw [Finset.sum_sub_distrib, smul_sub] at h1\n rw [h1]\n simp only [map_sub]\n abel\n -- norm estimate\n have hnormA : ‖∑ k ∈ Finset.range (K₀+1), f' (y k)‖\n ≤ η⁻¹ * (‖x (K₀+1) - x K₀‖ + θ * ‖x K₀ - x 0‖) := by\n rw [hsumf, norm_smul, Real.norm_eq_abs, abs_of_pos (by positivity : (0:ℝ) < η⁻¹), norm_neg]\n have h1 := norm_add_le (x (K₀+1) - x K₀) (θ • (x K₀ - x 0))\n have h2 : ‖θ • (x K₀ - x 0)‖ = θ * ‖x K₀ - x 0‖ := by\n rw [norm_smul, Real.norm_eq_abs, abs_of_pos hθ0]\n have h3 : (0:ℝ) < η⁻¹ := by positivity\n nlinarith [h1, h2, h3]\n have hnormD : ‖∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0))‖ ≤ ((K₀:ℝ)+1) * (2*(ρ:ℝ)*B^2) := by\n have h1 := norm_sum_le (Finset.range (K₀+1))\n (fun k => f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0))\n have h2 : ∑ k ∈ Finset.range (K₀+1), ‖f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0)‖\n ≤ ∑ k ∈ Finset.range (K₀+1), (2*(ρ:ℝ)*B^2) := by\n apply Finset.sum_le_sum\n intro i hi\n simp only [Finset.mem_range] at hi\n exact hδ2 (y i) (hy0 i (by omega))\n rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul] at h2\n push_cast at h2\n linarith\n have hnormY : ‖f' yhat - f' (x 0) - (Hf (x 0)) (yhat - x 0)‖ ≤ 2*(ρ:ℝ)*B^2 :=\n hδ2 yhat hyhat0\n have hcinv : (0:ℝ) < ((K₀:ℝ)+1)⁻¹ := by positivity\n have hmain : ‖f' yhat‖ ≤ ((K₀:ℝ)+1)⁻¹ * (η⁻¹ * (‖x (K₀+1) - x K₀‖ + θ * ‖x K₀ - x 0‖))\n + 4*(ρ:ℝ)*B^2 := by\n have hstep : ‖f' yhat‖ ≤ ‖((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1), f' (y k))‖\n + ‖((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0)))‖\n + ‖f' yhat - f' (x 0) - (Hf (x 0)) (yhat - x 0)‖ := by\n calc ‖f' yhat‖ = ‖(((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1), f' (y k))\n - ((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0))))\n + (f' yhat - f' (x 0) - (Hf (x 0)) (yhat - x 0))‖ := by rw [← hkey]\n _ ≤ ‖((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1), f' (y k))\n - ((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0)))‖\n + ‖f' yhat - f' (x 0) - (Hf (x 0)) (yhat - x 0)‖ := norm_add_le _ _\n _ ≤ _ := by\n have := norm_sub_le (((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1), f' (y k)))\n (((K₀:ℝ)+1)⁻¹ • (∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0))))\n linarith\n rw [norm_smul, norm_smul, Real.norm_eq_abs, abs_of_pos hcinv] at hstep\n have e1 : ((K₀:ℝ)+1)⁻¹ * ‖∑ k ∈ Finset.range (K₀+1), f' (y k)‖\n ≤ ((K₀:ℝ)+1)⁻¹ * (η⁻¹ * (‖x (K₀+1) - x K₀‖ + θ * ‖x K₀ - x 0‖)) :=\n mul_le_mul_of_nonneg_left hnormA hcinv.le\n have e2 : ((K₀:ℝ)+1)⁻¹ * ‖∑ k ∈ Finset.range (K₀+1),\n (f' (y k) - f' (x 0) - (Hf (x 0)) (y k - x 0))‖ ≤ 2*(ρ:ℝ)*B^2 := by\n have := mul_le_mul_of_nonneg_left hnormD hcinv.le\n rw [← mul_assoc, inv_mul_cancel₀ (ne_of_gt hcpos), one_mul] at this\n exact this\n linarith\n -- numeric facts\n have hεργ : (0:ℝ) ≤ ε * (ρ:ℝ) * η^2 := by positivity\n have hq : ((ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/4))^2 = Real.sqrt (ε*(ρ:ℝ)) * η := by\n have h1 : ((ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/4))^(2:ℕ) = (ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/2) := by\n rw [← Real.rpow_natCast ((ε * (ρ:ℝ) * η^2) ^ ((1:ℝ)/4)) 2, ← Real.rpow_mul hεργ]\n norm_num\n rw [h1, ← Real.sqrt_eq_rpow, Real.sqrt_mul (by positivity : (0:ℝ) ≤ ε*(ρ:ℝ)),\n Real.sqrt_sq hη.le]\n have hθsq : θ^2 = 16 * (Real.sqrt (ε*(ρ:ℝ)) * η) := by\n rw [hθv, mul_pow, hq]; norm_num\n have hBs : B * Real.sqrt (ε*(ρ:ℝ)) = ε := by\n rw [hBv, ← Real.sqrt_mul (by positivity : (0:ℝ) ≤ ε/(ρ:ℝ))]\n rw [show ε/(ρ:ℝ) * (ε*(ρ:ℝ)) = ε^2 by field_simp]\n exact Real.sqrt_sq hε.le\n have hρB : (ρ:ℝ) * B^2 = ε := by\n rw [hBv, Real.sq_sqrt (by positivity : (0:ℝ) ≤ ε/(ρ:ℝ))]\n field_simp\n have hKK0 : (K:ℝ) ≤ 2 * ((K₀:ℝ)+1) := by\n have hnn : K ≤ 2*K₀ + 2 := by omega\n have hcast : ((K:ℕ):ℝ) ≤ ((2*K₀+2 : ℕ):ℝ) := by exact_mod_cast hnn\n push_cast at hcast\n linarith\n have hc_le : ((K₀:ℝ)+1)⁻¹ ≤ 2/(K:ℝ) := by\n rw [inv_eq_one_div, div_le_div_iff₀ hcpos hKr0]\n linarith\n have hKinv : ((K:ℝ))⁻¹ = θ := by rw [hKv]; field_simp\n -- combine\n have hA' : η⁻¹ * (‖x (K₀+1) - x K₀‖ + θ * ‖x K₀ - x 0‖)\n ≤ η⁻¹ * ((71/50)*B/(K:ℝ) + θ*B) := by\n apply mul_le_mul_of_nonneg_left _ (by positivity)\n have hw := hxx0 K₀ (le_of_lt hK₀hi)\n nlinarith [hdK0, hθ0]\n have hA'nn : (0:ℝ) ≤ η⁻¹ * ((71/50)*B/(K:ℝ) + θ*B) := by positivity\n have hstep4 : ((K₀:ℝ)+1)⁻¹ * (η⁻¹ * (‖x (K₀+1) - x K₀‖ + θ * ‖x K₀ - x 0‖))\n ≤ (2/(K:ℝ)) * (η⁻¹ * ((71/50)*B/(K:ℝ) + θ*B)) := by\n calc ((K₀:ℝ)+1)⁻¹ * (η⁻¹ * (‖x (K₀+1) - x K₀‖ + θ * ‖x K₀ - x 0‖))\n ≤ ((K₀:ℝ)+1)⁻¹ * (η⁻¹ * ((71/50)*B/(K:ℝ) + θ*B)) :=\n mul_le_mul_of_nonneg_left hA' hcinv.le\n _ ≤ (2/(K:ℝ)) * (η⁻¹ * ((71/50)*B/(K:ℝ) + θ*B)) :=\n mul_le_mul_of_nonneg_right hc_le hA'nn\n have hexpr : (2/(K:ℝ)) * (η⁻¹ * ((71/50)*B/(K:ℝ) + θ*B)) = (121/25) * (θ^2 * B / η) := by\n rw [div_eq_mul_inv 2 (K:ℝ), div_eq_mul_inv ((71/50)*B) (K:ℝ), hKinv]\n field_simp\n norm_num\n have hθBn : θ^2 * B = 16 * ε * η := by\n rw [hθsq]; linear_combination (16*η) * hBs\n have hθB : θ^2 * B / η = 16 * ε := by\n rw [hθBn, mul_div_assoc, div_self (ne_of_gt hη), mul_one]\n linarith [hmain, hstep4, hexpr, hθB, hρB, hε]\n\ntheorem theorem1_complexity\n (ε ρ L Δ : ℝ) (hε : 0 < ε) (hρ : 0 < ρ) (hL : 0 < L) (hΔ : 0 ≤ Δ)\n (hK1 : (1 : ℝ) ≤ (1 : ℝ) / 2 * (L ^ 2 / (ε * ρ)) ^ ((1 : ℝ) / 4))\n (N : ℕ) (F : ℕ → ℝ) (Fmin : ℝ)\n (hdec : ∀ i, i < N →\n F (i + 1) ≤ F i - 7 * ε ^ ((3 : ℝ) / 2) / (8 * Real.sqrt ρ))\n (hlb : Fmin ≤ F N)\n (hΔf : F 0 - Fmin ≤ Δ) :\n (N : ℝ) * ((1 : ℝ) / 2 * (L ^ 2 / (ε * ρ)) ^ ((1 : ℝ) / 4))\n ≤ Δ * Real.sqrt L * ρ ^ ((1 : ℝ) / 4) / ε ^ ((7 : ℝ) / 4) := by\n set u : ℝ := ε ^ ((1:ℝ)/4) with hu\n set v : ℝ := ρ ^ ((1:ℝ)/4) with hv\n have hu0 : 0 < u := Real.rpow_pos_of_pos hε _\n have hv0 : 0 < v := Real.rpow_pos_of_pos hρ _\n have hsL0 : 0 < Real.sqrt L := Real.sqrt_pos.mpr hL\n have hε32 : ε ^ ((3:ℝ)/2) = u^6 := by\n rw [hu, ← Real.rpow_natCast (ε ^ ((1:ℝ)/4)) 6, ← Real.rpow_mul hε.le]\n norm_num\n have hε74 : ε ^ ((7:ℝ)/4) = u^7 := by\n rw [hu, ← Real.rpow_natCast (ε ^ ((1:ℝ)/4)) 7, ← Real.rpow_mul hε.le]\n norm_num\n have hρs : Real.sqrt ρ = v^2 := by\n rw [hv, ← Real.rpow_natCast (ρ ^ ((1:ℝ)/4)) 2, ← Real.rpow_mul hρ.le, Real.sqrt_eq_rpow]\n norm_num\n have hLrp : (L ^ 2 / (ε * ρ)) ^ ((1:ℝ)/4) = Real.sqrt L / (u * v) := by\n rw [Real.div_rpow (by positivity) (by positivity), Real.mul_rpow hε.le hρ.le]\n congr 1\n rw [← Real.rpow_natCast L 2, ← Real.rpow_mul hL.le, Real.sqrt_eq_rpow]\n norm_num\n -- descent chain\n set c : ℝ := 7 * ε ^ ((3:ℝ)/2) / (8 * Real.sqrt ρ) with hc\n have hc0 : 0 < c := by\n rw [hc]; positivity\n have hstep : ∀ m, m ≤ N → F m ≤ F 0 - (m:ℝ) * c := by\n intro m\n induction m with\n | zero => intro _; simp\n | succ k ih =>\n intro hk\n have h1 := ih (by omega)\n have h2 := hdec k (by omega)\n push_cast\n linarith\n have hNc : (N:ℝ) * c ≤ Δ := by\n have h := hstep N le_rfl\n linarith\n set R : ℝ := Real.sqrt L * v / u^7 with hR\n have hR0 : 0 ≤ R := by rw [hR]; positivity\n have hAeq : (1:ℝ)/2 * (L ^ 2 / (ε * ρ)) ^ ((1:ℝ)/4) = (4/7) * R * c := by\n rw [hLrp, hR, hc, hε32, hρs]\n field_simp\n ring\n have hgoal : Δ * Real.sqrt L * ρ ^ ((1:ℝ)/4) / ε ^ ((7:ℝ)/4) = Δ * R := by\n rw [hR, ← hv, hε74]\n ring\n rw [hAeq, hgoal]\n have : (N:ℝ) * ((4/7) * R * c) = (4/7) * R * ((N:ℝ) * c) := by ring\n rw [this]\n nlinarith [hR0, hNc, hΔ]\n\nend ResearchLevel\n"} +{"id": "v3-brafman02a", "source": "Research-level", "targets": [{"label": "Lemma 4 (Simulation Lemma)", "decls": ["simulation_lemma"], "statement": "Lemma 4 Suppose $M$ and $\\bar{M}$ are SGs on $N$ states and that $\\bar{M}$ is an $\\frac{\\epsilon}{N T R_{m a x}}$ -approximation of $M$. Then, for any state $s$, any policy $\\pi$ of the agent and any policy $\\rho$ of the adversary,\n\n$$\n|U_{\\bar{M}}(s,\\pi,\\rho,T)-U_{M}(s,\\pi,\\rho,T)|\\le\\epsilon .\n$$", "context_ids": ["v3-brafman02a:ctx1", "v3-brafman02a:ctx2", "v3-brafman02a:ctx3", "v3-brafman02a:ctx4", "v3-brafman02a:ctx6", "v3-brafman02a:ctx8"], "sibling_refs": [], "topic_domain": "Online Learning & RL", "topic_subtopic": "Reinforcement Learning"}, {"label": "Lemma 4 engine (path-distribution total-variation bound)", "decls": ["path_dist_l1_bound"], "statement": "**Lemma 4, engine (path-distribution total-variation bound).**\n\nSame setting as Lemma 4: a two-player stochastic game on $N$ states, $k$ actions and horizon $T$, and $\\bar{M}$ approximating $M$ to within $\\alpha \\ge 0$ in the sense that rewards agree and $|\\bar{P}(s,a,a',t) - P(s,a,a',t)| \\le \\alpha$ for all $s, a, a', t$.\n\nClaim: the two induced distributions over length-$T$ trajectories (each trajectory being a sequence of $T+1$ states together with both players' $T$ actions) are close in total variation —\n\n$$\n\\sum_w |\\Pr_{\\bar{M}}(w) - \\Pr_M(w)| \\le N \\cdot T \\cdot \\alpha,\n$$\n\nthe sum being over all trajectories $w$ from $s_0$. This is the step that carries Lemma 4: a per-transition error of $\\alpha$ accumulates to at most $N \\cdot T \\cdot \\alpha$ over the whole path distribution, and bounded rewards then turn that into the value bound.", "context_ids": ["v3-brafman02a:ctx1", "v3-brafman02a:ctx2", "v3-brafman02a:ctx3", "v3-brafman02a:ctx4", "v3-brafman02a:ctx6", "v3-brafman02a:ctx8"], "sibling_refs": ["Lemma 4 (Simulation Lemma)"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Reinforcement Learning"}, {"label": "Lemma 6 core (implicit explore-or-exploit value bound)", "decls": ["value_diff_escape_bound"], "statement": "**Lemma 6, core (implicit explore-or-exploit value bound).**\n\nSetting: a stochastic game $M$ on $N$ states as in Lemma 4, together with a set $L$ of (state, action, action) triples designated UNKNOWN. Build an auxiliary game on $N+1$ states by adding one absorbing state: from any triple in $L$ the auxiliary game moves to the new state with probability 1 and pays $R_{\\max}$; the new state is absorbing and also pays $R_{\\max}$; off $L$ the auxiliary game agrees with $M$ in both transitions and rewards. Lift a pair of policies for $M$ to the auxiliary game so that they behave identically on histories that never leave the original $N$ states.\n\nLet the escape probability be the probability, under $M$ and the original policies from $s_0$, that the trajectory uses at least one triple in $L$.\n\nClaim: the values of the two games differ by at most $R_{\\max}$ times that probability —\n\n$$\n|U_{\\mathrm{aux}}(\\pi_a', \\pi_d', s_0) - U_M(\\pi_a, \\pi_d, s_0)| \\le R_{\\max} \\cdot \\Pr[\\text{escape}].\n$$\n\nThis is the explore-or-exploit dichotomy in quantitative form: optimism about the unknown triples costs nothing unless they are actually reached, so either the auxiliary game's value is nearly the true value, or the unknown set gets visited with substantial probability.", "context_ids": ["v3-brafman02a:ctx1", "v3-brafman02a:ctx2", "v3-brafman02a:ctx3", "v3-brafman02a:ctx4", "v3-brafman02a:ctx6", "v3-brafman02a:ctx7", "v3-brafman02a:ctx9", "v3-brafman02a:ctx10"], "sibling_refs": ["Lemma 4 (Simulation Lemma)"], "topic_domain": "Online Learning & RL", "topic_subtopic": "Reinforcement Learning"}], "nl_proof": "### Proof of Lemma 4 (Simulation Lemma)\n\nProof Once the policies of both players are fixed, an MDP and a general SG alike give rise to a probability distribution over the T-step paths through the state space. Since the players' policies may be non-stationary, the resulting process need not be Markov. Still, at every point the transition probabilities are determined by the current state together with the actions chosen, and the probability of a path equals the product of the probabilities of the transitions along it. This holds regardless of whether the policies are pure or mixed.\n\nOur goal is to show\n\n$$\n\\sum_{p}|\\operatorname*{Pr}_{M}(p)U_{M}(p)-\\operatorname*{Pr}_{\\bar{M}}(p)U_{\\bar{M}}(p)|\\leq\\epsilon\n$$\n\nin which $p$ ranges over T-step paths that start at $s$ , $\\operatorname*{Pr}_{M}(p)$ (and, correspondingly, $\\mathrm{Pr}_{\\bar{M}}(p)$ ) denotes the probability of $p$ under the random process generated by M (respectively by $\\bar{M}$ ), π, and $\\rho,$ and $U_{M}(p)$ (respectively $U_{\\bar{M}}(p)$ ) denotes the average payoff collected along $p$. As the average payoff never exceeds $R_{m a x}$ , it follows that\n\n$$\n\\sum_{p}|\\operatorname*{Pr}_{M}(p)U_{M}(p)-\\operatorname*{Pr}_{\\bar{M}}(p)U_{\\bar{M}}(p)|\\leq\\sum_{p}|\\operatorname*{Pr}_{M}(p)-\\operatorname*{Pr}_{\\bar{M}}(p)|R_{max}.\n$$\n\nSo the proof will be finished once we verify that\n\n$$\n\\sum_{p}|\\operatorname*{Pr}_{M}(p)-\\operatorname*{Pr}_{\\bar{M}}(p)|\\leq\\epsilon/R_{max}\n$$\n\nDefine the random process $h_{i}$ as follows: begin in state s and play according to $\\rho$ and $\\pi ;$ during the first i steps, use transition probabilities equal to those of the process just described on $\\bar{M}$ , and during the remaining steps use transition probabilities equal to those of $M .$ For the purpose of evaluating probabilities of T-step paths, $h_{0}$ then coincides with the original process on M, and $h_{T}$ coincides with the original process on $\\bar{M}$. By the triangle inequality,\n\n$$\n\\sum_{p}|\\operatorname*{Pr}_{M}(p)-\\operatorname*{Pr}_{\\bar{M}}(p)| =\\sum_{p}|\\operatorname*{Pr}_{h_{0}}(p)-\\operatorname*{Pr}_{h_{T}}(p)|\\leq\\sum_{i=0}^{T-1}\\sum_{p}|\\operatorname*{Pr}_{h_{i}}(p)-\\operatorname*{Pr}_{h_{i+1}}(p)|\n$$\n\nHence, once we establish $\\begin{array}{r}{\\sum_{p}|\\operatorname*{Pr}_{h_{i}}(p)-\\operatorname*{Pr}_{h_{i+1}}(p)|\\leq\\epsilon/TR_{max}}\\end{array}$ for every $0 \\leq i < T$ , we obtain $\\begin{array}{r}{\\sum_{p}|\\operatorname*{Pr}_{M}(p)-\\operatorname*{Pr}_{\\bar{M}}(p)|\\leq\\epsilon/R_{max}}\\end{array}$ , which is exactly the required bound.\n\nIt therefore remains to show $\\begin{array}{r}{\\sum_{p}|\\operatorname*{Pr}_{h_{i}}(p)-\\operatorname*{Pr}_{h_{i+1}}(p)|\\leq\\epsilon/TR_{max}}\\end{array}$ . We organise the sum over paths $p$ in four layers: the outermost runs over the N states that may be occupied after i steps; next, for each such state, over the path prefixes leading to it; then over the states that may be occupied after step $i + 1$ ; and innermost, for each of those, over the suffixes beginning there. Each path $p$ then has probability equal to the probability of its prefix, times the probability of the transition from $x_{i}$ to $x_{i + 1}$ , times the probability of its suffix. Here $x_{i}$ stands for the state occupied after i steps, $x_{i + 1}$ for the state occupied after $i + 1$ steps, $pre(x_{i})$ for the i-step prefixes ending at $x_{i}$ , and $suf(x_{j})$ for the suffixes beginning at $x_{j}$ . Accordingly,\n\n$$\n\\begin{array}{r l}{\\underset{p}{\\mathop{\\sum}}|\\operatorname*{Pr}_{h_{i}}(p)-\\operatorname*{Pr}_{h_{i+1}}(p)| =\\underset{x_{i}}{\\mathop{\\sum}}}&{\\underset{pre(x_{i})}{\\mathop{\\sum}}\\underset{x_{i+1}}{\\mathop{\\sum}}\\underset{suf(x_{i+1})}{\\mathop{\\sum}}|(\\operatorname*{Pr}_{h_{i}}(pre(x_{i}))\\operatorname*{Pr}_{h_{i}}(x_{i}\\to x_{i+1})\\operatorname*{Pr}_{h_{i}}(suf(x_{i+1})))-}\\\\ {\\quad}&{(\\operatorname*{Pr}_{h_{i+1}}(pre(x_{i}))\\operatorname*{Pr}_{h_{i+1}}(x_{i}\\to x_{i+1})\\operatorname*{Pr}_{h_{i+1}}(suf(x_{i+1})))|}\\end{array}\n$$\n\nSince $h_{i}$ and $h_{i + 1}$ assign the same probabilities to prefixes and to suffixes, the sum above equals\n\n$$\n\\begin{array}{l}{\\displaystyle\\sum_{x_{i}}\\displaystyle\\sum_{pre(x_{i})}\\sum_{x_{i+1}}\\sum_{suf(x_{i+1})}\\operatorname*{Pr}_{h_{i}}(pre(x_{i}))\\operatorname*{Pr}_{h_{i}}(suf(x_{i+1}))|\\operatorname*{Pr}_{h_{i}}(x_{i}\\to x_{i+1})-\\operatorname*{Pr}_{h_{i+1}}(x_{i}\\to x_{i+1})| =}\\\\ {\\displaystyle\\sum_{x_{i}}\\displaystyle\\sum_{pre(x_{i})}\\operatorname*{Pr}_{h_{i}}(pre(x_{i}))\\sum_{x_{i+1}}\\sum_{suf(x_{i+1})}\\operatorname*{Pr}_{h_{i}}(suf(x_{i+1}))|\\operatorname*{Pr}_{h_{i}}(x_{i}\\to x_{i+1})-\\operatorname*{Pr}_{h_{i+1}}(x_{i}\\to x_{i+1})|\\le}\\\\ {\\displaystyle\\qquad [\\displaystyle\\sum_{x_{i}}\\sum_{pre(x_{i})}\\operatorname*{Pr}_{h_{i}}(pre(x_{i}))][\\displaystyle\\sum_{x_{i+1}}\\sum_{suf(x_{i+1})}\\operatorname*{Pr}_{h_{i}}(suf(x_{i+1}))\\epsilon/NTR_{max}]}\\end{array}\n$$\n\nThe final expression factors into two independent terms. The first one sums over every i-step prefix (that is, over every prefix that starts at the given $x_{0}$ and ends at $x_{i}$ , whatever $x_{i}$ is), so it equals 1. The second one sums over every suffix starting at $x_{i + 1}$ , whatever $x_{i + 1}$ is. For a fixed value of $x_{i + 1}$ , the suffixes starting there have total probability 1; adding these up over all possible values of $x_{i + 1}$ yields $N$\n\nConsequently,\n\n$$\n\\sum_{p}|\\operatorname*{Pr}_{h_{i}}(p)-\\operatorname*{Pr}_{h_{i+1}}(p)|\\leq 1\\cdot\\epsilon/NTR_{max}\\cdot N\n$$\n\nand the proof is complete.\n\n### Proof of Lemma 6 core (implicit explore-or-exploit value bound)\n\nTo establish the claim, we argue that when R-MAX is played, the agent's reward in M and its reward in $M_{L}$ differ by less than $R_{m a x}$ times the exploration probability. Consequently, a small exploration probability forces R-MAX to obtain a near-optimal payoff; put the other way, failing to obtain a near-optimal payoff forces the exploration probability to be large enough.\n\nEvery policy satisfies the decomposition\n\n$$\nU_{M}(s,\\pi,\\rho,T)=\\sum_{p}{Pr_{M}^{\\pi,s}[p]U_{M}(p)}=\\sum_{q}{Pr_{M}^{\\pi,s}[q]U_{M}(q)}+\\sum_{r}{Pr_{M}^{\\pi,s}[r]U_{M}(r)}\n$$\n\nin which the three sums range, in order, over all T-paths p in M, over the T-paths q in M none of whose visited entries lies in L, and over the T-paths r in M that visit at least one entry lying in L. It follows that\n\n$$\n\\begin{array}{l}{{\\displaystyle|U_{M}(s,{\\mathrm{R-max}},\\rho,T)-U_{M_{L}}(s,{\\mathrm{R-max}},\\rho,T)| = |\\sum_{p}Pr_{M}^{{\\mathrm{R-max}},\\rho,s}[p]U_{M}(p)-\\sum_{p}Pr_{M_{L}}^{{\\mathrm{R-max}},\\rho,s}[p]U_{M_{L}}(p)|}}\\\\ {~}\\\\ {{\\displaystyle~= |\\sum_{q}Pr_{M}^{{\\mathrm{R-max}},\\rho,s}[q]U_{M}(q)+\\sum_{r}Pr_{M}^{{\\mathrm{R-max}},\\rho,s}[r]U_{M}(r)-}}\\end{array}\n$$\n\n$$\n\\begin{array}{c l}{{}}&{{\\displaystyle\\sum_{q}Pr_{M_{L}}^{\\mathrm{R-max},\\rho,s}[q]U_{M_{L}}(q)+\\sum_{r}Pr_{M_{L}}^{\\mathrm{R-max},\\rho,s}[r]U_{M_{L}}(r)|}}\\\\ {{}}&{{\\displaystyle\\leq|\\sum_{q}Pr_{M}^{\\mathrm{R-max},\\rho,s}[q]U_{M}(q)-\\sum_{q}Pr_{M_{L}}^{\\mathrm{R-max},\\rho,s}[q]U_{M_{L}}(q)|\\ +}}\\\\ {{}}&{{\\displaystyle~|\\sum_{r}{Pr_{M}^{\\mathrm{R-max},\\rho,s}[r]U_{M}(r)-\\sum_{r}{Pr_{M_{L}}^{\\mathrm{R-max},\\rho,s}[r]U_{M_{L}}(r)}|}}}\\end{array}\n$$\n\nThe first of these differences,\n\n$$\n|\\sum_{q}{Pr_{M}^{\\mathrm{R-max},\\rho,s}[q]U_{M}(q)}-\\sum_{q}{Pr_{M_{L}}^{\\mathrm{R-max},\\rho,s}[q]U_{M_{L}}(q)|}\n$$\n\nis necessarily 0: along a path that never visits an unknown entry, M and $M_{L}$ yield the same rewards, and they also assign that path the same probability.\n\nWe are therefore left with\n\n$$\n\\begin{array}{r l}&{|U_{M}(s,\\mathrm{R-max},\\rho,T)-U_{M_{L}}(s,\\mathrm{R-max},\\rho,T)|\\leq|\\displaystyle\\sum_{r}Pr_{M}^{\\mathrm{R-max},\\rho,s}[r]U_{M}(r)-\\displaystyle\\sum_{r}Pr_{M_{L}}^{\\mathrm{R-max},\\rho,s}[r]U_{M_{L}}(r)|}\\\\ &{\\qquad\\leq\\displaystyle\\sum_{r}Pr_{M}^{\\mathrm{R-max},\\rho,s}[r]R_{max}}\\end{array}\n$$\n\nThe second inequality holds because the average reward along any path lies between 0 and $R_{m a x}$ ; hence the value of a path in M and its value in $M_{L}$ can differ by at most $R_{m a x}$\n\nThe final term equals $R_{m a x}$ multiplied by the probability of reaching an unknown entry.", "context": [{"id": "v3-brafman02a:ctx1", "name": "Setup: stochastic games (Section 2.1)", "statement": "A game models how several agents interact. It involves a set of players; each player picks an action to carry out from a prescribed action set. The combination of the players' choices determines an outcome, which is expressed numerically as a payoff vector, namely a vector containing one value per player. Our focus is on fixed-sum games with two players (games where the entries of the payoff vector always add up to the same constant). The player we control is called the agent, and the opposing player is called the adversary.$^{2}$\n\nGames are commonly represented by a matrix; this representation is called the strategic form of the game. Rows of the matrix are indexed by the agent's actions and columns by the adversary's actions. When the agent plays its $i^{t h}$ action and the adversary plays its $j^{t h}$ action, the rewards received by the agent and by the adversary are those recorded in the entry at row i and column $j$ of the game matrix. For simplicity, we assume that the agent and the adversary have action sets of the same size; extending to action sets of different sizes is trivial.\n\nA stochastic game (SG) consists of the players playing, one after another, standard games drawn from a given set of games; this sequence may be infinite. Each time a game is played, the players obtain the payoff prescribed by that game's matrix and then move on to a new game. Which game comes next depends stochastically on the game just played and on the actions the players took in it. Formally:"}, {"id": "v3-brafman02a:ctx2", "name": "Definition 1 (stochastic game)", "statement": "Definition 1 A fixed-sum, two player, stochastic-game [SG] M with state set $S=\\{1,\\ldots,N\\}$ and action set $A=\\{a_{1},\\ldots,a_{k}\\}$ is made up of the following components:\n\n• Stage Games: to every state $s \\in S$ there is attached a two-player, fixed-sum game in strategic form in which each player's action set is A. The reward matrix of stage-game i is written $R^{i}$.\n\nProbabilistic Transition Function: $P_{M}(s,t,a,a^{\\prime})$ denotes the probability of moving from state s to state t when the first player (the agent) chooses a and the second player (the adversary) chooses a'."}, {"id": "v3-brafman02a:ctx3", "name": "SGs vs MDPs (Section 2.1)", "statement": "SGs resemble MDPs: in each model, actions cause the world to move between states. The key distinction is that an MDP's transition is governed by the action of one agent, while an SG's transition is governed by the joint action of the agent and the adversary. Moreover, in an SG the agent's reward for an action depends both on that action and on the adversary's action. To capture this, each state is assigned a game, and for this reason we use the words state and game interchangeably."}, {"id": "v3-brafman02a:ctx4", "name": "Rewards in [0, R_max], histories, policies, T-step average value (Section 2.1)", "statement": "To simplify the presentation, the payoffs of both players in every stage game are normalised to be nonnegative real numbers lying between 0 and some constant $R_{m a x}.$ The number of actions is also treated as a constant. A history of length t is an element of $(S\\times A^{2}\\times R)^{t}\\times S$ , that is, t state-action-reward triplets in sequence, followed by the state that is reached. The set H of possible histories is the union, over all $t \\geq 0$ , of the sets of histories of length t, where the histories of length 0 are the elements of S.\n\nFor a given SG, an agent policy maps H to the set of probability distributions over A. Thus, for every possible history, a policy specifies the probability with which each action is chosen.\n\nPolicies are evaluated by the average expected reward criterion, defined as follows. For an SG M and a natural number $T,$ we write $U_{M}(s,\\pi,\\rho,T)$ for the expected T-step undiscounted average reward of a policy π against an adversary using policy $\\rho,$ with both $\\pi$ and $\\rho$ run from a state $s \\in S$ (the subscript naming the SG is dropped when no confusion arises). The value that π can guarantee over T steps from s is denoted $U_{M}(s,\\pi,T)=\\operatorname*{min}_{\\rho \\text{ is a policy}}U_{M}(s,\\pi,\\rho,T)$. We then set $\\begin{array}{r}{U_{M}(s,\\pi)=\\operatorname*{lim}\\operatorname*{inf}_{T\\to\\infty}U_{M}(s,\\pi,T)}\\end{array}$ , and, lastly, $\\begin{array}{r}{U_{M}(\\pi)=\\operatorname*{min}_{s\\in S}U_{M}(s,\\pi).}\\end{array}$ $^{3}$"}, {"id": "v3-brafman02a:ctx5", "name": "Assumptions: observability and known R_max (Section 2.2)", "statement": "Two assumptions underlie the analysis. The first is that the agent can always identify which state (or stage-game) it has arrived at, though not the payoffs and transition probabilities attached to it, and that once a game has been played the agent knows which action the adversary took and which payoffs resulted. The second is that the largest possible reward $R_{m a x}$ is known in advance; we expect that this second assumption can be dropped."}, {"id": "v3-brafman02a:ctx6", "name": "Setup and notation for R-MAX (Section 3)", "statement": "As before, M is a stochastic game made up of a set $S=\\{G_{1},\\ldots,G_{N}\\}$ of stage-games, in each of which both the agent and the adversary choose from the action set $A=\\{a_{1},\\ldots,a_{k}\\}$. Each game has a reward matrix $R^{i}$ attached to it, and $R_{m,l}^{i}$ stands for the pair formed by the agent's and the adversary's rewards when actions $a_{m}$ and $a_{l}$ , respectively, are played in game $G_{i}.$ There is also a probabilistic transition function $P_{M}$ , where $P_{M}(s,t,a,a^{\\prime})$ gives the probability of moving from $G_{s}$ to $G_{t}$ when the agent plays a and the adversary plays $a^{\\prime}.$ It is helpful to regard $P_{M}(i,\\cdot,a,a^{\\prime})$ as attached to the entry $(a,a^{\\prime})$ of the stage-game $G_{i}$ ; in this way every model parameter, reward or transition alike, belongs to a joint action of a specific game. Fix $\\epsilon > 0$ . To keep the exposition simple, for most of the analysis we assume that T, the $\\epsilon$-return mixing time of the optimal policy, is known; how to relax this assumption is shown later."}, {"id": "v3-brafman02a:ctx7", "name": "Algorithm R-MAX (Section 3)", "statement": "The R-MAX algorithm reads as follows.\n\nInput: N – how many stage games there are; k – how many actions each stage game has; $\\epsilon$ – the error bound; δ – the probability that the algorithm fails; $R_{m a x}$ – an upper bound on the reward function; T – the $\\epsilon$-return mixing time of an optimal policy.\n\nInitialize: Build a model $M'$ with $N{+ 1}$ stage-games $\\{G_{0},G_{1},\\dots,G_{N}\\}$ and k actions $\\{a_{1},\\ldots,a_{k}\\}$ . The games $G_{1},\\ldots,G_{N}$ stand for the real games and $\\{a_{1},\\ldots,a_{k}\\}$ for the real actions, while $G_{0}$ is an extra, fictitious game. Every entry of every game matrix is set to $(R_{max},0)$ initially.$^{4}$ Set $P_{M}(G_{i},G_{0},a,a^{\\prime})=1$ for every $i=0,\\ldots,N$ and every pair of actions $a,a^{\\prime}$\n\nAdditionally, for every entry of every game $G_{1},\\dots,G_{N}$ , keep track of: (1) a boolean flag known/unknown, whose initial value is unknown; (2) the states that have been reached by playing the joint action of this entry (together with the number of times each was reached); (3) the reward received (by both players) for playing the joint action of this entry. At the start, items 2 and 3 are empty.\n\n## Repeat:\n\nCompute and Act: For the current state, find a policy that is optimal over T steps, and follow it for T steps or until some new entry becomes known.\n\nObserve and update: After every joint action, proceed as follows. Let a be your action in $G_{i}$ and $a^{\\prime}$ the adversary's action.\n\nWhen the joint action $(a,a^{\\prime})$ is being performed in $G_{i}$ for the first time, set the reward associated with $(a,a^{\\prime})$ in $G_{i}$ to the observed one.\n\nUpdate the record of states that playing $(a,a^{\\prime})$ in $G_{i}$ has led to\n\nIf the record of states reached from this entry now holds $\\begin{array}{r}{K_{1}=\\operatorname*{max}((\\lceil\\frac{4 N T R_{m a x}}{\\epsilon})^{3}\\rceil,\\lceil-6 l n^{3}(\\frac{\\delta}{6 N k^{2}})\\rceil)+1}\\end{array}$ elements, flag this entry as known and set its transition probabilities to the observed frequencies.\n\nR-MAX is thus very simple. Its initial estimate of the model parameters assumes that every state and every joint action gives the maximal reward and moves with probability 1 to the fictitious stage-game $G_{0}$ . An optimal T-step policy is computed for the current model and then followed. After each joint action the agent lands in a new stage-game, and the transition is stored in the corresponding place. When enough information has been gathered about where a given joint action leads from a given stage-game, the model entries for that stage-game and joint action are updated. After every update of the model, an optimal policy is recomputed and the steps above are repeated."}, {"id": "v3-brafman02a:ctx8", "name": "Definition 3 (alpha-approximation)", "statement": "Definition 3 Suppose M and $\\bar{M}$ are SGs sharing the same state space and the same action space. $\\bar{M}$ is called an α-approximation of M if every state s satisfies the following:\n\n1. Writing $P_{M}(s,t,a,a^{\\prime})$ and $P_{\\bar{M}}(s,t,a,a^{\\prime})$ for the probability, in M and in $\\bar{M}$ respectively, of moving from state s to state t under the joint action $(a,a^{\\prime})$ of the agent and the adversary, we have $P_{M}(s,t,a,a^{\\prime})-\\alpha\\le P_{\\bar{M}}(s,t,a,a^{\\prime})\\le P_{M}(s,t,a,a^{\\prime})+\\alpha$\n\n2. For every state s, $\\bar{M}$ and M attach the same stage-game to s (so that the rewards coincide)."}, {"id": "v3-brafman02a:ctx9", "name": "Definition 5 (induced SG M_L) and R-max policy", "statement": "We now introduce induced SGs. Apart from the role played by $R_{m a x}$ , the definition mirrors the induced MDP of Kearns and Singh (1998). The agent chooses its policy on the basis of the induced SG.\n\nDefinition 5 Let M be an SG, and let L denote the set of entries $(G_{i},a,a^{\\prime})$ that are marked unknown; in other words, $(G_{i},a,a^{\\prime})\\in L$ means that the entry for the joint action $(a,a^{\\prime})$ in the stage-game $G_{i}$ is marked unknown. The SG $M_{L}$ is defined to coincide with M except that it has one more state, $G_{0}$ . Every entry of $M_{L}$ outside L has the same transitions and rewards as in M. Every entry that is in L or in $G_{0}$ moves to $G_{0}$ with probability 1 and gives reward $R_{m a x}$ to the agent and 0 to the adversary.$^{5}$\n\nFor an SG M with a set L of unknown states, $R^{M_{L}}$ -max stands for the optimal policy of the induced SG $M_{L}$ . If $M_{L}$ is clear from context, we just say R-MAX policy in place of $R^{M_{L}}$ -max policy."}, {"id": "v3-brafman02a:ctx10", "name": "Lemma 6 (implicit explore or exploit)", "statement": "Lemma 6 Let M be an SG and let L and $M_{L}$ be as above. Let $\\rho$ be any adversary policy, s any state, and $0 < \\alpha < 1$ . Then at least one of the following holds: (1) $V_{R-max}>Opt(\\Pi_{M}(\\epsilon,T))-\\alpha$ , where $V_{R - m a x}$ denotes the expected T-step average reward of the $R^{M_{L}}$ -max policy on M; or (2) when R-MAX is run on M for T steps, an unknown entry is played with probability at least $\\frac{\\alpha}{R_{m a x}}$\n\nThe adversary's policy $\\rho$ cannot be known ahead of time in practice, so we cannot tell in advance whether R-MAX will obtain near-optimal reward or will reach an unknown entry with sufficient probability. What matters is that one of the two will happen, whatever the adversary does."}], "lean": "import Mathlib\n\nopen scoped BigOperators\n\nnamespace ResearchLevel\n\nstructure SG (N k : ℕ) where\n P : Fin N → Fin k → Fin k → Fin N → ℝ\n R : Fin N → Fin k → Fin k → ℝ\n\nvariable {N k T : ℕ}\n\nabbrev Traj (N k T : ℕ) := (Fin (T + 1) → Fin N) × (Fin T → Fin k) × (Fin T → Fin k)\n\nabbrev Policy (N k T : ℕ) :=\n (i : Fin T) → (Fin (i.val + 1) → Fin N) → (Fin i.val → Fin k) →\n (Fin i.val → Fin k) → (Fin i.val → ℝ) → Fin k → ℝ\n\ndef stateHist (w : Traj N k T) (i : Fin T) : Fin (i.val + 1) → Fin N :=\n fun j => w.1 (Fin.castLE (by have := i.isLt; omega) j)\n\ndef agentHist (w : Traj N k T) (i : Fin T) : Fin i.val → Fin k :=\n fun j => w.2.1 (Fin.castLE (by have := i.isLt; omega) j)\n\ndef advHist (w : Traj N k T) (i : Fin T) : Fin i.val → Fin k :=\n fun j => w.2.2 (Fin.castLE (by have := i.isLt; omega) j)\n\ndef rewardHist (M : SG N k) (w : Traj N k T) (i : Fin T) : Fin i.val → ℝ :=\n fun j => M.R (w.1 (Fin.castLE (by have := i.isLt; omega) j).castSucc)\n (w.2.1 (Fin.castLE (by have := i.isLt; omega) j))\n (w.2.2 (Fin.castLE (by have := i.isLt; omega) j))\n\nnoncomputable def pathProb (M : SG N k)\n (πa πd : Policy N k T) (s0 : Fin N) (w : Traj N k T) : ℝ :=\n (if w.1 0 = s0 then (1 : ℝ) else 0) *\n ∏ i : Fin T,\n πa i (stateHist w i) (agentHist w i) (advHist w i) (rewardHist M w i) (w.2.1 i) *\n πd i (stateHist w i) (agentHist w i) (advHist w i) (rewardHist M w i) (w.2.2 i) *\n M.P (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) (w.1 i.succ)\n\nnoncomputable def pathPayoff (M : SG N k) (w : Traj N k T) : ℝ :=\n (1 / (T : ℝ)) * ∑ i : Fin T, M.R (w.1 i.castSucc) (w.2.1 i) (w.2.2 i)\n\nnoncomputable def U (M : SG N k)\n (πa πd : Policy N k T) (s0 : Fin N) : ℝ :=\n ∑ w : Traj N k T, pathProb M πa πd s0 w * pathPayoff M w\n\ndef Approximates (Mbar M : SG N k) (α : ℝ) : Prop :=\n (∀ s a a' t, |Mbar.P s a a' t - M.P s a a' t| ≤ α) ∧\n (∀ s a a', Mbar.R s a a' = M.R s a a')\n\nabbrev UnknownSet (N k : ℕ) := Finset (Fin N × Fin k × Fin k)\n\ndef inducedSG (M : SG N k) (L : UnknownSet N k) (Rmax : ℝ) : SG (N + 1) k where\n P := fun s a a' t =>\n if hs : (s : ℕ) < N then\n if (⟨s, hs⟩, a, a') ∈ L then (if t = Fin.last N then 1 else 0)\n else if ht : (t : ℕ) < N then M.P ⟨s, hs⟩ a a' ⟨t, ht⟩ else 0\n else if t = Fin.last N then 1 else 0\n R := fun s a a' =>\n if hs : (s : ℕ) < N then\n if (⟨s, hs⟩, a, a') ∈ L then Rmax else M.R ⟨s, hs⟩ a a'\n else Rmax\n\nnoncomputable def escapeProb (L : UnknownSet N k) (M : SG N k)\n (πa πd : Policy N k T) (s0 : Fin N) : ℝ :=\n ∑ w : Traj N k T,\n (if ∃ i : Fin T, (w.1 i.castSucc, w.2.1 i, w.2.2 i) ∈ L then\n pathProb M πa πd s0 w else 0)\n\ntheorem simulation_lemma\n (hN : 0 < N) (hk : 0 < k) (hT : 0 < T) (Rmax ε : ℝ) (hRmax : 0 < Rmax) (hε : 0 < ε)\n (M Mbar : SG N k)\n\n (hMP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (hMPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n\n (hMbarP0 : ∀ s a a' t, 0 ≤ Mbar.P s a a' t)\n (hMbarPsum : ∀ s a a', ∑ t, Mbar.P s a a' t = 1)\n\n (hR0 : ∀ s a a', 0 ≤ M.R s a a')\n (hRle : ∀ s a a', M.R s a a' ≤ Rmax)\n\n (πa πd : Policy N k T)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (s0 : Fin N)\n\n (happrox : Approximates Mbar M (ε / ((N : ℝ) * (T : ℝ) * Rmax))) :\n |U Mbar πa πd s0 - U M πa πd s0| ≤ ε := by\n sorry\n\ntheorem path_dist_l1_bound\n (hN : 0 < N) (hk : 0 < k) (hT : 0 < T) (α : ℝ) (hα : 0 ≤ α)\n (M Mbar : SG N k)\n (Rmax : ℝ) (hRmax : 0 < Rmax)\n (hR0 : ∀ s a a', 0 ≤ M.R s a a')\n (hRle : ∀ s a a', M.R s a a' ≤ Rmax)\n (hMP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (hMPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n (hMbarP0 : ∀ s a a' t, 0 ≤ Mbar.P s a a' t)\n (hMbarPsum : ∀ s a a', ∑ t, Mbar.P s a a' t = 1)\n (πa πd : Policy N k T)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (s0 : Fin N)\n (happrox : Approximates Mbar M α) :\n ∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w|\n ≤ (N : ℝ) * (T : ℝ) * α := by\n sorry\n\ntheorem value_diff_escape_bound\n (hN : 0 < N) (hk : 0 < k) (hT : 0 < T) (Rmax : ℝ) (hRmax : 0 < Rmax)\n (L : UnknownSet N k) (M : SG N k)\n (hMP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (hMPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n (hR0 : ∀ s a a', 0 ≤ M.R s a a') (hRle : ∀ s a a', M.R s a a' ≤ Rmax)\n (πa πd : Policy N k T)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (πa' πd' : Policy (N + 1) k T)\n (ha0' : ∀ i hs ha hd hr a, 0 ≤ πa' i hs ha hd hr a)\n (hasum' : ∀ i hs ha hd hr, ∑ a, πa' i hs ha hd hr a = 1)\n (hd0' : ∀ i hs ha hd hr a, 0 ≤ πd' i hs ha hd hr a)\n (hdsum' : ∀ i hs ha hd hr, ∑ a, πd' i hs ha hd hr a = 1)\n (hπa : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πa' i (fun j => (hs j).castSucc) ha hd hr a = πa i hs ha hd hr a)\n (hπd : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πd' i (fun j => (hs j).castSucc) ha hd hr a = πd i hs ha hd hr a)\n (s0 : Fin N) :\n |U (inducedSG M L Rmax) πa' πd' (Fin.castSucc s0) - U M πa πd s0|\n ≤ Rmax * escapeProb L M πa πd s0 := by\n sorry\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen scoped BigOperators\n\nnamespace ResearchLevel\n\nstructure SG (N k : ℕ) where\n P : Fin N → Fin k → Fin k → Fin N → ℝ\n R : Fin N → Fin k → Fin k → ℝ\n\nvariable {N k T : ℕ}\n\nabbrev Traj (N k T : ℕ) := (Fin (T + 1) → Fin N) × (Fin T → Fin k) × (Fin T → Fin k)\n\nabbrev Policy (N k T : ℕ) :=\n (i : Fin T) → (Fin (i.val + 1) → Fin N) → (Fin i.val → Fin k) →\n (Fin i.val → Fin k) → (Fin i.val → ℝ) → Fin k → ℝ\n\ndef stateHist (w : Traj N k T) (i : Fin T) : Fin (i.val + 1) → Fin N :=\n fun j => w.1 (Fin.castLE (by have := i.isLt; omega) j)\n\ndef agentHist (w : Traj N k T) (i : Fin T) : Fin i.val → Fin k :=\n fun j => w.2.1 (Fin.castLE (by have := i.isLt; omega) j)\n\ndef advHist (w : Traj N k T) (i : Fin T) : Fin i.val → Fin k :=\n fun j => w.2.2 (Fin.castLE (by have := i.isLt; omega) j)\n\ndef rewardHist (M : SG N k) (w : Traj N k T) (i : Fin T) : Fin i.val → ℝ :=\n fun j => M.R (w.1 (Fin.castLE (by have := i.isLt; omega) j).castSucc)\n (w.2.1 (Fin.castLE (by have := i.isLt; omega) j))\n (w.2.2 (Fin.castLE (by have := i.isLt; omega) j))\n\nnoncomputable def pathProb (M : SG N k)\n (πa πd : Policy N k T) (s0 : Fin N) (w : Traj N k T) : ℝ :=\n (if w.1 0 = s0 then (1 : ℝ) else 0) *\n ∏ i : Fin T,\n πa i (stateHist w i) (agentHist w i) (advHist w i) (rewardHist M w i) (w.2.1 i) *\n πd i (stateHist w i) (agentHist w i) (advHist w i) (rewardHist M w i) (w.2.2 i) *\n M.P (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) (w.1 i.succ)\n\nnoncomputable def pathPayoff (M : SG N k) (w : Traj N k T) : ℝ :=\n (1 / (T : ℝ)) * ∑ i : Fin T, M.R (w.1 i.castSucc) (w.2.1 i) (w.2.2 i)\n\nnoncomputable def U (M : SG N k)\n (πa πd : Policy N k T) (s0 : Fin N) : ℝ :=\n ∑ w : Traj N k T, pathProb M πa πd s0 w * pathPayoff M w\n\ndef Approximates (Mbar M : SG N k) (α : ℝ) : Prop :=\n (∀ s a a' t, |Mbar.P s a a' t - M.P s a a' t| ≤ α) ∧\n (∀ s a a', Mbar.R s a a' = M.R s a a')\n\nabbrev UnknownSet (N k : ℕ) := Finset (Fin N × Fin k × Fin k)\n\ndef inducedSG (M : SG N k) (L : UnknownSet N k) (Rmax : ℝ) : SG (N + 1) k where\n P := fun s a a' t =>\n if hs : (s : ℕ) < N then\n if (⟨s, hs⟩, a, a') ∈ L then (if t = Fin.last N then 1 else 0)\n else if ht : (t : ℕ) < N then M.P ⟨s, hs⟩ a a' ⟨t, ht⟩ else 0\n else if t = Fin.last N then 1 else 0\n R := fun s a a' =>\n if hs : (s : ℕ) < N then\n if (⟨s, hs⟩, a, a') ∈ L then Rmax else M.R ⟨s, hs⟩ a a'\n else Rmax\n\nnoncomputable def escapeProb (L : UnknownSet N k) (M : SG N k)\n (πa πd : Policy N k T) (s0 : Fin N) : ℝ :=\n ∑ w : Traj N k T,\n (if ∃ i : Fin T, (w.1 i.castSucc, w.2.1 i, w.2.2 i) ∈ L then\n pathProb M πa πd s0 w else 0)\n\n/- A finite autoregressive process, used to isolate the probability calculation\nfrom the concrete trajectory representation. -/\nprivate abbrev Round (N k : ℕ) := Fin k × Fin k × Fin N\n\nprivate def seqPrefix {X : Type*} {n : ℕ} (z : Fin n → X) (i : Fin n) :\n Fin i.val → X :=\n fun j => z ⟨j.val, lt_trans j.isLt i.isLt⟩\n\nprivate abbrev DepKernel (X : Type*) (n : ℕ) :=\n (i : Fin n) → (Fin i.val → X) → X → ℝ\n\nprivate noncomputable def depWeight {X : Type*} {n : ℕ}\n (K : DepKernel X n) (z : Fin n → X) : ℝ :=\n ∏ i : Fin n, K i (seqPrefix z i) (z i)\n\nprivate theorem depWeight_snoc {X : Type*} {n : ℕ} (K : DepKernel X (n + 1))\n (u : Fin n → X) (x : X) :\n depWeight K (Fin.snoc u x) =\n depWeight (fun i u x => K i.castSucc u x) u * K (Fin.last n) u x := by\n have hp (i : Fin n) :\n seqPrefix (Fin.snoc u x) i.castSucc = seqPrefix u i := by\n funext j\n have hj : j.val < n := lt_trans j.isLt i.isLt\n simp [seqPrefix, Fin.snoc, hj]\n have hl : seqPrefix (Fin.snoc u x) (Fin.last n) = u := by\n funext j\n have hj : j.val < n := j.isLt\n simp [seqPrefix, Fin.snoc, hj]\n simp [depWeight, Fin.prod_univ_castSucc, hp, hl]\n\nprivate def prefixStates {N k i : ℕ} (s0 : Fin N) (u : Fin i → Round N k) :\n Fin (i + 1) → Fin N :=\n Fin.cases s0 (fun j => (u j).2.2)\n\nprivate def prefixRewards {N k i : ℕ} (M : SG N k) (s0 : Fin N)\n (u : Fin i → Round N k) : Fin i → ℝ :=\n fun j => M.R (prefixStates s0 u j.castSucc) (u j).1 (u j).2.1\n\nprivate noncomputable def roundKernel (M : SG N k) (πa πd : Policy N k T)\n (s0 : Fin N) : DepKernel (Round N k) T :=\n fun i u x =>\n πa i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) x.1 *\n πd i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) x.2.1 *\n M.P (prefixStates s0 u (Fin.last i.val)) x.1 x.2.1 x.2.2\n\nprivate def trajFromRounds (s : Fin N) (z : Fin T → Round N k) : Traj N k T :=\n (Fin.cases s (fun i => (z i).2.2), (fun i => (z i).1), fun i => (z i).2.1)\n\nprivate def trajRoundEquiv : Traj N k T ≃ Fin N × (Fin T → Round N k) where\n toFun w := (w.1 0, fun i => (w.2.1 i, w.2.2 i, w.1 i.succ))\n invFun p := trajFromRounds p.1 p.2\n left_inv w := by\n rcases w with ⟨st, a, d⟩\n apply Prod.ext\n · funext j\n refine Fin.cases ?_ (fun i => ?_) j\n · rfl\n · rfl\n · apply Prod.ext <;> rfl\n right_inv p := by\n rcases p with ⟨s, z⟩\n apply Prod.ext\n · rfl\n · funext i\n rfl\n\nprivate theorem stateHist_trajFromRounds (s : Fin N) (z : Fin T → Round N k)\n (i : Fin T) :\n stateHist (trajFromRounds s z) i = prefixStates s (seqPrefix z i) := by\n funext j\n refine Fin.cases ?_ (fun q => ?_) j\n · simp [stateHist, trajFromRounds, prefixStates]\n · simp [stateHist, trajFromRounds, prefixStates, seqPrefix]\n congr 2\n\nprivate theorem agentHist_trajFromRounds (s : Fin N) (z : Fin T → Round N k)\n (i : Fin T) :\n agentHist (trajFromRounds s z) i = fun j => (seqPrefix z i j).1 := by\n funext j\n simp [agentHist, trajFromRounds, seqPrefix]\n congr 2\n\nprivate theorem advHist_trajFromRounds (s : Fin N) (z : Fin T → Round N k)\n (i : Fin T) :\n advHist (trajFromRounds s z) i = fun j => (seqPrefix z i j).2.1 := by\n funext j\n simp [advHist, trajFromRounds, seqPrefix]\n congr 2\n\nprivate theorem rewardHist_trajFromRounds (M : SG N k) (s : Fin N)\n (z : Fin T → Round N k) (i : Fin T) :\n rewardHist M (trajFromRounds s z) i =\n prefixRewards M s (seqPrefix z i) := by\n funext j\n change M.R _ _ _ =\n M.R (prefixStates s (seqPrefix z i) j.castSucc)\n (seqPrefix z i j).1 (seqPrefix z i j).2.1\n rw [show (Fin.castLE (by have := i.isLt; omega) j).castSucc =\n Fin.castLE (by have := i.isLt; omega) j.castSucc by apply Fin.ext; rfl]\n change M.R (stateHist (trajFromRounds s z) i j.castSucc)\n (agentHist (trajFromRounds s z) i j)\n (advHist (trajFromRounds s z) i j) = _\n rw [stateHist_trajFromRounds, agentHist_trajFromRounds,\n advHist_trajFromRounds]\n\nprivate theorem pathProb_trajFromRounds (M : SG N k) (πa πd : Policy N k T)\n (s0 : Fin N) (z : Fin T → Round N k) :\n pathProb M πa πd s0 (trajFromRounds s0 z) =\n depWeight (roundKernel M πa πd s0) z := by\n unfold pathProb depWeight\n rw [if_pos (by simp [trajFromRounds]), one_mul]\n apply Finset.prod_congr rfl\n intro i _\n have hcur : (trajFromRounds s0 z).1 i.castSucc =\n prefixStates s0 (seqPrefix z i) (Fin.last i.val) := by\n have h := congrFun (stateHist_trajFromRounds s0 z i) (Fin.last i.val)\n simpa [stateHist] using h\n have hnext : (trajFromRounds s0 z).1 i.succ = (z i).2.2 := by\n simp [trajFromRounds]\n rw [stateHist_trajFromRounds, agentHist_trajFromRounds,\n advHist_trajFromRounds, rewardHist_trajFromRounds]\n simp only [roundKernel]\n rw [hcur, hnext]\n simp [trajFromRounds]\n\nprivate theorem depWeight_nonneg\n {X : Type*} [Fintype X] {n : ℕ} (K : DepKernel X n)\n (hK0 : ∀ i u x, 0 ≤ K i u x) (z : Fin n → X) :\n 0 ≤ depWeight K z := by\n exact Finset.prod_nonneg fun i _ => hK0 i (seqPrefix z i) (z i)\n\nprivate theorem depWeight_sum_eq_one\n {X : Type*} [Fintype X] {n : ℕ} (K : DepKernel X n)\n (hKsum : ∀ i u, ∑ x, K i u x = 1) :\n ∑ z : Fin n → X, depWeight K z = 1 := by\n induction n with\n | zero =>\n simp [depWeight]\n | succ n ih =>\n let K' : DepKernel X n := fun i u x => K i.castSucc u x\n let e : ((Fin n → X) × X) ≃ (Fin (n + 1) → X) :=\n (Equiv.prodComm (Fin n → X) X).trans (Fin.snocEquiv (fun _ => X))\n calc\n (∑ z : Fin (n + 1) → X, depWeight K z) =\n ∑ ux : (Fin n → X) × X, depWeight K (e ux) :=\n (e.sum_comp (depWeight K)).symm\n _ = ∑ u : Fin n → X, ∑ x : X,\n depWeight K' u * K (Fin.last n) u x := by\n rw [Fintype.sum_prod_type]\n apply Fintype.sum_congr\n intro u\n apply Fintype.sum_congr\n intro x\n change depWeight K (Fin.snoc u x) = _\n simpa [K'] using depWeight_snoc K u x\n _ = ∑ u : Fin n → X, depWeight K' u := by\n apply Fintype.sum_congr\n intro u\n rw [← Finset.mul_sum]\n rw [hKsum]\n simp\n _ = 1 := ih K' (fun i u => hKsum i.castSucc u)\n\nprivate lemma abs_mul_sub_mul_le (pbar p bbar b : ℝ)\n (hpbar : 0 ≤ pbar) (hb : 0 ≤ b) :\n |pbar * bbar - p * b| ≤ pbar * |bbar - b| + |pbar - p| * b := by\n rw [show pbar * bbar - p * b =\n pbar * (bbar - b) + (pbar - p) * b by ring]\n calc\n |pbar * (bbar - b) + (pbar - p) * b| ≤\n |pbar * (bbar - b)| + |(pbar - p) * b| := abs_add_le _ _\n _ = pbar * |bbar - b| + |pbar - p| * b := by\n rw [abs_mul, abs_mul, abs_of_nonneg hpbar, abs_of_nonneg hb]\n\nprivate theorem depWeight_l1_bound\n {X : Type*} [Fintype X] {n : ℕ} (δ : ℝ) (hδ : 0 ≤ δ)\n (Kbar K : DepKernel X n)\n (hKbar0 : ∀ i u x, 0 ≤ Kbar i u x)\n (hK0 : ∀ i u x, 0 ≤ K i u x)\n (hKbarSum : ∀ i u, ∑ x, Kbar i u x = 1)\n (hKsum : ∀ i u, ∑ x, K i u x = 1)\n (hstep : ∀ i u, ∑ x, |Kbar i u x - K i u x| ≤ δ) :\n ∑ z : Fin n → X, |depWeight Kbar z - depWeight K z| ≤ (n : ℝ) * δ := by\n induction n with\n | zero => simp [depWeight]\n | succ n ih =>\n let Kbar' : DepKernel X n := fun i u x => Kbar i.castSucc u x\n let K' : DepKernel X n := fun i u x => K i.castSucc u x\n let e : ((Fin n → X) × X) ≃ (Fin (n + 1) → X) :=\n (Equiv.prodComm (Fin n → X) X).trans (Fin.snocEquiv (fun _ => X))\n have hpbar (u : Fin n → X) : 0 ≤ depWeight Kbar' u :=\n depWeight_nonneg Kbar' (fun i v x => hKbar0 i.castSucc v x) u\n have hinner (u : Fin n → X) :\n (∑ x : X,\n |depWeight Kbar' u * Kbar (Fin.last n) u x -\n depWeight K' u * K (Fin.last n) u x|) ≤\n depWeight Kbar' u * δ + |depWeight Kbar' u - depWeight K' u| := by\n calc\n (∑ x : X,\n |depWeight Kbar' u * Kbar (Fin.last n) u x -\n depWeight K' u * K (Fin.last n) u x|) ≤\n ∑ x : X, (depWeight Kbar' u *\n |Kbar (Fin.last n) u x - K (Fin.last n) u x| +\n |depWeight Kbar' u - depWeight K' u| * K (Fin.last n) u x) := by\n apply Finset.sum_le_sum\n intro x _\n exact abs_mul_sub_mul_le _ _ _ _ (hpbar u) (hK0 (Fin.last n) u x)\n _ = depWeight Kbar' u *\n (∑ x : X, |Kbar (Fin.last n) u x - K (Fin.last n) u x|) +\n |depWeight Kbar' u - depWeight K' u| *\n (∑ x : X, K (Fin.last n) u x) := by\n rw [Finset.sum_add_distrib, Finset.mul_sum, Finset.mul_sum]\n _ ≤ depWeight Kbar' u * δ +\n |depWeight Kbar' u - depWeight K' u| := by\n rw [hKsum]\n simp only [mul_one]\n exact add_le_add\n (mul_le_mul_of_nonneg_left (hstep (Fin.last n) u) (hpbar u)) le_rfl\n calc\n (∑ z : Fin (n + 1) → X,\n |depWeight Kbar z - depWeight K z|) =\n ∑ ux : (Fin n → X) × X,\n |depWeight Kbar (e ux) - depWeight K (e ux)| :=\n (e.sum_comp (fun z => |depWeight Kbar z - depWeight K z|)).symm\n _ = ∑ u : Fin n → X, ∑ x : X,\n |depWeight Kbar' u * Kbar (Fin.last n) u x -\n depWeight K' u * K (Fin.last n) u x| := by\n rw [Fintype.sum_prod_type]\n apply Fintype.sum_congr\n intro u\n apply Fintype.sum_congr\n intro x\n change |depWeight Kbar (Fin.snoc u x) -\n depWeight K (Fin.snoc u x)| = _\n rw [depWeight_snoc, depWeight_snoc]\n _ ≤ ∑ u : Fin n → X,\n (depWeight Kbar' u * δ +\n |depWeight Kbar' u - depWeight K' u|) := by\n exact Finset.sum_le_sum fun u _ => hinner u\n _ = (∑ u : Fin n → X, depWeight Kbar' u) * δ +\n ∑ u : Fin n → X, |depWeight Kbar' u - depWeight K' u| := by\n rw [Finset.sum_add_distrib, Finset.sum_mul]\n _ = δ + ∑ u : Fin n → X,\n |depWeight Kbar' u - depWeight K' u| := by\n rw [depWeight_sum_eq_one Kbar'\n (fun i u => hKbarSum i.castSucc u), one_mul]\n _ ≤ δ + (n : ℝ) * δ := by\n exact add_le_add le_rfl <| ih Kbar' K'\n (fun i u x => hKbar0 i.castSucc u x)\n (fun i u x => hK0 i.castSucc u x)\n (fun i u => hKbarSum i.castSucc u)\n (fun i u => hKsum i.castSucc u)\n (fun i u => hstep i.castSucc u)\n _ = ((n + 1 : ℕ) : ℝ) * δ := by push_cast; ring\n\nprivate theorem roundKernel_nonneg\n (M : SG N k) (πa πd : Policy N k T) (s0 : Fin N)\n (hP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a) :\n ∀ i u x, 0 ≤ roundKernel M πa πd s0 i u x := by\n intro i u x\n exact mul_nonneg\n (mul_nonneg\n (ha0 i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) x.1)\n (hd0 i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) x.2.1))\n (hP0 (prefixStates s0 u (Fin.last i.val)) x.1 x.2.1 x.2.2)\n\nprivate theorem roundKernel_sum_eq_one\n (M : SG N k) (πa πd : Policy N k T) (s0 : Fin N)\n (hPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1) :\n ∀ i u, ∑ x, roundKernel M πa πd s0 i u x = 1 := by\n intro i u\n simp only [roundKernel, Round]\n rw [Fintype.sum_prod_type]\n simp_rw [Fintype.sum_prod_type]\n simp_rw [← Finset.mul_sum]\n simp_rw [hPsum, mul_one]\n simp_rw [← Finset.mul_sum]\n simp_rw [hdsum, mul_one]\n exact hasum i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u)\n\nprivate theorem roundKernel_l1_bound\n (α : ℝ) (hα : 0 ≤ α) (M Mbar : SG N k)\n (πa πd : Policy N k T) (s0 : Fin N)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (happrox : Approximates Mbar M α) :\n ∀ i u, ∑ x, |roundKernel Mbar πa πd s0 i u x -\n roundKernel M πa πd s0 i u x| ≤ (N : ℝ) * α := by\n intro i u\n let A : Fin k → ℝ := fun a =>\n πa i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) a\n let D : Fin k → ℝ := fun a =>\n πd i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) a\n let s : Fin N := prefixStates s0 u (Fin.last i.val)\n have hrewards : prefixRewards Mbar s0 u = prefixRewards M s0 u := by\n funext j\n exact happrox.2 _ _ _\n have hA0 (a : Fin k) : 0 ≤ A a := by\n exact ha0 i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) a\n have hD0 (a : Fin k) : 0 ≤ D a := by\n exact hd0 i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u) a\n have hAsum : ∑ a, A a = 1 := by\n exact hasum i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u)\n have hDsum : ∑ a, D a = 1 := by\n exact hdsum i (prefixStates s0 u) (fun j => (u j).1) (fun j => (u j).2.1)\n (prefixRewards M s0 u)\n have hterm (a d : Fin k) (t : Fin N) :\n |A a * D d * Mbar.P s a d t - A a * D d * M.P s a d t| =\n A a * D d * |Mbar.P s a d t - M.P s a d t| := by\n rw [show A a * D d * Mbar.P s a d t - A a * D d * M.P s a d t =\n A a * D d * (Mbar.P s a d t - M.P s a d t) by ring]\n rw [abs_mul, abs_mul, abs_of_nonneg (hA0 a), abs_of_nonneg (hD0 d)]\n have htrans (a d : Fin k) :\n (∑ t : Fin N, |Mbar.P s a d t - M.P s a d t|) ≤ (N : ℝ) * α := by\n calc\n (∑ t : Fin N, |Mbar.P s a d t - M.P s a d t|) ≤ ∑ _t : Fin N, α := by\n exact Finset.sum_le_sum fun t _ => happrox.1 s a d t\n _ = (N : ℝ) * α := by simp [nsmul_eq_mul]\n simp only [roundKernel, Round]\n rw [Fintype.sum_prod_type]\n simp_rw [Fintype.sum_prod_type]\n rw [hrewards]\n change (∑ a : Fin k, ∑ d : Fin k, ∑ t : Fin N,\n |A a * D d * Mbar.P s a d t - A a * D d * M.P s a d t|) ≤ _\n simp_rw [hterm]\n calc\n (∑ a : Fin k, ∑ d : Fin k, ∑ t : Fin N,\n A a * D d * |Mbar.P s a d t - M.P s a d t|) =\n ∑ a : Fin k, ∑ d : Fin k,\n A a * D d * (∑ t : Fin N, |Mbar.P s a d t - M.P s a d t|) := by\n simp_rw [Finset.mul_sum]\n _ ≤ ∑ a : Fin k, ∑ d : Fin k, A a * D d * ((N : ℝ) * α) := by\n apply Finset.sum_le_sum\n intro a _\n apply Finset.sum_le_sum\n intro d _\n exact mul_le_mul_of_nonneg_left (htrans a d) (mul_nonneg (hA0 a) (hD0 d))\n _ = ∑ a : Fin k, (A a * ((N : ℝ) * α)) * (∑ d : Fin k, D d) := by\n apply Fintype.sum_congr\n intro a\n rw [Finset.mul_sum]\n apply Fintype.sum_congr\n intro d\n ring\n _ = ∑ a : Fin k, A a * ((N : ℝ) * α) := by rw [hDsum]; simp\n _ = (∑ a : Fin k, A a) * ((N : ℝ) * α) := by rw [Finset.sum_mul]\n _ = (N : ℝ) * α := by rw [hAsum, one_mul]\n\nprivate theorem path_l1_eq_depWeight\n (M Mbar : SG N k) (πa πd : Policy N k T) (s0 : Fin N) :\n (∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w|) =\n ∑ z : Fin T → Round N k,\n |depWeight (roundKernel Mbar πa πd s0) z -\n depWeight (roundKernel M πa πd s0) z| := by\n let f : Traj N k T → ℝ := fun w =>\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w|\n calc\n (∑ w : Traj N k T, f w) =\n ∑ p : Fin N × (Fin T → Round N k), f (trajRoundEquiv.symm p) := by\n exact Fintype.sum_equiv trajRoundEquiv _ _ (fun w => by simp)\n _ = ∑ s : Fin N, ∑ z : Fin T → Round N k,\n |pathProb Mbar πa πd s0 (trajFromRounds s z) -\n pathProb M πa πd s0 (trajFromRounds s z)| := by\n rw [Fintype.sum_prod_type]\n rfl\n _ = ∑ z : Fin T → Round N k,\n |pathProb Mbar πa πd s0 (trajFromRounds s0 z) -\n pathProb M πa πd s0 (trajFromRounds s0 z)| := by\n apply Fintype.sum_eq_single s0\n intro s hs\n apply Finset.sum_eq_zero\n intro z _\n simp [pathProb, trajFromRounds, hs]\n _ = ∑ z : Fin T → Round N k,\n |depWeight (roundKernel Mbar πa πd s0) z -\n depWeight (roundKernel M πa πd s0) z| := by\n apply Fintype.sum_congr\n intro z\n rw [pathProb_trajFromRounds, pathProb_trajFromRounds]\n\nprivate theorem pathPayoff_eq_of_reward_eq (M Mbar : SG N k)\n (hR : ∀ s a a', Mbar.R s a a' = M.R s a a') (w : Traj N k T) :\n pathPayoff Mbar w = pathPayoff M w := by\n unfold pathPayoff\n congr 1\n apply Fintype.sum_congr\n intro i\n exact hR _ _ _\n\nprivate theorem abs_pathPayoff_le (hT : 0 < T) (Rmax : ℝ)\n (M : SG N k)\n (hR0 : ∀ s a a', 0 ≤ M.R s a a')\n (hRle : ∀ s a a', M.R s a a' ≤ Rmax)\n (w : Traj N k T) :\n |pathPayoff M w| ≤ Rmax := by\n have hTc : 0 < (T : ℝ) := by exact_mod_cast hT\n have hsum0 : 0 ≤ ∑ i : Fin T,\n M.R (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) :=\n Finset.sum_nonneg fun i _ => hR0 _ _ _\n have hsumle : (∑ i : Fin T,\n M.R (w.1 i.castSucc) (w.2.1 i) (w.2.2 i)) ≤\n ∑ _i : Fin T, Rmax :=\n Finset.sum_le_sum fun i _ => hRle _ _ _\n rw [abs_of_nonneg]\n · unfold pathPayoff\n calc\n (1 / (T : ℝ)) * ∑ i : Fin T,\n M.R (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) ≤\n (1 / (T : ℝ)) * ∑ _i : Fin T, Rmax :=\n mul_le_mul_of_nonneg_left hsumle (by positivity)\n _ = (1 / (T : ℝ)) * ((T : ℝ) * Rmax) := by\n simp [nsmul_eq_mul]\n _ = Rmax := by field_simp\n · unfold pathPayoff\n exact mul_nonneg (by positivity) hsum0\n\nprivate theorem model_path_l1_bound\n (α : ℝ) (hα : 0 ≤ α) (M Mbar : SG N k)\n (hMP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (hMPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n (hMbarP0 : ∀ s a a' t, 0 ≤ Mbar.P s a a' t)\n (hMbarPsum : ∀ s a a', ∑ t, Mbar.P s a a' t = 1)\n (πa πd : Policy N k T)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (s0 : Fin N) (happrox : Approximates Mbar M α) :\n ∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w|\n ≤ (N : ℝ) * (T : ℝ) * α := by\n rw [path_l1_eq_depWeight M Mbar πa πd s0]\n calc\n (∑ z : Fin T → Round N k,\n |depWeight (roundKernel Mbar πa πd s0) z -\n depWeight (roundKernel M πa πd s0) z|)\n ≤ (T : ℝ) * ((N : ℝ) * α) :=\n depWeight_l1_bound ((N : ℝ) * α) (mul_nonneg (Nat.cast_nonneg N) hα)\n (roundKernel Mbar πa πd s0) (roundKernel M πa πd s0)\n (roundKernel_nonneg Mbar πa πd s0 hMbarP0 ha0 hd0)\n (roundKernel_nonneg M πa πd s0 hMP0 ha0 hd0)\n (roundKernel_sum_eq_one Mbar πa πd s0 hMbarPsum hasum hdsum)\n (roundKernel_sum_eq_one M πa πd s0 hMPsum hasum hdsum)\n (roundKernel_l1_bound α hα M Mbar πa πd s0 ha0 hd0 hasum hdsum happrox)\n _ = (N : ℝ) * (T : ℝ) * α := by ring\n\nprivate theorem pathProb_nonneg (M : SG N k) (πa πd : Policy N k T)\n (s0 : Fin N)\n (hP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (w : Traj N k T) : 0 ≤ pathProb M πa πd s0 w := by\n unfold pathProb\n apply mul_nonneg\n · split_ifs <;> positivity\n · apply Finset.prod_nonneg\n intro i _\n exact mul_nonneg\n (mul_nonneg (ha0 _ _ _ _ _ _) (hd0 _ _ _ _ _ _))\n (hP0 _ _ _ _)\n\nprivate theorem pathProb_sum_eq_one (M : SG N k) (πa πd : Policy N k T)\n (s0 : Fin N)\n (hPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1) :\n ∑ w : Traj N k T, pathProb M πa πd s0 w = 1 := by\n calc\n (∑ w : Traj N k T, pathProb M πa πd s0 w) =\n ∑ p : Fin N × (Fin T → Round N k),\n pathProb M πa πd s0 (trajRoundEquiv.symm p) := by\n exact Fintype.sum_equiv trajRoundEquiv _ _ (fun w => by simp)\n _ = ∑ s : Fin N, ∑ z : Fin T → Round N k,\n pathProb M πa πd s0 (trajFromRounds s z) := by\n rw [Fintype.sum_prod_type]\n rfl\n _ = ∑ z : Fin T → Round N k,\n pathProb M πa πd s0 (trajFromRounds s0 z) := by\n apply Fintype.sum_eq_single s0\n intro s hs\n apply Finset.sum_eq_zero\n intro z _\n simp [pathProb, trajFromRounds, hs]\n _ = ∑ z : Fin T → Round N k,\n depWeight (roundKernel M πa πd s0) z := by\n apply Fintype.sum_congr\n exact fun z => pathProb_trajFromRounds M πa πd s0 z\n _ = 1 := depWeight_sum_eq_one _\n (roundKernel_sum_eq_one M πa πd s0 hPsum hasum hdsum)\n\ntheorem simulation_lemma\n (hN : 0 < N) (hk : 0 < k) (hT : 0 < T) (Rmax ε : ℝ) (hRmax : 0 < Rmax) (hε : 0 < ε)\n (M Mbar : SG N k)\n\n (hMP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (hMPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n\n (hMbarP0 : ∀ s a a' t, 0 ≤ Mbar.P s a a' t)\n (hMbarPsum : ∀ s a a', ∑ t, Mbar.P s a a' t = 1)\n\n (hR0 : ∀ s a a', 0 ≤ M.R s a a')\n (hRle : ∀ s a a', M.R s a a' ≤ Rmax)\n\n (πa πd : Policy N k T)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (s0 : Fin N)\n\n (happrox : Approximates Mbar M (ε / ((N : ℝ) * (T : ℝ) * Rmax))) :\n |U Mbar πa πd s0 - U M πa πd s0| ≤ ε := by\n have hNc : 0 < (N : ℝ) := by exact_mod_cast hN\n have hTc : 0 < (T : ℝ) := by exact_mod_cast hT\n have hden : 0 < (N : ℝ) * (T : ℝ) * Rmax :=\n mul_pos (mul_pos hNc hTc) hRmax\n have hα : 0 ≤ ε / ((N : ℝ) * (T : ℝ) * Rmax) :=\n (div_pos hε hden).le\n have hdist := model_path_l1_bound\n (ε / ((N : ℝ) * (T : ℝ) * Rmax)) hα M Mbar\n hMP0 hMPsum hMbarP0 hMbarPsum πa πd ha0 hasum hd0 hdsum s0 happrox\n unfold U\n simp_rw [pathPayoff_eq_of_reward_eq M Mbar happrox.2]\n rw [← Finset.sum_sub_distrib]\n calc\n |∑ w : Traj N k T,\n (pathProb Mbar πa πd s0 w * pathPayoff M w -\n pathProb M πa πd s0 w * pathPayoff M w)| ≤\n ∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w * pathPayoff M w -\n pathProb M πa πd s0 w * pathPayoff M w| := by\n exact Finset.abs_sum_le_sum_abs _ _\n _ = ∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w| *\n |pathPayoff M w| := by\n apply Fintype.sum_congr\n intro w\n rw [← sub_mul, abs_mul]\n _ ≤ ∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w| * Rmax := by\n apply Finset.sum_le_sum\n intro w _\n exact mul_le_mul_of_nonneg_left (abs_pathPayoff_le hT Rmax M hR0 hRle w)\n (abs_nonneg _)\n _ = (∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w|) * Rmax := by\n rw [Finset.sum_mul]\n _ ≤ ((N : ℝ) * (T : ℝ) *\n (ε / ((N : ℝ) * (T : ℝ) * Rmax))) * Rmax :=\n mul_le_mul_of_nonneg_right hdist hRmax.le\n _ = ε := by field_simp\n\ntheorem path_dist_l1_bound\n (hN : 0 < N) (hk : 0 < k) (hT : 0 < T) (α : ℝ) (hα : 0 ≤ α)\n (M Mbar : SG N k)\n (Rmax : ℝ) (hRmax : 0 < Rmax)\n (hR0 : ∀ s a a', 0 ≤ M.R s a a')\n (hRle : ∀ s a a', M.R s a a' ≤ Rmax)\n (hMP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (hMPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n (hMbarP0 : ∀ s a a' t, 0 ≤ Mbar.P s a a' t)\n (hMbarPsum : ∀ s a a', ∑ t, Mbar.P s a a' t = 1)\n (πa πd : Policy N k T)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (s0 : Fin N)\n (happrox : Approximates Mbar M α) :\n ∑ w : Traj N k T,\n |pathProb Mbar πa πd s0 w - pathProb M πa πd s0 w|\n ≤ (N : ℝ) * (T : ℝ) * α := by\n rw [path_l1_eq_depWeight M Mbar πa πd s0]\n calc\n (∑ z : Fin T → Round N k,\n |depWeight (roundKernel Mbar πa πd s0) z -\n depWeight (roundKernel M πa πd s0) z|)\n ≤ (T : ℝ) * ((N : ℝ) * α) :=\n depWeight_l1_bound ((N : ℝ) * α) (mul_nonneg (Nat.cast_nonneg N) hα)\n (roundKernel Mbar ��a πd s0) (roundKernel M πa πd s0)\n (roundKernel_nonneg Mbar πa πd s0 hMbarP0 ha0 hd0)\n (roundKernel_nonneg M πa πd s0 hMP0 ha0 hd0)\n (roundKernel_sum_eq_one Mbar πa πd s0 hMbarPsum hasum hdsum)\n (roundKernel_sum_eq_one M πa πd s0 hMPsum hasum hdsum)\n (roundKernel_l1_bound α hα M Mbar πa πd s0 ha0 hd0 hasum hdsum happrox)\n _ = (N : ℝ) * (T : ℝ) * α := by ring\n\nprivate def liftedSG (M : SG N k) (Rmax : ℝ) : SG (N + 1) k where\n P := fun s a a' t =>\n if hs : (s : ℕ) < N then\n if ht : (t : ℕ) < N then M.P ⟨s, hs⟩ a a' ⟨t, ht⟩ else 0\n else if t = Fin.last N then 1 else 0\n R := fun s a a' =>\n if hs : (s : ℕ) < N then M.R ⟨s, hs⟩ a a' else Rmax\n\nprivate theorem liftedSG_P_nonneg (M : SG N k) (Rmax : ℝ)\n (hP0 : ∀ s a a' t, 0 ≤ M.P s a a' t) :\n ∀ s a a' t, 0 ≤ (liftedSG M Rmax).P s a a' t := by\n intro s a a' t\n simp only [liftedSG]\n split_ifs <;> try positivity\n exact hP0 _ _ _ _\n\nprivate theorem liftedSG_P_sum (M : SG N k) (Rmax : ℝ)\n (hPsum : ∀ s a a', ∑ t, M.P s a a' t = 1) :\n ∀ s a a', ∑ t, (liftedSG M Rmax).P s a a' t = 1 := by\n intro s a a'\n rw [Fin.sum_univ_castSucc]\n by_cases hs : (s : ℕ) < N\n · simp [liftedSG, hs, hPsum]\n · have hslast : s = Fin.last N := by\n apply Fin.ext\n simp\n omega\n subst s\n simp [liftedSG]\n\nprivate theorem inducedSG_P_nonneg (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (hP0 : ∀ s a a' t, 0 ≤ M.P s a a' t) :\n ∀ s a a' t, 0 ≤ (inducedSG M L Rmax).P s a a' t := by\n intro s a a' t\n simp only [inducedSG]\n split_ifs <;> try positivity\n exact hP0 _ _ _ _\n\nprivate theorem inducedSG_P_sum (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (hPsum : ∀ s a a', ∑ t, M.P s a a' t = 1) :\n ∀ s a a', ∑ t, (inducedSG M L Rmax).P s a a' t = 1 := by\n intro s a a'\n rw [Fin.sum_univ_castSucc]\n by_cases hs : (s : ℕ) < N\n · by_cases hL : (⟨s, hs⟩, a, a') ∈ L\n · simp [inducedSG, hs, hL]\n · simp [inducedSG, hs, hL, hPsum]\n · have hslast : s = Fin.last N := by\n apply Fin.ext\n simp\n omega\n subst s\n simp [inducedSG]\n\nprivate theorem liftedSG_R_bounds (M : SG N k) (Rmax : ℝ) (hRmax : 0 ≤ Rmax)\n (hR0 : ∀ s a a', 0 ≤ M.R s a a')\n (hRle : ∀ s a a', M.R s a a' ≤ Rmax) :\n (∀ s a a', 0 ≤ (liftedSG M Rmax).R s a a') ∧\n ∀ s a a', (liftedSG M Rmax).R s a a' ≤ Rmax := by\n constructor <;> intro s a a' <;> simp only [liftedSG] <;> split_ifs\n · exact hR0 _ _ _\n · exact hRmax\n · exact hRle _ _ _\n · exact le_rfl\n\nprivate theorem inducedSG_R_bounds (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (hRmax : 0 ≤ Rmax) (hR0 : ∀ s a a', 0 ≤ M.R s a a')\n (hRle : ∀ s a a', M.R s a a' ≤ Rmax) :\n (∀ s a a', 0 ≤ (inducedSG M L Rmax).R s a a') ∧\n ∀ s a a', (inducedSG M L Rmax).R s a a' ≤ Rmax := by\n constructor <;> intro s a a' <;> simp only [inducedSG] <;> split_ifs\n · exact hRmax\n · exact hR0 _ _ _\n · exact hRmax\n · exact le_rfl\n · exact hRle _ _ _\n · exact le_rfl\n\nprivate def extBad (L : UnknownSet N k) (w : Traj (N + 1) k T) : Prop :=\n (∃ (i : Fin T) (s : Fin N),\n w.1 i.castSucc = s.castSucc ∧ (s, w.2.1 i, w.2.2 i) ∈ L) ∨\n ∃ j : Fin (T + 1), w.1 j = Fin.last N\n\nprivate theorem not_extBad_state_embedded {L : UnknownSet N k}\n {w : Traj (N + 1) k T} (hgood : ¬ extBad L w) (j : Fin (T + 1)) :\n ∃ s : Fin N, w.1 j = s.castSucc := by\n have hne : w.1 j ≠ Fin.last N := by\n intro heq\n exact hgood (Or.inr ⟨j, heq⟩)\n have hslt : (w.1 j : ℕ) < N := by\n by_contra hn\n apply hne\n apply Fin.ext\n simp\n omega\n exact ⟨⟨w.1 j, hslt⟩, Fin.ext rfl⟩\n\nprivate theorem not_extBad_not_mem {L : UnknownSet N k}\n {w : Traj (N + 1) k T} (hgood : ¬ extBad L w) (i : Fin T)\n (s : Fin N) (hs : w.1 i.castSucc = s.castSucc) :\n (s, w.2.1 i, w.2.2 i) ∉ L := by\n intro hmem\n exact hgood (Or.inl ⟨i, s, hs, hmem⟩)\n\nprivate theorem induced_lift_R_eq_of_not_bad\n (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (w : Traj (N + 1) k T) (hgood : ¬ extBad L w) (i : Fin T) :\n (inducedSG M L Rmax).R (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) =\n (liftedSG M Rmax).R (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) := by\n obtain ⟨s, hs⟩ := not_extBad_state_embedded hgood i.castSucc\n have hmem := not_extBad_not_mem hgood i s hs\n rw [hs]\n simp [inducedSG, liftedSG, hmem]\n\nprivate theorem induced_lift_P_eq_of_not_bad\n (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (w : Traj (N + 1) k T) (hgood : ¬ extBad L w) (i : Fin T) :\n (inducedSG M L Rmax).P (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) (w.1 i.succ) =\n (liftedSG M Rmax).P (w.1 i.castSucc) (w.2.1 i) (w.2.2 i) (w.1 i.succ) := by\n obtain ⟨s, hs⟩ := not_extBad_state_embedded hgood i.castSucc\n have hmem := not_extBad_not_mem hgood i s hs\n rw [hs]\n simp [inducedSG, liftedSG, hmem]\n\nprivate theorem induced_lift_rewardHist_eq_of_not_bad\n (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (w : Traj (N + 1) k T) (hgood : ¬ extBad L w) (i : Fin T) :\n rewardHist (inducedSG M L Rmax) w i = rewardHist (liftedSG M Rmax) w i := by\n funext j\n exact induced_lift_R_eq_of_not_bad L M Rmax w hgood\n (Fin.castLE (by have := i.isLt; omega) j)\n\nprivate theorem induced_lift_pathProb_eq_of_not_bad\n (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (πa' πd' : Policy (N + 1) k T) (s0 : Fin N)\n (w : Traj (N + 1) k T) (hgood : ¬ extBad L w) :\n pathProb (inducedSG M L Rmax) πa' πd' s0.castSucc w =\n pathProb (liftedSG M Rmax) πa' πd' s0.castSucc w := by\n unfold pathProb\n congr 1\n apply Finset.prod_congr rfl\n intro i _\n rw [induced_lift_rewardHist_eq_of_not_bad L M Rmax w hgood i,\n induced_lift_P_eq_of_not_bad L M Rmax w hgood i]\n\nprivate theorem induced_lift_pathPayoff_eq_of_not_bad\n (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (w : Traj (N + 1) k T) (hgood : ¬ extBad L w) :\n pathPayoff (inducedSG M L Rmax) w = pathPayoff (liftedSG M Rmax) w := by\n unfold pathPayoff\n congr 1\n apply Fintype.sum_congr\n exact fun i => induced_lift_R_eq_of_not_bad L M Rmax w hgood i\n\nprivate theorem pathPayoff_nonneg (hT : 0 < T) (M : SG N k)\n (hR0 : ∀ s a a', 0 ≤ M.R s a a') (w : Traj N k T) :\n 0 ≤ pathPayoff M w := by\n unfold pathPayoff\n exact mul_nonneg (by positivity) (Finset.sum_nonneg fun i _ => hR0 _ _ _)\n\nprivate theorem expectation_diff_le_bad\n {Ω : Type*} [Fintype Ω] (bad : Ω → Prop) [DecidablePred bad]\n (Rmax : ℝ) (p p' q q' : Ω → ℝ)\n (hp0 : ∀ x, 0 ≤ p x) (hp'0 : ∀ x, 0 ≤ p' x)\n (hpsum : ∑ x, p x = 1) (hp'sum : ∑ x, p' x = 1)\n (hq0 : ∀ x, 0 ≤ q x) (hqle : ∀ x, q x ≤ Rmax)\n (hq'0 : ∀ x, 0 ≤ q' x) (hq'le : ∀ x, q' x ≤ Rmax)\n (hgoodp : ∀ x, ¬ bad x → p' x = p x)\n (hgoodq : ∀ x, ¬ bad x → q' x = q x) :\n |(∑ x, p' x * q' x) - ∑ x, p x * q x| ≤\n Rmax * ∑ x, if bad x then p x else 0 := by\n let bp : ℝ := ∑ x, if bad x then p x else 0\n let bp' : ℝ := ∑ x, if bad x then p' x else 0\n let gp : ℝ := ∑ x, if bad x then 0 else p x\n let gp' : ℝ := ∑ x, if bad x then 0 else p' x\n let be : ℝ := ∑ x, if bad x then p x * q x else 0\n let be' : ℝ := ∑ x, if bad x then p' x * q' x else 0\n let ge : ℝ := ∑ x, if bad x then 0 else p x * q x\n let ge' : ℝ := ∑ x, if bad x then 0 else p' x * q' x\n have hp_split : bp + gp = 1 := by\n rw [← hpsum]\n simp only [bp, gp, ← Finset.sum_add_distrib]\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x <;> simp [hx]\n have hp'_split : bp' + gp' = 1 := by\n rw [← hp'sum]\n simp only [bp', gp', ← Finset.sum_add_distrib]\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x <;> simp [hx]\n have hgp : gp' = gp := by\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x\n · simp [gp', gp, hx]\n · simp [gp', gp, hx, hgoodp x hx]\n have hbp : bp' = bp := by linarith\n have hge : ge' = ge := by\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x\n · simp [ge', ge, hx]\n · simp [ge', ge, hx, hgoodp x hx, hgoodq x hx]\n have he_split : (∑ x, p x * q x) = be + ge := by\n simp only [be, ge, ← Finset.sum_add_distrib]\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x <;> simp [hx]\n have he'_split : (∑ x, p' x * q' x) = be' + ge' := by\n simp only [be', ge', ← Finset.sum_add_distrib]\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x <;> simp [hx]\n have hbp0 : 0 ≤ bp := by\n apply Finset.sum_nonneg\n intro x _\n by_cases hx : bad x <;> simp [bp, hx, hp0 x]\n have hbp'0 : 0 ≤ bp' := by rw [hbp]; exact hbp0\n have hbe0 : 0 ≤ be := by\n apply Finset.sum_nonneg\n intro x _\n by_cases hx : bad x <;> simp [be, hx, mul_nonneg (hp0 x) (hq0 x)]\n have hbe'0 : 0 ≤ be' := by\n apply Finset.sum_nonneg\n intro x _\n by_cases hx : bad x <;> simp [be', hx, mul_nonneg (hp'0 x) (hq'0 x)]\n have hbe_le : be ≤ Rmax * bp := by\n calc\n be ≤ ∑ x, if bad x then p x * Rmax else 0 := by\n apply Finset.sum_le_sum\n intro x _\n by_cases hx : bad x\n · simp only [be, hx, if_true]\n exact mul_le_mul_of_nonneg_left (hqle x) (hp0 x)\n · simp [be, hx]\n _ = Rmax * bp := by\n simp only [bp]\n rw [Finset.mul_sum]\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x <;> simp [hx] <;> ring\n have hbe'_le : be' ≤ Rmax * bp := by\n calc\n be' ≤ ∑ x, if bad x then p' x * Rmax else 0 := by\n apply Finset.sum_le_sum\n intro x _\n by_cases hx : bad x\n · simp only [be', hx, if_true]\n exact mul_le_mul_of_nonneg_left (hq'le x) (hp'0 x)\n · simp [be', hx]\n _ = Rmax * bp' := by\n simp only [bp']\n rw [Finset.mul_sum]\n apply Fintype.sum_congr\n intro x\n by_cases hx : bad x <;> simp [hx] <;> ring\n _ = Rmax * bp := by rw [hbp]\n rw [he'_split, he_split, hge]\n rw [show be' + ge - (be + ge) = be' - be by ring]\n apply abs_sub_le_iff.mpr\n constructor\n · exact (sub_le_self _ hbe0).trans hbe'_le\n · exact (sub_le_self _ hbe'0).trans hbe_le\n\nprivate def embedTraj (w : Traj N k T) : Traj (N + 1) k T :=\n (fun j => (w.1 j).castSucc, w.2.1, w.2.2)\n\nprivate theorem stateHist_embedTraj (w : Traj N k T) (i : Fin T) :\n stateHist (embedTraj w) i = fun j => (stateHist w i j).castSucc := by\n rfl\n\nprivate theorem agentHist_embedTraj (w : Traj N k T) (i : Fin T) :\n agentHist (embedTraj w) i = agentHist w i := by\n rfl\n\nprivate theorem advHist_embedTraj (w : Traj N k T) (i : Fin T) :\n advHist (embedTraj w) i = advHist w i := by\n rfl\n\nprivate theorem lifted_rewardHist_embedTraj (M : SG N k) (Rmax : ℝ)\n (w : Traj N k T) (i : Fin T) :\n rewardHist (liftedSG M Rmax) (embedTraj w) i = rewardHist M w i := by\n funext j\n simp [rewardHist, embedTraj, liftedSG]\n\nprivate theorem lifted_pathProb_embedTraj\n (M : SG N k) (Rmax : ℝ) (πa πd : Policy N k T)\n (πa' πd' : Policy (N + 1) k T)\n (hπa : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πa' i (fun j => (hs j).castSucc) ha hd hr a = πa i hs ha hd hr a)\n (hπd : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πd' i (fun j => (hs j).castSucc) ha hd hr a = πd i hs ha hd hr a)\n (s0 : Fin N) (w : Traj N k T) :\n pathProb (liftedSG M Rmax) πa' πd' s0.castSucc (embedTraj w) =\n pathProb M πa πd s0 w := by\n unfold pathProb\n have hinit : ((embedTraj w).1 0 = s0.castSucc) ↔ w.1 0 = s0 := by\n simp [embedTraj]\n rw [if_congr hinit rfl rfl]\n congr 1\n apply Finset.prod_congr rfl\n intro i _\n rw [stateHist_embedTraj, agentHist_embedTraj, advHist_embedTraj,\n lifted_rewardHist_embedTraj]\n rw [hπa, hπd]\n simp [embedTraj, liftedSG]\n\nprivate theorem lifted_pathPayoff_embedTraj (M : SG N k) (Rmax : ℝ)\n (w : Traj N k T) :\n pathPayoff (liftedSG M Rmax) (embedTraj w) = pathPayoff M w := by\n unfold pathPayoff\n congr 1\n apply Fintype.sum_congr\n intro i\n simp [embedTraj, liftedSG]\n\nprivate theorem extBad_embedTraj_iff (L : UnknownSet N k) (w : Traj N k T) :\n extBad L (embedTraj w) ↔\n ∃ i : Fin T, (w.1 i.castSucc, w.2.1 i, w.2.2 i) ∈ L := by\n simp only [extBad, embedTraj]\n constructor\n · rintro (⟨i, s, hs, hmem⟩ | ⟨j, hj⟩)\n · have hstate : w.1 i.castSucc = s := Fin.castSucc_inj.mp hs\n subst s\n exact ⟨i, hmem⟩\n · exact False.elim (Fin.castSucc_ne_last _ hj)\n · rintro ⟨i, hmem⟩\n exact Or.inl ⟨i, w.1 i.castSucc, rfl, hmem⟩\n\nprivate def allEmbedded (w : Traj (N + 1) k T) : Prop :=\n ∀ j : Fin (T + 1), w.1 j ≠ Fin.last N\n\nprivate def embedTrajEquiv :\n Traj N k T ≃ {w : Traj (N + 1) k T // allEmbedded w} where\n toFun w := ⟨embedTraj w, by\n intro j\n simp [embedTraj]⟩\n invFun w :=\n (fun j => ⟨w.1.1 j, Fin.val_lt_last (w.2 j)⟩, w.1.2.1, w.1.2.2)\n left_inv w := by\n apply Prod.ext\n · funext j\n apply Fin.ext\n rfl\n · rfl\n right_inv w := by\n apply Subtype.ext\n apply Prod.ext\n · funext j\n apply Fin.ext\n rfl\n · rfl\n\nprivate theorem exists_step_to_last\n (st : Fin (T + 1) → Fin (N + 1))\n (h0 : st 0 ≠ Fin.last N) (hex : ∃ j, st j = Fin.last N) :\n ∃ i : Fin T, st i.castSucc ≠ Fin.last N ∧ st i.succ = Fin.last N := by\n let P : ℕ → Prop := fun n => ∃ hn : n < T + 1, st ⟨n, hn⟩ = Fin.last N\n have hP : ∃ n, P n := by\n obtain ⟨j, hj⟩ := hex\n exact ⟨j.val, j.isLt, hj⟩\n let m := Nat.find hP\n obtain ⟨hmT, hmstate⟩ := Nat.find_spec hP\n change m < T + 1 at hmT\n change st ⟨m, hmT⟩ = Fin.last N at hmstate\n have hm0 : m ≠ 0 := by\n intro heq\n apply h0\n have hidx : (⟨m, hmT⟩ : Fin (T + 1)) = 0 := by\n apply Fin.ext\n simp [heq]\n rw [← hidx]\n exact hmstate\n have hmpos : 0 < m := Nat.pos_of_ne_zero hm0\n have himT : m - 1 < T := by omega\n let i : Fin T := ⟨m - 1, himT⟩\n refine ⟨i, ?_, ?_⟩\n · intro hprev\n have hprevP : P (m - 1) := by\n refine ⟨by omega, ?_⟩\n have hidx : (⟨m - 1, by omega⟩ : Fin (T + 1)) = i.castSucc := by\n apply Fin.ext\n rfl\n simpa [hidx] using hprev\n exact (Nat.find_min hP (by omega)) hprevP\n · have hidx : i.succ = (⟨m, hmT⟩ : Fin (T + 1)) := by\n apply Fin.ext\n simp [i]\n omega\n rw [hidx]\n exact hmstate\n\nprivate theorem lifted_pathProb_zero_of_not_allEmbedded\n (M : SG N k) (Rmax : ℝ) (πa' πd' : Policy (N + 1) k T)\n (s0 : Fin N) (w : Traj (N + 1) k T) (hnot : ¬ allEmbedded w) :\n pathProb (liftedSG M Rmax) πa' πd' s0.castSucc w = 0 := by\n by_cases hinit : w.1 0 = s0.castSucc\n · have h0 : w.1 0 ≠ Fin.last N := by\n rw [hinit]\n exact Fin.castSucc_ne_last _\n have hex : ∃ j, w.1 j = Fin.last N := by\n simpa [allEmbedded] using hnot\n obtain ⟨i, hi, hinext⟩ := exists_step_to_last w.1 h0 hex\n have his : (w.1 i.castSucc : ℕ) < N := Fin.val_lt_last hi\n unfold pathProb\n rw [if_pos hinit, one_mul]\n apply Finset.prod_eq_zero (Finset.mem_univ i)\n rw [hinext]\n simp [liftedSG, his]\n · simp [pathProb, hinit]\n\nprivate theorem sum_over_extended_eq_sum_embed\n (F : Traj (N + 1) k T → ℝ)\n (hzero : ∀ w, ¬ allEmbedded w → F w = 0) :\n (∑ w : Traj (N + 1) k T, F w) = ∑ w : Traj N k T, F (embedTraj w) := by\n classical\n calc\n (∑ w : Traj (N + 1) k T, F w) =\n ∑ w : Traj (N + 1) k T, if allEmbedded w then F w else 0 := by\n apply Fintype.sum_congr\n intro w\n by_cases hw : allEmbedded w\n · simp [hw]\n · simp [hw, hzero w hw]\n _ = ∑ w ∈ (Finset.univ.filter allEmbedded), F w := by\n rw [Finset.sum_filter]\n _ = ∑ w : {w : Traj (N + 1) k T // allEmbedded w}, F w := by\n exact Finset.sum_subtype _ (by simp) F\n _ = ∑ w : Traj N k T, F (embedTraj w) := by\n exact (Fintype.sum_equiv embedTrajEquiv\n (fun w => F (embedTraj w)) (fun w => F w.1) (fun w => rfl)).symm\n\nprivate noncomputable def cutOn (p : Prop) (x : ℝ) : ℝ := by\n classical\n exact if p then x else 0\n\nprivate theorem lifted_U_eq_original\n (M : SG N k) (Rmax : ℝ) (πa πd : Policy N k T)\n (πa' πd' : Policy (N + 1) k T)\n (hπa : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πa' i (fun j => (hs j).castSucc) ha hd hr a = πa i hs ha hd hr a)\n (hπd : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πd' i (fun j => (hs j).castSucc) ha hd hr a = πd i hs ha hd hr a)\n (s0 : Fin N) :\n U (liftedSG M Rmax) πa' πd' s0.castSucc = U M πa πd s0 := by\n unfold U\n rw [sum_over_extended_eq_sum_embed]\n · apply Fintype.sum_congr\n intro w\n rw [lifted_pathProb_embedTraj M Rmax πa πd πa' πd' hπa hπd s0 w,\n lifted_pathPayoff_embedTraj]\n · intro w hw\n rw [lifted_pathProb_zero_of_not_allEmbedded M Rmax πa' πd' s0 w hw]\n simp\n\nprivate theorem lifted_bad_mass_eq_escapeProb\n (L : UnknownSet N k) (M : SG N k) (Rmax : ℝ)\n (πa πd : Policy N k T) (πa' πd' : Policy (N + 1) k T)\n (hπa : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πa' i (fun j => (hs j).castSucc) ha hd hr a = πa i hs ha hd hr a)\n (hπd : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πd' i (fun j => (hs j).castSucc) ha hd hr a = πd i hs ha hd hr a)\n (s0 : Fin N) :\n (∑ w : Traj (N + 1) k T,\n cutOn (extBad L w) (pathProb (liftedSG M Rmax) πa' πd' s0.castSucc w)) =\n escapeProb L M πa πd s0 := by\n classical\n unfold escapeProb\n rw [sum_over_extended_eq_sum_embed]\n · apply Fintype.sum_congr\n intro w\n simp only [cutOn]\n rw [lifted_pathProb_embedTraj M Rmax πa πd πa' πd' hπa hπd s0 w]\n rw [if_congr (extBad_embedTraj_iff L w) rfl rfl]\n · intro w hw\n simp only [cutOn]\n rw [lifted_pathProb_zero_of_not_allEmbedded M Rmax πa' πd' s0 w hw]\n split_ifs <;> rfl\n\ntheorem value_diff_escape_bound\n (hN : 0 < N) (hk : 0 < k) (hT : 0 < T) (Rmax : ℝ) (hRmax : 0 < Rmax)\n (L : UnknownSet N k) (M : SG N k)\n (hMP0 : ∀ s a a' t, 0 ≤ M.P s a a' t)\n (hMPsum : ∀ s a a', ∑ t, M.P s a a' t = 1)\n (hR0 : ∀ s a a', 0 ≤ M.R s a a') (hRle : ∀ s a a', M.R s a a' ≤ Rmax)\n (πa πd : Policy N k T)\n (ha0 : ∀ i hs ha hd hr a, 0 ≤ πa i hs ha hd hr a)\n (hasum : ∀ i hs ha hd hr, ∑ a, πa i hs ha hd hr a = 1)\n (hd0 : ∀ i hs ha hd hr a, 0 ≤ πd i hs ha hd hr a)\n (hdsum : ∀ i hs ha hd hr, ∑ a, πd i hs ha hd hr a = 1)\n (πa' πd' : Policy (N + 1) k T)\n (ha0' : ∀ i hs ha hd hr a, 0 ≤ πa' i hs ha hd hr a)\n (hasum' : ∀ i hs ha hd hr, ∑ a, πa' i hs ha hd hr a = 1)\n (hd0' : ∀ i hs ha hd hr a, 0 ≤ πd' i hs ha hd hr a)\n (hdsum' : ∀ i hs ha hd hr, ∑ a, πd' i hs ha hd hr a = 1)\n (hπa : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πa' i (fun j => (hs j).castSucc) ha hd hr a = πa i hs ha hd hr a)\n (hπd : ∀ (i : Fin T) (hs : Fin (i.val + 1) → Fin N) ha hd hr a,\n πd' i (fun j => (hs j).castSucc) ha hd hr a = πd i hs ha hd hr a)\n (s0 : Fin N) :\n |U (inducedSG M L Rmax) πa' πd' (Fin.castSucc s0) - U M πa πd s0|\n ≤ Rmax * escapeProb L M πa πd s0 := by\n classical\n have hLiftP0 := liftedSG_P_nonneg M Rmax hMP0\n have hLiftPsum := liftedSG_P_sum M Rmax hMPsum\n have hIndP0 := inducedSG_P_nonneg L M Rmax hMP0\n have hIndPsum := inducedSG_P_sum L M Rmax hMPsum\n have hLiftR := liftedSG_R_bounds M Rmax hRmax.le hR0 hRle\n have hIndR := inducedSG_R_bounds L M Rmax hRmax.le hR0 hRle\n have hbound := expectation_diff_le_bad (extBad L) Rmax\n (fun w : Traj (N + 1) k T =>\n pathProb (liftedSG M Rmax) πa' πd' s0.castSucc w)\n (fun w : Traj (N + 1) k T =>\n pathProb (inducedSG M L Rmax) πa' πd' s0.castSucc w)\n (fun w : Traj (N + 1) k T => pathPayoff (liftedSG M Rmax) w)\n (fun w : Traj (N + 1) k T => pathPayoff (inducedSG M L Rmax) w)\n (fun w => pathProb_nonneg (liftedSG M Rmax) πa' πd' s0.castSucc\n hLiftP0 ha0' hd0' w)\n (fun w => pathProb_nonneg (inducedSG M L Rmax) πa' πd' s0.castSucc\n hIndP0 ha0' hd0' w)\n (pathProb_sum_eq_one (liftedSG M Rmax) πa' πd' s0.castSucc\n hLiftPsum hasum' hdsum')\n (pathProb_sum_eq_one (inducedSG M L Rmax) πa' πd' s0.castSucc\n hIndPsum hasum' hdsum')\n (fun w => pathPayoff_nonneg hT (liftedSG M Rmax) hLiftR.1 w)\n (fun w => (le_abs_self _).trans\n (abs_pathPayoff_le hT Rmax (liftedSG M Rmax) hLiftR.1 hLiftR.2 w))\n (fun w => pathPayoff_nonneg hT (inducedSG M L Rmax) hIndR.1 w)\n (fun w => (le_abs_self _).trans\n (abs_pathPayoff_le hT Rmax (inducedSG M L Rmax) hIndR.1 hIndR.2 w))\n (fun w hw => induced_lift_pathProb_eq_of_not_bad L M Rmax πa' πd' s0 w hw)\n (fun w hw => induced_lift_pathPayoff_eq_of_not_bad L M Rmax w hw)\n calc\n |U (inducedSG M L Rmax) πa' πd' s0.castSucc - U M πa πd s0| =\n |U (inducedSG M L Rmax) πa' πd' s0.castSucc -\n U (liftedSG M Rmax) πa' πd' s0.castSucc| := by\n rw [lifted_U_eq_original M Rmax πa πd πa' πd' hπa hπd s0]\n _ ≤ Rmax * (∑ w : Traj (N + 1) k T,\n cutOn (extBad L w)\n (pathProb (liftedSG M Rmax) πa' πd' s0.castSucc w)) := by\n simpa only [U, cutOn] using hbound\n _ = Rmax * escapeProb L M πa πd s0 := by\n rw [lifted_bad_mass_eq_escapeProb L M Rmax πa πd πa' πd' hπa hπd s0]\nend ResearchLevel\n"} +{"id": "v24-22-0747", "source": "Research-level", "targets": [{"label": "Proposition 4", "decls": ["prop4"], "statement": "Proposition 4 For any distribution D, there exist a majority vote $B_{Q}$ such that\n\n$$\nR_{D}(B_{Q})\\leq\\mathcal{C}_{Q}^{D}=\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(\\underset{y\\sim D_{\\mathcal{Y}|x}}{\\mathbf{Var}}(y)\\right).\n$$\n\nMoreover, there is no majority vote which can produce a lower C-bound.", "context_ids": ["v24-22-0747:ctx1", "v24-22-0747:ctx2", "v24-22-0747:ctx3", "v24-22-0747:ctx8"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}, {"label": "Proposition 3", "decls": ["prop3"], "statement": "Proposition 3 (Proposition 15 in Germain et al. (2015) corrected) For any countable set of voters $\\mathcal{H}$, any distribution Q on ${\\mathcal{H}},$ and any distribution D on $\\mathcal{X}\\times\\{-1,1\\}$ such that there exists a function $g:\\mathcal{X}\\to\\{-1,1\\}$ for which $y=g(x)$ and $yf(x)>0$ for all $(x,y)\\sim D$ and $f \\in \\mathcal H$ , we have\n\n$$\n\\mathbf{Var}(M_{Q}^{D})\\leq\\sum_{f\\in\\mathcal{H}}Q^{2}(f)+\\sum_{f_{1}\\in\\mathcal{H}}\\sum_{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}Q(f_{1})Q(f_{2})\\mathbf{Cov}_{(x,y)\\sim D}(f_{1}(x),f_{2}(x)).\n$$", "context_ids": ["v24-22-0747:ctx1", "v24-22-0747:ctx2", "v24-22-0747:ctx3", "v24-22-0747:ctx4", "v24-22-0747:ctx5", "v24-22-0747:ctx7"], "sibling_refs": [], "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}, {"label": "Counter-example (Section 4, falsifying Corollary 2)", "decls": ["cbound_counterexample"], "statement": "Counter-example falsifying Corollary 2 (Corollary 16 in Germain et al. 2015). Corollary 2 claimed that for $n$ independent voters under a uniform distribution $Q$, the C-bound satisfies $R_D(B_Q) \\le C_Q^D \\le 1/(n(1-2 d_Q^D)) = 1/(n(1-2 R_D(G_Q)))$, and thus decreases asymptotically to 0 as $n$ grows. The erratum disproves this with a concrete construction (Section 4): the label $y$ is independent of the input $x$ with $\\Pr(y=1)=0.8$ (so $\\mathbb{E}[y]=3/5$), and there are $n$ mutually independent deterministic voters $f_1,\\dots,f_n$ each with $\\Pr(f_i=1)=0.8$ (so $\\mathbb{E}[f_i]=3/5$, $\\mathbb{E}[f_i^2]=1$, and $\\mathbb{E}[f_i f_j]=\\mathbb{E}[f_i]\\mathbb{E}[f_j]=9/25$ for $i \\neq j$), each given uniform weight $Q(f_i)=1/n$, giving the aggregated score $S(x)=(1/n) \\sum_i f_i(x)$. For this majority vote the first two margin moments are $\\mu_1 = \\mathbb{E}[y \\cdot S] = (3/5)(3/5) = 9/25$ and $\\mu_2 = \\mathbb{E}[S^2] = (16+9n)/(25n)$, so the C-bound equals $C_Q^D = 1 - \\mu_1^2/\\mu_2 = (400 + 144 n)/(400 + 225 n)$. In particular $C_Q^D > 0.64 = 16/25$ for every $n > 0$; hence the C-bound does not tend to 0 as the number of independent voters grows, contradicting Corollary 2 (and therefore Proposition 1).", "context_ids": ["v24-22-0747:ctx1", "v24-22-0747:ctx2", "v24-22-0747:ctx3", "v24-22-0747:ctx4", "v24-22-0747:ctx6"], "sibling_refs": [], "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "### Proof of Proposition 4\n\nProof Let $h(x)=\\mathbf{E}_{y\\sim D_{\\mathcal{Y}|x}}(y)$ and consider a majority vote $B_{Q}$ defined by a set of voters $\\mathcal{H}$ and a distribution $Q$ over this set. The score given to any input x by said majority vote $B_{Q}$ is given by $\\textstyle\\sum_{f\\in{\\mathcal{H}}}Q(f)f(x)$ . We first notice that this majority vote is equivalent to a majority vote comprised of a single voter $\\begin{array}{r}{k(x)=\\sum_{f\\in\\mathcal{H}}Q(f)f(x)}\\end{array}$ as the margin of both majority vote would follow the same distribution. To see this, let $M_{Q^{\\prime}}(x,y)$ be the margin function of this new majority vote where $Q^{\\prime}$ is a dirac distribution on the single voter $k(x)$. We then have\n\n$$\nM_{Q}(x,y)=\\underset{f\\sim Q}{\\mathbf{E}}\\left[yf(x)\\right]=y\\underset{f\\sim Q}{\\mathbf{E}}\\left[f(x)\\right]=yk(x)=\\underset{k\\sim Q^{\\prime}}{\\mathbf{E}}\\left[yk(x)\\right]=M_{Q^{\\prime}}(x,y).\n$$\n\nSince both functions $M_{Q}(x,y)$ and $M_{Q^{\\prime}}(x,y)$ are equal for any value $(x,y)$ , both margins $(M_{Q^{\\prime}}^{D}$ and $M_{Q}^{D})$ will have the same distribution. We remind that the C-bound can be defined using only the moments of its margin. Therefore, as both majority votes lead to the same margin, they will possess the same C-bound. We therefore adopt this equivalent majority vote which uses a single voter $k(x)$ and the margin $M_{Q}^{D}$ for the remainder of the proof. We then consider the definition of the C-bound and proceed as follows (recall that $y\\in\\{-1,1\\}$ , and therefore $y^{2}=1)$\n\n$$\n\\begin{array}{r l}&{\\mathcal{C}_{Q}^{D}=1-\\frac{\\big(\\mu_{1}(M_{Q}^{D})\\big)^{2}}{\\mu_{2}(M_{Q}^{D})}}\\\\ &{\\qquad=1-\\frac{\\Big(\\underset{(x,y)\\sim D}{\\mathbf{E}}(yk(x))\\Big)^{2}}{\\underset{(x,y)\\sim D}{\\mathbf{E}}(y^{2}k(x)^{2})}}\\\\ &{\\qquad=1-\\frac{\\Big(\\underset{(x,y)\\sim D}{\\mathbf{E}}(k(x)h(x))\\Big)^{2}}{\\underset{(x,y)\\sim D}{\\mathbf{E}}(k(x)^{2})}}\\\\ &{\\qquad\\geq 1-\\frac{\\underset{(x,y)\\sim D}{\\mathbf{E}}(k(x)^{2})\\underset{(x,y)\\sim D}{\\mathbf{E}}(h(x)^{2})}{\\underset{(x,y)\\sim D}{\\mathbf{E}}(k(x)^{2})}}\\\\ &{\\qquad=1-\\underset{(x,y)\\sim D}{\\mathbf{E}}(h(x)^{2}).}\\end{array}\n$$\n\nThe above inequality is given by the Cauchy-Schwarz inequality. We can easily see that by choosing k such that $k(x)\\ =\\ h(x)$ for all $x,$ the inequality becomes an equality. This means that the value of the C-bound for a given distribution D is lower-bounded by\n\n$1-\\mathbf{E}_{(x,y)\\sim D}(h(x)^{2})$ , which is always achievable. We can simplify this expression as follows:\n\n$$\n\\begin{array}{r l}&{\\mathcal{C}_{Q}^{D}=1-\\underset{(x,y)\\sim D}{\\mathbf{E}}(h(x)^{2})}\\\\ &{\\quad=1-\\underset{(x,y)\\sim D}{\\mathbf{E}}\\Big [\\Big(\\underset{y\\sim D_{\\mathcal{Y}|x}}{\\mathbf{E}}(y)\\Big)^{2}\\Big]}\\\\ &{\\quad=\\underset{(x,y)\\sim D}{\\mathbf{E}}\\Big [1-\\Big(\\underset{y\\sim D_{\\mathcal{Y}|x}}{\\mathbf{E}}(y)\\Big)^{2}\\Big]}\\\\ &{\\quad=\\underset{(x,y)\\sim D}{\\mathbf{E}}\\Big [\\underset{y\\sim D_{\\mathcal{Y}|x}}{\\mathbf{E}}(y^{2})-\\Big(\\underset{y\\sim D_{\\mathcal{Y}|x}}{\\mathbf{E}}(y)\\Big)^{2}\\Big]}\\\\ &{\\quad=\\underset{(x,y)\\sim D}{\\mathbf{E}}\\Big(\\underset{y\\sim D_{\\mathcal{Y}|x}}{\\mathbf{Var}}(y)\\Big).}\\end{array}\n$$\n\n### Proof of Proposition 3\n\nProof Let $g(x)$ be the labelling function assigning each value x to its true, and noiseless, label $y$ and let $f_{i}(x)$ be any voter taken from $\\mathcal{H}$. Since $yf_{i}(x)>0$ for any voter $f_{i}\\in \\mathcal{H}$ and for any given x, we have that the true labelling function $g(x)$ and the voter $f_{i}(x)$ are of the same sign. Thus, we always have $g(x)f_{i}(x)\\geq f_{i}(x)\\geq-g(x)f_{i}(x)$ , which gives us the following inequality:\n\n$$\n\\begin{array}{r l}&{\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(g(x)f_{i}(x)\\right)\\geq\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(f_{i}(x)\\right)\\geq-\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(g(x)f_{i}(x)\\right)}\\\\ {\\iff}&{\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(g(x)f_{i}(x)\\right)\\geq\\left|\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(f_{i}(x)\\right)\\right|}\\\\ {\\implies}&{\\left[\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(g(x)f_{i}(x)\\right)\\right]^{2}\\geq\\left[\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left(f_{i}(x)\\right)\\right]^{2}.}\\end{array}\n$$\n\nSince this inequality is true for each voter in $\\mathcal{H}$, we consider the previous inequality using the functions $f_{i}$ and $f_{j}$ . Using the fact that for values $a,b,c,d>0$ we have the implication $a0$ for any x, we have that both terms on the left side of the inequality are positive prior to being squared. Knowing this guarantees that the inequality still holds as we take the square root on both sides. This inequality can then be used as follows:\n\n$$\n\\begin{array}{r l}&{\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(y f_{i}(x),y f_{j}(x))}\\\\ &{=\\underset{(x,y)\\sim D}{\\mathbf{E}}(y^{2}f_{i}(x)f_{j}(x))-\\underset{(x,y)\\sim D}{\\mathbf{E}}(y f_{i}(x))\\underset{(x,y)\\sim D}{\\mathbf{E}}(y f_{j}(x))}\\\\ &{=\\underset{(x,y)\\sim D}{\\mathbf{E}}(1 f_{i}(x)f_{j}(x))-\\underset{(x,y)\\sim D}{\\mathbf{E}}(g(x)f_{i}(x))\\underset{(x,y)\\sim D}{\\mathbf{E}}(g(x)f_{j}(x))}\\\\ &{\\leq\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}(f_{i}(x)f_{j}(x))-\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}(f_{i}(x))\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}(f_{j}(x))}\\\\ &{=\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{Cov}}(f_{i}(x),f_{j}(x))}\\\\ &{=\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(f_{i}(x),f_{j}(x)).}\\end{array}\n$$\n\nThe last equality only serves to highlight that since y is absent from both $f_{i}(x)$ and $f_{j}(x)$ computing the covariance according to either the joint distribution D or the marginal distribution $D_{\\mathcal{X}}$ does not affect the result. We have now proven that under our new set of hypothesis, the inequality $\\mathbf{Cov}_{(x,y)\\sim D}\\left(y f_{1}(x),y f_{2}(x)\\right)\\le\\mathbf{Cov}_{(x,y)\\sim D}\\left(f_{1}(x),f_{2}(x)\\right)$ always stands. We note that the original proof erroneously assumed this to be an equality. Nonetheless, we can apply this new inequality to the original proof as follows:\n\n$$\n\\begin{array}{r l}{\\underset{(x,y)\\sim D}{\\mathbf{Var}}(M_{Q}(x,y))=\\underset{(x,y)\\sim D}{\\mathbf{Var}}\\left(\\underset{f\\in\\mathcal{H}}{\\sum}Q(f)y f(x)\\right)}&{}\\\\ &{=\\underset{f\\in\\mathcal{H}}{\\sum}Q^{2}(f)\\underset{(x,y)\\sim D}{\\mathbf{Var}}y f(x)+\\underset{f_{1}\\in\\mathcal{H}}{\\sum}\\underset{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}{\\sum}Q(f_{1})Q(f_{2})\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(y f_{1}(x),y f_{2}(x))}\\\\ &{\\leq\\underset{f\\in\\mathcal{H}}{\\sum}Q^{2}(f)\\underset{(x,y)\\sim D}{\\mathbf{Var}}y f(x)+\\underset{f_{1}\\in\\mathcal{H}}{\\sum}\\underset{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}{\\sum}Q(f_{1})Q(f_{2})\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(f_{1}(x),f_{2}(x))}\\\\ &{\\leq\\underset{f\\in\\mathcal{H}}{\\sum}Q^{2}(f)+\\underset{f_{1}\\in\\mathcal{H}}{\\sum}\\underset{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}{\\sum}Q(f_{1})Q(f_{2})\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(f_{1}(x),f_{2}(x)).}\\end{array}\n$$\n\nThe final inequality is given by the fact that $\\underset{(x,y)\\sim D}{\\mathbf{Var}}{y f(x)}\\leq 1$ for all voters $f \\in \\mathcal H$\n\n### Proof of Counter-example (Section 4, falsifying Corollary 2)\n\nCounter-example. Suppose a binary classification problem where each example $(x,y){\\sim}D$ is such that x is drawn from the uniform distribution over a one dimensional input space $\\mathcal{X}=[0,1]$ , and the output is either $y = 1$ with probability $p=0.8$ or $y = - 1$ with probability $1-p=0.2$ (that is, y is independent of x). Let us now consider a majority vote classifier made from the set of deterministic voters $\\mathcal{H}: =\\{f_{i}(x)\\}$ for $i\\in\\{1,2,...,n\\}$ such that $f_{i}(x)=1$ if the $i^{t h}$ decimal of x is greater or equal than 2, and $f_{i}(x)= -1$ otherwise. As x follows a uniform distribution over [0, 1], every decimal value will be taken from $0,1,2,...,9$ with probability 0.1 for each value. Furthermore, the value of every decimal positions are independent from one another, rendering the output of each voter mutually independent. Finally, each voter $f_{i}\\in \\mathcal{H}$ is given an equal weight of $Q(f_{i})=1/n$\n\nAccording to Corollary 2, this majority vote should yield a C-bound that decreases asymptotically to 0 as the number of voters n increases. Because $R_{D}(B_{Q})\\leq\\mathcal{C}_{Q}^{D}$ this implies that given a large enough amount of voters, it would be possible to predict with almost certainty the noisy label y, which is uncorrelated to both the input x and the voters. However, this result is clearly incorrect, as there is always a minimal probability of $2/10$ to make a false prediction, i.e., $R_{D}(B_{Q})\\geq 0.2$ . Moreover, given the construction of data distribution and the voters, we obtain from the definition of the C-bound $\\begin{array}{r}{\\mathcal{C}_{Q}^{D}=\\frac{400+144n}{400+225n}}\\end{array}$ . It is easy to see that the value $\\mathcal{C}_{Q}^{D}$ does not go to 0 as n grows as we have $\\mathcal{C}_{Q}^{D}>0.64$ for any value $n > 0$ . Thus, the C-bound does not possess the property stated by Corollary 2.\n\nIn other words, the result of said corollary is incorrect as we have now given a counterexample. Since the only argument in the demonstration of the corollary is the use of Proposition 1, this implies that Proposition 1 is also incorrect.", "context": [{"id": "v24-22-0747:ctx1", "name": "Setup: binary classification, voters, weighted majority vote, Bayes and Gibbs risk (Section 2, eq. 1)", "statement": "Throughout this paper, we employ the same notation and definitions used by Germain et al. (2015) unless specified otherwise. That is, we consider a binary classification problem in which each example $(x,y)$ consists of an input x and output y belonging to the spaces $\\mathcal{X}$ and $\\mathcal{Y}=\\{-1,1\\}$ respectively. The examples are sampled i.i.d. according to a true unknown distribution D over $\\mathcal{X}\\times\\{-1,1\\}$ . We consider $\\mathcal{H}$, a finite set of functions $f:\\mathcal{X}\\to [-1,1]$. Each such $f$ defines a \"voter\" in the context of majority vote rules. One may see the output of a given voter $f$ as a measurement of the confidence of the voter toward a given label. For example, say we have two voters $f_{1}(x)=0.1$ and $f_{2}(x)=0.9$ , then both voters lean towards the label 1, but the former less confidently then the latter.\n\nA weighted majority vote is defined by a distribution $Q$ over $\\mathcal{H}.$ Such a distribution defines the weight given to each voter, denoted $Q(f)$ , which gives rise to the majority vote classifier $B_{Q}(x)=\\mathrm{sgn}\\left[\\mathbf{E}_{f\\sim Q}f(x)\\right]$ . This majority vote is also called the Bayes classifier$^{1}$ in the PAC-Bayesian literature, as opposed to the stochastic Gibbs Classifier $G_{Q}$; with $\\begin{array}{r}{\\operatorname*{Pr}(G_{Q}(x)=y)=\\frac{1}{2}(1+y\\mathbf{E}_{f\\sim Q}f(x))}\\end{array}$ for $y\\in\\{-1,1\\}$ . The probability that the majority vote will make an incorrect prediction of the output for a given example drawn from distribution D is called the risk of the majority vote, or Bayes risk$^{2}$, and is denoted $R_{D}(B_{Q})$ :\n\n$$\nR_{D}(B_{Q})=\\operatorname*{Pr}_{(x,y)\\sim D}(B_{Q}(x)\\neq y)=\\underset{(x,y)\\sim D}{\\mathbf{E}}I\\left(\\underset{f\\sim Q}{\\mathbf{E}}yf(x)\\leq 0\\right),\n$$\n\nwhere $I(\\cdot)$ is the indicator function taking value 0 if the input is false and 1 otherwise. Correspondingly, the probability that the Gibbs classifier makes an error is called the Gibbs risk and is denoted $R_{D}(G_{Q})$ :\n\n$$\nR_{D}(G_{Q})=\\operatorname*{Pr}_{(x,y)\\sim D}(G_{Q}(x)\\neq y)=\\underset{(x,y)\\sim D}{\\mathbf{E}}\\left(\\frac{1}{2}-\\frac{1}{2}\\underset{f\\sim Q}{\\mathbf{E}}yf(x)\\right).\n$$"}, {"id": "v24-22-0747:ctx2", "name": "Margin, its moments, and the C-bound (Section 2; Lacasse et al. 2006 / Germain et al. 2015)", "statement": "The term $\\mathbf{E}_{f\\sim Q}yf(x)$ shared by both Bayes risk and Gibbs risk definitions is a commonly occurring expression in the context of majority votes. It is referred to as the margin of the majority vote and is denoted $M_{Q}(x,y)$ . Given that $(x,y){\\sim}D$ , Germain et al. (2015) study the margin as a random variable which they denote $M_{Q}^{D}$ . A longstanding intermediate result in PAC-Bayes analyses is the factor two bound between the Bayes Risk and the Gibbs risk (Langford and Shawe-Taylor, 2002; McAllester, 2003). That is, for fixed distributions D and $Q$, we have $R_{D}(B_{Q})\\leq 2R_{D}(G_{Q})$ . The C-bound (Lacasse et al., 2006; Germain et al., 2015) is a finer upper bound on the Bayes risk and is defined using the variance and first two moments of the margin $M_{Q}^{D}$ (denoted $\\mu_{1}(M_{Q}^{D})$ and $\\mu_{2}(M_{Q}^{D})$ respectively, with $\\mu_{i}(M_{Q}^{D})={\\bf E}_{(x,y)\\sim D}[M_{Q}(x,y)]^{i})$ . Equivalently, the C-bound can be expressed in terms of the Gibbs risk $R_{D}(G_{Q})$ and the expected disagreement (denoted $d_{Q}^{D}$ and defined below):\n\n$$\nR_{D}(B_{Q})\\leq{\\mathcal C}_{Q}^{D}=\\frac{\\mathbf{Var}(M_{Q}^{D})}{\\mu_{2}(M_{Q}^{D})}=1-\\frac{\\left(\\mu_{1}(M_{Q}^{D})\\right)^{2}}{\\mu_{2}(M_{Q}^{D})}=1-\\frac{(1-2 R_{D}(G_{Q}))^{2}}{1-2 d_{Q}^{D}},\n$$\n\nwhere\n\n$$\n\\begin{array}{c c}{{\\displaystyle\\mu_{1}\\big(M_{Q}^{D}\\big)=\\underset{(x,y)\\sim D}{\\mathbf{E}}\\,\\underset{f\\sim Q}{\\mathbf{E}}y f(x),}}&{{\\qquad\\mu_{2}\\big(M_{Q}^{D}\\big)=\\underset{x\\sim D_{\\mathcal{X}}}{\\mathbf{E}}\\left[\\underset{f\\sim Q}{\\mathbf{E}}f(x)\\right]^{2},}}\\\\ {{\\displaystyle{\\mathbf{Var}\\big(M_{Q}^{D}\\big)=\\mu_{2}\\big(M_{Q}^{D}\\big)-\\big(\\mu_{1}\\big(M_{Q}^{D}\\big)\\big)^{2},}}}&{{\\qquad d_{Q}^{D}=\\frac{1}{2}\\left(1-\\mu_{2}\\big(M_{Q}^{D}\\big)\\right).}}\\end{array}\n$$\n\nIn these definitions, $D_{\\mathcal{X}}$ denotes the marginal distribution on $\\mathcal{X}$ for a given distribution $D .^{1}$ We adopt this notation throughout the paper, as well as the use of $D_{\\mathcal{Y}| x}$ to denote the conditional distribution on the output space $\\mathcal{Y}$ given a fixed input $x \\in \\mathcal{X}$"}, {"id": "v24-22-0747:ctx3", "name": "Sources of stochasticity: label noise, stochastic voters, stochastic majority vote (Section 2)", "statement": "An important note has to be made about the notions of stochasticity and determinism as they appear in the original paper. The generic use of these terms can be confusing to the reader as it is sometimes unclear what is meant to be stochastic or deterministic in some passages. To alleviate this ambiguity we differentiate three distinct sources of stochasticity that are of importance in the studied framework.\n\nLabel noise. The stochasticity of the labels arises when for a given value of $x \\sim D_{\\mathcal{X}}$ , there is a non-zero probability of observing more than one value of $y \\sim D_{\\mathcal{Y}| x}$.\n\nStochastic voters. Of note, Germain et al. (2015) introduced voters as functions of the form $f:\\mathcal{X}\\to [-1,1]$, implying they were deterministic predictors. Nevertheless, the property that a given voter is deterministic remains unused in their analysis of majority votes. We may wish to consider stochastic voters, such as voters for which the output follows some distribution. Say we consider a stochastic voter $f^{*}$ such that for any given input $x,$ the output of the voter is a random variable $f^{*}(x)\\sim W_{x}$ , where $W_{x}$ is a distribution over [−1, 1] that depends of the value $x .$ To apply the work of Germain et al. (2015), one needs only to consider $f(x)$ as the expected output of the stochastic voter $f^{*}$ given by $f(x)=\\mathbf{E}_{f^{*}(x)\\sim W_{x}}~f^{*}(x)$ . Doing so, the value $f(x)$ will be deterministic. Moreover, this is coherent with the idea that $f(x)$ is the confidence of the voter towards a given label. The discussion in this erratum henceforth encompasses both deterministic and stochastic voters and we use the general term voter to refer to voters of both natures.\n\nStochastic majority vote. We specified that the Bayes classifier $B_{Q}$ is deterministic while the Gibbs classifier $G_{Q}$ is stochastic. This distinction, made by Germain et al. (2015), is meant to distinguish between the stochasticity that arises from sampling a single voter (Gibbs) as opposed to averaging over the value of each voter $f \\in \\mathcal H$ (Bayes). It is not meant to refer to the nature of the individual voters as we remind that both Germain et al. (2015) and this erratum consider deterministic voters only.\n\nWe remind that this erratum is valid when considering the deterministic majority vote classifier that embed the expected value of its voters for the Bayes risk of Equation (1). The interested reader may note that the recent work of Zantedeschi et al. (2021) provide PAC-Bayes bounds for stochastic majority votes where the voters weights are random variables. While this is a related line of work, it differs from ours and Germain et al. (2015) as we only consider majority votes for which the weight of each voter is fixed."}, {"id": "v24-22-0747:ctx4", "name": "Proposition 1 (Proposition 15 in Germain et al. 2015; erroneous)", "statement": "## Erroneous result\n\nProposition 1 (Proposition 15 in Germain et al. (2015)) For any countable set of voters $\\mathcal{H}$, any distribution Q on $\\mathcal{H}$, and any distribution D on $\\mathcal{X}\\times\\{-1,1\\}$ , we have\n\n$$\n\\mathbf{Var}(M_{Q}^{D})\\leq\\sum_{f\\in\\mathcal{H}}Q^{2}(f)+\\sum_{f_{1}\\in\\mathcal{H}}\\sum_{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}Q(f_{1})Q(f_{2})\\mathbf{Cov}_{(x,y)\\sim D}(f_{1}(x),f_{2}(x)).\n$$"}, {"id": "v24-22-0747:ctx5", "name": "Original proof of Proposition 1 (Germain et al. 2015) and its flaw", "statement": "Proof We begin with the definition of the margin, which can be seen as a sum of random variables, and develop the variance of the sum into the sum of covariances:\n\n$$\n\\mathbf{Var}\\left(M_{Q}^{D}\\right)=\\mathbf{Var}_{(x,y)\\sim D}\\left(M_{Q}(x,y)\\right)\n$$\n\n$$\n=\\underset{(x,y)\\sim D}{\\mathbf{Var}}\\left(\\sum_{f\\in\\mathcal{H}}Q(f)y f(x)\\right)\n$$\n\n$$\n\\begin{array}{r l}&{=\\displaystyle\\sum_{f\\in\\mathcal{H}}Q^{2}(f)\\underset{(x,y)\\sim D}{\\mathbf{Var}}y f(x)+\\displaystyle\\sum_{f_{1}\\in\\mathcal{H}}\\displaystyle\\sum_{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}Q(f_{1})Q(f_{2})\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(y f_{1}(x),y f_{2}(x))}\\\\ &{=\\displaystyle\\sum_{f\\in\\mathcal{H}}Q^{2}(f)\\underset{(x,y)\\sim D}{\\mathbf{Var}}y f(x)+\\displaystyle\\sum_{f_{1}\\in\\mathcal{H}}\\displaystyle\\sum_{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}Q(f_{1})Q(f_{2})\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(f_{1}(x),f_{2}(x))}\\\\ &{\\leq\\displaystyle\\sum_{f\\in\\mathcal{H}}Q^{2}(f)+\\displaystyle\\sum_{f_{1}\\in\\mathcal{H}}\\displaystyle\\sum_{f_{2}\\in\\mathcal{H}\\atop f_{2}\\neq f_{1}}Q(f_{1})Q(f_{2})\\underset{(x,y)\\sim D}{\\mathbf{Cov}}(f_{1}(x),f_{2}(x)).}\\end{array}\n$$\n\nThe inequality is given by the fact that the definitions of $y$ and $f(x)$ implie $yf(x)\\in [-1,1]$, from which we infer that $\\underset{(x,y)\\sim D}{\\mathbf{Var}}{y f(x)}\\leq 1$ for all voters $f \\in{\\mathcal{H}}$.\n\nThe problem in this demonstration arises when we simplify $\\mathbf{Cov}_{(x,y)\\sim D}\\left(y f_{1}(x),y f_{2}(x)\\right)$ to $\\mathbf{Cov}_{(x,y)\\sim D}\\left(f_{1}(x),f_{2}(x)\\right)$ , which could also be written as $\\mathbf{Cov}_{x\\sim D_{\\mathcal{X}}}\\left(f_{1}(x),f_{2}(x)\\right)$ . As this final writing is independent of y, this equality would imply that the value y has no effect in the expression $\\mathbf{Cov}_{(x,y)\\sim D}\\left(y f_{1}(x),y f_{2}(x)\\right)$ . This simplification does not stand in the general case as it is possible to find various examples of functions $f_{i}$ and distributions D that do not satisfy this equality. As an example, consider $f_{1}(x)=1,f_{2}(x)= -1$ and $\\operatorname*{Pr}_{y\\sim D_{\\mathcal{Y}|x}}(y{=}1)=\\operatorname*{Pr}_{y\\sim D_{\\mathcal{Y}|x}}(y{=}-1)=\\textstyle\\frac{1}{2}$ for any given value $x \\in \\mathcal{X}$ . Using these values, we get the following, which disproves the equality assumed in the said simplification:\n\n$$\n\\begin{array}{r}{\\mathbf{Cov}(f_{1}(x),f_{2}(x))=\\mathbf{Cov}(1,-1)=0\\qquad}\\\\ {\\mathbf{Cov}(y f_{1}(x),y f_{2}(x))=\\mathbf{Cov}(y,-y)= -\\mathbf{Cov}(y,y)= -1 .}\\end{array}\n$$"}, {"id": "v24-22-0747:ctx6", "name": "Corollary 2 (Corollary 16 in Germain et al. 2015; erroneous) and its motivation", "statement": "Even though the demonstration of Proposition 1 is flawed, this does not necessarily imply that the proposition itself does not stand. In principle, the proposition might be valid due to a different argument. However, in order to show that Proposition 15 of Germain et al. (2015) is indeed false, we introduce the following corollary. If Proposition 1 were true, then so would Corollary 2 which follows directly from it.\n\n## Erroneous result\n\nCorollary 2 (Corollary 16 in Germain et al. (2015)) Given n independent voters under a uniform distribution $Q,$ we have\n\n$$\nR_{D}(B_{Q})\\leq\\mathcal{C}_{Q}^{D}\\leq\\frac{1}{n(1-2d_{Q}^{D})}=\\frac{1}{n(1-2R_{D}(G_{Q}))}.\n$$\n\nTo prove the above corollary, Germain et al. (2015) note that under the hypothesis that the n voters are independents under a uniform distribution, Proposition 1 implies that $\\mathbf{Var}(M_{Q}^{D})\\leq 1/n;$ the result then follows from the definition of the C-bound.\n\nAt first glance, the corollary seems intuitive. Increasing the number of voters should improve the quality of the classification. Therefore, we would expect the C-bound to decrease. The main problem with this result is that it implies that as the number of independent voters n goes to infinity, the right side goes to 0. This means that for any binary classification problem, the risk of the majority vote can be made arbitrarily small by using a sufficiently large set of independent voters. Though this may seem like a desirable property, it is not realistic in the presence of label noise. In such case, the noise associated with the output y given a certain x will induce a minimum amount of erroneous classification (i.e., irreducible error). Notice that the label noise is an inherent property of a given distribution D, and the irreducible error (also known as Bayes error in the literature) is achieved by an optimal prediction rule for D. This irreducible error is not 0 in the presence of label noise, which contradicts the statement of Corollary 2. To clearly illustrate this contradiction, consider the following example."}, {"id": "v24-22-0747:ctx7", "name": "Assumptions 1-2: deterministic labels and sufficiently accurate voters (Section 5)", "statement": "We have now shown that Proposition 1 is incorrect as stated in the general case, namely when the labelling task includes label noise. The aim of the current section is to rectify Proposition 1 in a setting devoid of label noise, by introducing new assumptions on the data distribution and the voters. In the following section we build upon this knowledge a new, correct and improved result that stands in the general case.\n\nEven though the assumption that a given problem is devoid of label noise might not be realistic in most applications, we can see this case as an easy classification problem where an error of 0 should be achievable for some classifier. Given this assumption, we would thus desire a majority vote made with \"good enough\" voters to come arbitrarily close to null classification error. Moreover, we would expect a good bound on the risk of majority votes to reflect this fact by being potentially arbitrarily small in this setting.\n\nWe begin by noting that the assumption that distribution D is devoid of label noise implies that there exists a function that maps each input x to its correct label.\n\nAssumption 1: Deterministic labels. The data distribution D is such that there exists a function $g:\\mathcal{X}\\to\\{-1,1\\}$ for which $y=g(x)$ for all $(x,y)\\sim D$ , or equivalently $\\operatorname*{Pr}_{y\\sim D_{\\mathcal{Y}|x}}\\left(y{=}g(x)\\right)=1$ for all $x \\in \\mathcal{X}$\n\nThe counter-example of the previous section also illustrates that uncorrelated voters do not necessarily result in an accurate majority vote, as it does not imply that the input-output correlation is taken into account. Thus, we need a second assumption, capturing the fact that the majority vote must be made of \"good enough\" voters. Namely, we want each voter to classify this input correctly with a probability larger than $1 / 2$\n\nAssumption 2: Sufficiently accurate voters. For any given pair $(x,y)\\sim D$ , for any voter $f_{i}\\in\\mathcal{H},yf_{i}(x)>0;$ in other words, all voters are leaning towards the right label (although with scores, i.e., varying confidence levels) in a non ambivalent manner (i.e., $f_{i}(x)\\neq 0)$\n\nGiven the definition of a voter $f_{i}$, Assumption 2 implies that for any given input $x$ in $\\mathcal{X}$ and any given voter $f_{i}$ in $\\mathcal{H}$ , the expected output of $f_{i}(x)$ will agree with the true value of $y,$ meaning they will share the same sign. This assumption is very strong, as it will break when a single voter does not classify a given x with sufficient probability. It may seem trivial that under this assumption the majority vote will be correct every time and will thus have an actual risk of 0. Recall however that the majority vote risk $R_{D}(B_{Q})$ only considers the sign of the margin $[y\\,\\mathbf{E}_{f\\sim Q}f(x)]$ on $(x,y)\\sim D$ while the computation of the C-bound depends on the value of the margin itself. In other words, the risk $R_{D}(B_{Q})$ depends on which label the majority vote is most confident in but the C-bound further considers how confident the vote is. This implies that various majority votes which make the same prediction (same risk $R_{D}(B_{Q}))$ may have different C-bound as they may have different margins. Therefore, the C-bound is not trivially 0 under the above assumptions.\n\nWe now show that an updated Proposition 1 holds given these two new assumptions, namely that the labels are deterministic and the voters are sufficiently accurate."}, {"id": "v24-22-0747:ctx8", "name": "Section 6 introduction (goal of Proposition 4)", "statement": "The counter-example given in Section 4 was based on the knowledge that the risk of the majority vote should never be inferior to minimal risk induced by the label noise in D. We have shown in Section 5 that the C-bound can converge to the minimal risk in a setting deprived of label noise by proving that in such a setting, using voters of sufficient quality renders Corrolary 2 true. In this section, we aim to generalise this result to problems which contain label noise. To do so, we introduce in Proposition 4 a theoretical lower-bound for the C-bound for a given distribution D as well as the majority vote which achieves this bound."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace ResearchLevel\n\nnoncomputable def cMu1 {X : Type*} [MeasurableSpace X] (μ : Measure X) (h S : X → ℝ) : ℝ :=\n ∫ x, h x * S x ∂μ\n\nnoncomputable def cMu2 {X : Type*} [MeasurableSpace X] (μ : Measure X) (S : X → ℝ) : ℝ :=\n ∫ x, (S x) ^ 2 ∂μ\n\nnoncomputable def cBound {X : Type*} [MeasurableSpace X] (μ : Measure X) (h S : X → ℝ) : ℝ :=\n 1 - (cMu1 μ h S) ^ 2 / (cMu2 μ S)\n\nnoncomputable def labelVarMean {X : Type*} [MeasurableSpace X] (μ : Measure X) (h : X → ℝ) : ℝ :=\n ∫ x, (1 - (h x) ^ 2) ∂μ\n\nnoncomputable def condErr (hx sx : ℝ) : ℝ :=\n if 0 < sx then (1 - hx) / 2 else if sx < 0 then (1 + hx) / 2 else 1\n\nnoncomputable def riskD {X : Type*} [MeasurableSpace X] (μ : Measure X) (h S : X → ℝ) : ℝ :=\n ∫ x, condErr (h x) (S x) ∂μ\n\nnoncomputable def margin {Ω X ι : Type*} (Q : ι → ℝ) (f : ι → X → ℝ)\n (xx : Ω → X) (yy : Ω → ℝ) : Ω → ℝ :=\n fun ω => yy ω * ∑' i, Q i * f i (xx ω)\n\nnoncomputable def aggVote {Ω : Type*} (n : ℕ) (V : Fin n → Ω → ℝ) : Ω → ℝ :=\n fun ω => (n : ℝ)⁻¹ * ∑ i, V i ω\n\ntheorem prop4 {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ]\n (h : X → ℝ) (hh_meas : Measurable h) (hh_bdd : ∀ x, |h x| ≤ 1) :\n (∃ S : X → ℝ, Measurable S ∧ (∀ x, |S x| ≤ 1) ∧ 0 < cMu2 μ S ∧\n riskD μ h S ≤ cBound μ h S ∧\n cBound μ h S = labelVarMean μ h) ∧\n (∀ S : X → ℝ, Measurable S → (∀ x, |S x| ≤ 1) → 0 < cMu2 μ S →\n labelVarMean μ h ≤ cBound μ h S) := by\n sorry\n\ntheorem prop3 {Ω X ι : Type*} [MeasurableSpace Ω] [MeasurableSpace X] [Countable ι]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (Q : ι → ℝ) (hQ_nonneg : ∀ i, 0 ≤ Q i) (hQ_summable : Summable Q) (hQ_sum : ∑' i, Q i = 1)\n (f : ι → X → ℝ) (hf_bdd : ∀ i x, |f i x| ≤ 1)\n (xx : Ω → X) (yy : Ω → ℝ) (hy : ∀ᵐ ω ∂P, yy ω = 1 ∨ yy ω = -1)\n (g : X → ℝ) (hdet : ∀ᵐ ω ∂P, yy ω = g (xx ω))\n (hacc : ∀ i, ∀ᵐ ω ∂P, 0 < yy ω * f i (xx ω))\n (hmeas_x : Measurable xx) (hmeas_y : Measurable yy)\n (hmeas_f : ∀ i, Measurable (f i)) :\n Var[margin Q f xx yy; P]\n ≤ (∑' i, (Q i) ^ 2)\n + ∑' i, ∑' j : {j // j ≠ i},\n Q i * Q (j : ι) * cov[fun ω => f i (xx ω), fun ω => f (j : ι) (xx ω); P] := by\n sorry\n\ntheorem cbound_counterexample {Ω : Type*} [MeasurableSpace Ω]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (n : ℕ) (hn : 0 < n) (V : Fin n → Ω → ℝ) (Y : Ω → ℝ)\n (hVint : ∀ i, Integrable (V i) P)\n (hVcrossint : ∀ i j, Integrable (fun ω => V i ω * V j ω) P)\n (hYint : Integrable Y P)\n (hYSint : Integrable (fun ω => Y ω * aggVote n V ω) P)\n (hV1 : ∀ i, ∫ ω, V i ω ∂P = 3 / 5)\n (hV2 : ∀ i, ∫ ω, (V i ω) ^ 2 ∂P = 1)\n (hVuncorr : ∀ i j, i ≠ j → ∫ ω, V i ω * V j ω ∂P = 9 / 25)\n (hY1 : ∫ ω, Y ω ∂P = 3 / 5)\n (hYsq : ∀ ω, (Y ω) ^ 2 = 1)\n (hYindep : ∫ ω, Y ω * aggVote n V ω ∂P\n = (∫ ω, Y ω ∂P) * (∫ ω, aggVote n V ω ∂P))\n (X : Type*) [MeasurableSpace X] (xx : Ω → X) (v : Fin n → X → ℝ)\n (hVroute : ∀ i ω, V i ω = v i (xx ω))\n (hv_pm : ∀ i x, v i x = 1 ∨ v i x = -1)\n (hv_meas : ∀ i, Measurable (v i))\n (hVindep : ProbabilityTheory.iIndepFun V P)\n (hYXindep : ProbabilityTheory.IndepFun Y xx P) :\n cBound P Y (aggVote n V) = (400 + 144 * (n : ℝ)) / (400 + 225 * (n : ℝ))\n ∧ (16 : ℝ) / 25 < cBound P Y (aggVote n V) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace ResearchLevel\n\nnoncomputable def cMu1 {X : Type*} [MeasurableSpace X] (μ : Measure X) (h S : X → ℝ) : ℝ :=\n ∫ x, h x * S x ∂μ\n\nnoncomputable def cMu2 {X : Type*} [MeasurableSpace X] (μ : Measure X) (S : X → ℝ) : ℝ :=\n ∫ x, (S x) ^ 2 ∂μ\n\nnoncomputable def cBound {X : Type*} [MeasurableSpace X] (μ : Measure X) (h S : X → ℝ) : ℝ :=\n 1 - (cMu1 μ h S) ^ 2 / (cMu2 μ S)\n\nnoncomputable def labelVarMean {X : Type*} [MeasurableSpace X] (μ : Measure X) (h : X → ℝ) : ℝ :=\n ∫ x, (1 - (h x) ^ 2) ∂μ\n\nnoncomputable def condErr (hx sx : ℝ) : ℝ :=\n if 0 < sx then (1 - hx) / 2 else if sx < 0 then (1 + hx) / 2 else 1\n\nnoncomputable def riskD {X : Type*} [MeasurableSpace X] (μ : Measure X) (h S : X → ℝ) : ℝ :=\n ∫ x, condErr (h x) (S x) ∂μ\n\nnoncomputable def margin {Ω X ι : Type*} (Q : ι → ℝ) (f : ι → X → ℝ)\n (xx : Ω → X) (yy : Ω → ℝ) : Ω → ℝ :=\n fun ω => yy ω * ∑' i, Q i * f i (xx ω)\n\nnoncomputable def aggVote {Ω : Type*} (n : ℕ) (V : Fin n → Ω → ℝ) : Ω → ℝ :=\n fun ω => (n : ℝ)⁻¹ * ∑ i, V i ω\n\nprivate lemma integral_mul_sq_le_sq_integral_sq {X : Type*} [MeasurableSpace X]\n (μ : Measure X) (f g : X → ℝ)\n (hf2 : Integrable (fun x => (f x) ^ 2) μ)\n (hg2 : Integrable (fun x => (g x) ^ 2) μ)\n (hfg : Integrable (fun x => f x * g x) μ)\n (hgpos : 0 < ∫ x, (g x) ^ 2 ∂μ) :\n (∫ x, f x * g x ∂μ) ^ 2\n ≤ (∫ x, (f x) ^ 2 ∂μ) * (∫ x, (g x) ^ 2 ∂μ) := by\n let A : ℝ := ∫ x, (f x) ^ 2 ∂μ\n let B : ℝ := ∫ x, (g x) ^ 2 ∂μ\n let C : ℝ := ∫ x, f x * g x ∂μ\n have ht1 : Integrable (fun x => B ^ 2 * (f x) ^ 2) μ := hf2.const_mul _\n have ht2 : Integrable (fun x => (2 * B * C) * (f x * g x)) μ := hfg.const_mul _\n have ht3 : Integrable (fun x => C ^ 2 * (g x) ^ 2) μ := hg2.const_mul _\n have hexpand :\n (fun x => (B * f x - C * g x) ^ 2) =\n (fun x => B ^ 2 * (f x) ^ 2 - (2 * B * C) * (f x * g x) +\n C ^ 2 * (g x) ^ 2) := by\n funext x\n ring\n have heval :\n (∫ x, (B * f x - C * g x) ^ 2 ∂μ) = B * (B * A - C ^ 2) := by\n rw [hexpand]\n calc\n (∫ x, B ^ 2 * (f x) ^ 2 - (2 * B * C) * (f x * g x) +\n C ^ 2 * (g x) ^ 2 ∂μ) =\n (∫ x, B ^ 2 * (f x) ^ 2 - (2 * B * C) * (f x * g x) ∂μ) +\n ∫ x, C ^ 2 * (g x) ^ 2 ∂μ := by\n exact integral_add (ht1.sub ht2) ht3\n _ = ((∫ x, B ^ 2 * (f x) ^ 2 ∂μ) -\n ∫ x, (2 * B * C) * (f x * g x) ∂μ) +\n ∫ x, C ^ 2 * (g x) ^ 2 ∂μ := by\n rw [integral_sub ht1 ht2]\n _ = B * (B * A - C ^ 2) := by\n simp only [integral_const_mul]\n ring\n have hnonneg : 0 ≤ ∫ x, (B * f x - C * g x) ^ 2 ∂μ :=\n integral_nonneg (fun x => sq_nonneg _)\n have hfactor : 0 ≤ B * (B * A - C ^ 2) := heval ▸ hnonneg\n have hcore : 0 ≤ B * A - C ^ 2 :=\n nonneg_of_mul_nonneg_right hfactor (by simpa [B] using hgpos)\n simpa [A, B, C, mul_comm] using (sub_nonneg.mp hcore)\n\nprivate lemma condErr_nonneg_of_abs_le_one (a b : ℝ) (ha : |a| ≤ 1) :\n 0 ≤ condErr a b := by\n rcases abs_le.mp ha with ⟨haL, haU⟩\n unfold condErr\n split_ifs <;> linarith\n\nprivate lemma condErr_le_one_of_abs_le_one (a b : ℝ) (ha : |a| ≤ 1) :\n condErr a b ≤ 1 := by\n rcases abs_le.mp ha with ⟨haL, haU⟩\n unfold condErr\n split_ifs <;> linarith\n\nprivate lemma condErr_self_le_one_sub_sq (a : ℝ) (ha : |a| ≤ 1) :\n condErr a a ≤ 1 - a ^ 2 := by\n rcases abs_le.mp ha with ⟨haL, haU⟩\n unfold condErr\n split_ifs with hp hn\n · nlinarith [mul_nonneg (sub_nonneg.mpr haU) (by linarith : 0 ≤ a + 1)]\n · nlinarith [mul_nonneg (by linarith : 0 ≤ 1 - a) (by linarith : 0 ≤ a + 1)]\n · have : a = 0 := by linarith\n simp [this]\n\nprivate lemma measurable_condErr_comp {X : Type*} [MeasurableSpace X]\n {h S : X → ℝ} (hh : Measurable h) (hS : Measurable S) :\n Measurable (fun x => condErr (h x) (S x)) := by\n unfold condErr\n apply Measurable.ite\n · exact measurableSet_lt measurable_const hS\n · fun_prop\n · apply Measurable.ite\n · exact measurableSet_lt hS measurable_const\n · fun_prop\n · exact measurable_const\n\nprivate lemma integrable_bounded_one {X : Type*} [MeasurableSpace X]\n (μ : Measure X) [IsFiniteMeasure μ] {f : X → ℝ}\n (hf : Measurable f) (hb : ∀ x, |f x| ≤ 1) : Integrable f μ := by\n apply Integrable.of_bound hf.aestronglyMeasurable 1\n filter_upwards [] with x\n simpa [Real.norm_eq_abs] using hb x\n\nprivate lemma integrable_sq_bounded_one {X : Type*} [MeasurableSpace X]\n (μ : Measure X) [IsFiniteMeasure μ] {f : X → ℝ}\n (hf : Measurable f) (hb : ∀ x, |f x| ≤ 1) :\n Integrable (fun x => (f x) ^ 2) μ := by\n apply Integrable.of_bound (hf.pow_const 2).aestronglyMeasurable 1\n filter_upwards [] with x\n rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)]\n rcases abs_le.mp (hb x) with ⟨hL, hU⟩\n nlinarith [sq_nonneg (f x - 1), sq_nonneg (f x + 1)]\n\nprivate lemma integrable_mul_bounded_one {X : Type*} [MeasurableSpace X]\n (μ : Measure X) [IsFiniteMeasure μ] {f g : X → ℝ}\n (hf : Measurable f) (hg : Measurable g)\n (hfb : ∀ x, |f x| ≤ 1) (hgb : ∀ x, |g x| ≤ 1) :\n Integrable (fun x => f x * g x) μ := by\n apply Integrable.of_bound (hf.mul hg).aestronglyMeasurable 1\n filter_upwards [] with x\n rw [Real.norm_eq_abs, abs_mul]\n nlinarith [abs_nonneg (f x), abs_nonneg (g x), hfb x, hgb x]\n\nprivate lemma integrable_condErr_comp {X : Type*} [MeasurableSpace X]\n (μ : Measure X) [IsFiniteMeasure μ] {h S : X → ℝ}\n (hh : Measurable h) (hS : Measurable S) (hb : ∀ x, |h x| ≤ 1) :\n Integrable (fun x => condErr (h x) (S x)) μ := by\n apply Integrable.of_bound (measurable_condErr_comp hh hS).aestronglyMeasurable 1\n filter_upwards [] with x\n rw [Real.norm_eq_abs, abs_of_nonneg (condErr_nonneg_of_abs_le_one _ _ (hb x))]\n exact condErr_le_one_of_abs_le_one _ _ (hb x)\n\nprivate lemma abs_integral_le_one {X : Type*} [MeasurableSpace X]\n (μ : Measure X) [IsProbabilityMeasure μ] {f : X → ℝ}\n (hf : Measurable f) (hb : ∀ x, |f x| ≤ 1) :\n |∫ x, f x ∂μ| ≤ 1 := by\n have hfi : Integrable f μ := integrable_bounded_one μ hf hb\n calc\n |∫ x, f x ∂μ| = ‖∫ x, f x ∂μ‖ := rfl\n _ ≤ ∫ x, ‖f x‖ ∂μ := norm_integral_le_integral_norm f\n _ ≤ ∫ _x : X, (1 : ℝ) ∂μ := by\n apply integral_mono hfi.norm (integrable_const 1)\n intro x\n simpa [Real.norm_eq_abs] using hb x\n _ = 1 := by simp\n\ntheorem prop4 {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ]\n (h : X → ℝ) (hh_meas : Measurable h) (hh_bdd : ∀ x, |h x| ≤ 1) :\n (∃ S : X → ℝ, Measurable S ∧ (∀ x, |S x| ≤ 1) ∧ 0 < cMu2 μ S ∧\n riskD μ h S ≤ cBound μ h S ∧\n cBound μ h S = labelVarMean μ h) ∧\n (∀ S : X → ℝ, Measurable S → (∀ x, |S x| ≤ 1) → 0 < cMu2 μ S →\n labelVarMean μ h ≤ cBound μ h S) := by\n have hh_int : Integrable h μ := integrable_bounded_one μ hh_meas hh_bdd\n have hh2_int : Integrable (fun x => (h x) ^ 2) μ :=\n integrable_sq_bounded_one μ hh_meas hh_bdd\n have hlabel_int : Integrable (fun x => 1 - (h x) ^ 2) μ :=\n (integrable_const 1).sub hh2_int\n have hlabel : labelVarMean μ h = 1 - cMu2 μ h := by\n rw [labelVarMean, cMu2, integral_sub (integrable_const 1) hh2_int]\n simp\n have hh2_nonneg : 0 ≤ cMu2 μ h := by\n exact integral_nonneg (fun x => sq_nonneg _)\n constructor\n · by_cases hpos : 0 < cMu2 μ h\n · refine ⟨h, hh_meas, hh_bdd, hpos, ?_, ?_⟩\n · rw [riskD]\n exact integral_mono (integrable_condErr_comp μ hh_meas hh_meas hh_bdd)\n hlabel_int (fun x => condErr_self_le_one_sub_sq (h x) (hh_bdd x))\n |>.trans_eq (by\n change labelVarMean μ h = cBound μ h h\n rw [hlabel]\n have hmom : cMu1 μ h h = cMu2 μ h := by\n simp [cMu1, cMu2, pow_two]\n rw [cBound, hmom]\n simp [pow_two, hpos.ne'])\n · rw [hlabel]\n have hmom : cMu1 μ h h = cMu2 μ h := by\n simp [cMu1, cMu2, pow_two]\n rw [cBound, hmom]\n simp [pow_two, hpos.ne']\n · have hz : cMu2 μ h = 0 := le_antisymm (le_of_not_gt hpos) hh2_nonneg\n have hh2_ae : (fun x => (h x) ^ 2) =ᵐ[μ] 0 :=\n (integral_eq_zero_iff_of_nonneg (fun x => sq_nonneg (h x)) hh2_int).mp hz\n have hh_ae : h =ᵐ[μ] 0 := by\n filter_upwards [hh2_ae] with x hx\n dsimp at hx ⊢\n nlinarith [sq_nonneg (h x)]\n have hh_mean : ∫ x, h x ∂μ = 0 := by\n rw [integral_congr_ae hh_ae]\n simp\n let S : X → ℝ := fun _ => 1\n have hS_meas : Measurable S := measurable_const\n have hS_bdd : ∀ x, |S x| ≤ 1 := by intro x; simp [S]\n have hS2 : cMu2 μ S = 1 := by simp [cMu2, S]\n have hcross : cMu1 μ h S = 0 := by simp [cMu1, S, hh_mean]\n have hcb : cBound μ h S = 1 := by simp [cBound, hcross, hS2]\n refine ⟨S, hS_meas, hS_bdd, by simp [hS2], ?_, ?_⟩\n · rw [hcb, riskD]\n have hone_int : Integrable (fun _ : X => (1 : ℝ)) μ := integrable_const 1\n have := integral_mono (integrable_condErr_comp μ hh_meas hS_meas hh_bdd)\n hone_int (fun x => condErr_le_one_of_abs_le_one (h x) (S x) (hh_bdd x))\n simpa using this\n · rw [hcb, hlabel, hz]\n norm_num\n · intro S hS_meas hS_bdd hSpos\n have hS2_int : Integrable (fun x => (S x) ^ 2) μ :=\n integrable_sq_bounded_one μ hS_meas hS_bdd\n have hhS_int : Integrable (fun x => h x * S x) μ :=\n integrable_mul_bounded_one μ hh_meas hS_meas hh_bdd hS_bdd\n have hcs := integral_mul_sq_le_sq_integral_sq μ h S hh2_int hS2_int hhS_int hSpos\n have hdiv : (cMu1 μ h S) ^ 2 / cMu2 μ S ≤ cMu2 μ h := by\n apply (div_le_iff₀ hSpos).2\n simpa [cMu1, cMu2] using hcs\n rw [hlabel, cBound]\n linarith\n\nprivate lemma weighted_tsum_memLp_two {Ω ι : Type*} [MeasurableSpace Ω] [Countable ι]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (q : ι → ℝ) (hq_nonneg : ∀ i, 0 ≤ q i) (hq_summable : Summable q)\n (hq_sum : ∑' i, q i = 1)\n (F : ι → Ω → ℝ) (hF_meas : ∀ i, Measurable (F i))\n (hF_bdd : ∀ i ω, |F i ω| ≤ 1) :\n MemLp (fun ω => ∑' i, q i * F i ω) 2 P := by\n have hnorm_sum (ω : Ω) : Summable (fun i => ‖q i * F i ω‖) := by\n apply hq_summable.of_nonneg_of_le (fun i => norm_nonneg _)\n intro i\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hq_nonneg i)]\n exact mul_le_of_le_one_right (hq_nonneg i) (hF_bdd i ω)\n have hsum_meas : AEStronglyMeasurable (fun ω => ∑' i, q i * F i ω) P := by\n apply aestronglyMeasurable_of_tendsto_ae (Filter.atTop : Filter (Finset ι))\n · intro s\n exact s.aestronglyMeasurable_fun_sum fun i _ =>\n (hF_meas i).aestronglyMeasurable.const_mul (q i)\n · filter_upwards [] with ω\n exact (hnorm_sum ω).of_norm.hasSum\n apply MemLp.of_bound hsum_meas 1\n filter_upwards [] with ω\n calc\n ‖∑' i, q i * F i ω‖ ≤ ∑' i, ‖q i * F i ω‖ :=\n norm_tsum_le_tsum_norm (hnorm_sum ω)\n _ ≤ ∑' i, q i := by\n apply Summable.tsum_le_tsum\n · intro i\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hq_nonneg i)]\n exact mul_le_of_le_one_right (hq_nonneg i) (hF_bdd i ω)\n · exact hnorm_sum ω\n · exact hq_summable\n _ = 1 := hq_sum\n\nprivate lemma integral_weighted_tsum {Ω ι : Type*} [MeasurableSpace Ω] [Countable ι]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (q : ι → ℝ) (hq_nonneg : ∀ i, 0 ≤ q i) (hq_summable : Summable q)\n (F : ι → Ω → ℝ) (hF_meas : ∀ i, Measurable (F i))\n (hF_bdd : ∀ i ω, |F i ω| ≤ 1) :\n ∫ ω, ∑' i, q i * F i ω ∂P = ∑' i, q i * ∫ ω, F i ω ∂P := by\n have hnorm_sum (ω : Ω) : Summable (fun i => ‖q i * F i ω‖) := by\n apply hq_summable.of_nonneg_of_le (fun i => norm_nonneg _)\n intro i\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hq_nonneg i)]\n exact mul_le_of_le_one_right (hq_nonneg i) (hF_bdd i ω)\n have hhas :\n HasSum (fun i => ∫ ω, q i * F i ω ∂P)\n (∫ ω, ∑' i, q i * F i ω ∂P) := by\n apply hasSum_integral_of_dominated_convergence (fun i _ => q i)\n · intro i\n exact (hF_meas i).aestronglyMeasurable.const_mul (q i)\n · intro i\n filter_upwards [] with ω\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hq_nonneg i)]\n exact mul_le_of_le_one_right (hq_nonneg i) (hF_bdd i ω)\n · filter_upwards [] with ω\n exact hq_summable\n · exact integrable_const _\n · filter_upwards [] with ω\n exact (hnorm_sum ω).of_norm.hasSum\n calc\n (∫ ω, ∑' i, q i * F i ω ∂P) = ∑' i, ∫ ω, q i * F i ω ∂P :=\n hhas.tsum_eq.symm\n _ = ∑' i, q i * ∫ ω, F i ω ∂P := by\n apply tsum_congr\n intro i\n exact integral_const_mul (q i) (F i)\n\nprivate lemma weighted_covariance_summable {Ω ι : Type*} [MeasurableSpace Ω] [Countable ι]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (q : ι → ℝ) (hq_nonneg : ∀ i, 0 ≤ q i) (hq_summable : Summable q)\n (F : ι → Ω → ℝ) (hF_meas : ∀ i, Measurable (F i))\n (hF_bdd : ∀ i ω, |F i ω| ≤ 1) :\n Summable (fun p : ι × ι =>\n q p.1 * q p.2 * cov[F p.1, F p.2; P]) := by\n have hpair : Summable (fun p : ι × ι => q p.1 * q p.2) :=\n hq_summable.mul_of_nonneg hq_summable hq_nonneg hq_nonneg\n have hmem (i : ι) : MemLp (F i) 2 P := by\n apply MemLp.of_bound (hF_meas i).aestronglyMeasurable 1\n filter_upwards [] with ω\n simpa [Real.norm_eq_abs] using hF_bdd i ω\n apply Summable.of_norm_bounded (hpair.mul_left 2)\n intro p\n have hi := abs_integral_le_one P (hF_meas p.1) (hF_bdd p.1)\n have hj := abs_integral_le_one P (hF_meas p.2) (hF_bdd p.2)\n have hij : |∫ ω, F p.1 ω * F p.2 ω ∂P| ≤ 1 := by\n apply abs_integral_le_one P ((hF_meas p.1).mul (hF_meas p.2))\n intro ω\n rw [abs_mul]\n nlinarith [abs_nonneg (F p.1 ω), abs_nonneg (F p.2 ω),\n hF_bdd p.1 ω, hF_bdd p.2 ω]\n have hcov : |cov[F p.1, F p.2; P]| ≤ 2 := by\n rw [covariance_eq_sub (hmem p.1) (hmem p.2)]\n calc\n |(∫ ω, F p.1 ω * F p.2 ω ∂P) -\n (∫ ω, F p.1 ω ∂P) * ∫ ω, F p.2 ω ∂P| ≤\n |∫ ω, F p.1 ω * F p.2 ω ∂P| +\n |(∫ ω, F p.1 ω ∂P) * ∫ ω, F p.2 ω ∂P| := abs_sub _ _\n _ ≤ 1 + 1 := by\n gcongr\n rw [abs_mul]\n nlinarith [abs_nonneg (∫ ω, F p.1 ω ∂P),\n abs_nonneg (∫ ω, F p.2 ω ∂P)]\n _ = 2 := by norm_num\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg\n (mul_nonneg (hq_nonneg p.1) (hq_nonneg p.2))]\n simpa [mul_comm, mul_left_comm, mul_assoc] using\n (mul_le_mul_of_nonneg_left hcov\n (mul_nonneg (hq_nonneg p.1) (hq_nonneg p.2)))\n\nprivate lemma variance_weighted_tsum_eq {Ω ι : Type*} [MeasurableSpace Ω] [Countable ι]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (q : ι → ℝ) (hq_nonneg : ∀ i, 0 ≤ q i) (hq_summable : Summable q)\n (hq_sum : ∑' i, q i = 1)\n (F : ι → Ω → ℝ) (hF_meas : ∀ i, Measurable (F i))\n (hF_bdd : ∀ i ω, |F i ω| ≤ 1) :\n Var[fun ω => ∑' i, q i * F i ω; P] =\n ∑' i, ∑' j, q i * q j * cov[F i, F j; P] := by\n let S : Ω → ℝ := fun ω => ∑' i, q i * F i ω\n have hmem (i : ι) : MemLp (F i) 2 P := by\n apply MemLp.of_bound (hF_meas i).aestronglyMeasurable 1\n filter_upwards [] with ω\n simpa [Real.norm_eq_abs] using hF_bdd i ω\n have hSmem : MemLp S 2 P := by\n exact weighted_tsum_memLp_two P q hq_nonneg hq_summable hq_sum F hF_meas hF_bdd\n have hterm_norm (ω : Ω) : Summable (fun i => ‖q i * F i ω‖) := by\n apply hq_summable.of_nonneg_of_le (fun i => norm_nonneg _)\n intro i\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hq_nonneg i)]\n exact mul_le_of_le_one_right (hq_nonneg i) (hF_bdd i ω)\n have hpair_nonneg (p : ι × ι) : 0 ≤ q p.1 * q p.2 :=\n mul_nonneg (hq_nonneg p.1) (hq_nonneg p.2)\n have hpair_sum : Summable (fun p : ι × ι => q p.1 * q p.2) :=\n hq_summable.mul_of_nonneg hq_summable hq_nonneg hq_nonneg\n have hprod_meas (p : ι × ι) : Measurable (fun ω => F p.1 ω * F p.2 ω) :=\n (hF_meas p.1).mul (hF_meas p.2)\n have hprod_bdd (p : ι × ι) (ω : Ω) : |F p.1 ω * F p.2 ω| ≤ 1 := by\n rw [abs_mul]\n nlinarith [abs_nonneg (F p.1 ω), abs_nonneg (F p.2 ω),\n hF_bdd p.1 ω, hF_bdd p.2 ω]\n have hsquare (ω : Ω) :\n S ω ^ 2 = ∑' p : ι × ι, q p.1 * q p.2 * (F p.1 ω * F p.2 ω) := by\n have hmul := tsum_mul_tsum_of_summable_norm (hterm_norm ω) (hterm_norm ω)\n rw [pow_two]\n change (∑' i, q i * F i ω) * (∑' i, q i * F i ω) = _\n rw [hmul]\n apply tsum_congr\n intro p\n ring\n have hsecond :\n ∫ ω, S ω ^ 2 ∂P =\n ∑' p : ι × ι, q p.1 * q p.2 *\n ∫ ω, F p.1 ω * F p.2 ω ∂P := by\n calc\n (∫ ω, S ω ^ 2 ∂P) =\n ∫ ω, ∑' p : ι × ι,\n (q p.1 * q p.2) * (F p.1 ω * F p.2 ω) ∂P :=\n integral_congr_ae (ae_of_all P hsquare)\n _ = ∑' p : ι × ι, (q p.1 * q p.2) *\n ∫ ω, F p.1 ω * F p.2 ω ∂P :=\n integral_weighted_tsum P (fun p : ι × ι => q p.1 * q p.2)\n hpair_nonneg hpair_sum (fun p ω => F p.1 ω * F p.2 ω)\n hprod_meas hprod_bdd\n have hmean :\n ∫ ω, S ω ∂P = ∑' i, q i * ∫ ω, F i ω ∂P := by\n exact integral_weighted_tsum P q hq_nonneg hq_summable F hF_meas hF_bdd\n have hmean_norm : Summable (fun i => ‖q i * ∫ ω, F i ω ∂P‖) := by\n apply hq_summable.of_nonneg_of_le (fun i => norm_nonneg _)\n intro i\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hq_nonneg i)]\n exact mul_le_of_le_one_right (hq_nonneg i)\n (abs_integral_le_one P (hF_meas i) (hF_bdd i))\n have hmeansq :\n (∫ ω, S ω ∂P) ^ 2 =\n ∑' p : ι × ι, q p.1 * q p.2 *\n ((∫ ω, F p.1 ω ∂P) * ∫ ω, F p.2 ω ∂P) := by\n rw [hmean, pow_two,\n tsum_mul_tsum_of_summable_norm hmean_norm hmean_norm]\n apply tsum_congr\n intro p\n ring\n have hA : Summable (fun p : ι × ι =>\n q p.1 * q p.2 * ∫ ω, F p.1 ω * F p.2 ω ∂P) := by\n apply Summable.of_norm_bounded hpair_sum\n intro p\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hpair_nonneg p)]\n exact mul_le_of_le_one_right (hpair_nonneg p)\n (abs_integral_le_one P (hprod_meas p) (hprod_bdd p))\n have hB : Summable (fun p : ι × ι =>\n q p.1 * q p.2 *\n ((∫ ω, F p.1 ω ∂P) * ∫ ω, F p.2 ω ∂P)) := by\n apply Summable.of_norm_bounded hpair_sum\n intro p\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hpair_nonneg p), abs_mul]\n have hi := abs_integral_le_one P (hF_meas p.1) (hF_bdd p.1)\n have hj := abs_integral_le_one P (hF_meas p.2) (hF_bdd p.2)\n have hp : |∫ ω, F p.1 ω ∂P| * |∫ ω, F p.2 ω ∂P| ≤ 1 := by\n nlinarith [abs_nonneg (∫ ω, F p.1 ω ∂P),\n abs_nonneg (∫ ω, F p.2 ω ∂P)]\n exact mul_le_of_le_one_right (hpair_nonneg p) hp\n have hcov : Summable (fun p : ι × ι =>\n q p.1 * q p.2 * cov[F p.1, F p.2; P]) :=\n weighted_covariance_summable P q hq_nonneg hq_summable F hF_meas hF_bdd\n calc\n Var[S; P] = (∫ ω, S ω ^ 2 ∂P) - (∫ ω, S ω ∂P) ^ 2 := by\n simpa [Pi.pow_apply] using variance_eq_sub hSmem\n _ = (∑' p : ι × ι,\n q p.1 * q p.2 * ∫ ω, F p.1 ω * F p.2 ω ∂P) -\n ∑' p : ι × ι, q p.1 * q p.2 *\n ((∫ ω, F p.1 ω ∂P) * ∫ ω, F p.2 ω ∂P) := by\n rw [hsecond, hmeansq]\n _ = ∑' p : ι × ι, q p.1 * q p.2 * cov[F p.1, F p.2; P] := by\n rw [← hA.tsum_sub hB]\n apply tsum_congr\n intro p\n rw [covariance_eq_sub (hmem p.1) (hmem p.2)]\n simp only [Pi.mul_apply]\n ring\n _ = ∑' i, ∑' j, q i * q j * cov[F i, F j; P] := hcov.tsum_prod\n\ntheorem prop3 {Ω X ι : Type*} [MeasurableSpace Ω] [MeasurableSpace X] [Countable ι]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (Q : ι → ℝ) (hQ_nonneg : ∀ i, 0 ≤ Q i) (hQ_summable : Summable Q) (hQ_sum : ∑' i, Q i = 1)\n (f : ι → X → ℝ) (hf_bdd : ∀ i x, |f i x| ≤ 1)\n (xx : Ω → X) (yy : Ω → ℝ) (hy : ∀ᵐ ω ∂P, yy ω = 1 ∨ yy ω = -1)\n (g : X → ℝ) (hdet : ∀ᵐ ω ∂P, yy ω = g (xx ω))\n (hacc : ∀ i, ∀ᵐ ω ∂P, 0 < yy ω * f i (xx ω))\n (hmeas_x : Measurable xx) (hmeas_y : Measurable yy)\n (hmeas_f : ∀ i, Measurable (f i)) :\n Var[margin Q f xx yy; P]\n ≤ (∑' i, (Q i) ^ 2)\n + ∑' i, ∑' j : {j // j ≠ i},\n Q i * Q (j : ι) * cov[fun ω => f i (xx ω), fun ω => f (j : ι) (xx ω); P] := by\n let F : ι → Ω → ℝ := fun i ω => f i (xx ω)\n let S : Ω → ℝ := fun ω => ∑' i, Q i * F i ω\n have hF_meas (i : ι) : Measurable (F i) := (hmeas_f i).comp hmeas_x\n have hF_bdd (i : ι) (ω : Ω) : |F i ω| ≤ 1 := hf_bdd i (xx ω)\n have hSmem : MemLp S 2 P :=\n weighted_tsum_memLp_two P Q hQ_nonneg hQ_summable hQ_sum F hF_meas hF_bdd\n have hterm_norm (ω : Ω) : Summable (fun i => ‖Q i * F i ω‖) := by\n apply hQ_summable.of_nonneg_of_le (fun i => norm_nonneg _)\n intro i\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hQ_nonneg i)]\n exact mul_le_of_le_one_right (hQ_nonneg i) (hF_bdd i ω)\n have hS_bdd (ω : Ω) : |S ω| ≤ 1 := by\n change |∑' i, Q i * F i ω| ≤ 1\n calc\n |∑' i, Q i * F i ω| = ‖∑' i, Q i * F i ω‖ := rfl\n _ ≤ ∑' i, ‖Q i * F i ω‖ := norm_tsum_le_tsum_norm (hterm_norm ω)\n _ ≤ ∑' i, Q i := by\n apply Summable.tsum_le_tsum\n · intro i\n rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hQ_nonneg i)]\n exact mul_le_of_le_one_right (hQ_nonneg i) (hF_bdd i ω)\n · exact hterm_norm ω\n · exact hQ_summable\n _ = 1 := hQ_sum\n have hacc_all : ∀ᵐ ω ∂P, ∀ i, 0 < yy ω * F i ω := by\n apply eventually_countable_forall.mpr\n intro i\n simpa [F] using hacc i\n have hmargin_abs : margin Q f xx yy =ᵐ[P] fun ω => |S ω| := by\n filter_upwards [hy, hacc_all] with ω hyω haω\n change yy ω * (∑' i, Q i * F i ω) = |S ω|\n change yy ω * S ω = |S ω|\n rcases hyω with hy1 | hyn1\n · have hSnonneg : 0 ≤ S ω := by\n apply tsum_nonneg\n intro i\n have hFi : 0 ≤ F i ω := by\n have hi := haω i\n rw [hy1, one_mul] at hi\n exact hi.le\n exact mul_nonneg (hQ_nonneg i) hFi\n rw [hy1, one_mul, abs_of_nonneg hSnonneg]\n · have hSnonpos : S ω ≤ 0 := by\n have hneg : 0 ≤ ∑' i, -(Q i * F i ω) := by\n apply tsum_nonneg\n intro i\n have hFi : F i ω ≤ 0 := by\n have hi := haω i\n rw [hyn1, neg_one_mul] at hi\n linarith\n exact neg_nonneg.mpr (mul_nonpos_of_nonneg_of_nonpos (hQ_nonneg i) hFi)\n rw [tsum_neg] at hneg\n exact neg_nonneg.mp hneg\n rw [hyn1, neg_one_mul, abs_of_nonpos hSnonpos]\n have hM_meas : AEStronglyMeasurable (margin Q f xx yy) P := by\n change AEStronglyMeasurable (fun ω => yy ω * S ω) P\n exact hmeas_y.aestronglyMeasurable.mul hSmem.1\n have hMmem : MemLp (margin Q f xx yy) 2 P := by\n apply MemLp.of_bound hM_meas 1\n filter_upwards [hmargin_abs] with ω hm\n rw [hm, Real.norm_eq_abs, abs_abs]\n exact hS_bdd ω\n have hsq_int :\n ∫ ω, (margin Q f xx yy ω) ^ 2 ∂P = ∫ ω, (S ω) ^ 2 ∂P := by\n apply integral_congr_ae\n filter_upwards [hmargin_abs] with ω hm\n rw [hm]\n exact sq_abs (S ω)\n have hmean_eq :\n ∫ ω, margin Q f xx yy ω ∂P = ∫ ω, |S ω| ∂P :=\n integral_congr_ae hmargin_abs\n have hmean_nonneg : 0 ≤ ∫ ω, margin Q f xx yy ω ∂P := by\n rw [hmean_eq]\n exact integral_nonneg (fun ω => abs_nonneg (S ω))\n have habs_mean : |∫ ω, S ω ∂P| ≤ ∫ ω, margin Q f xx yy ω ∂P := by\n rw [hmean_eq]\n simpa [Real.norm_eq_abs] using norm_integral_le_integral_norm S\n have hmean_sq :\n (∫ ω, S ω ∂P) ^ 2 ≤ (∫ ω, margin Q f xx yy ω ∂P) ^ 2 := by\n have hmul := mul_nonneg (sub_nonneg.mpr habs_mean)\n (add_nonneg hmean_nonneg (abs_nonneg (∫ ω, S ω ∂P)))\n nlinarith [sq_abs (∫ ω, S ω ∂P)]\n have hvar_margin_score : Var[margin Q f xx yy; P] ≤ Var[S; P] := by\n rw [variance_eq_sub hMmem, variance_eq_sub hSmem]\n simp only [Pi.pow_apply]\n rw [hsq_int]\n linarith\n have hvarS : Var[S; P] =\n ∑' i, ∑' j, Q i * Q j * cov[F i, F j; P] := by\n exact variance_weighted_tsum_eq P Q hQ_nonneg hQ_summable hQ_sum\n F hF_meas hF_bdd\n have hFmem (i : ι) : MemLp (F i) 2 P := by\n apply MemLp.of_bound (hF_meas i).aestronglyMeasurable 1\n filter_upwards [] with ω\n simpa [Real.norm_eq_abs] using hF_bdd i ω\n have hvarF_le_one (i : ι) : Var[F i; P] ≤ 1 := by\n calc\n Var[F i; P] ≤ ∫ ω, (F i ω) ^ 2 ∂P := by\n simpa [Pi.pow_apply] using\n variance_le_expectation_sq (hF_meas i).aestronglyMeasurable\n _ ≤ ∫ _ω : Ω, (1 : ℝ) ∂P := by\n apply integral_mono\n (integrable_sq_bounded_one P (hF_meas i) (hF_bdd i))\n (integrable_const 1)\n intro ω\n rcases abs_le.mp (hF_bdd i ω) with ⟨hlo, hhi⟩\n nlinarith [sq_nonneg (F i ω - 1), sq_nonneg (F i ω + 1)]\n _ = 1 := by simp\n have hdiag_le (i : ι) :\n Q i * Q i * cov[F i, F i; P] ≤ (Q i) ^ 2 := by\n rw [covariance_self (hF_meas i).aemeasurable]\n simpa [pow_two] using\n (mul_le_mul_of_nonneg_left (hvarF_le_one i) (sq_nonneg (Q i)))\n have hcov_pair : Summable (fun p : ι × ι =>\n Q p.1 * Q p.2 * cov[F p.1, F p.2; P]) :=\n weighted_covariance_summable P Q hQ_nonneg hQ_summable F hF_meas hF_bdd\n have hpairQ : Summable (fun p : ι × ι => Q p.1 * Q p.2) :=\n hQ_summable.mul_of_nonneg hQ_summable hQ_nonneg hQ_nonneg\n have hdiag_inj : Function.Injective (fun i : ι => (i, i)) := by\n intro i j hij\n exact congrArg Prod.fst hij\n have hdiag_cov : Summable (fun i => Q i * Q i * cov[F i, F i; P]) := by\n simpa [Function.comp_def] using hcov_pair.comp_injective hdiag_inj\n have hdiag_Q : Summable (fun i => (Q i) ^ 2) := by\n simpa [Function.comp_def, pow_two] using hpairQ.comp_injective hdiag_inj\n let e : ((i : ι) × {j // j ≠ i}) → ι × ι :=\n fun p => (p.1, (p.2 : ι))\n have he_inj : Function.Injective e := by\n rintro ⟨i, j⟩ ⟨i', j'⟩ hp\n have hi : i = i' := congrArg Prod.fst hp\n subst i'\n have hj : (j : ι) = (j' : ι) := congrArg Prod.snd hp\n have : j = j' := Subtype.ext hj\n subst j'\n rfl\n have hoff_flat : Summable (fun p : ((i : ι) × {j // j ≠ i}) =>\n Q p.1 * Q (p.2 : ι) * cov[F p.1, F (p.2 : ι); P]) := by\n simpa [e, Function.comp_def] using hcov_pair.comp_injective he_inj\n have hoff : Summable (fun i => ∑' j : {j // j ≠ i},\n Q i * Q (j : ι) * cov[F i, F (j : ι); P]) := hoff_flat.sigma\n have hinner (i : ι) : Summable (fun j =>\n Q i * Q j * cov[F i, F j; P]) := by\n have hinj : Function.Injective (fun j : ι => (i, j)) := by\n intro j k hjk\n exact congrArg Prod.snd hjk\n simpa [Function.comp_def] using hcov_pair.comp_injective hinj\n have hsplit (i : ι) :\n (∑' j, Q i * Q j * cov[F i, F j; P]) =\n Q i * Q i * cov[F i, F i; P] +\n ∑' j : {j // j ≠ i},\n Q i * Q (j : ι) * cov[F i, F (j : ι); P] := by\n have hs := (hinner i).sum_add_tsum_subtype_compl ({i} : Finset ι)\n let ee : {x : ι // x ∉ ({i} : Finset ι)} ≃ {x : ι // x ≠ i} :=\n { toFun := fun x => ⟨x, by simpa using x.property⟩\n invFun := fun x => ⟨x, by simpa using x.property⟩\n left_inv := fun x => Subtype.ext rfl\n right_inv := fun x => Subtype.ext rfl }\n have hcomp :\n (∑' x : {x : ι // x ∉ ({i} : Finset ι)},\n Q i * Q (x : ι) * cov[F i, F (x : ι); P]) =\n ∑' x : {x : ι // x ≠ i},\n Q i * Q (x : ι) * cov[F i, F (x : ι); P] := by\n simpa [ee] using\n (Equiv.tsum_eq ee (fun x : {x : ι // x ≠ i} =>\n Q i * Q (x : ι) * cov[F i, F (x : ι); P]))\n rw [← hcomp]\n simpa using hs.symm\n have hvar_split : Var[S; P] =\n ∑' i, (Q i * Q i * cov[F i, F i; P] +\n ∑' j : {j // j ≠ i},\n Q i * Q (j : ι) * cov[F i, F (j : ι); P]) := by\n rw [hvarS]\n apply tsum_congr\n intro i\n exact hsplit i\n have hscore_rhs : Var[S; P] ≤\n (∑' i, (Q i) ^ 2) +\n ∑' i, ∑' j : {j // j ≠ i},\n Q i * Q (j : ι) * cov[F i, F (j : ι); P] := by\n rw [hvar_split, ← hdiag_Q.tsum_add hoff]\n apply Summable.tsum_le_tsum\n · intro i\n exact add_le_add (hdiag_le i) le_rfl\n · exact hdiag_cov.add hoff\n · exact hdiag_Q.add hoff\n exact hvar_margin_score.trans (by simpa [F, S] using hscore_rhs)\n\nprivate lemma integral_aggVote_eq_three_fifths {Ω : Type*} [MeasurableSpace Ω]\n (P : Measure Ω) (n : ℕ) (hn : 0 < n) (V : Fin n → Ω → ℝ)\n (hVint : ∀ i, Integrable (V i) P)\n (hV1 : ∀ i, ∫ ω, V i ω ∂P = 3 / 5) :\n ∫ ω, aggVote n V ω ∂P = 3 / 5 := by\n change (∫ ω, (n : ℝ)⁻¹ * ∑ i, V i ω ∂P) = 3 / 5\n rw [integral_const_mul,\n integral_finset_sum Finset.univ (fun i _ => hVint i)]\n simp_rw [hV1]\n rw [Finset.sum_const]\n simp [nsmul_eq_mul, hn.ne']\n\nprivate lemma integral_sq_aggVote {Ω : Type*} [MeasurableSpace Ω]\n (P : Measure Ω) (n : ℕ) (hn : 0 < n) (V : Fin n → Ω → ℝ)\n (hVcrossint : ∀ i j, Integrable (fun ω => V i ω * V j ω) P)\n (hV2 : ∀ i, ∫ ω, (V i ω) ^ 2 ∂P = 1)\n (hVuncorr : ∀ i j, i ≠ j → ∫ ω, V i ω * V j ω ∂P = 9 / 25) :\n ∫ ω, (aggVote n V ω) ^ 2 ∂P =\n (16 + 9 * (n : ℝ)) / (25 * (n : ℝ)) := by\n have hsquare (ω : Ω) :\n (∑ i, V i ω) ^ 2 = ∑ i, ∑ j, V i ω * V j ω := by\n rw [pow_two, Finset.sum_mul]\n apply Finset.sum_congr rfl\n intro i hi\n rw [Finset.mul_sum]\n have hinter (i : Fin n) :\n ∫ ω, ∑ j, V i ω * V j ω ∂P = ∑ j, ∫ ω, V i ω * V j ω ∂P := by\n exact integral_finset_sum Finset.univ (fun j _ => hVcrossint i j)\n have hinner (i : Fin n) :\n ∑ j, ∫ ω, V i ω * V j ω ∂P =\n 1 + ((n : ℝ) - 1) * (9 / 25) := by\n rw [Finset.sum_eq_add_sum_diff_singleton (Finset.mem_univ i)]\n have hdiag : ∫ ω, V i ω * V i ω ∂P = 1 := by\n simpa [pow_two] using hV2 i\n rw [hdiag]\n have hoff :\n ∑ x ∈ Finset.univ \\ {i}, ∫ ω, V i ω * V x ω ∂P =\n ∑ _x ∈ Finset.univ \\ {i}, (9 / 25 : ℝ) := by\n apply Finset.sum_congr rfl\n intro j hj\n apply hVuncorr\n have hji : j ≠ i := by simpa using (Finset.mem_sdiff.mp hj).2\n exact hji.symm\n have hcard : (Finset.univ \\ {i} : Finset (Fin n)).card = n - 1 := by\n rw [Finset.sdiff_singleton_eq_erase,\n Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ,\n Fintype.card_fin]\n rw [hoff, Finset.sum_const, hcard]\n simp [nsmul_eq_mul, Nat.cast_sub (show 1 ≤ n from hn)]\n change (∫ ω, ((n : ℝ)⁻¹ * ∑ i, V i ω) ^ 2 ∂P) =\n (16 + 9 * (n : ℝ)) / (25 * (n : ℝ))\n simp only [mul_pow]\n rw [integral_const_mul]\n have hsum_int (i : Fin n) : Integrable (fun ω => ∑ j, V i ω * V j ω) P :=\n integrable_finset_sum _ (fun j _ => hVcrossint i j)\n calc\n ((n : ℝ)⁻¹ ^ 2) * ∫ ω, (∑ i, V i ω) ^ 2 ∂P =\n ((n : ℝ)⁻¹ ^ 2) * ∫ ω, ∑ i, ∑ j, V i ω * V j ω ∂P := by\n congr 1\n exact integral_congr_ae (ae_of_all P hsquare)\n _ = ((n : ℝ)⁻¹ ^ 2) * ∑ i, ∫ ω, ∑ j, V i ω * V j ω ∂P := by\n rw [integral_finset_sum Finset.univ (fun i _ => hsum_int i)]\n _ = ((n : ℝ)⁻¹ ^ 2) * ∑ _i : Fin n,\n (1 + ((n : ℝ) - 1) * (9 / 25)) := by\n congr 1\n apply Finset.sum_congr rfl\n intro i hi\n rw [hinter, hinner]\n _ = (16 + 9 * (n : ℝ)) / (25 * (n : ℝ)) := by\n rw [Finset.sum_const]\n simp [nsmul_eq_mul]\n field_simp\n ring\n\ntheorem cbound_counterexample {Ω : Type*} [MeasurableSpace Ω]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (n : ℕ) (hn : 0 < n) (V : Fin n → Ω → ℝ) (Y : Ω → ℝ)\n (hVint : ∀ i, Integrable (V i) P)\n (hVcrossint : ∀ i j, Integrable (fun ω => V i ω * V j ω) P)\n (hYint : Integrable Y P)\n (hYSint : Integrable (fun ω => Y ω * aggVote n V ω) P)\n (hV1 : ∀ i, ∫ ω, V i ω ∂P = 3 / 5)\n (hV2 : ∀ i, ∫ ω, (V i ω) ^ 2 ∂P = 1)\n (hVuncorr : ∀ i j, i ≠ j → ∫ ω, V i ω * V j ω ∂P = 9 / 25)\n (hY1 : ∫ ω, Y ω ∂P = 3 / 5)\n (hYsq : ∀ ω, (Y ω) ^ 2 = 1)\n (hYindep : ∫ ω, Y ω * aggVote n V ω ∂P\n = (∫ ω, Y ω ∂P) * (∫ ω, aggVote n V ω ∂P))\n (X : Type*) [MeasurableSpace X] (xx : Ω → X) (v : Fin n → X → ℝ)\n (hVroute : ∀ i ω, V i ω = v i (xx ω))\n (hv_pm : ∀ i x, v i x = 1 ∨ v i x = -1)\n (hv_meas : ∀ i, Measurable (v i))\n (hVindep : ProbabilityTheory.iIndepFun V P)\n (hYXindep : ProbabilityTheory.IndepFun Y xx P) :\n cBound P Y (aggVote n V) = (400 + 144 * (n : ℝ)) / (400 + 225 * (n : ℝ))\n ∧ (16 : ℝ) / 25 < cBound P Y (aggVote n V) := by\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n have hmean : ∫ ω, aggVote n V ω ∂P = 3 / 5 :=\n integral_aggVote_eq_three_fifths P n hn V hVint hV1\n have hmu1 : cMu1 P Y (aggVote n V) = 9 / 25 := by\n rw [cMu1, hYindep, hY1, hmean]\n norm_num\n have hmu2 : cMu2 P (aggVote n V) =\n (16 + 9 * (n : ℝ)) / (25 * (n : ℝ)) := by\n exact integral_sq_aggVote P n hn V hVcrossint hV2 hVuncorr\n have hformula :\n cBound P Y (aggVote n V) =\n (400 + 144 * (n : ℝ)) / (400 + 225 * (n : ℝ)) := by\n rw [cBound, hmu1, hmu2]\n have h16 : 16 + 9 * (n : ℝ) ≠ 0 := by positivity\n have h400 : 400 + 225 * (n : ℝ) ≠ 0 := by positivity\n field_simp [hnR.ne', h16, h400]\n ring\n refine ⟨hformula, ?_⟩\n rw [hformula]\n have hden : 0 < 400 + 225 * (n : ℝ) := by positivity\n apply (div_lt_div_iff₀ (by norm_num : (0 : ℝ) < 25) hden).2\n nlinarith\n\nend ResearchLevel\n"} +{"id": "v25-22-1253", "source": "Research-level", "targets": [{"label": "Lemma 6 (Lipschitz property of EU)", "decls": ["lemma6_lipschitz"], "statement": "Lemma 6 (Lipschitz property of EU) $E_{\\beta}$ is Lipschitz continuous with respect to the supremum norm over ${\\mathcal{D}}_{M}$ with $L_{M}= |\\exp(\\beta M)-1|$ , Moreover, $L_{M}$ is tight with respect to both $\\beta$ and M, i.e., for every $\\beta \\neq 0$ and every $M > 0$ there exist $F,G\\in{\\mathcal{D}}_{M}$ with $\\| F - G \\|_{\\infty}> 0$ and $|E_{\\beta}(F)-E_{\\beta}(G)| =L_{M}\\|F-G\\|_{\\infty}$.", "context_ids": ["v25-22-1253:ctx1", "v25-22-1253:ctx3", "v25-22-1253:ctx4", "v25-22-1253:ctx5", "v25-22-1253:ctx6", "v25-22-1253:ctx9"], "sibling_refs": [], "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}, {"label": "Lemma 12", "decls": ["lemma12_optimistic_bound"], "statement": "Lemma 12 (Bound on the optimistic constant) For any distributions $\\{F_{i}\\}_{i\\in [n]}\\subseteq\\mathcal{D}(a,b)$ and any $\\theta,\\theta^{\\prime}\\in\\Delta_{n}$ it holds that if $c \\geq \\| \\theta - \\theta^{\\prime}\\|_{1}$ , then\n\n$$\n\\sum_{i=1}^{n}\\theta_{i}F_{i}\\preceq\\mathrm{O}_{c}^{\\infty}\\left(\\sum_{i=1}^{n}\\theta_{i}^{\\prime}F_{i}\\right).\n$$", "context_ids": ["v25-22-1253:ctx1", "v25-22-1253:ctx2", "v25-22-1253:ctx4", "v25-22-1253:ctx7", "v25-22-1253:ctx8", "v25-22-1253:ctx9"], "sibling_refs": [], "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}, {"label": "Lemma 8 (Optimality of the distributional optimism operator)", "decls": ["lemma8_optimism_operator_argmax"], "statement": "Lemma 8 Let ρ be a functional (not necessarily a risk measure) satisfying (M). For any $G\\in{\\mathcal{D}}(a,b)$ , it holds that if $G\\in B_{\\infty}(F,c)$ , then $G \\preceq \\mathrm{O}_{c}^{\\infty}F$ . Moreover, it holds that\n\n$$\n\\mathrm{O}_{c}^{\\infty}F\\in\\arg\\operatorname*{max}_{G\\in B_{\\infty}(F,c)\\cap\\mathcal{D}(a,b)}\\rho(G).\n$$", "context_ids": ["v25-22-1253:ctx1", "v25-22-1253:ctx2", "v25-22-1253:ctx4", "v25-22-1253:ctx7", "v25-22-1253:ctx9"], "sibling_refs": [], "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "### Proof of Lemma 6 (Lipschitz property of EU)\n\nProof We first provide the proof for the case $\\beta > 0$ . For any $F,G\\in{\\mathcal{D}}_{M}$ , without loss of generality we assume $\\begin{array}{r}{\\int_{0}^{M}G(x)d\\exp(\\beta x)-\\int_{0}^{M}F(x)d\\exp(\\beta x)\\geq 0}\\end{array}$ ,otherwise we switch the order.\n\n$$\n\\begin{array}{l}{\\displaystyle|E_{\\beta}(F)-E_{\\beta}(G)| = |\\int_{0}^{M}\\exp(\\beta x)dF(x)-\\int_{0}^{M}\\exp(\\beta x)dG(x)|}\\\\ {\\displaystyle= |\\exp(\\beta x)F(x)|_{0}^{M}-\\int_{0}^{M}F(x)d\\exp(\\beta x)-\\exp(\\beta x)G(x)\\big|_{0}^{M}+\\int_{0}^{M}G(x)d\\exp(\\beta x)|}\\\\ {\\displaystyle=\\int_{0}^{M}(G(x)-F(x))d\\exp(\\beta x)\\le\\int_{0}^{M}|G(x)-F(x)|d\\exp(\\beta x)}\\\\ {\\displaystyle\\le\\|F-G\\|_{\\infty}\\int_{0}^{M}1d\\exp(\\beta x)=(\\exp(\\beta M)-1)\\|F-G\\|_{\\infty}.}\\end{array}\n$$\n\nFor the case $\\beta < 0$ , we assume $\\begin{array}{r}{\\int_{0}^{M}G(x)d\\exp(\\beta x)-\\int_{0}^{M}F(x)d\\exp(\\beta x)\\geq 0.}\\end{array}$\n\n$$\n\\begin{array}{l l}{\\displaystyle|E_{\\beta}(F)-E_{\\beta}(G)| =\\int_{0}^{M}(G(x)-F(x))d\\exp(\\beta x)=\\int_{0}^{M}(G(x)-F(x))\\beta\\exp(\\beta x)dx}\\\\ {\\displaystyle\\le\\int_{0}^{M}|G(x)-F(x)| |\\beta|\\exp(\\beta x)dx}\\\\ {\\displaystyle\\le\\|F-G\\|_{\\infty}\\int_{0}^{M}-1d\\exp(\\beta x)=\\left(1-\\exp(\\beta M)\\right)\\|F-G\\|_{\\infty}}\\\\ {\\displaystyle= |\\exp(\\beta M)-1|\\left\\|F-G\\right\\|_{\\infty}.}\\end{array}\n$$\n\nThus $L_{M}= |\\exp(\\beta M)-1|$ for EU. To show the tightness of the constant, consider two scaled Bernoulli distributions $F=(1-\\mu_{1})\\psi_{0}+\\mu_{1}\\psi_{M}$ and $G=(1-\\mu_{2})\\psi_{0}+\\mu_{2}\\psi_{M}$ , where $\\mu_{1},\\mu_{2}\\in(0,1)$ are some constants. It holds that\n\n$$\n\\begin{array}{c}{{\\left|E_{\\beta}(F)-E_{\\beta}(G)\\right| =\\left|\\mu_{1}\\exp(\\beta M)+1-\\mu_{1}-(\\mu_{2}\\exp(\\beta M)+1-\\mu_{2})\\right|}}\\\\ {{{}}}\\\\ {{=\\left|\\mu_{1}-\\mu_{2}\\right|\\left|\\exp(\\beta M)-1\\right| =\\left\\|F-G\\right\\|_{\\infty}L_{M},}}\\end{array}\n$$\n\nwhere the last equality holds since $\\|F-G\\|_{\\infty}= |F(0)-G(0)| = |\\mu_{1}-\\mu_{2}|$ (independent of M ). More formally, we have\n\n$$\n\\operatorname*{inf}_{M>0,\\beta>0}\\operatorname*{sup}_{F,G\\in\\mathcal{D}_{M}}\\frac{|E_{\\beta}(F)-E_{\\beta}(G)|}{\\|F-G\\|_{\\infty}}= |\\exp(\\beta M)-1| =L_{M}.\n$$\n\n### Proof of Lemma 12\n\nProof Without loss of generality assume $F \\in \\mathcal{D}_{M}^{n}$ . By Lemma 11, for any x\n\n$$\n\\left|\\sum_{i=1}^{n}(\\theta_{i}^{\\prime}-\\theta_{i})F_{i}(x)\\right|\\leq\\left\\|\\theta^{\\prime}-\\theta\\right\\|_{1}.\n$$\n\nFor any $x\\in [0,M+1)$\n\n$$\n\\begin{array}{r l r}{{\\mathrm{O}_{c}^{\\infty}(\\sum_{i=1}^{n}\\theta_{i}^{\\prime}F_{i})(x)=[\\sum_{i=1}^{n}\\theta_{i}^{\\prime}F_{i}(x)-c]^{+}=[\\sum_{i=1}^{n}\\theta_{i}F_{i}(x)+\\sum_{i=1}^{n}(\\theta_{i}^{\\prime}-\\theta_{i})F_{i}(x)-c]^{+}}}\\\\ &{}&{\\leq [\\sum_{i=1}^{n}\\theta_{i}F_{i}(x)+\\|\\theta^{\\prime}-\\theta\\|_{1}-c]^{+}\\leq [\\sum_{i=1}^{n}\\theta_{i}F_{i}(x)]^{+}=\\sum_{i=1}^{n}\\theta_{i}F_{i}(x).}\\end{array}\n$$\n\n### Proof of Lemma 8 (Optimality of the distributional optimism operator)\n\nProof Consider any $G\\in\\mathcal{D}([a,b])\\cap B_{\\infty}(F,c)$ . By the definition of $B_{\\infty}(F,c)$ , we have $\\begin{array}{r}{\\operatorname*{sup}_{x\\in [a,b]}|F(x)-G(x)|\\leq c}\\end{array}$ Therefore, for any $x\\in [a,b]$ , we have $G(x)\\geq\\operatorname*{max}(F(x)-c,0)=$ $(\\mathrm{O}_{c}^{\\infty}F)(x)$ . Since ${\\mathrm{O}}_{c}^{\\infty}F$ dominates any G in $\\mathcal{D}([a,b])\\cap B_{\\infty}(F,c)$ and considering (M) of $\\rho,$ we arrive at the conclusion.", "context": [{"id": "v25-22-1253:ctx1", "name": "Notations (Section 2.1)", "statement": "We write $[M:N]\\triangleq\\{M,M+1,\\ldots,N\\}$ and $[ N ] \\triangleq [ 1 : N ]$ for any positive integers $M \\leq N .$ We adopt the convention that $\\textstyle \\sum_{i = n}^{m}a_{i}\\triangleq 0{\\mathrm{~ i f ~}}n > m$ and $\\textstyle \\prod_{i = n}^{m}a_{i}\\triangleq 1{\\mathrm{~ i f ~}}n > m$ .We use $\\mathbb{I}\\{\\cdot \\}$ to denote the indicator function. For any $x \\in \\mathbb{R}$ , we define $[x]^{+}\\triangleq\\operatorname*{max}\\{x,0\\}$ . We denote by $\\delta_{c}$ the Dirac measure at $c .$ Similarly, $\\psi_{c}$ represents the unit step function at $c,$ corresponding to the CDF of $\\delta_{c}$ . We denote by $\\Delta(\\mathcal{S}),\\mathcal{D}(a,b),\\mathcal{D}_{M}$ and $\\mathcal{D}$ the set of distributions supported on a set $\\mathcal{S},[a,b],[0,M]$ and the set of all distributions respectively. We use $(x_{1},x_{2};p)$ to denote a binary r.v. taking values $x_{1}$ and $x_{2}$ with probability $1 - p$ and $p .$ For a discrete set $x=\\{x_{1},\\cdots,x_{n}\\}$ and a probability vector $p=(p_{1},\\cdot\\cdot\\cdot,p_{n})$ , the notation $(x,p)$ represents the discrete distribution with $\\mathbb{P}(X=x_{i})=p_{i}$ . For a discrete distribution $\\eta=\\left(x,p\\right)$ , we use $| \\eta | = | x |$ to denote the number of atoms of the distribution $\\eta$ . We use $\\tilde{\\mathcal{O}}(\\cdot)$ to denote $\\mathcal{O}(\\cdot)$ omitting logarithmic factors. A table of notation is provided in Appendix A."}, {"id": "v25-22-1253:ctx2", "name": "Stochastic dominance and risk-measure properties (M), (TI), (DI) (Section 2.3)", "statement": "Consider two random variables $X \\sim F$ and $Y \\sim G$ . We assert that Y dominates $X,$ and correspondingly, G dominates $F,$ denoted as $Y \\succeq X$ and $G \\succeq F$ , if and only if for every real number x, the inequality $F(x)\\geq G(x)$ holds true. A risk measure, $\\rho,$ is a function mapping a set of random variables, denoted as $\\mathcal{X}$ , to the real numbers. This mapping adheres to several crucial properties:\n\n• Monotonicity (M): $X\\preceq Y\\Rightarrow\\rho(X)\\leq\\rho(Y),\\forall X,Y\\in{\\mathcal{X}}$\n\nTranslation-invariance $(\\mathbf{TI})\\colon\\rho(X+c)=\\rho(X)+c,\\forall X\\in{\\mathcal{X}},\\forall c\\in\\mathbb{R},$\n\nDistribution-invariance (DI): $F_{X_{1}}=F_{X_{2}}\\Rightarrow\\rho(X_{1})=\\rho(X_{2})$\n\nA mapping $\\rho : \\mathcal{X}\\to \\mathbb{R}$ qualifies as a risk measure if it satisfies both (M) and (TI). Additionally, a risk measure that also adheres to (DI) is termed a distribution-invariant risk measure. Distribution-invariant risk measure allows us to simplify notation by denoting $\\rho(F_{X})$ as $\\rho(X)$"}, {"id": "v25-22-1253:ctx3", "name": "Entropic risk measure EntRM (Section 2.3)", "statement": "We direct our attention to a specific distribution-invariant risk measure, EntRM, a prominent risk measure in domains requiring risk-sensitive decision-making, such as mathematical finance (Föllmer and Schied, 2016), Markovian decision processes (Bäuerle and Rieder, 2014). For a random variable $X \\sim F$ and a non-zero coefficient $\\beta,$ the EntRM is defined as:\n\n$$\nU_{\\beta}(X)\\triangleq{\\frac{1}{\\beta}}\\log\\left(\\mathbb{E}_{X\\sim F}\\left[e^{\\beta X}\\right]\\right)={\\frac{1}{\\beta}}\\log\\left(\\int_{\\mathbb{R}}e^{\\beta x}dF(x)\\right).\n$$"}, {"id": "v25-22-1253:ctx4", "name": "Supremum distance, l1 distance, norm balls B_infty(F,c) and B_1(P,c)", "statement": "We begin by establishing additional notations. For two Cumulative Distribution Functions (CDFs) F and G, the supremum distance between them is defined as $\\| F - G \\|_{\\infty}\\triangleq$ $\\begin{array}{r}{\\operatorname*{sup}_{x}|F(x)-G(x)|}\\end{array}$ We define the $\\ell_{1}$ distance between two Probability Mass Functions $(\\mathrm{PMFs})$ with the same support P and $Q$ as $\\begin{array}{r}{\\| P - Q \\|_{1}\\triangleq \\sum_{i}| P_{i}- Q_{i}|}\\end{array}$ . Furthermore, the set $B_{\\infty}(F,c): =\\{G\\in\\mathcal{D}|\\|G-F\\|_{\\infty}\\leq c\\}$ denotes the supremum norm ball of CDFs centered at F with radius c. Analogously, $B_{1}(P,c)$ represents the $\\ell_{1}$ norm ball of PMFs centered at P with radius c."}, {"id": "v25-22-1253:ctx5", "name": "Exponential utility E_beta (Section 4.1)", "statement": "Our analysis explores the relationship between EntRM and Exponential Utility (EU). The EU is defined as follows:\n\n$$\nE_{\\beta}(F)\\triangleq e^{\\beta U_{\\beta}(F)}=\\int_{\\mathbb{R}}e^{\\beta x}dF(x),\n$$\n\nwhere it serves as an exponential transformation of the EntRM. Notably, this transformation preserves the order in the sense that for any non-zero $\\beta,\\forall\\beta\\neq 0$\n\n$$\nU_{\\beta}(F)\\geq U_{\\beta}(G)\\Longleftrightarrow\\mathrm{sign}(\\beta)E_{\\beta}(F)\\geq\\mathrm{sign}(\\beta)E_{\\beta}(G).\n$$"}, {"id": "v25-22-1253:ctx6", "name": "Lipschitz constant L_M of E_beta over D_M", "statement": "We further present two important properties of EU, instrumental in formulating the regret upper bounds: Lipschitz continuity and linearity. Denote by $L_{M}$ the Lipschitz constant of $E_{\\beta}: \\mathcal{D}_{M}\\to \\mathbb{R}$ with respect to the infinity norm $\\left\\| \\cdot \\right\\|_{\\infty}$ , which satisfies:\n\n$$\nE_{\\beta}(F)-E_{\\beta}(G)\\leq L_{M}\\|F-G\\|_{\\infty},\\forall F,G\\in\\mathcal{D}_{M}.\n$$"}, {"id": "v25-22-1253:ctx7", "name": "Definition 7 and the distributional optimism operator O_c^infty (Section 4.2)", "statement": "Definition 7 Given two CDFs F and G, we say that F is more optimistic than G if $F \\geq G$\n\nThis definition aligns with the intuitive notion that a more optimistic distribution should possess a larger EntRM value. Given that the exponential transformation preserves order, F is more optimistic than G if and only if $E_{\\beta}(F)\\ge E_{\\beta}(G)$ . Following the methodology of Keramati et al. (2020), we introduce the distributional optimism operator $\\mathrm{O}_{c}^{\\infty}:\\mathcal{D}(a,b)\\mapsto$ $\\mathcal{D}(a,b)$ for a level $c\\in(0,1)$ as\n\n$$\n(\\mathrm{O}_{c}^{\\infty}F)(x)\\triangleq [F(x)-c\\mathbb{I}_{[a,b)}(x)]^{+}.\n$$\n\nThis operator shifts the distribution F down by a maximum of c over $[a,b)$ , ensuring that the resulting function ${\\mathrm{O}}_{c}^{\\infty}F$ remains a valid CDF in $\\mathcal{D}(a,b)$ and optimistically dominates all other CDFs within the confidence ball $B_{\\infty}(F,c)^{3}$ . In particular, ${\\mathrm{O}}_{c}^{\\infty}F$ represents maximum permissible downward adjustment under the constraints of the infinity ball, ensuring that for any distribution $G\\in B_{\\infty}(F,c)$\n\n$$\n(\\mathrm{O}_{c}^{\\infty}F)(x)\\leq G(x),\\forall x\\in\\mathbb{R}.\n$$"}, {"id": "v25-22-1253:ctx8", "name": "Lemma 11", "statement": "Lemma 11 For any $F_{i}\\in \\mathcal{D}$ and any $\\theta,\\theta^{\\prime}\\in\\Delta_{n}$ with any $n \\geq 2$ , it holds that\n\n$$\n\\left\\| \\sum_{i = 1}^{n}\\theta_{i}F_{i}- \\sum_{i = 1}^{n}\\theta_{i}^{\\prime}F_{i}\\right\\|_{\\infty}\\leq \\left\\| \\theta - \\theta^{\\prime}\\right\\|_{1}.\n$$"}, {"id": "v25-22-1253:ctx9", "name": "Table of notation: CDF classes and the infinity ball (Appendix A)", "statement": "
SymbolExplanation
$\\mathcal{D}$ The space of all CDFs
$\\mathcal{D}(a,b)$ The space of all CDFs supported on $[a,b]$
${\\mathcal{D}}_{M}$ The space of all CDFs supported on $[0,M]$
$B_{\\infty}(F,c)$ The $\\left\\| \\cdot \\right\\|_{\\infty}$ norm ball centered at $F$ with radius c
"}], "lean": "import Mathlib\n\nopen MeasureTheory\n\nnamespace ResearchLevel\n\nnoncomputable def EU (β : ℝ) (μ : Measure ℝ) : ℝ := ∫ x, Real.exp (β * x) ∂μ\n\nnoncomputable def optimismInf (a b c : ℝ) (F : ℝ → ℝ) : ℝ → ℝ :=\n fun x => max (F x - c * Set.indicator (Set.Ico a b) (fun _ => (1 : ℝ)) x) 0\n\ndef InDab (a b : ℝ) (F : ℝ → ℝ) : Prop :=\n Monotone F ∧ (∀ x, F x ∈ Set.Icc (0 : ℝ) 1)\n ∧ (∀ x, ContinuousWithinAt F (Set.Ici x) x)\n ∧ (∀ x, x < a → F x = 0) ∧ (∀ x, b ≤ x → F x = 1)\n\ntheorem lemma6_lipschitz {M β : ℝ} (hM : 0 ≤ M) (hβ : β ≠ 0)\n (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n (hμ : μ (Set.Icc 0 M) = 1) (hν : ν (Set.Icc 0 M) = 1) :\n (|EU β μ - EU β ν|\n ≤ |Real.exp (β * M) - 1|\n * ⨆ x : ℝ, |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x|)\n ∧ (0 < M → ∃ μ₀ ν₀ : Measure ℝ, IsProbabilityMeasure μ₀ ∧ IsProbabilityMeasure ν₀ ∧\n μ₀ (Set.Icc 0 M) = 1 ∧ ν₀ (Set.Icc 0 M) = 1 ∧\n 0 < (⨆ x : ℝ, |ProbabilityTheory.cdf μ₀ x - ProbabilityTheory.cdf ν₀ x|) ∧\n |EU β μ₀ - EU β ν₀|\n = |Real.exp (β * M) - 1|\n * ⨆ x : ℝ, |ProbabilityTheory.cdf μ₀ x - ProbabilityTheory.cdf ν₀ x|) := by\n sorry\n\ntheorem lemma12_optimistic_bound {n : ℕ} (a b c : ℝ) (hab : a ≤ b) (hc0 : 0 < c)\n (F : Fin n → ℝ → ℝ)\n (hFmono : ∀ i, Monotone (F i))\n (hFright : ∀ i x, ContinuousWithinAt (F i) (Set.Ici x) x)\n (hFrange : ∀ i x, F i x ∈ Set.Icc (0 : ℝ) 1)\n (hFlo : ∀ i x, x < a → F i x = 0)\n (hFhi : ∀ i x, b ≤ x → F i x = 1)\n (θ θ' : Fin n → ℝ)\n (hθnn : ∀ i, 0 ≤ θ i) (hθ'nn : ∀ i, 0 ≤ θ' i)\n (hθsum : ∑ i, θ i = 1) (hθ'sum : ∑ i, θ' i = 1)\n (hc : ∑ i, |θ i - θ' i| ≤ c) :\n ∀ x, optimismInf a b c (fun y => ∑ i, θ' i * F i y) x\n ≤ (∑ i, θ i * F i x) := by\n sorry\n\ntheorem lemma8_optimism_operator_argmax {a b c : ℝ} (hab : a ≤ b) (hc0 : 0 < c)\n (F : ℝ → ℝ) (hF : InDab a b F)\n (ρ : (ℝ → ℝ) → ℝ)\n (hρM : ∀ P Q : ℝ → ℝ, InDab a b P → InDab a b Q → (∀ x, P x ≤ Q x) → ρ Q ≤ ρ P) :\n (∀ G : ℝ → ℝ, InDab a b G → (∀ x, |G x - F x| ≤ c) →\n ∀ x, optimismInf a b c F x ≤ G x)\n ∧ ( InDab a b (optimismInf a b c F)\n ∧ (∀ x, |optimismInf a b c F x - F x| ≤ c)\n ∧ (∀ G : ℝ → ℝ, InDab a b G → (∀ x, |G x - F x| ≤ c) →\n ρ G ≤ ρ (optimismInf a b c F)) ) := by\n sorry\n\nend ResearchLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory\n\nnamespace ResearchLevel\n\nnoncomputable def EU (β : ℝ) (μ : Measure ℝ) : ℝ := ∫ x, Real.exp (β * x) ∂μ\n\nnoncomputable def optimismInf (a b c : ℝ) (F : ℝ → ℝ) : ℝ → ℝ :=\n fun x => max (F x - c * Set.indicator (Set.Ico a b) (fun _ => (1 : ℝ)) x) 0\n\ndef InDab (a b : ℝ) (F : ℝ → ℝ) : Prop :=\n Monotone F ∧ (∀ x, F x ∈ Set.Icc (0 : ℝ) 1)\n ∧ (∀ x, ContinuousWithinAt F (Set.Ici x) x)\n ∧ (∀ x, x < a → F x = 0) ∧ (∀ x, b ≤ x → F x = 1)\n\nprivate lemma integral_eq_integral_Ioc_meas_lt {α : Type*} [MeasurableSpace α]\n {μ : Measure α} {f : α → ℝ} {L : ℝ}\n (hf : Integrable f μ) (hf0 : 0 ≤ᵐ[μ] f) (hfL : f ≤ᵐ[μ] fun _ => L) :\n ∫ x, f x ∂μ = ∫ t in Set.Ioc 0 L, μ.real {x | t < f x} := by\n rw [hf.integral_eq_integral_meas_lt hf0]\n rw [setIntegral_eq_of_subset_of_ae_diff_eq_zero\n nullMeasurableSet_Ioi Set.Ioc_subset_Ioi_self]\n apply Filter.Eventually.of_forall\n intro t ht\n have htL : L < t := by\n simp_all only [Set.mem_diff, Set.mem_Ioi, Set.mem_Ioc, not_and, not_le]\n have hzero : μ {x | L < f x} = 0 := by\n rw [measure_eq_zero_iff_ae_notMem]\n filter_upwards [hfL] with x hx using not_lt.mpr hx\n rw [measureReal_def, ENNReal.toReal_eq_zero_iff]\n exact Or.inl <| measure_mono_null (fun x hx => htL.trans hx) hzero\n\nprivate lemma cdf_abs_bdd (μ ν : Measure ℝ) :\n BddAbove (Set.range fun x : ℝ =>\n |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x|) := by\n refine ⟨1, ?_⟩\n rintro _ ⟨x, rfl⟩\n rw [abs_le]\n constructor\n · linarith [ProbabilityTheory.cdf_nonneg μ x, ProbabilityTheory.cdf_le_one ν x]\n · linarith [ProbabilityTheory.cdf_nonneg ν x, ProbabilityTheory.cdf_le_one μ x]\n\nprivate lemma cdf_abs_le_iSup (μ ν : Measure ℝ) (x : ℝ) :\n |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x|\n ≤ ⨆ y : ℝ, |ProbabilityTheory.cdf μ y - ProbabilityTheory.cdf ν y| :=\n le_ciSup (cdf_abs_bdd μ ν) x\n\nprivate lemma abs_integral_sub_le_cdf_iSup_of_tail_Ioi {L : ℝ} (hL : 0 ≤ L)\n (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n (q : ℝ → ℝ)\n (hqμ : Integrable q μ) (hqν : Integrable q ν)\n (hqμ0 : 0 ≤ᵐ[μ] q) (hqν0 : 0 ≤ᵐ[ν] q)\n (hqμL : q ≤ᵐ[μ] fun _ => L) (hqνL : q ≤ᵐ[ν] fun _ => L)\n (htail : ∀ t ∈ Set.Ioc 0 L, ∃ r : ℝ, {x | t < q x} = Set.Ioi r) :\n |(∫ x, q x ∂μ) - ∫ x, q x ∂ν|\n ≤ L * ⨆ x : ℝ, |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x| := by\n let D : ℝ := ⨆ x : ℝ,\n |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x|\n let Tμ : ℝ → ℝ := fun t => μ.real {x | t < q x}\n let Tν : ℝ → ℝ := fun t => ν.real {x | t < q x}\n have hTμanti : Antitone Tμ := by\n intro s t hst\n exact measureReal_mono (fun x hx => hst.trans_lt hx)\n have hTνanti : Antitone Tν := by\n intro s t hst\n exact measureReal_mono (fun x hx => hst.trans_lt hx)\n have hTμint : IntegrableOn Tμ (Set.Ioc 0 L) := by\n refine IntegrableOn.of_bound (by rw [Real.volume_Ioc]; finiteness)\n hTμanti.measurable.aestronglyMeasurable 1 ?_\n apply Filter.Eventually.of_forall\n intro t\n rw [Real.norm_eq_abs, abs_of_nonneg measureReal_nonneg]\n have hmono := measureReal_mono (μ := μ) (Set.subset_univ {x | t < q x})\n simpa only [Tμ, probReal_univ] using hmono\n have hTνint : IntegrableOn Tν (Set.Ioc 0 L) := by\n refine IntegrableOn.of_bound (by rw [Real.volume_Ioc]; finiteness)\n hTνanti.measurable.aestronglyMeasurable 1 ?_\n apply Filter.Eventually.of_forall\n intro t\n rw [Real.norm_eq_abs, abs_of_nonneg measureReal_nonneg]\n have hmono := measureReal_mono (μ := ν) (Set.subset_univ {x | t < q x})\n simpa only [Tν, probReal_univ] using hmono\n have htail_bound : ∀ t ∈ Set.Ioc 0 L, |Tμ t - Tν t| ≤ D := by\n intro t ht\n rcases htail t ht with ⟨r, hr⟩\n have hμtail : μ.real (Set.Ioi r) = 1 - ProbabilityTheory.cdf μ r := by\n calc\n μ.real (Set.Ioi r) = μ.real (Set.Iic r)ᶜ := by\n congr 2\n ext x\n simp\n _ = μ.real Set.univ - μ.real (Set.Iic r) :=\n measureReal_compl measurableSet_Iic\n _ = 1 - ProbabilityTheory.cdf μ r := by\n rw [probReal_univ, ProbabilityTheory.cdf_eq_real]\n have hνtail : ν.real (Set.Ioi r) = 1 - ProbabilityTheory.cdf ν r := by\n calc\n ν.real (Set.Ioi r) = ν.real (Set.Iic r)ᶜ := by\n congr 2\n ext x\n simp\n _ = ν.real Set.univ - ν.real (Set.Iic r) :=\n measureReal_compl measurableSet_Iic\n _ = 1 - ProbabilityTheory.cdf ν r := by\n rw [probReal_univ, ProbabilityTheory.cdf_eq_real]\n change |μ.real {x | t < q x} - ν.real {x | t < q x}| ≤ D\n rw [hr, hμtail, hνtail]\n have hsup := cdf_abs_le_iSup μ ν r\n change |1 - ProbabilityTheory.cdf μ r - (1 - ProbabilityTheory.cdf ν r)| ≤ D\n calc\n |1 - ProbabilityTheory.cdf μ r - (1 - ProbabilityTheory.cdf ν r)| =\n |ProbabilityTheory.cdf μ r - ProbabilityTheory.cdf ν r| := by\n rw [show 1 - ProbabilityTheory.cdf μ r -\n (1 - ProbabilityTheory.cdf ν r) =\n ProbabilityTheory.cdf ν r - ProbabilityTheory.cdf μ r by ring,\n abs_sub_comm]\n _ ≤ D := by simpa only [D] using hsup\n have hqμeq : ∫ x, q x ∂μ = ∫ t in Set.Ioc 0 L, Tμ t := by\n simpa only [Tμ] using integral_eq_integral_Ioc_meas_lt hqμ hqμ0 hqμL\n have hqνeq : ∫ x, q x ∂ν = ∫ t in Set.Ioc 0 L, Tν t := by\n simpa only [Tν] using integral_eq_integral_Ioc_meas_lt hqν hqν0 hqνL\n rw [hqμeq, hqνeq, ← integral_sub hTμint hTνint]\n calc\n |∫ t in Set.Ioc 0 L, Tμ t - Tν t| ≤\n ∫ t in Set.Ioc 0 L, |Tμ t - Tν t| := abs_integral_le_integral_abs\n _ ≤ ∫ _ in Set.Ioc 0 L, D := by\n exact setIntegral_mono_on (hTμint.sub hTνint).abs\n (integrableOn_const (by rw [Real.volume_Ioc]; finiteness))\n measurableSet_Ioc htail_bound\n _ = L * D := by simp [hL]\n\nprivate lemma eu_lipschitz_pos {M β : ℝ} (hM : 0 ≤ M) (hβ : 0 < β)\n (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n (hμ : μ (Set.Icc 0 M) = 1) (hν : ν (Set.Icc 0 M) = 1) :\n |EU β μ - EU β ν| ≤ (Real.exp (β * M) - 1) *\n ⨆ x : ℝ, |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x| := by\n let q : ℝ → ℝ := fun x => Real.exp (β * x) - 1\n let L : ℝ := Real.exp (β * M) - 1\n have hμae : ∀ᵐ x ∂μ, x ∈ Set.Icc (0 : ℝ) M :=\n (ae_mem_iff_measure_eq measurableSet_Icc.nullMeasurableSet).2 (by simpa using hμ)\n have hνae : ∀ᵐ x ∂ν, x ∈ Set.Icc (0 : ℝ) M :=\n (ae_mem_iff_measure_eq measurableSet_Icc.nullMeasurableSet).2 (by simpa using hν)\n have hexpμ : Integrable (fun x : ℝ => Real.exp (β * x)) μ := by\n simpa only [id_eq] using\n (ProbabilityTheory.integrable_exp_mul_of_mem_Icc (μ := μ) (X := id) (t := β)\n measurable_id.aemeasurable hμae)\n have hexpν : Integrable (fun x : ℝ => Real.exp (β * x)) ν := by\n simpa only [id_eq] using\n (ProbabilityTheory.integrable_exp_mul_of_mem_Icc (μ := ν) (X := id) (t := β)\n measurable_id.aemeasurable hνae)\n have hqμ : Integrable q μ := by\n exact hexpμ.sub (integrable_const 1)\n have hqν : Integrable q ν := by\n exact hexpν.sub (integrable_const 1)\n have hL : 0 ≤ L := by\n dsimp [L]\n rw [sub_nonneg, Real.one_le_exp_iff]\n exact mul_nonneg hβ.le hM\n have hqμ0 : 0 ≤ᵐ[μ] q := by\n filter_upwards [hμae] with x hx\n dsimp [q]\n rw [sub_nonneg, Real.one_le_exp_iff]\n exact mul_nonneg hβ.le hx.1\n have hqν0 : 0 ≤ᵐ[ν] q := by\n filter_upwards [hνae] with x hx\n dsimp [q]\n rw [sub_nonneg, Real.one_le_exp_iff]\n exact mul_nonneg hβ.le hx.1\n have hqμL : q ≤ᵐ[μ] fun _ => L := by\n filter_upwards [hμae] with x hx\n dsimp [q, L]\n exact sub_le_sub_right (Real.exp_le_exp.mpr\n (mul_le_mul_of_nonneg_left hx.2 hβ.le)) 1\n have hqνL : q ≤ᵐ[ν] fun _ => L := by\n filter_upwards [hνae] with x hx\n dsimp [q, L]\n exact sub_le_sub_right (Real.exp_le_exp.mpr\n (mul_le_mul_of_nonneg_left hx.2 hβ.le)) 1\n have htail : ∀ t ∈ Set.Ioc 0 L, ∃ r : ℝ, {x | t < q x} = Set.Ioi r := by\n intro t ht\n have ht1 : 0 < t + 1 := by linarith [ht.1]\n refine ⟨Real.log (t + 1) / β, ?_⟩\n ext x\n simp only [Set.mem_setOf_eq, Set.mem_Ioi, q]\n calc\n t < Real.exp (β * x) - 1 ↔ t + 1 < Real.exp (β * x) := by\n constructor <;> intro h <;> linarith\n _ ↔ Real.log (t + 1) < β * x := (Real.log_lt_iff_lt_exp ht1).symm\n _ ↔ Real.log (t + 1) / β < x := by\n rw [div_lt_iff₀ hβ]\n simp only [mul_comm]\n have hmain := abs_integral_sub_le_cdf_iSup_of_tail_Ioi hL μ ν q\n hqμ hqν hqμ0 hqν0 hqμL hqνL htail\n have hqμeq : ∫ x, q x ∂μ = EU β μ - 1 := by\n calc\n ∫ x, q x ∂μ = (∫ x, Real.exp (β * x) ∂μ) - ∫ _x, (1 : ℝ) ∂μ := by\n simpa only [q] using integral_sub hexpμ (integrable_const 1)\n _ = EU β μ - 1 := by simp [EU]\n have hqνeq : ∫ x, q x ∂ν = EU β ν - 1 := by\n calc\n ∫ x, q x ∂ν = (∫ x, Real.exp (β * x) ∂ν) - ∫ _x, (1 : ℝ) ∂ν := by\n simpa only [q] using integral_sub hexpν (integrable_const 1)\n _ = EU β ν - 1 := by simp [EU]\n calc\n |EU β μ - EU β ν| = |(∫ x, q x ∂μ) - ∫ x, q x ∂ν| := by\n rw [hqμeq, hqνeq, sub_sub_sub_cancel_right]\n _ ≤ L * ⨆ x : ℝ,\n |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x| := hmain\n _ = (Real.exp (β * M) - 1) * ⨆ x : ℝ,\n |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x| := by rfl\n\nprivate lemma eu_lipschitz_neg {M β : ℝ} (hM : 0 ≤ M) (hβ : β < 0)\n (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n (hμ : μ (Set.Icc 0 M) = 1) (hν : ν (Set.Icc 0 M) = 1) :\n |EU β μ - EU β ν| ≤ (1 - Real.exp (β * M)) *\n ⨆ x : ℝ, |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x| := by\n let q : ℝ → ℝ := fun x => 1 - Real.exp (β * x)\n let L : ℝ := 1 - Real.exp (β * M)\n have hμae : ∀ᵐ x ∂μ, x ∈ Set.Icc (0 : ℝ) M :=\n (ae_mem_iff_measure_eq measurableSet_Icc.nullMeasurableSet).2 (by simpa using hμ)\n have hνae : ∀ᵐ x ∂ν, x ∈ Set.Icc (0 : ℝ) M :=\n (ae_mem_iff_measure_eq measurableSet_Icc.nullMeasurableSet).2 (by simpa using hν)\n have hexpμ : Integrable (fun x : ℝ => Real.exp (β * x)) μ := by\n simpa only [id_eq] using\n (ProbabilityTheory.integrable_exp_mul_of_mem_Icc (μ := μ) (X := id) (t := β)\n measurable_id.aemeasurable hμae)\n have hexpν : Integrable (fun x : ℝ => Real.exp (β * x)) ν := by\n simpa only [id_eq] using\n (ProbabilityTheory.integrable_exp_mul_of_mem_Icc (μ := ν) (X := id) (t := β)\n measurable_id.aemeasurable hνae)\n have hqμ : Integrable q μ := by\n exact (integrable_const 1).sub hexpμ\n have hqν : Integrable q ν := by\n exact (integrable_const 1).sub hexpν\n have hL : 0 ≤ L := by\n dsimp [L]\n rw [sub_nonneg, Real.exp_le_one_iff]\n exact mul_nonpos_of_nonpos_of_nonneg hβ.le hM\n have hqμ0 : 0 ≤ᵐ[μ] q := by\n filter_upwards [hμae] with x hx\n dsimp [q]\n rw [sub_nonneg, Real.exp_le_one_iff]\n exact mul_nonpos_of_nonpos_of_nonneg hβ.le hx.1\n have hqν0 : 0 ≤ᵐ[ν] q := by\n filter_upwards [hνae] with x hx\n dsimp [q]\n rw [sub_nonneg, Real.exp_le_one_iff]\n exact mul_nonpos_of_nonpos_of_nonneg hβ.le hx.1\n have hqμL : q ≤ᵐ[μ] fun _ => L := by\n filter_upwards [hμae] with x hx\n dsimp [q, L]\n exact sub_le_sub_left (Real.exp_le_exp.mpr\n (mul_le_mul_of_nonpos_left hx.2 hβ.le)) 1\n have hqνL : q ≤ᵐ[ν] fun _ => L := by\n filter_upwards [hνae] with x hx\n dsimp [q, L]\n exact sub_le_sub_left (Real.exp_le_exp.mpr\n (mul_le_mul_of_nonpos_left hx.2 hβ.le)) 1\n have htail : ∀ t ∈ Set.Ioc 0 L, ∃ r : ℝ, {x | t < q x} = Set.Ioi r := by\n intro t ht\n have hexp_le : Real.exp (β * M) ≤ 1 - t := by\n dsimp [L] at ht\n linarith [ht.2]\n have h1t : 0 < 1 - t := (Real.exp_pos (β * M)).trans_le hexp_le\n refine ⟨Real.log (1 - t) / β, ?_⟩\n ext x\n simp only [Set.mem_setOf_eq, Set.mem_Ioi, q]\n calc\n t < 1 - Real.exp (β * x) ↔ Real.exp (β * x) < 1 - t := by\n constructor <;> intro h <;> linarith\n _ ↔ β * x < Real.log (1 - t) := (Real.lt_log_iff_exp_lt h1t).symm\n _ ↔ Real.log (1 - t) / β < x := by\n rw [div_lt_iff_of_neg hβ]\n simp only [mul_comm]\n have hmain := abs_integral_sub_le_cdf_iSup_of_tail_Ioi hL μ ν q\n hqμ hqν hqμ0 hqν0 hqμL hqνL htail\n have hqμeq : ∫ x, q x ∂μ = 1 - EU β μ := by\n calc\n ∫ x, q x ∂μ = (∫ _x, (1 : ℝ) ∂μ) - ∫ x, Real.exp (β * x) ∂μ := by\n simpa only [q] using integral_sub (integrable_const 1) hexpμ\n _ = 1 - EU β μ := by simp [EU]\n have hqνeq : ∫ x, q x ∂ν = 1 - EU β ν := by\n calc\n ∫ x, q x ∂ν = (∫ _x, (1 : ℝ) ∂ν) - ∫ x, Real.exp (β * x) ∂ν := by\n simpa only [q] using integral_sub (integrable_const 1) hexpν\n _ = 1 - EU β ν := by simp [EU]\n calc\n |EU β μ - EU β ν| = |(∫ x, q x ∂μ) - ∫ x, q x ∂ν| := by\n rw [hqμeq, hqνeq,\n show 1 - EU β μ - (1 - EU β ν) = EU β ν - EU β μ by ring,\n abs_sub_comm]\n _ ≤ L * ⨆ x : ℝ,\n |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x| := hmain\n _ = (1 - Real.exp (β * M)) * ⨆ x : ℝ,\n |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x| := by rfl\n\ntheorem lemma6_lipschitz {M β : ℝ} (hM : 0 ≤ M) (hβ : β ≠ 0)\n (μ ν : Measure ℝ) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n (hμ : μ (Set.Icc 0 M) = 1) (hν : ν (Set.Icc 0 M) = 1) :\n (|EU β μ - EU β ν|\n ≤ |Real.exp (β * M) - 1|\n * ⨆ x : ℝ, |ProbabilityTheory.cdf μ x - ProbabilityTheory.cdf ν x|)\n ∧ (0 < M → ∃ μ₀ ν₀ : Measure ℝ, IsProbabilityMeasure μ₀ ∧ IsProbabilityMeasure ν₀ ∧\n μ₀ (Set.Icc 0 M) = 1 ∧ ν₀ (Set.Icc 0 M) = 1 ∧\n 0 < (⨆ x : ℝ, |ProbabilityTheory.cdf μ₀ x - ProbabilityTheory.cdf ν₀ x|) ∧\n |EU β μ₀ - EU β ν₀|\n = |Real.exp (β * M) - 1|\n * ⨆ x : ℝ, |ProbabilityTheory.cdf μ₀ x - ProbabilityTheory.cdf ν₀ x|) := by\n constructor\n · by_cases hβpos : 0 < β\n · have hexp : 1 ≤ Real.exp (β * M) := by\n rw [Real.one_le_exp_iff]\n positivity\n simpa [abs_of_nonneg (sub_nonneg.mpr hexp)] using\n eu_lipschitz_pos hM hβpos μ ν hμ hν\n · have hβneg : β < 0 := lt_of_le_of_ne (le_of_not_gt hβpos) hβ\n have hexp : Real.exp (β * M) ≤ 1 := by\n rw [Real.exp_le_one_iff]\n exact mul_nonpos_of_nonpos_of_nonneg hβneg.le hM\n simpa [abs_of_nonpos (sub_nonpos.mpr hexp)] using\n eu_lipschitz_neg hM hβneg μ ν hμ hν\n · intro hMpos\n let μ₀ : Measure ℝ := Measure.dirac 0\n let ν₀ : Measure ℝ := Measure.dirac M\n have hμ₀prob : IsProbabilityMeasure μ₀ := by\n dsimp [μ₀]\n infer_instance\n have hν₀prob : IsProbabilityMeasure ν₀ := by\n dsimp [ν₀]\n infer_instance\n have hμ₀supp : μ₀ (Set.Icc 0 M) = 1 := by\n simp [μ₀, hM]\n have hν₀supp : ν₀ (Set.Icc 0 M) = 1 := by\n simp [ν₀, hM]\n letI : IsProbabilityMeasure μ₀ := hμ₀prob\n letI : IsProbabilityMeasure ν₀ := hν₀prob\n have hcdfμ₀ : ProbabilityTheory.cdf μ₀ 0 = 1 := by\n rw [ProbabilityTheory.cdf_eq_real, measureReal_def]\n simp [μ₀]\n have hcdfν₀ : ProbabilityTheory.cdf ν₀ 0 = 0 := by\n rw [ProbabilityTheory.cdf_eq_real, measureReal_def]\n simp [ν₀, hMpos.not_ge]\n have hsup : (⨆ x : ℝ,\n |ProbabilityTheory.cdf μ₀ x - ProbabilityTheory.cdf ν₀ x|) = 1 := by\n apply le_antisymm\n · apply ciSup_le\n intro x\n rw [abs_le]\n constructor\n · linarith [ProbabilityTheory.cdf_nonneg μ₀ x,\n ProbabilityTheory.cdf_le_one ν₀ x]\n · linarith [ProbabilityTheory.cdf_nonneg ν₀ x,\n ProbabilityTheory.cdf_le_one μ₀ x]\n · calc\n 1 = |ProbabilityTheory.cdf μ₀ 0 - ProbabilityTheory.cdf ν₀ 0| := by\n rw [hcdfμ₀, hcdfν₀]\n norm_num\n _ ≤ ⨆ x : ℝ,\n |ProbabilityTheory.cdf μ₀ x - ProbabilityTheory.cdf ν₀ x| :=\n cdf_abs_le_iSup μ₀ ν₀ 0\n refine ⟨μ₀, ν₀, hμ₀prob, hν₀prob, hμ₀supp, hν₀supp, ?_, ?_⟩\n · rw [hsup]\n norm_num\n · rw [hsup]\n simp [EU, μ₀, ν₀, abs_sub_comm]\n\nprivate lemma weighted_cdf_sum_sub_le_l1 {n : ℕ}\n (F : Fin n → ℝ → ℝ) (hFrange : ∀ i x, F i x ∈ Set.Icc (0 : ℝ) 1)\n (θ θ' : Fin n → ℝ) (x : ℝ) :\n (∑ i, θ' i * F i x) - (∑ i, θ i * F i x) ≤ ∑ i, |θ i - θ' i| := by\n rw [← Finset.sum_sub_distrib]\n refine Finset.sum_le_sum fun i _ => ?_\n have hF0 : 0 ≤ F i x := (hFrange i x).1\n have hF1 : F i x ≤ 1 := (hFrange i x).2\n calc\n θ' i * F i x - θ i * F i x = (θ' i - θ i) * F i x := by ring\n _ ≤ |(θ' i - θ i) * F i x| := le_abs_self _\n _ = |θ' i - θ i| * F i x := by rw [abs_mul, abs_of_nonneg hF0]\n _ ≤ |θ' i - θ i| * 1 :=\n mul_le_mul_of_nonneg_left hF1 (abs_nonneg _)\n _ = |θ i - θ' i| := by rw [mul_one, abs_sub_comm]\n\ntheorem lemma12_optimistic_bound {n : ℕ} (a b c : ℝ) (hab : a ≤ b) (hc0 : 0 < c)\n (F : Fin n → ℝ → ℝ)\n (hFmono : ∀ i, Monotone (F i))\n (hFright : ∀ i x, ContinuousWithinAt (F i) (Set.Ici x) x)\n (hFrange : ∀ i x, F i x ∈ Set.Icc (0 : ℝ) 1)\n (hFlo : ∀ i x, x < a → F i x = 0)\n (hFhi : ∀ i x, b ≤ x → F i x = 1)\n (θ θ' : Fin n → ℝ)\n (hθnn : ∀ i, 0 ≤ θ i) (hθ'nn : ∀ i, 0 ≤ θ' i)\n (hθsum : ∑ i, θ i = 1) (hθ'sum : ∑ i, θ' i = 1)\n (hc : ∑ i, |θ i - θ' i| ≤ c) :\n ∀ x, optimismInf a b c (fun y => ∑ i, θ' i * F i y) x\n ≤ (∑ i, θ i * F i x) := by\n intro x\n by_cases hxa : x < a\n · have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hxa) hx.1\n simp [optimismInf, hFlo _ x hxa, hxnot]\n · have hax : a ≤ x := le_of_not_gt hxa\n by_cases hxb : x < b\n · have hxmem : x ∈ Set.Ico a b := ⟨hax, hxb⟩\n have hsum0 : 0 �� ∑ i, θ i * F i x :=\n Finset.sum_nonneg fun i _ => mul_nonneg (hθnn i) (hFrange i x).1\n have hdiff :\n (∑ i, θ' i * F i x) - (∑ i, θ i * F i x) ≤ c :=\n (weighted_cdf_sum_sub_le_l1 F hFrange θ θ' x).trans hc\n simp only [optimismInf, Set.indicator_of_mem hxmem, mul_one]\n apply max_le\n · linarith\n · exact hsum0\n · have hbx : b ≤ x := le_of_not_gt hxb\n have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hx.2) hbx\n simp [optimismInf, hFhi _ x hbx, hθsum, hθ'sum, hxnot]\n\nprivate lemma optimismInf_le_of_ball {a b c : ℝ} (hab : a ≤ b)\n (F G : ℝ → ℝ) (hF : InDab a b F) (hG : InDab a b G)\n (hclose : ∀ x, |G x - F x| ≤ c) :\n ∀ x, optimismInf a b c F x ≤ G x := by\n intro x\n by_cases hxa : x < a\n · have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hxa) hx.1\n simp [optimismInf, hxnot, hF.2.2.2.1 x hxa, hG.2.2.2.1 x hxa]\n · have hax : a ≤ x := le_of_not_gt hxa\n by_cases hxb : x < b\n · have hxmem : x ∈ Set.Ico a b := ⟨hax, hxb⟩\n have hbelow : F x - c ≤ G x := by\n have habs := hclose x\n have hneg : -|G x - F x| ≤ G x - F x := neg_abs_le _\n linarith\n simp only [optimismInf, Set.indicator_of_mem hxmem, mul_one]\n exact max_le hbelow (hG.2.1 x).1\n · have hbx : b ≤ x := le_of_not_gt hxb\n have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hx.2) hbx\n simp [optimismInf, hxnot, hF.2.2.2.2 x hbx, hG.2.2.2.2 x hbx]\n\nprivate lemma optimismInf_monotone {a b c : ℝ} (hab : a ≤ b) (hc0 : 0 < c)\n (F : ℝ → ℝ) (hF : InDab a b F) :\n Monotone (optimismInf a b c F) := by\n intro x y hxy\n by_cases hxa : x < a\n · have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hxa) hx.1\n have hxzero : optimismInf a b c F x = 0 := by\n simp [optimismInf, hxnot, hF.2.2.2.1 x hxa]\n rw [hxzero]\n exact le_max_right _ _\n · have hax : a ≤ x := le_of_not_gt hxa\n by_cases hbx : b ≤ x\n · have hby : b ≤ y := hbx.trans hxy\n have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hx.2) hbx\n have hynot : y ∉ Set.Ico a b := fun hy => (not_le_of_gt hy.2) hby\n simp [optimismInf, hxnot, hynot, hF.2.2.2.2 x hbx, hF.2.2.2.2 y hby]\n · have hxb : x < b := lt_of_not_ge hbx\n have hxmem : x ∈ Set.Ico a b := ⟨hax, hxb⟩\n by_cases hyb : y < b\n · have hay : a ≤ y := hax.trans hxy\n have hymem : y ∈ Set.Ico a b := ⟨hay, hyb⟩\n simp only [optimismInf, Set.indicator_of_mem hxmem,\n Set.indicator_of_mem hymem, mul_one]\n exact max_le_max (sub_le_sub_right (hF.1 hxy) c) le_rfl\n · have hby : b ≤ y := le_of_not_gt hyb\n have hynot : y ∉ Set.Ico a b := fun hy => (not_le_of_gt hy.2) hby\n calc\n optimismInf a b c F x ≤ 1 := by\n simp only [optimismInf, Set.indicator_of_mem hxmem, mul_one]\n exact max_le (by linarith [(hF.2.1 x).2]) (by norm_num)\n _ = optimismInf a b c F y := by\n symm\n simp [optimismInf, hynot, hF.2.2.2.2 y hby]\n\nprivate lemma optimismInf_rightContinuous {a b c : ℝ} (hab : a ≤ b) (hc0 : 0 < c)\n (F : ℝ → ℝ) (hF : InDab a b F) :\n ∀ x, ContinuousWithinAt (optimismInf a b c F) (Set.Ici x) x := by\n intro x\n by_cases hxa : x < a\n · have hlt : ∀ᶠ y in nhdsWithin x (Set.Ici x), y < a :=\n Filter.Eventually.filter_mono inf_le_left (Iio_mem_nhds hxa)\n have heq : optimismInf a b c F =ᶠ[nhdsWithin x (Set.Ici x)] fun _ => (0 : ℝ) := by\n filter_upwards [hlt] with y hya\n have hynot : y ∉ Set.Ico a b := fun hy => (not_le_of_gt hya) hy.1\n simp [optimismInf, hynot, hF.2.2.2.1 y hya]\n refine (continuousWithinAt_const :\n ContinuousWithinAt (fun _ : ℝ => (0 : ℝ)) (Set.Ici x) x).congr_of_eventuallyEq heq ?_\n have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hxa) hx.1\n simp [optimismInf, hxnot, hF.2.2.2.1 x hxa]\n · have hax : a ≤ x := le_of_not_gt hxa\n by_cases hxb : x < b\n · have hlt : ∀ᶠ y in nhdsWithin x (Set.Ici x), y < b :=\n Filter.Eventually.filter_mono inf_le_left (Iio_mem_nhds hxb)\n have heq : optimismInf a b c F =ᶠ[nhdsWithin x (Set.Ici x)]\n fun y => max (F y - c) 0 := by\n filter_upwards [hlt, self_mem_nhdsWithin] with y hyb hyx\n have hay : a ≤ y := hax.trans hyx\n have hymem : y ∈ Set.Ico a b := ⟨hay, hyb⟩\n simp [optimismInf, hymem]\n have hcont : ContinuousWithinAt (fun y => max (F y - c) 0) (Set.Ici x) x :=\n ((hF.2.2.1 x).sub continuousWithinAt_const).max continuousWithinAt_const\n refine hcont.congr_of_eventuallyEq heq ?_\n have hxmem : x ∈ Set.Ico a b := ⟨hax, hxb⟩\n simp [optimismInf, hxmem]\n · have hbx : b ≤ x := le_of_not_gt hxb\n refine (continuousWithinAt_const :\n ContinuousWithinAt (fun _ : ℝ => (1 : ℝ)) (Set.Ici x) x).congr ?_ ?_\n · intro y hy\n have hby : b ≤ y := hbx.trans hy\n have hynot : y ∉ Set.Ico a b := fun hmem => (not_le_of_gt hmem.2) hby\n simp [optimismInf, hynot, hF.2.2.2.2 y hby]\n · have hxnot : x ∉ Set.Ico a b := fun hmem => (not_le_of_gt hmem.2) hbx\n simp [optimismInf, hxnot, hF.2.2.2.2 x hbx]\n\nprivate lemma optimismInf_range {a b c : ℝ} (hc0 : 0 < c)\n (F : ℝ → ℝ) (hF : InDab a b F) :\n ∀ x, optimismInf a b c F x ∈ Set.Icc (0 : ℝ) 1 := by\n intro x\n constructor\n · exact le_max_right _ _\n · by_cases hxmem : x ∈ Set.Ico a b\n · simp only [optimismInf, Set.indicator_of_mem hxmem, mul_one]\n apply max_le\n · linarith [(hF.2.1 x).2]\n · norm_num\n · simp [optimismInf, hxmem, max_eq_left (hF.2.1 x).1, (hF.2.1 x).2]\n\nprivate lemma optimismInf_close {a b c : ℝ} (hc0 : 0 < c)\n (F : ℝ → ℝ) (hF : InDab a b F) :\n ∀ x, |optimismInf a b c F x - F x| ≤ c := by\n intro x\n by_cases hxmem : x ∈ Set.Ico a b\n · simp only [optimismInf, Set.indicator_of_mem hxmem, mul_one]\n have hlo : F x - c ≤ max (F x - c) 0 := le_max_left _ _\n have hhi : max (F x - c) 0 ≤ F x := by\n apply max_le\n · linarith\n · exact (hF.2.1 x).1\n rw [abs_le]\n constructor <;> linarith\n · simp [optimismInf, hxmem, max_eq_left (hF.2.1 x).1, le_of_lt hc0]\n\nprivate lemma optimismInf_inDab {a b c : ℝ} (hab : a ≤ b) (hc0 : 0 < c)\n (F : ℝ → ℝ) (hF : InDab a b F) :\n InDab a b (optimismInf a b c F) := by\n refine ⟨optimismInf_monotone hab hc0 F hF, optimismInf_range hc0 F hF,\n optimismInf_rightContinuous hab hc0 F hF, ?_, ?_⟩\n · intro x hxa\n have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hxa) hx.1\n simp [optimismInf, hxnot, hF.2.2.2.1 x hxa]\n · intro x hbx\n have hxnot : x ∉ Set.Ico a b := fun hx => (not_le_of_gt hx.2) hbx\n simp [optimismInf, hxnot, hF.2.2.2.2 x hbx]\n\ntheorem lemma8_optimism_operator_argmax {a b c : ℝ} (hab : a ≤ b) (hc0 : 0 < c)\n (F : ℝ → ℝ) (hF : InDab a b F)\n (ρ : (ℝ → ℝ) → ℝ)\n (hρM : ∀ P Q : ℝ → ℝ, InDab a b P → InDab a b Q → (∀ x, P x ≤ Q x) → ρ Q ≤ ρ P) :\n (∀ G : ℝ → ℝ, InDab a b G → (∀ x, |G x - F x| ≤ c) →\n ∀ x, optimismInf a b c F x ≤ G x)\n ∧ ( InDab a b (optimismInf a b c F)\n ∧ (∀ x, |optimismInf a b c F x - F x| ≤ c)\n ∧ (∀ G : ℝ → ℝ, InDab a b G → (∀ x, |G x - F x| ≤ c) →\n ρ G ≤ ρ (optimismInf a b c F)) ) := by\n have hO : InDab a b (optimismInf a b c F) := optimismInf_inDab hab hc0 F hF\n have hcloseO : ∀ x, |optimismInf a b c F x - F x| ≤ c :=\n optimismInf_close hc0 F hF\n refine ⟨?_, hO, hcloseO, ?_⟩\n · intro G hG hcloseG\n exact optimismInf_le_of_ball hab F G hF hG hcloseG\n · intro G hG hcloseG\n exact hρM (optimismInf a b c F) G hO hG\n (optimismInf_le_of_ball hab F G hF hG hcloseG)\n\nend ResearchLevel\n"} +{"id": "ch1_proposition_1_11", "source": "Graduate-level", "targets": [{"label": "ch1_proposition_1_11", "decls": ["ch1_proposition_1_11"], "statement": "If \\(f\\) is twice continuously differentiable on its domain \\(\\Omega\\), then \\(f\\) is convex if and only if \\(\\nabla^2 f(x)\\succeq 0\\) for all \\(x\\in\\Omega\\).", "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}], "nl_proof": "Suppose \\(f\\) is convex and our goal is to show that the Hessian is positive semidefinite. Let \\(y=x + \\alpha u\\) for some arbitrary vector \\(u\\) and scalar \\(\\alpha\\). Proposition first-order-lower-bound shows\n\\[\nf(y) - f(x) -\\nabla f(x)^\\top (y-x) \\geqslant 0\n\\]\nHence, by Proposition first-order-taylor,\n\\begin{align*}\n0&\\leqslant \\int_0^1 (1-\\gamma)\\frac{\\partial^2 f(x+\\gamma(y-x))}{\\partial\\gamma^2}\\,\\mathrm{d}\\gamma\\\\\n&= (1-\\gamma)\\frac{\\partial^2 f(x+\\gamma(y-x))}{\\partial\\gamma^2}\n\\quad\\text{for some $\\gamma\\in(0,1)$} \\tag{by the mean value theorem}\\\\\n&= (1-\\gamma)(y-x)^\\top \\nabla^2 f(x+\\gamma (y-x))(y-x)\n\\tag{by Fact 1d-nd-hessian}\\,.\n\\end{align*}\nPlugging in our choice of \\(y\\), this shows \\(0\\leqslant u^\\top \\nabla^2 f(x+\\alpha\\gamma u)u\\). Letting \\(\\alpha\\) tend to zero establishes that \\(\\nabla^2 f(x)\\succeq 0\\). (Note that \\(\\gamma\\) generally depends on \\(\\alpha\\) but is always bounded by \\(1\\).)\n\nNow, suppose the Hessian is positive semidefinite everywhere in \\(\\Omega\\) and our goal is to show that the function \\(f\\) is convex. Using the same derivation as above, we can see that the second-order error term in Taylor's theorem must be non-negative. Hence, the first-order approximation is a global lower bound and so the function \\(f\\) is convex by Proposition first-order-lower-bound.", "context": [{"id": "ch1:proposition:1_8", "name": "proposition 1.8", "statement": "Assume \\(f\\colon\\Omega\\to\\mathbb{R}\\) is differentiable. Then, \\(f\\) is convex if and only if for all \\(x,y\\in\\Omega\\) we have\n\\[\nf(y) \\geqslant f(x) + \\nabla f(x)^\\top (y-x)\\,.\n\\]"}, {"id": "ch1:proposition:1_7", "name": "proposition 1.7", "statement": "Assume \\(f\\colon\\Omega\\to\\mathbb{R}\\) is continuously differentiable along the line segment between two points \\(x\\) and \\(y\\). Then,\n\\[\nf(y) = f(x)\n+ \\nabla f(x)^\\top (y-x)\n+ \\int_0^1 (1-\\gamma)\\frac{\\partial^2 f(x+\\gamma(y-x))}{\\partial\\gamma^2}\\,\\mathrm{d}\\gamma\n\\]"}, {"id": "ch1:definition:1_3", "name": "Convex function", "statement": "A function \\(f\\colon\\Omega\\to\\mathbb{R}\\) is convex if for all \\(x,y\\in\\Omega\\) and all scalars \\(\\gamma\\in[0,1]\\) we have \\(f(\\gamma x+(1-\\gamma)y)\\leqslant \\gamma f(x)+(1-\\gamma)f(y)\\)."}], "lean": "import Mathlib\n\nopen scoped RealInnerProductSpace\n\nnamespace GraduateLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]\n\ntheorem ch1_proposition_1_11 {f : E → ℝ} {s : Set E}\n (hs : Convex ℝ s) (hs_open : IsOpen s) (hf : ContDiffOn ℝ 2 f s) :\n ConvexOn ℝ s f ↔ ∀ x ∈ s, ∀ u : E, 0 ≤ iteratedFDeriv ℝ 2 f x ![u, u] := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped RealInnerProductSpace\n\nnamespace GraduateLevel\n\nvariable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]\n\ntheorem ch1_proposition_1_11 {f : E → ℝ} {s : Set E}\n (hs : Convex ℝ s) (hs_open : IsOpen s) (hf : ContDiffOn ℝ 2 f s) :\n ConvexOn ℝ s f ↔ ∀ x ∈ s, ∀ u : E, 0 ≤ iteratedFDeriv ℝ 2 f x ![u, u] := by\n let A (a u : E) : ℝ →ᵃ[ℝ] E :=\n { toFun := fun t ↦ a + t • u\n linear := LinearMap.toSpanSingleton ℝ E u\n map_vadd' := by\n intro p v\n simp only [LinearMap.toSpanSingleton_apply, vadd_eq_add, add_smul]\n module }\n have hA (a u : E) (t : ℝ) : A a u t = a + t • u := rfl\n have hdiff (x : E) (hx : x ∈ s) :\n HasFDerivAt f (fderiv ℝ f x) x :=\n ((hf.contDiffAt (hs_open.mem_nhds hx)).differentiableAt (by norm_num)).hasFDerivAt\n have hline (a u : E) (t : ℝ) (ht : a + t • u ∈ s) :\n HasDerivAt (fun r : ℝ ↦ f (a + r • u)) (fderiv ℝ f (a + t • u) u) t := by\n apply (hdiff _ ht).comp_hasDerivAt t\n simpa using ((hasDerivAt_id t).smul_const u).const_add a\n have hline2 (a u : E) (t : ℝ) (ht : a + t • u ∈ s) :\n HasDerivAt (fun r : ℝ ↦ fderiv ℝ f (a + r • u) u)\n (iteratedFDeriv ℝ 2 f (a + t • u) ![u, u]) t := by\n have hp := hf.contDiffAt (hs_open.mem_nhds ht)\n have hfd : HasFDerivAt (fderiv ℝ f)\n (fderiv ℝ (fderiv ℝ f) (a + t • u)) (a + t • u) :=\n ((hp.fderiv_right (m := 1) (by norm_num)).differentiableAt (by norm_num)).hasFDerivAt\n have he := (ContinuousLinearMap.apply ℝ ℝ u).hasFDerivAt.comp (a + t • u) hfd\n have hin : HasDerivAt (fun r : ℝ ↦ a + r • u) u t := by\n simpa using ((hasDerivAt_id t).smul_const u).const_add a\n have hc := he.comp_hasDerivAt t hin\n simpa [iteratedFDeriv_two_apply] using hc\n constructor\n · intro hconv x hx u\n let T : Set ℝ := (A x u) ⁻¹' s\n have hTopen : IsOpen T := hs_open.preimage\n (continuous_const.add (continuous_id.smul continuous_const))\n have hTconv : Convex ℝ T := hs.affine_preimage (A x u)\n have hgc : ConvexOn ℝ T (fun t ↦ f (x + t • u)) := by\n simpa [T, A, Function.comp_def] using hconv.comp_affineMap (A x u)\n have hgd : ∀ t ∈ T, DifferentiableAt ℝ (fun r ↦ f (x + r • u)) t := by\n intro t ht\n exact (hline x u t ht).differentiableAt\n have hmono := hgc.monotoneOn_deriv hgd\n have hz : (0 : ℝ) ∈ T := by simpa [T, A] using hx\n have hqmono : MonotoneOn (fun t ↦ fderiv ℝ f (x + t • u) u) T := by\n intro a ha b hb hab\n simpa [(hline x u a ha).deriv, (hline x u b hb).deriv] using hmono ha hb hab\n have hd2 := hline2 x u 0 (by simpa using hx)\n have := hqmono.derivWithin_nonneg (x := (0 : ℝ))\n rw [derivWithin_of_isOpen hTopen hz, hd2.deriv] at this\n simpa using this\n · intro hpos\n rw [ConvexOn]\n refine ⟨hs, ?_⟩\n intro x hx y hy a b ha hb hab\n let g : ℝ → ℝ := fun t ↦ f (x + t • (y - x))\n have hseg (t : ℝ) (ht : t ∈ Set.Icc (0 : ℝ) 1) : x + t • (y - x) ∈ s :=\n hs.add_smul_sub_mem hx hy ht\n have hg' : ∀ t ∈ Set.Icc (0 : ℝ) 1,\n HasDerivWithinAt g (fderiv ℝ f (x + t • (y - x)) (y - x)) (Set.Icc 0 1) t := by\n intro t ht\n exact (hline x (y-x) t (hseg t ht)).hasDerivWithinAt\n have hg'' : ∀ t ∈ Set.Icc (0 : ℝ) 1,\n HasDerivWithinAt (fun r ↦ fderiv ℝ f (x + r • (y-x)) (y-x))\n (iteratedFDeriv ℝ 2 f (x + t • (y-x)) ![y-x, y-x]) (Set.Icc 0 1) t := by\n intro t ht\n exact (hline2 x (y-x) t (hseg t ht)).hasDerivWithinAt\n have hgc : ConvexOn ℝ (Set.Icc (0 : ℝ) 1) g := by\n apply convexOn_of_hasDerivWithinAt2_nonneg (f' := fun t ↦\n fderiv ℝ f (x + t • (y-x)) (y-x)) (f'' := fun t ↦\n iteratedFDeriv ℝ 2 f (x + t • (y-x)) ![y-x, y-x]) (convex_Icc 0 1)\n · exact fun t ht ↦ (hg' t ht).continuousWithinAt\n · intro t ht; exact (hg' t (interior_subset ht)).mono interior_subset\n · intro t ht; exact (hg'' t (interior_subset ht)).mono interior_subset\n · intro t ht; exact hpos _ (hseg t (interior_subset ht)) _\n have hc := hgc.2 (x := (0 : ℝ)) (y := (1 : ℝ)) (by simp) (by simp) ha hb hab\n have heq : x + b • (y - x) = a • x + b • y := by\n have ha' : a = 1 - b := by linarith\n rw [ha']\n module\n simpa [g, heq, smul_eq_mul] using hc\n\nend GraduateLevel"} +{"id": "ch11_theorem_11_6", "source": "Graduate-level", "targets": [{"label": "ch11_theorem_11_6", "decls": ["ch11_theorem_11_6"], "statement": "Assume \\(\\ell(w, z)\\) is \\(\\alpha\\)-strongly convex over the domain \\(\\Omega\\) and \\(L\\)-Lipschitz. Let \\(\\hat w_S = \\arg \\min_{w\\in \\Omega} \\frac{1}{m} \\sum_{i=1}^m \\ell(w, z_i)\\) denote the empirical risk minimizer (ERM). Then, ERM satisfies\n\\[\n\\Delta_{\\sup} (\\text{ERM}) \\leqslant \\frac{4L^2}{\\alpha m}\\,.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Denote by \\(\\hat w_S\\) the empirical risk minimizer on a sample \\(S.\\) Fix arbitrary samples \\(S,S'\\) of size \\(m\\) and an index \\(i\\in[m].\\) We need to show that\n\\[\n|(\\ell(\\hat w_{S^{(i)}},z_i')-\\ell(\\hat w_{S},z_i'))|\\leqslant\\frac{4L^2}{\\alpha m}\\,.\n\\]\nOn one hand, by strong convexity we know that\n\\[\nR_S(\\hat w_{S^{(i)}}) - R_S(\\hat w_{S}) \\geqslant \\frac{\\alpha}{2} \\| \\hat w_{S} - \\hat w_{S^{(i)}} \\|^2 \\,.\n\\]\nOn the other hand,\n\\begin{align*}\n&R_S(\\hat w_{S^{(i)}})-R_S(\\hat w_{S})\\\\\n&=\\frac{1}{m}(\\ell(\\hat w_{S^{(i)}},z_i)-\\ell(\\hat w_{S},z_i))+\\frac{1}{m}\\sum_{i\\neq j}(\\ell(\\hat w_{S^{(i)}},z_j)-\\ell(\\hat w_{S},z_j))\\\\\n&=\\frac{1}{m}(\\ell(\\hat w_{S^{(i)}},z_i)-\\ell(\\hat w_{S},z_i))+\\frac{1}{m}(\\ell(\\hat w_{S},z_i')-\\ell(\\hat w_{S^{(i)}},z_i'))+\\left(R_{S^{(i)}}(\\hat w_{S^{(i)}})-R_{S^{(i)}}(\\hat w_{S})\\right)\\\\\n&\\leqslant\\frac{1}{m}|\\ell(\\hat w_{S^{(i)}},z_i)-\\ell(\\hat w_{S},z_i)| +\\frac{1}{m}|(\\ell(\\hat w_{S},z_i')-\\ell(\\hat w_{S^{(i)}},z_i'))|\\\\\n&\\leqslant\\frac{2L}{m}\\|\\hat w_{S^{(i)}}-\\hat w_{S}\\|\\,.\n\\end{align*}\nHere, we used that\n\\[\nR_{S^{(i)}}(\\hat w_{S^{(i)}}) - R_{S^{(i)}}(\\hat w_{S})) \\leqslant 0\n\\]\nand the fact that \\(\\ell\\) is \\(L\\)-Lipschitz.\n\nPutting it all together \\(\\| \\hat w_{S^{(i)}} - \\hat w_{S} \\| \\leqslant \\frac{4 L}{\\alpha m}\\). Then by the Lipschitz condition we have that\n\\[\n\\frac{1}{m}|(\\ell(\\hat w_{S^{(i)}},z_i')-\\ell(\\hat w_{S},z_i'))|\\leqslant L\\|\\hat w_{S^{(i)}}-\\hat w_{S}\\|\\leqslant\\frac{4L^2}{\\alpha m}\\,.\n\\]\nHence, \\(\\Delta_{\\sup}(\\text{ERM}) \\leqslant \\frac{4 L ^ 2}{\\alpha m}\\).", "context": [{"id": "ch3:definition:3_1", "name": "Strong convexity", "statement": "A function \\(f\\colon\\Omega\\to\\mathbb{R}\\) is \\emph{\\(\\alpha\\)-strongly convex} if, for all \\(x,y\\in\\Omega\\), the following inequality holds for some \\(\\alpha>0\\): \\[ f(y) \\geqslant f(x) + g(x)^\\top(y-x) + \\frac{\\alpha}{2}\\left\\lVert x-y\\right\\rVert^2 \\]"}, {"id": "ch11:definition:11_4", "name": "Uniform stability", "statement": "The uniform stability of an algorithm \\(A\\) is defined as\n\\[\n\\Delta_{\\sup}(A) = \\sup_{S, S' \\in (X\\times Y)^m } \\sup_{i \\in [m]} |\\ell(A(S), z_i') - \\ell(A(S^{(i)}, z_i')|\n\\]"}], "lean": "import Mathlib\n\nopen scoped BigOperators\nopen Metric\n\nnamespace GraduateLevel\n\nnoncomputable def empRisk {E Z : Type*} {m : ℕ} (ℓ : E → Z → ℝ) (S : Fin m → Z) (w : E) : ℝ :=\n (1 / (m : ℝ)) * ∑ i, ℓ w (S i)\n\ntheorem ch11_theorem_11_6\n {E Z : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n {Ω : Set E} (hΩconv : Convex ℝ Ω) (hΩne : Ω.Nonempty)\n (ℓ : E → Z → ℝ) (α L : ℝ) (hα : 0 < α) (hL : 0 ≤ L)\n (m : ℕ) (hm : 0 < m)\n (hsc : ∀ z : Z, StrongConvexOn Ω α (fun w => ℓ w z))\n (hLip : ∀ z : Z, ∀ w ∈ Ω, ∀ w' ∈ Ω, |ℓ w z - ℓ w' z| ≤ L * ‖w - w'‖)\n (erm : (Fin m → Z) → E)\n (herm : ∀ S : Fin m → Z, IsMinOn (empRisk ℓ S) Ω (erm S) ∧ erm S ∈ Ω) :\n ∀ (S S' : Fin m → Z) (i : Fin m),\n |ℓ (erm (Function.update S i (S' i))) (S' i) - ℓ (erm S) (S' i)|\n ≤ 4 * L ^ 2 / (α * m) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\nopen scoped BigOperators\nopen Metric\n\nnamespace GraduateLevel\n\nprivate lemma Strongly_Convex_Bound {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n {s : Set E} {f : E → ℝ} (m : ℝ) (strongly_convex : StrongConvexOn s m f) :\n ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s →\n ∀ ⦃a⦄, 0 < a → ∀ ⦃b⦄, 0 < b → a + b = 1 → f (a • x + b • y)\n ≤ a * f x + b * f y - m / 2 * a * b * ‖x - y‖ ^ 2 := by\n intro x xs y ys a ap b bp abp\n rcases strongly_convex with ⟨_, sc⟩\n have anneg : a ≥ 0 := by linarith\n have bnneg : b ≥ 0 := by linarith\n rcases sc xs ys anneg bnneg abp with ineq\n simp at ineq\n rw [mul_comm (m / 2), mul_assoc a, mul_comm (m / 2), ← mul_assoc, mul_assoc (a * b)]\n apply ineq\n\nnoncomputable def empRisk {E Z : Type*} {m : ℕ} (ℓ : E → Z → ℝ) (S : Fin m → Z) (w : E) : ℝ :=\n (1 / (m : ℝ)) * ∑ i, ℓ w (S i)\n\ntheorem ch11_theorem_11_6\n {E Z : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n {Ω : Set E} (hΩconv : Convex ℝ Ω) (hΩne : Ω.Nonempty)\n (ℓ : E → Z → ℝ) (α L : ℝ) (hα : 0 < α) (hL : 0 ≤ L)\n (m : ℕ) (hm : 0 < m)\n (hsc : ∀ z : Z, StrongConvexOn Ω α (fun w => ℓ w z))\n (hLip : ∀ z : Z, ∀ w ∈ Ω, ∀ w' ∈ Ω, |ℓ w z - ℓ w' z| ≤ L * ‖w - w'‖)\n (erm : (Fin m → Z) → E)\n (herm : ∀ S : Fin m → Z, IsMinOn (empRisk ℓ S) Ω (erm S) ∧ erm S ∈ Ω) :\n ∀ (S S' : Fin m → Z) (i : Fin m),\n |ℓ (erm (Function.update S i (S' i))) (S' i) - ℓ (erm S) (S' i)|\n ≤ 4 * L ^ 2 / (α * m) := by\n have hmR : (0:ℝ) < m := by exact_mod_cast hm\n -- quadratic growth around a minimizer of the empirical risk\n have main : ∀ (P : Fin m → Z) (a b : E), a ∈ Ω → b ∈ Ω → IsMinOn (empRisk ℓ P) Ω a →\n α / 4 * ‖a - b‖ ^ 2 ≤ empRisk ℓ P b - empRisk ℓ P a := by\n intro P a b ha hb hmin\n have hc : ((1:ℝ)/2) • a + ((1:ℝ)/2) • b ∈ Ω :=\n hΩconv ha hb (by norm_num) (by norm_num) (by norm_num)\n have h1 : ∀ j : Fin m, ℓ (((1:ℝ)/2) • a + ((1:ℝ)/2) • b) (P j)\n ≤ (1/2) * ℓ a (P j) + (1/2) * ℓ b (P j) - α / 2 * (1/2) * (1/2) * ‖a - b‖ ^ 2 := by\n intro j\n exact Strongly_Convex_Bound α (hsc (P j)) ha hb\n (by norm_num) (by norm_num) (by norm_num)\n have hsum : ∑ j, ℓ (((1:ℝ)/2) • a + ((1:ℝ)/2) • b) (P j)\n ≤ ∑ j : Fin m, ((1/2) * ℓ a (P j) + (1/2) * ℓ b (P j)\n - α / 2 * (1/2) * (1/2) * ‖a - b‖ ^ 2) :=\n Finset.sum_le_sum (fun j _ => h1 j)\n rw [Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum,\n Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hsum\n have hle : empRisk ℓ P a ≤ empRisk ℓ P (((1:ℝ)/2) • a + ((1:ℝ)/2) • b) :=\n isMinOn_iff.mp hmin _ hc\n simp only [empRisk] at hle ⊢\n have hmne : (m:ℝ) ≠ 0 := ne_of_gt hmR\n have hpos : (0:ℝ) ≤ 1 / (m:ℝ) := by positivity\n have hC := mul_le_mul_of_nonneg_left hsum hpos\n have expand : (1 / (m:ℝ)) * (1 / 2 * ∑ j, ℓ a (P j) + 1 / 2 * ∑ j, ℓ b (P j)\n - (m:ℝ) * (α / 2 * (1/2) * (1/2) * ‖a - b‖ ^ 2))\n = (1/2) * ((1 / (m:ℝ)) * ∑ j, ℓ a (P j)) + (1/2) * ((1 / (m:ℝ)) * ∑ j, ℓ b (P j))\n - α / 8 * ‖a - b‖ ^ 2 := by\n field_simp; ring\n rw [expand] at hC\n linarith\n intro S S' i\n set T := Function.update S i (S' i) with hT\n set u := erm S with hu\n set v := erm T with hv\n have huΩ : u ∈ Ω := (herm S).2\n have hvΩ : v ∈ Ω := (herm T).2\n have h1 : α / 4 * ‖u - v‖ ^ 2 ≤ empRisk ℓ S v - empRisk ℓ S u :=\n main S u v huΩ hvΩ (herm S).1\n have h2 : α / 4 * ‖v - u‖ ^ 2 ≤ empRisk ℓ T u - empRisk ℓ T v :=\n main T v u hvΩ huΩ (herm T).1\n rw [norm_sub_rev v u] at h2\n -- difference of the two empirical risks\n have hdiff : ∀ w : E, empRisk ℓ S w - empRisk ℓ T w\n = (1 / (m:ℝ)) * (ℓ w (S i) - ℓ w (S' i)) := by\n intro w\n simp only [empRisk, ← mul_sub]\n congr 1\n rw [← Finset.sum_sub_distrib]\n rw [Finset.sum_eq_single i]\n · simp [hT]\n · intro j _ hj\n simp [hT, Function.update_of_ne hj]\n · intro h; exact absurd (Finset.mem_univ i) h\n have hsum2 : α / 2 * ‖u - v‖ ^ 2\n ≤ (1 / (m:ℝ)) * ((ℓ v (S i) - ℓ u (S i)) + (ℓ u (S' i) - ℓ v (S' i))) := by\n have e1 := hdiff u\n have e2 := hdiff v\n have : (empRisk ℓ S v - empRisk ℓ S u) + (empRisk ℓ T u - empRisk ℓ T v)\n = (1 / (m:ℝ)) * ((ℓ v (S i) - ℓ u (S i)) + (ℓ u (S' i) - ℓ v (S' i))) := by\n have := e1; have := e2\n nlinarith [e1, e2]\n linarith [h1, h2, this.symm.le, this.le]\n have hLip1 : ℓ v (S i) - ℓ u (S i) ≤ L * ‖u - v‖ := by\n have := hLip (S i) v hvΩ u huΩ\n have h := (abs_le.mp this).2\n rw [norm_sub_rev] at h\n linarith\n have hLip2 : ℓ u (S' i) - ℓ v (S' i) ≤ L * ‖u - v‖ := by\n have := hLip (S' i) u huΩ v hvΩ\n exact le_trans (abs_le.mp this).2 (le_refl _)\n have hmpos : (0:ℝ) < 1 / (m:ℝ) := by positivity\n have hstep : α / 2 * ‖u - v‖ ^ 2 ≤ (1 / (m:ℝ)) * (2 * L * ‖u - v‖) := by\n refine le_trans hsum2 ?_\n apply mul_le_mul_of_nonneg_left _ (le_of_lt hmpos)\n linarith\n have hd : ‖u - v‖ ≤ 4 * L / (α * m) := by\n rcases eq_or_lt_of_le (norm_nonneg (u - v)) with h0 | h0\n · rw [← h0]\n positivity\n · rw [le_div_iff₀ (by positivity)]\n have hm2 := mul_le_mul_of_nonneg_right hstep (le_of_lt hmR)\n have hrw : (1 / (m:ℝ) * (2 * L * ‖u - v‖)) * (m:ℝ) = 2 * L * ‖u - v‖ := by\n field_simp\n rw [hrw] at hm2\n nlinarith [hm2, h0]\n have hfinal : |ℓ v (S' i) - ℓ u (S' i)| ≤ L * ‖u - v‖ := by\n have := hLip (S' i) v hvΩ u huΩ\n rwa [norm_sub_rev] at this\n refine le_trans hfinal ?_\n have : L * ‖u - v‖ ≤ L * (4 * L / (α * m)) := by\n exact mul_le_mul_of_nonneg_left hd hL\n refine le_trans this (le_of_eq ?_)\n field_simp\n\nend GraduateLevel\n"} +{"id": "ch13_proposition_13_2", "source": "Graduate-level", "targets": [{"label": "ch13_proposition_13_2", "decls": ["ch13_proposition_13_2"], "statement": "Let \\(\\Omega \\subseteq \\mathbb{R}^d\\) be a closed convex set. Let \\(\\mathcal{A}\\) denote the affine set \\(\\{x : Ax = b\\}\\) for some \\(A \\in \\mathbb{R}^{n \\times d}\\) and \\(b \\in \\mathbb{R}^n\\). Suppose that the set \\(\\operatorname{ri}(\\Omega) \\cap \\mathcal{A}\\) is non-empty. Then for any \\(x \\in \\Omega \\cap \\mathcal{A}\\), \\[\\mathcal{N}_{\\Omega \\cap \\mathcal{A}}(x) = \\mathcal{N}_{\\Omega}(x) + \\{A^\\top \\lambda : \\lambda \\in \\mathbb{R}^n\\}\\,.\\]", "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}], "nl_proof": "The ``\\(\\supseteq\\)'' assertion is straightforward. To see this, suppose \\(z \\in \\Omega \\cap \\mathcal{A}\\) and note that \\(z-x \\in \\operatorname{null}(A)\\) so that \\((z-x)^\\top A^\\top \\lambda = \\lambda^\\top A(z-x) = 0\\) for all \\(\\lambda \\in \\mathbb{R}^n\\). If \\(u \\in \\mathcal{N}_{\\Omega}(x)\\), then \\((z-x)^\\top u \\leqslant 0\\), so for \\(\\lambda \\in \\mathbb{R}^n\\), we have \\[\\langle z-x, u + A^\\top \\lambda \\rangle = \\langle z-x, u \\rangle \\leqslant 0\\] implying that \\(u + A^\\top \\lambda \\in \\mathcal{N}_{\\Omega \\cap \\mathcal{A}}(x)\\). For the reverse inclusion, let \\(v \\in \\mathcal{N}_{\\Omega \\cap \\mathcal{A}}(x)\\). Then we have \\[v^\\top (z-x) \\leqslant 0 \\text{ for all } z \\in \\Omega \\cap \\mathcal{A}.\\] Now define the sets \\[\\begin{aligned} C_1 &= \\left\\{ (y,\\mu) \\in \\mathbb{R}^{d+1} : y = z-x,\\,\\, z \\in \\Omega,\\,\\, \\mu \\leqslant v^\\top y \\right\\}\\\\ C_2 &= \\left\\{ (y,\\mu) \\in \\mathbb{R}^{d+1} : y \\in \\operatorname{ker}(A),\\,\\, \\mu = 0 \\right\\}\\,. \\end{aligned}\\] Note that \\(\\operatorname{ri}(C_1) \\cap C_2 = \\emptyset\\) because otherwise there would exist a \\((\\hat{y},\\hat{\\mu})\\) such that \\[v^\\top \\hat{y} > \\hat{\\mu} = 0\\] and \\(\\hat{y} \\in \\mathcal{T}_{\\Omega \\cap \\mathcal{A}}(x)\\). This would contradict our assumption that \\(v \\in \\mathcal{N}_{\\Omega \\cap \\mathcal{A}}(x)\\). Since their intersection is empty, we can properly separate \\(\\operatorname{ri}(C_1)\\) from \\(C_2\\). Indeed, since \\(C_2\\) is a subspace and \\(C_1\\) has nonempty relative interior, there must be a \\((w,\\gamma)\\) such that \\[\\inf_{(y,\\mu)\\in C_1} \\{ w^\\top y + \\gamma \\mu\\} < \\sup_{(y,\\mu)\\in C_1} \\{ w^\\top y + \\gamma \\mu\\} \\leqslant 0\\] while \\[w^\\top u = 0 \\text{ for all } u \\in \\ker(A).\\] In particular, this means that \\(w = A^\\top \\lambda\\) for some \\(\\lambda \\in \\mathbb{R}^n\\). Now, \\(\\gamma\\) must be nonnegative, as otherwise, \\[\\sup_{(y,\\mu)\\in C_1} \\{ w^\\top y + \\gamma \\mu\\} = \\infty\\] (which can be seen by letting \\(\\mu\\) tend to negative infinity). If \\(\\gamma = 0\\), then \\[\\sup_{y \\in C_1} w^\\top y \\leqslant 0\\] but the set \\(\\{y : w^\\top y = 0\\}\\) does not contain the set \\(\\{z-x : z \\in \\Omega\\}\\) as the infimum is strictly negative. This means that the relative interior of \\(\\Omega - \\{x\\}\\) cannot intersect the kernel of \\(A\\) which contradicts our assumptions. Thus, we can conclude that \\(\\gamma\\) is strictly positive. By homogeneity, we may as well assume that \\(\\gamma = 1\\). To complete the argument, note that we now have \\[(w+v)^\\top (z-x) \\leqslant 0 \\text{ for all } z \\in \\Omega.\\] This means that \\(v+w \\in \\mathcal{N}_{\\Omega}(x)\\) and we have already shown that \\(w = A^\\top \\lambda\\). Thus, \\[v = (v+w)-w \\in \\mathcal{N}_{\\Omega}(x) + \\mathcal{N}_{\\mathcal{A}}(x)\\,.\\]", "context": [{"id": "ch1:definition:1_1", "name": "Convex set", "statement": "A set \\(K\\subseteq\\mathbb{R}^n\\) is convex if the line segment between any two points in \\(K\\) is also contained in \\(K\\). Formally, for all \\(x,y\\in K\\) and all scalars \\(\\gamma\\in[0,1]\\) we have \\(\\gamma x+(1-\\gamma)y\\in K\\)."}], "lean": "import Mathlib\n\nopen scoped Pointwise RealInnerProductSpace\n\nnamespace GraduateLevel\n\ndef normalCone {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (S : Set E) (x : E) : Set E :=\n {u | ∀ z ∈ S, inner ℝ (z - x) u ≤ 0}\n\ntheorem ch13_proposition_13_2\n {d n : ℕ}\n (Ω : Set (EuclideanSpace ℝ (Fin d)))\n (hΩclosed : IsClosed Ω) (hΩconvex : Convex ℝ Ω)\n (A : EuclideanSpace ℝ (Fin d) →ₗ[ℝ] EuclideanSpace ℝ (Fin n))\n (b : EuclideanSpace ℝ (Fin n))\n (𝒜 : Set (EuclideanSpace ℝ (Fin d)))\n (h𝒜 : 𝒜 = {x | A x = b})\n (hCQ : (intrinsicInterior ℝ Ω ∩ 𝒜).Nonempty)\n (x : EuclideanSpace ℝ (Fin d)) (hx : x ∈ Ω ∩ 𝒜) :\n normalCone (Ω ∩ 𝒜) x\n = normalCone Ω x\n + Set.range (fun μ : EuclideanSpace ℝ (Fin n) => (LinearMap.adjoint A) μ) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped Pointwise RealInnerProductSpace\n\nnamespace GraduateLevel\n\nset_option maxHeartbeats 800000\n\ndef normalCone {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (S : Set E) (x : E) : Set E :=\n {u | ∀ z ∈ S, inner ℝ (z - x) u ≤ 0}\n\ntheorem ch13_proposition_13_2\n {d n : ℕ}\n (Ω : Set (EuclideanSpace ℝ (Fin d)))\n (hΩclosed : IsClosed Ω) (hΩconvex : Convex ℝ Ω)\n (A : EuclideanSpace ℝ (Fin d) →ₗ[ℝ] EuclideanSpace ℝ (Fin n))\n (b : EuclideanSpace ℝ (Fin n))\n (𝒜 : Set (EuclideanSpace ℝ (Fin d)))\n (h𝒜 : 𝒜 = {x | A x = b})\n (hCQ : (intrinsicInterior ℝ Ω ∩ 𝒜).Nonempty)\n (x : EuclideanSpace ℝ (Fin d)) (hx : x ∈ Ω ∩ 𝒜) :\n normalCone (Ω ∩ 𝒜) x\n = normalCone Ω x\n + Set.range (fun μ : EuclideanSpace ℝ (Fin n) => (LinearMap.adjoint A) μ) := by\n classical\n let E := EuclideanSpace ℝ (Fin d)\n let H : Submodule ℝ E := LinearMap.ker A\n let L : Submodule ℝ E := (affineSpan ℝ Ω).direction\n let S : Submodule ℝ E := H ⊔ L\n have hxΩ : x ∈ Ω := by\n rw [← hΩclosed.closure_eq]\n exact subset_closure hx.1\n have hxA : A x = b := by\n have := hx.2\n rw [h𝒜] at this\n exact this\n obtain ⟨x₀, hx₀ri, hx₀A⟩ := hCQ\n have hx₀Ω : x₀ ∈ Ω := intrinsicInterior_subset hx₀ri\n have hx₀eq : A x₀ = b := by\n rw [h𝒜] at hx₀A\n exact hx₀A\n have hdiffH : x₀ - x ∈ H := by\n change A (x₀ - x) = 0\n rw [map_sub, hx₀eq, hxA, sub_self]\n have hdiffL (z : E) (hz : z ∈ Ω) : z - x ∈ L := by\n exact AffineSubspace.vsub_mem_direction\n (subset_affineSpan ℝ Ω hz) (subset_affineSpan ℝ Ω hxΩ)\n have hdiffS (z : E) (hz : z ∈ Ω) : z - x ∈ S :=\n show z - x ∈ H ⊔ L from Submodule.mem_sup.2\n ⟨0, H.zero_mem, z - x, hdiffL z hz, zero_add _⟩\n let K : ConvexCone ℝ S :=\n { carrier := {y | ∃ c : ℝ, 0 ≤ c ∧ ∃ z ∈ Ω, (y : E) = c • (z - x)}\n smul_mem' := by\n rintro a ha y ⟨c, hc, z, hz, hy⟩\n refine ⟨a * c, mul_nonneg ha.le hc, z, hz, ?_⟩\n simp only [Submodule.coe_smul, hy, mul_smul]\n add_mem' := by\n rintro y ⟨c, hc, z, hz, hy⟩ w ⟨e, he, t, ht, hw⟩\n by_cases hs : c + e = 0\n · have hc0 : c = 0 := by linarith\n have he0 : e = 0 := by linarith\n refine ⟨0, le_rfl, x, hxΩ, ?_⟩\n simp [hy, hw, hc0, he0]\n · have hspos : 0 < c + e := lt_of_le_of_ne (add_nonneg hc he) (Ne.symm hs)\n let z' : E := (c / (c + e)) • z + (e / (c + e)) • t\n have hz' : z' ∈ Ω := by\n apply hΩconvex hz ht\n · exact div_nonneg hc hspos.le\n · exact div_nonneg he hspos.le\n · field_simp\n refine ⟨c + e, hspos.le, z', hz', ?_⟩\n simp only [Submodule.coe_add, hy, hw]\n dsimp [z']\n have hc' : (c + e) * (c / (c + e)) = c := by\n field_simp\n have he' : (c + e) * (e / (c + e)) = e := by\n field_simp\n simp only [smul_sub, smul_add, smul_smul, hc', he']\n module }\n have hgen (z : E) (hz : z ∈ Ω) :\n (⟨z - x, hdiffS z hz⟩ : S) ∈ K :=\n ⟨1, zero_le_one, z, hz, by simp⟩\n have hstep : ∀ l : L, ∃ c : ℝ, 0 < c ∧\n x₀ + c • (l : E) ∈ Ω := by\n intro l\n letI : Nonempty (affineSpan ℝ Ω) :=\n ⟨⟨x, subset_affineSpan ℝ Ω hxΩ⟩⟩\n rw [mem_intrinsicInterior] at hx₀ri\n obtain ⟨q₀, hq₀, hq₀val⟩ := hx₀ri\n obtain ⟨ε, hε, hball⟩ := Metric.isOpen_iff.1 isOpen_interior q₀ hq₀\n let c : ℝ := ε / (2 * (‖(l : E)‖ + 1))\n have hc : 0 < c := by\n dsimp [c]\n positivity\n have hl : (l : E) ∈ (affineSpan ℝ Ω).direction := l.property\n let lv : (affineSpan ℝ Ω).direction := ⟨(l : E), hl⟩\n let q : affineSpan ℝ Ω := (c • lv) +ᵥ q₀\n have hqdist : dist q q₀ < ε := by\n rw [dist_eq_norm_vsub, vadd_vsub]\n change ‖c • (l : E)‖ < ε\n rw [norm_smul, Real.norm_eq_abs, abs_of_pos hc]\n dsimp [c]\n have hn : 0 ≤ ‖(l : E)‖ := norm_nonneg _\n field_simp\n nlinarith\n have hqΩ : (q : E) ∈ Ω := by\n change q ∈ (Subtype.val ⁻¹' Ω)\n exact interior_subset (hball (Metric.mem_ball.2 hqdist))\n refine ⟨c, hc, ?_⟩\n have hqcoe : (q : E) = c • (l : E) + x₀ := by\n dsimp [q, lv]\n change c • (l : E) + (q₀ : E) = _\n rw [hq₀val]\n rw [hqcoe] at hqΩ\n simpa [add_comm] using hqΩ\n apply Set.Subset.antisymm\n · intro v hv\n let P : Submodule ℝ S := H.comap S.subtype\n let f₀ : P →ₗ[ℝ] ℝ :=\n { toFun := fun y => - inner ℝ (y.1 : E) v\n map_add' := by\n intro a b\n simp only [Submodule.coe_add, inner_add_left, neg_add_rev]\n abel\n map_smul' := by\n intro c a\n simp [real_inner_smul_left] }\n let f : S →ₗ.[ℝ] ℝ := LinearPMap.mk P f₀\n have hnonneg : ∀ y : f.domain, (y : S) ∈ K → 0 ≤ f y := by\n intro y hyK\n obtain ⟨c, hc, z, hzΩ, hy⟩ := hyK\n change 0 ≤ -inner ℝ (((y : f.domain) : S) : E) v\n have hyH : ((y : S) : E) ∈ H := y.property\n change A ((y : S) : E) = 0 at hyH\n rw [hy, map_smul] at hyH\n by_cases hc0 : c = 0\n · rw [hy, hc0, zero_smul, inner_zero_left]\n norm_num\n have hzA : A z = b := by\n have : A (z - x) = 0 := by\n rcases smul_eq_zero.mp hyH with h | h\n · exact (hc0 h).elim\n · exact h\n rw [map_sub, hxA, sub_eq_zero] at this\n exact this\n have hvz : inner ℝ (z - x) v ≤ 0 :=\n hv z ⟨hzΩ, by simpa [h𝒜] using hzA⟩\n rw [hy, real_inner_smul_left]\n exact neg_nonneg.mpr (mul_nonpos_of_nonneg_of_nonpos hc hvz)\n have hdense : ∀ y : S, ∃ p : f.domain, (p : S) + y ∈ K := by\n intro y\n obtain ⟨h, hhH, l, hlL, hly⟩ := Submodule.mem_sup.1 y.property\n let l' : L := ⟨l, hlL⟩\n obtain ⟨c, hc, hzΩ⟩ := hstep l'\n let z : E := x₀ + c • l\n have hzΩ' : z ∈ Ω := by simpa [z, l'] using hzΩ\n have hk : (c⁻¹ : ℝ) • (⟨z - x, hdiffS z hzΩ'⟩ : S) ∈ K :=\n K.smul_mem (inv_pos.2 hc) (hgen z hzΩ')\n let pe : E := c⁻¹ • (x₀ - x) - h\n have hpeH : pe ∈ H := H.sub_mem (H.smul_mem _ hdiffH) hhH\n have hpeS : pe ∈ S := show pe ∈ H ⊔ L from\n Submodule.mem_sup.2 ⟨pe, hpeH, 0, L.zero_mem, add_zero _⟩\n let pS : S := ⟨pe, hpeS⟩\n have hpP : pS ∈ P := hpeH\n refine ⟨⟨pS, hpP⟩, ?_⟩\n convert hk using 1\n apply Subtype.ext\n simp only [Submodule.coe_add, Submodule.coe_smul]\n dsimp [pS, pe, z]\n rw [← hly]\n have hci : c⁻¹ * c = 1 := inv_mul_cancel₀ hc.ne'\n simp only [smul_sub, smul_add, smul_smul, hci, one_smul]\n module\n obtain ⟨g, hgf, hgK⟩ := riesz_extension K f hnonneg hdense\n obtain ⟨gE, hgE⟩ := LinearMap.exists_extend g\n let u : E := - LinearMap.adjoint gE (1 : ℝ)\n have hgu (y : S) : g y = - inner ℝ (y : E) u := by\n have hext : gE (y : E) = g y := by\n have := LinearMap.congr_fun hgE y\n exact this\n rw [← hext]\n dsimp [u]\n rw [inner_neg_right, neg_neg]\n rw [LinearMap.adjoint_inner_right]\n simp\n have hu : u ∈ normalCone Ω x := by\n intro z hzΩ\n have hzK := hgen z hzΩ\n have := hgK _ hzK\n rw [hgu] at this\n exact neg_nonneg.mp (by simpa using this)\n have hvuH : v - u ∈ Hᗮ := by\n rw [Submodule.mem_orthogonal']\n intro y hyH\n have hyS : y ∈ S := Submodule.mem_sup.2\n ⟨y, hyH, 0, L.zero_mem, add_zero _⟩\n let ys : S := ⟨y, hyS⟩\n have hysP : ys ∈ P := hyH\n have heq := hgf (⟨ys, hysP⟩ : f.domain)\n rw [hgu] at heq\n change inner ℝ (v - u) y = 0\n dsimp [f, f₀] at heq\n change -inner ℝ y u = -inner ℝ y v at heq\n have heq0 : inner ℝ y u = inner ℝ y v := neg_inj.mp heq\n have heq' : inner ℝ u y = inner ℝ v y := by\n calc\n inner ℝ u y = inner ℝ y u := real_inner_comm _ _\n _ = inner ℝ y v := heq0\n _ = inner ℝ v y := real_inner_comm _ _\n rw [inner_sub_left, heq', sub_self]\n have hvurange :\n v - u ∈ LinearMap.range (LinearMap.adjoint A) := by\n let Ac := LinearMap.toContinuousLinearMap A\n have hcorth : (LinearMap.ker Ac)ᗮ =\n LinearMap.range (ContinuousLinearMap.adjoint Ac) := by\n rw [ContinuousLinearMap.orthogonal_ker]\n apply SetLike.coe_injective\n rw [Submodule.topologicalClosure_coe]\n exact (LinearMap.range\n (ContinuousLinearMap.adjoint Ac)).closed_of_finiteDimensional.closure_eq\n have : v - u ∈ (LinearMap.ker Ac)ᗮ := by\n rw [LinearMap.ker_toContinuousLinearMap]\n exact hvuH\n rw [hcorth] at this\n simpa [Ac, ← LinearMap.adjoint_toContinuousLinearMap] using this\n obtain ⟨μ, hμ⟩ := hvurange\n refine ⟨u, hu, LinearMap.adjoint A μ, ⟨μ, rfl⟩, ?_⟩\n rw [hμ]\n change u + (v - u) = v\n abel\n · rintro v ⟨u, hu, w, ⟨μ, rfl⟩, rfl⟩\n intro z hz\n rw [inner_add_right]\n have hAu := hu z hz.1\n have hzA : A z = b := by\n rw [h𝒜] at hz\n exact hz.2\n rw [LinearMap.adjoint_inner_right, map_sub, hzA, hxA, sub_self, inner_zero_left]\n simpa using hAu\n\nend GraduateLevel\n"} +{"id": "ch17_proposition_17_3", "source": "Graduate-level", "targets": [{"label": "ch17_proposition_17_3", "decls": ["ch17_proposition_17_3"], "statement": "Let \\(x^*\\) be an unconstrained local minimum of \\(f\\colon \\mathbb{R}^n \\to \\mathbb{R}\\) and assume \\(f\\) is continuously differentiable (\\(C^1\\)) in an open set containing \\(x^*\\). Then\n\\begin{enumerate}\n \\item \\(\\nabla f(x^*) = 0\\) (First-Order Necessary Condition)\n \\item If in addition \\(f\\) is twice continuously differentiable in an open set around \\(x^*\\), then \\(\\nabla^2 f(x^*) \\succeq 0\\). (Second Order Necessary Condition)\n\\end{enumerate}", "topic_domain": "Optimization", "topic_subtopic": "Non-convex Geometry"}], "nl_proof": "Fix any direction \\(d \\in \\mathbb{R}^n\\).\n\\begin{enumerate}\n \\item \\(g(\\alpha) := f(x^* + \\alpha d)\\). Then\n \\[\n 0 \\leqslant \\lim_{\\alpha \\to 0} \\frac{f(x^* + \\alpha d) - f(x^*)}{\\alpha} = \\frac{\\partial g(0)}{\\partial \\alpha} = d^\\top \\nabla f(x^*)\n \\]\n The inequality follows because \\(x^*\\) is a local minimum, \\(0 \\leqslant f(x^* + \\alpha d) - f(x^*)\\) for sufficiently small \\(\\alpha\\). So, we can construct a sequence with only positive \\(\\alpha\\) that converges to \\(x^*\\) such that each element \\(0 \\leqslant \\frac{f(x^* + \\alpha_n d) - f(x^*)}{\\alpha_n}\\) which implies that statement given that \\(f\\) is locally differentiable. Since \\(d\\) is arbitrary, this implies that \\(\\nabla f(x^*) = 0\\).\n \\item First we represent \\(f(x^* + \\alpha d) - f(x^*)\\) using the 2nd order Taylor expansion.\n \\[\n f(x^* + \\alpha d) - f(x^*) = \\alpha \\nabla f(x^*)^\\top d + \\frac{\\alpha^2}{2} d^\\top \\nabla^2 f(x^*) d + O(\\alpha^2) = \\frac{\\alpha^2}{2} d^\\top \\nabla^2 f(x^*) d + O(\\alpha^2)\n \\]\n Now we do the following\n \\[\n 0 \\leqslant \\lim_{\\alpha \\to 0} \\frac{f(x^* + \\alpha d) - f(x^*)}{\\alpha^2} = \\lim_{\\alpha \\to 0} \\frac{1}{2} d^\\top \\nabla^2 f(x^*) d + \\frac{O(\\alpha^2)}{\\alpha^2} = \\frac{1}{2} d^\\top \\nabla^2 f(x^*) d\n \\]\n Because \\(d\\) is arbitrary, this implies that \\(\\nabla^2 f(x^*) \\succeq 0\\) (Positive semidefinite).\n\\end{enumerate}", "context": [{"id": "ch17:definition:17_1", "name": "Local minimum", "statement": "A point \\(x^*\\) is an unconstrained \\textit{local minimum} if there exists \\(\\epsilon > 0\\) such that \\(f(x^*) \\leqslant f(x)\\) for all \\(x\\) with \\(\\|x - x^*\\| < \\epsilon\\)."}], "lean": "import Mathlib\n\nopen scoped Gradient\n\nnamespace GraduateLevel\n\ntheorem ch17_proposition_17_3 {n : ℕ}\n (f : EuclideanSpace ℝ (Fin n) → ℝ) (x : EuclideanSpace ℝ (Fin n))\n (hmin : IsLocalMin f x) (hC1 : ContDiffAt ℝ 1 f x) :\n gradient f x = 0\n ∧ (ContDiffAt ℝ 2 f x →\n ∀ d : EuclideanSpace ℝ (Fin n),\n 0 ≤ iteratedFDeriv ℝ 2 f x ![d, d]) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped Gradient\n\nnamespace GraduateLevel\n\nopen Filter Topology\n\ntheorem ch17_proposition_17_3 {n : ℕ}\n (f : EuclideanSpace ℝ (Fin n) → ℝ) (x : EuclideanSpace ℝ (Fin n))\n (hmin : IsLocalMin f x) (hC1 : ContDiffAt ℝ 1 f x) :\n gradient f x = 0\n ∧ (ContDiffAt ℝ 2 f x →\n ∀ d : EuclideanSpace ℝ (Fin n),\n 0 ≤ iteratedFDeriv ℝ 2 f x ![d, d]) := by\n have hgrad : gradient f x = 0 := by\n simp [gradient, hmin.hasFDerivAt_eq_zero (hC1.differentiableAt le_rfl).hasFDerivAt]\n constructor\n · exact hgrad\n · intro hC2 d\n let ℓ : ℝ → EuclideanSpace ℝ (Fin n) := fun t => x + t • d\n let g : ℝ → ℝ := f ∘ ℓ\n have hℓ : ContDiffAt ℝ 2 ℓ 0 := by\n dsimp [ℓ]\n fun_prop\n have hC2' : ContDiffAt ℝ 2 f (ℓ 0) := by\n simpa [ℓ] using hC2\n have hg : ContDiffAt ℝ 2 g 0 := by\n exact hC2'.comp 0 hℓ\n have hmin_g : IsLocalMin g 0 := by\n have hmin' : IsLocalMin f (ℓ 0) := by\n simpa [ℓ] using hmin\n exact hmin'.comp_continuous hℓ.continuousAt\n have hderiv_g : deriv g 0 = 0 := hmin_g.deriv_eq_zero\n have hderiv_ℓ : ∀ t : ℝ, deriv ℓ t = d := by\n intro t\n simpa [ℓ] using ((hasDerivAt_const t x).add ((hasDerivAt_id t).smul_const d)).deriv\n have hderiv_ℓ_fun : deriv ℓ = fun _ => d := funext hderiv_ℓ\n have hsecond_ℓ : iteratedDeriv 2 ℓ 0 = 0 := by\n simp [iteratedDeriv_succ, hderiv_ℓ_fun]\n have hsecond : iteratedDeriv 2 g 0 = iteratedFDeriv ℝ 2 f x ![d, d] := by\n rw [iteratedDeriv_vcomp_two hC2' hℓ]\n simp [ℓ, hderiv_ℓ, hsecond_ℓ]\n congr 1\n funext i\n fin_cases i <;> rfl\n by_contra hnonneg\n have hneg : iteratedDeriv 2 g 0 < 0 := by\n rw [hsecond]\n exact lt_of_not_ge hnonneg\n have hmax_g : IsLocalMax g 0 := by\n apply isLocalMax_of_deriv_deriv_neg\n · simpa [iteratedDeriv_succ] using hneg\n · exact hderiv_g\n · exact hg.continuousAt\n have heq : g =ᶠ[𝓝 0] fun _ => g 0 := by\n filter_upwards [hmin_g, hmax_g] with y hymin hymax\n exact le_antisymm hymax hymin\n have hdereq : deriv g =���[𝓝 0] fun _ => 0 := by\n simpa using heq.deriv\n have hzero : deriv (deriv g) 0 = 0 := by\n rw [hdereq.deriv_eq]\n simp\n have : iteratedDeriv 2 g 0 = 0 := by\n simpa [iteratedDeriv_succ] using hzero\n linarith\n\nend GraduateLevel"} +{"id": "ch23_theorem_23_1", "source": "Graduate-level", "targets": [{"label": "ch23_theorem_23_1", "decls": ["ch23_theorem_23_1"], "statement": "Newton's method uses the update rule \\(x_{t+1} = x_t - \\nabla^2 f(x_t)^{-1}\\nabla f(x_t)\\). Throughout, \\(\\alpha > 0\\) (not written in the lecture, which leaves it implicit by dividing by \\(\\alpha\\)). Given \\(f: \\mathbb{R}^n \\rightarrow \\mathbb{R}\\) and assuming that \\begin{enumerate} \\item \\(f\\) is twice continuously differentiable \\item \\(\\nabla^2 f(x)\\) is Lipschitz: \\(\\| \\nabla^2 f(x) - \\nabla^2 f(x') \\| \\leqslant \\|x-x'\\|\\) \\item \\(\\exists x^*\\) s.t. \\(\\nabla f(x^*) = 0\\) and \\(\\nabla^2 f(x^*) \\succeq \\alpha I\\) and \\(\\|x^0 - x^*\\| \\leqslant \\frac{\\alpha}{2}\\) \\end{enumerate} Then, \\(\\|x_{t+1} - x^*\\| \\leqslant \\frac{1}{\\alpha} \\|x_t - x^*\\|^2\\)", "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}], "nl_proof": "Given that \\(\\nabla f(x^*) = 0\\), we have that \\begin{align*} x_{t+1} - x^* &= x_t - x^* - \\nabla^2 f(x_t)^{-1} \\nabla f(x_t) \\\\ &= \\nabla^2 f(x_t)^{-1} [\\nabla^2 f(x_t)(x_t - x^*) - (\\nabla f(x_t) - \\nabla f(x^*))] \\end{align*} This implies that \\[ \\|x_{t+1} - x^* \\| \\leqslant \\|\\nabla^2 f(x_t)^{-1} \\| \\cdot \\|\\nabla^2 f(x_t)(x_t - x^*) - (\\nabla f(x_t) - \\nabla f(x^*))\\| \\] \\textbf{Claim 23.2.} \\(\\|\\nabla^2 f(x_t)(x_t - x^*) - (\\nabla f(x_t) - \\nabla f(x^*))\\| \\leqslant \\frac{1}{2}\\|x_t - x^*\\|^2\\). \\emph{Proof.} Applying the integral remainder form of Taylor's theorem to \\(\\nabla f(x_t)\\) we have that \\(\\nabla f(x_t) - \\nabla f(x^*) = \\int_0^1 \\nabla^2 f(x_t + \\gamma(x^* - x_t))\\cdot(x_t - x^*)\\,d\\gamma\\). We therefore have that \\(\\|\\nabla^2 f(x_t)(x_t - x^*) - (\\nabla f(x_t) - \\nabla f(x^*))\\| = \\|\\int_0^1 [\\nabla^2 f(x_t) - \\nabla^2 f(x_t + \\gamma(x^* - x_t))](x_t - x^*)\\,d\\gamma\\| \\leqslant \\int_0^1 \\|\\nabla^2 f(x_t) - \\nabla^2 f(x_t + \\gamma(x^* - x_t))\\|\\cdot\\|x_t - x^*\\|\\,d\\gamma \\leqslant (\\int_0^1 \\gamma\\,d\\gamma)\\|x_t - x^*\\|^2 = \\frac{1}{2}\\|x_t - x^*\\|^2\\). \\textbf{Claim 23.3.} \\(\\|\\nabla^2 f(x_t)^{-1}\\| \\leqslant \\frac{2}{\\alpha}\\). \\emph{Proof.} By the Wielandt-Hoffman Theorem, \\(|\\lambda_{min}(\\nabla^2 f(x_t)) - \\lambda_{min}(\\nabla^2 f(x^*))| \\leqslant \\|\\nabla^2 f(x_t) - \\nabla^2 f(x^*)\\| \\leqslant \\|x_t - x^*\\|\\). Thus, for \\(\\|x_t - x^*\\| \\leqslant \\frac{\\alpha}{2}\\) and given that \\(\\nabla^2 f(x^*) \\succeq \\alpha I\\), this implies that \\(\\lambda_{min}(\\nabla^2 f(x_t)) \\geqslant \\frac{\\alpha}{2}\\). Hence, \\(\\|\\nabla^2 f(x_t)^{-1}\\| \\leqslant \\frac{2}{\\alpha}\\). Putting the two claims together, we have that \\[\\|x_{t+1} - x^*\\| \\leqslant \\frac{2}{\\alpha} \\cdot \\frac{1}{2} \\|x_t - x^*\\|^2 = \\frac{1}{\\alpha} \\|x_t - x^*\\|^2\\]", "context": [], "lean": "import Mathlib\n\nopen scoped RealInnerProductSpace\nopen Real\n\nnamespace GraduateLevel\n\ntheorem ch23_theorem_23_1\n {n : ℕ} (f : EuclideanSpace ℝ (Fin n) → ℝ) (α : ℝ) (hα : 0 < α)\n (hf : ContDiff ℝ 2 f)\n (hLip : LipschitzWith 1 (fun x => fderiv ℝ (gradient f) x))\n (xstar : EuclideanSpace ℝ (Fin n))\n (hstar : gradient f xstar = 0)\n (hpd : ∀ v : EuclideanSpace ℝ (Fin n),\n α * ‖v‖ ^ 2 ≤ ⟪(fderiv ℝ (gradient f) xstar) v, v⟫)\n (x : ℕ → EuclideanSpace ℝ (Fin n))\n (h0 : ‖x 0 - xstar‖ ≤ α / 2)\n (hnewton : ∀ t, ∃ H : EuclideanSpace ℝ (Fin n) ≃L[ℝ] EuclideanSpace ℝ (Fin n),\n (↑H = fderiv ℝ (gradient f) (x t)) ∧\n x (t + 1) = x t - H.symm (gradient f (x t))) :\n ∀ t, ‖x (t + 1) - xstar‖ ≤ (1 / α) * ‖x t - xstar‖ ^ 2 := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped RealInnerProductSpace\nopen Real\n\nnamespace GraduateLevel\n\nprivate lemma taylor_bnd {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]\n (g : E → E) (g' : E → E →L[ℝ] E) (hg : ∀ z, HasFDerivAt g (g' z) z)\n (hL : LipschitzWith 1 g') (a b : E) :\n ‖g b - g a - g' a (b - a)‖ ≤ (1/2) * ‖b - a‖^2 := by\n set d := b - a with hd\n set w := g' a d with hw\n set u : ℝ → E := fun s => g (a + s • d) - g a - s • w with hu\n set u' : ℝ → E := fun s => g' (a + s • d) d - w with hu'\n have hderiv : ∀ s : ℝ, HasDerivAt u (u' s) s := by\n intro s\n have h1 : HasDerivAt (fun s : ℝ => a + s • d) d s := by\n simpa using ((hasDerivAt_id s).smul_const d).const_add a\n have h2 : HasDerivAt (fun s : ℝ => g (a + s • d)) (g' (a + s • d) d) s :=\n (hg (a + s • d)).comp_hasDerivAt s h1\n have h3 : HasDerivAt (fun s : ℝ => s • w) w s := by\n simpa using (hasDerivAt_id s).smul_const w\n exact (h2.sub_const (g a)).sub h3\n set B : ℝ → ℝ := fun s => ‖d‖^2 * s^2 / 2 with hB\n set B' : ℝ → ℝ := fun s => ‖d‖^2 * s with hB'\n have hBd : ∀ s : ℝ, HasDerivAt B (B' s) s := by\n intro s\n have : HasDerivAt (fun s : ℝ => ‖d‖^2 * s^2 / 2) (‖d‖^2 * (2*s) / 2) s := by\n simpa using (((hasDerivAt_pow 2 s).const_mul (‖d‖^2)).div_const 2)\n convert this using 1\n simp [hB']; ring\n have key := image_norm_le_of_norm_deriv_right_le_deriv_boundary\n (f := u) (a := 0) (b := 1) (f' := u')\n (fun s _ => ((hderiv s).continuousAt).continuousWithinAt)\n (fun s _ => (hderiv s).hasDerivWithinAt)\n (by simp [hu, hB]) hBd\n (by\n intro s hs\n have hs0 : (0:ℝ) ≤ s := hs.1\n have hlip : ‖g' (a + s • d) - g' a‖ ≤ ‖s • d‖ := by\n have := hL.dist_le_mul (a + s • d) a\n simp only [dist_eq_norm] at this\n simpa using this\n have : u' s = (g' (a + s • d) - g' a) d := by simp [hu', hw]\n rw [this]\n calc ‖(g' (a + s • d) - g' a) d‖ ≤ ‖g' (a + s • d) - g' a‖ * ‖d‖ :=\n ContinuousLinearMap.le_opNorm _ _\n _ ≤ ‖s • d‖ * ‖d‖ := by gcongr\n _ = B' s := by simp [hB', norm_smul, abs_of_nonneg hs0]; ring)\n (by norm_num : (1:ℝ) ∈ Set.Icc (0:ℝ) 1)\n have hu1 : u 1 = g b - g a - g' a (b - a) := by simp [hu, hd, hw]\n rw [hu1] at key\n calc ‖g b - g a - g' a (b-a)‖ ≤ B 1 := key\n _ = 1/2 * ‖b-a‖^2 := by simp [hB, hd]; ring\n\ntheorem ch23_theorem_23_1\n {n : ℕ} (f : EuclideanSpace ℝ (Fin n) → ℝ) (α : ℝ) (hα : 0 < α)\n (hf : ContDiff ℝ 2 f)\n (hLip : LipschitzWith 1 (fun x => fderiv ℝ (gradient f) x))\n (xstar : EuclideanSpace ℝ (Fin n))\n (hstar : gradient f xstar = 0)\n (hpd : ∀ v : EuclideanSpace ℝ (Fin n),\n α * ‖v‖ ^ 2 ≤ ⟪(fderiv ℝ (gradient f) xstar) v, v⟫)\n (x : ℕ → EuclideanSpace ℝ (Fin n))\n (h0 : ‖x 0 - xstar‖ ≤ α / 2)\n (hnewton : ∀ t, ∃ H : EuclideanSpace ℝ (Fin n) ≃L[ℝ] EuclideanSpace ℝ (Fin n),\n (↑H = fderiv ℝ (gradient f) (x t)) ∧\n x (t + 1) = x t - H.symm (gradient f (x t))) :\n ∀ t, ‖x (t + 1) - xstar‖ ≤ (1 / α) * ‖x t - xstar‖ ^ 2 := by\n have hdiff : Differentiable ℝ (gradient f) := by\n have h1 : ContDiff ℝ 1 (fderiv ℝ f) := hf.fderiv_right (by norm_num)\n have h2 : ContDiff ℝ 1 (fun z => (InnerProductSpace.toDual ℝ (EuclideanSpace ℝ (Fin n))).symm (fderiv ℝ f z)) :=\n (((InnerProductSpace.toDual ℝ (EuclideanSpace ℝ (Fin n))).symm.toContinuousLinearEquiv.toContinuousLinearMap).contDiff).comp h1\n have he : (gradient f) = fun z => (InnerProductSpace.toDual ℝ (EuclideanSpace ℝ (Fin n))).symm (fderiv ℝ f z) := rfl\n rw [he]\n exact h2.differentiable le_rfl\n have hgd : ∀ z : EuclideanSpace ℝ (Fin n), HasFDerivAt (gradient f) (fderiv ℝ (gradient f) z) z :=\n fun z => (hdiff z).hasFDerivAt\n have hHlip : ∀ y z : EuclideanSpace ℝ (Fin n),\n ‖fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) z‖ ≤ ‖y - z‖ := by\n intro y z\n have h := hLip.dist_le_mul y z\n simp only [dist_eq_norm] at h\n simpa only [NNReal.coe_one, one_mul] using h\n have hpdy : ∀ y : EuclideanSpace ℝ (Fin n), ‖y - xstar‖ ≤ α / 2 →\n ∀ v : EuclideanSpace ℝ (Fin n),\n (α/2) * ‖v‖^2 ≤ ⟪(fderiv ℝ (gradient f) y) v, v⟫ := by\n intro y hy v\n have hdec : ⟪(fderiv ℝ (gradient f) y) v, v⟫\n = ⟪(fderiv ℝ (gradient f) xstar) v, v⟫\n + ⟪(fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) xstar) v, v⟫ := by\n simp [ContinuousLinearMap.sub_apply, inner_sub_left]\n have hAB : ‖fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) xstar‖ ≤ α/2 :=\n le_trans (hHlip y xstar) hy\n have hop : ‖(fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) xstar) v‖ ≤ (α/2) * ‖v‖ :=\n le_trans (ContinuousLinearMap.le_opNorm _ _) (mul_le_mul_of_nonneg_right hAB (norm_nonneg v))\n have hb : |⟪(fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) xstar) v, v⟫| ≤ (α/2) * ‖v‖^2 := by\n have h1 := abs_real_inner_le_norm ((fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) xstar) v) v\n have h2 : ‖(fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) xstar) v‖ * ‖v‖\n ≤ ((α/2) * ‖v‖) * ‖v‖ := mul_le_mul_of_nonneg_right hop (norm_nonneg v)\n nlinarith [h1, h2]\n have h1 := hpd v\n have h2 : -((α/2) * ‖v‖^2)\n ≤ ⟪(fderiv ℝ (gradient f) y - fderiv ℝ (gradient f) xstar) v, v⟫ :=\n neg_le_of_abs_le hb\n rw [hdec]\n linarith\n have hinv : ∀ (y : EuclideanSpace ℝ (Fin n)), ‖y - xstar‖ ≤ α / 2 →\n ∀ (H : EuclideanSpace ℝ (Fin n) ≃L[ℝ] EuclideanSpace ℝ (Fin n)),\n (↑H = fderiv ℝ (gradient f) y) →\n ∀ w : EuclideanSpace ℝ (Fin n), ‖H.symm w‖ ≤ (2/α) * ‖w‖ := by\n intro y hy H hH w\n set v := H.symm w with hv\n have hHv : (fderiv ℝ (gradient f) y) v = w := by\n rw [← hH, hv]; simp\n have h1 : (α/2) * ‖v‖^2 ≤ ⟪(fderiv ℝ (gradient f) y) v, v⟫ := hpdy y hy v\n rw [hHv] at h1\n have h3 : ⟪w, v⟫ ≤ ‖w‖ * ‖v‖ := real_inner_le_norm w v\n have h4 : (α/2) * ‖v‖^2 ≤ ‖w‖ * ‖v‖ := le_trans h1 h3\n rcases eq_or_lt_of_le (norm_nonneg v) with h | h\n · rw [← h]\n have : (0:ℝ) ≤ 2/α * ‖w‖ := by positivity\n linarith\n · rw [div_mul_eq_mul_div, le_div_iff₀ hα]\n nlinarith\n have step : ∀ t, ‖x t - xstar‖ ≤ α / 2 →\n ‖x (t+1) - xstar‖ ≤ (1/α) * ‖x t - xstar‖^2 := by\n intro t ht\n obtain ⟨H, hH, hstep⟩ := hnewton t\n set A := fderiv ℝ (gradient f) (x t) with hA\n set v := x t - xstar with hvdef\n set G := gradient f (x t) with hG\n have hAv : H.symm (A v) = v := by rw [← hH]; simp\n have hkey : x (t+1) - xstar = H.symm (A v - G) := by\n rw [hstep, map_sub, hAv, hvdef]\n abel\n have htay := taylor_bnd (gradient f) (fun z => fderiv ℝ (gradient f) z) hgd hLip (x t) xstar\n have hxv : xstar - x t = -v := by rw [hvdef]; abel\n have heq : gradient f xstar - gradient f (x t) - A (xstar - x t) = A v - G := by\n rw [hstar, hxv, map_neg, ← hG]\n abel\n simp only [← hA] at htay\n rw [heq] at htay\n have hnormeq : ‖xstar - x t‖ = ‖v‖ := by rw [hxv, norm_neg]\n rw [hnormeq] at htay\n have hb := hinv (x t) ht H hH (A v - G)\n rw [← hkey] at hb\n have hfin : (2/α) * ‖A v - G‖ ≤ (2/α) * ((1/2) * ‖v‖^2) :=\n mul_le_mul_of_nonneg_left htay (by positivity)\n have : (2/α) * ((1/2) * ‖v‖^2) = (1/α) * ‖v‖^2 := by field_simp\n linarith [le_trans hb hfin]\n have ball : ∀ t, ‖x t - xstar‖ ≤ α / 2 := by\n intro t\n induction t with\n | zero => exact h0\n | succ k ih =>\n have h1 := step k ih\n have hn : (0:ℝ) ≤ ‖x k - xstar‖ := norm_nonneg _\n have hsq : ‖x k - xstar‖^2 ≤ α^2/4 := by nlinarith\n have hpos : (0:ℝ) < 1/α := by positivity\n have h2 : (1/α) * ‖x k - xstar‖^2 ≤ α/4 := by\n have hc : (1/α) * ‖x k - xstar‖^2 ≤ (1/α) * (α^2/4) :=\n mul_le_mul_of_nonneg_left hsq (le_of_lt hpos)\n have he : (1/α) * (α^2/4) = α/4 := by field_simp\n linarith [hc, he.le, he.ge]\n linarith\n exact fun t => step t (ball t)\n\nend GraduateLevel\n"} +{"id": "ch14_theorem_14_1", "source": "Graduate-level", "targets": [{"label": "ch14_theorem_14_1", "decls": ["ch14_theorem_14_1"], "statement": "\\[\\mathbb{P}\\left(\\forall f\\in F,R(f)\\leq\\frac{2^{9/2}}{\\sqrt{n}}\\int_{0}^{d(0,f)}\\log^{1/2}\\mathcal{D}(F,\\varepsilon,d)d\\varepsilon+2^{7/2}d(0,f)\\sqrt{\\frac{u}{n}}\\right)\\geq 1-e^{-u}\\]\nfor any \\(u > 0\\)", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Without loss of generality, assume \\(0 \\in F\\)\nKolmogorov's chaining technique: define a sequence of subsets\n\\[\\{0\\}=F_{0}\\subseteq F_{1}\\dots\\subseteq F_{j}\\subseteq\\dots\\subseteq F\\]\nwhere \\(F_{j}\\) is defined such that\n(1) \\(\\forall f,g\\in F_{j},d(f,g)>2^{-j}\\)\n(2) \\(\\forall f \\in F\\) ,we can find \\(g\\in F_{j}\\) such that \\(d(f,g)\\leq 2^{-j}\\)\nHow to construct \\(F_{j+1}\\) if we have \\(F_{j}\\)\n\\(F_{j+1}: =F_{j}\\)\n· Find \\(f\\in F,d(f,g)>2^{-(j+1)}\\) for all \\(g\\in F_{j+1}\\)\n· Repeat until you cannot find such f\nDefine projection \\(\\pi_{j}:F\\mapsto F_{j}\\) as follows: for \\(f \\in F\\) find \\(g\\in F_{j}\\) with \\(d(f,g)\\leq 2^{-j}\\) and set \\(\\pi_{j}(f)=g\\) For any \\(f \\in F\\)\n\\[\\begin{array}{ l }{f=\\displaystyle\\pi_{0}(f)+(\\pi_{1}(f)-\\pi_{0}(f))+(\\pi_{2}(f)-\\pi_{1}(f))\\cdot\\cdot\\cdot}\\\\ {\\displaystyle=\\sum_{j=1}^{\\infty}(\\pi_{j}(f)-\\pi_{j-1}(f))}\\end{array}\\]\nMoreover,\n\\[\\begin{array}{ r l r }{{d(\\pi_{j-1}(f),\\pi_{j}(f))\\leq d(\\pi_{j-1}(f),f)+d(f,\\pi_{j}(f))}}\\\\ &{}&\\\\ &{}&{\\leq 2^{-(j-1)}+2^{-j}=3\\cdot 2^{-j}\\leq 2^{-j+2}}\\end{array}\\]\nDefine the links\n\\[L_{j-1,j}=\\{f-g:f\\in F_{j},g\\in F_{j-1},d(f,g)\\leq 2^{-j+2}\\}.\\]\nSince R is linear, \\(\\begin{array}{ r }{R(f)=\\sum_{j=1}^{\\infty}R(\\pi_{j}(f)-\\pi_{j-1}(f))}\\end{array}\\) . We first show how to control R on the links. Assume \\(\\ell\\in L_{j-1,j}\\) . Then by Hoeffding's inequality\n\\[\\begin{array}{ r l r }{{\\mathbb{P}(\\frac{1}{n}\\sum_{i=1}^{n}\\varepsilon_{i}\\ell_{i}\\geq t)\\leq\\exp(-\\frac{t^{2}}{2\\sum\\frac{1}{n^{2}}\\ell_{i}^{2}})}}\\\\ &{}&\\\\ &{}&{=\\exp(-\\frac{n t^{2}}{2\\frac{1}{n}\\sum_{i=1}^{n}\\ell_{i}^{2}})}\\\\ &{}&{\\leq\\exp(-\\frac{n t^{2}}{2\\cdot 2^{-2 j+4}})}\\end{array}\\]\nNote that\n\\[\\mathrm{card}L_{j-1,j}\\leq\\mathrm{card}F_{j-1}\\cdot\\mathrm{card}F_{j}\\leq(\\mathrm{card}F_{j})^{2}.\\]\n\\[\\begin{array}{ r l r }{{\\mathbb{P}(\\forall\\ell\\in L_{j-1,j},R(\\ell)=\\frac{1}{n}\\sum_{i=1}^{n}\\varepsilon_{i}\\ell_{i}\\leq t)\\geq 1-(\\mathrm{card}F_{j})^{2}e^{-\\frac{n t^{2}}{2\\cdot 2^{-2 j+5}}}}}\\\\ &{}&\\\\ &{}&{=1-\\frac{1}{(\\mathrm{card}F_{j})^{2}}e^{-u}}\\end{array}\\]\nafter changing the variable such that\n\\[t={\\sqrt{\\frac{2^{-2 j+5}}{n}\\left(4\\log(\\operatorname{card}F_{j})+u\\right)}}\\leq{\\sqrt{\\frac{2^{-2 j+5}}{n}4\\log(\\operatorname{card}F_{j})}}+{\\sqrt{\\frac{2^{-2 j+5}}{n}u}}.\\]\nHence,\n\\[\\mathbb{P}\\left(\\forall\\ell\\in L_{j-1,j},R(\\ell)\\leq\\frac{2^{7/2}2^{-j}}{\\sqrt{n}}\\log^{1/2}(\\mathrm{card}F_{j})+2^{5/2}2^{-j}\\sqrt{\\frac{u}{n}}\\right)\\geq 1-\\frac{1}{(\\mathrm{card}F_{j})^{2}}e^{-u}.\\]\nIf \\(F_{j-1}=F_{j}\\) then by definition \\(\\pi_{j-1}(f)=\\pi_{f}\\) and \\(L_{j-1,j}=\\{0\\}\\)\nBy union bound for all steps,\n\\[\\begin{array}{ r l }&{\\mathbb{P}\\left(\\forall j\\geq 1,\\forall\\ell\\in L_{j-1,j},R(\\ell)\\leq\\frac{2^{7/2}2^{-j}}{\\sqrt{n}}\\log^{1/2}(\\mathrm{card}F_{j})+2^{5/2}2^{-j}\\sqrt{\\frac{u}{n}}\\right)}\\\\ &{\\geq 1-\\displaystyle\\sum_{j=1}^{\\infty}\\frac{1}{(\\mathrm{card}F_{j})^{2}}e^{-u}}\\\\ &{\\geq 1-\\left(\\frac{1}{2^{2}}+\\frac{1}{3^{2}}+\\frac{1}{4^{2}}\\right)e^{-u}}\\\\ &{=1-(\\pi^{2}/6-1)e^{-u}\\geq 1-e^{-u}}\\end{array}\\]\nRecall that \\(\\begin{array}{ r }{R(f)=\\sum_{j=1}^{\\infty}R(\\pi_{j}(f)-\\pi_{j-1}(f))}\\end{array}\\) . If f is close to \\(0,-2^{k+1} 0\\) and \\(f_{1},\\ldots,f_{N}\\in\\mathcal{F}\\) , we say that \\(f_{1},\\ldots,f_{N}\\) are E-separated if \\(d(f_{i},f_{j})>\\varepsilon\\) for any \\(i \\neq j\\)"}, {"id": "ch14:setup:14_0", "name": "Lecture 14 setup (R, d, F) with the Lecture 7 Rademacher convention", "statement": "For \\(f \\in F \\subseteq [-1,1]^n\\), define \\(R(f) = \\frac{1}{n}\\sum_{i=1}^n \\varepsilon_i f_i\\), where \\(\\varepsilon_1,\\dots,\\varepsilon_n\\) are i.i.d. Rademacher random variables, \\(\\mathbb{P}(\\varepsilon_i = 1) = \\mathbb{P}(\\varepsilon_i = -1) = 1/2\\) (Lecture 7), and let \\(d(f,g) := \\left(\\frac{1}{n}\\sum_{i=1}^n (f_i - g_i)^2\\right)^{1/2}\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory\nopen scoped BigOperators ENNReal\n\nnoncomputable section\n\nnamespace GraduateLevel\n\ndef EmpL2 (n : ℕ) : Type := Fin n → ℝ\n\ninstance (n : ℕ) : Zero (EmpL2 n) := inferInstanceAs (Zero (Fin n → ℝ))\n\ndef empEmbed (n : ℕ) : EmpL2 n → EuclideanSpace ℝ (Fin n) :=\n fun f => (EuclideanSpace.equiv (Fin n) ℝ).symm (fun i => f i / Real.sqrt n)\n\ninstance (n : ℕ) : PseudoMetricSpace (EmpL2 n) :=\n PseudoMetricSpace.induced (empEmbed n) inferInstance\n\ndef radProc (n : ℕ) (f : Fin n → ℝ) (ε : Fin n → ℝ) : ℝ :=\n (1 / (n : ℝ)) * ∑ i, ε i * f i\n\ndef IsPacking {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n ↑t ⊆ s ∧ (↑t : Set A).Pairwise fun x y => eps < dist x y\n\nnoncomputable def packingNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop ℕ :=\n sSup {n | ∃ t, IsPacking t eps s ∧ ↑t.card = n}\n\ntheorem ch14_theorem_14_1\n {n : ℕ} (hn : 0 < n)\n (P : Measure (Fin n → ℝ)) [IsProbabilityMeasure P]\n (hP : P = Measure.pi\n (fun _ : Fin n => ((1 : ℝ≥0∞) / 2) • (Measure.dirac (-1 : ℝ) + Measure.dirac 1)))\n (F : Set (EmpL2 n))\n (hFbdd : ∀ f ∈ F, ∀ i, |(f : Fin n → ℝ) i| ≤ 1)\n (hFin : ∀ ε : ℝ, 0 < ε → packingNumber ε F ≠ ⊤)\n (hD : ∀ f ∈ F, ∀ ε ∈ Set.Ioo (0:ℝ) (dist (0 : EmpL2 n) f),\n (1 : ℝ) ≤ (((packingNumber ε F).untopD 0 : ℕ) : ℝ))\n (hInt : ∀ f ∈ F, IntervalIntegrable\n (fun ε => Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)))\n MeasureTheory.volume 0 (dist (0 : EmpL2 n) f))\n (u : ℝ) (hu : 0 < u) :\n (1 : ℝ) - Real.exp (-u) ≤\n (P {ω | ∀ f ∈ F, radProc n (f : Fin n → ℝ) ω ≤\n (2 ^ (9/2 : ℝ) / Real.sqrt n) *\n (∫ ε in (0:ℝ)..(dist (0 : EmpL2 n) f),\n Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)))\n + 2 ^ (7/2 : ℝ) * dist (0 : EmpL2 n) f * Real.sqrt (u / n)}).toReal := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory\nopen scoped BigOperators ENNReal\n\nnoncomputable section\n\nnamespace GraduateLevel\n\ndef EmpL2 (n : ℕ) : Type := Fin n → ℝ\n\ninstance (n : ℕ) : Zero (EmpL2 n) := inferInstanceAs (Zero (Fin n → ℝ))\n\ndef empEmbed (n : ℕ) : EmpL2 n → EuclideanSpace ℝ (Fin n) :=\n fun f => (EuclideanSpace.equiv (Fin n) ℝ).symm (fun i => f i / Real.sqrt n)\n\ninstance (n : ℕ) : PseudoMetricSpace (EmpL2 n) :=\n PseudoMetricSpace.induced (empEmbed n) inferInstance\n\ndef radProc (n : ℕ) (f : Fin n → ℝ) (ε : Fin n → ℝ) : ℝ :=\n (1 / (n : ℝ)) * ∑ i, ε i * f i\n\ndef IsPacking {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n ↑t ⊆ s ∧ (↑t : Set A).Pairwise fun x y => eps < dist x y\n\nnoncomputable def packingNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop ℕ :=\n sSup {n | ∃ t, IsPacking t eps s ∧ ↑t.card = n}\n\n/- ###################################################################### -/\n/- Part 1 : the Rademacher product measure -/\n/- ###################################################################### -/\n\nopen ProbabilityTheory in\ndef rad : Measure ℝ := ((1 : ℝ≥0∞) / 2) • (Measure.dirac (-1 : ℝ) + Measure.dirac 1)\n\ninstance : IsProbabilityMeasure rad := by\n constructor; simp [rad]; exact ENNReal.inv_two_add_inv_two\n\nlemma rad_integral (g : ℝ → ℝ) : ∫ x, g x ∂rad = (g (-1) + g 1)/2 := by\n rw [rad, integral_smul_measure,\n integral_add_measure (integrable_dirac (by finiteness)) (integrable_dirac (by finiteness)),\n integral_dirac, integral_dirac]\n simp; ring\n\nlemma rad_ae (p : ℝ → Prop) (h : p (-1)) (h' : p 1) : ∀ᵐ x ∂rad, p x := by\n have : rad {x | ¬ p x} = 0 := by rw [rad]; simp [h, h']\n exact this\n\ndef radP (n : ℕ) : Measure (Fin n → ℝ) := Measure.pi (fun _ => rad)\n\ninstance (n : ℕ) : IsProbabilityMeasure (radP n) := by unfold radP; infer_instance\n\nopen ProbabilityTheory in\nlemma coord_subG (n : ℕ) (c : ℝ) (i : Fin n) :\n HasSubgaussianMGF (fun ω : Fin n → ℝ => c * ω i) (‖c‖₊^2) (radP n) := by\n have hmp : MeasurePreserving (Function.eval i) (radP n) rad := by\n unfold radP; exact measurePreserving_eval _ i\n have key : HasSubgaussianMGF (fun x : ℝ => c * x) (‖c‖₊^2) rad := by\n have h := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero (μ := rad)\n (X := fun x : ℝ => c * x) (a := -|c|) (b := |c|)\n (by fun_prop)\n (rad_ae _ (by constructor <;> nlinarith [abs_nonneg c, neg_abs_le c, le_abs_self c])\n (by constructor <;> nlinarith [abs_nonneg c, neg_abs_le c, le_abs_self c]))\n (by rw [rad_integral]; ring)\n convert h using 2\n rw [show |c| - -|c| = 2*|c| by ring]\n simp [nnnorm_mul]\n exact HasSubgaussianMGF.of_map (Y := Function.eval i) (hmp.measurable.aemeasurable)\n (by rw [hmp.map_eq]; exact key)\n\nopen ProbabilityTheory in\nlemma indep_coords (n : ℕ) (c : Fin n → ℝ) :\n iIndepFun (fun (i : Fin n) (ω : Fin n → ℝ) => c i * ω i) (radP n) := by\n unfold radP\n exact iIndepFun_pi (X := fun i (x : ℝ) => c i * x) (fun i => by fun_prop)\n\n/- ###################################################################### -/\n/- Part 2 : the empirical L² pseudometric -/\n/- ###################################################################### -/\n\nsection Metric\nvariable {n : ℕ}\n\nlemma dist_eq' (a b : EmpL2 n) :\n dist a b = Real.sqrt (∑ i, ((a i - b i) / Real.sqrt n)^2) := by\n show dist (empEmbed n a) (empEmbed n b) = _\n rw [EuclideanSpace.dist_eq]\n simp [empEmbed, Real.dist_eq, sq_abs, sub_div]\n\nlemma dist_sq (hn : 0 < n) (a b : EmpL2 n) :\n (dist a b)^2 = (∑ i, ((a : Fin n → ℝ) i - b i)^2) / n := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n rw [dist_eq', Real.sq_sqrt]\n · rw [Finset.sum_div]\n exact Finset.sum_congr rfl fun i _ => by rw [div_pow, Real.sq_sqrt hn'.le]\n · positivity\n\nlemma sum_sq_eq (hn : 0 < n) (a : EmpL2 n) :\n (∑ i, ((a : Fin n → ℝ) i)^2) = n * (dist (0 : EmpL2 n) a)^2 := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n rw [dist_sq hn]\n have : ∀ i, ((0 : EmpL2 n) i - a i)^2 = (a i)^2 := by\n intro i; show ((0:ℝ) - a i)^2 = _; ring\n simp only [this]\n field_simp\n\nend Metric\n\n/- ###################################################################### -/\n/- Part 3 : Hoeffding + symmetry -/\n/- ###################################################################### -/\n\nsection Prob\nvariable {n : ℕ}\n\nlemma hoeff (hn : 0 < n) (a : Fin n → ℝ) (v : ℝ) (hv : 0 ≤ v) :\n (radP n).real {ω | dist (0 : EmpL2 n) a * Real.sqrt (2*v/n) < radProc n a ω}\n ≤ Real.exp (-v) := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n set D := dist (0 : EmpL2 n) a with hD\n have hD0 : 0 ≤ D := dist_nonneg\n rcases eq_or_lt_of_le hD0 with h0 | hpos\n · have hsum : (∑ i, (a i)^2) = 0 := by rw [sum_sq_eq hn a, ← hD, ← h0]; ring\n have ha : ∀ i, a i = 0 := by\n intro i\n have := (Finset.sum_eq_zero_iff_of_nonneg (fun i _ => sq_nonneg (a i))).mp hsum i (Finset.mem_univ i)\n exact pow_eq_zero_iff (n := 2) (by norm_num) |>.mp this\n have : {ω : Fin n → ℝ | D * Real.sqrt (2*v/n) < radProc n a ω} = ∅ := by\n ext ω; simp [radProc, ha, ← h0]\n rw [this]; simp [Real.exp_nonneg]\n · have hsub : {ω : Fin n → ℝ | D * Real.sqrt (2*v/n) < radProc n a ω}\n ⊆ {ω : Fin n → ℝ | D * Real.sqrt (2*v/n) ≤ ∑ i, (a i / n) * ω i} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n have hr : radProc n a ω = ∑ i, (a i / n) * ω i := by\n rw [radProc, Finset.mul_sum]; exact Finset.sum_congr rfl fun i _ => by ring\n rw [hr] at hω; exact hω.le\n have hε : 0 ≤ D * Real.sqrt (2*v/n) := by positivity\n refine (measureReal_mono hsub (measure_ne_top _ _)).trans ?_\n have key := ProbabilityTheory.HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun\n (indep_coords n (fun i => a i / n)) (c := fun i => ‖a i / (n:ℝ)‖₊^2)\n (s := Finset.univ) (fun i _ => coord_subG n (a i / n) i) hε\n refine key.trans_eq ?_\n congr 1\n have hcsum : ((∑ i, ‖a i / (n:ℝ)‖₊^2 : NNReal) : ℝ) = D^2 / n := by\n push_cast\n have hh : ∀ i : Fin n, ‖a i / (n:ℝ)‖^2 = (a i)^2 / (n:ℝ)^2 := by\n intro i; rw [Real.norm_eq_abs, sq_abs, div_pow]\n simp only [hh]\n rw [← Finset.sum_div, sum_sq_eq hn a]\n field_simp\n exact congrArg (· ^ 2) hD.symm\n rw [hcsum]\n rw [mul_pow, Real.sq_sqrt (by positivity)]\n field_simp\n\nlemma rad_neg : rad.map (fun x : ℝ => -x) = rad := by\n rw [rad, Measure.map_smul, Measure.map_add _ _ (by fun_prop),\n Measure.map_dirac (by fun_prop), Measure.map_dirac (by fun_prop)]\n norm_num\n rw [add_comm]\n\nlemma radP_neg (n : ℕ) : (radP n).map (fun ω : Fin n → ℝ => -ω) = radP n := by\n unfold radP\n rw [show (fun ω : Fin n → ℝ => -ω) = (fun (x : Fin n → ℝ) i => (fun (y:ℝ) => -y) (x i)) from rfl]\n rw [Measure.pi_map_pi (fun i => (by fun_prop : AEMeasurable (fun y : ℝ => -y) rad))]\n simp [rad_neg]\n\nlemma symm_half (n : ℕ) (a : Fin n → ℝ) (t : ℝ) (ht : 0 ≤ t) :\n (radP n).real {ω | t < radProc n a ω} ≤ 1/2 := by\n have hcont : Continuous (fun ω : Fin n → ℝ => radProc n a ω) := by\n unfold radProc; fun_prop\n set S : Set (Fin n → ℝ) := {ω | 0 < radProc n a ω} with hS\n set S' : Set (Fin n → ℝ) := {ω | radProc n a ω < 0} with hS'\n have hSm : MeasurableSet S := measurableSet_lt measurable_const hcont.measurable\n have hS'm : MeasurableSet S' := measurableSet_lt hcont.measurable measurable_const\n have hneg : ∀ ω : Fin n → ℝ, radProc n a (-ω) = - radProc n a ω := by\n intro ω\n simp only [radProc, Pi.neg_apply, neg_mul, Finset.sum_neg_distrib, mul_neg]\n have hpre : (fun ω : Fin n → ℝ => -ω) ⁻¹' S = S' := by\n ext ω\n simp only [hS, hS', Set.mem_preimage, Set.mem_setOf_eq, hneg]\n constructor <;> intro h <;> linarith\n have heq : radP n S' = radP n S := by\n rw [← hpre, ← Measure.map_apply (by fun_prop) hSm, radP_neg]\n have hdisj : Disjoint S S' := by\n rw [Set.disjoint_left]; intro ω h1 h2; simp only [hS, hS', Set.mem_setOf_eq] at h1 h2; linarith\n have hle : (radP n).real S + (radP n).real S' ≤ 1 := by\n rw [← measureReal_union hdisj hS'm]\n have := measureReal_mono (μ := radP n) (Set.subset_univ (S ∪ S')) (measure_ne_top (radP n) _)\n simpa using this\n have heqr : (radP n).real S' = (radP n).real S := by\n unfold Measure.real; rw [heq]\n rw [heqr] at hle\n have hsub : {ω : Fin n → ℝ | t < radProc n a ω} ⊆ S := fun ω hω => lt_of_le_of_lt ht hω\n refine (measureReal_mono hsub (measure_ne_top _ _)).trans ?_\n linarith\n\nend Prob\n\n/- ###################################################################### -/\n/- Part 4 : packing numbers -/\n/- ###################################################################### -/\n\nsection Packing\nvariable {A : Type*} [PseudoMetricSpace A]\n\nlemma untopD_coe_eq (x : ℕ∞) (h : x ≠ ⊤) : ((x.untopD 0 : ℕ) : ℕ∞) = x := by\n lift x to ℕ using h; simp\n\nlemma card_le_packing {t : Finset A} {eps : ℝ} {s : Set A} (h : IsPacking t eps s) :\n (t.card : ℕ∞) ≤ packingNumber eps s :=\n le_sSup ⟨t, h, rfl⟩\n\nlemma card_le_packNat {t : Finset A} {eps : ℝ} {s : Set A} (h : IsPacking t eps s)\n (hfin : packingNumber eps s ≠ ⊤) : t.card ≤ (packingNumber eps s).untopD 0 := by\n have := card_le_packing h\n rw [← untopD_coe_eq _ hfin] at this\n exact_mod_cast this\n\nlemma exists_max_packing {eps : ℝ} {s : Set A} (hfin : packingNumber eps s ≠ ⊤) :\n ∃ t : Finset A, IsPacking t eps s ∧ t.card = (packingNumber eps s).untopD 0 := by\n set N := (packingNumber eps s).untopD 0 with hN\n by_contra hc\n push_neg at hc\n have hlt : ∀ t : Finset A, IsPacking t eps s → (t.card : ℕ∞) ≤ ((N - 1 : ℕ) : ℕ∞) := by\n intro t ht\n have h1 : t.card ≤ N := card_le_packNat ht hfin\n have h2 : t.card ≠ N := hc t ht\n have : t.card ≤ N - 1 := Nat.le_sub_one_of_lt (lt_of_le_of_ne h1 h2)\n exact_mod_cast this\n have hsup : packingNumber eps s ≤ ((N - 1 : ℕ) : ℕ∞) := by\n apply sSup_le\n rintro x ⟨t, ht, rfl⟩\n exact hlt t ht\n rw [← untopD_coe_eq _ hfin, ← hN] at hsup\n have hNle : N ≤ N - 1 := by exact_mod_cast hsup\n have hN0 : N = 0 := by omega\n exact hc ∅ ⟨by simp, by simp⟩ (by simp [hN0])\n\n/-- A packing of maximum cardinality is a net. -/\nlemma max_packing_isNet {eps : ℝ} (heps : 0 ≤ eps) {s : Set A} (hfin : packingNumber eps s ≠ ⊤)\n {t : Finset A} (ht : IsPacking t eps s) (hcard : t.card = (packingNumber eps s).untopD 0) :\n ∀ f ∈ s, ∃ g ∈ t, dist f g ≤ eps := by\n classical\n intro f hf\n by_contra hcon\n push_neg at hcon\n have hfnot : f ∉ t := by\n intro hft\n have h2 := hcon f hft\n rw [dist_self] at h2\n linarith\n have hins : IsPacking (insert f t) eps s := by\n constructor\n · rw [Finset.coe_insert]; exact Set.insert_subset hf ht.1\n · rw [Finset.coe_insert]\n intro x hx y hy hxy\n simp only [Set.mem_insert_iff, Finset.mem_coe] at hx hy\n rcases hx with rfl | hx\n · rcases hy with rfl | hy\n · exact absurd rfl hxy\n · exact hcon y hy\n · rcases hy with rfl | hy\n · rw [dist_comm]; exact hcon x hx\n · exact ht.2 (by simpa using hx) (by simpa using hy) hxy\n have := card_le_packNat hins hfin\n rw [Finset.card_insert_of_notMem hfnot, hcard] at this\n omega\n\n/-- packing numbers are antitone in the scale -/\nlemma packing_antitone {eps eps' : ℝ} (h : eps ≤ eps') (s : Set A) :\n packingNumber eps' s ≤ packingNumber eps s := by\n apply sSup_le\n rintro x ⟨t, ht, rfl⟩\n exact le_sSup ⟨t, ⟨ht.1, fun a ha b hb hab => lt_of_le_of_lt h (ht.2 ha hb hab)⟩, rfl⟩\n\nend Packing\n\n/- ###################################################################### -/\n/- Part 5 : elementary facts about `radProc` -/\n/- ###################################################################### -/\n\nsection RadProc\nvariable {n : ℕ}\n\nlemma radProc_sub (a b : Fin n → ℝ) (ω : Fin n → ℝ) :\n radProc n (a - b) ω = radProc n a ω - radProc n b ω := by\n simp only [radProc, Pi.sub_apply, mul_sub, Finset.sum_sub_distrib, mul_sub]\n\nlemma dist_zero_sub (a b : Fin n → ℝ) :\n dist (0 : EmpL2 n) (show EmpL2 n from a - b)\n = dist (show EmpL2 n from a) (show EmpL2 n from b) := by\n rw [dist_eq', dist_eq']\n congr 1\n refine Finset.sum_congr rfl fun i _ => ?_\n have h : (((0 : EmpL2 n) : Fin n → ℝ) i - (a - b) i) = -(a i - b i) := by\n show (0:ℝ) - (a i - b i) = -(a i - b i); ring\n rw [h, neg_div, neg_pow]\n simp\n\nlemma radProc_le_dist (hn : 0 < n) (a : Fin n → ℝ) (ω : Fin n → ℝ) (hω : ∀ i, |ω i| ≤ 1) :\n radProc n a ω ≤ dist (0 : EmpL2 n) a := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n set D := dist (0 : EmpL2 n) a with hDdef\n have hD0 : 0 ≤ D := dist_nonneg\n have hcs := Real.sum_mul_le_sqrt_mul_sqrt Finset.univ ω a\n have h1 : (∑ i : Fin n, (ω i)^2) ≤ (n:ℝ) := by\n have hb : ∀ i : Fin n, (ω i)^2 ≤ (1:ℝ) := by\n intro i\n have := abs_le.mp (hω i)\n nlinarith [this.1, this.2]\n calc (∑ i : Fin n, (ω i)^2) ≤ ∑ _i : Fin n, (1:ℝ) := Finset.sum_le_sum (fun i _ => hb i)\n _ = (n:ℝ) := by simp\n have h2 : (∑ i : Fin n, (a i)^2) = (n:ℝ) * D^2 := sum_sq_eq hn a\n have h3 : Real.sqrt (∑ i : Fin n, (ω i)^2) ≤ Real.sqrt n := Real.sqrt_le_sqrt h1\n have h4 : Real.sqrt (∑ i : Fin n, (a i)^2) = Real.sqrt n * D := by\n rw [h2, Real.sqrt_mul hn'.le, Real.sqrt_sq hD0]\n have h6 : Real.sqrt n * Real.sqrt n = (n:ℝ) := Real.mul_self_sqrt hn'.le\n have h5 : (∑ i : Fin n, ω i * a i) ≤ (n:ℝ) * D := by\n refine hcs.trans ?_\n rw [h4]\n calc Real.sqrt (∑ i : Fin n, (ω i)^2) * (Real.sqrt n * D)\n ≤ Real.sqrt n * (Real.sqrt n * D) :=\n mul_le_mul_of_nonneg_right h3 (by positivity)\n _ = (n:ℝ) * D := by rw [← mul_assoc, h6]\n rw [radProc, one_div]\n calc (n:ℝ)⁻¹ * (∑ i, ω i * a i) ≤ (n:ℝ)⁻¹ * ((n:ℝ) * D) :=\n mul_le_mul_of_nonneg_left h5 (by positivity)\n _ = D := by field_simp\n\nend RadProc\n\n/- ###################################################################### -/\n/- Part 6 : a convergent series bound -/\n/- ###################################################################### -/\n\n/-- `Wser m = ∑_{p=2}^m p⁻³`. -/\ndef Wser (m : ℕ) : ℝ := ∑ p ∈ Finset.Ioc 1 m, (1:ℝ)/(p:ℝ)^3\n\nlemma Wser_nonneg (m : ℕ) : 0 ≤ Wser m :=\n Finset.sum_nonneg fun i _ => by positivity\n\nlemma Wser_mono {a b : ℕ} (h : a ≤ b) : Wser a ≤ Wser b := by\n unfold Wser\n refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.Ioc_subset_Ioc_right h) ?_\n intro i _ _; positivity\n\nlemma Wser_succ (m : ℕ) (hm : 1 ≤ m) : Wser (m+1) = Wser m + 1/((m:ℝ)+1)^3 := by\n unfold Wser\n rw [← Finset.sum_Ioc_consecutive _ hm (Nat.le_succ m)]\n congr 1\n rw [show Finset.Ioc m (m+1) = {m+1} from by ext x; simp only [Finset.mem_Ioc, Finset.mem_singleton]; omega]\n push_cast\n simp\n\nlemma Wser_le (m : ℕ) : Wser m ≤ 5/24 := by\n rcases le_or_gt m 1 with h | h\n · have he : Finset.Ioc 1 m = (∅ : Finset ℕ) := by\n rw [Finset.Ioc_eq_empty]; omega\n simp only [Wser, he, Finset.sum_empty]\n norm_num\n · have key : ∀ m : ℕ, 2 ≤ m → Wser m ≤ 5/24 - 1/(2*(m:ℝ)*((m:ℝ)+1)) := by\n intro m hm\n induction m, hm using Nat.le_induction with\n | base =>\n rw [show Wser 2 = 1/8 from by\n unfold Wser\n rw [show Finset.Ioc 1 2 = ({2} : Finset ℕ) from by ext x; simp only [Finset.mem_Ioc, Finset.mem_singleton]; omega]\n norm_num]\n norm_num\n | succ m hm ih =>\n have hm' : (2:ℝ) ≤ (m:ℝ) := by exact_mod_cast hm\n have hmpos : (0:ℝ) < (m:ℝ) := by linarith\n rw [Wser_succ m (by omega)]\n have e1 : 1/(2*(m:ℝ)*((m:ℝ)+1)) - 1/(2*((m:ℝ)+1)*((m:ℝ)+1+1))\n = 1/((m:ℝ)*((m:ℝ)+1)*((m:ℝ)+2)) := by\n field_simp; ring\n have e2 : 1/((m:ℝ)+1)^3 ≤ 1/((m:ℝ)*((m:ℝ)+1)*((m:ℝ)+2)) := by\n refine one_div_le_one_div_of_le (by positivity) ?_\n nlinarith\n push_cast\n linarith [ih]\n have hge : 0 < 1/(2*(m:ℝ)*((m:ℝ)+1)) := by\n have : (0:ℝ) < (m:ℝ) := by exact_mod_cast Nat.lt_of_lt_of_le Nat.zero_lt_one h.le\n positivity\n linarith [key m h]\n\nlemma Wser_diff_ge {a b : ℕ} (ha : 1 ≤ a) (hab : a < b) :\n (1:ℝ)/(b:ℝ)^3 ≤ Wser b - Wser a := by\n have hsplit : Wser a + ∑ p ∈ Finset.Ioc a b, (1:ℝ)/(p:ℝ)^3 = Wser b := by\n unfold Wser\n exact Finset.sum_Ioc_consecutive _ ha hab.le\n have hmem : b ∈ Finset.Ioc a b := by simp [hab]\n have := Finset.single_le_sum (f := fun p : ℕ => (1:ℝ)/(p:ℝ)^3)\n (fun i _ => by positivity) hmem\n linarith\n\n/- ###################################################################### -/\n/- Part 7 : a coherent family of maximal packings (\"nets\") -/\n/- ###################################################################### -/\n\nsection Nets\nvariable {A : Type*} [PseudoMetricSpace A]\n\nlemma half_pow_le {i j : ℕ} (h : i ≤ j) : (1/2:ℝ)^j ≤ (1/2:ℝ)^i := by\n exact pow_le_pow_of_le_one (by norm_num) (by norm_num) h\n\nlemma exists_nets (s : Set A) (hfin : ∀ j : ℕ, packingNumber ((1/2:ℝ)^j) s ≠ ⊤) :\n ∃ T : ℕ → Finset A,\n (∀ j, (T j).card = (packingNumber ((1/2:ℝ)^j) s).untopD 0) ∧\n (∀ j, ∀ f ∈ s, ∃ g ∈ T j, dist f g ≤ (1/2:ℝ)^j) ∧\n (∀ j, (packingNumber ((1/2:ℝ)^(j+1)) s).untopD 0\n = (packingNumber ((1/2:ℝ)^j) s).untopD 0 → T (j+1) = T j) := by\n classical\n choose t ht hcard using fun j : ℕ => exists_max_packing (hfin j)\n set N : ℕ → ℕ := fun j => (packingNumber ((1/2:ℝ)^j) s).untopD 0 with hN\n refine ⟨fun j => Nat.rec (t 0) (fun i prev => if N (i+1) = N i then prev else t (i+1)) j,\n ?_, ?_, ?_⟩\n · intro j\n induction j with\n | zero => exact hcard 0\n | succ i ih =>\n show (if N (i+1) = N i then _ else t (i+1)).card = N (i+1)\n by_cases h : N (i+1) = N i\n · rw [if_pos h, ih, h]\n · rw [if_neg h]; exact hcard (i+1)\n · -- net property\n intro j\n have hpack : ∀ j : ℕ, IsPacking\n (Nat.rec (motive := fun _ => Finset A) (t 0)\n (fun i prev => if N (i+1) = N i then prev else t (i+1)) j) ((1/2:ℝ)^j) s := by\n intro j\n induction j with\n | zero => exact ht 0\n | succ i ih =>\n show IsPacking (if N (i+1) = N i then _ else t (i+1)) _ _\n by_cases h : N (i+1) = N i\n · rw [if_pos h]\n exact ⟨ih.1, fun x hx y hy hxy =>\n lt_of_le_of_lt (half_pow_le (Nat.le_succ i)) (ih.2 hx hy hxy)⟩\n · rw [if_neg h]; exact ht (i+1)\n have hcd : ∀ j : ℕ, (Nat.rec (motive := fun _ => Finset A) (t 0)\n (fun i prev => if N (i+1) = N i then prev else t (i+1)) j).card = N j := by\n intro j\n induction j with\n | zero => exact hcard 0\n | succ i ih =>\n show (if N (i+1) = N i then _ else t (i+1)).card = N (i+1)\n by_cases h : N (i+1) = N i\n · rw [if_pos h, ih, h]\n · rw [if_neg h]; exact hcard (i+1)\n exact max_packing_isNet (by positivity) (hfin j) (hpack j) (hcd j)\n · intro j hj\n show (if N (j+1) = N j then _ else t (j+1)) = _\n rw [if_pos hj]\n\nend Nets\n\n/- ###################################################################### -/\n/- Part 8 : nearest–point projection onto a finite set -/\n/- ###################################################################### -/\n\ndef nearest {A : Type*} [PseudoMetricSpace A] (T : Finset A) (f : A) : A :=\n if h : T.Nonempty then Classical.choose (T.exists_min_image (dist f) h) else f\n\nlemma nearest_mem {A : Type*} [PseudoMetricSpace A] {T : Finset A} (h : T.Nonempty) (f : A) :\n nearest T f ∈ T := by\n unfold nearest; rw [dif_pos h]\n exact (Classical.choose_spec (T.exists_min_image (dist f) h)).1\n\nlemma nearest_le {A : Type*} [PseudoMetricSpace A] {T : Finset A} (h : T.Nonempty) (f : A) :\n ∀ g ∈ T, dist f (nearest T f) ≤ dist f g := by\n unfold nearest; rw [dif_pos h]\n exact (Classical.choose_spec (T.exists_min_image (dist f) h)).2\n\n/- ###################################################################### -/\n/- Part 9 : lower bound of an integral by a dyadic sum -/\n/- ###################################################################### -/\n\nlemma integral_ge_dyadic_sum {φ : ℝ → ℝ} {D : ℝ}\n (hphi0 : ∀ x, 0 ≤ φ x)\n (hint : IntervalIntegrable φ MeasureTheory.volume 0 D)\n (c : ℕ → ℝ)\n (hmono : ∀ m : ℕ, ∀ x ∈ Set.Icc ((1/2:ℝ)^(m+1)) ((1/2:ℝ)^m), c m ≤ φ x)\n (k J : ℕ) (hkJ : k ≤ J) (hk : (1/2:ℝ)^k ≤ D) :\n ∑ m ∈ Finset.Icc k J, (1/2:ℝ)^(m+1) * c m ≤ ∫ x in (0:ℝ)..D, φ x := by\n have hD : 0 ≤ D := le_trans (by positivity) hk\n have hsub : ∀ x y : ℝ, 0 ≤ x → x ≤ y → y ≤ D → IntervalIntegrable φ MeasureTheory.volume x y := by\n intro x y hx hxy hy\n refine hint.mono_set ?_\n rw [Set.uIcc_of_le hxy, Set.uIcc_of_le hD]\n exact Set.Icc_subset_Icc hx hy\n have hpow_le : ∀ m : ℕ, (1/2:ℝ)^(m+1) ≤ (1/2:ℝ)^m := fun m => half_pow_le (Nat.le_succ m)\n have hpow_leD : ∀ m : ℕ, k ≤ m → (1/2:ℝ)^m ≤ D := fun m hm =>\n le_trans (half_pow_le hm) hk\n -- one step\n have hstep : ∀ m : ℕ, k ≤ m → (1/2:ℝ)^(m+1) * c m\n ≤ ∫ x in ((1/2:ℝ)^(m+1))..((1/2:ℝ)^m), φ x := by\n intro m hm\n have hii : IntervalIntegrable φ MeasureTheory.volume ((1/2:ℝ)^(m+1)) ((1/2:ℝ)^m) :=\n hsub _ _ (by positivity) (hpow_le m) (hpow_leD m hm)\n have h1 : (∫ x in ((1/2:ℝ)^(m+1))..((1/2:ℝ)^m), c m)\n ≤ ∫ x in ((1/2:ℝ)^(m+1))..((1/2:ℝ)^m), φ x := by\n refine intervalIntegral.integral_mono_on (hpow_le m) intervalIntegrable_const hii ?_\n intro x hx\n exact hmono m x hx\n rw [intervalIntegral.integral_const] at h1\n have : (1/2:ℝ)^m - (1/2:ℝ)^(m+1) = (1/2:ℝ)^(m+1) := by ring\n simp only [smul_eq_mul] at h1\n rw [this] at h1\n exact h1\n -- the telescoped sum\n have main : ∀ J : ℕ, k ≤ J →\n ∑ m ∈ Finset.Icc k J, (1/2:ℝ)^(m+1) * c m\n ≤ ∫ x in ((1/2:ℝ)^(J+1))..((1/2:ℝ)^k), φ x := by\n intro J hJ\n induction J, hJ using Nat.le_induction with\n | base =>\n rw [Finset.Icc_self, Finset.sum_singleton]\n exact hstep k le_rfl\n | succ J hJ ih =>\n have hsplit : ∑ m ∈ Finset.Icc k (J+1), (1/2:ℝ)^(m+1) * c m\n = (∑ m ∈ Finset.Icc k J, (1/2:ℝ)^(m+1) * c m) + (1/2:ℝ)^(J+1+1) * c (J+1) :=\n Finset.sum_Icc_succ_top (by omega) _\n rw [hsplit]\n have hadj : (∫ x in ((1/2:ℝ)^(J+1+1))..((1/2:ℝ)^(J+1)), φ x)\n + (∫ x in ((1/2:ℝ)^(J+1))..((1/2:ℝ)^k), φ x)\n = ∫ x in ((1/2:ℝ)^(J+1+1))..((1/2:ℝ)^k), φ x := by\n refine intervalIntegral.integral_add_adjacent_intervals\n (hsub _ _ (by positivity) (hpow_le (J+1)) (hpow_leD (J+1) (by omega)))\n (hsub _ _ (by positivity) (half_pow_le (by omega)) (hpow_leD k le_rfl))\n have := hstep (J+1) (by omega)\n linarith [ih, hadj]\n refine le_trans (main J hkJ) ?_\n -- extend the integral to [0, D]\n have e1 : (∫ x in (0:ℝ)..((1/2:ℝ)^(J+1)), φ x) + (∫ x in ((1/2:ℝ)^(J+1))..D, φ x)\n = ∫ x in (0:ℝ)..D, φ x :=\n intervalIntegral.integral_add_adjacent_intervals\n (hsub _ _ le_rfl (by positivity) (le_trans (half_pow_le (by omega : k ≤ J+1)) hk))\n (hsub _ _ (by positivity) (le_trans (half_pow_le (by omega : k ≤ J+1)) hk) le_rfl)\n have e2 : (∫ x in ((1/2:ℝ)^(J+1))..((1/2:ℝ)^k), φ x) + (∫ x in ((1/2:ℝ)^k)..D, φ x)\n = ∫ x in ((1/2:ℝ)^(J+1))..D, φ x :=\n intervalIntegral.integral_add_adjacent_intervals\n (hsub _ _ (by positivity) (half_pow_le (by omega : k ≤ J+1)) (hpow_leD k le_rfl))\n (hsub _ _ (by positivity) (hpow_leD k le_rfl) le_rfl)\n have p1 : 0 ≤ ∫ x in (0:ℝ)..((1/2:ℝ)^(J+1)), φ x :=\n intervalIntegral.integral_nonneg (by positivity) (fun x _ => hphi0 x)\n have p2 : 0 ≤ ∫ x in ((1/2:ℝ)^k)..D, φ x :=\n intervalIntegral.integral_nonneg (hpow_leD k le_rfl) (fun x _ => hphi0 x)\n linarith\n\n/- ###################################################################### -/\n/- Part 10 : a `tsum` helper -/\n/- ###################################################################### -/\n\nlemma tsum_le_of_partial_sums {c : ℕ → ℝ≥0∞} {B : ℝ≥0∞}\n (h : ∀ M : ℕ, ∑ i ∈ Finset.range M, c i ≤ B) : ∑' i, c i ≤ B := by\n rw [ENNReal.tsum_eq_iSup_sum]\n refine iSup_le fun s => ?_\n have hsub : s ⊆ Finset.range (s.sup id + 1) := by\n intro x hx\n simp only [Finset.mem_range]\n have hle : id x ≤ s.sup id := Finset.le_sup hx\n simpa using Nat.lt_succ_of_le hle\n exact le_trans (Finset.sum_le_sum_of_subset hsub) (h _)\n\n/- ###################################################################### -/\n/- Part 11 : numeric helpers -/\n/- ###################################################################### -/\n\nlemma sqrt_add_le_add {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) :\n Real.sqrt (a + b) ≤ Real.sqrt a + Real.sqrt b := by\n have key : a + b ≤ (Real.sqrt a + Real.sqrt b)^2 := by\n have h1 : Real.sqrt a ^ 2 = a := Real.sq_sqrt ha\n have h2 : Real.sqrt b ^ 2 = b := Real.sq_sqrt hb\n nlinarith [Real.sqrt_nonneg a, Real.sqrt_nonneg b]\n calc Real.sqrt (a+b) ≤ Real.sqrt ((Real.sqrt a + Real.sqrt b)^2) := Real.sqrt_le_sqrt key\n _ = Real.sqrt a + Real.sqrt b := Real.sqrt_sq (by positivity)\n\nlemma two_rpow_92 : (2:ℝ)^(9/2:ℝ) = 16 * Real.sqrt 2 := by\n rw [show (9/2:ℝ) = 4 + 1/2 by norm_num, Real.rpow_add (by norm_num)]\n rw [show (4:ℝ) = ((4:ℕ):ℝ) by norm_num, Real.rpow_natCast]\n rw [← Real.sqrt_eq_rpow]\n norm_num\n\nlemma two_rpow_72 : (2:ℝ)^(7/2:ℝ) = 8 * Real.sqrt 2 := by\n rw [show (7/2:ℝ) = 3 + 1/2 by norm_num, Real.rpow_add (by norm_num)]\n rw [show (3:ℝ) = ((3:ℕ):ℝ) by norm_num, Real.rpow_natCast]\n rw [← Real.sqrt_eq_rpow]\n norm_num\n\nlemma sqrt_two_v {n : ℕ} (hn : 0 < n) {a b u L : ℝ} (hu : 0 ≤ u) (hL : 0 ≤ L)\n (ha : 0 ≤ a) (hb : 0 ≤ b) :\n Real.sqrt (2 * (a*u + b*L) / n)\n ≤ Real.sqrt (2*a) * Real.sqrt (u/n) + Real.sqrt (2*b) * (Real.sqrt L / Real.sqrt n) := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hsplit : 2 * (a*u + b*L) / n = (2*a) * (u/n) + (2*b) * (L/n) := by field_simp; try ring\n have e1 : Real.sqrt ((2*a) * (u/(n:ℝ))) = Real.sqrt (2*a) * Real.sqrt (u/n) :=\n Real.sqrt_mul (by positivity) _\n have e2 : Real.sqrt ((2*b) * (L/(n:ℝ))) = Real.sqrt (2*b) * (Real.sqrt L / Real.sqrt n) := by\n rw [Real.sqrt_mul (by positivity), Real.sqrt_div hL]\n rw [hsplit]\n refine (sqrt_add_le_add (by positivity) (by positivity)).trans ?_\n rw [e1, e2]\n\nlemma sqrt8_eq : Real.sqrt 8 = 2 * Real.sqrt 2 := by\n rw [show (8:ℝ) = 2^2*2 by norm_num, Real.sqrt_mul (by positivity), Real.sqrt_sq (by norm_num)]\n\nlemma five_sqrt5_le : 5*Real.sqrt 5 ≤ 8*Real.sqrt 2 := by\n have h5 : Real.sqrt 5 ^2 = 5 := Real.sq_sqrt (by norm_num)\n have h2 : Real.sqrt 2 ^2 = 2 := Real.sq_sqrt (by norm_num)\n nlinarith [Real.sqrt_nonneg 5, Real.sqrt_nonneg 2]\n\nlemma six_sqrt14_le : 6*Real.sqrt 14 ≤ 16*Real.sqrt 2 := by\n have h14 : Real.sqrt 14 ^2 = 14 := Real.sq_sqrt (by norm_num)\n have h2 : Real.sqrt 2 ^2 = 2 := Real.sq_sqrt (by norm_num)\n nlinarith [Real.sqrt_nonneg 14, Real.sqrt_nonneg 2]\n\nlemma sqrt_vS {n : ℕ} (hn : 0 < n) {u L : ℝ} (hu : 0 ≤ u) (hL : 0 ≤ L) :\n Real.sqrt (2 * ((5/2)*u + 4*L) / n)\n ≤ Real.sqrt 5 * Real.sqrt (u/n) + 2*Real.sqrt 2 * (Real.sqrt L / Real.sqrt n) := by\n have h := sqrt_two_v hn (a := 5/2) (b := 4) hu hL (by norm_num) (by norm_num)\n have e1 : Real.sqrt (2*(5/2:ℝ)) = Real.sqrt 5 := by norm_num\n have e2 : Real.sqrt (2*(4:ℝ)) = 2*Real.sqrt 2 := by\n rw [show (2:ℝ)*4 = 8 by norm_num]; exact sqrt8_eq\n rw [e1, e2] at h\n exact h\n\nlemma sqrt_vL {n : ℕ} (hn : 0 < n) {u L : ℝ} (hu : 0 ≤ u) (hL : 0 ≤ L) :\n Real.sqrt (2 * ((5/2)*u + 7*L) / n)\n ≤ Real.sqrt 5 * Real.sqrt (u/n) + Real.sqrt 14 * (Real.sqrt L / Real.sqrt n) := by\n have h := sqrt_two_v hn (a := 5/2) (b := 7) hu hL (by norm_num) (by norm_num)\n have e1 : Real.sqrt (2*(5/2:ℝ)) = Real.sqrt 5 := by norm_num\n have e2 : Real.sqrt (2*(7:ℝ)) = Real.sqrt 14 := by norm_num\n rw [e1, e2] at h\n exact h\n\n/- ###################################################################### -/\n/- Part 12 : the theorem -/\n/- ###################################################################### -/\n\nset_option maxHeartbeats 4000000 in\ntheorem ch14_theorem_14_1\n {n : ℕ} (hn : 0 < n)\n (P : Measure (Fin n → ℝ)) [IsProbabilityMeasure P]\n (hP : P = Measure.pi\n (fun _ : Fin n => ((1 : ℝ≥0∞) / 2) • (Measure.dirac (-1 : ℝ) + Measure.dirac 1)))\n (F : Set (EmpL2 n))\n (hFbdd : ∀ f ∈ F, ∀ i, |(f : Fin n → ℝ) i| ≤ 1)\n (hFin : ∀ ε : ℝ, 0 < ε → packingNumber ε F ≠ ⊤)\n (hD : ∀ f ∈ F, ∀ ε ∈ Set.Ioo (0:ℝ) (dist (0 : EmpL2 n) f),\n (1 : ℝ) ≤ (((packingNumber ε F).untopD 0 : ℕ) : ℝ))\n (hInt : ∀ f ∈ F, IntervalIntegrable\n (fun ε => Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)))\n MeasureTheory.volume 0 (dist (0 : EmpL2 n) f))\n (u : ℝ) (hu : 0 < u) :\n (1 : ℝ) - Real.exp (-u) ≤\n (P {ω | ∀ f ∈ F, radProc n (f : Fin n → ℝ) ω ≤\n (2 ^ (9/2 : ℝ) / Real.sqrt n) *\n (∫ ε in (0:ℝ)..(dist (0 : EmpL2 n) f),\n Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)))\n + 2 ^ (7/2 : ℝ) * dist (0 : EmpL2 n) f * Real.sqrt (u / n)}).toReal := by\n classical\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hPeq : P = radP n := hP\n rw [hPeq]\n obtain ⟨Gset, hGset⟩ : ∃ G : Set (Fin n → ℝ), G =\n {ω | ∀ f ∈ F, radProc n (f : Fin n → ℝ) ω ≤\n (2 ^ (9/2 : ℝ) / Real.sqrt n) *\n (∫ ε in (0:ℝ)..(dist (0 : EmpL2 n) f),\n Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)))\n + 2 ^ (7/2 : ℝ) * dist (0 : EmpL2 n) f * Real.sqrt (u / n)} := ⟨_, rfl⟩\n rw [← hGset]\n rcases Set.eq_empty_or_nonempty F with hFe | hFne\n · have hsu : Gset = Set.univ := by rw [hGset]; ext ω; simp [hFe]\n rw [hsu, measure_univ]\n simp only [ENNReal.toReal_one]\n linarith [Real.exp_pos (-u)]\n -- ### the real work ###\n have hfin : ∀ j : ℕ, packingNumber ((1/2:ℝ)^j) F ≠ ⊤ := fun j => hFin _ (by positivity)\n obtain ⟨T, hTcard, hTnet, hTstab⟩ := exists_nets F hfin\n obtain ⟨N, hNdef⟩ : ∃ N : ℕ → ℕ, ∀ j, N j = (packingNumber ((1/2:ℝ)^j) F).untopD 0 :=\n ⟨_, fun _ => rfl⟩\n have hTcard' : ∀ j, (T j).card = N j := by intro j; rw [hNdef]; exact hTcard j\n have hN1 : ∀ j, 1 ≤ N j := by\n intro j\n obtain ⟨f0, hf0⟩ := hFne\n have hpk : IsPacking ({f0} : Finset (EmpL2 n)) ((1/2:ℝ)^j) F := by\n refine ⟨by simpa using hf0, ?_⟩\n intro x hx y hy hxy\n simp only [Finset.coe_singleton, Set.mem_singleton_iff] at hx hy\n exact absurd (hx.trans hy.symm) hxy\n have := card_le_packNat hpk (hfin j)\n rw [← hNdef] at this\n simpa using this\n have hNmono : ∀ i j, i ≤ j → N i ≤ N j := by\n intro i j hij\n have h1 := packing_antitone (half_pow_le hij) F\n rw [← untopD_coe_eq _ (hfin i), ← untopD_coe_eq _ (hfin j), ← hNdef, ← hNdef] at h1\n exact_mod_cast h1\n have hTne : ∀ j, (T j).Nonempty := by\n intro j; rw [← Finset.card_pos, hTcard' j]; exact hN1 j\n have hlogN : ∀ j, 0 ≤ Real.log (N j) := by\n intro j\n apply Real.log_nonneg\n exact_mod_cast hN1 j\n -- the events\n obtain ⟨Ev, hEv⟩ : ∃ Ev : (Fin n → ℝ) → ℝ → Set (Fin n → ℝ),\n ∀ a v, Ev a v = {ω | dist (0:EmpL2 n) a * Real.sqrt (2*v/n) < radProc n a ω} :=\n ⟨_, fun _ _ => rfl⟩\n obtain ⟨vS, hvS⟩ : ∃ vS : ℕ → ℝ, ∀ i, vS i = (5/2)*u + 4 * Real.log (N i) := ⟨_, fun _ => rfl⟩\n obtain ⟨vL, hvL⟩ : ∃ vL : ℕ → ℝ, ∀ i, vL i = (5/2)*u + 7 * Real.log (N i) := ⟨_, fun _ => rfl⟩\n have hvS0 : ∀ i, 0 ≤ vS i := by\n intro i; rw [hvS]; have := hlogN i; linarith\n have hvL0 : ∀ i, 0 ≤ vL i := by\n intro i; rw [hvL]; have := hlogN i; linarith\n obtain ⟨BadS, hBadS⟩ : ∃ BadS : ℕ → Set (Fin n → ℝ), ∀ i, BadS i =\n if (0 < i ∧ N i = N (i-1)) then ∅ else ⋃ h ∈ T i, Ev (h : Fin n → ℝ) (vS i) :=\n ⟨_, fun _ => rfl⟩\n obtain ⟨BadL, hBadL⟩ : ∃ BadL : ℕ → Set (Fin n → ℝ), ∀ j, BadL j =\n if N (j+1) = N j then ∅\n else ⋃ g ∈ T j, ⋃ h ∈ T (j+1), Ev ((show Fin n → ℝ from h) - (show Fin n → ℝ from g)) (vL (j+1)) :=\n ⟨_, fun _ => rfl⟩\n obtain ⟨Wset, hWset⟩ : ∃ W : Set (Fin n → ℝ), W = {ω | ∀ i, |ω i| ≤ 1} := ⟨_, rfl⟩\n obtain ⟨Bad, hBad⟩ : ∃ B : Set (Fin n → ℝ), B = (⋃ i, BadS i) ∪ (⋃ j, BadL j) ∪ Wsetᶜ :=\n ⟨_, rfl⟩\n -- ### Claim A : Bad ᶜ ⊆ Gset ###\n have claimA : Badᶜ ⊆ Gset := by\n intro ω hω\n rw [hBad] at hω\n simp only [Set.mem_compl_iff, Set.mem_union, not_or] at hω\n obtain ⟨⟨hωS, hωL⟩, hωW⟩ := hω\n have hωW' : ∀ i, |ω i| ≤ 1 := by\n have hmem : ω ∈ Wset := not_not.mp hωW\n rw [hWset] at hmem; exact hmem\n have hEvnot : ∀ (a : Fin n → ℝ) (v : ℝ), ω ∉ Ev a v →\n radProc n a ω ≤ dist (0:EmpL2 n) a * Real.sqrt (2*v/n) := by\n intro a v h\n rw [hEv] at h\n simpa only [Set.mem_setOf_eq, not_lt] using h\n -- the \"start\" bound holds at every level\n have hstart : ∀ i, ∀ h ∈ T i, radProc n (show Fin n → ℝ from h) ω\n ≤ dist (0:EmpL2 n) (show Fin n → ℝ from h) * Real.sqrt (2 * vS i / n) := by\n intro i\n induction i with\n | zero =>\n intro h hh\n have hnb : ω ∉ BadS 0 := fun hc => hωS (Set.mem_iUnion.mpr ⟨0, hc⟩)\n rw [hBadS, if_neg (by rintro ⟨hcc, -⟩; exact absurd hcc (lt_irrefl 0))] at hnb\n exact hEvnot _ _ (fun hc => hnb (Set.mem_biUnion hh hc))\n | succ i ih =>\n intro h hh\n by_cases hc : N (i+1) = N i\n · have hTeq : T (i+1) = T i := hTstab i (by rw [← hNdef, ← hNdef]; exact hc)\n have hvSeq : vS (i+1) = vS i := by rw [hvS, hvS, hc]\n rw [hvSeq]\n exact ih h (by rw [← hTeq]; exact hh)\n · have hnb : ω ∉ BadS (i+1) := fun hcc => hωS (Set.mem_iUnion.mpr ⟨i+1, hcc⟩)\n rw [hBadS, if_neg (by rintro ⟨-, h2⟩; exact hc (by simpa using h2))] at hnb\n exact hEvnot _ _ (fun hc2 => hnb (Set.mem_biUnion hh hc2))\n rw [hGset]\n intro f hf\n obtain ⟨Df, hDf⟩ : ∃ d : ℝ, d = dist (0 : EmpL2 n) f := ⟨_, rfl⟩\n have hDf0 : 0 ≤ Df := by rw [hDf]; exact dist_nonneg\n rcases eq_or_lt_of_le hDf0 with hD0 | hDpos\n · -- degenerate case f = 0\n have hsum : (∑ i, ((f : Fin n → ℝ) i)^2) = 0 := by\n rw [sum_sq_eq hn f, ← hDf, ← hD0]; ring\n have hfz : ∀ i, (f : Fin n → ℝ) i = 0 := by\n intro i\n have h2 := (Finset.sum_eq_zero_iff_of_nonneg\n (fun i (_ : i ∈ Finset.univ) => sq_nonneg ((f : Fin n → ℝ) i))).mp hsum i\n (Finset.mem_univ i)\n exact pow_eq_zero_iff (n := 2) (by norm_num) |>.mp h2\n have hr0 : radProc n (f : Fin n → ℝ) ω = 0 := by\n simp [radProc, hfz]\n have hdd : dist (0 : EmpL2 n) f = 0 := by rw [← hDf, ← hD0]\n rw [hr0, hdd]\n simp\n · -- the main case\n have hDle1 : Df ≤ 1 := by\n have hsum : (∑ i : Fin n, ((f : Fin n → ℝ) i)^2) ≤ (n:ℝ) := by\n calc (∑ i : Fin n, ((f : Fin n → ℝ) i)^2) ≤ ∑ _i : Fin n, (1:ℝ) := by\n refine Finset.sum_le_sum (fun i _ => ?_)\n have hb := abs_le.mp (hFbdd f hf i)\n nlinarith [hb.1, hb.2]\n _ = (n:ℝ) := by simp\n rw [sum_sq_eq hn f, ← hDf] at hsum\n have h2 : Df^2 ≤ 1 := by\n have h3 : (n:ℝ) * Df^2 ≤ (n:ℝ) * 1 := by linarith\n exact le_of_mul_le_mul_left h3 hn'\n nlinarith [h2, hDf0]\n have hex : ∃ j : ℕ, (1/2:ℝ)^j ≤ Df := by\n obtain ⟨j, hj⟩ := exists_pow_lt_of_lt_one hDpos (by norm_num : (1/2:ℝ) < 1)\n exact ⟨j, hj.le⟩\n obtain ⟨k, hk1, hk2⟩ : ∃ k : ℕ, (1/2:ℝ)^k ≤ Df ∧ Df < 2 * (1/2:ℝ)^k := by\n refine ⟨Nat.find hex, Nat.find_spec hex, ?_⟩\n rcases Nat.eq_zero_or_pos (Nat.find hex) with h0 | hpos\n · rw [h0]; norm_num; linarith\n · have hlt : ¬ ((1/2:ℝ)^(Nat.find hex - 1) ≤ Df) := Nat.find_min hex (by omega)\n push_neg at hlt\n have hkk : Nat.find hex - 1 + 1 = Nat.find hex := by omega\n have heq : (1/2:ℝ)^(Nat.find hex - 1) = 2 * (1/2:ℝ)^(Nat.find hex) := by\n conv_rhs => rw [← hkk]\n rw [pow_succ]; ring\n linarith\n obtain ⟨pi, hpi⟩ : ∃ p : ℕ → EmpL2 n, ∀ j, p j = nearest (T j) f := ⟨_, fun _ => rfl⟩\n have hpimem : ∀ j, pi j ∈ T j := by intro j; rw [hpi]; exact nearest_mem (hTne j) f\n have hpidist : ∀ j, dist f (pi j) ≤ (1/2:ℝ)^j := by\n intro j\n obtain ⟨g, hg, hgd⟩ := hTnet j f hf\n rw [hpi]\n exact le_trans (nearest_le (hTne j) f g hg) hgd\n -- the \"link\" bound\n have hlink : ∀ j, radProc n ((show Fin n → ℝ from pi (j+1)) -\n (show Fin n → ℝ from pi j)) ω\n ≤ dist (pi (j+1)) (pi j) * Real.sqrt (2 * vL (j+1) / n) := by\n intro j\n by_cases hc : N (j+1) = N j\n · have he : pi (j+1) = pi j := by\n rw [hpi, hpi, hTstab j (by rw [← hNdef, ← hNdef]; exact hc)]\n rw [he]\n have hz : (show Fin n → ℝ from pi j) - (show Fin n → ℝ from pi j)\n = (0 : Fin n → ℝ) := by ext i; simp\n rw [hz, show radProc n (0 : Fin n → ℝ) ω = 0 by simp [radProc]]\n exact mul_nonneg dist_nonneg (Real.sqrt_nonneg _)\n · have hnb : ω ∉ BadL j := fun hcc => hωL (Set.mem_iUnion.mpr ⟨j, hcc⟩)\n rw [hBadL, if_neg hc] at hnb\n have hnotev : ω ∉ Ev ((show Fin n → ℝ from pi (j+1)) -\n (show Fin n → ℝ from pi j)) (vL (j+1)) := by\n intro hc2\n exact hnb (Set.mem_biUnion (hpimem j) (Set.mem_biUnion (hpimem (j+1)) hc2))\n have hres := hEvnot _ _ hnotev\n rwa [dist_zero_sub] at hres\n -- distances along the chain\n have hlinkdist : ∀ j, dist (pi (j+1)) (pi j) ≤ 3 * (1/2:ℝ)^(j+1) := by\n intro j\n have h1 := dist_triangle (pi (j+1)) f (pi j)\n have h2 : dist (pi (j+1)) f = dist f (pi (j+1)) := dist_comm _ _\n have h3 := hpidist (j+1)\n have h4 := hpidist j\n have h5 : (1/2:ℝ)^j = 2 * (1/2:ℝ)^(j+1) := by rw [pow_succ]; ring\n rw [h2] at h1\n linarith\n have hstartdist : dist (0 : EmpL2 n) (pi k) ≤ 2 * Df := by\n have h1 := dist_triangle (0 : EmpL2 n) f (pi k)\n rw [← hDf] at h1\n linarith [hpidist k, hk1]\n -- the chain bound\n obtain ⟨cb, hcb⟩ : ∃ cb : ℕ → ℝ, ∀ J, cb J =\n 2*Real.sqrt 5 * Df * Real.sqrt (u/n)\n + (16*Real.sqrt 2/Real.sqrt n) *\n (∑ m ∈ Finset.Icc k J, (1/2:ℝ)^(m+1) * Real.sqrt (Real.log ((N m : ℕ):ℝ)))\n + 3*Real.sqrt 5 * ((1/2:ℝ)^k - (1/2:ℝ)^J) * Real.sqrt (u/n) := ⟨_, fun _ => rfl⟩\n have hsqn : (0:ℝ) < Real.sqrt n := Real.sqrt_pos.mpr hn'\n have hchain : ∀ J, k ≤ J → radProc n (show Fin n → ℝ from pi J) ω ≤ cb J := by\n intro J hJ\n induction J, hJ using Nat.le_induction with\n | base =>\n have h1 := hstart k (pi k) (hpimem k)\n have h2 : Real.sqrt (2 * vS k / n)\n ≤ Real.sqrt 5 * Real.sqrt (u/n)\n + 2*Real.sqrt 2 * (Real.sqrt (Real.log ((N k : ℕ):ℝ)) / Real.sqrt n) := by\n rw [hvS]\n exact sqrt_vS hn hu.le (hlogN k)\n have h3 : dist (0:EmpL2 n) (show Fin n → ℝ from pi k) * Real.sqrt (2 * vS k / n)\n ≤ (2*Df) * (Real.sqrt 5 * Real.sqrt (u/n)\n + 2*Real.sqrt 2 * (Real.sqrt (Real.log ((N k : ℕ):ℝ)) / Real.sqrt n)) := by\n refine mul_le_mul hstartdist h2 (Real.sqrt_nonneg _) (by linarith)\n have h4 : (2*Df) * (Real.sqrt 5 * Real.sqrt (u/n)\n + 2*Real.sqrt 2 * (Real.sqrt (Real.log ((N k : ℕ):ℝ)) / Real.sqrt n))\n ≤ cb k := by\n rw [hcb, Finset.Icc_self, Finset.sum_singleton]\n have hDf2 : Df ≤ 4 * (1/2:ℝ)^(k+1) := by\n have : (1/2:ℝ)^k = 2 * (1/2:ℝ)^(k+1) := by rw [pow_succ]; ring\n linarith\n have hL : (0:ℝ) ≤ Real.sqrt (Real.log ((N k : ℕ):ℝ)) := Real.sqrt_nonneg _\n have hkey : 4*Real.sqrt 2 * Df * (Real.sqrt (Real.log ((N k : ℕ):ℝ)) / Real.sqrt n)\n ≤ (16*Real.sqrt 2/Real.sqrt n) *\n ((1/2:ℝ)^(k+1) * Real.sqrt (Real.log ((N k : ℕ):ℝ))) := by\n have hQ : (0:ℝ) ≤ Real.sqrt (Real.log ((N k : ℕ):ℝ)) / Real.sqrt n := by positivity\n have hco : 4*Real.sqrt 2 * Df ≤ 16*Real.sqrt 2 * (1/2:ℝ)^(k+1) := by\n nlinarith [Real.sqrt_nonneg 2, hDf2]\n have hstep := mul_le_mul_of_nonneg_right hco hQ\n have heq : (16*Real.sqrt 2 * (1/2:ℝ)^(k+1)) *\n (Real.sqrt (Real.log ((N k : ℕ):ℝ)) / Real.sqrt n)\n = (16*Real.sqrt 2/Real.sqrt n) *\n ((1/2:ℝ)^(k+1) * Real.sqrt (Real.log ((N k : ℕ):ℝ))) := by\n field_simp; try ring\n rw [← heq]\n exact hstep\n nlinarith [hkey, Real.sqrt_nonneg 5, Real.sqrt_nonneg 2, hL]\n linarith\n | succ J hJ ih =>\n have hsplit : radProc n (show Fin n → ℝ from pi (J+1)) ω\n = radProc n (show Fin n → ℝ from pi J) ω\n + radProc n ((show Fin n → ℝ from pi (J+1)) -\n (show Fin n → ℝ from pi J)) ω := by\n rw [radProc_sub]; ring\n have h1 := hlink J\n have h2 : Real.sqrt (2 * vL (J+1) / n)\n ≤ Real.sqrt 5 * Real.sqrt (u/n)\n + Real.sqrt 14 * (Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ)) / Real.sqrt n) := by\n rw [hvL]\n exact sqrt_vL hn hu.le (hlogN (J+1))\n have h3 : dist (pi (J+1)) (pi J) * Real.sqrt (2 * vL (J+1) / n)\n ≤ (3*(1/2:ℝ)^(J+1)) * (Real.sqrt 5 * Real.sqrt (u/n)\n + Real.sqrt 14 * (Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ)) / Real.sqrt n)) :=\n mul_le_mul (hlinkdist J) h2 (Real.sqrt_nonneg _) (by positivity)\n have hIcc : (∑ m ∈ Finset.Icc k (J+1), (1/2:ℝ)^(m+1) *\n Real.sqrt (Real.log ((N m : ℕ):ℝ)))\n = (∑ m ∈ Finset.Icc k J, (1/2:ℝ)^(m+1) * Real.sqrt (Real.log ((N m : ℕ):ℝ)))\n + (1/2:ℝ)^(J+1+1) * Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ)) :=\n Finset.sum_Icc_succ_top (by omega) _\n have hL : (0:ℝ) ≤ Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ)) := Real.sqrt_nonneg _\n have hkey : 3*Real.sqrt 14 * (1/2:ℝ)^(J+1) *\n (Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ)) / Real.sqrt n)\n ≤ (16*Real.sqrt 2/Real.sqrt n) *\n ((1/2:ℝ)^(J+1+1) * Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ))) := by\n have hQ : (0:ℝ) ≤ Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ)) / Real.sqrt n := by\n positivity\n have hp : (1/2:ℝ)^(J+1) = 2 * (1/2:ℝ)^(J+1+1) := by rw [pow_succ]; ring\n have hco : 3*Real.sqrt 14 * (1/2:ℝ)^(J+1)\n ≤ 16*Real.sqrt 2 * (1/2:ℝ)^(J+1+1) := by\n rw [hp]\n nlinarith [six_sqrt14_le, pow_pos (show (0:ℝ) < 1/2 by norm_num) (J+1+1)]\n have hstep := mul_le_mul_of_nonneg_right hco hQ\n have heq : (16*Real.sqrt 2 * (1/2:ℝ)^(J+1+1)) *\n (Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ)) / Real.sqrt n)\n = (16*Real.sqrt 2/Real.sqrt n) *\n ((1/2:ℝ)^(J+1+1) * Real.sqrt (Real.log ((N (J+1) : ℕ):ℝ))) := by\n field_simp; try ring\n rw [← heq]\n exact hstep\n have hgeo : ((1/2:ℝ)^k - (1/2:ℝ)^(J+1))\n = ((1/2:ℝ)^k - (1/2:ℝ)^J) + (1/2:ℝ)^(J+1) := by\n have : (1/2:ℝ)^J = 2*(1/2:ℝ)^(J+1) := by rw [pow_succ]; ring\n linarith\n rw [hsplit, hcb, hIcc, hgeo]\n rw [hcb] at ih\n nlinarith [ih, h1, h3, hkey]\n -- the tail term\n have htail : ∀ J, radProc n (f : Fin n → ℝ) ω\n ≤ radProc n (show Fin n → ℝ from pi J) ω + (1/2:ℝ)^J := by\n intro J\n have h1 : radProc n ((show Fin n → ℝ from f) - (show Fin n → ℝ from pi J)) ω\n ≤ dist (0:EmpL2 n) ((show Fin n → ℝ from f) - (show Fin n → ℝ from pi J)) :=\n radProc_le_dist hn _ ω hωW'\n rw [dist_zero_sub] at h1\n have h2 := hpidist J\n have h3 : radProc n ((show Fin n → ℝ from f) - (show Fin n → ℝ from pi J)) ω\n = radProc n (f : Fin n → ℝ) ω - radProc n (show Fin n → ℝ from pi J) ω :=\n radProc_sub _ _ _\n rw [h3] at h1\n linarith\n -- the dyadic sum is dominated by the entropy integral\n have hentropy : ∀ J, k ≤ J →\n (∑ m ∈ Finset.Icc k J, (1/2:ℝ)^(m+1) * Real.sqrt (Real.log ((N m : ℕ):ℝ)))\n ≤ ∫ ε in (0:ℝ)..(dist (0 : EmpL2 n) f),\n Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)) := by\n intro J hJ\n refine integral_ge_dyadic_sum (φ := fun ε =>\n Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)))\n (fun x => Real.sqrt_nonneg _) (hInt f hf)\n (fun m => Real.sqrt (Real.log ((N m : ℕ):ℝ))) ?_ k J hJ (by rw [← hDf]; exact hk1)\n intro m x hx\n have hxpos : (0:ℝ) < x := lt_of_lt_of_le (by positivity) hx.1\n have hxle : x ≤ (1/2:ℝ)^m := hx.2\n have hmono : packingNumber ((1/2:ℝ)^m) F ≤ packingNumber x F :=\n packing_antitone hxle F\n have hfx : packingNumber x F ≠ ⊤ := hFin x hxpos\n have hNle : N m ≤ ((packingNumber x F).untopD 0 : ℕ) := by\n rw [hNdef]\n rw [← untopD_coe_eq _ (hfin m), ← untopD_coe_eq _ hfx] at hmono\n exact_mod_cast hmono\n refine Real.sqrt_le_sqrt (Real.log_le_log ?_ ?_)\n · exact_mod_cast hN1 m\n · exact_mod_cast hNle\n -- put everything together\n refine le_of_forall_pos_le_add ?_\n intro δ hδ\n obtain ⟨J0, hJ0⟩ := exists_pow_lt_of_lt_one hδ (show (1/2:ℝ) < 1 by norm_num)\n obtain ⟨J, hJ1, hJ2⟩ : ∃ J : ℕ, k ≤ J ∧ (1/2:ℝ)^J ≤ δ :=\n ⟨max k J0, le_max_left _ _, le_trans (half_pow_le (le_max_right _ _)) hJ0.le⟩\n refine le_trans (htail J) ?_\n have hc := hchain J hJ1\n rw [hcb] at hc\n have hI := hentropy J hJ1\n have hIpos : (0:ℝ) ≤ ∫ ε in (0:ℝ)..(dist (0 : EmpL2 n) f),\n Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ)) := by\n refine intervalIntegral.integral_nonneg (by rw [← hDf]; exact hDf0) ?_\n intro x _; exact Real.sqrt_nonneg _\n have hq : (0:ℝ) ≤ Real.sqrt (u/n) := Real.sqrt_nonneg _\n have hcoef : (16*Real.sqrt 2/Real.sqrt n) *\n (∑ m ∈ Finset.Icc k J, (1/2:ℝ)^(m+1) * Real.sqrt (Real.log ((N m : ℕ):ℝ)))\n ≤ (2 ^ (9/2 : ℝ) / Real.sqrt n) *\n (∫ ε in (0:ℝ)..(dist (0 : EmpL2 n) f),\n Real.sqrt (Real.log (((packingNumber ε F).untopD 0 : ℕ) : ℝ))) := by\n rw [two_rpow_92]\n have hpos : (0:ℝ) ≤ 16*Real.sqrt 2/Real.sqrt n := by positivity\n exact mul_le_mul_of_nonneg_left hI hpos\n have hu2 : 2*Real.sqrt 5 * Df * Real.sqrt (u/n)\n + 3*Real.sqrt 5 * ((1/2:ℝ)^k - (1/2:ℝ)^J) * Real.sqrt (u/n)\n ≤ 2 ^ (7/2 : ℝ) * dist (0 : EmpL2 n) f * Real.sqrt (u/n) := by\n rw [two_rpow_72, ← hDf]\n have h1 : (1/2:ℝ)^k - (1/2:ℝ)^J ≤ Df := by\n have := pow_pos (show (0:ℝ) < 1/2 by norm_num) J\n linarith\n have h2 : (0:ℝ) ≤ Real.sqrt 5 := Real.sqrt_nonneg _\n have h3 : 3*Real.sqrt 5 * ((1/2:ℝ)^k - (1/2:ℝ)^J) * Real.sqrt (u/n)\n ≤ 3*Real.sqrt 5 * Df * Real.sqrt (u/n) := by\n have hc : (0:ℝ) ≤ 3*Real.sqrt 5 := by positivity\n exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left h1 hc) hq\n have h4 : 5*Real.sqrt 5 * Df * Real.sqrt (u/n)\n ≤ 8*Real.sqrt 2 * Df * Real.sqrt (u/n) := by\n have hc : (0:ℝ) ≤ Df * Real.sqrt (u/n) := mul_nonneg hDf0 hq\n calc 5*Real.sqrt 5 * Df * Real.sqrt (u/n)\n = (5*Real.sqrt 5) * (Df * Real.sqrt (u/n)) := by ring\n _ ≤ (8*Real.sqrt 2) * (Df * Real.sqrt (u/n)) :=\n mul_le_mul_of_nonneg_right five_sqrt5_le hc\n _ = 8*Real.sqrt 2 * Df * Real.sqrt (u/n) := by ring\n linarith\n linarith\n -- ### Claim B : the measure of Bad is small ###\n have claimB : (radP n).real Bad ≤ Real.exp (-u) := by\n obtain ⟨E, hE⟩ : ∃ E : ℝ, E = Real.exp (-((5/2)*u)) := ⟨_, rfl⟩\n have hEpos : 0 < E := by rw [hE]; exact Real.exp_pos _\n have hEle1 : E ≤ 1 := by\n rw [hE]; rw [Real.exp_le_one_iff]; linarith\n -- probability of a single event\n have hEvProb : ∀ (a : Fin n → ℝ) (v : ℝ), 0 ≤ v →\n radP n (Ev a v) ≤ ENNReal.ofReal (min (Real.exp (-v)) (1/2)) := by\n intro a v hv\n have h1 : (radP n).real (Ev a v) ≤ Real.exp (-v) := by\n rw [hEv]; exact hoeff hn a v hv\n have h2 : (radP n).real (Ev a v) ≤ 1/2 := by\n rw [hEv]\n exact symm_half n a _ (mul_nonneg dist_nonneg (Real.sqrt_nonneg _))\n have h3 : radP n (Ev a v) = ENNReal.ofReal ((radP n).real (Ev a v)) := by\n rw [measureReal_def, ENNReal.ofReal_toReal (measure_ne_top _ _)]\n rw [h3]\n exact ENNReal.ofReal_le_ofReal (le_min h1 h2)\n -- explicit form of the exponentials\n have hexpS : ∀ i, Real.exp (-(vS i)) = E * ((N i : ℝ)^4)⁻¹ := by\n intro i\n have hx : (0:ℝ) < (N i : ℝ) := by exact_mod_cast hN1 i\n have h1 : Real.exp (4 * Real.log ((N i : ℝ))) = (N i : ℝ)^4 := by\n have hh : (4:ℝ) * Real.log ((N i:ℝ)) = Real.log ((N i:ℝ)^4) := by\n rw [Real.log_pow]; norm_num\n rw [hh, Real.exp_log (by positivity)]\n rw [hvS, hE,\n show -((5/2)*u + 4 * Real.log ((N i : ℝ)))\n = -((5/2)*u) + (-(4 * Real.log ((N i : ℝ)))) by ring,\n Real.exp_add,\n show Real.exp (-(4 * Real.log ((N i : ℝ)))) = (Real.exp (4*Real.log ((N i : ℝ))))⁻¹ from\n Real.exp_neg _, h1]\n have hexpL : ∀ i, Real.exp (-(vL i)) = E * ((N i : ℝ)^7)⁻¹ := by\n intro i\n have hx : (0:ℝ) < (N i : ℝ) := by exact_mod_cast hN1 i\n have h1 : Real.exp (7 * Real.log ((N i : ℝ))) = (N i : ℝ)^7 := by\n have hh : (7:ℝ) * Real.log ((N i:ℝ)) = Real.log ((N i:ℝ)^7) := by\n rw [Real.log_pow]; norm_num\n rw [hh, Real.exp_log (by positivity)]\n rw [hvL, hE,\n show -((5/2)*u + 7 * Real.log ((N i : ℝ)))\n = -((5/2)*u) + (-(7 * Real.log ((N i : ℝ)))) by ring,\n Real.exp_add,\n show Real.exp (-(7 * Real.log ((N i : ℝ)))) = (Real.exp (7*Real.log ((N i : ℝ))))⁻¹ from\n Real.exp_neg _, h1]\n -- the real bounds\n obtain ⟨bS, hbS⟩ : ∃ bS : ℕ → ℝ, ∀ i, bS i =\n if (0 < i ∧ N i = N (i-1)) then 0\n else (N i : ℝ) * min (Real.exp (-(vS i))) (1/2) := ⟨_, fun _ => rfl⟩\n obtain ⟨bL, hbL⟩ : ∃ bL : ℕ → ℝ, ∀ j, bL j =\n if N (j+1) = N j then 0\n else (N j : ℝ) * (N (j+1) : ℝ) * Real.exp (-(vL (j+1))) := ⟨_, fun _ => rfl⟩\n have hbS0 : ∀ i, 0 ≤ bS i := by\n intro i; rw [hbS]\n split\n · exact le_refl 0\n · exact mul_nonneg (by positivity) (le_min (Real.exp_nonneg _) (by norm_num))\n have hbL0 : ∀ j, 0 ≤ bL j := by\n intro j; rw [hbL]\n split\n · exact le_refl 0\n · positivity\n -- measure bounds\n have hmS : ∀ i, radP n (BadS i) ≤ ENNReal.ofReal (bS i) := by\n intro i\n rw [hBadS, hbS]\n by_cases hc : (0 < i ∧ N i = N (i-1))\n · rw [if_pos hc, if_pos hc]; simp\n · rw [if_neg hc, if_neg hc]\n calc radP n (⋃ h ∈ T i, Ev (show Fin n → ℝ from h) (vS i))\n ≤ ∑ h ∈ T i, radP n (Ev (show Fin n → ℝ from h) (vS i)) :=\n measure_biUnion_finset_le _ _\n _ ≤ ∑ _h ∈ T i, ENNReal.ofReal (min (Real.exp (-(vS i))) (1/2)) :=\n Finset.sum_le_sum (fun h _ => hEvProb _ _ (hvS0 i))\n _ = (T i).card • ENNReal.ofReal (min (Real.exp (-(vS i))) (1/2)) := by\n rw [Finset.sum_const]\n _ = ENNReal.ofReal ((N i : ℝ) * min (Real.exp (-(vS i))) (1/2)) := by\n rw [hTcard' i, nsmul_eq_mul,\n ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_natCast]\n have hmL : ∀ j, radP n (BadL j) ≤ ENNReal.ofReal (bL j) := by\n intro j\n rw [hBadL, hbL]\n by_cases hc : N (j+1) = N j\n · rw [if_pos hc, if_pos hc]; simp\n · rw [if_neg hc, if_neg hc]\n have hin : ∀ g : EmpL2 n,\n radP n (⋃ h ∈ T (j+1), Ev ((show Fin n → ℝ from h) - (show Fin n → ℝ from g))\n (vL (j+1)))\n ≤ ENNReal.ofReal ((N (j+1) : ℝ) * Real.exp (-(vL (j+1)))) := by\n intro g\n calc radP n (⋃ h ∈ T (j+1), Ev ((show Fin n → ℝ from h) - (show Fin n → ℝ from g))\n (vL (j+1)))\n ≤ ∑ h ∈ T (j+1), radP n (Ev ((show Fin n → ℝ from h) -\n (show Fin n → ℝ from g)) (vL (j+1))) := measure_biUnion_finset_le _ _\n _ ≤ ∑ _h ∈ T (j+1), ENNReal.ofReal (Real.exp (-(vL (j+1)))) :=\n Finset.sum_le_sum (fun h _ =>\n le_trans (hEvProb _ _ (hvL0 (j+1)))\n (ENNReal.ofReal_le_ofReal (min_le_left _ _)))\n _ = (T (j+1)).card • ENNReal.ofReal (Real.exp (-(vL (j+1)))) := by\n rw [Finset.sum_const]\n _ = ENNReal.ofReal ((N (j+1) : ℝ) * Real.exp (-(vL (j+1)))) := by\n rw [hTcard' (j+1), nsmul_eq_mul,\n ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_natCast]\n calc radP n (⋃ g ∈ T j, ⋃ h ∈ T (j+1),\n Ev ((show Fin n → ℝ from h) - (show Fin n → ℝ from g)) (vL (j+1)))\n ≤ ∑ g ∈ T j, radP n (⋃ h ∈ T (j+1),\n Ev ((show Fin n → ℝ from h) - (show Fin n → ℝ from g)) (vL (j+1))) :=\n measure_biUnion_finset_le _ _\n _ ≤ ∑ _g ∈ T j, ENNReal.ofReal ((N (j+1) : ℝ) * Real.exp (-(vL (j+1)))) :=\n Finset.sum_le_sum (fun g _ => hin g)\n _ = (T j).card • ENNReal.ofReal ((N (j+1) : ℝ) * Real.exp (-(vL (j+1)))) := by\n rw [Finset.sum_const]\n _ = ENNReal.ofReal ((N j : ℝ) * (N (j+1) : ℝ) * Real.exp (-(vL (j+1)))) := by\n rw [hTcard' j, nsmul_eq_mul, ← ENNReal.ofReal_natCast (N j),\n ← ENNReal.ofReal_mul (by positivity), mul_assoc]\n -- partial sums of `bS`\n have hWser1 : Wser 1 = 0 := by\n unfold Wser\n rw [show Finset.Ioc 1 1 = (∅ : Finset ℕ) from by\n ext x; simp only [Finset.mem_Ioc, Finset.notMem_empty, iff_false]; omega]\n simp\n have hWterm : ∀ m : ℕ, 2 ≤ m → (1:ℝ)/(m:ℝ)^3 ≤ Wser m := by\n intro m hm\n have := Wser_diff_ge (a := 1) (b := m) le_rfl (by omega)\n rw [hWser1] at this; linarith\n have hpS' : ∀ M : ℕ, ∑ i ∈ Finset.range (M+1), bS i ≤ min E (1/2) + E * Wser (N M) := by\n intro M\n induction M with\n | zero =>\n rw [Finset.sum_range_one, hbS]\n rw [if_neg (by intro h; exact absurd h.1 (lt_irrefl 0))]\n have hx : (0:ℝ) < (N 0 : ℝ) := by exact_mod_cast hN1 0\n have hW0 : 0 ≤ E * Wser (N 0) := mul_nonneg hEpos.le (Wser_nonneg _)\n have hmin : 0 ≤ min E (1/2) := le_min (le_of_lt hEpos) (by norm_num)\n rcases eq_or_lt_of_le (hN1 0) with h1 | h2\n · have hc1 : ((N 0 : ℕ) : ℝ) = 1 := by rw [← h1]; norm_num\n have hee : Real.exp (-(vS 0)) = E := by rw [hexpS 0, hc1]; norm_num\n rw [hee, hc1, one_mul]\n linarith\n · have hN02 : 2 ≤ N 0 := h2\n have hb : (N 0 : ℝ) * min (Real.exp (-(vS 0))) (1/2) ≤ E * Wser (N 0) := by\n refine le_trans (mul_le_mul_of_nonneg_left (min_le_left _ _) (le_of_lt hx)) ?_\n rw [hexpS 0]\n have h4 : (N 0 : ℝ) * (E * ((N 0 : ℝ)^4)⁻¹) = E * (1/(N 0:ℝ)^3) := by\n field_simp; try ring\n rw [h4]\n exact mul_le_mul_of_nonneg_left (hWterm _ hN02) (le_of_lt hEpos)\n linarith\n | succ M ih =>\n rw [Finset.sum_range_succ]\n by_cases hc : N (M+1) = N M\n · have hb0 : bS (M+1) = 0 := by\n rw [hbS, if_pos ⟨by omega, by simpa using hc⟩]\n rw [hb0, hc]\n linarith [ih]\n · have hlt : N M < N (M+1) := lt_of_le_of_ne (hNmono M (M+1) (by omega)) (Ne.symm hc)\n have hx : (0:ℝ) < (N (M+1) : ℝ) := by exact_mod_cast hN1 (M+1)\n have hb : bS (M+1) ≤ E * (Wser (N (M+1)) - Wser (N M)) := by\n rw [hbS, if_neg (by intro h; exact hc h.2)]\n refine le_trans (mul_le_mul_of_nonneg_left (min_le_left _ _) (le_of_lt hx)) ?_\n rw [hexpS (M+1)]\n have h4 : (N (M+1) : ℝ) * (E * ((N (M+1) : ℝ)^4)⁻¹) = E * (1/(N (M+1):ℝ)^3) := by\n field_simp; try ring\n rw [h4]\n exact mul_le_mul_of_nonneg_left (Wser_diff_ge (hN1 M) hlt) (le_of_lt hEpos)\n have := ih\n nlinarith [hb, ih]\n have hpS : ∀ M : ℕ, ∑ i ∈ Finset.range M, bS i ≤ min E (1/2) + E * (5/24) := by\n intro M\n cases M with\n | zero =>\n simp only [Finset.range_zero, Finset.sum_empty]\n have h1 : 0 ≤ min E (1/2) := le_min (le_of_lt hEpos) (by norm_num)\n nlinarith [hEpos]\n | succ M =>\n refine le_trans (hpS' M) ?_\n have := Wser_le (N M)\n nlinarith [hEpos, Wser_nonneg (N M)]\n -- partial sums of `bL`\n have hpL' : ∀ M : ℕ, ∑ j ∈ Finset.range M, bL j ≤ (E/4) * Wser (N M) := by\n intro M\n induction M with\n | zero =>\n simp only [Finset.range_zero, Finset.sum_empty]\n have := Wser_nonneg (N 0)\n positivity\n | succ M ih =>\n rw [Finset.sum_range_succ]\n by_cases hc : N (M+1) = N M\n · have hb0 : bL M = 0 := by rw [hbL, if_pos hc]\n rw [hb0, hc]\n linarith [ih]\n · have hlt : N M < N (M+1) := lt_of_le_of_ne (hNmono M (M+1) (by omega)) (Ne.symm hc)\n have hx : (0:ℝ) < (N (M+1) : ℝ) := by exact_mod_cast hN1 (M+1)\n have hNM1 : 1 ≤ N M := hN1 M\n have hx2 : (2:ℝ) ≤ (N (M+1) : ℝ) := by\n have h2' : 2 ≤ N (M+1) := by omega\n exact_mod_cast h2'\n have hxj : (0:ℝ) < (N M : ℝ) := by exact_mod_cast hN1 M\n have hxjle : (N M : ℝ) ≤ (N (M+1) : ℝ) := by exact_mod_cast hlt.le\n have hb : bL M ≤ (E/4) * (Wser (N (M+1)) - Wser (N M)) := by\n rw [hbL, if_neg hc, hexpL (M+1)]\n have step1 : (N M : ℝ) * (N (M+1) : ℝ) * (E * ((N (M+1) : ℝ)^7)⁻¹)\n ≤ (E/4) * (1/(N (M+1):ℝ)^3) := by\n rw [← sub_nonneg]\n have key : (E/4) * (1/(N (M+1):ℝ)^3)\n - (N M : ℝ) * (N (M+1) : ℝ) * (E * ((N (M+1) : ℝ)^7)⁻¹)\n = E * ((N (M+1):ℝ)^4 - 4*(N M:ℝ)*(N (M+1):ℝ)) / (4*(N (M+1):ℝ)^7) := by\n field_simp; try ring\n rw [key]\n have hA : (4:ℝ)*(N (M+1):ℝ)^2 ≤ (N (M+1):ℝ)^4 := by\n have h1 : (4:ℝ) ≤ (N (M+1):ℝ)^2 := by nlinarith [hx2]\n calc (4:ℝ)*(N (M+1):ℝ)^2 ≤ (N (M+1):ℝ)^2 * (N (M+1):ℝ)^2 :=\n mul_le_mul_of_nonneg_right h1 (sq_nonneg _)\n _ = (N (M+1):ℝ)^4 := by ring\n have hB : (4:ℝ)*(N M:ℝ)*(N (M+1):ℝ) ≤ 4*(N (M+1):ℝ)^2 := by\n nlinarith [hxjle, hx]\n have hnum : 0 ≤ (N (M+1):ℝ)^4 - 4*(N M:ℝ)*(N (M+1):ℝ) := by linarith\n exact div_nonneg (mul_nonneg hEpos.le hnum) (by positivity)\n refine le_trans step1 ?_\n exact mul_le_mul_of_nonneg_left (Wser_diff_ge (hN1 M) hlt) (by positivity)\n linarith [ih, hb]\n have hpL : ∀ M : ℕ, ∑ j ∈ Finset.range M, bL j ≤ E * (5/96) := by\n intro M\n refine le_trans (hpL' M) ?_\n have := Wser_le (N M)\n nlinarith [hEpos, Wser_nonneg (N M)]\n -- the measure of the complement of `Wset` is zero\n have hWc : radP n Wsetᶜ = 0 := by\n have hms : MeasurableSet {x : ℝ | ¬ (|x| ≤ 1)} := by\n have : {x : ℝ | ¬ (|x| ≤ 1)} = {x : ℝ | 1 < |x|} := by\n ext x; simp only [Set.mem_setOf_eq, not_le]\n rw [this]\n exact measurableSet_lt measurable_const continuous_abs.measurable\n have hrad0 : rad {x : ℝ | ¬ (|x| ≤ 1)} = 0 :=\n rad_ae (fun x => |x| ≤ 1) (by norm_num) (by norm_num)\n have hsub : Wsetᶜ ⊆ ⋃ i : Fin n, (Function.eval i) ⁻¹' {x : ℝ | ¬ (|x| ≤ 1)} := by\n intro ω hω\n rw [hWset] at hω\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_forall] at hω\n obtain ⟨i, hi⟩ := hω\n exact Set.mem_iUnion.mpr ⟨i, hi⟩\n refine measure_mono_null hsub (measure_iUnion_null fun i => ?_)\n have hmp : MeasurePreserving (Function.eval i) (radP n) rad := by\n unfold radP; exact measurePreserving_eval _ i\n rw [← Measure.map_apply (measurable_pi_apply i) hms, hmp.map_eq, hrad0]\n -- putting the pieces together\n have hsumS : ∑' i, radP n (BadS i) ≤ ENNReal.ofReal (min E (1/2) + E*(5/24)) := by\n refine tsum_le_of_partial_sums (fun M => ?_)\n calc ∑ i ∈ Finset.range M, radP n (BadS i)\n ≤ ∑ i ∈ Finset.range M, ENNReal.ofReal (bS i) :=\n Finset.sum_le_sum (fun i _ => hmS i)\n _ = ENNReal.ofReal (∑ i ∈ Finset.range M, bS i) :=\n (ENNReal.ofReal_sum_of_nonneg (fun i _ => hbS0 i)).symm\n _ ≤ ENNReal.ofReal (min E (1/2) + E*(5/24)) := ENNReal.ofReal_le_ofReal (hpS M)\n have hsumL : ∑' j, radP n (BadL j) ≤ ENNReal.ofReal (E*(5/96)) := by\n refine tsum_le_of_partial_sums (fun M => ?_)\n calc ∑ j ∈ Finset.range M, radP n (BadL j)\n ≤ ∑ j ∈ Finset.range M, ENNReal.ofReal (bL j) :=\n Finset.sum_le_sum (fun j _ => hmL j)\n _ = ENNReal.ofReal (∑ j ∈ Finset.range M, bL j) :=\n (ENNReal.ofReal_sum_of_nonneg (fun j _ => hbL0 j)).symm\n _ ≤ ENNReal.ofReal (E*(5/96)) := ENNReal.ofReal_le_ofReal (hpL M)\n have hmeasBad : radP n Bad ≤ ENNReal.ofReal (min E (1/2) + E*(5/24) + E*(5/96)) := by\n rw [hBad]\n have e1 : radP n ((⋃ i, BadS i) ∪ (⋃ j, BadL j) ∪ Wsetᶜ)\n ≤ radP n ((⋃ i, BadS i) ∪ (⋃ j, BadL j)) + radP n Wsetᶜ := measure_union_le _ _\n have e2 : radP n ((⋃ i, BadS i) ∪ (⋃ j, BadL j))\n ≤ radP n (⋃ i, BadS i) + radP n (⋃ j, BadL j) := measure_union_le _ _\n have e3 : radP n (⋃ i, BadS i) ≤ ENNReal.ofReal (min E (1/2) + E*(5/24)) :=\n le_trans (measure_iUnion_le _) hsumS\n have e4 : radP n (⋃ j, BadL j) ≤ ENNReal.ofReal (E*(5/96)) :=\n le_trans (measure_iUnion_le _) hsumL\n rw [hWc, add_zero] at e1\n refine le_trans e1 (le_trans e2 ?_)\n rw [ENNReal.ofReal_add (by\n have hmm : 0 ≤ min E (1/2) := le_min (le_of_lt hEpos) (by norm_num)\n nlinarith [hEpos]) (by positivity)]\n exact add_le_add e3 e4\n -- final numeric estimate\n have hXnn : 0 ≤ min E (1/2) + E*(5/24) + E*(5/96) := by\n have : 0 ≤ min E (1/2) := le_min (le_of_lt hEpos) (by norm_num)\n nlinarith [hEpos]\n have hfinal : min E (1/2) + E*(5/24) + E*(5/96) ≤ Real.exp (-u) := by\n rcases le_or_gt (1/5 : ℝ) u with hcase | hcase\n · have h1 : min E (1/2) ≤ E := min_le_left _ _\n have h2 : Real.exp (-u) = E * Real.exp ((3/2)*u) := by\n rw [hE, ← Real.exp_add]; ring_nf\n have h3 : (121/96 : ℝ) ≤ Real.exp ((3/2)*u) := by\n have := Real.add_one_le_exp ((3/2)*u)\n nlinarith\n rw [h2]\n nlinarith [hEpos]\n · have h1 : min E (1/2) ≤ 1/2 := min_le_right _ _\n have h2 : (1:ℝ) - u ≤ Real.exp (-u) := by\n have := Real.add_one_le_exp (-u); linarith\n nlinarith [hEle1, hEpos]\n calc (radP n).real Bad = (radP n Bad).toReal := rfl\n _ ≤ (ENNReal.ofReal (min E (1/2) + E*(5/24) + E*(5/96))).toReal := by\n refine ENNReal.toReal_mono (by finiteness) hmeasBad\n _ = min E (1/2) + E*(5/24) + E*(5/96) := ENNReal.toReal_ofReal hXnn\n _ ≤ Real.exp (-u) := hfinal\n -- conclusion\n have hcover : (Set.univ : Set (Fin n → ℝ)) ⊆ Gset ∪ Bad := by\n intro ω _\n by_cases h : ω ∈ Bad\n · exact Or.inr h\n · exact Or.inl (claimA h)\n have h1 : (1:ℝ) ≤ (radP n).real Gset + (radP n).real Bad := by\n have h2 : (radP n).real Set.univ ≤ (radP n).real (Gset ∪ Bad) :=\n measureReal_mono hcover (measure_ne_top _ _)\n have h3 := measureReal_union_le (μ := radP n) Gset Bad\n rw [measureReal_univ_eq_one] at h2\n linarith\n have : ((radP n) Gset).toReal = (radP n).real Gset := rfl\n rw [this]\n linarith\n\nend GraduateLevel\n"} +{"id": "ch15_lemma_15_1", "source": "Graduate-level", "targets": [{"label": "ch15_lemma_15_1", "decls": ["ch15_lemma_15_1"], "statement": "Let \\(\\xi,\\nu\\) - random variables.Assume that\n\\[\\mathbb{P}\\left(\\nu\\geq t\\right)\\leq\\Gamma e^{-\\gamma t}\\]\nwhere \\(\\Gamma\\geq 1,t\\geq 0\\) ,and \\(\\gamma > 0\\) . Furthermore, for all \\(a > 0\\) assume that\n\\[\\mathbb{E}\\phi(\\xi)\\le\\mathbb{E}\\phi(\\nu)\\]\nwhere \\(\\phi(x)=(x-a)_{+}\\) .Then\n\\[\\mathbb{P}\\left(\\xi\\geq t\\right)\\leq\\Gamma\\cdot e\\cdot e^{-\\gamma t}.\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "Since \\(\\phi(x)=(x-a)_{+}\\) ,we have \\(\\phi(\\xi)\\geq\\phi(t)\\) whenever \\(\\xi \\geq t .\\)\n\\[\\begin{array}{ r l }&{\\mathbb{P}\\left(\\xi\\geq t\\right)\\leq\\mathbb{P}\\left(\\phi(\\xi)\\geq\\phi(t)\\right)}\\\\ &{\\qquad\\leq\\displaystyle\\frac{\\mathbb{E}\\phi(\\xi)}{\\phi(t)}\\leq\\frac{\\mathbb{E}\\phi(\\nu)}{\\phi(t)}=\\frac{\\mathbb{E}\\left(\\nu-a\\right)_{+}}{(t-a)_{+}}}\\end{array}\\]\nFurthermore,\n\\[\\begin{array}{ r l }{\\displaystyle\\mathbb{E}(\\nu-a)_{+}=}&{\\mathbb{E}\\int_{0}^{(\\nu-a)_{+}}\\mathrm{1}d x}\\\\ &{=\\mathbb{E}\\int_{0}^{\\infty}I(x\\leq(\\nu-a)_{+})d x}\\\\ &{=\\int_{0}^{\\infty}\\mathbb{E}I(x\\leq(\\nu-a)_{+})d x}\\\\ &{=\\int_{0}^{\\infty}\\mathbb{P}\\left((\\nu-a)_{+}\\geq x\\right)d x}\\\\ &{=\\int_{0}^{\\infty}\\mathbb{P}\\left(\\nu\\geq a+x\\right)d x}\\\\ &{\\leq\\int_{0}^{\\infty}\\Gamma e^{-\\gamma a-\\gamma x}d x=\\frac{\\Gamma e^{-\\gamma a}}{\\gamma}.}\\end{array}\\]\nHence,\n\\[\\mathbb{P}\\left(\\xi\\geq t\\right)\\leq\\frac{\\Gamma e^{-\\gamma a}}{\\gamma(t-a)_{+}}=\\frac{\\Gamma\\cdot e\\cdot e^{-\\gamma t}}{1}=\\Gamma\\cdot e\\cdot e^{-\\gamma t}\\]\nwhere we chose optimal \\(\\begin{array}{ r }{a=t-\\frac{1}{\\gamma}}\\end{array}\\) to minimize \\(\\frac{\\Gamma e^{-\\gamma a}}{\\gamma}\\)", "context": [], "lean": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch15_lemma_15_1\n {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n {ξ ν : Ω → ℝ} (hξm : Measurable ξ) (hνm : Measurable ν)\n {Γ γ : ℝ} (hΓ : 1 ≤ Γ) (hγ : 0 < γ)\n (hint : ∀ a : ℝ, 0 < a →\n Integrable (fun ω => max (ξ ω - a) 0) μ ∧ Integrable (fun ω => max (ν ω - a) 0) μ)\n (htail : ∀ t : ℝ, 0 ≤ t → (μ {ω | t ≤ ν ω}).toReal ≤ Γ * Real.exp (-γ * t))\n (hcmp : ∀ a : ℝ, 0 < a →\n ∫ ω, max (ξ ω - a) 0 ∂μ ≤ ∫ ω, max (ν ω - a) 0 ∂μ)\n {t : ℝ} (ht : 0 �� t) :\n (μ {ω | t ≤ ξ ω}).toReal ≤ Γ * Real.exp 1 * Real.exp (-γ * t) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\nprivate lemma exp_neg_mul_integral_Ioi {γ : ℝ} (h : 0 < γ) :\n ∫ x in Set.Ioi (0:ℝ), Real.exp (-γ * x) = 1 / γ := by\n have := integral_comp_mul_left_Ioi (fun x => Real.exp (-x)) 0 h\n simp only [mul_zero, smul_eq_mul] at this\n have e2 : (fun x : ℝ => Real.exp (-γ * x)) = (fun x : ℝ => Real.exp (-(γ * x))) := by\n ext x; ring_nf\n rw [e2, this, integral_exp_neg_Ioi_zero]\n ring\n\nprivate lemma tail_int_bound {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω}\n [IsFiniteMeasure μ] {ν : Ω → ℝ} {Γ γ a : ℝ} (hγ : 0 < γ) (ha : 0 ≤ a)\n (hI : Integrable (fun ω => max (ν ω - a) 0) μ)\n (htail : ∀ t : ℝ, 0 ≤ t → (μ {ω | t ≤ ν ω}).toReal ≤ Γ * Real.exp (-γ * t)) :\n ∫ ω, max (ν ω - a) 0 ∂μ ≤ Γ * Real.exp (-γ * a) / γ := by\n have hnn : 0 ≤ᵐ[μ] (fun ω => max (ν ω - a) 0) :=\n Filter.Eventually.of_forall (fun ω => le_max_right _ _)\n rw [hI.integral_eq_integral_meas_lt hnn]\n have key : ∀ x ∈ Set.Ioi (0:ℝ),\n μ.real {ω | x < max (ν ω - a) 0} ≤ Γ * Real.exp (-γ * a) * Real.exp (-γ * x) := by\n intro x hx\n simp only [Set.mem_Ioi] at hx\n have hsub : {ω | x < max (ν ω - a) 0} ⊆ {ω | a + x ≤ ν ω} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n rcases max_cases (ν ω - a) 0 with ⟨h1, _⟩ | ⟨h1, _⟩\n · rw [h1] at hω; linarith\n · rw [h1] at hω; linarith\n have h1 : μ.real {ω | x < max (ν ω - a) 0} ≤ μ.real {ω | a + x ≤ ν ω} :=\n measureReal_mono hsub (measure_ne_top _ _)\n have h2 := htail (a + x) (by linarith)\n have h3 : Γ * Real.exp (-γ * (a + x)) = Γ * Real.exp (-γ * a) * Real.exp (-γ * x) := by\n rw [show -γ * (a + x) = -γ * a + -γ * x by ring, Real.exp_add]; ring\n have : μ.real {ω | a + x ≤ ν ω} ≤ Γ * Real.exp (-γ * a) * Real.exp (-γ * x) := by\n rw [← h3]; exact h2\n linarith\n have hint2 : IntegrableOn (fun x : ℝ => Γ * Real.exp (-γ * a) * Real.exp (-γ * x))\n (Set.Ioi 0) volume := (exp_neg_integrableOn_Ioi 0 hγ).const_mul _\n calc ∫ x in Set.Ioi (0:ℝ), μ.real {ω | x < max (ν ω - a) 0}\n ≤ ∫ x in Set.Ioi (0:ℝ), Γ * Real.exp (-γ * a) * Real.exp (-γ * x) := by\n refine integral_mono_of_nonneg ?_ hint2 ?_\n · filter_upwards with x using measureReal_nonneg\n · filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx using key x hx\n _ = Γ * Real.exp (-γ * a) / γ := by\n rw [integral_const_mul, exp_neg_mul_integral_Ioi hγ]\n field_simp\n\ntheorem ch15_lemma_15_1\n {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n {ξ ν : Ω → ℝ} (hξm : Measurable ξ) (hνm : Measurable ν)\n {Γ γ : ℝ} (hΓ : 1 ≤ Γ) (hγ : 0 < γ)\n (hint : ∀ a : ℝ, 0 < a →\n Integrable (fun ω => max (ξ ω - a) 0) μ ∧ Integrable (fun ω => max (ν ω - a) 0) μ)\n (htail : ∀ t : ℝ, 0 ≤ t → (μ {ω | t ≤ ν ω}).toReal ≤ Γ * Real.exp (-γ * t))\n (hcmp : ∀ a : ℝ, 0 < a →\n ∫ ω, max (ξ ω - a) 0 ∂μ ≤ ∫ ω, max (ν ω - a) 0 ∂μ)\n {t : ℝ} (ht : 0 ≤ t) :\n (μ {ω | t ≤ ξ ω}).toReal ≤ Γ * Real.exp 1 * Real.exp (-γ * t) := by\n have hprob : (μ {ω | t ≤ ξ ω}).toReal ≤ 1 := by\n have h := prob_le_one (μ := μ) (s := {ω | t ≤ ξ ω})\n calc (μ {ω | t ≤ ξ ω}).toReal ≤ (1 : ENNReal).toReal := ENNReal.toReal_mono (by simp) h\n _ = 1 := by simp\n by_cases hcase : t ≤ 1 / γ\n · have hγt : γ * t ≤ 1 := by\n rw [mul_comm]; exact (le_div_iff₀ hγ).mp hcase\n have hee : Real.exp 1 * Real.exp (-γ * t) = Real.exp (1 + -γ * t) := (Real.exp_add _ _).symm\n have h1 : (1:ℝ) ≤ Real.exp 1 * Real.exp (-γ * t) := by\n rw [hee]; exact Real.one_le_exp (by linarith)\n nlinarith [h1, hprob]\n · push_neg at hcase\n obtain ⟨a, ha_def⟩ : ∃ a : ℝ, a = t - 1 / γ := ⟨_, rfl⟩\n have hapos : 0 < a := by rw [ha_def]; linarith\n have hta : t - a = 1 / γ := by rw [ha_def]; ring\n obtain ⟨hIξ, hIν⟩ := hint a hapos\n have hnn : 0 ≤ᵐ[μ] (fun ω => max (ξ ω - a) 0) :=\n Filter.Eventually.of_forall (fun ω => le_max_right _ _)\n have hmarkov := mul_meas_ge_le_integral_of_nonneg hnn hIξ (t - a)\n have hsub : {ω | t ≤ ξ ω} ⊆ {x | t - a ≤ max (ξ x - a) 0} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n exact le_max_of_le_left (by linarith)\n have hmono : μ.real {ω | t ≤ ξ ω} ≤ μ.real {x | t - a ≤ max (ξ x - a) 0} :=\n measureReal_mono hsub (measure_ne_top _ _)\n have hstep1 : (t - a) * μ.real {ω | t ≤ ξ ω} ≤ ∫ ω, max (ξ ω - a) 0 ∂μ := by\n have hpos : 0 < t - a := by rw [hta]; positivity\n have := mul_le_mul_of_nonneg_left hmono hpos.le\n linarith [hmarkov]\n have hstep2 := hcmp a hapos\n have hstep3 := tail_int_bound (μ := μ) (ν := ν) (Γ := Γ) (γ := γ) (a := a)\n hγ hapos.le hIν htail\n have hchain : (1 / γ) * μ.real {ω | t ≤ ξ ω} ≤ Γ * Real.exp (-γ * a) / γ := by\n rw [← hta]; linarith\n have hexp : Real.exp (-γ * a) = Real.exp 1 * Real.exp (-γ * t) := by\n have hga : γ * a = γ * t - 1 := by rw [ha_def]; field_simp\n have h9 : -γ * a = 1 + -γ * t := by linear_combination -hga\n rw [h9, Real.exp_add]\n rw [hexp] at hchain\n have heq : Γ * (Real.exp 1 * Real.exp (-γ * t)) / γ\n = (1 / γ) * (Γ * (Real.exp 1 * Real.exp (-γ * t))) := by ring\n rw [heq] at hchain\n have hfin : μ.real {ω | t ≤ ξ ω} ≤ Γ * (Real.exp 1 * Real.exp (-γ * t)) :=\n le_of_mul_le_mul_left hchain (by positivity)\n calc (μ {ω | t ≤ ξ ω}).toReal ≤ Γ * (Real.exp 1 * Real.exp (-γ * t)) := hfin\n _ = Γ * Real.exp 1 * Real.exp (-γ * t) := by ring\n\nend GraduateLevel\n"} +{"id": "ch26_lemma_26_1", "source": "Graduate-level", "targets": [{"label": "ch26_lemma_26_1", "decls": ["ch26_lemma_26_1"], "statement": "\\[\\mathbb{E}\\operatorname*{sup}_{t\\in T}\\left|\\sum_{i=1}^{n}\\varepsilon_{i}\\varphi_{i}(t_{i})\\right|\\leq 2\\mathbb{E}\\operatorname*{sup}_{t\\in T}\\left|\\sum_{i=1}^{n}\\varepsilon_{i}t_{i}\\right|\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Note that\n\\[|x| =(x)^{+}+(x)^{-}=(x)^{+}+(-x)^{+}.\\]\nWe apply the Contraction Inequality for Rademacher processes with \\(G(s)=(s)^{+}\\)\n\\[\\begin{array}{ r l }&{\\mathbb{E}\\displaystyle\\operatorname*{sup}_{t\\in T}\\left|\\displaystyle\\sum_{i=1}^{n}\\varepsilon_{i}\\varphi_{i}(t_{i})\\right| =\\mathbb{E}\\displaystyle\\operatorname*{sup}_{t\\in T}\\left(\\left(\\displaystyle\\sum_{i=1}^{n}\\varepsilon_{i}\\varphi_{i}(t_{i})\\right)^{+}+\\left(\\displaystyle\\sum_{i=1}^{n}(-\\varepsilon_{i})\\varphi_{i}(t_{i})\\right)^{+}\\right)}\\\\ &{\\qquad\\leq 2\\mathbb{E}\\displaystyle\\operatorname*{sup}_{t\\in T}\\left(\\displaystyle\\sum_{i=1}^{n}\\varepsilon_{i}\\varphi_{i}(t_{i})\\right)^{+}}\\\\ &{\\qquad\\leq 2\\mathbb{E}\\displaystyle\\operatorname*{sup}_{t\\in T}\\left(\\displaystyle\\sum_{i=1}^{n}\\varepsilon_{i}t_{i}\\right)^{+}\\leq 2\\mathbb{E}\\displaystyle\\operatorname*{sup}_{t\\in T}\\left|\\displaystyle\\sum_{i=1}^{n}\\varepsilon_{i}t_{i}\\right|.}\\end{array}\\]", "context": [{"id": "ch26:theorem:26_1", "name": "theorem 26.1", "statement": "\\(I f - 1 \\leq f \\leq 1\\) ,then\n\\[\\mathbb{P}\\left(Z(x)\\leq 2\\mathbb{E}R(x)+2{\\sqrt{\\frac{2 t}{n}}}\\right)\\geq 1-e^{-t}.\\]\n\\(I f 0 \\leq f \\leq 1\\) ,then\n\\[\\mathbb{P}\\left(Z(x)\\le 2\\mathbb{E}R(x)+\\sqrt{\\frac{2 t}{n}}\\right)\\ge 1-e^{-t}.\\]\nConsider \\(\\begin{array}{ r }{\\mathbb E_{\\varepsilon}R(x)=\\mathbb E_{\\varepsilon}\\operatorname*{sup}_{f\\in\\mathcal{F}}\\frac{1}{n}\\sum_{i=1}^{n}\\varepsilon_{i}f(x_{i})}\\end{array}\\) . Since \\(x_{i}\\) are fixed, \\(f(x_{i})\\) are just vectors. Let \\(F\\subseteq\\mathbb{R}^{n},f\\in F\\) where \\(f=(f_{1},\\ldots,f_{n})\\)\nDefine contraction \\(\\varphi_{i}:\\mathbb{R}\\mapsto\\mathbb{R}\\) for \\(i=1,\\ldots,n\\) such that \\(\\varphi_{i}(0)=0\\) and \\(|\\varphi_{i}(s)-\\varphi_{i}(t)|\\leq|s-t|\\)\nLet \\(G:\\mathbb{R}\\mapsto\\mathbb{R}\\) be convex and non-decreasing.\nThe following theorem is called Comparison inequality for Rademacher process.\nTheorem 26.2.\n\\[\\mathbb{E}_{\\varepsilon}G\\left(\\operatorname*{sup}_{f\\in F}\\sum\\varepsilon_{i}\\varphi_{i}(f_{i})\\right)\\leq\\mathbb{E}_{\\varepsilon}G\\left(\\operatorname*{sup}_{f\\in F}\\sum\\varepsilon_{i}f_{i}\\right).\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ ({-1, 1} : Finset ℤ) }))\n\ntheorem ch26_lemma_26_1\n {n : ℕ} {T : Type*} [Nonempty T]\n (t : T → (Fin n → ℝ))\n (φ : Fin n → ℝ → ℝ)\n (hφ0 : ∀ i, φ i 0 = 0)\n (hφL : ∀ i s s', |φ i s' - φ i s| ≤ |s' - s|)\n (hbddφ : ∀ σ : RadSigns n,\n BddAbove (Set.range (fun τ : T => |∑ i : Fin n, (σ i : ℝ) * φ i (t τ i)|)))\n (hbdd : ∀ σ : RadSigns n,\n BddAbove (Set.range (fun τ : T => |∑ i : Fin n, (σ i : ℝ) * t τ i|))) :\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ τ : T, |∑ i : Fin n, (σ i : ℝ) * φ i (t τ i)|\n ≤ 2 * ((Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ τ : T, |∑ i : Fin n, (σ i : ℝ) * t τ i|) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ ({-1, 1} : Finset ℤ) }))\n\ninstance {n} : Nonempty (RadSigns n) := ⟨fun _ => ⟨1, by simp⟩⟩\n\nprivate lemma rad_abs {n : ℕ} (σ : RadSigns n) (i : Fin n) : |((σ i : ℤ) : ℝ)| = 1 := by\n have h := (σ i).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h <;> rw [h] <;> norm_num\n\nnoncomputable def Xs {n : ℕ} {T : Type*} (t : T → Fin n → ℝ) (Ψ : Fin n → ℝ → ℝ)\n (σ : RadSigns n) (τ : T) : ℝ := ∑ i, ((σ i : ℤ) : ℝ) * Ψ i (t τ i)\n\nnoncomputable def Sg {n : ℕ} {T : Type*} (t : T → Fin n → ℝ) (Ψ : Fin n → ℝ → ℝ) : ℝ :=\n ∑ σ : RadSigns n, max (⨆ τ : T, Xs t Ψ σ τ) 0\n\nprivate def negOne (x : ({-1, 1} : Finset ℤ)) : ({-1, 1} : Finset ℤ) :=\n ⟨-(x : ℤ), by\n have h := x.2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h ⊢\n rcases h with h | h <;> simp [h]⟩\n\nprivate lemma negOne_val (x : ({-1, 1} : Finset ℤ)) : ((negOne x : ℤ) : ℝ) = -((x : ℤ) : ℝ) := by\n simp [negOne]\n\nprivate lemma negOne_negOne (x : ({-1, 1} : Finset ℤ)) : negOne (negOne x) = x := by\n apply Subtype.ext\n simp [negOne]\n\nprivate def flipAt {n : ℕ} (k : Fin n) (σ : RadSigns n) : RadSigns n :=\n fun i => if i = k then negOne (σ i) else σ i\n\nprivate def negAll {n : ℕ} (σ : RadSigns n) : RadSigns n := fun i => negOne (σ i)\n\nprivate lemma flipAt_inv {n : ℕ} (k : Fin n) : Function.Involutive (flipAt (n := n) k) := by\n intro σ\n funext i\n by_cases h : i = k <;> simp [flipAt, h, negOne_negOne]\n\nprivate lemma negAll_inv {n : ℕ} : Function.Involutive (negAll (n := n)) := by\n intro σ\n funext i\n simp [negAll, negOne_negOne]\n\nprivate lemma sum_flip {n : ℕ} (k : Fin n) (F : RadSigns n → ℝ) :\n ∑ σ : RadSigns n, F (flipAt k σ) = ∑ σ : RadSigns n, F σ :=\n Fintype.sum_equiv (flipAt_inv k).toPerm _ _ (fun _ => rfl)\n\nprivate lemma sum_negAll {n : ℕ} (F : RadSigns n → ℝ) :\n ∑ σ : RadSigns n, F (negAll σ) = ∑ σ : RadSigns n, F σ :=\n Fintype.sum_equiv (negAll_inv).toPerm _ _ (fun _ => rfl)\n\nprivate lemma Xs_negAll {n : ℕ} {T : Type*} (t : T → Fin n → ℝ) (Ψ : Fin n → ℝ → ℝ)\n (σ : RadSigns n) (τ : T) : Xs t Ψ (negAll σ) τ = -(Xs t Ψ σ τ) := by\n simp only [Xs, negAll, negOne_val, ← Finset.sum_neg_distrib]\n refine Finset.sum_congr rfl ?_\n intro i _\n ring\n\nprivate lemma Xs_bound {n : ℕ} {T : Type*} (t : T → Fin n → ℝ) (M : ℝ)\n (hM : ∀ τ, ∑ i, |t τ i| ≤ M) (Ψ : Fin n → ℝ → ℝ) (hΨ : ∀ i s, |Ψ i s| ≤ |s|)\n (σ : RadSigns n) (τ : T) : |Xs t Ψ σ τ| ≤ M := by\n calc |Xs t Ψ σ τ| ≤ ∑ i, |((σ i : ℤ) : ℝ) * Ψ i (t τ i)| :=\n Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ i, |t τ i| := by\n refine Finset.sum_le_sum ?_\n intro i _\n rw [abs_mul, rad_abs, one_mul]\n exact hΨ i (t τ i)\n _ ≤ M := hM τ\n\nprivate lemma bddAbove_of_bound {T : Type*} (a : T → ℝ) (M : ℝ) (h : ∀ τ, a τ ≤ M) :\n BddAbove (Set.range a) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨τ, rfl⟩\n exact h τ\n\nprivate lemma key_two {T : Type*} [Nonempty T] (f g u : T → ℝ)\n (h1 : ∀ a b : T, u a - u b ≤ |g a - g b|)\n (h2 : ∀ a : T, |u a| ≤ |g a|)\n (hbu : BddAbove (Set.range fun τ => f τ + u τ))\n (hbu' : BddAbove (Set.range fun τ => f τ - u τ))\n (hbg : BddAbove (Set.range fun τ => f τ + g τ))\n (hbg' : BddAbove (Set.range fun τ => f τ - g τ)) :\n max (⨆ τ, (f τ + u τ)) 0 + max (⨆ τ, (f τ - u τ)) 0\n ≤ max (⨆ τ, (f τ + g τ)) 0 + max (⨆ τ, (f τ - g τ)) 0 := by\n set P := ⨆ τ, (f τ + u τ) with hP\n set Q := ⨆ τ, (f τ - u τ) with hQ\n set A := ⨆ τ, (f τ + g τ) with hA\n set B := ⨆ τ, (f τ - g τ) with hB\n have hAle : A ≤ max A 0 := le_max_left _ _\n have hBle : B ≤ max B 0 := le_max_left _ _\n have hA0 : (0:ℝ) ≤ max A 0 := le_max_right _ _\n have hB0 : (0:ℝ) ≤ max B 0 := le_max_right _ _\n have F1 : P + Q ≤ A + B := by\n have hp : P ≤ A + B - Q := by\n rw [hP]\n refine ciSup_le ?_\n intro a\n have hq : Q ≤ A + B - (f a + u a) := by\n rw [hQ]\n refine ciSup_le ?_\n intro b\n rcases le_total (g b) (g a) with h | h\n · have hab := h1 a b\n rw [abs_of_nonneg (by linarith)] at hab\n have hA' : f a + g a ≤ A := le_ciSup hbg a\n have hB' : f b - g b ≤ B := le_ciSup hbg' b\n linarith\n · have hab := h1 a b\n rw [abs_of_nonpos (by linarith)] at hab\n have hA' : f b + g b ≤ A := le_ciSup hbg b\n have hB' : f a - g a ≤ B := le_ciSup hbg' a\n linarith\n linarith\n linarith\n have F2 : P ≤ max A 0 + max B 0 := by\n rw [hP]\n refine ciSup_le ?_\n intro a\n have hu : u a ≤ |g a| := le_trans (le_abs_self _) (h2 a)\n rcases le_total 0 (g a) with h | h\n · rw [abs_of_nonneg h] at hu\n have hA' : f a + g a ≤ A := le_ciSup hbg a\n linarith\n · rw [abs_of_nonpos h] at hu\n have hB' : f a - g a ≤ B := le_ciSup hbg' a\n linarith\n have F3 : Q ≤ max A 0 + max B 0 := by\n rw [hQ]\n refine ciSup_le ?_\n intro a\n have hu : -u a ≤ |g a| := le_trans (neg_le_abs _) (h2 a)\n rcases le_total 0 (g a) with h | h\n · rw [abs_of_nonneg h] at hu\n have hA' : f a + g a ≤ A := le_ciSup hbg a\n linarith\n · rw [abs_of_nonpos h] at hu\n have hB' : f a - g a ≤ B := le_ciSup hbg' a\n linarith\n rcases le_or_lt P 0 with hp0 | hp0 <;> rcases le_or_lt Q 0 with hq0 | hq0\n · rw [max_eq_right hp0, max_eq_right hq0]; linarith\n · rw [max_eq_right hp0, max_eq_left hq0.le]; linarith\n · rw [max_eq_left hp0.le, max_eq_right hq0]; linarith\n · rw [max_eq_left hp0.le, max_eq_left hq0.le]; linarith\n\nprivate lemma step {n : ℕ} {T : Type*} [Nonempty T] (t : T → Fin n → ℝ) (M : ℝ)\n (hM : ∀ τ, ∑ i, |t τ i| ≤ M)\n (Ψ : Fin n → ℝ → ℝ) (hΨb : ∀ i s, |Ψ i s| ≤ |s|)\n (hΨL : ∀ i s s', |Ψ i s' - Ψ i s| ≤ |s' - s|)\n (k : Fin n) :\n Sg t Ψ ≤ Sg t (Function.update Ψ k (fun s => s)) := by\n classical\n set Ψ' := Function.update Ψ k (fun s : ℝ => s) with hΨ'\n have hΨ'b : ∀ i s, |Ψ' i s| ≤ |s| := by\n intro i s\n by_cases h : i = k\n · subst h; simp [hΨ']\n · rw [hΨ', Function.update_of_ne h]; exact hΨb i s\n have key : ∀ σ : RadSigns n,\n max (⨆ τ : T, Xs t Ψ σ τ) 0 + max (⨆ τ : T, Xs t Ψ (flipAt k σ) τ) 0\n ≤ max (⨆ τ : T, Xs t Ψ' σ τ) 0 + max (⨆ τ : T, Xs t Ψ' (flipAt k σ) τ) 0 := by\n intro σ\n set f : T → ℝ := fun τ => ∑ i ∈ Finset.univ.erase k, ((σ i : ℤ) : ℝ) * Ψ i (t τ i) with hfdef\n set u : T → ℝ := fun τ => ((σ k : ℤ) : ℝ) * Ψ k (t τ k) with hudef\n set g : T → ℝ := fun τ => ((σ k : ℤ) : ℝ) * (t τ k) with hgdef\n have hsplit : ∀ (Θ : Fin n → ℝ → ℝ) (ρ : RadSigns n) (τ : T),\n Xs t Θ ρ τ\n = (∑ i ∈ Finset.univ.erase k, ((ρ i : ℤ) : ℝ) * Θ i (t τ i))\n + ((ρ k : ℤ) : ℝ) * Θ k (t τ k) := by\n intro Θ ρ τ\n rw [Xs, ← Finset.sum_erase_add _ _ (Finset.mem_univ k)]\n have hflip_erase : ∀ (Θ : Fin n → ℝ → ℝ) (τ : T),\n (∑ i ∈ Finset.univ.erase k, ((flipAt k σ i : ℤ) : ℝ) * Θ i (t τ i))\n = ∑ i ∈ Finset.univ.erase k, ((σ i : ℤ) : ℝ) * Θ i (t τ i) := by\n intro Θ τ\n refine Finset.sum_congr rfl ?_\n intro i hi\n have hik : i ≠ k := (Finset.mem_erase.mp hi).1\n simp [flipAt, hik]\n have hflip_k : ((flipAt k σ k : ℤ) : ℝ) = -((σ k : ℤ) : ℝ) := by\n simp [flipAt, negOne_val]\n have hΨ'_erase : ∀ (ρ : RadSigns n) (τ : T),\n (∑ i ∈ Finset.univ.erase k, ((ρ i : ℤ) : ℝ) * Ψ' i (t τ i))\n = ∑ i ∈ Finset.univ.erase k, ((ρ i : ℤ) : ℝ) * Ψ i (t τ i) := by\n intro ρ τ\n refine Finset.sum_congr rfl ?_\n intro i hi\n have hik : i ≠ k := (Finset.mem_erase.mp hi).1\n rw [hΨ', Function.update_of_ne hik]\n have E1 : ∀ τ, Xs t Ψ σ τ = f τ + u τ := by\n intro τ; rw [hsplit]\n have E2 : ∀ τ, Xs t Ψ (flipAt k σ) τ = f τ - u τ := by\n intro τ\n rw [hsplit, hflip_erase, hflip_k]\n rw [hfdef, hudef]\n ring\n have E3 : ∀ τ, Xs t Ψ' σ τ = f τ + g τ := by\n intro τ\n rw [hsplit, hΨ'_erase]\n have : Ψ' k (t τ k) = t τ k := by simp [hΨ']\n rw [this]\n have E4 : ∀ τ, Xs t Ψ' (flipAt k σ) τ = f τ - g τ := by\n intro τ\n rw [hsplit, hΨ'_erase, hflip_erase, hflip_k]\n have : Ψ' k (t τ k) = t τ k := by simp [hΨ']\n rw [this, hfdef, hgdef]\n ring\n have hbd : ∀ (Θ : Fin n → ℝ → ℝ), (∀ i s, |Θ i s| ≤ |s|) → ∀ ρ : RadSigns n,\n BddAbove (Set.range fun τ : T => Xs t Θ ρ τ) := by\n intro Θ hΘ ρ\n exact bddAbove_of_bound _ M (fun τ => le_of_abs_le (Xs_bound t M hM Θ hΘ ρ τ))\n have hb1 : BddAbove (Set.range fun τ : T => f τ + u τ) := by\n have := hbd Ψ hΨb σ\n simpa [E1] using this\n have hb2 : BddAbove (Set.range fun τ : T => f τ - u τ) := by\n have := hbd Ψ hΨb (flipAt k σ)\n simpa [E2] using this\n have hb3 : BddAbove (Set.range fun τ : T => f τ + g τ) := by\n have := hbd Ψ' hΨ'b σ\n simpa [E3] using this\n have hb4 : BddAbove (Set.range fun τ : T => f τ - g τ) := by\n have := hbd Ψ' hΨ'b (flipAt k σ)\n simpa [E4] using this\n have habs : |((σ k : ℤ) : ℝ)| = 1 := rad_abs σ k\n have h1 : ∀ a b : T, u a - u b ≤ |g a - g b| := by\n intro a b\n have hgg : |g a - g b| = |t a k - t b k| := by\n rw [hgdef]\n simp only\n rw [← mul_sub, abs_mul, habs, one_mul]\n have : u a - u b ≤ |u a - u b| := le_abs_self _\n have h' : |u a - u b| = |Ψ k (t a k) - Ψ k (t b k)| := by\n rw [hudef]\n simp only\n rw [← mul_sub, abs_mul, habs, one_mul]\n rw [hgg]\n calc u a - u b ≤ |u a - u b| := le_abs_self _\n _ = |Ψ k (t a k) - Ψ k (t b k)| := h'\n _ ≤ |t a k - t b k| := hΨL k (t b k) (t a k)\n have h2 : ∀ a : T, |u a| ≤ |g a| := by\n intro a\n rw [hudef, hgdef]\n simp only\n rw [abs_mul, abs_mul, habs, one_mul, one_mul]\n exact hΨb k (t a k)\n have := key_two f g u h1 h2 hb1 hb2 hb3 hb4\n calc max (⨆ τ : T, Xs t Ψ σ τ) 0 + max (⨆ τ : T, Xs t Ψ (flipAt k σ) τ) 0\n = max (⨆ τ : T, (f τ + u τ)) 0 + max (⨆ τ : T, (f τ - u τ)) 0 := by\n rw [iSup_congr E1, iSup_congr E2]\n _ ≤ max (⨆ τ : T, (f τ + g τ)) 0 + max (⨆ τ : T, (f τ - g τ)) 0 := this\n _ = max (⨆ τ : T, Xs t Ψ' σ τ) 0 + max (⨆ τ : T, Xs t Ψ' (flipAt k σ) τ) 0 := by\n rw [iSup_congr E3, iSup_congr E4]\n have hsum1 : ∑ σ : RadSigns n, max (⨆ τ : T, Xs t Ψ (flipAt k σ) τ) 0 = Sg t Ψ :=\n sum_flip k (fun σ => max (⨆ τ : T, Xs t Ψ σ τ) 0)\n have hsum2 : ∑ σ : RadSigns n, max (⨆ τ : T, Xs t Ψ' (flipAt k σ) τ) 0 = Sg t Ψ' :=\n sum_flip k (fun σ => max (⨆ τ : T, Xs t Ψ' σ τ) 0)\n have := Finset.sum_le_sum (fun σ (_ : σ ∈ (Finset.univ : Finset (RadSigns n))) => key σ)\n rw [Finset.sum_add_distrib, Finset.sum_add_distrib] at this\n rw [hsum1, hsum2] at this\n have hSg : Sg t Ψ = ∑ σ : RadSigns n, max (⨆ τ : T, Xs t Ψ σ τ) 0 := rfl\n have hSg' : Sg t Ψ' = ∑ σ : RadSigns n, max (⨆ τ : T, Xs t Ψ' σ τ) 0 := rfl\n rw [← hSg, ← hSg'] at this\n linarith\n\ntheorem ch26_lemma_26_1\n {n : ℕ} {T : Type*} [Nonempty T]\n (t : T → (Fin n → ℝ))\n (φ : Fin n → ℝ → ℝ)\n (hφ0 : ∀ i, φ i 0 = 0)\n (hφL : ∀ i s s', |φ i s' - φ i s| ≤ |s' - s|)\n (hbddφ : ∀ σ : RadSigns n,\n BddAbove (Set.range (fun τ : T => |∑ i : Fin n, (σ i : ℝ) * φ i (t τ i)|)))\n (hbdd : ∀ σ : RadSigns n,\n BddAbove (Set.range (fun τ : T => |∑ i : Fin n, (σ i : ℝ) * t τ i|))) :\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ τ : T, |∑ i : Fin n, (σ i : ℝ) * φ i (t τ i)|\n ≤ 2 * ((Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ τ : T, |∑ i : Fin n, (σ i : ℝ) * t τ i|) := by\n classical\n set M : ℝ := Finset.univ.sup' Finset.univ_nonempty\n (fun σ : RadSigns n => ⨆ τ : T, |∑ i : Fin n, ((σ i : ℤ) : ℝ) * t τ i|) with hMdef\n have hM : ∀ τ, ∑ i, |t τ i| ≤ M := by\n intro τ\n refine\n let σ : RadSigns n := fun i => if 0 ≤ t τ i then ⟨1, by simp⟩ else ⟨-1, by simp⟩\n ?_\n have h1 : ∑ i, |t τ i| = ∑ i : Fin n, ((σ i : ℤ) : ℝ) * t τ i := by\n refine Finset.sum_congr rfl ?_\n intro i _\n by_cases h : 0 ≤ t τ i\n · simp [σ, h, abs_of_nonneg h]\n · simp [σ, h, abs_of_neg (not_le.mp h)]\n calc ∑ i, |t τ i| = ∑ i : Fin n, ((σ i : ℤ) : ℝ) * t τ i := h1\n _ ≤ |∑ i : Fin n, ((σ i : ℤ) : ℝ) * t τ i| := le_abs_self _\n _ ≤ ⨆ τ : T, |∑ i : Fin n, ((σ i : ℤ) : ℝ) * t τ i| := le_ciSup (hbdd σ) τ\n _ ≤ M := by\n rw [hMdef]\n exact Finset.le_sup'\n (fun ρ : RadSigns n => ⨆ τ : T, |∑ i : Fin n, ((ρ i : ℤ) : ℝ) * t τ i|)\n (Finset.mem_univ σ)\n have hφb : ∀ i s, |φ i s| ≤ |s| := by\n intro i s\n have := hφL i 0 s\n rw [hφ0 i, sub_zero, sub_zero] at this\n exact this\n have hidb : ∀ (i : Fin n) (s : ℝ), |(fun (_ : Fin n) (y : ℝ) => y) i s| ≤ |s| := by\n intro i s; exact le_rfl\n have hyb_b : ∀ (s : Finset (Fin n)) (i : Fin n) (x : ℝ),\n |(if i ∈ s then (fun y : ℝ => y) else φ i) x| ≤ |x| := by\n intro s i x\n by_cases h : i ∈ s\n · simp [h]\n · simp only [h, if_false]; exact hφb i x\n have hyb_L : ∀ (s : Finset (Fin n)) (i : Fin n) (a b : ℝ),\n |(if i ∈ s then (fun y : ℝ => y) else φ i) b\n - (if i ∈ s then (fun y : ℝ => y) else φ i) a| ≤ |b - a| := by\n intro s i a b\n by_cases h : i ∈ s\n · simp [h]\n · simp only [h, if_false]; exact hφL i a b\n have IH : ∀ s : Finset (Fin n),\n Sg t φ ≤ Sg t (fun i => if i ∈ s then (fun y : ℝ => y) else φ i) := by\n intro s\n induction s using Finset.induction_on with\n | empty => simp\n | insert k s hk ih =>\n refine ih.trans ?_\n have heq : (fun i => if i ∈ insert k s then (fun y : ℝ => y) else φ i)\n = Function.update (fun i => if i ∈ s then (fun y : ℝ => y) else φ i) k\n (fun y : ℝ => y) := by\n funext i\n by_cases h : i = k\n · subst h; simp\n · rw [Function.update_of_ne h]\n simp [Finset.mem_insert, h]\n rw [heq]\n exact step t M hM _ (hyb_b s) (fun i a b => hyb_L s i a b) k\n have main : Sg t φ ≤ Sg t (fun _ => fun y : ℝ => y) := by\n have := IH Finset.univ\n simpa using this\n have hbdd' : ∀ (Θ : Fin n → ℝ → ℝ), (∀ i s, |Θ i s| ≤ |s|) → ∀ ρ : RadSigns n,\n BddAbove (Set.range fun τ : T => Xs t Θ ρ τ) := by\n intro Θ hΘ ρ\n exact bddAbove_of_bound _ M (fun τ => le_of_abs_le (Xs_bound t M hM Θ hΘ ρ τ))\n have hbddabs : ∀ (Θ : Fin n → ℝ → ℝ), (∀ i s, |Θ i s| ≤ |s|) → ∀ ρ : RadSigns n,\n BddAbove (Set.range fun τ : T => |Xs t Θ ρ τ|) := by\n intro Θ hΘ ρ\n exact bddAbove_of_bound _ M (fun τ => Xs_bound t M hM Θ hΘ ρ τ)\n -- Step A : sum of sup of abs ≤ 2 * Sg\n have stepA : (∑ σ : RadSigns n, ⨆ τ : T, |Xs t φ σ τ|) ≤ 2 * Sg t φ := by\n have hper : ∀ σ : RadSigns n,\n (⨆ τ : T, |Xs t φ σ τ|)\n ≤ max (⨆ τ : T, Xs t φ σ τ) 0 + max (⨆ τ : T, Xs t φ (negAll σ) τ) 0 := by\n intro σ\n refine ciSup_le ?_\n intro τ\n have h1 : Xs t φ σ τ ≤ ⨆ τ : T, Xs t φ σ τ := le_ciSup (hbdd' φ hφb σ) τ\n have h2 : Xs t φ (negAll σ) τ ≤ ⨆ τ : T, Xs t φ (negAll σ) τ :=\n le_ciSup (hbdd' φ hφb (negAll σ)) τ\n rw [Xs_negAll] at h2\n have m1 : max (Xs t φ σ τ) 0 ≤ max (⨆ τ : T, Xs t φ σ τ) 0 := by\n exact max_le_max h1 le_rfl\n have m2 : max (-(Xs t φ σ τ)) 0 ≤ max (⨆ τ : T, Xs t φ (negAll σ) τ) 0 := by\n exact max_le_max h2 le_rfl\n have : |Xs t φ σ τ| = max (Xs t φ σ τ) 0 + max (-(Xs t φ σ τ)) 0 := by\n rcases le_total 0 (Xs t φ σ τ) with h | h\n · rw [abs_of_nonneg h, max_eq_left h, max_eq_right (by linarith)]; ring\n · rw [abs_of_nonpos h, max_eq_right h, max_eq_left (by linarith)]; ring\n rw [this]\n linarith\n have hsum := Finset.sum_le_sum (fun σ (_ : σ ∈ (Finset.univ : Finset (RadSigns n))) => hper σ)\n rw [Finset.sum_add_distrib] at hsum\n have hre : ∑ σ : RadSigns n, max (⨆ τ : T, Xs t φ (negAll σ) τ) 0 = Sg t φ :=\n sum_negAll (fun σ => max (⨆ τ : T, Xs t φ σ τ) 0)\n rw [hre] at hsum\n have hSg : Sg t φ = ∑ σ : RadSigns n, max (⨆ τ : T, Xs t φ σ τ) 0 := rfl\n rw [← hSg] at hsum\n linarith\n -- Step C : Sg (id) ≤ sum of sup of abs\n have stepC : Sg t (fun _ => fun y : ℝ => y)\n ≤ ∑ σ : RadSigns n, ⨆ τ : T, |Xs t (fun _ => fun y : ℝ => y) σ τ| := by\n refine Finset.sum_le_sum ?_\n intro σ _\n have hb := hbddabs (fun _ => fun y : ℝ => y) hidb σ\n have h1 : (⨆ τ : T, Xs t (fun _ => fun y : ℝ => y) σ τ)\n ≤ ⨆ τ : T, |Xs t (fun _ => fun y : ℝ => y) σ τ| := by\n refine ciSup_le ?_\n intro τ\n exact le_trans (le_abs_self _) (le_ciSup hb τ)\n have h0 : (0:ℝ) ≤ ⨆ τ : T, |Xs t (fun _ => fun y : ℝ => y) σ τ| := by\n obtain ⟨τ0⟩ := ‹Nonempty T›\n exact le_trans (abs_nonneg _) (le_ciSup hb τ0)\n exact max_le h1 h0\n have hfinal : (∑ σ : RadSigns n, ⨆ τ : T, |Xs t φ σ τ|)\n ≤ 2 * ∑ σ : RadSigns n, ⨆ τ : T, |Xs t (fun _ => fun y : ℝ => y) σ τ| := by\n linarith\n simp only [Xs] at hfinal\n have hc : (0:ℝ) ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ := by positivity\n refine le_trans (mul_le_mul_of_nonneg_left hfinal hc) (le_of_eq (by ring))\n\nend GraduateLevel\n"} +{"id": "ch37_lemma_37_1", "source": "Graduate-level", "targets": [{"label": "ch37_lemma_37_1", "decls": ["ch37_lemma_37_1"], "statement": "Let\n\\[V(x)=\\mathbb{E}_{x^{\\prime}}\\operatorname*{sup}_{f\\in\\mathcal{F}}\\sum_{i=1}^{n}(f(x_{i})-f(x_{i}^{\\prime}))^{2}\\]\nand \\(a \\leq f \\leq b\\) for all \\(f\\in{\\mathcal{F}}\\) . Then\n\\[\\begin{array}{ r }{\\operatorname{\\mathbb{P}}\\left(V\\leq 4\\operatorname{\\mathbb{E}}V+(b-a)^{2}t\\right)\\geq 1-4\\cdot 2^{-t}.}\\end{array}\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Functional & Supremum Concentration"}], "nl_proof": "Consider M-median of V, i.e. \\(\\mathbb{P}\\left(V\\ge M\\right)\\ge 1/2,\\mathbb{P}\\left(V\\le M\\right)\\ge 1/2\\) Let \\(A=\\left\\{y\\in{\\mathcal{X}}^{n},V(y)\\leq M\\right\\}\\subseteq\\) \\(\\mathcal{X}^{n}\\) . Hence,A consists of points with typical behavior.We wil use control by 2 points to show that any other point is close to these two points.\nBy control by 2 points,\n\\[\\mathbb{P}\\left(d(A,A,x)\\ge t\\right)\\le\\frac{1}{\\mathbb{P}\\left(A\\right)\\mathbb{P}\\left(A\\right)}\\cdot 2^{-t}\\le 4\\cdot 2^{-t}\\]\nTake any \\(x\\in\\mathcal{X}^{n}\\) .With probability at least \\(1-4\\cdot 2^{-t},d(A,A,x)\\leq t .\\) ,Hence,we can find \\(y^{1}\\in A,y^{2}\\in A\\) such that card \\(\\{i\\leq n,x_{i}\\neq y_{i}^{1},x_{i}\\neq y_{i}^{2}\\}\\leq t\\)\nLet\n\\[I_{1}=\\{i\\leq n:x_{i}=y_{i}^{1}\\},I_{2}=\\{i\\leq n:x_{i}\\neq y_{i}^{1},x_{i}=y_{i}^{2}\\},\\]\nand\n\\[I_{3}=\\{i\\leq n:x_{i}\\neq y_{i}^{1},x_{i}\\neq y_{i}^{2}\\}\\]\nThen we can decompose V as follows\n\\[\\begin{aligned} V(x)&=\\mathbb E_{x'}\\sup_{f\\in\\mathcal F}\\sum_{i=1}^n(f(x_i)-f(x_i'))^2\\\\ &=\\mathbb E_{x'}\\sup_{f\\in\\mathcal F}\\left[\\sum_{i\\in I_1}(f(x_i)-f(x_i'))^2+\\sum_{i\\in I_2}(f(x_i)-f(x_i'))^2+\\sum_{i\\in I_3}(f(x_i)-f(x_i'))^2\\right]\\\\ &\\le\\mathbb E_{x'}\\sup_{f\\in\\mathcal F}\\sum_{i\\in I_1}(f(x_i)-f(x_i'))^2+\\mathbb E_{x'}\\sup_{f\\in\\mathcal F}\\sum_{i\\in I_2}(f(x_i)-f(x_i'))^2+\\mathbb E_{x'}\\sup_{f\\in\\mathcal F}\\sum_{i\\in I_3}(f(x_i)-f(x_i'))^2\\\\ &\\le\\mathbb E_{x'}\\sup_{f\\in\\mathcal F}\\sum_{i=1}^n(f(y_i^1)-f(x_i'))^2+\\mathbb E_{x'}\\sup_{f\\in\\mathcal F}\\sum_{i=1}^n(f(y_i^2)-f(x_i'))^2+(b-a)^2t\\\\ &=V(y^1)+V(y^2)+(b-a)^2t\\\\ &\\le M+M+(b-a)^2t \\end{aligned}\\]\nbecause \\(y^{1},y^{2}\\in A\\) 1.Hence,\n\\[\\begin{array}{ r }{\\mathbb{P}\\left(V(x)\\leq 2 M+(b-a)^{2}t\\right)\\geq 1-4\\cdot 2^{-t}.}\\end{array}\\]\nFinally, \\(M\\leq 2\\mathbb{E}V\\) because\n\\[\\mathbb{P}\\left(V\\ge 2\\mathbb{E}V\\right)\\le\\frac{\\mathbb{E}V}{2\\mathbb{E}V}=\\frac{1}{2}\\qquad\\mathrm{while}\\qquad\\mathbb{P}\\left(V\\ge M\\right)\\ge\\frac{1}{2}.\\]", "context": [{"id": "ch33:theorem:33_1", "name": "theorem 33.1", "statement": "\\[\\mathbb{E}e^{{\\frac{1}{4}}d(A,x)}=\\int e^{{\\frac{1}{4}}d(A,x)}d P^{n}(x)\\leq{\\frac{1}{P^{n}(A)}}\\]\nand\n\\[P^{n}(d(A,x)\\geq t)\\leq{\\frac{1}{P^{n}(A)}}e^{-t/4}.\\]"}, {"id": "ch36:lemma:36_1", "name": "lemma 36.1", "statement": "Let \\(0\\leq g_{1},g_{2}\\leq 1,g_{i}:\\mathcal{X}\\mapsto [0,1]\\) . Then\n\\[\\int\\operatorname*{min}\\left(2,{\\frac{1}{g_{1}(x)}},{\\frac{1}{g_{2}(x)}}\\right)d P(x)\\cdot\\int g_{1}(x)d P(x)\\cdot\\int g_{2}(x)d P(x)\\leq 1\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory\n\nnamespace GraduateLevel\n\ntheorem ch37_lemma_37_1\n {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ]\n (n : ℕ) (a b : ℝ) (hab : a ≤ b)\n (F : Set (X → ℝ)) (hF : F.Nonempty)\n (hbound : ∀ f ∈ F, ∀ x, a ≤ f x ∧ f x ≤ b)\n (V : (Fin n → X) → ℝ)\n (hVdef : V = fun x => ∫ x',\n (⨆ f ∈ F, ∑ i : Fin n, (f (x i) - f (x' i))^2) ∂(Measure.pi (fun _ : Fin n => μ)))\n (hVintegrand : ∀ x : Fin n → X,\n Integrable (fun x' => ⨆ f ∈ F, ∑ i : Fin n, (f (x i) - f (x' i)) ^ 2)\n (Measure.pi (fun _ : Fin n => μ)))\n (hVmeas : Measurable V)\n (hVint : Integrable V (Measure.pi (fun _ : Fin n => μ))) :\n ∀ t : ℝ, 0 ≤ t →\n ((Measure.pi (fun _ : Fin n => μ))\n {x | V x ≤ 4 * (∫ x, V x ∂(Measure.pi (fun _ : Fin n => μ))) + (b - a)^2 * t}).toReal\n ≥ 1 - 4 * (2 : ℝ) ^ (-t) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory\nopen scoped NNReal ENNReal\n\nnamespace GraduateLevel\n\nprivate lemma real_stepA (I a₁ a₂ b₁ b₂ : ℝ)\n (hI : 0 ≤ I) (ha₁ : 0 ≤ a₁) (ha₂ : 0 ≤ a₂) (hb₁ : 0 < b₁) (hb₂ : 0 < b₂)\n (hab₁ : a₁ ≤ b₁) (hab₂ : a₂ ≤ b₂)\n (h2 : I * b₁ * b₂ ≤ 2) (h3 : I * a₁ * b₂ ≤ 1) (h4 : I * b₁ * a₂ ≤ 1) :\n I * (b₁ * b₁ * b₂ * b₂) + a₁ * b₂ + a₂ * b₁ ≤ 3 * (b₁ * b₂) := by\n have hw : 0 < b₁ * b₂ := mul_pos hb₁ hb₂\n have key : (2 - I * b₁ * b₂) * (2 * (b₁ * b₂) - a₁ * b₂ - a₂ * b₁) ≥ 0 := by\n apply mul_nonneg (by linarith)\n nlinarith [mul_le_mul_of_nonneg_right hab₁ hb₂.le, mul_le_mul_of_nonneg_right hab₂ hb₁.le]\n have e3 : (I * a₁ * b₂) * (b₁ * b₂) ≤ 1 * (b₁ * b₂) :=\n mul_le_mul_of_nonneg_right h3 hw.le\n have e4 : (I * b₁ * a₂) * (b₁ * b₂) ≤ 1 * (b₁ * b₂) :=\n mul_le_mul_of_nonneg_right h4 hw.le\n nlinarith [key, e3, e4]\n\nprivate lemma real_cube (w u v : ℝ) (hu : 0 ≤ u) (hv : 0 ≤ v) (huw : u ≤ w) (hvw : v ≤ w) :\n (3 * w - u - v) * (u * v) ≤ w ^ 3 := by\n have hw0 : 0 ≤ w := le_trans hu huw\n have h1 : (2 * w - (u + v)) ^ 2 * (w + (u + v)) ≥ 0 :=\n mul_nonneg (sq_nonneg _) (by linarith)\n have h2 : 4 * (u * v) ≤ (u + v) ^ 2 := by nlinarith [sq_nonneg (u - v)]\n have h3 : 0 ≤ 3 * w - u - v := by linarith\n nlinarith [mul_le_mul_of_nonneg_left h2 h3]\n\nprivate lemma real_stepB (Y b₁ b₂ c₁ c₂ : ℝ)\n (hY : 0 ≤ Y) (hc₁ : 0 ≤ c₁) (hc₂ : 0 ≤ c₂) (hb₁ : 0 < b₁) (hb₂ : 0 < b₂)\n (hcb₁ : c₁ ≤ b₁) (hcb₂ : c₂ ≤ b₂)\n (H : Y * (b₁ * b₁ * b₂ * b₂) + c₁ * b₂ + c₂ * b₁ ≤ 3 * (b₁ * b₂)) :\n Y * c₁ * c₂ ≤ 1 := by\n set w := b₁ * b₂ with hw\n have hwpos : 0 < w := mul_pos hb₁ hb₂\n set u := c₁ * b₂ with hu\n set v := c₂ * b₁ with hv\n have hu0 : 0 ≤ u := mul_nonneg hc₁ hb₂.le\n have hv0 : 0 ≤ v := mul_nonneg hc₂ hb₁.le\n have huw : u ≤ w := by simpa [hu, hw] using mul_le_mul_of_nonneg_right hcb₁ hb₂.le\n have hvw : v ≤ w := by\n have := mul_le_mul_of_nonneg_right hcb₂ hb₁.le\n simp only [hv, hw]; nlinarith\n have hcube := real_cube w u v hu0 hv0 huw hvw\n have hH : Y * w ^ 2 ≤ 3 * w - u - v := by nlinarith\n have h5 : Y * w ^ 2 * (u * v) ≤ (3 * w - u - v) * (u * v) :=\n mul_le_mul_of_nonneg_right hH (mul_nonneg hu0 hv0)\n have h6 : Y * w ^ 2 * (u * v) ≤ w ^ 3 := le_trans h5 hcube\n have key : (Y * c₁ * c₂) * w ^ 3 ≤ 1 * w ^ 3 := by\n have : u * v = c₁ * c₂ * w := by rw [hu, hv, hw]; ring\n calc (Y * c₁ * c₂) * w ^ 3 = Y * w ^ 2 * (c₁ * c₂ * w) := by ring\n _ = Y * w ^ 2 * (u * v) := by rw [this]\n _ ≤ w ^ 3 := h6\n _ = 1 * w ^ 3 := by ring\n have := le_of_mul_le_mul_right (by linarith [key] : (Y * c₁ * c₂) * w ^ 3 ≤ 1 * w ^ 3) (by positivity : (0:ℝ) < w ^ 3)\n exact this\n\n\nprivate lemma enn_stepA (I a₁ a₂ b₁ b₂ : ℝ≥0∞) (hb₁ : b₁ ≠ 0) (hb₂ : b₂ ≠ 0)\n (hb₁' : b₁ ≠ ⊤) (hb₂' : b₂ ≠ ⊤)\n (hab₁ : a₁ ≤ b₁) (hab₂ : a₂ ≤ b₂)\n (h2 : I * b₁ * b₂ ≤ 2) (h3 : I * a₁ * b₂ ≤ 1) (h4 : I * b₁ * a₂ ≤ 1) :\n I * (b₁ * b₁ * b₂ * b₂) + a₁ * b₂ + a₂ * b₁ ≤ 3 * (b₁ * b₂) := by\n have hI : I ≠ ⊤ := by\n rintro rfl\n rw [ENNReal.top_mul hb₁, ENNReal.top_mul hb₂] at h2\n simp at h2\n have ha₁' : a₁ ≠ ⊤ := ne_top_of_le_ne_top hb₁' hab₁\n have ha₂' : a₂ ≠ ⊤ := ne_top_of_le_ne_top hb₂' hab₂\n lift I to ℝ≥0 using hI\n lift a₁ to ℝ≥0 using ha₁'\n lift a₂ to ℝ≥0 using ha₂'\n lift b₁ to ℝ≥0 using hb₁'\n lift b₂ to ℝ≥0 using hb₂'\n simp only [← ENNReal.coe_mul, ← ENNReal.coe_add, ← ENNReal.coe_ofNat, ← ENNReal.coe_one, ENNReal.coe_le_coe]\n at h2 h3 h4 hab₁ hab₂ ⊢\n rw [← NNReal.coe_le_coe] at h2 h3 h4 hab₁ hab₂ ⊢\n push_cast at h2 h3 h4 hab₁ hab₂ ⊢\n have hb₁p : (0:ℝ) < b₁ := by\n have h : b₁ ≠ 0 := by simpa using hb₁\n exact lt_of_le_of_ne (b₁.coe_nonneg) (Ne.symm (NNReal.coe_ne_zero.2 h))\n have hb₂p : (0:ℝ) < b₂ := by\n have h : b₂ ≠ 0 := by simpa using hb₂\n exact lt_of_le_of_ne (b₂.coe_nonneg) (Ne.symm (NNReal.coe_ne_zero.2 h))\n exact real_stepA _ _ _ _ _ I.coe_nonneg a₁.coe_nonneg a₂.coe_nonneg hb₁p hb₂p hab₁ hab₂ h2 h3 h4\n\nprivate lemma enn_stepB (Y b₁ b₂ c₁ c₂ : ℝ≥0∞) (hb₁ : b₁ ≠ 0) (hb₂ : b₂ ≠ 0)\n (hb₁' : b₁ ≠ ⊤) (hb₂' : b₂ ≠ ⊤)\n (hcb₁ : c₁ ≤ b₁) (hcb₂ : c₂ ≤ b₂)\n (H : Y * (b₁ * b₁ * b₂ * b₂) + c₁ * b₂ + c₂ * b₁ ≤ 3 * (b₁ * b₂)) :\n Y * c₁ * c₂ ≤ 1 := by\n have hc₁' : c₁ ≠ ⊤ := ne_top_of_le_ne_top hb₁' hcb₁\n have hc₂' : c₂ ≠ ⊤ := ne_top_of_le_ne_top hb₂' hcb₂\n have hbne : b₁ * b₁ * b₂ * b₂ ≠ 0 := by\n simp [hb₁, hb₂]\n have hY : Y ≠ ⊤ := by\n rintro rfl\n rw [ENNReal.top_mul hbne] at H\n have h1 : (⊤ : ℝ≥0∞) ≤ 3 * (b₁ * b₂) :=\n le_trans (le_trans le_self_add le_self_add) H\n have h2 : (3 : ℝ≥0∞) * (b₁ * b₂) ≠ ⊤ := by\n finiteness\n exact h2 (top_le_iff.1 h1)\n lift Y to ℝ≥0 using hY\n lift c₁ to ℝ≥0 using hc₁'\n lift c₂ to ℝ≥0 using hc₂'\n lift b₁ to ℝ≥0 using hb₁'\n lift b₂ to ℝ≥0 using hb₂'\n simp only [← ENNReal.coe_mul, ← ENNReal.coe_add, ← ENNReal.coe_ofNat, ← ENNReal.coe_one,\n ENNReal.coe_le_coe] at H hcb₁ hcb₂ ⊢\n rw [← NNReal.coe_le_coe] at H hcb₁ hcb₂ ⊢\n push_cast at H hcb₁ hcb₂ ⊢\n have hb₁p : (0:ℝ) < b₁ := by\n have h : b₁ ≠ 0 := by simpa using hb₁\n exact lt_of_le_of_ne (b₁.coe_nonneg) (Ne.symm (NNReal.coe_ne_zero.2 h))\n have hb₂p : (0:ℝ) < b₂ := by\n have h : b₂ ≠ 0 := by simpa using hb₂\n exact lt_of_le_of_ne (b₂.coe_nonneg) (Ne.symm (NNReal.coe_ne_zero.2 h))\n exact real_stepB _ _ _ _ _ Y.coe_nonneg c₁.coe_nonneg c₂.coe_nonneg hb₁p hb₂p hcb₁ hcb₂ H\n\nprivate lemma mul3_le_one {a b c : ℝ≥0∞} (ha : a ≤ 1) (hb : b ≤ 1) (hc : c ≤ 1) :\n a * b * c ≤ 1 := by\n calc a * b * c ≤ 1 * 1 * 1 := mul_le_mul' (mul_le_mul' ha hb) hc\n _ = 1 := by norm_num\n\nprivate theorem talagrand2 {X : Type*} [MeasurableSpace X] (μ : Measure X)\n [IsProbabilityMeasure μ] :\n ∀ (n : ℕ) (A₁ A₂ : Set (Fin n → X)), MeasurableSet A₁ → MeasurableSet A₂ →\n ∀ (h : (Fin n → X) → ℝ≥0∞), Measurable h →\n (∀ (x : Fin n → X), ∀ y ∈ A₁, ∀ z ∈ A₂, ∀ s : Finset (Fin n),\n (∀ i, i ∉ s → x i = y i ∨ x i = z i) → h x ≤ 2 ^ s.card) →\n (∫⁻ x, h x ∂(Measure.pi fun _ : Fin n => μ)) * (Measure.pi fun _ : Fin n => μ) A₁ *\n (Measure.pi fun _ : Fin n => μ) A₂ ≤ 1 := by\n intro n\n induction n with\n | zero =>\n intro A₁ A₂ hA₁ hA₂ h hh hdom\n rcases Set.eq_empty_or_nonempty A₁ with rfl | ⟨y, hy⟩\n · simp\n rcases Set.eq_empty_or_nonempty A₂ with rfl | ⟨z, hz⟩\n · simp\n have h1 : ∀ x, h x ≤ 1 := by\n intro x\n have := hdom x y hy z hz ∅ (fun i _ => i.elim0)\n simpa using this\n have h2 : (∫⁻ x, h x ∂(Measure.pi fun _ : Fin 0 => μ)) ≤ 1 := by\n calc (∫⁻ x, h x ∂(Measure.pi fun _ : Fin 0 => μ))\n ≤ ∫⁻ _, 1 ∂(Measure.pi fun _ : Fin 0 => μ) := lintegral_mono h1\n _ = 1 := by simp\n exact mul3_le_one h2 prob_le_one prob_le_one\n | succ n IH =>\n intro A₁ A₂ hA₁ hA₂ h hh hdom\n classical\n set P : Measure (Fin n → X) := Measure.pi fun _ => μ with hPdef\n set Q : Measure (Fin (n+1) → X) := Measure.pi fun _ => μ with hQdef\n by_cases hQ₁ : Q A₁ = 0\n · simp [hQ₁]\n by_cases hQ₂ : Q A₂ = 0\n · simp [hQ₂]\n have hA₁ne : A₁.Nonempty := by\n rcases Set.eq_empty_or_nonempty A₁ with rfl | hne\n · exact absurd (by simp) hQ₁\n · exact hne\n obtain ⟨x₀, hx₀⟩ := hA₁ne\n have hXne : Nonempty X := ⟨x₀ (Fin.last n)⟩\n set e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => X) (Fin.last n) with he\n set F : X → (Fin n → X) → (Fin (n+1) → X) := fun ω y => e.symm (ω, y) with hFdef\n have hFlast : ∀ ω y, F ω y (Fin.last n) = ω := by\n intro ω y; simp [hFdef, he, MeasurableEquiv.piFinSuccAbove_symm_apply]\n have hFcast : ∀ ω y (j : Fin n), F ω y (Fin.castSucc j) = y j := by\n intro ω y j; simp [hFdef, he, MeasurableEquiv.piFinSuccAbove_symm_apply]\n have hFmeas : ∀ ω, Measurable (F ω) := by\n intro ω\n exact e.symm.measurable.comp measurable_prodMk_left\n have hmp : MeasurePreserving e Q (μ.prod P) :=\n measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => μ) (Fin.last n)\n have hslice : ∀ (A : Set (Fin (n+1) → X)), MeasurableSet A → ∀ ω,\n MeasurableSet {y | F ω y ∈ A} := by\n intro A hA ω\n exact hA.preimage (hFmeas ω)\n have hameas : ∀ (A : Set (Fin (n+1) → X)), MeasurableSet A →\n Measurable (fun ω => P {y | F ω y ∈ A}) := by\n intro A hA\n exact measurable_measure_prodMk_left (hA.preimage e.symm.measurable)\n have hint : ∀ (A : Set (Fin (n+1) → X)), MeasurableSet A →\n ∫⁻ ω, P {y | F ω y ∈ A} ∂μ = Q A := by\n intro A hA\n have h1 : MeasurableSet (⇑e.symm ⁻¹' A) := hA.preimage e.symm.measurable\n have h2 : (μ.prod P) (⇑e.symm ⁻¹' A) = Q A := by\n rw [← hmp.map_eq, MeasurableEquiv.map_apply]\n congr 1\n ext x\n simp\n rw [← h2, Measure.prod_apply h1]\n rfl\n -- construction of the \"projection substitute\" B\n have hB : ∀ (A : Set (Fin (n+1) → X)), MeasurableSet A → Q A ≠ 0 →\n ∃ B : Set (Fin n → X), MeasurableSet B ∧ (∀ y ∈ B, ∃ ω, F ω y ∈ A) ∧\n (∀ ω, P {y | F ω y ∈ A} ≤ P B) ∧ P B ≠ 0 := by\n intro A hA hAne\n set a : X → ℝ≥0∞ := fun ω => P {y | F ω y ∈ A} with hadef\n set s := ⨆ ω, a ω with hsdef\n have hchoice : ∀ q : ℚ, ∃ ω : X, (ENNReal.ofReal (q:ℝ) < s → ENNReal.ofReal (q:ℝ) < a ω) := by\n intro q\n by_cases hq : ENNReal.ofReal (q:ℝ) < s\n · obtain ⟨ω, hω⟩ := lt_iSup_iff.1 hq\n exact ⟨ω, fun _ => hω⟩\n · exact ⟨Classical.arbitrary X, fun hcon => absurd hcon hq⟩\n choose w hw using hchoice\n set B : Set (Fin n → X) := ⋃ q : ℚ, {y | F (w q) y ∈ A} with hBdef\n have hBmeas : MeasurableSet B := MeasurableSet.iUnion (fun q => hslice A hA (w q))\n have hsubs : ∀ q : ℚ, {y | F (w q) y ∈ A} ⊆ B := by\n intro q\n rw [hBdef]\n exact Set.subset_iUnion (fun q : ℚ => {y | F (w q) y ∈ A}) q\n have hsB : s ≤ P B := by\n by_contra hcon\n push_neg at hcon\n obtain ⟨q, hq0, hq1, hq2⟩ := ENNReal.lt_iff_exists_rat_btwn.1 hcon\n have h1 : ENNReal.ofReal (q:ℝ) < a (w q) := hw q hq2\n have h2 : a (w q) ≤ P B := measure_mono (hsubs q)\n exact absurd (lt_of_lt_of_le h1 h2) (not_lt.2 hq1.le)\n have haB : ∀ ω, a ω ≤ P B := fun ω => le_trans (le_iSup a ω) hsB\n refine ⟨B, hBmeas, ?_, haB, ?_⟩\n · intro y hy\n simp only [hBdef, Set.mem_iUnion, Set.mem_setOf_eq] at hy\n obtain ⟨q, hq⟩ := hy\n exact ⟨w q, hq⟩\n · intro hPB0\n apply hAne\n rw [← hint A hA]\n have : ∀ ω, a ω = 0 := by\n intro ω\n exact le_antisymm (hPB0 ▸ haB ω) (zero_le _)\n simp only [hadef] at this\n simp [this]\n obtain ⟨B₁, hB₁meas, hB₁lift, hB₁ge, hB₁ne⟩ := hB A₁ hA₁ hQ₁\n obtain ⟨B₂, hB₂meas, hB₂lift, hB₂ge, hB₂ne⟩ := hB A₂ hA₂ hQ₂\n set cs : Fin n ↪ Fin (n+1) := ⟨Fin.castSucc, Fin.castSucc_injective n⟩ with hcs\n have hcs_notmem : ∀ (s : Finset (Fin n)) (j : Fin n),\n Fin.castSucc j ∉ Finset.map cs s → j ∉ s := by\n intro s j hj hjs\n exact hj (by simpa [hcs] using Finset.mem_map_of_mem cs hjs)\n -- IH applications\n have key3 : ∀ ω, (∫⁻ y, h (F ω y) ∂P) * P {y | F ω y ∈ A₁} * P B₂ ≤ 1 := by\n intro ω\n refine IH {y | F ω y ∈ A₁} B₂ (hslice A₁ hA₁ ω) hB₂meas (fun y => h (F ω y))\n (hh.comp (hFmeas ω)) ?_\n intro x u hu v hv s hcond\n obtain ⟨ω₂, hω₂⟩ := hB₂lift v hv\n have hb := hdom (F ω x) (F ω u) hu (F ω₂ v) hω₂ (Finset.map cs s) ?_\n · simpa [Finset.card_map] using hb\n · intro i hi\n revert hi\n induction i using Fin.lastCases with\n | last => intro _; left; rw [hFlast, hFlast]\n | cast j =>\n intro hi\n have hj : j ∉ s := hcs_notmem s j hi\n rcases hcond j hj with hjj | hjj\n · left; rw [hFcast, hFcast, hjj]\n · right; rw [hFcast, hFcast, hjj]\n have key4 : ∀ ω, (∫⁻ y, h (F ω y) ∂P) * P B₁ * P {y | F ω y ∈ A₂} ≤ 1 := by\n intro ω\n refine IH B₁ {y | F ω y ∈ A₂} hB₁meas (hslice A₂ hA₂ ω) (fun y => h (F ω y))\n (hh.comp (hFmeas ω)) ?_\n intro x u hu v hv s hcond\n obtain ⟨ω₁, hω₁⟩ := hB₁lift u hu\n have hb := hdom (F ω x) (F ω₁ u) hω₁ (F ω v) hv (Finset.map cs s) ?_\n · simpa [Finset.card_map] using hb\n · intro i hi\n revert hi\n induction i using Fin.lastCases with\n | last => intro _; right; rw [hFlast, hFlast]\n | cast j =>\n intro hi\n have hj : j ∉ s := hcs_notmem s j hi\n rcases hcond j hj with hjj | hjj\n · left; rw [hFcast, hFcast, hjj]\n · right; rw [hFcast, hFcast, hjj]\n have key2 : ∀ ω, (∫⁻ y, h (F ω y) ∂P) * P B₁ * P B₂ ≤ 2 := by\n intro ω\n have hhalf : (∫⁻ y, h (F ω y) / 2 ∂P) * P B₁ * P B₂ ≤ 1 := by\n refine IH B₁ B₂ hB₁meas hB₂meas (fun y => h (F ω y) / 2)\n ((hh.comp (hFmeas ω)).div_const 2) ?_\n intro x u hu v hv s hcond\n obtain ⟨ω₁, hω₁⟩ := hB₁lift u hu\n obtain ⟨ω₂, hω₂⟩ := hB₂lift v hv\n have hb := hdom (F ω x) (F ω₁ u) hω₁ (F ω₂ v) hω₂\n (insert (Fin.last n) (Finset.map cs s)) ?_\n · have hcard : (insert (Fin.last n) (Finset.map cs s)).card ≤ s.card + 1 := by\n calc (insert (Fin.last n) (Finset.map cs s)).card\n ≤ (Finset.map cs s).card + 1 := Finset.card_insert_le _ _\n _ = s.card + 1 := by rw [Finset.card_map]\n have hb2 : h (F ω x) ≤ 2 ^ (s.card + 1) :=\n le_trans hb (pow_le_pow_right₀ one_le_two hcard)\n refine ENNReal.div_le_of_le_mul ?_\n rw [← pow_succ]\n exact hb2\n · intro i hi\n revert hi\n induction i using Fin.lastCases with\n | last => intro hi; exact absurd (Finset.mem_insert_self _ _) hi\n | cast j =>\n intro hi\n have hj : j ∉ s := hcs_notmem s j (fun hc => hi (Finset.mem_insert_of_mem hc))\n rcases hcond j hj with hjj | hjj\n · left; rw [hFcast, hFcast, hjj]\n · right; rw [hFcast, hFcast, hjj]\n have hrw : (∫⁻ y, h (F ω y) / 2 ∂P) = 2⁻¹ * ∫⁻ y, h (F ω y) ∂P := by\n simp_rw [ENNReal.div_eq_inv_mul]\n exact lintegral_const_mul _ (hh.comp (hFmeas ω))\n rw [hrw] at hhalf\n have h2 := mul_le_mul_left' hhalf (2:ℝ≥0∞)\n have hrw2 : (2:ℝ≥0∞) * (2⁻¹ * (∫⁻ y, h (F ω y) ∂P) * P B₁ * P B₂)\n = (2 * 2⁻¹) * ((∫⁻ y, h (F ω y) ∂P) * P B₁ * P B₂) := by ring\n rw [hrw2, ENNReal.mul_inv_cancel two_ne_zero (by norm_num), one_mul, mul_one] at h2\n exact h2\n -- pointwise combination\n have hpt : ∀ ω, (∫⁻ y, h (F ω y) ∂P) * (P B₁ * P B₁ * P B₂ * P B₂)\n + P {y | F ω y ∈ A₁} * P B₂ + P {y | F ω y ∈ A₂} * P B₁ ≤ 3 * (P B₁ * P B₂) := by\n intro ω\n exact enn_stepA _ _ _ _ _ hB₁ne hB₂ne (measure_ne_top P B₁) (measure_ne_top P B₂)\n (hB₁ge ω) (hB₂ge ω) (key2 ω) (key3 ω) (key4 ω)\n have hImeas : Measurable (fun ω => ∫⁻ y, h (F ω y) ∂P) :=\n (hh.comp e.symm.measurable).lintegral_prod_right'\n have hIint : ∫⁻ ω, (∫⁻ y, h (F ω y) ∂P) ∂μ = ∫⁻ x, h x ∂Q :=\n (lintegral_prod (fun p => h (e.symm p)) (hh.comp e.symm.measurable).aemeasurable).symm.trans\n (hmp.symm.lintegral_comp hh)\n have hsum : ∫⁻ ω, ((∫⁻ y, h (F ω y) ∂P) * (P B₁ * P B₁ * P B₂ * P B₂)\n + P {y | F ω y ∈ A₁} * P B₂ + P {y | F ω y ∈ A₂} * P B₁) ∂μ\n = (∫⁻ x, h x ∂Q) * (P B₁ * P B₁ * P B₂ * P B₂) + Q A₁ * P B₂ + Q A₂ * P B₁ := by\n rw [lintegral_add_left (by exact ((hImeas.mul_const _).add ((hameas A₁ hA₁).mul_const _))),\n lintegral_add_left (by exact hImeas.mul_const _),\n lintegral_mul_const _ hImeas, lintegral_mul_const _ (hameas A₁ hA₁),\n lintegral_mul_const _ (hameas A₂ hA₂), hIint, hint A₁ hA₁, hint A₂ hA₂]\n have hfinal : (∫⁻ x, h x ∂Q) * (P B₁ * P B₁ * P B₂ * P B₂) + Q A₁ * P B₂ + Q A₂ * P B₁\n ≤ 3 * (P B₁ * P B₂) := by\n rw [← hsum]\n calc ∫⁻ ω, ((∫⁻ y, h (F ω y) ∂P) * (P B₁ * P B₁ * P B₂ * P B₂)\n + P {y | F ω y ∈ A₁} * P B₂ + P {y | F ω y ∈ A₂} * P B₁) ∂μ\n ≤ ∫⁻ _, 3 * (P B₁ * P B₂) ∂μ := lintegral_mono hpt\n _ = 3 * (P B₁ * P B₂) := by simp\n have hcb₁ : Q A₁ ≤ P B₁ := by\n rw [← hint A₁ hA₁]\n calc ∫⁻ ω, P {y | F ω y ∈ A₁} ∂μ ≤ ∫⁻ _, P B₁ ∂μ := lintegral_mono hB₁ge\n _ = P B₁ := by simp\n have hcb₂ : Q A₂ ≤ P B₂ := by\n rw [← hint A₂ hA₂]\n calc ∫⁻ ω, P {y | F ω y ∈ A₂} ∂μ ≤ ∫⁻ _, P B₂ ∂μ := lintegral_mono hB₂ge\n _ = P B₂ := by simp\n exact enn_stepB _ _ _ _ _ hB₁ne hB₂ne (measure_ne_top P B₁) (measure_ne_top P B₂)\n hcb₁ hcb₂ hfinal\n\nprivate lemma sq_diff_le {a b : ℝ} (u v : ℝ) (hu : a ≤ u ∧ u ≤ b) (hv : a ≤ v ∧ v ≤ b) :\n (u - v)^2 ≤ (b - a)^2 := by\n obtain ⟨hu1, hu2⟩ := hu\n obtain ⟨hv1, hv2⟩ := hv\n nlinarith [sq_nonneg (u - v), sq_nonneg (b - a)]\n\nprivate lemma sum_decomp {n : ℕ} {X : Type*} (a b : ℝ) (f : X → ℝ)\n (hb : ∀ u, a ≤ f u ∧ f u ≤ b)\n (x y z x' : Fin n → X) (s : Finset (Fin n))\n (hcond : ∀ i, i ∉ s → x i = y i ∨ x i = z i) :\n ∑ i, (f (x i) - f (x' i))^2 ≤ (∑ i, (f (y i) - f (x' i))^2) + (∑ i, (f (z i) - f (x' i))^2)\n + s.card * (b - a)^2 := by\n classical\n set g : Fin n → ℝ := fun i => (f (x i) - f (x' i))^2 with hg\n have hgnn : ∀ i, 0 ≤ g i := fun i => sq_nonneg _\n have h1 : ∑ i, g i = ∑ i ∈ Finset.univ \\ s, g i + ∑ i ∈ s, g i :=\n (Finset.sum_sdiff (Finset.subset_univ s)).symm\n have h2 : ∑ i ∈ Finset.univ \\ s, g i\n = ∑ i ∈ (Finset.univ \\ s).filter (fun i => x i = y i), g i\n + ∑ i ∈ (Finset.univ \\ s).filter (fun i => ¬ (x i = y i)), g i :=\n (Finset.sum_filter_add_sum_filter_not _ _ _).symm\n have hT1 : ∑ i ∈ (Finset.univ \\ s).filter (fun i => x i = y i), g i\n ≤ ∑ i, (f (y i) - f (x' i))^2 := by\n have hcongr : ∑ i ∈ (Finset.univ \\ s).filter (fun i => x i = y i), g i\n = ∑ i ∈ (Finset.univ \\ s).filter (fun i => x i = y i), (f (y i) - f (x' i))^2 := by\n refine Finset.sum_congr rfl (fun i hi => ?_)\n simp only [Finset.mem_filter] at hi\n rw [hg]; simp only; rw [hi.2]\n rw [hcongr]\n exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _)\n (fun i _ _ => sq_nonneg _)\n have hT2 : ∑ i ∈ (Finset.univ \\ s).filter (fun i => ¬ (x i = y i)), g i\n ≤ ∑ i, (f (z i) - f (x' i))^2 := by\n have hcongr : ∑ i ∈ (Finset.univ \\ s).filter (fun i => ¬ (x i = y i)), g i\n = ∑ i ∈ (Finset.univ \\ s).filter (fun i => ¬ (x i = y i)), (f (z i) - f (x' i))^2 := by\n refine Finset.sum_congr rfl (fun i hi => ?_)\n simp only [Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and] at hi\n have hz : x i = z i := by\n rcases hcond i hi.1 with h | h\n · exact absurd h hi.2\n · exact h\n rw [hg]; simp only; rw [hz]\n rw [hcongr]\n exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _)\n (fun i _ _ => sq_nonneg _)\n have hT3 : ∑ i ∈ s, g i ≤ s.card * (b - a)^2 := by\n calc ∑ i ∈ s, g i ≤ ∑ _i ∈ s, (b - a)^2 :=\n Finset.sum_le_sum (fun i _ => sq_diff_le _ _ (hb (x i)) (hb (x' i)))\n _ = s.card * (b - a)^2 := by rw [Finset.sum_const, nsmul_eq_mul]\n rw [h1, h2]\n linarith\n\nprivate lemma bddAbove_biSup {ι : Type*} [Nonempty ι] (F : Set ι) (g : ι → ℝ) (c : ℝ) (hc : 0 ≤ c)\n (hg : ∀ f ∈ F, g f ≤ c) : BddAbove (Set.range (fun f => ⨆ _ : f ∈ F, g f)) := by\n refine ⟨c, ?_⟩\n rintro w ⟨f, rfl⟩\n show (⨆ _ : f ∈ F, g f) ≤ c\n by_cases hf : f ∈ F\n · have : Nonempty (f ∈ F) := ⟨hf⟩\n rw [ciSup_const]\n exact hg f hf\n · have : IsEmpty (f ∈ F) := ⟨hf⟩\n rw [Real.iSup_of_isEmpty]\n exact hc\n\nprivate lemma biSup_le' {ι : Type*} [Nonempty ι] (F : Set ι) (g : ι → ℝ) (c : ℝ) (hc : 0 ≤ c)\n (hg : ∀ f ∈ F, g f ≤ c) : (⨆ f ∈ F, g f) ≤ c := by\n refine ciSup_le (fun f => ?_)\n by_cases hf : f ∈ F\n · have : Nonempty (f ∈ F) := ⟨hf⟩\n rw [ciSup_const]; exact hg f hf\n · have : IsEmpty (f ∈ F) := ⟨hf⟩\n rw [Real.iSup_of_isEmpty]; exact hc\n\nprivate lemma le_biSup' {ι : Type*} [Nonempty ι] (F : Set ι) (g : ι → ℝ)\n (hbdd : BddAbove (Set.range (fun f => ⨆ _ : f ∈ F, g f))) {f : ι} (hf : f ∈ F) :\n g f ≤ ⨆ f ∈ F, g f := by\n have h1 : (⨆ _ : f ∈ F, g f) ≤ ⨆ f', ⨆ _ : f' ∈ F, g f' := le_ciSup hbdd f\n have : Nonempty (f ∈ F) := ⟨hf⟩\n rwa [ciSup_const] at h1\n\ntheorem ch37_lemma_37_1\n {X : Type*} [MeasurableSpace X] (μ : Measure X) [IsProbabilityMeasure μ]\n (n : ℕ) (a b : ℝ) (hab : a ≤ b)\n (F : Set (X → ℝ)) (hF : F.Nonempty)\n (hbound : ∀ f ∈ F, ∀ x, a ≤ f x ∧ f x ≤ b)\n (V : (Fin n → X) → ℝ)\n (hVdef : V = fun x => ∫ x',\n (⨆ f ∈ F, ∑ i : Fin n, (f (x i) - f (x' i))^2) ∂(Measure.pi (fun _ : Fin n => μ)))\n (hVintegrand : ∀ x : Fin n → X,\n Integrable (fun x' => ⨆ f ∈ F, ∑ i : Fin n, (f (x i) - f (x' i)) ^ 2)\n (Measure.pi (fun _ : Fin n => μ)))\n (hVmeas : Measurable V)\n (hVint : Integrable V (Measure.pi (fun _ : Fin n => μ))) :\n ∀ t : ℝ, 0 ≤ t →\n ((Measure.pi (fun _ : Fin n => μ))\n {x | V x ≤ 4 * (∫ x, V x ∂(Measure.pi (fun _ : Fin n => μ))) + (b - a)^2 * t}).toReal\n ≥ 1 - 4 * (2 : ℝ) ^ (-t) := by\n intro t ht\n classical\n set P : Measure (Fin n → X) := Measure.pi fun _ => μ with hPdef\n set G : (Fin n → X) → (Fin n → X) → ℝ :=\n fun x x' => ⨆ f ∈ F, ∑ i : Fin n, (f (x i) - f (x' i))^2 with hGdef\n have hVval : ∀ x, V x = ∫ x', G x x' ∂P := by\n intro x; rw [hVdef]\n -- boundedness of the family\n have hsumle : ∀ (x x' : Fin n → X), ∀ f ∈ F,\n ∑ i : Fin n, (f (x i) - f (x' i))^2 ≤ (n : ℝ) * (b - a)^2 := by\n intro x x' f hf\n calc ∑ i : Fin n, (f (x i) - f (x' i))^2 ≤ ∑ _i : Fin n, (b - a)^2 :=\n Finset.sum_le_sum (fun i _ => sq_diff_le _ _ (hbound f hf (x i)) (hbound f hf (x' i)))\n _ = (n : ℝ) * (b - a)^2 := by\n rw [Finset.sum_const, nsmul_eq_mul, Finset.card_univ, Fintype.card_fin]\n have hcnn : (0:ℝ) ≤ (n : ℝ) * (b - a)^2 := by positivity\n have hbddG : ∀ (x x' : Fin n → X),\n BddAbove (Set.range (fun f : X → ℝ => ⨆ _ : f ∈ F, ∑ i : Fin n, (f (x i) - f (x' i))^2)) :=\n fun x x' => bddAbove_biSup F _ _ hcnn (hsumle x x')\n have hleG : ∀ (x x' : Fin n → X), ∀ f ∈ F,\n ∑ i : Fin n, (f (x i) - f (x' i))^2 ≤ G x x' :=\n fun x x' f hf => le_biSup' F _ (hbddG x x') hf\n have hGnn : ∀ x x', 0 ≤ G x x' := by\n intro x x'\n obtain ⟨f₀, hf₀⟩ := hF\n refine le_trans ?_ (hleG x x' f₀ hf₀)\n exact Finset.sum_nonneg (fun i _ => sq_nonneg _)\n have hVnn : ∀ x, 0 ≤ V x := by\n intro x\n rw [hVval x]\n exact integral_nonneg (fun x' => hGnn x x')\n -- key decomposition\n have K1 : ∀ (x y z : Fin n → X) (s : Finset (Fin n)),\n (∀ i, i ∉ s → x i = y i ∨ x i = z i) → V x ≤ V y + V z + s.card * (b - a)^2 := by\n intro x y z s hcond\n have hptwise : ∀ x', G x x' ≤ G y x' + G z x' + s.card * (b - a)^2 := by\n intro x'\n refine biSup_le' F _ _ ?_ ?_\n · have := hGnn y x'\n have := hGnn z x'\n have : (0:ℝ) ≤ s.card * (b - a)^2 := by positivity\n linarith [hGnn y x', hGnn z x']\n · intro f hf\n calc ∑ i : Fin n, (f (x i) - f (x' i))^2\n ≤ (∑ i, (f (y i) - f (x' i))^2) + (∑ i, (f (z i) - f (x' i))^2)\n + s.card * (b - a)^2 :=\n sum_decomp a b f (fun u => hbound f hf u) x y z x' s hcond\n _ ≤ G y x' + G z x' + s.card * (b - a)^2 := by\n have h1 := hleG y x' f hf\n have h2 := hleG z x' f hf\n linarith\n rw [hVval x, hVval y, hVval z]\n have hig : ∀ w : Fin n → X, Integrable (fun x' => G w x') P := hVintegrand\n have hyz : Integrable (fun x' => G y x' + G z x') P := (hig y).add (hig z)\n have hyzc : Integrable (fun x' => G y x' + G z x' + (s.card : ℝ) * (b - a)^2) P :=\n hyz.add (integrable_const _)\n calc ∫ x', G x x' ∂P\n ≤ ∫ x', (G y x' + G z x' + s.card * (b - a)^2) ∂P :=\n integral_mono (hig x) hyzc hptwise\n _ = (∫ x', G y x' ∂P) + (∫ x', G z x' ∂P) + s.card * (b - a)^2 := by\n rw [integral_add hyz (integrable_const _), integral_add (hig y) (hig z),\n integral_const]\n simp\n\n -- Markov: the set A of \"typical\" points has probability at least 1/2\n set EV := ∫ x, V x ∂P with hEVdef\n have hEVnn : 0 ≤ EV := by rw [hEVdef]; exact integral_nonneg hVnn\n set A : Set (Fin n → X) := {x | V x ≤ 2 * EV} with hAdef\n have hAmeas : MeasurableSet A := measurableSet_le hVmeas measurable_const\n have hPAc : P Aᶜ ≤ 2⁻¹ := by\n rcases eq_or_lt_of_le hEVnn with hEV0 | hEVpos\n · have hzero : ∫ x, V x ∂P = 0 := by rw [← hEVdef, ← hEV0]\n have hae : V =ᶠ[ae P] 0 := (integral_eq_zero_iff_of_nonneg (fun x => hVnn x) hVint).1 hzero\n have hnull : P {x | ¬ (V x = 0)} = 0 := by\n have := ae_iff.1 hae\n simpa using this\n have hAc0 : P Aᶜ = 0 := by\n refine measure_mono_null (fun x hx => ?_) hnull\n simp only [hAdef, Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hx\n simp only [Set.mem_setOf_eq]\n intro hV0\n rw [← hEV0] at hx\n simp only [mul_zero] at hx\n linarith [hx, hV0.ge]\n rw [hAc0]; exact zero_le _\n · have hmarkov := mul_meas_ge_le_lintegral₀\n (hVmeas.ennreal_ofReal.aemeasurable (μ := P)) (ENNReal.ofReal (2 * EV))\n rw [← ofReal_integral_eq_lintegral_ofReal hVint\n (Filter.Eventually.of_forall hVnn)] at hmarkov\n rw [← hEVdef] at hmarkov\n have hsub : Aᶜ ⊆ {x | ENNReal.ofReal (2 * EV) ≤ ENNReal.ofReal (V x)} := by\n intro x hx\n simp only [hAdef, Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hx\n exact ENNReal.ofReal_le_ofReal hx.le\n have h1 : ENNReal.ofReal (2 * EV) * P Aᶜ ≤ ENNReal.ofReal EV :=\n le_trans (mul_le_mul_left' (measure_mono hsub) _) hmarkov\n have h2 : ENNReal.ofReal (2 * EV) = 2 * ENNReal.ofReal EV := by\n rw [ENNReal.ofReal_mul (by norm_num)]\n norm_num\n rw [h2] at h1\n have hEVne : ENNReal.ofReal EV ≠ 0 := by\n simp only [ne_eq, ENNReal.ofReal_eq_zero, not_le]\n exact hEVpos\n have h3 : ENNReal.ofReal EV * (2 * P Aᶜ) ≤ ENNReal.ofReal EV * 1 := by\n rw [mul_one]\n calc ENNReal.ofReal EV * (2 * P Aᶜ) = 2 * ENNReal.ofReal EV * P Aᶜ := by ring\n _ ≤ ENNReal.ofReal EV := h1\n have h4 : 2 * P Aᶜ ≤ 1 :=\n (ENNReal.mul_le_mul_left hEVne ENNReal.ofReal_ne_top).1 h3\n calc P Aᶜ = 1 * P Aᶜ := (one_mul _).symm\n _ = (2 * 2⁻¹) * P Aᶜ := by\n rw [ENNReal.mul_inv_cancel two_ne_zero (by norm_num)]\n _ = 2⁻¹ * (2 * P Aᶜ) := by ring\n _ ≤ 2⁻¹ * 1 := mul_le_mul_left' h4 _\n _ = 2⁻¹ := mul_one _\n have hPA : (2:ℝ≥0∞)⁻¹ ≤ P A := by\n have hsum : P A + P Aᶜ = 1 := by\n rw [measure_add_measure_compl hAmeas, measure_univ]\n by_contra hcon\n push_neg at hcon\n have h1 : P A + P Aᶜ < 2⁻¹ + P Aᶜ :=\n ENNReal.add_lt_add_right (measure_ne_top P Aᶜ) hcon\n have h2 : (2:ℝ≥0∞)⁻¹ + P Aᶜ ≤ 2⁻¹ + 2⁻¹ := add_le_add (le_refl _) hPAc\n have h3 : (2:ℝ≥0∞)⁻¹ + 2⁻¹ = 1 := by\n rw [← two_mul]\n exact ENNReal.mul_inv_cancel two_ne_zero (by norm_num)\n have : (1:ℝ≥0∞) < 1 := by\n calc (1:ℝ≥0∞) = P A + P Aᶜ := hsum.symm\n _ < 2⁻¹ + P Aᶜ := h1\n _ ≤ 2⁻¹ + 2⁻¹ := h2\n _ = 1 := h3\n exact lt_irrefl _ this\n -- the good set S\n set S : Set (Fin n → X) := {x | V x ≤ 4 * EV + (b - a)^2 * t} with hSdef\n have hSmeas : MeasurableSet S := measurableSet_le hVmeas measurable_const\n set hfn : (Fin n → X) → ℝ≥0∞ := Sᶜ.indicator (fun _ => ENNReal.ofReal ((2:ℝ)^t)) with hfndef\n have hfnmeas : Measurable hfn := measurable_const.indicator hSmeas.compl\n have hdom : ∀ x : Fin n → X, ∀ y ∈ A, ∀ z ∈ A, ∀ s : Finset (Fin n),\n (∀ i, i ∉ s → x i = y i ∨ x i = z i) → hfn x ≤ 2 ^ s.card := by\n intro x y hy z hz s hcond\n by_cases hx : x ∈ S\n · have hz0 : hfn x = 0 := by\n rw [hfndef]\n simp [hx]\n rw [hz0]; exact zero_le _\n · have hVx : 4 * EV + (b - a)^2 * t < V x := by\n simp only [hSdef, Set.mem_setOf_eq, not_le] at hx\n exact hx\n have hle := K1 x y z s hcond\n have hy2 : V y ≤ 2 * EV := hy\n have hz2 : V z ≤ 2 * EV := hz\n have hkey : (b - a)^2 * t < (s.card : ℝ) * (b - a)^2 := by linarith\n have hba : 0 < (b - a)^2 := by\n rcases (sq_nonneg (b - a)).lt_or_eq with hlt | heq\n · exact hlt\n · exfalso; rw [← heq] at hkey; simp at hkey\n have htcard : t < (s.card : ℝ) := by\n refine lt_of_mul_lt_mul_left ?_ (le_of_lt hba)\n calc (b - a)^2 * t < (s.card : ℝ) * (b - a)^2 := hkey\n _ = (b - a)^2 * (s.card : ℝ) := by ring\n have hpow : (2:ℝ)^t ≤ (2:ℝ)^(s.card) := by\n have hh := (Real.rpow_le_rpow_left_iff (x := 2) (by norm_num)).2 htcard.le\n rwa [Real.rpow_natCast] at hh\n have hfx : hfn x = ENNReal.ofReal ((2:ℝ)^t) := by\n rw [hfndef]\n simp [hx]\n rw [hfx]\n calc ENNReal.ofReal ((2:ℝ)^t) ≤ ENNReal.ofReal ((2:ℝ)^(s.card)) :=\n ENNReal.ofReal_le_ofReal hpow\n _ = 2 ^ s.card := by\n rw [ENNReal.ofReal_pow (by norm_num)]\n norm_num\n have hTal := talagrand2 μ n A A hAmeas hAmeas hfn hfnmeas hdom\n rw [← hPdef] at hTal\n have hlint : ∫⁻ x, hfn x ∂P = ENNReal.ofReal ((2:ℝ)^t) * P Sᶜ := by\n rw [hfndef, lintegral_indicator hSmeas.compl, setLIntegral_const]\n rw [hlint] at hTal\n -- deduce ofReal (2^t) * P Sᶜ ≤ 4\n have hZ : ENNReal.ofReal ((2:ℝ)^t) * P Sᶜ ≤ 4 := by\n set Z := ENNReal.ofReal ((2:ℝ)^t) * P Sᶜ with hZdef\n have h1 : Z * 2⁻¹ * 2⁻¹ ≤ Z * P A * P A :=\n mul_le_mul' (mul_le_mul' (le_refl Z) hPA) hPA\n have h2 : Z * 2⁻¹ * 2⁻¹ ≤ 1 := le_trans h1 hTal\n have hcancel : (4:ℝ≥0∞) * (2⁻¹ * 2⁻¹) = 1 := by\n have hh : (2:ℝ≥0∞) * 2⁻¹ = 1 := ENNReal.mul_inv_cancel two_ne_zero (by norm_num)\n calc (4:ℝ≥0∞) * (2⁻¹ * 2⁻¹) = (2 * 2⁻¹) * (2 * 2⁻¹) := by\n rw [show (4:ℝ≥0∞) = 2 * 2 by norm_num]; ring\n _ = 1 := by rw [hh]; norm_num\n calc Z = Z * ((4:ℝ≥0∞) * (2⁻¹ * 2⁻¹)) := by rw [hcancel, mul_one]\n _ = 4 * (Z * 2⁻¹ * 2⁻¹) := by ring\n _ ≤ 4 * 1 := mul_le_mul_left' h2 _\n _ = 4 := mul_one _\n -- convert to real numbers\n have h2t : (0:ℝ) < (2:ℝ)^t := Real.rpow_pos_of_pos (by norm_num) t\n have hc : (P Sᶜ).toReal ≤ 4 * (2:ℝ)^(-t) := by\n have hh := ENNReal.toReal_mono (by norm_num) hZ\n rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal h2t.le] at hh\n have hh4 : ((4:ℝ≥0∞)).toReal = (4:ℝ) := by norm_num\n rw [hh4] at hh\n rw [Real.rpow_neg (by norm_num), ← div_eq_mul_inv, le_div_iff₀ h2t]\n linarith [hh]\n have hSsum : (P S).toReal + (P Sᶜ).toReal = 1 := by\n have hh : P S + P Sᶜ = 1 := by rw [measure_add_measure_compl hSmeas, measure_univ]\n calc (P S).toReal + (P Sᶜ).toReal\n = (P S + P Sᶜ).toReal :=\n (ENNReal.toReal_add (measure_ne_top _ _) (measure_ne_top _ _)).symm\n _ = (1:ℝ≥0∞).toReal := by rw [hh]\n _ = 1 := ENNReal.toReal_one\n linarith\n\nend GraduateLevel\n"} +{"id": "ch4_theorem_4_17", "source": "Graduate-level", "targets": [{"label": "ch4_theorem_4_17", "decls": ["ch4_theorem_4_17"], "statement": "If \\(\\mathcal{F}\\) is a function class from \\(Z \\mapsto \\mathbb{R}\\), then\n\\[\nR_S(\\mathcal{F}) \\leq 12\\int_{0}^{\\infty}\\sqrt{\\frac{\\log N(\\epsilon, \\mathcal{F}, L_2(P_n))}{n}}\\,d\\epsilon.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Let \\(\\epsilon_0 = \\sup_{f\\in \\mathcal{F}} \\max_i |f(z_i)|\\), so that for all \\(v \\in \\mathcal{Q}\\),\n\\[\n\\epsilon_0 \\ge \\sqrt{\\frac{1}{n} \\sum_{i=1}^n f(z_i)^2} = \\sqrt{\\frac{1}{n} \\|v\\|_2^2}.\n\\]\n\nDefine \\(\\epsilon_j = 2^{-j}\\epsilon_0\\) and let \\(\\mathcal{C}_j\\) be an \\(\\epsilon_j\\)-cover of \\(\\mathcal{Q}\\). Then \\(\\mathcal{C}_0\\) is the coarsest cover of \\(\\mathcal{Q}\\), and as \\(j\\) increases we obtain progressively more fine-grained covers \\(\\mathcal{C}_j\\). We next use this sequence of covers to define a telescoping series that equals \\(v\\).\n\nFor \\(v \\in \\mathcal{Q}\\), let \\(u_i\\) denote the nearest neighbor of \\(v\\) in \\(\\mathcal{C}_i\\). Note that by definition \\(\\rho(u, v_j) \\leq \\epsilon_j\\). Taking \\(u_0 = 0\\), it follows that as \\(j \\to \\infty\\), \\(\\epsilon_j \\to 0\\) and \\(u_j \\to v\\). Thus,\n\\[\nv = (u_1 - u_0) + (u_2 - u_1) + (u_3 - u_2) + \\cdots = \\sum_{i=1}^\\infty (u_i - u_{i-1}).\n\\]\n\nSubstituting this telescoping expansion into the Rademacher complexity,\n\\[\n\\mathbb{E}\\left[\\sup_{v \\in \\mathcal{Q}} \\frac{1}{n} \\langle v, \\sigma \\rangle\\right] = \\mathbb{E}\\left[\\sup_{v \\in \\mathcal{Q}} \\frac{1}{n} \\sum_{i=1}^\\infty \\langle u_i - u_{i-1}, \\sigma \\rangle\\right] \\le \\sum_{i=1}^\\infty \\mathbb{E}\\left[ \\sup_{u_i \\in \\mathcal{C}_i,\\, u_{i-1} \\in \\mathcal{C}_{i-1}} \\frac{1}{n}\\langle u_i - u_{i-1}, \\sigma \\rangle\\right].\n\\]\n\nEach term is a Rademacher complexity over the finite space \\(\\mathcal{C}_i \\times \\mathcal{C}_{i-1}\\), so we apply Massart's lemma (the referenced result). We first bound \\(\\frac{1}{\\sqrt{n}} \\|u_i - u_{i-1}\\|_2\\):\n\\[\n\\frac{1}{\\sqrt{n}} \\|u_i - u_{i-1}\\|_2 \\le \\frac{1}{\\sqrt{n}} \\left(\\|u_i - v\\|_2 + \\|u_{i-1} - v\\|_2\\right) \\le \\epsilon_i + \\epsilon_{i-1} = 3\\epsilon_i,\n\\]\nsince \\(\\epsilon_{i-1} = 2\\epsilon_i\\). Applying Massart's lemma with \\(M = 3\\epsilon_i\\) and \\(|\\mathcal{Q}| = |\\mathcal{C}_i \\times \\mathcal{C}_{i-1}| \\leq |\\mathcal{C}_i| \\cdot |\\mathcal{C}_{i-1}|\\),\n\\[\n\\mathbb{E}\\left[\\sup_{u_i \\in \\mathcal{C}_i,\\, u_{i-1} \\in \\mathcal{C}_{i-1}} \\frac{1}{n} \\langle u_i - u_{i-1}, \\sigma \\rangle \\right] \\le \\sqrt{\\frac{2(3\\epsilon_i)^2 \\log(|\\mathcal{C}_i| \\cdot |\\mathcal{C}_{i-1}|)}{n}} \\le \\frac{6\\epsilon_i}{\\sqrt{n}}\\sqrt{\\log |\\mathcal{C}_i|},\n\\]\nusing \\(|\\mathcal{C}_i| \\ge |\\mathcal{C}_{i-1}|\\). Thus,\n\\[\n\\mathbb{E}\\left[\\sup_{v \\in \\mathcal{Q}} \\frac{1}{n} \\langle v, \\sigma \\rangle \\right] \\le \\sum_{i=1}^\\infty \\frac{6\\epsilon_i}{\\sqrt{n}}\\sqrt{\\log N(\\epsilon_i, \\mathcal{F}, L_2(P_n))}.\n\\]\n\nTo relate this sum to the integral, note that \\(\\epsilon_i - \\epsilon_{i+1} = \\frac{\\epsilon_i}{2}\\) and that \\(\\log N(\\epsilon, \\mathcal{F}, L_2(P_n))\\) is monotone decreasing in \\(\\epsilon\\), so the right Riemann sum underestimates the integral:\n\\[\n(\\epsilon_i - \\epsilon_{i+1}) \\sqrt{\\log |\\mathcal{C}_i|} \\leq \\int_{\\epsilon_{i+1}}^{\\epsilon_i} \\sqrt{\\log N(\\epsilon, \\mathcal{F}, L_2(P_n))}\\,d\\epsilon.\n\\]\nTherefore,\n\\[\n\\sum_{i=1}^\\infty \\frac{6\\epsilon_i}{\\sqrt{n}}\\sqrt{\\log N(\\epsilon_i, \\mathcal{F}, L_2(P_n))} = \\frac{12}{\\sqrt{n}} \\sum_{i=1}^\\infty (\\epsilon_i - \\epsilon_{i+1}) \\sqrt{\\log N(\\epsilon_i, \\mathcal{F}, L_2(P_n))} \\leq \\frac{12}{\\sqrt{n}} \\int_{0}^{\\epsilon_0} \\sqrt{\\log N(\\epsilon, \\mathcal{F}, L_2(P_n))}\\,d\\epsilon.\n\\]\nSince \\(\\log N(\\epsilon, \\mathcal{F}, L_2(P_n)) = 0\\) for all \\(\\epsilon > \\epsilon_0\\), we extend the upper limit to \\(\\infty\\) and obtain\n\\[\n\\mathbb{E}\\left[\\sup_{v \\in \\mathcal{Q}} \\frac{1}{n} \\langle v, \\sigma \\rangle \\right] \\le \\frac{12}{\\sqrt{n}} \\int_{0}^\\infty \\sqrt{\\log N(\\epsilon, \\mathcal{F}, L_2(P_n))}\\,d\\epsilon = 12\\int_{0}^{\\infty}\\sqrt{\\frac{\\log N(\\epsilon, \\mathcal{F}, L_2(P_n))}{n}}\\,d\\epsilon.\n\\]", "context": [{"id": "ch4:definition:4_8", "name": "Empirical Rademacher complexity", "statement": "Given a dataset \\(S = \\{z_1, \\dots, z_n\\}\\), the empirical Rademacher complexity is defined as\n\\[\nR_S(\\mathcal{F}) \\stackrel{\\Delta}{=} \\mathbb{E}_{\\sigma_1,\\dots, \\sigma_n} \\left[ \\sup_{f\\in \\mathcal{F}} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i) \\right].\n\\]\n\\(R_S(\\mathcal{F})\\) is a function of both the function class \\(\\mathcal{F}\\) and the dataset \\(S\\)."}, {"id": "ch4:definition:4_14", "name": "definition 4.14", "statement": "\\(\\mathcal{C}\\) is an \\(\\epsilon\\)-cover of \\(\\mathcal{Q}\\) with respect to metric \\(\\rho\\) if for all \\(v' \\in \\mathcal{Q}\\), there exists \\(v \\in \\mathcal{C}\\) such that \\(\\rho(v,v')\\le \\epsilon\\)."}, {"id": "ch4:definition:4_15", "name": "definition 4.15", "statement": "The covering number is defined as the minimum size of an \\(\\epsilon\\)-cover, or explicitly:\n\\[\nN(\\epsilon, \\mathcal{Q}, \\rho) \\stackrel{\\Delta}{=} (\\text{min size of } \\epsilon\\text{-cover of } \\mathcal{Q} \\text{ w.r.t. metric } \\rho).\n\\]"}, {"id": "ch4:proposition:4_12", "name": "proposition 4.12", "statement": "Let \\(\\mathcal{F}\\) be a collection of functions mapping \\(Z \\mapsto \\mathbb{R}\\) and let \\(\\mathcal{Q}\\) be defined as in the referenced equation. Assume that \\(\\frac{1}{\\sqrt{n}} \\|v\\|_2 \\le M < \\infty\\) for all \\(v \\in \\mathcal{Q}\\). Then,\n\\[\nR_S(\\mathcal{F}) \\leq \\sqrt{\\frac{2 M^2 \\log |\\mathcal{Q}|}{n}}.\n\\]"}, {"id": "ch4_theorem_4_17:fix:1", "name": "Output space \\(\\mathcal{Q}\\) and the \\(L_2(P_n)\\) metric", "statement": "Given a dataset \\(S = \\{z_1, \\dots, z_n\\}\\), define the output space\n\\[\n\\mathcal{Q} \\triangleq \\left\\{ \\left(f(z_1), \\dots, f(z_n)\\right)^\\top : f \\in \\mathcal{F} \\right\\} \\subseteq \\mathbb{R}^n.\n\\]\nCorrespondingly, the empirical Rademacher complexity can be rewritten as a maximization over the output space \\(\\mathcal{Q}\\) instead of the function space \\(\\mathcal{F}\\):\n\\[\nR_S(\\mathcal{F}) = \\mathbb{E}_{\\sigma}\\left[ \\sup_{v \\in \\mathcal{Q}} \\frac{1}{n} \\langle \\sigma, v \\rangle \\right].\n\\]\nWe use the metric \\(\\rho(v, v') = \\frac{1}{\\sqrt{n}} \\|v - v'\\|_2\\). In the literature, an \\(\\epsilon\\)-cover of \\(\\mathcal{Q}\\) with respect to \\(\\rho\\) is also referred to as an \\(\\epsilon\\)-cover of the function class \\(\\mathcal{F}\\) under the \\(L_2(P_n)\\) metric, where \\(P_n\\) denotes the empirical distribution, i.e. the uniform distribution over the observations \\(z_1, \\dots, z_n\\). In particular,\n\\[\nL_2(P_n)(f, f') = \\sqrt{\\frac{1}{n} \\sum_{i=1}^n (f(z_i) - f'(z_i))^2}.\n\\]\nWe can write a trivial correspondence between both the output and function class points of view as follows:\n\\[\nN(\\epsilon, \\mathcal{F}, L_2(P_n)) = N\\left(\\epsilon, \\mathcal{Q}, \\frac{1}{\\sqrt{n}} \\|\\cdot\\|_2\\right).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def empiricalNorm (n : ℕ) (f : Fin n → ℝ) : ℝ :=\n Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, f k ^ 2)\n\nlemma empiricalNorm_nonneg (n : ℕ) (f : Fin n → ℝ) : 0 ≤ empiricalNorm n f :=\n Real.sqrt_nonneg _\n\nlemma empiricalNorm_zero (n : ℕ) : empiricalNorm n (0 : Fin n → ℝ) = 0 := by\n unfold empiricalNorm; simp\n\nlemma empiricalNorm_neg (n : ℕ) (f : Fin n → ℝ) : empiricalNorm n (-f) = empiricalNorm n f := by\n unfold empiricalNorm\n congr 2\n apply Finset.sum_congr rfl\n intro i _\n simp only [Pi.neg_apply, neg_sq]\n\ndef EmpiricalSpace (n : ℕ) := Fin n → ℝ\n\nnamespace EmpiricalSpace\n\ninstance (n : ℕ) : Inhabited (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Zero (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Add (EmpiricalSpace n) := ⟨fun a b i => a i + b i⟩\ninstance (n : ℕ) : Sub (EmpiricalSpace n) := ⟨fun a b i => a i - b i⟩\ninstance (n : ℕ) : Neg (EmpiricalSpace n) := ⟨fun a i => -a i⟩\n\nnoncomputable instance instDist (n : ℕ) : Dist (EmpiricalSpace n) where\n dist a b := empiricalNorm n (a - b)\n\nnoncomputable instance instEDist (n : ℕ) : EDist (EmpiricalSpace n) where\n edist a b := ENNReal.ofReal (dist a b)\n\nlemma dist_self (n : ℕ) (a : EmpiricalSpace n) : dist a a = 0 := by\n show empiricalNorm n (a - a) = 0\n have h : (a - a : EmpiricalSpace n) = 0 := by\n funext i\n show a i - a i = (0 : Fin n → ℝ) i\n simp\n rw [h]\n exact empiricalNorm_zero n\n\nlemma dist_comm (n : ℕ) (a b : EmpiricalSpace n) : dist a b = dist b a := by\n show empiricalNorm n (a - b) = empiricalNorm n (b - a)\n have h : (a - b : EmpiricalSpace n) = -(b - a) := by\n funext i\n show a i - b i = -(b i - a i)\n ring\n rw [h]\n exact empiricalNorm_neg n _\n\nlemma dist_triangle (n : ℕ) (a b c : EmpiricalSpace n) :\n dist a c ≤ dist a b + dist b c := by\n show empiricalNorm n (a - c) ≤ empiricalNorm n (a - b) + empiricalNorm n (b - c)\n unfold empiricalNorm\n have eq_ac : ∀ k, (a - c : EmpiricalSpace n) k = a k - c k := fun k => rfl\n have eq_ab : ∀ k, (a - b : EmpiricalSpace n) k = a k - b k := fun k => rfl\n have eq_bc : ∀ k, (b - c : EmpiricalSpace n) k = b k - c k := fun k => rfl\n simp_rw [eq_ac, eq_ab, eq_bc]\n by_cases hn : n = 0\n · simp [hn]\n have hn_pos : (0 : ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)\n have hn_inv_nonneg : 0 ≤ (n : ℝ)⁻¹ := inv_nonneg.mpr (le_of_lt hn_pos)\n have h_factor : ∀ f : Fin n → ℝ, Real.sqrt ((n : ℝ)⁻¹ * ∑ i, (f i)^2) =\n Real.sqrt (n : ℝ)⁻¹ * Real.sqrt (∑ i, (f i)^2) := fun f => by\n rw [Real.sqrt_mul hn_inv_nonneg]\n rw [h_factor (fun i => a i - c i), h_factor (fun i => a i - b i),\n h_factor (fun i => b i - c i), ← mul_add]\n apply mul_le_mul_of_nonneg_left _ (Real.sqrt_nonneg _)\n let e := EuclideanSpace.equiv (Fin n) ℝ\n let a' : EuclideanSpace ℝ (Fin n) := e.symm a\n let b' : EuclideanSpace ℝ (Fin n) := e.symm b\n let c' : EuclideanSpace ℝ (Fin n) := e.symm c\n have h_a' : ∀ i, a' i = a i := fun i => rfl\n have h_b' : ∀ i, b' i = b i := fun i => rfl\n have h_c' : ∀ i, c' i = c i := fun i => rfl\n have h_norm : ∀ (x y : EuclideanSpace ℝ (Fin n)),\n Real.sqrt (∑ i, (x i - y i)^2) = ‖x - y‖ := fun x y => by\n rw [EuclideanSpace.norm_eq]\n congr 1\n apply Finset.sum_congr rfl\n intro i _\n rw [Real.norm_eq_abs, sq_abs]\n rfl\n simp only [← h_a', ← h_b', ← h_c']\n rw [h_norm a' c', h_norm a' b', h_norm b' c']\n have h_eq : a' - c' = (a' - b') + (b' - c') := (sub_add_sub_cancel a' b' c').symm\n rw [h_eq]\n exact norm_add_le (a' - b') (b' - c')\n\nlemma edist_dist (n : ℕ) (a b : EmpiricalSpace n) :\n edist a b = ENNReal.ofReal (dist a b) := rfl\n\nnoncomputable instance instPseudoMetricSpace (n : ℕ) : PseudoMetricSpace (EmpiricalSpace n) where\n dist_self := dist_self n\n dist_comm := dist_comm n\n dist_triangle := dist_triangle n\n edist_dist := edist_dist n\n\nend EmpiricalSpace\n\ndef empiricalMetricImage {X : Type*} (n : ℕ) (x : Fin n → X) (g : X → ℝ) : EmpiricalSpace n :=\n fun i => g (x i)\n\ndef IsENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop ℕ :=\n sInf {n | ∃ t, IsENet t eps s ∧ (t.card : WithTop ℕ) = n}\n\ndef Signs (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (Signs n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empiricalRademacherComplexity_without_abs {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ntheorem ch4_theorem_4_17\n {ι : Type*} [Nonempty ι] {𝒳 : Type*}\n (n : ℕ) (hn : 0 < n)\n (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳)\n (s : Set (EmpiricalSpace n))\n (hs : s = Set.range (fun i => empiricalMetricImage n S (f i)))\n (hcov : ∀ ε ∈ Set.Ioi (0 : ℝ), coveringNumber ε s ≠ ⊤)\n (hint : MeasureTheory.IntegrableOn\n (fun ε : ℝ =>\n Real.sqrt\n (Real.log (((coveringNumber ε s).untopD 0 : ℕ) : ℝ)\n / (n : ℝ)))\n (Set.Ioi 0)) :\n empiricalRademacherComplexity_without_abs n f S ≤\n 12 *\n ∫ ε in Set.Ioi (0 : ℝ),\n Real.sqrt\n (Real.log (((coveringNumber ε s).untopD 0 : ℕ) : ℝ)\n / (n : ℝ)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def empiricalNorm (n : ℕ) (f : Fin n → ℝ) : ℝ :=\n Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, f k ^ 2)\n\nlemma empiricalNorm_nonneg (n : ℕ) (f : Fin n → ℝ) : 0 ≤ empiricalNorm n f :=\n Real.sqrt_nonneg _\n\nlemma empiricalNorm_zero (n : ℕ) : empiricalNorm n (0 : Fin n → ℝ) = 0 := by\n unfold empiricalNorm; simp\n\nlemma empiricalNorm_neg (n : ℕ) (f : Fin n → ℝ) : empiricalNorm n (-f) = empiricalNorm n f := by\n unfold empiricalNorm\n congr 2\n apply Finset.sum_congr rfl\n intro i _\n simp only [Pi.neg_apply, neg_sq]\n\ndef EmpiricalSpace (n : ℕ) := Fin n → ℝ\n\nnamespace EmpiricalSpace\n\ninstance (n : ℕ) : Inhabited (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Zero (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Add (EmpiricalSpace n) := ⟨fun a b i => a i + b i⟩\ninstance (n : ℕ) : Sub (EmpiricalSpace n) := ⟨fun a b i => a i - b i⟩\ninstance (n : ℕ) : Neg (EmpiricalSpace n) := ⟨fun a i => -a i⟩\n\nnoncomputable instance instDist (n : ℕ) : Dist (EmpiricalSpace n) where\n dist a b := empiricalNorm n (a - b)\n\nnoncomputable instance instEDist (n : ℕ) : EDist (EmpiricalSpace n) where\n edist a b := ENNReal.ofReal (dist a b)\n\nlemma dist_self (n : ℕ) (a : EmpiricalSpace n) : dist a a = 0 := by\n show empiricalNorm n (a - a) = 0\n have h : (a - a : EmpiricalSpace n) = 0 := by\n funext i\n show a i - a i = (0 : Fin n → ℝ) i\n simp\n rw [h]\n exact empiricalNorm_zero n\n\nlemma dist_comm (n : ℕ) (a b : EmpiricalSpace n) : dist a b = dist b a := by\n show empiricalNorm n (a - b) = empiricalNorm n (b - a)\n have h : (a - b : EmpiricalSpace n) = -(b - a) := by\n funext i\n show a i - b i = -(b i - a i)\n ring\n rw [h]\n exact empiricalNorm_neg n _\n\nlemma dist_triangle (n : ℕ) (a b c : EmpiricalSpace n) :\n dist a c ≤ dist a b + dist b c := by\n show empiricalNorm n (a - c) ≤ empiricalNorm n (a - b) + empiricalNorm n (b - c)\n unfold empiricalNorm\n have eq_ac : ∀ k, (a - c : EmpiricalSpace n) k = a k - c k := fun k => rfl\n have eq_ab : ∀ k, (a - b : EmpiricalSpace n) k = a k - b k := fun k => rfl\n have eq_bc : ∀ k, (b - c : EmpiricalSpace n) k = b k - c k := fun k => rfl\n simp_rw [eq_ac, eq_ab, eq_bc]\n by_cases hn : n = 0\n · simp [hn]\n have hn_pos : (0 : ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)\n have hn_inv_nonneg : 0 ≤ (n : ℝ)⁻¹ := inv_nonneg.mpr (le_of_lt hn_pos)\n have h_factor : ∀ f : Fin n → ℝ, Real.sqrt ((n : ℝ)⁻¹ * ∑ i, (f i)^2) =\n Real.sqrt (n : ℝ)⁻¹ * Real.sqrt (∑ i, (f i)^2) := fun f => by\n rw [Real.sqrt_mul hn_inv_nonneg]\n rw [h_factor (fun i => a i - c i), h_factor (fun i => a i - b i),\n h_factor (fun i => b i - c i), ← mul_add]\n apply mul_le_mul_of_nonneg_left _ (Real.sqrt_nonneg _)\n let e := EuclideanSpace.equiv (Fin n) ℝ\n let a' : EuclideanSpace ℝ (Fin n) := e.symm a\n let b' : EuclideanSpace ℝ (Fin n) := e.symm b\n let c' : EuclideanSpace ℝ (Fin n) := e.symm c\n have h_a' : ∀ i, a' i = a i := fun i => rfl\n have h_b' : ∀ i, b' i = b i := fun i => rfl\n have h_c' : ∀ i, c' i = c i := fun i => rfl\n have h_norm : ∀ (x y : EuclideanSpace ℝ (Fin n)),\n Real.sqrt (∑ i, (x i - y i)^2) = ‖x - y‖ := fun x y => by\n rw [EuclideanSpace.norm_eq]\n congr 1\n apply Finset.sum_congr rfl\n intro i _\n rw [Real.norm_eq_abs, sq_abs]\n rfl\n simp only [← h_a', ← h_b', ← h_c']\n rw [h_norm a' c', h_norm a' b', h_norm b' c']\n have h_eq : a' - c' = (a' - b') + (b' - c') := (sub_add_sub_cancel a' b' c').symm\n rw [h_eq]\n exact norm_add_le (a' - b') (b' - c')\n\nlemma edist_dist (n : ℕ) (a b : EmpiricalSpace n) :\n edist a b = ENNReal.ofReal (dist a b) := rfl\n\nnoncomputable instance instPseudoMetricSpace (n : ℕ) : PseudoMetricSpace (EmpiricalSpace n) where\n dist_self := dist_self n\n dist_comm := dist_comm n\n dist_triangle := dist_triangle n\n edist_dist := edist_dist n\n\nend EmpiricalSpace\n\ndef empiricalMetricImage {X : Type*} (n : ℕ) (x : Fin n → X) (g : X → ℝ) : EmpiricalSpace n :=\n fun i => g (x i)\n\ndef IsENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop ℕ :=\n sInf {n | ∃ t, IsENet t eps s ∧ (t.card : WithTop ℕ) = n}\n\ndef Signs (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (Signs n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empiricalRademacherComplexity_without_abs {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nsection MassartTools\n\nlemma card_signs (n : ℕ) : Fintype.card (Signs n) = 2 ^ n := by\n show Fintype.card (Fin n → ({-1, 1} : Finset ℤ)) = 2 ^ n\n rw [Fintype.card_fun, Fintype.card_coe, Fintype.card_fin]\n norm_num\n\nlemma sum_signs_prod (n : ℕ) (g : Fin n → ℤ → ℝ) :\n ∑ σ : Signs n, ∏ k : Fin n, g k (σ k) = ∏ k : Fin n, (g k (-1) + g k 1) := by\n have h1 : ∀ k : Fin n, (g k (-1) + g k 1) = ∑ j : ({-1,1} : Finset ℤ), g k j := by\n intro k\n rw [Finset.univ_eq_attach, Finset.sum_attach ({-1,1} : Finset ℤ) (fun b => g k b)]\n rw [Finset.sum_pair (by norm_num : (-1 : ℤ) ≠ 1)]\n rw [Finset.prod_congr rfl (fun k (_ : k ∈ Finset.univ) => h1 k)]\n rw [Fintype.prod_sum (fun (k : Fin n) (b : ({-1,1} : Finset ℤ)) => g k b)]\n exact Fintype.sum_equiv (Equiv.refl (Signs n)) _ _ (fun x => rfl)\n\nlemma mgf_bound (n : ℕ) (v : Fin n → ℝ) (lam : ℝ) :\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, Real.exp (lam * ∑ k : Fin n, (σ k : ℝ) * v k)\n ≤ Real.exp (lam ^ 2 * (∑ k : Fin n, (v k) ^ 2) / 2) := by\n have hstep : ∀ σ : Signs n, Real.exp (lam * ∑ k : Fin n, (σ k : ℝ) * v k)\n = ∏ k : Fin n, Real.exp (lam * (((σ k : ℤ) : ℝ) * v k)) := by\n intro σ\n rw [Finset.mul_sum, Real.exp_sum]\n rw [Finset.sum_congr rfl (fun σ (_ : σ ∈ Finset.univ) => hstep σ)]\n rw [sum_signs_prod n (fun k b => Real.exp (lam * ((b : ℝ) * v k)))]\n have h2 : ∀ k : Fin n,\n Real.exp (lam * (((-1 : ℤ) : ℝ) * v k)) + Real.exp (lam * (((1 : ℤ) : ℝ) * v k))\n = 2 * Real.cosh (lam * v k) := by\n intro k\n rw [Real.cosh_eq]\n push_cast\n ring_nf\n rw [Finset.prod_congr rfl (fun k (_ : k ∈ Finset.univ) => h2 k)]\n rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin]\n rw [card_signs]\n rw [← mul_assoc]\n have : ((2:ℝ) ^ n)⁻¹ * (2:ℝ) ^ n = 1 := by\n field_simp\n rw [show ((2 ^ n : ℕ) : ℝ) = (2:ℝ)^n by push_cast; ring, this, one_mul]\n calc ∏ k : Fin n, Real.cosh (lam * v k)\n ≤ ∏ k : Fin n, Real.exp ((lam * v k) ^ 2 / 2) := by\n apply Finset.prod_le_prod\n · intro i _; positivity\n · intro i _; exact Real.cosh_le_exp_half_sq _\n _ = Real.exp (lam ^ 2 * (∑ k : Fin n, (v k) ^ 2) / 2) := by\n rw [← Real.exp_sum]\n congr 1\n rw [Finset.mul_sum, Finset.sum_div]\n apply Finset.sum_congr rfl\n intro i _\n ring\n\n\ninstance instNonemptySigns (n : ℕ) : Nonempty (Signs n) := ⟨fun _ => ⟨1, by decide⟩⟩\n\nlemma exp_avg_le {α : Type*} [Fintype α] [Nonempty α] (Y : α → ℝ) :\n Real.exp ((Fintype.card α : ℝ)⁻¹ * ∑ a, Y a)\n ≤ (Fintype.card α : ℝ)⁻¹ * ∑ a, Real.exp (Y a) := by\n have hNpos : (0:ℝ) < (Fintype.card α : ℝ) := by exact_mod_cast Fintype.card_pos\n set N : ℝ := (Fintype.card α : ℝ) with hN\n set m : ℝ := N⁻¹ * ∑ a, Y a with hm\n have hYsum : ∑ a, Y a = N * m := by\n rw [hm, ← mul_assoc, mul_inv_cancel₀ (ne_of_gt hNpos), one_mul]\n have key : ∀ a ∈ (Finset.univ : Finset α),\n Real.exp m * ((Y a - m) + 1) ≤ Real.exp (Y a) := by\n intro a _\n have h1 : Real.exp m * Real.exp (Y a - m) = Real.exp (Y a) := by\n rw [← Real.exp_add]; ring_nf\n rw [← h1]\n exact mul_le_mul_of_nonneg_left (Real.add_one_le_exp _) (Real.exp_pos m).le\n have hsum : Real.exp m * N ≤ ∑ a, Real.exp (Y a) := by\n refine le_trans (le_of_eq ?_) (Finset.sum_le_sum key)\n rw [← Finset.mul_sum]\n congr 1\n rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, Finset.sum_const, Finset.sum_const,\n Finset.card_univ, nsmul_eq_mul, nsmul_eq_mul, hYsum, ← hN]\n ring\n calc Real.exp m = N⁻¹ * (Real.exp m * N) := by field_simp\n _ ≤ N⁻¹ * ∑ a, Real.exp (Y a) := mul_le_mul_of_nonneg_left hsum (by positivity)\n\nlemma massart_lam {α : Type*} (n : ℕ) (T : Finset α) (hT : T.Nonempty)\n (v : α → Fin n → ℝ) (B : ℝ)\n (hbd : ∀ a ∈ T, ∑ k : Fin n, (v a k) ^ 2 ≤ B)\n (lam : ℝ) (hlam : 0 < lam) :\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, T.sup' hT (fun a => ∑ k : Fin n, (σ k : ℝ) * v a k)\n ≤ Real.log (T.card) / lam + lam * B / 2 := by\n have hBnn : 0 ≤ B := by\n obtain ⟨a, ha⟩ := hT\n exact le_trans (Finset.sum_nonneg (fun k _ => sq_nonneg _)) (hbd a ha)\n set W : Signs n → ℝ := fun σ => T.sup' hT (fun a => ∑ k : Fin n, (σ k : ℝ) * v a k) with hW\n set A : ℝ := (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, W σ with hA\n have step1 : Real.exp (lam * A) ≤\n (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, Real.exp (lam * W σ) := by\n have h : lam * A = (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, (lam * W σ) := by\n rw [hA, ← Finset.mul_sum]; ring\n rw [h]\n exact exp_avg_le (fun σ => lam * W σ)\n have step2 : ∀ σ : Signs n, Real.exp (lam * W σ)\n ≤ ∑ a ∈ T, Real.exp (lam * ∑ k : Fin n, (σ k : ℝ) * v a k) := by\n intro σ\n obtain ⟨a, haT, ha⟩ := Finset.exists_mem_eq_sup' hT (fun a => ∑ k : Fin n, (σ k : ℝ) * v a k)\n rw [hW]\n simp only\n rw [ha]\n exact Finset.single_le_sum (f := fun a => Real.exp (lam * ∑ k : Fin n, (σ k : ℝ) * v a k))\n (fun i _ => (Real.exp_pos _).le) haT\n have hc : (0:ℝ) ≤ (Fintype.card (Signs n) : ℝ)⁻¹ := by positivity\n have step3 : (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, Real.exp (lam * W σ)\n ≤ (T.card : ℝ) * Real.exp (lam ^ 2 * B / 2) := by\n refine le_trans (mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun σ _ => step2 σ)) hc) ?_\n have hswap : (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, ∑ a ∈ T, Real.exp (lam * ∑ k : Fin n, (σ k : ℝ) * v a k)\n = ∑ a ∈ T, (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, Real.exp (lam * ∑ k : Fin n, (σ k : ℝ) * v a k) := by\n rw [Finset.sum_comm, Finset.mul_sum]\n rw [hswap]\n calc ∑ a ∈ T, (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, Real.exp (lam * ∑ k : Fin n, (σ k : ℝ) * v a k)\n ≤ ∑ _a ∈ T, Real.exp (lam ^ 2 * B / 2) := by\n refine Finset.sum_le_sum ?_\n intro a ha\n refine le_trans (mgf_bound n (v a) lam) (Real.exp_le_exp.mpr ?_)\n have h : lam ^ 2 * (∑ k : Fin n, (v a k) ^ 2) ≤ lam ^ 2 * B :=\n mul_le_mul_of_nonneg_left (hbd a ha) (by positivity)\n linarith\n _ = (T.card : ℝ) * Real.exp (lam ^ 2 * B / 2) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n have hcard : (0:ℝ) < (T.card : ℝ) := by\n exact_mod_cast Finset.card_pos.mpr hT\n have hfin : Real.exp (lam * A) ≤ (T.card : ℝ) * Real.exp (lam ^ 2 * B / 2) :=\n le_trans step1 step3\n have hlog : lam * A ≤ Real.log (T.card) + lam ^ 2 * B / 2 := by\n have hpos : (0:ℝ) < (T.card : ℝ) * Real.exp (lam ^ 2 * B / 2) := by positivity\n have := (Real.le_log_iff_exp_le hpos).mpr hfin\n rwa [Real.log_mul (ne_of_gt hcard) (Real.exp_ne_zero _), Real.log_exp] at this\n have hfin2 : A ≤ (Real.log (T.card) + lam ^ 2 * B / 2) / lam := by\n rw [le_div_iff₀ hlam]\n linarith [hlog]\n refine le_trans hfin2 (le_of_eq ?_)\n field_simp\n\n\nlemma massart {α : Type*} (n : ℕ) (T : Finset α) (hT : T.Nonempty)\n (v : α → Fin n → ℝ) (B : ℝ)\n (hbd : ∀ a ∈ T, ∑ k : Fin n, (v a k) ^ 2 ≤ B) :\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, T.sup' hT (fun a => ∑ k : Fin n, (σ k : ℝ) * v a k)\n ≤ Real.sqrt (2 * B * Real.log (T.card)) := by\n have hBnn : 0 ≤ B := by\n obtain ⟨a, ha⟩ := hT\n exact le_trans (Finset.sum_nonneg (fun k _ => sq_nonneg _)) (hbd a ha)\n set c : ℝ := Real.log (T.card) with hcdef\n have hcnn : 0 ≤ c := by\n rw [hcdef]\n apply Real.log_nonneg\n exact_mod_cast Finset.card_pos.mpr hT\n set LHS : ℝ := (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, T.sup' hT (fun a => ∑ k : Fin n, (σ k : ℝ) * v a k) with hLHS\n have key : ∀ lam : ℝ, 0 < lam → LHS ≤ c / lam + lam * B / 2 :=\n fun lam hlam => massart_lam n T hT v B hbd lam hlam\n rcases eq_or_lt_of_le hcnn with hc0 | hcpos\n · -- c = 0\n have hz : Real.sqrt (2 * B * c) = 0 := by rw [← hc0]; simp\n rw [hz]\n refine le_of_forall_pos_le_add ?_\n intro e he\n rcases eq_or_lt_of_le hBnn with hB0 | hBpos\n · have := key 1 (by norm_num)\n rw [← hc0, ← hB0] at this\n simpa using le_trans this (by linarith)\n · have := key (2 * e / B) (by positivity)\n rw [← hc0] at this\n have heq : (2 * e / B) * B / 2 = e := by field_simp\n rw [heq] at this\n simpa using this\n · rcases eq_or_lt_of_le hBnn with hB0 | hBpos\n · -- B = 0\n have hz : Real.sqrt (2 * B * c) = 0 := by rw [← hB0]; simp\n rw [hz]\n refine le_of_forall_pos_le_add ?_\n intro e he\n have := key (c / e + 1) (by positivity)\n rw [← hB0] at this\n have h2 : c / (c / e + 1) ≤ e := by\n rw [div_le_iff₀ (by positivity)]\n have : 0 < e := he\n field_simp\n nlinarith\n simpa using le_trans this (by linarith)\n · set lam : ℝ := Real.sqrt (2 * c / B) with hlamdef\n have hlampos : 0 < lam := Real.sqrt_pos.mpr (by positivity)\n have hlam2 : lam ^ 2 = 2 * c / B := Real.sq_sqrt (by positivity)\n have hlB : lam ^ 2 * B = 2 * c := by rw [hlam2]; field_simp\n have h1 : c / lam + lam * B / 2 = 2 * c / lam := by\n field_simp\n nlinarith [hlB]\n have h2 : Real.sqrt (2 * B * c) = 2 * c / lam := by\n have hsq : (2 * c / lam) ^ 2 = 2 * B * c := by\n rw [div_pow, hlam2]\n field_simp\n rw [← hsq, Real.sqrt_sq (by positivity)]\n rw [h2, ← h1]\n exact key lam hlampos\n\nend MassartTools\n\nsection CoverTools\n\nvariable {A : Type*} [PseudoMetricSpace A]\n\nlemma coveringNumber_le_card (eps : ℝ) (s : Set A) (t : Finset A) (ht : IsENet t eps s) :\n coveringNumber eps s ≤ (t.card : WithTop ℕ) :=\n sInf_le ⟨t, ht, rfl⟩\n\nlemma isENet_mono {t : Finset A} {a b : ℝ} (hab : a ≤ b) {s : Set A} (ht : IsENet t a s) :\n IsENet t b s := by\n intro x hx\n have := ht hx\n simp only [Set.mem_iUnion] at this ⊢\n obtain ⟨y, hy, hxy⟩ := this\n exact ⟨y, hy, le_trans hxy hab⟩\n\nlemma coveringNumber_anti (s : Set A) {a b : ℝ} (hab : a ≤ b) :\n coveringNumber b s ≤ coveringNumber a s := by\n apply sInf_le_sInf\n rintro m ⟨t, ht, hcard⟩\n exact ⟨t, isENet_mono hab ht, hcard⟩\n\nlemma exists_net_eq (eps : ℝ) (s : Set A) (h : coveringNumber eps s ≠ ⊤) :\n ∃ t : Finset A, IsENet t eps s ∧ (t.card : WithTop ℕ) = coveringNumber eps s := by\n classical\n set E' : Set ℕ := {k : ℕ | ∃ t : Finset A, IsENet t eps s ∧ t.card = k} with hE'\n have hE'ne : E'.Nonempty := by\n by_contra hno\n rw [Set.not_nonempty_iff_eq_empty] at hno\n apply h\n unfold coveringNumber\n have hemp :\n {m : WithTop ℕ | ∃ t : Finset A, IsENet t eps s ∧ (t.card : WithTop ℕ) = m} = ∅ := by\n ext m\n simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]\n rintro ⟨t, ht, -⟩\n have hmem : t.card ∈ E' := ⟨t, ht, rfl⟩\n rw [hno] at hmem\n exact hmem\n rw [hemp]\n exact sInf_empty\n obtain ⟨t, ht, htc⟩ : ∃ t : Finset A, IsENet t eps s ∧ t.card = sInf E' := Nat.sInf_mem hE'ne\n refine ⟨t, ht, ?_⟩\n rw [htc]\n refine le_antisymm ?_ ?_\n · apply le_sInf\n rintro m ⟨t', ht', rfl⟩\n have hle : sInf E' ≤ t'.card := Nat.sInf_le ⟨t', ht', rfl⟩\n exact_mod_cast hle\n · rw [← htc]\n exact coveringNumber_le_card eps s t ht\n\nlemma exists_net_card (eps : ℝ) (s : Set A) (h : coveringNumber eps s ≠ ⊤) :\n ∃ t : Finset A, IsENet t eps s ∧ t.card = (coveringNumber eps s).untopD 0 := by\n obtain ⟨t, ht, hc⟩ := exists_net_eq eps s h\n refine ⟨t, ht, ?_⟩\n rw [← hc]\n rfl\n\nlemma covering_pos (eps : ℝ) (s : Set A) (hs : s.Nonempty) (h : coveringNumber eps s ≠ ⊤) :\n 1 ≤ (coveringNumber eps s).untopD 0 := by\n obtain ⟨t, ht, hc⟩ := exists_net_card eps s h\n rw [← hc]\n have hne : t.Nonempty := by\n obtain ⟨x, hx⟩ := hs\n have hmem := ht hx\n simp only [Set.mem_iUnion] at hmem\n obtain ⟨y, hy, -⟩ := hmem\n exact ⟨y, hy⟩\n exact Finset.card_pos.mpr hne\n\nlemma covering_anti (s : Set A) {a b : ℝ} (hab : a ≤ b) (ha : coveringNumber a s ≠ ⊤) :\n (coveringNumber b s).untopD 0 ≤ (coveringNumber a s).untopD 0 :=\n WithTop.untopD_mono ha (coveringNumber_anti s hab)\n\nend CoverTools\n\nsection GeomTools\n\nlemma dist_eq_enorm (n : ℕ) (a b : EmpiricalSpace n) :\n dist a b = empiricalNorm n (fun k => a k - b k) := rfl\n\nlemma sign_sq (n : ℕ) (σ : Signs n) (k : Fin n) : ((σ k : ℤ) : ℝ) ^ 2 = 1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h <;> rw [h] <;> norm_num\n\nlemma inner_le_enorm (n : ℕ) (σ : Signs n) (w : Fin n → ℝ) :\n (n : ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ) : ℝ) * w k ≤ empiricalNorm n w := by\n rcases Nat.eq_zero_or_pos n with hn | hn\n · subst hn\n simp [empiricalNorm]\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n have hcs : ∑ k : Fin n, ((σ k : ℤ) : ℝ) * w k\n ≤ Real.sqrt (∑ k : Fin n, ((σ k : ℤ) : ℝ) ^ 2) * Real.sqrt (∑ k : Fin n, (w k) ^ 2) :=\n Real.sum_mul_le_sqrt_mul_sqrt Finset.univ _ _\n have hsum1 : ∑ k : Fin n, ((σ k : ℤ) : ℝ) ^ 2 = (n : ℝ) := by\n rw [Finset.sum_congr rfl (fun k (_ : k ∈ Finset.univ) => sign_sq n σ k)]\n simp\n rw [hsum1] at hcs\n have hstep : (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ) : ℝ) * w k\n ≤ (n:ℝ)⁻¹ * (Real.sqrt (n:ℝ) * Real.sqrt (∑ k : Fin n, (w k) ^ 2)) :=\n mul_le_mul_of_nonneg_left hcs (by positivity)\n refine le_trans hstep (le_of_eq ?_)\n unfold empiricalNorm\n rw [Real.sqrt_mul (by positivity)]\n have hsq : Real.sqrt (n:ℝ) ≠ 0 := by positivity\n rw [Real.sqrt_inv]\n field_simp\n rw [Real.sq_sqrt (le_of_lt hnR)]\n\nlemma sum_signs_coord (n : ℕ) (k : Fin n) : ∑ σ : Signs n, ((σ k : ℤ) : ℝ) = 0 := by\n have h := sum_signs_prod n (fun k' (b : ℤ) => if k' = k then (b : ℝ) else 1)\n simp only at h\n rw [show (∑ σ : Signs n, ((σ k : ℤ) : ℝ))\n = ∑ σ : Signs n, ∏ k' : Fin n, (if k' = k then ((σ k' : ℤ) : ℝ) else 1) from ?_]\n · rw [h]\n apply Finset.prod_eq_zero (Finset.mem_univ k)\n norm_num\n · apply Finset.sum_congr rfl\n intro σ _\n rw [Finset.prod_ite_eq' Finset.univ k (fun k' => ((σ k' : ℤ) : ℝ))]\n simp\n\nlemma sup'_const_mul {α : Type*} (T : Finset α) (hT : T.Nonempty) (c : ℝ) (hc : 0 ≤ c)\n (g : α → ℝ) : T.sup' hT (fun a => c * g a) = c * T.sup' hT g := by\n rcases eq_or_lt_of_le hc with hc0 | hcpos\n · rw [← hc0]\n simp\n · refine le_antisymm ?_ ?_\n · refine Finset.sup'_le _ _ ?_\n intro a ha\n exact mul_le_mul_of_nonneg_left (Finset.le_sup' g ha) hc\n · rw [← le_div_iff₀' hcpos]\n refine Finset.sup'_le _ _ ?_\n intro a ha\n rw [le_div_iff₀' hcpos]\n exact Finset.le_sup' (fun a => c * g a) ha\n\n\nlemma massart_scaled {α : Type*} (n : ℕ) (hn : 0 < n) (T : Finset α) (hT : T.Nonempty)\n (v : α → Fin n → ℝ) (M : ℝ) (hM : 0 ≤ M)\n (hbd : ∀ a ∈ T, empiricalNorm n (v a) ≤ M) :\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, T.sup' hT (fun a => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * v a k)\n ≤ M * Real.sqrt (2 * Real.log (T.card) / (n:ℝ)) := by\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n have hbd' : ∀ a ∈ T, ∑ k : Fin n, (v a k)^2 ≤ (n:ℝ) * M^2 := by\n intro a ha\n have h := hbd a ha\n unfold empiricalNorm at h\n have hX : (0:ℝ) ≤ (n:ℝ)⁻¹ * ∑ k : Fin n, (v a k)^2 := by positivity\n have hsq := Real.sq_sqrt hX\n have hnn := Real.sqrt_nonneg ((n:ℝ)⁻¹ * ∑ k : Fin n, (v a k)^2)\n have h2 : ((n:ℝ)⁻¹ * ∑ k : Fin n, (v a k)^2) ≤ M^2 := by nlinarith\n have h3 := mul_le_mul_of_nonneg_left h2 hnR.le\n rwa [← mul_assoc, mul_inv_cancel₀ (ne_of_gt hnR), one_mul] at h3\n have hpull : ∀ σ : Signs n,\n T.sup' hT (fun a => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * v a k)\n = (n:ℝ)⁻¹ * T.sup' hT (fun a => ∑ k : Fin n, ((σ k : ℤ):ℝ) * v a k) :=\n fun σ => sup'_const_mul T hT _ (by positivity) _\n rw [Finset.sum_congr rfl (fun σ (_ : σ ∈ Finset.univ) => hpull σ), ← Finset.mul_sum,\n show (Fintype.card (Signs n) : ℝ)⁻¹ * ((n:ℝ)⁻¹ *\n ∑ σ : Signs n, T.sup' hT (fun a => ∑ k : Fin n, ((σ k : ℤ):ℝ) * v a k))\n = (n:ℝ)⁻¹ * ((Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, T.sup' hT (fun a => ∑ k : Fin n, ((σ k : ℤ):ℝ) * v a k)) by ring]\n refine le_trans (mul_le_mul_of_nonneg_left (massart n T hT v ((n:ℝ) * M^2) hbd')\n (by positivity)) (le_of_eq ?_)\n set L : ℝ := Real.log (T.card) with hLdef\n have h1 : 2 * ((n:ℝ) * M^2) * L = M^2 * (2 * L * (n:ℝ)) := by ring\n have h2 : 2 * L / (n:ℝ) = ((n:ℝ)⁻¹)^2 * (2 * L * (n:ℝ)) := by\n field_simp\n rw [h1, h2, Real.sqrt_mul (sq_nonneg M), Real.sqrt_sq hM,\n Real.sqrt_mul (sq_nonneg ((n:ℝ)⁻¹)), Real.sqrt_sq (by positivity)]\n ring\n\nend GeomTools\n\nsection IntTools\n\nlemma riemann_step (g : ℝ → ℝ) (hg0 : ∀ x, 0 ≤ g x)\n (hganti : ∀ x y : ℝ, 0 < x → x ≤ y → g y ≤ g x)\n (hgint : MeasureTheory.IntegrableOn g (Set.Ioi (0:ℝ)))\n (a b : ℝ) (ha : 0 < a) (hab : a ≤ b) :\n (b - a) * g b ≤ ∫ x in Set.Ioc a b, g x := by\n have hsub : Set.Ioc a b ⊆ Set.Ioi (0:ℝ) := by\n intro x hx; exact lt_of_lt_of_le ha hx.1.le\n have hint1 : MeasureTheory.IntegrableOn g (Set.Ioc a b) := hgint.mono_set hsub\n have hint2 : MeasureTheory.IntegrableOn (fun _ : ℝ => g b) (Set.Ioc a b) := by\n refine MeasureTheory.integrableOn_const ?_\n rw [Real.volume_Ioc]\n exact ENNReal.ofReal_ne_top\n have hconst : ∫ _ in Set.Ioc a b, g b = (b - a) * g b := by\n rw [MeasureTheory.setIntegral_const, MeasureTheory.measureReal_def, Real.volume_Ioc,\n ENNReal.toReal_ofReal (by linarith), smul_eq_mul]\n rw [← hconst]\n refine MeasureTheory.setIntegral_mono_on hint2 hint1 measurableSet_Ioc ?_\n intro x hx\n exact hganti x b (lt_of_lt_of_le ha hx.1.le) hx.2\n\nlemma sum_le_integral (g : ℝ → ℝ) (hg0 : ∀ x, 0 ≤ g x)\n (hganti : ∀ x y : ℝ, 0 < x → x ≤ y → g y ≤ g x)\n (hgint : MeasureTheory.IntegrableOn g (Set.Ioi (0:ℝ)))\n (e : ℕ → ℝ) (hepos : ∀ j, 0 < e j) (hemono : ∀ j, e (j+1) ≤ e j) (J : ℕ) :\n ∑ j ∈ Finset.range J, (e (j+1) - e (j+2)) * g (e (j+1))\n ≤ ∫ x in Set.Ioc (e (J+1)) (e 1), g x := by\n have hanti : ∀ {i j : ℕ}, i ≤ j → e j ≤ e i := by\n intro i j hij\n exact antitone_nat_of_succ_le hemono hij\n induction J with\n | zero => simp\n | succ J ih =>\n rw [Finset.sum_range_succ]\n have h1 := riemann_step g hg0 hganti hgint (e (J+2)) (e (J+1)) (hepos _) (hemono (J+1))\n have hle1 : e (J+2) ≤ e (J+1) := hemono (J+1)\n have hle2 : e (J+1) ≤ e 1 := hanti (by omega)\n have hsplit : (∫ x in Set.Ioc (e (J+2)) (e (J+1)), g x)\n + (∫ x in Set.Ioc (e (J+1)) (e 1), g x)\n = ∫ x in Set.Ioc (e (J+2)) (e 1), g x := by\n rw [← MeasureTheory.setIntegral_union]\n · rw [Set.Ioc_union_Ioc_eq_Ioc hle1 hle2]\n · exact Set.Ioc_disjoint_Ioc_of_le (le_refl _)\n · exact measurableSet_Ioc\n · exact hgint.mono_set (fun x hx => lt_of_lt_of_le (hepos (J+2)) hx.1.le)\n · exact hgint.mono_set (fun x hx => lt_of_lt_of_le (hepos (J+1)) hx.1.le)\n rw [← hsplit]\n linarith\n\nlemma sum_le_integral' (g : ℝ → ℝ) (hg0 : ∀ x, 0 ≤ g x)\n (hganti : ∀ x y : ℝ, 0 < x → x ≤ y → g y ≤ g x)\n (hgint : MeasureTheory.IntegrableOn g (Set.Ioi (0:ℝ)))\n (e : ℕ → ℝ) (hepos : ∀ j, 0 < e j) (hemono : ∀ j, e (j+1) ≤ e j) (J : ℕ) :\n ∑ j ∈ Finset.range J, (e (j+1) - e (j+2)) * g (e (j+1))\n ≤ ∫ x in Set.Ioi (0:ℝ), g x := by\n refine le_trans (sum_le_integral g hg0 hganti hgint e hepos hemono J) ?_\n refine MeasureTheory.setIntegral_mono_set hgint ?_ ?_\n · filter_upwards with x using hg0 x\n · exact Filter.Eventually.of_forall\n (fun x hx => lt_of_lt_of_le (hepos (J+1)) hx.1.le)\n\nend IntTools\n\nsection Dudley\n\nlemma Y_sub (n : ℕ) (σ : Signs n) (a b : Fin n → ℝ) :\n (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * a k\n - (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * b k\n = (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (a k - b k) := by\n rw [← mul_sub, ← Finset.sum_sub_distrib]\n exact congrArg _ (Finset.sum_congr rfl (fun k _ => by ring))\n\nlemma dudley {ι : Type*} [Nonempty ι] (n : ℕ) (hn : 0 < n)\n (V : ι → EmpiricalSpace n) (s : Set (EmpiricalSpace n)) (hs : s = Set.range V)\n (hcov : ∀ ε ∈ Set.Ioi (0:ℝ), coveringNumber ε s ≠ ⊤)\n (hint : MeasureTheory.IntegrableOn\n (fun ε : ℝ => Real.sqrt (Real.log (((coveringNumber ε s).untopD 0 : ℕ):ℝ) / (n:ℝ)))\n (Set.Ioi 0)) :\n (Fintype.card (Signs n) : ℝ)⁻¹ *\n ∑ σ : Signs n, ⨆ i, (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * V i k\n ≤ 12 * ∫ ε in Set.Ioi (0:ℝ),\n Real.sqrt (Real.log (((coveringNumber ε s).untopD 0 : ℕ):ℝ) / (n:ℝ)) := by\n classical\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n set g : ℝ → ℝ :=\n fun ε => Real.sqrt (Real.log (((coveringNumber ε s).untopD 0 : ℕ):ℝ) / (n:ℝ)) with hgdef\n have hVs : ∀ i, V i ∈ s := fun i => by rw [hs]; exact ⟨i, rfl⟩\n have hsne : s.Nonempty := ⟨V (Classical.arbitrary ι), hVs _⟩\n have hNpos : ∀ ε : ℝ, 0 < ε → 1 ≤ (coveringNumber ε s).untopD 0 :=\n fun ε hε => covering_pos ε s hsne (hcov ε hε)\n have hg0 : ∀ x, 0 ≤ g x := fun x => Real.sqrt_nonneg _\n have hganti : ∀ x y : ℝ, 0 < x → x ≤ y → g y ≤ g x := by\n intro x y hx hxy\n have hy : 0 < y := lt_of_lt_of_le hx hxy\n have h1 : (coveringNumber y s).untopD 0 ≤ (coveringNumber x s).untopD 0 :=\n covering_anti s hxy (hcov x hx)\n have h2 : (1:ℝ) ≤ (((coveringNumber y s).untopD 0 : ℕ):ℝ) := by exact_mod_cast hNpos y hy\n have h3 : Real.log ((((coveringNumber y s).untopD 0 : ℕ)):ℝ)\n ≤ Real.log ((((coveringNumber x s).untopD 0 : ℕ)):ℝ) :=\n Real.log_le_log (by linarith) (by exact_mod_cast h1)\n apply Real.sqrt_le_sqrt\n rw [div_eq_mul_inv, div_eq_mul_inv]\n exact mul_le_mul_of_nonneg_right h3 (by positivity)\n -- base point and radius\n set p : EmpiricalSpace n := V (Classical.arbitrary ι) with hpdef\n have hps : p ∈ s := hVs _\n obtain ⟨t1, ht1, -⟩ := exists_net_card (1:ℝ) s (hcov 1 (by norm_num))\n have ht1ne : t1.Nonempty := by\n have hmem := ht1 hps\n simp only [Set.mem_iUnion, Metric.mem_closedBall, exists_prop] at hmem\n obtain ⟨y, hy, -⟩ := hmem\n exact ⟨y, hy⟩\n set e0 : ℝ := 1 + t1.sup' ht1ne (fun x => dist x p) with he0def\n have he0pos : 0 < e0 := by\n obtain ⟨x, hx⟩ := id ht1ne\n have : (0:ℝ) ≤ t1.sup' ht1ne (fun x => dist x p) :=\n le_trans dist_nonneg (Finset.le_sup' (fun x => dist x p) hx)\n rw [he0def]; linarith\n have hrad : ∀ v ∈ s, dist v p ≤ e0 := by\n intro v hv\n have hmem := ht1 hv\n simp only [Set.mem_iUnion, Metric.mem_closedBall, exists_prop] at hmem\n obtain ⟨y, hy, hvy⟩ := hmem\n calc dist v p ≤ dist v y + dist y p := dist_triangle _ _ _\n _ ≤ 1 + t1.sup' ht1ne (fun x => dist x p) :=\n add_le_add hvy (Finset.le_sup' (fun x => dist x p) hy)\n -- scales\n set eps : ℕ → ℝ := fun j => e0 / 2 ^ j with hepsdef\n have hepspos : ∀ j, 0 < eps j := fun j => by rw [hepsdef]; positivity\n have hepshalf : ∀ j, eps (j + 1) = eps j / 2 := by\n intro j; rw [hepsdef]; simp [pow_succ]; ring\n have hepsmono : ∀ j, eps (j + 1) ≤ eps j := by\n intro j; rw [hepshalf j]; linarith [hepspos j]\n have heps0 : eps 0 = e0 := by rw [hepsdef]; simp\n -- nets at each scale\n have hCex : ∀ j : ℕ, ∃ C : Finset (EmpiricalSpace n),\n IsENet C (eps (j+1)) s ∧ C.card = (coveringNumber (eps (j+1)) s).untopD 0 :=\n fun j => exists_net_card (eps (j+1)) s (hcov _ (hepspos (j+1)))\n choose Cs hCsnet hCscard using hCex\n obtain ⟨C, hC0, hCsucc⟩ : ∃ C : ℕ → Finset (EmpiricalSpace n),\n C 0 = {p} ∧ ∀ j, C (j+1) = Cs j :=\n ⟨fun j => Nat.rec ({p} : Finset (EmpiricalSpace n)) (fun m _ => Cs m) j, rfl, fun j => rfl⟩\n have hCnet : ∀ j, IsENet (C j) (eps j) s := by\n intro j\n cases j with\n | zero =>\n rw [hC0, heps0]\n intro v hv\n simp only [Set.mem_iUnion, Metric.mem_closedBall, exists_prop, Finset.mem_singleton]\n exact ⟨p, rfl, hrad v hv⟩\n | succ m => rw [hCsucc]; exact hCsnet m\n have hCcard : ∀ j, (C (j+1)).card = (coveringNumber (eps (j+1)) s).untopD 0 := by\n intro j; rw [hCsucc]; exact hCscard j\n have hCcardmono : ∀ j, (C j).card ≤ (C (j+1)).card := by\n intro j\n cases j with\n | zero =>\n rw [hC0, hCcard 0, Finset.card_singleton]\n exact hNpos (eps 1) (hepspos 1)\n | succ m =>\n rw [hCcard m, hCcard (m+1)]\n exact covering_anti s (hepsmono (m+1)) (hcov _ (hepspos (m+2)))\n -- nearest-point projections\n have hpiex : ∀ (j : ℕ) (i : ι), ∃ x : EmpiricalSpace n, x ∈ C j ∧ dist (V i) x ≤ eps j := by\n intro j i\n have hmem := hCnet j (hVs i)\n simp only [Set.mem_iUnion, Metric.mem_closedBall, exists_prop] at hmem\n obtain ⟨x, hx, hdx⟩ := hmem\n exact ⟨x, hx, hdx⟩\n choose pj hpjmem hpjdist using hpiex\n have hpj0 : ∀ i, pj 0 i = p := by\n intro i\n have hm := hpjmem 0 i\n rw [hC0, Finset.mem_singleton] at hm\n exact hm\n -- pair sets\n obtain ⟨D, hDdef⟩ : ∃ D : ℕ → Finset (EmpiricalSpace n × EmpiricalSpace n), ∀ j,\n D j = (C (j+1) ×ˢ C j).filter\n (fun q => empiricalNorm n (fun k => q.1 k - q.2 k) ≤ 3 * eps (j+1)) :=\n ⟨_, fun j => rfl⟩\n have hDmem : ∀ (j : ℕ) (i : ι), (pj (j+1) i, pj j i) ∈ D j := by\n intro j i\n rw [hDdef]\n simp only [Finset.mem_filter, Finset.mem_product]\n refine ⟨⟨hpjmem (j+1) i, hpjmem j i⟩, ?_⟩\n have h1 : dist (pj (j+1) i) (pj j i) ≤ eps (j+1) + eps j :=\n le_trans (dist_triangle (pj (j+1) i) (V i) (pj j i))\n (add_le_add (by rw [dist_comm]; exact hpjdist (j+1) i) (hpjdist j i))\n have h2 : eps j = 2 * eps (j+1) := by rw [hepshalf j]; ring\n rw [← dist_eq_enorm]\n rw [h2] at h1\n linarith\n have hDne : ∀ j, (D j).Nonempty := fun j => ⟨_, hDmem j (Classical.arbitrary ι)⟩\n -- the chaining inequality, for each sign vector and each index\n have hchain : ∀ (J : ℕ) (σ : Signs n) (i : ι),\n (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * V i k\n ≤ (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * p k\n + (∑ j ∈ Finset.range J, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)))\n + eps J := by\n intro J σ i\n obtain ⟨h, hh⟩ : ∃ h : ℕ → ℝ,\n ∀ j, h j = (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (pj j i) k := ⟨_, fun j => rfl⟩\n have htel : ∑ j ∈ Finset.range J, (h (j+1) - h j) = h J - h 0 := Finset.sum_range_sub h J\n have hh0 : h 0 = (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * p k := by\n rw [hh 0, hpj0 i]\n have hstep : ∀ j, h (j+1) - h j\n ≤ (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)) := by\n intro j\n rw [hh (j+1), hh j, Y_sub n σ (pj (j+1) i) (pj j i)]\n exact Finset.le_sup'\n (fun q : EmpiricalSpace n × EmpiricalSpace n =>\n (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)) (hDmem j i)\n have hlast : (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * V i k - h J ≤ eps J := by\n rw [hh J, Y_sub n σ (V i) (pj J i)]\n refine le_trans (inner_le_enorm n σ (fun k => V i k - (pj J i) k)) ?_\n rw [← dist_eq_enorm]\n exact hpjdist J i\n have hsum : h J - h 0\n ≤ ∑ j ∈ Finset.range J, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)) := by\n rw [← htel]\n exact Finset.sum_le_sum (fun j _ => hstep j)\n linarith\n have hsup : ∀ (J : ℕ) (σ : Signs n),\n (⨆ i, (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * V i k)\n ≤ (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * p k\n + (∑ j ∈ Finset.range J, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)))\n + eps J :=\n fun J σ => ciSup_le (fun i => hchain J σ i)\n -- Massart's bound at each scale\n have hlevel : ∀ j : ℕ,\n (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k))\n ≤ 12 * ((eps (j+1) - eps (j+2)) * g (eps (j+1))) := by\n intro j\n have hMnn : (0:ℝ) ≤ 3 * eps (j+1) := by positivity\n have hbdq : ∀ q ∈ D j, empiricalNorm n (fun k => q.1 k - q.2 k) ≤ 3 * eps (j+1) := by\n intro q hq\n rw [hDdef] at hq\n exact (Finset.mem_filter.mp hq).2\n have hms := massart_scaled n hn (D j) (hDne j) (fun q k => q.1 k - q.2 k)\n (3 * eps (j+1)) hMnn hbdq\n refine le_trans hms ?_\n have hcard1 : (D j).card ≤ (C (j+1)).card * (C j).card := by\n rw [hDdef]\n refine le_trans (Finset.card_filter_le _ _) (le_of_eq ?_)\n exact Finset.card_product _ _\n have hcard2 : (D j).card ≤ (C (j+1)).card ^ 2 := by\n have hmm := hCcardmono j\n calc (D j).card ≤ (C (j+1)).card * (C j).card := hcard1\n _ ≤ (C (j+1)).card * (C (j+1)).card := Nat.mul_le_mul_left _ hmm\n _ = (C (j+1)).card ^ 2 := by ring\n have hCpos : 0 < (C (j+1)).card := by\n rw [hCcard j]; exact hNpos (eps (j+1)) (hepspos (j+1))\n have hDpos : 0 < (D j).card := Finset.card_pos.mpr (hDne j)\n have hlog : Real.log ((D j).card : ℝ) ≤ 2 * Real.log ((C (j+1)).card : ℝ) := by\n have h1 : ((D j).card : ℝ) ≤ (((C (j+1)).card : ℝ)) ^ 2 := by exact_mod_cast hcard2\n have h2 : Real.log ((D j).card : ℝ) ≤ Real.log ((((C (j+1)).card : ℝ)) ^ 2) := by\n refine Real.log_le_log ?_ h1\n exact_mod_cast hDpos\n rw [Real.log_pow] at h2\n push_cast at h2\n linarith\n have hgval : g (eps (j+1)) = Real.sqrt (Real.log ((C (j+1)).card : ℝ) / (n:ℝ)) := by\n rw [hgdef]\n simp only\n rw [hCcard j]\n have hstep : Real.sqrt (2 * Real.log ((D j).card : ℝ) / (n:ℝ))\n ≤ 2 * Real.sqrt (Real.log ((C (j+1)).card : ℝ) / (n:ℝ)) := by\n have h4 : (2:ℝ) * Real.sqrt (Real.log ((C (j+1)).card : ℝ) / (n:ℝ))\n = Real.sqrt (2^2 * (Real.log ((C (j+1)).card : ℝ) / (n:ℝ))) := by\n rw [Real.sqrt_mul (by norm_num : (0:ℝ) ≤ 2^2), Real.sqrt_sq (by norm_num : (0:ℝ) ≤ 2)]\n rw [h4]\n refine Real.sqrt_le_sqrt ?_\n have hinv : (0:ℝ) ≤ (n:ℝ)⁻¹ := by positivity\n have hh : 2 * Real.log ((D j).card : ℝ) ≤ 2^2 * Real.log ((C (j+1)).card : ℝ) := by\n norm_num; linarith\n calc 2 * Real.log ((D j).card : ℝ) / (n:ℝ)\n = (2 * Real.log ((D j).card : ℝ)) * (n:ℝ)⁻¹ := by ring\n _ ≤ (2^2 * Real.log ((C (j+1)).card : ℝ)) * (n:ℝ)⁻¹ :=\n mul_le_mul_of_nonneg_right hh hinv\n _ = 2^2 * (Real.log ((C (j+1)).card : ℝ) / (n:ℝ)) := by ring\n have h22 : eps (j+2) = eps (j+1) / 2 := hepshalf (j+1)\n rw [hgval, h22]\n calc 3 * eps (j+1) * Real.sqrt (2 * Real.log ((D j).card : ℝ) / (n:ℝ))\n ≤ 3 * eps (j+1) * (2 * Real.sqrt (Real.log ((C (j+1)).card : ℝ) / (n:ℝ))) :=\n mul_le_mul_of_nonneg_left hstep (by positivity)\n _ = 12 * ((eps (j+1) - eps (j+1) / 2)\n * Real.sqrt (Real.log ((C (j+1)).card : ℝ) / (n:ℝ))) := by ring\n -- the base point contributes nothing on average\n have hbase : ∑ σ : Signs n, (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * p k = 0 := by\n rw [← Finset.mul_sum, Finset.sum_comm]\n have hz : ∀ k : Fin n, ∑ σ : Signs n, ((σ k : ℤ):ℝ) * p k = 0 := by\n intro k\n rw [← Finset.sum_mul, sum_signs_coord n k, zero_mul]\n rw [Finset.sum_congr rfl (fun k (_ : k ∈ Finset.univ) => hz k)]\n simp\n have hcardpos : (0:ℝ) < (Fintype.card (Signs n) : ℝ) := by\n exact_mod_cast Fintype.card_pos\n have hKnn : (0:ℝ) ≤ (Fintype.card (Signs n) : ℝ)⁻¹ := by positivity\n have main : ∀ J : ℕ,\n (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n,\n (⨆ i, (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * V i k)\n ≤ 12 * (∫ x in Set.Ioi (0:ℝ), g x) + eps J := by\n intro J\n have h1 : ∑ σ : Signs n, (⨆ i, (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * V i k)\n ≤ ∑ σ : Signs n, ((n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * p k\n + (∑ j ∈ Finset.range J, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)))\n + eps J) := Finset.sum_le_sum (fun σ _ => hsup J σ)\n have h2 : ∑ σ : Signs n, ((n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * p k\n + (∑ j ∈ Finset.range J, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)))\n + eps J)\n = (∑ σ : Signs n, (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * p k)\n + (∑ j ∈ Finset.range J, ∑ σ : Signs n, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)))\n + (Fintype.card (Signs n) : ℝ) * eps J := by\n rw [Finset.sum_add_distrib, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ,\n nsmul_eq_mul, Finset.sum_comm]\n have h4 : (Fintype.card (Signs n) : ℝ)⁻¹ * ∑ σ : Signs n,\n (⨆ i, (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * V i k)\n ≤ (Fintype.card (Signs n) : ℝ)⁻¹ *\n ((∑ j ∈ Finset.range J, ∑ σ : Signs n, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)))\n + (Fintype.card (Signs n) : ℝ) * eps J) := by\n refine mul_le_mul_of_nonneg_left ?_ hKnn\n refine le_trans h1 (le_of_eq ?_)\n rw [h2, hbase, zero_add]\n refine le_trans h4 ?_\n rw [mul_add, ← mul_assoc, inv_mul_cancel₀ (ne_of_gt hcardpos), one_mul, Finset.mul_sum]\n have h5 : ∑ j ∈ Finset.range J, (Fintype.card (Signs n) : ℝ)⁻¹ *\n (∑ σ : Signs n, (D j).sup' (hDne j)\n (fun q => (n:ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ):ℝ) * (q.1 k - q.2 k)))\n ≤ ∑ j ∈ Finset.range J, 12 * ((eps (j+1) - eps (j+2)) * g (eps (j+1))) :=\n Finset.sum_le_sum (fun j _ => hlevel j)\n have h6 : ∑ j ∈ Finset.range J, 12 * ((eps (j+1) - eps (j+2)) * g (eps (j+1)))\n = 12 * ∑ j ∈ Finset.range J, (eps (j+1) - eps (j+2)) * g (eps (j+1)) := by\n rw [Finset.mul_sum]\n have h7 := sum_le_integral' g hg0 hganti hint eps hepspos hepsmono J\n linarith\n refine le_of_forall_pos_le_add ?_\n intro δ hδ\n obtain ⟨J, hJ⟩ : ∃ J : ℕ, eps J < δ := by\n obtain ⟨J, hJ⟩ := exists_pow_lt_of_lt_one (show (0:ℝ) < δ / e0 by positivity)\n (show (1:ℝ)/2 < 1 by norm_num)\n refine ⟨J, ?_⟩\n have hlt : e0 * ((1:ℝ)/2)^J < e0 * (δ / e0) := by\n exact mul_lt_mul_of_pos_left hJ he0pos\n rw [mul_div_cancel₀ _ (ne_of_gt he0pos)] at hlt\n calc eps J = e0 * ((1:ℝ)/2)^J := by rw [hepsdef]; rw [div_pow, one_pow]; ring\n _ < δ := hlt\n exact le_trans (main J) (by linarith [hJ])\n\nend Dudley\n\ntheorem ch4_theorem_4_17\n {ι : Type*} [Nonempty ι] {𝒳 : Type*}\n (n : ℕ) (hn : 0 < n)\n (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳)\n (s : Set (EmpiricalSpace n))\n (hs : s = Set.range (fun i => empiricalMetricImage n S (f i)))\n (hcov : ∀ ε ∈ Set.Ioi (0 : ℝ), coveringNumber ε s ≠ ⊤)\n (hint : MeasureTheory.IntegrableOn\n (fun ε : ℝ =>\n Real.sqrt\n (Real.log (((coveringNumber ε s).untopD 0 : ℕ) : ℝ)\n / (n : ℝ)))\n (Set.Ioi 0)) :\n empiricalRademacherComplexity_without_abs n f S ≤\n 12 *\n ∫ ε in Set.Ioi (0 : ℝ),\n Real.sqrt\n (Real.log (((coveringNumber ε s).untopD 0 : ℕ) : ℝ)\n / (n : ℝ)) := by\n exact dudley n hn (fun i => empiricalMetricImage n S (f i)) s hs hcov hint\n\nend GraduateLevel\n"} +{"id": "ch4_theorem_4_8", "source": "Graduate-level", "targets": [{"label": "ch4_theorem_4_8", "decls": ["ch4_theorem_4_8"], "statement": "Assume that our infinite hypothesis class \\(\\mathcal{H}\\) can be parameterized by \\(\\mathcal{H} = \\{h_\\theta : \\theta \\in \\mathbb{R}^p, \\|\\theta\\|_2 \\leq B\\}\\). Suppose \\(\\ell((x,y), \\theta) \\in [0,1]\\), and \\(\\ell((x,y), \\theta)\\) is \\(\\kappa\\)-Lipschitz in \\(\\theta\\) with respect to the \\(\\ell_2\\)-norm for all \\((x, y)\\). Then, with probability at least \\(1-O(\\exp(-\\Omega(p)))\\), we have\n\\[\n\\forall \\theta, \\quad |\\widehat{L}(\\theta)- L(\\theta)| \\leq O\\!\\left(\\sqrt{\\frac{p \\max(\\ln(\\kappa Bn), 1)}{n}}\\right).\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Fix parameters \\(\\delta, \\epsilon>0\\) (we will specify their values later). Let \\(C\\) be the \\(\\epsilon\\)-cover of our parameter space \\(S\\) with respect to the \\(\\ell_2\\)-norm constructed in the referenced lemma. Define event \\(E = \\left\\{ \\forall \\theta \\in C, \\; |\\widehat{L}(\\theta) - L(\\theta)| \\le \\delta \\right\\}\\). By Theorem 4.1, we have \\(\\mathbb{P}(E) \\ge 1 - 2|C|\\exp(-2n\\delta^2)\\).\n\nNow for any \\(\\theta \\in S\\), we can pick some \\(\\theta_0 \\in C\\) such that \\(\\|\\theta-\\theta_0\\|_2 \\le \\epsilon\\). Since \\(L\\) and \\(\\widehat{L}\\) are \\(\\kappa\\)-Lipschitz functions (this follows from the Lipschitzness of \\(\\ell\\)), we have\n\\[\n|L(\\theta) - L(\\theta_0)| \\le \\kappa \\|\\theta-\\theta_0\\|_2 \\le \\kappa \\epsilon, \\quad\\text{and}\\quad |\\widehat{L}(\\theta) - \\widehat{L}(\\theta_0)| \\le \\kappa \\|\\theta-\\theta_0\\|_2 \\le \\kappa \\epsilon.\n\\]\n\nTherefore, conditional on \\(E\\), we have\n\\[\n|\\widehat{L}(\\theta) - L(\\theta)| \\le |\\widehat{L}(\\theta)-\\widehat{L}(\\theta_0)| + |\\widehat{L}(\\theta_0) - L(\\theta_0)| + |L(\\theta_0) - L(\\theta)| \\le 2 \\kappa\\epsilon+\\delta.\n\\]\n\nSet \\(\\epsilon = \\delta / (2 \\kappa)\\) so that conditional on \\(E\\),\n\\[\n|\\widehat{L}(\\theta) - L(\\theta)| \\le 2\\delta.\n\\]\n\nThe event \\(E\\) happens with probability \\(1 - 2|C|\\exp(-2n\\delta^2) = 1 - 2 \\exp(\\ln{|C|} - 2n\\delta^2)\\). From the referenced remark, \\(\\ln{|C|} \\leq p \\ln{ (3B / (\\delta / 2)) }\\). If we ignore the log term and assume \\(\\ln{|C|} \\leq p\\), then:\n\\[\n2|C| \\exp(-2n\\delta^2) = 2\\exp(\\ln{|C|} - 2n\\delta^2) \\leq 2\\exp(p - 2p) = 2\\exp(-p).\n\\]\n\nSince we cannot drop the log term in \\(\\ln{|C|} \\leq p \\ln{ (3B / (\\delta / 2)) }\\), we set \\(\\delta = \\sqrt{\\frac{c_0 p \\max(1, \\ln{(\\kappa Bn)})}{n}}\\) with \\(c_0 = 36\\). Then,\n\\[\n\\ln{|C|} - 2n\\delta^2 \\leq p \\ln\\!\\left(\\frac{6B \\kappa}{\\delta}\\right) - 2n\\delta^2 \\leq p \\ln\\!\\left(\\frac{6B\\kappa \\sqrt{n}}{ \\sqrt{c_0 p \\max(1, \\ln{(\\kappa Bn)})} }\\right) - 2n \\frac{c_0p}{n} \\ln(\\kappa Bn)\n\\leq p\\ln\\!\\left(\\frac{B\\kappa \\sqrt{n}}{\\sqrt{p}}\\right) - 72 p \\ln(\\kappa Bn)\n\\leq p \\ln(B\\kappa n) - 72 p \\ln(B\\kappa n) \\leq -p,\n\\]\nsince \\(\\ln (B\\kappa n) \\geq 1\\) for large enough \\(n\\). Therefore, with probability greater than \\(1 - O(e^{-p})\\), we have\n\\[\n|\\widehat{L}(\\theta) - L(\\theta)| \\leq 2\\delta = O\\!\\left(\\sqrt{\\frac{p}{n}\\max(1,\\ln(\\kappa Bn))}\\right).\n\\]", "context": [{"id": "ch4:definition:4_7", "name": "\\(\\kappa\\)-Lipschitz functions", "statement": "Let \\(\\kappa \\geq 0\\) and let \\(\\|\\cdot\\|\\) be a norm on the domain \\(D\\). A function \\(L : D \\to \\mathbb{R}\\) is said to be \\(\\kappa\\)-Lipschitz with respect to \\(\\|\\cdot\\|\\) if for all \\(\\theta, \\theta' \\in D\\),\n\\[\n|L(\\theta) - L(\\theta')| \\leq \\kappa\\,\\|\\theta - \\theta'\\|.\n\\]"}, {"id": "ch4:lemma:4_5", "name": "\\(\\epsilon\\)-cover of \\(\\ell_2\\) ball", "statement": "Let \\(B, \\epsilon > 0\\), and let \\(S = \\{x \\in \\mathbb{R}^p : \\|x\\|_2 \\leq B\\}\\). Then there exists an \\(\\epsilon\\)-cover of \\(S\\) with respect to the \\(\\ell_2\\)-norm with at most \\(\\max\\!\\left(\\left(\\dfrac{3B\\sqrt{p}}{\\epsilon}\\right)^p,\\, 1\\right)\\) elements."}, {"id": "ch4:theorem:4_1", "name": "Uniform convergence bound for finite hypothesis classes", "statement": "Suppose that the hypothesis class \\(\\mathcal{H}\\) is finite and the loss function \\(\\ell\\) is bounded in \\([0,1]\\), i.e. \\(0 \\leq \\ell((x,y),h) \\leq 1\\). Then for all \\(\\delta\\) with \\(0 < \\delta < \\tfrac{1}{2}\\), with probability at least \\(1 - \\delta\\),\n\\[\n|L(h) - \\widehat{L}(h)| \\leq \\sqrt{\\frac{\\ln|\\mathcal{H}| + \\ln(2/\\delta)}{2n}} \\qquad \\forall h \\in \\mathcal{H}.\n\\]\nAs a corollary,\n\\[\nL(\\hat{h}) - L(h^{*}) \\leq \\sqrt{\\frac{2(\\ln|\\mathcal{H}| + \\ln(2/\\delta))}{n}}.\n\\]"}, {"id": "ch4:definition:4_1_risk_setup", "name": "Risk and empirical-risk minimizer setup for finite hypothesis classes", "statement": "Let \\(\\mathcal{H}\\) be a finite hypothesis class and let \\(\\ell\\) be a loss function with \\(0 \\leq \\ell((x,y),h) \\leq 1\\). For \\(h \\in \\mathcal{H}\\), define the population risk\n\\[\nL(h) = \\mathbb{E}_{(x,y) \\sim \\mathcal{D}}[\\ell((x,y),h)].\n\\]\nGiven \\(n\\) iid samples \\((x^{(1)},y^{(1)}), \\dots, (x^{(n)},y^{(n)})\\) from \\(\\mathcal{D}\\), define the empirical risk\n\\[\n\\widehat{L}(h) = \\frac{1}{n}\\sum_{i=1}^n \\ell((x^{(i)},y^{(i)}),h).\n\\]\nLet \\(\\hat{h} \\in \\arg\\min_{h \\in \\mathcal{H}} \\widehat{L}(h)\\) be an empirical-risk minimizer and let \\(h^* \\in \\arg\\min_{h \\in \\mathcal{H}} L(h)\\) be a population-risk minimizer."}, {"id": "ch4_theorem_4_8:fix:1", "name": "Remark 4.6", "statement": "We can actually prove a stronger version of Lemma 4.5: there exists an \\(\\epsilon\\)-cover of \\(S\\) with at most \\(\\left(\\frac{3B}{\\epsilon}\\right)^p\\) elements."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch4_theorem_4_8 :\n ∃ c₀ c₁ c₂ : ℝ, 0 < c₀ ∧ 0 < c₁ ∧ 0 < c₂ ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {𝒳 𝒴 : Type*} [MeasurableSpace 𝒳] [MeasurableSpace 𝒴]\n (p n : ℕ) [NeZero n] (κ B : ℝ)\n (ℓ : (𝒳 × 𝒴) → EuclideanSpace ℝ (Fin p) → ℝ)\n (Z : Fin n → Ω → (𝒳 × 𝒴)),\n 1 ≤ p → 1 ≤ n → 0 ≤ κ → 0 < B →\n (∀ z θ, ‖θ‖ ≤ B → ℓ z θ ∈ Set.Icc (0 : ℝ) 1) →\n (∀ z θ θ', ‖θ‖ ≤ B → ‖θ'‖ ≤ B → |ℓ z θ - ℓ z θ'| ≤ κ * dist θ θ') →\n iIndepFun Z μ →\n (∀ i, ProbabilityTheory.IdentDistrib (Z i) (Z 0) μ μ) →\n (∀ θ, Measurable (fun z => ℓ z θ)) →\n (∀ i θ, AEMeasurable (fun ω => ℓ (Z i ω) θ) μ) →\n let L : EuclideanSpace ℝ (Fin p) → ℝ := fun θ => ∫ ω, ℓ (Z 0 ω) θ ∂μ\n let Lhat : Ω → EuclideanSpace ℝ (Fin p) → ℝ := fun ω θ => (1 / (n : ℝ)) * ∑ i, ℓ (Z i ω) θ\n 1 - c₁ * Real.exp (- c₂ * p) ≤\n μ.real {ω | ∀ θ : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B →\n |Lhat ω θ - L θ| ≤ c₀ * Real.sqrt (p * max (Real.log (κ * B * n)) 1 / n)} := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\n/-! ## Covering/packing machinery\n\nOnly the declarations on the call path from `exists_maximal_packing`,\n`maximal_packing_isENet`, and `packing_card_bound` down to Mathlib primitives are\nincluded here (covering numbers, `IsENet` monotonicity, optimal nets, etc. are not\nneeded and are omitted). -/\n\nsection CoveringPacking\n\n/-- `t` is an `eps`-packing for `s` if it is contained in `s` and any two distinct points are\n`eps`-separated. -/\ndef local_IsPacking {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n (↑t ⊆ s) ∧ (t : Set A).Pairwise (fun x y => eps < dist x y)\n\n/-- `t` is an `eps`-net for `s` if the `eps`-balls around `t` cover `s`. -/\ndef local_IsENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nvariable {A : Type*} [PseudoMetricSpace A]\n\n/-- A maximal packing is a covering: if no point of `s` can be added to a packing `t`,\n then `t` is an `eps`-net for `s`. Requires `eps ≥ 0` for the closed ball condition. -/\nlemma local_isENet_of_maximal {t : Finset A} {eps : ℝ} {s : Set A}\n (heps : 0 ≤ eps)\n (hmax : ∀ a ∈ s, a ∉ t → ∃ x ∈ t, dist a x ≤ eps) :\n local_IsENet t eps s := by\n intro a ha\n by_cases hat : a ∈ t\n · exact Set.mem_iUnion₂.mpr ⟨a, hat, Metric.mem_closedBall_self heps⟩\n · obtain ⟨x, hx_mem, hx_dist⟩ := hmax a ha hat\n exact Set.mem_iUnion₂.mpr ⟨x, hx_mem, Metric.mem_closedBall.mpr hx_dist⟩\n\n/-- A maximal packing is an ε-net: if no point of s can be added while maintaining\n ε-separation, then the packing is an ε-net. -/\nlemma local_maximal_packing_isENet {E : Type*} [PseudoMetricSpace E]\n {t : Finset E} {eps : ℝ} {s : Set E}\n (heps : 0 ≤ eps)\n (_hpacking : local_IsPacking t eps s)\n (hmaximal : ∀ x ∈ s, x ∉ t → ∃ y ∈ t, dist x y ≤ eps) :\n local_IsENet t eps s :=\n local_isENet_of_maximal heps hmaximal\n\n/-- The existence of a maximal packing in a totally bounded set. -/\nlemma local_exists_maximal_packing {E : Type*} [PseudoMetricSpace E]\n {s : Set E} (eps : ℝ) (heps : 0 < eps) (hs : TotallyBounded s) :\n ∃ t : Finset E, local_IsPacking t eps s ∧\n (∀ x ∈ s, x ∉ t → ∃ y ∈ t, dist x y ≤ eps) := by\n classical\n have heps2 : 0 < eps / 2 := by linarith\n obtain ⟨cover, _, hcover_finite, hcover⟩ := Metric.finite_approx_of_totallyBounded hs (eps / 2) heps2\n have hbound : ∀ t : Finset E, local_IsPacking t eps s → t.card ≤ cover.ncard := by\n intro t ht\n have ht_sep : (t : Set E).Pairwise (fun x y => eps < dist x y) := ht.2\n have hmaps : ∀ x ∈ t, ∃ c ∈ cover, x ∈ Metric.ball c (eps / 2) := fun x hx => by\n have hxs := ht.1 hx\n have := hcover hxs\n simp only [Set.mem_iUnion] at this\n obtain ⟨c, hc, hxball⟩ := this\n exact ⟨c, hc, hxball⟩\n let f : t → cover := fun ⟨x, hx⟩ => ⟨(hmaps x hx).choose, (hmaps x hx).choose_spec.1⟩\n have hf_inj : Function.Injective f := by\n intro ⟨x, hx⟩ ⟨y, hy⟩ heq\n simp only [f, Subtype.mk.injEq] at heq\n have hxc := (hmaps x hx).choose_spec.2\n have hyc : y ∈ Metric.ball (hmaps y hy).choose (eps / 2) := (hmaps y hy).choose_spec.2\n by_cases hxy : x = y\n · exact Subtype.ext hxy\n · exfalso\n have hsep_xy := ht_sep hx hy hxy\n have heq' : (hmaps x hx).choose = (hmaps y hy).choose := heq\n have hdist : dist x y < eps := by\n calc dist x y ≤ dist x (hmaps x hx).choose + dist (hmaps x hx).choose y := dist_triangle _ _ _\n _ < eps / 2 + eps / 2 := by\n apply add_lt_add\n · exact Metric.mem_ball.mp hxc\n · rw [heq', dist_comm]; exact Metric.mem_ball.mp hyc\n _ = eps := by ring\n linarith\n haveI : Finite cover := hcover_finite\n haveI : Fintype cover := Fintype.ofFinite cover\n calc t.card = Fintype.card t := by rw [Fintype.card_coe]\n _ ≤ Fintype.card cover := Fintype.card_le_of_injective f hf_inj\n _ = cover.ncard := by\n rw [Set.ncard_eq_toFinset_card cover]\n simp [Set.toFinset_card]\n let bound := cover.ncard\n have iterate : ∀ n : ℕ, ∀ t : Finset E, local_IsPacking t eps s → bound - t.card = n →\n ∃ t' : Finset E, t ⊆ t' ∧ local_IsPacking t' eps s ∧\n (∀ x ∈ s, x ∉ t' → ∃ y ∈ t', dist x y ≤ eps) := by\n intro n\n induction n with\n | zero =>\n intro t ht_pack heq\n use t, Finset.Subset.refl t, ht_pack\n intro x hxs hxt\n by_contra h\n push_neg at h\n have hx_sep : ∀ y ∈ t, eps < dist x y := fun y hy => h y hy\n have ht'_pack : local_IsPacking (insert x t) eps s := by\n constructor\n · intro y hy\n rw [Finset.mem_coe, Finset.mem_insert] at hy\n rcases hy with rfl | hy\n · exact hxs\n · exact ht_pack.1 hy\n · intro y hy z hz hyz\n rw [Finset.mem_coe, Finset.mem_insert] at hy hz\n rcases hy with rfl | hy <;> rcases hz with rfl | hz\n · exact absurd rfl hyz\n · exact hx_sep z hz\n · rw [dist_comm]; exact hx_sep y hy\n · exact ht_pack.2 hy hz hyz\n have h_bound := hbound (insert x t) ht'_pack\n have h_card : (insert x t).card = t.card + 1 := Finset.card_insert_of_notMem hxt\n omega\n | succ n ih =>\n intro t ht_pack heq\n by_cases hmaximal : ∀ x ∈ s, x ∉ t → ∃ y ∈ t, dist x y ≤ eps\n · use t, Finset.Subset.refl t, ht_pack, hmaximal\n · push_neg at hmaximal\n obtain ⟨x, hxs, hxt, hx_sep⟩ := hmaximal\n have ht'_pack : local_IsPacking (insert x t) eps s := by\n constructor\n · intro y hy\n rw [Finset.mem_coe, Finset.mem_insert] at hy\n rcases hy with rfl | hy\n · exact hxs\n · exact ht_pack.1 hy\n · intro y hy z hz hyz\n rw [Finset.mem_coe, Finset.mem_insert] at hy hz\n rcases hy with rfl | hy <;> rcases hz with rfl | hz\n · exact absurd rfl hyz\n · have := hx_sep z hz; linarith\n · have := hx_sep y hy; rw [dist_comm]; linarith\n · exact ht_pack.2 hy hz hyz\n have h_card : (insert x t).card = t.card + 1 := Finset.card_insert_of_notMem hxt\n have h_gap : bound - (insert x t).card = n := by omega\n obtain ⟨t'', ht''_sub, ht''_pack, ht''_max⟩ := ih (insert x t) ht'_pack h_gap\n exact ⟨t'', Finset.Subset.trans (Finset.subset_insert x t) ht''_sub, ht''_pack, ht''_max⟩\n have hempty_pack : local_IsPacking (∅ : Finset E) eps s := by\n constructor\n · simp\n · simp\n have hgap : bound - (∅ : Finset E).card = bound := by simp\n obtain ⟨t, _, ht_pack, ht_max⟩ := iterate bound ∅ hempty_pack hgap\n exact ⟨t, ht_pack, ht_max⟩\n\nsection EuclideanBall\n\nvariable {ι : Type*} [Fintype ι] [Nonempty ι]\n\n/-- The closed Euclidean ball of radius R centered at 0 in EuclideanSpace ℝ ι. -/\nabbrev local_euclideanBall (R : ℝ) : Set (EuclideanSpace ℝ ι) := Metric.closedBall 0 R\n\nomit [Nonempty ι] in\n/-- The Euclidean ball is totally bounded (since it's compact in finite dimensions). -/\nlemma local_euclideanBall_totallyBounded (R : ℝ) :\n TotallyBounded (local_euclideanBall R : Set (EuclideanSpace ℝ ι)) :=\n (isCompact_closedBall (0 : EuclideanSpace ℝ ι) R).totallyBounded\n\n/-- If points x and y are ε-separated (dist x y > ε), then the closed balls of radius ε/2\n around them are disjoint. -/\nlemma local_closedBall_half_disjoint {E : Type*} [PseudoMetricSpace E] {x y : E} {eps : ℝ}\n (_heps : 0 ≤ eps) (hsep : eps < dist x y) :\n Disjoint (Metric.closedBall x (eps / 2)) (Metric.closedBall y (eps / 2)) := by\n apply Metric.closedBall_disjoint_closedBall\n calc eps / 2 + eps / 2 = eps := by ring\n _ < dist x y := hsep\n\n/-- For a packing, the half-radius balls around distinct points are pairwise disjoint. -/\nlemma local_packing_halfBalls_pairwiseDisjoint {E : Type*} [PseudoMetricSpace E]\n {t : Finset E} {eps : ℝ} {s : Set E}\n (heps : 0 ≤ eps) (hpacking : local_IsPacking t eps s) :\n (t : Set E).PairwiseDisjoint (fun x => Metric.closedBall x (eps / 2)) := by\n intro x hx y hy hxy\n have hsep := hpacking.2 hx hy hxy\n exact local_closedBall_half_disjoint heps hsep\n\n/-- A half-radius ball around a point in closedBall(0, R) is contained in closedBall(0, R + eps/2). -/\nlemma local_halfBall_subset_enlargedBall {E : Type*} [SeminormedAddCommGroup E]\n {x : E} {R eps : ℝ} (hx : x ∈ Metric.closedBall (0 : E) R) :\n Metric.closedBall x (eps / 2) ⊆ Metric.closedBall (0 : E) (R + eps / 2) := by\n intro z hz\n rw [Metric.mem_closedBall] at hx hz ⊢\n simp only [dist_zero_right] at hx ⊢\n have h1 : ‖z‖ = ‖z - x + x‖ := by simp\n calc ‖z‖ = ‖z - x + x‖ := h1\n _ ≤ ‖z - x‖ + ‖x‖ := norm_add_le _ _\n _ = dist z x + ‖x‖ := by rw [dist_eq_norm]\n _ ≤ eps / 2 + R := by linarith [hz, hx]\n _ = R + eps / 2 := by ring\n\n/-- Union of half-balls around a packing in B(0, R) is contained in B(0, R + eps/2). -/\nlemma local_packing_halfBalls_subset {E : Type*} [SeminormedAddCommGroup E]\n {t : Finset E} {R eps : ℝ} {s : Set E}\n (hpacking : local_IsPacking t eps s) (hs : s ⊆ Metric.closedBall (0 : E) R) :\n (⋃ x ∈ t, Metric.closedBall x (eps / 2)) ⊆ Metric.closedBall (0 : E) (R + eps / 2) := by\n intro z hz\n rw [Set.mem_iUnion₂] at hz\n obtain ⟨x, hxt, hzx⟩ := hz\n have hxs : x ∈ s := hpacking.1 hxt\n have hxR : x ∈ Metric.closedBall (0 : E) R := hs hxs\n exact local_halfBall_subset_enlargedBall hxR hzx\n\nomit [Nonempty ι] in\n/-- Key volume lemma: The volume of disjoint half-balls equals the sum of individual volumes. -/\nlemma local_volume_disjoint_union_closedBalls\n {t : Finset (EuclideanSpace ℝ ι)} {eps : ℝ} (_heps : 0 ≤ eps)\n (hpwd : (t : Set (EuclideanSpace ℝ ι)).PairwiseDisjoint\n (fun x => Metric.closedBall x (eps / 2))) :\n MeasureTheory.volume (⋃ x ∈ t, Metric.closedBall x (eps / 2)) =\n ∑ x ∈ t, MeasureTheory.volume (Metric.closedBall x (eps / 2)) := by\n have hmeas : ∀ b ∈ t, MeasurableSet (Metric.closedBall b (eps / 2)) :=\n fun _ _ => measurableSet_closedBall\n exact measure_biUnion_finset hpwd hmeas\n\n/-- The constant factor in the volume of a unit ball. -/\nnoncomputable def local_euclideanBallVolumeConst (d : ℕ) : ℝ :=\n Real.pi.sqrt ^ d / Real.Gamma (d / 2 + 1)\n\nlemma local_euclideanBallVolumeConst_pos (d : ℕ) : 0 < local_euclideanBallVolumeConst d := by\n unfold local_euclideanBallVolumeConst\n apply div_pos\n · exact pow_pos (Real.sqrt_pos.mpr Real.pi_pos) d\n · have h : (0 : ℝ) < (d : ℝ) / 2 + 1 := by positivity\n exact Real.Gamma_pos_of_pos h\n\n/-- The volume of a closed ball with radius r equals r^d times the unit ball volume. -/\nlemma local_volume_closedBall_eq_rpow (x : EuclideanSpace ℝ ι) (r : ℝ) (hr : 0 ≤ r) :\n MeasureTheory.volume (Metric.closedBall x r) =\n ENNReal.ofReal (r ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) := by\n rw [EuclideanSpace.volume_closedBall]\n have hr_pow : ENNReal.ofReal r ^ Fintype.card ι = ENNReal.ofReal (r ^ Fintype.card ι) := by\n induction Fintype.card ι with\n | zero => simp\n | succ n ih =>\n rw [pow_succ, pow_succ, ih]\n rw [mul_comm (ENNReal.ofReal _) (ENNReal.ofReal r)]\n rw [← ENNReal.ofReal_mul hr]\n rw [mul_comm r (r ^ n)]\n rw [hr_pow]\n unfold local_euclideanBallVolumeConst\n rw [← ENNReal.ofReal_mul (pow_nonneg hr _)]\n\n/-- Key cardinality bound: For a packing in B(0, R), we have\n |t| ≤ ((R + ε/2) / (ε/2))^d = (1 + 2R/ε)^d -/\nlemma local_packing_card_bound_aux\n {t : Finset (EuclideanSpace ℝ ι)} {R eps : ℝ}\n (hR : 0 ≤ R) (heps : 0 < eps)\n (hpacking : local_IsPacking t eps (local_euclideanBall R)) :\n (t.card : ℝ) ≤ ((R + eps / 2) / (eps / 2)) ^ Fintype.card ι := by\n have hpwd := local_packing_halfBalls_pairwiseDisjoint (le_of_lt heps) hpacking\n have hsub := local_packing_halfBalls_subset hpacking (le_refl _)\n have hvol_eq := local_volume_disjoint_union_closedBalls (le_of_lt heps) hpwd\n have hvol_le : MeasureTheory.volume (⋃ x ∈ t, Metric.closedBall x (eps / 2)) ≤\n MeasureTheory.volume (Metric.closedBall (0 : EuclideanSpace ℝ ι) (R + eps / 2)) :=\n MeasureTheory.measure_mono hsub\n have heps_half_pos : 0 < eps / 2 := by linarith\n have heps_half_nonneg : 0 ≤ eps / 2 := le_of_lt heps_half_pos\n have hR_plus_pos : 0 ≤ R + eps / 2 := by linarith\n have hvol_small : ∀ x : EuclideanSpace ℝ ι, MeasureTheory.volume (Metric.closedBall x (eps / 2)) =\n ENNReal.ofReal ((eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) :=\n fun x => local_volume_closedBall_eq_rpow x (eps / 2) heps_half_nonneg\n have hvol_large : MeasureTheory.volume (Metric.closedBall (0 : EuclideanSpace ℝ ι) (R + eps / 2)) =\n ENNReal.ofReal ((R + eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) :=\n local_volume_closedBall_eq_rpow 0 (R + eps / 2) hR_plus_pos\n have hvol_sum : ∑ x ∈ t, MeasureTheory.volume (Metric.closedBall x (eps / 2)) =\n t.card * ENNReal.ofReal ((eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) := by\n simp only [hvol_small]\n rw [Finset.sum_const]\n simp only [nsmul_eq_mul]\n rw [hvol_eq, hvol_sum] at hvol_le\n rw [hvol_large] at hvol_le\n have hconst_pos := local_euclideanBallVolumeConst_pos (Fintype.card ι)\n have hsmall_pos : 0 < (eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι) :=\n mul_pos (pow_pos heps_half_pos _) hconst_pos\n have hlarge_pos : 0 < (R + eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι) :=\n mul_pos (pow_pos (by linarith : 0 < R + eps / 2) _) hconst_pos\n have hlarge_nonneg : 0 ≤ (R + eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι) :=\n le_of_lt hlarge_pos\n have h : t.card * ENNReal.ofReal ((eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) ≤\n ENNReal.ofReal ((R + eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) := hvol_le\n rw [← ENNReal.ofReal_natCast] at h\n rw [← ENNReal.ofReal_mul (Nat.cast_nonneg _)] at h\n have h' := ENNReal.ofReal_le_ofReal_iff hlarge_nonneg |>.mp h\n have hdiv : t.card * ((eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) ≤\n (R + eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι) := h'\n have hcancel : (t.card : ℝ) ≤ (R + eps / 2) ^ Fintype.card ι / (eps / 2) ^ Fintype.card ι := by\n have hne : (eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι) ≠ 0 :=\n ne_of_gt hsmall_pos\n have hsmall_nonneg : 0 ≤ (eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι) :=\n le_of_lt hsmall_pos\n calc (t.card : ℝ)\n _ = t.card * ((eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) /\n ((eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) := by\n rw [mul_div_cancel_right₀ _ hne]\n _ ≤ (R + eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι) /\n ((eps / 2) ^ Fintype.card ι * local_euclideanBallVolumeConst (Fintype.card ι)) := by\n apply div_le_div_of_nonneg_right hdiv hsmall_nonneg\n _ = (R + eps / 2) ^ Fintype.card ι / (eps / 2) ^ Fintype.card ι := by\n rw [mul_div_mul_right _ _ (ne_of_gt hconst_pos)]\n have hdiv_eq : (R + eps / 2) ^ Fintype.card ι / (eps / 2) ^ Fintype.card ι =\n ((R + eps / 2) / (eps / 2)) ^ Fintype.card ι := by\n rw [← div_pow]\n rw [hdiv_eq] at hcancel\n exact hcancel\n\n/-- Main bound: For a packing, |t| ≤ (1 + 2R/ε)^d. -/\nlemma local_packing_card_bound\n {t : Finset (EuclideanSpace ℝ ι)} {R eps : ℝ}\n (hR : 0 ≤ R) (heps : 0 < eps)\n (hpacking : local_IsPacking t eps (local_euclideanBall R)) :\n (t.card : ℝ) ≤ (1 + 2 * R / eps) ^ Fintype.card ι := by\n have h := local_packing_card_bound_aux hR heps hpacking\n have heq : (R + eps / 2) / (eps / 2) = 1 + 2 * R / eps := by\n field_simp\n ring\n rw [heq] at h\n exact h\n\nend EuclideanBall\n\nend CoveringPacking\n\n/-! ## Hoeffding inequality\n\n`hoeffding_sum`'s proof is a thin wrapper around Mathlib's own\n`ProbabilityTheory.hasSubgaussianMGF_of_mem_Icc` and\n`ProbabilityTheory.HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun`. -/\n\nsection HoeffdingSum\n\nvariable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n\n/-- **Hoeffding's inequality** (two-sided, sum of independent bounded random variables). -/\ntheorem local_hoeffding_sum [IsProbabilityMeasure μ]\n {n : ℕ} {X : Fin n → Ω → ℝ} (h_indep : iIndepFun X μ)\n {a b : Fin n → ℝ}\n (h_bound : ∀ i, ∀ᵐ ω ∂μ, X i ω ∈ Set.Icc (a i) (b i))\n (h_meas : ∀ i, AEMeasurable (X i) μ)\n {ε : ℝ} (hε : 0 ≤ ε) :\n μ.real {ω | ε ≤ |∑ i : Fin n, (X i ω - μ[X i])|}\n ≤ 2 * exp (- ε ^ 2 / (2 * (∑ i : Fin n, ((‖b i - a i‖₊ : ℝ) / 2) ^ 2))) := by\n have h_subG : ∀ i : Fin n,\n HasSubgaussianMGF (fun ω ↦ X i ω - μ[X i]) ((‖b i - a i‖₊ / 2) ^ 2) μ :=\n fun i ↦ hasSubgaussianMGF_of_mem_Icc (h_meas i) (h_bound i)\n have h_indep_Y : iIndepFun (fun i ω ↦ X i ω - μ[X i]) μ := by\n show iIndepFun (fun i ↦ (fun x : ℝ ↦ x - μ[X i]) ∘ X i) μ\n exact h_indep.comp (fun i ↦ fun x : ℝ ↦ x - μ[X i])\n (fun i ↦ measurable_id.sub measurable_const)\n have h_right : μ.real {ω | ε ≤ ∑ i : Fin n, (X i ω - μ[X i])} ≤\n exp (- ε ^ 2 / (2 * (∑ i : Fin n, ((‖b i - a i‖₊ : ℝ) / 2) ^ 2))) := by\n have h1 := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun (μ := μ)\n (s := Finset.univ) h_indep_Y (fun i _ ↦ h_subG i) hε\n convert h1 using 2\n push_cast [NNReal.coe_sum, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat]\n rfl\n have h_neg : ∀ i : Fin n,\n HasSubgaussianMGF (fun ω ↦ -(X i ω - μ[X i])) ((‖b i - a i‖₊ / 2) ^ 2) μ :=\n fun i ↦ (h_subG i).neg\n have h_indep_neg : iIndepFun (fun i ω ↦ -(X i ω - μ[X i])) μ := by\n show iIndepFun (fun i ↦ (Neg.neg : ℝ → ℝ) ∘ (fun ω ↦ X i ω - μ[X i])) μ\n exact h_indep_Y.comp (fun _ ↦ (Neg.neg : ℝ → ℝ)) (fun _ ↦ measurable_neg)\n have h_left : μ.real {ω | ε ≤ -(∑ i : Fin n, (X i ω - μ[X i]))} ≤\n exp (- ε ^ 2 / (2 * (∑ i : Fin n, ((‖b i - a i‖₊ : ℝ) / 2) ^ 2))) := by\n have h1 := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun (μ := μ)\n (s := Finset.univ) h_indep_neg (fun i _ ↦ h_neg i) hε\n rw [show {ω | ε ≤ -(∑ i : Fin n, (X i ω - μ[X i]))} =\n {ω | ε ≤ ∑ i : Fin n, (-(X i ω - μ[X i]))} by\n simp]\n convert h1 using 2\n push_cast [NNReal.coe_sum, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat]\n rfl\n set S : Ω → ℝ := fun ω ↦ ∑ i : Fin n, (X i ω - μ[X i])\n have h_union : {ω | ε ≤ |S ω|} ⊆ {ω | ε ≤ S ω} ∪ {ω | ε ≤ -S ω} := by\n intro ω hω\n simp only [Set.mem_setOf_eq, Set.mem_union] at *\n rcases le_or_gt 0 (S ω) with h | h\n · left; rwa [abs_of_nonneg h] at hω\n · right\n have : |S ω| = -S ω := abs_of_neg h\n linarith [this ▸ hω]\n calc μ.real {ω | ε ≤ |S ω|}\n ≤ μ.real ({ω | ε ≤ S ω} ∪ {ω | ε ≤ -S ω}) := measureReal_mono h_union\n _ ≤ μ.real {ω | ε ≤ S ω} + μ.real {ω | ε ≤ -S ω} := measureReal_union_le _ _\n _ ≤ exp (- ε ^ 2 / (2 * (∑ i : Fin n, ((‖b i - a i‖₊ : ℝ) / 2) ^ 2)))\n + exp (- ε ^ 2 / (2 * (∑ i : Fin n, ((‖b i - a i‖₊ : ℝ) / 2) ^ 2))) := by\n gcongr\n _ = 2 * exp (- ε ^ 2 / (2 * (∑ i : Fin n, ((‖b i - a i‖₊ : ℝ) / 2) ^ 2))) := by ring\n\nend HoeffdingSum\n\nset_option maxHeartbeats 2000000 in\ntheorem ch4_theorem_4_8 :\n ∃ c₀ c₁ c₂ : ℝ, 0 < c₀ ∧ 0 < c₁ ∧ 0 < c₂ ∧\n ∀ {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {𝒳 𝒴 : Type*} [MeasurableSpace 𝒳] [MeasurableSpace 𝒴]\n (p n : ℕ) [NeZero n] (κ B : ℝ)\n (ℓ : (𝒳 × 𝒴) → EuclideanSpace ℝ (Fin p) → ℝ)\n (Z : Fin n → Ω → (𝒳 × 𝒴)),\n 1 ≤ p → 1 ≤ n → 0 ≤ κ → 0 < B →\n (∀ z θ, ‖θ‖ ≤ B → ℓ z θ ∈ Set.Icc (0 : ℝ) 1) →\n (∀ z θ θ', ‖θ‖ ≤ B → ‖θ'‖ ≤ B → |ℓ z θ - ℓ z θ'| ≤ κ * dist θ θ') →\n iIndepFun Z μ →\n (∀ i, ProbabilityTheory.IdentDistrib (Z i) (Z 0) μ μ) →\n (∀ θ, Measurable (fun z => ℓ z θ)) →\n (∀ i θ, AEMeasurable (fun ω => ℓ (Z i ω) θ) μ) →\n let L : EuclideanSpace ℝ (Fin p) → ℝ := fun θ => ∫ ω, ℓ (Z 0 ω) θ ∂μ\n let Lhat : Ω → EuclideanSpace ℝ (Fin p) → ℝ := fun ω θ => (1 / (n : ℝ)) * ∑ i, ℓ (Z i ω) θ\n 1 - c₁ * Real.exp (- c₂ * p) ≤\n μ.real {ω | ∀ θ : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B →\n |Lhat ω θ - L θ| ≤ c₀ * Real.sqrt (p * max (Real.log (κ * B * n)) 1 / n)} := by\n refine ⟨8, 2, 1, by norm_num, by norm_num, by norm_num, ?_⟩\n intro Ω _ μ _ 𝒳 𝒴 _ _ p n _ κ B ℓ Z hp hn hκ hB hIcc hLip hindep hident hmeasℓ hameas L Lhat\n have hLdef : ∀ θ, L θ = ∫ ω, ℓ (Z 0 ω) θ ∂μ := fun _ => rfl\n have hLhatdef : ∀ ω θ, Lhat ω θ = (1 / (n : ℝ)) * ∑ i, ℓ (Z i ω) θ := fun _ _ => rfl\n -- numeric preliminaries\n have hnR : (1 : ℝ) ≤ (n : ℝ) := by exact_mod_cast hn\n have hn0 : (0 : ℝ) < (n : ℝ) := by linarith\n have hpR : (1 : ℝ) ≤ (p : ℝ) := by exact_mod_cast hp\n set M : ℝ := max (Real.log (κ * B * n)) 1 with hMdef\n have hM1 : (1 : ℝ) ≤ M := le_max_right _ _\n set r : ℝ := (p : ℝ) * M / (n : ℝ) with hrdef\n have hpM : (1 : ℝ) ≤ (p : ℝ) * M := by nlinarith\n have hrpos : 0 < r := by rw [hrdef]; positivity\n have hr_ge : 1 / (n : ℝ) ≤ r := by\n rw [hrdef, div_le_div_iff_of_pos_right hn0]\n exact hpM\n set δ : ℝ := 4 * Real.sqrt r with hδdef\n have hsqrtpos : 0 < Real.sqrt r := Real.sqrt_pos.mpr hrpos\n have hδpos : 0 < δ := by rw [hδdef]; linarith\n have hδ2 : δ ^ 2 = 16 * r := by\n rw [hδdef, mul_pow, Real.sq_sqrt hrpos.le]; ring\n -- 1 ≤ n * √r\n have hnsr : (1 : ℝ) ≤ (n : ℝ) * Real.sqrt r := by\n have he : ((n : ℝ) * Real.sqrt r) = Real.sqrt ((n : ℝ) ^ 2 * r) := by\n rw [Real.sqrt_mul (by positivity), Real.sqrt_sq hn0.le]\n rw [he, show (1 : ℝ) = Real.sqrt 1 by simp]\n apply Real.sqrt_le_sqrt\n have h10 : (n : ℝ) ^ 2 * r = (n : ℝ) * ((p : ℝ) * M) := by\n rw [hrdef]; field_simp; try ring\n rw [h10]\n nlinarith\n -- the cover scale\n have hκB : 0 ≤ κ * B := mul_nonneg hκ hB.le\n have hden : (0 : ℝ) < 1 + 2 * κ * B / δ := by\n have : (0 : ℝ) ≤ 2 * κ * B / δ := div_nonneg (by nlinarith) hδpos.le\n linarith\n set ε : ℝ := B / (1 + 2 * κ * B / δ) with hεdef\n have hεpos : 0 < ε := div_pos hB hden\n have hδne : δ ≠ 0 := ne_of_gt hδpos\n have hκε : κ * ε ≤ δ / 2 := by\n have h1 : κ * ε = κ * B / (1 + 2 * κ * B / δ) := by rw [hεdef]; ring\n rw [h1, div_le_iff₀ hden]\n have : δ / 2 * (1 + 2 * κ * B / δ) = δ / 2 + κ * B := by field_simp; try ring\n rw [this]\n linarith\n -- the cover\n have hNE : Nonempty (Fin p) := ⟨⟨0, by omega⟩⟩\n obtain ⟨T, hpack, hmax⟩ := local_exists_maximal_packing\n (s := (local_euclideanBall B : Set (EuclideanSpace ℝ (Fin p)))) ε hεpos\n (local_euclideanBall_totallyBounded B)\n have hnet := local_maximal_packing_isENet hεpos.le hpack hmax\n have hTnorm : ∀ θ ∈ T, ‖θ‖ ≤ B := by\n intro θ hθ\n have := hpack.1 (Finset.mem_coe.mpr hθ)\n simpa [local_euclideanBall, Metric.mem_closedBall, dist_zero_right] using this\n have hcover : ∀ θ : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B → ∃ θ₀ ∈ T, dist θ θ₀ ≤ ε := by\n intro θ hθ\n have hmem : θ ∈ (local_euclideanBall B : Set (EuclideanSpace ℝ (Fin p))) := by\n simpa [local_euclideanBall, Metric.mem_closedBall, dist_zero_right] using hθ\n have h := hnet hmem\n simp only [Set.mem_iUnion, Metric.mem_closedBall, exists_prop] at h\n exact h\n have hcard : (T.card : ℝ) ≤ (1 + 2 * B / ε) ^ p := by\n have h := local_packing_card_bound hB.le hεpos hpack\n simpa [Fintype.card_fin] using h\n have hXeq : 1 + 2 * B / ε = 3 + 4 * κ * B / δ := by\n rw [hεdef]\n rw [div_div_eq_mul_div]\n field_simp\n ring\n rw [hXeq] at hcard\n -- key numeric bound : 3 + 4κB/δ ≤ exp (31 M)\n have hu0 : (0 : ℝ) ≤ κ * B * (n : ℝ) := by positivity\n have hufrac : 4 * κ * B / δ ≤ κ * B * (n : ℝ) := by\n rw [div_le_iff₀ hδpos, hδdef]\n have h1 : κ * B * (n : ℝ) * (4 * Real.sqrt r) = 4 * (κ * B) * ((n : ℝ) * Real.sqrt r) := by\n ring\n rw [h1]\n nlinarith\n have hXexp : 3 + 4 * κ * B / δ ≤ Real.exp (31 * M) := by\n set u : ℝ := κ * B * (n : ℝ) with hudef\n have hexp1 : (1 : ℝ) + 31 * M ≤ Real.exp (31 * M) := by\n have := Real.add_one_le_exp (31 * M); linarith\n have hstep : 3 + 4 * κ * B / δ ≤ 3 + u := by linarith [hufrac]\n rcases le_or_gt u 4 with h | h\n · have h7 : (7 : ℝ) ≤ Real.exp (31 * M) := by linarith\n linarith\n · have hlogu : Real.log u ≤ M := by\n rw [hMdef]; exact le_max_left _ _\n have hlognn : 0 ≤ Real.log u := Real.log_nonneg (by linarith)\n have h2M : 2 * Real.log u ≤ 31 * M := by linarith\n have hmono : Real.exp (2 * Real.log u) ≤ Real.exp (31 * M) := Real.exp_le_exp.mpr h2M\n have hu2 : Real.exp (2 * Real.log u) = u ^ 2 := by\n rw [show (2 : ℝ) * Real.log u = Real.log u + Real.log u by ring, Real.exp_add,\n Real.exp_log (by linarith)]\n ring\n rw [hu2] at hmono\n have h10 : 3 + u ≤ u ^ 2 := by nlinarith\n linarith\n -- integrability\n have hint : ∀ i, ∀ θ : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B →\n Integrable (fun ω => ℓ (Z i ω) θ) μ := by\n intro i θ hθ\n refine Integrable.mono' (integrable_const (1 : ℝ)) (hameas i θ).aestronglyMeasurable\n (Filter.Eventually.of_forall fun ω => ?_)\n have h := hIcc (Z i ω) θ hθ\n rw [Real.norm_eq_abs, abs_le]\n constructor <;> [linarith [h.1, h.2]; linarith [h.1, h.2]]\n -- identical expectations\n have hEq : ∀ i, ∀ θ : EuclideanSpace ℝ (Fin p), ∫ ω, ℓ (Z i ω) θ ∂μ = L θ := by\n intro i θ\n have h : IdentDistrib (fun ω => ℓ (Z i ω) θ) (fun ω => ℓ (Z 0 ω) θ) μ μ :=\n (hident i).comp (hmeasℓ θ)\n rw [hLdef]\n exact h.integral_eq\n -- Lipschitz bounds\n have hLlip : ∀ θ θ' : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B → ‖θ'‖ ≤ B →\n |L θ - L θ'| ≤ κ * dist θ θ' := by\n intro θ θ' h1 h2\n have hi1 := hint 0 θ h1\n have hi2 := hint 0 θ' h2\n rw [hLdef, hLdef, ← integral_sub hi1 hi2]\n calc |∫ ω, (ℓ (Z 0 ω) θ - ��� (Z 0 ω) θ') ∂μ|\n ≤ ∫ ω, |ℓ (Z 0 ω) θ - ℓ (Z 0 ω) θ'| ∂μ := abs_integral_le_integral_abs\n _ ≤ ∫ _ω, κ * dist θ θ' ∂μ :=\n integral_mono (hi1.sub hi2).abs (integrable_const _)\n (fun ω => hLip (Z 0 ω) θ θ' h1 h2)\n _ = κ * dist θ θ' := by simp\n have hLhatlip : ∀ ω, ∀ θ θ' : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B → ‖θ'‖ ≤ B →\n |Lhat ω θ - Lhat ω θ'| ≤ κ * dist θ θ' := by\n intro ω θ θ' h1 h2\n have hd : Lhat ω θ - Lhat ω θ' = (1 / (n : ℝ)) * ∑ i, (ℓ (Z i ω) θ - ℓ (Z i ω) θ') := by\n rw [hLhatdef, hLhatdef, Finset.sum_sub_distrib]; ring\n rw [hd, abs_mul, abs_of_nonneg (by positivity : (0 : ℝ) ≤ 1 / (n : ℝ))]\n have hs : |∑ i, (ℓ (Z i ω) θ - ℓ (Z i ω) θ')| ≤ (n : ℝ) * (κ * dist θ θ') := by\n calc |∑ i, (ℓ (Z i ω) θ - ℓ (Z i ω) θ')|\n ≤ ∑ i, |ℓ (Z i ω) θ - ℓ (Z i ω) θ'| := Finset.abs_sum_le_sum_abs _ _\n _ ≤ ∑ _i : Fin n, κ * dist θ θ' :=\n Finset.sum_le_sum (fun i _ => hLip (Z i ω) θ θ' h1 h2)\n _ = (n : ℝ) * (κ * dist θ θ') := by\n simp [Finset.sum_const, Fintype.card_fin]\n calc 1 / (n : ℝ) * |∑ i, (ℓ (Z i ω) θ - ℓ (Z i ω) θ')|\n ≤ 1 / (n : ℝ) * ((n : ℝ) * (κ * dist θ θ')) :=\n mul_le_mul_of_nonneg_left hs (by positivity)\n _ = κ * dist θ θ' := by field_simp\n -- Hoeffding at each cover point\n have hhoeff : ∀ θ : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B →\n μ.real {ω | δ ≤ |Lhat ω θ - L θ|} ≤ 2 * Real.exp (-(32 * (p : ℝ) * M)) := by\n intro θ hθ\n have hXindep : iIndepFun (fun i ω => ℓ (Z i ω) θ) μ :=\n hindep.comp (fun _ => fun z => ℓ z θ) (fun _ => hmeasℓ θ)\n have hbound : ∀ i : Fin n, ∀ᵐ ω ∂μ, ℓ (Z i ω) θ ∈ Set.Icc ((fun _ : Fin n => (0 : ℝ)) i)\n ((fun _ : Fin n => (1 : ℝ)) i) :=\n fun i => Filter.Eventually.of_forall (fun ω => hIcc _ _ hθ)\n have hh := local_hoeffding_sum μ hXindep (a := fun _ => (0 : ℝ))\n (b := fun _ => (1 : ℝ)) hbound (fun i => hameas i θ) (ε := (n : ℝ) * δ)\n (by positivity)\n have hset : {ω | δ ≤ |Lhat ω θ - L θ|} =\n {ω | (n : ℝ) * δ ≤ |∑ i : Fin n, (ℓ (Z i ω) θ - ∫ x, ℓ (Z i x) θ ∂μ)|} := by\n ext ω\n simp only [Set.mem_setOf_eq]\n have hs : ∑ i : Fin n, (ℓ (Z i ω) θ - ∫ x, ℓ (Z i x) θ ∂μ) = (n : ℝ) * (Lhat ω θ - L θ) := by\n simp only [hEq]\n rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin,\n nsmul_eq_mul, hLhatdef]\n field_simp\n rw [hs, abs_mul, abs_of_nonneg hn0.le]\n exact ⟨fun hc => by nlinarith, fun hc => by nlinarith⟩\n rw [hset]\n refine hh.trans ?_\n have hsum : (2 * (∑ _i : Fin n, (((‖(1 : ℝ) - 0‖₊ : ℝ)) / 2) ^ 2)) = (n : ℝ) / 2 := by\n simp [Finset.sum_const, Fintype.card_fin]\n ring\n rw [hsum]\n have harg : -((n : ℝ) * δ) ^ 2 / ((n : ℝ) / 2) = -(32 * (p : ℝ) * M) := by\n have h1 : ((n : ℝ) * δ) ^ 2 = (n : ℝ) ^ 2 * (16 * r) := by rw [mul_pow, hδ2]\n rw [h1, hrdef]\n field_simp\n ring\n rw [harg]\n -- the bad event\n classical\n set good : Set Ω := {ω | ∀ θ : EuclideanSpace ℝ (Fin p), ‖θ‖ ≤ B →\n |Lhat ω θ - L θ| ≤ 8 * Real.sqrt r} with hgooddef\n set bad : Set Ω := ⋃ θ ∈ T, {ω | δ ≤ |Lhat ω θ - L θ|} with hbaddef\n have hcompl : ∀ ω, ω ∉ bad → ω ∈ good := by\n intro ω hω θ hθ\n obtain ⟨θ₀, hθ₀T, hθ₀d⟩ := hcover θ hθ\n have hnb : ¬ (δ ≤ |Lhat ω θ₀ - L θ₀|) := by\n intro hc\n exact hω (by rw [hbaddef]; exact Set.mem_biUnion hθ₀T hc)\n have hb : |Lhat ω θ₀ - L θ₀| < δ := lt_of_not_ge hnb\n have h1 : |Lhat ω θ - Lhat ω θ₀| ≤ κ * dist θ θ₀ := hLhatlip ω θ θ₀ hθ (hTnorm θ₀ hθ₀T)\n have h2 : |L θ₀ - L θ| ≤ κ * dist θ₀ θ := hLlip θ₀ θ (hTnorm θ₀ hθ₀T) hθ\n have h3 : κ * dist θ θ₀ ≤ δ / 2 := by\n have : κ * dist θ θ₀ ≤ κ * ε := by\n exact mul_le_mul_of_nonneg_left hθ₀d hκ\n linarith\n have h4 : κ * dist θ₀ θ ≤ δ / 2 := by\n rw [dist_comm]; exact h3\n have a1 := abs_le.mp h1\n have a2 := abs_le.mp h2\n have a3 := abs_le.mp hb.le\n have : |Lhat ω θ - L θ| ≤ 2 * δ :=\n abs_le.mpr ⟨by linarith [a1.1, a1.2, a2.1, a2.2, a3.1, a3.2],\n by linarith [a1.1, a1.2, a2.1, a2.2, a3.1, a3.2]⟩\n rw [hδdef] at this\n linarith\n -- probability of the bad event\n have hbadle : μ.real bad ≤ 2 * Real.exp (-1 * (p : ℝ)) := by\n have hb1 : μ.real bad ≤ ∑ θ ∈ T, μ.real {ω | δ ≤ |Lhat ω θ - L θ|} := by\n rw [hbaddef]; exact measureReal_biUnion_finset_le T _\n have hb2 : ∑ θ ∈ T, μ.real {ω | δ ≤ |Lhat ω θ - L θ|}\n ≤ ∑ _θ ∈ T, 2 * Real.exp (-(32 * (p : ℝ) * M)) :=\n Finset.sum_le_sum (fun θ hθ => hhoeff θ (hTnorm θ hθ))\n rw [Finset.sum_const, nsmul_eq_mul] at hb2\n have hb3 : (T.card : ℝ) * (2 * Real.exp (-(32 * (p : ℝ) * M)))\n ≤ (3 + 4 * κ * B / δ) ^ p * (2 * Real.exp (-(32 * (p : ℝ) * M))) := by\n apply mul_le_mul_of_nonneg_right hcard\n positivity\n have hXnn : (0 : ℝ) ≤ 3 + 4 * κ * B / δ := by\n have : (0 : ℝ) ≤ 4 * κ * B / δ := div_nonneg (by nlinarith) hδpos.le\n linarith\n have hb4 : (3 + 4 * κ * B / δ) ^ p ≤ (Real.exp (31 * M)) ^ p := by\n exact pow_le_pow_left₀ hXnn hXexp p\n have hb5 : (Real.exp (31 * M)) ^ p = Real.exp ((p : ℝ) * (31 * M)) :=\n (Real.exp_nat_mul (31 * M) p).symm\n have hb6 : Real.exp ((p : ℝ) * (31 * M)) * (2 * Real.exp (-(32 * (p : ℝ) * M)))\n = 2 * Real.exp (-((p : ℝ) * M)) := by\n rw [show Real.exp ((p : ℝ) * (31 * M)) * (2 * Real.exp (-(32 * (p : ℝ) * M)))\n = 2 * (Real.exp ((p : ℝ) * (31 * M)) * Real.exp (-(32 * (p : ℝ) * M))) by ring,\n ← Real.exp_add]\n congr 2\n ring\n have hb7 : Real.exp (-((p : ℝ) * M)) ≤ Real.exp (-1 * (p : ℝ)) := by\n apply Real.exp_le_exp.mpr\n nlinarith\n have hb8 : (3 + 4 * κ * B / δ) ^ p * (2 * Real.exp (-(32 * (p : ℝ) * M)))\n ≤ Real.exp ((p : ℝ) * (31 * M)) * (2 * Real.exp (-(32 * (p : ℝ) * M))) := by\n apply mul_le_mul_of_nonneg_right _ (by positivity)\n rw [← hb5]; exact hb4\n linarith\n -- conclude\n have hgeq : (1 : ℝ) ≤ μ.real good + μ.real bad := by\n have hsub : (Set.univ : Set Ω) ⊆ good ∪ bad := by\n intro ω _\n by_cases h : ω ∈ bad\n · exact Or.inr h\n · exact Or.inl (hcompl ω h)\n have h1 : (1 : ℝ) = μ.real (Set.univ : Set Ω) := by simp\n calc (1 : ℝ) = μ.real (Set.univ : Set Ω) := h1\n _ ≤ μ.real (good ∪ bad) := measureReal_mono hsub\n _ ≤ μ.real good + μ.real bad := measureReal_union_le _ _\n show 1 - 2 * Real.exp (-1 * (p : ℝ)) ≤ μ.real good\n linarith\n\nend GraduateLevel\n"} +{"id": "ch5_theorem_5_10", "source": "Graduate-level", "targets": [{"label": "ch5_theorem_5_10", "decls": ["ch5_theorem_5_10"], "statement": "Let \\(C(\\theta)=\\sum_{j=1}^{m}\\left|w_{j}\\right|\\left\\|u_{j}\\right\\|_{2}\\), and for some constant \\(B > 0\\) consider the hypothesis class\n\\[\n\\mathcal{H}=\\left\\{f_{\\theta} \\mid C(\\theta) \\leq B\\right\\}.\n\\]\nIf \\(\\left\\|x^{(i)}\\right\\|_{2} \\leq C\\) for all \\(i \\in\\{1, \\ldots, n\\}\\), then\n\\[\nR_{S}(\\mathcal{H}) \\leq \\frac{2 B C}{\\sqrt{n}}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Due to the positive homogeneity of the ReLU function \\(\\phi\\), it will be useful to define the \\(\\ell_2\\)-normalized weight vector \\(\\bar{u}_j \\stackrel{\\Delta}{=} u_j / \\|u_j\\|_2\\) so that \\(\\phi\\left(u_j^\\top x\\right) = \\|u_j\\|_2 \\cdot \\phi(\\bar{u}_j^\\top x)\\). The empirical Rademacher complexity satisfies\n\\[\n\\begin{aligned}\nR_S(\\mathcal{H}) &= \\frac{1}{n}\\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\sum_{i=1}^n \\sigma_i f_{\\theta}\\left(x^{(i)}\\right) \\right] \\\\\n&= \\frac{1}{n}\\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\sum_{i=1}^n \\sigma_i \\left[\\sum_{j=1}^m w_j \\phi\\left(u_j^\\top x^{(i)}\\right) \\right] \\right] \\quad \\text{(by definition of }f_\\theta\\text{)} \\\\\n&= \\frac{1}{n}\\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\sum_{i=1}^n \\sigma_i \\left[\\sum_{j=1}^m w_j \\|u_j\\|_2 \\phi\\left(\\bar{u}_j^\\top x^{(i)}\\right) \\right] \\right] \\quad \\text{(by positive homogeneity of }\\phi\\text{)} \\\\\n&= \\frac{1}{n}\\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\sum_{j=1}^m w_j \\|u_j\\|_2 \\left[ \\sum_{i=1}^n \\sigma_i \\phi\\left(\\bar{u}_j^\\top x^{(i)}\\right) \\right] \\right] \\\\\n&\\leq \\frac{1}{n}\\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\sum_{j=1}^m |w_j| \\|u_j\\|_2 \\max_{k \\in [n]}\\left| \\sum_{i=1}^n \\sigma_i \\phi\\left(\\bar{u}_k^\\top x^{(i)}\\right) \\right| \\right] \\quad \\left(\\text{because }\\sum_j \\alpha_j \\beta_j \\leq \\sum_j |\\alpha_j| \\max_{k} |\\beta_k|\\right) \\\\\n&\\leq \\frac{B}{n} \\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta = (w, U)} \\max_{k \\in [n]} \\left| \\sum_{i=1}^n \\sigma_i \\phi\\left(\\bar{u}_k^\\top x^{(i)}\\right) \\right| \\right] \\quad \\text{(because }C(\\theta) \\leq B\\text{)} \\\\\n&= \\frac{B}{n} \\mathbb{E}_{\\sigma}\\left[ \\sup_{\\bar{u}: \\|\\bar{u}\\|_2 = 1} \\left| \\sum_{i=1}^n \\sigma_i \\phi\\left(\\bar{u}^\\top x^{(i)}\\right) \\right| \\right] \\\\\n&\\le \\frac{B}{n} \\mathbb{E}_{\\sigma}\\left[ \\sup_{\\bar{u}: \\|\\bar{u}\\|_2 \\le 1} \\left| \\sum_{i=1}^n \\sigma_i \\phi\\left(\\bar{u}^\\top x^{(i)}\\right) \\right| \\right] \\\\\n&\\le \\frac{2B}{n} \\mathbb{E}_{\\sigma}\\left[ \\sup_{\\bar{u}: \\|\\bar{u}\\|_2 \\le 1} \\sum_{i=1}^n \\sigma_i \\phi\\left(\\bar{u}^\\top x^{(i)}\\right) \\right] \\quad \\text{(see the referenced result)} \\\\\n&= 2B \\cdot R_S(\\mathcal{H}'),\n\\end{aligned}\n\\]\nwhere \\(\\mathcal{H}' = \\left\\{x \\mapsto \\phi(\\bar{u}^\\top x) : \\bar{u} \\in \\mathbb{R}^d, \\|\\bar{u}\\|_2 \\leq 1 \\right\\}\\). By Talagrand's lemma, since \\(\\phi\\) is \\(1\\)-Lipschitz, \\(R_S(\\mathcal{H}') \\leq R_S(\\mathcal{H}'')\\) where \\(\\mathcal{H}'' = \\left\\{x \\mapsto \\bar{u}^\\top x : \\bar{u} \\in \\mathbb{R}^d, \\|\\bar{u}\\|_2 \\leq 1 \\right\\}\\) is a linear hypothesis space. Using \\(R_S(\\mathcal{H}'') \\leq \\frac{C}{\\sqrt{n}}\\) by the referenced \\(\\ell_2\\) linear-model theorem then concludes the proof.\n\nNotably, the referenced lemma's assumption holds in the current context, since\n\\[\n\\sup_{\\theta} \\langle \\sigma, f_{\\theta}(x) \\rangle = \\sup_{\\bar{u}: \\|\\bar{u}\\|_2 \\le 1} \\sum_{i=1}^n \\sigma_i \\phi\\left(\\bar{u}^\\top x^{(i)}\\right) \\geq 0,\n\\]\nsince one can take \\(\\bar{u} = 0\\) for any \\(\\sigma = (\\sigma_1, \\dots, \\sigma_n)\\).", "context": [{"id": "ch5:lemma:5_12", "name": "Removing the absolute value in Rademacher complexity", "statement": "Let \\(\\sigma = (\\sigma_1, \\dots, \\sigma_n)\\) and \\(f_{\\theta}(x) = \\left(f_{\\theta}\\left(x^{(1)}\\right), \\dots, f_{\\theta}\\left(x^{(n)}\\right)\\right)\\). Suppose that for any \\(\\sigma \\in \\{\\pm 1\\}^n\\), \\(\\sup_{\\theta} \\langle \\sigma, f_{\\theta}(x) \\rangle \\geq 0\\). Then,\n\\[\n\\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\left| \\langle \\sigma, f_{\\theta}(x) \\rangle \\right| \\right] \\leq 2\\, \\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\langle \\sigma, f_{\\theta}(x) \\rangle \\right].\n\\]"}, {"id": "ch5:lemma:5_3", "name": "Talagrand's lemma", "statement": "Let \\(\\phi:\\mathbb{R}\\to\\mathbb{R}\\) be a \\(\\kappa\\)-Lipschitz function. Then\n\\[\nR_S(\\phi\\circ \\mathcal{H})\\leq \\kappa R_S(\\mathcal{H}),\n\\]\nwhere \\(\\phi\\circ\\mathcal{H} = \\{z\\mapsto \\phi(h(z))\\mid h\\in\\mathcal{H}\\}\\)."}, {"id": "ch5:theorem:5_5", "name": "Rademacher complexity of l2-bounded linear functions", "statement": "Let \\(\\mathcal{H} = \\{x \\mapsto \\langle w,x \\rangle \\mid w \\in \\mathbb{R}^d,\\, \\|w\\|_2 \\le B\\}\\) for some constant \\(B > 0\\). Moreover, assume \\(\\mathbb{E}_{x \\sim P}[\\|x\\|_2^2] \\leq C^2\\), where \\(P\\) is some distribution and \\(C > 0\\) is a constant. Then\n\\[\nR_S(\\mathcal{H}) \\le \\frac{B}{n} \\sqrt{\\sum_{i=1}^n \\|x^{(i)}\\|_2^2},\n\\]\nand\n\\[\nR_n(\\mathcal{H}) \\le \\frac{BC}{\\sqrt{n}}.\n\\]"}, {"id": "ch4:definition:4_17", "name": "Empirical Rademacher complexity", "statement": "Given a dataset \\(S = \\{z_1, \\dots, z_n\\}\\), the empirical Rademacher complexity is defined as\n\\[\nR_S(\\mathcal{F}) \\stackrel{\\Delta}{=} \\mathbb{E}_{\\sigma_1,\\dots, \\sigma_n} \\left[ \\sup_{f\\in \\mathcal{F}} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i) \\right].\n\\]\n\\(R_S(\\mathcal{F})\\) is a function of both the function class \\(\\mathcal{F}\\) and the dataset \\(S\\)."}, {"id": "ch5:definition:two_layer_relu_network", "name": "Two-layer ReLU network", "statement": "Given a width \\(m\\), let \\(w_1,\\dots,w_m \\in \\mathbb{R}\\), \\(u_1,\\dots,u_m \\in \\mathbb{R}^d\\), and let \\(\\phi\\) denote the ReLU activation. For \\(\\theta=(w_1,\\dots,w_m,u_1,\\dots,u_m)\\), define the two-layer ReLU network\n\\[\nf_{\\theta}(x)=\\sum_{j=1}^m w_j \\phi\\left(u_j^\\top x\\right).\n\\]"}], "lean": "import Mathlib\n\nopen scoped BigOperators\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ndef relu (x : ℝ) : ℝ := max 0 x\n\nnoncomputable def pathNorm {m d : ℕ} (w : Fin m → ℝ) (u : Fin m → EuclideanSpace ℝ (Fin d)) : ℝ :=\n ∑ j : Fin m, |w j| * ‖u j‖\n\nnoncomputable def predict {m d : ℕ} (w : Fin m → ℝ) (u : Fin m → EuclideanSpace ℝ (Fin d))\n (x : EuclideanSpace ℝ (Fin d)) : ℝ :=\n ∑ j : Fin m, w j * relu (inner ℝ (u j) x)\n\ntheorem ch5_theorem_5_10\n {m d n : ℕ} (B : ℝ) (Cdata : ℝ)\n (hn : 0 < n) (hB : 0 < B) (hCdata : 0 ≤ Cdata)\n (x : Fin n → EuclideanSpace ℝ (Fin d))\n (hx : ∀ i, ‖x i‖ ≤ Cdata)\n (F : {θ : (Fin m → ℝ) × (Fin m → EuclideanSpace ℝ (Fin d)) // pathNorm θ.1 θ.2 ≤ B}\n → EuclideanSpace ℝ (Fin d) → ℝ)\n (hF : ∀ θ, F θ = predict (θ : (Fin m → ℝ) × (Fin m → EuclideanSpace ℝ (Fin d))).1\n (θ : (Fin m → ℝ) × (Fin m → EuclideanSpace ℝ (Fin d))).2) :\n empRadSigned n F x ≤ 2 * B * Cdata / Real.sqrt n := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped BigOperators\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ndef relu (x : ℝ) : ℝ := max 0 x\n\nnoncomputable def pathNorm {m d : ℕ} (w : Fin m → ℝ) (u : Fin m → EuclideanSpace ℝ (Fin d)) : ℝ :=\n ∑ j : Fin m, |w j| * ‖u j‖\n\nnoncomputable def predict {m d : ℕ} (w : Fin m → ℝ) (u : Fin m → EuclideanSpace ℝ (Fin d))\n (x : EuclideanSpace ℝ (Fin d)) : ℝ :=\n ∑ j : Fin m, w j * relu (inner ℝ (u j) x)\n\nsection Aux\n\nvariable {n d : ℕ}\n\nnoncomputable def sgn (σ : RadSigns n) (k : Fin n) : ℝ := ((σ k : ℤ) : ℝ)\n\nlemma sgn_cases (σ : RadSigns n) (k : Fin n) : sgn σ k = -1 ∨ sgn σ k = 1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h\n · left; simp [sgn, h]\n · right; simp [sgn, h]\n\nlemma abs_sgn (σ : RadSigns n) (k : Fin n) : |sgn σ k| = 1 := by\n rcases sgn_cases σ k with h | h <;> simp [h]\n\nlemma sgn_mul_self (σ : RadSigns n) (k : Fin n) : sgn σ k * sgn σ k = 1 := by\n rcases sgn_cases σ k with h | h <;> simp [h]\n\ndef negIdx (s : ({-1, 1} : Finset ℤ)) : ({-1, 1} : Finset ℤ) :=\n ⟨-(s : ℤ), by\n have h := s.2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h ⊢\n rcases h with h | h <;> simp [h]⟩\n\nlemma negIdx_involutive : Function.Involutive (negIdx) := by\n intro s\n apply Subtype.ext\n simp [negIdx]\n\ndef flipAt (j : Fin n) (σ : RadSigns n) : RadSigns n :=\n fun k => if k = j then negIdx (σ k) else σ k\n\ndef negAll (σ : RadSigns n) : RadSigns n := fun k => negIdx (σ k)\n\nlemma flipAt_involutive (j : Fin n) : Function.Involutive (flipAt j : RadSigns n → RadSigns n) := by\n intro σ\n funext k\n by_cases h : k = j\n · subst h\n simp only [flipAt, if_pos rfl]\n exact negIdx_involutive (σ k)\n · simp [flipAt, h]\n\nlemma negAll_involutive : Function.Involutive (negAll : RadSigns n → RadSigns n) := by\n intro σ\n funext k\n simp [negAll, negIdx_involutive (σ k)]\n\nlemma sgn_flipAt_self (j : Fin n) (σ : RadSigns n) : sgn (flipAt j σ) j = - sgn σ j := by\n simp [sgn, flipAt, negIdx]\n\nlemma sgn_flipAt_ne (j : Fin n) (σ : RadSigns n) {k : Fin n} (h : k ≠ j) :\n sgn (flipAt j σ) k = sgn σ k := by\n simp [sgn, flipAt, h]\n\nlemma sgn_negAll (σ : RadSigns n) (k : Fin n) : sgn (negAll σ) k = - sgn σ k := by\n simp [sgn, negAll, negIdx]\n\nlemma sum_flipAt (j : Fin n) (f : RadSigns n → ℝ) : ∑ σ : RadSigns n, f (flipAt j σ) = ∑ σ, f σ :=\n Equiv.sum_comp (Function.Involutive.toPerm _ (flipAt_involutive j)) f\n\nlemma sum_negAll (f : RadSigns n → ℝ) : ∑ σ : RadSigns n, f (negAll σ) = ∑ σ, f σ :=\n Equiv.sum_comp (Function.Involutive.toPerm _ negAll_involutive) f\n\nlemma relu_nonneg (t : ℝ) : 0 ≤ relu t := le_max_left _ _\n\nlemma relu_zero : relu 0 = 0 := by simp [relu]\n\nlemma abs_relu_le (t : ℝ) : |relu t| ≤ |t| := by\n rw [abs_of_nonneg (relu_nonneg t)]\n rcases le_total 0 t with h | h\n · simp [relu, max_eq_right h, abs_of_nonneg h]\n · simp [relu, max_eq_left h]\n\nlemma relu_lipschitz (a b : ℝ) : |relu a - relu b| ≤ |a - b| := by\n simp only [relu, max_comm (0:ℝ)]\n exact abs_max_sub_max_le_abs a b 0\n\nlemma relu_smul {c t : ℝ} (hc : 0 ≤ c) : relu (c * t) = c * relu t := by\n simp only [relu]\n rcases le_total 0 t with h | h\n · rw [max_eq_right h, max_eq_right (by positivity)]\n · rw [max_eq_left h, max_eq_left (by nlinarith), mul_zero]\n\ninstance instNeRad (n : ℕ) : Nonempty (RadSigns n) := ⟨fun _ => ⟨1, by decide⟩⟩\n\nabbrev Ball (d : ℕ) := {v : EuclideanSpace ℝ (Fin d) // ‖v‖ ≤ 1}\n\ninstance : Nonempty (Ball d) := ⟨⟨0, by simp⟩⟩\n\nvariable (x : Fin n → EuclideanSpace ℝ (Fin d))\n\nnoncomputable def gg (S : Finset (Fin n)) (v : Ball d) (k : Fin n) : ℝ :=\n if k ∈ S then relu (inner ℝ (v : EuclideanSpace ℝ (Fin d)) (x k))\n else (inner ℝ (v : EuclideanSpace ℝ (Fin d)) (x k) : ℝ)\n\nnoncomputable def Psi (S : Finset (Fin n)) (σ : RadSigns n) : ℝ :=\n ⨆ v : Ball d, ∑ k, sgn σ k * gg x S v k\n\nlemma abs_gg_le (S : Finset (Fin n)) (v : Ball d) (k : Fin n) : |gg x S v k| ≤ ‖x k‖ := by\n have hi : |(inner ℝ (v : EuclideanSpace ℝ (Fin d)) (x k) : ℝ)| ≤ ‖x k‖ := by\n have := abs_real_inner_le_norm (v : EuclideanSpace ℝ (Fin d)) (x k)\n have h2 : ‖(v : EuclideanSpace ℝ (Fin d))‖ * ‖x k‖ ≤ 1 * ‖x k‖ :=\n mul_le_mul_of_nonneg_right v.2 (norm_nonneg _)\n linarith\n unfold gg\n split\n · exact le_trans (abs_relu_le _) hi\n · exact hi\n\nlemma bdd_Psi (S : Finset (Fin n)) (σ : RadSigns n) :\n BddAbove (Set.range fun v : Ball d => ∑ k, sgn σ k * gg x S v k) := by\n refine ⟨∑ k, ‖x k‖, ?_⟩\n rintro y ⟨v, rfl⟩\n refine le_trans (le_abs_self _) ?_\n refine le_trans (Finset.abs_sum_le_sum_abs _ _) ?_\n refine Finset.sum_le_sum (fun k _ => ?_)\n rw [abs_mul, abs_sgn, one_mul]\n exact abs_gg_le x S v k\n\nlemma Psi_nonneg (S : Finset (Fin n)) (σ : RadSigns n) : 0 ≤ Psi x S σ := by\n have h : (0:ℝ) = ∑ k, sgn σ k * gg x S (⟨0, by simp⟩ : Ball d) k := by\n symm\n refine Finset.sum_eq_zero (fun k _ => ?_)\n have : gg x S (⟨0, by simp⟩ : Ball d) k = 0 := by\n unfold gg\n split <;> simp [relu_zero]\n rw [this, mul_zero]\n rw [h]\n exact le_ciSup (bdd_Psi x S σ) _\n\nlemma sup_le_two_terms {W : Type*} [Nonempty W] (A a R : W → ℝ) (p : ℝ) (hp : p = 1 ∨ p = -1)\n (hlip : ∀ v v' : W, |A v - A v'| ≤ |a v - a v'|)\n (hb1 : BddAbove (Set.range fun v => p * a v + R v))\n (hb2 : BddAbove (Set.range fun v => -(p * a v) + R v)) :\n (⨆ v, p * A v + R v) + (⨆ v, -(p * A v) + R v)\n ≤ (⨆ v, p * a v + R v) + (⨆ v, -(p * a v) + R v) := by\n have key : ∀ v v' : W, (p * A v + R v) + (-(p * A v') + R v')\n ≤ (⨆ v, p * a v + R v) + (⨆ v, -(p * a v) + R v) := by\n intro v v'\n have h1 := le_ciSup hb1 v\n have h2 := le_ciSup hb2 v'\n have h3 := le_ciSup hb1 v'\n have h4 := le_ciSup hb2 v\n have hL1 : A v - A v' ≤ |a v - a v'| := le_trans (le_abs_self _) (hlip v v')\n have hL2 : A v' - A v ≤ |a v - a v'| := by\n have h := le_trans (le_abs_self _) (hlip v' v)\n rwa [abs_sub_comm (a v')] at h\n simp only at h1 h2 h3 h4\n rcases hp with rfl | rfl <;>\n rcases abs_cases (a v - a v') with ⟨he, _⟩ | ⟨he, _⟩ <;> rw [he] at hL1 hL2 <;> linarith\n have hA : (⨆ v, p * A v + R v)\n ≤ (⨆ v, p * a v + R v) + (⨆ v, -(p * a v) + R v) - (⨆ v', -(p * A v') + R v') := by\n apply ciSup_le\n intro v\n have h : (⨆ v', -(p * A v') + R v')\n ≤ (⨆ v, p * a v + R v) + (⨆ v, -(p * a v) + R v) - (p * A v + R v) := by\n apply ciSup_le\n intro v'\n linarith [key v v']\n linarith\n linarith\n\nlemma contraction_step (S : Finset (Fin n)) (j : Fin n) (hj : j ∉ S) :\n ∑ σ : RadSigns n, Psi x (insert j S) σ ≤ ∑ σ : RadSigns n, Psi x S σ := by\n have pt : ∀ σ : RadSigns n, Psi x (insert j S) σ + Psi x (insert j S) (flipAt j σ)\n ≤ Psi x S σ + Psi x S (flipAt j σ) := by\n intro σ\n set A : Ball d → ℝ := fun v => relu (inner ℝ (v : EuclideanSpace ℝ (Fin d)) (x j)) with hA\n set a : Ball d → ℝ := fun v => (inner ℝ (v : EuclideanSpace ℝ (Fin d)) (x j) : ℝ) with ha\n set R : Ball d → ℝ := fun v => ∑ k ∈ Finset.univ.erase j, sgn σ k * gg x S v k with hR\n have e1 : (fun v : Ball d => ∑ k, sgn σ k * gg x (insert j S) v k)\n = fun v => sgn σ j * A v + R v := by\n funext v\n rw [← Finset.add_sum_erase _ _ (Finset.mem_univ j)]\n congr 1\n · simp [gg, hA]\n · refine Finset.sum_congr rfl (fun k hk => ?_)\n have hkj : k ≠ j := (Finset.mem_erase.mp hk).1\n simp [gg, hkj]\n have e2 : (fun v : Ball d => ∑ k, sgn (flipAt j σ) k * gg x (insert j S) v k)\n = fun v => -(sgn σ j * A v) + R v := by\n funext v\n rw [← Finset.add_sum_erase _ _ (Finset.mem_univ j)]\n congr 1\n · rw [sgn_flipAt_self]\n simp [gg, hA]\n · refine Finset.sum_congr rfl (fun k hk => ?_)\n have hkj : k ≠ j := (Finset.mem_erase.mp hk).1\n rw [sgn_flipAt_ne j σ hkj]\n simp [gg, hkj]\n have e3 : (fun v : Ball d => ∑ k, sgn σ k * gg x S v k)\n = fun v => sgn σ j * a v + R v := by\n funext v\n rw [← Finset.add_sum_erase _ _ (Finset.mem_univ j)]\n congr 1\n simp [gg, ha, hj]\n have e4 : (fun v : Ball d => ∑ k, sgn (flipAt j σ) k * gg x S v k)\n = fun v => -(sgn σ j * a v) + R v := by\n funext v\n rw [← Finset.add_sum_erase _ _ (Finset.mem_univ j)]\n congr 1\n · rw [sgn_flipAt_self]\n simp [gg, ha, hj]\n · refine Finset.sum_congr rfl (fun k hk => ?_)\n have hkj : k ≠ j := (Finset.mem_erase.mp hk).1\n rw [sgn_flipAt_ne j σ hkj]\n have hb1 : BddAbove (Set.range fun v : Ball d => sgn σ j * a v + R v) := by\n have := bdd_Psi x S σ\n rwa [e3] at this\n have hb2 : BddAbove (Set.range fun v : Ball d => -(sgn σ j * a v) + R v) := by\n have := bdd_Psi x S (flipAt j σ)\n rwa [e4] at this\n have hmain := sup_le_two_terms A a R (sgn σ j)\n (by rcases sgn_cases σ j with h | h; exacts [Or.inr h, Or.inl h])\n (fun v v' => relu_lipschitz _ _) hb1 hb2\n unfold Psi\n rw [e1, e2, e3, e4]\n exact hmain\n have s1 : ∑ σ : RadSigns n, Psi x (insert j S) (flipAt j σ)\n = ∑ σ : RadSigns n, Psi x (insert j S) σ := sum_flipAt j _\n have s2 : ∑ σ : RadSigns n, Psi x S (flipAt j σ) = ∑ σ : RadSigns n, Psi x S σ :=\n sum_flipAt j _\n have hsum : ∑ σ : RadSigns n, (Psi x (insert j S) σ + Psi x (insert j S) (flipAt j σ))\n ≤ ∑ σ : RadSigns n, (Psi x S σ + Psi x S (flipAt j σ)) :=\n Finset.sum_le_sum (fun σ _ => pt σ)\n rw [Finset.sum_add_distrib, Finset.sum_add_distrib, s1, s2] at hsum\n linarith\n\nlemma contraction (S : Finset (Fin n)) :\n ∑ σ : RadSigns n, Psi x S σ ≤ ∑ σ : RadSigns n, Psi x ∅ σ := by\n induction S using Finset.induction_on with\n | empty => exact le_rfl\n | insert j S hj ih => exact le_trans (contraction_step x S j hj) ih\n\nlemma Psi_empty_le (σ : RadSigns n) : Psi x ∅ σ ≤ ‖∑ k, sgn σ k • x k‖ := by\n apply ciSup_le\n intro v\n have hEq : ∑ k, sgn σ k * gg x ∅ v k\n = (inner ℝ (v : EuclideanSpace ℝ (Fin d)) (∑ k, sgn σ k • x k) : ℝ) := by\n rw [inner_sum]\n refine Finset.sum_congr rfl (fun k _ => ?_)\n rw [real_inner_smul_right]\n simp [gg]\n rw [hEq]\n have h1 := abs_real_inner_le_norm (v : EuclideanSpace ℝ (Fin d)) (∑ k, sgn σ k • x k)\n have h2 : ‖(v : EuclideanSpace ℝ (Fin d))‖ * ‖∑ k, sgn σ k • x k‖\n ≤ 1 * ‖∑ k, sgn σ k • x k‖ := mul_le_mul_of_nonneg_right v.2 (norm_nonneg _)\n have := le_abs_self (inner ℝ (v : EuclideanSpace ℝ (Fin d)) (∑ k, sgn σ k • x k) : ℝ)\n linarith\n\nlemma neuron_bound (σ : RadSigns n) (u : EuclideanSpace ℝ (Fin d)) :\n ∑ k, sgn σ k * relu (inner ℝ u (x k)) ≤ ‖u‖ * Psi x Finset.univ σ := by\n rcases eq_or_lt_of_le (norm_nonneg u) with h | h\n · have hu : u = 0 := by\n have : ‖u‖ = 0 := h.symm\n simpa using this\n subst hu\n simp [relu_zero, ← h]\n · set c := ‖u‖ with hc\n have hcpos : 0 < c := h\n have hv : ‖(c⁻¹ • u : EuclideanSpace ℝ (Fin d))‖ ≤ 1 := by\n rw [norm_smul]\n simp [abs_of_pos (inv_pos.mpr hcpos), hc]\n rw [inv_mul_cancel₀ (ne_of_gt hcpos)]\n set v : Ball d := ⟨c⁻¹ • u, hv⟩ with hvdef\n have hterm : ∀ k, sgn σ k * gg x Finset.univ v k\n = c⁻¹ * (sgn σ k * relu (inner ℝ u (x k))) := by\n intro k\n have : (inner ℝ (v : EuclideanSpace ℝ (Fin d)) (x k) : ℝ)\n = c⁻¹ * (inner ℝ u (x k) : ℝ) := by\n simp [hvdef, real_inner_smul_left]\n simp only [gg, Finset.mem_univ, if_true, this,\n relu_smul (le_of_lt (inv_pos.mpr hcpos))]\n ring\n have hle : ∑ k, sgn σ k * gg x Finset.univ v k ≤ Psi x Finset.univ σ :=\n le_ciSup (bdd_Psi x Finset.univ σ) v\n rw [Finset.sum_congr rfl (fun k _ => hterm k), ← Finset.mul_sum] at hle\n have := mul_le_mul_of_nonneg_left hle (le_of_lt hcpos)\n rw [← mul_assoc, mul_inv_cancel₀ (ne_of_gt hcpos), one_mul] at this\n exact this\n\nlemma neuron_bound_abs (σ : RadSigns n) (u : EuclideanSpace ℝ (Fin d)) :\n |∑ k, sgn σ k * relu (inner ℝ u (x k))|\n ≤ ‖u‖ * (Psi x Finset.univ σ + Psi x Finset.univ (negAll σ)) := by\n have h1 := neuron_bound x σ u\n have h2 := neuron_bound x (negAll σ) u\n have h2' : -∑ k, sgn σ k * relu (inner ℝ u (x k)) ≤ ‖u‖ * Psi x Finset.univ (negAll σ) := by\n have : ∑ k, sgn (negAll σ) k * relu (inner ℝ u (x k))\n = -∑ k, sgn σ k * relu (inner ℝ u (x k)) := by\n rw [← Finset.sum_neg_distrib]\n refine Finset.sum_congr rfl (fun k _ => ?_)\n rw [sgn_negAll]\n ring\n rw [this] at h2\n exact h2\n have hn1 : 0 ≤ ‖u‖ * Psi x Finset.univ σ :=\n mul_nonneg (norm_nonneg _) (Psi_nonneg x _ _)\n have hn2 : 0 ≤ ‖u‖ * Psi x Finset.univ (negAll σ) :=\n mul_nonneg (norm_nonneg _) (Psi_nonneg x _ _)\n rw [mul_add]\n rcases abs_cases (∑ k, sgn σ k * relu (inner ℝ u (x k))) with ⟨he, _⟩ | ⟨he, _⟩ <;>\n rw [he] <;> linarith\n\nlemma orth (k l : Fin n) (hkl : k ≠ l) : ∑ σ : RadSigns n, sgn σ k * sgn σ l = 0 := by\n have h : ∑ σ : RadSigns n, sgn (flipAt k σ) k * sgn (flipAt k σ) l\n = ∑ σ : RadSigns n, sgn σ k * sgn σ l :=\n sum_flipAt k (fun σ => sgn σ k * sgn σ l)\n have h2 : ∀ σ : RadSigns n, sgn (flipAt k σ) k * sgn (flipAt k σ) l\n = -(sgn σ k * sgn σ l) := by\n intro σ\n rw [sgn_flipAt_self, sgn_flipAt_ne k σ (Ne.symm hkl)]\n ring\n rw [Finset.sum_congr rfl (fun σ _ => h2 σ)] at h\n have h3 : ∑ σ : RadSigns n, -(sgn σ k * sgn σ l) = -∑ σ : RadSigns n, sgn σ k * sgn σ l := by\n simp\n rw [h3] at h\n linarith\n\nlemma sum_norm_sq :\n ∑ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖ ^ 2\n = (Fintype.card (RadSigns n) : ℝ) * ∑ k, ‖x k‖ ^ 2 := by\n have expand : ∀ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖ ^ 2\n = ∑ k, ∑ l, (sgn σ k * sgn σ l) * (inner ℝ (x k) (x l) : ℝ) := by\n intro σ\n rw [← real_inner_self_eq_norm_sq]\n rw [sum_inner]\n refine Finset.sum_congr rfl (fun k _ => ?_)\n rw [real_inner_smul_left, inner_sum, Finset.mul_sum]\n refine Finset.sum_congr rfl (fun l _ => ?_)\n rw [real_inner_smul_right]\n ring\n rw [Finset.sum_congr rfl (fun σ _ => expand σ)]\n rw [Finset.sum_comm]\n have : ∀ k : Fin n, ∑ σ : RadSigns n, ∑ l, (sgn σ k * sgn σ l) * (inner ℝ (x k) (x l) : ℝ)\n = (Fintype.card (RadSigns n) : ℝ) * ‖x k‖ ^ 2 := by\n intro k\n rw [Finset.sum_comm]\n have hz : ∀ l : Fin n, l ∈ (Finset.univ : Finset (Fin n)) → l ≠ k →\n ∑ σ : RadSigns n, (sgn σ k * sgn σ l) * (inner ℝ (x k) (x l) : ℝ) = 0 := by\n intro l _ hlk\n rw [← Finset.sum_mul, orth k l (Ne.symm hlk), zero_mul]\n rw [Finset.sum_eq_single k hz (by simp)]\n rw [← Finset.sum_mul]\n have : ∑ σ : RadSigns n, sgn σ k * sgn σ k = (Fintype.card (RadSigns n) : ℝ) := by\n simp [sgn_mul_self]\n rw [this, real_inner_self_eq_norm_sq]\n rw [Finset.sum_congr rfl (fun k _ => this k), ← Finset.mul_sum]\n\nend Aux\n\ntheorem ch5_theorem_5_10\n {m d n : ℕ} (B : ℝ) (Cdata : ℝ)\n (hn : 0 < n) (hB : 0 < B) (hCdata : 0 ≤ Cdata)\n (x : Fin n → EuclideanSpace ℝ (Fin d))\n (hx : ∀ i, ‖x i‖ ≤ Cdata)\n (F : {θ : (Fin m → ℝ) × (Fin m → EuclideanSpace ℝ (Fin d)) // pathNorm θ.1 θ.2 ≤ B}\n → EuclideanSpace ℝ (Fin d) → ℝ)\n (hF : ∀ θ, F θ = predict (θ : (Fin m → ℝ) × (Fin m → EuclideanSpace ℝ (Fin d))).1\n (θ : (Fin m → ℝ) × (Fin m → EuclideanSpace ℝ (Fin d))).2) :\n empRadSigned n F x ≤ 2 * B * Cdata / Real.sqrt n := by\n classical\n haveI : Nonempty {θ : (Fin m → ℝ) × (Fin m → EuclideanSpace ℝ (Fin d)) //\n pathNorm θ.1 θ.2 ≤ B} := ⟨⟨(0, 0), by simpa [pathNorm] using hB.le⟩⟩\n set N : ℝ := (Fintype.card (RadSigns n) : ℝ) with hN\n have hNpos : 0 < N := by\n rw [hN]\n exact_mod_cast Fintype.card_pos (α := RadSigns n)\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n have hsqrt : 0 < Real.sqrt n := Real.sqrt_pos.mpr hnR\n have stepA : ∀ σ : RadSigns n,\n (⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * F i (x k))\n ≤ (n:ℝ)⁻¹ * (B * (Psi x Finset.univ σ + Psi x Finset.univ (negAll σ))) := by\n intro σ\n apply ciSup_le\n rintro ⟨⟨w, u⟩, hθ⟩\n have hexp : ∑ k : Fin n, ((σ k : ℤ) : ℝ) * F ⟨(w, u), hθ⟩ (x k)\n = ∑ j : Fin m, w j * ∑ k : Fin n, sgn σ k * relu (inner ℝ (u j) (x k)) := by\n simp only [hF, predict, Finset.mul_sum]\n rw [Finset.sum_comm]\n refine Finset.sum_congr rfl (fun j _ => ?_)\n refine Finset.sum_congr rfl (fun k _ => ?_)\n simp only [sgn]\n ring\n set P : ℝ := Psi x Finset.univ σ + Psi x Finset.univ (negAll σ) with hP\n have hPnn : 0 ≤ P := by\n rw [hP]; exact add_nonneg (Psi_nonneg x _ _) (Psi_nonneg x _ _)\n have hbnd : ∑ k : Fin n, ((σ k : ℤ) : ℝ) * F ⟨(w, u), hθ⟩ (x k) ≤ B * P := by\n rw [hexp]\n have h1 : ∀ j : Fin m, w j * ∑ k : Fin n, sgn σ k * relu (inner ℝ (u j) (x k))\n ≤ (|w j| * ‖u j‖) * P := by\n intro j\n have h2 := neuron_bound_abs x σ (u j)\n have h3 : w j * ∑ k : Fin n, sgn σ k * relu (inner ℝ (u j) (x k))\n ≤ |w j| * |∑ k : Fin n, sgn σ k * relu (inner ℝ (u j) (x k))| := by\n rw [← abs_mul]\n exact le_abs_self _\n have h4 : |w j| * |∑ k : Fin n, sgn σ k * relu (inner ℝ (u j) (x k))|\n ≤ |w j| * (‖u j‖ * P) := mul_le_mul_of_nonneg_left h2 (abs_nonneg _)\n calc w j * ∑ k : Fin n, sgn σ k * relu (inner ℝ (u j) (x k))\n ≤ |w j| * (‖u j‖ * P) := le_trans h3 h4\n _ = (|w j| * ‖u j‖) * P := by ring\n refine le_trans (Finset.sum_le_sum (fun j _ => h1 j)) ?_\n rw [← Finset.sum_mul]\n have : pathNorm w u ≤ B := hθ\n have hpn : ∑ j : Fin m, |w j| * ‖u j‖ ≤ B := this\n exact mul_le_mul_of_nonneg_right hpn hPnn\n have hinv : (0:ℝ) ≤ (n:ℝ)⁻¹ := by positivity\n exact mul_le_mul_of_nonneg_left hbnd hinv\n have hneg : ∑ σ : RadSigns n, Psi x Finset.univ (negAll σ)\n = ∑ σ : RadSigns n, Psi x Finset.univ σ := sum_negAll (fun σ => Psi x Finset.univ σ)\n have hcontr : ∑ σ : RadSigns n, Psi x Finset.univ σ\n ≤ ∑ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖ :=\n le_trans (contraction x Finset.univ) (Finset.sum_le_sum (fun σ _ => Psi_empty_le x σ))\n have hD : ∑ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖ ≤ N * (Cdata * Real.sqrt n) := by\n have hcs : (∑ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖)^2\n ≤ ((Finset.univ : Finset (RadSigns n)).card : ℝ)\n * ∑ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖^2 := sq_sum_le_card_mul_sum_sq\n rw [sum_norm_sq x, Finset.card_univ, ← hN] at hcs\n have hxb : ∑ k, ‖x k‖^2 ≤ (n:ℝ) * Cdata^2 := by\n have hpt : ∀ k : Fin n, ‖x k‖^2 ≤ Cdata^2 := by\n intro k\n have := hx k\n nlinarith [norm_nonneg (x k)]\n calc ∑ k, ‖x k‖^2 ≤ ∑ _k : Fin n, Cdata^2 := Finset.sum_le_sum (fun k _ => hpt k)\n _ = (n:ℝ) * Cdata^2 := by simp [Finset.sum_const, Finset.card_univ]\n have hnonneg : 0 ≤ ∑ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖ :=\n Finset.sum_nonneg (fun _ _ => norm_nonneg _)\n have hRn : 0 ≤ N * (Cdata * Real.sqrt n) := by positivity\n have hmul : N * (N * ∑ k, ‖x k‖^2) ≤ N * (N * ((n:ℝ) * Cdata^2)) := by\n apply mul_le_mul_of_nonneg_left _ hNpos.le\n exact mul_le_mul_of_nonneg_left hxb hNpos.le\n have hexp2 : (N * (Cdata * Real.sqrt n))^2 = N * (N * ((n:ℝ) * Cdata^2)) := by\n rw [mul_pow, mul_pow, Real.sq_sqrt hnR.le]; ring\n have hsq : (∑ σ : RadSigns n, ‖∑ k, sgn σ k • x k‖)^2 ≤ (N * (Cdata * Real.sqrt n))^2 := by\n rw [hexp2]; linarith\n nlinarith [hsq, hnonneg, hRn]\n have hstep : ∑ σ : RadSigns n, (⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * F i (x k))\n ≤ (n:ℝ)⁻¹ * B * (2 * (N * (Cdata * Real.sqrt n))) := by\n refine le_trans (Finset.sum_le_sum (fun σ _ => stepA σ)) ?_\n have e : ∀ σ : RadSigns n,\n (n:ℝ)⁻¹ * (B * (Psi x Finset.univ σ + Psi x Finset.univ (negAll σ)))\n = (n:ℝ)⁻¹ * B * Psi x Finset.univ σ + (n:ℝ)⁻¹ * B * Psi x Finset.univ (negAll σ) := by\n intro σ; ring\n rw [Finset.sum_congr rfl (fun σ _ => e σ), Finset.sum_add_distrib, ← Finset.mul_sum,\n ← Finset.mul_sum, hneg]\n have hcoef : 0 ≤ (n:ℝ)⁻¹ * B := by positivity\n nlinarith [le_trans hcontr hD, hcoef]\n have hfin : N⁻¹ * ∑ σ : RadSigns n, (⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * F i (x k))\n ≤ N⁻¹ * ((n:ℝ)⁻¹ * B * (2 * (N * (Cdata * Real.sqrt n)))) :=\n mul_le_mul_of_nonneg_left hstep (by positivity)\n have heq : N⁻¹ * ((n:ℝ)⁻¹ * B * (2 * (N * (Cdata * Real.sqrt n))))\n = 2 * B * Cdata / Real.sqrt n := by\n have hs : Real.sqrt n * Real.sqrt n = (n:ℝ) := Real.mul_self_sqrt hnR.le\n field_simp\n nlinarith [hs]\n rw [empRadSigned, ← hN]\n rw [← heq]\n exact hfin\n\nend GraduateLevel\n"} +{"id": "ch5_theorem_5_5", "source": "Graduate-level", "targets": [{"label": "ch5_theorem_5_5", "decls": ["ch5_theorem_5_5"], "statement": "Let \\(\\mathcal{H} = \\{x \\mapsto \\langle w,x \\rangle \\mid w \\in \\mathbb{R}^d,\\, \\|w\\|_2 \\le B\\}\\) for some constant \\(B > 0\\). Moreover, assume \\(\\mathbb{E}_{x \\sim P}[\\|x\\|_2^2] \\leq C^2\\), where \\(P\\) is some distribution and \\(C > 0\\) is a constant. Then\n\\[\nR_S(\\mathcal{H}) \\le \\frac{B}{n} \\sqrt{\\sum_{i=1}^n \\|x^{(i)}\\|_2^2},\n\\]\nand\n\\[\nR_n(\\mathcal{H}) \\le \\frac{BC}{\\sqrt{n}}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "By definition,\n\\[\nR_S(\\mathcal{H}) = \\mathbb{E}_\\sigma\\left[ \\sup_{\\|w\\|_2 \\le B} \\frac{1}{n} \\sum_{i=1}^n \\sigma_i \\langle w, x^{(i)} \\rangle \\right] = \\frac{1}{n} \\mathbb{E}_\\sigma\\left[ \\sup_{\\|w\\|_2 \\le B} \\left\\langle w, \\sum_{i=1}^n \\sigma_i x^{(i)} \\right\\rangle \\right] = \\frac{B}{n} \\mathbb{E}_\\sigma\\left[ \\left\\|\\sum_{i=1}^n \\sigma_i x^{(i)}\\right\\|_2 \\right],\n\\]\nusing \\(\\sup_{\\|w\\|_2 \\le B} \\langle w,v\\rangle = B\\|v\\|_2\\). By Jensen's inequality applied to \\(\\alpha \\mapsto \\alpha^2\\),\n\\[\n\\frac{B}{n} \\mathbb{E}_\\sigma\\left[ \\left\\|\\sum_{i=1}^n \\sigma_i x^{(i)}\\right\\|_2 \\right] \\leq \\frac{B}{n} \\sqrt{ \\mathbb{E}_\\sigma\\left[\\left\\|\\sum_{i=1}^n \\sigma_i x^{(i)}\\right\\|_2^2\\right] } = \\frac{B}{n} \\sqrt{\\sum_{i=1}^n \\|x^{(i)}\\|_2^2},\n\\]\nwhere the last equality uses independence of the \\(\\sigma_i\\) and \\(\\mathbb{E}[\\sigma_i] = 0\\). This proves the bound on \\(R_S(\\mathcal{H})\\). For the average Rademacher complexity,\n\\[\nR_n(\\mathcal{H}) = \\mathbb{E}[R_S(\\mathcal{H})] \\le \\frac{B}{n} \\mathbb{E}\\left[\\sqrt{\\sum_{i=1}^n \\|x^{(i)}\\|_2^2}\\right] \\le \\frac{B}{n} \\sqrt{\\sum_{i=1}^n \\mathbb{E}\\left[\\|x^{(i)}\\|_2^2\\right]} \\le \\frac{BC}{\\sqrt{n}},\n\\]\nwhere the first inequality is Jensen's inequality and the second uses \\(\\mathbb{E}_{x \\sim P}[\\|x\\|_2^2] \\leq C^2\\).", "context": [{"id": "ch4:definition:4_17", "name": "Empirical Rademacher complexity", "statement": "Given a dataset \\(S = \\{z_1, \\dots, z_n\\}\\), the empirical Rademacher complexity is defined as\n\\[\nR_S(\\mathcal{F}) \\stackrel{\\Delta}{=} \\mathbb{E}_{\\sigma_1,\\dots, \\sigma_n} \\left[ \\sup_{f\\in \\mathcal{F}} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i) \\right].\n\\]\n\\(R_S(\\mathcal{F})\\) is a function of both the function class \\(\\mathcal{F}\\) and the dataset \\(S\\)."}, {"id": "ch4:definition:4_10", "name": "Rademacher complexity", "statement": "Let \\(\\mathcal{F}\\) be a family of functions mapping \\(Z \\mapsto \\mathbb{R}\\), and let \\(P\\) be a distribution over \\(Z\\). The (average) Rademacher complexity of \\(\\mathcal{F}\\) is defined as\n\\[\nR_n(F) \\triangleq \\mathbb{E}_{z_1, \\dots, z_n \\overset{\\text{iid}}{\\sim} P} \\left[ \\mathbb{E}_{\\sigma_1, \\dots, \\sigma_n \\overset{\\text{iid}}{\\sim}\\{ \\pm 1 \\}} \\left[ \\sup_{f\\in F} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i) \\right] \\right],\n\\]\nwhere \\(\\sigma_1, \\dots, \\sigma_n\\) are independent Rademacher random variables, i.e. each taking on the value of \\(1\\) or \\(-1\\) with probability \\(1/2\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\nnoncomputable def l2LinearClass (d : ℕ) (B : ℝ) :\n {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B} → EuclideanSpace ℝ (Fin d) → ℝ :=\n fun w x => @inner ℝ _ _ (w : EuclideanSpace ℝ (Fin d)) x\n\ntheorem ch5_theorem_5_5\n {d n : ℕ} (hn : 0 < n) {B C : ℝ} (hB : 0 < B) (hC : 0 < C)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n empRadSigned n (l2LinearClass d B) S\n ≤ (B / n) * Real.sqrt (∑ i : Fin n, ‖S i‖ ^ 2)\n ∧ ∀ {Ω : Type} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n (X : Ω → EuclideanSpace ℝ (Fin d)),\n Measurable X →\n Integrable (fun ω => ‖X ω‖ ^ 2) P →\n (∫ ω, ‖X ω‖ ^ 2 ∂P) ≤ C ^ 2 →\n popRadSigned n (l2LinearClass d B) P X\n ≤ B * C / Real.sqrt n := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\nnoncomputable def l2LinearClass (d : ℕ) (B : ℝ) :\n {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B} → EuclideanSpace ℝ (Fin d) → ℝ :=\n fun w x => @inner ℝ _ _ (w : EuclideanSpace ℝ (Fin d)) x\n\ninstance instNonemptyRadSigns {n : ℕ} : Nonempty (RadSigns n) :=\n ⟨fun _ => ⟨1, by decide⟩⟩\n\nprivate def negElt (x : ({-1, 1} : Finset ℤ)) : ({-1, 1} : Finset ℤ) :=\n ⟨-(x : ℤ), by\n have h := x.2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h ⊢\n rcases h with h | h <;> simp [h]⟩\n\nprivate def flipAt {n : ℕ} (k : Fin n) (σ : RadSigns n) : RadSigns n :=\n Function.update (σ : Fin n → ({-1, 1} : Finset ℤ)) k (negElt (σ k))\n\nprivate lemma flipAt_involutive {n : ℕ} (k : Fin n) : Function.Involutive (flipAt k) := by\n intro σ\n funext j\n by_cases h : j = k\n · subst h\n simp only [flipAt, Function.update_self]\n apply Subtype.ext\n simp [negElt]\n · simp [flipAt, Function.update_of_ne h]\n\nprivate lemma sq_coe {n : ℕ} (σ : RadSigns n) (k : Fin n) :\n ((σ k : ℝ)) * ((σ k : ℝ)) = 1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h <;> · rw [h]; norm_num\n\nprivate lemma sum_sign_mul {n : ℕ} {k l : Fin n} (hkl : k ≠ l) :\n ∑ σ : RadSigns n, ((σ k : ℝ)) * ((σ l : ℝ)) = 0 := by\n classical\n have h1 : ∑ σ : RadSigns n, ((flipAt k σ) k : ℝ) * ((flipAt k σ) l : ℝ)\n = ∑ σ : RadSigns n, ((σ k : ℝ)) * ((σ l : ℝ)) :=\n Equiv.sum_comp (flipAt_involutive k).toPerm (fun σ => ((σ k : ℝ)) * ((σ l : ℝ)))\n have h2 : ∀ σ : RadSigns n, ((flipAt k σ) k : ℝ) * ((flipAt k σ) l : ℝ)\n = -(((σ k : ℝ)) * ((σ l : ℝ))) := by\n intro σ\n have hkl' : l ≠ k := Ne.symm hkl\n simp only [flipAt, Function.update_self, Function.update_of_ne hkl', negElt]\n push_cast\n ring\n simp only [h2] at h1\n rw [Finset.sum_neg_distrib] at h1\n linarith\n\nprivate lemma sup_inner_eq {d : ℕ} {B c : ℝ} (hB : 0 < B) (hc : 0 ≤ c)\n (v : EuclideanSpace ℝ (Fin d)) :\n (⨆ w : {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B},\n c * (inner ℝ (w : EuclideanSpace ℝ (Fin d)) v)) = c * (B * ‖v‖) := by\n haveI : Nonempty {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B} := ⟨⟨0, by simp [hB.le]⟩⟩\n have hb : ∀ w : {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B},\n c * (inner ℝ (w : EuclideanSpace ℝ (Fin d)) v) ≤ c * (B * ‖v‖) := by\n intro w\n refine mul_le_mul_of_nonneg_left ?_ hc\n calc (inner ℝ (w : EuclideanSpace ℝ (Fin d)) v : ℝ)\n ≤ ‖(w : EuclideanSpace ℝ (Fin d))‖ * ‖v‖ := real_inner_le_norm _ _\n _ ≤ B * ‖v‖ := by\n have := w.2\n have : ‖(w : EuclideanSpace ℝ (Fin d))‖ ≤ B := w.2\n nlinarith [norm_nonneg v, norm_nonneg (w : EuclideanSpace ℝ (Fin d))]\n refine le_antisymm (ciSup_le hb) ?_\n have hbdd : BddAbove (Set.range fun w : {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B} =>\n c * (inner ℝ (w : EuclideanSpace ℝ (Fin d)) v)) := by\n refine ⟨c * (B * ‖v‖), ?_⟩\n rintro _ ⟨w, rfl⟩\n exact hb w\n rcases eq_or_ne v 0 with rfl | hv\n · simp\n · have hvn : 0 < ‖v‖ := norm_pos_iff.mpr hv\n have hw : ‖(B / ‖v‖) • v‖ ≤ B := by\n rw [norm_smul]\n rw [Real.norm_eq_abs, abs_of_nonneg (by positivity)]\n rw [div_mul_cancel₀ _ (ne_of_gt hvn)]\n have hle := le_ciSup hbdd (⟨(B / ‖v‖) • v, hw⟩ :\n {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B})\n refine le_trans (le_of_eq ?_) hle\n simp only [real_inner_smul_left, real_inner_self_eq_norm_sq]\n field_simp <;> ring\n\nprivate lemma emp_eq {d n : ℕ} {B : ℝ} (hB : 0 < B)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n empRadSigned n (l2LinearClass d B) S\n = (Fintype.card (RadSigns n) : ℝ)⁻¹ * (n : ℝ)⁻¹ * B *\n ∑ σ : RadSigns n, ‖∑ k : Fin n, (σ k : ℝ) • S k‖ := by\n have hstep : ∀ σ : RadSigns n,\n (⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * l2LinearClass d B i (S k))\n = (n : ℝ)⁻¹ * (B * ‖∑ k : Fin n, (σ k : ℝ) • S k‖) := by\n intro σ\n have h1 : ∀ i : {w : EuclideanSpace ℝ (Fin d) // ‖w‖ ≤ B},\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * l2LinearClass d B i (S k)\n = (n : ℝ)⁻¹ * (inner ℝ (i : EuclideanSpace ℝ (Fin d))\n (∑ k : Fin n, (σ k : ℝ) • S k)) := by\n intro i\n congr 1\n rw [inner_sum]\n exact Finset.sum_congr rfl fun k _ => by\n simp [l2LinearClass, real_inner_smul_right]\n simp only [h1]\n exact sup_inner_eq hB (by positivity) _\n unfold empRadSigned\n simp only [hstep]\n have : ∑ σ : RadSigns n, ((n : ℝ)⁻¹ * (B * ‖∑ k : Fin n, (σ k : ℝ) • S k‖))\n = ((n : ℝ)⁻¹ * B) * ∑ σ : RadSigns n, ‖∑ k : Fin n, (σ k : ℝ) • S k‖ := by\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl fun _ _ => by ring\n rw [this]\n ring\n\nprivate lemma emp_nonneg {d n : ℕ} {B : ℝ} (hB : 0 < B)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n 0 ≤ empRadSigned n (l2LinearClass d B) S := by\n rw [emp_eq hB]\n have h1 : (0:ℝ) ≤ ∑ σ : RadSigns n, ‖∑ k : Fin n, (σ k : ℝ) • S k‖ :=\n Finset.sum_nonneg fun _ _ => norm_nonneg _\n have h2 : (0:ℝ) ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ * (n : ℝ)⁻¹ * B := by positivity\n exact mul_nonneg h2 h1\n\nprivate lemma emp_bound {d n : ℕ} (hn : 0 < n) {B : ℝ} (hB : 0 < B)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n empRadSigned n (l2LinearClass d B) S ≤ (B / n) * Real.sqrt (∑ i : Fin n, ‖S i‖ ^ 2) := by\n classical\n rw [emp_eq hB]\n set N : ℝ := (Fintype.card (RadSigns n) : ℝ) with hNdef\n have hN : 0 < N := by\n rw [hNdef]\n exact_mod_cast Fintype.card_pos\n set v : RadSigns n → EuclideanSpace ℝ (Fin d) := fun σ => ∑ k : Fin n, (σ k : ℝ) • S k with hvdef\n set Q : ℝ := ∑ i : Fin n, ‖S i‖ ^ 2 with hQdef\n have hQ : 0 ≤ Q := by\n rw [hQdef]; positivity\n have hexp : ∀ σ : RadSigns n, ‖v σ‖ ^ 2\n = ∑ k : Fin n, ∑ l : Fin n, ((σ k : ℝ) * (σ l : ℝ)) * (inner ℝ (S k) (S l) : ℝ) := by\n intro σ\n rw [← real_inner_self_eq_norm_sq]\n simp only [hvdef, sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,\n Finset.mul_sum]\n exact Finset.sum_congr rfl fun k _ => Finset.sum_congr rfl fun l _ => by\n rw [real_inner_comm (S l) (S k)]; ring\n have hsum : ∑ σ : RadSigns n, ‖v σ‖ ^ 2 = N * Q := by\n simp only [hexp]\n rw [Finset.sum_comm, hQdef, Finset.mul_sum]\n refine Finset.sum_congr rfl fun k _ => ?_\n rw [Finset.sum_comm]\n have hkey : ∀ l : Fin n, ∑ σ : RadSigns n,\n ((σ k : ℝ) * (σ l : ℝ)) * (inner ℝ (S k) (S l) : ℝ)\n = if l = k then N * ‖S k‖ ^ 2 else 0 := by\n intro l\n rw [← Finset.sum_mul]\n by_cases h : l = k\n · subst h\n rw [Finset.sum_congr rfl (fun σ _ => sq_coe σ l)]\n simp only [Finset.sum_const, nsmul_eq_mul, mul_one, Finset.card_univ]\n rw [real_inner_self_eq_norm_sq]\n simp [hNdef]\n · rw [sum_sign_mul (Ne.symm h)]\n simp [h]\n simp only [hkey]\n simp\n have hjensen : (∑ σ : RadSigns n, ‖v σ‖) ^ 2 ≤ N * (N * Q) := by\n have := sq_sum_le_card_mul_sum_sq (s := (Finset.univ : Finset (RadSigns n)))\n (f := fun σ => ‖v σ‖)\n rw [hsum] at this\n simpa [hNdef, Finset.card_univ] using this\n have hsl : ∑ σ : RadSigns n, ��v σ‖ ≤ N * Real.sqrt Q := by\n have ha : (0:ℝ) ≤ ∑ σ : RadSigns n, ‖v σ‖ := Finset.sum_nonneg fun _ _ => norm_nonneg _\n have hb : (0:ℝ) ≤ N * Real.sqrt Q := by positivity\n have hsq : (∑ σ : RadSigns n, ‖v σ‖) ^ 2 ≤ (N * Real.sqrt Q) ^ 2 := by\n rw [mul_pow, Real.sq_sqrt hQ]\n nlinarith [hjensen]\n nlinarith [hsq, ha, hb]\n have hc : (0:ℝ) ≤ N⁻¹ * (n : ℝ)⁻¹ * B := by positivity\n calc N⁻¹ * (n : ℝ)⁻¹ * B * ∑ σ : RadSigns n, ‖v σ‖\n ≤ N⁻¹ * (n : ℝ)⁻¹ * B * (N * Real.sqrt Q) := by\n exact mul_le_mul_of_nonneg_left hsl hc\n _ = (B / n) * Real.sqrt Q := by\n field_simp <;> ring\n\ntheorem ch5_theorem_5_5\n {d n : ℕ} (hn : 0 < n) {B C : ℝ} (hB : 0 < B) (hC : 0 < C)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n empRadSigned n (l2LinearClass d B) S\n ≤ (B / n) * Real.sqrt (∑ i : Fin n, ‖S i‖ ^ 2)\n ∧ ∀ {Ω : Type} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n (X : Ω → EuclideanSpace ℝ (Fin d)),\n Measurable X →\n Integrable (fun ω => ‖X ω‖ ^ 2) P →\n (∫ ω, ‖X ω‖ ^ 2 ∂P) ≤ C ^ 2 →\n popRadSigned n (l2LinearClass d B) P X\n ≤ B * C / Real.sqrt n := by\n refine ⟨emp_bound hn hB S, ?_⟩\n intro Ω _ P _ X hXm hXint hCbd\n classical\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n set s : ℝ := Real.sqrt (n : ℝ) with hsdef\n have hs0 : 0 < s := by\n rw [hsdef]; exact Real.sqrt_pos.mpr hnR\n have hss : s * s = (n : ℝ) := by\n rw [hsdef]; exact Real.mul_self_sqrt hnR.le\n set a : ℝ := C * s with hadef\n have ha : 0 < a := by rw [hadef]; positivity\n set g : (Fin n → Ω) → ℝ := fun ω => ∑ k : Fin n, ‖X (ω k)‖ ^ 2 with hgdef\n have hgint : Integrable g (Measure.pi fun _ => P) := by\n rw [hgdef]\n exact integrable_finset_sum _ fun k _ =>\n integrable_comp_eval (μ := fun _ : Fin n => P) (i := k) (f := fun ω => ‖X ω‖ ^ 2) hXint\n have hbound : ∀ ω : Fin n → Ω,\n empRadSigned n (l2LinearClass d B) (X ∘ ω) ≤ (B / n) * (g ω / (2 * a) + a / 2) := by\n intro ω\n have h1 := emp_bound hn hB (X ∘ ω)\n have hg0 : 0 ≤ g ω := by rw [hgdef]; positivity\n have h2 : Real.sqrt (g ω) ≤ g ω / (2 * a) + a / 2 := by\n have ht : (Real.sqrt (g ω)) ^ 2 = g ω := Real.sq_sqrt hg0\n set t := Real.sqrt (g ω) with htdef\n rw [← ht, ← sub_nonneg]\n have hkey : t ^ 2 / (2 * a) + a / 2 - t\n = (t - a) ^ 2 / (2 * a) := by\n field_simp\n ring\n rw [hkey]\n positivity\n have h3 : (∑ i : Fin n, ‖(X ∘ ω) i‖ ^ 2) = g ω := by\n rw [hgdef]; rfl\n rw [h3] at h1\n refine h1.trans ?_\n exact mul_le_mul_of_nonneg_left h2 (by positivity)\n have hint2 : Integrable (fun ω => (B / n) * (g ω / (2 * a) + a / 2))\n (Measure.pi fun _ => P) := by\n have : (fun ω => (B / n) * (g ω / (2 * a) + a / 2))\n = fun ω => ((B / n) / (2 * a)) * g ω + (B / n) * (a / 2) := by\n funext ω; ring\n rw [this]\n exact (hgint.const_mul _).add (integrable_const _)\n have hmono : popRadSigned n (l2LinearClass d B) P X\n ≤ ∫ ω : Fin n → Ω, (B / n) * (g ω / (2 * a) + a / 2) ∂(Measure.pi fun _ => P) := by\n unfold popRadSigned\n refine integral_mono_of_nonneg (Filter.Eventually.of_forall fun ω => emp_nonneg hB _)\n hint2 (Filter.Eventually.of_forall hbound)\n have hEq : ∫ ω : Fin n → Ω, (B / n) * (g ω / (2 * a) + a / 2) ∂(Measure.pi fun _ => P)\n = (B / n) * ((∫ ω : Fin n → Ω, g ω ∂(Measure.pi fun _ => P)) / (2 * a) + a / 2) := by\n have hfun : (fun ω : Fin n → Ω => (B / n) * (g ω / (2 * a) + a / 2))\n = fun ω => ((B / n) / (2 * a)) * g ω + (B / n) * (a / 2) := by\n funext ω; ring\n rw [hfun, integral_add (hgint.const_mul _) (integrable_const _), integral_const_mul,\n integral_const]\n rw [probReal_univ, one_smul]\n ring\n have hgval : (∫ ω : Fin n → Ω, g ω ∂(Measure.pi fun _ => P)) = n * ∫ ω, ‖X ω‖ ^ 2 ∂P := by\n have hgg : (fun ω : Fin n → Ω => g ω) = fun ω => ∑ k : Fin n, ‖X (ω k)‖ ^ 2 := by\n rw [hgdef]\n rw [hgg, integral_finset_sum _ fun k _ =>\n integrable_comp_eval (μ := fun _ : Fin n => P) (i := k) (f := fun ω => ‖X ω‖ ^ 2) hXint]\n have hone : ∀ k : Fin n, (∫ ω : Fin n → Ω, ‖X (ω k)‖ ^ 2 ∂(Measure.pi fun _ => P))\n = ∫ ω, ‖X ω‖ ^ 2 ∂P := fun k =>\n integral_comp_eval (μ := fun _ : Fin n => P) (i := k) (f := fun ω => ‖X ω‖ ^ 2)\n hXint.aestronglyMeasurable\n simp [hone, Finset.card_univ]\n have hG0 : 0 ≤ ∫ ω : Fin n → Ω, g ω ∂(Measure.pi fun _ => P) := by\n refine integral_nonneg fun ω => ?_\n rw [hgdef]; positivity\n have hGle : (∫ ω : Fin n → Ω, g ω ∂(Measure.pi fun _ => P)) ≤ (n : ℝ) * C ^ 2 := by\n rw [hgval]\n exact mul_le_mul_of_nonneg_left hCbd hnR.le\n refine hmono.trans ?_\n rw [hEq]\n set G : ℝ := ∫ ω : Fin n → Ω, g ω ∂(Measure.pi fun _ => P) with hGdef\n have hfin : (B / n) * (G / (2 * a) + a / 2) ≤ (B / n) * (((n:ℝ) * C ^ 2) / (2 * a) + a / 2) := by\n have hBn : 0 ≤ B / (n:ℝ) := by positivity\n refine mul_le_mul_of_nonneg_left ?_ hBn\n have hd : G / (2 * a) ≤ ((n:ℝ) * C ^ 2) / (2 * a) := by\n gcongr\n linarith\n refine hfin.trans (le_of_eq ?_)\n rw [hadef, ← hss]\n field_simp <;> ring\n\nend GraduateLevel\n"} +{"id": "ch8_theorem_8_3", "source": "Graduate-level", "targets": [{"label": "ch8_theorem_8_3", "decls": ["ch8_theorem_8_3"], "statement": "Suppose gradient descent on \\(\\widehat{L}(\\beta)\\) with initialization \\(\\beta^0 = 0\\) converges to a solution \\(\\hat{\\beta}\\) such that \\(\\widehat{L}(\\hat{\\beta}) = 0\\). Then \\(\\hat{\\beta} = \\beta^\\star\\).", "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}], "nl_proof": "We first show via induction that \\(\\beta^t \\in \\operatorname{span}\\{x^{(1)}, \\dots, x^{(n)}\\}\\) for all \\(t\\). For the base case, note that \\(\\beta^0 = 0 \\in \\operatorname{span}\\{x^{(1)}, \\dots, x^{(n)}\\}\\). Now suppose \\(\\beta^{t-1} \\in \\operatorname{span}\\{x^{(1)}, \\dots, x^{(n)}\\}\\). Recall that \\(\\beta^t = \\beta^{t-1} - \\eta \\nabla \\widehat{L}(\\beta^{t-1})\\). Since left-multiplying any vector by \\(X^\\top\\) amounts to taking a linear combination of the rows of \\(X\\), it follows that \\(\\eta \\nabla \\widehat{L}(\\beta^{t-1}) = \\eta X^\\top(X\\beta^{t-1} - \\vec{y}) \\in \\operatorname{span}\\{x^{(1)}, \\dots, x^{(n)}\\}\\), and so \\(\\beta^t \\in \\operatorname{span}\\{x^{(1)}, \\dots, x^{(n)}\\}\\). This proves the induction step.\n\nNext, we show that \\(\\hat{\\beta} \\in \\operatorname{span}\\{x^{(1)}, \\dots, x^{(n)}\\}\\) and \\(\\widehat{L}(\\hat{\\beta}) = 0\\) implies \\(\\hat{\\beta} = \\beta^\\star\\). By definition, \\(\\hat{\\beta} \\in \\operatorname{span}\\{x^{(1)}, \\dots, x^{(n)}\\}\\) implies \\(\\hat{\\beta} = X^\\top v\\) for some \\(v \\in \\mathbb{R}^n\\). Since \\(\\widehat{L}(\\hat{\\beta}) = 0\\), we have \\(0 = X\\hat{\\beta} - \\vec{y} = XX^\\top v - \\vec{y}\\). This implies \\(v = (XX^\\top)^{-1}y\\), and so \\(\\hat{\\beta} = X^\\top v = X^\\top(XX^\\top)^{-1}\\vec{y} = X^+\\vec{y} = \\beta^\\star\\).", "context": [{"id": "ch8:corollary:8_2", "name": "Minimum-norm least-squares solution", "statement": "From the referenced lemma, we can derive an explicit formula for the minimum norm interpolant \\(\\beta^\\star \\triangleq \\operatorname{argmin}_{\\beta:\\widehat{L}(\\beta)=0}\\|\\beta\\|_2\\). \\(\\beta^\\star = X^+\\vec{y}\\)."}, {"id": "ch8:lemma:8_1", "name": "Characterization of global minimizers of underdetermined least squares", "statement": "Let \\(X^+\\) denote the pseudoinverse of \\(X\\) (since \\(X\\) is full rank, \\(XX^\\top\\) is invertible and \\(X^+ = X^\\top(XX^\\top)^{-1}\\); note that \\(XX^+X = X\\)). Then \\(\\beta\\) is a global minimizer if and only if \\(\\beta = X^+\\vec{y} + \\zeta\\) for some \\(\\zeta\\) such that \\(\\zeta \\perp x_1, \\dots, x_n\\)."}, {"id": "ch8:definition:empirical_least_squares_loss", "name": "Empirical least-squares loss", "statement": "In the underdetermined least-squares setting of Chapter 8, let \\(X \\in \\mathbb{R}^{n \\times d}\\) have rows \\(x^{(1)}, \\dots, x^{(n)}\\) and let \\(\\vec{y} \\in \\mathbb{R}^n\\) be the response vector, where \\(n < d\\). Assume \\(X\\) is full rank. Define the empirical least-squares loss by \\(\\widehat{L}(\\beta) = \\tfrac12\\|X\\beta - \\vec{y}\\|_2^2\\). Its gradient is \\(\\nabla \\widehat{L}(\\beta) = X^\\top(X\\beta - \\vec{y})\\), and \\(\\widehat{L}(\\beta) = 0\\) if and only if \\(X\\beta = \\vec{y}\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory Real\nopen scoped InnerProductSpace\n\nnamespace GraduateLevel\n\nnoncomputable def designMatrixMul {n d : ℕ} (x : Fin n → EuclideanSpace ℝ (Fin d))\n (θ : EuclideanSpace ℝ (Fin d)) : EuclideanSpace ℝ (Fin n) :=\n (WithLp.equiv 2 (Fin n → ℝ)).symm (fun i => @inner ℝ _ _ θ (x i))\n\nnoncomputable def designMatrixLinearMap {n d : ℕ} (x : Fin n → EuclideanSpace ℝ (Fin d)) :\n EuclideanSpace ℝ (Fin d) →ₗ[ℝ] EuclideanSpace ℝ (Fin n) where\n toFun := designMatrixMul x\n map_add' θ₁ θ₂ := by\n ext i; simp only [designMatrixMul, inner_add_left]; rfl\n map_smul' c θ := by\n ext i; simp only [designMatrixMul, inner_smul_left, RCLike.conj_to_real]; rfl\n\nnoncomputable def gdStep {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n [CompleteSpace E] (f : E → ℝ) (α : ℝ) (x : E) : E :=\n x - α • gradient f x\n\nnoncomputable def gdSeq {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n [CompleteSpace E] (f : E → ℝ) (α : ℕ → ℝ) (x₀ : E) : ℕ → E\n | 0 => x₀\n | k + 1 => gdStep f (α k) (gdSeq f α x₀ k)\n\ntheorem ch8_theorem_8_3\n {n d : ℕ} (hnd : n < d)\n (x : Fin n → EuclideanSpace ℝ (Fin d))\n (y : EuclideanSpace ℝ (Fin n))\n (η : ℝ)\n\n (Lhat : EuclideanSpace ℝ (Fin d) → ℝ)\n (hLhat : Lhat = fun β =>\n (1 / 2 : ℝ) * ‖designMatrixMul x β - y‖ ^ 2)\n\n (XXTinv : EuclideanSpace ℝ (Fin n) →ₗ[ℝ] EuclideanSpace ℝ (Fin n))\n (hinvL : XXTinv ∘ₗ\n (designMatrixLinearMap x ∘ₗ\n LinearMap.adjoint (designMatrixLinearMap x))\n = LinearMap.id)\n (hinvR :\n (designMatrixLinearMap x ∘ₗ\n LinearMap.adjoint (designMatrixLinearMap x)) ∘ₗ XXTinv\n = LinearMap.id)\n\n (βhat : EuclideanSpace ℝ (Fin d))\n (hconv : Filter.Tendsto\n (gdSeq Lhat (fun _ => η) 0) Filter.atTop (nhds βhat))\n\n (hfit : Lhat βhat = 0) :\n βhat = LinearMap.adjoint (designMatrixLinearMap x) (XXTinv y) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real\nopen scoped InnerProductSpace\n\nnamespace GraduateLevel\n\nnoncomputable def designMatrixMul {n d : ℕ} (x : Fin n → EuclideanSpace ℝ (Fin d))\n (θ : EuclideanSpace ℝ (Fin d)) : EuclideanSpace ℝ (Fin n) :=\n (WithLp.equiv 2 (Fin n → ℝ)).symm (fun i => @inner ℝ _ _ θ (x i))\n\nnoncomputable def designMatrixLinearMap {n d : ℕ} (x : Fin n → EuclideanSpace ℝ (Fin d)) :\n EuclideanSpace ℝ (Fin d) →ₗ[ℝ] EuclideanSpace ℝ (Fin n) where\n toFun := designMatrixMul x\n map_add' θ₁ θ₂ := by\n ext i; simp only [designMatrixMul, inner_add_left]; rfl\n map_smul' c θ := by\n ext i; simp only [designMatrixMul, inner_smul_left, RCLike.conj_to_real]; rfl\n\nnoncomputable def gdStep {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n [CompleteSpace E] (f : E → ℝ) (α : ℝ) (x : E) : E :=\n x - α • gradient f x\n\nnoncomputable def gdSeq {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n [CompleteSpace E] (f : E → ℝ) (α : ℕ → ℝ) (x₀ : E) : ℕ → E\n | 0 => x₀\n | k + 1 => gdStep f (α k) (gdSeq f α x₀ k)\n\ntheorem ch8_theorem_8_3\n {n d : ℕ} (hnd : n < d)\n (x : Fin n → EuclideanSpace ℝ (Fin d))\n (y : EuclideanSpace ℝ (Fin n))\n (η : ℝ)\n\n (Lhat : EuclideanSpace ℝ (Fin d) → ℝ)\n (hLhat : Lhat = fun β =>\n (1 / 2 : ℝ) * ‖designMatrixMul x β - y‖ ^ 2)\n\n (XXTinv : EuclideanSpace ℝ (Fin n) →ₗ[ℝ] EuclideanSpace ℝ (Fin n))\n (hinvL : XXTinv ∘ₗ\n (designMatrixLinearMap x ∘ₗ\n LinearMap.adjoint (designMatrixLinearMap x))\n = LinearMap.id)\n (hinvR :\n (designMatrixLinearMap x ∘ₗ\n LinearMap.adjoint (designMatrixLinearMap x)) ∘ₗ XXTinv\n = LinearMap.id)\n\n (βhat : EuclideanSpace ℝ (Fin d))\n (hconv : Filter.Tendsto\n (gdSeq Lhat (fun _ => η) 0) Filter.atTop (nhds βhat))\n\n (hfit : Lhat βhat = 0) :\n βhat = LinearMap.adjoint (designMatrixLinearMap x) (XXTinv y) := by\n classical\n set A : EuclideanSpace ℝ (Fin d) →ₗ[ℝ] EuclideanSpace ℝ (Fin n) :=\n designMatrixLinearMap x with hA\n set Ac : EuclideanSpace ℝ (Fin d) →L[ℝ] EuclideanSpace ℝ (Fin n) :=\n LinearMap.toContinuousLinearMap A with hAc\n have hAcA : ∀ b, Ac b = A b := fun b => rfl\n have hmul : ∀ b, designMatrixMul x b = A b := fun b => rfl\n -- gradient formula\n have hgrad : ∀ β, gradient Lhat β = LinearMap.adjoint A (A β - y) := by\n intro β\n have h1 : HasFDerivAt (fun b => Ac b - y) Ac β := (Ac.hasFDerivAt).sub_const y\n have h2 := h1.norm_sq\n have h3 : HasFDerivAt Lhat\n ((1/2 : ℝ) • (2 • ((innerSL ℝ (Ac β - y)).comp Ac))) β := by\n rw [hLhat]\n exact h2.const_mul _\n have h4 : HasGradientAt Lhat (LinearMap.adjoint A (A β - y)) β := by\n rw [hasGradientAt_iff_hasFDerivAt]\n convert h3 using 1\n ext w\n simp only [ContinuousLinearMap.smul_apply, ContinuousLinearMap.coe_comp',\n Function.comp_apply, innerSL_apply, InnerProductSpace.toDual_apply,\n smul_eq_mul, ContinuousLinearMap.add_apply]\n rw [LinearMap.adjoint_inner_left]\n simp [hAcA, real_inner_comm]\n exact h4.gradient\n -- the sequence stays in the range of the adjoint\n set S : Submodule ℝ (EuclideanSpace ℝ (Fin d)) := LinearMap.range (LinearMap.adjoint A) with hS\n have hseq : ∀ k, gdSeq Lhat (fun _ => η) 0 k ∈ S := by\n intro k\n induction k with\n | zero => simpa [gdSeq] using S.zero_mem\n | succ k ih =>\n have : gdSeq Lhat (fun _ => η) 0 (k+1)\n = gdSeq Lhat (fun _ => η) 0 k - η • gradient Lhat (gdSeq Lhat (fun _ => η) 0 k) := rfl\n rw [this, hgrad]\n exact S.sub_mem ih (S.smul_mem _ (LinearMap.mem_range_self _ _))\n have hclosed : IsClosed (S : Set (EuclideanSpace ℝ (Fin d))) :=\n S.closed_of_finiteDimensional\n have hmem : βhat ∈ S := hclosed.mem_of_tendsto hconv (Filter.Eventually.of_forall hseq)\n obtain ⟨v, hv⟩ := hmem\n -- zero loss gives A βhat = y\n have hzero : A βhat - y = 0 := by\n have : (1 / 2 : ℝ) * ‖designMatrixMul x βhat - y‖ ^ 2 = 0 := by\n rw [hLhat] at hfit; exact hfit\n have h2 : ‖A βhat - y‖ ^ 2 = 0 := by\n rw [hmul] at this; linarith\n have := pow_eq_zero_iff (n := 2) (by norm_num) |>.mp h2\n exact norm_eq_zero.mp this\n have hAy : A (LinearMap.adjoint A v) = y := by\n rw [hv]; linear_combination (norm := module) hzero\n have hv2 : v = XXTinv y := by\n have := congrArg XXTinv hAy\n calc v = (XXTinv ∘ₗ (A ∘ₗ LinearMap.adjoint A)) v := by rw [hinvL]; rfl\n _ = XXTinv (A (LinearMap.adjoint A v)) := rfl\n _ = XXTinv y := this\n rw [← hv, hv2]\n\nend GraduateLevel\n"} +{"id": "ch9_lemma_9_1", "source": "Graduate-level", "targets": [{"label": "ch9_lemma_9_1", "decls": ["ch9_lemma_9_1"], "statement": "Suppose \\(z \\sim \\mathcal{N}(v, I)\\). Then,\n\\[\n\\mathbb{E}[z \\otimes z \\otimes z] = v \\otimes v \\otimes v + \\sum_{l=1}^d \\mathbb{E}[z] \\otimes e_l \\otimes e_l + \\sum_{l=1}^d e_l \\otimes \\mathbb{E}[z] \\otimes e_l + \\sum_{l=1}^d e_l \\otimes e_l \\otimes \\mathbb{E}[z],\n\\]\nwhere \\(e_1,\\dots,e_d\\) denote the canonical basis vectors.", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "We compute the third moment element-wise. That is,\n\\[\n(\\mathbb{E}[z \\otimes z \\otimes z])_{ijk} = \\mathbb{E}[z_i z_j z_k] = \\mathbb{E}[(v_i + \\xi_i)(v_j + \\xi_j)(v_k + \\xi_k)] \\quad (z = v + \\xi,\\ \\xi \\sim \\mathcal{N}(0, I))\n\\]\n\\[\n= v_i v_j v_k + \\underbrace{\\mathbb{E}[v_i v_j \\xi_k] + \\mathbb{E}[v_i \\xi_j v_k] + \\mathbb{E}[\\xi_i v_j v_k]}_{=0} + \\mathbb{E}[v_i \\xi_j \\xi_k] + \\mathbb{E}[v_j \\xi_i \\xi_k] + \\mathbb{E}[v_k \\xi_i \\xi_j] + \\mathbb{E}[\\xi_i \\xi_j \\xi_k].\n\\]\nTo explicitly compute the last four terms, we note that:\n\\[\n\\mathbb{E}[\\xi_i \\xi_k] = \\begin{cases} 0 & \\text{if } i \\neq k \\\\ \\mathbb{E}[\\xi_i^2] = 1 & \\text{if } i = k, \\end{cases}\n\\]\nand that for any choice of \\(i, j, k\\),\n\\[\n\\mathbb{E}[\\xi_i \\xi_j \\xi_k] = 0.\n\\]\nTherefore,\n\\[\n(\\mathbb{E}[z \\otimes z \\otimes z])_{ijk} = v_i v_j v_k + v_i \\mathbf{1}[j=k] + v_j \\mathbf{1}[i=k] + v_k \\mathbf{1}[i=j].\n\\]\nSince \\(\\left(\\sum_{l=1}^d v \\otimes e_l \\otimes e_l\\right)_{ijk} = \\sum_{l=1}^d v_i e_{lj} e_{lk} = v_i \\mathbb{I}(j=k)\\), we have proven that:\n\\[\n\\mathbb{E}[z \\otimes z \\otimes z] = v \\otimes v \\otimes v + \\sum_{l=1}^d v \\otimes e_l \\otimes e_l + \\sum_{l=1}^d e_l \\otimes v \\otimes e_l + \\sum_{l=1}^d e_l \\otimes e_l \\otimes v.\n\\]", "context": [], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace GraduateLevel\n\nnoncomputable def stdGaussianPi (n : ℕ) : Measure (Fin n → ℝ) :=\n Measure.pi fun _ : Fin n => gaussianReal 0 1\n\ntheorem ch9_lemma_9_1 (d : ℕ) (v : Fin d → ℝ) (i j k : Fin d) :\n ∫ ξ, (v i + ξ i) * (v j + ξ j) * (v k + ξ k) ∂(stdGaussianPi d)\n = v i * v j * v k\n + v i * (if j = k then 1 else 0)\n + v j * (if i = k then 1 else 0)\n + v k * (if i = j then 1 else 0) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nnoncomputable def stdGaussianPi (n : ℕ) : Measure (Fin n → ℝ) :=\n Measure.pi fun _ : Fin n => gaussianReal 0 1\n\nlemma int_pow_gauss (n : ℕ) : Integrable (fun x : ℝ => x ^ n) (gaussianReal 0 1) := by\n rcases n with _ | m\n · simpa using (integrable_const (1 : ℝ) (μ := gaussianReal 0 1))\n · have h : MemLp (id : ℝ → ℝ) ((m + 1 : ℕ) : ℝ≥0∞) (gaussianReal 0 1) := by\n have := memLp_id_gaussianReal (μ := 0) (v := 1) ((m + 1 : ℕ) : ℝ≥0)\n simpa using this\n have h2 := h.integrable_norm_pow (p := m + 1) (by omega)\n refine h2.mono ?_ ?_\n · exact (measurable_id.pow_const _).aestronglyMeasurable\n · filter_upwards with x\n simp [abs_pow]\n\nlemma m1 : ∫ x : ℝ, x ∂(gaussianReal 0 1) = 0 := by\n simpa using integral_id_gaussianReal (μ := 0) (v := 1)\n\nlemma m2 : ∫ x : ℝ, x ^ 2 ∂(gaussianReal 0 1) = 1 := by\n have hv := variance_fun_id_gaussianReal (μ := 0) (v := 1)\n have hL : MemLp (fun x : ℝ => x) 2 (gaussianReal 0 1) := by\n have := memLp_id_gaussianReal (μ := 0) (v := 1) (2 : ℝ≥0)\n simpa using this\n rw [variance_def' hL, m1] at hv\n simpa using hv\n\nlemma m3 : ∫ x : ℝ, x ^ 3 ∂(gaussianReal 0 1) = 0 := by\n have hmap : (gaussianReal 0 1).map (fun x : ℝ => -x) = gaussianReal 0 1 := by\n simpa using gaussianReal_map_neg (μ := 0) (v := 1)\n have h1 : ∫ x : ℝ, x ^ 3 ∂((gaussianReal 0 1).map (fun x : ℝ => -x))\n = ∫ x : ℝ, (-x) ^ 3 ∂(gaussianReal 0 1) :=\n integral_map (μ := gaussianReal 0 1) (φ := fun x : ℝ => -x) (f := fun x : ℝ => x ^ 3)\n measurable_neg.aemeasurable (measurable_id.pow_const 3).aestronglyMeasurable\n rw [hmap] at h1\n have h2 : ∫ x : ℝ, (-x) ^ 3 ∂(gaussianReal 0 1) = - ∫ x : ℝ, x ^ 3 ∂(gaussianReal 0 1) := by\n rw [← integral_neg]\n congr 1\n funext x\n ring\n rw [h2] at h1\n linarith\n\nlemma poly_int (a b c e : ℝ) :\n ∫ x : ℝ, (a + b * x + c * x ^ 2 + e * x ^ 3) ∂(gaussianReal 0 1) = a + c := by\n have hI1 : Integrable (fun x : ℝ => x) (gaussianReal 0 1) := by\n simpa using int_pow_gauss 1\n have hI2 : Integrable (fun x : ℝ => x ^ 2) (gaussianReal 0 1) := int_pow_gauss 2\n have hI3 : Integrable (fun x : ℝ => x ^ 3) (gaussianReal 0 1) := int_pow_gauss 3\n have hc : Integrable (fun _ : ℝ => a) (gaussianReal 0 1) := integrable_const a\n have hb : Integrable (fun x : ℝ => b * x) (gaussianReal 0 1) := hI1.const_mul b\n have hcc : Integrable (fun x : ℝ => c * x ^ 2) (gaussianReal 0 1) := hI2.const_mul c\n have he : Integrable (fun x : ℝ => e * x ^ 3) (gaussianReal 0 1) := hI3.const_mul e\n have e1 : ∫ x : ℝ, (a + b * x + c * x ^ 2 + e * x ^ 3) ∂(gaussianReal 0 1)\n = (∫ x : ℝ, (a + b * x + c * x ^ 2) ∂(gaussianReal 0 1))\n + ∫ x : ℝ, e * x ^ 3 ∂(gaussianReal 0 1) :=\n integral_add ((hc.add hb).add hcc) he\n have e2 : ∫ x : ℝ, (a + b * x + c * x ^ 2) ∂(gaussianReal 0 1)\n = (∫ x : ℝ, (a + b * x) ∂(gaussianReal 0 1))\n + ∫ x : ℝ, c * x ^ 2 ∂(gaussianReal 0 1) :=\n integral_add (hc.add hb) hcc\n have e3 : ∫ x : ℝ, (a + b * x) ∂(gaussianReal 0 1)\n = (∫ _ : ℝ, a ∂(gaussianReal 0 1)) + ∫ x : ℝ, b * x ∂(gaussianReal 0 1) :=\n integral_add hc hb\n rw [e1, e2, e3, integral_const_mul, integral_const_mul, integral_const_mul, m1, m2, m3,\n integral_const]\n simp\n\nlemma pi_prod (d : ℕ) (s : Finset (Fin d)) (g : Fin d → ℝ → ℝ) :\n ∫ ξ, ∏ l ∈ s, g l (ξ l) ∂(stdGaussianPi d)\n = ∏ l ∈ s, ∫ x, g l x ∂(gaussianReal 0 1) := by\n have key := integral_fintype_prod_eq_prod (𝕜 := ℝ) (ι := Fin d) (E := fun _ => ℝ)\n (fun l x => if l ∈ s then g l x else 1) (μ := fun _ => gaussianReal 0 1)\n have step : ∀ l : Fin d, (∫ x, (if l ∈ s then g l x else 1) ∂(gaussianReal 0 1))\n = if l ∈ s then (∫ x, g l x ∂(gaussianReal 0 1)) else 1 := by\n intro l\n split <;> simp\n simp only [Finset.prod_ite_mem, Finset.univ_inter, step] at key\n rw [stdGaussianPi]\n rw [key]\n\nlemma pi1 (d : ℕ) (i : Fin d) (g : ℝ → ℝ) :\n ∫ ξ, g (ξ i) ∂(stdGaussianPi d) = ∫ x, g x ∂(gaussianReal 0 1) := by\n have := pi_prod d {i} (fun _ => g)\n simpa using this\n\nlemma pi2 (d : ℕ) (i j : Fin d) (hij : i ≠ j) (g h : ℝ → ℝ) :\n ∫ ξ, g (ξ i) * h (ξ j) ∂(stdGaussianPi d)\n = (∫ x, g x ∂(gaussianReal 0 1)) * (∫ x, h x ∂(gaussianReal 0 1)) := by\n have := pi_prod d {i, j} (fun l => if l = i then g else h)\n simpa [Finset.prod_insert, hij, Ne.symm hij] using this\n\nlemma pi3 (d : ℕ) (i j k : Fin d) (hij : i ≠ j) (hik : i ≠ k) (hjk : j ≠ k)\n (g h f : ℝ → ℝ) :\n ∫ ξ, g (ξ i) * h (ξ j) * f (ξ k) ∂(stdGaussianPi d)\n = (∫ x, g x ∂(gaussianReal 0 1)) * (∫ x, h x ∂(gaussianReal 0 1))\n * (∫ x, f x ∂(gaussianReal 0 1)) := by\n have := pi_prod d {i, j, k} (fun l => if l = i then g else if l = j then h else f)\n simpa [Finset.prod_insert, hij, hik, hjk, Ne.symm hij, Ne.symm hik, Ne.symm hjk,\n mul_assoc] using this\n\nlemma lin1 (a : ℝ) : ∫ x : ℝ, (a + x) ∂(gaussianReal 0 1) = a := by\n have h : (fun x : ℝ => a + x) = fun x : ℝ => a + 1 * x + 0 * x ^ 2 + 0 * x ^ 3 := by\n funext x; ring\n rw [h, poly_int]\n ring\n\nlemma lin2 (a : ℝ) : ∫ x : ℝ, (a + x) * (a + x) ∂(gaussianReal 0 1) = a * a + 1 := by\n have h : ∀ x : ℝ, (a + x) * (a + x) = a * a + (2 * a) * x + 1 * x ^ 2 + 0 * x ^ 3 := by\n intro x; ring\n simp_rw [h]\n rw [poly_int]\n\nlemma lin3 (a : ℝ) :\n ∫ x : ℝ, (a + x) * (a + x) * (a + x) ∂(gaussianReal 0 1) = a * a * a + 3 * a := by\n have h : ∀ x : ℝ, (a + x) * (a + x) * (a + x)\n = a * a * a + (3 * a ^ 2) * x + (3 * a) * x ^ 2 + 1 * x ^ 3 := by\n intro x; ring\n simp_rw [h]\n rw [poly_int]\n\ntheorem ch9_lemma_9_1 (d : ℕ) (v : Fin d → ℝ) (i j k : Fin d) :\n ∫ ξ, (v i + ξ i) * (v j + ξ j) * (v k + ξ k) ∂(stdGaussianPi d)\n = v i * v j * v k\n + v i * (if j = k then 1 else 0)\n + v j * (if i = k then 1 else 0)\n + v k * (if i = j then 1 else 0) := by\n by_cases hij : i = j\n · subst hij\n by_cases hik : i = k\n · subst hik\n rw [pi1 d i (fun x => (v i + x) * (v i + x) * (v i + x)), lin3,\n if_pos (rfl : i = i)]\n ring\n · rw [pi2 d i k hik (fun x => (v i + x) * (v i + x)) (fun x => v k + x), lin2, lin1]\n simp [hik]\n ring\n · by_cases hik : i = k\n · subst hik\n have hji : j ≠ i := fun h => hij h.symm\n have hre : ∀ ξ : Fin d → ℝ, (v i + ξ i) * (v j + ξ j) * (v i + ξ i)\n = ((v i + ξ i) * (v i + ξ i)) * (v j + ξ j) := by intro ξ; ring\n simp_rw [hre]\n rw [pi2 d i j hij (fun x => (v i + x) * (v i + x)) (fun x => v j + x), lin2, lin1]\n simp [hij, hji]\n ring\n · by_cases hjk : j = k\n · subst hjk\n have hre : ∀ ξ : Fin d → ℝ, (v i + ξ i) * (v j + ξ j) * (v j + ξ j)\n = (v i + ξ i) * ((v j + ξ j) * (v j + ξ j)) := by intro ξ; ring\n simp_rw [hre]\n rw [pi2 d i j hij (fun x => v i + x) (fun x => (v j + x) * (v j + x)), lin1, lin2]\n simp [hij]\n ring\n · rw [pi3 d i j k hij hik hjk (fun x => v i + x) (fun x => v j + x) (fun x => v k + x),\n lin1, lin1, lin1]\n simp [hij, hik, hjk]\n\nend GraduateLevel\n"} +{"id": "ch2_corollary_2_18", "source": "Graduate-level", "targets": [{"label": "ch2_corollary_2_18", "decls": ["ch2_corollary_2_18"], "statement": "Assume that \\(X_{1}\\in [0,1]\\).\nThen for all \\(\\epsilon > 0\\):\n\\[\n\\Pr\\left(\\bar{X}_{n}\\geq(1+\\epsilon)\\mu\\right)\\leq\\exp\\left[\\frac{-n\\mu\\epsilon^{2}}{2+\\epsilon}\\right],\n\\]\n\\[\n\\Pr\\left(\\bar{X}_{n}\\leq(1-\\epsilon)\\mu\\right)\\leq\\exp\\left[\\frac{-n\\mu\\epsilon^{2}}{2}\\right].\n\\]\nMoreover, for \\( t > 0 \\), we have:\n\\[\n\\Pr\\left(\\bar{X}_{n}\\geq\\mu+\\sqrt{\\frac{2\\mu t}{n}}+\\frac{t}{3 n}\\right)\\leq e^{-t}.\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "The first and the second results can be obtained from Theorem 2.17 and the inequality \\(\\mathrm{KL}(z||\\mu) \\geq (z - \\mu)^2 / \\max(2\\mu, \\mu + z)\\) (which is left as an exercise). We then take \\(z = (1 + \\epsilon)\\mu\\) and \\(z = (1 - \\epsilon)\\mu\\) respectively for the first and the second inequalities.\nFor the third inequality (which is sharper than the first inequality), we may apply Theorem 2.10. Just observe from Lemma 2.15 that when \\(\\lambda > 0\\):\n\\[\n\\begin{array}{l}\\Lambda_{X_{1}}(\\lambda)\\leq\\ln [(1-\\mu)e^{0}+\\mu e^{\\lambda}]\\\\ \\leq\\mu(e^{\\lambda}-1)=\\mu\\lambda+\\mu\\sum_{k\\geq 2}\\frac{\\lambda^{k}}{k!}\\\\ \\leq\\mu\\lambda+\\frac{\\mu\\lambda^{2}}{2(1-\\lambda/3)}.\\\\ \\end{array}\n\\]\nIn the above derivation, the equality used the Taylor expansion of exponential function. The last inequality used \\( k! \\geq 2 \\cdot 3^{k-2} \\) and the sum of infinite geometric series. We may take \\( \\alpha = \\mu \\) and \\( \\beta = 1/3 \\) in Theorem 2.10 to obtain the desired bound.", "context": [{"id": "ch2:theorem:2_17", "name": "theorem 2.17", "statement": "Assume that \\(X_{1}\\in [0,1]\\) . Then for all \\(\\epsilon >0\\) , we have\n\\[\n\\begin{array}{l}\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq e^{-n\\mathrm{KL}(\\mu+\\epsilon| |\\mu)},\\\\ \\Pr(\\bar{X}_{n}\\leq\\mu-\\epsilon)\\leq e^{-n\\mathrm{KL}(\\mu-\\epsilon| |\\mu)},\\\\ \\end{array}\n\\]\nwhere \\(\\mathrm{KL}(z||\\mu)\\) is the Kullback-Leibler divergence (KL divergence) defined as\n\\[\n\\mathrm{KL}(z| |\\mu)=z\\ln{\\frac{z}{\\mu}}+(1-z)\\ln{\\frac{1-z}{1-\\mu}}.\n\\]"}, {"id": "ch2:theorem:2_10", "name": "theorem 2.10", "statement": "If \\( X_{1} \\) has a logarithmic moment generating function that satisfies (2.9) for \\( \\lambda > 0 \\), then all \\( \\epsilon > 0 \\):\n\\[\n\\operatorname*{Pr}(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq\\exp\\left[\\frac{-n\\epsilon^{2}}{2(\\alpha+\\beta\\epsilon)}\\right].\n\\]\nMoreover, for \\(t > 0\\), we have\n\\[\n\\operatorname*{Pr}\\left(\\bar{X}_{n}\\geq\\mu+\\sqrt{\\frac{2\\alpha t}{n}}+\\frac{\\beta t}{n}\\right)\\leq e^{-t}.\n\\]"}, {"id": "ch2:lemma:2_15", "name": "lemma 2.15", "statement": "Consider a random variable \\(X \\in [0,1]\\) and \\(\\mathbb{E}X = \\mu\\). We have the following inequality:\n\\[\n\\ln\\mathbb{E}e^{\\lambda X}\\leq\\ln [(1-\\mu)e^{0}+\\mu e^{\\lambda}]\\leq\\lambda\\mu+\\lambda^{2}/8.\n\\]"}, {"id": "ch2_corollary_2_18:fix:1", "name": "Lemma 2.9 (equation (2.9))", "statement": "Consider a random variable \\(X\\) so that \\(\\mathbb{E}[X] = \\mu\\). Assume that there exists \\(\\alpha > 0\\) and \\(\\beta \\geq 0\\) such that for \\(\\lambda \\in [0, \\beta^{-1})\\):\n\\[\n\\Lambda_{X}(\\lambda)\\leq\\lambda\\mu+\\frac{\\alpha\\lambda^{2}}{2(1-\\beta\\lambda)},\\tag{2.9}\n\\]"}, {"id": "ch2_corollary_2_18:fix:2", "name": "Definition 2.4", "statement": "Given a random variable \\(X\\), we may define its logarithmic moment generating function as\n\\[\n\\Lambda_{X}(\\lambda)=\\ln\\mathbb{E}e^{\\lambda X}.\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch2_corollary_2_18\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} [NeZero n] (X : Fin n → Ω → ℝ)\n (hmeas : ∀ i, AEMeasurable (X i) P)\n (hindep : iIndepFun X P)\n (hbdd : ∀ i, ∀ᵐ ω ∂P, X i ω ∈ Set.Icc (0 : ℝ) 1)\n (hident : ∀ i, Measure.map (X i) P = Measure.map (X 0) P)\n (h_int : ∀ t, Integrable (fun ω => Real.exp (t * X 0 ω)) P)\n (μ : ℝ) (hmu : μ = ∫ ω, X 0 ω ∂P) :\n (∀ ε : ℝ, 0 < ε →\n (P {ω | (1 + ε) * μ ≤ (∑ i, X i ω) / n}).toReal\n ≤ Real.exp (-(n : ℝ) * μ * ε ^ 2 / (2 + ε))) ∧\n (∀ ε : ℝ, 0 < ε →\n (P {ω | (∑ i, X i ω) / n ≤ (1 - ε) * μ}).toReal\n ≤ Real.exp (-(n : ℝ) * μ * ε ^ 2 / 2)) ∧\n (∀ t : ℝ, 0 < t →\n (P {ω | μ + Real.sqrt (2 * μ * t / n) + t / (3 * n) ≤ (∑ i, X i ω) / n}).toReal\n ≤ Real.exp (-t)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nprivate lemma mgf_le_exp_mean_of_mem_Icc\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n (Z : Ω → ℝ) (hmeas : AEMeasurable Z P)\n (hbdd : ∀ᵐ ω ∂P, Z ω ∈ Set.Icc (0 : ℝ) 1)\n (h_int : ∀ t, Integrable (fun ω => Real.exp (t * Z ω)) P) (t : ℝ) :\n mgf Z P t ≤ Real.exp ((∫ ω, Z ω ∂P) * (Real.exp t - 1)) := by\n have hZint : Integrable Z P := by\n refine Integrable.mono' (integrable_const (1 : ℝ)) hmeas.aestronglyMeasurable ?_\n filter_upwards [hbdd] with ω hω\n simp only [norm_eq_abs, norm_one]\n rw [abs_of_nonneg hω.1]\n exact hω.2\n have hlin_int : Integrable (fun ω => 1 - Z ω + Z ω * Real.exp t) P :=\n ((integrable_const (1 : ℝ)).sub hZint).add (hZint.mul_const (Real.exp t))\n have hpoint :\n ∀ᵐ ω ∂P, Real.exp (t * Z ω) ≤ 1 - Z ω + Z ω * Real.exp t := by\n filter_upwards [hbdd] with ω hω\n have hc := convexOn_exp.2 (Set.mem_univ (0 : ℝ)) (Set.mem_univ t)\n (sub_nonneg.mpr hω.2) hω.1 (by ring : (1 - Z ω) + Z ω = 1)\n simpa [smul_eq_mul, mul_comm] using hc\n calc\n mgf Z P t\n ≤ ∫ ω, (1 - Z ω + Z ω * Real.exp t) ∂P :=\n integral_mono_ae (h_int t) hlin_int hpoint\n _ = 1 + (∫ ω, Z ω ∂P) * (Real.exp t - 1) := by\n calc\n ∫ ω, 1 - Z ω + Z ω * Real.exp t ∂P =\n (∫ ω, 1 - Z ω ∂P) + ∫ ω, Z ω * Real.exp t ∂P := by\n exact integral_add\n ((integrable_const (1 : ℝ)).sub hZint)\n (hZint.mul_const (Real.exp t))\n _ = (1 - ∫ ω, Z ω ∂P) + (∫ ω, Z ω ∂P) * Real.exp t := by\n rw [integral_sub (integrable_const (1 : ℝ)) hZint,\n integral_const, integral_mul_const]\n simp only [probReal_univ, one_smul]\n _ = 1 + (∫ ω, Z ω ∂P) * (Real.exp t - 1) := by ring\n _ ≤ Real.exp ((∫ ω, Z ω ∂P) * (Real.exp t - 1)) :=\n by simpa [add_comm] using\n Real.add_one_le_exp ((∫ ω, Z ω ∂P) * (Real.exp t - 1))\n\nprivate lemma exp_sub_one_sub_le {x : ℝ} (hx0 : 0 ≤ x) (hx3 : x < 3) :\n Real.exp x - 1 - x ≤ x ^ 2 / (2 * (1 - x / 3)) := by\n let r : ℝ → ℝ := fun y => 1 + y + y ^ 2 / (2 * (1 - y / 3))\n let g : ℝ → ℝ := fun y => Real.exp (-y) * r y\n have hg_has (y : ℝ) (hy : y < 3) :\n HasDerivAt g (Real.exp (-y) * y ^ 3 / (2 * (3 - y) ^ 2)) y := by\n have hne : 2 * (1 - y / 3) ≠ 0 := by\n apply mul_ne_zero (by norm_num)\n intro h\n have : y = 3 := by linarith\n linarith\n have hr_has :\n HasDerivAt r\n (1 + ((2 * y) * (2 * (1 - y / 3)) -\n y ^ 2 * (2 * (-(1 / 3 : ℝ)))) /\n (2 * (1 - y / 3)) ^ 2) y := by\n dsimp [r]\n convert ((hasDerivAt_const y (1 : ℝ)).add (hasDerivAt_id y)).add\n (((hasDerivAt_id y).pow 2).div\n ((hasDerivAt_const y (2 : ℝ)).mul\n ((hasDerivAt_const y (1 : ℝ)).sub ((hasDerivAt_id y).div_const 3))) hne) using 1 <;>\n simp only [id_eq, Pi.pow_apply, Pi.mul_apply, Pi.sub_apply, Pi.div_apply] <;>\n field_simp [hne] <;> ring\n have he_has : HasDerivAt (fun z : ℝ => Real.exp (-z)) (-Real.exp (-y)) y := by\n simpa using (Real.hasDerivAt_exp (-y)).comp y (hasDerivAt_id y).neg\n dsimp [r] at hr_has\n have h3ne : 3 - y ≠ 0 := by linarith\n dsimp [g, r]\n convert he_has.mul hr_has using 1 <;>\n field_simp [hne, h3ne] <;> ring\n have hg_cont : ContinuousOn g (Set.Ico (0 : ℝ) 3) := by\n intro y hy\n exact (hg_has y hy.2).continuousAt.continuousWithinAt\n have hg_diff : DifferentiableOn ℝ g (interior (Set.Ico (0 : ℝ) 3)) := by\n intro y hy\n have hy' : y ∈ Set.Ioo (0 : ℝ) 3 := by simpa only [interior_Ico] using hy\n exact (hg_has y hy'.2).differentiableAt.differentiableWithinAt\n have hg_deriv : ∀ y ∈ interior (Set.Ico (0 : ℝ) 3), 0 ≤ deriv g y := by\n intro y hy\n have hy' : y ∈ Set.Ioo (0 : ℝ) 3 := by simpa only [interior_Ico] using hy\n rw [(hg_has y hy'.2).deriv]\n exact div_nonneg\n (mul_nonneg (Real.exp_pos _).le (pow_nonneg hy'.1.le _))\n (mul_nonneg (by norm_num) (sq_nonneg _))\n have hg_mono : MonotoneOn g (Set.Ico (0 : ℝ) 3) :=\n monotoneOn_of_deriv_nonneg (convex_Ico 0 3) hg_cont hg_diff hg_deriv\n have hmono := hg_mono (Set.left_mem_Ico.mpr (by norm_num : (0 : ℝ) < 3))\n ⟨hx0, hx3⟩ hx0\n have hr : Real.exp x ≤ r x := by\n dsimp [g, r] at hmono ⊢\n norm_num at hmono\n calc\n Real.exp x = Real.exp x * 1 := by ring\n _ ≤ Real.exp x *\n (Real.exp (-x) * (1 + x + x ^ 2 / (2 * (1 - x / 3)))) :=\n mul_le_mul_of_nonneg_left hmono (Real.exp_pos x).le\n _ = 1 + x + x ^ 2 / (2 * (1 - x / 3)) := by\n rw [← mul_assoc, ��� Real.exp_add]\n simp\n dsimp [r] at hr\n linarith\n\ntheorem ch2_corollary_2_18\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} [NeZero n] (X : Fin n → Ω → ℝ)\n (hmeas : ∀ i, AEMeasurable (X i) P)\n (hindep : iIndepFun X P)\n (hbdd : ∀ i, ∀ᵐ ω ∂P, X i ω ∈ Set.Icc (0 : ℝ) 1)\n (hident : ∀ i, Measure.map (X i) P = Measure.map (X 0) P)\n (h_int : ∀ t, Integrable (fun ω => Real.exp (t * X 0 ω)) P)\n (μ : ℝ) (hmu : μ = ∫ ω, X 0 ω ∂P) :\n (∀ ε : ℝ, 0 < ε →\n (P {ω | (1 + ε) * μ ≤ (∑ i, X i ω) / n}).toReal\n ≤ Real.exp (-(n : ℝ) * μ * ε ^ 2 / (2 + ε))) ∧\n (∀ ε : ℝ, 0 < ε →\n (P {ω | (∑ i, X i ω) / n ≤ (1 - ε) * μ}).toReal\n ≤ Real.exp (-(n : ℝ) * μ * ε ^ 2 / 2)) ∧\n (∀ t : ℝ, 0 < t →\n (P {ω | μ + Real.sqrt (2 * μ * t / n) + t / (3 * n) ≤ (∑ i, X i ω) / n}).toReal\n ≤ Real.exp (-t)) := by\n classical\n let Y : Fin n → Ω → ℝ := fun i => (hmeas i).mk (X i)\n have hXY (i : Fin n) : X i =ᵐ[P] Y i := (hmeas i).ae_eq_mk\n have hYmeas (i : Fin n) : Measurable (Y i) := (hmeas i).measurable_mk\n have hYb (i : Fin n) : ∀ᵐ ω ∂P, Y i ω ∈ Set.Icc (0 : ℝ) 1 := by\n filter_upwards [hbdd i, hXY i] with ω hb heq\n rwa [← heq]\n have hYindep : iIndepFun Y P := hindep.congr hXY\n have hid (i : Fin n) : IdentDistrib (X i) (X 0) P P :=\n ⟨hmeas i, hmeas 0, hident i⟩\n have hmeanX (i : Fin n) : ∫ ω, X i ω ∂P = μ := by\n calc\n ∫ ω, X i ω ∂P = ∫ ω, X 0 ω ∂P := (hid i).integral_eq\n _ = μ := hmu.symm\n have hmeanY (i : Fin n) : ∫ ω, Y i ω ∂P = μ := by\n rw [integral_congr_ae (hXY i).symm]\n exact hmeanX i\n have hYexp (i : Fin n) (s : ℝ) :\n Integrable (fun ω => Real.exp (s * Y i ω)) P := by\n have hi : Integrable (fun ω => Real.exp (s * X i ω)) P := by\n have hd := (hid i).comp (measurable_const_mul s |>.exp)\n exact hd.integrable_iff.mpr (h_int s)\n exact hi.congr ((hXY i).fun_comp fun x => Real.exp (s * x))\n have hmgfY (i : Fin n) (s : ℝ) :\n mgf (Y i) P s ≤ Real.exp (μ * (Real.exp s - 1)) := by\n simpa [hmeanY i] using\n mgf_le_exp_mean_of_mem_Icc P (Y i) (hYmeas i).aemeasurable\n (hYb i) (hYexp i) s\n let S : Ω → ℝ := fun ω => ∑ i, Y i ω\n have hSint (s : ℝ) : Integrable (fun ω => Real.exp (s * S ω)) P := by\n simpa [S] using hYindep.integrable_exp_mul_sum hYmeas\n (s := Finset.univ) (fun i _ => hYexp i s)\n have hmgfS (s : ℝ) :\n mgf S P s ≤ Real.exp ((n : ℝ) * μ * (Real.exp s - 1)) := by\n calc\n mgf S P s = ∏ i : Fin n, mgf (Y i) P s := by\n rw [show S = ∑ i : Fin n, Y i by\n funext ω\n simp [S]]\n exact hYindep.mgf_sum hYmeas (Finset.univ : Finset (Fin n))\n _ ≤ ∏ _i : Fin n, Real.exp (μ * (Real.exp s - 1)) := by\n exact Finset.prod_le_prod (fun _ _ => mgf_nonneg) (fun i _ => hmgfY i s)\n _ = Real.exp (μ * (Real.exp s - 1)) ^ n := by simp\n _ = Real.exp ((n : ℝ) * μ * (Real.exp s - 1)) := by\n rw [← Real.exp_nat_mul]\n congr 1\n ring\n have hsum_ae : (fun ω => ∑ i, X i ω) =ᵐ[P] S := by\n have hsums (s : Finset (Fin n)) :\n (fun ω => ∑ i ∈ s, X i ω) =ᵐ[P] fun ω => ∑ i ∈ s, Y i ω := by\n induction s using Finset.induction_on with\n | empty => simp\n | @insert i s hi ih =>\n filter_upwards [hXY i, ih] with ω h_i h_s\n simp only [Finset.sum_insert hi]\n rw [h_i, h_s]\n simpa [S] using hsums Finset.univ\n have hn_nat : 0 < n := Nat.pos_of_ne_zero (NeZero.ne n)\n have hn : 0 < (n : ℝ) := by exact_mod_cast hn_nat\n have hμ : 0 ≤ μ := by\n rw [hmu]\n exact integral_nonneg_of_ae ((hbdd 0).mono fun _ h => h.1)\n have hmeasure_ge (a : ℝ) :\n (P {ω | a ≤ (∑ i, X i ω) / n}).toReal =\n (P {ω | (n : ℝ) * a ≤ S ω}).toReal := by\n congr 1\n apply measure_congr\n filter_upwards [hsum_ae] with ω hω\n apply propext\n change (a ≤ (∑ i, X i ω) / (n : ℝ)) ↔ ((n : ℝ) * a ≤ S ω)\n rw [hω]\n simpa [mul_comm] using (le_div_iff₀ hn)\n have hmeasure_le (a : ℝ) :\n (P {ω | (∑ i, X i ω) / n ≤ a}).toReal =\n (P {ω | S ω ≤ (n : ℝ) * a}).toReal := by\n congr 1\n apply measure_congr\n filter_upwards [hsum_ae] with ω hω\n apply propext\n change ((∑ i, X i ω) / (n : ℝ) ≤ a) ↔ (S ω ≤ (n : ℝ) * a)\n rw [hω]\n simpa [mul_comm] using (div_le_iff₀ hn)\n have hchernoff_ge (a s : ℝ) (hs : 0 ≤ s) :\n (P {ω | a ≤ S ω}).toReal ≤\n Real.exp (-s * a + (n : ℝ) * μ * (Real.exp s - 1)) := by\n calc\n (P {ω | a ≤ S ω}).toReal ≤ Real.exp (-s * a) * mgf S P s :=\n measure_ge_le_exp_mul_mgf a hs (hSint s)\n _ ≤ Real.exp (-s * a) *\n Real.exp ((n : ℝ) * μ * (Real.exp s - 1)) :=\n mul_le_mul_of_nonneg_left (hmgfS s) (Real.exp_pos _).le\n _ = Real.exp (-s * a + (n : ℝ) * μ * (Real.exp s - 1)) := by\n rw [Real.exp_add]\n have hchernoff_le (a s : ℝ) (hs : s ≤ 0) :\n (P {ω | S ω ≤ a}).toReal ≤\n Real.exp (-s * a + (n : ℝ) * μ * (Real.exp s - 1)) := by\n calc\n (P {ω | S ω ≤ a}).toReal ≤ Real.exp (-s * a) * mgf S P s :=\n measure_le_le_exp_mul_mgf a hs (hSint s)\n _ ≤ Real.exp (-s * a) *\n Real.exp ((n : ℝ) * μ * (Real.exp s - 1)) :=\n mul_le_mul_of_nonneg_left (hmgfS s) (Real.exp_pos _).le\n _ = Real.exp (-s * a + (n : ℝ) * μ * (Real.exp s - 1)) := by\n rw [Real.exp_add]\n refine ⟨?_, ?_, ?_⟩\n · intro ε hε\n have hden : 0 < ε + 2 := by linarith\n have hlog : 2 * ε / (ε + 2) ≤ Real.log (1 + ε) :=\n Real.le_log_one_add_of_nonneg hε.le\n have hcore : 0 ≤ (ε + 2) * Real.log (1 + ε) - 2 * ε := by\n have := (div_le_iff₀ hden).mp hlog\n linarith\n have hrate :\n ε ^ 2 / (2 + ε) ≤ (1 + ε) * Real.log (1 + ε) - ε := by\n apply (div_le_iff₀ (by linarith : 0 < 2 + ε)).2\n have hp := mul_nonneg (by linarith : 0 ≤ 1 + ε) hcore\n nlinarith\n rw [hmeasure_ge ((1 + ε) * μ)]\n calc\n (P {ω | (n : ℝ) * ((1 + ε) * μ) ≤ S ω}).toReal\n ≤ Real.exp (-Real.log (1 + ε) * ((n : ℝ) * ((1 + ε) * μ)) +\n (n : ℝ) * μ * (Real.exp (Real.log (1 + ε)) - 1)) :=\n hchernoff_ge _ _ (Real.log_nonneg (by linarith))\n _ = Real.exp ((n : ℝ) * μ *\n (ε - (1 + ε) * Real.log (1 + ε))) := by\n rw [Real.exp_log (by linarith : 0 < 1 + ε)]\n congr 1\n ring\n _ ≤ Real.exp (-(n : ℝ) * μ * ε ^ 2 / (2 + ε)) := by\n apply Real.exp_le_exp.mpr\n have hnm : 0 ≤ (n : ℝ) * μ := mul_nonneg hn.le hμ\n calc\n (n : ℝ) * μ * (ε - (1 + ε) * Real.log (1 + ε)) =\n -((n : ℝ) * μ * ((1 + ε) * Real.log (1 + ε) - ε)) := by ring\n _ ≤ -((n : ℝ) * μ * (ε ^ 2 / (2 + ε))) :=\n neg_le_neg (mul_le_mul_of_nonneg_left hrate hnm)\n _ = -(n : ℝ) * μ * ε ^ 2 / (2 + ε) := by ring\n · intro ε hε\n have hp : 0 ≤ 1 - ε + ε ^ 2 / 2 := by\n nlinarith [sq_nonneg (ε - 1)]\n have hquad : 1 + ε + ε ^ 2 / 2 ≤ Real.exp ε :=\n Real.quadratic_le_exp_of_nonneg hε.le\n have hexpneg : Real.exp (-ε) ≤ 1 - ε + ε ^ 2 / 2 := by\n rw [Real.exp_neg]\n rw [inv_eq_one_div]\n apply (div_le_iff₀ (Real.exp_pos ε)).2\n calc\n 1 ≤ (1 - ε + ε ^ 2 / 2) * (1 + ε + ε ^ 2 / 2) := by\n nlinarith [sq_nonneg (ε ^ 2)]\n _ ≤ (1 - ε + ε ^ 2 / 2) * Real.exp ε :=\n mul_le_mul_of_nonneg_left hquad hp\n rw [hmeasure_le ((1 - ε) * μ)]\n calc\n (P {ω | S ω ≤ (n : ℝ) * ((1 - ε) * μ)}).toReal\n ≤ Real.exp (-(-ε) * ((n : ℝ) * ((1 - ε) * μ)) +\n (n : ℝ) * μ * (Real.exp (-ε) - 1)) :=\n hchernoff_le _ _ (by linarith)\n _ ≤ Real.exp ((n : ℝ) * μ * (-ε ^ 2 / 2)) := by\n apply Real.exp_le_exp.mpr\n have hnm : 0 ≤ (n : ℝ) * μ := mul_nonneg hn.le hμ\n have hinside :\n Real.exp (-ε) - 1 + ε * (1 - ε) ≤ -ε ^ 2 / 2 := by\n linarith\n calc\n -(-ε) * ((n : ℝ) * ((1 - ε) * μ)) +\n (n : ℝ) * μ * (Real.exp (-ε) - 1) =\n (n : ℝ) * μ * (Real.exp (-ε) - 1 + ε * (1 - ε)) := by ring\n _ ≤ (n : ℝ) * μ * (-ε ^ 2 / 2) :=\n mul_le_mul_of_nonneg_left hinside hnm\n _ = Real.exp (-(n : ℝ) * μ * ε ^ 2 / 2) := by\n congr 1\n ring\n · intro t ht\n by_cases hμ0 : μ = 0\n · rw [hmeasure_ge\n (μ + Real.sqrt (2 * μ * t / n) + t / (3 * n))]\n have hthreshold :\n (n : ℝ) * (μ + Real.sqrt (2 * μ * t / n) + t / (3 * n)) = t / 3 := by\n rw [hμ0]\n simp [hn.ne']\n field_simp [hn.ne']\n rw [hthreshold]\n calc\n (P {ω | t / 3 ≤ S ω}).toReal ≤\n Real.exp (-(3 : ℝ) * (t / 3) +\n (n : ℝ) * μ * (Real.exp 3 - 1)) :=\n hchernoff_ge _ 3 (by norm_num)\n _ = Real.exp (-t) := by rw [hμ0]; congr 1; ring\n · have hμpos : 0 < μ := lt_of_le_of_ne hμ (Ne.symm hμ0)\n let v : ℝ := (n : ℝ) * μ\n have hv : 0 < v := mul_pos hn hμpos\n let q : ℝ := Real.sqrt (2 * t / v)\n have harg : 0 < 2 * t / v := div_pos (mul_pos (by norm_num) ht) hv\n have hq : 0 < q := Real.sqrt_pos.2 harg\n have hq_sq : q ^ 2 = 2 * t / v := by\n dsimp [q]\n exact Real.sq_sqrt harg.le\n let l : ℝ := q / (1 + q / 3)\n have hlden : 0 < 1 + q / 3 := by positivity\n have hl0 : 0 ≤ l := (div_pos hq hlden).le\n have hl3 : l < 3 := by\n dsimp [l]\n apply (div_lt_iff₀ hlden).2\n linarith\n have hone : 0 < 1 - l / 3 := by linarith\n have hexprem :\n Real.exp l - 1 - l ≤ l ^ 2 / (2 * (1 - l / 3)) :=\n exp_sub_one_sub_le hl0 hl3\n let d : ℝ := v * q + t / 3\n have hsqrt_mean :\n (n : ℝ) * Real.sqrt (2 * μ * t / n) = v * q := by\n have ha : 0 ≤ 2 * μ * t / (n : ℝ) := by positivity\n have hs_sq := Real.sq_sqrt ha\n have hs_nonneg := Real.sqrt_nonneg (2 * μ * t / (n : ℝ))\n have hl_nonneg : 0 ≤ (n : ℝ) * Real.sqrt (2 * μ * t / n) :=\n mul_nonneg hn.le hs_nonneg\n have hr_nonneg : 0 ≤ v * q := mul_nonneg hv.le hq.le\n have hv_ne : v ≠ 0 := hv.ne'\n have hn_ne : (n : ℝ) ≠ 0 := hn.ne'\n apply sq_eq_sq₀ hl_nonneg hr_nonneg |>.mp\n rw [mul_pow, mul_pow, hs_sq, hq_sq]\n dsimp [v]\n field_simp\n have hthreshold :\n (n : ℝ) *\n (μ + Real.sqrt (2 * μ * t / n) + t / (3 * n)) = v + d := by\n dsimp [d, v] at hsqrt_mean ⊢\n field_simp [hn.ne'] at hsqrt_mean ⊢\n nlinarith\n rw [hmeasure_ge\n (μ + Real.sqrt (2 * μ * t / n) + t / (3 * n)), hthreshold]\n calc\n (P {ω | v + d ≤ S ω}).toReal ≤\n Real.exp (-l * (v + d) +\n (n : ℝ) * μ * (Real.exp l - 1)) :=\n hchernoff_ge _ _ hl0\n _ ≤ Real.exp (-l * d + v * l ^ 2 / (2 * (1 - l / 3))) := by\n apply Real.exp_le_exp.mpr\n have hvrem := mul_le_mul_of_nonneg_left hexprem hv.le\n change -l * (v + d) + v * (Real.exp l - 1) ≤\n -l * d + v * l ^ 2 / (2 * (1 - l / 3))\n calc\n -l * (v + d) + v * (Real.exp l - 1) =\n -l * d + v * (Real.exp l - 1 - l) := by ring\n _ ≤ -l * d + v * (l ^ 2 / (2 * (1 - l / 3))) :=\n by simpa [add_comm] using add_le_add_left hvrem (-l * d)\n _ = -l * d + v * l ^ 2 / (2 * (1 - l / 3)) := by ring\n _ = Real.exp (-t) := by\n congr 1\n have hqt : v * q ^ 2 = 2 * t := by\n rw [hq_sq]\n field_simp [hv.ne']\n dsimp [l, d]\n field_simp [hlden.ne', hv.ne']\n nlinarith [hqt]\n\nend GraduateLevel"} +{"id": "ch2_corollary_2_19", "source": "Graduate-level", "targets": [{"label": "ch2_corollary_2_19", "decls": ["ch2_corollary_2_19"], "statement": "Assume that \\(X_{1}\\in \\{0,1\\}\\). Then for all \\(\\epsilon >0\\) that satisfies\n\\[\n\\epsilon^{\\prime}=\\epsilon+2\\sqrt{(\\mu+\\epsilon)(1-(\\mu+\\epsilon))/n}<1-\\mu,\n\\]\nand \\(n\\geq (1 - \\mu -\\epsilon) / (\\mu +\\epsilon)\\), we have\n\\[\n\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\geq 0.25\\exp\\left[-n\\mathrm{KL}(\\mu+\\epsilon^{\\prime}| |\\mu)-\\sqrt{n}\\Delta I\\right],\n\\]\nwhere\n\\[\n\\Delta I=2\\sqrt{(\\mu+\\epsilon)(1-\\mu-\\epsilon)}\\ln\\frac{(\\mu+\\epsilon^{\\prime})(1-\\mu)}{(1-(\\mu+\\epsilon^{\\prime}))\\mu}.\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "In (2.8), we let \\(\\epsilon'' = 2\\epsilon' - \\epsilon\\). Since \\(X_i' \\in \\{0,1\\}\\) and \\(\\mathbb{E}X_i' = \\mu + \\epsilon'\\), we have\n\\(\\operatorname{Var}(X_1') = (\\mu + \\epsilon') (1 - \\mu - \\epsilon')\\). Using Chebyshev's inequality, we obtain\n\\[\n\\begin{array}{l}\\Pr\\left(|\\bar{X}_{n}^{\\prime}-(\\mu+\\epsilon^{\\prime})|\\geq\\epsilon^{\\prime}-\\epsilon\\right)\\leq\\frac{(\\mu+\\epsilon^{\\prime})(1-\\mu-\\epsilon^{\\prime})}{n(\\epsilon^{\\prime}-\\epsilon)^{2}}\\\\ =\\frac{(\\mu+\\epsilon^{\\prime})(1-\\mu-\\epsilon^{\\prime})}{4(\\mu+\\epsilon)(1-(\\mu+\\epsilon))}\\leq\\frac{(\\mu+\\epsilon^{\\prime})}{4(\\mu+\\epsilon)}=0. 25+\\frac{\\epsilon^{\\prime}-\\epsilon}{4(\\mu+\\epsilon)}.\\\\ \\end{array}\n\\]\nTherefore\n\\[\n\\begin{array}{l}\\Pr\\left(\\bar{X}_{n}^{\\prime}\\in(\\mu+\\epsilon,\\mu+\\epsilon^{\\prime\\prime})\\right)=1-\\Pr\\left(|\\bar{X}_{n}^{\\prime}-(\\mu+\\epsilon^{\\prime})|\\geq\\epsilon^{\\prime}-\\epsilon\\right)\\\\ \\geq 0. 75-\\frac{\\epsilon^{\\prime}-\\epsilon}{4(\\mu+\\epsilon)}=0. 75-0. 5\\sqrt{\\frac{1-\\mu-\\epsilon}{n(\\mu+\\epsilon)}}\\geq 0. 25.\\\\ \\end{array}\n\\]\nThe choice of \\(\\lambda\\) in (2.4) is given by\n\\[\n\\lambda=\\ln{\\frac{(\\mu+\\epsilon^{\\prime})(1-\\mu)}{(1-(\\mu+\\epsilon^{\\prime}))\\mu}}.\n\\]\nBy using the above estimates, we can obtain the desired bound from (2.8).", "context": [{"id": "ch2:corollary:2_3", "name": "Chebyshev's Inequality", "statement": "We have\n\\[\n\\Pr\\left(\\left|\\bar{X}_{n}-\\mu\\right|\\geq\\epsilon\\right)\\leq\\frac{\\operatorname{Var}\\left(X_{1}\\right)}{n\\epsilon^{2}}.\\tag{2.2}\n\\]"}, {"id": "ch2:theorem:2_17", "name": "theorem 2.17", "statement": "Assume that \\(X_{1}\\in [0,1]\\) . Then for all \\(\\epsilon >0\\) , we have\n\\[\n\\begin{array}{l}\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq e^{-n\\mathrm{KL}(\\mu+\\epsilon| |\\mu)},\\\\ \\Pr(\\bar{X}_{n}\\leq\\mu-\\epsilon)\\leq e^{-n\\mathrm{KL}(\\mu-\\epsilon| |\\mu)},\\\\ \\end{array}\n\\]\nwhere \\(\\mathrm{KL}(z||\\mu)\\) is the Kullback-Leibler divergence (KL divergence) defined as\n\\[\n\\mathrm{KL}(z| |\\mu)=z\\ln{\\frac{z}{\\mu}}+(1-z)\\ln{\\frac{1-z}{1-\\mu}}.\n\\]"}, {"id": "ch2_corollary_2_19:fix:1", "name": "Theorem 2.7 (proof)", "statement": "Theorem 2.7. For all \\(\\epsilon' > \\epsilon > 0\\):\n\\[\n\\underline{\\lim}_{n\\rightarrow\\infty}\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\geq-I_{X_{1}}(\\mu+\\epsilon^{\\prime}).\n\\]\nSimilarly,\n\\[\n\\underline{\\lim}_{n\\rightarrow\\infty}\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}\\leq\\mu-\\epsilon)\\geq-I_{X_{1}}(\\mu-\\epsilon^{\\prime}).\n\\]\nProof. We only need to prove the first inequality. Consider \\(\\Pr(X_i \\leq x)\\) as a function of \\(x\\), and define a random variable \\(X_i'\\) with density at \\(x\\) as\n\\[\nd\\Pr(X_{i}^{\\prime}\\leq x)=e^{\\lambda x-\\Lambda_{X_{1}}(\\lambda)}d\\Pr(X_{i}\\leq x).\n\\]\nThis choice implies that\n\\[\n\\frac{d}{d\\lambda}\\Lambda_{X_{1}}(\\lambda)=\\frac{\\int x e^{\\lambda x}d\\Pr(X_{1}\\leq x)}{\\int e^{\\lambda x}d\\Pr(X_{1}\\leq x)}=\\mathbb{E}_{X_{1}^{\\prime}}X_{1}^{\\prime}.\n\\]\nWe now take \\(\\lambda\\) such that\n\\[\n\\lambda=\\arg\\max_{\\lambda^{\\prime}>0}\\left[\\lambda^{\\prime}(\\mu+\\epsilon^{\\prime})-\\Lambda_{X_{1}}(\\lambda^{\\prime})\\right].\n\\]\nBy setting the derivative to zero, we obtain\n\\[\n\\mathbb{E}_{X_{1}^{\\prime}}X_{1}^{\\prime}=\\frac{d}{d\\lambda}\\Lambda_{X_{1}}(\\lambda)=\\mu+\\epsilon^{\\prime},\\tag{2.3}\n\\]\n\\[\n-\\lambda(\\mu+\\epsilon^{\\prime})+\\Lambda(\\lambda)= -I(\\mu+\\epsilon^{\\prime}).\\tag{2.4}\n\\]\nLet \\(\\bar{X}_n' = n^{-1} \\sum_{i=1}^{n} X_i'\\). Then by the law of large numbers, we know that for \\(\\epsilon'' > \\epsilon'\\), we obtain from (2.3)\n\\[\n\\lim_{n\\rightarrow\\infty}\\Pr(\\bar{X}_{n}^{\\prime}-\\mu\\in [\\epsilon,\\epsilon^{\\prime\\prime}])=1.\\tag{2.5}\n\\]\nSince the joint density of \\((X_1', \\ldots, X_n')\\) satisfies\n\\[\ne^{-\\lambda\\sum_{i=1}^{n}x_{i}+n\\Lambda_{X_{1}}(\\lambda)}\\prod_{i}d\\Pr(X_{i}^{\\prime}\\leq x_{i})=\\prod_{i}d\\Pr(X_{i}\\leq x_{i}),\\tag{2.6}\n\\]\nby using \\(\\mathbb{1}(\\cdot)\\) to denote the set indicator function, we obtain\n\\[\n\\begin{array}{l}\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\geq\\Pr(\\bar{X}_{n}-\\mu\\in [\\epsilon,\\epsilon^{\\prime\\prime}])\\\\ =\\mathbb{E}_{X_{1},\\ldots,X_{n}}\\mathbb{1}(\\bar{X}_{n}-\\mu\\in [\\epsilon,\\epsilon^{\\prime\\prime}])\\\\ =\\mathbb{E}_{X_{1}^{\\prime},\\ldots,X_{n}^{\\prime}}e^{-\\lambda n\\bar{X}_{n}^{\\prime}+n\\Lambda(\\lambda)}\\mathbb{1}(\\bar{X}_{n}^{\\prime}-\\mu\\in [\\epsilon,\\epsilon^{\\prime\\prime}])\\\\ \\geq e^{-\\lambda n(\\mu+\\epsilon^{\\prime\\prime})+n\\Lambda(\\lambda)}\\Pr(\\bar{X}_{n}^{\\prime}-\\mu\\in [\\epsilon,\\epsilon^{\\prime\\prime}]).\\\\ \\end{array}\n\\]\nThe first equality used the definition of \\(\\Pr(\\cdot)\\). The second equality used (2.6). The last inequality used Markov's inequality. Now by taking logarithm, and divide by \\(n\\), we obtain\n\\[\n\\begin{array}{l}\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\qquad(2.7)\\\\ \\geq-\\lambda(\\mu+\\epsilon^{\\prime\\prime})+\\Lambda(\\lambda)+\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}^{\\prime}-\\mu\\in [\\epsilon,\\epsilon^{\\prime\\prime}])\\\\ = -I(\\mu+\\epsilon^{\\prime})-\\lambda(\\epsilon^{\\prime\\prime}-\\epsilon^{\\prime})+\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}^{\\prime}-\\mu\\in [\\epsilon,\\epsilon^{\\prime\\prime}]),\\qquad(2.8)\\\\ \\end{array}\n\\]\nThe equality used (2.4). Now we obtain the desired bound by letting \\(n \\to \\infty\\), applying (2.5), and letting \\(\\epsilon'' \\to \\epsilon'\\) so that \\(\\lambda(\\epsilon'' - \\epsilon') \\to 0\\) (this is true because \\(\\lambda\\) depends only on \\(\\epsilon'\\))."}, {"id": "ch2_corollary_2_19:fix:2", "name": "Definition 2.4", "statement": "Definition 2.4. Given a random variable \\(X\\), we may define its logarithmic moment generating function as\n\\[\n\\Lambda_{X}(\\lambda)=\\ln\\mathbb{E}e^{\\lambda X}.\n\\]\nMoreover, given \\(z \\in \\mathbb{R}\\), the rate function \\(I_X(z)\\) is defined as\n\\[\nI_{X}(z)=\\left\\{\\begin{array}{l l}\\sup_{\\lambda>0}\\left[\\lambda z-\\Lambda_{X}(\\lambda)\\right]&z>\\mu\\\\ 0&z=\\mu\\\\ \\sup_{\\lambda<0}\\left[\\lambda z-\\Lambda_{X}(\\lambda)\\right]&z<\\mu,\\end{array}\\right.\n\\]\nwhere \\(\\mu = \\mathbb{E}[X]\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def bernoulliKL (z m : ℝ) : ℝ :=\n z * Real.log (z / m) + (1 - z) * Real.log ((1 - z) / (1 - m))\n\ntheorem ch2_corollary_2_19\n {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P]\n {n : ℕ} (hn : 0 < n) (μ ε : ℝ)\n (X : Fin n → Ω → ℝ)\n (hmeas : ∀ i, Measurable (X i))\n (hbin : ∀ i, ∀ ω, X i ω = 0 ∨ X i ω = 1)\n (hindep : iIndepFun X P)\n (hmean : ∀ i, ∫ ω, X i ω ∂P = μ)\n (hμ0 : 0 < μ) (hμ1 : μ < 1) (hε : 0 < ε) (hμε : μ + ε < 1)\n (hεp_lt : ε + 2 * Real.sqrt ((μ + ε) * (1 - (μ + ε)) / (n : ℝ)) < 1 - μ)\n (hn_lb : (1 - μ - ε) / (μ + ε) ≤ (n : ℝ)) :\n (let ε' := ε + 2 * Real.sqrt ((μ + ε) * (1 - (μ + ��)) / (n : ℝ));\n let ΔI := 2 * Real.sqrt ((μ + ε) * (1 - μ - ε)) *\n Real.log (((μ + ε') * (1 - μ)) / ((1 - (μ + ε')) * μ));\n (P {ω | μ + ε ≤ (1 / (n : ℝ)) * ∑ i : Fin n, X i ω}).toReal ≥\n (0.25 : ℝ) * Real.exp (-(n : ℝ) * bernoulliKL (μ + ε') μ - Real.sqrt (n : ℝ) * ΔI)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nset_option maxHeartbeats 800000\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def bernoulliKL (z m : ℝ) : ℝ :=\n z * Real.log (z / m) + (1 - z) * Real.log ((1 - z) / (1 - m))\n\ntheorem ch2_corollary_2_19\n {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P]\n {n : ℕ} (hn : 0 < n) (μ ε : ℝ)\n (X : Fin n → Ω → ℝ)\n (hmeas : ∀ i, Measurable (X i))\n (hbin : ∀ i, ∀ ω, X i ω = 0 ∨ X i ω = 1)\n (hindep : iIndepFun X P)\n (hmean : ∀ i, ∫ ω, X i ω ∂P = μ)\n (hμ0 : 0 < μ) (hμ1 : μ < 1) (hε : 0 < ε) (hμε : μ + ε < 1)\n (hεp_lt : ε + 2 * Real.sqrt ((μ + ε) * (1 - (μ + ε)) / (n : ℝ)) < 1 - μ)\n (hn_lb : (1 - μ - ε) / (μ + ε) ≤ (n : ℝ)) :\n (let ε' := ε + 2 * Real.sqrt ((μ + ε) * (1 - (μ + ε)) / (n : ℝ));\n let ΔI := 2 * Real.sqrt ((μ + ε) * (1 - μ - ε)) *\n Real.log (((μ + ε') * (1 - μ)) / ((1 - (μ + ε')) * μ));\n (P {ω | μ + ε ≤ (1 / (n : ℝ)) * ∑ i : Fin n, X i ω}).toReal ≥\n (0.25 : ℝ) * Real.exp (-(n : ℝ) * bernoulliKL (μ + ε') μ - Real.sqrt (n : ℝ) * ΔI)) := by\n classical\n dsimp only\n let N : ℝ := n\n let a : ℝ := μ + ε\n let d : ℝ := 2 * Real.sqrt (a * (1 - a) / N)\n let p : ℝ := a + d\n let l : ℝ := Real.log ((p * (1 - μ)) / ((1 - p) * μ))\n let Y : Ω → ℝ := fun ω ↦ ∑ i : Fin n, X i ω\n have hN : 0 < N := by dsimp [N]; exact_mod_cast hn\n have ha0 : 0 < a := by dsimp [a]; linarith\n have ha1 : a < 1 := by dsimp [a]; linarith\n have hrad0 : 0 ≤ a * (1 - a) / N := div_nonneg (mul_nonneg ha0.le (sub_nonneg.mpr ha1.le)) hN.le\n have hd0 : 0 ≤ d := by simp [d]\n have hp0 : 0 < p := by dsimp [p]; linarith\n have hp1 : p < 1 := by\n dsimp [p, d, a, N]\n linarith\n have hμ0' : μ ≠ 0 := ne_of_gt hμ0\n have h1μ0 : 0 < 1 - μ := sub_pos.mpr hμ1\n have h1p0 : 0 < 1 - p := sub_pos.mpr hp1\n have hratio0 : 0 < (p * (1 - μ)) / ((1 - p) * μ) :=\n div_pos (mul_pos hp0 h1μ0) (mul_pos h1p0 hμ0)\n have hl0 : 0 < l := by\n change 0 < Real.log ((p * (1 - μ)) / ((1 - p) * μ))\n exact Real.log_pos ((one_lt_div₀ (mul_pos h1p0 hμ0)).2 (by nlinarith))\n have hX_mem (i : Fin n) : ∀ᵐ ω ∂P, X i ω ∈ Set.Icc (0 : ℝ) 1 := by\n filter_upwards [] with ω\n rcases hbin i ω with h | h <;> simp [h]\n have hXi_int (i : Fin n) : Integrable (X i) P :=\n (integrable_const (1 : ℝ)).mono (hmeas i).aestronglyMeasurable (by\n filter_upwards [hX_mem i] with ω hω\n rw [Real.norm_eq_abs, abs_of_nonneg hω.1]\n simpa using hω.2)\n have hXi_mgf (i : Fin n) (t : ℝ) :\n ProbabilityTheory.mgf (X i) P t = 1 - μ + μ * Real.exp t := by\n rw [ProbabilityTheory.mgf]\n have heq : (fun ω ↦ Real.exp (t * X i ω)) =ᵐ[P]\n fun ω ↦ 1 + X i ω * (Real.exp t - 1) := by\n filter_upwards [] with ω\n rcases hbin i ω with h | h <;> simp [h]\n rw [integral_congr_ae heq, integral_add, integral_const, integral_mul_const, hmean i,\n measureReal_univ_eq_one]\n · norm_num\n ring\n · exact integrable_const _\n · exact hXi_int i |>.mul_const _\n have hExp (i : Fin n) (t : ℝ) : Integrable (fun ω ↦ Real.exp (t * X i ω)) P :=\n integrable_exp_mul_of_mem_Icc (hmeas i).aemeasurable (hX_mem i)\n have hYmeas : Measurable Y := by\n exact Finset.measurable_sum _ fun i _ ↦ hmeas i\n have hYexp (t : ℝ) : Integrable (fun ω ↦ Real.exp (t * Y ω)) P := by\n simpa [Y] using\n hindep.integrable_exp_mul_sum (t := t) hmeas\n (s := Finset.univ) (fun i _ ↦ hExp i t)\n have hcgf (t : ℝ) :\n ProbabilityTheory.cgf Y P t = N * Real.log (1 - μ + μ * Real.exp t) := by\n rw [show Y = ∑ i ∈ Finset.univ, X i by\n funext ω; simp [Y, Finset.sum_apply]]\n rw [hindep.cgf_sum hmeas (fun i _ ↦ hExp i t)]\n simp_rw [ProbabilityTheory.cgf, hXi_mgf]\n simp [N]\n have hbase0 (t : ℝ) : 0 < 1 - μ + μ * Real.exp t := by positivity\n have hl_exp :\n Real.exp l = (p * (1 - μ)) / ((1 - p) * μ) := by\n change Real.exp (Real.log ((p * (1 - μ)) / ((1 - p) * μ))) =\n (p * (1 - μ)) / ((1 - p) * μ)\n rw [Real.exp_log hratio0]\n have hmgfl :\n 1 - μ + μ * Real.exp l = (1 - μ) / (1 - p) := by\n rw [hl_exp]\n field_simp\n ring\n let Q : Measure Ω := P.tilted (l * Y ·)\n have hQprob : IsProbabilityMeasure Q := by\n dsimp [Q]\n exact isProbabilityMeasure_tilted (hYexp l)\n letI : IsProbabilityMeasure Q := hQprob\n have hl_mem : l ∈ interior (integrableExpSet Y P) := by\n have hs : integrableExpSet Y P = Set.univ := by\n apply Set.eq_univ_of_forall\n intro t\n exact hYexp t\n rw [hs, interior_univ]\n trivial\n have hderiv (t : ℝ) :\n deriv (fun s ↦ N * Real.log (1 - μ + μ * Real.exp s)) t =\n N * (μ * Real.exp t) / (1 - μ + μ * Real.exp t) := by\n convert (((Real.hasDerivAt_exp t).const_mul μ).const_add (1 - μ)).log\n (ne_of_gt (hbase0 t)) |>.const_mul N |>.deriv using 1 <;> ring\n have hderiv_fun :\n deriv (fun s ↦ N * Real.log (1 - μ + μ * Real.exp s)) =\n fun t ↦ N * (μ * Real.exp t) / (1 - μ + μ * Real.exp t) :=\n funext hderiv\n have hQmean : ∫ ω, Y ω ∂Q = N * p := by\n rw [show Q = P.tilted (l * Y ·) by rfl, integral_tilted_mul_self hl_mem]\n rw [show ProbabilityTheory.cgf Y P =\n fun t ↦ N * Real.log (1 - μ + μ * Real.exp t) from funext hcgf]\n rw [hderiv, hmgfl, hl_exp]\n field_simp\n have hQvar : Var[Y; Q] = N * p * (1 - p) := by\n rw [show Q = P.tilted (l * Y ·) by rfl, variance_tilted_mul hl_mem]\n rw [show ProbabilityTheory.cgf Y P =\n fun t ↦ N * Real.log (1 - μ + μ * Real.exp t) from funext hcgf]\n rw [show (2 : ℕ) = 1 + 1 by omega, iteratedDeriv_succ,\n show (1 : ℕ) = 0 + 1 by omega, iteratedDeriv_succ]\n simp only [iteratedDeriv_zero]\n rw [hderiv_fun]\n have hh : HasDerivAt\n (fun t ↦ N * (μ * Real.exp t) / (1 - μ + μ * Real.exp t))\n (N * ((μ * Real.exp l) * (1 - μ + μ * Real.exp l) -\n (μ * Real.exp l) * (μ * Real.exp l)) /\n (1 - μ + μ * Real.exp l) ^ 2) l := by\n convert (((Real.hasDerivAt_exp l).const_mul μ).div\n (((Real.hasDerivAt_exp l).const_mul μ).const_add (1 - μ))\n (ne_of_gt (hbase0 l))).const_mul N using 1\n · funext x\n simp [div_eq_mul_inv]\n ring\n · ring\n rw [hh.deriv, hmgfl, hl_exp]\n field_simp\n have hradpos : 0 < a * (1 - a) / N :=\n div_pos (mul_pos ha0 (sub_pos.mpr ha1)) hN\n have hdpos : 0 < d := by simp [d, Real.sqrt_pos.2 hradpos]\n have hd_sq : d ^ 2 = 4 * a * (1 - a) / N := by\n change (2 * Real.sqrt (a * (1 - a) / N)) ^ 2 = _\n rw [mul_pow, Real.sq_sqrt hrad0]\n ring\n have hd_le : d ≤ 2 * a := by\n have hh : (1 - a) / N ≤ a := by\n apply (div_le_iff₀ hN).2\n have := hn_lb\n dsimp [a, N] at *\n apply (div_le_iff₀ ha0).1 at this\n nlinarith\n have hs : d ^ 2 ≤ (2 * a) ^ 2 := by\n rw [hd_sq]\n apply (div_le_iff₀ hN).2\n have hha := (div_le_iff₀ hN).1 hh\n nlinarith\n nlinarith\n have hchebR : Q.real {ω | N * d ≤ |Y ω - N * p|} ≤\n p * (1 - p) / (N * d ^ 2) := by\n have hc := meas_ge_le_variance_div_sq\n (μ := Q) (X := Y) (memLp_tilted_mul hl_mem 2) (mul_pos hN hdpos)\n rw [hQmean, hQvar] at hc\n have ht := ENNReal.toReal_mono (by simp) hc\n rw [ENNReal.toReal_ofReal (by positivity)] at ht\n convert ht using 1\n field_simp [hN.ne', hdpos.ne']\n <;> ring\n have hcheb : Q.real {ω | N * d ≤ |Y ω - N * p|} ≤ (0.75 : ℝ) := by\n calc\n _ ≤ p * (1 - p) / (N * d ^ 2) := hchebR\n _ = p * (1 - p) / (4 * a * (1 - a)) := by rw [hd_sq]; field_simp\n _ ≤ p / (4 * a) := by\n have hpa : a ≤ p := by dsimp [p]; linarith\n have hx : 0 ≤ 4 * a * p * (p - a) :=\n mul_nonneg (mul_nonneg (by positivity) hp0.le) (sub_nonneg.mpr hpa)\n apply (div_le_div_iff₀ (mul_pos (mul_pos (by norm_num) ha0) (sub_pos.mpr ha1))\n (mul_pos (by norm_num) ha0)).2\n nlinarith\n _ ≤ 0.75 := by\n apply (div_le_iff₀ (by positivity)).2\n dsimp [p]\n nlinarith\n let B : Set Ω := {ω | |Y ω - N * p| < N * d}\n have hBmeas : MeasurableSet B := by\n exact (hYmeas.sub measurable_const).abs measurableSet_Iio\n have hQB : (0.25 : ℝ) ≤ Q.real B := by\n have hcomp : Bᶜ = {ω | N * d ≤ |Y ω - N * p|} := by\n ext ω\n simp [B]\n have hc : Q.real B + Q.real {ω | N * d ≤ |Y ω - N * p|} = 1 := by\n rw [← hcomp, measureReal_compl hBmeas, probReal_univ]\n ring\n linarith\n let C : ℝ := Real.exp (l * (N * p + N * d) -\n ProbabilityTheory.cgf Y P l)\n have hQBP : Q.real B ≤ C * P.real B := by\n have happ := tilted_mul_apply_cgf (μ := P) (X := Y) (t := l) B (hYexp l)\n change Q B =\n ∫⁻ ω in B, ENNReal.ofReal\n (Real.exp (l * Y ω - ProbabilityTheory.cgf Y P l)) ∂P at happ\n have hen :\n Q B ≤ ENNReal.ofReal C * P B := by\n rw [happ]\n calc\n _ ≤ ∫⁻ _ in B, ENNReal.ofReal C ∂P := by\n apply setLIntegral_mono' hBmeas\n intro ω hω\n apply ENNReal.ofReal_le_ofReal\n apply Real.exp_le_exp.mpr\n have hy : Y ω < N * p + N * d := by\n have := hω\n simp only [B, Set.mem_setOf_eq] at this\n rw [abs_lt] at this\n linarith\n nlinarith [mul_pos hl0 (sub_pos.mpr hy)]\n _ = ENNReal.ofReal C * P B := by simp\n have ht := ENNReal.toReal_mono\n (ENNReal.mul_ne_top (by simp) (measure_ne_top P B)) hen\n rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal (by positivity)] at ht\n exact ht\n have hPB : (0.25 : ℝ) * Real.exp\n (ProbabilityTheory.cgf Y P l - l * (N * p + N * d)) ≤ P.real B := by\n have hCpos : 0 < C := by positivity\n have := hQBP.trans' hQB\n calc\n _ = 0.25 / C := by\n change 0.25 * Real.exp _ =\n 0.25 / Real.exp (l * (N * p + N * d) - ProbabilityTheory.cgf Y P l)\n rw [div_eq_mul_inv, ← Real.exp_neg]\n congr 2\n ring\n _ ≤ P.real B := (div_le_iff₀ hCpos).2 (by simpa [mul_comm] using this)\n have hBA : B ⊆ {ω | a ≤ (1 / N) * Y ω} := by\n intro ω hω\n have hy : N * p - N * d < Y ω := by\n have hh := (abs_lt.1 (show |Y ω - N * p| < N * d by exact hω)).1\n linarith\n have hpa : p - d = a := by simp [p]\n change a ≤ (1 / N) * Y ω\n rw [← hpa]\n apply le_of_lt\n calc\n p - d = (1 / N) * (N * p - N * d) := by field_simp\n _ < (1 / N) * Y ω := by gcongr\n have hPmono : P.real B ≤ P.real {ω | a ≤ (1 / N) * Y ω} := by\n apply ENNReal.toReal_mono (measure_ne_top P _)\n exact measure_mono hBA\n have hexp :\n ProbabilityTheory.cgf Y P l - l * (N * p + N * d) =\n -N * bernoulliKL p μ - Real.sqrt N *\n (2 * Real.sqrt (a * (1 - a)) * l) := by\n rw [hcgf, hmgfl]\n have hsN : Real.sqrt N * Real.sqrt N = N := by\n nlinarith [Real.sq_sqrt hN.le]\n have hsd : Real.sqrt N * (2 * Real.sqrt (a * (1 - a))) = N * d := by\n change Real.sqrt N * (2 * Real.sqrt (a * (1 - a))) =\n N * (2 * Real.sqrt (a * (1 - a) / N))\n rw [Real.sqrt_div (mul_nonneg ha0.le (sub_nonneg.mpr ha1.le))]\n field_simp [Real.sqrt_ne_zero'.2 hN]\n ring_nf at hsN ⊢\n rw [hsN]\n ring\n simp only [l]\n unfold bernoulliKL\n have hlogratio :\n Real.log (p * (1 - μ) / ((1 - p) * μ)) =\n Real.log (p / μ) - Real.log ((1 - p) / (1 - μ)) := by\n rw [Real.log_div (mul_pos hp0 h1μ0).ne' (mul_pos h1p0 hμ0).ne',\n Real.log_mul hp0.ne' h1μ0.ne', Real.log_mul h1p0.ne' hμ0.ne',\n Real.log_div hp0.ne' hμ0.ne', Real.log_div h1p0.ne' h1μ0.ne']\n ring\n rw [Real.log_div h1μ0.ne' h1p0.ne', Real.log_div hp0.ne' hμ0.ne',\n Real.log_div h1p0.ne' h1μ0.ne', hlogratio,\n Real.log_div hp0.ne' hμ0.ne', Real.log_div h1p0.ne' h1μ0.ne', ← hsd]\n ring\n have hmain :\n (0.25 : ℝ) * Real.exp\n (-N * bernoulliKL p μ - Real.sqrt N *\n (2 * Real.sqrt (a * (1 - a)) * l)) ≤\n P.real {ω | a ≤ (1 / N) * Y ω} := by\n calc\n (0.25 : ℝ) * Real.exp\n (-N * bernoulliKL p μ - Real.sqrt N *\n (2 * Real.sqrt (a * (1 - a)) * l))\n = (0.25 : ℝ) * Real.exp\n (ProbabilityTheory.cgf Y P l - l * (N * p + N * d)) := by rw [hexp]\n _ ≤ P.real B := hPB\n _ ≤ P.real {ω | a ≤ (1 / N) * Y ω} := hPmono\n have haexpr : a * (1 - a) = (μ + ε) * (1 - μ - ε) := by\n dsimp [a]\n ring\n rw [haexpr] at hmain\n simpa only [N, a, d, p, l, Y, add_assoc] using hmain\n\nend GraduateLevel\n"} +{"id": "ch2_lemma_2_15", "source": "Graduate-level", "targets": [{"label": "ch2_lemma_2_15", "decls": ["ch2_lemma_2_15"], "statement": "Consider a random variable \\(X \\in [0,1]\\) and \\(\\mathbb{E}X = \\mu\\). We have the following inequality:\n\\[\n\\ln\\mathbb{E}e^{\\lambda X}\\leq\\ln [(1-\\mu)e^{0}+\\mu e^{\\lambda}]\\leq\\lambda\\mu+\\lambda^{2}/8.\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "Let \\( h_L(\\lambda) = \\mathbb{E}e^{\\lambda X} \\) and \\( h_R(\\lambda) = (1 - \\mu)e^0 + \\mu e^\\lambda \\). We know that \\( h_L(0) = h_R(0) \\). Moreover, when \\( \\lambda \\geq 0 \\):\n\\[\nh_{L}^{\\prime}(\\lambda)=\\mathbb{E}X e^{\\lambda X}\\leq\\mathbb{E}X e^{\\lambda}=\\mu e^{\\lambda}=h_{R}^{\\prime}(\\lambda),\n\\]\nand similarly \\(h_L'(\\lambda) \\geq h_R'(\\lambda)\\) when \\(\\lambda \\leq 0\\). This proves the first inequality.\nNow we let\n\\[\nh(\\lambda)=\\ln [(1-\\mu)e^{0}+\\mu e^{\\lambda}].\n\\]\nIt implies that\n\\[\nh^{\\prime}(\\lambda)=\\frac{\\mu e^{\\lambda}}{(1-\\mu)e^{0}+\\mu e^{\\lambda}},\n\\]\nand\n\\[\n\\begin{array}{l}h^{\\prime\\prime}(\\lambda)=\\frac{\\mu e^{\\lambda}}{(1-\\mu)e^{0}+\\mu e^{\\lambda}}-\\frac{(\\mu e^{\\lambda})^{2}}{[(1-\\mu)e^{0}+\\mu e^{\\lambda}]^{2}}\\\\ =\\left|h^{\\prime}(\\lambda)\\right|\\left(1-\\left|h^{\\prime}(\\lambda)\\right|\\right)\\leq 1/4.\\\\ \\end{array}\n\\]\nUsing Taylor expansion, we obtain the inequality \\( h(\\lambda) \\leq h(0) + \\lambda h'(0) + \\lambda^2 / 8 \\), which proves the second inequality.", "context": [{"id": "ch2:theorem:2_12", "name": "theorem 2.12", "statement": "If \\(X_{1}\\) is sub-Gaussian as in (2.10), then for all \\(t > 0\\):\n\\[\n\\Pr\\left(\\bar{X}_{n}\\geq\\mu+\\sqrt{\\frac{2 b t}{n}}\\right)\\leq e^{-t},\n\\]\n\\[\n\\Pr\\left(\\bar{X}_{n}\\leq\\mu-\\sqrt{\\frac{2 b t}{n}}\\right)\\leq e^{-t}.\n\\]"}, {"id": "ch2:definition:2_11", "name": "definition 2.11", "statement": "A sub-Gaussian random variable \\(X\\) has quadratic logarithmic moment generating function for all \\(\\lambda \\in \\mathbb{R}\\):\n\\[\n\\ln\\mathbb{E}e^{\\lambda X}\\leq\\lambda\\mu+\\frac{\\lambda^{2}}{2}b.\\tag{2.10}\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch2_lemma_2_15 {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)\n [IsProbabilityMeasure P] {X : Ω → ℝ} (μ : ℝ)\n (hX : AEMeasurable X P)\n (hmem : ∀ᵐ ω ∂P, X ω ∈ Set.Icc (0 : ℝ) 1)\n (hint : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) P)\n (hmean : ∫ ω, X ω ∂P = μ) :\n ∀ lam : ℝ,\n cgf X P lam ≤ Real.log ((1 - μ) + μ * Real.exp lam) ∧\n Real.log ((1 - μ) + μ * Real.exp lam) ≤ lam * μ + lam ^ 2 / 8 := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch2_lemma_2_15 {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)\n [IsProbabilityMeasure P] {X : Ω → ℝ} (μ : ℝ)\n (hX : AEMeasurable X P)\n (hmem : ∀ᵐ ω ∂P, X ω ∈ Set.Icc (0 : ℝ) 1)\n (hint : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) P)\n (hmean : ∫ ω, X ω ∂P = μ) :\n ∀ lam : ℝ,\n cgf X P lam ≤ Real.log ((1 - μ) + μ * Real.exp lam) ∧\n Real.log ((1 - μ) + μ * Real.exp lam) ≤ lam * μ + lam ^ 2 / 8 := by\n intro lam\n have hXint : Integrable X P := Integrable.of_mem_Icc 0 1 hX hmem\n have hright : Integrable (fun ω => (1 - X ω) * Real.exp 0 + X ω * Real.exp lam) P := by\n convert ((integrable_const (c := (1 : ℝ))).add (hXint.const_mul (Real.exp lam - 1))) using 1 <;>\n ext ω <;> simp <;> ring\n have hchord : ∀ᵐ ω ∂P,\n Real.exp (lam * X ω) ≤ (1 - X ω) * Real.exp 0 + X ω * Real.exp lam := by\n filter_upwards [hmem] with ω hω\n have hc := (convexOn_exp).2 (Set.mem_univ (0 : ℝ)) (Set.mem_univ lam)\n (sub_nonneg.mpr hω.2) hω.1 (by ring)\n convert hc using 1 <;> simp [smul_eq_mul] <;> ring\n have hmgf : mgf X P lam ≤ (1 - μ) + μ * Real.exp lam := by\n rw [mgf]\n calc\n ∫ ω, Real.exp (lam * X ω) ∂P ≤\n ∫ ω, ((1 - X ω) * Real.exp 0 + X ω * Real.exp lam) ∂P :=\n integral_mono_ae (hint lam) hright hchord\n _ = (1 - μ) + μ * Real.exp lam := by\n rw [show (fun ω => (1 - X ω) * Real.exp 0 + X ω * Real.exp lam) =\n fun ω => 1 + (Real.exp lam - 1) * X ω by ext ω; simp; ring]\n rw [integral_add (integrable_const (c := (1 : ℝ))) ((hXint.const_mul _)), integral_const,\n integral_const_mul, hmean]\n simp\n ring\n constructor\n · exact Real.log_le_log (mgf_pos (hint lam)) hmgf\n · have hμ0 : 0 ≤ μ := by\n rw [← hmean]\n exact integral_nonneg_of_ae (hmem.mono fun _ h => h.1)\n have hμ1 : μ ≤ 1 := by\n rw [← hmean]\n have := integral_mono_ae hXint (integrable_const (c := (1 : ℝ)))\n (hmem.mono fun _ h => h.2)\n simpa using this\n let p : NNReal := μ.toNNReal\n have hp : p ≤ 1 := by simpa [p, Real.toNNReal_of_nonneg hμ0] using hμ1\n let Q : Measure Bool := (PMF.bernoulli p hp).toMeasure\n let Y : Bool → ℝ := fun b => cond b 1 0\n have hYmeas : AEMeasurable Y Q := Measurable.aemeasurable (measurable_of_countable _)\n have hYmem : ∀ᵐ b ∂Q, Y b ∈ Set.Icc (0 : ℝ) 1 := Filter.Eventually.of_forall fun b => by\n cases b <;> simp [Y]\n have hs := hasSubgaussianMGF_of_mem_Icc hYmeas hYmem\n have hYmean : ∫ b, Y b ∂Q = μ := by\n simpa [Q, Y, p, Real.toNNReal_of_nonneg hμ0] using PMF.bernoulli_expectation hp\n have hcenter : mgf (fun b => Y b - μ) Q lam ≤ Real.exp (lam ^ 2 / 8) := by\n convert hs.mgf_le lam using 1 <;> simp [hYmean] <;> ring\n have hmgf' : mgf Y Q lam ≤ Real.exp (lam * μ + lam ^ 2 / 8) := by\n have hshift : Y = fun b => (Y b - μ) + μ := by\n funext b\n ring\n rw [hshift, mgf_add_const]\n calc\n mgf (fun b => Y b - μ) Q lam * Real.exp (lam * μ) ≤\n Real.exp (lam ^ 2 / 8) * Real.exp (lam * μ) :=\n mul_le_mul_of_nonneg_right hcenter (le_of_lt (Real.exp_pos _))\n _ = Real.exp (lam * μ + lam ^ 2 / 8) := by rw [← Real.exp_add]; ring_nf\n have hYmgf : mgf Y Q lam = (1 - μ) + μ * Real.exp lam := by\n simp [mgf, Q, Y, PMF.integral_eq_sum, PMF.bernoulli]\n have hsub : (1 - (p : ENNReal)).toReal = 1 - (p : ℝ) := by\n have hp' : (p : ENNReal) ≤ 1 := by exact_mod_cast hp\n rw [ENNReal.toReal_sub_of_le hp' ENNReal.one_ne_top]\n simp\n rw [hsub]\n have hpcoe : (p : ℝ) = μ := Real.coe_toNNReal μ hμ0\n rw [hpcoe]\n ring\n rw [← hYmgf]\n simpa [cgf] using Real.log_le_log\n (mgf_pos (integrable_exp_mul_of_mem_Icc hYmeas hYmem)) hmgf'\n\nend GraduateLevel\n"} +{"id": "ch2_lemma_2_20", "source": "Graduate-level", "targets": [{"label": "ch2_lemma_2_20", "decls": ["ch2_lemma_2_20"], "statement": "If \\(X - \\mathbb{E}X \\leq b\\), then \\(\\forall \\lambda \\geq 0\\):\n\\[\n\\ln \\mathbb{E} e^{\\lambda X} \\leq \\lambda \\mathbb{E}X + \\lambda^{2} \\phi(\\lambda b) \\operatorname{Var}(X),\n\\]\nwhere \\(\\phi(z) = (e^{z} - z - 1)/z^{2}\\).", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "Let \\(X' = X - \\mathbb{E}X\\). We have\n\\[\n\\begin{array}{l}\n\\ln \\mathbb{E} e^{\\lambda X} = \\lambda \\mathbb{E}X + \\ln \\mathbb{E} e^{\\lambda X'} \\\\\n\\leq \\lambda \\mathbb{E}X + \\mathbb{E} e^{\\lambda X'} - 1 \\\\\n= \\lambda \\mathbb{E}X + \\lambda^{2} \\mathbb{E} \\frac{e^{\\lambda X'} - \\lambda X' - 1}{(\\lambda X')^{2}} (X')^{2} \\\\\n\\leq \\lambda \\mathbb{E}X + \\lambda^{2} \\mathbb{E} \\phi(\\lambda b) (X')^{2},\n\\end{array}\n\\]\nwhere the first inequality used \\(\\ln z \\leq z - 1\\); the second inequality follows from the fact that the function \\(\\phi(z)\\) is non-decreasing (left as an exercise) and \\(\\lambda X' \\leq \\lambda b\\).", "context": [{"id": "ch2:theorem:2_5", "name": "theorem 2.5", "statement": "For any \\(n\\) and \\(\\epsilon >0\\):\n\\[\n\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq-I_{X_{1}}(\\mu+\\epsilon)=\\inf_{\\lambda>0}\\left[-\\lambda(\\mu+\\epsilon)+\\ln\\mathbb{E}e^{\\lambda X_{1}}\\right],\n\\]\n\\[\n\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}\\leq\\mu-\\epsilon)\\leq-I_{X_{1}}(\\mu-\\epsilon)=\\inf_{\\lambda<0}\\left[-\\lambda(\\mu-\\epsilon)+\\ln\\mathbb{E}e^{\\lambda X_{1}}\\right].\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def phi (z : ℝ) : ℝ := if z = 0 then 1/2 else (Real.exp z - z - 1) / z ^ 2\n\ntheorem ch2_lemma_2_20 {Ω : Type*} [MeasurableSpace Ω]\n (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsProbabilityMeasure μ]\n (X : Ω → ℝ) (b : ℝ)\n (hX_int : MeasureTheory.Integrable X μ)\n (hexpX_int : ∀ lam : ℝ, 0 ≤ lam →\n MeasureTheory.Integrable (fun ω => Real.exp (lam * X ω)) μ)\n (hX_L2 : MeasureTheory.MemLp X 2 μ)\n (hb : ∀ᵐ ω ∂μ, X ω - (∫ x, X x ∂μ) ≤ b) :\n ∀ lam : ℝ, 0 ≤ lam →\n Real.log (∫ ω, Real.exp (lam * X ω) ∂μ)\n ≤ lam * (∫ ω, X ω ∂μ)\n + lam ^ 2 * phi (lam * b) * ProbabilityTheory.variance X μ := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def phi (z : ℝ) : ℝ := if z = 0 then 1/2 else (Real.exp z - z - 1) / z ^ 2\n\nprivate lemma phi_id (z : ℝ) : Real.exp z - z - 1 = z ^ 2 * phi z := by\n rcases eq_or_ne z 0 with rfl | hz\n · simp\n · rw [phi, if_neg hz]\n field_simp\n\nprivate lemma cont_aux (z : ℝ) :\n Continuous (fun t : ℝ => (1 - t) * Real.exp (t * z)) := by\n fun_prop\n\nprivate lemma phi_eq_int (z : ℝ) :\n phi z = ∫ t in (0:ℝ)..1, (1 - t) * Real.exp (t * z) := by\n rcases eq_or_ne z 0 with rfl | hz\n · have : (∫ t in (0:ℝ)..1, (1 - t) * Real.exp (t * 0)) = ∫ t in (0:ℝ)..1, (1 - t) := by\n congr 1; funext t; simp\n rw [this]\n rw [intervalIntegral.integral_sub intervalIntegrable_const\n (intervalIntegral.intervalIntegrable_id)]\n simp [phi]\n norm_num\n · have hF : ∀ t : ℝ, HasDerivAt\n (fun t : ℝ => ((1/z + 1/z^2) + (-1/z) * t) * Real.exp (t * z))\n ((1 - t) * Real.exp (t * z)) t := by\n intro t\n have h1 : HasDerivAt (fun t : ℝ => (1/z + 1/z^2) + (-1/z) * t) (-1/z) t := by\n simpa using ((hasDerivAt_id t).const_mul (-1/z)).const_add (1/z + 1/z^2)\n have h2 : HasDerivAt (fun t : ℝ => Real.exp (t * z)) (Real.exp (t * z) * z) t := by\n simpa using (Real.hasDerivAt_exp (t * z)).comp t ((hasDerivAt_id t).mul_const z)\n have h3 := h1.mul h2\n convert h3 using 1\n field_simp\n ring\n rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hF t)\n ((cont_aux z).intervalIntegrable _ _)]\n rw [phi, if_neg hz]\n simp only [Real.exp_zero, mul_one, zero_mul, one_mul]\n field_simp\n ring\n\nprivate lemma phi_mono : Monotone phi := by\n intro u v huv\n rw [phi_eq_int, phi_eq_int]\n apply intervalIntegral.integral_mono_on (by norm_num)\n ((cont_aux u).intervalIntegrable _ _) ((cont_aux v).intervalIntegrable _ _)\n intro t ht\n have h0 : (0:ℝ) ≤ 1 - t := by linarith [ht.2]\n have h1 : t * u ≤ t * v := mul_le_mul_of_nonneg_left huv ht.1\n exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.2 h1) h0\n\nprivate lemma phi_pointwise (lam b x : ℝ) (hlam : 0 ≤ lam) (hx : x ≤ b) :\n Real.exp (lam * x) - lam * x - 1 ≤ lam ^ 2 * phi (lam * b) * x ^ 2 := by\n have h1 : Real.exp (lam * x) - lam * x - 1 = (lam * x) ^ 2 * phi (lam * x) := phi_id _\n have h2 : phi (lam * x) ≤ phi (lam * b) :=\n phi_mono (mul_le_mul_of_nonneg_left hx hlam)\n have h3 : (lam * x) ^ 2 * phi (lam * x) ≤ (lam * x) ^ 2 * phi (lam * b) :=\n mul_le_mul_of_nonneg_left h2 (sq_nonneg _)\n rw [h1]\n calc (lam * x) ^ 2 * phi (lam * x) ≤ (lam * x) ^ 2 * phi (lam * b) := h3\n _ = lam ^ 2 * phi (lam * b) * x ^ 2 := by ring\n\ntheorem ch2_lemma_2_20 {Ω : Type*} [MeasurableSpace Ω]\n (μ : MeasureTheory.Measure Ω) [MeasureTheory.IsProbabilityMeasure μ]\n (X : Ω → ℝ) (b : ℝ)\n (hX_int : MeasureTheory.Integrable X μ)\n (hexpX_int : ∀ lam : ℝ, 0 ≤ lam →\n MeasureTheory.Integrable (fun ω => Real.exp (lam * X ω)) μ)\n (hX_L2 : MeasureTheory.MemLp X 2 μ)\n (hb : ∀ᵐ ω ∂μ, X ω - (∫ x, X x ∂μ) ≤ b) :\n ∀ lam : ℝ, 0 ≤ lam →\n Real.log (∫ ω, Real.exp (lam * X ω) ∂μ)\n ≤ lam * (∫ ω, X ω ∂μ)\n + lam ^ 2 * phi (lam * b) * ProbabilityTheory.variance X μ := by\n intro lam hlam\n set m : ℝ := ∫ x, X x ∂μ with hm\n -- integrability of the centered exponential\n have hint1 : Integrable (fun ω => Real.exp (lam * (X ω - m))) μ := by\n have := (hexpX_int lam hlam).const_mul (Real.exp (-(lam * m)))\n refine this.congr (Filter.Eventually.of_forall fun ω => ?_)\n simp only [← Real.exp_add]\n ring_nf\n have hint2 : Integrable (fun ω => lam * (X ω - m)) μ :=\n ((hX_int.sub (integrable_const m)).const_mul lam)\n have hint3 : Integrable (fun _ : Ω => (1:ℝ)) μ := integrable_const 1\n have hsqint : Integrable (fun ω => (X ω - m) ^ 2) μ := by\n have h := (hX_L2.sub (memLp_const (p := 2) (μ := μ) m))\n simpa using h.integrable_sq\n set A : ℝ := ∫ ω, Real.exp (lam * (X ω - m)) ∂μ with hA\n have hsplit : (∫ ω, Real.exp (lam * X ω) ∂μ) = Real.exp (lam * m) * A := by\n rw [hA, ← integral_const_mul]\n congr 1\n funext ω\n rw [← Real.exp_add]\n ring_nf\n have hApos : 0 < A := by\n rw [hA, integral_pos_iff_support_of_nonneg\n (fun ω => (Real.exp_pos _).le) hint1]\n have : (Function.support fun ω => Real.exp (lam * (X ω - m))) = Set.univ := by\n ext ω; simp [Function.support, Real.exp_ne_zero]\n rw [this]\n simp\n have hXm : (∫ ω, (X ω - m) ∂μ) = 0 := by\n rw [integral_sub hX_int (integrable_const m), integral_const]\n simp [hm]\n have hint12 : Integrable (fun ω => Real.exp (lam * (X ω - m)) - lam * (X ω - m)) μ :=\n hint1.sub hint2\n have hAeq : A - 1 = ∫ ω, (Real.exp (lam * (X ω - m)) - lam * (X ω - m) - 1) ∂μ := by\n rw [integral_sub hint12 hint3, integral_sub hint1 hint2,\n integral_const_mul, hXm]\n simp\n exact hA\n have hmono : (∫ ω, (Real.exp (lam * (X ω - m)) - lam * (X ω - m) - 1) ∂μ)\n ≤ ∫ ω, lam ^ 2 * phi (lam * b) * (X ω - m) ^ 2 ∂μ := by\n refine integral_mono_ae ((hint1.sub hint2).sub hint3) (hsqint.const_mul _) ?_\n filter_upwards [hb] with ω hω\n exact phi_pointwise lam b (X ω - m) hlam hω\n have hvar : (∫ ω, lam ^ 2 * phi (lam * b) * (X ω - m) ^ 2 ∂μ)\n = lam ^ 2 * phi (lam * b) * ProbabilityTheory.variance X μ := by\n rw [integral_const_mul, ProbabilityTheory.variance_eq_integral hX_int.aemeasurable]\n rw [hsplit, Real.log_mul (Real.exp_ne_zero _) (ne_of_gt hApos), Real.log_exp]\n have hlog : Real.log A ≤ A - 1 := Real.log_le_sub_one_of_pos hApos\n have : Real.log A ≤ lam ^ 2 * phi (lam * b) * ProbabilityTheory.variance X μ := by\n calc Real.log A ≤ A - 1 := hlog\n _ = _ := hAeq\n _ ≤ _ := hmono\n _ = _ := hvar\n linarith\n\nend GraduateLevel\n"} +{"id": "ch2_theorem_2_16", "source": "Graduate-level", "targets": [{"label": "ch2_theorem_2_16", "decls": ["ch2_theorem_2_16"], "statement": "Assume that \\( X_{1} \\in [0,1] \\). Then for all \\( \\epsilon > 0 \\):\n\\[\n\\begin{array}{l}\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq e^{-2n\\epsilon^{2}},\\\\ \\operatorname*{Pr}(\\bar{X}_{n}\\leq\\mu-\\epsilon)\\leq e^{-2n\\epsilon^{2}}.\\\\ \\end{array}\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "We simply take \\( b = 1/4 \\) and \\( t = 2n\\epsilon^2 \\) in Theorem 2.12 to obtain the first inequality. The second inequality follows from the equivalence of \\( \\bar{X}_n \\leq \\mu - \\epsilon \\) and \\( -\\bar{X}_n \\leq -\\mu + \\epsilon \\).", "context": [{"id": "ch2:theorem:2_12", "name": "theorem 2.12", "statement": "If \\(X_{1}\\) is sub-Gaussian as in (2.10), then for all \\(t > 0\\):\n\\[\n\\Pr\\left(\\bar{X}_{n}\\geq\\mu+\\sqrt{\\frac{2 b t}{n}}\\right)\\leq e^{-t},\n\\]\n\\[\n\\Pr\\left(\\bar{X}_{n}\\leq\\mu-\\sqrt{\\frac{2 b t}{n}}\\right)\\leq e^{-t}.\n\\]"}, {"id": "ch2:lemma:2_15", "name": "lemma 2.15", "statement": "Consider a random variable \\(X \\in [0,1]\\) and \\(\\mathbb{E}X = \\mu\\). We have the following inequality:\n\\[\n\\ln\\mathbb{E}e^{\\lambda X}\\leq\\ln [(1-\\mu)e^{0}+\\mu e^{\\lambda}]\\leq\\lambda\\mu+\\lambda^{2}/8.\n\\]"}, {"id": "ch2:equation:2_1", "name": "equation 2.1", "statement": "Let \\(X_1, \\ldots, X_n\\) be \\(n\\) real-valued independent and identically distributed (iid) random variables, with expectation \\(\\mu = \\mathbb{E} X_i\\). Let\n\\[\n\\bar{X}_n = \\frac{1}{n}\\sum_{i=1}^n X_i. \\tag{2.1}\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch2_theorem_2_16\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} (hn : 0 < n) (X : Fin n → Ω → ℝ)\n (h_meas : ∀ i, AEMeasurable (X i) P)\n (h_indep : iIndepFun X P)\n (hident : ∀ i j, Measure.map (X i) P = Measure.map (X j) P)\n (h_bound : ∀ i, ∀ᵐ ω ∂P, X i ω ∈ Set.Icc (0 : ℝ) 1)\n (m : ℝ) (hm : ∀ i, ∫ ω, X i ω ∂P = m)\n {ε : ℝ} (hε : 0 < ε) :\n (P {ω | m + ε ≤ (n : ℝ)⁻¹ * ∑ i, X i ω}).toReal ≤ Real.exp (-2 * (n : ℝ) * ε ^ 2) ∧\n (P {ω | (n : ℝ)⁻¹ * ∑ i, X i ω ≤ m - ε}).toReal ≤ Real.exp (-2 * (n : ℝ) * ε ^ 2) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch2_theorem_2_16\n {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P]\n {n : ℕ} (hn : 0 < n) (X : Fin n → Ω → ℝ)\n (h_meas : ∀ i, AEMeasurable (X i) P)\n (h_indep : iIndepFun X P)\n (hident : ∀ i j, Measure.map (X i) P = Measure.map (X j) P)\n (h_bound : ∀ i, ∀ᵐ ω ∂P, X i ω ∈ Set.Icc (0 : ℝ) 1)\n (m : ℝ) (hm : ∀ i, ∫ ω, X i ω ∂P = m)\n {ε : ℝ} (hε : 0 < ε) :\n (P {ω | m + ε ≤ (n : ℝ)⁻¹ * ∑ i, X i ω}).toReal ≤ Real.exp (-2 * (n : ℝ) * ε ^ 2) ∧\n (P {ω | (n : ℝ)⁻¹ * ∑ i, X i ω ≤ m - ε}).toReal ≤ Real.exp (-2 * (n : ℝ) * ε ^ 2) := by\n let Y : Fin n → Ω → ℝ := fun i ω => X i ω - m\n have hnR : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn)\n have h_indepY : iIndepFun Y P := by\n let g : Fin n → ℝ → ℝ := fun _ x => x - m\n have hg : ∀ i : Fin n, Measurable (g i) :=\n fun _ => measurable_id.sub_const m\n have hcomp := h_indep.comp g hg\n simpa [Y, g, Function.comp_def] using hcomp\n have h_subG : ∀ i, HasSubgaussianMGF (Y i) (1 / 4 : NNReal) P := by\n intro i\n have h := hasSubgaussianMGF_of_mem_Icc (h_meas i) (h_bound i)\n convert h using 1 <;> simp [Y, hm i] <;> norm_num\n have h_sum : HasSubgaussianMGF (fun ω => ∑ i, Y i ω) (n / 4 : NNReal) P := by\n have h := HasSubgaussianMGF.sum_of_iIndepFun h_indepY\n (s := Finset.univ) (c := fun _ => (1 / 4 : NNReal))\n (fun i _ => h_subG i)\n simpa using h\n have h_avg := h_sum.const_mul (n : ℝ)⁻¹\n have h_tail := h_avg.measure_ge_le (le_of_lt hε)\n constructor\n · rw [show {ω | m + ε ≤ (n : ℝ)⁻¹ * ∑ i, X i ω} =\n {ω | ε ≤ (n : ℝ)⁻¹ * ∑ i, Y i ω} by\n ext ω\n simp only [Set.mem_setOf_eq, Y, Finset.sum_sub_distrib, Finset.sum_const,\n Finset.card_univ, nsmul_eq_mul]\n field_simp\n rw [Fintype.card_fin]\n constructor <;> intro h <;> linarith]\n convert h_tail using 1 <;> norm_num [hnR]\n field_simp\n ring\n · have h_neg := h_avg.neg.measure_ge_le (le_of_lt hε)\n rw [show {ω | (n : ℝ)⁻¹ * ∑ i, X i ω ≤ m - ε} =\n {ω | ε ≤ -( (n : ℝ)⁻¹ * ∑ i, Y i ω)} by\n ext ω\n simp only [Set.mem_setOf_eq, Y, Finset.sum_sub_distrib, Finset.sum_const,\n Finset.card_univ, nsmul_eq_mul]\n field_simp\n rw [Fintype.card_fin]\n constructor <;> intro h <;> linarith]\n convert h_neg using 1 <;> norm_num [hnR]\n field_simp\n ring\n\nend GraduateLevel\n"} +{"id": "ch2_theorem_2_21", "source": "Graduate-level", "targets": [{"label": "ch2_theorem_2_21", "decls": ["ch2_theorem_2_21"], "statement": "If \\( X_{1} \\leq \\mu + b \\), for some \\( b > 0 \\). Let \\( \\psi(z) = (1 + z)\\ln(1 + z) - z \\), then \\( \\forall \\epsilon > 0 \\):\n\\[\n\\Pr\\left[\\bar{X}_{n}\\geq\\mu+\\epsilon\\right]\\leq\\exp\\left[\\frac{-n\\operatorname{Var}\\left(X_{1}\\right)}{b^{2}}\\psi\\left(\\frac{\\epsilon b}{\\operatorname{Var}\\left(X_{1}\\right)}\\right)\\right],\n\\]\n\\[\n\\Pr [\\bar{X}_{n}\\geq\\mu+\\epsilon]\\leq\\exp\\left[\\frac{-n\\epsilon^{2}}{2\\operatorname{Var}(X_{1})+2\\epsilon b/3}\\right].\n\\]\nMoreover, for \\( t > 0 \\):\n\\[\n\\operatorname*{Pr}\\left[\\bar{X}_{n}\\geq\\mu+\\sqrt{\\frac{2\\operatorname{Var}(X_{1})t}{n}}+\\frac{bt}{3n}\\right]\\leq e^{-t}.\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "Lemma 2.20 implies that\n\\[\n-I_{X_{1}}(\\mu+\\epsilon)\\leq\\inf_{\\lambda>0}\\left[-\\lambda\\epsilon+b^{-2}\\left(e^{\\lambda b}-\\lambda b-1\\right)\\operatorname{Var}\\left(X_{1}\\right)\\right].\n\\]\nWe can set the derivative of the objective function on the right hand side with respect to \\(\\lambda\\) to zero at the minimum solution, and obtain the condition for the optimal \\(\\lambda\\) as follows:\n\\[\n-\\epsilon+b^{-1}(e^{\\lambda b}-1)\\operatorname{Var}\\left(X_{1}\\right)=0.\n\\]\nThis gives the solution \\(\\lambda = b^{-1}\\ln (1 + \\epsilon b / \\mathrm{Var}(X_1))\\). Plugging this solution into the objective function, we obtain\n\\[\n-I_{X_{1}}(\\mu+\\epsilon)\\leq-\\frac{\\operatorname{Var}\\left(X_{1}\\right)}{b^{2}}\\psi\\left(\\frac{\\epsilon b}{\\operatorname{Var}\\left(X_{1}\\right)}\\right).\n\\]\nThe first inequality of the theorem follows from an application of Theorem 2.5.\nGiven \\(\\lambda \\in (0,3 / b)\\), it is easy to verify the following inequality using the Taylor expansion of the exponential function\n\\[\n\\begin{array}{l}\\Lambda_{X_{1}}(\\lambda)\\leq\\mu\\lambda+b^{-2}\\left[e^{\\lambda b}-\\lambda b-1\\right]\\operatorname{Var}(X_{1})\\\\ \\leq\\mu\\lambda+\\frac{\\operatorname{Var}\\left(X_{1}\\right)\\lambda^{2}}{2}\\sum_{m=0}^{\\infty}(\\lambda b/3)^{m}=\\mu\\lambda+\\frac{\\operatorname{Var}\\left(X_{1}\\right)\\lambda^{2}}{2(1-\\lambda b/3)}.\\tag{2.13}\\\\ \\end{array}\n\\]\nThe second and the third desired bounds follow from direct applications of Theorem 2.10 with \\(\\alpha = \\operatorname{Var}(X_1)\\) and \\(\\beta = b / 3\\).", "context": [{"id": "ch2:lemma:2_20", "name": "lemma 2.20", "statement": "If \\(X - \\mathbb{E}X \\leq b\\), then \\(\\forall \\lambda \\geq 0\\):\n\\[\n\\ln \\mathbb{E} e^{\\lambda X} \\leq \\lambda \\mathbb{E}X + \\lambda^{2} \\phi(\\lambda b) \\operatorname{Var}(X),\n\\]\nwhere \\(\\phi(z) = (e^{z} - z - 1)/z^{2}\\)."}, {"id": "ch2:theorem:2_5", "name": "theorem 2.5", "statement": "For any \\(n\\) and \\(\\epsilon >0\\):\n\\[\n\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq-I_{X_{1}}(\\mu+\\epsilon)=\\inf_{\\lambda>0}\\left[-\\lambda(\\mu+\\epsilon)+\\ln\\mathbb{E}e^{\\lambda X_{1}}\\right],\n\\]\n\\[\n\\frac{1}{n}\\ln\\Pr(\\bar{X}_{n}\\leq\\mu-\\epsilon)\\leq-I_{X_{1}}(\\mu-\\epsilon)=\\inf_{\\lambda<0}\\left[-\\lambda(\\mu-\\epsilon)+\\ln\\mathbb{E}e^{\\lambda X_{1}}\\right].\n\\]"}, {"id": "ch2:theorem:2_10", "name": "theorem 2.10", "statement": "If \\( X_{1} \\) has a logarithmic moment generating function that satisfies (2.9) for \\( \\lambda > 0 \\), then all \\( \\epsilon > 0 \\):\n\\[\n\\operatorname*{Pr}(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq\\exp\\left[\\frac{-n\\epsilon^{2}}{2(\\alpha+\\beta\\epsilon)}\\right].\n\\]\nMoreover, for \\(t > 0\\), we have\n\\[\n\\operatorname*{Pr}\\left(\\bar{X}_{n}\\geq\\mu+\\sqrt{\\frac{2\\alpha t}{n}}+\\frac{\\beta t}{n}\\right)\\leq e^{-t}.\n\\]"}, {"id": "ch2_theorem_2_21:fix:1", "name": "Lemma 2.9 (assumption (2.9))", "statement": "Consider a random variable \\(X\\) so that \\(\\mathbb{E}[X] = \\mu\\). Assume that there exists \\(\\alpha > 0\\) and \\(\\beta \\geq 0\\) such that for \\(\\lambda \\in [0, \\beta^{-1})\\):\n\\[\n\\Lambda_X(\\lambda) \\leq \\lambda \\mu + \\frac{\\alpha \\lambda^{2}}{2(1 - \\beta \\lambda)}, \\tag{2.9}\n\\]"}, {"id": "ch2_theorem_2_21:fix:2", "name": "Definition 2.4", "statement": "Given a random variable \\(X\\), we may define its logarithmic moment generating function as\n\\[\n\\Lambda_X(\\lambda) = \\ln \\mathbb{E} e^{\\lambda X}.\n\\]\nMoreover, given \\(z \\in \\mathbb{R}\\), the rate function \\(I_X(z)\\) is defined as\n\\[\nI_X(z) = \\begin{cases} \\sup_{\\lambda > 0} [\\lambda z - \\Lambda_X(\\lambda)] & z > \\mu \\\\ 0 & z = \\mu \\\\ \\sup_{\\lambda < 0} [\\lambda z - \\Lambda_X(\\lambda)] & z < \\mu, \\end{cases}\n\\]\nwhere \\(\\mu = \\mathbb{E}[X]\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch2_theorem_2_21\n {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P]\n (X : ℕ → Ω → ℝ) (hX : ∀ i, Measurable (X i))\n (hint_int : Integrable (X 0) P)\n (hint_L2 : MemLp (X 0) 2 P)\n (hvar : 0 < variance (X 0) P)\n (hindep : iIndepFun X P)\n (hident : ∀ i, IdentDistrib (X i) (X 0) P P)\n (n : ℕ) (hn : 0 < n)\n (μ : ℝ) (hμ : μ = ∫ ω, X 0 ω ∂P)\n (b : ℝ) (hb_pos : 0 < b)\n (hbound : ∀ᵐ ω ∂P, X 0 ω ≤ μ + b) :\n\n (∀ ε : ℝ, 0 < ε →\n (P {ω | μ + ε ≤ (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤\n Real.exp ((-(n : ℝ) * variance (X 0) P / b ^ 2) *\n (let z := ε * b / variance (X 0) P\n (1 + z) * Real.log (1 + z) - z))) ∧\n\n (∀ ε : ℝ, 0 < ε →\n (P {ω | μ + ε ≤ (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤\n Real.exp (-(n : ℝ) * ε ^ 2 / (2 * variance (X 0) P + 2 * ε * b / 3))) ∧\n\n (∀ t : ℝ, 0 < t →\n (P {ω | μ + (Real.sqrt (2 * variance (X 0) P * t / n) + b * t / (3 * n)) ≤\n (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤ Real.exp (-t)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def Gf (u : ℝ) : ℝ := ∫ t in (0:ℝ)..1, (1-t) * Real.exp (t*u)\n\nlemma Gf_spec (u : ℝ) : u^2 * Gf u = Real.exp u - 1 - u := by\n rcases eq_or_ne u 0 with rfl|hu\n · simp\n · have hF : ∀ t : ℝ, HasDerivAt\n (fun s : ℝ => (1-s) * Real.exp (s*u)/u + Real.exp (s*u)/u^2)\n ((1-t) * Real.exp (t*u)) t := by\n intro t\n have hE : HasDerivAt (fun s : ℝ => Real.exp (s*u)) (Real.exp (t*u) * u) t := by\n simpa using ((hasDerivAt_id t).mul_const u).exp\n have h2 : HasDerivAt (fun s : ℝ => (1-s)) (-1) t := by\n simpa using (hasDerivAt_const t (1:ℝ)).sub (hasDerivAt_id t)\n have h3 := ((h2.mul hE).div_const u).add (hE.div_const (u^2))\n convert h3 using 1\n field_simp\n ring\n have hint : IntervalIntegrable (fun t : ℝ => (1-t) * Real.exp (t*u)) MeasureTheory.volume 0 1 :=\n (by fun_prop : Continuous (fun t : ℝ => (1-t) * Real.exp (t*u))).intervalIntegrable 0 1\n have := intervalIntegral.integral_eq_sub_of_hasDerivAt (f := fun s : ℝ =>\n (1-s) * Real.exp (s*u)/u + Real.exp (s*u)/u^2) (fun t _ => hF t) hint\n rw [Gf, this]\n simp only [Real.exp_zero, mul_zero, zero_mul, sub_zero, sub_self]\n field_simp\n ring\n\nlemma Gf_mono {u w : ℝ} (h : u ≤ w) : Gf u ≤ Gf w := by\n apply intervalIntegral.integral_mono_on (by norm_num)\n ((by fun_prop : Continuous (fun t : ℝ => (1-t) * Real.exp (t*u))).intervalIntegrable 0 1)\n ((by fun_prop : Continuous (fun t : ℝ => (1-t) * Real.exp (t*w))).intervalIntegrable 0 1)\n intro t ht\n have ht0 : (0:ℝ) ≤ t := ht.1\n have ht1 : t ≤ 1 := ht.2\n have : Real.exp (t*u) ≤ Real.exp (t*w) :=\n Real.exp_le_exp.mpr (by nlinarith)\n nlinarith [Real.exp_pos (t*u)]\n\nlemma exp_key {u w : ℝ} (h : u ≤ w) :\n (Real.exp u - 1 - u) * w^2 ≤ (Real.exp w - 1 - w) * u^2 := by\n rw [← Gf_spec u, ← Gf_spec w]\n nlinarith [mul_nonneg (sq_nonneg u) (sq_nonneg w), Gf_mono h]\n\nlemma mono_Ici {f f' : ℝ → ℝ} (hc : ContinuousOn f (Set.Ici (0:ℝ)))\n (hd : ∀ x, 0 < x → HasDerivAt f (f' x) x)\n (hn : ∀ x, 0 < x → 0 ≤ f' x) {x : ℝ} (hx : 0 ≤ x) : f 0 ≤ f x := by\n have h := monotoneOn_of_hasDerivWithinAt_nonneg (f := f) (f' := f') (convex_Ici (0:ℝ)) hc\n (fun y hy => by rw [interior_Ici] at hy; exact (hd y hy).hasDerivWithinAt)\n (fun y hy => by rw [interior_Ici] at hy; exact hn y hy)\n exact h Set.left_mem_Ici (Set.mem_Ici.mpr hx) hx\n\nnoncomputable def psi (z : ℝ) : ℝ := (1+z)*Real.log (1+z) - z\n\nlemma hasDerivAt_psi {z : ℝ} (hz : -1 < z) : HasDerivAt psi (Real.log (1+z)) z := by\n have hne : (1:ℝ)+z ≠ 0 := by linarith\n have h1 : HasDerivAt (fun w:ℝ => 1+w) 1 z := by simpa using (hasDerivAt_id z).const_add (1:ℝ)\n have h2 : HasDerivAt (fun w:ℝ => Real.log (1+w)) (1/(1+z)) z := by\n have := (Real.hasDerivAt_log hne).comp z h1\n simpa [one_div] using this\n have h3 := (h1.mul h2).sub (hasDerivAt_id z)\n convert h3 using 1\n field_simp\n ring\n\nlemma logineq1 {z : ℝ} (hz : 0 ≤ z) : 3*z*(6+z)/(2*(3+z)^2) ≤ Real.log (1+z) := by\n have key : ∀ x : ℝ, 0 ≤ x →\n (Real.log (1+0) - 3*0*(6+0)/(2*(3+0)^2)) ≤ (Real.log (1+x) - 3*x*(6+x)/(2*(3+x)^2)) := by\n intro x hx\n refine mono_Ici (f := fun x : ℝ => Real.log (1+x) - 3*x*(6+x)/(2*(3+x)^2))\n (f' := fun x : ℝ => 1/(1+x) - 27/(3+x)^3) ?_ ?_ ?_ hx\n · apply ContinuousOn.sub\n · apply ContinuousOn.log (by fun_prop)\n intro y hy; simp at hy; intro h; linarith\n · apply ContinuousOn.div (by fun_prop) (by fun_prop)\n intro y hy; simp at hy; positivity\n · intro y hy\n have h1 : (1:ℝ)+y ≠ 0 := by linarith\n have h3 : (3:ℝ)+y ≠ 0 := by linarith\n have hl : HasDerivAt (fun w:ℝ => Real.log (1+w)) (1/(1+y)) y := by\n have := (Real.hasDerivAt_log h1).comp y (by simpa using (hasDerivAt_id y).const_add (1:ℝ))\n simpa [one_div] using this\n have hc : HasDerivAt (fun w:ℝ => 3*w*(6+w)) (18+6*y) y := by\n have : HasDerivAt (fun w:ℝ => 18*w+3*w^2) (18+6*y) y := by\n have h := ((hasDerivAt_id y).const_mul (18:ℝ)).add\n ((hasDerivAt_pow 2 y).const_mul (3:ℝ))\n convert h using 1; ring\n convert this using 1; ext w; ring\n have hd : HasDerivAt (fun w:ℝ => 2*(3+w)^2) (4*(3+y)) y := by\n have h := ((by simpa using (hasDerivAt_id y).const_add (3:ℝ) :\n HasDerivAt (fun w:ℝ => 3+w) 1 y).pow 2).const_mul (2:ℝ)\n convert h using 1; ring\n have hdne : (2:ℝ)*(3+y)^2 ≠ 0 := by positivity\n have := hl.sub (hc.div hd hdne)\n convert this using 1\n field_simp\n ring\n · intro y hy\n have h1 : (0:ℝ) < 1+y := by linarith\n have h3 : (0:ℝ) < 3+y := by linarith\n rw [sub_nonneg, div_le_div_iff₀ (by positivity) h1]\n nlinarith [sq_nonneg y, hy.le]\n have := key z hz\n simp only [add_zero, Real.log_one, mul_zero, zero_mul, zero_div, sub_zero, zero_add] at this\n norm_num at this\n linarith\n\nlemma psi_lower1 {z : ℝ} (hz : 0 ≤ z) : 3*z^2/(6+2*z) ≤ psi z := by\n have key : ∀ x : ℝ, 0 ≤ x → (psi 0 - 3*0^2/(6+2*0)) ≤ (psi x - 3*x^2/(6+2*x)) := by\n intro x hx\n refine mono_Ici (f := fun x : ℝ => psi x - 3*x^2/(6+2*x))\n (f' := fun x : ℝ => Real.log (1+x) - 3*x*(6+x)/(2*(3+x)^2)) ?_ ?_ ?_ hx\n · apply ContinuousOn.sub\n · apply ContinuousOn.sub\n · apply ContinuousOn.mul (by fun_prop)\n apply ContinuousOn.log (by fun_prop)\n intro y hy; simp at hy; intro h; linarith\n · fun_prop\n · apply ContinuousOn.div (by fun_prop) (by fun_prop)\n intro y hy; simp at hy; positivity\n · intro y hy\n have hp : HasDerivAt psi (Real.log (1+y)) y := hasDerivAt_psi (by linarith)\n have hc : HasDerivAt (fun w:ℝ => 3*w^2) (6*y) y := by\n have h := (hasDerivAt_pow 2 y).const_mul (3:ℝ)\n convert h using 1; ring\n have hd : HasDerivAt (fun w:ℝ => 6+2*w) 2 y := by\n have h : HasDerivAt (fun w:ℝ => 6+2*w) (0+2*1) y :=\n (hasDerivAt_const y (6:ℝ)).add ((hasDerivAt_id y).const_mul (2:ℝ))\n convert h using 1; ring\n have hdne : (6:ℝ)+2*y ≠ 0 := by linarith\n have := hp.sub (hc.div hd hdne)\n convert this using 1\n field_simp\n ring\n · intro y hy\n have := logineq1 (le_of_lt hy)\n linarith\n have h0 := key z hz\n simp only [psi] at h0 ⊢\n norm_num at h0\n linarith\n\nlemma logineq2 {A : ℝ} (hA : 0 ≤ A) : 3*A/(3+A) ≤ Real.log (1+A+A^2/6) := by\n have key : ∀ x : ℝ, 0 ≤ x →\n (Real.log (1+0+0^2/6) - 3*0/(3+0)) ≤ (Real.log (1+x+x^2/6) - 3*x/(3+x)) := by\n intro x hx\n refine mono_Ici (f := fun x : ℝ => Real.log (1+x+x^2/6) - 3*x/(3+x))\n (f' := fun x : ℝ => (1+x/3)/(1+x+x^2/6) - 9/(3+x)^2) ?_ ?_ ?_ hx\n · apply ContinuousOn.sub\n · apply ContinuousOn.log (by fun_prop)\n intro y hy; simp at hy; nlinarith\n · apply ContinuousOn.div (by fun_prop) (by fun_prop)\n intro y hy; simp at hy; intro h; linarith\n · intro y hy\n have h1 : (0:ℝ) < 1+y+y^2/6 := by nlinarith\n have h3 : (0:ℝ) < 3+y := by linarith\n have hz : HasDerivAt (fun w:ℝ => 1+w+w^2/6) (1+y/3) y := by\n have h := ((hasDerivAt_const y (1:ℝ)).add (hasDerivAt_id y)).add\n ((hasDerivAt_pow 2 y).div_const (6:ℝ))\n convert h using 1; simp; ring\n have hl : HasDerivAt (fun w:ℝ => Real.log (1+w+w^2/6)) ((1+y/3)/(1+y+y^2/6)) y := by\n have := (Real.hasDerivAt_log h1.ne').comp y hz\n simpa [div_eq_mul_inv, mul_comm] using this\n have hc : HasDerivAt (fun w:ℝ => 3*w) 3 y := by\n simpa using (hasDerivAt_id y).const_mul (3:ℝ)\n have hd : HasDerivAt (fun w:ℝ => 3+w) 1 y := by\n simpa using (hasDerivAt_const y (3:ℝ)).add (hasDerivAt_id y)\n have := hl.sub (hc.div hd h3.ne')\n convert this using 1\n field_simp\n ring\n · intro y hy\n have h1 : (0:ℝ) < 1+y+y^2/6 := by nlinarith\n have h3 : (0:ℝ) < 3+y := by linarith\n rw [sub_nonneg, div_le_div_iff₀ (by positivity) h1]\n nlinarith [sq_nonneg y, hy.le, sq_nonneg (y*y)]\n have := key A hA\n norm_num at this\n linarith\n\nlemma psi_lower2 {A : ℝ} (hA : 0 ≤ A) : A^2/2 ≤ psi (A + A^2/6) := by\n have key : ∀ x : ℝ, 0 ≤ x →\n (psi (0 + 0^2/6) - 0^2/2) ≤ (psi (x + x^2/6) - x^2/2) := by\n intro x hx\n refine mono_Ici (f := fun x : ℝ => psi (x + x^2/6) - x^2/2)\n (f' := fun x : ℝ => Real.log (1+x+x^2/6)*(1+x/3) - x) ?_ ?_ ?_ hx\n · apply ContinuousOn.sub\n · apply ContinuousOn.sub\n · apply ContinuousOn.mul (by fun_prop)\n apply ContinuousOn.log (by fun_prop)\n intro y hy; simp at hy; nlinarith\n · fun_prop\n · fun_prop\n · intro y hy\n have hz : HasDerivAt (fun w:ℝ => w + w^2/6) (1+y/3) y := by\n have h := (hasDerivAt_id y).add ((hasDerivAt_pow 2 y).div_const (6:ℝ))\n convert h using 1; simp; ring\n have hp : HasDerivAt (fun w:ℝ => psi (w + w^2/6))\n (Real.log (1+(y+y^2/6)) * (1+y/3)) y :=\n (hasDerivAt_psi (by nlinarith)).comp y hz\n have hq : HasDerivAt (fun w:ℝ => w^2/2) y y := by\n have h := (hasDerivAt_pow 2 y).div_const (2:ℝ)\n convert h using 1; ring\n have := hp.sub hq\n convert this using 1\n simp only [add_assoc]\n · intro y hy\n have := logineq2 hy.le\n have h3 : (0:ℝ) < 3+y := by linarith\n have hstep : 3*y/(3+y) * (1+y/3) ≤ Real.log (1+y+y^2/6) * (1+y/3) := by\n apply mul_le_mul_of_nonneg_right this (by linarith)\n have : 3*y/(3+y) * (1+y/3) = y := by field_simp\n linarith [hstep, this]\n have h0 := key A hA\n simp only [psi] at h0 ⊢\n norm_num at h0\n linarith\n\ntheorem ch2_theorem_2_21\n {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P]\n (X : ℕ → Ω → ℝ) (hX : ∀ i, Measurable (X i))\n (hint_int : Integrable (X 0) P)\n (hint_L2 : MemLp (X 0) 2 P)\n (hvar : 0 < variance (X 0) P)\n (hindep : iIndepFun X P)\n (hident : ∀ i, IdentDistrib (X i) (X 0) P P)\n (n : ℕ) (hn : 0 < n)\n (μ : ℝ) (hμ : μ = ∫ ω, X 0 ω ∂P)\n (b : ℝ) (hb_pos : 0 < b)\n (hbound : ∀ᵐ ω ∂P, X 0 ω ≤ μ + b) :\n\n (∀ ε : ℝ, 0 < ε →\n (P {ω | μ + ε ≤ (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤\n Real.exp ((-(n : ℝ) * variance (X 0) P / b ^ 2) *\n (let z := ε * b / variance (X 0) P\n (1 + z) * Real.log (1 + z) - z))) ∧\n\n (∀ ε : ℝ, 0 < ε →\n (P {ω | μ + ε ≤ (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤\n Real.exp (-(n : ℝ) * ε ^ 2 / (2 * variance (X 0) P + 2 * ε * b / 3))) ∧\n\n (∀ t : ℝ, 0 < t →\n (P {ω | μ + (Real.sqrt (2 * variance (X 0) P * t / n) + b * t / (3 * n)) ≤\n (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤ Real.exp (-t)) := by\n have hb2 : (0:ℝ) < b^2 := by positivity\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n set v := variance (X 0) P with hvdef\n have hv : 0 < v := hvar\n have hEX : ∫ ω, X 0 ω ∂P = μ := hμ.symm\n have hsq : Integrable (fun ω => (X 0 ω - μ)^2) P :=\n (hint_L2.sub (memLp_const μ)).integrable_sq\n have hcenint : Integrable (fun ω => X 0 ω - μ) P := hint_int.sub (integrable_const μ)\n have hcen : ∫ ω, (X 0 ω - μ) ∂P = 0 := by\n rw [integral_sub hint_int (integrable_const μ)]\n simp [hEX]\n have hvar_eq : ∫ ω, (X 0 ω - μ)^2 ∂P = v := by\n rw [hvdef, variance_eq_integral (hX 0).aemeasurable, hEX]\n have hbi : ∀ i, ∀ᵐ ω ∂P, X i ω ≤ μ + b := by\n intro i\n exact (hident i).symm.ae_snd (p := fun x => x ≤ μ + b)\n (measurableSet_Iic (a := μ + b)) hbound\n have hexpint : ∀ lam : ℝ, 0 ≤ lam → ∀ i, Integrable (fun ω => Real.exp (lam * X i ω)) P := by\n intro lam hlam i\n apply Integrable.mono' (g := fun _ : Ω => Real.exp (lam*(μ+b))) (integrable_const _)\n (((hX i).const_mul lam).exp.aestronglyMeasurable)\n filter_upwards [hbi i] with ω hω\n rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)]\n exact Real.exp_le_exp.mpr (by nlinarith)\n have hmgf : ∀ lam : ℝ, 0 < lam →\n mgf (X 0) P lam ≤ Real.exp (lam*μ + v*((Real.exp (lam*b) - lam*b - 1)/b^2)) := by\n intro lam hlam\n set c := (Real.exp (lam*b) - lam*b - 1)/b^2 with hc\n have hc0 : 0 ≤ c := by\n rw [hc]\n apply div_nonneg _ hb2.le\n nlinarith [Real.add_one_le_exp (lam*b)]\n have hpt : ∀ᵐ ω ∂P, Real.exp (lam * X 0 ω) ≤\n Real.exp (lam*μ) * (1 + lam*(X 0 ω - μ) + c*(X 0 ω - μ)^2) := by\n filter_upwards [hbound] with ω hω\n have hle : lam * (X 0 ω - μ) ≤ lam * b := by nlinarith\n have hk := exp_key hle\n have hl2 : (0:ℝ) < lam^2 := by positivity\n have h1 : Real.exp (lam*(X 0 ω - μ)) - 1 - lam*(X 0 ω - μ) ≤ c * (X 0 ω - μ)^2 := by\n rw [hc, div_mul_eq_mul_div, le_div_iff₀ hb2]\n have h9 : ((Real.exp (lam*(X 0 ω - μ)) - 1 - lam*(X 0 ω - μ)) * b^2) * lam^2\n ≤ ((Real.exp (lam*b) - lam*b - 1) * (X 0 ω - μ)^2) * lam^2 := by\n linear_combination hk\n exact le_of_mul_le_mul_right h9 hl2\n have h2 : Real.exp (lam * X 0 ω) = Real.exp (lam*μ) * Real.exp (lam*(X 0 ω - μ)) := by\n rw [← Real.exp_add]; ring_nf\n rw [h2]\n nlinarith [Real.exp_pos (lam*μ), h1]\n have hint1 : Integrable (fun ω => Real.exp (lam * X 0 ω)) P := hexpint lam hlam.le 0\n have hint2 : Integrable\n (fun ω => Real.exp (lam*μ) * (1 + lam*(X 0 ω - μ) + c*(X 0 ω - μ)^2)) P := by\n apply Integrable.const_mul\n exact ((integrable_const (1:ℝ)).add (hcenint.const_mul lam)).add (hsq.const_mul c)\n have hle := integral_mono_ae hint1 hint2 hpt\n have hrhs : ∫ ω, Real.exp (lam*μ) * (1 + lam*(X 0 ω - μ) + c*(X 0 ω - μ)^2) ∂P\n = Real.exp (lam*μ) * (1 + c*v) := by\n have i0 : Integrable (fun _ : Ω => (1:ℝ)) P := integrable_const (1:ℝ)\n have i1' : Integrable (fun ω => lam*(X 0 ω - μ)) P := hcenint.const_mul lam\n have i1 : Integrable (fun ω => 1 + lam*(X 0 ω - μ)) P := i0.add i1'\n have i2 : Integrable (fun ω => c*(X 0 ω - μ)^2) P := hsq.const_mul c\n rw [integral_const_mul]\n congr 1\n rw [integral_add i1 i2, integral_add i0 i1',\n integral_const_mul, integral_const_mul, hcen, hvar_eq]\n simp\n rw [hrhs] at hle\n calc mgf (X 0) P lam = ∫ ω, Real.exp (lam * X 0 ω) ∂P := rfl\n _ ≤ Real.exp (lam*μ) * (1 + c*v) := hle\n _ ≤ Real.exp (lam*μ) * Real.exp (c*v) := by\n apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le\n have := Real.add_one_le_exp (c*v)\n linarith\n _ = Real.exp (lam*μ + v*c) := by rw [← Real.exp_add]; ring_nf\n have master : ∀ lam : ℝ, 0 < lam → ∀ ε : ℝ,\n (P {ω | μ + ε ≤ (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤\n Real.exp ((n:ℝ) * (-(lam*ε) + v*((Real.exp (lam*b) - lam*b - 1)/b^2))) := by\n intro lam hlam ε\n have hset : {ω | μ + ε ≤ (∑ i ∈ Finset.range n, X i ω) / n}\n = {ω | (n:ℝ)*(μ+ε) ≤ (∑ i ∈ Finset.range n, X i) ω} := by\n ext ω\n simp only [Set.mem_setOf_eq, Finset.sum_apply]\n rw [le_div_iff₀ hn']\n constructor <;> intro h <;> nlinarith [h]\n rw [hset, ← measureReal_def]\n have hSint : Integrable (fun ω => Real.exp (lam * (∑ i ∈ Finset.range n, X i) ω)) P :=\n hindep.integrable_exp_mul_sum hX (fun i _ => hexpint lam hlam.le i)\n have hch := measure_ge_le_exp_mul_mgf (μ := P) (X := (∑ i ∈ Finset.range n, X i))\n ((n:ℝ)*(μ+ε)) hlam.le hSint\n have hmgfsum : mgf (∑ i ∈ Finset.range n, X i) P lam = (mgf (X 0) P lam)^n := by\n have := mgf_sum_of_identDistrib (X := X) (s := Finset.range n) (j := 0) hX hindep\n (fun i _ j _ => (hident i).trans (hident j).symm) (Finset.mem_range.mpr hn) lam\n simpa using this\n rw [hmgfsum] at hch\n refine hch.trans ?_\n have hpow : (mgf (X 0) P lam)^n\n ≤ (Real.exp (lam*μ + v*((Real.exp (lam*b) - lam*b - 1)/b^2)))^n :=\n pow_le_pow_left₀ (mgf_nonneg) (hmgf lam hlam) n\n calc Real.exp (-lam * ((n:ℝ)*(μ+ε))) * (mgf (X 0) P lam)^n\n ≤ Real.exp (-lam * ((n:ℝ)*(μ+ε))) *\n (Real.exp (lam*μ + v*((Real.exp (lam*b) - lam*b - 1)/b^2)))^n := by\n exact mul_le_mul_of_nonneg_left hpow (Real.exp_pos _).le\n _ = Real.exp ((n:ℝ) * (-(lam*ε) + v*((Real.exp (lam*b) - lam*b - 1)/b^2))) := by\n rw [← Real.exp_nat_mul, ← Real.exp_add]\n congr 1\n ring\n have part1 : ∀ ε : ℝ, 0 < ε →\n (P {ω | μ + ε ≤ (∑ i ∈ Finset.range n, X i ω) / n}).toReal ≤\n Real.exp ((-(n : ℝ) * v / b ^ 2) * psi (ε * b / v)) := by\n intro ε hε\n set z := ε * b / v with hz\n have hz0 : 0 < z := by rw [hz]; positivity\n have hz1 : (0:ℝ) < 1 + z := by linarith\n set lam := Real.log (1+z) / b with hlam\n have hlog : 0 < Real.log (1+z) := Real.log_pos (by linarith)\n have hlampos : 0 < lam := by rw [hlam]; positivity\n have hlb : lam * b = Real.log (1+z) := by rw [hlam]; field_simp\n have hexplb : Real.exp (lam*b) = 1 + z := by rw [hlb, Real.exp_log hz1]\n refine (master lam hlampos ε).trans_eq ?_\n congr 1\n rw [hexplb, hlb, psi]\n have hεz : ε = z * v / b := by rw [hz]; field_simp\n rw [hεz, hlam]\n field_simp\n ring\n refine ⟨part1, ?_, ?_⟩\n · intro ε hε\n refine (part1 ε hε).trans ?_\n apply Real.exp_le_exp.mpr\n set z := ε * b / v with hz\n have hz0 : 0 < z := by rw [hz]; positivity\n have hpsi := psi_lower1 hz0.le\n have hden : (0:ℝ) < 2*v + 2*ε*b/3 := by positivity\n have hkey : (n:ℝ) * ε^2 / (2*v + 2*ε*b/3) ≤ ((n:ℝ) * v / b^2) * psi z := by\n have h1 : ((n:ℝ) * v / b^2) * (3*z^2/(6+2*z)) = (n:ℝ) * ε^2 / (2*v + 2*ε*b/3) := by\n rw [hz]; field_simp; ring\n rw [← h1]\n apply mul_le_mul_of_nonneg_left hpsi (by positivity)\n have : -((n:ℝ) * v / b^2) * psi z ≤ -((n:ℝ) * ε^2 / (2*v + 2*ε*b/3)) := by linarith\n calc (-(n : ℝ) * v / b ^ 2) * psi z = -((n:ℝ) * v / b^2) * psi z := by ring\n _ ≤ -((n:ℝ) * ε^2 / (2*v + 2*ε*b/3)) := this\n _ = -(n : ℝ) * ε ^ 2 / (2 * v + 2 * ε * b / 3) := by ring\n · intro t ht\n set ε := Real.sqrt (2 * v * t / n) + b * t / (3*n) with hεdef\n have hs0 : 0 < Real.sqrt (2*v*t/n) := Real.sqrt_pos.mpr (by positivity)\n have hε : 0 < ε := by rw [hεdef]; positivity\n refine (part1 ε hε).trans ?_\n apply Real.exp_le_exp.mpr\n set A := b * Real.sqrt (2*v*t/n) / v with hA\n have hA0 : 0 ≤ A := by rw [hA]; positivity\n have hAsq : A^2 = 2*b^2*t/(n*v) := by\n rw [hA, div_pow, mul_pow, Real.sq_sqrt (by positivity : (0:ℝ) ≤ 2*v*t/n)]\n field_simp\n have hzeq : ε * b / v = A + A^2/6 := by\n rw [hεdef, hAsq, hA]\n field_simp\n ring\n have hpsi := psi_lower2 hA0\n rw [hzeq]\n have hkey : t ≤ ((n:ℝ) * v / b^2) * psi (A + A^2/6) := by\n have h1 : ((n:ℝ) * v / b^2) * (A^2/2) = t := by\n rw [hAsq]; field_simp\n calc t = ((n:ℝ) * v / b^2) * (A^2/2) := h1.symm\n _ ≤ ((n:ℝ) * v / b^2) * psi (A + A^2/6) :=\n mul_le_mul_of_nonneg_left hpsi (by positivity)\n have : (-(n : ℝ) * v / b ^ 2) * psi (A + A^2/6) = -(((n:ℝ) * v / b^2) * psi (A + A^2/6)) := by\n ring\n rw [this]\n linarith\n\nend GraduateLevel\n"} +{"id": "ch4_lemma_4_16", "source": "Graduate-level", "targets": [{"label": "ch4_lemma_4_16", "decls": ["ch4_lemma_4_16"], "statement": "If \\(\\operatorname{vc}(\\mathcal{G}) = d\\), then we have for all \\(n > 0\\) and empirical samples \\(\\mathcal{S}_n = \\{Z_1, \\ldots, Z_n\\} \\in \\mathcal{Z}^n\\):\n\\[\n|\\mathcal{G}(\\mathcal{S}_{n})|\\leq\\sum_{\\ell=0}^{d}\\binom{n}{\\ell}\\leq\\max(2,e n/d)^{d}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "First, we prove the statement under the assumption that \\(|\\mathcal{G}(\\mathcal{S}_n)|\\) is upper bounded by the number of subsets of \\(\\mathcal{S}_n\\) (including the empty set) that are shattered by \\(\\mathcal{G}\\). Under this assumption, since any subset shattered by \\(\\mathcal{G}\\) cannot be larger than \\(d\\) by the definition of VC-dimension, and the number of subsets of size \\(\\ell\\) is \\(\\binom{n}{\\ell}\\), we know that the number of subsets shattered by \\(\\mathcal{G}\\) cannot be more than \\(\\sum_{\\ell=1}^{d} \\binom{n}{\\ell}\\). When \\(n \\geq d\\), we have (see Exercise 4.1)\n\\[\n\\sum_{\\ell=0}^{d}\\binom{n}{\\ell}\\leq(e n/d)^{d}.\\tag{4.2}\n\\]\nWhen \\(n \\leq d\\), we have \\(\\sum_{\\ell=0}^{d} \\binom{n}{\\ell} \\leq 2^d\\). This implies the desired result.\nIn the following, we only need to prove the statement that \\(|\\mathcal{G}(\\mathcal{S}_n)|\\) is upper bounded by the number of subsets of \\(\\mathcal{S}_n\\) that are shattered by \\(\\mathcal{G}\\). This can be proved by induction on \\(n\\). When \\(n = 1\\), one can check that the claim holds trivially.\nNow assume that the claim holds for all empirical samples of size no more than \\( n - 1 \\). Consider \\( n \\) samples \\( \\{Z_1, \\ldots, Z_n\\} \\). We define\n\\[\n\\phi(w,\\mathcal{S}_{k})=[\\phi(w,Z_{1}),\\dots,\\phi(w,Z_{k})],\n\\]\n\\[\n\\mathcal{G}_{n-1}(\\mathcal{S}_{n})=\\left\\{\\left[\\phi(w,\\mathcal{S}_{n-1}),1\\right]:\\left[\\phi(w,\\mathcal{S}_{n-1}),0\\right],\\left[\\phi(w,\\mathcal{S}_{n-1}),1\\right]\\in\\mathcal{G}(\\mathcal{S}_{n})\\right\\}.\n\\]\nUsing the induction hypothesis, we know that \\(|\\mathcal{G}_{n - 1}(\\mathcal{S}_n)|\\) is bounded by the number of shattered subset \\(\\mathcal{S}\\subset \\mathcal{S}_{n - 1}\\); for each shattered \\(\\mathcal{S}\\subset \\mathcal{S}_{n - 1}\\), \\(\\mathcal{S}\\cup \\{Z_n\\}\\) is shattered by \\(\\mathcal{G}\\) because both \\([\\phi (w,\\mathcal{S}_{n - 1}),1]\\) and \\([\\phi (w,S_{n - 1}),0]\\) belong to \\(\\mathcal{G}(\\mathcal{S}_n)\\). Therefore \\(|\\mathcal{G}_{n - 1}(\\mathcal{S}_n)|\\) is no more than the number of shattered subsets of \\(\\mathcal{S}_n\\) that contains \\(Z_{n}\\).\nMoreover, since for \\(\\phi(w,\\cdot) \\in \\mathcal{G}(\\mathcal{S}_n) - \\mathcal{G}_{n-1}(\\mathcal{S}_n)\\), \\(\\phi(w,Z_n)\\) is uniquely determined by its values at \\(\\mathcal{S}_{n-1}\\) (if not, then both \\([\\phi(w,\\mathcal{S}_{n-1}),0]\\) and \\([\\phi(w,\\mathcal{S}_{n-1}),1]\\) can be achieved in \\(\\mathcal{G}(\\mathcal{S}_n) - \\mathcal{G}_{n-1}(\\mathcal{S}_n)\\), which is impossible because by definition, we should have put \\([\\phi(w,\\mathcal{S}_{n-1}),1]\\) in \\(\\mathcal{G}_{n-1}(\\mathcal{S}_n)\\)), it follows that \\(|\\mathcal{G}(\\mathcal{S}_n) - \\mathcal{G}_{n-1}(\\mathcal{S}_n)|\\) is no more than \\(|\\mathcal{G}(\\mathcal{S}_{n-1})|\\). By induction hypothesis, \\(|\\mathcal{G}(\\mathcal{S}_{n-1})|\\) is no more than the number of shattered subsets of \\(\\mathcal{S}_n\\) that does not contain \\(Z_n\\). By combining the above two facts, \\(|\\mathcal{G}(\\mathcal{S}_n)|\\) is no more than the number of shattered subsets of \\(\\mathcal{S}_n\\).", "context": [{"id": "ch4:definition:4_15", "name": "VC-dimension", "statement": "Let \\(\\mathcal{G} = \\{\\phi(w,z) : w \\in \\Omega\\}\\) be a \\(\\{0,1\\}\\) valued binary function class of \\(z \\in \\mathcal{Z}\\) indexed by \\(w \\in \\Omega\\). Given an arbitrary set of \\(n\\) samples \\(\\mathcal{S}_n = \\{Z_1, \\ldots, Z_n\\} \\in \\mathcal{Z}^n\\), we are interested in the number of functions (uniform \\(L_\\infty\\) cover of the function class at \\(\\epsilon = 0\\)) that \\(\\mathcal{G}(\\mathcal{S}_n) = \\{[\\phi(w,Z_1), \\ldots, \\phi(w,Z_n)] : w \\in \\Omega\\}\\) can achieve.\nWe say that \\(\\mathcal{G}\\) shatters \\(S_{n}\\) if the number of elements \\(|\\mathcal{G}(S_n)|\\) is \\(2^{n}\\). That is, we can always find \\(w\\in \\Omega\\) so that \\(\\phi (w,z)\\) matches any arbitrary possible choice of \\(\\{0,1\\} ^n\\) values at the \\(n\\) points. The maximum \\(n\\) such that \\(\\mathcal{G}\\) shatters at least one instance of \\(S_{n}\\in \\mathcal{Z}^{n}\\), denoted by \\(\\mathrm{vc}(\\mathcal{G})\\), is called the VC-dimension of \\(\\mathcal{G}\\).\nNote that the maximum number of functions in \\(\\mathcal{G}(\\mathcal{S}_n)\\) is \\(2^n\\). If \\(n > d\\), then for any \\(n\\) samples \\(\\mathcal{S}_n\\), \\(\\mathcal{G}(\\mathcal{S}_n)\\) contains fewer than \\(2^n\\) elements. Surprisingly, if a binary-valued function class \\(\\mathcal{G}\\) has VC dimension \\(d\\), then when \\(n > d\\), the size of set \\(\\mathcal{G}(\\mathcal{S}_n)\\) can grow only polynomially in \\(n\\). This gives an \\(O(d\\ln n)\\) upper bound on the uniform entropy of the function class \\(\\mathcal{G}\\) with a finite VC-dimension (see Vapnik and Chervonenkis, 1968, 1971; Sauer, 1972)."}, {"id": "ch4:corollary:4_13", "name": "corollary 4.13", "statement": "If \\(\\phi(w, z) \\in [0,1]\\). Let \\(\\mathcal{G} = \\{\\phi(w, z) : w \\in \\Omega\\}\\). With probability at least \\(1 - \\delta\\), the approximate ERM method (3.3) satisfies the (additive) oracle inequality:\n\\[\n\\begin{array}{l}\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(\\hat{w},Z)\\leq\\inf_{w\\in\\Omega}\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(w,Z)+\\epsilon^{\\prime}\\\\ +\\inf_{\\epsilon>0}\\left[2\\epsilon+\\sqrt{\\frac{8\\ln(4 N_{1}(\\epsilon,\\mathcal{G},n)/\\delta)}{n}}\\right].\\\\ \\end{array}\n\\]\nMoreover, we have the following (multiplicative) oracle inequality for all \\(\\gamma \\in (0,1)\\): with probability at least \\(1 - \\delta\\),\n\\[\n\\begin{array}{l}(1-\\gamma)^{2}\\mathbb{E}_{(X,Y)\\sim\\mathcal{D}}\\phi(\\hat{w},Z)\\leq\\inf_{w\\in\\Omega}(1+\\gamma)\\mathbb{E}_{(X,Y)\\sim\\mathcal{D}}\\phi(w,Z)+\\epsilon^{\\prime}\\\\ +\\inf_{\\epsilon>0}\\left[2\\epsilon+\\frac{(6-3\\gamma)\\ln(4 N_{1}(\\epsilon,\\mathcal{G},n)/\\delta)}{2\\gamma n}\\right].\\\\ \\end{array}\n\\]"}], "lean": "import Mathlib\n\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\nstructure Predictor (𝒳 : Type*) (𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] where\n f : 𝒳 → 𝒴'\n hf : Measurable f\n\nabbrev HypothesisClass (𝒳 : Type*) (𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] : Type _ :=\n Set (Predictor 𝒳 𝒴')\n\ndef Shatters {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) (S : Finset 𝒳) : Prop :=\n ∀ (b : ↥S → Bool), ∃ h ∈ H, ∀ (x : ↥S), h.f ↑x = b x\n\nnoncomputable def VCDim {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) : ℕ∞ :=\n ⨆ S, ⨆ (_ : Shatters H S), ↑S.card\n\ndef Restrictions {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) (S : Finset 𝒳) : Set (↥S → Bool) :=\n (fun h x => h.f ↑x) '' H\n\nnoncomputable def GrowthFunction {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) (n : ℕ) : ℕ :=\n sSup ((fun S => (Restrictions H S).ncard) '' {S | S.card = n})\n\ntheorem ch4_lemma_4_16\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n (d : ℕ) (hd : 0 < d) (hVC : VCDim H = (d : ℕ∞))\n (n : ℕ) (hn : 0 < n) :\n GrowthFunction H n ≤ ∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ ∧\n ((∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ : ℕ) : ℝ)\n ≤ max 2 (Real.exp 1 * n / d) ^ d := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\nstructure Predictor (𝒳 : Type*) (𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] where\n f : 𝒳 → 𝒴'\n hf : Measurable f\n\nabbrev HypothesisClass (𝒳 : Type*) (𝒴' : Type*) [MeasurableSpace 𝒳] [MeasurableSpace 𝒴'] : Type _ :=\n Set (Predictor 𝒳 𝒴')\n\ndef Shatters {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) (S : Finset 𝒳) : Prop :=\n ∀ (b : ↥S → Bool), ∃ h ∈ H, ∀ (x : ↥S), h.f ↑x = b x\n\nnoncomputable def VCDim {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) : ℕ∞ :=\n ⨆ S, ⨆ (_ : Shatters H S), ↑S.card\n\ndef Restrictions {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) (S : Finset 𝒳) : Set (↥S → Bool) :=\n (fun h x => h.f ↑x) '' H\n\nnoncomputable def GrowthFunction {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool) (n : ℕ) : ℕ :=\n sSup ((fun S => (Restrictions H S).ncard) '' {S | S.card = n})\n\nprivate lemma sum_choose_bound (d n : ℕ) (hd : 0 < d) (hn : 0 < n) :\n ((∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ : ℕ) : ℝ)\n ≤ max 2 (Real.exp 1 * n / d) ^ d := by\n have hcast : ((∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ : ℕ) : ℝ)\n = ∑ ℓ ∈ Finset.range (d + 1), ((n.choose ℓ : ℕ) : ℝ) := by push_cast; ring\n rw [hcast]\n rcases le_or_lt d n with hdn | hnd\n · -- main case d ≤ n\n have hn0 : (0:ℝ) < n := by exact_mod_cast hn\n have hd0 : (0:ℝ) < d := by exact_mod_cast hd\n set r : ℝ := (d : ℝ) / n with hr\n have hr0 : 0 < r := div_pos hd0 hn0\n have hr1 : r ≤ 1 := by\n rw [hr, div_le_one hn0]; exact_mod_cast hdn\n set A : ℝ := ∑ ℓ ∈ Finset.range (d + 1), ((n.choose ℓ : ℕ) : ℝ) with hA\n have h1 : A * r ^ d ≤ ∑ ℓ ∈ Finset.range (d + 1), ((n.choose ℓ : ℕ) : ℝ) * r ^ ℓ := by\n rw [hA, Finset.sum_mul]\n refine Finset.sum_le_sum ?_\n intro ℓ hℓ\n have hℓd : ℓ ≤ d := by\n have := Finset.mem_range.1 hℓ; omega\n have : r ^ d ≤ r ^ ℓ := pow_le_pow_of_le_one hr0.le hr1 hℓd\n exact mul_le_mul_of_nonneg_left this (by positivity)\n have h2 : ∑ ℓ ∈ Finset.range (d + 1), ((n.choose ℓ : ℕ) : ℝ) * r ^ ℓ\n ≤ ∑ ℓ ∈ Finset.range (n + 1), ((n.choose ℓ : ℕ) : ℝ) * r ^ ℓ := by\n refine Finset.sum_le_sum_of_subset_of_nonneg ?_ ?_\n · intro x hx\n simp only [Finset.mem_range] at hx ⊢; omega\n · intro i _ _; positivity\n have h3 : ∑ ℓ ∈ Finset.range (n + 1), ((n.choose ℓ : ℕ) : ℝ) * r ^ ℓ = (1 + r) ^ n := by\n have := add_pow (r : ℝ) 1 n\n simp only [one_pow, mul_one] at this\n rw [add_comm (1:ℝ) r, this]\n refine Finset.sum_congr rfl ?_\n intro i _\n ring\n have h4 : (1 + r) ^ n ≤ Real.exp 1 ^ d := by\n have hstep : (1 + r) ^ n ≤ (Real.exp r) ^ n := by\n refine pow_le_pow_left₀ (by positivity) ?_ n\n have := Real.add_one_le_exp r\n linarith\n have : (Real.exp r) ^ n = Real.exp 1 ^ d := by\n rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]\n congr 1\n rw [hr]\n field_simp\n linarith [hstep, this.le, this.ge]\n have h5 : A * r ^ d ≤ Real.exp 1 ^ d := by linarith\n have hrd : (0:ℝ) < r ^ d := by positivity\n have h6 : A ≤ (Real.exp 1 / r) ^ d := by\n rw [div_pow, le_div_iff₀ hrd]\n exact h5\n have hmax : max 2 (Real.exp 1 * n / d) = Real.exp 1 * n / d := by\n refine max_eq_right ?_\n have he : (2:ℝ) ≤ Real.exp 1 := by\n nlinarith [Real.add_one_le_exp (1:ℝ)]\n have hnd' : (1:ℝ) ≤ (n:ℝ) / d := by\n rw [le_div_iff₀ hd0]; simpa using (by exact_mod_cast hdn : (d:ℝ) ≤ n)\n have : Real.exp 1 * 1 ≤ Real.exp 1 * ((n:ℝ)/d) := by\n exact mul_le_mul_of_nonneg_left hnd' (Real.exp_pos 1).le\n calc (2:ℝ) ≤ Real.exp 1 := he\n _ = Real.exp 1 * 1 := by ring\n _ ≤ Real.exp 1 * ((n:ℝ)/d) := this\n _ = Real.exp 1 * n / d := by ring\n rw [hmax]\n have : Real.exp 1 / r = Real.exp 1 * n / d := by\n rw [hr]; field_simp\n rw [← this]\n exact h6\n · -- case n < d\n have hsum : ∑ ℓ ∈ Finset.range (d + 1), ((n.choose ℓ : ℕ) : ℝ)\n = ∑ ℓ ∈ Finset.range (n + 1), ((n.choose ℓ : ℕ) : ℝ) := by\n refine (Finset.sum_subset ?_ ?_).symm\n · intro x hx; simp only [Finset.mem_range] at hx ⊢; omega\n · intro x hx hx2\n simp only [Finset.mem_range] at hx hx2\n have : n < x := by omega\n rw [Nat.choose_eq_zero_of_lt this]\n simp\n rw [hsum]\n have : ∑ ℓ ∈ Finset.range (n + 1), ((n.choose ℓ : ℕ) : ℝ) = ((2:ℝ)) ^ n := by\n have := Nat.sum_range_choose n\n have h' : ((∑ ℓ ∈ Finset.range (n+1), n.choose ℓ : ℕ) : ℝ) = ((2^n : ℕ) : ℝ) := by\n exact_mod_cast congrArg (fun m : ℕ => (m : ℝ)) this\n push_cast at h'\n exact h'\n rw [this]\n have h2m : (2:ℝ) ≤ max 2 (Real.exp 1 * n / d) := le_max_left _ _\n calc (2:ℝ) ^ n ≤ (2:ℝ) ^ d := by\n apply pow_le_pow_right₀ (by norm_num); omega\n _ ≤ max 2 (Real.exp 1 * n / d) ^ d := by\n apply pow_le_pow_left₀ (by norm_num) h2m\n\nprivate lemma growth_le {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n (d : ℕ) (hVC : ∀ T : Finset 𝒳, Shatters H T → T.card ≤ d)\n (n : ℕ) : GrowthFunction H n ≤ ∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ := by\n classical\n apply csSup_le'\n rintro m ⟨S, hS, rfl⟩\n simp only [Set.mem_setOf_eq] at hS\n set α := {x // x ∈ S}\n have hfin : (Restrictions H S).Finite := Set.toFinite _\n set e : (α → Bool) → Finset α := fun f => Finset.univ.filter (fun x => f x = true) with he\n have he_inj : Function.Injective e := by\n intro f g hfg\n funext x\n have : x ∈ e f ↔ x ∈ e g := by rw [hfg]\n simpa [he] using this\n set 𝒜 : Finset (Finset α) := hfin.toFinset.image e with h𝒜\n have hcard : (Restrictions H S).ncard = 𝒜.card := by\n rw [h𝒜, Finset.card_image_of_injective _ he_inj,\n Set.ncard_eq_toFinset_card _ hfin]\n -- key : shattering transfer\n have key : ∀ T : Finset α, 𝒜.Shatters T → Shatters H (T.image (Subtype.val)) := by\n intro T hT b\n set g : α → Bool := fun x => if h : (x : 𝒳) ∈ T.image (Subtype.val) then b ⟨(x : 𝒳), h⟩\n else false with hg\n obtain ⟨u, hu, hTu⟩ := hT (Finset.filter_subset (fun x => g x = true) T)\n rw [h𝒜, Finset.mem_image] at hu\n obtain ⟨f, hf, hfe⟩ := hu\n rw [Set.Finite.mem_toFinset] at hf\n obtain ⟨h, hh, hfeq⟩ := hf\n refine ⟨h, hh, ?_⟩\n intro y\n obtain ⟨x, hxT, hxy⟩ := Finset.mem_image.1 y.2\n have hxu : (x ∈ u) ↔ (f x = true) := by\n rw [← hfe]; simp [he]\n have hmem : x ∈ T ∩ u ↔ x ∈ T.filter (fun z => g z = true) := by rw [hTu]\n simp only [Finset.mem_inter, Finset.mem_filter, hxT, true_and] at hmem\n have hfg : f x = true ↔ g x = true := by rw [← hxu]; exact hmem\n have hyx : y = ⟨(x : 𝒳), Finset.mem_image_of_mem _ hxT⟩ := by\n apply Subtype.ext; exact hxy.symm\n have hgx : g x = b y := by\n rw [hg]\n simp only\n rw [dif_pos (Finset.mem_image_of_mem (Subtype.val) hxT)]\n rw [hyx]\n have hhf : h.f (x : 𝒳) = f x := by\n rw [← hfeq]\n rw [← hxy, hhf]\n rcases hb : (f x) with _ | _\n · have : g x ≠ true := by\n intro hc; rw [hfg.2 hc] at hb; exact Bool.noConfusion hb\n have : g x = false := by\n cases hgv : g x\n · rfl\n · exact absurd hgv this\n rw [← hgx, this]\n · rw [← hgx, hfg.1 hb]\n have hvc : 𝒜.vcDim ≤ d := by\n apply Finset.sup_le\n intro T hT\n rw [Finset.mem_shatterer] at hT\n have := hVC _ (key T hT)\n rwa [Finset.card_image_of_injective _ (Subtype.val_injective)] at this\n have hcardα : Fintype.card α = n := by\n rw [← hS]\n exact Fintype.card_coe S\n calc (Restrictions H S).ncard = 𝒜.card := hcard\n _ ≤ 𝒜.shatterer.card := Finset.card_le_card_shatterer 𝒜\n _ ≤ ∑ k ∈ Finset.Iic 𝒜.vcDim, (Fintype.card α).choose k :=\n Finset.card_shatterer_le_sum_vcDim\n _ = ∑ k ∈ Finset.Iic 𝒜.vcDim, n.choose k := by rw [hcardα]\n _ ≤ ∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ := by\n apply Finset.sum_le_sum_of_subset\n intro x hx\n simp only [Finset.mem_Iic] at hx\n simp only [Finset.mem_range]\n omega\n\ntheorem ch4_lemma_4_16\n {𝒳 : Type*} [MeasurableSpace 𝒳] (H : HypothesisClass 𝒳 Bool)\n (d : ℕ) (hd : 0 < d) (hVC : VCDim H = (d : ℕ∞))\n (n : ℕ) (hn : 0 < n) :\n GrowthFunction H n ≤ ∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ ∧\n ((∑ ℓ ∈ Finset.range (d + 1), n.choose ℓ : ℕ) : ℝ)\n ≤ max 2 (Real.exp 1 * n / d) ^ d := by\n refine ⟨?_, sum_choose_bound d n hd hn⟩\n refine growth_le H d ?_ n\n intro T hT\n have h1 : ((T.card : ℕ) : ℕ∞) ≤ VCDim H := by\n rw [VCDim]\n exact le_iSup₂ (f := fun (S : Finset 𝒳) (_ : Shatters H S) => ((S.card : ℕ) : ℕ∞)) T hT\n rw [hVC] at h1\n exact_mod_cast h1\n\nend GraduateLevel\n"} +{"id": "ch4_lemma_4_8", "source": "Graduate-level", "targets": [{"label": "symmetrization_4_8", "decls": ["symmetrization_4_8"], "statement": "(Symmetrization) Consider a real valued function family \\(F = \\{f : Z \\rightarrow \\mathbb{R}\\}\\). Assume there exists a function \\(\\psi : F \\times Z^{n} \\rightarrow \\mathbb{R}\\) and \\(\\epsilon_{n} : (0,1) \\rightarrow \\mathbb{R}\\) so that with probability at least \\(1-\\delta\\):\n\\[\n\\forall f \\in F, \\qquad f(\\sigma, S_{n}) \\leq \\psi(f, S_{n}) + \\epsilon_{n}(\\delta),\n\\]\nwhere the randomness is over both \\(S_{n} \\sim D^{n}\\) and \\(\\sigma\\). If there exists \\(\\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime})\\) so that the following superadditive inequality holds for all \\((S_{n}, S_{n}^{\\prime})\\)\n\\[\n\\psi(f, S_{n}) + \\psi(f, S_{n}^{\\prime}) \\leq \\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime}),\n\\]\nthen with probability at least \\(1-\\delta\\) over independent random data \\((S_{n}, S_{n}^{\\prime}) \\sim D^{2n}\\):\n\\[\n\\forall f \\in F, \\qquad f(S_{n}^{\\prime}) \\leq f(S_{n}) + \\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime}) + 2\\epsilon_{n}(\\delta/2).\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Consider independent random samples \\((S_{n}, S_{n}^{\\prime}) \\sim D^{2n}\\). The distribution of \\(f(S_{n}) - f(S_{n}^{\\prime})\\) is the same as that of \\(f(\\sigma, S_{n}) - f(\\sigma, S_{n}^{\\prime})\\), and the latter contains additional randomness from Bernoulli random variables \\(\\sigma\\), drawn independently of \\((S_{n}, S_{n}^{\\prime})\\), as in Definition 4.7. It follows that\n\\[\n\\begin{array}{l}\n\\Pr\\Bigl(\\exists f \\in F,\\ f(S_{n}^{\\prime}) > f(S_{n}) + \\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime}) + 2\\epsilon_{n}(\\delta/2)\\Bigr) \\\\\n= \\Pr\\Bigl(\\exists f \\in F,\\ f(\\sigma, S_{n}^{\\prime}) > f(\\sigma, S_{n}) + \\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime}) + 2\\epsilon_{n}(\\delta/2)\\Bigr) \\\\\n\\overset{(a)}{\\leq} \\Pr\\Bigl(\\underbrace{\\exists f \\in F,\\ f(\\sigma, S_{n}^{\\prime}) > f(\\sigma, S_{n}) + (\\psi(f, S_{n}) + \\psi(f, S_{n}^{\\prime})) + 2\\epsilon_{n}(\\delta/2)}_{E_{0}}\\Bigr)\n\\end{array}\n\\]\n\\[\n\\begin{array}{l}\n\\overset{(b)}{\\leq} \\Pr\\Bigl(\\underbrace{\\exists f \\in F,\\ f(\\sigma, S_{n}^{\\prime}) > \\psi(f, S_{n}^{\\prime}) + \\epsilon_{n}(\\delta/2)}_{E_{1}}\\Bigr) \\\\\n\\quad + \\Pr\\Bigl(\\underbrace{\\exists f \\in F,\\ -f(\\sigma, S_{n}) > \\psi(f, S_{n}) + \\epsilon_{n}(\\delta/2)}_{E_{2}}\\Bigr)\n\\end{array}\n\\]\n\\[\n= 2\\Pr\\Bigl(\\exists f \\in F,\\ f(\\sigma, S_{n}) > \\psi(f, S_{n}) + \\epsilon_{n}(\\delta/2)\\Bigr) \\leq 2(\\delta/2).\n\\]\nIn the above derivation, the first equation used the fact that \\(f(S_{n}) - f(S_{n}^{\\prime})\\) and \\(f(\\sigma, S_{n}) - f(\\sigma, S_{n}^{\\prime})\\) have the same distributions. (a) used the assumption \\(\\psi(S_{n}) + \\psi(S_{n}^{\\prime}) \\leq \\widetilde{\\psi}(S_{n} \\cup S_{n}^{\\prime})\\). (b) used the union bound, and the fact that if event \\(E_{0}\\) holds, then either event \\(E_{1}\\) holds or event \\(E_{2}\\) holds. The next equation used the symmetry of \\(-f(\\sigma, S_{n})\\) and \\(f(\\sigma, S_{n})\\), and the last inequality used the assumption of the lemma. The result implies the desired bound.", "context": [{"id": "ch2:corollary:2_27", "name": "corollary 2.27", "statement": "Let \\(\\sigma_{i} = \\{\\pm 1\\}\\) be independent Bernoulli random variables ( each takes value \\(\\pm 1\\) with equal probability). Let \\(a_{i}\\) be fixed numbers \\((i=1,\\dots,n)\\) Then for all \\(\\epsilon >0\\) ..\n\\[\n\\Pr\\left(n^{-1}\\sum_{i=1}^{n}\\sigma_{i}a_{i}\\geq\\epsilon\\right)\\leq\\exp\\left[-\\frac{n\\epsilon^{2}}{2 n^{-1}\\sum_{i=1}^{n}a_{i}^{2}}\\right].\n\\]"}, {"id": "ch4:definition:4_7", "name": "definition 4.7", "statement": "Consider a real-valued function family \\(\\mathcal{F}:\\mathcal{Z}\\to \\mathbb{R}\\). Consider \\(n\\) iid Bernoulli random variables \\(\\sigma_{i}\\in \\{\\pm 1\\}\\), where \\(\\operatorname*{Pr}(\\sigma_i=1)=\\operatorname*{Pr}(\\sigma_i= -1)=0.5\\). The symmetrized empirical process is\n\\[\nf(\\sigma,\\mathcal{S}_{n})=\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}f(Z_{i})\\qquad f\\in\\mathcal{F},\n\\]\nwhere the randomness is with respect to both \\(S_{n} = \\{Z_{i}\\}\\) and \\(\\sigma = \\{\\sigma_{i}\\}\\).\nNote that in order to bound the symmetrized empirical process, we only need a covering number result on \\( S_{n} \\). Therefore the symmetrization analysis allows us to work with empirical covering numbers. Next we will show that a bound on the symmetrized empirical process can be used to obtain uniform convergence of the empirical process \\( \\{f(S_{n}): f \\in \\mathcal{F}\\} \\) to the corresponding result on the validation data. Since one can relate the validation loss of a learning algorithm to its generalization error on the test data, we can use this result to obtain generalization bounds.\nThe following lemma shows that if we can obtain an upper bound on the symmetrized empirical process \\(\\{f(\\sigma, S_n) : f \\in \\mathcal{F}\\}\\), and the upper bound satisfies a superadditive property, then we can obtain the uniform convergence of the empirical process \\(\\{f(S_n) : f \\in \\mathcal{F}\\}\\) on the training data \\(S_n\\) to the corresponding result on the validation data \\(S_n'\\)."}, {"id": "ch3:proposition:3_5", "name": "Union Bound", "statement": "(Union Bound) Consider \\(m\\) events \\(E_1, \\ldots, E_m\\). The following probability inequality holds:\n\\[\n\\Pr (E_1 \\cup \\cdots \\cup E_m) \\leq \\sum_{j=1}^{m} \\Pr(E_j).\n\\]\n\nThe union bound has an alternative expression, which is often used in the learning theory analysis. If each \\(E_j\\) occurs with probability at least \\(1-\\delta_j\\) for \\(j=1, \\ldots, m\\), then with probability at least \\(1-\\sum_{j=1}^{m} \\delta_j\\), all of events \\(\\{E_j\\}\\) occur simultaneously for \\(j=1, \\ldots, m\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\ndef Signs (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance instFintypeSigns {n} : Fintype (Signs n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\ninstance instMSSigns (n : ℕ) : MeasurableSpace (Signs n) := ⊤\n\ninstance instNESigns (n : ℕ) : Nonempty (Signs n) :=\n ⟨fun _ => ⟨1, by decide⟩⟩\n\nnoncomputable def empMean {Z : Type*} {ι : Type*} {n : ℕ}\n (f : ι → Z → ℝ) (i : ι) (S : Fin n → Z) : ℝ :=\n (∑ k : Fin n, f i (S k)) / n\n\nnoncomputable def empSym {Z : Type*} {ι : Type*} {n : ℕ}\n (f : ι → Z → ℝ) (i : ι) (σ : Signs n) (S : Fin n → Z) : ℝ :=\n (∑ k : Fin n, ((σ k : ℤ) : ℝ) * f i (S k)) / n\n\nnoncomputable def μσ (n : ℕ) : Measure (Signs n) :=\n (PMF.uniformOfFintype (Signs n)).toMeasure\n\ninstance (n : ℕ) : IsProbabilityMeasure (μσ n) := by\n unfold μσ; infer_instance\n\ntheorem symmetrization_4_8\n {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {ι : Type*} {n : ℕ} (hn : 0 < n)\n (f : ι → Z → ℝ)\n (ψ : ι → (Fin n → Z) → ℝ)\n (ψtilde : ι → Multiset Z → ℝ)\n (εn : ℝ → ℝ)\n (δ : ℝ) (hδ : 0 < δ ∧ δ < 1)\n\n (hmeas_hyp : ∀ δ' : ℝ,\n MeasurableSet\n {p : (Fin n → Z) × Signs n |\n ∀ i, empSym f i p.2 p.1 ≤ ψ i p.1 + εn δ'})\n\n (hmeas_concl :\n MeasurableSet\n {p : (Fin n → Z) × (Fin n → Z) |\n ∀ i, empMean f i p.2 ≤ empMean f i p.1\n + ψtilde i (((List.ofFn p.1 : List Z) : Multiset Z) + ((List.ofFn p.2 : List Z) : Multiset Z)) + 2 * εn (δ / 2)})\n\n (h_hyp : ∀ δ' : ℝ, 0 < δ' → δ' < 1 →\n ((Measure.pi fun _ => D).prod (μσ n))\n {p : (Fin n → Z) × Signs n |\n ∀ i, empSym f i p.2 p.1 ≤ ψ i p.1 + εn δ'}\n ≥ ENNReal.ofReal (1 - δ'))\n\n (h_super : ∀ i (S S' : Fin n → Z),\n ψ i S + ψ i S' ≤ ψtilde i (((List.ofFn S : List Z) : Multiset Z) + ((List.ofFn S' : List Z) : Multiset Z))) :\n ((Measure.pi fun _ => D).prod (Measure.pi fun _ => D))\n {p : (Fin n → Z) × (Fin n → Z) |\n ∀ i, empMean f i p.2 ≤ empMean f i p.1\n + ψtilde i (((List.ofFn p.1 : List Z) : Multiset Z) + ((List.ofFn p.2 : List Z) : Multiset Z)) + 2 * εn (δ / 2)}\n ≥ ENNReal.ofReal (1 - δ) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\ndef Signs (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance instFintypeSigns {n} : Fintype (Signs n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\ninstance instMSSigns (n : ℕ) : MeasurableSpace (Signs n) := ⊤\n\ninstance instNESigns (n : ℕ) : Nonempty (Signs n) :=\n ⟨fun _ => ⟨1, by decide��⟩\n\nnoncomputable def empMean {Z : Type*} {ι : Type*} {n : ℕ}\n (f : ι → Z → ℝ) (i : ι) (S : Fin n → Z) : ℝ :=\n (∑ k : Fin n, f i (S k)) / n\n\nnoncomputable def empSym {Z : Type*} {ι : Type*} {n : ℕ}\n (f : ι → Z → ℝ) (i : ι) (σ : Signs n) (S : Fin n → Z) : ℝ :=\n (∑ k : Fin n, ((σ k : ℤ) : ℝ) * f i (S k)) / n\n\nnoncomputable def μσ (n : ℕ) : Measure (Signs n) :=\n (PMF.uniformOfFintype (Signs n)).toMeasure\n\ninstance (n : ℕ) : IsProbabilityMeasure (μσ n) := by\n unfold μσ; infer_instance\n\ndef swapL {Z : Type*} {n : ℕ} (σ : Signs n) (S S' : Fin n → Z) : Fin n → Z :=\n fun k => if (σ k : ℤ) = 1 then S k else S' k\n\ndef negS {n : ℕ} (σ : Signs n) : Signs n :=\n fun k => ⟨-((σ k : ℤ)), by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h ⊢\n rcases h with h | h <;> simp [h]⟩\n\nlemma coe_negS {n : ℕ} (σ : Signs n) (k : Fin n) :\n ((negS σ k : ℤ)) = -((σ k : ℤ)) := rfl\n\nlemma sign_eq {n : ℕ} (σ : Signs n) (k : Fin n) :\n (σ k : ℤ) = 1 ∨ (σ k : ℤ) = -1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n tauto\n\nlemma ms_swap {Z : Type*} {n : ℕ} (c : Fin n → Prop) [DecidablePred c]\n (S S' : Fin n → Z) (L : Multiset (Fin n)) :\n (L.map fun k => if c k then S k else S' k) + (L.map fun k => if c k then S' k else S k)\n = L.map S + L.map S' := by\n induction L using Multiset.induction with\n | empty => simp\n | cons a L ih =>\n simp only [Multiset.map_cons, Multiset.cons_add, Multiset.add_cons]\n by_cases h : c a\n · simp only [h, if_true, ih]\n · simp only [h, if_false, ih]\n exact Multiset.cons_swap _ _ _\n\nlemma ofFn_ms {Z : Type*} {n : ℕ} (g : Fin n → Z) :\n ((List.ofFn g : List Z) : Multiset Z)\n = Multiset.map g ((List.finRange n : List (Fin n)) : Multiset (Fin n)) := by\n rw [List.ofFn_eq_map]\n simp\n\nlemma swap_mp {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {n : ℕ} (σ : Signs n) :\n MeasurePreserving (fun p : (Fin n → Z) × (Fin n → Z) => (swapL σ p.1 p.2, swapL σ p.2 p.1))\n ((Measure.pi fun _ : Fin n => D).prod (Measure.pi fun _ : Fin n => D))\n ((Measure.pi fun _ : Fin n => D).prod (Measure.pi fun _ : Fin n => D)) := by\n classical\n have h1 : MeasurePreserving (MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n))\n (Measure.pi fun _ : Fin n => D.prod D)\n ((Measure.pi fun _ : Fin n => D).prod (Measure.pi fun _ : Fin n => D)) :=\n measurePreserving_arrowProdEquivProdArrow Z Z (Fin n) (fun _ => D) (fun _ => D)\n have h2 : MeasurePreserving\n (fun (x : Fin n → Z × Z) (k : Fin n) =>\n (fun (k : Fin n) (z : Z × Z) => if (σ k : ℤ) = 1 then z else z.swap) k (x k))\n (Measure.pi fun _ : Fin n => D.prod D) (Measure.pi fun _ : Fin n => D.prod D) := by\n refine measurePreserving_pi (fun _ : Fin n => D.prod D) (fun _ : Fin n => D.prod D)\n (f := fun (k : Fin n) (z : Z × Z) => if (σ k : ℤ) = 1 then z else z.swap) (fun k => ?_)\n by_cases h : (σ k : ℤ) = 1\n · simp only [h, if_true]\n exact MeasurePreserving.id _\n · simp only [h, if_false]\n exact Measure.measurePreserving_swap\n have h3 := h1.comp (h2.comp (MeasurePreserving.symm\n (MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n)) h1))\n have heq : (fun p : (Fin n → Z) × (Fin n → Z) => (swapL σ p.1 p.2, swapL σ p.2 p.1))\n = (⇑(MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n))) ∘\n ((fun (x : Fin n → Z × Z) (k : Fin n) =>\n (fun (k : Fin n) (z : Z × Z) => if (σ k : ℤ) = 1 then z else z.swap) k (x k)) ∘\n ⇑(MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n)).symm) := by\n funext p\n have h1' : ∀ q : Fin n → Z × Z,\n (MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n)) q\n = (fun c => (q c).1, fun c => (q c).2) := fun q => rfl\n have h2' : ∀ q : (Fin n → Z) × (Fin n → Z),\n (MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n)).symm q\n = fun c => (q.1 c, q.2 c) := fun q => rfl\n simp only [Function.comp_apply, h1', h2']\n ext k\n · simp only [swapL]\n by_cases h : (σ k : ℤ) = 1 <;> simp [h]\n · simp only [swapL]\n by_cases h : (σ k : ℤ) = 1 <;> simp [h]\n rw [heq]\n exact h3\n\nlemma negS_mp (n : ℕ) : MeasurePreserving (negS (n := n)) (μσ n) (μσ n) := by\n classical\n haveI : MeasurableSingletonClass (Signs n) := ⟨fun _ => trivial⟩\n have hall : ∀ t : Set (Signs n), MeasurableSet t := fun _ => trivial\n have hmeasneg : Measurable (negS (n := n)) := fun s _ => trivial\n refine ⟨hmeasneg, ?_⟩\n ext s _\n have hinv : Function.Involutive (negS (n := n)) := by\n intro σ\n funext k\n apply Subtype.ext\n show -(-((σ k : ℤ))) = _\n ring\n rw [Measure.map_apply hmeasneg (hall s)]\n unfold μσ\n rw [PMF.toMeasure_apply_fintype, PMF.toMeasure_apply_fintype]\n refine Fintype.sum_equiv hinv.toPerm _ _ (fun x => ?_)\n simp only [Set.indicator, PMF.uniformOfFintype_apply, Set.mem_preimage]\n rfl\n\nlemma mean_swap {Z : Type*} {ι : Type*} {n : ℕ} (f : ι → Z → ℝ) (i : ι) (σ : Signs n)\n (S S' : Fin n → Z) :\n empMean f i (swapL σ S' S) - empMean f i (swapL σ S S')\n = empSym f i σ S' - empSym f i σ S := by\n have h : ∀ k : Fin n, f i (swapL σ S' S k) - f i (swapL σ S S' k)\n = ((σ k : ℤ) : ℝ) * f i (S' k) - ((σ k : ℤ) : ℝ) * f i (S k) := by\n intro k\n rcases sign_eq σ k with h1 | h1 <;> simp [swapL, h1] <;> ring\n simp only [empMean, empSym]\n rw [div_sub_div_same, div_sub_div_same, ← Finset.sum_sub_distrib, ← Finset.sum_sub_distrib]\n exact congrArg (fun t : ℝ => t / (n : ℝ)) (Finset.sum_congr rfl (fun k _ => h k))\n\nlemma empSym_negS {Z : Type*} {ι : Type*} {n : ℕ} (f : ι → Z → ℝ) (i : ι) (σ : Signs n)\n (S : Fin n → Z) :\n empSym f i (negS σ) S = - empSym f i σ S := by\n simp only [empSym, coe_negS, Int.cast_neg, neg_mul, Finset.sum_neg_distrib, neg_div]\n\nlemma ms_swap_ofFn {Z : Type*} {n : ℕ} (σ : Signs n) (S S' : Fin n → Z) :\n ((List.ofFn (swapL σ S S') : List Z) : Multiset Z)\n + ((List.ofFn (swapL σ S' S) : List Z) : Multiset Z)\n = ((List.ofFn S : List Z) : Multiset Z) + ((List.ofFn S' : List Z) : Multiset Z) := by\n simp only [ofFn_ms, swapL]\n exact ms_swap (fun k => (σ k : ℤ) = 1) S S' _\n\nlemma main_helper {Z : Type*} [MeasurableSpace Z] {ι : Type*} {n : ℕ}\n (PP : Measure (Fin n → Z)) [IsProbabilityMeasure PP]\n (f : ι → Z → ℝ) (ψ : ι → (Fin n → Z) → ℝ) (ψtilde : ι → Multiset Z → ℝ)\n (c : ℝ) (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hswap : ∀ σ : Signs n, MeasurePreserving\n (fun p : (Fin n → Z) × (Fin n → Z) => (swapL σ p.1 p.2, swapL σ p.2 p.1))\n (PP.prod PP) (PP.prod PP))\n (A : Set ((Fin n → Z) × Signs n)) (B : Set ((Fin n → Z) × (Fin n → Z)))\n (hAdef : A = {p | ∀ i, empSym f i p.2 p.1 ≤ ψ i p.1 + c})\n (hBdef : B = {p | ∀ i, empMean f i p.2 ≤ empMean f i p.1\n + ψtilde i (((List.ofFn p.1 : List Z) : Multiset Z)\n + ((List.ofFn p.2 : List Z) : Multiset Z)) + 2 * c})\n (hA_meas : MeasurableSet A) (hB_meas : MeasurableSet B)\n (hA_prob : ENNReal.ofReal (1 - δ / 2) ≤ (PP.prod (μσ n)) A)\n (h_super : ∀ i (S S' : Fin n → Z),\n ψ i S + ψ i S' ≤ ψtilde i (((List.ofFn S : List Z) : Multiset Z)\n + ((List.ofFn S' : List Z) : Multiset Z))) :\n ENNReal.ofReal (1 - δ) ≤ (PP.prod PP) B := by\n classical\n have hnegmeas : Measurable (negS (n := n)) := fun s _ => trivial\n -- pointwise inclusion\n have hsub : ∀ (σ : Signs n) (p : (Fin n → Z) × (Fin n → Z)),\n ((p.2, σ) ∈ A) → ((p.1, negS σ) ∈ A) →\n (swapL σ p.1 p.2, swapL σ p.2 p.1) ∈ B := by\n intro σ p h1 h2\n rw [hAdef, Set.mem_setOf_eq] at h1 h2\n rw [hBdef, Set.mem_setOf_eq]\n intro i\n have hm := ms_swap_ofFn σ p.1 p.2\n have ha := mean_swap f i σ p.1 p.2\n have e1 := h1 i\n have e2 := h2 i\n rw [empSym_negS] at e2\n have hs := h_super i p.1 p.2\n rw [hm]\n linarith\n -- for each σ, the good set has measure at most that of B\n have hkey : ∀ σ : Signs n,\n (PP.prod PP) {p : (Fin n → Z) × (Fin n → Z) | (p.2, σ) ∈ A ∧ (p.1, negS σ) ∈ A}\n ≤ (PP.prod PP) B := by\n intro σ\n have hincl : {p : (Fin n → Z) × (Fin n → Z) | (p.2, σ) ∈ A ∧ (p.1, negS σ) ∈ A}\n ⊆ (fun p : (Fin n → Z) × (Fin n → Z) => (swapL σ p.1 p.2, swapL σ p.2 p.1)) ⁻¹' B := by\n rintro p ⟨ha, hb⟩\n exact hsub σ p ha hb\n calc (PP.prod PP) {p : (Fin n → Z) × (Fin n → Z) | (p.2, σ) ∈ A ∧ (p.1, negS σ) ∈ A}\n ≤ (PP.prod PP)\n ((fun p : (Fin n → Z) × (Fin n → Z) => (swapL σ p.1 p.2, swapL σ p.2 p.1)) ⁻¹' B) :=\n measure_mono hincl\n _ = (PP.prod PP) B := (hswap σ).measure_preimage hB_meas.nullMeasurableSet\n -- the joint space\n have hm1meas : Measurable\n (fun q : ((Fin n → Z) × (Fin n → Z)) × Signs n => (q.1.2, q.2)) :=\n (measurable_snd.comp measurable_fst).prodMk measurable_snd\n have hm2meas : Measurable\n (fun q : ((Fin n → Z) × (Fin n → Z)) × Signs n => (q.1.1, negS q.2)) :=\n (measurable_fst.comp measurable_fst).prodMk (hnegmeas.comp measurable_snd)\n have hGmeas : MeasurableSet\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∈ A ∧ (q.1.1, negS q.2) ∈ A} :=\n (hm1meas hA_meas).inter (hm2meas hA_meas)\n have hE1meas : MeasurableSet\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∉ A} := hm1meas hA_meas.compl\n have hE2meas : MeasurableSet\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.1, negS q.2) ∉ A} := hm2meas hA_meas.compl\n have hcompl : ∀ (μ : Measure ((Fin n → Z) × Signs n)) [IsProbabilityMeasure μ],\n ENNReal.ofReal (1 - δ / 2) ≤ μ A → μ Aᶜ ≤ ENNReal.ofReal (δ / 2) := by\n intro μ _ h\n rw [prob_compl_eq_one_sub hA_meas]\n refine tsub_le_iff_right.mpr ?_\n calc (1 : ℝ≥0∞) = ENNReal.ofReal (δ / 2) + ENNReal.ofReal (1 - δ / 2) := by\n rw [← ENNReal.ofReal_add (by linarith) (by linarith)]\n norm_num\n _ ≤ ENNReal.ofReal (δ / 2) + μ A := by gcongr\n have hE1 : ((PP.prod PP).prod (μσ n))\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∉ A} ≤ ENNReal.ofReal (δ / 2) := by\n have hmp : MeasurePreserving\n (fun q : ((Fin n → Z) × (Fin n → Z)) × Signs n => (q.1.2, q.2))\n ((PP.prod PP).prod (μσ n)) (PP.prod (μσ n)) :=\n MeasurePreserving.prod (MeasureTheory.measurePreserving_snd) (MeasurePreserving.id _)\n have := hmp.measure_preimage (hA_meas.compl.nullMeasurableSet)\n calc ((PP.prod PP).prod (μσ n))\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∉ A} = (PP.prod (μσ n)) Aᶜ :=\n this\n _ ≤ ENNReal.ofReal (δ / 2) := hcompl _ hA_prob\n have hE2 : ((PP.prod PP).prod (μσ n))\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.1, negS q.2) ∉ A}\n ≤ ENNReal.ofReal (δ / 2) := by\n have hmp : MeasurePreserving\n (fun q : ((Fin n → Z) × (Fin n → Z)) × Signs n => (q.1.1, negS q.2))\n ((PP.prod PP).prod (μσ n)) (PP.prod (μσ n)) :=\n MeasurePreserving.prod (MeasureTheory.measurePreserving_fst) (negS_mp n)\n have := hmp.measure_preimage (hA_meas.compl.nullMeasurableSet)\n calc ((PP.prod PP).prod (μσ n))\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.1, negS q.2) ∉ A}\n = (PP.prod (μσ n)) Aᶜ := this\n _ ≤ ENNReal.ofReal (δ / 2) := hcompl _ hA_prob\n have hjoint : ENNReal.ofReal (1 - δ) ≤ ((PP.prod PP).prod (μσ n))\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∈ A ∧ (q.1.1, negS q.2) ∈ A} := by\n have hGc : {q : ((Fin n → Z) × (Fin n → Z)) × Signs n |\n (q.1.2, q.2) ∈ A ∧ (q.1.1, negS q.2) ∈ A}\n = ({q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∉ A}\n ∪ {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.1, negS q.2) ∉ A})ᶜ := by\n ext q\n simp only [Set.mem_setOf_eq, Set.mem_compl_iff, Set.mem_union, not_or, not_not]\n have hunion : ((PP.prod PP).prod (μσ n))\n ({q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∉ A}\n ∪ {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.1, negS q.2) ∉ A})\n ≤ ENNReal.ofReal δ := by\n refine (measure_union_le _ _).trans ?_\n have hsum : ENNReal.ofReal (δ / 2) + ENNReal.ofReal (δ / 2) = ENNReal.ofReal δ := by\n rw [← ENNReal.ofReal_add (by linarith) (by linarith)]\n norm_num\n rw [← hsum]\n exact add_le_add hE1 hE2\n rw [hGc, prob_compl_eq_one_sub (hE1meas.union hE2meas)]\n calc ENNReal.ofReal (1 - δ) = 1 - ENNReal.ofReal δ := by\n rw [ENNReal.ofReal_sub _ hδ0.le, ENNReal.ofReal_one]\n _ ≤ _ := tsub_le_tsub_left hunion 1\n have hfin : ((PP.prod PP).prod (μσ n))\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n | (q.1.2, q.2) ∈ A ∧ (q.1.1, negS q.2) ∈ A}\n ≤ (PP.prod PP) B := by\n rw [Measure.prod_apply_symm hGmeas]\n calc ∫⁻ σ : Signs n, (PP.prod PP) ((fun p => (p, σ)) ⁻¹'\n {q : ((Fin n → Z) × (Fin n → Z)) × Signs n |\n (q.1.2, q.2) ∈ A ∧ (q.1.1, negS q.2) ∈ A}) ∂(μσ n)\n ≤ ∫⁻ _ : Signs n, (PP.prod PP) B ∂(μσ n) := lintegral_mono (fun σ => hkey σ)\n _ = (PP.prod PP) B := by simp\n exact hjoint.trans hfin\n\ntheorem symmetrization_4_8\n {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {ι : Type*} {n : ℕ} (hn : 0 < n)\n (f : ι → Z → ℝ)\n (ψ : ι → (Fin n → Z) → ℝ)\n (ψtilde : ι → Multiset Z → ℝ)\n (εn : ℝ → ℝ)\n (δ : ℝ) (hδ : 0 < δ ∧ δ < 1)\n\n (hmeas_hyp : ∀ δ' : ℝ,\n MeasurableSet\n {p : (Fin n → Z) × Signs n |\n ∀ i, empSym f i p.2 p.1 ≤ ψ i p.1 + εn δ'})\n\n (hmeas_concl :\n MeasurableSet\n {p : (Fin n → Z) × (Fin n → Z) |\n ∀ i, empMean f i p.2 ≤ empMean f i p.1\n + ψtilde i (((List.ofFn p.1 : List Z) : Multiset Z) + ((List.ofFn p.2 : List Z) : Multiset Z)) + 2 * εn (δ / 2)})\n\n (h_hyp : ∀ δ' : ℝ, 0 < δ' → δ' < 1 →\n ((Measure.pi fun _ => D).prod (μσ n))\n {p : (Fin n → Z) × Signs n |\n ∀ i, empSym f i p.2 p.1 ≤ ψ i p.1 + εn δ'}\n ≥ ENNReal.ofReal (1 - δ'))\n\n (h_super : ∀ i (S S' : Fin n → Z),\n ψ i S + ψ i S' ≤ ψtilde i (((List.ofFn S : List Z) : Multiset Z) + ((List.ofFn S' : List Z) : Multiset Z))) :\n ((Measure.pi fun _ => D).prod (Measure.pi fun _ => D))\n {p : (Fin n → Z) × (Fin n → Z) |\n ∀ i, empMean f i p.2 ≤ empMean f i p.1\n + ψtilde i (((List.ofFn p.1 : List Z) : Multiset Z) + ((List.ofFn p.2 : List Z) : Multiset Z)) + 2 * εn (δ / 2)}\n ≥ ENNReal.ofReal (1 - δ) := by\n obtain ⟨hδ0, hδ1⟩ := hδ\n show ENNReal.ofReal (1 - δ) ≤ _\n refine main_helper (Measure.pi fun _ : Fin n => D) f ψ ψtilde (εn (δ / 2)) δ hδ0 hδ1\n (fun σ => swap_mp D σ) _ _ rfl rfl (hmeas_hyp (δ / 2)) hmeas_concl ?_ h_super\n exact h_hyp (δ / 2) (by linarith) (by linarith)\n\nend GraduateLevel\n"} +{"id": "ch6_theorem_6_14", "source": "Graduate-level", "targets": [{"label": "ch6_theorem_6_14", "decls": ["ch6_theorem_6_14"], "statement": "Consider offset function of (6.3). We have\n\\[\n\\epsilon_{n}^{h}(\\mathcal{G},\\mathcal{D})\\leq 2 R_{n}^{h}(\\mathcal{G},\\mathcal{D}).\n\\]\nConsequently, the approximate regularized ERM method of (6.1) satisfies\n\\[\n\\mathbb{E}_{\\mathcal{S}_{n}}\\phi(\\hat{w},\\mathcal{D})\\leq\\inf_{w\\in\\Omega}[\\phi(w,\\mathcal{D})+\\mathbb{E}_{\\mathcal{S}_{n}}h(w,\\mathcal{S}_{n})]+\\epsilon^{\\prime}+2 R_{n}^{h}(\\mathcal{G},\\mathcal{D}).\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Let \\(\\mathcal{S}_n' = \\{Z_1', \\ldots, Z_n'\\} \\sim \\mathcal{D}^n\\) be \\(n\\) iid samples from \\(\\mathcal{D}\\) that are independent of \\(\\mathcal{S}_n\\). We have\n\\[\n\\epsilon_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}\\sup_{w\\in\\Omega}[\\phi(w,\\mathcal{D})-\\phi(w,\\mathcal{S}_{n})-h(w,\\mathcal{S}_{n})]\n\\]\n\\[\n=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}\\sup_{w\\in\\Omega}\\left[\\mathbb{E}_{\\mathcal{S}_{n}^{\\prime}\\sim\\mathcal{D}^{n}}\\phi(w,\\mathcal{S}_{n}^{\\prime})-\\phi(w,\\mathcal{S}_{n})-h(w,\\mathcal{S}_{n})\\right]\n\\]\n\\[\n\\leq\\mathbb{E}_{\\left(\\mathcal{S}_{n},\\mathcal{S}_{n}^{\\prime}\\right)\\sim\\mathcal{D}^{2 n}}\\sup_{w\\in\\Omega}\\left[\\phi(w,\\mathcal{S}_{n}^{\\prime})-\\phi(w,\\mathcal{S}_{n})-h(w,\\mathcal{S}_{n})\\right]\n\\]\n\\[\n\\begin{array}{l}=\\mathbb{E}_{\\left(\\mathcal{S}_{n},\\mathcal{S}_{n}^{\\prime}\\right)\\sim\\mathcal{D}^{2n}}\\sup_{w\\in\\Omega}\\left[\\left[\\phi(w,\\mathcal{S}_{n}^{\\prime})+0. 5h_{1}(w,\\mathcal{S}_{n}^{\\prime})\\right]-0. 5h(w,\\mathcal{S}_{n}^{\\prime})\\right.\\\\ -\\left[\\phi(w,\\mathcal{S}_{n})+0. 5h_{1}(w,\\mathcal{S}_{n})\\right]-0. 5h(w,\\mathcal{S}_{n})]\\\\ \\end{array}\n\\]\n\\[\n\\begin{array}{l}\\stackrel{(a)}{=}\\mathbb{E}_{\\left(\\mathcal{S}_{n},\\mathcal{S}_{n}^{\\prime}\\right)\\sim\\mathcal{D}^{2n}}\\mathbb{E}_{\\sigma}\\sup_{w\\in\\Omega}\\frac{1}{n}\\sum_{i=1}^{n}\\left[\\sigma_{i}\\left(\\phi\\left(w,Z_{i}^{\\prime}\\right)+0. 5h_{1}\\left(w,Z_{i}^{\\prime}\\right)\\right)-0. 5h(w,\\mathcal{S}_{n}^{\\prime})\\right.\\\\ \\left.-\\sigma_{i}\\left(\\phi\\left(w,Z_{i}\\right)+0. 5h_{1}\\left(w,Z_{i}\\right)\\right)-0. 5h\\left(w,\\mathcal{S}_{n}\\right)\\right]\\\\ \\end{array}\n\\]\n\\[\n\\begin{array}{l}\\leq\\mathbb{E}_{\\left(\\mathcal{S}_{n},\\mathcal{S}_{n}^{\\prime}\\right)\\sim\\mathcal{D}^{2n}}\\mathbb{E}_{\\sigma}\\sup_{w\\in\\Omega}\\frac{1}{n}\\sum_{i=1}^{n}\\left[\\sigma_{i}\\left(\\phi\\left(w,Z_{i}^{\\prime}\\right)+0. 5h_{1}\\left(w,Z_{i}^{\\prime}\\right)\\right)-0. 5h\\left(w,\\mathcal{S}_{n}^{\\prime}\\right)\\right]\\\\ +\\mathbb{E}_{(\\mathcal{S}_{n},\\mathcal{S}_{n}^{\\prime})\\sim\\mathcal{D}^{2n}}\\mathbb{E}_{\\sigma}\\sup_{w\\in\\Omega}\\frac{1}{n}\\sum_{i=1}^{n}[-\\sigma_{i}(\\phi(w,Z_{i})+0. 5h_{1}(w,Z_{i})-0. 5h(w,\\mathcal{S}_{n})]\\\\ \\end{array}\n\\]\n\\[\n=\\mathbb{E}_{(\\mathcal{S}_{n},\\mathcal{S}_{n}^{\\prime})\\sim\\mathcal{D}^{2 n}}[R^{h}(\\mathcal{G},\\mathcal{S}_{n})+R^{h}(\\mathcal{G},\\mathcal{S}_{n}^{\\prime})]=2 R_{n}^{h}(\\mathcal{G},\\mathcal{D}).\n\\]\nIn the above derivation, \\((a)\\) used the fact that \\(\\sigma_{i}(\\phi (w,Z_{i}^{\\prime}) + 0.5h_{1}(w,Z_{i}^{\\prime})) - \\sigma_{i}(\\phi (w,Z_{i}) + 0.5h_{1}(w,Z_{i}))\\) and \\((\\phi (w,Z_i^{\\prime}) + 0.5h_1(w,Z_i^{\\prime})) - (\\phi (w,Z_i) + 0.5h_1(w,Z_i))\\) have the same distributions.", "context": [{"id": "ch6:definition:6_6", "name": "definition 6.6", "statement": "Consider any known data-dependent offset function \\( h(w, S_n) \\). Define the uniform convergence complexity of a function class \\( \\mathcal{G} \\) with offset \\( h \\) as\n\\[\n\\epsilon_{n}^{h}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}\\sup_{w\\in\\Omega}[\\phi(w,\\mathcal{D})-\\phi(w,\\mathcal{S}_{n})-h(w,\\mathcal{S}_{n})].\\tag{6.2}\n\\]\nThis quantity measures the one-sided expected uniform convergence of function class \\(\\mathcal{G}\\) with offset function \\(h(w, S_n)\\).\nWe note that\n\\[\n\\epsilon_{n}(\\mathcal{G},\\mathcal{D})=\\epsilon_{n}^{h}(\\mathcal{G},\\mathcal{D}),\\qquad \\text{w i t h} h=0.\n\\]"}, {"id": "ch6:definition:6_11", "name": "definition 6.11", "statement": "Consider a function class \\(\\mathcal{G} = \\{\\phi(w, Z) : w \\in \\Omega\\}\\), and let \\(h\\) be an offset function of the following form\n\\[\nh(w,\\mathcal{S}_{n})=\\frac{1}{n}\\sum_{i=1}^{n}h(w,Z_{i}),\\quad h(w,z)=h_{0}(w)+h_{1}(w,z).\\tag{6.3}\n\\]\nGiven \\( S_{n}=\\{Z_{1},\\ldots,Z_{n}\\} \\), the (one-sided) empirical Rademacher complexity of \\( \\mathcal{G} \\) with offset \\( h \\) decomposition (6.3) is defined as\n\\[\nR^{h}(\\mathcal{G},\\mathcal{S}_{n})=\\mathbb{E}_{\\sigma}\\sup_{w\\in\\Omega}\\left[\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}[\\phi(w,Z_{i})+0. 5h_{1}(w,Z_{i})]-0. 5h(w,\\mathcal{S}_{n})\\right],\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}^{h}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R^{h}(\\mathcal{G},\\mathcal{S}_{n}).\n\\]\nWe note that the standard Rademacher complexity can be regarded as a special case of the offset Rademacher complexity with \\( h(\\cdot) = h_0(\\cdot) = h_1(\\cdot) = 0 \\):\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n})=R^{0}(\\mathcal{G},\\mathcal{S}_{n}),\\quad R_{n}(\\mathcal{G},\\mathcal{D})=R_{n}^{0}(\\mathcal{G},\\mathcal{D}).\n\\]\nIt should be pointed out that the decomposition of \\( h \\) in (6.3) may not be unique, and the offset Rademacher complexity relies on the specific decomposition used.\nAs shown in Example 6.10, we allow distribution dependent offset in the definition of uniform convergence complexity. We also allow distribution dependent offset in the definition of offset Rademacher complexity."}, {"id": "ch6:equation:6_1", "name": "equation (6.1)", "statement": "The approximate regularized ERM method is to find \\( \\hat{w} \\in \\Omega \\) such that, for some \\( \\epsilon' \\geq 0 \\),\n\\[\n\\phi(\\hat{w},\\mathcal{S}_{n})+h(\\hat{w},\\mathcal{S}_{n})\\leq\\inf_{w\\in\\Omega}[\\phi(w,\\mathcal{S}_{n})+h(w,\\mathcal{S}_{n})]+\\epsilon'.\\tag{6.1}\n\\]\nWhen \\(h = 0\\), this reduces to the plain approximate ERM method."}, {"id": "ch6:theorem:6_7", "name": "theorem 6.7", "statement": "Let \\( S_{n} \\) be \\( n \\) iid samples from \\( \\mathcal{D} \\). Then the approximate ERM method of (6.1) satisfies\n\\[\n\\mathbb{E}_{\\mathcal{S}_{n}}\\phi(\\hat{w},\\mathcal{D})\\leq\\inf_{w\\in\\Omega}\\left[\\phi(w,\\mathcal{D})+\\mathbb{E}_{\\mathcal{S}_{n}}h(w,\\mathcal{S}_{n})\\right]+\\epsilon^{\\prime}+\\epsilon_{n}^{h}(\\mathcal{G},\\mathcal{D}).\n\\]"}, {"id": "ch3:definition:3_8", "name": "definition 3.8", "statement": "We define\n\\[\n\\phi(w,z)=L\\left(f(w,x),y\\right)-L_{*}(x,y),\\tag{3.4}\n\\]\nfor \\( w \\in \\Omega \\) and \\( z = (x, y) \\in \\mathcal{Z} = \\mathcal{X} \\times \\mathcal{Y} \\), and a pre-chosen \\( L_{*}(x, y) \\) of \\( z = (x, y) \\) that does not depend on \\( w \\).\nFor training data \\( S_{n}=\\{Z_{i}=(X_{i},Y_{i}):i=1,\\ldots,n\\} \\), we define the training loss for \\( w\\in \\Omega \\) as\n\\[\n\\phi(w,\\mathcal{S}_{n})=\\frac{1}{n}\\sum_{i=1}^{n}\\phi(w,Z_{i}).\\tag{3.5}\n\\]\nMoreover, for a distribution \\(\\mathcal{D}\\) on \\(\\mathcal{Z}\\), we define the test loss for \\(w \\in \\Omega\\) as:\n\\[\n\\phi(w,\\mathcal{D})=\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(w,Z).\\tag{3.6}\n\\]\nSince \\( L_{*}(x,y) \\) does not depend on \\( w \\), the ERM solution with respect to the loss \\( L(\\cdot) \\) is equivalent to the ERM solution with respect to \\( \\phi (w,\\cdot) \\). Therefore with the simplified notations, the approximate ERM method (3.3) is a special case of the following method:\n\\[\n\\phi(\\hat{w},\\mathcal{S}_{n})\\leq\\inf_{w\\in\\Omega}\\phi(w,\\mathcal{S}_{n})+\\epsilon^{\\prime}.\\tag{3.7}\n\\]\nIn general, we may simply take \\( L_{*}(x,y) = 0 \\) in (3.4). However, for some applications, we may choose a non-zero \\( L_{*}(x,y) \\) so that\n\\[\nL(f(w,x),y)-L_{*}(x,y)\n\\]\nhas a small variance. For least squares loss, this can be achieved with \\( L_{*}(x,y) = L(f_{*}(x),y) \\) where \\( f_{*}(x) \\) is the optimal prediction function that minimizes the test loss as shown in Example 3.9. The smaller variance, combined with Bernstein's inequality, implies better generalization bound (see Section 3.6 for more details)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empOffsetRademacher {Ω Z : Type*} (n : ℕ)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ) (S : Fin n → Z) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ w : Ω,\n ((n : ℝ)⁻¹ * ∑ i : Fin n,\n (σ i : ℝ) * (φ w (S i) + (1/2) * h₁ w (S i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))\n\nnoncomputable def offsetRademacher {Ω Z : Type*} [MeasurableSpace Z] (n : ℕ)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ) (D : Measure Z) : ℝ :=\n (Measure.pi (fun _ : Fin n => D))[fun S => empOffsetRademacher n φ h₀ h₁ S]\n\nnoncomputable def offsetUniformConv {Ω Z : Type*} [MeasurableSpace Z] (n : ℕ)\n (φ : Ω → Z ��� ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ) (D : Measure Z) : ℝ :=\n (Measure.pi (fun _ : Fin n => D))[fun S =>\n ⨆ w : Ω,\n (D[fun z => φ w z]\n - (n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i)\n - (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))]\n\ntheorem ch6_theorem_6_14\n {Ω Z : Type*} [Nonempty Ω] [MeasurableSpace Z]\n (n : ℕ) (hn : 1 ≤ n)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ)\n (D : Measure Z) [IsProbabilityMeasure D]\n (hIntφ : ∀ w, Integrable (fun z => φ w z) D)\n (hInth₁ : ∀ w, Integrable (fun z => h₁ w z) D)\n (hBddSup : ∀ S : Fin n → Z,\n BddAbove (Set.range (fun w : Ω =>\n D[fun z => φ w z]\n - (n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i)\n - (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))))\n (hIntSup : Integrable (fun S : Fin n → Z =>\n ⨆ w : Ω,\n (D[fun z => φ w z]\n - (n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i)\n - (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))))\n (Measure.pi (fun _ : Fin n => D)))\n (hBddRad : ∀ (S : Fin n → Z) (σ : RadSigns n),\n BddAbove (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n,\n (σ i : ℝ) * (φ w (S i) + (1/2) * h₁ w (S i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))))))\n (hIntRad : Integrable (fun S : Fin n → Z => empOffsetRademacher n φ h₀ h₁ S)\n (Measure.pi (fun _ : Fin n => D)))\n (hBddSup2 : ∀ P : (Fin n → Z) × (Fin n → Z),\n BddAbove (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.1 i))))))\n (hIntSup2 : Integrable (fun P : (Fin n → Z) × (Fin n → Z) =>\n ⨆ w : Ω,\n ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.1 i))))\n ((Measure.pi (fun _ : Fin n => D)).prod (Measure.pi (fun _ : Fin n => D)))) :\n offsetUniformConv n φ h₀ h₁ D ≤ 2 * offsetRademacher n φ h₀ h₁ D\n ∧\n (∀ (ŵ : (Fin n → Z) → Ω) (ε' : ℝ), 0 ≤ ε' →\n (∀ S : Fin n → Z,\n ((n : ℝ)⁻¹ * ∑ i : Fin n, φ (ŵ S) (S i))\n + ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ (ŵ S) + h₁ (ŵ S) (S i)))\n ≤ (⨅ w : Ω,\n ((n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i))\n + ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))) + ε') →\n Integrable (fun S : Fin n → Z => D[fun z => φ (ŵ S) z])\n (Measure.pi (fun _ : Fin n => D)) →\n BddBelow (Set.range (fun w : Ω =>\n D[fun z => φ w z]\n + (Measure.pi (fun _ : Fin n => D))[fun S =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))])) →\n (∀ S : Fin n → Z,\n BddBelow (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i))\n + ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))))) →\n (Measure.pi (fun _ : Fin n => D))[fun S => D[fun z => φ (ŵ S) z]]\n ≤ (⨅ w : Ω,\n D[fun z => φ w z]\n + (Measure.pi (fun _ : Fin n => D))[fun S =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))])\n + ε' + 2 * offsetRademacher n φ h₀ h₁ D) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empOffsetRademacher {Ω Z : Type*} (n : ℕ)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ) (S : Fin n → Z) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ w : Ω,\n ((n : ℝ)⁻¹ * ∑ i : Fin n,\n (σ i : ℝ) * (φ w (S i) + (1/2) * h₁ w (S i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))\n\nnoncomputable def offsetRademacher {Ω Z : Type*} [MeasurableSpace Z] (n : ℕ)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ) (D : Measure Z) : ℝ :=\n (Measure.pi (fun _ : Fin n => D))[fun S => empOffsetRademacher n φ h₀ h₁ S]\n\nnoncomputable def offsetUniformConv {Ω Z : Type*} [MeasurableSpace Z] (n : ℕ)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ) (D : Measure Z) : ℝ :=\n (Measure.pi (fun _ : Fin n => D))[fun S =>\n ⨆ w : Ω,\n (D[fun z => φ w z]\n - (n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i)\n - (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))]\n\nprivate lemma mean_integrable {Z : Type*} [MeasurableSpace Z]\n (n : ℕ) (D : Measure Z) [IsProbabilityMeasure D] (f : Z → ℝ)\n (hf : Integrable f D) :\n Integrable (fun S : Fin n → Z => (n : ℝ)⁻¹ * ∑ i, f (S i))\n (Measure.pi (fun _ : Fin n => D)) := by\n exact (integrable_finset_sum _ (fun i _ => integrable_comp_eval hf)).const_mul _\n\nprivate lemma mean_integral {Z : Type*} [MeasurableSpace Z]\n (n : ℕ) (hn : 1 ≤ n) (D : Measure Z) [IsProbabilityMeasure D] (f : Z → ℝ)\n (hf : Integrable f D) :\n ∫ S : Fin n → Z, (n : ℝ)⁻¹ * ∑ i, f (S i) ∂Measure.pi (fun _ : Fin n => D)\n = ∫ z, f z ∂D := by\n rw [integral_const_mul, integral_finset_sum _ (fun i _ => integrable_comp_eval hf)]\n simp_rw [integral_comp_eval (μ := fun _ : Fin n => D) hf.aestronglyMeasurable]\n simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (by omega : n ≠ 0)\n field_simp\n\nprivate lemma rad_neg_equiv (n : ℕ) :\n ∃ e : RadSigns n ≃ RadSigns n, ∀ σ i, (e σ i : ℝ) = -(σ i : ℝ) := by\n let e₀ : ({-1, 1} : Finset ℤ) ≃ ({-1, 1} : Finset ℤ) :=\n { toFun := fun x => ⟨-x.val, by\n have hx := x.property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hx ⊢\n rcases hx with hx | hx <;> simp [hx]⟩\n invFun := fun x => ⟨-x.val, by\n have hx := x.property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hx ⊢\n rcases hx with hx | hx <;> simp [hx]⟩\n left_inv := by intro x; apply Subtype.ext; simp\n right_inv := by intro x; apply Subtype.ext; simp }\n refine ⟨Equiv.piCongrRight (fun _ : Fin n => e₀), ?_⟩\n intro σ i\n change ((-(σ i).val : ℤ) : ℝ) = _\n simp\n\nprivate lemma swap_samples {Z : Type*} [MeasurableSpace Z]\n (n : ℕ) (D : Measure Z) [IsProbabilityMeasure D] (σ : RadSigns n)\n (F : (Fin n → Z) × (Fin n → Z) → ℝ)\n (hF : Integrable F ((Measure.pi (fun _ : Fin n => D)).prod\n (Measure.pi (fun _ : Fin n => D)))) :\n let t := fun P : (Fin n → Z) × (Fin n → Z) =>\n ((fun i => if (σ i : ℤ) = 1 then P.1 i else P.2 i),\n (fun i => if (σ i : ℤ) = 1 then P.2 i else P.1 i))\n Integrable (fun P => F (t P)) ((Measure.pi (fun _ : Fin n => D)).prod\n (Measure.pi (fun _ : Fin n => D))) ∧\n ∫ P, F (t P) ∂((Measure.pi (fun _ : Fin n => D)).prod\n (Measure.pi (fun _ : Fin n => D))) =\n ∫ P, F P ∂((Measure.pi (fun _ : Fin n => D)).prod\n (Measure.pi (fun _ : Fin n => D))) := by\n classical\n let e := MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n)\n let k (i : Fin n) : Z × Z ≃ᵐ Z × Z :=\n if (σ i : ℤ) = 1 then MeasurableEquiv.refl _ else MeasurableEquiv.prodComm\n have he := measurePreserving_arrowProdEquivProdArrow Z Z (Fin n)\n (fun _ => D) (fun _ => D)\n have hk (i : Fin n) : MeasurePreserving (k i) (D.prod D) (D.prod D) := by\n dsimp [k]\n split_ifs\n · exact MeasurePreserving.id _\n · exact Measure.measurePreserving_swap\n have hp : MeasurePreserving (MeasurableEquiv.piCongrRight k)\n (Measure.pi (fun _ : Fin n => D.prod D))\n (Measure.pi (fun _ : Fin n => D.prod D)) :=\n measurePreserving_pi _ _ hk\n let q := e.symm.trans ((MeasurableEquiv.piCongrRight k).trans e)\n have hq : MeasurePreserving q ((Measure.pi (fun _ : Fin n => D)).prod\n (Measure.pi (fun _ : Fin n => D)))\n ((Measure.pi (fun _ : Fin n => D)).prod\n (Measure.pi (fun _ : Fin n => D))) := he.comp (hp.comp (he.symm e))\n have hq_apply (P : (Fin n → Z) × (Fin n → Z)) :\n q P = ((fun i => if (σ i : ℤ) = 1 then P.1 i else P.2 i),\n (fun i => if (σ i : ℤ) = 1 then P.2 i else P.1 i)) := by\n ext i <;> simp [q, e, k, MeasurableEquiv.arrowProdEquivProdArrow,\n MeasurableEquiv.piCongrRight] <;> split_ifs <;> rfl\n dsimp only\n constructor\n · simpa only [hq_apply, Function.comp_def] using hq.integrable_comp_of_integrable hF\n · simpa only [hq_apply] using hq.integral_comp' F\nprivate lemma symmetrize_sums {Ω Z : Type*} [Nonempty Ω] [MeasurableSpace Z]\n (n : ℕ) (D : Measure Z) [IsProbabilityMeasure D]\n (f g : Ω → Z → ℝ)\n (hBdd : ∀ (σ : RadSigns n) (S : Fin n → Z),\n BddAbove (Set.range (fun w => ∑ i, ((σ i : ℝ) * f w (S i) - g w (S i)))))\n (hAvg : Integrable (fun S : Fin n → Z =>\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ w, ∑ i, ((σ i : ℝ) * f w (S i) - g w (S i)))\n (Measure.pi (fun _ : Fin n => D)))\n (hPair : Integrable (fun P : (Fin n → Z) × (Fin n → Z) =>\n ⨆ w, ∑ i, (f w (P.2 i) - g w (P.2 i) - f w (P.1 i) - g w (P.1 i)))\n ((Measure.pi (fun _ : Fin n => D)).prod (Measure.pi (fun _ : Fin n => D)))) :\n (∫ P : (Fin n → Z) × (Fin n → Z),\n ⨆ w, ∑ i, (f w (P.2 i) - g w (P.2 i) - f w (P.1 i) - g w (P.1 i))\n ∂((Measure.pi (fun _ : Fin n => D)).prod (Measure.pi (fun _ : Fin n => D)))) ≤\n 2 * ∫ S : Fin n → Z, (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ w, ∑ i, ((σ i : ℝ) * f w (S i) - g w (S i))\n ∂Measure.pi (fun _ : Fin n => D) := by\n classical\n let μ := Measure.pi (fun _ : Fin n => D)\n let R (σ : RadSigns n) (S : Fin n → Z) :=\n ⨆ w, ∑ i, ((σ i : ℝ) * f w (S i) - g w (S i))\n let A (S : Fin n → Z) := (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ, R σ S\n let H (P : (Fin n → Z) × (Fin n → Z)) :=\n ⨆ w, ∑ i, (f w (P.2 i) - g w (P.2 i) - f w (P.1 i) - g w (P.1 i))\n let t (σ : RadSigns n) (P : (Fin n → Z) × (Fin n → Z)) :=\n ((fun i => if (σ i : ℤ) = 1 then P.1 i else P.2 i),\n (fun i => if (σ i : ℤ) = 1 then P.2 i else P.1 i))\n obtain ⟨e, he⟩ := rad_neg_equiv n\n have ht (σ : RadSigns n) : Integrable (fun P => H (t σ P)) (μ.prod μ) ∧\n (∫ P, H (t σ P) ∂μ.prod μ) = ∫ P, H P ∂μ.prod μ :=\n swap_samples n D σ H hPair\n have hpoint (σ : RadSigns n) (P : (Fin n → Z) × (Fin n → Z)) :\n H (t σ P) ≤ R σ P.2 + R (e σ) P.1 := by\n apply ciSup_le\n intro w\n calc\n _ = (∑ i, ((σ i : ℝ) * f w (P.2 i) - g w (P.2 i))) +\n ∑ i, ((e σ i : ℝ) * f w (P.1 i) - g w (P.1 i)) := by\n rw [← Finset.sum_add_distrib]\n apply Finset.sum_congr rfl\n intro i _\n dsimp [t]\n rw [he]\n have hs := (σ i).property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hs\n rcases hs with hs | hs <;> simp [hs] <;> ring\n _ ≤ _ := add_le_add (le_ciSup (hBdd σ P.2) w) (le_ciSup (hBdd (e σ) P.1) w)\n have hsum (P : (Fin n → Z) × (Fin n → Z)) :\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ, H (t σ P) ≤ A P.1 + A P.2 := by\n calc\n _ ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ, (R σ P.2 + R (e σ) P.1) :=\n mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun σ _ => hpoint σ P))\n (inv_nonneg.mpr (Nat.cast_nonneg _))\n _ = _ := by rw [Finset.sum_add_distrib, e.sum_comp (fun σ => R σ P.1)]; dsimp [A]; ring\n have hi := integral_mono\n ((integrable_finset_sum _ (fun σ _ => (ht σ).1)).const_mul\n (Fintype.card (RadSigns n) : ℝ)⁻¹)\n ((hAvg.comp_fst μ).add (hAvg.comp_snd μ)) hsum\n simp only [Pi.add_apply] at hi\n rw [integral_const_mul, integral_finset_sum _ (fun σ _ => (ht σ).1)] at hi\n simp_rw [(ht _).2] at hi\n haveI : Nonempty (RadSigns n) := ⟨fun _ => ⟨1, by simp⟩⟩\n have hc : (Fintype.card (RadSigns n) : ℝ) ≠ 0 :=\n Nat.cast_ne_zero.mpr Fintype.card_ne_zero\n simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul,\n ← mul_assoc, inv_mul_cancel₀ hc, one_mul] at hi\n rw [integral_add (hAvg.comp_fst μ) (hAvg.comp_snd μ), integral_fun_fst A,\n integral_fun_snd A] at hi\n simpa [μ, A, R, H, two_mul] using hi\n\nprivate lemma ghost_sup_bound {Ω X : Type*} [Nonempty Ω] [MeasurableSpace X]\n (μ : Measure X) [IsProbabilityMeasure μ] (a b : Ω → X → ℝ) (c : Ω → ℝ)\n (ha : ∀ w, Integrable (a w) μ) (hmean : ∀ w, ∫ S, a w S ∂μ = c w)\n (hSup : Integrable (fun S => ⨆ w, c w - a w S - b w S) μ)\n (hBdd : ∀ P : X × X, BddAbove\n (Set.range (fun w => a w P.2 - a w P.1 - b w P.1)))\n (hPair : Integrable (fun P : X × X => ⨆ w, a w P.2 - a w P.1 - b w P.1)\n (μ.prod μ)) :\n (∫ S, ⨆ w, c w - a w S - b w S ∂μ) ≤\n ∫ P : X × X, ⨆ w, a w P.2 - a w P.1 - b w P.1 ∂μ.prod μ := by\n rw [integral_prod _ hPair]\n apply integral_mono_ae hSup hPair.integral_prod_left\n filter_upwards [hPair.prod_right_ae] with S hS\n apply ciSup_le\n intro w\n have hw : Integrable (fun T => a w T - a w S - b w S) μ :=\n ((ha w).sub (integrable_const _)).sub (integrable_const _)\n calc\n _ = ∫ T, a w T - a w S - b w S ∂μ := by\n rw [integral_sub (f := fun T => a w T - a w S)\n ((ha w).sub (integrable_const (a w S))) (integrable_const (b w S)),\n integral_sub (ha w) (integrable_const (a w S)), hmean]\n simp\n _ ≤ _ := integral_mono hw hS (fun T => le_ciSup (hBdd (S, T)) w)\n\n\nprivate theorem offset_symmetrization_bound\n {Ω Z : Type*} [Nonempty Ω] [MeasurableSpace Z]\n (n : ℕ) (hn : 1 ≤ n)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ)\n (D : Measure Z) [IsProbabilityMeasure D]\n (hIntφ : ∀ w, Integrable (fun z => φ w z) D)\n (hIntSup : Integrable (fun S : Fin n → Z =>\n ⨆ w : Ω,\n (D[fun z => φ w z]\n - (n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i)\n - (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))))\n (Measure.pi (fun _ : Fin n => D)))\n (hBddRad : ∀ (S : Fin n → Z) (σ : RadSigns n),\n BddAbove (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n,\n (σ i : ℝ) * (φ w (S i) + (1/2) * h₁ w (S i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))))))\n (hIntRad : Integrable (fun S : Fin n → Z => empOffsetRademacher n φ h₀ h₁ S)\n (Measure.pi (fun _ : Fin n => D)))\n (hBddSup2 : ∀ P : (Fin n → Z) × (Fin n → Z),\n BddAbove (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.1 i))))))\n (hIntSup2 : Integrable (fun P : (Fin n → Z) × (Fin n → Z) =>\n ⨆ w : Ω,\n ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.1 i))))\n ((Measure.pi (fun _ : Fin n => D)).prod (Measure.pi (fun _ : Fin n => D)))) :\n offsetUniformConv n φ h₀ h₁ D ≤ 2 * offsetRademacher n φ h₀ h₁ D\n := by\n classical\n let f (w : Ω) (z : Z) := (n : ℝ)⁻¹ * (φ w z + (1/2) * h₁ w z)\n let g (w : Ω) (z : Z) := (1/2) * (n : ℝ)⁻¹ * (h₀ w + h₁ w z)\n have hrad (σ : RadSigns n) (S : Fin n → Z) (w : Ω) :\n (∑ i, ((σ i : ℝ) * f w (S i) - g w (S i))) =\n ((n : ℝ)⁻¹ * ∑ i, (σ i : ℝ) * (φ w (S i) + (1/2) * h₁ w (S i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (S i))) := by\n dsimp [f, g]\n simp only [Finset.mul_sum, ← Finset.sum_sub_distrib]\n apply Finset.sum_congr rfl\n intro i _\n ring\n have hpair (P : (Fin n → Z) × (Fin n → Z)) (w : Ω) :\n (∑ i, (f w (P.2 i) - g w (P.2 i) - f w (P.1 i) - g w (P.1 i))) =\n ((n : ℝ)⁻¹ * ∑ i, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (P.1 i))) := by\n dsimp [f, g]\n simp only [Finset.mul_sum, ← Finset.sum_sub_distrib]\n apply Finset.sum_congr rfl\n intro i _\n ring\n have hghost (P : (Fin n → Z) × (Fin n → Z)) (w : Ω) :\n ((n : ℝ)⁻¹ * ∑ i, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (P.1 i))) =\n (n : ℝ)⁻¹ * ∑ i, φ w (P.2 i) - (n : ℝ)⁻¹ * ∑ i, φ w (P.1 i)\n - (n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (P.1 i)) := by\n simp only [Finset.sum_add_distrib, ← Finset.mul_sum]\n ring\n have hs := symmetrize_sums n D f g\n (fun σ S => by simpa only [hrad] using hBddRad S σ)\n (by simpa only [hrad, empOffsetRademacher] using hIntRad)\n (by simpa only [hpair] using hIntSup2)\n have hg := ghost_sup_bound (Measure.pi (fun _ : Fin n => D))\n (fun w S => (n : ℝ)⁻¹ * ∑ i, φ w (S i))\n (fun w S => (n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (S i)))\n (fun w => D[fun z => φ w z])\n (fun w => mean_integrable n D (φ w) (hIntφ w))\n (fun w => mean_integral n hn D (φ w) (hIntφ w)) hIntSup\n (fun P => by simpa only [hghost] using hBddSup2 P)\n (by simpa only [hghost] using hIntSup2)\n simp only [hpair, hghost, hrad] at hs\n exact hg.trans (by simpa only [offsetRademacher, empOffsetRademacher] using hs)\n\ntheorem ch6_theorem_6_14\n {Ω Z : Type*} [Nonempty Ω] [MeasurableSpace Z]\n (n : ℕ) (hn : 1 ≤ n)\n (φ : Ω → Z → ℝ) (h₀ : Ω → ℝ) (h₁ : Ω → Z → ℝ)\n (D : Measure Z) [IsProbabilityMeasure D]\n (hIntφ : ∀ w, Integrable (fun z => φ w z) D)\n (hInth₁ : ∀ w, Integrable (fun z => h₁ w z) D)\n (hBddSup : ∀ S : Fin n → Z,\n BddAbove (Set.range (fun w : Ω =>\n D[fun z => φ w z]\n - (n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i)\n - (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))))\n (hIntSup : Integrable (fun S : Fin n → Z =>\n ⨆ w : Ω,\n (D[fun z => φ w z]\n - (n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i)\n - (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))))\n (Measure.pi (fun _ : Fin n => D)))\n (hBddRad : ∀ (S : Fin n → Z) (σ : RadSigns n),\n BddAbove (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n,\n (σ i : ℝ) * (φ w (S i) + (1/2) * h₁ w (S i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))))))\n (hIntRad : Integrable (fun S : Fin n → Z => empOffsetRademacher n φ h₀ h₁ S)\n (Measure.pi (fun _ : Fin n => D)))\n (hBddSup2 : ∀ P : (Fin n → Z) × (Fin n → Z),\n BddAbove (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.1 i))))))\n (hIntSup2 : Integrable (fun P : (Fin n → Z) × (Fin n → Z) =>\n ⨆ w : Ω,\n ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.2 i) + (1/2) * h₁ w (P.2 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.2 i)))\n - ((n : ℝ)⁻¹ * ∑ i : Fin n, (φ w (P.1 i) + (1/2) * h₁ w (P.1 i)))\n - (1/2) * ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (P.1 i))))\n ((Measure.pi (fun _ : Fin n => D)).prod (Measure.pi (fun _ : Fin n => D)))) :\n offsetUniformConv n φ h₀ h₁ D ≤ 2 * offsetRademacher n φ h₀ h₁ D\n ∧\n (∀ (ŵ : (Fin n → Z) → Ω) (ε' : ℝ), 0 ≤ ε' →\n (∀ S : Fin n → Z,\n ((n : ℝ)⁻¹ * ∑ i : Fin n, φ (ŵ S) (S i))\n + ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ (ŵ S) + h₁ (ŵ S) (S i)))\n ≤ (⨅ w : Ω,\n ((n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i))\n + ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))) + ε') →\n Integrable (fun S : Fin n → Z => D[fun z => φ (ŵ S) z])\n (Measure.pi (fun _ : Fin n => D)) →\n BddBelow (Set.range (fun w : Ω =>\n D[fun z => φ w z]\n + (Measure.pi (fun _ : Fin n => D))[fun S =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))])) →\n (∀ S : Fin n → Z,\n BddBelow (Set.range (fun w : Ω =>\n ((n : ℝ)⁻¹ * ∑ i : Fin n, φ w (S i))\n + ((n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i)))))) →\n (Measure.pi (fun _ : Fin n => D))[fun S => D[fun z => φ (ŵ S) z]]\n ≤ (⨅ w : Ω,\n D[fun z => φ w z]\n + (Measure.pi (fun _ : Fin n => D))[fun S =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (h₀ w + h₁ w (S i))])\n + ε' + 2 * offsetRademacher n φ h₀ h₁ D) := by\n have hsymm := offset_symmetrization_bound n hn φ h₀ h₁ D hIntφ\n hIntSup hBddRad hIntRad hBddSup2 hIntSup2\n refine ⟨hsymm, ?_⟩\n intro ŵ ε' hε hERM hRisk hLower hEmpLower\n have hcomp (w : Ω) :\n (Measure.pi (fun _ : Fin n => D))[fun S => D[fun z => φ (ŵ S) z]] ≤\n D[fun z => φ w z] +\n (Measure.pi (fun _ : Fin n => D))[fun S =>\n (n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (S i))] + ε' +\n offsetUniformConv n φ h₀ h₁ D := by\n have hφ := mean_integrable n D (φ w) (hIntφ w)\n have hh := mean_integrable n D (fun z => h₀ w + h₁ w z)\n ((integrable_const _).add (hInth₁ w))\n have hpoint (S : Fin n → Z) := le_ciSup (hBddSup S) (ŵ S)\n have herm (S : Fin n → Z) := (hERM S).trans\n (add_le_add (ciInf_le (hEmpLower S) w) (le_refl ε'))\n have hi := integral_mono hRisk (((hφ.add hh).add (integrable_const ε')).add hIntSup)\n (fun S => by dsimp at hpoint herm ⊢; linarith [hpoint S, herm S])\n rw [integral_add' ((hφ.add hh).add (integrable_const ε')) hIntSup,\n integral_add' (hφ.add hh) (integrable_const ε'), integral_add' hφ hh,\n mean_integral n hn D (φ w) (hIntφ w)] at hi\n simpa [offsetUniformConv] using hi\n have hbase :\n (Measure.pi (fun _ : Fin n => D))[fun S => D[fun z => φ (ŵ S) z]]\n - ε' - offsetUniformConv n φ h₀ h₁ D ≤\n ⨅ w : Ω, D[fun z => φ w z] +\n (Measure.pi (fun _ : Fin n => D))[fun S =>\n (n : ℝ)⁻¹ * ∑ i, (h₀ w + h₁ w (S i))] := by\n apply le_ciInf\n intro w\n linarith [hcomp w]\n linarith\n\n\nend GraduateLevel\n"} +{"id": "ch6_theorem_6_25", "source": "Graduate-level", "targets": [{"label": "ch6_theorem_6_25", "decls": ["ch6_theorem_6_25"], "statement": "We have\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n})\\leq\\inf_{\\epsilon\\geq 0}\\left[4\\epsilon+12\\int_{\\epsilon}^{\\infty}\\sqrt{\\frac{\\ln N(\\epsilon^{\\prime},\\mathcal{G},L_{2}(\\mathcal{S}_{n}))}{n}}d\\epsilon^{\\prime}\\right].\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Let \\(B = \\sup_{g\\in \\mathcal{G}}\\| g\\|_{L_2(S_n)}\\), and let \\(\\epsilon_{\\ell} = 2^{-\\ell}B\\) for \\(\\ell = 0,1,\\ldots\\). Let \\(\\mathcal{G}_{\\ell}\\) be an \\(\\epsilon_{\\ell}\\)-cover of \\(\\mathcal{G}\\) with metric \\(L_{2}(S_{n})\\), and \\(N_{\\ell} = |\\mathcal{G}_{\\ell}| = N(\\epsilon_{\\ell},\\mathcal{G},L_{2}(S_{n}))\\). We may let \\(\\mathcal{G}_0 = \\{0\\}\\) at scale \\(\\epsilon_0 = B\\).\nFor each \\( g \\in \\mathcal{G} \\), we consider \\( g_{\\ell}(g) \\in \\mathcal{G}_{\\ell} \\) so that \\( \\| g - g_{\\ell}(g)\\|_{L_2(\\mathcal{S}_n)} \\leq \\epsilon_{\\ell} \\). The key idea in chaining is to rewrite \\( g \\in \\mathcal{G} \\) using the following multi-scale decomposition:\n\\[\ng=(g-g_{L}(g))+\\sum_{\\ell=1}^{L}(g_{\\ell}(g)-g_{\\ell-1}(g)).\n\\]\nWe also have\n\\[\n\\left\\|g_{\\ell}(g)-g_{\\ell-1}(g)\\right\\|_{L_{2}\\left(\\mathcal{S}_{n}\\right)}\\leq\\left\\|g_{\\ell}(g)-g\\right\\|_{L_{2}\\left(\\mathcal{S}_{n}\\right)}+\\left\\|g_{\\ell-1}(g)-g\\right\\|_{L_{2}\\left(\\mathcal{S}_{n}\\right)}\\leq 3\\epsilon_{\\ell}.\\tag{6.7}\n\\]\nThe number of distinct \\( g_{\\ell}(g) - g_{\\ell - 1}(g) \\) is no more than \\( N_{\\ell}N_{\\ell - 1} \\). It implies that\n\\[\n\\begin{array}{l}R(\\mathcal{G},\\mathcal{S}_{n})=\\mathbb{E}_{\\sigma}\\sup_{g\\in\\mathcal{G}}\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}\\left[(g-g_{L}(g))(Z_{i})+\\sum_{\\ell=1}^{L}(g_{\\ell}(g)-g_{\\ell-1}(g))(Z_{i})\\right]\\\\ \\leq\\mathbb{E}_{\\sigma}\\sup_{g\\in\\mathcal{G}}\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}(g-g_{L}(g))(Z_{i})+\\sum_{\\ell=1}^{L}\\mathbb{E}_{\\sigma}\\sup_{g\\in\\mathcal{G}}\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}(g_{\\ell}(g)-g_{\\ell-1}(g))(Z_{i})\\\\ \\stackrel{(a)}{\\leq}\\epsilon_{L}+\\sum_{\\ell=1}^{L}\\sup_{g\\in\\mathcal{G}}\\|g_{\\ell}(g)-g_{\\ell-1}(g)\\|_{L_{2}(\\mathcal{S}_{n})}\\sqrt{\\frac{2\\ln [N_{\\ell}N_{\\ell-1}]}{n}}\\\\ \\stackrel{(b)}{\\leq}\\epsilon_{L}+3\\sum_{\\ell=1}^{L}\\epsilon_{\\ell}\\sqrt{\\frac{2\\ln\\left[N_{\\ell}N_{\\ell-1}\\right]}{n}}\\\\ \\leq\\epsilon_{L}+12\\sum_{\\ell=1}^{L}\\left(\\epsilon_{\\ell}-\\epsilon_{\\ell+1}\\right)\\sqrt{\\frac{\\ln\\left[N_{\\ell}\\right]}{n}}\\\\ \\leq\\epsilon_{L}+12\\int_{\\epsilon_{L}/2}^{\\infty}\\sqrt{\\frac{\\ln N(\\epsilon^{\\prime},\\mathcal{G},L_{2}(\\mathcal{S}_{n}))}{n}}d\\epsilon^{\\prime}.\\\\ \\end{array}\n\\]\nThe derivation of (a) used Theorem 6.23, and the derivation of (b) used (6.7). The next two inequalities used \\( N(\\epsilon, \\mathcal{G}, L_2(S_n)) \\) is a non-increasing function of \\( \\epsilon \\). Now given any \\( \\epsilon > 0 \\), we can choose \\( \\epsilon_L \\) so that \\( \\epsilon \\in [\\epsilon_L / 4, \\epsilon_L / 2] \\). This leads to the desired result.", "context": [{"id": "ch6:theorem:6_23", "name": "theorem 6.23", "statement": "If \\(\\mathcal{G}\\) is a finite function class with \\(|\\mathcal{G}| = N\\), then\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n})\\leq\\sup_{g\\in\\mathcal{G}}\\|g\\|_{L_{2}(\\mathcal{S}_{n})}\\cdot\\sqrt{\\frac{2\\ln N}{n}}.\n\\]\nIf moreover, for all \\( g \\in \\mathcal{G} \\), \\( g(z) \\in [0,1] \\). Consider the offset decomposition (6.3), and let \\( h_0(g) = 0 \\), and \\( h_1(g, S_n) = (\\gamma / n)\\sum_{i=1}^{n} g(Z_i) \\). Then we have\n\\[\nR^{h}(\\mathcal{G},\\mathcal{S}_{n})\\leq\\frac{(1+0.5\\gamma)^{2}\\ln N}{\\gamma n}.\n\\]"}, {"id": "ch4:definition:4_4", "name": "Empirical and Uniform Covering Number", "statement": "Given an empirical distribution \\( S_{n}=\\{Z_{1},\\ldots,Z_{n}\\} \\), we define the pseudometric \\( d = L_{p}(S_{n}) \\) as\n\\[\nd(\\phi,\\phi^{\\prime})=\\left[\\frac{1}{n}\\sum_{i=1}^{n}|\\phi(Z_{i})-\\phi^{\\prime}(Z_{i})|^{p}\\right]^{1/p}.\n\\]\nThe corresponding metric covering number \\(N(\\epsilon, \\mathcal{G}, L_p(\\mathcal{S}_n))\\) is referred to as the\nempirical \\( L_{p} \\) covering number. Given \\( n \\), the largest \\( L_{p} \\) covering number over empirical distribution \\( S_{n} \\) is referred to as the uniform \\( L_{p} \\) covering number\n\\[\nN_{p}(\\epsilon,\\mathcal{G},n)=\\sup_{\\mathcal{S}_{n}}N(\\epsilon,\\mathcal{G},L_{p}(\\mathcal{S}_{n})).\n\\]"}, {"id": "ch6:definition:6_3", "name": "definition 6.3", "statement": "Given \\(S_{n}=\\{Z_{1},\\ldots,Z_{n}\\}\\), the (one-sided) empirical Rademacher complexity of \\(\\mathcal{G}\\) is defined as\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n}) = \\mathbb{E}_{\\sigma}\\sup_{w\\in \\Omega}\\frac{1}{n}\\sum_{i = 1}^{n}\\sigma_{i}\\phi (w,Z_{i}),\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R(\\mathcal{G},\\mathcal{S}_{n}).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ndef isENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNum {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop ℕ :=\n sInf {n | ∃ t, isENet t eps s ∧ (t.card : WithTop ℕ) = n}\n\nnoncomputable def dudleyIntegrand6_25 {ι : Type*} [PseudoMetricSpace ι]\n (n : ℕ) (eps' : ℝ) : ℝ :=\n Real.sqrt\n (Real.log (((coveringNum eps' (Set.univ : Set ι)).untopD 0 : ℕ) : ℝ)\n / (n : ℝ))\n\ntheorem ch6_theorem_6_25\n {ι : Type*} {𝒳 : Type*} [PseudoMetricSpace ι]\n (n : ℕ) (hn : 1 ≤ n)\n (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳)\n (hdist : ∀ i j : ι,\n dist i j = Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, (f i (S k) - f j (S k)) ^ 2))\n (hTB : TotallyBounded (Set.univ : Set ι))\n (hBdd : BddAbove (Set.range (fun i : ι =>\n Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, (f i (S k)) ^ 2))))\n (hInt : ∀ eps ∈ Set.Ici (0 : ℝ),\n IntegrableOn (fun eps' => dudleyIntegrand6_25 (ι := ι) n eps') (Set.Ioi eps)) :\n empRadSigned n f S\n ≤ ⨅ eps : Set.Ici (0 : ℝ),\n (4 * (eps : ℝ)\n + 12 * ∫ eps' in Set.Ioi (eps : ℝ), dudleyIntegrand6_25 (ι := ι) n eps') := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ndef isENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNum {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop ℕ :=\n sInf {n | ∃ t, isENet t eps s ∧ (t.card : WithTop ℕ) = n}\n\nnoncomputable def dudleyIntegrand6_25 {ι : Type*} [PseudoMetricSpace ι]\n (n : ℕ) (eps' : ℝ) : ℝ :=\n Real.sqrt\n (Real.log (((coveringNum eps' (Set.univ : Set ι)).untopD 0 : ℕ) : ℝ)\n / (n : ℝ))\n\n/- ================= AUXILIARY ================= -/\n\n/-- Unnormalised euclidean norm. -/\nnoncomputable def auxE (n : ℕ) (a : Fin n → ℝ) : ℝ := Real.sqrt (∑ k, (a k) ^ 2)\n\n/-- Normalised (`L²(Sₙ)`) norm. -/\nnoncomputable def auxNrm (n : ℕ) (a : Fin n → ℝ) : ℝ :=\n Real.sqrt ((n : ℝ)⁻¹ * ∑ k, (a k) ^ 2)\n\nlemma auxNrm_nonneg (n : ℕ) (a : Fin n → ℝ) : 0 ≤ auxNrm n a := Real.sqrt_nonneg _\n\nlemma auxE_nonneg (n : ℕ) (a : Fin n → ℝ) : 0 ≤ auxE n a := Real.sqrt_nonneg _\n\nlemma auxNrm_eq (n : ℕ) (a : Fin n → ℝ) : auxNrm n a = auxE n a / Real.sqrt n := by\n unfold auxNrm auxE\n rw [Real.sqrt_mul (by positivity), Real.sqrt_inv, inv_mul_eq_div]\n\nlemma auxNrm_sq (n : ℕ) (a : Fin n → ℝ) :\n (auxNrm n a) ^ 2 = (n : ℝ)⁻¹ * ∑ k, (a k) ^ 2 := by\n unfold auxNrm\n exact Real.sq_sqrt (by positivity)\n\nlemma auxE_sub_le (n : ℕ) (a b : Fin n → ℝ) :\n auxE n (fun k => a k - b k) ≤ auxE n a + auxE n b := by\n have hA : (0:ℝ) ≤ ∑ k, (a k) ^ 2 := by positivity\n have hB : (0:ℝ) ≤ ∑ k, (b k) ^ 2 := by positivity\n have hcs : ∑ k, (a k) * (-(b k)) ≤\n Real.sqrt (∑ k, (a k) ^ 2) * Real.sqrt (∑ k, (-(b k)) ^ 2) :=\n Real.sum_mul_le_sqrt_mul_sqrt _ _ _\n have hb2 : ∑ k, (-(b k)) ^ 2 = ∑ k, (b k) ^ 2 := by\n refine Finset.sum_congr rfl (fun k _ => by ring)\n rw [hb2] at hcs\n have hcs' : -(∑ k, (a k) * (b k)) ≤\n Real.sqrt (∑ k, (a k) ^ 2) * Real.sqrt (∑ k, (b k) ^ 2) := by\n have : ∑ k, (a k) * (-(b k)) = -(∑ k, (a k) * (b k)) := by\n rw [← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl (fun k _ => by ring)\n linarith [hcs, this.symm.le, this.le]\n have expand : ∑ k, (a k - b k) ^ 2\n = (∑ k, (a k) ^ 2) - 2 * (∑ k, (a k) * (b k)) + (∑ k, (b k) ^ 2) := by\n rw [Finset.sum_congr rfl (fun k (_ : k ∈ Finset.univ) =>\n (by ring : (a k - b k) ^ 2 = (a k) ^ 2 - 2 * ((a k) * (b k)) + (b k) ^ 2))]\n rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, Finset.mul_sum]\n have key : ∑ k, (a k - b k) ^ 2\n ≤ (Real.sqrt (∑ k, (a k) ^ 2) + Real.sqrt (∑ k, (b k) ^ 2)) ^ 2 := by\n have e1 : (Real.sqrt (∑ k, (a k) ^ 2)) ^ 2 = ∑ k, (a k) ^ 2 := Real.sq_sqrt hA\n have e2 : (Real.sqrt (∑ k, (b k) ^ 2)) ^ 2 = ∑ k, (b k) ^ 2 := Real.sq_sqrt hB\n nlinarith [hcs', e1, e2]\n unfold auxE\n calc Real.sqrt (∑ k, (a k - b k) ^ 2)\n ≤ Real.sqrt ((Real.sqrt (∑ k, (a k) ^ 2) + Real.sqrt (∑ k, (b k) ^ 2)) ^ 2) :=\n Real.sqrt_le_sqrt key\n _ = Real.sqrt (∑ k, (a k) ^ 2) + Real.sqrt (∑ k, (b k) ^ 2) :=\n Real.sqrt_sq (by positivity)\n\nlemma auxNrm_sub_le {n : ℕ} (hn : 1 ≤ n) (a b : Fin n → ℝ) :\n auxNrm n (fun k => a k - b k) ≤ auxNrm n a + auxNrm n b := by\n have hs : (0:ℝ) < Real.sqrt n := Real.sqrt_pos.mpr (by exact_mod_cast hn)\n rw [auxNrm_eq, auxNrm_eq, auxNrm_eq, ← add_div]\n exact div_le_div_of_nonneg_right (auxE_sub_le n a b) hs.le\n\n\n/- ----------- Rademacher averages ----------- -/\n\nlemma auxRadSignsNonempty (n : ℕ) : Nonempty (RadSigns n) :=\n ⟨fun _ => ⟨1, by simp⟩⟩\n\n/-- The signed empirical average of a vector. -/\nnoncomputable def auxT {n : ℕ} (σ : RadSigns n) (a : Fin n → ℝ) : ℝ :=\n (n : ℝ)⁻¹ * ∑ k, (σ k : ℝ) * a k\n\n/-- Empirical Rademacher complexity of a family of vectors. -/\nnoncomputable def auxRad {ι : Type*} (n : ℕ) (g : ι → Fin n → ℝ) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, ⨆ i, auxT σ (g i)\n\nlemma empRad_eq {ι 𝒳 : Type*} (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) :\n empRadSigned n f S = auxRad n (fun i k => f i (S k)) := rfl\n\nlemma auxSign_sq {n : ℕ} (σ : RadSigns n) (k : Fin n) : ((σ k : ℤ) : ℝ) ^ 2 = 1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h <;> rw [h] <;> norm_num\n\nlemma auxNegMem {x : ℤ} (hx : x ∈ ({-1, 1} : Finset ℤ)) : -x ∈ ({-1, 1} : Finset ℤ) := by\n simp only [Finset.mem_insert, Finset.mem_singleton] at hx ⊢\n rcases hx with h | h <;> simp [h]\n\n/-- Flip all the signs. -/\ndef auxNeg {n : ℕ} (σ : RadSigns n) : RadSigns n := fun k => ⟨-((σ k : ℤ)), auxNegMem (σ k).2⟩\n\nlemma auxNeg_involutive {n : ℕ} : Function.Involutive (auxNeg (n := n)) := by\n intro σ\n funext k\n apply Subtype.ext\n simp [auxNeg]\n\nlemma auxT_auxNeg {n : ℕ} (σ : RadSigns n) (a : Fin n → ℝ) :\n auxT (auxNeg σ) a = - auxT σ a := by\n unfold auxT\n rw [← mul_neg, ← Finset.sum_neg_distrib]\n congr 1\n refine Finset.sum_congr rfl (fun k _ => ?_)\n simp [auxNeg]\n\nlemma auxSum_neg {n : ℕ} (F : RadSigns n → ℝ) :\n ∑ σ : RadSigns n, F σ = ∑ σ : RadSigns n, F (auxNeg σ) :=\n (Equiv.sum_comp (Function.Involutive.toPerm _ auxNeg_involutive) F).symm\n\nlemma auxT_add {n : ℕ} (σ : RadSigns n) (a b : Fin n → ℝ) :\n auxT σ (fun k => a k + b k) = auxT σ a + auxT σ b := by\n unfold auxT\n rw [← mul_add, ← Finset.sum_add_distrib]\n congr 1\n exact Finset.sum_congr rfl (fun k _ => by ring)\n\nlemma auxT_le_nrm {n : ℕ} (hn : 1 ≤ n) (σ : RadSigns n) (a : Fin n → ℝ) :\n auxT σ a ≤ auxNrm n a := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hsq : Real.sqrt n * Real.sqrt n = (n:ℝ) := Real.mul_self_sqrt hn'.le\n have hcs : ∑ k, ((σ k : ℤ):ℝ) * a k\n ≤ Real.sqrt (∑ k, ((σ k : ℤ):ℝ)^2) * Real.sqrt (∑ k, (a k)^2) :=\n Real.sum_mul_le_sqrt_mul_sqrt _ _ _\n have hsig : ∑ k, ((σ k : ℤ):ℝ)^2 = (n:ℝ) := by\n simp only [auxSign_sq]\n simp\n rw [hsig] at hcs\n have hsne : Real.sqrt n ≠ 0 := (Real.sqrt_pos.mpr hn').ne'\n have hnne : (n:ℝ) ≠ 0 := hn'.ne'\n have key : (n:ℝ)⁻¹ * Real.sqrt n = (Real.sqrt n)⁻¹ := by\n field_simp\n linarith [hsq]\n unfold auxT\n rw [auxNrm_eq]\n calc (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ):ℝ) * a k\n ≤ (n:ℝ)⁻¹ * (Real.sqrt n * Real.sqrt (∑ k, (a k)^2)) :=\n mul_le_mul_of_nonneg_left hcs (by positivity)\n _ = auxE n a / Real.sqrt n := by\n rw [← mul_assoc, key, inv_mul_eq_div]; rfl\n\nlemma auxBddAbove {ι : Type*} {n : ℕ} (g : ι → Fin n → ℝ) (c : ℝ) (σ : RadSigns n)\n (h : ∀ i, auxT σ (g i) ≤ c) : BddAbove (Set.range fun i => auxT σ (g i)) :=\n ⟨c, by rintro _ ⟨i, rfl⟩; exact h i⟩\n\nlemma auxRad_le {ι : Type*} [Nonempty ι] {n : ℕ} (g : ι → Fin n → ℝ) (c : ℝ)\n (h : ∀ (σ : RadSigns n) (i : ι), auxT σ (g i) ≤ c) : auxRad n g ≤ c := by\n have hcard : (0:ℝ) < (Fintype.card (RadSigns n) : ℝ) := by\n have := Fintype.card_pos_iff (α := RadSigns n) |>.mpr (auxRadSignsNonempty n)\n exact_mod_cast this\n unfold auxRad\n have h2 : ∑ σ : RadSigns n, (⨆ i, auxT σ (g i)) ≤ (Fintype.card (RadSigns n) : ℝ) * c := by\n calc ∑ σ : RadSigns n, (⨆ i, auxT σ (g i)) ≤ ∑ _σ : RadSigns n, c :=\n Finset.sum_le_sum (fun σ _ => ciSup_le (h σ))\n _ = (Fintype.card (RadSigns n) : ℝ) * c := by\n rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]\n calc (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, (⨆ i, auxT σ (g i))\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ * ((Fintype.card (RadSigns n) : ℝ) * c) :=\n mul_le_mul_of_nonneg_left h2 (by positivity)\n _ = c := by field_simp\n\nlemma auxRad_const {ι : Type*} [Nonempty ι] {n : ℕ} (c : Fin n → ℝ) :\n auxRad n (fun _ : ι => c) = 0 := by\n unfold auxRad\n have hc : ∀ σ : RadSigns n, (⨆ _ : ι, auxT σ c) = auxT σ c := fun σ => ciSup_const\n simp only [hc]\n have h2 : ∑ σ : RadSigns n, auxT σ c = 0 := by\n have h3 := auxSum_neg (fun σ => auxT σ c)\n simp only [auxT_auxNeg] at h3\n rw [Finset.sum_neg_distrib] at h3\n linarith\n rw [h2, mul_zero]\n\nlemma auxRad_add_le {ι : Type*} [Nonempty ι] {n : ℕ} (g h : ι → Fin n → ℝ)\n (hg : ∀ σ : RadSigns n, BddAbove (Set.range fun i => auxT σ (g i)))\n (hh : ∀ σ : RadSigns n, BddAbove (Set.range fun i => auxT σ (h i))) :\n auxRad n (fun i k => g i k + h i k) ≤ auxRad n g + auxRad n h := by\n unfold auxRad\n rw [← mul_add, ← Finset.sum_add_distrib]\n refine mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun σ _ => ?_) (by positivity)\n refine ciSup_le fun i => ?_\n have : auxT σ (fun k => g i k + h i k) = auxT σ (g i) + auxT σ (h i) := auxT_add σ (g i) (h i)\n rw [this]\n exact add_le_add (le_ciSup (hg σ) i) (le_ciSup (hh σ) i)\n\n/- ----------- Massart's finite class lemma ----------- -/\n\nlemma aux_le_of_forall_pos {M b : ℝ} (h : ∀ ε : ℝ, 0 < ε → M ≤ b + ε) : M ≤ b := by\n by_contra hc\n push_neg at hc\n have := h ((M - b) / 2) (by linarith)\n linarith\n\nlemma aux_opt {M t s : ℝ} (ht : 0 ≤ t) (hs : 0 ≤ s)\n (h : ∀ lam : ℝ, 0 < lam → M ≤ t / lam + lam * s) :\n M ≤ 2 * Real.sqrt (t * s) := by\n rcases eq_or_lt_of_le ht with ht0 | htpos\n · have h0 : t = 0 := ht0.symm\n subst h0\n have : M ≤ 0 := by\n refine aux_le_of_forall_pos (fun ε hε => ?_)\n have := h (ε / (s + 1)) (by positivity)\n have hle : (ε / (s + 1)) * s ≤ ε := by\n rw [div_mul_eq_mul_div, div_le_iff₀ (by positivity)]\n nlinarith\n simp only [zero_div, zero_add] at this\n linarith\n simpa using this\n · rcases eq_or_lt_of_le hs with hs0 | hspos\n · have h0 : s = 0 := hs0.symm\n subst h0\n have : M ≤ 0 := by\n refine aux_le_of_forall_pos (fun ε hε => ?_)\n have := h (t / ε) (by positivity)\n rw [div_div_eq_mul_div, mul_zero, add_zero] at this\n have : M ≤ ε := by\n refine this.trans ?_\n rw [div_le_iff₀ (by positivity)]\n nlinarith\n linarith\n simpa using this\n · obtain ⟨u, hu0, rfl⟩ : ∃ u : ℝ, 0 < u ∧ t = u ^ 2 :=\n ⟨Real.sqrt t, Real.sqrt_pos.mpr htpos, (Real.sq_sqrt ht).symm⟩\n obtain ⟨w, hw0, rfl⟩ : ∃ w : ℝ, 0 < w ∧ s = w ^ 2 :=\n ⟨Real.sqrt s, Real.sqrt_pos.mpr hspos, (Real.sq_sqrt hs).symm⟩\n have hsq : Real.sqrt (u ^ 2 * w ^ 2) = u * w := by\n rw [show u ^ 2 * w ^ 2 = (u * w) ^ 2 by ring, Real.sqrt_sq (by positivity)]\n rw [hsq]\n have h1 := h (u / w) (by positivity)\n refine h1.trans ?_\n rw [div_div_eq_mul_div]\n field_simp\n ring_nf\n nlinarith [hu0, hw0]\n\nlemma auxCardRadSigns (n : ℕ) : Fintype.card (RadSigns n) = 2 ^ n := by\n show Fintype.card (Fin n → ({-1, 1} : Finset ℤ)) = 2 ^ n\n rw [Fintype.card_fun, Fintype.card_coe, Fintype.card_fin]\n norm_num\n\nlemma auxMGF {n : ℕ} (hn : 1 ≤ n) (a : Fin n → ℝ) (r lam : ℝ) (hr : 0 ≤ r)\n (hb : auxNrm n a ≤ r) :\n ∑ σ : RadSigns n, Real.exp (lam * auxT σ a)\n ≤ (Fintype.card (RadSigns n) : ℝ) * Real.exp (lam ^ 2 * r ^ 2 / (2 * n)) := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n set c : Fin n → ℝ := fun k => lam * (n:ℝ)⁻¹ * a k with hcdef\n have hla : ∀ σ : RadSigns n, lam * auxT σ a = ∑ k, c k * ((σ k : ℤ) : ℝ) := by\n intro σ\n show lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * a k) = _\n rw [← mul_assoc, Finset.mul_sum]\n exact Finset.sum_congr rfl (fun k _ => by simp only [hcdef]; ring)\n have step1 : ∑ σ : RadSigns n, Real.exp (∑ k, c k * ((σ k : ℤ) : ℝ))\n = ∏ k, ∑ s : ({-1, 1} : Finset ℤ), Real.exp (c k * ((s : ℤ) : ℝ)) := by\n rw [Fintype.prod_sum\n (fun (k : Fin n) (s : ({-1, 1} : Finset ℤ)) => Real.exp (c k * ((s : ℤ) : ℝ)))]\n refine Finset.sum_congr rfl (fun σ _ => ?_)\n exact Real.exp_sum _ _\n have step2 : ∀ k : Fin n, (∑ s : ({-1, 1} : Finset ℤ), Real.exp (c k * ((s : ℤ) : ℝ)))\n ≤ 2 * Real.exp ((c k) ^ 2 / 2) := by\n intro k\n rw [Finset.sum_coe_sort ({-1, 1} : Finset ℤ) (fun x : ℤ => Real.exp (c k * (x : ℝ)))]\n rw [Finset.sum_pair (by norm_num : (-1 : ℤ) ≠ 1)]\n have e1 : c k * ((-1 : ℤ) : ℝ) = -(c k) := by push_cast; ring\n have e2 : c k * ((1 : ℤ) : ℝ) = c k := by push_cast; ring\n rw [e1, e2]\n have := Real.cosh_le_exp_half_sq (c k)\n rw [Real.cosh_eq] at this\n linarith\n have step3 : ∏ k : Fin n, (2 * Real.exp ((c k) ^ 2 / 2))\n = (2:ℝ) ^ n * Real.exp ((∑ k, (c k) ^ 2) / 2) := by\n rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin,\n ← Real.exp_sum, Finset.sum_div]\n have hnrm2 : (n:ℝ)⁻¹ * ∑ k, (a k) ^ 2 ≤ r ^ 2 := by\n rw [← auxNrm_sq]\n exact pow_le_pow_left₀ (auxNrm_nonneg n a) hb 2\n have hcs : (∑ k, (c k) ^ 2) / 2 ≤ lam ^ 2 * r ^ 2 / (2 * n) := by\n have hexp : ∑ k, (c k) ^ 2 = lam ^ 2 * (n:ℝ)⁻¹ * ((n:ℝ)⁻¹ * ∑ k, (a k) ^ 2) := by\n rw [Finset.mul_sum, Finset.mul_sum]\n refine Finset.sum_congr rfl (fun k _ => ?_)\n simp only [hcdef]\n ring\n have hgoal : lam ^ 2 * r ^ 2 / (2 * n) = lam ^ 2 * (n:ℝ)⁻¹ * r ^ 2 / 2 := by\n field_simp\n rw [hexp, hgoal]\n have hlam : (0:ℝ) ≤ lam ^ 2 * (n:ℝ)⁻¹ := by positivity\n exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hnrm2 hlam) (by norm_num)\n calc ∑ σ : RadSigns n, Real.exp (lam * auxT σ a)\n = ∑ σ : RadSigns n, Real.exp (∑ k, c k * ((σ k : ℤ) : ℝ)) := by\n exact Finset.sum_congr rfl (fun σ _ => by rw [hla σ])\n _ = ∏ k, ∑ s : ({-1, 1} : Finset ℤ), Real.exp (c k * ((s : ℤ) : ℝ)) := step1\n _ ≤ ∏ k : Fin n, (2 * Real.exp ((c k) ^ 2 / 2)) := by\n refine Finset.prod_le_prod (fun k _ => ?_) (fun k _ => step2 k)\n exact Finset.sum_nonneg (fun s _ => (Real.exp_pos _).le)\n _ = (2:ℝ) ^ n * Real.exp ((∑ k, (c k) ^ 2) / 2) := step3\n _ ≤ (2:ℝ) ^ n * Real.exp (lam ^ 2 * r ^ 2 / (2 * n)) := by\n exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr hcs) (by positivity)\n _ = (Fintype.card (RadSigns n) : ℝ) * Real.exp (lam ^ 2 * r ^ 2 / (2 * n)) := by\n rw [auxCardRadSigns]; norm_num\n\nlemma auxMassart {α : Type*} {n : ℕ} (hn : 1 ≤ n) (A : Finset α) (hA : A.Nonempty)\n (a : α → Fin n → ℝ) (r : ℝ) (hr : 0 ≤ r) (hb : ∀ p ∈ A, auxNrm n (a p) ≤ r) :\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, A.sup' hA (fun p => auxT σ (a p))\n ≤ r * Real.sqrt (2 * Real.log A.card / n) := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hcardpos : (0:ℝ) < (Fintype.card (RadSigns n) : ℝ) := by\n rw [auxCardRadSigns]; positivity\n set M := (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, A.sup' hA (fun p => auxT σ (a p)) with hM\n have hAcard : (1:ℝ) ≤ (A.card : ℝ) := by exact_mod_cast Finset.one_le_card.mpr hA\n have hlog : 0 ≤ Real.log A.card := Real.log_nonneg hAcard\n have key : ∀ lam : ℝ, 0 < lam → M ≤ Real.log A.card / lam + lam * (r ^ 2 / (2 * n)) := by\n intro lam hlam\n have e1 : lam * M = ∑ σ : RadSigns n,\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * (lam * A.sup' hA (fun p => auxT σ (a p))) := by\n rw [hM, ← Finset.mul_sum, ← Finset.mul_sum]\n ring\n have hw : ∀ σ ∈ (Finset.univ : Finset (RadSigns n)),\n (0:ℝ) ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ := fun _ _ => by positivity\n have hw1 : ∑ _σ : RadSigns n, (Fintype.card (RadSigns n) : ℝ)⁻¹ = 1 := by\n rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]\n field_simp\n have hjen := convexOn_exp.map_sum_le (t := (Finset.univ : Finset (RadSigns n)))\n (w := fun _ => (Fintype.card (RadSigns n) : ℝ)⁻¹)\n (p := fun σ => lam * A.sup' hA (fun p => auxT σ (a p))) hw hw1 (fun _ _ => Set.mem_univ _)\n simp only [smul_eq_mul] at hjen\n have hjen2 : Real.exp (lam * M) ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, Real.exp (lam * A.sup' hA (fun p => auxT σ (a p))) := by\n calc Real.exp (lam * M)\n = Real.exp (∑ σ : RadSigns n,\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * (lam * A.sup' hA (fun p => auxT σ (a p)))) := by\n rw [e1]\n _ ≤ ∑ σ : RadSigns n, (Fintype.card (RadSigns n) : ℝ)⁻¹\n * Real.exp (lam * A.sup' hA (fun p => auxT σ (a p))) := hjen\n _ = (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, Real.exp (lam * A.sup' hA (fun p => auxT σ (a p))) := by\n rw [← Finset.mul_sum]\n have hsup : ∀ σ : RadSigns n, Real.exp (lam * A.sup' hA (fun p => auxT σ (a p)))\n ≤ ∑ p ∈ A, Real.exp (lam * auxT σ (a p)) := by\n intro σ\n obtain ⟨p₀, hp₀, hval⟩ := Finset.exists_mem_eq_sup' hA (fun p => auxT σ (a p))\n rw [hval]\n exact Finset.single_le_sum (f := fun p => Real.exp (lam * auxT σ (a p)))\n (fun p _ => (Real.exp_pos _).le) hp₀\n have hsum : ∑ σ : RadSigns n, Real.exp (lam * A.sup' hA (fun p => auxT σ (a p)))\n ≤ (A.card : ℝ) * ((Fintype.card (RadSigns n) : ℝ)\n * Real.exp (lam ^ 2 * r ^ 2 / (2 * n))) := by\n calc ∑ σ : RadSigns n, Real.exp (lam * A.sup' hA (fun p => auxT σ (a p)))\n ≤ ∑ σ : RadSigns n, ∑ p ∈ A, Real.exp (lam * auxT σ (a p)) :=\n Finset.sum_le_sum (fun σ _ => hsup σ)\n _ = ∑ p ∈ A, ∑ σ : RadSigns n, Real.exp (lam * auxT σ (a p)) := Finset.sum_comm\n _ ≤ ∑ _p ∈ A, ((Fintype.card (RadSigns n) : ℝ)\n * Real.exp (lam ^ 2 * r ^ 2 / (2 * n))) :=\n Finset.sum_le_sum (fun p hp => auxMGF hn (a p) r lam hr (hb p hp))\n _ = (A.card : ℝ) * ((Fintype.card (RadSigns n) : ℝ)\n * Real.exp (lam ^ 2 * r ^ 2 / (2 * n))) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n have hfin : Real.exp (lam * M) ≤ (A.card : ℝ) * Real.exp (lam ^ 2 * r ^ 2 / (2 * n)) := by\n refine hjen2.trans ?_\n calc (Fintype.card (RadSigns n) : ℝ)⁻¹\n * ∑ σ : RadSigns n, Real.exp (lam * A.sup' hA (fun p => auxT σ (a p)))\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ * ((A.card : ℝ)\n * ((Fintype.card (RadSigns n) : ℝ) * Real.exp (lam ^ 2 * r ^ 2 / (2 * n)))) :=\n mul_le_mul_of_nonneg_left hsum (by positivity)\n _ = (A.card : ℝ) * Real.exp (lam ^ 2 * r ^ 2 / (2 * n)) := by\n field_simp\n have hlin : lam * M ≤ Real.log A.card + lam ^ 2 * r ^ 2 / (2 * n) := by\n have hpos : (0:ℝ) < (A.card : ℝ) := by linarith\n have heq : (A.card : ℝ) * Real.exp (lam ^ 2 * r ^ 2 / (2 * n))\n = Real.exp (Real.log A.card + lam ^ 2 * r ^ 2 / (2 * n)) := by\n rw [Real.exp_add, Real.exp_log hpos]\n rw [heq] at hfin\n exact Real.exp_le_exp.mp hfin\n have hdiv : M ≤ (Real.log A.card + lam ^ 2 * r ^ 2 / (2 * n)) / lam := by\n rw [le_div_iff₀ hlam]\n linarith\n refine hdiv.trans_eq ?_\n field_simp\n have hfinal := aux_opt hlog (by positivity : (0:ℝ) ≤ r ^ 2 / (2 * n)) key\n refine hfinal.trans_eq ?_\n rw [show Real.log A.card * (r ^ 2 / (2 * n)) = (r / 2) ^ 2 * (2 * Real.log A.card / n) by\n field_simp]\n rw [Real.sqrt_mul (by positivity), Real.sqrt_sq (by linarith : (0:ℝ) ≤ r / 2)]\n ring\n\n/- ----------- one chaining level ----------- -/\n\nlemma auxLevel {ι : Type*} [PseudoMetricSpace ι] [Nonempty ι] {n : ℕ} (hn : 1 ≤ n)\n (v : ι → Fin n → ℝ)\n (hdist : ∀ i j : ι, dist i j = auxNrm n (fun k => v i k - v j k))\n (p q : ι → ι) (Tp Tq : Finset ι) (hp : ∀ i, p i ∈ Tp) (hq : ∀ i, q i ∈ Tq)\n (r : ℝ) (hr : 0 ≤ r) (hpq : ∀ i, dist (p i) (q i) ≤ r) :\n auxRad n (fun i k => v (p i) k - v (q i) k)\n ≤ r * Real.sqrt (2 * Real.log ((Tp.card : ℝ) * (Tq.card : ℝ)) / n) := by\n classical\n obtain ⟨i₀⟩ := ‹Nonempty ι›\n set P : ι → ι × ι := fun i => (p i, q i) with hPdef\n set A : Finset (ι × ι) := (Tp ×ˢ Tq).filter (fun z => ∃ i, P i = z) with hAdef\n have hPA : ∀ i, P i ∈ A := by\n intro i\n simp only [hAdef, Finset.mem_filter, Finset.mem_product]\n exact ⟨⟨hp i, hq i⟩, ⟨i, rfl⟩⟩\n have hAne : A.Nonempty := ⟨P i₀, hPA i₀⟩\n have hAcard : A.card ≤ Tp.card * Tq.card := by\n calc A.card ≤ (Tp ×ˢ Tq).card := Finset.card_filter_le _ _\n _ = Tp.card * Tq.card := Finset.card_product _ _\n set w : ι × ι → Fin n → ℝ := fun z k => v z.1 k - v z.2 k with hwdef\n have hnorm : ∀ z ∈ A, auxNrm n (w z) ≤ r := by\n intro z hz\n simp only [hAdef, Finset.mem_filter] at hz\n obtain ⟨-, i, hi⟩ := hz\n subst hi\n have h2 := hpq i\n rw [hdist] at h2\n exact h2\n have hle : auxRad n (fun i k => v (p i) k - v (q i) k)\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, A.sup' hAne (fun z => auxT σ (w z)) := by\n unfold auxRad\n refine mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun σ _ => ?_) (by positivity)\n refine ciSup_le fun i => ?_\n exact Finset.le_sup' (fun z => auxT σ (w z)) (hPA i)\n refine hle.trans ?_\n refine (auxMassart hn A hAne w r hr hnorm).trans ?_\n have hApos : (0:ℝ) < (A.card : ℝ) := by\n exact_mod_cast Finset.card_pos.mpr hAne\n have hlogle : Real.log (A.card : ℝ) ≤ Real.log ((Tp.card : ℝ) * (Tq.card : ℝ)) := by\n refine Real.log_le_log hApos ?_\n exact_mod_cast hAcard\n refine mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt ?_) hr\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n exact div_le_div_of_nonneg_right (by linarith) hn'.le\n\n/- ----------- covering numbers ----------- -/\n\nnoncomputable def auxN (ι : Type*) [PseudoMetricSpace ι] (eps : ℝ) : ℕ :=\n (coveringNum eps (Set.univ : Set ι)).untopD 0\n\nlemma auxDudley_eq {ι : Type*} [PseudoMetricSpace ι] (n : ℕ) (eps : ℝ) :\n dudleyIntegrand6_25 (ι := ι) n eps = Real.sqrt (Real.log (auxN ι eps) / n) := rfl\n\nlemma auxExistsNet {ι : Type*} [PseudoMetricSpace ι] (hTB : TotallyBounded (Set.univ : Set ι))\n {eps : ℝ} (heps : 0 < eps) : ∃ t : Finset ι, isENet t eps (Set.univ : Set ι) := by\n rw [Metric.totallyBounded_iff] at hTB\n obtain ⟨s, hsfin, hsub⟩ := hTB eps heps\n refine ⟨hsfin.toFinset, ?_⟩\n intro x hx\n have hx2 := hsub hx\n simp only [Set.mem_iUnion, exists_prop] at hx2 ⊢\n obtain ⟨y, hy, hxy⟩ := hx2\n exact ⟨y, by simpa using hy, Metric.ball_subset_closedBall hxy⟩\n\nlemma auxN_eq {ι : Type*} [PseudoMetricSpace ι] {eps : ℝ} {t0 : Finset ι}\n (ht0 : isENet t0 eps (Set.univ : Set ι)) :\n auxN ι eps = sInf {m : ℕ | ∃ t : Finset ι, isENet t eps (Set.univ : Set ι) ∧ t.card = m} := by\n set Sn : Set ℕ := {m : ℕ | ∃ t : Finset ι, isENet t eps (Set.univ : Set ι) ∧ t.card = m} with hSn\n have hne : Sn.Nonempty := ⟨t0.card, ⟨t0, ht0, rfl⟩⟩\n have hmem : sInf Sn ∈ Sn := Nat.sInf_mem hne\n have hcov : coveringNum eps (Set.univ : Set ι) = ((sInf Sn : ℕ) : WithTop ℕ) := by\n apply le_antisymm\n · apply sInf_le\n obtain ⟨t, ht, htc⟩ := hmem\n exact ⟨t, ht, by rw [htc]⟩\n · refine le_sInf ?_\n rintro N ⟨t, ht, rfl⟩\n have hle : sInf Sn ≤ t.card := Nat.sInf_le ⟨t, ht, rfl⟩\n exact_mod_cast hle\n unfold auxN\n rw [hcov]\n rfl\n\nlemma auxN_le {ι : Type*} [PseudoMetricSpace ι] {eps : ℝ} {t : Finset ι}\n (ht : isENet t eps (Set.univ : Set ι)) : auxN ι eps ≤ t.card := by\n rw [auxN_eq ht]\n exact Nat.sInf_le ⟨t, ht, rfl⟩\n\nlemma auxN_spec {ι : Type*} [PseudoMetricSpace ι] (hTB : TotallyBounded (Set.univ : Set ι))\n {eps : ℝ} (heps : 0 < eps) :\n ∃ t : Finset ι, isENet t eps (Set.univ : Set ι) ∧ t.card = auxN ι eps := by\n obtain ⟨t0, ht0⟩ := auxExistsNet hTB heps\n have hne : {m : ℕ | ∃ t : Finset ι, isENet t eps (Set.univ : Set ι) ∧ t.card = m}.Nonempty :=\n ⟨t0.card, ⟨t0, ht0, rfl⟩⟩\n obtain ⟨t, ht, htc⟩ := Nat.sInf_mem hne\n exact ⟨t, ht, by rw [auxN_eq ht0, htc]⟩\n\nlemma auxN_anti {ι : Type*} [PseudoMetricSpace ι] (hTB : TotallyBounded (Set.univ : Set ι))\n {e1 e2 : ℝ} (h1 : 0 < e1) (h12 : e1 ≤ e2) : auxN ι e2 ≤ auxN ι e1 := by\n obtain ⟨t, ht, htc⟩ := auxN_spec hTB h1\n have ht2 : isENet t e2 (Set.univ : Set ι) := by\n intro x hx\n have h3 := ht hx\n simp only [Set.mem_iUnion, exists_prop] at h3 ⊢\n obtain ⟨y, hy, hxy⟩ := h3\n exact ⟨y, hy, Metric.closedBall_subset_closedBall h12 hxy⟩\n calc auxN ι e2 ≤ t.card := auxN_le ht2\n _ = auxN ι e1 := htc\n\nlemma auxN_pos {ι : Type*} [PseudoMetricSpace ι] [Nonempty ι]\n (hTB : TotallyBounded (Set.univ : Set ι)) {eps : ℝ} (heps : 0 < eps) : 0 < auxN ι eps := by\n obtain ⟨t, ht, htc⟩ := auxN_spec hTB heps\n rw [← htc]\n rcases Finset.eq_empty_or_nonempty t with rfl | h\n · exfalso\n obtain ⟨i⟩ := ‹Nonempty ι›\n have h3 := ht (Set.mem_univ i)\n simp at h3\n · exact Finset.card_pos.mpr h\n\n/- ----------- chaining ----------- -/\n\nlemma auxBddDiff {ι : Type*} [PseudoMetricSpace ι] {n : ℕ} (hn : 1 ≤ n)\n (v : ι → Fin n → ℝ)\n (hdist : ∀ i j : ι, dist i j = auxNrm n (fun k => v i k - v j k))\n (p q : ι → ι) (r : ℝ) (hpq : ∀ i, dist (p i) (q i) ≤ r) (σ : RadSigns n) :\n BddAbove (Set.range fun i => auxT σ ((fun i k => v (p i) k - v (q i) k) i)) := by\n refine auxBddAbove _ r σ (fun i => ?_)\n refine (auxT_le_nrm hn σ _).trans ?_\n rw [← hdist]\n exact hpq i\n\nlemma auxRad_diff_le {ι : Type*} [PseudoMetricSpace ι] [Nonempty ι] {n : ℕ} (hn : 1 ≤ n)\n (v : ι → Fin n → ℝ)\n (hdist : ∀ i j : ι, dist i j = auxNrm n (fun k => v i k - v j k))\n (p q : ι → ι) (r : ℝ) (hpq : ∀ i, dist (p i) (q i) ≤ r) :\n auxRad n (fun i k => v (p i) k - v (q i) k) ≤ r := by\n refine auxRad_le _ r (fun σ i => ?_)\n refine (auxT_le_nrm hn σ _).trans ?_\n rw [← hdist]\n exact hpq i\n\nlemma auxChainCore {ι : Type*} [PseudoMetricSpace ι] [Nonempty ι] {n : ℕ} (hn : 1 ≤ n)\n (v : ι → Fin n → ℝ)\n (hdist : ∀ i j : ι, dist i j = auxNrm n (fun k => v i k - v j k))\n (cen : ℕ → ι → ι) (e : ℕ → ℝ) (he : ∀ ℓ i, dist i (cen ℓ i) ≤ e ℓ)\n (i₀ : ι) (h0 : ∀ i, cen 0 i = i₀) (L : ℕ) :\n auxRad n v ≤ auxRad n (fun i k => v i k - v (cen L i) k)\n + ∑ ℓ ∈ Finset.range L, auxRad n (fun i k => v (cen (ℓ+1) i) k - v (cen ℓ i) k) := by\n induction L with\n | zero =>\n simp only [Finset.range_zero, Finset.sum_empty, add_zero]\n have hb1 : ∀ σ : RadSigns n,\n BddAbove (Set.range fun i => auxT σ ((fun i k => v i k - v (cen 0 i) k) i)) := by\n intro σ\n exact auxBddDiff hn v hdist id (cen 0) (e 0) (fun i => he 0 i) σ\n have hb2 : ∀ σ : RadSigns n,\n BddAbove (Set.range fun i => auxT σ ((fun (i : ι) k => v (cen 0 i) k) i)) := by\n intro σ\n refine auxBddAbove _ (auxT σ (v i₀)) σ (fun i => ?_)\n exact le_of_eq (by rw [h0 i])\n have hsplit := auxRad_add_le (fun i k => v i k - v (cen 0 i) k)\n (fun (i : ι) k => v (cen 0 i) k) hb1 hb2\n have hzero : auxRad n (fun (i : ι) k => v (cen 0 i) k) = 0 := by\n have hfun : (fun (i : ι) (k : Fin n) => v (cen 0 i) k) = (fun (_ : ι) => v i₀) := by\n funext i k; rw [h0 i]\n rw [hfun]\n exact auxRad_const _\n rw [hzero, add_zero] at hsplit\n refine le_trans ?_ hsplit\n apply le_of_eq\n congr 1\n funext i k\n ring\n | succ L ih =>\n rw [Finset.sum_range_succ]\n have hb1 : ∀ σ : RadSigns n,\n BddAbove (Set.range fun i => auxT σ ((fun i k => v i k - v (cen (L+1) i) k) i)) := by\n intro σ\n exact auxBddDiff hn v hdist id (cen (L+1)) (e (L+1)) (fun i => he (L+1) i) σ\n have hb2 : ∀ σ : RadSigns n,\n BddAbove (Set.range fun i => auxT σ ((fun i k => v (cen (L+1) i) k - v (cen L i) k) i)) := by\n intro σ\n refine auxBddDiff hn v hdist (cen (L+1)) (cen L) (e (L+1) + e L) (fun i => ?_) σ\n calc dist (cen (L+1) i) (cen L i) ≤ dist (cen (L+1) i) i + dist i (cen L i) := dist_triangle _ _ _\n _ ≤ e (L+1) + e L := by\n have := he (L+1) i\n rw [dist_comm] at this\n exact add_le_add this (he L i)\n have hsplit := auxRad_add_le (fun i k => v i k - v (cen (L+1) i) k)\n (fun i k => v (cen (L+1) i) k - v (cen L i) k) hb1 hb2\n have hkey : auxRad n (fun i k => v i k - v (cen L i) k)\n ≤ auxRad n (fun i k => v i k - v (cen (L+1) i) k)\n + auxRad n (fun i k => v (cen (L+1) i) k - v (cen L i) k) := by\n refine le_trans ?_ hsplit\n apply le_of_eq\n congr 1\n funext i k\n ring\n linarith [ih]\n\nlemma auxChainBound {ι : Type*} [PseudoMetricSpace ι] [Nonempty ι] {n : ℕ} (hn : 1 ≤ n)\n (v : ι → Fin n → ℝ)\n (hdist : ∀ i j : ι, dist i j = auxNrm n (fun k => v i k - v j k))\n (cen : ℕ → ι → ι) (T : ℕ → Finset ι) (e : ℕ → ℝ)\n (hT : ∀ ℓ i, cen ℓ i ∈ T ℓ)\n (he : ∀ ℓ i, dist i (cen ℓ i) ≤ e ℓ)\n (hepos : ∀ ℓ, 0 ≤ e ℓ)\n (i₀ : ι) (h0 : ∀ i, cen 0 i = i₀) (L : ℕ) :\n auxRad n v ≤ e L + ∑ ℓ ∈ Finset.range L,\n (e ℓ + e (ℓ+1)) *\n Real.sqrt (2 * Real.log (((T (ℓ+1)).card : ℝ) * ((T ℓ).card : ℝ)) / n) := by\n refine (auxChainCore hn v hdist cen e he i₀ h0 L).trans ?_\n refine add_le_add ?_ (Finset.sum_le_sum fun ℓ _ => ?_)\n · exact auxRad_diff_le hn v hdist id (cen L) (e L) (fun i => he L i)\n · have hd : ∀ i, dist (cen (ℓ+1) i) (cen ℓ i) ≤ e ℓ + e (ℓ+1) := by\n intro i\n calc dist (cen (ℓ+1) i) (cen ℓ i) ≤ dist (cen (ℓ+1) i) i + dist i (cen ℓ i) := dist_triangle _ _ _\n _ ≤ e (ℓ+1) + e ℓ := by\n have h5 := he (ℓ+1) i\n rw [dist_comm] at h5\n exact add_le_add h5 (he ℓ i)\n _ = e ℓ + e (ℓ+1) := by ring\n exact auxLevel hn v hdist (cen (ℓ+1)) (cen ℓ) (T (ℓ+1)) (T ℓ) (hT (ℓ+1)) (hT ℓ)\n (e ℓ + e (ℓ+1)) (by linarith [hepos ℓ, hepos (ℓ+1)]) hd\n\n/- ----------- integral facts ----------- -/\n\nlemma auxDudley_nonneg {ι : Type*} [PseudoMetricSpace ι] (n : ℕ) (x : ℝ) :\n 0 ≤ dudleyIntegrand6_25 (ι := ι) n x := Real.sqrt_nonneg _\n\nlemma auxIntNonneg {ι : Type*} [PseudoMetricSpace ι] (n : ℕ) (s : Set ℝ) :\n 0 ≤ ∫ x in s, dudleyIntegrand6_25 (ι := ι) n x :=\n MeasureTheory.setIntegral_nonneg_of_ae_restrict\n (Filter.Eventually.of_forall (fun x => auxDudley_nonneg n x))\n\nlemma auxIntSplit {ι : Type*} [PseudoMetricSpace ι] {n : ℕ}\n (hInt : ∀ eps ∈ Set.Ici (0:ℝ),\n IntegrableOn (fun eps' => dudleyIntegrand6_25 (ι := ι) n eps') (Set.Ioi eps))\n {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) :\n ∫ x in Set.Ioi a, dudleyIntegrand6_25 (ι := ι) n x\n = (∫ x in Set.Ioc a b, dudleyIntegrand6_25 (ι := ι) n x)\n + ∫ x in Set.Ioi b, dudleyIntegrand6_25 (ι := ι) n x := by\n have hIa := hInt a ha\n have h1 : Set.Ioc a b ∪ Set.Ioi b = Set.Ioi a := Set.Ioc_union_Ioi_eq_Ioi hab\n have hdisj : Disjoint (Set.Ioc a b) (Set.Ioi b) := by\n rw [Set.disjoint_left]\n intro x hx hx2\n exact absurd hx.2 (not_le.mpr hx2)\n calc ∫ x in Set.Ioi a, dudleyIntegrand6_25 (ι := ι) n x\n = ∫ x in Set.Ioc a b ∪ Set.Ioi b, dudleyIntegrand6_25 (ι := ι) n x := by rw [h1]\n _ = _ := MeasureTheory.setIntegral_union hdisj measurableSet_Ioi\n (hIa.mono_set (by rw [← h1]; exact Set.subset_union_left))\n (hIa.mono_set (by rw [← h1]; exact Set.subset_union_right))\n\nlemma auxIntMonoSet {ι : Type*} [PseudoMetricSpace ι] {n : ℕ}\n (hInt : ∀ eps ∈ Set.Ici (0:ℝ),\n IntegrableOn (fun eps' => dudleyIntegrand6_25 (ι := ι) n eps') (Set.Ioi eps))\n {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) :\n (∫ x in Set.Ioi b, dudleyIntegrand6_25 (ι := ι) n x)\n ≤ ∫ x in Set.Ioi a, dudleyIntegrand6_25 (ι := ι) n x := by\n rw [auxIntSplit hInt ha hab]\n linarith [auxIntNonneg (ι := ι) n (Set.Ioc a b)]\n\nlemma auxIntLower {ι : Type*} [PseudoMetricSpace ι] {n : ℕ}\n (hInt : ∀ eps ∈ Set.Ici (0:ℝ),\n IntegrableOn (fun eps' => dudleyIntegrand6_25 (ι := ι) n eps') (Set.Ioi eps))\n {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (c : ℝ)\n (hc : ∀ x ∈ Set.Ioc a b, c ≤ dudleyIntegrand6_25 (ι := ι) n x) :\n c * (b - a) ≤ ∫ x in Set.Ioc a b, dudleyIntegrand6_25 (ι := ι) n x := by\n have hIa := hInt a ha\n have hsub : IntegrableOn (fun x => dudleyIntegrand6_25 (ι := ι) n x) (Set.Ioc a b) :=\n hIa.mono_set Set.Ioc_subset_Ioi_self\n have hfin := MeasureTheory.setIntegral_ge_of_const_le_real (μ := volume) measurableSet_Ioc\n (by rw [Real.volume_Ioc]; exact ENNReal.ofReal_ne_top) hc hsub\n rwa [Real.volume_real_Ioc_of_le hab] at hfin\n\n/- ----------- main estimate ----------- -/\n\nlemma auxMainPos {ι : Type*} [PseudoMetricSpace ι] [Nonempty ι] {n : ℕ} (hn : 1 ≤ n)\n (v : ι → Fin n → ℝ)\n (hdist : ∀ i j : ι, dist i j = auxNrm n (fun k => v i k - v j k))\n (hTB : TotallyBounded (Set.univ : Set ι))\n (hBdd : BddAbove (Set.range (fun i : ι => auxNrm n (v i))))\n (hInt : ∀ eps ∈ Set.Ici (0 : ℝ),\n IntegrableOn (fun eps' => dudleyIntegrand6_25 (ι := ι) n eps') (Set.Ioi eps))\n (eps : ℝ) (heps : 0 < eps) :\n auxRad n v ≤ 4 * eps + 12 * ∫ x in Set.Ioi eps, dudleyIntegrand6_25 (ι := ι) n x := by\n classical\n obtain ⟨i₀⟩ := ‹Nonempty ι›\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n set B : ℝ := sSup (Set.range (fun i : ι => auxNrm n (v i))) with hBdef\n have hvB : ∀ i, auxNrm n (v i) ≤ B := fun i => le_csSup hBdd ⟨i, rfl⟩\n have hB0 : (0:ℝ) ≤ B := le_trans (auxNrm_nonneg n (v i₀)) (hvB i₀)\n have hRadB : auxRad n v ≤ B := auxRad_le v B (fun σ i => (auxT_le_nrm hn σ (v i)).trans (hvB i))\n have hIeps : (0:ℝ) ≤ ∫ x in Set.Ioi eps, dudleyIntegrand6_25 (ι := ι) n x := auxIntNonneg n _\n rcases le_or_lt B (4 * eps) with hcase | hcase\n · linarith\n have hBpos : (0:ℝ) < B := by linarith\n set e : ℕ → ℝ := fun l => 2 * B / 2 ^ l with hedef\n have hepos : ∀ l, 0 < e l := by\n intro l\n simp only [hedef]\n exact div_pos (by linarith) (by positivity)\n have hehalf : ∀ l, e (l + 1) = e l / 2 := by\n intro l\n simp only [hedef, pow_succ]\n ring\n have heanti : ∀ l, e (l + 1) ≤ e l := by\n intro l\n rw [hehalf l]\n linarith [hepos l]\n have hnetex : ∀ l : ℕ, ∃ t : Finset ι, ∃ c : ι → ι,\n (∀ i, c i ∈ t) ∧ (∀ i, dist i (c i) ≤ e (l + 1)) ∧ t.card = auxN ι (e (l + 1)) := by\n intro l\n obtain ⟨t, ht, htc⟩ := auxN_spec hTB (hepos (l + 1))\n have hc : ∀ i : ι, ∃ x, x ∈ t ∧ dist i x ≤ e (l + 1) := by\n intro i\n have h5 := ht (Set.mem_univ i)\n simp only [Set.mem_iUnion, exists_prop, Metric.mem_closedBall] at h5\n exact h5\n choose c hc1 hc2 using hc\n exact ⟨t, c, hc1, hc2, htc⟩\n choose T0 cen0 hT01 hT02 hT03 using hnetex\n obtain ⟨TT, cc, hccmem, hccdist, hcc0, hTTcard, hTT0card⟩ :\n ∃ (TT : ℕ → Finset ι) (cc : ℕ → ι → ι),\n (∀ l i, cc l i ∈ TT l) ∧ (∀ l i, dist i (cc l i) ≤ e l) ∧ (∀ i, cc 0 i = i₀) ∧\n (∀ l, (TT (l + 1)).card = auxN ι (e (l + 1))) ∧ (TT 0).card = 1 := by\n refine ⟨fun l => Nat.casesOn l ({i₀} : Finset ι) (fun m => T0 m),\n fun l => Nat.casesOn l (fun _ : ι => i₀) (fun m => cen0 m), ?_, ?_, ?_, ?_, ?_⟩\n · intro l i\n cases l with\n | zero => exact Finset.mem_singleton_self i₀\n | succ m => exact hT01 m i\n · intro l i\n cases l with\n | zero =>\n show dist i i₀ ≤ e 0\n rw [hdist i i₀]\n have htri := auxNrm_sub_le hn (v i) (v i₀)\n have h2 : e 0 = 2 * B := by simp [hedef]\n rw [h2]\n linarith [hvB i, hvB i₀]\n | succ m => exact hT02 m i\n · intro i; rfl\n · intro l; exact hT03 l\n · exact Finset.card_singleton i₀\n have hNpos : ∀ l : ℕ, 0 < (TT l).card := by\n intro l\n cases l with\n | zero => rw [hTT0card]; norm_num\n | succ m => rw [hTTcard m]; exact auxN_pos hTB (hepos (m + 1))\n have hNle : ∀ l : ℕ, (TT l).card ≤ (TT (l + 1)).card := by\n intro l\n cases l with\n | zero =>\n rw [hTT0card, hTTcard 0]\n exact auxN_pos hTB (hepos 1)\n | succ m =>\n rw [hTTcard m, hTTcard (m + 1)]\n exact auxN_anti hTB (hepos (m + 2)) (heanti (m + 1))\n have hchain := fun L => auxChainBound hn v hdist cc TT e hccmem hccdist\n (fun l => (hepos l).le) i₀ hcc0 L\n have hterm : ∀ l : ℕ,\n (e l + e (l + 1)) *\n Real.sqrt (2 * Real.log (((TT (l + 1)).card : ℝ) * ((TT l).card : ℝ)) / n)\n ≤ 12 * ((∫ x in Set.Ioi (e (l + 1 + 1)), dudleyIntegrand6_25 (ι := ι) n x)\n - ∫ x in Set.Ioi (e (l + 1)), dudleyIntegrand6_25 (ι := ι) n x) := by\n intro l\n have hN1pos : (0:ℝ) < ((TT (l + 1)).card : ℝ) := by exact_mod_cast hNpos (l + 1)\n have hN0pos : (0:ℝ) < ((TT l).card : ℝ) := by exact_mod_cast hNpos l\n have hN01 : ((TT l).card : ℝ) ≤ ((TT (l + 1)).card : ℝ) := by exact_mod_cast hNle l\n have hlogle : Real.log (((TT (l + 1)).card : ℝ) * ((TT l).card : ℝ))\n ≤ 2 * Real.log ((TT (l + 1)).card : ℝ) := by\n rw [Real.log_mul (ne_of_gt hN1pos) (ne_of_gt hN0pos)]\n have := Real.log_le_log hN0pos hN01\n linarith\n have hDeq : dudleyIntegrand6_25 (ι := ι) n (e (l + 1))\n = Real.sqrt (Real.log ((TT (l + 1)).card : ℝ) / n) := by\n rw [auxDudley_eq, hTTcard l]\n have hDnn : 0 ≤ dudleyIntegrand6_25 (ι := ι) n (e (l + 1)) := auxDudley_nonneg n _\n have hstep1 : Real.sqrt (2 * Real.log (((TT (l + 1)).card : ℝ) * ((TT l).card : ℝ)) / n)\n ≤ 2 * dudleyIntegrand6_25 (ι := ι) n (e (l + 1)) := by\n have h1 : 2 * Real.log (((TT (l + 1)).card : ℝ) * ((TT l).card : ℝ)) / n\n ≤ 4 * (Real.log ((TT (l + 1)).card : ℝ) / n) := by\n rw [mul_div_assoc']\n exact div_le_div_of_nonneg_right (by linarith) hn'.le\n have hsq4 : Real.sqrt 4 = 2 := by\n rw [show (4:ℝ) = 2 ^ 2 by norm_num, Real.sqrt_sq (by norm_num)]\n calc Real.sqrt (2 * Real.log (((TT (l + 1)).card : ℝ) * ((TT l).card : ℝ)) / n)\n ≤ Real.sqrt (4 * (Real.log ((TT (l + 1)).card : ℝ) / n)) := Real.sqrt_le_sqrt h1\n _ = 2 * Real.sqrt (Real.log ((TT (l + 1)).card : ℝ) / n) := by\n rw [Real.sqrt_mul (by norm_num), hsq4]\n _ = 2 * dudleyIntegrand6_25 (ι := ��) n (e (l + 1)) := by rw [hDeq]\n have hcoef : e l + e (l + 1) = 6 * (e (l + 1) - e (l + 1 + 1)) := by\n have h1 := hehalf l\n have h2 := hehalf (l + 1)\n rw [h2, h1]; ring\n have hgap : e (l + 1 + 1) ≤ e (l + 1) := heanti (l + 1)\n have hint : dudleyIntegrand6_25 (ι := ι) n (e (l + 1)) * (e (l + 1) - e (l + 1 + 1))\n ≤ ∫ x in Set.Ioc (e (l + 1 + 1)) (e (l + 1)), dudleyIntegrand6_25 (ι := ι) n x := by\n refine auxIntLower hInt (hepos (l + 1 + 1)).le hgap _ ?_\n intro x hx\n have hxpos : 0 < x := lt_trans (hepos (l + 1 + 1)) hx.1\n have hNx : auxN ι (e (l + 1)) ≤ auxN ι x := auxN_anti hTB hxpos hx.2\n rw [hDeq, auxDudley_eq]\n refine Real.sqrt_le_sqrt ?_\n refine div_le_div_of_nonneg_right ?_ hn'.le\n rw [hTTcard l]\n refine Real.log_le_log ?_ ?_\n · exact_mod_cast auxN_pos hTB (hepos (l + 1))\n · exact_mod_cast hNx\n have hsplit := auxIntSplit (ι := ι) (n := n) hInt (hepos (l + 1 + 1)).le hgap\n rw [hcoef]\n calc 6 * (e (l + 1) - e (l + 1 + 1)) *\n Real.sqrt (2 * Real.log (((TT (l + 1)).card : ℝ) * ((TT l).card : ℝ)) / n)\n ≤ 6 * (e (l + 1) - e (l + 1 + 1)) * (2 * dudleyIntegrand6_25 (ι := ι) n (e (l + 1))) := by\n refine mul_le_mul_of_nonneg_left hstep1 ?_\n have : 0 ≤ e (l + 1) - e (l + 1 + 1) := by linarith\n linarith\n _ = 12 * (dudleyIntegrand6_25 (ι := ι) n (e (l + 1)) * (e (l + 1) - e (l + 1 + 1))) := by\n ring\n _ ≤ 12 * (∫ x in Set.Ioc (e (l + 1 + 1)) (e (l + 1)),\n dudleyIntegrand6_25 (ι := ι) n x) := by linarith\n _ = 12 * ((∫ x in Set.Ioi (e (l + 1 + 1)), dudleyIntegrand6_25 (ι := ι) n x)\n - ∫ x in Set.Ioi (e (l + 1)), dudleyIntegrand6_25 (ι := ι) n x) := by\n rw [hsplit]; ring\n have hsum : ∀ L : ℕ, auxRad n v ≤ e L\n + 12 * ((∫ x in Set.Ioi (e (L + 1)), dudleyIntegrand6_25 (ι := ι) n x)\n - ∫ x in Set.Ioi (e (0 + 1)), dudleyIntegrand6_25 (ι := ι) n x) := by\n intro L\n refine (hchain L).trans ?_\n refine add_le_add le_rfl ?_\n calc ∑ l ∈ Finset.range L, (e l + e (l + 1)) *\n Real.sqrt (2 * Real.log (((TT (l + 1)).card : ℝ) * ((TT l).card : ℝ)) / n)\n ≤ ∑ l ∈ Finset.range L, 12 * ((∫ x in Set.Ioi (e (l + 1 + 1)),\n dudleyIntegrand6_25 (ι := ι) n x)\n - ∫ x in Set.Ioi (e (l + 1)), dudleyIntegrand6_25 (ι := ι) n x) :=\n Finset.sum_le_sum (fun l _ => hterm l)\n _ = 12 * ∑ l ∈ Finset.range L, ((∫ x in Set.Ioi (e (l + 1 + 1)),\n dudleyIntegrand6_25 (ι := ι) n x)\n - ∫ x in Set.Ioi (e (l + 1)), dudleyIntegrand6_25 (ι := ι) n x) := by\n rw [Finset.mul_sum]\n _ = 12 * ((∫ x in Set.Ioi (e (L + 1)), dudleyIntegrand6_25 (ι := ι) n x)\n - ∫ x in Set.Ioi (e (0 + 1)), dudleyIntegrand6_25 (ι := ι) n x) := by\n rw [Finset.sum_range_sub\n (fun l => ∫ x in Set.Ioi (e (l + 1)), dudleyIntegrand6_25 (ι := ι) n x)]\n have hexL : ∃ L : ℕ, e (L + 2) ≤ eps := by\n obtain ⟨m, hm⟩ := pow_unbounded_of_one_lt (B / (2 * eps)) (by norm_num : (1:ℝ) < 2)\n refine ⟨m, ?_⟩\n have he2 : e (m + 2) = B / (2 * 2 ^ m) := by\n simp only [hedef, pow_add]\n ring\n rw [he2, div_le_iff₀ (by positivity)]\n rw [div_lt_iff₀ (by positivity)] at hm\n nlinarith [hm]\n set L := Nat.find hexL with hLdef\n have hLspec : e (L + 2) ≤ eps := Nat.find_spec hexL\n have hLne : L ≠ 0 := by\n intro h0\n rw [h0] at hLspec\n have h2 : e 2 = B / 2 := by\n simp only [hedef]\n ring\n rw [show (0:ℕ) + 2 = 2 from rfl] at hLspec\n rw [h2] at hLspec\n linarith\n obtain ⟨M, hM⟩ : ∃ M, L = M + 1 := ⟨L - 1, by omega⟩\n have hmin : ¬ (e (M + 2) ≤ eps) := by\n rw [hLdef] at hM\n exact Nat.find_min hexL (by omega)\n have hepsle : eps ≤ e (M + 2) := le_of_lt (not_le.mp hmin)\n have hcombine := hsum L\n have hI0 : (0:ℝ) ≤ ∫ x in Set.Ioi (e (0 + 1)), dudleyIntegrand6_25 (ι := ι) n x :=\n auxIntNonneg n _\n have hmono : (∫ x in Set.Ioi (e (L + 1)), dudleyIntegrand6_25 (ι := ι) n x)\n ≤ ∫ x in Set.Ioi eps, dudleyIntegrand6_25 (ι := ι) n x := by\n refine auxIntMonoSet hInt heps.le ?_\n rw [hM]\n exact hepsle\n have heL : e L ≤ 4 * eps := by\n have h1 : e (L + 2) = e L / 4 := by\n have a1 := hehalf L\n have a2 := hehalf (L + 1)\n rw [show L + 2 = L + 1 + 1 from rfl, a2, a1]\n ring\n rw [h1] at hLspec\n linarith\n linarith\ntheorem ch6_theorem_6_25\n {ι : Type*} {𝒳 : Type*} [PseudoMetricSpace ι]\n (n : ℕ) (hn : 1 ≤ n)\n (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳)\n (hdist : ∀ i j : ι,\n dist i j = Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, (f i (S k) - f j (S k)) ^ 2))\n (hTB : TotallyBounded (Set.univ : Set ι))\n (hBdd : BddAbove (Set.range (fun i : ι =>\n Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, (f i (S k)) ^ 2))))\n (hInt : ∀ eps ∈ Set.Ici (0 : ℝ),\n IntegrableOn (fun eps' => dudleyIntegrand6_25 (ι := ι) n eps') (Set.Ioi eps)) :\n empRadSigned n f S\n ≤ ⨅ eps : Set.Ici (0 : ℝ),\n (4 * (eps : ℝ)\n + 12 * ∫ eps' in Set.Ioi (eps : ℝ), dudleyIntegrand6_25 (ι := ι) n eps') := by\n classical\n haveI : Nonempty (Set.Ici (0:ℝ)) := ⟨⟨0, Set.left_mem_Ici⟩⟩\n have hnn : ∀ epsx : Set.Ici (0:ℝ), (0:ℝ) ≤ 4 * (epsx : ℝ)\n + 12 * ∫ x in Set.Ioi (epsx : ℝ), dudleyIntegrand6_25 (ι := ι) n x := by\n intro epsx\n have h1 : (0:ℝ) ≤ (epsx : ℝ) := epsx.2\n have h2 := auxIntNonneg (ι := ι) n (Set.Ioi (epsx : ℝ))\n linarith\n rcases isEmpty_or_nonempty ι with hemp | hne\n · haveI := hemp\n have hlhs : empRadSigned n f S = 0 := by\n unfold empRadSigned\n have hz : ∀ σ : RadSigns n,\n (⨆ i : ι, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)) = 0 :=\n fun σ => Real.iSup_of_isEmpty _\n simp only [hz]\n simp\n rw [hlhs]\n exact le_ciInf (fun epsx => hnn epsx)\n · refine le_ciInf (fun epsx => ?_)\n have hep0 : (0:ℝ) ≤ (epsx : ℝ) := epsx.2\n rw [empRad_eq]\n rcases eq_or_lt_of_le hep0 with hz | hpos\n · have hep : (epsx : ℝ) = 0 := hz.symm\n rw [hep]\n have hkey : auxRad n (fun i k => f i (S k))\n ≤ 12 * ∫ x in Set.Ioi (0:ℝ), dudleyIntegrand6_25 (ι := ι) n x := by\n refine aux_le_of_forall_pos (fun ε hε => ?_)\n have h1 := auxMainPos hn (fun i k => f i (S k)) hdist hTB hBdd hInt (ε / 4)\n (by linarith)\n have h2 : (∫ x in Set.Ioi (ε / 4), dudleyIntegrand6_25 (ι := ι) n x)\n ≤ ∫ x in Set.Ioi (0:ℝ), dudleyIntegrand6_25 (ι := ι) n x :=\n auxIntMonoSet hInt le_rfl (by linarith)\n have h3 : 4 * (ε / 4) = ε := by ring\n linarith\n linarith\n · exact auxMainPos hn (fun i k => f i (S k)) hdist hTB hBdd hInt (epsx : ℝ) hpos\n\nend GraduateLevel\n"} +{"id": "ch8_theorem_8_9", "source": "Graduate-level", "targets": [{"label": "ch8_theorem_8_9", "decls": ["ch8_theorem_8_9"], "statement": "Consider \\( h \\) with decomposition 6.3 as \\( h(f,z) = h_0(f) + h_1(f,z) \\). Assume that for some \\( M \\geq 0 \\):\n\\[\n\\sup_{f\\in\\mathcal{F}}\\sup_{z,z^{\\prime}}[|\\phi(f,z)-\\phi(f,z^{\\prime})| + |h_{1}(f,z)-h_{1}(f,z^{\\prime})|]\\leq M.\n\\]\nWe have with probability at least \\(1 - \\delta\\)\n\\[\nR_{n}^{h}(\\mathcal{F},\\mathcal{D})\\leq R^{h}(\\mathcal{F},\\mathcal{S}_{n})+M\\sqrt{\\frac{\\ln(1/\\delta)}{2 n}}.\n\\]\nSimilarly, with probability at least \\(1 - \\delta\\), we have\n\\[\nR_{n}^{h}(\\mathcal{F},\\mathcal{D})\\geq R^{h}(\\mathcal{F},\\mathcal{S}_{n})-M\\sqrt{\\frac{\\ln(1/\\delta)}{2 n}}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Let \\( S_{n}=\\{Z_{1},\\ldots,Z_{n}\\} \\) and \\( S_{n}^{\\prime}=\\{Z_{1}^{\\prime},\\dots,Z_{n}^{\\prime}\\} \\), where \\( Z_{i} = Z_{i}^{\\prime} \\) except at a single index \\( k \\). For any \\( \\sigma \\), we assume the sup of the following can be achieved at\n\\[\n\\hat{f}(\\sigma,\\mathcal{S}_{n})=\\arg\\max_{f\\in\\mathcal{F}}\\left[\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}[\\phi(f,Z_{i})+0. 5h_{1}(f,Z_{i})]-0. 5h(f,\\mathcal{S}_{n})\\right].\n\\]\nLet\n\\[\n\\phi^{\\prime}(f,Z)=\\phi(f,Z)+0. 5h_{1}(f,Z).\n\\]\nIt follows that\n\\[\n\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}\\phi^{\\prime}(\\hat{f},Z_{i}^{\\prime})-0. 5h(\\hat{f},\\mathcal{S}_{n}^{\\prime})\\leq\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}\\phi(\\hat{f}^{\\prime},Z_{i}^{\\prime})-0. 5h(\\hat{f}^{\\prime},\\mathcal{S}_{n}^{\\prime}),\\tag{8.4}\n\\]\nwhere \\(\\hat{f}\\) is the short for \\(\\hat{f}(\\sigma, S_n)\\), and \\(\\hat{f}'\\) is the short for \\(\\hat{f}(\\sigma, S_n')\\). Therefore\n\\[\n\\begin{array}{l}R^{h}(\\mathcal{F},\\mathcal{S}_{n})-R^{h}(\\mathcal{F},\\mathcal{S}_{n}^{\\prime})\\\\ =\\mathbb{E}_{\\sigma}\\left[\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}\\phi^{\\prime}(\\hat{f},Z_{i})-\\frac{1}{2}h(\\hat{f},\\mathcal{S}_{n})-\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}\\phi^{\\prime}(\\hat{f}^{\\prime},Z_{i}^{\\prime})+\\frac{1}{2}h(\\hat{f}^{\\prime},\\mathcal{S}_{n}^{\\prime})\\right]\\\\ \\leq\\mathbb{E}_{\\sigma}\\left[\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}\\phi^{\\prime}(\\hat{f},Z_{i})-\\frac{1}{2}h(\\hat{f},\\mathcal{S}_{n})-\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}\\phi^{\\prime}(\\hat{f},Z_{i}^{\\prime})+\\frac{1}{2}h(\\hat{f},\\mathcal{S}_{n}^{\\prime})\\right]\\\\ =\\mathbb{E}_{\\sigma}\\left[\\frac{1}{n}\\sigma_{k}\\phi^{\\prime}(\\hat{f},Z_{k})-\\frac{1}{n}\\sigma_{k}\\phi^{\\prime}(\\hat{f},Z_{k}^{\\prime})+\\frac{1}{2 n}h_{1}(\\hat{f},Z_{k}^{\\prime})-\\frac{1}{2 n}h_{1}(\\hat{f},Z_{k})\\right]\\\\ \\leq M/n.\\\\ \\end{array}\n\\]\nThe first inequality used (8.4). Similarly, we have \\( R^{h}(\\mathcal{F},\\mathcal{S}_{n}^{\\prime}) - R^{h}(\\mathcal{F},\\mathcal{S}_{n})\\leq M / n \\). This implies that \\( |R^{h}(\\mathcal{F},\\mathcal{S}_{n}) - R^{h}(\\mathcal{F},\\mathcal{S}_{n}^{\\prime})|\\leq M / n \\). The desired bound is a direct consequence of McDiarmid's inequality.", "context": [{"id": "ch6:theorem:6_16", "name": "McDiarmid's Inequality", "statement": "Consider \\( n \\) independent random variables \\( X_{1},\\ldots,X_{n} \\), and a real-valued function \\( f(X_{1},\\ldots,X_{n}) \\) that satisfies the following inequality\n\\[\n\\sup_{x_{1},\\dots,x_{n},x_{i}^{\\prime}}|f(x_{1},\\dots,x_{n})-f(x_{1},\\dots,x_{i-1},x_{i}^{\\prime},x_{i+1},\\dots,x_{n})|\\leq c_{i}\n\\]\nfor all \\(1 \\leq i \\leq n\\). Then for all \\(\\epsilon > 0\\):\n\\[\n\\Pr\\left[f\\left(X_{1},\\dots,X_{n}\\right)\\geq\\mathbb{E}f\\left(X_{1},\\dots,X_{n}\\right)+\\epsilon\\right]\\leq\\exp\\left(\\frac{-2\\epsilon^{2}}{\\sum_{i=1}^{n}c_{i}^{2}}\\right).\n\\]\nSimilarly:\n\\[\n\\Pr\\left[f\\left(X_{1},\\dots,X_{n}\\right)\\leq\\mathbb{E}f\\left(X_{1},\\dots,X_{n}\\right)-\\epsilon\\right]\\leq\\exp\\left(\\frac{-2\\epsilon^{2}}{\\sum_{i=1}^{n}c_{i}^{2}}\\right).\n\\]"}, {"id": "ch6:definition:6_11", "name": "definition 6.11", "statement": "Consider a function class \\(\\mathcal{G} = \\{\\phi(w, Z) : w \\in \\Omega\\}\\), and let \\(h\\) be an offset function of the following form\n\\[\nh(w,\\mathcal{S}_{n})=\\frac{1}{n}\\sum_{i=1}^{n}h(w,Z_{i}),\\quad h(w,z)=h_{0}(w)+h_{1}(w,z).\\tag{6.3}\n\\]\nGiven \\( S_{n}=\\{Z_{1},\\ldots,Z_{n}\\} \\), the (one-sided) empirical Rademacher complexity of \\( \\mathcal{G} \\) with offset \\( h \\) decomposition (6.3) is defined as\n\\[\nR^{h}(\\mathcal{G},\\mathcal{S}_{n})=\\mathbb{E}_{\\sigma}\\sup_{w\\in\\Omega}\\left[\\frac{1}{n}\\sum_{i=1}^{n}\\sigma_{i}[\\phi(w,Z_{i})+0. 5h_{1}(w,Z_{i})]-0. 5h(w,\\mathcal{S}_{n})\\right],\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}^{h}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R^{h}(\\mathcal{G},\\mathcal{S}_{n}).\n\\]\nWe note that the standard Rademacher complexity can be regarded as a special case of the offset Rademacher complexity with \\( h(\\cdot) = h_0(\\cdot) = h_1(\\cdot) = 0 \\):\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n})=R^{0}(\\mathcal{G},\\mathcal{S}_{n}),\\quad R_{n}(\\mathcal{G},\\mathcal{D})=R_{n}^{0}(\\mathcal{G},\\mathcal{D}).\n\\]\nIt should be pointed out that the decomposition of \\( h \\) in (6.3) may not be unique, and the offset Rademacher complexity relies on the specific decomposition used.\nAs shown in Example 6.10, we allow distribution dependent offset in the definition of uniform convergence complexity. We also allow distribution dependent offset in the definition of offset Rademacher complexity."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped BigOperators\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def offsetH {F : Type*} {𝒵 : Type*} {n : ℕ}\n (h0 : F → ℝ) (h1 : F → 𝒵 → ℝ) (f : F) (s : Fin n → 𝒵) : ℝ :=\n h0 f + (n : ℝ)⁻¹ * ∑ i : Fin n, h1 f (s i)\n\nnoncomputable def offsetEmpRC {F : Type*} {𝒵 : Type*} (n : ℕ)\n (φ : F → 𝒵 → ℝ) (h0 : F → ℝ) (h1 : F → 𝒵 → ℝ) (s : Fin n → 𝒵) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ f : F,\n ( (n : ℝ)⁻¹ * ∑ i : Fin n, (σ i : ℝ) * (φ f (s i) + (1/2) * h1 f (s i))\n - (1/2) * offsetH h0 h1 f s )\n\ntheorem ch8_theorem_8_9\n {F : Type*} [Nonempty F]\n {𝒵 : Type*} [MeasurableSpace 𝒵] [Nonempty 𝒵]\n {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n {n : ℕ} (hn : 0 < n)\n (Z : Fin n → Ω → 𝒵)\n (hZmeas : ∀ i, Measurable (Z i))\n (hZindep : ProbabilityTheory.iIndepFun Z μ)\n (hZident : ∀ i j, Measure.map (Z i) μ = Measure.map (Z j) μ)\n (φ : F → 𝒵 → ℝ) (h0 : F → ℝ) (h1 : F → 𝒵 → ℝ)\n\n (hBdd : ∀ (s : Fin n → 𝒵) (σ : RadSigns n),\n BddAbove (Set.range (fun f : F =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (σ i : ℝ) * (φ f (s i) + (1/2) * h1 f (s i))\n - (1/2) * offsetH h0 h1 f s)))\n\n (hRmeas : Measurable (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s))\n\n (hRint : Integrable (fun x => offsetEmpRC n φ h0 h1 (fun i => Z i x)) μ)\n (M : ℝ) (hM : 0 ≤ M)\n\n (hSens : ∀ (f : F) (z z' : 𝒵),\n |φ f z - φ f z'| + |h1 f z - h1 f z'| ≤ M)\n {δ : ℝ} (hδ0 : 0 < δ) (hδ1 : δ ≤ 1) :\n\n ( 1 - δ ≤\n (μ {ω |\n (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i ω)\n ≥ (∫ x, (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i x) ∂μ)\n - M * Real.sqrt (Real.log (1/δ) / (2 * n)) }).toReal )\n ∧\n ( 1 - δ ≤\n (μ {ω |\n (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i ω)\n ≤ (∫ x, (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i x) ∂μ)\n + M * Real.sqrt (Real.log (1/δ) / (2 * n)) }).toReal ) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped BigOperators\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def offsetH {F : Type*} {𝒵 : Type*} {n : ℕ}\n (h0 : F → ℝ) (h1 : F → 𝒵 → ℝ) (f : F) (s : Fin n → 𝒵) : ℝ :=\n h0 f + (n : ℝ)⁻¹ * ∑ i : Fin n, h1 f (s i)\n\nnoncomputable def offsetEmpRC {F : Type*} {𝒵 : Type*} (n : ℕ)\n (φ : F → 𝒵 → ℝ) (h0 : F → ℝ) (h1 : F → 𝒵 → ℝ) (s : Fin n → 𝒵) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n ⨆ f : F,\n ( (n : ℝ)⁻¹ * ∑ i : Fin n, (σ i : ℝ) * (φ f (s i) + (1/2) * h1 f (s i))\n - (1/2) * offsetH h0 h1 f s )\n\nnamespace McD\nvariable {𝒵 : Type*} [MeasurableSpace 𝒵] [Nonempty 𝒵]\n\nlemma intg_of_bdd {α : Type*} [MeasurableSpace α] {m : Measure α} [IsFiniteMeasure m] {f : α → ℝ}\n (hf : Measurable f) {C : ℝ} (h : ∀ x, |f x| ≤ C) : Integrable f m :=\n Integrable.of_bound hf.aestronglyMeasurable C\n (Filter.Eventually.of_forall (fun x => by simpa [Real.norm_eq_abs] using h x))\n\nlemma meas_cons {n : ℕ} {F : (Fin (n+1) → 𝒵) → ℝ} (hF : Measurable F) :\n Measurable (fun p : 𝒵 × (Fin n → 𝒵) => F (Fin.cons p.1 p.2)) := by\n apply hF.comp\n apply measurable_pi_lambda\n intro i\n refine Fin.cases ?_ ?_ i\n · simpa using measurable_fst\n · intro j; simpa using (measurable_pi_apply j).comp measurable_snd\n\nlemma pi_succ_integral {n : ℕ} (ν : Fin (n+1) → Measure 𝒵) [∀ i, IsProbabilityMeasure (ν i)]\n (F : (Fin (n+1) → 𝒵) → ℝ) (hF : Measurable F) (C : ℝ) (hC : ∀ s, |F s| ≤ C) :\n ∫ s, F s ∂(Measure.pi ν)\n = ∫ z, (∫ s', F (Fin.cons z s') ∂(Measure.pi fun j : Fin n => ν j.succ)) ∂(ν 0) := by\n rw [← ((measurePreserving_piFinSuccAbove ν 0).symm).integral_comp' F]\n simp_rw [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, Fin.insertNth_zero,\n Equiv.coe_fn_mk, Fin.zero_succAbove, cast_eq]\n rw [integral_prod]\n exact intg_of_bdd (meas_cons hF) (C := C) (fun p => hC _)\n\ndef BD {n : ℕ} (g : (Fin n → 𝒵) → ℝ) (c : Fin n → ℝ) : Prop :=\n ∀ (k : Fin n) (s s' : Fin n → 𝒵), (∀ j, j ≠ k → s j = s' j) → |g s - g s'| ≤ c k\n\ntheorem mgf_bd : ∀ (n : ℕ) (ν : Fin n → Measure 𝒵) (_hν : ∀ i, IsProbabilityMeasure (ν i))\n (g : (Fin n → 𝒵) → ℝ) (_hg : Measurable g) (B : ℝ) (_hB : ∀ s, |g s| ≤ B)\n (c : Fin n → ℝ) (_hc : BD g c) (t : ℝ),\n ∫ s, exp (t * (g s - ∫ s', g s' ∂(Measure.pi ν))) ∂(Measure.pi ν)\n ≤ exp (t ^ 2 * (∑ k, c k ^ 2) / 8) := by\n intro n\n induction n with\n | zero =>\n intro ν hν g hg B hB c hc t\n haveI : ∀ i, IsProbabilityMeasure (ν i) := hν\n have hconst : ∀ s : Fin 0 → 𝒵, g s = g (fun i => i.elim0) := by\n intro s; congr 1; funext i; exact i.elim0\n have h1 : (∫ s', g s' ∂(Measure.pi ν)) = g (fun i => i.elim0) := by simp [hconst]\n simp only [hconst]\n simp\n | succ n ih =>\n intro ν hν g hg B hB c hc t\n haveI : ∀ i, IsProbabilityMeasure (ν i) := hν\n set π' := Measure.pi (fun j : Fin n => ν j.succ) with hπ'\n haveI : IsProbabilityMeasure π' := inferInstance\n set G : 𝒵 → ℝ := fun z => ∫ s', g (Fin.cons z s') ∂π' with hGdef\n have hGmeas : Measurable G :=\n ((meas_cons hg).stronglyMeasurable.integral_prod_right' (ν := π')).measurable\n have hGB : ∀ z, |G z| ≤ B := by\n intro z\n have := norm_integral_le_of_norm_le_const (μ := π')\n (f := fun s' => g (Fin.cons z s')) (C := B)\n (Filter.Eventually.of_forall fun s' => by simpa [Real.norm_eq_abs] using hB _)\n simpa [Real.norm_eq_abs] using this\n have hgz : ∀ z, Measurable (fun s' : Fin n → 𝒵 => g (Fin.cons z s')) := by\n intro z; exact (meas_cons hg).comp (measurable_const.prodMk measurable_id)\n have hGBD : ∀ z z' : 𝒵, |G z - G z'| ≤ c 0 := by\n intro z z'\n have hsub : G z - G z' = ∫ s', (g (Fin.cons z s') - g (Fin.cons z' s')) ∂π' := by\n rw [integral_sub (intg_of_bdd (hgz z) (C := B) fun s' => hB _)\n (intg_of_bdd (hgz z') (C := B) fun s' => hB _)]\n rw [hsub]\n have := norm_integral_le_of_norm_le_const (μ := π')\n (f := fun s' => g (Fin.cons z s') - g (Fin.cons z' s')) (C := c 0)\n (Filter.Eventually.of_forall fun s' => by\n simp only [Real.norm_eq_abs]\n refine hc 0 _ _ ?_\n intro j hj\n rcases Fin.eq_zero_or_eq_succ j with rfl | ⟨m, rfl⟩\n · exact absurd rfl hj\n · simp)\n simpa [Real.norm_eq_abs] using this\n have hc0 : 0 ≤ c 0 := le_trans (abs_nonneg _) (hGBD (Classical.arbitrary 𝒵) (Classical.arbitrary 𝒵))\n set A := sInf (Set.range G) with hA\n have hne : (Set.range G).Nonempty := ⟨G (Classical.arbitrary 𝒵), ⟨Classical.arbitrary 𝒵, rfl⟩⟩\n have hbb : BddBelow (Set.range G) := ⟨-B, by\n rintro _ ⟨z, rfl⟩; have := hGB z; cases abs_le.1 this with | intro h1 h2 => exact h1⟩\n have hlow : ∀ z, A ≤ G z := fun z => csInf_le hbb ⟨z, rfl⟩\n have hhigh : ∀ z, G z ≤ A + c 0 := by\n intro z\n refine le_of_forall_pos_le_add ?_\n intro ε hε\n obtain ⟨x, hx, hxlt⟩ := Real.lt_sInf_add_pos hne hε\n obtain ⟨z', rfl⟩ := hx\n have := (abs_le.1 (hGBD z z')).2\n linarith\n have hIcc : ∀ᵐ z ∂(ν 0), G z ∈ Set.Icc A (A + c 0) :=\n Filter.Eventually.of_forall fun z => ⟨hlow z, hhigh z⟩\n have hsg := ProbabilityTheory.hasSubgaussianMGF_of_mem_Icc (X := G) (μ := ν 0)\n hGmeas.aemeasurable hIcc\n have hmgf := hsg.mgf_le t\n have hHoef : ∫ z, exp (t * (G z - ∫ z', G z' ∂(ν 0))) ∂(ν 0) ≤ exp (t ^ 2 * c 0 ^ 2 / 8) := by\n have hm : mgf (fun z => G z - (ν 0)[G]) (ν 0) t\n = ∫ z, exp (t * (G z - ∫ z', G z' ∂(ν 0))) ∂(ν 0) := by\n simp [mgf]\n rw [← hm]\n refine hmgf.trans ?_\n apply Real.exp_le_exp.2\n have hnn : (((‖A + c 0 - A‖₊ / 2) ^ 2 : NNReal) : ℝ) = (c 0 / 2) ^ 2 := by\n rw [show A + c 0 - A = c 0 by ring]\n push_cast\n simp [abs_of_nonneg hc0]\n rw [hnn]\n nlinarith [sq_nonneg (t * c 0)]\n have hEg : (∫ s, g s ∂(Measure.pi ν)) = ∫ z, G z ∂(ν 0) := pi_succ_integral ν g hg B hB\n set Eg := ∫ s, g s ∂(Measure.pi ν) with hEgdef\n set K : ℝ := exp (|t| * (B + |Eg|)) with hK\n have habs : ∀ s : Fin (n+1) → 𝒵, |exp (t * (g s - Eg))| ≤ K := by\n intro s\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.2\n have h2 : |g s - Eg| ≤ |g s| + |Eg| := by\n exact abs_le.2 ⟨by linarith [neg_abs_le (g s), le_abs_self Eg],\n by linarith [le_abs_self (g s), neg_abs_le Eg]⟩\n have h3 := hB s\n calc t * (g s - Eg) ≤ |t * (g s - Eg)| := le_abs_self _\n _ = |t| * |g s - Eg| := abs_mul _ _\n _ ≤ |t| * (B + |Eg|) := by\n refine mul_le_mul_of_nonneg_left ?_ (abs_nonneg t)\n linarith\n have hmE : Measurable (fun s : Fin (n+1) → 𝒵 => exp (t * (g s - Eg))) := by fun_prop\n have hFub : ∫ s, exp (t * (g s - Eg)) ∂(Measure.pi ν)\n = ∫ z, (∫ s', exp (t * (g (Fin.cons z s') - Eg)) ∂π') ∂(ν 0) :=\n pi_succ_integral ν _ hmE K habs\n have hBD' : ∀ z : 𝒵, BD (fun s' : Fin n → 𝒵 => g (Fin.cons z s')) (fun j => c j.succ) := by\n intro z k s s' hss\n refine hc k.succ _ _ ?_\n intro j hj\n rcases Fin.eq_zero_or_eq_succ j with rfl | ⟨m, rfl⟩\n · simp\n · have : m ≠ k := fun h => hj (by rw [h])\n simp [hss m this]\n have hinner : ∀ z, (∫ s', exp (t * (g (Fin.cons z s') - Eg)) ∂π')\n ≤ exp (t * (G z - Eg)) * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8) := by\n intro z\n have hsplit : ∀ s' : Fin n → 𝒵, exp (t * (g (Fin.cons z s') - Eg))\n = exp (t * (G z - Eg)) * exp (t * (g (Fin.cons z s') - G z)) := by\n intro s'; rw [← Real.exp_add]; ring_nf\n simp_rw [hsplit]\n rw [integral_const_mul]\n have hih := ih (fun j => ν j.succ) (fun i => hν _) (fun s' => g (Fin.cons z s')) (hgz z) B\n (fun s' => hB _) (fun j => c j.succ) (hBD' z) t\n exact mul_le_mul_of_nonneg_left hih (le_of_lt (Real.exp_pos _))\n have hLmeas : Measurable (fun z => ∫ s', exp (t * (g (Fin.cons z s') - Eg)) ∂π') :=\n ((meas_cons hmE).stronglyMeasurable.integral_prod_right' (ν := π')).measurable\n have hLbd : ∀ z, |∫ s', exp (t * (g (Fin.cons z s') - Eg)) ∂π'| ≤ K := by\n intro z\n have := norm_integral_le_of_norm_le_const (μ := π')\n (f := fun s' => exp (t * (g (Fin.cons z s') - Eg))) (C := K)\n (Filter.Eventually.of_forall fun s' => by simpa [Real.norm_eq_abs] using habs _)\n simpa [Real.norm_eq_abs] using this\n have hRmeas2 : Measurable (fun z => exp (t * (G z - Eg))\n * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8)) := by fun_prop\n have hRbd : ∀ z, |exp (t * (G z - Eg)) * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8)|\n ≤ K * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8) := by\n intro z\n rw [abs_mul, abs_of_pos (Real.exp_pos _), abs_of_pos (Real.exp_pos _)]\n refine mul_le_mul_of_nonneg_right ?_ (le_of_lt (Real.exp_pos _))\n have : |exp (t * (G z - Eg))| ≤ K := by\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.2\n have h2 : |G z - Eg| ≤ |G z| + |Eg| := by\n exact abs_le.2 ⟨by linarith [neg_abs_le (G z), le_abs_self Eg],\n by linarith [le_abs_self (G z), neg_abs_le Eg]⟩\n have h3 := hGB z\n calc t * (G z - Eg) ≤ |t * (G z - Eg)| := le_abs_self _\n _ = |t| * |G z - Eg| := abs_mul _ _\n _ ≤ |t| * (B + |Eg|) := by\n refine mul_le_mul_of_nonneg_left ?_ (abs_nonneg t)\n linarith\n simpa [abs_of_pos (Real.exp_pos _)] using this\n rw [hFub]\n have step1 : ∫ z, (∫ s', exp (t * (g (Fin.cons z s') - Eg)) ∂π') ∂(ν 0)\n ≤ ∫ z, exp (t * (G z - Eg)) * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8) ∂(ν 0) :=\n integral_mono (intg_of_bdd hLmeas hLbd) (intg_of_bdd hRmeas2 hRbd) hinner\n have step2 : ∫ z, exp (t * (G z - Eg)) * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8) ∂(ν 0)\n = (∫ z, exp (t * (G z - Eg)) ∂(ν 0)) * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8) :=\n integral_mul_const _ _\n have step3 : (∫ z, exp (t * (G z - Eg)) ∂(ν 0)) ≤ exp (t ^ 2 * c 0 ^ 2 / 8) := by\n rw [hEg]; exact hHoef\n calc ∫ z, (∫ s', exp (t * (g (Fin.cons z s') - Eg)) ∂π') ∂(ν 0)\n ≤ (∫ z, exp (t * (G z - Eg)) ∂(ν 0))\n * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8) := by rw [← step2]; exact step1\n _ ≤ exp (t ^ 2 * c 0 ^ 2 / 8) * exp (t ^ 2 * (∑ j : Fin n, c j.succ ^ 2) / 8) := by\n exact mul_le_mul_of_nonneg_right step3 (le_of_lt (Real.exp_pos _))\n _ = exp (t ^ 2 * (∑ k, c k ^ 2) / 8) := by\n rw [← Real.exp_add, Fin.sum_univ_succ]; ring_nf\n\nlemma bd_bound {n : ℕ} {g : (Fin n → 𝒵) → ℝ} {c : Fin n → ℝ} (hc : BD g c) (s s' : Fin n → 𝒵) :\n |g s - g s'| ≤ ∑ k, c k := by\n classical\n have key : ∀ T : Finset (Fin n),\n |g s - g (fun j => if j ∈ T then s' j else s j)| ≤ ∑ k ∈ T, c k := by\n intro T\n induction T using Finset.induction with\n | empty => simp\n | insert a T ha ih =>\n have hstep : |g (fun j => if j ∈ T then s' j else s j)\n - g (fun j => if j ∈ insert a T then s' j else s j)| ≤ c a := by\n refine hc a _ _ ?_\n intro j hj\n have : (j ∈ insert a T) = (j ∈ T) := by\n simp [Finset.mem_insert, hj]\n simp [this]\n have := abs_sub_le (g s) (g (fun j => if j ∈ T then s' j else s j))\n (g (fun j => if j ∈ insert a T then s' j else s j))\n rw [Finset.sum_insert ha]\n linarith\n have := key Finset.univ\n simpa using this\n\ntheorem tail_bd {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n {n : ℕ} (Z : Fin n → Ω → 𝒵) (hZmeas : ∀ i, Measurable (Z i))\n (hZindep : ProbabilityTheory.iIndepFun Z μ)\n (g : (Fin n → 𝒵) → ℝ) (hg : Measurable g) (c : Fin n → ℝ) (hc : BD g c)\n (ε : ℝ) (hε : 0 ≤ ε) (C : ℝ) (hCpos : 0 < C) (hC : ∑ k, c k ^ 2 ≤ C) :\n (μ {ω | (∫ x, g (fun i => Z i x) ∂μ) + ε ≤ g (fun i => Z i ω)}).toReal\n ≤ exp (-(2 * ε ^ 2) / C) := by\n classical\n set ν : Fin n → Measure 𝒵 := fun i => Measure.map (Z i) μ with hν\n haveI : ∀ i, IsProbabilityMeasure (ν i) := fun i => Measure.isProbabilityMeasure_map (hZmeas i).aemeasurable\n have hZvec : Measurable (fun ω i => Z i ω) := measurable_pi_lambda _ hZmeas\n have hmap : Measure.map (fun ω i => Z i ω) μ = Measure.pi ν :=\n (ProbabilityTheory.iIndepFun_iff_map_fun_eq_pi_map (fun i => (hZmeas i).aemeasurable)).1 hZindep\n set s0 : Fin n → 𝒵 := fun _ => Classical.arbitrary 𝒵 with hs0\n set B : ℝ := |g s0| + ∑ k, c k with hBdef\n have hB : ∀ s, |g s| ≤ B := by\n intro s\n have h1 := bd_bound hc s s0\n have h2 : |g s| ≤ |g s - g s0| + |g s0| := by\n have := abs_sub_le (g s) (g s0) 0\n simpa using (abs_sub_abs_le_abs_sub (g s) (g s0)).trans (le_refl _) |>.trans (le_refl _)\n have h3 : |g s| - |g s0| ≤ |g s - g s0| := abs_sub_abs_le_abs_sub (g s) (g s0)\n rw [hBdef]; linarith\n set Eg : ℝ := ∫ x, g (fun i => Z i x) ∂μ with hEgd\n have hEg2 : Eg = ∫ s, g s ∂(Measure.pi ν) := by\n rw [hEgd, ← hmap, integral_map hZvec.aemeasurable hg.aestronglyMeasurable]\n set X : Ω → ℝ := fun ω => g (fun i => Z i ω) - Eg with hXd\n have hXmeas : Measurable X := (hg.comp hZvec).sub measurable_const\n have hXbd : ∀ ω, |X ω| ≤ B + |Eg| := by\n intro ω\n have := hB (fun i => Z i ω)\n rw [hXd]\n exact abs_le.2 ⟨by linarith [neg_abs_le (g (fun i => Z i ω)), le_abs_self Eg],\n by linarith [le_abs_self (g (fun i => Z i ω)), neg_abs_le Eg]⟩\n have hmgf : ∀ t : ℝ, mgf X μ t ≤ exp (t ^ 2 * C / 8) := by\n intro t\n have h1 : mgf X μ t = ∫ s, exp (t * (g s - Eg)) ∂(Measure.pi ν) := by\n have hh := integral_map (μ := μ) (φ := fun ω i => Z i ω) hZvec.aemeasurable\n (f := fun s : Fin n → 𝒵 => exp (t * (g s - Eg)))\n (Measurable.exp (by fun_prop)).aestronglyMeasurable\n rw [hmap] at hh\n rw [mgf, hh]\n rw [h1, hEg2]\n refine (mgf_bd n ν (fun i => inferInstance) g hg B hB c hc t).trans ?_\n apply Real.exp_le_exp.2\n have : (0:ℝ) ≤ t ^ 2 := sq_nonneg t\n have := mul_le_mul_of_nonneg_left hC this\n linarith\n have hint : ∀ t : ℝ, Integrable (fun ω => exp (t * X ω)) μ := by\n intro t\n refine intg_of_bdd (by fun_prop) (C := exp (|t| * (B + |Eg|))) ?_\n intro ω\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.2\n calc t * X ω ≤ |t * X ω| := le_abs_self _\n _ = |t| * |X ω| := abs_mul _ _\n _ ≤ |t| * (B + |Eg|) := mul_le_mul_of_nonneg_left (hXbd ω) (abs_nonneg t)\n set t : ℝ := 4 * ε / C with htd\n have ht : 0 ≤ t := by positivity\n have hset : {ω | Eg + ε ≤ g (fun i => Z i ω)} = {ω | ε ≤ X ω} := by\n ext ω; simp [hXd, le_sub_iff_add_le, add_comm]\n rw [hEgd] at hset\n rw [show {ω | (∫ x, g (fun i => Z i x) ∂μ) + ε ≤ g (fun i => Z i ω)} = {ω | ε ≤ X ω} from hset]\n have hch := ProbabilityTheory.measure_ge_le_exp_mul_mgf (μ := μ) (X := X) (t := t) ε ht (hint t)\n rw [measureReal_def] at hch\n refine hch.trans ?_\n calc exp (-t * ε) * mgf X μ t ≤ exp (-t * ε) * exp (t ^ 2 * C / 8) :=\n mul_le_mul_of_nonneg_left (hmgf t) (le_of_lt (Real.exp_pos _))\n _ = exp (-(2 * ε ^ 2) / C) := by\n rw [← Real.exp_add]\n congr 1\n rw [htd]\n field_simp\n ring\n\nend McD\n\n\nlemma bd_offset {F : Type*} [Nonempty F] {𝒵 : Type*} {n : ℕ} (hn : 0 < n)\n (φ : F → 𝒵 → ℝ) (h0 : F → ℝ) (h1 : F → 𝒵 → ℝ)\n (hBdd : ∀ (s : Fin n → 𝒵) (σ : RadSigns n),\n BddAbove (Set.range (fun f : F =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (σ i : ℝ) * (φ f (s i) + (1/2) * h1 f (s i))\n - (1/2) * offsetH h0 h1 f s)))\n (M : ℝ)\n (hSens : ∀ (f : F) (z z' : 𝒵), |φ f z - φ f z'| + |h1 f z - h1 f z'| ≤ M) :\n McD.BD (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun _ => M / n) := by\n classical\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n set A : RadSigns n → F → (Fin n → 𝒵) → ℝ := fun σ f s =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (σ i : ℝ) * (φ f (s i) + (1/2) * h1 f (s i))\n - (1/2) * offsetH h0 h1 f s with hAdef\n have hBdd' : ∀ (s : Fin n → 𝒵) (σ : RadSigns n), BddAbove (Set.range (fun f : F => A σ f s)) :=\n hBdd\n have hpt : ∀ (k : Fin n) (σ : RadSigns n) (f : F) (u v : Fin n → 𝒵),\n (∀ j, j ≠ k → u j = v j) → A σ f u - A σ f v ≤ M / n := by\n intro k σ f u v huv\n have hσ : ((σ k : ℤ) : ℝ) = -1 ∨ ((σ k : ℤ) : ℝ) = 1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h <;> rw [h] <;> norm_num\n have hs1 : (∑ i : Fin n, (σ i : ℝ) * (φ f (u i) + (1/2) * h1 f (u i)))\n - (∑ i : Fin n, (σ i : ℝ) * (φ f (v i) + (1/2) * h1 f (v i)))\n = (σ k : ℝ) * ((φ f (u k) + (1/2) * h1 f (u k))\n - (φ f (v k) + (1/2) * h1 f (v k))) := by\n rw [← Finset.sum_sub_distrib, Finset.sum_eq_single k]\n · ring\n · intro i _ hik; rw [huv i hik]; ring\n · intro h; exact absurd (Finset.mem_univ k) h\n have hs2 : (∑ i : Fin n, h1 f (u i)) - (∑ i : Fin n, h1 f (v i))\n = h1 f (u k) - h1 f (v k) := by\n rw [← Finset.sum_sub_distrib, Finset.sum_eq_single k]\n · intro i _ hik; rw [huv i hik]; ring\n · intro h; exact absurd (Finset.mem_univ k) h\n have hkey : A σ f u - A σ f v\n = (n : ℝ)⁻¹ * ((∑ i : Fin n, (σ i : ℝ) * (φ f (u i) + (1/2) * h1 f (u i)))\n - (∑ i : Fin n, (σ i : ℝ) * (φ f (v i) + (1/2) * h1 f (v i))))\n - (1/2) * ((n : ℝ)⁻¹ * ((∑ i : Fin n, h1 f (u i)) - (∑ i : Fin n, h1 f (v i)))) := by\n simp only [hAdef, offsetH]; ring\n rw [hs1, hs2] at hkey\n have hnn : (0:ℝ) ≤ (n:ℝ)⁻¹ := by positivity\n have hE : (σ k : ℝ) * ((φ f (u k) + (1/2) * h1 f (u k)) - (φ f (v k) + (1/2) * h1 f (v k)))\n - (1/2) * (h1 f (u k) - h1 f (v k)) ≤ M := by\n have hsn := hSens f (u k) (v k)\n rcases hσ with h | h <;> rw [h] <;>\n nlinarith [le_abs_self (φ f (u k) - φ f (v k)), neg_abs_le (φ f (u k) - φ f (v k)),\n le_abs_self (h1 f (u k) - h1 f (v k)), neg_abs_le (h1 f (u k) - h1 f (v k))]\n have habc : ∀ (X Y : ℝ), X - 1/2 * Y ≤ M →\n (n:ℝ)⁻¹ * X - 1/2 * ((n:ℝ)⁻¹ * Y) ≤ M / n := by\n intro X Y h\n have hrw2 : (n:ℝ)⁻¹ * X - 1/2 * ((n:ℝ)⁻¹ * Y) = (n:ℝ)⁻¹ * (X - 1/2 * Y) := by ring\n have hrw3 : M / (n:ℝ) = (n:ℝ)⁻¹ * M := by ring\n rw [hrw2, hrw3]\n exact mul_le_mul_of_nonneg_left h hnn\n rw [hkey]\n exact habc _ _ hE\n have hsup : ∀ (k : Fin n) (σ : RadSigns n) (u v : Fin n → 𝒵),\n (∀ j, j ≠ k → u j = v j) → (⨆ f, A σ f u) ≤ (⨆ f, A σ f v) + M / n := by\n intro k σ u v huv\n refine ciSup_le (fun f => ?_)\n have h1' := hpt k σ f u v huv\n have h2' := le_ciSup (hBdd' v σ) f\n linarith\n have hdiff : ∀ (k : Fin n) (u v : Fin n → 𝒵), (∀ j, j ≠ k → u j = v j) →\n offsetEmpRC n φ h0 h1 u - offsetEmpRC n φ h0 h1 v ≤ M / n := by\n intro k u v huv\n haveI : Nonempty (RadSigns n) :=\n ⟨(fun _ => ⟨1, by simp⟩ : Fin n → ({-1, 1} : Finset ℤ))⟩\n have hcard : (0:ℝ) < (Fintype.card (RadSigns n) : ℝ) := by\n have : 0 < Fintype.card (RadSigns n) := Fintype.card_pos\n exact_mod_cast this\n have hrw : offsetEmpRC n φ h0 h1 u - offsetEmpRC n φ h0 h1 v\n = (Fintype.card (RadSigns n) : ℝ)⁻¹\n * ∑ σ : RadSigns n, ((⨆ f, A σ f u) - (⨆ f, A σ f v)) := by\n simp only [offsetEmpRC, hAdef]\n rw [Finset.sum_sub_distrib]\n ring\n rw [hrw]\n have hsum : ∑ σ : RadSigns n, ((⨆ f, A σ f u) - (⨆ f, A σ f v))\n ≤ ∑ _σ : RadSigns n, (M / n) :=\n Finset.sum_le_sum (fun σ _ => by linarith [hsup k σ u v huv])\n rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] at hsum\n have hnn : (0:ℝ) ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ := by positivity\n have := mul_le_mul_of_nonneg_left hsum hnn\n calc (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, ((⨆ f, A σ f u) - (⨆ f, A σ f v))\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ * ((Fintype.card (RadSigns n) : ℝ) * (M / n)) := this\n _ = M / n := by field_simp\n intro k s s' hss\n have h1' := hdiff k s s' hss\n have h2' := hdiff k s' s (fun j hj => (hss j hj).symm)\n exact abs_le.2 ⟨by linarith, h1'⟩\n\n\ntheorem ch8_theorem_8_9\n {F : Type*} [Nonempty F]\n {𝒵 : Type*} [MeasurableSpace 𝒵] [Nonempty 𝒵]\n {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n {n : ℕ} (hn : 0 < n)\n (Z : Fin n → Ω → 𝒵)\n (hZmeas : ∀ i, Measurable (Z i))\n (hZindep : ProbabilityTheory.iIndepFun Z μ)\n (hZident : ∀ i j, Measure.map (Z i) μ = Measure.map (Z j) μ)\n (φ : F → 𝒵 → ℝ) (h0 : F → ℝ) (h1 : F → 𝒵 → ℝ)\n (hBdd : ∀ (s : Fin n → 𝒵) (σ : RadSigns n),\n BddAbove (Set.range (fun f : F =>\n (n : ℝ)⁻¹ * ∑ i : Fin n, (σ i : ℝ) * (φ f (s i) + (1/2) * h1 f (s i))\n - (1/2) * offsetH h0 h1 f s)))\n (hRmeas : Measurable (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s))\n (hRint : Integrable (fun x => offsetEmpRC n φ h0 h1 (fun i => Z i x)) μ)\n (M : ℝ) (hM : 0 ≤ M)\n (hSens : ∀ (f : F) (z z' : 𝒵),\n |φ f z - φ f z'| + |h1 f z - h1 f z'| ≤ M)\n {δ : ℝ} (hδ0 : 0 < δ) (hδ1 : δ ≤ 1) :\n ( 1 - δ ≤\n (μ {ω |\n (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i ω)\n ≥ (∫ x, (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i x) ∂μ)\n - M * Real.sqrt (Real.log (1/δ) / (2 * n)) }).toReal )\n ∧\n ( 1 - δ ≤\n (μ {ω |\n (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i ω)\n ≤ (∫ x, (fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s) (fun i => Z i x) ∂μ)\n + M * Real.sqrt (Real.log (1/δ) / (2 * n)) }).toReal ) := by\n classical\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n have hcompl : ∀ (A S : Set Ω), Aᶜ ⊆ S → (μ S).toReal ≤ δ → 1 - δ ≤ (μ A).toReal := by\n intro A S hsub hS\n have h1' : (μ Aᶜ).toReal ≤ (μ S).toReal :=\n ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono hsub)\n have h2' : μ Set.univ ≤ μ A + μ Aᶜ := by\n have h := measure_union_le (μ := μ) A Aᶜ\n rwa [Set.union_compl_self] at h\n have h3' : (1:ℝ) ≤ (μ A).toReal + (μ Aᶜ).toReal := by\n have h4 := ENNReal.toReal_mono\n (ENNReal.add_ne_top.2 ⟨measure_ne_top μ A, measure_ne_top μ Aᶜ⟩) h2'\n rw [ENNReal.toReal_add (measure_ne_top μ A) (measure_ne_top μ Aᶜ)] at h4\n simpa using h4\n linarith\n set g : (Fin n → 𝒵) → ℝ := fun s : Fin n → 𝒵 => offsetEmpRC n φ h0 h1 s with hgdef\n have hBD : McD.BD g (fun _ => M / n) := bd_offset hn φ h0 h1 hBdd M hSens\n have hlog : 0 ≤ Real.log (1/δ) := Real.log_nonneg (by rw [le_div_iff₀ hδ0]; linarith)\n set ε : ℝ := M * Real.sqrt (Real.log (1/δ) / (2 * n)) with hεdef\n have hε0 : 0 ≤ ε := by rw [hεdef]; positivity\n set Eg : ℝ := ∫ x, g (fun i => Z i x) ∂μ with hEgd\n rcases eq_or_lt_of_le hM with hM0 | hMpos\n · have hzero : ∀ s s' : Fin n → 𝒵, g s = g s' := by\n intro s s'\n have hbb := McD.bd_bound hBD s s'\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, ← hM0] at hbb\n have hb2 : |g s - g s'| ≤ 0 := by\n have : (n:ℝ) * (0 / n) = 0 := by ring\n linarith [hbb, this]\n have := abs_eq_zero.1 (le_antisymm hb2 (abs_nonneg _))\n linarith\n have hEgc : Eg = g (fun _ => Classical.arbitrary 𝒵) := by\n rw [hEgd]\n have hfe : (fun x => g (fun i => Z i x)) = fun _ => g (fun _ => Classical.arbitrary 𝒵) :=\n funext fun x => hzero _ _\n rw [hfe, integral_const]\n simp\n have hεz : ε = 0 := by rw [hεdef, ← hM0]; ring\n constructor\n · have hu : {ω | g (fun i => Z i ω) ≥ Eg - ε} = Set.univ := by\n ext ω\n simp only [Set.mem_setOf_eq, Set.mem_univ, iff_true, ge_iff_le, hεz, sub_zero, hEgc]\n exact le_of_eq (hzero _ _)\n rw [hu]\n simp\n linarith\n · have hu : {ω | g (fun i => Z i ω) ≤ Eg + ε} = Set.univ := by\n ext ω\n simp only [Set.mem_setOf_eq, Set.mem_univ, iff_true, hεz, add_zero, hEgc]\n exact le_of_eq (hzero _ _)\n rw [hu]\n simp\n linarith\n · have hCpos : (0:ℝ) < M ^ 2 / n := by positivity\n have hsumc : ∑ _k : Fin n, (M / n) ^ 2 ≤ M ^ 2 / n := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, div_pow]\n have hrw : (n:ℝ) * (M ^ 2 / (n:ℝ) ^ 2) = M ^ 2 / n := by field_simp\n rw [hrw]\n have hexp : Real.exp (-(2 * ε ^ 2) / (M ^ 2 / n)) = δ := by\n have hs : Real.sqrt (Real.log (1/δ) / (2 * n)) ^ 2 = Real.log (1/δ) / (2 * n) :=\n Real.sq_sqrt (by positivity)\n have hkey : -(2 * ε ^ 2) / (M ^ 2 / n) = -Real.log (1/δ) := by\n rw [hεdef, mul_pow, hs]\n field_simp\n rw [hkey, Real.exp_neg, Real.exp_log (by positivity), one_div, inv_inv]\n have hup : (μ {ω | Eg + ε ≤ g (fun i => Z i ω)}).toReal ≤ δ := by\n have := McD.tail_bd Z hZmeas hZindep g hRmeas (fun _ => M / n) hBD ε hε0 (M ^ 2 / n)\n hCpos hsumc\n rw [hexp] at this\n exact this\n have hBDneg : McD.BD (fun s => -g s) (fun _ => M / n) := by\n intro k s s' hss\n have := hBD k s s' hss\n rw [show -g s - -g s' = -(g s - g s') from by ring, abs_neg]\n exact this\n have hEneg : (∫ x, (fun s => -g s) (fun i => Z i x) ∂μ) = -Eg := by\n simp only [hEgd]\n rw [integral_neg]\n have hlow : (μ {ω | -Eg + ε ≤ -g (fun i => Z i ω)}).toReal ≤ δ := by\n have h := McD.tail_bd Z hZmeas hZindep (fun s => -g s) hRmeas.neg (fun _ => M / n) hBDneg\n ε hε0 (M ^ 2 / n) hCpos hsumc\n rw [hexp, hEneg] at h\n exact h\n constructor\n · refine hcompl _ _ ?_ hlow\n intro ω hω\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, ge_iff_le, not_le] at hω\n simp only [Set.mem_setOf_eq]\n linarith\n · refine hcompl _ _ ?_ hup\n intro ω hω\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hω\n simp only [Set.mem_setOf_eq]\n linarith\n\nend GraduateLevel\n"} +{"id": "ch10_corollary_10_17", "source": "Graduate-level", "targets": [{"label": "ch10_corollary_10_17", "decls": ["ch10_corollary_10_17"], "statement": "Let \\(\\mathcal{F}_A = \\{f(q,x):\\mathrm{KL}(q||q_0)\\leq A^2\\}\\) be entropy regularized functions of (10.11). Then\n\\[\nR\\left(\\mathcal{F}_{A},\\mathcal{S}_{n}\\right)\\leq\\sqrt{\\frac{2}{n}}A\\sup_{\\theta}\\sqrt{\\frac{1}{n}\\sum_{i=1}^{n}\\psi\\left(\\theta,X_{i}\\right)^{2}}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "From Theorem 10.16, we have\n\\[\nR\\left(\\mathcal{F}_{A},\\mathcal{S}_{n}\\right)\\leq\\frac{\\lambda}{2}A^{2}+\\frac{1}{\\lambda n^{2}}\\sup_{\\theta}\\sum_{i=1}^{n}\\psi\\left(\\theta,X_{i}\\right)^{2}.\n\\]\nBy optimizing over \\(\\lambda\\), we obtain the desired bound.", "context": [{"id": "ch10:theorem:10_16", "name": "theorem 10.16", "statement": "Consider \\( h(q) = h_0(q) = \\lambda \\mathrm{KL}(q||q_0) \\), and \\( \\mathcal{F} = \\{f(q,x)\\} \\) in (10.11). The offset Rademacher complexity can be bounded as\n\\[\nR^{h}(\\mathcal{F},\\mathcal{S}_{n})\\leq\\frac{\\lambda}{2}\\ln\\mathbb{E}_{\\theta\\sim q_{0}}\\exp\\left[\\frac{2}{\\lambda^{2}n^{2}}\\sum_{i=1}^{n}\\psi(\\theta,X_{i})^{2}\\right]\\leq\\frac{1}{\\lambda n^{2}}\\sup_{\\theta}\\sum_{i=1}^{n}\\psi(\\theta,X_{i})^{2}.\n\\]"}, {"id": "ch10:equation:10_11", "name": "equation (10.11)", "statement": "Let \\(\\Theta\\) be a parameter space, let \\(q\\) and the reference distribution \\(q_0\\) be probability distributions on \\(\\Theta\\), and let \\(\\psi(\\theta,x)\\) be a base function indexed by \\(\\theta\\in\\Theta\\). Define\n\\[\nf(q,x)=\\mathbb{E}_{\\theta\\sim q}\\psi(\\theta,x).\n\\tag{10.11}\n\\]\nFor \\(A\\geq 0\\), the entropy-regularized function class is\n\\[\n\\mathcal{F}_A=\\{f(q,x):\\mathrm{KL}(q||q_0)\\leq A^2\\}.\n\\]"}, {"id": "ch6:definition:6_3", "name": "definition 6.3", "statement": "Given \\(S_{n}=\\{Z_{1},\\ldots,Z_{n}\\}\\), the (one-sided) empirical Rademacher complexity of \\(\\mathcal{G}\\) is defined as\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n}) = \\mathbb{E}_{\\sigma}\\sup_{w\\in \\Omega}\\frac{1}{n}\\sum_{i = 1}^{n}\\sigma_{i}\\phi (w,Z_{i}),\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R(\\mathcal{G},\\mathcal{S}_{n}).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ntheorem ch10_corollary_10_17\n {Θ : Type*} [MeasurableSpace Θ] {𝒳 : Type*}\n {n : ℕ} (hn : 0 < n)\n (A : ℝ) (hA : 0 ≤ A)\n (q_0 : Measure Θ) [IsProbabilityMeasure q_0]\n (ψ : Θ → 𝒳 → ℝ)\n (S : Fin n → 𝒳)\n (hint : ∀ (q : Measure Θ), IsProbabilityMeasure q →\n InformationTheory.klDiv q q_0 ≤ ENNReal.ofReal (A^2) →\n ∀ x : 𝒳, Integrable (fun θ => ψ θ x) q)\n (hbdd : BddAbove (Set.range (fun θ : Θ => (1 / (n : ℝ)) * ∑ i, (ψ θ (S i))^2))) :\n empRadSigned\n (ι := {q : Measure Θ //\n IsProbabilityMeasure q ∧\n InformationTheory.klDiv q q_0 ≤ ENNReal.ofReal (A^2)})\n n\n (fun q x => ∫ θ, ψ θ x ∂(q : Measure Θ))\n S\n ≤ Real.sqrt (2 / n) * A *\n ⨆ θ : Θ, Real.sqrt ((1 / (n : ℝ)) * ∑ i, (ψ θ (S i))^2) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nprivate lemma sum_sign_exp (x : ℝ) :\n ∑ s : ({-1, 1} : Finset ℤ), Real.exp ((s : ℝ) * x) = 2 * Real.cosh x := by\n rw [← Finset.sum_subtype ({-1, 1} : Finset ℤ) (by simp)\n (fun s : ℤ ↦ Real.exp ((s : ℝ) * x))]\n rw [Finset.sum_insert (by norm_num), Finset.sum_singleton, Real.cosh_eq]\n norm_num only [Int.cast_neg, Int.cast_one, neg_mul, one_mul]\n ring\n\nprivate lemma radSigns_card (n : ℕ) :\n Fintype.card (RadSigns n) = 2 ^ n := by\n simp [RadSigns]\n\nprivate lemma rad_mgf {n : ℕ} (a : Fin n → ℝ) (t : ℝ) :\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, Real.exp (t * ∑ i, (σ i : ℝ) * a i)\n ≤ Real.exp ((t ^ 2 / 2) * ∑ i, (a i) ^ 2) := by\n classical\n have hsum :\n ∑ σ : RadSigns n, Real.exp (t * ∑ i, (σ i : ℝ) * a i)\n = ∏ i : Fin n, (2 * Real.cosh (t * a i)) := by\n calc\n ∑ σ : RadSigns n, Real.exp (t * ∑ i, (σ i : ℝ) * a i)\n = ∑ σ : RadSigns n, ∏ i : Fin n,\n Real.exp (t * ((σ i : ℝ) * a i)) := by\n congr 1\n funext σ\n rw [← Real.exp_sum]\n congr 1\n rw [Finset.mul_sum]\n _ = ∏ i : Fin n, ∑ s : ({-1, 1} : Finset ℤ),\n Real.exp (t * ((s : ℝ) * a i)) := by\n symm\n exact Fintype.prod_sum\n (κ := fun _ : Fin n ↦ ({-1, 1} : Finset ℤ))\n (fun i s ↦ Real.exp (t * ((s : ℝ) * a i)))\n _ = ∏ i : Fin n, (2 * Real.cosh (t * a i)) := by\n apply Finset.prod_congr rfl\n intro i _\n simpa [mul_assoc, mul_left_comm, mul_comm] using sum_sign_exp (t * a i)\n rw [hsum, radSigns_card]\n rw [Nat.cast_pow]\n rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ,\n Fintype.card_fin]\n have htwo : (2 : ℝ) ^ n ≠ 0 := by positivity\n norm_num only [Nat.cast_ofNat]\n rw [← mul_assoc]\n rw [inv_mul_cancel₀ htwo, one_mul]\n calc\n ∏ i : Fin n, Real.cosh (t * a i)\n ≤ ∏ i : Fin n, Real.exp ((t * a i) ^ 2 / 2) := by\n exact Finset.prod_le_prod (fun _ _ ↦ Real.cosh_pos _ |>.le)\n (fun i _ ↦ Real.cosh_le_exp_half_sq _)\n _ = Real.exp ((t ^ 2 / 2) * ∑ i, (a i) ^ 2) := by\n rw [← Real.exp_sum]\n congr 1\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro i _\n ring\n\nprivate lemma integral_le_kl_add_log_mgf\n {α : Type*} [MeasurableSpace α]\n (μ ν : Measure α) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n (f : α → ℝ) (hfμ : Integrable f μ)\n (hfexp : Integrable (fun x ↦ Real.exp (f x)) ν)\n (hkl : InformationTheory.klDiv μ ν ≠ ∞) :\n ∫ x, f x ∂μ ≤ (InformationTheory.klDiv μ ν).toReal +\n Real.log (∫ x, Real.exp (f x) ∂ν) := by\n have hbase := InformationTheory.klDiv_ne_top_iff.mp hkl\n letI : IsProbabilityMeasure (ν.tilted f) :=\n MeasureTheory.isProbabilityMeasure_tilted hfexp\n have hac : μ ≪ ν.tilted f :=\n hbase.1.trans (MeasureTheory.absolutelyContinuous_tilted hfexp)\n have hintilt : Integrable (llr μ (ν.tilted f)) μ :=\n MeasureTheory.integrable_llr_tilted_right hbase.1 hfμ hbase.2 hfexp\n have hnonneg :=\n InformationTheory.integral_llr_add_sub_measure_univ_nonneg hac hintilt\n have hformula :=\n MeasureTheory.integral_llr_tilted_right hbase.1 hfμ hfexp hbase.2\n rw [hformula] at hnonneg\n rw [InformationTheory.toReal_klDiv_of_measure_eq hbase.1 (by simp)]\n have hnonneg' :\n ∫ x, llr μ ν x ∂μ - ∫ x, f x ∂μ +\n Real.log (∫ x, Real.exp (f x) ∂ν) ≥ 0 := by\n simpa using hnonneg\n linarith\n\nprivate lemma avg_log_mgf_le\n {α : Type*} [MeasurableSpace α] (ν : Measure α) [IsProbabilityMeasure ν]\n {n : ℕ} (a : α → Fin n → ℝ) (t V : ℝ)\n (hexp : ∀ σ : RadSigns n,\n Integrable (fun x ↦ Real.exp (t * ∑ i, (σ i : ℝ) * a x i)) ν)\n (hV : ∀ x, ∑ i, (a x i) ^ 2 ≤ V) :\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n Real.log (∫ x, Real.exp (t * ∑ i, (σ i : ℝ) * a x i) ∂ν)\n ≤ (t ^ 2 / 2) * V := by\n classical\n let σone : RadSigns n := fun _ ↦ ⟨1, by simp⟩\n letI : Nonempty (RadSigns n) := ⟨σone⟩\n let c : ℝ := (Fintype.card (RadSigns n) : ℝ)⁻¹\n let Z : RadSigns n → ℝ := fun σ ↦\n ∫ x, Real.exp (t * ∑ i, (σ i : ℝ) * a x i) ∂ν\n have hcard : (Fintype.card (RadSigns n) : ℝ) ≠ 0 := by\n exact_mod_cast Fintype.card_ne_zero\n have hc : 0 < c := by\n dsimp [c]\n positivity\n have hZ : ∀ σ, 0 < Z σ := fun σ ↦ by\n dsimp [Z]\n exact integral_exp_pos (hexp σ)\n have hweights : ∑ _σ : RadSigns n, c = 1 := by\n simp [c, hcard]\n have hjensen :=\n strictConcaveOn_log_Ioi.concaveOn.le_map_sum\n (t := Finset.univ) (w := fun _ : RadSigns n ↦ c) (p := Z)\n (fun _ _ ↦ hc.le) hweights (fun σ _ ↦ hZ σ)\n have hjensen' :\n c * ∑ σ : RadSigns n, Real.log (Z σ)\n ≤ Real.log (c * ∑ σ : RadSigns n, Z σ) := by\n simpa [Finset.mul_sum, smul_eq_mul] using hjensen\n have havg_int :\n c * ∑ σ : RadSigns n, Z σ =\n ∫ x, c * ∑ σ : RadSigns n,\n Real.exp (t * ∑ i, (σ i : ℝ) * a x i) ∂ν := by\n dsimp [Z]\n rw [integral_const_mul]\n congr 1\n symm\n exact integral_finset_sum Finset.univ (fun σ _ ↦ hexp σ)\n have havg_integrable :\n Integrable (fun x ↦ c * ∑ σ : RadSigns n,\n Real.exp (t * ∑ i, (σ i : ℝ) * a x i)) ν := by\n exact (integrable_finset_sum Finset.univ (fun σ _ ↦ hexp σ)).const_mul c\n have hpoint : ∀ x,\n c * ∑ σ : RadSigns n,\n Real.exp (t * ∑ i, (σ i : ℝ) * a x i)\n ≤ Real.exp ((t ^ 2 / 2) * V) := by\n intro x\n calc\n c * ∑ σ : RadSigns n,\n Real.exp (t * ∑ i, (σ i : ℝ) * a x i)\n ≤ Real.exp ((t ^ 2 / 2) * ∑ i, (a x i) ^ 2) := rad_mgf (a x) t\n _ ≤ Real.exp ((t ^ 2 / 2) * V) := by\n rw [Real.exp_le_exp]\n exact mul_le_mul_of_nonneg_left (hV x) (by positivity)\n have hint_le :\n ∫ x, c * ∑ σ : RadSigns n,\n Real.exp (t * ∑ i, (σ i : ℝ) * a x i) ∂ν\n ≤ Real.exp ((t ^ 2 / 2) * V) := by\n have hconst : Integrable (fun _x : α ↦ Real.exp ((t ^ 2 / 2) * V)) ν :=\n integrable_const _\n have := integral_mono_ae havg_integrable hconst (ae_of_all _ hpoint)\n simpa using this\n have havg_pos :\n 0 < ∫ x, c * ∑ σ : RadSigns n,\n Real.exp (t * ∑ i, (σ i : ℝ) * a x i) ∂ν := by\n rw [← havg_int]\n exact mul_pos hc (Finset.sum_pos' (fun σ _ ↦ (hZ σ).le)\n ⟨σone, Finset.mem_univ _, hZ σone⟩)\n calc\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, Real.log\n (∫ x, Real.exp (t * ∑ i, (σ i : ℝ) * a x i) ∂ν)\n = c * ∑ σ : RadSigns n, Real.log (Z σ) := by rfl\n _ ≤ Real.log (c * ∑ σ : RadSigns n, Z σ) := hjensen'\n _ = Real.log (∫ x, c * ∑ σ : RadSigns n,\n Real.exp (t * ∑ i, (σ i : ℝ) * a x i) ∂ν) := by rw [havg_int]\n _ ≤ Real.log (Real.exp ((t ^ 2 / 2) * V)) := by\n exact Real.log_le_log havg_pos hint_le\n _ = (t ^ 2 / 2) * V := Real.log_exp _\n\ntheorem ch10_corollary_10_17\n {Θ : Type*} [MeasurableSpace Θ] {𝒳 : Type*}\n {n : ℕ} (hn : 0 < n)\n (A : ℝ) (hA : 0 ≤ A)\n (q_0 : Measure Θ) [IsProbabilityMeasure q_0]\n (ψ : Θ → 𝒳 → ℝ)\n (S : Fin n → 𝒳)\n (hint : ∀ (q : Measure Θ), IsProbabilityMeasure q →\n InformationTheory.klDiv q q_0 ≤ ENNReal.ofReal (A^2) →\n ∀ x : 𝒳, Integrable (fun θ => ψ θ x) q)\n (hbdd : BddAbove (Set.range (fun θ : Θ => (1 / (n : ℝ)) * ∑ i, (ψ θ (S i))^2))) :\n empRadSigned\n (ι := {q : Measure Θ //\n IsProbabilityMeasure q ∧\n InformationTheory.klDiv q q_0 ≤ ENNReal.ofReal (A^2)})\n n\n (fun q x => ∫ θ, ψ θ x ∂(q : Measure Θ))\n S\n ≤ Real.sqrt (2 / n) * A *\n ⨆ θ : Θ, Real.sqrt ((1 / (n : ℝ)) * ∑ i, (ψ θ (S i))^2) := by\n classical\n letI : Nonempty Θ := Measure.nonempty_of_neZero q_0\n let v : Θ → ℝ := fun θ ↦\n (1 / (n : ℝ)) * ∑ i, (ψ θ (S i)) ^ 2\n let B : ℝ := ⨆ θ : Θ, Real.sqrt (v θ)\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n have hv_nonneg : ∀ θ, 0 ≤ v θ := by\n intro θ\n dsimp [v]\n positivity\n obtain ⟨C, hC⟩ := hbdd\n have hsqrt_bdd : BddAbove (Set.range (fun θ : Θ ↦ Real.sqrt (v θ))) := by\n refine ⟨Real.sqrt (max C 0), ?_⟩\n rintro y ⟨θ, rfl⟩\n apply Real.sqrt_le_sqrt\n exact (hC ⟨θ, rfl⟩).trans (le_max_left _ _)\n have hsqrt_le (θ : Θ) : Real.sqrt (v θ) ≤ B :=\n le_ciSup hsqrt_bdd θ\n have hB0 : 0 ≤ B := by\n let θ : Θ := Classical.choice inferInstance\n exact (Real.sqrt_nonneg _).trans (hsqrt_le θ)\n have hvB (θ : Θ) : v θ ≤ B ^ 2 := by\n calc\n v θ = Real.sqrt (v θ) ^ 2 := (Real.sq_sqrt (hv_nonneg θ)).symm\n _ ≤ B ^ 2 := (sq_le_sq₀ (Real.sqrt_nonneg _) hB0).2 (hsqrt_le θ)\n let a : Θ → Fin n → ℝ := fun θ i ↦ (n : ℝ)⁻¹ * ψ θ (S i)\n have ha_sq (θ : Θ) :\n ∑ i, (a θ i) ^ 2 ≤ B ^ 2 / n := by\n have h := hvB θ\n dsimp [v] at h\n dsimp [a]\n calc\n ∑ i, ((n : ℝ)⁻¹ * ψ θ (S i)) ^ 2\n = (n : ℝ)⁻¹ ^ 2 * ∑ i, (ψ θ (S i)) ^ 2 := by\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro i _\n ring\n _ ≤ B ^ 2 / n := by\n rw [div_eq_mul_inv]\n have hn0 : (n : ℝ) ≠ 0 := ne_of_gt hnR\n calc\n (n : ℝ)⁻¹ ^ 2 * ∑ i, (ψ θ (S i)) ^ 2\n = (n : ℝ)⁻¹ * ((1 / (n : ℝ)) *\n ∑ i, (ψ θ (S i)) ^ 2) := by\n field_simp\n _ ≤ (n : ℝ)⁻¹ * B ^ 2 :=\n mul_le_mul_of_nonneg_left h (by positivity)\n _ = B ^ 2 * (n : ℝ)⁻¹ := by ring\n have hpsi0 (x : 𝒳) : Integrable (fun θ ↦ ψ θ x) q_0 := by\n apply hint q_0 inferInstance\n rw [InformationTheory.klDiv_self]\n positivity\n have ha0 (i : Fin n) : Integrable (fun θ ↦ a θ i) q_0 := by\n exact (hpsi0 (S i)).const_mul _\n have hbase_abs (σ : RadSigns n) (θ : Θ) :\n |∑ i, (σ i : ℝ) * a θ i| ≤ B := by\n have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ\n (fun i : Fin n ↦ (σ i : ℝ)) (fun i ↦ a θ i)\n have hsign : ∑ i : Fin n, ((σ i : ℝ) ^ 2) = n := by\n calc\n ∑ i : Fin n, ((σ i : ℝ) ^ 2) = ∑ _i : Fin n, (1 : ℝ) := by\n apply Finset.sum_congr rfl\n intro i _\n have hp := (σ i).property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hp\n rcases hp with hp | hp\n · rw [hp]; norm_num\n · rw [hp]; norm_num\n _ = n := by simp\n rw [hsign] at hcs\n have hsquare : (∑ i, (σ i : ℝ) * a θ i) ^ 2 ≤ B ^ 2 := by\n calc\n (∑ i, (σ i : ℝ) * a θ i) ^ 2\n ≤ (n : ℝ) * ∑ i, (a θ i) ^ 2 := hcs\n _ ≤ (n : ℝ) * (B ^ 2 / n) :=\n mul_le_mul_of_nonneg_left (ha_sq θ) hnR.le\n _ = B ^ 2 := by field_simp\n exact abs_le_of_sq_le_sq hsquare hB0\n have hexp (t : ℝ) (σ : RadSigns n) :\n Integrable (fun θ ↦ Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i)) q_0 := by\n have hmeas : AEStronglyMeasurable\n (fun θ ↦ t * ∑ i, (σ i : ℝ) * a θ i) q_0 := by\n apply AEStronglyMeasurable.const_mul\n exact (integrable_finset_sum Finset.univ (fun i _ ↦\n (ha0 i).const_mul (σ i : ℝ))).aestronglyMeasurable\n apply Integrable.of_bound (continuous_exp.comp_aestronglyMeasurable hmeas)\n (Real.exp (|t| * B))\n filter_upwards with θ\n rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)]\n rw [Real.exp_le_exp]\n calc\n t * ∑ i, (σ i : ℝ) * a θ i\n ≤ |t * ∑ i, (σ i : ℝ) * a θ i| := le_abs_self _\n _ = |t| * |∑ i, (σ i : ℝ) * a θ i| := abs_mul _ _\n _ ≤ |t| * B := mul_le_mul_of_nonneg_left (hbase_abs σ θ) (abs_nonneg _)\n change _ ≤ Real.sqrt (2 / n) * A * B\n let Q := {q : Measure Θ //\n IsProbabilityMeasure q ∧\n InformationTheory.klDiv q q_0 ≤ ENNReal.ofReal (A ^ 2)}\n let qzero : Q := ⟨q_0, inferInstance, by\n rw [InformationTheory.klDiv_self]\n positivity⟩\n letI : Nonempty Q := ⟨qzero⟩\n have hmaster (t : ℝ) (ht : 0 < t) :\n empRadSigned (ι := Q) n\n (fun q x ↦ ∫ θ, ψ θ x ∂(q : Measure Θ)) S\n ≤ A ^ 2 / t + (t / 2) * (B ^ 2 / n) := by\n let σone : RadSigns n := fun _ ↦ ⟨1, by simp⟩\n letI : Nonempty (RadSigns n) := ⟨σone⟩\n have hsup (σ : RadSigns n) :\n (⨆ q : Q, (n : ℝ)⁻¹ * ∑ k : Fin n,\n (σ k : ℝ) * ∫ θ, ψ θ (S k) ∂(q : Measure Θ))\n ≤ A ^ 2 / t +\n Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0) / t := by\n apply ciSup_le\n intro q\n letI : IsProbabilityMeasure (q : Measure Θ) := q.property.1\n have hψq (i : Fin n) : Integrable (fun θ ↦ ψ θ (S i)) (q : Measure Θ) :=\n hint (q : Measure Θ) inferInstance q.property.2 (S i)\n have habaseq : Integrable\n (fun θ ↦ ∑ i, (σ i : ℝ) * a θ i) (q : Measure Θ) := by\n exact integrable_finset_sum Finset.univ (fun i _ ↦\n ((hψq i).const_mul _).const_mul _)\n have hbase_integral :\n ∫ θ, (∑ i, (σ i : ℝ) * a θ i) ∂(q : Measure Θ)\n = (n : ℝ)⁻¹ * ∑ i, (σ i : ℝ) *\n ∫ θ, ψ θ (S i) ∂(q : Measure Θ) := by\n rw [integral_finset_sum Finset.univ (fun i _ ↦\n ((hψq i).const_mul _).const_mul _)]\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro i _\n dsimp [a]\n rw [integral_const_mul, integral_const_mul]\n ring\n have hkltop : InformationTheory.klDiv (q : Measure Θ) q_0 ≠ ∞ :=\n ne_top_of_le_ne_top ENNReal.ofReal_ne_top q.property.2\n have hvar := integral_le_kl_add_log_mgf\n (q : Measure Θ) q_0\n (fun θ ↦ t * ∑ i, (σ i : ℝ) * a θ i)\n (habaseq.const_mul t) (hexp t σ) hkltop\n rw [integral_const_mul, hbase_integral] at hvar\n have hklreal :\n (InformationTheory.klDiv (q : Measure Θ) q_0).toReal ≤ A ^ 2 := by\n have := (ENNReal.toReal_le_toReal hkltop ENNReal.ofReal_ne_top).2 q.property.2\n rwa [ENNReal.toReal_ofReal (sq_nonneg A)] at this\n have hdiv :\n (n : ℝ)⁻¹ * ∑ i, (σ i : ℝ) *\n ∫ θ, ψ θ (S i) ∂(q : Measure Θ)\n ≤ ((InformationTheory.klDiv (q : Measure Θ) q_0).toReal +\n Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0)) / t := by\n rw [le_div_iff₀ ht]\n simpa [mul_comm] using hvar\n calc\n (n : ℝ)⁻¹ * ∑ k : Fin n,\n (σ k : ℝ) * ∫ θ, ψ θ (S k) ∂(q : Measure Θ)\n ≤ ((InformationTheory.klDiv (q : Measure Θ) q_0).toReal +\n Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0)) / t := hdiv\n _ ≤ A ^ 2 / t +\n Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0) / t := by\n have ht0 : 0 ≤ t := ht.le\n calc\n ((InformationTheory.klDiv (q : Measure Θ) q_0).toReal +\n Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0)) / t\n ≤ (A ^ 2 + Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0)) / t :=\n div_le_div_of_nonneg_right (by gcongr) ht0\n _ = _ := by ring\n have havglog := avg_log_mgf_le q_0 a t (B ^ 2 / n)\n (hexp t) ha_sq\n rw [empRadSigned]\n let c : ℝ := (Fintype.card (RadSigns n) : ℝ)⁻¹\n have hcard : (Fintype.card (RadSigns n) : ℝ) ≠ 0 := by\n exact_mod_cast Fintype.card_ne_zero\n calc\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ q : Q, (n : ℝ)⁻¹ *\n ∑ k, (σ k : ℝ) * ∫ θ, ψ θ (S k) ∂(q : Measure Θ)\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, (A ^ 2 / t +\n Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0) / t) := by\n gcongr with σ\n exact hsup σ\n _ = A ^ 2 / t +\n ((Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, Real.log (∫ θ, Real.exp\n (t * ∑ i, (σ i : ℝ) * a θ i) ∂q_0)) / t := by\n rw [Finset.sum_add_distrib, Finset.sum_const, nsmul_eq_mul,\n Finset.card_univ]\n rw [← Finset.sum_div]\n field_simp [hcard, ne_of_gt ht]\n _ ≤ A ^ 2 / t + ((t ^ 2 / 2) * (B ^ 2 / n)) / t :=\n by gcongr\n _ = A ^ 2 / t + (t / 2) * (B ^ 2 / n) := by\n field_simp [ne_of_gt ht]\n change empRadSigned (ι := Q) n\n (fun q x ↦ ∫ θ, ψ θ x ∂(q : Measure Θ)) S\n ≤ Real.sqrt (2 / n) * A * B\n by_cases hAz : A = 0\n · subst A\n simp only [zero_mul, mul_zero]\n by_cases hBz : B = 0\n · simpa [hBz] using hmaster 1 (by norm_num)\n · have hBp : 0 < B := lt_of_le_of_ne hB0 (Ne.symm hBz)\n apply le_of_forall_pos_le_add\n intro ε hε\n let t : ℝ := 2 * ε * n / B ^ 2\n have ht : 0 < t := by\n dsimp [t]\n positivity\n have hm := hmaster t ht\n have heq : (t / 2) * (B ^ 2 / n) = ε := by\n dsimp [t]\n field_simp [ne_of_gt hnR, ne_of_gt hBp]\n simpa [heq] using hm\n · have hAp : 0 < A := lt_of_le_of_ne hA (Ne.symm hAz)\n by_cases hBz : B = 0\n · have hzero : empRadSigned (ι := Q) n\n (fun q x ↦ ∫ θ, ψ θ x ∂(q : Measure Θ)) S ≤ 0 := by\n apply le_of_forall_pos_le_add\n intro ε hε\n let t : ��� := A ^ 2 / ε\n have ht : 0 < t := by\n dsimp [t]\n positivity\n have hm := hmaster t ht\n have heq : A ^ 2 / t = ε := by\n dsimp [t]\n field_simp [ne_of_gt hAp, ne_of_gt hε]\n simpa [hBz, heq] using hm\n simpa [hBz] using hzero\n · have hBp : 0 < B := lt_of_le_of_ne hB0 (Ne.symm hBz)\n let r : ℝ := Real.sqrt (2 / (n : ℝ))\n have hrp : 0 < r := by\n dsimp [r]\n positivity\n have hrsq : r ^ 2 = 2 / (n : ℝ) := by\n dsimp [r]\n rw [Real.sq_sqrt]\n positivity\n have hrn : r ^ 2 * (n : ℝ) = 2 := by\n rw [hrsq]\n field_simp [ne_of_gt hnR]\n let t : ℝ := 2 * A / (r * B)\n have ht : 0 < t := by\n dsimp [t]\n positivity\n have hm := hmaster t ht\n have heq :\n A ^ 2 / t + (t / 2) * (B ^ 2 / n) = r * A * B := by\n dsimp [t]\n field_simp [ne_of_gt hnR, ne_of_gt hrp, ne_of_gt hAp, ne_of_gt hBp]\n nlinarith [hrn]\n rw [heq] at hm\n simpa [r] using hm\n\nend GraduateLevel\n"} +{"id": "ch10_proposition_10_1", "source": "Graduate-level", "targets": [{"label": "ch10_proposition_10_1", "decls": ["ch10_proposition_10_1"], "statement": "Assume that the \\(m\\) feature functions \\(\\{\\psi_j(X)\\}\\) are orthonormal when \\(X\\sim \\mathcal{D}\\). Then there exists an absolute constant \\(c > 0\\) such that for sufficiently large \\(n\\),\n\\[\nR_{n}(\\mathcal{F}^{\\prime},\\mathcal{D})\\geq c\\sqrt{\\frac{m}{n}}A,\n\\]\nwhere \\(\\mathcal{F}'\\) is given by (10.2).", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "When \\( n \\) is sufficiently large, the vectors \\( \\{\\psi_j\\} \\) are near orthonormal on the empirical distribution \\( S_{n} \\). Therefore with constant probability, \\( \\mathcal{F}' \\) is nearly an \\( m \\)-dimensional ball of radius \\( A \\) with respect to \\( L_{2}(S_{n}) \\). Therefore Theorem 5.3 implies that \\( M(\\epsilon, \\mathcal{F}, L_{2}(S_{n})) \\geq 2^{m} \\) at \\( \\epsilon = c_{0}A \\) for some \\( c_{0} > 0 \\). The Rademacher complexity lower bound is now a direct consequence of Sudakov minoration (see Theorem 12.4) with such \\( \\epsilon \\).", "context": [{"id": "ch5:theorem:5_3", "name": "theorem 5.3", "statement": "Let \\(\\| \\cdot \\|\\) be a seminorm on \\(\\mathbb{R}^k\\). Let \\(B(r) = \\{z \\in \\mathbb{R}^k : \\| z \\| \\leq r\\}\\) be the \\(\\| \\cdot \\|\\)-ball with radius \\(r\\). Then\n\\[\nM(\\epsilon,B(r),\\|\\cdot\\|)\\leq\\left(1+2 r/\\epsilon\\right)^{k}.\n\\]\nMoreover, if \\(\\| \\cdot \\|\\) is a norm, then\n\\[\nN(\\epsilon,B(r),\\|\\cdot\\|)\\geq(r/\\epsilon)^{k}.\n\\]"}, {"id": "ch10:equation:10_2", "name": "equation 10.2", "statement": "\\[\n\\mathcal{F}^{\\prime}=\\{f(w,x)=w^\\top\\psi(x):\\|w\\|_2\\leq A\\}.\n\\]"}, {"id": "ch6:definition:6_3", "name": "definition 6.3", "statement": "Given \\(S_{n}=\\{Z_{1},\\ldots,Z_{n}\\}\\), the (one-sided) empirical Rademacher complexity of \\(\\mathcal{G}\\) is defined as\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n}) = \\mathbb{E}_{\\sigma}\\sup_{w\\in \\Omega}\\frac{1}{n}\\sum_{i = 1}^{n}\\sigma_{i}\\phi (w,Z_{i}),\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R(\\mathcal{G},\\mathcal{S}_{n}).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\nabbrev L2BallIndex (m : ℕ) (A : ℝ) : Type :=\n {w : EuclideanSpace ℝ (Fin m) // ‖w‖ ≤ A}\n\ndef linPred (m : ℕ) (A : ℝ) {𝒳 : Type*} (ψ : 𝒳 → Fin m → ℝ)\n (w : L2BallIndex m A) (x : 𝒳) : ℝ :=\n ∑ j : Fin m, w.1 j * ψ x j\n\ntheorem ch10_proposition_10_1 {𝒳 : Type*} [MeasurableSpace 𝒳] :\n ∃ c : ℝ, 0 < c ∧\n ∀ (m : ℕ) (A : ℝ) (ψ : 𝒳 → Fin m → ℝ) (D : Measure 𝒳)\n [IsProbabilityMeasure D],\n 0 ≤ A →\n (∀ j, Measurable (fun x => ψ x j)) →\n (∀ j k, Integrable (fun x => ψ x j * ψ x k) D) →\n (∀ j k, ∫ x, ψ x j * ψ x k ∂D = if j = k then 1 else 0) →\n ∃ N₀ : ℕ, ∀ n : ℕ, N₀ ≤ n →\n c * Real.sqrt ((m : ��) / (n : ℝ)) * A ≤\n popRadSigned n (linPred m A ψ) D (id : 𝒳 → 𝒳) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\nabbrev L2BallIndex (m : ℕ) (A : ℝ) : Type :=\n {w : EuclideanSpace ℝ (Fin m) // ‖w‖ ≤ A}\n\ndef linPred (m : ℕ) (A : ℝ) {𝒳 : Type*} (ψ : 𝒳 → Fin m → ℝ)\n (w : L2BallIndex m A) (x : 𝒳) : ℝ :=\n ∑ j : Fin m, w.1 j * ψ x j\n\nprivate lemma iSup_l2Ball_inner {m : ℕ} {A : ℝ} (hA : 0 ≤ A)\n (v : EuclideanSpace ℝ (Fin m)) :\n (⨆ w : L2BallIndex m A, ∑ j : Fin m, w.1 j * v j) = A * ‖v‖ := by\n classical\n let w₀ : L2BallIndex m A := ⟨0, by simpa using hA⟩\n letI : Nonempty (L2BallIndex m A) := ⟨w₀⟩\n have hinner (x y : EuclideanSpace ℝ (Fin m)) :\n (∑ j : Fin m, x j * y j) = inner ℝ x y := by\n rw [PiLp.inner_apply]\n simp only [RCLike.inner_apply, conj_trivial]\n exact Finset.sum_congr rfl fun _ _ => mul_comm _ _\n have huv : ∀ w : L2BallIndex m A,\n (∑ j : Fin m, w.1 j * v j) ≤ A * ‖v‖ := by\n intro w\n rw [hinner]\n exact (real_inner_le_norm w.1 v).trans\n (mul_le_mul_of_nonneg_right w.2 (norm_nonneg v))\n apply le_antisymm\n · exact ciSup_le huv\n · have hb : BddAbove (Set.range fun w : L2BallIndex m A =>\n ∑ j : Fin m, w.1 j * v j) := ⟨A * ‖v‖, by\n rintro _ ⟨w, rfl⟩\n exact huv w⟩\n by_cases hv : v = 0\n · subst v\n simp only [norm_zero, mul_zero]\n calc\n 0 = ∑ j : Fin m, w₀.1 j * (0 : EuclideanSpace ℝ (Fin m)) j := by\n simp [w₀]\n _ ≤ _ := le_ciSup hb w₀\n · let w : EuclideanSpace ℝ (Fin m) := (A / ‖v‖) • v\n have hw : ‖w‖ ≤ A := by\n rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg (div_nonneg hA (norm_nonneg v)),\n div_mul_cancel₀]\n exact norm_ne_zero_iff.mpr hv\n calc\n A * ‖v‖ = ∑ j : Fin m, (⟨w, hw⟩ : L2BallIndex m A).1 j * v j := by\n rw [hinner]\n simp only [w, real_inner_smul_left, real_inner_self_eq_norm_mul_norm]\n field_simp\n _ ≤ _ := le_ciSup hb (⟨w, hw⟩ : L2BallIndex m A)\n\nprivate lemma empiricalRademacherComplexity_without_abs_linPred\n {𝒳 : Type*} {m n : ℕ} {A : ℝ} (hA : 0 ≤ A)\n (ψ : 𝒳 → Fin m → ℝ) (S : Fin n → 𝒳) :\n empRadSigned n\n (linPred m A ψ) S =\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n A * ‖WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j)‖ := by\n classical\n unfold empRadSigned\n congr 1\n apply Finset.sum_congr rfl\n intro σ _\n let v : EuclideanSpace ℝ (Fin m) :=\n WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j)\n have hv (w : L2BallIndex m A) :\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * linPred m A ψ w (S k) =\n ∑ j : Fin m, w.1 j * v j := by\n simp only [linPred]\n dsimp only [v]\n calc\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) *\n ∑ j : Fin m, w.1 j * ψ (S k) j =\n ∑ k : Fin n, ∑ j : Fin m,\n (n : ℝ)⁻¹ * ((σ k : ℝ) * (w.1 j * ψ (S k) j)) := by\n simp_rw [Finset.mul_sum]\n _ = ∑ j : Fin m, ∑ k : Fin n,\n (n : ℝ)⁻¹ * ((σ k : ℝ) * (w.1 j * ψ (S k) j)) := Finset.sum_comm\n _ = ∑ j : Fin m, w.1 j *\n ((n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j) := by\n apply Finset.sum_congr rfl\n intro j _\n rw [Finset.mul_sum]\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro k _\n ring\n simp_rw [hv]\n exact iSup_l2Ball_inner hA v\n\nprivate lemma sum_sq_cubed_le_sum_abs_sq_mul_sum_fourth\n {ι : Type*} (s : Finset ι) (x : ι → ℝ) :\n (∑ i ∈ s, x i ^ 2) ^ 3 ≤\n (∑ i ∈ s, |x i|) ^ 2 * ∑ i ∈ s, x i ^ 4 := by\n classical\n let r : ι → ℝ := fun i => Real.sqrt |x i|\n have hr (i : ι) : r i ^ 2 = |x i| := by\n exact Real.sq_sqrt (abs_nonneg _)\n have h1 := Finset.sum_mul_sq_le_sq_mul_sq s r (fun i => r i ^ 3)\n have h2 := Finset.sum_mul_sq_le_sq_mul_sq s (fun i => |x i|) (fun i => x i ^ 2)\n have e1 : (∑ i ∈ s, r i * r i ^ 3) = ∑ i ∈ s, x i ^ 2 := by\n apply Finset.sum_congr rfl\n intro i _\n calc\n r i * r i ^ 3 = (r i ^ 2) ^ 2 := by ring\n _ = |x i| ^ 2 := by rw [hr]\n _ = x i ^ 2 := sq_abs _\n have e2 : (∑ i ∈ s, r i ^ 2) = ∑ i ∈ s, |x i| := by\n apply Finset.sum_congr rfl\n intro i _\n exact hr i\n have e3 : (∑ i ∈ s, (r i ^ 3) ^ 2) = ∑ i ∈ s, |x i| ^ 3 := by\n apply Finset.sum_congr rfl\n intro i _\n rw [← pow_mul, show 3 * 2 = 2 * 3 by norm_num, pow_mul, hr]\n have e4 : (∑ i ∈ s, |x i| * x i ^ 2) = ∑ i ∈ s, |x i| ^ 3 := by\n apply Finset.sum_congr rfl\n intro i _\n rw [← sq_abs]\n ring\n have e5 : (∑ i ∈ s, |x i| ^ 2) = ∑ i ∈ s, x i ^ 2 := by\n apply Finset.sum_congr rfl\n intro i _\n exact sq_abs (x i)\n have e6 : (∑ i ∈ s, (x i ^ 2) ^ 2) = ∑ i ∈ s, x i ^ 4 := by\n apply Finset.sum_congr rfl\n intro i _\n ring\n rw [e1, e2, e3] at h1\n rw [e4, e5, e6] at h2\n let S₁ := ∑ i ∈ s, |x i|\n let S₂ := ∑ i ∈ s, x i ^ 2\n let S₃ := ∑ i ∈ s, |x i| ^ 3\n let S₄ := ∑ i ∈ s, x i ^ 4\n have hS₁ : 0 ≤ S₁ := Finset.sum_nonneg fun _ _ => abs_nonneg _\n have hS₂ : 0 ≤ S₂ := Finset.sum_nonneg fun _ _ => sq_nonneg _\n have hS₃ : 0 ≤ S₃ := Finset.sum_nonneg fun _ _ => pow_nonneg (abs_nonneg _) _\n have hS₄ : 0 ≤ S₄ := Finset.sum_nonneg fun _ _ => by positivity\n change S₂ ^ 2 ≤ S₁ * S₃ at h1\n change S₃ ^ 2 ≤ S₂ * S₄ at h2\n change S₂ ^ 3 ≤ S₁ ^ 2 * S₄\n by_cases hz : S₂ = 0\n · rw [hz]\n norm_num\n exact mul_nonneg (sq_nonneg _) hS₄\n have hp : 0 < S₂ := lt_of_le_of_ne hS₂ (Ne.symm hz)\n nlinarith [sq_nonneg (S₁ * S₃), sq_nonneg (S₂ ^ 2)]\n\nprivate abbrev SignValue := {x // x ∈ ({-1, 1} : Finset ℤ)}\n\nprivate lemma signValue_eq_neg_one_or_one (s : SignValue) :\n s.1 = -1 ∨ s.1 = 1 := by\n have h := s.2\n rw [Finset.mem_insert, Finset.mem_singleton] at h\n exact h\n\nprivate lemma signValue_univ :\n (Finset.univ : Finset SignValue) =\n {⟨-1, by simp⟩, ⟨1, by simp⟩} := by\n ext s\n simp only [Finset.mem_univ, Finset.mem_insert, Finset.mem_singleton, true_iff]\n rcases signValue_eq_neg_one_or_one s with h | h\n · left\n exact Subtype.ext h\n · right\n exact Subtype.ext h\n\nprivate lemma sum_signValue_powers (a x : ℝ) :\n (∑ s : SignValue, (x + (s.1 : ℝ) * a) ^ 2) =\n 2 * (x ^ 2 + a ^ 2) ∧\n (∑ s : SignValue, (x + (s.1 : ℝ) * a) ^ 4) =\n 2 * x ^ 4 + 12 * x ^ 2 * a ^ 2 + 2 * a ^ 4 := by\n rw [signValue_univ]\n norm_num\n constructor <;> ring\n\nprivate def signSuccEquiv (n : ℕ) :\n RadSigns (n + 1) ≃\n SignValue × RadSigns n where\n toFun σ := (σ 0, fun i => σ i.succ)\n invFun p := Fin.cases p.1 p.2\n left_inv σ := by\n funext i\n refine Fin.cases ?_ (fun j => ?_) i <;> simp\n right_inv p := by\n rcases p with ⟨s, σ⟩\n ext <;> simp\n\nprivate lemma rademacher_second_fourth_moments (n : ℕ) (a : Fin n → ℝ) :\n (∑ σ : RadSigns n,\n (∑ i : Fin n, (σ i : ℝ) * a i) ^ 2) =\n (Fintype.card (RadSigns n) : ℝ) *\n ∑ i : Fin n, a i ^ 2 ∧\n (∑ σ : RadSigns n,\n (∑ i : Fin n, (σ i : ℝ) * a i) ^ 4) ≤\n 3 * (Fintype.card (RadSigns n) : ℝ) *\n (∑ i : Fin n, a i ^ 2) ^ 2 := by\n induction n with\n | zero =>\n simp [RadSigns]\n | succ n ih =>\n let b : ℝ := a 0\n let a' : Fin n → ℝ := fun i => a i.succ\n let X : RadSigns n → ℝ :=\n fun σ => ∑ i : Fin n, (σ i : ℝ) * a' i\n have hsum (s : SignValue) (σ : RadSigns n) :\n (∑ i : Fin (n + 1),\n (((signSuccEquiv n).symm (s, σ)) i : ℝ) * a i) =\n X σ + (s.1 : ℝ) * b := by\n rw [Fin.sum_univ_succ]\n simp only [signSuccEquiv, Equiv.coe_fn_symm_mk, Fin.cases_zero, Fin.cases_succ]\n dsimp only [X, a', b]\n ring\n have hcard :\n (Fintype.card (RadSigns (n + 1)) : ℝ) =\n 2 * (Fintype.card (RadSigns n) : ℝ) := by\n rw [Fintype.card_congr (signSuccEquiv n), Fintype.card_prod]\n norm_num [signValue_univ]\n have hsquares :\n (∑ i : Fin (n + 1), a i ^ 2) = b ^ 2 + ∑ i : Fin n, a' i ^ 2 := by\n rw [Fin.sum_univ_succ]\n constructor\n · calc\n (∑ σ : RadSigns (n + 1),\n (∑ i : Fin (n + 1), (σ i : ℝ) * a i) ^ 2) =\n ∑ p : SignValue × RadSigns n,\n (∑ i : Fin (n + 1),\n (((signSuccEquiv n).symm p) i : ℝ) * a i) ^ 2 := by\n symm\n exact (signSuccEquiv n).symm.sum_comp\n (fun σ => (∑ i : Fin (n + 1), (σ i : ℝ) * a i) ^ 2)\n _ = ∑ σ : RadSigns n,\n ∑ s : SignValue, (X σ + (s.1 : ℝ) * b) ^ 2 := by\n rw [Fintype.sum_prod_type, Finset.sum_comm]\n apply Finset.sum_congr rfl\n intro σ _\n apply Finset.sum_congr rfl\n intro s _\n rw [hsum]\n _ = ∑ σ : RadSigns n, 2 * (X σ ^ 2 + b ^ 2) := by\n apply Finset.sum_congr rfl\n intro σ _\n exact (sum_signValue_powers b (X σ)).1\n _ = 2 * ((Fintype.card (RadSigns n) : ℝ) * b ^ 2 +\n ∑ σ : RadSigns n, X σ ^ 2) := by\n simp_rw [mul_add]\n rw [Finset.sum_add_distrib]\n simp\n rw [← Finset.mul_sum]\n ring\n _ = (Fintype.card (RadSigns (n + 1)) : ℝ) *\n ∑ i : Fin (n + 1), a i ^ 2 := by\n rw [ih a' |>.1, hcard, hsquares]\n ring\n · calc\n (∑ σ : RadSigns (n + 1),\n (∑ i : Fin (n + 1), (σ i : ℝ) * a i) ^ 4) =\n ∑ p : SignValue × RadSigns n,\n (∑ i : Fin (n + 1),\n (((signSuccEquiv n).symm p) i : ℝ) * a i) ^ 4 := by\n symm\n exact (signSuccEquiv n).symm.sum_comp\n (fun σ => (∑ i : Fin (n + 1), (σ i : ℝ) * a i) ^ 4)\n _ = ∑ σ : RadSigns n,\n ∑ s : SignValue, (X σ + (s.1 : ℝ) * b) ^ 4 := by\n rw [Fintype.sum_prod_type, Finset.sum_comm]\n apply Finset.sum_congr rfl\n intro σ _\n apply Finset.sum_congr rfl\n intro s _\n rw [hsum]\n _ = ∑ σ : RadSigns n,\n (2 * X σ ^ 4 + 12 * X σ ^ 2 * b ^ 2 + 2 * b ^ 4) := by\n apply Finset.sum_congr rfl\n intro σ _\n exact (sum_signValue_powers b (X σ)).2\n _ = 2 * (∑ σ : RadSigns n, X σ ^ 4) +\n 12 * b ^ 2 * (∑ σ : RadSigns n, X σ ^ 2) +\n 2 * (Fintype.card (RadSigns n) : ℝ) * b ^ 4 := by\n simp_rw [Finset.sum_add_distrib, ← Finset.mul_sum]\n have hm : (∑ x : RadSigns n,\n 12 * X x ^ 2 * b ^ 2) =\n 12 * b ^ 2 * ∑ x : RadSigns n, X x ^ 2 := by\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro x _\n ring\n have hcst : (∑ _x : RadSigns n, b ^ 4) =\n (Fintype.card (RadSigns n) : ℝ) * b ^ 4 := by\n simp\n rw [hm, hcst]\n ring\n _ ≤ 2 * (3 * (Fintype.card (RadSigns n) : ℝ) *\n (∑ i : Fin n, a' i ^ 2) ^ 2) +\n 12 * b ^ 2 * (∑ σ : RadSigns n, X σ ^ 2) +\n 2 * (Fintype.card (RadSigns n) : ℝ) * b ^ 4 := by\n gcongr\n exact ih a' |>.2\n _ = 6 * (Fintype.card (RadSigns n) : ℝ) *\n (∑ i : Fin n, a' i ^ 2) ^ 2 +\n 12 * b ^ 2 *\n ((Fintype.card (RadSigns n) : ℝ) *\n ∑ i : Fin n, a' i ^ 2) +\n 2 * (Fintype.card (RadSigns n) : ℝ) * b ^ 4 := by\n rw [ih a' |>.1]\n ring\n _ ≤ 3 * (Fintype.card (RadSigns (n + 1)) : ℝ) *\n (∑ i : Fin (n + 1), a i ^ 2) ^ 2 := by\n rw [hcard, hsquares]\n have hc : 0 ≤ (Fintype.card\n (RadSigns n) : ℝ) := by positivity\n have hb2 : 0 ≤ b ^ 2 := sq_nonneg _\n have ha2 : 0 ≤ ∑ i : Fin n, a' i ^ 2 :=\n Finset.sum_nonneg fun _ _ => sq_nonneg _\n ring_nf\n nlinarith [mul_nonneg hc (sq_nonneg (b ^ 2))]\n\nprivate lemma rademacher_sum_abs_lower (n : ℕ) (a : Fin n → ℝ) :\n (Fintype.card (RadSigns n) : ℝ) *\n Real.sqrt (∑ i : Fin n, a i ^ 2) ≤\n 2 * ∑ σ : RadSigns n,\n |∑ i : Fin n, (σ i : ℝ) * a i| := by\n let C : ℝ := Fintype.card (RadSigns n)\n let Q : ℝ := ∑ i : Fin n, a i ^ 2\n let L : ℝ := ∑ σ : RadSigns n,\n |∑ i : Fin n, (σ i : ℝ) * a i|\n let M₂ : ℝ := ∑ σ : RadSigns n,\n (∑ i : Fin n, (σ i : ℝ) * a i) ^ 2\n let M₄ : ℝ := ∑ σ : RadSigns n,\n (∑ i : Fin n, (σ i : ℝ) * a i) ^ 4\n have hm := rademacher_second_fourth_moments n a\n have hm2 : M₂ = C * Q := hm.1\n have hm4 : M₄ ≤ 3 * C * Q ^ 2 := hm.2\n have hinterp : M₂ ^ 3 ≤ L ^ 2 * M₄ := by\n exact sum_sq_cubed_le_sum_abs_sq_mul_sum_fourth Finset.univ\n (fun σ : RadSigns n =>\n ∑ i : Fin n, (σ i : ℝ) * a i)\n have hC : 0 < C := by\n dsimp only [C]\n exact_mod_cast Fintype.card_pos_iff.mpr\n ⟨fun _ : Fin n => (⟨1, by simp⟩ : SignValue)⟩\n have hQ : 0 ≤ Q := by\n exact Finset.sum_nonneg fun _ _ => sq_nonneg _\n have hL : 0 ≤ L := by\n exact Finset.sum_nonneg fun _ _ => abs_nonneg _\n by_cases hQ0 : Q = 0\n · change C * Real.sqrt Q ≤ 2 * L\n rw [hQ0]\n simpa using mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) hL\n have hQpos : 0 < Q := lt_of_le_of_ne hQ (Ne.symm hQ0)\n have hmain : (C * Q) ^ 3 ≤ L ^ 2 * (3 * C * Q ^ 2) := by\n calc\n (C * Q) ^ 3 = M₂ ^ 3 := by rw [hm2]\n _ ≤ L ^ 2 * M₄ := hinterp\n _ ≤ L ^ 2 * (3 * C * Q ^ 2) :=\n mul_le_mul_of_nonneg_left hm4 (sq_nonneg L)\n have hcancel : C ^ 2 * Q ≤ 3 * L ^ 2 := by\n have hfactor : (C * Q ^ 2) * (C ^ 2 * Q) ≤\n (C * Q ^ 2) * (3 * L ^ 2) := by\n convert hmain using 1 <;> ring\n exact le_of_mul_le_mul_left hfactor (mul_pos hC (sq_pos_of_pos hQpos))\n have hsqrt : Real.sqrt Q ^ 2 = Q := Real.sq_sqrt hQ\n apply (sq_le_sq₀ (mul_nonneg hC.le (Real.sqrt_nonneg Q))\n (mul_nonneg (by norm_num) hL)).mp\n calc\n (C * Real.sqrt Q) ^ 2 = C ^ 2 * Q := by rw [mul_pow, hsqrt]\n _ ≤ 3 * L ^ 2 := hcancel\n _ ≤ (2 * L) ^ 2 := by nlinarith [sq_nonneg L]\n\nprivate lemma sum_abs_le_sqrt_card_mul_norm {m : ℕ}\n (v : EuclideanSpace ℝ (Fin m)) :\n (∑ j : Fin m, |v j|) ≤ Real.sqrt (m : ℝ) * ‖v‖ := by\n have hcs := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset (Fin m))\n (fun _ => (1 : ℝ)) (fun j => |v j|)\n have hsum : (∑ j : Fin m, v j ^ 2) = ‖v‖ ^ 2 := by\n calc\n (∑ j : Fin m, v j ^ 2) = inner ℝ v v := by\n rw [PiLp.inner_apply]\n apply Finset.sum_congr rfl\n intro j _\n simp only [RCLike.inner_apply, conj_trivial]\n ring\n _ = ‖v‖ ^ 2 := real_inner_self_eq_norm_sq v\n have hsqrt : Real.sqrt (m : ℝ) ^ 2 = (m : ℝ) :=\n Real.sq_sqrt (Nat.cast_nonneg m)\n have hsquares :\n (∑ j : Fin m, |v j|) ^ 2 ≤\n (Real.sqrt (m : ℝ) * ‖v‖) ^ 2 := by\n simpa only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, Fintype.card_fin,\n nsmul_eq_mul, Nat.cast_ofNat, mul_one, sq_abs, mul_pow, hsqrt, hsum] using hcs\n exact (sq_le_sq₀ (Finset.sum_nonneg fun _ _ => abs_nonneg _)\n (mul_nonneg (Real.sqrt_nonneg _) (norm_nonneg _))).mp hsquares\n\nprivate lemma sqrt_sum_sq_le_sum_abs {ι : Type*} [Fintype ι] (a : ι → ℝ) :\n Real.sqrt (∑ i, a i ^ 2) ≤ ∑ i, |a i| := by\n have hnonneg : 0 ≤ ∑ i, a i ^ 2 :=\n Finset.sum_nonneg fun _ _ => sq_nonneg _\n apply (sq_le_sq₀ (Real.sqrt_nonneg _) (Finset.sum_nonneg fun _ _ => abs_nonneg _)).mp\n rw [Real.sq_sqrt hnonneg]\n simpa only [sq_abs] using\n (Finset.sum_sq_le_sq_sum_of_nonneg (s := Finset.univ)\n (f := fun i => |a i|) (fun _ _ => abs_nonneg _))\n\nprivate lemma eventually_empirical_energy_good\n {𝒳 : Type*} [MeasurableSpace 𝒳] (D : Measure 𝒳) [IsProbabilityMeasure D]\n (f : 𝒳 → ℝ) (hf : Measurable f)\n (hf2 : Integrable (fun x => f x ^ 2) D)\n (hmean : ∫ x, f x ^ 2 ∂D = 1) :\n ∃ N : ℕ, ∀ n : ℕ, N ≤ n →\n (Measure.pi (fun _ : Fin n => D)).real\n {S | (n : ℝ) / 4 ≤ ∑ k : Fin n, f (S k) ^ 2} ≥ 1 / 2 := by\n let g : 𝒳 → ℝ := fun x => f x ^ 2\n have hg : Measurable g := hf.pow_const 2\n have hgnonneg : 0 ≤ g := fun _ => sq_nonneg _\n obtain ⟨B : ℝ, hB : 1 / 2 < ∫ x, ProbabilityTheory.truncation g B x ∂D⟩ := by\n have ht := ProbabilityTheory.tendsto_integral_truncation hf2\n rw [hmean] at ht\n exact ((tendsto_order.1 ht).1 (1 / 2) (by norm_num)).exists\n let Y : 𝒳 → ℝ := ProbabilityTheory.truncation g B\n have hYmeas : Measurable Y := by\n dsimp only [Y]\n unfold ProbabilityTheory.truncation\n exact (measurable_id.indicator measurableSet_Ioc).comp hg\n have hYnonneg : 0 ≤ Y :=\n fun x => ProbabilityTheory.truncation_nonneg B (hgnonneg x)\n have hYbound : ∀ x, Y x ≤ |B| := fun x =>\n (le_abs_self _).trans (ProbabilityTheory.abs_truncation_le_bound g B x)\n let q : ℝ := ∫ x, Y x ∂D\n have hq : 1 / 2 < q := hB\n obtain ⟨N : ℕ, hN : max (1 : ℝ) (8 * |B| ^ 2) ≤ (N : ℝ)⟩ :=\n exists_nat_ge (max (1 : ℝ) (8 * |B| ^ 2))\n refine ⟨N, fun n hn => ?_⟩\n have hn1 : 1 ≤ n := by\n exact_mod_cast (le_trans (le_max_left _ _) (hN.trans (Nat.cast_le.2 hn)))\n have hnpos : 0 < (n : ℝ) := by positivity\n let μn : Measure (Fin n → 𝒳) := Measure.pi (fun _ : Fin n => D)\n let Yk : Fin n → (Fin n → 𝒳) → ℝ := fun k S => Y (S k)\n let Z : (Fin n → 𝒳) → ℝ := fun S => ∑ k : Fin n, Yk k S\n have hYmem : MemLp Y 2 D := by\n simpa only [Y] using\n (hg.aestronglyMeasurable.memLp_truncation (A := B) (p := 2))\n have hYkmem : ∀ k, MemLp (Yk k) 2 μn := by\n intro k\n exact hYmem.comp_measurePreserving\n (measurePreserving_eval (fun _ : Fin n => D) k)\n have hZmem : MemLp Z 2 μn := by\n have h := memLp_finset_sum' Finset.univ fun k _ => hYkmem k\n convert h using 1\n ext S\n simp only [Z, Finset.sum_apply]\n have hZint : ∫ S, Z S ∂μn = (n : ℝ) * q := by\n rw [integral_finset_sum Finset.univ fun k _ =>\n (hYkmem k).integrable (by norm_num)]\n have heval : ∀ k, ∫ S, Yk k S ∂μn = q := by\n intro k\n dsimp only [Yk, μn, q]\n have hmap := (measurePreserving_eval (fun _ : Fin n => D) k).map_eq\n have hm : AEStronglyMeasurable Y\n (Measure.map (fun S : Fin n → 𝒳 => S k)\n (Measure.pi (fun _ : Fin n => D))) := by\n rw [hmap]\n exact hYmeas.aestronglyMeasurable\n calc\n (∫ S : Fin n → 𝒳, Y (S k) ∂Measure.pi (fun _ : Fin n => D)) =\n ∫ x, Y x ∂Measure.map (fun S : Fin n → 𝒳 => S k)\n (Measure.pi (fun _ : Fin n => D)) :=\n (integral_map\n (μ := Measure.pi (fun _ : Fin n => D))\n (φ := fun S : Fin n → 𝒳 => S k) (f := Y)\n (measurable_pi_apply k).aemeasurable hm).symm\n _ = ∫ x, Y x ∂D := by rw [hmap]\n simp_rw [heval]\n simp\n have hvarY : ProbabilityTheory.variance Y D ≤ (|B| / 2) ^ 2 := by\n simpa only [sub_zero] using ProbabilityTheory.variance_le_sq_of_bounded\n (μ := D) (a := 0) (b := |B|)\n (Filter.Eventually.of_forall fun x => ⟨hYnonneg x, hYbound x⟩)\n hYmeas.aemeasurable\n have hvarZ : ProbabilityTheory.variance Z μn ≤\n (n : ℝ) * (|B| / 2) ^ 2 := by\n have hi := ProbabilityTheory.iIndepFun_pi\n (μ := fun _ : Fin n => D) (X := fun _ => Y)\n (fun _ => hYmeas.aemeasurable)\n have hvsum := ProbabilityTheory.IndepFun.variance_sum\n (s := (Finset.univ : Finset (Fin n)))\n (fun k _ => hYkmem k)\n (fun i _ j _ hij => hi.indepFun hij)\n have hvsum' : ProbabilityTheory.variance Z μn =\n ∑ k : Fin n, ProbabilityTheory.variance (Yk k) μn := by\n have hZeq : Z = ∑ k : Fin n, Yk k := by\n funext S\n simp only [Z, Finset.sum_apply]\n rw [hZeq]\n exact hvsum\n rw [hvsum']\n calc\n (∑ k : Fin n, ProbabilityTheory.variance (Yk k) μn) ≤\n ∑ _k : Fin n, (|B| / 2) ^ 2 := by\n gcongr with k\n rw [(measurePreserving_eval\n (fun _ : Fin n => D) k).variance_fun_comp hYmeas.aemeasurable]\n exact hvarY\n _ = (n : ℝ) * (|B| / 2) ^ 2 := by simp\n let E : Set (Fin n → 𝒳) :=\n {S | (n : ℝ) / 4 ≤ |Z S - ∫ T, Z T ∂μn|}\n have hZmeas : Measurable Z := by\n dsimp only [Z, Yk]\n fun_prop\n have hEmeas : MeasurableSet E := by\n dsimp only [E]\n exact measurableSet_le measurable_const\n ((hZmeas.sub measurable_const).abs)\n have hcheb : μn E ≤ ENNReal.ofReal\n (ProbabilityTheory.variance Z μn / ((n : ℝ) / 4) ^ 2) := by\n exact ProbabilityTheory.meas_ge_le_variance_div_sq hZmem (by positivity)\n have hratio : ProbabilityTheory.variance Z μn / ((n : ℝ) / 4) ^ 2 ≤ 1 / 2 := by\n calc\n ProbabilityTheory.variance Z μn / ((n : ℝ) / 4) ^ 2 ≤\n ((n : ℝ) * (|B| / 2) ^ 2) / ((n : ℝ) / 4) ^ 2 :=\n div_le_div_of_nonneg_right hvarZ (sq_nonneg _)\n _ = 4 * |B| ^ 2 / (n : ℝ) := by field_simp; ring\n _ ≤ 1 / 2 := by\n have hnB : 8 * |B| ^ 2 ≤ (n : ℝ) :=\n (le_max_right 1 _).trans (hN.trans (Nat.cast_le.2 hn))\n apply (div_le_iff₀ hnpos).2\n linarith\n have hEreal : μn.real E ≤ 1 / 2 := by\n rw [Measure.real, ← ENNReal.toReal_ofReal (by norm_num : (0 : ℝ) ≤ 1 / 2)]\n apply ENNReal.toReal_mono\n · finiteness\n exact hcheb.trans (ENNReal.ofReal_le_ofReal hratio)\n have hEcReal : μn.real Eᶜ ≥ 1 / 2 := by\n rw [probReal_compl_eq_one_sub hEmeas]\n linarith\n have hsubset : Eᶜ ⊆\n {S | (n : ℝ) / 4 ≤ ∑ k : Fin n, f (S k) ^ 2} := by\n intro S hSE\n have hdev : |Z S - ∫ T, Z T ∂μn| < (n : ℝ) / 4 := by\n simpa [E, Set.mem_compl_iff, not_le] using hSE\n have hZlower : (n : ℝ) / 4 < Z S := by\n rw [hZint] at hdev\n have : (n : ℝ) / 2 < (n : ℝ) * q := by\n nlinarith [mul_pos hnpos (sub_pos.mpr hq)]\n rw [abs_lt] at hdev\n linarith\n exact hZlower.le.trans (Finset.sum_le_sum fun k _ => by\n change Y (S k) ≤ g (S k)\n exact ((le_abs_self _).trans\n (ProbabilityTheory.abs_truncation_le_abs_self g B (S k))).trans_eq\n (abs_of_nonneg (hgnonneg (S k))))\n exact hEcReal.trans (measureReal_mono hsubset)\n\nprivate lemma empirical_linPred_lower\n {𝒳 : Type*} {m n : ℕ} {A : ℝ} (hm : 0 < m) (hn : 0 < n)\n (hA : 0 ≤ A) (ψ : 𝒳 → Fin m → ℝ) (S : Fin n → 𝒳) :\n A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) *\n (∑ j : Fin m, Real.sqrt (∑ k : Fin n, ψ (S k) j ^ 2)) ≤\n empRadSigned n\n (linPred m A ψ) S := by\n let C : ℝ := Fintype.card (RadSigns n)\n have hC : 0 < C := by\n dsimp only [C]\n exact_mod_cast Fintype.card_pos_iff.mpr\n ⟨fun _ : Fin n => (⟨1, by simp⟩ : SignValue)⟩\n have hnR : 0 < (n : ℝ) := by positivity\n have hmR : 0 < (m : ℝ) := by positivity\n have hsqrtm : 0 < Real.sqrt (m : ℝ) := Real.sqrt_pos.2 hmR\n rw [empiricalRademacherComplexity_without_abs_linPred hA]\n have hnorm (σ : RadSigns n) :\n (n : ℝ)⁻¹ / Real.sqrt (m : ℝ) *\n (∑ j : Fin m, |∑ k : Fin n, (σ k : ℝ) * ψ (S k) j|) ≤\n ‖WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (�� k : ℝ) * ψ (S k) j)‖ := by\n rw [div_mul_eq_mul_div]\n apply (div_le_iff₀ hsqrtm).2\n have hl1 := sum_abs_le_sqrt_card_mul_norm\n (WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j))\n have hinv : 0 ≤ (n : ℝ)⁻¹ := inv_nonneg.2 hnR.le\n have habs : (∑ j : Fin m,\n |(n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j|) =\n (n : ℝ)⁻¹ *\n ∑ j : Fin m, |∑ k : Fin n, (σ k : ℝ) * ψ (S k) j| := by\n simp_rw [abs_mul, abs_of_nonneg hinv, Finset.mul_sum]\n rw [habs] at hl1\n nlinarith\n have hsumNorm :\n C / (2 * Real.sqrt (m : ℝ)) * (n : ℝ)⁻¹ *\n (∑ j : Fin m, Real.sqrt (∑ k : Fin n, ψ (S k) j ^ 2)) ≤\n ∑ σ : RadSigns n,\n ‖WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j)‖ := by\n calc\n C / (2 * Real.sqrt (m : ℝ)) * (n : ℝ)⁻¹ *\n (∑ j : Fin m, Real.sqrt (∑ k : Fin n, ψ (S k) j ^ 2)) =\n (n : ℝ)⁻¹ / Real.sqrt (m : ℝ) *\n ∑ j : Fin m, (C / 2) *\n Real.sqrt (∑ k : Fin n, ψ (S k) j ^ 2) := by\n conv_lhs => rw [Finset.mul_sum]\n conv_rhs => rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro j _\n ring\n _ ≤ (n : ℝ)⁻¹ / Real.sqrt (m : ℝ) *\n ∑ j : Fin m, ∑ σ : RadSigns n,\n |∑ k : Fin n, (σ k : ℝ) * ψ (S k) j| := by\n gcongr with j\n have hk := rademacher_sum_abs_lower n (fun k => ψ (S k) j)\n nlinarith\n _ = ∑ σ : RadSigns n,\n ((n : ℝ)⁻¹ / Real.sqrt (m : ℝ) *\n ∑ j : Fin m, |∑ k : Fin n, (σ k : ℝ) * ψ (S k) j|) := by\n rw [Finset.sum_comm, Finset.mul_sum]\n _ ≤ _ := Finset.sum_le_sum fun σ _ => hnorm σ\n calc\n A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) *\n (∑ j : Fin m, Real.sqrt (∑ k : Fin n, ψ (S k) j ^ 2)) =\n C⁻¹ * (A * (C / (2 * Real.sqrt (m : ℝ)) * (n : ℝ)⁻¹ *\n (∑ j : Fin m, Real.sqrt (∑ k : Fin n, ψ (S k) j ^ 2)))) := by\n field_simp\n _ ≤ C⁻¹ * (A * ∑ σ : RadSigns n,\n ‖WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j)‖) := by\n gcongr\n _ = C⁻¹ * ∑ σ : RadSigns n,\n A * ‖WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j)‖ := by\n rw [Finset.mul_sum]\n _ = _ := rfl\n\ntheorem ch10_proposition_10_1 {𝒳 : Type*} [MeasurableSpace 𝒳] :\n ∃ c : ℝ, 0 < c ∧\n ∀ (m : ℕ) (A : ℝ) (ψ : 𝒳 → Fin m → ℝ) (D : Measure 𝒳)\n [IsProbabilityMeasure D],\n 0 ≤ A →\n (∀ j, Measurable (fun x => ψ x j)) →\n (∀ j k, Integrable (fun x => ψ x j * ψ x k) D) →\n (∀ j k, ∫ x, ψ x j * ψ x k ∂D = if j = k then 1 else 0) →\n ∃ N₀ : ℕ, ∀ n : ℕ, N₀ ≤ n →\n c * Real.sqrt ((m : ℝ) / (n : ℝ)) * A ≤\n popRadSigned n (linPred m A ψ) D (id : 𝒳 → 𝒳) := by\n classical\n refine ⟨1 / 16, by norm_num, ?_⟩\n intro m A ψ D inst hA hψ hψprod horth\n by_cases hm0 : m = 0\n · subst m\n refine ⟨0, fun n _ => ?_⟩\n simp [popRadSigned,\n empRadSigned, linPred]\n have hm : 0 < m := Nat.pos_of_ne_zero hm0\n have hψ2int (j : Fin m) : Integrable (fun x => ψ x j ^ 2) D := by\n simpa only [pow_two] using hψprod j j\n have hψ2mean (j : Fin m) : ∫ x, ψ x j ^ 2 ∂D = 1 := by\n simpa only [pow_two] using horth j j\n have henergy (j : Fin m) :\n ∃ N : ℕ, ∀ n : ℕ, N ≤ n →\n (Measure.pi (fun _ : Fin n => D)).real\n {S | (n : ℝ) / 4 ≤ ∑ k : Fin n, ψ (S k) j ^ 2} ≥ 1 / 2 :=\n eventually_empirical_energy_good D (fun x => ψ x j) (hψ j)\n (hψ2int j) (hψ2mean j)\n choose N hN using henergy\n let N₀ : ℕ := 1 + ∑ j : Fin m, N j\n refine ⟨N₀, fun n hn => ?_⟩\n have hnNat : 0 < n := by\n have : 1 ≤ N₀ := by simp [N₀]\n omega\n have hnR : 0 < (n : ℝ) := by positivity\n have hmR : 0 < (m : ℝ) := by positivity\n have hsqrtm : 0 < Real.sqrt (m : ℝ) := Real.sqrt_pos.2 hmR\n have hsqrtn : 0 < Real.sqrt (n : ℝ) := Real.sqrt_pos.2 hnR\n let μn : Measure (Fin n → 𝒳) := Measure.pi (fun _ : Fin n => D)\n let F : Fin m → (Fin n → 𝒳) → ℝ :=\n fun j S => Real.sqrt (∑ k : Fin n, ψ (S k) j ^ 2)\n have hNj (j : Fin m) : N j ≤ n := by\n have hjle : N j ≤ ∑ i : Fin m, N i :=\n Finset.single_le_sum (fun _ _ => Nat.zero_le _) (Finset.mem_univ j)\n omega\n have hgood (j : Fin m) :\n μn.real {S | (n : ℝ) / 4 ≤ ∑ k : Fin n, ψ (S k) j ^ 2} ≥ 1 / 2 := by\n exact hN j n (hNj j)\n have hψint (j : Fin m) : Integrable (fun x => ψ x j) D := by\n have hmem : MemLp (fun x => ψ x j) 2 D :=\n (memLp_two_iff_integrable_sq (hψ j).aestronglyMeasurable).2 (hψ2int j)\n exact hmem.integrable (by norm_num)\n have hevalInt (j : Fin m) (k : Fin n) :\n Integrable (fun S : Fin n → 𝒳 => ψ (S k) j) μn := by\n have hp := measurePreserving_eval (fun _ : Fin n => D) k\n exact (hp.integrable_comp (hψ j).aestronglyMeasurable).2 (hψint j)\n have hFmeas (j : Fin m) : Measurable (F j) := by\n dsimp only [F]\n fun_prop\n have hFint (j : Fin m) : Integrable (F j) μn := by\n have hmajor : Integrable\n (fun S : Fin n → 𝒳 => ∑ k : Fin n, |ψ (S k) j|) μn :=\n integrable_finset_sum Finset.univ fun k _ => (hevalInt j k).abs\n apply hmajor.mono' (hFmeas j).aestronglyMeasurable\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_of_nonneg (Real.sqrt_nonneg _)]\n exact sqrt_sum_sq_le_sum_abs (fun k : Fin n => ψ (S k) j)\n have hFexpect (j : Fin m) : Real.sqrt (n : ℝ) / 4 ≤ ∫ S, F j S ∂μn := by\n let G : Set (Fin n → 𝒳) :=\n {S | (n : ℝ) / 4 ≤ ∑ k : Fin n, ψ (S k) j ^ 2}\n have hGmeas : MeasurableSet G := by\n dsimp only [G]\n apply measurableSet_le measurable_const\n fun_prop\n have hconstint : Integrable\n (G.indicator (fun _ : Fin n → 𝒳 => Real.sqrt ((n : ℝ) / 4))) μn :=\n (integrable_const _).indicator hGmeas\n have hmono : ∫ S, G.indicator\n (fun _ : Fin n → 𝒳 => Real.sqrt ((n : ℝ) / 4)) S ∂μn ≤\n ∫ S, F j S ∂μn := by\n apply integral_mono hconstint (hFint j)\n intro S\n by_cases hSG : S ∈ G\n · rw [Set.indicator_of_mem hSG]\n exact Real.sqrt_le_sqrt hSG\n · rw [Set.indicator_of_notMem hSG]\n exact Real.sqrt_nonneg _\n calc\n Real.sqrt (n : ℝ) / 4 =\n (1 / 2) * Real.sqrt ((n : ℝ) / 4) := by\n rw [Real.sqrt_div (Nat.cast_nonneg n), show Real.sqrt (4 : ℝ) = 2 by norm_num]\n ring\n _ ≤ μn.real G * Real.sqrt ((n : ℝ) / 4) := by\n gcongr\n exact hgood j\n _ = ∫ S, G.indicator\n (fun _ : Fin n → 𝒳 => Real.sqrt ((n : ℝ) / 4)) S ∂μn := by\n rw [integral_indicator_const _ hGmeas]\n rfl\n _ ≤ _ := hmono\n have hempInt :\n Integrable\n (fun S : Fin n → 𝒳 =>\n empRadSigned n\n (linPred m A ψ) S) μn := by\n rw [show (fun S : Fin n → 𝒳 =>\n empRadSigned n\n (linPred m A ψ) S) =\n fun S => (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n,\n A * ‖WithLp.toLp 2 (fun j : Fin m =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * ψ (S k) j)‖ by\n funext S\n exact empiricalRademacherComplexity_without_abs_linPred hA ψ S]\n apply Integrable.const_mul\n apply integrable_finset_sum Finset.univ\n intro σ _\n apply Integrable.const_mul\n apply Integrable.norm\n apply Integrable.of_eval_piLp\n intro j\n apply Integrable.const_mul\n apply integrable_finset_sum Finset.univ\n intro k _\n exact (hevalInt j k).const_mul _\n have hpopLower :\n A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) *\n ∑ j : Fin m, (∫ S, F j S ∂μn) ≤\n popRadSigned n\n (linPred m A ψ) D (id : 𝒳 → 𝒳) := by\n unfold popRadSigned\n have hcoef : 0 ≤ A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) := by positivity\n calc\n A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) *\n ∑ j : Fin m, (∫ S, F j S ∂μn) =\n ∫ S, (A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) *\n ∑ j : Fin m, F j S) ∂μn := by\n rw [integral_const_mul]\n congr 1\n rw [integral_finset_sum Finset.univ fun j _ => hFint j]\n _ ≤ ∫ S, empRadSigned n\n (linPred m A ψ) S ∂μn := by\n apply integral_mono_of_nonneg\n · exact Filter.Eventually.of_forall fun S =>\n mul_nonneg hcoef (Finset.sum_nonneg fun _ _ => Real.sqrt_nonneg _)\n · exact hempInt\n · exact Filter.Eventually.of_forall fun S =>\n empirical_linPred_lower hm hnNat hA ψ S\n _ = _ := rfl\n calc\n (1 / 16) * Real.sqrt ((m : ℝ) / (n : ℝ)) * A ≤\n A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) *\n ∑ _j : Fin m, (Real.sqrt (n : ℝ) / 4) := by\n rw [Real.sqrt_div hmR.le, Finset.sum_const, Finset.card_univ,\n Fintype.card_fin, nsmul_eq_mul]\n have hsqrtm_sq : Real.sqrt (m : ℝ) ^ 2 = (m : ℝ) :=\n Real.sq_sqrt hmR.le\n have hsqrtn_sq : Real.sqrt (n : ℝ) ^ 2 = (n : ℝ) :=\n Real.sq_sqrt hnR.le\n field_simp\n rw [hsqrtm_sq, hsqrtn_sq]\n nlinarith [mul_nonneg (mul_nonneg hA (Nat.cast_nonneg m))\n (Nat.cast_nonneg n)]\n _ ≤ A * (n : ℝ)⁻¹ / (2 * Real.sqrt (m : ℝ)) *\n ∑ j : Fin m, (∫ S, F j S ∂μn) := by\n gcongr with j\n exact hFexpect j\n _ ��� _ := hpopLower\n\nend GraduateLevel\n"} +{"id": "ch10_proposition_10_35", "source": "Graduate-level", "targets": [{"label": "ch10_proposition_10_35", "decls": ["ch10_proposition_10_35"], "statement": "Let \\(\\hat{F} = \\mathrm{supp}(\\hat{w})\\). If \\(X_{\\hat{F}}^{\\top}X_{\\hat{F}}\\) is positive definite, and\n\\[\nX_{\\hat{F}}^{\\top}\\left(X_{\\hat{F}}\\hat{w}_{\\hat{F}}-Y\\right)+\\lambda\\operatorname{sign}(\\hat{w})_{\\hat{F}}=0,\n\\]\n\\[\nX_{j}^{\\top}(X_{\\hat{F}}\\hat{w}_{\\hat{F}}-Y)\\in(-\\lambda,\\lambda)\\qquad(j\\not\\in\\hat{F}),\n\\]\nthen \\(\\hat{w}\\) is the unique solution of (10.20).", "topic_domain": "Optimization", "topic_subtopic": "Convex Analysis & Duality"}], "nl_proof": "We only need to show that for any \\(\\Delta w \\neq 0\\), \\(\\hat{w} + \\Delta w\\) is not a solution. For \\(j \\notin \\hat{F}\\), we define\n\\[\n\\lambda_{j}^{\\prime}= |X_{j}^{\\top}(X_{\\hat{F}}\\hat{w}_{\\hat{F}}-Y)| <\\lambda,\n\\]\nand let\n\\[\nQ_{L_{1}}^{\\prime}(w)=0. 5\\|Xw-Y\\|_{2}^{2}+\\lambda\\sum_{j\\in\\hat{F}}|w_{j}| +\\sum_{j\\notin\\hat{F}}\\lambda_{j}^{\\prime}|w_{j}|.\n\\]\nSince there exists a subgradient \\(\\nabla Q_{L_1}'(\\hat{w}) = 0\\), we know that \\(\\hat{w}\\) achieves the minimum of \\(Q_{L_1}'(w)\\), and thus \\(Q_{L_1}'(\\hat{w} + \\Delta w) \\geq Q_{L_1}'(\\hat{w}) = Q_{L_1}(\\hat{w})\\). Now, if \\(\\Delta w_j \\neq 0\\) for some \\(j \\notin \\hat{F}\\), then \\(Q_{L_1}(\\hat{w} + \\Delta w) > Q_{L_1}'(\\hat{w} + \\Delta w) \\geq Q_{L_1}(\\hat{w})\\), and thus \\(\\hat{w} + \\Delta w\\) is not a solution of the original Lasso problem. If \\(\\Delta w_j = 0\\) for all \\(j \\notin \\hat{F}\\), then \\(\\mathrm{supp}(\\hat{w} + \\Delta w) \\subset \\hat{F}\\). However, the positive definiteness of \\(X_{\\hat{F}}^\\top X_{\\hat{F}}\\) means that \\(Q_{L_1}(w)\\) is strictly convex when the support is restricted to \\(\\hat{F}\\), and hence the solution (with support restricted to \\(\\hat{F}\\)) is unique. This implies that \\(\\Delta w = 0\\).", "context": [{"id": "ch10:definition:10_2", "name": "definition 10.2", "statement": "The sparsity pattern, or support of a weight vector \\( w \\in \\mathbb{R}^m \\) is defined as\n\\[\n\\operatorname{supp}(w)=\\{j:w_{j}\\neq 0\\},\n\\]\nand the \\(L_0\\) norm of \\(w\\) is defined as\n\\[\n\\left\\|w\\right\\|_{0}=\\left|\\operatorname{supp}(w)\\right|.\n\\]"}, {"id": "ch10:equation:10_20", "name": "equation 10.20", "statement": "\\[\\hat{w} = \\arg\\min_w Q_{L_1}(w); \\quad Q_{L_1}(w) = \\frac{1}{2}\\left\\|Xw - Y\\right\\|_2^2 + \\lambda \\left\\|w\\right\\|_1, \\tag{10.20}\\] where \\(\\lambda > 0\\) is an appropriately chosen regularization parameter."}, {"id": "ch10:proposition:10_34", "name": "proposition 10.34", "statement": "Let \\(\\hat{F} = \\mathrm{supp}(\\hat{w})\\), then \\(\\hat{w}\\) is a solution of (10.20) if and\nonly if\n\\[\nX_{\\hat{F}}^{\\top}(X_{\\hat{F}}\\hat{w}_{\\hat{F}}-Y)+\\lambda\\mathrm{sign}(\\hat{w})_{\\hat{F}}=0,\n\\]\n\\[\nX_{j}^{\\top}(X_{\\hat{F}}\\hat{w}_{\\hat{F}}-Y)\\in [-\\lambda,\\lambda]\\qquad(j\\not\\in\\hat{F}),\n\\]\nwhere \\( X_{\\hat{F}} \\) contains columns of \\( X \\) with columns in \\( \\hat{F} \\), and \\( X_{j} \\) is the \\( j \\)-th column of \\( X \\)."}], "lean": "import Mathlib\n\nopen MeasureTheory Matrix Real\n\nnamespace GraduateLevel\n\nclass PosDefAsymm {α : Type*} [Fintype α] (A : Matrix α α ℝ) : Prop where\n pd : ∀ x, x ≠ 0 → 0 < x ⬝ᵥ (A *ᵥ x)\n\nnoncomputable def lassoObjective {n : ℕ} {ι : Type*} [Fintype ι]\n (X : Matrix (Fin n) ι ℝ) (Y : Fin n → ℝ) (lam : ℝ) (w : ι → ℝ) : ℝ :=\n (1 / 2) * (∑ i : Fin n, (X.mulVec w i - Y i) ^ 2) + lam * (∑ j : ι, |w j|)\n\ntheorem ch10_proposition_10_35\n {n : ℕ} {ι : Type*} [Fintype ι] [DecidableEq ι]\n (X : Matrix (Fin n) ι ℝ) (Y : Fin n → ℝ) (lam : ℝ) (ŵ : ι → ℝ)\n (hlam : 0 ≤ lam)\n (hPD : PosDefAsymm\n ((X.submatrix (id : Fin n → Fin n) (Subtype.val : {j // ŵ j ≠ 0} → ι))ᵀ *\n (X.submatrix (id : Fin n → Fin n) (Subtype.val : {j // ŵ j ≠ 0} → ι))))\n (hStat : ∀ j : ι, ŵ j ≠ 0 →\n (∑ i : Fin n, X i j * (X.mulVec ŵ i - Y i)) + lam * Real.sign (ŵ j) = 0)\n (hOff : ∀ j : ι, ŵ j = 0 →\n |∑ i : Fin n, X i j * (X.mulVec ŵ i - Y i)| < lam) :\n IsMinOn (lassoObjective X Y lam) Set.univ ŵ ∧\n (∀ w, IsMinOn (lassoObjective X Y lam) Set.univ w → w = ŵ) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Matrix Real\n\nnamespace GraduateLevel\n\nclass PosDefAsymm {α : Type*} [Fintype α] (A : Matrix α α ℝ) : Prop where\n pd : ∀ x, x ≠ 0 → 0 < x ⬝ᵥ (A *ᵥ x)\n\nnoncomputable def lassoObjective {n : ℕ} {ι : Type*} [Fintype ι]\n (X : Matrix (Fin n) ι ℝ) (Y : Fin n → ℝ) (lam : ℝ) (w : ι → ℝ) : ℝ :=\n (1 / 2) * (∑ i : Fin n, (X.mulVec w i - Y i) ^ 2) + lam * (∑ j : ι, |w j|)\n\ntheorem ch10_proposition_10_35\n {n : ℕ} {ι : Type*} [Fintype ι] [DecidableEq ι]\n (X : Matrix (Fin n) ι ℝ) (Y : Fin n → ℝ) (lam : ℝ) (ŵ : ι → ℝ)\n (hlam : 0 ≤ lam)\n (hPD : PosDefAsymm\n ((X.submatrix (id : Fin n → Fin n) (Subtype.val : {j // ŵ j ≠ 0} → ι))ᵀ *\n (X.submatrix (id : Fin n → Fin n) (Subtype.val : {j // ŵ j ≠ 0} → ι))))\n (hStat : ∀ j : ι, ŵ j ≠ 0 →\n (∑ i : Fin n, X i j * (X.mulVec ŵ i - Y i)) + lam * Real.sign (ŵ j) = 0)\n (hOff : ∀ j : ι, ŵ j = 0 →\n |∑ i : Fin n, X i j * (X.mulVec ŵ i - Y i)| < lam) :\n IsMinOn (lassoObjective X Y lam) Set.univ ŵ ∧\n (∀ w, IsMinOn (lassoObjective X Y lam) Set.univ w → w = ŵ) := by\n classical\n obtain ⟨r, hrdef⟩ : ∃ r : Fin n → ℝ, r = fun i => X.mulVec ŵ i - Y i := ⟨_, rfl⟩\n obtain ⟨g, hgdef⟩ : ∃ g : ι → ℝ, g = fun j => ∑ i : Fin n, X i j * r i := ⟨_, rfl⟩\n have hcross : ∀ d : ι → ℝ, ∑ i, r i * (X.mulVec d i) = ∑ j, g j * d j := by\n intro d\n have h1 : ∀ i : Fin n, r i * (X.mulVec d i) = ∑ j, (X i j * r i) * d j := by\n intro i\n simp only [Matrix.mulVec, dotProduct, Finset.mul_sum]\n exact Finset.sum_congr rfl (fun j _ => by ring)\n rw [Finset.sum_congr rfl (fun i (_ : i ∈ Finset.univ) => h1 i), Finset.sum_comm]\n refine Finset.sum_congr rfl (fun j _ => ?_)\n rw [← Finset.sum_mul, hgdef]\n have key : ∀ w : ι → ℝ, lassoObjective X Y lam w - lassoObjective X Y lam ŵ\n = (∑ j : ι, (g j * (w j - ŵ j) + lam * (|w j| - |ŵ j|)))\n + (1/2) * ∑ i, (X.mulVec (w - ŵ) i)^2 := by\n intro w\n have he : ∀ i, X.mulVec w i - Y i = r i + X.mulVec (w - ŵ) i := by\n intro i\n have h2 : X.mulVec (w - ŵ) = X.mulVec w - X.mulVec ŵ := Matrix.mulVec_sub _ _ _\n rw [h2, hrdef]\n simp\n have hA : ∑ i, (X.mulVec w i - Y i)^2\n = (∑ i, (r i)^2) + 2 * (∑ j, g j * (w j - ŵ j)) + ∑ i, (X.mulVec (w - ŵ) i)^2 := by\n have h3 : ∑ i, (X.mulVec w i - Y i)^2\n = ∑ i, ((r i)^2 + 2*(r i * X.mulVec (w-ŵ) i) + (X.mulVec (w-ŵ) i)^2) := by\n refine Finset.sum_congr rfl fun i _ => ?_\n rw [he i]; ring\n rw [h3, Finset.sum_add_distrib, Finset.sum_add_distrib, ← Finset.mul_sum,\n hcross (w - ŵ)]\n simp\n have hB : ∑ j : ι, (g j * (w j - ŵ j) + lam * (|w j| - |ŵ j|))\n = (∑ j, g j * (w j - ŵ j)) + (lam * (∑ j, |w j|) - lam * ∑ j, |ŵ j|) := by\n rw [Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_sub_distrib, mul_sub]\n have hC : ∑ i, (X.mulVec ŵ i - Y i)^2 = ∑ i, (r i)^2 := by rw [hrdef]\n simp only [lassoObjective]\n rw [hA, hB, hC]\n ring\n have hterm : ∀ w : ι → ℝ, ∀ j, 0 ≤ g j * (w j - ŵ j) + lam * (|w j| - |ŵ j|) := by\n intro w j\n by_cases hj : ŵ j = 0\n · have hg0 : |g j| < lam := by rw [hgdef, hrdef]; exact hOff j hj\n have h1 : -(|g j| * |w j|) ≤ g j * w j := by\n have h2 : |g j * w j| = |g j| * |w j| := abs_mul _ _\n have h3 : -|g j * w j| ≤ g j * w j := neg_abs_le _\n rw [h2] at h3; exact h3\n have h4 : 0 ≤ (lam - |g j|) * |w j| :=\n mul_nonneg (by linarith) (abs_nonneg _)\n rw [hj]\n simp only [abs_zero, sub_zero, mul_sub] at *\n nlinarith [abs_nonneg (w j)]\n · rcases lt_trichotomy (ŵ j) 0 with hlt | heq | hgt\n · have hs : Real.sign (ŵ j) = -1 := Real.sign_of_neg hlt\n have := hStat j hj\n rw [hs] at this\n have hgj : g j = lam := by\n rw [hgdef, hrdef]; simp only []; linarith [this]\n have habs : |ŵ j| = -ŵ j := abs_of_neg hlt\n rw [hgj, habs]\n have : -w j ≤ |w j| := neg_le_abs _\n nlinarith\n · exact absurd heq hj\n · have hs : Real.sign (ŵ j) = 1 := Real.sign_of_pos hgt\n have := hStat j hj\n rw [hs] at this\n have hgj : g j = -lam := by\n rw [hgdef, hrdef]; simp only []; linarith [this]\n have habs : |ŵ j| = ŵ j := abs_of_pos hgt\n rw [hgj, habs]\n have : w j ≤ |w j| := le_abs_self _\n nlinarith\n have hterm0 : ∀ w : ι → ℝ, ∀ j, ŵ j = 0 → w j ≠ 0 →\n 0 < g j * (w j - ŵ j) + lam * (|w j| - |ŵ j|) := by\n intro w j hj hwj\n have hg0 : |g j| < lam := by rw [hgdef, hrdef]; exact hOff j hj\n have h3 : -(|g j| * |w j|) ≤ g j * w j := by\n have h2 : |g j * w j| = |g j| * |w j| := abs_mul _ _\n have h3 : -|g j * w j| ≤ g j * w j := neg_abs_le _\n rw [h2] at h3; exact h3\n have hpos : 0 < |w j| := abs_pos.mpr hwj\n have h4 : 0 < (lam - |g j|) * |w j| := mul_pos (by linarith) hpos\n rw [hj]\n simp only [abs_zero, sub_zero]\n nlinarith\n have hmin : IsMinOn (lassoObjective X Y lam) Set.univ ŵ := by\n rw [isMinOn_iff]\n intro w _\n have h := key w\n have h1 : 0 ≤ ∑ j : ι, (g j * (w j - ŵ j) + lam * (|w j| - |ŵ j|)) :=\n Finset.sum_nonneg (fun j _ => hterm w j)\n have h2 : 0 ≤ ∑ i, (X.mulVec (w - ŵ) i)^2 :=\n Finset.sum_nonneg (fun i _ => sq_nonneg _)\n linarith\n refine ⟨hmin, ?_⟩\n intro w hw\n have hle : lassoObjective X Y lam w ≤ lassoObjective X Y lam ŵ := by\n have := hw (Set.mem_univ ŵ)\n exact this\n have h := key w\n have h1 : 0 ≤ ∑ j : ι, (g j * (w j - ŵ j) + lam * (|w j| - |ŵ j|)) :=\n Finset.sum_nonneg (fun j _ => hterm w j)\n have h2 : 0 ≤ ∑ i, (X.mulVec (w - ŵ) i)^2 :=\n Finset.sum_nonneg (fun i _ => sq_nonneg _)\n have hsum0 : ∑ j : ι, (g j * (w j - ŵ j) + lam * (|w j| - |ŵ j|)) = 0 := by linarith\n have hnorm0 : ∑ i, (X.mulVec (w - ŵ) i)^2 = 0 := by linarith\n have hzero : ∀ j : ι, ŵ j = 0 → w j = 0 := by\n intro j hj\n by_contra hwj\n have hlt := hterm0 w j hj hwj\n have := (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => hterm w j)).mp hsum0 j\n (Finset.mem_univ j)\n linarith\n have hXd : ∀ i, X.mulVec (w - ŵ) i = 0 := by\n intro i\n have := (Finset.sum_eq_zero_iff_of_nonneg (fun i _ => sq_nonneg\n (X.mulVec (w - ŵ) i))).mp hnorm0 i (Finset.mem_univ i)\n exact pow_eq_zero_iff (n := 2) (by norm_num) |>.mp this\n set M := X.submatrix (id : Fin n → Fin n) (Subtype.val : {j // ŵ j ≠ 0} → ι) with hM\n set v : {j // ŵ j ≠ 0} → ℝ := fun j => (w - ŵ) j.val with hv\n have hMv : M.mulVec v = 0 := by\n funext i\n have hsub : ∑ j : {j // ŵ j ≠ 0}, X i j.val * (w - ŵ) j.val\n = ∑ j : ι, X i j * (w - ŵ) j := by\n have hfil : ∀ x : ι, x ∈ (Finset.univ.filter (fun j => ŵ j ≠ 0)) ↔ ŵ x ≠ 0 := by\n intro x; simp\n rw [← Finset.sum_subtype _ hfil (fun j => X i j * (w - ŵ) j)]\n refine Finset.sum_subset (Finset.subset_univ _) ?_\n intro x _ hx\n simp only [Finset.mem_filter, Finset.mem_univ, true_and, not_not] at hx\n have : w x = 0 := hzero x hx\n simp [Pi.sub_apply, this, hx]\n have hx := hXd i\n simp only [Matrix.mulVec, dotProduct] at hx\n simp only [hM, hv, Matrix.mulVec, dotProduct, Matrix.submatrix_apply, id, Pi.zero_apply]\n rw [hsub]\n exact hx\n have hvz : v = 0 := by\n by_contra hvne\n have := hPD.pd v hvne\n have hcalc : (Mᵀ * M).mulVec v = 0 := by\n rw [← Matrix.mulVec_mulVec, hMv]\n simp\n rw [hcalc] at this\n simp at this\n have hd : ∀ j : ι, w j = ŵ j := by\n intro j\n by_cases hj : ŵ j = 0\n · rw [hj, hzero j hj]\n · have := congrFun hvz ⟨j, hj⟩\n simp only [hv, Pi.sub_apply, Pi.zero_apply] at this\n linarith\n funext j\n exact hd j\n\nend GraduateLevel\n"} +{"id": "ch11_proposition_11_9", "source": "Graduate-level", "targets": [{"label": "ch11_proposition_11_9", "decls": ["ch11_proposition_11_9"], "statement": "Let \\(\\mathcal{F} = \\{h(\\theta^\\top x):\\theta \\in \\mathbb{R}^d\\}\\) and \\(\\mathcal{F}_{\\pm} = \\mathcal{F}\\cup -\\mathcal{F}\\). Let\n\\[\n\\mathcal{F}_{A}^{1}=\\{\\mathbb{E}_{\\theta\\sim\\mu}u(\\theta)h(\\theta^{\\top}x):\\mathbb{E}_{\\theta\\sim\\mu}|u(\\theta)|\\leq A\\}.\n\\]\nThen for all monotone function \\( h(\\cdot) \\) with \\( h(\\cdot) \\in [0, M] \\):\n\\[\nR\\left(\\mathcal{F}_{\\pm},\\mathcal{S}_{n}\\right)\\leq M\\frac{32\\sqrt{d+1}}{\\sqrt{n}}\n\\]\n\\[\nR\\left(\\mathcal{F}_{A}^{1},\\mathcal{S}_{n}\\right)\\leq A M\\frac{32\\sqrt{d+1}}{\\sqrt{n}}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Since \\( h(\\cdot) \\) is monotone, we know that \\( \\mathcal{F} \\) is a VC-subgraph class with VC dimension \\( d + 1 \\). Therefore from Theorem 5.11 and the calculation in Example 6.26, we obtain\n\\[\nR(\\mathcal{F},\\mathcal{S}_{n})\\leq M\\frac{16\\sqrt{d+1}}{\\sqrt{n}}.\n\\]\nThis leads to the first bound. The second bound follows from Theorem 10.8. \\(\\square\\)", "context": [{"id": "ch5:theorem:5_11", "name": "theorem 5.11", "statement": "Assume that \\(\\mathcal{G}\\) is a VC subgraph class, with VC dimension \\(d\\), and all \\(\\phi \\in \\mathcal{G}\\) are bounded: \\(\\phi(Z) \\in [0,1]\\). Then for any distribution \\(\\mathcal{D}\\) over \\(Z\\), \\(\\epsilon \\in (0,1]\\) and \\(p \\in [1,\\infty)\\), we have\n\\[\n\\ln M(\\epsilon,\\mathcal{G},L_{p}(\\mathcal{D}))\\leq 1+\\ln(d+1)+d\\ln(2 e/\\epsilon^{p}).\n\\]\nMoreover,\n\\[\n\\ln N_{\\infty}(\\epsilon,\\mathcal{G},n)\\leq d\\ln\\max [2,e n/(d\\epsilon)].\n\\]"}, {"id": "ch6:example:6_26", "name": "example 6.26", "statement": "From Corollary 5.7, we know that if a binary-valued function class \\(\\mathcal{G}\\) (or a VC-subgraph class with values in \\([0,1]\\)) has VC-dimension \\(d\\), then\n\\[\n\\ln N_{2}(\\epsilon,\\mathcal{G},n)\\leq 1+\\ln(d+1)+d\\ln(2 e/\\epsilon^{2}).\n\\]\nSince \\(N_{2}(0.5,\\mathcal{G},n) = 1\\), we have\n\\[\n12\\int_{0}^{\\infty}\\sqrt{\\ln N_{2}(\\epsilon,\\mathcal{G},n)}d\\epsilon\\leq 12\\int_{0}^{0. 5}\\sqrt{1+\\ln(d+1)+d\\ln(2e/\\epsilon^{2})}d\\epsilon\\leq 16\\sqrt{d}.\n\\]\nIt follows that\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n})\\leq\\frac{16\\sqrt{d}}{\\sqrt{n}}.\n\\]\nThe constant isn't optimal, and in fact a better constant can be obtained using packing number (see Example 6.4). The result implies the following uniform convergence result: with probability at least \\(1 - \\delta\\), for all \\(w \\in \\Omega\\),\n\\[\n\\phi(w,\\mathcal{D})\\leq\\phi(w,\\mathcal{S}_{n})+\\frac{32\\sqrt{d}}{\\sqrt{n}}+\\sqrt{\\frac{\\ln(1/\\delta)}{2n}}.\n\\]\nThis bound removes a \\( \\ln n \\) factor from the additive uniform convergence bound in Theorem 4.17."}, {"id": "ch10:theorem:10_8", "name": "theorem 10.8", "statement": "We have\n\\[\nR(\\mathrm{CONV}(\\Psi),\\mathcal{S}_{n})=R(\\Psi,\\mathcal{S}_{n}).\n\\]\nIf either \\(\\Psi = -\\Psi\\) or \\(0 \\in \\Psi\\), then the following equality holds:\n\\[\nR\\left(\\mathcal{F}_{A,L_{1}}^{+}(\\Psi),\\mathcal{S}_{n}\\right)=A\\cdot R(\\Psi,\\mathcal{S}_{n}).\n\\]\nIf \\(\\Psi = -\\Psi\\), then the following equality holds:\n\\[\nR\\left(\\mathcal{F}_{A,L_{1}}(\\Psi),\\mathcal{S}_{n}\\right)=A\\cdot R(\\Psi,\\mathcal{S}_{n}).\n\\]"}, {"id": "ch6:definition:6_3", "name": "definition 6.3", "statement": "Given \\(S_{n}=\\{Z_{1},\\ldots,Z_{n}\\}\\), the (one-sided) empirical Rademacher complexity of \\(\\mathcal{G}\\) is defined as\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n}) = \\mathbb{E}_{\\sigma}\\sup_{w\\in \\Omega}\\frac{1}{n}\\sum_{i = 1}^{n}\\sigma_{i}\\phi (w,Z_{i}),\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R(\\mathcal{G},\\mathcal{S}_{n}).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ndef dotProd {d : ℕ} (θ x : Fin d → ℝ) : ℝ := ∑ i, θ i * x i\n\nabbrev IdxPM (d : ℕ) : Type := (Fin d → ℝ) × Bool\n\ndef famPM {d : ℕ} (h : ℝ → ℝ) : IdxPM d → (Fin d → ℝ) → ℝ :=\n fun p x => (if p.2 then (1 : ℝ) else -1) * h (dotProd p.1 x)\n\nabbrev IdxA {d : ℕ} (μ : MeasureTheory.Measure (Fin d → ℝ)) (A : ℝ) : Type :=\n {u : (Fin d → ℝ) → ℝ // Integrable u μ ∧ (∫ θ, |u θ| ∂μ) ≤ A}\n\nnoncomputable def famA {d : ℕ} (μ : MeasureTheory.Measure (Fin d → ℝ)) (A : ℝ) (h : ℝ → ℝ) :\n IdxA μ A → (Fin d → ℝ) → ℝ :=\n fun u x => ∫ θ, u.1 θ * h (dotProd θ x) ∂μ\n\ntheorem ch11_proposition_11_9\n {d n : ℕ} {M A : ℝ}\n (μ : MeasureTheory.Measure (Fin d → ℝ)) [IsProbabilityMeasure μ]\n (S : Fin n → (Fin d → ℝ))\n (h : ℝ → ℝ)\n (hmono : Monotone h ∨ Antitone h)\n (hrange : ∀ t, h t ∈ Set.Icc (0 : ℝ) M)\n (hM : 0 ≤ M) (hA : 0 ≤ A) (hn : 0 < n) :\n empRadSigned n (famPM (d := d) h) S\n ≤ M * 32 * Real.sqrt (d + 1) / Real.sqrt n\n ∧\n empRadSigned n (famA μ A h) S\n ≤ A * M * 32 * Real.sqrt (d + 1) / Real.sqrt n := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ndef dotProd {d : ℕ} (θ x : Fin d → ℝ) : ℝ := ∑ i, θ i * x i\n\nabbrev IdxPM (d : ℕ) : Type := (Fin d → ℝ) × Bool\n\ndef famPM {d : ℕ} (h : ℝ → ℝ) : IdxPM d → (Fin d → ℝ) → ℝ :=\n fun p x => (if p.2 then (1 : ℝ) else -1) * h (dotProd p.1 x)\n\nabbrev IdxA {d : ℕ} (μ : MeasureTheory.Measure (Fin d → ℝ)) (A : ℝ) : Type :=\n {u : (Fin d → ℝ) → ℝ // Integrable u μ ∧ (∫ θ, |u θ| ∂μ) ≤ A}\n\nnoncomputable def famA {d : ℕ} (μ : MeasureTheory.Measure (Fin d → ℝ)) (A : ℝ) (h : ℝ → ℝ) :\n IdxA μ A → (Fin d → ℝ) → ℝ :=\n fun u x => ∫ θ, u.1 θ * h (dotProd θ x) ∂μ\n\n/-! ### Helper machinery -/\n\nnoncomputable def sg {n : ℕ} (σ : RadSigns n) (k : Fin n) : ℝ := ((σ k : ℤ) : ℝ)\n\nlemma sg_eq {n : ℕ} (σ : RadSigns n) (k : Fin n) : ((σ k : ℤ) : ℝ) = sg σ k := rfl\n\nnoncomputable def Eσ {n : ℕ} (F : RadSigns n → ℝ) : ℝ :=\n ((2:ℝ) ^ n)⁻¹ * ∑ σ : RadSigns n, F σ\n\nlemma card_radSigns (n : ℕ) : Fintype.card (RadSigns n) = 2 ^ n := by simp [RadSigns]\n\nlemma Eσ_mono {n : ℕ} {F G : RadSigns n → ℝ} (h : ∀ σ, F σ ≤ G σ) : Eσ F ≤ Eσ G := by\n unfold Eσ\n have : (0:ℝ) < ((2:ℝ)^n)⁻¹ := by positivity\n exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun σ _ => h σ) this.le\n\nlemma Eσ_affine {n : ℕ} (a b : ℝ) (F : RadSigns n → ℝ) :\n Eσ (fun σ => a * F σ + b) = a * Eσ F + b := by\n unfold Eσ\n rw [Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_const, Finset.card_univ,\n card_radSigns, nsmul_eq_mul]\n push_cast\n field_simp\n\nlemma Eσ_smul {n : ℕ} (a : ℝ) (F : RadSigns n → ℝ) :\n Eσ (fun σ => a * F σ) = a * Eσ F := by\n have := Eσ_affine (n := n) a 0 F\n simpa using this\n\nlemma Eσ_const {n : ℕ} (c : ℝ) : Eσ (fun _ : RadSigns n => c) = c := by\n have := Eσ_affine (n := n) 0 c (fun _ => 0)\n simpa using this\n\nlemma Eσ_add {n : ℕ} (F G : RadSigns n → ℝ) : Eσ (fun σ => F σ + G σ) = Eσ F + Eσ G := by\n unfold Eσ\n rw [Finset.sum_add_distrib]\n ring\n\n/-- The family of subsets of the sample cut out by (open) affine halfspaces. -/\nnoncomputable def hsFam {n d : ℕ} (S : Fin n → (Fin d → ℝ)) : Finset (Finset (Fin n)) :=\n letI := Classical.decPred\n (fun T : Finset (Fin n) => ∃ (w : Fin d → ℝ) (c : ℝ), ∀ k, k ∈ T ↔ c < dotProd w (S k))\n Finset.univ.filter\n (fun T : Finset (Fin n) => ∃ (w : Fin d → ℝ) (c : ℝ), ∀ k, k ∈ T ↔ c < dotProd w (S k))\n\nlemma mem_hsFam {n d : ℕ} (S : Fin n → (Fin d → ℝ)) (T : Finset (Fin n)) :\n T ∈ hsFam S ↔ ∃ (w : Fin d → ℝ) (c : ℝ), ∀ k, k ∈ T ↔ c < dotProd w (S k) := by\n unfold hsFam\n simp\n\nlemma hsFam_nonempty {n d : ℕ} (S : Fin n → (Fin d → ℝ)) : (hsFam S).Nonempty := by\n refine ⟨∅, (mem_hsFam S ∅).2 ⟨0, 0, fun k => ?_⟩⟩\n simp [dotProd]\n\n/-- The supremum of the signed sums over the halfspace family. -/\nnoncomputable def Qs {n d : ℕ} (S : Fin n → (Fin d → ℝ)) (σ : RadSigns n) : ℝ :=\n (hsFam S).sup' (hsFam_nonempty S) (fun T => ∑ k ∈ T, sg σ k)\n\nnoncomputable def Zs {n : ℕ} (σ : RadSigns n) : ℝ := max 0 (-∑ k, sg σ k)\n\nnoncomputable def Gs {n d : ℕ} (M : ℝ) (S : Fin n → (Fin d → ℝ)) (σ : RadSigns n) : ℝ :=\n (n : ℝ)⁻¹ * M * (Qs S σ + Zs σ)\n\n\nlemma dotProd_neg {d : ℕ} (θ x : Fin d → ℝ) : dotProd (-θ) x = -(dotProd θ x) := by\n unfold dotProd\n rw [← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl fun i _ => by simp\n\nlemma int_step (M c : ℝ) (hc : 0 ≤ c) (hcM : c ≤ M) :\n (∫ y in (0:ℝ)..M, (if y < c then (1:ℝ) else 0)) = c := by\n have h1 : (fun y : ℝ => if y < c then (1:ℝ) else 0)\n = Set.indicator (Set.Iio c) (fun _ => (1:ℝ)) := by\n funext y; by_cases h : y < c <;> simp [Set.indicator, h]\n rw [h1, intervalIntegral.integral_of_le (by linarith : (0:ℝ) ≤ M),\n MeasureTheory.setIntegral_indicator measurableSet_Iio, MeasureTheory.setIntegral_const]\n have h2 : Set.Ioc (0:ℝ) M ∩ Set.Iio c = Set.Ioo 0 c := by\n ext y\n simp only [Set.mem_inter_iff, Set.mem_Ioc, Set.mem_Iio, Set.mem_Ioo]\n constructor\n · rintro ⟨⟨h1, _⟩, h3⟩; exact ⟨h1, h3⟩\n · rintro ⟨h1, h2⟩; exact ⟨⟨h1, by linarith⟩, h2⟩\n rw [h2]\n simp [MeasureTheory.measureReal_def, Real.volume_Ioo, ENNReal.toReal_ofReal hc]\n\nlemma upset_lemma {n : ℕ} (hn : 0 < n) (t : Fin n → ℝ) (K : Finset (Fin n))\n (hK : ∀ k k', k ∈ K → t k ≤ t k' → k' ∈ K) : ∃ c, ∀ k, (k ∈ K ↔ c < t k) := by\n classical\n have huniv : (Finset.univ : Finset (Fin n)).Nonempty := by\n rw [← Finset.card_pos, Finset.card_univ, Fintype.card_fin]; exact hn\n by_cases hc : (Finset.univ \\ K).Nonempty\n · refine ⟨(Finset.univ \\ K).sup' hc t, fun k => ?_⟩\n constructor\n · intro hk\n rw [Finset.sup'_lt_iff]\n intro k' hk'\n by_contra hcon\n push_neg at hcon\n exact (Finset.mem_sdiff.mp hk').2 (hK k k' hk hcon)\n · intro hlt\n by_contra hcon\n have : k ∈ Finset.univ \\ K := Finset.mem_sdiff.mpr ⟨Finset.mem_univ k, hcon⟩\n exact absurd (Finset.le_sup' t this) (not_le.mpr hlt)\n · have hKall : ∀ k, k ∈ K := by\n intro k\n by_contra hcon\n exact hc ⟨k, Finset.mem_sdiff.mpr ⟨Finset.mem_univ k, hcon⟩⟩\n refine ⟨(Finset.univ.inf' huniv t) - 1, fun k => ?_⟩\n exact ⟨fun _ => by have := Finset.inf'_le t (Finset.mem_univ k); linarith,\n fun _ => hKall k⟩\n\nlemma levelSet_mem {n d : ℕ} (hn : 0 < n) (S : Fin n → (Fin d → ℝ)) (θ : Fin d → ℝ)\n (g : ℝ → ℝ) (hg : Monotone g ∨ Antitone g) (y : ℝ) :\n (Finset.univ.filter (fun k => y < g (dotProd θ (S k)))) ∈ hsFam S := by\n rcases hg with hm | hm\n · obtain ⟨c, hc⟩ := upset_lemma hn (fun k => dotProd θ (S k))\n (Finset.univ.filter (fun k => y < g (dotProd θ (S k)))) (by\n intro k k' hk hle\n simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hk ⊢\n exact lt_of_lt_of_le hk (hm hle))\n exact (mem_hsFam S _).2 ⟨θ, c, fun k => hc k⟩\n · obtain ⟨c, hc⟩ := upset_lemma hn (fun k => -(dotProd θ (S k)))\n (Finset.univ.filter (fun k => y < g (dotProd θ (S k)))) (by\n intro k k' hk hle\n simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hk ⊢\n exact lt_of_lt_of_le hk (hm (by linarith)))\n refine (mem_hsFam S _).2 ⟨-θ, c, fun k => ?_⟩\n rw [hc k, dotProd_neg]\n\nlemma Zs_nonneg {n : ℕ} (σ : RadSigns n) : 0 ≤ Zs σ := le_max_left _ _\n\nlemma Qs_nonneg {n d : ℕ} (S : Fin n → (Fin d → ℝ)) (σ : RadSigns n) : 0 ≤ Qs S σ := by\n have h0 : (∅ : Finset (Fin n)) ∈ hsFam S :=\n (mem_hsFam S ∅).2 ⟨0, 0, fun k => by simp [dotProd]⟩\n have := Finset.le_sup' (f := fun T : Finset (Fin n) => ∑ k ∈ T, sg σ k) h0\n simpa [Qs] using this\n\nlemma layer_bound {n d : ℕ} (hn : 0 < n) {M : ℝ} (hM : 0 ≤ M) (S : Fin n → (Fin d → ℝ))\n (g : ℝ → ℝ) (hg : Monotone g ∨ Antitone g) (hgr : ∀ t, g t ∈ Set.Icc (0:ℝ) M)\n (σ : RadSigns n) (θ : Fin d → ℝ) :\n ∑ k, sg σ k * g (dotProd θ (S k)) ≤ M * Qs S σ := by\n have hii : ∀ c : ℝ, IntervalIntegrable (fun y => if y < c then (1:ℝ) else 0) volume 0 M := by\n intro c\n refine Antitone.intervalIntegrable ?_\n intro a b hab\n by_cases hb : b < c\n · have ha : a < c := lt_of_le_of_lt hab hb\n simp [ha, hb]\n · simp only [hb, if_false]\n split_ifs <;> norm_num\n have hsum : ∑ k, sg σ k * g (dotProd θ (S k))\n = ∫ y in (0:ℝ)..M, ∑ k, sg σ k * (if y < g (dotProd θ (S k)) then (1:ℝ) else 0) := by\n rw [intervalIntegral.integral_finset_sum (fun k _ => (hii (g (dotProd θ (S k)))).const_mul _)]\n refine Finset.sum_congr rfl fun k _ => ?_\n rw [intervalIntegral.integral_const_mul,\n int_step M (g (dotProd θ (S k))) (hgr _).1 (hgr _).2]\n rw [hsum]\n have hle : ∀ y : ℝ, ∑ k, sg σ k * (if y < g (dotProd θ (S k)) then (1:ℝ) else 0) ≤ Qs S σ := by\n intro y\n have h1 : ∑ k, sg σ k * (if y < g (dotProd θ (S k)) then (1:ℝ) else 0)\n = ∑ k ∈ Finset.univ.filter (fun k => y < g (dotProd θ (S k))), sg σ k := by\n rw [Finset.sum_filter]\n exact Finset.sum_congr rfl fun k _ => by split_ifs <;> ring\n rw [h1]\n exact Finset.le_sup' (f := fun T : Finset (Fin n) => ∑ k ∈ T, sg σ k)\n (levelSet_mem hn S θ g hg y)\n calc (∫ y in (0:ℝ)..M, ∑ k, sg σ k * (if y < g (dotProd θ (S k)) then (1:ℝ) else 0))\n ≤ ∫ _y in (0:ℝ)..M, Qs S σ := by\n refine intervalIntegral.integral_mono_on hM ?_ intervalIntegrable_const (fun y _ => hle y)\n have hfun : (fun y => ∑ k, sg σ k * (if y < g (dotProd θ (S k)) then (1:ℝ) else 0))\n = ∑ k : Fin n, (fun y => sg σ k * (if y < g (dotProd θ (S k)) then (1:ℝ) else 0)) := by\n funext y; simp\n rw [hfun]\n exact IntervalIntegrable.sum _ (fun k _ => (hii _).const_mul _)\n _ = M * Qs S σ := by\n rw [intervalIntegral.integral_const]\n simp\n\n/-- Key pointwise bound: the layer-cake / VC reduction. -/\nlemma key_pointwise {n d : ℕ} (hn : 0 < n) {M : ℝ} (hM : 0 ≤ M)\n (S : Fin n → (Fin d → ℝ)) (h : ℝ → ℝ)\n (hmono : Monotone h ∨ Antitone h) (hrange : ∀ t, h t ∈ Set.Icc (0:ℝ) M)\n (σ : RadSigns n) (θ : Fin d → ℝ) :\n |(n : ℝ)⁻¹ * ∑ k, sg σ k * h (dotProd θ (S k))| ≤ Gs M S σ := by\n have hA : ∑ k, sg σ k * h (dotProd θ (S k)) ≤ M * Qs S σ :=\n layer_bound hn hM S h hmono hrange σ θ\n have hB : ∑ k, sg σ k * (M - h (dotProd θ (S k))) ≤ M * Qs S σ := by\n refine layer_bound hn hM S (fun x => M - h x) ?_ (fun s => ?_) σ θ\n · rcases hmono with hm | hm\n · exact Or.inr fun a b hab => by have := hm hab; dsimp only; linarith\n · exact Or.inl fun a b hab => by have := hm hab; dsimp only; linarith\n · exact ⟨by have := (hrange s).2; linarith, by have := (hrange s).1; linarith⟩\n have hsplit : ∑ k, sg σ k * (M - h (dotProd θ (S k)))\n = M * (∑ k, sg σ k) - ∑ k, sg σ k * h (dotProd θ (S k)) := by\n rw [Finset.mul_sum, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl fun k _ => by ring\n rw [hsplit] at hB\n have hZ : -(∑ k, sg σ k) ≤ Zs σ := le_max_right _ _\n have hQ : 0 ≤ Qs S σ := Qs_nonneg S σ\n have hZ0 : 0 ≤ Zs σ := Zs_nonneg σ\n have hX1 : ∑ k, sg σ k * h (dotProd θ (S k)) ≤ M * (Qs S σ + Zs σ) := by nlinarith\n have hX2 : -(∑ k, sg σ k * h (dotProd θ (S k))) ≤ M * (Qs S σ + Zs σ) := by nlinarith\n have hnn : (0:ℝ) ≤ (n:ℝ)⁻¹ := by positivity\n rw [abs_mul, abs_of_nonneg hnn]\n have habs : |∑ k, sg σ k * h (dotProd θ (S k))| ≤ M * (Qs S σ + Zs σ) := abs_le.mpr ⟨by linarith, hX1⟩\n calc (n:ℝ)⁻¹ * |∑ k, sg σ k * h (dotProd θ (S k))|\n ≤ (n:ℝ)⁻¹ * (M * (Qs S σ + Zs σ)) := by\n exact mul_le_mul_of_nonneg_left habs hnn\n _ = Gs M S σ := by unfold Gs; ring\n\n\n/-! ### Massart's finite class lemma -/\n\nlemma Eσ_pos {n : ℕ} {F : RadSigns n → ℝ} (h : ∀ σ, 0 < F σ) : 0 < Eσ F := by\n unfold Eσ\n have hne : (Finset.univ : Finset (RadSigns n)).Nonempty := by\n rw [← Finset.card_pos, Finset.card_univ, card_radSigns]; positivity\n have : (0:ℝ) < ∑ σ : RadSigns n, F σ := Finset.sum_pos (fun σ _ => h σ) hne\n positivity\n\nlemma Eσ_finsum {n : ℕ} {ι : Type*} (s : Finset ι) (F : ι → RadSigns n → ℝ) :\n Eσ (fun σ => ∑ i ∈ s, F i σ) = ∑ i ∈ s, Eσ (F i) := by\n unfold Eσ\n simp only [Finset.mul_sum]\n rw [Finset.sum_comm]\n\nlemma sum_prod_signs {n : ℕ} (g : Fin n → ℝ → ℝ) :\n ∑ σ : RadSigns n, ∏ k, g k (sg σ k) = ∏ k, (g k 1 + g k (-1)) := by\n have hkey := Finset.prod_univ_sum (ι := Fin n) (κ := fun _ => ({-1,1} : Finset ℤ))\n (fun _ => Finset.univ) (fun i b => g i ((b : ℤ) : ℝ))\n rw [Fintype.piFinset_univ] at hkey\n simp only [sg]\n have key : ∑ σ : RadSigns n, ∏ k, g k (((σ k : ℤ)) : ℝ)\n = ∏ i, ∑ j : ({-1,1} : Finset ℤ), g i ((j : ℤ) : ℝ) := hkey.symm\n rw [key]\n refine Finset.prod_congr rfl fun i _ => ?_\n rw [Finset.sum_coe_sort (s := ({-1,1} : Finset ℤ)) (f := fun b => g i ((b:ℤ):ℝ))]\n rw [show ({-1,1} : Finset ℤ) = {1, -1} by decide]\n rw [Finset.sum_pair (by norm_num)]\n norm_num\n\nlemma Eσ_exp_inner {n : ℕ} (v : Fin n → ℝ) (l : ℝ) :\n Eσ (fun σ => Real.exp (l * ∑ k, sg σ k * v k)) = ∏ k, Real.cosh (l * v k) := by\n unfold Eσ\n have h1 : ∀ σ : RadSigns n, Real.exp (l * ∑ k, sg σ k * v k)\n = ∏ k, Real.exp (l * (sg σ k * v k)) := by\n intro σ\n rw [← Real.exp_sum, Finset.mul_sum]\n simp only [h1]\n rw [sum_prod_signs (fun k x => Real.exp (l * (x * v k)))]\n have h2 : ∀ k : Fin n, Real.exp (l * (1 * v k)) + Real.exp (l * ((-1) * v k))\n = 2 * Real.cosh (l * v k) := by\n intro k\n rw [Real.cosh_eq, show l * (1 * v k) = l * v k by ring,\n show l * (-1 * v k) = -(l * v k) by ring]\n ring\n simp only [h2]\n rw [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin]\n field_simp\n\nlemma Eσ_exp_inner_le {n : ℕ} (v : Fin n → ℝ) (l : ℝ) (R : ℝ) (hv : ∑ k, (v k)^2 ≤ R^2) :\n Eσ (fun σ => Real.exp (l * ∑ k, sg σ k * v k)) ≤ Real.exp (l^2 * R^2 / 2) := by\n rw [Eσ_exp_inner]\n have h1 : ∏ k, Real.cosh (l * v k) ≤ ∏ k : Fin n, Real.exp ((l * v k)^2 / 2) :=\n Finset.prod_le_prod (fun k _ => (Real.cosh_pos _).le)\n (fun k _ => Real.cosh_le_exp_half_sq _)\n refine h1.trans ?_\n rw [← Real.exp_sum]\n apply Real.exp_le_exp.2\n have h2 : ∑ k : Fin n, (l * v k)^2/2 = l^2 * (∑ k, (v k)^2)/2 := by\n rw [Finset.mul_sum, ← Finset.sum_div]\n exact congrArg (· / 2) (Finset.sum_congr rfl fun k _ => by ring)\n rw [h2]\n nlinarith [sq_nonneg l]\n\nlemma massart {n : ℕ} (V : Finset (Fin n → ℝ)) (hV : V.Nonempty) (R : ℝ) (hR : 0 ≤ R)\n (hbd : ∀ v ∈ V, ∑ k, (v k)^2 ≤ R^2) :\n Eσ (fun σ => V.sup' hV (fun v => ∑ k, sg σ k * v k))\n ≤ R * Real.sqrt (2 * Real.log (2 * V.card)) := by\n set X : RadSigns n → ℝ := fun σ => V.sup' hV (fun v => ∑ k, sg σ k * v k) with hX\n rcases eq_or_lt_of_le hR with hR0 | hR0\n · have hv0 : ∀ v ∈ V, ∀ k, v k = 0 := by\n intro v hv k\n have h1 := hbd v hv\n rw [← hR0] at h1\n have h2 : ∑ k, (v k)^2 ≤ 0 := by simpa using h1\n have h3 : (v k)^2 ≤ 0 :=\n le_trans (Finset.single_le_sum (f := fun k => (v k)^2) (fun i _ => sq_nonneg _)\n (Finset.mem_univ k)) h2\n nlinarith [sq_nonneg (v k)]\n have hXz : ∀ σ, X σ = 0 := by\n intro σ\n have hz : ∀ v ∈ V, (∑ k, sg σ k * v k) = 0 := by\n intro v hv\n refine Finset.sum_eq_zero fun k _ => ?_\n rw [hv0 v hv k, mul_zero]\n refine le_antisymm (Finset.sup'_le hV _ (fun v hv => le_of_eq (hz v hv))) ?_\n obtain ⟨v, hv⟩ := hV\n exact le_trans (le_of_eq (hz v hv).symm)\n (Finset.le_sup' (f := fun v : Fin n → ℝ => ∑ k, sg σ k * v k) hv)\n have hE : Eσ X = 0 := by\n rw [show X = (fun _ : RadSigns n => (0:ℝ)) from funext hXz, Eσ_const]\n rw [hE, ← hR0]\n simp\n · set N : ℝ := (V.card : ℝ) with hNdef\n have hN1 : (1:ℝ) ≤ N := by\n rw [hNdef]\n exact_mod_cast Finset.card_pos.2 hV\n set L : ℝ := Real.log (2 * N) with hLdef\n have hL : 0 < L := Real.log_pos (by linarith)\n set s : ℝ := Real.sqrt (2 * L) with hsdef\n have hs : 0 < s := Real.sqrt_pos.2 (by linarith)\n have hs2 : s ^ 2 = 2 * L := Real.sq_sqrt (by linarith)\n set l : ℝ := s / R with hldef\n have hl : 0 < l := div_pos hs hR0\n set c : ℝ := Eσ (fun σ => Real.exp (l * X σ)) with hcdef\n have hc : 0 < c := Eσ_pos (fun σ => Real.exp_pos _)\n have jensen : l * Eσ X ≤ Real.log c := by\n have key : ∀ σ, l * X σ ≤ (1/c) * Real.exp (l * X σ) + (Real.log c - 1) := by\n intro σ\n have h1 : Real.log (Real.exp (l * X σ) / c) ≤ Real.exp (l * X σ) / c - 1 :=\n Real.log_le_sub_one_of_pos (by positivity)\n rw [Real.log_div (ne_of_gt (Real.exp_pos _)) (ne_of_gt hc), Real.log_exp] at h1\n have h2 : Real.exp (l * X σ) / c = (1/c) * Real.exp (l * X σ) := by ring\n rw [h2] at h1\n linarith\n have h2 := Eσ_mono key\n rw [Eσ_smul l X, Eσ_affine (1/c) (Real.log c - 1) (fun σ => Real.exp (l * X σ))] at h2\n rw [← hcdef] at h2\n have h3 : (1/c) * c = 1 := by field_simp\n rw [h3] at h2\n linarith\n have hcbound : c ≤ N * Real.exp (l^2 * R^2 / 2) := by\n have h1 : ∀ σ, Real.exp (l * X σ) ≤ ∑ v ∈ V, Real.exp (l * ∑ k, sg σ k * v k) := by\n intro σ\n obtain ⟨v, hv, hveq⟩ := Finset.exists_mem_eq_sup' hV (fun v => ∑ k, sg σ k * v k)\n have h2 : X σ = ∑ k, sg σ k * v k := hveq\n rw [h2]\n exact Finset.single_le_sum (f := fun v : Fin n → ℝ => Real.exp (l * ∑ k, sg σ k * v k))\n (fun i _ => (Real.exp_pos _).le) hv\n calc c ≤ Eσ (fun σ => ∑ v ∈ V, Real.exp (l * ∑ k, sg σ k * v k)) := Eσ_mono h1\n _ = ∑ v ∈ V, Eσ (fun σ => Real.exp (l * ∑ k, sg σ k * v k)) := Eσ_finsum _ _\n _ ≤ ∑ _v ∈ V, Real.exp (l^2 * R^2/2) :=\n Finset.sum_le_sum (fun v hv => Eσ_exp_inner_le v l R (hbd v hv))\n _ = N * Real.exp (l^2*R^2/2) := by rw [Finset.sum_const, nsmul_eq_mul]\n have hlogc : Real.log c ≤ Real.log N + l^2 * R^2/2 := by\n have h1 := Real.log_le_log hc hcbound\n rwa [Real.log_mul (by linarith) (ne_of_gt (Real.exp_pos _)), Real.log_exp] at h1\n have hlogN : Real.log N ≤ L := by\n rw [hLdef]\n exact Real.log_le_log (by linarith) (by linarith)\n have hlR : l * R = s := by rw [hldef]; field_simp\n have hfinal : Eσ X ≤ R * s := by\n have h1 : l * Eσ X ≤ L + s^2/2 := by\n have h2 : l^2 * R^2 = s^2 := by rw [show l^2 * R^2 = (l*R)^2 by ring, hlR]\n rw [← h2] at *\n linarith\n have h2 : L = s^2/2 := by rw [hs2]; ring\n rw [h2] at h1\n have h3 : l * Eσ X ≤ s^2 := by linarith\n have h4 : Eσ X ≤ s^2 / l := by rwa [le_div_iff₀ hl, mul_comm]\n have h5 : s^2/l = R * s := by rw [hldef]; field_simp\n linarith [h5 ▸ h4]\n exact hfinal\n\n/-! ### The chaining bound -/\n\nlemma hsFam_vcDim {n d : ℕ} (S : Fin n → (Fin d → ℝ)) : (hsFam S).vcDim ≤ d + 1 := by\n classical\n refine Finset.sup_le fun s hs => ?_\n rw [Finset.mem_shatterer] at hs\n by_contra hcon\n push_neg at hcon\n obtain ⟨s', hs's, hcard⟩ := Finset.exists_subset_card_eq (n := d + 2) (s := s) hcon\n have hsh : (hsFam S).Shatters s' := hs.mono_right hs's\n -- injective enumeration\n set e : Fin (d+2) → Fin n := fun i => ((s'.orderIsoOfFin hcard i : { x // x ∈ s'}) : Fin n) with he\n have hein : Function.Injective e := by\n intro i j hij\n have := Subtype.ext hij\n exact (s'.orderIsoOfFin hcard).injective this\n have hemem : ∀ i, e i ∈ s' := fun i => (s'.orderIsoOfFin hcard i).2\n -- vectors\n set v : Fin (d+2) → ((Fin d → ℝ) × ℝ) := fun i => (S (e i), 1) with hv\n have hnli : ¬ LinearIndependent ℝ v := by\n intro hli\n have := hli.fintype_card_le_finrank\n simp only [Fintype.card_fin] at this\n rw [Module.finrank_prod, Module.finrank_fin_fun, Module.finrank_self] at this\n omega\n obtain ⟨g0, hg00, i0, hi0⟩ := Fintype.not_linearIndependent_iff.1 hnli\n have key : ∀ (g : Fin (d+2) → ℝ), (∀ j, ∑ i, g i * S (e i) j = 0) → (∑ i, g i = 0) →\n (∃ i, 0 < g i) → False := by\n intro g h1 h2 hpos\n set t : Finset (Fin n) := (Finset.univ.filter (fun i => 0 < g i)).image e with ht\n have hts : t ⊆ s' := by\n intro x hx\n rw [ht, Finset.mem_image] at hx\n obtain ⟨i, _, rfl⟩ := hx\n exact hemem i\n obtain ⟨T, hT, hTs⟩ := hsh hts\n obtain ⟨w, c, hwc⟩ := (mem_hsFam S T).1 hT\n have hmemt : ∀ i, (e i ∈ t) ↔ (0 < g i) := by\n intro i\n constructor\n · intro hx\n rw [ht, Finset.mem_image] at hx\n obtain ⟨i', hi', hii'⟩ := hx\n have : i' = i := hein hii'\n subst this\n simpa using hi'\n · intro hx\n rw [ht, Finset.mem_image]\n exact ⟨i, by simpa using hx, rfl⟩\n have hkey : ∀ i, (0 < g i) ↔ (c < dotProd w (S (e i))) := by\n intro i\n rw [← hmemt i, ← hTs]\n simp only [Finset.mem_inter, hemem i, true_and]\n exact hwc (e i)\n have hzero : ∑ i, g i * (dotProd w (S (e i)) - c) = 0 := by\n have e1 : ∑ i, g i * (dotProd w (S (e i)) - c)\n = (∑ i, g i * dotProd w (S (e i))) - c * ∑ i, g i := by\n rw [Finset.mul_sum, ← Finset.sum_sub_distrib]\n exact Finset.sum_congr rfl fun i _ => by ring\n rw [e1, h2, mul_zero, sub_zero]\n have e2 : ∑ i, g i * dotProd w (S (e i)) = ∑ j : Fin d, w j * ∑ i, g i * S (e i) j := by\n unfold dotProd\n have hx : ∀ i, g i * ∑ j : Fin d, w j * S (e i) j\n = ∑ j : Fin d, g i * (w j * S (e i) j) := fun i => by rw [Finset.mul_sum]\n simp only [hx]\n rw [Finset.sum_comm]\n refine Finset.sum_congr rfl fun j _ => ?_\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl fun i _ => by ring\n rw [e2]\n exact Finset.sum_eq_zero fun j _ => by rw [h1 j, mul_zero]\n have hnn : ∀ i ∈ (Finset.univ : Finset (Fin (d+2))), 0 ≤ g i * (dotProd w (S (e i)) - c) := by\n intro i _\n rcases lt_trichotomy (g i) 0 with h | h | h\n · have : ¬ (c < dotProd w (S (e i))) := fun hc => absurd ((hkey i).2 hc) (by linarith)\n push_neg at this\n nlinarith\n · rw [h]; ring_nf; exact le_refl 0\n · have := (hkey i).1 h\n nlinarith\n obtain ⟨i1, hi1⟩ := hpos\n have hp : 0 < ∑ i, g i * (dotProd w (S (e i)) - c) := by\n refine Finset.sum_pos' hnn ⟨i1, Finset.mem_univ i1, ?_⟩\n have := (hkey i1).1 hi1\n nlinarith\n linarith\n have h1' : ∀ j, ∑ i, g0 i * S (e i) j = 0 := by\n have := congrArg Prod.fst hg00\n simp only [hv, Prod.fst_sum, Prod.smul_fst, Prod.fst_zero] at this\n intro j\n have := congrFun this j\n simpa [Finset.sum_apply] using this\n have h2' : ∑ i, g0 i = 0 := by\n have := congrArg Prod.snd hg00\n simpa [hv, Prod.snd_sum] using this\n rcases lt_trichotomy (g0 i0) 0 with hneg | hz | hpos\n · refine key (fun i => - g0 i) ?_ ?_ ⟨i0, by linarith⟩\n · intro j\n show ∑ i, (-g0 i) * S (e i) j = 0\n have hx : ∑ i, (-g0 i) * S (e i) j = -∑ i, g0 i * S (e i) j := by\n rw [← Finset.sum_neg_distrib]; exact Finset.sum_congr rfl fun i _ => by ring\n rw [hx, h1' j, neg_zero]\n · show ∑ i, (-g0 i) = 0\n rw [Finset.sum_neg_distrib, h2', neg_zero]\n · exact hi0 hz\n · exact key g0 h1' h2' ⟨i0, hpos⟩\n\n/-! ### Hamming distance and indicator vectors -/\n\nnoncomputable def ivec {n : ℕ} (T : Finset (Fin n)) : Fin n → ℝ := fun k => if k ∈ T then 1 else 0\n\ndef dst {n : ℕ} (T T' : Finset (Fin n)) : ℕ :=\n (Finset.univ.filter (fun k => ¬ (k ∈ T ↔ k ∈ T'))).card\n\nlemma dst_comm {n : ℕ} (T T' : Finset (Fin n)) : dst T T' = dst T' T := by\n unfold dst\n congr 1\n apply Finset.filter_congr\n intro k _\n constructor <;> · intro h hc; exact h hc.symm\n\nlemma dst_self {n : ℕ} (T : Finset (Fin n)) : dst T T = 0 := by\n unfold dst\n simp\n\nlemma dst_eq_zero {n : ℕ} {T T' : Finset (Fin n)} (h : dst T T' = 0) : T = T' := by\n unfold dst at h\n rw [Finset.card_eq_zero] at h\n ext k\n by_contra hc\n have : k ∈ Finset.univ.filter (fun k => ¬ (k ∈ T ↔ k ∈ T')) := by\n simp only [Finset.mem_filter, Finset.mem_univ, true_and]\n exact hc\n rw [h] at this\n simp at this\n\nlemma dst_triangle {n : ℕ} (a b c : Finset (Fin n)) : dst a c ≤ dst a b + dst b c := by\n unfold dst\n classical\n have hsub : (Finset.univ.filter (fun k => ¬ (k ∈ a ↔ k ∈ c)))\n ⊆ (Finset.univ.filter (fun k => ¬ (k ∈ a ↔ k ∈ b)))\n ∪ (Finset.univ.filter (fun k => ¬ (k ∈ b ↔ k ∈ c))) := by\n intro k hk\n simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_union] at hk ⊢\n by_contra hc\n push_neg at hc\n exact hk (hc.1.trans hc.2)\n exact le_trans (Finset.card_le_card hsub) (Finset.card_union_le _ _)\n\nlemma dst_le_n {n : ℕ} (T T' : Finset (Fin n)) : dst T T' ≤ n := by\n unfold dst\n have := Finset.card_filter_le (Finset.univ : Finset (Fin n)) (fun k => ¬ (k ∈ T ↔ k ∈ T'))\n simpa using this\n\nlemma sum_sq_ivec_sub {n : ℕ} (T T' : Finset (Fin n)) :\n ∑ k, (ivec T k - ivec T' k)^2 = (dst T T' : ℝ) := by\n classical\n unfold ivec dst\n rw [Finset.card_filter]\n push_cast\n refine Finset.sum_congr rfl fun k _ => ?_\n by_cases h1 : k ∈ T <;> by_cases h2 : k ∈ T' <;> simp [h1, h2]\n\nlemma dst_empty {n : ℕ} (T : Finset (Fin n)) : dst T ∅ = T.card := by\n unfold dst\n congr 1\n rw [Finset.filter_congr (q := fun k => k ∈ T) (fun k _ => by simp)]\n simp\n\n/-! ### Sauer-Shelah counting -/\n\nlemma card_le_binom_sum {m D : ℕ} (𝒜 : Finset (Finset (Fin m))) (hvc : 𝒜.vcDim ≤ D) :\n 𝒜.card ≤ ∑ k ∈ Finset.Iic D, m.choose k := by\n classical\n refine le_trans (Finset.card_le_card_shatterer 𝒜) ?_\n refine le_trans Finset.card_shatterer_le_sum_vcDim ?_\n rw [Fintype.card_fin]\n exact Finset.sum_le_sum_of_subset (Finset.Iic_subset_Iic.2 hvc)\n\nlemma card_le_two_pow {m : ℕ} (𝒜 : Finset (Finset (Fin m))) : (𝒜.card : ℝ) ≤ 2^m := by\n have h1 : 𝒜.card ≤ Fintype.card (Finset (Fin m)) := Finset.card_le_univ 𝒜\n rw [Fintype.card_finset, Fintype.card_fin] at h1\n exact_mod_cast h1\n\nlemma sauer_exp {m D : ℕ} (hD : 1 ≤ D) (hDm : D ≤ m) (𝒜 : Finset (Finset (Fin m)))\n (hvc : 𝒜.vcDim ≤ D) : (𝒜.card : ℝ) ≤ (Real.exp 1 * m / D)^D := by\n classical\n have hm : 0 < m := lt_of_lt_of_le hD hDm\n set x : ℝ := (D : ℝ) / m with hx\n have hDpos : (0:ℝ) < D := by exact_mod_cast hD\n have hmpos : (0:ℝ) < m := by exact_mod_cast hm\n have hx0 : 0 < x := div_pos hDpos hmpos\n have hx1 : x ≤ 1 := by\n rw [hx, div_le_one hmpos]\n exact_mod_cast hDm\n -- step 1\n have step1 : ((∑ k ∈ Finset.Iic D, m.choose k : ℕ) : ℝ)\n ≤ x^(-(D:ℤ)) * ∑ k ∈ Finset.Iic D, (m.choose k : ℝ) * x^k := by\n rw [Finset.mul_sum]\n push_cast\n refine Finset.sum_le_sum fun k hk => ?_\n rw [Finset.mem_Iic] at hk\n have hxk : x^D ≤ x^k := pow_le_pow_of_le_one hx0.le hx1 hk\n have hxD : x^(-(D:ℤ)) = (x^D)⁻¹ := by\n rw [zpow_neg, zpow_natCast]\n rw [hxD]\n have hpos : (0:ℝ) < x^D := pow_pos hx0 D\n have h1 : (1:ℝ) ≤ x^k / x^D := (one_le_div hpos).2 hxk\n have hc : (0:ℝ) ≤ (m.choose k : ℝ) := Nat.cast_nonneg _\n calc (m.choose k : ℝ) = (m.choose k : ℝ) * 1 := by ring\n _ ≤ (m.choose k:ℝ) * (x^k/x^D) := mul_le_mul_of_nonneg_left h1 hc\n _ = (x^D)⁻¹ * ((m.choose k:ℝ) * x^k) := by field_simp\n have step2 : ∑ k ∈ Finset.Iic D, (m.choose k : ℝ) * x^k\n ≤ ∑ k ∈ Finset.range (m+1), (m.choose k : ℝ) * x^k := by\n refine Finset.sum_le_sum_of_subset_of_nonneg ?_ (fun k _ _ => by positivity)\n intro k hk\n rw [Finset.mem_Iic] at hk\n rw [Finset.mem_range]\n omega\n have step3 : ∑ k ∈ Finset.range (m+1), (m.choose k : ℝ) * x^k = (x + 1)^m := by\n rw [add_pow]\n refine Finset.sum_congr rfl fun k _ => by rw [one_pow, mul_one]; ring\n have step4 : (x+1)^m ≤ Real.exp (x * m) := by\n have h1 : (x+1)^m ≤ (Real.exp x)^m :=\n pow_le_pow_left₀ (by positivity) (Real.add_one_le_exp x) m\n rw [← Real.exp_nat_mul] at h1\n rw [mul_comm] at h1\n exact h1\n have hxm : x * m = D := by rw [hx]; field_simp\n have hfin : x^(-(D:ℤ)) = ((m:ℝ)/D)^D := by\n rw [hx, zpow_neg, zpow_natCast, ← inv_pow, inv_div]\n calc (𝒜.card : ℝ) ≤ ((∑ k ∈ Finset.Iic D, m.choose k : ℕ) : ℝ) := by\n exact_mod_cast card_le_binom_sum 𝒜 hvc\n _ ≤ x^(-(D:ℤ)) * ∑ k ∈ Finset.Iic D, (m.choose k : ℝ) * x^k := step1\n _ ≤ x^(-(D:ℤ)) * (x+1)^m := by\n rw [← step3]\n exact mul_le_mul_of_nonneg_left step2 (by positivity)\n _ ≤ x^(-(D:ℤ)) * Real.exp ((D:ℝ)) := by\n rw [← hxm]\n exact mul_le_mul_of_nonneg_left step4 (by positivity)\n _ = (Real.exp 1 * m / D)^D := by\n rw [hfin, show Real.exp ((D:ℝ)) = (Real.exp 1)^D by\n rw [← Real.exp_nat_mul]; ring_nf]\n rw [← mul_pow]\n congr 1\n field_simp\n\n\n/-- The set of coordinates on which `T` and `T'` agree. -/\ndef agr {n : ℕ} (T T' : Finset (Fin n)) : Finset (Fin n) :=\n Finset.univ.filter (fun k => (k ∈ T ↔ k ∈ T'))\n\nlemma card_agr_add_dst {n : ℕ} (T T' : Finset (Fin n)) : (agr T T').card + dst T T' = n := by\n classical\n unfold agr dst\n rw [Finset.card_filter_add_card_filter_not]\n simp\n\nlemma exists_good_map {n m : ℕ} (hn : 0 < n) (A : Finset (Finset (Fin n))) (δ : ℝ)\n (hδ0 : 0 < δ) (hδ1 : δ ≤ 1)\n (hsep : ∀ T ∈ A, ∀ T' ∈ A, T ≠ T' → δ * n < (dst T T' : ℝ))\n (hbd : (A.card : ℝ)^2 * (1-δ)^m < 1) :\n ∃ f : Fin m → Fin n, ∀ T ∈ A, ∀ T' ∈ A, T ≠ T' → ∃ i, ¬ (f i ∈ T ↔ f i ∈ T') := by\n classical\n by_contra hcon\n push_neg at hcon\n set P : Finset ((Finset (Fin n)) × (Finset (Fin n))) :=\n (A ×ˢ A).filter (fun p => p.1 ≠ p.2) with hP\n have hcover : (Finset.univ : Finset (Fin m → Fin n))\n ⊆ P.biUnion (fun p => Fintype.piFinset (fun _ => agr p.1 p.2)) := by\n intro f _\n obtain ⟨T, hT, T', hT', hne, hagree⟩ := hcon f\n refine Finset.mem_biUnion.2 ⟨(T, T'), ?_, ?_⟩\n · rw [hP, Finset.mem_filter]\n exact ⟨Finset.mem_product.2 ⟨hT, hT'⟩, hne⟩\n · rw [Fintype.mem_piFinset]\n intro i\n simp only [agr, Finset.mem_filter, Finset.mem_univ, true_and]\n exact hagree i\n have hcard : (n:ℕ)^m ≤ ∑ p ∈ P, (agr p.1 p.2).card ^ m := by\n have h1 : (Finset.univ : Finset (Fin m → Fin n)).card = n ^ m := by\n rw [Finset.card_univ]\n simp\n rw [← h1]\n refine le_trans (Finset.card_le_card hcover) ?_\n refine le_trans (Finset.card_biUnion_le) ?_\n refine Finset.sum_le_sum fun p _ => ?_\n rw [Fintype.card_piFinset]\n simp\n -- real version\n have hnr : (0:ℝ) < n := by exact_mod_cast hn\n have hagrle : ∀ p ∈ P, ((agr p.1 p.2).card : ℝ) ≤ (n:ℝ) * (1-δ) := by\n intro p hp\n rw [hP, Finset.mem_filter, Finset.mem_product] at hp\n have hd := hsep p.1 hp.1.1 p.2 hp.1.2 hp.2\n have := card_agr_add_dst p.1 p.2\n have hc : ((agr p.1 p.2).card : ℝ) + (dst p.1 p.2 : ℝ) = (n:ℝ) := by exact_mod_cast this\n nlinarith\n have hreal : (n:ℝ)^m ≤ (A.card:ℝ)^2 * ((n:ℝ)*(1-δ))^m := by\n have h1 : ((n:ℕ)^m : ℝ) ≤ ∑ p ∈ P, (((agr p.1 p.2).card : ℝ)) ^ m := by\n have := hcard\n have hc : (((n:ℕ)^m : ℕ) : ℝ) ≤ ((∑ p ∈ P, (agr p.1 p.2).card ^ m : ℕ) : ℝ) := by\n exact_mod_cast this\n simpa using hc\n refine le_trans h1 ?_\n have h2 : ∑ p ∈ P, (((agr p.1 p.2).card : ℝ)) ^ m ≤ ∑ _p ∈ P, ((n:ℝ)*(1-δ))^m := by\n refine Finset.sum_le_sum fun p hp => ?_\n exact pow_le_pow_left₀ (by positivity) (hagrle p hp) m\n refine le_trans h2 ?_\n rw [Finset.sum_const, nsmul_eq_mul]\n have hPcard : (P.card : ℝ) ≤ (A.card:ℝ)^2 := by\n have : P.card ≤ (A ×ˢ A).card := Finset.card_filter_le _ _\n rw [Finset.card_product] at this\n have h3 : (P.card : ℝ) ≤ ((A.card * A.card : ℕ) : ℝ) := by exact_mod_cast this\n push_cast at h3\n nlinarith [h3]\n exact mul_le_mul_of_nonneg_right hPcard (pow_nonneg (by nlinarith) m)\n have hexp : ((n:ℝ)*(1-δ))^m = (n:ℝ)^m * (1-δ)^m := mul_pow _ _ _\n rw [hexp] at hreal\n have hnm : (0:ℝ) < (n:ℝ)^m := by positivity\n nlinarith [hreal, hbd, hnm]\n\nlemma vcDim_image_le {n m D : ℕ} (A : Finset (Finset (Fin n))) (hvc : A.vcDim ≤ D)\n (f : Fin m → Fin n) :\n (A.image (fun T => Finset.univ.filter (fun i => f i ∈ T))).vcDim ≤ D := by\n classical\n refine Finset.sup_le fun s hs => ?_\n rw [Finset.mem_shatterer] at hs\n -- f is injective on s\n have hinj : Set.InjOn f (s : Set (Fin m)) := by\n intro i hi i' hi' hff\n by_contra hne\n obtain ⟨u, hu, hsu⟩ := hs (Finset.singleton_subset_iff.2 hi)\n rw [Finset.mem_image] at hu\n obtain ⟨T, hT, rfl⟩ := hu\n have h1 : i ∈ s ∩ Finset.univ.filter (fun i => f i ∈ T) := by\n rw [hsu]; exact Finset.mem_singleton_self i\n have h2 : i' ∉ s ∩ Finset.univ.filter (fun i => f i ∈ T) := by\n rw [hsu]\n simp only [Finset.mem_singleton]\n exact fun hc => hne hc.symm\n simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and] at h1 h2\n exact h2 ⟨hi', by rw [← hff]; exact h1.2⟩\n have hshat : A.Shatters (s.image f) := by\n intro w hw\n set t : Finset (Fin m) := s.filter (fun i => f i ∈ w) with ht\n have hts : t ⊆ s := Finset.filter_subset _ _\n obtain ⟨u, hu, hsu⟩ := hs hts\n rw [Finset.mem_image] at hu\n obtain ⟨T, hT, rfl⟩ := hu\n refine ⟨T, hT, ?_⟩\n ext y\n simp only [Finset.mem_inter, Finset.mem_image]\n constructor\n · rintro ⟨⟨i, hi, rfl⟩, hfT⟩\n have : i ∈ s ∩ Finset.univ.filter (fun i => f i ∈ T) := by\n simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and]\n exact ⟨hi, hfT⟩\n rw [hsu, ht, Finset.mem_filter] at this\n exact this.2\n · intro hyw\n obtain ⟨i, hi, rfl⟩ := Finset.mem_image.1 (hw hyw)\n have hit : i ∈ t := by rw [ht, Finset.mem_filter]; exact ⟨hi, hyw⟩\n have : i ∈ s ∩ Finset.univ.filter (fun i => f i ∈ T) := by rw [hsu]; exact hit\n simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and] at this\n exact ⟨⟨i, hi, rfl⟩, this.2⟩\n have hc : (s.image f).card = s.card := Finset.card_image_of_injOn hinj\n rw [← hc]\n exact hshat.card_le_vcDim.trans hvc\n\n\n/-! ### The packing bound for VC classes -/\n\n/-- The arithmetic core of the packing estimate. -/\nlemma packing_arith {D t δ mm : ℝ} (hDpos : 1 ≤ D) (hu : 0 ≤ -Real.log δ)\n (hδ0 : 0 < δ) (hδ1 : δ ≤ 1) (htpos : 0 < t)\n (hmhigh : mm ≤ 4*(D*t)/δ + 2) (hmpos : 0 < mm)\n (h4 : t ≤ 1 + Real.log (mm/D)) : t ≤ 6 + 2*(-Real.log δ) := by\n have hDpos' : (0:ℝ) < D := by linarith\n rcases le_or_lt δ (2*t) with hcase | hcase\n · have hb2 : (2:ℝ) ≤ 4*t/δ := by\n rw [le_div_iff₀ hδ0]; linarith\n have hb3 : mm/D ≤ 4*t/δ + 2/D := by\n rw [div_le_iff₀ hDpos']\n have hexp : (4*t/δ + 2/D)*D = 4*(D*t)/δ + 2 := by field_simp\n rw [hexp]\n exact hmhigh\n have hb4 : (2:ℝ)/D ≤ 2 := by\n rw [div_le_iff₀ hDpos']; nlinarith\n have hmD8 : mm/D ≤ 8*t/δ := by\n have h8 : (8:ℝ)*t/δ = (4*t/δ) + (4*t/δ) := by ring\n rw [h8]\n linarith\n have h5 : Real.log (mm/D) ≤ Real.log (8*t/δ) :=\n Real.log_le_log (by positivity) hmD8\n have h6 : Real.log (8*t/δ) = Real.log 8 + Real.log t - Real.log δ := by\n rw [Real.log_div (by positivity) (ne_of_gt hδ0),\n Real.log_mul (by norm_num) (ne_of_gt htpos)]\n have h7 : Real.log 8 = 3 * Real.log 2 := by\n rw [show (8:ℝ) = 2^3 by norm_num, Real.log_pow]\n norm_num\n have h8 : Real.log t ≤ t/2 - 1 + Real.log 2 := by\n have hh := Real.log_le_sub_one_of_pos (show (0:ℝ) < t/2 by positivity)\n rw [Real.log_div (ne_of_gt htpos) (by norm_num)] at hh\n linarith\n have hl2 : Real.log 2 < 0.6931471808 := Real.log_two_lt_d9\n rw [h6, h7] at h5\n linarith\n · linarith\n\nlemma packing {n D : ℕ} (hn : 0 < n) (hD : 1 ≤ D) (A : Finset (Finset (Fin n)))\n (hvc : A.vcDim ≤ D) (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ ≤ 1)\n (hsep : ∀ T ∈ A, ∀ T' ∈ A, T ≠ T' → δ * n < (dst T T' : ℝ)) :\n Real.log A.card ≤ 2 * D * (-Real.log δ + 3) := by\n classical\n have hDr : (1:ℝ) ≤ (D:ℝ) := by exact_mod_cast hD\n have hDpos : (0:ℝ) < (D:ℝ) := by linarith\n have hu : 0 ≤ -Real.log δ := by\n have := Real.log_nonpos (le_of_lt hδ0) hδ1\n linarith\n rcases le_or_lt (A.card) 1 with hN1 | hN2\n · have : Real.log (A.card : ℝ) ≤ 0 := by\n apply Real.log_nonpos (by positivity)\n exact_mod_cast hN1\n nlinarith\n · have hN2r : (2:ℝ) ≤ (A.card : ℝ) := by exact_mod_cast hN2\n have hNpos : (0:ℝ) < (A.card:ℝ) := by linarith\n obtain ⟨L, hLdef⟩ : ∃ L : ℝ, L = Real.log (A.card : ℝ) := ⟨_, rfl⟩\n have hL2 : Real.log 2 ≤ L := by rw [hLdef]; exact Real.log_le_log (by norm_num) hN2r\n have hlog2 : (0:ℝ) < Real.log 2 := Real.log_pos (by norm_num)\n have hLpos : 0 < L := lt_of_lt_of_le hlog2 hL2\n have hNe : (A.card:ℝ) = Real.exp L := by rw [hLdef, Real.exp_log hNpos]\n rw [← hLdef]\n obtain ⟨m, hm0, hmlow, hmhigh⟩ :\n ∃ m : ℕ, 0 < m ∧ 4*L/δ ≤ (m:ℝ) ∧ (m:ℝ) ≤ 4*L/δ + 2 := by\n refine ⟨⌈4*L/δ⌉₊ + 1, by omega, ?_, ?_⟩\n · push_cast\n have := Nat.le_ceil (4*L/δ)\n linarith\n · push_cast\n have := Nat.ceil_lt_add_one (a := 4*L/δ) (by positivity)\n linarith\n have hbd : (A.card : ℝ)^2 * (1-δ)^m < 1 := by\n have h1 : (1-δ) ≤ Real.exp (-δ) := by\n have := Real.add_one_le_exp (-δ)\n linarith\n have h2 : (1-δ)^m ≤ (Real.exp (-δ))^m :=\n pow_le_pow_left₀ (by linarith) h1 m\n have h3 : (Real.exp (-δ))^m = Real.exp (-(δ * m)) := by\n rw [← Real.exp_nat_mul]; ring_nf\n have h4 : 4*L ≤ δ * m := by\n have := (div_le_iff₀ hδ0).1 hmlow\n linarith\n have h5 : Real.exp (-(δ*m)) ≤ Real.exp (-(4*L)) := by\n apply Real.exp_le_exp.2; linarith\n have h6 : (1-δ)^m ≤ Real.exp (-(4*L)) := ((h2.trans h3.le).trans h5)\n have hN2eq : (A.card:ℝ)^2 = Real.exp (L + L) := by\n rw [hNe, Real.exp_add]; ring\n calc (A.card:ℝ)^2 * (1-δ)^m ≤ Real.exp (L+L) * Real.exp (-(4*L)) := by\n rw [hN2eq]\n exact mul_le_mul_of_nonneg_left h6 (by positivity)\n _ = Real.exp (-(2*L)) := by rw [← Real.exp_add]; ring_nf\n _ < 1 := by rw [Real.exp_lt_one_iff]; linarith\n obtain ⟨f, hf⟩ := exists_good_map hn A δ hδ0 hδ1 hsep hbd\n have hginj : Set.InjOn (fun T => Finset.univ.filter (fun i => f i ∈ T))\n (A : Set (Finset (Fin n))) := by\n intro T hT T' hT' hTT'\n by_contra hne\n obtain ⟨i, hi⟩ := hf T hT T' hT' hne\n apply hi\n have h := congrArg (fun (s : Finset (Fin m)) => i ∈ s) hTT'\n simpa using h\n have hcardeq : (A.image (fun T => Finset.univ.filter (fun i => f i ∈ T))).card = A.card :=\n Finset.card_image_of_injOn hginj\n have hvc' : (A.image (fun T => Finset.univ.filter (fun i => f i ∈ T))).vcDim ≤ D :=\n vcDim_image_le A hvc f\n rcases le_or_lt m D with hmD | hmD\n · have h1 : (A.card:ℝ) ≤ 2^m := by\n rw [← hcardeq]; exact card_le_two_pow _\n have h2 : L ≤ Real.log ((2:ℝ)^m) := by rw [hLdef]; exact Real.log_le_log hNpos h1\n rw [Real.log_pow] at h2\n have hmDr : (m:ℝ) ≤ (D:ℝ) := by exact_mod_cast hmD\n have hl2 : Real.log 2 < 0.6931471808 := Real.log_two_lt_d9\n have hmnn : (0:ℝ) ≤ (m:ℝ) := by positivity\n nlinarith [hu, hDr, h2]\n · have hDm : D ≤ m := le_of_lt hmD\n have h1 : (A.card:ℝ) ≤ (Real.exp 1 * m / D)^D := by\n rw [← hcardeq]; exact sauer_exp hD hDm _ hvc'\n have hmpos : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm0\n have h2 : L ≤ (D:ℝ) * Real.log (Real.exp 1 * m / D) := by\n have hh := Real.log_le_log hNpos h1\n rw [Real.log_pow] at hh\n rw [hLdef]\n exact_mod_cast hh\n have h3 : Real.log (Real.exp 1 * m / D) = 1 + Real.log ((m:ℝ)/D) := by\n rw [show Real.exp 1 * (m:ℝ) / D = Real.exp 1 * ((m:ℝ)/D) by ring,\n Real.log_mul (by positivity) (by positivity), Real.log_exp]\n rw [h3] at h2\n obtain ⟨t, htdef⟩ : ∃ t : ℝ, t = L / D := ⟨_, rfl⟩\n have hLt : L = D * t := by rw [htdef]; field_simp\n have htpos : 0 < t := by rw [htdef]; positivity\n have h4 : t ≤ 1 + Real.log ((m:ℝ)/D) := by\n rw [hLt] at h2\n nlinarith [h2, hDpos]\n have hmh2 : (m:ℝ) ≤ 4*((D:ℝ)*t)/δ + 2 := by rw [← hLt]; exact hmhigh\n have := packing_arith hDr hu hδ0 hδ1 htpos hmh2 hmpos h4\n rw [hLt]\n nlinarith [this, hDpos, hu]\n\n\nlemma exists_net {n : ℕ} (𝒯 : Finset (Finset (Fin n))) (h𝒯 : 𝒯.Nonempty) (ρ : ℝ) (hρ : 0 ≤ ρ) :\n ∃ A : Finset (Finset (Fin n)), A ⊆ 𝒯 ∧ A.Nonempty ∧\n (∀ T ∈ A, ∀ T' ∈ A, T ≠ T' → ρ < (dst T T' : ℝ)) ∧\n (∀ T ∈ 𝒯, ∃ a ∈ A, (dst T a : ℝ) ≤ ρ) := by\n classical\n set C : Finset (Finset (Finset (Fin n))) :=\n 𝒯.powerset.filter (fun B => ∀ T ∈ B, ∀ T' ∈ B, T ≠ T' → ρ < (dst T T' : ℝ)) with hC\n obtain ⟨T0, hT0⟩ := h𝒯\n have hsingle : ({T0} : Finset (Finset (Fin n))) ∈ C := by\n rw [hC, Finset.mem_filter, Finset.mem_powerset]\n refine ⟨Finset.singleton_subset_iff.2 hT0, ?_⟩\n intro T hT T' hT' hne\n rw [Finset.mem_singleton] at hT hT'\n exact absurd (hT.trans hT'.symm) hne\n obtain ⟨A, hAC, hAmax⟩ := C.exists_max_image Finset.card ⟨_, hsingle⟩\n have hAC' := hAC\n rw [hC, Finset.mem_filter, Finset.mem_powerset] at hAC'\n refine ⟨A, hAC'.1, ?_, hAC'.2, ?_⟩\n · rw [← Finset.card_pos]\n have h1 := hAmax _ hsingle\n rw [Finset.card_singleton] at h1\n omega\n · intro T hT\n by_contra hcon\n push_neg at hcon\n have hTA : T ∉ A := by\n intro h\n have h2 := hcon T h\n rw [dst_self] at h2\n norm_num at h2\n linarith\n have hins : insert T A ∈ C := by\n rw [hC, Finset.mem_filter, Finset.mem_powerset]\n refine ⟨Finset.insert_subset hT hAC'.1, ?_⟩\n intro x hx y hy hxy\n rw [Finset.mem_insert] at hx hy\n rcases hx with rfl | hx\n · rcases hy with rfl | hy\n · exact absurd rfl hxy\n · exact hcon y hy\n · rcases hy with rfl | hy\n · rw [dst_comm]; exact hcon x hx\n · exact hAC'.2 x hx y hy hxy\n have h3 := hAmax _ hins\n rw [Finset.card_insert_of_notMem hTA] at h3\n omega\n\n\n/-! ### Chaining -/\n\nlemma sum_ivec {n : ℕ} (σ : RadSigns n) (T : Finset (Fin n)) :\n ∑ k, sg σ k * ivec T k = ∑ k ∈ T, sg σ k := by\n classical\n unfold ivec\n have h1 : ∀ k, sg σ k * (if k ∈ T then (1:ℝ) else 0) = if k ∈ T then sg σ k else 0 := by\n intro k; split_ifs <;> ring\n simp only [h1]\n rw [← Finset.sum_filter]\n congr 1\n simp\n\nlemma nets_exist {n D : ℕ} (hn : 0 < n) (hD : 1 ≤ D) (𝒯 : Finset (Finset (Fin n)))\n (h𝒯 : 𝒯.Nonempty) (hvc : 𝒯.vcDim ≤ D) (i : ℕ) :\n ∃ (B : Finset (Finset (Fin n))) (q : Finset (Fin n) → Finset (Fin n)),\n B.Nonempty ∧ Real.log (B.card : ℝ) ≤ 2*(D:ℝ)*(2*((i:ℝ)+1)*Real.log 2 + 3) ∧\n (∀ T ∈ 𝒯, q T ∈ B) ∧ (∀ T ∈ 𝒯, (dst T (q T) : ℝ) ≤ (n:ℝ)/4^(i+1)) := by\n classical\n obtain ⟨A, hA𝒯, hAne, hAsep, hAnet⟩ := exists_net 𝒯 h𝒯 ((n:ℝ)/4^(i+1)) (by positivity)\n have hq : ∀ T : Finset (Fin n),\n ∃ a : Finset (Fin n), (T ∈ 𝒯 → (a ∈ A ∧ (dst T a:ℝ) ≤ (n:ℝ)/4^(i+1))) := by\n intro T\n by_cases hT : T ∈ 𝒯\n · obtain ⟨a, ha, hda⟩ := hAnet T hT\n exact ⟨a, fun _ => ⟨ha, hda⟩⟩\n · obtain ⟨a, ha⟩ := hAne\n exact ⟨a, fun h => absurd h hT⟩\n choose q hqq using hq\n refine ⟨A, q, hAne, ?_, fun T hT => (hqq T hT).1, fun T hT => (hqq T hT).2⟩\n have hδ : (0:ℝ) < (1:ℝ)/4^(i+1) := by positivity\n have hδ1 : (1:ℝ)/4^(i+1) ≤ 1 := by\n rw [div_le_one (by positivity)]\n exact one_le_pow₀ (by norm_num)\n have hsep' : ∀ T ∈ A, ∀ T' ∈ A, T ≠ T' → ((1:ℝ)/4^(i+1)) * n < (dst T T' : ℝ) := by\n intro T hT T' hT' hne\n have h := hAsep T hT T' hT' hne\n calc ((1:ℝ)/4^(i+1))*n = (n:ℝ)/4^(i+1) := by ring\n _ < _ := h\n have hvcA : A.vcDim ≤ D := le_trans (Finset.vcDim_mono hA𝒯) hvc\n have hp := packing hn hD A hvcA ((1:ℝ)/4^(i+1)) hδ hδ1 hsep'\n have hlog : -Real.log ((1:ℝ)/4^(i+1)) = 2*((i:ℝ)+1)*Real.log 2 := by\n rw [Real.log_div (by norm_num) (by positivity), Real.log_one, Real.log_pow,\n show (4:ℝ) = 2^2 by norm_num, Real.log_pow]\n push_cast\n ring\n rw [hlog] at hp\n exact hp\n\n\nlemma sqrt_le_div8 (x : ℝ) (hx : 0 ≤ x) : Real.sqrt x ≤ (x + 16)/8 := by\n nlinarith [Real.sq_sqrt hx, Real.sqrt_nonneg x, sq_nonneg (Real.sqrt x - 4)]\n\nlemma geom_sum_one (m : ℕ) : ∑ i ∈ Finset.range m, (1:ℝ)/2^i = 2 - 2/2^m := by\n induction m with\n | zero => norm_num\n | succ k ih =>\n rw [Finset.sum_range_succ, ih]\n field_simp\n ring\n\nlemma geom_sum_lin (m : ℕ) : ∑ i ∈ Finset.range m, (i:ℝ)/2^i = 2 - 2*((m:ℝ)+1)/2^m := by\n induction m with\n | zero => norm_num\n | succ k ih =>\n rw [Finset.sum_range_succ, ih]\n push_cast\n field_simp\n ring\n\nlemma geom_sum_one_le (m : ℕ) : ∑ i ∈ Finset.range m, (1:ℝ)/2^i ≤ 2 := by\n rw [geom_sum_one]\n have : (0:ℝ) < 2/2^m := by positivity\n linarith\n\nlemma geom_sum_lin_le (m : ℕ) : ∑ i ∈ Finset.range m, (i:ℝ)/2^i ≤ 2 := by\n rw [geom_sum_lin]\n have : (0:ℝ) < 2*((m:ℝ)+1)/2^m := by positivity\n linarith\n\n\nlemma chain_series_bound (m : ℕ) :\n ∑ i ∈ Finset.range m, ((3*(i:ℝ)+28)/(4*2^(i+2))) ≤ 3.875 := by\n have hrw : ∀ i:ℕ, (3*(i:ℝ)+28)/(4*2^(i+2)) = (3/16)*((i:ℝ)/2^i) + (28/16)*(1/2^i) := by\n intro i\n rw [pow_add]\n have h2i : ((2:ℝ)^i) ≠ 0 := by positivity\n field_simp\n ring\n rw [Finset.sum_congr rfl (fun i (_ : i ∈ Finset.range m) => hrw i),\n Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum]\n have h1 := geom_sum_lin_le m\n have h2 := geom_sum_one_le m\n linarith\n\nlemma ivec_sq_sum {n : ℕ} (b : Finset (Fin n)) : ∑ k, (ivec b k)^2 = (b.card : ℝ) := by\n have h := sum_sq_ivec_sub b (∅ : Finset (Fin n))\n rw [dst_empty] at h\n rw [← h]\n refine Finset.sum_congr rfl fun k _ => ?_\n simp [ivec]\n\nset_option maxHeartbeats 2000000 in\nlemma chaining {n D : ℕ} (hn : 0 < n) (hD : 1 ≤ D) (𝒯 : Finset (Finset (Fin n)))\n (h𝒯 : ��.Nonempty) (hvc : 𝒯.vcDim ≤ D) :\n Eσ (fun σ => 𝒯.sup' h𝒯 (fun T => ∑ k ∈ T, sg σ k)) ≤ 30 * Real.sqrt (D * n) := by\n classical\n choose B q hBne hBlog hqmem hqdist using nets_exist hn hD 𝒯 h𝒯 hvc\n have hnr : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn\n have hDr : (1:ℝ) ≤ (D:ℝ) := by exact_mod_cast hD\n -- terminal level\n have hterm : ∀ T ∈ 𝒯, q (n-1) T = T := by\n intro T hT\n have h1 := hqdist (n-1) T hT\n have hnn : n - 1 + 1 = n := by omega\n rw [hnn] at h1\n have h2 : (n:ℝ)/4^n < 1 := by\n rw [div_lt_one (by positivity)]\n have : n < 4^n := Nat.lt_pow_self (by norm_num)\n exact_mod_cast this\n have h3 : (dst T (q (n-1) T) : ℝ) < 1 := lt_of_le_of_lt h1 h2\n have h4 : dst T (q (n-1) T) = 0 := by\n by_contra hc\n have h5 : 1 ≤ dst T (q (n-1) T) := Nat.one_le_iff_ne_zero.2 hc\n have h6 : (1:ℝ) ≤ (dst T (q (n-1) T) : ℝ) := by exact_mod_cast h5\n linarith\n exact (dst_eq_zero h4).symm\n -- pairwise distance bound\n have hdstpair : ∀ (i : ℕ), ∀ T ∈ 𝒯,\n (dst (q (i+1) T) (q i T) : ℝ) ≤ 5*(n:ℝ)/4^(i+2) := by\n intro i T hT\n have h1 : (dst (q (i+1) T) (q i T) : ℝ)\n ≤ (dst (q (i+1) T) T : ℝ) + (dst T (q i T) : ℝ) := by\n exact_mod_cast dst_triangle (q (i+1) T) T (q i T)\n have h2 : (dst (q (i+1) T) T : ℝ) = (dst T (q (i+1) T) : ℝ) := by rw [dst_comm]\n have h3 := hqdist (i+1) T hT\n have h4 := hqdist i T hT\n rw [h2] at h1\n have hp : (4:ℝ)^(i+2) = 4^(i+1) * 4 := pow_succ 4 (i+1)\n have h41 : (4:ℝ)^(i+1) ≠ 0 := by positivity\n have h5 : (n:ℝ)/4^(i+1) = 4*((n:ℝ)/4^(i+2)) := by\n rw [hp]; field_simp\n rw [h5] at h4\n have h3' : (dst T (q (i+1) T) : ℝ) ≤ (n:ℝ)/4^(i+2) := h3\n have h7 : 5*(n:ℝ)/4^(i+2) = (n:ℝ)/4^(i+2) + 4*((n:ℝ)/4^(i+2)) := by ring\n rw [h7]\n linarith\n -- the level-0 family and the increment families\n set V0 : Finset (Fin n → ℝ) := (B 0).image ivec with hV0def\n have hV0ne : V0.Nonempty := (hBne 0).image _\n set V : ℕ → Finset (Fin n → ℝ) := fun i =>\n ((B (i+1) ×ˢ B i).filter (fun pr => (dst pr.1 pr.2 : ℝ) ≤ 5*(n:ℝ)/4^(i+2))).image\n (fun pr => ivec pr.1 - ivec pr.2) with hVdef\n obtain ⟨T0, hT0⟩ := id h𝒯\n have hVmem : ∀ (i : ℕ), ∀ T ∈ 𝒯, ivec (q (i+1) T) - ivec (q i T) ∈ V i := by\n intro i T hT\n rw [hVdef]\n simp only [Finset.mem_image, Finset.mem_filter, Finset.mem_product]\n exact ⟨(q (i+1) T, q i T), ⟨⟨hqmem _ _ hT, hqmem _ _ hT⟩, hdstpair i T hT⟩, rfl⟩\n have hVne : ∀ i, (V i).Nonempty := fun i => ⟨_, hVmem i T0 hT0⟩\n -- pointwise chaining\n have hkey : ∀ (σ : RadSigns n), 𝒯.sup' ⟨T0, hT0⟩ (fun T => ∑ k ∈ T, sg σ k)\n ≤ V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k)\n + ∑ i ∈ Finset.range (n-1), (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k) := by\n intro σ\n refine Finset.sup'_le _ _ (fun T hT => ?_)\n have hTel : ∑ i ∈ Finset.range (n-1),\n ((fun i => ∑ k, sg σ k * ivec (q i T) k) (i+1)\n - (fun i => ∑ k, sg σ k * ivec (q i T) k) i)\n = (fun i => ∑ k, sg σ k * ivec (q i T) k) (n-1)\n - (fun i => ∑ k, sg σ k * ivec (q i T) k) 0 :=\n Finset.sum_range_sub (fun i => ∑ k, sg σ k * ivec (q i T) k) (n-1)\n simp only at hTel\n have hfn : ∑ k, sg σ k * ivec (q (n-1) T) k = ∑ k ∈ T, sg σ k := by\n rw [hterm T hT, sum_ivec]\n have hstep : ∀ i ∈ Finset.range (n-1),\n (∑ k, sg σ k * ivec (q (i+1) T) k) - (∑ k, sg σ k * ivec (q i T) k)\n ≤ (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k) := by\n intro i _\n have heq : (∑ k, sg σ k * ivec (q (i+1) T) k) - (∑ k, sg σ k * ivec (q i T) k)\n = ∑ k, sg σ k * (ivec (q (i+1) T) - ivec (q i T)) k := by\n rw [← Finset.sum_sub_distrib]\n refine Finset.sum_congr rfl fun k _ => ?_\n simp only [Pi.sub_apply]\n ring\n rw [heq]\n exact Finset.le_sup' (f := fun v : Fin n → ℝ => ∑ k, sg σ k * v k) (hVmem i T hT)\n have h0 : (∑ k, sg σ k * ivec (q 0 T) k) ≤ V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k) := by\n have hm : ivec (q 0 T) ∈ V0 := Finset.mem_image_of_mem _ (hqmem 0 T hT)\n exact Finset.le_sup' (f := fun v : Fin n → ℝ => ∑ k, sg σ k * v k) hm\n have hs := Finset.sum_le_sum hstep\n rw [hTel, hfn] at hs\n linarith\n -- pass to expectations\n have hE1 : Eσ (fun σ => 𝒯.sup' h𝒯 (fun T => ∑ k ∈ T, sg σ k))\n ≤ Eσ (fun σ => V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k)\n + ∑ i ∈ Finset.range (n-1), (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k)) :=\n Eσ_mono hkey\n have hE2 : Eσ (fun σ => V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k)\n + ∑ i ∈ Finset.range (n-1), (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k))\n = Eσ (fun σ => V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k))\n + ∑ i ∈ Finset.range (n-1),\n Eσ (fun σ => (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k)) := by\n rw [Eσ_add (fun σ => V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k))\n (fun σ => ∑ i ∈ Finset.range (n-1), (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k))]\n congr 1\n exact Eσ_finsum (Finset.range (n-1))\n (fun i σ => (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k))\n rw [hE2] at hE1\n -- Massart at level 0\n have hm0 : Eσ (fun σ => V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k))\n ≤ Real.sqrt n * Real.sqrt (2 * Real.log (2 * V0.card)) := by\n refine massart V0 hV0ne (Real.sqrt n) (Real.sqrt_nonneg _) ?_\n intro v hv\n rw [hV0def, Finset.mem_image] at hv\n obtain ⟨b, hb, rfl⟩ := hv\n rw [ivec_sq_sum, Real.sq_sqrt hnr.le]\n have : b.card ≤ n := by\n have := Finset.card_le_univ b\n simpa using this\n exact_mod_cast this\n -- Massart at level i\n have h4pow : ∀ i : ℕ, ((2:ℝ)^(i+2))^2 = 4^(i+2) := by\n intro i\n rw [← pow_mul, mul_comm (i+2) 2, pow_mul]\n norm_num\n have hmi : ∀ i, Eσ (fun σ => (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k))\n ≤ (Real.sqrt 5 * Real.sqrt n / 2^(i+2)) * Real.sqrt (2 * Real.log (2 * (V i).card)) := by\n intro i\n refine massart (V i) (hVne i) _ (by positivity) ?_\n intro v hv\n rw [hVdef] at hv\n simp only [Finset.mem_image, Finset.mem_filter, Finset.mem_product] at hv\n obtain ⟨pr, ⟨⟨h1, h2⟩, h3⟩, rfl⟩ := hv\n have hsq : ∑ k, ((ivec pr.1 - ivec pr.2) k)^2 = (dst pr.1 pr.2 : ℝ) := by\n rw [← sum_sq_ivec_sub]\n exact Finset.sum_congr rfl fun k _ => by simp only [Pi.sub_apply]\n rw [hsq]\n have hR : (Real.sqrt 5 * Real.sqrt n / 2^(i+2))^2 = 5*(n:ℝ)/4^(i+2) := by\n rw [div_pow, mul_pow, Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 5), Real.sq_sqrt hnr.le,\n h4pow i]\n rw [hR]\n exact h3\n -- numeric bounds on the log-cardinalities\n have hl2 : Real.log 2 < 0.6931471808 := Real.log_two_lt_d9\n have hl2p : 0 < Real.log 2 := Real.log_pos (by norm_num)\n have hD0 : (0:ℝ) ≤ (D:ℝ) := by linarith\n have hDl : (D:ℝ) * Real.log 2 ≤ 0.6931471808 * (D:ℝ) := by\n have := mul_le_mul_of_nonneg_left hl2.le hD0\n linarith\n have hlog0 : 2 * Real.log (2 * (V0.card:ℝ)) ≤ 20 * (D:ℝ) := by\n have hB0pos : (1:ℝ) ≤ ((B 0).card : ℝ) := by\n exact_mod_cast Finset.card_pos.2 (hBne 0)\n have hV0pos : (1:ℝ) ≤ (V0.card : ℝ) := by\n exact_mod_cast Finset.card_pos.2 hV0ne\n have hV0card : V0.card ≤ (B 0).card := by rw [hV0def]; exact Finset.card_image_le\n have hV0cardr : (V0.card : ℝ) ≤ ((B 0).card:ℝ) := by exact_mod_cast hV0card\n have h1 : Real.log (2 * (V0.card:ℝ)) ≤ Real.log (2 * ((B 0).card:ℝ)) :=\n Real.log_le_log (by linarith) (by linarith)\n have h2 : Real.log (2 * ((B 0).card:ℝ)) = Real.log 2 + Real.log ((B 0).card:ℝ) :=\n Real.log_mul (by norm_num) (by linarith)\n have h3 := hBlog 0\n rw [Nat.cast_zero] at h3\n nlinarith [h1, h2, h3, hDr, hl2, hDl]\n have hlogi : ∀ i : ℕ, 2 * Real.log (2 * ((V i).card:ℝ)) ≤ 4*(D:ℝ)*(3*(i:ℝ)+12) := by\n intro i\n have hB1 : (1:ℝ) ≤ ((B (i+1)).card : ℝ) := by\n exact_mod_cast Finset.card_pos.2 (hBne (i+1))\n have hB2 : (1:ℝ) ≤ ((B i).card : ℝ) := by\n exact_mod_cast Finset.card_pos.2 (hBne i)\n have hVpos : (1:ℝ) ≤ ((V i).card : ℝ) := by\n exact_mod_cast Finset.card_pos.2 (hVne i)\n have hVcard : (V i).card ≤ (B (i+1)).card * (B i).card := by\n rw [hVdef]\n refine le_trans Finset.card_image_le ?_\n refine le_trans (Finset.card_filter_le _ _) ?_\n rw [Finset.card_product]\n have hVcardr : ((V i).card : ℝ) ≤ ((B (i+1)).card : ℝ) * ((B i).card : ℝ) := by\n exact_mod_cast hVcard\n have h1 : Real.log (2 * ((V i).card:ℝ))\n ≤ Real.log (2 * (((B (i+1)).card:ℝ) * ((B i).card:ℝ))) :=\n Real.log_le_log (by linarith) (by nlinarith)\n have h2 : Real.log (2 * (((B (i+1)).card:ℝ) * ((B i).card:ℝ)))\n = Real.log 2 + Real.log ((B (i+1)).card:ℝ) + Real.log ((B i).card:ℝ) := by\n rw [Real.log_mul (by norm_num) (by positivity),\n Real.log_mul (by linarith) (by linarith)]\n ring\n have h3 := hBlog (i+1)\n have h4 := hBlog i\n rw [Nat.cast_add, Nat.cast_one] at h3\n have hi0 : (0:ℝ) ≤ (i:ℝ) := by positivity\n have hDli : (D:ℝ) * ((i:ℝ) * Real.log 2) ≤ 0.6931471808 * ((D:ℝ) * (i:ℝ)) := by\n have : (i:ℝ) * Real.log 2 ≤ 0.6931471808 * (i:ℝ) := by\n have := mul_le_mul_of_nonneg_left hl2.le hi0\n linarith\n nlinarith [this, hD0]\n nlinarith [h1, h2, h3, h4, hDr, hl2, hDl, hDli, hi0]\n clear_value V0 V\n -- square root bounds\n have hsqrt20 : Real.sqrt 20 ≤ 4.5 := by\n have h := Real.sqrt_le_sqrt (show (20:ℝ) ≤ 4.5^2 by norm_num)\n rwa [Real.sqrt_sq (by norm_num)] at h\n have hsqrt5 : Real.sqrt 5 ≤ 2.25 := by\n have h := Real.sqrt_le_sqrt (show (5:ℝ) ≤ 2.25^2 by norm_num)\n rwa [Real.sqrt_sq (by norm_num)] at h\n have hsq0 : Real.sqrt (2 * Real.log (2 * (V0.card:ℝ))) ≤ 4.5 * Real.sqrt D := by\n refine (Real.sqrt_le_sqrt hlog0).trans ?_\n rw [Real.sqrt_mul (by norm_num : (0:ℝ) ≤ 20)]\n exact mul_le_mul_of_nonneg_right hsqrt20 (Real.sqrt_nonneg _)\n have hsqi : ∀ i : ℕ, Real.sqrt (2 * Real.log (2 * ((V i).card:ℝ)))\n ≤ Real.sqrt D * (3*(i:ℝ)+28)/4 := by\n intro i\n refine (Real.sqrt_le_sqrt (hlogi i)).trans ?_\n have h2 : (4:ℝ)*(D:ℝ)*(3*(i:ℝ)+12) = 4 * ((D:ℝ)*(3*(i:ℝ)+12)) := by ring\n rw [h2, Real.sqrt_mul (by norm_num : (0:ℝ) ≤ 4), Real.sqrt_mul hD0,\n show Real.sqrt 4 = 2 by\n rw [show (4:ℝ) = 2^2 by norm_num, Real.sqrt_sq (by norm_num : (0:ℝ) ≤ 2)]]\n have h3 : Real.sqrt (3*(i:ℝ)+12) ≤ (3*(i:ℝ)+28)/8 := by\n have h33 := sqrt_le_div8 (3*(i:ℝ)+12) (by positivity)\n linarith\n have hDs : 0 ≤ Real.sqrt (D:ℝ) := Real.sqrt_nonneg _\n have h4 := mul_le_mul_of_nonneg_left h3 hDs\n linarith\n -- assemble\n have hX : (0:ℝ) ≤ Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ) := by positivity\n have hterm0 : Eσ (fun σ => V0.sup' hV0ne (fun v => ∑ k, sg σ k * v k))\n ≤ 4.5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ)) := by\n refine hm0.trans ?_\n have := mul_le_mul_of_nonneg_left hsq0 (Real.sqrt_nonneg (n:ℝ))\n calc Real.sqrt n * Real.sqrt (2 * Real.log (2 * (V0.card:ℝ)))\n ≤ Real.sqrt n * (4.5 * Real.sqrt (D:ℝ)) := this\n _ = 4.5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ)) := by ring\n have htermi : ∀ i : ℕ, Eσ (fun σ => (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k))\n ≤ (Real.sqrt 5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ))) * ((3*(i:ℝ)+28)/(4*2^(i+2))) := by\n intro i\n refine (hmi i).trans ?_\n have hcoef : (0:ℝ) ≤ Real.sqrt 5 * Real.sqrt (n:ℝ) / 2^(i+2) := by positivity\n calc (Real.sqrt 5 * Real.sqrt n / 2^(i+2)) * Real.sqrt (2 * Real.log (2 * ((V i).card:ℝ)))\n ≤ (Real.sqrt 5 * Real.sqrt n / 2^(i+2)) * (Real.sqrt (D:ℝ) * (3*(i:ℝ)+28)/4) :=\n mul_le_mul_of_nonneg_left (hsqi i) hcoef\n _ = (Real.sqrt 5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ))) * ((3*(i:ℝ)+28)/(4*2^(i+2))) := by\n ring\n have hsumbound := chain_series_bound (n-1)\n have hsum : ∑ i ∈ Finset.range (n-1),\n Eσ (fun σ => (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k))\n ≤ (Real.sqrt 5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ))) * 3.875 := by\n calc ∑ i ∈ Finset.range (n-1),\n Eσ (fun σ => (V i).sup' (hVne i) (fun v => ∑ k, sg σ k * v k))\n ≤ ∑ i ∈ Finset.range (n-1),\n (Real.sqrt 5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ))) * ((3*(i:ℝ)+28)/(4*2^(i+2))) :=\n Finset.sum_le_sum (fun i _ => htermi i)\n _ = (Real.sqrt 5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ)))\n * ∑ i ∈ Finset.range (n-1), ((3*(i:ℝ)+28)/(4*2^(i+2))) := by\n rw [← Finset.mul_sum]\n _ ≤ (Real.sqrt 5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ))) * 3.875 :=\n mul_le_mul_of_nonneg_left hsumbound (by positivity)\n have hgoal : Real.sqrt ((D:ℝ) * (n:ℝ)) = Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ) :=\n Real.sqrt_mul hD0 _\n rw [hgoal]\n refine hE1.trans ?_\n have hkey5 : Real.sqrt 5 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ))\n ≤ 2.25 * (Real.sqrt (D:ℝ) * Real.sqrt (n:ℝ)) :=\n mul_le_mul_of_nonneg_right hsqrt5 hX\n linarith [hterm0, hsum, hX, hkey5]\n\n\nlemma Eσ_Zs_bound {n : ℕ} (hn : 0 < n) : Eσ (fun σ : RadSigns n => Zs σ) ≤ 2 * Real.sqrt n := by\n classical\n have hV : ({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).Nonempty := ⟨0, by simp⟩\n have hsup : ∀ σ : RadSigns n,\n ({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).sup' hV\n (fun v => ∑ k, sg σ k * v k) = Zs σ := by\n intro σ\n rw [Finset.sup'_insert (H := Finset.singleton_nonempty _), Finset.sup'_singleton]\n unfold Zs\n have e1 : (∑ k, sg σ k * (0 : Fin n → ℝ) k) = 0 := by simp\n have e2 : (∑ k, sg σ k * ((fun _ => (-1:ℝ)) : Fin n → ℝ) k) = -∑ k, sg σ k := by\n rw [← Finset.sum_neg_distrib]\n exact Finset.sum_congr rfl fun k _ => by simp\n rw [e1, e2]\n have hcard : ((({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).card : ℝ)) ≤ 2 := by\n have h : ({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).card ≤ 2 :=\n le_trans (Finset.card_insert_le _ _) (by simp)\n exact_mod_cast h\n have hcard1 : (1:ℝ) ≤ (({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).card : ℝ) := by\n have h : 1 ≤ ({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).card :=\n Finset.card_pos.2 hV\n exact_mod_cast h\n have hbd : ∀ v ∈ ({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)),\n ∑ k, (v k)^2 ≤ (Real.sqrt n)^2 := by\n intro v hv\n have hsq : (Real.sqrt n)^2 = (n:ℝ) := Real.sq_sqrt (by positivity)\n rw [hsq]\n simp only [Finset.mem_insert, Finset.mem_singleton] at hv\n rcases hv with rfl | rfl\n · simp\n · simp\n have hm := massart _ hV (Real.sqrt n) (Real.sqrt_nonneg _) hbd\n simp only [hsup] at hm\n refine hm.trans ?_\n have hlog4 : Real.log 4 < 2 := by\n have h2 : Real.log 4 = Real.log 2 + Real.log 2 := by\n rw [← Real.log_mul (by norm_num) (by norm_num)]\n norm_num\n have := Real.log_two_lt_d9\n rw [h2]; linarith\n have hlog : Real.log (2 * (({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).card : ℝ))\n ≤ Real.log 4 := Real.log_le_log (by linarith) (by linarith)\n have hsqrt : Real.sqrt\n (2 * Real.log (2 * (({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).card : ℝ)))\n ≤ 2 := by\n have h4 : (2:ℝ) * Real.log (2 * (({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))}\n : Finset (Fin n → ℝ)).card : ℝ)) ≤ 4 := by linarith\n refine le_trans (Real.sqrt_le_sqrt h4) ?_\n rw [show (4:ℝ) = 2^2 by norm_num, Real.sqrt_sq (by norm_num : (0:ℝ) ≤ 2)]\n calc Real.sqrt n * Real.sqrt (2 * Real.log (2 *\n (({(0 : Fin n → ℝ), (fun _ => (-1:ℝ))} : Finset (Fin n → ℝ)).card : ℝ)))\n ≤ Real.sqrt n * 2 := mul_le_mul_of_nonneg_left hsqrt (Real.sqrt_nonneg _)\n _ = 2 * Real.sqrt n := by ring\n\nlemma Eσ_Qs_bound {n d : ℕ} (hn : 0 < n) (S : Fin n → (Fin d → ℝ)) :\n Eσ (fun σ => Qs S σ) ≤ 30 * Real.sqrt (((d:ℝ)+1) * n) := by\n have h := chaining hn (D := d+1) (by omega) (hsFam S) (hsFam_nonempty S) (hsFam_vcDim S)\n have hcast : (((d+1 : ℕ)):ℝ) = (d:ℝ) + 1 := by push_cast; ring\n rw [hcast] at h\n exact h\n\nlemma Eσ_Gs_bound {n d : ℕ} (hn : 0 < n) {M : ℝ} (hM : 0 ≤ M) (S : Fin n → (Fin d → ℝ)) :\n Eσ (Gs M S) ≤ M * 32 * Real.sqrt (d + 1) / Real.sqrt n := by\n have hsn : 0 < Real.sqrt n := Real.sqrt_pos.2 (by exact_mod_cast hn)\n have hnn : (n:ℝ) = Real.sqrt n * Real.sqrt n := (Real.mul_self_sqrt (by positivity)).symm\n have hsd : (1:ℝ) ≤ Real.sqrt ((d:ℝ)+1) := by\n rw [show (1:ℝ) = Real.sqrt 1 by simp]\n apply Real.sqrt_le_sqrt\n simp\n have hsplit : Real.sqrt (((d:ℝ)+1) * n) = Real.sqrt ((d:ℝ)+1) * Real.sqrt n :=\n Real.sqrt_mul (by positivity) _\n have h1 : Eσ (Gs M S)\n = ((n:ℝ)⁻¹ * M) * (Eσ (fun σ => Qs S σ) + Eσ (fun σ : RadSigns n => Zs σ)) := by\n unfold Gs\n rw [Eσ_smul ((n:ℝ)⁻¹ * M) (fun σ : RadSigns n => Qs S σ + Zs σ),\n Eσ_add (fun σ : RadSigns n => Qs S σ) (fun σ : RadSigns n => Zs σ)]\n rw [h1]\n have h2 : Eσ (fun σ => Qs S σ) + Eσ (fun σ : RadSigns n => Zs σ)\n ≤ 30 * Real.sqrt (((d:ℝ)+1) * n) + 2 * Real.sqrt n :=\n add_le_add (Eσ_Qs_bound hn S) (Eσ_Zs_bound hn)\n have hcoef : (0:ℝ) ≤ (n:ℝ)⁻¹ * M := by positivity\n refine le_trans (mul_le_mul_of_nonneg_left h2 hcoef) ?_\n rw [hsplit]\n rw [div_eq_mul_inv]\n have hkey : ((n:ℝ)⁻¹ * M) * (30 * (Real.sqrt ((d:ℝ)+1) * Real.sqrt n) + 2 * Real.sqrt n)\n ≤ M * 32 * Real.sqrt ((d:ℝ)+1) * (Real.sqrt n)⁻¹ := by\n have hinv : (n:ℝ)⁻¹ * Real.sqrt n = (Real.sqrt n)⁻¹ := by\n rw [show ((n:ℝ))⁻¹ = ((Real.sqrt n) * (Real.sqrt n))⁻¹ by\n rw [Real.mul_self_sqrt (by positivity)],\n mul_inv, mul_assoc, inv_mul_cancel₀ (ne_of_gt hsn), mul_one]\n have hexp : ((n:ℝ)⁻¹ * M) * (30 * (Real.sqrt ((d:ℝ)+1) * Real.sqrt n) + 2 * Real.sqrt n)\n = (M * ((n:ℝ)⁻¹ * Real.sqrt n)) * (30 * Real.sqrt ((d:ℝ)+1) + 2) := by ring\n rw [hexp, hinv]\n have hMs : (0:ℝ) ≤ M * (Real.sqrt n)⁻¹ := by positivity\n have : 30 * Real.sqrt ((d:ℝ)+1) + 2 ≤ 32 * Real.sqrt ((d:ℝ)+1) := by linarith\n calc (M * (Real.sqrt n)⁻¹) * (30 * Real.sqrt ((d:ℝ)+1) + 2)\n ≤ (M * (Real.sqrt n)⁻¹) * (32 * Real.sqrt ((d:ℝ)+1)) :=\n mul_le_mul_of_nonneg_left this hMs\n _ = M * 32 * Real.sqrt ((d:ℝ)+1) * (Real.sqrt n)⁻¹ := by ring\n exact hkey\n\nlemma Gs_nonneg {n d : ℕ} {M : ℝ} (hM : 0 ≤ M) (S : Fin n → (Fin d → ℝ)) (σ : RadSigns n) :\n 0 ≤ Gs M S σ := by\n unfold Gs\n have h1 : (0:ℝ) ≤ (n:ℝ)⁻¹ := by positivity\n have h2 := Qs_nonneg S σ\n have h3 := Zs_nonneg σ\n have : (0:ℝ) ≤ (n:ℝ)⁻¹ * M := by positivity\n nlinarith\n\ntheorem ch11_proposition_11_9\n {d n : ℕ} {M A : ℝ}\n (μ : MeasureTheory.Measure (Fin d → ℝ)) [IsProbabilityMeasure μ]\n (S : Fin n → (Fin d → ℝ))\n (h : ℝ → ℝ)\n (hmono : Monotone h ∨ Antitone h)\n (hrange : ∀ t, h t ∈ Set.Icc (0 : ℝ) M)\n (hM : 0 ≤ M) (hA : 0 ≤ A) (hn : 0 < n) :\n empRadSigned n (famPM (d := d) h) S\n ≤ M * 32 * Real.sqrt (d + 1) / Real.sqrt n\n ∧\n empRadSigned n (famA μ A h) S\n ≤ A * M * 32 * Real.sqrt (d + 1) / Real.sqrt n := by\n have hcard : ((Fintype.card (RadSigns n) : ℝ)) = 2 ^ n := by\n rw [card_radSigns]; push_cast; ring\n have hkey := key_pointwise hn hM S h hmono hrange\n have hEG := Eσ_Gs_bound (d := d) hn hM S\n constructor\n · have e1 : empRadSigned n (famPM (d := d) h) S\n = Eσ (fun σ => ⨆ p : IdxPM d, (n:ℝ)⁻¹ * ∑ k, sg σ k * famPM h p (S k)) := by\n unfold empRadSigned Eσ\n rw [hcard]\n rfl\n rw [e1]\n refine le_trans (Eσ_mono ?_) hEG\n intro σ\n refine ciSup_le fun p => ?_\n have hb := hkey σ p.1\n have hval : ∀ k : Fin n, sg σ k * famPM h p (S k)\n = (if p.2 then (1:ℝ) else -1) * (sg σ k * h (dotProd p.1 (S k))) := by\n intro k; unfold famPM; ring\n rw [Finset.sum_congr rfl (fun k (_ : k ∈ Finset.univ) => hval k), ← Finset.mul_sum]\n rcases Bool.eq_false_or_eq_true p.2 with hp | hp <;> rw [hp]\n · have e : (n:ℝ)⁻¹ * ((if (true : Bool) then (1:ℝ) else -1)\n * ∑ k, sg σ k * h (dotProd p.1 (S k)))\n = (n:ℝ)⁻¹ * ∑ k, sg σ k * h (dotProd p.1 (S k)) := by\n norm_num\n rw [e]\n exact le_of_abs_le hb\n · have e : (n:ℝ)⁻¹ * ((if (false : Bool) then (1:ℝ) else -1)\n * ∑ k, sg σ k * h (dotProd p.1 (S k)))\n = -((n:ℝ)⁻¹ * ∑ k, sg σ k * h (dotProd p.1 (S k))) := by\n norm_num\n rw [e]\n have := (abs_le.mp hb).1\n linarith\n · have e2 : empRadSigned n (famA μ A h) S\n = Eσ (fun σ => ⨆ u : IdxA μ A, (n:ℝ)⁻¹ * ∑ k, sg σ k * famA μ A h u (S k)) := by\n unfold empRadSigned Eσ\n rw [hcard]\n rfl\n rw [e2]\n have hmeas : ∀ (x : Fin d → ℝ), Measurable (fun θ : Fin d → ℝ => h (dotProd θ x)) := by\n intro x\n have hc : Continuous (fun θ : Fin d → ℝ => dotProd θ x) := by\n unfold dotProd\n exact continuous_finset_sum _ (fun i _ => (continuous_apply i).mul continuous_const)\n rcases hmono with hm | hm\n · exact hm.measurable.comp hc.measurable\n · exact hm.measurable.comp hc.measurable\n have hbdd : ∀ (x θ : Fin d → ℝ), ‖h (dotProd θ x)‖ ≤ M := by\n intro x θ\n rcases hrange (dotProd θ x) with ⟨h1, h2⟩\n rw [Real.norm_eq_abs, abs_of_nonneg h1]; exact h2\n haveI : Nonempty (IdxA μ A) := ⟨⟨0, integrable_zero _ _ _, by simpa using hA⟩⟩\n refine le_trans (Eσ_mono (G := fun σ => A * Gs M S σ) ?_) ?_\n · intro σ\n refine ciSup_le fun u => ?_\n set F : (Fin d → ℝ) → ℝ := fun θ => (n:ℝ)⁻¹ * ∑ k, sg σ k * h (dotProd θ (S k)) with hF\n have hFmeas : Measurable F := by\n rw [hF]\n exact measurable_const.mul (Finset.measurable_sum _\n (fun k _ => measurable_const.mul (hmeas (S k))))\n have hFbd : ∀ θ, ‖F θ‖ ≤ Gs M S σ := fun θ => hkey σ θ\n have hint1 : ∀ k : Fin n, Integrable (fun θ => u.1 θ * h (dotProd θ (S k))) μ :=\n fun k => u.2.1.mul_bdd ((hmeas (S k)).aestronglyMeasurable) (ae_of_all _ (hbdd (S k)))\n have step1 : ∫ θ, u.1 θ * F θ ∂μ = (n:ℝ)⁻¹ * ∑ k, sg σ k * famA μ A h u (S k) := by\n have hrw : (fun θ => u.1 θ * F θ)\n = fun θ => ∑ k, ((n:ℝ)⁻¹ * sg σ k) * (u.1 θ * h (dotProd θ (S k))) := by\n funext θ\n rw [hF]\n simp only [Finset.mul_sum]\n exact Finset.sum_congr rfl fun k _ => by ring\n rw [hrw, integral_finset_sum _ (fun k _ => (hint1 k).const_mul _)]\n simp only [integral_const_mul]\n rw [Finset.mul_sum]\n exact Finset.sum_congr rfl fun k _ => by unfold famA; ring\n have step2 : ∫ θ, u.1 θ * F θ ∂μ ≤ ∫ θ, |u.1 θ| * Gs M S σ ∂μ := by\n refine integral_mono (u.2.1.mul_bdd hFmeas.aestronglyMeasurable (ae_of_all _ hFbd))\n (u.2.1.abs.mul_const _) (fun θ => ?_)\n calc u.1 θ * F θ ≤ |u.1 θ * F θ| := le_abs_self _\n _ = |u.1 θ| * |F θ| := abs_mul _ _\n _ ≤ |u.1 θ| * Gs M S σ := by\n exact mul_le_mul_of_nonneg_left (hFbd θ) (abs_nonneg _)\n have step3 : ∫ θ, |u.1 θ| * Gs M S σ ∂μ = (∫ θ, |u.1 θ| ∂μ) * Gs M S σ :=\n integral_mul_const _ _\n rw [← step1]\n refine step2.trans ?_\n rw [step3]\n exact mul_le_mul_of_nonneg_right u.2.2 (Gs_nonneg hM S σ)\n · have : Eσ (fun σ => A * Gs M S σ) = A * Eσ (Gs M S) := Eσ_smul A (Gs M S)\n rw [this]\n calc A * Eσ (Gs M S) ≤ A * (M * 32 * Real.sqrt (d+1) / Real.sqrt n) :=\n mul_le_mul_of_nonneg_left hEG hA\n _ = A * M * 32 * Real.sqrt (d+1) / Real.sqrt n := by ring\n\nend GraduateLevel\n"} +{"id": "ch12_lemma_12_27", "source": "Graduate-level", "targets": [{"label": "ch12_lemma_12_27", "decls": ["ch12_lemma_12_27"], "statement": "Consider a finite family of distributions \\(\\mathcal{P}\\). Let \\(d \\geq 1\\) be an integer, and \\(Q\\) can be decomposed as\n\\[\nQ(\\theta,\\mathcal{D})=\\sum_{j=1}^{d}Q_{j}(\\theta,\\mathcal{D}),\n\\]\nwhere \\( Q_{j} \\geq 0 \\) are all non-negative. Assume for all \\( j \\), there exists a partition \\( M_{j} \\) of \\( \\mathcal{P} \\). We use notation \\( \\mathcal{D}' \\sim_{j} \\mathcal{D} \\) to indicate that \\( \\mathcal{D}' \\) and \\( \\mathcal{D} \\) belong to the same partition in \\( M_{j} \\). Let \\( m_{j}(\\mathcal{D}) \\) be the number of elements in the partition containing \\( \\mathcal{D} \\). Assume there exist \\( \\epsilon, \\beta \\geq 0 \\) such that\n\\[\n\\begin{array}{l}\\forall\\mathcal{D}^{\\prime}\\sim_{j}\\mathcal{D},\\mathcal{D}^{\\prime}\\neq\\mathcal{D}:\\quad\\inf_{\\theta}[Q_{j}(\\theta,\\mathcal{D}^{\\prime})+Q_{j}(\\theta,\\mathcal{D})]\\geq\\epsilon,\\\\ \\forall\\mathcal{D}\\in\\mathcal{P}:\\frac{1}{d(\\mathcal{P})}\\sum_{j=1}^{d}\\sum_{\\mathcal{D}\\in\\mathcal{P}_{j}}\\frac{1}{m_{j}(\\mathcal{D})-1}\\sum_{\\mathcal{D}^{\\prime}\\sim_{j}\\mathcal{D}}\\|\\mathcal{D}^{\\prime}-\\mathcal{D}\\|_{\\mathrm{TV}}\\leq\\beta,\\\\ \\end{array}\n\\]\nwhere \\(\\mathcal{P}_j = \\{\\mathcal{D}\\in \\mathcal{P}:m_j(\\mathcal{D}) > 1\\}\\) and \\(d(\\mathcal{P}) = \\sum_{j = 1}^{d}|\\mathcal{P}_j|\\). Let \\(\\mathcal{A}(Z)\\) be any estimator, we have\n\\[\n\\frac{1}{|\\mathcal{P}|}\\sum_{\\mathcal{D}\\in\\mathcal{P}}\\mathbb{E}_{Z\\sim\\mathcal{D}}\\mathbb{E}_{\\mathcal{A}}Q(\\mathcal{A}(Z),\\mathcal{D})\\geq\\frac{\\epsilon d(\\mathcal{P})}{2|\\mathcal{P}|}[1-\\beta],\n\\]\nwhere \\(\\mathbb{E}_A\\) is with respect to the internal randomization in \\(\\mathcal{A}\\).", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Statistical Estimation & Minimax Theory"}], "nl_proof": "For notation convenient, assume there exists \\(d\\mu (z)\\) so that for all \\(\\mathcal{D}\\in \\mathcal{P}\\), \\(p_{\\mathcal{D}}(z)d\\mu (z)\\) is the distribution of \\(\\mathcal{D}\\). Then\n\\[\n\\begin{array}{l}\\frac{2}{|\\mathcal{P}|}\\sum_{j=1}^{d}\\sum_{\\mathcal{D}\\in\\mathcal{P}}\\mathbb{E}_{Z\\sim\\mathcal{D}}Q_{j}(\\mathcal{A}(Z),\\mathcal{D})\\geq\\frac{2}{|\\mathcal{P}|}\\sum_{j=1}^{d}\\sum_{\\mathcal{D}\\in\\mathcal{P}_{j}}\\mathbb{E}_{Z\\sim\\mathcal{D}}Q_{j}(\\mathcal{A}(Z),\\mathcal{D})\\\\ =\\frac{1}{|\\mathcal{P}|}\\sum_{j=1}^{d}\\sum_{\\mathcal{D}\\in\\mathcal{P}_{j}}\\frac{1}{m_{j}(\\mathcal{D})-1}\\sum_{\\substack{\\mathcal{D}^{\\prime}\\sim_{j}\\mathcal{D}\\\\ \\mathcal{D}^{\\prime}\\neq\\mathcal{D}}}\\left[\\mathbb{E}_{Z\\sim\\mathcal{D}^{\\prime}}Q_{j}(\\mathcal{A}(Z),\\mathcal{D}^{\\prime})+\\mathbb{E}_{Z\\sim\\mathcal{D}}Q_{j}(\\mathcal{A}(Z),\\mathcal{D})\\right]\\\\ =\\frac{1}{|\\mathcal{P}|}\\sum_{j=1}^{d}\\sum_{\\mathcal{D}\\in\\mathcal{P}_{j}}\\frac{1}{m_{j}(\\mathcal{D})-1}\\sum_{\\substack{\\mathcal{D}^{\\prime}\\sim_{j}\\mathcal{D}\\\\ \\mathcal{D}^{\\prime}\\neq\\mathcal{D}}}\\int [Q_{j}(\\mathcal{A}(z),\\mathcal{D})p_{\\mathcal{D}}(z)+Q_{j}(\\mathcal{A}(z),\\mathcal{D}^{\\prime})p_{\\mathcal{D}^{\\prime}}(z)]d\\mu(z)\\\\ \\stackrel{(a)}{\\geq}\\frac{1}{|\\mathcal{P}|}\\sum_{j=1}^{d}\\sum_{\\mathcal{D}\\in\\mathcal{P}_{j}}\\frac{1}{m_{j}(\\mathcal{D})-1}\\sum_{\\substack{\\mathcal{D}^{\\prime}\\sim_{j}\\mathcal{D}\\\\ \\mathcal{D}^{\\prime}\\neq\\mathcal{D}}}\\int\\epsilon\\min(p_{\\mathcal{D}}(z),p_{\\mathcal{D}^{\\prime}}(z))d\\mu(z)\\\\ \\stackrel{(b)}{=}\\frac{1}{|\\mathcal{P}|}\\sum_{j=1}^{d}\\sum_{\\mathcal{D}\\in\\mathcal{P}_{j}}\\frac{1}{m_{j}(\\mathcal{D})-1}\\sum_{\\substack{\\mathcal{D}^{\\prime}\\sim_{j}\\mathcal{D}\\\\ \\mathcal{D}^{\\prime}\\neq\\mathcal{D}}}\\epsilon(1-\\|\\mathcal{D}-\\mathcal{D}^{\\prime}\\|_{\\mathrm{TV}}).\\\\ \\end{array}\n\\]\nIn the above derivation, the first inequality used \\( Q_{j}(\\cdot) \\geq 0 \\); (a) used the assumption of the lemma, and (b) used the definition of TV-norm (see Appendix B). By rearranging the last term and using the definition of \\( \\beta \\), we obtain the desired bound.", "context": [], "lean": "import Mathlib\n\nopen MeasureTheory Finset\n\nnamespace GraduateLevel\n\nnoncomputable def tvDist {Ω : Type*} [MeasurableSpace Ω]\n (μ ν : Measure Ω) [IsFiniteMeasure μ] [IsFiniteMeasure ν] : ℝ :=\n (((μ.toSignedMeasure - ν.toSignedMeasure).totalVariation Set.univ).toReal) / 2\n\nnoncomputable def blockSize {ι : Type*} [Fintype ι] (M : Setoid ι)\n [DecidableRel M.r] (i : ι) : ℕ :=\n (Finset.univ.filter (fun i' => M.r i i')).card\n\ntheorem ch12_lemma_12_27\n {Ω : Type*} [MeasurableSpace Ω]\n {R : Type*} [MeasurableSpace R] (μR : Measure R) [IsProbabilityMeasure μR]\n {ι : Type*} [Fintype ι] [Nonempty ι] [DecidableEq ι]\n {κ : Type*} [Fintype κ] [Nonempty κ]\n {Θ : Type*}\n (D : ι → Measure Ω) [hP : ∀ i, IsProbabilityMeasure (D i)]\n (Qcomp : κ → Θ → ι → ℝ)\n (hQnonneg : ∀ j θ i, 0 ≤ Qcomp j θ i)\n (M : κ → Setoid ι) [hM : ∀ j, DecidableRel (M j).r]\n (ε β : ℝ) (hε : 0 ≤ ε) (hβ : 0 ≤ β)\n (A : Ω → R → Θ)\n (q : Ω → ι → ℝ)\n (hQIntR : ∀ (j : κ) (ω : Ω) (i : ι), Integrable (fun r => Qcomp j (A ω r) i) μR)\n (hQIntΩ : ∀ (j : κ) (i : ι), Integrable (fun ω => ∫ r, Qcomp j (A ω r) i ∂μR) (D i))\n (hqdef : ∀ ω i, q ω i = ∫ r, (∑ j : κ, Qcomp j (A ω r) i) ∂μR)\n (hqInt : ∀ i, Integrable (fun ω => q ω i) (D i))\n (Pj : κ → Finset ι)\n (hPj : ∀ j, Pj j = Finset.univ.filter (fun i => 1 < blockSize (M j) i))\n (dP : ℕ) (hdP : dP = ∑ j : κ, (Pj j).card) (hdPpos : 0 < dP)\n (ha : ∀ (j : κ) (i i' : ι) (θ : Θ), (M j).r i i' → i' ≠ i →\n ε ≤ Qcomp j θ i' + Qcomp j θ i)\n (hb : (1 / (dP : ℝ)) *\n ∑ j : κ, ∑ i ∈ Pj j,\n (1 / ((blockSize (M j) i : ℝ) - 1)) *\n ∑ i' ∈ Finset.univ.filter (fun i' => (M j).r i i' ∧ i' ≠ i),\n tvDist (D i') (D i) ≤ β) :\n (ε * (dP : ℝ) / (2 * (Fintype.card ι : ℝ))) * (1 - β) ≤\n (1 / (Fintype.card ι : ℝ)) *\n ∑ i : ι, ∫ ω, q ω i ∂(D i) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Finset\n\nnamespace GraduateLevel\n\nnoncomputable def tvDist {Ω : Type*} [MeasurableSpace Ω]\n (μ ν : Measure Ω) [IsFiniteMeasure μ] [IsFiniteMeasure ν] : ℝ :=\n (((μ.toSignedMeasure - ν.toSignedMeasure).totalVariation Set.univ).toReal) / 2\n\nnoncomputable def blockSize {ι : Type*} [Fintype ι] (M : Setoid ι)\n [DecidableRel M.r] (i : ι) : ℕ :=\n (Finset.univ.filter (fun i' => M.r i i')).card\n\nprivate lemma tv_pair {Ω : Type*} [MeasurableSpace Ω] (μ ν : Measure Ω)\n [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n (f g : Ω → ℝ) (hf : Integrable f μ) (hg : Integrable g ν)\n (hfnn : ∀ ω, 0 ≤ f ω) (hgnn : ∀ ω, 0 ≤ g ω)\n (ε : ℝ) (hε : 0 ≤ ε) (hfg : ∀ ω, ε ≤ f ω + g ω) :\n ε * (1 - tvDist μ ν) ≤ (∫ ω, f ω ∂μ) + ∫ ω, g ω ∂ν := by\n classical\n set s : SignedMeasure Ω := μ.toSignedMeasure - ν.toSignedMeasure with hsdef\n obtain ⟨A, hA, hpos, hneg, hp, hn⟩ := s.toJordanDecomposition_spec\n have hsapp : ∀ E : Set Ω, MeasurableSet E → s E = (μ E).toReal - (ν E).toReal := by\n intro E hE\n rw [hsdef]\n rw [MeasureTheory.VectorMeasure.sub_apply,\n MeasureTheory.Measure.toSignedMeasure_apply_measurable hE,\n MeasureTheory.Measure.toSignedMeasure_apply_measurable hE]\n rfl\n -- tvDist equals s A\n have htv : tvDist μ ν = s A := by\n have huniv : s Set.univ = 0 := by\n rw [hsapp _ MeasurableSet.univ]; simp\n have hAc : s Aᶜ = - s A := by\n have h0 : s (A ∪ Aᶜ) = s A + s Aᶜ :=\n MeasureTheory.VectorMeasure.of_union disjoint_compl_right hA hA.compl\n rw [Set.union_compl_self] at h0\n rw [huniv] at h0\n linarith\n have hsA : 0 ≤ s A := by\n have := (MeasureTheory.VectorMeasure.restrict_le_restrict_iff (0 : SignedMeasure Ω) s\n hA).1 hpos hA (subset_refl _)\n simpa using this\n have hposu : (s.toJordanDecomposition.posPart) Set.univ = ENNReal.ofReal (s A) := by\n rw [hp, MeasureTheory.SignedMeasure.toMeasureOfZeroLE_apply _ hpos hA MeasurableSet.univ]\n simp only [Set.inter_univ]\n rw [ENNReal.ofReal]\n congr 1\n ext\n simp [max_eq_left hsA]\n have hnegu : (s.toJordanDecomposition.negPart) Set.univ = ENNReal.ofReal (s A) := by\n rw [hn, MeasureTheory.SignedMeasure.toMeasureOfLEZero_apply _ hneg hA.compl\n MeasurableSet.univ]\n simp only [Set.inter_univ]\n rw [ENNReal.ofReal]\n congr 1\n ext\n simp [hAc, max_eq_left hsA]\n show ((s.totalVariation Set.univ).toReal) / 2 = s A\n rw [MeasureTheory.SignedMeasure.totalVariation]\n simp only [MeasureTheory.Measure.coe_add, Pi.add_apply, hposu, hnegu]\n rw [← ENNReal.ofReal_add hsA hsA, ENNReal.toReal_ofReal (by linarith)]\n ring\n -- restriction inequalities\n have h1 : ν.restrict A ≤ μ.restrict A := by\n refine MeasureTheory.Measure.le_iff.2 fun E hE => ?_\n rw [Measure.restrict_apply hE, Measure.restrict_apply hE]\n have hEA : MeasurableSet (E ∩ A) := hE.inter hA\n have := (MeasureTheory.VectorMeasure.restrict_le_restrict_iff (0 : SignedMeasure Ω) s\n hA).1 hpos hEA Set.inter_subset_right\n rw [hsapp _ hEA] at this\n simp only [MeasureTheory.VectorMeasure.coe_zero, Pi.zero_apply] at this\n have h2 := ENNReal.toReal_le_toReal (measure_ne_top ν (E ∩ A)) (measure_ne_top μ (E ∩ A))\n exact h2.1 (by linarith)\n have h2 : μ.restrict Aᶜ ≤ ν.restrict Aᶜ := by\n refine MeasureTheory.Measure.le_iff.2 fun E hE => ?_\n rw [Measure.restrict_apply hE, Measure.restrict_apply hE]\n have hEA : MeasurableSet (E ∩ Aᶜ) := hE.inter hA.compl\n have := (MeasureTheory.VectorMeasure.restrict_le_restrict_iff s (0 : SignedMeasure Ω)\n hA.compl).1 hneg hEA Set.inter_subset_right\n rw [hsapp _ hEA] at this\n simp only [MeasureTheory.VectorMeasure.coe_zero, Pi.zero_apply] at this\n have h3 := ENNReal.toReal_le_toReal (measure_ne_top μ (E ∩ Aᶜ)) (measure_ne_top ν (E ∩ Aᶜ))\n exact h3.1 (by linarith)\n -- integrability on the pieces\n have hfνA : Integrable f (ν.restrict A) := (hf.restrict (s := A)).mono_measure h1\n have hgνA : Integrable g (ν.restrict A) := hg.restrict\n have hfμC : Integrable f (μ.restrict Aᶜ) := hf.restrict\n have hgμC : Integrable g (μ.restrict Aᶜ) := (hg.restrict (s := Aᶜ)).mono_measure h2\n have e1 : (∫ ω, f �� ∂μ) = (∫ ω in A, f ω ∂μ) + ∫ ω in Aᶜ, f ω ∂μ :=\n (integral_add_compl hA hf).symm\n have e2 : (∫ ω, g ω ∂ν) = (∫ ω in A, g ω ∂ν) + ∫ ω in Aᶜ, g ω ∂ν :=\n (integral_add_compl hA hg).symm\n have i1 : (∫ ω in A, f ω ∂ν) ≤ ∫ ω in A, f ω ∂μ :=\n integral_mono_measure h1 (Filter.Eventually.of_forall hfnn) hf.restrict\n have i2 : (∫ ω in Aᶜ, g ω ∂μ) ≤ ∫ ω in Aᶜ, g ω ∂ν :=\n integral_mono_measure h2 (Filter.Eventually.of_forall hgnn) hg.restrict\n have s1 : ε * (ν A).toReal ≤ (∫ ω in A, f ω ∂ν) + ∫ ω in A, g ω ∂ν := by\n rw [← integral_add hfνA hgνA]\n have := integral_mono (μ := ν.restrict A) (f := fun _ => ε) (g := fun ω => f ω + g ω)\n (integrable_const ε) (hfνA.add hgνA) (fun ω => hfg ω)\n calc ε * (ν A).toReal = ∫ _ in A, ε ∂ν := by\n rw [setIntegral_const, smul_eq_mul, measureReal_def]; ring\n _ ≤ _ := this\n have s2 : ε * (μ Aᶜ).toReal ≤ (∫ ω in Aᶜ, f ω ∂μ) + ∫ ω in Aᶜ, g ω ∂μ := by\n rw [← integral_add hfμC hgμC]\n have := integral_mono (μ := μ.restrict Aᶜ) (f := fun _ => ε) (g := fun ω => f ω + g ω)\n (integrable_const ε) (hfμC.add hgμC) (fun ω => hfg ω)\n calc ε * (μ Aᶜ).toReal = ∫ _ in Aᶜ, ε ∂μ := by\n rw [setIntegral_const, smul_eq_mul, measureReal_def]; ring\n _ ≤ _ := this\n have hmc : ∀ (m : Measure Ω), IsProbabilityMeasure m →\n (m A).toReal + (m Aᶜ).toReal = 1 := by\n intro m hm\n have h := measure_add_measure_compl (μ := m) hA\n have : ((m A + m Aᶜ : ENNReal)).toReal = ((1 : ENNReal)).toReal := by\n rw [h]; simp [hm.measure_univ]\n rwa [ENNReal.toReal_add (measure_ne_top m A) (measure_ne_top m Aᶜ), ENNReal.toReal_one] at this\n have hAeq : s A = (μ A).toReal - (ν A).toReal := hsapp A hA\n have hμc := hmc μ inferInstance\n have hνc := hmc ν inferInstance\n rw [htv, e1, e2]\n have : ε * (1 - s A) = ε * (ν A).toReal + ε * (μ Aᶜ).toReal := by\n rw [hAeq]; nlinarith [hνc, hμc]\n rw [this]\n linarith\n\nprivate lemma main_comb {ι : Type*} [Fintype ι] [DecidableEq ι] {κ : Type*} [Fintype κ]\n (M : κ → Setoid ι) [hM : ∀ j, DecidableRel (M j).r]\n (F : κ → ι → ℝ) (hFnn : ∀ j i, 0 ≤ F j i)\n (T : ι → ι → ℝ)\n (ε β : ℝ) (hε : 0 ≤ ε)\n (Pj : κ → Finset ι)\n (hPj : ∀ j, Pj j = Finset.univ.filter (fun i => 1 < blockSize (M j) i))\n (dP : ℕ) (hdP : dP = ∑ j : κ, (Pj j).card) (hdPpos : 0 < dP)\n (hpair : ∀ (j : κ) (i i' : ι), (M j).r i i' → i' ≠ i →\n ε * (1 - T i' i) ≤ F j i' + F j i)\n (hb : (1 / (dP : ℝ)) *\n ∑ j : κ, ∑ i ∈ Pj j,\n (1 / ((blockSize (M j) i : ℝ) - 1)) *\n ∑ i' ∈ Finset.univ.filter (fun i' => (M j).r i i' ∧ i' ≠ i),\n T i' i ≤ β) :\n ε * (dP : ℝ) * (1 - β) ≤ 2 * ∑ i : ι, ∑ j : κ, F j i := by\n classical\n set N : κ → ι → Finset ι :=\n fun j i => Finset.univ.filter (fun i' => (M j).r i i' ∧ i' ≠ i) with hN\n set c : κ → ι → ℝ := fun j i => 1 / ((blockSize (M j) i : ℝ) - 1) with hc\n have hbs : ∀ (j : κ) (i i' : ι), (M j).r i i' →\n blockSize (M j) i = blockSize (M j) i' := by\n intro j i i' hr\n unfold blockSize\n congr 1\n ext x\n simp only [Finset.mem_filter, Finset.mem_univ, true_and]\n constructor\n · intro h; exact (M j).trans ((M j).symm hr) h\n · intro h; exact (M j).trans hr h\n have hbs1 : ∀ (j : κ) (i : ι), 1 ≤ blockSize (M j) i := by\n intro j i\n have : i ∈ Finset.univ.filter (fun i' => (M j).r i i') := by\n simp only [Finset.mem_filter, Finset.mem_univ, true_and]; exact (M j).refl i\n exact Finset.card_pos.2 ⟨i, this⟩\n have hcard : ∀ (j : κ) (i : ι), ((N j i).card : ℝ) = (blockSize (M j) i : ℝ) - 1 := by\n intro j i\n have hset : N j i = (Finset.univ.filter (fun i' => (M j).r i i')).erase i := by\n ext x\n simp only [hN, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_erase]\n tauto\n have hmem : i ∈ Finset.univ.filter (fun i' => (M j).r i i') := by\n simp only [Finset.mem_filter, Finset.mem_univ, true_and]; exact (M j).refl i\n rw [hset, Finset.card_erase_of_mem hmem]\n have : blockSize (M j) i = (Finset.univ.filter (fun i' => (M j).r i i')).card := rfl\n rw [← this]\n have := hbs1 j i\n push_cast [Nat.cast_sub this]\n ring\n have hmemPj : ∀ (j : κ) (i : ι), i ∈ Pj j ↔ 1 < blockSize (M j) i := by\n intro j i; rw [hPj]; simp\n have hcpos : ∀ (j : κ) (i : ι), i ∈ Pj j → 0 < c j i := by\n intro j i hi\n have := (hmemPj j i).1 hi\n have h2 : (1 : ℝ) < (blockSize (M j) i : ℝ) := by exact_mod_cast this\n simp only [hc]\n apply div_pos one_pos\n linarith\n have hccard : ∀ (j : κ) (i : ι), i ∈ Pj j → c j i * ((N j i).card : ℝ) = 1 := by\n intro j i hi\n have h1 := (hmemPj j i).1 hi\n have h2 : (1 : ℝ) < (blockSize (M j) i : ℝ) := by exact_mod_cast h1\n rw [hcard]\n simp only [hc]\n exact one_div_mul_cancel (by linarith)\n have key : ∀ j : κ,\n ε * ((Pj j).card : ℝ) - ε * (∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, T i' i)\n ≤ 2 * ∑ i ∈ Pj j, F j i := by\n intro j\n have hswap : (∑ i ∈ Pj j, ∑ i' ∈ N j i, c j i * F j i') = ∑ i ∈ Pj j, F j i := by\n have hcond : ∀ (i i' : ι), (i ∈ Pj j ∧ i' ∈ N j i) ↔ (i ∈ N j i' ∧ i' ∈ Pj j) := by\n intro i i'\n simp only [hN, Finset.mem_filter, Finset.mem_univ, true_and, hmemPj]\n constructor\n · rintro ⟨h1, h2, h3⟩\n refine ⟨⟨(M j).symm h2, fun hh => h3 hh.symm⟩, ?_⟩\n rwa [← hbs j i i' h2]\n · rintro ⟨⟨h2, h3⟩, h1⟩\n refine ⟨?_, (M j).symm h2, fun hh => h3 hh.symm⟩\n rwa [← hbs j i' i h2]\n rw [Finset.sum_comm' hcond]\n refine Finset.sum_congr rfl ?_\n intro i' hi'\n have hin : ∀ i ∈ N j i', c j i * F j i' = c j i' * F j i' := by\n intro i hi\n have hr : (M j).r i' i := by\n have := (Finset.mem_filter.1 hi).2\n exact this.1\n simp only [hc]\n rw [hbs j i' i hr]\n rw [Finset.sum_congr rfl hin, ← Finset.sum_mul, Finset.sum_const, nsmul_eq_mul,\n mul_comm ((N j i').card : ℝ) (c j i'), hccard j i' hi', one_mul]\n have hsplit : (∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, (F j i' + F j i))\n = 2 * ∑ i ∈ Pj j, F j i := by\n have hstep : ∀ i ∈ Pj j, c j i * (∑ i' ∈ N j i, (F j i' + F j i))\n = (∑ i' ∈ N j i, c j i * F j i') + F j i := by\n intro i hi\n rw [Finset.sum_add_distrib, Finset.sum_const, nsmul_eq_mul, mul_add, Finset.mul_sum,\n ← mul_assoc, mul_comm (c j i) ((N j i).card : ℝ), mul_comm ((N j i).card : ℝ) (c j i),\n hccard j i hi, one_mul]\n rw [Finset.sum_congr rfl hstep, Finset.sum_add_distrib, hswap]\n ring\n have hmono : (∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, (ε * (1 - T i' i)))\n ≤ ∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, (F j i' + F j i) := by\n refine Finset.sum_le_sum ?_\n intro i hi\n refine mul_le_mul_of_nonneg_left ?_ (le_of_lt (hcpos j i hi))\n refine Finset.sum_le_sum ?_\n intro i' hi'\n have h2 := (Finset.mem_filter.1 hi').2\n exact hpair j i i' h2.1 h2.2\n have hlhs : (∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, (ε * (1 - T i' i)))\n = ε * ((Pj j).card : ℝ) - ε * (∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, T i' i) := by\n have hstep : ∀ i ∈ Pj j, c j i * (∑ i' ∈ N j i, (ε * (1 - T i' i)))\n = ε - ε * (c j i * ∑ i' ∈ N j i, T i' i) := by\n intro i hi\n have heq : ∀ i' : ι, ε * (1 - T i' i) = ε - ε * T i' i := fun i' => by ring\n have : (∑ i' ∈ N j i, (ε * (1 - T i' i)))\n = ε * ((N j i).card : ℝ) - ε * ∑ i' ∈ N j i, T i' i := by\n simp only [heq]\n rw [Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul, ← Finset.mul_sum]\n ring\n rw [this, mul_sub, ← mul_assoc, mul_comm (c j i) ε, mul_assoc ε (c j i),\n hccard j i hi, mul_one]\n ring\n rw [Finset.sum_congr rfl hstep, Finset.sum_sub_distrib, Finset.sum_const, nsmul_eq_mul,\n ← Finset.mul_sum]\n ring\n rw [hlhs] at hmono\n rw [hsplit] at hmono\n exact hmono\n have hdPR : (0 : ℝ) < (dP : ℝ) := by exact_mod_cast hdPpos\n have hb2 : (∑ j : κ, ∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, T i' i) ≤ β * (dP : ℝ) := by\n simp only [hc, hN]\n have := hb\n rw [div_mul_eq_mul_div, one_mul, div_le_iff₀ hdPR] at this\n linarith [this]\n have hsum : ε * (dP : ℝ) - ε * (∑ j : κ, ∑ i ∈ Pj j, c j i * ∑ i' ∈ N j i, T i' i)\n ≤ 2 * ∑ j : κ, ∑ i ∈ Pj j, F j i := by\n have := Finset.sum_le_sum (fun j (_ : j ∈ (Finset.univ : Finset κ)) => key j)\n rw [Finset.sum_sub_distrib, ← Finset.mul_sum, ← Finset.mul_sum, ← Finset.mul_sum] at this\n have hdc : (∑ j : κ, ((Pj j).card : ℝ)) = (dP : ℝ) := by\n rw [hdP]; push_cast; ring\n rw [hdc] at this\n exact this\n have hle2 : (∑ j : κ, ∑ i ∈ Pj j, F j i) ≤ ∑ i : ι, ∑ j : κ, F j i := by\n rw [Finset.sum_comm]\n refine Finset.sum_le_sum ?_\n intro j _\n exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _)\n (fun i _ _ => hFnn j i)\n nlinarith [hsum, hle2, hb2, hε, hdPR]\n\ntheorem ch12_lemma_12_27\n {Ω : Type*} [MeasurableSpace Ω]\n {R : Type*} [MeasurableSpace R] (μR : Measure R) [IsProbabilityMeasure μR]\n {ι : Type*} [Fintype ι] [Nonempty ι] [DecidableEq ι]\n {κ : Type*} [Fintype κ] [Nonempty κ]\n {Θ : Type*}\n (D : ι → Measure Ω) [hP : ∀ i, IsProbabilityMeasure (D i)]\n (Qcomp : κ → Θ → ι → ℝ)\n (hQnonneg : ∀ j θ i, 0 ≤ Qcomp j θ i)\n (M : κ → Setoid ι) [hM : ∀ j, DecidableRel (M j).r]\n (ε β : ℝ) (hε : 0 ≤ ε) (hβ : 0 ≤ β)\n (A : Ω → R → Θ)\n (q : Ω → ι → ℝ)\n (hQIntR : ∀ (j : κ) (ω : Ω) (i : ι), Integrable (fun r => Qcomp j (A ω r) i) μR)\n (hQIntΩ : ∀ (j : κ) (i : ι), Integrable (fun ω => ∫ r, Qcomp j (A ω r) i ∂μR) (D i))\n (hqdef : ∀ ω i, q ω i = ∫ r, (∑ j : κ, Qcomp j (A ω r) i) ∂μR)\n (hqInt : ∀ i, Integrable (fun ω => q ω i) (D i))\n (Pj : κ → Finset ι)\n (hPj : ∀ j, Pj j = Finset.univ.filter (fun i => 1 < blockSize (M j) i))\n (dP : ℕ) (hdP : dP = ∑ j : κ, (Pj j).card) (hdPpos : 0 < dP)\n (ha : ∀ (j : κ) (i i' : ι) (θ : Θ), (M j).r i i' → i' ≠ i →\n ε ≤ Qcomp j θ i' + Qcomp j θ i)\n (hb : (1 / (dP : ℝ)) *\n ∑ j : κ, ∑ i ∈ Pj j,\n (1 / ((blockSize (M j) i : ℝ) - 1)) *\n ∑ i' ∈ Finset.univ.filter (fun i' => (M j).r i i' ∧ i' ≠ i),\n tvDist (D i') (D i) ≤ β) :\n (ε * (dP : ℝ) / (2 * (Fintype.card ι : ℝ))) * (1 - β) ≤\n (1 / (Fintype.card ι : ℝ)) *\n ∑ i : ι, ∫ ω, q ω i ∂(D i) := by\n classical\n set F : κ → ι → ℝ := fun j i => ∫ ω, (∫ r, Qcomp j (A ω r) i ∂μR) ∂(D i) with hF\n have hFnn : ∀ j i, 0 ≤ F j i := by\n intro j i\n exact integral_nonneg (fun ω => integral_nonneg (fun r => hQnonneg _ _ _))\n have hq : ∀ i, (∫ ω, q ω i ∂(D i)) = ∑ j : κ, F j i := by\n intro i\n have hpt : ∀ ω, q ω i = ∑ j : κ, ∫ r, Qcomp j (A ω r) i ∂μR := by\n intro ω\n rw [hqdef]\n exact integral_finset_sum _ (fun j _ => hQIntR j ω i)\n rw [integral_congr_ae (Filter.Eventually.of_forall hpt)]\n exact integral_finset_sum _ (fun j _ => hQIntΩ j i)\n have hpair : ∀ (j : κ) (i i' : ι), (M j).r i i' → i' ≠ i →\n ε * (1 - tvDist (D i') (D i)) ≤ F j i' + F j i := by\n intro j i i' hr hne\n refine tv_pair (D i') (D i) _ _ (hQIntΩ j i') (hQIntΩ j i)\n (fun ω => integral_nonneg (fun r => hQnonneg _ _ _))\n (fun ω => integral_nonneg (fun r => hQnonneg _ _ _)) ε hε ?_\n intro ω\n have h1 : (∫ r, Qcomp j (A ω r) i' ∂μR) + ∫ r, Qcomp j (A ω r) i ∂μR\n = ∫ r, (Qcomp j (A ω r) i' + Qcomp j (A ω r) i) ∂μR := by\n rw [integral_add (hQIntR j ω i') (hQIntR j ω i)]\n rw [h1]\n have h2 : (∫ _ : R, ε ∂μR) ≤ ∫ r, (Qcomp j (A ω r) i' + Qcomp j (A ω r) i) ∂μR := by\n refine integral_mono (integrable_const ε) ((hQIntR j ω i').add (hQIntR j ω i)) ?_\n intro r\n exact ha j i i' (A ω r) hr hne\n simpa using h2\n have hmain := main_comb M F hFnn (fun i' i => tvDist (D i') (D i)) ε β hε Pj hPj dP hdP\n hdPpos hpair hb\n have hqsum : (∑ i : ι, ∫ ω, q ω i ∂(D i)) = ∑ i : ι, ∑ j : κ, F j i :=\n Finset.sum_congr rfl (fun i _ => hq i)\n have hn : (0 : ℝ) < (Fintype.card ι : ℝ) := by\n have : 0 < Fintype.card ι := Fintype.card_pos\n exact_mod_cast this\n rw [hqsum]\n rw [div_mul_eq_mul_div, div_le_iff₀ (by positivity)]\n have hcalc : (1 / (Fintype.card ι : ℝ)) * (∑ i : ι, ∑ j : κ, F j i) *\n (2 * (Fintype.card ι : ℝ)) = 2 * ∑ i : ι, ∑ j : κ, F j i := by\n field_simp\n rw [hcalc]\n exact hmain\n\nend GraduateLevel\n"} +{"id": "ch12_theorem_12_11", "source": "Graduate-level", "targets": [{"label": "ch12_theorem_12_11", "decls": ["ch12_theorem_12_11"], "statement": "Consider a finite family of distributions \\(\\mathcal{P} = \\{\\mathcal{D}_1, \\ldots, \\mathcal{D}_N\\}\\). Given a loss function \\(Q\\) on \\(\\Theta \\times \\mathcal{P}\\), let\n\\[\nm=\\sup_{\\theta\\in\\Theta}\\left|\\left\\{k:Q(\\theta,\\mathcal{D}_{k})<\\epsilon\\right\\}\\right|.\n\\]\nAssume that \\(j\\) is a random variable that is uniformly distributed in \\(\\{1, \\dots, N\\}\\), and conditioned on \\(j\\), \\(Z \\sim \\mathcal{D}_j\\). Given any (possibly random) estimator \\(\\mathcal{A}(Z)\\). Then\n\\[\n\\frac{1}{N}\\sum_{j=1}^{N}\\operatorname*{Pr}_{Z\\sim\\mathcal{D}_{j}}(Q(\\mathcal{A}(Z),\\mathcal{D}_{j})<\\epsilon)\\leq\\max\\left(\\frac{m}{N},\\frac{I(j,Z)+\\ln 2}{\\ln(N/m)}\\right),\n\\]\nwhere \\( I(j,Z) \\) is the mutual information of \\( j \\) and \\( Z \\). The probability includes possible randomization in \\( \\mathcal{A} \\).", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Statistical Estimation & Minimax Theory"}], "nl_proof": "Let \\( p_j \\) be the density function of \\( Z \\) for \\( \\mathcal{D}_j \\). Then the joint distribution of \\( (j,Z) \\) is given by\n\\[\np(j,Z)=\\frac{1}{N}p_{j}(Z).\n\\]\nWe can introduce a random variable \\( Z' \\) with the same marginal distribution as \\( Z \\), but is independent of \\( j \\):\n\\[\np(Z^{\\prime})=\\frac{1}{N}\\sum_{j=1}^{N}p_{j}(Z^{\\prime}).\n\\]\nNow, consider an arbitrary and possibly random estimator \\(\\hat{\\theta} = \\mathcal{A}(Z)\\). Let \\(\\hat{\\theta}' = \\mathcal{A}(Z')\\). By the data processing inequality for KL-divergence (see Theorem B.4), with input \\((j,Z)\\) and binary output \\(h(j,Z) = \\mathbb{1}(Q(\\hat{\\theta},\\mathcal{D}_j) < \\epsilon)\\), where \\(\\mathbb{1}(\\cdot)\\) is the indicator function. We obtain\n\\[\n\\operatorname{KL}\\left(\\mathbb{1}\\left(Q(\\hat{\\theta},\\mathcal{D}_{j})<\\epsilon\\right)| |\\mathbb{1}\\left(Q\\left(\\hat{\\theta}^{\\prime},\\mathcal{D}_{j}\\right)<\\epsilon\\right)\\right)\\leq\\operatorname{KL}\\left((j,Z)| |(j,Z^{\\prime})\\right)=I(j,Z).\n\\]\nNow let \\( q = \\operatorname*{Pr}(Q(\\hat{\\theta},\\mathcal{D}_j) < \\epsilon) \\) and \\( q' = \\operatorname*{Pr}(Q(\\hat{\\theta}',\\mathcal{D}_j) < \\epsilon) \\), then the above inequality can be rewritten as:\n\\[\n\\mathrm{KL}(q| |q^{\\prime})=q\\ln\\frac{q}{q^{\\prime}}+(1-q)\\ln\\frac{1-q}{1-q^{\\prime}}\\le I(j,Z).\n\\]\nSince \\(\\hat{\\theta}^{\\prime}\\) is independent of \\(j\\), and\n\\[\n|\\{j:Q(\\hat{\\theta}^{\\prime},\\mathcal{D}_{j})<\\epsilon\\}|\\leq m\n\\]\nfor each \\(\\hat{\\theta}^{\\prime}\\), we obtain\n\\[\nq^{\\prime}\\leq m/N.\n\\]\nIf \\( q \\leq m / N \\), we have proved the desired inequality. Otherwise, since \\( \\mathrm{KL}(q||q') \\) as a function of \\( q' \\) is decreasing in \\( [0, q] \\), we have\n\\[\nq\\ln{\\frac{q}{m/N}}+(1-q)\\ln{\\frac{1-q}{1-m/N}}\\le I(j,Z).\n\\]\nSince \\(q\\ln q + (1 - q)\\ln (1 - q)\\geq -\\ln 2\\) , we obtain\n\\[\n-\\ln 2+q\\ln{\\frac{N}{m}}+(1-q)\\ln{\\frac{N}{N-m}}\\leq I(j,Z).\n\\]\nThis implies that\n\\[\nq\\leq\\frac{I(j,Z)+\\ln 2}{\\ln(N/m)}.\n\\]\nWe thus obtain the desired bound.", "context": [{"id": "ch12:definition:12_9", "name": "definition 12.9", "statement": "Consider a distribution family \\(\\mathcal{P}\\) on sample space \\(\\mathcal{Z}\\), a parameter space \\(\\Theta\\). A learning algorithm \\(\\mathcal{A}:\\mathcal{Z}^n\\to \\Theta\\), a loss function \\(Q:\\Theta \\times \\mathcal{P}\\rightarrow \\mathbb{R}\\). Then the worst case expected risk of a learning algorithm (i.e., a statistical estimator) \\(\\mathcal{A}\\) with respect to \\(\\mathcal{P}\\) is given by\n\\[\nr_{n}(\\mathcal{A},\\mathcal{P},Q)=\\sup_{\\mathcal{D}\\in\\mathcal{P}}\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}\\mathbb{E}_{\\mathcal{A}}Q(\\mathcal{A}(\\mathcal{S}_{n}),\\mathcal{D}),\n\\]\nwhere \\(\\mathbb{E}_{\\mathcal{A}}\\) is the expectation over any internal randomization of \\(\\mathcal{A}\\). Moreover, the minimax risk is defined as:\n\\[\nr_{n}(\\mathcal{P},Q)=\\inf_{\\mathcal{A}}r_{n}(\\mathcal{A},\\mathcal{P},Q).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\nnoncomputable def lowLossCount {N : ℕ} {Θ : Type*} (Q : Θ → Fin N → ℝ) (ε : ℝ)\n (θ : Θ) : ℕ :=\n (Finset.univ.filter (fun k : Fin N => Q θ k < ε)).card\n\nnoncomputable def jointLaw {N : ℕ} [NeZero N] {Z : Type*} [MeasurableSpace Z]\n (D : Fin N → Measure Z) : Measure (Fin N × Z) :=\n Measure.bind ((PMF.uniformOfFintype (Fin N)).toMeasure)\n (fun j => (D j).map (fun z => (j, z)))\n\nnoncomputable def prodMarginals {N : ℕ} [NeZero N] {Z : Type*} [MeasurableSpace Z]\n (D : Fin N → Measure Z) : Measure (Fin N × Z) :=\n ((jointLaw D).map Prod.fst).prod ((jointLaw D).map Prod.snd)\n\ntheorem ch12_theorem_12_11\n {N : ℕ} [NeZero N]\n {Z : Type*} [MeasurableSpace Z]\n {Θ : Type*} [MeasurableSpace Θ]\n (D : Fin N → Measure Z) (hD : ∀ j, IsProbabilityMeasure (D j))\n (Q : Θ → Fin N → ℝ)\n (ε : ℝ)\n (m : ℕ)\n (hm_def : m = ⨆ θ : Θ, lowLossCount Q ε θ)\n (A : Z → Measure Θ) (hA : ∀ z, IsProbabilityMeasure (A z))\n (hAmeas : Measurable A)\n (hQmeas : ∀ j : Fin N, MeasurableSet {θ : Θ | Q θ j < ε})\n (I : ℝ)\n (hI : I = (InformationTheory.klDiv (jointLaw D) (prodMarginals D)).toReal)\n (hI_fin : InformationTheory.klDiv (jointLaw D) (prodMarginals D) ≠ ⊤) :\n (1 / (N : ℝ)) * ∑ j : Fin N, ((D j).bind A {θ : Θ | Q θ j < ε}).toReal\n ≤ max ((m : ℝ) / (N : ℝ)) ((I + Real.log 2) / Real.log ((N : ℝ) / (m : ℝ))) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\nnoncomputable def lowLossCount {N : ℕ} {Θ : Type*} (Q : Θ → Fin N → ℝ) (ε : ℝ)\n (θ : Θ) : ℕ :=\n (Finset.univ.filter (fun k : Fin N => Q θ k < ε)).card\n\nnoncomputable def jointLaw {N : ℕ} [NeZero N] {Z : Type*} [MeasurableSpace Z]\n (D : Fin N → Measure Z) : Measure (Fin N × Z) :=\n Measure.bind ((PMF.uniformOfFintype (Fin N)).toMeasure)\n (fun j => (D j).map (fun z => (j, z)))\n\nnoncomputable def prodMarginals {N : ℕ} [NeZero N] {Z : Type*} [MeasurableSpace Z]\n (D : Fin N → Measure Z) : Measure (Fin N × Z) :=\n ((jointLaw D).map Prod.fst).prod ((jointLaw D).map Prod.snd)\n\nopen InformationTheory\n\nprivate lemma fenchel {x : ℝ} (hx : 0 ≤ x) (y : ℝ) :\n x * y - Real.exp (y - 1) ≤ x * Real.log x := by\n rcases hx.eq_or_lt with h | h\n · rw [← h]\n simp only [zero_mul, zero_sub, neg_nonpos]\n positivity\n · have h1 : (y - 1 - Real.log x) + 1 ≤ Real.exp (y - 1 - Real.log x) :=\n Real.add_one_le_exp _\n have h2 : x * ((y - 1 - Real.log x) + 1) ≤ x * Real.exp (y - 1 - Real.log x) :=\n mul_le_mul_of_nonneg_left h1 hx\n have h3 : x * Real.exp (y - 1 - Real.log x) = Real.exp (y - 1) := by\n rw [Real.exp_sub, Real.exp_log h]\n field_simp\n have h4 : x * ((y - 1 - Real.log x) + 1) = x * y - x * Real.log x := by ring\n rw [h3, h4] at h2\n linarith\n\nprivate lemma dv_bound {X : Type*} [MeasurableSpace X] {P Qm : Measure X}\n [IsProbabilityMeasure P] [IsProbabilityMeasure Qm]\n (hfin : klDiv P Qm ≠ ⊤) {f : X → ℝ} (hf : Measurable f) {C : ℝ}\n (hbdd : ∀ x, ‖f x‖ ≤ C) :\n ∫ x, f x ∂P ≤ (klDiv P Qm).toReal + ∫ x, Real.exp (f x - 1) ∂Qm := by\n obtain ⟨hac, hint⟩ := klDiv_ne_top_iff.mp hfin\n have hri : Integrable (fun x => (P.rnDeriv Qm x).toReal) Qm :=\n Measure.integrable_toReal_rnDeriv\n have hklint : Integrable (fun x => klFun (P.rnDeriv Qm x).toReal) Qm :=\n (integrable_klFun_rnDeriv_iff hac).mpr hint\n have hem : Measurable fun x => Real.exp (f x - 1) :=\n Real.measurable_exp.comp (hf.sub measurable_const)\n have hexpi : Integrable (fun x => Real.exp (f x - 1)) Qm := by\n refine Integrable.mono' (integrable_const (Real.exp (C - 1)))\n hem.aestronglyMeasurable (Filter.Eventually.of_forall fun x => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg (Real.exp_nonneg _)]\n refine Real.exp_le_exp.mpr ?_\n have := hbdd x\n rw [Real.norm_eq_abs] at this\n have := (abs_le.mp this).2\n linarith\n have hrfi : Integrable (fun x => (P.rnDeriv Qm x).toReal * f x) Qm :=\n (hri.bdd_mul' hf.aestronglyMeasurable (Filter.Eventually.of_forall hbdd)).congr\n (Filter.Eventually.of_forall fun x => mul_comm _ _)\n have i1 : Integrable (fun x => (P.rnDeriv Qm x).toReal * f x - Real.exp (f x - 1)) Qm :=\n hrfi.sub hexpi\n have i2 : Integrable\n (fun x => (P.rnDeriv Qm x).toReal * f x - Real.exp (f x - 1) + 1) Qm :=\n i1.add (integrable_const 1)\n have i3 : Integrable\n (fun x => (P.rnDeriv Qm x).toReal * f x - Real.exp (f x - 1) + 1\n - (P.rnDeriv Qm x).toReal) Qm := i2.sub hri\n have key : ∫ x, ((P.rnDeriv Qm x).toReal * f x - Real.exp (f x - 1) + 1\n - (P.rnDeriv Qm x).toReal) ∂Qm ≤ ∫ x, klFun (P.rnDeriv Qm x).toReal ∂Qm := by\n refine integral_mono i3 hklint ?_\n intro x\n have h := fenchel (x := (P.rnDeriv Qm x).toReal) ENNReal.toReal_nonneg (f x)\n simp only [klFun]\n linarith\n rw [integral_sub i2 hri, integral_add i1 (integrable_const 1),\n integral_sub hrfi hexpi] at key\n have e1 : ∫ x, (P.rnDeriv Qm x).toReal * f x ∂Qm = ∫ x, f x ∂P := by\n simpa [smul_eq_mul] using integral_rnDeriv_smul (f := f) hac\n have e2 : ∫ x, (P.rnDeriv Qm x).toReal ∂Qm = 1 := by\n have h := integral_rnDeriv_smul (f := fun _ : X => (1:ℝ)) hac\n simpa using h\n rw [e1, e2, ← toReal_klDiv_eq_integral_klFun hac] at key\n simp only [integral_const, measureReal_univ_eq_one, smul_eq_mul, mul_one] at key\n linarith\n\ntheorem ch12_theorem_12_11\n {N : ℕ} [NeZero N]\n {Z : Type*} [MeasurableSpace Z]\n {Θ : Type*} [MeasurableSpace Θ]\n (D : Fin N → Measure Z) (hD : ∀ j, IsProbabilityMeasure (D j))\n (Q : Θ → Fin N → ℝ)\n (ε : ℝ)\n (m : ℕ)\n (hm_def : m = ⨆ θ : Θ, lowLossCount Q ε θ)\n (A : Z → Measure Θ) (hA : ∀ z, IsProbabilityMeasure (A z))\n (hAmeas : Measurable A)\n (hQmeas : ∀ j : Fin N, MeasurableSet {θ : Θ | Q θ j < ε})\n (I : ℝ)\n (hI : I = (InformationTheory.klDiv (jointLaw D) (prodMarginals D)).toReal)\n (hI_fin : InformationTheory.klDiv (jointLaw D) (prodMarginals D) ≠ ⊤) :\n (1 / (N : ℝ)) * ∑ j : Fin N, ((D j).bind A {θ : Θ | Q θ j < ε}).toReal\n ≤ max ((m : ℝ) / (N : ℝ)) ((I + Real.log 2) / Real.log ((N : ℝ) / (m : ℝ))) := by\n classical\n haveI : ∀ j, IsProbabilityMeasure (D j) := hD\n haveI : ∀ z, IsProbabilityMeasure (A z) := hA\n have hN0 : 0 < N := Nat.pos_of_ne_zero (NeZero.ne N)\n have hNR : (0:ℝ) < N := by exact_mod_cast hN0\n set S : Fin N → Set Θ := fun j => {θ : Θ | Q θ j < ε} with hS\n set G : Fin N × Z → ℝ≥0∞ := fun x => (A x.2) (S x.1) with hG\n have hGm : Measurable G := by\n refine measurable_from_prod_countable_right (fun j => ?_)\n exact (Measure.measurable_coe (hQmeas j)).comp hAmeas\n have hGle : ∀ x, G x ≤ 1 := fun x => by\n simpa using prob_le_one (μ := A x.2) (s := S x.1)\n -- lintegral against the joint law\n have hlj : ∀ (F : Fin N × Z → ℝ≥0∞), Measurable F →\n ∫⁻ x, F x ∂(jointLaw D) = ∑ j : Fin N, (N : ℝ≥0∞)⁻¹ * ∫⁻ z, F (j, z) ∂(D j) := by\n intro F hF\n rw [jointLaw, Measure.lintegral_bind (Measurable.of_discrete).aemeasurable hF.aemeasurable,\n lintegral_fintype]\n refine Finset.sum_congr rfl fun j _ => ?_\n rw [PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton j),\n PMF.uniformOfFintype_apply, lintegral_map hF (measurable_prodMk_left)]\n simp [mul_comm]\n haveI hPprob : IsProbabilityMeasure (jointLaw D) := by\n constructor\n have h := hlj (fun _ => 1) measurable_const\n simp only [lintegral_one, measure_univ, mul_one, Finset.sum_const, Finset.card_univ,\n Fintype.card_fin, nsmul_eq_mul] at h\n rw [h]\n exact ENNReal.mul_inv_cancel (by exact_mod_cast hN0.ne') (by simp)\n haveI : IsProbabilityMeasure ((jointLaw D).map Prod.fst) :=\n Measure.isProbabilityMeasure_map measurable_fst.aemeasurable\n haveI : IsProbabilityMeasure ((jointLaw D).map Prod.snd) :=\n Measure.isProbabilityMeasure_map measurable_snd.aemeasurable\n haveI hQprob : IsProbabilityMeasure (prodMarginals D) := by\n rw [prodMarginals]; infer_instance\n -- q\n set q : ℝ := (∫⁻ x, G x ∂(jointLaw D)).toReal with hq\n have hle1 : ∫⁻ x, G x ∂(jointLaw D) ≤ 1 := by\n calc ∫⁻ x, G x ∂(jointLaw D) ≤ ∫⁻ _, (1:ℝ≥0∞) ∂(jointLaw D) := lintegral_mono hGle\n _ = 1 := by simp\n have hGint_ne : ∫⁻ x, G x ∂(jointLaw D) ≠ ⊤ := ne_top_of_le_ne_top ENNReal.one_ne_top hle1\n have hq_le_one : q ≤ 1 := by\n have h2 := (ENNReal.toReal_le_toReal hGint_ne ENNReal.one_ne_top).mpr hle1\n simpa [hq] using h2\n have hq_nonneg : 0 ≤ q := ENNReal.toReal_nonneg\n -- LHS equals q\n have hLHS : (1 / (N : ℝ)) * ∑ j : Fin N, ((D j).bind A {θ : Θ | Q θ j < ε}).toReal = q := by\n have hbind : ∀ j : Fin N, ((D j).bind A) (S j) = ∫⁻ z, G (j, z) ∂(D j) := by\n intro j\n rw [Measure.bind_apply (hQmeas j) hAmeas.aemeasurable]\n have h1 : ∫⁻ x, G x ∂(jointLaw D) = ∑ j : Fin N, (N : ℝ≥0∞)⁻¹ * ((D j).bind A) (S j) := by\n rw [hlj G hGm]\n exact Finset.sum_congr rfl fun j _ => by rw [hbind j]\n have hbind_le : ∀ j : Fin N, ((D j).bind A) (S j) ≤ 1 := by\n intro j\n rw [hbind j]\n calc ∫⁻ z, G (j, z) ∂(D j) ≤ ∫⁻ _ : Z, (1:ℝ≥0∞) ∂(D j) :=\n lintegral_mono (fun z => hGle (j, z))\n _ = 1 := by simp\n rw [hq, h1, ENNReal.toReal_sum (fun j _ =>\n ENNReal.mul_ne_top (ENNReal.inv_ne_top.mpr (by exact_mod_cast hN0.ne'))\n (ne_top_of_le_ne_top ENNReal.one_ne_top (hbind_le j)))]\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl fun j _ => ?_\n rw [ENNReal.toReal_mul, ENNReal.toReal_inv, ENNReal.toReal_natCast]\n ring\n rw [hLHS]\n -- q'\n set q' : ℝ := (∫⁻ x, G x ∂(prodMarginals D)).toReal with hq'\n have hle1' : ∫⁻ x, G x ∂(prodMarginals D) ≤ 1 := by\n calc ∫⁻ x, G x ∂(prodMarginals D) ≤ ∫⁻ _, (1:ℝ≥0∞) ∂(prodMarginals D) :=\n lintegral_mono hGle\n _ = 1 := by simp\n have hGint'_ne : ∫⁻ x, G x ∂(prodMarginals D) ≠ ⊤ :=\n ne_top_of_le_ne_top ENNReal.one_ne_top hle1'\n -- bound on m\n have hbdd_sup : BddAbove (Set.range (fun θ : Θ => lowLossCount Q ε θ)) := by\n refine ⟨N, ?_⟩\n rintro _ ⟨θ, rfl⟩\n simp only [lowLossCount]\n calc (Finset.univ.filter (fun k : Fin N => Q θ k < ε)).card\n ≤ (Finset.univ : Finset (Fin N)).card := Finset.card_filter_le _ _\n _ = N := by simp\n have hm_le : ∀ θ : Θ, lowLossCount Q ε θ ≤ m := by\n intro θ; rw [hm_def]; exact le_ciSup hbdd_sup θ\n have hsum : ∀ z : Z, ∑ j : Fin N, (A z) (S j) ≤ (m : ℝ≥0∞) := by\n intro z\n have hrw : ∀ j : Fin N, (A z) (S j) = ∫⁻ θ, (S j).indicator (fun _ => (1:ℝ≥0∞)) θ ∂(A z) := by\n intro j\n rw [lintegral_indicator (s := S j) (hQmeas j)]\n simp\n rw [Finset.sum_congr rfl (fun j _ => hrw j),\n ← lintegral_finset_sum _ (fun j _ => measurable_const.indicator (hQmeas j))]\n calc ∫⁻ θ, ∑ j : Fin N, (S j).indicator (fun _ => (1:ℝ≥0∞)) θ ∂(A z)\n ≤ ∫⁻ _, (m : ℝ≥0∞) ∂(A z) := by\n refine lintegral_mono fun θ => ?_\n have hi : ∀ j : Fin N, (S j).indicator (fun _ => (1:ℝ≥0∞)) θ\n = if Q θ j < ε then 1 else 0 := by\n intro j; simp [Set.indicator_apply, hS]\n rw [Finset.sum_congr rfl fun j _ => hi j, Finset.sum_ite, Finset.sum_const,\n Finset.sum_const_zero, add_zero, nsmul_eq_mul, mul_one]\n have := hm_le θ\n rw [lowLossCount] at this\n exact_mod_cast Nat.cast_le.mpr this\n _ = (m : ℝ≥0∞) := by simp\n have hq'_le : q' ≤ (m : ℝ) / (N : ℝ) := by\n have hlp : ∫⁻ x, G x ∂(prodMarginals D)\n = ∫⁻ z, (∫⁻ j, G (j, z) ∂((jointLaw D).map Prod.fst)) ∂((jointLaw D).map Prod.snd) := by\n rw [prodMarginals]\n exact lintegral_prod_symm G hGm.aemeasurable\n have hinner : ∀ z : Z, ∫⁻ j, G (j, z) ∂((jointLaw D).map Prod.fst)\n ≤ (N : ℝ≥0∞)⁻¹ * (m : ℝ≥0∞) := by\n intro z\n rw [lintegral_map (Measurable.of_discrete) measurable_fst,\n hlj (fun x => G (x.1, z)) (hGm.comp (measurable_fst.prodMk measurable_const))]\n have : ∀ j : Fin N, ∫⁻ _ : Z, G (j, z) ∂(D j) = G (j, z) := by\n intro j; simp\n rw [Finset.sum_congr rfl fun j _ => by rw [this j], ← Finset.mul_sum]\n exact mul_le_mul_left' (hsum z) _\n have hle : ∫⁻ x, G x ∂(prodMarginals D) ≤ (N : ℝ≥0∞)⁻¹ * (m : ℝ≥0∞) := by\n rw [hlp]\n calc ∫⁻ z, (∫⁻ j, G (j, z) ∂((jointLaw D).map Prod.fst)) ∂((jointLaw D).map Prod.snd)\n ≤ ∫⁻ _, (N : ℝ≥0∞)⁻¹ * (m : ℝ≥0∞) ∂((jointLaw D).map Prod.snd) :=\n lintegral_mono hinner\n _ = (N : ℝ≥0∞)⁻¹ * (m : ℝ≥0∞) := by simp\n have := (ENNReal.toReal_le_toReal hGint'_ne\n (ENNReal.mul_ne_top (ENNReal.inv_ne_top.mpr (by exact_mod_cast hN0.ne'))\n (ENNReal.natCast_ne_top m))).mpr hle\n rw [hq']\n refine this.trans_eq ?_\n rw [ENNReal.toReal_mul, ENNReal.toReal_inv, ENNReal.toReal_natCast, ENNReal.toReal_natCast]\n ring\n have hq'_nonneg : 0 ≤ q' := ENNReal.toReal_nonneg\n -- easy cases\n rcases le_or_lt q ((m : ℝ) / (N : ℝ)) with hcase | hcase\n · exact le_max_of_le_left hcase\n have hmpos : 0 < m := by\n by_contra h\n have hm0 : m = 0 := Nat.eq_zero_of_not_pos h\n have hGz : ∀ x, G x = 0 := by\n intro x\n have hz : ∑ j : Fin N, (A x.2) (S j) = 0 :=\n le_antisymm (by simpa [hm0] using hsum x.2) (zero_le _)\n exact (Finset.sum_eq_zero_iff).mp hz x.1 (Finset.mem_univ _)\n have : q = 0 := by\n rw [hq]\n simp [hGz]\n rw [this, hm0] at hcase\n simp at hcase\n have hmN : m < N := by\n by_contra h\n push_neg at h\n have : (1:ℝ) ≤ (m : ℝ) / (N : ℝ) := by\n rw [le_div_iff₀ hNR, one_mul]\n exact_mod_cast h\n linarith [hq_le_one]\n have hmR : (0:ℝ) < m := by exact_mod_cast hmpos\n have hNm : (1:ℝ) < (N : ℝ) / (m : ℝ) := by\n rw [lt_div_iff₀ hmR, one_mul]\n exact_mod_cast hmN\n set s : ℝ := Real.log ((N : ℝ) / (m : ℝ)) with hs_def\n have hs_pos : 0 < s := Real.log_pos hNm\n have hexps : Real.exp s = (N : ℝ) / (m : ℝ) := Real.exp_log (by positivity)\n -- the real-valued function\n set g : Fin N × Z → ℝ := fun x => (G x).toReal with hg_def\n have hgm : Measurable g := hGm.ennreal_toReal\n have hg0 : ∀ x, 0 ≤ g x := fun _ => ENNReal.toReal_nonneg\n have hg1 : ∀ x, g x ≤ 1 := by\n intro x\n rw [hg_def]\n exact ENNReal.toReal_le_of_le_ofReal zero_le_one (by simpa using hGle x)\n have hgiP : Integrable g (jointLaw D) := by\n refine Integrable.mono' (integrable_const (1:ℝ)) hgm.aestronglyMeasurable\n (Filter.Eventually.of_forall fun x => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg (hg0 x)]\n exact hg1 x\n have hgiQ : Integrable g (prodMarginals D) := by\n refine Integrable.mono' (integrable_const (1:ℝ)) hgm.aestronglyMeasurable\n (Filter.Eventually.of_forall fun x => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg (hg0 x)]\n exact hg1 x\n have hgP : ∫ x, g x ∂(jointLaw D) = q := by\n rw [hg_def, hq]\n exact integral_toReal hGm.aemeasurable\n (Filter.Eventually.of_forall fun x => lt_of_le_of_lt (hGle x) (by simp))\n have hgQ : ∫ x, g x ∂(prodMarginals D) = q' := by\n rw [hg_def, hq']\n exact integral_toReal hGm.aemeasurable\n (Filter.Eventually.of_forall fun x => lt_of_le_of_lt (hGle x) (by simp))\n set B : ℝ := ∫ x, Real.exp (s * g x) ∂(prodMarginals D) with hB_def\n have hexpm : Measurable fun x => Real.exp (s * g x) :=\n Real.measurable_exp.comp (measurable_const.mul hgm)\n have hexpi : Integrable (fun x => Real.exp (s * g x)) (prodMarginals D) := by\n refine Integrable.mono' (integrable_const (Real.exp s)) hexpm.aestronglyMeasurable\n (Filter.Eventually.of_forall fun x => ?_)\n rw [Real.norm_eq_abs, abs_of_nonneg (Real.exp_nonneg _)]\n exact Real.exp_le_exp.mpr (by nlinarith [hg0 x, hg1 x])\n have hB1 : 1 ≤ B := by\n rw [hB_def]\n have : ∫ _ : Fin N × Z, (1:ℝ) ∂(prodMarginals D) ≤ ∫ x, Real.exp (s * g x) ∂(prodMarginals D) :=\n integral_mono (integrable_const 1) hexpi (fun x => by\n have : (0:ℝ) ≤ s * g x := by positivity\n simpa using Real.one_le_exp this)\n simpa using this\n have hBpos : 0 < B := lt_of_lt_of_le zero_lt_one hB1\n have hB2 : B ≤ 1 + (Real.exp s - 1) * q' := by\n have hcv := convexOn_exp.2\n have hpt : ∀ x, Real.exp (s * g x) ≤ 1 + (Real.exp s - 1) * g x := by\n intro x\n have hc := hcv (Set.mem_univ (0:ℝ)) (Set.mem_univ s) (a := 1 - g x) (b := g x)\n (by linarith [hg1 x]) (hg0 x) (by ring)\n simp only [smul_eq_mul, mul_zero, zero_add, Real.exp_zero, mul_one] at hc\n calc Real.exp (s * g x) = Real.exp (g x * s) := by rw [mul_comm]\n _ ≤ (1 - g x) + g x * Real.exp s := hc\n _ = 1 + (Real.exp s - 1) * g x := by ring\n have ic1 : Integrable (fun _ : Fin N × Z => (1:ℝ)) (prodMarginals D) := integrable_const 1\n have ic2 : Integrable (fun x => (Real.exp s - 1) * g x) (prodMarginals D) :=\n hgiQ.const_mul (Real.exp s - 1)\n have ic3 : Integrable (fun x => 1 + (Real.exp s - 1) * g x) (prodMarginals D) := ic1.add ic2\n have hmono := integral_mono hexpi ic3 hpt\n rw [integral_add ic1 ic2, integral_const_mul, hgQ] at hmono\n simpa using hmono\n have hBle2 : B ≤ 2 := by\n have h1 : (Real.exp s - 1) * q' ≤ (Real.exp s - 1) * ((m : ℝ) / (N : ℝ)) := by\n refine mul_le_mul_of_nonneg_left hq'_le ?_\n rw [hexps]; linarith\n have h2 : (Real.exp s - 1) * ((m : ℝ) / (N : ℝ)) = 1 - (m : ℝ) / (N : ℝ) := by\n rw [hexps]; field_simp\n have h3 : 0 ≤ (m : ℝ) / (N : ℝ) := by positivity\n linarith\n -- apply the variational bound\n set c : ℝ := 1 - Real.log B with hc_def\n set f : Fin N × Z → ℝ := fun x => s * g x + c with hf_def\n have hfm : Measurable f := (measurable_const.mul hgm).add measurable_const\n have hfbdd : ∀ x, ‖f x‖ ≤ s + |c| := by\n intro x\n rw [Real.norm_eq_abs, hf_def]\n refine (abs_add_le _ _).trans ?_\n have : |s * g x| ≤ s := by\n rw [abs_mul, abs_of_pos hs_pos, abs_of_nonneg (hg0 x)]\n nlinarith [hg1 x, hs_pos.le, hg0 x]\n linarith\n have hdv := dv_bound (P := jointLaw D) (Qm := prodMarginals D) hI_fin hfm hfbdd\n have hfP : ∫ x, f x ∂(jointLaw D) = s * q + c := by\n have ja1 : Integrable (fun x => s * g x) (jointLaw D) := hgiP.const_mul s\n have ja2 : Integrable (fun _ : Fin N × Z => c) (jointLaw D) := integrable_const c\n rw [hf_def, integral_add ja1 ja2, integral_const_mul, hgP]\n simp\n have hexpc : ∀ x, Real.exp (f x - 1) = B⁻¹ * Real.exp (s * g x) := by\n intro x\n rw [hf_def, hc_def]\n have : s * g x + (1 - Real.log B) - 1 = s * g x - Real.log B := by ring\n rw [this, Real.exp_sub, Real.exp_log hBpos]\n ring\n have hfQ : ∫ x, Real.exp (f x - 1) ∂(prodMarginals D) = 1 := by\n rw [integral_congr_ae (Filter.Eventually.of_forall hexpc), integral_const_mul, ← hB_def]\n field_simp\n rw [hfP, hfQ, ← hI] at hdv\n have hkey : s * q ≤ I + Real.log B := by\n rw [hc_def] at hdv\n linarith\n have hlogB : Real.log B ≤ Real.log 2 := Real.log_le_log hBpos hBle2\n have hfinal : q ≤ (I + Real.log 2) / s := by\n rw [le_div_iff₀ hs_pos]\n nlinarith [hkey, hlogB]\n exact le_max_of_le_right hfinal\n\nend GraduateLevel\n"} +{"id": "ch13_theorem_13_5", "source": "Graduate-level", "targets": [{"label": "ch13_theorem_13_5", "decls": ["ch13_theorem_13_5"], "statement": "Consider a sequence of random functions \\(\\xi_1(S_1),\\ldots,\\xi_t(S_t),\\ldots\\) such that \\(\\xi_{i}\\in [0,1]\\) for all \\(i\\). We have for \\(\\lambda >0\\), with probability at least \\(1 - \\delta\\):\n\\[\n\\forall n>0:\\frac{1}{n}\\sum_{i=1}^{n}\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i}<\\frac{\\lambda}{1-e^{-\\lambda}}\\frac{1}{n}\\sum_{i=1}^{n}\\xi_{i}+\\frac{\\ln(1/\\delta)}{\\left(1-e^{-\\lambda}\\right)n}.\n\\]\nSimilarly, for \\(\\lambda > 0\\), with probability at least \\(1 - \\delta\\):\n\\[\n\\forall n>0:\\frac{1}{n}\\sum_{i=1}^{n}\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i}>\\frac{\\lambda}{e^{\\lambda}-1}\\frac{1}{n}\\sum_{i=1}^{n}\\xi_{i}-\\frac{\\ln(1/\\delta)}{(e^{\\lambda}-1)n}.\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Martingales & Dependent Data"}], "nl_proof": "We obtain from Lemma 2.15 and Theorem 13.2 that with probability at least \\(1 - \\delta\\)\n\\[\n\\begin{array}{l}-\\sum_{i=1}^{n}\\xi_{i}<\\frac{\\ln(1/\\delta)}{\\lambda}+\\frac{1}{\\lambda}\\sum_{i=1}^{n}\\ln(1+(e^{-\\lambda}-1)\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i})\\\\ \\leq\\frac{\\ln(1/\\delta)}{\\lambda}+\\frac{1}{\\lambda}\\sum_{i=1}^{n}\\left(e^{-\\lambda}-1\\right)\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i}.\\\\ \\end{array}\n\\]\nThis implies the first bound. Moreover, with probability at least \\(1 - \\delta\\):\n\\[\n-\\sum_{i=1}^{n}[1-\\xi_{i}]<\\frac{\\ln(1/\\delta)}{\\lambda}+\\frac{1}{\\lambda}\\sum_{i=1}^{n}\\ln(1+(e^{-\\lambda}-1)\\mathbb{E}_{Z_{i}^{(y)}}[1-\\xi_{i}])\n\\]\nimplies that\n\\[\n\\begin{array}{l}\\sum_{i=1}^{n}\\xi_{i}<\\frac{\\ln(1/\\delta)}{\\lambda}+\\frac{1}{\\lambda}\\sum_{i=1}^{n}\\ln(1+(e^{\\lambda}-1)\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i})\\\\ \\leq\\frac{\\ln(1/\\delta)}{\\lambda}+\\frac{1}{\\lambda}\\sum_{i=1}^{n}\\left(e^{\\lambda}-1\\right)\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i}.\\\\ \\end{array}\n\\]\nThis implies the second bound.", "context": [{"id": "ch2:lemma:2_15", "name": "lemma 2.15", "statement": "Consider a random variable \\(X \\in [0,1]\\) and \\(\\mathbb{E}X = \\mu\\). We have the following inequality:\n\\[\n\\ln\\mathbb{E}e^{\\lambda X}\\leq\\ln [(1-\\mu)e^{0}+\\mu e^{\\lambda}]\\leq\\lambda\\mu+\\lambda^{2}/8.\n\\]"}, {"id": "ch13:theorem:13_2", "name": "theorem 13.2", "statement": "Consider a sequence of random functions \\(\\xi_1(S_1),\\ldots,\\xi_t(S_t),\\ldots\\) with filtration \\(\\{\\mathcal{F}_t\\}\\). We have for any \\(\\delta \\in (0,1)\\) and \\(\\lambda >0\\):\n\\[\n\\operatorname*{Pr}\\left[\\exists n>0: -\\sum_{i=1}^{n}\\xi_{i}\\geq\\frac{\\ln(1/\\delta)}{\\lambda}+\\frac{1}{\\lambda}\\sum_{i=1}^{n}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{-\\lambda\\xi_{i}}\\right]\\leq\\delta .\n\\]\nMoreover, consider a sequence of \\(\\{z_t\\in \\mathbb{R}\\}\\) adapted to \\(\\{\\mathcal{F}_t\\}\\), and events \\(A_{t}\\) on \\(\\mathcal{F}_t\\):\n\\[\n\\ln\\Pr\\left[\\exists n>0:\\sum_{i=1}^{n}\\xi_{i}\\leq z_{n}\\&\\mathcal{S}_{n}\\in A_{n}\\right]\\leq\\inf_{\\lambda>0}\\sup_{n>0}\\sup_{\\mathcal{S}_{n}\\in A_{n}}\\left[\\lambda z_{n}+\\sum_{i=1}^{n}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{-\\lambda\\xi_{i}}\\right].\n\\]"}, {"id": "ch13:setup:13_1", "name": "section 13.1 sequential observation setup", "statement": "In Section 13.1, data are observed sequentially. At each time \\(t\\), after the history \\(S_{t-1}\\) has been observed, the next observation \\(Z_t\\) is drawn according to a distribution that may depend on that history. The observation is decomposed as \\(Z_t=(Z_t^{(x)},Z_t^{(y)})\\), where \\(Z_t^{(x)}\\) is the component determined by the past history or the chosen action at time \\(t\\), and \\(Z_t^{(y)}\\) is the random response component. The history after time \\(t\\) is \\(S_t=(Z_1,\\ldots,Z_t)\\), and \\(\\mathcal{S}_T\\) denotes the full sequential experiment/history through time \\(T\\). For a function depending on \\(S_t\\), the notation \\(\\mathbb{E}_{Z_t^{(y)}}[\\cdot]\\) means conditional expectation over the response component \\(Z_t^{(y)}\\), conditional on \\(S_{t-1}\\) and on \\(Z_t^{(x)}\\). Stopping times are adapted to the filtration generated by the histories \\(S_t\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch13_theorem_13_5\n {Ω : Type*} {m : MeasurableSpace Ω} (μ : Measure Ω) [IsProbabilityMeasure μ]\n (ℱ : MeasureTheory.Filtration ℕ m)\n (ξ : ℕ → Ω → ℝ)\n (lam δ : ℝ) (hlam : 0 < lam) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hmeas : ∀ i, Measurable (ξ i))\n (hadapt : MeasureTheory.Adapted ℱ ξ)\n (hbound : ∀ i ω, ξ i ω ∈ Set.Icc (0 : ℝ) 1) :\n (1 - δ ≤ (μ {ω : Ω | ∀ n : ℕ, 0 < n →\n (n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, (μ[ξ i | ℱ (i - 1)]) ω\n < (lam / (1 - Real.exp (-lam))) * ((n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, ξ i ω)\n + Real.log (1 / δ) / ((1 - Real.exp (-lam)) * n)}).toReal)\n ∧\n (1 - δ ≤ (μ {ω : Ω | ∀ n : ℕ, 0 < n →\n (n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, (μ[ξ i | ℱ (i - 1)]) ω\n > (lam / (Real.exp lam - 1)) * ((n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, ξ i ω)\n - Real.log (1 / δ) / ((Real.exp lam - 1) * n)}).toReal) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nsection Aux\n\nvariable {Ω : Type*} {m : MeasurableSpace Ω}\n\nprivate lemma exp_le_lin (θ : ℝ) {x : ℝ} (hx0 : 0 ≤ x) (hx1 : x ≤ 1) :\n Real.exp (θ * x) ≤ 1 + (Real.exp θ - 1) * x := by\n have h := convexOn_exp.2 (Set.mem_univ (0 : ℝ)) (Set.mem_univ θ)\n (by linarith : (0:ℝ) ≤ 1 - x) hx0 (by ring)\n simp only [smul_eq_mul, mul_zero, zero_add, Real.exp_zero, mul_one] at h\n rw [mul_comm θ x]\n nlinarith [h, Real.exp_pos θ]\n\nprivate lemma ville {μ : Measure Ω} [IsProbabilityMeasure μ] {ℱ : Filtration ℕ m}\n {N : ℕ → Ω → ℝ} (hsup : Supermartingale N ℱ μ) (hnn : ∀ n ω, 0 ≤ N n ω)\n (hN0 : ∀ ω, N 0 ω = 1) {ε : ℝ} (hε : 0 < ε) :\n μ {ω | ∃ n, ε ≤ N n ω} ≤ ENNReal.ofReal ε⁻¹ := by\n classical\n have hNmeas : ∀ k, Measurable (N k) := fun k =>\n ((hsup.stronglyMeasurable k).mono (ℱ.le k)).measurable\n have hAmeas : ∀ n : ℕ, MeasurableSet {ω | ∃ k ≤ n, ε ≤ N k ω} := by\n intro n\n have he : {ω | ∃ k ≤ n, ε ≤ N k ω} = ⋃ k ∈ Finset.range (n+1), {ω | ε ≤ N k ω} := by\n ext ω; simp [Nat.lt_succ_iff]\n rw [he]\n exact MeasurableSet.biUnion (Set.to_countable _)\n (fun k _ => measurableSet_le measurable_const (hNmeas k))\n have key : ∀ n : ℕ, μ {ω | ∃ k ≤ n, ε ≤ N k ω} ≤ ENNReal.ofReal ε⁻¹ := by\n intro n\n set τ : Ω → ℕ∞ := fun ω => ((hittingBtwn N {y : ℝ | ε ≤ y} 0 n ω : ℕ) : ℕ∞) with hτdef\n have hτ : IsStoppingTime ℱ τ :=\n hittingBtwn_isStoppingTime hsup.adapted measurableSet_Ici\n have hbdd : ∀ ω, τ ω ≤ (n : ℕ∞) := by\n intro ω\n have h := hittingBtwn_le (u := N) (s := {y : ℝ | ε ≤ y}) (n := 0) (m := n) ω\n simp only [hτdef]\n exact_mod_cast h\n have hsubm : Submartingale (-N) ℱ μ := hsup.neg\n have hmono := hsubm.expected_stoppedValue_mono (isStoppingTime_const ℱ 0) hτ\n (fun ω => by simp [hτdef]) hbdd\n have hsvneg : stoppedValue (-N) τ = -stoppedValue N τ := by\n funext ω; simp [stoppedValue]\n rw [stoppedValue_const, hsvneg] at hmono\n have hL : ∫ x, (-N) 0 x ∂μ = -1 := by simp [hN0]\n rw [hL] at hmono\n simp only [Pi.neg_apply, integral_neg] at hmono\n have hintsv : Integrable (stoppedValue N τ) μ :=\n integrable_stoppedValue ℕ hτ hsup.integrable hbdd\n have htot : ∫ ω, stoppedValue N τ ω ∂μ ≤ 1 := by linarith\n have hge : ∀ ω ∈ {ω | ∃ k ≤ n, ε ≤ N k ω}, ε ≤ stoppedValue N τ ω := by\n rintro ω ⟨k, hk, hkε⟩\n exact stoppedValue_hittingBtwn_mem ⟨k, ⟨Nat.zero_le _, hk⟩, hkε⟩\n have h1 := setIntegral_ge_of_const_le_real (hAmeas n) (measure_ne_top _ _) hge\n hintsv.integrableOn\n have h2 : ∫ ω in {ω | ∃ k ≤ n, ε ≤ N k ω}, stoppedValue N τ ω ∂μ\n ≤ ∫ ω, stoppedValue N τ ω ∂μ :=\n setIntegral_le_integral hintsv (ae_of_all _ fun ω => hnn _ _)\n simp only [measureReal_def] at h1\n have h3 : ε * (μ {ω | ∃ k ≤ n, ε ≤ N k ω}).toReal ≤ 1 := by linarith\n have hinv : ε * ε⁻¹ = 1 := mul_inv_cancel₀ (ne_of_gt hε)\n have h4 : (μ {ω | ∃ k ≤ n, ε ≤ N k ω}).toReal ≤ ε⁻¹ := by nlinarith [h3, hinv, hε]\n calc μ {ω | ∃ k ≤ n, ε ≤ N k ω}\n = ENNReal.ofReal (μ {ω | ∃ k ≤ n, ε ≤ N k ω}).toReal := by\n rw [ENNReal.ofReal_toReal (measure_ne_top _ _)]\n _ ≤ ENNReal.ofReal ε⁻¹ := ENNReal.ofReal_le_ofReal h4\n have hunion : {ω | ∃ n, ε ≤ N n ω} = ⋃ n : ℕ, {ω | ∃ k ≤ n, ε ≤ N k ω} := by\n ext ω\n constructor\n · rintro ⟨n, hn⟩; exact Set.mem_iUnion.2 ⟨n, n, le_rfl, hn⟩\n · rintro h\n obtain ⟨n, k, _, hk⟩ := Set.mem_iUnion.1 h\n exact ⟨k, hk⟩\n have hmono' : Monotone (fun n : ℕ => {ω | ∃ k ≤ n, ε ≤ N k ω}) := by\n intro a b hab\n rintro ω ⟨k, hk, hkε⟩\n exact ⟨k, hk.trans hab, hkε⟩\n rw [hunion, hmono'.measure_iUnion]\n exact iSup_le key\n\nprivate lemma main_bound (μ : Measure Ω) [IsProbabilityMeasure μ]\n (ℱ : Filtration ℕ m) (ξ : ℕ → Ω → ℝ) (θ δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hmeas : ∀ i, Measurable (ξ i)) (hadapt : Adapted ℱ ξ)\n (hbound : ∀ i ω, ξ i ω ∈ Set.Icc (0 : ℝ) 1) :\n 1 - δ ≤ (μ {ω : Ω | ∀ n : ℕ, 0 < n →\n θ * (∑ i ∈ Finset.Icc 1 n, ξ i ω)\n - (Real.exp θ - 1) * (∑ i ∈ Finset.Icc 1 n, (μ[ξ i | ℱ (i-1)]) ω)\n < Real.log (1/δ)}).toReal := by\n classical\n obtain ⟨g, hgdef⟩ : ∃ g : ℕ → Ω → ℝ, ∀ i, g i = μ[ξ i | ℱ (i-1)] := ⟨_, fun _ => rfl⟩\n obtain ⟨K, hKdef⟩ : ∃ K : ℝ, K = Real.exp θ - 1 := ⟨_, rfl⟩\n simp only [← hgdef, ← hKdef]\n have hint : ∀ i, Integrable (ξ i) μ := by\n intro i\n refine Integrable.mono' (integrable_const (1:ℝ)) (hmeas i).aestronglyMeasurable ?_\n filter_upwards with ω\n rw [Real.norm_eq_abs, abs_le]\n exact ⟨by linarith [(hbound i ω).1], (hbound i ω).2⟩\n have hgm : ∀ i, StronglyMeasurable[ℱ (i-1)] (g i) := by\n intro i; rw [hgdef]; exact stronglyMeasurable_condExp\n have hgint : ∀ i, Integrable (g i) μ := by\n intro i; rw [hgdef]; exact integrable_condExp\n have hg0 : ∀ i, 0 ≤ᵐ[μ] g i := by\n intro i\n have h := condExp_mono (μ := μ) (m := ℱ (i-1)) (integrable_const (0:ℝ)) (hint i)\n (ae_of_all _ (fun ω => (hbound i ω).1))\n rw [condExp_const (ℱ.le _)] at h\n rw [hgdef]; exact h\n have hg1 : ∀ i, g i ≤ᵐ[μ] fun _ => (1:ℝ) := by\n intro i\n have h := condExp_mono (μ := μ) (m := ℱ (i-1)) (hint i) (integrable_const (1:ℝ))\n (ae_of_all _ (fun ω => (hbound i ω).2))\n rw [condExp_const (ℱ.le _)] at h\n rw [hgdef]; exact h\n have hgae : ∀ᵐ ω ∂μ, ∀ i, 0 ≤ g i ω ∧ g i ω ≤ 1 := by\n rw [ae_all_iff]\n intro i\n filter_upwards [hg0 i, hg1 i] with ω h1 h2 using ⟨h1, h2⟩\n obtain ⟨Nn, hNdef⟩ : ∃ N : ℕ → Ω → ℝ, ∀ n ω, N n ω =\n Real.exp (θ * (∑ i ∈ Finset.Icc 1 n, ξ i ω) - K * (∑ i ∈ Finset.Icc 1 n, g i ω)) :=\n ⟨_, fun _ _ => rfl⟩\n have hFsm : ∀ n, StronglyMeasurable[ℱ n]\n (fun ω => θ * (∑ i ∈ Finset.Icc 1 n, ξ i ω) - K * (∑ i ∈ Finset.Icc 1 n, g i ω)) := by\n intro n\n have h1 : StronglyMeasurable[ℱ n] (fun ω => ∑ i ∈ Finset.Icc 1 n, ξ i ω) :=\n Finset.stronglyMeasurable_fun_sum _\n (fun i hi => (hadapt i).mono (ℱ.mono (Finset.mem_Icc.mp hi).2))\n have h2 : StronglyMeasurable[ℱ n] (fun ω => ∑ i ∈ Finset.Icc 1 n, g i ω) :=\n Finset.stronglyMeasurable_fun_sum _\n (fun i hi => (hgm i).mono (ℱ.mono ((Nat.sub_le i 1).trans (Finset.mem_Icc.mp hi).2)))\n exact (h1.const_mul θ).sub (h2.const_mul K)\n have hNsm : ∀ n, StronglyMeasurable[ℱ n] (Nn n) := by\n intro n\n have : Nn n = fun ω => Real.exp\n (θ * (∑ i ∈ Finset.Icc 1 n, ξ i ω) - K * (∑ i ∈ Finset.Icc 1 n, g i ω)) :=\n funext (hNdef n)\n rw [this]\n exact Real.continuous_exp.comp_stronglyMeasurable (hFsm n)\n have hNint : ∀ n, Integrable (Nn n) μ := by\n intro n\n refine Integrable.mono' (integrable_const (Real.exp ((|θ| + |K|) * n)))\n ((hNsm n).mono (ℱ.le n)).aestronglyMeasurable ?_\n filter_upwards [hgae] with ω hω\n have hs1 : (0:ℝ) ≤ ∑ i ∈ Finset.Icc 1 n, ξ i ω := Finset.sum_nonneg fun i _ => (hbound i ω).1\n have hs1' : (∑ i ∈ Finset.Icc 1 n, ξ i ω) ≤ n := by\n calc (∑ i ∈ Finset.Icc 1 n, ξ i ω) ≤ ∑ _i ∈ Finset.Icc 1 n, (1:ℝ) :=\n Finset.sum_le_sum fun i _ => (hbound i ω).2\n _ = n := by simp\n have hs2 : (0:ℝ) ≤ ∑ i ∈ Finset.Icc 1 n, g i ω := Finset.sum_nonneg fun i _ => (hω i).1\n have hs2' : (∑ i ∈ Finset.Icc 1 n, g i ω) ≤ n := by\n calc (∑ i ∈ Finset.Icc 1 n, g i ω) ≤ ∑ _i ∈ Finset.Icc 1 n, (1:ℝ) :=\n Finset.sum_le_sum fun i _ => (hω i).2\n _ = n := by simp\n have hnn : (0:ℝ) ≤ (n:ℝ) := Nat.cast_nonneg n\n have hb : θ * (∑ i ∈ Finset.Icc 1 n, ξ i ω) - K * (∑ i ∈ Finset.Icc 1 n, g i ω)\n ≤ (|θ| + |K|) * n := by\n have e1 : θ * (∑ i ∈ Finset.Icc 1 n, ξ i ω) ≤ |θ| * n := by\n nlinarith [le_abs_self θ, abs_nonneg θ, neg_abs_le θ]\n have e2 : -(K * (∑ i ∈ Finset.Icc 1 n, g i ω)) ≤ |K| * n := by\n nlinarith [le_abs_self K, abs_nonneg K, neg_abs_le K, abs_nonneg K]\n nlinarith\n rw [hNdef, Real.norm_eq_abs, abs_of_nonneg (Real.exp_nonneg _)]\n exact Real.exp_le_exp.mpr hb\n have hsuper : Supermartingale Nn ℱ μ := by\n refine supermartingale_nat (fun n => hNsm n) hNint ?_\n intro i\n have hi1 : (i + 1) - 1 = i := by omega\n have hsplit : ∀ ω, Nn (i+1) ω\n = (Nn i ω * Real.exp (-(K * g (i+1) ω))) * Real.exp (θ * ξ (i+1) ω) := by\n intro ω\n rw [hNdef, hNdef, Finset.sum_Icc_succ_top (by omega : 1 ≤ i + 1),\n Finset.sum_Icc_succ_top (by omega : 1 ≤ i + 1), ← Real.exp_add, ← Real.exp_add]\n congr 1\n ring\n have hPsm : StronglyMeasurable[ℱ i] (fun ω => Nn i ω * Real.exp (-(K * g (i+1) ω))) := by\n have hgi : StronglyMeasurable[ℱ i] (g (i+1)) := by\n have := hgm (i+1); rwa [hi1] at this\n exact (hNsm i).mul (Real.continuous_exp.comp_stronglyMeasurable ((hgi.const_mul K).neg))\n have hQint : Integrable (fun ω => Real.exp (θ * ξ (i+1) ω)) μ := by\n refine Integrable.mono' (integrable_const (Real.exp (|θ|))\n ) ((Real.continuous_exp.comp_stronglyMeasurable\n (((hadapt (i+1)).mono (ℱ.le _)).const_mul θ)).aestronglyMeasurable) ?_\n filter_upwards with ω\n rw [Real.norm_eq_abs, abs_of_nonneg (Real.exp_nonneg _)]\n refine Real.exp_le_exp.mpr ?_\n nlinarith [le_abs_self θ, abs_nonneg θ, neg_abs_le θ, (hbound (i+1) ω).1,\n (hbound (i+1) ω).2]\n have hfun : Nn (i+1) = (fun ω => Nn i ω * Real.exp (-(K * g (i+1) ω)))\n * (fun ω => Real.exp (θ * ξ (i+1) ω)) := funext hsplit\n have h1 : μ[Nn (i+1) | ℱ i] =ᵐ[μ] (fun ω => Nn i ω * Real.exp (-(K * g (i+1) ω)))\n * μ[fun ω => Real.exp (θ * ξ (i+1) ω) | ℱ i] := by\n rw [hfun]\n exact condExp_mul_of_stronglyMeasurable_left hPsm (by rw [← hfun]; exact hNint _) hQint\n have hcond2 : μ[fun ω => Real.exp (θ * ξ (i+1) ω) | ℱ i]\n ≤ᵐ[μ] fun ω => 1 + K * g (i+1) ω := by\n have hle : (fun ω => Real.exp (θ * ξ (i+1) ω)) ≤ᵐ[μ]\n ((fun _ : Ω => (1:ℝ)) + (fun _ : Ω => K) * ξ (i+1)) := by\n refine ae_of_all _ fun ω => ?_\n show Real.exp (θ * ξ (i+1) ω) ≤ 1 + K * ξ (i+1) ω\n rw [hKdef]\n exact exp_le_lin θ (hbound (i+1) ω).1 (hbound (i+1) ω).2\n have hKint : Integrable ((fun _ : Ω => K) * ξ (i+1)) μ := (hint (i+1)).const_mul K\n have hintR : Integrable ((fun _ : Ω => (1:ℝ)) + (fun _ : Ω => K) * ξ (i+1)) μ :=\n (integrable_const (1:ℝ)).add hKint\n have hmono := condExp_mono (μ := μ) (m := ℱ i) hQint hintR hle\n have hR : μ[((fun _ : Ω => (1:ℝ)) + (fun _ : Ω => K) * ξ (i+1)) | ℱ i]\n =ᵐ[μ] fun ω => 1 + K * g (i+1) ω := by\n have hadd := condExp_add (μ := μ) (integrable_const (1:ℝ)) hKint (ℱ i)\n have hsm := condExp_mul_of_stronglyMeasurable_left (μ := μ) (m := ℱ i)\n (stronglyMeasurable_const (b := K)) hKint (hint (i+1))\n have hc1 : μ[fun _ : Ω => (1:ℝ) | ℱ i] = fun _ => (1:ℝ) := condExp_const (ℱ.le _) _\n have hgg : (μ[ξ (i+1) | ℱ i]) = g (i+1) := by rw [hgdef, hi1]\n filter_upwards [hadd, hsm] with ω ha hb\n rw [ha]\n simp only [Pi.add_apply, Pi.mul_apply] at hb ⊢\n rw [hb, hc1, hgg]\n exact hmono.trans hR.le\n filter_upwards [h1, hcond2, hgae] with ω hω1 hω2 hω3\n rw [hω1]\n simp only [Pi.mul_apply] at hω1 ⊢\n have hPnn : 0 ≤ Nn i ω * Real.exp (-(K * g (i+1) ω)) := by\n rw [hNdef]; positivity\n have hstep : Nn i ω * Real.exp (-(K * g (i+1) ω)) *\n (μ[fun ω => Real.exp (θ * ξ (i+1) ω) | ℱ i]) ω\n ≤ Nn i ω * Real.exp (-(K * g (i+1) ω)) * (1 + K * g (i+1) ω) :=\n mul_le_mul_of_nonneg_left hω2 hPnn\n have hexp : 1 + K * g (i+1) ω ≤ Real.exp (K * g (i+1) ω) := by\n have := Real.add_one_le_exp (K * g (i+1) ω)\n linarith\n have hNni : 0 ≤ Nn i ω := by rw [hNdef]; positivity\n have hfin : Nn i ω * Real.exp (-(K * g (i+1) ω)) * (1 + K * g (i+1) ω) ≤ Nn i ω := by\n have h5 : Nn i ω * Real.exp (-(K * g (i+1) ω)) * (1 + K * g (i+1) ω)\n ≤ Nn i ω * Real.exp (-(K * g (i+1) ω)) * Real.exp (K * g (i+1) ω) :=\n mul_le_mul_of_nonneg_left hexp hPnn\n have h6 : Nn i ω * Real.exp (-(K * g (i+1) ω)) * Real.exp (K * g (i+1) ω) = Nn i ω := by\n rw [mul_assoc, ← Real.exp_add]\n simp\n linarith [h5, h6.le, h6.ge]\n linarith\n have hεpos : (0:ℝ) < 1/δ := by positivity\n have hN0 : ∀ ω, Nn 0 ω = 1 := by\n intro ω\n rw [hNdef, Finset.Icc_eq_empty (by omega)]\n simp\n have hville := ville hsuper (fun n ω => by rw [hNdef]; positivity) hN0 hεpos\n set S : Set Ω := {ω : Ω | ∀ n : ℕ, 0 < n →\n θ * (∑ i ∈ Finset.Icc 1 n, ξ i ω) - K * (∑ i ∈ Finset.Icc 1 n, g i ω)\n < Real.log (1/δ)} with hSdef\n have hcompl : Sᶜ ⊆ {ω | ∃ n, (1/δ) ≤ Nn n ω} := by\n intro ω hω\n simp only [hSdef, Set.mem_compl_iff, Set.mem_setOf_eq, not_forall, not_lt] at hω\n obtain ⟨n, hn, hn2⟩ := hω\n refine ⟨n, ?_⟩\n rw [hNdef]\n calc (1:ℝ)/δ = Real.exp (Real.log (1/δ)) := (Real.exp_log hεpos).symm\n _ ≤ _ := Real.exp_le_exp.mpr hn2\n have hbad : μ Sᶜ ≤ ENNReal.ofReal δ := by\n refine (measure_mono hcompl).trans ?_\n refine hville.trans ?_\n rw [one_div, inv_inv]\n have hu : (1:ℝ≥0∞) ≤ μ S + ENNReal.ofReal δ := by\n calc (1:ℝ≥0∞) = μ Set.univ := (measure_univ).symm\n _ = μ (S ∪ Sᶜ) := by rw [Set.union_compl_self]\n _ ≤ μ S + μ Sᶜ := measure_union_le _ _\n _ ≤ μ S + ENNReal.ofReal δ := by gcongr\n have hfin : μ S + ENNReal.ofReal δ ≠ ⊤ := by\n exact ENNReal.add_ne_top.2 ⟨measure_ne_top _ _, ENNReal.ofReal_ne_top⟩\n have h9 := ENNReal.toReal_mono hfin hu\n rw [ENNReal.toReal_add (measure_ne_top _ _) ENNReal.ofReal_ne_top,\n ENNReal.toReal_ofReal hδ0.le, ENNReal.toReal_one] at h9\n linarith\n\nend Aux\n\ntheorem ch13_theorem_13_5\n {Ω : Type*} {m : MeasurableSpace Ω} (μ : Measure Ω) [IsProbabilityMeasure μ]\n (ℱ : MeasureTheory.Filtration ℕ m)\n (ξ : ℕ → Ω → ℝ)\n (lam δ : ℝ) (hlam : 0 < lam) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hmeas : ∀ i, Measurable (ξ i))\n (hadapt : MeasureTheory.Adapted ℱ ξ)\n (hbound : ∀ i ω, ξ i ω ∈ Set.Icc (0 : ℝ) 1) :\n (1 - δ ≤ (μ {ω : Ω | ∀ n : ℕ, 0 < n →\n (n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, (μ[ξ i | ℱ (i - 1)]) ω\n < (lam / (1 - Real.exp (-lam))) * ((n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, ξ i ω)\n + Real.log (1 / δ) / ((1 - Real.exp (-lam)) * n)}).toReal)\n ∧\n (1 - δ ≤ (μ {ω : Ω | ∀ n : ℕ, 0 < n →\n (n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, (μ[ξ i | ℱ (i - 1)]) ω\n > (lam / (Real.exp lam - 1)) * ((n : ℝ)⁻¹ * ∑ i ∈ Finset.Icc 1 n, ξ i ω)\n - Real.log (1 / δ) / ((Real.exp lam - 1) * n)}).toReal) := by\n constructor\n · have h := main_bound μ ℱ ξ (-lam) δ hδ0 hδ1 hmeas hadapt hbound\n refine h.trans (ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono ?_))\n intro ω hω n hn\n simp only [Set.mem_setOf_eq] at hω\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hc : (0:ℝ) < 1 - Real.exp (-lam) := by\n have : Real.exp (-lam) < 1 := Real.exp_lt_one_iff.mpr (by linarith)\n linarith\n have hcn : (0:ℝ) < (1 - Real.exp (-lam)) * n := mul_pos hc hn'\n have hkey := hω n hn\n set u := ∑ i ∈ Finset.Icc 1 n, (μ[ξ i | ℱ (i - 1)]) ω with hu\n set v := ∑ i ∈ Finset.Icc 1 n, ξ i ω with hv\n have h2 : (1 - Real.exp (-lam)) * u < lam * v + Real.log (1/δ) := by nlinarith [hkey]\n have h5 : (lam / (1 - Real.exp (-lam))) * ((n:ℝ)⁻¹ * v)\n + Real.log (1/δ) / ((1 - Real.exp (-lam)) * n) - (n:ℝ)⁻¹ * u\n = (lam * v + Real.log (1/δ) - (1 - Real.exp (-lam)) * u) / ((1 - Real.exp (-lam)) * n) := by\n field_simp\n try ring\n have hpos : 0 < (lam * v + Real.log (1/δ) - (1 - Real.exp (-lam)) * u)\n / ((1 - Real.exp (-lam)) * n) := div_pos (by linarith) hcn\n linarith [h5, hpos]\n · have h := main_bound μ ℱ ξ lam δ hδ0 hδ1 hmeas hadapt hbound\n refine h.trans (ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono ?_))\n intro ω hω n hn\n simp only [Set.mem_setOf_eq] at hω\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hD : (0:ℝ) < Real.exp lam - 1 := by\n have := Real.add_one_le_exp lam\n linarith\n have hDn : (0:ℝ) < (Real.exp lam - 1) * n := mul_pos hD hn'\n have hkey := hω n hn\n set u := ∑ i ∈ Finset.Icc 1 n, (μ[ξ i | ℱ (i - 1)]) ω with hu\n set v := ∑ i ∈ Finset.Icc 1 n, ξ i ω with hv\n have h2 : lam * v - (Real.exp lam - 1) * u < Real.log (1/δ) := hkey\n show _ > _\n have h5 : (n:ℝ)⁻¹ * u - ((lam / (Real.exp lam - 1)) * ((n:ℝ)⁻¹ * v)\n - Real.log (1/δ) / ((Real.exp lam - 1) * n))\n = ((Real.exp lam - 1) * u - lam * v + Real.log (1/δ)) / ((Real.exp lam - 1) * n) := by\n field_simp\n try ring\n have hpos : 0 < ((Real.exp lam - 1) * u - lam * v + Real.log (1/δ))\n / ((Real.exp lam - 1) * n) := div_pos (by linarith) hDn\n linarith [h5, hpos]\n\nend GraduateLevel\n"} +{"id": "ch15_corollary_15_7", "source": "Graduate-level", "targets": [{"label": "ch15_corollary_15_7", "decls": ["ch15_corollary_15_7"], "statement": "Assume that \\( Y_{t} \\in [0, M] \\) for \\( t \\geq 1 \\). Consider the ridge regression method of (15.3), with \\(\\Lambda_0\\) symmetric positive definite, and let\n\\[\n\\hat{Y}_{t}=\\max(0,\\min(M,\\hat{w}(\\mathcal{S}_{t-1})^{\\top}\\psi(X_{t}))).\n\\]\nWe have\n\\[\n\\sum_{t=1}^{T}(Y_{t}-\\hat{Y}_{t})^{2}\\leq\\inf_{w}\\left[\\sum_{t=1}^{T}(Y_{t}-w^{\\top}\\psi(X_{t}))^{2}+\\|w\\|_{\\Lambda_{0}}^{2}\\right]+M^{2}\\ln\\left|\\Lambda_{0}^{-1}\\Lambda_{T}\\right|,\n\\]\nwhere\n\\[\n\\Lambda_{T}=\\Lambda_{0}+\\sum_{s=1}^{T}\\psi(X_{s})\\psi(X_{s})^{\\top}.\n\\]", "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}], "nl_proof": "We can apply Theorem 15.6 by taking \\(\\sigma^2 = M^2\\). By using the following inequality\n\\[\n0\\leq\\frac{1-b_{t}}{b_{t}}+\\ln b_{t},\n\\]\nwe obtain\n\\[\n\\begin{array}{l}\\sum_{t=1}^{T}(Y_{t}-\\hat{Y}_{t})^{2}\\leq\\sum_{t=1}^{T}\\left[(Y_{t}-\\hat{Y}_{t})^{2}+M^{2}\\frac{1-b_{t}}{b_{t}}+M^{2}\\ln b_{t}\\right]\\\\ \\leq\\sum_{t=1}^{T}\\left[\\left(Y_{t}-\\hat{Y}_{t}\\right)^{2}+\\left(Y_{t}-\\hat{Y}_{t}\\right)^{2}\\frac{1-b_{t}}{b_{t}}+M^{2}\\ln b_{t}\\right]\\tag{15.5}\\\\ \\leq\\sum_{t=1}^{T}\\left[\\frac{(Y_{t}-\\hat{w}(\\mathcal{S}_{t-1})^{\\top}\\psi(X_{i}))^{2}}{b_{t}}+M^{2}\\ln b_{t}\\right],\\\\ \\end{array}\n\\]\nwhere \\( b_{t} \\) is defined in Theorem 15.6. Note that (15.5) used \\( 1 - b_{t} \\leq 0 \\) and \\( (Y_{t} - \\hat{Y}_{t})^{2} \\leq M^{2} \\). The desired result is now a direct application of Theorem 15.6.", "context": [{"id": "ch15:theorem:15_6", "name": "theorem 15.6", "statement": "Consider the ridge regression method of (15.3). We have the following result for any \\(\\sigma \\geq 0\\) and for all observed sequence \\(S_T\\):\n\\[\n\\begin{array}{l}\\sum_{t=1}^{T}\\left[\\frac{\\left(Y_{t}-\\hat{w}\\left(\\mathcal{S}_{t-1}\\right)^{\\top}\\psi\\left(X_{t}\\right)\\right)^{2}}{b_{t}}+\\sigma^{2}\\ln b_{t}\\right]\\\\ =\\inf_{w}\\left[\\sum_{t=1}^{T}\\left(Y_{t}-w^{\\top}\\psi\\left(X_{t}\\right)\\right)^{2}+\\|w\\|_{\\Lambda_{0}}^{2}\\right]+\\sigma^{2}\\ln\\left|\\Lambda_{0}^{-1}\\Lambda_{T}\\right|,\\\\ \\end{array}\n\\]\nwhere\n\\[\n\\Lambda_{t}=\\Lambda_{0}+\\sum_{s=1}^{t}\\psi(X_{s})\\psi(X_{s})^{\\top},\n\\]\nand \\(b_{t} = 1 + \\psi (X_{t})^{\\top}\\Lambda_{t - 1}^{-1}\\psi (X_{t}).\\)"}, {"id": "ch15:equation:15_3", "name": "equation (15.3)", "statement": "The ridge regression method defines, for each \\(n\\),\n\\[\n\\hat{w}(\\mathcal{S}_{n})=\\arg\\min_{w}\\left[\\sum_{i=1}^{n}(Y_{i}-w^{\\top}\\psi(X_{i}))^{2}+\\|w\\|_{\\Lambda_{0}}^{2}\\right].\n\\]\nEquivalently,\n\\[\n\\hat{w}(\\mathcal{S}_{n})=\\Lambda_{n}^{-1}\\sum_{i=1}^{n}\\psi(X_{i})Y_{i},\\quad\\Lambda_{n}=\\Lambda_{0}+\\sum_{s=1}^{n}\\psi(X_{s})\\psi(X_{s})^{\\top}.\n\\]"}, {"id": "ch15:definition:15_3", "name": "equation (15.3)", "statement": "Let \\(\\Lambda_0\\) be a symmetric positive definite regularizer and let \\(\\psi\\) be a feature map. Given \\(\\mathcal{S}_n = \\{(X_1,Y_1),\\ldots,(X_n,Y_n)\\}\\), define\n\\[\n\\hat{\\Lambda}(\\mathcal{S}_{n})=\\Lambda_{0}+\\sum_{i=1}^{n}\\psi(X_{i})\\psi(X_{i})^{\\top}\n\\]\nand the ridge regression estimator\n\\[\n\\hat{w}(\\mathcal{S}_{n})=\\hat{\\Lambda}(\\mathcal{S}_{n})^{-1}\\sum_{i=1}^{n}\\psi(X_{i})Y_{i}.\\tag{15.3}\n\\]\nEquivalently, \\(\\hat{w}(\\mathcal{S}_{n})\\) minimizes\n\\[\n\\sum_{i=1}^{n}(w^{\\top}\\psi(X_{i})-Y_{i})^{2}+\\|w\\|_{\\Lambda_{0}}^{2}.\n\\]"}], "lean": "import Mathlib\n\nopen Matrix\n\nnamespace GraduateLevel\n\ntheorem ch15_corollary_15_7\n {𝒳 : Type*} {d T : ℕ}\n (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (hΛ0 : Λ₀.PosDef)\n (ψ : 𝒳 → (Fin d → ℝ)) (X : ℕ → 𝒳) (Y : ℕ → ℝ)\n (M : ℝ) (hM : 0 ≤ M) (hYrange : ∀ t, 1 ≤ t → Y t ∈ Set.Icc 0 M)\n (Λ : ℕ → Matrix (Fin d) (Fin d) ℝ)\n (hΛ : ∀ n, Λ n = Λ₀ + ∑ s ∈ Finset.Icc 1 n, Matrix.vecMulVec (ψ (X s)) (ψ (X s)))\n (ŵ : ℕ → (Fin d → ℝ))\n (hŵ : ∀ n, ŵ n = (Λ n)⁻¹.mulVec (∑ i ∈ Finset.Icc 1 n, Y i • ψ (X i)))\n (Ŷ : ℕ → ℝ)\n (hŶ : ∀ t, Ŷ t = max 0 (min M ((ŵ (t - 1)) ⬝ᵥ (ψ (X t))))) :\n (∑ t ∈ Finset.Icc 1 T, (Y t - Ŷ t) ^ 2)\n ≤ (⨅ w : Fin d → ℝ,\n ((∑ t ∈ Finset.Icc 1 T, (Y t - (w ⬝ᵥ (ψ (X t)))) ^ 2)\n + (Λ₀.mulVec w) ⬝ᵥ w))\n + M ^ 2 * Real.log |(Λ₀⁻¹ * Λ T).det| := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen Matrix\n\nnamespace GraduateLevel\n\nprivate lemma symm_dot {d : ℕ} {A : Matrix (Fin d) (Fin d) ℝ} (hA : Aᵀ = A) (u v : Fin d → ℝ) :\n (A *ᵥ u) ⬝ᵥ v = u ⬝ᵥ (A *ᵥ v) := by\n rw [Matrix.dotProduct_mulVec, ← Matrix.mulVec_transpose, hA]\n\nprivate lemma quad_min {d : ℕ} {A : Matrix (Fin d) (Fin d) ℝ} (hA : A.PosDef) (b w : Fin d → ℝ) :\n - (b ⬝ᵥ (A⁻¹ *ᵥ b)) ≤ (A *ᵥ w) ⬝ᵥ w - 2 * (w ⬝ᵥ b) := by\n classical\n have hAU : IsUnit A.det := isUnit_iff_ne_zero.mpr hA.det_pos.ne'\n have hsym' : Aᵀ = A := by\n have := hA.isHermitian\n simpa [Matrix.IsHermitian, Matrix.conjTranspose, Matrix.transpose] using this.eq\n set q : Fin d → ℝ := A⁻¹ *ᵥ b with hq\n have hAq : A *ᵥ q = b := by\n rw [hq, Matrix.mulVec_mulVec]\n simp [Matrix.mul_nonsing_inv _ hAU]\n have hnn : 0 ≤ (w - q) ⬝ᵥ (A *ᵥ (w - q)) := by\n simpa using hA.posSemidef.dotProduct_mulVec_nonneg (w - q)\n have hexp : (w - q) ⬝ᵥ (A *ᵥ (w - q))\n = (A *ᵥ w) ⬝ᵥ w - 2 * (w ⬝ᵥ b) + b ⬝ᵥ (A⁻¹ *ᵥ b) := by\n have h1 : A *ᵥ (w - q) = A *ᵥ w - A *ᵥ q := by\n simp [Matrix.mulVec_sub]\n rw [h1, hAq]\n have h2 : (w - q) ⬝ᵥ (A *ᵥ w - b) = w ⬝ᵥ (A *ᵥ w) - w ⬝ᵥ b - q ⬝ᵥ (A *ᵥ w) + q ⬝ᵥ b := by\n simp [sub_dotProduct, dotProduct_sub]\n ring\n rw [h2]\n have h3 : q ⬝ᵥ (A *ᵥ w) = (A *ᵥ q) ⬝ᵥ w := (symm_dot hsym' q w).symm\n have h4 : w ⬝ᵥ (A *ᵥ w) = (A *ᵥ w) ⬝ᵥ w := (symm_dot hsym' w w).symm\n rw [h3, h4, hAq]\n have h5 : b ⬝ᵥ w = w ⬝ᵥ b := dotProduct_comm _ _\n rw [h5, hq, dotProduct_comm (A⁻¹ *ᵥ b) b]\n ring\n linarith [hexp ▸ hnn]\n\nprivate lemma det_rank_one_sub {d : ℕ} {B : Matrix (Fin d) (Fin d) ℝ} (hB : IsUnit B.det)\n (p : Fin d → ℝ) :\n (B - Matrix.vecMulVec p p).det = B.det * (1 - p ⬝ᵥ (B⁻¹ *ᵥ p)) := by\n classical\n set q : Fin d → ℝ := B⁻¹ *ᵥ p with hq\n have hBq : B *ᵥ q = p := by\n rw [hq, Matrix.mulVec_mulVec]\n simp [Matrix.mul_nonsing_inv _ hB]\n have hmul : B * Matrix.vecMulVec q p = Matrix.vecMulVec p p := by\n have : B * Matrix.vecMulVec q p = Matrix.vecMulVec (B *ᵥ q) p := by\n ext i j\n simp [Matrix.mul_apply, Matrix.vecMulVec_apply, Matrix.mulVec, dotProduct,\n Finset.sum_mul, mul_assoc]\n rw [this, hBq]\n have hfac : B - Matrix.vecMulVec p p = B * (1 - Matrix.vecMulVec q p) := by\n rw [Matrix.mul_sub, Matrix.mul_one, hmul]\n rw [hfac, Matrix.det_mul]\n congr 1\n have hrep : (1 : Matrix (Fin d) (Fin d) ℝ) - Matrix.vecMulVec q p\n = 1 + Matrix.replicateCol Unit (-q) * Matrix.replicateRow Unit p := by\n rw [← Matrix.vecMulVec_eq Unit]\n ext i j\n simp [Matrix.vecMulVec_apply]\n ring\n rw [hrep, Matrix.det_one_add_replicateCol_mul_replicateRow]\n rw [dotProduct_neg]\n ring\n\nprivate lemma clip_sq {y z M : ℝ} (hM : 0 ≤ M) (h0 : 0 ≤ y) (h1 : y ≤ M) :\n (y - max 0 (min M z)) ^ 2 ≤ (y - z) ^ 2 ∧ (y - max 0 (min M z)) ^ 2 ≤ M ^ 2 := by\n rcases le_total z 0 with h | h\n · have hmin : min M z = z := min_eq_right (le_trans h hM)\n have hmax : max 0 z = 0 := max_eq_left h\n rw [hmin, hmax]\n constructor <;> nlinarith\n · rcases le_total z M with h2 | h2\n · have hmin : min M z = z := min_eq_right h2\n have hmax : max 0 z = z := max_eq_right h\n rw [hmin, hmax]\n constructor <;> nlinarith\n · have hmin : min M z = M := min_eq_left h2\n have hmax : max 0 M = M := max_eq_right hM\n rw [hmin, hmax]\n constructor <;> nlinarith\n\ntheorem ch15_corollary_15_7\n {𝒳 : Type*} {d T : ℕ}\n (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (hΛ0 : Λ₀.PosDef)\n (ψ : 𝒳 → (Fin d → ℝ)) (X : ℕ → 𝒳) (Y : ℕ → ℝ)\n (M : ℝ) (hM : 0 ≤ M) (hYrange : ∀ t, 1 ≤ t → Y t ∈ Set.Icc 0 M)\n (Λ : ℕ → Matrix (Fin d) (Fin d) ℝ)\n (hΛ : ∀ n, Λ n = Λ₀ + ∑ s ∈ Finset.Icc 1 n, Matrix.vecMulVec (ψ (X s)) (ψ (X s)))\n (ŵ : ℕ → (Fin d → ℝ))\n (hŵ : ∀ n, ŵ n = (Λ n)⁻¹.mulVec (∑ i ∈ Finset.Icc 1 n, Y i • ψ (X i)))\n (Ŷ : ℕ → ℝ)\n (hŶ : ∀ t, Ŷ t = max 0 (min M ((ŵ (t - 1)) ⬝ᵥ (ψ (X t))))) :\n (∑ t ∈ Finset.Icc 1 T, (Y t - Ŷ t) ^ 2)\n ≤ (⨅ w : Fin d → ℝ,\n ((∑ t ∈ Finset.Icc 1 T, (Y t - (w ⬝ᵥ (ψ (X t)))) ^ 2)\n + (Λ₀.mulVec w) ⬝ᵥ w))\n + M ^ 2 * Real.log |(Λ₀⁻¹ * Λ T).det| := by\n classical\n set bb : ℕ → (Fin d → ℝ) := fun n => ∑ i ∈ Finset.Icc 1 n, Y i • ψ (X i) with hbb\n set cc : ℕ → ℝ := fun n => ∑ i ∈ Finset.Icc 1 n, (Y i) ^ 2 with hcc\n set V : ℕ → ℝ := fun n => cc n - (bb n) ⬝ᵥ ((Λ n)⁻¹ *ᵥ (bb n)) with hV\n -- basic structure\n have hΛ0eq : Λ 0 = Λ₀ := by rw [hΛ]; simp\n have hsucc : ∀ n, Λ (n + 1) = Λ n + Matrix.vecMulVec (ψ (X (n+1))) (ψ (X (n+1))) := by\n intro n\n rw [hΛ, hΛ, Finset.sum_Icc_succ_top (by omega)]\n abel\n have hpd : ∀ n, (Λ n).PosDef := by\n intro n\n induction n with\n | zero => rw [hΛ0eq]; exact hΛ0\n | succ k ih =>\n rw [hsucc k]\n refine ih.add_posSemidef ?_\n simpa using Matrix.posSemidef_vecMulVec_self_star (ψ (X (k+1)))\n have hsym : ∀ n, (Λ n)ᵀ = Λ n := by\n intro n\n have := (hpd n).isHermitian\n simpa [Matrix.IsHermitian, Matrix.conjTranspose, Matrix.transpose] using this.eq\n have hdetpos : ∀ n, 0 < (Λ n).det := fun n => (hpd n).det_pos\n have hIU : ∀ n, IsUnit (Λ n).det := fun n => isUnit_iff_ne_zero.mpr (hdetpos n).ne'\n have hbbsucc : ∀ n, bb (n+1) = bb n + Y (n+1) • ψ (X (n+1)) := by\n intro n\n simp only [hbb]\n rw [Finset.sum_Icc_succ_top (by omega)]\n have hccsucc : ∀ n, cc (n+1) = cc n + (Y (n+1)) ^ 2 := by\n intro n\n simp only [hcc]\n rw [Finset.sum_Icc_succ_top (by omega)]\n -- gamma\n set γ : ℕ → ℝ := fun n => (ψ (X (n+1))) ⬝ᵥ ((Λ (n+1))⁻¹ *ᵥ (ψ (X (n+1)))) with hγ\n have hγnn : ∀ n, 0 ≤ γ n := by\n intro n\n simpa [hγ] using (hpd (n+1)).inv.posSemidef.dotProduct_mulVec_nonneg (ψ (X (n+1)))\n have hdetstep : ∀ n, (Λ n).det = (Λ (n+1)).det * (1 - γ n) := by\n intro n\n have h := det_rank_one_sub (hIU (n+1)) (ψ (X (n+1)))\n have h2 : Λ (n+1) - Matrix.vecMulVec (ψ (X (n+1))) (ψ (X (n+1))) = Λ n := by\n rw [hsucc n]; abel\n rw [h2] at h\n exact h\n have hβpos : ∀ n, 0 < 1 - γ n := by\n intro n\n have h := hdetstep n\n nlinarith [hdetpos n, hdetpos (n+1)]\n -- the key algebraic step\n have hstep : ∀ n, V (n+1) - V n\n = (Y (n+1) - (ŵ n) ⬝ᵥ (ψ (X (n+1)))) ^ 2 * (1 - γ n) := by\n intro n\n set p := ψ (X (n+1)) with hp\n set A := Λ n with hA\n set Bm := Λ (n+1) with hBm\n set w := ŵ n with hw\n have hwdef : w = A⁻¹ *ᵥ bb n := by rw [hw, hŵ]\n have hAw : A *ᵥ w = bb n := by\n rw [hwdef, Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ (hIU n), Matrix.one_mulVec]\n have hBmw : Bm *ᵥ w = bb n + (p ⬝ᵥ w) • p := by\n rw [hBm, hsucc n, Matrix.add_mulVec, ← hA, hAw]\n congr 1\n ext i\n simp only [Matrix.mulVec, Matrix.vecMulVec_apply, dotProduct, Pi.smul_apply, smul_eq_mul,\n Finset.sum_mul]\n exact Finset.sum_congr rfl (fun j _ => by ring)\n set r := Y (n+1) - w ⬝ᵥ p with hr\n have hpw : p ⬝ᵥ w = w ⬝ᵥ p := dotProduct_comm _ _\n have hbb1 : bb (n+1) = Bm *ᵥ w + r • p := by\n rw [hbbsucc n, hBmw, hr, hpw]\n ext i\n simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul]\n ring\n have hinv : Bm⁻¹ *ᵥ (Bm *ᵥ w) = w := by\n rw [Matrix.mulVec_mulVec, Matrix.nonsing_inv_mul _ (hIU (n+1)), Matrix.one_mulVec]\n have hexp : (bb (n+1)) ⬝ᵥ (Bm⁻¹ *ᵥ (bb (n+1)))\n = (A *ᵥ w) ⬝ᵥ w + (w ⬝ᵥ p) ^ 2 + 2 * r * (w ⬝ᵥ p) + r ^ 2 * γ n := by\n rw [hbb1]\n rw [Matrix.mulVec_add, Matrix.mulVec_smul, hinv]\n rw [add_dotProduct, dotProduct_add, dotProduct_add,\n smul_dotProduct, dotProduct_smul, dotProduct_smul,\n smul_dotProduct]\n have e1 : (Bm *ᵥ w) ⬝ᵥ w = (A *ᵥ w) ⬝ᵥ w + (p ⬝ᵥ w) * (p ⬝ᵥ w) := by\n rw [hBmw, add_dotProduct, smul_dotProduct, hAw, smul_eq_mul]\n have e2 : (Bm *ᵥ w) ⬝ᵥ (Bm⁻¹ *ᵥ p) = w ⬝ᵥ p := by\n rw [symm_dot (hsym (n+1)) w (Bm⁻¹ *ᵥ p), Matrix.mulVec_mulVec,\n Matrix.mul_nonsing_inv _ (hIU (n+1)), Matrix.one_mulVec]\n have e3 : p ⬝ᵥ w = w ⬝ᵥ p := hpw\n have e4 : p ⬝ᵥ (Bm⁻¹ *ᵥ p) = γ n := rfl\n rw [e1, e2, e3, e4]\n simp only [smul_eq_mul]\n ring\n have hV0 : (bb n) ⬝ᵥ ((Λ n)⁻¹ *ᵥ (bb n)) = (A *ᵥ w) ⬝ᵥ w := by\n rw [← hwdef]\n conv_lhs => rw [← hAw]\n simp only [hV]\n rw [hccsucc n, hexp, hV0]\n rw [hr]\n have : w ⬝ᵥ p = w ⬝ᵥ p := rfl\n ring\n -- per-step inequality\n have hper : ∀ n, (Y (n+1) - Ŷ (n+1)) ^ 2\n ≤ (V (n+1) - V n) + M ^ 2 * (Real.log ((Λ (n+1)).det) - Real.log ((Λ n).det)) := by\n intro n\n have hY := hYrange (n+1) (by omega)\n obtain ⟨hY0, hY1⟩ := hY\n have hŶeq : Ŷ (n+1) = max 0 (min M ((ŵ n) ⬝ᵥ (ψ (X (n+1))))) := by\n rw [hŶ]; norm_num\n obtain ⟨hc1, hc2⟩ := clip_sq (z := (ŵ n) ⬝ᵥ (ψ (X (n+1)))) hM hY0 hY1\n rw [hŶeq]\n set e := (Y (n+1) - max 0 (min M ((ŵ n) ⬝ᵥ (ψ (X (n+1)))))) ^ 2 with he\n set r := (Y (n+1) - (ŵ n) ⬝ᵥ (ψ (X (n+1)))) ^ 2 with hrr\n set β := 1 - γ n with hβ\n have hβp : 0 < β := hβpos n\n have hβ1 : β ≤ 1 := by have hg := hγnn n; simp only [hβ]; linarith\n have hlog : Real.log ((Λ (n+1)).det) - Real.log ((Λ n).det) = - Real.log β := by\n rw [hdetstep n, Real.log_mul (ne_of_gt (hdetpos (n+1))) (ne_of_gt hβp)]\n ring\n rw [hstep n, hlog]\n have hlb : Real.log β ≤ β - 1 := Real.log_le_sub_one_of_pos hβp\n have hMsq : 0 ≤ M ^ 2 := by positivity\n have h1 : e * β ≤ r * β := by nlinarith\n nlinarith [hc2, hMsq, hlb, hβp]\n -- telescoping\n have hmain : ∀ n, (∑ t ∈ Finset.Icc 1 n, (Y t - Ŷ t) ^ 2)\n ≤ V n + M ^ 2 * (Real.log ((Λ n).det) - Real.log ((Λ 0).det)) := by\n intro n\n induction n with\n | zero =>\n simp only [hV, hcc, hbb]\n simp\n | succ k ih =>\n rw [Finset.sum_Icc_succ_top (by omega)]\n have := hper k\n linarith\n -- V T ≤ inf\n have hVinf : V T ≤ (⨅ w : Fin d → ℝ,\n ((∑ t ∈ Finset.Icc 1 T, (Y t - (w ⬝ᵥ (ψ (X t)))) ^ 2) + (Λ₀.mulVec w) ⬝ᵥ w)) := by\n refine le_ciInf ?_\n intro w\n have hquad : (∑ t ∈ Finset.Icc 1 T, (Y t - (w ⬝ᵥ (ψ (X t)))) ^ 2) + (Λ₀.mulVec w) ⬝ᵥ w\n = ((Λ T) *ᵥ w) ⬝ᵥ w - 2 * (w ⬝ᵥ (bb T)) + cc T := by\n have hexpand : ∀ t, (Y t - (w ⬝ᵥ (ψ (X t)))) ^ 2\n = (Y t) ^ 2 - 2 * (Y t * (w ⬝ᵥ ψ (X t)))\n + ((Matrix.vecMulVec (ψ (X t)) (ψ (X t))) *ᵥ w) ⬝ᵥ w := by\n intro t\n rw [Matrix.vecMulVec_mulVec, smul_dotProduct]\n have : (ψ (X t)) ⬝ᵥ w = w ⬝ᵥ (ψ (X t)) := dotProduct_comm _ _\n rw [this]\n simp [smul_eq_mul]\n ring\n rw [Finset.sum_congr rfl (fun t _ => hexpand t)]\n rw [Finset.sum_add_distrib, Finset.sum_sub_distrib]\n have hs1 : ∑ t ∈ Finset.Icc 1 T,\n ((Matrix.vecMulVec (ψ (X t)) (ψ (X t))) *ᵥ w) ⬝ᵥ w\n = ((∑ t ∈ Finset.Icc 1 T, Matrix.vecMulVec (ψ (X t)) (ψ (X t))) *ᵥ w) ⬝ᵥ w := by\n rw [Matrix.sum_mulVec, sum_dotProduct]\n have hs2 : ∑ t ∈ Finset.Icc 1 T, 2 * (Y t * (w ⬝ᵥ ψ (X t))) = 2 * (w ⬝ᵥ (bb T)) := by\n rw [← Finset.mul_sum]\n congr 1\n rw [hbb]\n rw [dotProduct_sum]\n refine Finset.sum_congr rfl (fun t _ => ?_)\n rw [dotProduct_smul]\n simp [smul_eq_mul]\n rw [hs1, hs2]\n rw [hΛ T, Matrix.add_mulVec, add_dotProduct]\n simp only [hcc]\n ring\n rw [hquad]\n have := quad_min (hpd T) (bb T) w\n simp only [hV]\n linarith\n -- final log identity\n have hlogfin : Real.log |(Λ₀⁻¹ * Λ T).det| = Real.log ((Λ T).det) - Real.log ((Λ 0).det) := by\n rw [Matrix.det_mul]\n rw [Matrix.det_nonsing_inv]\n have h0 : (0:ℝ) < Λ₀.det := hΛ0eq ▸ hdetpos 0\n have hT : (0:ℝ) < (Λ T).det := hdetpos T\n rw [Ring.inverse_eq_inv]\n have : |Λ₀.det⁻¹ * (Λ T).det| = Λ₀.det⁻¹ * (Λ T).det := by\n rw [abs_of_pos]; positivity\n rw [this, Real.log_mul (by positivity) (by positivity), Real.log_inv, hΛ0eq]\n ring\n have := hmain T\n rw [hlogfin]\n linarith [hVinf]\n\nend GraduateLevel\n"} +{"id": "ch16_theorem_16_17", "source": "Graduate-level", "targets": [{"label": "ch16_theorem_16_17", "decls": ["ch16_theorem_16_17"], "statement": "Consider Algorithm 16.5. Let \\( G_{*} = \\max_{a}\\sum_{t = 1}^{T}r_{t}(a) \\). We have the following bound for the adversarial regret (16.1):\n\\[\n\\mathrm{REG}_{T}\\leq(e-1)\\gamma G_{*}+\\frac{K\\ln K}{\\gamma}.\n\\]", "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}], "nl_proof": "We have\n\\[\n\\sum_{a=1}^{K}\\hat{\\pi}_{t}(a)\\hat{r}_{t}(a,a_{t})=r_{t}(a_{t}),\\tag{16.9}\n\\]\n\\[\n\\sum_{a=1}^{K}\\hat{\\pi}_{t}(a)\\hat{r}_{t}\\left(a,a_{t}\\right)^{2}=\\hat{r}_{t}\\left(a_{t},a_{t}\\right)r_{t}\\left(a_{t}\\right)\\leq\\hat{r}_{t}\\left(a_{t},a_{t}\\right).\\tag{16.10}\n\\]\nIt follows that for all \\(t \\geq 1\\):\n\\[\n\\begin{array}{l}\\frac{w_{t}}{w_{t-1}}=\\sum_{a=1}^{K}\\frac{w_{t}(a)}{w_{t-1}}=\\sum_{a=1}^{K}\\frac{w_{t-1}(a)}{w_{t-1}}\\exp(\\gamma\\hat{r}_{t}(a,a_{t})/K)\\\\ =\\sum_{a=1}^{K}\\frac{\\hat{\\pi}_{t}(a)-\\gamma/K}{1-\\gamma}\\exp\\left(\\gamma\\hat{r}_{t}\\left(a,a_{t}\\right)/K\\right)\\quad \\text{(d e f i n i t i o n o f}\\hat{\\pi}_{t}(a))\\\\ \\stackrel{(a)}{\\leq}\\sum_{a=1}^{K}\\frac{\\hat{\\pi}_{t}(a)-\\gamma/K}{1-\\gamma}\\left[1+\\gamma\\hat{r}_{t}(a,a_{t})/K+(e-2)(\\gamma\\hat{r}_{t}(a,a_{t})/K)^{2}\\right]\\\\ \\leq 1+\\frac{1}{1-\\gamma}\\left[\\sum_{a=1}^{K}\\hat{\\pi}_{t}(a)\\gamma\\hat{r}_{t}(a,a_{t})/K+\\sum_{a=1}^{K}\\hat{\\pi}_{t}(a)(e-2)(\\gamma\\hat{r}_{t}(a,a_{t})/K)^{2}\\right]\\\\ \\stackrel{(b)}{\\leq}1+\\frac{\\gamma/K}{1-\\gamma}r_{t}(a_{t})+\\frac{(e-2)(\\gamma/K)^{2}}{1-\\gamma}\\hat{r}_{t}(a_{t},a_{t}).\\\\ \\end{array}\n\\]\nIn \\((a)\\), we used \\(\\exp(z) \\leq 1 + z + (e - 2)z^2\\) when \\(z \\leq 1\\), and \\(\\gamma \\hat{r}_t(a, a_t) / K \\leq 1\\). In \\((b)\\), we used (16.9) and (16.10).\nTherefore\n\\[\n\\begin{array}{l}\\ln\\frac{w_{t}}{w_{t-1}}\\leq\\ln\\left(1+\\frac{\\gamma/K}{1-\\gamma}r_{t}(a_{t})+\\frac{(e-2)(\\gamma/K)^{2}}{1-\\gamma}\\hat{r}_{t}(a_{t},a_{t})\\right)\\\\ \\leq\\frac{\\gamma/K}{1-\\gamma}r_{t}(a_{t})+\\frac{(e-2)(\\gamma/K)^{2}}{1-\\gamma}\\hat{r}_{t}(a_{t},a_{t}).\\\\ \\end{array}\n\\]\nThe second inequality follows from \\(\\ln (1 + z) \\leq z\\).\nNow, by summing over \\(t\\), and let\n\\[\nG_{T}=\\sum_{t=1}^{T}r_{t}(a_{t}),\n\\]\nwe obtain\n\\[\n'\\ln\\frac{w_{T}}{w_{0}}\\leq\\frac{\\gamma/K}{1-\\gamma}G_{T}+\\frac{(e-2)(\\gamma/K)^{2}}{1-\\gamma}\\sum_{t=1}^{T}\\sum_{a=1}^{K}\\hat{r}_{t}(a,a_{t}),\n\\]\nwhere we used \\(\\hat{r}_t(a_t, a_t) = \\sum_{a=1}^{K} \\hat{r}_t(a, a_t)\\). Note that for all \\(a'\\):\n\\[\n\\ln\\frac{w_{T}}{w_{0}}\\geq\\ln\\frac{w_{T}(a^{\\prime})}{w_{0}}=\\frac{\\gamma}{K}\\sum_{t=1}^{T}\\hat{r}_{t}(a^{\\prime},a_{t})-\\ln K.\n\\]\nIt follows that\n\\[\n\\frac{\\gamma}{K}\\sum_{t=1}^{T}\\hat{r}_{t}(a^{\\prime},a_{t})\\leq\\frac{\\gamma/K}{1-\\gamma}G_{T}+\\frac{(e-2)(\\gamma/K)^{2}}{1-\\gamma}\\sum_{t=1}^{T}\\sum_{a=1}^{K}\\hat{r}_{t}(a,a_{t})+\\ln K.\n\\]\nObserve that conditioned on the history,\n\\[\n\\mathbb{E}_{a_{t}\\sim\\hat{\\pi}_{t}}\\hat{r}_{t}(a,a_{t})=r_{t}(a).\n\\]\nWe obtain the following bound by taking expectation:\n\\[\n\\begin{array}{l}\\mathbb{E}\\frac{\\gamma}{K}\\sum_{t=1}^{T}r_{t}(a^{\\prime})\\leq\\frac{\\gamma/K}{1-\\gamma}\\mathbb{E}G_{T}+\\frac{(e-2)(\\gamma/K)^{2}}{1-\\gamma}\\mathbb{E}\\sum_{t=1}^{T}\\sum_{a=1}^{K}r_{t}(a)+\\ln K\\\\ \\leq\\frac{\\gamma/K}{1-\\gamma}\\mathbb{E}G_{T}+\\frac{(e-2)(\\gamma/K)^{2}}{1-\\gamma}K G_{*}+\\ln K.\\\\ \\end{array}\n\\]\nLet \\(a^\\prime\\) be the optimal arm, and rearrange, we obtain\n\\[\nG_{*}\\leq\\frac{1}{1-\\gamma}\\mathbb{E}G_{T}+\\frac{(e-2)\\gamma}{(1-\\gamma)}G_{*}+\\frac{K}{\\gamma}\\ln K.\n\\]\nThis implies the desired result.", "context": [{"id": "ch16:algorithm:16_5", "name": "EXP3", "statement": "Algorithm 16.5: EXP3\nInput: \\(K, T, \\gamma \\in (0,1]\\) \nfor \\(a = 1, \\ldots, K\\) do \n\\(\\begin{array}{r}\\lfloor \\mathrm{Let}w_0(a) = 1 \\end{array}\\) \nfor \\(t = 1,2,\\dots,T\\) do \n\\(\\begin{array}{rl}&{\\mathrm{Let}w_{t-1}=\\sum_{a=1}^{K}w_{t-1}(a)}\\\\ &{\\mathrm{for}a=1,\\ldots,K\\mathrm{do}}\\\\ &{\\mathrm{Let}\\hat{\\pi}_t(a)=(1-\\gamma)w_{t-1}(a)/w_{t-1}+\\gamma/K}\\\\ &{\\mathrm{Sample}a_t\\mathrm{according to}\\hat{\\pi}_t(\\cdot)}\\\\ &{\\mathrm{Pull}\\mathrm{arm}a_t\\mathrm{and observe reward}r_t(a_t)\\in [0,1]}\\\\ &{\\mathrm{for}a=1,\\ldots,K\\mathrm{do}}\\\\ &{\\mathrm{Let}\\hat{r}_t(a,a_t)=r_t(a_t)\\mathbb{1}(a=a_t)/\\hat{\\pi}_t(a_t)}\\\\ &{\\mathrm{Let}w_t(a)=w_{t-1}(a)\\exp(\\gamma\\hat{r}_t(a,a_t)/K)}\\end{array}\\)"}, {"id": "ch16:definition:16_1", "name": "definition 16.1", "statement": "In the multi-armed bandit (or MAB) problem, we consider \\(K\\) arms. The environment generates a sequence of reward vectors for time steps \\(t \\geq 1\\) as \\(r_t = [r_t(1), \\ldots, r_t(K)]\\). Each \\(r_t(a)\\) is associated with an arm \\(a \\in \\{1, \\ldots, K\\}\\). In the literature, an arm \\(a\\) is also referred to as an action. At each time step \\(t = 1, 2, \\ldots, T\\),\n- The player pulls one of the arms \\( a_{t} \\in \\{1, \\dots, K\\} \\).\n- The environment returns the reward \\( r_t(a_t) \\), but does not reveal information on any other arm \\( a \\neq a_t \\).\nAt each time \\( t \\), a (randomized) bandit algorithm takes the historic observations observed so far, and maps it to a distribution \\( \\hat{\\pi}_{t-1} \\) over actions \\( a \\in \\{1, \\ldots, K\\} \\). We then draw a random action \\( a_t \\) (arm) from \\( \\hat{\\pi}_{t-1} \\). Here \\( \\hat{\\pi}_{t-1} \\) is referred to as policy.\nIn the adversarial bandit problem, we are given an arbitrary reward sequence \\(\\{[r_1(1),\\ldots,r_t(K)]:t\\geq 1\\}\\) before hand. The adversary in this setting is called oblivious, who decides the rewards of all the rounds before the game starts (but may take advantage of the bandit algorithm's weakness). For this reward se\nquence, the expected cumulative reward of a randomized bandit algorithm is\n\\[\n\\mathbb{E}\\sum_{t=1}^{T}r_{t}(a_{t}),\n\\]\nwhere the randomization is over the internal randomization of the bandit algorithm. The expected regret is defined as\n\\[\n\\operatorname{REG}_{T}=\\max_{a}\\sum_{t=1}^{T}r_{t}(a)-\\mathbb{E}\\sum_{t=1}^{T}r_{t}\\left(a_{t}\\right).\\tag{16.1}\n\\]\nIf the bandit algorithm is deterministic: i.e. pulling a single arm \\(a_{t}\\) only at any time step, then the regret is\n\\[\n\\mathrm{REG}_{T}=\\max_{a}\\sum_{t=1}^{T}r_{t}(a)-\\sum_{t=1}^{T}r_{t}(a_{t}).\n\\]\nIn the adversarial bandit problem, our goal is to minimize the expected regret \\(\\mathrm{REG}_T\\) (and the expectation is with respect to the internal randomization of the algorithm instead of the data).\nAnother form of bandit problem, called stochastic bandit, assumes that the reward \\( r_t(a) \\) is drawn independently from a distribution \\( \\mathcal{D}_a \\), with mean \\( \\mu(a) = \\mathbb{E}_{r_t(a) \\sim \\mathcal{D}_a} [r_t(a)] \\). In this setting, the goal of bandit is to find \\( a \\) that maximizes the expected reward \\( \\mu(a) \\). We are interested in the expected regret defined as:\n\\[\n\\operatorname{REG}_{T}=T\\max_{a}\\mu(a)-\\mathbb{E}\\sum_{t=1}^{T}\\mu\\left(a_{t}\\right).\\tag{16.2}\n\\]\nAgain, this regret is defined for each realization of the stochastic rewards, and the expectation is with respect to the randomness of the algorithm. If algorithm is deterministic and outputs \\( a_{t} \\) at each time \\( t \\), then\n\\[\n\\mathrm{REG}_{T}=T\\max_{a}\\mu(a)-\\sum_{t=1}^{T}\\mu(a_{t}).\n\\]\nWe can further include randomization over data into the regret of stochastic bandit, by considering expected regret as follows:\n\\[\n\\mathbb{E}\\operatorname{REG}_{T}=T\\max_{a}\\mu(a)-\\mathbb{E}\\sum_{t=1}^{T}\\mu(a_{t}),\n\\]\nwhere the expectation is with respect to both the data and the internal randomization of the learning algorithm."}], "lean": "import Mathlib\n\nopen MeasureTheory\nopen scoped MeasureTheory\n\nnamespace GraduateLevel\n\ndef bestArmReward {K T : ℕ} (hK : 1 ≤ K) (r : Fin T → Fin K → ℝ) : ℝ :=\n haveI : Nonempty (Fin K) := ⟨⟨0, by omega⟩⟩\n (Finset.univ : Finset (Fin K)).sup' Finset.univ_nonempty (fun a => ∑ t : Fin T, r t a)\n\ntheorem ch16_theorem_16_17\n {K T : ℕ} (hK : 1 ≤ K) (γ : ℝ) (hγ : 0 < γ) (hγ1 : γ ≤ 1)\n (r : Fin T → Fin K → ℝ) (hr : ∀ t a, r t a ∈ Set.Icc (0 : ℝ) 1)\n {Ω : Type*} {m0 : MeasurableSpace Ω} (μ : @Measure Ω m0) [IsProbabilityMeasure μ]\n (w : Fin (T + 1) → Ω → Fin K → ℝ) (pol : Fin T → Ω → Fin K → ℝ)\n (a' : Fin T → Ω → Fin K) (rhat : Fin T → Ω → Fin K → ℝ)\n (ha'meas : ∀ t, Measurable (a' t)) (hw0 : ∀ ω a, w 0 ω a = 1)\n (hwnonneg : ∀ (t : Fin (T + 1)) ω a, 0 ≤ w t ω a)\n (hwpos : ∀ (t : Fin T) ω, 0 < ∑ b : Fin K, w t.castSucc ω b)\n (hpol : ∀ (t : Fin T) ω a, pol t ω a = (1 - γ) * (w t.castSucc ω a / ∑ b : Fin K, w t.castSucc ω b) + γ / K)\n (hpolpos : ∀ (t : Fin T) ω a, 0 < pol t ω a)\n (hrhat : ∀ (t : Fin T) ω a, rhat t ω a = if a = a' t ω then r t (a' t ω) / pol t ω (a' t ω) else 0)\n (hwupd : ∀ (t : Fin T) ω a, w t.succ ω a = w t.castSucc ω a * Real.exp (γ * rhat t ω a / K))\n (ℱ : Fin T → MeasurableSpace Ω)\n (hℱ : ∀ t, ℱ t ≤ m0)\n (ha'adapted : ∀ (s t : Fin T), s < t → Measurable[ℱ t] (a' s))\n (hpol_meas : ∀ (t : Fin T) (a : Fin K), Measurable[ℱ t] (fun ω => pol t ω a))\n (hsample : ∀ (t : Fin T) (a : Fin K),\n μ[(fun ω => if a' t ω = a then (1 : ℝ) else 0) | ℱ t]\n =ᵐ[μ] fun ω => pol t ω a)\n (hint_rhat : ∀ (t : Fin T) (a : Fin K), Integrable (fun ω => rhat t ω a) μ)\n (hint_rew : Integrable (fun ω => ∑ t : Fin T, r t (a' t ω)) μ)\n (REG : ℝ) (hREG : REG = bestArmReward hK r - ∫ ω, ∑ t : Fin T, r t (a' t ω) ∂μ) :\n REG ≤ (Real.exp 1 - 1) * γ * bestArmReward hK r + (K * Real.log K) / γ := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory\nopen scoped MeasureTheory\n\nnamespace GraduateLevel\n\ndef bestArmReward {K T : ℕ} (hK : 1 ≤ K) (r : Fin T → Fin K → ℝ) : ℝ :=\n haveI : Nonempty (Fin K) := ⟨⟨0, by omega⟩⟩\n (Finset.univ : Finset (Fin K)).sup' Finset.univ_nonempty (fun a => ∑ t : Fin T, r t a)\n\nprivate theorem expser (x : ℝ) : Real.exp x = ∑' n : ℕ, x ^ n / (Nat.factorial n) := by\n rw [Real.exp_eq_exp_ℝ, NormedSpace.exp_eq_tsum_div]\n\nprivate theorem exp_quad (z : ℝ) (h0 : 0 ≤ z) (h1 : z ≤ 1) :\n Real.exp z ≤ 1 + z + (Real.exp 1 - 2) * z ^ 2 := by\n have hs : ∀ y : ℝ, Summable (fun n : ℕ => y ^ n / (Nat.factorial n)) :=\n Real.summable_pow_div_factorial\n have hs2 : ∀ y : ℝ, Summable (fun n : ℕ => y ^ (n + 2) / (Nat.factorial (n + 2))) := by\n intro y\n exact (summable_nat_add_iff 2).2 (hs y)\n have hsplit : ∀ y : ℝ, Real.exp y = 1 + y + ∑' n : ℕ, y ^ (n + 2) / (Nat.factorial (n + 2)) := by\n intro y\n rw [expser y, (hs y).tsum_eq_zero_add, ((summable_nat_add_iff 1).2 (hs y)).tsum_eq_zero_add]\n push_cast\n ring\n rw [hsplit z, hsplit 1]\n have hle : ∑' n : ℕ, z ^ (n + 2) / (Nat.factorial (n + 2))\n ≤ ∑' n : ℕ, z ^ 2 * ((1 : ℝ) ^ (n + 2) / (Nat.factorial (n + 2))) := by\n apply Summable.tsum_le_tsum _ (hs2 z) ((hs2 1).mul_left _)\n intro n\n have hzz : z ^ (n + 2) ≤ z ^ 2 := by\n calc z ^ (n + 2) = z ^ 2 * z ^ n := by ring\n _ ≤ z ^ 2 * 1 := by\n apply mul_le_mul_of_nonneg_left (pow_le_one₀ h0 h1) (by positivity)\n _ = z ^ 2 := by ring\n rw [one_pow]\n rw [div_le_iff₀ (by positivity)]\n rw [mul_comm (z ^ 2)]\n rw [div_mul_eq_mul_div, mul_comm, mul_div_assoc]\n field_simp\n linarith [hzz]\n rw [tsum_mul_left] at hle\n have hh : (1 : ℝ) + 1 + ∑' n : ℕ, (1 : ℝ) ^ (n + 2) / (Nat.factorial (n + 2)) = Real.exp 1 :=\n (hsplit 1).symm\n nlinarith [hle, hh]\n\nprivate theorem tele : ∀ {T : ℕ} (L : Fin (T + 1) → ℝ),\n ∑ t : Fin T, (L t.succ - L t.castSucc) = L (Fin.last T) - L 0 := by\n intro T\n induction T with\n | zero => intro L; simp\n | succ n ih =>\n intro L\n rw [Fin.sum_univ_castSucc]\n have h := ih (fun i => L i.castSucc)\n rw [show (∑ i : Fin n, (L (Fin.castSucc i).succ - L (Fin.castSucc i).castSucc))\n = ∑ i : Fin n, ((fun j : Fin (n+1) => L j.castSucc) i.succ\n - (fun j : Fin (n+1) => L j.castSucc) i.castSucc) from by\n apply Finset.sum_congr rfl; intro i _; rw [Fin.succ_castSucc]]\n rw [h]\n simp [Fin.succ_last]\n\nprivate theorem one_step {K : ℕ} (hK : 1 ≤ K) (γ : ℝ) (hγ : 0 < γ) (hγ1 : γ < 1)\n (v v' p rh : Fin K → ℝ) (b : Fin K) (rv : ℝ)\n (hvnonneg : ∀ a, 0 ≤ v a) (hVpos : 0 < ∑ a, v a)\n (hp : ∀ a, p a = (1 - γ) * (v a / ∑ c, v c) + γ / K)\n (hrh : ∀ a, rh a = if a = b then rv / p b else 0)\n (hrv0 : 0 ≤ rv) (hrv1 : rv ≤ 1)\n (hv' : ∀ a, v' a = v a * Real.exp (γ * rh a / K)) :\n Real.log (∑ a, v' a) - Real.log (∑ a, v a)\n ≤ (γ / K) / (1 - γ) * rv + (Real.exp 1 - 2) * (γ / K) ^ 2 / (1 - γ) * (∑ a, rh a) := by\n have hK0 : (0 : ℝ) < K := by exact_mod_cast hK\n have hD : 0 < 1 - γ := by linarith\n have hpge : ∀ a, γ / K ≤ p a := by\n intro a\n rw [hp a]\n have h1 : 0 ≤ (1 - γ) * (v a / ∑ c, v c) :=\n mul_nonneg (by linarith) (div_nonneg (hvnonneg a) hVpos.le)\n linarith\n have hppos : ∀ a, 0 < p a := fun a => lt_of_lt_of_le (by positivity) (hpge a)\n have hrhnn : ∀ a, 0 ≤ rh a := by\n intro a\n rw [hrh a]\n split\n · exact div_nonneg hrv0 (hppos b).le\n · exact le_refl 0\n have hrhle : ∀ a, γ * rh a / K ≤ 1 := by\n intro a\n have h1 : rh a ≤ K / γ := by\n rw [hrh a]\n split\n · rw [div_le_div_iff₀ (hppos b) hγ]\n have hb1 : (K:ℝ) * (γ / K) ≤ (K:ℝ) * p b := mul_le_mul_of_nonneg_left (hpge b) hK0.le\n have hb2 : (K:ℝ) * (γ / K) = γ := by field_simp\n nlinarith [hb1, hb2, hγ, hrv1]\n · positivity\n rw [div_le_one hK0]\n have h3 : γ * ((K:ℝ)/γ) = (K:ℝ) := by field_simp\n nlinarith [mul_le_mul_of_nonneg_left h1 hγ.le, h3]\n have hpb : p b ≠ 0 := (hppos b).ne'\n have hsum1 : ∑ a, p a * rh a = rv := by\n rw [Finset.sum_eq_single b]\n · rw [hrh b, if_pos rfl]\n field_simp\n · intro c _ hc\n rw [hrh c, if_neg hc]\n ring\n · intro h\n exact absurd (Finset.mem_univ b) h\n have hsumrh : ∑ a, rh a = rv / p b := by\n rw [Finset.sum_eq_single b]\n · rw [hrh b, if_pos rfl]\n · intro c _ hc\n rw [hrh c, if_neg hc]\n · intro h\n exact absurd (Finset.mem_univ b) h\n have hsum2 : ∑ a, p a * (rh a) ^ 2 = rv * (rv / p b) := by\n rw [Finset.sum_eq_single b]\n · rw [hrh b, if_pos rfl]\n field_simp\n · intro c _ hc\n rw [hrh c, if_neg hc]\n ring\n · intro h\n exact absurd (Finset.mem_univ b) h\n have hvle : ∀ a, v a ≤ ((∑ c, v c) / (1 - γ)) * p a := by\n intro a\n rw [hp a]\n have h1 : ((∑ c, v c) / (1 - γ)) * ((1 - γ) * (v a / ∑ c, v c) + γ / K)\n = v a + ((∑ c, v c) / (1 - γ)) * (γ / K) := by\n field_simp\n rw [h1]\n have h2 : 0 ≤ ((∑ c, v c) / (1 - γ)) * (γ / K) :=\n mul_nonneg (div_nonneg hVpos.le hD.le) (by positivity)\n linarith\n have he2 : (0 : ℝ) < Real.exp 1 - 2 := by nlinarith [Real.exp_one_gt_d9]\n have b1 : ∑ a, v a * (γ * rh a / K) ≤ ((∑ c, v c) / (1 - γ)) * ((γ / K) * rv) := by\n calc ∑ a, v a * (γ * rh a / K)\n ≤ ∑ a, (((∑ c, v c) / (1 - γ)) * p a) * (γ * rh a / K) := by\n apply Finset.sum_le_sum\n intro a _\n apply mul_le_mul_of_nonneg_right (hvle a)\n have := hrhnn a\n positivity\n _ = ((∑ c, v c) / (1 - γ)) * ((γ / K) * (∑ a, p a * rh a)) := by\n rw [Finset.mul_sum, Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro a _\n field_simp\n _ = ((∑ c, v c) / (1 - γ)) * ((γ / K) * rv) := by rw [hsum1]\n have b2 : ∑ a, v a * (γ * rh a / K) ^ 2\n ≤ ((∑ c, v c) / (1 - γ)) * ((γ / K) ^ 2 * (∑ a, rh a)) := by\n calc ∑ a, v a * (γ * rh a / K) ^ 2\n ≤ ∑ a, (((∑ c, v c) / (1 - γ)) * p a) * (γ * rh a / K) ^ 2 := by\n apply Finset.sum_le_sum\n intro a _\n apply mul_le_mul_of_nonneg_right (hvle a)\n positivity\n _ = ((∑ c, v c) / (1 - γ)) * ((γ / K) ^ 2 * (∑ a, p a * (rh a) ^ 2)) := by\n rw [Finset.mul_sum, Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro a _\n field_simp\n _ ≤ ((∑ c, v c) / (1 - γ)) * ((γ / K) ^ 2 * (∑ a, rh a)) := by\n rw [hsum2, hsumrh]\n have hq : 0 ≤ rv / p b := div_nonneg hrv0 (hppos b).le\n have h3 : rv * (rv / p b) ≤ rv / p b := by nlinarith\n have h4 : (0:ℝ) ≤ (∑ c, v c) / (1 - γ) := div_nonneg hVpos.le hD.le\n have h5 : (0:ℝ) ≤ (γ / K) ^ 2 := sq_nonneg _\n exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left h3 h5) h4\n have hSnn : (0:ℝ) ≤ ∑ a, rh a := Finset.sum_nonneg (fun a _ => hrhnn a)\n set A : ℝ := (γ / K) / (1 - γ) * rv + (Real.exp 1 - 2) * (γ / K) ^ 2 / (1 - γ) * (∑ a, rh a)\n with hA\n have hAnn : 0 ≤ A := by\n rw [hA]\n have : (0:ℝ) ≤ (γ / K) / (1 - γ) * rv := by positivity\n have h2 : (0:ℝ) ≤ (Real.exp 1 - 2) * (γ / K) ^ 2 / (1 - γ) * (∑ a, rh a) := by\n apply mul_nonneg _ hSnn\n apply div_nonneg _ hD.le\n positivity\n linarith\n have hV'le : ∑ a, v' a ≤ (∑ a, v a) * (1 + A) := by\n calc ∑ a, v' a = ∑ a, v a * Real.exp (γ * rh a / K) := by\n apply Finset.sum_congr rfl; intro a _; rw [hv' a]\n _ ≤ ∑ a, v a * (1 + (γ * rh a / K) + (Real.exp 1 - 2) * (γ * rh a / K) ^ 2) := by\n apply Finset.sum_le_sum\n intro a _\n refine mul_le_mul_of_nonneg_left (exp_quad _ ?_ (hrhle a)) (hvnonneg a)\n have := hrhnn a\n positivity\n _ = ∑ a, (v a + v a * (γ * rh a / K)\n + (Real.exp 1 - 2) * (v a * (γ * rh a / K) ^ 2)) := by\n apply Finset.sum_congr rfl; intro a _; ring\n _ = (∑ a, v a) + (∑ a, v a * (γ * rh a / K))\n + (Real.exp 1 - 2) * (∑ a, v a * (γ * rh a / K) ^ 2) := by\n rw [Finset.sum_add_distrib, Finset.sum_add_distrib, ← Finset.mul_sum]\n _ ≤ (∑ a, v a) + ((∑ c, v c) / (1 - γ)) * ((γ / K) * rv)\n + (Real.exp 1 - 2) * (((∑ c, v c) / (1 - γ)) * ((γ / K) ^ 2 * (∑ a, rh a))) := by\n nlinarith [b1, b2, he2]\n _ = (∑ a, v a) * (1 + A) := by\n rw [hA]; field_simp; ring\n have hV'pos : 0 < ∑ a, v' a := by\n obtain ⟨a1, -, ha1⟩ := Finset.exists_lt_of_sum_lt\n (show ∑ _a : Fin K, (0:ℝ) < ∑ a, v a by simpa using hVpos)\n refine Finset.sum_pos' (fun a _ => ?_) ⟨a1, Finset.mem_univ a1, ?_⟩\n · rw [hv' a]; exact mul_nonneg (hvnonneg a) (Real.exp_pos _).le\n · rw [hv' a1]; exact mul_pos ha1 (Real.exp_pos _)\n have hlog := Real.log_le_log hV'pos hV'le\n rw [Real.log_mul hVpos.ne' (by positivity)] at hlog\n have hlog1 : Real.log (1 + A) ≤ A := by\n have h := Real.log_le_sub_one_of_pos (show (0:ℝ) < 1 + A by linarith)\n linarith\n linarith\n\ntheorem ch16_theorem_16_17\n {K T : ℕ} (hK : 1 ≤ K) (γ : ℝ) (hγ : 0 < γ) (hγ1 : γ ≤ 1)\n (r : Fin T → Fin K → ℝ) (hr : ∀ t a, r t a ∈ Set.Icc (0 : ℝ) 1)\n {Ω : Type*} {m0 : MeasurableSpace Ω} (μ : @Measure Ω m0) [IsProbabilityMeasure μ]\n (w : Fin (T + 1) → Ω → Fin K → ℝ) (pol : Fin T → Ω → Fin K → ℝ)\n (a' : Fin T → Ω → Fin K) (rhat : Fin T → Ω → Fin K → ℝ)\n (ha'meas : ∀ t, Measurable (a' t)) (hw0 : ∀ ω a, w 0 ω a = 1)\n (hwnonneg : ∀ (t : Fin (T + 1)) ω a, 0 ≤ w t ω a)\n (hwpos : ∀ (t : Fin T) ω, 0 < ∑ b : Fin K, w t.castSucc ω b)\n (hpol : ∀ (t : Fin T) ω a, pol t ω a = (1 - γ) * (w t.castSucc ω a / ∑ b : Fin K, w t.castSucc ω b) + γ / K)\n (hpolpos : ∀ (t : Fin T) ω a, 0 < pol t ω a)\n (hrhat : ∀ (t : Fin T) ω a, rhat t ω a = if a = a' t ω then r t (a' t ω) / pol t ω (a' t ω) else 0)\n (hwupd : ∀ (t : Fin T) ω a, w t.succ ω a = w t.castSucc ω a * Real.exp (γ * rhat t ω a / K))\n (ℱ : Fin T → MeasurableSpace Ω)\n (hℱ : ∀ t, ℱ t ≤ m0)\n (ha'adapted : ∀ (s t : Fin T), s < t → Measurable[ℱ t] (a' s))\n (hpol_meas : ∀ (t : Fin T) (a : Fin K), Measurable[ℱ t] (fun ω => pol t ω a))\n (hsample : ∀ (t : Fin T) (a : Fin K),\n μ[(fun ω => if a' t ω = a then (1 : ℝ) else 0) | ℱ t]\n =ᵐ[μ] fun ω => pol t ω a)\n (hint_rhat : ∀ (t : Fin T) (a : Fin K), Integrable (fun ω => rhat t ω a) μ)\n (hint_rew : Integrable (fun ω => ∑ t : Fin T, r t (a' t ω)) μ)\n (REG : ℝ) (hREG : REG = bestArmReward hK r - ∫ ω, ∑ t : Fin T, r t (a' t ω) ∂μ) :\n REG ≤ (Real.exp 1 - 1) * γ * bestArmReward hK r + (K * Real.log K) / γ := by\n haveI : Nonempty (Fin K) := ⟨⟨0, hK⟩⟩\n have hK0 : (0:ℝ) < K := by exact_mod_cast hK\n have hlogK : (0:ℝ) ≤ Real.log K := Real.log_nonneg (by exact_mod_cast hK)\n have he2 : (0:ℝ) < Real.exp 1 - 2 := by nlinarith [Real.exp_one_gt_d9]\n have hGle : ∀ a, ∑ t : Fin T, r t a ≤ bestArmReward hK r := by\n intro a\n unfold bestArmReward\n exact Finset.le_sup' (fun a => ∑ t : Fin T, r t a) (Finset.mem_univ a)\n have hGnonneg : (0:ℝ) ≤ bestArmReward hK r := by\n refine le_trans ?_ (hGle ⟨0, hK⟩)\n exact Finset.sum_nonneg (fun t _ => (hr t _).1)\n have hEnonneg : (0:ℝ) ≤ ∫ ω, ∑ t : Fin T, r t (a' t ω) ∂μ :=\n integral_nonneg (fun ω => Finset.sum_nonneg (fun t _ => (hr t _).1))\n by_cases hlt : γ < 1\n swap\n · have hγ1' : γ = 1 := le_antisymm hγ1 (not_lt.mp hlt)\n subst hγ1'\n rw [hREG]\n have h1 : (0:ℝ) ≤ (K : ℝ) * Real.log K / 1 := by positivity\n nlinarith [hGnonneg, hEnonneg, he2, h1]\n -- main case\n obtain ⟨a₀, ha₀⟩ : ∃ a₀ : Fin K, bestArmReward hK r = ∑ t : Fin T, r t a₀ := by\n unfold bestArmReward\n obtain ⟨a₀, -, h⟩ := Finset.exists_mem_eq_sup' (Finset.univ_nonempty)\n (fun a => ∑ t : Fin T, r t a)\n exact ⟨a₀, h⟩\n have hD : (0:ℝ) < 1 - γ := by linarith\n set C : ℝ := (Real.exp 1 - 2) * (γ / K) ^ 2 / (1 - γ) with hC\n have hCnn : 0 ≤ C := by rw [hC]; positivity\n -- master pointwise inequality\n have master : ∀ ω, (γ / K) * (∑ t : Fin T, rhat t ω a₀) - Real.log K\n ≤ (γ / K) / (1 - γ) * (∑ t : Fin T, r t (a' t ω))\n + C * (∑ t : Fin T, ∑ a : Fin K, rhat t ω a) := by\n intro ω\n have hup : Real.log (∑ b, w (Fin.last T) ω b) - Real.log (∑ b, w 0 ω b)\n ≤ (γ / K) / (1 - γ) * (∑ t : Fin T, r t (a' t ω))\n + C * (∑ t : Fin T, ∑ a : Fin K, rhat t ω a) := by\n rw [← tele (fun i => Real.log (∑ b, w i ω b))]\n calc ∑ t : Fin T, (Real.log (∑ b, w t.succ ω b) - Real.log (∑ b, w t.castSucc ω b))\n ≤ ∑ t : Fin T, ((γ / K) / (1 - γ) * r t (a' t ω)\n + C * (∑ a : Fin K, rhat t ω a)) := by\n apply Finset.sum_le_sum\n intro t _\n exact one_step hK γ hγ hlt (w t.castSucc ω) (w t.succ ω) (pol t ω) (rhat t ω)\n (a' t ω) (r t (a' t ω)) (fun a => hwnonneg _ _ _) (hwpos t ω)\n (fun a => hpol t ω a) (fun a => hrhat t ω a) (hr t _).1 (hr t _).2\n (fun a => hwupd t ω a)\n _ = (γ / K) / (1 - γ) * (∑ t : Fin T, r t (a' t ω))\n + C * (∑ t : Fin T, ∑ a : Fin K, rhat t ω a) := by\n rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum]\n have hwa0pos : ∀ i : Fin (T + 1), 0 < w i ω a₀ := by\n intro i\n induction i using Fin.induction with\n | zero => rw [hw0]; norm_num\n | succ j ih => rw [hwupd]; exact mul_pos ih (Real.exp_pos _)\n have hlogw : ∑ t : Fin T, (γ * rhat t ω a₀ / K) = Real.log (w (Fin.last T) ω a₀) := by\n have h2 := tele (fun i => Real.log (w i ω a₀))\n simp only [hw0, Real.log_one, sub_zero] at h2\n rw [← h2]\n apply Finset.sum_congr rfl\n intro t _\n rw [hwupd t ω a₀, Real.log_mul (hwa0pos _).ne' (Real.exp_pos _).ne', Real.log_exp]\n ring\n have hle : w (Fin.last T) ω a₀ ≤ ∑ b, w (Fin.last T) ω b :=\n Finset.single_le_sum (f := fun b => w (Fin.last T) ω b)\n (fun b _ => hwnonneg _ _ _) (Finset.mem_univ a₀)\n have hlog2 : Real.log (w (Fin.last T) ω a₀) ≤ Real.log (∑ b, w (Fin.last T) ω b) :=\n Real.log_le_log (hwa0pos _) hle\n have hW0 : (∑ b, w (0 : Fin (T + 1)) ω b) = (K : ℝ) := by\n simp [hw0]\n have hmul : (γ / K) * (∑ t : Fin T, rhat t ω a₀) = ∑ t : Fin T, (γ * rhat t ω a₀ / K) := by\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro t _\n ring\n rw [hW0] at hup\n linarith [hup, hlog2, hlogw, hmul]\n -- expectation of rhat\n have hIntRhat : ∀ (t : Fin T) (a : Fin K), ∫ ω, rhat t ω a ∂μ = r t a := by\n intro t a\n set f : Ω → ℝ := fun ω => r t a / pol t ω a with hf\n set g : Ω → ℝ := fun ω => if a' t ω = a then (1:ℝ) else 0 with hg\n have hfg : ∀ ω, rhat t ω a = f ω * g ω := by\n intro ω\n simp only [hf, hg]\n rw [hrhat t ω a]\n by_cases h : a = a' t ω\n · subst h\n simp\n · rw [if_neg h, if_neg (fun hh => h hh.symm)]\n ring\n have hfmeas : Measurable[ℱ t] f := by\n rw [hf]\n exact measurable_const.div (hpol_meas t a)\n have hgmeas : Measurable g := by\n rw [hg]\n exact Measurable.ite (measurableSet_eq_fun (ha'meas t) measurable_const)\n measurable_const measurable_const\n have hgint : Integrable g μ := by\n refine Integrable.mono' (integrable_const 1) hgmeas.aestronglyMeasurable ?_\n filter_upwards with ω\n rw [hg]\n by_cases h : a' t ω = a <;> simp [h]\n have hfgint : Integrable (fun ω => f ω * g ω) μ := by\n simpa [hfg] using hint_rhat t a\n have h1 : μ[(fun ω => f ω * g ω)|ℱ t] =ᵐ[μ] f * μ[g|ℱ t] :=\n condExp_mul_of_stronglyMeasurable_left hfmeas.stronglyMeasurable hfgint hgint\n have h2 := integral_condExp (μ := μ) (f := fun ω => f ω * g ω) (hℱ t)\n calc ∫ ω, rhat t ω a ∂μ = ∫ ω, f ω * g ω ∂μ := by\n apply integral_congr_ae; filter_upwards with ω; rw [hfg ω]\n _ = ∫ ω, (μ[(fun ω => f ω * g ω)|ℱ t]) ω ∂μ := h2.symm\n _ = ∫ ω, r t a ∂μ := by\n apply integral_congr_ae\n filter_upwards [h1, hsample t a] with ω hw hw2\n rw [hw]\n simp only [Pi.mul_apply]\n rw [hw2]\n simp only [hf]\n have hp0 : pol t ω a ≠ 0 := (hpolpos t ω a).ne'\n field_simp\n _ = r t a := by simp\n -- integrate the master inequality\n have hI1 : Integrable (fun ω => ∑ t : Fin T, rhat t ω a₀) μ :=\n integrable_finset_sum _ (fun t _ => hint_rhat t a₀)\n have hI2 : Integrable (fun ω => ∑ t : Fin T, ∑ a : Fin K, rhat t ω a) μ :=\n integrable_finset_sum _ (fun t _ => integrable_finset_sum _ (fun a _ => hint_rhat t a))\n have hIL : Integrable (fun ω => (γ / K) * (∑ t : Fin T, rhat t ω a₀) - Real.log K) μ :=\n (hI1.const_mul _).sub (integrable_const _)\n have hIR : Integrable (fun ω => (γ / K) / (1 - γ) * (∑ t : Fin T, r t (a' t ω))\n + C * (∑ t : Fin T, ∑ a : Fin K, rhat t ω a)) μ :=\n (hint_rew.const_mul _).add (hI2.const_mul _)\n have hmono := integral_mono hIL hIR master\n have hL : ∫ ω, ((γ / K) * (∑ t : Fin T, rhat t ω a₀) - Real.log K) ∂μ\n = (γ / K) * (∑ t : Fin T, r t a₀) - Real.log K := by\n rw [integral_sub (hI1.const_mul _) (integrable_const _), integral_const_mul,\n integral_finset_sum _ (fun t _ => hint_rhat t a₀)]\n simp [hIntRhat]\n have hR : ∫ ω, ((γ / K) / (1 - γ) * (∑ t : Fin T, r t (a' t ω))\n + C * (∑ t : Fin T, ∑ a : Fin K, rhat t ω a)) ∂μ\n = (γ / K) / (1 - γ) * (∫ ω, ∑ t : Fin T, r t (a' t ω) ∂μ)\n + C * (∑ t : Fin T, ∑ a : Fin K, r t a) := by\n rw [integral_add (hint_rew.const_mul _) (hI2.const_mul _), integral_const_mul,\n integral_const_mul,\n integral_finset_sum _ (fun t _ => integrable_finset_sum _ (fun a _ => hint_rhat t a))]\n congr 2\n apply Finset.sum_congr rfl\n intro t _\n rw [integral_finset_sum _ (fun a _ => hint_rhat t a)]\n exact Finset.sum_congr rfl (fun a _ => hIntRhat t a)\n rw [hL, hR] at hmono\n -- final algebra\n set G : ℝ := bestArmReward hK r with hG\n set E : ℝ := ∫ ω, ∑ t : Fin T, r t (a' t ω) ∂μ with hE\n set S : ℝ := ∑ t : Fin T, ∑ a : Fin K, r t a with hS\n have hSle : S ≤ (K : ℝ) * G := by\n rw [hS, Finset.sum_comm]\n calc ∑ a : Fin K, ∑ t : Fin T, r t a ≤ ∑ _a : Fin K, G :=\n Finset.sum_le_sum (fun a _ => hGle a)\n _ = (K : ℝ) * G := by simp [mul_comm]\n have hSnn : (0:ℝ) ≤ S := by\n rw [hS]\n exact Finset.sum_nonneg (fun t _ => Finset.sum_nonneg (fun a _ => (hr t a).1))\n rw [← ha₀] at hmono\n -- hmono : (γ/K)*G - log K ≤ (γ/K)/(1-γ)*E + C*S\n have hposm : (0:ℝ) < (K : ℝ) * (1 - γ) / γ := by positivity\n have key2 := mul_le_mul_of_nonneg_left hmono hposm.le\n have ee1 : ((K : ℝ) * (1 - γ) / γ) * ((γ / K) * G - Real.log K)\n = (1 - γ) * G - (K : ℝ) * (1 - γ) * Real.log K / γ := by\n field_simp\n have ee2 : ((K : ℝ) * (1 - γ) / γ) * ((γ / K) / (1 - γ) * E + C * S)\n = E + (Real.exp 1 - 2) * (γ / K) * S := by\n rw [hC]\n field_simp\n rw [ee1, ee2] at key2\n have hSb : (Real.exp 1 - 2) * (γ / K) * S ≤ (Real.exp 1 - 2) * γ * G := by\n have h1 : (γ / K) * S ≤ (γ / K) * ((K : ℝ) * G) :=\n mul_le_mul_of_nonneg_left hSle (by positivity)\n have h2 : (γ / K) * ((K : ℝ) * G) = γ * G := by field_simp\n rw [h2] at h1\n calc (Real.exp 1 - 2) * (γ / K) * S = (Real.exp 1 - 2) * ((γ / K) * S) := by ring\n _ ≤ (Real.exp 1 - 2) * (γ * G) := mul_le_mul_of_nonneg_left h1 he2.le\n _ = (Real.exp 1 - 2) * γ * G := by ring\n have hlogb : (K : ℝ) * (1 - γ) * Real.log K / γ ≤ (K : ℝ) * Real.log K / γ := by\n have hnum : (K : ℝ) * (1 - γ) * Real.log K ≤ (K : ℝ) * Real.log K := by\n nlinarith [mul_nonneg (mul_nonneg hγ.le hK0.le) hlogK]\n exact div_le_div_of_nonneg_right hnum hγ.le\n rw [hREG]\n linarith [key2, hSb, hlogb]\n\nend GraduateLevel\n"} +{"id": "ch7_theorem_7_7", "source": "Graduate-level", "targets": [{"label": "ch7_theorem_7_7", "decls": ["ch7_theorem_7_7"], "statement": "All local minima of \\(g\\) are global minima (even though \\(g\\) is non-convex).", "topic_domain": "Optimization", "topic_subtopic": "Non-convex Geometry"}], "nl_proof": "Step 1: Show that all stationary points must be eigenvectors. We have \\(\\nabla g(x) = -(M - xx^\\top)x\\), hence\n\\[\n\\nabla g(x) = 0 \\implies Mx = \\|x\\|_2^2 \\cdot x,\n\\]\nwhich implies that \\(x\\) is an eigenvector of \\(M\\) with eigenvalue \\(\\|x\\|_2^2\\). From the Eckart–Young–Mirsky theorem the global minimum (i.e. the best rank-1 approximation) is the eigenvector with the largest eigenvalue.\n\nStep 2: Show that all local minima must be eigenvectors of the largest eigenvalue. We use the second-order condition. For \\(x\\) to be a local minimum we need \\(\\nabla^2 g(x) \\succeq 0\\), i.e. for any \\(v \\in \\mathbb{R}^d\\),\n\\[\n\\langle v, \\nabla^2 g(x)\\, v \\rangle \\geq 0.\n\\]\nExpanding \\(g(x+v)\\) into \\(g(x) + \\text{linear term in }v + \\text{quadratic term in }v\\) (the quadratic term equals \\(\\frac{1}{2}\\langle v, \\nabla^2 g(x)\\,v\\rangle\\)),\n\\[\ng(x+v) = \\tfrac{1}{2}\\|M - (x+v)(x+v)^\\top\\|_F^2 = \\tfrac{1}{2}\\|M - xx^\\top\\|_F^2 - \\langle M - xx^\\top, xv^\\top + vx^\\top\\rangle + \\tfrac{1}{2}\\langle xv^\\top + vx^\\top, xv^\\top + vx^\\top\\rangle - \\langle M - xx^\\top, vv^\\top\\rangle + \\text{higher order terms in }v.\n\\]\nHence,\n\\[\n\\tfrac{1}{2}\\langle v, \\nabla^2 g(x)\\,v\\rangle = \\tfrac{1}{2}\\langle xv^\\top + vx^\\top, xv^\\top + vx^\\top\\rangle - \\langle M - xx^\\top, vv^\\top\\rangle = 2\\langle x, v\\rangle^2 + \\|x\\|_2^2\\|v\\|_2^2 - v^\\top M v.\n\\]\nPicking \\(v = v_1\\), the unit eigenvector with the largest eigenvalue \\(\\lambda_1\\), the local minimum condition requires\n\\[\n\\langle v_1, \\nabla^2 g(x)\\,v_1\\rangle = 2\\langle x, v_1\\rangle^2 - v_1^\\top M v_1 + \\|x\\|_2^2 \\geq 0.\n\\]\nSince all candidates for local minima are eigenvectors of \\(M\\), there are two cases:\n- Case 1: \\(x\\) has eigenvalue \\(\\lambda_1\\). Then \\(x\\) is the global minimum (by the Eckart–Young–Mirsky theorem).\n- Case 2: \\(x\\) has eigenvalue \\(\\lambda < \\lambda_1\\). Then \\(x\\) and \\(v_1\\) are orthogonal, so\n\\[\n2\\langle x, v_1\\rangle^2 - v_1^\\top M v_1 + \\|x\\|_2^2 = 0 - \\lambda_1 + \\lambda \\geq 0,\n\\]\nwhich implies \\(\\lambda \\geq \\lambda_1\\), a contradiction.\n\nIn summary, if \\(x\\) is a stationary point and not a global minimum, then moving in the direction of \\(v_1\\) yields a second-order improvement and \\(x\\) cannot be a local minimum.", "context": [{"id": "ch7:definition:7_1", "name": "Local minimum of a function", "statement": "We say that \\(x\\) is a local minimum of a function \\(f\\) if there exists an open neighborhood \\(N\\) around \\(x\\) such that in \\(N\\), the function values are at least \\(f(x)\\)."}, {"id": "ch7:setup:7_7", "name": "PCA rank-1 objective and assumptions", "statement": "Let \\(M \\in \\mathbb{R}^{d \\times d}\\) be symmetric positive semidefinite. For \\(x \\in \\mathbb{R}^d\\), define \\(g(x) := \\frac{1}{2}\\|M - xx^\\top\\|_F^2\\)."}], "lean": "import Mathlib\n\nopen scoped Matrix\n\nnamespace GraduateLevel\n\nnoncomputable def pcaObjective {d : ℕ} (M : Matrix (Fin d) (Fin d) ℝ) (x : Fin d → ℝ) : ℝ :=\n (1 / 2) * ∑ i : Fin d, ∑ j : Fin d, (M i j - Matrix.vecMulVec x x i j) ^ 2\n\ntheorem ch7_theorem_7_7\n {d : ℕ} (M : Matrix (Fin d) (Fin d) ℝ)\n (hSymm : M.IsSymm) (hPSD : M.PosSemidef)\n (x : Fin d → ℝ)\n (hLocal : IsLocalMin (pcaObjective M) x) :\n ∀ y : Fin d → ℝ, pcaObjective M x ≤ pcaObjective M y := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped Matrix\n\nnamespace GraduateLevel\n\nnoncomputable def pcaObjective {d : ℕ} (M : Matrix (Fin d) (Fin d) ℝ) (x : Fin d → ℝ) : ℝ :=\n (1 / 2) * ∑ i : Fin d, ∑ j : Fin d, (M i j - Matrix.vecMulVec x x i j) ^ 2\n\nopen Filter Topology\n\nsection aux\n\nvariable {d : ℕ}\n\nnoncomputable def ipp (u w : Fin d → ℝ) : ℝ := ∑ i, u i * w i\nnoncomputable def nnn (u : Fin d → ℝ) : ℝ := ∑ i, u i ^ 2\nnoncomputable def qbb (M : Matrix (Fin d) (Fin d) ℝ) (u w : Fin d → ℝ) : ℝ :=\n ∑ i, ∑ j, M i j * u i * w j\n\nlemma nnn_nonneg (u : Fin d → ℝ) : 0 ≤ nnn u := by\n unfold nnn\n exact Finset.sum_nonneg fun i _ => sq_nonneg _\n\nlemma ipp_comm (u w : Fin d → ℝ) : ipp u w = ipp w u := by\n unfold ipp\n exact Finset.sum_congr rfl fun i _ => mul_comm _ _\n\nlemma ipp_self (u : Fin d → ℝ) : ipp u u = nnn u := by\n unfold ipp nnn\n exact Finset.sum_congr rfl fun i _ => (sq (u i)).symm\n\nlemma qbb_expand (M : Matrix (Fin d) (Fin d) ℝ) (u w : Fin d → ℝ) (c : ℝ) :\n qbb M (u + c • w) (u + c • w)\n = qbb M u u + c * (qbb M u w + qbb M w u) + c ^ 2 * qbb M w w := by\n simp only [qbb, Pi.add_apply, Pi.smul_apply, smul_eq_mul, Finset.mul_sum,\n ← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl fun i _ => ?_\n refine Finset.sum_congr rfl fun j _ => ?_\n ring\n\nlemma nnn_expand (u w : Fin d → ℝ) (c : ℝ) :\n nnn (u + c • w) = nnn u + 2 * c * ipp u w + c ^ 2 * nnn w := by\n simp only [nnn, ipp, Pi.add_apply, Pi.smul_apply, smul_eq_mul, Finset.mul_sum,\n ← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl fun i _ => ?_\n ring\n\nlemma ipp_expand (u w z : Fin d → ℝ) (c : ℝ) :\n ipp u (w + c • z) = ipp u w + c * ipp u z := by\n simp only [ipp, Pi.add_apply, Pi.smul_apply, smul_eq_mul, Finset.mul_sum,\n ← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl fun i _ => ?_\n ring\n\nlemma pca_expand (M : Matrix (Fin d) (Fin d) ℝ) (y : Fin d → ℝ) :\n pcaObjective M y\n = (1 / 2) * (∑ i : Fin d, ∑ j : Fin d, (M i j) ^ 2) - qbb M y y + (nnn y) ^ 2 / 2 := by\n have hsq : (nnn y) ^ 2 = ∑ i : Fin d, ∑ j : Fin d, (y i ^ 2 * y j ^ 2) := by\n simp only [nnn, sq]\n rw [Finset.sum_mul_sum]\n have hmain : (∑ i : Fin d, ∑ j : Fin d, (M i j - Matrix.vecMulVec y y i j) ^ 2)\n = (∑ i : Fin d, ∑ j : Fin d, (M i j) ^ 2)\n - 2 * (∑ i : Fin d, ∑ j : Fin d, M i j * y i * y j)\n + (∑ i : Fin d, ∑ j : Fin d, (y i ^ 2 * y j ^ 2)) := by\n simp only [Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl fun i _ => ?_\n refine Finset.sum_congr rfl fun j _ => ?_\n simp only [Matrix.vecMulVec_apply]\n ring\n simp only [pcaObjective, qbb]\n rw [hmain, hsq]\n ring\n\nend aux\n\ntheorem ch7_theorem_7_7\n {d : ℕ} (M : Matrix (Fin d) (Fin d) ℝ)\n (hSymm : M.IsSymm) (hPSD : M.PosSemidef)\n (x : Fin d → ℝ)\n (hLocal : IsLocalMin (pcaObjective M) x) :\n ∀ y : Fin d → ℝ, pcaObjective M x ≤ pcaObjective M y := by\n have hL : ∀ᶠ y in nhds x, pcaObjective M x ≤ pcaObjective M y := hLocal\n have key : ∀ v : Fin d → ℝ,\n (-(qbb M x v + qbb M v x) + 2 * ipp x v * nnn x = 0) ∧\n (0 ≤ -(qbb M v v) + nnn x * nnn v + 2 * (ipp x v) ^ 2) := by\n intro v\n set a1 : ℝ := -(qbb M x v + qbb M v x) + 2 * ipp x v * nnn x with ha1\n set a2 : ℝ := -(qbb M v v) + nnn x * nnn v + 2 * (ipp x v) ^ 2 with ha2\n set a3 : ℝ := 2 * ipp x v * nnn v with ha3\n set a4 : ℝ := (nnn v) ^ 2 / 2 with ha4\n have hpoly : ∀ t : ℝ, pcaObjective M (x + t • v)\n = pcaObjective M x + a1 * t + a2 * t ^ 2 + a3 * t ^ 3 + a4 * t ^ 4 := by\n intro t\n rw [pca_expand M (x + t • v), pca_expand M x, qbb_expand, nnn_expand, ha1, ha2, ha3, ha4]\n ring\n have hev : ∀ᶠ t : ℝ in nhds 0,\n 0 ≤ a1 * t + a2 * t ^ 2 + a3 * t ^ 3 + a4 * t ^ 4 := by\n have hc : Filter.Tendsto (fun t : ℝ => x + t • v) (nhds 0) (nhds x) := by\n have h : ContinuousAt (fun t : ℝ => x + t • v) 0 := by fun_prop\n simpa using h.tendsto\n have h3 := hc.eventually hL\n filter_upwards [h3] with t ht\n rw [hpoly t] at ht\n linarith\n have hloc0 : IsLocalMin (fun t : ℝ =>\n pcaObjective M x + a1 * t + a2 * t ^ 2 + a3 * t ^ 3 + a4 * t ^ 4) 0 := by\n filter_upwards [hev] with t ht\n have h0 : pcaObjective M x + a1 * 0 + a2 * 0 ^ 2 + a3 * 0 ^ 3 + a4 * 0 ^ 4\n ≤ pcaObjective M x + a1 * t + a2 * t ^ 2 + a3 * t ^ 3 + a4 * t ^ 4 := by\n nlinarith [ht]\n exact h0\n have hderiv : HasDerivAt (fun t : ℝ =>\n pcaObjective M x + a1 * t + a2 * t ^ 2 + a3 * t ^ 3 + a4 * t ^ 4) a1 0 := by\n have d0 : HasDerivAt (fun _ : ℝ => pcaObjective M x) 0 0 := hasDerivAt_const _ _\n have d1 : HasDerivAt (fun t : ℝ => a1 * t) a1 0 := by\n simpa using (hasDerivAt_id (0 : ℝ)).const_mul a1\n have d2 : HasDerivAt (fun t : ℝ => a2 * t ^ 2) 0 0 := by\n simpa using (hasDerivAt_pow 2 (0 : ℝ)).const_mul a2\n have d3 : HasDerivAt (fun t : ℝ => a3 * t ^ 3) 0 0 := by\n simpa using (hasDerivAt_pow 3 (0 : ℝ)).const_mul a3\n have d4 : HasDerivAt (fun t : ℝ => a4 * t ^ 4) 0 0 := by\n simpa using (hasDerivAt_pow 4 (0 : ℝ)).const_mul a4\n simpa using (((d0.add d1).add d2).add d3).add d4\n have ha1zero : a1 = 0 := hloc0.hasDerivAt_eq_zero hderiv\n refine ⟨ha1zero, ?_⟩\n have hev2 : ∀ᶠ t : ℝ in 𝓝[≠] (0 : ℝ), 0 ≤ a2 + a3 * t + a4 * t ^ 2 := by\n have h : ∀ᶠ t : ℝ in 𝓝[≠] (0 : ℝ),\n 0 ≤ a1 * t + a2 * t ^ 2 + a3 * t ^ 3 + a4 * t ^ 4 :=\n hev.filter_mono nhdsWithin_le_nhds\n filter_upwards [h, self_mem_nhdsWithin] with t ht htne\n have htne' : t ≠ 0 := htne\n have hpos : 0 < t ^ 2 := by positivity\n rw [ha1zero] at ht\n nlinarith [ht, hpos]\n have hc2 : Filter.Tendsto (fun t : ℝ => a2 + a3 * t + a4 * t ^ 2)\n (𝓝[≠] (0 : ℝ)) (nhds a2) := by\n have hcont : Continuous (fun t : ℝ => a2 + a3 * t + a4 * t ^ 2) := by continuity\n have h5 : Filter.Tendsto (fun t : ℝ => a2 + a3 * t + a4 * t ^ 2)\n (𝓝[≠] (0 : ℝ)) (nhds (a2 + a3 * 0 + a4 * 0 ^ 2)) :=\n (hcont.tendsto 0).mono_left nhdsWithin_le_nhds\n simpa using h5\n exact ge_of_tendsto hc2 hev2\n have hxx : qbb M x x = (nnn x) ^ 2 := by\n have h := (key x).1\n rw [ipp_self] at h\n nlinarith [h]\n have hbound : ∀ v : Fin d → ℝ, qbb M v v ≤ nnn x * nnn v := by\n intro v\n rcases eq_or_lt_of_le (nnn_nonneg x) with h0 | hpos\n · have hs : ∑ i : Fin d, x i ^ 2 = 0 := by\n have : nnn x = 0 := h0.symm\n unfold nnn at this\n exact this\n have hx0 : ∀ i, x i = 0 := by\n intro i\n have h2 := (Finset.sum_eq_zero_iff_of_nonneg\n (fun i _ => sq_nonneg (x i))).mp hs i (Finset.mem_univ i)\n exact pow_eq_zero_iff (n := 2) (by norm_num) |>.mp h2\n have hipz : ipp x v = 0 := by\n unfold ipp\n refine Finset.sum_eq_zero fun i _ => ?_\n rw [hx0 i]; ring\n have h2 := (key v).2\n rw [hipz, ← h0] at h2\n rw [← h0]\n linarith\n · have hnx : nnn x ≠ 0 := ne_of_gt hpos\n obtain ⟨c, hcx⟩ : ∃ c : ℝ, c * nnn x = ipp x v :=\n ⟨ipp x v / nnn x, by field_simp⟩\n have hfo : qbb M x v + qbb M v x = 2 * ipp x v * nnn x := by\n have := (key v).1; linarith\n have hqw : qbb M (v + (-c) • x) (v + (-c) • x)\n = qbb M v v - c ^ 2 * (nnn x) ^ 2 := by\n rw [qbb_expand, hxx]\n linear_combination (-c) * hfo + (2 * c * nnn x) * hcx\n have hnw : nnn (v + (-c) • x) = nnn v - c ^ 2 * nnn x := by\n rw [nnn_expand, ipp_comm v x]\n linear_combination (2 * c) * hcx\n have hipw : ipp x (v + (-c) • x) = 0 := by\n rw [ipp_expand, ipp_self]\n linear_combination -hcx\n set w : Fin d → ℝ := v + (-c) • x with hw\n have h2 := (key w).2\n rw [hqw, hnw, hipw] at h2\n nlinarith [h2]\n intro y\n have h1 : qbb M y y ≤ nnn x * nnn y := hbound y\n rw [pca_expand M x, pca_expand M y, hxx]\n nlinarith [h1, sq_nonneg (nnn x - nnn y)]\n\nend GraduateLevel\n"} +{"id": "ch4_theorem_4_18", "source": "Graduate-level", "targets": [{"label": "ch4_theorem_4_18", "decls": ["ch4_theorem_4_18"], "statement": "Suppose for all \\(f \\in \\mathcal{F}\\), \\(0 \\leq f(z) \\leq 1\\). Then, with probability at least \\(1-\\delta\\),\n\\[\n\\sup_{f\\in \\mathcal{F}} \\left[ \\frac{1}{n} \\sum^n_{i=1} f(z_i) - \\mathbb{E}[f(z)] \\right] \\leq 2 R_S(\\mathcal{F}) + 3\\sqrt{\\frac{\\log{(2/\\delta)}}{2n}}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Define\n\\[\ng(z_1, \\dots, z_n) \\triangleq \\sup_{f\\in F} \\left[ \\frac{1}{n} \\sum^{n}_{i=1} f(z_i) - \\mathbb{E}[f(z)]\\right].\n\\]\n\nWe prove the theorem in 4 steps.\n\nStep 1: We bound \\(g\\) using McDiarmid's Inequality. To use McDiarmid's Inequality, we check that the bounded difference condition holds:\n\\[\ng(z_1,\\dots,z_n)-g(z_1,\\dots,z_i',\\dots,z_n)\n\\leq\\sup_{f\\in\\mathcal{F}}\\left[\\frac{1}{n}\\sum^{n}_{j=1}f(z_j)\\right]-\\sup_{f\\in\\mathcal{F}}\\left[\\left(\\frac{1}{n}\\sum^{n}_{j=1,j\\neq i}f(z_j)\\right)+\\frac{f(z_i')}{n}\\right]\n\\leq\\sup_{f\\in\\mathcal{F}}\\left[\\frac{1}{n}\\sum^{n}_{j=1}f(z_j)-\\left(\\frac{1}{n}\\sum^{n}_{j=1,j\\neq i}f(z_j)\\right)-\\frac{f(z_i')}{n}\\right]\n=\\sup_{f\\in\\mathcal{F}}\\left[\\frac{1}{n}\\left(f(z_i)-f(z_i')\\right)\\right]\n\\leq\\frac{1}{n}.\n\\]\nThe first inequality holds because in general \\(\\sup_f A(f) - \\sup_f B(f) \\leq \\sup_f [A(f) - B(f)]\\), and the last inequality holds since \\(f\\) is bounded by \\([0,1]\\). We can thus apply McDiarmid's Inequality with parameters \\(c_1 = \\dots = c_n = 1/n\\):\n\\[\n\\mathbb{P}\\left[g(z_1,\\dots,z_n)\\geq\\mathbb{E}_{z_1,\\dots,z_n\\overset{\\text{iid}}{\\sim}P}[g]+\\epsilon\\right]\\leq\\exp\\!\\left(\\frac{-2\\epsilon^2}{\\sum^n_{i=1}c_i^2}\\right)=\\exp(-2n\\epsilon^2).\n\\]\n\nStep 2: We apply the referenced theorem to get\n\\[\n\\mathbb{E}_{z_1,\\dots, z_n \\overset{\\text{iid}}{\\sim} P}[g] \\leq 2R_n(\\mathcal{F}).\n\\]\n\nStep 3: Define\n\\[\n\\tilde{g}(z_1, \\dots, z_n) = R_S(\\mathcal{F}) \\triangleq \\mathbb{E}_{\\sigma_i}\\left[\\sup_{f\\in \\mathcal{F}} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i)\\right].\n\\]\n\nUsing a similar argument to that of Step 1, \\(\\tilde{g}\\) satisfies the bounded difference condition:\n\\[\n\\tilde{g}(z_1, \\dots, z_n) - \\tilde{g}(z_1, \\dots, z_i', \\dots, z_n)\n\\leq \\mathbb{E}_{\\sigma_i} \\left[\\sup_{f\\in F} \\left[ \\frac{1}{n} \\sum^{n}_{j=1} \\sigma_j f(z_j) \\right] - \\sup_{f\\in F} \\left[ \\left(\\frac{1}{n} \\sum^{n}_{j=1, j \\neq i} \\sigma_j f(z_j)\\right) + \\frac{1}{n} \\sigma_if(z_i')\\right]\\right]\n\\leq \\mathbb{E}_{\\sigma_i}\\left[\\sup_{f\\in F} \\left(\\frac{1}{n} \\sigma_i(f(z_i) - f(z_i'))\\right)\\right]\n\\leq \\frac{1}{n},\n\\]\nsince the term inside the \\(\\sup\\) is always upper bounded by 1. We can thus apply McDiarmid's Inequality with parameters \\(c_1 = \\dots = c_n = 1/n\\):\n\\[\n\\mathbb{P}\\left[ \\tilde{g} - \\mathbb{E}[\\tilde{g}] \\geq \\epsilon \\right] \\leq \\exp(-2n \\epsilon^2), \\quad\\text{and}\\quad \\mathbb{P}\\left[ \\tilde{g} - \\mathbb{E}[\\tilde{g}] \\leq -\\epsilon \\right] \\leq \\exp(-2n \\epsilon^2).\n\\]\n\nStep 4: We set \\(\\delta\\) such that \\(\\exp(-2n \\epsilon^2) = \\delta/2\\), implying \\(\\epsilon = \\sqrt{\\frac{\\log(2/\\delta)}{2n}}\\). Then, with probability \\(\\geq 1 - \\delta\\),\n\\[\n\\sup_{f\\in \\mathcal{F}} \\left[ \\frac{1}{n} \\sum^n_{i=1} f(z_i) - \\mathbb{E}[f]\\right] = g \\leq \\mathbb{E}[g] + \\epsilon \\leq 2R_n(\\mathcal{F}) + \\epsilon \\leq 2(R_S(\\mathcal{F}) + \\epsilon) + \\epsilon = 2R_S(\\mathcal{F}) + 3\\epsilon,\n\\]\nas required.", "context": [{"id": "ch4:definition:4_17", "name": "Empirical Rademacher complexity", "statement": "Given a dataset \\(S = \\{z_1, \\dots, z_n\\}\\), the empirical Rademacher complexity is defined as\n\\[\nR_S(\\mathcal{F}) \\stackrel{\\Delta}{=} \\mathbb{E}_{\\sigma_1,\\dots, \\sigma_n} \\left[ \\sup_{f\\in \\mathcal{F}} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i) \\right].\n\\]\n\\(R_S(\\mathcal{F})\\) is a function of both the function class \\(\\mathcal{F}\\) and the dataset \\(S\\).\nAs the name suggests, the expectation of the empirical Rademacher complexity is the Rademacher complexity:\n\\[\nR_n(\\mathcal{F}) = \\mathbb{E}_{\\substack{z_1, \\dots, z_n \\overset{\\text{iid}}{\\sim} P \\\\ S = \\{z_1, \\dots, z_n\\}}}\\left[ R_S(\\mathcal{F}) \\right].\n\\]"}, {"id": "ch4:theorem:4_13", "name": "Symmetrization bound by Rademacher complexity", "statement": "\\[\n\\mathbb{E}_{z_1, \\dots, z_n \\overset{\\text{iid}}{\\sim} P} \\left[ \\sup_{f\\in F} \\left[ \\frac{1}{n} \\sum^n_{i=1} f(z_i) - \\mathbb{E}_{z\\sim P} [f(z)] \\right]\\right] \\leq 2 R_n(\\mathcal{F}).\n\\]"}, {"id": "ch3:theorem:3_15", "name": "McDiarmid's inequality", "statement": "Suppose \\(f : \\mathbb{R}^n \\to \\mathbb{R}\\) satisfies the bounded difference condition: there exist constants \\(c_1, \\ldots, c_n \\in \\mathbb{R}\\) such that for all real numbers \\(x_1, \\ldots, x_n\\) and \\(x_i'\\),\n\\[\n|f(x_1, \\ldots, x_n) - f(x_1, \\ldots, x_{i-1}, x_i', x_{i+1}, \\ldots, x_n)| \\leq c_i.\n\\]\nThen, for any independent random variables \\(X_1, \\ldots, X_n\\),\n\\[\n\\mathbb{P}\\left[f(X_1, \\ldots, X_n) - \\mathbb{E}[f(X_1, \\ldots, X_n)] \\geq t\\right] \\leq \\exp\\left(-\\frac{2t^2}{\\sum_{i=1}^n c_i^2}\\right).\n\\]\nMoreover, \\(f(X_1, \\ldots, X_n)\\) is \\(O\\!\\left(\\sqrt{\\sum_{i=1}^n c_i^2}\\right)\\)-sub-Gaussian."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ntheorem ch4_theorem_4_18\n {Ω : Type u} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {ι : Type v} [Nonempty ι]\n {𝒳 : Type w} [MeasurableSpace 𝒳]\n (n : ℕ) (hn : 0 < n)\n (f : ι → 𝒳 → ℝ)\n (X : Ω → 𝒳) (hX : Measurable X)\n (hf01 : ∀ i, ∀ z : 𝒳, 0 ≤ f i z ∧ f i z ≤ 1)\n (hfmeas : ∀ i, Measurable (fun z => f i z))\n (hgmeas : Measurable (fun ω : Fin n → Ω =>\n ⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ)))\n (hRmeas : Measurable (fun ω : Fin n → Ω =>\n empRadSigned n f (fun k => X (ω k))))\n (hint : ∀ i, Integrable (fun ω => f i (X ω)) μ)\n (hsym : (∫ ω, (⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ))\n ∂(Measure.pi (fun _ : Fin n => μ)))\n ≤ 2 * ∫ ω, empRadSigned n f (fun k => X (ω k))\n ∂(Measure.pi (fun _ : Fin n => μ)))\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ ≤ 1) :\n (Measure.pi (fun _ : Fin n => μ))\n {ω : Fin n → Ω |\n (⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ))\n ≤ 2 * empRadSigned n f\n (fun k => X (ω k))\n + 3 * Real.sqrt (Real.log (2 / δ) / (2 * n))}\n ≥ ENNReal.ofReal (1 - δ) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped NNReal\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\n\nprivate lemma abs_iSup_sub_iSup_le\n {I : Type*} [Nonempty I] (a b : I → ℝ) (M c : ℝ)\n (ha : ∀ i, |a i| ≤ M) (hb : ∀ i, |b i| ≤ M)\n (hab : ∀ i, |a i - b i| ≤ c) :\n |(⨆ i, a i) - (⨆ i, b i)| ≤ c := by\n have haB : BddAbove (Set.range a) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨i, rfl⟩\n exact (le_abs_self _).trans (ha i)\n have hbB : BddAbove (Set.range b) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨i, rfl⟩\n exact (le_abs_self _).trans (hb i)\n rw [abs_le]\n constructor\n · have hle : (⨆ i, b i) ≤ (⨆ i, a i) + c := by\n apply ciSup_le\n intro i\n calc\n b i ≤ a i + c := by\n have := (abs_le.mp (hab i)).1\n linarith\n _ ≤ (⨆ i, a i) + c := by gcongr; exact le_ciSup haB i\n exact (neg_le_sub_iff_le_add).2 hle\n · have hle : (⨆ i, a i) ≤ (⨆ i, b i) + c := by\n apply ciSup_le\n intro i\n calc\n a i ≤ b i + c := by\n have := (abs_le.mp (hab i)).2\n linarith\n _ ≤ (⨆ i, b i) + c := by gcongr; exact le_ciSup hbB i\n exact (sub_le_iff_le_add).2 (by simpa [add_comm] using hle)\n\nprivate lemma abs_iSup_le\n {I : Type*} [Nonempty I] (a : I → ℝ) (M : ℝ)\n (ha : ∀ i, |a i| ≤ M) : |⨆ i, a i| ≤ M := by\n have hM0 : 0 ≤ M := (abs_nonneg (a (Classical.choice inferInstance))).trans (ha _)\n have hB : BddAbove (Set.range a) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨i, rfl⟩\n exact (le_abs_self _).trans (ha i)\n rw [abs_le]\n constructor\n · have h := le_ciSup hB (Classical.choice inferInstance)\n have := (neg_le_of_abs_le (ha (Classical.choice inferInstance)))\n linarith\n · exact ciSup_le (fun i ↦ (le_abs_self _).trans (ha i))\n\nprivate lemma hasSubgaussianMGF_prod_step\n {A B : Type*} [MeasurableSpace A] [MeasurableSpace B] [Nonempty A]\n (mu : Measure A) [IsProbabilityMeasure mu]\n (nu : Measure B) [IsProbabilityMeasure nu]\n (F : A × B → ℝ) (hF : Measurable F)\n (M : ℝ) (hM : ∀ z, |F z| ≤ M)\n (c C : ℝ≥0)\n (hosc : ∀ y x x', |F (x, y) - F (x', y)| ≤ (c : ℝ))\n (havg : HasSubgaussianMGF\n (fun y ↦ (∫ x, F (x, y) ∂mu) - ∫ y, ∫ x, F (x, y) ∂mu ∂nu) C nu) :\n HasSubgaussianMGF\n (fun z ↦ F z - ∫ z, F z ∂(mu.prod nu)) (C + c ^ 2 / 4) (mu.prod nu) := by\n have hFint : Integrable F (mu.prod nu) :=\n Integrable.of_bound hF.aestronglyMeasurable M (ae_of_all _ (fun z ↦ by simpa using hM z))\n let Aavg : B → ℝ := fun y ↦ ∫ x, F (x, y) ∂mu\n have hAmeas : Measurable Aavg := by\n exact (StronglyMeasurable.integral_prod_left' (μ := mu) hF.stronglyMeasurable).measurable\n have hAint : Integrable Aavg nu := hFint.integral_prod_right\n have hmean : (∫ z, F z ∂(mu.prod nu)) = ∫ y, Aavg y ∂nu := by\n exact integral_prod_symm F hFint\n have hD (y : B) : HasSubgaussianMGF\n (fun x ↦ F (x, y) - Aavg y) (c ^ 2 / 4) mu := by\n let S : Set ℝ := Set.range (fun x ↦ F (x, y))\n have hSne : S.Nonempty := Set.range_nonempty _\n have hSbdAbove : BddAbove S := by\n refine ⟨M, ?_⟩\n rintro _ ⟨x, rfl⟩\n exact (le_abs_self _).trans (hM _)\n have hSbdBelow : BddBelow S := by\n refine ⟨-M, ?_⟩\n rintro _ ⟨x, rfl⟩\n exact (neg_le_of_abs_le (hM _))\n let a : ℝ := sInf S\n let b : ℝ := sSup S\n have hab_mem (x : A) : F (x, y) ∈ Set.Icc a b := by\n exact ⟨csInf_le hSbdBelow ⟨x, rfl⟩, le_csSup hSbdAbove ⟨x, rfl⟩⟩\n have hab : b - a ≤ (c : ℝ) := by\n have hb : b ≤ a + (c : ℝ) := by\n apply csSup_le hSne\n rintro _ ⟨x, rfl⟩\n have hxa : F (x, y) - (c : ℝ) ≤ a := by\n apply le_csInf hSne\n rintro _ ⟨x', rfl⟩\n have := hosc y x x'\n rw [abs_le] at this\n linarith\n linarith\n linarith\n have hba : 0 ≤ b - a := by\n let x : A := Classical.choice inferInstance\n exact sub_nonneg.mpr ((csInf_le hSbdBelow ⟨x, rfl⟩).trans\n (le_csSup hSbdAbove ⟨x, rfl⟩))\n have hcenter : ∫ x, (F (x, y) - Aavg y) ∂mu = 0 := by\n rw [integral_sub]\n · simp [Aavg]\n · exact Integrable.of_bound (hF.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable\n M (ae_of_all _ (fun x ↦ by simpa using hM (x, y)))\n · fun_prop\n have hbase := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero\n ((hF.comp (measurable_id.prodMk measurable_const)).sub_const _).aemeasurable\n (ae_of_all _ (fun x ↦ show F (x, y) - Aavg y ∈\n Set.Icc (a - Aavg y) (b - Aavg y) by simpa using hab_mem x)) hcenter\n refine ⟨hbase.integrable_exp_mul, fun t ↦ ?_⟩\n calc\n mgf (fun x ↦ F (x, y) - Aavg y) mu t\n ≤ exp (((‖(b - Aavg y) - (a - Aavg y)‖₊ / 2 : ℝ≥0) ^ 2 : ℝ) * t ^ 2 / 2) :=\n hbase.mgf_le t\n _ ≤ exp (((c ^ 2 / 4 : ℝ≥0) : ℝ) * t ^ 2 / 2) := by\n gcongr\n rw [show (b - Aavg y) - (a - Aavg y) = b - a by ring]\n change (((‖b - a‖₊ / 2 : ℝ≥0) ^ 2 : ℝ)) ≤ (((c ^ 2 / 4 : ℝ≥0) : ℝ))\n push_cast\n rw [Real.norm_eq_abs, abs_of_nonneg hba]\n nlinarith [c.coe_nonneg]\n have hcenter_meas : Measurable (fun z ↦ F z - ∫ z, F z ∂(mu.prod nu)) := hF.sub_const _\n refine ⟨?_, ?_⟩\n · intro t\n apply Integrable.of_bound (by fun_prop) (exp (|t| * (M + M)))\n filter_upwards [] with z\n rw [Real.norm_eq_abs, abs_exp, Real.exp_le_exp]\n have hmean_abs : |∫ z, F z ∂(mu.prod nu)| ≤ M := by\n calc\n |∫ z, F z ∂(mu.prod nu)| ≤ ∫ z, |F z| ∂(mu.prod nu) := abs_integral_le_integral_abs\n _ ≤ ∫ _z, M ∂(mu.prod nu) := integral_mono_ae hFint.abs\n (integrable_const _) (ae_of_all _ hM)\n _ = M := by simp\n calc\n t * (F z - ∫ z, F z ∂(mu.prod nu))\n ≤ |t| * |F z - ∫ z, F z ∂(mu.prod nu)| := by\n simpa [abs_mul] using\n (le_abs_self (t * (F z - ∫ z, F z ∂(mu.prod nu))))\n _ ≤ |t| * (M + M) := by\n gcongr\n exact (abs_sub _ _).trans (add_le_add (hM z) hmean_abs)\n · intro t\n rw [mgf, hmean]\n have hExpInt : Integrable\n (fun z ↦ exp (t * (F z - ∫ y, Aavg y ∂nu))) (mu.prod nu) := by\n simpa [hmean] using\n (show Integrable (fun z ↦ exp (t * (F z - ∫ z, F z ∂(mu.prod nu))))\n (mu.prod nu) from by\n apply Integrable.of_bound (by fun_prop) (exp (|t| * (M + M)))\n filter_upwards [] with z\n rw [Real.norm_eq_abs, abs_exp, Real.exp_le_exp]\n have hmean_abs : |∫ z, F z ∂(mu.prod nu)| ≤ M := by\n calc\n |∫ z, F z ∂(mu.prod nu)| ≤ ∫ z, |F z| ∂(mu.prod nu) := abs_integral_le_integral_abs\n _ ≤ ∫ _z, M ∂(mu.prod nu) := integral_mono_ae hFint.abs\n (integrable_const _) (ae_of_all _ hM)\n _ = M := by simp\n calc\n t * (F z - ∫ z, F z ∂(mu.prod nu)) ≤\n |t| * |F z - ∫ z, F z ∂(mu.prod nu)| :=\n (by simpa [abs_mul] using\n (le_abs_self (t * (F z - ∫ z, F z ∂(mu.prod nu)))))\n _ ≤ |t| * (M + M) := by\n gcongr\n exact (abs_sub _ _).trans (add_le_add (hM z) hmean_abs))\n rw [integral_prod_symm _ hExpInt]\n calc\n (∫ y, ∫ x, exp (t * (F (x, y) - ∫ y, Aavg y ∂nu)) ∂mu ∂nu)\n = ∫ y, exp (t * (Aavg y - ∫ y, Aavg y ∂nu)) *\n mgf (fun x ↦ F (x, y) - Aavg y) mu t ∂nu := by\n apply integral_congr_ae\n filter_upwards [] with y\n rw [mgf, ← integral_const_mul]\n apply integral_congr_ae\n filter_upwards [] with x\n rw [← Real.exp_add]\n congr 1\n ring\n _ ≤ ∫ y, exp (t * (Aavg y - ∫ y, Aavg y ∂nu)) *\n exp ((((c ^ 2 / 4 : ℝ≥0) : ℝ) * t ^ 2 / 2)) ∂nu := by\n apply integral_mono_of_nonneg\n · filter_upwards [] with y\n exact mul_nonneg (Real.exp_nonneg _)\n (integral_nonneg (fun _ ↦ Real.exp_nonneg _))\n · exact (havg.integrable_exp_mul t).mul_const _\n · filter_upwards [] with y\n gcongr\n exact (hD y).mgf_le t\n _ = mgf (fun y ↦ Aavg y - ∫ y, Aavg y ∂nu) nu t *\n exp ((((c ^ 2 / 4 : ℝ≥0) : ℝ) * t ^ 2 / 2)) := by\n rw [mgf, integral_mul_const]\n _ ≤ exp (((C : ℝ) * t ^ 2 / 2)) *\n exp ((((c ^ 2 / 4 : ℝ≥0) : ℝ) * t ^ 2 / 2)) := by\n gcongr\n simpa [Aavg] using havg.mgf_le t\n _ = exp ((((C + c ^ 2 / 4 : ℝ≥0) : ℝ) * t ^ 2 / 2)) := by\n rw [← Real.exp_add]\n push_cast\n ring\n\nprivate lemma hasSubgaussianMGF_pi_boundedDifferences\n {Omega : Type*} [MeasurableSpace Omega] [Nonempty Omega]\n (mu : Measure Omega) [IsProbabilityMeasure mu]\n (m : ℕ) (F : (Fin m → Omega) → ℝ) (hF : Measurable F)\n (M : ℝ) (hM : ∀ x, |F x| ≤ M)\n (c : ℝ≥0)\n (hosc : ∀ x x' (i : Fin m), (∀ j, j ≠ i → x j = x' j) →\n |F x - F x'| ≤ (c : ℝ)) :\n HasSubgaussianMGF\n (fun x ↦ F x - ∫ x, F x ∂(Measure.pi (fun _ : Fin m ↦ mu)))\n ((m : ℝ≥0) * c ^ 2 / 4) (Measure.pi (fun _ : Fin m ↦ mu)) := by\n induction m with\n | zero =>\n let x0 : Fin 0 → Omega := fun i ↦ Fin.elim0 i\n have hconst : F = fun _ ↦ F x0 := by\n funext x\n congr 1\n funext i\n exact Fin.elim0 i\n have hmean0 : (∫ x, F x ∂(Measure.pi (fun _ : Fin 0 ↦ mu))) = F x0 := by\n rw [hconst]\n simp\n have hz : (fun x ↦ F x - ∫ x, F x ∂(Measure.pi (fun _ : Fin 0 ↦ mu))) =\n fun _ ↦ 0 := by\n funext x\n rw [hmean0, congrFun hconst x]\n simp\n simpa [hz] using\n (HasSubgaussianMGF.fun_zero (mu := Measure.pi (fun _ : Fin 0 ↦ mu)))\n | succ m ih =>\n let Pm : Measure (Fin m → Omega) := Measure.pi (fun _ : Fin m ↦ mu)\n let e : (Fin (m + 1) → Omega) ≃ᵐ (Omega × (Fin m → Omega)) :=\n MeasurableEquiv.piFinSuccAbove (fun _ : Fin (m + 1) ↦ Omega) 0\n let G : Omega × (Fin m → Omega) → ℝ := fun z ↦ F (e.symm z)\n have hG : Measurable G := hF.comp e.symm.measurable\n have hGM : ∀ z, |G z| ≤ M := fun z ↦ hM _\n let Aavg : (Fin m → Omega) → ℝ := fun y ↦ ∫ x, G (x, y) ∂mu\n have hGint : Integrable G (mu.prod Pm) :=\n Integrable.of_bound hG.aestronglyMeasurable M (ae_of_all _ (fun z ↦ by simpa using hGM z))\n have hAmeas : Measurable Aavg := by\n exact (StronglyMeasurable.integral_prod_left' (μ := mu) hG.stronglyMeasurable).measurable\n have hAM : ∀ y, |Aavg y| ≤ M := by\n intro y\n calc\n |Aavg y| ≤ ∫ x, |G (x, y)| ∂mu := abs_integral_le_integral_abs\n _ ≤ ∫ _x, M ∂mu := by\n apply integral_mono_ae\n · exact Integrable.of_bound\n (hG.comp (measurable_id.prodMk measurable_const)).abs.aestronglyMeasurable M\n (ae_of_all _ (fun x ↦ by simpa using hGM (x, y)))\n · exact integrable_const _\n · exact ae_of_all _ (fun x ↦ hGM (x, y))\n _ = M := by simp\n have hAosc : ∀ y y' (i : Fin m), (∀ j, j ≠ i → y j = y' j) →\n |Aavg y - Aavg y'| ≤ (c : ℝ) := by\n intro y y' i hy\n have hsec (y : Fin m → Omega) : Integrable (fun x ↦ G (x, y)) mu :=\n Integrable.of_bound (hG.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable\n M (ae_of_all _ (fun x ↦ by simpa using hGM (x, y)))\n rw [show Aavg y - Aavg y' = ∫ x, (G (x, y) - G (x, y')) ∂mu by\n rw [integral_sub (hsec y) (hsec y')]]\n calc\n |∫ x, (G (x, y) - G (x, y')) ∂mu| ≤\n ∫ x, |G (x, y) - G (x, y')| ∂mu := abs_integral_le_integral_abs\n _ ≤ ∫ _x, (c : ℝ) ∂mu := by\n apply integral_mono_ae\n · exact (hsec y).sub (hsec y') |>.abs\n · exact integrable_const _\n · filter_upwards [] with x\n apply hosc (e.symm (x, y)) (e.symm (x, y')) (Fin.succ i)\n intro j hj\n revert hj\n refine Fin.cases (fun _ ↦ ?_) (fun k hk ↦ ?_) j\n · simp [G, e, MeasurableEquiv.piFinSuccAbove_symm_apply]\n · simp only [G, e, MeasurableEquiv.piFinSuccAbove_symm_apply,\n Fin.insertNthEquiv_apply, Fin.insertNth_apply_succAbove]\n exact hy k (by\n intro hki\n subst k\n exact hk rfl)\n _ = (c : ℝ) := by simp\n have hA := ih Aavg hAmeas hAM hAosc\n have hfirst : ∀ y x x', |G (x, y) - G (x', y)| ≤ (c : ℝ) := by\n intro y x x'\n apply hosc (e.symm (x, y)) (e.symm (x', y)) 0\n intro j hj\n revert hj\n refine Fin.cases (fun hj ↦ False.elim (hj rfl)) (fun k _ ↦ ?_) j\n simp [e, MeasurableEquiv.piFinSuccAbove_symm_apply]\n have hpair := hasSubgaussianMGF_prod_step mu Pm G hG M hGM c\n (((m : ℝ≥0) * c ^ 2 / 4)) hfirst (by simpa [Aavg, Pm] using hA)\n have he_mp := measurePreserving_piFinSuccAbove (fun _ : Fin (m + 1) ↦ mu) 0\n have hmap : (Measure.pi (fun _ : Fin (m + 1) ↦ mu)).map e = mu.prod Pm := by\n simpa [e, Pm] using he_mp.map_eq\n have htrans := HasSubgaussianMGF.of_map e.measurable.aemeasurable (by\n rw [hmap]\n exact hpair)\n have hGe (x : Fin (m + 1) → Omega) : G (e x) = F x := by\n change F (e.symm (e x)) = F x\n rw [e.symm_apply_apply]\n have hmean : (∫ z, G z ∂(mu.prod Pm)) =\n ∫ x, F x ∂(Measure.pi (fun _ : Fin (m + 1) ↦ mu)) := by\n symm\n calc\n (∫ x, F x ∂(Measure.pi (fun _ : Fin (m + 1) ↦ mu))) =\n ∫ x, G (e x) ∂(Measure.pi (fun _ : Fin (m + 1) ↦ mu)) := by\n apply integral_congr_ae\n exact ae_of_all _ (fun x ↦ (hGe x).symm)\n _ = ∫ z, G z ∂(mu.prod Pm) := by\n simpa [e, Pm] using he_mp.integral_comp' G\n have hfun : (fun z ↦ G z - ∫ z, G z ∂(mu.prod Pm)) ∘ e =\n (fun x ↦ F x - ∫ x, F x ∂(Measure.pi (fun _ : Fin (m + 1) ↦ mu))) := by\n funext x\n change G (e x) - ∫ z, G z ∂(mu.prod Pm) =\n F x - ∫ x, F x ∂(Measure.pi (fun _ : Fin (m + 1) ↦ mu))\n rw [hGe x, hmean]\n rw [hfun] at htrans\n convert htrans using 1 <;> push_cast <;> ring\n\ntheorem ch4_theorem_4_18\n {Ω : Type u} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {ι : Type v} [Nonempty ι]\n {𝒳 : Type w} [MeasurableSpace 𝒳]\n (n : ℕ) (hn : 0 < n)\n (f : ι → 𝒳 → ℝ)\n (X : Ω → 𝒳) (hX : Measurable X)\n (hf01 : ∀ i, ∀ z : 𝒳, 0 ≤ f i z ∧ f i z ≤ 1)\n (hfmeas : ∀ i, Measurable (fun z => f i z))\n (hgmeas : Measurable (fun ω : Fin n → Ω =>\n ⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ)))\n (hRmeas : Measurable (fun ω : Fin n → Ω =>\n empRadSigned n f (fun k => X (ω k))))\n (hint : ∀ i, Integrable (fun ω => f i (X ω)) μ)\n (hsym : (∫ ω, (⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ))\n ∂(Measure.pi (fun _ : Fin n => μ)))\n ≤ 2 * ∫ ω, empRadSigned n f (fun k => X (ω k))\n ∂(Measure.pi (fun _ : Fin n => μ)))\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ ≤ 1) :\n (Measure.pi (fun _ : Fin n => μ))\n {ω : Fin n → Ω |\n (⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ))\n ≤ 2 * empRadSigned n f\n (fun k => X (ω k))\n + 3 * Real.sqrt (Real.log (2 / δ) / (2 * n))}\n ≥ ENNReal.ofReal (1 - δ) := by\n classical\n let P : Measure (Fin n → Ω) := Measure.pi (fun _ : Fin n ↦ μ)\n let g : (Fin n → Ω) → ℝ := fun ω ↦\n ⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ)\n let R : (Fin n → Ω) → ℝ := fun ω ↦\n empRadSigned n f (fun k ↦ X (ω k))\n let H : (Fin n → Ω) → ℝ := fun ω ↦ g ω - 2 * R ω\n have hnonempty : Nonempty Ω := by\n obtain ⟨x, _⟩ := nonempty_of_measure_ne_zero (μ := μ) (s := Set.univ) (by simp)\n exact ⟨x⟩\n letI : Nonempty Ω := hnonempty\n have hYmeas (i : ι) : Measurable (fun ω ↦ f i (X ω)) := (hfmeas i).comp hX\n have hmean01 (i : ι) : 0 ≤ ∫ x, f i (X x) ∂μ ∧ ∫ x, f i (X x) ∂μ ≤ 1 := by\n constructor\n · exact integral_nonneg_of_ae (ae_of_all _ (fun x ↦ (hf01 i _).1))\n · calc\n (∫ x, f i (X x) ∂μ) ≤ ∫ _x, (1 : ℝ) ∂μ :=\n integral_mono_ae (hint i) (integrable_const _)\n (ae_of_all _ (fun x ↦ (hf01 i _).2))\n _ = 1 := by simp\n have hemp01 (i : ι) (ω : Fin n → Ω) :\n 0 ≤ (n : ℝ)⁻¹ * ∑ k, f i (X (ω k)) ∧\n (n : ℝ)⁻¹ * ∑ k, f i (X (ω k)) ≤ 1 := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n constructor\n · exact mul_nonneg (inv_nonneg.mpr hnR.le)\n (Finset.sum_nonneg (fun k _ ↦ (hf01 i _).1))\n · have hs : (∑ k : Fin n, f i (X (ω k))) ≤ n := by\n calc\n (∑ k : Fin n, f i (X (ω k))) ≤ ∑ _k : Fin n, (1 : ℝ) := by\n gcongr with k\n exact (hf01 i _).2\n _ = n := by simp\n calc\n (n : ℝ)⁻¹ * ∑ k, f i (X (ω k)) ≤ (n : ℝ)⁻¹ * n := by\n gcongr\n _ = 1 := by field_simp\n have hg_bound (ω : Fin n → Ω) : |g ω| ≤ 1 := by\n apply abs_iSup_le _ 1\n intro i\n rw [abs_le]\n constructor <;> linarith [hemp01 i ω, hmean01 i]\n have hsigma_abs (sigma : RadSigns n) (k : Fin n) : |(sigma k : ℝ)| = 1 := by\n have hk := (sigma k).property\n simp only [Finset.mem_insert, Finset.mem_singleton] at hk\n rcases hk with hk | hk <;> simp [hk]\n have hsigned_bound (sigma : RadSigns n) (i : ι) (ω : Fin n → Ω) :\n |(n : ℝ)⁻¹ * ∑ k, (sigma k : ℝ) * f i (X (ω k))| ≤ 1 := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n rw [abs_mul]\n calc\n |(n : ℝ)⁻¹| * |∑ k, (sigma k : ℝ) * f i (X (ω k))| ≤\n (n : ℝ)⁻¹ * ∑ k, |(sigma k : ℝ) * f i (X (ω k))| := by\n rw [abs_of_pos (inv_pos.mpr hnR)]\n gcongr\n exact Finset.abs_sum_le_sum_abs _ _\n _ ≤ (n : ℝ)⁻¹ * ∑ _k : Fin n, (1 : ℝ) := by\n gcongr with k\n rw [abs_mul, hsigma_abs]\n rw [one_mul, abs_of_nonneg (hf01 i (X (ω k))).1]\n exact (hf01 i (X (ω k))).2\n _ = 1 := by simp [hnR.ne']\n have hrSigma_bound (sigma : RadSigns n) (ω : Fin n → Ω) :\n |⨆ i, (n : ℝ)⁻¹ * ∑ k, (sigma k : ℝ) * f i (X (ω k))| ≤ 1 :=\n abs_iSup_le _ 1 (fun i ↦ hsigned_bound sigma i ω)\n letI : Nonempty (RadSigns n) :=\n ⟨fun _ ↦ ⟨1, by simp⟩⟩\n have hcard : 0 < Fintype.card (RadSigns n) := Fintype.card_pos\n have hR_bound (ω : Fin n → Ω) : |R ω| ≤ 1 := by\n rw [show R ω = (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ sigma : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k, (sigma k : ℝ) * f i (X (ω k)) by rfl]\n rw [abs_mul, abs_of_pos (inv_pos.mpr (by exact_mod_cast hcard))]\n calc\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n |∑ sigma : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k, (sigma k : ℝ) * f i (X (ω k))| ≤\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ _sigma : RadSigns n, (1 : ℝ) := by\n gcongr\n exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun sigma _ ↦ hrSigma_bound sigma ω))\n _ = 1 := by simp [Nat.ne_of_gt hcard]\n have hH_bound (ω : Fin n → Ω) : |H ω| ≤ 3 := by\n dsimp [H]\n calc\n |g ω - 2 * R ω| ≤ |g ω| + 2 * |R ω| := by\n calc\n |g ω - 2 * R ω| ≤ |g ω| + |2 * R ω| := abs_sub _ _\n _ = |g ω| + 2 * |R ω| := by rw [abs_mul]; norm_num\n _ ≤ 3 := by linarith [hg_bound ω, hR_bound ω]\n have hHmeas : Measurable H := by\n exact hgmeas.sub (hRmeas.const_mul 2)\n have hcoord_g (ω ω' : Fin n → Ω) (j : Fin n)\n (heq : ∀ k, k ≠ j → ω k = ω' k) :\n |g ω - g ω'| ≤ (n : ℝ)⁻¹ := by\n apply abs_iSup_sub_iSup_le _ _ 1 (n : ℝ)⁻¹\n · intro i\n rw [abs_le]\n constructor <;> linarith [hemp01 i ω, hmean01 i]\n · intro i\n rw [abs_le]\n constructor <;> linarith [hemp01 i ω', hmean01 i]\n · intro i\n have hsum : (∑ k, f i (X (ω k))) - (∑ k, f i (X (ω' k))) =\n f i (X (ω j)) - f i (X (ω' j)) := by\n rw [← Finset.sum_sub_distrib, Finset.sum_eq_single j]\n · intro k _ hkj\n rw [heq k hkj]\n simp\n · simp\n rw [show ((n : ℝ)⁻¹ * ∑ k, f i (X (ω k)) - ∫ x, f i (X x) ∂μ) -\n ((n : ℝ)⁻¹ * ∑ k, f i (X (ω' k)) - ∫ x, f i (X x) ∂μ) =\n (n : ℝ)⁻¹ * (f i (X (ω j)) - f i (X (ω' j))) by rw [← hsum]; ring]\n rw [abs_mul, abs_of_nonneg (inv_nonneg.mpr (by positivity))]\n calc\n (n : ℝ)⁻¹ * |f i (X (ω j)) - f i (X (ω' j))| ≤\n (n : ℝ)⁻¹ * 1 := by\n apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (by positivity))\n rw [abs_le]\n constructor <;> linarith [hf01 i (X (ω j)), hf01 i (X (ω' j))]\n _ = (n : ℝ)⁻¹ := mul_one _\n have hcoord_R (ω ω' : Fin n → Ω) (j : Fin n)\n (heq : ∀ k, k ≠ j → ω k = ω' k) :\n |R ω - R ω'| ≤ (n : ℝ)⁻¹ := by\n let r : RadSigns n → (Fin n → Ω) → ℝ := fun sigma s ↦\n ⨆ i, (n : ℝ)⁻¹ * ∑ k, (sigma k : ℝ) * f i (X (s k))\n have hr (sigma : RadSigns n) : |r sigma ω - r sigma ω'| ≤ (n : ℝ)⁻¹ := by\n apply abs_iSup_sub_iSup_le _ _ 1 (n : ℝ)⁻¹\n · exact fun i ↦ hsigned_bound sigma i ω\n · exact fun i ↦ hsigned_bound sigma i ω'\n · intro i\n have hsum :\n (∑ k, (sigma k : ℝ) * f i (X (ω k))) -\n (∑ k, (sigma k : ℝ) * f i (X (ω' k))) =\n (sigma j : ℝ) * (f i (X (ω j)) - f i (X (ω' j))) := by\n rw [← Finset.sum_sub_distrib, Finset.sum_eq_single j]\n · ring\n · intro k _ hkj\n rw [heq k hkj]\n simp\n · simp\n rw [show ((n : ℝ)⁻¹ * ∑ k, (sigma k : ℝ) * f i (X (ω k))) -\n ((n : ℝ)⁻¹ * ∑ k, (sigma k : ℝ) * f i (X (ω' k))) =\n (n : ℝ)⁻¹ * ((sigma j : ℝ) *\n (f i (X (ω j)) - f i (X (ω' j)))) by rw [← hsum]; ring]\n rw [abs_mul, abs_of_nonneg (inv_nonneg.mpr (by positivity)), abs_mul, hsigma_abs, one_mul]\n calc\n (n : ℝ)⁻¹ * |f i (X (ω j)) - f i (X (ω' j))| ≤\n (n : ℝ)⁻¹ * 1 := by\n apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (by positivity))\n rw [abs_le]\n constructor <;> linarith [hf01 i (X (ω j)), hf01 i (X (ω' j))]\n _ = (n : ℝ)⁻¹ := mul_one _\n change |(Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ sigma, r sigma ω -\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ sigma, r sigma ω'| ≤ (n : ℝ)⁻¹\n rw [← mul_sub, ← Finset.sum_sub_distrib, abs_mul,\n abs_of_pos (inv_pos.mpr (by exact_mod_cast hcard))]\n calc\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n |∑ sigma, (r sigma ω - r sigma ω')| ≤\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ _sigma : RadSigns n, (n : ℝ)⁻¹ := by\n gcongr\n exact (Finset.abs_sum_le_sum_abs _ _).trans\n (Finset.sum_le_sum (fun sigma _ ↦ hr sigma))\n _ = (n : ℝ)⁻¹ := by\n rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]\n field_simp\n have hcoord_H (ω ω' : Fin n → Ω) (j : Fin n)\n (heq : ∀ k, k ≠ j → ω k = ω' k) :\n |H ω - H ω'| ≤ 3 * (n : ℝ)⁻¹ := by\n dsimp [H]\n calc\n |(g ω - 2 * R ω) - (g ω' - 2 * R ω')| ≤\n |g ω - g ω'| + 2 * |R ω - R ω'| := by\n calc\n _ = |(g ω - g ω') - 2 * (R ω - R ω')| := by ring_nf\n _ ≤ |g ω - g ω'| + |2 * (R ω - R ω')| := abs_sub _ _\n _ = _ := by rw [abs_mul]; norm_num\n _ ≤ 3 * (n : ℝ)⁻¹ := by\n linarith [hcoord_g ω ω' j heq, hcoord_R ω ω' j heq]\n have hmeanH : (∫ ω, H ω ∂P) ≤ 0 := by\n have hgint : Integrable g P :=\n Integrable.of_bound hgmeas.aestronglyMeasurable 1 (ae_of_all _ hg_bound)\n have hRint : Integrable R P :=\n Integrable.of_bound hRmeas.aestronglyMeasurable 1 (ae_of_all _ hR_bound)\n dsimp [H]\n rw [integral_sub hgint (hRint.const_mul 2), integral_const_mul]\n exact sub_nonpos.mpr hsym\n let c : ℝ≥0 := ⟨3 * (n : ℝ)⁻¹, mul_nonneg (by norm_num) (inv_nonneg.mpr (by positivity))⟩\n have hsubG := hasSubgaussianMGF_pi_boundedDifferences μ n H hHmeas 3 hH_bound c (by\n intro ω ω' j heq\n exact hcoord_H ω ω' j heq)\n let q : ℝ := Real.log (2 / δ)\n let eps : ℝ := 3 * Real.sqrt (q / (2 * n))\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n have hratio : 1 < 2 / δ := by\n rw [lt_div_iff₀ hδ0]\n linarith\n have hq : 0 < q := Real.log_pos hratio\n have harg : 0 ≤ q / (2 * (n : ℝ)) := div_nonneg hq.le (by positivity)\n have heps0 : 0 ≤ eps := mul_nonneg (by norm_num) (Real.sqrt_nonneg _)\n have hcval : ((((n : ℝ≥0) * c ^ 2 / 4 : ℝ≥0) : ℝ)) = 9 / (4 * n) := by\n dsimp [c]\n push_cast\n field_simp [hnR.ne']\n ring\n have hepssq : eps ^ 2 = 9 * (q / (2 * n)) := by\n dsimp [eps]\n rw [mul_pow, Real.sq_sqrt harg]\n norm_num\n have hexp : Real.exp (-eps ^ 2 /\n (2 * ((((n : ℝ≥0) * c ^ 2 / 4 : ℝ≥0) : ℝ)))) = δ / 2 := by\n rw [hcval, hepssq]\n have hinside : -(9 * (q / (2 * (n : ℝ)))) / (2 * (9 / (4 * n))) = -q := by\n field_simp [hnR.ne']\n ring\n rw [hinside, Real.exp_neg, Real.exp_log (by positivity : 0 < 2 / δ)]\n field_simp [hδ0.ne']\n have htail_center : P.real {ω | eps ≤ H ω - ∫ ω, H ω ∂P} ≤ δ := by\n have ht := hsubG.measure_ge_le heps0\n rw [hexp] at ht\n exact ht.trans (by linarith)\n have hfail_subset : {ω | eps < H ω} ⊆\n {ω | eps ≤ H ω - ∫ ω, H ω ∂P} := by\n intro ω homega\n dsimp only [Set.mem_setOf_eq] at homega ⊢\n linarith\n have hfail : P.real {ω | eps < H ω} ≤ δ :=\n (measureReal_mono hfail_subset).trans htail_center\n have hfail_meas : MeasurableSet {ω | eps < H ω} :=\n measurableSet_lt measurable_const hHmeas\n have hsuccess_real : 1 - δ ≤ P.real {ω | H ω ≤ eps} := by\n have hcompl : {ω | H ω ≤ eps} = {ω | eps < H ω}ᶜ := by\n ext ω\n simp\n rw [hcompl, measureReal_compl hfail_meas, measureReal_univ_eq_one]\n linarith\n have hevent :\n {ω : Fin n → Ω |\n (⨆ i, ((n : ℝ)⁻¹ * ∑ k : Fin n, f i (X (ω k)) - ∫ x, f i (X x) ∂μ)) ≤\n 2 * empRadSigned n f (fun k ↦ X (ω k)) +\n 3 * Real.sqrt (Real.log (2 / δ) / (2 * n))} =\n {ω | H ω ≤ eps} := by\n ext ω\n change g ω ≤ 2 * R ω +\n 3 * Real.sqrt (Real.log (2 / ��) / (2 * (n : ℝ))) ↔ H ω ≤ eps\n dsimp [H, eps, q]\n constructor <;> intro h <;> linarith\n rw [hevent]\n apply (ENNReal.ofReal_le_iff_le_toReal (measure_ne_top _ _)).2\n dsimp [P] at hsuccess_real\n simpa [Measure.real_def] using hsuccess_real\n\nend GraduateLevel\n"} +{"id": "ch4_theorem_4_16", "source": "Graduate-level", "targets": [{"label": "ch4_theorem_4_16", "decls": ["ch4_theorem_4_16"], "statement": "Let \\(\\mathcal{F}\\) be a family of functions \\(Z \\mapsto [-1,1]\\). Then\n\\[\nR_S(\\mathcal{F})\\le\\inf_{\\epsilon>0}\\left(\\epsilon+\\sqrt{\\frac{2\\log N(\\epsilon,\\mathcal{F},L_2(P_n))}{n}}\\right).\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Fix any \\(\\epsilon > 0\\). Let \\(\\mathcal{C}\\) be the minimal \\(\\epsilon\\)-cover of \\(\\mathcal{Q}\\) with respect to the metric \\(\\rho(v,v') = \\frac{1}{\\sqrt{n}} \\|v-v'\\|_2\\). Note that \\(|\\mathcal{C}| = N(\\epsilon, \\mathcal{Q}, \\frac{1}{\\sqrt{n}} \\|\\cdot\\|_2) = N(\\epsilon, \\mathcal{F}, L_2(P_n))\\).\n\nWe aim to bound \\(R_S(\\mathcal{F}) = \\mathbb{E}_\\sigma[\\sup_{v \\in \\mathcal{Q}} \\frac{1}{n} \\langle v, \\sigma \\rangle]\\) by approximating \\(v\\) with \\(v' \\in \\mathcal{C}\\). In particular, for every point \\(v \\in \\mathcal{Q}\\), choose \\(v' \\in \\mathcal{C}\\) such that \\(\\rho(v, v') \\leq \\epsilon\\) and \\(z\\) is small (specifically, \\(\\frac{1}{\\sqrt{n}} \\|z\\|_2 \\le \\epsilon\\)). This gives\n\\[\n\\frac{1}{n} \\langle v, \\sigma \\rangle = \\frac{1}{n} \\langle v', \\sigma \\rangle + \\frac{1}{n} \\langle v - v', \\sigma \\rangle \\le \\frac{1}{n} \\langle v', \\sigma \\rangle + \\frac{1}{n} \\|z\\|_2 \\|\\sigma\\|_2 \\le \\frac{1}{n} \\langle v', \\sigma \\rangle + \\epsilon,\n\\]\nwhere \\(z \\stackrel{\\Delta}{=} v - v'\\), using Cauchy-Schwarz and the fact that \\(\\|z\\|_2 \\le \\sqrt{n}\\epsilon\\) and \\(\\|\\sigma\\|_2 \\le \\sqrt{n}\\).\n\nTaking the expectation of the supremum on both sides gives\n\\[\nR_S(\\mathcal{F}) = \\mathbb{E}_\\sigma \\left[\\sup_{v\\in \\mathcal{Q}} \\frac{1}{n} \\langle v,\\sigma \\rangle \\right] \\le \\mathbb{E}_\\sigma \\left[\\sup_{v'\\in \\mathcal{C}} \\left(\\frac{1}{n} \\langle v',\\sigma \\rangle + \\epsilon\\right)\\right] = \\epsilon + \\mathbb{E}_\\sigma \\left[\\sup_{v'\\in \\mathcal{C}} \\frac{1}{n} \\langle v',\\sigma \\rangle\\right] \\le \\epsilon + \\sqrt{ \\frac{2\\log |\\mathcal{C}|}{n} },\n\\]\nby Massart's lemma (the referenced result). Since the argument holds for any \\(\\epsilon > 0\\), taking the infimum over all \\(\\epsilon\\) yields \\(R_S(\\mathcal{F})\\le\\inf_{\\epsilon>0}\\left(\\epsilon+\\sqrt{\\frac{2\\log N(\\epsilon,\\mathcal{F},L_2(P_n))}{n}}\\right)\\).", "context": [{"id": "ch4:definition:4_8", "name": "Empirical Rademacher complexity", "statement": "Given a dataset \\(S = \\{z_1, \\dots, z_n\\}\\), the empirical Rademacher complexity is defined as\n\\[\nR_S(\\mathcal{F}) \\stackrel{\\Delta}{=} \\mathbb{E}_{\\sigma_1,\\dots, \\sigma_n} \\left[ \\sup_{f\\in \\mathcal{F}} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i) \\right].\n\\]\n\\(R_S(\\mathcal{F})\\) is a function of both the function class \\(\\mathcal{F}\\) and the dataset \\(S\\)."}, {"id": "ch4:definition:4_14", "name": "definition 4.14", "statement": "\\(\\mathcal{C}\\) is an \\(\\epsilon\\)-cover of \\(\\mathcal{Q}\\) with respect to metric \\(\\rho\\) if for all \\(v' \\in \\mathcal{Q}\\), there exists \\(v \\in \\mathcal{C}\\) such that \\(\\rho(v,v')\\le \\epsilon\\)."}, {"id": "ch4:definition:4_15", "name": "definition 4.15", "statement": "The covering number is defined as the minimum size of an \\(\\epsilon\\)-cover, or explicitly:\n\\[\nN(\\epsilon, \\mathcal{Q}, \\rho) \\stackrel{\\Delta}{=} (\\text{min size of } \\epsilon\\text{-cover of } \\mathcal{Q} \\text{ w.r.t. metric } \\rho).\n\\]"}, {"id": "ch4:proposition:4_12", "name": "proposition 4.12", "statement": "Let \\(\\mathcal{F}\\) be a collection of functions mapping \\(Z \\mapsto \\mathbb{R}\\) and let \\(\\mathcal{Q}\\) be defined as in the referenced equation. Assume that \\(\\frac{1}{\\sqrt{n}} \\|v\\|_2 \\le M < \\infty\\) for all \\(v \\in \\mathcal{Q}\\). Then,\n\\[\nR_S(\\mathcal{F}) \\leq \\sqrt{\\frac{2 M^2 \\log |\\mathcal{Q}|}{n}}.\n\\]"}, {"id": "ch4_theorem_4_16:fix:1", "name": "Output space \\(\\mathcal{Q}\\) and the \\(L_2(P_n)\\) metric", "statement": "Given a dataset \\(S = \\{z_1, \\dots, z_n\\}\\), define the output space\n\\[\n\\mathcal{Q} \\triangleq \\left\\{ \\left(f(z_1), \\dots, f(z_n)\\right)^\\top : f \\in \\mathcal{F} \\right\\} \\subseteq \\mathbb{R}^n.\n\\]\nCorrespondingly, the empirical Rademacher complexity can be rewritten as a maximization over the output space \\(\\mathcal{Q}\\) instead of the function space \\(\\mathcal{F}\\):\n\\[\nR_S(\\mathcal{F}) = \\mathbb{E}_{\\sigma}\\left[ \\sup_{v \\in \\mathcal{Q}} \\frac{1}{n} \\langle \\sigma, v \\rangle \\right].\n\\]\nWe use the metric \\(\\rho(v, v') = \\frac{1}{\\sqrt{n}} \\|v - v'\\|_2\\). In the literature, an \\(\\epsilon\\)-cover of \\(\\mathcal{Q}\\) with respect to \\(\\rho\\) is also referred to as an \\(\\epsilon\\)-cover of the function class \\(\\mathcal{F}\\) under the \\(L_2(P_n)\\) metric, where \\(P_n\\) denotes the empirical distribution, i.e. the uniform distribution over the observations \\(z_1, \\dots, z_n\\). In particular,\n\\[\nL_2(P_n)(f, f') = \\sqrt{\\frac{1}{n} \\sum_{i=1}^n (f(z_i) - f'(z_i))^2}.\n\\]\nWe can write a trivial correspondence between both the output and function class points of view as follows:\n\\[\nN(\\epsilon, \\mathcal{F}, L_2(P_n)) = N\\left(\\epsilon, \\mathcal{Q}, \\frac{1}{\\sqrt{n}} \\|\\cdot\\|_2\\right).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def empiricalNorm (n : ℕ) (f : Fin n → ℝ) : ℝ :=\n Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, f k ^ 2)\n\nlemma empiricalNorm_nonneg (n : ℕ) (f : Fin n → ℝ) : 0 ≤ empiricalNorm n f :=\n Real.sqrt_nonneg _\n\nlemma empiricalNorm_zero (n : ℕ) : empiricalNorm n (0 : Fin n → ℝ) = 0 := by\n unfold empiricalNorm\n simp\n\nlemma empiricalNorm_neg (n : ℕ) (f : Fin n → ℝ) : empiricalNorm n (-f) = empiricalNorm n f := by\n unfold empiricalNorm\n congr 2\n apply Finset.sum_congr rfl\n intro i _\n simp only [Pi.neg_apply, neg_sq]\n\ndef EmpiricalSpace (n : ℕ) := Fin n → ℝ\n\nnamespace EmpiricalSpace\n\ninstance (n : ℕ) : Inhabited (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Zero (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Add (EmpiricalSpace n) := ⟨fun a b i => a i + b i⟩\ninstance (n : ℕ) : Sub (EmpiricalSpace n) := ⟨fun a b i => a i - b i⟩\ninstance (n : ℕ) : Neg (EmpiricalSpace n) := ⟨fun a i => -a i⟩\n\nnoncomputable instance instDist (n : ℕ) : Dist (EmpiricalSpace n) where\n dist a b := empiricalNorm n (a - b)\n\nnoncomputable instance instEDist (n : ℕ) : EDist (EmpiricalSpace n) where\n edist a b := ENNReal.ofReal (dist a b)\n\nlemma dist_self (n : ℕ) (a : EmpiricalSpace n) : dist a a = 0 := by\n show empiricalNorm n (a - a) = 0\n have h : (a - a : EmpiricalSpace n) = 0 := by\n funext i\n show a i - a i = (0 : Fin n → ℝ) i\n simp\n rw [h]\n exact empiricalNorm_zero n\n\nlemma dist_comm (n : ℕ) (a b : EmpiricalSpace n) : dist a b = dist b a := by\n show empiricalNorm n (a - b) = empiricalNorm n (b - a)\n have h : (a - b : EmpiricalSpace n) = -(b - a) := by\n funext i\n show a i - b i = -(b i - a i)\n ring\n rw [h]\n exact empiricalNorm_neg n _\n\nlemma dist_triangle (n : ℕ) (a b c : EmpiricalSpace n) :\n dist a c ≤ dist a b + dist b c := by\n show empiricalNorm n (a - c) ≤ empiricalNorm n (a - b) + empiricalNorm n (b - c)\n unfold empiricalNorm\n have eq_ac : ∀ k, (a - c : EmpiricalSpace n) k = a k - c k := fun k => rfl\n have eq_ab : ∀ k, (a - b : EmpiricalSpace n) k = a k - b k := fun k => rfl\n have eq_bc : ∀ k, (b - c : EmpiricalSpace n) k = b k - c k := fun k => rfl\n simp_rw [eq_ac, eq_ab, eq_bc]\n by_cases hn : n = 0\n · simp [hn]\n have hn_pos : (0 : ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)\n have hn_inv_nonneg : 0 ≤ (n : ℝ)⁻¹ := inv_nonneg.mpr (le_of_lt hn_pos)\n have h_factor : ∀ f : Fin n → ℝ, Real.sqrt ((n : ℝ)⁻¹ * ∑ i, (f i)^2) =\n Real.sqrt (n : ℝ)⁻¹ * Real.sqrt (∑ i, (f i)^2) := fun f => by\n rw [Real.sqrt_mul hn_inv_nonneg]\n rw [h_factor (fun i => a i - c i), h_factor (fun i => a i - b i),\n h_factor (fun i => b i - c i), ← mul_add]\n apply mul_le_mul_of_nonneg_left _ (Real.sqrt_nonneg _)\n let e := EuclideanSpace.equiv (Fin n) ℝ\n let a' : EuclideanSpace ℝ (Fin n) := e.symm a\n let b' : EuclideanSpace ℝ (Fin n) := e.symm b\n let c' : EuclideanSpace ℝ (Fin n) := e.symm c\n have h_a' : ∀ i, a' i = a i := fun i => rfl\n have h_b' : ∀ i, b' i = b i := fun i => rfl\n have h_c' : ∀ i, c' i = c i := fun i => rfl\n have h_norm : ∀ (x y : EuclideanSpace ℝ (Fin n)),\n Real.sqrt (∑ i, (x i - y i)^2) = ‖x - y‖ := fun x y => by\n rw [EuclideanSpace.norm_eq]\n congr 1\n apply Finset.sum_congr rfl\n intro i _\n rw [Real.norm_eq_abs, sq_abs]\n rfl\n simp only [← h_a', ← h_b', ← h_c']\n rw [h_norm a' c', h_norm a' b', h_norm b' c']\n have h_eq : a' - c' = (a' - b') + (b' - c') := (sub_add_sub_cancel a' b' c').symm\n rw [h_eq]\n exact norm_add_le (a' - b') (b' - c')\n\nlemma edist_dist (n : ℕ) (a b : EmpiricalSpace n) :\n edist a b = ENNReal.ofReal (dist a b) := rfl\n\nnoncomputable instance instPseudoMetricSpace (n : ℕ) : PseudoMetricSpace (EmpiricalSpace n) where\n dist_self := dist_self n\n dist_comm := dist_comm n\n dist_triangle := dist_triangle n\n edist_dist := edist_dist n\n\nend EmpiricalSpace\n\ndef empiricalMetricImage {X : Type*} (n : ℕ) (x : Fin n → X) (g : X → ℝ) : EmpiricalSpace n :=\n fun i => g (x i)\n\ndef IsENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop Nat :=\n sInf {n : WithTop Nat | ∃ t : Finset A, IsENet t eps s ∧ (t.card : WithTop Nat) = n}\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\ntheorem ch4_theorem_4_16\n {ι : Type*} [Nonempty ι] {𝒳 : Type*}\n (n : ℕ) (hn : 0 < n)\n (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳)\n (hf : ∀ i, ∀ z, f i z ∈ Set.Icc (-1 : ℝ) 1)\n (s : Set (EmpiricalSpace n))\n (hs : s = Set.range (fun i => empiricalMetricImage n S (f i)))\n (hcov : ∀ ε ∈ Set.Ioi (0 : ℝ), coveringNumber ε s ≠ ⊤) :\n empRadSigned n f S ≤\n ⨅ ε : Set.Ioi (0 : ℝ),\n ((ε : ℝ) +\n Real.sqrt\n (2 * Real.log (((coveringNumber (ε : ℝ) s).untopD 0 : ℕ) : ℝ)\n / (n : ℝ))) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def empiricalNorm (n : ℕ) (f : Fin n → ℝ) : ℝ :=\n Real.sqrt ((n : ℝ)⁻¹ * ∑ k : Fin n, f k ^ 2)\n\nlemma empiricalNorm_nonneg (n : ℕ) (f : Fin n → ℝ) : 0 ≤ empiricalNorm n f :=\n Real.sqrt_nonneg _\n\nlemma empiricalNorm_zero (n : ℕ) : empiricalNorm n (0 : Fin n → ℝ) = 0 := by\n unfold empiricalNorm\n simp\n\nlemma empiricalNorm_neg (n : ℕ) (f : Fin n → ℝ) : empiricalNorm n (-f) = empiricalNorm n f := by\n unfold empiricalNorm\n congr 2\n apply Finset.sum_congr rfl\n intro i _\n simp only [Pi.neg_apply, neg_sq]\n\ndef EmpiricalSpace (n : ℕ) := Fin n → ℝ\n\nnamespace EmpiricalSpace\n\ninstance (n : ℕ) : Inhabited (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Zero (EmpiricalSpace n) := ⟨fun _ => 0⟩\ninstance (n : ℕ) : Add (EmpiricalSpace n) := ⟨fun a b i => a i + b i⟩\ninstance (n : ℕ) : Sub (EmpiricalSpace n) := ⟨fun a b i => a i - b i⟩\ninstance (n : ℕ) : Neg (EmpiricalSpace n) := ⟨fun a i => -a i⟩\n\nnoncomputable instance instDist (n : ℕ) : Dist (EmpiricalSpace n) where\n dist a b := empiricalNorm n (a - b)\n\nnoncomputable instance instEDist (n : ℕ) : EDist (EmpiricalSpace n) where\n edist a b := ENNReal.ofReal (dist a b)\n\nlemma dist_self (n : ℕ) (a : EmpiricalSpace n) : dist a a = 0 := by\n show empiricalNorm n (a - a) = 0\n have h : (a - a : EmpiricalSpace n) = 0 := by\n funext i\n show a i - a i = (0 : Fin n → ℝ) i\n simp\n rw [h]\n exact empiricalNorm_zero n\n\nlemma dist_comm (n : ℕ) (a b : EmpiricalSpace n) : dist a b = dist b a := by\n show empiricalNorm n (a - b) = empiricalNorm n (b - a)\n have h : (a - b : EmpiricalSpace n) = -(b - a) := by\n funext i\n show a i - b i = -(b i - a i)\n ring\n rw [h]\n exact empiricalNorm_neg n _\n\nlemma dist_triangle (n : ℕ) (a b c : EmpiricalSpace n) :\n dist a c ≤ dist a b + dist b c := by\n show empiricalNorm n (a - c) ≤ empiricalNorm n (a - b) + empiricalNorm n (b - c)\n unfold empiricalNorm\n have eq_ac : ∀ k, (a - c : EmpiricalSpace n) k = a k - c k := fun k => rfl\n have eq_ab : ∀ k, (a - b : EmpiricalSpace n) k = a k - b k := fun k => rfl\n have eq_bc : ∀ k, (b - c : EmpiricalSpace n) k = b k - c k := fun k => rfl\n simp_rw [eq_ac, eq_ab, eq_bc]\n by_cases hn : n = 0\n · simp [hn]\n have hn_pos : (0 : ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)\n have hn_inv_nonneg : 0 ≤ (n : ℝ)⁻¹ := inv_nonneg.mpr (le_of_lt hn_pos)\n have h_factor : ∀ f : Fin n → ℝ, Real.sqrt ((n : ℝ)⁻¹ * ∑ i, (f i)^2) =\n Real.sqrt (n : ℝ)⁻¹ * Real.sqrt (∑ i, (f i)^2) := fun f => by\n rw [Real.sqrt_mul hn_inv_nonneg]\n rw [h_factor (fun i => a i - c i), h_factor (fun i => a i - b i),\n h_factor (fun i => b i - c i), ← mul_add]\n apply mul_le_mul_of_nonneg_left _ (Real.sqrt_nonneg _)\n let e := EuclideanSpace.equiv (Fin n) ℝ\n let a' : EuclideanSpace ℝ (Fin n) := e.symm a\n let b' : EuclideanSpace ℝ (Fin n) := e.symm b\n let c' : EuclideanSpace ℝ (Fin n) := e.symm c\n have h_a' : ∀ i, a' i = a i := fun i => rfl\n have h_b' : ∀ i, b' i = b i := fun i => rfl\n have h_c' : ∀ i, c' i = c i := fun i => rfl\n have h_norm : ∀ (x y : EuclideanSpace ℝ (Fin n)),\n Real.sqrt (∑ i, (x i - y i)^2) = ‖x - y‖ := fun x y => by\n rw [EuclideanSpace.norm_eq]\n congr 1\n apply Finset.sum_congr rfl\n intro i _\n rw [Real.norm_eq_abs, sq_abs]\n rfl\n simp only [← h_a', ← h_b', ← h_c']\n rw [h_norm a' c', h_norm a' b', h_norm b' c']\n have h_eq : a' - c' = (a' - b') + (b' - c') := (sub_add_sub_cancel a' b' c').symm\n rw [h_eq]\n exact norm_add_le (a' - b') (b' - c')\n\nlemma edist_dist (n : ℕ) (a b : EmpiricalSpace n) :\n edist a b = ENNReal.ofReal (dist a b) := rfl\n\nnoncomputable instance instPseudoMetricSpace (n : ℕ) : PseudoMetricSpace (EmpiricalSpace n) where\n dist_self := dist_self n\n dist_comm := dist_comm n\n dist_triangle := dist_triangle n\n edist_dist := edist_dist n\n\nend EmpiricalSpace\n\ndef empiricalMetricImage {X : Type*} (n : ℕ) (x : Fin n → X) (g : X → ℝ) : EmpiricalSpace n :=\n fun i => g (x i)\n\ndef IsENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) : WithTop Nat :=\n sInf {n : WithTop Nat | ∃ t : Finset A, IsENet t eps s ∧ (t.card : WithTop Nat) = n}\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\n\nlemma trunc_sq_le (a b : ℝ) (ha : -1 ≤ a) (ha' : a ≤ 1) :\n (a - max (-1) (min 1 b))^2 ≤ (a - b)^2 := by\n rcases le_total b (-1) with h | h\n · have hb : max (-1:ℝ) (min 1 b) = -1 := by\n rw [min_eq_right (by linarith : b ≤ 1)]; exact max_eq_left h\n rw [hb]; nlinarith\n · rcases le_total 1 b with h2 | h2\n · have hb : max (-1:ℝ) (min 1 b) = 1 := by\n rw [min_eq_left h2]; norm_num\n rw [hb]; nlinarith\n · have hb : max (-1:ℝ) (min 1 b) = b := by\n rw [min_eq_right h2]; exact max_eq_right h\n rw [hb]\n\nlemma radsigns_card (n : ℕ) : Fintype.card (RadSigns n) = 2^n := by\n show Fintype.card (Fin n → ({-1, 1} : Finset ℤ)) = 2^n\n simp\n\nlemma sum_prod_rad (n : ℕ) (F : Fin n → ℤ → ℝ) :\n ∑ σ : RadSigns n, ∏ k, F k (σ k) = ∏ k : Fin n, ∑ b ∈ ({-1,1} : Finset ℤ), F k b := by\n rw [Finset.prod_univ_sum]\n refine Finset.sum_nbij' (i := fun (σ : RadSigns n) => (fun k => ((σ k : ℤ)) : Fin n → ℤ))\n (j := fun (x : Fin n → ℤ) => (fun k => if h : x k ∈ ({-1,1} : Finset ℤ) then (⟨x k, h⟩ : ({-1,1} : Finset ℤ)) else ⟨1, by simp⟩ : RadSigns n))\n ?_ ?_ ?_ ?_ ?_\n · intro a _; simp [Fintype.mem_piFinset]\n · intro b _; simp\n · intro a _; funext k; simp\n · intro b hb; funext k; rw [Fintype.mem_piFinset] at hb; simp [hb k]\n · intro a _; rfl\n\nlemma mgf_bound (n : ℕ) (hn : 0 < n) (lam : ℝ) (v : Fin n → ℝ) (hv : ∀ k, v k ^ 2 ≤ 1) :\n ∑ σ : RadSigns n, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, (σ k : ℝ) * v k))\n ≤ (2^n : ℝ) * Real.exp (lam^2/(2*n)) := by\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n have key : ∀ σ : RadSigns n, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, (σ k : ℝ) * v k))\n = ∏ k, Real.exp (((σ k : ℤ) : ℝ) * (lam * (n:ℝ)⁻¹ * v k)) := by\n intro σ\n rw [← Real.exp_sum]\n congr 1\n simp only [Finset.mul_sum]\n exact Finset.sum_congr rfl (fun k _ => by ring)\n simp_rw [key]\n rw [sum_prod_rad n (fun k b => Real.exp ((b : ℝ) * (lam * (n:ℝ)⁻¹ * v k)))]\n have step1 : ∀ k : Fin n, ∑ b ∈ ({-1,1} : Finset ℤ), Real.exp ((b : ℝ) * (lam * (n:ℝ)⁻¹ * v k))\n = 2 * Real.cosh (lam * (n:ℝ)⁻¹ * v k) := by\n intro k\n rw [show ({-1,1} : Finset ℤ) = {(-1 : ℤ), (1:ℤ)} from rfl,\n Finset.sum_pair (by norm_num : (-1:ℤ) ≠ 1)]\n rw [Real.cosh_eq]\n push_cast\n ring_nf\n simp_rw [step1]\n have step2 : ∏ k : Fin n, (2 * Real.cosh (lam * (n:ℝ)⁻¹ * v k))\n ≤ ∏ k : Fin n, (2 * Real.exp ((lam * (n:ℝ)⁻¹ * v k)^2/2)) := by\n apply Finset.prod_le_prod\n · intro k _; positivity\n · intro k _\n exact mul_le_mul_of_nonneg_left (Real.cosh_le_exp_half_sq _) (by norm_num)\n refine step2.trans ?_\n rw [Finset.prod_mul_distrib, ← Real.exp_sum]\n simp only [Finset.prod_const, Finset.card_univ, Fintype.card_fin]\n apply mul_le_mul_of_nonneg_left _ (by positivity)\n apply Real.exp_le_exp.mpr\n have : ∀ k : Fin n, (lam * (n:ℝ)⁻¹ * v k)^2/2 ≤ lam^2 * ((n:ℝ)⁻¹)^2/2 := by\n intro k\n have h1 : (lam * (n:ℝ)⁻¹ * v k)^2 = lam^2 * ((n:ℝ)⁻¹)^2 * (v k)^2 := by ring\n rw [h1]\n have := hv k\n nlinarith [sq_nonneg (lam * (n:ℝ)⁻¹), sq_nonneg (v k)]\n refine (Finset.sum_le_sum (fun k _ => this k)).trans ?_\n simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n have hne : (n:ℝ) ≠ 0 := ne_of_gt hnR\n refine le_of_eq ?_\n field_simp\n\n\nlemma massart (n : ℕ) (hn : 0 < n) {α : Type*} (t : Finset α) (ht : t.Nonempty)\n (w : α → Fin n → ℝ) (hw : ∀ a ∈ t, ∀ k, (w a k)^2 ≤ 1) :\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, t.sup' ht (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k)\n ≤ Real.sqrt (2 * Real.log (t.card : ℝ) / n) := by\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n set C : ℝ := (Fintype.card (RadSigns n) : ℝ) with hC\n have hCval : C = 2^n := by rw [hC, radsigns_card]; push_cast; ring\n have hCpos : 0 < C := by rw [hCval]; positivity\n set M : RadSigns n → ℝ := fun σ => t.sup' ht (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k) with hM\n set A : ℝ := C⁻¹ * ∑ σ : RadSigns n, M σ with hA\n set L : ℝ := Real.log (t.card : ℝ) with hL\n have htc : 1 ≤ (t.card : ℝ) := by\n exact_mod_cast Finset.card_pos.mpr ht\n have hLnn : 0 ≤ L := Real.log_nonneg htc\n -- main inequality\n have main : ∀ lam : ℝ, 0 < lam → lam * A ≤ L + lam^2/(2*n) := by\n intro lam hlam\n have jensen : Real.exp (C⁻¹ * ∑ σ : RadSigns n, (lam * M σ))\n ≤ C⁻¹ * ∑ σ : RadSigns n, Real.exp (lam * M σ) := by\n have h := ConvexOn.map_sum_le (𝕜 := ℝ) (f := Real.exp) convexOn_exp\n (t := (Finset.univ : Finset (RadSigns n))) (w := fun _ => C⁻¹)\n (p := fun σ => lam * M σ) (fun i _ => le_of_lt (inv_pos.mpr hCpos))\n (by rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, ← hC]\n exact mul_inv_cancel₀ (ne_of_gt hCpos)) (fun i _ => trivial)\n simpa [smul_eq_mul, Finset.mul_sum] using h\n have hpt : ∀ σ : RadSigns n, Real.exp (lam * M σ)\n ≤ ∑ a ∈ t, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k)) := by\n intro σ\n obtain ⟨a0, ha0, heq⟩ := Finset.exists_mem_eq_sup' ht\n (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k)\n rw [hM]\n simp only\n rw [heq]\n exact Finset.single_le_sum (f := fun a => Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k)))\n (fun i _ => le_of_lt (Real.exp_pos _)) ha0\n have hsum : C⁻¹ * ∑ σ : RadSigns n, Real.exp (lam * M σ) ≤ (t.card : ℝ) * Real.exp (lam^2/(2*n)) := by\n have h1 : ∑ σ : RadSigns n, Real.exp (lam * M σ)\n ≤ ∑ σ : RadSigns n, ∑ a ∈ t, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k)) :=\n Finset.sum_le_sum (fun σ _ => hpt σ)\n have h2 : ∑ σ : RadSigns n, ∑ a ∈ t, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k))\n = ∑ a ∈ t, ∑ σ : RadSigns n, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k)) :=\n Finset.sum_comm\n have h3 : ∀ a ∈ t, ∑ σ : RadSigns n, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k))\n ≤ (2^n : ℝ) * Real.exp (lam^2/(2*n)) := fun a ha => mgf_bound n hn lam (w a) (hw a ha)\n have h4 : ∑ a ∈ t, ∑ σ : RadSigns n, Real.exp (lam * ((n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k))\n ≤ (t.card : ℝ) * ((2^n : ℝ) * Real.exp (lam^2/(2*n))) := by\n calc _ ≤ ∑ _a ∈ t, ((2^n : ℝ) * Real.exp (lam^2/(2*n))) := Finset.sum_le_sum h3\n _ = (t.card : ℝ) * ((2^n : ℝ) * Real.exp (lam^2/(2*n))) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n have : ∑ σ : RadSigns n, Real.exp (lam * M σ) ≤ (t.card : ℝ) * ((2^n : ℝ) * Real.exp (lam^2/(2*n))) := by\n rw [h2] at h1; exact h1.trans h4\n calc C⁻¹ * ∑ σ : RadSigns n, Real.exp (lam * M σ)\n ≤ C⁻¹ * ((t.card : ℝ) * ((2^n : ℝ) * Real.exp (lam^2/(2*n)))) :=\n mul_le_mul_of_nonneg_left this (le_of_lt (inv_pos.mpr hCpos))\n _ = (t.card : ℝ) * Real.exp (lam^2/(2*n)) := by\n rw [hCval]; field_simp\n have hexp : Real.exp (lam * A) ≤ Real.exp (L + lam^2/(2*n)) := by\n have e1 : lam * A = C⁻¹ * ∑ σ : RadSigns n, (lam * M σ) := by\n rw [hA, ← Finset.mul_sum]; ring\n rw [e1]\n refine jensen.trans (hsum.trans ?_)\n rw [Real.exp_add]\n have : Real.exp L = (t.card : ℝ) := Real.exp_log (by linarith)\n rw [this]\n have := Real.exp_le_exp.mp hexp\n exact this\n -- conclude\n rcases eq_or_lt_of_le hLnn with hL0 | hLpos\n · have hA0 : A ≤ 0 := by\n refine le_of_forall_pos_le_add ?_\n intro e he\n have := main (2*n*e) (by positivity)\n rw [← hL0] at this\n have hd : (2*(n:ℝ)*e)^2/(2*n) = (2*(n:ℝ)*e)*e := by field_simp\n rw [hd] at this\n have hpos : (0:ℝ) < 2*(n:ℝ)*e := by positivity\n have h6 : (2*(n:ℝ)*e) * A ≤ (2*(n:ℝ)*e) * e := by linarith\n have := le_of_mul_le_mul_left h6 hpos\n linarith\n have : Real.sqrt (2 * L / n) = 0 := by rw [← hL0]; simp\n rw [← hL] at *\n calc A ≤ 0 := hA0\n _ = Real.sqrt (2 * L / n) := this.symm\n · set u : ℝ := Real.sqrt (2 * L / n) with hu\n have hupos : 0 < u := Real.sqrt_pos.mpr (by positivity)\n have hu2 : u^2 = 2 * L / n := Real.sq_sqrt (by positivity)\n have hnu : (n:ℝ) * u^2 = 2 * L := by rw [hu2]; field_simp\n have hmain := main ((n:ℝ) * u) (by positivity)\n have hd : ((n:ℝ)*u)^2/(2*(n:ℝ)) = ((n:ℝ)*u^2)/2 := by field_simp\n rw [hd, hnu] at hmain\n have hnu' : (0:ℝ) < (n:ℝ)*u := by positivity\n have h5 : (n:ℝ)*u*A ≤ (n:���)*u*u := by\n have hq : (n:ℝ)*u*u = 2*L := by nlinarith [hnu]\n rw [hq]; linarith\n exact le_of_mul_le_mul_left h5 hnu'\n\ntheorem ch4_theorem_4_16\n {ι : Type*} [Nonempty ι] {𝒳 : Type*}\n (n : ℕ) (hn : 0 < n)\n (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳)\n (hf : ∀ i, ∀ z, f i z ∈ Set.Icc (-1 : ℝ) 1)\n (s : Set (EmpiricalSpace n))\n (hs : s = Set.range (fun i => empiricalMetricImage n S (f i)))\n (hcov : ∀ ε ∈ Set.Ioi (0 : ℝ), coveringNumber ε s ≠ ⊤) :\n empRadSigned n f S ≤\n ⨅ ε : Set.Ioi (0 : ℝ),\n ((ε : ℝ) +\n Real.sqrt\n (2 * Real.log (((coveringNumber (ε : ℝ) s).untopD 0 : ℕ) : ℝ)\n / (n : ℝ))) := by\n classical\n have hnR : (0:ℝ) < n := by exact_mod_cast hn\n haveI : Nonempty (Set.Ioi (0:ℝ)) := ⟨⟨1, by norm_num⟩⟩\n refine le_ciInf ?_\n rintro ⟨ε, hε⟩\n simp only [Set.mem_Ioi] at hε\n simp only\n -- covering number is attained\n have hsetne : {x : WithTop ℕ | ∃ t : Finset (EmpiricalSpace n),\n IsENet t ε s ∧ (t.card : WithTop ℕ) = x}.Nonempty := by\n by_contra hcon\n rw [Set.not_nonempty_iff_eq_empty] at hcon\n apply hcov ε hε\n unfold coveringNumber\n rw [hcon]\n exact sInf_empty\n obtain ⟨x0, tx, htx, hx0⟩ := hsetne\n set Mset : Set ℕ := {m : ℕ | ∃ t : Finset (EmpiricalSpace n), IsENet t ε s ∧ t.card = m} with hMset\n have hMne : Mset.Nonempty := ⟨tx.card, tx, htx, rfl⟩\n set N : ℕ := sInf Mset with hNdef\n obtain ⟨t, htnet, htcard⟩ : N ∈ Mset := Nat.sInf_mem hMne\n have hcovval : coveringNumber ε s = (N : WithTop ℕ) := by\n apply le_antisymm\n · exact sInf_le ⟨t, htnet, by rw [htcard]⟩\n · refine le_sInf ?_\n rintro y ⟨t', ht', rfl⟩\n have : N ≤ t'.card := Nat.sInf_le ⟨t', ht', rfl⟩\n exact_mod_cast this\n have huntop : ((coveringNumber ε s).untopD 0) = N := by rw [hcovval]; rfl\n rw [huntop]\n -- truncation map\n set w : EmpiricalSpace n → Fin n → ℝ := fun v k => max (-1) (min 1 (v k)) with hw\n have hwb : ∀ (v : EmpiricalSpace n) (k : Fin n), -1 ≤ w v k ∧ w v k ≤ 1 := by\n intro v k\n constructor\n · exact le_max_left _ _\n · exact max_le (by norm_num) (min_le_left _ _)\n have hwsq : ∀ a ∈ t, ∀ k, (w a k)^2 ≤ 1 := by\n intro a _ k\n obtain ⟨h1, h2⟩ := hwb a k\n nlinarith\n -- t is nonempty\n obtain ⟨i0⟩ := ‹Nonempty ι›\n have hmem0 : (empiricalMetricImage n S (f i0)) ∈ s := by rw [hs]; exact ⟨i0, rfl⟩\n have ht : t.Nonempty := by\n have h2 := htnet hmem0\n simp only [Set.mem_iUnion] at h2\n obtain ⟨v, hv, _⟩ := h2\n exact ⟨v, hv⟩\n -- key pointwise bound\n have hkey : ∀ σ : RadSigns n, (⨆ i, (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * f i (S k))\n ≤ ε + t.sup' ht (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k) := by\n intro σ\n refine ciSup_le ?_\n intro i\n have hmem : (empiricalMetricImage n S (f i)) ∈ s := by rw [hs]; exact ⟨i, rfl⟩\n have h2 := htnet hmem\n simp only [Set.mem_iUnion, Metric.mem_closedBall] at h2\n obtain ⟨v, hvt, hdv⟩ := h2\n -- distance bound\n have hdist : Real.sqrt ((n:ℝ)⁻¹ * ∑ k, (f i (S k) - v k)^2) ≤ ε := by\n refine le_trans (le_of_eq ?_) hdv\n show _ = empiricalNorm n (empiricalMetricImage n S (f i) - v)\n unfold empiricalNorm\n congr 2\n have hsq : (n:ℝ)⁻¹ * ∑ k, (f i (S k) - v k)^2 ≤ ε^2 := by\n have hnn : (0:ℝ) ≤ (n:ℝ)⁻¹ * ∑ k, (f i (S k) - v k)^2 := by\n have : (0:ℝ) ≤ ∑ k, (f i (S k) - v k)^2 :=\n Finset.sum_nonneg (fun k _ => sq_nonneg _)\n positivity\n nlinarith [Real.sq_sqrt hnn, Real.sqrt_nonneg ((n:ℝ)⁻¹ * ∑ k, (f i (S k) - v k)^2)]\n have hsum1 : ∑ k, (f i (S k) - v k)^2 ≤ (n:ℝ) * ε^2 := by\n have := mul_le_mul_of_nonneg_left hsq (le_of_lt hnR)\n rw [← mul_assoc] at this\n rw [mul_inv_cancel₀ (ne_of_gt hnR), one_mul] at this\n exact this\n have hsum2 : ∑ k, (f i (S k) - w v k)^2 ≤ (n:ℝ) * ε^2 := by\n refine le_trans (Finset.sum_le_sum ?_) hsum1\n intro k _\n have hb := hf i (S k)\n simp only [Set.mem_Icc] at hb\n exact trunc_sq_le _ _ hb.1 hb.2\n -- Cauchy-Schwarz\n have hσsq : ∑ k : Fin n, (((σ k : ℤ) : ℝ))^2 = (n:ℝ) := by\n have hone : ∀ k : Fin n, (((σ k : ℤ) : ℝ))^2 = 1 := by\n intro k\n have hk := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at hk\n rcases hk with h | h <;> rw [h] <;> norm_num\n simp [hone]\n have hcs : (∑ k, ((σ k : ℤ) : ℝ) * (f i (S k) - w v k))^2\n ≤ (∑ k : Fin n, (((σ k : ℤ) : ℝ))^2) * (∑ k, (f i (S k) - w v k)^2) :=\n Finset.sum_mul_sq_le_sq_mul_sq Finset.univ _ _\n have hbound : ∑ k, ((σ k : ℤ) : ℝ) * (f i (S k) - w v k) ≤ (n:ℝ) * ε := by\n rw [hσsq] at hcs\n have h3 : (∑ k, ((σ k : ℤ) : ℝ) * (f i (S k) - w v k))^2 ≤ ((n:ℝ)*ε)^2 := by\n have h4 : (n:ℝ) * (∑ k, (f i (S k) - w v k)^2) ≤ (n:ℝ) * ((n:ℝ) * ε^2) :=\n mul_le_mul_of_nonneg_left hsum2 (le_of_lt hnR)\n nlinarith\n nlinarith [h3, mul_pos hnR hε]\n -- combine\n have hsplit : (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * f i (S k)\n ≤ (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w v k + ε := by\n have heq : ∑ k, ((σ k : ℤ) : ℝ) * f i (S k)\n = ∑ k, ((σ k : ℤ) : ℝ) * w v k + ∑ k, ((σ k : ℤ) : ℝ) * (f i (S k) - w v k) := by\n rw [← Finset.sum_add_distrib]\n exact Finset.sum_congr rfl (fun k _ => by ring)\n rw [heq, mul_add]\n have : (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * (f i (S k) - w v k) ≤ ε := by\n have := mul_le_mul_of_nonneg_left hbound (le_of_lt (inv_pos.mpr hnR))\n rw [← mul_assoc, inv_mul_cancel₀ (ne_of_gt hnR), one_mul] at this\n exact this\n linarith\n have hle : (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w v k\n ≤ t.sup' ht (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k) :=\n Finset.le_sup' (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k) hvt\n linarith\n -- assemble\n have hCpos : (0:ℝ) < (Fintype.card (RadSigns n) : ℝ) := by\n rw [radsigns_card]; positivity\n have hstep : empRadSigned n f S\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n,\n (ε + t.sup' ht (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k)) := by\n unfold empRadSigned\n exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun σ _ => hkey σ))\n (le_of_lt (inv_pos.mpr hCpos))\n have heq2 : (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n,\n (ε + t.sup' ht (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k))\n = ε + (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n,\n t.sup' ht (fun a => (n:ℝ)⁻¹ * ∑ k, ((σ k : ℤ) : ℝ) * w a k) := by\n rw [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_add,\n ← mul_assoc, inv_mul_cancel₀ (ne_of_gt hCpos), one_mul]\n have hmass := massart n hn t ht w hwsq\n rw [htcard] at hmass\n linarith [hstep, heq2.le, heq2.ge, hmass]\n\n\nend GraduateLevel\n"} +{"id": "ch5_theorem_5_9", "source": "Graduate-level", "targets": [{"label": "ch5_theorem_5_9", "decls": ["ch5_theorem_5_9"], "statement": "For some constants \\(B_w > 0\\) and \\(B_u > 0\\), let\n\\[\n\\mathcal{H} = \\left\\{ f_\\theta \\mid \\left\\|w\\right\\|_2 \\leq B_w,\\ \\left\\|u_i\\right\\|_2 \\leq B_u,\\ \\forall i \\in \\{1,2,\\dots,m\\} \\right\\},\n\\]\nand suppose \\(\\mathbb{E}\\left[\\left\\|x\\right\\|_2^2\\right] \\leq C^2\\). Then\n\\[\nR_n(\\mathcal{H}) \\le 2 B_w B_u C\\sqrt{\\frac{m}{n}}.\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "By definition,\n\\[\n\\begin{aligned}\nR_S(\\mathcal{H})\n&= \\mathbb{E}_\\sigma\\left[ \\sup_\\theta \\frac{1}{n} \\sum_{i=1}^n \\sigma_i \\left\\langle w,\\phi(Ux^{(i)})\\right\\rangle \\right] \\\\\n&= \\frac{1}{n} \\mathbb{E}_\\sigma\\left[ \\sup_{U : \\left\\|u_j\\right\\|_2 \\leq B_u} \\sup_{\\left\\|w\\right\\|_2 \\leq B_w} \\left\\langle w,\\sum_{i=1}^n \\sigma_i \\phi(Ux^{(i)})\\right\\rangle \\right] \\\\\n&= \\frac{B_w}{n}\\mathbb{E}_\\sigma\\left[ \\sup_{U : \\left\\|u_j\\right\\|_2 \\leq B_u} \\left\\| \\sum_{i=1}^n \\sigma_i \\phi(Ux^{(i)})\\right\\|_2 \\right]\n\\quad \\text{(}\\textstyle\\sup_{\\left\\|w\\right\\|_2\\leq B}\\left\\langle w,v\\right\\rangle = B\\left\\|v\\right\\|_2\\text{)} \\\\\n&\\leq \\frac{B_w\\sqrt{m}}{n}\\mathbb{E}_\\sigma\\left[ \\sup_{U : \\left\\|u_j\\right\\|_2 \\leq B_u} \\left\\| \\sum_{i=1}^n \\sigma_i \\phi(Ux^{(i)})\\right\\|_\\infty \\right]\n\\quad \\text{(}\\left\\|v\\right\\|_2 \\leq \\sqrt{m}\\left\\|v\\right\\|_\\infty\\text{)} \\\\\n&= \\frac{B_w\\sqrt{m}}{n}\\mathbb{E}_\\sigma\\left[ \\sup_{U : \\left\\|u_j\\right\\|_2 \\leq B_u} \\max_{1\\leq j\\leq m} \\left| \\sum_{i=1}^n \\sigma_i \\phi(u_j^\\top x^{(i)})\\right| \\right] \\\\\n&= \\frac{B_w\\sqrt{m}}{n}\\mathbb{E}_\\sigma\\left[ \\sup_{\\left\\|u\\right\\|_2 \\leq B_u} \\left| \\sum_{i=1}^n \\sigma_i \\phi(u^\\top x^{(i)})\\right| \\right] \\\\\n&\\leq \\frac{2B_w\\sqrt{m}}{n}\\mathbb{E}_\\sigma\\left[ \\sup_{\\left\\|u\\right\\|_2 \\leq B_u} \\sum_{i=1}^n \\sigma_i \\phi(u^\\top x^{(i)}) \\right]\n\\quad \\text{(by the referenced result)} \\\\\n&\\leq \\frac{2B_w\\sqrt{m}}{n}\\mathbb{E}_\\sigma\\left[ \\sup_{\\left\\|u\\right\\|_2 \\leq B_u} \\sum_{i=1}^n \\sigma_i u^\\top x^{(i)} \\right],\n\\end{aligned}\n\\]\nwhere the last inequality follows by applying the contraction lemma (Talagrand's lemma) and observing that the ReLU function is \\(1\\)-Lipschitz. (The expectation above is the Rademacher complexity for \\(\\{ x \\mapsto \\phi(u^\\top x) \\mid \\left\\|u\\right\\|_2 \\leq B_u \\}\\): this is the family that we are applying the contraction lemma to.)\n\nWe now observe that the expectation in the last line is the Rademacher complexity of the family of linear models \\(\\{x \\mapsto \\langle u,x\\rangle \\mid \\left\\|u\\right\\|_2\\leq B_u\\}\\). Thus, applying the referenced linear-model Rademacher bound yields\n\\[\nR_S(\\mathcal{H}) \\leq \\frac{2B_w\\sqrt{m}}{n}B_u\\sqrt{\\sum_{i=1}^n \\left\\|x^{(i)}\\right\\|_2^2}.\n\\]\n\nTaking the expectation of both sides and using similar steps to those in the proof of the referenced theorem gives us\n\\[\n\\begin{aligned}\nR_n(\\mathcal{H}) &= \\mathbb{E}\\left[ R_S(\\mathcal{H})\\right] \\\\\n&\\leq \\frac{2B_wB_u\\sqrt{m}}{n} \\mathbb{E}\\left[\\sqrt{\\sum_{i=1}^n \\left\\|x^{(i)}\\right\\|_2^2}\\right] \\\\\n&\\leq \\frac{2B_wB_u\\sqrt{m}}{n} C\\sqrt{n} \\\\\n&= 2 B_w B_u C\\sqrt{\\frac{m}{n}},\n\\end{aligned}\n\\]\nwhich completes the proof.", "context": [{"id": "ch5:lemma:5_12", "name": "Removing the absolute value in Rademacher complexity", "statement": "Let \\(\\sigma = (\\sigma_1, \\dots, \\sigma_n)\\) and \\(f_{\\theta}(x) = \\left(f_{\\theta}\\left(x^{(1)}\\right), \\dots, f_{\\theta}\\left(x^{(n)}\\right)\\right)\\). Suppose that for any \\(\\sigma \\in \\{\\pm 1\\}^n\\), \\(\\sup_{\\theta} \\langle \\sigma, f_{\\theta}(x) \\rangle \\geq 0\\). Then,\n\\[\n\\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\left| \\langle \\sigma, f_{\\theta}(x) \\rangle \\right| \\right] \\leq 2\\, \\mathbb{E}_{\\sigma}\\left[ \\sup_{\\theta} \\langle \\sigma, f_{\\theta}(x) \\rangle \\right].\n\\]"}, {"id": "ch5:lemma:5_3", "name": "Talagrand's lemma", "statement": "Let \\(\\phi:\\mathbb{R}\\to\\mathbb{R}\\) be a \\(\\kappa\\)-Lipschitz function. Then\n\\[\nR_S(\\phi\\circ \\mathcal{H})\\leq \\kappa R_S(\\mathcal{H}),\n\\]\nwhere \\(\\phi\\circ\\mathcal{H} = \\{z\\mapsto \\phi(h(z))\\mid h\\in\\mathcal{H}\\}\\)."}, {"id": "ch5:theorem:5_5", "name": "Rademacher complexity of l2-bounded linear functions", "statement": "Let \\(\\mathcal{H} = \\{x \\mapsto \\langle w,x \\rangle \\mid w \\in \\mathbb{R}^d,\\, \\|w\\|_2 \\le B\\}\\) for some constant \\(B > 0\\). Moreover, assume \\(\\mathbb{E}_{x \\sim P}[\\|x\\|_2^2] \\leq C^2\\), where \\(P\\) is some distribution and \\(C > 0\\) is a constant. Then\n\\[\nR_S(\\mathcal{H}) \\le \\frac{B}{n} \\sqrt{\\sum_{i=1}^n \\|x^{(i)}\\|_2^2},\n\\]\nand\n\\[\nR_n(\\mathcal{H}) \\le \\frac{BC}{\\sqrt{n}}.\n\\]"}, {"id": "ch4:definition:4_10", "name": "Rademacher complexity", "statement": "Let \\(\\mathcal{F}\\) be a family of functions mapping \\(Z \\mapsto \\mathbb{R}\\), and let \\(P\\) be a distribution over \\(Z\\). The (average) Rademacher complexity of \\(\\mathcal{F}\\) is defined as\n\\[\nR_n(F) \\triangleq \\mathbb{E}_{z_1, \\dots, z_n \\overset{\\text{iid}}{\\sim} P} \\left[ \\mathbb{E}_{\\sigma_1, \\dots, \\sigma_n \\overset{\\text{iid}}{\\sim}\\{ \\pm 1 \\}} \\left[ \\sup_{f\\in F} \\frac{1}{n} \\sum^n_{i=1} \\sigma_i f(z_i) \\right] \\right],\n\\]\nwhere \\(\\sigma_1, \\dots, \\sigma_n\\) are independent Rademacher random variables, i.e. each taking on the value of \\(1\\) or \\(-1\\) with probability \\(1/2\\)."}, {"id": "ch5:definition:two_layer_relu_network", "name": "Two-layer ReLU network", "statement": "Given a width \\(m\\), let \\(w_1,\\dots,w_m \\in \\mathbb{R}\\), \\(u_1,\\dots,u_m \\in \\mathbb{R}^d\\), and let \\(\\phi\\) denote the ReLU activation. For \\(\\theta=(w_1,\\dots,w_m,u_1,\\dots,u_m)\\), define the two-layer ReLU network\n\\[\nf_{\\theta}(x)=\\sum_{j=1}^m w_j \\phi\\left(u_j^\\top x\\right).\n\\]\nThroughout this section, we use the following notation: \\(\\theta = (w, U)\\) are the parameters of the model with \\(w \\in \\mathbb{R}^m\\) and \\(U \\in \\mathbb{R}^{m\\times d}\\), where \\(m\\) denotes the number of hidden units. We use \\(u_i \\in \\mathbb{R}^d\\) to denote the \\(i\\)-th row of \\(U\\) (written as a column vector). \\(\\phi(z) = \\max(z,0)\\) is the ReLU activation function applied element-wise. \\(f_\\theta(x) = \\langle w, \\phi(Ux)\\rangle = w^\\top \\phi(Ux)\\) is the model. \\(\\{(x^{(i)}, y^{(i)})\\}_{i=1}^n\\) is the training set, with \\(x^{(i)} \\in \\mathbb{R}^d\\) and \\(y^{(i)} \\in \\mathbb{R}\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\ndef reluAct : ℝ → ℝ := fun x => max 0 x\n\ndef NetParam (d m : ℕ) (Bw Bu : ℝ) : Type := {p : EuclideanSpace ℝ (Fin m) × (Fin m → EuclideanSpace ℝ (Fin d)) // ‖p.1‖ ≤ Bw ∧ ∀ i, ‖p.2 i‖ ≤ Bu}\n\nnoncomputable def netFun {d m : ℕ} {Bw Bu : ℝ} (p : NetParam d m Bw Bu) (x : EuclideanSpace ℝ (Fin d)) : ℝ := ∑ j : Fin m, (p.1.1 j) * reluAct (inner ℝ (p.1.2 j) x)\n\ntheorem ch5_theorem_5_9 {d m n : ℕ} (Bw Bu C : ℝ) (hBw : 0 < Bw) (hBu : 0 < Bu) (hC : 0 ≤ C) (hn : 0 < n) {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (X : Ω → EuclideanSpace ℝ (Fin d)) (hXmeas : AEMeasurable X μ) (hXsq_int : Integrable (fun ω => ‖X ω‖ ^ 2) μ) (hmom : ∫ ω, ‖X ω‖ ^ 2 ∂μ ≤ C ^ 2) : popRadSigned n (fun (p : NetParam d m Bw Bu) => netFun p) μ X ≤ 2 * Bw * Bu * C * Real.sqrt (m / n) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nprivate instance : Neg { x // x ∈ ({-1, 1} : Finset ℤ) } where\n neg x := ⟨-x.val, by\n cases x with\n | mk val h =>\n simp at h\n cases h\n · simp [*]\n · simp [*]\n ⟩\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\ndef reluAct : ℝ → ℝ := fun x => max 0 x\n\ndef NetParam (d m : ℕ) (Bw Bu : ℝ) : Type := {p : EuclideanSpace ℝ (Fin m) × (Fin m → EuclideanSpace ℝ (Fin d)) // ‖p.1‖ ≤ Bw ∧ ∀ i, ‖p.2 i‖ ≤ Bu}\n\nnoncomputable def netFun {d m : ℕ} {Bw Bu : ℝ} (p : NetParam d m Bw Bu) (x : EuclideanSpace ℝ (Fin d)) : ℝ := ∑ j : Fin m, (p.1.1 j) * reluAct (inner ℝ (p.1.2 j) x)\n\nopen scoped BigOperators ENNReal\n\n/-- ReLU is continuous. -/\nprivate lemma reluAct_continuous : Continuous reluAct :=\n continuous_const.max continuous_id\n\n/-- ReLU is 1-Lipschitz. -/\nprivate lemma reluAct_lipschitzWith : LipschitzWith 1 reluAct := by\n show LipschitzWith 1 (fun x => max 0 x)\n have h₁ : LipschitzWith 0 (fun _ : ℝ => (0 : ℝ)) := LipschitzWith.const 0\n have h₂ : LipschitzWith 1 (id : ℝ → ℝ) := LipschitzWith.id\n have h := h₁.max h₂\n simpa using h\n\nprivate abbrev RSigns (n : ℕ) := RadSigns n\n\nprivate instance (n : ℕ) : Nonempty (RSigns n) :=\n ⟨fun _ => ⟨1, by simp⟩⟩\n\nprivate lemma signs_split {n : ℕ} (f : ℤ → RSigns n → ℝ) :\n ∑ s ∈ ({-1, 1} : Finset ℤ), ∑ σ : RSigns n, f s σ =\n ∑ σ : RSigns (n + 1), f (σ (Fin.last n)) (Fin.init σ) := by\n calc\n _ = ∑ z : ({-1, 1} : Finset ℤ) × RSigns n, f z.1 z.2 := by\n exact (Fintype.sum_prod_type\n (fun z : ({-1, 1} : Finset ℤ) × RSigns n => f z.1 z.2)).symm\n _ = ∑ σ : RSigns (n + 1),\n (fun z : ({-1, 1} : Finset ℤ) × RSigns n => f z.1 z.2)\n ((Fin.snocEquiv fun _ => ({-1, 1} : Finset ℤ)).symm σ) := by\n exact (Fintype.sum_equiv\n (Fin.snocEquiv fun _ => ({-1, 1} : Finset ℤ)).symm _ _ (fun _ => rfl)).symm\n _ = _ := by simp\n\nprivate lemma sign_abs {n : ℕ} (σ : RSigns n) (k : Fin n) :\n |(σ k : ℝ)| = 1 := by\n have h := (σ k).property\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h <;> simp [h]\n\nprivate lemma exists_eq_ciSup_of_compact\n {H : Type*} [TopologicalSpace H] [CompactSpace H] [Nonempty H]\n (f : H → ℝ) (hf : Continuous f) :\n ∃ h, f h = ⨆ h, f h := by\n obtain ⟨h, -, hh⟩ :=\n isCompact_univ.exists_isMaxOn Set.univ_nonempty hf.continuousOn\n have hb : BddAbove (Set.range f) := ⟨f h, by\n rintro _ ⟨x, rfl⟩\n exact hh (Set.mem_univ x)⟩\n refine ⟨h, le_antisymm (le_ciSup hb h) ?_⟩\n exact ciSup_le fun x => hh (Set.mem_univ x)\n\nprivate lemma bddAbove_range_of_compact\n {H : Type*} [TopologicalSpace H] [CompactSpace H] [Nonempty H]\n (f : H → ℝ) (hf : Continuous f) : BddAbove (Set.range f) := by\n obtain ⟨h, -, hh⟩ :=\n isCompact_univ.exists_isMaxOn Set.univ_nonempty hf.continuousOn\n exact ⟨f h, by\n rintro _ ⟨x, rfl⟩\n exact hh (Set.mem_univ x)⟩\n\nprivate lemma two_iSup_contraction_compact\n {H : Type*} [TopologicalSpace H] [CompactSpace H] [Nonempty H]\n (A x : H → ℝ) (ψ : ℝ → ℝ) {L : ℝ}\n (hA : Continuous A) (hx : Continuous x) (hψc : Continuous ψ)\n (hψ : ∀ u v, |ψ u - ψ v| ≤ L * |u - v|) :\n (⨆ h, A h + ψ (x h)) + (⨆ h, A h - ψ (x h)) ≤\n (⨆ h, A h + L * x h) + (⨆ h, A h - L * x h) := by\n obtain ⟨h₁, hh₁⟩ := exists_eq_ciSup_of_compact\n (fun h => A h + ψ (x h)) (hA.add (hψc.comp hx))\n obtain ⟨h₂, hh₂⟩ := exists_eq_ciSup_of_compact\n (fun h => A h - ψ (x h)) (hA.sub (hψc.comp hx))\n rw [← hh₁, ← hh₂]\n have hp : Continuous (fun h => A h + L * x h) :=\n hA.add (continuous_const.mul hx)\n have hm : Continuous (fun h => A h - L * x h) :=\n hA.sub (continuous_const.mul hx)\n obtain ⟨hp₀, ehp⟩ := exists_eq_ciSup_of_compact _ hp\n obtain ⟨hm₀, ehm⟩ := exists_eq_ciSup_of_compact _ hm\n by_cases hxx : x h₂ ≤ x h₁\n · have hd : ψ (x h₁) - ψ (x h₂) ≤ L * (x h₁ - x h₂) := by\n calc\n _ ≤ |ψ (x h₁) - ψ (x h₂)| := le_abs_self _\n _ ≤ L * |x h₁ - x h₂| := hψ _ _\n _ = _ := by rw [abs_of_nonneg (sub_nonneg.mpr hxx)]\n calc\n _ = A h₁ + A h₂ + (ψ (x h₁) - ψ (x h₂)) := by ring\n _ ≤ A h₁ + A h₂ + L * (x h₁ - x h₂) := by linarith\n _ = (A h₁ + L * x h₁) + (A h₂ - L * x h₂) := by ring\n _ ≤ (⨆ h, A h + L * x h) + (⨆ h, A h - L * x h) := by\n rw [← ehp, ← ehm]\n exact add_le_add\n (by rw [ehp]; exact le_ciSup (bddAbove_range_of_compact _ hp) h₁)\n (by rw [ehm]; exact le_ciSup (bddAbove_range_of_compact _ hm) h₂)\n · have hxx' : x h₁ ≤ x h₂ := le_of_not_ge hxx\n have hd : ψ (x h₁) - ψ (x h₂) ≤ L * (x h₂ - x h₁) := by\n calc\n _ ≤ |ψ (x h₁) - ψ (x h₂)| := le_abs_self _\n _ ≤ L * |x h₁ - x h₂| := hψ _ _\n _ = _ := by rw [abs_sub_comm, abs_of_nonneg (sub_nonneg.mpr hxx')]\n calc\n _ = A h₁ + A h₂ + (ψ (x h₁) - ψ (x h₂)) := by ring\n _ ≤ A h₁ + A h₂ + L * (x h₂ - x h₁) := by linarith\n _ = (A h₂ + L * x h₂) + (A h₁ - L * x h₁) := by ring\n _ ≤ (⨆ h, A h + L * x h) + (⨆ h, A h - L * x h) := by\n rw [← ehp, ← ehm]\n exact add_le_add\n (by rw [ehp]; exact le_ciSup (bddAbove_range_of_compact _ hp) h₂)\n (by rw [ehm]; exact le_ciSup (bddAbove_range_of_compact _ hm) h₁)\n\nprivate theorem sum_iSup_contraction_compact\n {H : Type*} [TopologicalSpace H] [CompactSpace H] [Nonempty H]\n (n : ℕ) (a : H → Fin n → ℝ) (ψ : Fin n → ℝ → ℝ)\n (c : H → ℝ) {L : ℝ}\n (ha : ∀ k, Continuous fun h => a h k)\n (hψc : ∀ k, Continuous (ψ k)) (hc : Continuous c)\n (hψ : ∀ k u v, |ψ k u - ψ k v| ≤ L * |u - v|) :\n (∑ σ : RSigns n,\n ⨆ h, c h + ∑ k : Fin n, (σ k : ℝ) * ψ k (a h k)) ≤\n ∑ σ : RSigns n,\n ⨆ h, c h + L * ∑ k : Fin n, (σ k : ℝ) * a h k := by\n induction n generalizing c with\n | zero => simp\n | succ q ih =>\n let a₀ : H → Fin q → ℝ := fun h k => a h k.castSucc\n let ψ₀ : Fin q → ℝ → ℝ := fun k => ψ k.castSucc\n let x : H → ℝ := fun h => a h (Fin.last q)\n have ha₀ : ∀ k, Continuous fun h => a₀ h k := fun k => ha k.castSucc\n have hψc₀ : ∀ k, Continuous (ψ₀ k) := fun k => hψc k.castSucc\n have hx : Continuous x := ha (Fin.last q)\n have hψ₀ : ∀ k u v, |ψ₀ k u - ψ₀ k v| ≤ L * |u - v| :=\n fun k u v => hψ k.castSucc u v\n have hlast :\n ∑ τ : RSigns q,\n ((⨆ h,\n c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) +\n ψ (Fin.last q) (x h)) +\n (⨆ h,\n c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) -\n ψ (Fin.last q) (x h))) ≤\n ∑ τ : RSigns q,\n ((⨆ h,\n c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) +\n L * x h) +\n (⨆ h,\n c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) -\n L * x h)) := by\n apply Finset.sum_le_sum\n intro τ _\n let A : H → ℝ :=\n fun h => c h + ∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)\n have hA : Continuous A := hc.add <| continuous_finset_sum _ fun k _ =>\n continuous_const.mul ((hψc₀ k).comp (ha₀ k))\n simpa [A, add_assoc] using\n two_iSup_contraction_compact A x (ψ (Fin.last q))\n hA hx (hψc (Fin.last q)) (hψ (Fin.last q))\n have hminus := ih (a := a₀) (ψ := ψ₀)\n (c := fun h => c h - L * x h) ha₀ hψc₀\n (hc.sub (continuous_const.mul hx)) hψ₀\n have hplus := ih (a := a₀) (ψ := ψ₀)\n (c := fun h => c h + L * x h) ha₀ hψc₀\n (hc.add (continuous_const.mul hx)) hψ₀\n let Q : ℤ → RSigns q → ℝ :=\n fun s τ =>\n ⨆ h, c h +\n ((∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) +\n (s : ℝ) * ψ (Fin.last q) (x h))\n let QL : ℤ → RSigns q → ℝ :=\n fun s τ =>\n ⨆ h, c h + L *\n ((∑ k : Fin q, (τ k : ℝ) * a₀ h k) + (s : ℝ) * x h)\n calc\n (∑ σ : RSigns (q + 1),\n ⨆ h, c h + ∑ k : Fin (q + 1),\n (σ k : ℝ) * ψ k (a h k)) =\n ∑ σ : RSigns (q + 1), Q (σ (Fin.last q)) (Fin.init σ) := by\n apply Finset.sum_congr rfl\n intro σ _\n dsimp only [Q]\n apply congrArg\n funext h\n rw [Fin.sum_univ_castSucc]\n rfl\n _ = ∑ s ∈ ({-1, 1} : Finset ℤ), ∑ τ : RSigns q,\n ⨆ h, c h +\n ((∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) +\n (s : ℝ) * ψ (Fin.last q) (x h)) := (signs_split Q).symm\n _ = ∑ τ : RSigns q,\n ((⨆ h, c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) -\n ψ (Fin.last q) (x h)) +\n (⨆ h, c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) +\n ψ (Fin.last q) (x h))) := by\n simp [Finset.sum_add_distrib, add_comm, add_left_comm]\n apply Finset.sum_congr rfl\n intro τ _\n apply congrArg\n funext h\n ring\n _ ≤ ∑ τ : RSigns q,\n ((⨆ h, c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) -\n L * x h) +\n (⨆ h, c h + (∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) +\n L * x h)) := by simpa [add_comm] using hlast\n _ = (∑ τ : RSigns q,\n ⨆ h, (c h - L * x h) +\n ∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k)) +\n ∑ τ : RSigns q,\n ⨆ h, (c h + L * x h) +\n ∑ k : Fin q, (τ k : ℝ) * ψ₀ k (a₀ h k) := by\n simp only [Finset.sum_add_distrib]\n congr 1 <;> apply Finset.sum_congr rfl <;> intro τ _ <;>\n apply congrArg <;> funext h <;> ring\n _ ≤ (∑ τ : RSigns q,\n ⨆ h, (c h - L * x h) +\n L * ∑ k : Fin q, (τ k : ℝ) * a₀ h k) +\n ∑ τ : RSigns q,\n ⨆ h, (c h + L * x h) +\n L * ∑ k : Fin q, (τ k : ℝ) * a₀ h k :=\n add_le_add hminus hplus\n _ = ∑ s ∈ ({-1, 1} : Finset ℤ), ∑ τ : RSigns q,\n ⨆ h, c h + L *\n ((∑ k : Fin q, (τ k : ℝ) * a₀ h k) + (s : ℝ) * x h) := by\n simp [add_comm, add_assoc]\n congr 1 <;> apply Finset.sum_congr rfl <;> intro τ _ <;>\n apply congrArg <;> funext h <;> ring\n _ = ∑ σ : RSigns (q + 1), QL (σ (Fin.last q)) (Fin.init σ) :=\n signs_split QL\n _ = ∑ σ : RSigns (q + 1),\n ⨆ h, c h + L * ∑ k : Fin (q + 1), (σ k : ℝ) * a h k := by\n apply Finset.sum_congr rfl\n intro σ _\n dsimp only [QL]\n apply congrArg\n funext h\n rw [Fin.sum_univ_castSucc]\n rfl\n\nprivate def flipSign {n : ℕ} (k : Fin n) (σ : RSigns n) : RSigns n :=\n fun i => if i = k then -(σ i) else σ i\n\nprivate lemma flipSign_involutive {n : ℕ} (k : Fin n) :\n Function.Involutive (flipSign k) := by\n intro σ\n funext i\n dsimp [flipSign]\n by_cases h : i = k\n · subst i\n simp\n apply Subtype.ext\n change - -((σ k : ℤ)) = (σ k : ℤ)\n ring_nf\n · simp [h]\n\nprivate lemma sign_orthogonality {n : ℕ} (k l : Fin n) (hkl : k ≠ l) :\n ∑ σ : RSigns n, (σ k : ℝ) * (σ l : ℝ) = 0 := by\n let e : RSigns n ≃ RSigns n :=\n { toFun := flipSign k\n invFun := flipSign k\n left_inv := flipSign_involutive k\n right_inv := flipSign_involutive k }\n have heq :\n ∑ σ : RSigns n, (σ k : ℝ) * (σ l : ℝ) =\n ∑ σ : RSigns n, ((e σ) k : ℝ) * ((e σ) l : ℝ) := by\n exact Fintype.sum_equiv e _ _ (fun x => by\n rw [show e (e x) = x from flipSign_involutive k x])\n have hneg :\n ∑ σ : RSigns n, ((e σ) k : ℝ) * ((e σ) l : ℝ) =\n -∑ σ : RSigns n, (σ k : ℝ) * (σ l : ℝ) := by\n rw [← Finset.sum_neg_distrib]\n apply Finset.sum_congr rfl\n intro σ _\n dsimp [e, flipSign]\n rw [if_pos rfl, if_neg (Ne.symm hkl)]\n change ((-(σ k : ℤ) : ℤ) : ℝ) * ((σ l : ℤ) : ℝ) =\n -(((σ k : ℤ) : ℝ) * ((σ l : ℤ) : ℝ))\n push_cast\n ring\n linarith\n\nprivate lemma rademacher_norm_sq_average\n {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]\n {n : ℕ} (Y : Fin n → H) :\n (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, ‖∑ k : Fin n, (σ k : ℝ) • Y k‖ ^ 2 =\n ∑ k : Fin n, ‖Y k‖ ^ 2 := by\n let A : RSigns n → Fin n → Fin n → ℝ :=\n fun σ k l => (σ k : ℝ) * (σ l : ℝ) * inner ℝ (Y k) (Y l)\n have hexpand : ∀ σ : RSigns n,\n ‖∑ k : Fin n, (σ k : ℝ) • Y k‖ ^ 2 =\n ∑ k : Fin n, ∑ l : Fin n, A σ k l := by\n intro σ\n calc\n _ = inner ℝ (∑ k : Fin n, (σ k : ℝ) • Y k)\n (∑ l : Fin n, (σ l : ℝ) • Y l) := by\n symm\n exact real_inner_self_eq_norm_sq _\n _ = ∑ k : Fin n, inner ℝ ((σ k : ℝ) • Y k)\n (∑ l : Fin n, (σ l : ��) • Y l) := by rw [sum_inner]\n _ = ∑ k : Fin n, ∑ l : Fin n,\n inner ℝ ((σ k : ℝ) • Y k) ((σ l : ℝ) • Y l) := by\n apply Finset.sum_congr rfl\n intro k _\n rw [inner_sum]\n _ = _ := by\n apply Finset.sum_congr rfl\n intro k _\n apply Finset.sum_congr rfl\n intro l _\n simp only [A, real_inner_smul_left, real_inner_smul_right]\n ring\n have hsign : ∀ k l : Fin n,\n ∑ σ : RSigns n, (σ k : ℝ) * (σ l : ℝ) =\n if k = l then (Fintype.card (RSigns n) : ℝ) else 0 := by\n intro k l\n by_cases hkl : k = l\n · subst l\n simp only [if_pos]\n calc\n ∑ σ : RSigns n, (σ k : ℝ) * (σ k : ℝ) =\n ∑ _σ : RSigns n, (1 : ℝ) := by\n apply Finset.sum_congr rfl\n intro σ _\n calc\n (σ k : ℝ) * (σ k : ℝ) = (σ k : ℝ) ^ 2 := by ring\n _ = |(σ k : ℝ)| ^ 2 := (sq_abs _).symm\n _ = 1 := by rw [sign_abs]; norm_num\n _ = _ := by simp\n · simpa [hkl] using sign_orthogonality k l hkl\n calc\n _ = (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, ∑ k : Fin n, ∑ l : Fin n, A σ k l := by\n apply congrArg\n exact Finset.sum_congr rfl fun σ _ => hexpand σ\n _ = (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ k : Fin n, ∑ l : Fin n, ∑ σ : RSigns n, A σ k l := by\n congr 1\n rw [Finset.sum_comm]\n apply Finset.sum_congr rfl\n intro k _\n rw [Finset.sum_comm]\n _ = (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ k : Fin n, ∑ l : Fin n,\n (if k = l then (Fintype.card (RSigns n) : ℝ) else 0) *\n inner ℝ (Y k) (Y l) := by\n congr 1\n apply Finset.sum_congr rfl\n intro k _\n apply Finset.sum_congr rfl\n intro l _\n simp only [A]\n rw [← Finset.sum_mul, hsign k l]\n _ = (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ((Fintype.card (RSigns n) : ℝ) * ∑ k : Fin n, ‖Y k‖ ^ 2) := by\n apply congrArg\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro k _\n rw [Finset.sum_eq_single k]\n · simp\n · intro l _ hlk\n simp [Ne.symm hlk]\n · simp\n _ = _ := by\n have hc : (Fintype.card (RSigns n) : ℝ) ≠ 0 := by positivity\n field_simp [hc]\n\nprivate lemma rademacher_norm_average_le\n {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]\n {n : ℕ} (Y : Fin n → H) :\n (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, ‖∑ k : Fin n, (σ k : ℝ) • Y k‖ ≤\n Real.sqrt (∑ k : Fin n, ‖Y k‖ ^ 2) := by\n have hs :\n ((Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, ‖∑ k : Fin n, (σ k : ℝ) • Y k‖) ^ 2 ≤\n (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, ‖∑ k : Fin n, (σ k : ℝ) • Y k‖ ^ 2 := by\n let f : RSigns n → ℝ := fun _ => 1\n let g : RSigns n → ℝ := fun σ =>\n ‖∑ k : Fin n, (σ k : ℝ) • Y k‖ *\n (Fintype.card (RSigns n) : ℝ)⁻¹\n have hcs := Finset.sum_mul_sq_le_sq_mul_sq\n (s := (Finset.univ : Finset (RSigns n))) f g\n dsimp only [f, g] at hcs\n simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ,\n nsmul_eq_mul, mul_one] at hcs\n have hc : (Fintype.card (RSigns n) : ℝ) ≠ 0 := by positivity\n calc\n _ = (∑ σ : RSigns n,\n ‖∑ k : Fin n, (σ k : ℝ) • Y k‖ *\n (Fintype.card (RSigns n) : ℝ)⁻¹) ^ 2 := by\n congr 1\n rw [mul_comm, Finset.sum_mul]\n _ ≤ (Fintype.card (RSigns n) : ℝ) *\n ∑ σ : RSigns n,\n (‖∑ k : Fin n, (σ k : ℝ) • Y k‖ *\n (Fintype.card (RSigns n) : ℝ)⁻¹) ^ 2 := hcs\n _ = _ := by\n rw [show (∑ σ : RSigns n,\n (‖∑ k : Fin n, (σ k : ℝ) • Y k‖ *\n (Fintype.card (RSigns n) : ℝ)⁻¹) ^ 2) =\n ∑ σ : RSigns n,\n ‖∑ k : Fin n, (σ k : ℝ) • Y k‖ ^ 2 *\n ((Fintype.card (RSigns n) : ℝ)⁻¹)^2 by\n apply Finset.sum_congr rfl\n intro σ _\n ring]\n rw [← Finset.sum_mul]\n field_simp [hc]\n apply (le_sqrt_of_sq_le hs).trans_eq\n rw [rademacher_norm_sq_average Y]\n\nprivate abbrev UBall (d : ℕ) (B : ℝ) :=\n Metric.closedBall (0 : EuclideanSpace ℝ (Fin d)) B\n\nprivate def negSignsEquiv (n : ℕ) : RSigns n ≃ RSigns n where\n toFun σ := fun k => -(σ k)\n invFun σ := fun k => -(σ k)\n left_inv σ := by\n funext k\n apply Subtype.ext\n change - -((σ k : ℤ)) = (σ k : ℤ)\n ring_nf\n right_inv σ := by\n funext k\n apply Subtype.ext\n change - -((σ k : ℤ)) = (σ k : ℤ)\n ring_nf\n\nprivate lemma relu_abs_sign_sum_le\n {d n : ℕ} (B : ℝ) (hB : 0 ≤ B)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n ∑ σ : RSigns n,\n ⨆ u : UBall d B,\n |∑ k : Fin n, (σ k : ℝ) *\n reluAct (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))| ≤\n 2 * ∑ σ : RSigns n,\n ⨆ u : UBall d B,\n ∑ k : Fin n, (σ k : ℝ) *\n reluAct (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k)) := by\n letI : Nonempty (UBall d B) :=\n (Metric.nonempty_closedBall.mpr hB).to_subtype\n let F : RSigns n → UBall d B → ℝ := fun σ u =>\n ∑ k : Fin n, (σ k : ℝ) *\n reluAct (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))\n have hFc : ∀ σ, Continuous (F σ) := by\n intro σ\n exact continuous_finset_sum _ fun k _ =>\n continuous_const.mul\n (reluAct_continuous.comp (by fun_prop))\n have hone : ∀ σ,\n (⨆ u, |F σ u|) ≤ (⨆ u, F σ u) + (⨆ u, -F σ u) := by\n intro σ\n apply ciSup_le\n intro u\n let u0 : UBall d B := ⟨0, by simpa using hB⟩\n have hF0 : F σ u0 = 0 := by\n simp [F, u0, reluAct]\n have hp0 : 0 ≤ ⨆ u, F σ u := by\n rw [← hF0]\n exact le_ciSup (bddAbove_range_of_compact _ (hFc σ)) u0\n have hn0 : 0 ≤ ⨆ u, -F σ u := by\n rw [show (0 : ℝ) = -F σ u0 by rw [hF0]; simp]\n exact le_ciSup (bddAbove_range_of_compact _ (hFc σ).neg) u0\n apply abs_le.mpr\n constructor\n · have hu := le_ciSup (bddAbove_range_of_compact _ (hFc σ).neg) u\n linarith\n · have hu := le_ciSup (bddAbove_range_of_compact _ (hFc σ)) u\n linarith\n have hneg :\n ∑ σ : RSigns n, (⨆ u : UBall d B, -F σ u) =\n ∑ σ : RSigns n, (⨆ u : UBall d B, F σ u) := by\n let e := negSignsEquiv n\n refine Fintype.sum_equiv e _ _ ?_\n intro σ\n apply congrArg\n funext u\n dsimp [e, negSignsEquiv, F]\n rw [← Finset.sum_neg_distrib]\n apply Finset.sum_congr rfl\n intro k _\n change -(((σ k : ℤ) : ℝ) *\n reluAct (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))) =\n (((-(σ k : ℤ) : ℤ) : ℝ) *\n reluAct (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k)))\n push_cast\n ring\n change (∑ σ : RSigns n, ⨆ u : UBall d B, |F σ u|) ≤\n 2 * ∑ σ : RSigns n, ⨆ u : UBall d B, F σ u\n calc\n _ ≤ ∑ σ : RSigns n, ((⨆ u, F σ u) + (⨆ u, -F σ u)) := by\n exact Finset.sum_le_sum fun σ _ => hone σ\n _ = (∑ σ : RSigns n, ⨆ u, F σ u) +\n ∑ σ : RSigns n, ⨆ u, -F σ u := Finset.sum_add_distrib\n _ = 2 * ∑ σ : RSigns n, ⨆ u, F σ u := by rw [hneg]; ring\n\nprivate lemma relu_sign_contraction\n {d n : ℕ} (B : ℝ) (hB : 0 ≤ B)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n ∑ σ : RSigns n,\n ⨆ u : UBall d B,\n ∑ k : Fin n, (σ k : ℝ) *\n reluAct (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k)) ≤\n ∑ σ : RSigns n,\n ⨆ u : UBall d B,\n ∑ k : Fin n, (σ k : ℝ) *\n inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k) := by\n letI : Nonempty (UBall d B) :=\n (Metric.nonempty_closedBall.mpr hB).to_subtype\n have h := sum_iSup_contraction_compact n\n (fun (u : UBall d B) k => inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))\n (fun _ => reluAct) (fun _ => 0)\n (L := 1) (fun _ => by fun_prop)\n (fun _ => reluAct_continuous)\n continuous_const (fun _ x y => by\n simpa [Real.dist_eq] using\n reluAct_lipschitzWith.dist_le_mul x y)\n simpa using h\n\nprivate lemma linear_sign_sup_average_le\n {d n : ℕ} (B : ℝ) (hB : 0 ≤ B)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n,\n ⨆ u : UBall d B,\n ∑ k : Fin n, (σ k : ℝ) *\n inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k) ≤\n B * Real.sqrt (∑ k : Fin n, ‖S k‖ ^ 2) := by\n letI : Nonempty (UBall d B) :=\n (Metric.nonempty_closedBall.mpr hB).to_subtype\n calc\n _ ≤ (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, B * ‖∑ k : Fin n, (σ k : ℝ) • S k‖ := by\n gcongr with σ\n apply ciSup_le\n intro u\n have heq :\n ∑ k : Fin n, (σ k : ℝ) *\n inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k) =\n inner ℝ (u : EuclideanSpace ℝ (Fin d))\n (∑ k : Fin n, (σ k : ℝ) • S k) := by\n rw [inner_sum]\n apply Finset.sum_congr rfl\n intro k _\n rw [real_inner_smul_right]\n rw [heq]\n exact (le_abs_self _).trans <| (abs_real_inner_le_norm _ _).trans <| by\n gcongr\n exact mem_closedBall_zero_iff.mp u.property\n _ = B * ((Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, ‖∑ k : Fin n, (σ k : ℝ) • S k‖) := by\n rw [← Finset.mul_sum]\n ring\n _ ≤ _ := by\n gcongr\n exact rademacher_norm_average_le S\n\nprivate lemma empirical_net_bound\n {d m n : ℕ} (Bw Bu : ℝ) (hBw : 0 ≤ Bw) (hBu : 0 ≤ Bu)\n (S : Fin n → EuclideanSpace ℝ (Fin d)) :\n empRadSigned n\n (fun (p : NetParam d m Bw Bu) => netFun p) S ≤\n 2 * Bw * Bu * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹ *\n Real.sqrt (∑ k : Fin n, ‖S k‖ ^ 2) := by\n letI : Nonempty (NetParam d m Bw Bu) := ⟨⟨(0, fun _ => 0), by\n constructor\n · simpa using hBw\n · intro i\n simpa using hBu⟩⟩\n letI : Nonempty (UBall d Bu) :=\n (Metric.nonempty_closedBall.mpr hBu).to_subtype\n let M : RSigns n → ℝ := fun σ =>\n ⨆ u : UBall d Bu,\n |∑ k : Fin n, (σ k : ℝ) *\n reluAct\n (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))|\n have hMc : ∀ σ : RSigns n, Continuous fun u : UBall d Bu =>\n |∑ k : Fin n, (σ k : ℝ) *\n reluAct\n (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))| := by\n intro σ\n exact (continuous_finset_sum _ fun k _ =>\n continuous_const.mul\n (reluAct_continuous.comp (by fun_prop))).abs\n have hM0 : ∀ σ, 0 ≤ M σ := by\n intro σ\n change 0 ≤ ⨆ u : UBall d Bu,\n |∑ k : Fin n, (σ k : ℝ) *\n reluAct\n (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))|\n obtain ⟨u, hu⟩ := exists_eq_ciSup_of_compact _ (hMc σ)\n rw [← hu]\n positivity\n have hraw : ∀ (σ : RSigns n) (p : NetParam d m Bw Bu),\n ∑ k : Fin n, (σ k : ℝ) * netFun p (S k) ≤\n Bw * Real.sqrt (m : ℝ) * M σ := by\n intro σ p\n let v : EuclideanSpace ℝ (Fin m) := WithLp.toLp 2 fun j =>\n ∑ k : Fin n, (σ k : ℝ) *\n reluAct (inner ℝ (p.1.2 j) (S k))\n have heq :\n ∑ k : Fin n, (σ k : ℝ) * netFun p (S k) =\n inner ℝ p.1.1 v := by\n simp only [netFun, v, PiLp.inner_apply, RCLike.inner_apply, conj_trivial]\n simp_rw [Finset.mul_sum]\n rw [Finset.sum_comm]\n apply Finset.sum_congr rfl\n intro j _\n rw [Finset.sum_mul]\n apply Finset.sum_congr rfl\n intro k _\n ring\n have hv : ‖v‖ ≤ Real.sqrt (m : ℝ) * M σ := by\n rw [EuclideanSpace.norm_eq]\n calc\n Real.sqrt (∑ j : Fin m, ‖v j‖ ^ 2) ≤\n Real.sqrt (∑ _j : Fin m, (M σ) ^ 2) := by\n gcongr with j\n have hj :\n |v j| ≤ M σ := by\n exact le_ciSup (bddAbove_range_of_compact _ (hMc σ))\n (⟨p.1.2 j, by\n simpa [mem_closedBall_zero_iff] using p.2.2 j⟩ : UBall d Bu)\n simpa [Real.norm_eq_abs] using hj\n _ = Real.sqrt ((m : ℝ) * (M σ) ^ 2) := by simp\n _ = Real.sqrt (m : ℝ) * M σ := by\n rw [Real.sqrt_mul (Nat.cast_nonneg m), Real.sqrt_sq_eq_abs,\n abs_of_nonneg (hM0 σ)]\n rw [heq]\n calc\n inner ℝ p.1.1 v ≤ |inner ℝ p.1.1 v| := le_abs_self _\n _ ≤ ‖p.1.1‖ * ‖v‖ := abs_real_inner_le_norm _ _\n _ ≤ Bw * (Real.sqrt (m : ℝ) * M σ) := by\n exact mul_le_mul p.2.1 hv (norm_nonneg _) hBw\n _ = _ := by ring\n unfold empRadSigned\n have hq : 0 ≤ (n : ℝ)⁻¹ := inv_nonneg.mpr (Nat.cast_nonneg n)\n calc\n (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, ⨆ p : NetParam d m Bw Bu,\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * netFun p (S k) ≤\n (Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n, (n : ℝ)⁻¹ *\n (Bw * Real.sqrt (m : ℝ) * M σ) := by\n gcongr with σ\n apply ciSup_le\n intro p\n exact mul_le_mul_of_nonneg_left\n (hraw σ p) hq\n _ = Bw * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹ *\n ((Fintype.card (RSigns n) : ℝ)⁻¹ * ∑ σ : RSigns n, M σ) := by\n simp_rw [show ∀ σ, (n : ℝ)⁻¹ * (Bw * Real.sqrt (m : ℝ) * M σ) =\n ((n : ℝ)⁻¹ * Bw * Real.sqrt (m : ℝ)) * M σ by\n intro σ\n ring]\n rw [← Finset.mul_sum]\n ring\n _ ≤ Bw * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹ *\n ((Fintype.card (RSigns n) : ℝ)⁻¹ *\n (2 * ∑ σ : RSigns n,\n ⨆ u : UBall d Bu,\n ∑ k : Fin n, (σ k : ℝ) *\n reluAct\n (inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k)))) := by\n gcongr\n exact relu_abs_sign_sum_le Bu hBu S\n _ ≤ Bw * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹ *\n ((Fintype.card (RSigns n) : ℝ)⁻¹ *\n (2 * ∑ σ : RSigns n,\n ⨆ u : UBall d Bu,\n ∑ k : Fin n, (σ k : ℝ) *\n inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k))) := by\n apply mul_le_mul_of_nonneg_left\n · apply mul_le_mul_of_nonneg_left\n · apply mul_le_mul_of_nonneg_left\n · exact relu_sign_contraction Bu hBu S\n · positivity\n · positivity\n · positivity\n _ ≤ 2 * Bw * Bu * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹ *\n Real.sqrt (∑ k : Fin n, ‖S k‖ ^ 2) := by\n have hl := linear_sign_sup_average_le Bu hBu S\n calc\n _ = (2 * Bw * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹) *\n ((Fintype.card (RSigns n) : ℝ)⁻¹ *\n ∑ σ : RSigns n,\n ⨆ u : UBall d Bu,\n ∑ k : Fin n, (σ k : ℝ) *\n inner ℝ (u : EuclideanSpace ℝ (Fin d)) (S k)) := by ring\n _ ≤ (2 * Bw * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹) *\n (Bu * Real.sqrt (∑ k : Fin n, ‖S k‖ ^ 2)) :=\n mul_le_mul_of_nonneg_left hl (by positivity)\n _ = _ := by ring\n\ntheorem ch5_theorem_5_9 {d m n : ℕ} (Bw Bu C : ℝ) (hBw : 0 < Bw) (hBu : 0 < Bu) (hC : 0 ≤ C) (hn : 0 < n) {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (X : Ω → EuclideanSpace ℝ (Fin d)) (hXmeas : AEMeasurable X μ) (hXsq_int : Integrable (fun ω => ‖X ω‖ ^ 2) μ) (hmom : ∫ ω, ‖X ω‖ ^ 2 ∂μ ≤ C ^ 2) : popRadSigned n (fun (p : NetParam d m Bw Bu) => netFun p) μ X ≤ 2 * Bw * Bu * C * Real.sqrt (m / n) := by\n have _hXmeas_used : AEMeasurable X μ := hXmeas\n let ν : Measure (Fin n → Ω) := Measure.pi (fun _ => μ)\n let q : (Fin n → Ω) → ℝ := fun ω =>\n ∑ k : Fin n, ‖X (ω k)‖ ^ 2\n let g : (Fin n → Ω) → ℝ := fun ω =>\n empRadSigned n\n (fun (p : NetParam d m Bw Bu) => netFun p) (X ∘ ω)\n let K : ℝ := 2 * Bw * Bu * Real.sqrt (m : ℝ) * (n : ℝ)⁻¹\n have hq0 : ∀ ω, 0 ≤ q ω := fun ω => by\n dsimp [q]\n positivity\n have hqi : Integrable q ν := by\n dsimp [q, ν]\n apply integrable_finset_sum\n intro k _\n simpa using\n (MeasureTheory.integrable_comp_eval (μ := fun _ : Fin n => μ)\n (i := k) hXsq_int)\n have hqint :\n (∫ ω, q ω ∂ν) ≤ (n : ℝ) * C ^ 2 := by\n calc\n (∫ ω, q ω ∂ν) =\n ∑ k : Fin n, ∫ ω : Fin n → Ω, ‖X (ω k)‖ ^ 2 ∂ν := by\n dsimp [q]\n rw [MeasureTheory.integral_finset_sum]\n intro k _\n simpa [ν] using\n (MeasureTheory.integrable_comp_eval (μ := fun _ : Fin n => μ)\n (i := k) hXsq_int)\n _ = ∑ _k : Fin n, ∫ ω, ‖X ω‖ ^ 2 ∂μ := by\n apply Finset.sum_congr rfl\n intro k _\n exact MeasureTheory.integral_comp_eval\n (μ := fun _ : Fin n => μ) (i := k) hXsq_int.aestronglyMeasurable\n _ = (n : ℝ) * ∫ ω, ‖X ω‖ ^ 2 ∂μ := by simp\n _ ≤ (n : ℝ) * C ^ 2 := by\n gcongr\n have hsqrt_int : Integrable (fun ω => Real.sqrt (q ω)) ν := by\n apply (hqi.add (integrable_const (1 : ℝ))).mono'\n · exact Real.continuous_sqrt.comp_aestronglyMeasurable\n hqi.aestronglyMeasurable\n · filter_upwards [] with ω\n rw [Real.norm_of_nonneg (Real.sqrt_nonneg _)]\n change Real.sqrt (q ω) ≤ q ω + 1\n rw [Real.sqrt_le_iff]\n constructor\n · linarith [hq0 ω]\n · nlinarith [hq0 ω, sq_nonneg (q ω)]\n have hsqrt_expect :\n (∫ ω, Real.sqrt (q ω) ∂ν) ≤ C * Real.sqrt (n : ℝ) := by\n have hj :\n (∫ ω, Real.sqrt (q ω) ∂ν) ≤\n Real.sqrt (∫ ω, q ω ∂ν) := by\n simpa [Function.comp_def] using\n (Real.strictConcaveOn_sqrt.concaveOn.le_map_integral\n Real.continuous_sqrt.continuousOn isClosed_Ici\n (show ∀ᵐ ω ∂ν, q ω ∈ Set.Ici (0 : ℝ) from\n Filter.Eventually.of_forall hq0)\n hqi hsqrt_int)\n calc\n _ ≤ Real.sqrt (∫ ω, q ω ∂ν) := hj\n _ ≤ Real.sqrt ((n : ℝ) * C ^ 2) := by gcongr\n _ = Real.sqrt (n : ℝ) * C := by\n rw [Real.sqrt_mul (Nat.cast_nonneg n), Real.sqrt_sq_eq_abs,\n abs_of_nonneg hC]\n _ = C * Real.sqrt (n : ℝ) := by ring\n have hpoint : ∀ ω, g ω ≤ K * Real.sqrt (q ω) := by\n intro ω\n simpa [g, K, q, Function.comp_def] using\n empirical_net_bound Bw Bu hBw.le hBu.le (X ∘ ω)\n have hfinal_alg :\n K * (C * Real.sqrt (n : ℝ)) =\n 2 * Bw * Bu * C * Real.sqrt ((m : ℝ) / (n : ℝ)) := by\n have hnR : (0 : ℝ) < n := Nat.cast_pos.mpr hn\n have hsne : Real.sqrt (n : ℝ) ≠ 0 := by positivity\n dsimp [K]\n rw [Real.sqrt_div (Nat.cast_nonneg m)]\n field_simp [hsne, hnR.ne']\n rw [Real.sq_sqrt hnR.le]\n ring\n unfold popRadSigned\n change (∫ ω, g ω ∂ν) ≤ _\n by_cases hg : Integrable g ν\n · have hr : Integrable (fun ω => K * Real.sqrt (q ω)) ν :=\n hsqrt_int.const_mul K\n calc\n (∫ ω, g ω ∂ν) ≤ ∫ ω, K * Real.sqrt (q ω) ∂ν :=\n integral_mono_ae hg hr (Filter.Eventually.of_forall hpoint)\n _ = K * ∫ ω, Real.sqrt (q ω) ∂ν := integral_const_mul _ _\n _ ≤ K * (C * Real.sqrt (n : ℝ)) := by\n exact mul_le_mul_of_nonneg_left hsqrt_expect (by positivity)\n _ = _ := hfinal_alg\n · rw [integral_undef hg]\n positivity\n\nend GraduateLevel\n"} +{"id": "ch9_theorem_9_2", "source": "Graduate-level", "targets": [{"label": "ch9_theorem_9_2", "decls": ["ch9_theorem_9_2"], "statement": "Let \\(t \\leqslant n\\), \\(L, R > 0\\). There exists a convex \\(L\\)-Lipschitz function \\(f\\) such that any black-box procedure started at \\(x_0 = 0\\) satisfies \\[ \\min_{1 \\leqslant s \\leqslant t} f(x_s) - \\min_{x \\in B_2(R)} f(x) \\geqslant \\frac{RL}{2(1+\\sqrt{t})}. \\] Furthermore, there is an \\(\\alpha\\)-strongly convex, \\(L\\)-Lipschitz function \\(f\\) such that \\[ \\min_{1 \\leqslant s \\leqslant t} f(x_s) - \\min_{x \\in B_2(\\frac{L}{2\\alpha})} f(x) \\geqslant \\frac{L^2}{8\\alpha t}. \\]", "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}], "nl_proof": "Consider the function \\[ f(x) = \\gamma \\max_{1 \\leqslant i \\leqslant t} x[i] + \\frac{\\alpha}{2} \\|x\\|^2, \\] for some \\(\\gamma, \\alpha \\in \\mathbb{R}\\). In the strongly convex case, \\(\\gamma\\) is a free parameter, and in the Lipschitz case both \\(\\alpha\\) and \\(\\gamma\\) are free parameters. By the subdifferential calculus, \\[ \\partial f(x) = \\alpha x + \\gamma \\conv\\{e_i \\colon i \\in \\argmax_{1 \\leqslant j \\leqslant t} x(j)\\}. \\] The function \\(f\\) is evidently \\(\\alpha\\)-strongly convex. Furthermore, if \\(\\|x\\| \\leqslant R\\) and \\(g \\in \\partial f(x)\\), then \\(\\|g\\| \\leqslant \\alpha R + \\gamma\\), so \\(f\\) is \\((\\alpha R + \\gamma)\\)-Lipschitz on \\(B_2(R)\\). Suppose the gradient oracle returns \\(g_i = \\alpha x + \\gamma e_i\\), where \\(i\\) is the first coordinate such that \\(x[i] = \\max_{1 \\leqslant j \\leqslant t} x[j]\\). An inductive argument then shows \\[ x_s \\in \\Span\\{e_1, \\dots, e_{s-1}\\} \\] Consequently, for \\(s \\leqslant t\\), \\(f(x_s) \\geqslant 0\\). However, consider \\(y\\in \\mathbb{R}^n\\) such that \\[ y[i] = \\begin{cases} -\\frac{\\gamma}{\\alpha t} &\\text{if } 1 \\leqslant i \\leqslant t\\\\ 0 &\\text{otherwise}. \\end{cases} \\] Since \\(0 \\in \\partial f(y)\\), \\(y\\) is a minimizer of \\(f\\) with objective value \\[ f(y) = \\frac{-\\gamma^2}{\\alpha t} + \\frac{\\alpha}{2}\\frac{\\gamma^2}{\\alpha^2 t} = -\\frac{\\gamma^2}{2\\alpha t}, \\] and hence \\(f(x_s) - f(y) \\geqslant \\frac{\\gamma^2}{2 \\alpha t}\\). We conclude the proof by appropriately choosing \\(\\alpha\\) and \\(\\gamma\\). In the convex, Lipschitz case, set \\[ \\alpha = \\frac{L}{R} \\frac{1}{1 + \\sqrt{t}} \\quad \\text{and} \\quad \\gamma = L \\frac{\\sqrt{t}}{1 + \\sqrt{t}}. \\] Then, \\(f\\) is \\(L\\)-Lipschitz, \\[ \\|y\\| = \\sqrt{t \\left(\\frac{-\\gamma}{\\alpha t} \\right)^2} = \\frac{\\gamma}{\\alpha \\sqrt{t}} = R \\] and hence \\[ f(x_s) - \\min_{x \\in B_2(R)} f(x) = f(x_s) - f(y) \\geqslant \\frac{\\gamma^2}{2\\alpha t} = \\frac{RL}{2(1+\\sqrt{t})}. \\] In the strongly-convex case, set \\(\\gamma = \\frac{L}{2}\\) and take \\(R = \\frac{L}{2\\alpha}\\). Then, \\(f\\) is \\(L\\)-Lipschitz, \\[ \\|y\\| = \\frac{\\gamma}{\\alpha \\sqrt{t}} = \\frac{L}{2\\alpha \\sqrt{t}} = \\frac{R}{\\sqrt{t}} \\leqslant R, \\] and therefore \\[ f(x_s) - \\min_{x \\in B_2(L/2\\alpha)} f(x) = f(x_s) - f(y) \\geqslant \\frac{LR}{4t} = \\frac{L^2}{8\\alpha t}. \\]", "context": [{"id": "ch9:definition:9_1", "name": "Black-Box Procedure", "statement": "A \\textit{black-box procedure} generates a sequence of points \\(\\{x_t\\}\\) such that \\[ x_{t+1} \\in x_0 + \\Span\\{g_1, \\dots, g_t\\}, \\] and \\(g_s \\in \\partial f (x_s)\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory RealInnerProductSpace\n\nnamespace GraduateLevel\n\ndef HasSubgradientAt {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (f : E → ℝ) (g x : E) : Prop :=\n ∀ y, f y ≥ f x + ⟪g, y - x⟫\n\ndef SubderivAt {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (f : E → ℝ) (x : E) : Set E :=\n {g : E | HasSubgradientAt f g x}\n\ndef OracleProcedure {n : ℕ} (f : EuclideanSpace ℝ (Fin n) → ℝ)\n (G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n))\n (x : ℕ → EuclideanSpace ℝ (Fin n)) : Prop :=\n x 0 = 0 ∧\n (∀ s, x (s + 1) - x 0 ∈\n Submodule.span ℝ ((fun i => G (x i)) '' Set.Icc 1 s))\n\ntheorem ch9_theorem_9_2 (n t : ℕ) (L R α : ℝ)\n (ht : 1 ≤ t) (htn : t ≤ n) (hL : 0 < L) (hR : 0 < R) (hα : 0 < α) :\n (∃ f : EuclideanSpace ℝ (Fin n) → ℝ,\n ConvexOn ℝ Set.univ f ∧\n LipschitzOnWith L.toNNReal f (Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R) ∧\n ∃ G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n),\n (∀ z, G z ∈ SubderivAt f z) ∧\n ∀ x : ℕ → EuclideanSpace ℝ (Fin n), OracleProcedure f G x →\n ((Finset.Icc 1 t).image (fun s => f (x s))).min'\n (by simpa [Finset.image_nonempty, Finset.nonempty_Icc] using ht)\n - sInf (f '' Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R)\n ≥ R * L / (2 * (1 + Real.sqrt t))) ∧\n (∃ f : EuclideanSpace ℝ (Fin n) → ℝ,\n StrongConvexOn Set.univ α f ∧\n LipschitzOnWith L.toNNReal f\n (Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) (L / (2 * α))) ∧\n ∃ G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n),\n (∀ z, G z ∈ SubderivAt f z) ∧\n ∀ x : ℕ → EuclideanSpace ℝ (Fin n), OracleProcedure f G x →\n ((Finset.Icc 1 t).image (fun s => f (x s))).min'\n (by simpa [Finset.image_nonempty, Finset.nonempty_Icc] using ht)\n - sInf (f '' Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) (L / (2 * α)))\n ≥ L ^ 2 / (8 * α * t)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory RealInnerProductSpace\n\nset_option maxHeartbeats 1000000\n\nnamespace GraduateLevel\n\ndef HasSubgradientAt {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (f : E → ℝ) (g x : E) : Prop :=\n ∀ y, f y ≥ f x + ⟪g, y - x⟫\n\ndef SubderivAt {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n (f : E → ℝ) (x : E) : Set E :=\n {g : E | HasSubgradientAt f g x}\n\ndef OracleProcedure {n : ℕ} (f : EuclideanSpace ℝ (Fin n) → ℝ)\n (G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n))\n (x : ℕ → EuclideanSpace ℝ (Fin n)) : Prop :=\n x 0 = 0 ∧\n (∀ s, x (s + 1) - x 0 ∈\n Submodule.span ℝ ((fun i => G (x i)) '' Set.Icc 1 s))\n\nsection Aux\n\nprivate lemma abs_coord_le {n : ℕ} (x : EuclideanSpace ℝ (Fin n)) (a : Fin n) :\n |x a| ≤ ‖x‖ := by\n have h := abs_real_inner_le_norm (EuclideanSpace.single a (1:ℝ)) x\n rw [EuclideanSpace.inner_single_left] at h\n simpa using h\n\nprivate def Wsub (n t : ℕ) (htn : t ≤ n) (m : ℕ) :\n Submodule ℝ (EuclideanSpace ℝ (Fin n)) where\n carrier := {x | ∀ i : Fin t, m ≤ (i:ℕ) → x (Fin.castLE htn i) = 0}\n zero_mem' := by intro i _; simp\n add_mem' := by intro a b ha hb i hi; simp [ha i hi, hb i hi]\n smul_mem' := by intro c a ha i hi; simp [ha i hi]\n\nprivate lemma mem_Wsub {n t : ℕ} {htn : t ≤ n} {m : ℕ}\n {x : EuclideanSpace ℝ (Fin n)} :\n x ∈ Wsub n t htn m ↔ ∀ i : Fin t, m ≤ (i:ℕ) → x (Fin.castLE htn i) = 0 := Iff.rfl\n\nprivate theorem key (n t : ℕ) (ht : 1 ≤ t) (htn : t ≤ n) (α γ R K B c : ℝ)\n (hα : 0 ≤ α) (hγ : 0 ≤ γ) (hR : 0 < R) (hK : γ + α * R ≤ K)\n (hc : 0 ≤ c) (hcR : c * Real.sqrt t ≤ R)\n (hB : B ≤ γ * c - (α/2) * c^2 * t) :\n ∃ f : EuclideanSpace ℝ (Fin n) → ℝ,\n ConvexOn ℝ Set.univ f ∧ StrongConvexOn Set.univ α f ∧\n LipschitzOnWith K.toNNReal f (Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R) ∧\n ∃ G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n),\n (∀ z, G z ∈ SubderivAt f z) ∧\n ∀ x : ℕ → EuclideanSpace ℝ (Fin n), OracleProcedure f G x →\n ∀ h : ((Finset.Icc 1 t).image (fun s => f (x s))).Nonempty,\n ((Finset.Icc 1 t).image (fun s => f (x s))).min' h\n - sInf (f '' Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R) ≥ B := by\n classical\n haveI : Nonempty (Fin t) := ⟨⟨0, by omega⟩⟩\n have hne : (Finset.univ : Finset (Fin t)).Nonempty := Finset.univ_nonempty\n set ι : Fin t → Fin n := Fin.castLE htn with hιdef\n set M : EuclideanSpace ℝ (Fin n) → ℝ :=\n fun x => Finset.univ.sup' hne (fun i : Fin t => x (ι i)) with hMdef\n set f : EuclideanSpace ℝ (Fin n) → ℝ := fun x => γ * M x + (α/2) * ‖x‖^2 with hfdef\n have hMle : ∀ (x : EuclideanSpace ℝ (Fin n)) (i : Fin t), x (ι i) ≤ M x := by\n intro x i\n exact Finset.le_sup' (fun i : Fin t => x (ι i)) (Finset.mem_univ i)\n have hkspec : ∀ x : EuclideanSpace ℝ (Fin n), ∃ i : Fin t, x (ι i) = M x := by\n intro x\n obtain ⟨b, -, hb⟩ := Finset.exists_mem_eq_sup' hne (fun i : Fin t => x (ι i))\n exact ⟨b, hb.symm⟩\n set kf : EuclideanSpace ℝ (Fin n) → Fin t :=\n fun x => (Finset.univ.filter (fun i : Fin t => x (ι i) = M x)).min'\n ⟨(hkspec x).choose, by simpa using (hkspec x).choose_spec⟩ with hkfdef\n have hk1 : ∀ x, x (ι (kf x)) = M x := by\n intro x\n have := Finset.min'_mem (Finset.univ.filter (fun i : Fin t => x (ι i) = M x))\n ⟨(hkspec x).choose, by simpa using (hkspec x).choose_spec⟩\n simpa [hkfdef] using this\n have hk2 : ∀ (x) (i : Fin t), x (ι i) = M x → (kf x : ℕ) ≤ (i : ℕ) := by\n intro x i hi\n have : kf x ≤ i := Finset.min'_le _ i (by simpa using hi)\n exact this\n set G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n) :=\n fun x => γ • EuclideanSpace.single (ι (kf x)) (1:ℝ) + α • x with hGdef\n -- basic quadratic identity\n have hquad : ∀ (u v : EuclideanSpace ℝ (Fin n)), ‖u - v‖^2 = ‖u‖^2 - 2*⟪u,v⟫ + ‖v‖^2 := by\n intro u v\n have := norm_sub_sq_real u v\n linarith [this]\n have hMc : ∀ (x y : EuclideanSpace ℝ (Fin n)) (a b : ℝ), 0 ≤ a → 0 ≤ b →\n M (a • x + b • y) ≤ a * M x + b * M y := by\n intro x y a b ha hb\n apply Finset.sup'_le\n intro i _\n have hco : (a • x + b • y) (ι i) = a * x (ι i) + b * y (ι i) := by simp\n rw [hco]\n have h1 := hMle x i\n have h2 := hMle y i\n nlinarith\n have hqid : ∀ (x y : EuclideanSpace ℝ (Fin n)) (a b : ℝ), 0 ≤ a → 0 ≤ b → a + b = 1 →\n ‖a • x + b • y‖^2 = a*‖x‖^2 + b*‖y‖^2 - a*b*‖x - y‖^2 := by\n intro x y a b ha hb hab\n have e1 : ‖a • x + b • y‖^2 = a^2*‖x‖^2 + 2*(a*b*⟪x,y⟫) + b^2*‖y‖^2 := by\n rw [norm_add_sq_real, norm_smul, norm_smul, real_inner_smul_left, real_inner_smul_right]\n simp [abs_of_nonneg ha, abs_of_nonneg hb]\n ring\n have e2 := hquad x y\n rw [e1, e2]\n linear_combination (a*‖x‖^2 + b*‖y‖^2) * hab\n have hstrong : StrongConvexOn Set.univ α f := by\n refine ⟨convex_univ, ?_⟩\n intro x _ y _ a b ha hb hab\n have h1 := hMc x y a b ha hb\n have h2 := hqid x y a b ha hb hab\n simp only [hfdef, smul_eq_mul]\n rw [h2]\n nlinarith [mul_nonneg hγ (sub_nonneg.2 h1)]\n refine ⟨f, ?_, hstrong, ?_, G, ?_, ?_⟩\n · -- ConvexOn\n refine ⟨convex_univ, ?_⟩\n intro x _ y _ a b ha hb hab\n have h := hstrong.2 (Set.mem_univ x) (Set.mem_univ y) ha hb hab\n have hnn : 0 ≤ a * b * (α/2 * ‖x - y‖^2) :=\n mul_nonneg (mul_nonneg ha hb) (mul_nonneg (by linarith) (sq_nonneg _))\n simp only [smul_eq_mul] at h ⊢\n linarith\n · -- Lipschitz\n have hK0 : 0 ≤ K := le_trans (by positivity) hK\n apply LipschitzOnWith.of_dist_le_mul\n intro u hu v hv\n have hu' : ‖u‖ ≤ R := by simpa [dist_eq_norm] using hu\n have hv' : ‖v‖ ≤ R := by simpa [dist_eq_norm] using hv\n have hMlip : ∀ p q : EuclideanSpace ℝ (Fin n), M p - M q ≤ ‖p - q‖ := by\n intro p q\n obtain ⟨i, hi⟩ := hkspec p\n have hco : |(p - q) (ι i)| ≤ ‖p - q‖ := abs_coord_le _ _\n have hco2 : (p - q) (ι i) = p (ι i) - q (ι i) := by simp\n have h2 := hMle q i\n rw [hco2] at hco\n have := abs_le.1 hco\n linarith [this.1, this.2]\n have h1 := hMlip u v\n have h2 := hMlip v u\n have hsymm : ‖v - u‖ = ‖u - v‖ := by rw [norm_sub_rev]\n rw [hsymm] at h2\n have hnorm : |‖u‖ - ‖v‖| ≤ ‖u - v‖ := abs_norm_sub_norm_le u v\n have hnn : 0 ≤ ‖u - v‖ := norm_nonneg _\n have hpq : |‖u‖ - ‖v‖| * (‖u‖ + ‖v‖) ≤ ‖u - v‖ * (2*R) :=\n mul_le_mul hnorm (by linarith) (by positivity) hnn\n have hquad2 : |(α/2) * ‖u‖^2 - (α/2)*‖v‖^2| ≤ α * R * ‖u - v‖ := by\n rw [show (α/2) * ‖u‖^2 - (α/2)*‖v‖^2 = (α/2) * ((‖u‖ - ‖v‖) * (‖u‖ + ‖v‖)) by ring,\n abs_mul, abs_of_nonneg (show (0:ℝ) ≤ α/2 by linarith), abs_mul,\n abs_of_nonneg (show (0:ℝ) ≤ ‖u‖ + ‖v‖ by positivity)]\n have := mul_le_mul_of_nonneg_left hpq (show (0:ℝ) ≤ α/2 by linarith)\n linarith\n have hq := abs_le.1 hquad2\n have e1 : γ * (M u - M v) ≤ γ * ‖u - v‖ := mul_le_mul_of_nonneg_left h1 hγ\n have e2 : γ * (M v - M u) ≤ γ * ‖u - v‖ := mul_le_mul_of_nonneg_left h2 hγ\n have e3 : 0 ≤ (K - (γ + α*R)) * ‖u - v‖ := mul_nonneg (by linarith) hnn\n rw [Real.dist_eq, dist_eq_norm, Real.coe_toNNReal K hK0]\n rw [abs_le]\n simp only [hfdef]\n constructor\n · linarith\n · linarith\n · -- subgradient\n intro z y\n show f y ≥ f z + ⟪G z, y - z⟫\n have hinner : ⟪G z, y - z⟫ = γ * ((y - z) (ι (kf z))) + α * ⟪z, y - z⟫ := by\n simp [hGdef, inner_add_left, real_inner_smul_left, EuclideanSpace.inner_single_left]\n have hco : (y - z) (ι (kf z)) = y (ι (kf z)) - z (ι (kf z)) := by simp\n have h3 := hk1 z\n have h4 := hMle y (kf z)\n have h5 : ⟪z, y - z⟫ = ⟪z, y⟫ - ‖z‖^2 := by\n rw [inner_sub_right, real_inner_self_eq_norm_sq]\n have h6 := hquad y z\n have h7 : ⟪y, z⟫ = ⟪z, y⟫ := real_inner_comm z y\n have h8 : 0 ≤ ‖y - z‖^2 := sq_nonneg _\n rw [hinner, hco, h3, h5]\n simp only [hfdef]\n nlinarith [mul_nonneg hγ (sub_nonneg.2 h4), mul_nonneg hα h8]\n · -- the lower bound\n intro x hx hnonempty\n obtain ⟨hx0, hspan⟩ := hx\n have hGW : ∀ (m : ℕ) (z : EuclideanSpace ℝ (Fin n)), m < t →\n z ∈ Wsub n t htn m → G z ∈ Wsub n t htn (m+1) := by\n intro m z hm hz\n have hzm : z (ι ⟨m, hm⟩) = 0 := hz ⟨m, hm⟩ (le_refl m)\n have hk : (kf z : ℕ) ≤ m := by\n by_cases h : (kf z : ℕ) < m\n · omega\n · have hz0 : z (ι (kf z)) = 0 := hz (kf z) (by omega)\n have hMz0 : M z = 0 := by rw [← hk1 z, hz0]\n have := hk2 z ⟨m, hm⟩ (by rw [hzm, hMz0])\n simpa using this\n intro i hi\n have hne' : ¬ (Fin.castLE htn i = ι (kf z)) := by\n intro h\n have h2 := congrArg Fin.val h\n simp [hιdef] at h2\n omega\n have hzi : z (Fin.castLE htn i) = 0 := hz i (by omega)\n simp [hGdef, EuclideanSpace.single_apply, hne', hzi]\n have hW : ∀ s : ℕ, s + 1 ≤ t → x (s+1) ∈ Wsub n t htn s := by\n intro s\n induction s using Nat.strong_induction_on with\n | _ s IH =>\n intro hst\n have hx' : x (s+1) ∈ Submodule.span ℝ ((fun i => G (x i)) '' Set.Icc 1 s) := by\n have := hspan s\n rwa [hx0, sub_zero] at this\n have hsub : Submodule.span ℝ ((fun i => G (x i)) '' Set.Icc 1 s) ≤ Wsub n t htn s := by\n rw [Submodule.span_le]\n rintro w ⟨i, hi, rfl⟩\n obtain ⟨hi1, hi2⟩ := hi\n have hxi : x i ∈ Wsub n t htn (i-1) := by\n have := IH (i-1) (by omega) (by omega)\n rwa [show i - 1 + 1 = i by omega] at this\n have hGi : G (x i) ∈ Wsub n t htn (i-1+1) := hGW _ _ (by omega) hxi\n intro j hj\n exact hGi j (by omega)\n exact hsub hx'\n have hfnonneg : ∀ s : ℕ, 1 ≤ s → s ≤ t → 0 ≤ f (x s) := by\n intro s h1 h2\n have hmem := hW (s-1) (by omega)\n rw [show s - 1 + 1 = s by omega] at hmem\n have hz : x s (ι ⟨s-1, by omega⟩) = 0 := hmem ⟨s-1, by omega⟩ (le_refl _)\n have hM0 : 0 ≤ M (x s) := by\n have := hMle (x s) ⟨s-1, by omega⟩\n rw [hz] at this\n exact this\n have hn2 : 0 ≤ ‖x s‖^2 := sq_nonneg _\n simp only [hfdef]\n nlinarith\n have hmin : 0 ≤ ((Finset.Icc 1 t).image (fun s => f (x s))).min' hnonempty := by\n apply Finset.le_min'\n intro w hw\n simp only [Finset.mem_image, Finset.mem_Icc] at hw\n obtain ⟨s, ⟨hs1, hs2⟩, rfl⟩ := hw\n exact hfnonneg s hs1 hs2\n -- the witness point\n obtain ⟨y, hydef⟩ : ∃ y : EuclideanSpace ℝ (Fin n),\n y = ∑ i : Fin t, EuclideanSpace.single (ι i) (-c) := ⟨_, rfl⟩\n have hinj : Function.Injective ι := by\n intro a b hab\n have h : (a : ℕ) = (b : ℕ) := by\n have h2 := congrArg Fin.val hab\n simpa [hιdef] using h2\n exact Fin.ext h\n have hycoord : ∀ j : Fin t, y (ι j) = -c := by\n intro j\n rw [hydef]\n simp [EuclideanSpace.single_apply, Pi.single_apply, hinj.eq_iff]\n have hynorm : ‖y‖^2 = (t:ℝ) * c^2 := by\n have hterm : ∀ i : Fin t,\n ⟪(EuclideanSpace.single (ι i) (-c) : EuclideanSpace ℝ (Fin n)), y⟫ = c^2 := by\n intro i\n rw [EuclideanSpace.inner_single_left, hycoord i]\n first\n | (simp; ring)\n | simp\n | ring\n have h0 : ⟪y, y⟫ = (t:ℝ) * c^2 := by\n nth_rewrite 1 [hydef]\n rw [sum_inner]\n rw [Finset.sum_congr rfl (fun i _ => hterm i)]\n simp [mul_comm]\n rw [← real_inner_self_eq_norm_sq]\n exact h0\n have hyball : y ∈ Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R := by\n have ht0 : (0:ℝ) ≤ (t:ℝ) := Nat.cast_nonneg t\n have hsq : (Real.sqrt t)^2 = (t:ℝ) := Real.sq_sqrt ht0\n have hcs : (0:ℝ) ≤ c * Real.sqrt t := mul_nonneg hc (Real.sqrt_nonneg _)\n have heq : (t:ℝ)*c^2 = (c * Real.sqrt t)^2 := by rw [mul_pow, hsq]; ring\n have h1 : ‖y‖^2 ≤ R^2 := by\n rw [hynorm, heq]\n exact pow_le_pow_left₀ hcs hcR 2\n have h2 := Real.sqrt_le_sqrt h1\n rw [Real.sqrt_sq (norm_nonneg y), Real.sqrt_sq hR.le] at h2\n simpa [dist_zero_right] using h2\n have hMy : M y = -c := by\n apply le_antisymm\n · apply Finset.sup'_le\n intro i _\n simp [hycoord i]\n · have h := hMle y ⟨0, by omega⟩\n rwa [hycoord ⟨0, by omega⟩] at h\n have hfy : f y = -(γ * c) + (α/2) * ((t:ℝ) * c^2) := by\n have hfe : f y = γ * M y + (α/2) * ‖y‖^2 := by rw [hfdef]\n rw [hfe, hMy, hynorm]\n ring\n have hbdd : BddBelow (f '' Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R) := by\n refine ⟨-(γ*R), ?_⟩\n rintro w ⟨z, hz, rfl⟩\n have hzR : ‖z‖ ≤ R := by simpa [dist_eq_norm] using hz\n obtain ⟨i, hi⟩ := hkspec z\n have hab : |z (ι i)| ≤ ‖z‖ := abs_coord_le z _\n have := abs_le.1 hab\n have hMz : -R ≤ M z := by rw [← hi]; linarith [this.1]\n have hn2 : 0 ≤ ‖z‖^2 := sq_nonneg _\n have e1 : γ * (-R) ≤ γ * M z := mul_le_mul_of_nonneg_left hMz hγ\n have e2 : 0 ≤ (α/2) * ‖z‖^2 := mul_nonneg (by linarith) hn2\n have e3 : f z = γ * M z + (α/2) * ‖z‖^2 := by rw [hfdef]\n rw [e3]\n linarith\n have hinf : sInf (f '' Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R) ≤ f y :=\n csInf_le hbdd ⟨y, hyball, rfl⟩\n have : f y ≤ -B := by rw [hfy]; linarith\n linarith\n\nend Aux\n\ntheorem ch9_theorem_9_2 (n t : ℕ) (L R α : ℝ)\n (ht : 1 ≤ t) (htn : t ≤ n) (hL : 0 < L) (hR : 0 < R) (hα : 0 < α) :\n (∃ f : EuclideanSpace ℝ (Fin n) → ℝ,\n ConvexOn ℝ Set.univ f ∧\n LipschitzOnWith L.toNNReal f (Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R) ∧\n ∃ G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n),\n (∀ z, G z ∈ SubderivAt f z) ∧\n ∀ x : ℕ → EuclideanSpace ℝ (Fin n), OracleProcedure f G x →\n ((Finset.Icc 1 t).image (fun s => f (x s))).min'\n (by simpa [Finset.image_nonempty, Finset.nonempty_Icc] using ht)\n - sInf (f '' Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) R)\n ≥ R * L / (2 * (1 + Real.sqrt t))) ∧\n (∃ f : EuclideanSpace ℝ (Fin n) → ℝ,\n StrongConvexOn Set.univ α f ∧\n LipschitzOnWith L.toNNReal f\n (Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) (L / (2 * α))) ∧\n ∃ G : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n),\n (∀ z, G z ∈ SubderivAt f z) ∧\n ∀ x : ℕ → EuclideanSpace ℝ (Fin n), OracleProcedure f G x →\n ((Finset.Icc 1 t).image (fun s => f (x s))).min'\n (by simpa [Finset.image_nonempty, Finset.nonempty_Icc] using ht)\n - sInf (f '' Metric.closedBall (0 : EuclideanSpace ℝ (Fin n)) (L / (2 * α)))\n ≥ L ^ 2 / (8 * α * t)) := by\n have ht1 : (1:ℝ) ≤ (t:ℝ) := by exact_mod_cast ht\n have ht0 : (0:ℝ) < (t:ℝ) := by linarith\n have hs0 : 0 < Real.sqrt t := Real.sqrt_pos.2 ht0\n have hssq : (Real.sqrt t)^2 = (t:ℝ) := Real.sq_sqrt (le_of_lt ht0)\n have hs1 : 1 ≤ Real.sqrt t := by nlinarith [Real.sqrt_nonneg (t:ℝ)]\n have hsne : Real.sqrt t ≠ 0 := ne_of_gt hs0\n have hst : Real.sqrt t ≤ (t:ℝ) := by nlinarith\n constructor\n · obtain ⟨f, hconv, -, hlip, G, hG, hmain⟩ :=\n key n t ht htn 0 L R L (R * L / (2 * (1 + Real.sqrt t))) (R / Real.sqrt t)\n (le_refl 0) (le_of_lt hL) hR (by linarith) (by positivity)\n (by rw [div_mul_cancel₀ _ hsne]) (by\n rw [← sub_nonneg]\n have hexp : L * (R / Real.sqrt t) - (0:ℝ)/2 * (R / Real.sqrt t)^2 * (t:ℝ)\n - R * L / (2 * (1 + Real.sqrt t))\n = R * L * (2 + Real.sqrt t) / (2 * Real.sqrt t * (1 + Real.sqrt t)) := by\n field_simp\n ring\n rw [hexp]\n positivity)\n exact ⟨f, hconv, hlip, G, hG, fun x hx => hmain x hx _⟩\n · have hα0 : α ≠ 0 := ne_of_gt hα\n obtain ⟨f, -, hconv, hlip, G, hG, hmain⟩ :=\n key n t ht htn α (L/2) (L/(2*α)) L (L^2 / (8 * α * t)) (L/(2*α*t))\n (le_of_lt hα) (by linarith) (by positivity)\n (by\n have h : α * (L / (2*α)) = L/2 := by field_simp\n rw [h]; linarith)\n (by positivity)\n (by\n rw [← sub_nonneg]\n have hexp : L/(2*α) - L/(2*α*(t:ℝ)) * Real.sqrt t\n = L * ((t:ℝ) - Real.sqrt t) / (2*α*(t:ℝ)) := by\n first\n | (field_simp; ring)\n | field_simp\n rw [hexp]\n apply div_nonneg _ (by positivity)\n have : (0:ℝ) ≤ (t:ℝ) - Real.sqrt t := by linarith\n exact mul_nonneg hL.le this)\n (by\n apply le_of_eq\n first\n | (field_simp; ring)\n | field_simp)\n exact ⟨f, hconv, hlip, G, hG, fun x hx => hmain x hx _⟩\n\nend GraduateLevel\n"} +{"id": "ch3_theorem_3_3", "source": "Graduate-level", "targets": [{"label": "ch3_theorem_3_3", "decls": ["ch3_theorem_3_3"], "statement": "Assume \\(f\\colon\\Omega\\to\\mathbb{R}\\) is \\emph{\\(\\alpha\\)-strongly convex} and \\emph{\\(L\\)-Lipschitz}. Let \\(x^{*}\\) be an optimizer of \\(f\\), and let \\(x_{s}\\) be the updated point at step \\(s\\) using projected gradient descent. Let the max number of iterations be \\(t\\) with an adaptive step size \\(\\eta_{s} = \\frac{2}{\\alpha(s+1)}\\), then \\[ f\\left(\\sum_{s=1}^{t}\\frac{2s}{t(t+1)}x_{s}\\right) - f(x^{*})\\leqslant\\frac{2 L^{2}}{\\alpha(t+1)} \\]", "topic_domain": "Optimization", "topic_subtopic": "Algorithms & Convergence"}], "nl_proof": "Recall the two steps update rule of projected gradient descent\n\\begin{align*}\ny_{s+1} &= x_{s} - \\eta_{s}\\nabla f(x_{s})\\\\\nx_{s+1} &= \\Pi_{\\Omega}(y_{s+1})\n\\end{align*}\nFirst, the proof begins by exploring an upper bound of difference between function values \\(f(x_{s})\\) and \\(f(x^{*})\\).\n\\begin{align*}\nf(x_{s}) - f(x^{*}) &\\leqslant \\nabla f(x_{s})^{\\top}(x_{s}-x^{*}) - \\frac{\\alpha}{2}\\|x_{s}-x^{*}\\|^{2}\\\\\n\t\t\t &=\\frac{1}{\\eta_{s}} (x_{s} - y_{s+1})^{\\top}(x_{s}-x^{*}) - \\frac{\\alpha}{2}\\|x_{s}-x^{*}\\|^{2} \\tag{by update rule}\\\\\n\t\t\t &=\\frac{1}{2\\eta_{s}} (\\|x_{s} - x^{*}\\|^{2} + \\|x_{s} - y_{s+1}\\|^{2} - \\|y_{s+1}-x^{*}\\|^{2}) - \\frac{\\alpha}{2}\\|x_{s}-x^{*}\\|^{2} \\tag{by \"Fundamental Theorem of Optimization\"}\\\\\n\t\t\t &=\\frac{1}{2\\eta_{s}} (\\|x_{s} - x^{*}\\|^{2} - \\|y_{s+1}-x^{*}\\|^{2}) +\\frac{\\eta_{s}}{2}\\|\\nabla f(x_{s})\\|^{2} - \\frac{\\alpha}{2}\\|x_{s}-x^{*}\\|^{2} \\tag{by update rule}\\\\\n\t\t\t &\\leqslant \\frac{1}{2\\eta_{s}} (\\|x_{s} - x^{*}\\|^{2} - \\|x_{s+1}-x^{*}\\|^{2}) +\\frac{\\eta_{s}}{2}\\|\\nabla f(x_{s})\\|^{2} - \\frac{\\alpha}{2}\\|x_{s}-x^{*}\\|^{2} \\tag{by Pythagorean lemma}\\\\\n\t\t\t &\\leqslant (\\frac{1}{2\\eta_{s}} - \\frac{\\alpha}{2})\\|x_{s}-x^{*}\\|^{2} -\\frac{1}{2\\eta_{s}}\\|x_{s+1}-x^{*}\\|^{2} + \\frac{\\eta_{s}L^{2}}{2} \\tag{by Lipschitzness}\n\\end{align*}\nBy multiplying \\(s\\) on both sides and substituting the step size \\(\\eta_{s}\\) by \\(\\frac{2}{\\alpha(s+1)}\\), we get\n\\[\ns(f(x_{s}) - f(x^{*})) \\leqslant \\frac{L^{2}}{\\alpha} + \\frac{\\alpha}{4}(s(s-1)\\|x_{s}-x^{*}\\|^{2} - s(s+1)\\|x_{s+1} - x^{*}\\|^{2})\n\\]\nFinally, we can find the upper bound of the function value obtained using \\(t\\) steps projected gradient descent\n\\begin{align*}\nf\\left(\\sum_{s=1}^{t}\\frac{2s}{t(t+1)}x_{s}\\right)\n&\\leqslant \\sum_{s=1}^{t}\\frac{2s}{t(t+1)}f(x_{s})\n\\tag{by Jensen's inequality}\\\\\n&\\leqslant \\frac{2}{t(t+1)}\\sum_{s=1}^{t}\\left(sf(x^{*}) + \\frac{L^{2}}{\\alpha}\n+ \\frac{\\alpha}{4}(s(s-1)\\|x_{s}-x^{*}\\|^{2} - s(s+1)\\|x_{s+1} - x^{*}\\|^{2}) \\right)\\\\\n&= \\frac{2}{t(t+1)}\\sum_{s=1}^{t}sf(x^{*}) + \\frac{2L^{2}}{\\alpha(t+1)} - \\frac{\\alpha}{2}\\|x_{t+1} - x^{*}\\|^{2} \\tag{by telescoping sum}\\\\\n&\\leqslant f(x^{*}) + \\frac{2L^{2}}{\\alpha(t+1)}\n\\end{align*}\nThis concludes that solving an optimization problem with a strongly convex objective function with projected gradient descent has a convergence rate of the order \\(\\frac{1}{t+1}\\), which is faster compared to the case purely with Lipschitzness.", "context": [{"id": "ch2:lemma:2_3", "name": "lemma 2.3", "statement": "\\[\n\\| \\Pi_{\\Omega}(y) - x \\|^2 \\leqslant \\| y - x \\|^2 - \\| y - \\Pi_{\\Omega}(y) \\|^2\n\\]"}, {"id": "ch3:proposition:3_4", "name": "Jensen's inequality", "statement": "Assume \\(f\\colon\\Omega\\to\\mathbb{R}\\) is a convex function and \\(x_{1}, x_{2}, \\ldots, x_{n}, \\sum_{i=1}^{n}\\gamma_{i}x_{i}/\\sum_{i=1}^{n}\\gamma_{i}\\in\\Omega\\) with weights \\(\\gamma_{i} > 0\\), then \\[ f\\left(\\frac{\\sum_{i=1}^{n}\\gamma_{i}x_{i}}{\\sum_{i=1}^{n}\\gamma_{i}}\\right) \\leqslant \\frac{\\sum_{i=1}^{n}\\gamma_{i}f(x_{i})}{\\sum_{i=1}^{n}\\gamma_{i}} \\]"}, {"id": "ch3:definition:3_1", "name": "Strong convexity", "statement": "A function \\(f\\colon\\Omega\\to\\mathbb{R}\\) is \\emph{\\(\\alpha\\)-strongly convex} if, for all \\(x,y\\in\\Omega\\), the following inequality holds for some \\(\\alpha>0\\): \\[ f(y) \\geqslant f(x) + g(x)^\\top(y-x) + \\frac{\\alpha}{2}\\left\\lVert x-y\\right\\rVert^2 \\]"}], "lean": "import Mathlib\n\nopen scoped RealInnerProductSpace\nopen Finset\n\nnamespace GraduateLevel\n\ntheorem ch3_theorem_3_3\n {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E]\n (Ω : Set E) (f : E → ℝ) (f' : E → E)\n (proj : E → E)\n (α : ℝ) (L : NNReal) (t : ℕ)\n (x : ℕ → E)\n (xopt : E)\n\n (hsc : StrongConvexOn Ω α f)\n\n (hLip : LipschitzOnWith L f Ω)\n\n (hgrad : ∀ s, 1 ≤ s → s ≤ t →\n (∀ y ∈ Ω, f y ≥ f (x s) + inner ℝ (f' (x s)) (y - x s)) ∧ ‖f' (x s)‖ ≤ (L : ℝ))\n\n (hα : 0 < α)\n\n (ht : 1 ≤ t)\n\n (hΩ : Convex ℝ Ω) (hΩc : IsClosed Ω)\n (hprojmem : ∀ y, proj y ∈ Ω)\n (hproj : ∀ y, ∀ z ∈ Ω, ‖proj y - z‖ ^ 2 ≤ ‖y - z‖ ^ 2 - ‖y - proj y‖ ^ 2)\n\n (hx1 : x 1 ∈ Ω)\n (hrec : ∀ s, 1 ≤ s → x (s + 1) = proj (x s - (2 / (α * (s + 1))) • f' (x s)))\n\n (hxopt_mem : xopt ∈ Ω)\n (hxopt_min : ∀ z ∈ Ω, f xopt ≤ f z) :\n f (∑ s ∈ Finset.Icc 1 t, (2 * (s : ℝ) / ((t : ℝ) * ((t : ℝ) + 1))) • x s) - f xopt\n ≤ 2 * (L : ℝ) ^ 2 / (α * ((t : ℝ) + 1)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen scoped RealInnerProductSpace\nopen Finset\n\nnamespace GraduateLevel\n\nprivate lemma strong_subgrad {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]\n {Ω : Set E} {f : E → ℝ} {α : ℝ} (hα : 0 ≤ α) (hsc : StrongConvexOn Ω α f)\n {p g : E} (hp : p ∈ Ω)\n (hsub : ∀ y ∈ Ω, f y ≥ f p + inner ℝ g (y - p)) :\n ∀ y ∈ Ω, f y ≥ f p + inner ℝ g (y - p) + (α/2) * ‖y - p‖^2 := by\n intro y hy\n obtain ⟨hconv, hs⟩ := hsc\n set c : ℝ := (α/2) * ‖y - p‖^2 with hc\n have hc0 : 0 ≤ c := by positivity\n set A : ℝ := f y - f p - inner ℝ g (y - p) with hA\n have main : ∀ a : ℝ, 0 < a → a ≤ 1 → (1 - a) * c ≤ A := by\n intro a ha ha1\n have hb0 : (0:ℝ) ≤ 1 - a := by linarith\n have hz : ((1-a) • p + a • y) ∈ Ω := hconv hp hy hb0 ha.le (by ring)\n have h1 := hs hp hy hb0 ha.le (by ring)\n have h2 := hsub _ hz\n have hzp : ((1-a) • p + a • y) - p = a • (y - p) := by module\n rw [hzp, real_inner_smul_right] at h2\n rw [norm_sub_rev p y] at h1\n simp only [smul_eq_mul] at h1\n have key : a * ((1-a) * c) ≤ a * A := by rw [hc, hA]; nlinarith\n exact le_of_mul_le_mul_left key ha\n have hAc : c ≤ A := by\n rcases eq_or_lt_of_le hc0 with h | h\n · have h1 := main 1 one_pos le_rfl\n simp at h1\n linarith\n · refine le_of_forall_pos_le_add ?_\n intro ε hε\n have hpos : 0 < min 1 (ε / c) := lt_min one_pos (by positivity)\n have hle : min 1 (ε/c) ≤ 1 := min_le_left _ _\n have h1 := main _ hpos hle\n have h2 : min 1 (ε/c) * c ≤ ε := by\n rcases min_cases 1 (ε/c) with ⟨he, hle2⟩ | ⟨he, hle2⟩\n · rw [he]; rw [le_div_iff₀ h] at hle2; linarith\n · rw [he, div_mul_cancel₀ _ h.ne']\n nlinarith\n rw [hA] at hAc\n linarith\n\nprivate lemma alg_step (α S P Q I N Lr F η : ℝ)\n (hα : 0 < α) (hS : 1 ≤ S) (hN : 0 ≤ N) (hNL : N ≤ Lr)\n (hη : 0 < η) (hηk : η * (α * (S + 1)) = 2)\n (h1 : Q ≤ P - 2 * (η * I) + η ^ 2 * N)\n (h2 : F ≤ I - (α / 2) * P) :\n S * F ≤ Lr / α + ((α/4) * (S * (S - 1)) * P - (α/4) * ((S+1) * ((S+1) - 1)) * Q) := by\n have hS0 : (0:ℝ) < S := by linarith\n have hS1 : (0:ℝ) < S + 1 := by linarith\n have hm0 : (0:ℝ) ≤ S * α * (S+1) / 4 := by positivity\n have h3 := mul_le_mul_of_nonneg_left h1 hm0\n have heq : (S * α * (S+1) / 4) * (P - 2*(η*I) + η^2*N) - (S * α * (S+1) / 4) * Q\n = (S * α * (S+1) / 4)*(P-Q) + S*η*N/2 - S*I := by\n linear_combination (-(S/2)*I + (S/4)*η*N) * hηk\n have e1 : S * I ≤ (S * α * (S+1) / 4)*(P-Q) + S*η*N/2 := by linarith\n have e2 : S*η*N/2 ≤ Lr/α := by\n refine le_of_mul_le_mul_right ?_ (mul_pos hα hS1)\n have hprod : (S*η*N/2) * (α*(S+1)) = S*N := by linear_combination (S*N/2) * hηk\n have hprod2 : (Lr/α) * (α*(S+1)) = Lr*(S+1) := by field_simp\n rw [hprod, hprod2]\n nlinarith\n have h4 : S * F ≤ S * (I - (α/2)*P) := mul_le_mul_of_nonneg_left h2 hS0.le\n nlinarith [e1, e2, h4]\n\ntheorem ch3_theorem_3_3\n {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E]\n (Ω : Set E) (f : E → ℝ) (f' : E → E)\n (proj : E → E)\n (α : ℝ) (L : NNReal) (t : ℕ)\n (x : ℕ → E)\n (xopt : E)\n\n (hsc : StrongConvexOn Ω α f)\n\n (hLip : LipschitzOnWith L f Ω)\n\n (hgrad : ∀ s, 1 ≤ s → s ≤ t →\n (∀ y ∈ Ω, f y ≥ f (x s) + inner ℝ (f' (x s)) (y - x s)) ∧ ‖f' (x s)‖ ≤ (L : ℝ))\n\n (hα : 0 < α)\n\n (ht : 1 ≤ t)\n\n (hΩ : Convex ℝ Ω) (hΩc : IsClosed Ω)\n (hprojmem : ∀ y, proj y ∈ Ω)\n (hproj : ∀ y, ∀ z ∈ Ω, ‖proj y - z‖ ^ 2 ≤ ‖y - z‖ ^ 2 - ‖y - proj y‖ ^ 2)\n\n (hx1 : x 1 ∈ Ω)\n (hrec : ∀ s, 1 ≤ s → x (s + 1) = proj (x s - (2 / (α * (s + 1))) • f' (x s)))\n\n (hxopt_mem : xopt ∈ Ω)\n (hxopt_min : ∀ z ∈ Ω, f xopt ≤ f z) :\n f (∑ s ∈ Finset.Icc 1 t, (2 * (s : ℝ) / ((t : ℝ) * ((t : ℝ) + 1))) • x s) - f xopt\n ≤ 2 * (L : ℝ) ^ 2 / (α * ((t : ℝ) + 1)) := by\n have hα0 : (0:ℝ) ≤ α := hα.le\n have hmem : ∀ s, 1 ≤ s → x s ∈ Ω := by\n intro s hs\n induction s with\n | zero => omega\n | succ n ih =>\n rcases Nat.lt_or_ge n 1 with h | h\n · have hn : n = 0 := by omega\n subst hn; exact hx1\n · rw [hrec n h]; exact hprojmem _\n have hconv : ConvexOn ℝ Ω f := UniformConvexOn.convexOn hsc (by intro r; positivity)\n -- key one-step inequality\n have key : ∀ s, 1 ≤ s → s ≤ t →\n (s:ℝ) * (f (x s) - f xopt) ≤ (L:ℝ)^2/α +\n ((α/4) * ((s:ℝ) * ((s:ℝ) - 1)) * ‖x s - xopt‖^2\n - (α/4) * (((s:ℝ)+1) * (((s:ℝ)+1) - 1)) * ‖x (s+1) - xopt‖^2) := by\n intro s hs1 hst\n obtain ⟨hsub, hgL⟩ := hgrad s hs1 hst\n have hSnn : (0:ℝ) ≤ (s:ℝ) := Nat.cast_nonneg s\n have hS1 : (1:ℝ) ≤ (s:ℝ) := by exact_mod_cast hs1\n have hk : (0:ℝ) < α * ((s:ℝ) + 1) := by nlinarith\n have hηpos : (0:ℝ) < 2 / (α * ((s:ℝ) + 1)) := div_pos (by norm_num) hk\n have hηk : (2 / (α * ((s:ℝ) + 1))) * (α * ((s:ℝ) + 1)) = 2 :=\n div_mul_cancel₀ _ hk.ne'\n set y : E := x s - (2 / (α * ((s:ℝ) + 1))) • f' (x s) with hydef\n have hxs : x (s+1) = proj y := by rw [hydef]; exact hrec s hs1\n have hpy := hproj y xopt hxopt_mem\n have hd : ‖x (s+1) - xopt‖^2 ≤ ‖y - xopt‖^2 := by\n rw [hxs]; nlinarith [sq_nonneg ‖y - proj y‖]\n have hyx : y - xopt = (x s - xopt) - (2 / (α * ((s:ℝ) + 1))) • f' (x s) := by\n rw [hydef]; abel\n have hexp : ‖y - xopt‖^2 = ‖x s - xopt‖^2\n - 2 * ((2 / (α * ((s:ℝ) + 1))) * inner ℝ (f' (x s)) (x s - xopt))\n + (2 / (α * ((s:ℝ) + 1)))^2 * ‖f' (x s)‖^2 := by\n rw [hyx, norm_sub_sq_real, real_inner_smul_right, real_inner_comm, norm_smul,\n mul_pow, Real.norm_eq_abs, sq_abs]\n have hss := strong_subgrad hα0 hsc (hmem s hs1) hsub xopt hxopt_mem\n have hinner : inner ℝ (f' (x s)) (xopt - x s) = - inner ℝ (f' (x s)) (x s - xopt) := by\n rw [← inner_neg_right]; congr 1; abel\n rw [hinner, norm_sub_rev xopt (x s)] at hss\n have hgL2 : ‖f' (x s)‖^2 ≤ (L:ℝ)^2 := by\n have := norm_nonneg (f' (x s)); nlinarith\n refine alg_step α (s:ℝ) (‖x s - xopt‖^2) (‖x (s+1) - xopt‖^2)\n (inner ℝ (f' (x s)) (x s - xopt)) (‖f' (x s)‖^2) ((L:ℝ)^2)\n (f (x s) - f xopt) (2 / (α * ((s:ℝ) + 1))) hα hS1 (sq_nonneg _) hgL2 hηpos hηk ?_ ?_\n · linarith [hd, hexp.ge, hexp.le]\n · linarith\n -- telescoping sum\n have sum_key : ∀ n, n ≤ t → ∑ s ∈ Icc 1 n, (s:ℝ)*(f (x s) - f xopt)\n ≤ (n:ℝ) * ((L:ℝ)^2/α)\n - (α/4) * (((n:ℝ)+1) * (((n:ℝ)+1) - 1)) * ‖x (n+1) - xopt‖^2 := by\n intro n hn\n induction n with\n | zero => norm_num\n | succ m ih =>\n have hm := ih (by omega)\n rw [Finset.sum_Icc_succ_top (by omega)]\n have hk := key (m+1) (by omega) hn\n push_cast at hk hm ⊢\n linarith\n have hsum_id : ∀ n : ℕ, ∑ s ∈ Icc 1 n, (s:ℝ) = (n:ℝ)*((n:ℝ)+1)/2 := by\n intro n\n induction n with\n | zero => norm_num\n | succ m ih =>\n rw [Finset.sum_Icc_succ_top (by omega), ih]\n push_cast; ring\n have htpos : (0:ℝ) < (t:ℝ) := by exact_mod_cast ht\n have hden : (0:ℝ) < (t:ℝ)*((t:ℝ)+1) := by nlinarith\n have hw : ∑ s ∈ Icc 1 t, (2*(s:ℝ)/((t:ℝ)*((t:ℝ)+1))) = 1 := by\n have : ∑ s ∈ Icc 1 t, (2*(s:ℝ)/((t:ℝ)*((t:ℝ)+1)))\n = (2/((t:ℝ)*((t:ℝ)+1))) * ∑ s ∈ Icc 1 t, (s:ℝ) := by\n rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intros; ring\n rw [this, hsum_id]\n field_simp\n have hjen := hconv.map_sum_le (t := Icc 1 t)\n (w := fun s => 2*(s:ℝ)/((t:ℝ)*((t:ℝ)+1))) (p := x)\n (by intro i _; positivity) hw (by intro i hi; exact hmem i (Finset.mem_Icc.mp hi).1)\n have hbound : ∑ s ∈ Icc 1 t, (s:ℝ)*(f (x s) - f xopt) ≤ (t:ℝ) * ((L:ℝ)^2/α) := by\n have h8 := sum_key t le_rfl\n have hnn : 0 ≤ α/4 * (((t:ℝ)+1) * (((t:ℝ)+1) - 1)) * ‖x (t+1) - xopt‖^2 := by\n have he : ((t:ℝ)+1) * (((t:ℝ)+1) - 1) = ((t:ℝ)+1) * (t:ℝ) := by ring\n rw [he]\n have : (0:ℝ) ≤ (t:ℝ) := Nat.cast_nonneg t\n positivity\n linarith\n have hstep : ∑ i ∈ Icc 1 t, (2*(i:ℝ)/((t:ℝ)*((t:ℝ)+1))) • f (x i) - f xopt\n = (2/((t:ℝ)*((t:ℝ)+1))) * ∑ i ∈ Icc 1 t, (i:ℝ)*(f (x i) - f xopt) := by\n rw [Finset.mul_sum]\n have h5 : ∑ i ∈ Icc 1 t, (2/((t:ℝ)*((t:ℝ)+1))) * ((i:ℝ)*(f (x i) - f xopt))\n = ∑ i ∈ Icc 1 t, ((2*(i:ℝ)/((t:ℝ)*((t:ℝ)+1))) * f (x i)\n - (2*(i:ℝ)/((t:ℝ)*((t:ℝ)+1))) * f xopt) := by\n apply Finset.sum_congr rfl; intros; ring\n rw [h5, Finset.sum_sub_distrib, ← Finset.sum_mul, hw, one_mul]\n simp [smul_eq_mul]\n have hfinal : (2/((t:ℝ)*((t:ℝ)+1))) * ∑ i ∈ Icc 1 t, (i:ℝ)*(f (x i) - f xopt)\n ≤ 2 * (L:ℝ)^2 / (α * ((t:ℝ)+1)) := by\n have hc : (0:ℝ) ≤ 2/((t:ℝ)*((t:ℝ)+1)) := by positivity\n have h6 := mul_le_mul_of_nonneg_left hbound hc\n have h7 : (2/((t:ℝ)*((t:ℝ)+1))) * ((t:ℝ) * ((L:ℝ)^2/α)) = 2 * (L:ℝ)^2 / (α * ((t:ℝ)+1)) := by\n field_simp\n linarith [h6, h7.le, h7.ge]\n linarith [hjen, hstep.le, hstep.ge, hfinal]\n\nend GraduateLevel\n"} +{"id": "ch41_theorem_41_2", "source": "Graduate-level", "targets": [{"label": "ch41_theorem_41_2", "decls": ["ch41_theorem_41_2"], "statement": "Let \\(x_1, \\cdots, x_n\\) be independent random variables (Lecture 41, opening paragraph). [Editorial, not in the source: each \\(f_i\\) is a function of \\(x_i\\), so that \\(Z = \\sup_{f\\in\\mathcal F}\\sum_{i=1}^n f_i(x_i)\\).] Let \\(\\mathcal{F}\\) be a finite set of functions \\(|{\\mathcal{F}}| <\\infty .\\forall f=(f_{1},\\cdots,f_{n})\\in{\\mathcal{F}},0\\leq f_{i}\\leq 1,Z=\\) \\(\\textstyle\\operatorname*{sup}_{f}\\sum_{i=1}^{n}f_{i}\\) , and define h as \\(h(u)=(1+u)\\log(1+u)-u\\) where \\(u \\geq 0\\) Then \\(\\mathbb{P}(Z\\geq\\mathbb{E}Z+x)\\leq e^{-\\mathbb{E}Z\\cdot h(x/\\mathbb{E}Z)}\\)", "topic_domain": "Probability & Concentration", "topic_subtopic": "Functional & Supremum Concentration"}], "nl_proof": "Let\n\\[Z\\quad=\\quad\\operatorname*{sup}_{f\\in{\\mathcal{F}}}\\sum_{i=1}^{n}f_{i}\\ {\\stackrel{\\mathrm{d e f .}}{=}}\\ \\sum_{i=1}^{n}f_{i}^{\\circ}\\]\n\\[Z^{i}\\quad=\\quad\\operatorname*{sup}_{f\\in{\\mathcal{F}}}\\sum_{j\\neq i}f_{j}.\\]\nIt follows that \\(0\\leq Z-Z^{i}\\leq f_{i}^{\\circ}\\leq 1\\) . Since \\(\\phi=e^{x}-x-1\\) is a convex function of \\(x,\\)\n\\[\\phi(-\\lambda(Z-Z^{i}))=\\phi(-\\lambda\\cdot(Z-Z^{i})+0\\cdot(1-(Z-Z^{i})))\\leq(Z-Z^{i})\\phi(-\\lambda)\\]\nand\n\\[\\begin{array}{ r c l }{\\mathbb{E}\\left(\\lambda Z e^{\\lambda Z}\\right)-\\mathbb{E}e^{\\lambda Z}\\log\\mathbb{E}e^{\\lambda Z}}&{\\leq}&{\\mathbb{E}\\left(e^{\\lambda Z}\\displaystyle\\sum_{i=1}^{n}\\phi\\left(-\\lambda(Z-Z^{i})\\right)\\right)}\\\\ &{\\leq}&{\\mathbb{E}\\left(e^{\\lambda Z}\\phi(-\\lambda)\\displaystyle\\sum_{i}\\left(Z-Z^{i}\\right)\\right)}\\\\ &{\\leq}&{\\phi(-\\lambda)\\mathbb{E}\\left(e^{\\lambda Z}\\cdot\\displaystyle\\sum_{i}f_{i}^{\\circ}\\right)}\\\\ &{=}&{\\phi(-\\lambda)\\mathbb{E}\\left(Z\\cdot e^{\\lambda Z}\\right).}\\end{array}\\]\nSet \\(\\tilde{Z}=Z-\\mathbb{E}Z\\ (\\mathrm{i . e .}\\) , center Z),and we get\n\\[\\begin{array}{ r l r }{\\mathbb{E}\\left(\\lambda\\tilde{Z}e^{\\lambda\\tilde{Z}}\\right)-\\mathbb{E}e^{\\lambda\\tilde{Z}}\\log\\mathbb{E}e^{\\lambda\\tilde{Z}}}&{\\leq}&{\\phi(-\\lambda)\\mathbb{E}\\left(\\tilde{Z}\\cdot e^{\\lambda\\tilde{Z}}\\right)\\leq\\phi(-\\lambda)\\mathbb{E}\\left(\\left(\\tilde{Z}+\\mathbb{E}Z\\right)\\cdot e^{\\lambda\\tilde{Z}}\\right)}\\\\ {(\\lambda-\\phi(-\\lambda))\\mathbb{E}\\left(\\tilde{Z}e^{\\lambda\\tilde{Z}}\\right)-\\mathbb{E}e^{\\lambda\\tilde{Z}}\\log\\mathbb{E}e^{\\lambda\\tilde{Z}}}&{\\leq}&{\\phi(-\\lambda)\\cdot\\mathbb{E}Z\\cdot\\mathbb{E}e^{\\lambda\\tilde{Z}}.}\\end{array}\\]\nLet \\(v=\\mathbb{E}Z,F(\\lambda)=\\mathbb{E}e^{\\lambda\\tilde{Z}}\\) , 亚 = logF,and we get\n\\[\\begin{array}{ r c l }{{(\\lambda-\\phi(-\\lambda)){\\displaystyle\\frac{F_{\\lambda}^{\\prime}(\\lambda)}{F(\\lambda)}}-\\log F(\\lambda)}}&{{\\le}}&{{v\\phi(-\\lambda)}}\\\\ {{(\\lambda-\\phi(-\\lambda)){(\\log F(\\lambda))}_{\\lambda}^{\\prime}-\\log F(\\lambda)}}&{{\\le}}&{{v\\phi(-\\lambda).}}\\end{array}\\tag{41.1}\\]\nSolving the differential equation\n\\[(\\lambda-\\phi(-\\lambda))\\left(\\underbrace{\\log F(\\lambda)}_{\\Psi_{0}}\\right)_{\\lambda}^{\\prime}-\\underbrace{\\log F(\\lambda)}_{\\Psi_{0}}=v\\phi(-\\lambda),\\tag{41.2}\\]\nyields \\(\\Psi_{0}=v\\cdot\\phi(\\lambda)\\) . We will proceed to show that 亚 satisfying 41.1 has the property \\(\\Psi\\leq\\Psi_{0}\\)\n\\[\\begin{array}{ r l r }{\\mathrm{Substract~41.2~from~41.1,~and~let~\\Psi\\Psi_1=\\Psi-\\Psi_0~}}&{}&\\\\ {(1-e^{-\\lambda})\\Psi_{1}^{\\prime}-\\Psi_{1}}&{\\le}&{0}\\end{array}\\]\n\\[\\begin{array}{ r c l }{\\displaystyle\\big(e^{\\lambda}-1\\big)\\big(1-e^{-\\lambda}\\big)\\frac{1}{e^{\\lambda}-1}=1-e^{-\\lambda}\\mathrm{,a n d}\\big(e^{\\lambda}-1\\big)\\big(1-e^{-\\lambda}\\big)\\frac{e^{\\lambda}}{(e^{\\lambda}-1)^{2}}=1}&&\\\\ {\\displaystyle\\big(e^{\\lambda}-1\\big)\\big(1-e^{-\\lambda}\\big)\\underbrace{\\Bigg(\\frac{1}{e^{\\lambda}-1}\\Psi_{1}^{\\prime}-\\frac{e^{\\lambda}}{\\big(e^{\\lambda}-1\\big)^{2}}\\Psi_{1}\\Bigg)}_{\\big(\\frac{\\Psi_{1}}{e^{\\lambda}-1}\\big)_{\\lambda}^{\\prime}}}&{\\le}&{0}\\end{array}\\]\n\\[{\\frac{\\Psi_{1}(\\lambda)}{e^{\\lambda}-1}}~\\leq~\\operatorname*{lim}_{\\lambda\\to 0}{\\frac{\\Psi_{1}(\\lambda)}{e^{\\lambda}-1}}=0 .\\]\nIt follows that \\(\\Psi\\leq v\\phi(\\lambda)\\) ,and \\(F=\\mathbb{E}e^{\\lambda Z}\\leq e^{v\\phi(\\lambda)}\\) . By Chebychev's inequality, \\(\\mathbb{P}\\left(Z\\geq\\mathbb{E}Z+t\\right)\\leq e^{-\\lambda t+v\\phi\\left(\\lambda\\right)}\\) Minimizing over all \\(\\lambda > 0\\) ,we get \\(\\mathbb{P}\\left(Z\\geq\\mathbb{E}Z+t\\right)\\leq e^{-v\\cdot h\\left(t/v\\right)}\\) where \\(h(x)=(1+x)\\cdot\\log(1+x)-x.\\)", "context": [{"id": "ch41_theorem_41_2:fix:1", "name": "Tensorization of entropy lemma (recalled, Lecture 41 opening paragraph)", "statement": "Recall the tensorization of entropy lemma we proved previously. Let \\(x_1, \\cdots, x_n\\) be independent random variables, \\(x'_1, \\cdots, x'_n\\) be their independent copies, \\(Z = Z(x_1, \\cdots, x_n)\\), \\(Z^i = Z(x_1, \\cdots, x_{i-1}, x'_i, x_{i+1}, \\cdots, x_n)\\), and \\(\\phi(x) = e^x - x - 1\\). We have \\(\\mathbb{E}\\lambda Z e^{\\lambda Z} - \\mathbb{E}e^{\\lambda Z}\\log\\mathbb{E}e^{\\lambda Z} \\le \\mathbb{E}e^{\\lambda Z}\\sum_{i=1}^n \\phi(-\\lambda(Z - Z^i))\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def bennettH (u : ℝ) : ℝ := (1 + u) * Real.log (1 + u) - u\n\ntheorem ch41_theorem_41_2\n {n : ℕ}\n {α : Fin n → Type*} [∀ i, MeasurableSpace (α i)]\n (μ : ∀ i, Measure (α i)) [∀ i, IsProbabilityMeasure (μ i)]\n (F : Finset (∀ i, α i → ℝ)) (hF : F.Nonempty)\n (hmeas : ∀ f ∈ F, ∀ i, Measurable (f i))\n (hbound : ∀ f ∈ F, ∀ i (a : α i), 0 ≤ f i a ∧ f i a ≤ 1)\n (Z : (∀ i, α i) → ℝ)\n (hZ : ∀ ω, Z ω = F.sup' hF (fun f => ∑ i : Fin n, f i (ω i)))\n (hZint : Integrable Z (Measure.pi μ))\n (hEZ : 0 < ∫ ω, Z ω ∂(Measure.pi μ))\n {x : ℝ} (hx : 0 ≤ x) :\n ((Measure.pi μ) {ω | Z ω ≥ (∫ ω, Z ω ∂(Measure.pi μ)) + x}).toReal\n ≤ Real.exp (-(∫ ω, Z ω ∂(Measure.pi μ)) *\n bennettH (x / (∫ ω, Z ω ∂(Measure.pi μ)))) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real Filter\n\nnamespace GraduateLevel\n\nprivate noncomputable def kl (a b : ℝ) : ℝ := a * Real.log (a / b) - a + b\n\nprivate noncomputable def entropy {Ω : Type*} [MeasurableSpace Ω]\n (μ : Measure Ω) (f : Ω → ℝ) : ℝ :=\n (∫ x, f x * Real.log (f x) ∂μ) -\n (∫ x, f x ∂μ) * Real.log (∫ x, f x ∂μ)\n\nprivate lemma integrable_of_measurable_bounded\n {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsFiniteMeasure μ]\n {f : Ω → ℝ} (hf : Measurable f) {C : ℝ} (hC : ∀ x, |f x| ≤ C) :\n Integrable f μ := by\n refine (integrable_const C).mono hf.aestronglyMeasurable ?_\n filter_upwards [] with x\n simpa only [Real.norm_eq_abs, norm_eq_abs] using (hC x).trans (le_abs_self C)\n\nprivate lemma kl_nonneg {a b : ℝ} (ha : 0 < a) (hb : 0 < b) : 0 ≤ kl a b := by\n have hlog := Real.log_le_sub_one_of_pos (div_pos hb ha)\n rw [Real.log_div hb.ne' ha.ne'] at hlog\n have hmul := mul_le_mul_of_nonneg_left hlog ha.le\n have hright : a * (b / a - 1) = b - a := by\n field_simp\n dsimp [kl]\n rw [Real.log_div ha.ne' hb.ne']\n rw [hright] at hmul\n calc\n 0 ≤ -(a * (Real.log b - Real.log a)) + (b - a) := by\n simpa [sub_eq_add_neg, add_comm] using sub_nonneg.mpr hmul\n _ = a * (Real.log a - Real.log b) - a + b := by ring\n\nprivate lemma kl_fenchel (a b s : ℝ) (ha : 0 < a) (hb : 0 < b) :\n s * a - (Real.exp s - 1) * b ≤ kl a b := by\n have h := kl_nonneg (a := a) (b := b * Real.exp s)\n ha (mul_pos hb (Real.exp_pos s))\n rw [kl, Real.log_div ha.ne' (mul_ne_zero hb.ne' (Real.exp_ne_zero s)),\n Real.log_mul hb.ne' (Real.exp_ne_zero s), Real.log_exp] at h\n dsimp [kl]\n rw [Real.log_div ha.ne' hb.ne']\n linarith\n\nprivate lemma integrable_mul_log_of_bounds\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {f : Ω → ℝ} {C : ℝ} (hf : Measurable f)\n (hf1 : ∀ x, 1 ≤ f x) (hfC : ∀ x, f x ≤ C) :\n Integrable (fun x => f x * Real.log (f x)) μ := by\n letI : Nonempty Ω := ProbabilityMeasure.nonempty ⟨μ, inferInstance⟩\n let x0 : Ω := Classical.choice (inferInstance : Nonempty Ω)\n have hC1 : 1 ≤ C := (hf1 x0).trans (hfC x0)\n apply integrable_of_measurable_bounded (hf.mul hf.log)\n intro x\n rw [abs_mul, abs_of_nonneg (zero_le_one.trans (hf1 x)),\n abs_of_nonneg (Real.log_nonneg (hf1 x))]\n exact mul_le_mul (hfC x) (Real.log_le_log (lt_of_lt_of_le zero_lt_one (hf1 x)) (hfC x))\n (Real.log_nonneg (hf1 x)) (zero_le_one.trans hC1)\n\nprivate lemma integrable_kl_of_bounds\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {f g : Ω → ℝ} {C : ℝ} (hf : Measurable f) (hg : Measurable g)\n (hf1 : ∀ x, 1 ≤ f x) (hg1 : ∀ x, 1 ≤ g x)\n (hfC : ∀ x, f x ≤ C) (hgC : ∀ x, g x ≤ C) :\n Integrable (fun x => kl (f x) (g x)) μ := by\n letI : Nonempty Ω := ProbabilityMeasure.nonempty ⟨μ, inferInstance⟩\n let x0 : Ω := Classical.choice (inferInstance : Nonempty Ω)\n have hC1 : 1 ≤ C := (hf1 x0).trans (hfC x0)\n have hC0 : 0 ≤ C := zero_le_one.trans hC1\n apply integrable_of_measurable_bounded ((hf.mul (hf.div hg).log).sub hf |>.add hg)\n intro x\n have hdivhi : f x / g x ≤ C := by\n apply (div_le_iff₀ (lt_of_lt_of_le zero_lt_one (hg1 x))).2\n nlinarith [hfC x, hg1 x]\n have habslog : |Real.log (f x / g x)| ≤ Real.log C := by\n rw [abs_le]\n constructor\n · rw [neg_le, ← Real.log_inv]\n apply Real.log_le_log (inv_pos.mpr (div_pos\n (lt_of_lt_of_le zero_lt_one (hf1 x))\n (lt_of_lt_of_le zero_lt_one (hg1 x))))\n rw [inv_div]\n apply (div_le_iff₀ (lt_of_lt_of_le zero_lt_one (hf1 x))).2\n nlinarith [hgC x, hf1 x]\n · exact Real.log_le_log (div_pos (lt_of_lt_of_le zero_lt_one (hf1 x))\n (lt_of_lt_of_le zero_lt_one (hg1 x))) hdivhi\n have hmul : |f x * Real.log (f x / g x)| ≤ C * Real.log C := by\n rw [abs_mul, abs_of_nonneg (zero_le_one.trans (hf1 x))]\n exact (mul_le_mul_of_nonneg_right (hfC x) (abs_nonneg _)).trans\n (mul_le_mul_of_nonneg_left habslog hC0)\n calc\n |kl (f x) (g x)| ≤ |f x * Real.log (f x / g x)| + |f x| + |g x| := by\n dsimp [kl]\n calc\n |f x * Real.log (f x / g x) - f x + g x|\n ≤ |f x * Real.log (f x / g x) - f x| + |g x| := abs_add_le _ _\n _ ≤ |f x * Real.log (f x / g x)| + |f x| + |g x| := by\n gcongr\n exact abs_sub _ _\n _ ≤ C * Real.log C + C + C := by\n exact add_le_add\n (add_le_add hmul (by simpa [abs_of_nonneg (zero_le_one.trans (hf1 x))] using hfC x))\n (by simpa [abs_of_nonneg (zero_le_one.trans (hg1 x))] using hgC x)\n\nprivate lemma integral_kl_contraction\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {f g : Ω → ℝ} {C : ℝ}\n (hf : Measurable f) (hg : Measurable g)\n (hf1 : ∀ x, 1 ≤ f x) (hg1 : ∀ x, 1 ≤ g x)\n (hfC : ∀ x, f x ≤ C) (hgC : ∀ x, g x ≤ C) :\n kl (∫ x, f x ∂μ) (∫ x, g x ∂μ) ≤ ∫ x, kl (f x) (g x) ∂μ := by\n letI : Nonempty Ω := ProbabilityMeasure.nonempty ⟨μ, inferInstance⟩\n let x0 : Ω := Classical.choice (inferInstance : Nonempty Ω)\n have hC0 : 0 ≤ C := by\n exact zero_le_one.trans ((hf1 x0).trans (hfC x0))\n have hfi : Integrable f μ := integrable_of_measurable_bounded hf fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hf1 x))]\n exact hfC x\n have hgi : Integrable g μ := integrable_of_measurable_bounded hg fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hg1 x))]\n exact hgC x\n have hfpos : 0 < ∫ x, f x ∂μ := by\n have : (0 : ℝ) < ∫ _x, (1 : ℝ) ∂μ := by simp\n exact this.trans_le (integral_mono (integrable_const 1) hfi (fun x => hf1 x))\n have hgpos : 0 < ∫ x, g x ∂μ := by\n have : (0 : ℝ) < ∫ _x, (1 : ℝ) ∂μ := by simp\n exact this.trans_le (integral_mono (integrable_const 1) hgi (fun x => hg1 x))\n let s := Real.log ((∫ x, f x ∂μ) / (∫ x, g x ∂μ))\n have hpoint : ∀ x, s * f x - (Real.exp s - 1) * g x ≤ kl (f x) (g x) :=\n fun x => kl_fenchel _ _ _ (lt_of_lt_of_le zero_lt_one (hf1 x))\n (lt_of_lt_of_le zero_lt_one (hg1 x))\n have hkmeas : Measurable (fun x => kl (f x) (g x)) := by\n exact ((hf.mul (hf.div hg).log).sub hf).add hg\n have hki : Integrable (fun x => kl (f x) (g x)) μ := by\n apply integrable_of_measurable_bounded hkmeas\n intro x\n have hC1 : 1 ≤ C := (hf1 x).trans (hfC x)\n have hdivlo : 1 / C ≤ f x / g x := by\n apply (div_le_div_iff₀ (by positivity) (lt_of_lt_of_le zero_lt_one (hg1 x))).2\n nlinarith [hf1 x, hgC x]\n have hdivhi : f x / g x ≤ C := by\n apply (div_le_iff₀ (lt_of_lt_of_le zero_lt_one (hg1 x))).2\n nlinarith [hfC x, hg1 x]\n have habslog : |Real.log (f x / g x)| ≤ Real.log C := by\n rw [abs_le]\n constructor\n · rw [neg_le, ← Real.log_inv]\n apply Real.log_le_log (inv_pos.mpr (div_pos\n (lt_of_lt_of_le zero_lt_one (hf1 x))\n (lt_of_lt_of_le zero_lt_one (hg1 x))))\n rw [inv_div]\n apply (div_le_iff₀ (lt_of_lt_of_le zero_lt_one (hf1 x))).2\n nlinarith [hgC x, hf1 x]\n · exact Real.log_le_log (div_pos (lt_of_lt_of_le zero_lt_one (hf1 x))\n (lt_of_lt_of_le zero_lt_one (hg1 x))) hdivhi\n have hlogC : 0 ≤ Real.log C := Real.log_nonneg hC1\n have hf0 : 0 ≤ f x := zero_le_one.trans (hf1 x)\n have hg0 : 0 ≤ g x := zero_le_one.trans (hg1 x)\n have hmul : |f x * Real.log (f x / g x)| ≤ C * Real.log C := by\n rw [abs_mul, abs_of_nonneg hf0]\n exact (mul_le_mul_of_nonneg_right (hfC x) (abs_nonneg _)).trans\n (mul_le_mul_of_nonneg_left habslog hC0)\n calc\n |kl (f x) (g x)|\n ≤ |f x * Real.log (f x / g x)| + |f x| + |g x| := by\n dsimp [kl]\n calc\n |f x * Real.log (f x / g x) - f x + g x|\n ≤ |f x * Real.log (f x / g x) - f x| + |g x| := abs_add_le _ _\n _ ≤ |f x * Real.log (f x / g x)| + |f x| + |g x| := by\n gcongr\n exact abs_sub _ _\n _ ≤ C * Real.log C + C + C := by\n exact add_le_add (add_le_add hmul (by simpa [abs_of_nonneg hf0] using hfC x))\n (by simpa [abs_of_nonneg hg0] using hgC x)\n have hint := integral_mono (hfi.const_mul s |>.sub (hgi.const_mul (Real.exp s - 1))) hki hpoint\n have hs_exp : Real.exp s = (∫ x, f x ∂μ) / (∫ x, g x ∂μ) := by\n dsimp [s]\n rw [Real.exp_log (div_pos hfpos hgpos)]\n have hs_log : s = Real.log (∫ x, f x ∂μ) - Real.log (∫ x, g x ∂μ) := by\n dsimp [s]\n rw [Real.log_div hfpos.ne' hgpos.ne']\n change (∫ x, s * f x - (Real.exp s - 1) * g x ∂μ) ≤ _ at hint\n rw [integral_sub (hfi.const_mul s) (hgi.const_mul (Real.exp s - 1)),\n integral_const_mul, integral_const_mul] at hint\n rw [kl, Real.log_div hfpos.ne' hgpos.ne']\n calc\n (∫ x, f x ∂μ) * (Real.log (∫ x, f x ∂μ) - Real.log (∫ x, g x ∂μ)) -\n (∫ x, f x ∂μ) + ∫ x, g x ∂μ\n = s * (∫ x, f x ∂μ) -\n (((∫ x, f x ∂μ) / (∫ x, g x ∂μ)) - 1) * (∫ x, g x ∂μ) := by\n rw [hs_log]\n field_simp\n <;> ring\n _ ≤ ∫ x, kl (f x) (g x) ∂μ := by\n simpa only [hs_exp] using hint\n\nprivate lemma entropy_le_integral_kl_const\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n {f : Ω → ℝ} {a C : ℝ}\n (hf : Measurable f) (hf1 : ∀ x, 1 ≤ f x) (hfC : ∀ x, f x ≤ C)\n (ha : 0 < a) :\n entropy μ f ≤ ∫ x, kl (f x) a ∂μ := by\n letI : Nonempty Ω := ProbabilityMeasure.nonempty ⟨μ, inferInstance⟩\n let x0 : Ω := Classical.choice (inferInstance : Nonempty Ω)\n have hC1 : 1 ≤ C := (hf1 x0).trans (hfC x0)\n have hfi : Integrable f μ := integrable_of_measurable_bounded hf fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hf1 x))]\n exact hfC x\n have hflog : Integrable (fun x => f x * Real.log (f x)) μ := by\n apply integrable_of_measurable_bounded (hf.mul hf.log)\n intro x\n rw [abs_mul, abs_of_nonneg (zero_le_one.trans (hf1 x)),\n abs_of_nonneg (Real.log_nonneg (hf1 x))]\n exact mul_le_mul (hfC x) (Real.log_le_log (lt_of_lt_of_le zero_lt_one (hf1 x)) (hfC x))\n (Real.log_nonneg (hf1 x)) (zero_le_one.trans hC1)\n have hmeanpos : 0 < ∫ x, f x ∂μ := by\n have h : (0 : ℝ) < ∫ _x, (1 : ℝ) ∂μ := by simp\n exact h.trans_le (integral_mono (integrable_const 1) hfi hf1)\n have hscalar := kl_nonneg hmeanpos ha\n have hrewrite :\n (∫ x, kl (f x) a ∂μ) = entropy μ f + kl (∫ x, f x ∂μ) a := by\n simp_rw [kl, Real.log_div (lt_of_lt_of_le zero_lt_one (hf1 _)).ne' ha.ne',\n mul_sub, mul_comm (f _) (Real.log a)]\n have hlogmul : Integrable (fun x => Real.log a * f x) μ := hfi.const_mul _\n have hfirst : Integrable (fun x => f x * Real.log (f x) - Real.log a * f x) μ :=\n hflog.sub hlogmul\n have hleft : Integrable\n (fun x => f x * Real.log (f x) - Real.log a * f x - f x) μ := hfirst.sub hfi\n rw [integral_add hleft (integrable_const a), integral_sub hfirst hfi,\n integral_sub hflog hlogmul, integral_const_mul, integral_const]\n simp only [measureReal_univ_eq_one, one_smul]\n rw [entropy, Real.log_div hmeanpos.ne' ha.ne']\n ring\n rw [hrewrite]\n linarith\n\nprivate lemma entropy_prod_eq\n {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]\n (μ : Measure Ω₁) (ν : Measure Ω₂) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]\n {f : Ω₁ × Ω₂ → ℝ} {C : ℝ}\n (hf : Measurable f) (hf1 : ∀ x, 1 ≤ f x) (hfC : ∀ x, f x ≤ C) :\n entropy (μ.prod ν) f =\n (∫ y, entropy μ (fun x => f (x, y)) ∂ν) +\n entropy ν (fun y => ∫ x, f (x, y) ∂μ) := by\n letI : Nonempty Ω₁ := ProbabilityMeasure.nonempty ⟨μ, inferInstance⟩\n letI : Nonempty Ω₂ := ProbabilityMeasure.nonempty ⟨ν, inferInstance⟩\n let z0 : Ω₁ × Ω₂ :=\n (Classical.choice (inferInstance : Nonempty Ω₁),\n Classical.choice (inferInstance : Nonempty Ω₂))\n have hC1 : 1 ≤ C := (hf1 z0).trans (hfC z0)\n have hfi : Integrable f (μ.prod ν) := integrable_of_measurable_bounded hf fun z => by\n rw [abs_of_nonneg (zero_le_one.trans (hf1 z))]\n exact hfC z\n have hflog : Integrable (fun z => f z * Real.log (f z)) (μ.prod ν) := by\n apply integrable_of_measurable_bounded (hf.mul hf.log)\n intro z\n rw [abs_mul, abs_of_nonneg (zero_le_one.trans (hf1 z)),\n abs_of_nonneg (Real.log_nonneg (hf1 z))]\n exact mul_le_mul (hfC z) (Real.log_le_log (lt_of_lt_of_le zero_lt_one (hf1 z)) (hfC z))\n (Real.log_nonneg (hf1 z)) (zero_le_one.trans hC1)\n let m : Ω₂ → ℝ := fun y => ∫ x, f (x, y) ∂μ\n have hm_meas : Measurable m := by\n exact hf.stronglyMeasurable.integral_prod_left'.measurable\n have hm1 : ∀ y, 1 ≤ m y := by\n intro y\n have hsec : Integrable (fun x => f (x, y)) μ :=\n integrable_of_measurable_bounded (hf.comp (measurable_id.prodMk measurable_const)) fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hf1 (x, y)))]\n exact hfC (x, y)\n simpa [m] using integral_mono (integrable_const 1) hsec (fun x => hf1 (x, y))\n have hmC : ∀ y, m y ≤ C := by\n intro y\n have hsec : Integrable (fun x => f (x, y)) μ :=\n integrable_of_measurable_bounded (hf.comp (measurable_id.prodMk measurable_const)) fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hf1 (x, y)))]\n exact hfC (x, y)\n simpa [m] using integral_mono hsec (integrable_const C) (fun x => hfC (x, y))\n have hmi : Integrable m ν := integrable_of_measurable_bounded hm_meas fun y => by\n rw [abs_of_nonneg (zero_le_one.trans (hm1 y))]\n exact hmC y\n have hmlog : Integrable (fun y => m y * Real.log (m y)) ν := by\n apply integrable_of_measurable_bounded (hm_meas.mul hm_meas.log)\n intro y\n rw [abs_mul, abs_of_nonneg (zero_le_one.trans (hm1 y)),\n abs_of_nonneg (Real.log_nonneg (hm1 y))]\n exact mul_le_mul (hmC y) (Real.log_le_log (lt_of_lt_of_le zero_lt_one (hm1 y)) (hmC y))\n (Real.log_nonneg (hm1 y)) (zero_le_one.trans hC1)\n have hinnerlog : Integrable (fun y => ∫ x, f (x, y) * Real.log (f (x, y)) ∂μ) ν :=\n hflog.integral_prod_right\n simp_rw [entropy]\n rw [integral_sub hinnerlog hmlog]\n change (∫ z, f z * Real.log (f z) ∂μ.prod ν) -\n (∫ z, f z ∂μ.prod ν) * Real.log (∫ z, f z ∂μ.prod ν) =\n ((∫ y, ∫ x, f (x, y) * Real.log (f (x, y)) ∂μ ∂ν) -\n ∫ y, m y * Real.log (m y) ∂ν) +\n ((∫ y, m y * Real.log (m y) ∂ν) -\n (∫ y, m y ∂ν) * Real.log (∫ y, m y ∂ν))\n rw [← integral_prod_symm _ hflog, ← integral_prod_symm _ hfi]\n ring\n\nprivate lemma entropy_comp_equiv\n {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω']\n {μ : Measure Ω} {ν : Measure Ω'} (e : Ω ≃ᵐ Ω')\n (he : MeasurePreserving e μ ν) (f : Ω → ℝ) :\n entropy ν (f ∘ e.symm) = entropy μ f := by\n rw [entropy, entropy]\n change (∫ x, (fun y => f y * Real.log (f y)) (e.symm x) ∂ν) -\n (∫ x, f (e.symm x) ∂ν) * Real.log (∫ x, f (e.symm x) ∂ν) = _\n have hq : (∫ x, (fun y => f y * Real.log (f y)) (e.symm x) ∂ν) =\n ∫ y, f y * Real.log (f y) ∂μ :=\n he.symm.integral_comp' (fun y : Ω => f y * Real.log (f y))\n have hfm : (∫ x, f (e.symm x) ∂ν) = ∫ y, f y ∂μ :=\n he.symm.integral_comp' (fun y : Ω => f y)\n rw [hq, hfm]\n\nprivate lemma entropy_pi_le_sum_kl\n {n : ℕ} {α : Fin n → Type*} [∀ i, MeasurableSpace (α i)]\n (μ : ∀ i, Measure (α i)) [∀ i, IsProbabilityMeasure (μ i)]\n {g : (∀ i, α i) → ℝ} {a : Fin n → (∀ i, α i) → ℝ} {C : ℝ}\n (hg : Measurable g) (ha : ∀ i, Measurable (a i))\n (hg1 : ∀ ω, 1 ≤ g ω) (hgC : ∀ ω, g ω ≤ C)\n (ha1 : ∀ i ω, 1 ≤ a i ω) (haC : ∀ i ω, a i ω ≤ C)\n (hainv : ∀ i ω x, a i (Function.update ω i x) = a i ω) :\n entropy (Measure.pi μ) g ≤\n ∫ ω, ∑ i, kl (g ω) (a i ω) ∂Measure.pi μ := by\n induction n with\n | zero =>\n have hgconst : g = fun _ => g default := by\n funext x\n congr 1\n ext i\n exact Fin.elim0 i\n rw [hgconst]\n simp only [Finset.univ_eq_empty, Finset.sum_empty, integral_zero]\n simp only [entropy, integral_const, probReal_univ, one_smul, sub_self]\n exact le_rfl\n | succ n ih =>\n let β := fun j : Fin n => α j.succ\n let ν : Measure (∀ j, β j) := Measure.pi (fun j => μ j.succ)\n let e : (∀ i, α i) ≃ᵐ α 0 × (∀ j, β j) := MeasurableEquiv.piFinSuccAbove α 0\n let G : α 0 × (∀ j, β j) → ℝ := fun p => g (e.symm p)\n let A0 : α 0 × (∀ j, β j) → ℝ := fun p => a 0 (e.symm p)\n let Ar : Fin n → α 0 × (∀ j, β j) → ℝ :=\n fun j p => a j.succ (e.symm p)\n let m : (∀ j, β j) → ℝ := fun y => ∫ x, G (x, y) ∂μ 0\n let b : Fin n → (∀ j, β j) → ℝ :=\n fun j y => ∫ x, Ar j (x, y) ∂μ 0\n have he : MeasurePreserving e (Measure.pi μ) ((μ 0).prod ν) := by\n simpa [e, ν, β] using measurePreserving_piFinSuccAbove μ 0\n have he_cons (x : α 0) (y : ∀ j, β j) : e.symm (x, y) = Fin.cons x y := by\n change (MeasurableEquiv.piFinSuccAbove α 0).symm (x, y) = Fin.cons x y\n rw [MeasurableEquiv.piFinSuccAbove_symm_apply]\n ext i\n refine Fin.cases ?_ (fun j => ?_) i <;> simp\n have hA0_const (x x' : α 0) (y : ∀ j, β j) : A0 (x, y) = A0 (x', y) := by\n dsimp [A0]\n rw [he_cons, he_cons]\n simpa only [Fin.update_cons_zero] using hainv 0 (Fin.cons x' y) x\n have hG : Measurable G := hg.comp e.symm.measurable\n have hA0 : Measurable A0 := (ha 0).comp e.symm.measurable\n have hAr : ∀ j, Measurable (Ar j) := fun j => (ha j.succ).comp e.symm.measurable\n have hG1 : ∀ p, 1 ≤ G p := fun p => hg1 (e.symm p)\n have hGC : ∀ p, G p ≤ C := fun p => hgC (e.symm p)\n have hA01 : ∀ p, 1 ≤ A0 p := fun p => ha1 0 (e.symm p)\n have hA0C : ∀ p, A0 p ≤ C := fun p => haC 0 (e.symm p)\n have hAr1 : ∀ j p, 1 ≤ Ar j p := fun j p => ha1 j.succ (e.symm p)\n have hArC : ∀ j p, Ar j p ≤ C := fun j p => haC j.succ (e.symm p)\n have hm_meas : Measurable m := hG.stronglyMeasurable.integral_prod_left'.measurable\n have hb_meas : ∀ j, Measurable (b j) :=\n fun j => (hAr j).stronglyMeasurable.integral_prod_left'.measurable\n have hm1 : ∀ y, 1 ≤ m y := by\n intro y\n have hi : Integrable (fun x => G (x, y)) (μ 0) :=\n integrable_of_measurable_bounded\n (hG.comp (measurable_id.prodMk measurable_const)) fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hG1 (x, y)))]\n exact hGC (x, y)\n simpa [m] using integral_mono (integrable_const 1) hi (fun x => hG1 (x, y))\n have hmC : ∀ y, m y ≤ C := by\n intro y\n have hi : Integrable (fun x => G (x, y)) (μ 0) :=\n integrable_of_measurable_bounded\n (hG.comp (measurable_id.prodMk measurable_const)) fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hG1 (x, y)))]\n exact hGC (x, y)\n simpa [m] using integral_mono hi (integrable_const C) (fun x => hGC (x, y))\n have hb1 : ∀ j y, 1 ≤ b j y := by\n intro j y\n have hi : Integrable (fun x => Ar j (x, y)) (μ 0) :=\n integrable_of_measurable_bounded\n ((hAr j).comp (measurable_id.prodMk measurable_const)) fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hAr1 j (x, y)))]\n exact hArC j (x, y)\n simpa [b] using integral_mono (integrable_const 1) hi (fun x => hAr1 j (x, y))\n have hbC : ∀ j y, b j y ≤ C := by\n intro j y\n have hi : Integrable (fun x => Ar j (x, y)) (μ 0) :=\n integrable_of_measurable_bounded\n ((hAr j).comp (measurable_id.prodMk measurable_const)) fun x => by\n rw [abs_of_nonneg (zero_le_one.trans (hAr1 j (x, y)))]\n exact hArC j (x, y)\n simpa [b] using integral_mono hi (integrable_const C) (fun x => hArC j (x, y))\n have hb_inv : ∀ j y x, b j (Function.update y j x) = b j y := by\n intro j y x\n apply integral_congr_ae\n filter_upwards [] with x0\n dsimp [b, Ar]\n rw [he_cons, he_cons, Fin.cons_update]\n exact hainv j.succ (Fin.cons x0 y) x\n have hrest := ih (μ := fun j => μ j.succ) (g := m) (a := b)\n hm_meas hb_meas hm1 hmC hb1 hbC hb_inv\n have hfirst :\n ∫ y, entropy (μ 0) (fun x => G (x, y)) ∂ν ≤\n ∫ p, kl (G p) (A0 p) ∂((μ 0).prod ν) := by\n let xref : α 0 := (ProbabilityMeasure.nonempty ⟨μ 0, inferInstance⟩).some\n have hpoint (y : ∀ j, β j) :\n entropy (μ 0) (fun x => G (x, y)) ≤\n ∫ x, kl (G (x, y)) (A0 (x, y)) ∂μ 0 := by\n calc\n entropy (μ 0) (fun x => G (x, y)) ≤\n ∫ x, kl (G (x, y)) (A0 (xref, y)) ∂μ 0 :=\n entropy_le_integral_kl_const (μ 0)\n (hG.comp (measurable_id.prodMk measurable_const))\n (fun x => hG1 (x, y)) (fun x => hGC (x, y))\n (lt_of_lt_of_le zero_lt_one (hA01 (xref, y)))\n _ = ∫ x, kl (G (x, y)) (A0 (x, y)) ∂μ 0 := by\n apply integral_congr_ae\n filter_upwards [] with x\n rw [hA0_const xref x y]\n have hGlog : Integrable (fun p => G p * Real.log (G p)) ((μ 0).prod ν) :=\n integrable_mul_log_of_bounds ((μ 0).prod ν) hG hG1 hGC\n have hmlog : Integrable (fun y => m y * Real.log (m y)) ν :=\n integrable_mul_log_of_bounds ν hm_meas hm1 hmC\n have hent : Integrable (fun y => entropy (μ 0) (fun x => G (x, y))) ν := by\n simpa only [entropy, m] using hGlog.integral_prod_right.sub hmlog\n have hK : Integrable (fun p => kl (G p) (A0 p)) ((μ 0).prod ν) :=\n integrable_kl_of_bounds ((μ 0).prod ν) hG hA0 hG1 hA01 hGC hA0C\n have hmono := integral_mono hent hK.integral_prod_right hpoint\n rw [← integral_prod_symm _ hK] at hmono\n exact hmono\n have hcontract :\n (∫ y, ∑ j, kl (m y) (b j y) ∂ν) ≤\n ∫ p, ∑ j, kl (G p) (Ar j p) ∂((μ 0).prod ν) := by\n have hsecG (y : ∀ j, β j) : Measurable (fun x => G (x, y)) :=\n hG.comp (measurable_id.prodMk measurable_const)\n have hsecAr (j : Fin n) (y : ∀ j, β j) : Measurable (fun x => Ar j (x, y)) :=\n (hAr j).comp (measurable_id.prodMk measurable_const)\n have hKsec (j : Fin n) (y : ∀ j, β j) :\n Integrable (fun x => kl (G (x, y)) (Ar j (x, y))) (μ 0) :=\n integrable_kl_of_bounds (μ 0) (hsecG y) (hsecAr j y)\n (fun x => hG1 (x, y)) (fun x => hAr1 j (x, y))\n (fun x => hGC (x, y)) (fun x => hArC j (x, y))\n have hpoint (y : ∀ j, β j) :\n (∑ j, kl (m y) (b j y)) ≤\n ∫ x, ∑ j, kl (G (x, y)) (Ar j (x, y)) ∂μ 0 := by\n calc\n (∑ j, kl (m y) (b j y)) ≤\n ∑ j, ∫ x, kl (G (x, y)) (Ar j (x, y)) ∂μ 0 := by\n apply Finset.sum_le_sum\n intro j _\n simpa only [m, b] using integral_kl_contraction (μ 0)\n (hsecG y) (hsecAr j y) (fun x => hG1 (x, y))\n (fun x => hAr1 j (x, y)) (fun x => hGC (x, y))\n (fun x => hArC j (x, y))\n _ = ∫ x, ∑ j, kl (G (x, y)) (Ar j (x, y)) ∂μ 0 := by\n symm\n exact integral_finset_sum Finset.univ (fun j _ => hKsec j y)\n have hL : Integrable (fun y => ∑ j, kl (m y) (b j y)) ν :=\n integrable_finset_sum Finset.univ fun j _ =>\n integrable_kl_of_bounds ν hm_meas (hb_meas j) hm1 (hb1 j) hmC (hbC j)\n have hPj (j : Fin n) :\n Integrable (fun p => kl (G p) (Ar j p)) ((μ 0).prod ν) :=\n integrable_kl_of_bounds ((μ 0).prod ν) hG (hAr j) hG1 (hAr1 j) hGC (hArC j)\n have hP : Integrable (fun p => ∑ j, kl (G p) (Ar j p)) ((μ 0).prod ν) :=\n integrable_finset_sum Finset.univ fun j _ => hPj j\n have hmono := integral_mono hL hP.integral_prod_right hpoint\n rw [← integral_prod_symm _ hP] at hmono\n exact hmono\n rw [← entropy_comp_equiv e he g]\n calc\n entropy ((μ 0).prod ν) G\n = (∫ y, entropy (μ 0) (fun x => G (x, y)) ∂ν) + entropy ν m :=\n entropy_prod_eq (μ 0) ν hG hG1 hGC\n _ ≤ (∫ p, kl (G p) (A0 p) ∂((μ 0).prod ν)) +\n (∫ y, ∑ j, kl (m y) (b j y) ∂ν) := add_le_add hfirst hrest\n _ ≤ (∫ p, kl (G p) (A0 p) ∂((μ 0).prod ν)) +\n (∫ p, ∑ j, kl (G p) (Ar j p) ∂((μ 0).prod ν)) :=\n add_le_add le_rfl hcontract\n _ = ∫ p, ∑ i, kl (G p) (a i (e.symm p)) ∂((μ 0).prod ν) := by\n have hK0 : Integrable (fun p => kl (G p) (A0 p)) ((μ 0).prod ν) :=\n integrable_kl_of_bounds ((μ 0).prod ν) hG hA0 hG1 hA01 hGC hA0C\n have hKr : Integrable (fun p => ∑ j, kl (G p) (Ar j p)) ((μ 0).prod ν) :=\n integrable_finset_sum Finset.univ fun j _ =>\n integrable_kl_of_bounds ((μ 0).prod ν) hG (hAr j) hG1 (hAr1 j)\n hGC (hArC j)\n rw [← integral_add hK0 hKr]\n apply integral_congr_ae\n filter_upwards [] with p\n rw [Fin.sum_univ_succ]\n _ = ∫ ω, ∑ i, kl (g ω) (a i ω) ∂Measure.pi μ := by\n rw [← he.integral_comp']\n simp only [G, MeasurableEquiv.symm_apply_apply]\n\nprivate lemma exp_chord (t d : ℝ) (ht : 0 ≤ t) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) :\n Real.exp (-t * d) + t * d - 1 ≤ d * (Real.exp (-t) + t - 1) := by\n have he : Real.exp (-t * d) ≤ (1 - d) * Real.exp 0 + d * Real.exp (-t) := by\n convert convexOn_exp.2 (Set.mem_univ (0 : ℝ)) (Set.mem_univ (-t))\n (sub_nonneg.mpr hd1) hd0 (by ring) using 1 <;> simp only [smul_eq_mul] <;> ring\n calc\n Real.exp (-t * d) + t * d - 1 ≤\n ((1 - d) * Real.exp 0 + d * Real.exp (-t)) + t * d - 1 := by linarith\n _ = d * (Real.exp (-t) + t - 1) := by rw [Real.exp_zero]; ring\n\nprivate lemma kl_exp_eq (A B : ℝ) :\n kl (Real.exp A) (Real.exp B) =\n Real.exp A * (Real.exp (B - A) + (A - B) - 1) := by\n rw [kl, ← Real.exp_sub, Real.log_exp]\n have he : Real.exp B = Real.exp A * Real.exp (B - A) := by\n rw [← Real.exp_add]\n congr 1\n ring\n rw [he]\n ring\n\nprivate lemma entropy_exp_selfBounded\n {n : ℕ} {α : Fin n → Type*} [∀ i, MeasurableSpace (α i)]\n (μ : ∀ i, Measure (α i)) [∀ i, IsProbabilityMeasure (μ i)]\n {Z : (∀ i, α i) → ℝ} {Zi : Fin n → (∀ i, α i) → ℝ} {B t : ℝ}\n (hZmeas : Measurable Z) (hZimeas : ∀ i, Measurable (Zi i))\n (hZ0 : ∀ ω, 0 ≤ Z ω) (hZB : ∀ ω, Z ω ≤ B)\n (hZi0 : ∀ i ω, 0 ≤ Zi i ω) (hZiB : ∀ i ω, Zi i ω ≤ B)\n (hZiinv : ∀ i ω x, Zi i (Function.update ω i x) = Zi i ω)\n (hd0 : ∀ i ω, 0 ≤ Z ω - Zi i ω)\n (hd1 : ∀ i ω, Z ω - Zi i ω ≤ 1)\n (hsum : ∀ ω, (∑ i, (Z ω - Zi i ω)) ≤ Z ω)\n (ht : 0 ≤ t) :\n entropy (Measure.pi μ) (fun ω => Real.exp (t * Z ω)) ≤\n (Real.exp (-t) + t - 1) *\n ∫ ω, Z ω * Real.exp (t * Z ω) ∂Measure.pi μ := by\n let g : (∀ i, α i) → ℝ := fun ω => Real.exp (t * Z ω)\n let a : Fin n → (∀ i, α i) → ℝ := fun i ω => Real.exp (t * Zi i ω)\n let C : ℝ := Real.exp (t * B)\n have hg : Measurable g := (hZmeas.const_mul t).exp\n have ha : ∀ i, Measurable (a i) := fun i => ((hZimeas i).const_mul t).exp\n have hg1 : ∀ ω, 1 ≤ g ω := fun ω => by\n rw [← Real.exp_zero]\n exact Real.exp_le_exp.mpr (mul_nonneg ht (hZ0 ω))\n have hgC : ∀ ω, g ω ≤ C := fun ω => Real.exp_le_exp.mpr\n (mul_le_mul_of_nonneg_left (hZB ω) ht)\n have ha1 : ∀ i ω, 1 ≤ a i ω := fun i ω => by\n rw [← Real.exp_zero]\n exact Real.exp_le_exp.mpr (mul_nonneg ht (hZi0 i ω))\n have haC : ∀ i ω, a i ω ≤ C := fun i ω => Real.exp_le_exp.mpr\n (mul_le_mul_of_nonneg_left (hZiB i ω) ht)\n have hainv : ∀ i ω x, a i (Function.update ω i x) = a i ω := by\n intro i ω x\n dsimp [a]\n rw [hZiinv]\n have hent := entropy_pi_le_sum_kl μ hg ha hg1 hgC ha1 haC hainv\n let c : ℝ := Real.exp (-t) + t - 1\n have hc : 0 ≤ c := by\n dsimp [c]\n linarith [Real.add_one_le_exp (-t)]\n have hpoint (ω : ∀ i, α i) :\n (∑ i, kl (g ω) (a i ω)) ≤ c * (Z ω * Real.exp (t * Z ω)) := by\n have hterm (i : Fin n) :\n kl (g ω) (a i ω) ≤\n Real.exp (t * Z ω) * ((Z ω - Zi i ω) * c) := by\n rw [show kl (g ω) (a i ω) = Real.exp (t * Z ω) *\n (Real.exp (-t * (Z ω - Zi i ω)) + t * (Z ω - Zi i ω) - 1) by\n dsimp [g, a]\n rw [kl_exp_eq]\n congr 1 <;> ring]\n exact mul_le_mul_of_nonneg_left\n (exp_chord t (Z ω - Zi i ω) ht (hd0 i ω) (hd1 i ω)) (Real.exp_pos _).le\n calc\n (∑ i, kl (g ω) (a i ω)) ≤\n ∑ i, Real.exp (t * Z ω) * ((Z ω - Zi i ω) * c) :=\n Finset.sum_le_sum fun i _ => hterm i\n _ = Real.exp (t * Z ω) * ((∑ i, (Z ω - Zi i ω)) * c) := by\n simp_rw [← mul_assoc]\n rw [← Finset.sum_mul, ← Finset.mul_sum]\n _ ≤ Real.exp (t * Z ω) * (Z ω * c) := by\n gcongr\n exact hsum ω\n _ = c * (Z ω * Real.exp (t * Z ω)) := by ring\n have hK : Integrable (fun ω => ∑ i, kl (g ω) (a i ω)) (Measure.pi μ) :=\n integrable_finset_sum Finset.univ fun i _ =>\n integrable_kl_of_bounds (Measure.pi μ) hg (ha i) hg1 (ha1 i) hgC (haC i)\n have htarget : Integrable (fun ω => c * (Z ω * Real.exp (t * Z ω))) (Measure.pi μ) := by\n letI : Nonempty (∀ i, α i) :=\n ProbabilityMeasure.nonempty ⟨Measure.pi μ, inferInstance⟩\n let ω0 : ∀ i, α i := Classical.choice (inferInstance : Nonempty (∀ i, α i))\n have hB0 : 0 ≤ B := (hZ0 ω0).trans (hZB ω0)\n apply Integrable.const_mul\n apply integrable_of_measurable_bounded (hZmeas.mul hg)\n intro ω\n rw [abs_mul, abs_of_nonneg (hZ0 ω), abs_of_pos (Real.exp_pos _)]\n exact mul_le_mul (hZB ω) (hgC ω) (Real.exp_pos _).le hB0\n calc\n entropy (Measure.pi μ) g ≤\n ∫ ω, ∑ i, kl (g ω) (a i ω) ∂Measure.pi μ := hent\n _ ≤ ∫ ω, c * (Z ω * Real.exp (t * Z ω)) ∂Measure.pi μ :=\n integral_mono hK htarget hpoint\n _ = c * ∫ ω, Z ω * Real.exp (t * Z ω) ∂Measure.pi μ := by\n rw [integral_const_mul]\n\nprivate lemma cgf_selfBounded_le\n {n : ℕ} {α : Fin n → Type*} [∀ i, MeasurableSpace (α i)]\n (μ : ∀ i, Measure (α i)) [∀ i, IsProbabilityMeasure (μ i)]\n {Z : (∀ i, α i) → ℝ} {Zi : Fin n → (∀ i, α i) → ℝ} {B : ℝ}\n (hZmeas : Measurable Z) (hZimeas : ∀ i, Measurable (Zi i))\n (hZ0 : ∀ ω, 0 ≤ Z ω) (hZB : ∀ ω, Z ω ≤ B)\n (hZi0 : ∀ i ω, 0 ≤ Zi i ω) (hZiB : ∀ i ω, Zi i ω ≤ B)\n (hZiinv : ∀ i ω x, Zi i (Function.update ω i x) = Zi i ω)\n (hd0 : ∀ i ω, 0 ≤ Z ω - Zi i ω)\n (hd1 : ∀ i ω, Z ω - Zi i ω ≤ 1)\n (hsum : ∀ ω, (∑ i, (Z ω - Zi i ω)) ≤ Z ω)\n {t : ℝ} (ht : 0 ≤ t) :\n ProbabilityTheory.cgf Z (Measure.pi μ) t ≤\n (∫ ω, Z ω ∂Measure.pi μ) * (Real.exp t - 1) := by\n let P : Measure (∀ i, α i) := Measure.pi μ\n let ψ : ℝ → ℝ := ProbabilityTheory.cgf Z P\n let v : ℝ := ∫ ω, Z ω ∂P\n have hP : IsProbabilityMeasure P := by dsimp [P]; infer_instance\n letI : IsProbabilityMeasure P := hP\n letI : Nonempty (∀ i, α i) := ProbabilityMeasure.nonempty ⟨P, inferInstance⟩\n let ω0 : ∀ i, α i := Classical.choice (inferInstance : Nonempty (∀ i, α i))\n have hB0 : 0 ≤ B := (hZ0 ω0).trans (hZB ω0)\n have hexp (s : ℝ) : Integrable (fun ω => Real.exp (s * Z ω)) P := by\n apply integrable_of_measurable_bounded (hZmeas.const_mul s |>.exp)\n intro ω\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.mpr\n calc\n s * Z ω ≤ |s| * Z ω := mul_le_mul_of_nonneg_right (le_abs_self s) (hZ0 ω)\n _ ≤ |s| * B := mul_le_mul_of_nonneg_left (hZB ω) (abs_nonneg s)\n have hExpSet : ProbabilityTheory.integrableExpSet Z P = Set.univ := by\n ext s\n simp only [ProbabilityTheory.integrableExpSet, Set.mem_setOf_eq, Set.mem_univ, iff_true]\n exact hexp s\n have hinter (s : ℝ) : s ∈ interior (ProbabilityTheory.integrableExpSet Z P) := by\n simp [hExpSet]\n have hmgfpos (s : ℝ) : 0 < ProbabilityTheory.mgf Z P s :=\n ProbabilityTheory.mgf_pos (hexp s)\n have hψ0 : ψ 0 = 0 := by simp [ψ]\n have hderivψ (s : ℝ) :\n deriv ψ s = (∫ ω, Z ω * Real.exp (s * Z ω) ∂P) /\n ProbabilityTheory.mgf Z P s := by\n simpa [ψ] using ProbabilityTheory.deriv_cgf (hinter s)\n have hdiff (s : ℝ) (hs : 0 ≤ s) :\n (1 - Real.exp (-s)) * deriv ψ s ≤ ψ s := by\n have hent := entropy_exp_selfBounded μ hZmeas hZimeas hZ0 hZB hZi0 hZiB\n hZiinv hd0 hd1 hsum hs\n let I : ℝ := ∫ ω, Z ω * Real.exp (s * Z ω) ∂P\n let F : ℝ := ProbabilityTheory.mgf Z P s\n have hent_eq :\n entropy P (fun ω => Real.exp (s * Z ω)) = s * I - F * ψ s := by\n rw [entropy]\n have hfun : (fun ω => Real.exp (s * Z ω) * Real.log (Real.exp (s * Z ω))) =\n fun ω => s * (Z ω * Real.exp (s * Z ω)) := by\n funext ω\n rw [Real.log_exp]\n ring\n rw [hfun, integral_const_mul]\n rfl\n have hraw : (1 - Real.exp (-s)) * I ≤ F * ψ s := by\n rw [hent_eq] at hent\n dsimp [I, F] at hent ⊢\n linarith\n rw [hderivψ]\n change (1 - Real.exp (-s)) * (I / F) ≤ ψ s\n rw [← mul_div_assoc]\n apply (div_le_iff₀ (hmgfpos s)).2\n simpa [mul_comm] using hraw\n let q : ℝ → ℝ := fun s => ψ s / (Real.exp s - 1)\n have hq_deriv (s : ℝ) (hs : 0 < s) : deriv q s ≤ 0 := by\n have hψder : HasDerivAt ψ (deriv ψ s) s :=\n (ProbabilityTheory.analyticAt_cgf (hinter s)).differentiableAt.hasDerivAt\n have hden : Real.exp s - 1 ≠ 0 := sub_ne_zero.mpr (ne_of_gt (Real.one_lt_exp_iff.mpr hs))\n have hqder := hψder.div ((Real.hasDerivAt_exp s).sub_const 1) hden\n have hnum : deriv ψ s * (Real.exp s - 1) - ψ s * Real.exp s ≤ 0 := by\n have hd := hdiff s hs.le\n have hm := mul_le_mul_of_nonneg_left hd (Real.exp_pos s).le\n have he : Real.exp s * (1 - Real.exp (-s)) = Real.exp s - 1 := by\n rw [mul_sub, mul_one, ← Real.exp_add]\n simp\n apply sub_nonpos.mpr\n calc\n deriv ψ s * (Real.exp s - 1) =\n Real.exp s * ((1 - Real.exp (-s)) * deriv ψ s) := by\n rw [← he]\n ring\n _ ≤ Real.exp s * ψ s := hm\n _ = ψ s * Real.exp s := by ring\n change deriv (ψ / fun x => Real.exp x - 1) s ≤ 0\n rw [hqder.deriv]\n exact div_nonpos_of_nonpos_of_nonneg hnum (sq_nonneg _)\n have hq_diff : DifferentiableOn ℝ q (Set.Ioi 0) := by\n intro s hs\n have hψd : HasDerivAt ψ (deriv ψ s) s :=\n (ProbabilityTheory.analyticAt_cgf (hinter s)).differentiableAt.hasDerivAt\n have hdend : HasDerivAt (fun r : ℝ => Real.exp r - 1) (Real.exp s) s :=\n (Real.hasDerivAt_exp s).sub_const 1\n have hquot := hψd.div hdend\n (sub_ne_zero.mpr (ne_of_gt (Real.one_lt_exp_iff.mpr hs)))\n exact hquot.hasDerivWithinAt.differentiableWithinAt\n have hq_anti : AntitoneOn q (Set.Ioi 0) := by\n apply antitoneOn_of_deriv_nonpos (convex_Ioi 0) hq_diff.continuousOn\n · simpa using hq_diff\n intro s hs\n exact hq_deriv s (interior_subset hs)\n have hψder0 : HasDerivAt ψ v 0 := by\n have h := (ProbabilityTheory.analyticAt_cgf (hinter 0)).differentiableAt.hasDerivAt\n rw [ProbabilityTheory.deriv_cgf_zero (hinter 0)] at h\n simpa [v] using h\n have hden0 : HasDerivAt (fun s : ℝ => Real.exp s - 1) 1 0 := by\n simpa using (Real.hasDerivAt_exp 0).sub_const 1\n have hnum_lim : Tendsto (fun s : ℝ => s⁻¹ * ψ s)\n (nhdsWithin 0 (Set.Ioi 0)) (nhds v) := by\n simpa [hψ0, smul_eq_mul] using hψder0.tendsto_slope_zero_right\n have hden_lim : Tendsto (fun s : ℝ => s⁻¹ * (Real.exp s - 1))\n (nhdsWithin 0 (Set.Ioi 0)) (nhds 1) := by\n simpa [smul_eq_mul] using hden0.tendsto_slope_zero_right\n have hq_lim : Tendsto q (nhdsWithin 0 (Set.Ioi 0)) (nhds v) := by\n have hratio := hnum_lim.div hden_lim (by norm_num)\n have hratio' : Tendsto\n ((fun s : ℝ => s⁻¹ * ψ s) / fun s => s⁻¹ * (Real.exp s - 1))\n (nhdsWithin 0 (Set.Ioi 0)) (nhds v) := by\n simpa using hratio\n apply hratio'.congr'\n filter_upwards [self_mem_nhdsWithin] with s hs\n dsimp [q]\n have hs' : 0 < s := hs\n have hsne : s ≠ 0 := ne_of_gt hs'\n have hene : Real.exp s - 1 ≠ 0 :=\n sub_ne_zero.mpr (ne_of_gt (Real.one_lt_exp_iff.mpr hs'))\n field_simp [hsne, hene]\n rcases ht.eq_or_lt with rfl | htpos\n · simp [ψ]\n have hqt : q t ≤ v := by\n apply ge_of_tendsto hq_lim\n filter_upwards [self_mem_nhdsWithin,\n (eventually_lt_nhds htpos).filter_mono inf_le_left] with s hs0 hst\n exact hq_anti hs0 htpos hst.le\n have hdenpos : 0 < Real.exp t - 1 := sub_pos.mpr (Real.one_lt_exp_iff.mpr htpos)\n change ψ t ≤ v * (Real.exp t - 1)\n exact (div_le_iff₀ hdenpos).1 hqt\n\nnoncomputable def bennettH (u : ℝ) : ℝ :=\n (1 + u) * Real.log (1 + u) - u\n\nprivate lemma bennett_tail_of_cgf\n {Ω : Type*} [MeasurableSpace Ω]\n (P : Measure Ω) [IsProbabilityMeasure P]\n {Z : Ω → ℝ}\n (hexp : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * Z ω)) P)\n {v : ℝ}\n (hcgf : ∀ t : ℝ, 0 ≤ t →\n ProbabilityTheory.cgf Z P t ≤ v * (Real.exp t - 1))\n (hv : 0 < v) {x : ℝ} (hx : 0 ≤ x) :\n P.real {ω | v + x ≤ Z ω} ≤\n Real.exp (-v * bennettH (x / v)) := by\n let u : ℝ := x / v\n let t : ℝ := Real.log (1 + u)\n have hvne : v ≠ 0 := ne_of_gt hv\n have hu : 0 ≤ u := by\n dsimp [u]\n exact div_nonneg hx hv.le\n have h1u : 0 < 1 + u := by linarith\n have ht : 0 ≤ t := by\n dsimp [t]\n exact Real.log_nonneg (by linarith)\n have hchernoff := ProbabilityTheory.measure_ge_le_exp_cgf\n (X := Z) (μ := P) (t := t) (v + x) ht (hexp t)\n calc\n P.real {ω | v + x ≤ Z ω} ≤\n Real.exp (-t * (v + x) + ProbabilityTheory.cgf Z P t) := hchernoff\n _ ≤ Real.exp (-t * (v + x) + v * (Real.exp t - 1)) := by\n exact Real.exp_le_exp.mpr (by linarith [hcgf t ht])\n _ = Real.exp (-v * bennettH (x / v)) := by\n congr 1\n have hvx : x = v * u := by\n dsimp [u]\n field_simp [hvne]\n rw [show Real.exp t = 1 + u by\n dsimp [t]\n exact Real.exp_log h1u]\n change -t * (v + x) + v * ((1 + u) - 1) = -v * bennettH u\n rw [hvx]\n simp only [bennettH]\n dsimp [t]\n ring\n\nprivate lemma bennett_tail_selfBounded\n {n : ℕ} {α : Fin n → Type*} [∀ i, MeasurableSpace (α i)]\n (μ : ∀ i, Measure (α i)) [∀ i, IsProbabilityMeasure (μ i)]\n {Z : (∀ i, α i) → ℝ} {Zi : Fin n → (∀ i, α i) → ℝ} {B : ℝ}\n (hZmeas : Measurable Z) (hZimeas : ∀ i, Measurable (Zi i))\n (hZ0 : ∀ ω, 0 ≤ Z ω) (hZB : ∀ ω, Z ω ≤ B)\n (hZi0 : ∀ i ω, 0 ≤ Zi i ω) (hZiB : ∀ i ω, Zi i ω ≤ B)\n (hZiinv : ∀ i ω x, Zi i (Function.update ω i x) = Zi i ω)\n (hd0 : ∀ i ω, 0 ≤ Z ω - Zi i ω)\n (hd1 : ∀ i ω, Z ω - Zi i ω ≤ 1)\n (hsum : ∀ ω, (∑ i, (Z ω - Zi i ω)) ≤ Z ω)\n (hv : 0 < ∫ ω, Z ω ∂Measure.pi μ)\n {x : ℝ} (hx : 0 ≤ x) :\n (Measure.pi μ).real\n {ω | (∫ ω, Z ω ∂Measure.pi μ) + x ≤ Z ω} ≤\n Real.exp (-(∫ ω, Z ω ∂Measure.pi μ) *\n bennettH (x / (∫ ω, Z ω ∂Measure.pi μ))) := by\n let P : Measure (∀ i, α i) := Measure.pi μ\n have hP : IsProbabilityMeasure P := by dsimp [P]; infer_instance\n letI : IsProbabilityMeasure P := hP\n letI : Nonempty (∀ i, α i) := ProbabilityMeasure.nonempty ⟨P, inferInstance⟩\n let ω0 : ∀ i, α i := Classical.choice (inferInstance : Nonempty (∀ i, α i))\n have hB0 : 0 ≤ B := (hZ0 ω0).trans (hZB ω0)\n have hexp (t : ℝ) : Integrable (fun ω => Real.exp (t * Z ω)) P := by\n apply integrable_of_measurable_bounded (hZmeas.const_mul t |>.exp)\n intro ω\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.mpr\n calc\n t * Z ω ≤ |t| * Z ω :=\n mul_le_mul_of_nonneg_right (le_abs_self t) (hZ0 ω)\n _ ≤ |t| * B :=\n mul_le_mul_of_nonneg_left (hZB ω) (abs_nonneg t)\n apply bennett_tail_of_cgf P hexp (v := ∫ ω, Z ω ∂Measure.pi μ) ?_ hv hx\n intro t ht\n exact cgf_selfBounded_le μ hZmeas hZimeas hZ0 hZB hZi0 hZiB hZiinv\n hd0 hd1 hsum ht\n\ntheorem ch41_theorem_41_2\n {n : ℕ}\n {α : Fin n → Type*} [∀ i, MeasurableSpace (α i)]\n (μ : ∀ i, Measure (α i)) [∀ i, IsProbabilityMeasure (μ i)]\n (F : Finset (∀ i, α i → ℝ)) (hF : F.Nonempty)\n (hmeas : ∀ f ∈ F, ∀ i, Measurable (f i))\n (hbound : ∀ f ∈ F, ∀ i (a : α i), 0 ≤ f i a ∧ f i a ≤ 1)\n (Z : (∀ i, α i) → ℝ)\n (hZ : ∀ ω, Z ω = F.sup' hF (fun f => ∑ i : Fin n, f i (ω i)))\n (hZint : Integrable Z (Measure.pi μ))\n (hEZ : 0 < ∫ ω, Z ω ∂(Measure.pi μ))\n {x : ℝ} (hx : 0 ≤ x) :\n ((Measure.pi μ) {ω | Z ω ≥ (∫ ω, Z ω ∂(Measure.pi μ)) + x}).toReal\n ≤ Real.exp (-(∫ ω, Z ω ∂(Measure.pi μ)) *\n bennettH (x / (∫ ω, Z ω ∂(Measure.pi μ)))) := by\n let Zi : Fin n → (∀ i, α i) → ℝ := fun i ω =>\n F.sup' hF (fun f => ∑ j ∈ Finset.univ.erase i, f j (ω j))\n have hZmeas : Measurable Z := by\n rw [show Z = fun ω => F.sup' hF (fun f => ∑ i : Fin n, f i (ω i)) by\n funext ω\n exact hZ ω]\n have hm : Measurable (F.sup' hF\n (fun f (ω : ∀ i, α i) => ∑ i : Fin n, f i (ω i))) := by\n apply Finset.measurable_sup' hF\n intro f hf\n apply Finset.measurable_sum\n intro i hi\n exact (hmeas f hf i).comp (measurable_pi_apply i)\n have heq :\n (fun ω => F.sup' hF (fun f => ∑ i : Fin n, f i (ω i))) =\n F.sup' hF (fun f (ω : ∀ i, α i) => ∑ i : Fin n, f i (ω i)) := by\n funext ω\n exact (Finset.sup'_apply\n (C := fun _ : (∀ i, α i) => ℝ) hF\n (fun f (ω : ∀ i, α i) => ∑ i : Fin n, f i (ω i)) ω).symm\n rw [heq]\n exact hm\n have hZimeas : ∀ i, Measurable (Zi i) := by\n intro i\n dsimp [Zi]\n have hm : Measurable (F.sup' hF\n (fun f (ω : ∀ i, α i) =>\n ∑ j ∈ Finset.univ.erase i, f j (ω j))) := by\n apply Finset.measurable_sup' hF\n intro f hf\n apply Finset.measurable_sum\n intro j hj\n exact (hmeas f hf j).comp (measurable_pi_apply j)\n have heq :\n (fun ω => F.sup' hF\n (fun f => ∑ j ∈ Finset.univ.erase i, f j (ω j))) =\n F.sup' hF (fun f (ω : ∀ i, α i) =>\n ∑ j ∈ Finset.univ.erase i, f j (ω j)) := by\n funext ω\n exact (Finset.sup'_apply\n (C := fun _ : (∀ i, α i) => ℝ) hF\n (fun f (ω : ∀ i, α i) =>\n ∑ j ∈ Finset.univ.erase i, f j (ω j)) ω).symm\n rw [heq]\n exact hm\n have hZ0 : ∀ ω, 0 ≤ Z ω := by\n intro ω\n rw [hZ ω]\n obtain ⟨f, hf⟩ := (show F.Nonempty from hF)\n calc\n 0 ≤ ∑ i : Fin n, f i (ω i) := by\n exact Finset.sum_nonneg fun i _ => (hbound f hf i (ω i)).1\n _ ≤ F.sup' hF (fun g => ∑ i : Fin n, g i (ω i)) :=\n Finset.le_sup' (fun g => ∑ i : Fin n, g i (ω i)) hf\n have hZB : ∀ ω, Z ω ≤ (n : ℝ) := by\n intro ω\n rw [hZ ω]\n apply Finset.sup'_le hF\n intro f hf\n calc\n (∑ i : Fin n, f i (ω i)) ≤ ∑ _i : Fin n, (1 : ℝ) := by\n exact Finset.sum_le_sum fun i _ => (hbound f hf i (ω i)).2\n _ = (n : ℝ) := by simp\n have hZi0 : ∀ i ω, 0 ≤ Zi i ω := by\n intro i ω\n dsimp [Zi]\n obtain ⟨f, hf⟩ := (show F.Nonempty from hF)\n calc\n 0 ≤ ∑ j ∈ Finset.univ.erase i, f j (ω j) := by\n exact Finset.sum_nonneg fun j _ => (hbound f hf j (ω j)).1\n _ ≤ F.sup' hF (fun g => ∑ j ∈ Finset.univ.erase i, g j (ω j)) :=\n Finset.le_sup' (fun g => ∑ j ∈ Finset.univ.erase i, g j (ω j)) hf\n have hZiB : ∀ i ω, Zi i ω ≤ (n : ℝ) := by\n intro i ω\n dsimp [Zi]\n apply Finset.sup'_le hF\n intro f hf\n calc\n (∑ j ∈ Finset.univ.erase i, f j (ω j)) ≤\n ∑ _j ∈ Finset.univ.erase i, (1 : ℝ) := by\n exact Finset.sum_le_sum fun j _ => (hbound f hf j (ω j)).2\n _ = ((Finset.univ.erase i).card : ℝ) := by simp\n _ ≤ (n : ℝ) := by\n norm_cast\n simpa using Finset.card_le_card (Finset.erase_subset i Finset.univ)\n have hZiinv : ∀ i ω a, Zi i (Function.update ω i a) = Zi i ω := by\n intro i ω a\n dsimp [Zi]\n apply Finset.sup'_congr hF rfl\n intro f hf\n apply Finset.sum_congr rfl\n intro j hj\n have hji : j ≠ i := (Finset.mem_erase.mp hj).1\n rw [Function.update_of_ne hji]\n have hd0 : ∀ i ω, 0 ≤ Z ω - Zi i ω := by\n intro i ω\n apply sub_nonneg.mpr\n rw [hZ ω]\n dsimp [Zi]\n apply Finset.sup'_le hF\n intro f hf\n calc\n (∑ j ∈ Finset.univ.erase i, f j (ω j)) ≤\n ∑ j : Fin n, f j (ω j) := by\n rw [← Finset.sum_erase_add Finset.univ (fun j => f j (ω j))\n (Finset.mem_univ i)]\n exact le_add_of_nonneg_right (hbound f hf i (ω i)).1\n _ ≤ F.sup' hF (fun g => ∑ j : Fin n, g j (ω j)) :=\n Finset.le_sup' (fun g => ∑ j : Fin n, g j (ω j)) hf\n have hd1 : ∀ i ω, Z ω - Zi i ω ≤ 1 := by\n intro i ω\n rw [hZ ω]\n obtain ⟨f, hf, hmax⟩ :=\n Finset.exists_mem_eq_sup' hF (fun g => ∑ j : Fin n, g j (ω j))\n rw [hmax]\n have hp : (∑ j ∈ Finset.univ.erase i, f j (ω j)) ≤ Zi i ω := by\n dsimp [Zi]\n exact Finset.le_sup'\n (fun g => ∑ j ∈ Finset.univ.erase i, g j (ω j)) hf\n have hid := Finset.sum_erase_add Finset.univ (fun j => f j (ω j))\n (Finset.mem_univ i)\n have hb := (hbound f hf i (ω i)).2\n linarith\n have hsum : ∀ ω, (∑ i, (Z ω - Zi i ω)) ≤ Z ω := by\n intro ω\n rw [hZ ω]\n obtain ⟨f, hf, hmax⟩ :=\n Finset.exists_mem_eq_sup' hF (fun g => ∑ j : Fin n, g j (ω j))\n rw [hmax]\n apply Finset.sum_le_sum\n intro i hi\n have hp : (∑ j ∈ Finset.univ.erase i, f j (ω j)) ≤ Zi i ω := by\n dsimp [Zi]\n exact Finset.le_sup'\n (fun g => ∑ j ∈ Finset.univ.erase i, g j (ω j)) hf\n have hid := Finset.sum_erase_add Finset.univ (fun j => f j (ω j))\n (Finset.mem_univ i)\n linarith\n exact bennett_tail_selfBounded μ hZmeas hZimeas hZ0 hZB hZi0 hZiB hZiinv\n hd0 hd1 hsum hEZ hx\n\nend GraduateLevel\n"} +{"id": "ch15_lemma_15_2", "source": "Graduate-level", "targets": [{"label": "ch15_lemma_15_2", "decls": ["ch15_lemma_15_2"], "statement": "Let \\(x=(x_{1},\\ldots,x_{n}),x^{\\prime}=(x_{1}^{\\prime},\\ldots,x_{n}^{\\prime})\\) . If for functions \\(\\varphi_{1}(x,x^{\\prime}),\\varphi_{2}(x,x^{\\prime}),\\varphi_{3}(x,x^{\\prime})\\)\n\\[\\begin{array}{ r }{\\mathbb{P}\\left(\\varphi_{1}(x,x^{\\prime})\\geq\\varphi_{2}(x,x^{\\prime})+\\sqrt{\\varphi_{3}(x,x^{\\prime})\\cdot t}\\right)\\leq\\Gamma e^{-\\gamma t}}\\end{array}\\]\nthen\n\\[\\begin{array}{ r }{\\mathbb{P}\\left(\\mathbb{E}_{x^{\\prime}}\\varphi_{1}(x,x^{\\prime})\\geq\\mathbb{E}_{x^{\\prime}}\\varphi_{2}(x,x^{\\prime})+\\sqrt{\\mathbb{E}_{x^{\\prime}}\\varphi_{3}(x,x^{\\prime})\\cdot t}\\right)\\leq\\Gamma\\cdot e\\cdot e^{-\\gamma t}.}\\end{array}\\]\n(i.e. if the inequality holds, then it holds with averaging over one of the copies)", "topic_domain": "Probability & Concentration", "topic_subtopic": "Functional & Supremum Concentration"}], "nl_proof": "First, note that \\(\\begin{array}{ r }{\\sqrt{a b}=\\operatorname*{inf}_{\\delta>0}(\\delta a+\\frac{b}{4\\delta})}\\end{array}\\) with \\(\\begin{array}{ r }{\\delta_{*}=\\sqrt{\\frac{b}{4 a}}}\\end{array}\\) achieving the infima. Hence,\n\\[\\begin{array}{ c }{{\\{\\varphi_{1}\\geq\\varphi_{2}+\\sqrt{\\varphi_{3}t}\\}=\\{\\exists\\delta>0,\\varphi_{1}\\geq\\varphi_{2}+\\delta\\varphi_{3}+\\displaystyle\\frac{t}{4\\delta}\\}}}\\\\ {{=\\{\\exists\\delta>0,(\\varphi_{1}-\\varphi_{2}-\\delta\\varphi_{3})4\\delta\\geq t\\}}}\\\\ {{=\\{\\underbrace{\\operatorname*{sup}_{\\delta>0}(\\varphi_{1}-\\varphi_{2}-\\delta\\varphi_{3})4\\delta}_{\\nu}\\geq t\\}}}\\end{array}\\]\nand similarly\n\\[\\big\\{\\mathbb{E}_{x^{\\prime}}\\varphi_{1}\\geq\\mathbb{E}_{x^{\\prime}}\\varphi_{2}+\\sqrt{\\mathbb{E}_{x^{\\prime}}\\varphi_{3}t}\\big\\}=\\underbrace{\\{\\operatorname*{sup}_{\\delta>0}(\\mathbb{E}_{x^{\\prime}}\\varphi_{1}-\\mathbb{E}_{x^{\\prime}}\\varphi_{2}-\\delta\\mathbb{E}_{x^{\\prime}}\\varphi_{3})4\\delta\\geq t\\}}_{\\xi}.\\]\nBy assumption, \\(\\mathbb{P}\\left(\\nu\\geq t\\right)\\leq\\Gamma e^{-\\gamma t}\\) . We want to prove \\(\\mathbb{P}\\left(\\xi\\geq t\\right)\\leq\\Gamma\\cdot e\\cdot e^{-\\gamma t}\\) . By the previous lemma, we only need to check whether \\(\\mathbb{E}\\phi(\\xi)\\le\\mathbb{E}\\phi(\\nu)\\)\n\\[\\begin{array}{ l }{\\displaystyle\\xi=\\operatorname*{sup}_{\\delta>0}\\mathbb{E}_{x^{\\prime}}(\\varphi_{1}-\\varphi_{2}-\\delta\\varphi_{3})4\\delta}\\\\ {\\displaystyle\\quad\\leq\\mathbb{E}_{x^{\\prime}}\\operatorname*{sup}_{\\delta>0}(\\varphi_{1}-\\varphi_{2}-\\delta\\varphi_{3})4\\delta}\\\\ {\\displaystyle=\\mathbb{E}_{x^{\\prime}}\\nu}\\end{array}\\]\nThus,\n\\[\\phi(\\xi)\\leq\\phi(\\mathbb{E}_{x^{\\prime}}\\nu)\\leq\\mathbb{E}_{x^{\\prime}}\\phi(\\nu)\\]\nby Jensen's inequality (\\(\\phi\\) is convex). Hence,\n\\[\\mathbb{E}\\phi(\\xi)\\le\\mathbb{E}\\mathbb{E}_{x^{\\prime}}\\phi(\\nu)=\\mathbb{E}\\phi(\\nu).\\]", "context": [{"id": "ch15:lemma:15_1", "name": "lemma 15.1", "statement": "Let \\(\\xi,\\nu\\) - random variables.Assume that\n\\[\\mathbb{P}\\left(\\nu\\geq t\\right)\\leq\\Gamma e^{-\\gamma t}\\]\nwhere \\(\\Gamma\\geq 1,t\\geq 0\\) ,and \\(\\gamma > 0\\) . Furthermore, for all \\(a > 0\\) assume that\n\\[\\mathbb{E}\\phi(\\xi)\\le\\mathbb{E}\\phi(\\nu)\\]\nwhere \\(\\phi(x)=(x-a)_{+}\\) .Then\n\\[\\mathbb{P}\\left(\\xi\\geq t\\right)\\leq\\Gamma\\cdot e\\cdot e^{-\\gamma t}.\\]"}, {"id": "ch14:theorem:14_1", "name": "theorem 14.1", "statement": "\\[\\mathbb{P}\\left(\\forall f\\in F,R(f)\\leq\\frac{2^{9/2}}{\\sqrt{n}}\\int_{0}^{d(0,f)}\\log^{1/2}\\mathcal{D}(F,\\varepsilon,d)d\\varepsilon+2^{7/2}d(0,f)\\sqrt{\\frac{u}{n}}\\right)\\geq 1-e^{-u}\\]\nfor any \\(u > 0\\)"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch15_lemma_15_2\n {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω']\n (μ : Measure Ω) (μ' : Measure Ω')\n [IsProbabilityMeasure μ] [IsProbabilityMeasure μ']\n (phi1 phi2 phi3 : Ω → Ω' → ℝ)\n (hmeas1 : Measurable (Function.uncurry phi1))\n (hmeas2 : Measurable (Function.uncurry phi2))\n (hmeas3 : Measurable (Function.uncurry phi3))\n (hphi3_nonneg : ∀ x x', 0 ≤ phi3 x x')\n (hint1 : ∀ x, Integrable (fun x' => phi1 x x') μ')\n (hint2 : ∀ x, Integrable (fun x' => phi2 x x') μ')\n (hint3 : ∀ x, Integrable (fun x' => phi3 x x') μ')\n (hmavg1 : Measurable (fun x => ∫ x', phi1 x x' ∂μ'))\n (hmavg2 : Measurable (fun x => ∫ x', phi2 x x' ∂μ'))\n (hmavg3 : Measurable (fun x => ∫ x', phi3 x x' ∂μ'))\n (Γ γ t : ℝ) (hΓ : 1 ≤ Γ) (hγ : 0 < γ) (ht : 0 ≤ t)\n (hyp : ∀ s : ℝ, 0 ≤ s →\n (μ.prod μ') {p : Ω × Ω' | phi1 p.1 p.2 ≥ phi2 p.1 p.2 + Real.sqrt (phi3 p.1 p.2 * s)}\n ≤ ENNReal.ofReal (Γ * Real.exp (-γ * s))) :\n μ {x : Ω | (∫ x', phi1 x x' ∂μ') ≥ (∫ x', phi2 x x' ∂μ')\n + Real.sqrt ((∫ x', phi3 x x' ∂μ') * t)}\n ≤ ENNReal.ofReal (Γ * Real.exp 1 * Real.exp (-γ * t)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real ENNReal NNReal\n\nnamespace GraduateLevel\n\nprivate lemma ofReal_max_zero (a : ℝ) : ENNReal.ofReal (max a 0) = ENNReal.ofReal a := by\n rcases le_or_lt a 0 with h | h\n · rw [max_eq_right h, ENNReal.ofReal_zero, (ENNReal.ofReal_eq_zero).2 h]\n · rw [max_eq_left h.le]\n\nprivate lemma sqrt_amgm {a s δ : ℝ} (ha : 0 ≤ a) (hs : 0 ≤ s) (hδ : 0 < δ) :\n Real.sqrt (a * s) ≤ δ * a + s / (4 * δ) := by\n obtain ⟨A, hA0, rfl⟩ : ∃ A, 0 ≤ A ∧ a = A ^ 2 :=\n ⟨Real.sqrt a, Real.sqrt_nonneg a, (Real.sq_sqrt ha).symm⟩\n obtain ⟨S, hS0, rfl⟩ : ∃ S, 0 ≤ S ∧ s = S ^ 2 :=\n ⟨Real.sqrt s, Real.sqrt_nonneg s, (Real.sq_sqrt hs).symm⟩\n have he : Real.sqrt (A ^ 2 * S ^ 2) = A * S := by\n rw [show A ^ 2 * S ^ 2 = (A * S) ^ 2 by ring, Real.sqrt_sq (by positivity)]\n rw [he, ← sub_nonneg]\n have h : δ * A ^ 2 + S ^ 2 / (4 * δ) - A * S = (2 * δ * A - S) ^ 2 / (4 * δ) := by\n field_simp; ring\n rw [h]; positivity\n\ntheorem ch15_lemma_15_2\n {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω']\n (μ : Measure Ω) (μ' : Measure Ω')\n [IsProbabilityMeasure μ] [IsProbabilityMeasure μ']\n (phi1 phi2 phi3 : Ω → Ω' → ℝ)\n (hmeas1 : Measurable (Function.uncurry phi1))\n (hmeas2 : Measurable (Function.uncurry phi2))\n (hmeas3 : Measurable (Function.uncurry phi3))\n (hphi3_nonneg : ∀ x x', 0 ≤ phi3 x x')\n (hint1 : ∀ x, Integrable (fun x' => phi1 x x') μ')\n (hint2 : ∀ x, Integrable (fun x' => phi2 x x') μ')\n (hint3 : ∀ x, Integrable (fun x' => phi3 x x') μ')\n (hmavg1 : Measurable (fun x => ∫ x', phi1 x x' ∂μ'))\n (hmavg2 : Measurable (fun x => ∫ x', phi2 x x' ∂μ'))\n (hmavg3 : Measurable (fun x => ∫ x', phi3 x x' ∂μ'))\n (Γ γ t : ℝ) (hΓ : 1 ≤ Γ) (hγ : 0 < γ) (ht : 0 ≤ t)\n (hyp : ∀ s : ℝ, 0 ≤ s →\n (μ.prod μ') {p : Ω × Ω' | phi1 p.1 p.2 ≥ phi2 p.1 p.2 + Real.sqrt (phi3 p.1 p.2 * s)}\n ≤ ENNReal.ofReal (Γ * Real.exp (-γ * s))) :\n μ {x : Ω | (∫ x', phi1 x x' ∂μ') ≥ (∫ x', phi2 x x' ∂μ')\n + Real.sqrt ((∫ x', phi3 x x' ∂μ') * t)}\n ≤ ENNReal.ofReal (Γ * Real.exp 1 * Real.exp (-γ * t)) := by\n have hE1 : (2:ℝ) ≤ Real.exp 1 := by have := Real.add_one_le_exp (1:ℝ); linarith\n have m1 : Measurable (fun p : Ω × Ω' => phi1 p.1 p.2) := hmeas1\n have m2 : Measurable (fun p : Ω × Ω' => phi2 p.1 p.2) := hmeas2\n have m3 : Measurable (fun p : Ω × Ω' => phi3 p.1 p.2) := hmeas3\n set S : Set Ω := {x : Ω | (∫ x', phi1 x x' ∂μ') ≥ (∫ x', phi2 x x' ∂μ')\n + Real.sqrt ((∫ x', phi3 x x' ∂μ') * t)} with hSdef\n rcases eq_or_lt_of_le ht with ht0 | ht0\n · -- t = 0\n refine le_trans prob_le_one ?_\n rw [ENNReal.one_le_ofReal]\n have h2 : Real.exp (-γ * t) = 1 := by rw [← ht0]; simp\n rw [h2, mul_one]\n nlinarith\n -- 0 < t\n set u : Ω → ℝ := fun x => (∫ x', phi1 x x' ∂μ') - (∫ x', phi2 x x' ∂μ') with hudef\n set Av : Ω → ℝ := fun x => (∫ x', phi3 x x' ∂μ') with hAvdef\n have hAvmeas : Measurable Av := hmavg3\n have humeas : Measurable u := hmavg1.sub hmavg2\n have hAvnn : ∀ x, 0 ≤ Av x := fun x => integral_nonneg (fun x' => hphi3_nonneg x x')\n set d : Ω → ℝ := fun x =>\n if 0 < Av x then Real.sqrt (t / Av x) / 2 else (if 0 < u x then t / (4 * u x) else 1) with hddef\n have hdmeas : Measurable d := by\n refine Measurable.ite (measurableSet_lt measurable_const hAvmeas) ?_ ?_\n · exact (Real.continuous_sqrt.measurable.comp (measurable_const.div hAvmeas)).div_const 2\n · exact Measurable.ite (measurableSet_lt measurable_const humeas)\n (measurable_const.div (measurable_const.mul humeas)) measurable_const\n have hdpos : ∀ x, 0 < d x := by\n intro x\n simp only [hddef]\n split_ifs with h1 h2\n · exact half_pos (Real.sqrt_pos.2 (div_pos ht0 h1))\n · exact div_pos ht0 (by linarith)\n · exact one_pos\n set g : Ω → Ω' → ℝ := fun x x' =>\n 1 + γ * (4 * d x * (phi1 x x' - phi2 x x' - d x * phi3 x x') - t) with hgdef\n have hdm : Measurable (fun p : Ω × Ω' => d p.1) := hdmeas.comp measurable_fst\n have hgm : Measurable (fun p : Ω × Ω' => g p.1 p.2) := by\n simp only [hgdef]\n exact measurable_const.add\n ((((measurable_const.mul hdm).mul ((m1.sub m2).sub (hdm.mul m3))).sub_const t).const_mul γ)\n have hgint : ∀ x, Integrable (fun x' => g x x') μ' := by\n intro x\n have h0 : Integrable (fun x' => phi1 x x' - phi2 x x' - d x * phi3 x x') μ' :=\n ((hint1 x).sub (hint2 x)).sub ((hint3 x).const_mul (d x))\n have h1 : Integrable\n (fun x' => 4 * d x * (phi1 x x' - phi2 x x' - d x * phi3 x x') - t) μ' :=\n (h0.const_mul (4 * d x)).sub (integrable_const t)\n exact (integrable_const 1).add (h1.const_mul γ)\n have hgintegral : ∀ x, (∫ x', g x x' ∂μ') = 1 + γ * (4 * d x * (u x - d x * Av x) - t) := by\n intro x\n have h0 : Integrable (fun x' => phi1 x x' - phi2 x x' - d x * phi3 x x') μ' :=\n ((hint1 x).sub (hint2 x)).sub ((hint3 x).const_mul (d x))\n have hi12 : Integrable (fun x' => phi1 x x' - phi2 x x') μ' := (hint1 x).sub (hint2 x)\n have hi3 : Integrable (fun x' => d x * phi3 x x') μ' := (hint3 x).const_mul (d x)\n have e0 : (∫ x', (phi1 x x' - phi2 x x' - d x * phi3 x x') ∂μ') = u x - d x * Av x := by\n rw [integral_sub hi12 hi3, integral_sub (hint1 x) (hint2 x), integral_const_mul]\n have h1 : Integrable\n (fun x' => 4 * d x * (phi1 x x' - phi2 x x' - d x * phi3 x x') - t) μ' :=\n (h0.const_mul (4 * d x)).sub (integrable_const t)\n simp only [hgdef]\n rw [integral_add (integrable_const 1) (h1.const_mul γ), integral_const, integral_const_mul,\n integral_sub (h0.const_mul _) (integrable_const t), integral_const_mul, e0, integral_const]\n simp\n -- the exceptional null set\n set A0 : Set Ω := {x | Av x = 0 ∧ u x = 0} with hA0def\n have hA0meas : MeasurableSet A0 :=\n (hAvmeas (measurableSet_singleton 0)).inter (humeas (measurableSet_singleton 0))\n have hnull : μ A0 = 0 := by\n set N : Set (Ω × Ω') :=\n {p : Ω × Ω' | phi3 p.1 p.2 = 0 ∧ phi2 p.1 p.2 ≤ phi1 p.1 p.2} with hNdef\n have hNmeas : MeasurableSet N :=\n (m3 (measurableSet_singleton 0)).inter (measurableSet_le m2 m1)\n have hNsub : ∀ s : ℝ, 0 ≤ s →\n N ⊆ {p : Ω × Ω' | phi1 p.1 p.2 ≥ phi2 p.1 p.2 + Real.sqrt (phi3 p.1 p.2 * s)} := by\n intro s _ p hp\n simp only [Set.mem_setOf_eq] at hp ⊢\n rw [hp.1, zero_mul, Real.sqrt_zero, add_zero]\n exact hp.2\n have hNzero : (μ.prod μ') N = 0 := by\n refine le_antisymm ?_ (zero_le _)\n refine ENNReal.le_of_forall_pos_le_add ?_\n intro ε hε _\n have hεpos : (0:ℝ) < (ε : ℝ) := by exact_mod_cast hε\n set s : ℝ := max 0 ((Real.log Γ - Real.log (ε:ℝ)) / γ) with hsdef\n have hs0 : 0 ≤ s := le_max_left _ _\n have hle : Γ * Real.exp (-γ * s) ≤ (ε:ℝ) := by\n have h1 : (Real.log Γ - Real.log (ε:ℝ)) / γ ≤ s := le_max_right _ _\n have h2 : Real.log Γ - Real.log (ε:ℝ) ≤ γ * s := by\n rw [div_le_iff₀ hγ] at h1; linarith [h1]\n have h3 : -γ * s ≤ Real.log (ε:ℝ) - Real.log Γ := by linarith\n have hΓ0 : (0:ℝ) < Γ := by linarith\n calc Γ * Real.exp (-γ * s) ≤ Γ * Real.exp (Real.log (ε:ℝ) - Real.log Γ) := by\n exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.2 h3) (by linarith)\n _ = Γ * ((ε:ℝ) / Γ) := by\n rw [Real.exp_sub, Real.exp_log hεpos, Real.exp_log hΓ0]\n _ = (ε:ℝ) := by field_simp\n calc (μ.prod μ') N ≤ ENNReal.ofReal (Γ * Real.exp (-γ * s)) :=\n le_trans (measure_mono (hNsub s hs0)) (hyp s hs0)\n _ ≤ ENNReal.ofReal (ε:ℝ) := ENNReal.ofReal_le_ofReal hle\n _ = 0 + (ε : ℝ≥0∞) := by\n rw [zero_add, ENNReal.ofReal_coe_nnreal]\n have hslice : ∫⁻ x, μ' (Prod.mk x ⁻¹' N) ∂μ = 0 := by\n rw [← Measure.prod_apply hNmeas]; exact hNzero\n have hFae : ∀ᵐ x ∂μ, μ' (Prod.mk x ⁻¹' N) = 0 := by\n have hmeasF : Measurable fun x => μ' (Prod.mk x ⁻¹' N) :=\n measurable_measure_prodMk_left hNmeas\n rw [lintegral_eq_zero_iff hmeasF] at hslice\n filter_upwards [hslice] with x hx using hx\n have hsub : A0 ⊆ {x | μ' (Prod.mk x ⁻¹' N) ≠ 0} := by\n intro x hx\n simp only [Set.mem_setOf_eq]\n intro hzero\n obtain ⟨hAv0, hu0⟩ := hx\n have h3 : (fun x' => phi3 x x') =ᵐ[μ'] 0 :=\n (integral_eq_zero_iff_of_nonneg (fun x' => hphi3_nonneg x x') (hint3 x)).1 hAv0\n have hslice0 : ∀ᵐ x' ∂μ', ¬ (phi3 x x' = 0 ∧ phi2 x x' ≤ phi1 x x') := by\n rw [ae_iff]\n have hEq : {a | ¬¬(phi3 x a = 0 ∧ phi2 x a ≤ phi1 x a)} = Prod.mk x ⁻¹' N := by\n ext a; simp [hNdef]\n rw [hEq]; exact hzero\n have hlt : ∀ᵐ x' ∂μ', phi1 x x' < phi2 x x' := by\n filter_upwards [h3, hslice0] with x' e1 e2\n by_contra hcon\n exact e2 ⟨e1, le_of_not_lt hcon⟩\n have hfnn : 0 ≤ᵐ[μ'] (fun x' => phi2 x x' - phi1 x x') := by\n filter_upwards [hlt] with x' e; simp only [Pi.zero_apply]; linarith\n have hfi : Integrable (fun x' => phi2 x x' - phi1 x x') μ' := (hint2 x).sub (hint1 x)\n have hint0 : (∫ x', (phi2 x x' - phi1 x x') ∂μ') = 0 := by\n rw [integral_sub (hint2 x) (hint1 x)]\n have : (∫ x', phi1 x x' ∂μ') = (∫ x', phi2 x x' ∂μ') := by\n have := hu0; simp only [hudef] at this; linarith\n rw [this]; ring\n have hf0 := (integral_eq_zero_iff_of_nonneg_ae hfnn hfi).1 hint0\n have hfalse : ∀ᵐ _x' ∂μ', False := by\n filter_upwards [hf0, hlt] with x' e1 e2\n simp only [Pi.zero_apply] at e1\n linarith\n rw [Filter.eventually_false_iff_eq_bot] at hfalse\n exact (ae_neBot.2 (IsProbabilityMeasure.ne_zero μ')).ne hfalse\n refine measure_mono_null hsub ?_\n rw [← ae_iff] at *\n exact hFae\n -- key lower bound on the inner integral\n have hkey : ∀ x ∈ S \\ A0, (1:ℝ≥0∞) ≤ ∫⁻ x', ENNReal.ofReal (g x x') ∂μ' := by\n intro x hx\n obtain ⟨hxS, hxA0⟩ := hx\n have hxS' : (∫ x', phi2 x x' ∂μ') + Real.sqrt (Av x * t) ≤ (∫ x', phi1 x x' ∂μ') := hxS\n have hu' : Real.sqrt (Av x * t) ≤ u x := by simp only [hudef]; linarith\n have hbig : t ≤ 4 * d x * (u x - d x * Av x) := by\n simp only [hddef]\n split_ifs with h1 h2\n · set q := Real.sqrt (t / Av x) with hq\n have hq0 : 0 ≤ q := Real.sqrt_nonneg _\n have hq2 : q ^ 2 = t / Av x := Real.sq_sqrt (by positivity)\n have hqq : q * Real.sqrt (Av x * t) = t := by\n rw [hq, ← Real.sqrt_mul (by positivity)]\n rw [show t / Av x * (Av x * t) = t ^ 2 by field_simp]\n exact Real.sqrt_sq ht\n have hq2' : q ^ 2 * Av x = t := by rw [hq2]; field_simp\n have hst : 0 ≤ Real.sqrt (Av x * t) := Real.sqrt_nonneg _\n nlinarith [mul_le_mul_of_nonneg_left hu' hq0]\n · have hAv0 : Av x = 0 := le_antisymm (not_lt.1 h1) (hAvnn x)\n have hune : u x ≠ 0 := ne_of_gt h2\n have hcalc : 4 * (t / (4 * u x)) * (u x - t / (4 * u x) * Av x) = t := by\n rw [hAv0]; field_simp; ring\n rw [hcalc]\n · exfalso\n have hAv0 : Av x = 0 := le_antisymm (not_lt.1 h1) (hAvnn x)\n have hu0 : u x = 0 := by\n have := not_lt.1 h2\n have hnn : 0 ≤ u x := by\n have : Real.sqrt (Av x * t) = 0 := by rw [hAv0, zero_mul, Real.sqrt_zero]\n linarith [hu', this.symm ▸ hu']\n linarith\n exact hxA0 ⟨hAv0, hu0⟩\n have hone : (1:ℝ) ≤ ∫ x', g x x' ∂μ' := by\n rw [hgintegral x]\n nlinarith [hγ.le, hbig]\n have hmax : Integrable (fun x' => max (g x x') 0) μ' := (hgint x).pos_part\n calc (1:ℝ≥0∞) = ENNReal.ofReal 1 := by simp\n _ ≤ ENNReal.ofReal (∫ x', g x x' ∂μ') := ENNReal.ofReal_le_ofReal hone\n _ ≤ ENNReal.ofReal (∫ x', max (g x x') 0 ∂μ') :=\n ENNReal.ofReal_le_ofReal (integral_mono (hgint x) hmax (fun x' => le_max_left _ _))\n _ = ∫⁻ x', ENNReal.ofReal (max (g x x') 0) ∂μ' :=\n ofReal_integral_eq_lintegral_ofReal hmax\n (Filter.Eventually.of_forall fun x' => le_max_right _ _)\n _ = ∫⁻ x', ENNReal.ofReal (g x x') ∂μ' := by simp only [ofReal_max_zero]\n -- tail bound\n have htail : ∀ r : ℝ, 0 < r →\n (μ.prod μ') {p : Ω × Ω' | r < g p.1 p.2}\n ≤ ENNReal.ofReal (Γ * Real.exp (-γ * t) * Real.exp (1 - r)) := by\n intro r hr\n set s : ℝ := t + (r - 1) / γ with hsdef\n have hgs : γ * s = γ * t + (r - 1) := by\n rw [hsdef]; field_simp\n have hexp : Γ * Real.exp (-γ * t) * Real.exp (1 - r) = Γ * Real.exp (-γ * s) := by\n rw [mul_assoc, ← Real.exp_add]\n congr 2\n linarith\n rcases lt_or_le s 0 with hs | hs\n · refine le_trans prob_le_one ?_\n rw [ENNReal.one_le_ofReal, hexp]\n have h1 : 0 < -γ * s := by nlinarith\n have := Real.add_one_le_exp (-γ * s)\n nlinarith\n · rw [hexp]\n refine le_trans (measure_mono ?_) (hyp s hs)\n intro p hp\n simp only [Set.mem_setOf_eq, hgdef] at hp\n simp only [Set.mem_setOf_eq, ge_iff_le]\n have hD := hdpos p.1\n have hgt : s < 4 * d p.1 * (phi1 p.1 p.2 - phi2 p.1 p.2 - d p.1 * phi3 p.1 p.2) := by\n have h2 : (r - 1) / γ\n < 4 * d p.1 * (phi1 p.1 p.2 - phi2 p.1 p.2 - d p.1 * phi3 p.1 p.2) - t :=\n (div_lt_iff₀ hγ).2 (by nlinarith [hp])\n rw [hsdef]; linarith\n have hstep : s / (4 * d p.1)\n < phi1 p.1 p.2 - phi2 p.1 p.2 - d p.1 * phi3 p.1 p.2 :=\n (div_lt_iff₀ (by positivity)).2 (by nlinarith [hgt])\n have := sqrt_amgm (hphi3_nonneg p.1 p.2) hs hD\n linarith\n -- integral bound over the product\n have hprodbound : ∫⁻ p, ENNReal.ofReal (g p.1 p.2) ∂(μ.prod μ')\n ≤ ENNReal.ofReal (Γ * Real.exp 1 * Real.exp (-γ * t)) := by\n have hnn : 0 ≤ᵐ[μ.prod μ'] (fun p : Ω × Ω' => max (g p.1 p.2) 0) :=\n Filter.Eventually.of_forall fun p => le_max_right _ _\n have hmb : AEMeasurable (fun p : Ω × Ω' => max (g p.1 p.2) 0) (μ.prod μ') :=\n (hgm.max measurable_const).aemeasurable\n have hlc := lintegral_eq_lintegral_meas_lt (μ.prod μ') hnn hmb\n have hrw : ∫⁻ p, ENNReal.ofReal (g p.1 p.2) ∂(μ.prod μ')\n = ∫⁻ r in Set.Ioi (0:ℝ), (μ.prod μ') {p : Ω × Ω' | r < max (g p.1 p.2) 0} := by\n rw [← hlc]\n simp only [ofReal_max_zero]\n rw [hrw]\n have hbound : ∫⁻ r in Set.Ioi (0:ℝ), (μ.prod μ') {p : Ω × Ω' | r < max (g p.1 p.2) 0}\n ≤ ∫⁻ r in Set.Ioi (0:ℝ),\n ENNReal.ofReal (Γ * Real.exp (-γ * t) * Real.exp 1 * Real.exp (-r)) := by\n refine lintegral_mono_ae ?_\n filter_upwards [self_mem_ae_restrict measurableSet_Ioi] with r hr\n have hr0 : (0:ℝ) < r := hr\n have hset : {p : Ω × Ω' | r < max (g p.1 p.2) 0} = {p : Ω × Ω' | r < g p.1 p.2} := by\n ext p\n simp only [Set.mem_setOf_eq, lt_max_iff]\n constructor\n · rintro (h | h); · exact h\n · exact absurd h (not_lt.2 hr0.le)\n · exact fun h => Or.inl h\n rw [hset]\n refine le_trans (htail r hr0) (le_of_eq ?_)\n have he : Real.exp (1 - r) = Real.exp 1 * Real.exp (-r) := by\n rw [← Real.exp_add]; ring_nf\n congr 1\n rw [he]; ring\n refine le_trans hbound ?_\n set C : ℝ := Γ * Real.exp (-γ * t) * Real.exp 1 with hC\n have hCnn : 0 ≤ C := by positivity\n have hInt : IntegrableOn (fun r : ℝ => C * Real.exp (-r)) (Set.Ioi (0:ℝ)) := by\n have := (exp_neg_integrableOn_Ioi (0:ℝ) (b := 1) one_pos)\n simpa using this.const_mul C\n have heq : ∫⁻ r in Set.Ioi (0:ℝ), ENNReal.ofReal (C * Real.exp (-r))\n = ENNReal.ofReal (∫ r in Set.Ioi (0:ℝ), C * Real.exp (-r)) := by\n rw [ofReal_integral_eq_lintegral_ofReal hInt\n (Filter.Eventually.of_forall fun r => by positivity)]\n rw [heq]\n have hval : (∫ r in Set.Ioi (0:ℝ), C * Real.exp (-r)) = C := by\n rw [integral_const_mul, integral_exp_neg_Ioi_zero, mul_one]\n rw [hval]\n apply ENNReal.ofReal_le_ofReal\n rw [hC]\n apply le_of_eq\n ring\n -- put everything together\n have hFmeas : Measurable fun x => ∫⁻ x', ENNReal.ofReal (g x x') ∂μ' := by\n have : Measurable (Function.uncurry fun x x' => ENNReal.ofReal (g x x')) := by\n exact ENNReal.measurable_ofReal.comp hgm\n exact this.lintegral_prod_right\n have hfinal : μ (S \\ A0) ≤ ENNReal.ofReal (Γ * Real.exp 1 * Real.exp (-γ * t)) := by\n have hSmeas : MeasurableSet S := by\n apply measurableSet_le\n · exact hmavg2.add (Real.continuous_sqrt.measurable.comp (hmavg3.mul_const t))\n · exact hmavg1\n have hdiff : MeasurableSet (S \\ A0) := hSmeas.diff hA0meas\n calc μ (S \\ A0) = ∫⁻ _x in (S \\ A0), 1 ∂μ := by\n rw [setLIntegral_one]\n _ ≤ ∫⁻ x in (S \\ A0), (∫⁻ x', ENNReal.ofReal (g x x') ∂μ') ∂μ := by\n refine setLIntegral_mono hFmeas ?_\n intro x hx\n exact hkey x hx\n _ ≤ ∫⁻ x, (∫⁻ x', ENNReal.ofReal (g x x') ∂μ') ∂μ := setLIntegral_le_lintegral _ _\n _ = ∫⁻ p, ENNReal.ofReal (g p.1 p.2) ∂(μ.prod μ') :=\n (lintegral_prod _ (ENNReal.measurable_ofReal.comp hgm).aemeasurable).symm\n _ ≤ _ := hprodbound\n calc μ S ≤ μ ((S \\ A0) ∪ A0) := by\n refine measure_mono ?_\n intro x hx\n by_cases h : x ∈ A0\n · exact Or.inr h\n · exact Or.inl ⟨hx, h⟩\n _ ≤ μ (S \\ A0) + μ A0 := measure_union_le _ _\n _ = μ (S \\ A0) := by rw [hnull, add_zero]\n _ ≤ _ := hfinal\n\nend GraduateLevel\n"} +{"id": "ch7_theorem_7_3", "source": "Graduate-level", "targets": [{"label": "ch7_theorem_7_3", "decls": ["ch7_theorem_7_3"], "statement": "Let \\(a_{1},\\cdots,a_{n}\\in\\mathbb{R},\\epsilon_{i},\\cdots,\\epsilon_{n}\\) be i.i.d. Rademacher random variables: \\(\\mathbb{P}(\\epsilon_{i}=1)=\\mathbb{P}(\\epsilon_{i}= -1)=0.5\\) and \\(0 < p < \\infty\\) . Then\n\\[A_{p}\\cdot\\left(\\sum_{i=1}^{n}\\left|a_{i}\\right|^{2}\\right)^{1/2}\\leq\\left(\\mathbb{E}\\left|\\sum_{i=1}^{n}a_{i}\\epsilon_{i}\\right|^{p}\\right)^{1/p}\\leq B_{p}\\cdot\\left(\\sum_{i=1}^{n}\\left|a_{i}\\right|^{2}\\right)^{1/2}\\]\nfor some constants \\(A_{p}\\) and \\(B_{p}\\) depending on p.", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "Let \\(\\sum\\left|a_{i}\\right|^{2}=1\\) without lossing generality. Then\n\\[\\begin{array}{ r c l }{\\displaystyle\\mathbb E\\left|\\sum a_{i}\\boldsymbol{\\epsilon}_{i}\\right|^{p}}&{=}&{\\displaystyle\\int_{0}^{\\infty}\\mathbb P\\left(\\left|\\sum a_{i}\\boldsymbol{\\epsilon}_{i}\\right|^{p}\\geq s^{p}\\right)~d s^{p}}\\\\ &{=}&{\\displaystyle\\int_{0}^{\\infty}\\mathbb P\\left(\\left|\\sum a_{i}\\boldsymbol{\\epsilon}_{i}\\right|\\geq s\\right)\\cdot p s^{p-1}~d s^{p}}\\\\ &{=}&{\\displaystyle\\int_{0}^{\\infty}\\mathbb P\\left(\\left|\\sum a_{i}\\boldsymbol{\\epsilon}_{i}\\right|\\geq s\\right)\\cdot p s^{p-1}~d s^{p}}\\\\ &{\\leq}&{\\displaystyle\\int_{0}^{\\infty}2\\exp(-\\frac{s^{2}}{2})\\cdot p s^{p-1}~d s^{p}~,~\\mathrm{Hoe}\\mathrm{f l d i n g's~i n e q u a l i t y}}\\\\ &{=}&{(B_{p})^{p}~,\\mathrm{when}~p\\geq 2 .}\\end{array}\\]\nWhen \\(0 < p < 2\\)\n\\[\\begin{array}{ r c l }{\\mathbb{E}\\left|\\sum a_{i}\\epsilon_{i}\\right|^{p}}&{\\leq}&{\\mathbb{E}\\left|\\sum a_{i}\\epsilon_{i}\\right|^{2}}\\\\ &{=}&{\\mathbb{E}\\left|\\sum a_{i}\\epsilon_{i}\\right|^{\\frac{2}{3}p+(2-\\frac{2}{3}p)}}\\\\ &{\\leq}&{\\left(\\mathbb{E}\\left|\\sum a_{i}\\epsilon_{i}\\right|^{p}\\right)^{\\frac{2}{3}}\\left(\\mathbb{E}\\left|\\sum a_{i}\\epsilon_{i}\\right|^{6-2 p}\\right)^{\\frac{1}{3}},\\mathrm{~H o l d e r's~i n e q u a l i t y}}\\\\ &{\\leq}&{\\left(B_{6-2 p}\\right)^{2-\\frac{2}{3}p}\\cdot\\left(\\mathbb{E}\\left|\\sum a_{i}\\epsilon_{i}\\right|^{p}\\right)^{\\frac{2}{3}}.}\\end{array}\\]\nThus \\(\\begin{array}{ r }{\\mathbb{E}\\left|\\sum a_{i}\\epsilon_{i}\\right|^{p}\\le\\left(B_{6-2 p}\\right)^{6-2 p}}\\end{array}\\) , completing the proof.", "context": [{"id": "ch7:theorem:7_1", "name": "theorem 7.1", "statement": "For \\(t \\geq 0\\)\n\\[\\mathbb{P}\\left(\\sum_{i=1}^{n}\\varepsilon_{i}a_{i}\\geq t\\right)\\leq\\exp\\left(-\\frac{t^{2}}{2\\sum_{i=1}^{n}a_{i}^{2}}\\right).\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ntheorem ch7_theorem_7_3 :\n ∀ p : ℝ, 0 < p →\n ∃ Ap Bp : ℝ, 0 < Ap ∧ 0 < Bp ∧\n ∀ (n : ℕ) {Ω : Type} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (ε : Fin n → Ω → ℝ)\n (_hindep : iIndepFun ε μ)\n (_hmeas : ∀ i, AEMeasurable (ε i) μ)\n (_hrad : ∀ i, μ {ω | ε i ω = 1} = 1/2 ∧ μ {ω | ε i ω = -1} = 1/2)\n (a : Fin n → ℝ),\n Ap * (∑ i, (a i)^2) ^ ((1:ℝ)/2)\n ≤ (∫ ω, |∑ i, a i * ε i ω| ^ p ∂μ) ^ (1/p)\n ∧ (∫ ω, |∑ i, a i * ε i ω| ^ p ∂μ) ^ (1/p)\n ≤ Bp * (∑ i, (a i)^2) ^ ((1:ℝ)/2) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped NNReal ENNReal\n\nnamespace GraduateLevel\n\nprivate lemma rpow_le_const_mul_exp {p t : ℝ} (hp : 0 < p) (ht : 0 ≤ t) :\n t ^ p ≤ (p / Real.exp 1) ^ p * Real.exp t := by\n have hpe : (0:ℝ) < p / Real.exp 1 := by positivity\n rcases eq_or_lt_of_le ht with h | h\n · rw [← h, Real.zero_rpow hp.ne']\n positivity\n · rw [Real.rpow_def_of_pos h, Real.rpow_def_of_pos hpe, ← Real.exp_add]\n apply Real.exp_le_exp.2\n have hkey : Real.log (t / p) ≤ t / p - 1 := Real.log_le_sub_one_of_pos (by positivity)\n rw [Real.log_div h.ne' hp.ne'] at hkey\n have hlp : Real.log (p / Real.exp 1) = Real.log p - 1 := by\n rw [Real.log_div hp.ne' (Real.exp_ne_zero 1), Real.log_exp]\n rw [hlp]\n have h4 := mul_le_mul_of_nonneg_right hkey hp.le\n have h6 : (t / p - 1) * p = t - p := by field_simp\n rw [h6] at h4\n nlinarith [h4]\n\nprivate lemma abs_rpow_integrable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω)\n [IsProbabilityMeasure μ] (S : Ω → ℝ) (c : NNReal) (hs : HasSubgaussianMGF S c μ)\n (q : ℝ) (hq : 0 < q) : Integrable (fun ω => |S ω| ^ q) μ := by\n have hqn : ((q.toNNReal : ℝ≥0) : ℝ≥0∞) ≠ 0 := by\n simp only [ne_eq, ENNReal.coe_eq_zero, Real.toNNReal_eq_zero, not_le]\n exact hq\n have h := (hs.memLp q.toNNReal).integrable_norm_rpow hqn (by simp)\n simpa [Real.coe_toNNReal _ hq.le, Real.norm_eq_abs] using h\n\nprivate lemma moment_ub {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (S : Ω → ℝ) (c : NNReal) (hs : HasSubgaussianMGF S c μ) (q : ℝ) (hq : 0 < q) :\n ∫ ω, |S ω| ^ q ∂μ ≤ 2 * Real.exp (q / 2) * (Real.sqrt q * Real.sqrt c / Real.exp 1) ^ q := by\n have hqLHSint : Integrable (fun ω => |S ω| ^ q) μ := by\n have hqn : ((q.toNNReal : ℝ≥0) : ℝ≥0∞) ≠ 0 := by\n simp only [ne_eq, ENNReal.coe_eq_zero, Real.toNNReal_eq_zero, not_le]\n exact hq\n have h := (hs.memLp q.toNNReal).integrable_norm_rpow hqn (by simp)\n simpa [Real.coe_toNNReal _ hq.le, Real.norm_eq_abs] using h\n rcases eq_or_lt_of_le (zero_le c) with hc | hc\n · have hc0 : c = 0 := hc.symm\n subst hc0\n have h0 : S =ᵐ[μ] 0 := hs.ae_eq_zero_of_hasSubgaussianMGF_zero\n have : ∫ ω, |S ω| ^ q ∂μ = 0 := by\n rw [integral_congr_ae (g := fun _ => (0:ℝ)) ?_]\n · simp\n · filter_upwards [h0] with ω hω\n simp [hω, Real.zero_rpow hq.ne']\n rw [this]\n positivity\n · have hcR : (0:ℝ) < (c:ℝ) := hc\n set lam : ℝ := Real.sqrt q / Real.sqrt c with hlamdef\n have hsq : (0:ℝ) < Real.sqrt q := Real.sqrt_pos.2 hq\n have hsc : (0:ℝ) < Real.sqrt c := Real.sqrt_pos.2 hcR\n have hlam : 0 < lam := by positivity\n set K : ℝ := (q / (Real.exp 1 * lam)) ^ q with hK\n have hKpos : 0 < K := by\n have : (0:ℝ) < q / (Real.exp 1 * lam) := by positivity\n exact Real.rpow_pos_of_pos this q\n have hb : ∀ ω, |S ω| ^ q ≤ K * (Real.exp (lam * S ω) + Real.exp ((-lam) * S ω)) := by\n intro ω\n have h1 := rpow_le_const_mul_exp (p := q) (t := lam * |S ω|) hq (by positivity)\n have h2 : (lam * |S ω|) ^ q = lam ^ q * |S ω| ^ q := by\n rw [Real.mul_rpow hlam.le (abs_nonneg _)]\n have hexp : Real.exp (lam * |S ω|) ≤ Real.exp (lam * S ω) + Real.exp ((-lam) * S ω) := by\n rcases abs_cases (S ω) with ⟨he, _⟩ | ⟨he, _⟩\n · rw [he]\n have : (0:ℝ) < Real.exp ((-lam) * S ω) := Real.exp_pos _\n linarith\n · rw [he]\n have : (0:ℝ) < Real.exp (lam * S ω) := Real.exp_pos _\n have : lam * -S ω = (-lam) * S ω := by ring\n rw [this]\n have := Real.exp_pos (lam * S ω)\n linarith\n have hKeq : K * lam ^ q = (q / Real.exp 1) ^ q := by\n rw [hK, ← Real.mul_rpow (by positivity) hlam.le]\n congr 1\n field_simp\n have hlamq : (0:ℝ) < lam ^ q := Real.rpow_pos_of_pos hlam q\n rw [h2] at h1\n have h3 : lam ^ q * |S ω| ^ q ≤ (q / Real.exp 1) ^ q *\n (Real.exp (lam * S ω) + Real.exp ((-lam) * S ω)) := by\n refine h1.trans ?_\n exact mul_le_mul_of_nonneg_left hexp (by positivity)\n rw [← hKeq] at h3\n nlinarith [h3, hlamq]\n have hRint : Integrable\n (fun ω => K * (Real.exp (lam * S ω) + Real.exp ((-lam) * S ω))) μ :=\n ((hs.integrable_exp_mul lam).add (hs.integrable_exp_mul (-lam))).const_mul K\n have hmono := integral_mono hqLHSint hRint hb\n have hval : ∫ ω, K * (Real.exp (lam * S ω) + Real.exp ((-lam) * S ω)) ∂μ\n ≤ K * (2 * Real.exp (q / 2)) := by\n rw [integral_const_mul,\n integral_add (hs.integrable_exp_mul lam) (hs.integrable_exp_mul (-lam))]\n have h1 : mgf S μ lam ≤ Real.exp (c * lam ^ 2 / 2) := hs.mgf_le lam\n have h2 : mgf S μ (-lam) ≤ Real.exp (c * (-lam) ^ 2 / 2) := hs.mgf_le (-lam)\n have hclam : (c:ℝ) * lam ^ 2 / 2 = q / 2 := by\n rw [hlamdef]\n rw [div_pow, Real.sq_sqrt hq.le, Real.sq_sqrt hcR.le]\n field_simp\n have : ∫ ω, Real.exp (lam * S ω) ∂μ + ∫ ω, Real.exp ((-lam) * S ω) ∂μ\n ≤ 2 * Real.exp (q / 2) := by\n have e1 : ∫ ω, Real.exp (lam * S ω) ∂μ = mgf S μ lam := rfl\n have e2 : ∫ ω, Real.exp ((-lam) * S ω) ∂μ = mgf S μ (-lam) := rfl\n rw [e1, e2]\n have : (c:ℝ) * (-lam) ^ 2 / 2 = q / 2 := by rw [neg_pow]; simpa using hclam\n rw [hclam] at h1\n rw [this] at h2\n linarith\n exact mul_le_mul_of_nonneg_left this hKpos.le\n have hfin : K * (2 * Real.exp (q / 2))\n = 2 * Real.exp (q / 2) * (Real.sqrt q * Real.sqrt c / Real.exp 1) ^ q := by\n rw [hK]\n have : q / (Real.exp 1 * lam) = Real.sqrt q * Real.sqrt c / Real.exp 1 := by\n rw [hlamdef]\n have hq' : q = Real.sqrt q * Real.sqrt q := (Real.mul_self_sqrt hq.le).symm\n field_simp\n nlinarith [hq', hsq, hsc]\n rw [this]; ring\n linarith [hmono, hval, hfin.le, hfin.ge]\n\ntheorem ch7_theorem_7_3 :\n ∀ p : ℝ, 0 < p →\n ∃ Ap Bp : ℝ, 0 < Ap ∧ 0 < Bp ∧\n ∀ (n : ℕ) {Ω : Type} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (ε : Fin n → Ω → ℝ)\n (_hindep : iIndepFun ε μ)\n (_hmeas : ∀ i, AEMeasurable (ε i) μ)\n (_hrad : ∀ i, μ {ω | ε i ω = 1} = 1/2 ∧ μ {ω | ε i ω = -1} = 1/2)\n (a : Fin n → ℝ),\n Ap * (∑ i, (a i)^2) ^ ((1:ℝ)/2)\n ≤ (∫ ω, |∑ i, a i * ε i ω| ^ p ∂μ) ^ (1/p)\n ∧ (∫ ω, |∑ i, a i * ε i ω| ^ p ∂μ) ^ (1/p)\n ≤ Bp * (∑ i, (a i)^2) ^ ((1:ℝ)/2) := by\n intro p hp\n set C : ℝ := 32 / Real.exp 2 with hCdef\n have hCpos : (0:ℝ) < C := by rw [hCdef]; positivity\n refine ⟨(1/(8*C)) ^ (1/p) / 2, 2 ^ (1/p) * Real.exp (1/2) * Real.sqrt p / Real.exp 1,\n by positivity, by positivity, ?_⟩\n intro n Ω _ μ _ ε hindep hmeas hrad a\n set σ2 : ℝ := ∑ i, (a i)^2 with hσ2\n have hσ2nn : (0:ℝ) ≤ σ2 := Finset.sum_nonneg fun i _ => sq_nonneg _\n have hrad' : ∀ i, (∀ᵐ ω ∂μ, ε i ω = 1 ∨ ε i ω = -1) ∧ ∫ ω, ε i ω ∂μ = 0 := by\n intro i\n obtain ⟨h1, h2⟩ := hrad i\n have hA0 : NullMeasurableSet {ω | ε i ω = 1} μ :=\n (hmeas i).nullMeasurable (measurableSet_singleton (1:ℝ))\n have hB0 : NullMeasurableSet {ω | ε i ω = -1} μ :=\n (hmeas i).nullMeasurable (measurableSet_singleton (-1:ℝ))\n have hinter : ({ω | ε i ω = 1} ∩ {ω | ε i ω = -1}) = (∅ : Set Ω) := by\n ext ω\n simp only [Set.mem_inter_iff, Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]\n rintro ⟨ha, hb⟩\n rw [ha] at hb; norm_num at hb\n have hdisj : AEDisjoint μ {ω | ε i ω = 1} {ω | ε i ω = -1} := by\n show μ ({ω | ε i ω = 1} ∩ {ω | ε i ω = -1}) = 0\n rw [hinter, measure_empty]\n have hun : μ ({ω | ε i ω = 1} ∪ {ω | ε i ω = -1}) = 1 := by\n rw [measure_union₀ hB0 hdisj, h1, h2]\n rw [ENNReal.div_add_div_same,\n show (1:ℝ≥0∞) + 1 = 2 by norm_num, ENNReal.div_self (by norm_num) (by norm_num)]\n have hcompl : μ ({ω | ε i ω = 1} ∪ {ω | ε i ω = -1})ᶜ = 0 := by\n rw [measure_compl₀ (hA0.union hB0) (measure_ne_top _ _), hun, measure_univ]\n simp\n have hae : ∀ᵐ ω ∂μ, ε i ω = 1 ∨ ε i ω = -1 := by\n rw [ae_iff]\n refine measure_mono_null ?_ hcompl\n intro ω hω\n simp only [Set.mem_setOf_eq, not_or] at hω\n simp only [Set.mem_compl_iff, Set.mem_union, Set.mem_setOf_eq, not_or]\n exact ⟨hω.1, hω.2⟩\n refine ⟨hae, ?_⟩\n set A := toMeasurable μ {ω | ε i ω = 1} with hAdef\n have hAm : MeasurableSet A := measurableSet_toMeasurable _ _\n have hAmeas : μ A = 1/2 := by rw [hAdef, measure_toMeasurable, h1]\n have hAeq : A =ᵐ[μ] {ω | ε i ω = 1} := (hA0.toMeasurable_ae_eq)\n have hAeq' : ∀ᵐ ω ∂μ, (ω ∈ A ↔ ω ∈ {ω | ε i ω = 1}) := Filter.eventuallyEq_set.1 hAeq\n have hfeq : ε i =ᵐ[μ] fun ω => 2 * A.indicator (fun _ => (1:ℝ)) ω - 1 := by\n filter_upwards [hae, hAeq'] with ω hω hiff\n rcases hω with h | h\n · have hmem : ω ∈ A := hiff.2 h\n rw [h, Set.indicator_of_mem hmem]\n norm_num\n · have hnA : ω ∉ A := by\n intro hmem\n have h5 := hiff.1 hmem\n simp only [Set.mem_setOf_eq] at h5\n rw [h] at h5; norm_num at h5\n rw [h, Set.indicator_of_notMem hnA]\n norm_num\n have hAreal : μ.real A = 1/2 := by\n rw [measureReal_def, hAmeas]\n simp\n rw [integral_congr_ae hfeq,\n integral_sub (((integrable_const (1:ℝ)).indicator hAm).const_mul 2) (integrable_const _),\n integral_const_mul, integral_indicator_const (1:ℝ) hAm]\n simp [hAreal]\n set X : Fin n → Ω → ℝ := fun i ω => a i * ε i ω with hXdef\n have hindX : iIndepFun X μ :=\n hindep.comp (fun (i : Fin n) (x : ℝ) => a i * x) (fun i => measurable_const_mul (a i))\n have hsubX : ∀ i, HasSubgaussianMGF (X i) (((a i)^2).toNNReal) μ := by\n intro i\n have hbdd : ∀ᵐ ω ∂μ, X i ω ∈ Set.Icc (-|a i|) (|a i|) := by\n filter_upwards [(hrad' i).1] with ω hω\n have h1 : -|a i| ≤ a i := neg_abs_le (a i)\n have h2 : a i ≤ |a i| := le_abs_self (a i)\n rcases hω with h | h\n · simp only [hXdef, h, mul_one, Set.mem_Icc]\n exact ⟨h1, h2⟩\n · simp only [hXdef, h, mul_neg_one, Set.mem_Icc]\n constructor <;> linarith\n have hint : ∫ ω, X i ω ∂μ = 0 := by\n simp only [hXdef]\n rw [integral_const_mul, (hrad' i).2, mul_zero]\n have hmain := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero\n (X := X i) (μ := μ) ((hmeas i).const_mul (a i)) hbdd hint\n have hceq : ((‖|a i| - -|a i|‖₊ / 2) ^ 2 : ℝ≥0) = ((a i)^2).toNNReal := by\n apply NNReal.coe_injective\n push_cast\n rw [Real.coe_toNNReal _ (sq_nonneg _), sub_neg_eq_add, ← two_mul,\n Real.norm_eq_abs, abs_of_nonneg (by positivity : (0:ℝ) ≤ 2 * |a i|),\n show (2 * |a i|)/2 = |a i| by ring, sq_abs]\n rwa [hceq] at hmain\n have hsumc : ∑ i, ((a i)^2).toNNReal = σ2.toNNReal := by\n rw [hσ2, Real.toNNReal_sum_of_nonneg (fun i _ => sq_nonneg _)]\n have hsubS0 : HasSubgaussianMGF (fun ω => ∑ i, X i ω) σ2.toNNReal μ := by\n have := HasSubgaussianMGF.sum_of_iIndepFun (X := X) (s := Finset.univ) hindX\n (fun i _ => hsubX i)\n rwa [hsumc] at this\n obtain ⟨S, hSm, hSeq⟩ := hsubS0.aemeasurable\n have hsubS : HasSubgaussianMGF S σ2.toNNReal μ := hsubS0.congr hSeq\n have hMeq : ∫ ω, |∑ i, a i * ε i ω| ^ p ∂μ = ∫ ω, |S ω| ^ p ∂μ := by\n refine integral_congr_ae ?_\n filter_upwards [hSeq] with ω hω\n simp only [hXdef] at hω\n rw [hω]\n have hcoeσ : ((σ2.toNNReal : ℝ≥0) : ℝ) = σ2 := Real.coe_toNNReal _ hσ2nn\n have hsqrtσ : (σ2) ^ ((1:ℝ)/2) = Real.sqrt σ2 := (Real.sqrt_eq_rpow σ2).symm\n have hmemX : ∀ i, MemLp (X i) 2 μ := fun i => by simpa using (hsubX i).memLp 2\n have hmemS : MemLp S 2 μ := by simpa using hsubS.memLp 2\n have hintX : ∀ i, ∫ ω, X i ω ∂μ = 0 := by\n intro i\n simp only [hXdef]\n rw [integral_const_mul, (hrad' i).2, mul_zero]\n have hvarX : ∀ i, Var[X i; μ] = (a i)^2 := by\n intro i\n rw [variance_eq_sub (hmemX i)]\n have h2 : μ[(X i)^2] = (a i)^2 := by\n have hae2 : ∀ᵐ ω ∂μ, ((X i)^2) ω = (a i)^2 := by\n filter_upwards [(hrad' i).1] with ω hω\n rcases hω with h | h <;> simp only [Pi.pow_apply, hXdef, h] <;> ring\n rw [integral_congr_ae hae2]\n simp\n rw [h2, hintX i]\n ring\n have hpair : Set.Pairwise (↑(Finset.univ : Finset (Fin n)))\n (fun i j => IndepFun (X i) (X j) μ) := fun i _ j _ hij => hindX.indepFun hij\n have hSeq' : S =ᵐ[μ] ∑ i, X i := by\n filter_upwards [hSeq] with ω hω\n rw [← hω]\n simp [hXdef]\n have hvarS : Var[S; μ] = σ2 := by\n rw [variance_congr hSeq', IndepFun.variance_sum (fun i _ => hmemX i) hpair]\n simp [hvarX, hσ2]\n have hES : μ[S] = 0 := by\n rw [integral_congr_ae hSeq',\n show (∑ i, X i) = fun ω => ∑ i, X i ω by funext ω; simp,\n integral_finset_sum _ (fun i _ => (hsubX i).integrable)]\n simp [hintX]\n have hES2 : ∫ ω, (S ω)^2 ∂μ = σ2 := by\n have h := variance_eq_sub hmemS\n rw [hvarS, hES] at h\n simp only [Pi.pow_apply] at h\n simpa using h.symm\n have hub : ∀ q : ℝ, 0 < q → ∫ ω, |S ω| ^ q ∂μ\n ≤ 2 * Real.exp (q/2) * (Real.sqrt q * Real.sqrt σ2 / Real.exp 1) ^ q := by\n intro q hq\n have h := moment_ub μ S σ2.toNNReal hsubS q hq\n rwa [hcoeσ] at h\n have h4eq : ∀ ω, ((S ω)^2)^2 = |S ω| ^ (4:ℝ) := by\n intro ω\n rw [show (4:ℝ) = ((4:ℕ):ℝ) by norm_num, Real.rpow_natCast, ← sq_abs (S ω)]\n ring\n have h2eq : ∀ ω, (S ω)^2 = |S ω| ^ (2:ℝ) := by\n intro ω\n rw [show (2:ℝ) = ((2:ℕ):ℝ) by norm_num, Real.rpow_natCast, sq_abs]\n have hI2 : Integrable (fun ω => (S ω)^2) μ := by\n refine (abs_rpow_integrable μ S σ2.toNNReal hsubS 2 (by norm_num)).congr ?_\n exact Filter.Eventually.of_forall (fun ω => (h2eq ω).symm)\n have hI4 : Integrable (fun ω => ((S ω)^2)^2) μ := by\n refine (abs_rpow_integrable μ S σ2.toNNReal hsubS 4 (by norm_num)).congr ?_\n exact Filter.Eventually.of_forall (fun ω => (h4eq ω).symm)\n have hIp : Integrable (fun ω => |S ω| ^ p) μ := abs_rpow_integrable μ S σ2.toNNReal hsubS p hp\n have hE4 : ∫ ω, ((S ω)^2)^2 ∂μ ≤ C * σ2^2 := by\n have h := hub 4 (by norm_num)\n have hval : 2 * Real.exp ((4:ℝ)/2) * (Real.sqrt 4 * Real.sqrt σ2 / Real.exp 1) ^ (4:ℝ)\n = C * σ2^2 := by\n rw [show (4:ℝ)/2 = 2 by norm_num,\n show Real.sqrt 4 = 2 by\n rw [show (4:ℝ) = 2^2 by norm_num, Real.sqrt_sq (by norm_num)],\n show (4:ℝ) = ((4:ℕ):ℝ) by norm_num, Real.rpow_natCast, hCdef, div_pow, mul_pow,\n Real.exp_one_pow,\n show Real.sqrt σ2 ^ (4:ℕ) = σ2^2 by\n rw [show (4:ℕ) = 2*2 by norm_num, pow_mul, Real.sq_sqrt hσ2nn],\n show Real.exp ((4:ℕ):ℝ) = Real.exp 2 * Real.exp 2 by\n rw [← Real.exp_add]; norm_num]\n have := Real.exp_pos 2\n field_simp\n ring\n calc ∫ ω, ((S ω)^2)^2 ∂μ = ∫ ω, |S ω| ^ (4:ℝ) ∂μ :=\n integral_congr_ae (Filter.Eventually.of_forall (fun ω => h4eq ω))\n _ ≤ _ := h\n _ = C * σ2^2 := hval\n rw [hMeq, hsqrtσ]\n set M : ℝ := ∫ ω, |S ω| ^ p ∂μ with hMdef\n have hMnn : (0:ℝ) ≤ M := integral_nonneg (fun ω => Real.rpow_nonneg (abs_nonneg _) _)\n constructor\n · rcases eq_or_lt_of_le hσ2nn with h0 | hpos\n · rw [← h0, Real.sqrt_zero, mul_zero]\n positivity\n · set T : Set Ω := {ω | σ2/4 ≤ (S ω)^2} with hTdef\n have hTm : MeasurableSet T := measurableSet_le measurable_const (hSm.pow_const 2)\n set b : ℝ := 4 * C * σ2 with hbdef\n have hbpos : (0:ℝ) < b := by positivity\n have hpt : ∀ ω, (S ω)^2 ≤ σ2/4 + b * T.indicator (fun _ => (1:ℝ)) ω\n + ((S ω)^2)^2 / b := by\n intro ω\n rcases lt_or_ge ((S ω)^2) (σ2/4) with h | h\n · have hb1 : (0:ℝ) ≤ b * T.indicator (fun _ => (1:ℝ)) ω :=\n mul_nonneg hbpos.le (Set.indicator_nonneg (fun _ _ => by norm_num) ω)\n have hb2 : (0:ℝ) ≤ ((S ω)^2)^2 / b := by positivity\n linarith\n · have hmem : ω ∈ T := h\n rw [Set.indicator_of_mem hmem, mul_one]\n rcases le_or_gt ((S ω)^2) b with h2 | h2\n · have hb2 : (0:ℝ) ≤ ((S ω)^2)^2 / b := by positivity\n have hb3 : (0:ℝ) ≤ σ2/4 := by positivity\n linarith\n · have h4 : (S ω)^2 ≤ ((S ω)^2)^2/b := by\n rw [le_div_iff₀ hbpos]\n nlinarith [sq_nonneg (S ω)]\n have hb3 : (0:ℝ) ≤ σ2/4 := by positivity\n linarith\n have hIind : Integrable (fun ω => b * T.indicator (fun _ => (1:ℝ)) ω) μ :=\n ((integrable_const (1:ℝ)).indicator hTm).const_mul b\n have hIrhs : Integrable (fun ω => σ2/4 + b * T.indicator (fun _ => (1:ℝ)) ω\n + ((S ω)^2)^2 / b) μ :=\n ((integrable_const _).add hIind).add (hI4.div_const b)\n have hmono := integral_mono hI2 hIrhs (fun ω => hpt ω)\n rw [hES2] at hmono\n have hRHS : ∫ ω, (σ2/4 + b * T.indicator (fun _ => (1:ℝ)) ω + ((S ω)^2)^2 / b) ∂μ\n = σ2/4 + b * μ.real T + (∫ ω, ((S ω)^2)^2 ∂μ)/b := by\n rw [integral_add (f := fun ω => σ2/4 + b * T.indicator (fun _ => (1:ℝ)) ω)\n (g := fun ω => ((S ω)^2)^2 / b) ((integrable_const _).add hIind)\n (hI4.div_const b),\n integral_add (f := fun _ => σ2/4) (g := fun ω => b * T.indicator (fun _ => (1:ℝ)) ω)\n (integrable_const _) hIind,\n integral_const, integral_const_mul, integral_indicator_const (1:ℝ) hTm,\n integral_div]\n simp\n rw [hRHS] at hmono\n have hE4b : (∫ ω, ((S ω)^2)^2 ∂μ) / b ≤ σ2/4 := by\n rw [div_le_iff₀ hbpos, hbdef]\n nlinarith [hE4, hCpos, hpos]\n have hP : (1:ℝ)/(8*C) ≤ μ.real T := by\n have hbP : σ2/2 ≤ b * μ.real T := by linarith\n rw [hbdef] at hbP\n rw [div_le_iff₀ (by positivity)]\n nlinarith [hbP, hCpos, hpos]\n have hptlow : ∀ ω, (Real.sqrt σ2/2) ^ p * T.indicator (fun _ => (1:ℝ)) ω ≤ |S ω| ^ p := by\n intro ω\n by_cases hmem : ω ∈ T\n · rw [Set.indicator_of_mem hmem, mul_one]\n refine Real.rpow_le_rpow (by positivity) ?_ hp.le\n have h1 : σ2/4 ≤ (S ω)^2 := hmem\n have h2 : Real.sqrt (σ2/4) ≤ Real.sqrt ((S ω)^2) := Real.sqrt_le_sqrt h1\n rw [Real.sqrt_sq_eq_abs] at h2\n have h3 : Real.sqrt (σ2/4) = Real.sqrt σ2 / 2 := by\n rw [show σ2/4 = σ2 * (1/2)^2 by ring, Real.sqrt_mul hσ2nn,\n Real.sqrt_sq (by norm_num : (0:ℝ) ≤ 1/2)]\n ring\n rw [h3] at h2\n exact h2\n · rw [Set.indicator_of_notMem hmem, mul_zero]\n positivity\n have hlowM : (Real.sqrt σ2/2) ^ p * (1/(8*C)) ≤ M := by\n have hIL : Integrable\n (fun ω => (Real.sqrt σ2/2) ^ p * T.indicator (fun _ => (1:ℝ)) ω) μ :=\n ((integrable_const (1:ℝ)).indicator hTm).const_mul _\n have hI := integral_mono hIL hIp hptlow\n rw [integral_const_mul, integral_indicator_const (1:ℝ) hTm] at hI\n simp only [smul_eq_mul, mul_one] at hI\n have hcoef : (0:ℝ) ≤ (Real.sqrt σ2/2) ^ p := Real.rpow_nonneg (by positivity) _\n calc (Real.sqrt σ2/2) ^ p * (1/(8*C)) ≤ (Real.sqrt σ2/2)^p * μ.real T :=\n mul_le_mul_of_nonneg_left hP hcoef\n _ ≤ M := hI\n have hfinal := Real.rpow_le_rpow (by positivity) hlowM\n (le_of_lt (by positivity : (0:ℝ) < 1/p))\n refine le_trans (le_of_eq ?_) hfinal\n rw [Real.mul_rpow (by positivity) (by positivity), ← Real.rpow_mul (by positivity),\n mul_one_div_cancel hp.ne', Real.rpow_one]\n ring\n · have hupper : M ^ (1/p) ≤ 2 ^ (1/p) * Real.exp (1/2) * Real.sqrt p / Real.exp 1\n * Real.sqrt σ2 := by\n have h1 : M ^ (1/p)\n ≤ (2 * Real.exp (p/2) * (Real.sqrt p * Real.sqrt σ2 / Real.exp 1) ^ p) ^ (1/p) :=\n Real.rpow_le_rpow hMnn (hub p hp) (by positivity)\n refine h1.trans_eq ?_\n rw [Real.mul_rpow (by positivity) (by positivity),\n Real.mul_rpow (by positivity) (by positivity),\n ← Real.rpow_mul (by positivity), mul_one_div_cancel hp.ne', Real.rpow_one,\n ← Real.exp_mul, show p/2 * (1/p) = 1/2 by field_simp]\n field_simp\n exact hupper\n\nend GraduateLevel\n"} +{"id": "ch10_lemma_10_1", "source": "Graduate-level", "targets": [{"label": "ch10_lemma_10_1", "decls": ["ch10_lemma_10_1"], "statement": "If \\(t\\geq{\\sqrt{\\frac{2}{n}}}.\\) then\n\\[\\mathbb{P}\\left(\\operatorname*{sup}_{C\\in\\mathcal{C}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\mathbb{P}\\left(C\\right)\\right|\\geq t\\right)\\leq 2\\mathbb{P}\\left(\\operatorname*{sup}_{C\\in\\mathcal{C}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C)\\right|\\geq t/2\\right).\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Suppose the event\n\\[\\operatorname*{sup}_{C\\in{\\mathcal{C}}}\\left|{\\frac{1}{n}}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\mathbb{P}\\left(C\\right)\\right|\\geq t\\]\noccurs.Let \\(\\begin{array}{ r }{X=(X_{1},\\ldots,X_{n})\\in\\{\\operatorname*{sup}_{C\\in\\mathcal{C}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\mathbb{P}\\left(C\\right)\\right|\\geq t\\}}\\end{array}\\) . Then\n\\[\\exists C_{X}{\\mathrm{~s u c h~t h a t~}}\\left|{\\frac{1}{n}}\\sum_{i=1}^{n}I(X_{i}\\in C_{X})-\\mathbb{P}\\left(C_{X}\\right)\\right|\\geq t .\\]\nFor a fixed C,\n\\[\\begin{array}{ r }{\\mathbb{P}_{X^{\\prime}}\\left(\\left|\\displaystyle\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in\\mathcal{C})-\\mathbb{P}(\\mathcal{C})\\right|\\geq t/2\\right)=\\mathbb{P}\\left(\\left(\\displaystyle\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in\\mathcal{C})-\\mathbb{P}(\\mathcal{C})\\right)^{2}\\geq t^{2}/4\\right)}\\\\ {\\leq\\mathrm{~(b y~C h e b y s h e v~s~I n e q)~}\\frac{4\\mathbb{E}\\left(\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in\\mathcal{C})-\\mathbb{P}(\\mathcal{C})\\right)^{2}}{t^{2}}}\\\\ {=\\frac{4}{n^{2}t^{2}}\\displaystyle\\sum_{i,j}\\mathbb{E}(I(X_{i}^{\\prime}\\in\\mathcal{C})-\\mathbb{P}(\\mathcal{C}))(I(X_{j}^{\\prime}\\in\\mathcal{C})-\\mathbb{P}(\\mathcal{C}))}\\\\ {=\\frac{4}{n^{2}t^{2}}\\displaystyle\\sum_{i=1}^{n}\\mathbb{E}(I(X_{i}^{\\prime}\\in\\mathcal{C})-\\mathbb{P}(\\mathcal{C}))^{2}=\\frac{4 n\\mathbb{P}\\left(\\mathcal{C}\\right)\\left(1-\\mathbb{P}(\\mathcal{C})\\right)}{n^{2}t^{2}}\\leq\\frac{1}{n t^{2}}\\leq\\frac{1}{2}}\\end{array}\\]\nsince we chose \\(t\\geq\\sqrt{\\textstyle{\\frac{2}{n}}}.\\)\nSo,\n\\[\\mathbb{P}_{X^{\\prime}}\\left(\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C_{X})-\\mathbb{P}\\left(C_{X}\\right)\\right|\\leq t/2\\Bigg|\\exists C_{X}\\right)\\geq 1/2\\]\nif \\(t\\geq\\sqrt{2/n}\\) .Assume that the event\n\\[\\left|{\\frac{1}{n}}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C_{X})-\\mathbb{P}\\left(C_{X}\\right)\\right|\\leq t/2\\]\noccurs. Recall that\n\\[\\left|{\\frac{1}{n}}\\sum_{i=1}^{n}I(X_{i}\\in C_{X})-\\mathbb{P}\\left(C_{X}\\right)\\right|\\geq t .\\]\nHence,it must be that\n\\[\\left|{\\frac{1}{n}}\\sum_{i=1}^{n}I(X_{i}\\in C_{X})-{\\frac{1}{n}}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C_{X})\\right|\\geq t/2 .\\]\nWe conclude\n\\[\\begin{array}{ r c l }{\\displaystyle\\frac 12}&{\\le}&{\\displaystyle\\mathbb{P}_{X^{\\prime}}\\left(\\left|\\frac 1n\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C_{X})-\\mathbb{P}(C_{X})\\right|\\le t/2\\Bigg|\\exists C_{X}\\right)}\\\\ &{\\le}&{\\displaystyle\\mathbb{P}_{X^{\\prime}}\\left(\\left|\\frac 1n\\sum_{i=1}^{n}I(X_{i}\\in C_{X})-\\frac 1n\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C_{X})\\right|\\ge t/2\\Bigg|\\exists C_{X}\\right)}\\\\ &&{\\displaystyle\\mathbb{P}_{X^{\\prime}}\\left(\\displaystyle\\operatorname*{sup}_{C\\in\\mathcal{C}}\\left|\\frac 1n\\sum_{i=1}^{n}I(X_{i}\\in C)-\\frac 1n\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C)\\right|\\ge t/2\\Bigg|\\exists C_{X}\\right).}\\end{array}\\]\nSince indicators are 0,1-valued,\n\\[\\begin{array}{ r l r }&{}&{\\displaystyle\\frac{1}{2}I\\left(\\underbrace{\\operatorname*{sup}_{C\\in{\\mathcal C}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\mathbb{P}(C)\\right|\\ge t}_{\\exists C_{X}}\\right)}\\\\ &{}&{\\displaystyle\\le\\mathbb{P}_{X^{\\prime}}\\left(\\underset{C\\in{\\mathcal C}}{\\operatorname*{sup}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C)\\right|\\ge t/2\\Bigg|\\exists C_{X}\\right)\\cdot I\\left(\\exists C_{X}\\right)}\\\\ &{}&{\\displaystyle\\le\\mathbb{P}_{X,X^{\\prime}}\\left(\\underset{C\\in{\\mathcal C}}{\\operatorname*{sup}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C)\\right|\\ge t/2\\right).}\\end{array}\\]\nNow, take expectation with respect to \\(X_{i}\\)'s to obtain\n\\[\\begin{array}{ r l r }&{}&{\\mathbb{P}_{X}\\left(\\displaystyle\\operatorname*{sup}_{C\\in\\mathcal{C}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\mathbb{P}\\left(C\\right)\\right|\\ge t\\right)}\\\\ &{}&{\\displaystyle\\le 2\\cdot\\mathbb{P}_{X,X^{\\prime}}\\left(\\displaystyle\\operatorname*{sup}_{C\\in\\mathcal{C}}\\left|\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}\\in C)-\\frac{1}{n}\\sum_{i=1}^{n}I(X_{i}^{\\prime}\\in C)\\right|\\ge t/2\\right).}\\end{array}\\]", "context": [], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Filter\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nnoncomputable def empFreq {Ω 𝒳 ι : Type*} (n : ℕ) (C : ι → Set 𝒳) (X : Fin n → Ω → 𝒳) (i' : ι) (ω : Ω) : ℝ :=\n (n : ℝ)⁻¹ * ∑ k : Fin n, (C i').indicator (fun _ => (1 : ℝ)) (X k ω)\n\nnoncomputable def supDevTruth {Ω 𝒳 ι : Type*} [MeasurableSpace 𝒳] (n : ℕ) (C : ι → Set 𝒳) (μ𝒳 : Measure 𝒳) (X : Fin n → Ω → 𝒳) (ω : Ω) : ℝ :=\n ⨆ i' : ι, |empFreq n C X i' ω - (μ𝒳 (C i')).toReal|\n\nnoncomputable def supDevGhost {Ω 𝒳 ι : Type*} (n : ℕ) (C : ι → Set 𝒳) (X X' : Fin n → Ω → 𝒳) (ω : Ω) : ℝ :=\n ⨆ i' : ι, |empFreq n C X i' ω - empFreq n C X' i' ω|\n\ntheorem ch10_lemma_10_1\n {Ω 𝒳 ι : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒳]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (μ𝒳 : Measure 𝒳)\n (n : ℕ) [NeZero n] (hn : 0 < n)\n (C : ι → Set 𝒳) (hC : ∀ i' : ι, MeasurableSet (C i'))\n (X X' : Fin n → Ω → 𝒳)\n (hXmeas : ∀ k, Measurable (X k)) (hX'meas : ∀ k, Measurable (X' k))\n (hXlaw : ∀ k, Measure.map (X k) μ = μ𝒳)\n (hX'law : ∀ k, Measure.map (X' k) μ = μ𝒳)\n (hXindep : iIndepFun X μ) (hX'indep : iIndepFun X' μ)\n (hmTruth : Measurable\n (fun p : Ω × Ω => supDevTruth n C μ𝒳 (fun (k : Fin n) (q : Ω × Ω) => X k q.1) p))\n (hmGhost : Measurable\n (fun p : Ω × Ω =>\n supDevGhost n C (fun (k : Fin n) (q : Ω × Ω) => X k q.1)\n (fun (k : Fin n) (q : Ω × Ω) => X' k q.2) p))\n (t : ℝ) (ht : t ≥ Real.sqrt (2 / (n : ℝ))) :\n ((μ.prod μ)\n {p : Ω × Ω | supDevTruth n C μ𝒳 (fun (k : Fin n) (q : Ω × Ω) => X k q.1) p ≥ t}).toReal\n ≤ 2 * ((μ.prod μ)\n {p : Ω × Ω |\n supDevGhost n C (fun (k : Fin n) (q : Ω × Ω) => X k q.1)\n (fun (k : Fin n) (q : Ω × Ω) => X' k q.2) p ≥ t / 2}).toReal := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Filter\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nnoncomputable def empFreq {Ω 𝒳 ι : Type*} (n : ℕ) (C : ι → Set 𝒳) (X : Fin n → Ω → 𝒳) (i' : ι) (ω : Ω) : ℝ :=\n (n : ℝ)⁻¹ * ∑ k : Fin n, (C i').indicator (fun _ => (1 : ℝ)) (X k ω)\n\nnoncomputable def supDevTruth {Ω 𝒳 ι : Type*} [MeasurableSpace 𝒳] (n : ℕ) (C : ι → Set 𝒳) (μ𝒳 : Measure 𝒳) (X : Fin n → Ω → 𝒳) (ω : Ω) : ℝ :=\n ⨆ i' : ι, |empFreq n C X i' ω - (μ𝒳 (C i')).toReal|\n\nnoncomputable def supDevGhost {Ω 𝒳 ι : Type*} (n : ℕ) (C : ι → Set 𝒳) (X X' : Fin n → Ω → 𝒳) (ω : Ω) : ℝ :=\n ⨆ i' : ι, |empFreq n C X i' ω - empFreq n C X' i' ω|\n\n/-! ### Elementary facts about indicators and empirical frequencies -/\n\nprivate lemma ind_nonneg {𝒳 : Type*} (s : Set 𝒳) (x : 𝒳) :\n 0 ≤ s.indicator (fun _ => (1 : ℝ)) x := by\n by_cases h : x ∈ s <;> simp [h]\n\nprivate lemma ind_le_one {𝒳 : Type*} (s : Set 𝒳) (x : 𝒳) :\n s.indicator (fun _ => (1 : ℝ)) x ≤ 1 := by\n by_cases h : x ∈ s <;> simp [h]\n\nprivate lemma ind_sq {𝒳 : Type*} (s : Set 𝒳) (x : 𝒳) :\n (s.indicator (fun _ => (1 : ℝ)) x) ^ 2 = s.indicator (fun _ => (1 : ℝ)) x := by\n by_cases h : x ∈ s <;> simp [h]\n\nprivate lemma empFreq_nonneg {Ω 𝒳 ι : Type*} (n : ℕ) (C : ι → Set 𝒳) (X : Fin n → Ω → 𝒳)\n (i : ι) (ω : Ω) : 0 ≤ empFreq n C X i ω := by\n unfold empFreq\n have : (0:ℝ) ≤ ∑ k : Fin n, (C i).indicator (fun _ => (1 : ℝ)) (X k ω) :=\n Finset.sum_nonneg (fun k _ => ind_nonneg _ _)\n positivity\n\nprivate lemma empFreq_le_one {Ω 𝒳 ι : Type*} {n : ℕ} (hn : 0 < n) (C : ι → Set 𝒳)\n (X : Fin n → Ω → 𝒳) (i : ι) (ω : Ω) : empFreq n C X i ω ≤ 1 := by\n have hnR : (0:ℝ) < (n : ℝ) := by exact_mod_cast hn\n unfold empFreq\n have h1 : ∑ k : Fin n, (C i).indicator (fun _ => (1 : ℝ)) (X k ω) ≤ (n : ℝ) := by\n calc ∑ k : Fin n, (C i).indicator (fun _ => (1 : ℝ)) (X k ω)\n ≤ ∑ _k : Fin n, (1:ℝ) := Finset.sum_le_sum (fun k _ => ind_le_one _ _)\n _ = (n : ℝ) := by simp\n rw [inv_mul_le_iff₀ hnR, mul_one]\n exact h1\n\nprivate lemma measurable_empFreq {Ω 𝒳 ι : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒳]\n (n : ℕ) (C : ι → Set 𝒳) (hC : ∀ i, MeasurableSet (C i)) (X : Fin n → Ω → 𝒳)\n (hX : ∀ k, Measurable (X k)) (i : ι) : Measurable (fun ω => empFreq n C X i ω) := by\n unfold empFreq\n refine Measurable.const_mul ?_ _\n refine Finset.measurable_sum _ (fun k _ => ?_)\n exact (measurable_const.indicator (hC i)).comp (hX k)\n\nprivate lemma integral_ind_comp {Ω 𝒳 : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒳]\n (μ : Measure Ω) (μ𝒳 : Measure 𝒳)\n (s : Set 𝒳) (hs : MeasurableSet s) (Z : Ω → 𝒳) (hZ : Measurable Z)\n (hlaw : Measure.map Z μ = μ𝒳) :\n ∫ ω, s.indicator (fun _ => (1:ℝ)) (Z ω) ∂μ = (μ𝒳 s).toReal := by\n have h1 : ∫ x, s.indicator (fun _ => (1:ℝ)) x ∂(μ.map Z)\n = ∫ ω, s.indicator (fun _ => (1:ℝ)) (Z ω) ∂μ :=\n integral_map hZ.aemeasurable ((measurable_const.indicator hs).aestronglyMeasurable)\n rw [← h1, hlaw, integral_indicator_const _ hs]\n simp [measureReal_def]\n\n/-- Chebyshev's inequality for the empirical frequency of an i.i.d. sample. -/\nprivate lemma cheb_empFreq {Ω 𝒳 ι : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒳]\n (μ : Measure Ω) [IsProbabilityMeasure μ] (μ𝒳 : Measure 𝒳)\n {n : ℕ} (hn : 0 < n) (C : ι → Set 𝒳) (hC : ∀ i, MeasurableSet (C i))\n (Z : Fin n → Ω → 𝒳) (hZmeas : ∀ k, Measurable (Z k))\n (hZlaw : ∀ k, Measure.map (Z k) μ = μ𝒳) (hZindep : iIndepFun Z μ)\n (i : ι) {s : ℝ} (hs : 0 < s) :\n (μ {ω | s ≤ |empFreq n C Z i ω - (μ𝒳 (C i)).toReal|}).toReal ≤ 1 / (4 * n * s ^ 2) := by\n classical\n have hnR : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn\n set p : ℝ := (μ𝒳 (C i)).toReal with hpdef\n set Y : Fin n → Ω → ℝ := fun k ω => (C i).indicator (fun _ => (1:ℝ)) (Z k ω) with hYdef\n have hYmeas : ∀ k, Measurable (Y k) := fun k =>\n (measurable_const.indicator (hC i)).comp (hZmeas k)\n have hYLp : ∀ k, MemLp (Y k) 2 μ := by\n intro k\n refine MemLp.of_bound (hYmeas k).aestronglyMeasurable 1 (.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (ind_nonneg _ _)]\n exact ind_le_one _ _\n have hYint : ∀ k, ∫ ω, Y k ω ∂μ = p := fun k =>\n integral_ind_comp μ μ𝒳 (C i) (hC i) (Z k) (hZmeas k) (hZlaw k)\n have hYvar : ∀ k, Var[Y k; μ] = p - p ^ 2 := by\n intro k\n rw [variance_eq_sub (hYLp k), hYint k]\n congr 1\n have h2 : (Y k) ^ 2 = Y k := by\n funext ω\n simpa [hYdef] using ind_sq (C i) (Z k ω)\n rw [h2, hYint k]\n -- pairwise independence of the indicators\n have hYindep : Set.Pairwise (↑(Finset.univ : Finset (Fin n))) fun k l => Y k ⟂ᵢ[μ] Y l := by\n intro k _ l _ hkl\n exact (hZindep.indepFun hkl).comp (measurable_const.indicator (hC i))\n (measurable_const.indicator (hC i))\n have hsumvar : Var[∑ k : Fin n, Y k; μ] = (n : ℝ) * (p - p ^ 2) := by\n rw [IndepFun.variance_sum (fun k _ => hYLp k) hYindep]\n simp only [hYvar, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n -- the empirical frequency as a rescaled sum\n have hEF : (fun ω => empFreq n C Z i ω) = fun ω => (n:ℝ)⁻¹ * (∑ k : Fin n, Y k) ω := by\n funext ω\n simp [empFreq, hYdef, Finset.sum_apply]\n have hEFmean : ∫ ω, empFreq n C Z i ω ∂μ = p := by\n rw [hEF]\n have hint : ∀ k : Fin n, Integrable (Y k) μ := fun k => (hYLp k).integrable (by norm_num)\n have : ∫ ω, (n:ℝ)⁻¹ * (∑ k : Fin n, Y k) ω ∂μ = (n:ℝ)⁻¹ * ∫ ω, (∑ k : Fin n, Y k) ω ∂μ :=\n integral_const_mul _ _\n rw [this]\n have h2 : ∫ ω, (∑ k : Fin n, Y k) ω ∂μ = ∑ k : Fin n, ∫ ω, Y k ω ∂μ := by\n simp only [Finset.sum_apply]\n exact integral_finset_sum _ (fun k _ => hint k)\n rw [h2]\n simp [hYint]\n field_simp\n have hEFvar : Var[fun ω => empFreq n C Z i ω; μ] ≤ 1 / (4 * n) := by\n rw [hEF, variance_const_mul, hsumvar]\n have h1 : ((n:ℝ)⁻¹)^2 * ((n:ℝ) * (p - p^2)) = (p - p^2) / n := by\n field_simp\n rw [h1]\n have h2 : (p - p^2) ≤ 1/4 := by nlinarith [sq_nonneg (p - 1/2)]\n calc (p - p^2)/(n:ℝ) ≤ (1/4)/(n:ℝ) := by gcongr\n _ = 1/(4*(n:ℝ)) := by rw [div_div]\n have hSmeas : Measurable (fun ω => empFreq n C Z i ω) := by\n unfold empFreq\n refine Measurable.const_mul ?_ _\n exact Finset.measurable_sum _ (fun k _ => (measurable_const.indicator (hC i)).comp (hZmeas k))\n have hSLp : MemLp (fun ω => empFreq n C Z i ω) 2 μ := by\n refine MemLp.of_bound hSmeas.aestronglyMeasurable 1 (.of_forall (fun ω => ?_))\n rw [Real.norm_eq_abs, abs_of_nonneg (empFreq_nonneg n C Z i ω)]\n exact empFreq_le_one hn C Z i ω\n have hcheb := meas_ge_le_variance_div_sq hSLp hs\n simp only [hEFmean] at hcheb\n have hvnn : 0 ≤ Var[fun ω => empFreq n C Z i ω; μ] := variance_nonneg _ _\n have h1 : (μ {ω | s ≤ |empFreq n C Z i ω - p|}).toReal\n ≤ Var[fun ω => empFreq n C Z i ω; μ] / s ^ 2 := by\n have := ENNReal.toReal_mono ENNReal.ofReal_ne_top hcheb\n rwa [ENNReal.toReal_ofReal (by positivity)] at this\n refine h1.trans ?_\n calc Var[fun ω => empFreq n C Z i ω; μ] / s ^ 2 ≤ (1/(4*(n:ℝ))) / s^2 := by gcongr\n _ = 1 / (4 * n * s ^ 2) := by rw [div_div]\n\n/-- The slice estimate: if the truth-deviation at `ω` is at least `t`, then with probability at\nleast `1/2` over the ghost sample the ghost-deviation is at least `t/2`. -/\nprivate lemma key_slice {Ω 𝒳 ι : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒳]\n (μ : Measure Ω) [IsProbabilityMeasure μ] (μ𝒳 : Measure 𝒳) [IsProbabilityMeasure μ𝒳]\n {n : ℕ} (hn : 0 < n) (C : ι → Set 𝒳) (hC : ∀ i, MeasurableSet (C i))\n (X X' : Fin n → Ω → 𝒳)\n (hX'meas : ∀ k, Measurable (X' k)) (hX'law : ∀ k, Measure.map (X' k) μ = μ𝒳)\n (hX'indep : iIndepFun X' μ)\n {t : ℝ} (ht : Real.sqrt (2 / (n : ℝ)) ≤ t)\n (ω : Ω) (hω : t ≤ supDevTruth n C μ𝒳 X ω)\n (B : Set Ω)\n (hBdef : ∀ ω' : Ω, ω' ∈ B ↔ t / 2 ≤ ⨆ i, |empFreq n C X i ω - empFreq n C X' i ω'|) :\n (1 : ℝ≥0∞) / 2 ≤ μ B := by\n classical\n have hnR : (0:ℝ) < (n : ℝ) := by exact_mod_cast hn\n have ht0 : 0 < t := lt_of_lt_of_le (Real.sqrt_pos.mpr (by positivity)) ht\n have ht2 : 2 / (n:ℝ) ≤ t ^ 2 := by\n have h := Real.sq_sqrt (show (0:ℝ) ≤ 2 / (n:ℝ) by positivity)\n nlinarith [Real.sqrt_nonneg (2 / (n:ℝ))]\n by_contra hcon\n push_neg at hcon\n have hBne : μ B ≠ ⊤ := measure_ne_top _ _\n set c : ℝ := (μ B).toReal with hcdef\n have hc0 : 0 ≤ c := ENNReal.toReal_nonneg\n have hclt : c < 1 / 2 := by\n have h1 : (μ B).toReal < ((1:ℝ≥0∞)/2).toReal :=\n (ENNReal.toReal_lt_toReal hBne (by norm_num)).mpr hcon\n simpa using h1\n have h1c : (1:ℝ)/2 < 1 - c := by linarith\n -- the threshold `u`\n have hm_pos : 0 < 1 / (4 * (n:ℝ) * (1 - c)) := by positivity\n have hmr : 1 / (4 * (n:ℝ) * (1 - c)) < (t/2)^2 := by\n have hA : 1 / (4 * (n:ℝ) * (1 - c)) < 1 / (2 * (n:ℝ)) := by\n apply one_div_lt_one_div_of_lt (by positivity)\n nlinarith\n have hB : 1 / (2 * (n:ℝ)) ≤ (t/2)^2 := by\n have he : 1 / (2*(n:ℝ)) = (2/(n:ℝ))/4 := by\n field_simp\n norm_num\n have he2 : (t/2)^2 = t^2/4 := by ring\n rw [he, he2]\n linarith\n linarith\n set u : ℝ := Real.sqrt ((1 / (4 * (n:ℝ) * (1 - c)) + (t/2)^2) / 2) with hudef\n have hu0 : 0 < u := Real.sqrt_pos.mpr (by linarith)\n have husq : u ^ 2 = (1 / (4 * (n:ℝ) * (1 - c)) + (t/2)^2) / 2 :=\n Real.sq_sqrt (by linarith)\n have hult : u < t / 2 := by nlinarith\n -- pick an index nearly attaining the supremum\n have hne : Nonempty ι := by\n by_contra hemp\n rw [not_nonempty_iff] at hemp\n have h0 : supDevTruth n C μ𝒳 X ω = 0 := Real.iSup_of_isEmpty _\n rw [h0] at hω\n linarith\n have hlt : t/2 + u < ⨆ i, |empFreq n C X i ω - (μ𝒳 (C i)).toReal| := by\n have h1 : t/2 + u < t := by linarith\n exact lt_of_lt_of_le h1 hω\n obtain ⟨i, hi⟩ := exists_lt_of_lt_ciSup hlt\n -- Chebyshev for the ghost sample at index `i`\n have hchebS := cheb_empFreq μ μ𝒳 hn C hC X' hX'meas hX'law hX'indep i hu0\n -- the complement of the bad set is contained in `B`\n have hsub : (Set.univ : Set Ω)\n ⊆ B ∪ {ω' | u ≤ |empFreq n C X' i ω' - (μ𝒳 (C i)).toReal|} := by\n intro ω' _\n by_cases hmem : ω' ∈ {ω' | u ≤ |empFreq n C X' i ω' - (μ𝒳 (C i)).toReal|}\n · exact Or.inr hmem\n · left\n rw [Set.mem_setOf_eq, not_le] at hmem\n rw [hBdef]\n have hbdd2 : BddAbove (Set.range fun i' => |empFreq n C X i' ω - empFreq n C X' i' ω'|) := by\n refine ⟨1, ?_⟩\n rintro x ⟨i', rfl⟩\n have h1 := empFreq_nonneg n C X i' ω\n have h2 := empFreq_le_one hn C X i' ω\n have h3 := empFreq_nonneg n C X' i' ω'\n have h4 := empFreq_le_one hn C X' i' ω'\n rw [abs_le]\n constructor <;> linarith\n have hterm : t/2 ≤ |empFreq n C X i ω - empFreq n C X' i ω'| := by\n have habs := abs_sub_abs_le_abs_sub\n (empFreq n C X i ω - (μ𝒳 (C i)).toReal)\n (empFreq n C X' i ω' - (μ𝒳 (C i)).toReal)\n have heq : (empFreq n C X i ω - (μ𝒳 (C i)).toReal)\n - (empFreq n C X' i ω' - (μ𝒳 (C i)).toReal)\n = empFreq n C X i ω - empFreq n C X' i ω' := by ring\n rw [heq] at habs\n linarith\n exact le_trans hterm (le_ciSup hbdd2 i)\n -- combine\n have hSne : μ {ω' | u ≤ |empFreq n C X' i ω' - (μ𝒳 (C i)).toReal|} ≠ ⊤ := measure_ne_top _ _\n have hmeasle : (1:ℝ≥0∞) ≤ μ B + μ {ω' | u ≤ |empFreq n C X' i ω' - (μ𝒳 (C i)).toReal|} := by\n calc (1:ℝ≥0∞) = μ (Set.univ : Set Ω) := measure_univ.symm\n _ ≤ μ (B ∪ {ω' | u ≤ |empFreq n C X' i ω' - (μ𝒳 (C i)).toReal|}) := measure_mono hsub\n _ ≤ _ := measure_union_le _ _\n have hreal : (1:ℝ) ≤ c + (μ {ω' | u ≤ |empFreq n C X' i ω' - (μ𝒳 (C i)).toReal|}).toReal := by\n have h := ENNReal.toReal_mono (ENNReal.add_ne_top.mpr ⟨hBne, hSne⟩) hmeasle\n rwa [ENNReal.toReal_add hBne hSne, ENNReal.toReal_one] at h\n have hlast : 1 / (4 * (n:ℝ) * u ^ 2) < 1 - c := by\n have hum : 1 / (4 * (n:ℝ) * (1 - c)) < u ^ 2 := by rw [husq]; linarith\n have h1 : 1 < u ^ 2 * (4 * (n:ℝ) * (1 - c)) :=\n (div_lt_iff₀ (show (0:ℝ) < 4 * (n:ℝ) * (1 - c) by positivity)).mp hum\n rw [div_lt_iff₀ (by positivity)]\n nlinarith\n linarith\n\ntheorem ch10_lemma_10_1\n {Ω 𝒳 ι : Type*} [MeasurableSpace Ω] [MeasurableSpace 𝒳]\n (μ : Measure Ω) [IsProbabilityMeasure μ]\n (μ𝒳 : Measure 𝒳)\n (n : ℕ) [NeZero n] (hn : 0 < n)\n (C : ι → Set 𝒳) (hC : ∀ i' : ι, MeasurableSet (C i'))\n (X X' : Fin n → Ω → 𝒳)\n (hXmeas : ∀ k, Measurable (X k)) (hX'meas : ∀ k, Measurable (X' k))\n (hXlaw : ∀ k, Measure.map (X k) μ = μ𝒳)\n (hX'law : ∀ k, Measure.map (X' k) μ = μ𝒳)\n (hXindep : iIndepFun X μ) (hX'indep : iIndepFun X' μ)\n (hmTruth : Measurable\n (fun p : Ω × Ω => supDevTruth n C μ𝒳 (fun (k : Fin n) (q : Ω × Ω) => X k q.1) p))\n (hmGhost : Measurable\n (fun p : Ω × Ω =>\n supDevGhost n C (fun (k : Fin n) (q : Ω × Ω) => X k q.1)\n (fun (k : Fin n) (q : Ω × Ω) => X' k q.2) p))\n (t : ℝ) (ht : t ≥ Real.sqrt (2 / (n : ℝ))) :\n ((μ.prod μ)\n {p : Ω × Ω | supDevTruth n C μ𝒳 (fun (k : Fin n) (q : Ω × Ω) => X k q.1) p ≥ t}).toReal\n ≤ 2 * ((μ.prod μ)\n {p : Ω × Ω |\n supDevGhost n C (fun (k : Fin n) (q : Ω × Ω) => X k q.1)\n (fun (k : Fin n) (q : Ω × Ω) => X' k q.2) p ≥ t / 2}).toReal := by\n classical\n have hnR : (0:ℝ) < (n : ℝ) := by exact_mod_cast hn\n have ht0 : 0 < t := lt_of_lt_of_le (Real.sqrt_pos.mpr (by positivity)) ht\n -- `Ω` is nonempty\n have hΩ : Nonempty Ω := by\n by_contra h\n rw [not_nonempty_iff] at h\n have h1 : μ (Set.univ : Set Ω) = 1 := measure_univ\n rw [Set.univ_eq_empty_iff.mpr h, measure_empty] at h1\n exact zero_ne_one h1\n obtain ⟨ω₀⟩ := hΩ\n -- `μ𝒳` is a probability measure\n have hprob𝒳 : IsProbabilityMeasure μ𝒳 := by\n rw [← hXlaw ⟨0, hn⟩]\n exact Measure.isProbabilityMeasure_map (hXmeas _).aemeasurable\n -- the two events, described intrinsically\n set A : Set Ω := {ω : Ω | supDevTruth n C μ𝒳 X ω ≥ t} with hAdef\n set G : Set (Ω × Ω) :=\n {p : Ω × Ω |\n supDevGhost n C (fun (k : Fin n) (q : Ω × Ω) => X k q.1)\n (fun (k : Fin n) (q : Ω × Ω) => X' k q.2) p ≥ t / 2} with hGdef\n have hGmeas : MeasurableSet G := hmGhost measurableSet_Ici\n have hmeasT : Measurable (fun ω : Ω => supDevTruth n C μ𝒳 X ω) := by\n have h : Measurable (fun ω : Ω => (ω, ω₀)) := measurable_id.prodMk measurable_const\n have h2 := hmTruth.comp h\n exact h2\n have hAmeas : MeasurableSet A := hmeasT measurableSet_Ici\n -- the key slice estimate\n have key : ∀ ω ∈ A, (1 : ℝ≥0∞) / 2 ≤ μ (Prod.mk ω ⁻¹' G) := by\n intro ω hω\n refine key_slice μ μ𝒳 hn C hC X X' hX'meas hX'law hX'indep ht ω hω _ ?_\n intro ω'\n exact Iff.rfl\n -- Fubini\n have hfub : (1 : ℝ≥0∞) / 2 * μ A ≤ (μ.prod μ) G := by\n rw [Measure.prod_apply hGmeas]\n calc (1 : ℝ≥0∞) / 2 * μ A\n = ∫⁻ ω, A.indicator (fun _ => (1 : ℝ≥0∞) / 2) ω ∂μ :=\n (lintegral_indicator_const hAmeas _).symm\n _ ≤ ∫⁻ ω, μ (Prod.mk ω ⁻¹' G) ∂μ := by\n refine lintegral_mono (fun ω => ?_)\n by_cases hω : ω ∈ A\n · rw [Set.indicator_of_mem hω]\n exact key ω hω\n · rw [Set.indicator_of_notMem hω]\n exact zero_le _\n have hfub' : μ A ≤ 2 * (μ.prod μ) G := by\n have hhalf : (2 : ℝ≥0∞) * ((1 : ℝ≥0∞) / 2) = 1 := by\n rw [one_div, ENNReal.mul_inv_cancel (by norm_num) (by norm_num)]\n have h2 : (2 : ℝ≥0∞) * ((1 : ℝ≥0∞) / 2 * μ A) = μ A := by\n rw [← mul_assoc, hhalf, one_mul]\n calc μ A = 2 * ((1 : ℝ≥0∞) / 2 * μ A) := h2.symm\n _ ≤ 2 * (μ.prod μ) G := by gcongr\n -- identify the left-hand event\n have hLHS : (μ.prod μ)\n {p : Ω × Ω | supDevTruth n C μ𝒳 (fun (k : Fin n) (q : Ω × Ω) => X k q.1) p ≥ t}\n = μ A := by\n have hset : {p : Ω × Ω | supDevTruth n C μ𝒳 (fun (k : Fin n) (q : Ω × Ω) => X k q.1) p ≥ t}\n = A ×ˢ (Set.univ : Set Ω) := by\n ext p\n simp only [Set.mem_setOf_eq, Set.mem_prod, Set.mem_univ, and_true, hAdef]\n rfl\n rw [hset, Measure.prod_prod, measure_univ, mul_one]\n rw [hLHS]\n have hfin : (2 : ℝ≥0∞) * (μ.prod μ) G ≠ ⊤ := by\n refine ENNReal.mul_ne_top (by norm_num) (measure_ne_top _ _)\n have := ENNReal.toReal_mono hfin hfub'\n rwa [ENNReal.toReal_mul, ENNReal.toReal_ofNat] at this\n\nend GraduateLevel\n"} +{"id": "ch4_theorem_4_12", "source": "Graduate-level", "targets": [{"label": "ch4_theorem_4_12", "decls": ["ch4_theorem_4_12"], "statement": "Assume that \\(\\phi(w, z) \\in [0,1]\\) for all \\(w\\) and \\(z\\). Then given \\(\\delta \\in (0,1)\\), with probability at least \\(1 - \\delta\\), the following inequality holds:\n\\[\n\\forall w\\in\\Omega:\\phi(w,\\mathcal{D})\\leq\\phi(w,\\mathcal{S}_{n})+\\epsilon_{n}(\\delta),\n\\]\nwhere\n\\[\n\\epsilon_{n}(\\delta)=\\inf_{\\epsilon>0}\\left[2\\epsilon+3\\sqrt{\\frac{\\ln(3 N_{1}(\\epsilon,\\mathcal{G},2 n)/\\delta)}{2 n}}\\right].\n\\]\nMoreover, for any \\(\\gamma \\in (0,1)\\), with probability at least \\(1 - \\delta\\), the following inequality holds:\n\\[\n\\forall w\\in\\Omega:(1-\\gamma)^{2}\\phi(w,\\mathcal{D})\\leq\\phi(w,\\mathcal{S}_{n})+\\epsilon_{n}(\\delta),\n\\]\nwhere\n\\[\n\\epsilon_{n}(\\delta)=\\inf_{\\epsilon>0}\\left[2\\epsilon+\\frac{(5-4\\gamma)\\ln(3 N_{1}(\\epsilon,\\mathcal{G},n)/\\delta)}{2\\gamma n}\\right].\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Let \\(\\mathcal{F} = \\{f(z) = \\phi(w,z) - 0.5 : w \\in \\Omega\\}\\). Given \\(S_{n}\\), we consider an \\(\\epsilon-L_{1}(S_{n})\\) cover \\(\\mathcal{F}_{\\epsilon}(S_{n})\\) of \\(\\mathcal{F}\\), of size no more \\(N = N_{1}(\\epsilon, \\mathcal{G}, n)\\). We may assume that \\(f(Z_{i}) \\in [-0.5, 0.5]\\) for \\(f \\in \\mathcal{F}_{\\epsilon}(S_{n})\\). From Corollary 2.27 (with \\(a_{i} = 0.5\\)) and the union bound, we obtain the following uniform convergence result over \\(\\mathcal{F}_{\\epsilon}(S_{n})\\). With probability \\(1-\\delta\\):\n\\[\n\\forall f\\in\\mathcal{F}_{\\epsilon}(\\mathcal{S}_{n}):f(\\sigma,\\mathcal{S}_{n})\\leq\\sqrt{\\frac{\\ln(N/\\delta)}{2 n}}.\n\\]\nSince for all \\( f \\in \\mathcal{F} \\), we can find \\( f' \\in \\mathcal{F}_{\\epsilon}(\\mathcal{S}_n) \\) so that \\( n^{-1} \\sum_{Z \\in \\mathcal{S}_n} |f(Z) - f'(Z)| \\leq \\epsilon \\) for all \\( Z \\in \\mathcal{S}_n \\). It follows that\n\\[\nf(\\sigma,\\mathcal{S}_{n})\\leq f^{\\prime}(\\sigma,\\mathcal{S}_{n})+\\epsilon\\leq\\epsilon+\\sqrt{\\frac{\\ln(N/\\delta)}{2 n}}.\n\\]\nUsing Lemma 4.8 with \\(\\psi = 0\\), this uniform convergence result for the symmetrized\nempirical process implies the following uniform convergence result. With probability at least \\(1 - \\delta_{1}\\) over \\((S_n, S'_n) \\sim \\mathcal{D}^{2n}\\):\n\\[\n\\forall w\\in\\Omega:\\underbrace{\\phi(w,\\mathcal{S}_{n}^{\\prime})}_{\\psi_{\\mathrm{val}}}\\leq\\underbrace{\\phi(w,\\mathcal{S}_{n})}_{\\psi_{\\mathrm{trn}}}+\\underbrace{2\\epsilon+\\sqrt{\\frac{2\\ln(2 N/\\delta_{1})}{n}}}_{\\epsilon_{n}^{1}(\\delta_{1})}.\n\\]\nThe standard additive Chernoff bound implies that for all \\( w \\in \\Omega \\), with probability at least \\( 1 - \\delta_2 \\):\n\\[\n\\underbrace{\\phi(w,\\mathcal{D})}_{\\psi_{\\mathrm{tst}}}\\leq\\underbrace{\\phi(w,\\mathcal{S}_{n}^{\\prime})}_{\\psi_{\\mathrm{val}}}+\\underbrace{\\sqrt{\\frac{\\ln(1/\\delta_{2})}{2 n}}}_{\\epsilon_{n}^{2}(\\delta_{2})}.\n\\]\nTherefore in Lemma 4.11, we can take symbols as defined above, together with \\(\\delta_1 = 2\\delta /3\\) and \\(\\delta_{2} = \\delta /3\\) to obtain the desired bound.\nSimilarly, we consider \\(\\mathcal{F} = \\{f(z) = \\phi (w,z):w\\in \\Omega \\}\\). Given \\(S_{n}\\), we consider an \\(\\epsilon -L_{1}(S_{n})\\) cover \\(\\mathcal{F}_{\\epsilon}(\\mathcal{S}_n)\\) of \\(\\mathcal{F}\\), of size no more \\(N=N_{1}(\\epsilon,\\mathcal{G},n)\\). We assume that \\(f(Z_{i})\\in [0,1]\\) for all \\(f\\in \\mathcal{F}_{\\epsilon}(\\mathcal{S}_n)\\). From Corollary 2.27 and the union bound, we obtain the following uniform convergence result over \\(\\mathcal{F}_{\\epsilon}(\\mathcal{S}_n)\\). With probability at least \\(1 - \\delta\\):\n\\[\n\\begin{array}{l}\\forall f\\in\\mathcal{F}_{\\epsilon}(\\mathcal{S}_{n}):f(\\sigma,\\mathcal{S}_{n})\\leq\\sqrt{\\frac{2\\sum_{Z\\in\\mathcal{S}_{n}}f(Z)^{2}\\ln(N/\\delta)}{n^{2}}}\\\\ \\leq\\gamma^{\\prime}\\frac{1}{n}\\sum_{Z\\in\\mathcal{S}_{n}}f(Z)+\\frac{\\ln(N/\\delta)}{2\\gamma^{\\prime}n}.\\\\ \\end{array}\n\\]\nThe first inequality used Corollary 2.27. The second inequality used \\(\\sqrt{2ab} \\leq \\gamma' a + b / (2\\gamma')\\) and \\(f(Z)^2 \\leq f(Z)\\). Since for all \\(f \\in \\mathcal{F}\\), we can find \\(f' \\in \\mathcal{F}_{\\epsilon}(\\mathcal{S}_n)\\) so that \\(\\frac{1}{n} \\sum_{Z \\in \\mathcal{S}_n} |f(Z) - f'(Z)| \\leq \\epsilon\\). It follows that\n\\[\n\\begin{array}{l}f(\\sigma,\\mathcal{S}_{n})\\leq f^{\\prime}(\\sigma,\\mathcal{S}_{n})+\\epsilon\\\\ \\leq\\gamma^{\\prime}\\frac{1}{n}\\sum_{Z\\in\\mathcal{S}_{n}}f^{\\prime}(Z)+\\frac{\\ln(N/\\delta)}{2\\gamma^{\\prime}n}+\\epsilon\\\\ \\leq\\gamma^{\\prime}\\frac{1}{n}\\sum_{Z\\in\\mathcal{S}_{n}}f(Z)+\\frac{\\ln(N/\\delta)}{2\\gamma^{\\prime}n}+(1+\\gamma^{\\prime})\\epsilon .\\\\ \\end{array}\n\\]\nNow, with \\(\\psi(f, \\mathcal{S}_n) = \\widetilde{\\psi}(f, \\mathcal{S}_n) = \\gamma' \\frac{1}{n} \\sum_{Z \\in \\mathcal{S}_n} f(Z)\\), we obtain from Lemma 4.8 the following uniform convergence result. With probability at least \\(1 - \\delta_1\\) over \\((\\mathcal{S}_n, \\mathcal{S}_n') \\sim \\mathcal{D}^{2n}\\):\n\\[\n\\forall w\\in\\Omega:(1-\\gamma^{\\prime})\\phi(w,\\mathcal{S}_{n}^{\\prime})\\leq(1+\\gamma^{\\prime})\\phi(w,\\mathcal{S}_{n})+2(1+\\gamma^{\\prime})\\epsilon+\\frac{\\ln(2 N/\\delta_{1})}{\\gamma^{\\prime}n}.\n\\]\nLet \\(\\gamma' = \\gamma / (2 - \\gamma)\\), then it is easy to check algebraically that \\((1 - \\gamma') / (1 + \\gamma') = 1 - \\gamma\\)\nand \\(1 / (\\gamma^{\\prime}(1 + \\gamma^{\\prime})) = (2 - \\gamma)^{2} / (2\\gamma)\\). We thus obtain:\n\\[\n\\forall w\\in\\Omega:\\underbrace{(1-\\gamma)\\phi(w,\\mathcal{S}_{n}^{\\prime})}_{\\psi_{\\mathrm{val}}}\\leq\\underbrace{\\phi(w,\\mathcal{S}_{n})}_{\\psi_{\\mathrm{trn}}}+\\underbrace{2\\epsilon+\\frac{(2-\\gamma)^{2}\\ln(2 N/\\delta_{1})}{2\\gamma n}}_{\\epsilon_{n}^{1}(\\delta_{1})}.\\tag{4.1}\n\\]\nThe standard multiplicative Chernoff bound in (2.11) implies that with probability \\( 1 - \\delta_2 \\):\n\\[\n\\underbrace{(1-\\gamma)(1-\\gamma)\\phi(w,\\mathcal{D})}_{\\psi_{\\mathrm{tst}}}\\leq\\underbrace{(1-\\gamma)\\phi(w,\\mathcal{S}_{n}^{\\prime})}_{\\psi_{\\mathrm{val}}}+\\underbrace{(1-\\gamma)\\frac{\\ln(1/\\delta_{2})}{2\\gamma n}}_{\\epsilon_{n}^{2}(\\delta_{2})}.\n\\]\nTherefore in Lemma 4.11, we can use symbols as displayed above, together with \\(\\delta_1 = 2\\delta /3\\) and \\(\\delta_{2} = \\delta /3\\) to obtain the desired bound.", "context": [{"id": "ch2:corollary:2_27", "name": "corollary 2.27", "statement": "Let \\(\\sigma_{i} = \\{\\pm 1\\}\\) be independent Bernoulli random variables ( each takes value \\(\\pm 1\\) with equal probability). Let \\(a_{i}\\) be fixed numbers \\((i=1,\\dots,n)\\) Then for all \\(\\epsilon >0\\) ..\n\\[\n\\Pr\\left(n^{-1}\\sum_{i=1}^{n}\\sigma_{i}a_{i}\\geq\\epsilon\\right)\\leq\\exp\\left[-\\frac{n\\epsilon^{2}}{2 n^{-1}\\sum_{i=1}^{n}a_{i}^{2}}\\right].\n\\]"}, {"id": "ch4:lemma:4_8", "name": "Lemma 4.8", "statement": "(Symmetrization) Consider a real valued function family \\(F = \\{f : Z \\rightarrow \\mathbb{R}\\}\\). Assume there exists a function \\(\\psi : F \\times Z^{n} \\rightarrow \\mathbb{R}\\) and \\(\\epsilon_{n} : (0,1) \\rightarrow \\mathbb{R}\\) so that with probability at least \\(1-\\delta\\):\n\\[\n\\forall f \\in F, \\qquad f(\\sigma, S_{n}) \\leq \\psi(f, S_{n}) + \\epsilon_{n}(\\delta),\n\\]\nwhere the randomness is over both \\(S_{n} \\sim D^{n}\\) and \\(\\sigma\\). If there exists \\(\\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime})\\) so that the following superadditive inequality holds for all \\((S_{n}, S_{n}^{\\prime})\\)\n\\[\n\\psi(f, S_{n}) + \\psi(f, S_{n}^{\\prime}) \\leq \\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime}),\n\\]\nthen with probability at least \\(1-\\delta\\) over independent random data \\((S_{n}, S_{n}^{\\prime}) \\sim D^{2n}\\):\n\\[\n\\forall f \\in F, \\qquad f(S_{n}^{\\prime}) \\leq f(S_{n}) + \\tilde{\\psi}(f, S_{n} \\cup S_{n}^{\\prime}) + 2\\epsilon_{n}(\\delta/2).\n\\]"}, {"id": "ch4:lemma:4_11", "name": "lemma 4.11", "statement": "Let \\(\\psi_{\\mathrm{trn}}: \\mathcal{F} \\times \\mathcal{Z}^n \\to \\mathbb{R}\\), \\(\\psi_{\\mathrm{val}}: \\mathcal{F} \\times \\mathcal{Z}^n \\to \\mathbb{R}\\), \\(\\psi_{\\mathrm{tst}}: \\mathcal{F} \\times \\mathcal{D} \\to \\mathbb{R}\\) be appropriately training (where \\(\\mathcal{D}\\) denotes probability distributions on \\(\\mathcal{Z}\\)), validation, and test statistics. Assume that for any \\(\\delta_1 \\in (0,1)\\), the following uniform convergence result holds. With probability at least \\(1 - \\delta_1\\) over randomly drawn training and validation sets \\((S_n, S_n') \\sim \\mathcal{D}^{2n}\\):\n\\[\n\\forall f\\in\\mathcal{F}:\\psi_{\\mathrm{val}}(f,\\mathcal{S}_{n}^{\\prime})\\leq\\psi_{\\mathrm{trn}}(f,\\mathcal{S}_{n})+\\epsilon_{n}^{1}(\\delta_{1}).\n\\]\nMoreover, assume \\(\\forall f\\in \\mathcal{F}\\), we have with probability \\(1 - \\delta_{2}\\) over randomly drawn \\(\\mathcal{S}_n^\\prime \\sim \\mathcal{D}\\):\n\\[\n\\psi_{\\mathrm{tst}}(f,\\mathcal{D})\\leq\\psi_{\\mathrm{val}}(f,\\mathcal{S}_{n}^{\\prime})+\\epsilon_{n}^{2}(\\delta_{2}).\n\\]\nThen the following uniform convergence statement holds. With probability at least \\(1 - \\delta_1 - \\delta_2\\),\n\\[\n\\forall f\\in\\mathcal{F}:\\psi_{\\mathrm{tst}}(f,\\mathcal{D})\\leq\\psi_{\\mathrm{trn}}(f,\\mathcal{S}_{n})+\\epsilon_{n}^{1}(\\delta_{1})+\\epsilon_{n}^{2}(\\delta_{2}).\n\\]"}, {"id": "ch3:proposition:3_5", "name": "Union Bound", "statement": "(Union Bound) Consider \\(m\\) events \\(E_1, \\ldots, E_m\\). The following probability inequality holds:\n\\[\n\\Pr (E_1 \\cup \\cdots \\cup E_m) \\leq \\sum_{j=1}^{m} \\Pr(E_j).\n\\]\n\nThe union bound has an alternative expression, which is often used in the learning theory analysis. If each \\(E_j\\) occurs with probability at least \\(1-\\delta_j\\) for \\(j=1, \\ldots, m\\), then with probability at least \\(1-\\sum_{j=1}^{m} \\delta_j\\), all of events \\(\\{E_j\\}\\) occur simultaneously for \\(j=1, \\ldots, m\\)."}, {"id": "ch4:definition:4_1", "name": "definition 4.1", "statement": "Let \\((\\mathcal{V},d)\\) be a pseudometric space with metric \\(d(\\cdot,\\cdot)\\). A finite\nset \\(\\mathcal{G}(\\epsilon) \\subset \\mathcal{V}\\) is an \\(\\epsilon\\)-cover (or \\(\\epsilon\\)-net) of \\(\\mathcal{G} \\subset \\mathcal{V}\\) if, for all \\(\\phi \\in \\mathcal{G}\\), there exists \\(\\phi' \\in \\mathcal{G}(\\epsilon)\\) so that \\(d(\\phi', \\phi) \\leq \\epsilon\\). The \\(\\epsilon\\)-covering number of \\(\\mathcal{G}\\) with metric \\(d\\) is the smallest cardinality \\(N(\\epsilon, \\mathcal{G}, d)\\) of such \\(\\mathcal{G}(\\epsilon)\\). The number \\(\\ln N(\\epsilon, \\mathcal{G}, d)\\) is called the \\(\\epsilon\\)-entropy.\nFor a function class \\(\\mathcal{G}\\) with seminorm \\(L_{p}(\\mathcal{D})\\) in (3.19), we denote the corresponding \\(L_{p}(\\mathcal{D})\\)-covering number as \\(N(\\epsilon, \\mathcal{G}, L_{p}(\\mathcal{D}))\\). When \\(1 \\leq p \\leq q\\), we have\n\\[\nN(\\epsilon,\\mathcal{G},L_{p}(\\mathcal{D}))\\leq N(\\epsilon,\\mathcal{G},L_{q}(\\mathcal{D})).\n\\]"}, {"id": "ch3:definition:3_8", "name": "definition 3.8", "statement": "We define\n\\[\n\\phi(w,z)=L\\left(f(w,x),y\\right)-L_{*}(x,y),\\tag{3.4}\n\\]\nfor \\( w \\in \\Omega \\) and \\( z = (x, y) \\in \\mathcal{Z} = \\mathcal{X} \\times \\mathcal{Y} \\), and a pre-chosen \\( L_{*}(x, y) \\) of \\( z = (x, y) \\) that does not depend on \\( w \\).\nFor training data \\( S_{n}=\\{Z_{i}=(X_{i},Y_{i}):i=1,\\ldots,n\\} \\), we define the training loss for \\( w\\in \\Omega \\) as\n\\[\n\\phi(w,\\mathcal{S}_{n})=\\frac{1}{n}\\sum_{i=1}^{n}\\phi(w,Z_{i}).\\tag{3.5}\n\\]\nMoreover, for a distribution \\(\\mathcal{D}\\) on \\(\\mathcal{Z}\\), we define the test loss for \\(w \\in \\Omega\\) as:\n\\[\n\\phi(w,\\mathcal{D})=\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(w,Z).\\tag{3.6}\n\\]\nSince \\( L_{*}(x,y) \\) does not depend on \\( w \\), the ERM solution with respect to the loss \\( L(\\cdot) \\) is equivalent to the ERM solution with respect to \\( \\phi (w,\\cdot) \\). Therefore with the simplified notations, the approximate ERM method (3.3) is a special case of the following method:\n\\[\n\\phi(\\hat{w},\\mathcal{S}_{n})\\leq\\inf_{w\\in\\Omega}\\phi(w,\\mathcal{S}_{n})+\\epsilon^{\\prime}.\\tag{3.7}\n\\]\nIn general, we may simply take \\( L_{*}(x,y) = 0 \\) in (3.4). However, for some applications, we may choose a non-zero \\( L_{*}(x,y) \\) so that\n\\[\nL(f(w,x),y)-L_{*}(x,y)\n\\]\nhas a small variance. For least squares loss, this can be achieved with \\( L_{*}(x,y) = L(f_{*}(x),y) \\) where \\( f_{*}(x) \\) is the optimal prediction function that minimizes the test loss as shown in Example 3.9. The smaller variance, combined with Bernstein's inequality, implies better generalization bound (see Section 3.6 for more details)."}, {"id": "ch4:definition:4_4", "name": "Empirical and Uniform Covering Number", "statement": "Given an empirical distribution \\( S_{n}=\\{Z_{1},\\ldots,Z_{n}\\} \\), we define the pseudometric \\( d = L_{p}(S_{n}) \\) as\n\\[\nd(\\phi,\\phi^{\\prime})=\\left[\\frac{1}{n}\\sum_{i=1}^{n}|\\phi(Z_{i})-\\phi^{\\prime}(Z_{i})|^{p}\\right]^{1/p}.\n\\]\nThe corresponding metric covering number \\(N(\\epsilon, \\mathcal{G}, L_p(\\mathcal{S}_n))\\) is referred to as the\nempirical \\( L_{p} \\) covering number. Given \\( n \\), the largest \\( L_{p} \\) covering number over empirical distribution \\( S_{n} \\) is referred to as the uniform \\( L_{p} \\) covering number\n\\[\nN_{p}(\\epsilon,\\mathcal{G},n)=\\sup_{\\mathcal{S}_{n}}N(\\epsilon,\\mathcal{G},L_{p}(\\mathcal{S}_{n})).\n\\]"}, {"id": "ch3:definition:3_27", "name": "Bracketing Number", "statement": "Let \\(\\mathcal{G} = \\{\\phi(w, \\cdot) : w \\in \\Omega\\}\\) be a real-valued function class, equipped with a pseudometric \\(d\\). We say\n\\[\n\\mathcal{G}(\\epsilon)=\\left\\{\\left[\\phi_{1}^{L}(z),\\phi_{1}^{U}(z)\\right],\\dots,\\left[\\phi_{N}^{L}(z),\\phi_{N}^{U}(z)\\right]\\right\\}\n\\]\nis an \\(\\epsilon\\)-bracket of \\(\\mathcal{G}\\) under metric \\(d\\) if for all \\(w \\in \\Omega\\), there exists \\(j = j(w)\\) such that \\(\\forall z\\):\n\\[\n\\phi_{j}^{L}(z)\\leq\\phi(w,z)\\leq\\phi_{j}^{U}(z),\\quad d(\\phi_{j}^{L},\\phi_{j}^{U})\\leq\\epsilon .\n\\]\nThe \\(\\epsilon\\)-bracketing number is the smallest cardinality \\(N_{\\mathbb{I}}(\\epsilon, \\mathcal{G}, d)\\) of such \\(\\mathcal{G}(\\epsilon)\\). The quantity \\(\\ln N_{\\mathbb{I}}(\\epsilon, \\mathcal{G}, d)\\) is called \\(\\epsilon\\) bracketing entropy.\nIn particular, given a distribution \\(\\mathcal{D}\\) and \\(p \\geq 1\\), we define \\(L_{p}\\)-seminorm in function space as\n\\[\n\\left\\|f-f^{\\prime}\\right\\|_{L_{p}(\\mathcal{D})}=\\left[\\mathbb{E}_{Z\\sim\\mathcal{D}}|f(Z)-f^{\\prime}(Z)|^{p}\\right]^{1/p}.\\tag{3.19}\n\\]\nIt induces a pseudometric, denoted as \\( d = L_{p}(\\mathcal{D}) \\), and the corresponding bracketing number is \\( N_{\\parallel}(\\epsilon, \\mathcal{G}, L_{p}(\\mathcal{D})) \\).\nFor \\(p = \\infty\\), the \\(L_{\\infty}(\\mathcal{D})\\)-seminorm is defined as the essential supremum seminorm, which leads to the pseudometric\n\\[\nd(f,f^{\\prime})=\\inf\\left\\{\\omega:\\Pr_{\\mathcal{D}}[|f(Z)-f^{\\prime}(Z)|\\leq\\omega]=1\\right\\}.\n\\]\nHowever, when \\( p = \\infty \\), instead of using the \\( L_{\\infty} \\) bracketing number, it is more conventional to use the equivalent notion of \\( L_{\\infty} \\) covering number (see Proposition 4.3)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def empLoss {𝒵 : Type*} {Ωp : Type*} {n : ℕ}\n (φ : Ωp → 𝒵 → ℝ) (Z : Fin n → 𝒵) (w : Ωp) : ℝ :=\n (1 / (n : ℝ)) * ∑ i : Fin n, φ w (Z i)\n\nnoncomputable def testLoss {𝒵 : Type*} [MeasurableSpace 𝒵] {Ωp : Type*}\n (φ : Ωp → 𝒵 → ℝ) (D : Measure 𝒵) (w : Ωp) : ℝ :=\n ∫ z, φ w z ∂D\n\ndef IsUnifL1Cover {𝒵 : Type*} [MeasurableSpace 𝒵] {Ωp : Type*}\n (D : Measure 𝒵)\n (C : Finset (𝒵 → ℝ)) (φ : Ωp → 𝒵 → ℝ) (𝒲 : Set Ωp) (ε : ℝ) {m : ℕ}\n (S : Fin m → 𝒵) : Prop :=\n (∀ g ∈ C, (∀ z, g z ∈ Set.Icc (0 : ℝ) 1) ∧ AEMeasurable g D) ∧\n (∀ w ∈ 𝒲, ∃ g ∈ C,\n (1 / (m : ℝ)) * ∑ j : Fin m, |φ w (S j) - g (S j)| ≤ ε)\n\ndef IsUnifL1CoveringNumber {𝒵 : Type*} [MeasurableSpace 𝒵] {Ωp : Type*}\n (D : Measure 𝒵)\n (N : ℕ) (φ : Ωp → 𝒵 → ℝ) (𝒲 : Set Ωp) (ε : ℝ) (m : ℕ) : Prop :=\n (∀ S : Fin m → 𝒵, ∃ C : Finset (𝒵 → ℝ),\n C.card ≤ N ∧ IsUnifL1Cover D C φ 𝒲 ε S) ∧\n (∀ M : ℕ,\n (∀ S : Fin m → 𝒵, ∃ C : Finset (𝒵 → ℝ),\n C.card ≤ M ∧ IsUnifL1Cover D C φ 𝒲 ε S) →\n N ≤ M)\n\ntheorem ch4_theorem_4_12\n {𝒵 : Type*} [MeasurableSpace 𝒵]\n {Ωp : Type*}\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (𝒲 : Set Ωp) (hW : 𝒲.Nonempty) (hW_ctble : 𝒲.Countable)\n (φ : Ωp → 𝒵 → ℝ)\n (hφ_bdd : ∀ w ∈ 𝒲, ∀ z, φ w z ∈ Set.Icc (0 : ℝ) 1)\n (hφ_meas : ∀ w ∈ 𝒲, AEMeasurable (fun z => φ w z) D)\n (n : ℕ) (hn : 0 < n)\n (Z : Ω → Fin n → 𝒵)\n (hZ_meas : ∀ i, AEMeasurable (fun ω => Z ω i) μ)\n (hZ_iid : (iIndepFun (fun i ω => Z ω i) μ) ∧\n (∀ i, Measure.map (fun ω => Z ω i) μ = D))\n (N₁ : ℝ → ℕ → ℕ)\n (hN₁ : ∀ ε > (0 : ℝ),\n IsUnifL1CoveringNumber D (N₁ ε n) φ 𝒲 ε n ∧\n IsUnifL1CoveringNumber D (N₁ ε (2 * n)) φ 𝒲 ε (2 * n))\n (δ : ℝ) (hδ : δ ∈ Set.Ioo (0 : ℝ) 1) :\n (1 - δ ≤ μ.real {ω |\n ∀ w ∈ 𝒲,\n testLoss φ D w ≤ empLoss φ (Z ω) w\n + ⨅ ε : {e : ℝ // 0 < e},\n (2 * (ε : ℝ)\n + 3 * Real.sqrt\n (Real.log (3 * (N₁ (ε : ℝ) (2 * n) : ℝ) / δ) / (2 * n)))})\n ∧\n (∀ γ ∈ Set.Ioo (0 : ℝ) 1,\n 1 - δ ≤ μ.real {ω |\n ∀ w ∈ 𝒲,\n (1 - γ) ^ 2 * testLoss φ D w ≤ empLoss φ (Z ω) w\n + ⨅ ε : {e : ℝ // 0 < e},\n (2 * (ε : ℝ)\n + (5 - 4 * γ) * Real.log (3 * (N₁ (ε : ℝ) n : ℝ) / δ)\n / (2 * γ * n))}) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnamespace GtLib\n\n/-! ### Rademacher machinery -/\n\nnoncomputable def bern : Measure Bool := (PMF.bernoulli (1/2) (by norm_num)).toMeasure\n\ninstance : IsProbabilityMeasure bern := by unfold bern; infer_instance\n\nlemma bern_integral (h : Bool → ℝ) : ∫ x, h x ∂bern = (1/2) * h true + (1/2) * h false := by\n rw [bern, PMF.integral_eq_sum]\n simp [PMF.bernoulli]\n\nnoncomputable def Rm (n : ℕ) : Measure (Fin n → Bool) := Measure.pi (fun _ => bern)\n\ninstance (n : ℕ) : IsProbabilityMeasure (Rm n) := by unfold Rm; infer_instance\n\ndef sgnb {n : ℕ} (A : Fin n → Bool) (i : Fin n) : ℝ := if A i then -1 else 1\n\nlemma measurable_sgnb {n : ℕ} (i : Fin n) : Measurable (fun A : Fin n → Bool => sgnb A i) := by\n have : (fun A : Fin n → Bool => sgnb A i) = (fun x : Bool => if x then (-1:ℝ) else 1) ∘ (fun A : Fin n → Bool => A i) := rfl\n rw [this]\n exact Measurable.of_discrete.comp (measurable_pi_apply i)\n\nlemma Rm_integral_eval {n : ℕ} (i : Fin n) (h : Bool → ℝ) :\n ∫ A, h (A i) ∂(Rm n) = ∫ x, h x ∂bern := by\n have hmp := measurePreserving_eval (fun _ : Fin n => bern) i\n rw [← hmp.map_eq, integral_map ((measurable_pi_apply i).aemeasurable) (by fun_prop)]\n rfl\n\nlemma rad_tail (n : ℕ) (b : Fin n → ℝ) (t : ℝ) (ht : 0 ≤ t) :\n (Rm n).real {A | t ≤ ∑ i, sgnb A i * b i} ≤ Real.exp (-t^2 / (2 * ∑ i, (b i)^2)) := by\n classical\n set X : Fin n → (Fin n → Bool) → ℝ := fun i A => sgnb A i * b i with hX\n set c : Fin n → NNReal := fun i => ⟨(b i)^2, sq_nonneg _⟩ with hc\n have hmeasX : ∀ i, Measurable (X i) := fun i => (measurable_sgnb i).mul_const _\n have hindep0 : iIndepFun (fun (i : Fin n) (A : Fin n → Bool) => A i) (Rm n) := by\n have := iIndepFun_pi (μ := fun _ : Fin n => bern) (X := fun _ => (id : Bool → Bool))\n (fun i => aemeasurable_id)\n simpa [Rm] using this\n have hindep : iIndepFun X (Rm n) := by\n have := hindep0.comp (fun i => fun (x : Bool) => (if x then (-1:ℝ) else 1) * b i)\n (fun i => by fun_prop)\n exact this\n have hsub : ∀ i : Fin n, HasSubgaussianMGF (X i) (c i) (Rm n) := by\n intro i\n have hmean : ∫ A, X i A ∂(Rm n) = 0 := by\n have h1 : ∫ A, X i A ∂(Rm n) = ∫ x, (if x then -(b i) else b i) ∂bern := by\n rw [← Rm_integral_eval i (fun x => if x then -(b i) else b i)]\n congr 1; funext A; simp only [hX, sgnb]; split <;> ring\n rw [h1, bern_integral]; norm_num\n have hbdd : ∀ᵐ A ∂(Rm n), X i A ∈ Set.Icc (-|b i|) (|b i|) := by\n filter_upwards with A\n simp only [hX, sgnb]\n split <;> constructor <;>\n nlinarith [abs_nonneg (b i), le_abs_self (b i), neg_abs_le (b i)]\n have h2 := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero (μ := Rm n) (X := X i)\n (hmeasX i).aemeasurable hbdd hmean\n have heq : (‖|b i| - -|b i|‖₊ / 2) ^ 2 = c i := by\n apply NNReal.coe_injective\n push_cast\n rw [Real.norm_eq_abs]\n rw [abs_of_nonneg (by linarith [abs_nonneg (b i)] : (0:ℝ) ≤ |b i| - -|b i|)]\n have : |b i| - -|b i| = 2 * |b i| := by ring\n rw [this]\n have : (2 * |b i| / 2) = |b i| := by ring\n rw [this, sq_abs]\n simp [hc]\n rwa [heq] at h2\n have := ProbabilityTheory.HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hindep\n (c := c) (s := Finset.univ) (fun i _ => hsub i) ht\n simpa [hX, hc, NNReal.coe_sum] using this\n\n\nlemma abs_sgnb {n : ℕ} (A : Fin n → Bool) (i : Fin n) : |sgnb A i| = 1 := by\n unfold sgnb; split <;> norm_num\n\nlemma rad_tail_le {n : ℕ} (b : Fin n → ℝ) (t V L : ℝ) (ht : 0 < t)\n (hb : ∑ i, (b i)^2 ≤ V) (hVL : 2*V*L ≤ t^2) :\n (Rm n) {A | t ≤ ∑ i, sgnb A i * b i} ≤ ENNReal.ofReal (Real.exp (-L)) := by\n rcases eq_or_lt_of_le (Finset.sum_nonneg (fun i (_ : i ∈ Finset.univ) => sq_nonneg (b i)))\n with hW | hW\n · -- ∑ b² = 0 : all b i = 0\n have hb0 : ∀ i, b i = 0 := by\n intro i\n have := (Finset.sum_eq_zero_iff_of_nonneg\n (fun i (_ : i ∈ Finset.univ) => sq_nonneg (b i))).1 hW.symm i (Finset.mem_univ i)\n exact pow_eq_zero_iff (n := 2) (by norm_num) |>.1 this\n have hempty : {A : Fin n → Bool | t ≤ ∑ i, sgnb A i * b i} = ∅ := by\n ext A\n simp only [hb0, mul_zero, Finset.sum_const_zero, Set.mem_setOf_eq, Set.mem_empty_iff_false,\n iff_false, not_le]\n exact ht\n rw [hempty]; simp\n · have hVpos : 0 < V := lt_of_lt_of_le hW hb\n have h1 := rad_tail n b t ht.le\n have h2 : Real.exp (-t^2 / (2 * ∑ i, (b i)^2)) ≤ Real.exp (-L) := by\n apply Real.exp_le_exp.2\n rw [div_le_iff₀ (by positivity)]\n have hL : L ≤ t^2/(2*V) := by\n rw [le_div_iff₀ (by positivity)]; linarith\n nlinarith [hW, hb, hVpos]\n have h3 : (Rm n).real {A | t ≤ ∑ i, sgnb A i * b i} ≤ Real.exp (-L) := h1.trans h2\n exact (ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) (Real.exp_pos _).le).2 h3\n\n\nlemma pointwise1 {𝒵 : Type*} {ι : Type*} {n : ℕ} (hn : 0 < n)\n (f : ι → 𝒵 → ℝ) (hf01 : ∀ w z, f w z ∈ Set.Icc (0:ℝ) 1)\n (y : Fin n → 𝒵 × 𝒵) (ε s : ℝ) (hs : 0 < s)\n (C : Finset (𝒵 → ℝ)) (hC01 : ∀ g ∈ C, ∀ z, g z ∈ Set.Icc (0:ℝ) 1)\n (hCcov : ∀ w : ι, ∃ g ∈ C, (1/(2*(n:ℝ))) *\n ∑ i, (|f w (y i).1 - g (y i).1| + |f w (y i).2 - g (y i).2|) ≤ ε)\n (L : ℝ) (hL : 2 * (n:ℝ) * L ≤ ((n:ℝ)*s)^2) :\n (Rm n) {A | ∃ w : ι, 2*ε + s < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)}\n ≤ (C.card : ENNReal) * ENNReal.ofReal (Real.exp (-L)) := by\n classical\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hsubset : {A : Fin n → Bool |\n ∃ w : ι, 2*ε + s < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)}\n ⊆ ⋃ g ∈ C, {A : Fin n → Bool |\n (n:ℝ)*s ≤ ∑ i, sgnb A i * (g (y i).2 - g (y i).1)} := by\n rintro A ⟨w, hw⟩\n obtain ⟨g, hgC, hg⟩ := hCcov w\n refine Set.mem_biUnion hgC ?_\n simp only [Set.mem_setOf_eq]\n have hdiff : ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)\n - ∑ i, sgnb A i * (g (y i).2 - g (y i).1)\n ≤ ∑ i, (|f w (y i).1 - g (y i).1| + |f w (y i).2 - g (y i).2|) := by\n rw [← Finset.sum_sub_distrib]\n apply Finset.sum_le_sum\n intro i _\n have heq : sgnb A i * (f w (y i).2 - f w (y i).1) - sgnb A i * (g (y i).2 - g (y i).1)\n = sgnb A i * ((f w (y i).2 - g (y i).2) - (f w (y i).1 - g (y i).1)) := by ring\n rw [heq]\n calc sgnb A i * ((f w (y i).2 - g (y i).2) - (f w (y i).1 - g (y i).1))\n ≤ |sgnb A i * ((f w (y i).2 - g (y i).2) - (f w (y i).1 - g (y i).1))| := le_abs_self _\n _ = |(f w (y i).2 - g (y i).2) - (f w (y i).1 - g (y i).1)| := by\n rw [abs_mul, abs_sgnb, one_mul]\n _ ≤ |f w (y i).2 - g (y i).2| + |f w (y i).1 - g (y i).1| := by\n exact (abs_sub _ _).trans (le_of_eq rfl)\n _ = |f w (y i).1 - g (y i).1| + |f w (y i).2 - g (y i).2| := by ring\n have hsum : ∑ i, (|f w (y i).1 - g (y i).1| + |f w (y i).2 - g (y i).2|) ≤ 2*(n:ℝ)*ε := by\n rw [div_mul_eq_mul_div, one_mul, div_le_iff₀ (by positivity)] at hg\n linarith\n rw [div_mul_eq_mul_div, one_mul, lt_div_iff₀ hn'] at hw\n linarith\n calc (Rm n) {A : Fin n → Bool |\n ∃ w : ι, 2*ε + s < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)}\n ≤ (Rm n) (⋃ g ∈ C, {A : Fin n → Bool |\n (n:ℝ)*s ≤ ∑ i, sgnb A i * (g (y i).2 - g (y i).1)}) := measure_mono hsubset\n _ ≤ ∑ g ∈ C, (Rm n) {A : Fin n → Bool |\n (n:ℝ)*s ≤ ∑ i, sgnb A i * (g (y i).2 - g (y i).1)} := measure_biUnion_finset_le C _\n _ ≤ ∑ _g ∈ C, ENNReal.ofReal (Real.exp (-L)) := by\n apply Finset.sum_le_sum\n intro g hgC\n refine rad_tail_le _ ((n:ℝ)*s) (n:ℝ) L (by positivity) ?_ ?_\n · calc ∑ i, (g (y i).2 - g (y i).1)^2 ≤ ∑ _i : Fin n, (1:ℝ) := by\n apply Finset.sum_le_sum\n intro i _\n have h1 := hC01 g hgC (y i).1\n have h2 := hC01 g hgC (y i).2\n simp only [Set.mem_Icc] at h1 h2\n nlinarith [h1.1, h1.2, h2.1, h2.2]\n _ = (n:ℝ) := by simp\n · linarith\n _ = (C.card : ENNReal) * ENNReal.ofReal (Real.exp (-L)) := by\n rw [Finset.sum_const, nsmul_eq_mul]\n\n\nlemma pointwise2 {𝒵 : Type*} {ι : Type*} {n : ℕ} (hn : 0 < n)\n (f : ι → 𝒵 → ℝ) (hf01 : ∀ w z, f w z ∈ Set.Icc (0:ℝ) 1)\n (y : Fin n → 𝒵 × 𝒵) (ε : ℝ) (γ' : ℝ) (hγ' : 0 < γ')\n (C₁ C₂ : Finset (𝒵 → ℝ))\n (hC₁01 : ∀ g ∈ C₁, ∀ z, g z ∈ Set.Icc (0:ℝ) 1)\n (hC₂01 : ∀ g ∈ C₂, ∀ z, g z ∈ Set.Icc (0:ℝ) 1)\n (hcov₁ : ∀ w : ι, ∃ g ∈ C₁, (1/(n:ℝ)) * ∑ i, |f w (y i).1 - g (y i).1| ≤ ε)\n (hcov₂ : ∀ w : ι, ∃ g ∈ C₂, (1/(n:ℝ)) * ∑ i, |f w (y i).2 - g (y i).2| ≤ ε)\n (L : ℝ) (hL : 0 < L) :\n (Rm n) {A | ∃ w : ι,\n γ' * ((1/(n:ℝ)) * ∑ i, (f w (y i).1 + f w (y i).2)) + (2*(1+γ')*ε + L/(2*γ'*(n:ℝ)))\n < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)}\n ≤ ((C₁.card * C₂.card : ℕ) : ENNReal) * ENNReal.ofReal (Real.exp (-L)) := by\n classical\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hsubset : {A : Fin n → Bool | ∃ w : ι,\n γ' * ((1/(n:ℝ)) * ∑ i, (f w (y i).1 + f w (y i).2)) + (2*(1+γ')*ε + L/(2*γ'*(n:ℝ)))\n < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)}\n ⊆ ⋃ p ∈ C₁ ×ˢ C₂, {A : Fin n → Bool |\n (n:ℝ) * (γ' * ((1/(n:ℝ)) * ∑ i, (p.1 (y i).1 + p.2 (y i).2)) + L/(2*γ'*(n:ℝ)))\n ≤ ∑ i, sgnb A i * (p.2 (y i).2 - p.1 (y i).1)} := by\n rintro A ⟨w, hw⟩\n obtain ⟨g, hgC, hg⟩ := hcov₁ w\n obtain ⟨h, hhC, hh⟩ := hcov₂ w\n refine Set.mem_biUnion (show (g,h) ∈ C₁ ×ˢ C₂ from Finset.mem_product.2 ⟨hgC, hhC⟩) ?_\n simp only [Set.mem_setOf_eq]\n -- notation\n set Sw : ℝ := ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1) with hSw\n set Sgh : ℝ := ∑ i, sgnb A i * (h (y i).2 - g (y i).1) with hSgh\n set Tw : ℝ := ∑ i, (f w (y i).1 + f w (y i).2) with hTw\n set Tgh : ℝ := ∑ i, (g (y i).1 + h (y i).2) with hTgh\n have hd1 : Sw - Sgh ≤ ∑ i, (|f w (y i).1 - g (y i).1| + |f w (y i).2 - h (y i).2|) := by\n rw [hSw, hSgh, ← Finset.sum_sub_distrib]\n apply Finset.sum_le_sum\n intro i _\n have heq : sgnb A i * (f w (y i).2 - f w (y i).1) - sgnb A i * (h (y i).2 - g (y i).1)\n = sgnb A i * ((f w (y i).2 - h (y i).2) - (f w (y i).1 - g (y i).1)) := by ring\n rw [heq]\n calc sgnb A i * ((f w (y i).2 - h (y i).2) - (f w (y i).1 - g (y i).1))\n ≤ |sgnb A i * ((f w (y i).2 - h (y i).2) - (f w (y i).1 - g (y i).1))| := le_abs_self _\n _ = |(f w (y i).2 - h (y i).2) - (f w (y i).1 - g (y i).1)| := by\n rw [abs_mul, abs_sgnb, one_mul]\n _ ≤ |f w (y i).2 - h (y i).2| + |f w (y i).1 - g (y i).1| := abs_sub _ _\n _ = |f w (y i).1 - g (y i).1| + |f w (y i).2 - h (y i).2| := by ring\n have hd2 : Tgh - Tw ≤ ∑ i, (|f w (y i).1 - g (y i).1| + |f w (y i).2 - h (y i).2|) := by\n rw [hTgh, hTw, ← Finset.sum_sub_distrib]\n apply Finset.sum_le_sum\n intro i _\n have heq : (g (y i).1 + h (y i).2) - (f w (y i).1 + f w (y i).2)\n = -(f w (y i).1 - g (y i).1) + -(f w (y i).2 - h (y i).2) := by ring\n rw [heq]\n have b1 : -(f w (y i).1 - g (y i).1) ≤ |f w (y i).1 - g (y i).1| := neg_le_abs _\n have b2 : -(f w (y i).2 - h (y i).2) ≤ |f w (y i).2 - h (y i).2| := neg_le_abs _\n linarith\n have hcovsum : ∑ i, (|f w (y i).1 - g (y i).1| + |f w (y i).2 - h (y i).2|) ≤ 2*(n:ℝ)*ε := by\n rw [Finset.sum_add_distrib]\n rw [div_mul_eq_mul_div, one_mul, div_le_iff₀ hn'] at hg hh\n linarith\n have hne : (n:ℝ) ≠ 0 := ne_of_gt hn'\n have hγne : γ' ≠ 0 := ne_of_gt hγ'\n have hmul := mul_lt_mul_of_pos_left hw hn'\n have e1 : (n:ℝ) * (γ' * (1/(n:ℝ) * Tw) + (2*(1+γ')*ε + L/(2*γ'*(n:ℝ))))\n = γ' * Tw + (n:ℝ)*(2*(1+γ')*ε) + L/(2*γ') := by field_simp; ring\n have e2 : (n:ℝ) * (1/(n:ℝ) * Sw) = Sw := by field_simp\n rw [e1, e2] at hmul\n have e3 : (n:ℝ) * (γ' * (1/(n:ℝ) * Tgh) + L/(2*γ'*(n:ℝ))) = γ' * Tgh + L/(2*γ') := by\n field_simp\n show (n:ℝ) * (γ' * (1/(n:ℝ) * Tgh) + L/(2*γ'*(n:ℝ))) ≤ Sgh\n rw [e3]\n have h5 : γ' * Tgh ≤ γ' * (Tw + 2*(n:ℝ)*ε) := by nlinarith [hd2, hcovsum, hγ'.le]\n linarith [hd1, hcovsum, hmul, h5]\n calc (Rm n) {A : Fin n → Bool | ∃ w : ι,\n γ' * ((1/(n:ℝ)) * ∑ i, (f w (y i).1 + f w (y i).2)) + (2*(1+γ')*ε + L/(2*γ'*(n:ℝ)))\n < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)}\n ≤ (Rm n) (⋃ p ∈ C₁ ×ˢ C₂, {A : Fin n → Bool |\n (n:ℝ) * (γ' * ((1/(n:ℝ)) * ∑ i, (p.1 (y i).1 + p.2 (y i).2)) + L/(2*γ'*(n:ℝ)))\n ≤ ∑ i, sgnb A i * (p.2 (y i).2 - p.1 (y i).1)}) := measure_mono hsubset\n _ ≤ ∑ p ∈ C₁ ×ˢ C₂, (Rm n) {A : Fin n → Bool |\n (n:ℝ) * (γ' * ((1/(n:ℝ)) * ∑ i, (p.1 (y i).1 + p.2 (y i).2)) + L/(2*γ'*(n:ℝ)))\n ≤ ∑ i, sgnb A i * (p.2 (y i).2 - p.1 (y i).1)} := measure_biUnion_finset_le _ _\n _ ≤ ∑ _p ∈ C₁ ×ˢ C₂, ENNReal.ofReal (Real.exp (-L)) := by\n apply Finset.sum_le_sum\n rintro ⟨g, h⟩ hp\n rw [Finset.mem_product] at hp\n obtain ⟨hgC, hhC⟩ := hp\n set T : ℝ := (1/(n:ℝ)) * ∑ i, (g (y i).1 + h (y i).2) with hT\n have hT0 : 0 ≤ T := by\n rw [hT]\n apply mul_nonneg (by positivity)\n apply Finset.sum_nonneg\n intro i _\n have a1 := (hC₁01 g hgC (y i).1).1\n have a2 := (hC₂01 h hhC (y i).2).1\n linarith\n refine rad_tail_le _ ((n:ℝ) * (γ' * T + L/(2*γ'*(n:ℝ)))) ((n:ℝ)*T) L ?_ ?_ ?_\n · have : 0 < L/(2*γ'*(n:ℝ)) := by positivity\n have : 0 ≤ γ' * T := mul_nonneg hγ'.le hT0\n nlinarith\n · calc ∑ i, (h (y i).2 - g (y i).1)^2 ≤ ∑ i, (g (y i).1 + h (y i).2) := by\n apply Finset.sum_le_sum\n intro i _\n have a1 := hC₁01 g hgC (y i).1\n have a2 := hC₂01 h hhC (y i).2\n simp only [Set.mem_Icc] at a1 a2\n nlinarith [a1.1, a1.2, a2.1, a2.2]\n _ = (n:ℝ)*T := by rw [hT]; field_simp\n · have e1 : (n:ℝ) * (γ' * T + L/(2*γ'*(n:ℝ))) = (n:ℝ)*γ'*T + L/(2*γ') := by\n field_simp\n rw [e1]\n have h4 : 4 * ((n:ℝ)*γ'*T) * (L/(2*γ')) ≤ ((n:ℝ)*γ'*T + L/(2*γ'))^2 := by\n nlinarith [sq_nonneg ((n:ℝ)*γ'*T - L/(2*γ'))]\n have e2 : 4 * ((n:ℝ)*γ'*T) * (L/(2*γ')) = 2*((n:ℝ)*T)*L := by\n field_simp; ring\n linarith\n _ = ((C₁.card * C₂.card : ℕ) : ENNReal) * ENNReal.ofReal (Real.exp (-L)) := by\n rw [Finset.sum_const, nsmul_eq_mul, Finset.card_product]\n\n\n/-! ### Chernoff bounds -/\n\nlemma exp_neg_quad (x : ℝ) (hx : 0 ≤ x) : Real.exp (-x) ≤ 1 - x + x^2/2 := by\n have hderiv : ∀ t : ℝ, HasDerivAt (fun t : ℝ => 1 - t + t^2/2 - Real.exp (-t))\n (-1 + t + Real.exp (-t)) t := by\n intro t\n have h1 : HasDerivAt (fun t : ℝ => 1 - t + t^2/2) (-1 + t) t := by\n have : HasDerivAt (fun t : ℝ => t^2/2) t t := by\n simpa using ((hasDerivAt_pow 2 t).div_const 2)\n simpa using ((hasDerivAt_const t (1:ℝ)).sub (hasDerivAt_id t)).add this\n have h2 : HasDerivAt (fun t : ℝ => Real.exp (-t)) (-Real.exp (-t)) t := by\n simpa using (Real.hasDerivAt_exp (-t)).comp t ((hasDerivAt_id t).neg)\n simpa using h1.sub h2\n have hdiff : Differentiable ℝ (fun t : ℝ => 1 - t + t^2/2 - Real.exp (-t)) :=\n fun t => (hderiv t).differentiableAt\n have hmono : Monotone (fun t : ℝ => 1 - t + t^2/2 - Real.exp (-t)) := by\n apply monotone_of_deriv_nonneg hdiff\n intro t\n rw [(hderiv t).deriv]\n have := Real.add_one_le_exp (-t)\n linarith\n have := hmono hx\n simp only at this\n norm_num at this\n linarith\n\n\nvariable {𝒵 : Type*} [MeasurableSpace 𝒵]\n\nnoncomputable def Pm (D : Measure 𝒵) (n : ℕ) : Measure (Fin n → 𝒵) := Measure.pi (fun _ => D)\n\ninstance (D : Measure 𝒵) [IsProbabilityMeasure D] (n : ℕ) : IsProbabilityMeasure (Pm D n) := by\n unfold Pm; infer_instance\n\nlemma pi_integral_eval (D : Measure 𝒵) [IsProbabilityMeasure D]\n {n : ℕ} (i : Fin n) (h : 𝒵 → ℝ) (hh : AEStronglyMeasurable h D) :\n ∫ S, h (S i) ∂(Pm D n) = ∫ z, h z ∂D := by\n have hmp := measurePreserving_eval (fun _ : Fin n => D) i\n have hmap : Measure.map (Function.eval i) (Pm D n) = D := by rw [Pm]; exact hmp.map_eq\n have hh' : AEStronglyMeasurable h (Measure.map (Function.eval i) (Pm D n)) := by\n rw [hmap]; exact hh\n calc ∫ S, h (S i) ∂(Pm D n)\n = ∫ z, h z ∂(Measure.map (Function.eval i) (Pm D n)) := by\n rw [integral_map ((measurable_pi_apply i).aemeasurable) hh']\n _ = ∫ z, h z ∂D := by rw [hmap]\n\nlemma iIndep_coords (D : Measure 𝒵) [IsProbabilityMeasure D] (n : ℕ) :\n iIndepFun (fun (i : Fin n) (S : Fin n → 𝒵) => S i) (Pm D n) := by\n have := iIndepFun_pi (μ := fun _ : Fin n => D) (X := fun _ => (id : 𝒵 → 𝒵))\n (fun i => aemeasurable_id)\n simpa [Pm] using this\n\nlemma mult_chernoff (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) (hn : 0 < n) (g : 𝒵 → ℝ) (hg : Measurable g) (hg01 : ∀ z, g z ∈ Set.Icc (0:ℝ) 1)\n (γ : ℝ) (hγ0 : 0 < γ) (hγ1 : γ < 1) (c : ℝ) :\n (Pm D n).real {S | (1/(n:ℝ)) * ∑ i, g (S i) ≤ (1-γ) * (∫ z, g z ∂D) - c}\n ≤ Real.exp (-(2*γ*(n:ℝ)*c)) := by\n classical\n set p : ℝ := ∫ z, g z ∂D with hp\n have hgint : Integrable g D := Integrable.of_mem_Icc 0 1 hg.aemeasurable (ae_of_all _ hg01)\n have hp0 : 0 ≤ p := integral_nonneg (fun z => (hg01 z).1)\n set Y : Fin n → (Fin n → 𝒵) → ℝ := fun i S => g (S i) with hY\n have hYmeas : ∀ i, Measurable (Y i) := fun i => hg.comp (measurable_pi_apply i)\n have hindep : iIndepFun Y (Pm D n) := (iIndep_coords D n).comp (fun _ => g) (fun _ => hg)\n set X : (Fin n → 𝒵) → ℝ := fun S => ∑ i, Y i S with hX\n have hXeq : (∑ i ∈ Finset.univ, Y i) = X := by funext S; simp [hX]\n -- the mgf bound\n set lam : ℝ := 2*γ with hlam\n have hmgfY : ∀ i, mgf (Y i) (Pm D n) (-lam) = ∫ z, Real.exp (-lam * g z) ∂D := by\n intro i\n rw [mgf]\n exact pi_integral_eval D i (fun z => Real.exp (-lam * g z))\n ((hg.const_mul _).exp.aestronglyMeasurable)\n have hm_le : (∫ z, Real.exp (-lam * g z) ∂D) ≤ 1 - p * (1 - Real.exp (-lam)) := by\n have hpt : ∀ z, Real.exp (-lam * g z) ≤ 1 - g z * (1 - Real.exp (-lam)) := by\n intro z\n obtain ⟨h0, h1⟩ := hg01 z\n have hconv := (convexOn_exp).2 (Set.mem_univ (0:ℝ)) (Set.mem_univ (-lam))\n (by linarith : (0:ℝ) ≤ 1 - g z) h0 (by ring)\n simp only [smul_eq_mul, Real.exp_zero, mul_one] at hconv\n have : (1 - g z) * (0:ℝ) + g z * (-lam) = -lam * g z := by ring\n rw [this] at hconv\n nlinarith [hconv]\n have hint1 : Integrable (fun z => Real.exp (-lam * g z)) D :=\n Integrable.of_mem_Icc 0 (Real.exp 0) ((hg.const_mul _).exp.aemeasurable)\n (ae_of_all _ (fun z => ⟨(Real.exp_pos _).le, by\n apply Real.exp_le_exp.2\n have h0 : (0:ℝ) ≤ g z := (hg01 z).1\n have : (0:ℝ) < lam := by rw [hlam]; linarith\n nlinarith⟩))\n have hint2 : Integrable (fun z => 1 - g z * (1 - Real.exp (-lam))) D := by\n apply Integrable.sub (integrable_const 1)\n exact hgint.mul_const _\n have := integral_mono hint1 hint2 hpt\n rw [integral_sub (integrable_const 1) (hgint.mul_const _)] at this\n simpa [integral_mul_const, hp] using this\n -- pointwise bounds on X\n have hXnn : ∀ S, 0 ≤ X S := by\n intro S; exact Finset.sum_nonneg (fun i _ => (hg01 (S i)).1)\n have hXmeas : Measurable X := by\n apply Finset.measurable_sum; intro i _; exact hYmeas i\n have hlam0 : 0 < lam := by rw [hlam]; linarith\n have hint : Integrable (fun S => Real.exp (-lam * X S)) (Pm D n) := by\n apply Integrable.of_mem_Icc 0 1 ((hXmeas.const_mul _).exp.aemeasurable)\n filter_upwards with S\n refine ⟨(Real.exp_pos _).le, ?_⟩\n rw [show (1:ℝ) = Real.exp 0 by simp]\n apply Real.exp_le_exp.2\n nlinarith [hXnn S]\n have hevent : {S : Fin n → 𝒵 | (1/(n:ℝ)) * ∑ i, g (S i) ≤ (1-γ) * p - c}\n = {S | X S ≤ (n:ℝ) * ((1-γ)*p - c)} := by\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n ext S\n simp only [Set.mem_setOf_eq, hX, hY]\n rw [div_mul_eq_mul_div, one_mul, div_le_iff₀ hn']\n constructor <;> intro h <;> nlinarith [h]\n have hcher := measure_le_le_exp_mul_mgf (μ := Pm D n) (X := X)\n ((n:ℝ)*((1-γ)*p - c)) (t := -lam) (by linarith) hint\n have hmgfX : mgf X (Pm D n) (-lam) = ∏ _i : Fin n, (∫ z, Real.exp (-lam * g z) ∂D) := by\n rw [← hXeq, hindep.mgf_sum hYmeas Finset.univ]\n exact Finset.prod_congr rfl (fun i _ => hmgfY i)\n have hmnn : 0 ≤ ∫ z, Real.exp (-lam * g z) ∂D :=\n integral_nonneg (fun z => (Real.exp_pos _).le)\n have hmgf_le : mgf X (Pm D n) (-lam) ≤ Real.exp (-((n:ℝ) * p * (1 - Real.exp (-lam)))) := by\n rw [hmgfX, Finset.prod_const, Finset.card_univ, Fintype.card_fin]\n calc (∫ z, Real.exp (-lam * g z) ∂D)^n\n ≤ (Real.exp (-(p * (1 - Real.exp (-lam)))))^n := by\n apply pow_le_pow_left₀ hmnn\n refine hm_le.trans ?_\n have := Real.add_one_le_exp (-(p * (1 - Real.exp (-lam))))\n linarith\n _ = Real.exp (-((n:ℝ) * p * (1 - Real.exp (-lam)))) := by\n rw [← Real.exp_nat_mul]; congr 1; ring\n rw [hevent]\n refine hcher.trans ?_\n calc Real.exp (-(-lam) * ((n:ℝ)*((1-γ)*p - c))) * mgf X (Pm D n) (-lam)\n ≤ Real.exp (-(-lam) * ((n:ℝ)*((1-γ)*p - c))) * Real.exp (-((n:ℝ) * p * (1 - Real.exp (-lam)))) := by\n apply mul_le_mul_of_nonneg_left hmgf_le (Real.exp_pos _).le\n _ = Real.exp (lam * ((n:ℝ)*((1-γ)*p - c)) - (n:ℝ) * p * (1 - Real.exp (-lam))) := by\n rw [← Real.exp_add]; congr 1; ring\n _ ≤ Real.exp (-(2*γ*(n:ℝ)*c)) := by\n apply Real.exp_le_exp.2\n have hq : Real.exp (-(2*γ)) ≤ 1 - 2*γ + (2*γ)^2/2 := exp_neg_quad (2*γ) (by linarith)\n have hn0 : (0:ℝ) ≤ n := Nat.cast_nonneg n\n rw [hlam]\n have hbr : 2*γ*(1-γ) - 1 + Real.exp (-(2*γ)) ≤ 0 := by nlinarith [hq]\n have key : ((n:ℝ)*p) * (2*γ*(1-γ) - 1 + Real.exp (-(2*γ))) ≤ 0 :=\n mul_nonpos_of_nonneg_of_nonpos (mul_nonneg hn0 hp0) hbr\n nlinarith [key]\n\n\nlemma add_hoeffding (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) (hn : 0 < n) (g : 𝒵 → ℝ) (hg : Measurable g) (hg01 : ∀ z, g z ∈ Set.Icc (0:ℝ) 1)\n (u : ℝ) (hu : 0 ≤ u) :\n (Pm D n).real {S | (1/(n:ℝ)) * ∑ i, g (S i) ≤ (∫ z, g z ∂D) - u}\n ≤ Real.exp (-(2*(n:ℝ)*u^2)) := by\n classical\n set p : ℝ := ∫ z, g z ∂D with hp\n have hgint : Integrable g D := Integrable.of_mem_Icc 0 1 hg.aemeasurable (ae_of_all _ hg01)\n set W : Fin n → (Fin n → 𝒵) → ℝ := fun i S => p - g (S i) with hW\n have hWmeas : ∀ i, Measurable (W i) := fun i => measurable_const.sub (hg.comp (measurable_pi_apply i))\n have hindep : iIndepFun W (Pm D n) :=\n (iIndep_coords D n).comp (fun _ => fun z => p - g z) (fun _ => measurable_const.sub hg)\n have hsub : ∀ i : Fin n, HasSubgaussianMGF (W i) (1/4 : NNReal) (Pm D n) := by\n intro i\n have hmean : ∫ S, W i S ∂(Pm D n) = 0 := by\n have : ∫ S, W i S ∂(Pm D n) = ∫ z, (p - g z) ∂D :=\n pi_integral_eval D i (fun z => p - g z) (by fun_prop)\n rw [this, integral_sub (integrable_const p) hgint]\n simp [hp]\n have hbdd : ∀ᵐ S ∂(Pm D n), W i S ∈ Set.Icc (p - 1) (p - 0) := by\n filter_upwards with S\n obtain ⟨h0, h1⟩ := hg01 (S i)\n constructor <;> simp [hW] <;> linarith\n have h2 := hasSubgaussianMGF_of_mem_Icc_of_integral_eq_zero (μ := Pm D n) (X := W i)\n (hWmeas i).aemeasurable hbdd hmean\n have heq : (‖(p - 0) - (p - 1)‖₊ / 2) ^ 2 = (1/4 : NNReal) := by\n apply NNReal.coe_injective\n push_cast\n norm_num\n rwa [heq] at h2\n have hmain := ProbabilityTheory.HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hindep\n (c := fun _ => (1/4 : NNReal)) (s := Finset.univ) (fun i _ => hsub i)\n (ε := (n:ℝ)*u) (by positivity)\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hevent : {S : Fin n → 𝒵 | (1/(n:ℝ)) * ∑ i, g (S i) ≤ p - u}\n = {S | (n:ℝ)*u ≤ ∑ i, W i S} := by\n ext S\n simp only [Set.mem_setOf_eq, hW, Finset.sum_sub_distrib]\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n rw [div_mul_eq_mul_div, one_mul, div_le_iff₀ hn']\n constructor <;> intro h <;> nlinarith [h]\n rw [hevent]\n refine hmain.trans ?_\n apply Real.exp_le_exp.2\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n push_cast\n rw [div_le_iff₀ (by positivity)]\n ring_nf\n nlinarith [sq_nonneg u, hn'.le]\n\n\n/-! ### Symmetrization -/\n\nnoncomputable def Qm (D : Measure 𝒵) (n : ℕ) : Measure (Fin n → 𝒵 × 𝒵) :=\n Measure.pi (fun _ => D.prod D)\n\ninstance (D : Measure 𝒵) [IsProbabilityMeasure D] (n : ℕ) : IsProbabilityMeasure (Qm D n) := by\n unfold Qm; infer_instance\n\ndef swapY {n : ℕ} (A : Fin n → Bool) (y : Fin n → 𝒵 × 𝒵) : Fin n → 𝒵 × 𝒵 :=\n fun i => if A i then (y i).swap else y i\n\nlemma measurable_swapY {n : ℕ} (A : Fin n → Bool) :\n Measurable (swapY A : (Fin n → 𝒵 × 𝒵) → (Fin n → 𝒵 × 𝒵)) := by\n apply measurable_pi_lambda\n intro i\n by_cases h : A i <;> simp only [swapY, h, if_true, if_false, reduceIte]\n · exact measurable_swap.comp (measurable_pi_apply i)\n · exact measurable_pi_apply i\n\nlemma measurable_swapY_prod {n : ℕ} :\n Measurable (fun q : (Fin n → Bool) × (Fin n → 𝒵 × 𝒵) => swapY q.1 q.2) := by\n apply measurable_pi_lambda\n intro i\n have hset : MeasurableSet {q : (Fin n → Bool) × (Fin n → 𝒵 × 𝒵) | q.1 i = true} := by\n have he : {q : (Fin n → Bool) × (Fin n → 𝒵 × 𝒵) | q.1 i = true}\n = (fun q : (Fin n → Bool) × (Fin n → 𝒵 × 𝒵) => q.1 i) ⁻¹' {true} := rfl\n rw [he]\n exact ((measurable_pi_apply i).comp measurable_fst) (measurableSet_singleton true)\n show Measurable (fun q : (Fin n → Bool) × (Fin n → 𝒵 × 𝒵) =>\n if q.1 i then (q.2 i).swap else q.2 i)\n exact Measurable.ite hset (measurable_swap.comp ((measurable_pi_apply i).comp measurable_snd))\n ((measurable_pi_apply i).comp measurable_snd)\n\nlemma swapY_map (D : Measure 𝒵) [IsProbabilityMeasure D] (n : ℕ) (A : Fin n → Bool) :\n Measure.map (swapY A) (Qm D n) = Qm D n := by\n classical\n rw [Qm]\n refine (Measure.pi_eq (μ := fun _ : Fin n => D.prod D) ?_).symm\n intro s hs\n rw [Measure.map_apply (measurable_swapY A) (MeasurableSet.univ_pi hs)]\n have hpre : (swapY A) ⁻¹' (Set.univ.pi s)\n = Set.univ.pi (fun i => if A i then Prod.swap ⁻¹' (s i) else s i) := by\n ext y\n simp only [Set.mem_preimage, Set.mem_univ_pi, swapY]\n constructor\n · intro h i\n have := h i\n by_cases hA : A i <;> simp [hA] at this ⊢ <;> exact this\n · intro h i\n have := h i\n by_cases hA : A i <;> simp [hA] at this ⊢ <;> exact this\n rw [hpre, Measure.pi_pi]\n apply Finset.prod_congr rfl\n intro i _\n by_cases hA : A i\n · simp only [hA, if_true]\n rw [← Measure.map_apply measurable_swap (hs i), Measure.prod_swap]\n · simp [hA]\n\nlemma symmetrization (D : Measure 𝒵) [IsProbabilityMeasure D] (n : ℕ)\n {G : Set (Fin n → 𝒵 × 𝒵)} (hG : MeasurableSet G) :\n Qm D n G = ∫⁻ y, (Rm n) {A | swapY A y ∈ G} ∂(Qm D n) := by\n set T : (Fin n → Bool) × (Fin n → 𝒵 × 𝒵) → (Fin n → 𝒵 × 𝒵) := fun q => swapY q.1 q.2 with hT\n have hTm : Measurable T := measurable_swapY_prod\n have h2 : ((Rm n).prod (Qm D n)) (T ⁻¹' G) = ∫⁻ y, (Rm n) {A | swapY A y ∈ G} ∂(Qm D n) := by\n rw [Measure.prod_apply_symm (hTm hG)]\n rfl\n have h1 : ((Rm n).prod (Qm D n)) (T ⁻¹' G) = Qm D n G := by\n rw [Measure.prod_apply (hTm hG)]\n have : ∀ A : Fin n → Bool, (Qm D n) (Prod.mk A ⁻¹' (T ⁻¹' G)) = Qm D n G := by\n intro A\n have : Prod.mk A ⁻¹' (T ⁻¹' G) = (swapY A) ⁻¹' G := rfl\n rw [this, ← Measure.map_apply (measurable_swapY A) hG, swapY_map]\n simp_rw [this]\n simp\n rw [← h1, h2]\n\n\n/-! ### Union of events / selection -/\n\nlemma combine {X : Type*} [MeasurableSpace X] (P : Measure X) [IsProbabilityMeasure P]\n {ι : Type*} [Countable ι] [Nonempty ι] (a : ι → ℝ) (V Tr : X → ι → ℝ)\n (hV : ∀ w, Measurable (fun S => V S w)) (hTr : ∀ w, Measurable (fun S => Tr S w))\n (c₁ c₂ δ δ₁ δ₂ : ℝ) (hδ₂0 : 0 ≤ δ₂) (hδ₂1 : δ₂ < 1) (hδ0 : 0 ≤ δ)\n (h1 : (P.prod P) {q | ∃ w, Tr q.1 w + c₁ < V q.2 w} ≤ ENNReal.ofReal δ₁)\n (h2 : ∀ w, P {S | V S w + c₂ < a w} ≤ ENNReal.ofReal δ₂)\n (hcond : δ₁ ≤ δ * (1 - δ₂)) :\n P {S | ∃ w, Tr S w + (c₁ + c₂) < a w} ≤ ENNReal.ofReal δ := by\n classical\n obtain ⟨e, he⟩ : ∃ e : ℕ → ι, Function.Surjective e := exists_surjective_nat ι\n set Bad : ��� → Set X := fun k => {S | Tr S (e k) + (c₁+c₂) < a (e k)} with hBad\n have hBadm : ∀ k, MeasurableSet (Bad k) := by\n intro k\n exact measurableSet_lt ((hTr (e k)).add_const _) measurable_const\n set U : ℕ → Set X := disjointed Bad with hU\n have hUm : ∀ k, MeasurableSet (U k) := fun k => MeasurableSet.disjointed hBadm k\n have hUdisj : Pairwise (Function.onFun Disjoint U) := disjoint_disjointed Bad\n have hUunion : (⋃ k, U k) = {S | ∃ w, Tr S w + (c₁ + c₂) < a w} := by\n rw [hU, iUnion_disjointed]\n ext S\n simp only [Set.mem_iUnion, Set.mem_setOf_eq, hBad]\n constructor\n · rintro ⟨k, hk⟩; exact ⟨e k, hk⟩\n · rintro ⟨w, hw⟩\n obtain ⟨k, rfl⟩ := he w\n exact ⟨k, hw⟩\n set Good : ℕ → Set X := fun k => {S | a (e k) ≤ V S (e k) + c₂} with hGood\n have hGoodm : ∀ k, MeasurableSet (Good k) := by\n intro k\n exact measurableSet_le measurable_const ((hV (e k)).add_const _)\n have hGoodP : ∀ k, ENNReal.ofReal (1-δ₂) ≤ P (Good k) := by\n intro k\n have hc : (Good k)ᶜ = {S | V S (e k) + c₂ < a (e k)} := by\n ext S; simp [hGood, not_le]\n have h3 : P ((Good k)ᶜ) ≤ ENNReal.ofReal δ₂ := by rw [hc]; exact h2 (e k)\n have h4 : P (Good k) = 1 - P ((Good k)ᶜ) := by\n rw [measure_compl (hGoodm k) (measure_ne_top _ _)]\n rw [measure_univ]\n rw [ENNReal.sub_sub_cancel ENNReal.one_ne_top prob_le_one]\n rw [h4]\n have : (1:ENNReal) - ENNReal.ofReal δ₂ ≤ 1 - P ((Good k)ᶜ) := tsub_le_tsub_left h3 1\n refine le_trans ?_ this\n rw [ENNReal.ofReal_sub _ hδ₂0]\n simp\n have hsub : (⋃ k, (U k) ×ˢ (Good k)) ⊆ {q : X × X | ∃ w, Tr q.1 w + c₁ < V q.2 w} := by\n rintro ⟨S, S'⟩ hq\n simp only [Set.mem_iUnion, Set.mem_prod] at hq\n obtain ⟨k, hS, hS'⟩ := hq\n refine ⟨e k, ?_⟩\n have h5 : Tr S (e k) + (c₁+c₂) < a (e k) := (disjointed_le Bad k hS)\n have h6 : a (e k) ≤ V S' (e k) + c₂ := hS'\n linarith\n have hdisj2 : Pairwise (Function.onFun Disjoint (fun k => (U k) ×ˢ (Good k))) := by\n intro i j hij\n have := hUdisj hij\n simp only [Function.onFun, Set.disjoint_left] at this ⊢\n rintro ⟨S, S'⟩ h1 h2\n exact this h1.1 h2.1\n have key : ENNReal.ofReal (1-δ₂) * P {S | ∃ w, Tr S w + (c₁ + c₂) < a w} ≤ ENNReal.ofReal δ₁ := by\n rw [← hUunion, measure_iUnion hUdisj hUm, ENNReal.tsum_mul_left.symm]\n calc ∑' k, ENNReal.ofReal (1-δ₂) * P (U k)\n ≤ ∑' k, P (Good k) * P (U k) :=\n ENNReal.tsum_le_tsum (fun k => mul_le_mul_right' (hGoodP k) _)\n _ = ∑' k, (P.prod P) ((U k) ×ˢ (Good k)) := by\n refine tsum_congr (fun k => ?_)\n rw [Measure.prod_prod, mul_comm]\n _ = (P.prod P) (⋃ k, (U k) ×ˢ (Good k)) :=\n (measure_iUnion hdisj2 (fun k => (hUm k).prod (hGoodm k))).symm\n _ ≤ (P.prod P) {q : X × X | ∃ w, Tr q.1 w + c₁ < V q.2 w} := measure_mono hsub\n _ ≤ ENNReal.ofReal δ₁ := h1\n have hpos : ENNReal.ofReal (1-δ₂) ≠ 0 := by\n simp [ENNReal.ofReal_eq_zero]; linarith\n have hfin : ENNReal.ofReal (1-δ₂) ≠ ⊤ := ENNReal.ofReal_ne_top\n rw [mul_comm] at key\n have := (ENNReal.le_div_iff_mul_le (Or.inl hpos) (Or.inl hfin)).2 key\n refine this.trans ?_\n rw [ENNReal.div_le_iff hpos hfin, ← ENNReal.ofReal_mul hδ0]\n exact ENNReal.ofReal_le_ofReal hcond\n\n\n/-! ### swap identities -/\n\nlemma swap_diff {𝒵 ι : Type*} (f : ι → 𝒵 → ℝ) {n : ℕ} (A : Fin n → Bool)\n (y : Fin n → 𝒵 × 𝒵) (w : ι) :\n (1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).2 - (1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).1\n = (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1) := by\n rw [← mul_sub, ← Finset.sum_sub_distrib]\n congr 1\n apply Finset.sum_congr rfl\n intro i _\n by_cases h : A i <;> simp [swapY, sgnb, h] <;> ring\n\nlemma swap_sum {𝒵 ι : Type*} (f : ι → 𝒵 → ℝ) {n : ℕ} (A : Fin n → Bool)\n (y : Fin n → 𝒵 × 𝒵) (w : ι) :\n ∑ i, (f w ((swapY A y) i).1 + f w ((swapY A y) i).2)\n = ∑ i, (f w (y i).1 + f w (y i).2) := by\n apply Finset.sum_congr rfl\n intro i _\n by_cases h : A i <;> simp [swapY, h] <;> ring\n\n/-! ### transport between the double sample space and the product space -/\n\nlemma Qm_to_prod {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) {B : Set ((Fin n → 𝒵) × (Fin n → 𝒵))} (hB : MeasurableSet B) :\n ((Pm D n).prod (Pm D n)) B\n = (Qm D n) {y : Fin n → 𝒵 × 𝒵 | ((fun i => (y i).1), (fun i => (y i).2)) ∈ B} := by\n have he := measurePreserving_arrowProdEquivProdArrow 𝒵 𝒵 (Fin n) (fun _ => D) (fun _ => D)\n have h1 : (Qm D n) ((MeasurableEquiv.arrowProdEquivProdArrow 𝒵 𝒵 (Fin n)) ⁻¹' B)\n = ((Pm D n).prod (Pm D n)) B := by\n have := he.measure_preimage hB.nullMeasurableSet\n simpa [Qm, Pm] using this\n rw [← h1]\n rfl\n\n/-! ### Core theorem, additive version -/\n\ntheorem core1 {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵) [IsProbabilityMeasure D]\n {ι : Type*} [Countable ι] [Nonempty ι]\n (f : ι → 𝒵 → ℝ) (hfm : ∀ w, Measurable (f w)) (hf01 : ∀ w z, f w z ∈ Set.Icc (0:ℝ) 1)\n (n : ℕ) (hn : 0 < n) (ε : ℝ) (hε : 0 < ε) (N : ℕ) (hN : 1 ≤ N)\n (hcov : ∀ᵐ y ∂(Qm D n), ∃ C : Finset (𝒵 → ℝ), C.card ≤ N ∧\n (∀ g ∈ C, ∀ z, g z ∈ Set.Icc (0:ℝ) 1) ∧\n ∀ w : ι, ∃ g ∈ C, (1/(2*(n:ℝ))) *\n ∑ i, (|f w (y i).1 - g (y i).1| + |f w (y i).2 - g (y i).2|) ≤ ε)\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1) :\n (Pm D n) {S | ∃ w : ι, (1/(n:ℝ)) * ∑ i, f w (S i)\n + (2*ε + 3 * Real.sqrt (Real.log (3*(N:ℝ)/δ)/(2*(n:ℝ)))) < ∫ z, f w z ∂D}\n ≤ ENNReal.ofReal δ := by\n classical\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hN' : (1:ℝ) ≤ (N:ℝ) := by exact_mod_cast hN\n set δ₁ : ℝ := 2*δ/3 with hδ₁def\n set δ₂ : ℝ := δ/3 with hδ₂def\n have hδ₁0 : 0 < δ₁ := by rw [hδ₁def]; linarith\n have hδ₁1 : δ₁ < 1 := by rw [hδ₁def]; linarith\n have hδ₂0 : 0 < δ₂ := by rw [hδ₂def]; linarith\n have hδ₂1 : δ₂ < 1 := by rw [hδ₂def]; linarith\n set Λ : ℝ := Real.log (3*(N:ℝ)/δ) with hΛdef\n set L : ℝ := Real.log ((N:ℝ)/δ₁) with hLdef\n set L₂ : ℝ := Real.log (1/δ₂) with hL₂def\n have hLΛ : L ≤ Λ := by\n rw [hLdef, hΛdef]\n apply Real.log_le_log (by positivity)\n rw [div_le_div_iff₀ (by positivity) (by positivity)]\n rw [hδ₁def]; nlinarith\n have hL₂Λ : L₂ ≤ Λ := by\n rw [hL₂def, hΛdef]\n apply Real.log_le_log (by positivity)\n rw [hδ₂def, div_le_div_iff₀ (by positivity) (by positivity)]\n nlinarith\n have hL0 : 0 < L := by\n rw [hLdef]\n apply Real.log_pos\n rw [lt_div_iff₀ hδ₁0]; linarith\n have hL₂0 : 0 < L₂ := by\n rw [hL₂def]\n apply Real.log_pos\n rw [lt_div_iff₀ hδ₂0]; linarith\n set s : ℝ := Real.sqrt (2*L/(n:ℝ)) with hsdef\n set u : ℝ := Real.sqrt (L₂/(2*(n:ℝ))) with hudef\n have hs0 : 0 < s := Real.sqrt_pos.2 (by positivity)\n have hu0 : 0 < u := Real.sqrt_pos.2 (by positivity)\n have hs2 : s^2 = 2*L/(n:ℝ) := Real.sq_sqrt (by positivity)\n have hu2 : u^2 = L₂/(2*(n:ℝ)) := Real.sq_sqrt (by positivity)\n -- measurability facts\n have hmeas1 : ∀ w : ι, Measurable (fun y : Fin n → 𝒵 × 𝒵 => (1/(n:ℝ)) * ∑ i, f w (y i).1) := by\n intro w\n apply Measurable.const_mul\n apply Finset.measurable_sum\n intro i _\n exact (hfm w).comp (measurable_fst.comp (measurable_pi_apply i))\n have hmeas2 : ∀ w : ι, Measurable (fun y : Fin n → 𝒵 × 𝒵 => (1/(n:ℝ)) * ∑ i, f w (y i).2) := by\n intro w\n apply Measurable.const_mul\n apply Finset.measurable_sum\n intro i _\n exact (hfm w).comp (measurable_snd.comp (measurable_pi_apply i))\n have hmeasP : ∀ w : ι, Measurable (fun S : Fin n → 𝒵 => (1/(n:ℝ)) * ∑ i, f w (S i)) := by\n intro w\n apply Measurable.const_mul\n apply Finset.measurable_sum\n intro i _\n exact (hfm w).comp (measurable_pi_apply i)\n -- Step 1 : the double sample bound on Qm\n have hQ : (Qm D n) {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w (y i).1 + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (y i).2}\n ≤ ENNReal.ofReal δ₁ := by\n have hGmeas : MeasurableSet {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w (y i).1 + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (y i).2} := by\n have he : {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w (y i).1 + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (y i).2}\n = ⋃ w : ι, {y : Fin n → 𝒵 × 𝒵 |\n (1/(n:ℝ)) * ∑ i, f w (y i).1 + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (y i).2} := by\n ext y; simp\n rw [he]\n exact MeasurableSet.iUnion (fun w =>\n measurableSet_lt ((hmeas1 w).add_const _) (hmeas2 w))\n rw [symmetrization D n hGmeas]\n calc ∫⁻ y, (Rm n) {A | swapY A y ∈ {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w (y i).1 + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (y i).2}}\n ∂(Qm D n)\n ≤ ∫⁻ _y, ENNReal.ofReal δ₁ ∂(Qm D n) := by\n apply lintegral_mono_ae\n filter_upwards [hcov] with y hy\n obtain ⟨C, hcard, hC01, hCcov⟩ := hy\n have hset : {A : Fin n → Bool | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).1 + (2*ε + s)\n < (1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).2}\n = {A : Fin n → Bool | ∃ w : ι,\n 2*ε + s < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)} := by\n ext A\n simp only [Set.mem_setOf_eq]\n constructor\n · rintro ⟨w, hw⟩\n refine ⟨w, ?_⟩\n rw [← swap_diff f A y w]\n linarith\n · rintro ⟨w, hw⟩\n refine ���w, ?_⟩\n rw [← swap_diff f A y w] at hw\n linarith\n rw [hset]\n refine le_trans (pointwise1 hn f hf01 y ε s hs0 C hC01 hCcov L ?_) ?_\n · rw [mul_pow, hs2]\n field_simp\n ring_nf\n nlinarith [hL0.le, hn'.le, sq_nonneg ((n:ℝ))]\n · have hcexp : (C.card : ENNReal) * ENNReal.ofReal (Real.exp (-L))\n ≤ (N : ENNReal) * ENNReal.ofReal (Real.exp (-L)) := by\n apply mul_le_mul_right'\n exact_mod_cast hcard\n refine hcexp.trans ?_\n rw [show ((N:ENNReal)) = ENNReal.ofReal (N:ℝ) by\n simp [ENNReal.ofReal_natCast]]\n rw [← ENNReal.ofReal_mul (by positivity)]\n apply ENNReal.ofReal_le_ofReal\n rw [hLdef, Real.exp_neg, Real.exp_log (by positivity)]\n rw [inv_div]\n field_simp\n norm_num\n _ = ENNReal.ofReal δ₁ := by\n rw [lintegral_const, measure_univ, mul_one]\n -- Step 2 : transport to the product measure\n have hPP : ((Pm D n).prod (Pm D n)) {q : (Fin n → 𝒵) × (Fin n → 𝒵) | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w (q.1 i) + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (q.2 i)}\n ≤ ENNReal.ofReal δ₁ := by\n have hBmeas : MeasurableSet {q : (Fin n → 𝒵) × (Fin n → 𝒵) | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w (q.1 i) + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (q.2 i)} := by\n have he : {q : (Fin n → 𝒵) × (Fin n → 𝒵) | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, f w (q.1 i) + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (q.2 i)}\n = ⋃ w : ι, {q : (Fin n → 𝒵) × (Fin n → 𝒵) |\n (1/(n:ℝ)) * ∑ i, f w (q.1 i) + (2*ε + s) < (1/(n:ℝ)) * ∑ i, f w (q.2 i)} := by\n ext q; simp\n rw [he]\n exact MeasurableSet.iUnion (fun w =>\n measurableSet_lt (((hmeasP w).comp measurable_fst).add_const _)\n ((hmeasP w).comp measurable_snd))\n rw [Qm_to_prod D n hBmeas]\n exact hQ\n -- Step 3 : Chernoff bound for a fixed w\n have hCher : ∀ w : ι, (Pm D n) {S : Fin n → 𝒵 |\n (1/(n:ℝ)) * ∑ i, f w (S i) + u < ∫ z, f w z ∂D} ≤ ENNReal.ofReal δ₂ := by\n intro w\n have h1 := add_hoeffding D n hn (f w) (hfm w) (hf01 w) u hu0.le\n have h2 : {S : Fin n → 𝒵 | (1/(n:ℝ)) * ∑ i, f w (S i) + u < ∫ z, f w z ∂D}\n ⊆ {S : Fin n → 𝒵 | (1/(n:ℝ)) * ∑ i, f w (S i) ≤ (∫ z, f w z ∂D) - u} := by\n intro S hS\n simp only [Set.mem_setOf_eq] at hS ⊢\n linarith\n refine le_trans (measure_mono h2) ?_\n have h3 : (Pm D n) {S : Fin n → 𝒵 | (1/(n:ℝ)) * ∑ i, f w (S i) ≤ (∫ z, f w z ∂D) - u}\n ≤ ENNReal.ofReal (Real.exp (-(2*(n:ℝ)*u^2))) :=\n (ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) (Real.exp_pos _).le).2 h1\n refine h3.trans (ENNReal.ofReal_le_ofReal ?_)\n rw [hu2]\n have : 2*(n:ℝ)*(L₂/(2*(n:ℝ))) = L₂ := by field_simp\n rw [this, hL₂def, Real.exp_neg, Real.exp_log (by positivity)]\n rw [inv_div]\n simp\n -- Step 4 : combination\n have hcomb := combine (Pm D n) (fun w : ι => ∫ z, f w z ∂D)\n (fun S w => (1/(n:ℝ)) * ∑ i, f w (S i)) (fun S w => (1/(n:ℝ)) * ∑ i, f w (S i))\n hmeasP hmeasP (2*ε + s) u δ δ₁ δ₂ hδ₂0.le hδ₂1 hδ0.le hPP hCher\n (by rw [hδ₁def, hδ₂def]; nlinarith)\n refine le_trans (measure_mono ?_) hcomb\n intro S hS\n simp only [Set.mem_setOf_eq] at hS ⊢\n obtain ⟨w, hw⟩ := hS\n refine ⟨w, ?_⟩\n have hsu : s + u ≤ 3 * Real.sqrt (Λ/(2*(n:ℝ))) := by\n have h1 : s ≤ 2 * Real.sqrt (Λ/(2*(n:ℝ))) := by\n rw [hsdef]\n have he : 2 * Real.sqrt (Λ/(2*(n:ℝ))) = Real.sqrt (4*(Λ/(2*(n:ℝ)))) := by\n rw [show (4:ℝ) = 2^2 by norm_num, Real.sqrt_mul (by positivity),\n Real.sqrt_sq (by norm_num)]\n rw [he]\n apply Real.sqrt_le_sqrt\n rw [div_le_iff₀ hn']\n have : 4*(Λ/(2*(n:ℝ)))*(n:ℝ) = 2*Λ := by field_simp; ring\n rw [this]\n linarith\n have h2 : u ≤ Real.sqrt (Λ/(2*(n:ℝ))) := by\n rw [hudef]\n apply Real.sqrt_le_sqrt\n apply div_le_div_of_nonneg_right hL₂Λ (by positivity)\n linarith\n linarith\n\n/-! ### Core theorem, multiplicative version -/\n\nlemma Qm_fst_measurePreserving {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵)\n [IsProbabilityMeasure D] (n : ℕ) :\n MeasurePreserving (fun y : Fin n → 𝒵 × 𝒵 => fun i => (y i).1) (Qm D n) (Pm D n) := by\n have he := measurePreserving_arrowProdEquivProdArrow 𝒵 𝒵 (Fin n) (fun _ => D) (fun _ => D)\n have he' : MeasurePreserving (MeasurableEquiv.arrowProdEquivProdArrow 𝒵 𝒵 (Fin n))\n (Qm D n) ((Pm D n).prod (Pm D n)) := by simpa [Qm, Pm] using he\n exact (measurePreserving_fst).comp he'\n\nlemma Qm_snd_measurePreserving {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵)\n [IsProbabilityMeasure D] (n : ℕ) :\n MeasurePreserving (fun y : Fin n → 𝒵 × 𝒵 => fun i => (y i).2) (Qm D n) (Pm D n) := by\n have he := measurePreserving_arrowProdEquivProdArrow 𝒵 𝒵 (Fin n) (fun _ => D) (fun _ => D)\n have he' : MeasurePreserving (MeasurableEquiv.arrowProdEquivProdArrow 𝒵 𝒵 (Fin n))\n (Qm D n) ((Pm D n).prod (Pm D n)) := by simpa [Qm, Pm] using he\n exact (measurePreserving_snd).comp he'\n\nset_option maxHeartbeats 1000000 in\ntheorem core2 {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵) [IsProbabilityMeasure D]\n {ι : Type*} [Countable ι] [Nonempty ι]\n (f : ι → 𝒵 → ℝ) (hfm : ∀ w, Measurable (f w)) (hf01 : ∀ w z, f w z ∈ Set.Icc (0:ℝ) 1)\n (n : ℕ) (hn : 0 < n) (ε : ℝ) (hε : 0 < ε) (N : ℕ) (hN : 1 ≤ N)\n (γ : ℝ) (hγ0 : 0 < γ) (hγ1 : γ < 1)\n (hcov : ∀ᵐ S ∂(Pm D n), ∃ C : Finset (𝒵 → ℝ), C.card ≤ N ∧\n (∀ g ∈ C, ∀ z, g z ∈ Set.Icc (0:ℝ) 1) ∧\n ∀ w : ι, ∃ g ∈ C, (1/(n:ℝ)) * ∑ i, |f w (S i) - g (S i)| ≤ ε)\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1) :\n (Pm D n) {S | ∃ w : ι, (1/(n:ℝ)) * ∑ i, f w (S i)\n + (2*ε + (5-4*γ) * Real.log (3*(N:ℝ)/δ) / (2*γ*(n:ℝ))) < (1-γ)^2 * ∫ z, f w z ∂D}\n ≤ ENNReal.ofReal δ := by\n classical\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n have hN' : (1:ℝ) ≤ (N:ℝ) := by exact_mod_cast hN\n have h2γ : (0:ℝ) < 2 - γ := by linarith\n set γ' : ℝ := γ/(2-γ) with hγ'def\n have hγ'0 : 0 < γ' := by rw [hγ'def]; positivity\n have h1pγ' : 1 + γ' = 2/(2-γ) := by rw [hγ'def]; field_simp; ring\n have hprod : (1+γ')*(1-γ) = 1-γ' := by rw [hγ'def]; field_simp; ring\n have h1pγ'0 : 0 < 1 + γ' := by linarith\n set δ₁ : ℝ := 2*δ/3 with hδ₁def\n set δ₂ : ℝ := δ/3 with hδ₂def\n have hδ₁0 : 0 < δ₁ := by rw [hδ₁def]; linarith\n have hδ₁1 : δ₁ < 1 := by rw [hδ₁def]; linarith\n have hδ₂0 : 0 < δ₂ := by rw [hδ₂def]; linarith\n have hδ₂1 : δ₂ < 1 := by rw [hδ₂def]; linarith\n set Λ : ℝ := Real.log (3*(N:ℝ)/δ) with hΛdef\n set L₁ : ℝ := Real.log ((N:ℝ)^2/δ₁) with hL₁def\n set L₂ : ℝ := Real.log (1/δ₂) with hL₂def\n have hΛ0 : 0 ≤ Λ := by\n rw [hΛdef]\n apply Real.log_nonneg\n rw [le_div_iff₀ hδ0]; nlinarith\n have hL₁0 : 0 < L₁ := by\n rw [hL₁def]\n apply Real.log_pos\n rw [lt_div_iff₀ hδ₁0]; nlinarith\n have hL₂0 : 0 < L₂ := by\n rw [hL₂def]\n apply Real.log_pos\n rw [lt_div_iff₀ hδ₂0]; linarith\n have hL₁Λ : L₁ ≤ 2*Λ := by\n have : (N:ℝ)^2/δ₁ ≤ (3*(N:ℝ)/δ)^2 := by\n rw [div_pow, div_le_div_iff₀ hδ₁0 (by positivity), hδ₁def]\n have hsq : (0:ℝ) ≤ (N:ℝ)^2 := sq_nonneg _\n have hd2 : δ^2 ≤ δ := by nlinarith\n nlinarith [mul_le_mul_of_nonneg_left hd2 hsq]\n calc L₁ ≤ Real.log ((3*(N:ℝ)/δ)^2) := by\n rw [hL₁def]; exact Real.log_le_log (by positivity) this\n _ = 2*Λ := by rw [hΛdef, Real.log_pow]; push_cast; ring\n have hL₂Λ : L₂ ≤ Λ := by\n rw [hL₂def, hΛdef]\n apply Real.log_le_log (by positivity)\n rw [hδ₂def, div_le_div_iff₀ (by positivity) (by positivity)]\n nlinarith\n set c₁ : ℝ := 2*(1+γ')*ε + L₁/(2*γ'*(n:ℝ)) with hc₁def\n set c₂ : ℝ := (1+γ')*(1-γ)*(L₂/(2*γ*(n:ℝ))) with hc₂def\n -- measurability\n have hmeas1 : ∀ w : ι, Measurable (fun y : Fin n → 𝒵 × 𝒵 => (1/(n:ℝ)) * ∑ i, f w (y i).1) := by\n intro w\n exact Measurable.const_mul (Finset.measurable_sum _\n (fun i _ => (hfm w).comp (measurable_fst.comp (measurable_pi_apply i)))) _\n have hmeas2 : ∀ w : ι, Measurable (fun y : Fin n → 𝒵 × 𝒵 => (1/(n:ℝ)) * ∑ i, f w (y i).2) := by\n intro w\n exact Measurable.const_mul (Finset.measurable_sum _\n (fun i _ => (hfm w).comp (measurable_snd.comp (measurable_pi_apply i)))) _\n have hmeasP : ∀ w : ι, Measurable (fun S : Fin n → 𝒵 => (1/(n:ℝ)) * ∑ i, f w (S i)) := by\n intro w\n exact Measurable.const_mul (Finset.measurable_sum _\n (fun i _ => (hfm w).comp (measurable_pi_apply i))) _\n -- the two covers, almost surely on the double sample space\n have hcov2 : ∀ᵐ y ∂(Qm D n),\n (∃ C : Finset (𝒵 → ℝ), C.card ≤ N ∧ (∀ g ∈ C, ∀ z, g z ∈ Set.Icc (0:ℝ) 1) ∧\n ∀ w : ι, ∃ g ∈ C, (1/(n:ℝ)) * ∑ i, |f w (y i).1 - g (y i).1| ≤ ε) ∧\n (∃ C : Finset (𝒵 → ℝ), C.card ≤ N ∧ (∀ g ∈ C, ∀ z, g z ∈ Set.Icc (0:ℝ) 1) ∧\n ∀ w : ι, ∃ g ∈ C, (1/(n:ℝ)) * ∑ i, |f w (y i).2 - g (y i).2| ≤ ε) := by\n have h1 := (Qm_fst_measurePreserving D n).quasiMeasurePreserving.ae hcov\n have h2 := (Qm_snd_measurePreserving D n).quasiMeasurePreserving.ae hcov\n filter_upwards [h1, h2] with y hy1 hy2\n exact ⟨hy1, hy2⟩\n -- Step 1 : the double sample bound\n have hQ : (Qm D n) {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).1) + c₁ < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).2)}\n ≤ ENNReal.ofReal δ₁ := by\n have hGmeas : MeasurableSet {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).1) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).2)} := by\n have he : {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).1) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).2)}\n = ⋃ w : ι, {y : Fin n → 𝒵 × 𝒵 |\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).1) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).2)} := by\n ext y; simp\n rw [he]\n exact MeasurableSet.iUnion (fun w =>\n measurableSet_lt (((hmeas1 w).const_mul _).add_const _) ((hmeas2 w).const_mul _))\n rw [symmetrization D n hGmeas]\n calc ∫⁻ y, (Rm n) {A | swapY A y ∈ {y : Fin n → 𝒵 × 𝒵 | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).1) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (y i).2)}} ∂(Qm D n)\n ≤ ∫⁻ _y, ENNReal.ofReal δ₁ ∂(Qm D n) := by\n apply lintegral_mono_ae\n filter_upwards [hcov2] with y hy\n obtain ⟨⟨C₁, hcard₁, hC₁01, hcov₁⟩, ⟨C₂, hcard₂, hC₂01, hcov₂⟩⟩ := hy\n have hset : {A : Fin n → Bool | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).1) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).2)}\n = {A : Fin n → Bool | ∃ w : ι,\n γ' * ((1/(n:ℝ)) * ∑ i, (f w (y i).1 + f w (y i).2))\n + (2*(1+γ')*ε + L₁/(2*γ'*(n:ℝ)))\n < (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)} := by\n ext A\n simp only [Set.mem_setOf_eq]\n have hkey : ∀ w : ι,\n ((1-γ') * ((1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).2)\n - (1+γ') * ((1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).1))\n = (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1)\n - γ' * ((1/(n:ℝ)) * ∑ i, (f w (y i).1 + f w (y i).2)) := by\n intro w\n set E1 : ℝ := (1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).1 with hE1\n set E2 : ℝ := (1/(n:ℝ)) * ∑ i, f w ((swapY A y) i).2 with hE2\n set Sg : ℝ := (1/(n:ℝ)) * ∑ i, sgnb A i * (f w (y i).2 - f w (y i).1) with hSg\n set TT : ℝ := (1/(n:ℝ)) * ∑ i, (f w (y i).1 + f w (y i).2) with hTT\n have e1 : E2 - E1 = Sg := swap_diff f A y w\n have e2 : E1 + E2 = TT := by\n rw [hE1, hE2, hTT, ← mul_add, ← Finset.sum_add_distrib]\n congr 1\n exact swap_sum f A y w\n calc (1-γ')*E2 - (1+γ')*E1 = (E2 - E1) - γ'*(E1+E2) := by ring\n _ = Sg - γ'*TT := by rw [e1, e2]\n constructor\n · rintro ⟨w, hw⟩\n refine ⟨w, ?_⟩\n have := hkey w\n rw [hc₁def] at hw\n linarith\n · rintro ⟨w, hw⟩\n refine ⟨w, ?_⟩\n have := hkey w\n rw [hc₁def]\n linarith\n rw [hset]\n refine le_trans (pointwise2 hn f hf01 y ε γ' hγ'0 C₁ C₂ hC₁01 hC₂01 hcov₁ hcov₂\n L₁ hL₁0) ?_\n have hcexp : ((C₁.card * C₂.card : ℕ) : ENNReal) * ENNReal.ofReal (Real.exp (-L₁))\n ≤ ((N*N : ℕ) : ENNReal) * ENNReal.ofReal (Real.exp (-L₁)) := by\n apply mul_le_mul_right'\n exact_mod_cast Nat.mul_le_mul hcard₁ hcard₂\n refine hcexp.trans ?_\n rw [show (((N*N : ℕ)) : ENNReal) = ENNReal.ofReal ((N:ℝ)*(N:ℝ)) by\n push_cast; rw [ENNReal.ofReal_mul (by positivity)]; simp [ENNReal.ofReal_natCast]]\n rw [← ENNReal.ofReal_mul (by positivity)]\n apply ENNReal.ofReal_le_ofReal\n rw [hL₁def, Real.exp_neg, Real.exp_log (by positivity), inv_div]\n rw [show ((N:ℝ)*(N:ℝ)) = (N:ℝ)^2 by ring]\n have hcalc : (N:ℝ)^2 * (δ₁/(N:ℝ)^2) = δ₁ := by field_simp\n exact le_of_eq hcalc\n _ = ENNReal.ofReal δ₁ := by rw [lintegral_const, measure_univ, mul_one]\n -- Step 2 : transport\n have hPP : ((Pm D n).prod (Pm D n)) {q : (Fin n → 𝒵) × (Fin n → 𝒵) | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (q.1 i)) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (q.2 i))} ≤ ENNReal.ofReal δ₁ := by\n have hBmeas : MeasurableSet {q : (Fin n → 𝒵) × (Fin n → 𝒵) | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (q.1 i)) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (q.2 i))} := by\n have he : {q : (Fin n → 𝒵) × (Fin n → 𝒵) | ∃ w : ι,\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (q.1 i)) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (q.2 i))}\n = ⋃ w : ι, {q : (Fin n → 𝒵) × (Fin n → 𝒵) |\n (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (q.1 i)) + c₁\n < (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (q.2 i))} := by\n ext q; simp\n rw [he]\n exact MeasurableSet.iUnion (fun w =>\n measurableSet_lt ((((hmeasP w).comp measurable_fst).const_mul _).add_const _)\n (((hmeasP w).comp measurable_snd).const_mul _))\n rw [Qm_to_prod D n hBmeas]\n exact hQ\n -- Step 3 : multiplicative Chernoff for a fixed w\n have hCher : ∀ w : ι, (Pm D n) {S : Fin n → 𝒵 |\n (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (S i)) + c₂ < (1+γ')*(1-γ)^2 * ∫ z, f w z ∂D}\n ≤ ENNReal.ofReal δ₂ := by\n intro w\n have h1 := mult_chernoff D n hn (f w) (hfm w) (hf01 w) γ hγ0 hγ1 (L₂/(2*γ*(n:ℝ)))\n have h2 : {S : Fin n → 𝒵 |\n (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (S i)) + c₂ < (1+γ')*(1-γ)^2 * ∫ z, f w z ∂D}\n ⊆ {S : Fin n → 𝒵 | (1/(n:ℝ)) * ∑ i, f w (S i)\n ≤ (1-γ) * (∫ z, f w z ∂D) - L₂/(2*γ*(n:ℝ))} := by\n intro S hS\n simp only [Set.mem_setOf_eq] at hS ⊢\n have hpos : 0 < (1+γ')*(1-γ) := by nlinarith\n have hexp : (1+γ')*(1-γ) * ((1/(n:ℝ)) * ∑ i, f w (S i) + L₂/(2*γ*(n:ℝ)))\n < (1+γ')*(1-γ) * ((1-γ) * (∫ z, f w z ∂D)) := by\n rw [hc₂def] at hS\n calc (1+γ')*(1-γ) * ((1/(n:ℝ)) * ∑ i, f w (S i) + L₂/(2*γ*(n:ℝ)))\n = (1-γ')*((1/(n:ℝ)) * ∑ i, f w (S i))\n + (1+γ')*(1-γ)*(L₂/(2*γ*(n:ℝ))) := by rw [← hprod]; ring\n _ < (1+γ')*(1-γ)^2 * ∫ z, f w z ∂D := hS\n _ = (1+γ')*(1-γ) * ((1-γ) * (∫ z, f w z ∂D)) := by ring\n have := lt_of_mul_lt_mul_left hexp (le_of_lt hpos)\n linarith\n refine le_trans (measure_mono h2) ?_\n have h3 : (Pm D n) {S : Fin n → 𝒵 | (1/(n:ℝ)) * ∑ i, f w (S i)\n ≤ (1-γ) * (∫ z, f w z ∂D) - L₂/(2*γ*(n:ℝ))}\n ≤ ENNReal.ofReal (Real.exp (-(2*γ*(n:ℝ)*(L₂/(2*γ*(n:ℝ)))))) :=\n (ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) (Real.exp_pos _).le).2 h1\n refine h3.trans (ENNReal.ofReal_le_ofReal ?_)\n have he : 2*γ*(n:ℝ)*(L₂/(2*γ*(n:ℝ))) = L₂ := by field_simp\n rw [he, hL₂def, Real.exp_neg, Real.exp_log (by positivity), inv_div]\n simp\n -- Step 4 : combination\n have hcomb := combine (Pm D n) (fun w : ι => (1+γ')*(1-γ)^2 * ∫ z, f w z ∂D)\n (fun S w => (1-γ') * ((1/(n:ℝ)) * ∑ i, f w (S i)))\n (fun S w => (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (S i)))\n (fun w => (hmeasP w).const_mul _) (fun w => (hmeasP w).const_mul _)\n c₁ c₂ δ δ₁ δ₂ hδ₂0.le hδ₂1 hδ0.le hPP hCher\n (by rw [hδ₁def, hδ₂def]; nlinarith)\n refine le_trans (measure_mono ?_) hcomb\n -- Step 5 : the constants\n have hcc : c₁ + c₂ ≤ (1+γ')*(2*ε + (5-4*γ)*Λ/(2*γ*(n:ℝ))) := by\n have expand : (1+γ')*(2*ε + (5-4*γ)*Λ/(2*γ*(n:ℝ))) - (c₁ + c₂)\n = (2*(5-4*γ)*Λ - L₁*(2-γ)^2 - 2*(1-γ)*L₂) / ((2-γ)*(2*γ*(n:ℝ))) := by\n rw [hc₁def, hc₂def, hγ'def]\n field_simp\n ring\n have hnum : 0 ≤ 2*(5-4*γ)*Λ - L₁*(2-γ)^2 - 2*(1-γ)*L₂ := by\n have hq1 : L₁*(2-γ)^2 ≤ 2*Λ*(2-γ)^2 := by nlinarith [sq_nonneg (2-γ), hL₁Λ]\n have hq2 : 2*(1-γ)*L₂ ≤ 2*(1-γ)*Λ := by nlinarith [hL₂Λ]\n have hq3 : 0 ≤ Λ * (γ - γ^2) := mul_nonneg hΛ0 (by nlinarith)\n nlinarith [hq1, hq2, hq3]\n have hden : 0 < (2-γ)*(2*γ*(n:ℝ)) := by positivity\n have := div_nonneg hnum hden.le\n linarith [expand]\n intro S hS\n simp only [Set.mem_setOf_eq] at hS ⊢\n obtain ⟨w, hw⟩ := hS\n refine ⟨w, ?_⟩\n have hmul : (1+γ') * ((1/(n:ℝ)) * ∑ i, f w (S i))\n + (1+γ')*(2*ε + (5-4*γ)*Λ/(2*γ*(n:ℝ))) < (1+γ')*((1-γ)^2 * ∫ z, f w z ∂D) := by\n have := mul_lt_mul_of_pos_left hw h1pγ'0\n nlinarith [this]\n nlinarith [hmul, hcc]\n\n/-! ### Passing to the infimum over ε -/\n\ntheorem master {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵) [IsProbabilityMeasure D]\n {ι : Type*} [Countable ι]\n (ψ : ι → 𝒵 → ℝ) (hψm : ∀ w, Measurable (ψ w)) (n : ℕ) (hn : 0 < n)\n (κ : ℝ) (F : ℝ → ℝ) (δ : ℝ) (hδ0 : 0 < δ)\n (hFnn : ∀ ε : ℝ, 0 < ε → 0 ≤ F ε)\n (hF : ∀ ε : ℝ, 0 < ε → (Pm D n) {S : Fin n → 𝒵 | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, ψ w (S i) + F ε < κ * ∫ z, ψ w z ∂D} ≤ ENNReal.ofReal δ) :\n ENNReal.ofReal (1-δ) ≤ (Pm D n) {S : Fin n → 𝒵 | ∀ w : ι,\n κ * (∫ z, ψ w z ∂D) ≤ (1/(n:ℝ)) * ∑ i, ψ w (S i)\n + ⨅ e : {e : ℝ // 0 < e}, F (e : ℝ)} := by\n classical\n set I : ℝ := ⨅ e : {e : ℝ // 0 < e}, F (e : ℝ) with hIdef\n set Bad : ℝ → Set (Fin n → 𝒵) := fun c => {S : Fin n → 𝒵 | ∃ w : ι,\n (1/(n:ℝ)) * ∑ i, ψ w (S i) + c < κ * ∫ z, ψ w z ∂D} with hBaddef\n have hBadmeas : ∀ c, MeasurableSet (Bad c) := by\n intro c\n have he : Bad c = ⋃ w : ι, {S : Fin n → 𝒵 |\n (1/(n:ℝ)) * ∑ i, ψ w (S i) + c < κ * ∫ z, ψ w z ∂D} := by\n rw [hBaddef]; ext S; simp\n rw [he]\n refine MeasurableSet.iUnion (fun w => measurableSet_lt ?_ measurable_const)\n exact (Measurable.const_mul (Finset.measurable_sum _\n (fun i _ => (hψm w).comp (measurable_pi_apply i))) _).add_const _\n have hmono : Monotone (fun k : ℕ => Bad (I + 1/((k:ℝ)+1))) := by\n intro k l hkl\n intro S hS\n obtain ⟨w, hw⟩ := hS\n refine ⟨w, ?_⟩\n have : (1:ℝ)/((l:ℝ)+1) ≤ 1/((k:ℝ)+1) := by\n apply one_div_le_one_div_of_le (by positivity)\n have : (k:ℝ) ≤ (l:ℝ) := by exact_mod_cast hkl\n linarith\n linarith\n have hunion : Bad I = ⋃ k : ℕ, Bad (I + 1/((k:ℝ)+1)) := by\n ext S\n simp only [hBaddef, Set.mem_iUnion, Set.mem_setOf_eq]\n constructor\n · rintro ⟨w, hw⟩\n obtain ⟨k, hk⟩ := exists_nat_one_div_lt (show (0:ℝ) <\n κ * (∫ z, ψ w z ∂D) - ((1/(n:ℝ)) * ∑ i, ψ w (S i) + I) by linarith)\n exact ⟨k, w, by linarith⟩\n · rintro ⟨k, w, hw⟩\n refine ⟨w, ?_⟩\n have : (0:ℝ) < 1/((k:ℝ)+1) := by positivity\n linarith\n have hIle : ∀ e : {e : ℝ // 0 < e}, I ≤ F (e : ℝ) := by\n intro e\n apply ciInf_le\n exact ⟨0, by rintro x ⟨e', rfl⟩; exact hFnn _ e'.2⟩\n have hBadI : (Pm D n) (Bad I) ≤ ENNReal.ofReal δ := by\n rw [hunion, hmono.measure_iUnion]\n apply iSup_le\n intro k\n have hlt : I < I + 1/((k:ℝ)+1) := by\n have : (0:ℝ) < 1/((k:ℝ)+1) := by positivity\n linarith\n obtain ⟨e, he⟩ := exists_lt_of_ciInf_lt (f := fun e : {e : ℝ // 0 < e} => F (e : ℝ)) hlt\n refine le_trans (measure_mono ?_) (hF (e : ℝ) e.2)\n intro S hS\n obtain ⟨w, hw⟩ := hS\n exact ⟨w, by linarith⟩\n have hcompl : {S : Fin n → 𝒵 | ∀ w : ι,\n κ * (∫ z, ψ w z ∂D) ≤ (1/(n:ℝ)) * ∑ i, ψ w (S i) + I} = (Bad I)ᶜ := by\n rw [hBaddef]\n ext S\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_exists, not_lt]\n rw [hcompl, measure_compl (hBadmeas I) (measure_ne_top _ _), measure_univ]\n have h1 : ENNReal.ofReal (1-δ) = 1 - ENNReal.ofReal δ := by\n rw [ENNReal.ofReal_sub _ hδ0.le]; simp\n rw [h1]\n exact tsub_le_tsub_left hBadI 1\n\n/-! ### Flattening pairs -/\n\ndef flatEq (n : ℕ) : Fin n ⊕ Fin n ≃ Fin (2*n) :=\n finSumFinEquiv.trans (finCongr (by ring))\n\ndef pairFlat {𝒵 : Type*} {n : ℕ} (y : Fin n → 𝒵 × 𝒵) : Fin (2*n) → 𝒵 :=\n fun j => Sum.elim (fun i => (y i).1) (fun i => (y i).2) ((flatEq n).symm j)\n\nlemma sum_pairFlat {𝒵 : Type*} {n : ℕ} (y : Fin n → 𝒵 × 𝒵) (F : 𝒵 → ℝ) :\n ∑ j : Fin (2*n), F (pairFlat y j)\n = ∑ i : Fin n, (F (y i).1 + F (y i).2) := by\n rw [← Equiv.sum_comp (flatEq n) (fun j => F (pairFlat y j))]\n simp only [pairFlat, Equiv.symm_apply_apply]\n rw [Fintype.sum_sum_type]\n simp [Finset.sum_add_distrib]\n\nlemma Qm_fst_eval {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) (i : Fin n) :\n MeasurePreserving (fun y : Fin n → 𝒵 × 𝒵 => (y i).1) (Qm D n) D := by\n have h1 := Qm_fst_measurePreserving D n\n have h2 : MeasurePreserving (fun S : Fin n → 𝒵 => S i) (Pm D n) D := by\n have := measurePreserving_eval (fun _ : Fin n => D) i\n simpa [Pm] using this\n exact h2.comp h1\n\nlemma Qm_snd_eval {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) (i : Fin n) :\n MeasurePreserving (fun y : Fin n → 𝒵 × 𝒵 => (y i).2) (Qm D n) D := by\n have h1 := Qm_snd_measurePreserving D n\n have h2 : MeasurePreserving (fun S : Fin n → 𝒵 => S i) (Pm D n) D := by\n have := measurePreserving_eval (fun _ : Fin n => D) i\n simpa [Pm] using this\n exact h2.comp h1\n\nlemma Pm_eval {𝒵 : Type*} [MeasurableSpace 𝒵] (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) (i : Fin n) :\n MeasurePreserving (fun S : Fin n → 𝒵 => S i) (Pm D n) D := by\n have := measurePreserving_eval (fun _ : Fin n => D) i\n simpa [Pm] using this\n\nend GtLib\n\nopen GtLib\n\nnoncomputable def empLoss {𝒵 : Type*} {Ωp : Type*} {n : ℕ}\n (φ : Ωp → 𝒵 → ℝ) (Z : Fin n → 𝒵) (w : Ωp) : ℝ :=\n (1 / (n : ℝ)) * ∑ i : Fin n, φ w (Z i)\n\nnoncomputable def testLoss {𝒵 : Type*} [MeasurableSpace 𝒵] {Ωp : Type*}\n (φ : Ωp → 𝒵 → ℝ) (D : Measure 𝒵) (w : Ωp) : ℝ :=\n ∫ z, φ w z ∂D\n\ndef IsUnifL1Cover {𝒵 : Type*} [MeasurableSpace 𝒵] {Ωp : Type*}\n (D : Measure 𝒵)\n (C : Finset (𝒵 → ℝ)) (φ : Ωp → 𝒵 → ℝ) (𝒲 : Set Ωp) (ε : ℝ) {m : ℕ}\n (S : Fin m → 𝒵) : Prop :=\n (∀ g ∈ C, (∀ z, g z ∈ Set.Icc (0 : ℝ) 1) ∧ AEMeasurable g D) ∧\n (∀ w ∈ 𝒲, ∃ g ∈ C,\n (1 / (m : ℝ)) * ∑ j : Fin m, |φ w (S j) - g (S j)| ≤ ε)\n\ndef IsUnifL1CoveringNumber {𝒵 : Type*} [MeasurableSpace 𝒵] {Ωp : Type*}\n (D : Measure 𝒵)\n (N : ℕ) (φ : Ωp → 𝒵 → ℝ) (𝒲 : Set Ωp) (ε : ℝ) (m : ℕ) : Prop :=\n (∀ S : Fin m → 𝒵, ∃ C : Finset (𝒵 → ℝ),\n C.card ≤ N ∧ IsUnifL1Cover D C φ 𝒲 ε S) ∧\n (∀ M : ℕ,\n (∀ S : Fin m → 𝒵, ∃ C : Finset (𝒵 → ℝ),\n C.card ≤ M ∧ IsUnifL1Cover D C φ 𝒲 ε S) →\n N ≤ M)\n\ntheorem ch4_theorem_4_12\n {𝒵 : Type*} [MeasurableSpace 𝒵]\n {Ωp : Type*}\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ]\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (𝒲 : Set Ωp) (hW : 𝒲.Nonempty) (hW_ctble : 𝒲.Countable)\n (φ : Ωp → 𝒵 → ℝ)\n (hφ_bdd : ∀ w ∈ 𝒲, ∀ z, φ w z ∈ Set.Icc (0 : ℝ) 1)\n (hφ_meas : ∀ w ∈ 𝒲, AEMeasurable (fun z => φ w z) D)\n (n : ℕ) (hn : 0 < n)\n (Z : Ω → Fin n → 𝒵)\n (hZ_meas : ∀ i, AEMeasurable (fun ω => Z ω i) μ)\n (hZ_iid : (iIndepFun (fun i ω => Z ω i) μ) ∧\n (∀ i, Measure.map (fun ω => Z ω i) μ = D))\n (N₁ : ℝ → ℕ → ℕ)\n (hN₁ : ∀ ε > (0 : ℝ),\n IsUnifL1CoveringNumber D (N₁ ε n) φ 𝒲 ε n ∧\n IsUnifL1CoveringNumber D (N₁ ε (2 * n)) φ 𝒲 ε (2 * n))\n (δ : ℝ) (hδ : δ ∈ Set.Ioo (0 : ℝ) 1) :\n (1 - δ ≤ μ.real {ω |\n ∀ w ∈ 𝒲,\n testLoss φ D w ≤ empLoss φ (Z ω) w\n + ⨅ ε : {e : ℝ // 0 < e},\n (2 * (ε : ℝ)\n + 3 * Real.sqrt\n (Real.log (3 * (N₁ (ε : ℝ) (2 * n) : ℝ) / δ) / (2 * n)))})\n ∧\n (∀ γ ∈ Set.Ioo (0 : ℝ) 1,\n 1 - δ ≤ μ.real {ω |\n ∀ w ∈ 𝒲,\n (1 - γ) ^ 2 * testLoss φ D w ≤ empLoss φ (Z ω) w\n + ⨅ ε : {e : ℝ // 0 < e},\n (2 * (ε : ℝ)\n + (5 - 4 * γ) * Real.log (3 * (N₁ (ε : ℝ) n : ℝ) / δ)\n / (2 * γ * n))}) := by\n classical\n obtain ⟨hδ0, hδ1⟩ := hδ\n have hn' : (0:ℝ) < n := by exact_mod_cast hn\n -- 𝒵 is nonempty\n haveI hZne : Nonempty 𝒵 := by\n rcases isEmpty_or_nonempty 𝒵 with h | h\n · exfalso\n have h1 : (Set.univ : Set 𝒵) = ∅ := Set.univ_eq_empty_iff.2 h\n have h2 := measure_univ (μ := D)\n rw [h1, measure_empty] at h2\n exact zero_ne_one h2\n · exact h\n haveI hιc : Countable ↥𝒲 := hW_ctble.to_subtype\n haveI hιne : Nonempty ↥𝒲 := hW.to_subtype\n -- measurable modification of φ\n have hmk : ∀ w : ↥𝒲, AEMeasurable (fun z => φ (w : Ωp) z) D := fun w => hφ_meas w.1 w.2\n set ψ : ↥𝒲 → 𝒵 → ℝ :=\n fun w z => max 0 (min 1 (((hmk w).mk (fun z => φ (w : Ωp) z)) z)) with hψdef\n have hψm : ∀ w, Measurable (ψ w) := by\n intro w\n exact measurable_const.max (measurable_const.min (hmk w).measurable_mk)\n have hψ01 : ∀ w z, ψ w z ∈ Set.Icc (0:ℝ) 1 := by\n intro w z\n constructor\n · exact le_max_left _ _\n · rw [hψdef]\n simp only\n exact max_le (by norm_num) (min_le_left _ _)\n have hψeq : ∀ w : ↥𝒲, ψ w =ᵐ[D] (fun z => φ (w : Ωp) z) := by\n intro w\n filter_upwards [(hmk w).ae_eq_mk] with z hz\n have hb := hφ_bdd w.1 w.2 z\n rw [hψdef]\n simp only\n rw [← hz]\n rw [min_eq_right hb.2, max_eq_right hb.1]\n have hint : ∀ w : ↥𝒲, ∫ z, ψ w z ∂D = testLoss φ D (w : Ωp) := by\n intro w\n exact integral_congr_ae (hψeq w)\n -- the bad set\n obtain ⟨B, hBsub, hBmeas, hB0⟩ :=\n exists_measurable_superset_of_null (μ := D)\n (s := ⋃ w : ↥𝒲, {z | ψ w z ≠ φ (w : Ωp) z})\n (measure_iUnion_null (fun w => ae_iff.1 (hψeq w)))\n have hgood : ∀ z ∉ B, ∀ w : ↥𝒲, ψ w z = φ (w : Ωp) z := by\n intro z hz w\n by_contra hc\n exact hz (hBsub (Set.mem_iUnion.2 ⟨w, hc⟩))\n -- N ≥ 1\n have hNpos : ∀ (ε : ℝ), 0 < ε → ∀ (m : ℕ),\n (∀ S : Fin m → 𝒵, ∃ C : Finset (𝒵 → ℝ), C.card ≤ N₁ ε m ∧ IsUnifL1Cover D C φ 𝒲 ε S) →\n 1 ≤ N₁ ε m := by\n intro ε hε m hcov\n obtain ⟨C, hCcard, _, hC2⟩ := hcov (fun _ => Classical.arbitrary 𝒵)\n obtain ⟨w0, hw0⟩ := hW\n obtain ⟨g, hg, _⟩ := hC2 w0 hw0\n exact le_trans (Finset.card_pos.2 ⟨g, hg⟩) hCcard\n have hN1n : ∀ (ε : ℝ), 0 < ε → 1 ≤ N₁ ε n := fun ε hε =>\n hNpos ε hε n (hN₁ ε hε).1.1\n have hN12n : ∀ (ε : ℝ), 0 < ε → 1 ≤ N₁ ε (2*n) := fun ε hε =>\n hNpos ε hε (2*n) (hN₁ ε hε).2.1\n -- Z pushes forward to the product measure\n have hZam : AEMeasurable (fun ω => Z ω) μ := aemeasurable_pi_iff.2 hZ_meas\n set Z' : Ω → Fin n → 𝒵 := hZam.mk (fun ω => Z ω) with hZ'def\n have hZ'm : Measurable Z' := hZam.measurable_mk\n have hZ'ae : (fun ω => Z ω) =ᵐ[μ] Z' := hZam.ae_eq_mk\n have hZmap : Measure.map Z' μ = Pm D n := by\n rw [← Measure.map_congr hZ'ae]\n have h1 := (iIndepFun_iff_map_fun_eq_pi_map hZ_meas).1 hZ_iid.1\n simp only [hZ_iid.2] at h1\n rw [Pm]\n exact h1\n -- coordinate bad events are null\n have hbadZ : ∀ᵐ ω ∂μ, ∀ i, Z ω i ∉ B := by\n rw [ae_all_iff]\n intro i\n rw [ae_iff]\n simp only [not_not]\n have he : {ω | Z ω i ∈ B} = (fun ω => Z ω i) ⁻¹' B := rfl\n rw [he, ← Measure.map_apply_of_aemeasurable (hZ_meas i) hBmeas, hZ_iid.2 i]\n exact hB0\n -- generic transfer from the product measure to μ\n have transfer : ∀ (κ : ℝ) (F : ℝ → ℝ),\n (∀ ε : ℝ, 0 < ε → 0 ≤ F ε) →\n (∀ ε : ℝ, 0 < ε → (Pm D n) {S : Fin n → 𝒵 | ∃ w : ↥𝒲,\n (1/(n:ℝ)) * ∑ i, ψ w (S i) + F ε < κ * ∫ z, ψ w z ∂D} ≤ ENNReal.ofReal δ) →\n 1 - δ ≤ μ.real {ω | ∀ w ∈ 𝒲, κ * testLoss φ D w ≤ empLoss φ (Z ω) w\n + ⨅ e : {e : ℝ // 0 < e}, F (e : ℝ)} := by\n intro κ F hFnn hF\n set I : ℝ := ⨅ e : {e : ℝ // 0 < e}, F (e : ℝ) with hIdef\n have hmaster := master D ψ hψm n hn κ F δ hδ0 hFnn hF\n set A : Set (Fin n → 𝒵) := {S : Fin n → 𝒵 | ∀ w : ↥𝒲,\n κ * (∫ z, ψ w z ∂D) ≤ (1/(n:ℝ)) * ∑ i, ψ w (S i) + I} with hAdef\n have hAmeas : MeasurableSet A := by\n have he : A = ⋂ w : ↥𝒲, {S : Fin n → 𝒵 |\n κ * (∫ z, ψ w z ∂D) ≤ (1/(n:ℝ)) * ∑ i, ψ w (S i) + I} := by\n rw [hAdef]; ext S; simp\n rw [he]\n refine MeasurableSet.iInter (fun w => measurableSet_le measurable_const ?_)\n exact (Measurable.const_mul (Finset.measurable_sum _\n (fun i _ => (hψm w).comp (measurable_pi_apply i))) _).add_const _\n set G : Set Ω := {ω | (fun ω => Z ω) ω = Z' ω ∧ ∀ i, Z ω i ∉ B} with hGdef\n have hG0 : μ Gᶜ = 0 := ae_iff.1 (hZ'ae.and hbadZ)\n set T : Set Ω := {ω | ∀ w ∈ 𝒲, κ * testLoss φ D w ≤ empLoss φ (Z ω) w + I} with hTdef\n have hpre : Z' ⁻¹' A ∩ G ⊆ T := by\n rintro ω ⟨hA, h1, h2⟩\n intro w hw\n have hthis := hA ⟨w, hw⟩\n rw [hint ⟨w, hw⟩] at hthis\n have hs : ∑ i, ψ ⟨w, hw⟩ (Z' ω i) = ∑ i : Fin n, φ w (Z ω i) := by\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [← h1]\n exact hgood (Z ω i) (h2 i) ⟨w, hw⟩\n rw [hs] at hthis\n exact hthis\n have hkey : ENNReal.ofReal (1 - δ) ≤ μ T := by\n have h1 : μ (Z' ⁻¹' A) = Pm D n A := by\n rw [← hZmap, Measure.map_apply hZ'm hAmeas]\n calc ENNReal.ofReal (1 - δ) ≤ Pm D n A := hmaster\n _ = μ (Z' ⁻¹' A) := h1.symm\n _ ≤ μ (Z' ⁻¹' A ∩ G) + μ (Z' ⁻¹' A \\ G) := measure_le_inter_add_diff _ _ _\n _ ≤ μ T + 0 := by\n refine add_le_add (measure_mono hpre) ?_\n refine le_trans (measure_mono (fun x hx => hx.2)) ?_\n exact le_of_eq hG0\n _ = μ T := add_zero _\n have h2 := ENNReal.toReal_mono (measure_ne_top μ T) hkey\n rw [ENNReal.toReal_ofReal (by linarith)] at h2\n exact h2\n refine ⟨?_, ?_⟩\n · -- Part 1\n have hFnn : ∀ ε : ℝ, 0 < ε →\n 0 ≤ 2 * ε + 3 * Real.sqrt (Real.log (3 * (N₁ ε (2*n) : ℝ) / δ) / (2 * (n:ℝ))) := by\n intro ε hε\n have := Real.sqrt_nonneg (Real.log (3 * (N₁ ε (2*n) : ℝ) / δ) / (2 * (n:ℝ)))\n linarith\n have hF : ∀ ε : ℝ, 0 < ε → (Pm D n) {S : Fin n → 𝒵 | ∃ w : ↥𝒲,\n (1/(n:ℝ)) * ∑ i, ψ w (S i)\n + (2 * ε + 3 * Real.sqrt (Real.log (3 * (N₁ ε (2*n) : ℝ) / δ) / (2 * (n:ℝ))))\n < 1 * ∫ z, ψ w z ∂D} ≤ ENNReal.ofReal δ := by\n intro ε hε\n simp only [one_mul]\n -- covering hypothesis on Qm\n have hae : ∀ᵐ y ∂(Qm D n), ∀ i : Fin n, (y i).1 ∉ B ∧ (y i).2 ∉ B := by\n rw [ae_all_iff]\n intro i\n have h1 : ∀ᵐ y ∂(Qm D n), (y i).1 ∉ B := by\n rw [ae_iff]\n simp only [not_not]\n have hmp := Qm_fst_eval D n i\n have he : {y : Fin n → 𝒵 × 𝒵 | (y i).1 ∈ B}\n = (fun y : Fin n → 𝒵 × 𝒵 => (y i).1) ⁻¹' B := rfl\n rw [he, ← Measure.map_apply hmp.measurable hBmeas, hmp.map_eq]\n exact hB0\n have h2 : ∀ᵐ y ∂(Qm D n), (y i).2 ∉ B := by\n rw [ae_iff]\n simp only [not_not]\n have hmp := Qm_snd_eval D n i\n have he : {y : Fin n → 𝒵 × 𝒵 | (y i).2 ∈ B}\n = (fun y : Fin n → 𝒵 × 𝒵 => (y i).2) ⁻¹' B := rfl\n rw [he, ← Measure.map_apply hmp.measurable hBmeas, hmp.map_eq]\n exact hB0\n exact h1.and h2\n have hcov : ∀ᵐ y ∂(Qm D n), ∃ C : Finset (𝒵 → ℝ), C.card ≤ N₁ ε (2*n) ∧\n (∀ g ∈ C, ∀ z, g z ∈ Set.Icc (0:ℝ) 1) ∧\n ∀ w : ↥𝒲, ∃ g ∈ C, (1/(2*(n:ℝ))) *\n ∑ i, (|ψ w (y i).1 - g (y i).1| + |ψ w (y i).2 - g (y i).2|) ≤ ε := by\n filter_upwards [hae] with y hy\n obtain ⟨C, hCcard, hC1, hC2⟩ := (hN₁ ε hε).2.1 (pairFlat y)\n refine ⟨C, hCcard, fun g hg => (hC1 g hg).1, ?_⟩\n intro w\n obtain ⟨g, hg, hgle⟩ := hC2 w.1 w.2\n refine ⟨g, hg, ?_⟩\n have hsum := sum_pairFlat y (fun z => |φ (w : Ωp) z - g z|)\n have heq : ∑ i : Fin n, (|ψ w (y i).1 - g (y i).1| + |ψ w (y i).2 - g (y i).2|)\n = ∑ i : Fin n, (|φ (w : Ωp) (y i).1 - g (y i).1|\n + |φ (w : Ωp) (y i).2 - g (y i).2|) := by\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [hgood _ (hy i).1 w, hgood _ (hy i).2 w]\n rw [heq, ← hsum]\n have hcast : ((2*n : ℕ) : ℝ) = 2*(n:ℝ) := by push_cast; ring\n rw [← hcast]\n exact hgle\n exact core1 D ψ hψm hψ01 n hn ε hε (N₁ ε (2*n)) (hN12n ε hε) hcov δ hδ0 hδ1\n have h := transfer 1\n (fun e => 2 * e + 3 * Real.sqrt (Real.log (3 * (N₁ e (2*n) : ℝ) / δ) / (2 * (n:ℝ))))\n hFnn hF\n simp only [one_mul] at h\n exact h\n · -- Part 2\n rintro γ ⟨hγ0, hγ1⟩\n have hlognn : ∀ ε : ℝ, 0 < ε → 0 ≤ Real.log (3 * (N₁ ε n : ℝ) / δ) := by\n intro ε hε\n apply Real.log_nonneg\n have hN : (1:ℝ) ≤ (N₁ ε n : ℝ) := by exact_mod_cast hN1n ε hε\n rw [le_div_iff₀ hδ0]\n linarith\n have hFnn : ∀ ε : ℝ, 0 < ε →\n 0 ≤ 2 * ε + (5 - 4*γ) * Real.log (3 * (N₁ ε n : ℝ) / δ) / (2 * γ * (n:ℝ)) := by\n intro ε hε\n have h1 := hlognn ε hε\n have h2 : (0:ℝ) ≤ (5 - 4*γ) * Real.log (3 * (N₁ ε n : ℝ) / δ) / (2 * γ * (n:ℝ)) := by\n apply div_nonneg\n · nlinarith\n · positivity\n linarith\n have hF : ∀ ε : ℝ, 0 < ε → (Pm D n) {S : Fin n → 𝒵 | ∃ w : ↥𝒲,\n (1/(n:ℝ)) * ∑ i, ψ w (S i)\n + (2 * ε + (5 - 4*γ) * Real.log (3 * (N₁ ε n : ℝ) / δ) / (2 * γ * (n:ℝ)))\n < (1-γ)^2 * ∫ z, ψ w z ∂D} ≤ ENNReal.ofReal δ := by\n intro ε hε\n have hae : ∀ᵐ S ∂(Pm D n), ∀ i : Fin n, S i ∉ B := by\n rw [ae_all_iff]\n intro i\n rw [ae_iff]\n simp only [not_not]\n have hmp := Pm_eval D n i\n have he : {S : Fin n → 𝒵 | S i ∈ B} = (fun S : Fin n → 𝒵 => S i) ⁻¹' B := rfl\n rw [he, ← Measure.map_apply hmp.measurable hBmeas, hmp.map_eq]\n exact hB0\n have hcov : ∀ᵐ S ∂(Pm D n), ∃ C : Finset (𝒵 → ℝ), C.card ≤ N₁ ε n ∧\n (∀ g ∈ C, ∀ z, g z ∈ Set.Icc (0:ℝ) 1) ∧\n ∀ w : ↥𝒲, ∃ g ∈ C, (1/(n:ℝ)) * ∑ i, |ψ w (S i) - g (S i)| ≤ ε := by\n filter_upwards [hae] with S hS\n obtain ⟨C, hCcard, hC1, hC2⟩ := (hN₁ ε hε).1.1 S\n refine ⟨C, hCcard, fun g hg => (hC1 g hg).1, ?_⟩\n intro w\n obtain ⟨g, hg, hgle⟩ := hC2 w.1 w.2\n refine ⟨g, hg, ?_⟩\n have heq : ∑ i : Fin n, |ψ w (S i) - g (S i)|\n = ∑ i : Fin n, |φ (w : Ωp) (S i) - g (S i)| := by\n refine Finset.sum_congr rfl (fun i _ => ?_)\n rw [hgood _ (hS i) w]\n rw [heq]\n exact hgle\n exact core2 D ψ hψm hψ01 n hn ε hε (N₁ ε n) (hN1n ε hε) γ hγ0 hγ1 hcov δ hδ0 hδ1\n exact transfer ((1-γ)^2)\n (fun e => 2 * e + (5 - 4*γ) * Real.log (3 * (N₁ e n : ℝ) / δ) / (2 * γ * (n:ℝ)))\n hFnn hF\n\nend GraduateLevel\n"} +{"id": "ch16_theorem_16_3", "source": "Graduate-level", "targets": [{"label": "ch16_theorem_16_3", "decls": ["ch16_theorem_16_3"], "statement": "Assume that rewards \\(r_t(a) \\in [0,1]\\). Let \\(a_* \\in \\arg \\max_a \\mu(a)\\). With a choice of\n\\[\n\\hat{c}_{t}(a)=\\sqrt{\\frac{\\ln(2(\\hat{n}_{t}(a)+1)^{2}/\\delta)}{2\\hat{n}_{t}(a)}},\n\\]\nwe have with probability at least \\(1 - \\delta\\):\n\\[\n\\mathrm{REG}_{T}\\leq(K-1)+\\sqrt{8\\ln(2 K T^{2}/\\delta)(T-K)K}.\n\\]", "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}], "nl_proof": "Given any integer \\( m \\geq 1 \\) and \\( a \\in \\{1, \\ldots, K\\} \\). We know that the sequence \\( r(a_{t})\\mathbb{1}(a_{t} = a) \\) satisfies the sub-Gaussian bound in Theorem 13.3 with \\( \\sigma_{i} = 0.5\\mathbb{1}(a_{i} = a) \\). This means that \\( \\sum_{i=1}^{t}\\sigma_{i}^{2} = 0.25\\hat{n}_{t}(a) \\). By letting \\( \\sigma = 0.5\\sqrt{m} \\) for a constant \\( m \\), and considering the event \\( \\hat{n}_{t}(a) = m \\), we obtain with probability at most \\( 0.5\\delta / (m + 1)^{2} \\):\n\\[\n\\exists t\\geq 1:\\mu(a)>\\hat{\\mu}_{t}(a)+\\hat{c}_{t}(a)\\&\\hat{n}_{t}(a)=m.\n\\]\nSimilarly, with probability at most \\((0.5 / K)\\delta /(m + 1)^2\\)\n\\[\n\\exists t\\geq 1:\\mu(a)<\\hat{\\mu}_{t}(a)-\\hat{c}_{t}^{\\prime}(a)\\&\\hat{n}_{t}(a)=m,\n\\]\nwhere the lower confidence interval size is defined as\n\\[\n\\hat{c}_{t}^{\\prime}(a)=\\sqrt{\\frac{\\ln(2 K(\\hat{n}_{t}(a)+1)^{2}/\\delta)}{2\\hat{n}_{t}(a)}}.\n\\]\nIt follows that the failure probability of upper confidence bound is given by\n\\[\n\\begin{array}{l}\\Pr\\left[\\exists t>K:\\mu\\left(a_{*}\\right)>\\hat{\\mu}_{t}\\left(a_{*}\\right)+\\hat{c}_{t}\\left(a_{*}\\right)\\right]\\\\ \\leq\\sum_{m=1}^{\\infty}\\Pr\\left[\\exists t>K:\\hat{n}_{t}\\left(a_{*}\\right)=m\\&\\mu\\left(a_{*}\\right)>\\hat{\\mu}_{t}\\left(a_{*}\\right)+\\hat{c}_{t}\\left(a_{*}\\right)\\right]\\\\ \\leq\\sum_{m=1}^{\\infty}0. 5\\delta/(m+1)^{2}\\leq 0. 5\\delta .\\\\ \\end{array}\n\\]\nMoreover, the failure probability of lower confidence bound is given by\n\\[\n\\begin{array}{l}\\Pr\\left[\\exists t>K\\&a\\in\\{1,\\dots,K\\}:\\mu(a)<\\hat{\\mu}_{t}(a)-\\hat{c}_{t}^{\\prime}(a)\\right]\\\\ \\leq\\sum_{a=1}^{K}\\Pr\\left[\\exists t>K:\\mu(a)<\\hat{\\mu}_{t}(a)-\\hat{c}_{t}^{\\prime}(a)\\right]\\\\ \\leq\\sum_{a=1}^{K}\\sum_{m=1}^{\\infty}\\Pr\\left[\\exists t>K:\\hat{n}_{t}(a)=m\\&\\mu(a)<\\hat{\\mu}_{t}(a)-\\hat{c}_{t}^{\\prime}(a)\\right]\\\\ \\leq\\sum_{a=1}^{K}\\sum_{m=1}^{\\infty}\\frac{\\delta}{2 K(m+1)^{2}}\\leq\\delta/2.\\\\ \\end{array}\n\\]\nThe following bound follows from Lemma 16.2. With probability at least \\(1 - \\delta\\):\n\\[\n\\begin{array}{l}\\sum_{t=1}^{T}[\\mu(a_{*})-\\mu(a_{t})]-\\sum_{a=1}^{K}[\\mu(a_{*})-\\mu(a)]\\leq\\sum_{t=K+1}^{T}[\\hat{c}_{t-1}(a_{t})+\\hat{c}_{t-1}^{\\prime}(a_{t})]\\\\ \\leq 2\\sum_{t=K+1}^{T}\\sqrt{\\frac{\\ln(2 K(\\hat{n}_{t-1}(a_{t})+1)^{2}/\\delta)}{2\\hat{n}_{t-1}(a_{t})}}\\\\ =2\\sum_{a=1}^{K}\\sum_{t=K+1}^{T}\\sqrt{\\frac{\\ln\\left(2 K\\left(\\hat{n}_{t-1}\\left(a_{t}\\right)+1\\right)^{2}/\\delta\\right)}{2\\hat{n}_{t-1}\\left(a_{t}\\right)}}\\mathbb{1}\\left(a_{t}=a\\right)\\\\ \\stackrel{(a)}{=}2\\sum_{a=1}^{K}\\sum_{m=1}^{\\hat{n}_{T}(a)-1}\\sqrt{\\frac{\\ln(2 K(m+1)^{2}/\\delta)}{2 m}}\\\\ \\leq 2\\sum_{a=1}^{K}\\int_{0}^{\\hat{n}_{T}(a)-1}\\sqrt{\\frac{\\ln\\left(2 K\\hat{n}_{T}(a)^{2}/\\delta\\right)}{2 t}}d t\\\\ =4\\sum_{a=1}^{K}\\sqrt{\\frac{\\ln(2 K\\hat{n}_{T}(a)^{2}/\\delta)(\\hat{n}_{T}(a)-1)}{2}}\\\\ \\leq 4\\sqrt{\\frac{\\ln(2 K T^{2}/\\delta)(T-K)K}{2}}.\\\\ \\end{array}\n\\]\nEquation (a) used the fact that for each arm \\( a \\), with \\( a_{t} = a \\), \\( \\hat{n}_{t-1}(a_{t}) \\) takes values from \\( m = 1 \\) to \\( m = \\hat{n}_T(a) - 1 \\), once for each value. In the derivation of the last inequality, we used Jensen's inequality and the concavity of \\( \\sqrt{z} \\), which implies that\n\\[\n\\sum_{a=1}^{K}\\sqrt{\\hat{n}_{T}(a)-1}\\leq\\sqrt{K\\sum_{a=1}^{K}(\\hat{n}_{T}(a)-1)}=\\sqrt{K(T-K)}.\n\\]\nThis implies the desired bound.", "context": [{"id": "ch13:theorem:13_3", "name": "Martingale Sub-Gaussian Inequality", "statement": "Consider a sequence of random functions \\(\\xi_1(S_1),\\ldots,\\xi_t(S_t),\\ldots\\) Assume each \\(\\xi_{i}\\) is sub-Gaussian with respect to \\(Z_{i}^{(y)}\\):\n\\[\n\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{\\lambda\\xi_{i}}\\leq\\lambda\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i}+\\frac{\\lambda^{2}\\sigma_{i}^{2}}{2}\n\\]\nfor some \\(\\sigma_{i}\\) that may depend on \\(S_{i - 1}\\) and \\(Z_{i}^{(x)}\\). Then for all \\(\\sigma >0\\), with probability at least \\(1 - \\delta\\)\n\\[\n\\forall n>0:\\sum_{i=1}^{n}\\mathbb{E}_{Z_{i}^{(y)}}\\xi_{i}<\\sum_{i=1}^{n}\\xi_{i}+\\left(\\sigma+\\frac{\\sum_{i=1}^{n}\\sigma_{i}^{2}}{\\sigma}\\right)\\sqrt{\\frac{\\ln(1/\\delta)}{2}}.\n\\]"}, {"id": "ch16:lemma:16_2", "name": "lemma 16.2", "statement": "Let \\(a_* \\in \\arg \\max_a \\mu(a)\\). Let\n\\[\n\\delta_{1}=\\Pr [\\exists t>K:\\mu(a_{*})>\\hat{\\mu}_{t-1}(a_{*})+\\hat{c}_{t-1}(a_{*})]\n\\]\nbe the probability that the upper confident bound fails on \\( a_* \\). Let\n\\[\n\\delta_{2}=\\Pr\\left[\\exists t>K\\&a\\in\\{1,\\dots,K\\}\\backslash\\left\\{a_{*}\\right\\}:\\mu(a)<\\hat{\\mu}_{t-1}(a)-\\hat{c}_{t-1}^{\\prime}(a)\\right]\n\\]\nbe the probability that the lower confident bound fails on \\( a \\neq a_* \\). Then for Algorithm 16.1, we have with probability at least \\( 1 - \\delta_1 - \\delta_2 \\):\n\\[\n\\operatorname{REG}_{T}\\leq\\sum_{a=1}^{K}[\\mu(a_{*})-\\mu(a)]+\\sum_{t=K+1}^{T}[\\hat{c}_{t-1}(a_{t})+\\hat{c}_{t-1}^{\\prime}(a_{t})]\\mathbb{1}(a_{t}\\neq a_{*}).\n\\]"}, {"id": "ch16:definition:16_1", "name": "definition 16.1", "statement": "In the multi-armed bandit (or MAB) problem, we consider \\(K\\) arms. The environment generates a sequence of reward vectors for time steps \\(t \\geq 1\\) as \\(r_t = [r_t(1), \\ldots, r_t(K)]\\). Each \\(r_t(a)\\) is associated with an arm \\(a \\in \\{1, \\ldots, K\\}\\). In the literature, an arm \\(a\\) is also referred to as an action. At each time step \\(t = 1, 2, \\ldots, T\\),\n- The player pulls one of the arms \\( a_{t} \\in \\{1, \\dots, K\\} \\).\n- The environment returns the reward \\( r_t(a_t) \\), but does not reveal information on any other arm \\( a \\neq a_t \\).\nAt each time \\( t \\), a (randomized) bandit algorithm takes the historic observations observed so far, and maps it to a distribution \\( \\hat{\\pi}_{t-1} \\) over actions \\( a \\in \\{1, \\ldots, K\\} \\). We then draw a random action \\( a_t \\) (arm) from \\( \\hat{\\pi}_{t-1} \\). Here \\( \\hat{\\pi}_{t-1} \\) is referred to as policy.\nIn the adversarial bandit problem, we are given an arbitrary reward sequence \\(\\{[r_1(1),\\ldots,r_t(K)]:t\\geq 1\\}\\) before hand. The adversary in this setting is called oblivious, who decides the rewards of all the rounds before the game starts (but may take advantage of the bandit algorithm's weakness). For this reward se\nquence, the expected cumulative reward of a randomized bandit algorithm is\n\\[\n\\mathbb{E}\\sum_{t=1}^{T}r_{t}(a_{t}),\n\\]\nwhere the randomization is over the internal randomization of the bandit algorithm. The expected regret is defined as\n\\[\n\\operatorname{REG}_{T}=\\max_{a}\\sum_{t=1}^{T}r_{t}(a)-\\mathbb{E}\\sum_{t=1}^{T}r_{t}\\left(a_{t}\\right).\\tag{16.1}\n\\]\nIf the bandit algorithm is deterministic: i.e. pulling a single arm \\(a_{t}\\) only at any time step, then the regret is\n\\[\n\\mathrm{REG}_{T}=\\max_{a}\\sum_{t=1}^{T}r_{t}(a)-\\sum_{t=1}^{T}r_{t}(a_{t}).\n\\]\nIn the adversarial bandit problem, our goal is to minimize the expected regret \\(\\mathrm{REG}_T\\) (and the expectation is with respect to the internal randomization of the algorithm instead of the data).\nAnother form of bandit problem, called stochastic bandit, assumes that the reward \\( r_t(a) \\) is drawn independently from a distribution \\( \\mathcal{D}_a \\), with mean \\( \\mu(a) = \\mathbb{E}_{r_t(a) \\sim \\mathcal{D}_a} [r_t(a)] \\). In this setting, the goal of bandit is to find \\( a \\) that maximizes the expected reward \\( \\mu(a) \\). We are interested in the expected regret defined as:\n\\[\n\\operatorname{REG}_{T}=T\\max_{a}\\mu(a)-\\mathbb{E}\\sum_{t=1}^{T}\\mu\\left(a_{t}\\right).\\tag{16.2}\n\\]\nAgain, this regret is defined for each realization of the stochastic rewards, and the expectation is with respect to the randomness of the algorithm. If algorithm is deterministic and outputs \\( a_{t} \\) at each time \\( t \\), then\n\\[\n\\mathrm{REG}_{T}=T\\max_{a}\\mu(a)-\\sum_{t=1}^{T}\\mu(a_{t}).\n\\]\nWe can further include randomization over data into the regret of stochastic bandit, by considering expected regret as follows:\n\\[\n\\mathbb{E}\\operatorname{REG}_{T}=T\\max_{a}\\mu(a)-\\mathbb{E}\\sum_{t=1}^{T}\\mu(a_{t}),\n\\]\nwhere the expectation is with respect to both the data and the internal randomization of the learning algorithm."}, {"id": "ch16:algorithm:16_1", "name": "UCB Algorithm", "statement": "Algorithm 16.1: UCB Algorithm\nInput: \\(K\\) and \\(T\\geq K\\) \n1 for \\(a=1,\\dots,K\\) do \n2 Let \\(\\hat{n}_0(a) = 0\\) \n3 Let \\(\\hat{\\mu}_0(a) = 0\\) \n4 for \\(t=1,2,\\ldots,T\\) do \n5 if \\(t\\leq K\\) then \n6 Let \\(a_{t} = t\\) \n7 else \n8 Let \\(a_{t}\\in \\arg \\max_{a}[\\hat{\\mu}_{t - 1}(a) + \\hat{c}_{t - 1}(a)]\\) according to (16.3) \n9 Pull arm \\(a_{t}\\) and observe reward \\(r_t(a_t)\\)"}, {"id": "ch16:equation:16_3", "name": "equation 16.3", "statement": "For each arm \\(a\\), define the number of pulls up to time \\(t\\) and the corresponding empirical mean by\n\\[\n\\hat n_t(a)=\\sum_{s=1}^{t}\\mathbb{1}(a_s=a), \\qquad\n\\hat\\mu_t(a)=\\frac{1}{\\hat n_t(a)}\\sum_{s=1}^{t} r_s(a_s)\\mathbb{1}(a_s=a),\n\\]\nwith the initialization \\(\\hat n_0(a)=0\\) and \\(\\hat\\mu_0(a)=0\\). In the UCB algorithm, after the initialization rounds, the arm is selected according to\n\\[\na_t\\in\\arg\\max_a\\left[\\hat\\mu_{t-1}(a)+\\hat c_{t-1}(a)\\right]. \\tag{16.3}\n\\]\nHere \\(\\hat c_t(a)\\) denotes the confidence width used by the algorithm."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Finset\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nlemma measurable_encode {α : Type*} {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n Measurable (Encodable.encode (α := α)) := by\n refine measurable_to_nat fun a ↦ ?_\n have : Encodable.encode ⁻¹' {Encodable.encode a} = {a} := by ext; simp\n rw [this]\n exact measurableSet_singleton _\n\nlemma measurableEmbedding_encode (α : Type*) {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n MeasurableEmbedding (Encodable.encode (α := α)) where\n injective := Encodable.encode_injective\n measurable := measurable_encode\n measurableSet_image' _ _ := .of_discrete\n\nsection Finite\n\nvariable {𝓧 𝓨 α : Type*} {m𝓧 : MeasurableSpace 𝓧} {m𝓨 : MeasurableSpace 𝓨}\n {mα : MeasurableSpace α} [TopologicalSpace α] [LinearOrder α]\n [OpensMeasurableSpace α] [OrderClosedTopology α] [SecondCountableTopology α]\n\nlemma measurableSet_isMax [Countable 𝓨]\n {f : 𝓧 → 𝓨 → α} (hf : ∀ y, Measurable (fun x ↦ f x y)) (y : 𝓨) :\n MeasurableSet {x | ∀ z, f x z ≤ f x y} := by\n rw [show {x | ∀ y', f x y' ≤ f x y} = ⋂ y', {x | f x y' ≤ f x y} by ext; simp]\n exact MeasurableSet.iInter fun z ↦ measurableSet_le (by fun_prop) (by fun_prop)\n\nlemma exists_isMaxOn' {α : Type*} [LinearOrder α]\n [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] (f : 𝓧 → 𝓨 → α) (x : 𝓧) :\n ∃ n : ℕ, ∃ y, n = Encodable.encode y ∧ ∀ z, f x z ≤ f x y := by\n obtain ⟨y, h⟩ := Finite.exists_max (f x)\n exact ⟨Encodable.encode y, y, rfl, h⟩\n\nnoncomputable\ndef measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] [MeasurableSingletonClass 𝓨]\n (f : 𝓧 → 𝓨 → α)\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (x : 𝓧) :\n 𝓨 :=\n (measurableEmbedding_encode 𝓨).invFun (Nat.find (exists_isMaxOn' f x))\n\nlemma measurable_measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨]\n [MeasurableSingletonClass 𝓨]\n {f : 𝓧 → 𝓨 → α}\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (hf : ∀ y, Measurable (fun x ↦ f x y)) :\n Measurable (measurableArgmax f) := by\n refine (MeasurableEmbedding.measurable_invFun (measurableEmbedding_encode 𝓨)).comp ?_\n refine measurable_find _ fun n ↦ ?_\n have : {x | ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y}\n = ⋃ y, ({x | n = Encodable.encode y} ∩ {x | ∀ z, f x z ≤ f x y}) := by ext; simp\n rw [this]\n refine MeasurableSet.iUnion fun y ↦ (MeasurableSet.inter (by simp) ?_)\n exact measurableSet_isMax (by fun_prop) y\n\nend Finite\n\nstructure Algorithm (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n\n policy : (n : ℕ) → Kernel (Iic n → 𝓐 × 𝓨) 𝓐\n [h_policy : ∀ n, IsMarkovKernel (policy n)]\n\n p0 : Measure 𝓐\n [hp0 : IsProbabilityMeasure p0]\n\nattribute [instance] Algorithm.h_policy Algorithm.hp0\n\nstructure Environment (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n\n feedback : (n : ℕ) → Kernel ((Iic n → 𝓐 × 𝓨) × 𝓐) 𝓨\n [h_feedback : ∀ n, IsMarkovKernel (feedback n)]\n\n ν0 : Kernel 𝓐 𝓨\n [hp0 : IsMarkovKernel ν0]\n\nattribute [instance] Environment.h_feedback Environment.hp0\n\nsection Traj\n\nvariable {𝓐 𝓨 : Type*} [MeasurableSpace 𝓐] [MeasurableSpace 𝓨]\n\nnoncomputable\ndef stepKernel (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n Kernel (Iic n → 𝓐 × 𝓨) (𝓐 × 𝓨) :=\n alg.policy n ⊗ₖ env.feedback n\n\ninstance (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n IsMarkovKernel (stepKernel alg env n) := by\n rw [stepKernel]; infer_instance\n\nnoncomputable\ndef trajMeasure (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) :\n Measure (ℕ → 𝓐 × 𝓨) :=\n Kernel.trajMeasure (alg.p0 ⊗ₘ env.ν0) (stepKernel alg env)\n\ndef action (n : ℕ) (h : ℕ → 𝓐 × 𝓨) : 𝓐 := (h n).1\n\nend Traj\n\nnoncomputable\ndef regret {𝓐 Ω : Type*} [MeasurableSpace 𝓐] (ν : Kernel 𝓐 ℝ) (A : ℕ → Ω → 𝓐) (t : ℕ) (ω : Ω) :\n ℝ :=\n (t : ℝ) * (⨆ a, (ν a)[id]) - ∑ s ∈ range t, (ν (A s ω))[id]\n\nsection History\n\nvariable {𝓐 R : Type*} [DecidableEq 𝓐] {n : ℕ}\n\nnoncomputable def pullCount' (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) : ℕ :=\n #(univ.filter (fun s ↦ (h s).1 = a))\n\nlemma pullCount'_eq_sum (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) :\n pullCount' n h a = ∑ s : Iic n, if (h s).1 = a then 1 else 0 := by\n rw [pullCount', Finset.card_filter]\n\nnoncomputable def sumRewards' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n ∑ s, if (h s).1 = a then (h s).2 else 0\n\nnoncomputable def empMean' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n sumRewards' n h a / pullCount' n h a\n\nvariable [MeasurableSpace 𝓐] [MeasurableSingletonClass 𝓐] [MeasurableSpace R]\n\n@[fun_prop]\nlemma measurable_pullCount' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × R ↦ pullCount' n h a) := by\n simp_rw [pullCount'_eq_sum]\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × R) ↦ if (h s).1 = a then 1 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_sumRewards' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ sumRewards' n h a) := by\n simp_rw [sumRewards']\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × ℝ) ↦ if (h s).1 = a then (h s).2 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_empMean' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ empMean' n h a) := by\n unfold empMean'; fun_prop\n\nend History\n\ndef RoundRobin.nextAction {K : ℕ} (hK : 0 < K) (n : ℕ) : Fin K := ⟨(n + 1) % K, Nat.mod_lt _ hK⟩\n\nsection Interaction\n\nvariable {𝓐 𝓨 : Type*} [MeasurableSpace 𝓐] [MeasurableSpace 𝓨]\n\nnoncomputable def detAlgorithm (nextA : (n : ℕ) → (Iic n → 𝓐 × 𝓨) → 𝓐)\n (h_next : ∀ n, Measurable (nextA n)) (action0 : 𝓐) : Algorithm 𝓐 𝓨 where\n policy n := Kernel.deterministic (nextA n) (h_next n)\n p0 := Measure.dirac action0\n\nnoncomputable def stationaryEnv (ν : Kernel 𝓐 𝓨) [IsMarkovKernel ν] : Environment 𝓐 𝓨 where\n feedback _ := ν.comap Prod.snd measurable_snd\n ν0 := ν\n\nend Interaction\n\nnoncomputable def ucbWidthNL {K : ℕ} (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) (a : Fin K) : ℝ :=\n Real.sqrt (Real.log (2 * ((pullCount' n h a : ℝ) + 1) ^ 2 / δ) / (2 * pullCount' n h a))\n\n@[fun_prop]\nlemma measurable_ucbWidthNL {K : ℕ} (δ : ℝ) (n : ℕ) (a : Fin K) :\n Measurable (fun h : Iic n → Fin K × ℝ ↦ ucbWidthNL δ n h a) := by\n unfold ucbWidthNL; fun_prop\n\nopen Classical in\n\nnoncomputable def nextArmNL {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) : Fin K :=\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n if n < K - 1 then RoundRobin.nextAction hK n else\n measurableArgmax (fun h a ↦ empMean' n h a + ucbWidthNL δ n h a) h\n\nopen Classical in\n@[fun_prop]\nlemma measurable_nextArmNL {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) :\n Measurable (nextArmNL hK δ n) := by\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n unfold nextArmNL\n split_ifs with hc\n · exact measurable_const\n · refine measurable_measurableArgmax fun a ↦ ?_\n fun_prop\n\nnoncomputable def ucbAlgorithmNL {K : ℕ} (hK : 0 < K) (δ : ℝ) : Algorithm (Fin K) ℝ :=\n detAlgorithm (nextArmNL hK δ) (measurable_nextArmNL hK δ) ⟨0, hK⟩\n\ntheorem ch16_theorem_16_3 {K T : ℕ} (hK : 0 < K) (hKT : K ≤ T)\n {δ : ℝ} (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1)\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K)\n (hmeasA : ∀ n, Measurable (nextA n))\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + ucbWidthNL δ n h a ≤\n empMean' n h (nextA n h) + ucbWidthNL δ n h (nextA n h)) :\n (trajMeasure (detAlgorithm nextA hmeasA ⟨0, hK⟩) (stationaryEnv ν))\n {ω | regret ν (action (𝓐 := Fin K) (𝓨 := ℝ)) T ω ≤\n ((K:ℝ) - 1) + Real.sqrt (8 * Real.log (2 * K * T ^ 2 / δ) * ((T:ℝ) - K) * K)}\n ≥ ENNReal.ofReal (1 - δ) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Finset\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nlemma measurable_encode {α : Type*} {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n Measurable (Encodable.encode (α := α)) := by\n refine measurable_to_nat fun a ↦ ?_\n have : Encodable.encode ⁻¹' {Encodable.encode a} = {a} := by ext; simp\n rw [this]\n exact measurableSet_singleton _\n\nlemma measurableEmbedding_encode (α : Type*) {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n MeasurableEmbedding (Encodable.encode (α := α)) where\n injective := Encodable.encode_injective\n measurable := measurable_encode\n measurableSet_image' _ _ := .of_discrete\n\nsection Finite\n\nvariable {𝓧 𝓨 α : Type*} {m𝓧 : MeasurableSpace 𝓧} {m𝓨 : MeasurableSpace 𝓨}\n {mα : MeasurableSpace α} [TopologicalSpace α] [LinearOrder α]\n [OpensMeasurableSpace α] [OrderClosedTopology α] [SecondCountableTopology α]\n\nlemma measurableSet_isMax [Countable 𝓨]\n {f : 𝓧 → 𝓨 → α} (hf : ∀ y, Measurable (fun x ↦ f x y)) (y : 𝓨) :\n MeasurableSet {x | ∀ z, f x z ≤ f x y} := by\n rw [show {x | ∀ y', f x y' ≤ f x y} = ⋂ y', {x | f x y' ≤ f x y} by ext; simp]\n exact MeasurableSet.iInter fun z ↦ measurableSet_le (by fun_prop) (by fun_prop)\n\nlemma exists_isMaxOn' {α : Type*} [LinearOrder α]\n [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] (f : 𝓧 → 𝓨 → α) (x : 𝓧) :\n ∃ n : ℕ, ∃ y, n = Encodable.encode y ∧ ∀ z, f x z ≤ f x y := by\n obtain ⟨y, h⟩ := Finite.exists_max (f x)\n exact ⟨Encodable.encode y, y, rfl, h⟩\n\nnoncomputable\ndef measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] [MeasurableSingletonClass 𝓨]\n (f : 𝓧 → 𝓨 → α)\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (x : 𝓧) :\n 𝓨 :=\n (measurableEmbedding_encode 𝓨).invFun (Nat.find (exists_isMaxOn' f x))\n\nlemma measurable_measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨]\n [MeasurableSingletonClass 𝓨]\n {f : 𝓧 → 𝓨 → α}\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (hf : ∀ y, Measurable (fun x ↦ f x y)) :\n Measurable (measurableArgmax f) := by\n refine (MeasurableEmbedding.measurable_invFun (measurableEmbedding_encode 𝓨)).comp ?_\n refine measurable_find _ fun n ↦ ?_\n have : {x | ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y}\n = ⋃ y, ({x | n = Encodable.encode y} ∩ {x | ∀ z, f x z ≤ f x y}) := by ext; simp\n rw [this]\n refine MeasurableSet.iUnion fun y ↦ (MeasurableSet.inter (by simp) ?_)\n exact measurableSet_isMax (by fun_prop) y\n\nend Finite\n\nstructure Algorithm (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n\n policy : (n : ℕ) → Kernel (Iic n → 𝓐 × 𝓨) 𝓐\n [h_policy : ∀ n, IsMarkovKernel (policy n)]\n\n p0 : Measure 𝓐\n [hp0 : IsProbabilityMeasure p0]\n\nattribute [instance] Algorithm.h_policy Algorithm.hp0\n\nstructure Environment (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n\n feedback : (n : ℕ) → Kernel ((Iic n → 𝓐 × 𝓨) × 𝓐) 𝓨\n [h_feedback : ∀ n, IsMarkovKernel (feedback n)]\n\n ν0 : Kernel 𝓐 𝓨\n [hp0 : IsMarkovKernel ν0]\n\nattribute [instance] Environment.h_feedback Environment.hp0\n\nsection Traj\n\nvariable {𝓐 𝓨 : Type*} [MeasurableSpace 𝓐] [MeasurableSpace 𝓨]\n\nnoncomputable\ndef stepKernel (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n Kernel (Iic n → 𝓐 × 𝓨) (𝓐 × 𝓨) :=\n alg.policy n ⊗ₖ env.feedback n\n\ninstance (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n IsMarkovKernel (stepKernel alg env n) := by\n rw [stepKernel]; infer_instance\n\nnoncomputable\ndef trajMeasure (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) :\n Measure (ℕ → 𝓐 × 𝓨) :=\n Kernel.trajMeasure (alg.p0 ⊗ₘ env.ν0) (stepKernel alg env)\n\ndef action (n : ℕ) (h : ℕ → 𝓐 × 𝓨) : 𝓐 := (h n).1\n\nend Traj\n\nnoncomputable\ndef regret {𝓐 Ω : Type*} [MeasurableSpace 𝓐] (ν : Kernel 𝓐 ℝ) (A : ℕ → Ω → 𝓐) (t : ℕ) (ω : Ω) :\n ℝ :=\n (t : ℝ) * (⨆ a, (ν a)[id]) - ∑ s ∈ range t, (ν (A s ω))[id]\n\nsection History\n\nvariable {𝓐 R : Type*} [DecidableEq 𝓐] {n : ℕ}\n\nnoncomputable def pullCount' (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) : ℕ :=\n #(univ.filter (fun s ↦ (h s).1 = a))\n\nlemma pullCount'_eq_sum (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) :\n pullCount' n h a = ∑ s : Iic n, if (h s).1 = a then 1 else 0 := by\n rw [pullCount', Finset.card_filter]\n\nnoncomputable def sumRewards' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n ∑ s, if (h s).1 = a then (h s).2 else 0\n\nnoncomputable def empMean' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n sumRewards' n h a / pullCount' n h a\n\nvariable [MeasurableSpace 𝓐] [MeasurableSingletonClass 𝓐] [MeasurableSpace R]\n\n@[fun_prop]\nlemma measurable_pullCount' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × R ↦ pullCount' n h a) := by\n simp_rw [pullCount'_eq_sum]\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × R) ↦ if (h s).1 = a then 1 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_sumRewards' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ sumRewards' n h a) := by\n simp_rw [sumRewards']\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × ℝ) ↦ if (h s).1 = a then (h s).2 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_empMean' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ empMean' n h a) := by\n unfold empMean'; fun_prop\n\nend History\n\ndef RoundRobin.nextAction {K : ℕ} (hK : 0 < K) (n : ℕ) : Fin K := ⟨(n + 1) % K, Nat.mod_lt _ hK⟩\n\nsection Interaction\n\nvariable {𝓐 𝓨 : Type*} [MeasurableSpace 𝓐] [MeasurableSpace 𝓨]\n\nnoncomputable def detAlgorithm (nextA : (n : ℕ) → (Iic n → 𝓐 × 𝓨) → 𝓐)\n (h_next : ∀ n, Measurable (nextA n)) (action0 : 𝓐) : Algorithm 𝓐 𝓨 where\n policy n := Kernel.deterministic (nextA n) (h_next n)\n p0 := Measure.dirac action0\n\nnoncomputable def stationaryEnv (ν : Kernel 𝓐 𝓨) [IsMarkovKernel ν] : Environment 𝓐 𝓨 where\n feedback _ := ν.comap Prod.snd measurable_snd\n ν0 := ν\n\nend Interaction\n\nnoncomputable def ucbWidthNL {K : ℕ} (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) (a : Fin K) : ℝ :=\n Real.sqrt (Real.log (2 * ((pullCount' n h a : ℝ) + 1) ^ 2 / δ) / (2 * pullCount' n h a))\n\n@[fun_prop]\nlemma measurable_ucbWidthNL {K : ℕ} (δ : ℝ) (n : ℕ) (a : Fin K) :\n Measurable (fun h : Iic n → Fin K × ℝ ↦ ucbWidthNL δ n h a) := by\n unfold ucbWidthNL; fun_prop\n\nopen Classical in\n\nnoncomputable def nextArmNL {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) : Fin K :=\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n if n < K - 1 then RoundRobin.nextAction hK n else\n measurableArgmax (fun h a ↦ empMean' n h a + ucbWidthNL δ n h a) h\n\nopen Classical in\n@[fun_prop]\nlemma measurable_nextArmNL {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) :\n Measurable (nextArmNL hK δ n) := by\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n unfold nextArmNL\n split_ifs with hc\n · exact measurable_const\n · refine measurable_measurableArgmax fun a ↦ ?_\n fun_prop\n\nnoncomputable def ucbAlgorithmNL {K : ℕ} (hK : 0 < K) (δ : ℝ) : Algorithm (Fin K) ℝ :=\n detAlgorithm (nextArmNL hK δ) (measurable_nextArmNL hK δ) ⟨0, hK⟩\n\n\nsection Process\n\nvariable {K : ℕ}\n\n/-- Number of pulls of arm `a` in rounds `0, ..., n-1`. -/\ndef bcnt (a : Fin K) (n : ℕ) (ω : ℕ → Fin K × ℝ) : ℕ :=\n ∑ s ∈ range n, if (ω s).1 = a then 1 else 0\n\n/-- Sum of rewards obtained from arm `a` in rounds `0, ..., n-1`. -/\nnoncomputable def bsumR (a : Fin K) (n : ℕ) (ω : ℕ → Fin K × ℝ) : ℝ :=\n ∑ s ∈ range n, if (ω s).1 = a then (ω s).2 else 0\n\n/-- Sum of the centred rewards over the first `m` pulls of arm `a`, among rounds `0,...,n-1`. -/\nnoncomputable def bW (mu : Fin K → ℝ) (a : Fin K) (m n : ℕ) (ω : ℕ → Fin K × ℝ) : ℝ :=\n ∑ s ∈ range n, if (ω s).1 = a ∧ bcnt a s ω < m then (ω s).2 - mu a else 0\n\n/-- Number of terms in `bW`. -/\ndef bD (a : Fin K) (m n : ℕ) (ω : ℕ → Fin K × ℝ) : ℕ :=\n ∑ s ∈ range n, if (ω s).1 = a ∧ bcnt a s ω < m then 1 else 0\n\nvariable {a : Fin K} {m n : ℕ} {ω ω' : ℕ → Fin K × ℝ} {mu : Fin K → ℝ}\n\n@[simp] lemma bcnt_zero : bcnt a 0 ω = 0 := by simp [bcnt]\n@[simp] lemma bW_zero : bW mu a m 0 ω = 0 := by simp [bW]\n@[simp] lemma bD_zero : bD a m 0 ω = 0 := by simp [bD]\n@[simp] lemma bsumR_zero : bsumR a 0 ω = 0 := by simp [bsumR]\n\nlemma bcnt_succ : bcnt a (n+1) ω = bcnt a n ω + (if (ω n).1 = a then 1 else 0) := by\n rw [bcnt, bcnt, Finset.sum_range_succ]\n\nlemma bW_succ : bW mu a m (n+1) ω\n = bW mu a m n ω + (if (ω n).1 = a ∧ bcnt a n ω < m then (ω n).2 - mu a else 0) := by\n rw [bW, bW, Finset.sum_range_succ]\n\nlemma bD_succ : bD a m (n+1) ω\n = bD a m n ω + (if (ω n).1 = a ∧ bcnt a n ω < m then 1 else 0) := by\n rw [bD, bD, Finset.sum_range_succ]\n\nlemma bcnt_mono (h : n ≤ n') : bcnt a n ω ≤ bcnt a n' ω := by\n have hsub : range n ⊆ range n' := Finset.range_subset_range.2 h\n exact Finset.sum_le_sum_of_subset hsub\n\nlemma bcnt_le_self : bcnt a n ω ≤ n := by\n calc bcnt a n ω ≤ ∑ _s ∈ range n, 1 := by\n refine Finset.sum_le_sum fun i _ ↦ ?_\n split <;> simp\n _ = n := by simp\n\nlemma bcnt_congr (h : ∀ i < n, ω i = ω' i) : bcnt a n ω = bcnt a n ω' := by\n refine Finset.sum_congr rfl fun i hi ↦ ?_\n rw [h i (Finset.mem_range.1 hi)]\n\nlemma bW_congr (h : ∀ i < n, ω i = ω' i) : bW mu a m n ω = bW mu a m n ω' := by\n refine Finset.sum_congr rfl fun i hi ↦ ?_\n have hi' := Finset.mem_range.1 hi\n rw [h i hi', bcnt_congr (fun j hj ↦ h j (hj.trans hi'))]\n\nlemma bD_congr (h : ∀ i < n, ω i = ω' i) : bD a m n ω = bD a m n ω' := by\n refine Finset.sum_congr rfl fun i hi ↦ ?_\n have hi' := Finset.mem_range.1 hi\n rw [h i hi', bcnt_congr (fun j hj ↦ h j (hj.trans hi'))]\n\n/-- If `s < n` and arm `a` is pulled at time `s`, then `s` is among the first `bcnt a n ω`\npulls of `a`. -/\nlemma bcnt_lt_of_pull (hs : s < n) (ha : (ω s).1 = a) : bcnt a s ω < bcnt a n ω := by\n have h1 : bcnt a (s+1) ω = bcnt a s ω + 1 := by rw [bcnt_succ, if_pos ha]\n have h2 : bcnt a (s+1) ω ≤ bcnt a n ω := bcnt_mono hs\n lia\n\nlemma bW_eq_of_cnt (h : bcnt a n ω = m) :\n bW mu a m n ω = bsumR a n ω - (m : ℝ) * mu a := by\n have key : ∀ s ∈ range n, (if (ω s).1 = a ∧ bcnt a s ω < m then (ω s).2 - mu a else 0)\n = (if (ω s).1 = a then (ω s).2 else 0) - (if (ω s).1 = a then mu a else 0) := by\n intro s hs\n by_cases ha : (ω s).1 = a\n · have : bcnt a s ω < m := h ▸ bcnt_lt_of_pull (Finset.mem_range.1 hs) ha\n simp [ha, this]\n · simp [ha]\n have key2 : ∑ s ∈ range n, (if (ω s).1 = a then mu a else 0) = (m : ℝ) * mu a := by\n have h3 : ∀ s ∈ range n, (if (ω s).1 = a then mu a else 0)\n = ((if (ω s).1 = a then (1:ℝ) else 0)) * mu a := by\n intro s _; split <;> simp\n rw [Finset.sum_congr rfl h3, ← Finset.sum_mul, ← h]\n congr 1\n rw [bcnt, Nat.cast_sum]\n refine Finset.sum_congr rfl fun s _ ↦ ?_\n split <;> simp\n rw [bW, Finset.sum_congr rfl key, Finset.sum_sub_distrib, key2]\n rfl\n\nlemma bW_stable (h : bcnt a n ω = m) (hn : n ≤ n') :\n bW mu a m n' ω = bW mu a m n ω := by\n rw [bW, bW, ← Finset.sum_range_add_sum_Ico _ hn]\n have : ∑ s ∈ Finset.Ico n n', (if (ω s).1 = a ∧ bcnt a s ω < m then (ω s).2 - mu a else 0) = 0 := by\n refine Finset.sum_eq_zero fun s hs ↦ ?_\n rw [if_neg]\n rintro ⟨-, hlt⟩\n have : m ≤ bcnt a s ω := h ▸ bcnt_mono (Finset.mem_Ico.1 hs).1\n lia\n rw [this, add_zero]\n\nlemma bD_stable (h : bcnt a n ω = m) (hn : n ≤ n') :\n bD a m n' ω = bD a m n ω := by\n rw [bD, bD, ← Finset.sum_range_add_sum_Ico _ hn]\n have : ∑ s ∈ Finset.Ico n n', (if (ω s).1 = a ∧ bcnt a s ω < m then 1 else 0) = 0 := by\n refine Finset.sum_eq_zero fun s hs ↦ ?_\n rw [if_neg]\n rintro ⟨-, hlt⟩\n have : m ≤ bcnt a s ω := h ▸ bcnt_mono (Finset.mem_Ico.1 hs).1\n lia\n rw [this, add_zero]\n\nlemma bD_le : bD a m n ω ≤ m := by\n classical\n have hcard : bD a m n ω\n = #((range n).filter (fun s ↦ (ω s).1 = a ∧ bcnt a s ω < m)) := by\n rw [bD, Finset.card_filter]\n rw [hcard]\n have : #((range n).filter (fun s ↦ (ω s).1 = a ∧ bcnt a s ω < m)) ≤ #(range m) := by\n refine Finset.card_le_card_of_injOn (fun s ↦ bcnt a s ω) ?_ ?_\n · intro s hs\n simp only [Finset.coe_filter, Set.mem_setOf_eq] at hs\n exact Finset.mem_range.2 hs.2.2\n · intro s hs t ht hst\n simp only [Finset.coe_filter, Set.mem_setOf_eq] at hs ht\n by_contra hne\n rcases lt_or_gt_of_ne hne with hlt | hlt\n · have := bcnt_lt_of_pull hlt hs.2.1\n lia\n · have := bcnt_lt_of_pull hlt ht.2.1\n lia\n rwa [Finset.card_range] at this\n\nend Process\n\nsection Meas\n\nvariable {K : ℕ}\n\nlemma measurableSet_action (s : ℕ) (a : Fin K) :\n MeasurableSet {ω : ℕ → Fin K × ℝ | (ω s).1 = a} :=\n (measurableSet_singleton a).preimage (by fun_prop)\n\nlemma measurable_bcnt (a : Fin K) (n : ℕ) :\n Measurable (fun ω : ℕ → Fin K × ℝ ↦ bcnt a n ω) := by\n induction n with\n | zero => simp only [bcnt_zero]; exact measurable_const\n | succ n ih =>\n simp only [bcnt_succ]\n exact ih.add (Measurable.ite (measurableSet_action n a) measurable_const measurable_const)\n\nlemma measurableSet_pullIdx (a : Fin K) (m s : ℕ) :\n MeasurableSet {ω : ℕ → Fin K × ℝ | (ω s).1 = a ∧ bcnt a s ω < m} :=\n (measurableSet_action s a).inter\n ((measurable_bcnt a s) (measurableSet_Iio (a := m)))\n\nlemma measurable_bW (mu : Fin K → ℝ) (a : Fin K) (m n : ℕ) :\n Measurable (fun ω : ℕ → Fin K × ℝ ↦ bW mu a m n ω) := by\n induction n with\n | zero => simp only [bW_zero]; exact measurable_const\n | succ n ih =>\n simp only [bW_succ]\n exact ih.add (Measurable.ite (measurableSet_pullIdx a m n) (by fun_prop) measurable_const)\n\nlemma measurable_bD (a : Fin K) (m n : ℕ) :\n Measurable (fun ω : ℕ → Fin K × ℝ ↦ bD a m n ω) := by\n induction n with\n | zero => simp only [bD_zero]; exact measurable_const\n | succ n ih =>\n simp only [bD_succ]\n exact ih.add (Measurable.ite (measurableSet_pullIdx a m n) measurable_const measurable_const)\n\nlemma measurable_bsumR (a : Fin K) (n : ℕ) :\n Measurable (fun ω : ℕ → Fin K × ℝ ↦ bsumR a n ω) := by\n induction n with\n | zero => simp only [bsumR_zero]; exact measurable_const\n | succ n ih =>\n have : ∀ ω : ℕ → Fin K × ℝ, bsumR a (n+1) ω\n = bsumR a n ω + (if (ω n).1 = a then (ω n).2 else 0) := by\n intro ω; rw [bsumR, bsumR, Finset.sum_range_succ]\n simp only [this]\n exact ih.add (Measurable.ite (measurableSet_action n a) (by fun_prop) measurable_const)\n\nend Meas\n\nsection MGF\n\nvariable {K : ℕ}\n\n/-- Extension of a finite history to an infinite trajectory (junk after time `n`). -/\ndef extd (z0 : Fin K × ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) : ℕ → Fin K × ℝ :=\n fun i ↦ if hi : i ≤ n then h ⟨i, Finset.mem_Iic.mpr hi⟩ else z0\n\nlemma extd_frestrictLe (z0 : Fin K × ℝ) (n : ℕ) (ω : ℕ → Fin K × ℝ) {i : ℕ} (hi : i ≤ n) :\n extd z0 n (Preorder.frestrictLe n ω) i = ω i := by\n simp [extd, hi, Preorder.frestrictLe]\n\nlemma measurable_extd (z0 : Fin K × ℝ) (n : ℕ) : Measurable (extd z0 n) := by\n refine measurable_pi_lambda _ fun i ↦ ?_\n by_cases hi : i ≤ n\n · simp only [extd, dif_pos hi]\n exact measurable_pi_apply _\n · simp only [extd, dif_neg hi]\n exact measurable_const\n\nnoncomputable def bPhi (mu : Fin K → ℝ) (lam : ℝ) (a : Fin K) (m n : ℕ)\n (ω : ℕ → Fin K × ℝ) : ℝ≥0∞ :=\n ENNReal.ofReal (Real.exp (lam * bW mu a m n ω - lam ^ 2 / 8 * (bD a m n ω : ℝ)))\n\nlemma measurable_bPhi (mu : Fin K → ℝ) (lam : ℝ) (a : Fin K) (m n : ℕ) :\n Measurable (bPhi mu lam a m n) := by\n unfold bPhi\n refine ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp ?_)\n exact ((measurable_bW mu a m n).const_mul lam).sub\n (((measurable_of_countable (Nat.cast : ℕ → ℝ)).comp (measurable_bD a m n)).const_mul _)\n\n@[simp] lemma bPhi_zero (mu : Fin K → ℝ) (lam : ℝ) (a : Fin K) (m : ℕ) (ω : ℕ → Fin K × ℝ) :\n bPhi mu lam a m 0 ω = 1 := by simp [bPhi]\n\nlemma bPhi_succ (mu : Fin K → ℝ) (lam : ℝ) (a : Fin K) (m n : ℕ) (ω : ℕ → Fin K × ℝ) :\n bPhi mu lam a m (n + 1) ω = bPhi mu lam a m n ω *\n ENNReal.ofReal (Real.exp\n (lam * (if (ω n).1 = a ∧ bcnt a n ω < m then (ω n).2 - mu a else 0)\n - lam ^ 2 / 8 * (if (ω n).1 = a ∧ bcnt a n ω < m then (1:ℝ) else 0))) := by\n rw [bPhi, bPhi, bW_succ, bD_succ, ← ENNReal.ofReal_mul (Real.exp_nonneg _), ← Real.exp_add]\n congr 1\n by_cases hP : (ω n).1 = a ∧ bcnt a n ω < m\n · simp only [if_pos hP]; push_cast; ring_nf\n · simp only [if_neg hP]; push_cast; ring_nf\n\nlemma bPhi_congr (mu : Fin K → ℝ) (lam : ℝ) (a : Fin K) (m n : ℕ) {ω ω' : ℕ → Fin K × ℝ}\n (h : ∀ i < n, ω i = ω' i) : bPhi mu lam a m n ω = bPhi mu lam a m n ω' := by\n rw [bPhi, bPhi, bW_congr h, bD_congr h]\n\nend MGF\n\nsection Bandit\n\nvariable {K : ℕ} {hK : 0 < K} {ν : Kernel (Fin K) ℝ} [IsMarkovKernel ν]\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K} {hmeasA : ∀ n, Measurable (nextA n)}\n\nnoncomputable def banditP {K : ℕ} (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K) (hmeasA : ∀ n, Measurable (nextA n)) :\n Measure (ℕ → Fin K × ℝ) :=\n trajMeasure (detAlgorithm nextA hmeasA ⟨0, hK⟩) (stationaryEnv ν)\n\ninstance : IsProbabilityMeasure (banditP hK ν nextA hmeasA) := by\n unfold banditP trajMeasure; infer_instance\n\nlemma stepKernel_lintegral (n : ℕ) (h : Iic n → Fin K × ℝ) (f : (Fin K × ℝ) → ℝ≥0∞)\n (hf : Measurable f) :\n ∫⁻ z, f z ∂(stepKernel (detAlgorithm nextA hmeasA ⟨0, hK⟩) (stationaryEnv ν) n h)\n = ∫⁻ y, f (nextA n h, y) ∂(ν (nextA n h)) := by\n rw [stepKernel, Kernel.lintegral_compProd _ _ _ hf]\n simp [detAlgorithm, stationaryEnv, Kernel.lintegral_deterministic]\n\nlemma keyStep (n : ℕ) {g : ((Iic n → Fin K × ℝ) × (Fin K × ℝ)) → ℝ≥0∞} (hg : Measurable g) :\n ∫⁻ ω, g (Preorder.frestrictLe n ω, ω (n+1)) ∂(banditP hK ν nextA hmeasA)\n = ∫⁻ ω, (∫⁻ y, g (Preorder.frestrictLe n ω,\n (nextA n (Preorder.frestrictLe n ω), y)) ∂(ν (nextA n (Preorder.frestrictLe n ω))))\n ∂(banditP hK ν nextA hmeasA) := by\n unfold banditP GraduateLevel.trajMeasure\n rw [← lintegral_map (g := fun x : ℕ → Fin K × ℝ ↦ (Preorder.frestrictLe n x, x (n+1)))\n hg (by fun_prop),\n ← Kernel.map_frestrictLe_trajMeasure_compProd_eq_map_trajMeasure,\n Measure.lintegral_compProd hg,\n lintegral_map (hg.lintegral_kernel_prod_right'\n (κ := stepKernel (detAlgorithm nextA hmeasA ⟨0, hK⟩) (stationaryEnv ν) n)) (by fun_prop)]\n refine lintegral_congr fun ω ↦ ?_\n exact stepKernel_lintegral n _ _ (hg.comp (by fun_prop))\n\nlemma trajMeasure_map_zero {X : ℕ → Type*} [∀ n, MeasurableSpace (X n)]\n (κ : (n : ℕ) → Kernel ((i : Iic n) → X i) (X (n + 1))) [∀ n, IsMarkovKernel (κ n)]\n (μ₀ : Measure (X 0)) [IsProbabilityMeasure μ₀] :\n (Kernel.trajMeasure μ₀ κ).map (fun x ↦ x 0) = μ₀ := by\n have h1 : (fun x : (∀ n, X n) ↦ x 0)\n = (fun h : ((i : Iic (0:ℕ)) → X i) ↦ h default) ∘ (Preorder.frestrictLe 0) := rfl\n rw [h1, ← Measure.map_map (by fun_prop) (by fun_prop)]\n rw [Kernel.trajMeasure, Measure.map_comp _ _ (by fun_prop), Kernel.traj_map_frestrictLe,\n Kernel.partialTraj_self]\n rw [Measure.id_comp, Measure.map_map (by fun_prop) (by fun_prop)]\n have : ((fun h : ((i : Iic (0:ℕ)) → X i) ↦ h default) ∘\n ⇑(MeasurableEquiv.piUnique (fun i : Iic (0:ℕ) ↦ X i)).symm) = id := by\n ext x; simp\n rw [this, Measure.map_id]\n\nlemma keyStep0 {g : (Fin K × ℝ) → ℝ≥0∞} (hg : Measurable g) :\n ∫⁻ ω, g (ω 0) ∂(banditP hK ν nextA hmeasA)\n = ∫⁻ y, g (⟨0, hK⟩, y) ∂(ν ⟨0, hK⟩) := by\n unfold banditP GraduateLevel.trajMeasure\n rw [← lintegral_map (g := fun x : ℕ → Fin K × ℝ ↦ x 0) hg (by fun_prop),\n trajMeasure_map_zero]\n show ∫⁻ z, g z ∂((Measure.dirac (⟨0, hK⟩ : Fin K)) ⊗ₘ ν) = _\n rw [Measure.lintegral_compProd hg, lintegral_dirac]\n\n/-- Mean reward of arm `a`. -/\nnoncomputable def bmu {K : ℕ} (ν : Kernel (Fin K) ℝ) (a : Fin K) : ℝ := ∫ y, y ∂(ν a)\n\nlemma ae_mem_Icc (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) :\n ∀ᵐ y ∂(ν a), y ∈ Set.Icc (0:ℝ) 1 := by\n rw [ae_iff]\n have h1 : {y : ℝ | ¬ y ∈ Set.Icc (0:ℝ) 1} = (Set.Icc (0:ℝ) 1)ᶜ := rfl\n rw [h1, prob_compl_eq_one_sub measurableSet_Icc, hrew a, tsub_self]\n\nlemma hoeffding_subG (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) :\n HasSubgaussianMGF (fun y : ℝ ↦ y - bmu ν a) ((‖(1:ℝ) - 0‖₊ / 2) ^ 2) (ν a) := by\n have := ProbabilityTheory.hasSubgaussianMGF_of_mem_Icc (μ := ν a) (X := (id : ℝ → ℝ))\n (a := 0) (b := 1) aemeasurable_id (ae_mem_Icc hrew a)\n simpa [bmu, id] using this\n\nlemma hoeffding_mgf (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) (lam : ℝ) :\n ∫⁻ y, ENNReal.ofReal (Real.exp (lam * (y - bmu ν a))) ∂(ν a)\n ≤ ENNReal.ofReal (Real.exp (lam ^ 2 / 8)) := by\n have hsub := hoeffding_subG hrew a\n have hint : Integrable (fun y : ℝ ↦ Real.exp (lam * (y - bmu ν a))) (ν a) :=\n hsub.integrable_exp_mul lam\n rw [← ofReal_integral_eq_lintegral_ofReal hint (ae_of_all _ fun y ↦ Real.exp_nonneg _)]\n refine ENNReal.ofReal_le_ofReal ?_\n have hm := hsub.mgf_le lam\n have hc : (((‖(1:ℝ) - 0‖₊ / 2) ^ 2 : ℝ≥0) : ℝ) = 1 / 4 := by\n norm_num\n rw [hc] at hm\n calc ∫ y, Real.exp (lam * (y - bmu ν a)) ∂(ν a) = mgf (fun y : ℝ ↦ y - bmu ν a) (ν a) lam := rfl\n _ ≤ Real.exp (1 / 4 * lam ^ 2 / 2) := hm\n _ = Real.exp (lam ^ 2 / 8) := by ring_nf\n\nlemma measurable_ite_const {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] (c : Prop)\n [Decidable c] {f g : α → β} (hf : Measurable f) (hg : Measurable g) :\n Measurable (fun x ↦ if c then f x else g x) := by\n by_cases h : c\n · simpa only [if_pos h] using hf\n · simpa only [if_neg h] using hg\n\nlemma onestep_le_eq (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) (lam : ℝ)\n (Q : Prop) [Decidable Q] :\n ∫⁻ y, ENNReal.ofReal (Real.exp\n (lam * (if Q then y - bmu ν a else 0)\n - lam ^ 2 / 8 * (if Q then (1:ℝ) else 0))) ∂(ν a) ≤ 1 := by\n by_cases hq : Q\n · have key := hoeffding_mgf hrew a lam\n simp only [if_pos hq]\n calc ∫⁻ y, ENNReal.ofReal (Real.exp (lam * (y - bmu ν a) - lam ^ 2 / 8 * 1)) ∂(ν a)\n = ∫⁻ y, ENNReal.ofReal (Real.exp (-(lam ^ 2 / 8)))\n * ENNReal.ofReal (Real.exp (lam * (y - bmu ν a))) ∂(ν a) := by\n refine lintegral_congr fun y ↦ ?_\n rw [← ENNReal.ofReal_mul (Real.exp_nonneg _), ← Real.exp_add]\n ring_nf\n _ = ENNReal.ofReal (Real.exp (-(lam ^ 2 / 8)))\n * ∫⁻ y, ENNReal.ofReal (Real.exp (lam * (y - bmu ν a))) ∂(ν a) := by\n rw [lintegral_const_mul _ (by fun_prop)]\n _ ≤ ENNReal.ofReal (Real.exp (-(lam ^ 2 / 8))) * ENNReal.ofReal (Real.exp (lam ^ 2 / 8)) :=\n mul_le_mul_left' key _\n _ = 1 := by\n rw [← ENNReal.ofReal_mul (Real.exp_nonneg _), ← Real.exp_add]\n norm_num\n · simp only [if_neg hq]\n simp\n\nlemma onestep_le (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a b : Fin K) (lam : ℝ)\n (Q : Prop) [Decidable Q] (hQ : Q → b = a) :\n ∫⁻ y, ENNReal.ofReal (Real.exp\n (lam * (if Q then y - bmu ν a else 0)\n - lam ^ 2 / 8 * (if Q then (1:ℝ) else 0))) ∂(ν b) ≤ 1 := by\n by_cases hq : Q\n · rw [hQ hq]\n exact onestep_le_eq hrew a lam Q\n · simp only [if_neg hq]\n simp\n\n/-- A junk element of the observation space. -/\ndef bz0 {K : ℕ} (hK : 0 < K) : Fin K × ℝ := (⟨0, hK⟩, 0)\n\nlemma bPhi_lintegral_le (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (lam : ℝ) (a : Fin K) (m n : ℕ) :\n ∫⁻ ω, bPhi (bmu ν) lam a m n ω ∂(banditP hK ν nextA hmeasA) ≤ 1 := by\n classical\n induction n with\n | zero => simp [bPhi_zero]\n | succ n ih =>\n cases n with\n | zero =>\n set g0 : Fin K × ℝ → ℝ≥0∞ := fun z ↦ ENNReal.ofReal (Real.exp\n (lam * (if z.1 = a ∧ (0:ℕ) < m then z.2 - bmu ν a else 0)\n - lam ^ 2 / 8 * (if z.1 = a ∧ (0:ℕ) < m then (1:ℝ) else 0))) with hg0\n have hg0meas : Measurable g0 := by\n rw [hg0]\n refine ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp ?_)\n have hset : MeasurableSet {z : Fin K × ℝ | z.1 = a ∧ (0:ℕ) < m} :=\n MeasurableSet.inter ((measurableSet_singleton a).preimage (by fun_prop))\n (MeasurableSet.const _)\n exact ((Measurable.ite hset (by fun_prop) measurable_const).const_mul lam).sub\n ((Measurable.ite hset measurable_const measurable_const).const_mul _)\n have h1 : ∀ ω : ℕ → Fin K × ℝ, bPhi (bmu ν) lam a m 1 ω = g0 (ω 0) := by\n intro ω\n rw [show (1:ℕ) = 0 + 1 from rfl, bPhi_succ, bPhi_zero, one_mul, bcnt_zero, hg0]\n calc ∫⁻ ω, bPhi (bmu ν) lam a m 1 ω ∂(banditP hK ν nextA hmeasA)\n = ∫⁻ ω, g0 (ω 0) ∂(banditP hK ν nextA hmeasA) := lintegral_congr h1\n _ = ∫⁻ y, g0 (⟨0, hK⟩, y) ∂(ν ⟨0, hK⟩) := keyStep0 hg0meas\n _ ≤ 1 := by\n simp only [hg0]\n exact onestep_le hrew a ⟨0, hK⟩ lam\n (((⟨0, hK⟩ : Fin K) = a ∧ (0:ℕ) < m)) (fun h ↦ h.1)\n | succ n =>\n set g : ((Iic n → Fin K × ℝ) × (Fin K × ℝ)) → ℝ≥0∞ := fun p ↦\n bPhi (bmu ν) lam a m (n+1) (extd (bz0 hK) n p.1) * ENNReal.ofReal (Real.exp\n (lam * (if p.2.1 = a ∧ bcnt a (n+1) (extd (bz0 hK) n p.1) < m\n then p.2.2 - bmu ν a else 0)\n - lam ^ 2 / 8 *\n (if p.2.1 = a ∧ bcnt a (n+1) (extd (bz0 hK) n p.1) < m then (1:ℝ) else 0))) with hg\n have hgmeas : Measurable g := by\n have h1 : Measurable (fun p : ((Iic n → Fin K × ℝ) × (Fin K × ℝ)) ↦\n extd (bz0 hK) n p.1) := (measurable_extd (bz0 hK) n).comp measurable_fst\n have h2 : MeasurableSet {p : ((Iic n → Fin K × ℝ) × (Fin K × ℝ)) |\n p.2.1 = a ∧ bcnt a (n+1) (extd (bz0 hK) n p.1) < m} :=\n MeasurableSet.inter ((measurableSet_singleton a).preimage (by fun_prop))\n (((measurable_bcnt a (n+1)).comp h1) (measurableSet_Iio (a := m)))\n rw [hg]\n refine Measurable.mul ((measurable_bPhi (bmu ν) lam a m (n+1)).comp h1) ?_\n refine ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp ?_)\n exact ((Measurable.ite h2 (by fun_prop) measurable_const).const_mul lam).sub\n ((Measurable.ite h2 measurable_const measurable_const).const_mul _)\n have hkey : ∀ ω : ℕ → Fin K × ℝ, bPhi (bmu ν) lam a m (n+1+1) ω\n = g (Preorder.frestrictLe n ω, ω (n+1)) := by\n intro ω\n have hext : ∀ i < n + 1, ω i = extd (bz0 hK) n (Preorder.frestrictLe n ω) i := fun i hi ↦\n (extd_frestrictLe (bz0 hK) n ω (Nat.lt_succ_iff.mp hi)).symm\n rw [bPhi_succ, hg]\n simp only\n rw [bPhi_congr (bmu ν) lam a m (n+1) hext, bcnt_congr hext]\n calc ∫⁻ ω, bPhi (bmu ν) lam a m (n+1+1) ω ∂(banditP hK ν nextA hmeasA)\n = ∫⁻ ω, g (Preorder.frestrictLe n ω, ω (n+1)) ∂(banditP hK ν nextA hmeasA) :=\n lintegral_congr hkey\n _ = ∫⁻ ω, (∫⁻ y, g (Preorder.frestrictLe n ω,\n (nextA n (Preorder.frestrictLe n ω), y)) ∂(ν (nextA n (Preorder.frestrictLe n ω))))\n ∂(banditP hK ν nextA hmeasA) := keyStep n hgmeas\n _ ≤ ∫⁻ ω, bPhi (bmu ν) lam a m (n+1) ω ∂(banditP hK ν nextA hmeasA) := by\n refine lintegral_mono fun ω ↦ ?_\n set h := Preorder.frestrictLe n ω with hh\n have hcm : Measurable (fun y : ℝ ↦ ENNReal.ofReal (Real.exp\n (lam * (if nextA n h = a ∧ bcnt a (n+1) (extd (bz0 hK) n h) < m\n then y - bmu ν a else 0)\n - lam ^ 2 / 8 *\n (if nextA n h = a ∧ bcnt a (n+1) (extd (bz0 hK) n h) < m\n then (1:ℝ) else 0)))) := by\n by_cases hC : nextA n h = a ∧ bcnt a (n+1) (extd (bz0 hK) n h) < m\n · simp only [if_pos hC]; fun_prop\n · simp only [if_neg hC]; fun_prop\n calc ∫⁻ y, g (h, (nextA n h, y)) ∂(ν (nextA n h))\n = ∫⁻ y, bPhi (bmu ν) lam a m (n+1) (extd (bz0 hK) n h)\n * ENNReal.ofReal (Real.exp\n (lam * (if nextA n h = a ∧ bcnt a (n+1) (extd (bz0 hK) n h) < m\n then y - bmu ν a else 0)\n - lam ^ 2 / 8 *\n (if nextA n h = a ∧ bcnt a (n+1) (extd (bz0 hK) n h) < m\n then (1:ℝ) else 0))) ∂(ν (nextA n h)) := by\n simp only [hg]\n _ = bPhi (bmu ν) lam a m (n+1) (extd (bz0 hK) n h) * ∫⁻ y, ENNReal.ofReal (Real.exp\n (lam * (if nextA n h = a ∧ bcnt a (n+1) (extd (bz0 hK) n h) < m\n then y - bmu ν a else 0)\n - lam ^ 2 / 8 *\n (if nextA n h = a ∧ bcnt a (n+1) (extd (bz0 hK) n h) < m\n then (1:ℝ) else 0))) ∂(ν (nextA n h)) :=\n lintegral_const_mul _ hcm\n _ ≤ bPhi (bmu ν) lam a m (n+1) (extd (bz0 hK) n h) * 1 :=\n mul_le_mul_left' (onestep_le hrew a _ lam _ (fun hh ↦ hh.1)) _\n _ = bPhi (bmu ν) lam a m (n+1) ω := by\n rw [mul_one]\n refine bPhi_congr (bmu ν) lam a m (n+1) fun i hi ↦ ?_\n exact extd_frestrictLe (bz0 hK) n ω (Nat.lt_succ_iff.mp hi)\n _ ≤ 1 := ih\n\nlemma tail_gen (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (lam : ℝ) (a : Fin K) (m N : ℕ) (r : ℝ) :\n (banditP hK ν nextA hmeasA) {ω | r ≤ lam * bW (bmu ν) a m N ω}\n ≤ ENNReal.ofReal (Real.exp (lam ^ 2 * m / 8 - r)) := by\n classical\n set c : ℝ≥0∞ := ENNReal.ofReal (Real.exp (r - lam ^ 2 * m / 8)) with hc\n have hcne : c ≠ 0 := by\n rw [hc]\n simp [Real.exp_pos]\n have hctop : c ≠ ⊤ := by rw [hc]; exact ENNReal.ofReal_ne_top\n have hsub : {ω : ℕ → Fin K × ℝ | r ≤ lam * bW (bmu ν) a m N ω}\n ⊆ {ω | c ≤ bPhi (bmu ν) lam a m N ω} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n rw [hc, bPhi]\n refine ENNReal.ofReal_le_ofReal (Real.exp_le_exp.2 ?_)\n have h1 : lam ^ 2 / 8 * (bD a m N ω : ℝ) ≤ lam ^ 2 / 8 * (m : ℝ) := by\n have : (bD a m N ω : ℝ) ≤ (m : ℝ) := Nat.cast_le.2 bD_le\n nlinarith [sq_nonneg lam]\n linarith\n calc (banditP hK ν nextA hmeasA) {ω | r ≤ lam * bW (bmu ν) a m N ω}\n ≤ (banditP hK ν nextA hmeasA) {ω | c ≤ bPhi (bmu ν) lam a m N ω} := measure_mono hsub\n _ ≤ (∫⁻ ω, bPhi (bmu ν) lam a m N ω ∂(banditP hK ν nextA hmeasA)) / c :=\n meas_ge_le_lintegral_div (measurable_bPhi _ _ _ _ _).aemeasurable hcne hctop\n _ ≤ 1 / c := by\n exact ENNReal.div_le_div_right (bPhi_lintegral_le hrew lam a m N) c\n _ = ENNReal.ofReal (Real.exp (lam ^ 2 * m / 8 - r)) := by\n rw [hc, ENNReal.div_eq_inv_mul, mul_one, ← ENNReal.ofReal_inv_of_pos (Real.exp_pos _),\n ← Real.exp_neg]\n ring_nf\n\nlemma tail_low (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) (m N : ℕ) (hm : 0 < m)\n (ε : ℝ) (hε : 0 ≤ ε) :\n (banditP hK ν nextA hmeasA) {ω | bW (bmu ν) a m N ω ≤ -ε}\n ≤ ENNReal.ofReal (Real.exp (-(2 * ε ^ 2 / m))) := by\n have hmR : (0:ℝ) < m := by exact_mod_cast hm\n have hsub : {ω : ℕ → Fin K × ℝ | bW (bmu ν) a m N ω ≤ -ε}\n ⊆ {ω | 4 * ε ^ 2 / m ≤ (-(4 * ε / m)) * bW (bmu ν) a m N ω} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n have hlam : (0:ℝ) ≤ 4 * ε / m := by positivity\n have hLe : 4 * ε ^ 2 / (m:ℝ) = (4 * ε / m) * ε := by field_simp\n rw [hLe, neg_mul, ← mul_neg]\n exact mul_le_mul_of_nonneg_left (by linarith) hlam\n refine le_trans (measure_mono hsub) ?_\n refine le_trans (tail_gen hrew (-(4 * ε / m)) a m N (4 * ε ^ 2 / m)) ?_\n refine le_of_eq ?_\n congr 1\n field_simp\n ring_nf\n\nlemma tail_high (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) (m N : ℕ) (hm : 0 < m)\n (ε : ℝ) (hε : 0 ≤ ε) :\n (banditP hK ν nextA hmeasA) {ω | ε ≤ bW (bmu ν) a m N ω}\n ≤ ENNReal.ofReal (Real.exp (-(2 * ε ^ 2 / m))) := by\n have hmR : (0:ℝ) < m := by exact_mod_cast hm\n have hsub : {ω : ℕ → Fin K × ℝ | ε ≤ bW (bmu ν) a m N ω}\n ⊆ {ω | 4 * ε ^ 2 / m ≤ (4 * ε / m) * bW (bmu ν) a m N ω} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n have hlam : (0:ℝ) ≤ 4 * ε / m := by positivity\n have hLe : 4 * ε ^ 2 / (m:ℝ) = (4 * ε / m) * ε := by field_simp\n rw [hLe]\n exact mul_le_mul_of_nonneg_left hω hlam\n refine le_trans (measure_mono hsub) ?_\n refine le_trans (tail_gen hrew (4 * ε / m) a m N (4 * ε ^ 2 / m)) ?_\n refine le_of_eq ?_\n congr 1\n field_simp\n ring_nf\n\nlemma ae_action_succ (n : ℕ) :\n ∀ᵐ ω ∂(banditP hK ν nextA hmeasA),\n (ω (n+1)).1 = nextA n (Preorder.frestrictLe n ω) := by\n classical\n set g : ((Iic n → Fin K × ℝ) × (Fin K × ℝ)) → ℝ≥0∞ := fun p ↦\n if p.2.1 = nextA n p.1 then 0 else 1 with hg\n have hgmeas : Measurable g := by\n rw [hg]\n refine Measurable.ite ?_ measurable_const measurable_const\n exact measurableSet_eq_fun (by fun_prop) ((hmeasA n).comp measurable_fst)\n have h0 : ∫⁻ ω, g (Preorder.frestrictLe n ω, ω (n+1)) ∂(banditP hK ν nextA hmeasA) = 0 := by\n rw [keyStep n hgmeas]\n have hz : ∀ ω : ℕ → Fin K × ℝ, (∫⁻ y, g (Preorder.frestrictLe n ω,\n (nextA n (Preorder.frestrictLe n ω), y)) ∂(ν (nextA n (Preorder.frestrictLe n ω)))) = 0 := by\n intro ω; simp [hg]\n simp_rw [hz]\n simp\n rw [ae_iff]\n refine le_antisymm ?_ (zero_le _)\n calc (banditP hK ν nextA hmeasA)\n {ω | ¬ ((ω (n+1)).1 = nextA n (Preorder.frestrictLe n ω))}\n ≤ (banditP hK ν nextA hmeasA)\n {ω | (1:ℝ≥0∞) ≤ g (Preorder.frestrictLe n ω, ω (n+1))} := by\n refine measure_mono fun ω hω ↦ ?_\n simp only [Set.mem_setOf_eq] at hω ⊢\n rw [hg]\n simp only [if_neg hω]\n exact le_rfl\n _ ≤ (∫⁻ ω, g (Preorder.frestrictLe n ω, ω (n+1)) ∂(banditP hK ν nextA hmeasA)) / 1 :=\n meas_ge_le_lintegral_div (hgmeas.comp (by fun_prop)).aemeasurable one_ne_zero ENNReal.one_ne_top\n _ = 0 := by rw [h0]; simp\n\nlemma ae_action_zero :\n ∀ᵐ ω ∂(banditP hK ν nextA hmeasA), (ω 0).1 = (⟨0, hK⟩ : Fin K) := by\n classical\n set g : (Fin K × ℝ) → ℝ≥0∞ := fun z ↦ if z.1 = (⟨0, hK⟩ : Fin K) then 0 else 1 with hg\n have hgmeas : Measurable g := by\n rw [hg]\n refine Measurable.ite ?_ measurable_const measurable_const\n exact (measurableSet_singleton _).preimage (by fun_prop)\n have h0 : ∫⁻ ω, g (ω 0) ∂(banditP hK ν nextA hmeasA) = 0 := by\n rw [keyStep0 hgmeas]\n simp [hg]\n rw [ae_iff]\n refine le_antisymm ?_ (zero_le _)\n calc (banditP hK ν nextA hmeasA) {ω | ¬ ((ω 0).1 = (⟨0, hK⟩ : Fin K))}\n ≤ (banditP hK ν nextA hmeasA) {ω | (1:ℝ≥0∞) ≤ g (ω 0)} := by\n refine measure_mono fun ω hω ↦ ?_\n simp only [Set.mem_setOf_eq] at hω ⊢\n rw [hg]\n simp only [if_neg hω]\n exact le_rfl\n _ ≤ (∫⁻ ω, g (ω 0) ∂(banditP hK ν nextA hmeasA)) / 1 :=\n meas_ge_le_lintegral_div (hgmeas.comp (by fun_prop)).aemeasurable one_ne_zero ENNReal.one_ne_top\n _ = 0 := by rw [h0]; simp\n\n/-- The trajectory follows the (deterministic) algorithm. -/\ndef followsAlg {K : ℕ} (hK : 0 < K) (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K)\n (ω : ℕ → Fin K × ℝ) : Prop :=\n (ω 0).1 = (⟨0, hK⟩ : Fin K) ∧ ∀ n, (ω (n+1)).1 = nextA n (Preorder.frestrictLe n ω)\n\nlemma ae_followsAlg :\n ∀ᵐ ω ∂(banditP hK ν nextA hmeasA), followsAlg hK nextA ω := by\n have h1 := ae_action_zero (hK := hK) (ν := ν) (nextA := nextA) (hmeasA := hmeasA)\n have h2 : ∀ᵐ ω ∂(banditP hK ν nextA hmeasA), ∀ n,\n (ω (n+1)).1 = nextA n (Preorder.frestrictLe n ω) :=\n (ae_all_iff).2 (fun n ↦ ae_action_succ n)\n filter_upwards [h1, h2] with ω ha hb using ⟨ha, hb⟩\n\nend Bandit\n\nsection Widths\n\nvariable {δ : ℝ} {K m : ℕ}\n\n/-- Upper confidence width used by the algorithm. -/\nnoncomputable def cUp (δ : ℝ) (m : ℕ) : ℝ :=\n Real.sqrt (Real.log (2 * ((m:ℝ) + 1) ^ 2 / δ) / (2 * m))\n\n/-- Lower confidence width. -/\nnoncomputable def cLow (δ : ℝ) (K : ℕ) (m : ℕ) : ℝ :=\n Real.sqrt (Real.log (2 * K * ((m:ℝ) + 1) ^ 2 / δ) / (2 * m))\n\nlemma one_le_argUp (hδ0 : 0 < δ) (hδ1 : δ < 1) (m : ℕ) :\n (1:ℝ) ≤ 2 * ((m:ℝ) + 1) ^ 2 / δ := by\n rw [le_div_iff₀ hδ0]\n have : (0:ℝ) ≤ (m:ℝ) := Nat.cast_nonneg m\n nlinarith\n\nlemma one_le_argLow (hδ0 : 0 < δ) (hδ1 : δ < 1) (hK : 0 < K) (m : ℕ) :\n (1:ℝ) ≤ 2 * K * ((m:ℝ) + 1) ^ 2 / δ := by\n rw [le_div_iff₀ hδ0]\n have h1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have : (0:ℝ) ≤ (m:ℝ) := Nat.cast_nonneg m\n nlinarith\n\nlemma logUp_nonneg (hδ0 : 0 < δ) (hδ1 : δ < 1) (m : ℕ) :\n 0 ≤ Real.log (2 * ((m:ℝ) + 1) ^ 2 / δ) :=\n Real.log_nonneg (one_le_argUp hδ0 hδ1 m)\n\nlemma logLow_nonneg (hδ0 : 0 < δ) (hδ1 : δ < 1) (hK : 0 < K) (m : ℕ) :\n 0 ≤ Real.log (2 * K * ((m:ℝ) + 1) ^ 2 / δ) :=\n Real.log_nonneg (one_le_argLow hδ0 hδ1 hK m)\n\nlemma cUp_nonneg : 0 ≤ cUp δ m := Real.sqrt_nonneg _\nlemma cLow_nonneg : 0 ≤ cLow δ K m := Real.sqrt_nonneg _\n\nlemma cUp_sq (hδ0 : 0 < δ) (hδ1 : δ < 1) (hm : 1 ≤ m) :\n (cUp δ m) ^ 2 = Real.log (2 * ((m:ℝ) + 1) ^ 2 / δ) / (2 * m) := by\n rw [cUp, Real.sq_sqrt]\n have hm' : (0:ℝ) < m := by exact_mod_cast hm\n have := logUp_nonneg hδ0 hδ1 m\n positivity\n\nlemma cLow_sq (hδ0 : 0 < δ) (hδ1 : δ < 1) (hK : 0 < K) (hm : 1 ≤ m) :\n (cLow δ K m) ^ 2 = Real.log (2 * K * ((m:ℝ) + 1) ^ 2 / δ) / (2 * m) := by\n rw [cLow, Real.sq_sqrt]\n have hm' : (0:ℝ) < m := by exact_mod_cast hm\n have := logLow_nonneg hδ0 hδ1 hK m\n positivity\n\nlemma cUp_le_cLow (hδ0 : 0 < δ) (hδ1 : δ < 1) (hK : 0 < K) (m : ℕ) :\n cUp δ m ≤ cLow δ K m := by\n refine Real.sqrt_le_sqrt ?_\n rcases Nat.eq_zero_or_pos m with hm | hm\n · subst hm; simp\n have hm' : (0:ℝ) < m := by exact_mod_cast hm\n have h1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have harg : 2 * ((m:ℝ) + 1) ^ 2 / δ ≤ 2 * K * ((m:ℝ) + 1) ^ 2 / δ := by\n rw [div_le_div_iff_of_pos_right hδ0]\n nlinarith [sq_nonneg ((m:ℝ) + 1)]\n have hlog : Real.log (2 * ((m:ℝ) + 1) ^ 2 / δ) ≤ Real.log (2 * K * ((m:ℝ) + 1) ^ 2 / δ) := by\n refine Real.log_le_log ?_ harg\n have : (0:ℝ) ≤ (m:ℝ) := Nat.cast_nonneg m\n positivity\n gcongr\n\nend Widths\n\nsection Failure\n\nlemma sum_inv_sq_le' (T : ℕ) :\n ∑ m ∈ Finset.Icc 1 T, (1:ℝ) / ((m:ℝ) + 1) ^ 2 ≤ 1 - 1 / ((T:ℝ) + 1) := by\n induction T with\n | zero => simp\n | succ T ih =>\n rw [Finset.sum_Icc_succ_top (by lia)]\n push_cast\n have hT : (0:ℝ) < (T:ℝ) + 1 := by positivity\n have hstep : (1:ℝ) / ((T:ℝ) + 1 + 1) ^ 2 ≤ 1 / ((T:ℝ) + 1) - 1 / ((T:ℝ) + 1 + 1) := by\n have h1 : (1:ℝ) / ((T:ℝ) + 1) - 1 / ((T:ℝ) + 1 + 1)\n = 1 / (((T:ℝ) + 1) * ((T:ℝ) + 1 + 1)) := by\n field_simp\n ring\n rw [h1]\n refine one_div_le_one_div_of_le (by positivity) ?_\n nlinarith\n linarith [ih, hstep]\n\nlemma sum_inv_sq_le (T : ℕ) : ∑ m ∈ Finset.Icc 1 T, (1:ℝ) / ((m:ℝ) + 1) ^ 2 ≤ 1 := by\n refine le_trans (sum_inv_sq_le' T) ?_\n have : (0:ℝ) < (T:ℝ) + 1 := by positivity\n have : (0:ℝ) ≤ 1 / ((T:ℝ) + 1) := by positivity\n linarith\n\nend Failure\n\nsection FailureProb\n\nvariable {K : ℕ} {hK : 0 < K} {ν : Kernel (Fin K) ℝ} [IsMarkovKernel ν]\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K} {hmeasA : ∀ n, Measurable (nextA n)}\n {δ : ℝ}\n\nlemma prob_fail_up (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (a : Fin K) (m N : ℕ) (hm : 1 ≤ m) :\n (banditP hK ν nextA hmeasA) {ω | bW (bmu ν) a m N ω < -((m:ℝ) * cUp δ m)}\n ≤ ENNReal.ofReal (δ / (2 * ((m:ℝ) + 1) ^ 2)) := by\n have hm' : (0:ℝ) < m := by exact_mod_cast hm\n have hsub : {ω : ℕ → Fin K × ℝ | bW (bmu ν) a m N ω < -((m:ℝ) * cUp δ m)}\n ⊆ {ω | bW (bmu ν) a m N ω ≤ -((m:ℝ) * cUp δ m)} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n exact le_of_lt hω\n refine le_trans (measure_mono hsub) ?_\n refine le_trans (tail_low hrew a m N hm ((m:ℝ) * cUp δ m)\n (mul_nonneg hm'.le cUp_nonneg)) ?_\n refine le_of_eq ?_\n congr 1\n have hkey : 2 * ((m:ℝ) * cUp δ m) ^ 2 / (m:ℝ) = Real.log (2 * ((m:ℝ) + 1) ^ 2 / δ) := by\n have h1 : ((m:ℝ) * cUp δ m) ^ 2 = (m:ℝ) ^ 2 * (cUp δ m) ^ 2 := by ring\n rw [h1, cUp_sq hδ0 hδ1 hm]\n field_simp\n rw [hkey, Real.exp_neg, Real.exp_log (by positivity), inv_div]\n\nlemma prob_fail_low (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hK' : 0 < K) (a : Fin K) (m N : ℕ) (hm : 1 ≤ m) :\n (banditP hK ν nextA hmeasA) {ω | (m:ℝ) * cLow δ K m < bW (bmu ν) a m N ω}\n ≤ ENNReal.ofReal (δ / (2 * K * ((m:ℝ) + 1) ^ 2)) := by\n have hm' : (0:ℝ) < m := by exact_mod_cast hm\n have hKR : (0:ℝ) < K := by exact_mod_cast hK'\n have hsub : {ω : ℕ → Fin K × ℝ | (m:ℝ) * cLow δ K m < bW (bmu ν) a m N ω}\n ⊆ {ω | (m:ℝ) * cLow δ K m ≤ bW (bmu ν) a m N ω} := by\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n exact le_of_lt hω\n refine le_trans (measure_mono hsub) ?_\n refine le_trans (tail_high hrew a m N hm ((m:ℝ) * cLow δ K m)\n (mul_nonneg hm'.le cLow_nonneg)) ?_\n refine le_of_eq ?_\n congr 1\n have hkey : 2 * ((m:ℝ) * cLow δ K m) ^ 2 / (m:ℝ)\n = Real.log (2 * K * ((m:ℝ) + 1) ^ 2 / δ) := by\n have h1 : ((m:ℝ) * cLow δ K m) ^ 2 = (m:ℝ) ^ 2 * (cLow δ K m) ^ 2 := by ring\n rw [h1, cLow_sq hδ0 hδ1 hK' hm]\n field_simp\n rw [hkey, Real.exp_neg, Real.exp_log (by positivity), inv_div]\n\nlemma prob_failUp_union (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (a : Fin K) (T : ℕ) :\n (banditP hK ν nextA hmeasA)\n (⋃ m ∈ Finset.Icc 1 T, {ω | bW (bmu ν) a m T ω < -((m:ℝ) * cUp δ m)})\n ≤ ENNReal.ofReal (δ / 2) := by\n refine le_trans (measure_biUnion_finset_le _ _) ?_\n refine le_trans (Finset.sum_le_sum (fun m hm ↦\n prob_fail_up hrew hδ0 hδ1 a m T (Finset.mem_Icc.mp hm).1)) ?_\n rw [← ENNReal.ofReal_sum_of_nonneg (fun m _ ↦ by positivity)]\n refine ENNReal.ofReal_le_ofReal ?_\n have hcg : ∀ m ∈ Finset.Icc 1 T,\n δ / (2 * ((m:ℝ) + 1) ^ 2) = (δ / 2) * (1 / ((m:ℝ) + 1) ^ 2) := by\n intro m _\n have : ((m:ℝ) + 1) ≠ 0 := by positivity\n field_simp\n rw [Finset.sum_congr rfl hcg, ← Finset.mul_sum]\n have h2 := sum_inv_sq_le T\n have h3 : (0:ℝ) ≤ δ / 2 := by linarith\n nlinarith\n\nlemma prob_failLow_union_arm (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hK' : 0 < K) (a : Fin K) (T : ℕ) :\n (banditP hK ν nextA hmeasA)\n (⋃ m ∈ Finset.Icc 1 T, {ω | (m:ℝ) * cLow δ K m < bW (bmu ν) a m T ω})\n ≤ ENNReal.ofReal (δ / (2 * K)) := by\n have hKR : (0:ℝ) < K := by exact_mod_cast hK'\n refine le_trans (measure_biUnion_finset_le _ _) ?_\n refine le_trans (Finset.sum_le_sum (fun m hm ↦\n prob_fail_low hrew hδ0 hδ1 hK' a m T (Finset.mem_Icc.mp hm).1)) ?_\n rw [← ENNReal.ofReal_sum_of_nonneg (fun m _ ↦ by positivity)]\n refine ENNReal.ofReal_le_ofReal ?_\n have hcg : ∀ m ∈ Finset.Icc 1 T,\n δ / (2 * K * ((m:ℝ) + 1) ^ 2) = (δ / (2 * K)) * (1 / ((m:ℝ) + 1) ^ 2) := by\n intro m _\n have h0 : ((m:ℝ) + 1) ≠ 0 := by positivity\n have h1 : (K:ℝ) ≠ 0 := ne_of_gt hKR\n field_simp\n rw [Finset.sum_congr rfl hcg, ← Finset.mul_sum]\n have h2 := sum_inv_sq_le T\n have h3 : (0:ℝ) ≤ δ / (2 * K) := by positivity\n nlinarith\n\nlemma prob_failLow_union (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hK' : 0 < K) (T : ℕ) :\n (banditP hK ν nextA hmeasA)\n (⋃ a : Fin K, ⋃ m ∈ Finset.Icc 1 T, {ω | (m:ℝ) * cLow δ K m < bW (bmu ν) a m T ω})\n ≤ ENNReal.ofReal (δ / 2) := by\n have hKR : (0:ℝ) < K := by exact_mod_cast hK'\n set S : Fin K → Set (ℕ → Fin K × ℝ) := fun a ↦\n ⋃ m ∈ Finset.Icc 1 T, {ω | (m:ℝ) * cLow δ K m < bW (bmu ν) a m T ω} with hS\n have hun : (⋃ a : Fin K, S a) = ⋃ a ∈ (Finset.univ : Finset (Fin K)), S a := by\n ext ω; simp\n show (banditP hK ν nextA hmeasA) (⋃ a : Fin K, S a) ≤ _\n rw [hun]\n refine le_trans (measure_biUnion_finset_le _ _) ?_\n refine le_trans (Finset.sum_le_sum (fun a _ ↦\n prob_failLow_union_arm hrew hδ0 hδ1 hK' a T)) ?_\n rw [← ENNReal.ofReal_sum_of_nonneg (fun a _ ↦ by positivity)]\n refine ENNReal.ofReal_le_ofReal ?_\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n have h1 : (K:ℝ) ≠ 0 := ne_of_gt hKR\n have hEq : (K:ℝ) * (δ / (2 * K)) = δ / 2 := by field_simp\n exact le_of_eq hEq\n\nend FailureProb\n\nsection Translate\n\nvariable {K : ℕ}\n\nlemma Iic_eq_range (n : ℕ) : Finset.Iic n = Finset.range (n + 1) := by\n ext x; simp [Nat.lt_succ_iff]\n\nlemma pullCount'_eq (n : ℕ) (ω : ℕ → Fin K × ℝ) (a : Fin K) :\n pullCount' n (Preorder.frestrictLe n ω) a = bcnt a (n + 1) ω := by\n rw [pullCount'_eq_sum, bcnt, ← Iic_eq_range,\n ← Finset.sum_coe_sort (Finset.Iic n) (fun s ↦ if (ω s).1 = a then 1 else 0)]\n rfl\n\nlemma sumRewards'_eq (n : ℕ) (ω : ℕ → Fin K × ℝ) (a : Fin K) :\n sumRewards' n (Preorder.frestrictLe n ω) a = bsumR a (n + 1) ω := by\n rw [sumRewards', bsumR, ← Iic_eq_range,\n ← Finset.sum_coe_sort (Finset.Iic n) (fun s ↦ if (ω s).1 = a then (ω s).2 else 0)]\n rfl\n\nlemma empMean'_eq (n : ℕ) (ω : ℕ → Fin K × ℝ) (a : Fin K) :\n empMean' n (Preorder.frestrictLe n ω) a\n = bsumR a (n + 1) ω / (bcnt a (n + 1) ω : ℝ) := by\n rw [empMean', sumRewards'_eq, pullCount'_eq]\n\nlemma ucbWidthNL_eq (δ : ℝ) (n : ℕ) (ω : ℕ → Fin K × ℝ) (a : Fin K) :\n ucbWidthNL δ n (Preorder.frestrictLe n ω) a = cUp δ (bcnt a (n + 1) ω) := by\n rw [ucbWidthNL, cUp, pullCount'_eq]\n\nend Translate\n\nsection Argmax\n\nvariable {K : ℕ}\n\nlemma exists_argmax (hK : 0 < K) (mu : Fin K → ℝ) : ∃ astar : Fin K, ∀ a, mu a ≤ mu astar := by\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n obtain ⟨astar, h⟩ := Finite.exists_max mu\n exact ⟨astar, h⟩\n\nlemma iSup_eq_max (hK : 0 < K) {mu : Fin K → ℝ} {astar : Fin K} (h : ∀ a, mu a ≤ mu astar) :\n (⨆ a, mu a) = mu astar := by\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n exact le_antisymm (ciSup_le h) (le_ciSup (Finite.bddAbove_range mu) astar)\n\nend Argmax\n\nsection MeanBounds\n\nvariable {K : ℕ} {ν : Kernel (Fin K) ℝ} [IsMarkovKernel ν]\n\nlemma integrable_id_nu (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) :\n Integrable (fun y : ℝ ↦ y) (ν a) :=\n Integrable.of_mem_Icc 0 1 aemeasurable_id (ae_mem_Icc hrew a)\n\nlemma bmu_nonneg (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) : 0 ≤ bmu ν a :=\n integral_nonneg_of_ae ((ae_mem_Icc hrew a).mono (fun y hy ↦ hy.1))\n\nlemma bmu_le_one (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1) (a : Fin K) : bmu ν a ≤ 1 := by\n have h := integral_mono_ae (integrable_id_nu hrew a) (integrable_const (1:ℝ))\n ((ae_mem_Icc hrew a).mono (fun y hy ↦ hy.2))\n simpa [bmu] using h\n\nend MeanBounds\n\nsection Warmup\n\nvariable {K : ℕ}\n\nlemma warm_action (hK : 0 < K) {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K}\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n {ω : ℕ → Fin K × ℝ} (hf : followsAlg hK nextA ω) :\n ∀ s, s < K → ((ω s).1 : ℕ) = s := by\n intro s\n induction s with\n | zero => intro _; rw [hf.1]\n | succ n _ =>\n intro hs\n have hn : n < K - 1 := by lia\n rw [hf.2 n, hwarm n _ hn, RoundRobin.nextAction]\n exact Nat.mod_eq_of_lt hs\n\nlemma bcnt_warm {ω : ℕ → Fin K × ℝ} (h : ∀ s, s < K → ((ω s).1 : ℕ) = s) (a : Fin K) :\n bcnt a K ω = 1 := by\n classical\n rw [bcnt]\n have hc : ∀ s ∈ range K, (if (ω s).1 = a then 1 else 0) = (if s = (a:ℕ) then 1 else 0) := by\n intro s hs\n have hs' := Finset.mem_range.mp hs\n by_cases h1 : (ω s).1 = a\n · have h2 : s = (a:ℕ) := by rw [← h s hs', h1]\n rw [if_pos h1, if_pos h2]\n · have h2 : ¬ (s = (a:ℕ)) := by\n intro h2\n exact h1 (Fin.val_injective (by rw [h s hs', h2]))\n rw [if_neg h1, if_neg h2]\n rw [Finset.sum_congr rfl hc, Finset.sum_ite_eq' (range K) (a:ℕ) (fun _ ↦ 1)]\n simp [a.isLt]\n\nlemma sum_range_K_eq {ω : ℕ → Fin K × ℝ} (h : ∀ s, s < K → ((ω s).1 : ℕ) = s) (f : Fin K → ℝ) :\n ∑ s ∈ range K, f ((ω s).1) = ∑ a : Fin K, f a := by\n classical\n set g : ℕ → ℝ := fun s ↦ if hs : s < K then f ⟨s, hs⟩ else 0 with hg\n have h1 : ∑ i : Fin K, g (i : ℕ) = ∑ a : Fin K, f a := by\n refine Finset.sum_congr rfl fun i _ ↦ ?_\n rw [hg]\n simp\n have h2 : ∑ s ∈ range K, g s = ∑ s ∈ range K, f ((ω s).1) := by\n refine Finset.sum_congr rfl fun s hs ↦ ?_\n have hs' := Finset.mem_range.mp hs\n rw [hg]\n simp only [dif_pos hs']\n congr 1\n exact Fin.val_injective (h s hs').symm\n rw [← h2, ← Fin.sum_univ_eq_sum_range g K, h1]\n\nlemma sum_gap_le (hK : 0 < K) {mu : Fin K → ℝ} {astar : Fin K}\n (hmax : ∀ a, mu a ≤ mu astar) (hb : ∀ a, 0 ≤ mu a ∧ mu a ≤ 1) :\n ∑ a : Fin K, (mu astar - mu a) ≤ (K:ℝ) - 1 := by\n classical\n have hsplit : ∑ a : Fin K, (mu astar - mu a)\n = ∑ a ∈ Finset.univ.erase astar, (mu astar - mu a) := by\n rw [Finset.sum_erase]\n simp\n rw [hsplit]\n calc ∑ a ∈ Finset.univ.erase astar, (mu astar - mu a)\n ≤ ∑ _a ∈ Finset.univ.erase astar, (1:ℝ) := by\n refine Finset.sum_le_sum fun a _ ↦ ?_\n have h1 := (hb astar).2\n have h2 := (hb a).1\n linarith\n _ = (((Finset.univ.erase astar).card : ℕ) : ℝ) := by simp\n _ = (K:ℝ) - 1 := by\n rw [Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, Fintype.card_fin,\n Nat.cast_sub hK]\n norm_num\n\nend Warmup\n\nsection RoundBound\n\nvariable {K T : ℕ} {δ : ℝ}\n\n/-- Upper confidence bounds hold for the optimal arm. -/\ndef goodUp (δ : ℝ) (T : ℕ) {K : ℕ} (mu : Fin K → ℝ) (astar : Fin K) (ω : ℕ → Fin K × ℝ) : Prop :=\n ∀ m, 1 ≤ m → m ≤ T → -((m:ℝ) * cUp δ m) ≤ bW mu astar m T ω\n\n/-- Lower confidence bounds hold for every arm. -/\ndef goodLow (δ : ℝ) (K T : ℕ) (mu : Fin K → ℝ) (ω : ℕ → Fin K × ℝ) : Prop :=\n ∀ (a : Fin K) (m : ℕ), 1 ≤ m → m ≤ T → bW mu a m T ω ≤ (m:ℝ) * cLow δ K m\n\nlemma round_bound (hK : 0 < K) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K}\n {mu : Fin K → ℝ} {astar : Fin K} {ω : ℕ → Fin K × ℝ}\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + ucbWidthNL δ n h a ≤\n empMean' n h (nextA n h) + ucbWidthNL δ n h (nextA n h))\n (hf : followsAlg hK nextA ω)\n (hwarmact : ∀ s, s < K → ((ω s).1 : ℕ) = s)\n (hgu : goodUp δ T mu astar ω) (hgl : goodLow δ K T mu ω)\n (s : ℕ) (hs1 : K ≤ s) (hs2 : s < T) :\n mu astar - mu ((ω s).1) ≤ 2 * cLow δ K (bcnt ((ω s).1) s ω) := by\n obtain ⟨n, rfl⟩ : ∃ n, s = n + 1 := ⟨s - 1, by lia⟩\n set b := (ω (n+1)).1 with hbdef\n set p := bcnt astar (n+1) ω with hpdef\n set q := bcnt b (n+1) ω with hqdef\n -- counts are in `[1, T]`\n have hcntK : ∀ a : Fin K, 1 ≤ bcnt a (n+1) ω := by\n intro a\n have h1 : bcnt a K ω = 1 := bcnt_warm hwarmact a\n have := bcnt_mono (a := a) (ω := ω) hs1\n lia\n have hp1 : 1 ≤ p := hcntK astar\n have hq1 : 1 ≤ q := hcntK b\n have hpT : p ≤ T := le_trans bcnt_le_self (by lia)\n have hqT : q ≤ T := le_trans bcnt_le_self (by lia)\n have hpR : (0:ℝ) < (p:ℝ) := by exact_mod_cast hp1\n have hqR : (0:ℝ) < (q:ℝ) := by exact_mod_cast hq1\n -- the empirical means\n set A := bsumR astar (n+1) ω / (p:ℝ) with hAdef\n set B := bsumR b (n+1) ω / (q:ℝ) with hBdef\n have hAp : bsumR astar (n+1) ω = A * (p:ℝ) := by\n rw [hAdef]; field_simp\n have hBq : bsumR b (n+1) ω = B * (q:ℝ) := by\n rw [hBdef]; field_simp\n -- upper confidence bound for `astar`\n have hupper : -((p:ℝ) * cUp δ p) ≤ bsumR astar (n+1) ω - (p:ℝ) * mu astar := by\n have h1 := hgu p hp1 hpT\n rwa [bW_stable (a := astar) (mu := mu) (m := p) (n := n+1) rfl (by lia),\n bW_eq_of_cnt (a := astar) (mu := mu) (m := p) (n := n+1) rfl] at h1\n have hA : mu astar ≤ A + cUp δ p := by nlinarith [hupper, hAp]\n -- lower confidence bound for the chosen arm\n have hlower : bsumR b (n+1) ω - (q:ℝ) * mu b ≤ (q:ℝ) * cLow δ K q := by\n have h1 := hgl b q hq1 hqT\n rwa [bW_stable (a := b) (mu := mu) (m := q) (n := n+1) rfl (by lia),\n bW_eq_of_cnt (a := b) (mu := mu) (m := q) (n := n+1) rfl] at h1\n have hB : B ≤ mu b + cLow δ K q := by nlinarith [hlower, hBq]\n -- the algorithm maximises the index\n have hbeq : b = nextA n (Preorder.frestrictLe n ω) := hf.2 n\n have hidx : A + cUp δ p ≤ B + cUp δ q := by\n have h1 := hargmax n (Preorder.frestrictLe n ω) astar (by lia)\n rw [empMean'_eq, ucbWidthNL_eq, empMean'_eq, ucbWidthNL_eq, ← hbeq] at h1\n exact h1\n have hcup : cUp δ q ≤ cLow δ K q := cUp_le_cLow hδ0 hδ1 hK q\n linarith\n\nend RoundBound\n\nsection Summation\n\nvariable {K T : ℕ} {δ : ℝ}\n\nlemma sum_inv_sqrt_le (M : ℕ) :\n ∑ m ∈ Finset.Icc 1 M, 1 / Real.sqrt m ≤ 2 * Real.sqrt M := by\n induction M with\n | zero => simp\n | succ M ih =>\n rw [Finset.sum_Icc_succ_top (by lia)]\n have hu0 : (0:ℝ) ≤ Real.sqrt M := Real.sqrt_nonneg _\n have hv0 : (0:ℝ) < Real.sqrt ((M:ℝ) + 1) := Real.sqrt_pos.mpr (by positivity)\n have hu2 : (Real.sqrt M) ^ 2 = (M:ℝ) := Real.sq_sqrt (Nat.cast_nonneg M)\n have hv2 : (Real.sqrt ((M:ℝ) + 1)) ^ 2 = (M:ℝ) + 1 := Real.sq_sqrt (by positivity)\n have hcast : (((M + 1 : ℕ)) : ℝ) = (M:ℝ) + 1 := by push_cast; ring\n rw [hcast]\n have hstep : 1 / Real.sqrt ((M:ℝ) + 1)\n ≤ 2 * Real.sqrt ((M:ℝ) + 1) - 2 * Real.sqrt M := by\n rw [div_le_iff₀ hv0]\n nlinarith [sq_nonneg (Real.sqrt ((M:ℝ) + 1) - Real.sqrt M)]\n linarith [ih, hstep]\n\nlemma sum_bcnt (n : ℕ) (ω : ℕ → Fin K × ℝ) : ∑ a : Fin K, bcnt a n ω = n := by\n classical\n have h1 : (∑ a : Fin K, bcnt a n ω)\n = ∑ a : Fin K, ∑ s ∈ range n, (if (ω s).1 = a then 1 else 0) := rfl\n rw [h1, Finset.sum_comm]\n have h2 : ∀ s ∈ range n, ∑ a : Fin K, (if (ω s).1 = a then 1 else 0) = 1 := by\n intro s _\n rw [Finset.sum_ite_eq Finset.univ ((ω s).1) (fun _ ↦ 1)]\n simp\n rw [Finset.sum_congr rfl h2]\n simp\n\nlemma cLow_le_bound (hδ0 : 0 < δ) (hδ1 : δ < 1) (hK : 0 < K) {m : ℕ} (hm : 1 ≤ m)\n (hmT : m + 1 ≤ T) :\n cLow δ K m ≤ Real.sqrt (Real.log (2 * K * (T:ℝ) ^ 2 / δ) / 2) * (1 / Real.sqrt m) := by\n have hmR : (0:ℝ) < m := by exact_mod_cast hm\n have hKR : (0:ℝ) < K := by exact_mod_cast hK\n have hmono : Real.log (2 * K * ((m:ℝ) + 1) ^ 2 / δ) ≤ Real.log (2 * K * (T:ℝ) ^ 2 / δ) := by\n refine Real.log_le_log (by positivity) ?_\n have h1 : (m:ℝ) + 1 ≤ (T:ℝ) := by exact_mod_cast hmT\n have h2 : (0:ℝ) ≤ (m:ℝ) + 1 := by positivity\n have h3 : ((m:ℝ) + 1) ^ 2 ≤ (T:ℝ) ^ 2 := by nlinarith\n rw [div_le_div_iff_of_pos_right hδ0]\n nlinarith\n have hLnn : 0 ≤ Real.log (2 * K * (T:ℝ) ^ 2 / δ) :=\n le_trans (logLow_nonneg hδ0 hδ1 hK m) hmono\n have hrw : Real.sqrt (Real.log (2 * K * (T:ℝ) ^ 2 / δ) / (2 * m))\n = Real.sqrt (Real.log (2 * K * (T:ℝ) ^ 2 / δ) / 2) * (1 / Real.sqrt m) := by\n rw [show Real.log (2 * K * (T:ℝ) ^ 2 / δ) / (2 * (m:ℝ))\n = (Real.log (2 * K * (T:ℝ) ^ 2 / δ) / 2) * (1 / (m:ℝ)) by field_simp]\n rw [Real.sqrt_mul (by positivity), one_div, Real.sqrt_inv, one_div]\n rw [cLow, ← hrw]\n refine Real.sqrt_le_sqrt ?_\n gcongr\n\nlemma sum_fiber_le (hδ0 : 0 < δ) (hδ1 : δ < 1) (hK : 0 < K) {ω : ℕ → Fin K × ℝ}\n (hwarmact : ∀ s, s < K → ((ω s).1 : ℕ) = s) (a : Fin K) :\n ∑ s ∈ (Finset.Ico K T).filter (fun s ↦ (ω s).1 = a), cLow δ K (bcnt a s ω)\n ≤ ∑ m ∈ Finset.Icc 1 (bcnt a T ω - 1), cLow δ K m := by\n classical\n have hinj : Set.InjOn (fun s ↦ bcnt a s ω)\n ↑((Finset.Ico K T).filter (fun s ↦ (ω s).1 = a)) := by\n intro x hx y hy hxy\n simp only [Finset.coe_filter, Set.mem_setOf_eq] at hx hy\n simp only at hxy\n simp only [Finset.mem_Ico] at hx hy\n by_contra hne\n rcases lt_or_gt_of_ne hne with hlt | hlt\n · have := bcnt_lt_of_pull hlt hx.2; lia\n · have := bcnt_lt_of_pull hlt hy.2; lia\n have hmaps : ((Finset.Ico K T).filter (fun s ↦ (ω s).1 = a)).image (fun s ↦ bcnt a s ω)\n ⊆ Finset.Icc 1 (bcnt a T ω - 1) := by\n intro m hm\n simp only [Finset.mem_image] at hm\n obtain ⟨s, hs, rfl⟩ := hm\n simp only [Finset.mem_filter, Finset.mem_Ico] at hs\n refine Finset.mem_Icc.mpr ⟨?_, ?_⟩\n · have h1 : bcnt a K ω = 1 := bcnt_warm hwarmact a\n have h2 := bcnt_mono (a := a) (ω := ω) hs.1.1\n lia\n · have h2 : bcnt a (s+1) ω = bcnt a s ω + 1 := by rw [bcnt_succ, if_pos hs.2]\n have h3 : bcnt a (s+1) ω ≤ bcnt a T ω := bcnt_mono (by lia)\n lia\n calc ∑ s ∈ (Finset.Ico K T).filter (fun s ↦ (ω s).1 = a), cLow δ K (bcnt a s ω)\n = ∑ m ∈ ((Finset.Ico K T).filter (fun s ↦ (ω s).1 = a)).image (fun s ↦ bcnt a s ω),\n cLow δ K m := (Finset.sum_image hinj).symm\n _ ≤ ∑ m ∈ Finset.Icc 1 (bcnt a T ω - 1), cLow δ K m :=\n Finset.sum_le_sum_of_subset_of_nonneg hmaps (fun _ _ _ ↦ cLow_nonneg)\n\nlemma sum_sqrt_counts_le (hK : 0 < K) (hKT : K ≤ T) {ω : ℕ → Fin K × ℝ}\n (hwarmact : ∀ s, s < K → ((ω s).1 : ℕ) = s) :\n ∑ a : Fin K, Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ)) ≤ Real.sqrt ((K:ℝ) * ((T:ℝ) - K)) := by\n classical\n have hNa : ∀ a : Fin K, 1 ≤ bcnt a T ω := by\n intro a\n have h1 : bcnt a K ω = 1 := bcnt_warm hwarmact a\n have h2 := bcnt_mono (a := a) (ω := ω) hKT\n lia\n have hsum' : ∑ a : Fin K, (((bcnt a T ω - 1 : ℕ) : ℝ)) = (T:ℝ) - K := by\n have h1 : ∀ a : Fin K, (((bcnt a T ω - 1 : ℕ) : ℝ)) = ((bcnt a T ω : ℝ)) - 1 := by\n intro a\n have := hNa a\n push_cast [Nat.cast_sub this]\n ring\n rw [Finset.sum_congr rfl (fun a _ ↦ h1 a), Finset.sum_sub_distrib]\n have h2 : ∑ a : Fin K, ((bcnt a T ω : ℝ)) = (T:ℝ) := by\n rw [← Nat.cast_sum, sum_bcnt]\n rw [h2]\n simp\n have hnn : (0:ℝ) ≤ ∑ a : Fin K, Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ)) :=\n Finset.sum_nonneg fun a _ ↦ Real.sqrt_nonneg _\n have hsq : (∑ a : Fin K, Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ))) ^ 2\n ≤ (K:ℝ) * ((T:ℝ) - K) := by\n have h1 := sq_sum_le_card_mul_sum_sq (s := (Finset.univ : Finset (Fin K)))\n (f := fun a ↦ Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ)))\n have h2 : ∀ a : Fin K, (Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ))) ^ 2\n = (((bcnt a T ω - 1 : ℕ) : ℝ)) := fun a ↦ Real.sq_sqrt (Nat.cast_nonneg _)\n rw [Finset.sum_congr rfl (fun a _ ↦ h2 a), hsum', Finset.card_univ, Fintype.card_fin] at h1\n exact h1\n calc ∑ a : Fin K, Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ))\n = Real.sqrt ((∑ a : Fin K, Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ))) ^ 2) :=\n (Real.sqrt_sq hnn).symm\n _ ≤ Real.sqrt ((K:ℝ) * ((T:ℝ) - K)) := Real.sqrt_le_sqrt hsq\n\nlemma sum_widths_bound (hδ0 : 0 < δ) (hδ1 : δ < 1) (hK : 0 < K) (hKT : K ≤ T)\n {ω : ℕ → Fin K × ℝ} (hwarmact : ∀ s, s < K → ((ω s).1 : ℕ) = s) :\n ∑ s ∈ Finset.Ico K T, cLow δ K (bcnt ((ω s).1) s ω)\n ≤ Real.sqrt (Real.log (2 * K * (T:ℝ) ^ 2 / δ) / 2)\n * (2 * Real.sqrt ((K:ℝ) * ((T:ℝ) - K))) := by\n classical\n set L := Real.log (2 * K * (T:ℝ) ^ 2 / δ) with hL\n have hKR : (0:ℝ) < K := by exact_mod_cast hK\n have hLnn : 0 ≤ L := by\n rw [hL]\n refine Real.log_nonneg ?_\n rw [le_div_iff₀ hδ0]\n have h1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have h2 : (1:ℝ) ≤ (T:ℝ) := by\n have : 1 ≤ T := by lia\n exact_mod_cast this\n nlinarith\n set C := Real.sqrt (L / 2) with hC\n have hCnn : 0 ≤ C := Real.sqrt_nonneg _\n have hNa : ∀ a : Fin K, 1 ≤ bcnt a T ω := by\n intro a\n have h1 : bcnt a K ω = 1 := bcnt_warm hwarmact a\n have h2 := bcnt_mono (a := a) (ω := ω) hKT\n lia\n have hNaT : ∀ a : Fin K, bcnt a T ω ≤ T := fun a ↦ bcnt_le_self\n calc ∑ s ∈ Finset.Ico K T, cLow δ K (bcnt ((ω s).1) s ω)\n = ∑ a : Fin K, ∑ s ∈ (Finset.Ico K T).filter (fun s ↦ (ω s).1 = a),\n cLow δ K (bcnt ((ω s).1) s ω) :=\n (Finset.sum_fiberwise (Finset.Ico K T) (fun s ↦ (ω s).1) _).symm\n _ = ∑ a : Fin K, ∑ s ∈ (Finset.Ico K T).filter (fun s ↦ (ω s).1 = a),\n cLow δ K (bcnt a s ω) := by\n refine Finset.sum_congr rfl fun a _ ↦ Finset.sum_congr rfl fun s hs ↦ ?_\n rw [(Finset.mem_filter.mp hs).2]\n _ ≤ ∑ a : Fin K, ∑ m ∈ Finset.Icc 1 (bcnt a T ω - 1), cLow δ K m :=\n Finset.sum_le_sum fun a _ ↦ sum_fiber_le hδ0 hδ1 hK hwarmact a\n _ ≤ ∑ a : Fin K, ∑ m ∈ Finset.Icc 1 (bcnt a T ω - 1), C * (1 / Real.sqrt m) := by\n refine Finset.sum_le_sum fun a _ ↦ Finset.sum_le_sum fun m hm ↦ ?_\n obtain ⟨hm1, hm2⟩ := Finset.mem_Icc.mp hm\n have hmT : m + 1 ≤ T := by have := hNa a; have := hNaT a; lia\n exact cLow_le_bound hδ0 hδ1 hK hm1 hmT\n _ = ∑ a : Fin K, C * (∑ m ∈ Finset.Icc 1 (bcnt a T ω - 1), (1 / Real.sqrt m)) := by\n refine Finset.sum_congr rfl fun a _ ↦ ?_\n rw [Finset.mul_sum]\n _ ≤ ∑ a : Fin K, C * (2 * Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ))) := by\n refine Finset.sum_le_sum fun a _ ↦ ?_\n exact mul_le_mul_of_nonneg_left (sum_inv_sqrt_le _) hCnn\n _ = C * (2 * ∑ a : Fin K, Real.sqrt (((bcnt a T ω - 1 : ℕ) : ℝ))) := by\n rw [Finset.mul_sum, Finset.mul_sum]\n _ ≤ C * (2 * Real.sqrt ((K:ℝ) * ((T:ℝ) - K))) := by\n refine mul_le_mul_of_nonneg_left ?_ hCnn\n have := sum_sqrt_counts_le hK hKT hwarmact\n linarith\n\nend Summation\n\nsection FinalDet\n\nvariable {K T : ℕ} {δ : ℝ} {ν : Kernel (Fin K) ℝ} [IsMarkovKernel ν]\n\nlemma sqrt_identity (hK : 0 < K) (hKT : K ≤ T) {L : ℝ} (hL : 0 ≤ L) :\n Real.sqrt (8 * L * ((T:ℝ) - K) * K)\n = 4 * Real.sqrt (L / 2) * Real.sqrt ((K:ℝ) * ((T:ℝ) - K)) := by\n have hTK : (0:ℝ) ≤ (T:ℝ) - K := by\n have : (K:ℝ) ≤ (T:ℝ) := by exact_mod_cast hKT\n linarith\n have h16 : Real.sqrt 16 = 4 := by\n rw [show (16:ℝ) = 4 ^ 2 by norm_num, Real.sqrt_sq (by norm_num)]\n rw [show 8 * L * ((T:ℝ) - K) * K = 16 * ((L / 2) * ((K:ℝ) * ((T:ℝ) - K))) by ring,\n Real.sqrt_mul (by norm_num), h16, Real.sqrt_mul (by positivity)]\n ring\n\nlemma regret_bound_det (hK : 0 < K) (hKT : K ≤ T) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1)\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K}\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + ucbWidthNL δ n h a ≤\n empMean' n h (nextA n h) + ucbWidthNL δ n h (nextA n h))\n {astar : Fin K} (hmax : ∀ a, bmu ν a ≤ bmu ν astar)\n {ω : ℕ → Fin K × ℝ} (hf : followsAlg hK nextA ω)\n (hgu : goodUp δ T (bmu ν) astar ω) (hgl : goodLow δ K T (bmu ν) ω) :\n (T:ℝ) * (⨆ a, bmu ν a) - ∑ s ∈ range T, bmu ν ((ω s).1)\n ≤ ((K:ℝ) - 1) + Real.sqrt (8 * Real.log (2 * K * (T:ℝ) ^ 2 / δ) * ((T:ℝ) - K) * K) := by\n have hwarmact := warm_action hK hwarm hf\n have hKR : (0:ℝ) < K := by exact_mod_cast hK\n have hLnn : 0 ≤ Real.log (2 * K * (T:ℝ) ^ 2 / δ) := by\n refine Real.log_nonneg ?_\n rw [le_div_iff₀ hδ0]\n have h1 : (1:ℝ) ≤ (K:ℝ) := by exact_mod_cast hK\n have h2 : (1:ℝ) ≤ (T:ℝ) := by\n have : 1 ≤ T := by lia\n exact_mod_cast this\n nlinarith\n have hsplit : (T:ℝ) * bmu ν astar - ∑ s ∈ range T, bmu ν ((ω s).1)\n = ∑ s ∈ range T, (bmu ν astar - bmu ν ((ω s).1)) := by\n rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_range, nsmul_eq_mul]\n rw [iSup_eq_max hK hmax, hsplit, ← Finset.sum_range_add_sum_Ico _ hKT]\n have hA : ∑ s ∈ range K, (bmu ν astar - bmu ν ((ω s).1)) ≤ (K:ℝ) - 1 := by\n rw [sum_range_K_eq hwarmact (fun a ↦ bmu ν astar - bmu ν a)]\n exact sum_gap_le hK hmax (fun a ↦ ⟨bmu_nonneg hrew a, bmu_le_one hrew a⟩)\n have hB : ∑ s ∈ Finset.Ico K T, (bmu ν astar - bmu ν ((ω s).1))\n ≤ 2 * ∑ s ∈ Finset.Ico K T, cLow δ K (bcnt ((ω s).1) s ω) := by\n rw [Finset.mul_sum]\n refine Finset.sum_le_sum fun s hs ↦ ?_\n obtain ⟨h1, h2⟩ := Finset.mem_Ico.mp hs\n exact round_bound hK hδ0 hδ1 hargmax hf hwarmact hgu hgl s h1 h2\n have hC := sum_widths_bound (δ := δ) (K := K) (T := T) hδ0 hδ1 hK hKT hwarmact\n have hfin : 2 * ∑ s ∈ Finset.Ico K T, cLow δ K (bcnt ((ω s).1) s ω)\n ≤ Real.sqrt (8 * Real.log (2 * K * (T:ℝ) ^ 2 / δ) * ((T:ℝ) - K) * K) := by\n rw [sqrt_identity hK hKT hLnn]\n linarith\n linarith\n\nend FinalDet\n\nsection MainBound\n\nvariable {K T : ℕ} {δ : ℝ}\n\nlemma main_bound {hK : 0 < K} (hKT : K ≤ T) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n {ν : Kernel (Fin K) ℝ} [IsMarkovKernel ν] (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1)\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K} {hmeasA : ∀ n, Measurable (nextA n)}\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + ucbWidthNL δ n h a ≤\n empMean' n h (nextA n h) + ucbWidthNL δ n h (nextA n h)) :\n ENNReal.ofReal (1 - δ) ≤ (banditP hK ν nextA hmeasA)\n {ω | (T:ℝ) * (⨆ a, bmu ν a) - ∑ s ∈ range T, bmu ν ((ω s).1)\n ≤ ((K:ℝ) - 1) + Real.sqrt (8 * Real.log (2 * K * (T:ℝ) ^ 2 / δ) * ((T:ℝ) - K) * K)} := by\n classical\n obtain ⟨astar, hmax⟩ := exists_argmax hK (bmu ν)\n set Tgt : Set (ℕ → Fin K × ℝ) :=\n {ω | (T:ℝ) * (⨆ a, bmu ν a) - ∑ s ∈ range T, bmu ν ((ω s).1)\n ≤ ((K:ℝ) - 1) + Real.sqrt (8 * Real.log (2 * K * (T:ℝ) ^ 2 / δ) * ((T:ℝ) - K) * K)}\n with hTgt\n set B1 : Set (ℕ → Fin K × ℝ) := ⋃ m ∈ Finset.Icc 1 T,\n {ω | bW (bmu ν) astar m T ω < -((m:ℝ) * cUp δ m)} with hB1\n set B2 : Set (ℕ → Fin K × ℝ) := ⋃ a : Fin K, ⋃ m ∈ Finset.Icc 1 T,\n {ω | (m:ℝ) * cLow δ K m < bW (bmu ν) a m T ω} with hB2\n set B3 : Set (ℕ → Fin K × ℝ) := {ω | ¬ followsAlg hK nextA ω} with hB3\n have hgood : ∀ ω : ℕ → Fin K × ℝ, ω ∉ B1 → ω ∉ B2 → ω ∉ B3 → ω ∈ Tgt := by\n intro ω h1 h2 h3\n have hf : followsAlg hK nextA ω := by\n by_contra hc\n exact h3 hc\n have hgu : goodUp δ T (bmu ν) astar ω := by\n intro m hm1 hm2\n by_contra hc\n push_neg at hc\n exact h1 (Set.mem_iUnion₂.mpr ⟨m, Finset.mem_Icc.mpr ⟨hm1, hm2⟩, hc⟩)\n have hgl : goodLow δ K T (bmu ν) ω := by\n intro a m hm1 hm2\n by_contra hc\n push_neg at hc\n exact h2 (Set.mem_iUnion.mpr\n ⟨a, Set.mem_iUnion₂.mpr ⟨m, Finset.mem_Icc.mpr ⟨hm1, hm2⟩, hc⟩⟩)\n exact regret_bound_det hK hKT hδ0 hδ1 hrew hwarm hargmax hmax hf hgu hgl\n have hcompl : Tgtᶜ ⊆ B1 ∪ B2 ∪ B3 := by\n intro ω hω\n by_contra hnot\n simp only [Set.mem_union, not_or] at hnot\n exact hω (hgood ω hnot.1.1 hnot.1.2 hnot.2)\n have hPB1 : (banditP hK ν nextA hmeasA) B1 ≤ ENNReal.ofReal (δ / 2) :=\n prob_failUp_union hrew hδ0 hδ1 astar T\n have hPB2 : (banditP hK ν nextA hmeasA) B2 ≤ ENNReal.ofReal (δ / 2) :=\n prob_failLow_union hrew hδ0 hδ1 hK T\n have hPB3 : (banditP hK ν nextA hmeasA) B3 = 0 := by\n have h := ae_followsAlg (hK := hK) (ν := ν) (nextA := nextA) (hmeasA := hmeasA)\n rwa [ae_iff] at h\n have hbad : (banditP hK ν nextA hmeasA) Tgtᶜ ≤ ENNReal.ofReal δ := by\n calc (banditP hK ν nextA hmeasA) Tgtᶜ\n ≤ (banditP hK ν nextA hmeasA) (B1 ∪ B2 ∪ B3) := measure_mono hcompl\n _ ≤ (banditP hK ν nextA hmeasA) (B1 ∪ B2) + (banditP hK ν nextA hmeasA) B3 :=\n measure_union_le _ _\n _ ≤ ((banditP hK ν nextA hmeasA) B1 + (banditP hK ν nextA hmeasA) B2)\n + (banditP hK ν nextA hmeasA) B3 := by\n have h := measure_union_le (μ := banditP hK ν nextA hmeasA) B1 B2\n exact add_le_add h le_rfl\n _ ≤ (ENNReal.ofReal (δ / 2) + ENNReal.ofReal (δ / 2)) + 0 := by\n rw [hPB3]\n exact add_le_add (add_le_add hPB1 hPB2) le_rfl\n _ = ENNReal.ofReal δ := by\n rw [add_zero, ← ENNReal.ofReal_add (by linarith) (by linarith)]\n norm_num\n have hone : (1:ℝ≥0∞) ≤ (banditP hK ν nextA hmeasA) Tgt + ENNReal.ofReal δ := by\n calc (1:ℝ≥0∞) = (banditP hK ν nextA hmeasA) Set.univ := (measure_univ).symm\n _ = (banditP hK ν nextA hmeasA) (Tgt ∪ Tgtᶜ) := by rw [Set.union_compl_self]\n _ ≤ (banditP hK ν nextA hmeasA) Tgt + (banditP hK ν nextA hmeasA) Tgtᶜ :=\n measure_union_le _ _\n _ ≤ (banditP hK ν nextA hmeasA) Tgt + ENNReal.ofReal δ := add_le_add le_rfl hbad\n rw [ENNReal.ofReal_sub 1 hδ0.le, ENNReal.ofReal_one]\n exact tsub_le_iff_right.mpr hone\n\nend MainBound\n\ntheorem ch16_theorem_16_3 {K T : ℕ} (hK : 0 < K) (hKT : K ≤ T)\n {δ : ℝ} (hδ0 : 0 < δ) (hδ1 : δ < 1)\n (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (hrew : ∀ a, (ν a) (Set.Icc 0 1) = 1)\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K)\n (hmeasA : ∀ n, Measurable (nextA n))\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + ucbWidthNL δ n h a ≤\n empMean' n h (nextA n h) + ucbWidthNL δ n h (nextA n h)) :\n (trajMeasure (detAlgorithm nextA hmeasA ⟨0, hK⟩) (stationaryEnv ν))\n {ω | regret ν (action (𝓐 := Fin K) (𝓨 := ℝ)) T ω ≤\n ((K:ℝ) - 1) + Real.sqrt (8 * Real.log (2 * K * T ^ 2 / δ) * ((T:ℝ) - K) * K)}\n ≥ ENNReal.ofReal (1 - δ) := by\n have h := main_bound (hK := hK) (hmeasA := hmeasA) hKT hδ0 hδ1 hrew hwarm hargmax\n exact h\n\nend GraduateLevel\n"} +{"id": "ch6_proposition_6_46", "source": "Graduate-level", "targets": [{"label": "ch6_proposition_6_46", "decls": ["ch6_proposition_6_46"], "statement": "Consider function class \\(\\mathcal{G} = \\{\\phi(w, z) : w \\in \\Omega\\}\\) with \\(h(w) = \\phi(w, \\mathcal{D})\\) and \\(\\inf_{w \\in \\Omega} h(w) = 0\\). Assume that \\(|\\phi(\\cdot)| \\leq M\\) and the variance condition (3.14) holds with \\(c_0 = 0\\). Assume that for any \\(b > 0\\), we have\n\\[\n\\sup_{\\mathcal{S}_{n}}R\\left(\\left\\{\\phi(w,\\cdot):\\frac{1}{n}\\sum_{i=1}^{n}\\phi(w,Z_{i})^{2}\\leq b\\right\\},\\mathcal{S}_{n}\\right)\\leq r_{n}(b),\n\\]\nwhere \\(r_n(b)\\) is a continuous concave function of \\(b\\). Let \\(\\alpha \\leq 0.5c_1 / M\\) and\n\\[\nb_{0}=\\sup\\{b>0:b\\leq(4 c_{1}/\\alpha)r_{n}(b)\\},\n\\]\nthen \\(\\bar{r}_n^h(\\alpha,\\mathcal{G},\\mathcal{D})\\leq 0.5\\alpha b_0/c_1\\)", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Consider any \\( b_0' > b_0 \\) and let\n\\[\n\\mathcal{G}_{0}=\\{\\phi(w,\\cdot):\\phi(w,\\mathcal{D})\\leq 0. 5b_{0}^{\\prime}/c_{1}\\},\n\\]\nand define\n\\[\n\\hat{b}(\\mathcal{S}_{n})=\\sup_{g\\in\\mathcal{G}_{0}}\\frac{1}{n}\\sum_{i=1}^{n}g(Z_{i})^{2}.\n\\]\nWe have\n\\[\nR\\left(\\mathcal{G}_{0},\\mathcal{S}_{n}\\right)\\leq r_{n}(\\hat{b}\\left(\\mathcal{S}_{n}\\right)),\\quad R\\left(-\\mathcal{G}_{0}^{2},\\mathcal{S}_{n}\\right)\\leq 2 M r_{n}(\\hat{b}\\left(\\mathcal{S}_{n}\\right)).\\tag{6.8}\n\\]\nThe first inequality used the definition of \\( r_n \\) and the definition of \\( \\hat{b} \\). The second inequality used Theorem 6.28 and \\( |\\phi(w_1, z)^2 - \\phi(w_2, z)^2| \\leq 2M|\\phi(w_1, z) - \\phi(w_2, z)| \\).\nLet \\(\\tilde{b} = \\mathbb{E}_{\\mathcal{S}_n}\\hat{b} (\\mathcal{S}_n)\\), then we have\n\\[\n\\begin{array}{l}\\tilde{b}=\\mathbb{E}_{\\mathcal{S}_{n}}\\hat{b}(\\mathcal{S}_{n})\\leq\\epsilon_{n}(-\\mathcal{G}_{0}^{2},\\mathcal{D})+0. 5b_{0}^{\\prime}\\\\ \\leq 2R_{n}\\left(-\\mathcal{G}_{0}^{2},\\mathcal{D}\\right)+0. 5b_{0}^{\\prime}\\\\ \\leq 4M\\mathbb{E}_{\\mathcal{S}_{n}}r_{n}(\\hat{b}(\\mathcal{S}_{n}))+0. 5b_{0}^{\\prime}\\leq(2c_{1}/\\alpha)r_{n}(\\tilde{b})+0. 5b_{0}^{\\prime}.\\\\ \\end{array}\n\\]\nThe first inequality used \\(\\sup_{g\\in \\mathcal{G}_0}\\mathbb{E}_{Z\\sim \\mathcal{D}}g(Z)^2\\leq 0.5b_0'\\), which follows from the\nvariance condition. The second inequality used Theorem 6.4. The third inequality used (6.8). The last inequality used the concavity of \\(r_n(\\cdot)\\) and \\(4M \\leq 2c_1 / \\alpha\\).\nFrom the above inequality, we have either \\(\\tilde{b} < b_0'\\), or \\(\\tilde{b} \\leq (2c_1 / \\alpha)r_n(\\tilde{b}) + 0.5\\tilde{b}\\). The latter also implies that \\(\\tilde{b} \\leq b_0 < b_0'\\) by using the definition of \\(b_0\\). We thus obtain\n\\[\n\\epsilon_{n}(\\mathcal{G}_{0})\\leq 2\\mathbb{E}_{\\mathcal{S}_{n}}R(\\mathcal{G}_{0},\\mathcal{S}_{n})\\leq 2\\mathbb{E}_{\\mathcal{S}_{n}}r_{n}(\\hat{b}(\\mathcal{S}_{n}))\\leq 2r_{n}(\\tilde{b})<(0. 5\\alpha/c_{1})b_{0}^{\\prime}.\n\\]\nThe first inequality used Theorem 6.4. The second inequality (6.8). The third inequality used the concavity of \\( r_n(\\cdot) \\). The last inequality used \\( \\tilde{b} < b_0' \\), \\( b_0' > b_0 \\), and the definition of \\( b_0 \\).\nTherefore if we let \\(r = 0.5(\\alpha /c_1)b_0'\\), then \\(\\epsilon_{n}(\\mathcal{G}^{h}(r / \\alpha)) = \\epsilon_{n}(\\mathcal{G}_{0})\\leq 2r_{n}(\\tilde{b}) < r\\), where \\(\\tilde{b}_0 < 2(c_1 / \\alpha)r\\). The condition that \\(r_n(\\cdot)\\) is continuous implies that \\(\\lim_{\\Delta r\\to 0^{+}}\\epsilon_{n}(\\mathcal{G}^{h}((r + \\Delta r) / \\alpha)) < r\\). The desired result follows from the definition of \\(\\bar{r}_n^h(\\alpha,\\mathcal{G},\\mathcal{D})\\).", "context": [{"id": "ch6:theorem:6_28", "name": "theorem 6.28", "statement": "Let \\(\\{\\phi_i\\}_{i=1}^n\\) be functions with Lipschitz constants \\(\\{\\gamma_i\\}_{i=1}^n\\) respectively. That is, \\(\\forall i \\in [n]\\):\n\\[\n\\left|\\phi_{i}(\\theta)-\\phi_{i}\\left(\\theta^{\\prime}\\right)\\right|\\leq\\gamma_{i}\\left|\\theta-\\theta^{\\prime}\\right|.\n\\]\nThen for any real valued function \\( h: \\mathcal{F} \\times \\mathcal{Z}^n \\to \\mathbb{R} \\), and \\( S_n = \\{Z_1, \\ldots, Z_n\\} \\subset \\mathcal{Z}^n \\), we have\n\\[\n\\mathbb{E}_{\\sigma}\\sup_{f\\in\\mathcal{F}}\\left[\\sum_{i=1}^{n}\\sigma_{i}\\phi_{i}(f(Z_{i}))-h(f,\\mathcal{S}_{n})\\right]\\leq\\mathbb{E}_{\\sigma}\\sup_{f\\in\\mathcal{F}}\\left[\\sum_{i=1}^{n}\\sigma_{i}\\gamma_{i}f(Z_{i})-h(f,\\mathcal{S}_{n})\\right].\n\\]"}, {"id": "ch6:theorem:6_4", "name": "theorem 6.4", "statement": "We have\n\\[\n\\epsilon_{n}(\\mathcal{G},\\mathcal{D})\\leq 2 R_{n}(\\mathcal{G},\\mathcal{D}).\n\\]\nConsequently, the approximate ERM method of (3.7) satisfies\n\\[\n\\mathbb{E}_{\\mathcal{S}_{n}}\\phi(\\hat{w},\\mathcal{D})\\leq\\inf_{w\\in\\Omega}\\phi(w,\\mathcal{D})+\\epsilon^{\\prime}+2 R_{n}(\\mathcal{G},\\mathcal{D}).\n\\]"}, {"id": "ch6:definition:6_35", "name": "definition 6.35", "statement": "Given \\(\\mathcal{D}\\) and \\(\\mathcal{F}\\), and consider a localization function \\(h: \\mathcal{F} \\to \\mathbb{R}\\) such that \\(b_0 = \\inf_{f \\in \\mathcal{F}} h(f) > -\\infty\\). Define localized function class \\(\\mathcal{F}^h(b) = \\{f \\in \\mathcal{F}: h(f) \\leq b\\}\\) for all \\(b > b_0\\). For any \\(\\alpha > 0\\), the rate function with respect to localization \\(h\\) is defined as\n\\[\n\\bar{r}_{n}^{h}(\\alpha,\\mathcal{F},\\mathcal{D})=\\sup\\left\\{r:r\\leq\\inf_{r^{\\prime}>\\max(r,\\alpha b_{0})}\\epsilon_{n}\\left(\\mathcal{F}^{h}\\big(r^{\\prime}/\\alpha\\big),\\mathcal{D}\\right)\\right\\}.\n\\]\nWe note that the requirement of \\( r' > \\alpha b_0 \\) in Definition 6.35 is only to make sure that \\( \\mathcal{F}^h(r'/\\alpha) \\) is always non-empty, and thus \\( \\epsilon_n(\\mathcal{F}^h(r'/\\alpha), \\mathcal{D}) \\) is well-defined."}, {"id": "ch6:definition:6_1", "name": "definition 6.1", "statement": "Given an empirical process \\(\\{\\phi(w, S_n) : w \\in \\Omega\\}\\), with \\(S_n \\sim \\mathcal{D}^n\\). Define the expected supremum of this empirical process as\n\\[\n\\epsilon_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}}\\sup_{w\\in\\Omega}\\left[\\phi(w,\\mathcal{D})-\\phi(w,\\mathcal{S}_{n})\\right],\n\\]\nwhich will be referred to as the uniform convergence complexity of the function class \\(\\mathcal{G}\\).\nThe smaller this quantity is, the closer the gap between the training error and the test error is, which implies that we have less overfitting. In Chapter 3, we\nobtained large probability uniform convergence results for empirical processes, and then derived oracle inequalities in large probabilities. In the following, we show that if average convergence can be obtained, then we can derive oracle inequalities in expectation directly."}, {"id": "ch6:definition:6_3", "name": "definition 6.3", "statement": "Given \\(S_{n}=\\{Z_{1},\\ldots,Z_{n}\\}\\), the (one-sided) empirical Rademacher complexity of \\(\\mathcal{G}\\) is defined as\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n}) = \\mathbb{E}_{\\sigma}\\sup_{w\\in \\Omega}\\frac{1}{n}\\sum_{i = 1}^{n}\\sigma_{i}\\phi (w,Z_{i}),\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R(\\mathcal{G},\\mathcal{S}_{n}).\n\\]"}, {"id": "ch3:definition:3_16", "name": "Variance Condition", "statement": "Given a function class \\(\\mathcal{G}\\). We say it satisfies the variance condition if there exists \\(c_0, c_1 > 0\\) such that for all \\(\\phi(z) \\in \\mathcal{G}\\):\n\\[\n\\operatorname{Var}_{Z\\sim\\mathcal{D}}(\\phi(Z))\\leq c_{0}^{2}+c_{1}\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(Z),\\tag{3.13}\n\\]\nwhere we require that \\(\\mathbb{E}_{Z\\sim \\mathcal{D}}\\phi (Z)\\geq -c_0^2 /c_1\\) for all \\(\\phi \\in \\mathcal{G}\\)\nIn applications, the following modification of the variance condition is often more convenient to employ\n\\[\n\\mathbb{E}_{Z\\sim\\mathcal{D}}[\\phi(Z)^{2}]\\leq c_{0}^{2}+c_{1}\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(Z).\\tag{3.14}\n\\]\nIt is easy to see that (3.14) implies (3.13). If \\(\\phi(Z)\\) is bounded, then the two conditions are equivalent.\nIn general, if the variance condition (3.13) only holds for \\( c_{1} = 0 \\), then we can only obtain a convergence rate that is \\( O(1 / \\sqrt{n}) \\) at the best. When the variance condition holds for \\( c_{1} > 0 \\) and \\( c_{0} = 0 \\), then we may be able to obtain a convergence rate faster than \\( O(1 / \\sqrt{n}) \\) by using Bernstein's inequality. The ability to achieve faster convergence is the main reason to study this condition."}], "lean": "import Mathlib\n\nopen MeasureTheory Real Set\nopen scoped BigOperators ENNReal NNReal\n\nnamespace GraduateLevel\n\nnoncomputable def popVal {𝒵 Ω : Type*} [MeasurableSpace 𝒵]\n (D : Measure 𝒵) (φ : Ω → 𝒵 → ℝ) (w : Ω) : ℝ :=\n ∫ z, φ w z ∂D\n\nnoncomputable def empMean {𝒵 : Type*} (n : ℕ) (g : 𝒵 → ℝ) (S : Fin n → 𝒵) : ℝ :=\n (1 / (n : ℝ)) * ∑ i, g (S i)\n\nnoncomputable def empRad {𝒵 Ω : Type*} (n : ℕ) (φ : Ω → 𝒵 → ℝ)\n (P : Set Ω) (S : Fin n → 𝒵) : ℝ :=\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool,\n ⨆ w : P, (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * φ w.1 (S i)\n\nnoncomputable def unifComplexity {𝒵 Ω : Type*} [MeasurableSpace 𝒵]\n (n : ℕ) (D : Measure 𝒵) (φ : Ω → 𝒵 → ℝ) (P : Set Ω) : ℝ :=\n ∫ S, (⨆ w : P, (popVal D φ w.1 - empMean n (φ w.1) S))\n ∂(Measure.pi (fun _ : Fin n => D))\n\nnoncomputable def bZero (c₁ α : ℝ) (r : ℝ → ℝ) : ℝ :=\n sSup {b : ℝ | 0 < b ∧ b ≤ (4 * c₁ / α) * r b}\n\ntheorem ch6_proposition_6_46\n {𝒵 Ω : Type*} [MeasurableSpace 𝒵] [Nonempty Ω] [Countable Ω]\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) (hn : 1 ≤ n)\n (φ : Ω → 𝒵 → ℝ)\n (M c₁ α : ℝ)\n (hM : 0 < M) (hc₁ : 0 < c₁) (hα : 0 < α)\n (hInf : ⨅ w, popVal D φ w = 0)\n (hMeas : ∀ w, AEStronglyMeasurable (fun z => φ w z) D)\n (hInt : ∀ w, Integrable (fun z => φ w z) D)\n (hInt2 : ∀ w, Integrable (fun z => (φ w z) ^ 2) D)\n (hBound : ∀ w z, |φ w z| ≤ M)\n (hVar : ∀ w, (∫ z, (φ w z) ^ 2 ∂D) ≤ c₁ * ∫ z, φ w z ∂D)\n (r : ℝ → ℝ)\n (hrCont : ContinuousOn r (Ici 0))\n (hrConcave : ConcaveOn ℝ (Ici 0) r)\n (hRad : ∀ b > (0 : ℝ),\n (⨆ S : Fin n → 𝒵, empRad n φ {w | empMean n (fun z => (φ w z) ^ 2) S ≤ b} S) ≤ r b)\n (hαM : α ≤ (1 / 2) * c₁ / M)\n (hbNE : {b : ℝ | 0 < b ∧ b ≤ (4 * c₁ / α) * r b}.Nonempty)\n (hbBdd : BddAbove {b : ℝ | 0 < b ∧ b ≤ (4 * c₁ / α) * r b})\n (rbar : ℝ)\n (hrbarDef : rbar = sSup {ρ : ℝ | ρ ≤\n sInf ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0)))})\n (hrbarNE : {ρ : ℝ | ρ ≤\n sInf ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0)))}.Nonempty)\n (hrbarBdd : BddAbove {ρ : ℝ | ρ ≤\n sInf ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0)))})\n (hInnerBdd : ∀ ρ : ℝ,\n BddBelow ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0))))\n (hUnifInt : ∀ r' : ℝ,\n Integrable (fun S : Fin n → 𝒵 =>\n ⨆ w : {w | popVal D φ w ≤ r' / α}, (popVal D φ w.1 - empMean n (φ w.1) S))\n (Measure.pi (fun _ : Fin n => D)))\n\n (hUnifInt2 : ∀ r' : ℝ,\n Integrable (fun S : Fin n → 𝒵 =>\n ⨆ w ∈ {w | popVal D φ w ≤ r' / α}, empMean n (fun z => (φ w z) ^ 2) S)\n (Measure.pi (fun _ : Fin n => D))) :\n rbar ≤ (1 / 2) * α * bZero c₁ α r / c₁ := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real Set\nopen scoped BigOperators ENNReal NNReal\n\nnamespace GraduateLevel\n\nnamespace Test\n\n\nprivate lemma bddAbove_range_of_abs_le {W : Type*} {f : W → ℝ} {C : ℝ}\n (h : ∀ w, |f w| ≤ C) : BddAbove (Set.range f) := by\n refine ⟨C, ?_⟩\n rintro _ ⟨w, rfl⟩\n exact (le_abs_self _).trans (h w)\n\nprivate lemma ciSup_add_ciSup {W : Type*} [Nonempty W] {f g : W → ℝ}\n (hf : BddAbove (Set.range f)) (hg : BddAbove (Set.range g)) :\n (⨆ w, f w) + ⨆ w, g w = ⨆ a, ⨆ b, f a + g b := by\n rw [ciSup_add hf]\n congr 1\n funext a\n rw [add_ciSup hg]\n\nprivate lemma ciSup_pair_le {W : Type*} [Nonempty W]\n {f g F G : W → ℝ} {cf cg cF cG : ℝ}\n (hf' : ∀ w, f w ≤ cf) (hg' : ∀ w, g w ≤ cg)\n (hF' : ∀ w, F w ≤ cF) (hG' : ∀ w, G w ≤ cG)\n (h : ∀ a b, f a + g b ≤ max (F a + G b) (G a + F b)) :\n (⨆ w, f w) + ⨆ w, g w ≤ (⨆ w, F w) + ⨆ w, G w := by\n have hf : BddAbove (Set.range f) := ⟨cf, by rintro _ ⟨w, rfl⟩; exact hf' w⟩\n have hg : BddAbove (Set.range g) := ⟨cg, by rintro _ ⟨w, rfl⟩; exact hg' w⟩\n have hF : BddAbove (Set.range F) := ⟨cF, by rintro _ ⟨w, rfl⟩; exact hF' w⟩\n have hG : BddAbove (Set.range G) := ⟨cG, by rintro _ ⟨w, rfl⟩; exact hG' w⟩\n rw [ciSup_add_ciSup hf hg, ciSup_add_ciSup hF hG]\n have hFG (a : W) : BddAbove (Set.range fun b => F a + G b) :=\n ⟨F a + cG, by rintro _ ⟨b, rfl⟩; exact add_le_add (le_refl _) (hG' b)⟩\n have hFG' : BddAbove (Set.range fun a => ⨆ b, F a + G b) :=\n ⟨cF + cG, by\n rintro _ ⟨a, rfl⟩\n exact ciSup_le fun b => add_le_add (hF' a) (hG' b)⟩\n refine ciSup_le fun a => ciSup_le fun b => ?_\n refine (h a b).trans ?_\n apply max_le\n · exact le_ciSup_of_le hFG' a (le_ciSup_of_le (hFG a) b (le_rfl))\n · exact le_ciSup_of_le hFG' b (le_ciSup_of_le (hFG b) a (by simpa [add_comm]))\n\nprivate lemma contraction_one {W : Type*} [Nonempty W]\n (u x ψ : W → ℝ) (L U X P : ℝ)\n (hL : 0 ≤ L)\n (hu : ∀ w, |u w| ≤ U) (hx : ∀ w, |x w| ≤ X) (hψ : ∀ w, |ψ w| ≤ P)\n (hlip : ∀ a b, |ψ a - ψ b| ≤ L * |x a - x b|) :\n (⨆ w, u w + ψ w) + (⨆ w, u w - ψ w) ≤\n (⨆ w, u w + L * x w) + (⨆ w, u w - L * x w) := by\n have hb (s t : W → ℝ) (S T : ℝ) (hs : ∀ w, |s w| ≤ S) (ht : ∀ w, |t w| ≤ T) :\n BddAbove (Set.range fun w => s w + t w) := by\n apply bddAbove_range_of_abs_le\n intro w\n exact (abs_add_le _ _).trans (add_le_add (hs w) (ht w))\n have hLx : ∀ w, |L * x w| ≤ L * X := by\n intro w\n rw [abs_mul, abs_of_nonneg hL]\n exact mul_le_mul_of_nonneg_left (hx w) hL\n apply ciSup_pair_le\n (fun w => (le_abs_self _).trans ((abs_add_le _ _).trans (add_le_add (hu w) (hψ w))))\n (fun w => (le_abs_self _).trans ((abs_add_le _ _).trans\n (add_le_add (hu w) (by simpa using hψ w))))\n (fun w => (le_abs_self _).trans ((abs_add_le _ _).trans (add_le_add (hu w) (hLx w))))\n (fun w => (le_abs_self _).trans ((abs_add_le _ _).trans\n (add_le_add (hu w) (by simpa using hLx w))))\n intro a b\n dsimp only\n have hab : ψ a - ψ b ≤ L * |x a - x b| :=\n (le_abs_self _).trans (hlip a b)\n rcases le_total (x b) (x a) with hxba | hxab\n · rw [abs_of_nonneg (sub_nonneg.mpr hxba)] at hab\n exact (show u a + ψ a + (u b + -ψ b) ≤\n u a + L * x a + (u b + -(L * x b)) by linarith).trans (le_max_left _ _)\n · rw [abs_of_nonpos (sub_nonpos.mpr hxab)] at hab\n exact (show u a + ψ a + (u b + -ψ b) ≤\n u a + -(L * x a) + (u b + L * x b) by linarith).trans (le_max_right _ _)\n\nprivate lemma sum_sign_succ (n : ℕ) (F : (Fin (n + 1) → Bool) → ℝ) :\n (∑ σ, F σ) = ∑ τ : Fin n → Bool, (F (Fin.cons true τ) + F (Fin.cons false τ)) := by\n calc\n (∑ σ, F σ) = ∑ p : Bool × (Fin n → Bool), F (Fin.cons p.1 p.2) := by\n simpa only [Fin.consEquiv_apply] using\n ((Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp F).symm\n _ = ∑ b : Bool, ∑ τ : Fin n → Bool, F (Fin.cons b τ) := by\n rw [Fintype.sum_prod_type]\n _ = ∑ τ : Fin n → Bool, ∑ b : Bool, F (Fin.cons b τ) := by\n rw [Finset.sum_comm]\n _ = _ := by simp only [Fintype.sum_bool]\n\nprivate lemma rademacher_contraction_sum_aux {W : Type*} [Nonempty W]\n (n : ℕ) (u : W → ℝ) (x ψ : W → Fin n → ℝ) (L U X P : ℝ)\n (hL : 0 ≤ L) (hu : ∀ w, |u w| ≤ U)\n (hx : ∀ w i, |x w i| ≤ X) (hψ : ∀ w i, |ψ w i| ≤ P)\n (hlip : ∀ i a b, |ψ a i - ψ b i| ≤ L * |x a i - x b i|) :\n (∑ σ : Fin n → Bool, ⨆ w : W,\n u w + ∑ i, (if σ i then (1 : ℝ) else -1) * ψ w i) ≤\n ∑ σ : Fin n → Bool, ⨆ w : W,\n u w + ∑ i, (if σ i then (1 : ℝ) else -1) * (L * x w i) := by\n induction n generalizing u U with\n | zero => simp\n | succ n ih =>\n rw [sum_sign_succ, sum_sign_succ]\n have htail (τ : Fin n → Bool) : ∀ w,\n |u w + ∑ i : Fin n, (if τ i then (1 : ℝ) else -1) * ψ w i.succ| ≤\n U + n * P := by\n intro w\n calc\n |u w + ∑ i : Fin n, (if τ i then (1 : ℝ) else -1) * ψ w i.succ| ≤\n |u w| + |∑ i : Fin n, (if τ i then (1 : ℝ) else -1) * ψ w i.succ| :=\n abs_add_le _ _\n _ ≤ U + ∑ i : Fin n,\n |(if τ i then (1 : ℝ) else -1) * ψ w i.succ| := by\n exact add_le_add (hu w) (Finset.abs_sum_le_sum_abs _ _)\n _ ≤ U + ∑ _i : Fin n, P := by\n gcongr with i hi\n simpa only [abs_mul, abs_ite, abs_one, abs_neg, ite_self, one_mul] using\n hψ w i.succ\n _ = U + n * P := by simp [mul_comm]\n have hpoint (τ : Fin n → Bool) :\n (⨆ w : W, u w + ∑ i,\n (if (Fin.cons true τ : Fin (n + 1) → Bool) i then (1 : ℝ) else -1) * ψ w i) +\n (⨆ w : W, u w + ∑ i,\n (if (Fin.cons false τ : Fin (n + 1) → Bool) i then (1 : ℝ) else -1) * ψ w i) ≤\n (⨆ w : W, (u w + L * x w 0) + ∑ i : Fin n,\n (if τ i then (1 : ℝ) else -1) * ψ w i.succ) +\n (⨆ w : W, (u w - L * x w 0) + ∑ i : Fin n,\n (if τ i then (1 : ℝ) else -1) * ψ w i.succ) := by\n simp [Fin.sum_univ_succ]\n let v : W → ℝ := fun w =>\n u w + ∑ i : Fin n, (if τ i then (1 : ℝ) else -1) * ψ w i.succ\n have hc := contraction_one v (fun w => x w 0) (fun w => ψ w 0) L\n (U + n * P) X P hL (htail τ) (fun w => hx w 0) (fun w => hψ w 0) (hlip 0)\n simpa [v, sub_eq_add_neg, add_assoc, add_comm, add_left_comm] using hc\n calc\n (∑ τ : Fin n → Bool,\n ((⨆ w : W, u w + ∑ i,\n (if (Fin.cons true τ : Fin (n + 1) → Bool) i then (1 : ℝ) else -1) * ψ w i) +\n (⨆ w : W, u w + ∑ i,\n (if (Fin.cons false τ : Fin (n + 1) → Bool) i then (1 : ℝ) else -1) * ψ w i)))\n ≤ ∑ τ : Fin n → Bool,\n ((⨆ w : W, (u w + L * x w 0) + ∑ i,\n (if τ i then (1 : ℝ) else -1) * ψ w i.succ) +\n (⨆ w : W, (u w - L * x w 0) + ∑ i,\n (if τ i then (1 : ℝ) else -1) * ψ w i.succ)) := by\n exact Finset.sum_le_sum fun τ _ => hpoint τ\n _ = (∑ τ : Fin n → Bool, ⨆ w : W,\n (u w + L * x w 0) + ∑ i,\n (if τ i then (1 : ℝ) else -1) * ψ w i.succ) +\n (∑ τ : Fin n → Bool, ⨆ w : W,\n (u w - L * x w 0) + ∑ i,\n (if τ i then (1 : ℝ) else -1) * ψ w i.succ) := by\n rw [Finset.sum_add_distrib]\n _ ≤ (∑ τ : Fin n → Bool, ⨆ w : W,\n (u w + L * x w 0) + ∑ i,\n (if τ i then (1 : ℝ) else -1) * (L * x w i.succ)) +\n (∑ τ : Fin n → Bool, ⨆ w : W,\n (u w - L * x w 0) + ∑ i,\n (if τ i then (1 : ℝ) else -1) * (L * x w i.succ)) := by\n apply add_le_add\n · exact ih (fun w => u w + L * x w 0)\n (fun w i => x w i.succ) (fun w i => ψ w i.succ)\n (U + L * X)\n (fun w => (abs_add_le _ _).trans (add_le_add (hu w) (by\n rw [abs_mul, abs_of_nonneg hL]\n exact mul_le_mul_of_nonneg_left (hx w 0) hL)))\n (fun w i => hx w i.succ) (fun w i => hψ w i.succ)\n (fun i a b => hlip i.succ a b)\n · exact ih (fun w => u w - L * x w 0)\n (fun w i => x w i.succ) (fun w i => �� w i.succ)\n (U + L * X)\n (fun w => (abs_add_le _ _).trans (add_le_add (hu w) (by\n simpa only [abs_neg, abs_mul, abs_of_nonneg hL] using\n mul_le_mul_of_nonneg_left (hx w 0) hL)))\n (fun w i => hx w i.succ) (fun w i => hψ w i.succ)\n (fun i a b => hlip i.succ a b)\n _ = ∑ τ : Fin n → Bool,\n ((⨆ w : W, u w + ∑ i,\n (if (Fin.cons true τ : Fin (n + 1) → Bool) i then (1 : ℝ) else -1) * (L * x w i)) +\n (⨆ w : W, u w + ∑ i,\n (if (Fin.cons false τ : Fin (n + 1) → Bool) i then (1 : ℝ) else -1) * (L * x w i))) := by\n rw [Finset.sum_add_distrib]\n simp [Fin.sum_univ_succ, sub_eq_add_neg, add_assoc]\n\nprivate lemma rademacher_contraction_sum {W : Type*} [Nonempty W]\n (n : ℕ) (x ψ : W → Fin n → ℝ) (L X P : ℝ)\n (hL : 0 ≤ L) (hx : ∀ w i, |x w i| ≤ X) (hψ : ∀ w i, |ψ w i| ≤ P)\n (hlip : ∀ i a b, |ψ a i - ψ b i| ≤ L * |x a i - x b i|) :\n (∑ σ : Fin n → Bool, ⨆ w : W,\n ∑ i, (if σ i then (1 : ℝ) else -1) * ψ w i) ≤\n ∑ σ : Fin n → Bool, ⨆ w : W,\n ∑ i, (if σ i then (1 : ℝ) else -1) * (L * x w i) := by\n simpa only [zero_add] using\n rademacher_contraction_sum_aux n (fun _ : W => 0) x ψ L 0 X P hL\n (fun _ => abs_zero.le) hx hψ hlip\n\ntheorem rademacher_square_contraction {W : Type*} [Nonempty W]\n (n : ℕ) (hn : 0 < n) (x : W → Fin n → ℝ) (M : ℝ) (hM : 0 ≤ M)\n (hx : ∀ w i, |x w i| ≤ M) :\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (-(x w i) ^ 2)) ≤\n (2 * M) * ((1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * x w i)) := by\n let q : ℝ := 1 / (n : ℝ)\n have hq : 0 ≤ q := by positivity\n have hc := rademacher_contraction_sum n\n (fun w i => q * x w i) (fun w i => q * (-(x w i) ^ 2))\n (2 * M) (q * M) (q * M ^ 2) (by positivity)\n (fun w i => by rw [abs_mul, abs_of_nonneg hq]; exact mul_le_mul_of_nonneg_left (hx w i) hq)\n (fun w i => by\n rw [abs_mul, abs_of_nonneg hq, abs_neg, abs_pow]\n apply mul_le_mul_of_nonneg_left _ hq\n exact pow_le_pow_left₀ (abs_nonneg _) (hx w i) 2)\n (fun i a b => by\n rw [← mul_sub, abs_mul, abs_of_nonneg hq, mul_assoc]\n have hs : |-x a i ^ 2 - -x b i ^ 2| ≤ (2 * M) * |x a i - x b i| := by\n rw [neg_sub_neg, abs_sub_comm, sq_sub_sq, abs_mul]\n apply mul_le_mul_of_nonneg_right\n · exact (abs_add_le _ _).trans (by linarith [hx a i, hx b i])\n · exact abs_nonneg _\n calc\n q * |-x a i ^ 2 - -x b i ^ 2| ≤ q * ((2 * M) * |x a i - x b i|) :=\n mul_le_mul_of_nonneg_left hs hq\n _ = 2 * (M * |q * x a i - q * x b i|) := by\n rw [← mul_sub, abs_mul, abs_of_nonneg hq]\n ring)\n have hb (σ : Fin n → Bool) : BddAbove (Set.range fun w : W =>\n q * ∑ i, (if σ i then (1 : ℝ) else -1) * x w i) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨w, rfl⟩\n exact (le_abs_self _).trans (by\n rw [abs_mul, abs_of_nonneg hq]\n calc\n q * |∑ i, (if σ i then (1 : ℝ) else -1) * x w i| ≤\n q * ∑ i, |(if σ i then (1 : ℝ) else -1) * x w i| := by\n gcongr\n exact Finset.abs_sum_le_sum_abs _ _\n _ ≤ q * ∑ _i : Fin n, M := by\n gcongr with i hi\n simpa only [abs_mul, abs_ite, abs_one, abs_neg, ite_self, one_mul] using hx w i\n _ = M := by\n dsimp [q]\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp)\n calc\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (-(x w i) ^ 2)) =\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n ∑ i, (if σ i then (1 : ℝ) else -1) * (q * (-(x w i) ^ 2))) := by\n congr 2\n funext σ\n congr 1\n funext w\n dsimp [q]\n rw [Finset.mul_sum]\n congr 1\n funext i\n ring\n _ ≤ (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n ∑ i, (if σ i then (1 : ℝ) else -1) * ((2 * M) * (q * x w i))) := by\n exact mul_le_mul_of_nonneg_left hc (by positivity)\n _ ≤ (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool,\n (2 * M) * (⨆ w : W, q * ∑ i,\n (if σ i then (1 : ℝ) else -1) * x w i) := by\n apply mul_le_mul_of_nonneg_left\n · apply Finset.sum_le_sum\n intro σ _\n apply ciSup_le\n intro w\n calc\n (∑ i, (if σ i then (1 : ℝ) else -1) * ((2 * M) * (q * x w i))) =\n (2 * M) * (q * ∑ i, (if σ i then (1 : ℝ) else -1) * x w i) := by\n rw [Finset.mul_sum, Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro i _\n ring\n _ ≤ (2 * M) * (⨆ w : W, q * ∑ i,\n (if σ i then (1 : ℝ) else -1) * x w i) := by\n gcongr\n exact le_ciSup (hb σ) w\n · positivity\n _ = (2 * M) * ((1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * x w i)) := by\n dsimp [q]\n rw [← Finset.mul_sum]\n ring\n\n\n\nprivate lemma integral_empirical_eq {Z : Type*} [MeasurableSpace Z]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (hn : 0 < n)\n (g : Z → ℝ) (hg : Integrable g D) :\n ∫ S : Fin n → Z, (1 / (n : ℝ)) * ∑ i, g (S i)\n ∂(Measure.pi (fun _ : Fin n => D)) = ∫ z, g z ∂D := by\n rw [integral_const_mul]\n rw [integral_finset_sum]\n · simp_rw [integral_comp_eval (μ := fun _ : Fin n => D) hg.aestronglyMeasurable]\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n · intro i _\n exact integrable_comp_eval (μ := fun _ : Fin n => D) hg\n\ntheorem integrable_ciSup_of_abs_le {A W : Type*} [MeasurableSpace A]\n [Countable W] [Nonempty W] (μ : Measure A) [IsFiniteMeasure μ]\n (f : W → A → ℝ) (C : ℝ)\n (hf : ∀ w, AEMeasurable (f w) μ) (hC : ∀ w a, |f w a| ≤ C) :\n Integrable (fun a => ⨆ w, f w a) μ := by\n have hmeas : AEMeasurable (fun a => ⨆ w, f w a) μ :=\n AEMeasurable.iSup hf\n apply Integrable.of_bound hmeas.aestronglyMeasurable C\n filter_upwards [] with a\n rw [Real.norm_eq_abs, abs_le]\n constructor\n · let w : W := Classical.choice inferInstance\n have hb : BddAbove (Set.range fun w => f w a) :=\n ⟨C, by rintro _ ⟨w, rfl⟩; exact (le_abs_self _).trans (hC w a)⟩\n exact (neg_le_of_abs_le (hC w a)).trans (le_ciSup hb w)\n · exact ciSup_le fun w => (le_abs_self _).trans (hC w a)\n\ntheorem aemeasurable_empirical {Z : Type*} [MeasurableSpace Z]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (g : Z → ℝ)\n (hg : AEStronglyMeasurable g D) :\n AEMeasurable (fun S : Fin n → Z =>\n (1 / (n : ℝ)) * ∑ i, g (S i)) (Measure.pi (fun _ : Fin n => D)) := by\n apply AEMeasurable.const_mul\n have h := Finset.aemeasurable_sum (μ := Measure.pi (fun _ : Fin n => D)) Finset.univ\n (fun i _ => hg.aemeasurable.comp_quasiMeasurePreserving\n (measurePreserving_eval (fun _ : Fin n => D) i).quasiMeasurePreserving)\n convert h using 1\n funext S\n simp only [Finset.sum_apply, Function.comp_apply]\n\nprivate lemma aemeasurable_signed_empirical {Z : Type*} [MeasurableSpace Z]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (g : Z → ℝ)\n (hg : AEStronglyMeasurable g D) (σ : Fin n → Bool) :\n AEMeasurable (fun S : Fin n → Z =>\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g (S i))\n (Measure.pi (fun _ : Fin n => D)) := by\n apply AEMeasurable.const_mul\n have h := Finset.aemeasurable_sum (μ := Measure.pi (fun _ : Fin n => D)) Finset.univ\n (fun i _ => AEMeasurable.const_mul\n (hg.aemeasurable.comp_quasiMeasurePreserving\n (measurePreserving_eval (fun _ : Fin n => D) i).quasiMeasurePreserving)\n (if σ i then (1 : ℝ) else -1))\n convert h using 1\n funext S\n simp only [Finset.sum_apply, Function.comp_apply]\n\ntheorem abs_empirical_le {Z : Type*} (n : ℕ) (hn : 0 < n)\n (g : Z → ℝ) (C : ℝ) (hg : ∀ z, |g z| ≤ C) (S : Fin n → Z) :\n |(1 / (n : ℝ)) * ∑ i, g (S i)| ≤ C := by\n rw [abs_mul, abs_of_nonneg (by positivity : 0 ≤ (1 / (n : ℝ)))]\n calc\n (1 / (n : ℝ)) * |∑ i, g (S i)| ≤\n (1 / (n : ℝ)) * ∑ i, |g (S i)| := by\n gcongr\n exact Finset.abs_sum_le_sum_abs _ _\n _ ≤ (1 / (n : ℝ)) * ∑ _i : Fin n, C := by\n gcongr with i hi\n exact hg (S i)\n _ = C := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n\nprivate lemma symmetrization_ghost {Z W : Type*} [MeasurableSpace Z]\n [Countable W] [Nonempty W]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (hn : 0 < n)\n (g : W → Z → ℝ) (C : ℝ)\n (hg : ∀ w, Integrable (g w) D) (hC : ∀ w z, |g w z| ≤ C) :\n (∫ S : Fin n → Z, (⨆ w : W,\n ((∫ z, g w z ∂D) - (1 / (n : ℝ)) * ∑ i, g w (S i)))\n ∂(Measure.pi (fun _ : Fin n => D))) ≤\n ∫ ST : (Fin n → Z) × (Fin n → Z), (⨆ w : W,\n ((1 / (n : ℝ)) * ∑ i, g w (ST.2 i) -\n (1 / (n : ℝ)) * ∑ i, g w (ST.1 i)))\n ∂((Measure.pi (fun _ : Fin n => D)).prod\n (Measure.pi (fun _ : Fin n => D))) := by\n let μn : Measure (Fin n → Z) := Measure.pi (fun _ : Fin n => D)\n let E : W → (Fin n → Z) → ℝ := fun w S =>\n (1 / (n : ℝ)) * ∑ i, g w (S i)\n let m : W → ℝ := fun w => ∫ z, g w z ∂D\n let dev : (Fin n → Z) → ℝ := fun S => ⨆ w : W, m w - E w S\n let pairDev : ((Fin n → Z) × (Fin n → Z)) → ℝ := fun ST =>\n ⨆ w : W, E w ST.2 - E w ST.1\n have hm (w : W) : |m w| ≤ C := by\n simpa only [m, Real.norm_eq_abs, probReal_univ, mul_one] using\n (norm_integral_le_of_norm_le_const (μ := D)\n (f := g w) (C := C)\n (ae_of_all D fun z => by simpa only [Real.norm_eq_abs] using hC w z))\n have hEmeas (w : W) : AEMeasurable (E w) μn := by\n exact aemeasurable_empirical D n (g w) (hg w).aestronglyMeasurable\n have hE (w : W) (S : Fin n → Z) : |E w S| ≤ C :=\n abs_empirical_le n hn (g w) C (hC w) S\n have hdevInt : Integrable dev μn := by\n apply integrable_ciSup_of_abs_le μn (fun w S => m w - E w S) (2 * C)\n · intro w\n exact AEMeasurable.const_sub (hEmeas w) (m w)\n · intro w S\n exact (abs_sub _ _).trans (by linarith [hm w, hE w S])\n have hpairMeas (w : W) :\n AEMeasurable (fun ST : (Fin n → Z) × (Fin n → Z) => E w ST.2 - E w ST.1)\n (μn.prod μn) := by\n exact (hEmeas w).comp_quasiMeasurePreserving\n (measurePreserving_snd (μ := μn) (ν := μn)).quasiMeasurePreserving |>.sub <|\n (hEmeas w).comp_quasiMeasurePreserving\n (measurePreserving_fst (μ := μn) (ν := μn)).quasiMeasurePreserving\n have hpairInt : Integrable pairDev (μn.prod μn) := by\n apply integrable_ciSup_of_abs_le (μn.prod μn)\n (fun w ST => E w ST.2 - E w ST.1) (2 * C) hpairMeas\n intro w ST\n exact (abs_sub _ _).trans (by linarith [hE w ST.2, hE w ST.1])\n have hinnerInt (S : Fin n → Z) :\n Integrable (fun T => pairDev (S, T)) μn := by\n apply integrable_ciSup_of_abs_le μn (fun w T => E w T - E w S) (2 * C)\n · intro w\n exact (hEmeas w).sub aemeasurable_const\n · intro w T\n exact (abs_sub _ _).trans (by linarith [hE w T, hE w S])\n have hpoint (S : Fin n → Z) : dev S ≤ ∫ T, pairDev (S, T) ∂μn := by\n apply ciSup_le\n intro w\n calc\n m w - E w S = ∫ T, E w T - E w S ∂μn := by\n rw [integral_sub]\n · rw [show (∫ T, E w T ∂μn) = m w by\n exact integral_empirical_eq D n hn (g w) (hg w)]\n simp [μn]\n · exact Integrable.of_bound\n (aemeasurable_empirical D n (g w) (hg w).aestronglyMeasurable).aestronglyMeasurable C\n (ae_of_all μn fun T => by simpa only [Real.norm_eq_abs] using hE w T)\n · exact integrable_const _\n _ ≤ ∫ T, pairDev (S, T) ∂μn := by\n apply integral_mono\n · exact Integrable.of_bound ((hEmeas w).sub aemeasurable_const).aestronglyMeasurable\n (2 * C) (ae_of_all μn fun T => by\n rw [Real.norm_eq_abs]\n exact (abs_sub _ _).trans (by linarith [hE w T, hE w S]))\n · exact hinnerInt S\n · intro T\n apply le_ciSup (c := w)\n exact ⟨2 * C, by\n rintro _ ⟨v, rfl⟩\n exact (le_abs_self _).trans\n ((abs_sub _ _).trans (by linarith [hE v T, hE v S]))⟩\n change (∫ S, dev S ∂μn) ≤ ∫ ST, pairDev ST ∂(μn.prod μn)\n rw [integral_prod pairDev hpairInt]\n exact integral_mono hdevInt hpairInt.integral_prod_left hpoint\n\ntheorem signed_empirical_abs_le {Z : Type*} (n : ℕ) (hn : 0 < n)\n (g : Z → ℝ) (C : ℝ) (hg : ∀ z, |g z| ≤ C)\n (σ : Fin n → Bool) (S : Fin n → Z) :\n |(1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * g (S i)| ≤ C := by\n rw [abs_mul, abs_of_nonneg (by positivity : 0 ≤ (1 / (n : ℝ)))]\n calc\n (1 / (n : ℝ)) * |∑ i, (if σ i then (1 : ℝ) else -1) * g (S i)| ≤\n (1 / (n : ℝ)) * ∑ i, |(if σ i then (1 : ℝ) else -1) * g (S i)| := by\n gcongr\n exact Finset.abs_sum_le_sum_abs _ _\n _ ≤ (1 / (n : ℝ)) * ∑ _i : Fin n, C := by\n gcongr with i hi\n simpa only [abs_mul, abs_ite, abs_one, abs_neg, ite_self, one_mul] using hg (S i)\n _ = C := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n\ntheorem integrable_rademacher {Z W : Type*} [MeasurableSpace Z]\n [Countable W] [Nonempty W]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (hn : 0 < n)\n (g : W → Z → ℝ) (C : ℝ)\n (hg : ∀ w, AEStronglyMeasurable (g w) D) (hC : ∀ w z, |g w z| ≤ C) :\n Integrable (fun S : Fin n → Z =>\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i)))\n (Measure.pi (fun _ : Fin n => D)) := by\n have hi (σ : Fin n → Bool) : Integrable (fun S : Fin n → Z => ⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i))\n (Measure.pi (fun _ : Fin n => D)) := by\n apply integrable_ciSup_of_abs_le (Measure.pi (fun _ : Fin n => D))\n (fun w S => (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * g w (S i)) C\n · intro w\n exact aemeasurable_signed_empirical D n (g w) (hg w) σ\n · intro w S\n exact signed_empirical_abs_le n hn (g w) C (hC w) σ S\n apply Integrable.const_mul\n exact integrable_finset_sum Finset.univ fun σ _ => hi σ\n\nprivate lemma randomized_diff_le {Z W : Type*} [Countable W] [Nonempty W]\n (n : ℕ) (hn : 0 < n) (g : W → Z → ℝ) (C : ℝ)\n (hC : ∀ w z, |g w z| ≤ C) (S T : Fin n → Z) :\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (g w (T i) - g w (S i))) ≤\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (T i)) +\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i)) := by\n let e : (Fin n → Bool) ≃ (Fin n → Bool) :=\n Equiv.piCongrRight (fun _ : Fin n => Equiv.boolNot)\n have hsign (σ : Fin n → Bool) (i : Fin n) :\n (if σ i then -(1 : ℝ) else 1) =\n (if e σ i then (1 : ℝ) else -1) := by\n cases h : σ i <;> simp [e, Equiv.piCongrRight_apply, h]\n have hterm (σ : Fin n → Bool) :\n (⨆ w : W, (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (g w (T i) - g w (S i))) ≤\n (⨆ w : W, (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * g w (T i)) +\n (⨆ w : W, (1 / (n : ℝ)) * ∑ i,\n (if e σ i then (1 : ℝ) else -1) * g w (S i)) := by\n apply ciSup_le\n intro w\n have hbT : BddAbove (Set.range fun v : W =>\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g v (T i)) := by\n refine ⟨C, ?_⟩\n rintro _ ⟨v, rfl⟩\n exact (le_abs_self _).trans (signed_empirical_abs_le n hn (g v) C (hC v) σ T)\n have hbS : BddAbove (Set.range fun v : W =>\n (1 / (n : ℝ)) * ∑ i, (if e σ i then (1 : ℝ) else -1) * g v (S i)) := by\n refine ⟨C, ?_⟩\n rintro _ ⟨v, rfl⟩\n exact (le_abs_self _).trans (signed_empirical_abs_le n hn (g v) C (hC v) (e σ) S)\n calc\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (g w (T i) - g w (S i)) =\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * g w (T i) +\n (1 / (n : ℝ)) * ∑ i,\n (if e σ i then (1 : ℝ) else -1) * g w (S i) := by\n rw [← mul_add, ← Finset.sum_add_distrib]\n congr 2\n funext i\n rw [← hsign σ i]\n by_cases h : σ i <;> simp [h] <;> ring\n _ ≤ _ := add_le_add (le_ciSup hbT w) (le_ciSup hbS w)\n calc\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (g w (T i) - g w (S i))) ≤\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool,\n ((⨆ w : W, (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * g w (T i)) +\n (⨆ w : W, (1 / (n : ℝ)) * ∑ i,\n (if e σ i then (1 : ℝ) else -1) * g w (S i))) := by\n apply mul_le_mul_of_nonneg_left\n · exact Finset.sum_le_sum fun σ _ => hterm σ\n · positivity\n _ = (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (T i)) +\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i)) := by\n rw [Finset.sum_add_distrib, mul_add]\n have heq :\n (∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if e σ i then (1 : ℝ) else -1) * g w (S i))) =\n ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i)) := by\n let F : (Fin n → Bool) → ℝ := fun σ => ⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i)\n simpa only [F] using e.sum_comp F\n rw [heq]\n\nprivate def coordinateSwap {Z : Type*} [MeasurableSpace Z] {n : ℕ}\n (σ : Fin n → Bool) : (Fin n → Z × Z) ≃ᵐ (Fin n → Z × Z) :=\n MeasurableEquiv.piCongrRight (fun i =>\n if σ i then MeasurableEquiv.refl (Z × Z) else MeasurableEquiv.prodComm)\n\nprivate lemma coordinateSwap_apply {Z : Type*} [MeasurableSpace Z] {n : ℕ}\n (σ : Fin n → Bool) (p : Fin n → Z × Z) (i : Fin n) :\n coordinateSwap σ p i = if σ i then p i else (p i).swap := by\n change (Equiv.piCongrRight (fun i =>\n (if σ i then MeasurableEquiv.refl (Z × Z) else MeasurableEquiv.prodComm).toEquiv) p) i = _\n rw [Equiv.piCongrRight_apply]\n by_cases h : σ i = true\n · simp [Pi.map_apply, h]\n · simp only [Pi.map_apply, h, if_false]\n change Prod.swap (p i) = (p i).swap\n rfl\n\nprivate lemma coordinateSwap_measurePreserving {Z : Type*} [MeasurableSpace Z]\n (D : Measure Z) [IsProbabilityMeasure D] {n : ℕ} (σ : Fin n → Bool) :\n MeasurePreserving (coordinateSwap σ)\n (Measure.pi (fun _ : Fin n => D.prod D))\n (Measure.pi (fun _ : Fin n => D.prod D)) := by\n have h : MeasurePreserving (fun p : Fin n → Z × Z => fun i =>\n if σ i then p i else (p i).swap)\n (Measure.pi (fun _ : Fin n => D.prod D))\n (Measure.pi (fun _ : Fin n => D.prod D)) :=\n measurePreserving_pi (fun _ : Fin n => D.prod D)\n (fun _ : Fin n => D.prod D)\n (f := fun i p => if σ i then p else p.swap) (fun i => by\n by_cases hi : σ i = true\n · simpa [hi] using (MeasurePreserving.id (D.prod D))\n · simpa [hi] using (Measure.measurePreserving_swap (μ := D) (ν := D)))\n convert h using 1\n funext p i\n exact coordinateSwap_apply σ p i\n\nprivate lemma randomization_integral {Z W : Type*} [MeasurableSpace Z]\n [Countable W] [Nonempty W]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (hn : 0 < n)\n (g : W → Z → ℝ) (C : ℝ)\n (hg : ∀ w, Integrable (g w) D) (hC : ∀ w z, |g w z| ≤ C) :\n (∫ p : Fin n → Z × Z, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (g w (p i).2 - g w (p i).1))\n ∂(Measure.pi (fun _ : Fin n => D.prod D))) =\n ∫ p : Fin n → Z × Z,\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (g w (p i).2 - g w (p i).1))\n ∂(Measure.pi (fun _ : Fin n => D.prod D)) := by\n let ν : Measure (Fin n → Z × Z) := Measure.pi (fun _ : Fin n => D.prod D)\n let base : (Fin n → Z × Z) → ℝ := fun p => ⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (g w (p i).2 - g w (p i).1)\n let signed : (Fin n → Bool) → (Fin n → Z × Z) → ℝ := fun σ p => ⨆ w : W,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (g w (p i).2 - g w (p i).1)\n have hpairAES (w : W) : AEStronglyMeasurable\n (fun z : Z × Z => g w z.2 - g w z.1) (D.prod D) :=\n (hg w).aestronglyMeasurable.comp_quasiMeasurePreserving\n (measurePreserving_snd (μ := D) (ν := D)).quasiMeasurePreserving |>.sub <|\n (hg w).aestronglyMeasurable.comp_quasiMeasurePreserving\n (measurePreserving_fst (μ := D) (ν := D)).quasiMeasurePreserving\n have hpairBound (w : W) (z : Z × Z) : |g w z.2 - g w z.1| ≤ 2 * C :=\n (abs_sub _ _).trans (by linarith [hC w z.2, hC w z.1])\n have hbaseInt : Integrable base ν := by\n apply integrable_ciSup_of_abs_le ν (fun w p =>\n (1 / (n : ℝ)) * ∑ i, (g w (p i).2 - g w (p i).1)) (2 * C)\n · intro w\n exact aemeasurable_empirical (D.prod D) n\n (fun z : Z × Z => g w z.2 - g w z.1) (hpairAES w)\n · intro w p\n exact abs_empirical_le n hn (fun z : Z × Z => g w z.2 - g w z.1)\n (2 * C) (hpairBound w) p\n have hswap (σ : Fin n → Bool) (p : Fin n → Z × Z) :\n base (coordinateSwap σ p) = signed σ p := by\n apply le_antisymm\n · apply ciSup_mono\n · refine ⟨2 * C, ?_⟩\n rintro _ ⟨w, rfl⟩\n exact (le_abs_self _).trans\n (signed_empirical_abs_le n hn\n (fun z : Z × Z => g w z.2 - g w z.1) (2 * C) (hpairBound w) σ p)\n · intro w\n apply le_of_eq\n congr 2\n funext i\n rw [coordinateSwap_apply]\n by_cases hi : σ i = true <;> simp [hi] <;> ring\n · apply ciSup_mono\n · refine ⟨2 * C, ?_⟩\n rintro _ ⟨w, rfl⟩\n exact (le_abs_self _).trans\n (abs_empirical_le n hn\n (fun z : Z × Z => g w z.2 - g w z.1) (2 * C) (hpairBound w)\n (coordinateSwap σ p))\n · intro w\n apply ge_of_eq\n congr 2\n funext i\n rw [coordinateSwap_apply]\n by_cases hi : σ i = true <;> simp [hi] <;> ring\n have hsignedInt (σ : Fin n → Bool) : Integrable (signed σ) ν := by\n have hc : Integrable (base ∘ coordinateSwap σ) ν :=\n ((coordinateSwap_measurePreserving D σ).integrable_comp_emb\n (coordinateSwap σ).measurableEmbedding).2 hbaseInt\n exact hc.congr (ae_of_all ν fun p => hswap σ p)\n have hint (σ : Fin n → Bool) : (∫ p, base p ∂ν) = ∫ p, signed σ p ∂ν := by\n calc\n (∫ p, base p ∂ν) = ∫ p, base (coordinateSwap σ p) ∂ν :=\n ((coordinateSwap_measurePreserving D σ).integral_comp' base).symm\n _ = ∫ p, signed σ p ∂ν := integral_congr_ae (ae_of_all ν fun p => hswap σ p)\n change (∫ p, base p ∂ν) = ∫ p, (1 / (2 ^ n : ℝ)) * ∑ σ, signed σ p ∂ν\n calc\n (∫ p, base p ∂ν) =\n (1 / (2 ^ n : ℝ)) * ∑ _σ : Fin n → Bool, (∫ p, base p ∂ν) := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_bool,\n Fintype.card_fin, nsmul_eq_mul]\n field_simp\n norm_num [Nat.cast_pow]\n _ = (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (∫ p, signed σ p ∂ν) := by\n congr 1\n exact Finset.sum_congr rfl fun σ _ => hint σ\n _ = ∫ p, (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, signed σ p ∂ν := by\n rw [integral_const_mul, integral_finset_sum]\n intro σ _\n exact hsignedInt σ\n\ntheorem symmetrization {Z W : Type*} [MeasurableSpace Z]\n [Countable W] [Nonempty W]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (hn : 0 < n)\n (g : W → Z → ℝ) (C : ℝ)\n (hg : ∀ w, Integrable (g w) D) (hC : ∀ w z, |g w z| ≤ C) :\n (∫ S : Fin n → Z, (⨆ w : W,\n ((∫ z, g w z ∂D) - (1 / (n : ℝ)) * ∑ i, g w (S i)))\n ∂(Measure.pi (fun _ : Fin n => D))) ≤\n 2 * ∫ S : Fin n → Z,\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i))\n ∂(Measure.pi (fun _ : Fin n => D)) := by\n let μn : Measure (Fin n → Z) := Measure.pi (fun _ : Fin n => D)\n let ν : Measure (Fin n → Z × Z) := Measure.pi (fun _ : Fin n => D.prod D)\n let rad : (Fin n → Z) → ℝ := fun S =>\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * g w (S i))\n let pairBase : (Fin n → Z × Z) → ℝ := fun p => ⨆ w : W,\n (1 / (n : ℝ)) * ∑ i, (g w (p i).2 - g w (p i).1)\n let pairRand : (Fin n → Z × Z) → ℝ := fun p =>\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : W,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (g w (p i).2 - g w (p i).1))\n have hghost := symmetrization_ghost D n hn g C hg hC\n have hpairAES (w : W) : AEStronglyMeasurable\n (fun z : Z × Z => g w z.2 - g w z.1) (D.prod D) :=\n (hg w).aestronglyMeasurable.comp_quasiMeasurePreserving\n (measurePreserving_snd (μ := D) (ν := D)).quasiMeasurePreserving |>.sub <|\n (hg w).aestronglyMeasurable.comp_quasiMeasurePreserving\n (measurePreserving_fst (μ := D) (ν := D)).quasiMeasurePreserving\n have hpairBound (w : W) (z : Z × Z) : |g w z.2 - g w z.1| ≤ 2 * C :=\n (abs_sub _ _).trans (by linarith [hC w z.2, hC w z.1])\n have hpairRandInt : Integrable pairRand ν := by\n exact integrable_rademacher (D.prod D) n hn\n (fun (w : W) (z : Z × Z) => g w z.2 - g w z.1) (2 * C) hpairAES hpairBound\n have hradInt : Integrable rad μn := by\n exact integrable_rademacher D n hn g C (fun w => (hg w).aestronglyMeasurable) hC\n have hfstMP : MeasurePreserving (fun p : Fin n → Z × Z => fun i => (p i).1) ν μn := by\n exact measurePreserving_pi (fun _ : Fin n => D.prod D) (fun _ : Fin n => D)\n (fun _ => measurePreserving_fst)\n have hsndMP : MeasurePreserving (fun p : Fin n → Z × Z => fun i => (p i).2) ν μn := by\n exact measurePreserving_pi (fun _ : Fin n => D.prod D) (fun _ : Fin n => D)\n (fun _ => measurePreserving_snd)\n have hradPairInt : Integrable\n (fun p : Fin n → Z × Z => rad (fun i => (p i).2) + rad (fun i => (p i).1)) ν :=\n ((hsndMP.integrable_comp hradInt.aestronglyMeasurable).2 hradInt).add\n ((hfstMP.integrable_comp hradInt.aestronglyMeasurable).2 hradInt)\n have hpairLe : (∫ p, pairRand p ∂ν) ≤\n ∫ p, rad (fun i => (p i).2) + rad (fun i => (p i).1) ∂ν := by\n apply integral_mono hpairRandInt hradPairInt\n intro p\n exact randomized_diff_le n hn g C hC (fun i => (p i).1) (fun i => (p i).2)\n have hprodPair :\n (∫ ST : (Fin n → Z) × (Fin n → Z), (⨆ w : W,\n ((1 / (n : ℝ)) * ∑ i, g w (ST.2 i) -\n (1 / (n : ℝ)) * ∑ i, g w (ST.1 i))) ∂(μn.prod μn)) =\n ∫ p, pairBase p ∂ν := by\n let e := MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n)\n have he := measurePreserving_arrowProdEquivProdArrow Z Z (Fin n)\n (fun _ : Fin n => D) (fun _ : Fin n => D)\n have hi := he.integral_comp' (fun ST : (Fin n → Z) × (Fin n → Z) =>\n ⨆ w : W, (1 / (n : ℝ)) * ∑ i, g w (ST.2 i) -\n (1 / (n : ℝ)) * ∑ i, g w (ST.1 i))\n symm\n convert hi using 1\n · congr 1\n funext p\n dsimp [pairBase]\n congr 1\n funext w\n change (1 / (n : ℝ)) * ∑ i, (g w (p i).2 - g w (p i).1) =\n (1 / (n : ℝ)) * ∑ i, g w (p i).2 -\n (1 / (n : ℝ)) * ∑ i, g w (p i).1\n rw [← mul_sub]\n rw [← Finset.sum_sub_distrib]\n have hpairRandom : (∫ p, pairBase p ∂ν) = ∫ p, pairRand p ∂ν :=\n randomization_integral D n hn g C hg hC\n have hradPairIntegral :\n (∫ p, rad (fun i => (p i).2) + rad (fun i => (p i).1) ∂ν) =\n 2 * ∫ S, rad S ∂μn := by\n let e := MeasurableEquiv.arrowProdEquivProdArrow Z Z (Fin n)\n have he := measurePreserving_arrowProdEquivProdArrow Z Z (Fin n)\n (fun _ : Fin n => D) (fun _ : Fin n => D)\n calc\n (∫ p, rad (fun i => (p i).2) + rad (fun i => (p i).1) ∂ν) =\n ∫ ST : (Fin n → Z) × (Fin n → Z), rad ST.2 + rad ST.1 ∂(μn.prod μn) := by\n have hi := he.integral_comp' (fun ST : (Fin n → Z) × (Fin n → Z) =>\n rad ST.2 + rad ST.1)\n convert hi using 1\n _ = ∫ S : Fin n → Z, ∫ T : Fin n → Z, rad T + rad S ∂μn ∂μn := by\n rw [integral_prod]\n exact ((measurePreserving_snd.integrable_comp hradInt.aestronglyMeasurable).2 hradInt).add\n ((measurePreserving_fst.integrable_comp hradInt.aestronglyMeasurable).2 hradInt)\n _ = 2 * ∫ S, rad S ∂μn := by\n simp_rw [integral_add hradInt (integrable_const _), integral_const, probReal_univ,\n one_smul]\n rw [integral_add (integrable_const _) hradInt, integral_const, probReal_univ, one_smul]\n ring\n change (∫ S, (⨆ w : W,\n ((∫ z, g w z ∂D) - (1 / (n : ℝ)) * ∑ i, g w (S i))) ∂μn) ≤\n 2 * ∫ S, rad S ∂μn\n calc\n _ ≤ ∫ ST : (Fin n → Z) × (Fin n → Z), (⨆ w : W,\n ((1 / (n : ℝ)) * ∑ i, g w (ST.2 i) -\n (1 / (n : ℝ)) * ∑ i, g w (ST.1 i))) ∂(μn.prod μn) := hghost\n _ = ∫ p, pairBase p ∂ν := hprodPair\n _ = ∫ p, pairRand p ∂ν := hpairRandom\n _ ≤ ∫ p, rad (fun i => (p i).2) + rad (fun i => (p i).1) ∂ν := hpairLe\n _ = 2 * ∫ S, rad S ∂μn := hradPairIntegral\n\n\nend Test\n\nnamespace Local\n\n\nnoncomputable def empRad {Z W : Type*} (n : ℕ) (phi : W → Z → ℝ)\n (P : Set W) (S : Fin n → Z) : ℝ :=\n (1 / (2 ^ n : ℝ)) * ∑ sigma : Fin n → Bool,\n ⨆ w : P, (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i)\n\nprivate lemma sum_sign_succ (n : ℕ) (F : (Fin (n + 1) → Bool) → ℝ) :\n (∑ sigma, F sigma) = ∑ tau : Fin n → Bool,\n (F (Fin.cons true tau) + F (Fin.cons false tau)) := by\n calc\n (∑ sigma, F sigma) = ∑ p : Bool × (Fin n → Bool), F (Fin.cons p.1 p.2) := by\n simpa only [Fin.consEquiv_apply] using\n ((Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp F).symm\n _ = ∑ b : Bool, ∑ tau : Fin n → Bool, F (Fin.cons b tau) := by\n rw [Fintype.sum_prod_type]\n _ = ∑ tau : Fin n → Bool, ∑ b : Bool, F (Fin.cons b tau) := by\n rw [Finset.sum_comm]\n _ = _ := by simp only [Fintype.sum_bool]\n\nprivate lemma sum_rademacher_linear_zero (n : ℕ) (x : Fin n → ℝ) :\n ∑ sigma : Fin n → Bool,\n ∑ i, (if sigma i then (1 : ℝ) else -1) * x i = 0 := by\n induction n with\n | zero => simp\n | succ n ih =>\n rw [sum_sign_succ]\n simp only [Fin.sum_univ_succ, Fin.cons_zero, if_true, one_mul,\n Fin.cons_succ, if_false, neg_one_mul]\n simp only [Bool.false_eq_true, if_false, neg_one_mul]\n simp_rw [show ∀ (a t : ℝ), a + t + (-a + t) = 2 * t by intros; ring]\n rw [← Finset.mul_sum]\n rw [ih (fun i => x i.succ)]\n simp\n\ntheorem empRad_nonneg {Z W : Type*} (n : ℕ) (phi : W → Z → ℝ)\n (M : ℝ) (hM : 0 ≤ M) (hbound : ∀ w z, |phi w z| ≤ M)\n (P : Set W) (S : Fin n → Z) : 0 ≤ empRad n phi P S := by\n classical\n by_cases hP : P.Nonempty\n · let w0 : P := ⟨hP.choose, hP.choose_spec⟩\n have hb (sigma : Fin n → Bool) : BddAbove (Set.range fun w : P =>\n (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i)) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨w, rfl⟩\n by_cases hn : n = 0\n · subst n\n simpa using hM\n · have hnpos : 0 < (n : ℝ) := by exact_mod_cast Nat.pos_of_ne_zero hn\n calc\n (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i) ≤\n |(1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i)| := le_abs_self _\n _ ≤ (1 / (n : ℝ)) * ∑ i,\n |(if sigma i then (1 : ℝ) else -1) * phi w.1 (S i)| := by\n rw [abs_mul, abs_of_nonneg (by positivity : 0 ≤ (1 / (n : ℝ)))]\n gcongr\n exact Finset.abs_sum_le_sum_abs _ _\n _ ≤ (1 / (n : ℝ)) * ∑ _i : Fin n, M := by\n gcongr with i hi\n simpa only [abs_mul, abs_ite, abs_one, abs_neg, ite_self, one_mul] using\n hbound w.1 (S i)\n _ = M := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n have hterm (sigma : Fin n → Bool) :\n (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w0.1 (S i) ≤\n ⨆ w : P, (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i) :=\n le_ciSup (hb sigma) w0\n have hsum :\n ∑ sigma : Fin n → Bool,\n (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w0.1 (S i) ≤\n ∑ sigma : Fin n → Bool,\n ⨆ w : P, (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i) := by\n exact Finset.sum_le_sum fun sigma _ => hterm sigma\n rw [empRad]\n apply mul_nonneg (by positivity)\n calc\n 0 = ∑ sigma : Fin n → Bool,\n (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w0.1 (S i) := by\n calc\n 0 = (1 / (n : ℝ)) * 0 := (mul_zero _).symm\n _ = (1 / (n : ℝ)) * ∑ sigma : Fin n → Bool,\n ∑ i, (if sigma i then (1 : ℝ) else -1) * phi w0.1 (S i) := by\n rw [sum_rademacher_linear_zero]\n _ = _ := by rw [Finset.mul_sum]\n _ ≤ _ := hsum\n · haveI : IsEmpty P := ⟨fun w => hP ⟨w.1, w.2⟩⟩\n simp [empRad, iSup_of_empty', csSup_empty]\n\ntheorem empRad_le_bound {Z W : Type*} (n : ℕ) (hn : 0 < n)\n (phi : W → Z → ℝ) (M : ℝ) (hM : 0 ≤ M)\n (hbound : ∀ w z, |phi w z| ≤ M) (P : Set W) (S : Fin n → Z) :\n empRad n phi P S ≤ M := by\n classical\n by_cases hP : P.Nonempty\n · letI : Nonempty P := hP.to_subtype\n have hsingle (sigma : Fin n → Bool) (w : P) :\n (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i) ≤ M := by\n apply (le_abs_self _).trans\n rw [abs_mul, abs_of_nonneg (by positivity : 0 ≤ (1 / (n : ℝ)))]\n calc\n (1 / (n : ℝ)) * |∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i)| ≤\n (1 / (n : ℝ)) * ∑ i,\n |(if sigma i then (1 : ℝ) else -1) * phi w.1 (S i)| := by\n gcongr\n exact Finset.abs_sum_le_sum_abs _ _\n _ ≤ (1 / (n : ℝ)) * ∑ _i : Fin n, M := by\n gcongr with i hi\n simpa only [abs_mul, abs_ite, abs_one, abs_neg, ite_self, one_mul] using\n hbound w.1 (S i)\n _ = M := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n rw [empRad]\n calc\n (1 / (2 ^ n : ℝ)) * ∑ sigma : Fin n → Bool,\n (⨆ w : P, (1 / (n : ℝ)) * ∑ i,\n (if sigma i then (1 : ℝ) else -1) * phi w.1 (S i)) ≤\n (1 / (2 ^ n : ℝ)) * ∑ _sigma : Fin n → Bool, M := by\n gcongr with sigma hsigma\n exact ciSup_le (hsingle sigma)\n _ = M := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fun,\n Fintype.card_bool, Fintype.card_fin, nsmul_eq_mul]\n norm_num\n · haveI : IsEmpty P := ⟨fun w => hP ⟨w.1, w.2⟩⟩\n simp [empRad, iSup_of_empty', csSup_empty, hM]\n\ntheorem r_nonneg_of_rademacher {Z W : Type*} [MeasurableSpace Z]\n (D : Measure Z) [IsProbabilityMeasure D] (n : ℕ) (hn : 0 < n)\n (phi : W → Z → ℝ) (M : ℝ) (hM : 0 ≤ M)\n (hbound : ∀ w z, |phi w z| ≤ M) (r : ℝ → ℝ)\n (hrCont : ContinuousOn r (Ici 0))\n (hRad : ∀ b > (0 : ℝ),\n (⨆ S : Fin n → Z,\n empRad n phi {w | (1 / (n : ℝ)) * ∑ i, (phi w (S i)) ^ 2 ≤ b} S) ≤ r b) :\n ∀ b, 0 ≤ b → 0 ≤ r b := by\n have hpos (b : ℝ) (hb : 0 < b) : 0 ≤ r b := by\n let P : (Fin n → Z) → Set W := fun S =>\n {w | (1 / (n : ℝ)) * ∑ i, (phi w (S i)) ^ 2 ≤ b}\n have houter : BddAbove (Set.range fun S : Fin n → Z => empRad n phi (P S) S) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨S, rfl⟩\n exact empRad_le_bound n hn phi M hM hbound (P S) S\n have hZ : Nonempty Z := by\n by_contra hZ\n letI : IsEmpty Z := not_nonempty_iff.mp hZ\n have hu : (Set.univ : Set Z) = ∅ := Subsingleton.elim _ _\n have hp : D Set.univ = 1 := measure_univ\n rw [hu, measure_empty] at hp\n exact zero_ne_one hp\n letI : Nonempty Z := hZ\n let S0 : Fin n → Z := Classical.choice inferInstance\n calc\n 0 ≤ empRad n phi (P S0) S0 := empRad_nonneg n phi M hM hbound (P S0) S0\n _ ≤ ⨆ S : Fin n → Z, empRad n phi (P S) S := le_ciSup houter S0\n _ ≤ r b := by simpa [P] using hRad b hb\n intro b hb\n rcases hb.eq_or_lt with rfl | hb\n · apply ContinuousWithinAt.closure_le (s := Ioi (0 : ℝ))\n (by rw [closure_Ioi]; exact left_mem_Ici)\n continuousWithinAt_const\n ((hrCont 0 left_mem_Ici).mono Ioi_subset_Ici_self)\n exact fun y hy => hpos y hy\n · exact hpos b hb\n\ntheorem concave_nonneg_monotone\n (f : ℝ → ℝ) (hf : ConcaveOn ℝ (Ici 0) f)\n (hnonneg : ∀ x, 0 ≤ x → 0 ≤ f x) : MonotoneOn f (Ici 0) := by\n intro x hx y hy hxy\n by_contra hnot\n have hyx : f y < f x := lt_of_not_ge hnot\n have hxy' : x < y := lt_of_le_of_ne hxy (fun h => by subst y; exact hyx.false)\n let z : ℝ := y + (f y + 1) * (y - x) / (f x - f y)\n have hden : 0 < f x - f y := sub_pos.mpr hyx\n have hfy : 0 ≤ f y := hnonneg y hy\n have hyz : y < z := by\n dsimp [z]\n have hfyp : 0 < f y + 1 := by linarith\n have hyxp : 0 < y - x := sub_pos.mpr hxy'\n have : 0 < (f y + 1) * (y - x) / (f x - f y) :=\n div_pos (mul_pos hfyp hyxp) hden\n linarith\n have hz : z ∈ Ici (0 : ℝ) := le_trans hy hyz.le\n have hs := hf.slope_anti_adjacent hx hz hxy' hyz\n have hzy : 0 < z - y := sub_pos.mpr hyz\n have hyxd : 0 < y - x := sub_pos.mpr hxy'\n have hs' : (f z - f y) * (y - x) ≤ (f y - f x) * (z - y) := by\n rw [div_le_div_iff₀ hzy hyxd] at hs\n exact hs\n have hzform : (f x - f y) * (z - y) = (f y + 1) * (y - x) := by\n dsimp [z]\n field_simp\n <;> ring\n have : f z ≤ -1 := by\n nlinarith\n linarith [hnonneg z hz]\n\n\nend Local\n\nnoncomputable def popVal {𝒵 Ω : Type*} [MeasurableSpace 𝒵]\n (D : Measure 𝒵) (φ : Ω → 𝒵 → ℝ) (w : Ω) : ℝ :=\n ∫ z, φ w z ∂D\n\nnoncomputable def empMean {𝒵 : Type*} (n : ℕ) (g : 𝒵 → ℝ) (S : Fin n → 𝒵) : ℝ :=\n (1 / (n : ℝ)) * ∑ i, g (S i)\n\nnoncomputable def empRad {𝒵 Ω : Type*} (n : ℕ) (φ : Ω → 𝒵 → ℝ)\n (P : Set Ω) (S : Fin n → 𝒵) : ℝ :=\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool,\n ⨆ w : P, (1 / (n : ℝ)) * ∑ i, (if σ i then (1 : ℝ) else -1) * φ w.1 (S i)\n\nnoncomputable def unifComplexity {𝒵 Ω : Type*} [MeasurableSpace 𝒵]\n (n : ℕ) (D : Measure 𝒵) (φ : Ω → 𝒵 → ℝ) (P : Set Ω) : ℝ :=\n ∫ S, (⨆ w : P, (popVal D φ w.1 - empMean n (φ w.1) S))\n ∂(Measure.pi (fun _ : Fin n => D))\n\nnoncomputable def bZero (c₁ α : ℝ) (r : ℝ → ℝ) : ℝ :=\n sSup {b : ℝ | 0 < b ∧ b ≤ (4 * c₁ / α) * r b}\n\nprivate lemma concave_nonneg_monotone\n (f : ℝ → ℝ) (hf : ConcaveOn ℝ (Ici 0) f)\n (hnonneg : ∀ x, 0 ≤ x → 0 ≤ f x) : MonotoneOn f (Ici 0) := by\n intro x hx y hy hxy\n by_contra hnot\n have hyx : f y < f x := lt_of_not_ge hnot\n have hxy' : x < y := lt_of_le_of_ne hxy (fun h => by subst y; exact hyx.false)\n let z : ℝ := y + (f y + 1) * (y - x) / (f x - f y)\n have hden : 0 < f x - f y := sub_pos.mpr hyx\n have hfy : 0 ≤ f y := hnonneg y hy\n have hyz : y < z := by\n dsimp [z]\n have hfyp : 0 < f y + 1 := by linarith\n have hyxp : 0 < y - x := sub_pos.mpr hxy'\n have : 0 < (f y + 1) * (y - x) / (f x - f y) :=\n div_pos (mul_pos hfyp hyxp) hden\n linarith\n have hz : z ∈ Ici (0 : ℝ) := le_trans hy hyz.le\n have hs := hf.slope_anti_adjacent hx hz hxy' hyz\n have hzy : 0 < z - y := sub_pos.mpr hyz\n have hyxd : 0 < y - x := sub_pos.mpr hxy'\n have hs' : (f z - f y) * (y - x) ≤ (f y - f x) * (z - y) := by\n rw [div_le_div_iff₀ hzy hyxd] at hs\n exact hs\n have hzform : (f x - f y) * (z - y) = (f y + 1) * (y - x) := by\n dsimp [z]\n field_simp\n <;> ring\n have : f z ≤ -1 := by\n nlinarith\n linarith [hnonneg z hz]\n\ntheorem localized_bound\n {Z W : Type*} [MeasurableSpace Z] [Nonempty W] [Countable W]\n (D : Measure Z) [IsProbabilityMeasure D]\n (n : ℕ) (hn : 0 < n)\n (phi : W → Z → ℝ) (M c1 alpha : ℝ)\n (hM : 0 < M) (hc1 : 0 < c1) (halpha : 0 < alpha)\n (hInf : ⨅ w, popVal D phi w = 0)\n (hInt : ∀ w, Integrable (phi w) D)\n (hInt2 : ∀ w, Integrable (fun z => (phi w z) ^ 2) D)\n (hBound : ∀ w z, |phi w z| ≤ M)\n (hVar : ∀ w, (∫ z, (phi w z) ^ 2 ∂D) ≤ c1 * ∫ z, phi w z ∂D)\n (r : ℝ → ℝ)\n (hrCont : ContinuousOn r (Ici 0))\n (hrConcave : ConcaveOn ℝ (Ici 0) r)\n (hRad : ∀ b > (0 : ℝ),\n (⨆ S : Fin n → Z,\n empRad n phi {w | empMean n (fun z => (phi w z) ^ 2) S ≤ b} S) ≤ r b)\n (hαM : alpha ≤ (1 / 2) * c1 / M)\n (hbNE : {t : ℝ | 0 < t ∧ t ≤ (4 * c1 / alpha) * r t}.Nonempty)\n (hbBdd : BddAbove {t : ℝ | 0 < t ∧ t ≤ (4 * c1 / alpha) * r t})\n (hUnifInt2 : ∀ r' : ℝ,\n Integrable (fun S : Fin n → Z =>\n ⨆ w ∈ {w | popVal D phi w ≤ r' / alpha},\n empMean n (fun z => (phi w z) ^ 2) S)\n (Measure.pi (fun _ : Fin n => D)))\n (b : ℝ) (hb : bZero c1 alpha r < b) :\n unifComplexity n D phi {w | popVal D phi w ≤ b / (2 * c1)} ≤ 2 * r b := by\n classical\n let μn : Measure (Fin n → Z) := Measure.pi (fun _ : Fin n => D)\n let P : Set W := {w | popVal D phi w ≤ b / (2 * c1)}\n have hb0_mem_le (t : ℝ)\n (ht : t ∈ {t : ℝ | 0 < t ∧ t ≤ (4 * c1 / alpha) * r t}) :\n t ≤ bZero c1 alpha r := by\n exact le_csSup hbBdd ht\n obtain ⟨t0, ht0pos, ht0⟩ := hbNE\n have hbZeroPos : 0 < bZero c1 alpha r := lt_of_lt_of_le ht0pos (hb0_mem_le t0 ⟨ht0pos, ht0⟩)\n have hbpos : 0 < b := lt_trans hbZeroPos hb\n have hrnonneg : ∀ t, 0 ≤ t → 0 ≤ r t := by\n exact Local.r_nonneg_of_rademacher D n hn phi M hM.le hBound r hrCont (by\n intro t ht\n simpa only [Local.empRad, empRad, empMean] using hRad t ht)\n have hrmono : MonotoneOn r (Ici 0) :=\n Local.concave_nonneg_monotone r hrConcave hrnonneg\n have hbr_lt : (4 * c1 / alpha) * r b < b := by\n have hnot : ¬ b ≤ (4 * c1 / alpha) * r b := by\n intro hle\n exact (not_lt_of_ge (hb0_mem_le b ⟨hbpos, hle⟩)) hb\n exact lt_of_not_ge hnot\n have hcoef : 4 * M ≤ 2 * c1 / alpha := by\n have haM : alpha * M ≤ (1 / 2) * c1 := (le_div_iff₀ hM).mp hαM\n apply (le_div_iff₀ halpha).2\n nlinarith\n have hsmall : 4 * M * r b < b / 2 := by\n have hmul := mul_le_mul_of_nonneg_right hcoef (hrnonneg b hbpos.le)\n have hhalf : (2 * c1 / alpha) * r b < b / 2 := by\n calc\n (2 * c1 / alpha) * r b = ((4 * c1 / alpha) * r b) / 2 := by ring\n _ < b / 2 := div_lt_div_of_pos_right hbr_lt (by norm_num)\n exact lt_of_le_of_lt hmul hhalf\n have hpopAbs (w : W) : |popVal D phi w| ≤ M := by\n simpa only [popVal, Real.norm_eq_abs, probReal_univ, mul_one] using\n (norm_integral_le_of_norm_le_const (f := phi w) (C := M)\n (ae_of_all D fun z => by simpa only [Real.norm_eq_abs] using hBound w z))\n have hpopBdd : BddBelow (Set.range fun w : W => popVal D phi w) := by\n refine ⟨-M, ?_⟩\n rintro _ ⟨w, rfl⟩\n exact neg_le_of_abs_le (hpopAbs w)\n have hPne : P.Nonempty := by\n have hthreshold : (⨅ w : W, popVal D phi w) < b / (2 * c1) := by\n rw [hInf]\n positivity\n obtain ⟨w, hw⟩ := (ciInf_lt_iff hpopBdd).mp hthreshold\n exact ⟨w, hw.le⟩\n letI : Nonempty P := hPne.to_subtype\n let B : (Fin n → Z) → ℝ := fun S =>\n ⨆ w : W, ⨆ _h : w ∈ P, empMean n (fun z => (phi w z) ^ 2) S\n let R : (Fin n → Z) → ℝ := fun S => empRad n phi P S\n let R2 : (Fin n → Z) → ℝ := fun S =>\n (1 / (2 ^ n : ℝ)) * ∑ σ : Fin n → Bool, (⨆ w : P,\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * (-(phi w.1 (S i)) ^ 2))\n have hemp2_nonneg (w : W) (S : Fin n → Z) :\n 0 ≤ empMean n (fun z => (phi w z) ^ 2) S := by\n unfold empMean\n positivity\n have hemp2_upper (w : W) (S : Fin n → Z) :\n empMean n (fun z => (phi w z) ^ 2) S ≤ M ^ 2 := by\n unfold empMean\n calc\n (1 / (n : ℝ)) * ∑ i, phi w (S i) ^ 2 ≤\n (1 / (n : ℝ)) * ∑ _i : Fin n, M ^ 2 := by\n apply mul_le_mul_of_nonneg_left _ (by positivity)\n apply Finset.sum_le_sum\n intro i hi\n simpa only [sq_abs] using\n (pow_le_pow_left₀ (abs_nonneg (phi w (S i))) (hBound w (S i)) 2)\n _ = M ^ 2 := by\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n have hBnonneg (S : Fin n → Z) : 0 ≤ B S := by\n let w0 : P := Classical.choice inferInstance\n letI : Nonempty (w0.1 ∈ P) := ⟨w0.2⟩\n have hinnerBdd : BddAbove (Set.range fun _h : w0.1 ∈ P =>\n empMean n (fun z => (phi w0.1 z) ^ 2) S) := by\n exact ⟨M ^ 2, by rintro _ ⟨hw, rfl⟩; exact hemp2_upper w0.1 S⟩\n have houterBdd : BddAbove (Set.range fun w : W =>\n ⨆ _h : w ∈ P, empMean n (fun z => (phi w z) ^ 2) S) := by\n refine ⟨M ^ 2, ?_⟩\n rintro _ ⟨w, rfl⟩\n by_cases hw : w ∈ P\n · letI : Nonempty (w ∈ P) := ⟨hw⟩\n exact ciSup_le fun _hw => hemp2_upper w S\n · haveI : IsEmpty (w ∈ P) := ⟨fun h => hw h⟩\n simp [iSup_of_empty', sq_nonneg]\n dsimp [B]\n exact (hemp2_nonneg w0.1 S).trans\n (le_ciSup_of_le houterBdd w0.1\n (le_ciSup_of_le hinnerBdd w0.2 le_rfl))\n have hBupper (S : Fin n → Z) : B S ≤ M ^ 2 := by\n dsimp [B]\n apply ciSup_le\n intro w\n by_cases hw : w ∈ P\n · letI : Nonempty (w ∈ P) := ⟨hw⟩\n exact ciSup_le fun _hw => hemp2_upper w S\n · haveI : IsEmpty (w ∈ P) := ⟨fun h => hw h⟩\n simp [iSup_of_empty', sq_nonneg]\n have hBInt : Integrable B μn := by\n have heq : alpha * (b / (2 * c1)) / alpha = b / (2 * c1) := by\n field_simp\n simpa only [B, P, μn, Set.mem_setOf_eq, heq] using\n hUnifInt2 (alpha * (b / (2 * c1)))\n have hRInt : Integrable R μn := by\n simpa only [R, μn, empRad] using\n (Test.integrable_rademacher D n hn (fun w : P => phi w.1) M\n (fun w => (hInt w.1).aestronglyMeasurable)\n (fun w z => hBound w.1 z))\n have hR2Int : Integrable R2 μn := by\n simpa only [R2, μn] using\n (Test.integrable_rademacher D n hn\n (fun w : P => fun z => -(phi w.1 z) ^ 2) (M ^ 2)\n (fun w => (hInt2 w.1).neg.aestronglyMeasurable)\n (fun w z => by\n rw [abs_neg, abs_of_nonneg (sq_nonneg _)]\n simpa only [sq_abs] using\n (pow_le_pow_left₀ (abs_nonneg (phi w.1 z)) (hBound w.1 z) 2)))\n have hempRad_mono (A C : Set W) (hA : A.Nonempty) (hAC : A ⊆ C)\n (S : Fin n → Z) : empRad n phi A S ≤ empRad n phi C S := by\n letI : Nonempty A := hA.to_subtype\n have hC : C.Nonempty := hA.mono hAC\n letI : Nonempty C := hC.to_subtype\n have hbC (σ : Fin n → Bool) : BddAbove (Set.range fun w : C =>\n (1 / (n : ℝ)) * ∑ i,\n (if σ i then (1 : ℝ) else -1) * phi w.1 (S i)) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨w, rfl⟩\n exact (le_abs_self _).trans\n (Test.signed_empirical_abs_le n hn (phi w.1) M (hBound w.1) σ S)\n rw [empRad, empRad]\n apply mul_le_mul_of_nonneg_left _ (by positivity)\n apply Finset.sum_le_sum\n intro σ hσ\n apply ciSup_le\n intro w\n exact le_ciSup (hbC σ) (⟨w.1, hAC w.2⟩ : C)\n have hR_le_rB (S : Fin n → Z) : R S ≤ r (B S) := by\n apply ContinuousWithinAt.closure_le (s := Ioi (B S))\n (by rw [closure_Ioi]; exact left_mem_Ici)\n continuousWithinAt_const\n ((hrCont (B S) (hBnonneg S)).mono (by\n intro t ht\n exact le_trans (hBnonneg S) ht.le))\n intro t ht\n have htpos : 0 < t := lt_of_le_of_lt (hBnonneg S) ht\n let Q : Set W := {w | empMean n (fun z => (phi w z) ^ 2) S ≤ t}\n have hPQ : P ⊆ Q := by\n intro w hw\n dsimp [Q]\n exact (le_ciSup_of_le\n ⟨M ^ 2, by\n rintro _ ⟨v, rfl⟩\n by_cases hv : v ∈ P\n · letI : Nonempty (v ∈ P) := ⟨hv⟩\n exact ciSup_le fun _hv => hemp2_upper v S\n · haveI : IsEmpty (v ∈ P) := ⟨fun h => hv h⟩\n simp [iSup_of_empty', sq_nonneg]⟩\n w (by\n letI : Nonempty (w ∈ P) := ⟨hw⟩\n exact le_ciSup (by\n exact ⟨M ^ 2, by rintro _ ⟨_h, rfl⟩; exact hemp2_upper w S⟩) hw)).trans ht.le\n have houterBdd : BddAbove (Set.range fun T : Fin n → Z =>\n empRad n phi {w | empMean n (fun z => (phi w z) ^ 2) T ≤ t} T) := by\n refine ⟨M, ?_⟩\n rintro _ ⟨T, rfl⟩\n simpa only [empRad, Local.empRad] using\n (Local.empRad_le_bound n hn phi M hM.le hBound\n {w | empMean n (fun z => (phi w z) ^ 2) T ≤ t} T)\n calc\n R S ≤ empRad n phi Q S := by\n exact hempRad_mono P Q hPne hPQ S\n _ ≤ ⨆ T : Fin n → Z,\n empRad n phi {w | empMean n (fun z => (phi w z) ^ 2) T ≤ t} T := by\n exact le_ciSup houterBdd S\n _ ≤ r t := hRad t htpos\n have hrBInt : Integrable (fun S => r (B S)) μn := by\n let Bsub : (Fin n → Z) → Ici (0 : ℝ) := fun S => ⟨B S, hBnonneg S⟩\n have hBsubMeas : AEStronglyMeasurable Bsub μn := by\n have hm := hBInt.aestronglyMeasurable.aemeasurable.subtype_mk\n (s := Ici (0 : ℝ)) (hfs := hBnonneg)\n exact hm.aestronglyMeasurable\n have hrBMeas : AEStronglyMeasurable (fun S => r (B S)) μn := by\n simpa only [Bsub, Set.restrict_apply] using\n hrCont.restrict.comp_aestronglyMeasurable hBsubMeas\n have hcontAbs : ContinuousOn (fun t => |r t|) (Icc 0 (M ^ 2)) :=\n (hrCont.mono Icc_subset_Ici_self).abs\n obtain ⟨C, hC⟩ := isCompact_Icc.bddAbove_image hcontAbs\n apply Integrable.of_bound hrBMeas C\n filter_upwards [] with S\n rw [Real.norm_eq_abs]\n exact hC ⟨B S, ⟨hBnonneg S, hBupper S⟩, rfl⟩\n have hmeanB : (∫ S, B S ∂μn) ≤ b / 2 + 4 * M * (∫ S, R S ∂μn) := by\n let g2 : P → Z → ℝ := fun w z => -(phi w.1 z) ^ 2\n let dev2 : (Fin n → Z) → ℝ := fun S => ⨆ w : P,\n (∫ z, g2 w z ∂D) - empMean n (g2 w) S\n have hg2Bound (w : P) (z : Z) : |g2 w z| ≤ M ^ 2 := by\n dsimp [g2]\n rw [abs_neg, abs_of_nonneg (sq_nonneg _)]\n simpa only [sq_abs] using\n (pow_le_pow_left₀ (abs_nonneg (phi w.1 z)) (hBound w.1 z) 2)\n have hpopg2 (w : P) : |∫ z, g2 w z ∂D| ≤ M ^ 2 := by\n simpa only [Real.norm_eq_abs, probReal_univ, mul_one] using\n (norm_integral_le_of_norm_le_const (f := g2 w) (C := M ^ 2)\n (ae_of_all D fun z => by\n simpa only [Real.norm_eq_abs] using hg2Bound w z))\n have hdevAbs (w : P) (S : Fin n → Z) :\n |(∫ z, g2 w z ∂D) - empMean n (g2 w) S| ≤ 2 * M ^ 2 := by\n calc\n |(∫ z, g2 w z ∂D) - empMean n (g2 w) S| ≤\n |∫ z, g2 w z ∂D| + |empMean n (g2 w) S| := abs_sub _ _\n _ ≤ M ^ 2 + M ^ 2 := add_le_add (hpopg2 w)\n (Test.abs_empirical_le n hn (g2 w) (M ^ 2) (hg2Bound w) S)\n _ = 2 * M ^ 2 := by ring\n have hdevInt : Integrable dev2 μn := by\n apply Test.integrable_ciSup_of_abs_le μn\n (fun w : P => fun S => (∫ z, g2 w z ∂D) - empMean n (g2 w) S)\n (2 * M ^ 2)\n · intro w\n exact AEMeasurable.const_sub\n (Test.aemeasurable_empirical D n (g2 w)\n ((hInt2 w.1).neg.aestronglyMeasurable)) _\n · exact hdevAbs\n have hdevBdd (S : Fin n → Z) : BddAbove (Set.range fun w : P =>\n (∫ z, g2 w z ∂D) - empMean n (g2 w) S) := by\n refine ⟨2 * M ^ 2, ?_⟩\n rintro _ ⟨w, rfl⟩\n exact (le_abs_self _).trans (hdevAbs w S)\n have hempNeg (w : P) (S : Fin n → Z) :\n empMean n (g2 w) S = -empMean n (fun z => (phi w.1 z) ^ 2) S := by\n dsimp [g2]\n unfold empMean\n rw [Finset.sum_neg_distrib]\n ring\n have hpop2le (w : P) : (∫ z, (phi w.1 z) ^ 2 ∂D) ≤ b / 2 := by\n calc\n (∫ z, (phi w.1 z) ^ 2 ∂D) ≤ c1 * popVal D phi w.1 := by\n simpa only [popVal] using hVar w.1\n _ ≤ c1 * (b / (2 * c1)) :=\n mul_le_mul_of_nonneg_left w.2 hc1.le\n _ = b / 2 := by field_simp\n have hBpoint (S : Fin n → Z) : B S ≤ b / 2 + dev2 S := by\n have hbsub : BddAbove (Set.range fun w : P =>\n empMean n (fun z => (phi w.1 z) ^ 2) S) := by\n exact ⟨M ^ 2, by rintro _ ⟨w, rfl⟩; exact hemp2_upper w.1 S⟩\n have hBeq : B S = ⨆ w : P,\n empMean n (fun z => (phi w.1 z) ^ 2) S := by\n let w0 : P := Classical.choice inferInstance\n have hz : 0 ≤ ⨆ w : P,\n empMean n (fun z => (phi w.1 z) ^ 2) S :=\n (hemp2_nonneg w0.1 S).trans (le_ciSup hbsub w0)\n dsimp [B]\n exact ciSup_subtype' hbsub (by rw [Real.sSup_empty]; exact hz)\n rw [hBeq]\n apply ciSup_le\n intro w\n calc\n empMean n (fun z => (phi w.1 z) ^ 2) S =\n (∫ z, (phi w.1 z) ^ 2 ∂D) +\n ((∫ z, g2 w z ∂D) - empMean n (g2 w) S) := by\n rw [show (∫ z, g2 w z ∂D) = -(∫ z, (phi w.1 z) ^ 2 ∂D) by\n dsimp [g2]\n rw [integral_neg], hempNeg]\n ring\n _ ≤ b / 2 + ((∫ z, g2 w z ∂D) - empMean n (g2 w) S) := by\n gcongr\n exact hpop2le w\n _ ≤ b / 2 + dev2 S := by\n gcongr\n exact le_ciSup (hdevBdd S) w\n have hsymm2 : (∫ S, dev2 S ∂μn) ≤ 2 * ∫ S, R2 S ∂μn := by\n have hs := Test.symmetrization D n hn g2 (M ^ 2)\n (fun w => (hInt2 w.1).neg) hg2Bound\n simpa only [dev2, g2, R2, μn, empMean] using hs\n have hcontract (S : Fin n → Z) : R2 S ≤ (2 * M) * R S := by\n have hc := Test.rademacher_square_contraction n hn\n (fun w : P => fun i => phi w.1 (S i)) M hM.le\n (fun w i => hBound w.1 (S i))\n simpa only [R2, R, empRad] using hc\n have hR2mean : (∫ S, R2 S ∂μn) ≤ (2 * M) * ∫ S, R S ∂μn := by\n calc\n (∫ S, R2 S ∂μn) ≤ ∫ S, (2 * M) * R S ∂μn := by\n exact integral_mono hR2Int (hRInt.const_mul _) hcontract\n _ = (2 * M) * ∫ S, R S ∂μn := by rw [integral_const_mul]\n calc\n (∫ S, B S ∂μn) ≤ ∫ S, b / 2 + dev2 S ∂μn := by\n exact integral_mono hBInt ((integrable_const _).add hdevInt) hBpoint\n _ = b / 2 + ∫ S, dev2 S ∂μn := by\n rw [integral_add (integrable_const _) hdevInt, integral_const, probReal_univ,\n one_smul]\n _ ≤ b / 2 + 2 * ∫ S, R2 S ∂μn := by gcongr\n _ ≤ b / 2 + 2 * ((2 * M) * ∫ S, R S ∂μn) := by gcongr\n _ = b / 2 + 4 * M * (∫ S, R S ∂μn) := by ring\n have hx_le : (∫ S, R S ∂μn) ≤ r (∫ S, B S ∂μn) := by\n calc\n (∫ S, R S ∂μn) ≤ ∫ S, r (B S) ∂μn :=\n integral_mono hRInt hrBInt hR_le_rB\n _ ≤ r (∫ S, B S ∂μn) := by\n simpa only [Function.comp_apply] using\n hrConcave.le_map_integral hrCont isClosed_Ici\n (ae_of_all μn hBnonneg) hBInt (by simpa only [Function.comp_apply] using hrBInt)\n have hx_rb : (∫ S, R S ∂μn) ≤ r b := by\n let x : ℝ := ∫ S, R S ∂μn\n let e : ℝ := ∫ S, B S ∂μn\n change x ≤ r b\n have hxe : x ≤ r e := by simpa only [x, e] using hx_le\n have hebound : e ≤ b / 2 + 4 * M * x := by simpa only [x, e] using hmeanB\n have he0 : 0 ≤ e := by\n dsimp [e]\n exact integral_nonneg hBnonneg\n by_contra hnot\n have hrb_lt_x : r b < x := lt_of_not_ge hnot\n have hb_lt_e : b < e := by\n by_contra hbe\n have heb : e ≤ b := le_of_not_gt hbe\n have hre : r e ≤ r b := hrmono he0 hbpos.le heb\n exact (not_lt_of_ge (hxe.trans hre)) hrb_lt_x\n have hepos : 0 < e := lt_trans hbpos hb_lt_e\n let q : ℝ := b / e\n have hq0 : 0 ≤ q := by dsimp [q]; positivity\n have hq1 : 0 ≤ 1 - q := by\n dsimp [q]\n exact sub_nonneg.mpr ((div_le_one hepos).2 hb_lt_e.le)\n have hqe : q * e = b := by\n dsimp [q]\n field_simp\n have hc : q • r e + (1 - q) • r 0 ≤\n r (q • e + (1 - q) • (0 : ℝ)) := by\n exact hrConcave.2 (show e ∈ Ici (0 : ℝ) from he0)\n (show (0 : ℝ) ∈ Ici (0 : ℝ) from left_mem_Ici)\n hq0 hq1 (by ring)\n have hc' : q * r e + (1 - q) * r 0 ≤ r b := by\n simpa only [smul_eq_mul, mul_zero, add_zero, hqe] using hc\n have hqre : q * r e ≤ r b := by\n exact (le_add_of_nonneg_right\n (mul_nonneg hq1 (hrnonneg 0 le_rfl))).trans hc'\n have hbre : b * r e ≤ e * r b := by\n have hd : b * r e / e ≤ r b := by\n calc\n b * r e / e = q * r e := by dsimp [q]; ring\n _ ≤ r b := hqre\n have := (div_le_iff₀ hepos).mp hd\n simpa only [mul_comm] using this\n have hbx : b * x ≤ b * r e := mul_le_mul_of_nonneg_left hxe hbpos.le\n have hmain : b * x ≤ e * r b := hbx.trans hbre\n have hfinal : b * x ≤ (b / 2 + 4 * M * x) * r b :=\n hmain.trans (mul_le_mul_of_nonneg_right hebound (hrnonneg b hbpos.le))\n have hcoeffx : (b - 4 * M * r b) * x ≤ (b / 2) * r b := by\n nlinarith [hfinal]\n have hcoefgt : b / 2 < b - 4 * M * r b := by nlinarith [hsmall]\n have hcoefpos : 0 < b - 4 * M * r b := lt_trans (by positivity) hcoefgt\n have hcontra : (b / 2) * r b < (b - 4 * M * r b) * x :=\n (mul_le_mul_of_nonneg_right hcoefgt.le (hrnonneg b hbpos.le)).trans_lt\n (mul_lt_mul_of_pos_left hrb_lt_x hcoefpos)\n exact (not_lt_of_ge hcoeffx) hcontra\n have hsymm := Test.symmetrization D n hn (fun w : P => phi w.1) M\n (fun w => hInt w.1) (fun w z => hBound w.1 z)\n change (∫ S : Fin n → Z, (⨆ w : P,\n popVal D phi w.1 - empMean n (phi w.1) S) ∂μn) ≤ 2 * r b\n calc\n (∫ S : Fin n → Z, (⨆ w : P,\n popVal D phi w.1 - empMean n (phi w.1) S) ∂μn) ≤\n 2 * ∫ S, R S ∂μn := by\n simpa only [popVal, empMean, R, P, μn, empRad] using hsymm\n _ ≤ 2 * r b := by gcongr\n\n\ntheorem ch6_proposition_6_46\n {𝒵 Ω : Type*} [MeasurableSpace 𝒵] [Nonempty Ω] [Countable Ω]\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (n : ℕ) (hn : 1 ≤ n)\n (φ : Ω → 𝒵 → ℝ)\n (M c₁ α : ℝ)\n (hM : 0 < M) (hc₁ : 0 < c₁) (hα : 0 < α)\n (hInf : ⨅ w, popVal D φ w = 0)\n (hMeas : ∀ w, AEStronglyMeasurable (fun z => φ w z) D)\n (hInt : ∀ w, Integrable (fun z => φ w z) D)\n (hInt2 : ∀ w, Integrable (fun z => (φ w z) ^ 2) D)\n (hBound : ∀ w z, |φ w z| ≤ M)\n (hVar : ∀ w, (∫ z, (φ w z) ^ 2 ∂D) ≤ c₁ * ∫ z, φ w z ∂D)\n (r : ℝ → ℝ)\n (hrCont : ContinuousOn r (Ici 0))\n (hrConcave : ConcaveOn ℝ (Ici 0) r)\n (hRad : ∀ b > (0 : ℝ),\n (⨆ S : Fin n → 𝒵, empRad n φ {w | empMean n (fun z => (φ w z) ^ 2) S ≤ b} S) ≤ r b)\n (hαM : α ≤ (1 / 2) * c₁ / M)\n (hbNE : {b : ℝ | 0 < b ∧ b ≤ (4 * c₁ / α) * r b}.Nonempty)\n (hbBdd : BddAbove {b : ℝ | 0 < b ∧ b ≤ (4 * c₁ / α) * r b})\n (rbar : ℝ)\n (hrbarDef : rbar = sSup {ρ : ℝ | ρ ≤\n sInf ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0)))})\n (hrbarNE : {ρ : ℝ | ρ ≤\n sInf ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0)))}.Nonempty)\n (hrbarBdd : BddAbove {ρ : ℝ | ρ ≤\n sInf ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0)))})\n (hInnerBdd : ∀ ρ : ℝ,\n BddBelow ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) '' Ioi (max ρ (α * 0))))\n (hUnifInt : ∀ r' : ℝ,\n Integrable (fun S : Fin n → 𝒵 =>\n ⨆ w : {w | popVal D φ w ≤ r' / α}, (popVal D φ w.1 - empMean n (φ w.1) S))\n (Measure.pi (fun _ : Fin n => D)))\n\n (hUnifInt2 : ∀ r' : ℝ,\n Integrable (fun S : Fin n → 𝒵 =>\n ⨆ w ∈ {w | popVal D φ w ≤ r' / α}, empMean n (fun z => (φ w z) ^ 2) S)\n (Measure.pi (fun _ : Fin n => D))) :\n rbar ≤ (1 / 2) * α * bZero c₁ α r / c₁ := by\n classical\n have hnpos : 0 < n := Nat.zero_lt_of_lt hn\n let A : Set ℝ := {ρ : ℝ | ρ ≤\n sInf ((fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) ''\n Ioi (max ρ (α * 0)))}\n rw [hrbarDef]\n apply csSup_le hrbarNE\n intro rho hrho\n change rho ≤ (1 / 2) * α * bZero c₁ α r / c₁\n obtain ⟨b0, hb0pos, hb0le⟩ := hbNE\n have hb0sup : b0 ≤ bZero c₁ α r := by\n exact le_csSup hbBdd ⟨hb0pos, hb0le⟩\n have hbZeroPos : 0 < bZero c₁ α r := lt_of_lt_of_le hb0pos hb0sup\n have htargetPos : 0 < (1 / 2) * α * bZero c₁ α r / c₁ := by positivity\n by_contra hnot\n have htarget_lt_rho : (1 / 2) * α * bZero c₁ α r / c₁ < rho :=\n lt_of_not_ge hnot\n have hrhopos : 0 < rho := lt_trans htargetPos htarget_lt_rho\n let t : ℝ := 2 * c₁ * rho / α\n let k : ℝ := α / (2 * c₁)\n have hkpos : 0 < k := by dsimp [k]; positivity\n have hkrho : k * t = rho := by\n dsimp [k, t]\n field_simp\n <;> ring\n have hbt : bZero c₁ α r < t := by\n have hscale := mul_lt_mul_of_pos_left htarget_lt_rho (show 0 < 2 * c₁ / α by positivity)\n dsimp [t]\n calc\n bZero c₁ α r = (2 * c₁ / α) *\n ((1 / 2) * α * bZero c₁ α r / c₁) := by\n field_simp\n <;> ring\n _ < (2 * c₁ / α) * rho := hscale\n _ = 2 * c₁ * rho / α := by ring\n have htpos : 0 < t := lt_trans hbZeroPos hbt\n change rho ≤ sInf ((fun r' =>\n unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) ''\n Ioi (max rho (α * 0))) at hrho\n have hnear (b : ℝ) (hb : t < b) : rho ≤ 2 * r b := by\n let rp : ℝ := α * b / (2 * c₁)\n have hrp : rp ∈ Ioi (max rho (α * 0)) := by\n simp only [mul_zero, max_eq_left hrhopos.le]\n dsimp [rp]\n calc\n rho = k * t := hkrho.symm\n _ < k * b := mul_lt_mul_of_pos_left hb hkpos\n _ = α * b / (2 * c₁) := by dsimp [k]; ring\n have hmem : unifComplexity n D φ {w | popVal D φ w ≤ rp / α} ∈\n (fun r' => unifComplexity n D φ {w | popVal D φ w ≤ r' / α}) ''\n Ioi (max rho (α * 0)) := ⟨rp, hrp, rfl⟩\n have hrhoF : rho ≤\n unifComplexity n D φ {w | popVal D φ w ≤ rp / α} :=\n hrho.trans (csInf_le (hInnerBdd rho) hmem)\n have hloc := localized_bound D n hnpos φ M c₁ α hM hc₁ hα\n hInf hInt hInt2 hBound hVar r hrCont hrConcave hRad hαM\n ⟨b0, hb0pos, hb0le⟩ hbBdd hUnifInt2\n b (lt_trans hbt hb)\n have heq : rp / α = b / (2 * c₁) := by\n dsimp [rp]\n field_simp\n exact hrhoF.trans (by simpa only [heq] using hloc)\n have hlim : rho ≤ 2 * r t := by\n apply ContinuousWithinAt.closure_le (s := Ioi t)\n (by rw [closure_Ioi]; exact left_mem_Ici)\n continuousWithinAt_const\n (continuousWithinAt_const.mul\n ((hrCont t htpos.le).mono (by\n intro b hb\n exact le_trans htpos.le hb.le)))\n exact fun b hb => hnear b hb\n have hrt_lt : (4 * c₁ / α) * r t < t := by\n have hnle : ¬ t ≤ (4 * c₁ / α) * r t := by\n intro hle\n have htsup : t ≤ bZero c₁ α r :=\n le_csSup hbBdd ⟨htpos, hle⟩\n exact (not_lt_of_ge htsup) hbt\n exact lt_of_not_ge hnle\n have h2rt_lt : 2 * r t < rho := by\n have hs := mul_lt_mul_of_pos_left hrt_lt hkpos\n calc\n 2 * r t = k * ((4 * c₁ / α) * r t) := by\n dsimp [k]\n field_simp\n <;> ring\n _ < k * t := hs\n _ = rho := hkrho\n exact (not_lt_of_ge hlim) h2rt_lt\n\n\nend GraduateLevel\n"} +{"id": "ch13_theorem_13_2", "source": "Graduate-level", "targets": [{"label": "ch13_theorem_13_2", "decls": ["ch13_theorem_13_2"], "statement": "Consider a sequence of random functions \\(\\xi_1(S_1),\\ldots,\\xi_t(S_t),\\ldots\\) with filtration \\(\\{\\mathcal{F}_t\\}\\). We have for any \\(\\delta \\in (0,1)\\) and \\(\\lambda >0\\):\n\\[\n\\operatorname*{Pr}\\left[\\exists n>0: -\\sum_{i=1}^{n}\\xi_{i}\\geq\\frac{\\ln(1/\\delta)}{\\lambda}+\\frac{1}{\\lambda}\\sum_{i=1}^{n}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{-\\lambda\\xi_{i}}\\right]\\leq\\delta .\n\\]\nMoreover, consider a sequence of \\(\\{z_t\\in \\mathbb{R}\\}\\) adapted to \\(\\{\\mathcal{F}_t\\}\\), and events \\(A_{t}\\) on \\(\\mathcal{F}_t\\):\n\\[\n\\ln\\Pr\\left[\\exists n>0:\\sum_{i=1}^{n}\\xi_{i}\\leq z_{n}\\&\\mathcal{S}_{n}\\in A_{n}\\right]\\leq\\inf_{\\lambda>0}\\sup_{n>0}\\sup_{\\mathcal{S}_{n}\\in A_{n}}\\left[\\lambda z_{n}+\\sum_{i=1}^{n}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{-\\lambda\\xi_{i}}\\right].\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Martingales & Dependent Data"}], "nl_proof": "We will prove the result for a finite time sequence \\(\\xi_1(S_1),\\ldots,\\xi_T(S_T)\\). It implies the desired result by letting \\(T\\to \\infty\\). Let\n\\[\n\\xi_{\\tau}(\\lambda)= -\\sum_{i=1}^{\\tau}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{-\\lambda\\xi_{i}}-\\lambda\\sum_{i=1}^{\\tau}\\xi_{i},\n\\]\nwhere \\(\\tau\\) is a stopping time, then we have from Lemma 13.1: \\(\\mathbb{E}e^{\\xi_{\\tau}(\\lambda)} = 1\\). Now for any given sequence of \\(\\tilde{z}_n(S_n)\\) and \\(A_{n}\\), define the stopping time \\(\\tau\\) as either \\(T\\), or the first time step \\(n\\) so that\n\\[\n\\xi_{n}(\\lambda)\\geq-\\tilde{z}_{n}\\left(\\mathcal{S}_{n}\\right)\\&\\mathcal{S}_{n}\\in A_{n}\n\\]\nfor each sequence \\(S_T\\). It follows that\n\\[\n\\begin{array}{l}\\Pr\\left(\\exists n:\\xi_{n}(\\lambda)\\geq-\\tilde{z}_{n}\\left(\\mathcal{S}_{n}\\right)\\&\\mathcal{S}_{n}\\in A_{n}\\right)\\inf_{n>0,\\mathcal{S}_{n}\\in A_{n}}e^{-\\tilde{z}_{n}\\left(\\mathcal{S}_{n}\\right)}\\\\ \\leq\\mathbb{E}\\left[e^{\\xi_{\\tau}(\\lambda)+\\tilde{z}_{\\tau}\\left(\\mathcal{S}_{\\tau}\\right)}\\mathbb{1}\\left(\\mathcal{S}_{\\tau}\\in A_{\\tau}\\right)\\right]\\inf_{n>0,\\mathcal{S}_{n}\\in A_{n}}e^{-\\tilde{z}_{n}\\left(\\mathcal{S}_{n}\\right)}\\\\ \\leq\\mathbb{E}\\left[e^{\\xi_{\\tau}(\\lambda)+\\tilde{z}_{\\tau}\\left(\\mathcal{S}_{\\tau}\\right)}\\mathbb{1}\\left(\\mathcal{S}_{\\tau}\\in A_{\\tau}\\right)e^{-\\tilde{z}_{\\tau}\\left(\\mathcal{S}_{\\tau}\\right)}\\right]\\\\ \\leq\\mathbb{E}e^{\\xi_{\\tau}(\\lambda)}=1.\\\\ \\end{array}\n\\]\nTherefore we obtain\n\\[\n\\begin{array}{l}\\ln\\operatorname*{Pr}\\left[\\exists n>0: -\\lambda\\sum_{i=1}^{n}\\xi_{i}\\geq-\\tilde{z}_{n}(\\mathcal{S}_{n})+\\sum_{i=1}^{n}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{-\\lambda\\xi_{i}}\\&\\mathcal{S}_{n}\\in A_{n}\\right]\\\\ \\leq\\sup_{n>0:\\mathcal{S}_{n}\\in A_{n}}\\tilde{z}_{n}(\\mathcal{S}_{n}).\\\\ \\end{array}\n\\]\nLet \\(\\tilde{z}(\\mathcal{S}_n) = \\ln \\delta\\), we obtain the first inequality. Let\n\\[\n\\tilde{z}_{n}(\\mathcal{S}_{n})=\\lambda z_{n}+\\sum_{i=1}^{n}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{-\\lambda\\xi_{i}},\n\\]\nwe obtain the second inequality.", "context": [{"id": "ch13:lemma:13_1", "name": "lemma 13.1", "statement": "Consider a sequence of real-valued random (measurable) functions \\(\\xi_1(S_1),\\ldots,\\xi_T(S_T)\\). Let \\(\\tau \\leq T\\) be a stopping time so that \\(\\mathbb{1}(t\\leq \\tau)\\) is measurable in \\(S_{t}\\). We have\n\\[\n\\mathbb{E}_{\\mathcal{S}_{T}}\\exp\\left(\\sum_{i=1}^{\\tau}\\xi_{i}-\\sum_{i=1}^{\\tau}\\ln\\mathbb{E}_{Z_{i}^{(y)}}e^{\\xi_{i}}\\right)=1.\n\\]"}, {"id": "ch13:setup:13_1", "name": "section 13.1 sequential observation setup", "statement": "In Section 13.1, data are observed sequentially. At each time \\(t\\), after the history \\(S_{t-1}\\) has been observed, the next observation \\(Z_t\\) is drawn according to a distribution that may depend on that history. The observation is decomposed as \\(Z_t=(Z_t^{(x)},Z_t^{(y)})\\), where \\(Z_t^{(x)}\\) is the component determined by the past history or the chosen action at time \\(t\\), and \\(Z_t^{(y)}\\) is the random response component. The history after time \\(t\\) is \\(S_t=(Z_1,\\ldots,Z_t)\\), and \\(\\mathcal{S}_T\\) denotes the full sequential experiment/history through time \\(T\\). For a function depending on \\(S_t\\), the notation \\(\\mathbb{E}_{Z_t^{(y)}}[\\cdot]\\) means conditional expectation over the response component \\(Z_t^{(y)}\\), conditional on \\(S_{t-1}\\) and on \\(Z_t^{(x)}\\). Stopping times are adapted to the filtration generated by the histories \\(S_t\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\n\nnamespace GraduateLevel\n\ndef partialSum {Ω : Type*} (ξ : ℕ → Ω → ℝ) (n : ℕ) (ω : Ω) : ℝ :=\n ∑ i ∈ Finset.Icc 1 n, ξ i ω\n\ntheorem ch13_theorem_13_2\n {Ω : Type*} [m₀ : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n (ℱ : Filtration ℕ m₀) (ξ : ℕ → Ω → ℝ) (hξ_adapted : Adapted ℱ ξ)\n (z : ℕ → Ω → ℝ) (hz_adapted : Adapted ℱ z)\n (A : ℕ → Set Ω) (hA : ∀ n, MeasurableSet[ℱ n] (A n))\n (c : ℝ → ℕ → Ω → ℝ)\n (hc_meas : ∀ lam i, StronglyMeasurable[ℱ (i - 1)] (c lam i))\n (hc_mgf : ∀ lam i, 0 < lam → ∀ s, MeasurableSet[ℱ (i - 1)] s →\n ∫⁻ ω in s, ENNReal.ofReal (Real.exp (-lam * ξ i ω)) ∂μ\n = ∫⁻ ω in s, ENNReal.ofReal (c lam i ω) ∂μ)\n (hc_pos : ∀ lam i ω, 0 < lam → 0 < c lam i ω) :\n (∀ δ : ℝ, 0 < δ → δ < 1 → ∀ lam : ℝ, 0 < lam →\n (μ {ω | ∃ n, 0 < n ∧\n Real.log (1 / δ) / lam + (1 / lam) * (∑ i ∈ Finset.Icc 1 n, Real.log (c lam i ω))\n ≤ - partialSum ξ n ω}).toReal ≤ δ)\n ∧ (ENNReal.log (μ {ω | ∃ n, 0 < n ∧ partialSum ξ n ω ≤ z n ω ∧ ω ∈ A n})\n ≤ ⨅ lam : {l : ℝ // 0 < l}, ⨆ n : {k : ℕ // 0 < k}, ⨆ ω ∈ A (n : ℕ),\n (((lam : ℝ) * z (n : ℕ) ω\n + ∑ i ∈ Finset.Icc 1 (n : ℕ), Real.log (c (lam : ℝ) i ω) : ℝ) : EReal)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory\nopen scoped NNReal ENNReal\n\nnamespace GraduateLevel\n\ndef partialSum {Ω : Type*} (ξ : ℕ → Ω → ℝ) (n : ℕ) (ω : Ω) : ℝ :=\n ∑ i ∈ Finset.Icc 1 n, ξ i ω\n\nprivate lemma lintegral_mul_eq_of_setLIntegral_eq\n {Ω : Type*} [m₀ : MeasurableSpace Ω] {μ : Measure Ω}\n {m : MeasurableSpace Ω} (hm : m ≤ m₀)\n {f c : Ω → ℝ≥0∞} (hf : Measurable[m₀] f) (hc : Measurable[m₀] c)\n (heq : ∀ s, MeasurableSet[m] s → ∫⁻ ω in s, f ω ∂μ = ∫⁻ ω in s, c ω ∂μ)\n {g : Ω → ℝ≥0∞} (hg : Measurable[m] g) :\n ∫⁻ ω, g ω * f ω ∂μ = ∫⁻ ω, g ω * c ω ∂μ := by\n have htrim : (μ.withDensity f).trim hm = (μ.withDensity c).trim hm := by\n refine @Measure.ext _ m _ _ (fun s hs => ?_)\n rw [trim_measurableSet_eq hm hs, trim_measurableSet_eq hm hs,\n withDensity_apply _ (hm s hs), withDensity_apply _ (hm s hs)]\n exact heq s hs\n have h1 : ∀ d : Ω → ℝ≥0∞, Measurable[m₀] d →\n ∫⁻ ω, g ω * d ω ∂μ = ∫⁻ ω, g ω ∂((μ.withDensity d).trim hm) := by\n intro d hd\n rw [lintegral_trim hm hg, lintegral_withDensity_eq_lintegral_mul _ hd (hg.mono hm le_rfl)]\n congr 1\n funext ω\n simp [mul_comm]\n rw [h1 f hf, h1 c hc, htrim]\n\nprivate noncomputable def likelihood {Ω : Type*} (ξ : ℕ → Ω → ℝ)\n (c : ℝ → ℕ → Ω → ℝ) (lam : ℝ) (n : ℕ) (ω : Ω) : ℝ :=\n ∏ i ∈ Finset.Icc 1 n, Real.exp (-lam * ξ i ω) / c lam i ω\n\nprivate lemma likelihood_eq_exp {Ω : Type*} (ξ : ℕ → Ω → ℝ)\n (c : ℝ → ℕ → Ω → ℝ) {lam : ℝ}\n (hc : ∀ i ω, 0 < c lam i ω) (n : ℕ) (ω : Ω) :\n likelihood ξ c lam n ω =\n Real.exp (-lam * partialSum ξ n ω -\n ∑ i ∈ Finset.Icc 1 n, Real.log (c lam i ω)) := by\n induction n with\n | zero => simp [likelihood, partialSum]\n | succ n ih =>\n rw [likelihood, Finset.prod_Icc_succ_top (Nat.succ_pos n)]\n rw [partialSum, Finset.sum_Icc_succ_top (Nat.succ_pos n)]\n rw [Finset.sum_Icc_succ_top (Nat.succ_pos n)]\n change likelihood ξ c lam n ω *\n (Real.exp (-lam * ξ (n + 1) ω) / c lam (n + 1) ω) = _\n rw [ih, ← Real.exp_log (hc (n + 1) ω), ← Real.exp_sub]\n rw [← Real.exp_add]\n congr 1\n simp only [Real.log_exp, partialSum]\n ring\n\nprivate lemma likelihood_martingale\n {Ω : Type*} [m₀ : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n (ℱ : Filtration ℕ m₀) (ξ : ℕ → Ω → ℝ) (hξ : Adapted ℱ ξ)\n (c : ℝ → ℕ → Ω → ℝ)\n (hc_meas : ∀ lam i, StronglyMeasurable[ℱ (i - 1)] (c lam i))\n (hc_mgf : ∀ lam i, 0 < lam → ∀ s, MeasurableSet[ℱ (i - 1)] s →\n ∫⁻ ω in s, ENNReal.ofReal (Real.exp (-lam * ξ i ω)) ∂μ\n = ∫⁻ ω in s, ENNReal.ofReal (c lam i ω) ∂μ)\n (hc_pos : ∀ lam i ω, 0 < lam → 0 < c lam i ω)\n {lam : ℝ} (hlam : 0 < lam) :\n Martingale (likelihood ξ c lam) ℱ μ := by\n have hstep (n : ℕ) :\n likelihood ξ c lam (n + 1) =\n fun ω => likelihood ξ c lam n ω / c lam (n + 1) ω *\n Real.exp (-lam * ξ (n + 1) ω) := by\n funext ω\n rw [likelihood, Finset.prod_Icc_succ_top (Nat.succ_pos n)]\n simp only [likelihood]\n ring\n have hadp : Adapted ℱ (likelihood ξ c lam) := by\n intro n\n unfold likelihood\n have H := (Finset.Icc 1 n).stronglyMeasurable_prod (f :=\n fun i ω => Real.exp (-lam * ξ i ω) / c lam i ω) (fun i hi => by\n rw [Finset.mem_Icc] at hi\n have hxi := (hξ i).mono (ℱ.mono hi.2)\n have hci := (hc_meas lam i).mono (ℱ.mono ((Nat.sub_le i 1).trans hi.2))\n exact\n ((hxi.measurable.const_mul (-lam)).exp.div hci.measurable).stronglyMeasurable)\n convert H using 1\n funext ω\n simp only [Finset.prod_apply]\n -- one-step identity for set-lintegrals on ℱ n-measurable sets\n have hkey : ∀ n s, MeasurableSet[ℱ n] s →\n ∫⁻ ω in s, ENNReal.ofReal (likelihood ξ c lam (n + 1) ω) ∂μ =\n ∫⁻ ω in s, ENNReal.ofReal (likelihood ξ c lam n ω) ∂μ := by\n intro n s hs\n have hsm : MeasurableSet s := ℱ.le n s hs\n let a : Ω → ℝ := fun ω => likelihood ξ c lam n ω / c lam (n + 1) ω\n have ham : Measurable[ℱ n] a :=\n (hadp n).measurable.div\n ((hc_meas lam (n + 1)).mono (by simp)).measurable\n let g : Ω → ℝ≥0∞ := s.indicator (fun ω => ENNReal.ofReal (a ω))\n have hgm : Measurable[ℱ n] g := (ENNReal.measurable_ofReal.comp ham).indicator hs\n have hf : Measurable (fun ω => ENNReal.ofReal (Real.exp (-lam * ξ (n + 1) ω))) :=\n ENNReal.measurable_ofReal.comp\n ((((hξ (n + 1)).mono (ℱ.le (n + 1))).measurable.const_mul (-lam)).exp)\n have hcm : Measurable (fun ω => ENNReal.ofReal (c lam (n + 1) ω)) :=\n ENNReal.measurable_ofReal.comp\n (((hc_meas lam (n + 1)).mono (ℱ.le _)).measurable)\n have hmgf : ∀ t, MeasurableSet[ℱ n] t →\n ∫⁻ ω in t, ENNReal.ofReal (Real.exp (-lam * ξ (n + 1) ω)) ∂μ =\n ∫⁻ ω in t, ENNReal.ofReal (c lam (n + 1) ω) ∂μ := by\n intro t ht\n exact hc_mgf lam (n + 1) hlam t (by simpa using ht)\n have hpull := lintegral_mul_eq_of_setLIntegral_eq (ℱ.le n) hf hcm hmgf hgm\n rw [← lintegral_indicator hsm, ← lintegral_indicator hsm]\n have hl : s.indicator (fun ω => ENNReal.ofReal (likelihood ξ c lam (n + 1) ω)) =\n fun ω => g ω * ENNReal.ofReal (Real.exp (-lam * ξ (n + 1) ω)) := by\n funext ω\n by_cases hω : ω ∈ s\n · have ha0 : 0 ≤ a ω := div_nonneg\n (Finset.prod_nonneg fun i hi =>\n div_nonneg (Real.exp_pos _).le (hc_pos lam i ω hlam).le)\n (hc_pos lam (n + 1) ω hlam).le\n simp only [Set.indicator_of_mem hω, g]\n rw [← ENNReal.ofReal_mul ha0, hstep n]\n · simp [Set.indicator_of_notMem hω, g]\n have hr : s.indicator (fun ω => ENNReal.ofReal (likelihood ξ c lam n ω)) =\n fun ω => g ω * ENNReal.ofReal (c lam (n + 1) ω) := by\n funext ω\n by_cases hω : ω ∈ s\n · have ha0 : 0 ≤ a ω := div_nonneg\n (Finset.prod_nonneg fun i hi =>\n div_nonneg (Real.exp_pos _).le (hc_pos lam i ω hlam).le)\n (hc_pos lam (n + 1) ω hlam).le\n simp only [Set.indicator_of_mem hω, g]\n rw [← ENNReal.ofReal_mul ha0]\n congr 1\n simp only [a]\n field_simp [ne_of_gt (hc_pos lam (n + 1) ω hlam)]\n · simp [Set.indicator_of_notMem hω, g]\n rw [hl, hr]\n exact hpull\n have hnn : ∀ n ω, 0 ≤ likelihood ξ c lam n ω := fun n ω =>\n Finset.prod_nonneg fun i hi =>\n div_nonneg (Real.exp_pos _).le (hc_pos lam i ω hlam).le\n have hone : ∀ n, ∫⁻ ω, ENNReal.ofReal (likelihood ξ c lam n ω) ∂μ = 1 := by\n intro n\n induction n with\n | zero => simp [likelihood]\n | succ n ih =>\n have := hkey n Set.univ MeasurableSet.univ\n simpa [Measure.restrict_univ, ih] using this\n have hint : ∀ n, Integrable (likelihood ξ c lam n) μ := by\n intro n\n refine ⟨((hadp n).mono (ℱ.le n)).aestronglyMeasurable, ?_⟩\n rw [hasFiniteIntegral_iff_ofReal (ae_of_all _ (hnn n)), hone n]\n exact ENNReal.one_lt_top\n apply martingale_nat hadp hint\n intro n\n refine ae_eq_condExp_of_forall_setIntegral_eq (ℱ.le n) (hint (n + 1))\n (fun s _ _ => (hint n).integrableOn) (fun s hs _ => ?_)\n ((hadp n).aestronglyMeasurable)\n rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ (hnn n))\n ((hint n).aestronglyMeasurable.restrict),\n integral_eq_lintegral_of_nonneg_ae (ae_of_all _ (hnn (n + 1)))\n ((hint (n + 1)).aestronglyMeasurable.restrict),\n hkey n s hs]\n\nprivate lemma likelihood_ville\n {Ω : Type*} [m₀ : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n (ℱ : Filtration ℕ m₀) (ξ : ℕ → Ω → ℝ) (hξ : Adapted ℱ ξ)\n (c : ℝ → ℕ → Ω → ℝ)\n (hc_meas : ∀ lam i, StronglyMeasurable[ℱ (i - 1)] (c lam i))\n (hc_mgf : ∀ lam i, 0 < lam → ∀ s, MeasurableSet[ℱ (i - 1)] s →\n ∫⁻ ω in s, ENNReal.ofReal (Real.exp (-lam * ξ i ω)) ∂μ\n = ∫⁻ ω in s, ENNReal.ofReal (c lam i ω) ∂μ)\n (hc_pos : ∀ lam i ω, 0 < lam → 0 < c lam i ω)\n {lam r : ℝ} (hlam : 0 < lam) (hr : 0 < r) :\n μ {ω | ∃ n, r ≤ likelihood ξ c lam n ω} ≤ ENNReal.ofReal r⁻¹ := by\n let ε : ℝ≥0 := ⟨r, hr.le⟩\n let E : ℕ → Set Ω := fun N => {ω | ∃ n ≤ N, r ≤ likelihood ξ c lam n ω}\n have hm := likelihood_martingale ℱ ξ hξ c hc_meas hc_mgf hc_pos hlam\n have hnonneg : 0 ≤ likelihood ξ c lam := fun n ω =>\n Finset.prod_nonneg fun i hi =>\n div_nonneg (Real.exp_pos _).le (hc_pos lam i ω hlam).le\n have hint (N : ℕ) : ∫ ω, likelihood ξ c lam N ω ∂μ = 1 := by\n calc\n _ = ∫ ω, μ[likelihood ξ c lam N | ℱ 0] ω ∂μ :=\n (integral_condExp (ℱ.le 0)).symm\n _ = ∫ ω, likelihood ξ c lam 0 ω ∂μ :=\n integral_congr_ae (hm.2 0 N (Nat.zero_le N))\n _ = 1 := by simp [likelihood]\n have hEN : ∀ N, μ (E N) ≤ ENNReal.ofReal r⁻¹ := by\n intro N\n let S : Set Ω := {ω | (ε : ℝ) ≤\n (Finset.range (N + 1)).sup' Finset.nonempty_range_add_one\n (fun k => likelihood ξ c lam k ω)}\n have hsub : E N ⊆ S := by\n rintro ω ⟨n, hn, hnr⟩\n change (ε : ℝ) ≤ _ \n exact hnr.trans (Finset.le_sup'\n (fun k => likelihood ξ c lam k ω)\n (Finset.mem_range.2 (Nat.lt_succ_iff.2 hn)))\n refine (measure_mono hsub).trans ?_\n have hmax := maximal_ineq hm.submartingale hnonneg (ε := ε) N\n have hset : ∫ ω in S, likelihood ξ c lam N ω ∂μ ≤ 1 :=\n (setIntegral_le_integral (hm.integrable N) (ae_of_all _ fun ω => hnonneg N ω)).trans_eq\n (hint N)\n have hmul : (ε : ℝ≥0∞) * μ S ≤ 1 := by\n calc\n (ε : ℝ≥0∞) * μ S = ε • μ S := by simp [ENNReal.smul_def]\n _ ≤ ENNReal.ofReal (∫ ω in S, likelihood ξ c lam N ω ∂μ) := hmax\n _ ≤ 1 := by simpa using ENNReal.ofReal_le_ofReal hset\n rw [ENNReal.ofReal_inv_of_pos hr, ENNReal.le_inv_iff_mul_le]\n simpa only [mul_comm, ε, ENNReal.coe_nnreal_eq, NNReal.coe_mk] using hmul\n have hmono : Monotone E := by\n intro a b hab ω\n rintro ⟨n, hn, hnr⟩\n exact ⟨n, hn.trans hab, hnr⟩\n have hunion : (⋃ N, E N) = {ω | ∃ n, r ≤ likelihood ξ c lam n ω} := by\n ext ω\n simp only [Set.mem_iUnion, Set.mem_setOf_eq, E]\n constructor\n · rintro ⟨N, n, hn, hnr⟩\n exact ⟨n, hnr⟩\n · rintro ⟨n, hn⟩\n exact ⟨n, n, le_rfl, hn⟩\n rw [← hunion, hmono.measure_iUnion]\n exact iSup_le hEN\n\ntheorem ch13_theorem_13_2\n {Ω : Type*} [m₀ : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ]\n (ℱ : Filtration ℕ m₀) (ξ : ℕ → Ω → ℝ) (hξ_adapted : Adapted ℱ ξ)\n (z : ℕ → Ω → ℝ) (hz_adapted : Adapted ℱ z)\n (A : ℕ → Set Ω) (hA : ∀ n, MeasurableSet[ℱ n] (A n))\n (c : ℝ → ℕ → Ω → ℝ)\n (hc_meas : ∀ lam i, StronglyMeasurable[ℱ (i - 1)] (c lam i))\n (hc_mgf : ∀ lam i, 0 < lam → ∀ s, MeasurableSet[ℱ (i - 1)] s →\n ∫⁻ ω in s, ENNReal.ofReal (Real.exp (-lam * ξ i ω)) ∂μ\n = ∫⁻ ω in s, ENNReal.ofReal (c lam i ω) ∂μ)\n (hc_pos : ∀ lam i ω, 0 < lam → 0 < c lam i ω) :\n (∀ δ : ℝ, 0 < δ → δ < 1 → ∀ lam : ℝ, 0 < lam →\n (μ {ω | ∃ n, 0 < n ∧\n Real.log (1 / δ) / lam + (1 / lam) * (∑ i ∈ Finset.Icc 1 n, Real.log (c lam i ω))\n ≤ - partialSum ξ n ω}).toReal ≤ δ)\n ∧ (ENNReal.log (μ {ω | ∃ n, 0 < n ∧ partialSum ξ n ω ≤ z n ω ∧ ω ∈ A n})\n ≤ ⨅ lam : {l : ℝ // 0 < l}, ⨆ n : {k : ℕ // 0 < k}, ⨆ ω ∈ A (n : ℕ),\n (((lam : ℝ) * z (n : ℕ) ω\n + ∑ i ∈ Finset.Icc 1 (n : ℕ), Real.log (c (lam : ℝ) i ω) : ℝ) : EReal)) := by\n constructor\n · intro δ hδ hδ1 lam hlam\n let B : Set Ω := {ω | ∃ n, 0 < n ∧\n Real.log (1 / δ) / lam +\n (1 / lam) * (∑ i ∈ Finset.Icc 1 n, Real.log (c lam i ω))\n ≤ -partialSum ξ n ω}\n have hr : 0 < 1 / δ := one_div_pos.mpr hδ\n have hv := likelihood_ville ℱ ξ hξ_adapted c hc_meas hc_mgf hc_pos\n hlam hr\n have hsub : B ⊆ {ω | ∃ n, 1 / δ ≤ likelihood ξ c lam n ω} := by\n rintro ω ⟨n, hn, hbound⟩\n refine ⟨n, ?_⟩\n rw [likelihood_eq_exp ξ c (fun i ω => hc_pos lam i ω hlam)]\n rw [← Real.exp_log hr]\n apply Real.exp_le_exp.mpr\n field_simp [ne_of_gt hlam] at hbound\n have hlog : Real.log (1 / δ) =\n Real.log (1 / δ) := rfl\n linarith\n have hmeasure : μ B ≤ ENNReal.ofReal (1 / δ)⁻¹ :=\n (measure_mono hsub).trans hv\n have hto : (μ B).toReal ≤ (ENNReal.ofReal (1 / δ)⁻¹).toReal :=\n ENNReal.toReal_mono ENNReal.ofReal_ne_top hmeasure\n change (μ B).toReal ≤ δ\n calc\n (μ B).toReal ≤ (ENNReal.ofReal (1 / δ)⁻¹).toReal := hto\n _ = δ := by\n rw [ENNReal.toReal_ofReal (inv_nonneg.mpr hr.le)]\n field_simp [ne_of_gt hδ]\n · let D : Set Ω :=\n {ω | ∃ n, 0 < n ∧ partialSum ξ n ω ≤ z n ω ∧ ω ∈ A n}\n apply le_iInf\n intro lam\n let S : EReal := ⨆ n : {k : ℕ // 0 < k}, ⨆ ω ∈ A (n : ℕ),\n ((((lam : ℝ) * z (n : ℕ) ω +\n ∑ i ∈ Finset.Icc 1 (n : ℕ), Real.log (c (lam : ℝ) i ω)) : ℝ) : EReal)\n change ENNReal.log (μ D) ≤ S\n by_cases htop : S = ⊤\n · rw [htop]\n exact le_top\n by_cases hbot : S = ⊥\n · have hD : D = ∅ := by\n ext ω\n constructor\n · rintro ⟨n, hn, hsum, hωA⟩\n let ns : {k : ℕ // 0 < k} := ⟨n, hn⟩\n have hle : ((((lam : ℝ) * z n ω +\n ∑ i ∈ Finset.Icc 1 n, Real.log (c (lam : ℝ) i ω)) : ℝ) : EReal) ≤ S :=\n le_iSup_of_le ns (le_iSup_of_le ω (le_iSup_of_le hωA le_rfl))\n rw [hbot] at hle\n exact (EReal.coe_ne_bot _ (le_bot_iff.mp hle)).elim\n · simp\n rw [hD, measure_empty, ENNReal.log_zero]\n exact bot_le\n · let s : ℝ := S.toReal\n have hSco : (s : EReal) = S := by\n exact EReal.coe_toReal htop hbot\n have hr : 0 < Real.exp (-s) := Real.exp_pos _\n have hv := likelihood_ville ℱ ξ hξ_adapted c hc_meas hc_mgf hc_pos\n lam.property hr\n have hsub : D ⊆ {ω | ∃ n, Real.exp (-s) ≤\n likelihood ξ c (lam : ℝ) n ω} := by\n rintro ω ⟨n, hn, hsum, hωA⟩\n refine ⟨n, ?_⟩\n rw [likelihood_eq_exp ξ c (fun i ω => hc_pos (lam : ℝ) i ω lam.property)]\n apply Real.exp_le_exp.mpr\n have hB : (((((lam : ℝ) * z n ω +\n ∑ i ∈ Finset.Icc 1 n, Real.log (c (lam : ℝ) i ω)) : ℝ) : EReal) ≤ S) := by\n exact le_iSup_of_le (⟨n, hn⟩ : {k : ℕ // 0 < k})\n (le_iSup_of_le ω (le_iSup_of_le hωA le_rfl))\n rw [← hSco] at hB\n have hBr : (lam : ℝ) * z n ω +\n ∑ i ∈ Finset.Icc 1 n, Real.log (c (lam : ℝ) i ω) ≤ s := by\n exact_mod_cast hB\n nlinarith [mul_le_mul_of_nonneg_left hsum lam.property.le]\n have hp : μ D ≤ ENNReal.ofReal (Real.exp (-s))⁻¹ :=\n (measure_mono hsub).trans hv\n calc\n ENNReal.log (μ D) ≤ ENNReal.log (ENNReal.ofReal (Real.exp (-s))⁻¹) :=\n ENNReal.log_le_log hp\n _ = (s : EReal) := by\n rw [ENNReal.log_ofReal]\n simp [not_le.mpr (inv_pos.mpr hr), Real.log_inv, Real.log_exp]\n _ = S := hSco\n\nend GraduateLevel\n"} +{"id": "ch8_theorem_8_2", "source": "Graduate-level", "targets": [{"label": "ch8_theorem_8_2", "decls": ["ch8_theorem_8_2"], "statement": "Assume \\(\\sup_{Z,Z'}[\\phi(f,Z) - \\phi(f,Z')] \\leq M\\) for all \\(f\\), and the validation data \\(\\bar{S}_m\\) contains \\(m\\) iid samples from \\(\\mathcal{D}\\). Given training data \\(S_n\\), consider (8.2) with\n\\[\nr_{m}(q)=M\\sqrt{\\frac{\\ln(1/q)}{2 m}}.\n\\]\nThen with probability at least \\(1 - \\delta\\) over the random selection of \\(S_{m}\\):\n\\[\n\\phi(\\mathcal{A}(\\hat{\\theta},\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{\\theta}Q(\\theta,\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\bar{\\mathcal{S}}_{m})+\\tilde{\\epsilon}+M\\sqrt{\\frac{\\ln(1/\\delta)}{2 m}}.\n\\]\nThis implies the following oracle inequality. With probability at least \\(1 - \\delta\\) over the random sampling of \\(\\bar{S}_m\\):\n\\[\n\\phi(\\mathcal{A}(\\hat{\\theta},\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{\\theta}[\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})+r_{m}(q(\\theta))]+\\tilde{\\epsilon}+M\\sqrt{\\frac{2\\ln(2/\\delta)}{m}},\n\\]\nwhere \\(q(\\theta)\\) satisfies (8.1).", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "For each model \\(\\theta\\), let \\(\\hat{f}_{\\theta} = \\mathcal{A}(\\theta, S_{n})\\). We obtain from the additive Chernoff bound that with probability at least \\(1 - q(\\theta)\\delta\\):\n\\[\n\\begin{array}{l}\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(\\hat{f}_{\\theta},Z)\\leq\\frac{1}{m}\\sum_{Z\\in\\bar{\\mathcal{S}}_{m}}\\phi(\\hat{f}_{\\theta},Z)+M\\sqrt{\\frac{\\ln(1/(q(\\theta)\\delta))}{2 m}}\\\\ \\leq\\frac{1}{m}\\sum_{Z\\in\\mathcal{S}_{m}}\\phi(\\hat{f}_{\\theta},Z)+M\\sqrt{\\frac{\\ln(1/q(\\theta))}{2 m}}+M\\sqrt{\\frac{\\ln(1/\\delta)}{2 m}}.\\\\ \\end{array}\n\\]\nTaking the union bound over \\(\\theta\\), we know that the above claim holds for all \\(\\theta \\geq 1\\) with probability at least \\(1 - \\delta\\). This result, combined with the definition of \\(\\bar{\\theta}\\) in (8.2), leads to the first desired bound.\nNow by applying the Chernoff bound for an arbitrary \\(\\theta\\) that does not depend on \\(\\bar{S}_m\\), we obtain with probability at least \\(1 - \\delta / 2\\):\n\\[\nQ(\\theta,\\hat{f}_{\\theta},\\bar{\\mathcal{S}}_{m})\\leq\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(\\hat{f}_{\\theta},Z)+r_{m}(q(\\theta))+M\\sqrt{\\frac{\\ln(2/\\delta)}{2 m}}.\n\\]\nBy combining this inequality with the first bound of the theorem, we obtain the second desired inequality.", "context": [{"id": "ch3:proposition:3_5", "name": "Union Bound", "statement": "(Union Bound) Consider \\(m\\) events \\(E_1, \\ldots, E_m\\). The following probability inequality holds:\n\\[\n\\Pr (E_1 \\cup \\cdots \\cup E_m) \\leq \\sum_{j=1}^{m} \\Pr(E_j).\n\\]\n\nThe union bound has an alternative expression, which is often used in the learning theory analysis. If each \\(E_j\\) occurs with probability at least \\(1-\\delta_j\\) for \\(j=1, \\ldots, m\\), then with probability at least \\(1-\\sum_{j=1}^{m} \\delta_j\\), all of events \\(\\{E_j\\}\\) occur simultaneously for \\(j=1, \\ldots, m\\)."}, {"id": "ch8:definition:8_1", "name": "definition 8.1", "statement": "Consider a loss function \\(\\phi(f, z): \\mathcal{F} \\times \\mathcal{Z} \\to \\mathbb{R}\\), and a model family \\(\\{\\mathcal{A}(\\theta, S_n): \\Theta \\times \\mathcal{Z}^n \\to \\mathcal{F}, n \\geq 0\\}\\). Consider \\(N \\geq n \\geq 0\\), and iid dataset \\(S_n \\subset S_N \\sim \\mathcal{D}^N\\). A model selection algorithm \\(\\bar{\\mathcal{A}}\\) maps \\(S_N\\) to \\(\\hat{\\theta} = \\hat{\\theta}(S_N) \\in \\Theta\\),\nand then train a model \\(\\hat{f} = \\mathcal{A}(\\hat{\\theta}(\\mathcal{S}_N), \\mathcal{S}_n) = \\bar{\\mathcal{A}}(\\mathcal{S}_N)\\). It satisfies an \\(\\epsilon_{n,N}(\\cdot, \\cdot)\\) oracle inequality if there exists \\(\\epsilon_{n,N}(\\theta, \\delta)\\), such that for all \\(\\delta \\in (0,1)\\), with probability at least \\(1 - \\delta\\) over \\(\\mathcal{S}_N\\):\n\\[\n\\phi(\\mathcal{A}(\\hat{\\theta}(\\mathcal{S}_{N}),\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{\\theta\\in\\Theta}[\\mathbb{E}_{\\mathcal{S}_{n}}\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})+\\epsilon_{n,N}(\\theta,\\delta)].\n\\]\nMore generally, a learning algorithm \\(\\bar{\\mathcal{A}}: S_N \\to \\mathcal{F}\\) is \\(\\epsilon_{n,N}(\\cdot, \\cdot)\\) adaptive to the model family \\(\\{\\mathcal{A}(\\theta, \\cdot): \\theta \\in \\Theta\\}\\) if there exists \\(\\epsilon_{n,N}(\\theta, \\delta)\\), such that for all \\(\\delta \\in (0,1)\\), with probability at least \\(1 - \\delta\\) over \\(S_N\\):\n\\[\n\\phi(\\bar{\\mathcal{A}}(\\mathcal{S}_{N}),\\mathcal{D})\\leq\\inf_{\\theta\\in\\Theta}\\left[\\mathbb{E}_{\\mathcal{S}_{n}}\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})+\\epsilon_{n,N}(\\theta,\\delta)\\right].\n\\]\nNote that we have used a slightly different notation \\(\\phi(f, Z)\\), instead of \\(\\phi(w, Z)\\) as in earlier chapters, to emphasize that in model selection, the prediction function \\(f(w, \\cdot)\\) from different models can be compared, but the parameter \\(w\\) of the functions may not be comparable when different models have different functional forms such as decision trees versus neural networks. Without causing confusion, one may consider \\(f\\) to be the function represented by \\(w\\), so that \\(\\phi(f, Z) = L(f(X), Y)\\) and \\(\\phi(w, Z) = L(f(w, X), Y)\\). Similar to Definition 3.8, we use the simplified notation\n\\[\n\\phi(f,\\mathcal{D})=\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(f,Z),\\quad\\phi(f,\\mathcal{S}_{n})=\\frac{1}{n}\\sum_{Z\\in\\mathcal{S}_{n}}\\phi(f,Z).\n\\]\nThe concept adaptivity is more general than model selection, as the algorithm does not need to choose a specific model \\(\\mathcal{A}(\\theta,\\cdot)\\) indexed by \\(\\theta\\). For example, a commonly used method to achieve adaptivity is model averaging, where we take the average of several different model outputs \\(\\hat{f}_{\\theta_j} = \\mathcal{A}(\\theta_j,\\mathcal{S}_n)\\) as\n\\[\n\\hat{f}_{\\mathrm{avg}}(x)=\\frac{1}{k}\\sum_{j=1}^{k}\\hat{f}_{\\theta_{j}}(x).\n\\]\nIf different models have the same functional form, with a vector model parameter \\( w \\in \\mathbb{R}^d \\): \\( \\hat{f}_{\\theta_j}(x) = f(\\hat{w}_j, x) \\). Then one may also average the model parameters as follows:\n\\[\n\\hat{w}_{\\mathrm{avg}}=\\frac{1}{k}\\sum_{j=1}^{k}\\hat{w}_{j}.\n\\]\nIn general, the training data \\( S_{n} \\) is a subset of \\( S_{N} \\), and we allow \\( n < N \\) in order to analyze validation methods which are commonly used in practice. In addition to the large probability bounds in Definition 8.1, one may also derive bounds that hold for expectation over \\( S_{N} \\)."}, {"id": "ch8:equation:8_2", "name": "equation (8.2)", "statement": "Given training data \\(S_n\\) and validation data \\(\\bar{S}_m\\), define the validation objective\n\\[\nQ(\\theta, f, \\bar{\\mathcal{S}}_m) = \\phi(f, \\bar{\\mathcal{S}}_m) + r_m(q(\\theta)).\n\\]\nWe select \\(\\hat{\\theta}\\) by approximate minimization:\n\\[\nQ(\\hat{\\theta}, \\mathcal{A}(\\hat{\\theta}, \\mathcal{S}_n), \\bar{\\mathcal{S}}_m) \\leq \\inf_{\\theta} Q(\\theta, \\mathcal{A}(\\theta, \\mathcal{S}_n), \\bar{\\mathcal{S}}_m) + \\tilde{\\epsilon}. \\tag{8.2}\n\\]\nHere \\(\\tilde{\\epsilon}\\) is the additive slack in the validation-based model-selection rule."}, {"id": "ch8:equation:8_1", "name": "equation (8.1)", "statement": "Let \\(q(\\theta)\\geq 0\\) for \\(\\theta = 1,2,\\ldots\\) satisfy\n\\[\n\\sum_{\\theta=1}^{\\infty} q(\\theta) \\leq 1. \\tag{8.1}\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def rPenalty (M : ℝ) (m : ℕ) (q : ℝ) : ℝ :=\n M * Real.sqrt (Real.log (1 / q) / (2 * m))\n\nnoncomputable def popLoss {F Z : Type*} [MeasurableSpace Z] (φ : F → Z → ℝ) (D : MeasureTheory.Measure Z) (f : F) : ℝ :=\n ∫ z, φ f z ∂D\n\nnoncomputable def empLoss {F Z : Type*} (φ : F → Z → ℝ) {m : ℕ} (S : Fin m → Z) (f : F) : ℝ :=\n (1 / (m : ℝ)) * ∑ i, φ f (S i)\n\nnoncomputable def Qobj {F Z Θ : Type*} (φ : F → Z → ℝ) {m : ℕ} (S : Fin m → Z)\n (M : ℝ) (q : Θ → ℝ) (θ : Θ) (f : F) : ℝ :=\n empLoss φ S f + rPenalty M m (q θ)\n\ntheorem ch8_theorem_8_2\n {F Z Θ : Type*} [MeasurableSpace Z] [Countable Θ] [Nonempty Θ]\n\n (φ : F → Z → ℝ)\n\n (D : MeasureTheory.Measure Z) [MeasureTheory.IsProbabilityMeasure D]\n\n (M : ℝ) (hM : 0 ≤ M)\n (hrange : ∀ (f : F) (z z' : Z), φ f z - φ f z' ≤ M)\n\n {m : ℕ} (hm : 0 < m)\n\n {Ω : Type*} [MeasurableSpace Ω]\n (P : MeasureTheory.Measure Ω) [MeasureTheory.IsProbabilityMeasure P]\n\n (S : Fin m → Ω → Z)\n (hSmeas : ∀ i, Measurable (S i))\n (hSindep : ProbabilityTheory.iIndepFun S P)\n (hSlaw : ∀ i, MeasureTheory.Measure.map (S i) P = D)\n\n (fhat : Θ → F)\n\n (hintg : ∀ θ, MeasureTheory.Integrable (fun z => φ (fhat θ) z) D)\n\n (hφmeas : ∀ θ, AEMeasurable (fun z => φ (fhat θ) z) D)\n\n (hφbdd : ∀ θ, ∃ a : ℝ, ∀ᵐ z ∂D, φ (fhat θ) z ∈ Set.Icc a (a + M))\n\n (hφSmeas : ∀ θ i, AEMeasurable (fun ω => φ (fhat θ) (S i ω)) P)\n\n (hφSbdd : ∀ θ, ∃ a : ℝ, ∀ i, ∀ᵐ ω ∂P, φ (fhat θ) (S i ω) ∈ Set.Icc a (a + M))\n\n (q : Θ → ℝ) (hqpos : ∀ θ, 0 < q θ) (hsummable : Summable q) (hqsum : ∑' θ, q θ ≤ 1)\n\n (εt : ℝ) (hεt : 0 ≤ εt)\n\n (thetahat : Ω → Θ)\n (hsel : ∀ ω, Qobj φ (fun i => S i ω) M q (thetahat ω) (fhat (thetahat ω))\n ≤ (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ)) + εt)\n\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n\n (hbddQ : ∀ ω, BddBelow (Set.range (fun θ => Qobj φ (fun i => S i ω) M q θ (fhat θ))))\n (hbddOr : BddBelow (Set.range (fun θ => popLoss φ D (fhat θ) + rPenalty M m (q θ)))) :\n\n (1 - δ ≤ P.real {ω |\n popLoss φ D (fhat (thetahat ω))\n ≤ (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ)) + εt\n + M * Real.sqrt (Real.log (1 / δ) / (2 * m))})\n ∧\n\n (1 - δ ≤ P.real {ω |\n popLoss φ D (fhat (thetahat ω))\n ≤ (⨅ θ, popLoss φ D (fhat θ) + rPenalty M m (q θ)) + εt\n + M * Real.sqrt (2 * Real.log (2 / δ) / m)}) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real NNReal\n\nnamespace GraduateLevel\n\nnoncomputable def rPenalty (M : ℝ) (m : ℕ) (q : ℝ) : ℝ :=\n M * Real.sqrt (Real.log (1 / q) / (2 * m))\n\nnoncomputable def popLoss {F Z : Type*} [MeasurableSpace Z] (φ : F → Z → ℝ) (D : MeasureTheory.Measure Z) (f : F) : ℝ :=\n ∫ z, φ f z ∂D\n\nnoncomputable def empLoss {F Z : Type*} (φ : F → Z → ℝ) {m : ℕ} (S : Fin m → Z) (f : F) : ℝ :=\n (1 / (m : ℝ)) * ∑ i, φ f (S i)\n\nnoncomputable def Qobj {F Z Θ : Type*} (φ : F → Z → ℝ) {m : ℕ} (S : Fin m → Z)\n (M : ℝ) (q : Θ → ℝ) (θ : Θ) (f : F) : ℝ :=\n empLoss φ S f + rPenalty M m (q θ)\n\n\nprivate lemma chernoff_core {Z Ω : Type*} [MeasurableSpace Z] [MeasurableSpace Ω]\n {D : Measure Z} [IsProbabilityMeasure D] {P : Measure Ω} [IsProbabilityMeasure P]\n {m : ℕ} (hm : 0 < m) {S : Fin m → Ω → Z} (hSmeas : ∀ i, Measurable (S i))\n (hSindep : iIndepFun S P) (hSlaw : ∀ i, Measure.map (S i) P = D)\n {M : ℝ} (hM : 0 ≤ M) {g : Z → ℝ} (hgm : AEMeasurable g D)\n {a : ℝ} (hgbdd : ∀ᵐ z ∂D, g z ∈ Set.Icc a (a + M))\n {t : ℝ} (ht0 : 0 < t) (ht1 : t ≤ 1) :\n P.real {ω | M * Real.sqrt (Real.log (1/t) / (2*m)) <\n (1/(m:ℝ)) * ∑ i, g (S i ω) - ∫ z, g z ∂D} ≤ t := by\n classical\n set g' : Z → ℝ := hgm.mk g with hg'def\n have hg'meas : Measurable g' := hgm.measurable_mk\n have hgg' : g =ᵐ[D] g' := hgm.ae_eq_mk\n obtain ⟨N, hsubN, hNmeas, hNnull⟩ := exists_measurable_superset_of_null (ae_iff.mp hgg')\n have hpre : ∀ i, P ((S i) ⁻¹' N) = 0 := by\n intro i\n rw [← Measure.map_apply (hSmeas i) hNmeas, hSlaw i]\n exact hNnull\n have hae : ∀ᵐ ω ∂P, ∀ i, g (S i ω) = g' (S i ω) := by\n rw [ae_all_iff]\n intro i\n filter_upwards [measure_zero_iff_ae_nmem.mp (hpre i)] with ω hω\n by_contra h\n exact hω (hsubN h)\n have hg'bdd : ∀ᵐ z ∂D, g' z ∈ Set.Icc a (a + M) := by\n filter_upwards [hgbdd, hgg'] with z h1 h2\n rwa [← h2]\n have hYbdd : ∀ i, ∀ᵐ ω ∂P, g' (S i ω) ∈ Set.Icc a (a + M) := by\n intro i\n have h := hg'bdd\n rw [← hSlaw i] at h\n exact (ae_map_iff (hSmeas i).aemeasurable (hg'meas measurableSet_Icc)).mp h\n have hint : ∀ i, ∫ ω, g' (S i ω) ∂P = ∫ z, g' z ∂D := by\n intro i\n rw [← hSlaw i, integral_map (hSmeas i).aemeasurable hg'meas.aestronglyMeasurable]\n have hintg : ∫ z, g z ∂D = ∫ z, g' z ∂D := integral_congr_ae hgg'\n have hmR : (0:ℝ) < m := by exact_mod_cast hm\n set L : ℝ := Real.log (1/t) with hLdef\n have hL0 : 0 ≤ L := by\n rw [hLdef, Real.log_nonneg_iff (by positivity)]\n rw [le_div_iff₀ ht0]; linarith\n set ε : ℝ := M * Real.sqrt (L / (2*m)) with hεdef\n have hε0 : 0 ≤ ε := by\n have : 0 ≤ Real.sqrt (L / (2*m)) := Real.sqrt_nonneg _\n positivity\n rcases eq_or_lt_of_le hM with hM0 | hMpos\n · -- M = 0 case\n have hMz : M = 0 := hM0.symm\n have hEa : ∀ᵐ ω ∂P, ∀ i, g' (S i ω) = a := by\n rw [ae_all_iff]\n intro i\n filter_upwards [hYbdd i] with ω hω\n have := hω.1; have h2 := hω.2\n rw [hMz] at h2; simp at h2; linarith\n have hIa : ∫ z, g' z ∂D = a := by\n rw [← hint ⟨0, hm⟩]\n have : ∀ᵐ ω ∂P, g' (S ⟨0, hm⟩ ω) = a := by\n filter_upwards [hEa] with ω hω using hω _\n rw [integral_congr_ae this]\n simp\n have hnull : P {ω | ε < (1/(m:ℝ)) * ∑ i, g (S i ω) - ∫ z, g z ∂D} = 0 := by\n have : ∀ᵐ ω ∂P, ω ∉ {ω | ε < (1/(m:ℝ)) * ∑ i, g (S i ω) - ∫ z, g z ∂D} := by\n filter_upwards [hae, hEa] with ω h1 h2\n simp only [Set.mem_setOf_eq, not_lt]\n have hsum : ∑ i, g (S i ω) = (m:ℝ) * a := by\n rw [Finset.sum_congr rfl (fun i _ => by rw [h1 i, h2 i])]\n simp [mul_comm]\n rw [hsum, hintg, hIa, hεdef, hMz]\n field_simp\n simp\n exact measure_zero_iff_ae_nmem.mpr this\n rw [Measure.real, hnull]\n simpa using ht0.le\n · -- M > 0\n set Y : Fin m → Ω → ℝ := fun i ω => g' (S i ω) with hYdef\n have hYmeas : ∀ i, AEMeasurable (Y i) P := fun i =>\n (hg'meas.comp (hSmeas i)).aemeasurable\n have hYindep : iIndepFun Y P := hSindep.comp (fun _ => g') (fun _ => hg'meas)\n have hsubG : ∀ i, HasSubgaussianMGF (fun ω => Y i ω - P[Y i]) ((‖(a+M) - a‖₊ / 2)^2) P :=\n fun i => hasSubgaussianMGF_of_mem_Icc (hYmeas i) (hYbdd i)\n have hYindep' : iIndepFun (fun i ω => Y i ω - P[Y i]) P := by\n show iIndepFun (fun i => (fun x : ℝ => x - P[Y i]) ∘ Y i) P\n exact hYindep.comp _ (fun i => measurable_id.sub measurable_const)\n have hkey := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun (μ := P)\n (s := (Finset.univ : Finset (Fin m))) hYindep' (fun i _ => hsubG i)\n (ε := (m:ℝ) * ε) (by positivity)\n have hEY : ∀ i, P[Y i] = ∫ z, g' z ∂D := fun i => hint i\n have hsubset : {ω | ε < (1/(m:ℝ)) * ∑ i, g (S i ω) - ∫ z, g z ∂D} ≤ᵐ[P]\n {ω | (m:ℝ) * ε ≤ ∑ i : Fin m, (Y i ω - P[Y i])} := by\n filter_upwards [hae] with ω h1 hmem\n show (m:ℝ) * ε ≤ ∑ i : Fin m, (Y i ω - P[Y i])\n have hsum : ∑ i, g (S i ω) = ∑ i, Y i ω := Finset.sum_congr rfl (fun i _ => h1 i)\n have : ∑ i : Fin m, (Y i ω - P[Y i]) = (∑ i, Y i ω) - (m:ℝ) * ∫ z, g' z ∂D := by\n simp [Finset.sum_sub_distrib, hEY, mul_comm]\n rw [this, ← hsum]\n rw [hintg] at hmem\n have hEq : (m:ℝ) * ((1/(m:ℝ)) * ∑ i, g (S i ω) - ∫ z, g' z ∂D)\n = ∑ i, g (S i ω) - (m:ℝ) * ∫ z, g' z ∂D := by\n field_simp\n have h2 := mul_lt_mul_of_pos_left hmem hmR\n rw [hEq] at h2\n linarith\n have hmono : P.real {ω | ε < (1/(m:ℝ)) * ∑ i, g (S i ω) - ∫ z, g z ∂D} ≤\n P.real {ω | (m:ℝ) * ε ≤ ∑ i : Fin m, (Y i ω - P[Y i])} := by\n apply ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono_ae hsubset)\n refine hmono.trans (hkey.trans ?_)\n have hnn : (‖(a+M) - a‖₊ : ℝ) = M := by\n simp [abs_of_nonneg hM]\n have hcsum : ((∑ _i : Fin m, ((‖(a+M) - a‖₊ / 2)^2 : NNReal) : NNReal) : ℝ) = (m:ℝ) * (M/2)^2 := by\n push_cast [hnn]\n simp [Finset.sum_const, Finset.card_univ]\n rw [hcsum]\n have hsq : ((m:ℝ) * ε)^2 = (m:ℝ) * M^2 * L / 2 := by\n rw [hεdef]\n have : Real.sqrt (L / (2*m)) ^ 2 = L / (2*m) := Real.sq_sqrt (by positivity)\n rw [mul_pow, mul_pow, this]\n field_simp\n rw [hsq]\n have : -((m:ℝ) * M ^ 2 * L / 2) / (2 * ((m:ℝ) * (M / 2) ^ 2)) = -L := by\n field_simp\n rw [this, hLdef, Real.log_div one_ne_zero (ne_of_gt ht0)]\n simp [Real.exp_log ht0]\n\nprivate lemma prob_good {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P]\n {G : Set Ω} {d : ℝ} (hd0 : 0 ≤ d) (hd : P Gᶜ ≤ ENNReal.ofReal d) : 1 - d ≤ P.real G := by\n have h1 : (1:ENNReal) ≤ P G + P Gᶜ := by\n calc (1:ENNReal) = P Set.univ := measure_univ.symm\n _ = P (G ∪ Gᶜ) := by rw [Set.union_compl_self]\n _ ≤ P G + P Gᶜ := measure_union_le _ _\n have hfin : P G + P Gᶜ ≠ ⊤ := by finiteness\n have h2 : (1:ℝ) ≤ P.real G + P.real Gᶜ := by\n have := ENNReal.toReal_mono hfin h1\n rwa [ENNReal.toReal_add (measure_ne_top _ _) (measure_ne_top _ _), ENNReal.toReal_one] at this\n have h3 : P.real Gᶜ ≤ d := by\n have := ENNReal.toReal_mono ENNReal.ofReal_ne_top hd\n rwa [ENNReal.toReal_ofReal hd0] at this\n linarith\n\nprivate lemma sqrt_add_le {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) :\n Real.sqrt (A + B) ≤ Real.sqrt A + Real.sqrt B := by\n nlinarith [Real.sq_sqrt hA, Real.sq_sqrt hB, Real.sq_sqrt (add_nonneg hA hB),\n Real.sqrt_nonneg A, Real.sqrt_nonneg B, Real.sqrt_nonneg (A+B),\n mul_nonneg (Real.sqrt_nonneg A) (Real.sqrt_nonneg B)]\n\ntheorem ch8_theorem_8_2\n {F Z Θ : Type*} [MeasurableSpace Z] [Countable Θ] [Nonempty Θ]\n\n (φ : F → Z → ℝ)\n\n (D : MeasureTheory.Measure Z) [MeasureTheory.IsProbabilityMeasure D]\n\n (M : ℝ) (hM : 0 ≤ M)\n (hrange : ∀ (f : F) (z z' : Z), φ f z - φ f z' ≤ M)\n\n {m : ℕ} (hm : 0 < m)\n\n {Ω : Type*} [MeasurableSpace Ω]\n (P : MeasureTheory.Measure Ω) [MeasureTheory.IsProbabilityMeasure P]\n\n (S : Fin m → Ω → Z)\n (hSmeas : ∀ i, Measurable (S i))\n (hSindep : ProbabilityTheory.iIndepFun S P)\n (hSlaw : ∀ i, MeasureTheory.Measure.map (S i) P = D)\n\n (fhat : Θ → F)\n\n (hintg : ∀ θ, MeasureTheory.Integrable (fun z => φ (fhat θ) z) D)\n\n (hφmeas : ∀ θ, AEMeasurable (fun z => φ (fhat θ) z) D)\n\n (hφbdd : ∀ θ, ∃ a : ℝ, ∀ᵐ z ∂D, φ (fhat θ) z ∈ Set.Icc a (a + M))\n\n (hφSmeas : ∀ θ i, AEMeasurable (fun ω => φ (fhat θ) (S i ω)) P)\n\n (hφSbdd : ∀ θ, ∃ a : ℝ, ∀ i, ∀ᵐ ω ∂P, φ (fhat θ) (S i ω) ∈ Set.Icc a (a + M))\n\n (q : Θ → ℝ) (hqpos : ∀ θ, 0 < q θ) (hsummable : Summable q) (hqsum : ∑' θ, q θ ≤ 1)\n\n (εt : ℝ) (hεt : 0 ≤ εt)\n\n (thetahat : Ω → Θ)\n (hsel : ∀ ω, Qobj φ (fun i => S i ω) M q (thetahat ω) (fhat (thetahat ω))\n ≤ (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ)) + εt)\n\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1)\n\n (hbddQ : ∀ ω, BddBelow (Set.range (fun θ => Qobj φ (fun i => S i ω) M q θ (fhat θ))))\n (hbddOr : BddBelow (Set.range (fun θ => popLoss φ D (fhat θ) + rPenalty M m (q θ)))) :\n\n (1 - δ ≤ P.real {ω |\n popLoss φ D (fhat (thetahat ω))\n ≤ (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ)) + εt\n + M * Real.sqrt (Real.log (1 / δ) / (2 * m))})\n ∧\n\n (1 - δ ≤ P.real {ω |\n popLoss φ D (fhat (thetahat ω))\n ≤ (⨅ θ, popLoss φ D (fhat θ) + rPenalty M m (q θ)) + εt\n + M * Real.sqrt (2 * Real.log (2 / δ) / m)}) := by\n classical\n have hmR : (0:ℝ) < m := by exact_mod_cast hm\n have hq1 : ∀ θ, q θ ≤ 1 := by\n intro θ\n have h := hsummable.sum_le_tsum ({θ} : Finset Θ) (fun b _ => (hqpos b).le)\n rw [Finset.sum_singleton] at h\n linarith [hqsum]\n -- one-sided deviation bounds\n have hdev_lo : ∀ (θ : Θ) (t : ℝ), 0 < t → t ≤ 1 →\n P.real {ω | M * Real.sqrt (Real.log (1/t) / (2*m)) <\n popLoss φ D (fhat θ) - empLoss φ (fun i => S i ω) (fhat θ)} ≤ t := by\n intro θ t ht0 ht1\n obtain ⟨a, ha⟩ := hφbdd θ\n have := chernoff_core (D := D) (P := P) hm hSmeas hSindep hSlaw hM\n (g := fun z => -φ (fhat θ) z) ((hφmeas θ).neg) (a := -(a+M))\n (by filter_upwards [ha] with z hz; constructor <;> [linarith [hz.2]; linarith [hz.1]])\n ht0 ht1\n refine le_trans (le_of_eq ?_) this\n congr 1\n ext ω\n simp only [Set.mem_setOf_eq, popLoss, empLoss, integral_neg, Finset.sum_neg_distrib]\n constructor <;> intro h <;> linarith\n have hdev_hi : ∀ (θ : Θ) (t : ℝ), 0 < t → t ≤ 1 →\n P.real {ω | M * Real.sqrt (Real.log (1/t) / (2*m)) <\n empLoss φ (fun i => S i ω) (fhat θ) - popLoss φ D (fhat θ)} ≤ t := by\n intro θ t ht0 ht1\n obtain ⟨a, ha⟩ := hφbdd θ\n have := chernoff_core (D := D) (P := P) hm hSmeas hSindep hSlaw hM\n (g := fun z => φ (fhat θ) z) (hφmeas θ) (a := a) ha ht0 ht1\n exact this\n -- splitting the penalty\n have hsplit : ∀ (x d : ℝ), 0 < x → x ≤ 1 → 0 < d → d ≤ 1 →\n M * Real.sqrt (Real.log (1/(x*d)) / (2*m))\n ≤ rPenalty M m x + M * Real.sqrt (Real.log (1/d) / (2*m)) := by\n intro x d hx0 hx1 hd0 hd1\n have hlog : Real.log (1/(x*d)) = Real.log (1/x) + Real.log (1/d) := by\n rw [one_div, one_div, one_div, mul_inv, Real.log_mul (by positivity) (by positivity)]\n have hA : (0:ℝ) ≤ Real.log (1/x) / (2*m) := by\n apply div_nonneg _ (by positivity)\n apply Real.log_nonneg\n rw [le_div_iff₀ hx0]; linarith\n have hB : (0:ℝ) ≤ Real.log (1/d) / (2*m) := by\n apply div_nonneg _ (by positivity)\n apply Real.log_nonneg\n rw [le_div_iff₀ hd0]; linarith\n have := sqrt_add_le hA hB\n have h2 : Real.log (1/(x*d)) / (2*(m:ℝ))\n = Real.log (1/x) / (2*m) + Real.log (1/d) / (2*m) := by\n rw [hlog]; ring\n rw [rPenalty, h2]\n have := mul_le_mul_of_nonneg_left (sqrt_add_le hA hB) hM\n linarith [this]\n -- main union-bound step\n have main1 : ∀ d : ℝ, 0 < d → d < 1 →\n P {ω | popLoss φ D (fhat (thetahat ω))\n ≤ (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ)) + εt\n + M * Real.sqrt (Real.log (1 / d) / (2 * m))}ᶜ ≤ ENNReal.ofReal d := by\n intro d hd0 hd1\n set Bad : Θ → Set Ω := fun θ => {ω | M * Real.sqrt (Real.log (1/(q θ * d)) / (2*m)) <\n popLoss φ D (fhat θ) - empLoss φ (fun i => S i ω) (fhat θ)} with hBad\n have hBadbd : ∀ θ, P.real (Bad θ) ≤ q θ * d := by\n intro θ\n exact hdev_lo θ (q θ * d) (mul_pos (hqpos θ) hd0)\n (by nlinarith [hq1 θ, (hqpos θ).le, hd0.le, hd1.le])\n have hsubset : {ω | popLoss φ D (fhat (thetahat ω))\n ≤ (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ)) + εt\n + M * Real.sqrt (Real.log (1 / d) / (2 * m))}ᶜ ⊆ ⋃ θ, Bad θ := by\n intro ω hω\n by_contra hcon\n simp only [Set.mem_iUnion, not_exists, hBad, Set.mem_setOf_eq, not_lt] at hcon\n apply hω\n simp only [Set.mem_setOf_eq]\n have h1 := hcon (thetahat ω)\n have h2 := hsel ω\n have h3 := hsplit (q (thetahat ω)) d (hqpos _) (hq1 _) hd0 hd1.le\n simp only [Qobj] at h2 ⊢\n linarith\n have hbound : P (⋃ θ, Bad θ) ≤ ENNReal.ofReal d := by\n refine le_trans (measure_iUnion_le _) ?_\n have hstep : ∀ θ, P (Bad θ) ≤ ENNReal.ofReal (q θ * d) := by\n intro θ\n have h := hBadbd θ\n rw [← ENNReal.ofReal_toReal (measure_ne_top P (Bad θ))]\n exact ENNReal.ofReal_le_ofReal h\n refine le_trans (ENNReal.tsum_le_tsum hstep) ?_\n rw [← ENNReal.ofReal_tsum_of_nonneg (fun θ => mul_nonneg (hqpos θ).le hd0.le)\n (hsummable.mul_right d)]\n apply ENNReal.ofReal_le_ofReal\n have hmr : ∑' θ, q θ * d = (∑' θ, q θ) * d := tsum_mul_right\n rw [hmr]\n have h6 : (∑' θ, q θ) * d ≤ 1 * d := mul_le_mul_of_nonneg_right hqsum hd0.le\n linarith\n exact le_trans (measure_mono hsubset) hbound\n have hδ2 : (0:ℝ) < δ/2 := by linarith\n have hδ21 : δ/2 < 1 := by linarith\n constructor\n · exact prob_good hδ0.le (main1 δ hδ0 hδ1)\n · -- second bound\n set C : ℝ := ⨅ θ, popLoss φ D (fhat θ) + rPenalty M m (q θ) with hC\n have hK2 : 2 * (M * Real.sqrt (Real.log (1/(δ/2)) / (2*m)))\n = M * Real.sqrt (2 * Real.log (2/δ) / m) := by\n rw [one_div_div]\n have h4 : (4:ℝ) * (Real.log (2/δ) / (2*m)) = 2 * Real.log (2/δ) / m := by\n field_simp; ring\n rw [← h4, show (4:ℝ) = 2^2 by norm_num, Real.sqrt_mul (by positivity),\n Real.sqrt_sq (by norm_num)]\n ring\n have hstep : ∀ η : ℝ, 0 < η →\n P {ω | popLoss φ D (fhat (thetahat ω)) ≤ C + εt + M * Real.sqrt (2 * Real.log (2 / δ) / m) + η}ᶜ ≤ ENNReal.ofReal δ := by\n intro η hη\n obtain ⟨θ₀, hθ₀⟩ : ∃ θ, popLoss φ D (fhat θ) + rPenalty M m (q θ) < C + η :=\n exists_lt_of_ciInf_lt (by rw [← hC]; linarith)\n set F : Set Ω := {ω | M * Real.sqrt (Real.log (1/(δ/2)) / (2*m)) <\n empLoss φ (fun i => S i ω) (fhat θ₀) - popLoss φ D (fhat θ₀)} with hF\n have hFbd : P F ≤ ENNReal.ofReal (δ/2) := by\n have h := hdev_hi θ₀ (δ/2) hδ2 hδ21.le\n rw [← ENNReal.ofReal_toReal (measure_ne_top P F)]\n exact ENNReal.ofReal_le_ofReal h\n set G1 : Set Ω := {ω | popLoss φ D (fhat (thetahat ω))\n ≤ (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ)) + εt\n + M * Real.sqrt (Real.log (1 / (δ/2)) / (2 * m))} with hG1\n have hsub : {ω | popLoss φ D (fhat (thetahat ω)) ≤ C + εt + M * Real.sqrt (2 * Real.log (2 / δ) / m) + η}ᶜ ⊆ G1ᶜ ∪ F := by\n intro ω hω\n by_contra hcon\n simp only [Set.mem_union, not_or, Set.mem_compl_iff, not_not] at hcon\n obtain ⟨h1, h2⟩ := hcon\n apply hω\n simp only [Set.mem_setOf_eq]\n simp only [hG1, Set.mem_setOf_eq] at h1\n simp only [hF, Set.mem_setOf_eq, not_lt] at h2\n have h3 : (⨅ θ, Qobj φ (fun i => S i ω) M q θ (fhat θ))\n ≤ Qobj φ (fun i => S i ω) M q θ₀ (fhat θ₀) := ciInf_le (hbddQ ω) θ₀\n simp only [Qobj] at h1 h3\n rw [← hK2]\n linarith\n refine le_trans (measure_mono hsub) ?_\n refine le_trans (measure_union_le _ _) ?_\n have := main1 (δ/2) hδ2 hδ21\n calc P G1ᶜ + P F ≤ ENNReal.ofReal (δ/2) + ENNReal.ofReal (δ/2) :=\n add_le_add this hFbd\n _ = ENNReal.ofReal δ := by\n rw [← ENNReal.ofReal_add hδ2.le hδ2.le]; norm_num\n refine prob_good hδ0.le ?_\n have hcompl : {ω | popLoss φ D (fhat (thetahat ω)) ≤ C + εt + M * Real.sqrt (2 * Real.log (2 / δ) / m)}ᶜ\n = ⋃ n : ℕ, {ω | popLoss φ D (fhat (thetahat ω)) ≤ C + εt + M * Real.sqrt (2 * Real.log (2 / δ) / m) + 1/(n+1)}ᶜ := by\n ext ω\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, Set.mem_iUnion, not_le]\n constructor\n · intro h\n obtain ⟨n, hn⟩ := exists_nat_one_div_lt (show (0:ℝ) < popLoss φ D (fhat (thetahat ω)) - (C + εt + M * Real.sqrt (2 * Real.log (2 / δ) / m)) by linarith)\n exact ⟨n, by linarith⟩\n · rintro ⟨n, hn⟩\n have : (0:ℝ) < 1/((n:ℝ)+1) := by positivity\n linarith\n have hmono : Monotone (fun n : ℕ => {ω | popLoss φ D (fhat (thetahat ω)) ≤ C + εt + M * Real.sqrt (2 * Real.log (2 / δ) / m) + 1/(n+1)}ᶜ) := by\n intro n k hnk ω hω\n simp only [Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hω ⊢\n have : (1:ℝ)/((k:ℝ)+1) ≤ 1/((n:ℝ)+1) := by\n apply one_div_le_one_div_of_le (by positivity)\n have : (n:ℝ) ≤ k := by exact_mod_cast hnk\n linarith\n linarith\n rw [hcompl, hmono.measure_iUnion (μ := P)]\n refine iSup_le (fun n => hstep _ (by positivity))\n\n\nend GraduateLevel"} +{"id": "ch14_theorem_14_15", "source": "Graduate-level", "targets": [{"label": "ch14_theorem_14_15", "decls": ["ch14_theorem_14_15"], "statement": "Assume that for all \\(t\\):\n\\[\n\\sup_{w\\in\\Omega}\\ell_{t}(w)-\\inf_{w\\in\\Omega}\\ell_{t}(w)\\leq M,\n\\]\nthen Algorithm 14.4 has regret\n\\[\n\\sum_{t=1}^{T}\\mathbb{E}_{w_{t-1}\\sim p_{t-1}(\\cdot)}\\ell_{t}(w_{t-1})\\leq\\inf_{p\\in\\Delta(\\Omega)}\\left[\\mathbb{E}_{w\\sim p}\\sum_{t=1}^{T}\\ell_{t}(w)+\\frac{1}{\\eta}\\mathrm{KL}(p| |p_{0})\\right]+\\frac{\\eta TM^{2}}{8},\n\\]\nwhere \\(\\Delta (\\Omega)\\) denotes the set of probability distributions on \\(\\Omega\\)", "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}], "nl_proof": "Let\n\\[\nZ_{t}= -\\ln\\mathbb{E}_{w\\sim p_{0}}\\exp\\left(-\\eta\\sum_{s=1}^{t}\\ell_{s}(w)\\right)\n\\]\nbe the log-partition function for observations up to time \\( t \\). We have\n\\[\n\\begin{array}{l}Z_{t-1}-Z_{t}=\\ln\\mathbb{E}_{w\\sim p_{t-1}}\\exp(-\\eta\\ell_{t}(w))\\\\ \\leq-\\eta\\mathbb{E}_{w\\sim p_{t-1}}\\ell_{t}(w)+\\frac{\\eta^{2}M^{2}}{8},\\\\ \\end{array}\n\\]\nwhere the first equation is simple algebra, and the inequality follows from the estimate of logarithmic moment generation function in Lemma 2.15. By summing\nover \\(t = 1\\) to \\(T\\), and noticing that \\(Z_{0} = 0\\), we obtain\n\\[\n\\sum_{t=1}^{T}\\mathbb{E}_{w_{t-1}\\sim p_{t-1}(\\cdot)}\\ell_{t}(w_{t-1})\\leq\\frac{1}{\\eta}Z_{T}+\\frac{\\eta T M^{2}}{8}.\n\\]\nThe desired bound follows by applying Proposition 7.16 to reformulate the log-partition function \\( Z_{T} \\).", "context": [{"id": "ch14:algorithm:14_4", "name": "Hedge Algorithm", "statement": "Hedge Algorithm\nInput: \\(T\\), prior \\(p_{0}(w)\\) on \\(\\Omega\\), learning rate \\(\\eta > 0\\)\n1 Randomly draw \\(w_{0} \\sim p_{0}(w)\\)\n2 for \\(t = 1, 2, \\ldots, T\\) do\n3 \\quad Observe loss \\(\\ell_{t}(w_{t-1})\\)\n4 \\quad Randomly draw \\(w_{t} \\sim p_{t}(w)\\) according to \\((14.9)\\)"}, {"id": "ch2:lemma:2_15", "name": "lemma 2.15", "statement": "Consider a random variable \\(X \\in [0,1]\\) and \\(\\mathbb{E}X = \\mu\\). We have the following inequality:\n\\[\n\\ln\\mathbb{E}e^{\\lambda X}\\leq\\ln [(1-\\mu)e^{0}+\\mu e^{\\lambda}]\\leq\\lambda\\mu+\\lambda^{2}/8.\n\\]"}, {"id": "ch7:proposition:7_16", "name": "proposition 7.16", "statement": "Given any function \\(U(w)\\), we have\n\\[\n\\min_{p\\in\\Delta(\\Omega)}\\left[\\mathbb{E}_{w\\sim p}U(w)+\\mathrm{KL}(p| |p_{0})\\right]= -\\ln\\mathbb{E}_{w\\sim p_{0}}\\exp(-U(w)),\n\\]\nand the solution is achieved by the Gibbs distribution \\( q(w) \\propto p_0(w) \\exp(-U(w)) \\). Here \\( \\Delta(\\Omega) \\) denotes the set of probability distributions on \\( \\Omega \\)."}, {"id": "ch14:proposition:14_14", "name": "proposition 14.14", "statement": "Consider \\(\\Omega = \\{w_0, w_1, \\ldots, w_T\\}\\) that contains \\(T\\) members. Given any deterministic online learning algorithm \\(\\mathcal{A}\\) that returns a model parameter \\(w_{t-1}\\) based on \\(\\{\\ell_s : s = 1, \\ldots, t-1\\}\\), there exists a loss sequence \\(\\ell_t(w) \\in \\{0, 1\\}\\) so that\n\\[\n\\inf_{w}\\sum_{t=1}^{T}\\ell_{t}(w)=0,\\qquad\\sum_{t=1}^{T}\\ell_{t}(w_{t-1})=T.\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\nnoncomputable abbrev klDiv {α : Type*} [MeasurableSpace α] (μ ν : Measure α) : ℝ≥0∞ :=\n _root_.InformationTheory.klDiv μ ν\n\n\ntheorem ch14_theorem_14_15\n {Ω : Type*} [MeasurableSpace Ω] [Nonempty Ω]\n (T : ℕ) (η M : ℝ) (hη : 0 < η)\n (ℓ : ℕ → Ω → ℝ)\n (p₀ : Measure Ω) [IsProbabilityMeasure p₀]\n (p : ℕ → Measure Ω) (hp₀ : p 0 = p₀)\n (hp : ∀ t < T, IsProbabilityMeasure (p t))\n (hpt_ac : ∀ t < T, p t ≪ p₀)\n (hℓmeas : ∀ t < T, Measurable (ℓ (t + 1)))\n (hℓint : ∀ t < T, Integrable (ℓ (t + 1)) (p t))\n (hℓintq : ∀ t < T, ∀ q : Measure Ω, IsProbabilityMeasure q → q ≪ p₀ →\n Integrable (ℓ (t + 1)) q)\n (hbdd : ∀ t < T, BddAbove (Set.range (ℓ (t + 1))) ∧ BddBelow (Set.range (ℓ (t + 1))))\n (hgibbs : ∀ t < T, ∃ Z : ℝ, 0 < Z ∧\n (p t).rnDeriv p₀ =ᵐ[p₀]\n fun w => ENNReal.ofReal (Real.exp (-η * (∑ s ∈ Finset.range t, ℓ (s + 1) w)) / Z))\n (hosc : ∀ t < T, (⨆ w, ℓ (t + 1) w) - (⨅ w, ℓ (t + 1) w) ≤ M) :\n ∀ q : Measure Ω, IsProbabilityMeasure q → q ≪ p₀ →\n GraduateLevel.klDiv q p₀ ≠ ⊤ →\n (∑ t ∈ Finset.range T, ∫ w, ℓ (t + 1) w ∂(p t))\n ≤ (∫ w, (∑ t ∈ Finset.range T, ℓ (t + 1) w) ∂q)\n + (1 / η) * (GraduateLevel.klDiv q p₀).toReal\n + η * (T : ℝ) * M ^ 2 / 8 := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nnoncomputable abbrev klDiv {α : Type*} [MeasurableSpace α] (μ ν : Measure α) : ℝ≥0∞ :=\n _root_.InformationTheory.klDiv μ ν\n\n\ntheorem ch14_theorem_14_15\n {Ω : Type*} [MeasurableSpace Ω] [Nonempty Ω]\n (T : ℕ) (η M : ℝ) (hη : 0 < η)\n (ℓ : ℕ → Ω → ℝ)\n (p₀ : Measure Ω) [IsProbabilityMeasure p₀]\n (p : ℕ → Measure Ω) (hp₀ : p 0 = p₀)\n (hp : ∀ t < T, IsProbabilityMeasure (p t))\n (hpt_ac : ∀ t < T, p t ≪ p₀)\n (hℓmeas : ∀ t < T, Measurable (ℓ (t + 1)))\n (hℓint : ∀ t < T, Integrable (ℓ (t + 1)) (p t))\n (hℓintq : ∀ t < T, ∀ q : Measure Ω, IsProbabilityMeasure q → q ≪ p₀ →\n Integrable (ℓ (t + 1)) q)\n (hbdd : ∀ t < T, BddAbove (Set.range (ℓ (t + 1))) ∧ BddBelow (Set.range (ℓ (t + 1))))\n (hgibbs : ∀ t < T, ∃ Z : ℝ, 0 < Z ∧\n (p t).rnDeriv p₀ =ᵐ[p₀]\n fun w => ENNReal.ofReal (Real.exp (-η * (∑ s ∈ Finset.range t, ℓ (s + 1) w)) / Z))\n (hosc : ∀ t < T, (⨆ w, ℓ (t + 1) w) - (⨅ w, ℓ (t + 1) w) ≤ M) :\n ∀ q : Measure Ω, IsProbabilityMeasure q → q ≪ p₀ →\n GraduateLevel.klDiv q p₀ ≠ ⊤ →\n (∑ t ∈ Finset.range T, ∫ w, ℓ (t + 1) w ∂(p t))\n ≤ (∫ w, (∑ t ∈ Finset.range T, ℓ (t + 1) w) ∂q)\n + (1 / η) * (GraduateLevel.klDiv q p₀).toReal\n + η * (T : ℝ) * M ^ 2 / 8 := by\n classical\n intro q hq hqac hkl\n set S : ℕ → Ω → ℝ := fun t w => ∑ s ∈ Finset.range t, ℓ (s + 1) w with hSdef\n set A : ℕ → ℝ := fun t => ∫ w, Real.exp (-η * S t w) ∂p₀ with hAdef\n have hSsucc : ∀ t w, S (t + 1) w = S t w + ℓ (t + 1) w := by\n intro t w; simp [hSdef, Finset.sum_range_succ]\n have hmeasS : ∀ t, t ≤ T → Measurable (S t) := by\n intro t ht\n refine Finset.measurable_sum _ ?_\n intro s hs\n exact hℓmeas s (lt_of_lt_of_le (Finset.mem_range.mp hs) ht)\n have hboundS : ∀ t, t ≤ T → ∃ C : ℝ, ∀ w, |S t w| ≤ C := by\n intro t\n induction t with\n | zero => intro _; exact ⟨0, by intro w; simp [hSdef]⟩\n | succ n ih =>\n intro ht\n obtain ⟨C, hC⟩ := ih (Nat.le_of_succ_le ht)\n obtain ⟨hu, hl⟩ := hbdd n (Nat.lt_of_succ_le ht)\n obtain ⟨b, hb⟩ := hu\n obtain ⟨a, ha⟩ := hl\n refine ⟨C + (|a| + |b|), fun w => ?_⟩\n have h1 : ℓ (n + 1) w ≤ b := hb ⟨w, rfl⟩\n have h2 : a ≤ ℓ (n + 1) w := ha ⟨w, rfl⟩\n have h3 := hC w\n have h4 : |ℓ (n + 1) w| ≤ |a| + |b| := by\n rw [abs_le]\n constructor\n · have := neg_abs_le a\n have := abs_nonneg b\n linarith\n · have := le_abs_self b\n have := abs_nonneg a\n linarith\n have h5 : |S (n + 1) w| ≤ |S n w| + |ℓ (n + 1) w| := by\n rw [hSsucc]; exact abs_add_le _ _\n linarith\n have hintexp : ∀ t, t ≤ T → ∀ (μ : Measure Ω), IsFiniteMeasure μ →\n Integrable (fun w => Real.exp (-η * S t w)) μ := by\n intro t ht μ hμ\n obtain ⟨C, hC⟩ := hboundS t ht\n have hm : Measurable (fun w => Real.exp (-η * S t w)) :=\n Real.measurable_exp.comp ((hmeasS t ht).const_mul _)\n refine Integrable.mono' (integrable_const (Real.exp (η * C))) hm.aestronglyMeasurable ?_\n filter_upwards with w\n rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.2\n have h6 := (abs_le.1 (hC w)).1\n nlinarith [hη.le]\n have hApos : ∀ t, t ≤ T → 0 < A t := by\n intro t ht\n simp only [hAdef]\n exact integral_exp_pos (hintexp t ht p₀ inferInstance)\n have hA0 : A 0 = 1 := by\n simp [hAdef, hSdef]\n -- Step 1 : the Gibbs measure is a tilted measure\n have hkey1 : ∀ t, t < T → p t = p₀.tilted (fun w => -η * S t w) := by\n intro t ht\n obtain ⟨Z, hZ, hZeq⟩ := hgibbs t ht\n have hpt : IsProbabilityMeasure (p t) := hp t ht\n have hac : p t ≪ p₀ := hpt_ac t ht\n have hint : Integrable (fun w => Real.exp (-η * S t w)) p₀ := hintexp t ht.le p₀ inferInstance\n have hZeq' : (p t).rnDeriv p₀ =ᵐ[p₀]\n fun w => ENNReal.ofReal (Real.exp (-η * S t w) / Z) := hZeq\n have hZA : Z = A t := by\n have h1 : ∫⁻ w, (p t).rnDeriv p₀ w ∂p₀ = 1 := by\n rw [Measure.lintegral_rnDeriv hac]; simp\n have h2 : ∫⁻ w, (p t).rnDeriv p₀ w ∂p₀\n = ∫⁻ w, ENNReal.ofReal (Real.exp (-η * S t w) / Z) ∂p₀ := lintegral_congr_ae hZeq'\n have h3 : ∫⁻ w, ENNReal.ofReal (Real.exp (-η * S t w) / Z) ∂p₀\n = ENNReal.ofReal (A t / Z) := by\n rw [← ofReal_integral_eq_lintegral_ofReal (hint.div_const Z)\n (by filter_upwards with w; positivity)]\n congr 1\n rw [integral_div]\n rw [h2, h3] at h1\n have h4 : A t / Z = 1 := by\n have := (ENNReal.ofReal_eq_one).1 h1\n exact this\n field_simp at h4\n linarith\n have hmeas : AEMeasurable (fun w => -η * S t w) p₀ :=\n ((hmeasS t ht.le).const_mul _).aemeasurable\n have hrn := MeasureTheory.rnDeriv_tilted_left_self (μ := p₀) (f := fun w => -η * S t w) hmeas\n have hrn2 : (p t).rnDeriv p₀ =ᵐ[p₀] (p₀.tilted (fun w => -η * S t w)).rnDeriv p₀ := by\n refine hZeq'.trans (Filter.EventuallyEq.symm (hrn.trans ?_))\n filter_upwards with w\n simp only [hZA, hAdef]\n calc p t = p₀.withDensity ((p t).rnDeriv p₀) :=\n (Measure.withDensity_rnDeriv_eq _ _ hac).symm\n _ = p₀.withDensity ((p₀.tilted (fun w => -η * S t w)).rnDeriv p₀) :=\n withDensity_congr_ae hrn2\n _ = p₀.tilted (fun w => -η * S t w) :=\n Measure.withDensity_rnDeriv_eq _ _ (tilted_absolutelyContinuous _ _)\n -- Step 2 : the recursion for the partition function\n have hkey2 : ∀ t, t < T → A (t + 1) = A t * ∫ w, Real.exp (-η * ℓ (t + 1) w) ∂(p t) := by\n intro t ht\n have hApos' := hApos t ht.le\n rw [hkey1 t ht, integral_exp_tilted]\n have hEq : (∫ x, Real.exp (((fun w => -η * S t w) + fun w => -η * ℓ (t + 1) w) x) ∂p₀)\n = A (t + 1) := by\n simp only [hAdef, Pi.add_apply]\n refine integral_congr_ae (Filter.Eventually.of_forall fun w => ?_)\n simp only [Pi.add_apply, hSsucc]\n congr 1\n ring\n rw [show (∫ x, Real.exp ((fun w => -η * S t w) x) ∂p₀) = A t from rfl]\n rw [hEq]\n field_simp\n -- Step 3 : Hoeffding's lemma\n have hkey3 : ∀ t, t < T → (∫ w, Real.exp (-η * ℓ (t + 1) w) ∂(p t))\n ≤ Real.exp (-η * (∫ w, ℓ (t + 1) w ∂(p t)) + η ^ 2 * M ^ 2 / 8) := by\n intro t ht\n have hpt : IsProbabilityMeasure (p t) := hp t ht\n obtain ⟨hu, hl⟩ := hbdd t ht\n set a := ⨅ w, ℓ (t + 1) w with hadef\n set b := ⨆ w, ℓ (t + 1) w with hbdef\n have hab : ∀ w, ℓ (t + 1) w ∈ Set.Icc a b := by\n intro w\n exact ⟨ciInf_le hl w, le_ciSup hu w⟩\n have hMle : b - a ≤ M := hosc t ht\n have hba : 0 ≤ b - a := by\n obtain ⟨w⟩ := ‹Nonempty Ω›\n have h := hab w\n have h1 := h.1\n have h2 := h.2\n linarith\n have hsg := ProbabilityTheory.hasSubgaussianMGF_of_mem_Icc (μ := p t) (X := ℓ (t + 1))\n (hℓmeas t ht).aemeasurable (Filter.Eventually.of_forall hab)\n have hmgf := hsg.mgf_le (-η)\n set E := ∫ w, ℓ (t + 1) w ∂(p t) with hEdef\n have hmgf_eq : mgf (fun w => ℓ (t + 1) w - E) (p t) (-η)\n = Real.exp (η * E) * ∫ w, Real.exp (-η * ℓ (t + 1) w) ∂(p t) := by\n rw [mgf, ← integral_const_mul]\n refine integral_congr_ae (Filter.Eventually.of_forall fun w => ?_)\n simp only [← Real.exp_add]\n congr 1\n ring\n have hc : (((‖b - a‖₊ / 2 : ℝ≥0) ^ 2 : ℝ≥0) : ℝ) ≤ M ^ 2 / 4 := by\n push_cast\n rw [Real.norm_eq_abs, abs_of_nonneg hba]\n nlinarith\n have hcpos : (0:ℝ) ≤ (((‖b - a‖₊ / 2 : ℝ≥0) ^ 2 : ℝ≥0) : ℝ) := by positivity\n have hbound : Real.exp (η * E) * (∫ w, Real.exp (-η * ℓ (t + 1) w) ∂(p t))\n ≤ Real.exp (η ^ 2 * M ^ 2 / 8) := by\n rw [← hmgf_eq]\n refine hmgf.trans ?_\n apply Real.exp_le_exp.2\n have hsq : (-η) ^ 2 = η ^ 2 := by ring\n rw [hsq]\n nlinarith [mul_le_mul_of_nonneg_right hc (sq_nonneg η), sq_nonneg η]\n have hEpos : (0:ℝ) < Real.exp (η * E) := Real.exp_pos _\n have : (∫ w, Real.exp (-η * ℓ (t + 1) w) ∂(p t))\n ≤ Real.exp (η ^ 2 * M ^ 2 / 8) / Real.exp (η * E) := by\n rw [le_div_iff₀ hEpos]\n linarith [hbound]\n refine this.trans_eq ?_\n rw [← Real.exp_sub]\n congr 1\n ring\n -- Step 4 : telescoping\n have hkey4 : ∀ t, t ≤ T → A t ≤ Real.exp (-η * (∑ s ∈ Finset.range t, ∫ w, ℓ (s + 1) w ∂(p s))\n + (t : ℝ) * (η ^ 2 * M ^ 2 / 8)) := by\n intro t\n induction t with\n | zero => intro _; simp [hA0]\n | succ n ih =>\n intro ht\n have hn : n < T := Nat.lt_of_succ_le ht\n have h1 := ih hn.le\n have h2 := hkey3 n hn\n have h3 : (0:ℝ) ≤ ∫ w, Real.exp (-η * ℓ (n + 1) w) ∂(p n) :=\n integral_nonneg fun w => (Real.exp_pos _).le\n rw [hkey2 n hn]\n calc A n * ∫ w, Real.exp (-η * ℓ (n + 1) w) ∂(p n)\n ≤ Real.exp (-η * (∑ s ∈ Finset.range n, ∫ w, ℓ (s + 1) w ∂(p s))\n + (n : ℝ) * (η ^ 2 * M ^ 2 / 8))\n * Real.exp (-η * (∫ w, ℓ (n + 1) w ∂(p n)) + η ^ 2 * M ^ 2 / 8) := by\n exact mul_le_mul h1 h2 h3 (Real.exp_pos _).le\n _ = Real.exp (-η * (∑ s ∈ Finset.range (n + 1), ∫ w, ℓ (s + 1) w ∂(p s))\n + ((n + 1 : ℕ) : ℝ) * (η ^ 2 * M ^ 2 / 8)) := by\n rw [← Real.exp_add]\n congr 1\n rw [Finset.sum_range_succ]\n push_cast\n ring\n -- Step 5 : the Donsker-Varadhan / Gibbs variational principle\n have hSTq : Integrable (S T) q := by\n refine integrable_finset_sum _ ?_\n intro s hs\n exact hℓintq s (Finset.mem_range.mp hs) q hq hqac\n have hFq : Integrable (fun w => -η * S T w) q := hSTq.const_mul _\n have hFp0 : Integrable (fun w => Real.exp (-η * S T w)) p₀ :=\n hintexp T le_rfl p₀ inferInstance\n have hllr : Integrable (llr q p₀) q := ((InformationTheory.klDiv_ne_top_iff).1 hkl).2\n have hνprob : IsProbabilityMeasure (p₀.tilted (fun w => -η * S T w)) :=\n isProbabilityMeasure_tilted hFp0\n have hqν : q ≪ p₀.tilted (fun w => -η * S T w) :=\n hqac.trans (absolutelyContinuous_tilted hFp0)\n have hint2 : Integrable (llr q (p₀.tilted (fun w => -η * S T w))) q :=\n integrable_llr_tilted_right hqac hFq hllr hFp0\n have hnn := InformationTheory.integral_llr_add_sub_measure_univ_nonneg hqν hint2\n rw [integral_llr_tilted_right hqac hFq hFp0 hllr] at hnn\n have hklR : (GraduateLevel.klDiv q p₀).toReal = ∫ w, llr q p₀ w ∂q := by\n simpa using InformationTheory.toReal_klDiv_of_measure_eq (μ := q) (ν := p₀) hqac (by simp)\n have hFint : (∫ w, -η * S T w ∂q) = -η * ∫ w, S T w ∂q := integral_const_mul _ _\n have hlogA : Real.log (A T) ≤ -η * (∑ s ∈ Finset.range T, ∫ w, ℓ (s + 1) w ∂(p s))\n + (T : ℝ) * (η ^ 2 * M ^ 2 / 8) := by\n have := hkey4 T le_rfl\n have h := Real.log_le_log (hApos T le_rfl) this\n rwa [Real.log_exp] at h\n have hAeq : (∫ x, Real.exp (-η * S T x) ∂p₀) = A T := rfl\n rw [hAeq, hFint] at hnn\n simp only [measureReal_univ_eq_one] at hnn\n -- assemble\n have hfinal : (∑ s ∈ Finset.range T, ∫ w, ℓ (s + 1) w ∂(p s))\n ≤ (∫ w, S T w ∂q) + (1 / η) * (GraduateLevel.klDiv q p₀).toReal + η * (T : ℝ) * M ^ 2 / 8 := by\n rw [hklR]\n refine le_of_mul_le_mul_left ?_ hη\n have expand : η * ((∫ w, S T w ∂q) + (1 / η) * (∫ w, llr q p₀ w ∂q)\n + η * (T : ℝ) * M ^ 2 / 8)\n = η * (∫ w, S T w ∂q) + (∫ w, llr q p₀ w ∂q) + η ^ 2 * (T : ℝ) * M ^ 2 / 8 := by\n field_simp\n rw [expand]\n nlinarith [hnn, hlogA]\n simpa [hSdef] using hfinal\n\nend GraduateLevel\n"} +{"id": "ch9_theorem_9_35", "source": "Graduate-level", "targets": [{"label": "ch9_ridge_excess_risk_bound", "decls": ["ch9_ridge_excess_risk_bound"], "statement": "Assume that \\( \\mathcal{S}_n = \\{(X_i, Y_i)\\}_{1}^{n} \\sim \\mathcal{D}^n \\), and \\( \\operatorname{Var}[\\epsilon_i | X_i] \\leq \\sigma^2 \\) for all \\( X_i \\). If we choose \\( \\lambda \\) such that \\( \\lambda n > B^2 \\geq \\sup_x \\psi(x)^\\top \\psi(x) \\), then (9.18) satisfies\n\\[\n\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}\\mathbb{E}_{X\\sim\\mathcal{D}}(\\hat{w}^{\\top}\\psi(X)-w_{*}^{\\top}\\psi(X))^{2}\\leq\\frac{d_{1,\\lambda^{\\prime}}}{n}(\\sigma^{2}+\\lambda n\\|w_{*}\\|_{2}^{2}),\n\\]\nwhere\n\\[\nd_{1,\\lambda^{\\prime}}=\\mathrm{trace}\\left((\\Sigma_{\\mathcal{D}}+\\lambda^{\\prime}I)^{-1}\\Sigma_{\\mathcal{D}}\\right),\\quad\\Sigma_{\\mathcal{D}}=\\mathbb{E}_{\\mathcal{D}}\\psi(X)\\psi(X)^{\\top},\n\\]\nand \\(\\lambda' = (\\lambda n - B^2) / (n + 1)\\).", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Statistical Estimation & Minimax Theory"}], "nl_proof": "Consider \\( \\mathcal{S}_{n+1} = \\{(X_1, Y_1), \\ldots, (X_{n+1}, Y_{n+1})\\} \\). Let \\( \\hat{w} \\) be the solution with training data \\( \\mathcal{S}_n \\). Let\n\\[\n\\begin{array}{l}\\hat{\\Sigma}_{n+1}=\\sum_{i=1}^{n+1}\\psi(X_{i})\\psi(X_{i})^{\\top},\\\\ \\hat{\\Sigma}_{n}=\\sum_{i=1}^{n}\\psi(X_{i})\\psi(X_{i})^{\\top}+\\lambda n I,\\\\ \\end{array}\n\\]\nthen \\(\\hat{\\Sigma}_n\\geq \\hat{\\Sigma}_{n + 1} + (\\lambda n - B^2)I\\) . It follows that\n\\[\n\\begin{array}{l}\\mathbb{E}\\left[\\left(\\hat{w}-w_{*}\\right)^{\\top}\\psi\\left(X_{n+1}\\right)\\right]^{2}\\\\ \\leq\\left(\\sigma^{2}+\\lambda n\\|w_{*}\\|_{2}^{2}\\right)\\mathbb{E}\\left\\|\\psi\\left(X_{n+1}\\right)\\right\\|_{\\left(\\hat{\\Sigma}_{n+1}+(\\lambda n-B^{2})I\\right)^{-1}}^{2}\\\\ =\\frac{\\sigma^{2}+\\lambda n\\|w_{*}\\|_{2}^{2}}{n+1}\\mathbb{E}\\operatorname{trace}\\left((\\hat{\\Sigma}_{n+1}+(\\lambda n-B^{2})I)^{-1}\\hat{\\Sigma}_{n+1}\\right)\\\\ \\leq\\frac{\\sigma^{2}+\\lambda n\\|w_{*}\\|_{2}^{2}}{n+1}\\mathrm{trace}\\left((\\mathbb{E}[\\hat{\\Sigma}_{n+1}]+(\\lambda n-B^{2})I)^{-1}[\\mathbb{E}\\hat{\\Sigma}_{n+1}]\\right)\\\\ =\\frac{\\sigma^{2}+\\lambda n\\|w_{*}\\|_{2}^{2}}{n+1}d_{1,\\lambda^{\\prime}}.\\\\ \\end{array}\n\\]\nIn the above derivation, the first inequality used Lemma 9.34 and \\(\\hat{\\Sigma}_n^{-1} \\leq (\\hat{\\Sigma}_{n+1} + (\\lambda n - B^2)I)^{-1}\\). The first equality used the symmetry of \\(X_1, \\ldots, X_{n+1}\\) conditioned on \\(\\mathcal{S}_{n+1}\\). The second inequality used Jensen's inequality and the concavity of the matrix function trace \\(((A + \\mu I)^{-1}A)\\) for \\(\\mu > 0\\), where \\(A\\) is a symmetric positive semi-definite matrix (see Theorem A.18).", "context": [{"id": "ch9:lemma:9_34", "name": "lemma 9.34", "statement": "Let \\(\\{Y_i\\}_1^n\\) be independent samples conditioned on \\(\\{X_i\\}_1^n\\) according to (9.19). Given any vector \\(X\\) that is independent of \\(\\{Y_i\\}_1^n\\). If \\(\\mathbb{E}[\\epsilon_i|X_i] \\leq \\sigma^2\\) for all \\(i\\), then we have\n\\[\n\\mathbb{E}_{\\left\\{Y_{i}\\right\\}_{1}^{n}\\mid\\left\\{X_{i}\\right\\}_{1}^{n}}\\left[\\left(\\hat{w}^{\\top}\\psi(X)-w_{*}^{\\top}\\psi(X)\\right)^{2}\\right]\\leq\\left(\\left(\\sigma^{2}/n\\right)+\\lambda\\|w_{*}\\|_{2}^{2}\\right)\\|\\psi(X)\\|_{\\hat{\\Sigma}_{\\lambda}^{-1}}^{2},\n\\]\nwhere\n\\[\n\\hat{\\Sigma}_{\\lambda}=\\frac{1}{n}\\sum_{i=1}^{n}\\psi(X_{i})\\psi(X_{i})^{\\top}+\\lambda I.\n\\]\nMoreover if \\(\\epsilon\\) is sub-Gaussian:\n\\[\n\\forall i:\\ln\\mathbb{E}\\exp [\\mu\\epsilon_{i}|X_{i}]\\leq\\frac{\\mu^{2}\\sigma^{2}}{2},\n\\]\nthen the following inequalities hold for conditional probability of \\(\\{Y_i\\}_1^n|\\{X_i\\}_1^n\\):\n\\[\n\\Pr\\left[\\hat{w}^{\\top}\\psi(X)-w_{*}^{\\top}\\psi(X)\\leq\\left(\\sqrt{\\lambda}\\|w_{*}\\|_{2}+\\sigma\\sqrt{\\frac{2\\ln(1/\\delta)}{n}}\\right)\\|\\psi(X)\\|_{\\hat{\\Sigma}_{\\lambda}^{-1}}\\right]\\leq\\delta,\n\\]\n\\[\n\\Pr\\left[w_{*}^{\\top}\\psi(X)-\\hat{w}^{\\top}\\psi(X)\\leq\\left(\\sqrt{\\lambda}\\|w_{*}\\|_{2}+\\sigma\\sqrt{\\frac{2\\ln(1/\\delta)}{n}}\\right)\\|\\psi(X)\\|_{\\hat{\\Sigma}_{\\lambda}^{-1}}\\right]\\leq\\delta .\n\\]"}, {"id": "ch9:equation:9_18", "name": "equation 9.18", "statement": "The ridge-regression estimator \\(\\hat w\\) on training data \\(\\mathcal S_n = \\{(X_i,Y_i)\\}_{i=1}^n\\) is the regularized least-squares solution\n\\[\n\\hat{w}=\\hat{\\Sigma}_{\\lambda}^{-1}\\frac{1}{n}\\sum_{i=1}^{n}\\psi(X_{i})Y_{i},\\qquad\\hat{\\Sigma}_{\\lambda}=\\frac{1}{n}\\sum_{i=1}^{n}\\psi(X_{i})\\psi(X_{i})^{\\top}+\\lambda I.\n\\]"}, {"id": "ch9:equation:9_19", "name": "equation 9.19", "statement": "The response model is\n\\[\nY_i=w_{*}^{\\top}\\psi(X_i)+\\epsilon_i,\n\\]\nwhere \\(w_*\\) is the target parameter and the noise variables satisfy \\(\\mathbb E[\\epsilon_i \\mid X_i] = 0\\) and \\(\\operatorname{Var}[\\epsilon_i \\mid X_i] \\leq \\sigma^2\\)."}], "lean": "import Mathlib\n\nopen MeasureTheory\n\nnamespace GraduateLevel\n\nnoncomputable def featureCovariance {Ω : Type*} [MeasurableSpace Ω] {d : ℕ}\n (D : Measure Ω) (ψ : Ω → (Fin d → ℝ)) : Matrix (Fin d) (Fin d) ℝ :=\n Matrix.of fun j k => ∫ x, ψ x j * ψ x k ∂D\n\nnoncomputable def linPred {Ω : Type*} {d : ℕ}\n (w : Fin d → ℝ) (ψ : Ω → (Fin d → ℝ)) (x : Ω) : ℝ :=\n ∑ j, w j * ψ x j\n\ntheorem ch9_ridge_excess_risk_bound\n {Ω : Type*} [MeasurableSpace Ω] {𝒳 : Type*} [MeasurableSpace 𝒳] {d n : ℕ}\n (D : Measure Ω) [IsProbabilityMeasure D]\n (X : Ω → 𝒳) (feat : 𝒳 → (Fin d → ℝ))\n (ψ : Ω → (Fin d → ℝ)) (wstar : Fin d → ℝ)\n (ε : Fin n → Ω → ℝ) (Y : Fin n → Ω → ℝ)\n (what : (Fin n → Ω) → (Fin d → ℝ))\n (lam B σ : ℝ)\n (hn : 1 ≤ n)\n (hXmeas : Measurable X)\n (hfeatmeas : Measurable feat)\n (hψfac : ψ = fun ω => feat (X ω))\n (hψmeas : Measurable ψ)\n (hψ : ∀ j, AEMeasurable (fun x => ψ x j) D)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D)\n (hY : ∀ i x, Y i x = linPred wstar ψ x + ε i x)\n (hεint : ∀ i, Integrable (ε i) D)\n (hεsqint : ∀ i, Integrable (fun ω => (ε i ω)^2) D)\n (hεmean : ∀ i, MeasureTheory.condExp (MeasurableSpace.comap X inferInstance) D (ε i) =ᵐ[D] 0)\n (hεvar : ∀ i, MeasureTheory.condExp (MeasurableSpace.comap X inferInstance) D (fun ω => (ε i ω)^2) ≤ᵐ[D] fun _ => σ^2)\n (hiid : ∀ i j, D.map (fun ω => (X ω, Y i ω)) = D.map (fun ω => (X ω, Y j ω)))\n (hB : ∀ x, (∑ j, ψ x j ^ 2) ≤ B^2)\n (hlamB : B^2 < lam * n)\n (hExcInt : ∀ S, Integrable (fun x => (linPred (what S) ψ x - linPred wstar ψ x)^2) D)\n (hOuterInt : Integrable (fun S => ∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D) (Measure.pi fun _ => D))\n (hwhat : ∀ S : Fin n → Ω, what S = ((((n : ℝ)⁻¹) • Matrix.of (fun j k => ∑ i, ψ (S i) j * ψ (S i) k) + lam • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (fun j => ((n : ℝ)⁻¹) * ∑ i, ψ (S i) j * Y i (S i))) :\n ∫ S, (∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D) ∂(Measure.pi fun _ => D)\n ≤ ((Matrix.trace ((featureCovariance D ψ + ((lam * n - B^2) / (n + 1)) • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ * featureCovariance D ψ)) / n) * (σ^2 + lam * n * (∑ j, wstar j ^ 2)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nset_option maxHeartbeats 1000000\n\nopen MeasureTheory\nopen scoped MatrixOrder\n\nnamespace GraduateLevel\n\nnoncomputable def featureCovariance {Ω : Type*} [MeasurableSpace Ω] {d : ℕ}\n (D : Measure Ω) (ψ : Ω → (Fin d → ℝ)) : Matrix (Fin d) (Fin d) ℝ :=\n Matrix.of fun j k => ∫ x, ψ x j * ψ x k ∂D\n\nnoncomputable def linPred {Ω : Type*} {d : ℕ}\n (w : Fin d → ℝ) (ψ : Ω → (Fin d → ℝ)) (x : Ω) : ℝ :=\n ∑ j, w j * ψ x j\n\nlemma integral_mul_of_condExp_zero\n {Ω : Type*} {m mΩ : MeasurableSpace Ω} {D : Measure Ω}\n [IsProbabilityMeasure D] {g e : Ω → ℝ}\n (hm : m ≤ mΩ)\n (hg : StronglyMeasurable[m] g)\n (heint : Integrable e D)\n (hgeint : Integrable (g * e) D)\n (hemean : D[e | m] =ᵐ[D] 0) :\n ∫ x, g x * e x ∂D = 0 := by\n have hpull : D[g * e | m] =ᵐ[D] g * D[e | m] :=\n condExp_mul_of_stronglyMeasurable_left hg hgeint heint\n calc\n ∫ x, g x * e x ∂D = ∫ x, D[g * e | m] x ∂D := (integral_condExp hm).symm\n _ = ∫ x, g x * D[e | m] x ∂D := integral_congr_ae hpull\n _ = 0 := by\n have hz : (fun x => g x * D[e | m] x) =ᵐ[D] fun _ => 0 :=\n hemean.mono fun x hx => by\n change g x * D[e | m] x = 0\n change D[e | m] x = 0 at hx\n rw [hx, mul_zero]\n rw [integral_congr_ae hz]\n simp only [integral_zero]\n\nlemma integral_mul_sq_of_condExp_le\n {Ω : Type*} {m mΩ : MeasurableSpace Ω} {D : Measure Ω}\n [IsProbabilityMeasure D] {g e : Ω → ℝ} {s : ℝ}\n (hm : m ≤ mΩ)\n (hg : StronglyMeasurable[m] g)\n (hg0 : 0 ≤ g)\n (hgint : Integrable g D)\n (hesqint : Integrable (fun x => (e x)^2) D)\n (hgesqint : Integrable (fun x => g x * (e x)^2) D)\n (hevar : D[fun x => (e x)^2 | m] ≤ᵐ[D] fun _ => s) :\n ∫ x, g x * (e x)^2 ∂D ≤ s * ∫ x, g x ∂D := by\n have hpull : D[g * fun x => (e x)^2 | m] =ᵐ[D]\n g * D[fun x => (e x)^2 | m] :=\n condExp_mul_of_stronglyMeasurable_left hg hgesqint hesqint\n have hright : Integrable (fun x => g x * s) D := hgint.mul_const s\n calc\n ∫ x, g x * (e x)^2 ∂D = ∫ x, D[g * fun x => (e x)^2 | m] x ∂D :=\n (integral_condExp hm).symm\n _ = ∫ x, g x * D[fun x => (e x)^2 | m] x ∂D := integral_congr_ae hpull\n _ ≤ ∫ x, g x * s ∂D := by\n apply integral_mono_ae\n · exact integrable_condExp.congr hpull\n · exact hright\n · filter_upwards [hevar] with x hx\n exact mul_le_mul_of_nonneg_left hx (hg0 x)\n _ = s * ∫ x, g x ∂D := by\n rw [← integral_const_mul]\n apply integral_congr_ae\n filter_upwards with x\n ring\n\nlemma integral_pi_eq_zero_of_slices\n {Ω : Type*} [MeasurableSpace Ω] {D : Measure Ω} [IsProbabilityMeasure D]\n {n : ℕ} (i : Fin (n + 1)) {f : (Fin (n + 1) → Ω) → ℝ}\n (hf : Integrable f (Measure.pi fun _ : Fin (n + 1) => D))\n (hz : ∀ r : Fin n → Ω, ∫ x, f (i.insertNth x r) ∂D = 0) :\n ∫ S, f S ∂(Measure.pi fun _ : Fin (n + 1) => D) = 0 := by\n let e : (Fin (n + 1) → Ω) ≃ᵐ Ω × (Fin n → Ω) :=\n MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => Ω) i\n let ν : Measure (Fin n → Ω) := Measure.pi fun _ : Fin n => D\n have he : MeasurePreserving e (Measure.pi fun _ : Fin (n + 1) => D) (D.prod ν) :=\n measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => D) i\n let F : Ω × (Fin n → Ω) → ℝ := fun z => f (i.insertNth z.1 z.2)\n have hFeq : (fun S => F (e S)) = f := by\n funext S\n simp [F, e, MeasurableEquiv.piFinSuccAbove_apply]\n have hFint : Integrable F (D.prod ν) := by\n have hi := he.symm.integrable_comp_emb (MeasurableEquiv.measurableEmbedding e.symm) (g := f)\n apply hi.mpr\n simpa [F, e, MeasurableEquiv.piFinSuccAbove_symm_apply]\n calc\n ∫ S, f S ∂(Measure.pi fun _ : Fin (n + 1) => D) =\n ∫ S, F (e S) ∂(Measure.pi fun _ : Fin (n + 1) => D) := by rw [hFeq]\n _ = ∫ z, F z ∂(D.prod ν) := he.integral_comp' F\n _ = ∫ r, ∫ x, F (x, r) ∂D ∂ν := integral_prod_symm F hFint\n _ = 0 := by\n apply integral_eq_zero_of_ae\n filter_upwards with r\n exact hz r\n\nlemma integral_pi_le_of_slices\n {Ω : Type*} [MeasurableSpace Ω] {D : Measure Ω} [IsProbabilityMeasure D]\n {n : ℕ} (i : Fin (n + 1)) {f g : (Fin (n + 1) → Ω) → ℝ}\n (hf : Integrable f (Measure.pi fun _ : Fin (n + 1) => D))\n (hg : Integrable g (Measure.pi fun _ : Fin (n + 1) => D))\n (hle : ∀ r : Fin n → Ω,\n (∫ x, f (i.insertNth x r) ∂D) ≤ ∫ x, g (i.insertNth x r) ∂D) :\n (∫ S, f S ∂(Measure.pi fun _ : Fin (n + 1) => D)) ≤\n ∫ S, g S ∂(Measure.pi fun _ : Fin (n + 1) => D) := by\n let e : (Fin (n + 1) → Ω) ≃ᵐ Ω × (Fin n → Ω) :=\n MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => Ω) i\n let ν : Measure (Fin n → Ω) := Measure.pi fun _ : Fin n => D\n have he : MeasurePreserving e (Measure.pi fun _ : Fin (n + 1) => D) (D.prod ν) :=\n measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => D) i\n let F : Ω × (Fin n → Ω) → ℝ := fun z => f (i.insertNth z.1 z.2)\n let G : Ω × (Fin n → Ω) → ℝ := fun z => g (i.insertNth z.1 z.2)\n have hFeq : (fun S => F (e S)) = f := by\n funext S\n simp [F, e, MeasurableEquiv.piFinSuccAbove_apply]\n have hGeq : (fun S => G (e S)) = g := by\n funext S\n simp [G, e, MeasurableEquiv.piFinSuccAbove_apply]\n have hFint : Integrable F (D.prod ν) := by\n have hi := he.symm.integrable_comp_emb (MeasurableEquiv.measurableEmbedding e.symm) (g := f)\n apply hi.mpr\n simpa [F, e, MeasurableEquiv.piFinSuccAbove_symm_apply]\n have hGint : Integrable G (D.prod ν) := by\n have hi := he.symm.integrable_comp_emb (MeasurableEquiv.measurableEmbedding e.symm) (g := g)\n apply hi.mpr\n simpa [G, e, MeasurableEquiv.piFinSuccAbove_symm_apply]\n calc\n ∫ S, f S ∂(Measure.pi fun _ : Fin (n + 1) => D) =\n ∫ r, ∫ x, F (x, r) ∂D ∂ν := by\n rw [← hFeq, he.integral_comp' F, integral_prod_symm F hFint]\n _ ≤ ∫ r, ∫ x, G (x, r) ∂D ∂ν := by\n apply integral_mono_ae hFint.integral_prod_right hGint.integral_prod_right\n filter_upwards with r\n exact hle r\n _ = ∫ S, g S ∂(Measure.pi fun _ : Fin (n + 1) => D) := by\n rw [← integral_prod_symm G hGint, ← he.integral_comp' G, hGeq]\n\nlemma measurable_design_insert\n {Ω Z : Type*} [MeasurableSpace Ω] [MeasurableSpace Z]\n {n : ℕ} (i : Fin (n + 1)) (X : Ω → Z) (r : Fin n → Ω) :\n Measurable[MeasurableSpace.comap X inferInstance]\n (fun (x : Ω) (k : Fin (n + 1)) =>\n X ((@Fin.insertNth n (fun _ => Ω) i x r) k)) := by\n have hXm : Measurable[MeasurableSpace.comap X inferInstance] X :=\n measurable_iff_comap_le.mpr le_rfl\n have hins : Measurable (fun z : Z =>\n @Fin.insertNth n (fun _ => Z) i z (fun k => X (r k))) := by\n apply measurable_pi_lambda\n intro j\n by_cases hji : j = i\n · subst j\n simpa using (measurable_id : Measurable (fun z : Z => z))\n · obtain ⟨k, hk⟩ := Fin.exists_succAbove_eq hji\n subst j\n simpa using (measurable_const : Measurable (fun _ : Z => X (r k)))\n have hc := hins.comp hXm\n convert hc using 1\n funext x j\n by_cases hji : j = i\n · subst j\n simp\n · obtain ⟨k, hk⟩ := Fin.exists_succAbove_eq hji\n subst j\n simp\n\nlemma integrable_mul_of_sq_integrable\n {Ω : Type*} [MeasurableSpace Ω] {D : Measure Ω} {f g : Ω → ℝ}\n (hf : AEMeasurable f D) (hg : AEMeasurable g D)\n (hf2 : Integrable (fun x => (f x)^2) D)\n (hg2 : Integrable (fun x => (g x)^2) D) :\n Integrable (fun x => f x * g x) D := by\n have hsum : Integrable (fun x => (f x)^2 + (g x)^2) D := by\n simpa only [Pi.add_apply] using hf2.add hg2\n apply hsum.mono' (hf.mul hg).aestronglyMeasurable\n filter_upwards with x\n rw [Real.norm_eq_abs, abs_mul]\n have hsq := sq_nonneg (|f x| - |g x|)\n nlinarith [sq_abs (f x), sq_abs (g x)]\n\nlemma sq_le_sq_of_abs_le {x C : ℝ} (hC : 0 ≤ C) (h : |x| ≤ C) :\n x ^ 2 ≤ C ^ 2 := by\n rw [← sq_abs]\n nlinarith [mul_nonneg (sub_nonneg.mpr h) (add_nonneg hC (abs_nonneg x))]\n\nlemma sample_linear_noise_bound\n {Ω Z : Type*} [MeasurableSpace Ω] [MeasurableSpace Z]\n {D : Measure Ω} [IsProbabilityMeasure D] {n : ℕ}\n (X : Ω → Z) (hX : Measurable X)\n (e : Fin (n + 1) → Ω → ℝ)\n (heint : ∀ i, Integrable (e i) D)\n (hesqint : ∀ i, Integrable (fun x => (e i x)^2) D)\n (hemean : ∀ i, D[e i | MeasurableSpace.comap X inferInstance] =ᵐ[D] 0)\n (hevar : ∀ i, D[fun x => (e i x)^2 | MeasurableSpace.comap X inferInstance]\n ≤ᵐ[D] fun _ => s)\n (a : (Fin (n + 1) → Z) → (Fin (n + 1) → ℝ))\n (b : (Fin (n + 1) → Z) → ℝ)\n (ha : Measurable a) (hb : Measurable b)\n (Ca Cb : ℝ) (hCa : 0 ≤ Ca) (hCb : 0 ≤ Cb)\n (ha_bound : ∀ (S : Fin (n + 1) → Ω) i, |a (fun k => X (S k)) i| ≤ Ca)\n (hb_bound : ∀ (S : Fin (n + 1) → Ω), |b (fun k => X (S k))| ≤ Cb) :\n (∫ S, ((∑ i, a (fun k => X (S k)) i * e i (S i)) +\n b (fun k => X (S k)))^2\n ∂(Measure.pi fun _ : Fin (n + 1) => D))\n ≤ ∫ S, (s * ∑ i, (a (fun k => X (S k)) i)^2 +\n (b (fun k => X (S k)))^2)\n ∂(Measure.pi fun _ : Fin (n + 1) => D) := by\n let μ : Measure (Fin (n + 1) → Ω) := Measure.pi fun _ : Fin (n + 1) => D\n let z : (Fin (n + 1) → Ω) → (Fin (n + 1) → Z) := fun S k => X (S k)\n let A : (Fin (n + 1) → Ω) → Fin (n + 1) → ℝ := fun S i => a (z S) i\n let E : (Fin (n + 1) → Ω) → Fin (n + 1) → ℝ := fun S i => e i (S i)\n let T : (Fin (n + 1) → Ω) → Fin (n + 1) → ℝ := fun S i => A S i * E S i\n let B : (Fin (n + 1) → Ω) → ℝ := fun S => b (z S)\n have hz : Measurable z := by\n apply measurable_pi_lambda\n intro i\n exact hX.comp (measurable_pi_apply i)\n have hAmeas (i : Fin (n + 1)) : Measurable (fun S => A S i) := by\n exact (measurable_pi_apply i).comp (ha.comp hz)\n have hBmeas : Measurable B := hb.comp hz\n have hEint (i : Fin (n + 1)) : Integrable (fun S => E S i) μ := by\n simpa [E, μ] using\n (integrable_comp_eval (μ := fun _ : Fin (n + 1) => D) (heint i))\n have hE2int (i : Fin (n + 1)) : Integrable (fun S => (E S i)^2) μ := by\n simpa [E, μ] using\n (integrable_comp_eval (μ := fun _ : Fin (n + 1) => D) (hesqint i))\n have hTint (i : Fin (n + 1)) : Integrable (fun S => T S i) μ := by\n have hi := (hEint i).bdd_mul (hAmeas i).aestronglyMeasurable\n (ae_of_all _ fun S => by simpa [Real.norm_eq_abs, A, z] using ha_bound S i)\n simpa [T] using hi\n have hT2int (i : Fin (n + 1)) : Integrable (fun S => (T S i)^2) μ := by\n have hcoef : AEStronglyMeasurable (fun S => (A S i)^2) μ := by\n fun_prop\n have hbnd : ∀ᵐ S ∂μ, ‖(A S i)^2‖ ≤ Ca^2 := by\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_sq]\n simpa [A, z] using sq_le_sq_of_abs_le hCa (ha_bound S i)\n have hi := (hE2int i).bdd_mul hcoef hbnd\n apply hi.congr\n filter_upwards with S\n simp [T, E, pow_two]\n ring\n have hA2int (i : Fin (n + 1)) : Integrable (fun S => (A S i)^2) μ := by\n apply Integrable.of_bound (by fun_prop) (Ca^2)\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_sq]\n simpa [A, z] using sq_le_sq_of_abs_le hCa (ha_bound S i)\n have hBint : Integrable B μ := by\n apply Integrable.of_bound hBmeas.aestronglyMeasurable Cb\n filter_upwards with S\n simpa [Real.norm_eq_abs, B, z] using hb_bound S\n have hB2int : Integrable (fun S => (B S)^2) μ := by\n apply Integrable.of_bound (by fun_prop) (Cb^2)\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_sq]\n simpa [B, z] using sq_le_sq_of_abs_le hCb (hb_bound S)\n have hTTint (i j : Fin (n + 1)) : Integrable (fun S => T S i * T S j) μ := by\n by_cases hij : i = j\n · subst j\n simpa [pow_two] using hT2int i\n · exact integrable_mul_of_sq_integrable\n (hTint i).aemeasurable (hTint j).aemeasurable (hT2int i) (hT2int j)\n have hBTint (i : Fin (n + 1)) : Integrable (fun S => B S * T S i) μ := by\n have hi := (hTint i).mul_bdd hBmeas.aestronglyMeasurable\n (ae_of_all _ fun S => by simpa [Real.norm_eq_abs, B, z] using hb_bound S)\n apply hi.congr\n filter_upwards with S\n ring\n have hdiag (i : Fin (n + 1)) :\n (∫ S, (T S i)^2 ∂μ) ≤ s * ∫ S, (A S i)^2 ∂μ := by\n have hright : Integrable (fun S => s * (A S i)^2) μ := (hA2int i).const_mul s\n have hpi :\n (∫ S, (T S i)^2 ∂(Measure.pi fun _ : Fin (n + 1) => D)) ≤\n ∫ S, s * (A S i)^2 ∂(Measure.pi fun _ : Fin (n + 1) => D) := by\n apply (integral_pi_le_of_slices i (by simpa [μ] using hT2int i)\n (by simpa [μ] using hright))\n intro r\n let As : Ω → ℝ := fun x => A (i.insertNth x r) i\n have hAsmeas : Measurable[MeasurableSpace.comap X inferInstance] As := by\n have hd := measurable_design_insert i X r\n have hc := (measurable_pi_apply i).comp (ha.comp hd)\n simpa [As, A, z] using hc\n have hAs2int : Integrable (fun x => (As x)^2) D := by\n apply Integrable.of_bound\n ((hAsmeas.pow_const 2).mono hX.comap_le le_rfl).aestronglyMeasurable (Ca^2)\n filter_upwards with x\n rw [Real.norm_eq_abs, abs_sq]\n simpa [As, A] using\n sq_le_sq_of_abs_le hCa (ha_bound (i.insertNth x r) i)\n have hprod : Integrable (fun x => (As x)^2 * (e i x)^2) D := by\n apply (hesqint i).bdd_mul\n ((hAsmeas.pow_const 2).mono hX.comap_le le_rfl).aestronglyMeasurable\n filter_upwards with x\n rw [Real.norm_eq_abs, abs_sq]\n simpa [As, A] using\n sq_le_sq_of_abs_le hCa (ha_bound (i.insertNth x r) i)\n have hv := integral_mul_sq_of_condExp_le hX.comap_le\n (hAsmeas.pow_const 2).stronglyMeasurable\n (fun x => sq_nonneg (As x)) hAs2int (hesqint i) hprod (hevar i)\n calc\n ∫ x, (T (i.insertNth x r) i)^2 ∂D =\n ∫ x, (As x)^2 * (e i x)^2 ∂D := by\n apply integral_congr_ae\n filter_upwards with x\n simp [T, E, As, pow_two]\n ring\n _ ≤ s * ∫ x, (As x)^2 ∂D := hv\n _ = ∫ x, s * (A (i.insertNth x r) i)^2 ∂D := by\n rw [integral_const_mul]\n calc\n ∫ S, (T S i)^2 ∂μ ≤ ∫ S, s * (A S i)^2 ∂μ := by simpa [μ] using hpi\n _ = s * ∫ S, (A S i)^2 ∂μ := integral_const_mul s _\n have hmeanB (i : Fin (n + 1)) : ∫ S, B S * T S i ∂μ = 0 := by\n apply integral_pi_eq_zero_of_slices i (by simpa [μ] using hBTint i)\n intro r\n let C : Ω → ℝ := fun x => B (i.insertNth x r) * A (i.insertNth x r) i\n have hCmeas : Measurable[MeasurableSpace.comap X inferInstance] C := by\n have hd := measurable_design_insert i X r\n have ha' := (measurable_pi_apply i).comp (ha.comp hd)\n have hb' := hb.comp hd\n exact hb'.mul ha'\n have hCeint : Integrable (C * e i) D := by\n apply (heint i).bdd_mul\n ((hCmeas.mono hX.comap_le le_rfl).aestronglyMeasurable) (c := Cb * Ca)\n filter_upwards with x\n rw [Real.norm_eq_abs, abs_mul]\n exact mul_le_mul (hb_bound _) (ha_bound _ _) (abs_nonneg _) hCb\n have hz0 := integral_mul_of_condExp_zero hX.comap_le hCmeas.stronglyMeasurable\n (heint i) hCeint (hemean i)\n simpa [C, T, E, pow_two, mul_assoc] using hz0\n have hmeanOff (i j : Fin (n + 1)) (hij : i ≠ j) :\n ∫ S, T S i * T S j ∂μ = 0 := by\n apply integral_pi_eq_zero_of_slices i (by simpa [μ] using hTTint i j)\n intro r\n obtain ⟨k, hk⟩ := Fin.exists_succAbove_eq hij.symm\n subst j\n let C : Ω → ℝ := fun x =>\n A (i.insertNth x r) i * A (i.insertNth x r) (i.succAbove k) * e (i.succAbove k) (r k)\n have hCmeas : Measurable[MeasurableSpace.comap X inferInstance] C := by\n have hd := measurable_design_insert i X r\n have hai := (measurable_pi_apply i).comp (ha.comp hd)\n have haj := (measurable_pi_apply (i.succAbove k)).comp (ha.comp hd)\n exact (hai.mul haj).mul measurable_const\n have hCeint : Integrable (C * e i) D := by\n apply (heint i).bdd_mul\n ((hCmeas.mono hX.comap_le le_rfl).aestronglyMeasurable)\n (c := Ca^2 * |e (i.succAbove k) (r k)|)\n filter_upwards with x\n rw [Real.norm_eq_abs]\n dsimp [C]\n rw [abs_mul, abs_mul]\n have h1 := ha_bound (i.insertNth x r) i\n have h2 := ha_bound (i.insertNth x r) (i.succAbove k)\n calc\n |A (i.insertNth x r) i| * |A (i.insertNth x r) (i.succAbove k)| *\n |e (i.succAbove k) (r k)|\n ≤ Ca * Ca * |e (i.succAbove k) (r k)| := by gcongr\n _ = Ca^2 * |e (i.succAbove k) (r k)| := by ring\n have hz0 := integral_mul_of_condExp_zero hX.comap_le hCmeas.stronglyMeasurable\n (heint i) hCeint (hemean i)\n convert hz0 using 1\n apply integral_congr_ae\n filter_upwards with x\n simp [C, T, E]\n ring\n have hsumA2 : Integrable (fun S => ∑ i, (A S i)^2) μ :=\n integrable_finset_sum Finset.univ (fun i _ => hA2int i)\n have hright : Integrable (fun S => s * ∑ i, (A S i)^2 + (B S)^2) μ :=\n (hsumA2.const_mul s).add hB2int\n have hdouble : Integrable (fun S => ∑ i, ∑ j, T S i * T S j) μ :=\n integrable_finset_sum Finset.univ fun i _ =>\n integrable_finset_sum Finset.univ fun j _ => hTTint i j\n have hcross : Integrable (fun S => 2 * ∑ i, B S * T S i) μ :=\n (integrable_finset_sum Finset.univ fun i _ => hBTint i).const_mul 2\n calc\n ∫ S, ((∑ i, a (fun k => X (S k)) i * e i (S i)) + b (fun k => X (S k)))^2\n ∂(Measure.pi fun _ : Fin (n + 1) => D) =\n ∫ S, (∑ i, ∑ j, T S i * T S j) + 2 * (∑ i, B S * T S i) + (B S)^2 ∂μ := by\n apply integral_congr_ae\n filter_upwards with S\n change ((∑ i, T S i) + B S)^2 =\n (∑ i, ∑ j, T S i * T S j) + 2 * (∑ i, B S * T S i) + (B S)^2\n calc\n ((∑ i, T S i) + B S)^2 =\n (∑ i, T S i) * (∑ j, T S j) + 2 * B S * (∑ i, T S i) + (B S)^2 := by ring\n _ = (∑ i, ∑ j, T S i * T S j) +\n 2 * (∑ i, B S * T S i) + (B S)^2 := by\n rw [Finset.sum_mul_sum, Finset.mul_sum]\n simp_rw [mul_assoc]\n rw [Finset.mul_sum]\n _ = (∑ i, ∑ j, ∫ S, T S i * T S j ∂μ) +\n 2 * (∑ i, ∫ S, B S * T S i ∂μ) + ∫ S, (B S)^2 ∂μ := by\n calc\n ∫ S, (∑ i, ∑ j, T S i * T S j) + 2 * (∑ i, B S * T S i) + (B S)^2 ∂μ =\n (∫ S, (∑ i, ∑ j, T S i * T S j) + 2 * (∑ i, B S * T S i) ∂μ) +\n ∫ S, (B S)^2 ∂μ := integral_add (hdouble.add hcross) hB2int\n _ = ((∫ S, ∑ i, ∑ j, T S i * T S j ∂μ) +\n ∫ S, 2 * (∑ i, B S * T S i) ∂μ) + ∫ S, (B S)^2 ∂μ := by\n rw [integral_add hdouble hcross]\n _ = (∑ i, ∑ j, ∫ S, T S i * T S j ∂μ) +\n 2 * (∑ i, ∫ S, B S * T S i ∂μ) + ∫ S, (B S)^2 ∂μ := by\n rw [integral_finset_sum Finset.univ\n (fun i _ => integrable_finset_sum Finset.univ fun j _ => hTTint i j),\n integral_const_mul,\n integral_finset_sum Finset.univ (fun i _ => hBTint i)]\n apply congrArg (fun q => q + 2 * (∑ i, ∫ S, B S * T S i ∂μ) +\n ∫ S, (B S)^2 ∂μ)\n apply Finset.sum_congr rfl\n intro i _\n rw [integral_finset_sum Finset.univ (fun j _ => hTTint i j)]\n _ ≤ (∑ i, s * ∫ S, (A S i)^2 ∂μ) + ∫ S, (B S)^2 ∂μ := by\n rw [show (∑ i, ∫ S, B S * T S i ∂μ) = 0 by simp [hmeanB]]\n simp only [mul_zero, add_zero]\n gcongr with i hi\n calc\n ∑ j, ∫ S, T S i * T S j ∂μ = ∫ S, (T S i)^2 ∂μ := by\n rw [Finset.sum_eq_single i]\n · simp [pow_two]\n · intro j _ hji\n exact hmeanOff i j hji.symm\n · exact fun hi => (hi (Finset.mem_univ i)).elim\n _ ≤ s * ∫ S, (A S i)^2 ∂μ := hdiag i\n _ = ∫ S, s * ∑ i, (A S i)^2 + (B S)^2 ∂μ := by\n rw [integral_add (hsumA2.const_mul s) hB2int, integral_const_mul,\n integral_finset_sum Finset.univ (fun i _ => hA2int i), Finset.mul_sum]\n _ = ∫ S, (s * ∑ i, (a (fun k => X (S k)) i)^2 +\n (b (fun k => X (S k)))^2) ∂(Measure.pi fun _ : Fin (n + 1) => D) := by\n rfl\n\nnoncomputable def outer {d : ℕ} (u : Fin d → ℝ) : Matrix (Fin d) (Fin d) ℝ :=\n Matrix.of fun j k => u j * u k\n\nlemma outer_eq_vecMulVec {d : ℕ} (u : Fin d → ℝ) :\n outer u = Matrix.vecMulVec u u := by\n rfl\n\nlemma outer_posSemidef {d : ℕ} (u : Fin d → ℝ) : (outer u).PosSemidef := by\n rw [outer_eq_vecMulVec]\n simpa using Matrix.posSemidef_vecMulVec_star_self (R := ℝ) u\n\nlemma empirical_posSemidef {d n : ℕ} (u : Fin n → Fin d → ℝ) :\n (∑ i, outer (u i)).PosSemidef := by\n exact Matrix.posSemidef_sum Finset.univ (fun i _ => outer_posSemidef (u i))\n\nlemma dot_outer_mulVec {d : ℕ} (u v : Fin d → ℝ) :\n u ⬝ᵥ (outer v).mulVec u = (v ⬝ᵥ u) ^ 2 := by\n have hmv : (outer v).mulVec u = (v ⬝ᵥ u) • v := by\n ext j\n simp only [outer, Matrix.mulVec, Matrix.of_apply, dotProduct, Pi.smul_apply,\n smul_eq_mul]\n calc\n (∑ x, v j * v x * u x) = ∑ x, v j * (v x * u x) := by\n apply Finset.sum_congr rfl\n intro x _\n ring\n _ = v j * ∑ x, v x * u x := by rw [Finset.mul_sum]\n _ = (∑ i, v i * u i) * v j := by ring\n rw [hmv]\n simp only [dotProduct, Pi.smul_apply, smul_eq_mul]\n calc\n (∑ x, u x * ((∑ i, v i * u i) * v x)) =\n (∑ i, v i * u i) * ∑ x, v x * u x := by\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro x _\n ring\n _ = (∑ x, v x * u x) ^ 2 := by ring\n\nlemma psd_cauchy {d : ℕ} {P : Matrix (Fin d) (Fin d) ℝ}\n (hP : P.PosSemidef) (u v : Fin d → ℝ) :\n (u ⬝ᵥ P.mulVec v) ^ 2 ≤\n (u ⬝ᵥ P.mulVec u) * (v ⬝ᵥ P.mulVec v) := by\n classical\n obtain ⟨Q, hQ⟩ := CStarAlgebra.nonneg_iff_eq_star_mul_self.mp hP.nonneg\n rw [hQ]\n have hbilin (a b : Fin d → ℝ) :\n a ⬝ᵥ (star Q * Q).mulVec b = (Q.mulVec a) ⬝ᵥ (Q.mulVec b) := by\n rw [← Matrix.mulVec_mulVec, Matrix.dotProduct_mulVec]\n change Matrix.vecMul a (Matrix.conjTranspose Q) ⬝ᵥ Q.mulVec b = _\n rw [Matrix.vecMul_conjTranspose]\n simp\n rw [hbilin u v, hbilin u u, hbilin v v]\n simpa [dotProduct, pow_two] using\n (Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (Q.mulVec u) (Q.mulVec v))\n\nlemma scalar_one_posDef {d : ℕ} {c : ℝ} (hc : 0 < c) :\n (c • (1 : Matrix (Fin d) (Fin d) ℝ)).PosDef := by\n exact Matrix.PosDef.one.smul hc\n\nlemma ridge_posDef {d n : ℕ} (u : Fin n → Fin d → ℝ) {c : ℝ} (hc : 0 < c) :\n ((∑ i, outer (u i)) + c • (1 : Matrix (Fin d) (Fin d) ℝ)).PosDef := by\n simpa [add_comm] using\n (scalar_one_posDef (d := d) hc).add_posSemidef (empirical_posSemidef u)\n\nlemma scalar_mulVec {d : ℕ} (c : ℝ) (u : Fin d → ℝ) :\n (c • (1 : Matrix (Fin d) (Fin d) ℝ)).mulVec u = c • u := by\n rw [Matrix.smul_mulVec, Matrix.one_mulVec]\n\nlemma ridge_inverse_quadratic_le {d n : ℕ} (u : Fin n → Fin d → ℝ)\n {c : ℝ} (hc : 0 < c) (v : Fin d → ℝ) :\n c * (v ⬝ᵥ (((∑ i, outer (u i)) +\n c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec v) ≤ v ⬝ᵥ v := by\n let A := ∑ i, outer (u i)\n let H := A + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let x := H⁻¹.mulVec v\n have hA : A.PosSemidef := empirical_posSemidef u\n have hH : H.PosDef := by\n simpa [H, A, add_comm] using\n (scalar_one_posDef (d := d) hc).add_posSemidef hA\n have hdet : IsUnit H.det := H.isUnit_iff_isUnit_det.mp hH.isUnit\n have hHx : H.mulVec x = v := by\n dsimp [x]\n rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv H hdet, Matrix.one_mulVec]\n have hAx : 0 ≤ x ⬝ᵥ A.mulVec x := hA.dotProduct_mulVec_nonneg x\n have hAA : 0 ≤ A.mulVec x ⬝ᵥ A.mulVec x := by\n simp only [dotProduct]\n exact Finset.sum_nonneg fun i _ => mul_self_nonneg _\n have hcomm : A.mulVec x ⬝ᵥ x = x ⬝ᵥ A.mulVec x := dotProduct_comm _ _\n change c * (v ⬝ᵥ H⁻¹.mulVec v) ≤ v ⬝ᵥ v\n change c * (v ⬝ᵥ x) ≤ v ⬝ᵥ v\n rw [← hHx]\n have hexpand : H.mulVec x = A.mulVec x + c • x := by\n dsimp [H]\n rw [Matrix.add_mulVec, Matrix.smul_mulVec, Matrix.one_mulVec]\n rw [hexpand]\n simp only [add_dotProduct, dotProduct_add, smul_dotProduct, dotProduct_smul,\n smul_eq_mul]\n nlinarith\n\nlemma dot_mulVec_comm_of_posSemidef {d : ℕ}\n {M : Matrix (Fin d) (Fin d) ℝ} (hM : M.PosSemidef) (u v : Fin d → ℝ) :\n u ⬝ᵥ M.mulVec v = v ⬝ᵥ M.mulVec u := by\n have ht : M.transpose = M := by\n simpa [Matrix.conjTranspose] using hM.isHermitian.eq\n have hs (i j : Fin d) : M i j = M j i := by\n have h := congrFun (congrFun ht j) i\n simpa using h\n simp only [dotProduct, Matrix.mulVec]\n calc\n (∑ i, u i * ∑ j, M i j * v j) =\n ∑ i, ∑ j, u i * (M i j * v j) := by\n apply Finset.sum_congr rfl\n intro i _\n rw [Finset.mul_sum]\n _ = ∑ j, ∑ i, u i * (M i j * v j) := Finset.sum_comm\n _ = ∑ j, v j * ∑ i, M j i * u i := by\n apply Finset.sum_congr rfl\n intro j _\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro i _\n rw [hs i j]\n ring\n\nlemma empirical_quadratic_eq_sum_sq {d n : ℕ} (u : Fin n → Fin d → ℝ)\n (v : Fin d → ℝ) :\n v ⬝ᵥ (∑ i, outer (u i)).mulVec v = ∑ i, (u i ⬝ᵥ v)^2 := by\n have hmv : (∑ i, outer (u i)).mulVec v = ∑ i, (outer (u i)).mulVec v := by\n ext j\n simp only [Matrix.mulVec, Finset.sum_apply, dotProduct]\n rw [Finset.sum_comm]\n apply Finset.sum_congr rfl\n intro i _\n rw [Matrix.sum_apply, Finset.sum_mul]\n rw [hmv]\n have hdot := dotProduct_sum v Finset.univ (fun i => (outer (u i)).mulVec v)\n simp only [Finset.sum_filter, Finset.mem_univ, ↓reduceIte] at hdot\n rw [hdot]\n apply Finset.sum_congr rfl\n intro i _\n exact dot_outer_mulVec v (u i)\n\nlemma ridge_sum_coeff_sq_le_leverage {d n : ℕ} (u : Fin n → Fin d → ℝ)\n {c : ℝ} (hc : 0 < c) (v : Fin d → ℝ) :\n (∑ i, (v ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (u i))^2) ≤\n v ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec v := by\n let A := ∑ i, outer (u i)\n let H := A + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let x := H⁻¹.mulVec v\n have hH : H.PosDef := ridge_posDef u hc\n have hInv : H⁻¹.PosSemidef := hH.inv.posSemidef\n have hsymm (i : Fin n) : v ⬝ᵥ H⁻¹.mulVec (u i) = u i ⬝ᵥ x := by\n exact dot_mulVec_comm_of_posSemidef hInv v (u i)\n have hAx : x ⬝ᵥ A.mulVec x = ∑ i, (u i ⬝ᵥ x)^2 :=\n empirical_quadratic_eq_sum_sq u x\n have hEq : H.mulVec x = v := by\n dsimp [x]\n rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv H\n (H.isUnit_iff_isUnit_det.mp hH.isUnit)]\n simp\n have hnon : 0 ≤ x ⬝ᵥ x := by\n simp [dotProduct]\n exact Finset.sum_nonneg fun i _ => mul_self_nonneg (x i)\n have hlev : v ⬝ᵥ H⁻¹.mulVec v = x ⬝ᵥ A.mulVec x + c * (x ⬝ᵥ x) := by\n calc\n v ⬝ᵥ H⁻¹.mulVec v = x ⬝ᵥ v := dotProduct_comm _ _\n _ = x ⬝ᵥ H.mulVec x := by rw [hEq]\n _ = _ := by\n dsimp [H]\n rw [Matrix.add_mulVec, scalar_mulVec, dotProduct_add, dotProduct_smul]\n rfl\n change (∑ i, (v ⬝ᵥ H⁻¹.mulVec (u i))^2) ≤ v ⬝ᵥ H⁻¹.mulVec v\n simp_rw [hsymm]\n rw [← hAx, hlev]\n exact le_add_of_nonneg_right (mul_nonneg hc.le hnon)\n\nlemma ridge_deterministic_prediction_bound {d n : ℕ}\n (u : Fin n → Fin d → ℝ) {c : ℝ} (hc : 0 < c)\n (test w : Fin d → ℝ) (s : ℝ) :\n s^2 * (∑ i, (test ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (u i))^2) +\n c^2 * (test ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec w)^2 ≤\n (s^2 + c * (w ⬝ᵥ w)) *\n (test ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec test) := by\n let H := (∑ i, outer (u i)) + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let lev := test ⬝ᵥ H⁻¹.mulVec test\n let winv := w ⬝ᵥ H⁻¹.mulVec w\n have hH : H.PosDef := ridge_posDef u hc\n have hInv : H⁻¹.PosSemidef := hH.inv.posSemidef\n have hlev0 : 0 ≤ lev := hInv.dotProduct_mulVec_nonneg test\n have hwinv0 : 0 ≤ winv := hInv.dotProduct_mulVec_nonneg w\n have hsum : (∑ i, (test ⬝ᵥ H⁻¹.mulVec (u i))^2) ≤ lev :=\n ridge_sum_coeff_sq_le_leverage u hc test\n have hcs := psd_cauchy hInv test w\n have hw := ridge_inverse_quadratic_le u hc w\n have hs2 : 0 ≤ s^2 := sq_nonneg s\n have hww : 0 ≤ w ⬝ᵥ w := by\n simp [dotProduct]\n exact Finset.sum_nonneg fun i _ => mul_self_nonneg (w i)\n have hbias : c^2 * (test ⬝ᵥ H⁻¹.mulVec w)^2 ≤\n c * (w ⬝ᵥ w) * lev := by\n have h1 := mul_le_mul_of_nonneg_left hcs (sq_nonneg c)\n have h2 := mul_le_mul_of_nonneg_left hw (mul_nonneg hc.le hlev0)\n nlinarith [mul_nonneg hlev0 hwinv0]\n dsimp [H] at hsum hcs hw ⊢\n dsimp [lev, winv, H] at hlev0 hbias\n calc\n _ ≤ s^2 * (test ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec test) +\n c * (w ⬝ᵥ w) * (test ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec test) := by gcongr\n _ = _ := by ring\n\nlemma ridge_abs_bilinear_le {d n : ℕ} (u : Fin n → Fin d → ℝ)\n {c : ℝ} (hc : 0 < c) (v w : Fin d → ℝ) :\n |v ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec w| ≤\n ((v ⬝ᵥ v) + (w ⬝ᵥ w)) / (2 * c) := by\n let H := (∑ i, outer (u i)) + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let xv := v ⬝ᵥ H⁻¹.mulVec v\n let xw := w ⬝ᵥ H⁻¹.mulVec w\n let z := v ⬝ᵥ H⁻¹.mulVec w\n have hH : H.PosDef := ridge_posDef u hc\n have hInv : H⁻¹.PosSemidef := hH.inv.posSemidef\n have hv0 : 0 ≤ xv := hInv.dotProduct_mulVec_nonneg v\n have hw0 : 0 ≤ xw := hInv.dotProduct_mulVec_nonneg w\n have hz := psd_cauchy hInv v w\n have hv := ridge_inverse_quadratic_le u hc v\n have hw := ridge_inverse_quadratic_le u hc w\n have ham : 2 * |z| ≤ xv + xw := by\n have hsq : |z|^2 ≤ xv * xw := by simpa [sq_abs] using hz\n nlinarith [sq_nonneg (xv - xw), sq_nonneg (|z|), mul_nonneg hv0 hw0]\n have hscale : 2 * c * |z| ≤ (v ⬝ᵥ v) + (w ⬝ᵥ w) := by\n nlinarith [mul_nonneg hc.le (sub_nonneg.mpr ham)]\n change |z| ≤ ((v ⬝ᵥ v) + (w ⬝ᵥ w)) / (2 * c)\n rw [le_div_iff₀ (mul_pos (by norm_num) hc)]\n nlinarith\n\nlemma empirical_mulVec_apply {d n : ℕ} (u : Fin n → Fin d → ℝ)\n (w : Fin d → ℝ) (j : Fin d) :\n (∑ i, outer (u i)).mulVec w j = ∑ i, u i j * (u i ⬝ᵥ w) := by\n simp only [Matrix.mulVec, dotProduct]\n calc\n (∑ k, (∑ i, outer (u i)) j k * w k) =\n ∑ k, ∑ i, outer (u i) j k * w k := by\n apply Finset.sum_congr rfl\n intro k _\n rw [Matrix.sum_apply, Finset.sum_mul]\n _ = ∑ i, ∑ k, outer (u i) j k * w k := Finset.sum_comm\n _ = ∑ i, u i j * ∑ k, u i k * w k := by\n apply Finset.sum_congr rfl\n intro i _\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro k _\n dsimp [outer]\n ring\n\nlemma ridge_scaled_solution {d n : ℕ} (hn : 0 < n)\n (u : Fin n → Fin d → ℝ) {lam : ℝ} (hlam : 0 < lam) (r : Fin d → ℝ) :\n (((n : ℝ)⁻¹ • (∑ i, outer (u i)) + lam •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec ((n : ℝ)⁻¹ • r) =\n (((∑ i, outer (u i)) + (lam * n) •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec r := by\n let q : ℝ := n\n let A := ∑ i, outer (u i)\n let M := q⁻¹ • A + lam • (1 : Matrix (Fin d) (Fin d) ℝ)\n let H := A + (lam * q) • (1 : Matrix (Fin d) (Fin d) ℝ)\n have hq : 0 < q := by\n dsimp [q]\n exact_mod_cast hn\n have hc : 0 < lam * q := mul_pos hlam hq\n have hA : A.PosSemidef := empirical_posSemidef u\n have hM : M.PosDef := by\n have hs : (q⁻¹ • A).PosSemidef := hA.smul (inv_nonneg.mpr hq.le)\n simpa [M, add_comm] using\n (Matrix.PosDef.one.smul hlam).add_posSemidef hs\n have hH : H.PosDef := by simpa [H, q] using ridge_posDef u hc\n have hHM : H = q • M := by\n dsimp [H, M]\n rw [smul_add, smul_smul, smul_smul]\n rw [mul_inv_cancel₀ hq.ne', one_smul, mul_comm q lam]\n change M⁻¹.mulVec (q⁻¹ • r) = H⁻¹.mulVec r\n apply (Matrix.mulVec_injective_of_isUnit hH.isUnit)\n nth_rw 1 [hHM]\n rw [Matrix.smul_mulVec]\n have hMinv : M * M⁻¹ = 1 :=\n Matrix.mul_nonsing_inv M (M.isUnit_iff_isUnit_det.mp hM.isUnit)\n have hHinv : H * H⁻¹ = 1 :=\n Matrix.mul_nonsing_inv H (H.isUnit_iff_isUnit_det.mp hH.isUnit)\n ext j\n simp only [Matrix.mulVec_mulVec]\n rw [hMinv, hHinv]\n simp [q, hq.ne']\n\nlemma ridge_prediction_error_identity {d n : ℕ} (hn : 0 < n)\n (u : Fin n → Fin d → ℝ) (eps : Fin n → ℝ) (w test : Fin d → ℝ)\n {lam : ℝ} (hlam : 0 < lam) :\n test ⬝ᵥ (((n : ℝ)⁻¹ • (∑ i, outer (u i)) + lam •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec\n (fun j => (n : ℝ)⁻¹ * ∑ i, u i j * ((w ⬝ᵥ u i) + eps i)) -\n test ⬝ᵥ w =\n (∑ i, (test ⬝ᵥ (((∑ i, outer (u i)) + (lam * n) •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (u i)) * eps i) -\n (lam * n) * (test ⬝ᵥ (((∑ i, outer (u i)) + (lam * n) •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec w) := by\n let A := ∑ i, outer (u i)\n let c : ℝ := lam * n\n let H := A + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let noise : Fin d → ℝ := fun j => ∑ i, u i j * eps i\n let resp : Fin d → ℝ := fun j => ∑ i, u i j * ((w ⬝ᵥ u i) + eps i)\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n have hc : 0 < c := mul_pos hlam hnR\n have hH : H.PosDef := by simpa [H, A, c] using ridge_posDef u hc\n have hresp : resp = H.mulVec w + noise - c • w := by\n ext j\n simp only [resp, H, A, noise, Matrix.add_mulVec, scalar_mulVec, Pi.add_apply,\n Pi.sub_apply, Pi.smul_apply, smul_eq_mul]\n rw [empirical_mulVec_apply]\n have hsum : (∑ i, u i j * ((w ⬝ᵥ u i) + eps i)) =\n (∑ i, u i j * (w ⬝ᵥ u i)) + ∑ i, u i j * eps i := by\n rw [← Finset.sum_add_distrib]\n apply Finset.sum_congr rfl\n intro i _\n ring\n rw [hsum]\n have hcomm : (∑ i, u i j * (w ⬝ᵥ u i)) =\n ∑ i, u i j * (u i ⬝ᵥ w) := by\n apply Finset.sum_congr rfl\n intro i _\n rw [dotProduct_comm w (u i)]\n rw [hcomm]\n ring\n have hscaled := ridge_scaled_solution hn u hlam resp\n have hinput : (fun j => (n : ℝ)⁻¹ *\n ∑ i, u i j * ((w ⬝ᵥ u i) + eps i)) = (n : ℝ)⁻¹ • resp := by\n ext j\n rfl\n rw [hinput, hscaled]\n have hHinv : H⁻¹ * H = 1 :=\n Matrix.nonsing_inv_mul H (H.isUnit_iff_isUnit_det.mp hH.isUnit)\n have herr : H⁻¹.mulVec resp = w + H⁻¹.mulVec noise - c • H⁻¹.mulVec w := by\n rw [hresp]\n simp only [Matrix.mulVec_sub, Matrix.mulVec_add, Matrix.mulVec_smul]\n rw [Matrix.mulVec_mulVec, hHinv]\n simp\n rw [herr, dotProduct_sub, dotProduct_add, dotProduct_smul]\n have hnoise : test ⬝ᵥ H⁻¹.mulVec noise =\n ∑ i, (test ⬝ᵥ H⁻¹.mulVec (u i)) * eps i := by\n have hnoisevec : noise = ∑ i, eps i • u i := by\n ext j\n dsimp [noise]\n simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul]\n apply Finset.sum_congr rfl\n intro i _\n ring\n rw [hnoisevec]\n change test ⬝ᵥ (H⁻¹).mulVecLin (∑ i, eps i • u i) = _\n rw [map_sum]\n simp_rw [map_smul]\n simp only [Matrix.mulVecLin_apply]\n have hdot := dotProduct_sum test Finset.univ\n (fun i => eps i • H⁻¹.mulVec (u i))\n simp only [Finset.sum_filter, Finset.mem_univ, ↓reduceIte] at hdot\n rw [hdot]\n apply Finset.sum_congr rfl\n intro i _\n rw [dotProduct_smul]\n simp [smul_eq_mul, mul_comm]\n rw [hnoise]\n dsimp [H, A, c]\n ring\n\nlemma scalar_one_sub_outer_posSemidef {d : ℕ} (v : Fin d → ℝ) (B : ℝ)\n (hv : v ⬝ᵥ v ≤ B^2) :\n (B^2 • (1 : Matrix (Fin d) (Fin d) ℝ) - outer v).PosSemidef := by\n have hs : (B^2 • (1 : Matrix (Fin d) (Fin d) ℝ)).PosSemidef :=\n Matrix.PosSemidef.one.smul (sq_nonneg B)\n have ho : (outer v).PosSemidef := outer_posSemidef v\n apply Matrix.PosSemidef.of_dotProduct_mulVec_nonneg (hs.1.sub ho.1)\n intro x\n change 0 ≤ x ⬝ᵥ (B^2 • (1 : Matrix (Fin d) (Fin d) ℝ) - outer v).mulVec x\n rw [Matrix.sub_mulVec, scalar_mulVec, dotProduct_sub, dotProduct_smul,\n dot_outer_mulVec]\n simp only [smul_eq_mul]\n have hx : 0 ≤ x ⬝ᵥ x := by\n simp only [dotProduct]\n exact Finset.sum_nonneg fun i _ => mul_self_nonneg (x i)\n have hcs : (v ⬝ᵥ x)^2 ≤ (v ⬝ᵥ v) * (x ⬝ᵥ x) := by\n simpa [dotProduct, pow_two] using\n (Finset.sum_mul_sq_le_sq_mul_sq Finset.univ v x)\n nlinarith\n\nlemma inverse_quadratic_antitone_add_psd {d : ℕ}\n {G R : Matrix (Fin d) (Fin d) ℝ}\n (hG : G.PosDef) (hR : R.PosDef) (hRG : (R - G).PosSemidef)\n (v : Fin d → ℝ) :\n v ⬝ᵥ R⁻¹.mulVec v ≤ v ⬝ᵥ G⁻¹.mulVec v := by\n let x := R⁻¹.mulVec v\n let y := G⁻¹.mulVec v\n have hRx : R.mulVec x = v := by\n dsimp [x]\n rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv R\n (R.isUnit_iff_isUnit_det.mp hR.isUnit), Matrix.one_mulVec]\n have hGy : G.mulVec y = v := by\n dsimp [y]\n rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv G\n (G.isUnit_iff_isUnit_det.mp hG.isUnit), Matrix.one_mulVec]\n have hsymG (a b : Fin d → ℝ) : a ⬝ᵥ G.mulVec b = b ⬝ᵥ G.mulVec a :=\n dot_mulVec_comm_of_posSemidef hG.posSemidef a b\n have hsymR (a b : Fin d → ℝ) : a ⬝ᵥ R.mulVec b = b ⬝ᵥ R.mulVec a :=\n dot_mulVec_comm_of_posSemidef hR.posSemidef a b\n have horder : x ⬝ᵥ G.mulVec x ≤ x ⬝ᵥ R.mulVec x := by\n have hp := hRG.dotProduct_mulVec_nonneg x\n rw [Matrix.sub_mulVec, dotProduct_sub] at hp\n exact sub_nonneg.mp hp\n have hsquare := hG.posSemidef.dotProduct_mulVec_nonneg (x - y)\n have hsquare' : 0 ≤ x ⬝ᵥ G.mulVec x - 2 * (x ⬝ᵥ v) + y ⬝ᵥ v := by\n change 0 ≤ (x - y) ⬝ᵥ G.mulVec (x - y) at hsquare\n rw [Matrix.mulVec_sub, dotProduct_sub, sub_dotProduct, sub_dotProduct] at hsquare\n rw [hGy] at hsquare\n have hxy : y ⬝ᵥ G.mulVec x = x ⬝ᵥ v := by rw [hsymG, hGy]\n rw [hxy] at hsquare\n linarith\n have hleft : v ⬝ᵥ R⁻¹.mulVec v = 2 * (x ⬝ᵥ v) - x ⬝ᵥ R.mulVec x := by\n dsimp [x]\n rw [dotProduct_comm v (R⁻¹.mulVec v), hRx]\n ring\n have hright : v ⬝ᵥ G⁻¹.mulVec v = y ⬝ᵥ v := by\n dsimp [y]\n exact dotProduct_comm _ _\n rw [hleft, hright]\n linarith\n\nlemma ridge_le_common_leverage {d n : ℕ} (u : Fin n → Fin d → ℝ)\n (test : Fin d → ℝ) {c B : ℝ} (hcB : B^2 < c)\n (htest : test ⬝ᵥ test ≤ B^2) :\n test ⬝ᵥ (((∑ i, outer (u i)) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec test ≤\n test ⬝ᵥ (((∑ i, outer (u i)) + outer test +\n (c - B^2) • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec test := by\n let R := (∑ i, outer (u i)) + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let G := (∑ i, outer (u i)) + outer test +\n (c - B^2) • (1 : Matrix (Fin d) (Fin d) ℝ)\n have hR : R.PosDef := by\n simpa [R] using ridge_posDef u (lt_of_le_of_lt (sq_nonneg B) hcB)\n have hAG : ((∑ i, outer (u i)) + outer test).PosSemidef :=\n (empirical_posSemidef u).add (outer_posSemidef test)\n have hG : G.PosDef := by\n simpa [G, add_assoc, add_comm, add_left_comm] using\n (scalar_one_posDef (d := d) (sub_pos.mpr hcB)).add_posSemidef hAG\n have hdiff : R - G = B^2 ��� (1 : Matrix (Fin d) (Fin d) ℝ) - outer test := by\n dsimp [R, G]\n module\n exact inverse_quadratic_antitone_add_psd hG hR\n (hdiff ▸ scalar_one_sub_outer_posSemidef test B htest) test\n\nlemma trace_mul_outer {d : ℕ} (M : Matrix (Fin d) (Fin d) ℝ)\n (u : Fin d → ℝ) :\n Matrix.trace (M * outer u) = u ⬝ᵥ M.mulVec u := by\n simp only [Matrix.trace, Matrix.diag, Matrix.mul_apply, outer, Matrix.of_apply,\n dotProduct, Matrix.mulVec]\n apply Finset.sum_congr rfl\n intro i hi\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro j hj\n ring\n\nlemma effective_dimension_tangent {d : ℕ}\n {A K : Matrix (Fin d) (Fin d) ℝ}\n (hA : A.PosSemidef) (hK : K.PosSemidef) {c : ℝ} (hc : 0 < c) :\n Matrix.trace ((A + c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ * A) ≤\n Matrix.trace ((K + c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ * K) +\n c * Matrix.trace ((K + c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ *\n (A - K) * (K + c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹) := by\n let Q := A + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let P := K + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n let H := A - K\n have hQ : Q.PosDef := by\n simpa [Q, add_comm] using (scalar_one_posDef (d := d) hc).add_posSemidef hA\n have hP : P.PosDef := by\n simpa [P, add_comm] using (scalar_one_posDef (d := d) hc).add_posSemidef hK\n have hQmul : Q * Q⁻¹ = 1 :=\n Matrix.mul_nonsing_inv Q (Q.isUnit_iff_isUnit_det.mp hQ.isUnit)\n have hQinvMul : Q⁻¹ * Q = 1 :=\n Matrix.nonsing_inv_mul Q (Q.isUnit_iff_isUnit_det.mp hQ.isUnit)\n have hPmul : P * P⁻¹ = 1 :=\n Matrix.mul_nonsing_inv P (P.isUnit_iff_isUnit_det.mp hP.isUnit)\n have hPinvMul : P⁻¹ * P = 1 :=\n Matrix.nonsing_inv_mul P (P.isUnit_iff_isUnit_det.mp hP.isUnit)\n have hQP : Q - P = H := by dsimp [Q, P, H]; module\n have hresL : P⁻¹ - Q⁻¹ = P⁻¹ * H * Q⁻¹ := by\n calc\n P⁻¹ - Q⁻¹ = P⁻¹ * (Q * Q⁻¹) - (P⁻¹ * P) * Q⁻¹ := by\n rw [hQmul, hPinvMul]; simp\n _ = P⁻¹ * (Q - P) * Q⁻¹ := by noncomm_ring\n _ = P⁻¹ * H * Q⁻¹ := by rw [hQP]\n have hresR : P⁻¹ - Q⁻¹ = Q⁻¹ * H * P⁻¹ := by\n calc\n P⁻¹ - Q⁻¹ = (Q⁻¹ * Q) * P⁻¹ - Q⁻¹ * (P * P⁻¹) := by\n rw [hQinvMul, hPmul]; simp\n _ = Q⁻¹ * (Q - P) * P⁻¹ := by noncomm_ring\n _ = Q⁻¹ * H * P⁻¹ := by rw [hQP]\n let Rem := P⁻¹ * H * Q⁻¹ * H * P⁻¹\n have hRemEq : Rem = P⁻¹ * H * P⁻¹ - (P⁻¹ - Q⁻¹) := by\n calc\n Rem = P⁻¹ * H * (Q⁻¹ * H * P⁻¹) := by dsimp [Rem]; noncomm_ring\n _ = P⁻¹ * H * (P⁻¹ - Q⁻¹) := by rw [← hresR]\n _ = P⁻¹ * H * P⁻¹ - P⁻¹ * H * Q⁻¹ := by noncomm_ring\n _ = P⁻¹ * H * P⁻¹ - (P⁻¹ - Q⁻¹) := by rw [hresL]\n have hHherm : H.IsHermitian := hA.1.sub hK.1\n have hRemPSD : Rem.PosSemidef := by\n have hz := hQ.inv.posSemidef.conjTranspose_mul_mul_same (H * P⁻¹)\n have hPinvHerm : P⁻¹.IsHermitian := hP.inv.1\n have heq : Matrix.conjTranspose (H * P⁻¹) = P⁻¹ * H := by\n rw [Matrix.conjTranspose_mul, hPinvHerm.eq, hHherm.eq]\n rw [heq] at hz\n simpa [Rem, mul_assoc] using hz\n have hRemTrace : 0 ≤ Matrix.trace Rem := hRemPSD.trace_nonneg\n have htraceInv : Matrix.trace Q⁻¹ = Matrix.trace P⁻¹ -\n Matrix.trace (P⁻¹ * H * P⁻¹) + Matrix.trace Rem := by\n have hm : Q⁻¹ = P⁻¹ - P⁻¹ * H * P⁻¹ + Rem := by rw [hRemEq]; module\n rw [hm, Matrix.trace_add, Matrix.trace_sub]\n have hQA : Q⁻¹ * A = 1 - c • Q⁻¹ := by\n have hAQ : A = Q - c • (1 : Matrix (Fin d) (Fin d) ℝ) := by dsimp [Q]; module\n rw [hAQ, Matrix.mul_sub, Matrix.mul_smul, Matrix.mul_one, hQinvMul]\n have hPK : P⁻¹ * K = 1 - c • P⁻¹ := by\n have hKP : K = P - c • (1 : Matrix (Fin d) (Fin d) ℝ) := by dsimp [P]; module\n rw [hKP, Matrix.mul_sub, Matrix.mul_smul, Matrix.mul_one, hPinvMul]\n change Matrix.trace (Q⁻¹ * A) ≤ Matrix.trace (P⁻¹ * K) +\n c * Matrix.trace (P⁻¹ * H * P⁻¹)\n rw [hQA, hPK, Matrix.trace_sub, Matrix.trace_sub, Matrix.trace_smul,\n Matrix.trace_smul]\n simp only [smul_eq_mul]\n nlinarith [mul_nonneg hc.le hRemTrace]\n\nlemma trace_mul_empirical {d n : ℕ} (M : Matrix (Fin d) (Fin d) ℝ)\n (u : Fin n → Fin d → ℝ) :\n Matrix.trace (M * (∑ i, outer (u i))) =\n ∑ i, u i ⬝ᵥ M.mulVec (u i) := by\n rw [Matrix.mul_sum, Matrix.trace_sum]\n apply Finset.sum_congr rfl\n intro i hi\n exact trace_mul_outer M (u i)\n\nlemma measurable_matrix_det {Z : Type*} [MeasurableSpace Z] {d : ℕ}\n (A : Z → Matrix (Fin d) (Fin d) ℝ)\n (hA : ∀ i j, Measurable (fun z => A z i j)) :\n Measurable (fun z => (A z).det) := by\n simp only [Matrix.det_apply, smul_eq_mul]\n apply Finset.measurable_sum Finset.univ\n intro p hp\n apply Measurable.const_smul\n apply Finset.measurable_prod Finset.univ\n intro i hi\n exact hA _ _\n\nlemma measurable_matrix_inv_entry {Z : Type*} [MeasurableSpace Z] {d : ℕ}\n (A : Z → Matrix (Fin d) (Fin d) ℝ)\n (hA : ∀ i j, Measurable (fun z => A z i j)) (i j : Fin d) :\n Measurable (fun z => (A z)⁻¹ i j) := by\n simp only [Matrix.inv_def, Matrix.smul_apply, Ring.inverse_eq_inv,\n Matrix.adjugate_apply]\n apply Measurable.mul\n · exact (measurable_matrix_det A hA).inv\n · apply measurable_matrix_det\n intro k l\n by_cases h : k = j\n · subst k\n simp only [Matrix.updateRow_self]\n exact measurable_const\n · simp only [Matrix.updateRow_ne h]\n exact hA _ _\n\nlemma measurable_bilinear_inverse {Z : Type*} [MeasurableSpace Z] {d : ℕ}\n (A : Z → Matrix (Fin d) (Fin d) ℝ)\n (hA : ∀ i j, Measurable (fun z => A z i j))\n (u v : Z → Fin d → ℝ) (hu : Measurable u) (hv : Measurable v) :\n Measurable (fun z => u z ⬝ᵥ (A z)⁻¹.mulVec (v z)) := by\n simp only [dotProduct, Matrix.mulVec]\n apply Finset.measurable_sum Finset.univ\n intro i hi\n apply ((measurable_pi_apply i).comp hu).mul\n apply Finset.measurable_sum Finset.univ\n intro j hj\n exact (measurable_matrix_inv_entry A hA i j).mul\n ((measurable_pi_apply j).comp hv)\n\nlemma featureCovariance_posSemidef {Ω : Type*} [MeasurableSpace Ω] {d : ℕ}\n (D : Measure Ω) (ψ : Ω → Fin d → ℝ)\n (hψ : ∀ j, AEMeasurable (fun x => ψ x j) D)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D) :\n (featureCovariance D ψ).PosSemidef := by\n have hherm : (featureCovariance D ψ).IsHermitian := by\n change Matrix.conjTranspose (featureCovariance D ψ) = featureCovariance D ψ\n ext i j\n simp only [featureCovariance, Matrix.conjTranspose_apply, Matrix.of_apply, star_trivial]\n apply integral_congr_ae\n filter_upwards with x\n ring\n apply Matrix.PosSemidef.of_dotProduct_mulVec_nonneg hherm\n intro v\n change 0 ≤ v ⬝ᵥ (featureCovariance D ψ).mulVec v\n let g : Ω → ℝ := fun x => v ⬝ᵥ ψ x\n have hgmeas : AEMeasurable g D := by\n dsimp [g, dotProduct]\n fun_prop\n have hg2int : Integrable (fun x => (g x)^2) D := by\n have hdouble : Integrable (fun x => ∑ i, ∑ j,\n (v i * v j) * (ψ x i * ψ x j)) D :=\n integrable_finset_sum Finset.univ fun i _ =>\n integrable_finset_sum Finset.univ fun j _ =>\n (hψint i j).const_mul (v i * v j)\n apply hdouble.congr\n filter_upwards with x\n dsimp [g, dotProduct]\n rw [pow_two, Finset.sum_mul_sum]\n apply Finset.sum_congr rfl\n intro i hi\n apply Finset.sum_congr rfl\n intro j hj\n ring\n have heq : v ⬝ᵥ (featureCovariance D ψ).mulVec v = ∫ x, (g x)^2 ∂D := by\n calc\n v ⬝ᵥ (featureCovariance D ψ).mulVec v =\n ∑ i, ∑ j, (v i * v j) * ∫ x, ψ x i * ψ x j ∂D := by\n simp only [dotProduct, Matrix.mulVec, featureCovariance, Matrix.of_apply]\n apply Finset.sum_congr rfl\n intro i hi\n rw [Finset.mul_sum]\n apply Finset.sum_congr rfl\n intro j hj\n ring\n _ = ∑ i, ∑ j, ∫ x, (v i * v j) * (ψ x i * ψ x j) ∂D := by\n apply Finset.sum_congr rfl\n intro i hi\n apply Finset.sum_congr rfl\n intro j hj\n rw [integral_const_mul]\n _ = ∫ x, ∑ i, ∑ j, (v i * v j) * (ψ x i * ψ x j) ∂D := by\n rw [integral_finset_sum Finset.univ (fun i _ =>\n integrable_finset_sum Finset.univ fun j _ =>\n (hψint i j).const_mul (v i * v j))]\n apply Finset.sum_congr rfl\n intro i hi\n rw [integral_finset_sum Finset.univ (fun j _ =>\n (hψint i j).const_mul (v i * v j))]\n _ = ∫ x, (g x)^2 ∂D := by\n apply integral_congr_ae\n filter_upwards with x\n dsimp [g, dotProduct]\n rw [pow_two, Finset.sum_mul_sum]\n apply Finset.sum_congr rfl\n intro i hi\n apply Finset.sum_congr rfl\n intro j hj\n ring\n rw [heq]\n exact integral_nonneg (fun x => sq_nonneg (g x))\n\nlemma integrable_trace_mul_outer {Ω : Type*} [MeasurableSpace Ω] {d : ℕ}\n {D : Measure Ω} (ψ : Ω → Fin d → ℝ)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D)\n (M : Matrix (Fin d) (Fin d) ℝ) :\n Integrable (fun x => Matrix.trace (M * outer (ψ x))) D := by\n have hsum : Integrable (fun x => ∑ i, ∑ j,\n M i j * (ψ x j * ψ x i)) D :=\n integrable_finset_sum Finset.univ fun i _ =>\n integrable_finset_sum Finset.univ fun j _ =>\n (hψint j i).const_mul (M i j)\n apply hsum.congr\n filter_upwards with x\n simp only [Matrix.trace, Matrix.diag, Matrix.mul_apply, outer, Matrix.of_apply]\n\nlemma integral_trace_mul_outer {Ω : Type*} [MeasurableSpace Ω] {d : ℕ}\n {D : Measure Ω} (ψ : Ω → Fin d → ℝ)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D)\n (M : Matrix (Fin d) (Fin d) ℝ) :\n (∫ x, Matrix.trace (M * outer (ψ x)) ∂D) =\n Matrix.trace (M * featureCovariance D ψ) := by\n simp only [Matrix.trace, Matrix.diag, Matrix.mul_apply, outer, featureCovariance,\n Matrix.of_apply]\n rw [integral_finset_sum Finset.univ (fun i _ =>\n integrable_finset_sum Finset.univ fun j _ =>\n (hψint j i).const_mul (M i j))]\n apply Finset.sum_congr rfl\n intro i hi\n rw [integral_finset_sum Finset.univ (fun j _ =>\n (hψint j i).const_mul (M i j))]\n apply Finset.sum_congr rfl\n intro j hj\n rw [integral_const_mul]\n\nlemma integrable_trace_centered_empirical\n {Ω : Type*} [MeasurableSpace Ω] {d N : ℕ}\n (D : Measure Ω) [IsProbabilityMeasure D]\n (ψ : Ω → Fin d → ℝ)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D)\n (M : Matrix (Fin d) (Fin d) ℝ) :\n Integrable (fun S => Matrix.trace (M * ((∑ i : Fin N, outer (ψ (S i))) -\n (N : ℝ) • featureCovariance D ψ)))\n (Measure.pi fun _ : Fin N => D) := by\n let μ : Measure (Fin N → Ω) := Measure.pi fun _ : Fin N => D\n let q : ℝ := N\n let K := featureCovariance D ψ\n let f : Ω → ℝ := fun x => Matrix.trace (M * outer (ψ x))\n have hfint : Integrable f D := integrable_trace_mul_outer ψ hψint M\n have hcomp (i : Fin N) : Integrable (fun S => f (S i)) μ := by\n simpa [μ] using (integrable_comp_eval (μ := fun _ : Fin N => D) hfint)\n have hsum : Integrable (fun S => (∑ i : Fin N, f (S i)) -\n q * Matrix.trace (M * K)) μ :=\n (integrable_finset_sum Finset.univ fun i _ => hcomp i).sub\n (integrable_const (c := q * Matrix.trace (M * K)))\n apply hsum.congr\n filter_upwards with S\n dsimp [f]\n rw [Matrix.mul_sub, Matrix.mul_sum, Matrix.mul_smul, Matrix.trace_sub,\n Matrix.trace_sum, Matrix.trace_smul]\n simp only [smul_eq_mul]\n simp [q, K]\n\nlemma integral_trace_centered_empirical\n {Ω : Type*} [MeasurableSpace Ω] {d N : ℕ}\n (D : Measure Ω) [IsProbabilityMeasure D]\n (ψ : Ω → Fin d → ℝ)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D)\n (M : Matrix (Fin d) (Fin d) ℝ) :\n (∫ S, Matrix.trace (M * ((∑ i : Fin N, outer (ψ (S i))) -\n (N : ℝ) • featureCovariance D ψ))\n ∂(Measure.pi fun _ : Fin N => D)) = 0 := by\n let μ : Measure (Fin N → Ω) := Measure.pi fun _ : Fin N => D\n let q : ℝ := N\n let K := featureCovariance D ψ\n let f : Ω → ℝ := fun x => Matrix.trace (M * outer (ψ x))\n have hfint : Integrable f D := integrable_trace_mul_outer ψ hψint M\n have hcomp (i : Fin N) : Integrable (fun S => f (S i)) μ := by\n simpa [μ] using (integrable_comp_eval (μ := fun _ : Fin N => D) hfint)\n have hcint : Integrable (fun _ : Fin N → Ω => q * Matrix.trace (M * K)) μ :=\n integrable_const (c := q * Matrix.trace (M * K))\n have hpoint (S : Fin N → Ω) :\n Matrix.trace (M * ((∑ i : Fin N, outer (ψ (S i))) - q • K)) =\n (∑ i : Fin N, f (S i)) - q * Matrix.trace (M * K) := by\n dsimp [f]\n rw [Matrix.mul_sub, Matrix.mul_sum, Matrix.mul_smul, Matrix.trace_sub,\n Matrix.trace_sum, Matrix.trace_smul]\n simp only [smul_eq_mul]\n calc\n (∫ S, Matrix.trace (M * ((∑ i : Fin N, outer (ψ (S i))) -\n (N : ℝ) • featureCovariance D ψ)) ∂μ) =\n ∫ S, (∑ i : Fin N, f (S i)) - q * Matrix.trace (M * K) ∂μ := by\n apply integral_congr_ae\n filter_upwards with S\n exact hpoint S\n _ = (∑ i : Fin N, ∫ S, f (S i) ∂μ) - q * Matrix.trace (M * K) := by\n rw [integral_sub (integrable_finset_sum Finset.univ fun i _ => hcomp i) hcint,\n integral_finset_sum Finset.univ (fun i _ => hcomp i)]\n simp [μ]\n _ = (∑ i : Fin N, ∫ x, f x ∂D) - q * Matrix.trace (M * K) := by\n apply congrArg (fun z => z - q * Matrix.trace (M * K))\n apply Finset.sum_congr rfl\n intro i hi\n simpa [μ] using integral_comp_eval (μ := fun _ : Fin N => D)\n hfint.aestronglyMeasurable\n _ = 0 := by\n rw [integral_trace_mul_outer ψ hψint M]\n simp [q, K]\n\nlemma empirical_effective_dimension_integral_le\n {Ω : Type*} [MeasurableSpace Ω] {d N : ℕ}\n (D : Measure Ω) [IsProbabilityMeasure D]\n (ψ : Ω → Fin d → ℝ) (hψmeas : Measurable ψ)\n (hψ : ∀ j, AEMeasurable (fun x => ψ x j) D)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D)\n (B : ℝ) (hB : ∀ x, (∑ j, ψ x j ^ 2) ≤ B^2)\n {c : ℝ} (hc : 0 < c) :\n (∫ S, ∑ i : Fin N, ψ (S i) ⬝ᵥ\n (((∑ k : Fin N, outer (ψ (S k))) + c •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (ψ (S i))\n ∂(Measure.pi fun _ : Fin N => D)) ≤\n Matrix.trace ((((N : ℝ) • featureCovariance D ψ +\n c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹) *\n ((N : ℝ) • featureCovariance D ψ)) := by\n let μ : Measure (Fin N → Ω) := Measure.pi fun _ : Fin N => D\n let A : (Fin N → Ω) → Matrix (Fin d) (Fin d) ℝ := fun S =>\n ∑ k : Fin N, outer (ψ (S k))\n let Q : (Fin N → Ω) → Matrix (Fin d) (Fin d) ℝ := fun S => A S + c • 1\n let K : Matrix (Fin d) (Fin d) ℝ := (N : ℝ) • featureCovariance D ψ\n let P : Matrix (Fin d) (Fin d) ℝ := K + c • 1\n let lev : Fin N → (Fin N → Ω) → ��� := fun i S =>\n ψ (S i) ⬝ᵥ (Q S)⁻¹.mulVec (ψ (S i))\n have hcoord (i : Fin N) (j : Fin d) :\n Measurable (fun S : Fin N → Ω => ψ (S i) j) := by\n exact (measurable_pi_apply j).comp\n (hψmeas.comp (measurable_pi_apply i : Measurable (fun S : Fin N → Ω => S i)))\n have hAentry : ∀ j k, Measurable (fun S => Q S j k) := by\n intro j k\n simp only [Q, A, Matrix.add_apply, Matrix.sum_apply, outer, Matrix.of_apply,\n Matrix.smul_apply]\n apply Measurable.add\n · apply Finset.measurable_sum Finset.univ\n intro i hi\n exact (hcoord i j).mul (hcoord i k)\n · exact measurable_const\n have hlevmeas (i : Fin N) : Measurable (lev i) := by\n apply measurable_bilinear_inverse Q hAentry\n · exact hψmeas.comp (measurable_pi_apply i)\n · exact hψmeas.comp (measurable_pi_apply i)\n have hlev0 (i : Fin N) (S : Fin N → Ω) : 0 ≤ lev i S := by\n have hq : (Q S).PosDef := by\n simpa [Q, A] using ridge_posDef (fun k => ψ (S k)) hc\n exact hq.inv.posSemidef.dotProduct_mulVec_nonneg (ψ (S i))\n have hlevle (i : Fin N) (S : Fin N → Ω) : lev i S ≤ B^2 / c := by\n have hi := ridge_inverse_quadratic_le (fun k => ψ (S k)) hc (ψ (S i))\n have hb : ψ (S i) ⬝ᵥ ψ (S i) ≤ B^2 := by\n simpa [dotProduct, pow_two] using hB (S i)\n rw [le_div_iff₀ hc]\n simpa [lev, Q, mul_comm] using hi.trans hb\n have hlevint (i : Fin N) : Integrable (lev i) μ := by\n apply Integrable.of_bound (hlevmeas i).aestronglyMeasurable (B^2 / c)\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_of_nonneg (hlev0 i S)]\n exact hlevle i S\n have hsumint : Integrable (fun S => ∑ i : Fin N, lev i S) μ :=\n integrable_finset_sum Finset.univ fun i _ => hlevint i\n have hKpsd : K.PosSemidef :=\n (featureCovariance_posSemidef D ψ hψ hψint).smul (Nat.cast_nonneg N)\n have hP : P.PosDef := by\n simpa [P, add_comm] using (scalar_one_posDef (d := d) hc).add_posSemidef hKpsd\n let M : Matrix (Fin d) (Fin d) ℝ := P⁻¹ * P⁻¹\n let center : (Fin N → Ω) → ℝ := fun S => Matrix.trace (M * (A S - K))\n have hcenterint : Integrable center μ := by\n simpa [center, M, A, K, μ] using\n (integrable_trace_centered_empirical D ψ hψint M :\n Integrable (fun S => Matrix.trace (M * ((∑ i : Fin N, outer (ψ (S i))) -\n (N : ℝ) • featureCovariance D ψ)))\n (Measure.pi fun _ : Fin N => D))\n have hcenterzero : ∫ S, center S ∂μ = 0 := by\n simpa [center, M, A, K, μ] using\n (integral_trace_centered_empirical D ψ hψint M :\n (∫ S, Matrix.trace (M * ((∑ i : Fin N, outer (ψ (S i))) -\n (N : ℝ) • featureCovariance D ψ))\n ∂(Measure.pi fun _ : Fin N => D)) = 0)\n have hconstint : Integrable (fun _ : Fin N → Ω => Matrix.trace (P⁻¹ * K)) μ :=\n integrable_const (c := Matrix.trace (P⁻¹ * K))\n have hrhsint : Integrable (fun S => Matrix.trace (P⁻¹ * K) + c * center S) μ :=\n hconstint.add (hcenterint.const_mul c)\n have hpoint (S : Fin N → Ω) :\n (∑ i : Fin N, lev i S) ≤ Matrix.trace (P⁻¹ * K) + c * center S := by\n have ht := effective_dimension_tangent\n (empirical_posSemidef (fun k => ψ (S k))) hKpsd hc\n have hleft : Matrix.trace ((A S + c • 1)⁻¹ * A S) =\n ∑ i : Fin N, lev i S := by\n simpa [lev, Q] using\n trace_mul_empirical ((A S + c • 1)⁻¹) (fun i => ψ (S i))\n have hcycle : Matrix.trace (P⁻¹ * (A S - K) * P⁻¹) = center S := by\n dsimp [center, M]\n exact Matrix.trace_mul_cycle P⁻¹ (A S - K) P⁻¹\n change Matrix.trace ((A S + c • 1)⁻¹ * A S) ≤\n Matrix.trace (P⁻¹ * K) + c * Matrix.trace (P⁻¹ * (A S - K) * P⁻¹) at ht\n rw [hleft, hcycle] at ht\n exact ht\n calc\n (∫ S, ∑ i : Fin N, ψ (S i) ⬝ᵥ (((∑ k : Fin N, outer (ψ (S k))) +\n c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (ψ (S i)) ∂μ) =\n ∫ S, ∑ i : Fin N, lev i S ∂μ := by rfl\n _ ≤ ∫ S, Matrix.trace (P⁻¹ * K) + c * center S ∂μ := by\n apply integral_mono_ae hsumint hrhsint\n filter_upwards with S\n exact hpoint S\n _ = Matrix.trace (P⁻¹ * K) := by\n rw [integral_add hconstint (hcenterint.const_mul c), integral_const_mul,\n hcenterzero]\n simp [μ]\n _ = Matrix.trace ((((N : ℝ) • featureCovariance D ψ +\n c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹) *\n ((N : ℝ) • featureCovariance D ψ)) := by rfl\n\nlemma effective_dimension_scale {d : ℕ}\n (K : Matrix (Fin d) (Fin d) ℝ) (hK : K.PosSemidef)\n {q c : ℝ} (hq : 0 < q) (hc : 0 < c) :\n Matrix.trace ((q • K + c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ * (q • K)) =\n Matrix.trace ((K + (c / q) • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ * K) := by\n let P := K + (c / q) • (1 : Matrix (Fin d) (Fin d) ℝ)\n let Q := q • K + c • (1 : Matrix (Fin d) (Fin d) ℝ)\n have hcq : 0 < c / q := div_pos hc hq\n have hP : P.PosDef := by\n simpa [P, add_comm] using (scalar_one_posDef (d := d) hcq).add_posSemidef hK\n have hQ : Q.PosDef := by\n have hqK : (q • K).PosSemidef := hK.smul hq.le\n simpa [Q, add_comm] using (scalar_one_posDef (d := d) hc).add_posSemidef hqK\n have hQP : Q = q • P := by\n dsimp [Q, P]\n rw [smul_add, smul_smul]\n have hcancel : q * (c / q) = c := by field_simp\n rw [hcancel]\n have hQmul : Q * Q⁻¹ = 1 :=\n Matrix.mul_nonsing_inv Q (Q.isUnit_iff_isUnit_det.mp hQ.isUnit)\n have hPmul : P * P⁻¹ = 1 :=\n Matrix.mul_nonsing_inv P (P.isUnit_iff_isUnit_det.mp hP.isUnit)\n apply congrArg Matrix.trace\n apply hQ.isUnit.mul_left_cancel\n calc\n Q * (Q⁻¹ * (q • K)) = q • K := by\n rw [← Matrix.mul_assoc, hQmul, Matrix.one_mul]\n _ = Q * (P⁻¹ * K) := by\n rw [hQP, Matrix.smul_mul, ← Matrix.mul_assoc, hPmul, Matrix.one_mul]\n\ntheorem ch9_ridge_excess_risk_bound\n {Ω : Type*} [MeasurableSpace Ω] {𝒳 : Type*} [MeasurableSpace 𝒳] {d n : ℕ}\n (D : Measure Ω) [IsProbabilityMeasure D]\n (X : Ω → 𝒳) (feat : 𝒳 → (Fin d → ℝ))\n (ψ : Ω → (Fin d → ℝ)) (wstar : Fin d → ℝ)\n (ε : Fin n → Ω → ℝ) (Y : Fin n → Ω → ℝ)\n (what : (Fin n → Ω) → (Fin d → ℝ))\n (lam B σ : ℝ)\n (hn : 1 ≤ n)\n (hXmeas : Measurable X)\n (hfeatmeas : Measurable feat)\n (hψfac : ψ = fun ω => feat (X ω))\n (hψmeas : Measurable ψ)\n (hψ : ∀ j, AEMeasurable (fun x => ψ x j) D)\n (hψint : ∀ j k, Integrable (fun x => ψ x j * ψ x k) D)\n (hY : ∀ i x, Y i x = linPred wstar ψ x + ε i x)\n (hεint : ∀ i, Integrable (ε i) D)\n (hεsqint : ∀ i, Integrable (fun ω => (ε i ω)^2) D)\n (hεmean : ∀ i, MeasureTheory.condExp (MeasurableSpace.comap X inferInstance) D (ε i) =ᵐ[D] 0)\n (hεvar : ∀ i, MeasureTheory.condExp (MeasurableSpace.comap X inferInstance) D (fun ω => (ε i ω)^2) ≤ᵐ[D] fun _ => σ^2)\n (hiid : ∀ i j, D.map (fun ω => (X ω, Y i ω)) = D.map (fun ω => (X ω, Y j ω)))\n (hB : ∀ x, (∑ j, ψ x j ^ 2) ≤ B^2)\n (hlamB : B^2 < lam * n)\n (hExcInt : ∀ S, Integrable (fun x => (linPred (what S) ψ x - linPred wstar ψ x)^2) D)\n (hOuterInt : Integrable (fun S => ∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D) (Measure.pi fun _ => D))\n (hwhat : ∀ S : Fin n → Ω, what S = ((((n : ℝ)⁻¹) • Matrix.of (fun j k => ∑ i, ψ (S i) j * ψ (S i) k) + lam • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (fun j => ((n : ℝ)⁻¹) * ∑ i, ψ (S i) j * Y i (S i))) :\n ∫ S, (∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D) ∂(Measure.pi fun _ => D)\n ≤ ((Matrix.trace ((featureCovariance D ψ + ((lam * n - B^2) / (n + 1)) • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ * featureCovariance D ψ)) / n) * (σ^2 + lam * n * (∑ j, wstar j ^ 2)) := by\n classical\n have hn0 : 0 < n := lt_of_lt_of_le Nat.zero_lt_one hn\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn0\n let t : ℝ := lam * n\n let c : ℝ := t - B^2\n have ht : 0 < t := by\n dsimp [t]\n exact lt_of_le_of_lt (sq_nonneg B) hlamB\n have hc : 0 < c := by simpa [c, t] using sub_pos.mpr hlamB\n have hlam : 0 < lam := by nlinarith\n let iε : Fin n := ⟨0, hn0⟩\n let U : (Fin (n + 1) → 𝒳) → Fin n → Fin d → ℝ :=\n fun z k => feat (z k.castSucc)\n let V : (Fin (n + 1) → 𝒳) → Fin d → ℝ :=\n fun z => feat (z (Fin.last n))\n let H : (Fin (n + 1) → 𝒳) → Matrix (Fin d) (Fin d) ℝ :=\n fun z => (∑ k, outer (U z k)) + t • 1\n let coeff : (Fin (n + 1) → 𝒳) → Fin n → ℝ :=\n fun z k => V z ⬝ᵥ (H z)⁻¹.mulVec (U z k)\n let bias : (Fin (n + 1) → 𝒳) → ℝ :=\n fun z => -t * (V z ⬝ᵥ (H z)⁻¹.mulVec wstar)\n let a : (Fin (n + 1) → 𝒳) → Fin (n + 1) → ℝ :=\n fun z j => Fin.lastCases 0 (coeff z) j\n let enoise : Fin (n + 1) → Ω → ℝ :=\n fun j => Fin.lastCases (ε iε) (fun k => ε k) j\n have hUmeas (k : Fin n) : Measurable (fun z => U z k) := by\n exact hfeatmeas.comp (measurable_pi_apply k.castSucc)\n have hVmeas : Measurable V := by\n exact hfeatmeas.comp (measurable_pi_apply (Fin.last n))\n have hHentry : ∀ j k, Measurable (fun z => H z j k) := by\n intro j k\n simp only [H, Matrix.add_apply, Matrix.sum_apply, outer, Matrix.of_apply,\n Matrix.smul_apply]\n apply Measurable.add\n · apply Finset.measurable_sum Finset.univ\n intro r hr\n exact ((measurable_pi_apply j).comp (hUmeas r)).mul\n ((measurable_pi_apply k).comp (hUmeas r))\n · exact measurable_const\n have hcoeffmeas (k : Fin n) : Measurable (fun z => coeff z k) := by\n exact measurable_bilinear_inverse H hHentry V (fun z => U z k)\n hVmeas (hUmeas k)\n have hbiasmeas : Measurable bias := by\n have hz := measurable_bilinear_inverse H hHentry V (fun _ => wstar)\n hVmeas measurable_const\n exact measurable_const.mul hz\n have hameas : Measurable a := by\n apply measurable_pi_lambda\n intro j\n refine Fin.lastCases ?_ (fun k => ?_) j\n · simpa [a] using\n (measurable_const : Measurable (fun _ : Fin (n + 1) → 𝒳 => (0 : ℝ)))\n · simpa [a] using hcoeffmeas k\n have henoiseint : ∀ j, Integrable (enoise j) D := by\n intro j\n refine Fin.lastCases ?_ (fun k => ?_) j\n · simpa [enoise] using hεint iε\n · simpa [enoise] using hεint k\n have henoisesqint : ∀ j, Integrable (fun x => (enoise j x)^2) D := by\n intro j\n refine Fin.lastCases ?_ (fun k => ?_) j\n · simpa [enoise] using hεsqint iε\n · simpa [enoise] using hεsqint k\n have henoisemean : ∀ j,\n D[enoise j | MeasurableSpace.comap X inferInstance] =ᵐ[D] 0 := by\n intro j\n refine Fin.lastCases ?_ (fun k => ?_) j\n · simpa [enoise] using hεmean iε\n · simpa [enoise] using hεmean k\n have henoisevar : ∀ j,\n D[fun x => (enoise j x)^2 | MeasurableSpace.comap X inferInstance]\n ≤ᵐ[D] fun _ => σ^2 := by\n intro j\n refine Fin.lastCases ?_ (fun k => ?_) j\n · simpa [enoise] using hεvar iε\n · simpa [enoise] using hεvar k\n have hnorm (x : Ω) : ψ x ⬝ᵥ ψ x ≤ B^2 := by\n simpa [dotProduct, pow_two] using hB x\n let wnorm : ℝ := wstar ⬝ᵥ wstar\n have hwnorm : 0 ≤ wnorm := by\n dsimp [wnorm, dotProduct]\n exact Finset.sum_nonneg fun j _ => mul_self_nonneg (wstar j)\n let Ca : ℝ := B^2 / t\n let Cb : ℝ := (B^2 + wnorm) / 2\n have hCa : 0 ≤ Ca := div_nonneg (sq_nonneg B) ht.le\n have hCb : 0 ≤ Cb := by dsimp [Cb]; positivity\n have hacoeff (S : Fin (n + 1) → Ω) (k : Fin n) :\n |coeff (fun j => X (S j)) k| ≤ Ca := by\n let u : Fin n → Fin d → ℝ := fun r => ψ (S r.castSucc)\n let test : Fin d → ℝ := ψ (S (Fin.last n))\n have hr := ridge_abs_bilinear_le u ht test (u k)\n have hnum : (test ⬝ᵥ test) + (u k ⬝ᵥ u k) ≤ B^2 + B^2 :=\n add_le_add (hnorm _) (hnorm _)\n have hden : 0 < 2 * t := mul_pos (by norm_num) ht\n have hfrac : ((test ⬝ᵥ test) + (u k ⬝ᵥ u k)) / (2 * t) ≤ B^2 / t := by\n calc\n _ ≤ (B^2 + B^2) / (2 * t) := div_le_div_of_nonneg_right hnum hden.le\n _ = B^2 / t := by field_simp; ring\n simpa [coeff, H, U, V, Ca, t, u, test, hψfac] using hr.trans hfrac\n have habound (S : Fin (n + 1) → Ω) (j : Fin (n + 1)) :\n |a (fun k => X (S k)) j| ≤ Ca := by\n refine Fin.lastCases ?_ (fun k => ?_) j\n · simpa [a] using hCa\n · simpa [a] using hacoeff S k\n have hbbound (S : Fin (n + 1) → Ω) :\n |bias (fun k => X (S k))| ≤ Cb := by\n let u : Fin n → Fin d → ℝ := fun r => ψ (S r.castSucc)\n let test : Fin d → ℝ := ψ (S (Fin.last n))\n have hr := ridge_abs_bilinear_le u ht test wstar\n have hnum : (test ⬝ᵥ test) + (wstar ⬝ᵥ wstar) ≤ B^2 + wnorm := by\n exact add_le_add (hnorm _) (by rfl)\n have hden : 0 < 2 * t := mul_pos (by norm_num) ht\n have hfrac : ((test ⬝ᵥ test) + (wstar ⬝ᵥ wstar)) / (2 * t) ≤\n (B^2 + wnorm) / (2 * t) := div_le_div_of_nonneg_right hnum hden.le\n have hmul := mul_le_mul_of_nonneg_left (hr.trans hfrac) ht.le\n have heq : t * ((B^2 + wnorm) / (2 * t)) = Cb := by\n dsimp [Cb]\n field_simp\n rw [heq] at hmul\n simpa [bias, coeff, H, U, V, t, u, test, hψfac, abs_mul,\n abs_of_pos ht] using hmul\n have hsample := sample_linear_noise_bound X hXmeas enoise henoiseint\n henoisesqint henoisemean henoisevar a bias hameas hbiasmeas Ca Cb hCa hCb\n habound hbbound\n let train : (Fin (n + 1) → Ω) → Fin n → Ω :=\n fun S k => S k.castSucc\n let noiseTerm : (Fin (n + 1) → Ω) → ℝ := fun S =>\n (∑ j, a (fun k => X (S k)) j * enoise j (S j)) +\n bias (fun k => X (S k))\n let loss : (Fin (n + 1) → Ω) → ℝ := fun S =>\n (linPred (what (train S)) ψ (S (Fin.last n)) -\n linPred wstar ψ (S (Fin.last n)))^2\n have hpredict (S : Fin (n + 1) → Ω) :\n linPred (what (train S)) ψ (S (Fin.last n)) -\n linPred wstar ψ (S (Fin.last n)) = noiseTerm S := by\n let u : Fin n → Fin d → ℝ := fun k => ψ (S k.castSucc)\n let epsv : Fin n → ℝ := fun k => ε k (S k.castSucc)\n let test : Fin d → ℝ := ψ (S (Fin.last n))\n have hr := ridge_prediction_error_identity hn0 u epsv wstar test hlam\n have hmat : Matrix.of (fun j k =>\n ∑ i, ψ ((train S) i) j * ψ ((train S) i) k) =\n ∑ i, outer (u i) := by\n ext j k\n simp [Matrix.sum_apply, outer, train, u]\n rw [hwhat (train S), hmat]\n simp_rw [hY]\n simp only [linPred]\n change\n (((((n : ℝ)⁻¹ • (∑ i, outer (u i)) + lam •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec\n (fun j => (n : ℝ)⁻¹ * ∑ i, u i j *\n ((wstar ⬝ᵥ u i) + epsv i))) ⬝ᵥ test) -\n (wstar ⬝ᵥ test) = noiseTerm S\n rw [dotProduct_comm _ test, dotProduct_comm wstar test]\n rw [hr]\n dsimp [noiseTerm]\n rw [Fin.sum_univ_castSucc]\n simp [noiseTerm, a, enoise, coeff, bias, H, U, V, train, u, epsv,\n test, t, hY, hψfac]\n ring\n have hloss (S : Fin (n + 1) → Ω) : loss S = (noiseTerm S)^2 := by\n simp only [loss]\n rw [hpredict S]\n let μp : Measure (Fin (n + 1) → Ω) :=\n Measure.pi fun _ : Fin (n + 1) => D\n let zdesign : (Fin (n + 1) → Ω) → Fin (n + 1) → 𝒳 :=\n fun S k => X (S k)\n let varTerm : (Fin (n + 1) → Ω) → ℝ := fun S =>\n σ^2 * ∑ j, (a (zdesign S) j)^2 + (bias (zdesign S))^2\n have hzdesign : Measurable zdesign := by\n apply measurable_pi_lambda\n intro j\n exact hXmeas.comp (measurable_pi_apply j)\n have haeval (j : Fin (n + 1)) : Measurable (fun S => a (zdesign S) j) :=\n (measurable_pi_apply j).comp (hameas.comp hzdesign)\n have hbiaseval : Measurable (fun S => bias (zdesign S)) :=\n hbiasmeas.comp hzdesign\n have ha2int (j : Fin (n + 1)) :\n Integrable (fun S => (a (zdesign S) j)^2) μp := by\n apply Integrable.of_bound ((haeval j).pow_const 2).aestronglyMeasurable (Ca^2)\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_sq]\n exact sq_le_sq_of_abs_le hCa (by simpa [zdesign] using habound S j)\n have hb2int : Integrable (fun S => (bias (zdesign S))^2) μp := by\n apply Integrable.of_bound (hbiaseval.pow_const 2).aestronglyMeasurable (Cb^2)\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_sq]\n exact sq_le_sq_of_abs_le hCb (by simpa [zdesign] using hbbound S)\n have hvarint : Integrable varTerm μp := by\n exact ((integrable_finset_sum Finset.univ fun j _ => ha2int j).const_mul\n (σ^2)).add hb2int\n let common : (Fin (n + 1) → Ω) → Matrix (Fin d) (Fin d) ℝ :=\n fun S => (∑ j, outer (ψ (S j))) + c • 1\n let lev : Fin (n + 1) → (Fin (n + 1) → Ω) → ℝ :=\n fun i S => ψ (S i) ⬝ᵥ (common S)⁻¹.mulVec (ψ (S i))\n have hcommonentry : ∀ j k, Measurable (fun S => common S j k) := by\n intro j k\n simp only [common, Matrix.add_apply, Matrix.sum_apply, outer, Matrix.of_apply,\n Matrix.smul_apply]\n apply Measurable.add\n · apply Finset.measurable_sum Finset.univ\n intro i hi\n exact ((measurable_pi_apply j).comp (hψmeas.comp (measurable_pi_apply i))).mul\n ((measurable_pi_apply k).comp (hψmeas.comp (measurable_pi_apply i)))\n · exact measurable_const\n have hlevmeas (i : Fin (n + 1)) : Measurable (lev i) := by\n exact measurable_bilinear_inverse common hcommonentry\n (fun S => ψ (S i)) (fun S => ψ (S i))\n (hψmeas.comp (measurable_pi_apply i))\n (hψmeas.comp (measurable_pi_apply i))\n have hlev0 (i : Fin (n + 1)) (S : Fin (n + 1) → Ω) : 0 ≤ lev i S := by\n have hq : (common S).PosDef := by\n simpa [common] using ridge_posDef (fun k => ψ (S k)) hc\n exact hq.inv.posSemidef.dotProduct_mulVec_nonneg (ψ (S i))\n have hlevle (i : Fin (n + 1)) (S : Fin (n + 1) → Ω) :\n lev i S ≤ B^2 / c := by\n have hi := ridge_inverse_quadratic_le (fun k => ψ (S k)) hc (ψ (S i))\n have hb : ψ (S i) ⬝ᵥ ψ (S i) ≤ B^2 := hnorm (S i)\n rw [le_div_iff₀ hc]\n simpa [lev, common, mul_comm] using hi.trans hb\n have hlevint (i : Fin (n + 1)) : Integrable (lev i) μp := by\n apply Integrable.of_bound (hlevmeas i).aestronglyMeasurable (B^2 / c)\n filter_upwards with S\n rw [Real.norm_eq_abs, abs_of_nonneg (hlev0 i S)]\n exact hlevle i S\n let C : ℝ := σ^2 + t * wnorm\n have hC : 0 ≤ C := by\n dsimp [C]\n exact add_nonneg (sq_nonneg σ) (mul_nonneg ht.le hwnorm)\n have hvardet (S : Fin (n + 1) → Ω) :\n varTerm S ≤ C * lev (Fin.last n) S := by\n let u : Fin n → Fin d → ℝ := fun k => ψ (S k.castSucc)\n let test : Fin d → ℝ := ψ (S (Fin.last n))\n have hd := ridge_deterministic_prediction_bound u ht test wstar σ\n have hform : varTerm S =\n σ^2 * (∑ k, (test ⬝ᵥ (((∑ r, outer (u r)) + t •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec (u k))^2) +\n t^2 * (test ⬝ᵥ (((∑ r, outer (u r)) + t •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec wstar)^2 := by\n dsimp [varTerm, zdesign]\n rw [Fin.sum_univ_castSucc]\n simp [a, bias, coeff, H, U, V, u, test, t, hψfac]\n ring\n have hbase : varTerm S ≤\n C * (test ⬝ᵥ (((∑ r, outer (u r)) + t •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec test) := by\n rw [hform]\n simpa [C, wnorm] using hd\n have hcommonEq : common S =\n (∑ k, outer (u k)) + outer test +\n (t - B^2) • (1 : Matrix (Fin d) (Fin d) ℝ) := by\n dsimp [common]\n rw [Fin.sum_univ_castSucc]\n have hr := ridge_le_common_leverage u test (c := t) (B := B)\n hlamB (hnorm (S (Fin.last n)))\n have hr' :\n test ⬝ᵥ (((∑ r, outer (u r)) + t •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹).mulVec test ≤\n lev (Fin.last n) S := by\n rw [show lev (Fin.last n) S =\n test ⬝ᵥ (common S)⁻¹.mulVec test by rfl, hcommonEq]\n exact hr\n exact hbase.trans (mul_le_mul_of_nonneg_left hr' hC)\n have hsampleLoss : (∫ S, loss S ∂μp) ≤ ∫ S, varTerm S ��μp := by\n calc\n (∫ S, loss S ∂μp) = ∫ S, (noiseTerm S)^2 ∂μp := by\n apply integral_congr_ae\n filter_upwards with S\n exact hloss S\n _ ≤ ∫ S, varTerm S ∂μp := by\n simpa [μp, noiseTerm, varTerm, zdesign] using hsample\n have hvarLev : (∫ S, varTerm S ∂μp) ≤\n ∫ S, C * lev (Fin.last n) S ∂μp := by\n apply integral_mono_ae hvarint ((hlevint (Fin.last n)).const_mul C)\n filter_upwards with S\n exact hvardet S\n have haug : (∫ S, loss S ∂μp) ≤\n C * ∫ S, lev (Fin.last n) S ∂μp := by\n calc\n (∫ S, loss S ∂μp) ≤ ∫ S, varTerm S ∂μp := hsampleLoss\n _ ≤ ∫ S, C * lev (Fin.last n) S ∂μp := hvarLev\n _ = C * ∫ S, lev (Fin.last n) S ∂μp := by rw [integral_const_mul]\n have hnoiseAE : AEStronglyMeasurable noiseTerm μp := by\n have heval (j : Fin (n + 1)) :\n AEStronglyMeasurable (fun S => enoise j (S j)) μp := by\n have hi : Integrable (fun S => enoise j (S j)) μp := by\n simpa [μp] using\n (integrable_comp_eval (μ := fun _ : Fin (n + 1) => D)\n (henoiseint j))\n exact hi.aestronglyMeasurable\n have hsumAE : AEStronglyMeasurable\n (fun S => ∑ j, a (zdesign S) j * enoise j (S j)) μp := by\n have hs : AEStronglyMeasurable\n (∑ j, fun S => a (zdesign S) j * enoise j (S j)) μp := by\n apply Finset.aestronglyMeasurable_sum Finset.univ\n intro j hj\n exact (haeval j).aestronglyMeasurable.mul (heval j)\n exact hs.congr (ae_of_all _ fun S => by simp)\n exact (hsumAE.add hbiaseval.aestronglyMeasurable).congr\n (ae_of_all _ fun S => by rfl)\n have hlossAE : AEStronglyMeasurable loss μp := by\n exact (hnoiseAE.pow 2).congr (ae_of_all _ fun S => (hloss S).symm)\n let ν : Measure (Fin n → Ω) := Measure.pi fun _ : Fin n => D\n let e : (Fin (n + 1) → Ω) ≃ᵐ Ω × (Fin n → Ω) :=\n MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => Ω) (Fin.last n)\n have he : MeasurePreserving e μp (D.prod ν) := by\n simpa [e, μp, ν] using\n (measurePreserving_piFinSuccAbove\n (fun _ : Fin (n + 1) => D) (Fin.last n))\n let F : Ω × (Fin n → Ω) → ℝ := fun z =>\n (linPred (what z.2) ψ z.1 - linPred wstar ψ z.1)^2\n have hFeq : (fun S => F (e S)) = loss := by\n funext S\n have hinit : Fin.init S = (fun k => S k.castSucc) := by\n funext k\n rfl\n simp [F, e, loss, train, MeasurableEquiv.piFinSuccAbove_apply, hinit]\n have hFsymm : (fun z => loss (e.symm z)) = F := by\n funext z\n simp [F, e, loss, train, MeasurableEquiv.piFinSuccAbove_symm_apply]\n have hFae : AEStronglyMeasurable F (D.prod ν) := by\n rw [← hFsymm]\n exact hlossAE.comp_quasiMeasurePreserving he.symm.quasiMeasurePreserving\n have hFint : Integrable F (D.prod ν) := by\n apply (integrable_prod_iff' hFae).2\n constructor\n · filter_upwards with r\n simpa [F] using hExcInt r\n · have ho : Integrable\n (fun r => ∫ x, (linPred (what r) ψ x - linPred wstar ψ x)^2 ∂D) ν := by\n simpa [ν] using hOuterInt\n apply ho.congr\n filter_upwards with r\n apply integral_congr_ae\n filter_upwards with x\n rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)]\n have hriskEq :\n (∫ S, (∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D) ∂ν) =\n ∫ S, loss S ∂μp := by\n calc\n (∫ S, (∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D) ∂ν) =\n ∫ z, F z ∂(D.prod ν) := (integral_prod_symm F hFint).symm\n _ = ∫ S, F (e S) ∂μp := (he.integral_comp' F).symm\n _ = ∫ S, loss S ∂μp := by rw [hFeq]\n have hlevsymm (i : Fin (n + 1)) :\n (∫ S, lev i S ∂μp) = ∫ S, lev (Fin.last n) S ∂μp := by\n let p : Equiv.Perm (Fin (n + 1)) := Equiv.swap i (Fin.last n)\n let ep : (Fin (n + 1) → Ω) ≃ᵐ (Fin (n + 1) → Ω) :=\n MeasurableEquiv.piCongrLeft (fun _ : Fin (n + 1) => Ω) p\n have hep : MeasurePreserving ep μp μp := by\n simpa [ep, μp] using\n (measurePreserving_piCongrLeft (fun _ : Fin (n + 1) => D) p)\n have hcomp : (fun S => lev (Fin.last n) (ep S)) = lev i := by\n funext S\n have hlast : ep S (Fin.last n) = S i := by\n rw [← Equiv.swap_apply_left i (Fin.last n)]\n exact MeasurableEquiv.piCongrLeft_apply_apply\n (e := p) (x := S) (i := i) (β := fun _ => Ω)\n have hsum : (∑ j, outer (ψ (ep S j))) =\n ∑ j, outer (ψ (S j)) := by\n calc\n (∑ j, outer (ψ (ep S j))) =\n ∑ j, outer (ψ (ep S (p j))) :=\n (Equiv.sum_comp p (fun j => outer (ψ (ep S j)))).symm\n _ = ∑ j, outer (ψ (S j)) := by\n apply Finset.sum_congr rfl\n intro j hj\n rw [MeasurableEquiv.piCongrLeft_apply_apply\n (e := p) (x := S) (i := j) (β := fun _ => Ω)]\n have hcommon : common (ep S) = common S := by\n dsimp [common]\n rw [hsum]\n simp only [lev, hlast, hcommon]\n calc\n (∫ S, lev i S ∂μp) = ∫ S, lev (Fin.last n) (ep S) ∂μp := by\n rw [hcomp]\n _ = ∫ S, lev (Fin.last n) S ∂μp := hep.integral_comp' _\n have hsumlevint : Integrable (fun S => ∑ i, lev i S) μp :=\n integrable_finset_sum Finset.univ fun i _ => hlevint i\n have hsumEq : (∫ S, ∑ i, lev i S ∂μp) =\n ((n : ℝ) + 1) * ∫ S, lev (Fin.last n) S ∂μp := by\n rw [integral_finset_sum Finset.univ (fun i _ => hlevint i)]\n simp_rw [hlevsymm]\n simp\n let K : Matrix (Fin d) (Fin d) ℝ := featureCovariance D ψ\n have hK : K.PosSemidef := by\n exact featureCovariance_posSemidef D ψ hψ hψint\n let dbar : ℝ := Matrix.trace (((((n : ℝ) + 1) • K +\n c • (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹) * (((n : ℝ) + 1) • K))\n let deff : ℝ := Matrix.trace (((K + (c / ((n : ℝ) + 1)) •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹) * K)\n have hjensen : (∫ S, ∑ i, lev i S ∂μp) ≤ dbar := by\n have hj := empirical_effective_dimension_integral_le\n (N := n + 1) D ψ hψmeas hψ hψint B hB hc\n simpa [lev, common, μp, dbar, K, Nat.cast_add, Nat.cast_one] using hj\n have hq : (0 : ℝ) < (n : ℝ) + 1 := by positivity\n have hscale : dbar = deff := by\n simpa [dbar, deff] using\n (effective_dimension_scale K hK (q := (n : ℝ) + 1) (c := c) hq hc)\n have hfixed : (∫ S, lev (Fin.last n) S ∂μp) ≤\n deff / ((n : ℝ) + 1) := by\n rw [le_div_iff₀ hq]\n calc\n (∫ S, lev (Fin.last n) S ∂μp) * ((n : ℝ) + 1) =\n ((n : ℝ) + 1) * ∫ S, lev (Fin.last n) S ∂μp := mul_comm _ _\n _ = ∫ S, ∑ i, lev i S ∂μp := hsumEq.symm\n _ ≤ dbar := hjensen\n _ = deff := hscale\n have hsum0 : 0 ≤ ∫ S, ∑ i, lev i S ∂μp := by\n apply integral_nonneg_of_ae\n filter_upwards with S\n exact Finset.sum_nonneg fun i _ => hlev0 i S\n have hdeff : 0 ≤ deff := by\n rw [← hscale]\n exact hsum0.trans hjensen\n have hdenom : deff / ((n : ℝ) + 1) ≤ deff / (n : ℝ) := by\n exact div_le_div_of_nonneg_left hdeff hnR (by linarith)\n have hriskLoss :\n (∫ S, (∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D)\n ∂(Measure.pi fun _ : Fin n => D)) = ∫ S, loss S ∂μp := by\n simpa [ν] using hriskEq\n calc\n (∫ S, (∫ x, (linPred (what S) ψ x - linPred wstar ψ x)^2 ∂D)\n ∂(Measure.pi fun _ : Fin n => D)) = ∫ S, loss S ∂μp := hriskLoss\n _ ≤ C * ∫ S, lev (Fin.last n) S ∂μp := haug\n _ ≤ C * (deff / ((n : ℝ) + 1)) :=\n mul_le_mul_of_nonneg_left hfixed hC\n _ ≤ C * (deff / (n : ℝ)) := mul_le_mul_of_nonneg_left hdenom hC\n _ = (deff / (n : ℝ)) * C := mul_comm _ _\n _ = ((Matrix.trace ((featureCovariance D ψ +\n ((lam * n - B^2) / (n + 1)) •\n (1 : Matrix (Fin d) (Fin d) ℝ))⁻¹ * featureCovariance D ψ)) / n) *\n (σ^2 + lam * n * (∑ j, wstar j ^ 2)) := by\n simp [deff, K, c, t, C, wnorm, dotProduct, pow_two]\n\nend GraduateLevel\n"} +{"id": "ch5_theorem_5_14", "source": "Graduate-level", "targets": [{"label": "ch5_theorem_5_14", "decls": ["ch5_theorem_5_14"], "statement": "Consider any class \\(\\mathcal{F} = \\{f_1, \\ldots, f_d\\}\\), and assume that for a distribution \\(\\mathcal{D}\\), \\(\\sup_{f \\in \\mathcal{F}} \\|f\\|_{L_2(\\mathcal{D})} \\leq A\\). Then\n\\[\n\\ln N(\\epsilon,\\operatorname{CONV}(\\mathcal{F}),L_{2}(\\mathcal{D}))\\leq\\lceil A^{2}/\\epsilon^{2}\\rceil\\ln [e+e d\\epsilon^{2}/A^{2}].\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "For simplicity, we assume that \\(A = 1\\). Given any \\(f = \\sum_{j} \\alpha_{j} f_{j} \\in \\mathrm{CONV}(\\mathcal{F})\\) with \\(\\sum_{j} \\alpha_{j} = 1\\) and \\(\\alpha_{j} \\geq 0\\), we can regard \\(p_{\\alpha}\\) as a probability measure on \\(\\{1, \\ldots, d\\}\\) with \\(p_{\\alpha}(j) = \\alpha_{j}\\) (\\(j = 1, \\ldots, d\\)). Now, let \\(j_{1}, \\ldots, j_{k}\\) be \\(k\\) iid samples from \\(p_{\\alpha}\\), then \\(f = \\sum_{j} \\alpha_{j} f_{j} = \\mathbb{E}_{j_{s}} f_{j_{s}}\\).\n\\[\n\\begin{array}{l}\\mathbb{E}_{j_{1},\\dots,j_{k}}\\left\\|\\frac{1}{k}\\sum_{s=1}^{k}f_{j_{s}}-f\\right\\|_{L_{2}(\\mathcal{D})}^{2}=\\operatorname{Var}_{j_{1},\\dots,j_{k}}\\left(\\left\\|\\frac{1}{k}\\sum_{s=1}^{k}f_{j_{s}}\\right\\|_{L_{2}(\\mathcal{D})}\\right)\\\\ =k^{-2}\\sum_{s=1}^{k}\\operatorname{Var}_{j_{s}}\\left(\\left\\|f_{j_{s}}\\right\\|_{L_{2}(\\mathcal{D})}\\right)\\\\ \\leq k^{-2}\\sum_{s=1}^{k}\\mathbb{E}_{j_{s}}\\left(\\|f_{j_{s}}\\|_{L_{2}(\\mathcal{D})}^{2}\\right)\\leq 1/k.\\\\ \\end{array}\n\\]\nIt means that there exists \\(j_1, \\ldots, j_s\\) such that\n\\[\n\\left\\|\\frac{1}{k}\\sum_{s=1}^{k}f_{j_{s}}-f\\right\\|_{L_{2}(\\mathcal{D})}\\leq 1/\\sqrt{k}.\n\\]\nNow, consider\n\\[\nQ_{k}=\\left\\{\\frac{1}{k}\\sum_{j=1}^{d}n_{j}f_{j}:\\sum_{j=1}^{d}n_{j}=k;n_{j}\\geq 0\\right\\}.\n\\]\nSince \\( k^{-1} \\sum_{s=1}^{k} f_{j_s} \\in Q_k \\), we know that \\( Q_k \\) is an \\( 1/\\sqrt{k} \\) cover of \\( \\mathrm{CONV}(\\mathcal{F}) \\). Take \\( k = \\lceil 1/\\epsilon^2 \\rceil \\), we know that \\( Q_k \\) is an \\( \\epsilon \\) cover. Moreover, since\n\\[\n|Q_{k}|\\leq\\left(\\begin{array}{c}d+k-1\\\\ k\\end{array}\\right)\\leq e^{k}(1+d/k)^{k},\n\\]\nwe obtain the bound in the theorem.", "context": [{"id": "ch5:definition:5_12", "name": "definition 5.12", "statement": "The convex hull of a function class \\(\\mathcal{F} = \\{f(\\theta, x) : \\theta \\in \\Theta\\}\\) is defined as\n\\[\n\\operatorname{CONV}(\\mathcal{F})=\\left\\{\\sum_{j=1}^{m}w_{j}f\\left(\\theta_{j},x\\right):m>0,\\|w\\|_{1}=1,w_{j}\\geq 0,\\theta_{j}\\in\\Theta\\right\\}.\n\\]\nWe also include the closure of the finite sum functions above with respect to an appropriate topology in the convex hull."}, {"id": "ch4:definition:4_1", "name": "definition 4.1", "statement": "Let \\((\\mathcal{V},d)\\) be a pseudometric space with metric \\(d(\\cdot,\\cdot)\\). A finite\nset \\(\\mathcal{G}(\\epsilon) \\subset \\mathcal{V}\\) is an \\(\\epsilon\\)-cover (or \\(\\epsilon\\)-net) of \\(\\mathcal{G} \\subset \\mathcal{V}\\) if, for all \\(\\phi \\in \\mathcal{G}\\), there exists \\(\\phi' \\in \\mathcal{G}(\\epsilon)\\) so that \\(d(\\phi', \\phi) \\leq \\epsilon\\). The \\(\\epsilon\\)-covering number of \\(\\mathcal{G}\\) with metric \\(d\\) is the smallest cardinality \\(N(\\epsilon, \\mathcal{G}, d)\\) of such \\(\\mathcal{G}(\\epsilon)\\). The number \\(\\ln N(\\epsilon, \\mathcal{G}, d)\\) is called the \\(\\epsilon\\)-entropy.\nFor a function class \\(\\mathcal{G}\\) with seminorm \\(L_{p}(\\mathcal{D})\\) in (3.19), we denote the corresponding \\(L_{p}(\\mathcal{D})\\)-covering number as \\(N(\\epsilon, \\mathcal{G}, L_{p}(\\mathcal{D}))\\). When \\(1 \\leq p \\leq q\\), we have\n\\[\nN(\\epsilon,\\mathcal{G},L_{p}(\\mathcal{D}))\\leq N(\\epsilon,\\mathcal{G},L_{q}(\\mathcal{D})).\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory Set\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\ndef IsENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) :\n WithTop ℕ :=\n sInf {n | ∃ t, IsENet t eps s ∧ ↑t.card = n}\n\ntheorem ch5_theorem_5_14\n {α : Type*} [MeasurableSpace α] (D : Measure α) [IsProbabilityMeasure D]\n [Fact (1 ≤ (2 : ℝ≥0∞))]\n {d : ℕ} (hd : 0 < d) (f : Fin d → (α → ℝ))\n (hf : ∀ j, MemLp (f j) 2 D)\n (ε A : ℝ) (hε : 0 < ε) (hA : 0 < A)\n (hbound : ∀ j, eLpNorm (f j) 2 D ≤ ENNReal.ofReal A) :\n let S : Set (Lp ℝ 2 D) := Set.range (fun j : Fin d => (hf j).toLp (f j))\n coveringNumber ε (convexHull ℝ S) ≠ ⊤ ∧\n Real.log (ENNReal.toReal (ENat.toENNReal (coveringNumber ε (convexHull ℝ S))))\n ≤ (⌈A ^ 2 / ε ^ 2⌉₊ : ℝ)\n * Real.log (Real.exp 1 + Real.exp 1 * (d : ℝ) * ε ^ 2 / A ^ 2) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Set\nopen scoped ENNReal\n\nnamespace GraduateLevel\n\ndef IsENet {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n s ⊆ ⋃ x ∈ t, Metric.closedBall x eps\n\nnoncomputable def coveringNumber {A : Type*} [PseudoMetricSpace A] (eps : ℝ) (s : Set A) :\n WithTop ℕ :=\n sInf {n | ∃ t, IsENet t eps s ∧ ↑t.card = n}\n\nopen Finset in\nprivate lemma step_lemma {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] {d : ℕ}\n (g : Fin d → H) (A : ℝ) (hg : ∀ j, ‖g j‖ ≤ A)\n (α : Fin d → ℝ) (hα : ∀ j, 0 ≤ α j) (hs : ∑ j, α j = 1) (F : H)\n (hF : ∑ i, α i • g i = F) (v : H) :\n ∃ j, ‖v + g j - F‖ ^ 2 ≤ ‖v‖ ^ 2 + A ^ 2 := by\n classical\n have hexp : ∀ j : Fin d, α j * ‖v + g j - F‖ ^ 2\n = α j * ‖v‖ ^ 2 + (2 * (α j * inner ℝ v (g j)) +\n (-(2 * (α j * inner ℝ v F)) + (α j * ‖g j‖ ^ 2 +\n (-(2 * (α j * inner ℝ (g j) F)) + α j * ‖F‖ ^ 2)))) := by\n intro j\n have h1 : v + g j - F = v + (g j - F) := by abel\n rw [h1, norm_add_sq_real, norm_sub_sq_real, inner_sub_right]\n ring\n have hA1 : ∑ j, α j * inner ℝ v (g j) = inner ℝ v F := by\n rw [← hF, inner_sum]\n exact Finset.sum_congr rfl fun j _ => by rw [real_inner_smul_right]\n have hA2 : ∑ j, α j * inner ℝ (g j) F = ‖F‖ ^ 2 := by\n have h : ∑ j, α j * inner ℝ (g j) F = inner ℝ (∑ j, α j • g j) F := by\n rw [sum_inner]\n exact Finset.sum_congr rfl fun j _ => by rw [real_inner_smul_left]\n rw [h, hF, real_inner_self_eq_norm_sq]\n have hA3 : ∑ j, α j * ‖g j‖ ^ 2 ≤ A ^ 2 := by\n have : ∑ j, α j * ‖g j‖ ^ 2 ≤ ∑ j : Fin d, α j * A ^ 2 := by\n refine Finset.sum_le_sum fun j _ => ?_\n refine mul_le_mul_of_nonneg_left ?_ (hα j)\n exact pow_le_pow_left₀ (norm_nonneg _) (hg j) 2\n rw [← Finset.sum_mul, hs, one_mul] at this\n exact this\n have key : ��� j, α j * ‖v + g j - F‖ ^ 2 ≤ ‖v‖ ^ 2 + A ^ 2 := by\n rw [Finset.sum_congr rfl (fun j _ => hexp j)]\n simp only [Finset.sum_add_distrib, Finset.sum_neg_distrib, ← Finset.mul_sum,\n ← Finset.sum_mul]\n rw [hs, hA1, hA2]\n nlinarith [norm_nonneg F, hA3, sq_nonneg ‖F‖]\n by_contra hcon\n push_neg at hcon\n obtain ⟨j0, hj0mem, hj0⟩ : ∃ j0 ∈ Finset.univ, (0:ℝ) < α j0 := by\n by_contra h\n push_neg at h\n have hz : ∑ j, α j = 0 := Finset.sum_eq_zero fun j hj => le_antisymm (h j hj) (hα j)\n rw [hs] at hz; norm_num at hz\n have hsum_lt : ∑ j : Fin d, α j * (‖v‖ ^ 2 + A ^ 2) < ∑ j, α j * ‖v + g j - F‖ ^ 2 := by\n refine Finset.sum_lt_sum (fun i _ => mul_le_mul_of_nonneg_left (hcon i).le (hα i)) ?_\n exact ⟨j0, hj0mem, mul_lt_mul_of_pos_left (hcon j0) hj0⟩\n rw [← Finset.sum_mul, hs, one_mul] at hsum_lt\n linarith\n\nopen Finset in\nprivate lemma exists_ms {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] {d : ℕ}\n (g : Fin d → H) (A : ℝ) (hg : ∀ j, ‖g j‖ ≤ A)\n (α : Fin d → ℝ) (hα : ∀ j, 0 ≤ α j) (hs : ∑ j, α j = 1) (k : ℕ) :\n ∃ m : Multiset (Fin d), Multiset.card m = k ∧\n ‖(m.map g).sum - (k : ℝ) • (∑ i, α i • g i)‖ ^ 2 ≤ k * A ^ 2 := by\n induction k with\n | zero => exact ⟨0, by simp, by simp⟩\n | succ k ih =>\n obtain ⟨m, hm, hb⟩ := ih\n obtain ⟨j, hj⟩ := step_lemma g A hg α hα hs (∑ i, α i • g i) rfl\n ((m.map g).sum - (k : ℝ) • (∑ i, α i • g i))\n refine ⟨j ::ₘ m, by simp [hm], ?_⟩\n have heq : (((j ::ₘ m).map g).sum - ((k + 1 : ℕ) : ℝ) • (∑ i, α i • g i))\n = ((m.map g).sum - (k : ℝ) • (∑ i, α i • g i)) + g j - (∑ i, α i • g i) := by\n rw [Multiset.map_cons, Multiset.sum_cons]\n push_cast\n rw [add_smul, one_smul]\n abel\n rw [heq]\n push_cast\n linarith\n\nprivate lemma choose_bound (d k : ℕ) (hk : 0 < k) :\n (((d + k - 1).choose k : ℕ) : ℝ) ≤ (Real.exp 1 * (1 + (d : ℝ) / k)) ^ k := by\n have hkR : (0:ℝ) < k := by exact_mod_cast hk\n have h1 : (((d + k - 1).choose k : ℕ) : ℝ) ≤ ((d + k - 1 : ℕ) : ℝ) ^ k / (k.factorial : ℝ) :=\n Nat.choose_le_pow_div k (d + k - 1)\n have h2 : ((d + k - 1 : ℕ) : ℝ) ≤ (d : ℝ) + k := by\n have : (d + k - 1 : ℕ) ≤ d + k := Nat.sub_le _ _\n calc ((d + k - 1 : ℕ) : ℝ) ≤ ((d + k : ℕ) : ℝ) := by exact_mod_cast this\n _ = (d : ℝ) + k := by push_cast; ring\n have hfac : ((k : ℝ) ^ k) / (k.factorial : ℝ) ≤ Real.exp k := by\n have hpos : (0:ℝ) ≤ (k : ℝ) := le_of_lt hkR\n have := Real.sum_le_exp_of_nonneg hpos (k + 1)\n have hmem : (k : ℝ) ^ k / (k.factorial : ℝ)\n ≤ ∑ i ∈ Finset.range (k + 1), (k : ℝ) ^ i / (i.factorial : ℝ) := by\n refine Finset.single_le_sum (f := fun i => (k : ℝ) ^ i / (i.factorial : ℝ))\n (fun i _ => by positivity) (Finset.self_mem_range_succ k)\n linarith\n have hfacpos : (0:ℝ) < (k.factorial : ℝ) := by\n exact_mod_cast Nat.factorial_pos k\n have hsplit : ((d : ℝ) + k) ^ k = (((d : ℝ) + k) / k) ^ k * (k : ℝ) ^ k := by\n rw [div_pow]\n field_simp\n calc (((d + k - 1).choose k : ℕ) : ℝ) ≤ ((d + k - 1 : ℕ) : ℝ) ^ k / (k.factorial : ℝ) := h1\n _ ≤ ((d : ℝ) + k) ^ k / (k.factorial : ℝ) := by\n have := pow_le_pow_left₀ (by positivity : (0:ℝ) ≤ ((d + k - 1 : ℕ) : ℝ)) h2 k\n gcongr\n _ = (((d : ℝ) + k) / k) ^ k * ((k : ℝ) ^ k / (k.factorial : ℝ)) := by\n rw [hsplit]; ring\n _ ≤ (((d : ℝ) + k) / k) ^ k * Real.exp k := by\n apply mul_le_mul_of_nonneg_left hfac (by positivity)\n _ = (Real.exp 1 * (1 + (d : ℝ) / k)) ^ k := by\n rw [mul_pow, ← Real.exp_nat_mul, mul_one]\n rw [show ((d : ℝ) + k) / k = 1 + (d : ℝ) / k by field_simp; ring]\n ring\n\ntheorem ch5_theorem_5_14\n {α : Type*} [MeasurableSpace α] (D : Measure α) [IsProbabilityMeasure D]\n [Fact (1 ≤ (2 : ℝ≥0∞))]\n {d : ℕ} (hd : 0 < d) (f : Fin d → (α → ℝ))\n (hf : ∀ j, MemLp (f j) 2 D)\n (ε A : ℝ) (hε : 0 < ε) (hA : 0 < A)\n (hbound : ∀ j, eLpNorm (f j) 2 D ≤ ENNReal.ofReal A) :\n let S : Set (Lp ℝ 2 D) := Set.range (fun j : Fin d => (hf j).toLp (f j))\n coveringNumber ε (convexHull ℝ S) ≠ ⊤ ∧\n Real.log (ENNReal.toReal (ENat.toENNReal (coveringNumber ε (convexHull ℝ S))))\n ≤ (⌈A ^ 2 / ε ^ 2⌉₊ : ℝ)\n * Real.log (Real.exp 1 + Real.exp 1 * (d : ℝ) * ε ^ 2 / A ^ 2) := by\n classical\n intro S\n set g : Fin d → Lp ℝ 2 D := fun j => (hf j).toLp (f j) with hg_def\n have hgnorm : ∀ j, ‖g j‖ ≤ A := by\n intro j\n have h1 : ‖g j‖ = (eLpNorm (f j) 2 D).toReal := by\n rw [hg_def, Lp.norm_def]\n congr 1\n exact eLpNorm_congr_ae ((hf j).coeFn_toLp)\n rw [h1]\n exact ENNReal.toReal_le_of_le_ofReal hA.le (hbound j)\n set k : ℕ := ⌈A ^ 2 / ε ^ 2⌉₊ with hk_def\n have hkpos : 0 < k := Nat.ceil_pos.mpr (by positivity)\n have hkR : (0:ℝ) < k := by exact_mod_cast hkpos\n have hkge : A ^ 2 / ε ^ 2 ≤ (k : ℝ) := Nat.le_ceil _\n -- the net\n set Q : Finset (Lp ℝ 2 D) :=\n Finset.image (fun m : Sym (Fin d) k => (k : ℝ)⁻¹ • (((m : Multiset (Fin d)).map g).sum))\n Finset.univ with hQ_def\n have hnet : IsENet Q ε (convexHull ℝ S) := by\n intro x hx\n have hxr : x ∈ convexHull ℝ (Set.range g) := hx\n rw [convexHull_range_eq_exists_affineCombination] at hxr\n obtain ⟨s, w, hw0, hw1, hwx⟩ := hxr\n set α : Fin d → ℝ := fun i => if i ∈ s then w i else 0 with hα_def\n have hα0 : ∀ i, 0 ≤ α i := by\n intro i\n by_cases h : i ∈ s\n · simp only [hα_def, if_pos h]; exact hw0 i h\n · simp only [hα_def, if_neg h]\n exact le_refl 0\n have hαsum : ∑ i, α i = 1 := by\n rw [← hw1]\n rw [← Finset.sum_subset (Finset.subset_univ s) (fun i _ hi => by simp [hα_def, hi])]\n exact Finset.sum_congr rfl fun i hi => by simp [hα_def, hi]\n have hαx : ∑ i, α i • g i = x := by\n rw [Finset.affineCombination_eq_linear_combination s g w hw1] at hwx\n rw [← hwx]\n rw [← Finset.sum_subset (Finset.subset_univ s) (fun i _ hi => by simp [hα_def, hi])]\n exact Finset.sum_congr rfl fun i hi => by simp [hα_def, hi]\n obtain ⟨m, hmcard, hmb⟩ := exists_ms g A hgnorm α hα0 hαsum k\n rw [hαx] at hmb\n refine Set.mem_iUnion.2 ⟨(k : ℝ)⁻¹ • ((m.map g).sum), ?_⟩\n refine Set.mem_iUnion.2 ⟨?_, ?_⟩\n · rw [hQ_def]\n refine Finset.mem_image.2 ⟨⟨m, hmcard⟩, Finset.mem_univ _, rfl⟩\n · rw [Metric.mem_closedBall, dist_eq_norm]\n have hdec : x - (k : ℝ)⁻¹ • ((m.map g).sum)\n = -((k:ℝ)⁻¹ • ((m.map g).sum - (k : ℝ) • x)) := by\n rw [smul_sub, smul_smul]\n rw [inv_mul_cancel₀ (ne_of_gt hkR), one_smul]\n abel\n rw [hdec, norm_neg, norm_smul]\n have h2 : ‖(m.map g).sum - (k : ℝ) • x‖ ^ 2 ≤ (k : ℝ) * A ^ 2 := hmb\n have hnn : (0:ℝ) ≤ ‖(m.map g).sum - (k : ℝ) • x‖ := norm_nonneg _\n have hAk : A ^ 2 ≤ (k : ℝ) * ε ^ 2 := by\n rw [div_le_iff₀ (by positivity)] at hkge\n linarith\n have : ‖(k : ℝ)⁻¹‖ * ‖(m.map g).sum - (k : ℝ) • x‖\n = (k:ℝ)⁻¹ * ‖(m.map g).sum - (k : ℝ) • x‖ := by\n rw [Real.norm_eq_abs, abs_of_nonneg (by positivity)]\n rw [this]\n rw [inv_mul_le_iff₀ hkR]\n have hsq : ‖(m.map g).sum - (k : ℝ) • x‖ ^ 2 ≤ ((k:ℝ) * ε) ^ 2 := by\n nlinarith\n exact le_of_pow_le_pow_left₀ (by norm_num) (by positivity) hsq\n -- covering number bounded by card Q\n have hmem : ((Q.card : ℕ) : WithTop ℕ) ∈ {n | ∃ t, IsENet t ε (convexHull ℝ S) ∧ ↑t.card = n} :=\n ⟨Q, hnet, rfl⟩\n have hle : coveringNumber ε (convexHull ℝ S) ≤ ((Q.card : ℕ) : WithTop ℕ) := sInf_le hmem\n have hne : coveringNumber ε (convexHull ℝ S) ≠ ⊤ := by\n intro h\n rw [h] at hle\n exact (WithTop.coe_ne_top (a := Q.card)) (top_le_iff.mp hle)\n refine ⟨hne, ?_⟩\n -- numeric part\n have hcard : (Q.card : ℝ) ≤ (((d + k - 1).choose k : ℕ) : ℝ) := by\n have h1 : Q.card ≤ Fintype.card (Sym (Fin d) k) := by\n rw [hQ_def]\n calc (Finset.image\n (fun m : Sym (Fin d) k => (k : ℝ)⁻¹ • (((m : Multiset (Fin d)).map g).sum))\n Finset.univ).card ≤ (Finset.univ : Finset (Sym (Fin d) k)).card :=\n Finset.card_image_le\n _ = Fintype.card (Sym (Fin d) k) := rfl\n have h2 : Fintype.card (Sym (Fin d) k) = (d + k - 1).choose k := by\n rw [Sym.card_sym_eq_choose, Fintype.card_fin]\n rw [h2] at h1\n exact_mod_cast h1\n have hRlog : Real.log (ENNReal.toReal (ENat.toENNReal (coveringNumber ε (convexHull ℝ S))))\n ≤ Real.log (Q.card : ℝ) := by\n have hmono : ENat.toENNReal (coveringNumber ε (convexHull ℝ S)) ≤ (Q.card : ℝ≥0∞) := by\n have h0 : ENat.toENNReal (coveringNumber ε (convexHull ℝ S))\n ≤ ENat.toENNReal ((Q.card : ℕ) : ℕ∞) := ENat.toENNReal_le.2 hle\n simpa using h0\n have htr : ENNReal.toReal (ENat.toENNReal (coveringNumber ε (convexHull ℝ S)))\n ≤ (Q.card : ℝ) := by\n have := ENNReal.toReal_mono (by simp) hmono\n simpa using this\n rcases le_or_lt (ENNReal.toReal (ENat.toENNReal (coveringNumber ε (convexHull ℝ S)))) 0 with h | h\n · rcases le_or_lt (Q.card : ℝ) 0 with h' | h'\n · have : (Q.card : ℝ) = 0 := le_antisymm h' (by positivity)\n rw [this]\n have h0 : ENNReal.toReal (ENat.toENNReal (coveringNumber ε (convexHull ℝ S))) = 0 :=\n le_antisymm h ENNReal.toReal_nonneg\n rw [h0]\n · have h0 : ENNReal.toReal (ENat.toENNReal (coveringNumber ε (convexHull ℝ S))) = 0 :=\n le_antisymm h ENNReal.toReal_nonneg\n rw [h0, Real.log_zero]\n exact Real.log_nonneg (by\n have : (1:ℝ) ≤ (Q.card : ℝ) := by\n have : 1 ≤ Q.card := by\n by_contra hc\n push_neg at hc\n interval_cases h'' : Q.card\n · simp at h'\n exact_mod_cast this\n exact this)\n · exact Real.log_le_log h htr\n refine hRlog.trans ?_\n have hlog1 : Real.log (Q.card : ℝ) ≤ Real.log ((Real.exp 1 * (1 + (d : ℝ) / k)) ^ k) := by\n rcases le_or_lt (Q.card : ℝ) 0 with h' | h'\n · have : (Q.card : ℝ) = 0 := le_antisymm h' (by positivity)\n rw [this, Real.log_zero]\n apply Real.log_nonneg\n have : (1:ℝ) ≤ Real.exp 1 * (1 + (d : ℝ) / k) := by\n have h1 : (1:ℝ) ≤ Real.exp 1 := by\n have := Real.add_one_le_exp (1:ℝ); linarith\n have h2 : (1:ℝ) ≤ 1 + (d : ℝ) / k := by\n have : (0:ℝ) ≤ (d : ℝ) / k := by positivity\n linarith\n nlinarith\n exact one_le_pow₀ this\n · exact Real.log_le_log h' (hcard.trans (choose_bound d k hkpos))\n refine hlog1.trans ?_\n have hepos : (0:ℝ) < Real.exp 1 * (1 + (d : ℝ) / k) := by positivity\n rw [Real.log_pow]\n have hstep : Real.log (Real.exp 1 * (1 + (d : ℝ) / k))\n ≤ Real.log (Real.exp 1 + Real.exp 1 * (d : ℝ) * ε ^ 2 / A ^ 2) := by\n apply Real.log_le_log hepos\n have hkinv : (1:ℝ) / k ≤ ε ^ 2 / A ^ 2 := by\n rw [div_le_div_iff₀ hkR (by positivity)]\n rw [div_le_iff₀ (by positivity)] at hkge\n linarith\n have : Real.exp 1 * (1 + (d : ℝ) / k) = Real.exp 1 + Real.exp 1 * (d:ℝ) * (1 / k) := by\n field_simp\n rw [this]\n have hd0 : (0:ℝ) ≤ Real.exp 1 * (d:ℝ) := by positivity\n have := mul_le_mul_of_nonneg_left hkinv hd0\n have heq2 : Real.exp 1 * (d:ℝ) * (ε ^ 2 / A ^ 2) = Real.exp 1 * (d:ℝ) * ε ^ 2 / A ^ 2 := by\n ring\n nlinarith\n have hknn : (0:ℝ) ≤ (k:ℝ) := le_of_lt hkR\n exact mul_le_mul_of_nonneg_left hstep hknn\n\nend GraduateLevel\n"} +{"id": "ch6_corollary_6_34", "source": "Graduate-level", "targets": [{"label": "corollary_6_34", "decls": ["corollary_6_34"], "statement": "Consider a real valued function class \\(\\mathcal{F} = \\{f(z):\\mathcal{Z}\\to \\mathbb{R}\\}\\). Let \\(\\mathcal{D}\\) be a distribution on \\(\\mathcal{Z}\\). Assume that there exists \\(M,\\sigma >0\\) so that \\(\\forall f\\in \\mathcal{F}\\),\n\\(\\sigma^2 \\geq \\operatorname{Var}_{Z \\sim \\mathcal{D}}[f(Z)]\\), and \\(\\sup_{z' \\in \\mathcal{Z}} [\\mathbb{E}_{Z \\sim \\mathcal{D}} f(Z) - f(z')] \\leq M\\). Let \\(\\mathcal{S}_n = \\{Z_1, \\ldots, Z_n\\}\\) be \\(n\\) independent random variables from \\(\\mathcal{D}\\). Then with probability at least \\(1 - \\delta\\) over \\(\\mathcal{S}_n\\), for all \\(f \\in \\mathcal{F}\\),\n\\[\n\\begin{array}{l}\\mathbb{E}_{Z\\sim\\mathcal{D}}f(Z)-\\frac{1}{n}\\sum_{i=1}^{n}f\\left(Z_{i}\\right)\\\\ \\leq\\epsilon_{n}(\\mathcal{F},\\mathcal{D})+\\sqrt{\\frac{(4 M\\epsilon_{n}(\\mathcal{F},\\mathcal{D})+2\\sigma^{2})\\ln(1/\\delta)}{n}}+\\frac{M\\ln(1/\\delta)}{3 n}\\\\ \\leq 2\\epsilon_{n}(\\mathcal{F},\\mathcal{D})+\\sqrt{\\frac{2\\sigma^{2}\\ln(1/\\delta)}{n}}+\\frac{4 M\\ln(1/\\delta)}{3 n},\\\\ \\end{array}\n\\]\nwhere \\(\\epsilon_{n}(\\mathcal{F},\\mathcal{D})\\) is Definition 6.1.", "topic_domain": "Probability & Concentration", "topic_subtopic": "Functional & Supremum Concentration"}], "nl_proof": "Let\n\\[\n\\zeta=\\sup_{f\\in\\mathcal{F}}\\left[n\\mathbb{E}_{Z\\sim\\mathcal{D}}f(Z)-\\sum_{i=1}^{n}f(Z_{n})\\right],\n\\]\nand\n\\[\n\\zeta_{k}=\\sup_{f\\in\\mathcal{F}}\\left[(n-1)\\mathbb{E}_{Z\\sim\\mathcal{D}}f(Z)-\\sum_{i\\neq k}f(Z_{i})\\right].\n\\]\nAssume that \\(\\zeta_{k}\\) is achieved at \\(f_{k}\\), and \\(\\zeta\\) achieved at \\(f_{0}\\). Then\n\\[\n\\sum_{k=1}^{n}\\left[\\zeta-\\zeta_{k}\\right]\\leq\\sum_{k=1}^{n}\\left[\\mathbb{E}_{Z\\sim\\mathcal{D}}f_{0}(Z)-f_{0}\\left(Z_{k}\\right)\\right]=\\zeta .\n\\]\nLet\n\\[\n\\zeta_{k}^{\\prime}=\\left[n\\mathbb{E}_{Z\\sim\\mathcal{D}}f_{k}(Z)-\\sum_{i=1}^{n}f_{k}(Z_{i})\\right]-\\zeta_{k},\n\\]\nthen\n\\[\n\\zeta_{k}^{\\prime}\\leq\\zeta-\\zeta_{k}\\leq\\left[\\mathbb{E}_{Z}f_{0}(Z)-f_{0}(Z_{k})\\right]\\leq M.\n\\]\nMoreover, since \\(Z_{k}\\) is independent of \\(f_{k}\\), we have\n\\[\n\\mathbb{E}_{Z_{k}}\\zeta_{k}^{\\prime}=\\mathbb{E}_{Z_{k}}\\left[\\mathbb{E}_{Z}f_{k}(Z)-f_{k}\\left(Z_{k}\\right)\\right]=0\n\\]\n\\[\n\\mathbb{E}_{Z_{k}}\\left(\\zeta_{k}^{\\prime}\\right)^{2}=\\mathbb{E}_{Z_{k}}\\left[\\mathbb{E}_{Z}f_{k}(Z)-f_{k}(Z_{k})\\right]^{2}\\leq\\sigma^{2}.\n\\]\nBy taking \\( u = 1 \\) in Theorem 6.33, we obtain the first desired bound. The second bound is a consequence of\n\\[\n\\begin{array}{l}\\sqrt{\\left(4 M\\epsilon_{n}(\\mathcal{F},\\mathcal{D})+2\\sigma^{2}\\right)\\ln(1/\\delta)/n}\\\\ \\leq\\sqrt{4 M\\epsilon_{n}(\\mathcal{F},\\mathcal{D})\\ln(1/\\delta)/n}+\\sqrt{2\\sigma^{2}\\ln(1/\\delta)/n}\\\\ \\leq\\epsilon_{n}(\\mathcal{F},\\mathcal{D})+M\\ln(1/\\delta)/n+\\sqrt{2\\sigma^{2}\\ln(1/\\delta)/n}.\\\\ \\end{array}\n\\]\nThe first inequality used \\(\\sqrt{a + b} \\leq \\sqrt{a} + \\sqrt{b}\\), and the second inequality used \\(\\sqrt{4ab} \\leq a + b\\).", "context": [{"id": "ch6:definition:6_1", "name": "definition 6.1", "statement": "Given an empirical process \\(\\{\\phi(w, S_n) : w \\in \\Omega\\}\\), with \\(S_n \\sim \\mathcal{D}^n\\). Define the expected supremum of this empirical process as\n\\[\n\\epsilon_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}}\\sup_{w\\in\\Omega}\\left[\\phi(w,\\mathcal{D})-\\phi(w,\\mathcal{S}_{n})\\right],\n\\]\nwhich will be referred to as the uniform convergence complexity of the function class \\(\\mathcal{G}\\).\nThe smaller this quantity is, the closer the gap between the training error and the test error is, which implies that we have less overfitting. In Chapter 3, we\nobtained large probability uniform convergence results for empirical processes, and then derived oracle inequalities in large probabilities. In the following, we show that if average convergence can be obtained, then we can derive oracle inequalities in expectation directly."}, {"id": "ch6:theorem:6_33", "name": "Bousquet, 2002", "statement": "Consider iid random variables \\((Z_{1},\\ldots,Z_{n})\\sim\\) \\(\\mathcal{D}^n\\) . Let \\(\\zeta\\) be a real-valued function of \\((Z_{1},\\dots,Z_{n})\\) . Moreover, for each \\(k\\in [n]\\) let \\(\\zeta_{k}\\) be a real-valued function of \\((Z_{1},\\ldots,Z_{k-1},Z_{k+1},\\ldots,Z_{n})\\) so that\n\\[\n\\sum_{k=1}^{n}\\left[\\zeta-\\zeta_{k}\\right]\\leq\\zeta .\n\\]\nAssume that for each \\(k\\), there exists a function \\(\\zeta_k^\\prime\\) of \\((Z_{1},\\ldots,Z_{n})\\) such that\n\\[\n\\zeta_{k}^{\\prime}\\leq\\zeta-\\zeta_{k}\\leq M,\\quad\\mathbb{E}_{Z_{k}}\\zeta_{k}^{\\prime}\\geq 0,\\quad\\zeta_{k}^{\\prime}\\leq u M.\n\\]\nWe have for all \\(t \\geq 0\\):\n\\[\n\\operatorname*{Pr}\\left[\\zeta\\geq\\mathbb{E}\\zeta+\\sqrt{2((1+u)M\\mathbb{E}\\zeta+n\\sigma^{2})t}+\\frac{tM}{3}\\right]\\leq e^{-t},\n\\]\nwhere \\(\\sigma^2\\geq n^{-1}\\sum_{k = 1}^{n}\\mathbb{E}_{Z_k}(\\zeta_k')^2\\)"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def epsN {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) : ℝ :=\n ∫ ω, (⨆ f : F, ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)))\n ∂(Measure.pi (fun _ : Fin n => D))\n\ntheorem corollary_6_34\n {𝒵 : Type*} [MeasurableSpace 𝒵]\n (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (hF : F.Nonempty)\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (hMemLp : ∀ f ∈ F, MemLp f 2 D)\n (hInt : Integrable (fun ω => ⨆ f : F,\n ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)))\n (Measure.pi (fun _ : Fin n => D)))\n (M σ : ℝ) (hM : 0 < M) (hσ : 0 < σ)\n (hVar : ∀ f ∈ F, ProbabilityTheory.variance f D ≤ σ ^ 2)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (hBousquet : ∀ (ζ : (Fin n → 𝒵) → ℝ) (ζk ζ' : Fin n → (Fin n → 𝒵) → ℝ)\n (u Mb sb t : ℝ), 0 ≤ u → 0 ≤ t → 0 < Mb →\n (∀ k ω z, ζk k (Function.update ω k z) = ζk k ω) →\n (∀ ω, ∑ k, (ζ ω - ζk k ω) ≤ ζ ω) →\n (∀ k ω, ζ' k ω ≤ ζ ω - ζk k ω) →\n (∀ k ω, ζ ω - ζk k ω ≤ Mb) →\n (∀ k ω, ζ' k ω ≤ u * Mb) →\n Integrable ζ (Measure.pi (fun _ : Fin n => D)) →\n (∀ k ω, Integrable (fun z => ζ' k (Function.update ω k z)) D) →\n (∀ k ω, Integrable (fun z => (ζ' k (Function.update ω k z)) ^ 2) D) →\n (∀ k ω, 0 ≤ ∫ z, ζ' k (Function.update ω k z) ∂D) →\n (∀ k ω, ∫ z, (ζ' k (Function.update ω k z)) ^ 2 ∂D ≤ sb ^ 2) →\n (Measure.pi (fun _ : Fin n => D))\n {ω : Fin n → 𝒵 |\n (∫ x, ζ x ∂(Measure.pi (fun _ : Fin n => D)))\n + Real.sqrt (2 * ((1 + u) * Mb\n * (∫ x, ζ x ∂(Measure.pi (fun _ : Fin n => D))) + (n : ℝ) * sb ^ 2) * t)\n + t * Mb / 3 ≤ ζ ω}\n ≤ ENNReal.ofReal (Real.exp (-t)))\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1) :\n (1 - δ ≤ ((Measure.pi (fun _ : Fin n => D))\n {ω : Fin n → 𝒵 | ∀ f ∈ F,\n ((∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i) ≤\n epsN n F D + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * Real.log (1 / δ)) / (n : ℝ))\n + (M * Real.log (1 / δ)) / (3 * (n : ℝ)))\n ∧ ((∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i) ≤\n 2 * epsN n F D + Real.sqrt ((2 * σ ^ 2 * Real.log (1 / δ)) / (n : ℝ))\n + (4 * M * Real.log (1 / δ)) / (3 * (n : ℝ)))}).toReal)\n ∧ (epsN n F D + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * Real.log (1 / δ)) / (n : ℝ))\n + (M * Real.log (1 / δ)) / (3 * (n : ℝ))\n ≤ 2 * epsN n F D + Real.sqrt ((2 * σ ^ 2 * Real.log (1 / δ)) / (n : ℝ))\n + (4 * M * Real.log (1 / δ)) / (3 * (n : ℝ))) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def epsN {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) : ℝ :=\n ∫ ω, (⨆ f : F, ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)))\n ∂(Measure.pi (fun _ : Fin n => D))\n\nprivate lemma second_bound_of_nonneg\n (e M s L d : ℝ) (he : 0 ≤ e) (hM : 0 ≤ M) (hs : 0 ≤ s)\n (hL : 0 ≤ L) (hd : 0 < d) :\n e + Real.sqrt (((4 * M * e + 2 * s) * L) / d) + (M * L) / (3 * d) ≤\n 2 * e + Real.sqrt ((2 * s * L) / d) + (4 * M * L) / (3 * d) := by\n have hd0 : d ≠ 0 := ne_of_gt hd\n let q : ℝ := M * L / d\n let r : ℝ := 2 * s * L / d\n have hq : 0 ≤ q := by\n dsimp [q]\n positivity\n have hr : 0 ≤ r := by\n dsimp [r]\n positivity\n have hrad : ((4 * M * e + 2 * s) * L) / d = 4 * e * q + r := by\n dsimp [q, r]\n field_simp\n have hfour : Real.sqrt (4 * e * q) ≤ e + q := by\n rw [Real.sqrt_le_iff]\n constructor\n · positivity\n · have hsq : 0 ≤ (e - q) ^ 2 := sq_nonneg (e - q)\n nlinarith\n have hadd : Real.sqrt (4 * e * q + r) ≤\n Real.sqrt (4 * e * q) + Real.sqrt r := by\n rw [Real.sqrt_le_iff]\n constructor\n · positivity\n · have h4eq : 0 ≤ 4 * e * q := by positivity\n have hs4 := Real.sq_sqrt h4eq\n have hsr := Real.sq_sqrt hr\n have hsqrt4 : 0 ≤ Real.sqrt (4 * e * q) := Real.sqrt_nonneg _\n have hsqrtr : 0 ≤ Real.sqrt r := Real.sqrt_nonneg _\n nlinarith\n rw [hrad]\n have hsqrt : Real.sqrt (4 * e * q + r) ≤ e + q + Real.sqrt r := by\n linarith\n have hq_div_three : M * L / (3 * d) = q / 3 := by\n dsimp [q]\n field_simp\n have hfourq_div_three : 4 * M * L / (3 * d) = 4 * q / 3 := by\n dsimp [q]\n field_simp\n rw [hq_div_three, hfourq_div_three]\n linarith\n\nprivate lemma epsN_nonneg\n {𝒵 : Type*} [MeasurableSpace 𝒵]\n (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (hF : F.Nonempty)\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (hMemLp : ∀ f ∈ F, MemLp f 2 D)\n (hInt : Integrable (fun ω => ⨆ f : F,\n ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)))\n (Measure.pi (fun _ : Fin n => D)))\n (M : ℝ)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M) :\n 0 ≤ epsN n F D := by\n rcases hF with ⟨f₀, hf₀⟩\n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn\n have hf₀int : Integrable f₀ D := (hMemLp f₀ hf₀).integrable (by norm_num)\n have hcoord (i : Fin n) :\n Integrable (fun ω : Fin n → 𝒵 => f₀ (ω i))\n (Measure.pi (fun _ : Fin n => D)) :=\n integrable_comp_eval hf₀int\n have hsum : Integrable (fun ω : Fin n → 𝒵 => ∑ i, f₀ (ω i))\n (Measure.pi (fun _ : Fin n => D)) := by\n exact integrable_finset_sum Finset.univ (fun i _ => hcoord i)\n have hdev : Integrable (fun ω : Fin n → 𝒵 =>\n (∫ z, f₀ z ∂D) - (1 / (n : ℝ)) * ∑ i, f₀ (ω i))\n (Measure.pi (fun _ : Fin n => D)) :=\n (integrable_const _).sub (hsum.const_mul _)\n have hdev_le (ω : Fin n → 𝒵) (f : F) :\n (∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i) ≤ M := by\n have hsum_le : ∑ i : Fin n, ((∫ z, f.1 z ∂D) - f.1 (ω i)) ≤\n ∑ _i : Fin n, M :=\n Finset.sum_le_sum fun i _ => hSup f.1 f.2 (ω i)\n have hid : (∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i) =\n (1 / (n : ℝ)) * ∑ i, ((∫ z, f.1 z ∂D) - f.1 (ω i)) := by\n rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin]\n field_simp\n simp [nsmul_eq_mul]\n ring\n rw [hid]\n calc\n (1 / (n : ℝ)) * ∑ i, ((∫ z, f.1 z ∂D) - f.1 (ω i)) ≤\n (1 / (n : ℝ)) * ∑ _i : Fin n, M := by\n exact mul_le_mul_of_nonneg_left hsum_le (by positivity)\n _ = M := by\n simp [hnR.ne']\n have hselected_le (ω : Fin n → 𝒵) :\n (∫ z, f₀ z ∂D) - (1 / (n : ℝ)) * ∑ i, f₀ (ω i) ≤\n ⨆ f : F, ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)) := by\n simpa using le_ciSup\n (show BddAbove (Set.range (fun f : F =>\n (∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i))) from\n ⟨M, by rintro _ ⟨f, rfl⟩; exact hdev_le ω f⟩)\n (⟨f₀, hf₀⟩ : F)\n have hintegral_dev :\n (∫ ω : Fin n → 𝒵,\n ((∫ z, f₀ z ∂D) - (1 / (n : ℝ)) * ∑ i, f₀ (ω i))\n ∂(Measure.pi (fun _ : Fin n => D))) = 0 := by\n rw [integral_sub (integrable_const _) (hsum.const_mul _), integral_const,\n integral_const_mul, integral_finset_sum Finset.univ (fun i _ => hcoord i)]\n simp_rw [integral_comp_eval (μ := fun _ : Fin n => D) hf₀int.aestronglyMeasurable]\n simp [hnR.ne']\n rw [epsN, ← hintegral_dev]\n exact integral_mono hdev hInt hselected_le\n\n/-- The supremum functional over the class (the integrand of `epsN`). -/\nprivate noncomputable def Gsup {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (ω : Fin n → 𝒵) : ℝ :=\n ⨆ f : F, ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i))\n\n/-- The leave-one-out (unnormalised) supremum functional. -/\nprivate noncomputable def Ksup {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (k : Fin n) (ω : Fin n → 𝒵) : ℝ :=\n ⨆ f : F, ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i))\n\nprivate lemma dev_eq {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ) (hn : 0 < n)\n (D : Measure 𝒵) (f : 𝒵 → ℝ) (ω : Fin n → 𝒵) :\n (∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i)\n = (1 / (n : ℝ)) * ∑ i, ((∫ z, f z ∂D) - f (ω i)) := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin,\n nsmul_eq_mul]\n field_simp\n\nprivate lemma dev_le_M {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (M : ℝ)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (ω : Fin n → 𝒵) (f : F) :\n (∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i) ≤ M := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n have hsum_le : ∑ i : Fin n, ((∫ z, f.1 z ∂D) - f.1 (ω i)) ≤ ∑ _i : Fin n, M :=\n Finset.sum_le_sum fun i _ => hSup f.1 f.2 (ω i)\n rw [dev_eq n hn D f.1 ω]\n calc (1 / (n : ℝ)) * ∑ i, ((∫ z, f.1 z ∂D) - f.1 (ω i))\n ≤ (1 / (n : ℝ)) * ∑ _i : Fin n, M :=\n mul_le_mul_of_nonneg_left hsum_le (by positivity)\n _ = M := by simp [hnR.ne']\n\nprivate lemma bddAbove_dev {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (M : ℝ)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (ω : Fin n → 𝒵) :\n BddAbove (Set.range (fun f : F => (∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i))) :=\n ⟨M, by rintro _ ⟨f, rfl⟩; exact dev_le_M n hn F D M hSup ω f⟩\n\nprivate lemma bddAbove_part {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (M : ℝ) (hM : 0 < M)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (k : Fin n) (ω : Fin n → 𝒵) :\n BddAbove (Set.range\n (fun f : F => ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i)))) := by\n refine ⟨(n : ℝ) * M, ?_⟩\n rintro _ ⟨f, rfl⟩\n have h1 : ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i))\n ≤ ∑ _i ∈ Finset.univ.erase k, M :=\n Finset.sum_le_sum fun i _ => hSup f.1 f.2 (ω i)\n have h2 : ∑ _i ∈ Finset.univ.erase k, M\n = (((Finset.univ : Finset (Fin n)).erase k).card : ℝ) * M := by\n rw [Finset.sum_const, nsmul_eq_mul]\n have h3 : (((Finset.univ : Finset (Fin n)).erase k).card : ℝ) ≤ (n : ℝ) := by\n have h := Finset.card_le_card (Finset.erase_subset k (Finset.univ : Finset (Fin n)))\n simp only [Finset.card_univ, Fintype.card_fin] at h\n exact_mod_cast h\n calc ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i))\n ≤ (((Finset.univ : Finset (Fin n)).erase k).card : ℝ) * M := by rw [← h2]; exact h1\n _ ≤ (n : ℝ) * M := by nlinarith [hM.le]\n\nprivate lemma dev_le_Gsup {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (M : ℝ)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (ω : Fin n → 𝒵) (f : F) :\n (∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i) ≤ Gsup n F D ω :=\n le_ciSup (bddAbove_dev n hn F D M hSup ω) f\n\nprivate lemma part_le_Ksup {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (M : ℝ) (hM : 0 < M)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (k : Fin n) (ω : Fin n → 𝒵) (f : F) :\n ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i)) ≤ Ksup n F D k ω :=\n le_ciSup (bddAbove_part n F D M hM hSup k ω) f\n\nprivate lemma Ksup_update {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ)\n (F : Set (𝒵 → ℝ)) (D : Measure 𝒵) (k : Fin n) (ω : Fin n → 𝒵) (z : 𝒵) :\n Ksup n F D k (Function.update ω k z) = Ksup n F D k ω := by\n unfold Ksup\n congr 1\n funext f\n refine Finset.sum_congr rfl ?_\n intro i hi\n rw [Function.update_of_ne (Finset.ne_of_mem_erase hi)]\n\nprivate lemma nGsup_le {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (hF : F.Nonempty) (D : Measure 𝒵) (M : ℝ) (hM : 0 < M)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (k : Fin n) (ω : Fin n → 𝒵) :\n (n : ℝ) * Gsup n F D ω ≤ Ksup n F D k ω + M := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n letI : Nonempty F := hF.to_subtype\n have hkey : Gsup n F D ω ≤ (Ksup n F D k ω + M) / (n : ℝ) := by\n refine ciSup_le ?_\n intro f\n rw [dev_eq n hn D f.1 ω]\n have hsplit : ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i))\n + ((∫ z, f.1 z ∂D) - f.1 (ω k)) = ∑ i, ((∫ z, f.1 z ∂D) - f.1 (ω i)) :=\n Finset.sum_erase_add _ _ (Finset.mem_univ k)\n have h1 := part_le_Ksup n F D M hM hSup k ω f\n have h2 := hSup f.1 f.2 (ω k)\n have h3 : ∑ i, ((∫ z, f.1 z ∂D) - f.1 (ω i)) ≤ Ksup n F D k ω + M := by\n rw [← hsplit]; linarith\n have hgoal : (Ksup n F D k ω + M) / (n : ℝ) = (1 / (n : ℝ)) * (Ksup n F D k ω + M) := by\n ring\n rw [hgoal]\n exact mul_le_mul_of_nonneg_left h3 (by positivity)\n have h4 := (le_div_iff₀ hnR).mp hkey\n calc (n : ℝ) * Gsup n F D ω = Gsup n F D ω * (n : ℝ) := by ring\n _ ≤ Ksup n F D k ω + M := h4\n\nprivate lemma sum_gap_le {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (hF : F.Nonempty) (D : Measure 𝒵) (M : ℝ) (hM : 0 < M)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (ω : Fin n → 𝒵) :\n ∑ k : Fin n, ((n : ℝ) * Gsup n F D ω - Ksup n F D k ω) ≤ (n : ℝ) * Gsup n F D ω := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n have hn1 : (1 : ℝ) ≤ (n : ℝ) := by exact_mod_cast hn\n letI : Nonempty F := hF.to_subtype\n refine le_of_forall_pos_le_add ?_\n intro η hη\n have hpos : 0 < η / ((n : ℝ) * (n : ℝ)) := by positivity\n have hlt : Gsup n F D ω - η / ((n : ℝ) * (n : ℝ))\n < ⨆ f : F, ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)) := by\n show Gsup n F D ω - η / ((n : ℝ) * (n : ℝ)) < Gsup n F D ω\n linarith\n obtain ⟨f, hf⟩ := exists_lt_of_lt_ciSup hlt\n set b : ℝ := ∑ i, ((∫ z, f.1 z ∂D) - f.1 (ω i)) with hbdef\n have hfb : Gsup n F D ω - η / ((n : ℝ) * (n : ℝ)) < (1 / (n : ℝ)) * b := by\n rw [dev_eq n hn D f.1 ω] at hf\n exact hf\n have hb1 : (n : ℝ) * Gsup n F D ω - b < η / (n : ℝ) := by\n have h := mul_lt_mul_of_pos_left hfb hnR\n have e1 : (n : ℝ) * ((1 / (n : ℝ)) * b) = b := by field_simp\n have e2 : (n : ℝ) * (Gsup n F D ω - η / ((n : ℝ) * (n : ℝ)))\n = (n : ℝ) * Gsup n F D ω - η / (n : ℝ) := by field_simp\n rw [e1, e2] at h\n linarith\n have hb2 : b ≤ (n : ℝ) * Gsup n F D ω := by\n have h := dev_le_Gsup n hn F D M hSup ω f\n rw [dev_eq n hn D f.1 ω] at h\n have h2 := mul_le_mul_of_nonneg_left h (le_of_lt hnR)\n have e1 : (n : ℝ) * ((1 / (n : ℝ)) * b) = b := by field_simp\n rw [e1] at h2\n exact h2\n have hterm : ∀ k : Fin n, (n : ℝ) * Gsup n F D ω - Ksup n F D k ω\n ≤ ((n : ℝ) * Gsup n F D ω - b) + ((∫ z, f.1 z ∂D) - f.1 (ω k)) := by\n intro k\n have h1 := part_le_Ksup n F D M hM hSup k ω f\n have h2 : ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i))\n + ((∫ z, f.1 z ∂D) - f.1 (ω k)) = b :=\n Finset.sum_erase_add _ _ (Finset.mem_univ k)\n linarith\n have hA : (n : ℝ) * ((n : ℝ) * Gsup n F D ω - b) < η := by\n have h := mul_lt_mul_of_pos_left hb1 hnR\n rwa [mul_div_cancel₀ _ hnR.ne'] at h\n calc ∑ k : Fin n, ((n : ℝ) * Gsup n F D ω - Ksup n F D k ω)\n ≤ ∑ k : Fin n, (((n : ℝ) * Gsup n F D ω - b) + ((∫ z, f.1 z ∂D) - f.1 (ω k))) :=\n Finset.sum_le_sum fun k _ => hterm k\n _ = (n : ℝ) * ((n : ℝ) * Gsup n F D ω - b) + b := by\n rw [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin,\n nsmul_eq_mul]\n _ ≤ (n : ℝ) * Gsup n F D ω + η := by linarith\n\nprivate lemma integral_add_const_of_probability {α : Type*} [MeasurableSpace α]\n (μ : Measure α) [IsProbabilityMeasure μ] (g : α → ℝ) (hg : Integrable g μ) (A : ℝ) :\n ∫ z, (g z + A) ∂μ = (∫ z, g z ∂μ) + A := by\n rw [integral_add hg (integrable_const _), integral_const]\n simp\n\nprivate lemma integral_sq_add_const_of_probability {α : Type*} [MeasurableSpace α]\n (μ : Measure α) [IsProbabilityMeasure μ] (g : α → ℝ) (hg : Integrable g μ)\n (hg2 : Integrable (fun z => g z ^ 2) μ) (A : ℝ) :\n ∫ z, (g z + A) ^ 2 ∂μ = (∫ z, g z ^ 2 ∂μ) + 2 * A * (∫ z, g z ∂μ) + A ^ 2 := by\n have hi : Integrable (fun z => g z ^ 2 + 2 * A * g z) μ := by\n simpa using hg2.add (hg.const_mul (2 * A))\n have h : ∀ z, (g z + A) ^ 2 = (g z ^ 2 + (2 * A) * g z) + A ^ 2 := fun z => by ring\n simp_rw [h]\n rw [integral_add hi (integrable_const _),\n integral_add hg2 (hg.const_mul (2 * A)), integral_const_mul, integral_const]\n simp\n\n\n/-- The hypothesis `hBousquet` of the target theorem, packaged as a `Prop`. -/\nprivate def BousquetHyp {𝒵 : Type*} [MeasurableSpace 𝒵] (n : ℕ) (D : Measure 𝒵) : Prop :=\n ∀ (ζ : (Fin n → 𝒵) → ℝ) (ζk ζ' : Fin n → (Fin n → 𝒵) → ℝ)\n (u Mb sb t : ℝ), 0 ≤ u → 0 ≤ t → 0 < Mb →\n (∀ k ω z, ζk k (Function.update ω k z) = ζk k ω) →\n (∀ ω, ∑ k, (ζ ω - ζk k ω) ≤ ζ ω) →\n (∀ k ω, ζ' k ω ≤ ζ ω - ζk k ω) →\n (∀ k ω, ζ ω - ζk k ω ≤ Mb) →\n (∀ k ω, ζ' k ω ≤ u * Mb) →\n Integrable ζ (Measure.pi (fun _ : Fin n => D)) →\n (∀ k ω, Integrable (fun z => ζ' k (Function.update ω k z)) D) →\n (∀ k ω, Integrable (fun z => (ζ' k (Function.update ω k z)) ^ 2) D) →\n (∀ k ω, 0 ≤ ∫ z, ζ' k (Function.update ω k z) ∂D) →\n (∀ k ω, ∫ z, (ζ' k (Function.update ω k z)) ^ 2 ∂D ≤ sb ^ 2) →\n (Measure.pi (fun _ : Fin n => D))\n {ω : Fin n → 𝒵 |\n (∫ x, ζ x ∂(Measure.pi (fun _ : Fin n => D)))\n + Real.sqrt (2 * ((1 + u) * Mb\n * (∫ x, ζ x ∂(Measure.pi (fun _ : Fin n => D))) + (n : ℝ) * sb ^ 2) * t)\n + t * Mb / 3 ≤ ζ ω}\n ≤ ENNReal.ofReal (Real.exp (-t))\n\nprivate lemma prob_bound_c\n {𝒵 : Type*} [MeasurableSpace 𝒵]\n (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (hF : F.Nonempty)\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (hMemLp : ∀ f ∈ F, MemLp f 2 D)\n (hInt : Integrable (fun ω => ⨆ f : F,\n ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)))\n (Measure.pi (fun _ : Fin n => D)))\n (M σ : ℝ) (hM : 0 < M)\n (hVar : ∀ f ∈ F, ProbabilityTheory.variance f D ≤ σ ^ 2)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (hB : BousquetHyp n D)\n (t : ℝ) (ht : 0 ≤ t) (c : ℝ) (hc : 0 < c) :\n (Measure.pi (fun _ : Fin n => D))\n {ω : Fin n → 𝒵 |\n epsN n F D\n + Real.sqrt (2 * (2 * (M + c) * ((n : ℝ) * epsN n F D + (n : ℝ) * c)\n + (n : ℝ) * (σ ^ 2 + c ^ 2)) * t) / (n : ℝ)\n + t * (M + c) / (3 * (n : ℝ)) ≤ Gsup n F D ω}\n ≤ ENNReal.ofReal (Real.exp (-t)) := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n letI : Nonempty F := hF.to_subtype\n have hIntG : Integrable (fun ω => Gsup n F D ω) (Measure.pi (fun _ : Fin n => D)) := hInt\n have hZ : Nonempty 𝒵 := by\n rcases isEmpty_or_nonempty 𝒵 with h | h\n · exfalso\n have h1 : (Set.univ : Set 𝒵) = ∅ := Set.univ_eq_empty_iff.mpr h\n have h2 := measure_univ (μ := D)\n rw [h1] at h2\n simp at h2\n · exact h\n obtain ⟨z₀⟩ := hZ\n -- basic integral facts about the centred functions\n have hfint : ∀ f : F, Integrable f.1 D := fun f => (hMemLp f.1 f.2).integrable (by norm_num)\n have hgint : ∀ f : F, Integrable (fun z => (∫ w, f.1 w ∂D) - f.1 z) D :=\n fun f => (integrable_const _).sub (hfint f)\n have hg0 : ∀ f : F, (∫ z, ((∫ w, f.1 w ∂D) - f.1 z) ∂D) = 0 := by\n intro f\n rw [integral_sub (integrable_const _) (hfint f), integral_const]\n simp\n have hgsq_int : ∀ f : F, Integrable (fun z => ((∫ w, f.1 w ∂D) - f.1 z) ^ 2) D := by\n intro f\n exact ((memLp_const ((∫ w, f.1 w ∂D))).sub (hMemLp f.1 f.2)).integrable_sq\n have hgsq : ∀ f : F, (∫ z, ((∫ w, f.1 w ∂D) - f.1 z) ^ 2 ∂D) ≤ σ ^ 2 := by\n intro f\n have hae : AEMeasurable f.1 D := (hMemLp f.1 f.2).aestronglyMeasurable.aemeasurable\n have h1 : (∫ z, ((∫ w, f.1 w ∂D) - f.1 z) ^ 2 ∂D)\n = ∫ z, (f.1 z - ∫ w, f.1 w ∂D) ^ 2 ∂D := by\n congr 1\n funext z\n ring\n rw [h1, ← variance_eq_integral hae]\n exact hVar f.1 f.2\n -- an approximate maximiser of the leave-one-out supremum, not depending on coordinate `k`\n have hchoice : ∀ (k : Fin n) (ω : Fin n → 𝒵), ∃ f : F,\n Ksup n F D k ω - c ≤ ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i)) := by\n intro k ω\n have hlt : Ksup n F D k ω - c\n < ⨆ f : F, ∑ i ∈ Finset.univ.erase k, ((∫ z, f.1 z ∂D) - f.1 (ω i)) := by\n show Ksup n F D k ω - c < Ksup n F D k ω\n linarith\n obtain ⟨f, hf⟩ := exists_lt_of_lt_ciSup hlt\n exact ⟨f, hf.le⟩\n choose Ψ hΨ using hchoice\n obtain ⟨φ, hφupd, hφprop⟩ : ∃ φ : Fin n → (Fin n → 𝒵) → F,\n (∀ k ω z, φ k (Function.update ω k z) = φ k ω) ∧\n (∀ k ω, Ksup n F D k ω - c\n ≤ ∑ i ∈ Finset.univ.erase k, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i))) := by\n refine ⟨fun k ω => Ψ k (Function.update ω k z₀), ?_, ?_⟩\n · intro k ω z\n simp only [Function.update_idem]\n · intro k ω\n have h := hΨ k (Function.update ω k z₀)\n rw [Ksup_update] at h\n refine le_trans h (le_of_eq (Finset.sum_congr rfl ?_))\n intro i hi\n rw [Function.update_of_ne (Finset.ne_of_mem_erase hi)]\n have hφub : ∀ (k : Fin n) (ω : Fin n → 𝒵),\n ∑ i ∈ Finset.univ.erase k, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i))\n ≤ Ksup n F D k ω := fun k ω => part_le_Ksup n F D M hM hSup k ω (φ k ω)\n set ζ : (Fin n → 𝒵) → ℝ := fun ω => (n : ℝ) * Gsup n F D ω + (n : ℝ) * c with hζdef\n set ζk : Fin n → (Fin n → 𝒵) → ℝ :=\n fun k �� => Ksup n F D k ω - c + (n : ℝ) * c with hζkdef\n set ζ' : Fin n → (Fin n → 𝒵) → ℝ :=\n fun k ω => (∑ i, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i))) - Ksup n F D k ω + c\n with hζ'def\n -- shorthand for the \"defect\" of the approximate maximiser\n have hSle : ∀ (k : Fin n) (ω : Fin n → 𝒵),\n (∑ i, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i))) ≤ (n : ℝ) * Gsup n F D ω := by\n intro k ω\n have h := dev_le_Gsup n hn F D M hSup ω (φ k ω)\n rw [dev_eq n hn D (φ k ω).1 ω] at h\n have h2 := mul_le_mul_of_nonneg_left h (le_of_lt hnR)\n rw [show (n : ℝ) * ((1 / (n : ℝ)) * ∑ i, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i)))\n = ∑ i, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i)) by field_simp] at h2\n exact h2\n have hSsplit : ∀ (k : Fin n) (ω : Fin n → 𝒵),\n (∑ i ∈ Finset.univ.erase k, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i)))\n + ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω k))\n = ∑ i, ((∫ z, (φ k ω).1 z ∂D) - (φ k ω).1 (ω i)) :=\n fun k ω => Finset.sum_erase_add _ _ (Finset.mem_univ k)\n -- the Bousquet hypotheses\n have h1 : ∀ (k : Fin n) (ω : Fin n → 𝒵) (z : 𝒵),\n ζk k (Function.update ω k z) = ζk k ω := by\n intro k ω z\n simp only [hζkdef]\n rw [Ksup_update]\n have h2 : ∀ ω, ∑ k, (ζ ω - ζk k ω) ≤ ζ ω := by\n intro ω\n have hs := sum_gap_le n hn F hF D M hM hSup ω\n have hterm : ∀ k : Fin n, ζ ω - ζk k ω\n = ((n : ℝ) * Gsup n F D ω - Ksup n F D k ω) + c := by\n intro k\n simp only [hζdef, hζkdef]\n ring\n rw [Finset.sum_congr rfl (fun k (_ : k ∈ Finset.univ) => hterm k), Finset.sum_add_distrib,\n Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n simp only [hζdef]\n linarith\n have h3 : ∀ (k : Fin n) (ω : Fin n → 𝒵), ζ' k ω ≤ ζ ω - ζk k ω := by\n intro k ω\n simp only [hζdef, hζkdef, hζ'def]\n have := hSle k ω\n linarith\n have h4 : ∀ (k : Fin n) (ω : Fin n → 𝒵), ζ ω - ζk k ω ≤ M + c := by\n intro k ω\n simp only [hζdef, hζkdef]\n have := nGsup_le n hn F hF D M hM hSup k ω\n linarith\n have h5 : ∀ (k : Fin n) (ω : Fin n → 𝒵), ζ' k ω ≤ 1 * (M + c) := by\n intro k ω\n simp only [hζ'def]\n have hb := hφub k ω\n have hsp := hSsplit k ω\n have hM' := hSup (φ k ω).1 (φ k ω).2 (ω k)\n rw [one_mul]\n linarith\n have hζ'upd : ∀ (k : Fin n) (ω : Fin n → 𝒵) (z : 𝒵),\n ζ' k (Function.update ω k z)\n = ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 z)\n + ((∑ i ∈ Finset.univ.erase k, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (ω i)))\n - Ksup n F D k ω + c) := by\n intro k ω z\n simp only [hζ'def]\n rw [hφupd k ω z, Ksup_update]\n have hsplit : ∑ i, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (Function.update ω k z i))\n = (∑ i ∈ Finset.univ.erase k, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (ω i)))\n + ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 z) := by\n rw [← Finset.sum_erase_add _ _ (Finset.mem_univ k)]\n congr 1\n · exact Finset.sum_congr rfl fun i hi => by\n rw [Function.update_of_ne (Finset.ne_of_mem_erase hi)]\n · rw [Function.update_self]\n rw [hsplit]\n ring\n have hAnn : ∀ (k : Fin n) (ω : Fin n → 𝒵),\n 0 ≤ (∑ i ∈ Finset.univ.erase k, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (ω i)))\n - Ksup n F D k ω + c := by\n intro k ω\n have := hφprop k ω\n linarith\n have hAle : ∀ (k : Fin n) (ω : Fin n → 𝒵),\n (∑ i ∈ Finset.univ.erase k, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (ω i)))\n - Ksup n F D k ω + c ≤ c := by\n intro k ω\n have := hφub k ω\n linarith\n have h6 : ∀ (k : Fin n) (ω : Fin n → 𝒵),\n 0 ≤ ∫ z, ζ' k (Function.update ω k z) ∂D := by\n intro k ω\n simp_rw [hζ'upd k ω]\n rw [integral_add_const_of_probability D _ (hgint (φ k ω)), hg0 (φ k ω), zero_add]\n exact hAnn k ω\n have h7 : ∀ (k : Fin n) (ω : Fin n → 𝒵),\n ∫ z, (ζ' k (Function.update ω k z)) ^ 2 ∂D ≤ (Real.sqrt (σ ^ 2 + c ^ 2)) ^ 2 := by\n intro k ω\n rw [Real.sq_sqrt (by positivity)]\n simp_rw [hζ'upd k ω]\n rw [integral_sq_add_const_of_probability D _ (hgint (φ k ω)) (hgsq_int (φ k ω)),\n hg0 (φ k ω)]\n have hq := hgsq (φ k ω)\n have hn0 := hAnn k ω\n have hnc := hAle k ω\n nlinarith [hq, hn0, hnc, hc.le]\n have main := hB ζ ζk ζ' 1 (M + c) (Real.sqrt (σ ^ 2 + c ^ 2)) t zero_le_one ht\n (by linarith) h1 h2 h3 h4 h5\n (by\n simp only [hζdef]\n exact (hIntG.const_mul _).add (integrable_const _))\n (by\n intro k ω\n simp_rw [hζ'upd k ω]\n exact integrable_add_const_iff.mpr (hgint (φ k ω)))\n (by\n intro k ω\n simp_rw [hζ'upd k ω]\n have hg := hgint (φ k ω)\n have hg2 := hgsq_int (φ k ω)\n have h : ∀ z, (((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 z)\n + ((∑ i ∈ Finset.univ.erase k, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (ω i)))\n - Ksup n F D k ω + c)) ^ 2\n = (((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 z) ^ 2\n + (2 * ((∑ i ∈ Finset.univ.erase k, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (ω i)))\n - Ksup n F D k ω + c))\n * ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 z))\n + ((∑ i ∈ Finset.univ.erase k, ((∫ w, (φ k ω).1 w ∂D) - (φ k ω).1 (ω i)))\n - Ksup n F D k ω + c) ^ 2 := fun z => by ring\n simp_rw [h]\n exact ((hg2.add (hg.const_mul _)).add (integrable_const _)))\n h6 h7\n have hζint : (∫ x, ζ x ∂(Measure.pi (fun _ : Fin n => D)))\n = (n : ℝ) * epsN n F D + (n : ℝ) * c := by\n simp only [hζdef]\n rw [integral_add (hIntG.const_mul _) (integrable_const _), integral_const_mul,\n integral_const]\n have : (Measure.pi (fun _ : Fin n => D)).real Set.univ • ((n : ℝ) * c) = (n : ℝ) * c := by\n simp\n rw [this]\n rfl\n rw [hζint] at main\n refine le_trans (measure_mono ?_) main\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n rw [Real.sq_sqrt (by positivity : (0:ℝ) ≤ σ ^ 2 + c ^ 2)]\n simp only [hζdef]\n have hmul := mul_le_mul_of_nonneg_left hω (le_of_lt hnR)\n have hrw : (n : ℝ) * (epsN n F D\n + Real.sqrt (2 * (2 * (M + c) * ((n : ℝ) * epsN n F D + (n : ℝ) * c)\n + (n : ℝ) * (σ ^ 2 + c ^ 2)) * t) / (n : ℝ)\n + t * (M + c) / (3 * (n : ℝ)))\n = (n : ℝ) * epsN n F D\n + Real.sqrt (2 * (2 * (M + c) * ((n : ℝ) * epsN n F D + (n : ℝ) * c)\n + (n : ℝ) * (σ ^ 2 + c ^ 2)) * t)\n + t * (M + c) / 3 := by\n field_simp\n rw [hrw] at hmul\n have harg : (1 + (1:ℝ)) * (M + c) * ((n : ℝ) * epsN n F D + (n : ℝ) * c)\n + (n : ℝ) * (σ ^ 2 + c ^ 2)\n = 2 * (M + c) * ((n : ℝ) * epsN n F D + (n : ℝ) * c) + (n : ℝ) * (σ ^ 2 + c ^ 2) := by\n ring\n rw [harg]\n linarith\n\nprivate lemma prob_bound_final\n {𝒵 : Type*} [MeasurableSpace 𝒵]\n (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (hF : F.Nonempty)\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (hMemLp : ∀ f ∈ F, MemLp f 2 D)\n (hInt : Integrable (fun ω => ⨆ f : F,\n ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)))\n (Measure.pi (fun _ : Fin n => D)))\n (M σ : ℝ) (hM : 0 < M)\n (hVar : ∀ f ∈ F, ProbabilityTheory.variance f D ≤ σ ^ 2)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (hB : BousquetHyp n D)\n (t : ℝ) (ht : 0 ≤ t) :\n (Measure.pi (fun _ : Fin n => D))\n {ω : Fin n → 𝒵 |\n epsN n F D\n + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * t) / (n : ℝ))\n + (M * t) / (3 * (n : ℝ)) < Gsup n F D ω}\n ≤ ENNReal.ofReal (Real.exp (-t)) := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n have he : 0 ≤ epsN n F D := epsN_nonneg n hn F hF D hMemLp hInt M hSup\n set Bf : ℝ → ℝ := fun c => epsN n F D\n + Real.sqrt (2 * (2 * (M + c) * ((n : ℝ) * epsN n F D + (n : ℝ) * c)\n + (n : ℝ) * (σ ^ 2 + c ^ 2)) * t) / (n : ℝ)\n + t * (M + c) / (3 * (n : ℝ)) with hBfdef\n have hcont : Continuous Bf := by rw [hBfdef]; fun_prop\n have hB0 : Bf 0 = epsN n F D\n + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * t) / (n : ℝ))\n + (M * t) / (3 * (n : ℝ)) := by\n have hrad : (((4 * M * epsN n F D + 2 * σ ^ 2) * t) / (n : ℝ))\n = (2 * (2 * (M + 0) * ((n : ℝ) * epsN n F D + (n : ℝ) * 0)\n + (n : ℝ) * (σ ^ 2 + 0 ^ 2)) * t) / ((n : ℝ) ^ 2) := by\n field_simp\n ring\n have hnum : (0:ℝ) ≤ 2 * (2 * (M + 0) * ((n : ℝ) * epsN n F D + (n : ℝ) * 0)\n + (n : ℝ) * (σ ^ 2 + 0 ^ 2)) * t := by\n have hid : 2 * (2 * (M + 0) * ((n : ℝ) * epsN n F D + (n : ℝ) * 0)\n + (n : ℝ) * (σ ^ 2 + 0 ^ 2)) * t\n = 4 * (M * ((n : ℝ) * epsN n F D) * t) + 2 * ((n : ℝ) * (σ ^ 2 * t)) := by ring\n have hA : (0:ℝ) ≤ M * ((n : ℝ) * epsN n F D) * t :=\n mul_nonneg (mul_nonneg hM.le (mul_nonneg hnR.le he)) ht\n have hBn : (0:ℝ) ≤ (n : ℝ) * (σ ^ 2 * t) :=\n mul_nonneg hnR.le (mul_nonneg (sq_nonneg σ) ht)\n rw [hid]\n linarith\n rw [hBfdef]\n simp only\n rw [hrad, Real.sqrt_div hnum, Real.sqrt_sq hnR.le]\n ring_nf\n have key : ∀ η : ℝ, 0 < η →\n (Measure.pi (fun _ : Fin n => D)) {ω : Fin n → 𝒵 | Bf 0 + η ≤ Gsup n F D ω}\n ≤ ENNReal.ofReal (Real.exp (-t)) := by\n intro η hη\n have h2 : ∀ᶠ c in nhds (0:ℝ), Bf c < Bf 0 + η :=\n (hcont.tendsto 0).eventually (Iio_mem_nhds (by linarith))\n have h3 : ∀ᶠ c in nhdsWithin (0:ℝ) (Set.Ioi 0), Bf c < Bf 0 + η :=\n h2.filter_mono nhdsWithin_le_nhds\n have h4 : ∀ᶠ c in nhdsWithin (0:ℝ) (Set.Ioi 0), (0:ℝ) < c := self_mem_nhdsWithin\n obtain ⟨c, hclt, hcpos⟩ := (h3.and h4).exists\n refine le_trans (measure_mono ?_)\n (prob_bound_c n hn F hF D hMemLp hInt M σ hM hVar hSup hB t ht c hcpos)\n intro ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n have hbc : Bf c = epsN n F D\n + Real.sqrt (2 * (2 * (M + c) * ((n : ℝ) * epsN n F D + (n : ℝ) * c)\n + (n : ℝ) * (σ ^ 2 + c ^ 2)) * t) / (n : ℝ)\n + t * (M + c) / (3 * (n : ℝ)) := by rw [hBfdef]\n rw [← hbc]\n exact le_trans hclt.le hω\n have hmono : Monotone\n (fun m : ℕ => {ω : Fin n → 𝒵 | Bf 0 + 1 / ((m : ℝ) + 1) ≤ Gsup n F D ω}) := by\n intro a b hab ω hω\n simp only [Set.mem_setOf_eq] at hω ⊢\n have hle : (1:ℝ) / ((b : ℝ) + 1) ≤ 1 / ((a : ℝ) + 1) := by\n apply one_div_le_one_div_of_le\n · positivity\n · have : (a : ℝ) ≤ (b : ℝ) := by exact_mod_cast hab\n linarith\n linarith\n have hunion : {ω : Fin n → 𝒵 | Bf 0 < Gsup n F D ω}\n = ⋃ m : ℕ, {ω : Fin n → 𝒵 | Bf 0 + 1 / ((m : ℝ) + 1) ≤ Gsup n F D ω} := by\n ext ω\n simp only [Set.mem_setOf_eq, Set.mem_iUnion]\n constructor\n · intro h\n obtain ⟨m, hm⟩ := exists_nat_one_div_lt (show (0:ℝ) < Gsup n F D ω - Bf 0 by linarith)\n exact ⟨m, by linarith⟩\n · rintro ⟨m, hm⟩\n have hpos : (0:ℝ) < 1 / ((m : ℝ) + 1) := by positivity\n linarith\n rw [← hB0, hunion, hmono.measure_iUnion]\n refine iSup_le fun m => key _ (by positivity)\n\ntheorem corollary_6_34\n {𝒵 : Type*} [MeasurableSpace 𝒵]\n (n : ℕ) (hn : 0 < n)\n (F : Set (𝒵 → ℝ)) (hF : F.Nonempty)\n (D : Measure 𝒵) [IsProbabilityMeasure D]\n (hMemLp : ∀ f ∈ F, MemLp f 2 D)\n (hInt : Integrable (fun ω => ⨆ f : F,\n ((∫ z, f.1 z ∂D) - (1 / (n : ℝ)) * ∑ i, f.1 (ω i)))\n (Measure.pi (fun _ : Fin n => D)))\n (M σ : ℝ) (hM : 0 < M) (hσ : 0 < σ)\n (hVar : ∀ f ∈ F, ProbabilityTheory.variance f D ≤ σ ^ 2)\n (hSup : ∀ f ∈ F, ∀ z' : 𝒵, (∫ z, f z ∂D) - f z' ≤ M)\n (hBousquet : ∀ (ζ : (Fin n → 𝒵) → ℝ) (ζk ζ' : Fin n → (Fin n → 𝒵) → ℝ)\n (u Mb sb t : ℝ), 0 ≤ u → 0 ≤ t → 0 < Mb →\n (∀ k ω z, ζk k (Function.update ω k z) = ζk k ω) →\n (∀ ω, ∑ k, (ζ ω - ζk k ω) ≤ ζ ω) →\n (∀ k ω, ζ' k ω ≤ ζ ω - ζk k ω) →\n (∀ k ω, ζ ω - ζk k ω ≤ Mb) →\n (∀ k ω, ζ' k ω ≤ u * Mb) →\n Integrable ζ (Measure.pi (fun _ : Fin n => D)) →\n (∀ k ω, Integrable (fun z => ζ' k (Function.update ω k z)) D) →\n (∀ k ω, Integrable (fun z => (ζ' k (Function.update ω k z)) ^ 2) D) →\n (∀ k ω, 0 ≤ ∫ z, ζ' k (Function.update ω k z) ∂D) →\n (∀ k ω, ∫ z, (ζ' k (Function.update ω k z)) ^ 2 ∂D ≤ sb ^ 2) →\n (Measure.pi (fun _ : Fin n => D))\n {ω : Fin n → 𝒵 |\n (∫ x, ζ x ∂(Measure.pi (fun _ : Fin n => D)))\n + Real.sqrt (2 * ((1 + u) * Mb\n * (∫ x, ζ x ∂(Measure.pi (fun _ : Fin n => D))) + (n : ℝ) * sb ^ 2) * t)\n + t * Mb / 3 ≤ ζ ω}\n ≤ ENNReal.ofReal (Real.exp (-t)))\n (δ : ℝ) (hδ0 : 0 < δ) (hδ1 : δ < 1) :\n (1 - δ ≤ ((Measure.pi (fun _ : Fin n => D))\n {ω : Fin n → 𝒵 | ∀ f ∈ F,\n ((∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i) ≤\n epsN n F D + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * Real.log (1 / δ)) / (n : ℝ))\n + (M * Real.log (1 / δ)) / (3 * (n : ℝ)))\n ∧ ((∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i) ≤\n 2 * epsN n F D + Real.sqrt ((2 * σ ^ 2 * Real.log (1 / δ)) / (n : ℝ))\n + (4 * M * Real.log (1 / δ)) / (3 * (n : ℝ)))}).toReal)\n ∧ (epsN n F D + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * Real.log (1 / δ)) / (n : ℝ))\n + (M * Real.log (1 / δ)) / (3 * (n : ℝ))\n ≤ 2 * epsN n F D + Real.sqrt ((2 * σ ^ 2 * Real.log (1 / δ)) / (n : ℝ))\n + (4 * M * Real.log (1 / δ)) / (3 * (n : ℝ))) := by\n have hnR : (0 : ℝ) < n := by exact_mod_cast hn\n have hB : BousquetHyp n D := hBousquet\n have he : 0 ≤ epsN n F D := epsN_nonneg n hn F hF D hMemLp hInt M hSup\n have hL : 0 < Real.log (1 / δ) := by\n have h1 : (1:ℝ) < 1 / δ := by\n rw [lt_div_iff₀ hδ0]\n linarith\n exact Real.log_pos h1\n have hsecond : epsN n F D\n + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * Real.log (1 / δ)) / (n : ℝ))\n + (M * Real.log (1 / δ)) / (3 * (n : ℝ))\n ≤ 2 * epsN n F D + Real.sqrt ((2 * σ ^ 2 * Real.log (1 / δ)) / (n : ℝ))\n + (4 * M * Real.log (1 / δ)) / (3 * (n : ℝ)) :=\n second_bound_of_nonneg (epsN n F D) M (σ ^ 2) (Real.log (1 / δ)) (n : ℝ) he hM.le\n (by positivity) hL.le hnR\n refine ⟨?_, hsecond⟩\n have hkey := prob_bound_final n hn F hF D hMemLp hInt M σ hM hVar hSup hB\n (Real.log (1 / δ)) hL.le\n have hexp : Real.exp (-Real.log (1 / δ)) = δ := by\n rw [one_div, Real.log_inv, neg_neg, Real.exp_log hδ0]\n rw [hexp] at hkey\n set b0 : ℝ := epsN n F D\n + Real.sqrt (((4 * M * epsN n F D + 2 * σ ^ 2) * Real.log (1 / δ)) / (n : ℝ))\n + (M * Real.log (1 / δ)) / (3 * (n : ℝ)) with hb0def\n set b1 : ℝ := 2 * epsN n F D + Real.sqrt ((2 * σ ^ 2 * Real.log (1 / δ)) / (n : ℝ))\n + (4 * M * Real.log (1 / δ)) / (3 * (n : ℝ)) with hb1def\n set S : Set (Fin n → 𝒵) := {ω : Fin n → 𝒵 | ∀ f ∈ F,\n ((∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i) ≤ b0)\n ∧ ((∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i) ≤ b1)} with hSdef\n have hcompl : Sᶜ ⊆ {ω : Fin n → 𝒵 | b0 < Gsup n F D ω} := by\n intro ω hω\n simp only [hSdef, Set.mem_compl_iff, Set.mem_setOf_eq, not_forall] at hω\n obtain ⟨f, hf, hnot⟩ := hω\n have hdev : b0 < (∫ z, f z ∂D) - (1 / (n : ℝ)) * ∑ i, f (ω i) := by\n by_contra hcon\n push_neg at hcon\n exact hnot ⟨hcon, le_trans hcon hsecond⟩\n exact lt_of_lt_of_le hdev (dev_le_Gsup n hn F D M hSup ω ⟨f, hf⟩)\n have hmeasCompl : (Measure.pi (fun _ : Fin n => D)) Sᶜ ≤ ENNReal.ofReal δ :=\n le_trans (measure_mono hcompl) hkey\n have htot : (1 : ENNReal) ≤ (Measure.pi (fun _ : Fin n => D)) S\n + (Measure.pi (fun _ : Fin n => D)) Sᶜ := by\n have h := measure_union_le (μ := (Measure.pi (fun _ : Fin n => D))) S Sᶜ\n rw [Set.union_compl_self] at h\n simpa using h\n have hSge : (1 : ENNReal) - ENNReal.ofReal δ ≤ (Measure.pi (fun _ : Fin n => D)) S := by\n rw [tsub_le_iff_right]\n exact le_trans htot (by gcongr)\n have hδle : ENNReal.ofReal δ ≤ (1 : ENNReal) := by\n rw [← ENNReal.ofReal_one]\n exact ENNReal.ofReal_le_ofReal hδ1.le\n have hfin : (Measure.pi (fun _ : Fin n => D)) S ≠ ⊤ := measure_ne_top _ _\n have hmono := ENNReal.toReal_mono hfin hSge\n rw [ENNReal.toReal_sub_of_le hδle (by simp), ENNReal.toReal_one,\n ENNReal.toReal_ofReal hδ0.le] at hmono\n exact hmono\n\nend GraduateLevel\n"} +{"id": "ch15_theorem_15_6", "source": "Graduate-level", "targets": [{"label": "ch15_theorem_15_6", "decls": ["ch15_theorem_15_6"], "statement": "Consider the ridge regression method of (15.3), with \\(\\Lambda_0\\) symmetric positive definite. We have the following result for any \\(\\sigma \\geq 0\\) and for all observed sequence \\(S_T\\):\n\\[\n\\begin{array}{l}\\sum_{t=1}^{T}\\left[\\frac{\\left(Y_{t}-\\hat{w}\\left(\\mathcal{S}_{t-1}\\right)^{\\top}\\psi\\left(X_{t}\\right)\\right)^{2}}{b_{t}}+\\sigma^{2}\\ln b_{t}\\right]\\\\ =\\inf_{w}\\left[\\sum_{t=1}^{T}\\left(Y_{t}-w^{\\top}\\psi\\left(X_{t}\\right)\\right)^{2}+\\|w\\|_{\\Lambda_{0}}^{2}\\right]+\\sigma^{2}\\ln\\left|\\Lambda_{0}^{-1}\\Lambda_{T}\\right|,\\\\ \\end{array}\n\\]\nwhere\n\\[\n\\Lambda_{t}=\\Lambda_{0}+\\sum_{s=1}^{t}\\psi(X_{s})\\psi(X_{s})^{\\top},\n\\]\nand \\(b_{t} = 1 + \\psi (X_{t})^{\\top}\\Lambda_{t - 1}^{-1}\\psi (X_{t}).\\)", "topic_domain": "Online Learning & RL", "topic_subtopic": "Online Learning & Regret"}], "nl_proof": "Assume \\( w \\in \\mathbb{R}^d \\). We note that from Gaussian integration that\n\\[\n\\begin{array}{l}\\mathbb{E}_{w\\sim p_{0}}\\prod_{i=1}^{T}p\\left(Y_{i}|w,X_{i}\\right)\\\\ =\\int\\frac{\\left|\\Lambda_{0}^{-1}\\right|^{-1/2}}{(2\\pi)^{(T+d)/2}\\sigma^{T}\\sigma^{d}}\\exp\\left(-\\frac{1}{2\\sigma^{2}}\\sum_{i=1}^{T}\\left(Y_{i}-w^{\\top}\\psi\\left(X_{i}\\right)\\right)^{2}-\\frac{\\left\\|w\\right\\|_{\\Lambda_{0}}^{2}}{2\\sigma^{2}}\\right)d w\\\\ =\\frac{\\left|\\Lambda_{0}^{-1}\\Lambda_{T}\\right|^{-1/2}}{\\left(2\\pi\\right)^{T/2}\\sigma^{T}}\\exp\\left(-\\frac{1}{2\\sigma^{2}}\\sum_{i=1}^{T}\\left(Y_{i}-\\hat{w}\\left(\\mathcal{S}_{T}\\right)^{\\top}\\psi(X_{i})\\right)^{2}-\\frac{\\left\\|\\hat{w}\\left(\\mathcal{S}_{T}\\right)\\right\\|_{\\Lambda_{0}}^{2}}{2\\sigma^{2}}\\right),\\\\ \\end{array}\n\\]\nwhere the last equation used Gaussian integration with decomposition (15.4). That is,\n\\[\n\\begin{array}{l}-\\ln\\mathbb{E}_{w\\sim p_{0}}\\prod_{i=1}^{T}p(Y_{i}|w,X_{i})=T\\ln(\\sqrt{2\\pi}\\sigma)+\\frac{1}{2}\\ln\\left|\\Lambda_{0}^{-1}\\Lambda_{T}\\right|\\\\ +\\frac{1}{2\\sigma^{2}}\\sum_{i=1}^{T}(Y_{i}-\\hat{w}(\\mathcal{S}_{T})^{\\top}\\psi(X_{i}))^{2}+\\frac{\\|\\hat{w}(\\mathcal{S}_{T})\\|_{\\Lambda_{0}}^{2}}{2\\sigma^{2}}.\\\\ \\end{array}\n\\]\nMoreover, from Proposition 15.5, we have\n\\[\n\\begin{array}{l}\\sum_{i=1}^{T}-\\ln p(Y_{t}|\\hat{w}(\\mathcal{S}_{t-1}),X_{t})\\\\ =\\sum_{t=1}^{T}\\left[\\frac{\\left(Y_{t}-\\hat{w}\\left(\\mathcal{S}_{t-1}\\right)^{\\top}\\psi\\left(X_{t}\\right)\\right)^{2}}{2\\sigma^{2}b_{t}}+\\frac{1}{2}\\ln(b_{t})+\\ln(\\sqrt{2\\pi}\\sigma)\\right].\\\\ \\end{array}\n\\]\nThe desired result now follows from Theorem 15.3.", "context": [{"id": "ch15:proposition:15_5", "name": "proposition 15.5", "statement": "Consider probability model\n\\[\np(y|w,x)=N(w^{\\top}\\psi(x),\\sigma^{2}),\n\\]\nwith prior\n\\[\np_{0}(w)=N(0,\\sigma^{2}\\Lambda_{0}^{-1}).\n\\]\nThen given \\(\\mathcal{S}_n=\\{(X_1,Y_1),\\ldots,(X_n,Y_n)\\}\\) , we have\n\\[\np(w|\\mathcal{S}_{n})=N(\\hat{w}(\\mathcal{S}_{n}),\\sigma^{2}\\hat{\\Lambda}(\\mathcal{S}_{n})^{-1}),\n\\]\nwhere \\(\\hat{w} (S_n)\\) is given by (15.3) and\n\\[\n\\hat{\\Lambda}\\left(\\mathcal{S}_{n}\\right)=\\sum_{i=1}^{n}\\psi\\left(X_{i}\\right)\\psi\\left(X_{i}\\right)^{\\top}+\\Lambda_{0}.\n\\]\nGiven \\( x \\), the posterior distribution of \\( y \\) is\n\\[\n\\hat{p}(y|x,\\mathcal{S}_{n})=N\\left(\\hat{w}(\\mathcal{S}_{n})^{\\top}\\psi(x),\\sigma^{2}+\\sigma^{2}\\psi(x)^{\\top}\\hat{\\Lambda}(\\mathcal{S}_{n})^{-1}\\psi(x)\\right).\n\\]"}, {"id": "ch15:theorem:15_3", "name": "theorem 15.3", "statement": "We have\n\\[\n\\begin{array}{l}-\\sum_{t=1}^{T}\\ln\\hat{p}\\left(Y_{t}\\mid X_{t},\\mathcal{S}_{t-1}\\right)= -\\ln\\mathbb{E}_{w\\sim p_{0}}\\prod_{t=1}^{T}p\\left(Y_{t}\\mid w,X_{t}\\right)\\\\ =\\inf_{q\\in\\Delta(\\Omega)}\\left[-\\mathbb{E}_{w\\sim q}\\sum_{t=1}^{T}\\ln p(Y_{t}|w,X_{t})+\\mathbb{E}_{w\\sim q}\\ln\\frac{q(w)}{p_{0}(w)}\\right],\\\\ \\end{array}\n\\]\nwhere \\(\\Delta (\\Omega)\\) is the set of probability distributions over \\(\\Omega\\)"}, {"id": "ch15:definition:15_3", "name": "equation (15.3)", "statement": "Let \\(\\Lambda_0\\) be a symmetric positive definite regularizer and let \\(\\psi\\) be a feature map. Given \\(\\mathcal{S}_n = \\{(X_1,Y_1),\\ldots,(X_n,Y_n)\\}\\), define\n\\[\n\\hat{\\Lambda}(\\mathcal{S}_{n})=\\Lambda_{0}+\\sum_{i=1}^{n}\\psi(X_{i})\\psi(X_{i})^{\\top}\n\\]\nand the ridge regression estimator\n\\[\n\\hat{w}(\\mathcal{S}_{n})=\\hat{\\Lambda}(\\mathcal{S}_{n})^{-1}\\sum_{i=1}^{n}\\psi(X_{i})Y_{i}.\\tag{15.3}\n\\]\nEquivalently, \\(\\hat{w}(\\mathcal{S}_{n})\\) minimizes\n\\[\n\\sum_{i=1}^{n}(w^{\\top}\\psi(X_{i})-Y_{i})^{2}+\\|w\\|_{\\Lambda_{0}}^{2}.\n\\]"}], "lean": "import Mathlib\n\nopen Matrix Finset\n\nnamespace GraduateLevel\n\ndef lambdaHat {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (n : ℕ) : Matrix (Fin d) (Fin d) ℝ :=\n Λ₀ + ∑ i ∈ Finset.range n, Matrix.vecMulVec (ψ i) (ψ i)\n\nnoncomputable def ridgeEst {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (n : ℕ) : Fin d → ℝ :=\n (lambdaHat Λ₀ ψ n)⁻¹ *ᵥ (∑ i ∈ Finset.range n, Y i • ψ i)\n\nnoncomputable def bStep {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (t : ℕ) : ℝ :=\n 1 + (ψ t) ⬝ᵥ ((lambdaHat Λ₀ ψ t)⁻¹ *ᵥ (ψ t))\n\ndef batchObjective {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (T : ℕ) (w : Fin d → ℝ) : ℝ :=\n (∑ t ∈ Finset.range T, (Y t - w ⬝ᵥ (ψ t)) ^ 2) + w ⬝ᵥ (Λ₀ *ᵥ w)\n\ntheorem ch15_theorem_15_6 {d : ℕ}\n (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ)\n (σ : ℝ) (hσ : 0 ≤ σ) (T : ℕ) :\n (∑ t ∈ Finset.range T,\n ((Y t - (ridgeEst Λ₀ ψ Y t) ⬝ᵥ (ψ t)) ^ 2 / bStep Λ₀ ψ t\n + σ ^ 2 * Real.log (bStep Λ₀ ψ t)))\n = (⨅ w : Fin d → ℝ, batchObjective Λ₀ ψ Y T w)\n + σ ^ 2 * Real.log ((Λ₀⁻¹ * lambdaHat Λ₀ ψ T).det) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen Matrix Finset\n\nnamespace GraduateLevel\n\ndef lambdaHat {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (n : ℕ) : Matrix (Fin d) (Fin d) ℝ :=\n Λ₀ + ∑ i ∈ Finset.range n, Matrix.vecMulVec (ψ i) (ψ i)\n\nnoncomputable def ridgeEst {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (n : ℕ) : Fin d → ℝ :=\n (lambdaHat Λ₀ ψ n)⁻¹ *ᵥ (∑ i ∈ Finset.range n, Y i • ψ i)\n\nnoncomputable def bStep {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (t : ℕ) : ℝ :=\n 1 + (ψ t) ⬝ᵥ ((lambdaHat Λ₀ ψ t)⁻¹ *ᵥ (ψ t))\n\ndef batchObjective {d : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (T : ℕ) (w : Fin d → ℝ) : ℝ :=\n (∑ t ∈ Finset.range T, (Y t - w ⬝ᵥ (ψ t)) ^ 2) + w ⬝ᵥ (Λ₀ *ᵥ w)\n\nsection Aux\n\nvariable {d : ℕ}\n\nprivate lemma transp_eq {M : Matrix (Fin d) (Fin d) ℝ} (h : M.IsHermitian) : Mᵀ = M := by\n ext i j\n have := congrFun (congrFun h i) j\n simpa using this\n\nprivate lemma dot_mulVec_symm {M : Matrix (Fin d) (Fin d) ℝ} (hM : Mᵀ = M) (x y : Fin d → ℝ) :\n x ⬝ᵥ (M *ᵥ y) = y ⬝ᵥ (M *ᵥ x) := by\n rw [dotProduct_mulVec, ← Matrix.mulVec_transpose, hM, dotProduct_comm]\n\nprivate lemma vmv_mulVec (x v : Fin d → ℝ) :\n Matrix.vecMulVec x x *ᵥ v = (x ⬝ᵥ v) • x := by\n ext i\n simp only [Matrix.mulVec, dotProduct, Matrix.vecMulVec_apply, Pi.smul_apply, smul_eq_mul,\n Finset.sum_mul]\n exact Finset.sum_congr rfl fun j _ => by ring\n\nprivate lemma lambdaHat_succ (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (ψ : ℕ → (Fin d → ℝ)) (n : ℕ) :\n lambdaHat Λ₀ ψ (n + 1) = lambdaHat Λ₀ ψ n + Matrix.vecMulVec (ψ n) (ψ n) := by\n simp [lambdaHat, Finset.sum_range_succ, add_assoc]\n\nprivate lemma vmv_posSemidef (x : Fin d → ℝ) : (Matrix.vecMulVec x x).PosSemidef := by\n have := Matrix.posSemidef_vecMulVec_self_star (R := ℝ) x\n simpa using this\n\nprivate lemma lambdaHat_posDef {Λ₀ : Matrix (Fin d) (Fin d) ℝ} (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) : ∀ n, (lambdaHat Λ₀ ψ n).PosDef := by\n intro n\n induction n with\n | zero => simpa [lambdaHat] using hΛ₀\n | succ n ih =>\n rw [lambdaHat_succ]\n exact ih.add_posSemidef (vmv_posSemidef (ψ n))\n\nprivate lemma isUnit_det_of_posDef {M : Matrix (Fin d) (Fin d) ℝ} (hM : M.PosDef) :\n IsUnit M.det := (Matrix.isUnit_iff_isUnit_det M).mp hM.isUnit\n\nprivate lemma mulVec_inv_mulVec {Λ : Matrix (Fin d) (Fin d) ℝ} (hΛ : Λ.PosDef) (p : Fin d → ℝ) :\n Λ *ᵥ (Λ⁻¹ *ᵥ p) = p := by\n rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ (isUnit_det_of_posDef hΛ), Matrix.one_mulVec]\n\nprivate lemma quad_nonneg {Λ : Matrix (Fin d) (Fin d) ℝ} (hΛ : Λ.PosDef) (x : Fin d → ℝ) :\n 0 ≤ x ⬝ᵥ (Λ *ᵥ x) := by\n have := hΛ.posSemidef.dotProduct_mulVec_nonneg x\n simpa using this\n\nprivate lemma quad_inv_nonneg {Λ : Matrix (Fin d) (Fin d) ℝ} (hΛ : Λ.PosDef) (p : Fin d → ℝ) :\n 0 ≤ p ⬝ᵥ (Λ⁻¹ *ᵥ p) := by\n have h := quad_nonneg hΛ (Λ⁻¹ *ᵥ p)\n rw [mulVec_inv_mulVec hΛ] at h\n rwa [dotProduct_comm]\n\nprivate lemma bStep_pos {Λ₀ : Matrix (Fin d) (Fin d) ℝ} (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (t : ℕ) : 0 < bStep Λ₀ ψ t := by\n have := quad_inv_nonneg (lambdaHat_posDef hΛ₀ ψ t) (ψ t)\n unfold bStep\n linarith\n\n/-- Completing the square for the rank-one update. -/\nprivate lemma key_step {Λ : Matrix (Fin d) (Fin d) ℝ} (hΛ : Λ.PosDef) (p : Fin d → ℝ)\n (c : ℝ) (u : Fin d → ℝ) :\n u ⬝ᵥ (Λ *ᵥ u) + (c - u ⬝ᵥ p) ^ 2\n = c ^ 2 / (1 + p ⬝ᵥ (Λ⁻¹ *ᵥ p))\n + (u - (c / (1 + p ⬝ᵥ (Λ⁻¹ *ᵥ p))) • (Λ⁻¹ *ᵥ p)) ⬝ᵥ\n ((Λ + Matrix.vecMulVec p p) *ᵥ\n (u - (c / (1 + p ⬝ᵥ (Λ⁻¹ *ᵥ p))) • (Λ⁻¹ *ᵥ p))) := by\n set z : Fin d → ℝ := Λ⁻¹ *ᵥ p with hzdef\n have hz : Λ *ᵥ z = p := mulVec_inv_mulVec hΛ p\n have hsym : Λᵀ = Λ := transp_eq hΛ.isHermitian\n set k : ℝ := p ⬝ᵥ z with hkdef\n have hk : 0 ≤ k := quad_inv_nonneg hΛ p\n have hβ : (1 : ℝ) + k ≠ 0 := by positivity\n have hzp : z ⬝ᵥ p = k := by rw [hkdef, dotProduct_comm]\n have hpu : p ⬝ᵥ u = u ⬝ᵥ p := dotProduct_comm _ _\n have hzΛu : z ⬝ᵥ (Λ *ᵥ u) = u ⬝ᵥ p := by\n rw [dot_mulVec_symm hsym, hz]\n have hexp : ∀ t : ℝ, (u - t • z) ⬝ᵥ ((Λ + Matrix.vecMulVec p p) *ᵥ (u - t • z))\n = u ⬝ᵥ (Λ *ᵥ u) - 2 * t * (u ⬝ᵥ p) + t ^ 2 * k + ((u ⬝ᵥ p) - t * k) ^ 2 := by\n intro t\n rw [Matrix.add_mulVec, vmv_mulVec]\n simp only [Matrix.mulVec_sub, Matrix.mulVec_smul, hz, dotProduct_add, dotProduct_sub,\n sub_dotProduct, dotProduct_smul, smul_dotProduct, smul_eq_mul, hzp, hpu, hzΛu, hkdef]\n ring\n rw [hexp]\n field_simp\n ring\n\nprivate lemma ridgeEst_mulVec {Λ₀ : Matrix (Fin d) (Fin d) ℝ} (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (n : ℕ) :\n lambdaHat Λ₀ ψ n *ᵥ ridgeEst Λ₀ ψ Y n = ∑ i ∈ Finset.range n, Y i • ψ i :=\n mulVec_inv_mulVec (lambdaHat_posDef hΛ₀ ψ n) _\n\nprivate lemma ridgeEst_succ {Λ₀ : Matrix (Fin d) (Fin d) ℝ} (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (n : ℕ) :\n ridgeEst Λ₀ ψ Y (n + 1)\n = ridgeEst Λ₀ ψ Y n\n + ((Y n - (ridgeEst Λ₀ ψ Y n) ⬝ᵥ ψ n) / bStep Λ₀ ψ n) •\n ((lambdaHat Λ₀ ψ n)⁻¹ *ᵥ ψ n) := by\n have hΛ : (lambdaHat Λ₀ ψ n).PosDef := lambdaHat_posDef hΛ₀ ψ n\n have hz : lambdaHat Λ₀ ψ n *ᵥ ((lambdaHat Λ₀ ψ n)⁻¹ *ᵥ ψ n) = ψ n :=\n mulVec_inv_mulVec hΛ (ψ n)\n have hb : bStep Λ₀ ψ n = 1 + ψ n ⬝ᵥ ((lambdaHat Λ₀ ψ n)⁻¹ *ᵥ ψ n) := rfl\n have hbne : bStep Λ₀ ψ n ≠ 0 := (bStep_pos hΛ₀ ψ n).ne'\n have hbne' : (1 : ℝ) + ψ n ⬝ᵥ ((lambdaHat Λ₀ ψ n)⁻¹ *ᵥ ψ n) ≠ 0 := by rw [← hb]; exact hbne\n have hΛŵ : lambdaHat Λ₀ ψ n *ᵥ ridgeEst Λ₀ ψ Y n = ∑ i ∈ Finset.range n, Y i • ψ i :=\n ridgeEst_mulVec hΛ₀ ψ Y n\n have hmul : lambdaHat Λ₀ ψ (n + 1) *ᵥ\n (ridgeEst Λ₀ ψ Y n + ((Y n - (ridgeEst Λ₀ ψ Y n) ⬝ᵥ ψ n) / bStep Λ₀ ψ n) •\n ((lambdaHat Λ₀ ψ n)⁻¹ *ᵥ ψ n))\n = ∑ i ∈ Finset.range (n + 1), Y i • ψ i := by\n rw [lambdaHat_succ, Matrix.add_mulVec, vmv_mulVec, Finset.sum_range_succ]\n simp only [Matrix.mulVec_add, Matrix.mulVec_smul, hz, hΛŵ, dotProduct_add, dotProduct_smul,\n smul_eq_mul]\n rw [add_assoc, ← add_smul, add_right_inj]\n congr 1\n rw [dotProduct_comm (ψ n) (ridgeEst Λ₀ ψ Y n), hb]\n field_simp\n ring\n have := congrArg (fun v => (lambdaHat Λ₀ ψ (n + 1))⁻¹ *ᵥ v) hmul\n simp only at this\n rw [Matrix.mulVec_mulVec,\n Matrix.nonsing_inv_mul _ (isUnit_det_of_posDef (lambdaHat_posDef hΛ₀ ψ (n + 1))),\n Matrix.one_mulVec] at this\n rw [ridgeEst, ← this]\n\nprivate lemma batchObjective_succ (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (ψ : ℕ → (Fin d → ℝ))\n (Y : ℕ → ℝ) (T : ℕ) (w : Fin d → ℝ) :\n batchObjective Λ₀ ψ Y (T + 1) w\n = batchObjective Λ₀ ψ Y T w + (Y T - w ⬝ᵥ ψ T) ^ 2 := by\n simp [batchObjective, Finset.sum_range_succ]\n ring\n\nprivate lemma batch_decomp {Λ₀ : Matrix (Fin d) (Fin d) ℝ} (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (T : ℕ) (w : Fin d → ℝ) :\n batchObjective Λ₀ ψ Y T w\n = (∑ t ∈ Finset.range T, (Y t - (ridgeEst Λ₀ ψ Y t) ⬝ᵥ (ψ t)) ^ 2 / bStep Λ₀ ψ t)\n + (w - ridgeEst Λ₀ ψ Y T) ⬝ᵥ\n (lambdaHat Λ₀ ψ T *ᵥ (w - ridgeEst Λ₀ ψ Y T)) := by\n induction T with\n | zero =>\n simp [batchObjective, ridgeEst, lambdaHat]\n | succ T ih =>\n rw [batchObjective_succ, ih, Finset.sum_range_succ, lambdaHat_succ,\n ridgeEst_succ hΛ₀ ψ Y T]\n set Λ := lambdaHat Λ₀ ψ T with hΛdef\n have hΛ : Λ.PosDef := lambdaHat_posDef hΛ₀ ψ T\n set ŵ := ridgeEst Λ₀ ψ Y T with hŵdef\n set u : Fin d → ℝ := w - ŵ with hudef\n have hup : Y T - w ⬝ᵥ ψ T = (Y T - ŵ ⬝ᵥ ψ T) - u ⬝ᵥ ψ T := by\n rw [hudef, sub_dotProduct]; ring\n have hsub : w - (ŵ + ((Y T - ŵ ⬝ᵥ ψ T) / bStep Λ₀ ψ T) • (Λ⁻¹ *ᵥ ψ T))\n = u - ((Y T - ŵ ⬝ᵥ ψ T) / (1 + ψ T ⬝ᵥ (Λ⁻¹ *ᵥ ψ T))) • (Λ⁻¹ *ᵥ ψ T) := by\n rw [hudef]\n rw [show bStep Λ₀ ψ T = 1 + ψ T ⬝ᵥ (Λ⁻¹ *ᵥ ψ T) from rfl]\n abel\n rw [hup, hsub, show bStep Λ₀ ψ T = 1 + ψ T ⬝ᵥ (Λ⁻¹ *ᵥ ψ T) from rfl]\n linarith [key_step hΛ (ψ T) (Y T - ŵ ⬝ᵥ ψ T) u]\n\nprivate lemma inf_batch {Λ₀ : Matrix (Fin d) (Fin d) ℝ} (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ) (T : ℕ) :\n (⨅ w : Fin d → ℝ, batchObjective Λ₀ ψ Y T w)\n = ∑ t ∈ Finset.range T, (Y t - (ridgeEst Λ₀ ψ Y t) ⬝ᵥ (ψ t)) ^ 2 / bStep Λ₀ ψ t := by\n set F := ∑ t ∈ Finset.range T, (Y t - (ridgeEst Λ₀ ψ Y t) ⬝ᵥ (ψ t)) ^ 2 / bStep Λ₀ ψ t with hF\n have hge : ∀ w : Fin d → ℝ, F ≤ batchObjective Λ₀ ψ Y T w := by\n intro w\n rw [batch_decomp hΛ₀ ψ Y T w]\n have := quad_nonneg (lambdaHat_posDef hΛ₀ ψ T) (w - ridgeEst Λ₀ ψ Y T)\n linarith\n have hbdd : BddBelow (Set.range fun w : Fin d → ℝ => batchObjective Λ₀ ψ Y T w) := by\n refine ⟨F, ?_⟩\n rintro x ⟨w, rfl⟩\n exact hge w\n refine le_antisymm ?_ (le_ciInf hge)\n have h1 := ciInf_le hbdd (ridgeEst Λ₀ ψ Y T)\n have h2 : batchObjective Λ₀ ψ Y T (ridgeEst Λ₀ ψ Y T) = F := by\n rw [batch_decomp hΛ₀ ψ Y T, hF]\n simp\n linarith [h1, h2.le, h2.ge]\n\nprivate lemma det_lambdaHat {Λ₀ : Matrix (Fin d) (Fin d) ℝ} (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (T : ℕ) :\n (lambdaHat Λ₀ ψ T).det = Λ₀.det * ∏ t ∈ Finset.range T, bStep Λ₀ ψ t := by\n induction T with\n | zero => simp [lambdaHat]\n | succ T ih =>\n rw [lambdaHat_succ, Finset.prod_range_succ]\n have hΛ : (lambdaHat Λ₀ ψ T).PosDef := lambdaHat_posDef hΛ₀ ψ T\n have hu : IsUnit (lambdaHat Λ₀ ψ T).det := isUnit_det_of_posDef hΛ\n have hvm : Matrix.vecMulVec (ψ T) (ψ T)\n = Matrix.replicateCol (Fin 1) (ψ T) * Matrix.replicateRow (Fin 1) (ψ T) :=\n Matrix.vecMulVec_eq (Fin 1) _ _\n have hdet : (lambdaHat Λ₀ ψ T + Matrix.vecMulVec (ψ T) (ψ T)).det\n = (lambdaHat Λ₀ ψ T).det * bStep Λ₀ ψ T := by\n have hexp : lambdaHat Λ₀ ψ T + Matrix.vecMulVec (ψ T) (ψ T)\n = lambdaHat Λ₀ ψ T *\n (1 + Matrix.replicateCol (Fin 1) ((lambdaHat Λ₀ ψ T)⁻¹ *ᵥ ψ T) *\n Matrix.replicateRow (Fin 1) (ψ T)) := by\n rw [Matrix.mul_add, Matrix.mul_one, ← Matrix.mul_assoc,\n ← Matrix.replicateCol_mulVec, mulVec_inv_mulVec hΛ, ← hvm]\n rw [hexp, Matrix.det_mul, Matrix.det_one_add_replicateCol_mul_replicateRow]\n rfl\n rw [hdet, ih]\n ring\n\nend Aux\n\ntheorem ch15_theorem_15_6 {d : ℕ}\n (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (hΛ₀ : Λ₀.PosDef)\n (ψ : ℕ → (Fin d → ℝ)) (Y : ℕ → ℝ)\n (σ : ℝ) (hσ : 0 ≤ σ) (T : ℕ) :\n (∑ t ∈ Finset.range T,\n ((Y t - (ridgeEst Λ₀ ψ Y t) ⬝ᵥ (ψ t)) ^ 2 / bStep Λ₀ ψ t\n + σ ^ 2 * Real.log (bStep Λ₀ ψ t)))\n = (⨅ w : Fin d → ℝ, batchObjective Λ₀ ψ Y T w)\n + σ ^ 2 * Real.log ((Λ₀⁻¹ * lambdaHat Λ₀ ψ T).det) := by\n have hdet0 : Λ₀.det ≠ 0 := by\n have := isUnit_det_of_posDef hΛ₀\n exact this.ne_zero\n have hlog : Real.log ((Λ₀⁻¹ * lambdaHat Λ₀ ψ T).det)\n = ∑ t ∈ Finset.range T, Real.log (bStep Λ₀ ψ t) := by\n rw [Matrix.det_mul, Matrix.det_nonsing_inv, det_lambdaHat hΛ₀ ψ T]\n rw [Ring.inverse_eq_inv]\n rw [show (Λ₀.det)⁻¹ * (Λ₀.det * ∏ t ∈ Finset.range T, bStep Λ₀ ψ t)\n = ∏ t ∈ Finset.range T, bStep Λ₀ ψ t by field_simp]\n rw [Real.log_prod]\n intro t _\n exact (bStep_pos hΛ₀ ψ t).ne'\n rw [inf_batch hΛ₀ ψ Y T, hlog, Finset.sum_add_distrib, Finset.mul_sum]\n\nend GraduateLevel\n"} +{"id": "ch15_proposition_15_5", "source": "Graduate-level", "targets": [{"label": "ch15_proposition_15_5", "decls": ["ch15_proposition_15_5"], "statement": "Consider probability model\n\\[\np(y|w,x)=N(w^{\\top}\\psi(x),\\sigma^{2}),\n\\]\nwith prior\n\\[\np_{0}(w)=N(0,\\sigma^{2}\\Lambda_{0}^{-1}).\n\\]\nThen given \\(\\mathcal{S}_n=\\{(X_1,Y_1),\\ldots,(X_n,Y_n)\\}\\) , we have\n\\[\np(w|\\mathcal{S}_{n})=N(\\hat{w}(\\mathcal{S}_{n}),\\sigma^{2}\\hat{\\Lambda}(\\mathcal{S}_{n})^{-1}),\n\\]\nwhere \\(\\hat{w} (S_n)\\) is given by (15.3) and\n\\[\n\\hat{\\Lambda}\\left(\\mathcal{S}_{n}\\right)=\\sum_{i=1}^{n}\\psi\\left(X_{i}\\right)\\psi\\left(X_{i}\\right)^{\\top}+\\Lambda_{0}.\n\\]\nGiven \\( x \\), the posterior distribution of \\( y \\) is\n\\[\n\\hat{p}(y|x,\\mathcal{S}_{n})=N\\left(\\hat{w}(\\mathcal{S}_{n})^{\\top}\\psi(x),\\sigma^{2}+\\sigma^{2}\\psi(x)^{\\top}\\hat{\\Lambda}(\\mathcal{S}_{n})^{-1}\\psi(x)\\right).\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Statistical Estimation & Minimax Theory"}], "nl_proof": "It is clear that\n\\[\np(w|\\mathcal{S}_{n})\\propto\\exp\\left(-\\sum_{i=1}^{n}\\frac{(w^{\\top}\\psi(X_{i})-Y_{i})^{2}}{2\\sigma^{2}}-\\frac{\\|w\\|_{\\Lambda_{0}}^{2}}{2\\sigma^{2}}\\right).\n\\]\nNote that (15.3) implies that\n\\[\n\\begin{array}{l}\\sum_{i=1}^{n}\\frac{\\left(w^{\\top}\\psi\\left(X_{i}\\right)-Y_{i}\\right)^{2}}{2\\sigma^{2}}+\\frac{\\|w\\|_{\\Lambda_{0}}^{2}}{2\\sigma^{2}}\\\\ =\\sum_{i=1}^{n}\\frac{\\left(\\hat{w}^{\\top}\\psi\\left(X_{i}\\right)-Y_{i}\\right)^{2}}{2\\sigma^{2}}+\\frac{\\|\\hat{w}\\|_{\\Lambda_{0}}^{2}}{2\\sigma^{2}}+\\frac{1}{2\\sigma^{2}}(w-\\hat{w})^{\\top}\\hat{\\Lambda}\\left(S_{n}\\right)(w-\\hat{w}).\\tag{15.4}\\\\ \\end{array}\n\\]\nThis implies the first desired result. Moreover, given \\( x \\), and let the random variable \\( u = w^{\\top}\\psi (x) \\) with \\( w\\sim p(w|S_n) \\), we have\n\\[\nu|x,\\mathcal{S}_{n}\\sim N\\left(\\hat{w}^{\\top}\\psi(x),\\sigma^{2}\\psi(x)^{\\top}\\hat{\\Lambda}(\\mathcal{S}_{n})^{-1}\\psi(x)\\right).\n\\]\nSince in posterior distribution, the observation \\( y|u \\sim u + \\epsilon \\) with \\( \\epsilon \\sim N(0, \\sigma^2) \\), we know that\n\\[\ny|x,\\mathcal{S}_{n}\\sim N(\\hat{w}^{\\top}\\psi(x),\\sigma^{2}\\psi(x)^{\\top}\\hat{\\Lambda}^{-1}\\psi(x)+\\sigma^{2}).\n\\]\nThis implies the desired result.", "context": [{"id": "ch15:equation:15_3", "name": "equation (15.3)", "statement": "The ridge regression method defines, for each \\(n\\),\n\\[\n\\hat{w}(\\mathcal{S}_{n})=\\arg\\min_{w}\\left[\\sum_{i=1}^{n}(Y_{i}-w^{\\top}\\psi(X_{i}))^{2}+\\|w\\|_{\\Lambda_{0}}^{2}\\right].\n\\]\nEquivalently,\n\\[\n\\hat{w}(\\mathcal{S}_{n})=\\Lambda_{n}^{-1}\\sum_{i=1}^{n}\\psi(X_{i})Y_{i},\\quad\\Lambda_{n}=\\Lambda_{0}+\\sum_{s=1}^{n}\\psi(X_{s})\\psi(X_{s})^{\\top}.\n\\]"}, {"id": "ch15:theorem:15_3", "name": "theorem 15.3", "statement": "We have\n\\[\n\\begin{array}{l}-\\sum_{t=1}^{T}\\ln\\hat{p}\\left(Y_{t}\\mid X_{t},\\mathcal{S}_{t-1}\\right)= -\\ln\\mathbb{E}_{w\\sim p_{0}}\\prod_{t=1}^{T}p\\left(Y_{t}\\mid w,X_{t}\\right)\\\\ =\\inf_{q\\in\\Delta(\\Omega)}\\left[-\\mathbb{E}_{w\\sim q}\\sum_{t=1}^{T}\\ln p(Y_{t}|w,X_{t})+\\mathbb{E}_{w\\sim q}\\ln\\frac{q(w)}{p_{0}(w)}\\right],\\\\ \\end{array}\n\\]\nwhere \\(\\Delta (\\Omega)\\) is the set of probability distributions over \\(\\Omega\\)"}, {"id": "ch15_proposition_15_5:fix:1", "name": "Equations (15.1)-(15.2) (posterior and Bayesian posterior averaging estimator)", "statement": "In the Bayesian setting, the optimal statistical estimation of posterior density for log-loss is the Bayesian posterior averaging estimator. Here we consider a prior \\(p_{0}(w)\\) on \\(\\Omega\\). Given the training data \\(\\mathcal{S}_n = \\{Z_1, \\ldots, Z_n\\}\\), the posterior distribution is\n\\[\np(w|\\mathcal{S}_{n})=\\frac{\\prod_{i=1}^{n}p(Y_{i}|w,X_{i})p_{0}(w)}{\\int_{\\Omega}\\prod_{i=1}^{n}p(Y_{i}|w^{\\prime},X_{i})p_{0}(w^{\\prime})d w^{\\prime}}.\\tag{15.1}\n\\]\nUnlike ERM, the Bayesian posterior averaging method does not use \\(p(y|\\hat{w}, x)\\) for a specific \\(\\hat{w} \\in \\Omega\\) that is estimated from the training data, but instead use the averaged probability estimate over the posterior as follows:\n\\[\n\\hat{p}(y|x,\\mathcal{S}_{n})=\\int_{\\Omega}p(y|w,x)p(w|\\mathcal{S}_{n})d w.\\tag{15.2}\n\\]"}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Matrix\n\nnamespace GraduateLevel\n\nnoncomputable def postPrec {d n : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) : Matrix (Fin d) (Fin d) ℝ :=\n Λ₀ + ∑ i : Fin n, vecMulVec (ψ i) (ψ i)\n\nnoncomputable def postMean {d n : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ) : Fin d → ℝ :=\n (postPrec Λ₀ ψ)⁻¹.mulVec (∑ i : Fin n, (Y i) • (ψ i))\n\nnoncomputable def postUnnorm {d n : ℕ} (σ : ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ)\n (prior : Measure (Fin d → ℝ)) : Measure (Fin d → ℝ) :=\n prior.withDensity (fun w => ENNReal.ofReal\n (∏ i : Fin n, gaussianPDFReal (w ⬝ᵥ ψ i) ((σ^2).toNNReal) (Y i)))\n\nnoncomputable def posteriorMeasure {d n : ℕ} (σ : ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ)\n (prior : Measure (Fin d → ℝ)) : Measure (Fin d → ℝ) :=\n ((postUnnorm σ ψ Y prior) Set.univ)⁻¹ • postUnnorm σ ψ Y prior\n\nnoncomputable def predictiveMeasure {d n : ℕ} (σ : ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ) (φ : Fin d → ℝ)\n (prior : Measure (Fin d → ℝ)) : Measure ℝ :=\n (posteriorMeasure σ ψ Y prior).bind (fun w => gaussianReal (w ⬝ᵥ φ) ((σ^2).toNNReal))\n\ntheorem ch15_proposition_15_5\n {d n : ℕ} (σ : ℝ) (hσ : 0 < σ)\n (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (hΛ₀ : Λ₀.PosDef)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ)\n (φ : Fin d → ℝ)\n (prior : Measure (Fin d → ℝ))\n (hprior : ∀ c : Fin d → ℝ,\n prior.map (fun w => c ⬝ᵥ w)\n = gaussianReal 0 ((σ^2 * (c ⬝ᵥ Λ₀⁻¹.mulVec c)).toNNReal)) :\n IsProbabilityMeasure (posteriorMeasure σ ψ Y prior)\n ∧ (∀ c : Fin d → ℝ,\n (posteriorMeasure σ ψ Y prior).map (fun w => c ⬝ᵥ w)\n = gaussianReal (c ⬝ᵥ postMean Λ₀ ψ Y)\n ((σ^2 * (c ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec c)).toNNReal))\n ∧ predictiveMeasure σ ψ Y φ prior\n = gaussianReal (postMean Λ₀ ψ Y ⬝ᵥ φ)\n ((σ^2 + σ^2 * (φ ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec φ)).toNNReal) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Matrix\nopen scoped ENNReal NNReal\n\nnamespace GraduateLevel\n\nprivate lemma gaussianPDFReal_mul_likelihood\n (m y z : ℝ) (v s : ℝ≥0) (hv : v ≠ 0) (hs : s ≠ 0) :\n gaussianPDFReal m (s * v) z * gaussianPDFReal z v y =\n gaussianPDFReal m ((1 + s) * v) y *\n gaussianPDFReal ((m + (s : ℝ) * y) / (1 + (s : ℝ))) ((s / (1 + s)) * v) z := by\n unfold gaussianPDFReal\n have hvR : (v : ℝ) ≠ 0 := by exact_mod_cast hv\n have hsR : (s : ℝ) ≠ 0 := by exact_mod_cast hs\n have h1sR : (1 + (s : ℝ)) ≠ 0 := by positivity\n have hsvR : ((s * v : ℝ≥0) : ℝ) ≠ 0 := by positivity\n have hpostR : (((s / (1 + s)) * v : ℝ≥0) : ℝ) ≠ 0 := by positivity\n have hevidenceR : (((1 + s) * v : ℝ≥0) : ℝ) ≠ 0 := by positivity\n conv_lhs => rw [mul_mul_mul_comm]\n conv_rhs => rw [mul_mul_mul_comm]\n rw [← Real.exp_add, ← Real.exp_add]\n congr 1\n · rw [show ((s * v : ℝ≥0) : ℝ) = (s : ℝ) * v by norm_num,\n show (((1 + s) * v : ℝ≥0) : ℝ) = (1 + (s : ℝ)) * v by norm_num,\n show (((s / (1 + s)) * v : ℝ≥0) : ℝ) =\n ((s : ℝ) / (1 + (s : ℝ))) * v by norm_num]\n rw [← _root_.mul_inv_rev, ← _root_.mul_inv_rev]\n congr 1\n rw [← Real.sqrt_mul (show 0 ≤ 2 * π * (v : ℝ) by positivity),\n ← Real.sqrt_mul (show 0 ≤ 2 * π * ((s : ℝ) / (1 + (s : ℝ)) * v) by positivity)]\n congr 1\n ring_nf\n calc\n π ^ 2 * (v : ℝ) ^ 2 * (s : ℝ) * 4 =\n π ^ 2 * (v : ℝ) ^ 2 * (s : ℝ) * 4 *\n ((1 + (s : ℝ)) * (1 + (s : ℝ))⁻¹) := by\n rw [mul_inv_cancel₀ h1sR, mul_one]\n _ = π ^ 2 * (v : ℝ) ^ 2 * (s : ℝ) * (1 + (s : ℝ))⁻¹ * 4 +\n π ^ 2 * (v : ℝ) ^ 2 * (s : ℝ) ^ 2 * (1 + (s : ℝ))⁻¹ * 4 := by\n ring1\n · push_cast\n congr 1\n field_simp [hvR, hsR, h1sR]\n ring1\n\nprivate lemma gaussianPDF_mul_likelihood\n (m y z : ℝ) (v s : ℝ≥0) (hv : v ≠ 0) (hs : s ≠ 0) :\n gaussianPDF m (s * v) z * gaussianPDF z v y =\n gaussianPDF m ((1 + s) * v) y *\n gaussianPDF ((m + (s : ℝ) * y) / (1 + (s : ℝ))) ((s / (1 + s)) * v) z := by\n unfold gaussianPDF\n rw [← ENNReal.ofReal_mul (gaussianPDFReal_nonneg m (s * v) z),\n gaussianPDFReal_mul_likelihood m y z v s hv hs,\n ENNReal.ofReal_mul (gaussianPDFReal_nonneg m ((1 + s) * v) y)]\n\nprivate lemma gaussianPDF_symm (m x : ℝ) (v : ℝ≥0) :\n gaussianPDF m v x = gaussianPDF x v m := by\n unfold gaussianPDF gaussianPDFReal\n congr 2\n congr 1\n ring1\n\nprivate lemma gaussianReal_withDensity_likelihood\n (m y : ℝ) (v s : ℝ≥0) (hv : v ≠ 0) (hs : s ≠ 0) :\n (gaussianReal m (s * v)).withDensity (fun z => gaussianPDF z v y) =\n gaussianPDF m ((1 + s) * v) y •\n gaussianReal ((m + (s : ℝ) * y) / (1 + (s : ℝ))) ((s / (1 + s)) * v) := by\n have hsv : s * v ≠ 0 := mul_ne_zero hs hv\n have hpost : s / (1 + s) * v ≠ 0 := by\n exact mul_ne_zero (div_ne_zero hs (by positivity)) hv\n have hlike : Measurable (fun z : ℝ => gaussianPDF z v y) := by\n simpa only [gaussianPDF_symm] using measurable_gaussianPDF y v\n rw [gaussianReal_of_var_ne_zero m hsv,\n gaussianReal_of_var_ne_zero _ hpost,\n ← withDensity_mul volume (measurable_gaussianPDF m (s * v))\n hlike,\n ← withDensity_smul _ (measurable_gaussianPDF _ _)]\n congr 1\n funext z\n simp only [Pi.mul_apply, Pi.smul_apply, smul_eq_mul]\n exact gaussianPDF_mul_likelihood m y z v s hv hs\n\nprivate lemma map_prod_eq_gaussian_prod_of_map_add\n {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ]\n (X Z : Ω → ℝ) (hX : Measurable X) (hZ : Measurable Z)\n (mX mZ : ℝ) (vX vZ : ℝ≥0)\n (hadd : ∀ a b : ℝ,\n μ.map (fun w => a * X w + b * Z w) =\n gaussianReal (a * mX + b * mZ)\n (⟨a ^ 2, sq_nonneg a⟩ * vX + ⟨b ^ 2, sq_nonneg b⟩ * vZ)) :\n μ.map (fun w => (X w, Z w)) = (gaussianReal mX vX).prod (gaussianReal mZ vZ) := by\n rw [← charFun_eq_prod_iff]\n intro t\n let a : ℝ := (WithLp.ofLp t).1\n let b : ℝ := (WithLp.ofLp t).2\n calc\n charFun ((μ.map fun w => (X w, Z w)).map (WithLp.toLp 2)) t =\n charFun (μ.map (fun w => a * X w + b * Z w)) 1 := by\n simp only [charFun_apply]\n rw [integral_map (by fun_prop) (by fun_prop), integral_map (by fun_prop) (by fun_prop),\n integral_map (by fun_prop) (by fun_prop)]\n apply integral_congr_ae\n filter_upwards with w\n simp [WithLp.prod_inner_apply, RCLike.inner_apply, a, b, mul_comm]\n _ = charFun\n (gaussianReal (a * mX + b * mZ)\n (⟨a ^ 2, sq_nonneg a⟩ * vX + ⟨b ^ 2, sq_nonneg b⟩ * vZ)) 1 := by\n rw [hadd]\n _ = charFun (gaussianReal mX vX) a * charFun (gaussianReal mZ vZ) b := by\n simp_rw [charFun_gaussianReal]\n rw [← Complex.exp_add]\n congr 1\n push_cast\n ring1\n _ = charFun (gaussianReal mX vX) (WithLp.ofLp t).1 *\n charFun (gaussianReal mZ vZ) (WithLp.ofLp t).2 := by rfl\n\nprivate lemma posDef_bilinear_symm {d : ℕ}\n {A : Matrix (Fin d) (Fin d) ℝ} (hA : A.PosDef) (x y : Fin d → ℝ) :\n x ⬝ᵥ A.mulVec y = y ⬝ᵥ A.mulVec x := by\n have hAT : A.transpose = A := by\n rw [← conjTranspose_eq_transpose_of_trivial]\n exact hA.1.eq\n have hvec : x ᵥ* A = A.mulVec x := by\n calc\n x ᵥ* A = x ᵥ* A.transpose := by rw [hAT]\n _ = A.mulVec x := vecMul_transpose A x\n calc\n x ⬝ᵥ A.mulVec y = (x ᵥ* A) ⬝ᵥ y := dotProduct_mulVec x A y\n _ = A.mulVec x ⬝ᵥ y := by rw [hvec]\n _ = y ⬝ᵥ A.mulVec x := dotProduct_comm _ _\n\nprivate lemma rankOne_inv_mulVec {d : ℕ}\n (P : Matrix (Fin d) (Fin d) ℝ) (hP : P.PosDef)\n (ψ c : Fin d → ℝ) :\n (P + vecMulVec ψ ψ)⁻¹.mulVec c =\n P⁻¹.mulVec c -\n ((c ⬝ᵥ P⁻¹.mulVec ψ) / (1 + ψ ⬝ᵥ P⁻¹.mulVec ψ)) • P⁻¹.mulVec ψ := by\n let A := P⁻¹\n let r := c ⬝ᵥ A.mulVec ψ\n let s := ψ ⬝ᵥ A.mulVec ψ\n have hA : A.PosDef := hP.inv\n have hs : 0 ≤ s := hA.posSemidef.dotProduct_mulVec_nonneg ψ\n have hden : 1 + s ≠ 0 := by positivity\n have hP' : (P + vecMulVec ψ ψ).PosDef :=\n hP.add_posSemidef (by simpa using posSemidef_vecMulVec_self_star ψ)\n have hPdet : IsUnit P.det := P.isUnit_iff_isUnit_det.mp hP.isUnit\n have hP'det : IsUnit (P + vecMulVec ψ ψ).det :=\n (P + vecMulVec ψ ψ).isUnit_iff_isUnit_det.mp hP'.isUnit\n have hPA (x : Fin d → ℝ) : P.mulVec (A.mulVec x) = x := by\n rw [mulVec_mulVec, show P * A = 1 by exact P.mul_nonsing_inv hPdet]\n simp\n have hrank (x : Fin d → ℝ) :\n (vecMulVec ψ ψ).mulVec x = (ψ ⬝ᵥ x) • ψ := by\n simpa using vecMulVec_mulVec ψ ψ x\n have hsym : ψ ⬝ᵥ A.mulVec c = r := by\n exact posDef_bilinear_symm hA ψ c\n simp only [A] at hPA hsym\n apply (mulVec_injective_iff_isUnit.mpr hP'.isUnit)\n rw [mulVec_mulVec,\n show (P + vecMulVec ψ ψ) * (P + vecMulVec ψ ψ)⁻¹ = 1 by\n exact (P + vecMulVec ψ ψ).mul_nonsing_inv hP'det]\n simp only [one_mulVec, mulVec_sub, mulVec_smul, add_mulVec, hPA, hrank, hsym]\n change c = (c + r • ψ) - (r / (1 + s)) • (ψ + s • ψ)\n ext i\n simp only [Pi.add_apply, Pi.sub_apply, Pi.smul_apply, smul_eq_mul]\n field_simp\n ring1\n\nprivate lemma rankOne_inv_mulVec_update {d : ℕ}\n (P : Matrix (Fin d) (Fin d) ℝ) (hP : P.PosDef)\n (ψ b : Fin d → ℝ) (y : ℝ) :\n (P + vecMulVec ψ ψ)⁻¹.mulVec (b + y • ψ) =\n P⁻¹.mulVec b +\n ((y - ψ ⬝ᵥ P⁻¹.mulVec b) / (1 + ψ ⬝ᵥ P⁻¹.mulVec ψ)) • P⁻¹.mulVec ψ := by\n rw [rankOne_inv_mulVec P hP ψ (b + y • ψ)]\n have hsym := posDef_bilinear_symm hP.inv b ψ\n have hs : 0 ≤ ψ ⬝ᵥ P⁻¹.mulVec ψ :=\n hP.inv.posSemidef.dotProduct_mulVec_nonneg ψ\n simp only [mulVec_add, mulVec_smul, add_dotProduct, smul_dotProduct, smul_eq_mul]\n rw [hsym]\n ext i\n simp only [Pi.add_apply, Pi.sub_apply, Pi.smul_apply, smul_eq_mul]\n field_simp\n ring1\n\nprivate lemma residual_quad_nonneg {d : ℕ}\n {A : Matrix (Fin d) (Fin d) ℝ} (hA : A.PosDef)\n (ψ c : Fin d → ℝ) (hψ : ψ ≠ 0) :\n 0 ≤ c ⬝ᵥ A.mulVec c -\n (c ⬝ᵥ A.mulVec ψ) ^ 2 / (ψ ⬝ᵥ A.mulVec ψ) := by\n let r := c ⬝ᵥ A.mulVec ψ\n let s := ψ ⬝ᵥ A.mulVec ψ\n have hs : 0 < s := hA.dotProduct_mulVec_pos hψ\n have hsym : ψ ⬝ᵥ A.mulVec c = r := posDef_bilinear_symm hA ψ c\n have hnonneg : 0 ≤ (c - (r / s) • ψ) ⬝ᵥ A.mulVec (c - (r / s) • ψ) := by\n simpa using hA.posSemidef.dotProduct_mulVec_nonneg (c - (r / s) • ψ)\n simp only [mulVec_sub, mulVec_smul, sub_dotProduct, dotProduct_sub,\n smul_dotProduct, dotProduct_smul, smul_eq_mul] at hnonneg\n rw [hsym] at hnonneg\n change 0 ≤ c ⬝ᵥ A.mulVec c - r / s * r - r / s * (r - r / s * s) at hnonneg\n change 0 ≤ c ⬝ᵥ A.mulVec c - r ^ 2 / s\n have hs0 : s ≠ 0 := ne_of_gt hs\n field_simp [hs0] at hnonneg ⊢\n nlinarith [sq_nonneg r]\n\nprivate lemma map_withDensity_comp\n {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]\n (μ : Measure α) (f : α → β) (g : β → ℝ≥0∞)\n (hf : Measurable f) (hg : Measurable g) :\n (μ.withDensity (g ∘ f)).map f = (μ.map f).withDensity g := by\n ext s hs\n rw [Measure.map_apply hf hs, withDensity_apply _ (hf hs), withDensity_apply _ hs,\n setLIntegral_map hs hg hf]\n rfl\n\nprivate lemma residual_combo_quad {d : ℕ}\n {A : Matrix (Fin d) (Fin d) ℝ} (hA : A.PosDef)\n (ψ c : Fin d → ℝ) (hψ : ψ ≠ 0) (a b : ℝ) :\n let r := c ⬝ᵥ A.mulVec ψ\n let s := ψ ⬝ᵥ A.mulVec ψ\n let R := c - (r / s) • ψ\n (a • R + b • ψ) ⬝ᵥ A.mulVec (a • R + b • ψ) =\n a ^ 2 * (c ⬝ᵥ A.mulVec c - r ^ 2 / s) + b ^ 2 * s := by\n dsimp only\n let r := c ⬝ᵥ A.mulVec ψ\n let s := ψ ⬝ᵥ A.mulVec ψ\n have hs : 0 < s := hA.dotProduct_mulVec_pos hψ\n have hs0 : s ≠ 0 := ne_of_gt hs\n have hsym : ψ ⬝ᵥ A.mulVec c = r := posDef_bilinear_symm hA ψ c\n simp only [mulVec_add, mulVec_sub, mulVec_smul, add_dotProduct, sub_dotProduct,\n dotProduct_add, dotProduct_sub, smul_dotProduct, dotProduct_smul, smul_eq_mul]\n rw [hsym]\n dsimp only [r, s] at hs0 ⊢\n field_simp [hs0]\n ring1\n\nprivate lemma map_add_mul_gaussian_prod\n (m₁ m₂ a : ℝ) (v₁ v₂ : ℝ≥0) :\n ((gaussianReal m₁ v₁).prod (gaussianReal m₂ v₂)).map\n (fun p : ℝ × ℝ => p.1 + a * p.2) =\n gaussianReal (m₁ + a * m₂) (v₁ + ⟨a ^ 2, sq_nonneg a⟩ * v₂) := by\n calc\n ((gaussianReal m₁ v₁).prod (gaussianReal m₂ v₂)).map\n (fun p : ℝ × ℝ => p.1 + a * p.2) =\n gaussianReal m₁ v₁ ∗ (gaussianReal m₂ v₂).map (a * ·) := by\n unfold Measure.conv\n have hprod := Measure.map_prod_map (gaussianReal m₁ v₁) (gaussianReal m₂ v₂)\n measurable_id (measurable_const_mul a)\n rw [Measure.map_id] at hprod\n rw [hprod, Measure.map_map (by fun_prop) (by fun_prop)]\n rfl\n _ = gaussianReal m₁ v₁ ∗\n gaussianReal (a * m₂) (⟨a ^ 2, sq_nonneg a⟩ * v₂) := by\n rw [gaussianReal_map_const_mul]\n _ = gaussianReal (m₁ + a * m₂) (v₁ + ⟨a ^ 2, sq_nonneg a⟩ * v₂) :=\n gaussianReal_conv_gaussianReal\n\nprivate lemma gaussian_one_step_map\n {d : ℕ} (σ : ℝ) (hσ : 0 < σ)\n (P : Matrix (Fin d) (Fin d) ℝ) (hP : P.PosDef)\n (b ψ : Fin d → ℝ) (y : ℝ)\n (μ : Measure (Fin d → ℝ)) [IsProbabilityMeasure μ]\n (hμ : ∀ c : Fin d → ℝ,\n μ.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ P⁻¹.mulVec b)\n ((σ ^ 2 * (c ⬝ᵥ P⁻¹.mulVec c)).toNNReal))\n (c : Fin d → ℝ) :\n let v := (σ ^ 2).toNNReal\n let s := (ψ ⬝ᵥ P⁻¹.mulVec ψ).toNNReal\n let e := gaussianPDF (ψ ⬝ᵥ P⁻¹.mulVec b) ((1 + s) * v) y\n (μ.withDensity (fun w => gaussianPDF (ψ ⬝ᵥ w) v y)).map (fun w => c ⬝ᵥ w) =\n e • gaussianReal (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec (b + y • ψ))\n ((σ ^ 2 * (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec c)).toNNReal) := by\n dsimp only\n let A := P⁻¹\n let v := (σ ^ 2).toNNReal\n let sR := ψ ⬝ᵥ A.mulVec ψ\n let s := sR.toNNReal\n let mz := ψ ⬝ᵥ A.mulVec b\n let e := gaussianPDF mz ((1 + s) * v) y\n have hvR : 0 < σ ^ 2 := sq_pos_of_pos hσ\n have hvcoe : (v : ℝ) = σ ^ 2 := Real.coe_toNNReal _ hvR.le\n have hv : v ≠ 0 := by\n rw [ne_eq, ← NNReal.coe_eq_zero, hvcoe]\n exact ne_of_gt hvR\n by_cases hψ : ψ = 0\n · subst ψ\n simp only [zero_dotProduct, mulVec_zero, Real.toNNReal_zero, add_zero, vecMulVec_zero]\n rw [withDensity_const, Measure.map_smul]\n rw [hμ c]\n simp\n let r := c ⬝ᵥ A.mulVec ψ\n let q := c ⬝ᵥ A.mulVec c\n let qR := q - r ^ 2 / sR\n let qRn := qR.toNNReal\n let mx := c ⬝ᵥ A.mulVec b\n let mr := mx - (r / sR) * mz\n let Rv : Fin d → ℝ := c - (r / sR) • ψ\n let X : (Fin d → ℝ) → ℝ := fun w => Rv ⬝ᵥ w\n let Z : (Fin d → ℝ) → ℝ := fun w => ψ ⬝ᵥ w\n have hA : A.PosDef := hP.inv\n have hsR : 0 < sR := hA.dotProduct_mulVec_pos hψ\n have hsR0 : sR ≠ 0 := ne_of_gt hsR\n have hscoe : (s : ℝ) = sR := Real.coe_toNNReal _ hsR.le\n have hs : s ≠ 0 := by\n rw [ne_eq, ← NNReal.coe_eq_zero, hscoe]\n exact ne_of_gt hsR\n have hqR : 0 ≤ qR := by\n exact residual_quad_nonneg hA ψ c hψ\n have hqRcoe : (qRn : ℝ) = qR := Real.coe_toNNReal _ hqR\n have hpair :\n μ.map (fun w => (X w, Z w)) =\n (gaussianReal mr (qRn * v)).prod (gaussianReal mz (s * v)) := by\n apply map_prod_eq_gaussian_prod_of_map_add μ X Z (by fun_prop) (by fun_prop)\n intro aa bb\n let u : Fin d → ℝ := aa • Rv + bb • ψ\n calc\n μ.map (fun w => aa * X w + bb * Z w) = μ.map (fun w => u ⬝ᵥ w) := by\n congr 1\n funext w\n simp only [u, X, Z, add_dotProduct, smul_dotProduct, smul_eq_mul]\n _ = gaussianReal (u ⬝ᵥ P⁻¹.mulVec b)\n ((σ ^ 2 * (u ⬝ᵥ P⁻¹.mulVec u)).toNNReal) := hμ u\n _ = gaussianReal (aa * mr + bb * mz)\n (⟨aa ^ 2, sq_nonneg aa⟩ * (qRn * v) +\n ⟨bb ^ 2, sq_nonneg bb⟩ * (s * v)) := by\n congr 2\n · simp only [u, Rv, mr, mx, mz, A, add_dotProduct, sub_dotProduct,\n smul_dotProduct, smul_eq_mul]\n · rw [show u ⬝ᵥ A.mulVec u =\n aa ^ 2 * qR + bb ^ 2 * sR by\n exact residual_combo_quad hA ψ c hψ aa bb]\n apply NNReal.eq\n simp only [NNReal.coe_add, NNReal.coe_mul, NNReal.coe_mk]\n rw [Real.coe_toNNReal _ (mul_nonneg hvR.le\n (add_nonneg (mul_nonneg (sq_nonneg aa) hqR)\n (mul_nonneg (sq_nonneg bb) hsR.le))),\n hqRcoe, hscoe, hvcoe]\n ring1\n let mz' := (mz + (s : ℝ) * y) / (1 + (s : ℝ))\n let vz' := (s / (1 + s)) * v\n have hlike : Measurable (fun z : ℝ => gaussianPDF z v y) := by\n simpa only [gaussianPDF_symm] using measurable_gaussianPDF y v\n have hweightedPair :\n (μ.withDensity (fun w => gaussianPDF (Z w) v y)).map (fun w => (X w, Z w)) =\n e • ((gaussianReal mr (qRn * v)).prod (gaussianReal mz' vz')) := by\n calc\n (μ.withDensity (fun w => gaussianPDF (Z w) v y)).map (fun w => (X w, Z w)) =\n (μ.map (fun w => (X w, Z w))).withDensity\n (fun p : ℝ × ℝ => gaussianPDF p.2 v y) := by\n simpa [Function.comp_def] using\n map_withDensity_comp μ (fun w => (X w, Z w))\n (fun p : ℝ × ℝ => gaussianPDF p.2 v y) (by fun_prop) (hlike.comp measurable_snd)\n _ = ((gaussianReal mr (qRn * v)).prod (gaussianReal mz (s * v))).withDensity\n (fun p : ℝ × ℝ => gaussianPDF p.2 v y) := by rw [hpair]\n _ = (gaussianReal mr (qRn * v)).prod\n ((gaussianReal mz (s * v)).withDensity (fun z => gaussianPDF z v y)) := by\n rw [prod_withDensity_right hlike]\n _ = (gaussianReal mr (qRn * v)).prod\n (e • gaussianReal mz' vz') := by\n rw [gaussianReal_withDensity_likelihood mz y v s hv hs]\n _ = e • ((gaussianReal mr (qRn * v)).prod (gaussianReal mz' vz')) := by\n rw [Measure.prod_smul_right]\n let ar := r / sR\n calc\n (μ.withDensity (fun w => gaussianPDF (ψ ⬝ᵥ w) v y)).map (fun w => c ⬝ᵥ w) =\n ((μ.withDensity (fun w => gaussianPDF (Z w) v y)).map (fun w => (X w, Z w))).map\n (fun p : ℝ × ℝ => p.1 + ar * p.2) := by\n rw [Measure.map_map (by fun_prop) (by fun_prop)]\n congr 1\n funext w\n simp only [X, Z, Rv, ar, sub_dotProduct, smul_dotProduct, smul_eq_mul,\n Function.comp_apply]\n ring1\n _ = (e • ((gaussianReal mr (qRn * v)).prod (gaussianReal mz' vz'))).map\n (fun p : ℝ × ℝ => p.1 + ar * p.2) := by rw [hweightedPair]\n _ = e • (((gaussianReal mr (qRn * v)).prod (gaussianReal mz' vz')).map\n (fun p : ℝ × ℝ => p.1 + ar * p.2)) := by\n rw [Measure.map_smul]\n _ = e • gaussianReal (mr + ar * mz')\n (qRn * v + ⟨ar ^ 2, sq_nonneg ar⟩ * vz') := by\n rw [map_add_mul_gaussian_prod]\n _ = e • gaussianReal (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec (b + y • ψ))\n ((σ ^ 2 * (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec c)).toNNReal) := by\n congr 2\n · rw [rankOne_inv_mulVec_update P hP ψ b y]\n simp only [dotProduct_add, dotProduct_smul, smul_eq_mul]\n change mr + ar * mz' = mx + (y - mz) / (1 + sR) * r\n dsimp only [mr, ar, mz']\n rw [hscoe]\n field_simp [hsR0, show 1 + sR ≠ 0 by positivity]\n ring1\n · apply NNReal.eq\n have hP' : (P + vecMulVec ψ ψ).PosDef :=\n hP.add_posSemidef (by simpa using posSemidef_vecMulVec_self_star ψ)\n have hnew : 0 ≤ c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec c :=\n hP'.inv.posSemidef.dotProduct_mulVec_nonneg c\n simp only [NNReal.coe_add, NNReal.coe_mul, NNReal.coe_mk]\n rw [Real.coe_toNNReal _ (mul_nonneg hvR.le hnew), hqRcoe, hvcoe]\n rw [rankOne_inv_mulVec P hP ψ c]\n simp only [dotProduct_sub, dotProduct_smul, smul_eq_mul]\n change qR * σ ^ 2 + ar ^ 2 * (vz' : ℝ) =\n σ ^ 2 * (q - r / (1 + sR) * r)\n dsimp only [qR, ar, vz']\n push_cast\n rw [hscoe, hvcoe]\n field_simp [hsR0, show 1 + sR ≠ 0 by positivity]\n ring1\n\nprivate lemma gaussian_one_step_normalized\n {d : ℕ} (σ : ℝ) (hσ : 0 < σ)\n (P : Matrix (Fin d) (Fin d) ℝ) (hP : P.PosDef)\n (b ψ : Fin d → ℝ) (y : ℝ)\n (μ : Measure (Fin d → ℝ)) [IsProbabilityMeasure μ]\n (hμ : ∀ c : Fin d → ℝ,\n μ.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ P⁻¹.mulVec b)\n ((σ ^ 2 * (c ⬝ᵥ P⁻¹.mulVec c)).toNNReal)) :\n let U := μ.withDensity (fun w => gaussianPDF (ψ ⬝ᵥ w) ((σ ^ 2).toNNReal) y)\n let ν := (U Set.univ)⁻¹ • U\n IsProbabilityMeasure ν ∧\n ∀ c : Fin d → ℝ,\n ν.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec (b + y • ψ))\n ((σ ^ 2 * (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec c)).toNNReal) := by\n dsimp only\n let v := (σ ^ 2).toNNReal\n let s := (ψ ⬝ᵥ P⁻¹.mulVec ψ).toNNReal\n let e := gaussianPDF (ψ ⬝ᵥ P⁻¹.mulVec b) ((1 + s) * v) y\n let U := μ.withDensity (fun w => gaussianPDF (ψ ⬝ᵥ w) v y)\n have hvR : 0 < σ ^ 2 := sq_pos_of_pos hσ\n have hv : v ≠ 0 := by\n rw [ne_eq, ← NNReal.coe_eq_zero, show (v : ℝ) = σ ^ 2 by\n exact Real.coe_toNNReal _ hvR.le]\n exact ne_of_gt hvR\n have hevar : (1 + s) * v ≠ 0 := mul_ne_zero (by positivity) hv\n have he0 : e ≠ 0 := (gaussianPDF_pos _ hevar y).ne'\n have hetop : e ≠ ∞ := gaussianPDF_ne_top\n have hmap (c : Fin d → ℝ) :\n U.map (fun w => c ⬝ᵥ w) =\n e • gaussianReal (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec (b + y • ψ))\n ((σ ^ 2 * (c ⬝ᵥ (P + vecMulVec ψ ψ)⁻¹.mulVec c)).toNNReal) := by\n exact gaussian_one_step_map σ hσ P hP b ψ y μ hμ c\n have hmass : U Set.univ = e := by\n have h := congrArg (fun ξ : Measure ℝ => ξ Set.univ) (hmap 0)\n simpa [Measure.map_apply, U] using h\n constructor\n · refine ⟨?_⟩\n rw [Measure.smul_apply, hmass]\n exact ENNReal.inv_mul_cancel he0 hetop\n · intro c\n rw [Measure.map_smul, hmass, hmap c, smul_smul, ENNReal.inv_mul_cancel he0 hetop,\n one_smul]\n\nprivate lemma gaussian_one_step_mass_ne\n {d : ℕ} (σ : ℝ) (hσ : 0 < σ)\n (P : Matrix (Fin d) (Fin d) ℝ) (hP : P.PosDef)\n (b ψ : Fin d → ℝ) (y : ℝ)\n (μ : Measure (Fin d → ℝ)) [IsProbabilityMeasure μ]\n (hμ : ∀ c : Fin d → ℝ,\n μ.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ P⁻¹.mulVec b)\n ((σ ^ 2 * (c ⬝ᵥ P⁻¹.mulVec c)).toNNReal)) :\n let U := μ.withDensity (fun w => gaussianPDF (ψ ⬝ᵥ w) ((σ ^ 2).toNNReal) y)\n U Set.univ ≠ 0 ∧ U Set.univ ≠ ∞ := by\n dsimp only\n let v := (σ ^ 2).toNNReal\n let s := (ψ ⬝ᵥ P⁻¹.mulVec ψ).toNNReal\n let e := gaussianPDF (ψ ⬝ᵥ P⁻¹.mulVec b) ((1 + s) * v) y\n have hvR : 0 < σ ^ 2 := sq_pos_of_pos hσ\n have hv : v ≠ 0 := by\n rw [ne_eq, ← NNReal.coe_eq_zero, show (v : ℝ) = σ ^ 2 by\n exact Real.coe_toNNReal _ hvR.le]\n exact ne_of_gt hvR\n have hevar : (1 + s) * v ≠ 0 := mul_ne_zero (by positivity) hv\n have he0 : e ≠ 0 := (gaussianPDF_pos _ hevar y).ne'\n have hetop : e ≠ ∞ := gaussianPDF_ne_top\n have hmap := gaussian_one_step_map σ hσ P hP b ψ y μ hμ (0 : Fin d → ℝ)\n have hmass :\n (μ.withDensity (fun w => gaussianPDF (ψ ⬝ᵥ w) v y)) Set.univ = e := by\n have h := congrArg (fun ξ : Measure ℝ => ξ Set.univ) hmap\n simpa [Measure.map_apply, v, s, e] using h\n rw [hmass]\n exact ⟨he0, hetop⟩\n\nprivate noncomputable def normalizeMeasure {α : Type*} [MeasurableSpace α]\n (μ : Measure α) : Measure α := (μ Set.univ)⁻¹ • μ\n\nprivate lemma normalize_withDensity_normalize\n {α : Type*} [MeasurableSpace α] (μ : Measure α) (f : α → ℝ≥0∞)\n (ha0 : μ Set.univ ≠ 0) (hatop : μ Set.univ ≠ ∞) :\n normalizeMeasure ((normalizeMeasure μ).withDensity f) =\n normalizeMeasure (μ.withDensity f) := by\n unfold normalizeMeasure\n rw [withDensity_smul_measure, Measure.smul_apply]\n simp only [smul_smul]\n congr 1\n simp only [smul_eq_mul]\n rw [ENNReal.mul_inv (Or.inl (ENNReal.inv_ne_zero.mpr hatop))\n (Or.inl (ENNReal.inv_ne_top.mpr ha0)), inv_inv]\n calc\n μ Set.univ * (μ.withDensity f Set.univ)⁻¹ * (μ Set.univ)⁻¹ =\n (μ.withDensity f Set.univ)⁻¹ * (μ Set.univ * (μ Set.univ)⁻��) := by ac_rfl\n _ = (μ.withDensity f Set.univ)⁻¹ := by\n rw [ENNReal.mul_inv_cancel ha0 hatop, mul_one]\n\nprivate lemma gaussian_finset_update\n {d ι : ℕ} (σ : ℝ) (hσ : 0 < σ)\n (P : Matrix (Fin d) (Fin d) ℝ) (hP : P.PosDef)\n (b : Fin d → ℝ) (ψ : Fin ι → Fin d → ℝ) (Y : Fin ι → ℝ)\n (μ : Measure (Fin d → ℝ)) [IsProbabilityMeasure μ]\n (hμ : ∀ c : Fin d → ℝ,\n μ.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ P⁻¹.mulVec b)\n ((σ ^ 2 * (c ⬝ᵥ P⁻¹.mulVec c)).toNNReal))\n (S : Finset (Fin ι)) :\n let U := μ.withDensity (fun w =>\n ∏ i ∈ S, gaussianPDF (ψ i ⬝ᵥ w) ((σ ^ 2).toNNReal) (Y i))\n let P' := P + ∑ i ∈ S, vecMulVec (ψ i) (ψ i)\n let b' := b + ∑ i ∈ S, (Y i) • ψ i\n U Set.univ ≠ 0 ∧ U Set.univ ≠ ∞ ∧\n IsProbabilityMeasure (normalizeMeasure U) ∧\n ∀ c : Fin d → ℝ,\n (normalizeMeasure U).map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ P'⁻¹.mulVec b')\n ((σ ^ 2 * (c ⬝ᵥ P'⁻¹.mulVec c)).toNNReal) := by\n classical\n induction S using Finset.induction_on with\n | empty =>\n dsimp only\n have hprob : IsProbabilityMeasure μ := inferInstance\n simpa [normalizeMeasure, measure_univ] using\n (show μ Set.univ ≠ 0 ∧ μ Set.univ ≠ ∞ ∧\n IsProbabilityMeasure μ ∧ ∀ c : Fin d → ℝ,\n μ.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ P⁻¹.mulVec b)\n ((σ ^ 2 * (c ⬝ᵥ P⁻¹.mulVec c)).toNNReal) from\n ⟨by simp, by simp, hprob, hμ⟩)\n | @insert a S ha ih =>\n let v := (σ ^ 2).toNNReal\n let Ls : (Fin d → ℝ) → ℝ≥0∞ := fun w =>\n ∏ i ∈ S, gaussianPDF (ψ i ⬝ᵥ w) v (Y i)\n let La : (Fin d → ℝ) → ℝ≥0∞ := fun w => gaussianPDF (ψ a ⬝ᵥ w) v (Y a)\n let Us := μ.withDensity Ls\n let Ps := P + ∑ i ∈ S, vecMulVec (ψ i) (ψ i)\n let bs := b + ∑ i ∈ S, (Y i) • ψ i\n let νs := normalizeMeasure Us\n let U := μ.withDensity (fun w =>\n ∏ i ∈ insert a S, gaussianPDF (ψ i ⬝ᵥ w) v (Y i))\n let W := νs.withDensity La\n have hih : Us Set.univ ≠ 0 ∧ Us Set.univ ≠ ∞ ∧\n IsProbabilityMeasure νs ∧\n ∀ c : Fin d → ℝ,\n νs.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ Ps⁻¹.mulVec bs)\n ((σ ^ 2 * (c ⬝ᵥ Ps⁻¹.mulVec c)).toNNReal) := by\n simpa only [Us, Ls, v, Ps, bs, νs] using ih\n letI : IsProbabilityMeasure νs := hih.2.2.1\n have hsum : (∑ i ∈ S, vecMulVec (ψ i) (ψ i)).PosSemidef := by\n apply posSemidef_sum S\n intro i hi\n simpa using posSemidef_vecMulVec_self_star (ψ i)\n have hPs : Ps.PosDef := hP.add_posSemidef hsum\n have hLa : Measurable La := by\n dsimp only [La]\n simpa only [gaussianPDF_symm] using\n (measurable_gaussianPDF (Y a) v).comp (by fun_prop)\n have hLs : Measurable Ls := by\n dsimp only [Ls]\n apply Finset.measurable_prod S\n intro i hi\n simpa only [gaussianPDF_symm] using\n (measurable_gaussianPDF (Y i) v).comp (by fun_prop)\n have hU : U = Us.withDensity La := by\n dsimp only [U, Us]\n rw [show (fun w => ∏ i ∈ insert a S,\n gaussianPDF (ψ i ⬝ᵥ w) v (Y i)) = fun w => Ls w * La w by\n funext w\n simp only [Finset.prod_insert ha, Ls, La]\n exact mul_comm _ _]\n exact withDensity_mul μ hLs hLa\n have hstep : IsProbabilityMeasure (normalizeMeasure W) ∧\n ∀ c : Fin d → ℝ,\n (normalizeMeasure W).map (fun w => c ⬝ᵥ w) =\n gaussianReal\n (c ⬝ᵥ (Ps + vecMulVec (ψ a) (ψ a))⁻¹.mulVec (bs + Y a • ψ a))\n ((σ ^ 2 * (c ⬝ᵥ\n (Ps + vecMulVec (ψ a) (ψ a))⁻¹.mulVec c)).toNNReal) := by\n simpa only [W, La, v, νs, normalizeMeasure] using\n gaussian_one_step_normalized σ hσ Ps hPs bs (ψ a) (Y a) νs hih.2.2.2\n have hWmass : W Set.univ ≠ 0 ∧ W Set.univ ≠ ∞ := by\n simpa only [W, La, v] using\n gaussian_one_step_mass_ne σ hσ Ps hPs bs (ψ a) (Y a) νs hih.2.2.2\n have hWmass_eq : W Set.univ = (Us Set.univ)⁻¹ * U Set.univ := by\n dsimp only [W, νs]\n unfold normalizeMeasure\n rw [withDensity_smul_measure, Measure.smul_apply, ← hU]\n simp only [smul_eq_mul]\n have hU0 : U Set.univ ≠ 0 := by\n intro hzero\n apply hWmass.1\n rw [hWmass_eq, hzero, mul_zero]\n have hUtop : U Set.univ ≠ ∞ := by\n intro htop\n apply hWmass.2\n rw [hWmass_eq, htop]\n simp [ENNReal.inv_ne_zero.mpr hih.2.1]\n have hnorm : normalizeMeasure U = normalizeMeasure W := by\n rw [hU]\n symm\n simpa only [W, νs] using\n normalize_withDensity_normalize Us La hih.1 hih.2.1\n have hPnew : Ps + vecMulVec (ψ a) (ψ a) =\n P + ∑ i ∈ insert a S, vecMulVec (ψ i) (ψ i) := by\n rw [Finset.sum_insert ha]\n dsimp only [Ps]\n abel\n have hbnew : bs + Y a • ψ a = b + ∑ i ∈ insert a S, Y i • ψ i := by\n rw [Finset.sum_insert ha]\n dsimp only [bs]\n abel\n dsimp only\n change U Set.univ ≠ 0 ∧ U Set.univ ≠ ∞ ∧\n IsProbabilityMeasure (normalizeMeasure U) ∧ _\n refine ⟨hU0, hUtop, ?_, ?_⟩\n · rw [hnorm]\n exact hstep.1\n · intro c\n rw [hnorm, hstep.2 c, hPnew, hbnew]\n\nprivate lemma ofReal_prod_gaussianPDFReal\n {ι : Type*} (S : Finset ι) (m y : ι → ℝ) (v : ℝ≥0) :\n ENNReal.ofReal (∏ i ∈ S, gaussianPDFReal (m i) v (y i)) =\n ∏ i ∈ S, gaussianPDF (m i) v (y i) := by\n rw [ENNReal.ofReal_prod_of_nonneg]\n · rfl\n · intro i hi\n exact gaussianPDFReal_nonneg _ _ _\n\nprivate lemma bind_gaussianReal_of_map\n {α : Type*} [MeasurableSpace α]\n (μ : Measure α) [IsProbabilityMeasure μ]\n (f : α → ℝ) (hf : Measurable f) (m : ℝ) (v₁ v₂ : ℝ≥0)\n (hmap : μ.map f = gaussianReal m v₁) :\n μ.bind (fun x => gaussianReal (f x) v₂) = gaussianReal m (v₁ + v₂) := by\n let ν₀ := gaussianReal 0 v₂\n let G : α × ℝ → ℝ := fun p => f p.1 + p.2\n have hG : Measurable G := (hf.comp measurable_fst).add measurable_snd\n have hkernel : (fun x => gaussianReal (f x) v₂) =\n fun x => (ν₀.map (Prod.mk x)).map G := by\n funext x\n rw [Measure.map_map hG measurable_prodMk_left]\n change gaussianReal (f x) v₂ = (gaussianReal 0 v₂).map (fun z => f x + z)\n rw [gaussianReal_map_const_add]\n simp only [zero_add]\n have hkernel_meas : Measurable (fun x => gaussianReal (f x) v₂) := by\n rw [hkernel]\n exact (Measure.measurable_map G hG).comp Measurable.map_prodMk_left\n have hbindprod : μ.bind (fun x => gaussianReal (f x) v₂) = (μ.prod ν₀).map G := by\n ext A hA\n rw [Measure.bind_apply hA hkernel_meas.aemeasurable,\n Measure.map_apply hG hA, Measure.prod_apply (hG hA)]\n apply lintegral_congr\n intro x\n rw [congrFun hkernel x, Measure.map_apply hG hA,\n Measure.map_apply measurable_prodMk_left (hG hA)]\n have hprod := Measure.map_prod_map μ ν₀ hf measurable_id\n rw [Measure.map_id] at hprod\n calc\n μ.bind (fun x => gaussianReal (f x) v₂) = (μ.prod ν₀).map G := hbindprod\n _ = ((μ.prod ν₀).map (Prod.map f id)).map (fun p : ℝ × ℝ => p.1 + p.2) := by\n rw [Measure.map_map (by fun_prop) (hf.prodMap measurable_id)]\n congr 1\n _ = ((μ.map f).prod ν₀).map (fun p : ℝ × ℝ => p.1 + p.2) := by\n rw [← hprod]\n _ = ((gaussianReal m v₁).prod (gaussianReal 0 v₂)).map\n (fun p : ℝ × ℝ => p.1 + p.2) := by rw [hmap]\n _ = gaussianReal m (v₁ + v₂) := by\n simpa only [one_mul, add_zero, one_pow, NNReal.mk_one] using\n map_add_mul_gaussian_prod m 0 1 v₁ v₂\n\nnoncomputable def postPrec {d n : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) : Matrix (Fin d) (Fin d) ℝ :=\n Λ₀ + ∑ i : Fin n, vecMulVec (ψ i) (ψ i)\n\nnoncomputable def postMean {d n : ℕ} (Λ₀ : Matrix (Fin d) (Fin d) ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ) : Fin d → ℝ :=\n (postPrec Λ₀ ψ)⁻¹.mulVec (∑ i : Fin n, (Y i) • (ψ i))\n\nnoncomputable def postUnnorm {d n : ℕ} (σ : ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ)\n (prior : Measure (Fin d → ℝ)) : Measure (Fin d → ℝ) :=\n prior.withDensity (fun w => ENNReal.ofReal\n (∏ i : Fin n, gaussianPDFReal (w ⬝ᵥ ψ i) ((σ^2).toNNReal) (Y i)))\n\nnoncomputable def posteriorMeasure {d n : ℕ} (σ : ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ)\n (prior : Measure (Fin d → ℝ)) : Measure (Fin d → ℝ) :=\n ((postUnnorm σ ψ Y prior) Set.univ)⁻¹ • postUnnorm σ ψ Y prior\n\nnoncomputable def predictiveMeasure {d n : ℕ} (σ : ℝ)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ) (φ : Fin d → ℝ)\n (prior : Measure (Fin d → ℝ)) : Measure ℝ :=\n (posteriorMeasure σ ψ Y prior).bind (fun w => gaussianReal (w ⬝ᵥ φ) ((σ^2).toNNReal))\n\ntheorem ch15_proposition_15_5\n {d n : ℕ} (σ : ℝ) (hσ : 0 < σ)\n (Λ₀ : Matrix (Fin d) (Fin d) ℝ) (hΛ₀ : Λ₀.PosDef)\n (ψ : (Fin n) → (Fin d → ℝ)) (Y : (Fin n) → ℝ)\n (φ : Fin d → ℝ)\n (prior : Measure (Fin d → ℝ))\n (hprior : ∀ c : Fin d → ℝ,\n prior.map (fun w => c ⬝ᵥ w)\n = gaussianReal 0 ((σ^2 * (c ⬝ᵥ Λ₀⁻¹.mulVec c)).toNNReal)) :\n IsProbabilityMeasure (posteriorMeasure σ ψ Y prior)\n ∧ (∀ c : Fin d → ℝ,\n (posteriorMeasure σ ψ Y prior).map (fun w => c ⬝ᵥ w)\n = gaussianReal (c ⬝ᵥ postMean Λ₀ ψ Y)\n ((σ^2 * (c ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec c)).toNNReal))\n ∧ predictiveMeasure σ ψ Y φ prior\n = gaussianReal (postMean Λ₀ ψ Y ⬝ᵥ φ)\n ((σ^2 + σ^2 * (φ ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec φ)).toNNReal) := by\n classical\n have hprior_univ : prior Set.univ = 1 := by\n have h := congrArg (fun ξ : Measure ℝ => ξ Set.univ) (hprior 0)\n simpa [Measure.map_apply] using h\n letI : IsProbabilityMeasure prior := ⟨hprior_univ⟩\n have hprior' (c : Fin d → ℝ) :\n prior.map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ Λ₀⁻¹.mulVec 0)\n ((σ ^ 2 * (c ⬝ᵥ Λ₀⁻¹.mulVec c)).toNNReal) := by\n simpa using hprior c\n let U := prior.withDensity (fun w =>\n ∏ i : Fin n, gaussianPDF (ψ i ⬝ᵥ w) ((σ ^ 2).toNNReal) (Y i))\n have hpostU : postUnnorm σ ψ Y prior = U := by\n unfold postUnnorm\n dsimp only [U]\n congr 1\n funext w\n rw [ofReal_prod_gaussianPDFReal Finset.univ (fun i => w ⬝ᵥ ψ i) Y\n ((σ ^ 2).toNNReal)]\n apply Finset.prod_congr rfl\n intro i hi\n rw [dotProduct_comm]\n have hbatch : U Set.univ ≠ 0 ∧ U Set.univ ≠ ∞ ∧\n IsProbabilityMeasure (normalizeMeasure U) ∧\n ∀ c : Fin d → ℝ,\n (normalizeMeasure U).map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec\n (∑ i : Fin n, Y i • ψ i))\n ((σ ^ 2 * (c ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec c)).toNNReal) := by\n simpa only [U, postPrec, Finset.sum_filter, Finset.mem_univ, if_true, zero_add] using\n gaussian_finset_update σ hσ Λ₀ hΛ₀ (0 : Fin d → ℝ) ψ Y prior hprior' Finset.univ\n have hposteq : posteriorMeasure σ ψ Y prior = normalizeMeasure U := by\n unfold posteriorMeasure normalizeMeasure\n rw [hpostU]\n have hprob : IsProbabilityMeasure (posteriorMeasure σ ψ Y prior) := by\n rw [hposteq]\n exact hbatch.2.2.1\n have hproj (c : Fin d → ℝ) :\n (posteriorMeasure σ ψ Y prior).map (fun w => c ⬝ᵥ w) =\n gaussianReal (c ⬝ᵥ postMean Λ₀ ψ Y)\n ((σ ^ 2 * (c ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec c)).toNNReal) := by\n rw [hposteq]\n simpa only [postMean] using hbatch.2.2.2 c\n letI : IsProbabilityMeasure (posteriorMeasure σ ψ Y prior) := hprob\n have hsum : (∑ i : Fin n, vecMulVec (ψ i) (ψ i)).PosSemidef := by\n apply posSemidef_sum Finset.univ\n intro i hi\n simpa using posSemidef_vecMulVec_self_star (ψ i)\n have hpostPos : (postPrec Λ₀ ψ).PosDef := by\n exact hΛ₀.add_posSemidef hsum\n let q := φ ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec φ\n have hq : 0 ≤ q := hpostPos.inv.posSemidef.dotProduct_mulVec_nonneg φ\n let vp := (σ ^ 2 * q).toNNReal\n let ve := (σ ^ 2).toNNReal\n have hφmap : (posteriorMeasure σ ψ Y prior).map (fun w => w ⬝ᵥ φ) =\n gaussianReal (postMean Λ₀ ψ Y ⬝ᵥ φ) vp := by\n calc\n (posteriorMeasure σ ψ Y prior).map (fun w => w ⬝ᵥ φ) =\n (posteriorMeasure σ ψ Y prior).map (fun w => φ ⬝ᵥ w) := by\n congr 1\n funext w\n exact dotProduct_comm w φ\n _ = gaussianReal (φ ⬝ᵥ postMean Λ₀ ψ Y)\n ((σ ^ 2 * (φ ⬝ᵥ (postPrec Λ₀ ψ)⁻¹.mulVec φ)).toNNReal) := hproj φ\n _ = gaussianReal (postMean Λ₀ ψ Y ⬝ᵥ φ) vp := by\n rw [dotProduct_comm]\n have hpred : predictiveMeasure σ ψ Y φ prior =\n gaussianReal (postMean Λ₀ ψ Y ⬝ᵥ φ) (vp + ve) := by\n unfold predictiveMeasure\n exact bind_gaussianReal_of_map (posteriorMeasure σ ψ Y prior)\n (fun w => w ⬝ᵥ φ) (by fun_prop) (postMean Λ₀ ψ Y ⬝ᵥ φ) vp ve hφmap\n refine ⟨hprob, hproj, ?_⟩\n rw [hpred]\n congr 1\n dsimp only [vp, ve, q]\n rw [add_comm, ← Real.toNNReal_add (sq_nonneg σ)\n (mul_nonneg (sq_nonneg σ) hq)]\n\nend GraduateLevel\n"} +{"id": "ch2_theorem_2_1", "source": "Graduate-level", "targets": [{"label": "theorem_2_1", "decls": ["theorem_2_1"], "statement": "Let \\(X_{1},\\ldots,X_{n}\\) be \\(n\\) iid Gaussian random variables \\(X_{i}\\sim N(\\mu,\\sigma^{2})\\) and let \\(\\bar{X}_n = n^{-1}\\sum_{i = 1}^n X_i\\). Then given any \\(\\epsilon >0\\):\n\\[\n0.5e^{-n(\\epsilon+\\sigma/\\sqrt{n})^{2}/2\\sigma^{2}}\\leq\\operatorname*{Pr}(\\bar{X}_{n}\\geq\\mu+\\epsilon)\\leq 0.5e^{-n\\epsilon^{2}/2\\sigma^{2}}.\n\\]", "topic_domain": "Probability & Concentration", "topic_subtopic": "Distributions, Tails & Moments"}], "nl_proof": "We first consider a standard normal random variable \\( X \\sim N(0,1) \\), which has probability density function\n\\[\np(x)=\\frac{1}{\\sqrt{2\\pi}}e^{-x^{2}/2}.\n\\]\nGiven \\(\\epsilon > 0\\), we can upper bound the tail probability \\(\\operatorname*{Pr}(X \\geq \\epsilon)\\) as follows.\n\\[\n\\begin{array}{l}\\Pr(X\\geq\\epsilon)=\\int_{\\epsilon}^{\\infty}\\frac{1}{\\sqrt{2\\pi}}e^{-x^{2}/2}dx\\\\ =\\int_{0}^{\\infty}\\frac{1}{\\sqrt{2\\pi}}e^{-(x+\\epsilon)^{2}/2}dx\\leq\\int_{0}^{\\infty}\\frac{1}{\\sqrt{2\\pi}}e^{-(x^{2}+\\epsilon^{2})/2}dx\\\\ =0. 5e^{-\\epsilon^{2}/2}.\\\\ \\end{array}\n\\]\nWe also have the following lower bound:\n\\[\n\\begin{array}{l}\\Pr(X\\geq\\epsilon)=\\int_{\\epsilon}^{\\infty}\\frac{1}{\\sqrt{2\\pi}}e^{-x^{2}/2}dx\\\\ \\geq\\int_{0}^{1}\\frac{1}{\\sqrt{2\\pi}}e^{-(x+\\epsilon)^{2}/2}dx\\\\ \\geq\\int_{0}^{1}\\frac{1}{\\sqrt{2\\pi}}e^{-x^{2}/2}e^{-(2\\epsilon+\\epsilon^{2})/2}dx\\geq 0. 34e^{-(2\\epsilon+\\epsilon^{2})/2}\\\\ \\geq 0. 5e^{-(\\epsilon+1)^{2}/2}.\\\\ \\end{array}\n\\]\nTherefore we have\n\\[\n0. 5e^{-(\\epsilon+1)^{2}/2}\\leq\\Pr(X\\geq\\epsilon)\\leq 0. 5e^{-\\epsilon^{2}/2}.\n\\]\nSince \\(\\sqrt{n} (\\bar{X}_n - \\mu) / \\sigma \\sim N(0,1)\\), by using\n\\[\n\\Pr(\\bar{X}_{n}\\geq\\mu+\\epsilon)=\\Pr(\\sqrt{n}(\\bar{X}_{n}-\\mu)/\\sigma\\geq\\sqrt{n}\\epsilon/\\sigma),\n\\]\nwe obtain the desired result.", "context": [], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\nnoncomputable def sampleMean {Ω : Type*} {n : ℕ} (X : Fin n → Ω → ℝ) (ω : Ω) : ℝ :=\n (1 / (n : ℝ)) * ∑ i, X i ω\n\ntheorem theorem_2_1 {Ω : Type*} [MeasurableSpace Ω]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (n : ℕ) (μ σ : ℝ) (X : Fin n → Ω → ℝ)\n (hσ : 0 < σ) (hn : 0 < n)\n (hX_meas : ∀ i, Measurable (X i))\n (hX_indep : ProbabilityTheory.iIndepFun X P)\n (hX_gaussian :\n ∀ i, MeasureTheory.Measure.map (X i) P =\n ProbabilityTheory.gaussianReal μ (Real.toNNReal (σ ^ 2))) :\n ∀ ε : ℝ, 0 < ε →\n 0.5 * Real.exp (-(n : ℝ) * (ε + σ / Real.sqrt (n : ℝ)) ^ 2 / (2 * σ ^ 2)) ≤\n (P {ω : Ω | μ + ε ≤ sampleMean X ω}).toReal ∧\n (P {ω : Ω | μ + ε ≤ sampleMean X ω}).toReal ≤\n 0.5 * Real.exp (-(n : ℝ) * ε ^ 2 / (2 * σ ^ 2)) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\n\nnoncomputable def sampleMean {Ω : Type*} {n : ℕ} (X : Fin n → Ω → ℝ) (ω : Ω) : ℝ :=\n (1 / (n : ℝ)) * ∑ i, X i ω\n\nprivate lemma map_sum_gauss {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω)\n [IsProbabilityMeasure P] {n : ℕ} (X : Fin n → Ω → ℝ) (m : ℝ) (v : NNReal)\n (hX_meas : ∀ i, Measurable (X i))\n (hX_indep : iIndepFun X P)\n (hX_gauss : ∀ i, P.map (X i) = gaussianReal m v) (s : Finset (Fin n)) :\n P.map (fun ω => ∑ i ∈ s, X i ω)\n = gaussianReal ((s.card : ℝ) * m) ((s.card : NNReal) * v) := by\n classical\n induction s using Finset.induction with\n | empty =>\n simp only [Finset.sum_empty, Finset.card_empty, Nat.cast_zero, zero_mul]\n rw [Measure.map_const]\n simp [gaussianReal_zero_var]\n | insert a s ha ih =>\n have hsum : (∑ j ∈ s, X j) = fun ω => ∑ j ∈ s, X j ω := by\n funext ω; simp\n have hindep : IndepFun (fun ω => ∑ j ∈ s, X j ω) (X a) P := by\n rw [← hsum]; exact hX_indep.indepFun_finset_sum_of_notMem hX_meas ha\n have hfun : (fun ω => ∑ i ∈ insert a s, X i ω)\n = (fun ω => ∑ j ∈ s, X j ω) + X a := by\n funext ω\n simp [Finset.sum_insert ha, add_comm]\n rw [hfun, gaussianReal_add_gaussianReal_of_indepFun hindep ih (hX_gauss a)]\n rw [Finset.card_insert_of_notMem ha]\n congr 1\n · push_cast; ring\n · push_cast; ring\n\n\nprivate lemma half_int (v : NNReal) (hv : v ≠ 0) :\n ∫ x in Set.Ici (0:ℝ), gaussianPDFReal 0 v x = 1/2 := by\n set ν := gaussianReal 0 v with hν\n have hneg : ν.map (fun x => -x) = ν := by\n rw [hν, gaussianReal_map_neg]; norm_num\n have hIci : ν (Set.Ici (0:ℝ)) = ν (Set.Iic 0) := by\n conv_lhs => rw [← hneg]\n rw [Measure.map_apply measurable_neg measurableSet_Ici]\n congr 1\n ext x\n simp\n haveI : NoAtoms ν := noAtoms_gaussianReal hv\n have hIic : ν (Set.Iic (0:ℝ)) = ν (Set.Iio 0) := by\n exact (measure_congr (MeasureTheory.Iio_ae_eq_Iic' (measure_singleton (0:ℝ)))).symm\n have hsum : ν (Set.Ici (0:ℝ)) + ν (Set.Iio 0) = 1 := by\n have := measure_add_measure_compl (μ := ν) (s := Set.Ici (0:ℝ)) measurableSet_Ici\n simpa using this\n have hfin : ν (Set.Ici (0:ℝ)) ≠ ⊤ := measure_ne_top _ _\n have hfin2 : ν (Set.Iio (0:ℝ)) ≠ ⊤ := measure_ne_top _ _\n have key : (ν (Set.Ici (0:ℝ))).toReal = 1/2 := by\n have h1 : (ν (Set.Ici (0:ℝ))).toReal + (ν (Set.Iio (0:ℝ))).toReal = 1 := by\n rw [← ENNReal.toReal_add hfin hfin2, hsum]; simp\n have h2 : (ν (Set.Ici (0:ℝ))).toReal = (ν (Set.Iio (0:ℝ))).toReal := by\n rw [hIci, hIic]\n linarith\n rw [hν, gaussianReal_apply_eq_integral _ hv] at key\n rw [ENNReal.toReal_ofReal (integral_nonneg (gaussianPDFReal_nonneg _ _))] at key\n exact key\n\n\nprivate lemma tail_bounds (v : NNReal) (hv : v ≠ 0) (m ε : ℝ) (hε : 0 < ε) :\n 0.5 * Real.exp (-(ε + √(v:ℝ))^2 / (2*(v:ℝ)))\n ≤ (gaussianReal m v (Set.Ici (m+ε))).toReal ∧\n (gaussianReal m v (Set.Ici (m+ε))).toReal\n ≤ 0.5 * Real.exp (-ε^2/(2*(v:ℝ))) := by\n have hV : 0 < (v:ℝ) := lt_of_le_of_ne v.coe_nonneg (by simpa [eq_comm, NNReal.coe_eq_zero] using hv)\n set V : ℝ := (v:ℝ) with hVdef\n set c : ℝ := (√(2 * π * V))⁻¹ with hc\n have hcpos : 0 < c := by\n rw [hc]; positivity\n have hmap : (gaussianReal (-ε) v).map (· + (m+ε)) = gaussianReal m v := by\n rw [gaussianReal_map_add_const]; congr 1; ring\n have hred : gaussianReal m v (Set.Ici (m+ε)) = gaussianReal (-ε) v (Set.Ici 0) := by\n rw [← hmap, Measure.map_apply (by fun_prop) measurableSet_Ici]\n congr 1\n ext x\n simp\n have hint : (gaussianReal m v (Set.Ici (m+ε))).toReal\n = ∫ x in Set.Ici (0:ℝ), gaussianPDFReal (-ε) v x := by\n rw [hred, gaussianReal_apply_eq_integral _ hv,\n ENNReal.toReal_ofReal (integral_nonneg (fun x => gaussianPDFReal_nonneg _ _ _))]\n have hInt1 : IntegrableOn (gaussianPDFReal (-ε) v) (Set.Ici (0:ℝ)) :=\n (integrable_gaussianPDFReal _ _).restrict\n have hpdf : ∀ (a x : ℝ), gaussianPDFReal a v x = c * Real.exp (-(x-a)^2/(2*V)) := by\n intro a x; rw [gaussianPDFReal, hc, hVdef]\n constructor\n · -- lower bound\n rw [hint]\n set b := √V with hb\n have hbpos : 0 < b := Real.sqrt_pos.2 hV\n have hb2 : b^2 = V := Real.sq_sqrt hV.le\n set K := Real.exp (-(2*ε*b + ε^2)/(2*V)) with hK\n have hKpos : 0 < K := Real.exp_pos _\n have step1 : ∫ x in Set.Icc (0:ℝ) b, gaussianPDFReal (-ε) v x\n ≤ ∫ x in Set.Ici (0:ℝ), gaussianPDFReal (-ε) v x := by\n refine setIntegral_mono_set hInt1\n (Filter.Eventually.of_forall (fun x => gaussianPDFReal_nonneg _ _ _)) ?_\n exact HasSubset.Subset.eventuallyLE (fun x hx => hx.1)\n have step2 : ∫ x in Set.Icc (0:ℝ) b, K * c * (1 - x^2/(2*V))\n ≤ ∫ x in Set.Icc (0:ℝ) b, gaussianPDFReal (-ε) v x := by\n refine setIntegral_mono_on ?_ ((integrable_gaussianPDFReal _ _).restrict)\n measurableSet_Icc ?_\n · exact (Continuous.integrableOn_Icc (by fun_prop))\n · intro x hx\n obtain ⟨hx0, hxb⟩ := hx\n rw [hpdf]\n have h1 : K * c * (1 - x^2/(2*V)) ≤ K * c * Real.exp (-x^2/(2*V)) := by\n refine mul_le_mul_of_nonneg_left ?_ (by positivity)\n have h0 := Real.add_one_le_exp (-x^2/(2*V))\n simp only [neg_div] at h0 ⊢\n linarith\n refine h1.trans ?_\n have heq : K * c * Real.exp (-x^2/(2*V))\n = c * Real.exp (-(2*ε*b + ε^2)/(2*V) + -x^2/(2*V)) := by\n rw [hK, Real.exp_add]; ring\n rw [heq]\n refine mul_le_mul_of_nonneg_left (Real.exp_le_exp.2 ?_) hcpos.le\n rw [← add_div, div_le_div_iff_of_pos_right (by positivity : (0:ℝ) < 2*V)]\n nlinarith [hε.le, hx0, hxb]\n have step3 : ∫ x in Set.Icc (0:ℝ) b, K * c * (1 - x^2/(2*V)) = K * c * (b * (5/6)) := by\n rw [MeasureTheory.integral_Icc_eq_integral_Ioc,\n ← intervalIntegral.integral_of_le hbpos.le]\n have hderiv : ∀ x ∈ Set.uIcc (0:ℝ) b,\n HasDerivAt (fun y : ℝ => K * c * (y - y^3/(6*V))) (K * c * (1 - x^2/(2*V))) x := by\n intro x _\n have h := (((hasDerivAt_id x).sub ((hasDerivAt_pow 3 x).div_const (6*V))).const_mul (K*c))\n convert h using 1\n push_cast\n field_simp\n ring\n rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hderiv\n ((Continuous.intervalIntegrable (by fun_prop)) _ _)]\n have : b^3 = b * V := by nlinarith [hb2]\n rw [this]\n field_simp\n ring\n have step4 : 0.5 * Real.exp (-(ε + b)^2/(2*V)) ≤ K * c * (b * (5/6)) := by\n have hcb : c * b = (√(2*π))⁻¹ := by\n rw [hc, hb, show (2:ℝ) * π * V = (2*π) * V by ring, Real.sqrt_mul (by positivity)]\n field_simp\n have hexp : Real.exp (-(ε + b)^2/(2*V)) = K * Real.exp (-(1/2)) := by\n rw [hK, ← Real.exp_add]\n congr 1\n field_simp\n nlinarith [hb2]\n rw [hexp]\n have hnum : 0.5 * Real.exp (-(1/2:ℝ)) ≤ (√(2*π))⁻¹ * (5/6) := by\n have hs : 0 < √(2*π) := by positivity\n have he : 0 < Real.exp (1/2 : ℝ) := Real.exp_pos _\n have hsq : √(2*π) ≤ 2.51 := by\n rw [show (2.51:ℝ) = √(2.51^2) by rw [Real.sqrt_sq]; norm_num]\n apply Real.sqrt_le_sqrt\n nlinarith [Real.pi_lt_d2]\n have h4 : (1.25:ℝ) ≤ Real.exp (1/4 : ℝ) := by\n linarith [Real.add_one_le_exp (1/4 : ℝ)]\n have hhalf : (1.5625:ℝ) ≤ Real.exp (1/2 : ℝ) := by\n have : Real.exp (1/2 : ℝ) = Real.exp (1/4:ℝ) * Real.exp (1/4:ℝ) := by\n rw [← Real.exp_add]; norm_num\n rw [this]; nlinarith [h4]\n rw [Real.exp_neg,\n show (0.5:ℝ) * (Real.exp (1/2:ℝ))⁻¹ = 0.5 / Real.exp (1/2:ℝ) by ring,\n show (√(2*π))⁻¹ * (5/6) = (5/6) / √(2*π) by ring,\n div_le_div_iff₀ he hs]\n nlinarith [hsq, hhalf, hs, he]\n calc 0.5 * (K * Real.exp (-(1/2:ℝ))) = K * (0.5 * Real.exp (-(1/2:ℝ))) := by ring\n _ ≤ K * ((√(2*π))⁻¹ * (5/6)) := by exact mul_le_mul_of_nonneg_left hnum hKpos.le\n _ = K * c * (b * (5/6)) := by rw [← hcb]; ring\n calc 0.5 * Real.exp (-(ε + b)^2/(2*V)) ≤ K * c * (b*(5/6)) := step4\n _ = ∫ x in Set.Icc (0:ℝ) b, K * c * (1 - x^2/(2*V)) := step3.symm\n _ ≤ ∫ x in Set.Icc (0:ℝ) b, gaussianPDFReal (-ε) v x := step2\n _ ≤ _ := step1\n · -- upper bound\n rw [hint]\n have h1 : ∫ x in Set.Ici (0:ℝ), gaussianPDFReal (-ε) v x\n ≤ ∫ x in Set.Ici (0:ℝ), Real.exp (-ε^2/(2*V)) * gaussianPDFReal 0 v x := by\n refine setIntegral_mono_on hInt1 ?_ measurableSet_Ici ?_\n · exact ((integrable_gaussianPDFReal _ _).const_mul _).restrict\n · intro x hx\n simp only [Set.mem_Ici] at hx\n rw [hpdf, hpdf, ← mul_assoc, mul_comm (Real.exp _) c, mul_assoc, ← Real.exp_add]\n refine mul_le_mul_of_nonneg_left (Real.exp_le_exp.2 ?_) hcpos.le\n rw [div_add_div_same, div_le_div_iff_of_pos_right (by positivity)]\n nlinarith [hx, hε.le]\n rw [integral_const_mul, half_int v hv] at h1\n calc ∫ x in Set.Ici (0:ℝ), gaussianPDFReal (-ε) v x ≤ Real.exp (-ε^2/(2*V)) * (1/2) := h1\n _ = 0.5 * Real.exp (-ε^2/(2*V)) := by ring\n\n\ntheorem theorem_2_1 {Ω : Type*} [MeasurableSpace Ω]\n (P : Measure Ω) [IsProbabilityMeasure P]\n (n : ℕ) (μ σ : ℝ) (X : Fin n → Ω → ℝ)\n (hσ : 0 < σ) (hn : 0 < n)\n (hX_meas : ∀ i, Measurable (X i))\n (hX_indep : ProbabilityTheory.iIndepFun X P)\n (hX_gaussian :\n ∀ i, MeasureTheory.Measure.map (X i) P =\n ProbabilityTheory.gaussianReal μ (Real.toNNReal (σ ^ 2))) :\n ∀ ε : ℝ, 0 < ε →\n 0.5 * Real.exp (-(n : ℝ) * (ε + σ / Real.sqrt (n : ℝ)) ^ 2 / (2 * σ ^ 2)) ≤\n (P {ω : Ω | μ + ε ≤ sampleMean X ω}).toReal ∧\n (P {ω : Ω | μ + ε ≤ sampleMean X ω}).toReal ≤\n 0.5 * Real.exp (-(n : ℝ) * ε ^ 2 / (2 * σ ^ 2)) := by\n intro ε hε\n have hn' : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn\n set c : ℝ := 1 / (n:ℝ) with hcdef\n have hSmeas : Measurable (fun ω => ∑ i, X i ω) := by\n apply Finset.measurable_sum\n intro i _\n exact hX_meas i\n have hsum := map_sum_gauss P X μ (Real.toNNReal (σ^2)) hX_meas hX_indep hX_gaussian Finset.univ\n rw [Finset.card_univ, Fintype.card_fin] at hsum\n set v : NNReal := ⟨c^2, sq_nonneg _⟩ * ((n : NNReal) * Real.toNNReal (σ^2)) with hvdef\n have hmapmean : P.map (sampleMean X) = gaussianReal μ v := by\n have : sampleMean X = (fun x : ℝ => c * x) ∘ (fun ω => ∑ i, X i ω) := by\n funext ω; simp [sampleMean, hcdef]\n rw [this, ← Measure.map_map (by fun_prop) hSmeas, hsum, gaussianReal_map_const_mul]\n congr 1\n · rw [hcdef]; field_simp\n have hvcoe : ((v : NNReal) : ℝ) = σ^2 / (n:ℝ) := by\n rw [hvdef]\n push_cast [Real.coe_toNNReal _ (sq_nonneg σ)]\n rw [hcdef]\n field_simp\n have hvne : v ≠ 0 := by\n have hpos : ((v : NNReal) : ℝ) ≠ 0 := by rw [hvcoe]; positivity\n intro h\n apply hpos\n rw [h]\n simp\n have hset : P {ω : Ω | μ + ε ≤ sampleMean X ω} = gaussianReal μ v (Set.Ici (μ + ε)) := by\n have hmeas : Measurable (sampleMean X) := by\n have : sampleMean X = fun ω => c * ∑ i, X i ω := by funext ω; simp [sampleMean, hcdef]\n rw [this]; fun_prop\n rw [← hmapmean, Measure.map_apply hmeas measurableSet_Ici]\n rfl\n have key := tail_bounds v hvne μ ε hε\n rw [← hset] at key\n have hsq : √(σ^2/(n:ℝ)) = σ / √(n:ℝ) := by\n rw [Real.sqrt_div (sq_nonneg σ), Real.sqrt_sq hσ.le]\n rw [hvcoe, hsq] at key\n have e1 : -ε^2/(2*(σ^2/(n:ℝ))) = -(n:ℝ) * ε^2/(2*σ^2) := by\n field_simp\n have e2 : -(ε + σ/√(n:ℝ))^2/(2*(σ^2/(n:ℝ))) = -(n:ℝ) * (ε + σ/√(n:ℝ))^2/(2*σ^2) := by\n field_simp\n rw [e1, e2] at key\n exact key\n\nend GraduateLevel\n"} +{"id": "ch8_corollary_8_3", "source": "Graduate-level", "targets": [{"label": "ch8_corollary_8_3", "decls": ["ch8_corollary_8_3"], "statement": "Consider a countable family of approximate ERM algorithms \\(\\{\\mathcal{A}(\\theta, \\cdot): \\theta = 1, 2, \\ldots\\}\\), each characterized by its model space \\(\\mathcal{F}(\\theta)\\), and returns a function \\(\\hat{f}_{\\theta} \\in \\mathcal{F}(\\theta)\\) such that\n\\[\n\\phi(\\hat{f},\\mathcal{S}_{n})\\leq\\inf_{f\\in\\mathcal{F}(\\theta)}\\phi(f,\\mathcal{S}_{n})+\\epsilon^{\\prime},\n\\]\nwhere we use the notation of Definition 8.1.\nAssume further that \\(\\sup_{Z,Z'}[\\phi(f,Z) - \\phi(f,Z')]\\leq M\\) for all \\(f\\), and we use (8.2) to select the best model \\(\\hat{\\theta}\\) on the validation data \\(\\bar{S}_m\\), with the choice\n\\[\nr_{m}(q)=M\\sqrt{\\frac{\\ln(1/q)}{2 m}}.\n\\]\nThen the following result holds with probability at least \\(1 - \\delta\\) over random selection\nof \\(S_{n}\\) and \\(\\bar{S}_m\\) ..\n\\[\n\\begin{array}{l}\\phi(\\mathcal{A}(\\hat{\\theta},\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{\\theta}\\left[\\inf_{f\\in\\mathcal{F}(\\theta)}\\phi(f,\\mathcal{D})+2 R_{n}(\\mathcal{G}(\\theta),\\mathcal{D})+r_{m}(q(\\theta))\\right]\\\\ +\\tilde{\\epsilon}+\\epsilon^{\\prime}+M\\sqrt{\\frac{2\\ln(4/\\delta)}{n}}+M\\sqrt{\\frac{2\\ln(4/\\delta)}{m}},\\\\ \\end{array}\n\\]\nwhere \\( R_{n}(\\mathcal{G}(\\theta),\\mathcal{D}) \\) is the Rademacher complexity of \\( \\mathcal{G}(\\theta) = \\{\\phi (f,\\cdot):f\\in \\mathcal{F}(\\theta)\\} \\) and \\( q(\\theta) \\) satisfies (8.1).", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Generalization & Learnability"}], "nl_proof": "Consider any model \\(\\theta\\). We have from Theorem 8.2 that with probability \\(1 - \\delta / 2\\),\n\\[\n\\phi(\\mathcal{A}(\\hat{\\theta},\\mathcal{S}_{n}),\\mathcal{D})\\leq [\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})+r_{m}(q(\\theta))]+\\tilde{\\epsilon}+M\\sqrt{\\frac{2\\ln(4/\\delta)}{m}}.\n\\]\nMoreover, from Corollary 6.21 with \\( h(\\cdot) = 0 \\), we know that with probability at least \\( 1 - \\delta / 2 \\):\n\\[\n\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{f\\in\\mathcal{F}(\\theta)}\\phi(f,\\mathcal{D})+\\epsilon^{\\prime}+2 R_{n}(\\mathcal{G}(\\theta),\\mathcal{D})+2 M\\sqrt{\\frac{\\ln(4/\\delta)}{2 n}}.\n\\]\nTaking the union bound, both inequalities hold with probability at least \\(1 - \\delta\\), which leads to the desired bound.", "context": [{"id": "ch8:definition:8_1", "name": "definition 8.1", "statement": "Consider a loss function \\(\\phi(f, z): \\mathcal{F} \\times \\mathcal{Z} \\to \\mathbb{R}\\), and a model family \\(\\{\\mathcal{A}(\\theta, S_n): \\Theta \\times \\mathcal{Z}^n \\to \\mathcal{F}, n \\geq 0\\}\\). Consider \\(N \\geq n \\geq 0\\), and iid dataset \\(S_n \\subset S_N \\sim \\mathcal{D}^N\\). A model selection algorithm \\(\\bar{\\mathcal{A}}\\) maps \\(S_N\\) to \\(\\hat{\\theta} = \\hat{\\theta}(S_N) \\in \\Theta\\),\nand then train a model \\(\\hat{f} = \\mathcal{A}(\\hat{\\theta}(\\mathcal{S}_N), \\mathcal{S}_n) = \\bar{\\mathcal{A}}(\\mathcal{S}_N)\\). It satisfies an \\(\\epsilon_{n,N}(\\cdot, \\cdot)\\) oracle inequality if there exists \\(\\epsilon_{n,N}(\\theta, \\delta)\\), such that for all \\(\\delta \\in (0,1)\\), with probability at least \\(1 - \\delta\\) over \\(\\mathcal{S}_N\\):\n\\[\n\\phi(\\mathcal{A}(\\hat{\\theta}(\\mathcal{S}_{N}),\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{\\theta\\in\\Theta}[\\mathbb{E}_{\\mathcal{S}_{n}}\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})+\\epsilon_{n,N}(\\theta,\\delta)].\n\\]\nMore generally, a learning algorithm \\(\\bar{\\mathcal{A}}: S_N \\to \\mathcal{F}\\) is \\(\\epsilon_{n,N}(\\cdot, \\cdot)\\) adaptive to the model family \\(\\{\\mathcal{A}(\\theta, \\cdot): \\theta \\in \\Theta\\}\\) if there exists \\(\\epsilon_{n,N}(\\theta, \\delta)\\), such that for all \\(\\delta \\in (0,1)\\), with probability at least \\(1 - \\delta\\) over \\(S_N\\):\n\\[\n\\phi(\\bar{\\mathcal{A}}(\\mathcal{S}_{N}),\\mathcal{D})\\leq\\inf_{\\theta\\in\\Theta}\\left[\\mathbb{E}_{\\mathcal{S}_{n}}\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})+\\epsilon_{n,N}(\\theta,\\delta)\\right].\n\\]\nNote that we have used a slightly different notation \\(\\phi(f, Z)\\), instead of \\(\\phi(w, Z)\\) as in earlier chapters, to emphasize that in model selection, the prediction function \\(f(w, \\cdot)\\) from different models can be compared, but the parameter \\(w\\) of the functions may not be comparable when different models have different functional forms such as decision trees versus neural networks. Without causing confusion, one may consider \\(f\\) to be the function represented by \\(w\\), so that \\(\\phi(f, Z) = L(f(X), Y)\\) and \\(\\phi(w, Z) = L(f(w, X), Y)\\). Similar to Definition 3.8, we use the simplified notation\n\\[\n\\phi(f,\\mathcal{D})=\\mathbb{E}_{Z\\sim\\mathcal{D}}\\phi(f,Z),\\quad\\phi(f,\\mathcal{S}_{n})=\\frac{1}{n}\\sum_{Z\\in\\mathcal{S}_{n}}\\phi(f,Z).\n\\]\nThe concept adaptivity is more general than model selection, as the algorithm does not need to choose a specific model \\(\\mathcal{A}(\\theta,\\cdot)\\) indexed by \\(\\theta\\). For example, a commonly used method to achieve adaptivity is model averaging, where we take the average of several different model outputs \\(\\hat{f}_{\\theta_j} = \\mathcal{A}(\\theta_j,\\mathcal{S}_n)\\) as\n\\[\n\\hat{f}_{\\mathrm{avg}}(x)=\\frac{1}{k}\\sum_{j=1}^{k}\\hat{f}_{\\theta_{j}}(x).\n\\]\nIf different models have the same functional form, with a vector model parameter \\( w \\in \\mathbb{R}^d \\): \\( \\hat{f}_{\\theta_j}(x) = f(\\hat{w}_j, x) \\). Then one may also average the model parameters as follows:\n\\[\n\\hat{w}_{\\mathrm{avg}}=\\frac{1}{k}\\sum_{j=1}^{k}\\hat{w}_{j}.\n\\]\nIn general, the training data \\( S_{n} \\) is a subset of \\( S_{N} \\), and we allow \\( n < N \\) in order to analyze validation methods which are commonly used in practice. In addition to the large probability bounds in Definition 8.1, one may also derive bounds that hold for expectation over \\( S_{N} \\)."}, {"id": "ch8:theorem:8_2", "name": "Model Selction on Validation Data", "statement": "Assume \\(\\sup_{Z,Z'}[\\phi(f,Z) - \\phi(f,Z')] \\leq M\\) for all \\(f\\), and the validation data \\(\\bar{S}_m\\) contains \\(m\\) iid samples from \\(\\mathcal{D}\\). Given training data \\(S_n\\), consider (8.2) with\n\\[\nr_{m}(q)=M\\sqrt{\\frac{\\ln(1/q)}{2 m}}.\n\\]\nThen with probability at least \\(1 - \\delta\\) over the random selection of \\(S_{m}\\):\n\\[\n\\phi(\\mathcal{A}(\\hat{\\theta},\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{\\theta}Q(\\theta,\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\bar{\\mathcal{S}}_{m})+\\tilde{\\epsilon}+M\\sqrt{\\frac{\\ln(1/\\delta)}{2 m}}.\n\\]\nThis implies the following oracle inequality. With probability at least \\(1 - \\delta\\) over the random sampling of \\(\\bar{S}_m\\):\n\\[\n\\phi(\\mathcal{A}(\\hat{\\theta},\\mathcal{S}_{n}),\\mathcal{D})\\leq\\inf_{\\theta}[\\phi(\\mathcal{A}(\\theta,\\mathcal{S}_{n}),\\mathcal{D})+r_{m}(q(\\theta))]+\\tilde{\\epsilon}+M\\sqrt{\\frac{2\\ln(2/\\delta)}{m}},\n\\]\nwhere \\(q(\\theta)\\) satisfies (8.1)."}, {"id": "ch6:corollary:6_21", "name": "corollary 6.21", "statement": "Assume that for some \\(M \\geq 0\\):\n\\[\n\\sup_{w\\in\\Omega}\\left[\\sup_{z,z^{\\prime}}[\\phi(w,z)-\\phi(w,z^{\\prime})]+\\Delta_{n}h(w)\\right]\\leq M.\n\\]\nThen the approximate ERM method (6.1) satisfies the following oracle inequality. With probability at least \\( 1 - \\delta - \\delta' \\):\n\\[\n\\begin{array}{l}\\phi(\\hat{w},\\mathcal{D})\\leq\\inf_{w\\in\\Omega}\\left[\\phi(w,\\mathcal{D})+\\mathbb{E}_{\\mathcal{S}_{n}}h(w,\\mathcal{S}_{n})+\\Delta_{n}h(w)\\sqrt{\\frac{\\ln\\left(1/\\delta^{\\prime}\\right)}{2 n}}\\right]\\\\ +\\epsilon^{\\prime}+\\epsilon_{n}^{h}(\\mathcal{G},\\mathcal{D})+2 M\\sqrt{\\frac{\\ln(2/\\delta)}{2 n}}.\\\\ \\end{array}\n\\]\nIf \\( h(\\cdot) \\) has the decomposition (6.3), then\n\\[\n\\begin{array}{l}\\phi(\\hat{w},\\mathcal{D})\\leq\\inf_{w\\in\\Omega}\\left[\\phi(w,\\mathcal{D})+\\mathbb{E}_{\\mathcal{S}_{n}}h(w,\\mathcal{S}_{n})+\\Delta_{n}h(w)\\sqrt{\\frac{\\ln(1/\\delta^{\\prime})}{2 n}}\\right]\\\\ +\\epsilon^{\\prime}+2 R_{n}^{h}(\\mathcal{G},\\mathcal{D})+2 M\\sqrt{\\frac{\\ln(2/\\delta)}{2 n}}.\\\\ \\end{array}\n\\]"}, {"id": "ch3:proposition:3_5", "name": "Union Bound", "statement": "(Union Bound) Consider \\(m\\) events \\(E_1, \\ldots, E_m\\). The following probability inequality holds:\n\\[\n\\Pr (E_1 \\cup \\cdots \\cup E_m) \\leq \\sum_{j=1}^{m} \\Pr(E_j).\n\\]\n\nThe union bound has an alternative expression, which is often used in the learning theory analysis. If each \\(E_j\\) occurs with probability at least \\(1-\\delta_j\\) for \\(j=1, \\ldots, m\\), then with probability at least \\(1-\\sum_{j=1}^{m} \\delta_j\\), all of events \\(\\{E_j\\}\\) occur simultaneously for \\(j=1, \\ldots, m\\)."}, {"id": "ch6:definition:6_3", "name": "definition 6.3", "statement": "Given \\(S_{n}=\\{Z_{1},\\ldots,Z_{n}\\}\\), the (one-sided) empirical Rademacher complexity of \\(\\mathcal{G}\\) is defined as\n\\[\nR(\\mathcal{G},\\mathcal{S}_{n}) = \\mathbb{E}_{\\sigma}\\sup_{w\\in \\Omega}\\frac{1}{n}\\sum_{i = 1}^{n}\\sigma_{i}\\phi (w,Z_{i}),\n\\]\nwhere \\(\\sigma_1, \\ldots, \\sigma_n\\) are independent uniform \\(\\{\\pm 1\\}\\)-valued Bernoulli random variables. Moreover, the expected Rademacher complexity is\n\\[\nR_{n}(\\mathcal{G},\\mathcal{D})=\\mathbb{E}_{\\mathcal{S}_{n}\\sim\\mathcal{D}^{n}}R(\\mathcal{G},\\mathcal{S}_{n}).\n\\]"}, {"id": "ch8:equation:8_1", "name": "equation (8.1)", "statement": "Let \\(q(\\theta)\\geq 0\\) for \\(\\theta = 1,2,\\ldots\\) satisfy\n\\[\n\\sum_{\\theta=1}^{\\infty} q(\\theta) \\leq 1. \\tag{8.1}\n\\]"}, {"id": "ch8:equation:8_2", "name": "equation (8.2)", "statement": "Given training data \\(S_n\\) and validation data \\(\\bar{S}_m\\), define the validation objective\n\\[\nQ(\\theta, f, \\bar{\\mathcal{S}}_m) = \\phi(f, \\bar{\\mathcal{S}}_m) + r_m(q(\\theta)).\n\\]\nWe select \\(\\hat{\\theta}\\) by approximate minimization:\n\\[\nQ(\\hat{\\theta}, \\mathcal{A}(\\hat{\\theta}, \\mathcal{S}_n), \\bar{\\mathcal{S}}_m) \\leq \\inf_{\\theta} Q(\\theta, \\mathcal{A}(\\theta, \\mathcal{S}_n), \\bar{\\mathcal{S}}_m) + \\tilde{\\epsilon}. \\tag{8.2}\n\\]\nHere \\(\\tilde{\\epsilon}\\) is the additive slack in the validation-based model-selection rule."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\nnoncomputable def rmPenalty (M : ℝ) (m : ℕ) (q : ℝ) : ℝ :=\n M * Real.sqrt (Real.log (1 / q) / (2 * m))\n\nnoncomputable def radCx {Z Pred : Type*} [MeasurableSpace Z]\n (n : ℕ) (φ : Pred → Z → ℝ) (F : Set Pred) (D : Measure Z) : ℝ :=\n popRadSigned n (fun f : F => fun z => φ (f : Pred) z) D id\n\n\ntheorem ch8_corollary_8_3\n {Z Pred : Type*} [MeasurableSpace Z] [Nonempty Z] [MeasurableSpace Pred]\n (D : Measure Z) [IsProbabilityMeasure D]\n (φ : Pred → Z → ℝ)\n (F : ℕ+ → Set Pred)\n (hFne : ∀ θ, (F θ).Nonempty)\n (hint : ∀ f, Integrable (fun z => φ f z) D)\n (M ε' εt δ : ℝ) (n m : ℕ)\n (hn : 0 < n) (hm : 0 < m)\n (hδ : 0 < δ ∧ δ < 1)\n (hM : ∀ f, ∀ z z' : Z, φ f z - φ f z' ≤ M)\n (hBddAbove : ∀ (θ : ℕ+) (s : Fin n → Z) (σ : RadSigns n),\n BddAbove (Set.range (fun f : F θ =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * φ (f : Pred) (s k))))\n (hRadInt : ∀ θ : ℕ+, Integrable\n (fun s : Fin n → Z => empRadSigned n\n (fun f : F θ => fun z => φ (f : Pred) z) s)\n (Measure.pi (fun _ : Fin n => D)))\n (q : ℕ+ → ℝ) (hq_pos : ∀ θ, 0 < q θ)\n (hq_summable : Summable q)\n (hq_sum : ∑' θ, q θ ≤ 1)\n {Ωs : Type*} [MeasurableSpace Ωs] (P : Measure Ωs) [IsProbabilityMeasure P]\n (Strain : Ωs → Fin n → Z) (Sval : Ωs → Fin m → Z)\n (hStrain_meas : Measurable Strain) (hSval_meas : Measurable Sval)\n (hStrain_law : ∀ i, Measure.map (fun ω => Strain ω i) P = D)\n (hSval_law : ∀ i, Measure.map (fun ω => Sval ω i) P = D)\n (hStrain_indep : iIndepFun (fun i ω => Strain ω i) P)\n (hSval_indep : iIndepFun (fun i ω => Sval ω i) P)\n (hSplit_indep : IndepFun Strain Sval P)\n (A : ℕ+ → (Fin n → Z) → Pred) (hA_mem : ∀ θ s, A θ s ∈ F θ)\n (hA_meas : ∀ θ, Measurable (A θ))\n\n (hφ_meas : Measurable (fun p : Pred × Z => φ p.1 p.2))\n (hERM : ∀ θ s, (n:ℝ)⁻¹ * ∑ i, φ (A θ s) (s i) ≤ (⨅ f : F θ, (n:ℝ)⁻¹ * ∑ i, φ (f:Pred) (s i)) + ε')\n (thetaHat : (Fin n → Z) → (Fin m → Z) → ℕ+)\n\n (hSel : ∀ s v, ((m:ℝ)⁻¹ * ∑ i, φ (A (thetaHat s v) s) (v i) + rmPenalty M m (q (thetaHat s v))) ≤ (⨅ θ:ℕ+, ((m:ℝ)⁻¹ * ∑ i, φ (A θ s) (v i) + rmPenalty M m (q θ))) + εt)\n (hbddSel : ∀ (s : Fin n → Z) (v : Fin m → Z), BddBelow (Set.range (fun θ : ℕ+ =>\n (m:ℝ)⁻¹ * ∑ i, φ (A θ s) (v i) + rmPenalty M m (q θ))))\n (hbddOracle : BddBelow (Set.range (fun θ : ℕ+ =>\n (⨅ f : F θ, ∫ z, φ (f:Pred) z ∂D) + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ)))) :\n 1 - δ ≤ (P {ω : Ωs | ∫ z, φ (A (thetaHat (Strain ω) (Sval ω)) (Strain ω)) z ∂D ≤ (⨅ θ:ℕ+, ((⨅ f : F θ, ∫ z, φ (f:Pred) z ∂D) + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ))) + εt + ε' + M * Real.sqrt (2 * Real.log (4/δ) / n) + M * Real.sqrt (2 * Real.log (4/δ) / m)}).toReal := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real\nopen scoped ENNReal NNReal\n\nset_option maxHeartbeats 2000000\n\nnamespace GraduateLevel\n\ndef RadSigns (n : ℕ) : Type := Fin n → ({-1, 1} : Finset ℤ)\n\ninstance {n} : Fintype (RadSigns n) :=\n inferInstanceAs (Fintype (Fin n → { x // x ∈ {-1, 1} }))\n\nnoncomputable def empRadSigned {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (S : Fin n → 𝒳) : ℝ :=\n (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * f i (S k)\n\nnoncomputable def popRadSigned {Ω : Type*} [MeasurableSpace Ω] {ι : Type*} {𝒳 : Type*}\n (n : ℕ) (f : ι → 𝒳 → ℝ) (μ : Measure Ω) (X : Ω → 𝒳) : ℝ :=\n ∫ ω : Fin n → Ω, empRadSigned n f (X ∘ ω) ∂(Measure.pi fun _ => μ)\n\nnoncomputable def rmPenalty (M : ℝ) (m : ℕ) (q : ℝ) : ℝ :=\n M * Real.sqrt (Real.log (1 / q) / (2 * m))\n\nnoncomputable def radCx {Z Pred : Type*} [MeasurableSpace Z]\n (n : ℕ) (φ : Pred → Z → ℝ) (F : Set Pred) (D : Measure Z) : ℝ :=\n popRadSigned n (fun f : F => fun z => φ (f : Pred) z) D id\n\n\n/-! ## Auxiliary results -/\n\nnamespace Ch8Aux\n\ntheorem abs_integral_le {α : Type*} [MeasurableSpace α] (ν : Measure α) [IsProbabilityMeasure ν]\n (f : α → ℝ) (C : ℝ) (hf : ∀ x, |f x| ≤ C) : |∫ x, f x ∂ν| ≤ C := by\n have h := norm_integral_le_of_norm_le_const (μ := ν) (f := f) (C := C)\n (Filter.Eventually.of_forall (fun x => by simpa [Real.norm_eq_abs] using hf x))\n simpa [Real.norm_eq_abs] using h\n\ntheorem integrable_of_abs_le {α : Type*} [MeasurableSpace α] (ν : Measure α) [IsFiniteMeasure ν]\n {f : α → ℝ} (hf : Measurable f) (C : ℝ) (h : ∀ x, |f x| ≤ C) : Integrable f ν :=\n Integrable.of_mem_Icc (-C) C hf.aemeasurable\n (Filter.Eventually.of_forall (fun x => ⟨(abs_le.1 (h x)).1, (abs_le.1 (h x)).2⟩))\n\ntheorem ae_comp_of_measurePreserving {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]\n {ν₁ : Measure α} {ν₂ : Measure β} {f : α → ��} (hf : MeasurePreserving f ν₁ ν₂)\n {p : β → Prop} (hp : MeasurableSet {x | p x}) (h : ∀ᵐ y ∂ν₂, p y) : ∀ᵐ x ∂ν₁, p (f x) := by\n rw [← hf.map_eq] at h\n exact (ae_map_iff hf.measurable.aemeasurable hp).1 h\n\ntheorem measurable_updatePair {Y : Type*} [MeasurableSpace Y] {n : ℕ} [DecidableEq (Fin n)]\n (k : Fin n) :\n Measurable (fun p : (Fin n → Y) × Y => Function.update p.1 k p.2) := by\n refine measurable_pi_lambda _ (fun j => ?_)\n by_cases hj : j = k\n · subst hj\n simpa using measurable_snd\n · simp only [Function.update_of_ne hj]\n exact (measurable_pi_apply j).comp measurable_fst\n\ntheorem integral_comp_mp {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α}\n {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) {f : β → ℝ}\n (hf : AEStronglyMeasurable f ν) : ∫ x, f (g x) ∂μ = ∫ y, f y ∂ν := by\n conv_rhs => rw [← hg.map_eq]\n rw [integral_map hg.measurable.aemeasurable (by rwa [hg.map_eq])]\n\ntheorem integrable_comp_mp {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α}\n {ν : Measure β} {g : α → β} (hg : MeasurePreserving g μ ν) {f : β → ℝ}\n (hf : Integrable f ν) : Integrable (fun x => f (g x)) μ := by\n have h1 : Integrable f (Measure.map g μ) := by rw [hg.map_eq]; exact hf\n exact (integrable_map_measure h1.1 hg.measurable.aemeasurable).1 h1\n\ntheorem integral_eval_pi {Z : Type*} [MeasurableSpace Z] (D : Measure Z) [IsProbabilityMeasure D]\n {n : ℕ} (k : Fin n) (f : Z → ℝ) (hf : AEStronglyMeasurable f D) :\n ∫ s : Fin n → Z, f (s k) ∂(Measure.pi fun _ : Fin n => D) = ∫ z, f z ∂D := by\n have hmp := measurePreserving_eval (fun _ : Fin n => D) k\n conv_rhs => rw [← hmp.map_eq]\n rw [integral_map (measurable_pi_apply k).aemeasurable (by rwa [hmp.map_eq])]\n\ntheorem integrable_eval_pi {Z : Type*} [MeasurableSpace Z] (D : Measure Z)\n [IsProbabilityMeasure D] {n : ℕ} (k : Fin n) (f : Z → ℝ) (hf : Integrable f D) :\n Integrable (fun s : Fin n → Z => f (s k)) (Measure.pi fun _ : Fin n => D) := by\n have hmp := measurePreserving_eval (fun _ : Fin n => D) k\n have h1 : Integrable f (Measure.map (Function.eval k) (Measure.pi fun _ : Fin n => D)) := by\n rw [hmp.map_eq]; exact hf\n exact (integrable_map_measure h1.1 (measurable_pi_apply k).aemeasurable).1 h1\n\ntheorem measurePreserving_comp_perm {ι : Type*} [Fintype ι] [DecidableEq ι]\n {Y : Type*} [MeasurableSpace Y] (μ : Measure Y) [IsProbabilityMeasure μ] (e : ι ≃ ι) :\n MeasurePreserving (fun w : ι → Y => w ∘ e) (Measure.pi fun _ : ι => μ)\n (Measure.pi fun _ : ι => μ) := by\n have hmeas : Measurable (fun w : ι → Y => w ∘ (e : ι → ι)) :=\n measurable_pi_lambda _ (fun i => measurable_pi_apply (e i))\n refine ⟨hmeas, (Measure.pi_eq (fun s hs => ?_)).symm⟩\n have hpre : (fun w : ι → Y => w ∘ (e : ι → ι)) ⁻¹' (Set.univ.pi s)\n = Set.univ.pi (fun j => s (e.symm j)) := by\n ext w\n simp only [Set.mem_preimage, Set.mem_univ_pi, Function.comp_apply]\n constructor\n · intro h j; simpa using h (e.symm j)\n · intro h i; simpa using h (e i)\n rw [Measure.map_apply hmeas (MeasurableSet.univ_pi hs), hpre, Measure.pi_pi]\n exact Fintype.prod_equiv e.symm _ _ (fun j => rfl)\ndef negSign {n : ℕ} (σ : RadSigns n) : RadSigns n := fun k =>\n ⟨-(σ k : ℤ), by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h ⊢\n rcases h with h | h <;> simp [h]⟩\n\n@[simp] lemma negSign_coe {n : ℕ} (σ : RadSigns n) (k : Fin n) :\n ((negSign σ k : ℤ) : ℝ) = -((σ k : ℤ) : ℝ) := by\n simp [negSign]\n\ndef negSignEquiv (n : ℕ) : RadSigns n ≃ RadSigns n where\n toFun := negSign\n invFun := negSign\n left_inv := by intro σ; funext k; apply Subtype.ext; simp [negSign]\n right_inv := by intro σ; funext k; apply Subtype.ext; simp [negSign]\n\ntheorem card_radSigns_pos (n : ℕ) : 0 < Fintype.card (RadSigns n) :=\n Fintype.card_pos_iff.2 ⟨fun _ => ⟨1, by simp⟩⟩\n\n/-- The empirical Rademacher average is nonnegative. -/\ntheorem empRadSigned_nonneg {ι : Type*} [Nonempty ι] {𝒳 : Type*} (n : ℕ) (g : ι → 𝒳 → ℝ)\n (S : Fin n → 𝒳)\n (hbdd : ∀ σ : RadSigns n,\n BddAbove (Set.range (fun i => (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * g i (S k)))) :\n 0 ≤ empRadSigned n g S := by\n classical\n set h : RadSigns n → ℝ := fun σ => ⨆ i, (n : ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ) : ℝ) * g i (S k)\n with hh\n have key : ∀ σ : RadSigns n, 0 ≤ h σ + h (negSign σ) := by\n intro σ\n obtain ⟨i₀⟩ := ‹Nonempty ι›\n have h1 : (n : ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ) : ℝ) * g i₀ (S k) ≤ h σ :=\n le_ciSup (hbdd σ) i₀\n have h2 : (n : ℝ)⁻¹ * ∑ k : Fin n, ((negSign σ k : ℤ) : ℝ) * g i₀ (S k) ≤ h (negSign σ) :=\n le_ciSup (hbdd (negSign σ)) i₀\n have h3 : (n : ℝ)⁻¹ * ∑ k : Fin n, ((negSign σ k : ℤ) : ℝ) * g i₀ (S k)\n = -((n : ℝ)⁻¹ * ∑ k : Fin n, ((σ k : ℤ) : ℝ) * g i₀ (S k)) := by\n simp only [negSign_coe, neg_mul, Finset.sum_neg_distrib, mul_neg]\n rw [h3] at h2\n linarith\n have hsum : ∑ σ : RadSigns n, h σ = ∑ σ : RadSigns n, h (negSign σ) :=\n (Fintype.sum_equiv (negSignEquiv n) _ _ (fun σ => rfl)).symm\n have h2sum : 0 ≤ 2 * ∑ σ : RadSigns n, h σ := by\n have : ∑ σ : RadSigns n, (h σ + h (negSign σ)) = 2 * ∑ σ : RadSigns n, h σ := by\n rw [Finset.sum_add_distrib, ← hsum]; ring\n rw [← this]\n exact Finset.sum_nonneg (fun σ _ => key σ)\n have hcard : (0:ℝ) < (Fintype.card (RadSigns n) : ℝ) := by\n exact_mod_cast card_radSigns_pos n\n rw [show empRadSigned n g S = (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, h σ from rfl]\n exact mul_nonneg (le_of_lt (inv_pos.2 hcard)) (by linarith)\n\ntheorem sign_eq_one_or {n : ℕ} (σ : RadSigns n) (k : Fin n) :\n ((σ k : ℤ) : ℝ) = 1 ∨ ((σ k : ℤ) : ℝ) = -1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h\n · right; rw [h]; norm_num\n · left; rw [h]; norm_num\n\nsection Snoc\n\nvariable {Y : Type*} [MeasurableSpace Y] (μ : Measure Y) [IsProbabilityMeasure μ] (n : ℕ)\n\n/-- `(Fin (n+1) → Y) ≃ᵐ (Fin n → Y) × Y`, splitting off the last coordinate. -/\nnoncomputable def lastEquiv : (Fin (n + 1) → Y) ≃ᵐ (Fin n → Y) × Y :=\n (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) (Fin.last n)).trans\n (MeasurableEquiv.prodComm)\n\ntheorem lastEquiv_apply (w : Fin (n + 1) → Y) :\n lastEquiv (Y := Y) n w = (fun j : Fin n => w j.castSucc, w (Fin.last n)) := by\n simp [lastEquiv, Fin.init]\n rfl\n\ntheorem measurePreserving_lastEquiv :\n MeasurePreserving (lastEquiv (Y := Y) n) (Measure.pi fun _ : Fin (n+1) => μ)\n ((Measure.pi fun _ : Fin n => μ).prod μ) := by\n have h1 := measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => μ) (Fin.last n)\n have h2 : MeasurePreserving (Prod.swap : Y × (Fin n → Y) → (Fin n → Y) × Y)\n (μ.prod (Measure.pi fun _ : Fin n => μ)) ((Measure.pi fun _ : Fin n => μ).prod μ) :=\n Measure.measurePreserving_swap\n exact h2.comp h1\n\n/-- The \"resample coordinate `k`, remembering the old value\" map is measure preserving. -/\ntheorem measurePreserving_updateSwap {n : ℕ} (k : Fin n) :\n MeasurePreserving (fun p : (Fin n → Y) × Y => (Function.update p.1 k p.2, p.1 k))\n ((Measure.pi fun _ : Fin n => μ).prod μ)\n ((Measure.pi fun _ : Fin n => μ).prod μ) := by\n classical\n set e := lastEquiv (Y := Y) n with he\n set τ : Fin (n+1) ≃ Fin (n+1) := Equiv.swap k.castSucc (Fin.last n) with hτ\n have hmpe : MeasurePreserving e (Measure.pi fun _ : Fin (n+1) => μ)\n ((Measure.pi fun _ : Fin n => μ).prod μ) := measurePreserving_lastEquiv μ n\n have hmpes : MeasurePreserving (⇑e.symm) ((Measure.pi fun _ : Fin n => μ).prod μ)\n (Measure.pi fun _ : Fin (n+1) => μ) := hmpe.symm e\n have hmpτ := measurePreserving_comp_perm (ι := Fin (n+1)) μ τ\n have hcs : ∀ j : Fin n, (j.castSucc : Fin (n+1)) ≠ Fin.last n := fun j => (Fin.castSucc_lt_last j).ne\n have key : ∀ p : (Fin n → Y) × Y,\n e ((⇑e.symm p) ∘ (τ : Fin (n+1) → Fin (n+1))) = (Function.update p.1 k p.2, p.1 k) := by\n intro p\n have hap := e.apply_symm_apply p\n rw [lastEquiv_apply] at hap\n have hw : ∀ j : Fin n, (e.symm p) j.castSucc = p.1 j := fun j =>\n congrFun (congrArg Prod.fst hap) j\n have hl : (e.symm p) (Fin.last n) = p.2 := congrArg Prod.snd hap\n rw [lastEquiv_apply]\n refine Prod.ext ?_ ?_\n · funext j\n simp only [Function.comp_apply, hτ]\n by_cases hjk : j = k\n · subst hjk\n rw [Equiv.swap_apply_left, hl, Function.update_self]\n · rw [Equiv.swap_apply_of_ne_of_ne (by simpa using hjk) (hcs j), hw j,\n Function.update_of_ne hjk]\n · simp only [Function.comp_apply, hτ]\n rw [Equiv.swap_apply_right, hw k]\n have hcomp : MeasurePreserving\n (fun p : (Fin n → Y) × Y => e ((⇑e.symm p) ∘ (τ : Fin (n+1) → Fin (n+1))))\n ((Measure.pi fun _ : Fin n => μ).prod μ) ((Measure.pi fun _ : Fin n => μ).prod μ) :=\n hmpe.comp (hmpτ.comp hmpes)\n have : (fun p : (Fin n → Y) × Y => e ((⇑e.symm p) ∘ (τ : Fin (n+1) → Fin (n+1))))\n = fun p : (Fin n → Y) × Y => (Function.update p.1 k p.2, p.1 k) := funext key\n rwa [this] at hcomp\n\nend Snoc\n\nsection MDiarmid\n\nvariable {Y : Type*} [MeasurableSpace Y]\n\n/-- Splitting off the first coordinate. -/\nnoncomputable def firstEquiv (Y : Type*) [MeasurableSpace Y] (n : ℕ) :\n (Fin (n+1) → Y) ≃ᵐ Y × (Fin n → Y) :=\n MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) 0\n\ntheorem firstEquiv_apply {n : ℕ} (w : Fin (n+1) → Y) :\n firstEquiv Y n w = (w 0, fun j => w j.succ) := by\n simp only [firstEquiv, MeasurableEquiv.piFinSuccAbove_apply]\n rfl\n\n/-- Prepending a value to a tuple. -/\nnoncomputable def cns {n : ℕ} (y : Y) (s : Fin n → Y) : Fin (n+1) → Y :=\n (firstEquiv Y n).symm (y, s)\n\ntheorem firstEquiv_cns {n : ℕ} (y : Y) (s : Fin n → Y) :\n firstEquiv Y n (cns y s) = (y, s) := (firstEquiv Y n).apply_symm_apply _\n\ntheorem cns_zero {n : ℕ} (y : Y) (s : Fin n → Y) : cns y s 0 = y := by\n have := firstEquiv_cns y s\n rw [firstEquiv_apply] at this\n exact congrArg Prod.fst this\n\ntheorem cns_succ {n : ℕ} (y : Y) (s : Fin n → Y) (j : Fin n) : cns y s j.succ = s j := by\n have := firstEquiv_cns y s\n rw [firstEquiv_apply] at this\n exact congrFun (congrArg Prod.snd this) j\n\ntheorem measurable_cns {n : ℕ} : Measurable (fun p : Y × (Fin n → Y) => cns p.1 p.2) :=\n (firstEquiv Y n).symm.measurable\n\ntheorem update_cns_zero {n : ℕ} (y : Y) (s : Fin n → Y) (z : Y) :\n Function.update (cns y s) 0 z = cns z s := by\n apply (firstEquiv Y n).injective\n rw [firstEquiv_apply, firstEquiv_cns]\n refine Prod.ext ?_ ?_\n · simp\n · funext j\n simp only\n rw [Function.update_of_ne (Fin.succ_ne_zero j), cns_succ]\n\ntheorem update_cns_succ {n : ℕ} (y : Y) (s : Fin n → Y) (k : Fin n) (z : Y) :\n Function.update (cns y s) k.succ z = cns y (Function.update s k z) := by\n classical\n apply (firstEquiv Y n).injective\n rw [firstEquiv_apply, firstEquiv_cns]\n refine Prod.ext ?_ ?_\n · simp only\n rw [Function.update_of_ne (Ne.symm (Fin.succ_ne_zero k)), cns_zero]\n · funext j\n simp only\n by_cases hj : j = k\n · subst hj; rw [Function.update_self, Function.update_self]\n · rw [Function.update_of_ne (by simpa using hj), cns_succ, Function.update_of_ne hj]\n\ntheorem measurePreserving_cns (μ : Measure Y) [IsProbabilityMeasure μ] (n : ℕ) :\n MeasurePreserving (fun p : Y × (Fin n → Y) => cns p.1 p.2)\n (μ.prod (Measure.pi fun _ : Fin n => μ)) (Measure.pi fun _ : Fin (n+1) => μ) :=\n (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => μ) 0).symm (firstEquiv Y n)\n\n/-- If `g` almost surely satisfies `g y ≤ g z + c`, then `g` almost surely takes values in an\ninterval of length `c`. -/\ntheorem exists_Icc_ae_of_ae_diam (μ : Measure Y) [IsProbabilityMeasure μ]\n (g : Y → ℝ) (Bd : ℝ) (hb : ∀ y, |g y| ≤ Bd) (c : ℝ)\n (hd : ∀ᵐ y ∂μ, ∀ᵐ z ∂μ, g y ≤ g z + c) :\n ∃ a : ℝ, ∀ᵐ y ∂μ, g y ∈ Set.Icc a (a + c) := by\n classical\n set R : Set ℝ := {r : ℝ | ∀ᵐ z ∂μ, r ≤ g z} with hR\n have hRne : R.Nonempty :=\n ⟨-Bd, show ∀ᵐ z ∂μ, -Bd ≤ g z from\n Filter.Eventually.of_forall (fun z => (abs_le.1 (hb z)).1)⟩\n have hRbdd : BddAbove R := by\n refine ⟨Bd, ?_⟩\n intro r hr\n have hr' : ∀ᵐ z ∂μ, r ≤ g z := hr\n obtain ⟨z, hz⟩ := hr'.exists\n exact le_trans hz (abs_le.1 (hb z)).2\n set a : ℝ := sSup R with ha\n have hlow : ∀ᵐ z ∂μ, a ≤ g z := by\n have hex : ∀ j : ℕ, ∃ r ∈ R, a - 1/((j:ℝ)+1) < r := by\n intro j\n have hpos : (0:ℝ) < 1/((j:ℝ)+1) := by positivity\n exact exists_lt_of_lt_csSup hRne (by linarith)\n choose r hrR hrgt using hex\n have hall : ∀ᵐ z ∂μ, ∀ j : ℕ, r j ≤ g z :=\n ae_all_iff.2 (fun j => show ∀ᵐ z ∂μ, r j ≤ g z from hrR j)\n filter_upwards [hall] with z hz\n by_contra hcon\n push_neg at hcon\n obtain ⟨j, hj⟩ := exists_nat_one_div_lt (show (0:ℝ) < a - g z by linarith)\n have := hz j\n have := hrgt j\n simp only [one_div] at hj this ⊢\n linarith\n refine ⟨a, ?_⟩\n filter_upwards [hlow, hd] with y hy1 hy2\n refine ⟨hy1, ?_⟩\n have hmem : g y - c ∈ R := by\n show ∀ᵐ z ∂μ, g y - c ≤ g z\n filter_upwards [hy2] with z hz\n linarith\n have := le_csSup hRbdd hmem\n linarith\n\n/-- **The tensorisation (bounded-difference) bound on the mgf.** This is the analytic core of\nMcDiarmid's inequality, proved by induction on the number of coordinates of the product space. -/\ntheorem mcdiarmid_mgf (μ : Measure Y) [IsProbabilityMeasure μ] (c : ℝ) :\n ∀ (n : ℕ) (Bd : ℝ) (h : (Fin n → Y) → ℝ), Measurable h → (∀ s, |h s| ≤ Bd) →\n (∀ k : Fin n, ∀ᵐ p ∂((Measure.pi fun _ : Fin n => μ).prod μ),\n h p.1 ≤ h (Function.update p.1 k p.2) + c) →\n ∀ t : ℝ, ∫ s, Real.exp (t * (h s - ∫ s', h s' ∂(Measure.pi fun _ : Fin n => μ)))\n ∂(Measure.pi fun _ : Fin n => μ) ≤ Real.exp (n * c^2 * t^2/8) := by\n intro n\n induction n with\n | zero =>\n intro Bd h hmeas hb hdiff t\n have huniq : ∀ s s' : Fin 0 → Y, s = s' := fun s s' => funext (fun i => i.elim0)\n have e1 : ∫ s', h s' ∂(Measure.pi fun _ : Fin 0 => μ) = h (fun i => i.elim0) := by\n rw [show (fun s' : Fin 0 → Y => h s') = (fun _ => h (fun i => i.elim0)) from\n funext (fun s' => by rw [huniq s' (fun i => i.elim0)])]\n simp\n rw [e1, show (fun s : Fin 0 → Y => Real.exp (t * (h s - h (fun i => i.elim0))))\n = (fun _ => (1:ℝ)) from funext (fun s => by rw [huniq s (fun i => i.elim0)]; simp)]\n simp\n | succ n ih =>\n intro Bd h hmeas hb hdiff t\n have hpm := measurePreserving_cns μ n\n -- the partial average over the last `n` coordinates\n set g : Y → ℝ := fun y => ∫ s, h (cns y s) ∂(Measure.pi fun _ : Fin n => μ) with hg\n have hHmeas : Measurable (fun p : Y × (Fin n → Y) => h (cns p.1 p.2)) :=\n hmeas.comp measurable_cns\n have hgmeas : Measurable g :=\n (MeasureTheory.StronglyMeasurable.integral_prod_right'\n (ν := (Measure.pi fun _ : Fin n => μ)) hHmeas.stronglyMeasurable).measurable\n have hmeas_cns_left : ∀ y : Y, Measurable (fun s : Fin n → Y => h (cns y s)) := fun y =>\n hmeas.comp (measurable_cns.comp (measurable_const.prodMk measurable_id))\n have hint_cns : ∀ y : Y, Integrable (fun s : Fin n → Y => h (cns y s))\n (Measure.pi fun _ : Fin n => μ) := fun y =>\n integrable_of_abs_le _ (hmeas_cns_left y) Bd (fun s => hb _)\n have hgb : ∀ y, |g y| ≤ Bd := fun y =>\n abs_integral_le _ _ Bd (fun s => hb _)\n have hHint : Integrable (fun p : Y × (Fin n → Y) => h (cns p.1 p.2))\n (μ.prod (Measure.pi fun _ : Fin n => μ)) :=\n integrable_of_abs_le _ hHmeas Bd (fun p => hb _)\n -- the total mean\n have hEh : ∫ s', h s' ∂(Measure.pi fun _ : Fin (n+1) => μ) = ∫ y, g y ∂μ := by\n calc ∫ s', h s' ∂(Measure.pi fun _ : Fin (n+1) => μ)\n = ∫ p, h (cns p.1 p.2) ∂(μ.prod (Measure.pi fun _ : Fin n => μ)) := by\n rw [← hpm.map_eq, integral_map hpm.measurable.aemeasurable\n hmeas.aestronglyMeasurable]\n _ = ∫ y, g y ∂μ := integral_prod _ hHint\n set E : ℝ := ∫ s', h s' ∂(Measure.pi fun _ : Fin (n+1) => μ) with hE\n have hEb : |E| ≤ Bd := abs_integral_le _ _ Bd hb\n -- transfer the bounded-difference conditions through `cns`\n have htrans : ∀ k : Fin (n+1), ∀ᵐ y ∂μ, ∀ᵐ s ∂(Measure.pi fun _ : Fin n => μ), ∀ᵐ z ∂μ,\n h (cns y s) ≤ h (Function.update (cns y s) k z) + c := by\n intro k\n have h1 := hdiff k\n have hmap : Measure.map\n (Prod.map (fun p : Y × (Fin n → Y) => cns p.1 p.2) (id : Y → Y))\n ((μ.prod (Measure.pi fun _ : Fin n => μ)).prod μ)\n = (Measure.pi fun _ : Fin (n+1) => μ).prod μ := by\n rw [← Measure.map_prod_map _ _ hpm.measurable measurable_id, hpm.map_eq, Measure.map_id]\n have hmp2 : MeasurePreserving\n (Prod.map (fun p : Y × (Fin n → Y) => cns p.1 p.2) (id : Y → Y))\n ((μ.prod (Measure.pi fun _ : Fin n => μ)).prod μ)\n ((Measure.pi fun _ : Fin (n+1) => μ).prod μ) :=\n ⟨hpm.measurable.prodMap measurable_id, hmap⟩\n have hset : MeasurableSet {q : (Fin (n+1) → Y) × Y |\n h q.1 ≤ h (Function.update q.1 k q.2) + c} :=\n measurableSet_le (hmeas.comp measurable_fst)\n ((hmeas.comp (measurable_updatePair k)).add measurable_const)\n have h2 := ae_comp_of_measurePreserving hmp2 hset h1\n have h3 : ∀ᵐ p ∂(μ.prod (Measure.pi fun _ : Fin n => μ)), ∀ᵐ z ∂μ,\n h (cns p.1 p.2) ≤ h (Function.update (cns p.1 p.2) k z) + c :=\n Measure.ae_ae_of_ae_prod h2\n exact Measure.ae_ae_of_ae_prod h3\n -- inner mgf bound, coordinate by coordinate\n have hinner : ∀ᵐ y ∂μ, ∫ s, Real.exp (t * (h (cns y s) - g y))\n ∂(Measure.pi fun _ : Fin n => μ) ≤ Real.exp (n * c^2 * t^2/8) := by\n have hall : ∀ᵐ y ∂μ, ∀ k : Fin n, ∀ᵐ s ∂(Measure.pi fun _ : Fin n => μ), ∀ᵐ z ∂μ,\n h (cns y s) ≤ h (cns y (Function.update s k z)) + c := by\n refine ae_all_iff.2 (fun k => ?_)\n filter_upwards [htrans k.succ] with y hy\n filter_upwards [hy] with s hs\n filter_upwards [hs] with z hz\n rwa [update_cns_succ] at hz\n filter_upwards [hall] with y hy\n refine ih Bd (fun s => h (cns y s)) (hmeas_cns_left y) (fun s => hb _) (fun k => ?_) t\n refine (Measure.ae_prod_iff_ae_ae\n (p := fun q : (Fin n → Y) × Y =>\n h (cns y q.1) ≤ h (cns y (Function.update q.1 k q.2)) + c) ?_).2 (hy k)\n exact measurableSet_le ((hmeas_cns_left y).comp measurable_fst)\n (((hmeas_cns_left y).comp (measurable_updatePair k)).add measurable_const)\n -- essential range of `g`\n have hgdiam : ∀ᵐ y ∂μ, ∀ᵐ z ∂μ, g y ≤ g z + c := by\n have h0 : ∀ᵐ y ∂μ, ∀ᵐ s ∂(Measure.pi fun _ : Fin n => μ), ∀ᵐ z ∂μ,\n h (cns y s) ≤ h (cns z s) + c := by\n filter_upwards [htrans 0] with y hy\n filter_upwards [hy] with s hs\n filter_upwards [hs] with z hz\n rwa [update_cns_zero] at hz\n filter_upwards [h0] with y hy\n have hcomm : ∀ᵐ z ∂μ, ∀ᵐ s ∂(Measure.pi fun _ : Fin n => μ),\n h (cns y s) ≤ h (cns z s) + c := by\n refine (Measure.ae_ae_comm ?_).1 hy\n exact measurableSet_le (hmeas.comp ((measurable_cns).comp\n (measurable_const.prodMk measurable_fst)))\n ((hmeas.comp ((measurable_cns).comp (measurable_snd.prodMk measurable_fst))).add\n measurable_const)\n filter_upwards [hcomm] with z hz\n have hint2 : Integrable (fun s : Fin n → Y => h (cns z s) + c)\n (Measure.pi fun _ : Fin n => μ) := (hint_cns z).add (integrable_const c)\n have hle := integral_mono_ae (hint_cns y) hint2 hz\n rw [integral_add (hint_cns z) (integrable_const c)] at hle\n simpa [hg] using hle\n obtain ⟨a, hIcc⟩ := exists_Icc_ae_of_ae_diam μ g Bd hgb c hgdiam\n -- Hoeffding's lemma applied to `g`\n have hHoef : ∫ y, Real.exp (t * (g y - ∫ y', g y' ∂μ)) ∂μ ≤ Real.exp (c^2*t^2/8) := by\n have hsg := hasSubgaussianMGF_of_mem_Icc (μ := μ) (X := g) (a := a) (b := a + c)\n hgmeas.aemeasurable hIcc\n have := hsg.mgf_le t\n have hcst : (((‖(a + c) - a‖₊ / 2) ^ 2 : ℝ≥0) : ℝ) * t^2/2 = c^2*t^2/8 := by\n push_cast\n rw [Real.norm_eq_abs, show a + c - a = c by ring]\n rcases abs_cases c with ⟨h1, _⟩ | ⟨h1, _⟩ <;> rw [h1] <;> ring\n rw [hcst] at this\n exact this\n -- assemble\n have hKB : ∀ w : Fin (n+1) → Y, |Real.exp (t * (h w - E))| ≤ Real.exp (|t| * (2*Bd)) := by\n intro w\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.2\n have h1 : |h w - E| ≤ 2*Bd := by\n have := hb w; have := hEb; rw [abs_le] at *; constructor <;> linarith\n calc t * (h w - E) ≤ |t * (h w - E)| := le_abs_self _\n _ = |t| * |h w - E| := abs_mul _ _\n _ ≤ |t| * (2*Bd) := by\n apply mul_le_mul_of_nonneg_left h1 (abs_nonneg t)\n have hstep1 : ∫ w, Real.exp (t * (h w - E)) ∂(Measure.pi fun _ : Fin (n+1) => μ)\n = ∫ y, ∫ s, Real.exp (t * (h (cns y s) - E)) ∂(Measure.pi fun _ : Fin n => μ) ∂μ := by\n calc ∫ w, Real.exp (t * (h w - E)) ∂(Measure.pi fun _ : Fin (n+1) => μ)\n = ∫ p, Real.exp (t * (h (cns p.1 p.2) - E))\n ∂(μ.prod (Measure.pi fun _ : Fin n => μ)) := by\n rw [← hpm.map_eq, integral_map hpm.measurable.aemeasurable\n (((measurable_const.mul (hmeas.sub measurable_const)).exp)).aestronglyMeasurable]\n _ = _ := integral_prod _ (integrable_of_abs_le _\n (((measurable_const.mul (hHmeas.sub measurable_const)).exp)) _ (fun p => hKB _))\n have hstep2 : ∀ y : Y, ∫ s, Real.exp (t * (h (cns y s) - E))\n ∂(Measure.pi fun _ : Fin n => μ)\n = Real.exp (t * (g y - E)) * ∫ s, Real.exp (t * (h (cns y s) - g y))\n ∂(Measure.pi fun _ : Fin n => μ) := by\n intro y\n rw [← integral_const_mul]\n congr 1\n funext s\n rw [← Real.exp_add]\n ring_nf\n have hOuterMeas : Measurable (fun y => ∫ s, Real.exp (t * (h (cns y s) - E))\n ∂(Measure.pi fun _ : Fin n => μ)) :=\n (MeasureTheory.StronglyMeasurable.integral_prod_right'\n (ν := (Measure.pi fun _ : Fin n => μ))\n ((measurable_const.mul (hHmeas.sub measurable_const)).exp).stronglyMeasurable).measurable\n have hmono : ∫ y, ∫ s, Real.exp (t * (h (cns y s) - E))\n ∂(Measure.pi fun _ : Fin n => μ) ∂μ\n ≤ ∫ y, Real.exp (t * (g y - E)) * Real.exp (n * c^2 * t^2/8) ∂μ := by\n refine integral_mono_ae (integrable_of_abs_le _ hOuterMeas\n (Real.exp (|t| * (2*Bd))) (fun y => ?_)) ?_ ?_\n · rw [abs_le]\n constructor\n · have : (0:ℝ) ≤ ∫ s, Real.exp (t * (h (cns y s) - E))\n ∂(Measure.pi fun _ : Fin n => μ) :=\n integral_nonneg (fun s => (Real.exp_pos _).le)\n have h2 : (0:ℝ) ≤ Real.exp (|t| * (2*Bd)) := (Real.exp_pos _).le\n linarith\n · have := abs_integral_le (Measure.pi fun _ : Fin n => μ)\n (fun s => Real.exp (t * (h (cns y s) - E))) (Real.exp (|t| * (2*Bd)))\n (fun s => hKB _)\n exact le_trans (le_abs_self _) this\n · exact ((integrable_of_abs_le _ ((measurable_const.mul\n (hgmeas.sub measurable_const)).exp) (Real.exp (|t| * (2*Bd))) (fun y => by\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.2\n have h1 : |g y - E| ≤ 2*Bd := by\n have := hgb y; have := hEb; rw [abs_le] at *; constructor <;> linarith\n calc t * (g y - E) ≤ |t * (g y - E)| := le_abs_self _\n _ = |t| * |g y - E| := abs_mul _ _\n _ ≤ |t| * (2*Bd) := mul_le_mul_of_nonneg_left h1 (abs_nonneg t))).mul_const _)\n · filter_upwards [hinner] with y hy\n rw [hstep2 y]\n exact mul_le_mul_of_nonneg_left hy (Real.exp_pos _).le\n rw [hstep1]\n refine hmono.trans ?_\n rw [integral_mul_const]\n have : ∫ y, Real.exp (t * (g y - E)) ∂μ ≤ Real.exp (c^2*t^2/8) := by\n rw [hEh]; exact hHoef\n calc (∫ y, Real.exp (t * (g y - E)) ∂μ) * Real.exp (n * c^2*t^2/8)\n ≤ Real.exp (c^2*t^2/8) * Real.exp (↑n * c^2*t^2/8) := by\n exact mul_le_mul_of_nonneg_right this (Real.exp_pos _).le\n _ = Real.exp ((n+1 : ℕ) * c^2 * t^2/8) := by\n rw [← Real.exp_add]\n push_cast\n ring\n\n/-- **McDiarmid's bounded-difference inequality** (one-sided, with almost-everywhere bounded\ndifferences). -/\ntheorem mcdiarmid (μ : Measure Y) [IsProbabilityMeasure μ] {n : ℕ} (c : ℝ) (hc : 0 ≤ c)\n (Bd : ℝ) (h : (Fin n → Y) → ℝ) (hmeas : Measurable h) (hb : ∀ s, |h s| ≤ Bd)\n (hdiff : ∀ k : Fin n, ∀ᵐ p ∂((Measure.pi fun _ : Fin n => μ).prod μ),\n h p.1 ≤ h (Function.update p.1 k p.2) + c)\n {ε : ℝ} (hε : 0 ≤ ε) :\n (Measure.pi fun _ : Fin n => μ).real\n {s | (∫ s', h s' ∂(Measure.pi fun _ : Fin n => μ)) + ε ≤ h s}\n ≤ Real.exp (-(2 * ε^2) / (n * c^2)) := by\n classical\n set E : ℝ := ∫ s', h s' ∂(Measure.pi fun _ : Fin n => μ) with hE\n set κ : ℝ≥0 := ⟨(n : ℝ) * c^2/4, by positivity⟩ with hκ\n have hκval : ((κ : ℝ≥0) : ℝ) = (n : ℝ) * c^2/4 := rfl\n have hEb : |E| ≤ Bd := abs_integral_le _ _ Bd hb\n have hbnd : ∀ s, |Real.exp (0 * (h s - E))| ≤ 1 := by intro s; simp\n have hsg : HasSubgaussianMGF (fun s => h s - E) κ (Measure.pi fun _ : Fin n => μ) := by\n constructor\n · intro t\n refine integrable_of_abs_le _ ((measurable_const.mul\n (hmeas.sub measurable_const)).exp) (Real.exp (|t| * (2*Bd))) (fun s => ?_)\n rw [abs_of_pos (Real.exp_pos _)]\n apply Real.exp_le_exp.2\n have h1 : |h s - E| ≤ 2*Bd := by\n have := hb s; have := hEb; rw [abs_le] at *; constructor <;> linarith\n calc t * (h s - E) ≤ |t * (h s - E)| := le_abs_self _\n _ = |t| * |h s - E| := abs_mul _ _\n _ ≤ |t| * (2*Bd) := mul_le_mul_of_nonneg_left h1 (abs_nonneg t)\n · intro t\n have := mcdiarmid_mgf μ c n Bd h hmeas hb hdiff t\n refine le_trans (le_of_eq ?_) (le_trans this (le_of_eq ?_))\n · rfl\n · rw [hκval]; ring_nf\n have hkey := hsg.measure_ge_le hε\n have hsetEq : {s : Fin n → Y | E + ε ≤ h s} = {s : Fin n → Y | ε ≤ h s - E} := by\n ext s; simp only [Set.mem_setOf_eq]; constructor <;> intro hh <;> linarith\n rw [hsetEq]\n refine hkey.trans (le_of_eq ?_)\n congr 1\n rw [hκval]\n rcases eq_or_lt_of_le hc with hc0 | hc0\n · simp [← hc0]\n · rcases Nat.eq_zero_or_pos n with hn0 | hn0\n · simp [hn0]\n · have hnR : (0:ℝ) < n := by exact_mod_cast hn0\n field_simp\n ring\n\n\nend MDiarmid\n\n\nsection Selection\n\nvariable {α : Type*} [MeasurableSpace α] {P : Type*} [MeasurableSpace P]\n\nopen Classical in\n/-- Pointwise maximum of two selections, with respect to the score `J`. -/\nnoncomputable def Emax (J : P → α → ℝ) (B₁ B₂ : α → P) : α → P :=\n fun x => if J (B₁ x) x < J (B₂ x) x then B₂ x else B₁ x\n\ntheorem Emax_score (J : P → α → ℝ) (B₁ B₂ : α → P) (x : α) :\n J (Emax J B₁ B₂ x) x = max (J (B₁ x) x) (J (B₂ x) x) := by\n unfold Emax\n split_ifs with h\n · exact (max_eq_right h.le).symm\n · exact (max_eq_left (not_lt.1 h)).symm\n\ntheorem Emax_mem {G : Set P} (J : P → α → ℝ) {B₁ B₂ : α → P}\n (h₁ : ∀ x, B₁ x ∈ G) (h₂ : ∀ x, B₂ x ∈ G) (x : α) : Emax J B₁ B₂ x ∈ G := by\n unfold Emax; split_ifs; exacts [h₂ x, h₁ x]\n\ntheorem Emax_meas (J : P → α → ℝ) (hJ : Measurable (fun q : P × α => J q.1 q.2))\n {B₁ B₂ : α → P} (h₁ : Measurable B₁) (h₂ : Measurable B₂) : Measurable (Emax J B₁ B₂) := by\n have m₁ : Measurable (fun x => J (B₁ x) x) := hJ.comp (h₁.prodMk measurable_id)\n have m₂ : Measurable (fun x => J (B₂ x) x) := hJ.comp (h₂.prodMk measurable_id)\n exact Measurable.ite (measurableSet_lt m₁ m₂) h₂ h₁\n\n/-- Running maximum of a sequence of selections. -/\nnoncomputable def maxSel (J : P → α → ℝ) (B : ℕ → α → P) : ℕ → α → P\n | 0 => B 0\n | (j+1) => Emax J (maxSel J B j) (B (j+1))\n\ntheorem maxSel_meas (J : P → α → ℝ) (hJ : Measurable (fun q : P × α => J q.1 q.2))\n {B : ℕ → α → P} (hB : ∀ j, Measurable (B j)) : ∀ j, Measurable (maxSel J B j)\n | 0 => hB 0\n | (j+1) => Emax_meas J hJ (maxSel_meas J hJ hB j) (hB (j+1))\n\ntheorem maxSel_mem {G : Set P} (J : P → α → ℝ) {B : ℕ → α → P} (hB : ∀ j x, B j x ∈ G) :\n ∀ j x, maxSel J B j x ∈ G\n | 0, x => hB 0 x\n | (j+1), x => Emax_mem J (maxSel_mem J hB j) (hB (j+1)) x\n\ntheorem maxSel_mono (J : P → α → ℝ) (B : ℕ → α → P) (x : α) :\n Monotone (fun j => J (maxSel J B j x) x) := by\n apply monotone_nat_of_le_succ\n intro j\n show J (maxSel J B j x) x ≤ J (maxSel J B (j+1) x) x\n rw [show maxSel J B (j+1) = Emax J (maxSel J B j) (B (j+1)) from rfl,\n Emax_score J (maxSel J B j) (B (j+1)) x]\n exact le_max_left _ _\n\ntheorem maxSel_ge (J : P → α → ℝ) (B : ℕ → α → P) (x : α) : ∀ j, J (B j x) x ≤ J (maxSel J B j x) x\n | 0 => le_of_eq rfl\n | (j+1) => by\n rw [show maxSel J B (j+1) = Emax J (maxSel J B j) (B (j+1)) from rfl,\n Emax_score J (maxSel J B j) (B (j+1)) x]\n exact le_max_right _ _\n\n/-- **Essential supremum over measurable selections.** Given a jointly measurable, uniformly\nbounded score `J`, there is a measurable function `Ψ` which dominates `x ↦ J (B x) x` almost\neverywhere for *every* measurable selection `B` with values in `G`, and whose integral is at most\nany bound valid for all selections. -/\ntheorem exists_esssup_sel (ν : Measure α) [IsProbabilityMeasure ν]\n (G : Set P) (f₀ : P) (hf₀ : f₀ ∈ G)\n (J : P → α → ℝ) (hJ : Measurable (fun q : P × α => J q.1 q.2))\n (K : ℝ) (hK : ∀ p ∈ G, ∀ x, |J p x| ≤ K) :\n ∃ (Ψ : α → ℝ) (C : ℕ → α → P), (∀ j, Measurable (C j)) ∧ (∀ j x, C j x ∈ G) ∧\n (∀ x, Ψ x = ⨆ j, J (C j x) x) ∧ Measurable Ψ ∧ (∀ x, |Ψ x| ≤ K) ∧\n (∀ B : α → P, Measurable B → (∀ x, B x ∈ G) → ∀ᵐ x ∂ν, J (B x) x ≤ Ψ x) ∧\n (∀ b : ℝ, (∀ B : α → P, Measurable B → (∀ x, B x ∈ G) → ∫ x, J (B x) x ∂ν ≤ b) →\n ∫ x, Ψ x ∂ν ≤ b) := by\n classical\n -- measurability / integrability of the score of a selection\n have hmeasB : ∀ B : α → P, Measurable B → Measurable (fun x => J (B x) x) := fun B hB =>\n hJ.comp (hB.prodMk measurable_id)\n have hintB : ∀ B : α → P, Measurable B → (∀ x, B x ∈ G) → Integrable (fun x => J (B x) x) ν := by\n intro B hB hBm\n refine Integrable.of_mem_Icc (-K) K (hmeasB B hB).aemeasurable\n (Filter.Eventually.of_forall (fun x => ?_))\n have := hK (B x) (hBm x) x\n exact ⟨by cases abs_le.1 this with | intro h1 h2 => exact h1,\n by cases abs_le.1 this with | intro h1 h2 => exact h2⟩\n -- the supremum of the achievable integrals\n set T : Set ℝ := {r : ℝ | ∃ B : α → P, Measurable B ∧ (∀ x, B x ∈ G)\n ∧ r = ∫ x, J (B x) x ∂ν} with hT\n have hTne : T.Nonempty :=\n ⟨_, ⟨fun _ => f₀, measurable_const, fun _ => hf₀, rfl⟩⟩\n have hTbdd : BddAbove T := by\n refine ⟨K, ?_⟩\n rintro r ⟨B, hB, hBm, rfl⟩\n calc ∫ x, J (B x) x ∂ν ≤ ∫ _x, K ∂ν := by\n refine integral_mono (hintB B hB hBm) (integrable_const _) (fun x => ?_)\n exact (abs_le.1 (hK (B x) (hBm x) x)).2\n _ = K := by simp\n set S : ℝ := sSup T with hS\n have hleS : ∀ B : α → P, Measurable B → (∀ x, B x ∈ G) → ∫ x, J (B x) x ∂ν ≤ S := by\n intro B hB hBm\n exact le_csSup hTbdd ⟨B, hB, hBm, rfl⟩\n -- a maximising sequence\n have hchoose : ∀ j : ℕ, ∃ B : α → P, Measurable B ∧ (∀ x, B x ∈ G)\n ∧ S - 1/(j+1) < ∫ x, J (B x) x ∂ν := by\n intro j\n have hpos : (0:ℝ) < 1/((j:ℝ)+1) := by positivity\n obtain ⟨r, hrT, hr⟩ := exists_lt_of_lt_csSup hTne (show S - 1/((j:ℝ)+1) < S by linarith)\n obtain ⟨B, hB, hBm, rfl⟩ := hrT\n exact ⟨B, hB, hBm, hr⟩\n choose B hBmeas hBmem hBgt using hchoose\n set F : ℕ → α → ℝ := fun j x => J (maxSel J B j x) x with hF\n have hFmeas : ∀ j, Measurable (F j) := fun j => hmeasB _ (maxSel_meas J hJ hBmeas j)\n have hFbd : ∀ j x, |F j x| ≤ K := fun j x => hK _ (maxSel_mem J hBmem j x) x\n have hFmono : ∀ x, Monotone (fun j => F j x) := fun x => maxSel_mono J B x\n have hFbddA : ∀ x, BddAbove (Set.range (fun j => F j x)) := by\n intro x\n exact ⟨K, by rintro _ ⟨j, rfl⟩; exact (abs_le.1 (hFbd j x)).2⟩\n set Ψ : α → ℝ := fun x => ⨆ j, F j x with hΨ\n have hΨmeas : Measurable Ψ := Measurable.iSup hFmeas\n have hΨbd : ∀ x, |Ψ x| ≤ K := by\n intro x\n rw [abs_le]\n constructor\n · exact le_trans (abs_le.1 (hFbd 0 x)).1 (le_ciSup (hFbddA x) 0)\n · exact ciSup_le (fun j => (abs_le.1 (hFbd j x)).2)\n have hΨint : Integrable Ψ ν := by\n refine Integrable.of_mem_Icc (-K) K hΨmeas.aemeasurable\n (Filter.Eventually.of_forall (fun x => ⟨(abs_le.1 (hΨbd x)).1, (abs_le.1 (hΨbd x)).2⟩))\n have htend : ∀ x, Filter.Tendsto (fun j => F j x) Filter.atTop (nhds (Ψ x)) := fun x =>\n tendsto_atTop_ciSup (hFmono x) (hFbddA x)\n have hintlim : Filter.Tendsto (fun j => ∫ x, F j x ∂ν) Filter.atTop (nhds (∫ x, Ψ x ∂ν)) := by\n refine tendsto_integral_of_dominated_convergence (fun _ => K)\n (fun j => (hFmeas j).aestronglyMeasurable) (integrable_const _)\n (fun j => Filter.Eventually.of_forall (fun x => by\n simpa [Real.norm_eq_abs] using hFbd j x))\n (Filter.Eventually.of_forall htend)\n refine ⟨Ψ, maxSel J B, maxSel_meas J hJ hBmeas, maxSel_mem J hBmem, fun x => rfl,\n hΨmeas, hΨbd, ?_, ?_⟩\n · -- almost everywhere domination\n intro B' hB' hB'm\n have hcombine : ∀ j : ℕ, ∫ x, max (F j x) (J (B' x) x) ∂ν ≤ S := by\n intro j\n have hsel := hleS (Emax J (maxSel J B j) B')\n (Emax_meas J hJ (maxSel_meas J hJ hBmeas j) hB')\n (fun x => Emax_mem J (maxSel_mem J hBmem j) hB'm x)\n simpa only [Emax_score] using hsel\n have hΨS : ∫ x, Ψ x ∂ν = S := by\n refine le_antisymm ?_ ?_\n · refine le_of_tendsto hintlim (Filter.Eventually.of_forall (fun j => ?_))\n exact hleS _ (maxSel_meas J hJ hBmeas j) (maxSel_mem J hBmem j)\n · refine le_of_forall_lt_imp_le_of_dense (fun r hr => ?_)\n obtain ⟨j, hj⟩ := exists_nat_one_div_lt (show (0:ℝ) < S - r by linarith)\n have h1 : S - 1/((j:ℝ)+1) < ∫ x, J (B j x) x ∂ν := hBgt j\n have h2 : ∫ x, J (B j x) x ∂ν ≤ ∫ x, Ψ x ∂ν := by\n refine integral_mono (hintB _ (hBmeas j) (hBmem j)) hΨint (fun x => ?_)\n exact le_trans (maxSel_ge J B x j) (le_ciSup (hFbddA x) j)\n have : (1:ℝ)/((j:ℝ)+1) < S - r := hj\n linarith\n -- pass to the limit\n have hmaxint : Integrable (fun x => max (Ψ x) (J (B' x) x)) ν := by\n refine Integrable.of_mem_Icc (-K) K\n (hΨmeas.max (hmeasB B' hB')).aemeasurable (Filter.Eventually.of_forall (fun x => ?_))\n have h1 := abs_le.1 (hΨbd x)\n have h2 := abs_le.1 (hK (B' x) (hB'm x) x)\n exact ⟨le_max_of_le_left h1.1, max_le h1.2 h2.2⟩\n have hlim2 : Filter.Tendsto (fun j => ∫ x, max (F j x) (J (B' x) x) ∂ν) Filter.atTop\n (nhds (∫ x, max (Ψ x) (J (B' x) x) ∂ν)) := by\n refine tendsto_integral_of_dominated_convergence (fun _ => K)\n (fun j => ((hFmeas j).max (hmeasB B' hB')).aestronglyMeasurable) (integrable_const _)\n (fun j => Filter.Eventually.of_forall (fun x => ?_))\n (Filter.Eventually.of_forall (fun x => ?_))\n · have h1 := abs_le.1 (hFbd j x)\n have h2 := abs_le.1 (hK (B' x) (hB'm x) x)\n rw [Real.norm_eq_abs, abs_le]\n exact ⟨le_max_of_le_left h1.1, max_le h1.2 h2.2⟩\n · exact (htend x).max tendsto_const_nhds\n have hle : ∫ x, max (Ψ x) (J (B' x) x) ∂ν ≤ ∫ x, Ψ x ∂ν := by\n rw [hΨS]\n exact le_of_tendsto hlim2 (Filter.Eventually.of_forall hcombine)\n have hnn : 0 ≤ᵐ[ν] (fun x => max (Ψ x) (J (B' x) x) - Ψ x) :=\n Filter.Eventually.of_forall (fun x => by simp [le_max_left])\n have hdiffint : Integrable (fun x => max (Ψ x) (J (B' x) x) - Ψ x) ν := hmaxint.sub hΨint\n have hz : ∫ x, (max (Ψ x) (J (B' x) x) - Ψ x) ∂ν = 0 := by\n have h1 : ∫ x, (max (Ψ x) (J (B' x) x) - Ψ x) ∂ν\n = (∫ x, max (Ψ x) (J (B' x) x) ∂ν) - ∫ x, Ψ x ∂ν := integral_sub hmaxint hΨint\n have h2 : 0 ≤ ∫ x, (max (Ψ x) (J (B' x) x) - Ψ x) ∂ν := integral_nonneg (fun x => by\n simp [le_max_left])\n rw [h1] at h2 ⊢\n linarith\n have := (integral_eq_zero_iff_of_nonneg_ae hnn hdiffint).1 hz\n filter_upwards [this] with x hx\n have : max (Ψ x) (J (B' x) x) = Ψ x := by\n have : max (Ψ x) (J (B' x) x) - Ψ x = 0 := hx\n linarith\n exact le_of_max_le_right (le_of_eq this)\n · intro b hb\n refine le_of_tendsto hintlim (Filter.Eventually.of_forall (fun j => ?_))\n exact hb _ (maxSel_meas J hJ hBmeas j) (maxSel_mem J hBmem j)\n\n\nend Selection\n\n\nsection Hoeff\n\nvariable {Z : Type*} [MeasurableSpace Z]\n\n/-- A function whose range has diameter at most `M` takes values in an interval of length `M`. -/\ntheorem exists_Icc_of_diam {Z : Type*} [Nonempty Z] (g : Z → ℝ) (M : ℝ)\n (hMb : ∀ z z' : Z, g z - g z' ≤ M) : ∃ a : ℝ, ∀ z, g z ∈ Set.Icc a (a + M) := by\n have hne : (Set.range g).Nonempty := Set.range_nonempty g\n obtain ⟨z₀⟩ := ‹Nonempty Z›\n have hbdd : BddBelow (Set.range g) := by\n refine ⟨g z₀ - M, ?_⟩\n rintro _ ⟨z, rfl⟩\n have := hMb z₀ z\n linarith\n refine ⟨sInf (Set.range g), fun z => ⟨csInf_le hbdd ⟨z, rfl⟩, ?_⟩⟩\n have : g z - M ≤ sInf (Set.range g) := by\n refine le_csInf hne ?_\n rintro _ ⟨z', rfl⟩\n have := hMb z z'\n linarith\n linarith\n\ntheorem hoeffding_pi [Nonempty Z] (D : Measure Z) [IsProbabilityMeasure D] {N : ℕ} (hN : 0 < N)\n (g : Z → ℝ) (hg : Measurable g) (M : ℝ) (hMb : ∀ z z' : Z, g z - g z' ≤ M)\n {t : ℝ} (ht : 0 ≤ t) :\n (Measure.pi (fun _ : Fin N => D)).real\n {v | (∫ z, g z ∂D) + t ≤ (N : ℝ)⁻¹ * ∑ i, g (v i)}\n ≤ Real.exp (-(2 * N * t ^ 2) / M ^ 2) := by\n classical\n obtain ⟨a, ha⟩ := exists_Icc_of_diam g M hMb\n have hM0 : 0 ≤ M := by have := hMb Classical.ofNonempty Classical.ofNonempty; linarith\n have hNR : (0:ℝ) < N := by exact_mod_cast hN\n have hgint : Integrable g D := Integrable.of_mem_Icc a (a + M) hg.aemeasurable\n (Filter.Eventually.of_forall ha)\n set I : ℝ := ∫ z, g z ∂D with hI\n set X : Fin N → Z → ℝ := fun _ z => (N:ℝ)⁻¹ * g z - (N:ℝ)⁻¹ * I with hX\n have hindep : iIndepFun (fun (i : Fin N) (v : Fin N → Z) => X i (v i))\n (Measure.pi (fun _ : Fin N => D)) :=\n iIndepFun_pi (fun i => ((measurable_const.mul hg).sub measurable_const).aemeasurable)\n -- the constant\n set c : ℝ≥0 := (‖((N:ℝ)⁻¹ * (a + M)) - ((N:ℝ)⁻¹ * a)‖₊ / 2) ^ 2 with hc\n have hEY : ∀ i : Fin N, (∫ v, (N:ℝ)⁻¹ * g (v i) ∂(Measure.pi (fun _ : Fin N => D)))\n = (N:ℝ)⁻¹ * I := by\n intro i\n have hmp := measurePreserving_eval (fun _ : Fin N => D) i\n have h1 : ∫ v, (N:ℝ)⁻¹ * g (v i) ∂(Measure.pi (fun _ : Fin N => D))\n = ∫ z, (N:ℝ)⁻¹ * g z ∂D := by\n conv_rhs => rw [← hmp.map_eq]\n rw [integral_map (measurable_pi_apply i).aemeasurable\n (measurable_const.mul hg).aestronglyMeasurable]\n rw [h1, integral_const_mul]\n have hsubG : ∀ i : Fin N, HasSubgaussianMGF (fun v : Fin N → Z => X i (v i)) c\n (Measure.pi (fun _ : Fin N => D)) := by\n intro i\n have h := hasSubgaussianMGF_of_mem_Icc (μ := Measure.pi (fun _ : Fin N => D))\n (X := fun v : Fin N → Z => (N:ℝ)⁻¹ * g (v i))\n (a := (N:ℝ)⁻¹ * a) (b := (N:ℝ)⁻¹ * (a + M))\n (measurable_const.mul (hg.comp (measurable_pi_apply i))).aemeasurable\n (Filter.Eventually.of_forall (fun v => by\n have := ha (v i)\n exact ⟨by\n have h1 : a ≤ g (v i) := this.1\n exact mul_le_mul_of_nonneg_left h1 (by positivity), by\n have h2 : g (v i) ≤ a + M := this.2\n exact mul_le_mul_of_nonneg_left h2 (by positivity)⟩))\n rw [hEY i] at h\n exact h\n have hsum : ∀ v : Fin N → Z, ∑ i : Fin N, X i (v i)\n = (N:ℝ)⁻¹ * ∑ i, g (v i) - I := by\n intro v\n simp only [hX, Finset.sum_sub_distrib, ← Finset.mul_sum]\n simp [Finset.card_univ]\n field_simp\n have hset : {v : Fin N → Z | I + t ≤ (N : ℝ)⁻¹ * ∑ i, g (v i)}\n = {v : Fin N → Z | t ≤ ∑ i : Fin N, X i (v i)} := by\n ext v; simp only [Set.mem_setOf_eq, hsum v]; constructor <;> intro h <;> linarith\n rw [hset]\n have hkey := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hindep (c := fun _ => c) (s := Finset.univ)\n (fun i _ => hsubG i) ht\n simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hkey\n refine hkey.trans (le_of_eq ?_)\n congr 1\n have habs : |((N:ℝ))⁻¹ * (a + M) - ((N:ℝ))⁻¹ * a| = (N:ℝ)⁻¹ * M := by\n rw [abs_of_nonneg (by nlinarith [inv_pos.2 hNR] : (0:ℝ) ≤ (N:ℝ)⁻¹ * (a+M) - (N:ℝ)⁻¹ * a)]\n ring\n simp only [hc]\n push_cast\n rw [Real.norm_eq_abs, habs]\n rcases eq_or_lt_of_le hM0 with hM | hM\n · simp [← hM]\n · field_simp\n\n\nend Hoeff\n\n\ntheorem sym_sel {Z Pred : Type*} [MeasurableSpace Z] [Nonempty Z] [MeasurableSpace Pred]\n (D : Measure Z) [IsProbabilityMeasure D]\n (φ : Pred → Z → ℝ) (hφ : Measurable (fun p : Pred × Z => φ p.1 p.2))\n (M : ℝ) (hMb : ∀ f, ∀ z z' : Z, φ f z - φ f z' ≤ M)\n (hintφ : ∀ f, Integrable (fun z => φ f z) D)\n {n : ℕ} (hn : 0 < n) (G : Set Pred)\n (hbdd : ∀ (s : Fin n → Z) (σ : RadSigns n),\n BddAbove (Set.range (fun f : G => (n : ℝ)⁻¹ * ∑ k, (σ k : ℝ) * φ (f : Pred) (s k))))\n (hRint : Integrable (fun s : Fin n → Z =>\n empRadSigned n (fun f : G => fun z => φ (f : Pred) z) s) (Measure.pi fun _ : Fin n => D))\n (B : (Fin n → Z) → Pred) (hB : Measurable B) (hBmem : ∀ s, B s ∈ G) :\n ∫ s, ((∫ z, φ (B s) z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ (B s) (s k)) ∂(Measure.pi fun _ : Fin n => D)\n ≤ 2 * radCx n φ G D := by\n classical\n have hnR : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn\n obtain ⟨z₀⟩ := ‹Nonempty Z›\n have hM0 : (0:ℝ) ≤ M := by have := hMb (B (fun _ => z₀)) z₀ z₀; linarith\n -- notation\n set gg : G → Z → ℝ := fun f z => φ (f : Pred) z with hgg\n set F : (Fin n → Z) → (Fin n → Z) → ℝ := fun s s' =>\n (n:ℝ)⁻¹ * ∑ k, (φ (B s) (s' k) - φ (B s) (s k)) with hF\n set H : (Fin n → Z × Z) → ℝ := fun w => F (fun k => (w k).1) (fun k => (w k).2) with hH\n set T : RadSigns n → (Fin n → Z × Z) → (Fin n → Z × Z) := fun σ w k =>\n (if ((σ k : ℤ)) = 1 then (id : Z × Z → Z × Z) else Prod.swap) (w k) with hT\n set U : RadSigns n → (Fin n → Z) → ℝ := fun σ s =>\n ⨆ f : G, (n : ℝ)⁻¹ * ∑ k, (σ k : ℝ) * φ (f : Pred) (s k) with hU\n -- measure preserving maps on the doubled sample space\n have hp1 : MeasurePreserving (fun (w : Fin n → Z × Z) (k : Fin n) => (w k).1)\n (Measure.pi fun _ : Fin n => D.prod D) (Measure.pi fun _ : Fin n => D) :=\n measurePreserving_pi _ _ (fun _ => measurePreserving_fst)\n have hp2 : MeasurePreserving (fun (w : Fin n → Z × Z) (k : Fin n) => (w k).2)\n (Measure.pi fun _ : Fin n => D.prod D) (Measure.pi fun _ : Fin n => D) :=\n measurePreserving_pi _ _ (fun _ => measurePreserving_snd)\n have hpair : MeasurePreserving\n (fun (w : Fin n → Z × Z) => ((fun k => (w k).1), (fun k => (w k).2)))\n (Measure.pi fun _ : Fin n => D.prod D)\n ((Measure.pi fun _ : Fin n => D).prod (Measure.pi fun _ : Fin n => D)) :=\n measurePreserving_arrowProdEquivProdArrow Z Z (Fin n) (fun _ => D) (fun _ => D)\n have hTmp : ∀ σ : RadSigns n, MeasurePreserving (T σ)\n (Measure.pi fun _ : Fin n => D.prod D) (Measure.pi fun _ : Fin n => D.prod D) := by\n intro σ\n refine measurePreserving_pi _ _ (fun k => ?_)\n by_cases hk : ((σ k : ℤ)) = 1\n · simp only [hk, if_true]\n exact MeasurePreserving.id _\n · simp only [hk, if_false]\n exact Measure.measurePreserving_swap\n -- basic bounds and measurability\n have hFabs : ∀ s s', |F s s'| ≤ M := by\n intro s s'\n have hb : ∀ k : Fin n, |φ (B s) (s' k) - φ (B s) (s k)| ≤ M := by\n intro k\n rw [abs_le]\n exact ⟨by have := hMb (B s) (s k) (s' k); linarith, hMb (B s) (s' k) (s k)⟩\n rw [hF]\n simp only\n rw [abs_mul, abs_of_nonneg (le_of_lt (inv_pos.2 hnR))]\n have : |∑ k, (φ (B s) (s' k) - φ (B s) (s k))| ≤ (n:ℝ) * M := by\n refine le_trans (Finset.abs_sum_le_sum_abs _ _) ?_\n calc ∑ k : Fin n, |φ (B s) (s' k) - φ (B s) (s k)| ≤ ∑ _k : Fin n, M :=\n Finset.sum_le_sum (fun k _ => hb k)\n _ = (n:ℝ) * M := by simp [Finset.card_univ, mul_comm]\n calc (n:ℝ)⁻¹ * |∑ k, (φ (B s) (s' k) - φ (B s) (s k))| ≤ (n:ℝ)⁻¹ * ((n:ℝ) * M) := by\n exact mul_le_mul_of_nonneg_left this (le_of_lt (inv_pos.2 hnR))\n _ = M := by field_simp\n have hFmeas : Measurable (fun p : (Fin n → Z) × (Fin n → Z) => F p.1 p.2) := by\n rw [hF]\n refine measurable_const.mul (Finset.measurable_sum _ (fun k _ => ?_))\n exact (hφ.comp ((hB.comp measurable_fst).prodMk\n ((measurable_pi_apply k).comp measurable_snd))).sub\n (hφ.comp ((hB.comp measurable_fst).prodMk ((measurable_pi_apply k).comp measurable_fst)))\n have hHmeas : Measurable H := by\n rw [hH]\n exact hFmeas.comp ((measurable_pi_lambda _ (fun k => (measurable_fst.comp\n (measurable_pi_apply k)))).prodMk\n (measurable_pi_lambda _ (fun k => (measurable_snd.comp (measurable_pi_apply k)))))\n have hHint : Integrable H (Measure.pi fun _ : Fin n => D.prod D) :=\n integrable_of_abs_le _ hHmeas M (fun w => hFabs _ _)\n have hFint : Integrable (fun p : (Fin n → Z) × (Fin n → Z) => F p.1 p.2)\n ((Measure.pi fun _ : Fin n => D).prod (Measure.pi fun _ : Fin n => D)) :=\n integrable_of_abs_le _ hFmeas M (fun p => hFabs _ _)\n -- the inner integral of `F`\n have hinner : ∀ s : Fin n → Z, ∫ s', F s s' ∂(Measure.pi fun _ : Fin n => D)\n = (∫ z, φ (B s) z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ (B s) (s k) := by\n intro s\n have hi : ∀ k : Fin n, Integrable (fun s' : Fin n → Z => φ (B s) (s' k))\n (Measure.pi fun _ : Fin n => D) := fun k =>\n integrable_comp_mp (measurePreserving_eval (fun _ : Fin n => D) k) (hintφ (B s))\n have hisum : Integrable (fun s' : Fin n → Z => (n:ℝ)⁻¹ * ∑ k, φ (B s) (s' k))\n (Measure.pi fun _ : Fin n => D) :=\n Integrable.const_mul (integrable_finset_sum _ (fun k _ => hi k)) _\n have hsplit : (fun s' : Fin n → Z => F s s')\n = fun s' => ((n:ℝ)⁻¹ * ∑ k, φ (B s) (s' k)) - ((n:ℝ)⁻¹ * ∑ k, φ (B s) (s k)) := by\n funext s'\n rw [hF]\n simp only\n rw [Finset.sum_sub_distrib]\n ring\n rw [hsplit, integral_sub hisum (integrable_const _), integral_const]\n simp only [smul_eq_mul, probReal_univ, one_mul]\n congr 1\n rw [integral_const_mul, integral_finset_sum _ (fun k _ => hi k)]\n rw [Finset.sum_congr rfl (fun k (_ : k ∈ Finset.univ) =>\n integral_comp_mp (measurePreserving_eval (fun _ : Fin n => D) k) (hintφ (B s)).1)]\n rw [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n field_simp\n have hHintegral : ∫ w, H w ∂(Measure.pi fun _ : Fin n => D.prod D)\n = ∫ s, ((∫ z, φ (B s) z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ (B s) (s k))\n ∂(Measure.pi fun _ : Fin n => D) := by\n have h1 : ∫ w, H w ∂(Measure.pi fun _ : Fin n => D.prod D)\n = ∫ p, F p.1 p.2\n ∂((Measure.pi fun _ : Fin n => D).prod (Measure.pi fun _ : Fin n => D)) :=\n integral_comp_mp hpair hFmeas.aestronglyMeasurable\n rw [h1, integral_prod _ hFint]\n exact integral_congr_ae (Filter.Eventually.of_forall hinner)\n -- invariance under sign flips\n have hTHint : ∀ σ : RadSigns n, Integrable (fun w => H (T σ w))\n (Measure.pi fun _ : Fin n => D.prod D) := fun σ =>\n integrable_comp_mp (hTmp σ) hHint\n have hTinv : ∀ σ : RadSigns n, ∫ w, H (T σ w) ∂(Measure.pi fun _ : Fin n => D.prod D)\n = ∫ w, H w ∂(Measure.pi fun _ : Fin n => D.prod D) := fun σ =>\n integral_comp_mp (hTmp σ) hHmeas.aestronglyMeasurable\n have hcard : (0:ℝ) < (Fintype.card (RadSigns n) : ℝ) := by\n exact_mod_cast card_radSigns_pos n\n -- the pointwise symmetrisation bound\n have hptw : ∀ w : Fin n → Z × Z,\n (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, H (T σ w)\n ≤ empRadSigned n gg (fun k => (w k).2) + empRadSigned n gg (fun k => (w k).1) := by\n intro w\n have hkey : ∀ σ : RadSigns n, H (T σ w)\n ≤ U σ (fun k => (w k).2) + U (negSign σ) (fun k => (w k).1) := by\n intro σ\n have hfG : B (fun k => (T σ w k).1) ∈ G := hBmem _\n set f : Pred := B (fun k => (T σ w k).1) with hf\n have hterm : ∀ k : Fin n, φ f ((T σ w k).2) - φ f ((T �� w k).1)\n = (σ k : ℝ) * (φ f ((w k).2) - φ f ((w k).1)) := by\n intro k\n by_cases hk : ((σ k : ℤ)) = 1\n · simp only [hT, hk, if_true, id_eq]\n norm_num\n · have hm : ((σ k : ℤ)) = -1 := by\n have h := (σ k).2\n simp only [Finset.mem_insert, Finset.mem_singleton] at h\n rcases h with h | h\n · exact h\n · exact absurd h hk\n have hr : ((σ k : ℤ) : ℝ) = -1 := by rw [hm]; norm_num\n simp only [hT, hk, if_false, Prod.swap_prod_mk, Prod.fst_swap, Prod.snd_swap]\n rw [hr]; ring\n have hHval : H (T σ w) = ((n:ℝ)⁻¹ * ∑ k, (σ k : ℝ) * φ f ((w k).2))\n + ((n:ℝ)⁻¹ * ∑ k, ((negSign σ) k : ℝ) * φ f ((w k).1)) := by\n show F (fun k => (T σ w k).1) (fun k => (T σ w k).2) = _\n rw [hF]\n simp only\n rw [Finset.sum_congr rfl (fun k (_ : k ∈ Finset.univ) => hterm k)]\n have hs : ∑ k, (σ k : ℝ) * (φ f ((w k).2) - φ f ((w k).1))\n = (∑ k, (σ k : ℝ) * φ f ((w k).2))\n + ∑ k, ((negSign σ) k : ℝ) * φ f ((w k).1) := by\n rw [← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl (fun k _ => ?_)\n rw [negSign_coe]\n ring\n rw [hs]; ring\n have h1 : (n:ℝ)⁻¹ * ∑ k, (σ k : ℝ) * φ f ((w k).2) ≤ U σ (fun k => (w k).2) :=\n le_ciSup (hbdd _ σ) (⟨f, hfG⟩ : G)\n have h2 : (n:ℝ)⁻¹ * ∑ k, ((negSign σ) k : ℝ) * φ f ((w k).1)\n ≤ U (negSign σ) (fun k => (w k).1) :=\n le_ciSup (hbdd _ (negSign σ)) (⟨f, hfG⟩ : G)\n rw [hHval]\n linarith\n have hstep1 : (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, H (T σ w)\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, (U σ (fun k => (w k).2) + U (negSign σ) (fun k => (w k).1)) :=\n mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun σ _ => hkey σ))\n (le_of_lt (inv_pos.2 hcard))\n refine hstep1.trans (le_of_eq ?_)\n rw [Finset.sum_add_distrib, mul_add]\n have e1 : (Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, U σ (fun k => (w k).2)\n = empRadSigned n gg (fun k => (w k).2) := rfl\n have e2 : (Fintype.card (RadSigns n) : ℝ)⁻¹ *\n ∑ σ : RadSigns n, U (negSign σ) (fun k => (w k).1)\n = empRadSigned n gg (fun k => (w k).1) := by\n have hre : ∑ σ : RadSigns n, U (negSign σ) (fun k => (w k).1)\n = ∑ σ : RadSigns n, U σ (fun k => (w k).1) :=\n Fintype.sum_equiv (negSignEquiv n) _ _ (fun σ => rfl)\n rw [hre]\n rfl\n rw [e1, e2]\n -- assemble\n have hradCx : radCx n φ G D\n = ∫ s, empRadSigned n gg s ∂(Measure.pi fun _ : Fin n => D) := rfl\n have hI1 : Integrable (fun w : Fin n → Z × Z => empRadSigned n gg (fun k => (w k).1))\n (Measure.pi fun _ : Fin n => D.prod D) := integrable_comp_mp hp1 hRint\n have hI2 : Integrable (fun w : Fin n → Z × Z => empRadSigned n gg (fun k => (w k).2))\n (Measure.pi fun _ : Fin n => D.prod D) := integrable_comp_mp hp2 hRint\n have hE1 : ∫ w, empRadSigned n gg (fun k => (w k).1)\n ∂(Measure.pi fun _ : Fin n => D.prod D) = radCx n φ G D :=\n integral_comp_mp hp1 hRint.1\n have hE2 : ∫ w, empRadSigned n gg (fun k => (w k).2)\n ∂(Measure.pi fun _ : Fin n => D.prod D) = radCx n φ G D :=\n integral_comp_mp hp2 hRint.1\n have hIsum : Integrable (fun w : Fin n → Z × Z =>\n (empRadSigned n gg (fun k => (w k).2)) + empRadSigned n gg (fun k => (w k).1))\n (Measure.pi fun _ : Fin n => D.prod D) := hI2.add hI1\n have havg : ∫ w, ((Fintype.card (RadSigns n) : ℝ)⁻¹ * ∑ σ : RadSigns n, H (T σ w))\n ∂(Measure.pi fun _ : Fin n => D.prod D)\n = ∫ w, H w ∂(Measure.pi fun _ : Fin n => D.prod D) := by\n rw [integral_const_mul, integral_finset_sum _ (fun σ _ => hTHint σ)]\n simp only [hTinv]\n rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]\n field_simp\n rw [← hHintegral, ← havg]\n refine (integral_mono (by\n refine integrable_of_abs_le _ ?_ M (fun w => ?_)\n · exact measurable_const.mul (Finset.measurable_sum _\n (fun σ _ => hHmeas.comp (hTmp σ).measurable))\n · have hb : ∀ σ : RadSigns n, |H (T σ w)| ≤ M := fun σ => hFabs _ _\n rw [abs_mul, abs_of_nonneg (le_of_lt (inv_pos.2 hcard))]\n have h1 : |∑ σ : RadSigns n, H (T σ w)| ≤ (Fintype.card (RadSigns n) : ℝ) * M := by\n refine le_trans (Finset.abs_sum_le_sum_abs _ _) ?_\n calc ∑ σ : RadSigns n, |H (T σ w)| ≤ ∑ _σ : RadSigns n, M :=\n Finset.sum_le_sum (fun σ _ => hb σ)\n _ = (Fintype.card (RadSigns n) : ℝ) * M := by\n simp [Finset.card_univ, mul_comm]\n calc (Fintype.card (RadSigns n) : ℝ)⁻¹ * |∑ σ : RadSigns n, H (T σ w)|\n ≤ (Fintype.card (RadSigns n) : ℝ)⁻¹ * ((Fintype.card (RadSigns n) : ℝ) * M) :=\n mul_le_mul_of_nonneg_left h1 (le_of_lt (inv_pos.2 hcard))\n _ = M := by field_simp) hIsum hptw).trans (le_of_eq ?_)\n rw [integral_add hI2 hI1, hE1, hE2]\n ring\n\n\n\n/-- The key uniform-convergence tail bound for a measurable (approximate ERM) selection. -/\ntheorem crux {Z Pred : Type*} [MeasurableSpace Z] [Nonempty Z] [MeasurableSpace Pred]\n (D : Measure Z) [IsProbabilityMeasure D]\n (φ : Pred → Z → ℝ) (hφ : Measurable (fun p : Pred × Z => φ p.1 p.2))\n (M : ℝ) (hMb : ∀ f, ∀ z z' : Z, φ f z - φ f z' ≤ M)\n (hintφ : ∀ f, Integrable (fun z => φ f z) D)\n {n : ℕ} (hn : 0 < n) (G : Set Pred)\n (hbdd : ∀ (s : Fin n → Z) (σ : RadSigns n),\n BddAbove (Set.range (fun f : G => (n : ℝ)⁻¹ * ∑ k, (σ k : ℝ) * φ (f : Pred) (s k))))\n (hRint : Integrable (fun s : Fin n → Z =>\n empRadSigned n (fun f : G => fun z => φ (f : Pred) z) s) (Measure.pi fun _ : Fin n => D))\n (Asel : (Fin n → Z) → Pred) (hAm : Measurable Asel) (hAmem : ∀ s, Asel s ∈ G)\n {t : ℝ} (ht : 0 ≤ t) :\n (Measure.pi fun _ : Fin n => D).real\n {s | 2 * radCx n φ G D + t ≤ (∫ z, φ (Asel s) z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ (Asel s) (s k)}\n ≤ Real.exp (-(2 * n * t ^ 2) / M ^ 2) := by\n classical\n obtain ⟨z₀⟩ := ‹Nonempty Z›\n have hnR : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn\n have hM0 : (0:ℝ) ≤ M := by have := hMb (Asel (fun _ => z₀)) z₀ z₀; linarith\n set c : ℝ := M / (n:ℝ) with hcdef\n have hc0 : (0:ℝ) ≤ c := by rw [hcdef]; positivity\n set J : Pred → (Fin n → Z) → ℝ := fun f s =>\n (∫ z, φ f z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ f (s k) with hJdef\n have hpopmeas : Measurable (fun f : Pred => ∫ z, φ f z ∂D) :=\n (MeasureTheory.StronglyMeasurable.integral_prod_right' (ν := D)\n hφ.stronglyMeasurable).measurable\n have hJmeas : Measurable (fun q : Pred × (Fin n → Z) => J q.1 q.2) := by\n rw [hJdef]\n refine (hpopmeas.comp measurable_fst).sub (measurable_const.mul\n (Finset.measurable_sum _ (fun k _ => ?_)))\n exact hφ.comp (measurable_fst.prodMk ((measurable_pi_apply k).comp measurable_snd))\n -- the score is bounded by `M`\n have hkeybd : ∀ (f : Pred) (z : Z), |(∫ z', φ f z' ∂D) - φ f z| ≤ M := by\n intro f z\n have h1 : (∫ z', φ f z' ∂D) - φ f z = ∫ z', (φ f z' - φ f z) ∂D := by\n rw [integral_sub (hintφ f) (integrable_const _)]\n simp\n rw [h1, abs_le]\n constructor\n · have h2 : ∫ _z' : Z, (-M : ℝ) ∂D ≤ ∫ z', (φ f z' - φ f z) ∂D := by\n refine integral_mono (integrable_const _)\n ((hintφ f).sub (integrable_const _)) (fun z' => ?_)\n have := hMb f z z'\n linarith\n simpa using h2\n · have h2 : ∫ z', (φ f z' - φ f z) ∂D ≤ ∫ _z' : Z, (M : ℝ) ∂D := by\n refine integral_mono ((hintφ f).sub (integrable_const _))\n (integrable_const _) (fun z' => hMb f z' z)\n simpa using h2\n have hJabs : ∀ (f : Pred) (s : Fin n → Z), |J f s| ≤ M := by\n intro f s\n have hrw : J f s = (n:ℝ)⁻¹ * ∑ k, ((∫ z, φ f z ∂D) - φ f (s k)) := by\n rw [hJdef]\n simp only [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin,\n nsmul_eq_mul]\n field_simp\n rw [hrw, abs_mul, abs_of_nonneg (le_of_lt (inv_pos.2 hnR))]\n have h1 : |∑ k, ((∫ z, φ f z ∂D) - φ f (s k))| ≤ (n:ℝ) * M := by\n refine le_trans (Finset.abs_sum_le_sum_abs _ _) ?_\n calc ∑ k : Fin n, |(∫ z, φ f z ∂D) - φ f (s k)| ≤ ∑ _k : Fin n, M :=\n Finset.sum_le_sum (fun k _ => hkeybd f (s k))\n _ = (n:ℝ) * M := by simp [Finset.card_univ, mul_comm]\n calc (n:ℝ)⁻¹ * |∑ k, ((∫ z, φ f z ∂D) - φ f (s k))|\n ≤ (n:ℝ)⁻¹ * ((n:ℝ) * M) := mul_le_mul_of_nonneg_left h1 (le_of_lt (inv_pos.2 hnR))\n _ = M := by field_simp\n -- one-coordinate perturbations move the score by at most `c`\n have hJupd : ∀ (f : Pred) (s : Fin n → Z) (k : Fin n) (z : Z),\n J f s ≤ J f (Function.update s k z) + c := by\n intro f s k z\n have hsum : ∑ j, φ f (Function.update s k z j) = (∑ j, φ f (s j)) + (φ f z - φ f (s k)) := by\n have h1 : ∀ j : Fin n, φ f (Function.update s k z j)\n = φ f (s j) + (if j = k then φ f z - φ f (s k) else 0) := by\n intro j\n by_cases h : j = k\n · subst h; simp\n · simp [Function.update_of_ne h, h]\n rw [Finset.sum_congr rfl (fun j (_ : j ∈ Finset.univ) => h1 j), Finset.sum_add_distrib]\n simp\n have hd : J f s - J f (Function.update s k z) = (n:ℝ)⁻¹ * (φ f z - φ f (s k)) := by\n rw [hJdef]\n simp only\n rw [hsum]\n ring\n have hb : (n:ℝ)⁻¹ * (φ f z - φ f (s k)) ≤ c := by\n rw [hcdef]\n have := hMb f z (s k)\n have hinv : (0:ℝ) < (n:ℝ)⁻¹ := inv_pos.2 hnR\n calc (n:ℝ)⁻¹ * (φ f z - φ f (s k)) ≤ (n:ℝ)⁻¹ * M :=\n mul_le_mul_of_nonneg_left this (le_of_lt hinv)\n _ = M / (n:ℝ) := by field_simp\n linarith [hd, hb]\n -- essential suprema over measurable selections\n obtain ⟨Ψ, C, hCmeas, hCmem, hΨdef, hΨmeas, hΨbd, hΨdom, hΨintle⟩ :=\n exists_esssup_sel (Measure.pi fun _ : Fin n => D) G (Asel (fun _ => z₀)) (hAmem _) J hJmeas M\n (fun f _ s => hJabs f s)\n obtain ⟨Ψh, Ch, hChmeas, hChmem, hΨhdef, hΨhmeas, hΨhbd, hΨhdom, hΨhintle⟩ :=\n exists_esssup_sel ((Measure.pi fun _ : Fin n => D).prod D) G (Asel (fun _ => z₀)) (hAmem _)\n (fun f p => J f p.1)\n (hJmeas.comp (measurable_fst.prodMk (measurable_fst.comp measurable_snd))) M\n (fun f _ p => hJabs f p.1)\n -- the two essential suprema agree\n have hdom1 : ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D), Ψ p.1 ≤ Ψh p := by\n have hj : ∀ j : ℕ, ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D),\n J (C j p.1) p.1 ≤ Ψh p :=\n fun j => hΨhdom (fun p => C j p.1) ((hCmeas j).comp measurable_fst)\n (fun p => hCmem j p.1)\n filter_upwards [ae_all_iff.2 hj] with p hp\n rw [hΨdef]\n exact ciSup_le (fun j => hp j)\n have hdom2 : ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D), Ψh p ≤ Ψ p.1 := by\n have hj : ∀ j : ℕ, ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D),\n J (Ch j p) p.1 ≤ Ψ p.1 := by\n intro j\n have hmset : MeasurableSet {q : (Fin n → Z) × Z | J (Ch j q) q.1 ≤ Ψ q.1} := by\n refine measurableSet_le ?_ (hΨmeas.comp measurable_fst)\n exact hJmeas.comp ((hChmeas j).prodMk measurable_fst)\n have hz : ∀ z : Z, ∀ᵐ s ∂(Measure.pi fun _ : Fin n => D), J (Ch j (s, z)) s ≤ Ψ s :=\n fun z => hΨdom (fun s => Ch j (s, z))\n ((hChmeas j).comp (measurable_id.prodMk measurable_const))\n (fun s => hChmem j (s, z))\n refine (Measure.ae_prod_iff_ae_ae hmset).2 ?_\n exact (Measure.ae_ae_comm hmset).2 (Filter.Eventually.of_forall hz)\n filter_upwards [ae_all_iff.2 hj] with p hp\n rw [hΨhdef]\n exact ciSup_le (fun j => hp j)\n -- bounded differences for the essential supremum\n have hbdiff : ∀ k : Fin n, ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D),\n Ψ p.1 ≤ Ψ (Function.update p.1 k p.2) + c := by\n intro k\n have hRmp : MeasurePreserving (fun p : (Fin n → Z) × Z => (Function.update p.1 k p.2, p.1 k))\n ((Measure.pi fun _ : Fin n => D).prod D)\n ((Measure.pi fun _ : Fin n => D).prod D) := measurePreserving_updateSwap D k\n have hRinv : ∀ p : (Fin n → Z) × Z,\n ((Function.update (Function.update p.1 k p.2) k (p.1 k)\n : Fin n → Z), (Function.update p.1 k p.2 : Fin n → Z) k) = p := by\n intro p\n refine Prod.ext ?_ ?_\n · show Function.update (Function.update p.1 k p.2) k (p.1 k) = p.1\n rw [Function.update_idem, Function.update_eq_self]\n · show (Function.update p.1 k p.2 : Fin n → Z) k = p.2\n rw [Function.update_self]\n have hstep : ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D),\n Ψh p ≤ Ψh (Function.update p.1 k p.2, p.1 k) + c := by\n have hj : ∀ j : ℕ, ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D),\n J (Ch j p) p.1 ≤ Ψh (Function.update p.1 k p.2, p.1 k) + c := by\n intro j\n have h1 := hΨhdom (fun p : (Fin n → Z) × Z => Ch j (Function.update p.1 k p.2, p.1 k))\n ((hChmeas j).comp hRmp.measurable)\n (fun p => hChmem j (Function.update p.1 k p.2, p.1 k))\n have hmset : MeasurableSet {p : (Fin n → Z) × Z |\n J (Ch j (Function.update p.1 k p.2, p.1 k)) p.1 ≤ Ψh p} := by\n refine measurableSet_le ?_ hΨhmeas\n exact hJmeas.comp (((hChmeas j).comp hRmp.measurable).prodMk measurable_fst)\n have h2 := ae_comp_of_measurePreserving hRmp hmset h1\n filter_upwards [h2] with p hp\n rw [hRinv p] at hp\n have h3 := hJupd (Ch j p) p.1 k p.2\n exact le_trans h3 (by linarith [hp])\n filter_upwards [ae_all_iff.2 hj] with p hp\n rw [hΨhdef]\n exact ciSup_le (fun j => hp j)\n have hdom2R : ∀ᵐ p ∂((Measure.pi fun _ : Fin n => D).prod D),\n Ψh (Function.update p.1 k p.2, p.1 k) ≤ Ψ (Function.update p.1 k p.2) := by\n have hmset : MeasurableSet {p : (Fin n → Z) × Z | Ψh p ≤ Ψ p.1} :=\n measurableSet_le hΨhmeas (hΨmeas.comp measurable_fst)\n exact ae_comp_of_measurePreserving hRmp hmset hdom2\n filter_upwards [hdom1, hstep, hdom2R] with p h1 h2 h3\n linarith\n -- the mean of the essential supremum is at most twice the Rademacher complexity\n have hΨle : ∫ s, Ψ s ∂(Measure.pi fun _ : Fin n => D) ≤ 2 * radCx n φ G D :=\n hΨintle _ (fun B hBm hBmm => sym_sel D φ hφ M hMb hintφ hn G hbdd hRint B hBm hBmm)\n -- McDiarmid\n have hmcd := mcdiarmid D c hc0 M Ψ hΨmeas hΨbd hbdiff ht\n have hexp : Real.exp (-(2 * t ^ 2) / ((n:ℝ) * c ^ 2))\n = Real.exp (-(2 * (n:ℝ) * t ^ 2) / M ^ 2) := by\n congr 1\n rcases eq_or_lt_of_le hM0 with hM | hM\n · rw [hcdef, ← hM]\n simp\n · rw [hcdef]\n field_simp\n rw [hexp] at hmcd\n refine le_trans (le_trans (ENNReal.toReal_mono (measure_ne_top _ _) ?_) hmcd) (le_refl _)\n refine measure_mono_ae ?_\n filter_upwards [hΨdom Asel hAm hAmem] with s hs hmem\n show (∫ s', Ψ s' ∂(Measure.pi fun _ : Fin n => D)) + t ≤ Ψ s\n have hJs : J (Asel s) s = (∫ z, φ (Asel s) z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ (Asel s) (s k) := rfl\n rw [hJs] at hs\n have hmem' : 2 * radCx n φ G D + t\n ≤ (∫ z, φ (Asel s) z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ (Asel s) (s k) := hmem\n linarith [hΨle, hs, hmem']\n\n/-- If every `x`-section of `S` has `ρ`-measure at most `b`, the product measure of `S` is at\nmost `b`. -/\ntheorem prod_real_le {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y]\n (μ : Measure X) (ρ : Measure Y) [IsProbabilityMeasure μ] [IsFiniteMeasure ρ] [SFinite ρ]\n {S : Set (X × Y)} (hS : MeasurableSet S) {b : ℝ} (hb : 0 ≤ b)\n (hsec : ∀ x, ρ.real (Prod.mk x ⁻¹' S) ≤ b) :\n (μ.prod ρ).real S ≤ b := by\n have h1 : (μ.prod ρ) S = ∫⁻ x, ρ (Prod.mk x ⁻¹' S) ∂μ := Measure.prod_apply hS\n have h2 : ∀ x, ρ (Prod.mk x ⁻¹' S) ≤ ENNReal.ofReal b := by\n intro x\n have hx := hsec x\n rw [← ENNReal.ofReal_toReal (measure_ne_top ρ (Prod.mk x ⁻¹' S))]\n exact ENNReal.ofReal_le_ofReal hx\n have h3 : (μ.prod ρ) S ≤ ENNReal.ofReal b := by\n rw [h1]\n calc ∫⁻ x, ρ (Prod.mk x ⁻¹' S) ∂μ ≤ ∫⁻ _, ENNReal.ofReal b ∂μ := lintegral_mono h2\n _ = ENNReal.ofReal b := by simp\n calc (μ.prod ρ).real S ≤ (ENNReal.ofReal b).toReal :=\n ENNReal.toReal_mono (by simp) h3\n _ = b := ENNReal.toReal_ofReal hb\n\ntheorem prod_real_fst {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y]\n (μ : Measure X) (ρ : Measure Y) [IsProbabilityMeasure ρ] [SFinite μ] [SFinite ρ]\n (S : Set X) : (μ.prod ρ).real {p : X × Y | p.1 ∈ S} = μ.real S := by\n have hs : {p : X × Y | p.1 ∈ S} = S ×ˢ (Set.univ : Set Y) := by ext p; simp\n simp only [Measure.real, hs, Measure.prod_prod, measure_univ, mul_one]\n\n/-- The constant sign vector `-1`. -/\ndef negOne (n : ℕ) : RadSigns n := fun _ => ⟨-1, by decide⟩\n\n@[simp] theorem negOne_coe (n : ℕ) (k : Fin n) : ((negOne n k : ℤ) : ℝ) = -1 := by\n simp [negOne]\n\n/-- Boundedness above of all signed empirical averages gives boundedness below of the\n(unsigned) empirical averages. -/\ntheorem bddBelow_emp {Pred : Type*} {Z : Type*} {n : ℕ} (φ : Pred → Z → ℝ) (G : Set Pred)\n (s : Fin n → Z)\n (h : ∀ σ : RadSigns n, BddAbove (Set.range (fun f : G =>\n (n : ℝ)⁻¹ * ∑ k, (σ k : ℝ) * φ (f : Pred) (s k)))) :\n BddBelow (Set.range (fun f : G => (n : ℝ)⁻¹ * ∑ k, φ (f : Pred) (s k))) := by\n obtain ⟨c, hc⟩ := h (negOne n)\n refine ⟨-c, ?_⟩\n rintro x ⟨f, rfl⟩\n have hx := hc (Set.mem_range_self f)\n simp only [negOne_coe, neg_mul, one_mul, Finset.sum_neg_distrib, mul_neg] at hx\n linarith\n\nend Ch8Aux\n\n\ntheorem ch8_corollary_8_3\n {Z Pred : Type*} [MeasurableSpace Z] [Nonempty Z] [MeasurableSpace Pred]\n (D : Measure Z) [IsProbabilityMeasure D]\n (φ : Pred → Z → ℝ)\n (F : ℕ+ → Set Pred)\n (hFne : ∀ θ, (F θ).Nonempty)\n (hint : ∀ f, Integrable (fun z => φ f z) D)\n (M ε' εt δ : ℝ) (n m : ℕ)\n (hn : 0 < n) (hm : 0 < m)\n (hδ : 0 < δ ∧ δ < 1)\n (hM : ∀ f, ∀ z z' : Z, φ f z - φ f z' ≤ M)\n (hBddAbove : ∀ (θ : ℕ+) (s : Fin n → Z) (σ : RadSigns n),\n BddAbove (Set.range (fun f : F θ =>\n (n : ℝ)⁻¹ * ∑ k : Fin n, (σ k : ℝ) * φ (f : Pred) (s k))))\n (hRadInt : ∀ θ : ℕ+, Integrable\n (fun s : Fin n → Z => empRadSigned n\n (fun f : F θ => fun z => φ (f : Pred) z) s)\n (Measure.pi (fun _ : Fin n => D)))\n (q : ℕ+ → ℝ) (hq_pos : ∀ θ, 0 < q θ)\n (hq_summable : Summable q)\n (hq_sum : ∑' θ, q θ ≤ 1)\n {Ωs : Type*} [MeasurableSpace Ωs] (P : Measure Ωs) [IsProbabilityMeasure P]\n (Strain : Ωs → Fin n → Z) (Sval : Ωs → Fin m → Z)\n (hStrain_meas : Measurable Strain) (hSval_meas : Measurable Sval)\n (hStrain_law : ∀ i, Measure.map (fun ω => Strain ω i) P = D)\n (hSval_law : ∀ i, Measure.map (fun ω => Sval ω i) P = D)\n (hStrain_indep : iIndepFun (fun i ω => Strain ω i) P)\n (hSval_indep : iIndepFun (fun i ω => Sval ω i) P)\n (hSplit_indep : IndepFun Strain Sval P)\n (A : ℕ+ → (Fin n → Z) → Pred) (hA_mem : ∀ θ s, A θ s ∈ F θ)\n (hA_meas : ∀ θ, Measurable (A θ))\n\n (hφ_meas : Measurable (fun p : Pred × Z => φ p.1 p.2))\n (hERM : ∀ θ s, (n:ℝ)⁻¹ * ∑ i, φ (A θ s) (s i) ≤ (⨅ f : F θ, (n:ℝ)⁻¹ * ∑ i, φ (f:Pred) (s i)) + ε')\n (thetaHat : (Fin n → Z) → (Fin m → Z) → ℕ+)\n\n (hSel : ∀ s v, ((m:ℝ)⁻¹ * ∑ i, φ (A (thetaHat s v) s) (v i) + rmPenalty M m (q (thetaHat s v))) ≤ (⨅ θ:ℕ+, ((m:ℝ)⁻¹ * ∑ i, φ (A θ s) (v i) + rmPenalty M m (q θ))) + εt)\n (hbddSel : ∀ (s : Fin n → Z) (v : Fin m → Z), BddBelow (Set.range (fun θ : ℕ+ =>\n (m:ℝ)⁻¹ * ∑ i, φ (A θ s) (v i) + rmPenalty M m (q θ))))\n (hbddOracle : BddBelow (Set.range (fun θ : ℕ+ =>\n (⨅ f : F θ, ∫ z, φ (f:Pred) z ∂D) + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ)))) :\n 1 - δ ≤ (P {ω : Ωs | ∫ z, φ (A (thetaHat (Strain ω) (Sval ω)) (Strain ω)) z ∂D ≤ (⨅ θ:ℕ+, ((⨅ f : F θ, ∫ z, φ (f:Pred) z ∂D) + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ))) + εt + ε' + M * Real.sqrt (2 * Real.log (4/δ) / n) + M * Real.sqrt (2 * Real.log (4/δ) / m)}).toReal := by\n classical\n obtain ⟨hδ0, hδ1⟩ := hδ\n obtain ⟨f₀, hf₀⟩ := hFne 1\n have hM0 : 0 ≤ M := by\n obtain ⟨z₀⟩ := ‹Nonempty Z›\n have h := hM f₀ z₀ z₀\n simpa using h\n have hnR : (0:ℝ) < (n:ℝ) := by exact_mod_cast hn\n have hmR : (0:ℝ) < (m:ℝ) := by exact_mod_cast hm\n have hpopmeas : Measurable (fun f : Pred => ∫ z, φ f z ∂D) :=\n (MeasureTheory.StronglyMeasurable.integral_prod_right' (ν := D)\n hφ_meas.stronglyMeasurable).measurable\n -- laws of the samples\n have hmapS : Measure.map Strain P = Measure.pi (fun _ : Fin n => D) := by\n have h : Measure.map (fun (ω : Ωs) (i : Fin n) => Strain ω i) P\n = Measure.pi (fun i => Measure.map (fun ω => Strain ω i) P) :=\n (iIndepFun_iff_map_fun_eq_pi_map (μ := P) (f := fun i ω => Strain ω i)\n (fun i => ((measurable_pi_apply i).comp hStrain_meas).aemeasurable)).1 hStrain_indep\n simp only [hStrain_law] at h\n exact h\n have hmapV : Measure.map Sval P = Measure.pi (fun _ : Fin m => D) := by\n have h : Measure.map (fun (ω : Ωs) (i : Fin m) => Sval ω i) P\n = Measure.pi (fun i => Measure.map (fun ω => Sval ω i) P) :=\n (iIndepFun_iff_map_fun_eq_pi_map (μ := P) (f := fun i ω => Sval ω i)\n (fun i => ((measurable_pi_apply i).comp hSval_meas).aemeasurable)).1 hSval_indep\n simp only [hSval_law] at h\n exact h\n set ν : Measure ((Fin n → Z) × (Fin m → Z)) :=\n (Measure.pi (fun _ : Fin n => D)).prod (Measure.pi (fun _ : Fin m => D)) with hνdef\n haveI : IsProbabilityMeasure ν := by rw [hνdef]; infer_instance\n have hmapT : Measure.map (fun ω => (Strain ω, Sval ω)) P = ν := by\n rw [hνdef, (indepFun_iff_map_prod_eq_prod_map_map hStrain_meas.aemeasurable\n hSval_meas.aemeasurable).1 hSplit_indep, hmapS, hmapV]\n -- constants\n set L : ℝ := Real.log (4 / δ) with hLdef\n set an : ℝ := M * Real.sqrt (L / (2 * n)) with handef\n set am : ℝ := M * Real.sqrt (L / (2 * m)) with hamdef\n have han0 : 0 ≤ an := by\n rw [handef]; exact mul_nonneg hM0 (Real.sqrt_nonneg _)\n have ham0 : 0 ≤ am := by\n rw [hamdef]; exact mul_nonneg hM0 (Real.sqrt_nonneg _)\n set cstar : ℝ := (⨅ θ : ℕ+, ((⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D)\n + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ))) + ε' + 2 * an + am with hcstardef\n -- the events\n set Om1 : Set ((Fin n → Z) × (Fin m → Z)) :=\n {p | ∀ θ : ℕ+, (∫ z, φ (A θ p.1) z ∂D)\n ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am} with hOm1def\n set Om2 : ℕ+ → Set ((Fin n → Z) × (Fin m → Z)) := fun θ =>\n {p | (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) ≤ (∫ z, φ (A θ p.1) z ∂D) + am} with hOm2def\n set Om3 : ℕ+ → Set ((Fin n → Z) × (Fin m → Z)) := fun θ =>\n {p | (∫ z, φ (A θ p.1) z ∂D) - (n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ 2 * radCx n φ (F θ) D + an} with hOm3def\n set Om4 : ℕ+ → Set ((Fin n → Z) × (Fin m → Z)) := fun θ =>\n {p | (n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an} with hOm4def\n set Yf : ((Fin n → Z) × (Fin m → Z)) → ℝ := fun p =>\n ⨅ θ : ℕ+, ((m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ)) with hYfdef\n -- measurability\n have hmeas_pop : ∀ θ : ℕ+, Measurable (fun p : (Fin n → Z) × (Fin m → Z) =>\n ∫ z, φ (A θ p.1) z ∂D) := fun θ => hpopmeas.comp ((hA_meas θ).comp measurable_fst)\n have hmeas_em : ∀ θ : ℕ+, Measurable (fun p : (Fin n → Z) × (Fin m → Z) =>\n (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i)) := by\n intro θ\n refine measurable_const.mul (Finset.measurable_sum _ (fun i _ => ?_))\n exact hφ_meas.comp (((hA_meas θ).comp measurable_fst).prodMk\n ((measurable_pi_apply i).comp measurable_snd))\n have hmeas_en : ∀ θ : ℕ+, Measurable (fun p : (Fin n → Z) × (Fin m → Z) =>\n (n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)) := by\n intro θ\n refine measurable_const.mul (Finset.measurable_sum _ (fun i _ => ?_))\n exact hφ_meas.comp (((hA_meas θ).comp measurable_fst).prodMk\n ((measurable_pi_apply i).comp measurable_fst))\n have hmeasOm1 : MeasurableSet Om1 := by\n rw [hOm1def, Set.setOf_forall]\n exact MeasurableSet.iInter (fun θ =>\n measurableSet_le (hmeas_pop θ) (((hmeas_em θ).add measurable_const).add measurable_const))\n have hmeasOm2 : ∀ θ, MeasurableSet (Om2 θ) := fun θ => by\n rw [hOm2def]; exact measurableSet_le (hmeas_em θ) ((hmeas_pop θ).add measurable_const)\n have hmeasOm3 : ∀ θ, MeasurableSet (Om3 θ) := fun θ => by\n rw [hOm3def]\n exact measurableSet_le ((hmeas_pop θ).sub (hmeas_en θ)) measurable_const\n have hmeasOm4 : ∀ θ, MeasurableSet (Om4 θ) := fun θ => by\n rw [hOm4def]; exact measurableSet_le (hmeas_en θ) measurable_const\n have hmeasY : Measurable Yf := by\n rw [hYfdef]\n exact Measurable.iInf (fun θ => (hmeas_em θ).add measurable_const)\n -- the four probability estimates\n -- elementary facts about the constants\n have hnne : (n : ℝ) ≠ 0 := ne_of_gt hnR\n have hmne : (m : ℝ) ≠ 0 := ne_of_gt hmR\n have hL0 : 0 ≤ L := by\n rw [hLdef]\n refine Real.log_nonneg ?_\n rw [le_div_iff₀ hδ0]\n linarith\n have hexpL : Real.exp (-L) = δ / 4 := by\n rw [hLdef, Real.exp_neg, Real.exp_log (by positivity), inv_div]\n have hφf : ∀ f : Pred, Measurable (fun z => φ f z) := fun f =>\n hφ_meas.comp (measurable_const.prodMk measurable_id)\n have hrmdef : ∀ x : ℝ, rmPenalty M m x = M * Real.sqrt (Real.log (1 / x) / (2 * m)) :=\n fun _ => rfl\n have hrm0 : ∀ x : ℝ, 0 ≤ rmPenalty M m x := fun x => by\n rw [hrmdef]; exact mul_nonneg hM0 (Real.sqrt_nonneg _)\n have hanexp : 0 < M → (-(2 * (n : ℝ) * an ^ 2) / M ^ 2) = -L := by\n intro hMp\n have hsq : an ^ 2 = M ^ 2 * (L / (2 * n)) := by\n rw [handef, mul_pow, Real.sq_sqrt (div_nonneg hL0 (by positivity))]\n have hM2 : (M : ℝ) ^ 2 ≠ 0 := by positivity\n rw [hsq]\n field_simp\n have hamexp : 0 < M → (-(2 * (m : ℝ) * am ^ 2) / M ^ 2) = -L := by\n intro hMp\n have hsq : am ^ 2 = M ^ 2 * (L / (2 * m)) := by\n rw [hamdef, mul_pow, Real.sq_sqrt (div_nonneg hL0 (by positivity))]\n have hM2 : (M : ℝ) ^ 2 ≠ 0 := by positivity\n rw [hsq]\n field_simp\n have hMzero : M = 0 → ∀ (f : Pred) (z z' : Z), φ f z = φ f z' := by\n intro h0 f z z'\n have h1 := hM f z z'\n have h2 := hM f z' z\n rw [h0] at h1 h2\n linarith\n have hconstInt : M = 0 → ∀ (f : Pred) (w : Z), (∫ z, φ f z ∂D) = φ f w := by\n intro h0 f w\n have h : ∀ z, φ f z = φ f w := fun z => hMzero h0 f z w\n calc (∫ z, φ f z ∂D) = ∫ _z, φ f w ∂D :=\n integral_congr_ae (Filter.Eventually.of_forall h)\n _ = φ f w := by simp\n have hconstAvg : M = 0 → ∀ (N : ℕ), 0 < N → ∀ (f : Pred) (v : Fin N → Z) (w : Z),\n (N : ℝ)⁻¹ * ∑ i, φ f (v i) = φ f w := by\n intro h0 N hN f v w\n have h : ∀ i : Fin N, φ f (v i) = φ f w := fun i => hMzero h0 f (v i) w\n rw [Finset.sum_congr rfl (fun i (_ : i ∈ Finset.univ) => h i), Finset.sum_const,\n Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]\n have hNR : (N : ℝ) ≠ 0 := Nat.cast_ne_zero.2 (by omega)\n field_simp\n have hradnn : ∀ θ : ℕ+, 0 ≤ radCx n φ (F θ) D := by\n intro θ\n haveI : Nonempty (F θ) := (hFne θ).to_subtype\n refine integral_nonneg (fun s => ?_)\n exact Ch8Aux.empRadSigned_nonneg n _ _ (fun σ => hBddAbove θ _ σ)\n have hbddEmp : ∀ (θ : ℕ+) (s : Fin n → Z),\n BddBelow (Set.range (fun f : F θ => (n : ℝ)⁻¹ * ∑ i, φ (f : Pred) (s i))) :=\n fun θ s => Ch8Aux.bddBelow_emp φ (F θ) s (hBddAbove θ s)\n have hP1 : ν.real Om1ᶜ ≤ δ / 4 := by\n rcases eq_or_lt_of_le hM0 with hM00 | hMpos\n · have h0 : M = 0 := hM00.symm\n have hemp : Om1ᶜ = (∅ : Set ((Fin n → Z) × (Fin m → Z))) := by\n rw [Set.eq_empty_iff_forall_notMem]\n intro p hp\n have hp' : ¬ (∀ θ : ℕ+, (∫ z, φ (A θ p.1) z ∂D)\n ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am) := hp\n push_neg at hp'\n obtain ⟨θ, hθ⟩ := hp'\n rw [hconstInt h0 (A θ p.1) (p.2 ⟨0, hm⟩),\n hconstAvg h0 m hm (A θ p.1) p.2 (p.2 ⟨0, hm⟩)] at hθ\n have e1 : rmPenalty M m (q θ) = 0 := by rw [hrmdef, h0]; ring\n have e2 : am = 0 := by rw [hamdef, h0]; ring\n rw [e1, e2] at hθ\n linarith\n rw [hemp, measureReal_empty]\n linarith\n · have hMne : M ≠ 0 := ne_of_gt hMpos\n -- the exponential bound coming from Hoeffding, weighted by `q θ`\n have hkey1 : ∀ θ : ℕ+,\n Real.exp (-(2 * (m : ℝ) * (rmPenalty M m (q θ) + am) ^ 2) / M ^ 2)\n ≤ q θ * (δ / 4) := by\n intro θ\n have hqθ := hq_pos θ\n have hb0 : 0 ≤ L / (2 * m) := div_nonneg hL0 (by positivity)\n have hsqb : Real.sqrt (L / (2 * m)) ^ 2 = L / (2 * m) := Real.sq_sqrt hb0\n have hsqa : Real.log (1 / q θ) / (2 * m)\n ≤ Real.sqrt (Real.log (1 / q θ) / (2 * m)) ^ 2 := by\n rcases le_or_gt 0 (Real.log (1 / q θ) / (2 * m)) with h | h\n · rw [Real.sq_sqrt h]\n · rw [Real.sqrt_eq_zero_of_nonpos (le_of_lt h)]\n nlinarith\n have hcross : 0 ≤ Real.sqrt (Real.log (1 / q θ) / (2 * m))\n * Real.sqrt (L / (2 * m)) :=\n mul_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _)\n have ht : rmPenalty M m (q θ) + am\n = M * (Real.sqrt (Real.log (1 / q θ) / (2 * m)) + Real.sqrt (L / (2 * m))) := by\n rw [hrmdef, hamdef]; ring\n have hM2 : (0:ℝ) < M ^ 2 := by positivity\n have hexpand : Real.log (1 / q θ) / (2 * m) + L / (2 * m)\n ≤ (Real.sqrt (Real.log (1 / q θ) / (2 * m)) + Real.sqrt (L / (2 * m))) ^ 2 := by\n nlinarith\n have h2m : (0:ℝ) < 2 * m := by positivity\n have hstep : Real.log (1 / q θ) + L\n ≤ 2 * (m : ℝ) * (rmPenalty M m (q θ) + am) ^ 2 / M ^ 2 := by\n rw [ht, mul_pow]\n have hrw : 2 * (m : ℝ) * (M ^ 2 * (Real.sqrt (Real.log (1 / q θ) / (2 * m))\n + Real.sqrt (L / (2 * m))) ^ 2) / M ^ 2\n = 2 * (m : ℝ) * (Real.sqrt (Real.log (1 / q θ) / (2 * m))\n + Real.sqrt (L / (2 * m))) ^ 2 := by\n field_simp\n rw [hrw]\n calc Real.log (1 / q θ) + L\n = 2 * (m : ℝ) * (Real.log (1 / q θ) / (2 * m) + L / (2 * m)) := by field_simp\n _ ≤ 2 * (m : ℝ) * (Real.sqrt (Real.log (1 / q θ) / (2 * m))\n + Real.sqrt (L / (2 * m))) ^ 2 := by nlinarith\n calc Real.exp (-(2 * (m : ℝ) * (rmPenalty M m (q θ) + am) ^ 2) / M ^ 2)\n = Real.exp (-(2 * (m : ℝ) * (rmPenalty M m (q θ) + am) ^ 2 / M ^ 2)) := by\n rw [neg_div]\n _ ≤ Real.exp (-(Real.log (1 / q θ) + L)) := Real.exp_le_exp.2 (by linarith)\n _ = q θ * (δ / 4) := by\n rw [neg_add, Real.exp_add, Real.exp_neg (Real.log (1 / q θ)),\n Real.exp_log (one_div_pos.2 hqθ), hexpL, inv_div, div_one]\n have hmeasE : ∀ θ : ℕ+, MeasurableSet {p : (Fin n → Z) × (Fin m → Z) |\n (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am\n ≤ (∫ z, φ (A θ p.1) z ∂D)} := fun θ =>\n measurableSet_le (((hmeas_em θ).add measurable_const).add measurable_const)\n (hmeas_pop θ)\n have hEbound : ∀ θ : ℕ+, ν {p : (Fin n → Z) × (Fin m → Z) |\n (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am\n ≤ (∫ z, φ (A θ p.1) z ∂D)} ≤ ENNReal.ofReal (q θ * (δ / 4)) := by\n intro θ\n have hq4 : 0 ≤ q θ * (δ / 4) := by\n have := hq_pos θ; positivity\n refine (ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) hq4).2 ?_\n show ν.real {p : (Fin n → Z) × (Fin m → Z) |\n (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am\n ≤ (∫ z, φ (A θ p.1) z ∂D)} ≤ q θ * (δ / 4)\n rw [hνdef]\n refine Ch8Aux.prod_real_le _ _ (hmeasE θ) hq4 (fun s => ?_)\n have e1 : (∫ z, (-φ (A θ s) z) ∂D) = -(∫ z, φ (A θ s) z ∂D) := integral_neg _\n have e2 : ∀ v : Fin m → Z, (m : ℝ)⁻¹ * ∑ i, (-φ (A θ s) (v i))\n = -((m : ℝ)⁻¹ * ∑ i, φ (A θ s) (v i)) := by\n intro v; rw [Finset.sum_neg_distrib, mul_neg]\n have hsec : (Prod.mk s ⁻¹' {p : (Fin n → Z) × (Fin m → Z) |\n (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am\n ≤ (∫ z, φ (A θ p.1) z ∂D)})\n = {v : Fin m → Z | (∫ z, (-φ (A θ s) z) ∂D) + (rmPenalty M m (q θ) + am)\n ≤ (m : ℝ)⁻¹ * ∑ i, (-φ (A θ s) (v i))} := by\n ext v\n simp only [Set.mem_preimage, Set.mem_setOf_eq, e1, e2 v]\n constructor <;> intro h <;> linarith\n rw [hsec]\n refine le_trans (Ch8Aux.hoeffding_pi D hm (fun z => -φ (A θ s) z)\n ((hφf (A θ s)).neg) M (fun z z' => by have := hM (A θ s) z' z; linarith)\n (add_nonneg (hrm0 (q θ)) ham0)) ?_\n exact hkey1 θ\n have hsub : Om1ᶜ ⊆ ⋃ θ : ℕ+, {p : (Fin n → Z) × (Fin m → Z) |\n (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am\n ≤ (∫ z, φ (A θ p.1) z ∂D)} := by\n intro p hp\n have hp' : ¬ (∀ θ : ℕ+, (∫ z, φ (A θ p.1) z ∂D)\n ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) + am) := hp\n push_neg at hp'\n obtain ⟨θ, hθ⟩ := hp'\n exact Set.mem_iUnion.2 ⟨θ, le_of_lt hθ⟩\n have hfinal : ν Om1ᶜ ≤ ENNReal.ofReal (δ / 4) := by\n refine le_trans (measure_mono hsub) ?_\n refine le_trans (measure_iUnion_le _) ?_\n refine le_trans (ENNReal.tsum_le_tsum hEbound) ?_\n rw [← ENNReal.ofReal_tsum_of_nonneg (fun θ => by have := hq_pos θ; positivity)\n (hq_summable.mul_right _)]\n refine ENNReal.ofReal_le_ofReal ?_\n rw [tsum_mul_right]\n have hh : (∑' θ : ℕ+, q θ) * (δ / 4) ≤ 1 * (δ / 4) :=\n mul_le_mul_of_nonneg_right hq_sum (by linarith)\n linarith\n have hcv := ENNReal.toReal_mono (by simp) hfinal\n rwa [ENNReal.toReal_ofReal (by linarith)] at hcv\n have hP2 : ∀ θ : ℕ+, ν.real (Om2 θ)ᶜ ≤ δ / 4 := by\n intro θ\n rcases eq_or_lt_of_le hM0 with hM00 | hMpos\n · -- degenerate case `M = 0`: the event holds everywhere\n have h0 : M = 0 := hM00.symm\n have hemp : (Om2 θ)ᶜ = (∅ : Set ((Fin n → Z) × (Fin m → Z))) := by\n rw [Set.eq_empty_iff_forall_notMem]\n intro p hp\n have hp' : ¬ ((m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i)\n ≤ (∫ z, φ (A θ p.1) z ∂D) + am) := hp\n push_neg at hp'\n rw [hconstInt h0 (A θ p.1) (p.2 ⟨0, hm⟩),\n hconstAvg h0 m hm (A θ p.1) p.2 (p.2 ⟨0, hm⟩)] at hp'\n have e2 : am = 0 := by rw [hamdef, h0]; ring\n rw [e2] at hp'\n linarith\n rw [hemp, measureReal_empty]\n linarith\n · -- main case\n have hms : MeasurableSet {p : (Fin n → Z) × (Fin m → Z) |\n (∫ z, φ (A θ p.1) z ∂D) + am ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i)} :=\n measurableSet_le ((hmeas_pop θ).add measurable_const) (hmeas_em θ)\n have hsub : (Om2 θ)ᶜ ⊆ {p : (Fin n → Z) × (Fin m → Z) |\n (∫ z, φ (A θ p.1) z ∂D) + am ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i)} := by\n intro p hp\n have hp' : ¬ ((m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i)\n ≤ (∫ z, φ (A θ p.1) z ∂D) + am) := hp\n push_neg at hp'\n exact le_of_lt hp'\n refine le_trans (measureReal_mono hsub (measure_ne_top _ _)) ?_\n rw [hνdef]\n refine Ch8Aux.prod_real_le _ _ hms (by linarith) (fun s => ?_)\n have hsec : (Prod.mk s ⁻¹' {p : (Fin n → Z) × (Fin m → Z) |\n (∫ z, φ (A θ p.1) z ∂D) + am ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i)})\n = {v : Fin m → Z |\n (∫ z, φ (A θ s) z ∂D) + am ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ s) (v i)} := rfl\n rw [hsec]\n refine le_trans (Ch8Aux.hoeffding_pi D hm (fun z => φ (A θ s) z) (hφf (A θ s)) M\n (fun z z' => hM (A θ s) z z') ham0) ?_\n rw [hamexp hMpos, hexpL]\n have hP3 : ∀ θ : ℕ+, ν.real (Om3 θ)ᶜ ≤ δ / 4 := by\n intro θ\n rcases eq_or_lt_of_le hM0 with hM00 | hMpos\n · have h0 : M = 0 := hM00.symm\n have hemp : (Om3 θ)ᶜ = (∅ : Set ((Fin n → Z) × (Fin m → Z))) := by\n rw [Set.eq_empty_iff_forall_notMem]\n intro p hp\n have hp' : ¬ ((∫ z, φ (A θ p.1) z ∂D) - (n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ 2 * radCx n φ (F θ) D + an) := hp\n push_neg at hp'\n rw [hconstInt h0 (A θ p.1) (p.1 ⟨0, hn⟩),\n hconstAvg h0 n hn (A θ p.1) p.1 (p.1 ⟨0, hn⟩)] at hp'\n have e2 : an = 0 := by rw [handef, h0]; ring\n have e3 := hradnn θ\n rw [e2] at hp'\n linarith\n rw [hemp, measureReal_empty]\n linarith\n · have hsub : (Om3 θ)ᶜ ⊆ {p : (Fin n → Z) × (Fin m → Z) | p.1 ∈\n {s : Fin n → Z | 2 * radCx n φ (F θ) D + an\n ≤ (∫ z, φ (A θ s) z ∂D) - (n : ℝ)⁻¹ * ∑ k, φ (A θ s) (s k)}} := by\n intro p hp\n have hp' : ¬ ((∫ z, φ (A θ p.1) z ∂D) - (n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ 2 * radCx n φ (F θ) D + an) := hp\n push_neg at hp'\n exact le_of_lt hp'\n refine le_trans (measureReal_mono hsub (measure_ne_top _ _)) ?_\n rw [hνdef, Ch8Aux.prod_real_fst]\n refine le_trans (Ch8Aux.crux D φ hφ_meas M hM hint hn (F θ) (hBddAbove θ)\n (hRadInt θ) (A θ) (hA_meas θ) (hA_mem θ) han0) ?_\n rw [hanexp hMpos, hexpL]\n have hP4 : ∀ θ : ℕ+, ν.real (Om4 θ)ᶜ ≤ δ / 4 := by\n intro θ\n haveI : Nonempty (F θ) := (hFne θ).to_subtype\n rcases eq_or_lt_of_le hM0 with hM00 | hMpos\n · have h0 : M = 0 := hM00.symm\n have hemp : (Om4 θ)ᶜ = (∅ : Set ((Fin n → Z) × (Fin m → Z))) := by\n rw [Set.eq_empty_iff_forall_notMem]\n intro p hp\n have hp' : ¬ ((n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an) := hp\n push_neg at hp'\n have heq : (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D)\n = (⨅ f : F θ, (n : ℝ)⁻¹ * ∑ i, φ (f : Pred) (p.1 i)) := by\n refine iInf_congr (fun f => ?_)\n rw [hconstInt h0 (f : Pred) (p.1 ⟨0, hn⟩),\n hconstAvg h0 n hn (f : Pred) p.1 (p.1 ⟨0, hn⟩)]\n have e2 : an = 0 := by rw [handef, h0]; ring\n have h3 := hERM θ p.1\n rw [heq, e2] at hp'\n linarith\n rw [hemp, measureReal_empty]\n linarith\n · set Om4j : ℕ → Set ((Fin n → Z) × (Fin m → Z)) := fun j =>\n {p | (n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an + 1 / ((j : ℝ) + 1)} with hOm4jdef\n have hjbound : ∀ j : ℕ, ν ((Om4j j)ᶜ) ≤ ENNReal.ofReal (δ / 4) := by\n intro j\n have hpos : (0:ℝ) < 1 / ((j : ℝ) + 1) := by positivity\n obtain ⟨g, hg⟩ := exists_lt_of_ciInf_lt (f := fun f : F θ => ∫ z, φ (f : Pred) z ∂D)\n (a := (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + 1 / ((j : ℝ) + 1)) (by linarith)\n have hsub : (Om4j j)ᶜ ⊆ {p : (Fin n → Z) × (Fin m → Z) | p.1 ∈\n {s : Fin n → Z | (∫ z, φ (g : Pred) z ∂D) + an\n ≤ (n : ℝ)⁻¹ * ∑ i, φ (g : Pred) (s i)}} := by\n intro p hp\n have hp' : ¬ ((n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an + 1 / ((j : ℝ) + 1)) := hp\n push_neg at hp'\n have h1 := hERM θ p.1\n have h2 : (⨅ f : F θ, (n : ℝ)⁻¹ * ∑ i, φ (f : Pred) (p.1 i))\n ≤ (n : ℝ)⁻¹ * ∑ i, φ (g : Pred) (p.1 i) := ciInf_le (hbddEmp θ p.1) g\n show (∫ z, φ (g : Pred) z ∂D) + an ≤ (n : ℝ)⁻¹ * ∑ i, φ (g : Pred) (p.1 i)\n linarith\n refine le_trans (measure_mono hsub) ?_\n refine (ENNReal.le_ofReal_iff_toReal_le (measure_ne_top _ _) (by linarith)).2 ?_\n show ν.real {p : (Fin n → Z) × (Fin m → Z) | p.1 ∈\n {s : Fin n → Z | (∫ z, φ (g : Pred) z ∂D) + an\n ≤ (n : ℝ)⁻¹ * ∑ i, φ (g : Pred) (s i)}} ≤ δ / 4\n rw [hνdef, Ch8Aux.prod_real_fst]\n refine le_trans (Ch8Aux.hoeffding_pi D hn (fun z => φ (g : Pred) z) (hφf (g : Pred)) M\n (fun z z' => hM (g : Pred) z z') han0) ?_\n rw [hanexp hMpos, hexpL]\n have hmono : Monotone (fun j : ℕ => (Om4j j)ᶜ) := by\n intro i j hij p hp\n have hp' : ¬ ((n : ℝ)⁻¹ * ∑ k, φ (A θ p.1) (p.1 k)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an + 1 / ((i : ℝ) + 1)) := hp\n push_neg at hp'\n have hle : (1:ℝ) / ((j : ℝ) + 1) ≤ 1 / ((i : ℝ) + 1) := by\n refine one_div_le_one_div_of_le (by positivity) ?_\n have : (i : ℝ) ≤ (j : ℝ) := by exact_mod_cast hij\n linarith\n show ¬ ((n : ℝ)⁻¹ * ∑ k, φ (A θ p.1) (p.1 k)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an + 1 / ((j : ℝ) + 1))\n push_neg\n linarith\n have hunion : (Om4 θ)ᶜ = ⋃ j : ℕ, (Om4j j)ᶜ := by\n ext p\n constructor\n · intro hp\n have hp' : ¬ ((n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an) := hp\n push_neg at hp'\n obtain ⟨j, hj⟩ := exists_nat_one_div_lt (sub_pos.2 hp')\n refine Set.mem_iUnion.2 ⟨j, ?_⟩\n show ¬ ((n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an + 1 / ((j : ℝ) + 1))\n push_neg\n linarith\n · intro hp\n obtain ⟨j, hj⟩ := Set.mem_iUnion.1 hp\n have hj' : ¬ ((n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an + 1 / ((j : ℝ) + 1)) := hj\n push_neg at hj'\n have hpos : (0:ℝ) < 1 / ((j : ℝ) + 1) := by positivity\n show ¬ ((n : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.1 i)\n ≤ (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + ε' + an)\n push_neg\n linarith\n have hfinal : ν ((Om4 θ)ᶜ) ≤ ENNReal.ofReal (δ / 4) := by\n rw [hunion, hmono.measure_iUnion]\n exact iSup_le hjbound\n have hcv := ENNReal.toReal_mono (by simp) hfinal\n rwa [ENNReal.toReal_ofReal (by linarith)] at hcv\n -- the intersection of the four good events has probability at least 1 - δ\n have hG : ∀ θ : ℕ+, 1 - δ ≤ ν.real (Om1 ∩ Om2 θ ∩ Om3 θ ∩ Om4 θ) := by\n intro θ\n have hmeasG : MeasurableSet (Om1 ∩ Om2 θ ∩ Om3 θ ∩ Om4 θ) :=\n ((hmeasOm1.inter (hmeasOm2 θ)).inter (hmeasOm3 θ)).inter (hmeasOm4 θ)\n have hcompl : (Om1 ∩ Om2 θ ∩ Om3 θ ∩ Om4 θ)ᶜ\n = ((Om1ᶜ ∪ (Om2 θ)ᶜ) ∪ (Om3 θ)ᶜ) ∪ (Om4 θ)ᶜ := by\n simp [Set.compl_inter]\n have hle : ν.real (Om1 ∩ Om2 θ ∩ Om3 θ ∩ Om4 θ)ᶜ ≤ δ := by\n rw [hcompl]\n have b1 := measureReal_union_le (μ := ν) ((Om1ᶜ ∪ (Om2 θ)ᶜ) ∪ (Om3 θ)ᶜ) (Om4 θ)ᶜ\n have b2 := measureReal_union_le (μ := ν) (Om1ᶜ ∪ (Om2 θ)ᶜ) (Om3 θ)ᶜ\n have b3 := measureReal_union_le (μ := ν) Om1ᶜ (Om2 θ)ᶜ\n have := hP2 θ; have := hP3 θ; have := hP4 θ\n linarith\n have hcc := measureReal_compl (μ := ν) hmeasG\n rw [probReal_univ] at hcc\n linarith\n -- the limiting good event\n set Wj : ℕ → Set ((Fin n → Z) × (Fin m → Z)) := fun j =>\n Om1 ∩ {p | Yf p ≤ cstar + 1 / (j + 1)} with hWjdef\n set W : Set ((Fin n → Z) × (Fin m → Z)) := Om1 ∩ {p | Yf p ≤ cstar} with hWdef\n have hmeasWj : ∀ j, MeasurableSet (Wj j) := by\n intro j\n exact hmeasOm1.inter (measurableSet_le hmeasY measurable_const)\n have hmeasW : MeasurableSet W :=\n hmeasOm1.inter (measurableSet_le hmeasY measurable_const)\n have hWinter : W = ⋂ j : ℕ, Wj j := by\n ext p\n simp only [hWdef, hWjdef, Set.mem_inter_iff, Set.mem_iInter, Set.mem_setOf_eq]\n constructor\n · rintro ⟨h1, h2⟩ j\n refine ⟨h1, ?_⟩\n have : (0:ℝ) < (j:ℝ) + 1 := by positivity\n have : (0:ℝ) ≤ 1 / ((j:ℝ) + 1) := by positivity\n linarith\n · intro h\n refine ⟨(h 0).1, ?_⟩\n by_contra hc\n push_neg at hc\n obtain ⟨j, hj⟩ := exists_nat_one_div_lt (sub_pos.2 hc)\n have := (h j).2\n simp only [one_div] at hj this\n linarith\n have hanti : Antitone Wj := by\n intro i j hij p hp\n refine ⟨hp.1, ?_⟩\n have h1 : (1:ℝ) / ((j:ℝ) + 1) ≤ 1 / ((i:ℝ) + 1) := by\n apply one_div_le_one_div_of_le\n · positivity\n · have : (i:ℝ) ≤ (j:ℝ) := by exact_mod_cast hij\n linarith\n have := hp.2\n simp only [Set.mem_setOf_eq] at this ⊢\n linarith\n have hWjprob : ∀ j : ℕ, 1 - δ ≤ ν.real (Wj j) := by\n intro j\n have hpos : (0:ℝ) < 1 / ((j:ℝ) + 1) := by positivity\n obtain ⟨θ, hθ⟩ := exists_lt_of_ciInf_lt (f := fun θ : ℕ+ =>\n (⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D) + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ))\n (a := (⨅ θ : ℕ+, ((⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D)\n + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ))) + 1 / ((j:ℝ) + 1)) (by linarith)\n refine le_trans (hG θ) ?_\n apply measureReal_mono _ (measure_ne_top _ _)\n rintro p ⟨⟨⟨hp1, hp2⟩, hp3⟩, hp4⟩\n refine ⟨hp1, ?_⟩\n simp only [Set.mem_setOf_eq]\n have hy : Yf p ≤ (m : ℝ)⁻¹ * ∑ i, φ (A θ p.1) (p.2 i) + rmPenalty M m (q θ) := by\n rw [hYfdef]\n exact ciInf_le (hbddSel p.1 p.2) θ\n simp only [hOm2def, Set.mem_setOf_eq] at hp2\n simp only [hOm3def, Set.mem_setOf_eq] at hp3\n simp only [hOm4def, Set.mem_setOf_eq] at hp4\n rw [hcstardef]\n linarith\n have hWprob : 1 - δ ≤ ν.real W := by\n have hlim : Filter.Tendsto (fun j : ℕ => ν (Wj j)) Filter.atTop\n (nhds (ν (⋂ j : ℕ, Wj j))) :=\n tendsto_measure_iInter_atTop (fun j => (hmeasWj j).nullMeasurableSet) hanti\n ⟨0, measure_ne_top _ _⟩\n have hlow : ENNReal.ofReal (1 - δ) ≤ ν (⋂ j : ℕ, Wj j) := by\n refine ge_of_tendsto hlim (Filter.Eventually.of_forall fun j => ?_)\n rw [← ENNReal.ofReal_toReal (measure_ne_top ν (Wj j))]\n exact ENNReal.ofReal_le_ofReal (hWjprob j)\n rw [← hWinter] at hlow\n exact (ENNReal.ofReal_le_iff_le_toReal (measure_ne_top ν W)).1 hlow\n -- transfer to the original probability space\n have hsq : ∀ (x r : ℝ), 0 < r →\n 2 * (M * Real.sqrt (x / (2 * r))) = M * Real.sqrt (2 * x / r) := by\n intro x r hr\n rw [show (2 * x / r) = 4 * (x / (2 * r)) by field_simp; ring]\n rw [Real.sqrt_mul (by norm_num : (0:ℝ) ≤ 4)]\n rw [show Real.sqrt 4 = 2 by\n rw [show (4:ℝ) = 2 ^ 2 by norm_num, Real.sqrt_sq (by norm_num : (0:ℝ) ≤ 2)]]\n ring\n have hRHSeq : (⨅ θ : ℕ+, ((⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D)\n + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ))) + εt + ε'\n + M * Real.sqrt (2 * L / n) + M * Real.sqrt (2 * L / m)\n = cstar + εt + am := by\n rw [hcstardef, ← hsq L (n:ℝ) hnR, ← hsq L (m:ℝ) hmR, ← handef, ← hamdef]\n ring\n have hsub : (fun ω => (Strain ω, Sval ω)) ⁻¹' W ⊆\n {ω : Ωs | ∫ z, φ (A (thetaHat (Strain ω) (Sval ω)) (Strain ω)) z ∂D\n ≤ (⨅ θ : ℕ+, ((⨅ f : F θ, ∫ z, φ (f : Pred) z ∂D)\n + 2 * radCx n φ (F θ) D + rmPenalty M m (q θ))) + εt + ε'\n + M * Real.sqrt (2 * L / n) + M * Real.sqrt (2 * L / m)} := by\n intro ω hω\n obtain ⟨hω1, hω2⟩ := hω\n simp only [Set.mem_setOf_eq]\n rw [hRHSeq]\n have h1 := hω1 (thetaHat (Strain ω) (Sval ω))\n have h2 := hSel (Strain ω) (Sval ω)\n simp only [Set.mem_setOf_eq, hYfdef] at hω2\n simp only at h1 h2\n linarith\n calc 1 - δ ≤ ν.real W := hWprob\n _ = (P ((fun ω => (Strain ω, Sval ω)) ⁻¹' W)).toReal := by\n rw [Measure.real, ← hmapT, Measure.map_apply (by fun_prop) hmeasW]\n _ ≤ _ := by\n apply ENNReal.toReal_mono (measure_ne_top P _)\n exact measure_mono hsub\n\nend GraduateLevel\n"} +{"id": "ch16_theorem_16_7", "source": "Graduate-level", "targets": [{"label": "ch16_theorem_16_7", "decls": ["ch16_theorem_16_7"], "statement": "Assume that the reward \\(r_t(a) \\in [0,1]\\). Let \\(a_* \\in \\arg \\max_a \\mu(a)\\). With a choice of\n\\[\n\\hat{c}_{t}(a)=\\sqrt{\\frac{\\ln(2(\\hat{n}_{t}(a)+1)^{2}/\\delta)}{2\\hat{n}_{t}(a)}},\n\\]\nwe have\n\\[\n\\mathrm{REG}_{T}\\leq\\inf_{\\Delta_{0}>0}\\left[(T-K)\\Delta_{0}+\\sum_{a=1}^{K}\\frac{2\\ln(2 K T^{2}/\\delta)}{\\Delta(a)}\\mathbb{1}(\\Delta(a)>\\Delta_{0})\\right]+\\sum_{a=1}^{K}\\Delta(a).\n\\]", "topic_domain": "Online Learning & RL", "topic_subtopic": "Bandits"}], "nl_proof": "From the proof of Theorem 16.3, we know that with the choice of\n\\[\n\\hat{c}_{t}^{\\prime}(a)=\\sqrt{\\frac{\\ln(2 K(\\hat{n}_{t}(a)+1)^{2}/\\delta)}{2\\hat{n}_{t}(a)}},\n\\]\nthe inequality \\(\\Delta(a) \\leq \\hat{c}_{t-1}(a) + \\hat{c}_{t-1}'(a)\\) in the definition of \\(T(a)\\) implies that\n\\[\n\\Delta(a)\\leq\\sqrt{\\frac{2\\ln(2 K T^{2}/\\delta)}{\\hat{n}_{t-1}(a)}}.\n\\]\nThis implies that\n\\[\n\\hat{n}_{t-1}(a)\\leq\\frac{2\\ln(2 K T^{2}/\\delta)}{\\Delta(a)^{2}}.\n\\]\nTherefore\n\\[\nT(a)\\leq\\frac{2\\ln(2 K T^{2}/\\delta)}{\\Delta(a)^{2}}.\n\\]\nThis implies the desired result from Lemma 16.6.", "context": [{"id": "ch16:theorem:16_3", "name": "theorem 16.3", "statement": "Assume that rewards \\(r_t(a) \\in [0,1]\\). Let \\(a_* \\in \\arg \\max_a \\mu(a)\\). With a choice of\n\\[\n\\hat{c}_{t}(a)=\\sqrt{\\frac{\\ln(2(\\hat{n}_{t}(a)+1)^{2}/\\delta)}{2\\hat{n}_{t}(a)}},\n\\]\nwe have with probability at least \\(1 - \\delta\\):\n\\[\n\\mathrm{REG}_{T}\\leq(K-1)+\\sqrt{8\\ln(2 K T^{2}/\\delta)(T-K)K}.\n\\]"}, {"id": "ch16:lemma:16_6", "name": "lemma 16.6", "statement": "Let \\(a_* \\in \\arg \\max_a \\mu(a)\\). Let\n\\[\n\\delta_{1}=\\Pr\\left[\\exists t>K:\\mu\\left(a_{*}\\right)>\\hat{\\mu}_{t-1}\\left(a_{*}\\right)+\\hat{c}_{t-1}\\left(a_{*}\\right)\\right],\n\\]\n\\[\n\\delta_{2}=\\Pr\\left[\\exists t>K,a\\in\\{1,\\dots,K\\}\\backslash\\{a_{*}\\}:\\mu(a)<\\hat{\\mu}_{t-1}(a)-\\hat{c}_{t-1}^{\\prime}(a)\\right].\n\\]\nDefine \\(\\Delta(a) = \\mu(a_{*}) - \\mu(a)\\), and\n\\[\nT(a)=\\max\\left\\{m:\\Delta(a)\\leq\\hat{c}_{t-1}(a)+\\hat{c}_{t-1}^{\\prime}(a),\\hat{n}_{t-1}(a)=m,K0}\\left[\\sum_{a=1}^{K}T(a)\\Delta(a)\\mathbb{1}(\\Delta(a)>\\Delta_{0})+(T-K)\\Delta_{0}\\right]+\\sum_{a=1}^{K}\\Delta(a).\n\\]"}, {"id": "ch16:definition:16_1", "name": "definition 16.1", "statement": "In the multi-armed bandit (or MAB) problem, we consider \\(K\\) arms. The environment generates a sequence of reward vectors for time steps \\(t \\geq 1\\) as \\(r_t = [r_t(1), \\ldots, r_t(K)]\\). Each \\(r_t(a)\\) is associated with an arm \\(a \\in \\{1, \\ldots, K\\}\\). In the literature, an arm \\(a\\) is also referred to as an action. At each time step \\(t = 1, 2, \\ldots, T\\),\n- The player pulls one of the arms \\( a_{t} \\in \\{1, \\dots, K\\} \\).\n- The environment returns the reward \\( r_t(a_t) \\), but does not reveal information on any other arm \\( a \\neq a_t \\).\nAt each time \\( t \\), a (randomized) bandit algorithm takes the historic observations observed so far, and maps it to a distribution \\( \\hat{\\pi}_{t-1} \\) over actions \\( a \\in \\{1, \\ldots, K\\} \\). We then draw a random action \\( a_t \\) (arm) from \\( \\hat{\\pi}_{t-1} \\). Here \\( \\hat{\\pi}_{t-1} \\) is referred to as policy.\nIn the adversarial bandit problem, we are given an arbitrary reward sequence \\(\\{[r_1(1),\\ldots,r_t(K)]:t\\geq 1\\}\\) before hand. The adversary in this setting is called oblivious, who decides the rewards of all the rounds before the game starts (but may take advantage of the bandit algorithm's weakness). For this reward se\nquence, the expected cumulative reward of a randomized bandit algorithm is\n\\[\n\\mathbb{E}\\sum_{t=1}^{T}r_{t}(a_{t}),\n\\]\nwhere the randomization is over the internal randomization of the bandit algorithm. The expected regret is defined as\n\\[\n\\operatorname{REG}_{T}=\\max_{a}\\sum_{t=1}^{T}r_{t}(a)-\\mathbb{E}\\sum_{t=1}^{T}r_{t}\\left(a_{t}\\right).\\tag{16.1}\n\\]\nIf the bandit algorithm is deterministic: i.e. pulling a single arm \\(a_{t}\\) only at any time step, then the regret is\n\\[\n\\mathrm{REG}_{T}=\\max_{a}\\sum_{t=1}^{T}r_{t}(a)-\\sum_{t=1}^{T}r_{t}(a_{t}).\n\\]\nIn the adversarial bandit problem, our goal is to minimize the expected regret \\(\\mathrm{REG}_T\\) (and the expectation is with respect to the internal randomization of the algorithm instead of the data).\nAnother form of bandit problem, called stochastic bandit, assumes that the reward \\( r_t(a) \\) is drawn independently from a distribution \\( \\mathcal{D}_a \\), with mean \\( \\mu(a) = \\mathbb{E}_{r_t(a) \\sim \\mathcal{D}_a} [r_t(a)] \\). In this setting, the goal of bandit is to find \\( a \\) that maximizes the expected reward \\( \\mu(a) \\). We are interested in the expected regret defined as:\n\\[\n\\operatorname{REG}_{T}=T\\max_{a}\\mu(a)-\\mathbb{E}\\sum_{t=1}^{T}\\mu\\left(a_{t}\\right).\\tag{16.2}\n\\]\nAgain, this regret is defined for each realization of the stochastic rewards, and the expectation is with respect to the randomness of the algorithm. If algorithm is deterministic and outputs \\( a_{t} \\) at each time \\( t \\), then\n\\[\n\\mathrm{REG}_{T}=T\\max_{a}\\mu(a)-\\sum_{t=1}^{T}\\mu(a_{t}).\n\\]\nWe can further include randomization over data into the regret of stochastic bandit, by considering expected regret as follows:\n\\[\n\\mathbb{E}\\operatorname{REG}_{T}=T\\max_{a}\\mu(a)-\\mathbb{E}\\sum_{t=1}^{T}\\mu(a_{t}),\n\\]\nwhere the expectation is with respect to both the data and the internal randomization of the learning algorithm."}, {"id": "ch16:algorithm:16_1", "name": "UCB Algorithm", "statement": "Algorithm 16.1: UCB Algorithm\nInput: \\(K\\) and \\(T\\geq K\\) \n1 for \\(a=1,\\dots,K\\) do \n2 Let \\(\\hat{n}_0(a) = 0\\) \n3 Let \\(\\hat{\\mu}_0(a) = 0\\) \n4 for \\(t=1,2,\\ldots,T\\) do \n5 if \\(t\\leq K\\) then \n6 Let \\(a_{t} = t\\) \n7 else \n8 Let \\(a_{t}\\in \\arg \\max_{a}[\\hat{\\mu}_{t - 1}(a) + \\hat{c}_{t - 1}(a)]\\) according to (16.3) \n9 Pull arm \\(a_{t}\\) and observe reward \\(r_t(a_t)\\)"}, {"id": "ch16:equation:16_3", "name": "equation 16.3", "statement": "For each arm \\(a\\), define the number of pulls up to time \\(t\\) and the corresponding empirical mean by\n\\[\n\\hat n_t(a)=\\sum_{s=1}^{t}\\mathbb{1}(a_s=a), \\qquad\n\\hat\\mu_t(a)=\\frac{1}{\\hat n_t(a)}\\sum_{s=1}^{t} r_s(a_s)\\mathbb{1}(a_s=a),\n\\]\nwith the initialization \\(\\hat n_0(a)=0\\) and \\(\\hat\\mu_0(a)=0\\). In the UCB algorithm, after the initialization rounds, the arm is selected according to\n\\[\na_t\\in\\arg\\max_a\\left[\\hat\\mu_{t-1}(a)+\\hat c_{t-1}(a)\\right]. \\tag{16.3}\n\\]\nHere \\(\\hat c_t(a)\\) denotes the confidence width used by the algorithm."}], "lean": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Finset\n\nnamespace GraduateLevel\n\nlemma measurable_encode {α : Type*} {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n Measurable (Encodable.encode (α := α)) := by\n refine measurable_to_nat fun a ↦ ?_\n have : Encodable.encode ⁻¹' {Encodable.encode a} = {a} := by ext; simp\n rw [this]\n exact measurableSet_singleton _\n\nlemma measurableEmbedding_encode (α : Type*) {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n MeasurableEmbedding (Encodable.encode (α := α)) where\n injective := Encodable.encode_injective\n measurable := measurable_encode\n measurableSet_image' _ _ := .of_discrete\n\nsection Finite\n\nvariable {𝓧 𝓨 α : Type*} {m𝓧 : MeasurableSpace 𝓧} {m𝓨 : MeasurableSpace 𝓨}\n {mα : MeasurableSpace α} [TopologicalSpace α] [LinearOrder α]\n [OpensMeasurableSpace α] [OrderClosedTopology α] [SecondCountableTopology α]\n\nlemma measurableSet_isMax [Countable 𝓨]\n {f : 𝓧 → 𝓨 → α} (hf : ∀ y, Measurable (fun x ↦ f x y)) (y : 𝓨) :\n MeasurableSet {x | ∀ z, f x z ≤ f x y} := by\n rw [show {x | ∀ y', f x y' ≤ f x y} = ⋂ y', {x | f x y' ≤ f x y} by ext; simp]\n exact MeasurableSet.iInter fun z ↦ measurableSet_le (by fun_prop) (by fun_prop)\n\nlemma exists_isMaxOn' {α : Type*} [LinearOrder α]\n [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] (f : 𝓧 → 𝓨 → α) (x : 𝓧) :\n ∃ n : ℕ, ∃ y, n = Encodable.encode y ∧ ∀ z, f x z ≤ f x y := by\n obtain ⟨y, h⟩ := Finite.exists_max (f x)\n exact ⟨Encodable.encode y, y, rfl, h⟩\n\nnoncomputable\ndef measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] [MeasurableSingletonClass 𝓨]\n (f : 𝓧 → 𝓨 → α)\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (x : 𝓧) :\n 𝓨 :=\n (measurableEmbedding_encode 𝓨).invFun (Nat.find (exists_isMaxOn' f x))\n\nlemma measurable_measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨]\n [MeasurableSingletonClass 𝓨]\n {f : 𝓧 → 𝓨 → α}\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (hf : ∀ y, Measurable (fun x ↦ f x y)) :\n Measurable (measurableArgmax f) := by\n refine (MeasurableEmbedding.measurable_invFun (measurableEmbedding_encode 𝓨)).comp ?_\n refine measurable_find _ fun n ↦ ?_\n have : {x | ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y}\n = ⋃ y, ({x | n = Encodable.encode y} ∩ {x | ∀ z, f x z ≤ f x y}) := by ext; simp\n rw [this]\n refine MeasurableSet.iUnion fun y ↦ (MeasurableSet.inter (by simp) ?_)\n exact measurableSet_isMax (by fun_prop) y\n\nend Finite\n\nvariable {𝓐 𝓨 : Type*} [MeasurableSpace 𝓐] [MeasurableSpace 𝓨]\n\nstructure Algorithm (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n policy : (n : ℕ) → Kernel (Iic n → 𝓐 × 𝓨) 𝓐\n [h_policy : ∀ n, IsMarkovKernel (policy n)]\n p0 : Measure 𝓐\n [hp0 : IsProbabilityMeasure p0]\n\nattribute [instance] Algorithm.h_policy Algorithm.hp0\n\nstructure Environment (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n feedback : (n : ℕ) → Kernel ((Iic n → 𝓐 × 𝓨) × 𝓐) 𝓨\n [h_feedback : ∀ n, IsMarkovKernel (feedback n)]\n ν0 : Kernel 𝓐 𝓨\n [hp0 : IsMarkovKernel ν0]\n\nattribute [instance] Environment.h_feedback Environment.hp0\n\nnoncomputable\ndef stepKernel (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n Kernel (Iic n → 𝓐 × 𝓨) (𝓐 × 𝓨) :=\n alg.policy n ⊗ₖ env.feedback n\n\ninstance (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n IsMarkovKernel (stepKernel alg env n) := by\n rw [stepKernel]; infer_instance\n\nnoncomputable\ndef trajMeasure (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) :\n Measure (ℕ → 𝓐 × 𝓨) :=\n Kernel.trajMeasure (alg.p0 ⊗ₘ env.ν0) (stepKernel alg env)\n\nnoncomputable\ndef gap {𝓐 : Type*} [MeasurableSpace 𝓐] (ν : Kernel 𝓐 ℝ) (a : 𝓐) : ℝ :=\n (⨆ i, (ν i)[id]) - (ν a)[id]\n\nnoncomputable\ndef regret {𝓐 Ω : Type*} [MeasurableSpace 𝓐] (ν : Kernel 𝓐 ℝ) (A : ℕ → Ω → 𝓐) (t : ℕ) (ω : Ω) : ℝ :=\n t * (⨆ a, (ν a)[id]) - ∑ s ∈ range t, (ν (A s ω))[id]\n\nsection History\n\nvariable {𝓐 R : Type*} [DecidableEq 𝓐] {n : ℕ}\n\nnoncomputable def pullCount' (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) : ℕ :=\n #(univ.filter (fun s ↦ (h s).1 = a))\n\nlemma pullCount'_eq_sum (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) :\n pullCount' n h a = ∑ s : Iic n, if (h s).1 = a then 1 else 0 := by\n rw [pullCount', Finset.card_filter]\n\nnoncomputable def sumRewards' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n ∑ s, if (h s).1 = a then (h s).2 else 0\n\nnoncomputable def empMean' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n sumRewards' n h a / pullCount' n h a\n\nvariable [MeasurableSpace 𝓐] [MeasurableSingletonClass 𝓐] [MeasurableSpace R]\n\n@[fun_prop]\nlemma measurable_pullCount' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × R ↦ pullCount' n h a) := by\n simp_rw [pullCount'_eq_sum]\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × R) ↦ if (h s).1 = a then 1 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_sumRewards' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ sumRewards' n h a) := by\n simp_rw [sumRewards']\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × ℝ) ↦ if (h s).1 = a then (h s).2 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_empMean' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ empMean' n h a) := by\n unfold empMean'; fun_prop\n\nend History\n\ndef RoundRobin.nextAction {K : ℕ} (hK : 0 < K) (n : ℕ) : Fin K := ⟨(n + 1) % K, Nat.mod_lt _ hK⟩\n\nnoncomputable def detAlgorithm (nextA : (n : ℕ) → (Iic n → 𝓐 × 𝓨) → 𝓐)\n (h_next : ∀ n, Measurable (nextA n)) (action0 : 𝓐) : Algorithm 𝓐 𝓨 where\n policy n := Kernel.deterministic (nextA n) (h_next n)\n p0 := Measure.dirac action0\n\nnoncomputable def stationaryEnv (ν : Kernel 𝓐 𝓨) [IsMarkovKernel ν] : Environment 𝓐 𝓨 where\n feedback _ := ν.comap Prod.snd measurable_snd\n ν0 := ν\n\nnoncomputable def cHat {K : ℕ} (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) (a : Fin K) : ℝ :=\n Real.sqrt (Real.log (2 * (pullCount' n h a + 1) ^ 2 / δ) / (2 * pullCount' n h a))\n\n@[fun_prop]\nlemma measurable_cHat {K : ℕ} (δ : ℝ) (n : ℕ) (a : Fin K) :\n Measurable (fun h : Iic n → Fin K × ℝ ↦ cHat δ n h a) := by\n unfold cHat; fun_prop\n\nopen Classical in\n\nnoncomputable def nlNextArm {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) : Fin K :=\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n if n < K - 1 then RoundRobin.nextAction hK n else\n measurableArgmax (fun h a ↦ empMean' n h a + cHat δ n h a) h\n\nopen Classical in\n@[fun_prop]\nlemma measurable_nlNextArm {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) :\n Measurable (nlNextArm hK δ n) := by\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n unfold nlNextArm\n split_ifs with hc\n · exact measurable_const\n · refine measurable_measurableArgmax fun a ↦ ?_\n fun_prop\n\nnoncomputable def nlAlgo {K : ℕ} (hK : 0 < K) (δ : ℝ) : Algorithm (Fin K) ℝ :=\n detAlgorithm (nlNextArm hK δ) (measurable_nlNextArm hK δ) ⟨0, hK⟩\n\ntheorem ch16_theorem_16_7 {K : ℕ} (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (T : ℕ) (hKT : K ≤ T) (hT : 0 < T) (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1)\n (hrewards : ∀ a, ∀ᵐ x ∂(ν a), x ∈ Set.Icc (0 : ℝ) 1)\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K)\n (hmeasA : ∀ n, Measurable (nextA n))\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + cHat δ n h a ≤ empMean' n h (nextA n h) + cHat δ n h (nextA n h)) :\n (trajMeasure (detAlgorithm nextA hmeasA ⟨0, hK⟩) (stationaryEnv ν))\n {ω : ℕ → Fin K × ℝ |\n regret ν (fun s ω => (ω s).1) T ω ≤\n (⨅ Δ₀ : {x : ℝ // 0 < x},\n ((T : ℝ) - K) * (Δ₀ : ℝ) +\n ∑ a : Fin K,\n Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' => 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') a) +\n ∑ a : Fin K, gap ν a}\n ≥ ENNReal.ofReal (1 - δ) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory ProbabilityTheory Real Finset\n\nnamespace GraduateLevel\n\nlemma measurable_encode {α : Type*} {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n Measurable (Encodable.encode (α := α)) := by\n refine measurable_to_nat fun a ↦ ?_\n have : Encodable.encode ⁻¹' {Encodable.encode a} = {a} := by ext; simp\n rw [this]\n exact measurableSet_singleton _\n\nlemma measurableEmbedding_encode (α : Type*) {_ : MeasurableSpace α} [Encodable α]\n [MeasurableSingletonClass α] :\n MeasurableEmbedding (Encodable.encode (α := α)) where\n injective := Encodable.encode_injective\n measurable := measurable_encode\n measurableSet_image' _ _ := .of_discrete\n\nsection Finite\n\nvariable {𝓧 𝓨 α : Type*} {m𝓧 : MeasurableSpace 𝓧} {m𝓨 : MeasurableSpace 𝓨}\n {mα : MeasurableSpace α} [TopologicalSpace α] [LinearOrder α]\n [OpensMeasurableSpace α] [OrderClosedTopology α] [SecondCountableTopology α]\n\nlemma measurableSet_isMax [Countable 𝓨]\n {f : 𝓧 → 𝓨 → α} (hf : ∀ y, Measurable (fun x ↦ f x y)) (y : 𝓨) :\n MeasurableSet {x | ∀ z, f x z ≤ f x y} := by\n rw [show {x | ∀ y', f x y' ≤ f x y} = ⋂ y', {x | f x y' ≤ f x y} by ext; simp]\n exact MeasurableSet.iInter fun z ↦ measurableSet_le (by fun_prop) (by fun_prop)\n\nlemma exists_isMaxOn' {α : Type*} [LinearOrder α]\n [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] (f : 𝓧 → 𝓨 → α) (x : 𝓧) :\n ∃ n : ℕ, ∃ y, n = Encodable.encode y ∧ ∀ z, f x z ≤ f x y := by\n obtain ⟨y, h⟩ := Finite.exists_max (f x)\n exact ⟨Encodable.encode y, y, rfl, h⟩\n\nnoncomputable\ndef measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨] [MeasurableSingletonClass 𝓨]\n (f : 𝓧 → 𝓨 → α)\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (x : 𝓧) :\n 𝓨 :=\n (measurableEmbedding_encode 𝓨).invFun (Nat.find (exists_isMaxOn' f x))\n\nlemma measurable_measurableArgmax [Nonempty 𝓨] [Finite 𝓨] [Encodable 𝓨]\n [MeasurableSingletonClass 𝓨]\n {f : 𝓧 → 𝓨 → α}\n [∀ x, DecidablePred fun n ↦ ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y]\n (hf : ∀ y, Measurable (fun x ↦ f x y)) :\n Measurable (measurableArgmax f) := by\n refine (MeasurableEmbedding.measurable_invFun (measurableEmbedding_encode 𝓨)).comp ?_\n refine measurable_find _ fun n ↦ ?_\n have : {x | ∃ y, n = Encodable.encode y ∧ ∀ (z : 𝓨), f x z ≤ f x y}\n = ⋃ y, ({x | n = Encodable.encode y} ∩ {x | ∀ z, f x z ≤ f x y}) := by ext; simp\n rw [this]\n refine MeasurableSet.iUnion fun y ↦ (MeasurableSet.inter (by simp) ?_)\n exact measurableSet_isMax (by fun_prop) y\n\nend Finite\n\nvariable {𝓐 𝓨 : Type*} [MeasurableSpace 𝓐] [MeasurableSpace 𝓨]\n\nstructure Algorithm (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n policy : (n : ℕ) → Kernel (Iic n → 𝓐 × 𝓨) 𝓐\n [h_policy : ∀ n, IsMarkovKernel (policy n)]\n p0 : Measure 𝓐\n [hp0 : IsProbabilityMeasure p0]\n\nattribute [instance] Algorithm.h_policy Algorithm.hp0\n\nstructure Environment (𝓐 𝓨 : Type*) [MeasurableSpace 𝓐] [MeasurableSpace 𝓨] where\n feedback : (n : ℕ) → Kernel ((Iic n → 𝓐 × 𝓨) × 𝓐) 𝓨\n [h_feedback : ∀ n, IsMarkovKernel (feedback n)]\n ν0 : Kernel 𝓐 𝓨\n [hp0 : IsMarkovKernel ν0]\n\nattribute [instance] Environment.h_feedback Environment.hp0\n\nnoncomputable\ndef stepKernel (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n Kernel (Iic n → 𝓐 × 𝓨) (𝓐 × 𝓨) :=\n alg.policy n ⊗ₖ env.feedback n\n\ninstance (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) (n : ℕ) :\n IsMarkovKernel (stepKernel alg env n) := by\n rw [stepKernel]; infer_instance\n\nnoncomputable\ndef trajMeasure (alg : Algorithm 𝓐 𝓨) (env : Environment 𝓐 𝓨) :\n Measure (ℕ → 𝓐 × 𝓨) :=\n Kernel.trajMeasure (alg.p0 ⊗ₘ env.ν0) (stepKernel alg env)\n\nnoncomputable\ndef gap {𝓐 : Type*} [MeasurableSpace 𝓐] (ν : Kernel 𝓐 ℝ) (a : 𝓐) : ℝ :=\n (⨆ i, (ν i)[id]) - (ν a)[id]\n\nnoncomputable\ndef regret {𝓐 Ω : Type*} [MeasurableSpace 𝓐] (ν : Kernel 𝓐 ℝ) (A : ℕ → Ω → 𝓐) (t : ℕ) (ω : Ω) : ℝ :=\n t * (⨆ a, (ν a)[id]) - ∑ s ∈ range t, (ν (A s ω))[id]\n\nsection History\n\nvariable {𝓐 R : Type*} [DecidableEq 𝓐] {n : ℕ}\n\nnoncomputable def pullCount' (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) : ℕ :=\n #(univ.filter (fun s ↦ (h s).1 = a))\n\nlemma pullCount'_eq_sum (n : ℕ) (h : Iic n → 𝓐 × R) (a : 𝓐) :\n pullCount' n h a = ∑ s : Iic n, if (h s).1 = a then 1 else 0 := by\n rw [pullCount', Finset.card_filter]\n\nnoncomputable def sumRewards' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n ∑ s, if (h s).1 = a then (h s).2 else 0\n\nnoncomputable def empMean' (n : ℕ) (h : Iic n → 𝓐 × ℝ) (a : 𝓐) : ℝ :=\n sumRewards' n h a / pullCount' n h a\n\nvariable [MeasurableSpace 𝓐] [MeasurableSingletonClass 𝓐] [MeasurableSpace R]\n\n@[fun_prop]\nlemma measurable_pullCount' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × R ↦ pullCount' n h a) := by\n simp_rw [pullCount'_eq_sum]\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × R) ↦ if (h s).1 = a then 1 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_sumRewards' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ sumRewards' n h a) := by\n simp_rw [sumRewards']\n have h_meas s : Measurable (fun (h : Iic n → 𝓐 × ℝ) ↦ if (h s).1 = a then (h s).2 else 0) := by\n refine Measurable.ite ?_ (by fun_prop) (by fun_prop)\n exact (measurableSet_singleton _).preimage (by fun_prop)\n fun_prop\n\n@[fun_prop]\nlemma measurable_empMean' (n : ℕ) (a : 𝓐) :\n Measurable (fun h : Iic n → 𝓐 × ℝ ↦ empMean' n h a) := by\n unfold empMean'; fun_prop\n\nend History\n\ndef RoundRobin.nextAction {K : ℕ} (hK : 0 < K) (n : ℕ) : Fin K := ⟨(n + 1) % K, Nat.mod_lt _ hK⟩\n\nnoncomputable def detAlgorithm (nextA : (n : ℕ) → (Iic n → 𝓐 × 𝓨) → 𝓐)\n (h_next : ∀ n, Measurable (nextA n)) (action0 : 𝓐) : Algorithm 𝓐 𝓨 where\n policy n := Kernel.deterministic (nextA n) (h_next n)\n p0 := Measure.dirac action0\n\nnoncomputable def stationaryEnv (ν : Kernel 𝓐 𝓨) [IsMarkovKernel ν] : Environment 𝓐 𝓨 where\n feedback _ := ν.comap Prod.snd measurable_snd\n ν0 := ν\n\nnoncomputable def cHat {K : ℕ} (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) (a : Fin K) : ℝ :=\n Real.sqrt (Real.log (2 * (pullCount' n h a + 1) ^ 2 / δ) / (2 * pullCount' n h a))\n\n@[fun_prop]\nlemma measurable_cHat {K : ℕ} (δ : ℝ) (n : ℕ) (a : Fin K) :\n Measurable (fun h : Iic n → Fin K × ℝ ↦ cHat δ n h a) := by\n unfold cHat; fun_prop\n\nopen Classical in\n\nnoncomputable def nlNextArm {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) (h : Iic n → Fin K × ℝ) : Fin K :=\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n if n < K - 1 then RoundRobin.nextAction hK n else\n measurableArgmax (fun h a ↦ empMean' n h a + cHat δ n h a) h\n\nopen Classical in\n@[fun_prop]\nlemma measurable_nlNextArm {K : ℕ} (hK : 0 < K) (δ : ℝ) (n : ℕ) :\n Measurable (nlNextArm hK δ n) := by\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n unfold nlNextArm\n split_ifs with hc\n · exact measurable_const\n · refine measurable_measurableArgmax fun a ↦ ?_\n fun_prop\n\nnoncomputable def nlAlgo {K : ℕ} (hK : 0 < K) (δ : ℝ) : Algorithm (Fin K) ℝ :=\n detAlgorithm (nlNextArm hK δ) (measurable_nlNextArm hK δ) ⟨0, hK⟩\n\n/-! ### Auxiliary results about trajectory measures -/\n\nsection AuxTraj\n\nopen Preorder\nopen scoped ENNReal\n\nvariable {X : ℕ → Type*} [∀ n, MeasurableSpace (X n)]\n {κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))} [∀ n, IsMarkovKernel (κ n)]\n {μ₀ : Measure (X 0)} [IsProbabilityMeasure μ₀]\n\n/-- One-step decomposition of an integral against the trajectory measure. -/\ntheorem lintegral_trajMeasure_step (n : ℕ) (Φ : ((Π i : Iic n, X i) × X (n + 1)) → ℝ≥0∞)\n (hΦ : Measurable Φ) :\n ∫⁻ ω, Φ (frestrictLe n ω, ω (n + 1)) ∂(Kernel.trajMeasure μ₀ κ)\n = ∫⁻ ω, (∫⁻ p, Φ (frestrictLe n ω, p) ∂(κ n (frestrictLe n ω)))\n ∂(Kernel.trajMeasure μ₀ κ) := by\n have hF : Measurable (fun h ↦ ∫⁻ p, Φ (h, p) ∂(κ n h)) :=\n hΦ.lintegral_kernel_prod_right' (κ := κ n)\n have h1 : ∫⁻ ω, Φ (frestrictLe n ω, ω (n + 1)) ∂(Kernel.trajMeasure μ₀ κ)\n = ∫⁻ q, Φ q ∂((Kernel.trajMeasure μ₀ κ).map\n (fun ω ↦ (frestrictLe n ω, ω (n + 1)))) :=\n (lintegral_map hΦ (by fun_prop)).symm\n have h2 : ∫⁻ ω, (∫⁻ p, Φ (frestrictLe n ω, p) ∂(κ n (frestrictLe n ω)))\n ∂(Kernel.trajMeasure μ₀ κ)\n = ∫⁻ h, (∫⁻ p, Φ (h, p) ∂(κ n h)) ∂((Kernel.trajMeasure μ₀ κ).map (frestrictLe n)) :=\n (lintegral_map hF (measurable_frestrictLe n)).symm\n rw [h1, h2, ← Kernel.map_frestrictLe_trajMeasure_compProd_eq_map_trajMeasure,\n Measure.lintegral_compProd hΦ]\n\ntheorem map_zero_trajMeasure :\n (Kernel.trajMeasure μ₀ κ).map (fun ω ↦ ω 0) = μ₀ := by\n have h0 : (fun ω : Π n, X n ↦ ω 0)\n = (fun h : Π i : Iic 0, X i ↦ h ⟨0, by simp⟩) ∘ frestrictLe 0 := rfl\n rw [Kernel.trajMeasure, h0, ← Measure.map_map (by fun_prop) (by fun_prop),\n Measure.map_comp _ _ (by fun_prop), Kernel.traj_map_frestrictLe_of_le (le_refl 0),\n Measure.map_comp _ _ (by fun_prop), Kernel.deterministic_map _ (by fun_prop),\n Measure.deterministic_comp_eq_map, Measure.map_map (by fun_prop) (by fun_prop)]\n exact Measure.map_id\n\ntheorem lintegral_trajMeasure_zero (Ψ : X 0 → ℝ≥0∞) (hΨ : Measurable Ψ) :\n ∫⁻ ω, Ψ (ω 0) ∂(Kernel.trajMeasure μ₀ κ) = ∫⁻ p, Ψ p ∂μ₀ := by\n have h := lintegral_map (μ := Kernel.trajMeasure μ₀ κ) (f := Ψ) (g := fun ω ↦ ω 0)\n hΨ (by fun_prop)\n rw [map_zero_trajMeasure] at h\n exact h.symm\n\nend AuxTraj\n\n/-! ### The one-step structure of a deterministic algorithm in a stationary environment -/\n\nsection BanditStep\n\nopen Preorder\nopen scoped ENNReal\n\nlemma lintegral_stepKernel_det {nextA : (n : ℕ) → (Iic n → 𝓐 × 𝓨) → 𝓐}\n (hmeasA : ∀ n, Measurable (nextA n)) (a0 : 𝓐) (ν : Kernel 𝓐 𝓨) [IsMarkovKernel ν]\n (n : ℕ) (h : Iic n → 𝓐 × 𝓨) {F : 𝓐 × 𝓨 → ℝ≥0∞} (hF : Measurable F) :\n ∫⁻ p, F p ∂(stepKernel (detAlgorithm nextA hmeasA a0) (stationaryEnv ν) n h)\n = ∫⁻ y, F (nextA n h, y) ∂(ν (nextA n h)) := by\n rw [stepKernel, Kernel.lintegral_compProd _ _ _ hF]\n exact Kernel.lintegral_deterministic' (hmeasA n)\n (hF.lintegral_kernel_prod_right'' (η := (stationaryEnv (𝓨 := 𝓨) ν).feedback n))\n\nlemma lintegral_dirac_compProd (a0 : 𝓐) (ν : Kernel 𝓐 𝓨) [IsMarkovKernel ν]\n {F : 𝓐 × 𝓨 → ℝ≥0∞} (hF : Measurable F) :\n ∫⁻ p, F p ∂((Measure.dirac a0) ⊗ₘ ν) = ∫⁻ y, F (a0, y) ∂(ν a0) := by\n rw [Measure.lintegral_compProd hF,\n lintegral_dirac' _ (hF.lintegral_kernel_prod_right' (κ := ν))]\n\nend BanditStep\n\n/-! ### A general one-step supermartingale estimate -/\n\nsection OneStep\n\nopen Preorder\nopen scoped ENNReal\n\n/-- Extend a history to an infinite sequence, using `d` after time `n`. -/\ndef extSeq (n : ℕ) (d : 𝓐 × 𝓨) (h : Iic n → 𝓐 × 𝓨) : ℕ → 𝓐 × 𝓨 :=\n fun i ↦ if hi : i ≤ n then h ⟨i, Finset.mem_Iic.2 hi⟩ else d\n\nlemma extSeq_frestrictLe (n : ℕ) (d : 𝓐 × 𝓨) (ω : ℕ → 𝓐 × 𝓨) {i : ℕ} (hi : i ≤ n) :\n extSeq n d (frestrictLe n ω) i = ω i := by\n simp [extSeq, hi, frestrictLe]\n\n@[fun_prop]\nlemma measurable_extSeq (n : ℕ) (d : 𝓐 × 𝓨) : Measurable (extSeq n d) := by\n refine measurable_pi_lambda _ fun i ↦ ?_\n by_cases hi : i ≤ n\n · simp only [extSeq, dif_pos hi]\n exact measurable_pi_apply _\n · simp only [extSeq, dif_neg hi]\n exact measurable_const\n\ntheorem lintegral_onestep {nextA : (n : ℕ) → (Iic n → 𝓐 × 𝓨) → 𝓐}\n (hmeasA : ∀ n, Measurable (nextA n)) (a0 : 𝓐) (ν : Kernel 𝓐 𝓨) [IsMarkovKernel ν]\n (d : 𝓐 × 𝓨) (n : ℕ)\n (Φ : (ℕ → 𝓐 × 𝓨) → (𝓐 × 𝓨) → ℝ≥0∞) (W : (ℕ → 𝓐 × 𝓨) → ℝ≥0∞)\n (hΦmeas : Measurable (fun q : (ℕ → 𝓐 × 𝓨) × (𝓐 × 𝓨) ↦ Φ q.1 q.2))\n (hWmeas : Measurable W)\n (hΦdep : ∀ ω ω' : ℕ → 𝓐 × 𝓨, (∀ i, i < n → ω i = ω' i) → Φ ω = Φ ω')\n (hWdep : ∀ ω ω' : ℕ → 𝓐 × 𝓨, (∀ i, i < n → ω i = ω' i) → W ω = W ω')\n (hbound : ∀ ω b, (∫⁻ y, Φ ω (b, y) ∂(ν b)) ≤ W ω) :\n ∫⁻ ω, Φ ω (ω n) ∂(trajMeasure (detAlgorithm nextA hmeasA a0) (stationaryEnv ν))\n ≤ ∫⁻ ω, W ω ∂(trajMeasure (detAlgorithm nextA hmeasA a0) (stationaryEnv ν)) := by\n set P := trajMeasure (detAlgorithm nextA hmeasA a0) (stationaryEnv ν) with hP\n have hPdef : P = Kernel.trajMeasure ((detAlgorithm nextA hmeasA a0).p0 ⊗ₘ\n (stationaryEnv ν).ν0) (stepKernel (detAlgorithm nextA hmeasA a0) (stationaryEnv ν)) := rfl\n have hPprob : IsProbabilityMeasure P := by rw [hPdef]; infer_instance\n have hΦfix : ∀ ω0 : ℕ → 𝓐 × 𝓨, Measurable (fun p : 𝓐 × 𝓨 ↦ Φ ω0 p) := fun ω0 ↦\n hΦmeas.comp (measurable_const.prodMk measurable_id')\n match n with\n | 0 =>\n have hΦ0 : ∀ ω, Φ ω = Φ (fun _ ↦ d) := fun ω ↦ hΦdep _ _ (by omega)\n have hW0 : ∀ ω, W ω = W (fun _ ↦ d) := fun ω ↦ hWdep _ _ (by omega)\n have e1 : ∫⁻ ω, Φ ω (ω 0) ∂P = ∫⁻ ω, (Φ (fun _ ↦ d)) (ω 0) ∂P := by\n refine lintegral_congr fun ω ↦ ?_\n rw [hΦ0 ω]\n have e2 : ∫⁻ ω, W ω ∂P = W (fun _ ↦ d) := by\n rw [show (fun ω ↦ W ω) = (fun _ ↦ W (fun _ : ℕ ↦ d)) from funext hW0]\n simp\n have hz := lintegral_trajMeasure_zero (X := fun _ ↦ 𝓐 × 𝓨)\n (μ₀ := (detAlgorithm nextA hmeasA a0).p0 ⊗ₘ (stationaryEnv ν).ν0)\n (κ := stepKernel (detAlgorithm nextA hmeasA a0) (stationaryEnv ν))\n (fun p ↦ Φ (fun _ ↦ d) p) (hΦfix _)\n rw [e1, e2, hPdef, hz]\n calc ∫⁻ p, Φ (fun _ ↦ d) p ∂((detAlgorithm nextA hmeasA a0).p0 ⊗ₘ (stationaryEnv ν).ν0)\n = ∫⁻ y, Φ (fun _ ↦ d) (a0, y) ∂(ν a0) :=\n lintegral_dirac_compProd a0 ν (hΦfix _)\n _ ≤ W (fun _ ↦ d) := hbound _ a0\n | (m + 1) =>\n have key : ∀ ω : ℕ → 𝓐 × 𝓨, Φ (extSeq m d (frestrictLe m ω)) = Φ ω := by\n intro ω\n exact hΦdep _ _ fun i hi ↦ extSeq_frestrictLe m d ω (by omega)\n have hstep := lintegral_trajMeasure_step (X := fun _ ↦ 𝓐 × 𝓨) (μ₀ := (detAlgorithm nextA hmeasA a0).p0 ⊗ₘ\n (stationaryEnv ν).ν0) (κ := stepKernel (detAlgorithm nextA hmeasA a0) (stationaryEnv ν))\n m (fun q ↦ Φ (extSeq m d q.1) q.2)\n (hΦmeas.comp (((measurable_extSeq m d).comp measurable_fst).prodMk measurable_snd))\n have e1 : ∫⁻ ω, Φ ω (ω (m + 1)) ∂P\n = ∫⁻ ω, Φ (extSeq m d (frestrictLe m ω)) (ω (m + 1)) ∂P := by\n refine lintegral_congr fun ω ↦ ?_\n rw [key ω]\n rw [e1, hPdef, hstep]\n refine lintegral_mono fun ω ↦ ?_\n calc ∫⁻ p, Φ (extSeq m d (frestrictLe m ω)) p\n ∂(stepKernel (detAlgorithm nextA hmeasA a0) (stationaryEnv ν) m (frestrictLe m ω))\n = ∫⁻ y, Φ (extSeq m d (frestrictLe m ω))\n (nextA m (frestrictLe m ω), y) ∂(ν (nextA m (frestrictLe m ω))) :=\n lintegral_stepKernel_det hmeasA a0 ν m _ (hΦfix _)\n _ ≤ W (extSeq m d (frestrictLe m ω)) := hbound _ _\n _ = W ω := hWdep _ _ fun i hi ↦ extSeq_frestrictLe m d ω (by omega)\n\nend OneStep\n\n/-! ### Counting functions along a trajectory -/\n\nsection Counting\n\nopen scoped ENNReal NNReal\n\nvariable {K : ℕ}\n\n/-- The number of pulls of arm `a` at times strictly before `n`. -/\ndef cntω (a : Fin K) (n : ℕ) (ω : ℕ → Fin K × ℝ) : ℕ :=\n ∑ s ∈ range n, if (ω s).1 = a then 1 else 0\n\n/-- The number of times `s < n` that are among the first `m` pulls of arm `a`. -/\ndef cntSω (a : Fin K) (m n : ℕ) (ω : ℕ → Fin K × ℝ) : ℕ :=\n ∑ s ∈ range n, if (ω s).1 = a ∧ cntω a s ω < m then 1 else 0\n\n/-- The sum of the rewards collected at the first `m` pulls of arm `a`, among times `s < n`. -/\nnoncomputable def smSω (a : Fin K) (m n : ℕ) (ω : ℕ → Fin K × ℝ) : ℝ :=\n ∑ s ∈ range n, if (ω s).1 = a ∧ cntω a s ω < m then (ω s).2 else 0\n\n/-- The sum of the rewards collected from arm `a` at times `s < n`. -/\nnoncomputable def smω (a : Fin K) (n : ℕ) (ω : ℕ → Fin K × ℝ) : ℝ :=\n ∑ s ∈ range n, if (ω s).1 = a then (ω s).2 else 0\n\n@[simp] lemma cntω_zero (a : Fin K) (ω : ℕ → Fin K × ℝ) : cntω a 0 ω = 0 := by simp [cntω]\n@[simp] lemma cntSω_zero (a : Fin K) (m : ℕ) (ω : ℕ → Fin K × ℝ) : cntSω a m 0 ω = 0 := by\n simp [cntSω]\n@[simp] lemma smSω_zero (a : Fin K) (m : ℕ) (ω : ℕ → Fin K × ℝ) : smSω a m 0 ω = 0 := by\n simp [smSω]\n@[simp] lemma smω_zero (a : Fin K) (ω : ℕ → Fin K × ℝ) : smω a 0 ω = 0 := by simp [smω]\n\nlemma cntω_succ (a : Fin K) (n : ℕ) (ω : ℕ → Fin K × ℝ) :\n cntω a (n + 1) ω = cntω a n ω + (if (ω n).1 = a then 1 else 0) := by\n rw [cntω, cntω, Finset.sum_range_succ]\n\nlemma cntSω_succ (a : Fin K) (m n : ℕ) (ω : ℕ → Fin K × ℝ) :\n cntSω a m (n + 1) ω\n = cntSω a m n ω + (if (ω n).1 = a ∧ cntω a n ω < m then 1 else 0) := by\n rw [cntSω, cntSω, Finset.sum_range_succ]\n\nlemma smSω_succ (a : Fin K) (m n : ℕ) (ω : ℕ → Fin K × ℝ) :\n smSω a m (n + 1) ω\n = smSω a m n ω + (if (ω n).1 = a ∧ cntω a n ω < m then (ω n).2 else 0) := by\n rw [smSω, smSω, Finset.sum_range_succ]\n\nlemma smω_succ (a : Fin K) (n : ℕ) (ω : ℕ → Fin K × ℝ) :\n smω a (n + 1) ω = smω a n ω + (if (ω n).1 = a then (ω n).2 else 0) := by\n rw [smω, smω, Finset.sum_range_succ]\n\nlemma cntω_congr (a : Fin K) (n : ℕ) {ω ω' : ℕ → Fin K × ℝ} (h : ∀ i, i < n → ω i = ω' i) :\n cntω a n ω = cntω a n ω' :=\n Finset.sum_congr rfl fun s hs ↦ by rw [h s (mem_range.1 hs)]\n\nlemma cntSω_congr (a : Fin K) (m n : ℕ) {ω ω' : ℕ → Fin K × ℝ} (h : ∀ i, i < n → ω i = ω' i) :\n cntSω a m n ω = cntSω a m n ω' :=\n Finset.sum_congr rfl fun s hs ↦ by\n have hs' := mem_range.1 hs\n rw [h s hs', cntω_congr a s (fun i hi ↦ h i (hi.trans hs'))]\n\nlemma smSω_congr (a : Fin K) (m n : ℕ) {ω ω' : ℕ → Fin K × ℝ} (h : ∀ i, i < n → ω i = ω' i) :\n smSω a m n ω = smSω a m n ω' :=\n Finset.sum_congr rfl fun s hs ↦ by\n have hs' := mem_range.1 hs\n rw [h s hs', cntω_congr a s (fun i hi ↦ h i (hi.trans hs'))]\n\nlemma measurableSet_arm (s : ℕ) (a : Fin K) :\n MeasurableSet {ω : ℕ → Fin K × ℝ | (ω s).1 = a} :=\n (measurableSet_singleton a).preimage (by fun_prop)\n\n@[fun_prop]\nlemma measurable_cntω (a : Fin K) (n : ℕ) : Measurable (cntω a n) := by\n unfold cntω\n refine Finset.measurable_sum _ fun s _ ↦ ?_\n exact Measurable.ite (measurableSet_arm s a) measurable_const measurable_const\n\n@[fun_prop]\nlemma measurable_cntSω (a : Fin K) (m n : ℕ) : Measurable (cntSω a m n) := by\n unfold cntSω\n refine Finset.measurable_sum _ fun s _ ↦ ?_\n refine Measurable.ite ?_ measurable_const measurable_const\n exact (measurableSet_arm s a).inter (measurable_cntω a s (measurableSet_Iio (a := m)))\n\n@[fun_prop]\nlemma measurable_smSω (a : Fin K) (m n : ℕ) : Measurable (smSω a m n) := by\n unfold smSω\n refine Finset.measurable_sum _ fun s _ ↦ ?_\n refine Measurable.ite ?_ (by fun_prop) measurable_const\n exact (measurableSet_arm s a).inter (measurable_cntω a s (measurableSet_Iio (a := m)))\n\nend Counting\n\n/-! ### The exponential supermartingale -/\n\nsection Supermartingale\n\nopen scoped ENNReal NNReal\n\nvariable {K : ℕ}\n\nlemma lintegral_exp_hoeffding (μ : Measure ℝ) [IsProbabilityMeasure μ]\n (hrew : ∀ᵐ x ∂μ, x ∈ Set.Icc (0 : ℝ) 1) (lam : ℝ) :\n ∫⁻ y, ENNReal.ofReal (Real.exp (lam * (y - μ[id]) - lam ^ 2 / 8)) ∂μ ≤ 1 := by\n have hsg : HasSubgaussianMGF (fun y : ℝ ↦ id y - μ[id]) ((‖(1 : ℝ) - 0‖₊ / 2) ^ 2) μ :=\n hasSubgaussianMGF_of_mem_Icc aemeasurable_id hrew\n have hmgf := hsg.mgf_le lam\n have hint := hsg.integrable_exp_mul lam\n have hc : (((‖(1 : ℝ) - 0‖₊ / 2) ^ 2 : ℝ≥0) : ℝ) = 1 / 4 := by norm_num\n rw [mgf] at hmgf\n simp only [id] at hmgf hint\n have key : ∫⁻ y, ENNReal.ofReal (Real.exp (lam * (y - μ[id]) - lam ^ 2 / 8)) ∂μ\n = ENNReal.ofReal (∫ y, Real.exp (lam * (y - μ[id]) - lam ^ 2 / 8) ∂μ) := by\n rw [← ofReal_integral_eq_lintegral_ofReal]\n · simp_rw [sub_eq_add_neg (lam * _), Real.exp_add]\n exact hint.mul_const _\n · filter_upwards with y using (Real.exp_pos _).le\n rw [key]\n have h2 : ∫ y, Real.exp (lam * (y - μ[id]) - lam ^ 2 / 8) ∂μ\n = Real.exp (-(lam ^ 2 / 8)) * ∫ y, Real.exp (lam * (y - μ[id])) ∂μ := by\n rw [← integral_const_mul]\n congr 1 with y\n rw [← Real.exp_add]\n ring_nf\n rw [h2]\n have hfin : Real.exp (-(lam ^ 2 / 8)) * ∫ y, Real.exp (lam * (y - μ[id])) ∂μ ≤ 1 := by\n have h3 : ∫ y, Real.exp (lam * (y - μ[id])) ∂μ ≤ Real.exp (lam ^ 2 / 8) := by\n refine hmgf.trans_eq ?_\n rw [hc]; ring_nf\n calc Real.exp (-(lam ^ 2 / 8)) * ∫ y, Real.exp (lam * (y - μ[id])) ∂μ\n ≤ Real.exp (-(lam ^ 2 / 8)) * Real.exp (lam ^ 2 / 8) :=\n mul_le_mul_of_nonneg_left h3 (Real.exp_pos _).le\n _ = 1 := by rw [← Real.exp_add]; simp\n calc ENNReal.ofReal (Real.exp (-(lam ^ 2 / 8)) * ∫ y, Real.exp (lam * (y - μ[id])) ∂μ)\n ≤ ENNReal.ofReal 1 := ENNReal.ofReal_le_ofReal hfin\n _ = 1 := by simp\n\n/-- The exponential weight defining the supermartingale. -/\nnoncomputable def wgtF (ν : Kernel (Fin K) ℝ) (a : Fin K) (lam : ℝ) (m n : ℕ)\n (ω : ℕ → Fin K × ℝ) : ℝ≥0∞ :=\n ENNReal.ofReal (Real.exp (lam * (smSω a m n ω - (ν a)[id] * (cntSω a m n ω : ℝ))\n - lam ^ 2 / 8 * (cntSω a m n ω : ℝ)))\n\n@[simp] lemma wgtF_zero (ν : Kernel (Fin K) ℝ) (a : Fin K) (lam : ℝ) (m : ℕ)\n (ω : ℕ → Fin K × ℝ) : wgtF ν a lam m 0 ω = 1 := by\n simp [wgtF]\n\nlemma wgtF_succ (ν : Kernel (Fin K) ℝ) (a : Fin K) (lam : ℝ) (m n : ℕ) (ω : ℕ → Fin K × ℝ) :\n wgtF ν a lam m (n + 1) ω = wgtF ν a lam m n ω *\n (if (ω n).1 = a ∧ cntω a n ω < m then\n ENNReal.ofReal (Real.exp (lam * ((ω n).2 - (ν a)[id]) - lam ^ 2 / 8)) else 1) := by\n rw [wgtF, wgtF, cntSω_succ, smSω_succ]\n by_cases hc : (ω n).1 = a ∧ cntω a n ω < m\n · simp only [if_pos hc, Nat.cast_add, Nat.cast_one]\n rw [← ENNReal.ofReal_mul (Real.exp_nonneg _), ← Real.exp_add]\n congr 1\n ring\n · simp only [if_neg hc, Nat.cast_add, Nat.cast_zero, add_zero, mul_one]\n\nlemma wgtF_ne_top (ν : Kernel (Fin K) ℝ) (a : Fin K) (lam : ℝ) (m n : ℕ)\n (ω : ℕ → Fin K × ℝ) : wgtF ν a lam m n ω ≠ ∞ := by\n rw [wgtF]; exact ENNReal.ofReal_ne_top\n\n@[fun_prop]\nlemma measurable_wgtF (ν : Kernel (Fin K) ℝ) (a : Fin K) (lam : ℝ) (m n : ℕ) :\n Measurable (wgtF ν a lam m n) := by\n unfold wgtF\n fun_prop\n\nlemma wgtF_congr (ν : Kernel (Fin K) ℝ) (a : Fin K) (lam : ℝ) (m n : ℕ)\n {ω ω' : ℕ → Fin K × ℝ} (h : ∀ i, i < n → ω i = ω' i) :\n wgtF ν a lam m n ω = wgtF ν a lam m n ω' := by\n rw [wgtF, wgtF, smSω_congr a m n h, cntSω_congr a m n h]\n\ntheorem lintegral_wgtF_le_one (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (hrewards : ∀ a, ∀ᵐ x ∂(ν a), x ∈ Set.Icc (0 : ℝ) 1)\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K) (hmeasA : ∀ n, Measurable (nextA n))\n (a : Fin K) (lam : ℝ) (m n : ℕ) :\n ∫⁻ ω, wgtF ν a lam m n ω\n ∂(trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) ≤ 1 := by\n have hPprob : IsProbabilityMeasure\n (trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) := by\n rw [trajMeasure]; infer_instance\n induction n with\n | zero => simp\n | succ n ih =>\n refine le_trans ?_ ih\n set Φ : (ℕ → Fin K × ℝ) → (Fin K × ℝ) → ℝ≥0∞ := fun ω p ↦\n wgtF ν a lam m n ω * (if p.1 = a ∧ cntω a n ω < m then\n ENNReal.ofReal (Real.exp (lam * (p.2 - (ν a)[id]) - lam ^ 2 / 8)) else 1) with hΦ\n have hset : MeasurableSet {q : (ℕ → Fin K × ℝ) × (Fin K × ℝ) |\n q.2.1 = a ∧ cntω a n q.1 < m} := by\n have h1 : MeasurableSet {q : (ℕ → Fin K × ℝ) × (Fin K × ℝ) | q.2.1 = a} :=\n (measurableSet_singleton a).preimage (by fun_prop)\n have h2 : MeasurableSet {q : (ℕ → Fin K × ℝ) × (Fin K × ℝ) | cntω a n q.1 < m } :=\n ((measurable_cntω a n).comp measurable_fst) (measurableSet_Iio (a := m))\n exact h1.inter h2\n have hΦmeas : Measurable (fun q : (ℕ → Fin K × ℝ) × (Fin K × ℝ) ↦ Φ q.1 q.2) := by\n refine Measurable.mul ((measurable_wgtF ν a lam m n).comp measurable_fst) ?_\n exact Measurable.ite hset (by fun_prop) measurable_const\n have hcalc : ∀ ω : ℕ → Fin K × ℝ, wgtF ν a lam m (n + 1) ω = Φ ω (ω n) := fun ω ↦\n wgtF_succ ν a lam m n ω\n calc ∫⁻ ω, wgtF ν a lam m (n + 1) ω\n ∂(trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν))\n = ∫⁻ ω, Φ ω (ω n)\n ∂(trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) :=\n lintegral_congr hcalc\n _ ≤ ∫⁻ ω, wgtF ν a lam m n ω\n ∂(trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) := by\n refine lintegral_onestep hmeasA ⟨0, hK⟩ ν (⟨0, hK⟩, 0) n Φ (wgtF ν a lam m n)\n hΦmeas (measurable_wgtF ν a lam m n) ?_ ?_ ?_\n · intro ω ω' h\n funext p\n rw [hΦ]\n simp only\n rw [wgtF_congr ν a lam m n h, cntω_congr a n h]\n · intro ω ω' h\n exact wgtF_congr ν a lam m n h\n · intro ω b\n rw [hΦ]\n simp only\n rw [lintegral_const_mul' _ _ (wgtF_ne_top ν a lam m n ω)]\n by_cases hc : b = a ∧ cntω a n ω < m\n · simp only [if_pos hc]\n refine mul_le_of_le_one_right' ?_\n rw [hc.1]\n exact lintegral_exp_hoeffding (ν a) (hrewards a) lam\n · simp only [if_neg hc]\n simp\nend Supermartingale\n\n/-! ### Tail bounds and structure of the trajectory -/\n\nsection Tail\n\nopen Preorder\nopen scoped ENNReal NNReal\n\nvariable {K : ℕ}\n\ntheorem measure_tail_bound (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (hrewards : ∀ a, ∀ᵐ x ∂(ν a), x ∈ Set.Icc (0 : ℝ) 1)\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K) (hmeasA : ∀ n, Measurable (nextA n))\n (a : Fin K) (lam : ℝ) (m n : ℕ) (L : ℝ) :\n (trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν))\n {ω | L ≤ lam * (smSω a m n ω - (ν a)[id] * (cntSω a m n ω : ℝ))\n - lam ^ 2 / 8 * (cntSω a m n ω : ℝ)}\n ≤ ENNReal.ofReal (Real.exp (-L)) := by\n set P := trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν) with hPdef\n have hsub : {ω : ℕ → Fin K × ℝ | L ≤ lam * (smSω a m n ω - (ν a)[id] * (cntSω a m n ω : ℝ))\n - lam ^ 2 / 8 * (cntSω a m n ω : ℝ)}\n ⊆ {ω | ENNReal.ofReal (Real.exp L) ≤ wgtF ν a lam m n ω} := by\n intro ω hω\n exact ENNReal.ofReal_le_ofReal (Real.exp_le_exp.2 hω)\n have h1 : ENNReal.ofReal (Real.exp L) *\n P {ω | ENNReal.ofReal (Real.exp L) ≤ wgtF ν a lam m n ω} ≤ 1 :=\n (mul_meas_ge_le_lintegral (measurable_wgtF ν a lam m n) _).trans\n (lintegral_wgtF_le_one hK ν hrewards nextA hmeasA a lam m n)\n have h2 : P {ω | ENNReal.ofReal (Real.exp L) ≤ wgtF ν a lam m n ω}\n ≤ (ENNReal.ofReal (Real.exp L))⁻¹ := by\n rw [ENNReal.le_inv_iff_mul_le, mul_comm]\n exact h1\n refine (measure_mono hsub).trans (h2.trans_eq ?_)\n rw [Real.exp_neg, ENNReal.ofReal_inv_of_pos (Real.exp_pos _)]\n\nlemma measurableSet_actionEq (n : ℕ)\n (nextA : (m : ℕ) → (Iic m → Fin K × ℝ) → Fin K) (hmeasA : ∀ m, Measurable (nextA m)) :\n MeasurableSet {q : (Iic n → Fin K × ℝ) × (Fin K × ℝ) | q.2.1 = nextA n q.1} := by\n have : {q : (Iic n → Fin K × ℝ) × (Fin K × ℝ) | q.2.1 = nextA n q.1}\n = ⋃ b : Fin K, ((fun q : (Iic n → Fin K × ℝ) × (Fin K × ℝ) ↦ q.2.1) ⁻¹' {b}) ∩\n ((fun q : (Iic n → Fin K × ℝ) × (Fin K × ℝ) ↦ nextA n q.1) ⁻¹' {b}) := by\n ext q; simp only [Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_preimage,\n Set.mem_singleton_iff]\n exact ⟨fun h ↦ ⟨q.2.1, rfl, h.symm⟩, fun ⟨b, h1, h2⟩ ↦ h1.trans h2.symm⟩\n rw [this]\n exact MeasurableSet.iUnion fun b ↦\n ((measurableSet_singleton b).preimage (by fun_prop)).inter\n ((measurableSet_singleton b).preimage ((hmeasA n).comp measurable_fst))\n\ntheorem ae_action_succ (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K) (hmeasA : ∀ n, Measurable (nextA n))\n (n : ℕ) :\n ∀ᵐ ω ∂(trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)),\n (ω (n + 1)).1 = nextA n (frestrictLe n ω) := by\n set P := trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν) with hPdef\n have hPeq : P = Kernel.trajMeasure\n ((detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)).p0 ⊗ₘ (stationaryEnv ν).ν0)\n (stepKernel (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) := rfl\n set Φ : ((Iic n → Fin K × ℝ) × (Fin K × ℝ)) → ℝ≥0∞ := fun q ↦\n if q.2.1 = nextA n q.1 then 0 else 1 with hΦ\n have hΦmeas : Measurable Φ :=\n Measurable.ite (measurableSet_actionEq n nextA hmeasA) measurable_const measurable_const\n have hstep := lintegral_trajMeasure_step (X := fun _ ↦ Fin K × ℝ)\n (μ₀ := (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)).p0 ⊗ₘ (stationaryEnv ν).ν0)\n (κ := stepKernel (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) n Φ hΦmeas\n have hzero : ∫⁻ ω, Φ (frestrictLe n ω, ω (n + 1)) ∂P = 0 := by\n rw [hPeq, hstep]\n refine (lintegral_eq_zero_iff ?_).2 ?_\n · exact (hΦmeas.lintegral_kernel_prod_right'\n (κ := stepKernel (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν) n)).comp\n (measurable_frestrictLe n)\n · filter_upwards with ω\n rw [lintegral_stepKernel_det (F := fun p ↦ Φ (frestrictLe n ω, p)) hmeasA\n (⟨0, hK⟩ : Fin K) ν n (frestrictLe n ω)\n (hΦmeas.comp (measurable_const.prodMk measurable_id'))]\n simp [hΦ]\n have := (lintegral_eq_zero_iff\n (hΦmeas.comp ((measurable_frestrictLe n).prodMk (measurable_pi_apply (n + 1))))).1 hzero\n filter_upwards [this] with ω hω\n by_contra hcon\n simp only [Function.comp_apply, hΦ, Pi.zero_apply] at hω\n rw [if_neg hcon] at hω\n exact one_ne_zero hω\n\ntheorem ae_action_zero (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K) (hmeasA : ∀ n, Measurable (nextA n)) :\n ∀ᵐ ω ∂(trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)),\n (ω 0).1 = (⟨0, hK⟩ : Fin K) := by\n set P := trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν) with hPdef\n have hPeq : P = Kernel.trajMeasure\n ((detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)).p0 ⊗ₘ (stationaryEnv ν).ν0)\n (stepKernel (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) := rfl\n set Ψ : (Fin K × ℝ) → ℝ≥0∞ := fun p ↦ if p.1 = (⟨0, hK⟩ : Fin K) then 0 else 1 with hΨ\n have hΨmeas : Measurable Ψ :=\n Measurable.ite ((measurableSet_singleton _).preimage (by fun_prop))\n measurable_const measurable_const\n have hzero : ∫⁻ ω, Ψ (ω 0) ∂P = 0 := by\n rw [hPeq, lintegral_trajMeasure_zero (X := fun _ ↦ Fin K × ℝ)\n (μ₀ := (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)).p0 ⊗ₘ (stationaryEnv ν).ν0)\n (κ := stepKernel (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) Ψ hΨmeas,\n show (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)).p0 = Measure.dirac (⟨0, hK⟩ : Fin K) from\n rfl,\n show (stationaryEnv (𝓨 := ℝ) ν).ν0 = ν from rfl,\n lintegral_dirac_compProd (⟨0, hK⟩ : Fin K) ν hΨmeas]\n simp [hΨ]\n have := (lintegral_eq_zero_iff (hΨmeas.comp (measurable_pi_apply 0))).1 hzero\n filter_upwards [this] with ω hω\n by_contra hcon\n simp only [Function.comp_apply, hΨ, Pi.zero_apply] at hω\n rw [if_neg hcon] at hω\n exact one_ne_zero hω\n\nend Tail\n\n/-! ### Elementary combinatorial facts about the counting functions -/\n\nsection CountFacts\n\nopen Preorder\n\nvariable {K : ℕ}\n\nlemma cntω_mono (a : Fin K) (ω : ℕ → Fin K × ℝ) {s t : ℕ} (h : s ≤ t) :\n cntω a s ω ≤ cntω a t ω := by\n refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_subset_range.2 h) ?_\n intro i _ _\n positivity\n\nlemma cntω_le (a : Fin K) (n : ℕ) (ω : ℕ → Fin K × ℝ) : cntω a n ω ≤ n := by\n calc cntω a n ω ≤ ∑ _s ∈ range n, 1 := by\n refine Finset.sum_le_sum fun i _ ↦ ?_\n split <;> simp\n _ = n := by simp\n\nlemma cntω_lt_of_pull (a : Fin K) (ω : ℕ → Fin K × ℝ) {s : ℕ} (hs : (ω s).1 = a) :\n cntω a s ω < cntω a (s + 1) ω := by\n rw [cntω_succ, if_pos hs]\n omega\n\nlemma stopped_cond (a : Fin K) (ω : ℕ → Fin K × ℝ) (t s : ℕ) :\n ((ω s).1 = a ∧ cntω a s ω < cntω a t ω) ↔ ((ω s).1 = a ∧ s < t) := by\n constructor\n · rintro ⟨h1, h2⟩\n refine ⟨h1, ?_⟩\n by_contra hcon\n exact absurd (cntω_mono a ω (Nat.le_of_not_lt hcon)) (by omega)\n · rintro ⟨h1, h2⟩\n exact ⟨h1, lt_of_lt_of_le (cntω_lt_of_pull a ω h1) (cntω_mono a ω h2)⟩\n\nlemma cntSω_stop (a : Fin K) (ω : ℕ → Fin K × ℝ) {t N : ℕ} (htN : t ≤ N) :\n cntSω a (cntω a t ω) N ω = cntω a t ω := by\n rw [cntSω]\n have h1 : ∀ s ∈ range N, (if (ω s).1 = a ∧ cntω a s ω < cntω a t ω then 1 else 0)\n = (if (ω s).1 = a ∧ s < t then 1 else 0) := by\n intro s _\n exact if_congr (stopped_cond a ω t s) rfl rfl\n rw [Finset.sum_congr rfl h1, ← Finset.sum_subset (Finset.range_subset_range.2 htN)]\n · rw [cntω]\n refine Finset.sum_congr rfl fun s hs ↦ ?_\n rw [if_congr (and_iff_left (mem_range.1 hs)) rfl rfl]\n · intro s _ hs\n rw [if_neg]\n rintro ⟨-, h⟩\n exact hs (mem_range.2 h)\n\nlemma smSω_stop (a : Fin K) (ω : ℕ → Fin K × ℝ) {t N : ℕ} (htN : t ≤ N) :\n smSω a (cntω a t ω) N ω = smω a t ω := by\n rw [smSω]\n have h1 : ∀ s ∈ range N, (if (ω s).1 = a ∧ cntω a s ω < cntω a t ω then (ω s).2 else 0)\n = (if (ω s).1 = a ∧ s < t then (ω s).2 else 0) := by\n intro s _\n exact if_congr (stopped_cond a ω t s) rfl rfl\n rw [Finset.sum_congr rfl h1, ← Finset.sum_subset (Finset.range_subset_range.2 htN)]\n · rw [smω]\n refine Finset.sum_congr rfl fun s hs ↦ ?_\n rw [if_congr (and_iff_left (mem_range.1 hs)) rfl rfl]\n · intro s _ hs\n rw [if_neg]\n rintro ⟨-, h⟩\n exact hs (mem_range.2 h)\n\nlemma Iic_eq_range (n : ℕ) : Finset.Iic n = Finset.range (n + 1) := by\n ext i; simp [Nat.lt_succ_iff]\n\nlemma pullCount'_frestrictLe (n : ℕ) (ω : ℕ → Fin K × ℝ) (b : Fin K) :\n pullCount' n (frestrictLe n ω) b = cntω b (n + 1) ω := by\n rw [pullCount'_eq_sum, cntω, ← Iic_eq_range]\n exact Finset.sum_coe_sort (Finset.Iic n) (fun s ↦ if (ω s).1 = b then 1 else 0)\n\nlemma sumRewards'_frestrictLe (n : ℕ) (ω : ℕ → Fin K × ℝ) (b : Fin K) :\n sumRewards' n (frestrictLe n ω) b = smω b (n + 1) ω := by\n rw [sumRewards', smω, ← Iic_eq_range]\n exact Finset.sum_coe_sort (Finset.Iic n) (fun s ↦ if (ω s).1 = b then (ω s).2 else 0)\n\nlemma empMean'_frestrictLe (n : ℕ) (ω : ℕ → Fin K × ℝ) (b : Fin K) :\n empMean' n (frestrictLe n ω) b = smω b (n + 1) ω / (cntω b (n + 1) ω : ℝ) := by\n rw [empMean', sumRewards'_frestrictLe, pullCount'_frestrictLe]\n\nlemma cHat_frestrictLe (δ : ℝ) (n : ℕ) (ω : ℕ → Fin K × ℝ) (b : Fin K) :\n cHat δ n (frestrictLe n ω) b\n = Real.sqrt (Real.log (2 * ((cntω b (n + 1) ω : ℝ) + 1) ^ 2 / δ)\n / (2 * (cntω b (n + 1) ω : ℝ))) := by\n rw [cHat, pullCount'_frestrictLe]\n\nend CountFacts\n\n/-! ### The deterministic regret analysis -/\n\nsection Deterministic\n\nopen Preorder\n\nvariable {K : ℕ}\n\nlemma warmup_action (hK : 0 < K)\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K}\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (ω : ℕ → Fin K × ℝ) (h0 : (ω 0).1 = ⟨0, hK⟩)\n (hact : ∀ n, (ω (n + 1)).1 = nextA n (frestrictLe n ω))\n (s : ℕ) (hs : s < K) : ((ω s).1 : ℕ) = s := by\n induction s with\n | zero => rw [h0]\n | succ s ih =>\n rw [hact s, hwarm s _ (by omega), RoundRobin.nextAction]\n exact Nat.mod_eq_of_lt hs\n\nlemma warmup_count (hK : 0 < K)\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K}\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (ω : ℕ → Fin K × ℝ) (h0 : (ω 0).1 = ⟨0, hK⟩)\n (hact : ∀ n, (ω (n + 1)).1 = nextA n (frestrictLe n ω))\n (a : Fin K) : cntω a K ω = 1 := by\n have hw := warmup_action hK hwarm ω h0 hact\n rw [cntω]\n have h1 : ∀ s ∈ range K, (if (ω s).1 = a then (1 : ℕ) else 0) = (if s = (a : ℕ) then 1 else 0) := by\n intro s hs\n rw [mem_range] at hs\n refine if_congr ?_ rfl rfl\n constructor\n · intro h; rw [← hw s hs, h]\n · intro h; exact Fin.ext (by rw [hw s hs, h])\n rw [Finset.sum_congr rfl h1, Finset.sum_ite_eq' (range K) ((a : ℕ)) (fun _ ↦ (1 : ℕ))]\n simp [a.isLt]\n\ntheorem count_bound (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (T : ℕ) (hKT : K ≤ T) (hT : 0 < T) (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1)\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K}\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + cHat δ n h a ≤ empMean' n h (nextA n h) + cHat δ n h (nextA n h))\n (astar : Fin K) (hastar : ∀ b, (ν b)[id] ≤ (ν astar)[id])\n (ω : ℕ → Fin K × ℝ)\n (hwarmcount : ∀ b : Fin K, cntω b K ω = 1)\n (hact : ∀ n, (ω (n + 1)).1 = nextA n (frestrictLe n ω))\n (hup : ∀ (b : Fin K) (n : ℕ), 1 ≤ n → n < T → cntSω b n T ω = n →\n smSω b n T ω ≤ (n : ℝ) * (ν b)[id]\n + (n : ℝ) * Real.sqrt (Real.log (2 * K * T ^ 2 / δ) / (2 * n)))\n (hlow : ∀ (m : ℕ), 1 ≤ m → m < T → cntSω astar m T ω = m →\n (m : ℝ) * (ν astar)[id] - smSω astar m T ω\n ≤ (m : ℝ) * Real.sqrt (Real.log (2 * ((m : ℝ) + 1) ^ 2 / δ) / (2 * m)))\n (a : Fin K) :\n ((∑ s ∈ Ico K T, if (ω s).1 = a then (1 : ℕ) else 0 : ℕ) : ℝ)\n * ((ν astar)[id] - (ν a)[id]) ^ 2 ≤ 2 * Real.log (2 * K * T ^ 2 / δ) := by\n set L := Real.log (2 * (K : ℝ) * (T : ℝ) ^ 2 / δ) with hLdef\n have hKR : (1 : ℝ) ≤ (K : ℝ) := by exact_mod_cast hK\n have hTR : (1 : ℝ) ≤ (T : ℝ) := by exact_mod_cast hT\n have harg : (2 : ℝ) ≤ 2 * (K : ℝ) * (T : ℝ) ^ 2 / δ := by\n rw [le_div_iff₀ hδ]\n nlinarith [sq_nonneg ((T : ℝ) - 1)]\n have hLpos : 0 < L := Real.log_pos (by linarith)\n set M := (∑ s ∈ Ico K T, if (ω s).1 = a then (1 : ℕ) else 0) with hMdef\n set Δ := (ν astar)[id] - (ν a)[id] with hΔdef\n have hΔ0 : 0 ≤ Δ := by simp only [hΔdef, sub_nonneg]; exact hastar a\n rcases Nat.eq_zero_or_pos M with hM0 | hMpos\n · rw [hM0]\n simp only [Nat.cast_zero, zero_mul]\n linarith\n -- there is a last time in `[K, T)` at which arm `a` is pulled\n set S := (Ico K T).filter (fun s ↦ (ω s).1 = a) with hSdef\n have hcard : S.card = M := by\n rw [hSdef, hMdef, Finset.card_filter]\n have hSne : S.Nonempty := by\n rw [← Finset.card_pos, hcard]; exact hMpos\n set t := S.max' hSne with htdef\n have htS : t ∈ S := S.max'_mem hSne\n have htmem : t ∈ Ico K T := (Finset.mem_filter.1 htS).1\n have hta : (ω t).1 = a := (Finset.mem_filter.1 htS).2\n have hKt : K ≤ t := (Finset.mem_Ico.1 htmem).1\n have htT : t < T := (Finset.mem_Ico.1 htmem).2\n have hmaxS : ∀ s ∈ S, s ≤ t := fun s hs ↦ Finset.le_max' S s hs\n -- the pull count of `a` just before `t` equals `M`\n have hsum_tT : (∑ s ∈ Ico t T, if (ω s).1 = a then (1 : ℕ) else 0) = 1 := by\n rw [Finset.sum_eq_single_of_mem t (Finset.mem_Ico.2 ⟨le_refl t, htT⟩) ?_]\n · rw [if_pos hta]\n · intro b hb hbt\n rw [if_neg]\n intro hba\n have : b ∈ S := Finset.mem_filter.2 ⟨Finset.mem_Ico.2\n ⟨le_trans hKt (Finset.mem_Ico.1 hb).1, (Finset.mem_Ico.1 hb).2⟩, hba⟩\n have := hmaxS b this\n have := (Finset.mem_Ico.1 hb).1\n omega\n have hMsplit : M = (∑ s ∈ Ico K t, if (ω s).1 = a then (1 : ℕ) else 0) + 1 := by\n rw [hMdef, ← Finset.sum_Ico_consecutive (fun s ↦ if (ω s).1 = a then (1 : ℕ) else 0)\n hKt (le_of_lt htT), hsum_tT]\n have hcnt_t : cntω a t ω = M := by\n have e1 : cntω a t ω = (∑ s ∈ Ico 0 K, if (ω s).1 = a then (1 : ℕ) else 0)\n + (∑ s ∈ Ico K t, if (ω s).1 = a then (1 : ℕ) else 0) := by\n rw [cntω, Finset.range_eq_Ico, Finset.sum_Ico_consecutive _ (Nat.zero_le K) hKt]\n have e2 : (∑ s ∈ Ico 0 K, if (ω s).1 = a then (1 : ℕ) else 0) = 1 := by\n rw [← Finset.range_eq_Ico]; exact hwarmcount a\n rw [e1, e2, hMsplit]\n omega\n -- set up the last round\n obtain ⟨t', ht'⟩ : ∃ t', t = t' + 1 := ⟨t - 1, by omega⟩\n have hKt' : K - 1 ≤ t' := by omega\n have hMT : M < T := by\n have := cntω_le a t ω\n omega\n have hMR : (0 : ℝ) < (M : ℝ) := by exact_mod_cast hMpos\n have hm1 : 1 ≤ cntω astar t ω := by\n have h1 := hwarmcount astar\n have h2 := cntω_mono astar ω hKt\n omega\n have hmT : cntω astar t ω < T := lt_of_le_of_lt (cntω_le astar t ω) htT\n have hmR : (0 : ℝ) < ((cntω astar t ω : ℕ) : ℝ) := by exact_mod_cast hm1\n -- the algorithm's choice at time `t`\n have hnextA : nextA t' (frestrictLe t' ω) = a := by\n rw [← hact t', ← ht']; exact hta\n have hkey := hargmax t' (frestrictLe t' ω) astar hKt'\n rw [hnextA] at hkey\n rw [empMean'_frestrictLe, empMean'_frestrictLe, cHat_frestrictLe, cHat_frestrictLe,\n ← ht'] at hkey\n rw [hcnt_t] at hkey\n -- the confidence widths\n set γ := Real.sqrt (L / (2 * (M : ℝ))) with hγdef\n have hCa : Real.sqrt (Real.log (2 * ((M : ℝ) + 1) ^ 2 / δ) / (2 * (M : ℝ))) ≤ γ := by\n refine Real.sqrt_le_sqrt ?_\n have hlog : Real.log (2 * ((M : ℝ) + 1) ^ 2 / δ) ≤ L := by\n refine Real.log_le_log (by positivity) ?_\n have hMle : (M : ℝ) + 1 ≤ (T : ℝ) := by\n have : (M : ℝ) + 1 ≤ ((M + 1 : ℕ) : ℝ) := by push_cast; linarith\n have h2 : (M + 1 : ℕ) ≤ T := hMT\n calc (M : ℝ) + 1 = ((M + 1 : ℕ) : ℝ) := by push_cast; ring\n _ ≤ (T : ℝ) := by exact_mod_cast h2\n have h0M : (0 : ℝ) ≤ (M : ℝ) + 1 := by positivity\n have : ((M : ℝ) + 1) ^ 2 ≤ (K : ℝ) * (T : ℝ) ^ 2 := by nlinarith\n rw [div_le_div_iff_of_pos_right hδ]\n nlinarith\n gcongr\n -- upper deviation for arm `a`\n have hcntS_a : cntSω a M T ω = M := by\n have h := cntSω_stop a ω (le_of_lt htT); rwa [hcnt_t] at h\n have hsmS_a : smSω a M T ω = smω a t ω := by\n have h := smSω_stop a ω (le_of_lt htT); rwa [hcnt_t] at h\n have hupa := hup a M hMpos hMT hcntS_a\n rw [hsmS_a] at hupa\n have hEa : smω a t ω / (M : ℝ) ≤ (ν a)[id] + γ := by\n rw [div_le_iff₀ hMR]\n calc smω a t ω ≤ (M : ℝ) * (ν a)[id] + (M : ℝ) * γ := hupa\n _ = ((ν a)[id] + γ) * (M : ℝ) := by ring\n -- lower deviation for the optimal arm\n have hcntS_s : cntSω astar (cntω astar t ω) T ω = cntω astar t ω :=\n cntSω_stop astar ω (le_of_lt htT)\n have hsmS_s : smSω astar (cntω astar t ω) T ω = smω astar t ω :=\n smSω_stop astar ω (le_of_lt htT)\n have hlows := hlow (cntω astar t ω) hm1 hmT hcntS_s\n rw [hsmS_s] at hlows\n have hEs : (ν astar)[id] ≤ smω astar t ω / ((cntω astar t ω : ℕ) : ℝ)\n + Real.sqrt (Real.log (2 * (((cntω astar t ω : ℕ) : ℝ) + 1) ^ 2 / δ)\n / (2 * ((cntω astar t ω : ℕ) : ℝ))) := by\n rw [← sub_le_iff_le_add, le_div_iff₀ hmR]\n nlinarith [hlows]\n -- combine\n have hΔγ : Δ ≤ 2 * γ := by\n simp only [hΔdef]\n linarith [hkey, hCa, hEa, hEs]\n have hγsq : γ ^ 2 = L / (2 * (M : ℝ)) := Real.sq_sqrt (by positivity)\n have hsq : Δ ^ 2 ≤ (2 * γ) ^ 2 := by\n exact pow_le_pow_left₀ hΔ0 hΔγ 2\n have hfin : (2 * γ) ^ 2 = 4 * (L / (2 * (M : ℝ))) := by\n rw [mul_pow, hγsq]; norm_num\n calc ((M : ℕ) : ℝ) * Δ ^ 2 ≤ (M : ℝ) * (4 * (L / (2 * (M : ℝ)))) := by\n rw [← hfin]; exact mul_le_mul_of_nonneg_left hsq (le_of_lt hMR)\n _ = 2 * L := by field_simp; ring\n\ntheorem det_regret_bound (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (T : ℕ) (hKT : K ≤ T) (hT : 0 < T) (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1)\n {nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K}\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + cHat δ n h a ≤ empMean' n h (nextA n h) + cHat δ n h (nextA n h))\n (astar : Fin K) (hastar : ∀ b, (ν b)[id] ≤ (ν astar)[id])\n (ω : ℕ → Fin K × ℝ)\n (h0 : (ω 0).1 = ⟨0, hK⟩)\n (hact : ∀ n, (ω (n + 1)).1 = nextA n (frestrictLe n ω))\n (hup : ∀ (b : Fin K) (n : ℕ), 1 ≤ n → n < T → cntSω b n T ω = n →\n smSω b n T ω ≤ (n : ℝ) * (ν b)[id]\n + (n : ℝ) * Real.sqrt (Real.log (2 * K * T ^ 2 / δ) / (2 * n)))\n (hlow : ∀ (m : ℕ), 1 ≤ m → m < T → cntSω astar m T ω = m →\n (m : ℝ) * (ν astar)[id] - smSω astar m T ω\n ≤ (m : ℝ) * Real.sqrt (Real.log (2 * ((m : ℝ) + 1) ^ 2 / δ) / (2 * m))) :\n regret ν (fun s ω ↦ (ω s).1) T ω ≤\n (⨅ Δ₀ : {x : ℝ // 0 < x},\n ((T : ℝ) - K) * (Δ₀ : ℝ) +\n ∑ a : Fin K,\n Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' ↦ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') a)\n + ∑ a : Fin K, gap ν a := by\n have hwarmcount := warmup_count hK hwarm ω h0 hact\n have : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n have hsup : (⨆ i, (ν i)[id]) = (ν astar)[id] := by\n refine le_antisymm (ciSup_le hastar) ?_\n exact le_ciSup (f := fun i : Fin K ↦ (ν i)[id])\n (Set.Finite.bddAbove (Set.finite_range _)) astar\n have hgap : ∀ b : Fin K, gap ν b = (ν astar)[id] - (ν b)[id] := by\n intro b; rw [gap, hsup]\n have hgap0 : ∀ b : Fin K, 0 ≤ gap ν b := by\n intro b; rw [hgap]; linarith [hastar b]\n set Mn : Fin K → ℕ := fun b ↦ ∑ s ∈ Ico K T, if (ω s).1 = b then 1 else 0 with hMndef\n -- regret as a sum of gaps\n have hreg : regret ν (fun s ω ↦ (ω s).1) T ω = ∑ s ∈ range T, gap ν ((ω s).1) := by\n rw [regret]\n simp only [gap]\n rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_range, nsmul_eq_mul]\n -- the warm-up phase\n have hwarmsum : ∑ s ∈ range K, gap ν ((ω s).1) = ∑ a : Fin K, gap ν a := by\n have hw := warmup_action hK hwarm ω h0 hact\n have e1 : ∀ s ∈ range K, gap ν ((ω s).1)\n = (fun s : ℕ ↦ if h : s < K then gap ν ⟨s, h⟩ else 0) s := by\n intro s hs\n rw [mem_range] at hs\n simp only [dif_pos hs]\n congr 1\n exact Fin.ext (hw s hs)\n rw [Finset.sum_congr rfl e1,\n ← Fin.sum_univ_eq_sum_range (fun s : ℕ ↦ if h : s < K then gap ν ⟨s, h⟩ else 0) K]\n refine Finset.sum_congr rfl fun b _ ↦ ?_\n simp only [dif_pos b.isLt, Fin.eta]\n -- the exploitation phase, decomposed over arms\n have hexploit : ∑ s ∈ Ico K T, gap ν ((ω s).1)\n = ∑ b : Fin K, ((Mn b : ℕ) : ℝ) * gap ν b := by\n have e1 : ∀ s ∈ Ico K T, gap ν ((ω s).1)\n = ∑ b : Fin K, (if (ω s).1 = b then gap ν b else 0) := by\n intro s _\n rw [Finset.sum_ite_eq univ ((ω s).1) (fun b ↦ gap ν b)]\n simp\n rw [Finset.sum_congr rfl e1, Finset.sum_comm]\n refine Finset.sum_congr rfl fun b _ ↦ ?_\n rw [hMndef]\n push_cast\n rw [Finset.sum_mul]\n refine Finset.sum_congr rfl fun s _ ↦ ?_\n split <;> simp\n have hcount : ∑ b : Fin K, ((Mn b : ℕ) : ℝ) = (T : ℝ) - K := by\n have e1 : ∑ b : Fin K, (Mn b : ℕ) = T - K := by\n rw [hMndef]\n rw [Finset.sum_comm]\n have : ∀ s ∈ Ico K T, (∑ b : Fin K, if (ω s).1 = b then (1 : ℕ) else 0) = 1 := by\n intro s _\n rw [Finset.sum_ite_eq univ ((ω s).1) (fun _ ↦ (1 : ℕ))]\n simp\n rw [Finset.sum_congr rfl this]\n simp\n calc ∑ b : Fin K, ((Mn b : ℕ) : ℝ) = ((∑ b : Fin K, (Mn b : ℕ) : ℕ) : ℝ) := by push_cast; ring\n _ = ((T - K : ℕ) : ℝ) := by rw [e1]\n _ = (T : ℝ) - K := by\n exact Nat.cast_sub hKT\n -- the key bound for each `Δ₀`\n have hbound : ∀ Δ₀ : {x : ℝ // 0 < x},\n ∑ b : Fin K, ((Mn b : ℕ) : ℝ) * gap ν b ≤\n ((T : ℝ) - K) * (Δ₀ : ℝ) +\n ∑ a : Fin K,\n Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' ↦ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') a := by\n intro Δ₀\n have hstep : ∀ b : Fin K, ((Mn b : ℕ) : ℝ) * gap ν b ≤\n (Δ₀ : ℝ) * ((Mn b : ℕ) : ℝ) +\n Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' ↦ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') b := by\n intro b\n have hMn0 : (0 : ℝ) ≤ ((Mn b : ℕ) : ℝ) := Nat.cast_nonneg _\n by_cases hb : (Δ₀ : ℝ) < gap ν b\n · rw [Set.indicator_of_mem (show b ∈ {a' : Fin K | (Δ₀ : ℝ) < gap ν a'} from hb)]\n have hgb : 0 < gap ν b := lt_trans Δ₀.2 hb\n have hcb := count_bound hK ν T hKT hT δ hδ hδ1 hargmax astar hastar ω hwarmcount hact\n hup hlow b\n rw [← hgap b] at hcb\n have h2 : ((Mn b : ℕ) : ℝ) * gap ν b\n ≤ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν b := by\n rw [le_div_iff₀ hgb]\n calc ((Mn b : ℕ) : ℝ) * gap ν b * gap ν b\n = ((Mn b : ℕ) : ℝ) * gap ν b ^ 2 := by ring\n _ ≤ 2 * Real.log (2 * K * T ^ 2 / δ) := hcb\n nlinarith [mul_nonneg (le_of_lt Δ₀.2) hMn0]\n · rw [Set.indicator_of_notMem (show b ∉ {a' : Fin K | (Δ₀ : ℝ) < gap ν a'} from hb)]\n push_neg at hb\n nlinarith\n calc ∑ b : Fin K, ((Mn b : ℕ) : ℝ) * gap ν b\n ≤ ∑ b : Fin K, ((Δ₀ : ℝ) * ((Mn b : ℕ) : ℝ) +\n Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' ↦ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') b) :=\n Finset.sum_le_sum fun b _ ↦ hstep b\n _ = (Δ₀ : ℝ) * ((T : ℝ) - K) +\n ∑ a : Fin K, Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' ↦ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') a := by\n rw [Finset.sum_add_distrib, ← Finset.mul_sum, hcount]\n _ = ((T : ℝ) - K) * (Δ₀ : ℝ) +\n ∑ a : Fin K, Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' ↦ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') a := by\n rw [mul_comm]\n have hinf : ∑ b : Fin K, ((Mn b : ℕ) : ℝ) * gap ν b ≤\n ⨅ Δ₀ : {x : ℝ // 0 < x},\n ((T : ℝ) - K) * (Δ₀ : ℝ) +\n ∑ a : Fin K,\n Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' ↦ 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') a := le_ciInf hbound\n have hsplit : ∑ s ∈ range T, gap ν ((ω s).1)\n = (∑ s ∈ range K, gap ν ((ω s).1)) + ∑ s ∈ Ico K T, gap ν ((ω s).1) := by\n rw [Finset.range_eq_Ico, Finset.sum_Ico_consecutive _ (Nat.zero_le K) hKT]\n rw [hreg, hsplit, hwarmsum, hexploit]\n linarith\n\nend Deterministic\n\n/-! ### A telescoping estimate -/\n\nlemma sum_inv_sq_le (T : ℕ) : ∑ m ∈ Ico 1 T, (1 : ℝ) / ((m : ℝ) + 1) ^ 2 ≤ 1 := by\n rcases Nat.lt_or_ge T 1 with h | h\n · have : T = 0 := by omega\n simp [this]\n · have key : ∀ n : ℕ, 1 ≤ n → ∑ m ∈ Ico 1 n, (1 : ℝ) / ((m : ℝ) + 1) ^ 2 ≤ 1 - 1 / (n : ℝ) := by\n intro n hn\n induction n, hn using Nat.le_induction with\n | base => simp\n | succ n hn ih =>\n rw [Finset.sum_Ico_succ_top hn]\n have hn0 : (0 : ℝ) < (n : ℝ) := by exact_mod_cast hn\n have hstep : (1 : ℝ) / ((n : ℝ) + 1) ^ 2 ≤ 1 / (n : ℝ) - 1 / ((n : ℝ) + 1) := by\n rw [div_sub_div _ _ (ne_of_gt hn0) (by positivity),\n div_le_div_iff₀ (by positivity) (by positivity)]\n ring_nf\n nlinarith\n have hcast : ((n + 1 : ℕ) : ℝ) = (n : ℝ) + 1 := by push_cast; ring\n rw [hcast]\n linarith\n have h1 := key T h\n have h2 : (0 : ℝ) < (T : ℝ) := by exact_mod_cast h\n have : (0 : ℝ) < 1 / (T : ℝ) := by positivity\n linarith\n\n/-! ### The good event -/\n\nsection GoodEvent\n\nopen Preorder\nopen scoped ENNReal NNReal\n\nvariable {K : ℕ}\n\ntheorem good_event (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (hrewards : ∀ a, ∀ᵐ x ∂(ν a), x ∈ Set.Icc (0 : ℝ) 1)\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K) (hmeasA : ∀ n, Measurable (nextA n))\n (T : ℕ) (hT : 0 < T) (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1) (astar : Fin K) :\n ∃ Bad : Set (ℕ → Fin K × ℝ),\n trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν) Bad\n ≤ ENNReal.ofReal δ ∧\n ∀ ω, ω ∉ Bad →\n ((∀ (b : Fin K) (n : ℕ), 1 ≤ n → n < T → cntSω b n T ω = n →\n smSω b n T ω ≤ (n : ℝ) * (ν b)[id]\n + (n : ℝ) * Real.sqrt (Real.log (2 * K * T ^ 2 / δ) / (2 * n))) ∧\n (∀ (m : ℕ), 1 ≤ m → m < T → cntSω astar m T ω = m →\n (m : ℝ) * (ν astar)[id] - smSω astar m T ω\n ≤ (m : ℝ) * Real.sqrt (Real.log (2 * ((m : ℝ) + 1) ^ 2 / δ) / (2 * m)))) := by\n classical\n have hKR : (1 : ℝ) ≤ (K : ℝ) := by exact_mod_cast hK\n have hTR : (1 : ℝ) ≤ (T : ℝ) := by exact_mod_cast hT\n have hLarg : (2 : ℝ) ≤ 2 * (K : ℝ) * (T : ℝ) ^ 2 / δ := by\n rw [le_div_iff₀ hδ]; nlinarith [sq_nonneg ((T : ℝ) - 1)]\n have hLpos : 0 < Real.log (2 * (K : ℝ) * (T : ℝ) ^ 2 / δ) := Real.log_pos (by linarith)\n set L := Real.log (2 * (K : ℝ) * (T : ℝ) ^ 2 / δ) with hLdef\n set Lm : ℕ → ℝ := fun m ↦ Real.log (2 * ((m : ℝ) + 1) ^ 2 / δ) with hLmdef\n have hLmpos : ∀ m : ℕ, 1 ≤ m → 0 < Lm m := by\n intro m hm\n have hmR : (1 : ℝ) ≤ (m : ℝ) := by exact_mod_cast hm\n simp only [hLmdef]\n refine Real.log_pos ?_\n rw [lt_div_iff₀ hδ]\n nlinarith\n set g1 : ℕ → ℝ := fun n ↦ Real.sqrt (L / (2 * (n : ℝ))) with hg1def\n set g2 : ℕ → ℝ := fun m ↦ Real.sqrt (Lm m / (2 * (m : ℝ))) with hg2def\n set S1 : Fin K → ℕ → Set (ℕ → Fin K × ℝ) := fun b n ↦\n {ω | L ≤ (4 * g1 n) * (smSω b n T ω - (ν b)[id] * (cntSω b n T ω : ℝ))\n - (4 * g1 n) ^ 2 / 8 * (cntSω b n T ω : ℝ)} with hS1def\n set S2 : ℕ → Set (ℕ → Fin K × ℝ) := fun m ↦\n {ω | Lm m ≤ (-(4 * g2 m)) * (smSω astar m T ω - (ν astar)[id] * (cntSω astar m T ω : ℝ))\n - (-(4 * g2 m)) ^ 2 / 8 * (cntSω astar m T ω : ℝ)} with hS2def\n refine ⟨(⋃ b : Fin K, ⋃ n ∈ Finset.Ico 1 T, S1 b n) ∪ (⋃ m ∈ Finset.Ico 1 T, S2 m), ?_, ?_⟩\n · -- the union bound\n have hexpL : Real.exp (-L) = δ / (2 * (K : ℝ) * (T : ℝ) ^ 2) := by\n rw [hLdef, Real.exp_neg,\n Real.exp_log (by linarith : (0 : ℝ) < 2 * (K : ℝ) * (T : ℝ) ^ 2 / δ), inv_div]\n have hexpLm : ∀ m : ℕ, Real.exp (-(Lm m)) = δ / (2 * ((m : ℝ) + 1) ^ 2) := by\n intro m\n simp only [hLmdef]\n rw [Real.exp_neg, Real.exp_log (by positivity), inv_div]\n have hS1bound : ∀ (b : Fin K) (n : ℕ),\n trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν) (S1 b n)\n ≤ ENNReal.ofReal (δ / (2 * (K : ℝ) * (T : ℝ) ^ 2)) := by\n intro b n\n simp only [hS1def]\n refine le_trans (measure_tail_bound hK ν hrewards nextA hmeasA b (4 * g1 n) n T L) ?_\n rw [hexpL]\n have hS2bound : ∀ m : ℕ,\n trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν) (S2 m)\n ≤ ENNReal.ofReal (δ / (2 * ((m : ℝ) + 1) ^ 2)) := by\n intro m\n simp only [hS2def]\n refine le_trans\n (measure_tail_bound hK ν hrewards nextA hmeasA astar (-(4 * g2 m)) m T (Lm m)) ?_\n rw [hexpLm m]\n have hA : trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)\n (⋃ b : Fin K, ⋃ n ∈ Finset.Ico 1 T, S1 b n) ≤ ENNReal.ofReal (δ / 2) := by\n calc trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)\n (⋃ b : Fin K, ⋃ n ∈ Finset.Ico 1 T, S1 b n)\n ≤ ∑ b : Fin K, trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K))\n (stationaryEnv ν) (⋃ n ∈ Finset.Ico 1 T, S1 b n) :=\n measure_iUnion_fintype_le _ _\n _ ≤ ∑ b : Fin K, ∑ n ∈ Finset.Ico 1 T,\n trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K))\n (stationaryEnv ν) (S1 b n) :=\n Finset.sum_le_sum fun b _ ↦ measure_biUnion_finset_le _ _\n _ ≤ ∑ _b : Fin K, ∑ _n ∈ Finset.Ico 1 T,\n ENNReal.ofReal (δ / (2 * (K : ℝ) * (T : ℝ) ^ 2)) :=\n Finset.sum_le_sum fun b _ ↦ Finset.sum_le_sum fun n _ ↦ hS1bound b n\n _ = ENNReal.ofReal (∑ _b : Fin K, ∑ _n ∈ Finset.Ico 1 T,\n δ / (2 * (K : ℝ) * (T : ℝ) ^ 2)) := by\n rw [ENNReal.ofReal_sum_of_nonneg (fun b _ ↦ by positivity)]\n refine Finset.sum_congr rfl fun b _ ↦ ?_\n rw [ENNReal.ofReal_sum_of_nonneg (fun n _ ↦ by positivity)]\n _ ≤ ENNReal.ofReal (δ / 2) := by\n refine ENNReal.ofReal_le_ofReal ?_\n simp only [Finset.sum_const, Nat.card_Ico, Finset.card_univ, Fintype.card_fin,\n nsmul_eq_mul]\n have h1 : ((T - 1 : ℕ) : ℝ) ≤ (T : ℝ) := by exact_mod_cast Nat.sub_le T 1\n have h2 : (0 : ℝ) ≤ δ / (2 * (K : ℝ) * (T : ℝ) ^ 2) := by positivity\n calc (K : ℝ) * (((T - 1 : ℕ) : ℝ) * (δ / (2 * (K : ℝ) * (T : ℝ) ^ 2)))\n ≤ (K : ℝ) * ((T : ℝ) * (δ / (2 * (K : ℝ) * (T : ℝ) ^ 2))) := by\n exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right h1 h2)\n (by linarith)\n _ = δ / (2 * (T : ℝ)) := by field_simp\n _ ≤ δ / 2 := by\n rw [div_le_div_iff₀ (by linarith) (by norm_num)]\n nlinarith\n have hB : trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)\n (⋃ m ∈ Finset.Ico 1 T, S2 m) ≤ ENNReal.ofReal (δ / 2) := by\n calc trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)\n (⋃ m ∈ Finset.Ico 1 T, S2 m)\n ≤ ∑ m ∈ Finset.Ico 1 T, trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K))\n (stationaryEnv ν) (S2 m) := measure_biUnion_finset_le _ _\n _ ≤ ∑ m ∈ Finset.Ico 1 T, ENNReal.ofReal (δ / (2 * ((m : ℝ) + 1) ^ 2)) :=\n Finset.sum_le_sum fun m _ ↦ hS2bound m\n _ = ENNReal.ofReal (∑ m ∈ Finset.Ico 1 T, δ / (2 * ((m : ℝ) + 1) ^ 2)) := by\n rw [ENNReal.ofReal_sum_of_nonneg (fun m _ ↦ by positivity)]\n _ ≤ ENNReal.ofReal (δ / 2) := by\n refine ENNReal.ofReal_le_ofReal ?_\n have he : ∑ m ∈ Finset.Ico 1 T, δ / (2 * ((m : ℝ) + 1) ^ 2)\n = (δ / 2) * ∑ m ∈ Finset.Ico 1 T, (1 : ℝ) / ((m : ℝ) + 1) ^ 2 := by\n rw [Finset.mul_sum]\n refine Finset.sum_congr rfl fun m _ ↦ ?_\n have : ((m : ℝ) + 1) ^ 2 ≠ 0 := by positivity\n field_simp\n rw [he]\n have := sum_inv_sq_le T\n nlinarith [Finset.sum_nonneg (fun m (_ : m ∈ Finset.Ico 1 T) ↦\n (by positivity : (0:ℝ) ≤ (1 : ℝ) / ((m : ℝ) + 1) ^ 2))]\n calc trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)\n ((⋃ b : Fin K, ⋃ n ∈ Finset.Ico 1 T, S1 b n) ∪ (⋃ m ∈ Finset.Ico 1 T, S2 m))\n ≤ trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)\n (⋃ b : Fin K, ⋃ n ∈ Finset.Ico 1 T, S1 b n)\n + trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)\n (⋃ m ∈ Finset.Ico 1 T, S2 m) := measure_union_le _ _\n _ ≤ ENNReal.ofReal (δ / 2) + ENNReal.ofReal (δ / 2) := add_le_add hA hB\n _ = ENNReal.ofReal δ := by\n rw [← ENNReal.ofReal_add (by positivity) (by positivity)]\n norm_num\n · -- on the complement of the bad event both confidence bounds hold\n intro ω hω\n have hA' : ∀ (b : Fin K) (n : ℕ), n ∈ Finset.Ico 1 T → ω ∉ S1 b n := by\n intro b n hn hmem\n exact hω (Or.inl (Set.mem_iUnion.2 ⟨b, Set.mem_iUnion₂.2 ⟨n, hn, hmem⟩⟩))\n have hB' : ∀ m : ℕ, m ∈ Finset.Ico 1 T → ω ∉ S2 m := by\n intro m hm hmem\n exact hω (Or.inr (Set.mem_iUnion₂.2 ⟨m, hm, hmem⟩))\n constructor\n · intro b n hn1 hnT hcnt\n have hnot := hA' b n (Finset.mem_Ico.2 ⟨hn1, hnT⟩)\n simp only [hS1def, Set.mem_setOf_eq, not_le] at hnot\n rw [hcnt] at hnot\n have hnR : (0 : ℝ) < (n : ℝ) := by exact_mod_cast hn1\n have harg : 0 < L / (2 * (n : ℝ)) := by positivity\n have hg : 0 < g1 n := by simp only [hg1def]; exact Real.sqrt_pos.2 harg\n have hgsq : (g1 n) ^ 2 = L / (2 * (n : ℝ)) := by\n simp only [hg1def]; exact Real.sq_sqrt (le_of_lt harg)\n have hL2 : L = 2 * (n : ℝ) * (g1 n) ^ 2 := by rw [hgsq]; field_simp\n have key : (g1 n) * (smSω b n T ω - (ν b)[id] * (n : ℝ))\n < (g1 n) * ((n : ℝ) * g1 n) := by nlinarith [hnot, hL2]\n have hlt := lt_of_mul_lt_mul_left key (le_of_lt hg)\n have hfin : smSω b n T ω ≤ (n : ℝ) * (ν b)[id] + (n : ℝ) * (g1 n) := by nlinarith\n simpa only [hg1def] using hfin\n · intro m hm1 hmT hcnt\n have hnot := hB' m (Finset.mem_Ico.2 ⟨hm1, hmT⟩)\n simp only [hS2def, Set.mem_setOf_eq, not_le] at hnot\n rw [hcnt] at hnot\n have hmR : (0 : ℝ) < (m : ℝ) := by exact_mod_cast hm1\n have harg : 0 < Lm m / (2 * (m : ℝ)) := by\n have := hLmpos m hm1\n positivity\n have hg : 0 < g2 m := by simp only [hg2def]; exact Real.sqrt_pos.2 harg\n have hgsq : (g2 m) ^ 2 = Lm m / (2 * (m : ℝ)) := by\n simp only [hg2def]; exact Real.sq_sqrt (le_of_lt harg)\n have hL2 : Lm m = 2 * (m : ℝ) * (g2 m) ^ 2 := by rw [hgsq]; field_simp\n have key : (g2 m) * ((ν astar)[id] * (m : ℝ) - smSω astar m T ω)\n < (g2 m) * ((m : ℝ) * g2 m) := by nlinarith [hnot, hL2]\n have hlt := lt_of_mul_lt_mul_left key (le_of_lt hg)\n have hfin : (m : ℝ) * (ν astar)[id] - smSω astar m T ω ≤ (m : ℝ) * (g2 m) := by nlinarith\n simpa only [hg2def, hLmdef] using hfin\n\nend GoodEvent\n\nopen scoped ENNReal in\nlemma prob_ge_of_compl {α : Type*} [MeasurableSpace α] {μ : Measure α} [IsProbabilityMeasure μ]\n {S B : Set α} {r : ℝ≥0∞} (hsub : ∀ ω, ω ∉ B → ω ∈ S) (hB : μ B ≤ r) :\n 1 - r ≤ μ S := by\n have h1 : Sᶜ ⊆ B := by\n intro ω hω\n by_contra hcon\n exact hω (hsub ω hcon)\n rw [tsub_le_iff_right]\n calc (1 : ℝ≥0∞) = μ Set.univ := measure_univ.symm\n _ = μ (S ∪ Sᶜ) := by rw [Set.union_compl_self]\n _ ≤ μ S + μ Sᶜ := measure_union_le _ _\n _ ≤ μ S + r := by\n exact add_le_add (le_refl _) (le_trans (measure_mono h1) hB)\n\ntheorem ch16_theorem_16_7 {K : ℕ} (hK : 0 < K) (ν : Kernel (Fin K) ℝ) [IsMarkovKernel ν]\n (T : ℕ) (hKT : K ≤ T) (hT : 0 < T) (δ : ℝ) (hδ : 0 < δ) (hδ1 : δ ≤ 1)\n (hrewards : ∀ a, ∀ᵐ x ∂(ν a), x ∈ Set.Icc (0 : ℝ) 1)\n (nextA : (n : ℕ) → (Iic n → Fin K × ℝ) → Fin K)\n (hmeasA : ∀ n, Measurable (nextA n))\n (hwarm : ∀ n h, n < K - 1 → nextA n h = RoundRobin.nextAction hK n)\n (hargmax : ∀ n h a, K - 1 ≤ n →\n empMean' n h a + cHat δ n h a ≤ empMean' n h (nextA n h) + cHat δ n h (nextA n h)) :\n (trajMeasure (detAlgorithm nextA hmeasA ⟨0, hK⟩) (stationaryEnv ν))\n {ω : ℕ → Fin K × ℝ |\n regret ν (fun s ω => (ω s).1) T ω ≤\n (⨅ Δ₀ : {x : ℝ // 0 < x},\n ((T : ℝ) - K) * (Δ₀ : ℝ) +\n ∑ a : Fin K,\n Set.indicator {a' : Fin K | (Δ₀ : ℝ) < gap ν a'}\n (fun a' => 2 * Real.log (2 * K * T ^ 2 / δ) / gap ν a') a) +\n ∑ a : Fin K, gap ν a}\n ≥ ENNReal.ofReal (1 - δ) := by\n classical\n have hKne : Nonempty (Fin K) := Fin.pos_iff_nonempty.mp hK\n obtain ⟨astar, hastar⟩ := Finite.exists_max (fun b : Fin K ↦ (ν b)[id])\n obtain ⟨Bad, hBadmeas, hBadgood⟩ :=\n good_event hK ν hrewards nextA hmeasA T hT δ hδ hδ1 astar\n have hPprob : IsProbabilityMeasure\n (trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) := by\n rw [trajMeasure]; infer_instance\n set NotAct : Set (ℕ → Fin K × ℝ) := {ω | ¬((ω 0).1 = (⟨0, hK⟩ : Fin K) ∧\n ∀ n, (ω (n + 1)).1 = nextA n (Preorder.frestrictLe n ω))} with hNAdef\n have hae : ∀ᵐ ω ∂(trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)),\n (ω 0).1 = (⟨0, hK⟩ : Fin K) ∧\n ∀ n, (ω (n + 1)).1 = nextA n (Preorder.frestrictLe n ω) := by\n filter_upwards [ae_action_zero hK ν nextA hmeasA,\n (ae_all_iff.2 (fun n ↦ ae_action_succ hK ν nextA hmeasA n))] with ω h1 h2 using ⟨h1, h2⟩\n have hNA : (trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν))\n NotAct = 0 := ae_iff.1 hae\n rw [ge_iff_le, ENNReal.ofReal_sub 1 (le_of_lt hδ), ENNReal.ofReal_one]\n refine prob_ge_of_compl (B := NotAct ∪ Bad) ?_ ?_\n · intro ω hω\n simp only [Set.mem_union, not_or] at hω\n obtain ⟨hω1, hω2⟩ := hω\n have hstruct : (ω 0).1 = (⟨0, hK⟩ : Fin K) ∧\n ∀ n, (ω (n + 1)).1 = nextA n (Preorder.frestrictLe n ω) := by\n by_contra hcon\n exact hω1 hcon\n obtain ⟨hup, hlow⟩ := hBadgood ω hω2\n exact det_regret_bound hK ν T hKT hT δ hδ hδ1 hwarm hargmax astar hastar ω\n hstruct.1 hstruct.2 hup hlow\n · calc (trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν))\n (NotAct ∪ Bad)\n ≤ (trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) NotAct\n + (trajMeasure (detAlgorithm nextA hmeasA (⟨0, hK⟩ : Fin K)) (stationaryEnv ν)) Bad :=\n measure_union_le _ _\n _ ≤ 0 + ENNReal.ofReal δ := add_le_add (le_of_eq hNA) hBadmeas\n _ = ENNReal.ofReal δ := by rw [zero_add]\n\nend GraduateLevel\n"} +{"id": "ch5_theorem_5_13", "source": "Graduate-level", "targets": [{"label": "ch5_theorem_5_13", "decls": ["ch5_theorem_5_13"], "statement": "Consider a finite function class \\(\\mathcal{F} = \\{f_1, \\ldots, f_d\\}\\), and assume that for a distribution \\(\\mathcal{D}\\) and \\(p \\in [1, p]\\), \\(\\sup_{f \\in F} \\|f\\|_{L_p(\\mathcal{D})} \\leq A\\). Then for \\(\\epsilon \\leq A\\):\n\\[\n\\ln M(\\epsilon,\\operatorname{CONV}(\\mathcal{F}),L_{p}(\\mathcal{D}))\\leq d\\ln(3 A/\\epsilon).\n\\]", "topic_domain": "Statistical Learning Theory", "topic_subtopic": "Function Class Complexity"}], "nl_proof": "Let \\(B_{1} \\in R^{d}\\) be the \\(L_{1}\\) ball\n\\[\nB_{1}=\\left\\{q\\in R^{d}:\\|q\\|_{1}\\leq 1\\right\\}.\n\\]\nLet \\(Q = \\{q^1, \\ldots, q^M\\}\\) be a maximal \\(\\epsilon\\) \\(L_1\\) packing of \\(B_1\\). Theorem 5.3 implies that \\(M \\leq (3/\\epsilon)^d\\).\nNote that for any \\(q=[q_{1},\\ldots,q_{d}]\\in B_{1}\\) , let \\(q^{k}\\in Q\\) so that \\(\\| q - q^k\\| _1\\leq \\epsilon\\) , then\n\\[\n\\left[\\mathbb{E}_{Z\\sim\\mathcal{D}}\\left|\\sum_{j=1}^{d}q_{j}^{k}f_{j}(Z)-\\sum_{j=1}^{d}q_{j}f_{j}(Z)\\right|^{p}\\right]^{1/p}\\leq\\epsilon A.\n\\]\nTherefore \\(\\left\\{\\sum_{j=1}^{d} q_{j}^{k} f_{j}: k = 1, \\ldots, N\\right\\}\\) is an \\(\\epsilon A\\) \\(L_{p}\\)-cover of \\(\\mathrm{CONV}(F)\\). The result follows.", "context": [{"id": "ch5:theorem:5_3", "name": "theorem 5.3", "statement": "Let \\(\\| \\cdot \\|\\) be a seminorm on \\(\\mathbb{R}^k\\). Let \\(B(r) = \\{z \\in \\mathbb{R}^k : \\| z \\| \\leq r\\}\\) be the \\(\\| \\cdot \\|\\)-ball with radius \\(r\\). Then\n\\[\nM(\\epsilon,B(r),\\|\\cdot\\|)\\leq\\left(1+2 r/\\epsilon\\right)^{k}.\n\\]\nMoreover, if \\(\\| \\cdot \\|\\) is a norm, then\n\\[\nN(\\epsilon,B(r),\\|\\cdot\\|)\\geq(r/\\epsilon)^{k}.\n\\]"}, {"id": "ch5:definition:5_12", "name": "definition 5.12", "statement": "The convex hull of a function class \\(\\mathcal{F} = \\{f(\\theta, x) : \\theta \\in \\Theta\\}\\) is defined as\n\\[\n\\operatorname{CONV}(\\mathcal{F})=\\left\\{\\sum_{j=1}^{m}w_{j}f\\left(\\theta_{j},x\\right):m>0,\\|w\\|_{1}=1,w_{j}\\geq 0,\\theta_{j}\\in\\Theta\\right\\}.\n\\]\nWe also include the closure of the finite sum functions above with respect to an appropriate topology in the convex hull."}, {"id": "ch5:definition:5_1", "name": "Packing Number", "statement": "Let \\((\\mathcal{V},d)\\) be a pseudometric space with metric \\(d(\\cdot,\\cdot)\\). A finite subset \\(\\mathcal{G}(\\epsilon)\\subset \\mathcal{G}\\) is an \\(\\epsilon\\)-packing of \\(\\mathcal{G}\\) if \\(d(\\phi,\\phi^{\\prime})>\\epsilon\\) for all \\(\\phi,\\phi^{\\prime}\\in\\mathcal{G}(\\epsilon)\\). The \\(\\epsilon\\)-packing number of \\(\\mathcal{G}\\), denoted by \\(M(\\epsilon,\\mathcal{G},d)\\), is the largest cardinality of \\(\\epsilon\\)-packing of \\(\\mathcal{G}\\).\nThe following results illustrate the equivalence between covering number and packing number. One advantage of using an \\(\\epsilon\\) packing of \\(\\mathcal{G}\\) instead of an \\(\\epsilon\\) cover of \\(\\mathcal{G}\\) is that all members in the \\(\\epsilon\\) packing also belong to \\(\\mathcal{G}\\). There if members in \\(\\mathcal{G}\\) satisfy certain assumptions such as the variance condition, then members of its \\(\\epsilon\\) packing also satisfy such assumptions. For this reason, we will use packing numbers instead of covering numbers in some of the theoretical analysis in later chapters."}, {"id": "ch3:definition:3_27", "name": "Bracketing Number", "statement": "Let \\(\\mathcal{G} = \\{\\phi(w, \\cdot) : w \\in \\Omega\\}\\) be a real-valued function class, equipped with a pseudometric \\(d\\). We say\n\\[\n\\mathcal{G}(\\epsilon)=\\left\\{\\left[\\phi_{1}^{L}(z),\\phi_{1}^{U}(z)\\right],\\dots,\\left[\\phi_{N}^{L}(z),\\phi_{N}^{U}(z)\\right]\\right\\}\n\\]\nis an \\(\\epsilon\\)-bracket of \\(\\mathcal{G}\\) under metric \\(d\\) if for all \\(w \\in \\Omega\\), there exists \\(j = j(w)\\) such that \\(\\forall z\\):\n\\[\n\\phi_{j}^{L}(z)\\leq\\phi(w,z)\\leq\\phi_{j}^{U}(z),\\quad d(\\phi_{j}^{L},\\phi_{j}^{U})\\leq\\epsilon .\n\\]\nThe \\(\\epsilon\\)-bracketing number is the smallest cardinality \\(N_{\\mathbb{I}}(\\epsilon, \\mathcal{G}, d)\\) of such \\(\\mathcal{G}(\\epsilon)\\). The quantity \\(\\ln N_{\\mathbb{I}}(\\epsilon, \\mathcal{G}, d)\\) is called \\(\\epsilon\\) bracketing entropy.\nIn particular, given a distribution \\(\\mathcal{D}\\) and \\(p \\geq 1\\), we define \\(L_{p}\\)-seminorm in function space as\n\\[\n\\left\\|f-f^{\\prime}\\right\\|_{L_{p}(\\mathcal{D})}=\\left[\\mathbb{E}_{Z\\sim\\mathcal{D}}|f(Z)-f^{\\prime}(Z)|^{p}\\right]^{1/p}.\\tag{3.19}\n\\]\nIt induces a pseudometric, denoted as \\( d = L_{p}(\\mathcal{D}) \\), and the corresponding bracketing number is \\( N_{\\parallel}(\\epsilon, \\mathcal{G}, L_{p}(\\mathcal{D})) \\).\nFor \\(p = \\infty\\), the \\(L_{\\infty}(\\mathcal{D})\\)-seminorm is defined as the essential supremum seminorm, which leads to the pseudometric\n\\[\nd(f,f^{\\prime})=\\inf\\left\\{\\omega:\\Pr_{\\mathcal{D}}[|f(Z)-f^{\\prime}(Z)|\\leq\\omega]=1\\right\\}.\n\\]\nHowever, when \\( p = \\infty \\), instead of using the \\( L_{\\infty} \\) bracketing number, it is more conventional to use the equivalent notion of \\( L_{\\infty} \\) covering number (see Proposition 4.3)."}], "lean": "import Mathlib\n\nopen MeasureTheory Real ENNReal\n\nnamespace GraduateLevel\n\ndef IsPacking {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n ↑t ⊆ s ∧ (↑t : Set A).Pairwise fun x y => eps < dist x y\n\ntheorem ch5_theorem_5_13\n {Ω : Type*} [MeasurableSpace Ω]\n (D : Measure Ω) [IsProbabilityMeasure D]\n (d : ℕ)\n (p : ℝ≥0∞) [Fact (1 ≤ p)] (hp_top : p ≠ ⊤)\n (f : Fin d → Lp ℝ p D)\n (A : ℝ) (hA : 0 < A)\n (hbound : ∀ j, ‖f j‖ ≤ A)\n (ε : ℝ) (hε : 0 < ε) (hεA : ε ≤ A)\n (Q : Finset (Lp ℝ p D))\n (hQpack : IsPacking Q ε (convexHull ℝ (Set.range f))) :\n Real.log (Q.card : ℝ) ≤ (d : ℝ) * Real.log (3 * A / ε) := sorry\n\nend GraduateLevel\n", "solution": "import Mathlib\n\nopen MeasureTheory Real ENNReal\n\nnamespace GraduateLevel\n\ndef IsPacking {A : Type*} [PseudoMetricSpace A] (t : Finset A) (eps : ℝ) (s : Set A) : Prop :=\n ↑t ⊆ s ∧ (↑t : Set A).Pairwise fun x y => eps < dist x y\n\nprivate theorem card_le_volume_bound\n {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E]\n (s : Finset E) (A ε : ℝ) (hA : 0 < A) (hε : 0 < ε) (hεA : ε ≤ A)\n (hs : ∀ x ∈ s, ‖x‖ ≤ A)\n (hsep : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → ε < ‖x - y‖) :\n (s.card : ℝ) ≤ (3 * A / ε) ^ Module.finrank ℝ E := by\n borelize E\n let μ : Measure E := Measure.addHaar\n let δ : ℝ := ε / 2\n let ρ : ℝ := 3 * A / 2\n have hδ : 0 < δ := by dsimp [δ]; linarith\n have hρ : 0 < ρ := by dsimp [ρ]; linarith\n set U := ⋃ x ∈ s, Metric.ball (x : E) δ with hU\n have hdisj : Set.Pairwise (s : Set E)\n (Function.onFun Disjoint fun x => Metric.ball (x : E) δ) := by\n rintro x hx y hy hxy\n apply Metric.ball_disjoint_ball\n rw [dist_eq_norm]\n have h := hsep x hx y hy hxy\n dsimp [δ]\n linarith\n have hsub : U ⊆ Metric.ball (0 : E) ρ := by\n rw [hU]\n refine Set.iUnion₂_subset fun x hx => ?_\n apply Metric.ball_subset_ball'\n calc\n δ + dist x 0 ≤ δ + A := by\n rw [dist_zero_right]\n gcongr\n exact hs x hx\n _ ≤ ρ := by\n dsimp [δ, ρ]\n linarith\n have hmeasure :\n (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ Module.finrank ℝ E) *\n μ (Metric.ball 0 1) ≤\n ENNReal.ofReal (ρ ^ Module.finrank ℝ E) * μ (Metric.ball 0 1) := by\n calc\n (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ Module.finrank ℝ E) *\n μ (Metric.ball 0 1) =\n μ U := by\n rw [hU, measure_biUnion_finset hdisj fun x _ => measurableSet_ball]\n simp only [μ.addHaar_ball_of_pos _ hδ]\n simp only [Finset.sum_const, nsmul_eq_mul, mul_assoc]\n _ ≤ μ (Metric.ball (0 : E) ρ) := measure_mono hsub\n _ = ENNReal.ofReal (ρ ^ Module.finrank ℝ E) * μ (Metric.ball 0 1) := by\n simp only [μ.addHaar_ball_of_pos _ hρ]\n have hcancel :\n (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ Module.finrank ℝ E) ≤\n ENNReal.ofReal (ρ ^ Module.finrank ℝ E) :=\n (ENNReal.mul_le_mul_iff_left\n (Metric.measure_ball_pos μ (0 : E) zero_lt_one).ne'\n (measure_ball_lt_top (μ := μ) (x := (0 : E)) (r := 1)).ne).1 hmeasure\n have hreal :\n (s.card : ℝ) * δ ^ Module.finrank ℝ E ≤ ρ ^ Module.finrank ℝ E := by\n have := (ENNReal.toReal_le_toReal\n (ENNReal.mul_ne_top (ENNReal.natCast_ne_top s.card)\n (ENNReal.ofReal_ne_top :\n ENNReal.ofReal (δ ^ Module.finrank ℝ E) ≠ ⊤))\n (ENNReal.ofReal_ne_top :\n ENNReal.ofReal (ρ ^ Module.finrank ℝ E) ≠ ⊤)).2 hcancel\n simpa [ENNReal.toReal_mul, hδ.le, hρ.le] using this\n have hδpow : 0 < δ ^ Module.finrank ℝ E := pow_pos hδ _\n calc\n (s.card : ℝ) ≤ ρ ^ Module.finrank ℝ E / δ ^ Module.finrank ℝ E :=\n (le_div_iff₀ hδpow).2 hreal\n _ = (3 * A / ε) ^ Module.finrank ℝ E := by\n rw [← div_pow]\n dsimp [ρ, δ]\n congr 1\n field_simp\n\ntheorem ch5_theorem_5_13\n {Ω : Type*} [MeasurableSpace Ω]\n (D : Measure Ω) [IsProbabilityMeasure D]\n (d : ℕ)\n (p : ℝ≥0∞) [Fact (1 ≤ p)] (hp_top : p ≠ ⊤)\n (f : Fin d → Lp ℝ p D)\n (A : ℝ) (hA : 0 < A)\n (hbound : ∀ j, ‖f j‖ ≤ A)\n (ε : ℝ) (hε : 0 < ε) (hεA : ε ≤ A)\n (Q : Finset (Lp ℝ p D))\n (hQpack : IsPacking Q ε (convexHull ℝ (Set.range f))) :\n Real.log (Q.card : ℝ) ≤ (d : ℝ) * Real.log (3 * A / ε) := by\n classical\n let V : Submodule ℝ (Lp ℝ p D) := Submodule.span ℝ (Set.range f)\n letI : FiniteDimensional ℝ V := by\n dsimp [V]\n exact FiniteDimensional.span_of_finite ℝ (Set.finite_range f)\n have hconv_span : convexHull ℝ (Set.range f) ⊆ (V : Set (Lp ℝ p D)) := by\n apply convexHull_min\n · exact Submodule.subset_span\n · exact V.convex\n have hconv_ball :\n convexHull ℝ (Set.range f) ⊆ Metric.closedBall (0 : Lp ℝ p D) A := by\n apply convexHull_min\n · rintro x ⟨j, rfl⟩\n exact mem_closedBall_zero_iff.mpr (hbound j)\n · exact convex_closedBall 0 A\n let emb : {x // x ∈ Q} ↪ V :=\n { toFun := fun q => ⟨q.1, hconv_span (hQpack.1 q.2)⟩\n inj' := by\n intro x y h\n cases x with\n | mk x hx =>\n cases y with\n | mk y hy =>\n simp_all }\n let s : Finset V := Q.attach.map emb\n have hscard : s.card = Q.card := by\n simp [s]\n have hs_norm : ∀ x ∈ s, ‖x‖ ≤ A := by\n intro x hx\n rw [Finset.mem_map] at hx\n obtain ⟨q, hq, rfl⟩ := hx\n change ‖(q.1 : Lp ℝ p D)‖ ≤ A\n exact mem_closedBall_zero_iff.mp (hconv_ball (hQpack.1 q.2))\n have hs_sep : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → ε < ‖x - y‖ := by\n intro x hx y hy hxy\n rw [Finset.mem_map] at hx hy\n obtain ⟨q, hq, rfl⟩ := hx\n obtain ⟨r, hr, rfl⟩ := hy\n have hqr : q.1 ≠ r.1 := by\n intro h\n apply hxy\n apply Subtype.ext\n exact h\n simpa [dist_eq_norm] using hQpack.2 q.2 r.2 hqr\n let F : Finset (Lp ℝ p D) := Finset.univ.image f\n have hFrange : (↑F : Set (Lp ℝ p D)) = Set.range f := by\n ext x\n simp [F]\n have hfinrank : Module.finrank ℝ V ≤ d := by\n change Module.finrank ℝ (Submodule.span ℝ (Set.range f)) ≤ d\n rw [← hFrange]\n exact (finrank_span_finset_le_card F).trans\n (Finset.card_image_le.trans (by simp))\n have hcard :\n (Q.card : ℝ) ≤ (3 * A / ε) ^ Module.finrank ℝ V := by\n rw [← hscard]\n exact card_le_volume_bound s A ε hA hε hεA hs_norm hs_sep\n have hbase : 1 ≤ 3 * A / ε := by\n apply (le_div_iff₀ hε).2\n linarith\n have hlogbase : 0 ≤ Real.log (3 * A / ε) := Real.log_nonneg hbase\n by_cases hQ : Q = ∅\n · subst Q\n simp only [Finset.card_empty, Nat.cast_zero, Real.log_zero]\n exact mul_nonneg (Nat.cast_nonneg d) hlogbase\n · have hcardpos : 0 < (Q.card : ℝ) := by\n exact_mod_cast Finset.card_pos.mpr (Finset.nonempty_iff_ne_empty.mpr hQ)\n calc\n Real.log (Q.card : ℝ) ≤\n Real.log ((3 * A / ε) ^ Module.finrank ℝ V) :=\n Real.log_le_log hcardpos hcard\n _ = (Module.finrank ℝ V : ℝ) * Real.log (3 * A / ε) := by\n rw [Real.log_pow]\n _ ≤ (d : ℝ) * Real.log (3 * A / ε) := by\n exact mul_le_mul_of_nonneg_right (by exact_mod_cast hfinrank) hlogbase\n\nend GraduateLevel\n"}