[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"BLisql9GPu":3},"# Flashlight transformation in Lean 4\n\n[![Lean Action CI](https://github.com/asnelt/flashlight/actions/workflows/lean_action_ci.yml/badge.svg)](https://github.com/asnelt/flashlight/actions/workflows/lean_action_ci.yml)\n[![Documentation](https://img.shields.io/badge/docs-API-blue)](https://asnelt.github.io/flashlight/docs)\n\nA [Lean 4](https://lean-lang.org/) / [Mathlib](https://github.com/leanprover-community/mathlib4)\nformalization of the theorem on the *flashlight transformation* of copulas from\n\n> A. Onken, S. Grünewälder, M. H. J. Munk, K. Obermayer (2009).\n> Analyzing Short-Term Noise Dependencies of Spike-Counts in Macaque Prefrontal Cortex Using\n> Copulas and the Flashlight Transformation.\n> *PLoS Computational Biology* 5(11): e1000577.\n> \u003Chttps://doi.org/10.1371/journal.pcbi.1000577>\n\nThe informal proof is given in the supplementary\n[Text S1](https://doi.org/10.1371/journal.pcbi.1000577.s001).\n\n## The theorem\n\nLet `C` be a `d`-copula that is the distribution function of a random vector `U` on `[0,1]^d`,\nand let `S ⊆ {1, …, d}`. Then the flashlight transformation\n\n```\nC^F_S(u) := P((⋂_{i ∈ S} {U_i > 1 - u_i}) ∩ (⋂_{i ∉ S} {U_i ≤ u_i}))\n```\n\nis again a copula, and\n\n```\nC^F_S(u) = ∑_{A ⊆ S} (-1)^|A| C(κ_{S,A}(1, u), …, κ_{S,A}(d, u)),\n```\n\nwhere `κ_{S,A}(i, u)` is `1 - u_i` for `i ∈ A`, `1` for `i ∈ S \\ A`, and `u_i` for `i ∉ S`.\n\nIn Lean, this is `Flashlight.flashlight` in [`Flashlight.lean`](Flashlight.lean):\n\n```lean\ntheorem flashlight (μ : Measure (ι → ℝ)) [IsProbabilityMeasure μ]\n    {C : (ι → ℝ) → ℝ} (hC : IsCopula C)\n    (hμ : ∀ u ∈ unitCube ι, C u = μ.real {x | ∀ i, x i ≤ u i}) (S : Finset ι) :\n    IsCopula (flashlightMeasure μ S) ∧\n      ∀ u ∈ unitCube ι,\n        flashlightMeasure μ S u = ∑ A ∈ S.powerset, (-1) ^ #A * C (kappa S A u)\n```\n\nThe index set `{1, …, d}` is modeled by an arbitrary finite type `ι`. `IsCopula` requires the\nfunction to satisfy `C(1, …, 1) = 1`, to be grounded, to have uniform marginal distributions and\nto be `d`-increasing on `[0,1]^ι`.\n\n### Proof structure\n\nThe formalization follows the proof in Text S1:\n\n* **Lemma** (`restrictMeasure`): `P^A := P(• ∩ A)` is a measure.\n* **Flashlight formula** (`flashlightMeasure_eq_flashlightSum`): a `calc` chain.\n* **Copula properties** (`isCopula_flashlightSum`): normalization, groundedness,\n  uniform marginal distributions and `d`-increasing property.\n\nOne step of the original proof is made explicit. Identifying\n`P_U((⋂_{i ∈ A} {U_i ≤ 1 - u_i}) ∩ (⋂_{i ∈ S̄} {U_i ≤ u_i}))` with `C(κ_{S,A}(1, u), …)`\nreplaces the events `{U_i ≤ 1}`, `i ∈ S \\ A`, by the whole space. This is justified in\n`measure_compl_le_one_eq_zero` and `measureReal_eq_kappa`: since `C(1, …, 1) = 1`, the event\n`⋂_i {U_i ≤ 1}` has probability one.\n\nThe proof uses no axioms beyond the standard ones (`propext`, `Classical.choice`, `Quot.sound`).\n\n## Building\n\nInstall Lean via [elan](https://github.com/leanprover/elan), then run:\n\n```bash\ngit clone https://github.com/asnelt/flashlight.git\ncd flashlight\nlake exe cache get\nlake build\n```\n\n## Documentation\n\nThe API documentation is generated by CI and published at \u003Chttps://asnelt.github.io/flashlight/docs>.\n\n## Citation\n\nIf you use this formalization, please cite the original paper (see [`CITATION.cff`](CITATION.cff)).\n\n## License\n\n[Apache License 2.0](LICENSE)\n",1793400801262]