diff --git a/research/p104-native-ceiling/CHECK.txt b/research/p104-native-ceiling/CHECK.txt new file mode 100644 index 0000000000..d01349c353 --- /dev/null +++ b/research/p104-native-ceiling/CHECK.txt @@ -0,0 +1,71 @@ +CHECK.txt: fresh build of the import closure of Nov15/CongestionNativeH.lean (38 modules) +Toolchain leanprover/lean4:v4.33.0-rc1; Mathlib 55b7917b472489c7c56a0fa6393af05cfd536599 (an existing build of that commit, no download). + +METHOD + * Every module compiled ALONE in dependency order, one lean process at a time: lean -j1 -o out/Nov15/X.olean Nov15/X.lean from lean/, under a 3.5 GB (3,500,000 KB) RSS watcher. + * A fresh, initially empty output directory was FIRST on the module search path, so every import of every module resolved to an olean built in this run, then the pinned Mathlib packages. + * Axioms: the #print axioms lines inside the files. Union over all modules: {propext, Classical.choice, Quot.sound}; no Lean.ofReduceBool, no sorryAx, no 'declaration uses sorry' in any log. + * lake build was not run (it would download Mathlib). + +COMPILE TABLE (module, rc, wall, peak RSS, errors, sorry warnings), build order +CallerCost rc=0 time=13s peak=2993MB errors=0 sorry_warnings=0 +CongestionI3Data rc=0 time=4s peak=1327MB errors=0 sorry_warnings=0 +CongestionI3Cfg rc=0 time=69s peak=0MB errors=0 sorry_warnings=0 +CongestionI3Mu rc=0 time=5s peak=1299MB errors=0 sorry_warnings=0 +NumCertK rc=0 time=19s peak=2951MB errors=0 sorry_warnings=0 +CongestionI3NumA rc=0 time=24s peak=3139MB errors=0 sorry_warnings=0 +CongestionI3NumC1 rc=0 time=25s peak=3144MB errors=0 sorry_warnings=0 +CongestionI3NumC2 rc=0 time=24s peak=3033MB errors=0 sorry_warnings=0 +CongestionI3NumC3 rc=0 time=23s peak=3107MB errors=0 sorry_warnings=0 +CongestionI3NumC4 rc=0 time=16s peak=2869MB errors=0 sorry_warnings=0 +WholeFloorCoverData1 rc=0 time=26s peak=3046MB errors=0 sorry_warnings=0 +WholeFloorCoverData rc=0 time=39s peak=3244MB errors=0 sorry_warnings=0 +JointCeiling rc=0 time=18s peak=2996MB errors=0 sorry_warnings=0 +WholeFloorCover rc=0 time=9s peak=2873MB errors=0 sorry_warnings=0 +CongestionI3 rc=0 time=20s peak=2959MB errors=0 sorry_warnings=0 +TokenCancel rc=0 time=8s peak=1650MB errors=0 sorry_warnings=0 +FrameSep rc=0 time=5s peak=1503MB errors=0 sorry_warnings=0 +JunkLB2 rc=0 time=17s peak=2466MB errors=0 sorry_warnings=0 +RelaySandwich rc=0 time=6s peak=2323MB errors=0 sorry_warnings=0 +RankLaw rc=0 time=9s peak=2053MB errors=0 sorry_warnings=0 +RankLawC rc=0 time=6s peak=1991MB errors=0 sorry_warnings=0 +SwapWord rc=0 time=7s peak=2001MB errors=0 sorry_warnings=0 +SwapNull rc=0 time=11s peak=2455MB errors=0 sorry_warnings=0 +FibreK rc=0 time=10s peak=2941MB errors=0 sorry_warnings=0 +WordDuality rc=0 time=10s peak=2940MB errors=0 sorry_warnings=0 +CongestionI3DualAlg rc=0 time=8s peak=2877MB errors=0 sorry_warnings=0 +CongestionI3DualConst rc=0 time=4s peak=1124MB errors=0 sorry_warnings=0 +CongestionI3DualSig rc=0 time=8s peak=2909MB errors=0 sorry_warnings=0 +CongestionI3DualCertC0 rc=0 time=9s peak=3161MB errors=0 sorry_warnings=0 +CongestionI3DualCertC1 rc=0 time=9s peak=3184MB errors=0 sorry_warnings=0 +CongestionI3DualCertC2 rc=0 time=9s peak=3151MB errors=0 sorry_warnings=0 +CongestionI3DualCertC3 rc=0 time=9s peak=3198MB errors=0 sorry_warnings=0 +CongestionI3DualData rc=0 time=7s peak=2291MB errors=0 sorry_warnings=0 +CongestionI3DualNumC rc=0 time=18s peak=2941MB errors=0 sorry_warnings=0 +CongestionNativeTab rc=0 time=5s peak=1348MB errors=0 sorry_warnings=0 +CongestionNative rc=0 time=18s peak=2995MB errors=0 sorry_warnings=0 +PathCut rc=0 time=5s peak=1433MB errors=0 sorry_warnings=0 +CongestionNativeH rc=0 time=10s peak=2986MB errors=0 sorry_warnings=0 + +AXIOMS of the main theorems +'CongestionI3Dual.dualH_charge' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionI3Dual.gs_subadd' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionI3Dual.k0_eq_h9_swapN' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionI3Dual.nonmixed_charge' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionI3Dual.sum_all_c2_le' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionI3Dual.sum_c2_le' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionNative.branchC_om' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionNative.ceiling_native' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionNative.E_lower_cap_om' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionNative.hcong_of_capclass' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionNative.tab_piece' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionNative.unit_mono' depends on axioms: [propext, Classical.choice, Quot.sound] +'CongestionNativeH.ceiling_native'' depends on axioms: [propext, Classical.choice, Quot.sound] +'PathCut.nested_needed' depends on axioms: [propext, Classical.choice, Quot.sound] +'PathCut.path_cut' depends on axioms: [propext, Classical.choice, Quot.sound] +'PathCut.transported_card_le' depends on axioms: [propext, Classical.choice, Quot.sound] + +AXIOM UNION over all 38 logs + 143 [propext, Classical.choice, Quot.sound] + 12 [propext, Quot.sound] + 2 [propext] diff --git a/research/p104-native-ceiling/LICENSE b/research/p104-native-ceiling/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/research/p104-native-ceiling/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/research/p104-native-ceiling/NATIVES.md b/research/p104-native-ceiling/NATIVES.md new file mode 100644 index 0000000000..8367cc3579 --- /dev/null +++ b/research/p104-native-ceiling/NATIVES.md @@ -0,0 +1,26 @@ +# NATIVES: which premises of the Lean ceiling the three native words meet, and how that was computed + +Words: `st1`, `#7637`, `x1t2a` (the current frontier words; they share one owned layer and one port set of 104 odd-weight vectors, so this is closer to one data point than three). Lean treats every object in `ceiling_native'` as abstract. **Nothing in Lean ties a word to these hypotheses.** The checks below are exact computations by Python scripts (exact modular arithmetic, exact integers or outward-rounded Decimal), run on the word files; the scripts and word files are not part of this package. "Value" = the premise as computed, not a Lean fact. + +Honest summary: word-level premises are computed; hcong*, hdist, hspMono, hcstMono (now derived from the shape-DAG hypotheses of `CongestionNativeH`) and hst are paper theorems whose premises the natives meet. In the current Lean, `hspMono`/`hcstMono` are derived (CongestionNativeH `spShape_mono`, `cstShape_mono`, from `c2_anti`) and `hst` is still a hypothesis whose analytic proof (phi(a,b) = a^s + b^s - (a+b)^s increasing in a) is on paper only; `hdist` is derived from the new hypothesis `hdistShape`, `hcong*` from the per-cell path hypotheses (`hconf`, `hstart`, `hvisit`, `hleg`, `hclass`). + +| Lean premise | what the natives satisfy (value) | computed by | words | +|---|---|---|---| +| hmono, hd9 (public registers ascend, end at most 9) | 0 violations of either | exact replay of the program, structural audit (`aud2a`) | st1, #7637, x1t2a | +| hmix (at most 5 mixed registers) | exactly 5: [1,3], [5,7], [1,4,7], [1,2,3,6,8], [3,7,8] | `aud2a` | all three | +| hk, hmass, hmd, hmr (ks = 24 descents + 13 non-unit rises, mr = 10 unit rises) | all ranks in [1,6]; sum 102 >= 56; length 37 >= 8; mr 10 >= 8 | `hc6`, `aud2a` | all three | +| hY (104 <= st + (len ks + mr)) | st = 1266 / 1266 / 1265, so 1313 / 1313 / 1312 >= 104 | `hc6`, `aud2a` | all three | +| hF (F-currency inequality, exact) | the exponential-polynomial coefficients on both sides are identical integers (difference {}), so equality holds for every real s | `hc13` (`hF`), `hc6` | all three | +| hEex (sum of register excesses <= E) | E is defined as that same exponential polynomial (identity) | `hc13`, `hc6` | all three | +| hst ((2 - 2^s) st <= E) | premises computed: every public gap >= 1 and every main moves; st = 1266 / 1266 / 1265; grid slack 158.3 / 159.4 / 158.2 (zero only at s = 1) | `hc13`, `hc6` | all three | +| hJ (1936 <= \|J\|) | \|J^arr\| = 4962 on all three (2536 forced cells on the route flags) | `hc12` (exact mod 2^61-1), `hc11` | all three | +| hconf, hstart, hpub, hnest (per-cell chart paths) | public moves are nested strict ascents (6124); 47 owned moves, all nested (23 up, 24 down); every one of the 4962 cells has a legal (u_s in every chart) owned-descent-free, hence ascending and D-confined, path; 0 cells need a cut | `hc12`, `aud2a`, `aud2b` | all three | +| hvisit, h48 (visits and the 48-law) | the 24 transport frames have max n*m = 24, total even-cell capacity 204; max n*m = 48 over all subspaces of F2^9 in the census | `hc8` (natives' frames), `aud2d` (exhaustive census) | all three (frames); census word-independent | +| hleg, hclass (Cap class) | Cap margin Omega - cst (Rm - 8) - U Nf >= 19.35 on s in [.9, 1 - tC0] (Omega 47.995, Nf 24, Rm 56); by the Jt = 0 route the margin is about 45 | `hc13` (certified, 2000 pieces), `hc2`, `hc1` | all three | +| hdistShape, hspShape, hcstShape (the shape DAG) | spF is a minimum of c2-weighted sums over the 230 shapes (n >= 1, m >= 1, plus duals) of the census of subspaces of F2^9 for the natives' 104-port set; the shape list was re-derived independently by exhaustive enumeration of all 8,283,456 subspaces of dimensions 1 to 8 and is identical (230 = 230, histograms equal) | `hc9` (outward-rounded), independent census program | word-independent; port set identical for all three | +| hspTab, hcstTab, hunitTab (rational tables) | all table entries certified: slack about 1e-9 (spFlo) and about 2e-6 (C pieces) | `hc9` (Decimal at 80 digits, weights rounded down, constants rounded up) | word-independent | +| rank 8, descent mass C = 56 (the premise behind hJ) | the 8 routes have rank 8 and mass 56 (computed); the numerical rigidity of the decoder matrix does not hold exactly (6 mismatches), so "the native decoder is the enumerated configuration" holds for supports only | `hc8` | all three | +| span law (the legality the natives actually obey) | 0 span-law failures over 7906 / 7925 / 7902 route checkpoints; the per-port form of legality is false on the natives (1277 to 1280 rows with per-port illegal content) | `hc14` | st1 / #7637 / x1t2a | + +Not computed on a word and not in Lean: the class-wide bound |J| >= 1936 for decoders that are not rank 8, C = 56 (**a conjecture**), plane separation, and decoders with 9 or more rows or network decoders. For the natives the value is computed (4962), not bounded. +The link from the Lean `n` and `caller 6 7` / 17 to each word's invoice is the pricing script's, not Lean's. diff --git a/research/p104-native-ceiling/PROVED.md b/research/p104-native-ceiling/PROVED.md new file mode 100644 index 0000000000..535310d0c8 --- /dev/null +++ b/research/p104-native-ceiling/PROVED.md @@ -0,0 +1,306 @@ +# PROVED: statements of the main theorems, copied from the Lean sources + +Generated by a script that copies each statement (everything before `:=`) verbatim from `lean/Nov15/*.lean`. The Lean text is authoritative; every hypothesis in a statement is a hypothesis. All theorems below print axioms [propext, Classical.choice, Quot.sound] (CHECK.txt). Nothing here is a statement about a particular word: the objects `R, nR, dR, n, ks, mr, st, E, J, distF, spF, cstF, c, G, V, cells, ...` are abstract. + +## PathCut + +```lean +theorem path_cut {α : Type*} [Preorder α] (c : ℕ → α) (n : ℕ) (Hold : α → Prop) (G : α) (owned : ℕ → Prop) + (hHold : ∀ C C' : α, C ≤ C' → Hold C → Hold C') + (hpub : ∀ i < n, ¬ owned i → c i ≤ c (i + 1)) + (hnest : ∀ i < n, owned i → (c i ≤ c (i + 1) ∨ c (i + 1) ≤ c i)) + (hconf : ∀ i ≤ n, c i ≤ G) (hstart : Hold (c 0)) : + (∀ i ≤ n, Hold (c i)) ∨ + ∃ i < n, owned i ∧ Hold (c i) ∧ ¬ Hold (c (i + 1)) ∧ c (i + 1) < c i ∧ c i ≤ G ∧ ∀ j ≤ i, Hold (c j) +``` + +```lean +theorem nested_needed : ∃ (c : ℕ → Finset ℕ) (Hold : Finset ℕ → Prop) (G : Finset ℕ) (owned : ℕ → Prop), + (∀ C C' : Finset ℕ, C ≤ C' → Hold C → Hold C') ∧ (∀ i < 1, ¬ owned i → c i ≤ c (i + 1)) ∧ + (∀ i ≤ 1, c i ≤ G) ∧ Hold (c 0) ∧ + ¬ ((∀ i ≤ 1, Hold (c i)) ∨ + ∃ i < 1, owned i ∧ Hold (c i) ∧ ¬ Hold (c (i + 1)) ∧ c (i + 1) < c i ∧ c i ≤ G ∧ ∀ j ≤ i, Hold (c j)) +``` + +```lean +theorem transported_card_le {ν : Type*} [DecidableEq ν] (V : Finset ν) (cells : ν → Finset (ℕ × ℕ)) (Jt : Finset (ℕ × ℕ)) + (h48 : ∀ v ∈ V, (cells v).card ≤ 48) (hcut : ∀ p ∈ Jt, ∃ v ∈ V, p ∈ cells v) : + Jt.card ≤ 48 * V.card +``` + +## CongestionNative + +```lean +noncomputable def Omega (ks : List ℕ) (mr : ℕ) (s : ℝ) : ℝ +``` + +```lean +noncomputable def capC (s : ℝ) : ℝ +``` + +```lean +noncomputable def ellC (spF : ℝ → ℝ) (s : ℝ) : ℝ +``` + +```lean +noncomputable def corrC (cstF : ℝ → ℝ) (s : ℝ) : ℝ +``` + +```lean +theorem E_lower_cap_om (R : Finset ι) (n : ι → ℕ) (d : ι → ℕ → ℕ) (J : Finset (ℕ × ℕ)) (dist : ℕ × ℕ → ℝ) + (E s cap corr ell σ Om : ℝ) (m : ℕ) + (hmono : ∀ r ∈ R, ∀ i < n r, d r i ≤ d r (i + 1)) (hd9 : ∀ r ∈ R, d r (n r) ≤ 9) + (hm : (R.filter fun r => Mixed d n r).card ≤ m) (hσ0 : 0 ≤ σ) + (hσ : ∀ a b : ℕ, 1 ≤ a → a ≤ b → b ≤ 8 → c2 (gs s) (a : ℝ) (b : ℝ) ≤ σ) + (hcong : ∑ p ∈ J, min (dist p) cap - corr ≤ ∑ r ∈ R, ∑ i ∈ range (n r), c2 (gs s) (lev d r i) (lev d r (i + 1)) + Om) + (hEex : ∑ r ∈ R, ex (gs s) (lev d r) (n r) ≤ E) (hdist : ∀ p ∈ J, ell ≤ min (dist p) cap) (hJ : 1936 ≤ J.card) (hell : 0 ≤ ell) : + 1936 * ell - corr - m * σ ≤ E + Om +``` + +```lean +theorem branchC_om (n : Inv) (ks : List ℕ) (mr : ℕ) (E Lj s : ℝ) + (hF : Finv s n ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E) + (hE : Lj ≤ E + Omega ks mr s) (hFb : Fc cfC s < 17 * Lj) : + Finv s (invoice (caller 6 7) n 17) < 0 +``` + +```lean +theorem hcong_of_capclass (J : Finset (ℕ × ℕ)) (leg : ℕ × ℕ → Prop) [DecidablePred leg] (dist : ℕ × ℕ → ℝ) + (cap U Pub cst Rm Nf Om : ℝ) (hcap : cap = U / 48) (hU : 0 ≤ U) + (hleg : ∑ p ∈ J.filter leg, dist p ≤ Pub + cst * Rm) + (hT : ((J.filter fun p => ¬ leg p).card : ℝ) ≤ 48 * Nf) + (hclass : cst * (Rm - 8) + U * Nf ≤ Om) : + ∑ p ∈ J, min (dist p) cap - 8 * cst ≤ Pub + Om +``` + +```lean +theorem unit_mono (s s' : ℝ) (hs : 0 ≤ s) (h : s ≤ s') : (9 : ℝ) ^ s - (8 : ℝ) ^ s ≤ (9 : ℝ) ^ s' - (8 : ℝ) ^ s' +``` + +```lean +theorem tab_piece (spF cstF : ℝ → ℝ) (a b : ℚ) (lcp cH spLo unLo : ℚ) (hlcp : 0 ≤ lcp) (hcH : 0 ≤ cH) (ha0 : tC0 ≤ a) (hab : a ≤ b) (hb : b ≤ 1 / 10) + (hmS : MonotoneOn spF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) (hmC : MonotoneOn cstF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) + (hsp : (spLo : ℝ) ≤ spF (a : ℝ)) (hcs : cstF (b : ℝ) ≤ cH) + (hun : (unLo : ℝ) ≤ (9 : ℝ) ^ (1 - (b : ℝ)) - (8 : ℝ) ^ (1 - (b : ℝ))) + (hn1 : lcp + 8 * cH ≤ 1936 * spLo) (hn2 : lcp + 8 * cH ≤ 1936 * (unLo / 48)) : + ∀ s : ℝ, ((1 - b : ℚ) : ℝ) ≤ s → s ≤ ((1 - a : ℚ) : ℝ) → (lcp : ℝ) ≤ 1936 * ellC spF s - corrC cstF s ∧ 0 ≤ ellC spF s +``` + +```lean +theorem ceiling_native {ι : Type*} [DecidableEq ι] + (R : Finset ι) (nR : ι → ℕ) (dR : ι → ℕ → ℕ) + (hmono : ∀ r ∈ R, ∀ i < nR r, dR r i ≤ dR r (i + 1)) (hd9 : ∀ r ∈ R, dR r (nR r) ≤ 9) + (hmix : (R.filter fun r => Mixed dR nR r).card ≤ 5) + (n : Inv) (ks : List ℕ) (mr st : ℕ) (E : ℝ → ℝ) (J : Finset (ℕ × ℕ)) (distF : ℝ → ℕ × ℕ → ℝ) (spF cstF : ℝ → ℝ) + (hk : ∀ k ∈ ks, 1 ≤ k ∧ k ≤ 9) (hmass : 56 ≤ ks.sum) (hmd : 8 ≤ ks.length) (hmr : 8 ≤ mr) + (hF : ∀ s, 0 ≤ s → s ≤ 1 → Finv s n ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E s) + (hY : 104 ≤ st + (ks.length + mr)) + (hst : ∀ s, 0 ≤ s → s ≤ 1 → (2 - (2 : ℝ) ^ s) * st ≤ E s) + (hEex : ∀ s, 0 ≤ s → s ≤ 1 → ∑ r ∈ R, ex (gs s) (lev dR r) (nR r) ≤ E s) + (hcong : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → + ∑ p ∈ J, min (distF s p) (capC s) - corrC cstF s ≤ + ∑ r ∈ R, ∑ i ∈ range (nR r), c2 (gs s) (lev dR r i) (lev dR r (i + 1)) + Omega ks mr s) + (hdist : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → ∀ p ∈ J, spF (1 - s) ≤ distF s p) + (hJ : 1936 ≤ J.card) + (hspMono : MonotoneOn spF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) + (hcstMono : MonotoneOn cstF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) + (hspTab : ((spFloC0 : ℚ) : ℝ) ≤ spF ((tC0 : ℚ) : ℝ) ∧ ((spFloC1 : ℚ) : ℝ) ≤ spF ((tC1 : ℚ) : ℝ) ∧ + ((spFloC2 : ℚ) : ℝ) ≤ spF ((tC2 : ℚ) : ℝ) ∧ ((spFloC3 : ℚ) : ℝ) ≤ spF ((tC3 : ℚ) : ℝ)) + (hcstTab : cstF ((tC1 : ℚ) : ℝ) ≤ ((cHC0 : ℚ) : ℝ) ∧ cstF ((tC2 : ℚ) : ℝ) ≤ ((cHC1 : ℚ) : ℝ) ∧ + cstF ((tC3 : ℚ) : ℝ) ≤ ((cHC2 : ℚ) : ℝ) ∧ cstF (1 / 10) ≤ ((cHC3 : ℚ) : ℝ)) + (hunitTab : ((unitLoC0 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) ∧ + ((unitLoC1 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) ∧ + ((unitLoC2 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) ∧ + ((unitLoC3 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - (1 / 10 : ℝ)) - (8 : ℝ) ^ (1 - (1 / 10 : ℝ))) : + ∀ t : ℝ, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 → Finv (1 - t) (invoice (caller 6 7) n 17) < 0 +``` + +## CongestionNativeH + +```lean +theorem q_mono (s : ℝ) (hs0 : 9 / 10 ≤ s) (hs1 : s ≤ 1) : + MonotoneOn (fun x : ℝ => x ^ (s - 1) * Real.log x) (Set.Ioc 0 9) +``` + +```lean +theorem psi_superadd (s : ℝ) (hs0 : 9 / 10 ≤ s) (hs1 : s ≤ 1) (x y : ℝ) (hx : 0 ≤ x) (hy : 0 ≤ y) (hxy : x + y ≤ 9) : + x ^ s * Real.log x + y ^ s * Real.log y ≤ (x + y) ^ s * Real.log (x + y) +``` + +```lean +theorem tri_anti (u v : ℝ) (hu : 0 ≤ u) (hv : 0 ≤ v) (huv : u + v ≤ 9) : + AntitoneOn (fun s => gs s u + gs s v - gs s (u + v)) (Set.Icc (9 / 10) 1) +``` + +```lean +theorem c2_anti (a b : ℝ) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ 9) (s s' : ℝ) (hs : 9 / 10 ≤ s) (hss : s ≤ s') (hs' : s' ≤ 1) : + c2 (gs s') a b ≤ c2 (gs s) a b +``` + +```lean +abbrev Move +``` + +```lean +def Valid (m : Move) : Prop +``` + +```lean +noncomputable def wsum (p : List Move) (t : ℝ) : ℝ +``` + +```lean +theorem wsum_mono (p : List Move) (hp : ∀ m ∈ p, Valid m) (t t' : ℝ) (h0 : 0 ≤ t) (htt : t ≤ t') (h1 : t' ≤ 1 / 10) : + wsum p t ≤ wsum p t' +``` + +```lean +theorem spShape_mono {κ : Type*} (P : Finset κ) (hP : P.Nonempty) (pth : κ → List Move) (hv : ∀ q ∈ P, ∀ m ∈ pth q, Valid m) + (t t' : ℝ) (h0 : 0 ≤ t) (htt : t ≤ t') (h1 : t' ≤ 1 / 10) : + P.inf' hP (fun q => wsum (pth q) t) ≤ P.inf' hP (fun q => wsum (pth q) t') +``` + +```lean +theorem cstShape_mono {κ : Type*} (P : Finset κ) (hP : P.Nonempty) (pth : κ → List Move) (hv : ∀ q ∈ P, ∀ m ∈ pth q, Valid m) + (t t' : ℝ) (h0 : 0 ≤ t) (htt : t ≤ t') (h1 : t' ≤ 1 / 10) : + P.sup' hP (fun q => wsum (pth q) t) ≤ P.sup' hP (fun q => wsum (pth q) t') +``` + +```lean +theorem hdist_of_shape {κ : Type*} (P : Finset κ) (hP : P.Nonempty) (pth : κ → List Move) (d t : ℝ) + (h : ∃ q ∈ P, d = wsum (pth q) t) : P.inf' hP (fun q => wsum (pth q) t) ≤ d +``` + +```lean +theorem hcong_of_paths {α : Type*} [Preorder α] {ν : Type*} [DecidableEq ν] + (J : Finset (ℕ × ℕ)) (dist : ℕ × ℕ → ℝ) + (c : ℕ × ℕ → ℕ → α) (n : ℕ × ℕ → ℕ) (Hold : ℕ × ℕ → α → Prop) (G : ℕ × ℕ → α) (owned : ℕ × ℕ → ℕ → Prop) + (hHold : ∀ p ∈ J, ∀ C C' : α, C ≤ C' → Hold p C → Hold p C') + (hpub : ∀ p ∈ J, ∀ i < n p, ¬ owned p i → c p i ≤ c p (i + 1)) + (hnest : ∀ p ∈ J, ∀ i < n p, owned p i → (c p i ≤ c p (i + 1) ∨ c p (i + 1) ≤ c p i)) + (hconf : ∀ p ∈ J, ∀ i ≤ n p, c p i ≤ G p) (hstart : ∀ p ∈ J, Hold p (c p 0)) + (V : Finset ν) (cells : ν → Finset (ℕ × ℕ)) (h48 : ∀ v ∈ V, (cells v).card ≤ 48) + (hvisit : ∀ p ∈ J, ∀ i < n p, owned p i → Hold p (c p i) → ¬ Hold p (c p (i + 1)) → c p (i + 1) < c p i → c p i ≤ G p → + (∀ j ≤ i, Hold p (c p j)) → ∃ v ∈ V, p ∈ cells v) + (cap U Pub cst Rm Nf Om : ℝ) (hcap : cap = U / 48) (hU : 0 ≤ U) + (hleg : ∑ p ∈ J.filter (fun p => ∀ i ≤ n p, Hold p (c p i)), dist p ≤ Pub + cst * Rm) + (hVcard : (V.card : ℝ) ≤ Nf) (hclass : cst * (Rm - 8) + U * Nf ≤ Om) : + ∑ p ∈ J, min (dist p) cap - 8 * cst ≤ Pub + Om +``` + +```lean +theorem ceiling_native' {ι : Type*} [DecidableEq ι] + (R : Finset ι) (nR : ι → ℕ) (dR : ι → ℕ → ℕ) + (hmono : ∀ r ∈ R, ∀ i < nR r, dR r i ≤ dR r (i + 1)) (hd9 : ∀ r ∈ R, dR r (nR r) ≤ 9) + (hmix : (R.filter fun r => Mixed dR nR r).card ≤ 5) + (n : Inv) (ks : List ℕ) (mr st : ℕ) (E : ℝ → ℝ) (J : Finset (ℕ × ℕ)) (distF : ℝ → ℕ × ℕ → ℝ) (spF cstF : ℝ → ℝ) + (hk : ∀ k ∈ ks, 1 ≤ k ∧ k ≤ 9) (hmass : 56 ≤ ks.sum) (hmd : 8 ≤ ks.length) (hmr : 8 ≤ mr) + (hF : ∀ s, 0 ≤ s → s ≤ 1 → Finv s n ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E s) + (hY : 104 ≤ st + (ks.length + mr)) + (hst : ∀ s, 0 ≤ s → s ≤ 1 → (2 - (2 : ℝ) ^ s) * st ≤ E s) + (hEex : ∀ s, 0 ≤ s → s ≤ 1 → ∑ r ∈ R, ex (gs s) (lev dR r) (nR r) ≤ E s) + -- shape DAG: spF is the minimum, cstF the maximum, over finite families of paths of nonnegative combinations of c2-weights + {κP κC : Type*} (P : Finset κP) (hP : P.Nonempty) (pthP : κP → List Move) (hPv : ∀ q ∈ P, ∀ m ∈ pthP q, Valid m) + (C : Finset κC) (hC : C.Nonempty) (pthC : κC → List Move) (hCv : ∀ q ∈ C, ∀ m ∈ pthC q, Valid m) + (hspShape : ∀ t, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 / 10 → spF t = P.inf' hP (fun q => wsum (pthP q) t)) + (hcstShape : ∀ t, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 / 10 → cstF t = C.sup' hC (fun q => wsum (pthC q) t)) + -- dist is realised by a shape-DAG path + (hdistShape : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → ∀ p ∈ J, ∃ q ∈ P, distF s p = wsum (pthP q) (1 - s)) + (hJ : 1936 ≤ J.card) + -- per-cell chart paths (Path-Cut premises), 48-law and visits + {α : Type*} [Preorder α] {ν : Type*} [DecidableEq ν] + (c : ℕ × ℕ → ℕ → α) (nP : ℕ × ℕ → ℕ) (Hold : ℕ × ℕ → α → Prop) (G : ℕ × ℕ → α) (owned : ℕ × ℕ → ℕ → Prop) + (hHold : ∀ p ∈ J, ∀ C C' : α, C ≤ C' → Hold p C → Hold p C') + (hpub : ∀ p ∈ J, ∀ i < nP p, ¬ owned p i → c p i ≤ c p (i + 1)) + (hnest : ∀ p ∈ J, ∀ i < nP p, owned p i → (c p i ≤ c p (i + 1) ∨ c p (i + 1) ≤ c p i)) + (hconf : ∀ p ∈ J, ∀ i ≤ nP p, c p i ≤ G p) (hstart : ∀ p ∈ J, Hold p (c p 0)) + (V : Finset ν) (cells : ν → Finset (ℕ × ℕ)) (h48 : ∀ v ∈ V, (cells v).card ≤ 48) + (hvisit : ∀ p ∈ J, ∀ i < nP p, owned p i → Hold p (c p i) → ¬ Hold p (c p (i + 1)) → c p (i + 1) < c p i → c p i ≤ G p → + (∀ j ≤ i, Hold p (c p j)) → ∃ v ∈ V, p ∈ cells v) + (Rm Nf : ℝ) (hVcard : (V.card : ℝ) ≤ Nf) + (hleg : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → + ∑ p ∈ J.filter (fun p => ∀ i ≤ nP p, Hold p (c p i)), distF s p ≤ + ∑ r ∈ R, ∑ i ∈ range (nR r), c2 (gs s) (lev dR r i) (lev dR r (i + 1)) + cstF (1 - s) * Rm) + (hclass : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → cstF (1 - s) * (Rm - 8) + ((9 : ℝ) ^ s - (8 : ℝ) ^ s) * Nf ≤ Omega ks mr s) + (hspTab : ((spFloC0 : ℚ) : ℝ) ≤ spF ((tC0 : ℚ) : ℝ) ∧ ((spFloC1 : ℚ) : ℝ) ≤ spF ((tC1 : ℚ) : ℝ) ∧ + ((spFloC2 : ℚ) : ℝ) ≤ spF ((tC2 : ℚ) : ℝ) ∧ ((spFloC3 : ℚ) : ℝ) ≤ spF ((tC3 : ℚ) : ℝ)) + (hcstTab : cstF ((tC1 : ℚ) : ℝ) ≤ ((cHC0 : ℚ) : ℝ) ∧ cstF ((tC2 : ℚ) : ℝ) ≤ ((cHC1 : ℚ) : ℝ) ∧ + cstF ((tC3 : ℚ) : ℝ) ≤ ((cHC2 : ℚ) : ℝ) ∧ cstF (1 / 10) ≤ ((cHC3 : ℚ) : ℝ)) + (hunitTab : ((unitLoC0 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) ∧ + ((unitLoC1 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) ∧ + ((unitLoC2 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) ∧ + ((unitLoC3 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - (1 / 10 : ℝ)) - (8 : ℝ) ^ (1 - (1 / 10 : ℝ))) : + ∀ t : ℝ, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 → Finv (1 - t) (invoice (caller 6 7) n 17) < 0 +``` + +## CongestionI3DualAlg + +```lean +def h9 (g : ℝ → ℝ) (a b : ℝ) : ℝ +``` + +```lean +def k0 (g : ℝ → ℝ) (a b : ℝ) : ℝ +``` + +```lean +def c2 (g : ℝ → ℝ) (a b : ℝ) : ℝ +``` + +```lean +theorem k0_eq_h9_swapN (g : ℝ → ℝ) (a b : ℕ) (hb : b ≤ 9) (hab : a ≤ b) : + k0 g a b = h9 g (swapN 9 (a, b)).1 (swapN 9 (a, b)).2 +``` + +```lean +theorem nonmixed_charge (g : ℝ → ℝ) (hg0 : g 0 = 0) (d : ℕ → ℝ) (n : ℕ) (h : d n = 9 ∨ d 0 = 0) : + ∃ w : ℕ → ℝ, (∀ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ w i) ∧ ∑ i ∈ range n, w i = ex g d n +``` + +```lean +theorem sum_c2_le (g : ℝ → ℝ) (d : ℕ → ℝ) (n : ℕ) : + ∑ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ ex g d n + c2 g (d 0) (d n) +``` + +```lean +theorem c2_total_nonmixed (g : ℝ → ℝ) (hg0 : g 0 = 0) (a e : ℝ) (h : e = 9 ∨ a = 0) : c2 g a e ≤ 0 +``` + +```lean +def Mixed (d : ι → ℕ → ℕ) (n : ι → ℕ) (r : ι) : Prop +``` + +```lean +theorem sum_all_c2_le (g : ℝ → ℝ) (hg0 : g 0 = 0) (R : Finset ι) (n : ι → ℕ) (d : ι → ℕ → ℕ) + (hmono : ∀ r ∈ R, ∀ i < n r, d r i ≤ d r (i + 1)) (hd9 : ∀ r ∈ R, d r (n r) ≤ 9) + (m : ℕ) (hm : (R.filter fun r => Mixed d n r).card ≤ m) (σ : ℝ) (hσ0 : 0 ≤ σ) + (hσ : ∀ a b : ℕ, 1 ≤ a → a ≤ b → b ≤ 8 → c2 g (a : ℝ) (b : ℝ) ≤ σ) : + ∑ r ∈ R, ∑ i ∈ range (n r), c2 g (lev d r i) (lev d r (i + 1)) ≤ ∑ r ∈ R, ex g (lev d r) (n r) + m * σ +``` + +## CongestionI3DualSig + +```lean +theorem sig_of_ok (lo hi σ : ℚ) (hok : sigOK lo hi σ = true) (hlo : 0 ≤ lo) (hhi : hi ≤ 1) (hσ : 0 ≤ σ) (s : ℝ) + (h1 : (lo : ℝ) ≤ s) (h2 : s ≤ (hi : ℝ)) (a b : ℕ) (ha : 1 ≤ a) (hab : a ≤ b) (hb : b ≤ 8) : + c2 (gs s) (a : ℝ) (b : ℝ) ≤ (σ : ℝ) +``` + +## CongestionNativeTab + +```lean +theorem tabC0 : lcpC0 + 8 * cHC0 ≤ 1936 * spFloC0 ∧ lcpC0 + 8 * cHC0 ≤ 1936 * (unitLoC0 / 48) +``` + +```lean +theorem tabC1 : lcpC1 + 8 * cHC1 ≤ 1936 * spFloC1 ∧ lcpC1 + 8 * cHC1 ≤ 1936 * (unitLoC1 / 48) +``` + +```lean +theorem tabC2 : lcpC2 + 8 * cHC2 ≤ 1936 * spFloC2 ∧ lcpC2 + 8 * cHC2 ≤ 1936 * (unitLoC2 / 48) +``` + +```lean +theorem tabC3 : lcpC3 + 8 * cHC3 ≤ 1936 * spFloC3 ∧ lcpC3 + 8 * cHC3 ≤ 1936 * (unitLoC3 / 48) +``` + diff --git a/research/p104-native-ceiling/PR_BODY.md b/research/p104-native-ceiling/PR_BODY.md new file mode 100644 index 0000000000..244e4e6769 --- /dev/null +++ b/research/p104-native-ceiling/PR_BODY.md @@ -0,0 +1,16 @@ +P104: a conditional ceiling κ ≤ .0136564 covering the current frontier words (Lean, no κ) + +Lean-only package, builds on #7656 (its modules are included unchanged; 13 new modules). No κ claim. + +**Result.** `CongestionNative.ceiling_native`: F(1−t) < 0 for t in [.0136564, 1] on the 17-call invoice of the #7113 caller C(8|9), conditional on the named hypotheses in `PROVED.md` (copied from the Lean text). The hypotheses include at most 5 mixed public registers (the earlier restricted-class premise "every public register ends at V" is gone, via a two-sided I3 telescoping), the descent mass and rank conditions, the junk count |J| ≥ 1936, certified rational tables, and the Cap-class accounting. `CongestionNativeH.ceiling_native'` derives `hspMono`, `hcstMono`, `hdist` and `hcong*` from shape-DAG hypotheses and per-cell chart-path hypotheses (`path_cut`, the 48-law, `hcong_of_capclass` are proved and wired in). The monotonicity of c2 in t (superadditivity of x^s ln x) is proved in the kernel. All theorems print only propext, Classical.choice, Quot.sound; no `sorry`, no `native_decide`; every module was compiled fresh (`CHECK.txt`). + +**Caveats, stated plainly.** +- The class-wide bound |J| ≥ 1936 is a conjecture (it rests on the rank-8, C = 56 decoder structure, whose rigidity is numerical; decoders with 9 or more rows and network decoders are open). The natives' value, |J| = 4962, is computed, not bounded. +- Word-level premises are computed by scripts that are not in the package (`NATIVES.md`: script, words, result). hcong*, hdist, hspMono and hst are paper theorems whose premises the natives meet; in Lean, hspMono, hcstMono and hdist are now derived from shape-DAG hypotheses, and hst and the register-machine facts (hconf, hstart, hvisit, hleg) remain hypotheses. +- Path-Cut is stated for the cancellation (arrival) path of a junk cell. `hconf` and `hstart` are what that arrival decomposition supplies, not free premises; the lemma is not claimed for arbitrary paths, since a path that re-enters the confinement region by a nested owned descent is an arrival, counted on the left, never cut. The decomposition itself is not formalised. +- Completeness of the 230-shape DAG for the natives' 104-port set was re-derived independently by exhaustive enumeration (identical); other port sets are not covered. +- The natives share one owned layer and one port set, so they are close to a single data point. The data files' fidelity to the word files rests on reading, and the link from the Lean invoice to each word's pricing is the pricing script's. + +The premises under study are SYLforge's (#7616, #7620); the caller is rohanarun's (#7113). DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. + +🤖 Generated with [Claude Code](https://claude.com/claude-code) diff --git a/research/p104-native-ceiling/README.md b/research/p104-native-ceiling/README.md new file mode 100644 index 0000000000..e2051d7f3d --- /dev/null +++ b/research/p104-native-ceiling/README.md @@ -0,0 +1,31 @@ +# P104: a conditional ceiling kappa <= .0136564 covering the current frontier words (Lean, no kappa) + +Authors: DreamingOfClouds with Claude Opus 5.5 (Anthropic), via Claude Code. **No kappa claim.** Everything here is a Lean statement with named hypotheses. Lean proves nothing about the extracted data's fidelity, the word files, or the checker scripts; those premises are listed in `NATIVES.md`. + +## What is in it +The import closure of `Nov15/CongestionNativeH.lean` (38 modules). 25 modules are the unchanged files of the previous Lean package (#7656), 13 are new: +`CongestionI3DualAlg`, `CongestionI3DualConst`, `CongestionI3DualSig`, `CongestionI3DualCertC0` to `C3`, `CongestionI3DualData`, `CongestionI3DualNumC` (two-sided I3: each public register's excess is telescoped end-anchored or start-anchored, so the premise "every public register ends at V" is replaced by "at most 5 mixed registers"; sigma certificates; rational cell data), `CongestionNativeTab` (outward-rounded rational tables), `CongestionNative` (`ceiling_native`: F(1-t) < 0 for t in [tC0, 1], tC0 = .0136564), `PathCut` (`path_cut`, `nested_needed`, `transported_card_le`) and `CongestionNativeH` (`ceiling_native'`: the hypotheses `hspMono`, `hcstMono`, `hdist` and `hcong` are derived from shape-DAG and per-cell-path hypotheses). + +**The class-wide bound |J| >= 1936 (`hJ`) is a conjecture.** For the natives it is a computed value (|J| = 4962), not a bound; Lean takes it as a hypothesis. Equally, the natives' membership in the class is computed, not proved in Lean (`NATIVES.md`). + +## Files +| file | content | +|---|---| +| PROVED.md | the main statements, copied by script from the Lean text (all hypotheses visible) | +| NATIVES.md | per word-level premise: the script that computes it, the words it ran on, the result | +| CHECK.txt | fresh compile table of all 38 modules (one at a time, 3.5 GB guard) and `#print axioms` | +| PR_BODY.md | draft PR description | +| LICENSE | Apache-2.0 | +| lean/ | Lean subproject; sources in `lean/Nov15/`, notes in the per-file `.md` where present | + +## Pins and build +Toolchain `leanprover/lean4:v4.33.0-rc1` (`lean/lean-toolchain`); Mathlib commit `55b7917b472489c7c56a0fa6393af05cfd536599` (`lean/lakefile.toml`, `lean/lake-manifest.json`). +``` +cd lean +lake exe cache get +lake build +``` +CHECK.txt was produced file by file with `lean -j1 -o` in dependency order against an existing build of the pinned Mathlib, with a fresh output directory first on the search path. `lake build` itself was not run. + +## Not included +All scripts that compute the word-level premises, the word files, and the working notes the per-file `.md` notes cite. Labels such as HC5 or AUD refer to those notes. diff --git a/research/p104-native-ceiling/lean/Nov15/CallerCost.lean b/research/p104-native-ceiling/lean/Nov15/CallerCost.lean new file mode 100644 index 0000000000..644e5b918d --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CallerCost.lean @@ -0,0 +1,279 @@ +/- +CALLER-COST . Closed form of the CALLERCO caller invoice (internal notes `caller`, ck.py), +histograms as lists of (rank, count) terms, S = sum r*(T-P), D0 = sum (T-P)*f(r), f r = r ln r (FloorD0 convention), +invoice = caller + calls * native, reproduction of the #7113 caller at 8|9, S(k) = 3408 k - 208, single-crossing in the native +D0 per call, and the abstract composition lemma. Kernel only, no sorry / native_decide. +-/ +import Mathlib.Analysis.SpecialFunctions.Log.Basic +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Mathlib.Algebra.Order.BigOperators.Group.Finset +import Mathlib.Tactic + +namespace CallerCost +open Real + +/-- a histogram: list of (rank, count) terms -/ +abbrev Hist := List (ℕ × ℕ) + +def cnt (l : Hist) (r : ℕ) : ℕ := (l.map fun p => if p.1 = r then p.2 else 0).sum +def Sh (l : Hist) : ℤ := (l.map fun p => (p.1 : ℤ) * p.2).sum +noncomputable def fL (r : ℕ) : ℝ := (r : ℝ) * Real.log r +noncomputable def Dh (l : Hist) : ℝ := (l.map fun p => (p.2 : ℝ) * fL p.1).sum +def scale (L : ℕ) (l : Hist) : Hist := l.map fun p => (p.1, L * p.2) + +structure Inv where + T : Hist + P : Hist + +def Sinv (i : Inv) : ℤ := Sh i.T - Sh i.P +noncomputable def Dinv (i : Inv) : ℝ := Dh i.T - Dh i.P +/-- invoice = caller + L * native (pricekit.invoice, counts scaled by L) -/ +def invoice (c n : Inv) (L : ℕ) : Inv := ⟨c.T ++ scale L n.T, c.P ++ scale L n.P⟩ + +theorem Sh_append (l m : Hist) : Sh (l ++ m) = Sh l + Sh m := by simp [Sh] +theorem Dh_append (l m : Hist) : Dh (l ++ m) = Dh l + Dh m := by simp [Dh] +theorem Sh_scale (L : ℕ) (l : Hist) : Sh (scale L l) = L * Sh l := by + induction l with + | nil => simp [Sh, scale] + | cons p l ih => + simp only [Sh, scale, List.map_cons, List.sum_cons] at ih ⊢ + rw [ih]; push_cast; ring +theorem Dh_scale (L : ℕ) (l : Hist) : Dh (scale L l) = L * Dh l := by + induction l with + | nil => simp [Dh, scale] + | cons p l ih => + simp only [Dh, scale, List.map_cons, List.sum_cons] at ih ⊢ + rw [ih]; push_cast; ring + +theorem invoice_S (c n : Inv) (L : ℕ) : Sinv (invoice c n L) = Sinv c + L * Sinv n := by + simp only [Sinv, invoice, Sh_append, Sh_scale]; ring +theorem invoice_D0 (c n : Inv) (L : ℕ) : Dinv (invoice c n L) = Dinv c + L * Dinv n := by + simp only [Dinv, invoice, Dh_append, Dh_scale]; ring + +/-! ### the caller family C(a|b): g = 8, 96 A ports x 4 thin queries, 8 B ports (s1.py) -/ +def armT (n c : ℕ) : Hist := (List.range n).map fun i => (8 * i + 9, c) +def armP (m c : ℕ) : Hist := (List.range m).map fun i => (8 * i + 16, c) +/-- C(a'+2 | b'+2); stage count k = a'+b'+4. 208 = 2 * 104 ports. -/ +def callerT (a b : ℕ) : Hist := armT (a + 2) 208 ++ armT (b + 2) 208 ++ [(8 * (a + b + 4) + 1, 208)] +def callerP (a b : ℕ) : Hist := + armP a 208 ++ armP b 208 ++ [(8, 384), (1, 384), (8, 16 * (a + b + 4)), (9, 32)] +def caller (a b : ℕ) : Inv := ⟨callerT a b, callerP a b⟩ + +/-- #7113 caller invoice (PRICEKIT caller_invoice of MONOCALLER/7113_CALLER.json), data; nJ = 17 -/ +def dataT : Hist := [(9,416),(17,416),(25,416),(33,416),(41,416),(49,416),(57,416),(65,416),(73,208),(137,208)] +def dataP : Hist := [(1,384),(8,656),(9,32),(16,416),(24,416),(32,416),(40,416),(48,416),(56,416),(64,208)] + +theorem cnt_zero {l : Hist} {r : ℕ} (h : ∀ p ∈ l, p.1 ≠ r) : cnt l r = 0 := by + unfold cnt + apply List.sum_eq_zero + intro x hx + obtain ⟨p, hp, rfl⟩ := List.mem_map.mp hx + simp [h p hp] + +theorem keys_T : ∀ p ∈ callerT 6 7, p.1 < 200 := by decide +theorem keys_P : ∀ p ∈ callerP 6 7, p.1 < 200 := by decide +theorem keys_dT : ∀ p ∈ dataT, p.1 < 200 := by decide +theorem keys_dP : ∀ p ∈ dataP, p.1 < 200 := by decide + +theorem cnt_big {l : Hist} (hl : ∀ p ∈ l, p.1 < 200) {r : ℕ} (hr : 200 ≤ r) : cnt l r = 0 := + cnt_zero fun p hp => by have := hl p hp; omega + +theorem repro_T : ∀ r, cnt (callerT 6 7) r = cnt dataT r := by + intro r + by_cases hr : r < 200 + · interval_cases r <;> decide + · rw [cnt_big keys_T (by omega), cnt_big keys_dT (by omega)] +theorem repro_P : ∀ r, cnt (callerP 6 7) r = cnt dataP r := by + intro r + by_cases hr : r < 200 + · interval_cases r <;> decide + · rw [cnt_big keys_P (by omega), cnt_big keys_dP (by omega)] + +/-- weighted sums depend only on the histogram (keys below N) -/ +theorem wsum_cnt (w : ℕ → ℝ) (N : ℕ) : ∀ l : Hist, (∀ p ∈ l, p.1 < N) → + (l.map fun p => (p.2 : ℝ) * w p.1).sum = ∑ r ∈ Finset.range N, (cnt l r : ℝ) * w r := by + intro l + induction l with + | nil => intro _; simp [cnt] + | cons p l ih => + intro h + have hp : p.1 < N := h p (by simp) + have ih' := ih (fun q hq => h q (by simp [hq])) + have hc : ∀ r, (cnt (p :: l) r : ℝ) = (if p.1 = r then (p.2 : ℝ) else 0) + cnt l r := by + intro r; simp only [cnt, List.map_cons, List.sum_cons]; split_ifs <;> simp + simp only [List.map_cons, List.sum_cons] + rw [ih'] + simp only [hc, add_mul, Finset.sum_add_distrib] + congr 1 + rw [Finset.sum_eq_single p.1] + · simp + · intro b _ hb; simp [Ne.symm hb] + · intro h'; exact absurd (Finset.mem_range.mpr hp) h' + +theorem Dh_congr (l m : Hist) (hl : ∀ p ∈ l, p.1 < 200) (hm : ∀ p ∈ m, p.1 < 200) + (h : ∀ r, cnt l r = cnt m r) : Dh l = Dh m := by + unfold Dh; rw [wsum_cnt fL 200 l hl, wsum_cnt fL 200 m hm] + exact Finset.sum_congr rfl fun r _ => by rw [h r] + +theorem caller89_D0 : + Dh (callerT 6 7) = Dh dataT ∧ Dh (callerP 6 7) = Dh dataP := + ⟨Dh_congr _ _ keys_T keys_dT repro_T, Dh_congr _ _ keys_P keys_dP repro_P⟩ + +theorem caller89_S : Sh (callerT 6 7) = Sh dataT ∧ Sh (callerP 6 7) = Sh dataP := by + constructor <;> decide + +/-- REPRODUCTION: C(8|9) equals the #7113 caller invoice (histograms term for term; hence S and D0). -/ +theorem reproduction : + (∀ r, cnt (caller 6 7).T r = cnt dataT r) ∧ (∀ r, cnt (caller 6 7).P r = cnt dataP r) ∧ + Sinv (caller 6 7) = Sh dataT - Sh dataP ∧ Dinv (caller 6 7) = Dh dataT - Dh dataP := by + refine ⟨repro_T, repro_P, ?_, ?_⟩ + · simp only [Sinv, caller, caller89_S.1, caller89_S.2] + · simp only [Dinv, caller, caller89_D0.1, caller89_D0.2] + +theorem S_data : Sh dataT - Sh dataP = 57728 := by decide + +/-! ### closed forms -/ +theorem Sh_armT (n c : ℕ) : Sh (armT n c) = c * (4 * n * n + 5 * n) := by + induction n with + | zero => simp [armT, Sh] + | succ n ih => + have : armT (n + 1) c = armT n c ++ [(8 * n + 9, c)] := by simp [armT, List.range_succ] + rw [this, Sh_append, ih]; simp [Sh]; push_cast; ring +theorem Sh_armP (m c : ℕ) : Sh (armP m c) = c * (4 * m * m + 12 * m) := by + induction m with + | zero => simp [armP, Sh] + | succ n ih => + have : armP (n + 1) c = armP n c ++ [(8 * n + 16, c)] := by simp [armP, List.range_succ] + rw [this, Sh_append, ih]; simp [Sh]; push_cast; ring + +/-- caller S is affine in the stage count k = a+b+4: S = 3408 k - 208 (96 A + 8 B ports; both arms >= 2) -/ +theorem S_caller (a b : ℕ) : Sinv (caller a b) = 3408 * ((a : ℤ) + b + 4) - 208 := by + simp only [Sinv, caller, callerT, callerP, Sh_append, Sh_armT, Sh_armP] + simp [Sh]; push_cast; ring + +/-- S of the whole invoice with calls = k: (3408 + Sn) k - 208 -/ +theorem S_invoice (a b : ℕ) (n : Inv) : + Sinv (invoice (caller a b) n (a + b + 4)) = (3408 + Sinv n) * ((a : ℤ) + b + 4) - 208 := by + rw [invoice_S, S_caller]; push_cast; ring + +/-- with the #7630 native (S per call = -3312, from S = 1424 at k = 17): S(k) = 96 k - 208 -/ +theorem S_7630 (a b : ℕ) (n : Inv) (hn : Sinv n = -3312) : + Sinv (invoice (caller a b) n (a + b + 4)) = 96 * ((a : ℤ) + b + 4) - 208 := by + rw [S_invoice, hn]; ring + +theorem S_7630_k17 (n : Inv) (hn : Sinv n = -3312) : + Sinv (invoice (caller 6 7) n 17) = 1424 := by + have := S_7630 6 7 n hn; simpa using this + +theorem Dh_armT (n c : ℕ) : Dh (armT n c) = c * ∑ i ∈ Finset.range n, fL (8 * i + 9) := by + induction n with + | zero => simp [armT, Dh] + | succ n ih => + have : armT (n + 1) c = armT n c ++ [(8 * n + 9, c)] := by simp [armT, List.range_succ] + rw [this, Dh_append, ih, Finset.sum_range_succ]; simp [Dh]; ring +theorem Dh_armP (n c : ℕ) : Dh (armP n c) = c * ∑ i ∈ Finset.range n, fL (8 * i + 16) := by + induction n with + | zero => simp [armP, Dh] + | succ n ih => + have : armP (n + 1) c = armP n c ++ [(8 * n + 16, c)] := by simp [armP, List.range_succ] + rw [this, Dh_append, ih, Finset.sum_range_succ]; simp [Dh]; ring + +theorem fL_one : fL 1 = 0 := by simp [fL] + +/-- caller D0 (the stage-count cost C(k), exact): the sums are over the ranks 8j+1 (T) and 8j (P) -/ +theorem D0_caller (a b : ℕ) : Dinv (caller a b) = + 208 * (∑ i ∈ Finset.range (a + 2), fL (8 * i + 9) + ∑ i ∈ Finset.range (b + 2), fL (8 * i + 9) + + fL (8 * (a + b + 4) + 1) + - ∑ i ∈ Finset.range a, fL (8 * i + 16) - ∑ i ∈ Finset.range b, fL (8 * i + 16)) + - (384 + 16 * ((a : ℝ) + b + 4)) * fL 8 - 32 * fL 9 := by + simp only [Dinv, caller, callerT, callerP, Dh_append, Dh_armT, Dh_armP] + simp [Dh, fL_one]; ring + +/-! ### single crossing: a cheaper native can only lower the best stage count (first-order proxy K = S/D0) -/ +section crossing +variable {s ρ Dc1 Dc2 k1 k2 d d' : ℝ} + +/-- proxy objective K_d(k) = S(k) / (Dc(k) + k d), S(k) = s k - ρ, d = native D0 per call, calls = k -/ +theorem single_crossing (hρ : 0 < ρ) (hk : k1 ≤ k2) (hd : d ≤ d') + (hD1 : 0 < Dc1 + k1 * d) (hD2 : 0 < Dc2 + k2 * d) + (hD1' : 0 < Dc1 + k1 * d') (hD2' : 0 < Dc2 + k2 * d') + (h : (s * k1 - ρ) / (Dc1 + k1 * d) ≤ (s * k2 - ρ) / (Dc2 + k2 * d)) : + (s * k1 - ρ) / (Dc1 + k1 * d') ≤ (s * k2 - ρ) / (Dc2 + k2 * d') := by + rw [div_le_div_iff₀ hD1 hD2] at h + rw [div_le_div_iff₀ hD1' hD2'] + have : 0 ≤ (d' - d) * (ρ * (k2 - k1)) := mul_nonneg (by linarith) (mul_nonneg hρ.le (by linarith)) + nlinarith + +/-- contrapositive form: if at the costlier native the smaller k is (weakly) preferred, it is at the cheaper native too; + equivalently the best k never goes up when D0 per call goes down -/ +theorem cheaper_native_lowers_k (hρ : 0 < ρ) (hk : k1 ≤ k2) (hd : d ≤ d') + (hD1 : 0 < Dc1 + k1 * d) (hD2 : 0 < Dc2 + k2 * d) + (hD1' : 0 < Dc1 + k1 * d') (hD2' : 0 < Dc2 + k2 * d') + (h : (s * k2 - ρ) / (Dc2 + k2 * d') < (s * k1 - ρ) / (Dc1 + k1 * d')) : + (s * k2 - ρ) / (Dc2 + k2 * d) < (s * k1 - ρ) / (Dc1 + k1 * d) := by + by_contra hn + exact absurd (single_crossing hρ hk hd hD1 hD2 hD1' hD2' (not_lt.mp hn)) (not_le.mpr h) + +/-- the crossing native D0 per call at which k1 and k2 tie (proxy): d* = (S1 Dc2 - S2 Dc1) / (ρ (k2 - k1)) -/ +theorem crossing_value (hρ : 0 < ρ) (hk : k1 < k2) : + (s * k1 - ρ) * (Dc2 + k2 * d) = (s * k2 - ρ) * (Dc1 + k1 * d) ↔ + d = ((s * k1 - ρ) * Dc2 - (s * k2 - ρ) * Dc1) / (ρ * (k2 - k1)) := by + have hne : ρ * (k2 - k1) ≠ 0 := (mul_pos hρ (by linarith)).ne' + rw [eq_div_iff hne] + constructor <;> intro h <;> nlinarith + +/-- sensitivity: d/dd of the stationarity numerator N = S'D - SD' (D = Dc + k d) is k S' - S = rho > 0. + (CALLERCO R1 sec 3 writes -(kS'-S); the sign convention there is reversed, the conclusion "cheaper native -> smaller k" is the same.) -/ +theorem stationarity_slope (s ρ Dc Dc' k d : ℝ) : + (s * (Dc + k * d) - (s * k - ρ) * (Dc' + d)) = (s * Dc - (s * k - ρ) * Dc') + ρ * d := by ring +end crossing + +/-! ### composition: invoice D0 >= caller floor + calls * native floor -/ +section composition +variable {Cl : Type} + +/-- Abstract composition. A caller class Cl with D0 cost Dc and call count `calls`; native per-call D0 Dn. + hc: caller floor as a function of the number of calls it makes; hn: a floor on the TOTAL native D0 per call. -/ +theorem composition (Dc : Cl → ℝ) (calls : Cl → ℕ) (Fc : ℕ → ℝ) (Dn Fn : ℝ) + (hc : ∀ c, Fc (calls c) ≤ Dc c) (hn : Fn ≤ Dn) (c : Cl) : + Fc (calls c) + calls c * Fn ≤ Dc c + calls c * Dn := by + have := hc c + have : (calls c : ℝ) * Fn ≤ calls c * Dn := mul_le_mul_of_nonneg_left hn (Nat.cast_nonneg _) + linarith + +/-- the native's D0 per call splits as helperD0 + rest (mains and owned MOVEs; these are CREDITS, rest <= 0 on #7630). + The helper-only floor therefore needs a cap R on the credits: rest >= -R. -/ +theorem composition_helper (Dc : Cl → ℝ) (calls : Cl → ℕ) (Fc : ℕ → ℝ) (H rest Hf R : ℝ) + (hc : ∀ c, Fc (calls c) ≤ Dc c) (hH : Hf ≤ H) (hR : -R ≤ rest) (c : Cl) : + Fc (calls c) + calls c * (Hf - R) ≤ Dc c + calls c * (H + rest) := + composition Dc calls Fc (H + rest) (Hf - R) hc (by linarith) c + +/-- the proxy kappa is bounded by S / (floor) when the floor is positive -/ +theorem kappa_proxy_le {S D F : ℝ} (hS : 0 ≤ S) (hF : 0 < F) (hFD : F ≤ D) : S / D ≤ S / F := + div_le_div_of_nonneg_left hS hF hFD + +/-- FALSE AS WRITTEN: "invoice D0 >= caller D0 + calls * helperD0-floor" (helper floor 9,928.76 per call on #7630, + caller D0 270,813, calls 17, invoice D0 391,295.63 (R1 sec 2; numbers are hypotheses/data)). The missing term is the + mains/owned MOVE credits (negative D0). Counterexample: -/ +theorem naive_composition_false : + ¬ ((270813 : ℝ) + 17 * 9928.76 ≤ 391295.63) := by norm_num + +/-- the credits implied by the data: rest per call = (391295.63 - 270813)/17 - 9928.76 < 0 -/ +theorem rest_negative : (391295.63 - 270813 : ℝ) / 17 - 9928.76 < 0 := by norm_num + +end composition + +#print axioms reproduction +#print axioms S_caller +#print axioms S_7630_k17 +#print axioms D0_caller +#print axioms invoice_S +#print axioms invoice_D0 +#print axioms single_crossing +#print axioms cheaper_native_lowers_k +#print axioms crossing_value +#print axioms composition +#print axioms composition_helper +#print axioms naive_composition_false + +end CallerCost diff --git a/research/p104-native-ceiling/lean/Nov15/CallerCost.md b/research/p104-native-ceiling/lean/Nov15/CallerCost.md new file mode 100644 index 0000000000..da373369e1 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CallerCost.md @@ -0,0 +1,18 @@ +# CallerCost.lean: caller cost closed form, reproduction, single crossing, composition +Imports Mathlib only (no Nov15 deps).9 GB. 12 `#print axioms` within [propext, Classical.choice, Quot.sound]; no sorry, no native_decide. + +## Model +- Histograms = lists of (rank,count). S = sum r*(T-P) (Sinv), D0 = sum (T-P) f(r), f r = r ln r (fL, FloorD0 convention). invoice c n L = caller + L*native (counts scaled), `invoice_S`, `invoice_D0` exact. In the pricer the number of calls L = nJ = k = a+b (stage count). +- Caller family C(a|b), g=8, 96 A ports x 4 thin queries, 8 B ports (a,b >= 2; Lean params a'=a-2, b'=b-2, k = a'+b'+4). T: ranks 8j+1, j<=arm (and 8k+1), 208 = 2*104 each; P: ranks 8j, 2<=j<=arm-1, plus (8: 384+16k, 1: 384, 9: 32). +- The code does NOT use a Z^4 over ln 2/3/5/7 form (it works in Decimal over all ranks up to 137, which involve many primes). Exact form in Lean: `D0_caller`, a finite sum of f over the ranks 8j+1 and 8j, minus (384+16k) f(8) + 32 f(9) (f(1)=0). + +## Proved +- `reproduction`: C(8|9) = caller 6 7 equals the #7113 caller invoice (data lists dataT/dataP, transcribed from the pricer's invoice of the #7113 caller file) term for term as histograms (cnt equal at every rank), hence S and D0 equal (`caller89_S`, `caller89_D0`). S = 57728 (`S_data`). Data are transcribed; the Lean statement is about those lists. +- `S_caller`: S(caller) = 3408 k - 208. `S_invoice`: with calls = k, S = (3408 + S_n) k - 208. `S_7630`: S_n = -3312 gives 96 k - 208, and `S_7630_k17` gives 1424 (S' = 96, rho = 208 as in R1 sec 3). +- Single crossing (first-order proxy K = S/D0, S = sk - rho, D = Dc(k) + k d): `single_crossing`: for k1 <= k2, d <= d', K_d(k1) <= K_d(k2) implies K_d'(k1) <= K_d'(k2). `cheaper_native_lowers_k`: strict contrapositive, a cheaper native (d down) never favours a larger k. `crossing_value`: tie at d* = (S1 Dc2 - S2 Dc1)/(rho (k2-k1)). Convexity of C(k) not attempted (not clean: arm terms are sums of r ln r over unequal strides). +- `composition`: abstract caller class, caller floor Fc(calls) <= Dc, total native floor Fn <= Dn gives Fc(k) + k Fn <= invoice D0. `composition_helper`: with native D0 = helperD0 + rest, needs a cap rest >= -R on the mains/owned credits. `kappa_proxy_le`: S/D <= S/F. + +## Statements false / imprecise +1. FALSE as written: "invoice D0 >= caller floor + calls * (helperD0 floor)". With the numbers of the caller-floor note (helper floor 9,928.76 per call as helper D0 on #7630, caller D0 270,813 = 666,499 - 395,686, 17 calls, invoice D0 391,295.63): 270,813 + 17*9,928.76 = 439,602 > 391,296 (`naive_composition_false`). Reason: the native's main/owned MOVEs are credits (negative D0, `rest_negative`: about -2,842 per call). FloorD0's floor is on helperD0 only. Corrected: `composition` with a floor on TOTAL native D0 per call, or `composition_helper` with an explicit credit cap R. A caller-floor statement needs one of these. +2. Sign slip in the caller-ceiling note, section 3: d/dd of the numerator S'D - SD' is +(kS' - S) = +rho (`stationarity_slope`), not -rho. The conclusion (cheaper native lowers k*) is unchanged. +3. Scope: monotonicity is for the proxy S/D0 (kappa ~ S/D), not the exact root kappa of F(t) = 0; the exact-kappa version is not proved here. diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3.lean new file mode 100644 index 0000000000..3088163ca8 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3.lean @@ -0,0 +1,377 @@ +import Nov15.CongestionI3Cfg +import Nov15.CongestionI3Mu +import Nov15.CongestionI3NumA +import Nov15.CongestionI3NumC4 +import Nov15.WholeFloorCover +import Mathlib.Analysis.Convex.SpecificFunctions.Pow +import Mathlib.Analysis.Convex.SpecificFunctions.Basic +import Mathlib.Analysis.SpecialFunctions.Log.Base + +/-! +CONGESTION-I3 : the I3 congestion bound and F1's restricted-class ceilings (internal notes: F1.md, +AUDIT.md, LIFT1.md, AUDIT-LIFT.md, LIFT2.md; JUNKINT I3). See CongestionI3.md for the scope list. Kernel only: no sorry, no native_decide. + +Sections: 1 per-pair bound (I3 is a HYPOTHESIS `I3Path`, in model M_V; the shape-DAG minimum is a data hypothesis), 2 forced junk >= 1936 +(kernel-checked configurations + census; per-chain flag-DP minima are a data hypothesis), 3 combination with R3 by MAX, 4 the ceilings. +-/ +namespace CongestionI3 +open NumCertK JointCeiling CallerCost + +/-! ### 1. I3: public excess >= per-pair distance, summed over supp J -/ + +/-- JUNKINT I3 (F1.md sec. 1): in model M_V (every public register except the Y mains ends at V; owned code fixed; X_q born at A_q) the public +excess `E` over R3's per-register floors is at least the sum over the junk pairs of the shortest-path distance. NOT derived here (the +telescoping I1/I2 and the path bound are not formalised): it is the hypothesis `I3Path`, always taken together with its scope. -/ +def I3Path (J : Finset (ℕ × ℕ)) (dist : ℕ × ℕ → ℝ) (E : ℝ) : Prop := ∑ p ∈ J, dist p ≤ E + +/-- per-pair minimum => E >= delta * |J| -/ +theorem pair_bound {J : Finset (ℕ × ℕ)} {dist : ℕ × ℕ → ℝ} {E δ : ℝ} (hd : ∀ p ∈ J, δ ≤ dist p) (h : I3Path J dist E) : + δ * J.card ≤ E := by + have := Finset.card_nsmul_le_sum J dist δ hd + rw [nsmul_eq_mul] at this + unfold I3Path at h + linarith + +/-- D0 currency: shape-DAG minimum 0.541495 per even pair (F1 sec. 1, reproduced by the auditor); 1936 pairs give >= 1048.33 D0 per call. -/ +theorem i3_D0_per_call {J : Finset (ℕ × ℕ)} {dist : ℕ × ℕ → ℝ} {E : ℝ} (hd : ∀ p ∈ J, (0.541495 : ℝ) ≤ dist p) + (h : I3Path J dist E) (hJ : 1936 ≤ J.card) : (1048.33 : ℝ) ≤ E := by + have h1 := pair_bound hd h + have h2 : (1936 : ℝ) ≤ J.card := by exact_mod_cast hJ + nlinarith + +/-! ### 2. forced junk >= 1936 pairs per call for rank-8 C = 56 decoders -/ + +def mu (i k : ℕ) : ℕ := (muTab.getD i []).getD k 0 +/-- every configuration's per-chain minima sum to >= 1936 (kernel) -/ +theorem mu_sum : ∀ i < 8, 1936 ≤ ∑ k ∈ Finset.range 8, mu i k := by decide +kernel + +/-- **forced junk >= 1936 pairs** for a rank-8, C = 56 decoder (one of the 8 configurations `i` of `cfgs`). Scope/hypotheses, all explicit: +* `hsub`: the chain-k forced cells `F k` are unique cells of chain k (exactly one chain can touch them; kernel-defined `uniqCells`); +* `hJ`: forced cells lie in supp J (a product forced non-zero on a cell no other chain touches cannot be cancelled); +* `hDP`: the per-chain flag-DP minimum (data, internal notes, python exact DP over the subspace lattice, NOT kernel-checked). +The decoder class itself (rank-8 on P104 labels, C = 56, rigidity M^ = D1 G D2 quoted numerically, enumeration exhaustive = 12,870 subsets) is the +hypothesis `i < 8`. -/ +theorem forced_junk_ge (i : ℕ) (hi : i < 8) (J : Finset (ℕ × ℕ)) (F : ℕ → Finset (ℕ × ℕ)) + (hsub : ∀ k < 8, F k ⊆ uniqCells (cfgs.getD i []) k) (hJ : ∀ k < 8, F k ⊆ J) + (hDP : ∀ k < 8, mu i k ≤ (F k).card) : 1936 ≤ J.card := by + have hdisj : ∀ k ∈ Finset.range 8, ∀ k' ∈ Finset.range 8, k ≠ k' → Disjoint (F k) (F k') := by + intro k hk k' hk' hne + exact (uniqCells_disjoint (cfgs.getD i []) hne).mono (hsub k (Finset.mem_range.mp hk)) (hsub k' (Finset.mem_range.mp hk')) + have h1 : (Finset.range 8).biUnion F ⊆ J := by + intro p hp + obtain ⟨k, hk, hp⟩ := Finset.mem_biUnion.mp hp + exact hJ k (Finset.mem_range.mp hk) hp + have h2 : ((Finset.range 8).biUnion F).card = ∑ k ∈ Finset.range 8, (F k).card := + Finset.card_biUnion (fun k hk k' hk' hne => hdisj k hk k' hk' hne) + have h3 : ∑ k ∈ Finset.range 8, mu i k ≤ ∑ k ∈ Finset.range 8, (F k).card := + Finset.sum_le_sum fun k hk => hDP k (Finset.mem_range.mp hk) + have h4 := mu_sum i hi + calc 1936 ≤ ∑ k ∈ Finset.range 8, (F k).card := le_trans h4 h3 + _ = ((Finset.range 8).biUnion F).card := h2.symm + _ ≤ J.card := Finset.card_le_card h1 + +/-! ### 3. combination with R3: by MAX, not sum -/ + +/-- **F1 floor in F currency (max rule).** The word's public overpay `E` (F currency) is priced by BOTH R3's forced stops (E >= (2 - 2^s) st, +st + mp >= 104 with lat = 0, nested words) and by I3 (E >= I). Both bound the SAME quantity, so the floor is R1/R2's owned 16 plus +`max (88 (2 - 2^s)) I`. I = 0 recovers R3's `-Nfl`. -/ +theorem f1_floor (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s ≤ 1) (mp st : ℕ) (Fn E I : ℝ) + (hF : Fn ≤ -400 * (8 : ℝ) ^ s - mp - E) (hmp : 16 ≤ mp) (hY : 104 ≤ st + mp) + (hst : (2 - (2 : ℝ) ^ s) * st ≤ E) (hI : I ≤ E) : + Fn ≤ -400 * (8 : ℝ) ^ s - 16 - max (88 * (2 - (2 : ℝ) ^ s)) I := by + have hu1 : (1 : ℝ) ≤ (2 : ℝ) ^ s := Real.one_le_rpow (by norm_num) hs0 + have hu2 : (2 : ℝ) ^ s ≤ 2 := by + have := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 2 by norm_num) hs1 + simpa using this + set c : ℝ := 2 - (2 : ℝ) ^ s with hc + have hc0 : 0 ≤ c := by linarith + have hc1 : c ≤ 1 := by linarith + have hm : (16 : ℝ) ≤ mp := by exact_mod_cast hmp + have hY' : (104 : ℝ) ≤ st + mp := by exact_mod_cast hY + have hst0 : (0 : ℝ) ≤ st := Nat.cast_nonneg _ + have hE0 : 0 ≤ E := le_trans (mul_nonneg hc0 hst0) hst + suffices h : (16 : ℝ) + max (88 * c) I ≤ mp + E by linarith + rcases le_total (88 * c) I with h | h + · rw [max_eq_right h]; linarith + · rw [max_eq_left h] + rcases le_or_gt (mp : ℝ) 104 with h2 | h2 + · have h3 : c * (104 - mp) ≤ c * st := mul_le_mul_of_nonneg_left (by linarith) hc0 + nlinarith + · nlinarith + +/-- the max rule is not a sum rule: both hypotheses hold with E = max and fail for the sum (so `max` is all the two bounds give). -/ +theorem sum_not_implied : ∃ E I R : ℝ, I ≤ E ∧ R ≤ E ∧ ¬ (I + R ≤ E) := ⟨1, 1, 1, le_refl _, le_refl _, by norm_num⟩ + +/-! ### 4. the ceiling kappa <= .0183952347 (8|9) -/ + +/-- the native of F1's relaxation: owned floor `400 * 8^s + 16`, no stops -/ +def natBase : Inv := ⟨[], [(8, 400), (1, 16)]⟩ +theorem natBase_F (s : ℝ) : Finv s natBase = -(400 * (8 : ℝ) ^ s + 16) := by + simp [Finv, natBase, Fh] + +theorem base_eq (s : ℝ) : Finv s (invoice (caller 6 7) natBase 17) = Fc cfB s := by + simp only [Finv, Fh, invoice, caller, callerT, callerP, armT, armP, natBase, scale, Fc, cfB, + List.range_succ, List.range_zero] + norm_num + ring + +/-- tbar = .0183952347 -/ +def tbarA : ℚ := 183952347 / 10 ^ 10 +theorem sA_eq : sA = 1 - tbarA := by unfold sA tbarA; norm_num + +/-- **F1 ceiling, 8|9 (kappa <= .0183952347)** for words in the restricted class, with every hypothesis explicit: +* scope (propositions the caller must supply): `MV` (model M_V), `Rank8C56` (rank-8 decoder, C = 56 on P104 labels, one of the 8 configurations `i`), + `PlaneSep` (no second-plane carrier of plane-1 content) -- under `PlaneSep` fails the junk bound collapses to 0 (F1 f1k2); LIFT1 replaces it by + the public-provenance direction law (see `ceiling_A_noSep`). `nested`: lat = 0 (verifier rule, WholeFloorNest). +* `hI3`: I3 in F currency, `E s >= sum of per-pair F-distances` (hypothesis `I3Path`, valid under the scope); +* `hdist`: per-pair shape-DAG minimum `sigma0 <= sp_F(t)` for t in [tbar, .1] (DATA: f1ceil.spF at tbar; monotone in t numerically, AUDIT: the + convex/superadditive proof of monotonicity was not re-derived); +* `hforced`/`hDP`: section 2 (|J| >= 1936). +Conclusion: F < 0 on the 17-call invoice of the #7113 caller for every t in [tbar, 1] -- the ceiling convention of JointCeiling/WholeFloorCover. -/ +theorem ceiling_A (MV Rank8C56 PlaneSep : Prop) (hMV : MV) (hR : Rank8C56) (hP : PlaneSep) + (n : Inv) (mp st : ℕ) (E : ℝ → ℝ) (J : Finset (ℕ × ℕ)) (distF : ℝ → ℕ × ℕ → ℝ) + (hF : ∀ s, 0 ≤ s → s ≤ 1 → Finv s n ≤ -400 * (8 : ℝ) ^ s - mp - E s) + (hmp : 16 ≤ mp) (hY : 104 ≤ st + mp) + (hst : ∀ s, 0 ≤ s → s ≤ 1 → (2 - (2 : ℝ) ^ s) * st ≤ E s) + (hI3 : MV → Rank8C56 → PlaneSep → ∀ s, 0 ≤ s → s ≤ 1 → I3Path J (distF s) (E s)) + (hdist : ∀ s, 9 / 10 ≤ s → s ≤ ((sA : ℚ) : ℝ) → ∀ p ∈ J, ((sigma0 : ℚ) : ℝ) ≤ distF s p) + (hJ : 1936 ≤ J.card) : + ∀ t : ℝ, ((tbarA : ℚ) : ℝ) ≤ t → t ≤ 1 → Finv (1 - t) (invoice (caller 6 7) n 17) < 0 := by + intro t ht ht1 + have hsA : ((sA : ℚ) : ℝ) = 1 - ((tbarA : ℚ) : ℝ) := by rw [sA_eq]; push_cast; ring + have htb0 : (0 : ℝ) ≤ ((tbarA : ℚ) : ℝ) := by unfold tbarA; norm_num + have hs0 : (0 : ℝ) ≤ 1 - t := by linarith + have htb1 : ((tbarA : ℚ) : ℝ) ≤ 1 / 10 := by unfold tbarA; norm_num + have hs1 : 1 - t ≤ 1 := by linarith + have hu1 : (1 : ℝ) ≤ (2 : ℝ) ^ (1 - t) := Real.one_le_rpow (by norm_num) hs0 + have hu2 : (2 : ℝ) ^ (1 - t) ≤ 2 := by + have := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 2 by norm_num) hs1; simpa using this + have hE0 : 0 ≤ E (1 - t) := + le_trans (mul_nonneg (by linarith) (Nat.cast_nonneg st)) (hst _ hs0 hs1) + rcases le_or_gt (1 / 10 : ℝ) t with h10 | h10 + · -- t >= .1: R3 (I = 0), then the WholeFloorCover cover + have h1 := f1_floor (1 - t) hs0 hs1 mp st (Finv (1 - t) n) (E (1 - t)) 0 (hF _ hs0 hs1) hmp hY (hst _ hs0 hs1) hE0 + have hc0 : (0 : ℝ) ≤ 88 * (2 - (2 : ℝ) ^ (1 - t)) := by linarith + rw [max_eq_left hc0] at h1 + have h2 := invoice_F (1 - t) (caller 6 7) n 17 + have h3 := invoice_F (1 - t) (caller 6 7) natFloor 17 + have h4 := natFloor_F (1 - t) + have h5 := WholeFloorCover.cover t (by linarith) ht1 + have h6 : Nfl (1 - t) = 400 * (8 : ℝ) ^ (1 - t) + 16 + 88 * (2 - (2 : ℝ) ^ (1 - t)) := rfl + push_cast at h2 h3 + nlinarith + · -- t in [tbar, .1): I3 lift + have hsl : (9 / 10 : ℝ) ≤ 1 - t := by linarith + have hsr : 1 - t ≤ ((sA : ℚ) : ℝ) := by rw [hsA]; linarith + have hsum := pair_bound (hdist _ hsl hsr) (hI3 hMV hR hP _ hs0 hs1) + have hE : (1936 : ℝ) * ((sigma0 : ℚ) : ℝ) ≤ E (1 - t) := by + have : (1936 : ℝ) ≤ J.card := by exact_mod_cast hJ + have h0 : (0 : ℝ) ≤ ((sigma0 : ℚ) : ℝ) := by unfold sigma0; norm_num + nlinarith + have h1 := f1_floor (1 - t) hs0 hs1 mp st (Finv (1 - t) n) (E (1 - t)) (1936 * ((sigma0 : ℚ) : ℝ)) (hF _ hs0 hs1) hmp hY + (hst _ hs0 hs1) hE + have h1' : Finv (1 - t) n ≤ -400 * (8 : ℝ) ^ (1 - t) - 16 - 1936 * ((sigma0 : ℚ) : ℝ) := by + have := le_max_right (88 * (2 - (2 : ℝ) ^ (1 - t))) (1936 * ((sigma0 : ℚ) : ℝ)) + linarith + have h2 := invoice_F (1 - t) (caller 6 7) n 17 + have h3 := invoice_F (1 - t) (caller 6 7) natBase 17 + have h4 := natBase_F (1 - t) + have h5 := cfB_neg (1 - t) hsl hsr + have h6 := base_eq (1 - t) + have h7 : ((liftA : ℚ) : ℝ) = 17 * 1936 * ((sigma0 : ℚ) : ℝ) := by unfold liftA; push_cast; ring + push_cast at h2 h3 + nlinarith + + +/-! ### 5. descent-mass >= 56 charge and the own56 ceiling (kappa <= .0134769139) -/ + +/-- F price of a descent list (owned MOVEs of ranks `k`): sum of k^s -/ +noncomputable def dprice (ks : List ℕ) (s : ℝ) : ℝ := (ks.map fun k : ℕ => ((k : ℕ) : ℝ) ^ s).sum + +/-- concavity chord on [1, 9] -/ +theorem chord_k (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s ≤ 1) (k : ℝ) (hk1 : 1 ≤ k) (hk9 : k ≤ 9) : + 1 + ((9 : ℝ) ^ s - 1) / 8 * (k - 1) ≤ k ^ s := by + have hc := (Real.concaveOn_rpow hs0 hs1).2 (show (1 : ℝ) ∈ Set.Ici 0 by simp) (show (9 : ℝ) ∈ Set.Ici 0 by simp) + (show 0 ≤ (9 - k) / 8 by linarith) (show 0 ≤ (k - 1) / 8 by linarith) (show (9 - k) / 8 + (k - 1) / 8 = 1 by ring) + simp only [smul_eq_mul, Real.one_rpow] at hc + have e : (9 - k) / 8 * 1 + (k - 1) / 8 * 9 = k := by ring + rw [e] at hc + nlinarith + +theorem dprice_ge (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s ≤ 1) (ks : List ℕ) (hk : ∀ k ∈ ks, 1 ≤ k ∧ k ≤ 9) : + ks.length + ((9 : ℝ) ^ s - 1) / 8 * ((ks.sum : ℕ) - ks.length) ≤ dprice ks s := by + induction ks with + | nil => simp [dprice] + | cons a l ih => + have ha := hk a (by simp) + have hl : ∀ k ∈ l, 1 ≤ k ∧ k ≤ 9 := fun k hk' => hk k (by simp [hk']) + have ih := ih hl + have h1 := chord_k s hs0 hs1 (a : ℝ) (by exact_mod_cast ha.1) (by exact_mod_cast ha.2) + simp only [dprice, List.map_cons, List.sum_cons, List.length_cons] at ih ⊢ + simp only [Nat.cast_add, Nat.cast_one] + nlinarith + +/-- 9^s <= 8 * 2^s - 7 on [0,1] (convexity of u -> u^p, p = log_2 9, on [1,2]; equality at s = 0, 1). It gives +`(9 - 9^s)/8 >= 2 - 2^s`: an extra descent move is never cheaper than a forced stop it replaces. -/ +theorem nine_chord (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s ≤ 1) : (9 : ℝ) ^ s ≤ 8 * (2 : ℝ) ^ s - 7 := by + set p : ℝ := Real.logb 2 9 with hp + have h2p : (2 : ℝ) ^ p = 9 := Real.rpow_logb (by norm_num) (by norm_num) (by norm_num) + have hp1 : 1 ≤ p := by + have : (2 : ℝ) ^ (1 : ℝ) ≤ (2 : ℝ) ^ p := by rw [Real.rpow_one, h2p]; norm_num + exact (Real.rpow_le_rpow_left_iff (by norm_num : (1 : ℝ) < 2)).mp this + have hu1 : (1 : ℝ) ≤ (2 : ℝ) ^ s := Real.one_le_rpow (by norm_num) hs0 + have hu2 : (2 : ℝ) ^ s ≤ 2 := by + have := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 2 by norm_num) hs1; simpa using this + have hc := (convexOn_rpow hp1).2 (show (1 : ℝ) ∈ Set.Ici 0 by simp) (show (2 : ℝ) ∈ Set.Ici 0 by simp) + (show 0 ≤ 2 - (2 : ℝ) ^ s by linarith) (show 0 ≤ (2 : ℝ) ^ s - 1 by linarith) + (show (2 - (2 : ℝ) ^ s) + ((2 : ℝ) ^ s - 1) = 1 by ring) + simp only [smul_eq_mul, Real.one_rpow] at hc + have e : (2 - (2 : ℝ) ^ s) * 1 + ((2 : ℝ) ^ s - 1) * 2 = (2 : ℝ) ^ s := by ring + rw [e, h2p] at hc + have e2 : ((2 : ℝ) ^ s) ^ p = (9 : ℝ) ^ s := by + rw [← Real.rpow_mul (by norm_num), mul_comm, Real.rpow_mul (by norm_num), h2p] + rw [e2] at hc + nlinarith + +/-- **own56 floor (F currency, max rule)**: a rank-8 C = 56 decoder has descent mass >= 56 (hypothesis `hmass`, the F1 premise; descents are owned +MOVEs of rank k in 1..9), at least 8 descents and 8 rises (R1/R2). Charging the descents at their true F price `sum k^s` (>= 6 * 9^s + 2) and the 8 +rises at 1 each gives the floor `-400 8^s - (6 9^s + 10) - max (88 (2 - 2^s)) I`; extra moves beyond 8 + 8 cost at least what the stops they remove +save (`nine_chord`). -/ +theorem own56_floor (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s ≤ 1) (ks : List ℕ) (hk : ∀ k ∈ ks, 1 ≤ k ∧ k ≤ 9) + (hmass : 56 ≤ ks.sum) (hmd : 8 ≤ ks.length) (mr st : ℕ) (hmr : 8 ≤ mr) (Fn E I : ℝ) + (hF : Fn ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E) (hY : 104 ≤ st + (ks.length + mr)) + (hst : (2 - (2 : ℝ) ^ s) * st ≤ E) (hI : I ≤ E) : + Fn ≤ -400 * (8 : ℝ) ^ s - (6 * (9 : ℝ) ^ s + 10) - max (88 * (2 - (2 : ℝ) ^ s)) I := by + have hu1 : (1 : ℝ) ≤ (2 : ℝ) ^ s := Real.one_le_rpow (by norm_num) hs0 + have hu2 : (2 : ℝ) ^ s ≤ 2 := by + have := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 2 by norm_num) hs1; simpa using this + have h9a : (1 : ℝ) ≤ (9 : ℝ) ^ s := Real.one_le_rpow (by norm_num) hs0 + have h9b : (9 : ℝ) ^ s ≤ 9 := by + have := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 9 by norm_num) hs1; simpa using this + have hch := nine_chord s hs0 hs1 + have hdp := dprice_ge s hs0 hs1 ks hk + set c : ℝ := 2 - (2 : ℝ) ^ s with hc + have hc0 : 0 ≤ c := by linarith + have hc1 : c ≤ 1 := by linarith + set b : ℝ := ((9 : ℝ) ^ s - 1) / 8 with hb + have hb0 : 0 ≤ b := by rw [hb]; linarith + have hcb : c ≤ 1 - b := by rw [hb, hc]; linarith + have hm : (8 : ℝ) ≤ ks.length := by exact_mod_cast hmd + have hmr' : (8 : ℝ) ≤ mr := by exact_mod_cast hmr + have hmass' : (56 : ℝ) ≤ ((ks.sum : ℕ) : ℝ) := by exact_mod_cast hmass + have hY' : (104 : ℝ) ≤ st + (ks.length + mr) := by exact_mod_cast hY + have hst0 : (0 : ℝ) ≤ st := Nat.cast_nonneg _ + have hE0 : 0 ≤ E := le_trans (mul_nonneg hc0 hst0) hst + have hA : (ks.length : ℝ) + b * (56 - ks.length) ≤ dprice ks s := by + have : b * (56 - ks.length) ≤ b * (((ks.sum : ℕ) : ℝ) - ks.length) := mul_le_mul_of_nonneg_left (by linarith) hb0 + linarith + have e9 : (9 : ℝ) ^ s = 8 * b + 1 := by rw [hb]; ring + rw [e9] + suffices h : (6 * (8 * b + 1) + 10) + max (88 * c) I ≤ dprice ks s + mr + E by linarith + have hx : 0 ≤ ((ks.length : ℝ) - 8) * (1 - b - c) := mul_nonneg (by linarith) (by linarith) + have hy : 0 ≤ ((mr : ℝ) - 8) * (1 - c) := mul_nonneg (by linarith) (by linarith) + have hxb : 0 ≤ ((ks.length : ℝ) - 8) * b := mul_nonneg (by linarith) hb0 + rcases le_total (88 * c) I with h | h + · rw [max_eq_right h] + have hx2 : 0 ≤ ((ks.length : ℝ) - 8) * (1 - b) := mul_nonneg (by linarith) (by linarith) + nlinarith + · rw [max_eq_left h] + have h3 : c * (104 - ks.length - mr) ≤ c * st := mul_le_mul_of_nonneg_left (by linarith) hc0 + nlinarith + +/-- the cap/correction form of I3 without plane separation (LIFT1 sec. 1; HYPOTHESIS, valid under the public-provenance direction law only): +transport by owned rank caps each pair's contribution at `cap` and the 8 relaxation rises save at most `corr`. -/ +def I3Cap (J : Finset (ℕ × ℕ)) (dist : ℕ × ℕ → ℝ) (cap corr E : ℝ) : Prop := ∑ p ∈ J, min (dist p) cap - corr ≤ E + +def tbarC : ℚ := 134769139 / 10 ^ 10 +theorem sC_eq : sC = 1 - tbarC := by unfold sC tbarC; norm_num + +def natBaseC : Inv := ⟨[], [(8, 400), (9, 6), (1, 10)]⟩ +theorem natBaseC_F (s : ℝ) : Finv s natBaseC = -(400 * (8 : ℝ) ^ s + (6 * (9 : ℝ) ^ s + 10)) := by + simp [Finv, natBaseC, Fh] +theorem baseC_eq (s : ℝ) : Finv s (invoice (caller 6 7) natBaseC 17) = Fc cfC s := by + simp only [Finv, Fh, invoice, caller, callerT, callerP, armT, armP, natBaseC, scale, Fc, cfC, + List.range_succ, List.range_zero] + norm_num + ring +theorem base88_eq (s : ℝ) : + Finv s (invoice (caller 6 7) natBaseC 17) - 17 * (88 * (2 - (2 : ℝ) ^ s)) = Fc cfC88 s := by + rw [baseC_eq] + simp only [Fc, cfC, cfC88, List.map_cons, List.sum_cons, List.map_nil, List.sum_nil] + push_cast + simp only [Real.one_rpow] + ring + +/-- **own56 ceiling, 8|9 (kappa <= .0134769139)**: as `ceiling_A` but (i) the descent mass >= 56 of the rank-8 C = 56 decoder is charged +(`own56_floor`), and (ii) plane separation is NOT assumed: the junk lift is the capped, corrected one (`I3Cap`, LIFT1), valid under the +public-provenance direction law `Prov` (LIFT1 (i) junk reflux, (ii) non-monotone owned lifetimes, (iii) >= 9-row/network decoders are OPEN and are +exactly what `Prov`/`Rank8C56` stand for here; rank-8 decoders with C = 57 do not exist and C >= 58 is not covered by the junk bound 1936). +Data hypotheses: `hdist` (per-pair `ell s <= min dist cap`, from sp_F and unit/48), `hLc` (1936 * ell - corr >= 13.64105 on [tbarC, .1], python, +monotone numerically). -/ +theorem ceiling_C (MV Rank8C56 Prov : Prop) (hMV : MV) (hR : Rank8C56) (hP : Prov) + (n : Inv) (ks : List ℕ) (mr st : ℕ) (E cap corr ell : ℝ → ℝ) (J : Finset (ℕ × ℕ)) (distF : ℝ → ℕ × ℕ → ℝ) + (hk : ∀ k ∈ ks, 1 ≤ k ∧ k ≤ 9) (hmass : 56 ≤ ks.sum) (hmd : 8 ≤ ks.length) (hmr : 8 ≤ mr) (hcorr0 : ∀ s, 0 ≤ corr s) + (hF : ∀ s, 0 ≤ s → s ≤ 1 → Finv s n ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E s) + (hY : 104 ≤ st + (ks.length + mr)) + (hst : ∀ s, 0 ≤ s → s ≤ 1 → (2 - (2 : ℝ) ^ s) * st ≤ E s) + (hI3 : MV → Rank8C56 → Prov → ∀ s, 0 ≤ s → s ≤ 1 → I3Cap J (distF s) (cap s) (corr s) (E s)) + (hdist : ∀ s, 9 / 10 ≤ s → s ≤ ((sC : ℚ) : ℝ) → ∀ p ∈ J, ell s ≤ min (distF s p) (cap s)) + (hLc : ∀ s, 9 / 10 ≤ s → s ≤ ((sC : ℚ) : ℝ) → ((LcC : ℚ) : ℝ) ≤ 1936 * ell s - corr s) + (hJ : 1936 ≤ J.card) : + ∀ t : ℝ, ((tbarC : ℚ) : ℝ) ≤ t → t ≤ 1 → Finv (1 - t) (invoice (caller 6 7) n 17) < 0 := by + intro t ht ht1 + have hsC : ((sC : ℚ) : ℝ) = 1 - ((tbarC : ℚ) : ℝ) := by rw [sC_eq]; push_cast; ring + have htb0 : (0 : ℝ) ≤ ((tbarC : ℚ) : ℝ) := by unfold tbarC; norm_num + have htb1 : ((tbarC : ℚ) : ℝ) ≤ 1 / 10 := by unfold tbarC; norm_num + have hs0 : (0 : ℝ) ≤ 1 - t := by linarith + have hs1 : 1 - t ≤ 1 := by linarith + have hu1 : (1 : ℝ) ≤ (2 : ℝ) ^ (1 - t) := Real.one_le_rpow (by norm_num) hs0 + have hu2 : (2 : ℝ) ^ (1 - t) ≤ 2 := by + have := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 2 by norm_num) hs1; simpa using this + have hE0 : 0 ≤ E (1 - t) := + le_trans (mul_nonneg (by linarith) (Nat.cast_nonneg st)) (hst _ hs0 hs1) + have h2 := invoice_F (1 - t) (caller 6 7) n 17 + have h3 := invoice_F (1 - t) (caller 6 7) natBaseC 17 + have h4 := natBaseC_F (1 - t) + push_cast at h2 h3 + rcases le_or_gt (1 / 10 : ℝ) t with h10 | h10 + · have h1 := own56_floor (1 - t) hs0 hs1 ks hk hmass hmd mr st hmr (Finv (1 - t) n) (E (1 - t)) 0 (hF _ hs0 hs1) hY + (hst _ hs0 hs1) hE0 + have hc0 : (0 : ℝ) ≤ 88 * (2 - (2 : ℝ) ^ (1 - t)) := by linarith + rw [max_eq_left hc0] at h1 + have h5 := cfC88_neg (1 - t) hs0 (by linarith) + have h6 := base88_eq (1 - t) + nlinarith + · have hsl : (9 / 10 : ℝ) ≤ 1 - t := by linarith + have hsr : 1 - t ≤ ((sC : ℚ) : ℝ) := by rw [hsC]; linarith + have hcap := hI3 hMV hR hP _ hs0 hs1 + unfold I3Cap at hcap + have hLc' := hLc _ hsl hsr + have hLcpos : (0 : ℝ) < ((LcC : ℚ) : ℝ) := by unfold LcC; norm_num + have hell : 0 ≤ ell (1 - t) := by have := hcorr0 (1 - t); nlinarith + have hsum : (1936 : ℝ) * ell (1 - t) ≤ ∑ p ∈ J, min (distF (1 - t) p) (cap (1 - t)) := by + have := Finset.card_nsmul_le_sum J (fun p => min (distF (1 - t) p) (cap (1 - t))) (ell (1 - t)) (hdist _ hsl hsr) + rw [nsmul_eq_mul] at this + have hj : (1936 : ℝ) ≤ J.card := by exact_mod_cast hJ + nlinarith + have hE : ((LcC : ℚ) : ℝ) ≤ E (1 - t) := by linarith + have h1 := own56_floor (1 - t) hs0 hs1 ks hk hmass hmd mr st hmr (Finv (1 - t) n) (E (1 - t)) ((LcC : ℚ) : ℝ) (hF _ hs0 hs1) hY + (hst _ hs0 hs1) hE + have h1' : Finv (1 - t) n ≤ -400 * (8 : ℝ) ^ (1 - t) - (6 * (9 : ℝ) ^ (1 - t) + 10) - ((LcC : ℚ) : ℝ) := by + have := le_max_right (88 * (2 - (2 : ℝ) ^ (1 - t))) ((LcC : ℚ) : ℝ) + linarith + have h5 := cfC_neg (1 - t) hsl hsr + have h6 := baseC_eq (1 - t) + have h7 : ((liftC : ℚ) : ℝ) = 17 * ((LcC : ℚ) : ℝ) := by unfold liftC; push_cast; ring + nlinarith + +end CongestionI3 + +#print axioms CongestionI3.forced_junk_ge +#print axioms CongestionI3.f1_floor +#print axioms CongestionI3.ceiling_A +#print axioms CongestionI3.chord_k +#print axioms CongestionI3.dprice_ge +#print axioms CongestionI3.nine_chord +#print axioms CongestionI3.own56_floor +#print axioms CongestionI3.ceiling_C diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3.md b/research/p104-native-ceiling/lean/Nov15/CongestionI3.md new file mode 100644 index 0000000000..f4043c17df --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3.md @@ -0,0 +1,21 @@ +# CongestionI3*.lean: the I3 congestion bound and F1's restricted-class ceilings in Lean +Files (build order, each with `-o .lake/build/lib/lean/Nov15/.olean`, the memory-guarded build script, <= 3.5 GB): CongestionI3Data (11 s), CongestionI3Cfg (121 s / 3.37 GB), CongestionI3Mu (5 s), CongestionI3NumA (35 s / 3.2 GB), CongestionI3NumC1..C4 (34/31/28/17 s, <= 3.2 GB), CongestionI3 (24 s / 3.0 GB). Kernel only: no sorry, no native_decide; every `#print axioms` is within [propext, Classical.choice, Quot.sound]. The numeric files are split only for the memory guard (NumCertK interval checks, as in WholeFloorCoverData). +Sources: internal notes (not included in this package). + +## What is proved (kernel) +- **(1) per pair.** `pair_bound`: per-pair minimum delta => E >= delta |J|; `i3_D0_per_call`: 0.541495 per pair and |J| >= 1936 give >= 1048.33 D0/call. I3 itself is the HYPOTHESIS `I3Path J dist E` (sum of path distances <= public excess, model M_V): the telescoping/path bound is NOT formalised, and the shape-DAG minimum (0.541495 in D0, `sigma0` = 9785438/10^9 <= sp_F(t) in F currency) is a data hypothesis (230-shape DAG, f1ceil.py). +- **(2) forced junk >= 1936.** `cfgs` = the 8 valid rank-8 C = 56 configurations (f1enum, z.z' = 0); kernel: `cfgs_ok` (8 rows each, z.z' = 0 on the F2^9 labels `Ulab`), `cfg_uniq0..7` (every chain of every configuration has exactly 330 unique cells = 2640 per configuration, recomputed from `Ulab`/`Gmask`), `uniqCells_disjoint` (a unique cell belongs to one chain). `forced_junk_ge`: if the forced cells F k of chain k are unique cells (hsub), lie in supp J (hJ) and number >= mu(i,k) (hDP), then |J| >= sum_k mu = 1936 (`mu_sum`, kernel on the table `muTab`, all entries 242, from the per-chain rerun f1dp_chain_*.log; per-config sums reproduce f1dp.log). hDP is the python flag-DP minimum over the subspace lattice: DATA, not kernel-checked (a kernel re-run would be ~64 chain DPs). +- **(3) max, not sum.** `f1_floor`: from hF (F <= -400 8^s - mp - E), mp >= 16, st + mp >= 104 (lat = 0, nested words), E >= (2 - 2^s) st (R3's stops) and E >= I (I3): F <= -400 8^s - 16 - max(88 (2 - 2^s), I). I = 0 is R3's -Nfl. `sum_not_implied` records that the sum is not a consequence (E = max satisfies both bounds). +- **(4a) ceiling 8|9, kappa <= .0183952347.** `ceiling_A`: for t in [tbarA = .0183952347, 1], F(1 - t) < 0 on the 17-call #7113 invoice. t >= .1: f1_floor with I = 0 + WholeFloorCover.cover (R3). t in [tbar, .1): lift 17 * 1936 * sigma0 against `cfB_neg`: three Fup pieces on [.9, .93], dF/ds > 0 on [.93, 1 - tbar] (`Fc_mono`) and F_base(s0) < 17 * 1936 * sigma0 at the endpoint (true F_base(s0) = 322.05830, lift 322.05834; python root .0183952344, so .0183952347 is rounded up). +- **(4b) ceiling with descent mass >= 56, kappa <= .0134769139.** `own56_floor`: descents are owned MOVEs of rank k in 1..9 with sum >= 56 (rank-8 C = 56 premise), >= 8 descents and >= 8 rises: F price sum k^s >= 6 9^s + 2 (`chord_k`, `dprice_ge`: concavity chord on [1,9]); extra moves beyond 8 + 8 cost at least the stops they remove save, by `nine_chord` (9^s <= 8 2^s - 7 on [0,1], convexity of u -> u^(log_2 9); so (9 - 9^s)/8 >= 2 - 2^s). This RE-DERIVES the m-tradeoff at the own56 base, which LIFT1/f1ceil only assume (python charges the fixed 6x9 + 2x1 + 8 rises; the Lean statement shows it is sound). `ceiling_C`: F < 0 on [tbarC = .0134769139, 1]: t >= .1 by cfC88_neg (13 pieces, = base + 88 stops), t in [tbar, .1) by cfC_neg (lift 17 * 13.64105; true F_base(sC) = 231.89777, lift 231.89785). + +## Scope and hypotheses (stated in the theorems; none discharged by the kernel unless marked) +- **M_V**: every public register except Y mains ends at V, owned code fixed, X_q born at A_q (AUDIT (1)). Hypothesis `MV` in `hI3`. NO known native is in M_V (224 of 1,501 public registers end at dim <= 7): the ceilings are NOT a floor on the native class; the control pass (S22/#7641/#7637 under both ceilings) is feasibility only. +- **rank-8, C = 56** decoder on P104 labels, one of the 8 enumerated configurations (index i < 8): exhaustiveness over the 12,870 subsets and rigidity M^ = D1 G D2 are quoted/numerical. LIFT2: C = 57 impossible; C = 58 elementary mixes give junk >= 2093 >= 1936, C = 60 sampled; C >= 59 general X only sampled; >= 9-row and network decoders open. The junk bound 1936 is the min over C = 56 EXACTLY (AUDIT-LIFT (3)): a C >= 58 decoder is not covered. `hJ`/`Rank8C56` carry this. +- **plane separation** (`PlaneSep`, ceiling_A): without it the LB collapses to 0 (f1k2). ceiling_C does not assume it but replaces it by the **public-provenance direction law** `Prov` + the cap/correction inequality `I3Cap` (LIFT1 sec. 1; AUDIT-LIFT (1): holders with owned origin/reflux (i), non-monotone owned lifetimes (ii), >= 9-row/network decoders (iii) are OPEN; the split LB 242 < break-even 578 is a count, not a proof). +- **data hypotheses**: `hdist` (per-pair sp_F lower bound on [tbar, .1]; sp_F increasing in t is numerical, the convex/superadditive proof was not re-derived, AUDIT (1)); `hLc` (N min(sp_F, unit/48) - corr >= 13.64105 on [tbarC, .1]; python lift1c, monotone numerically); `hDP` (flag-DP minima); `corr >= 0`. +- **nested** (lat = 0): `hY : 104 <= st + mp` is Theorem Y with lateral owned MOVEs excluded by the verifier nesting rule (WholeFloorNest); R3's port lemma/Theorem Y and slack-rank independence stay upstream. +- The D0 floor 171,478.76 is not formalised (LIFT1: it does not survive without plane separation: owned mass is a D0 credit). + +## Statements false as written +None found. Two points to read carefully: (a) the sum of I3 and R3's stops is NOT implied (`sum_not_implied`); only max is (F1 uses max). (b) F1.md's "k <= 4" for the joint table is not a restriction (AUDIT: k <= 17), not touched here. The own56 ceiling's R3 trade-off is TRUE (nine_chord). diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3Cfg.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3Cfg.lean new file mode 100644 index 0000000000..4d50ff918d --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3Cfg.lean @@ -0,0 +1,73 @@ +import Nov15.CongestionI3Data + +/-! +CONGESTION-I3 configuration half . Kernel-checked facts about the 8 rank-8 C=56 decoder configurations +(internal notes sec. 2): z.z' = 0, and the census of the "unique" even cells (cells that exactly one chain can touch). +`dot` = F2 dot product of 9-bit labels; chain k = (z_k, z'_k) (virtual lines 104..119, labels `Ulab`); the chain k's support on the +cell (t, s) (t, s < 104) is G[t, z_k] * G[s, z'_k] (nonzero pattern `Gmask`). +-/ +set_option linter.constructorNameAsVariable false +namespace CongestionI3 + +/-- parity of the 9 low bits -/ +def par (x : ℕ) : ℕ := + let a := (x ^^^ (x >>> 4)) &&& 15 + let b := a ^^^ (a >>> 2) + ((b ^^^ (b >>> 1)) ^^^ (x >>> 8)) &&& 1 +theorem par_test : (List.range 512).all (fun x => par x == ((List.range 9).foldl (fun acc i => acc + (x >>> i) % 2) 0) % 2) = true := by decide +kernel +def dot (a b : ℕ) : ℕ := par (a &&& b) +def lab (i : ℕ) : ℕ := Ulab.getD i 0 +/-- G[t, z] ≠ 0 for t < 104, z in 104..119 -/ +def gnz (t z : ℕ) : Bool := ((Gmask.getD t 0) >>> (z - 104)) % 2 == 1 + +/-- the even cells: t ≠ s, q_t . q_s = 0 -/ +def even (t s : ℕ) : Bool := t != s && dot (lab t) (lab s) == 0 +/-- chains that may touch (t,s): q_t ⊥ z_k and q_s ⊥ z'_k (frames of the chain) -/ +def Kset (c : List (ℕ × ℕ)) (t s : ℕ) : List ℕ := + (List.range c.length).filter fun k => + dot (lab t) (lab (c.getD k (0, 0)).1) == 0 && dot (lab s) (lab (c.getD k (0, 0)).2) == 0 +/-- chains whose product is nonzero at (t,s) -/ +def Tset (c : List (ℕ × ℕ)) (t s : ℕ) : List ℕ := + (List.range c.length).filter fun k => gnz t (c.getD k (0, 0)).1 && gnz s (c.getD k (0, 0)).2 +/-- the unique cells of chain k: even, exactly one chain (k) may touch them, and it does -/ +def isUniq (c : List (ℕ × ℕ)) (k t s : ℕ) : Bool := even t s && Kset c t s == [k] && Tset c t s == [k] +def uniqCells (c : List (ℕ × ℕ)) (k : ℕ) : Finset (ℕ × ℕ) := + (Finset.range 104 ×ˢ Finset.range 104).filter fun p => isUniq c k p.1 p.2 = true + +/-- orthogonality z.z' = 0 for all rows -/ +def cfgOK (c : List (ℕ × ℕ)) : Bool := c.length == 8 && c.all fun p => dot (lab p.1) (lab p.2) == 0 +/-- chain index of every unique cell, one pass over the 104 x 104 cells -/ +def uniqOwners (c : List (ℕ × ℕ)) : List ℕ := + (List.range 104).flatMap fun t => (List.range 104).filterMap fun s => + if even t s then + (match Kset c t s with + | [k] => if Tset c t s == [k] then some k else none + | _ => none) + else none +def uniqCensus (c : List (ℕ × ℕ)) : List ℕ := (List.range 8).map fun k => (uniqOwners c).count k + +theorem cfgs_len : cfgs.length = 8 := by decide +kernel +theorem cfgs_ok : cfgs.all cfgOK = true := by decide +kernel +/-- every chain of every configuration has exactly 330 unique cells (2640 = 8 * 330 per configuration, F1 sec. 2); one theorem per +configuration (kernel memory is per declaration). -/ +theorem cfg_uniq0 : uniqCensus (cfgs.getD 0 []) = List.replicate 8 330 := by decide +kernel +theorem cfg_uniq1 : uniqCensus (cfgs.getD 1 []) = List.replicate 8 330 := by decide +kernel +theorem cfg_uniq2 : uniqCensus (cfgs.getD 2 []) = List.replicate 8 330 := by decide +kernel +theorem cfg_uniq3 : uniqCensus (cfgs.getD 3 []) = List.replicate 8 330 := by decide +kernel +theorem cfg_uniq4 : uniqCensus (cfgs.getD 4 []) = List.replicate 8 330 := by decide +kernel +theorem cfg_uniq5 : uniqCensus (cfgs.getD 5 []) = List.replicate 8 330 := by decide +kernel +theorem cfg_uniq6 : uniqCensus (cfgs.getD 6 []) = List.replicate 8 330 := by decide +kernel +theorem cfg_uniq7 : uniqCensus (cfgs.getD 7 []) = List.replicate 8 330 := by decide +kernel + +theorem uniqCells_disjoint (c : List (ℕ × ℕ)) {k k' : ℕ} (h : k ≠ k') : Disjoint (uniqCells c k) (uniqCells c k') := by + rw [Finset.disjoint_left] + intro p hp hp' + simp only [uniqCells, Finset.mem_filter, isUniq, Bool.and_eq_true, beq_iff_eq] at hp hp' + have := hp.2.1.2.symm.trans hp'.2.1.2 + simp at this + exact h this + +end CongestionI3 + +#print axioms CongestionI3.cfg_uniq7 +#print axioms CongestionI3.uniqCells_disjoint diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3Data.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3Data.lean new file mode 100644 index 0000000000..4f0921cc87 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3Data.lean @@ -0,0 +1,26 @@ +import Mathlib.Data.Finset.Basic +import Mathlib.Data.Finset.Card +import Mathlib.Data.Finset.Prod +import Mathlib.Data.Finset.Powerset +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Mathlib.Order.Interval.Finset.Nat + +/-! +CONGESTION-I3 data : the 8 valid rank-8 C=56 decoder configurations of internal notes (f1enum.py, z.z'=0), +the F2^9 labels U of the 120 E8 lines (PORTSET geo.py), the nonzero pattern of G[t,z] for t<104, z in 104..119, and the per-chain +flag-DP minima mu (internal notes,b}.log, a rerun of f1dp.py printing per-chain values). +-/ +namespace CongestionI3 + +def Ulab : List ℕ := [11, 19, 35, 131, 259, 13, 21, 37, 69, 133, 261, 41, 73, 265, 49, 145, 161, 193, 321, 385, 14, 22, 38, 70, 134, 26, 74, 138, 50, 146, 274, 194, 322, 386, 28, 44, 140, 84, 148, 276, 100, 292, 196, 324, 388, 56, 88, 152, 168, 296, 200, 328, 392, 112, 176, 304, 208, 336, 400, 224, 352, 416, 508, 506, 502, 494, 478, 446, 382, 254, 505, 501, 493, 477, 445, 381, 253, 499, 475, 443, 379, 251, 487, 471, 439, 375, 247, 463, 431, 367, 239, 415, 351, 223, 319, 191, 81, 98, 164, 262, 268, 273, 280, 290, 42, 266, 25, 137, 7, 67, 448, 104, 76, 82, 162, 97, 289, 127, 52, 491] +def Gmask : List ℕ := [16511, 33780, 7537, 26040, 29106, 34652, 17623, 55890, 36147, 41627, 46737, 6861, 19884, 30222, 55622, 41359, 16138, 26731, 31841, 21449, 39251, 23256, 50269, 37692, 48276, 39495, 21411, 31755, 51017, 49024, 43914, 30308, 25198, 19910, 23908, 50145, 47912, 22283, 30883, 27817, 51598, 61996, 45383, 42317, 35557, 49397, 38804, 47164, 9913, 12979, 29144, 26066, 19066, 51866, 58674, 61752, 45651, 42585, 35313, 11478, 14556, 6004, 7695, 55596, 6579, 55864, 17597, 5084, 15476, 10366, 50979, 1980, 50231, 23218, 3539, 8827, 13937, 49311, 40337, 51952, 58712, 61778, 50059, 23822, 2671, 9671, 12749, 40581, 51684, 58956, 62022, 22369, 30921, 27843, 12200, 15266, 36391, 3757, 58918, 43166, 44834, 46469, 44086, 13583] +def cfgs : List (List (ℕ × ℕ)) := [[(104, 105), (106, 107), (108, 109), (110, 118), (111, 115), (112, 116), (114, 117), (119, 113)], + [(104, 110), (105, 118), (111, 108), (112, 119), (114, 106), (115, 109), (116, 113), (117, 107)], + [(104, 111), (105, 115), (106, 119), (107, 113), (110, 108), (114, 112), (117, 116), (118, 109)], + [(104, 114), (105, 117), (108, 119), (109, 113), (110, 106), (111, 112), (115, 116), (118, 107)], + [(105, 104), (107, 106), (109, 108), (113, 119), (115, 111), (116, 112), (117, 114), (118, 110)], + [(106, 110), (107, 118), (112, 111), (113, 109), (114, 104), (116, 115), (117, 105), (119, 108)], + [(106, 114), (107, 117), (108, 111), (109, 115), (110, 104), (113, 116), (118, 105), (119, 112)], + [(108, 110), (109, 118), (111, 104), (112, 114), (113, 107), (115, 105), (116, 117), (119, 106)]] + +end CongestionI3 diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualAlg.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualAlg.lean new file mode 100644 index 0000000000..47362970ba --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualAlg.lean @@ -0,0 +1,224 @@ +import Nov15.WordDuality +import Mathlib.Analysis.MeanInequalitiesPow +import Mathlib.Analysis.SpecialFunctions.Pow.NNReal + +/-! +CONGESTION-I3-DUAL, algebra half. Source: internal notes (audited SOUND, i3dual/audit/AUD.md). +Two-sided I3: the excess of one public register is telescoped from the END (h9 charge, needs e = 9) or from the BIRTH (k0 charge, needs d0 = 0); +every move of a non-mixed register carries a charge >= c2 = min (h9, k0), and a mixed register (d0 >= 1, e <= 8) loses at most c2 (d0, e). +Kernel only; no sorry, no native_decide. `g` is an arbitrary price function with g 0 = 0 (instance: `gs s x = x^s`, s = 1 - t). +Nothing numeric here. See CongestionI3Dual.md. +-/ +namespace CongestionI3Dual +open Finset WordDuality + +/-! ### 1. move prices -/ + +/-- end-anchored move price (target V = dim 9): g(b-a) + g(9-b) - g(9-a) -/ +def h9 (g : ℝ → ℝ) (a b : ℝ) : ℝ := g (b - a) + g (9 - b) - g (9 - a) +/-- start-anchored move price (birth {0}): g(b-a) + g(a) - g(b) -/ +def k0 (g : ℝ → ℝ) (a b : ℝ) : ℝ := g (b - a) + g a - g b +/-- the uniform charge of ID1 sec. 1 -/ +def c2 (g : ℝ → ℝ) (a b : ℝ) : ℝ := min (h9 g a b) (k0 g a b) + +/-- the price function of the F currency: x^s on x > 0, and 0 at 0 -/ +noncomputable def gs (s : ℝ) (x : ℝ) : ℝ := if 0 < x then x ^ s else 0 +theorem gs_zero (s : ℝ) : gs s 0 = 0 := by simp [gs] + +/-- x^s is subadditive on [0, inf) for 0 <= s <= 1 -/ +theorem gs_subadd (s : ℝ) (hs0 : 0 ≤ s) (hs1 : s ≤ 1) (x y : ℝ) (hx : 0 ≤ x) (hy : 0 ≤ y) : + gs s (x + y) ≤ gs s x + gs s y := by + have key : (x + y) ^ s ≤ x ^ s + y ^ s := by + have := NNReal.rpow_add_le_add_rpow x.toNNReal y.toNNReal hs0 hs1 + have h3 : ((x.toNNReal + y.toNNReal) ^ s : NNReal) ≤ (x.toNNReal ^ s + y.toNNReal ^ s : NNReal) := this + have h4 := (NNReal.coe_le_coe.mpr h3) + simpa [NNReal.coe_rpow, Real.coe_toNNReal _ hx, Real.coe_toNNReal _ hy] using h4 + unfold gs + by_cases hx0 : 0 < x + · by_cases hy0 : 0 < y + · rw [if_pos hx0, if_pos hy0, if_pos (by linarith)]; exact key + · have : y = 0 := le_antisymm (not_lt.mp hy0) hy + subst this; simp + · have : x = 0 := le_antisymm (not_lt.mp hx0) hx + subst this; simp + +/-- the two prices are >= 0 for a subadditive g with g 0 = 0 on 0 <= a <= b <= 9 -/ +theorem h9_nonneg (g : ℝ → ℝ) (hg : ∀ x y, 0 ≤ x → 0 ≤ y → g (x + y) ≤ g x + g y) (a b : ℝ) (hab : a ≤ b) (hb : b ≤ 9) : + 0 ≤ h9 g a b := by + have := hg (b - a) (9 - b) (by linarith) (by linarith) + have e : b - a + (9 - b) = 9 - a := by ring + rw [e] at this; unfold h9; linarith +theorem k0_nonneg (g : ℝ → ℝ) (hg : ∀ x y, 0 ≤ x → 0 ≤ y → g (x + y) ≤ g x + g y) (a b : ℝ) (ha : 0 ≤ a) (hab : a ≤ b) : + 0 ≤ k0 g a b := by + have := hg (b - a) a (by linarith) ha + have e : b - a + a = b := by ring + rw [e] at this; unfold k0; linarith + +/-- duality at the level of move prices (DU1): the start-anchored price of (a,b) is the end-anchored price of the swapped move +`swapN 9 (a,b) = (9-b, 9-a)` of WordDuality. -/ +theorem k0_eq_h9_swapN (g : ℝ → ℝ) (a b : ℕ) (hb : b ≤ 9) (hab : a ≤ b) : + k0 g a b = h9 g (swapN 9 (a, b)).1 (swapN 9 (a, b)).2 := by + simp only [swapN, k0, h9] + have h1 : (((9 - b : ℕ) : ℕ) : ℝ) = 9 - b := by rw [Nat.cast_sub hb]; norm_num + have h2 : (((9 - a : ℕ) : ℕ) : ℝ) = 9 - a := by rw [Nat.cast_sub (le_trans hab hb)]; norm_num + rw [h1, h2] + have e1 : (9 - (a : ℝ)) - (9 - b) = b - a := by ring + have e2 : (9 : ℝ) - (9 - a) = a := by ring + have e3 : (9 : ℝ) - (9 - b) = b := by ring + rw [e1, e2, e3] + +/-- the dual helper (WordDuality `dualH 9`) has the same move prices: its end-anchored charge list is the start-anchored charge list of the +original (reversed order, equal sum). -/ +theorem dualH_charge (g : ℝ → ℝ) (h : FibreK.Helper) (hs : ∀ s ∈ h.steps, s.2 ≤ 9 ∧ s.1 ≤ s.2) : + (((dualH 9 h).steps).map fun s : ℕ × ℕ => h9 g s.1 s.2).sum = (h.steps.map fun s : ℕ × ℕ => k0 g s.1 s.2).sum := by + simp only [dualH, List.map_reverse, List.sum_reverse, List.map_map] + congr 1 + apply List.map_congr_left + intro s hs' + obtain ⟨h1, h2⟩ := hs s hs' + simp only [Function.comp] + exact (k0_eq_h9_swapN g s.1 s.2 h1 h2).symm + +/-! ### 2. one register: telescoping -/ + +/-- a register path: levels `d 0, ..., d n` (born at `d 0`, ending at `d n`); its excess over R3's floor is +`ex = sum g(gaps) - g(e - d0)` (ID1 sec. 1). -/ +def gsum (g : ℝ → ℝ) (d : ℕ → ℝ) (n : ℕ) : ℝ := ∑ i ∈ range n, g (d (i + 1) - d i) +def ex (g : ℝ → ℝ) (d : ℕ → ℝ) (n : ℕ) : ℝ := gsum g d n - g (d n - d 0) + +/-- end-anchored telescoping: for e = 9 the h9 charges sum to the excess -/ +theorem sum_h9_eq (g : ℝ → ℝ) (hg0 : g 0 = 0) (d : ℕ → ℝ) (n : ℕ) (he : d n = 9) : + ∑ i ∈ range n, h9 g (d i) (d (i + 1)) = ex g d n := by + have t : ∑ i ∈ range n, (g (9 - d (i + 1)) - g (9 - d i)) = g (9 - d n) - g (9 - d 0) := + Finset.sum_range_sub (fun i => g (9 - d i)) n + have h : ∑ i ∈ range n, h9 g (d i) (d (i + 1)) = gsum g d n + ∑ i ∈ range n, (g (9 - d (i + 1)) - g (9 - d i)) := by + unfold h9 gsum; rw [← Finset.sum_add_distrib]; apply Finset.sum_congr rfl; intro i _; ring + rw [h, t, he]; unfold ex + have e : (9 : ℝ) - 9 = 0 := by ring + rw [e, hg0, he]; ring + +/-- start-anchored telescoping: for d0 = 0 the k0 charges sum to the excess -/ +theorem sum_k0_eq (g : ℝ → ℝ) (hg0 : g 0 = 0) (d : ℕ → ℝ) (n : ℕ) (hd : d 0 = 0) : + ∑ i ∈ range n, k0 g (d i) (d (i + 1)) = ex g d n := by + have t : ∑ i ∈ range n, (g (d i) - g (d (i + 1))) = g (d 0) - g (d n) := by + have := Finset.sum_range_sub (fun i => g (d i)) n + have h2 : ∑ i ∈ range n, (g (d i) - g (d (i + 1))) = -∑ i ∈ range n, (g (d (i + 1)) - g (d i)) := by + rw [← Finset.sum_neg_distrib]; apply Finset.sum_congr rfl; intro i _; ring + rw [h2, this]; ring + have h : ∑ i ∈ range n, k0 g (d i) (d (i + 1)) = gsum g d n + ∑ i ∈ range n, (g (d i) - g (d (i + 1))) := by + unfold k0 gsum; rw [← Finset.sum_add_distrib]; apply Finset.sum_congr rfl; intro i _; ring + rw [h, t, hd]; unfold ex + rw [hd, hg0]; ring_nf + +/-- **non-mixed register: every move is charged >= c2 and the charges sum to the excess** (ID1 sec. 1, `charge_V`/`charge_Z`). -/ +theorem nonmixed_charge (g : ℝ → ℝ) (hg0 : g 0 = 0) (d : ℕ → ℝ) (n : ℕ) (h : d n = 9 ∨ d 0 = 0) : + ∃ w : ℕ → ℝ, (∀ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ w i) ∧ ∑ i ∈ range n, w i = ex g d n := by + rcases h with h | h + · exact ⟨fun i => h9 g (d i) (d (i + 1)), fun i _ => min_le_left _ _, sum_h9_eq g hg0 d n h⟩ + · exact ⟨fun i => k0 g (d i) (d (i + 1)), fun i _ => min_le_right _ _, sum_k0_eq g hg0 d n h⟩ + +/-- **the slack of any register** (covers mixed registers, ID1 sec. 2): the c2-charges sum to at most the excess plus c2 of the whole register. +No hypothesis on g or on the levels: pointwise `c2 <= g(gap) - max (g(9-a)-g(9-b), g(b)-g(a))`, and both maxima telescope. -/ +theorem sum_c2_le (g : ℝ → ℝ) (d : ℕ → ℝ) (n : ℕ) : + ∑ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ ex g d n + c2 g (d 0) (d n) := by + have t1 : ∑ i ∈ range n, (g (9 - d (i + 1)) - g (9 - d i)) = g (9 - d n) - g (9 - d 0) := + Finset.sum_range_sub (fun i => g (9 - d i)) n + have t2 : ∑ i ∈ range n, (g (d i) - g (d (i + 1))) = g (d 0) - g (d n) := by + have := Finset.sum_range_sub (fun i => g (d i)) n + have h2 : ∑ i ∈ range n, (g (d i) - g (d (i + 1))) = -∑ i ∈ range n, (g (d (i + 1)) - g (d i)) := by + rw [← Finset.sum_neg_distrib]; apply Finset.sum_congr rfl; intro i _; ring + rw [h2, this]; ring + have A : ∑ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ ex g d n + h9 g (d 0) (d n) := by + have : ∑ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ ∑ i ∈ range n, (g (d (i + 1) - d i) + (g (9 - d (i + 1)) - g (9 - d i))) := by + apply Finset.sum_le_sum; intro i _ + have : c2 g (d i) (d (i + 1)) ≤ h9 g (d i) (d (i + 1)) := min_le_left _ _ + unfold h9 at this; linarith + rw [Finset.sum_add_distrib, t1] at this + unfold ex gsum h9 at *; linarith + have B : ∑ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ ex g d n + k0 g (d 0) (d n) := by + have : ∑ i ∈ range n, c2 g (d i) (d (i + 1)) ≤ ∑ i ∈ range n, (g (d (i + 1) - d i) + (g (d i) - g (d (i + 1)))) := by + apply Finset.sum_le_sum; intro i _ + have : c2 g (d i) (d (i + 1)) ≤ k0 g (d i) (d (i + 1)) := min_le_right _ _ + unfold k0 at this; linarith + rw [Finset.sum_add_distrib, t2] at this + unfold ex gsum k0 at *; linarith + unfold c2 + rcases le_total (h9 g (d 0) (d n)) (k0 g (d 0) (d n)) with h | h + · rw [min_eq_left h]; exact A + · rw [min_eq_right h]; exact B + +/-- non-mixed (born at 0 or ending at 9): c2 of the whole register vanishes -/ +theorem c2_total_nonmixed (g : ℝ → ℝ) (hg0 : g 0 = 0) (a e : ℝ) (h : e = 9 ∨ a = 0) : c2 g a e ≤ 0 := by + unfold c2 + rcases h with h | h + · subst h; have : h9 g a 9 = g 0 := by unfold h9; simp + rw [hg0] at this; exact le_trans (min_le_left _ _) this.le + · subst h; have : k0 g 0 e = g 0 := by unfold k0; simp + rw [hg0] at this; exact le_trans (min_le_right _ _) this.le + +/-! ### 3. many registers: <= m mixed -/ + +section Many +variable {ι : Type*} [DecidableEq ι] + +/-- a register is MIXED if it is born above {0} and ends below V (levels are dims) -/ +def Mixed (d : ι → ℕ → ℕ) (n : ι → ℕ) (r : ι) : Prop := 1 ≤ d r 0 ∧ d r (n r) ≤ 8 +instance (d : ι → ℕ → ℕ) (n : ι → ℕ) (r : ι) : Decidable (Mixed d n r) := by unfold Mixed; infer_instance + +/-- the dim sequence of register `r` as reals -/ +def lev (d : ι → ℕ → ℕ) (r : ι) : ℕ → ℝ := fun i => (d r i : ℝ) + +/-- **summing over registers**: c2-charges of all moves <= total excess + (number of mixed registers) * sigma, where `sigma` bounds c2 of one +mixed register (dims 1 <= a <= b <= 8). -/ +theorem sum_all_c2_le (g : ℝ → ℝ) (hg0 : g 0 = 0) (R : Finset ι) (n : ι → ℕ) (d : ι → ℕ → ℕ) + (hmono : ∀ r ∈ R, ∀ i < n r, d r i ≤ d r (i + 1)) (hd9 : ∀ r ∈ R, d r (n r) ≤ 9) + (m : ℕ) (hm : (R.filter fun r => Mixed d n r).card ≤ m) (σ : ℝ) (hσ0 : 0 ≤ σ) + (hσ : ∀ a b : ℕ, 1 ≤ a → a ≤ b → b ≤ 8 → c2 g (a : ℝ) (b : ℝ) ≤ σ) : + ∑ r ∈ R, ∑ i ∈ range (n r), c2 g (lev d r i) (lev d r (i + 1)) ≤ ∑ r ∈ R, ex g (lev d r) (n r) + m * σ := by + have step : ∀ r ∈ R, ∑ i ∈ range (n r), c2 g (lev d r i) (lev d r (i + 1)) ≤ + ex g (lev d r) (n r) + (if Mixed d n r then σ else 0) := by + intro r hr + have h1 := sum_c2_le g (lev d r) (n r) + have hle : ∀ k ≤ n r, d r 0 ≤ d r k := by + intro k + induction k with + | zero => intro _; exact le_refl _ + | succ k ih => intro hk; exact le_trans (ih (by omega)) (hmono r hr k (by omega)) + have h0e := hle (n r) (le_refl _) + by_cases hmx : Mixed d n r + · rw [if_pos hmx] + have := hσ (d r 0) (d r (n r)) hmx.1 h0e hmx.2 + simp only [lev] at h1 ⊢ + linarith + · rw [if_neg hmx] + have hne : d r (n r) = 9 ∨ d r 0 = 0 := by + unfold Mixed at hmx + have := hd9 r hr + omega + have h2 := c2_total_nonmixed g hg0 (lev d r 0) (lev d r (n r)) + (by + rcases hne with h | h + · left; simp [lev, h] + · right; simp [lev, h]) + simp only [lev] at h1 h2 ⊢ + linarith + calc ∑ r ∈ R, ∑ i ∈ range (n r), c2 g (lev d r i) (lev d r (i + 1)) + ≤ ∑ r ∈ R, (ex g (lev d r) (n r) + (if Mixed d n r then σ else 0)) := Finset.sum_le_sum step + _ = ∑ r ∈ R, ex g (lev d r) (n r) + ∑ r ∈ R, (if Mixed d n r then σ else 0) := Finset.sum_add_distrib + _ ≤ ∑ r ∈ R, ex g (lev d r) (n r) + m * σ := by + have : ∑ r ∈ R, (if Mixed d n r then σ else 0) = ((R.filter fun r => Mixed d n r).card : ℝ) * σ := by + rw [← Finset.sum_filter]; simp + rw [this] + have hm' : ((R.filter fun r => Mixed d n r).card : ℝ) ≤ m := by exact_mod_cast hm + nlinarith + +end Many + +end CongestionI3Dual + +#print axioms CongestionI3Dual.gs_subadd +#print axioms CongestionI3Dual.k0_eq_h9_swapN +#print axioms CongestionI3Dual.dualH_charge +#print axioms CongestionI3Dual.nonmixed_charge +#print axioms CongestionI3Dual.sum_c2_le +#print axioms CongestionI3Dual.sum_all_c2_le diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC0.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC0.lean new file mode 100644 index 0000000000..75912b05b7 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC0.lean @@ -0,0 +1,5 @@ +import Nov15.CongestionI3DualSig +namespace CongestionI3Dual +open NumCertK +theorem sigC0 : sigOK (1 - tC1) (1 - tC0) sgC0 = true := by decide +kernel +end CongestionI3Dual diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC1.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC1.lean new file mode 100644 index 0000000000..55e0eb46d3 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC1.lean @@ -0,0 +1,5 @@ +import Nov15.CongestionI3DualSig +namespace CongestionI3Dual +open NumCertK +theorem sigC1 : sigOK (1 - tC2) (1 - tC1) sgC1 = true := by decide +kernel +end CongestionI3Dual diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC2.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC2.lean new file mode 100644 index 0000000000..87999f43fe --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC2.lean @@ -0,0 +1,5 @@ +import Nov15.CongestionI3DualSig +namespace CongestionI3Dual +open NumCertK +theorem sigC2 : sigOK (1 - tC3) (1 - tC2) sgC2 = true := by decide +kernel +end CongestionI3Dual diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC3.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC3.lean new file mode 100644 index 0000000000..ae82c32969 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualCertC3.lean @@ -0,0 +1,5 @@ +import Nov15.CongestionI3DualSig +namespace CongestionI3Dual +open NumCertK +theorem sigC3 : sigOK (9 / 10) (1 - tC3) sgC3 = true := by decide +kernel +end CongestionI3Dual diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualConst.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualConst.lean new file mode 100644 index 0000000000..192da15a75 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualConst.lean @@ -0,0 +1,43 @@ +import Mathlib.Data.Rat.Defs + +/-! CONGESTION-I3-DUAL constants: t-breakpoints of the pieces, certified sigma_j (Sig/Cert*), data lower bounds lcp_j +(python: internal notes; lcp_j = lower bound of 1936 spF(t_j) [8|9] resp. 1936 min(sp, cap) - 8 cst [own56], rounded down), L_j = lcp_j - 5 sigma_j. -/ +namespace CongestionI3Dual +-- 8|9 plain, m = 5: t-breakpoints +def tA0 : ℚ := 186470 / 10 ^ 7 +def tA1 : ℚ := 186490 / 10 ^ 7 +def tA2 : ℚ := 187490 / 10 ^ 7 +def tA3 : ℚ := 287490 / 10 ^ 7 +-- own56, m = 5 +def tC0 : ℚ := 136564 / 10 ^ 7 +def tC1 : ℚ := 136584 / 10 ^ 7 +def tC2 : ℚ := 137584 / 10 ^ 7 +def tC3 : ℚ := 237584 / 10 ^ 7 +def sgA0 : ℚ := 37981 / 500000 +def sgA1 : ℚ := 77257 / 10 ^ 6 +def sgA2 : ℚ := 213457 / 10 ^ 6 +def sgA3 : ℚ := 560567 / 500000 +def sgC0 : ℚ := 28029 / 500000 +def sgC1 : ℚ := 28683 / 500000 +def sgC2 : ℚ := 200709 / 10 ^ 6 +def sgC3 : ℚ := 1185727 / 10 ^ 6 + + +def lcpA0 : ℚ := 862761 / 50000 +def lcpA1 : ℚ := 17257043 / 10 ^ 6 +def lcpA2 : ℚ := 3469639 / 200000 +def lcpA3 : ℚ := 6597489 / 250000 +def LA0 : ℚ := lcpA0 - 5 * sgA0 +def LA1 : ℚ := lcpA1 - 5 * sgA1 +def LA2 : ℚ := lcpA2 - 5 * sgA2 +def LA3 : ℚ := lcpA3 - 5 * sgA3 +def lcpC0 : ℚ := 12418057 / 10 ^ 6 +def lcpC1 : ℚ := 248359 / 20000 +def lcpC2 : ℚ := 3079357 / 250000 +def lcpC3 : ℚ := 5022921 / 250000 +def LC0 : ℚ := lcpC0 - 5 * sgC0 +def LC1 : ℚ := lcpC1 - 5 * sgC1 +def LC2 : ℚ := lcpC2 - 5 * sgC2 +def LC3 : ℚ := lcpC3 - 5 * sgC3 + +end CongestionI3Dual diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualData.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualData.lean new file mode 100644 index 0000000000..ffe636e516 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualData.lean @@ -0,0 +1,12 @@ +import Nov15.CongestionI3DualConst +import Nov15.CongestionI3NumC4 +import Nov15.CongestionI3NumA + +namespace CongestionI3Dual +open NumCertK CongestionI3 + +/-- the tail pieces are covered by the F1 theorems `cfB_neg` / `cfC_neg` -/ +theorem LA3_ge : liftA ≤ 17 * LA3 := by unfold liftA sigma0 LA3 lcpA3 sgA3; norm_num +theorem LC3_ge : liftC ≤ 17 * LC3 := by unfold liftC LcC LC3 lcpC3 sgC3; norm_num + +end CongestionI3Dual diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualNumC.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualNumC.lean new file mode 100644 index 0000000000..965d2006a9 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualNumC.lean @@ -0,0 +1,8 @@ +import Nov15.CongestionI3DualConst +import Nov15.CongestionI3NumC4 +namespace CongestionI3Dual +open NumCertK CongestionI3 +theorem ptC0 : Fup cfC (1 - tC0) (1 - tC0) < 17 * LC0 := by unfold tC0 LC0 lcpC0 sgC0; decide +kernel +theorem ptC1 : Fup cfC (1 - tC1) (1 - tC1) < 17 * LC1 := by unfold tC1 LC1 lcpC1 sgC1; decide +kernel +theorem ptC2 : Fup cfC (1 - tC2) (1 - tC2) < 17 * LC2 := by unfold tC2 LC2 lcpC2 sgC2; decide +kernel +end CongestionI3Dual diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3DualSig.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualSig.lean new file mode 100644 index 0000000000..4f46eb66c0 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3DualSig.lean @@ -0,0 +1,78 @@ +import Nov15.CongestionI3DualAlg +import Nov15.NumCertK +import Nov15.CongestionI3DualConst + +/-! +CONGESTION-I3-DUAL, sigma certificates. `sigma(t)` = the largest c2 of one mixed register (dims 1 <= a <= b <= 8) is CERTIFIED here +on each t-piece by `NumCertK.Fup` (kernel interval arithmetic): for every pair (a,b), min(Fup h9, Fup k0) < sigma on the whole s-interval. So sigma needs +no monotonicity hypothesis: each piece carries its own certified bound. +-/ +namespace CongestionI3Dual +open NumCertK + +def h9CF (a b : ℕ) : CF := [(b - a, 1), (9 - b, 1), (9 - a, -1)] +def k0CF (a b : ℕ) : CF := [(b - a, 1), (a, 1), (b, -1)] + +theorem gs_nat (s : ℝ) (k : ℕ) (hk : 1 ≤ k) : gs s (k : ℝ) = (k : ℝ) ^ s := by + have : (0 : ℝ) < k := by exact_mod_cast hk + simp [gs, this] + +theorem h9_Fc (s : ℝ) (a b : ℕ) (ha : 1 ≤ a) (hab : a < b) (hb : b ≤ 8) : + h9 (gs s) (a : ℝ) (b : ℝ) = Fc (h9CF a b) s := by + have e1 : (b : ℝ) - a = ((b - a : ℕ) : ℝ) := by rw [Nat.cast_sub hab.le] + have e2 : (9 : ℝ) - b = ((9 - b : ℕ) : ℝ) := by rw [Nat.cast_sub (by omega)]; norm_num + have e3 : (9 : ℝ) - a = ((9 - a : ℕ) : ℝ) := by rw [Nat.cast_sub (by omega)]; norm_num + unfold h9; rw [e1, e2, e3, gs_nat s _ (by omega), gs_nat s _ (by omega), gs_nat s _ (by omega)] + simp [Fc, h9CF]; ring + +theorem k0_Fc (s : ℝ) (a b : ℕ) (ha : 1 ≤ a) (hab : a < b) (hb : b ≤ 8) : + k0 (gs s) (a : ℝ) (b : ℝ) = Fc (k0CF a b) s := by + have e1 : (b : ℝ) - a = ((b - a : ℕ) : ℝ) := by rw [Nat.cast_sub hab.le] + unfold k0; rw [e1, gs_nat s _ (by omega), gs_nat s _ ha, gs_nat s _ (by omega)] + simp [Fc, k0CF]; ring + +def pairs : List (ℕ × ℕ) := [(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8),(2,3),(2,4),(2,5),(2,6),(2,7),(2,8),(3,4),(3,5),(3,6),(3,7),(3,8), + (4,5),(4,6),(4,7),(4,8),(5,6),(5,7),(5,8),(6,7),(6,8),(7,8)] +theorem mem_pairs (a : ℕ) (ha : a < 9) (b : ℕ) (hb : b < 9) (h : 1 ≤ a ∧ a < b ∧ b ≤ 8) : (a, b) ∈ pairs := by + obtain ⟨h1, h2, h3⟩ := h + interval_cases a <;> interval_cases b <;> simp [pairs] at h2 h3 ⊢ + +def sigOK (lo hi σ : ℚ) : Bool := + pairs.all fun p => decide (Fup (h9CF p.1 p.2) lo hi < σ) || decide (Fup (k0CF p.1 p.2) lo hi < σ) + +theorem okR_h9CF (a b : ℕ) (ha : 1 ≤ a) (hab : a < b) (hb : b ≤ 8) : okR (h9CF a b) := by + intro p hp; simp [h9CF] at hp + rcases hp with h | h | h <;> subst h <;> simp <;> omega +theorem okR_k0CF (a b : ℕ) (ha : 1 ≤ a) (hab : a < b) (hb : b ≤ 8) : okR (k0CF a b) := by + intro p hp; simp [k0CF] at hp + rcases hp with h | h | h <;> subst h <;> simp <;> omega + +/-- **sigma certificate**: if `sigOK lo hi σ`, then for every s in [lo, hi], every 1 <= a <= b <= 8: c2 (gs s) a b <= σ (σ >= 0). -/ +theorem sig_of_ok (lo hi σ : ℚ) (hok : sigOK lo hi σ = true) (hlo : 0 ≤ lo) (hhi : hi ≤ 1) (hσ : 0 ≤ σ) (s : ℝ) + (h1 : (lo : ℝ) ≤ s) (h2 : s ≤ (hi : ℝ)) (a b : ℕ) (ha : 1 ≤ a) (hab : a ≤ b) (hb : b ≤ 8) : + c2 (gs s) (a : ℝ) (b : ℝ) ≤ (σ : ℝ) := by + rcases Nat.lt_or_ge a b with h | h + · have hm : (a, b) ∈ pairs := mem_pairs a (by omega) b (by omega) ⟨ha, h, hb⟩ + have := List.all_eq_true.mp hok (a, b) hm + simp only [Bool.or_eq_true, decide_eq_true_eq] at this + unfold c2 + rcases this with hh | hh + · have := Fc_le (h9CF a b) (okR_h9CF a b ha h hb) lo hi hlo hhi s h1 h2 + have h' : ((Fup (h9CF a b) lo hi : ℚ) : ℝ) < σ := by exact_mod_cast hh + rw [← h9_Fc s a b ha h hb] at this + exact le_trans (min_le_left _ _) (by linarith) + · have := Fc_le (k0CF a b) (okR_k0CF a b ha h hb) lo hi hlo hhi s h1 h2 + have h' : ((Fup (k0CF a b) lo hi : ℚ) : ℝ) < σ := by exact_mod_cast hh + rw [← k0_Fc s a b ha h hb] at this + exact le_trans (min_le_right _ _) (by linarith) + · have hba : a = b := le_antisymm hab h + subst hba + have h0 : h9 (gs s) (a : ℝ) (a : ℝ) = 0 := by unfold h9; simp [gs_zero] + have : c2 (gs s) (a : ℝ) (a : ℝ) ≤ 0 := by unfold c2; rw [h0]; exact min_le_left _ _ + have hσ' : (0 : ℝ) ≤ σ := by exact_mod_cast hσ + linarith + +/-! ### the pieces (t in [t_j, t_{j+1}], s in [1 - t_{j+1}, 1 - t_j]) -/ +end CongestionI3Dual + +#print axioms CongestionI3Dual.sig_of_ok diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3Mu.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3Mu.lean new file mode 100644 index 0000000000..b64a8e7023 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3Mu.lean @@ -0,0 +1,10 @@ +import Nov15.CongestionI3Data + +/-! +Per-chain flag-DP minima mu[i][k] (config i of `cfgs`, chain k): the minimum, over complete flags < ... < z_k^perp, of the number of +FORCED unique cells of chain k (F1 f1dp.py `flagdp(zp, z, cu)`). DATA from internal notes,b}.log (a rerun of f1dp.py with per-chain +printing; per-config sums reproduce f1dp.log: 1936 each). Python exact DP over the 29k-subspace lattice; NOT kernel-checked. +-/ +namespace CongestionI3 +def muTab : List (List ℕ) := [[242, 242, 242, 242, 242, 242, 242, 242], [242, 242, 242, 242, 242, 242, 242, 242], [242, 242, 242, 242, 242, 242, 242, 242], [242, 242, 242, 242, 242, 242, 242, 242], [242, 242, 242, 242, 242, 242, 242, 242], [242, 242, 242, 242, 242, 242, 242, 242], [242, 242, 242, 242, 242, 242, 242, 242], [242, 242, 242, 242, 242, 242, 242, 242]] +end CongestionI3 diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3NumA.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumA.lean new file mode 100644 index 0000000000..f31be96ce8 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumA.lean @@ -0,0 +1,47 @@ +import Nov15.NumCertK + +/-! +CONGESTION-I3 numeric half A : the 8|9 crossing of F1 (internal notes sec. 3) with NumCertK. +F_base = F of the #7113 caller C(8|9) (caller 6 7) at 17 calls with the native replaced by R1/R2's owned floor (400 * 8^s + 16) and NO stops +(`cfB`; = WholeFloorCover.cfW with the 17 * 88 stop terms (1, -2992), (2, +1496) removed). The I3 lift is the constant 17 * 1936 * sigma0, +sigma0 = 9785438/10^9 <= sp_F(t) (shape-DAG path bound in F currency, F1 f1ceil.spF at t = tbar = .0183952347; DATA, python). +Crossing: dF_base/ds > 0 on [.9, s0] (dLo, kernel), F_base(s0) < 17 * 1936 * sigma0 (kernel), s0 = 1 - tbar, tbar = .0183952347. +-/ +namespace CongestionI3 +open NumCertK + +def cfB : CF := [(1, -656), (8, -7456), (9, 384), (16, -416), (17, 416), (24, -416), (25, 416), (32, -416), (33, 416), + (40, -416), (41, 416), (48, -416), (49, 416), (56, -416), (57, 416), (64, -208), (65, 416), (73, 208), (137, 208)] +def sigma0 : ℚ := 9785438 / 10 ^ 9 +def sA : ℚ := 9816047653 / 10 ^ 10 +def liftA : ℚ := 17 * 1936 * sigma0 + +theorem cfB_ok : okR cfB := by decide +kernel +theorem cfB_p1 : Fup cfB (90 / 100) (91 / 100) < liftA := by decide +kernel +theorem cfB_p2 : Fup cfB (91 / 100) (92 / 100) < liftA := by decide +kernel +theorem cfB_p3 : Fup cfB (92 / 100) (93 / 100) < liftA := by decide +kernel +theorem cfB_d : 0 < dLo cfB (93 / 100) sA := by decide +kernel +theorem cfB_end : Fup cfB sA sA < liftA := by decide +kernel + +/-- F_base(s) < 17 * 1936 * sigma0 on s in [.9, 1 - tbar] -/ +theorem cfB_neg (s : ℝ) (h1 : (9 / 10 : ℝ) ≤ s) (h2 : s ≤ ((sA : ℚ) : ℝ)) : Fc cfB s < ((liftA : ℚ) : ℝ) := by + have piece : ∀ a b : ℚ, 0 ≤ a → b ≤ 1 → Fup cfB a b < liftA → (a : ℝ) ≤ s → s ≤ b → Fc cfB s < ((liftA : ℚ) : ℝ) := by + intro a b ha hb hF h1 h2 + have := Fc_le cfB cfB_ok a b ha hb s h1 h2 + have h' : ((Fup cfB a b : ℚ) : ℝ) < ((liftA : ℚ) : ℝ) := by exact_mod_cast hF + linarith + by_cases c1 : s ≤ (((91 / 100 : ℚ)) : ℝ) + · exact piece (90 / 100) (91 / 100) (by norm_num) (by norm_num) cfB_p1 (by push_cast; linarith) c1 + by_cases c2 : s ≤ (((92 / 100 : ℚ)) : ℝ) + · exact piece (91 / 100) (92 / 100) (by norm_num) (by norm_num) cfB_p2 (by push_neg at c1; exact c1.le) c2 + by_cases hc : s ≤ (((93 / 100 : ℚ)) : ℝ) + · exact piece (92 / 100) (93 / 100) (by norm_num) (by norm_num) cfB_p3 (by push_neg at c2; exact c2.le) hc + have h1' : (((93 / 100 : ℚ)) : ℝ) ≤ s := by push_neg at hc; exact hc.le + have hm := Fc_mono cfB cfB_ok (93 / 100) sA (by norm_num) (by unfold sA; norm_num) cfB_d s h1' h2 + have he := Fc_le cfB cfB_ok sA sA (by unfold sA; norm_num) (by unfold sA; norm_num) sA (le_refl _) (le_refl _) + have he' : ((Fup cfB sA sA : ℚ) : ℝ) < ((liftA : ℚ) : ℝ) := by exact_mod_cast cfB_end + linarith + +end CongestionI3 + +#print axioms CongestionI3.cfB_neg diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC1.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC1.lean new file mode 100644 index 0000000000..2533bd0108 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC1.lean @@ -0,0 +1,23 @@ +import Nov15.NumCertK + +/-! +CONGESTION-I3 numeric half C1 : own56 ceiling data, part 1. With the decoder's descent mass >= 56 charged (LIFT1 sec. 3: +cheapest F form 6 * 9^s + 2 * 1 plus 8 rises), the 17-call base is F_base = F(caller 6 7) - 17 (400 * 8^s + 6 * 9^s + 10) (`cfC`). `cfC88` +adds R3's 88 forced stops (-17 * 88 * (2 - 2^s): (1, -2992), (2, +1496)); F < 0 on s in [0, .9] (t >= .1) is covered here and in C2. +-/ +namespace CongestionI3 +open NumCertK + +def cfC : CF := [(1, -554), (8, -7456), (9, 282), (16, -416), (17, 416), (24, -416), (25, 416), (32, -416), (33, 416), + (40, -416), (41, 416), (48, -416), (49, 416), (56, -416), (57, 416), (64, -208), (65, 416), (73, 208), (137, 208)] +def cfC88 : CF := [(1, -3546), (2, 1496), (8, -7456), (9, 282), (16, -416), (17, 416), (24, -416), (25, 416), (32, -416), (33, 416), + (40, -416), (41, 416), (48, -416), (49, 416), (56, -416), (57, 416), (64, -208), (65, 416), (73, 208), (137, 208)] +theorem cfC_ok : okR cfC := by decide +kernel +theorem cfC88_ok : okR cfC88 := by decide +kernel +theorem cfC88_p1 : Fup cfC88 (0) (22/100) < 0 := by decide +kernel +theorem cfC88_p2 : Fup cfC88 (22/100) (39/100) < 0 := by decide +kernel +theorem cfC88_p3 : Fup cfC88 (39/100) (51/100) < 0 := by decide +kernel +theorem cfC88_p4 : Fup cfC88 (51/100) (6/10) < 0 := by decide +kernel +theorem cfC88_p5 : Fup cfC88 (6/10) (67/100) < 0 := by decide +kernel + +end CongestionI3 diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC2.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC2.lean new file mode 100644 index 0000000000..00254cf788 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC2.lean @@ -0,0 +1,13 @@ +import Nov15.CongestionI3NumC1 + +/-! CONGESTION-I3 numeric part C2 : kernel interval pieces for the own56 ceiling; see CongestionI3NumC1 and CongestionI3.md. -/ +namespace CongestionI3 +open NumCertK + +theorem cfC88_p6 : Fup cfC88 (67/100) (72/100) < 0 := by decide +kernel +theorem cfC88_p7 : Fup cfC88 (72/100) (76/100) < 0 := by decide +kernel +theorem cfC88_p8 : Fup cfC88 (76/100) (79/100) < 0 := by decide +kernel +theorem cfC88_p9 : Fup cfC88 (79/100) (81/100) < 0 := by decide +kernel +theorem cfC88_p10 : Fup cfC88 (81/100) (83/100) < 0 := by decide +kernel + +end CongestionI3 diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC3.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC3.lean new file mode 100644 index 0000000000..ddb23f0913 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC3.lean @@ -0,0 +1,17 @@ +import Nov15.CongestionI3NumC2 + +/-! CONGESTION-I3 numeric part C3 : kernel interval pieces for the own56 ceiling; see CongestionI3NumC1 and CongestionI3.md. -/ +namespace CongestionI3 +open NumCertK + +def sC : ℚ := 1 - 134769139 / 10 ^ 10 +def LcC : ℚ := 1364105 / 10 ^ 5 +def liftC : ℚ := 17 * LcC + +theorem cfC88_p11 : Fup cfC88 (83/100) (86/100) < 0 := by decide +kernel +theorem cfC88_p12 : Fup cfC88 (86/100) (88/100) < 0 := by decide +kernel +theorem cfC88_p13 : Fup cfC88 (88/100) (9/10) < 0 := by decide +kernel +theorem cfC_q1 : Fup cfC (90 / 100) (915 / 1000) < liftC := by decide +kernel +theorem cfC_q2 : Fup cfC (915 / 1000) (93 / 100) < liftC := by decide +kernel + +end CongestionI3 diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC4.lean b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC4.lean new file mode 100644 index 0000000000..b6b5c40c1d --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionI3NumC4.lean @@ -0,0 +1,59 @@ +import Nov15.CongestionI3NumC3 + +/-! CONGESTION-I3 numeric part C4 : kernel interval pieces for the own56 ceiling; see CongestionI3NumC1 and CongestionI3.md. -/ +namespace CongestionI3 +open NumCertK + +theorem cfC_d : 0 < dLo cfC (93 / 100) sC := by decide +kernel +theorem cfC_end : Fup cfC sC sC < liftC := by decide +kernel + +theorem cfC88_neg (s : ℝ) (h0 : 0 ≤ s) (hs : s ≤ (9 / 10 : ℝ)) : Fc cfC88 s < 0 := by + have piece : ∀ a b : ℚ, 0 ≤ a → b ≤ 1 → Fup cfC88 a b < 0 → (a : ℝ) ≤ s → s ≤ b → Fc cfC88 s < 0 := + fun a b ha hb hF h1 h2 => Fc_neg_piece cfC88 cfC88_ok a b ha hb hF s h1 h2 + by_cases c1 : s ≤ (((22/100) : ℚ) : ℝ) + · exact piece (0) (22/100) (by norm_num) (by norm_num) cfC88_p1 (by simpa using h0) c1 + by_cases c2 : s ≤ (((39/100) : ℚ) : ℝ) + · exact piece (22/100) (39/100) (by norm_num) (by norm_num) cfC88_p2 (by push_cast; push_neg at c1; linarith) c2 + by_cases c3 : s ≤ (((51/100) : ℚ) : ℝ) + · exact piece (39/100) (51/100) (by norm_num) (by norm_num) cfC88_p3 (by push_cast; push_neg at c2; linarith) c3 + by_cases c4 : s ≤ (((6/10) : ℚ) : ℝ) + · exact piece (51/100) (6/10) (by norm_num) (by norm_num) cfC88_p4 (by push_cast; push_neg at c3; linarith) c4 + by_cases c5 : s ≤ (((67/100) : ℚ) : ℝ) + · exact piece (6/10) (67/100) (by norm_num) (by norm_num) cfC88_p5 (by push_cast; push_neg at c4; linarith) c5 + by_cases c6 : s ≤ (((72/100) : ℚ) : ℝ) + · exact piece (67/100) (72/100) (by norm_num) (by norm_num) cfC88_p6 (by push_cast; push_neg at c5; linarith) c6 + by_cases c7 : s ≤ (((76/100) : ℚ) : ℝ) + · exact piece (72/100) (76/100) (by norm_num) (by norm_num) cfC88_p7 (by push_cast; push_neg at c6; linarith) c7 + by_cases c8 : s ≤ (((79/100) : ℚ) : ℝ) + · exact piece (76/100) (79/100) (by norm_num) (by norm_num) cfC88_p8 (by push_cast; push_neg at c7; linarith) c8 + by_cases c9 : s ≤ (((81/100) : ℚ) : ℝ) + · exact piece (79/100) (81/100) (by norm_num) (by norm_num) cfC88_p9 (by push_cast; push_neg at c8; linarith) c9 + by_cases c10 : s ≤ (((83/100) : ℚ) : ℝ) + · exact piece (81/100) (83/100) (by norm_num) (by norm_num) cfC88_p10 (by push_cast; push_neg at c9; linarith) c10 + by_cases c11 : s ≤ (((86/100) : ℚ) : ℝ) + · exact piece (83/100) (86/100) (by norm_num) (by norm_num) cfC88_p11 (by push_cast; push_neg at c10; linarith) c11 + by_cases c12 : s ≤ (((88/100) : ℚ) : ℝ) + · exact piece (86/100) (88/100) (by norm_num) (by norm_num) cfC88_p12 (by push_cast; push_neg at c11; linarith) c12 + exact piece (88/100) (9/10) (by norm_num) (by norm_num) cfC88_p13 (by push_cast; push_neg at c12; linarith) (by push_cast; linarith) + +/-- F_base < 17 * LcC on s in [.9, 1 - tbarC] (the lift is the constant 17 * LcC) -/ +theorem cfC_neg (s : ℝ) (h1 : (9 / 10 : ℝ) ≤ s) (h2 : s ≤ ((sC : ℚ) : ℝ)) : Fc cfC s < ((liftC : ℚ) : ℝ) := by + have piece : ∀ a b : ℚ, 0 ≤ a → b ≤ 1 → Fup cfC a b < liftC → (a : ℝ) ≤ s → s ≤ b → Fc cfC s < ((liftC : ℚ) : ℝ) := by + intro a b ha hb hF h1 h2 + have := Fc_le cfC cfC_ok a b ha hb s h1 h2 + have h' : ((Fup cfC a b : ℚ) : ℝ) < ((liftC : ℚ) : ℝ) := by exact_mod_cast hF + linarith + by_cases c1 : s ≤ (((915 / 1000 : ℚ)) : ℝ) + · exact piece (90 / 100) (915 / 1000) (by norm_num) (by norm_num) cfC_q1 (by push_cast; linarith) c1 + by_cases c2 : s ≤ (((93 / 100 : ℚ)) : ℝ) + · exact piece (915 / 1000) (93 / 100) (by norm_num) (by norm_num) cfC_q2 (by push_neg at c1; exact c1.le) c2 + have h1' : (((93 / 100 : ℚ)) : ℝ) ≤ s := by push_neg at c2; exact c2.le + have hm := Fc_mono cfC cfC_ok (93 / 100) sC (by norm_num) (by unfold sC; norm_num) cfC_d s h1' h2 + have he := Fc_le cfC cfC_ok sC sC (by unfold sC; norm_num) (by unfold sC; norm_num) sC (le_refl _) (le_refl _) + have he' : ((Fup cfC sC sC : ℚ) : ℝ) < ((liftC : ℚ) : ℝ) := by exact_mod_cast cfC_end + linarith + +end CongestionI3 + +#print axioms CongestionI3.cfC88_neg +#print axioms CongestionI3.cfC_neg diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionNative.lean b/research/p104-native-ceiling/lean/Nov15/CongestionNative.lean new file mode 100644 index 0000000000..899afcb54b --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionNative.lean @@ -0,0 +1,319 @@ +import Nov15.CongestionI3 +import Nov15.CongestionI3DualAlg +import Nov15.CongestionI3DualSig +import Nov15.CongestionI3DualConst +import Nov15.CongestionI3DualData +import Nov15.CongestionI3DualNumC +import Nov15.CongestionI3DualCertC0 +import Nov15.CongestionI3DualCertC1 +import Nov15.CongestionI3DualCertC2 +import Nov15.CongestionI3DualCertC3 +import Nov15.CongestionNativeTab + +/-! +CONGESTION-NATIVE: the native-covering ceiling kappa <= .0136564 (own56, 8|9, m <= 5), the corrected form of +`CongestionI3Dual.ceiling_C2` (a COPY; the shipped files are unchanged). See CongestionNative.md for the hypothesis ledger. +Changes against ceiling_C2 (HC1-HC4, AUD, AUD2 FIX A-C): +* hcong* carries the owned surplus `Omega = dprice ks s + mr - (6 * 9^s + 10)` on the right (ks = descents + non-unit rises, mr = unit rises: FIX-1) and is + stated only for s in [.9, 1 - tC0]; `hE` is generalised to `Lj <= E + Omega` (`branchC_om`, `E_lower_cap_om`). +* ONE J throughout (J = J^arr, the arrival residual): hcong*, hdist and hJ all use the same variable `J`. +* The placeholder Props (Rank8C56, Prov) are gone; `ell`, `corr`, `cap` are concrete (`ellC`, `corrC`, `capC`); `LcTabC` is DERIVED from + rational tables (CongestionNativeTab) and the hypotheses hspMono/hcstMono/hspTab/hcstTab/hunitTab. +* `hcong_of_capclass` (+ PathCut.lean) formalises the accounting that proves hcong* from the Cap class. +-/ +namespace CongestionNative +open NumCertK JointCeiling CallerCost CongestionI3 CongestionI3Dual Finset + +/-! ### 0. copied from CongestionI3Dual (F_base monotonicity and point enclosures, own56 side) -/ +theorem Fc_monoOn (cf : CF) (hok : okR cf) (a b : ℚ) (ha : 0 ≤ a) (hb1 : b ≤ 1) (hd : 0 < dLo cf a b) + (s s' : ℝ) (h1 : (a : ℝ) ≤ s) (hss : s ≤ s') (h2 : s' ≤ (b : ℝ)) : Fc cf s ≤ Fc cf s' := by + have hab : (a : ℝ) ≤ b := le_trans h1 (le_trans hss h2) + have hcont : ContinuousOn (Fc cf) (Set.Icc (a : ℝ) b) := + fun x _ => (Fc_hasDerivAt cf hok x).continuousAt.continuousWithinAt + have hm : StrictMonoOn (Fc cf) (Set.Icc (a : ℝ) b) := by + apply strictMonoOn_of_deriv_pos (convex_Icc _ _) hcont + intro x hx + rw [interior_Icc] at hx + rw [(Fc_hasDerivAt cf hok x).deriv] + have := dFc_ge cf hok a b ha hb1 x hx.1.le hx.2.le + have hd' : (0:ℝ) < ((dLo cf a b : ℚ) : ℝ) := by exact_mod_cast hd + linarith + exact hm.monotoneOn ⟨h1, le_trans hss h2⟩ ⟨le_trans h1 hss, h2⟩ hss + +theorem cfC_monoOn (s s' : ℝ) (h1 : (93 / 100 : ℝ) ≤ s) (hss : s ≤ s') (h2 : s' ≤ ((sC : ℚ) : ℝ)) : Fc cfC s ≤ Fc cfC s' := + Fc_monoOn cfC cfC_ok (93 / 100) sC (by norm_num) (by unfold sC; norm_num) cfC_d s s' + (by rw [show (((93 / 100 : ℚ)) : ℝ) = 93 / 100 by norm_num]; exact h1) hss h2 + +theorem pt_of_Fup (cf : CF) (hok : okR cf) (q L : ℚ) (hq0 : 0 ≤ q) (hq1 : q ≤ 1) (h : Fup cf q q < 17 * L) : + Fc cf (q : ℝ) < 17 * (L : ℝ) := by + have h1 := Fc_le cf hok q q hq0 hq1 (q : ℝ) (le_refl _) (le_refl _) + have h2 : ((Fup cf q q : ℚ) : ℝ) < ((17 * L : ℚ) : ℝ) := by exact_mod_cast h + push_cast at h2 + linarith + +theorem hFbC_of (a b L : ℚ) (hb93 : 93 / 100 ≤ 1 - b) (hab : a ≤ b) (haA : 1 - a ≤ sC) (ha0 : 0 ≤ a) + (hpt : Fup cfC (1 - a) (1 - a) < 17 * L) : + ∀ s : ℝ, ((1 - b : ℚ) : ℝ) ≤ s → s ≤ ((1 - a : ℚ) : ℝ) → Fc cfC s < 17 * (L : ℝ) := by + intro s h1 h2 + have hb : (((93 / 100 : ℚ)) : ℝ) ≤ s := le_trans (by exact_mod_cast hb93) h1 + have hb' : (93 / 100 : ℝ) ≤ s := by rwa [show (((93 / 100 : ℚ)) : ℝ) = 93 / 100 by norm_num] at hb + have hm := cfC_monoOn s ((1 - a : ℚ) : ℝ) hb' h2 (by exact_mod_cast haA) + exact lt_of_le_of_lt hm (pt_of_Fup cfC cfC_ok (1 - a) L (by linarith [(by exact_mod_cast hab : (a : ℚ) ≤ b)]) (by linarith) hpt) + +/-! ### 1. concrete definitions -/ + +/-- owned surplus: all owned moves `|k|^s` (ks = descents + non-unit rises, mr = unit rises, price 1 each) minus what `own56_floor` charges (6 * 9^s + 10). -/ +noncomputable def Omega (ks : List ℕ) (mr : ℕ) (s : ℝ) : ℝ := dprice ks s + mr - (6 * (9 : ℝ) ^ s + 10) +/-- per-cell cap `(9^s - 8^s) / 48` -/ +noncomputable def capC (s : ℝ) : ℝ := ((9 : ℝ) ^ s - (8 : ℝ) ^ s) / 48 +/-- lower bound of the capped per-cell distance: `min (spF (1 - s)) (cap s)` -/ +noncomputable def ellC (spF : ℝ → ℝ) (s : ℝ) : ℝ := min (spF (1 - s)) (capC s) +/-- LIFT1 rise correction `8 * cst(1 - s)` -/ +noncomputable def corrC (cstF : ℝ → ℝ) (s : ℝ) : ℝ := 8 * cstF (1 - s) + +/-! ### 2. two-sided I3 with the owned surplus on the right -/ +section Elower +variable {ι : Type*} [DecidableEq ι] + +/-- two-sided I3, cap/correction form with surplus: `sum min (dist, cap) - corr <= charges + Om` gives `E + Om >= 1936 ell - corr - m sigma`. -/ +theorem E_lower_cap_om (R : Finset ι) (n : ι → ℕ) (d : ι → ℕ → ℕ) (J : Finset (ℕ × ℕ)) (dist : ℕ × ℕ → ℝ) + (E s cap corr ell σ Om : ℝ) (m : ℕ) + (hmono : ∀ r ∈ R, ∀ i < n r, d r i ≤ d r (i + 1)) (hd9 : ∀ r ∈ R, d r (n r) ≤ 9) + (hm : (R.filter fun r => Mixed d n r).card ≤ m) (hσ0 : 0 ≤ σ) + (hσ : ∀ a b : ℕ, 1 ≤ a → a ≤ b → b ≤ 8 → c2 (gs s) (a : ℝ) (b : ℝ) ≤ σ) + (hcong : ∑ p ∈ J, min (dist p) cap - corr ≤ ∑ r ∈ R, ∑ i ∈ range (n r), c2 (gs s) (lev d r i) (lev d r (i + 1)) + Om) + (hEex : ∑ r ∈ R, ex (gs s) (lev d r) (n r) ≤ E) (hdist : ∀ p ∈ J, ell ≤ min (dist p) cap) (hJ : 1936 ≤ J.card) (hell : 0 ≤ ell) : + 1936 * ell - corr - m * σ ≤ E + Om := by + have h1 := sum_all_c2_le (gs s) (gs_zero s) R n d hmono hd9 m hm σ hσ0 hσ + have h2 := Finset.card_nsmul_le_sum J (fun p => min (dist p) cap) ell hdist + rw [nsmul_eq_mul] at h2 + have hj : (1936 : ℝ) ≤ J.card := by exact_mod_cast hJ + nlinarith + +end Elower + +/-! ### 3. the branch with the surplus (the 88c branch is only needed for t >= .1) -/ + +theorem branchC_om (n : Inv) (ks : List ℕ) (mr : ℕ) (E Lj s : ℝ) + (hF : Finv s n ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E) + (hE : Lj ≤ E + Omega ks mr s) (hFb : Fc cfC s < 17 * Lj) : + Finv s (invoice (caller 6 7) n 17) < 0 := by + have h1' : Finv s n ≤ -400 * (8 : ℝ) ^ s - (6 * (9 : ℝ) ^ s + 10) - Lj := by + unfold Omega at hE; linarith + have h2 := invoice_F s (caller 6 7) n 17 + have h3 := invoice_F s (caller 6 7) natBaseC 17 + have h4 := natBaseC_F s + have h6 := baseC_eq s + push_cast at h2 h3 + nlinarith + +/-! ### 4. the Cap-class accounting (HC1 sec. 2): hcong* from legal + transported cells -/ + +/-- `J` splits into LEGAL cells (a descent-free D_t-confined path: I3 charge + rise saving `cst * Rm`) and TRANSPORTED cells (cut at an owned descent, `<= 48 * Nf` of them, each at most `cap = U/48`). +Then `sum min - 8 cst <= Pub + Om` as soon as the Cap class inequality `cst (Rm - 8) + U Nf <= Om` holds. -/ +theorem hcong_of_capclass (J : Finset (ℕ × ℕ)) (leg : ℕ × ℕ → Prop) [DecidablePred leg] (dist : ℕ × ℕ → ℝ) + (cap U Pub cst Rm Nf Om : ℝ) (hcap : cap = U / 48) (hU : 0 ≤ U) + (hleg : ∑ p ∈ J.filter leg, dist p ≤ Pub + cst * Rm) + (hT : ((J.filter fun p => ¬ leg p).card : ℝ) ≤ 48 * Nf) + (hclass : cst * (Rm - 8) + U * Nf ≤ Om) : + ∑ p ∈ J, min (dist p) cap - 8 * cst ≤ Pub + Om := by + have hsplit := Finset.sum_filter_add_sum_filter_not J leg (fun p => min (dist p) cap) + have h1 : ∑ p ∈ J.filter leg, min (dist p) cap ≤ ∑ p ∈ J.filter leg, dist p := + Finset.sum_le_sum fun p _ => min_le_left _ _ + have h2 : ∑ p ∈ J.filter (fun p => ¬ leg p), min (dist p) cap ≤ ∑ _p ∈ J.filter (fun p => ¬ leg p), cap := + Finset.sum_le_sum fun p _ => min_le_right _ _ + rw [Finset.sum_const, nsmul_eq_mul] at h2 + have hc0 : 0 ≤ cap := by rw [hcap]; positivity + have h3 : ((J.filter fun p => ¬ leg p).card : ℝ) * cap ≤ 48 * Nf * cap := mul_le_mul_of_nonneg_right hT hc0 + have h4 : 48 * Nf * cap = U * Nf := by rw [hcap]; ring + nlinarith + +/-! ### 5. the derived table `LcTabC` -/ + +theorem unit_mono (s s' : ℝ) (hs : 0 ≤ s) (h : s ≤ s') : (9 : ℝ) ^ s - (8 : ℝ) ^ s ≤ (9 : ℝ) ^ s' - (8 : ℝ) ^ s' := by + have e : ∀ x : ℝ, (9 : ℝ) ^ x - (8 : ℝ) ^ x = (8 : ℝ) ^ x * (((9 : ℝ) / 8) ^ x - 1) := by + intro x + have h9 : (9 : ℝ) ^ x = (8 : ℝ) ^ x * ((9 : ℝ) / 8) ^ x := by + rw [← Real.mul_rpow (by norm_num) (by norm_num)]; norm_num + rw [h9]; ring + rw [e, e] + have h1 : (8 : ℝ) ^ s ≤ (8 : ℝ) ^ s' := Real.rpow_le_rpow_of_exponent_le (by norm_num) h + have h2 : ((9 : ℝ) / 8) ^ s ≤ ((9 : ℝ) / 8) ^ s' := Real.rpow_le_rpow_of_exponent_le (by norm_num) h + have h3 : (1 : ℝ) ≤ ((9 : ℝ) / 8) ^ s := Real.one_le_rpow (by norm_num) hs + exact mul_le_mul h1 (by linarith) (by linarith) (by positivity) + +/-- one t-piece `[a, b]` of the own56 table: `lcp <= 1936 ell - corr` follows from the rational table and endpoint hypotheses (monotonicity of spF and cst in t). -/ +theorem tab_piece (spF cstF : ℝ → ℝ) (a b : ℚ) (lcp cH spLo unLo : ℚ) (hlcp : 0 ≤ lcp) (hcH : 0 ≤ cH) (ha0 : tC0 ≤ a) (hab : a ≤ b) (hb : b ≤ 1 / 10) + (hmS : MonotoneOn spF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) (hmC : MonotoneOn cstF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) + (hsp : (spLo : ℝ) ≤ spF (a : ℝ)) (hcs : cstF (b : ℝ) ≤ cH) + (hun : (unLo : ℝ) ≤ (9 : ℝ) ^ (1 - (b : ℝ)) - (8 : ℝ) ^ (1 - (b : ℝ))) + (hn1 : lcp + 8 * cH ≤ 1936 * spLo) (hn2 : lcp + 8 * cH ≤ 1936 * (unLo / 48)) : + ∀ s : ℝ, ((1 - b : ℚ) : ℝ) ≤ s → s ≤ ((1 - a : ℚ) : ℝ) → (lcp : ℝ) ≤ 1936 * ellC spF s - corrC cstF s ∧ 0 ≤ ellC spF s := by + intro s h1 h2 + push_cast at h1 h2 + have ha' : ((tC0 : ℚ) : ℝ) ≤ a := by exact_mod_cast ha0 + have hab' : (a : ℝ) ≤ b := by exact_mod_cast hab + have hb' : (b : ℝ) ≤ 1 / 10 := by + have := (Rat.cast_le (K := ℝ)).mpr hb + push_cast at this; exact this + have htl : (a : ℝ) ≤ 1 - s := by linarith + have htu : 1 - s ≤ (b : ℝ) := by linarith + have hspt : spF a ≤ spF (1 - s) := hmS ⟨ha', by linarith⟩ ⟨by linarith, by linarith⟩ htl + have hcst : cstF (1 - s) ≤ cstF b := hmC ⟨by linarith, by linarith⟩ ⟨by linarith, hb'⟩ htu + have hcap : (unLo : ℝ) / 48 ≤ capC s := by + have := unit_mono (1 - b) s (by linarith) h1 + unfold capC; linarith + have hell : min (spLo : ℝ) ((unLo : ℝ) / 48) ≤ ellC spF s := by + unfold ellC + exact le_min (le_trans (min_le_left _ _) (by linarith)) (le_trans (min_le_right _ _) hcap) + have hcorr : corrC cstF s ≤ 8 * (cH : ℝ) := by unfold corrC; linarith + have hn1' : (lcp : ℝ) + 8 * cH ≤ 1936 * spLo := by exact_mod_cast hn1 + have hn2' : (lcp : ℝ) + 8 * cH ≤ 1936 * ((unLo : ℝ) / 48) := by exact_mod_cast hn2 + have hl0 : (0 : ℝ) ≤ lcp := by exact_mod_cast hlcp + have hc0 : (0 : ℝ) ≤ cH := by exact_mod_cast hcH + rcases le_total (spLo : ℝ) ((unLo : ℝ) / 48) with hh | hh + · rw [min_eq_left hh] at hell; exact ⟨by linarith, by linarith⟩ + · rw [min_eq_right hh] at hell; exact ⟨by linarith, by linarith⟩ + +/-! ### 6. the native-covering ceiling -/ + +/-- **native-covering ceiling.** For a word whose public registers have at most 5 mixed registers (`hmix`) and whose owned layer splits as `ks` (descents + non-unit rises) and `mr` (unit rises), +if the congestion step `hcong` (with the owned surplus), the distance floor `hdist`, `hJ` (|J| >= 1936) hold for ONE set `J` (= J^arr), together with the accounting identities and the +certified tables, then `F(1 - t, invoice (caller 6 7) n 17) < 0` for all t in [tC0, 1], i.e. kappa <= tC0 = .0136564 (8|9). Every hypothesis is listed in CongestionNative.md. -/ +theorem ceiling_native {ι : Type*} [DecidableEq ι] + (R : Finset ι) (nR : ι → ℕ) (dR : ι → ℕ → ℕ) + (hmono : ∀ r ∈ R, ∀ i < nR r, dR r i ≤ dR r (i + 1)) (hd9 : ∀ r ∈ R, dR r (nR r) ≤ 9) + (hmix : (R.filter fun r => Mixed dR nR r).card ≤ 5) + (n : Inv) (ks : List ℕ) (mr st : ℕ) (E : ℝ → ℝ) (J : Finset (ℕ × ℕ)) (distF : ℝ → ℕ × ℕ → ℝ) (spF cstF : ℝ → ℝ) + (hk : ∀ k ∈ ks, 1 ≤ k ∧ k ≤ 9) (hmass : 56 ≤ ks.sum) (hmd : 8 ≤ ks.length) (hmr : 8 ≤ mr) + (hF : ∀ s, 0 ≤ s → s ≤ 1 → Finv s n ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E s) + (hY : 104 ≤ st + (ks.length + mr)) + (hst : ∀ s, 0 ≤ s → s ≤ 1 → (2 - (2 : ℝ) ^ s) * st ≤ E s) + (hEex : ∀ s, 0 ≤ s → s ≤ 1 → ∑ r ∈ R, ex (gs s) (lev dR r) (nR r) ≤ E s) + (hcong : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → + ∑ p ∈ J, min (distF s p) (capC s) - corrC cstF s ≤ + ∑ r ∈ R, ∑ i ∈ range (nR r), c2 (gs s) (lev dR r i) (lev dR r (i + 1)) + Omega ks mr s) + (hdist : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → ∀ p ∈ J, spF (1 - s) ≤ distF s p) + (hJ : 1936 ≤ J.card) + (hspMono : MonotoneOn spF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) + (hcstMono : MonotoneOn cstF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10))) + (hspTab : ((spFloC0 : ℚ) : ℝ) ≤ spF ((tC0 : ℚ) : ℝ) ∧ ((spFloC1 : ℚ) : ℝ) ≤ spF ((tC1 : ℚ) : ℝ) ∧ + ((spFloC2 : ℚ) : ℝ) ≤ spF ((tC2 : ℚ) : ℝ) ∧ ((spFloC3 : ℚ) : ℝ) ≤ spF ((tC3 : ℚ) : ℝ)) + (hcstTab : cstF ((tC1 : ℚ) : ℝ) ≤ ((cHC0 : ℚ) : ℝ) ∧ cstF ((tC2 : ℚ) : ℝ) ≤ ((cHC1 : ℚ) : ℝ) ∧ + cstF ((tC3 : ℚ) : ℝ) ≤ ((cHC2 : ℚ) : ℝ) ∧ cstF (1 / 10) ≤ ((cHC3 : ℚ) : ℝ)) + (hunitTab : ((unitLoC0 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) ∧ + ((unitLoC1 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) ∧ + ((unitLoC2 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) ∧ + ((unitLoC3 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - (1 / 10 : ℝ)) - (8 : ℝ) ^ (1 - (1 / 10 : ℝ))) : + ∀ t : ℝ, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 → Finv (1 - t) (invoice (caller 6 7) n 17) < 0 := by + have piece : ∀ (a b lcp σ : ℚ), sigOK (1 - b) (1 - a) σ = true → 0 ≤ σ → tC0 ≤ a → a ≤ b → b ≤ 1 / 10 → 0 ≤ lcp → + (∀ s : ℝ, ((1 - b : ℚ) : ℝ) ≤ s → s ≤ ((1 - a : ℚ) : ℝ) → (lcp : ℝ) ≤ 1936 * ellC spF s - corrC cstF s ∧ 0 ≤ ellC spF s) → + (∀ s : ℝ, ((1 - b : ℚ) : ℝ) ≤ s → s ≤ ((1 - a : ℚ) : ℝ) → Fc cfC s < 17 * (((lcp - 5 * σ : ℚ)) : ℝ)) → + ∀ t : ℝ, (a : ℝ) ≤ t → t ≤ (b : ℝ) → Finv (1 - t) (invoice (caller 6 7) n 17) < 0 := by + intro a b lcp σ hσc hσ0 ha0 hab hb hl0 hLcp hFb t h1 h2 + have ha0q : (0 : ℚ) ≤ a := le_trans (by unfold tC0; norm_num) ha0 + have ha0' : ((tC0 : ℚ) : ℝ) ≤ a := by exact_mod_cast ha0 + have hb' : (b : ℝ) ≤ 1 / 10 := by + have := (Rat.cast_le (K := ℝ)).mpr hb + push_cast at this; exact this + have hab' : (a : ℝ) ≤ b := by exact_mod_cast hab + have hA0 : (0 : ℝ) ≤ a := by exact_mod_cast ha0q + have hs0 : 0 ≤ 1 - t := by linarith + have hs1 : 1 - t ≤ 1 := by linarith + have hσ : ∀ a' b' : ℕ, 1 ≤ a' → a' ≤ b' → b' ≤ 8 → c2 (gs (1 - t)) (a' : ℝ) (b' : ℝ) ≤ (σ : ℝ) := by + intro a' b' h1' h2' h3' + exact sig_of_ok (1 - b) (1 - a) σ hσc (by linarith) (by linarith) hσ0 (1 - t) + (by push_cast; linarith) (by push_cast; linarith) a' b' h1' h2' h3' + have hl0' : (0 : ℝ) ≤ lcp := by exact_mod_cast hl0 + have hLcp' := hLcp (1 - t) (by push_cast; linarith) (by push_cast; linarith) + have hslo : (9 / 10 : ℝ) ≤ 1 - t := by linarith + have hshi : 1 - t ≤ 1 - ((tC0 : ℚ) : ℝ) := by linarith + have hell : 0 ≤ ellC spF (1 - t) := hLcp'.2 + have hE := E_lower_cap_om R nR dR J (distF (1 - t)) (E (1 - t)) (1 - t) (capC (1 - t)) (corrC cstF (1 - t)) (ellC spF (1 - t)) + (σ : ℝ) (Omega ks mr (1 - t)) 5 hmono hd9 hmix (by exact_mod_cast hσ0) hσ (hcong (1 - t) hslo hshi) (hEex _ hs0 hs1) + (fun p hp => le_min (le_trans (min_le_left _ _) (hdist (1 - t) hslo hshi p hp)) (min_le_right _ _)) hJ hell + have hE' : (((lcp - 5 * σ : ℚ)) : ℝ) ≤ E (1 - t) + Omega ks mr (1 - t) := by push_cast; push_cast at hE; linarith [hLcp'.1] + exact branchC_om n ks mr (E (1 - t)) _ (1 - t) (hF _ hs0 hs1) hE' + (hFb (1 - t) (by push_cast; linarith) (by push_cast; linarith)) + intro t ht ht1 + have htC0 : (0 : ℝ) ≤ ((tC0 : ℚ) : ℝ) := by unfold tC0; norm_num + have hs0 : (0 : ℝ) ≤ 1 - t := by linarith + have hs1 : 1 - t ≤ 1 := by linarith + have hu1 : (1 : ℝ) ≤ (2 : ℝ) ^ (1 - t) := Real.one_le_rpow (by norm_num) hs0 + have hu2 : (2 : ℝ) ^ (1 - t) ≤ 2 := by + have := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 2 by norm_num) hs1; simpa using this + have hE0 : 0 ≤ E (1 - t) := + le_trans (mul_nonneg (by linarith) (Nat.cast_nonneg st)) (hst _ hs0 hs1) + rcases le_or_gt (1 / 10 : ℝ) t with h10 | h10 + · have h2 := invoice_F (1 - t) (caller 6 7) n 17 + have h3 := invoice_F (1 - t) (caller 6 7) natBaseC 17 + have h4 := natBaseC_F (1 - t) + push_cast at h2 h3 + have h1 := own56_floor (1 - t) hs0 hs1 ks hk hmass hmd mr st hmr (Finv (1 - t) n) (E (1 - t)) 0 (hF _ hs0 hs1) hY + (hst _ hs0 hs1) hE0 + have hc0 : (0 : ℝ) ≤ 88 * (2 - (2 : ℝ) ^ (1 - t)) := by linarith + rw [max_eq_left hc0] at h1 + have h5 := cfC88_neg (1 - t) hs0 (by linarith) + have h6 := base88_eq (1 - t) + nlinarith + · obtain ⟨sp0, sp1, sp2, sp3⟩ := hspTab + obtain ⟨cs0, cs1, cs2, cs3⟩ := hcstTab + obtain ⟨un0, un1, un2, un3⟩ := hunitTab + have q01 : tC0 ≤ tC1 := by unfold tC0 tC1; norm_num + have q12 : tC1 ≤ tC2 := by unfold tC1 tC2; norm_num + have q23 : tC2 ≤ tC3 := by unfold tC2 tC3; norm_num + have q3 : tC3 ≤ 1 / 10 := by unfold tC3; norm_num + have lcp0 : ∀ q : ℚ, q = lcpC0 ∨ q = lcpC1 ∨ q = lcpC2 ∨ q = lcpC3 → 0 ≤ q := by + intro q h; unfold lcpC0 lcpC1 lcpC2 lcpC3 at h; rcases h with h | h | h | h <;> rw [h] <;> norm_num + have cH0 : ∀ q : ℚ, q = cHC0 ∨ q = cHC1 ∨ q = cHC2 ∨ q = cHC3 → 0 ≤ q := by + intro q h; unfold cHC0 cHC1 cHC2 cHC3 at h; rcases h with h | h | h | h <;> rw [h] <;> norm_num + have e1 : ((tC0 : ℚ) : ℝ) ≤ ((tC1 : ℚ) : ℝ) := by exact_mod_cast q01 + have e2 : ((tC1 : ℚ) : ℝ) ≤ ((tC2 : ℚ) : ℝ) := by exact_mod_cast q12 + have e3 : ((tC2 : ℚ) : ℝ) ≤ ((tC3 : ℚ) : ℝ) := by exact_mod_cast q23 + by_cases k1 : t ≤ ((tC1 : ℚ) : ℝ) + · exact piece tC0 tC1 lcpC0 sgC0 sigC0 (by unfold sgC0; norm_num) (le_refl _) q01 (by linarith) (lcp0 _ (Or.inl rfl)) + (tab_piece spF cstF tC0 tC1 lcpC0 cHC0 spFloC0 unitLoC0 (lcp0 _ (Or.inl rfl)) (cH0 _ (Or.inl rfl)) (le_refl _) q01 (by linarith) + hspMono hcstMono sp0 cs0 un0 tabC0.1 tabC0.2) + (hFbC_of tC0 tC1 LC0 (by unfold tC1; norm_num) q01 (by unfold tC0 sC; norm_num) (by unfold tC0; norm_num) ptC0) t ht k1 + by_cases k2 : t ≤ ((tC2 : ℚ) : ℝ) + · exact piece tC1 tC2 lcpC1 sgC1 sigC1 (by unfold sgC1; norm_num) q01 q12 (by linarith) (lcp0 _ (Or.inr (Or.inl rfl))) + (tab_piece spF cstF tC1 tC2 lcpC1 cHC1 spFloC1 unitLoC1 (lcp0 _ (Or.inr (Or.inl rfl))) (cH0 _ (Or.inr (Or.inl rfl))) q01 q12 (by linarith) + hspMono hcstMono sp1 cs1 un1 tabC1.1 tabC1.2) + (hFbC_of tC1 tC2 LC1 (by unfold tC2; norm_num) q12 (by unfold tC1 sC; norm_num) (by unfold tC1; norm_num) ptC1) t + (by push Not at k1; exact k1.le) k2 + by_cases k3 : t ≤ ((tC3 : ℚ) : ℝ) + · exact piece tC2 tC3 lcpC2 sgC2 sigC2 (by unfold sgC2; norm_num) (le_trans q01 q12) q23 (by linarith) (lcp0 _ (Or.inr (Or.inr (Or.inl rfl)))) + (tab_piece spF cstF tC2 tC3 lcpC2 cHC2 spFloC2 unitLoC2 (lcp0 _ (Or.inr (Or.inr (Or.inl rfl)))) (cH0 _ (Or.inr (Or.inr (Or.inl rfl)))) + (le_trans q01 q12) q23 (by linarith) hspMono hcstMono sp2 cs2 un2 tabC2.1 tabC2.2) + (hFbC_of tC2 tC3 LC2 (by unfold tC3; norm_num) q23 (by unfold tC2 sC; norm_num) (by unfold tC2; norm_num) ptC2) t + (by push Not at k2; exact k2.le) k3 + · have h110 : (((1 / 10 : ℚ)) : ℝ) = 1 / 10 := by norm_num + refine piece tC3 (1 / 10) lcpC3 sgC3 ?_ (by unfold sgC3; norm_num) (le_trans q01 (le_trans q12 q23)) q3 (le_refl _) + (lcp0 _ (Or.inr (Or.inr (Or.inr rfl)))) ?_ ?_ t (by push Not at k3; exact k3.le) (by push_cast; exact h10.le) + · rw [show (1 - 1 / 10 : ℚ) = 9 / 10 by norm_num]; exact sigC3 + · refine tab_piece spF cstF tC3 (1 / 10) lcpC3 cHC3 spFloC3 unitLoC3 (lcp0 _ (Or.inr (Or.inr (Or.inr rfl)))) (cH0 _ (Or.inr (Or.inr (Or.inr rfl)))) + (le_trans q01 (le_trans q12 q23)) q3 (le_refl _) hspMono hcstMono sp3 ?_ ?_ tabC3.1 tabC3.2 + · rw [h110]; exact cs3 + · rw [h110]; exact un3 + · intro s hs1' hs2' + have hsC' : s ≤ ((sC : ℚ) : ℝ) := by + have : (1 : ℚ) - tC3 ≤ sC := by unfold tC3 sC; norm_num + have h' : (((1 - tC3 : ℚ)) : ℝ) ≤ ((sC : ℚ) : ℝ) := by exact_mod_cast this + linarith + have h9 : (9 / 10 : ℝ) ≤ s := by + have : ((((1 - 1 / 10 : ℚ)) : ℚ) : ℝ) = 9 / 10 := by norm_num + linarith + have := cfC_neg s h9 hsC' + have h7 : ((liftC : ℚ) : ℝ) ≤ 17 * (((lcpC3 - 5 * sgC3 : ℚ)) : ℝ) := by + have : liftC ≤ 17 * LC3 := LC3_ge + exact_mod_cast this + linarith + +end CongestionNative + +#print axioms CongestionNative.E_lower_cap_om +#print axioms CongestionNative.branchC_om +#print axioms CongestionNative.hcong_of_capclass +#print axioms CongestionNative.unit_mono +#print axioms CongestionNative.tab_piece +#print axioms CongestionNative.ceiling_native diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionNative.md b/research/p104-native-ceiling/lean/Nov15/CongestionNative.md new file mode 100644 index 0000000000..ea9a98b175 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionNative.md @@ -0,0 +1,33 @@ +# CongestionNative.lean (+ CongestionNativeTab.lean, PathCut.lean): the native-covering ceiling kappa <= .0136564 +Copy of the own56 half of CongestionI3Dual*.lean (shipped files untouched), with the HC1-HC4 / AUD / AUD2 edits. Kernel only: no sorry, no native_decide; `#print axioms` of every theorem = [propext, Classical.choice, Quot.sound]. Builds (runlean.sh, one at a time): CongestionNativeTab 10 s / 1.3 GB, PathCut 4 s / 1.4 GB, CongestionNative 11 s / 3.0 GB. + +## What changed against `ceiling_C2` (all done) +- hcong* has the owned surplus on the right: `Omega ks mr s = dprice ks s + mr - (6*9^s+10)`; ks = 24 descents + 13 non-unit rises (sum 102), mr = 10 unit rises (AUD FIX-1; the literal split gives Omega 16.1 < 24.8 and is out of class); stated only for s in [.9, 1 - tC0]. +- `hE` generalised to `Lj <= E + Omega` (`E_lower_cap_om`, `branchC_om`). Omega cancels, so tC0 = .0136564 is unchanged. `branchC_om` needs no ks-hypotheses; hk/hmass/hmd/hmr are used only in the t >= .1 branch (own56_floor, 88c). +- ONE J: a single `J : Finset (ℕ × ℕ)` in hcong, hdist, hJ. It is J^arr (the arrival residual) by interpretation; Lean cannot see that, it is a name for the set the data hypotheses are about. +- FIX C: `Rank8C56`, `Prov`, `PlaneSep`, `MV` are gone. No bare `Prop` stands in for a condition. `ell`, `corr`, `cap` are concrete: `ellC spF s = min (spF (1-s)) (capC s)`, `capC s = (9^s-8^s)/48`, `corrC cstF s = 8 * cstF (1-s)`. +- `LcTabC` is no longer a hypothesis: it is DERIVED (`tab_piece`, `unit_mono` proved) from the rational tables of CongestionNativeTab (outward-rounded, emitted from hc9's 80-digit Decimals; the arithmetic `lcp_j + 8 cH_j <= 1936 min(spFlo_j, unitLo_j/48)` is norm_num-proved) and the hypotheses 11-13 below. +- PathCut.lean: `path_cut` PROVED (abstract: preorder of charts, monotone `Hold`, public edges ascend, owned edges NESTED (FIX A), confinement to G; conclusion: legal path, or a first owned strict descent dropping u_s with all earlier charts holding u_s and c_i <= G). `nested_needed`: Lean counterexample (lateral owned move {0} -> {1}) showing the nestedness premise cannot be dropped. `transported_card_le`: |Jt| <= 48 |V| from the 48-law and "every transported cell lies in cells(visit)". +- `hcong_of_capclass` PROVED: legal cells (charge `Pub + cst*Rm`) + transported cells (`<= 48 Nf`, cap U/48) + Cap class `cst (Rm-8) + U Nf <= Omega` give hcong*. It is the accounting of HC1 sec. 2, not used inside `ceiling_native` (which takes hcong* itself). +No paper statement was found false as written. Known and already encoded: hcong* fails for the natives at t > ~.507 (hence the s-range); the literal ks/mr split is out of class (hence FIX-1). + +## `ceiling_native`: EVERY hypothesis (status for st1 / #7637 / x1t2a; "Lean" = what the kernel checked) +Lean treats R, n, ks, mr, st, E, J, distF, spF, cstF as abstract data. The statement is: IF the listed facts hold for these objects THEN F(1-t, invoice (caller 6 7) n 17) < 0 for t in [tC0, 1]. **That st1, #7637 and x1t2a satisfy the hypotheses (class membership) rests on the computed facts below, not on Lean.** One owned layer is shared by all three words (one data point, not three). +1. hmono, hd9 (public registers ascend, end <= 9): natives: computed fact (0 non-ascending public moves; WHOLEFLOOR/hcong/audit/au2.py, audit2/aud2a.py). +2. hmix (<= 5 mixed registers): natives: computed fact (hmix = 5, aud2a.py). +3. hk, hmass, hmd, hmr (ks/mr split, ranks <= 6 in [1,9], sum 102 >= 56, length 37 >= 8, mr 10 >= 8): natives: computed fact (au1.py, aud2a.py). +4. hF (F-currency identity, equality up to float noise): natives: computed fact (hc6.py, aud2a.py; needs all 400 mains to span 8). +5. hY (104 <= st + 47, st = 1266): natives: computed fact (aud2a.py). +6. hst (slack >= 158 on the grid; 0 only at s = 1): natives: computed fact (hc6.py, aud2a.py). +7. hEex (E >= sum of register excesses; identity): proved as an identity on the natives (hc6.py); open as a general lemma outside the natives. +8. **hcong\*** (sum_J min(dist,cap) - 8 cst <= sum_pub c2 + Omega, s in [.9, 1-tC0]): paper-proved on the Cap class from Path-Cut + I3 + rise charge (PV1 sec. 3, HC1 sec. 2); in Lean only `path_cut`, `transported_card_le`, `hcong_of_capclass` (the combinatorial/arithmetic parts) are proved; the register-machine facts (SP span law, D_t-confined ADD path, I3 distance bound) are NOT formalised. Natives: computed fact: Cap margin Omega - cst(Rm-8) - U Nf >= 19.356 on [.9, 1-tC0] (Omega 47.995, Nf 24, Rm 56); 6124 public moves nested strict ascents, 47 owned moves nested (23 up, 24 down), 207,881 ADDs same chart; all 4962 cells have a legal owned-descent-free path (WHOLEFLOOR/hcong/audit/au1.py, audit2/aud2a.py, prov/pv1-pv4.py). 48-law: computed exhaustively (aud2d.py, max n*m = 48 over all 1,398,491 port-spanned subspaces of dim <= 4; natives max 24, hc8.py). +9. hdist (spF(1-s) <= distF s p for p in J): paper-proved (I3 path bound, ID1, audited); Lean: hypothesis. Natives: covered by the same computed census as 8. +10. **hJ (1936 <= |J^arr|)**: HYPOTHESIS, and for the general Desc56 class a CONJECTURE (AUD2 FIX B: rigidity is numerical, span-form L1-L3 and shared carriers open). Natives: computed fact: |J^arr| = 4962 (aud2b.py exact mod 2^61-1; hc11.py; 2536 forced cells on route flags). +11. hspMono, hcstMono (spF, cst nondecreasing in t on [tC0, 1/10]): paper-proved (HC3: psi = x^s ln x convex, superadditive, so c2 nondecreasing in t); Lean: NOT proved (spF is a min over a 230+dual shape DAG, not defined in Lean); kept as named hypotheses. +12. hspTab, hcstTab (spFlo_j <= spF(tC_j); cst(t_{j+1}) <= cH_j): computed fact, outward-rounded (hc9.py / hc9.log "ALL TABLE ENTRIES CERTIFIED", relative slack ~1e-9); Lean: hypotheses over certified rationals, arithmetic proved (CongestionNativeTab). +13. hunitTab (unitLo_j <= 9^s - 8^s at s = 1 - t_{j+1}): computed fact (hc9.py unit_lo, Decimal 80 digits, outward); Lean: hypothesis (rpow numerics not kernel-checked). +Proved inside Lean (not hypotheses): sigma certificates sigC0..3, F_base point enclosures ptC0..2, tail cfC_neg/cfC88_neg, own56_floor, two-sided I3 (`E_lower_cap_om`), branches, table derivation. + +## Not covered / open +- Class extension (Desc56 in general, >= 9-row and network decoders, non-Desc56 words): open; Rank8C56 rigidity [Q] enters only through hJ. +- Hypotheses 8, 9, 11 are the formalisation gaps (statements about the register machine and the shape DAG); 10 is a conjecture beyond the natives; 12-13 are certified numerics outside the kernel. diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionNativeH.lean b/research/p104-native-ceiling/lean/Nov15/CongestionNativeH.lean new file mode 100644 index 0000000000..0a9abce348 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionNativeH.lean @@ -0,0 +1,245 @@ +import Nov15.CongestionNative +import Nov15.PathCut + +/-! +CONGESTION-NATIVE-H: hypothesis reduction for `CongestionNative.ceiling_native` (imported modules unchanged). +1. `c2_anti`: HC3's analytic monotonicity. psi_s(x) = x^s ln x; q(x) = psi_s(x)/x = x^(s-1) ln x is monotone on (0,9] for s in [.9,1], so psi_s is superadditive there, + so d/ds of both move prices h9, k0 is <= 0, so c2 (gs s) a b is nonincreasing in s (nondecreasing in t = 1 - s) for 0 <= a <= b <= 9. +2. `spShape`/`cstShape` (min / max over a finite family of nonnegative combinations of c2-weights) are monotone in t on [0, 1/10]; `hdist_of_shape`. +3. `hcong_of_paths`: Path-Cut + 48-law + `hcong_of_capclass` glued: hcong* from per-cell chart paths. +4. `ceiling_native'`: reduced hypothesis list (see CongestionNativeH.md). +-/ +namespace CongestionNativeH +open NumCertK JointCeiling CallerCost CongestionI3 Real Finset CongestionI3Dual CongestionNative + +/-! ### 1. superadditivity of psi and monotonicity of c2 in s -/ + +theorem q_mono (s : ℝ) (hs0 : 9 / 10 ≤ s) (hs1 : s ≤ 1) : + MonotoneOn (fun x : ℝ => x ^ (s - 1) * Real.log x) (Set.Ioc 0 9) := by + have hcont : ContinuousOn (fun x : ℝ => x ^ (s - 1) * Real.log x) (Set.Ioc 0 9) := by + apply ContinuousOn.mul + · intro x hx + exact (Real.continuousAt_rpow_const x (s - 1) (Or.inl hx.1.ne')).continuousWithinAt + · exact Real.continuousOn_log.mono (fun x hx => ne_of_gt hx.1) + have hder : ∀ x : ℝ, 0 < x → HasDerivAt (fun x : ℝ => x ^ (s - 1) * Real.log x) + ((s - 1) * x ^ (s - 1 - 1) * Real.log x + x ^ (s - 1) * x⁻¹) x := by + intro x hx + exact (Real.hasDerivAt_rpow_const (Or.inl hx.ne')).mul (Real.hasDerivAt_log hx.ne') + apply monotoneOn_of_deriv_nonneg (convex_Ioc 0 9) hcont + · intro x hx + rw [interior_Ioc] at hx + exact (hder x hx.1).differentiableAt.differentiableWithinAt + · intro x hx + rw [interior_Ioc] at hx + obtain ⟨hx0, hx9⟩ := hx + rw [(hder x hx0).deriv, Real.rpow_sub_one hx0.ne' (s - 1)] + have hp : 0 < x ^ (s - 1) := Real.rpow_pos_of_pos hx0 _ + have hlog := Real.log_le_sub_one_of_pos hx0 + have key : 0 ≤ (s - 1) * Real.log x + 1 := by + rcases le_total 0 (Real.log x) with h | h + · nlinarith + · nlinarith + have : (s - 1) * (x ^ (s - 1) / x) * Real.log x + x ^ (s - 1) * x⁻¹ = x ^ (s - 1) / x * ((s - 1) * Real.log x + 1) := by + field_simp + rw [this] + exact mul_nonneg (by positivity) key + +/-- psi_s(x) = x^s ln x is superadditive on [0, 9] for s in [.9, 1] -/ +theorem psi_superadd (s : ℝ) (hs0 : 9 / 10 ≤ s) (hs1 : s ≤ 1) (x y : ℝ) (hx : 0 ≤ x) (hy : 0 ≤ y) (hxy : x + y ≤ 9) : + x ^ s * Real.log x + y ^ s * Real.log y ≤ (x + y) ^ s * Real.log (x + y) := by + have hs : s ≠ 0 := by intro h; rw [h] at hs0; norm_num at hs0 + rcases hx.eq_or_lt with rfl | hx' + · simp [Real.zero_rpow hs] + rcases hy.eq_or_lt with rfl | hy' + · simp [Real.zero_rpow hs] + have hq := q_mono s hs0 hs1 + have e : ∀ z : ℝ, 0 < z → z ^ s * Real.log z = z * (z ^ (s - 1) * Real.log z) := by + intro z hz + rw [show z ^ s = z * z ^ (s - 1) by rw [← Real.rpow_one_add' hz.le (by linarith)]; ring_nf]; ring + have h1 : x ^ (s - 1) * Real.log x ≤ (x + y) ^ (s - 1) * Real.log (x + y) := + hq ⟨hx', by linarith⟩ ⟨by linarith, hxy⟩ (by linarith) + have h2 : y ^ (s - 1) * Real.log y ≤ (x + y) ^ (s - 1) * Real.log (x + y) := + hq ⟨hy', by linarith⟩ ⟨by linarith, hxy⟩ (by linarith) + rw [e x hx', e y hy', e (x + y) (by linarith)] + nlinarith + +/-- `s ↦ gs s u + gs s v - gs s (u+v)` is nonincreasing on [.9, 1] when u, v >= 0, u + v <= 9 -/ +theorem tri_anti (u v : ℝ) (hu : 0 ≤ u) (hv : 0 ≤ v) (huv : u + v ≤ 9) : + AntitoneOn (fun s => gs s u + gs s v - gs s (u + v)) (Set.Icc (9 / 10) 1) := by + have hd : ∀ z : ℝ, 0 ≤ z → ∀ s : ℝ, HasDerivAt (fun s => gs s z) (z ^ s * Real.log z) s := by + intro z hz s + rcases hz.eq_or_lt with rfl | hz' + · have : (fun s : ℝ => gs s 0) = fun _ => 0 := by funext s; exact gs_zero s + rw [this] + simpa using hasDerivAt_const s (0 : ℝ) + · have : (fun s : ℝ => gs s z) = fun s => z ^ s := by funext s; simp [gs, hz'] + rw [this] + have := (hasDerivAt_id s).const_rpow hz' + simpa [mul_comm] using this + have hall : ∀ s : ℝ, HasDerivAt (fun s => gs s u + gs s v - gs s (u + v)) + (u ^ s * Real.log u + v ^ s * Real.log v - (u + v) ^ s * Real.log (u + v)) s := + fun s => ((hd u hu s).add (hd v hv s)).sub (hd (u + v) (by linarith) s) + apply antitoneOn_of_deriv_nonpos (convex_Icc _ _) + · exact fun s _ => (hall s).continuousAt.continuousWithinAt + · exact fun s _ => (hall s).differentiableAt.differentiableWithinAt + · intro s hs + rw [interior_Icc] at hs + rw [(hall s).deriv] + linarith [psi_superadd s hs.1.le hs.2.le u v hu hv huv] + +/-- c2 is nonincreasing in s on [.9, 1] (nondecreasing in t = 1 - s) for 0 <= a <= b <= 9. -/ +theorem c2_anti (a b : ℝ) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ 9) (s s' : ℝ) (hs : 9 / 10 ≤ s) (hss : s ≤ s') (hs' : s' ≤ 1) : + c2 (gs s') a b ≤ c2 (gs s) a b := by + have m1 := tri_anti (b - a) (9 - b) (by linarith) (by linarith) (by linarith) ⟨hs, by linarith⟩ ⟨by linarith, hs'⟩ hss + have m2 := tri_anti (b - a) a (by linarith) ha (by linarith) ⟨hs, by linarith⟩ ⟨by linarith, hs'⟩ hss + simp only [show b - a + (9 - b) = 9 - a by ring, show b - a + a = b by ring] at m1 m2 + unfold c2 h9 k0 + exact min_le_min (by linarith) (by linarith) + +/-! ### 2. shape-DAG families: spF (min of sums) and cst (max of sums) are monotone in t; hdist from path membership -/ + +/-- a move of the shape DAG: (weight kappa >= 0, from a, to b), priced `kappa * c2 (gs (1-t)) a b` -/ +abbrev Move := ℝ × ℝ × ℝ +def Valid (m : Move) : Prop := 0 ≤ m.1 ∧ 0 ≤ m.2.1 ∧ m.2.1 ≤ m.2.2 ∧ m.2.2 ≤ 9 +/-- cost of a path (list of moves) at t -/ +noncomputable def wsum (p : List Move) (t : ℝ) : ℝ := (p.map fun m => m.1 * c2 (gs (1 - t)) m.2.1 m.2.2).sum + +theorem wsum_mono (p : List Move) (hp : ∀ m ∈ p, Valid m) (t t' : ℝ) (h0 : 0 ≤ t) (htt : t ≤ t') (h1 : t' ≤ 1 / 10) : + wsum p t ≤ wsum p t' := by + induction p with + | nil => simp [wsum] + | cons m r ih => + have hm := hp m (by simp) + have hr := ih (fun x hx => hp x (by simp [hx])) + have hc := c2_anti m.2.1 m.2.2 hm.2.1 hm.2.2.1 hm.2.2.2 (1 - t') (1 - t) (by linarith) (by linarith) (by linarith) + simp only [wsum, List.map_cons, List.sum_cons] at hr ⊢ + have := mul_le_mul_of_nonneg_left hc hm.1 + linarith + +theorem spShape_mono {κ : Type*} (P : Finset κ) (hP : P.Nonempty) (pth : κ → List Move) (hv : ∀ q ∈ P, ∀ m ∈ pth q, Valid m) + (t t' : ℝ) (h0 : 0 ≤ t) (htt : t ≤ t') (h1 : t' ≤ 1 / 10) : + P.inf' hP (fun q => wsum (pth q) t) ≤ P.inf' hP (fun q => wsum (pth q) t') := by + apply Finset.le_inf' + intro q hq + exact le_trans (Finset.inf'_le _ hq) (wsum_mono _ (hv q hq) t t' h0 htt h1) + +theorem cstShape_mono {κ : Type*} (P : Finset κ) (hP : P.Nonempty) (pth : κ → List Move) (hv : ∀ q ∈ P, ∀ m ∈ pth q, Valid m) + (t t' : ℝ) (h0 : 0 ≤ t) (htt : t ≤ t') (h1 : t' ≤ 1 / 10) : + P.sup' hP (fun q => wsum (pth q) t) ≤ P.sup' hP (fun q => wsum (pth q) t') := by + apply Finset.sup'_le + intro q hq + exact le_trans (wsum_mono _ (hv q hq) t t' h0 htt h1) (Finset.le_sup' (fun q => wsum (pth q) t') hq) + +/-- `hdist` from path membership: if dist equals the cost of SOME shape-DAG path, it is >= the minimum over the DAG. -/ +theorem hdist_of_shape {κ : Type*} (P : Finset κ) (hP : P.Nonempty) (pth : κ → List Move) (d t : ℝ) + (h : ∃ q ∈ P, d = wsum (pth q) t) : P.inf' hP (fun q => wsum (pth q) t) ≤ d := by + obtain ⟨q, hq, rfl⟩ := h + exact Finset.inf'_le _ hq + +/-! ### 3. Path-Cut + 48-law + Cap accounting glued: hcong* from per-cell chart paths -/ + +open Classical in +/-- hcong* (one value of s) from per-cell chart paths. Every cell `p` of `J` carries a chart path `c p 0 .. c p (n p)`; `Hold p C` = "u_s of p lies in C". +Premises of `PathCut.path_cut` hold per cell (public edges ascend, owned edges nested, confinement to `G p`, start holds). The path of a cell is its cancellation path (the beta-path of a J^arr cell); `hconf` and `hstart` are what the arrival decomposition supplies for that path, not free premises, and the lemma is not claimed for arbitrary X_s -> Y_t paths (a path that re-enters D_t by a nested owned descent is an ARRIVAL, counted as J^arr, never cut). A cell whose path is not legal (some chart misses u_s) is cut at a first owned strict +descent `i` dropping u_s with all earlier charts holding it and `c p i <= G p`; `hvisit` says such a cut cell is one of the `cells v` of a visit `v in V` (the 48-law gives `|cells v| <= 48`). +Legal cells charge `Pub + cst Rm` (`hleg`), `|V| <= Nf`, and the Cap class `cst (Rm-8) + U Nf <= Om` closes. -/ +theorem hcong_of_paths {α : Type*} [Preorder α] {ν : Type*} [DecidableEq ν] + (J : Finset (ℕ × ℕ)) (dist : ℕ × ℕ → ℝ) + (c : ℕ × ℕ → ℕ → α) (n : ℕ × ℕ → ℕ) (Hold : ℕ × ℕ → α → Prop) (G : ℕ × ℕ → α) (owned : ℕ × ℕ → ℕ → Prop) + (hHold : ∀ p ∈ J, ∀ C C' : α, C ≤ C' → Hold p C → Hold p C') + (hpub : ∀ p ∈ J, ∀ i < n p, ¬ owned p i → c p i ≤ c p (i + 1)) + (hnest : ∀ p ∈ J, ∀ i < n p, owned p i → (c p i ≤ c p (i + 1) ∨ c p (i + 1) ≤ c p i)) + (hconf : ∀ p ∈ J, ∀ i ≤ n p, c p i ≤ G p) (hstart : ∀ p ∈ J, Hold p (c p 0)) + (V : Finset ν) (cells : ν → Finset (ℕ × ℕ)) (h48 : ∀ v ∈ V, (cells v).card ≤ 48) + (hvisit : ∀ p ∈ J, ∀ i < n p, owned p i → Hold p (c p i) → ¬ Hold p (c p (i + 1)) → c p (i + 1) < c p i → c p i ≤ G p → + (∀ j ≤ i, Hold p (c p j)) → ∃ v ∈ V, p ∈ cells v) + (cap U Pub cst Rm Nf Om : ℝ) (hcap : cap = U / 48) (hU : 0 ≤ U) + (hleg : ∑ p ∈ J.filter (fun p => ∀ i ≤ n p, Hold p (c p i)), dist p ≤ Pub + cst * Rm) + (hVcard : (V.card : ℝ) ≤ Nf) (hclass : cst * (Rm - 8) + U * Nf ≤ Om) : + ∑ p ∈ J, min (dist p) cap - 8 * cst ≤ Pub + Om := by + have hcut : ∀ p ∈ J.filter (fun p => ¬ ∀ i ≤ n p, Hold p (c p i)), ∃ v ∈ V, p ∈ cells v := by + intro p hp + rw [Finset.mem_filter] at hp + obtain ⟨hpJ, hnl⟩ := hp + rcases PathCut.path_cut (c p) (n p) (Hold p) (G p) (owned p) (hHold p hpJ) (hpub p hpJ) (hnest p hpJ) (hconf p hpJ) (hstart p hpJ) with h | ⟨i, hi, ho, h1, h2, h3, h4, h5⟩ + · exact absurd h hnl + · exact hvisit p hpJ i hi ho h1 h2 h3 h4 h5 + have hT := PathCut.transported_card_le V cells _ h48 hcut + have hT' : (((J.filter fun p => ¬ ∀ i ≤ n p, Hold p (c p i)).card : ℕ) : ℝ) ≤ 48 * Nf := by + have : (((J.filter fun p => ¬ ∀ i ≤ n p, Hold p (c p i)).card : ℕ) : ℝ) ≤ 48 * (V.card : ℝ) := by exact_mod_cast hT + linarith + exact hcong_of_capclass J (fun p => ∀ i ≤ n p, Hold p (c p i)) dist cap U Pub cst Rm Nf Om hcap hU hleg hT' hclass + +/-! ### 4. `ceiling_native'`: ceiling_native with hcong, hdist, hspMono, hcstMono replaced by structural hypotheses -/ + +open Classical in +theorem ceiling_native' {ι : Type*} [DecidableEq ι] + (R : Finset ι) (nR : ι → ℕ) (dR : ι → ℕ → ℕ) + (hmono : ∀ r ∈ R, ∀ i < nR r, dR r i ≤ dR r (i + 1)) (hd9 : ∀ r ∈ R, dR r (nR r) ≤ 9) + (hmix : (R.filter fun r => Mixed dR nR r).card ≤ 5) + (n : Inv) (ks : List ℕ) (mr st : ℕ) (E : ℝ → ℝ) (J : Finset (ℕ × ℕ)) (distF : ℝ → ℕ × ℕ → ℝ) (spF cstF : ℝ → ℝ) + (hk : ∀ k ∈ ks, 1 ≤ k ∧ k ≤ 9) (hmass : 56 ≤ ks.sum) (hmd : 8 ≤ ks.length) (hmr : 8 ≤ mr) + (hF : ∀ s, 0 ≤ s → s ≤ 1 → Finv s n ≤ -400 * (8 : ℝ) ^ s - dprice ks s - mr - E s) + (hY : 104 ≤ st + (ks.length + mr)) + (hst : ∀ s, 0 ≤ s → s ≤ 1 → (2 - (2 : ℝ) ^ s) * st ≤ E s) + (hEex : ∀ s, 0 ≤ s → s ≤ 1 → ∑ r ∈ R, ex (gs s) (lev dR r) (nR r) ≤ E s) + -- shape DAG: spF is the minimum, cstF the maximum, over finite families of paths of nonnegative combinations of c2-weights + {κP κC : Type*} (P : Finset κP) (hP : P.Nonempty) (pthP : κP → List Move) (hPv : ∀ q ∈ P, ∀ m ∈ pthP q, Valid m) + (C : Finset κC) (hC : C.Nonempty) (pthC : κC → List Move) (hCv : ∀ q ∈ C, ∀ m ∈ pthC q, Valid m) + (hspShape : ∀ t, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 / 10 → spF t = P.inf' hP (fun q => wsum (pthP q) t)) + (hcstShape : ∀ t, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 / 10 → cstF t = C.sup' hC (fun q => wsum (pthC q) t)) + -- dist is realised by a shape-DAG path + (hdistShape : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → ∀ p ∈ J, ∃ q ∈ P, distF s p = wsum (pthP q) (1 - s)) + (hJ : 1936 ≤ J.card) + -- per-cell chart paths (Path-Cut premises), 48-law and visits + {α : Type*} [Preorder α] {ν : Type*} [DecidableEq ν] + (c : ℕ × ℕ → ℕ → α) (nP : ℕ × ℕ → ℕ) (Hold : ℕ × ℕ → α → Prop) (G : ℕ × ℕ → α) (owned : ℕ × ℕ → ℕ → Prop) + (hHold : ∀ p ∈ J, ∀ C C' : α, C ≤ C' → Hold p C → Hold p C') + (hpub : ∀ p ∈ J, ∀ i < nP p, ¬ owned p i → c p i ≤ c p (i + 1)) + (hnest : ∀ p ∈ J, ∀ i < nP p, owned p i → (c p i ≤ c p (i + 1) ∨ c p (i + 1) ≤ c p i)) + (hconf : ∀ p ∈ J, ∀ i ≤ nP p, c p i ≤ G p) (hstart : ∀ p ∈ J, Hold p (c p 0)) + (V : Finset ν) (cells : ν → Finset (ℕ × ℕ)) (h48 : ∀ v ∈ V, (cells v).card ≤ 48) + (hvisit : ∀ p ∈ J, ∀ i < nP p, owned p i → Hold p (c p i) → ¬ Hold p (c p (i + 1)) → c p (i + 1) < c p i → c p i ≤ G p → + (∀ j ≤ i, Hold p (c p j)) → ∃ v ∈ V, p ∈ cells v) + (Rm Nf : ℝ) (hVcard : (V.card : ℝ) ≤ Nf) + (hleg : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → + ∑ p ∈ J.filter (fun p => ∀ i ≤ nP p, Hold p (c p i)), distF s p ≤ + ∑ r ∈ R, ∑ i ∈ range (nR r), c2 (gs s) (lev dR r i) (lev dR r (i + 1)) + cstF (1 - s) * Rm) + (hclass : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → cstF (1 - s) * (Rm - 8) + ((9 : ℝ) ^ s - (8 : ℝ) ^ s) * Nf ≤ Omega ks mr s) + (hspTab : ((spFloC0 : ℚ) : ℝ) ≤ spF ((tC0 : ℚ) : ℝ) ∧ ((spFloC1 : ℚ) : ℝ) ≤ spF ((tC1 : ℚ) : ℝ) ∧ + ((spFloC2 : ℚ) : ℝ) ≤ spF ((tC2 : ℚ) : ℝ) ∧ ((spFloC3 : ℚ) : ℝ) ≤ spF ((tC3 : ℚ) : ℝ)) + (hcstTab : cstF ((tC1 : ℚ) : ℝ) ≤ ((cHC0 : ℚ) : ℝ) ∧ cstF ((tC2 : ℚ) : ℝ) ≤ ((cHC1 : ℚ) : ℝ) ∧ + cstF ((tC3 : ℚ) : ℝ) ≤ ((cHC2 : ℚ) : ℝ) ∧ cstF (1 / 10) ≤ ((cHC3 : ℚ) : ℝ)) + (hunitTab : ((unitLoC0 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC1 : ℚ) : ℝ)) ∧ + ((unitLoC1 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC2 : ℚ) : ℝ)) ∧ + ((unitLoC2 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) - (8 : ℝ) ^ (1 - ((tC3 : ℚ) : ℝ)) ∧ + ((unitLoC3 : ℚ) : ℝ) ≤ (9 : ℝ) ^ (1 - (1 / 10 : ℝ)) - (8 : ℝ) ^ (1 - (1 / 10 : ℝ))) : + ∀ t : ℝ, ((tC0 : ℚ) : ℝ) ≤ t → t ≤ 1 → Finv (1 - t) (invoice (caller 6 7) n 17) < 0 := by + have htC0 : (0 : ℝ) ≤ ((tC0 : ℚ) : ℝ) := by unfold tC0; norm_num + have hspMono : MonotoneOn spF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10)) := by + intro a ha b hb hab + rw [hspShape a ha.1 ha.2, hspShape b hb.1 hb.2] + exact spShape_mono P hP pthP hPv a b (by linarith [ha.1]) hab hb.2 + have hcstMono : MonotoneOn cstF (Set.Icc ((tC0 : ℚ) : ℝ) (1 / 10)) := by + intro a ha b hb hab + rw [hcstShape a ha.1 ha.2, hcstShape b hb.1 hb.2] + exact cstShape_mono C hC pthC hCv a b (by linarith [ha.1]) hab hb.2 + have hdist : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → ∀ p ∈ J, spF (1 - s) ≤ distF s p := by + intro s h1 h2 p hp + rw [hspShape (1 - s) (by linarith) (by linarith)] + exact hdist_of_shape P hP pthP _ _ (hdistShape s h1 h2 p hp) + have hcong : ∀ s, 9 / 10 ≤ s → s ≤ 1 - ((tC0 : ℚ) : ℝ) → + ∑ p ∈ J, min (distF s p) (capC s) - corrC cstF s ≤ + ∑ r ∈ R, ∑ i ∈ range (nR r), c2 (gs s) (lev dR r i) (lev dR r (i + 1)) + Omega ks mr s := by + intro s h1 h2 + have hU : (0 : ℝ) ≤ (9 : ℝ) ^ s - (8 : ℝ) ^ s := by + have := Real.rpow_le_rpow (show (0:ℝ) ≤ 8 by norm_num) (show (8:ℝ) ≤ 9 by norm_num) (show (0:ℝ) ≤ s by linarith) + linarith + exact hcong_of_paths J (distF s) c nP Hold G owned hHold hpub hnest hconf hstart V cells h48 hvisit + (capC s) ((9 : ℝ) ^ s - (8 : ℝ) ^ s) _ (cstF (1 - s)) Rm Nf (Omega ks mr s) (by unfold capC; rfl) hU + (hleg s h1 h2) hVcard (hclass s h1 h2) + exact ceiling_native R nR dR hmono hd9 hmix n ks mr st E J distF spF cstF hk hmass hmd hmr hF hY hst hEex hcong hdist hJ + hspMono hcstMono hspTab hcstTab hunitTab + +end CongestionNativeH +#print axioms CongestionNativeH.ceiling_native' diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionNativeH.md b/research/p104-native-ceiling/lean/Nov15/CongestionNativeH.md new file mode 100644 index 0000000000..39bac1fb7c --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionNativeH.md @@ -0,0 +1,32 @@ +# CongestionNativeH.lean: ceiling_native' with reduced hypotheses +Imports CongestionNative + PathCut (so path_cut, transported_card_le, hcong_of_capclass are now WIRED into the corollary via `hcong_of_paths`). Existing files unchanged. Kernel only; `#print axioms` of every theorem = [propext, Classical.choice, Quot.sound]. Build 8-20 s, 2.9 GB peak. + +## Proved here (no longer hypotheses) +- `q_mono`, `psi_superadd`, `tri_anti`, `c2_anti`: for s in [.9,1], psi_s(x)=x^s ln x is superadditive on [0,9] (via q(x)=x^(s-1) ln x monotone on (0,9]; first-derivative proof, HC3's convexity not needed), so `c2 (gs s) a b` is nonincreasing in s (nondecreasing in t=1-s) for 0<=a<=b<=9. The paper step was TRUE as written. +- `wsum_mono`, `spShape_mono`, `cstShape_mono`: min / max over a finite family of paths (lists of moves (kappa>=0,a,b), 0<=a<=b<=9, priced kappa*c2) is monotone in t on [0,1/10]. => hspMono, hcstMono DERIVED from `hspShape`/`hcstShape` (spF = inf', cstF = sup' of the path costs on [tC0,1/10]) + `hPv`/`hCv` (validity of moves). NOTE: "spF/cst are such min/max of c2-weighted sums (weights = c2 / (n m), constants)" is now the hypothesis; completeness of the 230+dual shape DAG is NOT checked by Lean. +- `hdist_of_shape`: hdist DERIVED from `hdistShape` (for s in [.9,1-tC0], p in J: distF s p equals the cost of SOME path of the family P at t=1-s) because spF = inf' over P. +- `hcong_of_paths` (+ `path_cut`, `transported_card_le`, `hcong_of_capclass`): hcong* DERIVED from per-cell chart paths (see below). + +## `ceiling_native'`: EVERY hypothesis (copied from the Lean statement) +Data: `{ι} [DecidableEq ι] R : Finset ι, nR : ι→ℕ, dR : ι→ℕ→ℕ` (public registers: level d r 0..n r), `n : Inv`, `ks : List ℕ`, `mr st : ℕ`, `E : ℝ→ℝ`, `J : Finset (ℕ×ℕ)`, `distF : ℝ→ℕ×ℕ→ℝ`, `spF cstF : ℝ→ℝ`; all abstract (nothing in Lean ties them to a word). +Carried over unchanged from ceiling_native: +1. hmono: ∀ r∈R, ∀ i) are consequences of that arrival decomposition, not free premises. They are still hypotheses of `path_cut` in Lean; the decomposition that supplies them is not formalised. For an arbitrary X_s -> Y_t path the conclusion "(t,s) in cells(C_a)" is false (a path that rises outside D_t and re-enters it by a nested owned descent dropping u_s is a path of an ARRIVAL; such cells are counted on the left-hand side as J^arr, never cut). The statement of the lemma is unchanged. On the three natives, 0 of the 4962 junk cells need a cut (every one has a legal owned-descent-free path). +- Corrections to CongestionNative.md (file untouched): its items 3-7, 9 misdescribe hk/hY/hF/hEex/hst/hdist as in item list above; item 8 should read cstF (1-s) not cst; hdist holds for s in [.9,1-tC0]; "natives satisfy hypotheses" rests on computed facts, and hcong/hdist/hspMono/hcstMono additionally on unformalised DAG/register-machine papers (AUD2 did not recheck ID1/DAG/hc9). diff --git a/research/p104-native-ceiling/lean/Nov15/CongestionNativeTab.lean b/research/p104-native-ceiling/lean/Nov15/CongestionNativeTab.lean new file mode 100644 index 0000000000..bb00941798 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/CongestionNativeTab.lean @@ -0,0 +1,38 @@ +import Mathlib.Data.Rat.Defs +import Mathlib.Tactic.NormNum +import Nov15.CongestionI3DualConst + +/-! CONGESTION-NATIVE certified rational tables. +Source: internal notes (Decimal exp/ln at 80 digits, +-1e-70 brackets; every weight of the spF DAG rounded DOWN, +cst rounded UP, unit_lo = 9^s lower - 8^s upper). The values below were emitted by re-running hc9's `spF_lo` / `unit_lo` and converting the +80-digit Decimals to exact rationals, rounded DOWN to 14 digits (outward). `cHC_j` are hc9's own rounded-UP cst brackets. +Here only the pure arithmetic is proved (kernel, norm_num): lcpC_j + 8 cHC_j <= 1936 * min(spFloC_j, unitLoC_j / 48). +The statements `spFloC_j <= spF(tC_j)`, `cst(t_{j+1}) <= cHC_j`, `unitLoC_j <= 9^s - 8^s` are HYPOTHESES of the ceiling (computed, hc9.log). -/ +namespace CongestionNative +open CongestionI3Dual + +def spFloC0 : ℚ := 131069767447 / 20000000000000 +def spFloC1 : ℚ := 655443767027 / 100000000000000 +def spFloC2 : ℚ := 26407594739 / 4000000000000 +def spFloC3 : ℚ := 141372084217 / 12500000000000 +/-- lower bound of 9^(1-t_{j+1}) - 8^(1-t_{j+1}) (t_1, t_2, t_3, 1/10) -/ +def unitLoC0 : ℚ := 11974198659989 / 12500000000000 +def unitLoC1 : ℚ := 95763386760327 / 100000000000000 +def unitLoC2 : ℚ := 23196470570391 / 25000000000000 +def unitLoC3 : ℚ := 72665488499219 / 100000000000000 +/-- upper brackets of cst(t_{j+1}) -/ +def cHC0 : ℚ := 84217 / 2500000 +def cHC1 : ℚ := 339299 / 10 ^ 7 +def cHC2 : ℚ := 579807 / 10 ^ 7 +def cHC3 : ℚ := 2255027 / 10 ^ 7 + +theorem tabC0 : lcpC0 + 8 * cHC0 ≤ 1936 * spFloC0 ∧ lcpC0 + 8 * cHC0 ≤ 1936 * (unitLoC0 / 48) := by + unfold lcpC0 cHC0 spFloC0 unitLoC0; constructor <;> norm_num +theorem tabC1 : lcpC1 + 8 * cHC1 ≤ 1936 * spFloC1 ∧ lcpC1 + 8 * cHC1 ≤ 1936 * (unitLoC1 / 48) := by + unfold lcpC1 cHC1 spFloC1 unitLoC1; constructor <;> norm_num +theorem tabC2 : lcpC2 + 8 * cHC2 ≤ 1936 * spFloC2 ∧ lcpC2 + 8 * cHC2 ≤ 1936 * (unitLoC2 / 48) := by + unfold lcpC2 cHC2 spFloC2 unitLoC2; constructor <;> norm_num +theorem tabC3 : lcpC3 + 8 * cHC3 ≤ 1936 * spFloC3 ∧ lcpC3 + 8 * cHC3 ≤ 1936 * (unitLoC3 / 48) := by + unfold lcpC3 cHC3 spFloC3 unitLoC3; constructor <;> norm_num + +end CongestionNative diff --git a/research/p104-native-ceiling/lean/Nov15/FibreK.lean b/research/p104-native-ceiling/lean/Nov15/FibreK.lean new file mode 100644 index 0000000000..33e2d3f083 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/FibreK.lean @@ -0,0 +1,537 @@ +/- +FibreK . See FibreK.md. Formalises the AUDITED parts of internal notes,2}.md, AUDIT2.md. + +Part 1 THEOREM K. Price premise P0 as an explicit hypothesis (a `Table`: the ranks charged for a helper climb d = e - b on T, + and for a helper MOVE of |dim step| = d on P). The invoice F(t) = sum_r (T_r - P_r) r^(1-t) of the word is + `FK E tb S Pi t`: a function of the ends E, the step multiset S and the climb multiset Pi only (`K_word`, `K_invoice`). +Part 2 G2 for PURE relabels. Helpers end identity; hub gauge L in Blk(V'), M in Blk(G0) (SwapNull.Blk / Undo). + * tail: row relabel (SwapNull.rowSw), V' = sigma^-1 V (the corrected hypothesis), `tail_pairs`; + * head: column relabel (SwapNull.colSw), prefix block G1 = the NEW births-at-0 set, proved DIRECTLY `head_pairs`; + the (birth,end) multiset, hence Pi, hence F(t) by K, is unchanged. +Kernel only: no sorry, no native_decide. +-/ +import Nov15.SwapNull +import Nov15.CallerCost + +set_option linter.unusedSectionVars false +set_option linter.unusedVariables false + +namespace FibreK +open CallerCost + +/-! ### Part 1: THEOREM K -/ + +/-- P0: rank tables. `tT d` = ranks charged to T for a helper with climb d = e - b; +`tP d` = ranks charged to P for a helper MOVE with |Δdim| = d. (Hist = (rank, count) lists.) -/ +structure Table where + tT : ℕ → Hist + tP : ℕ → Hist + +/-- A helper: birth dim, end dim, and its MOVE steps as (source dim, target dim). -/ +structure Helper where + b : ℕ + e : ℕ + steps : List (ℕ × ℕ) + +def gap (s : ℕ × ℕ) : ℕ := Int.natAbs ((s.2 : ℤ) - s.1) + +/-- F-contribution of a histogram: sum count * rank^(1-t). -/ +noncomputable def Fh (l : Hist) (t : ℝ) : ℝ := (l.map fun p => (p.2 : ℝ) * (p.1 : ℝ) ^ (1 - t)).sum +noncomputable def Fi (i : Inv) (t : ℝ) : ℝ := Fh i.T t - Fh i.P t + +theorem Fh_append (l m : Hist) (t : ℝ) : Fh (l ++ m) t = Fh l t + Fh m t := by simp [Fh] + +theorem Fh_scale (L : ℕ) (l : Hist) (t : ℝ) : Fh (scale L l) t = L * Fh l t := by + induction l with + | nil => simp [Fh, scale] + | cons p l ih => + simp only [Fh, scale, List.map_cons, List.sum_cons] at ih ⊢ + rw [ih]; push_cast; ring + +theorem Fh_flatMap {α : Type*} (l : List α) (g : α → Hist) (t : ℝ) : + Fh (l.flatMap g) t = (l.map fun x => Fh (g x) t).sum := by + induction l with + | nil => simp [Fh] + | cons x l ih => simp [List.flatMap_cons, Fh_append, ih] + +/-- invoice = caller + L * native, at the level of F. -/ +theorem Fi_invoice (c n : Inv) (L : ℕ) (t : ℝ) : + Fi (invoice c n L) t = Fi c t + L * Fi n t := by + simp only [Fi, invoice, Fh_append, Fh_scale]; ring + +/-- the native's invoice histograms from the helper list (P0). -/ +def nativeInv (E : Inv) (tb : Table) (H : List Helper) : Inv := + ⟨E.T ++ H.flatMap fun h => tb.tT (h.e - h.b), + E.P ++ H.flatMap fun h => h.steps.flatMap fun s => tb.tP (gap s)⟩ + +/-- the timed-step data: S = multiset of all helper MOVEs, Pi = multiset of climbs e - b. -/ +def Ssum (H : List Helper) : Multiset (ℕ × ℕ) := ↑(H.flatMap Helper.steps) +def PiW (H : List Helper) : Multiset ℕ := ↑(H.map fun h => h.e - h.b) + +/-- F as a function of the DATA (E, S, Pi). -/ +noncomputable def FK (E : Inv) (tb : Table) (S : Multiset (ℕ × ℕ)) (Pi : Multiset ℕ) (t : ℝ) : ℝ := + Fi E t + (Pi.map fun d => Fh (tb.tT d) t).sum - (S.map fun s => Fh (tb.tP (gap s)) t).sum + +theorem sum_flatMap_map {α β : Type*} (H : List α) (g : α → List β) (φ : β → ℝ) : + ((H.flatMap g).map φ).sum = (H.map fun h => ((g h).map φ).sum).sum := by + induction H with + | nil => simp + | cons h H ih => simp [List.flatMap_cons, List.map_append, List.sum_append, ih] + +/-- **THEOREM K** (P0 as hypothesis `tb`): the word's F is `FK` of its (E, S, Pi). -/ +theorem K_word (E : Inv) (tb : Table) (H : List Helper) (t : ℝ) : + Fi (nativeInv E tb H) t = FK E tb (Ssum H) (PiW H) t := by + simp only [Fi, nativeInv, FK, Ssum, PiW, Fh_append, Fh_flatMap, Multiset.map_coe, Multiset.sum_coe] + rw [sum_flatMap_map] + have : ∀ h : Helper, (h.steps.map fun s => Fh (tb.tP (gap s)) t).sum + = Fh (h.steps.flatMap fun s => tb.tP (gap s)) t := fun h => (Fh_flatMap _ _ _).symm + simp only [List.map_map, Function.comp_def, this] + ring + +/-- κ depends only on (E, S, Pi): two words with the same data have the same F, so the same roots. -/ +theorem K_congr (E : Inv) (tb : Table) (H H' : List Helper) + (hS : Ssum H' = Ssum H) (hP : PiW H' = PiW H) (t : ℝ) : + Fi (nativeInv E tb H') t = Fi (nativeInv E tb H) t := by + rw [K_word, K_word, hS, hP] + +/-- the caller invoice of the native (calls = L) is a function of (E, S, Pi) (and the fixed caller). -/ +theorem K_invoice (c E : Inv) (tb : Table) (H : List Helper) (L : ℕ) (t : ℝ) : + Fi (invoice c (nativeInv E tb H) L) t = Fi c t + L * FK E tb (Ssum H) (PiW H) t := by + rw [Fi_invoice, K_word] + +/-- κ = a root of F: invariant when F is. -/ +def IsRoot (F : ℝ → ℝ) (κ : ℝ) : Prop := F κ = 0 + +theorem kappa_depends_only (c E : Inv) (tb : Table) (H H' : List Helper) (L : ℕ) + (hS : Ssum H' = Ssum H) (hP : PiW H' = PiW H) (κ : ℝ) : + IsRoot (Fi (invoice c (nativeInv E tb H') L)) κ ↔ IsRoot (Fi (invoice c (nativeInv E tb H) L)) κ := by + unfold IsRoot + rw [K_invoice, K_invoice, hS, hP] + +/-- the instance used by FloorD0 / V2Bridge: D0 table `tT d = tP d = [(d, 1)]`; then the helper part is +Σ_h [f(e-b) - Σ_steps f(gap)] (the per-helper D0 identity). -/ +def d0Table : Table := ⟨fun d => [(d, 1)], fun d => [(d, 1)]⟩ + +theorem Dh_flatMap {α : Type*} (l : List α) (g : α → Hist) : + Dh (l.flatMap g) = (l.map fun x => Dh (g x)).sum := by + induction l with + | nil => simp [Dh] + | cons x l ih => simp [List.flatMap_cons, Dh_append, ih] + +theorem d0_native (E : Inv) (H : List Helper) : + Dinv (nativeInv E d0Table H) = Dinv E + (H.map fun h => + (fL (h.e - h.b) - (h.steps.map fun s => fL (gap s)).sum)).sum := by + simp only [Dinv, nativeInv, Dh_append, Dh_flatMap, d0Table] + have h1 : ∀ h : Helper, Dh [(h.e - h.b, 1)] = fL (h.e - h.b) := by intro h; simp [Dh] + have h2 : ∀ h : Helper, (h.steps.map fun s => Dh [(gap s, 1)]).sum = (h.steps.map fun s => fL (gap s)).sum := by + intro h; simp [Dh] + have hs : ∀ (l : List Helper) (a b : Helper → ℝ), + (l.map fun h => a h - b h).sum = (l.map a).sum - (l.map b).sum := by + intro l a b + induction l with + | nil => simp + | cons x l ih => simp [ih]; ring + simp only [h1, h2] + rw [hs] + ring + +/-! ### Part 2: G2 for pure relabels -/ +section G2 +open SwapNull +variable {K Reg : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] + +/-- helpers end identity: the final row of a helper is its own unit vector. -/ +def HelpersId (H : Reg → Prop) (F : Matrix Reg Reg K) : Prop := + ∀ x, H x → ∀ k, F x k = (1 : Matrix Reg Reg K) x k + +/-- Row x ∉ V' of L * A * M is the row of A * M. -/ +theorem lrow {V' : Reg → Prop} {L : Matrix Reg Reg K} (hL : Blk V' L) (A : Matrix Reg Reg K) + {x : Reg} (hx : ¬ V' x) (j : Reg) : (L * A) x j = A x j := by + rw [Matrix.mul_apply, Finset.sum_eq_single x] + · rw [hL x x (fun h => hx h.1)]; simp + · intro i _ hi; rw [hL x i (fun h => hx h.1), Matrix.one_apply_ne (Ne.symm hi)]; simp + · simp + +/-- TAIL force: if L ∈ Blk(V'), M ∈ Blk(G0) undo a row relabel of an identity-final matrix, every moved +helper x ∉ V' has x and σ x in G0. -/ +theorem tail_force {H V' G0 : Reg → Prop} {F : Matrix Reg Reg K} (hF : HelpersId H F) + (σ : Equiv.Perm Reg) (hσH : ∀ x, H x → H (σ x)) + (hu : Undo V' G0 F (rowSw σ F)) {x : Reg} (hx : H x) (hV : ¬ V' x) (hm : σ x ≠ x) : + G0 x ∧ G0 (σ x) := by + obtain ⟨L, M, hL, hM, h⟩ := hu + have key : ∀ k, M (σ x) k = (1 : Matrix Reg Reg K) x k := by + intro k + have h1 : (L * rowSw σ F * M) x k = M (σ x) k := by + rw [Matrix.mul_apply, Finset.sum_eq_single (σ x)] + · rw [lrow hL _ hV]; simp [rowSw, hF (σ x) (hσH x hx)] + · intro j _ hj + rw [lrow hL _ hV]; simp [rowSw, hF (σ x) (hσH x hx), Matrix.one_apply_ne (Ne.symm hj)] + · simp + rw [← h1, h]; exact hF x hx k + constructor + · by_contra hg + have := hM (σ x) x (fun h => hg h.2) + rw [key x, Matrix.one_apply_ne hm] at this + simp at this + · by_contra hg + have := hM (σ x) (σ x) (fun h => hg h.1) + rw [key (σ x), Matrix.one_apply_ne (Ne.symm hm)] at this + simp at this + +/-- HEAD force (direct, not by time reversal): a column relabel undone by L ∈ Blk(V), M ∈ Blk(G1): +every moved helper x ∉ V has σ⁻¹ x and x in G1. -/ +theorem head_force {H V G1 : Reg → Prop} {F : Matrix Reg Reg K} (hF : HelpersId H F) + (σ : Equiv.Perm Reg) + (hu : Undo V G1 F (colSw σ F)) {x : Reg} (hx : H x) (hV : ¬ V x) (hm : σ x ≠ x) : + G1 (σ.symm x) ∧ G1 x := by + obtain ⟨L, M, hL, hM, h⟩ := hu + have key : ∀ k, M (σ.symm x) k = (1 : Matrix Reg Reg K) x k := by + intro k + have h1 : (L * colSw σ F * M) x k = M (σ.symm x) k := by + rw [Matrix.mul_apply, Finset.sum_eq_single (σ.symm x)] + · rw [lrow hL _ hV]; simp [colSw, hF x hx] + · intro j _ hj + rw [lrow hL _ hV] + have : x ≠ σ j := fun e => hj (by rw [e]; simp) + simp [colSw, hF x hx, Matrix.one_apply_ne this] + · simp + rw [← h1, h]; exact hF x hx k + have hy : σ.symm x ≠ x := fun e => hm (by + have := congrArg σ e; simpa using this.symm) + constructor + · by_contra hg + have := hM (σ.symm x) (σ.symm x) (fun h => hg h.1) + rw [key (σ.symm x), Matrix.one_apply_ne (Ne.symm hy)] at this + simp at this + · by_contra hg + have := hM (σ.symm x) x (fun h => hg h.2) + rw [key x, Matrix.one_apply_ne hy] at this + simp at this + +/-! counting lemma: equal cardinality, differing only on birth-0 elements, so equal birth multisets -/ +theorem map_birth_eq (β : Reg → ℕ) (A B : Finset Reg) (hc : A.card = B.card) + (hA : ∀ x ∈ A, x ∉ B → β x = 0) (hB : ∀ x ∈ B, x ∉ A → β x = 0) : + A.val.map β = B.val.map β := by + classical + have hne : ∀ b : ℕ, b ≠ 0 → A.filter (fun x => b = β x) = B.filter (fun x => b = β x) := by + intro b hb + ext x + simp only [Finset.mem_filter] + constructor + · rintro ⟨ha, e⟩ + refine ⟨?_, e⟩ + by_contra hn + exact hb (e.trans (hA x ha hn)) + · rintro ⟨ha, e⟩ + refine ⟨?_, e⟩ + by_contra hn + exact hb (e.trans (hB x ha hn)) + apply Multiset.ext.2 + intro b + rw [Multiset.count_map, Multiset.count_map] + simp only [← Finset.filter_val, Finset.card_val] + by_cases hb : b = 0 + · subst hb + have h1 := Finset.card_filter_add_card_filter_not (s := A) (fun x => 0 = β x) + have h2 := Finset.card_filter_add_card_filter_not (s := B) (fun x => 0 = β x) + have h3 : A.filter (fun x => ¬ (0 = β x)) = B.filter (fun x => ¬ (0 = β x)) := by + ext x + simp only [Finset.mem_filter] + constructor + · rintro ⟨ha, e⟩ + refine ⟨?_, e⟩ + by_contra hn + exact e (hA x ha hn).symm + · rintro ⟨ha, e⟩ + refine ⟨?_, e⟩ + by_contra hn + exact e (hB x ha hn).symm + rw [h3] at h1 + omega + · rw [hne b hb] + +variable (β ε : Reg → ℕ) (d : ℕ) + +/-- birth/end pairs of the helpers `Hs`. -/ +def pairs (Hs : Finset Reg) : Multiset (ℕ × ℕ) := Hs.val.map fun x => (β x, ε x) +/-- after a tail relabel x keeps its birth but takes σ x's end. -/ +def pairsTail (σ : Equiv.Perm Reg) (Hs : Finset Reg) : Multiset (ℕ × ℕ) := + Hs.val.map fun x => (β x, ε (σ x)) +/-- after a head relabel x takes σ x's birth but keeps its end. -/ +def pairsHead (σ : Equiv.Perm Reg) (Hs : Finset Reg) : Multiset (ℕ × ℕ) := + Hs.val.map fun x => (β (σ x), ε x) + +theorem sigma_H {H : Reg → Prop} (σ : Equiv.Perm Reg) (hσ : ∀ x, ¬ H x → σ x = x) : + ∀ x, H x → H (σ x) := by + intro x hx + by_contra h + have h1 := hσ _ h + have : σ x = x := σ.injective h1 + exact h (by rw [this]; exact hx) + +theorem split_map {α γ : Type*} (s : Multiset α) (p : α → Prop) [DecidablePred p] (f : α → γ) : + s.map f = (s.filter p).map f + (s.filter (fun x => ¬ p x)).map f := by + rw [← Multiset.map_add, Multiset.filter_add_not] + +/-- the (birth, end) pair multiset determines the climb multiset Pi -/ +def PiOf (ps : Multiset (ℕ × ℕ)) : Multiset ℕ := ps.map fun p => p.2 - p.1 + +theorem PiW_eq (H : List Helper) : PiW H = PiOf (↑(H.map fun h => (h.b, h.e)) : Multiset (ℕ × ℕ)) := by + simp [PiW, PiOf, Multiset.map_coe, List.map_map, Function.comp_def] + +section Pairs + +theorem symm_fix (σ : Equiv.Perm Reg) (x : Reg) (h : σ.symm x = x) : σ x = x := by + have h2 := congrArg σ h + rw [Equiv.apply_symm_apply] at h2 + exact h2.symm + +/-- **G2, TAIL case.** Hypotheses (AUDIT2): helpers end identity; G0-members are born at 0; the V-enders +(= the helpers ending at the single chart `d`) are exactly V ⊆ H; σ permutes helpers only; hub gauge +L ∈ Blk(V'), M ∈ Blk(G0) with V' = σ⁻¹ V. Then the (birth,end) multiset is unchanged. -/ +theorem tail_pairs {H V G0 : Reg → Prop} [DecidablePred H] [DecidablePred V] + {F : Matrix Reg Reg K} (hF : HelpersId H F) (σ : Equiv.Perm Reg) (hσ : ∀ x, ¬ H x → σ x = x) + (hVH : ∀ x, V x → H x) (hE : ∀ x, H x → (ε x = d ↔ V x)) (hG : ∀ x, G0 x → β x = 0) + (hu : Undo (fun x => V (σ x)) G0 F (rowSw σ F)) : + pairsTail β ε σ (Finset.univ.filter H) = pairs β ε (Finset.univ.filter H) := by + classical + have hσH := sigma_H σ hσ + have hσs : ∀ x, ¬ H x → σ.symm x = x := fun x hx => (Equiv.symm_apply_eq σ).2 (hσ x hx).symm + have hσsH := sigma_H σ.symm hσs + set Hs : Finset Reg := Finset.univ.filter H with hHs + have memH : ∀ x, x ∈ Hs ↔ H x := by intro x; simp [hHs] + have F1 : ∀ x, H x → ¬ V (σ x) → σ x ≠ x → β x = 0 ∧ β (σ x) = 0 := by + intro x hx hv hm + obtain ⟨a, b⟩ := tail_force hF σ hσH hu hx hv hm + exact ⟨hG _ a, hG _ b⟩ + have F2 : ∀ x, H x → ¬ V (σ x) → β (σ x) = β x := by + intro x hx hv + by_cases hm : σ x = x + · rw [hm] + · obtain ⟨a, b⟩ := F1 x hx hv hm; rw [a, b] + set V' : Finset Reg := Hs.filter (fun x => V (σ x)) with hV' + set Vf : Finset Reg := Hs.filter V with hVf + have hcard : V'.card = Vf.card := by + apply Finset.card_bij (fun x _ => σ x) + · intro x hx + simp only [hV', hVf, Finset.mem_filter, memH] at hx ⊢ + exact ⟨hσH x hx.1, hx.2⟩ + · intro x _ y _ e; exact σ.injective e + · intro y hy + simp only [hV', hVf, Finset.mem_filter, memH] at hy ⊢ + refine ⟨σ.symm y, ⟨hσsH y hy.1, by simpa using hy.2⟩, by simp⟩ + have F4 : ∀ x ∈ V', x ∉ Vf → β x = 0 := by + intro x hx hxn + simp only [hV', hVf, Finset.mem_filter, memH] at hx hxn + have hnV : ¬ V x := fun h => hxn ⟨hx.1, h⟩ + have hmu : σ (σ.symm x) ≠ σ.symm x := by + intro e + rw [Equiv.apply_symm_apply] at e + exact hnV (by have := symm_fix σ x e.symm; rw [← this]; exact hx.2) + have := (F1 _ (hσsH x hx.1) (by rw [Equiv.apply_symm_apply]; exact hnV) hmu).2 + rwa [Equiv.apply_symm_apply] at this + have F5 : ∀ y ∈ Vf, y ∉ V' → β y = 0 := by + intro y hy hyn + simp only [hV', hVf, Finset.mem_filter, memH] at hy hyn + have hnV : ¬ V (σ y) := fun h => hyn ⟨hy.1, h⟩ + have hm : σ y ≠ y := fun e => hnV (by rw [e]; exact hy.2) + exact (F1 y hy.1 hnV hm).1 + have hV'map : V'.val.map β = Vf.val.map β := + map_birth_eq β V' Vf hcard F4 F5 + -- the non-V' part is carried to the non-V part by σ + set N1 : Finset Reg := Hs.filter (fun x => ¬ V (σ x)) with hN1 + set N2 : Finset Reg := Hs.filter (fun x => ¬ V x) with hN2 + have hN : N2 = N1.map σ.toEmbedding := by + ext y + simp only [hN1, hN2, Finset.mem_filter, Finset.mem_map, memH, Equiv.coe_toEmbedding] + constructor + · rintro ⟨hy, hv⟩ + exact ⟨σ.symm y, ⟨hσsH y hy, by simpa using hv⟩, by simp⟩ + · rintro ⟨x, ⟨hx, hv⟩, rfl⟩ + exact ⟨hσH x hx, hv⟩ + unfold pairsTail pairs + rw [split_map Hs.val (fun x => V (σ x)), split_map Hs.val V] + congr 1 + · have e1 : (Hs.val.filter (fun x => V (σ x))).map (fun x => (β x, ε (σ x))) = + V'.val.map (fun x => (β x, d)) := by + apply Multiset.map_congr rfl + intro x hx + have hx' : x ∈ V' := hx + simp only [hV', Finset.mem_filter, memH] at hx' + rw [(hE (σ x) (hσH x hx'.1)).2 hx'.2] + have e2 : (Hs.val.filter V).map (fun x => (β x, ε x)) = Vf.val.map (fun x => (β x, d)) := by + apply Multiset.map_congr rfl + intro x hx + have hx' : x ∈ Vf := hx + simp only [hVf, Finset.mem_filter, memH] at hx' + rw [(hE x hx'.1).2 hx'.2] + rw [e1, e2] + have h3 : ∀ A : Finset Reg, A.val.map (fun x => (β x, d)) = (A.val.map β).map (fun b => (b, d)) := by + intro A; rw [Multiset.map_map]; rfl + rw [h3, h3, hV'map] + · have e : (Hs.val.filter (fun x => ¬ V (σ x))) = N1.val := rfl + have e' : (Hs.val.filter (fun x => ¬ V x)) = N2.val := rfl + rw [e, e', hN, Finset.map_val, Multiset.map_map] + apply Multiset.map_congr rfl + intro x hx + have hx' : x ∈ N1 := hx + simp only [hN1, Finset.mem_filter, memH] at hx' + simp [F2 x hx'.1 hx'.2] + +/-- **G2, HEAD case, proved directly** (no time reversal). A head relabel x ↦ birth of σ x, same end; +the hub undoing it is L ∈ Blk(V) (the V-enders are unchanged) and the prefix M ∈ Blk(G1), where G1 is the set +of helpers born at 0 in the NEW word (`G1 x → β (σ x) = 0`; the head-side analogue of V' = σ⁻¹ V). -/ +theorem head_pairs {H V G1 : Reg → Prop} [DecidablePred H] [DecidablePred V] + {F : Matrix Reg Reg K} (hF : HelpersId H F) (σ : Equiv.Perm Reg) (hσ : ∀ x, ¬ H x → σ x = x) + (hVH : ∀ x, V x → H x) (hE : ∀ x, H x → (ε x = d ↔ V x)) (hG : ∀ x, G1 x → β (σ x) = 0) + (hu : Undo V G1 F (colSw σ F)) : + pairsHead β ε σ (Finset.univ.filter H) = pairs β ε (Finset.univ.filter H) := by + classical + have hσH := sigma_H σ hσ + have hσs : ∀ x, ¬ H x → σ.symm x = x := fun x hx => (Equiv.symm_apply_eq σ).2 (hσ x hx).symm + have hσsH := sigma_H σ.symm hσs + set Hs : Finset Reg := Finset.univ.filter H with hHs + have memH : ∀ x, x ∈ Hs ↔ H x := by intro x; simp [hHs] + have F1 : ∀ x, H x → ¬ V x → σ x ≠ x → β x = 0 ∧ β (σ x) = 0 := by + intro x hx hv hm + obtain ⟨a, b⟩ := head_force hF σ hu hx hv hm + refine ⟨?_, hG _ b⟩ + have := hG _ a + rwa [Equiv.apply_symm_apply] at this + have F2 : ∀ x, H x → ¬ V x → β (σ x) = β x := by + intro x hx hv + by_cases hm : σ x = x + · rw [hm] + · obtain ⟨a, b⟩ := F1 x hx hv hm; rw [a, b] + set Vf : Finset Reg := Hs.filter V with hVf + set Vs : Finset Reg := Vf.map σ.toEmbedding with hVs + have hcard : Vs.card = Vf.card := Finset.card_map _ + have F4 : ∀ x ∈ Vs, x ∉ Vf → β x = 0 := by + intro x hx hxn + simp only [hVs, hVf, Finset.mem_map, Finset.mem_filter, memH, Equiv.coe_toEmbedding] at hx hxn + obtain ⟨w, ⟨hw, hv⟩, rfl⟩ := hx + have hnV : ¬ V (σ w) := fun h => hxn ⟨hσH w hw, h⟩ + have hm : σ (σ w) ≠ σ w := fun e => hnV (by have := σ.injective e; rw [this]; exact hv) + exact (F1 (σ w) (hσH w hw) hnV hm).1 + have F5 : ∀ x ∈ Vf, x ∉ Vs → β x = 0 := by + intro x hx hxn + simp only [hVs, hVf, Finset.mem_map, Finset.mem_filter, memH, Equiv.coe_toEmbedding] at hx hxn + have hnV : ¬ V (σ.symm x) := fun h => hxn ⟨σ.symm x, ⟨hσsH x hx.1, h⟩, by simp⟩ + have hm : σ (σ.symm x) ≠ σ.symm x := by + intro e + rw [Equiv.apply_symm_apply] at e + exact hnV (by rw [← e]; exact hx.2) + have := (F1 (σ.symm x) (hσsH x hx.1) hnV hm).2 + rwa [Equiv.apply_symm_apply] at this + have hmap : Vs.val.map β = Vf.val.map β := map_birth_eq β Vs Vf hcard F4 F5 + unfold pairsHead pairs + rw [split_map Hs.val V] + conv_rhs => rw [split_map Hs.val V] + congr 1 + · have e1 : (Hs.val.filter V).map (fun x => (β (σ x), ε x)) = Vf.val.map (fun x => (β (σ x), d)) := by + apply Multiset.map_congr rfl + intro x hx + have hx' : x ∈ Vf := hx + simp only [hVf, Finset.mem_filter, memH] at hx' + rw [(hE x hx'.1).2 hx'.2] + have e2 : (Hs.val.filter V).map (fun x => (β x, ε x)) = Vf.val.map (fun x => (β x, d)) := by + apply Multiset.map_congr rfl + intro x hx + have hx' : x ∈ Vf := hx + simp only [hVf, Finset.mem_filter, memH] at hx' + rw [(hE x hx'.1).2 hx'.2] + rw [e1, e2] + have h3 : Vf.val.map (fun x => (β (σ x), d)) = (Vs.val.map β).map (fun b => (b, d)) := by + rw [hVs, Finset.map_val, Multiset.map_map, Multiset.map_map]; rfl + have h4 : Vf.val.map (fun x => (β x, d)) = (Vf.val.map β).map (fun b => (b, d)) := by + rw [Multiset.map_map]; rfl + rw [h3, h4, hmap] + · have e' : (Hs.val.filter (fun x => ¬ V x)) = (Hs.filter (fun x => ¬ V x)).val := rfl + rw [e'] + apply Multiset.map_congr rfl + intro x hx + have hx' : x ∈ Hs.filter (fun x => ¬ V x) := hx + simp only [Finset.mem_filter, memH] at hx' + simp [F2 x hx'.1 hx'.2] + +/-! ### G2 ⇒ Π ⇒ F: the combined statement -/ + +theorem tail_Pi {H V G0 : Reg → Prop} [DecidablePred H] [DecidablePred V] + {F : Matrix Reg Reg K} (hF : HelpersId H F) (σ : Equiv.Perm Reg) (hσ : ∀ x, ¬ H x → σ x = x) + (hVH : ∀ x, V x → H x) (hE : ∀ x, H x → (ε x = d ↔ V x)) (hG : ∀ x, G0 x → β x = 0) + (hu : Undo (fun x => V (σ x)) G0 F (rowSw σ F)) : + PiOf (pairsTail β ε σ (Finset.univ.filter H)) = PiOf (pairs β ε (Finset.univ.filter H)) := by + rw [tail_pairs β ε d hF σ hσ hVH hE hG hu] + +theorem head_Pi {H V G1 : Reg → Prop} [DecidablePred H] [DecidablePred V] + {F : Matrix Reg Reg K} (hF : HelpersId H F) (σ : Equiv.Perm Reg) (hσ : ∀ x, ¬ H x → σ x = x) + (hVH : ∀ x, V x → H x) (hE : ∀ x, H x → (ε x = d ↔ V x)) (hG : ∀ x, G1 x → β (σ x) = 0) + (hu : Undo V G1 F (colSw σ F)) : + PiOf (pairsHead β ε σ (Finset.univ.filter H)) = PiOf (pairs β ε (Finset.univ.filter H)) := by + rw [head_pairs β ε d hF σ hσ hVH hE hG hu] + +/-- G2 + K: a hub-undoable pure tail relabel that keeps the step multiset S (SwapNull.stays_multiset) leaves +F(t), hence κ, unchanged. -/ +theorem tail_F_null {H V G0 : Reg → Prop} [DecidablePred H] [DecidablePred V] + {F : Matrix Reg Reg K} (hF : HelpersId H F) (σ : Equiv.Perm Reg) (hσ : ∀ x, ¬ H x → σ x = x) + (hVH : ∀ x, V x → H x) (hE : ∀ x, H x → (ε x = d ↔ V x)) (hG : ∀ x, G0 x → β x = 0) + (hu : Undo (fun x => V (σ x)) G0 F (rowSw σ F)) + (E : Inv) (tb : Table) (S : Multiset (ℕ × ℕ)) (t : ℝ) : + FK E tb S (PiOf (pairsTail β ε σ (Finset.univ.filter H))) t = + FK E tb S (PiOf (pairs β ε (Finset.univ.filter H))) t := by + rw [tail_Pi β ε d hF σ hσ hVH hE hG hu] + +theorem head_F_null {H V G1 : Reg → Prop} [DecidablePred H] [DecidablePred V] + {F : Matrix Reg Reg K} (hF : HelpersId H F) (σ : Equiv.Perm Reg) (hσ : ∀ x, ¬ H x → σ x = x) + (hVH : ∀ x, V x → H x) (hE : ∀ x, H x → (ε x = d ↔ V x)) (hG : ∀ x, G1 x → β (σ x) = 0) + (hu : Undo V G1 F (colSw σ F)) + (E : Inv) (tb : Table) (S : Multiset (ℕ × ℕ)) (t : ℝ) : + FK E tb S (PiOf (pairsHead β ε σ (Finset.univ.filter H))) t = + FK E tb S (PiOf (pairs β ε (Finset.univ.filter H))) t := by + rw [head_Pi β ε d hF σ hσ hVH hE hG hu] + +end Pairs + +/-! ### C3 (R1's 3-cycle) is NOT undoable once V' = σ⁻¹ V is used (Lean check of AUDIT2's observation) -/ +section C3 +open SwapNull + +/-- a = (5→9), b = (0→7), c = (0→9) on Fin 3; σ: a ↦ b, b ↦ c, c ↦ a. -/ +def c3β : Fin 3 → ℕ := ![5, 0, 0] +def c3ε : Fin 3 → ℕ := ![9, 7, 9] +def c3σ : Equiv.Perm (Fin 3) := Equiv.swap 0 1 * Equiv.swap 1 2 + +theorem c3σ_apply : c3σ 0 = 1 ∧ c3σ 1 = 2 ∧ c3σ 2 = 0 := by decide + +/-- the pair multiset changes (Π {4,7,9} → {2,9,9} in R1's words) -/ +theorem c3_pairs_change : + pairsTail c3β c3ε c3σ Finset.univ ≠ pairs c3β c3ε Finset.univ := by decide + +theorem c3_not_undoable (G0 : Fin 3 → Prop) (hG : ∀ x, G0 x → c3β x = 0) : + ¬ Undo (fun x => (c3ε (c3σ x) = 9 : Prop)) G0 (1 : Matrix (Fin 3) (Fin 3) ℚ) + (rowSw c3σ 1) := by + intro hu + have := tail_pairs (K := ℚ) (H := fun _ => True) (V := fun x => c3ε x = 9) c3β c3ε 9 + (F := 1) (fun _ _ _ => rfl) c3σ (fun x hx => absurd trivial hx) (fun _ _ => trivial) + (fun x _ => Iff.rfl) hG hu + have h2 : (Finset.univ.filter (fun _ : Fin 3 => True)) = (Finset.univ : Finset (Fin 3)) := by simp + rw [h2] at this + exact c3_pairs_change this +end C3 + +#print axioms K_word +#print axioms K_congr +#print axioms K_invoice +#print axioms kappa_depends_only +#print axioms d0_native +#print axioms tail_force +#print axioms head_force +#print axioms tail_pairs +#print axioms head_pairs +#print axioms tail_F_null +#print axioms head_F_null +#print axioms c3_not_undoable + +end G2 + +end FibreK diff --git a/research/p104-native-ceiling/lean/Nov15/FibreK.md b/research/p104-native-ceiling/lean/Nov15/FibreK.md new file mode 100644 index 0000000000..eaeb3e7e8e --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/FibreK.md @@ -0,0 +1,51 @@ +# FibreK (Nov 17): Theorem K and G2 for pure relabels, in Lean + +`Nov15/FibreK.lean`, Lean 4.33.0-rc1 + Mathlib, kernel only: no `sorry`, no `native_decide`; every theorem prints +`[propext, Classical.choice, Quot.sound]`. Builds in 10 s / 2.9 GB (runlean.sh guard). Reuses `SwapNull` (Blk, Undo, rowSw, +colSw; olean built into .lake/build/lib/lean/Nov15) and `CallerCost` (Hist, Inv, invoice, Dh/Dinv). + +## 1. THEOREM K (AUDIT2: sound with fixes) +P0 is an explicit hypothesis: `Table {tT tP : ℕ → Hist}` = the ranks a helper pays on T for climb d = e - b and on P for a +helper MOVE of |Δdim| = d (the price checker's per-call ranks; AUDIT2 could not find the README in the tree, so the table is a parameter, +not a quoted constant). A word is `E : Inv` (fixed by the ends) plus helpers `{b, e, steps}`. +* `K_word`: `Fi (nativeInv E tb H) t = FK E tb (Ssum H) (PiW H) t`, i.e. F(t) = Σ_r (T_r − P_r) r^(1−t) is a function of + (E, S = multiset of helper MOVEs (src dim, tgt dim), Π = multiset {e_h − b_h}). Births/ends enter only through Π; ADD/SCALE/SWAP + appear nowhere (they are not in the table). +* `K_congr`, `kappa_depends_only`: same (E, S, Π) ⇒ same F, same roots, also for the caller invoice + `K_invoice : Fi (invoice c n L) t = Fi c t + L · FK E tb S Π t` (CallerCost.invoice). +* `d0_native`: for `d0Table` (ranks = gaps) the helper part is Σ_h [f(e−b) − Σ_steps f(gap)] (the per-helper D0 identity of + FloorD0/V2Bridge, f = r ln r, Dh convention). +Remark: the dependence on S is only through the multiset of GAPS |Δdim|; the source dim itself is not priced. + +## 2. G2 for PURE relabels (AUDIT2: sound with fixes) +Model: registers `Reg` (Fintype), final matrix `F : Matrix Reg Reg K`; `HelpersId H F` = every helper's final row is its own unit +vector; hub gauge = `Undo V G F F'` := ∃ L M, Blk V L ∧ Blk G M ∧ L·F'·M = F (SwapNull; invertibility NOT demanded, which only +strengthens the conclusions). σ permutes helpers only (`σ x = x` off H). β, ε : birth/end dims; V ⊆ H = the helpers with ε = d +(one chart, `hE : ε x = d ↔ V x`). +* `tail_force`: F' = rowSw σ F (SwapNull.tail_run), L ∈ Blk(V′), M ∈ Blk(G0) ⇒ every moved helper x ∉ V′ has x, σ x ∈ G0. +* `tail_pairs`: with G0 ⊆ {β = 0} and **V′ = σ⁻¹ V** (`fun x => V (σ x)`), the (birth,end) multiset {(β x, ε (σ x))} equals + {(β x, ε x)}. Proof: σ carries H∖V′ onto H∖V keeping β (moved ⇒ both birth 0); V′∖V and V∖V′ are birth-0 and |V′| = |V| + (`map_birth_eq`). +* `head_force`, `head_pairs`, DIRECT (not by time reversal): F' = colSw σ F (SwapNull.head_run), L ∈ Blk(V) (V unchanged), M ∈ Blk(G1) + where **G1 is the NEW births-at-0 set** (`G1 x → β (σ x) = 0`); moved x ∉ V ⇒ σ⁻¹x, x ∈ G1 ⇒ β x = β (σ x) = 0. Pair multiset + {(β (σ x), ε x)} = {(β x, ε x)}. This is the head analogue of V′ = σ⁻¹V (the time-reversal image of "prefix ↔ V"); using the + native G0 here is the head-side form of R1's slip. +* `tail_Pi`, `head_Pi`: Π unchanged. `tail_F_null`, `head_F_null`: FK (hence F(t), hence κ by K) unchanged, for any S, E, tb. S + being unchanged by a swap is SwapNull.stays_multiset (not re-proved; the theorem takes S as the common argument). +* `c3_not_undoable`: Lean check of AUDIT2's observation. R1's 3-cycle C3 (a=(5→9), b=(0→7), c=(0→9), σ: a→b→c→a, identity F) + is NOT undoable under V′ = σ⁻¹V for any G0 ⊆ {β=0}: its pair multiset changes (`c3_pairs_change`), which `tail_pairs` forbids + for undoable relabels. (Undoable only under the native V = the retracted slip.) + +No paper statement was found false as written. Corrections to the wording: (i) heads need the NEW G0 (G1 above), "same proof under +time reversal" is right only with that substitution; (ii) K needs P0 as a stated table; (iii) G2 conclusions about κ also need +S unchanged (SwapNull.stays_multiset), which is a separate hypothesis here. + +## 3. NOT covered +* relabel + interior gauge D(t) jointly (D(end) ≠ I on helper rows; AUDIT2 item 2/4): the model has D = I, F' = P_σ F exactly. +* the LOOP claim (THEORY2 §2 "interiors differ by a time-slice gauge, κ-null"): UNSOUND as stated (D(t) = U′U⁻¹ exists for any two + circuits; legality of D(t+1) T D(t)⁻¹ and D(end) = I are the content). Not formalised; only the true restatement + "same skeleton ⇒ κ-null" follows from K_word (S and Π fixed). +* "native = max over fibre": NOT established (needs the joint case above, theorem R with the real the price checker concavity, and S that + includes END charts for D helpers). R (re-pairing monotonicity), G1-tree, T (cover lemma), U in full generality are not formalised. +* mixed head+tail sequences (only each pure case); multi-chart V ends; helpers not ending identity. +* The real the price checker table values are not instantiated (`Table` is abstract; `d0Table` is the D0 convention). diff --git a/research/p104-native-ceiling/lean/Nov15/FrameSep.lean b/research/p104-native-ceiling/lean/Nov15/FrameSep.lean new file mode 100644 index 0000000000..abf460717d --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/FrameSep.lean @@ -0,0 +1,165 @@ +/- +SPEC7/SPEC8 frame-separation law, See FrameSep.md. +Source: internal notes (sec 2, 4), SPEC8.md (sec 2, 4). +Abstract model: frames = submodules of V; a route is a time-indexed frame sequence whose +non-owned (public) steps ascend by inclusion; owned steps are arbitrary. +-/ +import Mathlib.LinearAlgebra.Span.Basic +import Mathlib.Algebra.Field.Rat +import Mathlib.Data.Rat.Defs + +namespace FrameSep + +variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] + +/-- A register's frame history; `owned t` marks step t -> t+1 as an owned MOVE. -/ +structure Route (K V : Type*) [Field K] [AddCommGroup V] [Module K V] where + f : ℕ → Submodule K V + owned : ℕ → Prop + pub : ∀ t, ¬ owned t → f t ≤ f (t + 1) + +namespace Route +variable (R : Route K V) + +/-- public stretch: no owned step in [a,b) -/ +def Pub (a b : ℕ) : Prop := ∀ s, a ≤ s → s < b → ¬ R.owned s + +theorem pub_mono {a b : ℕ} (hab : a ≤ b) (h : R.Pub a b) : R.f a ≤ R.f b := by + induction b, hab using Nat.le_induction with + | base => exact le_rfl + | succ b hb ih => + exact (ih fun s h1 h2 => h s h1 (by omega)).trans (R.pub b (h b hb (by omega))) + +theorem persist {u : V} {a b : ℕ} (hab : a ≤ b) (h : R.Pub a b) (hu : u ∈ R.f a) : + u ∈ R.f b := R.pub_mono hab h hu + +/-- First-exit law: leaving a u-containing frame needs an OWNED step that genuinely drops u. -/ +theorem exit_owned {u : V} {a b : ℕ} (hab : a ≤ b) (hu : u ∈ R.f a) (hb : u ∉ R.f b) : + ∃ s, a ≤ s ∧ s < b ∧ R.owned s ∧ u ∈ R.f s ∧ u ∉ R.f (s + 1) := by + induction b, hab using Nat.le_induction with + | base => exact absurd hu hb + | succ b hb' ih => + by_cases hb0 : u ∈ R.f b + · refine ⟨b, hb', by omega, ?_, hb0, hb⟩ + by_contra hno + exact hb (R.pub b hno hb0) + · obtain ⟨s, h1, h2, h3, h4, h5⟩ := ih hb0 + exact ⟨s, h1, by omega, h3, h4, h5⟩ + +/-- A route is public if it has no owned steps. -/ +def IsPublic : Prop := ∀ t, ¬ R.owned t + +theorem IsPublic.mono {R : Route K V} (h : R.IsPublic) {a b : ℕ} (hab : a ≤ b) : + R.f a ≤ R.f b := R.pub_mono hab fun s _ _ => h s + +theorem IsPublic.persist {R : Route K V} (h : R.IsPublic) {u : V} {a b : ℕ} (hab : a ≤ b) + (hu : u ∈ R.f a) : u ∈ R.f b := h.mono hab hu + +end Route + +/-- SPEC7 core: X contains u at the start of a public route, Y's frames lie in W with u ∉ W. + Then X's frames never equal Y's frames. -/ +theorem X_Y_never_share (X Y : Route K V) (u : V) (W : Submodule K V) (hu : u ∉ W) + (hX : X.IsPublic) (hX0 : u ∈ X.f 0) (hY : ∀ t, Y.f t ≤ W) (s t : ℕ) : + X.f s ≠ Y.f t := by + intro h + exact hu (hY t (h ▸ hX.persist (Nat.zero_le s) hX0)) + +/-- Any public register that has read X_a (co-present at X's frame, X's frame containing u) + at time t0 never again shares a frame with Y at any time t ≥ t0. -/ +theorem reader_never_meets_Y_after (X Y P : Route K V) (u : V) (W : Submodule K V) + (hu : u ∉ W) (hX : X.IsPublic) (hX0 : u ∈ X.f 0) (hP : P.IsPublic) + (hY : ∀ t, Y.f t ≤ W) {s t0 : ℕ} (hread : P.f t0 = X.f s) {t t' : ℕ} (htt : t0 ≤ t) : + P.f t ≠ Y.f t' := by + intro h + have h1 : u ∈ P.f t0 := hread ▸ hX.persist (Nat.zero_le s) hX0 + exact hu (hY t' (h ▸ hP.persist htt h1)) + +/-- Scope: "ever reads X_a ⇒ never meets Y_a" needs "afterwards"; a public helper may meet Y + before it reads X. Concrete counterexample over ℚ×ℚ. -/ +theorem meet_before_read_possible : + ∃ (X Y P : Route ℚ (ℚ × ℚ)) (u : ℚ × ℚ) (W : Submodule ℚ (ℚ × ℚ)), + u ∉ W ∧ X.IsPublic ∧ u ∈ X.f 0 ∧ P.IsPublic ∧ (∀ t, Y.f t ≤ W) ∧ + P.f 1 = X.f 1 ∧ P.f 0 = Y.f 0 := by + let W : Submodule ℚ (ℚ × ℚ) := Submodule.span ℚ {((0 : ℚ), (1 : ℚ))} + refine ⟨⟨fun _ => ⊤, fun _ => False, fun _ _ => le_rfl⟩, + ⟨fun _ => W, fun _ => False, fun _ _ => le_rfl⟩, + ⟨fun t => if t = 0 then W else ⊤, fun _ => False, ?_⟩, (1, 0), W, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro t _ + by_cases h : t = 0 + · subst h; simp + · simp [h] + · intro h + obtain ⟨a, ha⟩ := Submodule.mem_span_singleton.mp h + have := congrArg Prod.fst ha + simp at this + · intro t h; exact h + · trivial + · intro t h; exact h + · intro t; exact le_rfl + · simp + · simp + +/-- Entry law: content (u) in a register's history, then a u-free frame at time t: + an owned step dropped it. With all owned destinations in D and F = frame(t) ∉ D, + the register took an owned MOVE to a landing frame d ∈ D and then ASCENDED + publicly (d < F strictly) before reaching F. -/ +theorem owned_landing_then_ascent (R : Route K V) (D : Set (Submodule K V)) (u : V) + (hD : ∀ s, R.owned s → R.f (s + 1) ∈ D) {a t : ℕ} (hat : a ≤ t) (hu : u ∈ R.f a) + (hF : u ∉ R.f t) (hFD : R.f t ∉ D) : + ∃ s, a ≤ s ∧ s < t ∧ R.owned s ∧ R.f (s + 1) ∈ D ∧ R.f (s + 1) < R.f t := by + -- last owned step before t + have key : ∀ t, a ≤ t → R.Pub a t ∨ + ∃ s, a ≤ s ∧ s < t ∧ R.owned s ∧ R.f (s + 1) ≤ R.f t := by + intro t hat + induction t, hat using Nat.le_induction with + | base => exact Or.inl fun s h1 h2 => by omega + | succ t ht ih => + by_cases ho : R.owned t + · exact Or.inr ⟨t, ht, by omega, ho, le_rfl⟩ + · rcases ih with h | ⟨s, h1, h2, h3, h4⟩ + · left + intro s h1 h2 + by_cases hs : s = t + · subst hs; exact ho + · exact h s h1 (by omega) + · exact Or.inr ⟨s, h1, by omega, h3, h4.trans (R.pub t ho)⟩ + rcases key t hat with h | ⟨s, h1, h2, h3, h4⟩ + · exact absurd (R.persist hat h hu) hF + · refine ⟨s, h1, h2, h3, hD s h3, lt_of_le_of_ne h4 ?_⟩ + intro heq + exact hFD (heq ▸ hD s h3) + +/-- SPEC8 corollary: a u-holding register sitting in Y's final frame F (u-free since F ≤ W, + u ∉ W) with F ∉ D has landed by an owned MOVE in D and climbed publicly strictly above + the landing frame: it is a ferrying register, not an owned register at a landing frame. -/ +theorem delivery_needs_ferry (R : Route K V) (D : Set (Submodule K V)) (u : V) + (W F : Submodule K V) (hu : u ∉ W) (hFW : F ≤ W) (hFD : F ∉ D) + (hD : ∀ s, R.owned s → R.f (s + 1) ∈ D) {a t : ℕ} (hat : a ≤ t) (hua : u ∈ R.f a) + (hFt : R.f t = F) : + ∃ s, a ≤ s ∧ s < t ∧ R.owned s ∧ R.f (s + 1) ∈ D ∧ R.f (s + 1) < F := by + have hF : u ∉ R.f t := fun h => hu (hFW (hFt ▸ h)) + obtain ⟨s, h1, h2, h3, h4, h5⟩ := + owned_landing_then_ascent R D u hD hat hua hF (hFt ▸ hFD) + exact ⟨s, h1, h2, h3, h4, hFt ▸ h5⟩ + +/-- Consequently no owned destination (a fixed set D) equals a delivered frame: + strict ascent means the delivering register took at least one public step after its + owned landing (landing frame ≠ F). -/ +theorem landing_ne_final (R : Route K V) (D : Set (Submodule K V)) (u : V) + (W F : Submodule K V) (hu : u ∉ W) (hFW : F ≤ W) (hFD : F ∉ D) + (hD : ∀ s, R.owned s → R.f (s + 1) ∈ D) {a t : ℕ} (hat : a ≤ t) (hua : u ∈ R.f a) + (hFt : R.f t = F) : + ∃ s, s < t ∧ R.owned s ∧ R.f (s + 1) ≠ F := by + obtain ⟨s, -, h2, h3, -, h5⟩ := delivery_needs_ferry R D u W F hu hFW hFD hD hat hua hFt + exact ⟨s, h2, h3, h5.ne⟩ + +end FrameSep + +#print axioms FrameSep.X_Y_never_share +#print axioms FrameSep.reader_never_meets_Y_after +#print axioms FrameSep.meet_before_read_possible +#print axioms FrameSep.Route.exit_owned +#print axioms FrameSep.owned_landing_then_ascent +#print axioms FrameSep.delivery_needs_ferry +#print axioms FrameSep.landing_ne_final diff --git a/research/p104-native-ceiling/lean/Nov15/FrameSep.md b/research/p104-native-ceiling/lean/Nov15/FrameSep.md new file mode 100644 index 0000000000..16dbbd840e --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/FrameSep.md @@ -0,0 +1,13 @@ +# FrameSep.lean: SPEC7 frame-separation law + SPEC8 corollary +Kernel-only, no sorry/native_decide, ~3 s / 1.5 GB, imports Mathlib only (does not need TokenCancel/TCLemma/W0Cancel: the law is purely about frames). Axioms [propext, Classical.choice, Quot.sound] (two theorems: [propext, Quot.sound]). + +**Model.** Frames = submodules of V. `Route`: frame sequence f, flag `owned t` for step t->t+1; non-owned (public) steps satisfy f t <= f (t+1); owned steps arbitrary. "Holds x_a content" = frame contains u_a. + +**Theorems.** +- `Route.exit_owned`: u in f a, u not in f b (a<=b) => an OWNED step s with u in f s, u not in f (s+1). (public routes never drop u.) +- `X_Y_never_share`: X public with u in f 0, Y frames <= W, u not in W => X.f s != Y.f t for all s,t (SPEC7 core; "below V" is automatic since W != V). +- `reader_never_meets_Y_after`: public P co-present with X at t0 => P.f t != Y.f t' for all t >= t0. +- `owned_landing_then_ascent`, `delivery_needs_ferry`, `landing_ne_final` (SPEC8): all owned MOVE destinations in D, F = Y's final frame (F <= W), F not in D, a register that ever held u sits in F at t => it took an owned MOVE to some d in D and climbed publicly with d < F strictly, i.e. it is a ferrying register, never an owned register at its landing frame. + +**Scope / correction (stated at once).** SPEC7's "any public that ever reads X_a can never meet Y_a" is true only AFTER the read (its parenthetical "later frames contain u_a"). `meet_before_read_possible` (over Q x Q): a public helper has frame W = Y's frame at time 0, then reads X at time 1. The paper statement is not false (it says later), but the unqualified reading is; use the `_after` form. +Modelling limits: content is tracked by "frame contained u" along one register's history (direct holders; multi-hop taint through u-free registers not modelled); owned steps are assumed to land in D (every owned step is a MOVE with destination in D); CLEAR of content is not modelled. diff --git a/research/p104-native-ceiling/lean/Nov15/JointCeiling.lean b/research/p104-native-ceiling/lean/Nov15/JointCeiling.lean new file mode 100644 index 0000000000..4989827790 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/JointCeiling.lean @@ -0,0 +1,809 @@ +/- +JOINT-CEILING (; CORRECTED by , Nov 17 per CALLERFLOOR R2 + AUDIT2: arms of 1 repriced). Formalises the AUDITED structure of CALLERFLOOR R1 (internal notes + AUDIT1.md) +on top of Nov15/CallerCost.lean. Kernel only (no sorry, no native_decide; `decide +kernel` is kernel evaluation, no extra axiom). +F(s) = sum (T-P) r^s, s = 1-t (so F = the R1 "F(t)" = sum (T-P) r^(1-t)). + 1. invoice F = caller F + k * native F for ALL s (invoice_F, same proof as D0). + 2. native floor Nfl(s) = 400*8^s + 16 + 88*(2-2^s): the exact F of the floor histogram (natFloor_F); the bound F_nat <= -Nfl is a HYPOTHESIS (hN). + 3. class lemmas as HYPOTHESES (structure InClass): B-form per-split optimality pointwise in F, sign floor th >= 4 (or 3), two arms (rho = 2). + 4. closed form FB a b th (all a,b >= 1) with bridge to CallerCost.caller for a,b >= 2 (FB_eq). + 5. ceiling theorem, REDUCED to the named numeric hypothesis NumCert th tbar (finite list of rational inequalities, tail.py). + 6. kernel-checked numerics: split 2|2 at t >= 141/4096, the CORRECTED argmax split 1|1 at t >= 176/4096 (36 rational cells), and the control C(8|9): root of the invoice F in (.0204,.0205). + CORRECTION (R2/AUDIT2): R1's FB overcharged every arm of length 1 by 208 one-stage lines (P[8]) -- FBc below adds 208*8^s per arm of 1; + the old .0336 ceiling (and the NumCert built from cf.py) is WITHDRAWN; the certified ceiling is kappa <= .0419448764 (A = 4 QUERY, B-form masks, peak 1|1). +-/ +import Nov15.CallerCost +import Mathlib.Analysis.SpecialFunctions.Pow.Real + +namespace JointCeiling +open CallerCost Real + +/-! ### 1. F-form of the invoice -/ +noncomputable def Fh (s : ℝ) (l : Hist) : ℝ := (l.map fun p => (p.2 : ℝ) * (p.1 : ℝ) ^ s).sum +noncomputable def Finv (s : ℝ) (i : Inv) : ℝ := Fh s i.T - Fh s i.P + +theorem Fh_append (s : ℝ) (l m : Hist) : Fh s (l ++ m) = Fh s l + Fh s m := by simp [Fh] +theorem Fh_scale (s : ℝ) (L : ℕ) (l : Hist) : Fh s (scale L l) = L * Fh s l := by + induction l with + | nil => simp [Fh, scale] + | cons p l ih => + simp only [Fh, scale, List.map_cons, List.sum_cons] at ih ⊢ + rw [ih]; push_cast; ring + +/-- the invoice in kappa form: F = caller part + k * native part, for every s (hence every t = 1 - s) -/ +theorem invoice_F (s : ℝ) (c n : Inv) (L : ℕ) : Finv s (invoice c n L) = Finv s c + L * Finv s n := by + simp only [Finv, invoice, Fh_append, Fh_scale]; ring + +theorem Fh_mono (l : Hist) (hl : ∀ p ∈ l, 1 ≤ p.1) {s s' : ℝ} (h : s ≤ s') : Fh s l ≤ Fh s' l := by + induction l with + | nil => simp [Fh] + | cons p l ih => + have ih' := ih (fun q hq => hl q (by simp [hq])) + have hp : (1 : ℝ) ≤ p.1 := by exact_mod_cast hl p (by simp) + simp only [Fh, List.map_cons, List.sum_cons] at ih' ⊢ + have := Real.rpow_le_rpow_of_exponent_le hp h + have h2 : (p.2 : ℝ) * (p.1 : ℝ) ^ s ≤ (p.2 : ℝ) * (p.1 : ℝ) ^ s' := + mul_le_mul_of_nonneg_left this (Nat.cast_nonneg _) + linarith + +/-! ### 2. native floor -/ +noncomputable def Nfl (s : ℝ) : ℝ := 400 * (8 : ℝ) ^ s + 16 + 88 * (2 - (2 : ℝ) ^ s) +/-- the per-call native floor histogram: 88 stops priced T[2]-2P[1], 400 rank-8 mains, 16 owned (rank 1) + 176 stop credits -/ +def natFloor : Inv := ⟨[(2, 88)], [(8, 400), (1, 192)]⟩ +theorem natFloor_F (s : ℝ) : Finv s natFloor = -Nfl s := by + simp [Finv, natFloor, Fh, Nfl]; ring + +/-! ### 3. closed form of the caller family, all a,b >= 1 -/ +noncomputable def FB (a b th : ℕ) (s : ℝ) : ℝ := + 208 * (∑ i ∈ Finset.range a, ((8 * i + 9 : ℕ) : ℝ) ^ s + ∑ i ∈ Finset.range b, ((8 * i + 9 : ℕ) : ℝ) ^ s + + ((8 * (a + b) + 1 : ℕ) : ℝ) ^ s) + - 208 * (∑ i ∈ Finset.range (a - 2), ((8 * i + 16 : ℕ) : ℝ) ^ s + ∑ i ∈ Finset.range (b - 2), ((8 * i + 16 : ℕ) : ℝ) ^ s) + - (384 + 16 * ((a + b : ℕ) : ℝ)) * (8 : ℝ) ^ s - 96 * th - 32 * (9 : ℝ) ^ s + +theorem Fh_armT (s : ℝ) (n c : ℕ) : + Fh s (armT n c) = c * ∑ i ∈ Finset.range n, ((8 * i + 9 : ℕ) : ℝ) ^ s := by + induction n with + | zero => simp [armT, Fh] + | succ n ih => + have : armT (n + 1) c = armT n c ++ [(8 * n + 9, c)] := by simp [armT, List.range_succ] + rw [this, Fh_append, ih, Finset.sum_range_succ]; simp [Fh]; ring +theorem Fh_armP (s : ℝ) (m c : ℕ) : + Fh s (armP m c) = c * ∑ i ∈ Finset.range m, ((8 * i + 16 : ℕ) : ℝ) ^ s := by + induction m with + | zero => simp [armP, Fh] + | succ n ih => + have : armP (n + 1) c = armP n c ++ [(8 * n + 16, c)] := by simp [armP, List.range_succ] + rw [this, Fh_append, ih, Finset.sum_range_succ]; simp [Fh]; ring + +/-- bridge: CallerCost's histogram caller (a' + 2 | b' + 2), thin 4, has F = FB (a'+2) (b'+2) 4 -/ +theorem FB_eq (s : ℝ) (a' b' : ℕ) : Finv s (caller a' b') = FB (a' + 2) (b' + 2) 4 s := by + have hk : a' + 2 + (b' + 2) = a' + b' + 4 := by ring + simp only [Finv, caller, callerT, callerP, Fh_append, Fh_armT, Fh_armP, FB, hk] + simp [Fh] + ring + +theorem FB_th_mono (a b : ℕ) {th th0 : ℕ} (h : th0 ≤ th) (s : ℝ) : FB a b th s ≤ FB a b th0 s := by + unfold FB + have : (th0 : ℝ) ≤ th := by exact_mod_cast h + linarith + +/-! ### 3b. CORRECTION (R2/AUDIT2): arms of length 1. + cf.py / CALLERCO s1h priced every arm of 1 with 208 spurious one-stage lines (P[8]); the ledger-correct caller (r2.py port model) + has the same histograms except P[8] is lowered by 208 per arm of 1. FBc = FB + 208 * 8^s per arm of 1; for a,b >= 2 FBc = FB. -/ +def ind (x : ℕ) : ℕ := if x = 1 then 1 else 0 +noncomputable def FBc (a b th : ℕ) (s : ℝ) : ℝ := FB a b th s + 208 * ((ind a + ind b : ℕ) : ℝ) * (8 : ℝ) ^ s + +theorem FBc_two (a b th : ℕ) (s : ℝ) (ha : 2 ≤ a) (hb : 2 ≤ b) : FBc a b th s = FB a b th s := by + have h1 : ind a = 0 := by unfold ind; split_ifs <;> omega + have h2 : ind b = 0 := by unfold ind; split_ifs <;> omega + simp [FBc, h1, h2] + +theorem FBc_th_mono (a b : ℕ) {th th0 : ℕ} (h : th0 ≤ th) (s : ℝ) : FBc a b th s ≤ FBc a b th0 s := by + unfold FBc + have := FB_th_mono a b h s + linarith + +/-- the corrected caller histograms (a, b >= 1; thin queries th): arms as in CallerCost, P[8] = 384 + 16 (a+b) - 208 (#arms of 1) -/ +def callerG (a b th : ℕ) : Inv := + ⟨armT a 208 ++ armT b 208 ++ [(8 * (a + b) + 1, 208)], + armP (a - 2) 208 ++ armP (b - 2) 208 ++ [(8, 384 + 16 * (a + b) - 208 * (ind a + ind b)), (1, 96 * th), (9, 32)]⟩ + +theorem ind_le (a b : ℕ) (ha : 1 ≤ a) (hb : 1 ≤ b) : 208 * (ind a + ind b) ≤ 384 + 16 * (a + b) := by + unfold ind; split_ifs <;> omega + +theorem callerG_F (a b th : ℕ) (ha : 1 ≤ a) (hb : 1 ≤ b) (s : ℝ) : Finv s (callerG a b th) = FBc a b th s := by + have hle := ind_le a b ha hb + have hc : (((384 + 16 * (a + b) - 208 * (ind a + ind b) : ℕ)) : ℝ) = 384 + 16 * ((a + b : ℕ) : ℝ) - 208 * ((ind a + ind b : ℕ) : ℝ) := by + rw [Nat.cast_sub hle]; push_cast; ring + simp only [Finv, callerG, Fh_append, Fh_armT, Fh_armP, FBc, FB] + simp [Fh, hc] + push_cast + ring + +/-- for a, b >= 2 the corrected caller has the same F as CallerCost.caller (so reproduction of #7113 is unaffected) -/ +theorem callerG_eq_caller_F (a' b' : ℕ) (s : ℝ) : Finv s (callerG (a' + 2) (b' + 2) 4) = Finv s (caller a' b') := by + rw [callerG_F _ _ _ (by omega) (by omega), FBc_two _ _ _ _ (by omega) (by omega), FB_eq] + +/-- LEDGER LAW for ALL arms >= 1: S(callerG) = 3408 (a+b) - 208 (+ 96 (4 - th)); at a,b >= 2 this is CallerCost.S_caller. + (cf.py's version gave 3408 (a+b) - 208 - 1664 per arm of 1: the broken ledger.) -/ +theorem Sh_armP' (x : ℕ) (hx : 1 ≤ x) : + Sh (armP (x - 2) 208) = 208 * (4 * ((x : ℤ) - 2) * ((x : ℤ) - 2) + 12 * ((x : ℤ) - 2)) + 1664 * (ind x : ℤ) := by + rw [Sh_armP] + rcases Nat.lt_or_ge x 2 with h | h + · have : x = 1 := by omega + subst this; simp [ind] + · have h1 : ((x - 2 : ℕ) : ℤ) = (x : ℤ) - 2 := by omega + have h2 : ind x = 0 := by unfold ind; split_ifs <;> omega + rw [h1, h2]; simp + +theorem callerG_S (a b : ℕ) (ha : 1 ≤ a) (hb : 1 ≤ b) : + Sinv (callerG a b 4) = 3408 * ((a : ℤ) + b) - 208 := by + have hle := ind_le a b ha hb + have hc : (((384 + 16 * (a + b) - 208 * (ind a + ind b) : ℕ)) : ℤ) = 384 + 16 * ((a + b : ℕ) : ℤ) - 208 * ((ind a + ind b : ℕ) : ℤ) := by + rw [Nat.cast_sub hle]; push_cast; ring + simp only [Sinv, callerG, Sh_append, Sh_armT, Sh_armP' a ha, Sh_armP' b hb] + simp only [Sh, List.map_cons, List.sum_cons, List.map_nil, List.sum_nil] + rw [hc] + push_cast + ring + +/-! ### 4. class lemmas as explicit hypotheses -/ +/-- A caller in the audited class (CALLERFLOOR R1 sec 1): two-arm nested rho = 2 root with arms a|b >= 1 (k = a+b calls), + thin queries th. The CLASS LEMMAS are fields (hypotheses; a parallel lane proves them): + hB : B-form per-split optimality, pointwise in F(t) (CALLEROPEN Crossing + Floor lemmas; AUDIT1 item 1: only the D0/ratio form is proved); + hth : sign floor thin >= th0 (SIGNCAP/BEAUTY84; th0 = 4 built, 3 unbuilt); + hrho: rho >= 2 (rho = 1 needs t = -1, closed). rho = 2 enters only through the shape of FB (the two-arm closed form). -/ +structure InClass (th0 : ℕ) where + a : ℕ + b : ℕ + th : ℕ + rho : ℕ + ci : Inv + ha : 1 ≤ a + hb : 1 ≤ b + hth : th0 ≤ th + hrho : 2 ≤ rho + hB : ∀ s : ℝ, 0 ≤ s → s ≤ 1 → Finv s ci ≤ FBc a b th s + + +/-- the NUMERIC CERTIFICATE as a named hypothesis (REGENERATED, , from the AUDITED r2c.py; R1's cf.py-based list is withdrawn). + Statement: for every split a|b (a,b>=1) and 0 <= s <= 1-tbar, FBc a b th0 s - (a+b) Nfl s < 0. + Source: internal notes (lines 8-12: 1|1 root via cf.cert on the ledger-correct port model, th = th0; lines 13-17: 1|b, b = 2..59, + interval cover on [t0, 1] with pk._coef of joint(A(1,b), B(1,b), 1+b); lines 18-26: tail k >= 61 with R1's U plus the arm-of-1 correction + +208*8^s, U < 0 and U' < 0 by cover) together with a,b >= 2 splits from R1 tail.py lines 6-26 / cf.py `cert` lines 33-40 (unchanged: FBc = FB there, + FBc_two + callerG_eq_caller_F; r2.py asserts identity with the port model). Output r2c.out (th4: kbar .041944876391, cert True, 1|b True, tail True; + th3: .068120327915). Not discharged in Lean: ~1,800 (a,b) pairs of 40-digit interval covers, plus the R1 tail Jensen/MVT step (AUDIT2: unaudited). + tbar = .0419448764 (th0 = 4, rounded UP from .041944876391; A = 4 QUERY, B-form masks) and .0681203280 (th0 = 3: th3 B-form-A class only; + AUDIT2: scanned, not covered, for the true sign-floor class). -/ +def NumCert (th0 : ℕ) (tbar : ℝ) : Prop := + ∀ a b : ℕ, 1 ≤ a → 1 ≤ b → ∀ s : ℝ, 0 ≤ s → s ≤ 1 - tbar → FBc a b th0 s - ((a + b : ℕ) : ℝ) * Nfl s < 0 + +noncomputable def tbar4 : ℝ := 419448764 / 10 ^ 10 +noncomputable def tbar3 : ℝ := 681203280 / 10 ^ 10 + +/-- CEILING THEOREM (conditional on the class lemmas hB/hth/hrho, the native floor hN, and NumCert): + for every caller in the class and every native meeting the floor, the invoice F(t) = Finv (1-t) is < 0 for t >= tbar. -/ +theorem ceiling {th0 : ℕ} {tbar : ℝ} (hnum : NumCert th0 tbar) (c : InClass th0) (n : Inv) + (hN : ∀ s : ℝ, 0 ≤ s → s ≤ 1 → Finv s n ≤ -Nfl s) (htb : 0 ≤ tbar) + (s : ℝ) (hs0 : 0 ≤ s) (hs : s ≤ 1 - tbar) : + Finv s (invoice c.ci n (c.a + c.b)) < 0 := by + have hs1 : s ≤ 1 := by linarith + rw [invoice_F] + have h1 := c.hB s hs0 hs1 + have h2 := hN s hs0 hs1 + have h3 : ((c.a + c.b : ℕ) : ℝ) * Finv s n ≤ ((c.a + c.b : ℕ) : ℝ) * (-Nfl s) := + mul_le_mul_of_nonneg_left h2 (Nat.cast_nonneg _) + have h4 := FBc_th_mono c.a c.b c.hth s + have h5 := hnum c.a c.b c.ha c.hb s hs0 hs + linarith + +theorem ceiling4 (hnum : NumCert 4 tbar4) (c : InClass 4) (n : Inv) + (hN : ∀ s : ℝ, 0 ≤ s → s ≤ 1 → Finv s n ≤ -Nfl s) (t : ℝ) (ht : tbar4 ≤ t) (ht1 : t ≤ 1) : + Finv (1 - t) (invoice c.ci n (c.a + c.b)) < 0 := + ceiling hnum c n hN (by unfold tbar4; norm_num) (1 - t) (by linarith) (by linarith) + +theorem ceiling3 (hnum : NumCert 3 tbar3) (c : InClass 3) (n : Inv) + (hN : ∀ s : ℝ, 0 ≤ s → s ≤ 1 → Finv s n ≤ -Nfl s) (t : ℝ) (ht : tbar3 ≤ t) (ht1 : t ≤ 1) : + Finv (1 - t) (invoice c.ci n (c.a + c.b)) < 0 := + ceiling hnum c n hN (by unfold tbar3; norm_num) (1 - t) (by linarith) (by linarith) + + +/-! ### 5. kernel-checked numerics: rational rpow bounds through natural-number powers -/ +theorem rp_pow {x : ℕ} {p q : ℕ} (hq : 0 < q) : (((x : ℝ) ^ ((p : ℝ) / q)) ^ q) = (x : ℝ) ^ p := by + rw [← Real.rpow_natCast, ← Real.rpow_mul (Nat.cast_nonneg x), div_mul_cancel₀ _ (by exact_mod_cast hq.ne'), + Real.rpow_natCast] + +theorem rp_le_nat {x p q n d : ℕ} (hq : 0 < q) (hd : 0 < d) (h : x ^ p * d ^ q ≤ n ^ q) : + (x : ℝ) ^ ((p : ℝ) / q) ≤ (n : ℝ) / d := by + by_contra hc + have hc := not_le.mp hc + have hdr : (0 : ℝ) < d := by exact_mod_cast hd + have h1 : (((n : ℝ) / d)) ^ q < (((x : ℝ) ^ ((p : ℝ) / q)) ^ q) := + pow_lt_pow_left₀ hc (by positivity) hq.ne' + rw [rp_pow hq, div_pow, div_lt_iff₀ (by positivity)] at h1 + have h2 : ((x ^ p * d ^ q : ℕ) : ℝ) ≤ ((n ^ q : ℕ) : ℝ) := by exact_mod_cast h + push_cast at h2 + linarith + +theorem rp_ge_nat {x p q n d : ℕ} (hq : 0 < q) (hd : 0 < d) (h : n ^ q ≤ x ^ p * d ^ q) : + (n : ℝ) / d ≤ (x : ℝ) ^ ((p : ℝ) / q) := by + by_contra hc + have hc := not_le.mp hc + have hdr : (0 : ℝ) < d := by exact_mod_cast hd + have h1 : (((x : ℝ) ^ ((p : ℝ) / q))) ^ q < (((n : ℝ) / d)) ^ q := + pow_lt_pow_left₀ hc (by positivity) hq.ne' + rw [rp_pow hq, div_pow, lt_div_iff₀ (by positivity)] at h1 + have h2 : ((n ^ q : ℕ) : ℝ) ≤ ((x ^ p * d ^ q : ℕ) : ℝ) := by exact_mod_cast h + push_cast at h2 + linarith + +/-- upper bound of F-sum of a histogram at s = p/q by natural numerators U r / d -/ +theorem Fh_le (l : Hist) (p q d : ℕ) (U : ℕ → ℕ) (hq : 0 < q) (hd : 0 < d) + (h : ∀ pr ∈ l, pr.1 ^ p * d ^ q ≤ (U pr.1) ^ q) : + Fh ((p : ℝ) / q) l ≤ ((l.map fun pr => pr.2 * U pr.1).sum : ℕ) / (d : ℝ) := by + induction l with + | nil => simp [Fh] + | cons pr l ih => + have ih' := ih (fun r hr => h r (by simp [hr])) + have h1 := rp_le_nat hq hd (h pr (by simp)) + simp only [Fh, List.map_cons, List.sum_cons] at ih' ⊢ + rw [Nat.cast_add, Nat.cast_mul] + have h2 : (pr.2 : ℝ) * (pr.1 : ℝ) ^ ((p : ℝ) / q) ≤ (pr.2 : ℝ) * ((U pr.1 : ℝ) / d) := + mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg _) + have h3 : (pr.2 : ℝ) * ((U pr.1 : ℝ) / d) = ((pr.2 : ℝ) * U pr.1) / d := by ring + rw [add_div] + linarith + +theorem Fh_ge (l : Hist) (p q d : ℕ) (L : ℕ → ℕ) (hq : 0 < q) (hd : 0 < d) + (h : ∀ pr ∈ l, (L pr.1) ^ q ≤ pr.1 ^ p * d ^ q) : + ((l.map fun pr => pr.2 * L pr.1).sum : ℕ) / (d : ℝ) ≤ Fh ((p : ℝ) / q) l := by + induction l with + | nil => simp [Fh] + | cons pr l ih => + have ih' := ih (fun r hr => h r (by simp [hr])) + have h1 := rp_ge_nat hq hd (h pr (by simp)) + simp only [Fh, List.map_cons, List.sum_cons] at ih' ⊢ + rw [Nat.cast_add, Nat.cast_mul] + have h2 : (pr.2 : ℝ) * ((L pr.1 : ℝ) / d) ≤ (pr.2 : ℝ) * (pr.1 : ℝ) ^ ((p : ℝ) / q) := + mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg _) + have h3 : (pr.2 : ℝ) * ((L pr.1 : ℝ) / d) = ((pr.2 : ℝ) * L pr.1) / d := by ring + rw [add_div] + linarith + +/-- certificate cell: for s in [px/q, py/q], F(s) <= (T-part at py) - (P-part at px) < 0 by natural-number checks -/ +theorem cell_neg (i : Inv) (px py q d : ℕ) (U L : ℕ → ℕ) (hq : 0 < q) (hd : 0 < d) + (hrT : ∀ pr ∈ i.T, 1 ≤ pr.1) (hrP : ∀ pr ∈ i.P, 1 ≤ pr.1) + (hT : ∀ pr ∈ i.T, pr.1 ^ py * d ^ q ≤ (U pr.1) ^ q) + (hP : ∀ pr ∈ i.P, (L pr.1) ^ q ≤ pr.1 ^ px * d ^ q) + (hsum : (i.T.map fun pr => pr.2 * U pr.1).sum < (i.P.map fun pr => pr.2 * L pr.1).sum) + (s : ℝ) (hx : (px : ℝ) / q ≤ s) (hy : s ≤ (py : ℝ) / q) : Finv s i < 0 := by + have a1 := Fh_mono i.T hrT hy + have a2 := Fh_mono i.P hrP hx + have a3 := Fh_le i.T py q d U hq hd hT + have a4 := Fh_ge i.P px q d L hq hd hP + have hdr : (0 : ℝ) < d := by exact_mod_cast hd + have a5 : (((i.T.map fun pr => pr.2 * U pr.1).sum : ℕ) : ℝ) < (((i.P.map fun pr => pr.2 * L pr.1).sum : ℕ) : ℝ) := by + exact_mod_cast hsum + have a6 : (((i.T.map fun pr => pr.2 * U pr.1).sum : ℕ) : ℝ) / d < (((i.P.map fun pr => pr.2 * L pr.1).sum : ℕ) : ℝ) / d := + div_lt_div_of_pos_right a5 hdr + unfold Finv + linarith + +/-- the converse cell for a positive sign (used for the control bracket): F(s) > 0 at the single point s = p/q -/ +theorem pt_pos (i : Inv) (p q d : ℕ) (U L : ℕ → ℕ) (hq : 0 < q) (hd : 0 < d) + (hT : ∀ pr ∈ i.T, (L pr.1) ^ q ≤ pr.1 ^ p * d ^ q) + (hP : ∀ pr ∈ i.P, pr.1 ^ p * d ^ q ≤ (U pr.1) ^ q) + (hsum : (i.P.map fun pr => pr.2 * U pr.1).sum < (i.T.map fun pr => pr.2 * L pr.1).sum) : + 0 < Finv ((p : ℝ) / q) i := by + have a3 := Fh_le i.P p q d U hq hd hP + have a4 := Fh_ge i.T p q d L hq hd hT + have hdr : (0 : ℝ) < d := by exact_mod_cast hd + have a5 : (((i.P.map fun pr => pr.2 * U pr.1).sum : ℕ) : ℝ) < (((i.T.map fun pr => pr.2 * L pr.1).sum : ℕ) : ℝ) := by + exact_mod_cast hsum + have a6 : (((i.P.map fun pr => pr.2 * U pr.1).sum : ℕ) : ℝ) / d < (((i.T.map fun pr => pr.2 * L pr.1).sum : ℕ) : ℝ) / d := + div_lt_div_of_pos_right a5 hdr + unfold Finv + linarith + +/-! ### 6. the argmax split 2|2 (k = 4, thin 4): F < 0 for t >= 141/4096 (= .034424), 28-cell rational cover (python: internal notes cover, generators Nov15/jointceiling_gen/) + (the exact crossing .0336321541 needs rpow to 1e-10: held in NumCert, see sec 4) -/ +def I22 : Inv := invoice (caller 0 0) natFloor 4 +theorem I22_F (s : ℝ) : Finv s I22 = FBc 2 2 4 s - ((2 + 2 : ℕ) : ℝ) * Nfl s := by + rw [FBc_two 2 2 4 s (by norm_num) (by norm_num)] + have h := invoice_F s (caller 0 0) natFloor 4 + rw [natFloor_F, FB_eq] at h + show Finv s (invoice (caller 0 0) natFloor 4) = _ + rw [h]; push_cast; ring +theorem cell22_0 (s : ℝ) (hx : ((0 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((988 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 0 988 4096 100000000 (fun r => if r = 2 then 118198437 else if r = 9 then 169892315 else if r = 17 then 198060441 else if r = 33 then 232424644 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 99999999 else if r = 9 then 99999999 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_1 (s : ℝ) (hx : ((988 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((1977 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 988 1977 4096 100000000 (fun r => if r = 2 then 139732347 else if r = 9 then 288788857 else if r = 17 then 392550812 else if r = 33 then 540673488 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 165133497 else if r = 9 then 169892312 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_2 (s : ℝ) (hx : ((1977 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((2471 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 1977 2471 4096 100000000 (fun r => if r = 2 then 151915755 else if r = 9 then 376415325 else if r = 17 then 552452252 else if r = 33 then 824282651 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 272829196 else if r = 9 then 288788854 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_3 (s : ℝ) (hx : ((2471 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((2718 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 2471 2718 4096 100000000 (fun r => if r = 2 then 158400208 else if r = 9 then 429744898 else if r = 17 then 655381507 else if r = 33 then 1017763102 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 350597193 else if r = 9 then 376415322 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_4 (s : ℝ) (hx : ((2718 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((2966 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 2718 2966 4096 100000000 (fun r => if r = 2 then 165189399 else if r = 9 then 490893330 else if r = 17 then 778025837 else if r = 33 then 1257731609 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 397436025 else if r = 9 then 429744895 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_5 (s : ℝ) (hx : ((2966 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3213 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 2966 3213 4096 100000000 (fun r => if r = 2 then 172240432 else if r = 9 then 560441857 else if r = 17 then 922982473 else if r = 33 then 1552953737 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 450761181 else if r = 9 then 490893327 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_6 (s : ℝ) (hx : ((3213 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3336 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3213 3336 4096 100000000 (fun r => if r = 2 then 175863141 else if r = 9 then 598667655 else if r = 17 then 1004946564 else if r = 33 then 1724878163 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 510981649 else if r = 9 then 560441854 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_7 (s : ℝ) (hx : ((3336 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3460 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3336 3460 4096 100000000 (fun r => if r = 2 then 179592434 else if r = 9 then 639843844 else if r = 17 then 1094946471 else if r = 33 then 1917472133 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 543906765 else if r = 9 then 598667652 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_8 (s : ℝ) (hx : ((3460 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3583 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3460 3583 4096 100000000 (fun r => if r = 2 then 183369777 else if r = 9 then 683485377 else if r = 17 then 1192181571 else if r = 33 then 2129751667 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 579247408 else if r = 9 then 639843841 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_9 (s : ℝ) (hx : ((3583 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3645 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3583 3645 4096 100000000 (fun r => if r = 2 then 185303816 else if r = 9 then 706599503 else if r = 17 then 1244421092 else if r = 33 then 2245506338 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 616571231 else if r = 9 then 683485374 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_10 (s : ℝ) (hx : ((3645 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3707 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3645 3707 4096 100000000 (fun r => if r = 2 then 187258254 else if r = 9 then 730495304 else if r = 17 then 1298949666 else if r = 33 then 2367552420 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 636287037 else if r = 9 then 706599500 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_11 (s : ℝ) (hx : ((3707 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3769 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3707 3769 4096 100000000 (fun r => if r = 2 then 189233305 else if r = 9 then 755199213 else if r = 17 then 1355867597 else if r = 33 then 2496231861 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 656633287 else if r = 9 then 730495301 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_12 (s : ℝ) (hx : ((3769 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3800 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3769 3800 4096 100000000 (fun r => if r = 2 then 190228629 else if r = 9 then 767862713 else if r = 17 then 1385255112 else if r = 33 then 2563171002 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 677630139 else if r = 9 then 755199210 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_13 (s : ℝ) (hx : ((3800 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3831 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3800 3831 4096 100000000 (fun r => if r = 2 then 191229188 else if r = 9 then 780738560 else if r = 17 then 1415279582 else if r = 33 then 2631905189 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 688379017 else if r = 9 then 767862710 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_14 (s : ℝ) (hx : ((3831 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3862 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3831 3862 4096 100000000 (fun r => if r = 2 then 192235010 else if r = 9 then 793830314 else if r = 17 then 1445954812 else if r = 33 then 2702482558 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 699298398 else if r = 9 then 780738557 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_15 (s : ℝ) (hx : ((3862 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3877 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3862 3877 4096 100000000 (fun r => if r = 2 then 192723596 else if r = 9 then 800243619 else if r = 17 then 1461035469 else if r = 33 then 2737309242 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 710390987 else if r = 9 then 793830311 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_16 (s : ℝ) (hx : ((3877 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3893 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3877 3893 4096 100000000 (fun r => if r = 2 then 193246122 else if r = 9 then 807141597 else if r = 17 then 1477294906 else if r = 33 then 2774952534 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 715821366 else if r = 9 then 800243616 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_17 (s : ℝ) (hx : ((3893 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3908 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3893 3908 4096 100000000 (fun r => if r = 2 then 193737278 else if r = 9 then 813662443 else if r = 17 then 1492702427 else if r = 33 then 2810713133 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 721659532 else if r = 9 then 807141594 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_18 (s : ℝ) (hx : ((3908 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3924 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3908 3924 4096 100000000 (fun r => if r = 2 then 194262553 else if r = 9 then 820676089 else if r = 17 then 1509314276 else if r = 33 then 2849365870 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 727176050 else if r = 9 then 813662440 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_19 (s : ℝ) (hx : ((3924 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3931 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3924 3931 4096 100000000 (fun r => if r = 2 then 194492808 else if r = 9 then 823763539 else if r = 17 then 1516639972 else if r = 33 then 2866443162 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 733106824 else if r = 9 then 820676086 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_20 (s : ℝ) (hx : ((3931 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3939 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3931 3939 4096 100000000 (fun r => if r = 2 then 194756291 else if r = 9 then 827306279 else if r = 17 then 1525055745 else if r = 33 then 2886085429 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 735716725 else if r = 9 then 823763536 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_21 (s : ℝ) (hx : ((3939 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3943 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3939 3943 4096 100000000 (fun r => if r = 2 then 194888167 else if r = 9 then 829083358 else if r = 17 then 1529281127 else if r = 33 then 2895956979 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 738710847 else if r = 9 then 827306276 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_22 (s : ℝ) (hx : ((3943 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3947 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3943 3947 4096 100000000 (fun r => if r = 2 then 195020132 else if r = 9 then 830864255 else if r = 17 then 1533518216 else if r = 33 then 2905862294 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 740212475 else if r = 9 then 829083355 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_23 (s : ℝ) (hx : ((3947 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3949 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3947 3949 4096 100000000 (fun r => if r = 2 then 195086147 else if r = 9 then 831756137 else if r = 17 then 1535641161 else if r = 33 then 2910827650 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 741717155 else if r = 9 then 830864252 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_24 (s : ℝ) (hx : ((3949 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3951 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3949 3951 4096 100000000 (fun r => if r = 2 then 195152186 else if r = 9 then 832648977 else if r = 17 then 1537767044 else if r = 33 then 2915801489 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 742470642 else if r = 9 then 831756134 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_25 (s : ℝ) (hx : ((3951 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3953 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3951 3953 4096 100000000 (fun r => if r = 2 then 195218246 else if r = 9 then 833542775 else if r = 17 then 1539895871 else if r = 33 then 2920783828 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 743224894 else if r = 9 then 832648974 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_26 (s : ℝ) (hx : ((3953 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3954 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3953 3954 4096 100000000 (fun r => if r = 2 then 195251285 else if r = 9 then 833990034 else if r = 17 then 1540961389 else if r = 33 then 2923278189 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 743979912 else if r = 9 then 833542772 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell22_27 (s : ℝ) (hx : ((3954 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3955 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I22 < 0 := + cell_neg I22 3954 3955 4096 100000000 (fun r => if r = 2 then 195284329 else if r = 9 then 834437532 else if r = 17 then 1542027645 else if r = 33 then 2925774680 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 744357709 else if r = 9 then 833990031 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem I22_neg (s : ℝ) (h0 : 0 ≤ s) (h1 : s ≤ ((3955 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : Finv s I22 < 0 := by + rcases le_total s (((988 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h2 | h2 + · exact cell22_0 s (by rw [Nat.cast_zero, zero_div]; exact h0) h2 + · rcases le_total s (((1977 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h3 | h3 + · exact cell22_1 s h2 h3 + · rcases le_total s (((2471 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h4 | h4 + · exact cell22_2 s h3 h4 + · rcases le_total s (((2718 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h5 | h5 + · exact cell22_3 s h4 h5 + · rcases le_total s (((2966 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h6 | h6 + · exact cell22_4 s h5 h6 + · rcases le_total s (((3213 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h7 | h7 + · exact cell22_5 s h6 h7 + · rcases le_total s (((3336 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h8 | h8 + · exact cell22_6 s h7 h8 + · rcases le_total s (((3460 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h9 | h9 + · exact cell22_7 s h8 h9 + · rcases le_total s (((3583 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h10 | h10 + · exact cell22_8 s h9 h10 + · rcases le_total s (((3645 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h11 | h11 + · exact cell22_9 s h10 h11 + · rcases le_total s (((3707 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h12 | h12 + · exact cell22_10 s h11 h12 + · rcases le_total s (((3769 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h13 | h13 + · exact cell22_11 s h12 h13 + · rcases le_total s (((3800 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h14 | h14 + · exact cell22_12 s h13 h14 + · rcases le_total s (((3831 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h15 | h15 + · exact cell22_13 s h14 h15 + · rcases le_total s (((3862 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h16 | h16 + · exact cell22_14 s h15 h16 + · rcases le_total s (((3877 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h17 | h17 + · exact cell22_15 s h16 h17 + · rcases le_total s (((3893 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h18 | h18 + · exact cell22_16 s h17 h18 + · rcases le_total s (((3908 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h19 | h19 + · exact cell22_17 s h18 h19 + · rcases le_total s (((3924 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h20 | h20 + · exact cell22_18 s h19 h20 + · rcases le_total s (((3931 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h21 | h21 + · exact cell22_19 s h20 h21 + · rcases le_total s (((3939 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h22 | h22 + · exact cell22_20 s h21 h22 + · rcases le_total s (((3943 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h23 | h23 + · exact cell22_21 s h22 h23 + · rcases le_total s (((3947 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h24 | h24 + · exact cell22_22 s h23 h24 + · rcases le_total s (((3949 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h25 | h25 + · exact cell22_23 s h24 h25 + · rcases le_total s (((3951 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h26 | h26 + · exact cell22_24 s h25 h26 + · rcases le_total s (((3953 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h27 | h27 + · exact cell22_25 s h26 h27 + · rcases le_total s (((3954 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h28 | h28 + · exact cell22_26 s h27 h28 + · exact cell22_27 s h28 h1 + +/-- t >= 141/4096 (s <= 3955/4096): the invoice F of EVERY native at the floor with the argmax caller 2|2 is negative -/ +theorem split22_ceiling (t : ℝ) (ht : (141 : ℝ) / 4096 ≤ t) (ht1 : t ≤ 1) : Finv (1 - t) I22 < 0 := by + apply I22_neg (1 - t) (by linarith) + have : ((3955 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) = 1 - 141 / 4096 := by norm_num + rw [this]; linarith + +/-! ### 7. the control C(8|9) (= #7113 caller, CallerCost.reproduction) at the native floor, k = 17: the root of F(t) lies in (.0204, .0205) + (R3 control .0204110964; exact root needs rpow to 1e-10, not done in kernel) -/ +def I89 : Inv := invoice (caller 6 7) natFloor 17 +theorem I89_F (s : ℝ) : Finv s I89 = FB 8 9 4 s - ((8 + 9 : ℕ) : ℝ) * Nfl s := by + have h := invoice_F s (caller 6 7) natFloor 17 + rw [natFloor_F, FB_eq] at h + show Finv s (invoice (caller 6 7) natFloor 17) = _ + rw [h]; push_cast; ring +/-- F(t = .0204) > 0 (s = 2449/2500) -/ +theorem control_pos : 0 < Finv (((2449 : ℕ) : ℝ) / ((2500 : ℕ) : ℝ)) I89 := + pt_pos I89 2449 2500 100000000 (fun r => if r = 1 then 100000001 else if r = 8 then 766773248 else if r = 9 then 860549711 else if r = 16 then 1512014428 else if r = 24 then 2249339100 else if r = 32 then 2981569375 else if r = 40 then 3710034667 else if r = 48 then 4435513611 else if r = 56 then 5158518488 else if r = 64 then 5879412111 else 0) (fun r => if r = 2 then 197191859 else if r = 9 then 860549708 else if r = 17 then 1604529710 else if r = 25 then 2341111144 else if r = 33 then 3072813876 else if r = 41 then 3800870438 else if r = 49 then 4526015947 else if r = 57 then 5248739375 else if r = 65 then 5969389592 else if r = 73 then 6688228062 else if r = 137 then 12391716458 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) +/-- F(t = .0205) < 0 (s = 1959/2000) -/ +theorem control_neg : Finv (((1959 : ℕ) : ℝ) / ((2000 : ℕ) : ℝ)) I89 < 0 := + cell_neg I89 1959 1959 2000 100000000 (fun r => if r = 2 then 197178194 else if r = 9 then 860360650 else if r = 17 then 1604075180 else if r = 25 then 2340357693 else if r = 33 then 3071739655 else if r = 41 then 3799459223 else if r = 49 then 4524254849 else if r = 57 then 5246617715 else if r = 65 then 5966898261 else if r = 73 then 6685359123 else if r = 137 then 12385621260 else 0) (fun r => if r = 1 then 99999999 else if r = 8 then 766613815 else if r = 9 then 860360647 else if r = 16 then 1511595264 else if r = 24 then 2248624359 else if r = 32 then 2980536218 else if r = 40 then 3708666329 else if r = 48 then 4433796864 else if r = 56 then 5156442418 else if r = 64 then 5876967437 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) _ le_rfl le_rfl +/-- the control brackets the R3 value .0204110964: F(.0204) > 0 > F(.0205) for the exact #7113 caller invoice at the floor native -/ +theorem control_bracket : + 0 < Finv (1 - (204 : ℝ) / 10000) I89 ∧ Finv (1 - (205 : ℝ) / 10000) I89 < 0 := by + constructor + · have h := control_pos + have e : ((2449 : ℕ) : ℝ) / ((2500 : ℕ) : ℝ) = 1 - 204 / 10000 := by norm_num + rwa [e] at h + · have h := control_neg + have e : ((1959 : ℕ) : ℝ) / ((2000 : ℕ) : ℝ) = 1 - 205 / 10000 := by norm_num + rwa [e] at h + + +/-! ### 8. the CORRECTED argmax split 1|1 (k = 2, thin 4, arms of 1 priced by the ledger): F < 0 for t >= 176/4096 = 0.042969 (root .0419448764), 36 rational cells. + (internal notes; the exact root needs rpow to 1e-10, held in NumCert) -/ +def I11 : Inv := invoice (callerG 1 1 4) natFloor 2 +theorem I11_F (s : ℝ) : Finv s I11 = FBc 1 1 4 s - ((1 + 1 : ℕ) : ℝ) * Nfl s := by + have h := invoice_F s (callerG 1 1 4) natFloor 2 + rw [natFloor_F, callerG_F 1 1 4 le_rfl le_rfl] at h + show Finv s (invoice (callerG 1 1 4) natFloor 2) = _ + rw [h]; push_cast; ring +theorem cell11_0 (s : ℝ) (hx : ((0 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((980 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 0 980 4096 100000000000 (fun r => if r = 2 then 118038526172 else if r = 9 then 169164790567 else if r = 17 then 196967474893 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 99999999999 else if r = 9 then 99999999999 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_1 (s : ℝ) (hx : ((980 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((1470 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 980 1470 4096 100000000000 (fun r => if r = 2 then 128243590121 else if r = 9 then 220021419926 else if r = 17 then 276434202378 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 164464184067 else if r = 9 then 169164790564 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_2 (s : ℝ) (hx : ((1470 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((1960 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 1470 1960 4096 100000000000 (fun r => if r = 2 then 139330936607 else if r = 9 then 286167263672 else if r = 17 then 387961861652 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 210914774109 else if r = 9 then 220021419923 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_3 (s : ℝ) (hx : ((1960 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((2450 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 1960 2450 4096 100000000000 (fun r => if r = 2 then 151376843687 else if r = 9 then 372198774216 else if r = 17 then 544485468158 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 270484678412 else if r = 9 then 286167263669 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_4 (s : ℝ) (hx : ((2450 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((2695 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 2450 2695 4096 100000000000 (fun r => if r = 2 then 157784882305 else if r = 9 then 424475308227 else if r = 17 then 645037439188 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 346879262320 else if r = 9 then 372198774213 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_5 (s : ℝ) (hx : ((2695 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((2940 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 2695 2940 4096 100000000000 (fun r => if r = 2 then 164464184070 else if r = 9 then 484094252257 else if r = 17 then 764158682436 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 392822333018 else if r = 9 then 424475308224 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_6 (s : ℝ) (hx : ((2940 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3185 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 2940 3185 4096 100000000000 (fun r => if r = 2 then 171426232010 else if r = 9 then 552086871782 else if r = 17 then 905278448145 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 444850419381 else if r = 9 then 484094252254 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_7 (s : ℝ) (hx : ((3185 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3307 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3185 3307 4096 100000000000 (fun r => if r = 2 then 175002198569 else if r = 9 then 589426533829 else if r = 17 then 984988805396 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 503769462655 else if r = 9 then 552086871779 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_8 (s : ℝ) (hx : ((3307 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3430 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3307 3430 4096 100000000000 (fun r => if r = 2 then 178682995252 else if r = 9 then 629629276888 else if r = 17 then 1072459277781 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 535957699595 else if r = 9 then 589426533826 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_9 (s : ℝ) (hx : ((3430 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3491 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3430 3491 4096 100000000000 (fun r => if r = 2 then 180537047876 else if r = 9 then 650573014604 else if r = 17 then 1118678695528 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 570492148478 else if r = 9 then 629629276885 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_10 (s : ℝ) (hx : ((3491 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3552 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3491 3552 4096 100000000000 (fun r => if r = 2 then 182410338542 else if r = 9 then 672213416478 else if r = 17 then 1166890016018 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 588435695526 else if r = 9 then 650573014601 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_11 (s : ℝ) (hx : ((3552 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3613 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3552 3613 4096 100000000000 (fun r => if r = 2 then 184303066870 else if r = 9 then 694573656069 else if r = 17 then 1217179083616 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 606943616478 else if r = 9 then 672213416475 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_12 (s : ℝ) (hx : ((3613 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3675 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3613 3675 4096 100000000000 (fun r => if r = 2 then 186246949593 else if r = 9 then 718062766164 else if r = 17 then 1270513956070 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 626033662444 else if r = 9 then 694573656066 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_13 (s : ℝ) (hx : ((3675 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3705 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3675 3705 4096 100000000000 (fun r => if r = 2 then 187194885136 else if r = 9 then 729712000715 else if r = 17 then 1297153933706 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 646052044837 else if r = 9 then 718062766161 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_14 (s : ℝ) (hx : ((3705 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3736 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3705 3736 4096 100000000000 (fun r => if r = 2 then 188179487410 else if r = 9 then 741948120277 else if r = 17 then 1325268869852 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 655966912907 else if r = 9 then 729712000712 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_15 (s : ℝ) (hx : ((3736 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3766 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3736 3766 4096 100000000000 (fun r => if r = 2 then 189137258933 else if r = 9 then 753984850330 else if r = 17 then 1353056941668 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 666372158432 else if r = 9 then 741948120274 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_16 (s : ℝ) (hx : ((3766 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3797 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3766 3797 4096 100000000000 (fun r => if r = 2 then 190132077649 else if r = 9 then 766627987305 else if r = 17 then 1382383537787 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 676598876371 else if r = 9 then 753984850327 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_17 (s : ℝ) (hx : ((3797 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3812 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3797 3812 4096 100000000000 (fun r => if r = 2 then 190615318327 else if r = 9 then 772821526227 else if r = 17 then 1396801175565 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 687331395485 else if r = 9 then 766627987302 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_18 (s : ℝ) (hx : ((3812 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3827 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3812 3827 4096 100000000000 (fun r => if r = 2 then 191099787212 else if r = 9 then 779065102357 else if r = 17 then 1411369182812 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 692585501907 else if r = 9 then 772821526224 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_19 (s : ℝ) (hx : ((3827 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3842 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3827 3842 4096 100000000000 (fun r => if r = 2 then 191585487426 else if r = 9 then 785359119943 else if r = 17 then 1426089127815 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 697879771828 else if r = 9 then 779065102354 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_20 (s : ℝ) (hx : ((3842 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3858 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3842 3858 4096 100000000000 (fun r => if r = 2 then 192104928378 else if r = 9 then 792128795609 else if r = 17 then 1441959657406 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 703214512268 else if r = 9 then 785359119940 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_21 (s : ℝ) (hx : ((3858 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3873 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3858 3873 4096 100000000000 (fun r => if r = 2 then 192593183263 else if r = 9 then 798528353945 else if r = 17 then 1456998647283 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 708949858185 else if r = 9 then 792128795606 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_22 (s : ℝ) (hx : ((3873 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3881 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3873 3881 4096 100000000000 (fun r => if r = 2 then 192854093080 else if r = 9 then 801962565455 else if r = 17 then 1465083472409 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 714369220704 else if r = 9 then 798528353942 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_23 (s : ℝ) (hx : ((3881 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3889 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3881 3889 4096 100000000000 (fun r => if r = 2 then 193115356356 else if r = 9 then 805411546396 else if r = 17 then 1473213159894 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 717276466233 else if r = 9 then 801962565452 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_24 (s : ℝ) (hx : ((3889 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3896 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3889 3896 4096 100000000000 (fun r => if r = 2 then 193344252046 else if r = 9 then 808441570194 else if r = 17 then 1480363633263 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 720195543287 else if r = 9 then 805411546393 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_25 (s : ℝ) (hx : ((3896 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3900 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3896 3900 4096 100000000000 (fun r => if r = 2 then 193475171374 else if r = 9 then 810178127625 else if r = 17 then 1484465189525 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 722759479103 else if r = 9 then 808441570191 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_26 (s : ℝ) (hx : ((3900 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3904 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3900 3904 4096 100000000000 (fun r => if r = 2 then 193606179351 else if r = 9 then 811918415234 else if r = 17 then 1488578109728 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 724228681377 else if r = 9 then 810178127622 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_27 (s : ℝ) (hx : ((3904 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3908 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3904 3908 4096 100000000000 (fun r => if r = 2 then 193737276037 else if r = 9 then 813662441034 else if r = 17 then 1492702425356 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 725700870199 else if r = 9 then 811918415231 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_28 (s : ℝ) (hx : ((3908 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3910 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3908 3910 4096 100000000000 (fun r => if r = 2 then 193802857665 else if r = 9 then 814535858265 else if r = 17 then 1494768866317 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 727176051638 else if r = 9 then 813662441031 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_29 (s : ℝ) (hx : ((3910 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3912 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3910 3912 4096 100000000000 (fun r => if r = 2 then 193868461493 else if r = 9 then 815410213056 else if r = 17 then 1496838167982 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 727914766490 else if r = 9 then 814535858262 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_30 (s : ℝ) (hx : ((3912 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3914 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3912 3914 4096 100000000000 (fun r => if r = 2 then 193934087529 else if r = 9 then 816285506414 else if r = 17 then 1498910334309 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 728654231779 else if r = 9 then 815410213053 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_31 (s : ℝ) (hx : ((3914 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3916 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3914 3916 4096 100000000000 (fun r => if r = 2 then 193999735779 else if r = 9 then 817161739346 else if r = 17 then 1500985369266 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 729394448267 else if r = 9 then 816285506411 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_32 (s : ℝ) (hx : ((3916 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3917 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3916 3917 4096 100000000000 (fun r => if r = 2 then 194032568237 else if r = 9 then 817600208467 else if r = 17 then 1502023963721 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 730135416717 else if r = 9 then 817161739343 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_33 (s : ℝ) (hx : ((3917 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3918 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3917 3918 4096 100000000000 (fun r => if r = 2 then 194065406252 else if r = 9 then 818038912861 else if r = 17 then 1503063276823 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 730506183167 else if r = 9 then 817600208464 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_34 (s : ℝ) (hx : ((3918 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3919 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3918 3919 4096 100000000000 (fun r => if r = 2 then 194098249824 else if r = 9 then 818477852652 else if r = 17 then 1504103309069 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 730877137893 else if r = 9 then 818038912858 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem cell11_35 (s : ℝ) (hx : ((3919 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) ≤ s) (hy : s ≤ ((3920 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : + Finv s I11 < 0 := + cell_neg I11 3919 3920 4096 100000000000 (fun r => if r = 2 then 194131098954 else if r = 9 then 818917027968 else if r = 17 then 1505144060957 else 0) (fun r => if r = 1 then 99999999999 else if r = 8 then 731248280993 else if r = 9 then 818477852649 else 0) (by norm_num) (by norm_num) + (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel) s hx hy +theorem I11_neg (s : ℝ) (h0 : 0 ≤ s) (h1 : s ≤ ((3920 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) : Finv s I11 < 0 := by + rcases le_total s (((980 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h2 | h2 + · exact cell11_0 s (by rw [Nat.cast_zero, zero_div]; exact h0) h2 + · rcases le_total s (((1470 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h3 | h3 + · exact cell11_1 s h2 h3 + · rcases le_total s (((1960 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h4 | h4 + · exact cell11_2 s h3 h4 + · rcases le_total s (((2450 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h5 | h5 + · exact cell11_3 s h4 h5 + · rcases le_total s (((2695 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h6 | h6 + · exact cell11_4 s h5 h6 + · rcases le_total s (((2940 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h7 | h7 + · exact cell11_5 s h6 h7 + · rcases le_total s (((3185 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h8 | h8 + · exact cell11_6 s h7 h8 + · rcases le_total s (((3307 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h9 | h9 + · exact cell11_7 s h8 h9 + · rcases le_total s (((3430 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h10 | h10 + · exact cell11_8 s h9 h10 + · rcases le_total s (((3491 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h11 | h11 + · exact cell11_9 s h10 h11 + · rcases le_total s (((3552 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h12 | h12 + · exact cell11_10 s h11 h12 + · rcases le_total s (((3613 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h13 | h13 + · exact cell11_11 s h12 h13 + · rcases le_total s (((3675 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h14 | h14 + · exact cell11_12 s h13 h14 + · rcases le_total s (((3705 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h15 | h15 + · exact cell11_13 s h14 h15 + · rcases le_total s (((3736 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h16 | h16 + · exact cell11_14 s h15 h16 + · rcases le_total s (((3766 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h17 | h17 + · exact cell11_15 s h16 h17 + · rcases le_total s (((3797 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h18 | h18 + · exact cell11_16 s h17 h18 + · rcases le_total s (((3812 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h19 | h19 + · exact cell11_17 s h18 h19 + · rcases le_total s (((3827 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h20 | h20 + · exact cell11_18 s h19 h20 + · rcases le_total s (((3842 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h21 | h21 + · exact cell11_19 s h20 h21 + · rcases le_total s (((3858 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h22 | h22 + · exact cell11_20 s h21 h22 + · rcases le_total s (((3873 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h23 | h23 + · exact cell11_21 s h22 h23 + · rcases le_total s (((3881 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h24 | h24 + · exact cell11_22 s h23 h24 + · rcases le_total s (((3889 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h25 | h25 + · exact cell11_23 s h24 h25 + · rcases le_total s (((3896 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h26 | h26 + · exact cell11_24 s h25 h26 + · rcases le_total s (((3900 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h27 | h27 + · exact cell11_25 s h26 h27 + · rcases le_total s (((3904 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h28 | h28 + · exact cell11_26 s h27 h28 + · rcases le_total s (((3908 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h29 | h29 + · exact cell11_27 s h28 h29 + · rcases le_total s (((3910 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h30 | h30 + · exact cell11_28 s h29 h30 + · rcases le_total s (((3912 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h31 | h31 + · exact cell11_29 s h30 h31 + · rcases le_total s (((3914 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h32 | h32 + · exact cell11_30 s h31 h32 + · rcases le_total s (((3916 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h33 | h33 + · exact cell11_31 s h32 h33 + · rcases le_total s (((3917 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h34 | h34 + · exact cell11_32 s h33 h34 + · rcases le_total s (((3918 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h35 | h35 + · exact cell11_33 s h34 h35 + · rcases le_total s (((3919 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ)) with h36 | h36 + · exact cell11_34 s h35 h36 + · exact cell11_35 s h36 h1 + +/-- t >= 176/4096: the invoice F of EVERY native at the floor with the 1|1 caller (thin 4) is negative -/ +theorem split11_ceiling (t : ℝ) (ht : (176 : ℝ) / 4096 ≤ t) (ht1 : t ≤ 1) : Finv (1 - t) I11 < 0 := by + apply I11_neg (1 - t) (by linarith) + have : ((3920 : ℕ) : ℝ) / ((4096 : ℕ) : ℝ) = 1 - 176 / 4096 := by norm_num + rw [this]; linarith + +/-- UNCONDITIONAL-NUMERICS instance of the ceiling theorem: argmax split 2|2, thin >= 4, any native meeting the floor: + F(t) < 0 for t >= 141/4096 (class lemmas hB/hth and the native floor hN stay hypotheses; no NumCert needed). -/ +theorem ceiling_split22 (c : InClass 4) (ha : c.a = 2) (hb : c.b = 2) (n : Inv) + (hN : ∀ s : ℝ, 0 ≤ s → s ≤ 1 → Finv s n ≤ -Nfl s) (t : ℝ) (ht : (141 : ℝ) / 4096 ≤ t) (ht1 : t ≤ 1) : + Finv (1 - t) (invoice c.ci n (c.a + c.b)) < 0 := by + have hs0 : (0 : ℝ) ≤ 1 - t := by linarith + have hs1 : 1 - t ≤ 1 := by linarith + rw [invoice_F] + have h1 := c.hB (1 - t) hs0 hs1 + have h2 := hN (1 - t) hs0 hs1 + have h3 : ((c.a + c.b : ℕ) : ℝ) * Finv (1 - t) n ≤ ((c.a + c.b : ℕ) : ℝ) * (-Nfl (1 - t)) := + mul_le_mul_of_nonneg_left h2 (Nat.cast_nonneg _) + have h4 := FBc_th_mono c.a c.b c.hth (1 - t) + have h5 := split22_ceiling t ht ht1 + rw [I22_F] at h5 + rw [ha, hb] at h1 h3 h4 ⊢ + push_cast at h3 ⊢ + norm_num at h3 h5 ⊢ + linarith + +/-- CORRECTED argmax split 1|1 (k = 2, thin >= 4, any native meeting the floor): F(t) < 0 for t >= 176/4096 = .04297 (kernel-checked, 36 cells; + the sharp value .0419448764 is the certified root, NumCert). Class lemmas hB/hth and the native floor hN stay hypotheses. -/ +theorem ceiling_split11 (c : InClass 4) (ha : c.a = 1) (hb : c.b = 1) (n : Inv) + (hN : ∀ s : ℝ, 0 ≤ s → s ≤ 1 → Finv s n ≤ -Nfl s) (t : ℝ) (ht : (176 : ℝ) / 4096 ≤ t) (ht1 : t ≤ 1) : + Finv (1 - t) (invoice c.ci n (c.a + c.b)) < 0 := by + have hs0 : (0 : ℝ) ≤ 1 - t := by linarith + have hs1 : 1 - t ≤ 1 := by linarith + rw [invoice_F] + have h1 := c.hB (1 - t) hs0 hs1 + have h2 := hN (1 - t) hs0 hs1 + have h3 : ((c.a + c.b : ℕ) : ℝ) * Finv (1 - t) n ≤ ((c.a + c.b : ℕ) : ℝ) * (-Nfl (1 - t)) := + mul_le_mul_of_nonneg_left h2 (Nat.cast_nonneg _) + have h4 := FBc_th_mono c.a c.b c.hth (1 - t) + have h5 := split11_ceiling t ht ht1 + rw [I11_F] at h5 + rw [ha, hb] at h1 h3 h4 ⊢ + push_cast at h3 ⊢ + norm_num at h3 h5 ⊢ + linarith + +#print axioms invoice_F +#print axioms natFloor_F +#print axioms FB_eq +#print axioms ceiling +#print axioms ceiling4 +#print axioms ceiling3 +#print axioms rp_le_nat +#print axioms rp_ge_nat +#print axioms I22_F +#print axioms split22_ceiling +#print axioms ceiling_split22 +#print axioms callerG_F +#print axioms callerG_S +#print axioms callerG_eq_caller_F +#print axioms split11_ceiling +#print axioms ceiling_split11 +#print axioms I89_F +#print axioms control_bracket + +end JointCeiling diff --git a/research/p104-native-ceiling/lean/Nov15/JointCeiling.md b/research/p104-native-ceiling/lean/Nov15/JointCeiling.md new file mode 100644 index 0000000000..9672a4cb33 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/JointCeiling.md @@ -0,0 +1,21 @@ +# JointCeiling.lean: Joint (caller, native) ceiling, CORRECTED +Imports Nov15.CallerCost + Mathlib. About 12 s, 2.9 GB. 18 `#print axioms` all within [propext, Classical.choice, Quot.sound]; no sorry, no native_decide (`decide +kernel` = kernel evaluation only). The rational-cell data are produced by scripts that are not shipped; Lean re-checks every cell. +Convention: F(s) = sum (T-P) r^s, s = 1-t. + +## WITHDRAWN +- **The old statement "kappa <= .0336321541 (thin 4) / .0400007313 (thin 3), argmax 2|2" is WITHDRAWN.** Reason (internal audit): the generating script overcharged every arm of length 1 by 208 one-stage lines (P[8]) -- two lines per port, 104 ports x 2 -- breaking the ledger S = 3408(a+b) - 208. The argmax is 1|1 (k = 2), not 2|2, and the R1 NumCert list built from that script is invalid for arms of 1. +- tbar4 = .0336321541, tbar3 = .0400007313 are removed from the file. + +## Proved (kernel) +- `invoice_F`, `Fh_mono`, `natFloor`, `natFloor_F` (Nfl = 400*8^s + 16 + 88(2-2^s)): unchanged. +- **Correction (a).** `FBc a b th s = FB a b th s + 208*8^s*(#arms of 1)`; `callerG a b th` = ledger-correct caller histogram (a,b >= 1; P[8] = 384 + 16(a+b) - 208 #arms-of-1). `callerG_F`: F(callerG) = FBc for all a,b >= 1. `callerG_S`: **S(callerG a b 4) = 3408(a+b) - 208 for ALL a,b >= 1** (the ledger law; with the floor native S = -3216/call this is 192k - 208 = 176, 368, 560 at 1|1, 1|2, 2|2). `FBc_two`, `callerG_eq_caller_F`: for a,b >= 2 FBc = FB and callerG has the same F as CallerCost.caller (and FB_eq / reproduction of #7113 / S_caller are untouched), so the a,b >= 2 agreement stands. (`FB_eq`, `FB_th_mono` kept.) +- **Ceiling theorems** (`ceiling`, `ceiling4`, `ceiling3`) now run on FBc; tbar4 = .0419448764 (rounded up from the certified root .041944876391), tbar3 = .0681203280 (th3 B-form-A class only). +- **(c) Kernel-checked numerics:** `split22_ceiling` / `ceiling_split22` (2|2, t >= 141/4096, 28 cells; unaffected by the correction) and NEW `split11_ceiling` / `ceiling_split11`: the corrected argmax 1|1, thin >= 4, any floor native: F(t) < 0 for t >= 176/4096 = .04297 (36 rational cells, DEC = 1e11, q = 4096; the sharp root .0419448764 is not reachable by 4096-grid cells, it is in NumCert). `control_bracket` (C(8|9) = #7113 caller, F(.0204) > 0 > F(.0205)) unchanged. + +## Hypotheses (explicit, named) +1. `InClass.hB`: B-form per-split optimality pointwise in F on [0,1] (justified by a tail-swap/join majorization + Karamata argument, phi concave; finite checks 58,873 schedules and 360,844 B layouts; the audit found it sound for B ports). It holds on B ports. **It FAILS on A ports for the true sign-floor masks (centre-drop case, 6,009 / 5,879 failing layouts)**, which is why the ceiling is stated for the built-type class (A = 4 QUERY, B-form masks). `hth`: th >= th0 (4 = A ports use 4 QUERY sign units; 3 unbuilt). `hrho`: rho >= 2 (Theorem H, + t = -1 closure, #7606 findings bundle), recorded only. +2. `hN`: F_nat <= -Nfl on [0,1] (whole-floor note). Not re-proved. +3. `NumCert th0 tbar` (regenerated): for every split a|b (a,b >= 1), 0 <= s <= 1-tbar: FBc a b th0 s - (a+b) Nfl s < 0. Source: an external interval-arithmetic script (1|1 root, 1|b for b = 2..59 by interval cover, tail k >= 61 by U plus 208*8^s with U < 0 and U' < 0, a,b >= 2 splits unchanged since FBc = FB there). Its output: th4 1|1 kbar .041944876391 cert True, 1|b True, tail True; th3 .068120327915. Not in the kernel: ~1,800 pairs of 40-digit interval covers; the tail U >= F Jensen/MVT step (R1) is unaudited (audit conditions). + +## Theorem as restated (paper) +For every rho = 2 nested two-arm caller (arms a,b >= 1, meeting only in hubs, host calls t != -1) with A ports at 4 QUERY sign units and B-form masks, composed with any native at the whole-floor per-call floor: kappa <= .0419448764, peak at 1|1 (k = 2). Conditions: [H-centre] (no line crosses the centre at h <= 4), [H-odd] (a B sign unit costs >= psi(1)), Theorem H + t = -1 closure (quoted), the R1 tail step (hypothesis, in NumCert), hN, and realisability of arms of 1 / k = 2 (no root built; Floor Lemma does not cover an innermost-only arm). Outside the class: trees, multi-centre, shared own roles. The .0681203279 figure (thin-3 masks) is only "scanned, conditional" for the true sign-floor class (audit); the Lean `ceiling3` certifies only the th3 B-form-A class under hB. diff --git a/research/p104-native-ceiling/lean/Nov15/JunkLB2.lean b/research/p104-native-ceiling/lean/Nov15/JunkLB2.lean new file mode 100644 index 0000000000..d9d034ea16 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/JunkLB2.lean @@ -0,0 +1,1188 @@ +/- +BIG-JUNKLB2 (internal notes), T1 g9 pricing (class M): charging every move at g9 = h_9, except a Y main's first move + (out of chart 0, never on a pair chain), never exceeds the real I1 cost; the gap for Y_p is + l(d_1) = f(8) - f(d_1) - f(9-d_1) ≥ 0. Hence Σ_{junk pairs} dist_{g9}(A_q → G_p) ≤ public cost. +T3 slot lemma (level 7): |D| ≤ rank{x_p : p ∈ D} + |Z|, with the T2 facts as explicit hypotheses. +T4 departer law, CORRECTED SCOPE (GAPMAP): arrivals = ALL arrivals at c, owned included; + dim π(Arr_c) ≤ #public departers + #owned arrivals + #Y enders. Each departer stop costs ≥ f(2). + The public-only version is false in the same model (`T4_public_only_false`). +(Nov 16): T1 linked to registers (`Net.T1_cost`, `Net.T1_full`: Σ move charges ≤ public +cost under JunkM op semantics); T2 proved from level-k op semantics (`T2_run`: complementarity, +independence, expansion existence) and discharged in T3 (`slot_lemma_T2`, `slot_lemma_run`). +Self-contained: h / gaps / hsum / two_point / Net are copied from Nov15/JunkM.lean. +-/ +import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog +import Mathlib.Analysis.Convex.Slope +import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas +import Mathlib.LinearAlgebra.StdBasis +import Mathlib.LinearAlgebra.Dimension.OrzechProperty + +open Finset + +set_option linter.unusedSectionVars false +set_option linter.unusedSimpArgs false + +namespace JunkLB2 + +/-! ## Costs (copied from JunkM, I1) -/ + +section Cost + +variable (f : ℝ → ℝ) + +/-- `h_e(a,b) = f(e-a) - f(b-a) - f(e-b)`. -/ +def h (e a b : ℝ) : ℝ := f (e - a) - f (b - a) - f (e - b) + +def gaps : List ℝ → ℝ + | a :: b :: t => f (b - a) + gaps (b :: t) + | _ => 0 + +/-- `Σ h_e(d_i, d_{i+1})` along a dim chain. -/ +def hsum (e : ℝ) : List ℝ → ℝ + | a :: b :: t => h f e a b + hsum e (b :: t) + | _ => 0 + +/-- telescoping with an arbitrary pricing level `e` (the chain need not end at `e`): +`Σ h_e(d_i,d_{i+1}) = f(e - d_0) - f(e - last) - Σ f(gaps)`. -/ +theorem hsum_tele (e : ℝ) : ∀ (d0 : ℝ) (ds : List ℝ), + hsum f e (d0 :: ds) = + f (e - d0) - f (e - (d0 :: ds).getLast (List.cons_ne_nil _ _)) - gaps f (d0 :: ds) + | d0, [] => by simp [hsum, gaps] + | d0, b :: t => by + have ih := hsum_tele e b t + rw [List.getLast_cons (List.cons_ne_nil _ _)] + simp only [hsum, gaps, h] at ih ⊢ + rw [ih]; ring + +end Cost + +/-- `f(r) = r log r`. -/ +noncomputable def fL (r : ℝ) : ℝ := r * Real.log r + +lemma fL_convex : ConvexOn ℝ (Set.Ici (0 : ℝ)) fL := Real.convexOn_mul_log + +/-- two-point majorisation for a convex function on `[0,∞)` (copied from JunkM). -/ +lemma two_point {f : ℝ → ℝ} (cvx : ConvexOn ℝ (Set.Ici (0 : ℝ)) f) {lo hi y z : ℝ} (h0 : 0 ≤ lo) + (hlt : lo < hi) (hy1 : lo ≤ y) (hy2 : y ≤ hi) (hz1 : lo ≤ z) (hz2 : z ≤ hi) + (hs : y + z = lo + hi) : f y + f z ≤ f lo + f hi := by + have hD : 0 < hi - lo := by linarith + have hlo : lo ∈ Set.Ici (0:ℝ) := h0 + have hhi : hi ∈ Set.Ici (0:ℝ) := by simp; linarith + have hy := cvx.2 hlo hhi + (div_nonneg (by linarith) hD.le : (0:ℝ) ≤ (hi - y) / (hi - lo)) + (div_nonneg (by linarith) hD.le : (0:ℝ) ≤ (y - lo) / (hi - lo)) (by field_simp; ring) + have hz := cvx.2 hlo hhi + (div_nonneg (by linarith) hD.le : (0:ℝ) ≤ (hi - z) / (hi - lo)) + (div_nonneg (by linarith) hD.le : (0:ℝ) ≤ (z - lo) / (hi - lo)) (by field_simp; ring) + simp only [smul_eq_mul] at hy hz + have ey : (hi - y) / (hi - lo) * lo + (y - lo) / (hi - lo) * hi = y := by field_simp; ring + have ez : (hi - z) / (hi - lo) * lo + (z - lo) / (hi - lo) * hi = z := by field_simp; ring + rw [ey] at hy; rw [ez] at hz + have e1 : (hi - y) / (hi - lo) + (hi - z) / (hi - lo) = 1 := by field_simp; linarith + have e2 : (y - lo) / (hi - lo) + (z - lo) / (hi - lo) = 1 := by field_simp; linarith + have : f y + f z ≤ ((hi - y) / (hi - lo) + (hi - z) / (hi - lo)) * f lo + + ((y - lo) / (hi - lo) + (z - lo) / (hi - lo)) * f hi := by linarith + rw [e1, e2] at this; linarith + +lemma fL0 : fL 0 = 0 := by simp [fL] +lemma fL1 : fL 1 = 0 := by simp [fL] + +/-- every ascending move strictly below the final dim costs at least `κ = f(2) = 2 log 2`: +`h_e(a,b) ≥ f(2)` when `b - a ≥ 1` and `e - b ≥ 1` (T4's "each departer stop costs ≥ f(2)"). -/ +theorem kappa_le (e a b : ℝ) (hab : 1 ≤ b - a) (hbe : 1 ≤ e - b) : fL 2 ≤ h fL e a b := by + have cvx := fL_convex + set x := b - a; set y := e - b + have hxy : e - a = x + y := by simp only [x, y]; ring + -- f(x) + f(1+y) ≤ f(1) + f(x+y) + have s1 := two_point cvx (lo := 1) (hi := x + y) (y := x) (z := 1 + y) + (by norm_num) (by linarith) hab (by linarith) (by linarith) (by linarith) (by ring) + -- f(y) + f(2) ≤ f(1) + f(1+y) + have s2 := two_point cvx (lo := 1) (hi := 1 + y) (y := y) (z := 2) + (by norm_num) (by linarith) hbe (by linarith) (by norm_num) (by linarith) (by ring) + simp only [h, hxy]; rw [fL1] at s1 s2; linarith + +/-- `g9(a,b) ≥ 0` for `a ≤ b ≤ 9`. -/ +lemma g9_nonneg (a b : ℝ) (hab : a ≤ b) (hb : b ≤ 9) : 0 ≤ h fL 9 a b := by + have := two_point fL_convex (lo := 0) (hi := 9 - a) (y := b - a) (z := 9 - b) + rcases (show a = 9 ∨ a < 9 by + rcases lt_or_eq_of_le (hab.trans hb) with h' | h' <;> [exact Or.inr h'; exact Or.inl h']) with + rfl | ha + · have : b = 9 := le_antisymm hb hab + subst this; simp [h, fL0] + · have := this le_rfl (by linarith) (by linarith) (by linarith) (by linarith) (by linarith) + (by ring) + simp only [h]; rw [fL0] at this; linarith + +/-! ## T1. g9 pricing (class M) -/ + +section T1 + +/-- **T1, Y main.** For `Y_p` with dim chain `0 < d_1 < … < d_k = 8`, the real I1 cost +`Σ h_8` equals the g9 charge on every move but the first, plus `l(d_1) = f(8) - f(d_1) - f(9 - d_1)`. -/ +theorem T1_Y (f : ℝ → ℝ) (hf0 : f 0 = 0) (hf1 : f 1 = 0) (d1 : ℝ) (rest : List ℝ) + (hlast : (d1 :: rest).getLast (List.cons_ne_nil _ _) = 8) : + hsum f 8 (0 :: d1 :: rest) = hsum f 9 (d1 :: rest) + (f 8 - f d1 - f (9 - d1)) := by + have e1 : hsum f 8 (0 :: d1 :: rest) = h f 8 0 d1 + hsum f 8 (d1 :: rest) := rfl + rw [e1, hsum_tele f 8 d1 rest, hsum_tele f 9 d1 rest, hlast] + have a1 : (8:ℝ) - 8 = 0 := by norm_num + have a2 : (9:ℝ) - 8 = 1 := by norm_num + simp only [h, a1, a2, hf0, hf1, sub_zero]; ring + +/-- the T1 slack `l(d) = f(8) - f(d) - f(9-d) ≥ 0` for `1 ≤ d ≤ 8` (and `l(1) = l(8) = 0`). -/ +theorem l_nonneg (d : ℝ) (h1 : 1 ≤ d) (h8 : d ≤ 8) : 0 ≤ fL 8 - fL d - fL (9 - d) := by + have := two_point fL_convex (lo := 1) (hi := 8) (y := d) (z := 9 - d) + (by norm_num) (by norm_num) h1 h8 (by linarith) (by linarith) (by ring) + rw [fL1] at this; linarith + +lemma l_one : fL 8 - fL 1 - fL (9 - 1) = 0 := by norm_num [fL1] + +/-- **T1, per register.** Charged ≤ real for a Y main (`0 :: d_1 :: … :: 8`, first move uncharged); +for a register ending at V (dim 9) the charge is its real cost by definition (`hsum fL 9`). -/ +theorem T1_Y_le (d1 : ℝ) (rest : List ℝ) (h1 : 1 ≤ d1) (h8 : d1 ≤ 8) + (hlast : (d1 :: rest).getLast (List.cons_ne_nil _ _) = 8) : + hsum fL 9 (d1 :: rest) ≤ hsum fL 8 (0 :: d1 :: rest) := by + rw [T1_Y fL fL0 fL1 d1 rest hlast]; linarith [l_nonneg d1 h1 h8] + +/-! ### The path bound with g9 everywhere (copy of JunkM's `Net`, no free moves) -/ + +attribute [local instance] Classical.propDecidable + +variable {C XP YP Mv : Type*} [PartialOrder C] [Fintype XP] [Fintype YP] [Fintype Mv] + +structure Net (C XP YP Mv : Type*) [PartialOrder C] where + inS : XP → C → Prop + inP : YP → C → Prop + monoS : ∀ q s s', s ≤ s' → inS q s → inS q s' + antiP : ∀ p t t', t ≤ t' → inP p t' → inP p t + A : XP → C + G : YP → C + hA : ∀ q, inS q (A q) + hG : ∀ p, inP p (G p) + src : Mv → C + tgt : Mv → C + hlt : ∀ m, src m < tgt m + +namespace Net + +variable (N : Net C XP YP Mv) + +noncomputable def nS (s : C) : ℕ := (univ.filter fun q => N.inS q s).card +noncomputable def mP (t : C) : ℕ := (univ.filter fun p => N.inP p t).card + +def Chain : C → List Mv → C → Prop + | a, [], b => a = b + | a, m :: ms, b => N.src m = a ∧ Chain (N.tgt m) ms b + +lemma chain_bounds : ∀ (a : C) (ℓ : List Mv) (b : C), N.Chain a ℓ b → + ∀ m ∈ ℓ, a ≤ N.src m ∧ N.tgt m ≤ b + | a, [], b, _, m, hm => absurd hm (List.not_mem_nil) + | a, m' :: ms, b, ⟨hs, hc⟩, m, hm => by + have hab : ∀ x ∈ ms, N.tgt m' ≤ N.src x ∧ N.tgt x ≤ b := chain_bounds _ ms b hc + have hend : N.tgt m' ≤ b := by + cases ms with + | nil => exact le_of_eq hc + | cons x xs => exact (le_of_lt (N.hlt x)).trans' ((hab x (by simp)).1) |>.trans (hab x (by simp)).2 + rcases List.mem_cons.mp hm with rfl | hm + · exact ⟨le_of_eq hs.symm, hend⟩ + · have := hab m hm + exact ⟨(le_of_eq hs.symm).trans ((le_of_lt (N.hlt m')).trans this.1), this.2⟩ + +lemma chain_nodup : ∀ (a : C) (ℓ : List Mv) (b : C), N.Chain a ℓ b → ℓ.Nodup + | a, [], b, _ => List.nodup_nil + | a, m :: ms, b, ⟨_, hc⟩ => by + refine List.nodup_cons.mpr ⟨fun hm => ?_, chain_nodup _ ms b hc⟩ + have := (N.chain_bounds _ ms b hc m hm).1 + exact absurd (lt_of_lt_of_le (N.hlt m) this) (lt_irrefl _) + +noncomputable def wt (c : C → C → ℝ) (m : Mv) : ℝ := + c (N.src m) (N.tgt m) / ((N.nS (N.src m) : ℝ) * N.mP (N.tgt m)) + +lemma users_card (P : Finset (YP × XP)) (path : YP × XP → List Mv) + (hpath : ∀ π ∈ P, N.Chain (N.A π.2) (path π) (N.G π.1)) (m : Mv) : + (P.filter fun π => m ∈ path π).card ≤ N.mP (N.tgt m) * N.nS (N.src m) := by + rw [mP, nS, ← card_product] + apply card_le_card + intro π hπ + rw [mem_filter] at hπ + have hb := N.chain_bounds _ _ _ (hpath π hπ.1) m hπ.2 + simp only [mem_product, mem_filter, mem_univ, true_and] + exact ⟨N.antiP π.1 _ _ hb.2 (N.hG π.1), N.monoS π.2 _ _ hb.1 (N.hA π.2)⟩ + +def ChartChain : C → List C → C → Prop + | a, [], b => a = b + | a, t :: ts, b => a < t ∧ ChartChain t ts b + +noncomputable def cw (c : C → C → ℝ) : C → List C → ℝ + | _, [] => 0 + | a, t :: ts => c a t / ((N.nS a : ℝ) * N.mP t) + cw c t ts + +/-- the shortest-path value `dist(a → b)` in the chart graph. -/ +noncomputable def dist (c : C → C → ℝ) (a b : C) : ℝ := + sInf {x | ∃ l, ChartChain a l b ∧ N.cw c a l = x} + +lemma cw_nonneg (c : C → C → ℝ) (hc0 : ∀ s t, 0 ≤ c s t) : ∀ a l, 0 ≤ N.cw c a l + | _, [] => le_rfl + | a, t :: ts => add_nonneg (div_nonneg (hc0 _ _) (by positivity)) (cw_nonneg c hc0 t ts) + +lemma chain_to_chart (c : C → C → ℝ) : ∀ (a : C) (ℓ : List Mv) (b : C), N.Chain a ℓ b → + ChartChain a (ℓ.map N.tgt) b ∧ N.cw c a (ℓ.map N.tgt) = (ℓ.map (N.wt c)).sum + | a, [], b, h => ⟨h, rfl⟩ + | a, m :: ms, b, ⟨hs, hc⟩ => by + obtain ⟨h1, h2⟩ := chain_to_chart c _ ms b hc + refine ⟨⟨hs ▸ N.hlt m, h1⟩, ?_⟩ + simp only [List.map_cons, cw, List.sum_cons, h2, wt, hs] + +lemma dist_le (c : C → C → ℝ) (hc0 : ∀ s t, 0 ≤ c s t) {a b : C} {ℓ : List Mv} + (h : N.Chain a ℓ b) : N.dist c a b ≤ (ℓ.map (N.wt c)).sum := by + obtain ⟨h1, h2⟩ := N.chain_to_chart c a ℓ b h + exact csInf_le ⟨0, fun x ⟨l, _, hx⟩ => hx ▸ N.cw_nonneg c hc0 a l⟩ ⟨_, h1, h2⟩ + +/-- the path bound without free moves: if every USED move is charged `w m ≥ c(src,tgt)`, then +`Σ_pairs dist ≤ Σ_m w m`. -/ +theorem bound0 (c : C → C → ℝ) (w : Mv → ℝ) (P : Finset (YP × XP)) (path : YP × XP → List Mv) + (hpath : ∀ π ∈ P, N.Chain (N.A π.2) (path π) (N.G π.1)) + (hc0 : ∀ s t, 0 ≤ c s t) (hw0 : ∀ m, 0 ≤ w m) + (hpay : ∀ m, (∃ π ∈ P, m ∈ path π) → c (N.src m) (N.tgt m) ≤ w m) : + ∑ π ∈ P, N.dist c (N.A π.2) (N.G π.1) ≤ ∑ m, w m := by + have s1 : ∑ π ∈ P, N.dist c (N.A π.2) (N.G π.1) ≤ ∑ π ∈ P, ((path π).map (N.wt c)).sum := + sum_le_sum fun π hπ => N.dist_le c hc0 (hpath π hπ) + have s2 : ∑ π ∈ P, ((path π).map (N.wt c)).sum + = ∑ m, ((P.filter fun π => m ∈ path π).card : ℝ) * N.wt c m := by + have e1 : ∀ π ∈ P, ((path π).map (N.wt c)).sum + = ∑ m, if m ∈ path π then N.wt c m else 0 := by + intro π hπ + rw [← List.sum_toFinset _ (N.chain_nodup _ _ _ (hpath π hπ)), ← sum_filter] + congr 1; ext m; simp + rw [sum_congr rfl e1, sum_comm] + refine sum_congr rfl fun m _ => ?_ + rw [← sum_filter, sum_const, nsmul_eq_mul] + have s3 : ∀ m, ((P.filter fun π => m ∈ path π).card : ℝ) * N.wt c m ≤ w m := by + intro m + by_cases hu : ∃ π ∈ P, m ∈ path π + · have hcard := N.users_card P path hpath m + obtain ⟨π, hπ, hm⟩ := hu + have hpos : 0 < (P.filter fun π => m ∈ path π).card := + card_pos.mpr ⟨π, mem_filter.mpr ⟨hπ, hm⟩⟩ + have hD : (0 : ℝ) < (N.nS (N.src m) : ℝ) * N.mP (N.tgt m) := by + have : 0 < N.mP (N.tgt m) * N.nS (N.src m) := lt_of_lt_of_le hpos hcard + rw [mul_comm]; exact_mod_cast this + have hle : ((P.filter fun π => m ∈ path π).card : ℝ) ≤ (N.nS (N.src m) : ℝ) * N.mP (N.tgt m) := by + rw [mul_comm]; exact_mod_cast hcard + have : ((P.filter fun π => m ∈ path π).card : ℝ) * N.wt c m ≤ c (N.src m) (N.tgt m) := by + rw [wt, mul_div_assoc', div_le_iff₀ hD] + exact mul_le_mul_of_nonneg_left hle (hc0 _ _) |>.trans_eq' (by ring) + exact this.trans (hpay m ⟨π, hπ, hm⟩) + · have : (P.filter fun π => m ∈ path π) = ∅ := by + ext π; simp only [mem_filter, Finset.notMem_empty, iff_false, not_and] + exact fun hπ hm => hu ⟨π, hπ, hm⟩ + simp [this, hw0 m] + calc _ ≤ _ := s1 + _ = _ := s2 + _ ≤ _ := sum_le_sum fun m _ => s3 m + +/-- **T1 (class M), path form.** Chart `z` (= chart 0) holds no X port (`n(0) = 0`). Every move +not leaving `z` is charged at least `c` (with `c = g9` on dims: `g9_nonneg`, `T1_Y_le`); moves out of +`z` (Y mains' first moves, the uncharged ones) may be charged anything `≥ 0`. Then +`Σ_{junk pairs} dist_c(A_q → G_p) ≤ Σ_m w m`; combined with `Σ_m w m ≤ public cost` (per register: +`T1_Y_le` for Y mains, equality for registers ending at V) this is T1's bound. -/ +theorem T1_bound (c : C → C → ℝ) (w : Mv → ℝ) (P : Finset (YP × XP)) (path : YP × XP → List Mv) + (hpath : ∀ π ∈ P, N.Chain (N.A π.2) (path π) (N.G π.1)) + (hc0 : ∀ s t, 0 ≤ c s t) (hw0 : ∀ m, 0 ≤ w m) (z : C) (hz : ∀ q, ¬ N.inS q z) + (hcharge : ∀ m, N.src m ≠ z → c (N.src m) (N.tgt m) ≤ w m) + (cost : ℝ) (hcost : ∑ m, w m ≤ cost) : + ∑ π ∈ P, N.dist c (N.A π.2) (N.G π.1) ≤ cost := by + refine (N.bound0 c w P path hpath hc0 hw0 fun m ⟨π, hπ, hm⟩ => hcharge m ?_).trans hcost + intro hzm + have := (N.chain_bounds _ _ _ (hpath π hπ) m hm).1 + rw [hzm] at this + exact hz π.2 (N.monoS π.2 _ _ this (N.hA π.2)) + +end Net + +end T1 + +/-! ## T1, linked to registers: total move charges ≤ public cost (JunkM op semantics) -/ + +section T1link + +attribute [local instance] Classical.propDecidable + +variable {C XP YP Mv R : Type*} [PartialOrder C] [Fintype XP] [Fintype YP] [Fintype Mv] [Fintype R] + +namespace Net + +variable (N : Net C XP YP Mv) + +lemma chain_append : ∀ (a : C) (ℓ : List Mv) (b : C) (m : Mv), N.Chain a ℓ b → N.src m = b → + N.Chain a (ℓ ++ [m]) (N.tgt m) + | a, [], b, m, h, hm => by simp only [Chain] at h; subst h; exact ⟨hm, rfl⟩ + | a, m' :: ms, b, m, ⟨hs, hc⟩, hm => ⟨hs, chain_append _ ms b m hc hm⟩ + +/-- register `i`'s moves up to time `n`, in time order: `mv t i` at each `t < n` where its chart +rises (JunkM's `mv t i`). -/ +noncomputable def movesOf (chart : ℕ → R → C) (mv : ℕ → R → Mv) (i : R) (n : ℕ) : List Mv := + ((List.range n).filter (fun t => decide (chart t i < chart (t + 1) i))).map (fun t => mv t i) + +/-- JunkM op semantics (b) charts never decrease, (c) `mv t i` goes `chart t i → chart (t+1) i` when +`i`'s chart rises: then `i`'s moves form a chain from its birth chart to its chart at time `n`. -/ +lemma movesOf_chain (chart : ℕ → R → C) (mv : ℕ → R → Mv) + (hmv : ∀ t i, chart t i < chart (t + 1) i → + N.src (mv t i) = chart t i ∧ N.tgt (mv t i) = chart (t + 1) i) + (hmono : ∀ t i, chart t i ≤ chart (t + 1) i) (i : R) : + ∀ n, N.Chain (chart 0 i) (movesOf chart mv i n) (chart n i) := by + intro n + induction n with + | zero => simp [movesOf, Chain] + | succ n ih => + by_cases hlt : chart n i < chart (n + 1) i + · have e : movesOf chart mv i (n + 1) = movesOf chart mv i n ++ [mv n i] := by + simp [movesOf, List.range_succ, List.filter_append, hlt] + obtain ⟨hs, ht⟩ := hmv n i hlt + rw [e, ← ht]; exact N.chain_append _ _ _ _ ih hs + · have e : movesOf chart mv i (n + 1) = movesOf chart mv i n := by + simp [movesOf, List.range_succ, List.filter_append, hlt] + have heq : chart (n + 1) i = chart n i := + ((hmono n i).lt_or_eq.resolve_left hlt).symm + rw [e, heq]; exact ih + +/-- the move costs along a chain telescope into `hsum` over the chain's dims. -/ +lemma chain_hsum (f : ℝ → ℝ) (e : ℝ) (dim : C → ℝ) : ∀ (a : C) (ℓ : List Mv) (b : C), N.Chain a ℓ b → + (ℓ.map fun m => h f e (dim (N.src m)) (dim (N.tgt m))).sum = + hsum f e (dim a :: ℓ.map fun m => dim (N.tgt m)) + | a, [], b, _ => by simp [hsum] + | a, m :: ms, b, ⟨hs, hc⟩ => by + simp only [List.map_cons, List.sum_cons, hsum] + rw [chain_hsum f e dim _ ms b hc, hs] + +lemma chain_last (dim : C → ℝ) : ∀ (a : C) (ℓ : List Mv) (b : C), N.Chain a ℓ b → + (dim a :: ℓ.map fun m => dim (N.tgt m)).getLast (List.cons_ne_nil _ _) = dim b + | a, [], b, hc => by simp only [Chain] at hc; subst hc; rfl + | a, m :: ms, b, ⟨_, hc⟩ => by + rw [List.map_cons, List.getLast_cons (List.cons_ne_nil _ _)] + exact chain_last dim _ ms b hc + +/-- the T1 edge price `c(s,t) = g9(dim s, dim t)` (clipped at 0, which changes nothing on real moves). -/ +noncomputable def cg (dim : C → ℕ) (s t : C) : ℝ := max (h fL 9 (dim s) (dim t)) 0 + +/-- the T1 move charge: moves out of chart `z` (= chart 0; Y mains' first moves) are uncharged, every +other move is charged `c(src, tgt)`. -/ +noncomputable def wz (dim : C → ℕ) (z : C) (m : Mv) : ℝ := + if N.src m = z then 0 else cg dim (N.src m) (N.tgt m) + +lemma cg_eq (dim : C → ℕ) (hdim : StrictMono dim) (s t : C) (hst : s < t) (ht : dim t ≤ 9) : + cg dim s t = h fL 9 (dim s) (dim t) := by + have h1 : (dim s : ℝ) ≤ dim t := by exact_mod_cast (hdim hst).le + have h2 : (dim t : ℝ) ≤ 9 := by exact_mod_cast ht + exact max_eq_left (g9_nonneg _ _ h1 h2) + +/-- a register ending at V (dim 9): its charges are at most its real cost `Σ h_9`. -/ +lemma reg_le_V (dim : C → ℕ) (hdim : StrictMono dim) (z : C) (a : C) (ℓ : List Mv) (b : C) + (hc : N.Chain a ℓ b) (hb : dim b ≤ 9) : + (ℓ.map (N.wz dim z)).sum ≤ hsum fL 9 ((dim a : ℝ) :: ℓ.map fun m => (dim (N.tgt m) : ℝ)) := by + rw [← N.chain_hsum fL 9 (fun c => (dim c : ℝ)) a ℓ b hc] + apply List.sum_le_sum + intro m hm + have hbd := N.chain_bounds a ℓ b hc m hm + have ht9 : dim (N.tgt m) ≤ 9 := (hdim.monotone hbd.2).trans hb + have hceq := cg_eq dim hdim _ _ (N.hlt m) ht9 + have h1 : (dim (N.src m) : ℝ) ≤ dim (N.tgt m) := by exact_mod_cast (hdim (N.hlt m)).le + have h2 : (dim (N.tgt m) : ℝ) ≤ 9 := by exact_mod_cast ht9 + unfold wz; split_ifs + · exact g9_nonneg _ _ h1 h2 + · exact hceq.le + +/-- a Y main (born at chart `z`, dim 0; ends at `G_p`, dim 8): charges ≤ real cost `Σ h_8` +(the first move is uncharged; `T1_Y_le`). -/ +lemma reg_le_Y (dim : C → ℕ) (hdim : StrictMono dim) (z : C) (hz0 : dim z = 0) (ℓ : List Mv) (b : C) + (hc : N.Chain z ℓ b) (hb : dim b = 8) : + (ℓ.map (N.wz dim z)).sum ≤ hsum fL 8 ((dim z : ℝ) :: ℓ.map fun m => (dim (N.tgt m) : ℝ)) := by + cases ℓ with + | nil => simp only [Chain] at hc; subst hc; omega + | cons m1 rest => + obtain ⟨hs1, hc'⟩ := hc + have hw1 : N.wz dim z m1 = 0 := by simp [wz, hs1] + have hrest : (rest.map (N.wz dim z)) = rest.map fun m => h fL 9 (dim (N.src m)) (dim (N.tgt m)) := by + apply List.map_congr_left + intro m hm + have hbd := N.chain_bounds _ rest b hc' m hm + have hpos : 0 < dim (N.src m) := by + have := hdim (lt_of_lt_of_le (hs1 ▸ N.hlt m1) hbd.1); omega + have hne : N.src m ≠ z := fun e => by rw [e] at hpos; omega + have ht9 : dim (N.tgt m) ≤ 9 := by have := hdim.monotone hbd.2; omega + simp only [wz, hne, if_false] + exact cg_eq dim hdim _ _ (N.hlt m) ht9 + rw [List.map_cons, List.sum_cons, hw1, zero_add, hrest, + N.chain_hsum fL 9 (fun c => (dim c : ℝ)) _ rest b hc', List.map_cons, hz0, Nat.cast_zero] + have hd1 : 0 < dim (N.tgt m1) := by have := hdim (hs1 ▸ N.hlt m1); omega + have hd8 : dim (N.tgt m1) ≤ 8 := by + have := hdim.monotone (show N.tgt m1 ≤ b from by + cases rest with + | nil => exact le_of_eq hc' + | cons x xs => + have hx := N.chain_bounds _ (x :: xs) b hc' x (by simp) + exact (le_of_lt (N.hlt x)).trans' hx.1 |>.trans hx.2) + omega + apply T1_Y_le + · exact_mod_cast hd1 + · exact_mod_cast hd8 + · rw [N.chain_last (fun c => (dim c : ℝ)) _ rest b hc', hb]; norm_num + +lemma list_range_filter_sum (n : ℕ) (p : ℕ → Prop) (g : ℕ → ℝ) : + (((List.range n).filter (fun t => decide (p t))).map g).sum = + ∑ t ∈ Finset.range n, if p t then g t else 0 := by + induction n with + | zero => simp + | succ n ih => + rw [List.range_succ, List.filter_append, List.map_append, List.sum_append, ih, + Finset.sum_range_succ] + by_cases hp : p n <;> simp [hp] + +/-- **T1, Σ_m w_m ≤ public cost, as a theorem.** JunkM op semantics: charts never decrease, +`mv t i` is register `i`'s move `chart t i → chart (t+1) i` when its chart rises, and the moves are +exactly these (each move is `mv t i` for exactly one rising step `t < n`). Charts carry a strictly +monotone dim (`z` = chart 0, dim 0). Model M: a Y main (`Ym`) is born at `z` and ends at dim 8, every +other register ends at V (dim 9). The public cost is `Σ_i h-sum` over each register's dim chain +(I1), with `e = 8` for Y mains and `9` otherwise. -/ +theorem T1_cost (chart : ℕ → R → C) (mv : ℕ → R → Mv) (n : ℕ) + (hmv : ∀ t i, chart t i < chart (t + 1) i → + N.src (mv t i) = chart t i ∧ N.tgt (mv t i) = chart (t + 1) i) + (hmono : ∀ t i, chart t i ≤ chart (t + 1) i) + (hsurj : ∀ m, ∃ t < n, ∃ i, chart t i < chart (t + 1) i ∧ mv t i = m) + (hinj : ∀ t t' i i', chart t i < chart (t + 1) i → chart t' i' < chart (t' + 1) i' → + mv t i = mv t' i' → t = t' ∧ i = i') + (dim : C → ℕ) (hdim : StrictMono dim) (z : C) (hz0 : dim z = 0) (Ym : Finset R) + (hY : ∀ i ∈ Ym, chart 0 i = z ∧ dim (chart n i) = 8) (hV : ∀ i ∉ Ym, dim (chart n i) = 9) : + ∑ m, N.wz dim z m ≤ ∑ i, hsum fL (if i ∈ Ym then 8 else 9) + ((dim (chart 0 i) : ℝ) :: (movesOf chart mv i n).map fun m => (dim (N.tgt m) : ℝ)) := by + have hsplit : ∑ m, N.wz dim z m = ∑ i, ((movesOf chart mv i n).map (N.wz dim z)).sum := by + have e1 : ∀ i, ((movesOf chart mv i n).map (N.wz dim z)).sum = + ∑ t ∈ Finset.range n, if chart t i < chart (t + 1) i then N.wz dim z (mv t i) else 0 := by + intro i; rw [movesOf, List.map_map]; exact list_range_filter_sum n _ _ + simp_rw [e1] + rw [Finset.sum_comm, ← Finset.sum_product (s := Finset.range n) (t := Finset.univ) + (f := fun x : ℕ × R => if chart x.1 x.2 < chart (x.1 + 1) x.2 then N.wz dim z (mv x.1 x.2) else 0), + ← Finset.sum_filter] + symm + refine Finset.sum_bij (fun x _ => mv x.1 x.2) (fun _ _ => Finset.mem_univ _) ?_ ?_ (fun _ _ => rfl) + · rintro ⟨t, i⟩ h1 ⟨t', i'⟩ h2 he + simp only [Finset.mem_filter] at h1 h2 + obtain ⟨rfl, rfl⟩ := hinj t t' i i' h1.2 h2.2 he; rfl + · intro m _ + obtain ⟨t, ht, i, hr, rfl⟩ := hsurj m + exact ⟨(t, i), by simp [ht, hr], rfl⟩ + rw [hsplit] + refine Finset.sum_le_sum fun i _ => ?_ + have hc := N.movesOf_chain chart mv hmv hmono i n + by_cases hi : i ∈ Ym + · obtain ⟨h0, h8⟩ := hY i hi + rw [if_pos hi, h0]; rw [h0] at hc + exact N.reg_le_Y dim hdim z hz0 _ _ hc h8 + · rw [if_neg hi] + exact N.reg_le_V dim hdim z _ _ _ hc (by rw [hV i hi]) + +/-- **T1 (class M), full form.** Under the hypotheses of `T1_cost`, with chart `z` holding no X port +and a move chain `A_q → G_p` for every junk pair (JunkM `hpath_of_junk`): +`Σ_{junk pairs} dist_{g9}(A_q → G_p) ≤ public cost`. -/ +theorem T1_full (chart : ℕ → R → C) (mv : ℕ → R → Mv) (n : ℕ) + (hmv : ∀ t i, chart t i < chart (t + 1) i → + N.src (mv t i) = chart t i ∧ N.tgt (mv t i) = chart (t + 1) i) + (hmono : ∀ t i, chart t i ≤ chart (t + 1) i) + (hsurj : ∀ m, ∃ t < n, ∃ i, chart t i < chart (t + 1) i ∧ mv t i = m) + (hinj : ∀ t t' i i', chart t i < chart (t + 1) i → chart t' i' < chart (t' + 1) i' → + mv t i = mv t' i' → t = t' ∧ i = i') + (dim : C → ℕ) (hdim : StrictMono dim) (z : C) (hz0 : dim z = 0) (Ym : Finset R) + (hY : ∀ i ∈ Ym, chart 0 i = z ∧ dim (chart n i) = 8) (hV : ∀ i ∉ Ym, dim (chart n i) = 9) + (hz : ∀ q, ¬ N.inS q z) + (P : Finset (YP × XP)) (path : YP × XP → List Mv) + (hpath : ∀ π ∈ P, N.Chain (N.A π.2) (path π) (N.G π.1)) : + ∑ π ∈ P, N.dist (cg dim) (N.A π.2) (N.G π.1) ≤ ∑ i, hsum fL (if i ∈ Ym then 8 else 9) + ((dim (chart 0 i) : ℝ) :: (movesOf chart mv i n).map fun m => (dim (N.tgt m) : ℝ)) := + N.T1_bound (cg dim) (N.wz dim z) P path hpath (fun _ _ => le_max_right _ _) + (fun m => by unfold wz; split_ifs; exact le_rfl; exact le_max_right _ _) z hz + (fun m hm => by simp [wz, hm]) _ + (N.T1_cost chart mv n hmv hmono hsurj hinj dim hdim z hz0 Ym hY hV) + +end Net + +end T1link + + + +/-! ## T3. Slot lemma (level 7) -/ + +section T3 + +open Module Submodule + +variable {K V Reg D C : Type*} [Field K] [AddCommGroup V] [Module K V] [FiniteDimensional K V] + [DecidableEq Reg] [Fintype D] + +/-- **T3 slot lemma.** Data at level 7 (all T2 outputs are hypotheses): +* `Cr` = crossers of level 7 with crossing rows `ρ μ`, linearly independent (T2(a)); +* `B0` = registers born at chart 0 with tokens `tok b`; `S0 = span tok(B0)`; +* `W ⊆ Cr ∩ B0` = 0-born registers jumping from chart 0 straight to dim 8/9; their crossing rows lie + in `S0` (chart 0 holds only 0-born tokens); `Z = (B0 ∩ Cr) \ W` (0-born, cross after a paid stop); +* `P` fixes every crossing row and kills the tokens of 0-born registers that never cross + (a projection onto span ρ(Cr) along the stayer tokens; it exists because these are complementary, + T2 proof — see `proj_exists`); +* for `p ∈ D`: `y p = Σ_μ A p μ • ρ μ` (T2(b)), where a non-`W` crosser has `A p μ ≠ 0` only if it + lands at `G p` (a level-7 crosser landing `≤ G_p`, dim 8, lands AT `G_p`), and `G` is injective; +* `y p = x p + e p` with `e p ∈ S0` (Y_p's token) and `0 ≠ x p ∈ X`, `X ⊓ S0 = ⊥` (X content and + 0-born tokens are different coordinates). +Then `|D| ≤ rank{x_p} + |Z|`. No directness of the `Y_p`, `p ∈ D`, is needed. -/ +theorem slot_lemma (Cr B0 W : Finset Reg) (hW : W ⊆ B0 ∩ Cr) + (ρ tok : Reg → V) (P : V →ₗ[K] V) + (hind : ∀ g : Reg → K, ∑ μ ∈ Cr, g μ • ρ μ = 0 → ∀ μ ∈ Cr, g μ = 0) + (hPρ : ∀ μ ∈ Cr, P (ρ μ) = ρ μ) + (hPst : ∀ b ∈ B0, b ∉ Cr → P (tok b) = 0) + (hWS0 : ∀ μ ∈ W, ρ μ ∈ span K (tok '' (B0 : Set Reg))) + (land : Reg → C) (G : D → C) (hG : Function.Injective G) + (y x e : D → V) (A : D → Reg → K) + (hT2b : ∀ p, y p = ∑ μ ∈ Cr, A p μ • ρ μ) + (hsupp : ∀ p, ∀ μ ∈ Cr, μ ∉ W → A p μ ≠ 0 → land μ = G p) + (hy : ∀ p, y p = x p + e p) (he : ∀ p, e p ∈ span K (tok '' (B0 : Set Reg))) + (X : Submodule K V) (hx : ∀ p, x p ∈ X) (hXS : X ⊓ span K (tok '' (B0 : Set Reg)) = ⊥) + (hx0 : ∀ p, x p ≠ 0) : + Fintype.card D ≤ finrank K (span K (Set.range x)) + ((B0 ∩ Cr) \ W).card := by + classical + set S0 := span K (tok '' (B0 : Set Reg)) with hS0 + -- step 1: every y p has a non-W crosser in its expansion + have hyW : ∀ p, ∃ μ ∈ Cr, μ ∉ W ∧ A p μ ≠ 0 := by + intro p; by_contra hcon; push Not at hcon + have hyS : y p ∈ S0 := by + rw [hT2b p] + refine Submodule.sum_mem _ fun μ hμ => ?_ + by_cases hμW : μ ∈ W + · exact Submodule.smul_mem _ _ (hWS0 μ hμW) + · rw [hcon μ hμ hμW, zero_smul]; exact Submodule.zero_mem _ + have hxS : x p ∈ S0 := by + have : x p = y p - e p := by rw [hy p]; abel + rw [this]; exact Submodule.sub_mem _ hyS (he p) + have : x p ∈ X ⊓ S0 := ⟨hx p, hxS⟩ + rw [hXS] at this + exact hx0 p ((Submodule.mem_bot K).mp this) + -- step 2: the family (y_p)_{p ∈ D} ⊔ (ρ_h)_{h ∈ W} is linearly independent + let F : D ⊕ W → V := Sum.elim y (fun h => ρ h) + have hF : LinearIndependent K F := by + rw [Fintype.linearIndependent_iff] + intro g hg + let gW : Reg → K := fun μ => if hμ : μ ∈ W then g (Sum.inr ⟨μ, hμ⟩) else 0 + let coef : Reg → K := fun μ => (∑ p, g (Sum.inl p) * A p μ) + gW μ + have hW' : ∑ h : W, g (Sum.inr h) • ρ h = ∑ μ ∈ Cr, gW μ • ρ μ := by + rw [← Finset.sum_subset (fun μ hμ => (mem_inter.mp (hW hμ)).2) + (fun μ _ hμ => by simp [gW, hμ])] + rw [← Finset.sum_attach W] + refine Finset.sum_congr rfl fun h _ => ?_ + simp [gW, h.2] + have hsum : ∑ μ ∈ Cr, coef μ • ρ μ = 0 := by + rw [← hg, Fintype.sum_sum_type] + simp only [F, Sum.elim_inl, Sum.elim_inr, hT2b, Finset.smul_sum, smul_smul, coef, add_smul, + Finset.sum_add_distrib, Finset.sum_smul] + rw [hW', Finset.sum_comm] + have hc := hind coef hsum + -- non-W crossers: only one p contributes + have hone : ∀ μ ∈ Cr, μ ∉ W → ∀ p, g (Sum.inl p) * A p μ = 0 := by + intro μ hμ hμW p + have h0 : coef μ = 0 := hc μ hμ + simp only [coef, gW, hμW, dite_false, add_zero] at h0 + by_cases hA2 : A p μ = 0 + · simp [hA2] + rw [Finset.sum_eq_single p] at h0 + · exact h0 + · intro p' _ hp' + by_cases hA : A p' μ = 0 + · simp [hA] + exact absurd (hG ((hsupp p' μ hμ hμW hA).symm.trans (hsupp p μ hμ hμW hA2))) hp' + · simp + have hD0 : ∀ p, g (Sum.inl p) = 0 := by + intro p + obtain ⟨μ, hμ, hμW, hA⟩ := hyW p + exact (mul_eq_zero.mp (hone μ hμ hμW p)).resolve_right hA + rintro (p | ⟨μ, hμW⟩) + · exact hD0 p + · have h0 : coef μ = 0 := hc μ (mem_inter.mp (hW hμW)).2 + simp only [coef, gW, hμW, dite_true, hD0, zero_mul, Finset.sum_const_zero, zero_add] at h0 + exact h0 + -- step 3: the family lies in span(P x) ⊔ E + let E : Submodule K V := span K (((B0 ∩ Cr).image fun b => P (tok b) : Finset V) : Set V) + have hPS0 : ∀ v ∈ S0, P v ∈ E := by + have : S0.map P ≤ E := by + rw [hS0, Submodule.map_span, Submodule.span_le] + rintro _ ⟨_, ⟨b, hb, rfl⟩, rfl⟩ + by_cases hbC : b ∈ Cr + · exact Submodule.subset_span (by simp only [coe_image, coe_inter]; exact ⟨b, ⟨hb, hbC⟩, rfl⟩) + · simp only [SetLike.mem_coe]; rw [hPst b hb hbC]; exact Submodule.zero_mem _ + exact fun v hv => this (Submodule.mem_map_of_mem hv) + set Sx := span K (Set.range fun p => P (x p)) + have hrange : Set.range F ⊆ (Sx ⊔ E : Submodule K V) := by + rintro _ ⟨i, rfl⟩ + rcases i with p | ⟨μ, hμW⟩ + · have hPy : P (y p) = y p := by + rw [hT2b p, map_sum] + exact Finset.sum_congr rfl fun μ hμ => by rw [map_smul, hPρ μ hμ] + show y p ∈ Sx ⊔ E + rw [← hPy, hy p, map_add] + exact Submodule.add_mem _ (Submodule.mem_sup_left (Submodule.subset_span ⟨p, rfl⟩)) + (Submodule.mem_sup_right (hPS0 _ (he p))) + · show ρ μ ∈ Sx ⊔ E + rw [← hPρ μ (mem_inter.mp (hW hμW)).2] + exact Submodule.mem_sup_right (hPS0 _ (hWS0 μ hμW)) + -- step 4: count + have h1 : Fintype.card (D ⊕ W) ≤ finrank K (Sx ⊔ E : Submodule K V) := by + rw [← finrank_span_eq_card hF] + exact Submodule.finrank_mono (Submodule.span_le.mpr hrange) + have h2 := Submodule.finrank_add_le_finrank_add_finrank Sx E + have h3 : finrank K Sx ≤ finrank K (span K (Set.range x)) := by + have : Sx = (span K (Set.range x)).map P := by + rw [Submodule.map_span, ← Set.range_comp]; rfl + rw [this]; exact Submodule.finrank_map_le _ _ + have h4 : finrank K E ≤ (B0 ∩ Cr).card := + (finrank_span_finset_le_card _).trans Finset.card_image_le + have h5 : (B0 ∩ Cr).card = W.card + ((B0 ∩ Cr) \ W).card := by + rw [add_comm, Finset.card_sdiff_add_card_eq_card hW] + rw [Fintype.card_sum, Fintype.card_coe] at h1 + omega + +/-- the projection `P` of T3 exists whenever the crossing span and the stayer-token span are +complementary (T2's proof gives exactly this). -/ +theorem proj_exists (R Q : Submodule K V) (hRQ : IsCompl R Q) : + ∃ P : V →ₗ[K] V, (∀ v ∈ R, P v = v) ∧ (∀ v ∈ Q, P v = 0) := by + refine ⟨R.subtype ∘ₗ Submodule.projectionOnto R Q hRQ, fun v hv => ?_, fun v hv => ?_⟩ + · simp [Submodule.projectionOnto_apply_of_mem_left hRQ hv] + · simp [Submodule.projectionOnto_apply_of_mem_right hRQ hv] + +end T3 + +/-! ## T2. Crossing-basis lemma (complementarity), from the level-k op semantics -/ + +section T2 + +open Module Submodule + +/-- dimension count: if `a ⊔ b = ⊤`, `dim a ≤ m`, `dim b ≤ n` and `dim V = m + n`, then `a`, `b` +are complementary and both bounds are equalities. -/ +lemma compl_of_sup {K V : Type*} [Field K] [AddCommGroup V] [Module K V] [FiniteDimensional K V] + (a b : Submodule K V) (m n : ℕ) (hsup : a ⊔ b = ⊤) (ha : finrank K a ≤ m) (hb : finrank K b ≤ n) + (hV : finrank K V = m + n) : IsCompl a b ∧ finrank K a = m ∧ finrank K b = n := by + have h := Submodule.finrank_sup_add_finrank_inf_eq a b + rw [hsup, finrank_top, hV] at h + have h0 : finrank K (a ⊓ b : Submodule K V) = 0 := by omega + refine ⟨⟨disjoint_iff.mpr (Submodule.finrank_eq_zero.mp h0), codisjoint_iff.mpr hsup⟩, by omega, + by omega⟩ + +lemma finrank_span_image_le {K V ι : Type*} [Field K] [AddCommGroup V] [Module K V] + (s : Finset ι) (f : ι → V) : finrank K (span K (f '' (s : Set ι))) ≤ s.card := by + classical + rw [← Finset.coe_image]; exact (finrank_span_finset_le_card _).trans Finset.card_image_le + +variable {K Reg : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] + +/-- ops seen at level `k`: an ADD `row_i += c·row_j` (co-present, so on the same side of level `k`), +or register `i` crossing level `k` (its first move from dim `≤ k` to dim `> k`). Moves that do not +cross level `k` change neither rows nor sides, so they are omitted. -/ +inductive LOp (K Reg : Type*) + | add (i j : Reg) (c : K) + | cross (i : Reg) + +/-- rows (initial-row coordinates), registers above level `k`, crossers so far, crossing rows. -/ +structure LSt (K Reg : Type*) where + row : Reg → Reg → K + ab : Finset Reg + cr : Finset Reg + rho : Reg → Reg → K + +def lstep : LSt K Reg → LOp K Reg → LSt K Reg + | s, .add i j c => ⟨Function.update s.row i (s.row i + c • s.row j), s.ab, s.cr, s.rho⟩ + | s, .cross i => ⟨s.row, insert i s.ab, insert i s.cr, Function.update s.rho i (s.row i)⟩ + +def lrun : LSt K Reg → List (LOp K Reg) → LSt K Reg + | s, [] => s + | s, op :: ops => lrun (lstep s op) ops + +/-- legality: an ADD has `i ≠ j` (an invertible public op) and both registers on the same side of +level `k` (co-presence at one chart); a crossing register is still at dim `≤ k`. -/ +def LLegal : LSt K Reg → List (LOp K Reg) → Prop + | _, [] => True + | s, .add i j c :: ops => (i ≠ j ∧ (i ∈ s.ab ↔ j ∈ s.ab)) ∧ LLegal (lstep s (.add i j c)) ops + | s, .cross i :: ops => i ∉ s.ab ∧ LLegal (lstep s (.cross i)) ops + +/-- time 0: every register holds its own token; `B` = registers born at dim `≤ k`, the rest are +above level `k` already. -/ +def lstart (B : Finset Reg) : LSt K Reg := ⟨fun r => Pi.single r 1, univ \ B, ∅, fun _ => 0⟩ + +/-- the run invariant (for any linear `L` that kills the tokens of registers born above `k`). -/ +structure LInv {W : Type*} [AddCommGroup W] [Module K W] (B : Finset Reg) (L : (Reg → K) →ₗ[K] W) + (s : LSt K Reg) : Prop where + crB : s.cr ⊆ B + ab_iff : ∀ r, r ∈ s.ab ↔ (r ∉ B ∨ r ∈ s.cr) + up : ∀ r ∈ s.ab, L (s.row r) ∈ span K ((fun μ => L (s.rho μ)) '' (s.cr : Set Reg)) + top : span K (Set.range s.row) = ⊤ + +lemma linv_start {W : Type*} [AddCommGroup W] [Module K W] (B : Finset Reg) + (L : (Reg → K) →ₗ[K] W) (hL : ∀ r, r ∉ B → L (Pi.single r 1) = 0) : + LInv B L (lstart (K := K) B) where + crB := by simp [lstart] + ab_iff := by intro r; simp [lstart] + up := by + intro r hr + simp only [lstart, mem_sdiff, mem_univ, true_and] at hr + simp only [lstart]; rw [hL r hr]; exact Submodule.zero_mem _ + top := by + have : Set.range (fun r : Reg => (Pi.single r (1 : K) : Reg → K)) = + Set.range (Pi.basisFun K Reg) := by + congr 1; funext r; simp + simp only [lstart]; rw [this]; exact (Pi.basisFun K Reg).span_eq + +lemma linv_step {W : Type*} [AddCommGroup W] [Module K W] (B : Finset Reg) + (L : (Reg → K) →ₗ[K] W) (s : LSt K Reg) (op : LOp K Reg) (hI : LInv B L s) + (hop : match op with + | .add i j _ => i ≠ j ∧ (i ∈ s.ab ↔ j ∈ s.ab) + | .cross i => i ∉ s.ab) : + LInv B L (lstep s op) := by + cases op with + | add i j c => + obtain ⟨hij, hside⟩ := hop + refine ⟨hI.crB, hI.ab_iff, ?_, ?_⟩ + · intro r hr + simp only [lstep] at hr ⊢ + by_cases hri : r = i + · subst hri + rw [Function.update_self, map_add, map_smul] + exact Submodule.add_mem _ (hI.up r hr) (Submodule.smul_mem _ _ (hI.up j (hside.mp hr))) + · rw [Function.update_of_ne hri]; exact hI.up r hr + · rw [eq_top_iff, ← hI.top, Submodule.span_le] + rintro _ ⟨r, rfl⟩ + simp only [lstep] + set u := Function.update s.row i (s.row i + c • s.row j) with hu + by_cases hri : r = i + · subst hri + have e1 : s.row r = u r - c • u j := by + rw [hu, Function.update_self, Function.update_of_ne (Ne.symm hij)]; abel + rw [e1] + exact Submodule.sub_mem _ (Submodule.subset_span ⟨r, rfl⟩) + (Submodule.smul_mem _ _ (Submodule.subset_span ⟨j, rfl⟩)) + · have : s.row r = u r := by + rw [hu, Function.update_of_ne hri] + rw [this]; exact Submodule.subset_span ⟨r, rfl⟩ + | cross i => + have hiB : i ∈ B := by + by_contra h; exact hop ((hI.ab_iff i).mpr (Or.inl h)) + have hicr : i ∉ s.cr := fun h => hop ((hI.ab_iff i).mpr (Or.inr h)) + have hmono : span K ((fun μ => L (s.rho μ)) '' (s.cr : Set Reg)) ≤ + span K ((fun μ => L (Function.update s.rho i (s.row i) μ)) '' ((insert i s.cr : Finset Reg) : Set Reg)) := by + apply Submodule.span_mono + rintro _ ⟨μ, hμ, rfl⟩ + have hμi : μ ≠ i := fun e => hicr (e ▸ hμ) + refine ⟨μ, by simp [hμ], ?_⟩ + simp [Function.update_of_ne hμi] + refine ⟨?_, ?_, ?_, hI.top⟩ + · simp only [lstep]; exact Finset.insert_subset hiB hI.crB + · intro r; simp only [lstep, mem_insert] + rw [hI.ab_iff r]; tauto + · intro r hr + simp only [lstep, mem_insert] at hr ⊢ + rcases hr with rfl | hr + · apply Submodule.subset_span + exact ⟨r, by simp, by simp⟩ + · exact hmono (hI.up r hr) + +lemma linv_run {W : Type*} [AddCommGroup W] [Module K W] (B : Finset Reg) + (L : (Reg → K) →ₗ[K] W) : ∀ (s : LSt K Reg) (ops : List (LOp K Reg)), + LInv B L s → LLegal s ops → LInv B L (lrun s ops) + | s, [], hI, _ => hI + | s, .add i j c :: ops, hI, ⟨h, hL⟩ => linv_run B L _ ops (linv_step B L s _ hI h) hL + | s, .cross i :: ops, hI, ⟨h, hL⟩ => linv_run B L _ ops (linv_step B L s _ hI h) hL + +/-- restriction to the coordinates of registers born at dim `≤ k`. -/ +def resB (B : Finset Reg) : (Reg → K) →ₗ[K] (B → K) := LinearMap.funLeft K K (Subtype.val) + +lemma resB_single (B : Finset Reg) (r : Reg) (hr : r ∉ B) : resB B (Pi.single r (1 : K)) = 0 := by + funext b + have : (b : Reg) ≠ r := fun e => hr (e ▸ b.2) + simp [resB, LinearMap.funLeft_apply, Pi.single_apply, this] + +/-- **T2 (crossing-basis lemma), from the op semantics.** Run legal level-`k` ops from time 0 +(`B` = registers born at dim `≤ k`). Class-N hypothesis: every stayer (born `≤ k`, never crosses) +ends as its own token. Restrict rows to the coordinates of `B` (`resB`). Then +* `cr ⊆ B`; +* (complementarity) the crossing rows and the stayer tokens span complementary subspaces of `B → K`; +* (T2(a)) the crossing rows are linearly independent; +* (T2(b), existence) every register above level `k` at the end (born above, or crossed) has its + restricted final row in the span of the crossing rows. -/ +theorem T2_run (B : Finset Reg) (ops : List (LOp K Reg)) (hL : LLegal (lstart B) ops) + (hst : ∀ r ∈ B, r ∉ (lrun (lstart B) ops).cr → (lrun (lstart B) ops).row r = Pi.single r 1) : + (lrun (lstart (K := K) B) ops).cr ⊆ B ∧ + IsCompl (span K ((fun μ => resB B ((lrun (lstart B) ops).rho μ)) '' ((lrun (lstart B) ops).cr : Set Reg))) + (span K ((fun b => resB B (Pi.single b (1 : K))) '' ((B \ (lrun (lstart B) ops).cr : Finset Reg) : Set Reg))) ∧ + LinearIndependent K (fun μ : (lrun (lstart (K := K) B) ops).cr => resB B ((lrun (lstart B) ops).rho μ)) ∧ + (∀ r, r ∉ B ∨ r ∈ (lrun (lstart (K := K) B) ops).cr → + resB B ((lrun (lstart B) ops).row r) ∈ + span K ((fun μ => resB B ((lrun (lstart B) ops).rho μ)) '' ((lrun (lstart B) ops).cr : Set Reg))) := by + classical + set s := lrun (lstart (K := K) B) ops + have hI : LInv B (resB B) s := linv_run B (resB B) _ ops (linv_start B _ (resB_single B)) hL + set a := span K ((fun μ => resB B (s.rho μ)) '' (s.cr : Set Reg)) + set b := span K ((fun b => resB B (Pi.single b (1 : K))) '' ((B \ s.cr : Finset Reg) : Set Reg)) + have hsup : a ⊔ b = ⊤ := by + have hsurj : Function.Surjective (resB (K := K) B) := + LinearMap.funLeft_surjective_of_injective _ _ _ Subtype.val_injective + rw [eq_top_iff, ← LinearMap.range_eq_top.mpr hsurj, LinearMap.range_eq_map, ← hI.top, + Submodule.map_span, Submodule.span_le] + rintro _ ⟨_, ⟨r, rfl⟩, rfl⟩ + by_cases hr : r ∈ s.ab + · exact Submodule.mem_sup_left (hI.up r hr) + · have hrB : r ∈ B := by by_contra h; exact hr ((hI.ab_iff r).mpr (Or.inl h)) + have hrc : r ∉ s.cr := fun h => hr ((hI.ab_iff r).mpr (Or.inr h)) + apply Submodule.mem_sup_right + rw [hst r hrB hrc] + exact Submodule.subset_span ⟨r, by simp [hrB, hrc], rfl⟩ + have ha : finrank K a ≤ s.cr.card := finrank_span_image_le _ _ + have hb : finrank K b ≤ (B \ s.cr).card := finrank_span_image_le _ _ + have hV : finrank K (B → K) = s.cr.card + (B \ s.cr).card := by + rw [Module.finrank_fintype_fun_eq_card, Fintype.card_coe, add_comm, + Finset.card_sdiff_add_card_eq_card hI.crB] + obtain ⟨hc, hfa, -⟩ := compl_of_sup a b _ _ hsup ha hb hV + refine ⟨hI.crB, hc, ?_, fun r hr => hI.up r ((hI.ab_iff r).mpr hr)⟩ + rw [linearIndependent_iff_card_eq_finrank_span, Set.finrank] + have : Set.range (fun μ : s.cr => resB B (s.rho μ)) = (fun μ => resB B (s.rho μ)) '' (s.cr : Set Reg) := by + ext v; simp + rw [this, Fintype.card_coe]; exact hfa.symm + +end T2 + +/-! ### T3 with T2 discharged -/ + +section T3T2 + +open Module Submodule + +/-- **T3 with the complementarity discharged.** `slot_lemma` with its T2 hypotheses (independence of +the crossing rows, and the projection `P`) replaced by the T2 data: the crossing rows `ρ(Cr)` and the +stayer tokens `tok(St)` span `V`, `dim V = |Cr| + |St|`, and every 0-born non-crosser is a stayer. +(`T2_run` derives exactly this from the op semantics, with `V = B → K`.) -/ +theorem slot_lemma_T2 {K V Reg D C : Type*} [Field K] [AddCommGroup V] [Module K V] + [FiniteDimensional K V] [DecidableEq Reg] [Fintype D] + (Cr B0 W St : Finset Reg) (hW : W ⊆ B0 ∩ Cr) (ρ tok : Reg → V) + (hsup : span K (ρ '' (Cr : Set Reg)) ⊔ span K (tok '' (St : Set Reg)) = ⊤) + (hdim : finrank K V = Cr.card + St.card) + (hSt : ∀ b ∈ B0, b ∉ Cr → b ∈ St) + (hWS0 : ∀ μ ∈ W, ρ μ ∈ span K (tok '' (B0 : Set Reg))) + (land : Reg → C) (G : D → C) (hG : Function.Injective G) + (y x e : D → V) (A : D → Reg → K) + (hT2b : ∀ p, y p = ∑ μ ∈ Cr, A p μ • ρ μ) + (hsupp : ∀ p, ∀ μ ∈ Cr, μ ∉ W → A p μ ≠ 0 → land μ = G p) + (hy : ∀ p, y p = x p + e p) (he : ∀ p, e p ∈ span K (tok '' (B0 : Set Reg))) + (X : Submodule K V) (hx : ∀ p, x p ∈ X) (hXS : X ⊓ span K (tok '' (B0 : Set Reg)) = ⊥) + (hx0 : ∀ p, x p ≠ 0) : + Fintype.card D ≤ finrank K (span K (Set.range x)) + ((B0 ∩ Cr) \ W).card := by + obtain ⟨hc, hfa, -⟩ := compl_of_sup _ _ _ _ hsup (finrank_span_image_le _ _) + (finrank_span_image_le _ _) hdim + obtain ⟨P, hP1, hP2⟩ := proj_exists _ _ hc + have hli : LinearIndependent K (fun μ : Cr => ρ μ) := by + rw [linearIndependent_iff_card_eq_finrank_span, Set.finrank] + have : Set.range (fun μ : Cr => ρ μ) = ρ '' (Cr : Set Reg) := by ext v; simp + rw [this, Fintype.card_coe]; exact hfa.symm + refine slot_lemma Cr B0 W hW ρ tok P ?_ (fun μ hμ => hP1 _ (subset_span ⟨μ, hμ, rfl⟩)) + (fun b hb hbC => hP2 _ (subset_span ⟨b, hSt b hb hbC, rfl⟩)) hWS0 land G hG y x e A hT2b hsupp + hy he X hx hXS hx0 + intro g hg μ hμ + have := Fintype.linearIndependent_iff.mp hli (fun μ => g μ) + (by rw [Finset.sum_coe_sort Cr (fun μ => g μ • ρ μ)]; exact hg) + exact this ⟨μ, hμ⟩ + +/-- **T3 from the op semantics.** Level-7 run (`T2_run`): `B` = registers born at dim `≤ 7`, `B0 ⊆ B` +the 0-born ones, stayers end as their own tokens (class N). In `V = B → K` with crossing rows +`resB(ρ_μ)` and tokens `resB(e_b)`, the slot bound holds with only T2(b)'s coefficient/support data, +the W/S0 facts and the X/S0 split left as hypotheses. -/ +theorem slot_lemma_run {K Reg D C : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] [Fintype D] + (B B0 W : Finset Reg) (hB0 : B0 ⊆ B) (ops : List (LOp K Reg)) (hL : LLegal (lstart B) ops) + (hst : ∀ r ∈ B, r ∉ (lrun (lstart B) ops).cr → (lrun (lstart B) ops).row r = Pi.single r 1) + (hW : W ⊆ B0 ∩ (lrun (lstart (K := K) B) ops).cr) + (hWS0 : ∀ μ ∈ W, resB B ((lrun (lstart B) ops).rho μ) ∈ + span K ((fun b => resB B (Pi.single b (1 : K))) '' (B0 : Set Reg))) + (land : Reg → C) (G : D → C) (hG : Function.Injective G) + (y x e : D → (B → K)) (A : D → Reg → K) + (hT2b : ∀ p, y p = ∑ μ ∈ (lrun (lstart (K := K) B) ops).cr, + A p μ • resB B ((lrun (lstart B) ops).rho μ)) + (hsupp : ∀ p, ∀ μ ∈ (lrun (lstart (K := K) B) ops).cr, μ ∉ W → A p μ ≠ 0 → land μ = G p) + (hy : ∀ p, y p = x p + e p) + (he : ∀ p, e p ∈ span K ((fun b => resB B (Pi.single b (1 : K))) '' (B0 : Set Reg))) + (X : Submodule K (B → K)) (hx : ∀ p, x p ∈ X) + (hXS : X ⊓ span K ((fun b => resB B (Pi.single b (1 : K))) '' (B0 : Set Reg)) = ⊥) + (hx0 : ∀ p, x p ≠ 0) : + Fintype.card D ≤ finrank K (span K (Set.range x)) + + ((B0 ∩ (lrun (lstart (K := K) B) ops).cr) \ W).card := by + obtain ⟨hcrB, hc, -, -⟩ := T2_run B ops hL hst + set s := lrun (lstart (K := K) B) ops + refine slot_lemma_T2 s.cr B0 W (B \ s.cr) hW (fun μ => resB B (s.rho μ)) + (fun b => resB B (Pi.single b (1 : K))) hc.sup_eq_top ?_ ?_ hWS0 land G hG y x e A hT2b hsupp + hy he X hx hXS hx0 + · rw [Module.finrank_fintype_fun_eq_card, Fintype.card_coe, add_comm, + Finset.card_sdiff_add_card_eq_card hcrB] + · intro b hb hbC; exact Finset.mem_sdiff.mpr ⟨hB0 hb, hbC⟩ + +end T3T2 + + +/-! ## T4. Departer law, corrected scope (all arrivals, owned included) -/ + +section T4 + +open Module Submodule + +variable {K Reg : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] + +/-- events at ONE chart `c`, in time order: a register arrives with a row, a register is born at +`c` (row = its own token), an ADD `row_i += k·row_j`, or a register departs (moves up). -/ +inductive Ev (K Reg : Type*) + | arrive (i : Reg) (v : Reg → K) + | born (b : Reg) + | add (i j : Reg) (k : K) + | depart (i : Reg) + +/-- rows (initial-row coordinates `Reg → K`) and the set of registers present at `c`. -/ +structure St (K Reg : Type*) where + row : Reg → Reg → K + pres : Finset Reg + +def step : St K Reg → Ev K Reg → St K Reg + | s, .arrive i v => ⟨Function.update s.row i v, insert i s.pres⟩ + | s, .born b => ⟨Function.update s.row b (Pi.single b 1), insert b s.pres⟩ + | s, .add i j k => ⟨Function.update s.row i (s.row i + k • s.row j), s.pres⟩ + | s, .depart i => ⟨s.row, s.pres.erase i⟩ + +def run : St K Reg → List (Ev K Reg) → St K Reg + | s, [] => s + | s, ev :: evs => run (step s ev) evs + +/-- an ADD at `c` only reads and writes registers present at `c` (owned ones included: they are +registers like any other and must ARRIVE or be BORN at `c` to be present). -/ +def Legal : St K Reg → List (Ev K Reg) → Prop + | _, [] => True + | s, .add i j k :: evs => (i ∈ s.pres ∧ j ∈ s.pres) ∧ Legal (step s (.add i j k)) evs + | s, ev :: evs => Legal (step s ev) evs + +/-- invariant: every present row lies in `N` as long as all arrival rows and born tokens do. -/ +lemma run_inv (N : Submodule K (Reg → K)) : + ∀ (s : St K Reg) (evs : List (Ev K Reg)), Legal s evs → + (∀ i ∈ s.pres, s.row i ∈ N) → + (∀ i v, Ev.arrive i v ∈ evs → v ∈ N) → (∀ b, Ev.born b ∈ evs → Pi.single b 1 ∈ N) → + ∀ i ∈ (run s evs).pres, (run s evs).row i ∈ N + | s, [], _, hs, _, _ => hs + | s, ev :: evs, hL, hs, harr, hborn => by + have harr' : ∀ i v, Ev.arrive i v ∈ evs → v ∈ N := fun i v h => harr i v (by simp [h]) + have hborn' : ∀ b, Ev.born b ∈ evs → Pi.single b 1 ∈ N := fun b h => hborn b (by simp [h]) + cases ev with + | arrive i v => + refine run_inv N _ evs hL ?_ harr' hborn' + intro r hr + simp only [step, mem_insert] at hr ⊢ + by_cases hri : r = i + · subst hri; simp only [Function.update_self]; exact harr r v (by simp) + · rw [Function.update_of_ne hri]; exact hs r (hr.resolve_left hri) + | born b => + refine run_inv N _ evs hL ?_ harr' hborn' + intro r hr + simp only [step, mem_insert] at hr ⊢ + by_cases hrb : r = b + · subst hrb; simp only [Function.update_self]; exact hborn r (by simp) + · rw [Function.update_of_ne hrb]; exact hs r (hr.resolve_left hrb) + | add i j k => + obtain ⟨⟨hi, hj⟩, hL⟩ := hL + refine run_inv N _ evs hL ?_ harr' hborn' + intro r hr + simp only [step] at hr ⊢ + by_cases hri : r = i + · subst hri; simp only [Function.update_self] + exact N.add_mem (hs r hi) (N.smul_mem k (hs j hj)) + · rw [Function.update_of_ne hri]; exact hs r hr + | depart i => + refine run_inv N _ evs hL ?_ harr' hborn' + intro r hr + simp only [step, mem_erase] at hr ⊢ + exact hs r hr.2 + +/-- the c-born coordinates can be stripped: if `v ∈ span S ⊔ span tok(Born)`, every generator in +`S` vanishes on `Born`, and `v` vanishes on `Born`, then `v ∈ span S`. -/ +lemma strip_born (S : Set (Reg → K)) (Born : Finset Reg) (hS : ∀ u ∈ S, ∀ b ∈ Born, u b = 0) + (v : Reg → K) (hv : v ∈ span K S ⊔ span K ((fun b => Pi.single b (1 : K)) '' (Born : Set Reg))) + (hvB : ∀ b ∈ Born, v b = 0) : v ∈ span K S := by + let L : (Reg → K) →ₗ[K] (Reg → K) := + LinearMap.pi fun r => if r ∈ Born then LinearMap.proj r else 0 + have hL : ∀ u r, L u r = if r ∈ Born then u r else 0 := by + intro u r; by_cases hr : r ∈ Born <;> simp [L, hr] + have hA : span K S ≤ LinearMap.ker L := by + rw [Submodule.span_le]; intro u hu + simp only [SetLike.mem_coe, LinearMap.mem_ker]; funext r + rw [hL]; split_ifs with hr + · exact hS u hu r hr + · rfl + have hT : span K ((fun b => Pi.single b (1 : K)) '' (Born : Set Reg)) ≤ LinearMap.eqLocus L LinearMap.id := by + rw [Submodule.span_le]; rintro _ ⟨b, hb, rfl⟩ + simp only [SetLike.mem_coe, LinearMap.mem_eqLocus, LinearMap.id_coe, id_eq]; funext r + rw [hL]; split_ifs with hr + · rfl + · have : r ≠ b := fun h => hr (h ▸ hb) + simp [Pi.single_apply, this] + obtain ⟨a, ha, t, ht, rfl⟩ := Submodule.mem_sup.mp hv + have hLv : L (a + t) = 0 := by + funext r; rw [hL]; split_ifs with hr + · exact hvB r hr + · rfl + have hLa : L a = 0 := hA ha + have hLt : L t = t := LinearMap.mem_eqLocus.mp (hT ht) + rw [map_add, hLa, zero_add, hLt] at hLv + rw [hLv, add_zero]; exact ha + +/-- **T4 (departer law), corrected scope.** One chart `c ≠ V` with its event list `evs` (legal, from +the empty state). Arrivals `Arr = Pub ∪ Own` (public and OWNED registers arriving at `c`, disjoint), +arrival rows `arrRow`, which carry no `c`-born coordinates; `Born` = registers born at `c`, disjoint +from `Arr`. Class N: a public register still at `c` at the end (an ender), other than a Y main in +`Ey`, has final row = its own token, and `π` kills that token. Then +`dim π(Arr_c) ≤ #public departers + #owned arrivals + #Y enders`. -/ +theorem T4_departer (π : (Reg → K) →ₗ[K] (Reg → K)) (evs : List (Ev K Reg)) + (Pub Own Born Ey : Finset Reg) (arrRow : Reg → Reg → K) + (hL : Legal ⟨fun _ => 0, ∅⟩ evs) + (harr : ∀ i v, Ev.arrive i v ∈ evs → (i ∈ Pub ∪ Own) ∧ v = arrRow i) + (hborn : ∀ b, Ev.born b ∈ evs → b ∈ Born) + (hPO : Disjoint Pub Own) (hAB : Disjoint (Pub ∪ Own) Born) + (hrowB : ∀ i ∈ Pub ∪ Own, ∀ b ∈ Born, arrRow i b = 0) + (hfinal : ∀ h ∈ Pub, h ∈ (run ⟨fun _ => 0, ∅⟩ evs).pres → h ∉ Ey → + (run ⟨fun _ => 0, ∅⟩ evs).row h = Pi.single h 1) + (hπ : ∀ h ∈ Pub, h ∉ Ey → π (Pi.single h 1) = 0) : + finrank K ((span K (arrRow '' ((Pub ∪ Own : Finset Reg) : Set Reg))).map π) ≤ + (Pub.filter fun h => h ∉ (run ⟨fun _ => 0, ∅⟩ evs).pres).card + Own.card + Ey.card := by + classical + set sf := run ⟨fun _ => 0, ∅⟩ evs + set Arr := Pub ∪ Own + set A := span K (arrRow '' (Arr : Set Reg)) + set Etok := (Pub.filter fun h => h ∈ sf.pres) \ Ey + -- enders' tokens lie in A + have hEA : ∀ h ∈ Etok, (Pi.single h (1 : K) : Reg → K) ∈ A := by + intro h hh + simp only [Etok, mem_sdiff, mem_filter] at hh + have hM := run_inv (A ⊔ span K ((fun b => Pi.single b (1 : K)) '' (Born : Set Reg))) + ⟨fun _ => 0, ∅⟩ evs hL (by simp) + (fun i v hv => by + obtain ⟨hi, rfl⟩ := harr i v hv + exact Submodule.mem_sup_left (Submodule.subset_span ⟨i, hi, rfl⟩)) + (fun b hb => Submodule.mem_sup_right (Submodule.subset_span ⟨b, hborn b hb, rfl⟩)) + h hh.1.2 + rw [hfinal h hh.1.1 hh.1.2 hh.2] at hM + refine strip_born _ Born ?_ _ hM ?_ + · rintro _ ⟨i, hi, rfl⟩ b hb; exact hrowB i hi b hb + · intro b hb + have : h ≠ b := fun e => Finset.disjoint_left.mp hAB (mem_union_left _ hh.1.1) (e ▸ hb) + simp [Pi.single_apply, Ne.symm this] + -- rank–nullity on π restricted to A + let f := π.domRestrict A + have hrn := LinearMap.finrank_range_add_finrank_ker f + have hrange : LinearMap.range f = A.map π := LinearMap.range_domRestrict A π + -- Etok tokens are independent inside ker f + have hker : Etok.card ≤ finrank K (LinearMap.ker f) := by + let g : Etok → LinearMap.ker f := fun h => + ⟨⟨Pi.single h.1 1, hEA h.1 h.2⟩, by + have hh := h.2 + simp only [Etok, mem_sdiff, mem_filter] at hh + simp [f, hπ h.1 hh.1.1 hh.2]⟩ + have hli : LinearIndependent K g := by + apply LinearIndependent.of_comp ((LinearMap.ker f).subtype) + apply LinearIndependent.of_comp A.subtype + have e : (⇑A.subtype ∘ ⇑(LinearMap.ker f).subtype ∘ g) = fun h : Etok => Pi.single h.1 (1 : K) := by + funext h; rfl + rw [e] + have hb := (Pi.basisFun K Reg).linearIndependent + have : (fun h : Etok => Pi.single h.1 (1 : K)) = (Pi.basisFun K Reg) ∘ Subtype.val := by + funext h; simp + rw [this]; exact hb.comp _ Subtype.val_injective + simpa using hli.fintype_card_le_finrank + have hAc : finrank K A ≤ Arr.card := by + have : (arrRow '' (Arr : Set Reg)) = ((Arr.image arrRow : Finset (Reg → K)) : Set (Reg → K)) := by + simp + rw [show A = span K (arrRow '' (Arr : Set Reg)) from rfl, this] + exact (finrank_span_finset_le_card _).trans Finset.card_image_le + have hArr : Arr.card = Pub.card + Own.card := Finset.card_union_of_disjoint hPO + have hPub : Pub.card = (Pub.filter fun h => h ∉ sf.pres).card + (Pub.filter fun h => h ∈ sf.pres).card := by + rw [add_comm]; exact (Finset.card_filter_add_card_filter_not _).symm + have hEt : (Pub.filter fun h => h ∈ sf.pres).card ≤ Etok.card + Ey.card := by + calc _ ≤ (Etok ∪ Ey).card := by + apply card_le_card; intro h hh + by_cases hy : h ∈ Ey + · exact mem_union_right _ hy + · exact mem_union_left _ (mem_sdiff.mpr ⟨hh, hy⟩) + _ ≤ _ := card_union_le _ _ + rw [← hrange] + have : finrank K A = finrank K (LinearMap.range f) + finrank K (LinearMap.ker f) := hrn.symm + omega + +/-- T4 for the public arrival span: it sits inside the all-arrivals span, so the same right-hand +side (with the owned-arrival term) bounds it. Without `Own.card` it is false (`T4_public_only_false`). -/ +theorem T4_public (π : (Reg → K) →ₗ[K] (Reg → K)) (Pub Own : Finset Reg) (arrRow : Reg → Reg → K) : + finrank K ((span K (arrRow '' (Pub : Set Reg))).map π) ≤ + finrank K ((span K (arrRow '' ((Pub ∪ Own : Finset Reg) : Set Reg))).map π) := + Submodule.finrank_mono (Submodule.map_mono (Submodule.span_mono + (Set.image_mono (by simp)))) + +/-- each departer's move into `c` is not its final move, so it costs `h_e(a, dim c)` with +`dim c + 1 ≤ e`, which is `≥ κ = f(2)` (`kappa_le`). Re-export for T4. -/ +theorem T4_stop_cost (e a b : ℝ) (hab : 1 ≤ b - a) (hbe : 1 ≤ e - b) : fL 2 ≤ h fL e a b := + kappa_le e a b hab hbe + +/-- the public-arrivals-only version of T4 is FALSE in this model (GAPMAP scope finding: owned +register 1502 ADDs X content into Y main 213 at charts 593–595, 597). Registers `0` = public `h`, +`1` = owned `o`, `2` = X coordinate. `h` arrives with `e_h + e_x`, `o` arrives with `-e_x`, then +`h += o`: `h` ends at `c` as its own token (class N) and π kills it, yet the public arrival span has +`dim π = 1 > 0 = #public departers + #Y enders`. Counting the owned arrival (`T4_departer`) fixes it. -/ +theorem T4_public_only_false : + let π : (Fin 3 → ℚ) →ₗ[ℚ] (Fin 3 → ℚ) := (LinearMap.single ℚ (fun _ => ℚ) 2) ∘ₗ LinearMap.proj 2 + let evs : List (Ev ℚ (Fin 3)) := + [.arrive 0 (Pi.single 0 1 + Pi.single 2 1), .arrive 1 (-Pi.single 2 1), .add 0 1 1] + let sf := run (⟨fun _ => 0, ∅⟩ : St ℚ (Fin 3)) evs + Legal (⟨fun _ => 0, ∅⟩ : St ℚ (Fin 3)) evs ∧ (0 : Fin 3) ∈ sf.pres ∧ + sf.row 0 = Pi.single 0 1 ∧ π (Pi.single 0 1) = 0 ∧ + ¬ finrank ℚ ((span ℚ {(Pi.single 0 1 + Pi.single 2 1 : Fin 3 → ℚ)}).map π) ≤ 0 := by + intro π evs sf + refine ⟨?_, ?_, ?_, ?_, ?_⟩ + · simp [evs, Legal, step] + · simp [sf, evs, run, step] + · simp only [sf, evs, run, step] + funext r; fin_cases r <;> simp [Function.update, Pi.single_apply] + · simp [π] + · intro h0 + have hbot := Submodule.finrank_eq_zero.mp (Nat.le_zero.mp h0) + have hmem : π (Pi.single 0 1 + Pi.single 2 1) ∈ + (span ℚ {(Pi.single 0 1 + Pi.single 2 1 : Fin 3 → ℚ)}).map π := + Submodule.mem_map_of_mem (Submodule.mem_span_singleton_self _) + rw [hbot, Submodule.mem_bot] at hmem + have := congrFun hmem 2 + simp [π] at this + +end T4 + +end JunkLB2 + +#print axioms JunkLB2.hsum_tele +#print axioms JunkLB2.kappa_le +#print axioms JunkLB2.g9_nonneg +#print axioms JunkLB2.T1_Y +#print axioms JunkLB2.l_nonneg +#print axioms JunkLB2.T1_Y_le +#print axioms JunkLB2.Net.T1_bound +#print axioms JunkLB2.slot_lemma +#print axioms JunkLB2.proj_exists +#print axioms JunkLB2.run_inv +#print axioms JunkLB2.strip_born +#print axioms JunkLB2.Net.movesOf_chain +#print axioms JunkLB2.Net.chain_hsum +#print axioms JunkLB2.Net.reg_le_V +#print axioms JunkLB2.Net.reg_le_Y +#print axioms JunkLB2.Net.T1_cost +#print axioms JunkLB2.Net.T1_full +#print axioms JunkLB2.compl_of_sup +#print axioms JunkLB2.T2_run +#print axioms JunkLB2.slot_lemma_T2 +#print axioms JunkLB2.slot_lemma_run +#print axioms JunkLB2.T4_departer +#print axioms JunkLB2.T4_public +#print axioms JunkLB2.T4_stop_cost +#print axioms JunkLB2.T4_public_only_false diff --git a/research/p104-native-ceiling/lean/Nov15/JunkLB2.md b/research/p104-native-ceiling/lean/Nov15/JunkLB2.md new file mode 100644 index 0000000000..38163ae6b5 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/JunkLB2.md @@ -0,0 +1,60 @@ +# JunkLB2.lean: JunkLB2 T1 (linked), T2, T3, T4 (Lean 4 + Mathlib), no sorry, ~9 s, 2.6 GB RSS +Source: internal notes (T1, T3, T4), with the T4 scope fix from internal notes §2. +Self-contained, namespace JunkLB2. h / gaps / hsum / two_point / Net / chain_append are copied from JunkM.lean. Axioms (all 25 printed): [propext, Classical.choice, Quot.sound]. + +**T1 (g9 pricing, class M).** +- `hsum_tele`: Σ h_e over any chain = f(e−d0) − f(e−last) − Σ f(gaps). The chain need not end at e. +- `T1_Y`: for Y_p with 0 < d1 < … < 8, the real cost Σ h_8(0::d1::…) equals the g9 charge on every move but the first, plus l(d1) = f(8) − f(d1) − f(9−d1). Needs f(0) = f(1) = 0. +- `l_nonneg` (1 ≤ d ≤ 8, by convexity), `l_one`, `T1_Y_le`: charged ≤ real. Direct Y (d1 = 8) is covered and gives 0. Registers ending at V: the charge is the real cost by definition. +- `g9_nonneg`: g9 ≥ 0 for a ≤ b ≤ 9. +- `Net.T1_bound`: Σ_{junk pairs} dist_c(A_q → G_p) ≤ cost. Hypotheses: + - a chain of moves A_q → G_p for each pair (JunkM `hpath_of_junk` now supplies it); + - chart 0 holds no X port; + - every move not leaving chart 0 is charged ≥ c (= g9); + - Σ_m w_m ≤ cost. +- Σ_m w_m ≤ public cost is now a THEOREM , `Net.T1_cost`; `Net.T1_full` chains it with `T1_bound`. + - Op semantics = JunkM's (`path_to_chain`): charts never decrease; `mv t i` is register i's move chart_t(i) → chart_{t+1}(i) when its chart rises. New hypothesis: the moves are EXACTLY these (each move is `mv t i` for one rising step t < n: `hsurj`, `hinj`). + - `movesOf i n` = register i's moves in time order; `movesOf_chain`: they form a chain birth chart → chart at time n. + - `chain_hsum`: Σ h_e over the chain's moves = hsum_e over its dim list (dim : C → ℕ, strictly monotone). + - Charge `wz`: 0 on moves out of chart z (dim 0), else c(s,t) = max(g9,0) (= g9 on every real move, `cg_eq`). + - Model M as hypotheses: Y mains (Ym) are born at z and end at dim 8; every other register ends at dim 9. Public cost := Σ_i hsum_{8 or 9}(i's dim chain) (I1). + - Per register: `reg_le_V` (charge ≤ Σ g9 = cost; 0-born non-Y first moves are charged 0 ≤ g9) and `reg_le_Y` (first move free, rest g9, then `T1_Y_le`). + - Still hypotheses in T1_full: the pair chains (`hpath`, from JunkM `hpath_of_junk`), and chart z holds no X port. + +**T3 (slot lemma), `slot_lemma`.** Conclusion: |D| ≤ rank{x_p : p ∈ D} + |(B0 ∩ Cr) \ W|. Hypotheses, all explicit: +- T2(a): the crossing rows ρ(Cr) are independent. +- T2(b): y_p = Σ A_{pμ} ρ_μ. A non-W crosser has A ≠ 0 only if it lands at G_p, and G is injective. +- W ⊆ B0 ∩ Cr. Crossing rows of W lie in S0 = span tok(B0). +- y_p = x_p + e_p with e_p ∈ S0, 0 ≠ x_p ∈ X, and X ⊓ S0 = 0. +- A linear P that fixes ρ(Cr) and kills the tokens of 0-born non-crossers. `proj_exists` builds P from IsCompl (the complementarity the T2 proof asserts). + +Two findings from the formal proof: +1. The prose step "dim(S0/W) ≤ |Z| after removing stayers" needs this projection. The proof runs in P(S0), and rank{P x_p} ≤ rank{x_p}. +2. Directness of the Y_p in D is never used. D may be any set of Y mains with x_p ≠ 0. Non-direct ones are simply in Z themselves. + +**T2 (crossing-basis lemma), now PROVED from op semantics , `T2_run`.** +- Model at level k: ops are ADD i += c·j (i ≠ j, both on the same side of level k, i.e. co-present) and `cross i` (i's first move from dim ≤ k to > k; its row then is ρ_i). Moves that do not cross k change nothing at this level and are omitted. Time 0: every row is its own token; B = registers born at dim ≤ k. +- Hypothesis (class N): every stayer (in B, never crosses) ends as its own token. +- Conclusions, in V = B → K (rows restricted to B's coordinates, `resB`): + - cr ⊆ B; + - complementarity: span ρ(Cr) and span tok(B \ Cr) are complementary (`IsCompl`); + - T2(a): the crossing rows are linearly independent; + - T2(b), existence: every register above k at the end has its restricted final row in span ρ(Cr). +- Proof (formal): invariants (`LInv`) = above-k rows stay in the span of crossing rows so far; all rows span everything (ADD with i ≠ j is invertible). Then `compl_of_sup`: a ⊔ b = ⊤ with dim a ≤ |Cr|, dim b ≤ |St|, dim V = |Cr| + |St| forces IsCompl and dim a = |Cr|. Stayer-token independence is not needed as input. +- Discharged in T3: `slot_lemma_T2` replaces slot_lemma's independence + projection hypotheses by "ρ(Cr) ∪ tok(St) spans V, dim V = |Cr| + |St|, 0-born non-crossers are stayers". `slot_lemma_run` instantiates it on the run (V = B → K, B0 ⊆ B). +- Still hypotheses in slot_lemma_run: T2(b)'s coefficients A and their support (A_{pμ} ≠ 0 ⇒ μ lands at G_p for non-W μ; the path/landing argument), W's rows in S0, e_p ∈ S0, X ⊓ S0 = 0, x_p ≠ 0. The expansion's existence is proved (T2_run part 4), and with independence A is unique. + +**T4 (departer law), CHOSEN SCOPE: owned arrivals counted.** +- Model: one chart's event list (arrive / born / ADD / depart), with ADDs only between registers present at c. Owned registers are registers too, so to be present at c they must arrive or be born there. +- `run_inv`: every present row lies in span(arrival rows) + span(c-born tokens). This is the prose's first step, and it holds only when ALL arrivals are counted. +- `strip_born`: a row with no c-born coordinates lies in the arrival span. This needs arrival rows to carry no c-born coordinates (a hypothesis). +- `T4_departer`: dim π(Arr_c^all) ≤ #public departers + #owned arrivals + #Y enders. Class-N hypothesis: public enders other than Y end as their own token, and π kills it. +- `T4_public`: the public-arrival span obeys the same bound. +- `T4_stop_cost` / `kappa_le`: a non-final move costs h_e(a,b) ≥ f(2) when b − a ≥ 1 and e − b ≥ 1. +- **Statement found false:** `T4_public_only_false`. The prose T4 (Arr_c = public arrivals, a ≤ d (+1)) fails in the same model, mirroring the gap map's owned-1502 → Y-213 charts. A public h arrives with e_h + e_x and owned o arrives with −e_x. Then h += o, so h ends as its own token. Yet dim π(public span) = 1 > 0. The gap is exactly step one of the prose proof. With no owned arrivals, `T4_departer` gives the prose statement back. + +Still prose / hypotheses: +- "arrivals carry no c-born coordinates" (content only flows upward); +- class-N final rows; +- one arrival per register at c. +- T5 path bound: charging half formalized in Nov15/JunkT5.lean . It is stated with the corrected T4 (owned arrivals) and needs root charts to be terminal. Descent is still prose. diff --git a/research/p104-native-ceiling/lean/Nov15/NumCertK.lean b/research/p104-native-ceiling/lean/Nov15/NumCertK.lean new file mode 100644 index 0000000000..1398c28ed5 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/NumCertK.lean @@ -0,0 +1,382 @@ +import Mathlib.Analysis.SpecialFunctions.Log.Deriv +import Mathlib.Analysis.SpecialFunctions.Pow.Deriv +import Mathlib.Analysis.Complex.ExponentialBounds +import Mathlib.Analysis.Calculus.Deriv.MeanValue + +/-! +NUMCERT-K . Kernel-checked interval arithmetic for the numeric crossing hypotheses of the kappa ceilings. +Section 1: rational enclosures of ln r (chain ln(c+2) = ln(c+1) + 2 atanh(1/(2c+3)) with an explicit geometric tail) and of exp (Taylor of x/8, explicit +remainder `Real.exp_bound'`, eighth power), packaged as `pow_lo`/`pow_hi`: r^s in [pLo r a, pHi r b] for s in [a,b]. Kernel only; no native_decide. +-/ + +namespace NumCertK +open Finset + +def SC : ℚ := 10 ^ 30 +def rdn (q : ℚ) : ℚ := ((⌊q * SC⌋ : ℤ) : ℚ) / SC +def rup (q : ℚ) : ℚ := ((⌈q * SC⌉ : ℤ) : ℚ) / SC +theorem SC_pos : (0 : ℚ) < SC := by unfold SC; positivity +theorem rdn_le (q : ℚ) : rdn q ≤ q := by + unfold rdn; rw [div_le_iff₀ SC_pos]; exact Int.floor_le _ +theorem le_rup (q : ℚ) : q ≤ rup q := by + unfold rup; rw [le_div_iff₀ SC_pos]; exact Int.le_ceil _ +theorem rdn_nonneg {q : ℚ} (h : 0 ≤ q) : 0 ≤ rdn q := by + unfold rdn + have : (0 : ℤ) ≤ ⌊q * SC⌋ := Int.floor_nonneg.mpr (mul_nonneg h SC_pos.le) + have h2 : (0 : ℚ) ≤ ((⌊q * SC⌋ : ℤ) : ℚ) := by exact_mod_cast this + exact div_nonneg h2 SC_pos.le +theorem rup_nonneg {q : ℚ} (h : 0 ≤ q) : 0 ≤ rup q := le_trans h (le_rup q) +theorem rdn_mono {p q : ℚ} (h : p ≤ q) : rdn p ≤ rdn q := by + unfold rdn + apply div_le_div_of_nonneg_right _ SC_pos.le + exact_mod_cast Int.floor_mono (mul_le_mul_of_nonneg_right h SC_pos.le) +theorem rup_mono {p q : ℚ} (h : p ≤ q) : rup p ≤ rup q := by + unfold rup + apply div_le_div_of_nonneg_right _ SC_pos.le + exact_mod_cast Int.ceil_mono (mul_le_mul_of_nonneg_right h SC_pos.le) + +/-! ### 1. ln -/ +def aS (a n : ℕ) : ℚ := + ∑ k ∈ range n, 2 * (1 / (2 * (k : ℚ) + 1)) * (1 / (2 * (a : ℚ) + 1)) ^ (2 * k + 1) +def aTail (a n : ℕ) : ℚ := + 2 * (1 / (2 * (a : ℚ) + 1)) ^ (2 * n + 1) / ((2 * (n : ℚ) + 1) * (1 - (1 / (2 * (a : ℚ) + 1)) ^ 2)) + +theorem atanh_bounds (a n : ℕ) (ha : 0 < a) : + ((aS a n : ℚ) : ℝ) ≤ Real.log (1 + (a : ℝ)⁻¹) ∧ + Real.log (1 + (a : ℝ)⁻¹) ≤ ((aS a n : ℚ) : ℝ) + ((aTail a n : ℚ) : ℝ) := by + have haR : (0 : ℝ) < a := by exact_mod_cast ha + have hs := Real.hasSum_log_one_add_inv haR + set y : ℝ := 1 / (2 * (a : ℝ) + 1) with hy + have hy0 : 0 < y := by rw [hy]; positivity + have hy1 : y < 1 := by + rw [hy, div_lt_one (by positivity)]; have : (1:ℝ) ≤ a := by exact_mod_cast ha + linarith + set f : ℕ → ℝ := fun k => 2 * (1 / (2 * (k : ℝ) + 1)) * y ^ (2 * k + 1) with hf + have hS : ((aS a n : ℚ) : ℝ) = ∑ k ∈ range n, f k := by + simp only [aS, hf, hy]; push_cast; rfl + have ht := (hasSum_nat_add_iff' n).mpr hs + rw [hS] + have hfpos : ∀ k, 0 ≤ f k := fun k => by simp only [hf]; positivity + constructor + · have := ht.nonneg (fun k => hfpos (k + n)) + linarith + · set c : ℝ := 2 * (1 / (2 * (n : ℝ) + 1)) * y ^ (2 * n + 1) with hc + have hy2 : y ^ 2 < 1 := by nlinarith + have hg : HasSum (fun k : ℕ => c * (y ^ 2) ^ k) (c * (1 - y ^ 2)⁻¹) := + (hasSum_geometric_of_lt_one (by positivity) hy2).mul_left c + have hle : ∀ k : ℕ, f (k + n) ≤ c * (y ^ 2) ^ k := by + intro k + simp only [hf, hc] + have e : y ^ (2 * (k + n) + 1) = y ^ (2 * n + 1) * (y ^ 2) ^ k := by + rw [← pow_mul]; rw [← pow_add]; congr 1; ring + push_cast + rw [e] + have h1 : 1 / (2 * ((k : ℝ) + n) + 1) ≤ 1 / (2 * (n : ℝ) + 1) := by + apply one_div_le_one_div_of_le (by positivity); nlinarith [(Nat.cast_nonneg k : (0:ℝ) ≤ k)] + have h2 : 0 ≤ y ^ (2 * n + 1) * (y ^ 2) ^ k := by positivity + nlinarith [mul_le_mul_of_nonneg_right h1 h2] + have := hasSum_le hle ht hg + have hT : ((aTail a n : ℚ) : ℝ) = c * (1 - y ^ 2)⁻¹ := by + simp only [aTail, hc, hy]; push_cast + have : (1 - (1 / (2 * (a : ℝ) + 1)) ^ 2) ≠ 0 := by + have := hy2; rw [hy] at this; intro h; linarith + field_simp + rw [hT]; linarith + +def N : ℕ := 36 +def lnLoC : ℕ → ℚ + | 0 => 0 + | c + 1 => lnLoC c + rdn (aS (c + 1) N) +def lnHiC : ℕ → ℚ + | 0 => 0 + | c + 1 => lnHiC c + rup (aS (c + 1) N + aTail (c + 1) N) +/-- bounds for ln r (r >= 1) -/ +def lnLo (r : ℕ) : ℚ := lnLoC (r - 1) +def lnHi (r : ℕ) : ℚ := lnHiC (r - 1) + +theorem aS_nonneg (a n : ℕ) : 0 ≤ aS a n := by + unfold aS; apply Finset.sum_nonneg; intro k _; positivity +theorem aTail_nonneg (a n : ℕ) : 0 ≤ aTail a n := by + unfold aTail + apply div_nonneg (by positivity) + apply mul_nonneg (by positivity) + by_cases h : a = 0 + · subst h; simp + · have : (1:ℚ) ≤ a := by exact_mod_cast Nat.pos_of_ne_zero h + have h1 : 1 / (2 * (a : ℚ) + 1) ≤ 1 := by rw [div_le_one (by positivity)]; linarith + have h0 : 0 ≤ 1 / (2 * (a : ℚ) + 1) := by positivity + nlinarith + +theorem ln_chain (c : ℕ) : + ((lnLoC c : ℚ) : ℝ) ≤ Real.log ((c : ℝ) + 1) ∧ Real.log ((c : ℝ) + 1) ≤ ((lnHiC c : ℚ) : ℝ) := by + induction c with + | zero => simp [lnLoC, lnHiC] + | succ c ih => + obtain ⟨h1, h2⟩ := ih + have hc : (0 : ℝ) < (c : ℝ) + 1 := by positivity + have e : Real.log (((c + 1 : ℕ) : ℝ) + 1) = Real.log ((c : ℝ) + 1) + Real.log (1 + (((c + 1 : ℕ) : ℝ))⁻¹) := by + rw [← Real.log_mul hc.ne' (by positivity)] + congr 1; push_cast; field_simp + obtain ⟨b1, b2⟩ := atanh_bounds (c + 1) N (Nat.succ_pos c) + rw [e] + constructor + · have : ((rdn (aS (c + 1) N) : ℚ) : ℝ) ≤ ((aS (c + 1) N : ℚ) : ℝ) := by exact_mod_cast rdn_le _ + simp only [lnLoC]; push_cast at *; linarith + · have : ((aS (c + 1) N + aTail (c + 1) N : ℚ) : ℝ) ≤ ((rup (aS (c + 1) N + aTail (c + 1) N) : ℚ) : ℝ) := + by exact_mod_cast le_rup _ + simp only [lnHiC]; push_cast at *; linarith + +theorem lnLo_le (r : ℕ) (hr : 1 ≤ r) : ((lnLo r : ℚ) : ℝ) ≤ Real.log r := by + have h := (ln_chain (r - 1)).1 + unfold lnLo + have : ((r - 1 : ℕ) : ℝ) + 1 = r := by rw [Nat.cast_sub hr]; simp + rwa [this] at h +theorem le_lnHi (r : ℕ) (hr : 1 ≤ r) : Real.log r ≤ ((lnHi r : ℚ) : ℝ) := by + have h := (ln_chain (r - 1)).2 + unfold lnHi + have : ((r - 1 : ℕ) : ℝ) + 1 = r := by rw [Nat.cast_sub hr]; simp + rwa [this] at h + +theorem lnLoC_nonneg (c : ℕ) : 0 ≤ lnLoC c := by + induction c with + | zero => simp [lnLoC] + | succ c ih => simp only [lnLoC]; exact add_nonneg ih (rdn_nonneg (aS_nonneg _ _)) +theorem lnHiC_mono : Monotone lnHiC := by + apply monotone_nat_of_le_succ; intro c + simp only [lnHiC] + have := rup_nonneg (add_nonneg (aS_nonneg (c + 1) N) (aTail_nonneg (c + 1) N)) + linarith +theorem lnLo_nonneg (r : ℕ) : 0 ≤ lnLo r := lnLoC_nonneg _ +theorem lnHi_nonneg (r : ℕ) : 0 ≤ lnHi r := by + have : (0:ℚ) ≤ lnHiC 0 := by simp [lnHiC] + exact le_trans this (lnHiC_mono (Nat.zero_le _)) + +theorem lnHi_145 : lnHi 145 ≤ 5 := by unfold lnHi; decide +kernel +theorem lnHi_le_5 (r : ℕ) (hr : r ≤ 145) : lnHi r ≤ 5 := by + refine le_trans ?_ lnHi_145 + exact lnHiC_mono (by omega) + +/-! ### 2. exp -/ +def NE : ℕ := 24 +def eS (y : ℚ) : ℚ := ∑ m ∈ range NE, y ^ m / (Nat.factorial m : ℚ) +def eR (y : ℚ) : ℚ := y ^ NE * ((NE : ℚ) + 1) / ((Nat.factorial NE : ℚ) * NE) +/-- lower / upper enclosure of exp x: (Taylor of x/8)^8 with outward fixed-point rounding -/ +def eLo (x : ℚ) : ℚ := rdn ((rdn (eS (x / 8))) ^ 8) +def eHi (x : ℚ) : ℚ := rup ((rup (eS (x / 8) + eR (x / 8))) ^ 8) + +theorem eLo_le (x : ℚ) (hx : 0 ≤ x) : ((eLo x : ℚ) : ℝ) ≤ Real.exp x := by + have hx0 : (0:ℝ) ≤ x := by exact_mod_cast hx + have hy : (0 : ℝ) ≤ (x : ℝ) / 8 := by positivity + have h1 := Real.sum_le_exp_of_nonneg hy NE + have hS : ((eS (x / 8) : ℚ) : ℝ) = ∑ m ∈ range NE, ((x : ℝ) / 8) ^ m / (Nat.factorial m : ℝ) := by + simp only [eS]; push_cast; rfl + have h0 : 0 ≤ eS (x / 8) := by + unfold eS; apply Finset.sum_nonneg; intro m _; have : 0 ≤ x / 8 := by positivity + positivity + have h2 : ((rdn (eS (x / 8)) : ℚ) : ℝ) ≤ Real.exp ((x : ℝ) / 8) := by + have : ((rdn (eS (x / 8)) : ℚ) : ℝ) ≤ ((eS (x / 8) : ℚ) : ℝ) := by exact_mod_cast rdn_le _ + linarith + have h3 : (0 : ℝ) ≤ ((rdn (eS (x / 8)) : ℚ) : ℝ) := by exact_mod_cast rdn_nonneg h0 + have h4 : (((rdn (eS (x / 8))) ^ 8 : ℚ) : ℝ) ≤ Real.exp x := by + push_cast + calc ((rdn (eS (x / 8)) : ℚ) : ℝ) ^ 8 ≤ (Real.exp ((x : ℝ) / 8)) ^ 8 := pow_le_pow_left₀ h3 h2 8 + _ = Real.exp x := by rw [← Real.exp_nat_mul]; congr 1; push_cast; ring + have h5 : ((rdn ((rdn (eS (x / 8))) ^ 8) : ℚ) : ℝ) ≤ (((rdn (eS (x / 8))) ^ 8 : ℚ) : ℝ) := by + exact_mod_cast rdn_le _ + unfold eLo; linarith + +theorem le_eHi (x : ℚ) (hx : 0 ≤ x) (hx8 : x ≤ 8) : Real.exp x ≤ ((eHi x : ℚ) : ℝ) := by + have hx0 : (0:ℝ) ≤ x := by exact_mod_cast hx + have hx8' : (x:ℝ) ≤ 8 := by exact_mod_cast hx8 + have hy : (0 : ℝ) ≤ (x : ℝ) / 8 := by positivity + have hy1 : (x : ℝ) / 8 ≤ 1 := by linarith + have h1 := Real.exp_bound' hy hy1 (n := NE) (by unfold NE; norm_num) + have hS : ((eS (x / 8) + eR (x / 8) : ℚ) : ℝ) = + (∑ m ∈ range NE, ((x : ℝ) / 8) ^ m / (Nat.factorial m : ℝ)) + + ((x : ℝ) / 8) ^ NE * ((NE : ℝ) + 1) / ((Nat.factorial NE : ℝ) * NE) := by + simp only [eS, eR]; push_cast; rfl + have h2 : Real.exp ((x : ℝ) / 8) ≤ ((rup (eS (x / 8) + eR (x / 8)) : ℚ) : ℝ) := by + have : ((eS (x / 8) + eR (x / 8) : ℚ) : ℝ) ≤ ((rup (eS (x / 8) + eR (x / 8)) : ℚ) : ℝ) := by + exact_mod_cast le_rup _ + linarith + have h3 : Real.exp x ≤ (((rup (eS (x / 8) + eR (x / 8))) ^ 8 : ℚ) : ℝ) := by + push_cast + calc Real.exp x = (Real.exp ((x : ℝ) / 8)) ^ 8 := by rw [← Real.exp_nat_mul]; congr 1; push_cast; ring + _ ≤ _ := pow_le_pow_left₀ (Real.exp_pos _).le h2 8 + have h5 : (((rup (eS (x / 8) + eR (x / 8))) ^ 8 : ℚ) : ℝ) ≤ ((rup ((rup (eS (x / 8) + eR (x / 8))) ^ 8) : ℚ) : ℝ) := by + exact_mod_cast le_rup _ + unfold eHi; linarith + +/-! ### 3. r^s on an interval of exponents -/ +def pLo (r : ℕ) (a : ℚ) : ℚ := eLo (rdn (a * lnLo r)) +def pHi (r : ℕ) (b : ℚ) : ℚ := eHi (rup (b * lnHi r)) + +/-- **rpow bound (lower)**: for 1 <= r, 0 <= a <= s: pLo r a <= r^s. -/ +theorem pow_lo (r : ℕ) (hr : 1 ≤ r) (a : ℚ) (ha : 0 ≤ a) (s : ℝ) (hs : (a : ℝ) ≤ s) : + ((pLo r a : ℚ) : ℝ) ≤ (r : ℝ) ^ s := by + have hr1 : (1 : ℝ) ≤ r := by exact_mod_cast hr + have hrp : (0 : ℝ) < r := by linarith + have ha0 : (0:ℝ) ≤ a := by exact_mod_cast ha + have h1 : (r : ℝ) ^ (a : ℝ) ≤ (r : ℝ) ^ s := Real.rpow_le_rpow_of_exponent_le hr1 hs + have hx0 : 0 ≤ rdn (a * lnLo r) := rdn_nonneg (mul_nonneg ha (lnLo_nonneg r)) + have h2 := eLo_le _ hx0 + have h3 : ((rdn (a * lnLo r) : ℚ) : ℝ) ≤ Real.log r * a := by + have a1 : ((rdn (a * lnLo r) : ℚ) : ℝ) ≤ ((a * lnLo r : ℚ) : ℝ) := by exact_mod_cast rdn_le _ + have a2 := lnLo_le r hr + push_cast at a1 + nlinarith + have e := Real.rpow_def_of_pos hrp (a : ℝ) + unfold pLo + have := Real.exp_le_exp.mpr h3 + linarith + +/-- **rpow bound (upper)**: for 1 <= r <= 145, 0 <= s <= b <= 1: r^s <= pHi r b. -/ +theorem pow_hi (r : ℕ) (hr : 1 ≤ r) (hr2 : r ≤ 145) (b : ℚ) (hb0 : 0 ≤ b) (hb1 : b ≤ 1) (s : ℝ) + (hs : s ≤ (b : ℝ)) : + (r : ℝ) ^ s ≤ ((pHi r b : ℚ) : ℝ) := by + have hr1 : (1 : ℝ) ≤ r := by exact_mod_cast hr + have hrp : (0 : ℝ) < r := by linarith + have h1 : (r : ℝ) ^ s ≤ (r : ℝ) ^ (b : ℝ) := Real.rpow_le_rpow_of_exponent_le hr1 hs + have hx0 : 0 ≤ rup (b * lnHi r) := rup_nonneg (mul_nonneg hb0 (lnHi_nonneg r)) + have h5 := lnHi_le_5 r hr2 + have hx8 : rup (b * lnHi r) ≤ 8 := by + have : b * lnHi r ≤ 5 := by nlinarith [lnHi_nonneg r] + have h6 := rup_mono this + have h7 : rup 5 = 5 := by unfold rup SC; norm_num + linarith + have h2 := le_eHi _ hx0 hx8 + have h3 : Real.log r * b ≤ ((rup (b * lnHi r) : ℚ) : ℝ) := by + have a1 : ((b * lnHi r : ℚ) : ℝ) ≤ ((rup (b * lnHi r) : ℚ) : ℝ) := by exact_mod_cast le_rup _ + have a2 := le_lnHi r hr + have hb : (0:ℝ) ≤ b := by exact_mod_cast hb0 + push_cast at a1 + nlinarith + have e := Real.rpow_def_of_pos hrp (b : ℝ) + unfold pHi + have := Real.exp_le_exp.mpr h3 + linarith + +/-! ### 4. F(s) = sum c_r r^s: enclosures of F and F', monotonicity -/ +abbrev CF := List (ℕ × ℤ) +noncomputable def Fc (cf : CF) (s : ℝ) : ℝ := (cf.map fun p => (p.2 : ℝ) * (p.1 : ℝ) ^ s).sum +noncomputable def dFc (cf : CF) (s : ℝ) : ℝ := (cf.map fun p => (p.2 : ℝ) * (Real.log p.1 * (p.1 : ℝ) ^ s)).sum +def okR (cf : CF) : Prop := ∀ p ∈ cf, 1 ≤ p.1 ∧ p.1 ≤ 145 +instance (cf : CF) : Decidable (okR cf) := by unfold okR; infer_instance +/-- upper bound of F on s in [a,b] -/ +def Fup (cf : CF) (a b : ℚ) : ℚ := + (cf.map fun p => if 0 ≤ p.2 then (p.2 : ℚ) * pHi p.1 b else (p.2 : ℚ) * pLo p.1 a).sum +/-- lower bound of F' on s in [a,b] -/ +def dLo (cf : CF) (a b : ℚ) : ℚ := + (cf.map fun p => if 0 ≤ p.2 then (p.2 : ℚ) * (lnLo p.1 * pLo p.1 a) + else (p.2 : ℚ) * (lnHi p.1 * pHi p.1 b)).sum + +theorem Fc_le (cf : CF) (hok : okR cf) (a b : ℚ) (ha : 0 ≤ a) (hb1 : b ≤ 1) (s : ℝ) + (h1 : (a : ℝ) ≤ s) (h2 : s ≤ (b : ℝ)) : Fc cf s ≤ ((Fup cf a b : ℚ) : ℝ) := by + have ha0 : (0:ℝ) ≤ a := by exact_mod_cast ha + have hb0 : 0 ≤ b := by + have : (0:ℝ) ≤ b := by linarith + exact_mod_cast this + induction cf with + | nil => simp [Fc, Fup] + | cons p l ih => + have hp := hok p (by simp) + have hl : okR l := fun q hq => hok q (by simp [hq]) + have ih := ih hl + simp only [Fc, Fup, List.map_cons, List.sum_cons] at ih ⊢ + rw [Rat.cast_add] + have hlo := pow_lo p.1 hp.1 a ha s h1 + have hhi := pow_hi p.1 hp.1 hp.2 b hb0 hb1 s h2 + split_ifs with hc + · have hc' : (0:ℝ) ≤ p.2 := by exact_mod_cast hc + simp only [Rat.cast_mul, Rat.cast_intCast] + nlinarith [mul_le_mul_of_nonneg_left hhi hc'] + · have hc' : (p.2:ℝ) ≤ 0 := by exact_mod_cast (show p.2 ≤ 0 by omega) + simp only [Rat.cast_mul, Rat.cast_intCast] + nlinarith [mul_le_mul_of_nonpos_left hlo hc'] + +theorem dFc_ge (cf : CF) (hok : okR cf) (a b : ℚ) (ha : 0 ≤ a) (hb1 : b ≤ 1) (s : ℝ) + (h1 : (a : ℝ) ≤ s) (h2 : s ≤ (b : ℝ)) : ((dLo cf a b : ℚ) : ℝ) ≤ dFc cf s := by + have ha0 : (0:ℝ) ≤ a := by exact_mod_cast ha + have hb0 : 0 ≤ b := by + have : (0:ℝ) ≤ b := by linarith + exact_mod_cast this + induction cf with + | nil => simp [dFc, dLo] + | cons p l ih => + have hp := hok p (by simp) + have hl : okR l := fun q hq => hok q (by simp [hq]) + have ih := ih hl + simp only [dFc, dLo, List.map_cons, List.sum_cons] at ih ⊢ + rw [Rat.cast_add] + have hlo := pow_lo p.1 hp.1 a ha s h1 + have hhi := pow_hi p.1 hp.1 hp.2 b hb0 hb1 s h2 + have hr1 : (1:ℝ) ≤ p.1 := by exact_mod_cast hp.1 + have hL0 : 0 ≤ Real.log p.1 := Real.log_nonneg hr1 + have hl1 := lnLo_le p.1 hp.1 + have hl2 := le_lnHi p.1 hp.1 + have hn0 : (0:ℝ) ≤ ((lnLo p.1 : ℚ) : ℝ) := by exact_mod_cast lnLo_nonneg p.1 + have hn1 : (0:ℝ) ≤ ((lnHi p.1 : ℚ) : ℝ) := by exact_mod_cast lnHi_nonneg p.1 + have hq0 : (0:ℝ) ≤ ((pLo p.1 a : ℚ) : ℝ) := by + have : 0 ≤ pLo p.1 a := by + unfold pLo eLo + apply rdn_nonneg; apply pow_nonneg; apply rdn_nonneg + unfold eS; apply Finset.sum_nonneg; intro m _ + have : 0 ≤ rdn (a * lnLo p.1) / 8 := div_nonneg (rdn_nonneg (mul_nonneg ha (lnLo_nonneg _))) (by norm_num) + positivity + exact_mod_cast this + have hrs : (0:ℝ) ≤ (p.1 : ℝ) ^ s := by positivity + split_ifs with hc + · have hc' : (0:ℝ) ≤ p.2 := by exact_mod_cast hc + simp only [Rat.cast_mul, Rat.cast_intCast] + have m1 : ((lnLo p.1 : ℚ) : ℝ) * ((pLo p.1 a : ℚ) : ℝ) ≤ Real.log p.1 * (p.1 : ℝ) ^ s := + mul_le_mul hl1 hlo hq0 hL0 + nlinarith [mul_le_mul_of_nonneg_left m1 hc'] + · have hc' : (p.2:ℝ) ≤ 0 := by exact_mod_cast (show p.2 ≤ 0 by omega) + simp only [Rat.cast_mul, Rat.cast_intCast] + have m1 : Real.log p.1 * (p.1 : ℝ) ^ s ≤ ((lnHi p.1 : ℚ) : ℝ) * ((pHi p.1 b : ℚ) : ℝ) := + mul_le_mul hl2 hhi hrs hn1 + nlinarith [mul_le_mul_of_nonpos_left m1 hc'] + +theorem Fc_hasDerivAt (cf : CF) (hok : okR cf) (s : ℝ) : HasDerivAt (Fc cf) (dFc cf s) s := by + induction cf with + | nil => simp only [Fc, dFc, List.map_nil, List.sum_nil]; exact hasDerivAt_const s (0 : ℝ) + | cons p l ih => + have hp := hok p (by simp) + have hl : okR l := fun q hq => hok q (by simp [hq]) + have ih := ih hl + have hrp : (0:ℝ) < p.1 := by have : (1:ℝ) ≤ p.1 := by exact_mod_cast hp.1 + linarith + have h1 := ((Real.hasStrictDerivAt_const_rpow hrp s).hasDerivAt.const_mul (p.2 : ℝ)).add ih + have e : Fc (p :: l) = fun s => (p.2 : ℝ) * (p.1 : ℝ) ^ s + Fc l s := by + funext s; simp [Fc] + have e2 : dFc (p :: l) s = (p.2 : ℝ) * ((p.1 : ℝ) ^ s * Real.log p.1) + dFc l s := by + simp only [dFc, List.map_cons, List.sum_cons]; ring + rw [e, e2]; exact h1 + +/-- if F' >= dLo > 0 on [a,b] then F(s) <= F(b) on [a,b] -/ +theorem Fc_mono (cf : CF) (hok : okR cf) (a b : ℚ) (ha : 0 ≤ a) (hb1 : b ≤ 1) (hd : 0 < dLo cf a b) + (s : ℝ) (h1 : (a : ℝ) ≤ s) (h2 : s ≤ (b : ℝ)) : Fc cf s ≤ Fc cf b := by + have hab : (a : ℝ) ≤ b := le_trans h1 h2 + have hcont : ContinuousOn (Fc cf) (Set.Icc (a : ℝ) b) := + fun x _ => (Fc_hasDerivAt cf hok x).continuousAt.continuousWithinAt + have hm : StrictMonoOn (Fc cf) (Set.Icc (a : ℝ) b) := by + apply strictMonoOn_of_deriv_pos (convex_Icc _ _) hcont + intro x hx + rw [interior_Icc] at hx + rw [(Fc_hasDerivAt cf hok x).deriv] + have := dFc_ge cf hok a b ha hb1 x hx.1.le hx.2.le + have hd' : (0:ℝ) < ((dLo cf a b : ℚ) : ℝ) := by exact_mod_cast hd + linarith + exact hm.monotoneOn ⟨h1, h2⟩ ⟨hab, le_refl _⟩ h2 + +theorem Fc_neg_piece (cf : CF) (hok : okR cf) (a b : ℚ) (ha : 0 ≤ a) (hb1 : b ≤ 1) (h : Fup cf a b < 0) + (s : ℝ) (h1 : (a : ℝ) ≤ s) (h2 : s ≤ (b : ℝ)) : Fc cf s < 0 := by + have := Fc_le cf hok a b ha hb1 s h1 h2 + have h' : ((Fup cf a b : ℚ) : ℝ) < 0 := by exact_mod_cast h + linarith + +end NumCertK + +#print axioms NumCertK.pow_lo +#print axioms NumCertK.pow_hi +#print axioms NumCertK.Fc_mono diff --git a/research/p104-native-ceiling/lean/Nov15/NumCertK.md b/research/p104-native-ceiling/lean/Nov15/NumCertK.md new file mode 100644 index 0000000000..5bd62abfc0 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/NumCertK.md @@ -0,0 +1,17 @@ +# NumCertK.lean + NumCertKData.lean + NumCertK22.lean: kernel-checked interval arithmetic; NumCert22 discharged +No sorry, no native_decide; axioms [propext, Classical.choice, Quot.sound] (all three files). Build order: NumCertK (13 s / 2.9 GB), NumCertKData (32 s / 3.4 GB), FloorK22, NumCertK22 (7 s / 2.9 GB); each with `-o .lake/build/lib/lean/Nov15/.olean`. NumCertK22 is a separate file only because importing FloorK22 + the checks in one run exceeds the 3.5 GB guard. + +## Library (NumCertK.lean, Mathlib only) +- ln: chain ln(c+2) = ln(c+1) + 2 atanh(1/(2c+3)) from `Real.hasSum_log_one_add_inv`, 36 terms, explicit geometric tail (`atanh_bounds`), outward rounding to 1e-30 (`rdn`/`rup`). `lnLo r <= ln r <= lnHi r`, r >= 1; accuracy ~1e-28 for r <= 145. +- exp: (Taylor_24(x/8))^8 with `Real.exp_bound'` remainder, outward rounding (`eLo_le`: 0 <= x; `le_eHi`: 0 <= x <= 8). +- **`pow_lo`**: 1 <= r, 0 <= a <= s => pLo r a <= r^s. **`pow_hi`**: 1 <= r <= 145, s <= b <= 1 => r^s <= pHi r b. (s-form: s = 1 - t, so r^(1-t) in [pLo r (1-t_hi), pHi r (1-t_lo)].) Rational, checked by `decide +kernel`. +- F(s) = sum c_r r^s (`Fc`): `Fc_le` (upper enclosure `Fup` on [a,b]), `dFc_ge` (lower enclosure `dLo` of F'), `Fc_hasDerivAt`, `Fc_mono` (dLo > 0 on [a,b] => F(s) <= F(b)). + +## Crossing for K(S22) (NumCertKData.lean, NumCertK22.lean) +- `cfK`: the 17-call invoice caller(6|7) + 17 x nK22, merged by rank: 24 ranks, c_1 = -42272, c_2 = 6494, ..., c_137 = 208 (`invoice_eq_Fc`, simp + ring: identical to the Finv of FloorK22). +- `cfK_neg`: F(s) < 0 for every s in [0, 9939802595/10^10 = 1 - .0060197405]. Proof: six `Fup` boxes cover [0, .9] (grid 0, .45, .6, .7, .8, .85, .9; F <= -3.3e3 at worst); on [.9, s0] one box gives dLo >= 2.5e4 > 0, so F(s) <= F(s0), and the point enclosure gives Fup(s0, s0) < 0 (true F(s0) = -4.83e-6, relative margin 1e-10 of the 2.8e4-sized terms, so the 1e-28 enclosure is ample). +- **`numCert22 : NumCert22 tbar22`** and **`ceiling22_unconditional`**: kappa <= .0060197405 on class K(S22) with NumCert22 discharged; other hypotheses of `ceiling22` unchanged (ClassK22 rank input, cost-model link `hF`). +- The crossing is TRUE: F(1 - .0060197405) = -4.83e-6 (root .00601974047925), F' = 2.33e5 there. + +## Not done +- JointCeiling's `NumCert th0 tbar`: it quantifies over ALL a, b >= 1 (R1 tail Jensen/MVT step, ~1,800 pairs, unaudited per its docstring); the library applies per (a,b) but the infinite tail is not an interval check. WholeFloor's (kappa <= .0204) was not available. diff --git a/research/p104-native-ceiling/lean/Nov15/PathCut.lean b/research/p104-native-ceiling/lean/Nov15/PathCut.lean new file mode 100644 index 0000000000..9352a0d906 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/PathCut.lean @@ -0,0 +1,83 @@ +import Mathlib.Order.Basic +import Mathlib.Data.Finset.Card +import Mathlib.Data.Finset.Union +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.IntervalCases +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Mathlib.Data.Finset.Lattice.Fold +import Mathlib.Order.Interval.Finset.Nat +import Mathlib.Algebra.Order.BigOperators.Group.Finset + +/-! PATH-CUT: the abstract core of internal notes section 3 (with AUD2 FIX A). +Charts form a preorder `alpha` (`C <= C'` = ascent). `Hold C` stands for "u_s lies in the chart C" and is preserved by ascent. A path is a sequence of charts +`c 0 .. c n`; every PUBLIC edge ascends; every OWNED edge is NESTED (comparable ends: rise or descent) -- FIX A. +Conclusion: either the path is legal (every chart holds u_s), or there is a FIRST owned strict descent `c i > c (i+1)` that drops u_s, all earlier charts hold u_s, and c i <= G +(the confinement chart G_t). Not formalised here: the register-machine facts that produce such a path (SP span law, ADD paths inside D_t = Dn(G_t)); +they are the premises of the abstract hypothesis `hcong` of CongestionNative. `nested_needed` shows the nestedness premise cannot be dropped. -/ +namespace PathCut + +theorem path_cut {α : Type*} [Preorder α] (c : ℕ → α) (n : ℕ) (Hold : α → Prop) (G : α) (owned : ℕ → Prop) + (hHold : ∀ C C' : α, C ≤ C' → Hold C → Hold C') + (hpub : ∀ i < n, ¬ owned i → c i ≤ c (i + 1)) + (hnest : ∀ i < n, owned i → (c i ≤ c (i + 1) ∨ c (i + 1) ≤ c i)) + (hconf : ∀ i ≤ n, c i ≤ G) (hstart : Hold (c 0)) : + (∀ i ≤ n, Hold (c i)) ∨ + ∃ i < n, owned i ∧ Hold (c i) ∧ ¬ Hold (c (i + 1)) ∧ c (i + 1) < c i ∧ c i ≤ G ∧ ∀ j ≤ i, Hold (c j) := by + classical + by_cases h : ∀ i ≤ n, Hold (c i) + · exact Or.inl h + · right + push Not at h + have hex : ∃ j, j ≤ n ∧ ¬ Hold (c j) := h + obtain ⟨j, hj, hmin⟩ : ∃ j, (j ≤ n ∧ ¬ Hold (c j)) ∧ ∀ k < j, ¬ (k ≤ n ∧ ¬ Hold (c k)) := + ⟨Nat.find hex, Nat.find_spec hex, fun k hk => Nat.find_min hex hk⟩ + have hj0 : j ≠ 0 := by + intro h0; apply hj.2; rw [h0]; exact hstart + obtain ⟨i, hi⟩ : ∃ i, j = i + 1 := Nat.exists_eq_succ_of_ne_zero hj0 + have hin : i < n := by have := hj.1; omega + have hHi : Hold (c i) := by + by_contra hc; exact hmin i (by omega) ⟨by omega, hc⟩ + have hall : ∀ k ≤ i, Hold (c k) := fun k hk => by + by_contra hc; exact hmin k (by omega) ⟨by omega, hc⟩ + have hnot : ¬ Hold (c (i + 1)) := by have := hj.2; rwa [hi] at this + have hnasc : ¬ c i ≤ c (i + 1) := fun hle => hnot (hHold _ _ hle hHi) + have howned : owned i := by + by_contra ho; exact hnasc (hpub i hin ho) + have hle : c (i + 1) ≤ c i := (hnest i hin howned).resolve_left hnasc + exact ⟨i, hin, howned, hHi, hnot, lt_of_le_not_ge hle hnasc, hconf i hin.le, hall⟩ + +/-- without nestedness the cut is not a descent: a LATERAL owned move can drop `u_s` (AUD2 FIX A). -/ +theorem nested_needed : ∃ (c : ℕ → Finset ℕ) (Hold : Finset ℕ → Prop) (G : Finset ℕ) (owned : ℕ → Prop), + (∀ C C' : Finset ℕ, C ≤ C' → Hold C → Hold C') ∧ (∀ i < 1, ¬ owned i → c i ≤ c (i + 1)) ∧ + (∀ i ≤ 1, c i ≤ G) ∧ Hold (c 0) ∧ + ¬ ((∀ i ≤ 1, Hold (c i)) ∨ + ∃ i < 1, owned i ∧ Hold (c i) ∧ ¬ Hold (c (i + 1)) ∧ c (i + 1) < c i ∧ c i ≤ G ∧ ∀ j ≤ i, Hold (c j)) := by + refine ⟨fun i => if i = 0 then {0} else {1}, fun C => 0 ∈ C, {0, 1}, fun _ => True, ?_, ?_, ?_, ?_, ?_⟩ + · intro C C' h h0; exact h h0 + · intro i hi h; exact absurd trivial h + · intro i hi + interval_cases i <;> simp [Finset.subset_iff] + · simp + · rintro (h | ⟨i, hi, -, -, hn, hlt, -⟩) + · have := h 1 le_rfl; simp at this + · have : i = 0 := by omega + subst this + simp at hlt + +/-- the transported cells of all N_f visits: `|Jt| <= 48 * |V|` when every visit has at most 48 cells (the 48-law) and every transported cell lies in the cells of some visit. -/ +theorem transported_card_le {ν : Type*} [DecidableEq ν] (V : Finset ν) (cells : ν → Finset (ℕ × ℕ)) (Jt : Finset (ℕ × ℕ)) + (h48 : ∀ v ∈ V, (cells v).card ≤ 48) (hcut : ∀ p ∈ Jt, ∃ v ∈ V, p ∈ cells v) : + Jt.card ≤ 48 * V.card := by + classical + have hsub : Jt ⊆ V.biUnion cells := by + intro p hp; obtain ⟨v, hv, hpv⟩ := hcut p hp; exact Finset.mem_biUnion.2 ⟨v, hv, hpv⟩ + calc Jt.card ≤ (V.biUnion cells).card := Finset.card_le_card hsub + _ ≤ ∑ v ∈ V, (cells v).card := Finset.card_biUnion_le + _ ≤ ∑ _v ∈ V, 48 := Finset.sum_le_sum h48 + _ = 48 * V.card := by simp [mul_comm] + +end PathCut + +#print axioms PathCut.path_cut +#print axioms PathCut.nested_needed +#print axioms PathCut.transported_card_le diff --git a/research/p104-native-ceiling/lean/Nov15/RankLaw.lean b/research/p104-native-ceiling/lean/Nov15/RankLaw.lean new file mode 100644 index 0000000000..fd4ec249d3 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/RankLaw.lean @@ -0,0 +1,597 @@ +import Nov15.TokenCancel +import Mathlib.LinearAlgebra.Matrix.ToLin +import Mathlib.LinearAlgebra.Determinant +import Mathlib.LinearAlgebra.Matrix.Block +import Mathlib.LinearAlgebra.Matrix.Transvection +import Mathlib.LinearAlgebra.Matrix.NonsingularInverse +import Mathlib.LinearAlgebra.Projection +import Mathlib.LinearAlgebra.Isomorphisms +import Mathlib.LinearAlgebra.Dimension.Constructions +import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas + +set_option linter.unusedSectionVars false +namespace RankLaw +open Submodule Module + +section Equiv +variable {K V W : Type*} [Field K] [AddCommGroup V] [Module K V] [AddCommGroup W] [Module K W] + [FiniteDimensional K V] + +/-- Two linear maps out of a finite-dimensional space with the same range differ by an +automorphism of the source. -/ +theorem exists_equiv_comp (f g : V →ₗ[K] W) (h : LinearMap.range f = LinearMap.range g) : + ∃ φ : V ≃ₗ[K] V, f ∘ₗ φ.toLinearMap = g := by + obtain ⟨Qg, hQg⟩ := Submodule.exists_isCompl (LinearMap.ker g) + obtain ⟨Qf, hQf⟩ := Submodule.exists_isCompl (LinearMap.ker f) + have hk : finrank K (LinearMap.ker g) = finrank K (LinearMap.ker f) := by + have h1 := LinearMap.finrank_range_add_finrank_ker f + have h2 := LinearMap.finrank_range_add_finrank_ker g + rw [h] at h1; omega + let e1 : LinearMap.ker g ≃ₗ[K] LinearMap.ker f := LinearEquiv.ofFinrankEq _ _ hk + let e2 : Qg ≃ₗ[K] Qf := + (Submodule.quotientEquivOfIsCompl _ _ hQg).symm ≪≫ₗ g.quotKerEquivRange ≪≫ₗ + (LinearEquiv.ofEq _ _ h.symm) ≪≫ₗ f.quotKerEquivRange.symm ≪≫ₗ + Submodule.quotientEquivOfIsCompl _ _ hQf + let φ : V ≃ₗ[K] V := (Submodule.prodEquivOfIsCompl _ _ hQg).symm ≪≫ₗ (e1.prodCongr e2) ≪≫ₗ + Submodule.prodEquivOfIsCompl _ _ hQf + refine ⟨φ, ?_⟩ + -- key: f (e2 q) = g q + have key : ∀ q : Qg, f (e2 q : V) = g q := by + intro q + set y : Qf := e2 q + have hy : (Submodule.Quotient.mk (y : V) : V ⧸ LinearMap.ker f) = + f.quotKerEquivRange.symm (LinearEquiv.ofEq _ _ h.symm + (g.quotKerEquivRange (Submodule.Quotient.mk (q : V)))) := by + have := Submodule.mk_quotientEquivOfIsCompl_apply hQf + (f.quotKerEquivRange.symm (LinearEquiv.ofEq _ _ h.symm + (g.quotKerEquivRange (Submodule.Quotient.mk (q : V))))) + convert this using 2 + simp [y, e2, Submodule.quotientEquivOfIsCompl_symm_apply] + have := congrArg (fun t => (f.quotKerEquivRange t : W)) hy + simpa using this + apply LinearMap.ext; intro v + obtain ⟨⟨k, q⟩, rfl⟩ := (Submodule.prodEquivOfIsCompl _ _ hQg).surjective v + have hφ : φ ((Submodule.prodEquivOfIsCompl _ _ hQg) (k, q)) = (e1 k : V) + (e2 q : V) := by + simp only [φ, LinearEquiv.trans_apply, LinearEquiv.symm_apply_apply] + rfl + rw [LinearMap.comp_apply, LinearEquiv.coe_coe, hφ, coe_prodEquivOfIsCompl', map_add, map_add] + have hk0 : f (e1 k : V) = 0 := (e1 k).2 + have hg0 : g (k : V) = 0 := k.2 + rw [hk0, hg0, key] +end Equiv + + +section Mix +variable {K G ι : Type*} [Field K] [Fintype G] [DecidableEq G] + +/-- **The V-mix target, as a linear system.** Given the end rows `X` of the registers that end at V +(indexed by `G`) and their target rows `R`, a V mix is an invertible `C` with `C * X = R`. -/ +def VMixM (X R : Matrix G ι K) : Prop := ∃ C : Matrix G G K, IsUnit C.det ∧ C * X = R + +/-- The V-mix system is solvable iff the end rows and the target rows span the same space. -/ +theorem vmixM_iff_span (X R : Matrix G ι K) : + VMixM X R ↔ span K (Set.range X.row) = span K (Set.range R.row) := by + constructor + · rintro ⟨C, hC, hCX⟩ + have hR : ∀ g, R.row g ∈ span K (Set.range X.row) := by + intro g; rw [← hCX] + have : (C * X).row g = Matrix.vecMul (C g) X := rfl + rw [this, ← range_vecMulLinear X]; exact ⟨C g, rfl⟩ + have hX : X = C⁻¹ * R := by rw [← hCX, ← Matrix.mul_assoc, Matrix.nonsing_inv_mul _ hC, Matrix.one_mul] + have hXR : ∀ g, X.row g ∈ span K (Set.range R.row) := by + intro g; rw [hX] + have : (C⁻¹ * R).row g = Matrix.vecMul (C⁻¹ g) R := rfl + rw [this, ← range_vecMulLinear R]; exact ⟨C⁻¹ g, rfl⟩ + apply le_antisymm + · exact span_le.2 (by rintro _ ⟨g, rfl⟩; exact hXR g) + · exact span_le.2 (by rintro _ ⟨g, rfl⟩; exact hR g) + · intro h + have h' : LinearMap.range X.vecMulLinear = LinearMap.range R.vecMulLinear := by + rw [range_vecMulLinear, range_vecMulLinear]; exact h + obtain ⟨φ, hφ⟩ := exists_equiv_comp X.vecMulLinear R.vecMulLinear h' + refine ⟨(LinearMap.toMatrix' φ.toLinearMap).transpose, ?_, ?_⟩ + · rw [Matrix.det_transpose, LinearMap.det_toMatrix'] + exact LinearEquiv.isUnit_det' φ + · ext g j + have e := congrArg (fun F : (G → K) →ₗ[K] (ι → K) => F (Pi.single g 1) j) hφ + simp only [LinearMap.comp_apply, Matrix.vecMulLinear_apply, LinearEquiv.coe_coe] at e + rw [Matrix.single_one_vecMul] at e + have hrow : (fun k => (LinearMap.toMatrix' φ.toLinearMap).transpose g k) = φ (Pi.single g 1) := by + funext k; simp [Matrix.transpose_apply, LinearMap.toMatrix'_apply] + change Matrix.vecMul _ X j = R.row g j + rw [hrow, e] +/-- If the targets are independent, a V mix makes the end rows independent too ("G1 rows are +|G1| independent vectors inside span(G1 targets)"). -/ +theorem vmixM_indep (X R : Matrix G ι K) (h : VMixM X R) (hR : LinearIndependent K R.row) : + LinearIndependent K X.row := by + obtain ⟨C, hC, hCX⟩ := h + have hX : X = C⁻¹ * R := by + rw [← hCX, ← Matrix.mul_assoc, Matrix.nonsing_inv_mul _ hC, Matrix.one_mul] + rw [← Matrix.vecMul_injective_iff] at hR ⊢ + have hCi : Function.Injective (fun v : G → K => Matrix.vecMul v C⁻¹) := + Matrix.vecMul_injective_iff_isUnit.2 ((Matrix.isUnit_iff_isUnit_det _).2 ((Matrix.isUnit_nonsing_inv_det_iff).2 hC)) + intro v w hvw + apply hCi; apply hR + simpa [hX, Matrix.vecMul_vecMul] using hvw + +/-- **Uniqueness.** With independent end rows, the V mix is unique. -/ +theorem vmixM_unique (X R : Matrix G ι K) (hX : LinearIndependent K X.row) + (C C' : Matrix G G K) (h : C * X = R) (h' : C' * X = R) : C = C' := by + rw [← Matrix.vecMul_injective_iff] at hX + ext g h0 + have : Matrix.vecMul (C g) X = Matrix.vecMul (C' g) X := by + have e1 : (C * X).row g = Matrix.vecMul (C g) X := rfl + have e2 : (C' * X).row g = Matrix.vecMul (C' g) X := rfl + rw [← e1, ← e2, h, h'] + exact congrFun (hX this) h0 + +/-- **Token order affects only fill.** `vmixM_iff_span` (and `rank_law`) carry no order hypothesis: +existence of the V mix does not depend on any carrier/token order. An order only shapes `C`: +if the end rows are a block-triangular (w.r.t. the order `b`) invertible recombination of the +targets, the V mix is block-triangular, so it has no fill outside the triangle. -/ +theorem vmixM_fill {α : Type*} [LinearOrder α] (b : G → α) (X R : Matrix G ι K) + (Tg : Matrix G G K) (hT : Tg.BlockTriangular b) (hdet : IsUnit Tg.det) (hX : X = Tg * R) : + ∃ C : Matrix G G K, IsUnit C.det ∧ C * X = R ∧ C.BlockTriangular b := by + letI := Matrix.invertibleOfIsUnitDet Tg hdet + refine ⟨Tg⁻¹, (Matrix.isUnit_nonsing_inv_det_iff).2 hdet, ?_, + Matrix.blockTriangular_inv_of_blockTriangular hT⟩ + rw [hX, ← Matrix.mul_assoc, Matrix.nonsing_inv_mul _ hdet, Matrix.one_mul] + +/-- **Realisability by V-hub ops.** Every V mix factors into transvections (ADD i += c·j between +two V-enders), a diagonal with nonzero entries (SCALEs), and transvections. -/ +theorem vmix_ops (Cm : Matrix G G K) (hC : IsUnit Cm.det) : + ∃ (L L' : List (Matrix.TransvectionStruct G K)) (D : G → K), (∀ g, D g ≠ 0) ∧ + Cm = (L.map Matrix.TransvectionStruct.toMatrix).prod * Matrix.diagonal D * + (L'.map Matrix.TransvectionStruct.toMatrix).prod := by + obtain ⟨L, L', D, hM⟩ := Matrix.Pivot.exists_list_transvec_mul_diagonal_mul_list_transvec Cm + refine ⟨L, L', D, fun g hg => ?_, hM⟩ + have hdet : Cm.det = ∏ g, D g := by + rw [hM, Matrix.det_mul, Matrix.det_mul, Matrix.TransvectionStruct.det_toMatrix_prod, + Matrix.TransvectionStruct.det_toMatrix_prod, Matrix.det_diagonal]; simp + rw [hdet] at hC + exact hC.ne_zero (Finset.prod_eq_zero (Finset.mem_univ g) hg) + +end Mix + +section Run +open TokenCancel +variable {K Reg C : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] [DecidableEq C] + +/-- Span of the rows of a state. -/ +abbrev Sp (s : St K Reg C) : Submodule K (Reg → K) := span K (Set.range s.row) + +/-- Rows of the other registers. -/ +abbrev Oth (s : St K Reg C) (i : Reg) : Submodule K (Reg → K) := span K (s.row '' {r | r ≠ i}) + +theorem span_range_update (f : Reg → Reg → K) (i : Reg) (v : Reg → K) : + span K (Set.range (Function.update f i v)) = span K (f '' {r | r ≠ i}) ⊔ K ∙ v := by + have : Set.range (Function.update f i v) = f '' {r | r ≠ i} ∪ {v} := by + ext x; constructor + · rintro ⟨r, rfl⟩ + by_cases hr : r = i + · subst hr; simp + · left; exact ⟨r, hr, by simp [Function.update_of_ne hr]⟩ + · rintro (⟨r, hr, rfl⟩ | hx) + · exact ⟨r, by simp [Function.update_of_ne (show r ≠ i from hr)]⟩ + · rw [Set.mem_singleton_iff] at hx; exact ⟨i, by simp [hx]⟩ + rw [this, span_union] + +theorem span_range_eq (f : Reg → Reg → K) (i : Reg) : + span K (Set.range f) = span K (f '' {r | r ≠ i}) ⊔ K ∙ f i := by + conv_lhs => rw [show f = Function.update f i (f i) by simp] + exact span_range_update f i (f i) + +theorem sup_singleton_add (S : Submodule K (Reg → K)) (x w : Reg → K) (hw : w ∈ S) : + S ⊔ K ∙ (x + w) = S ⊔ K ∙ x := by + apply le_antisymm + · refine sup_le le_sup_left ((span_singleton_le_iff_mem _ _).2 ?_) + exact add_mem (mem_sup_right (mem_span_singleton_self x)) (mem_sup_left hw) + · refine sup_le le_sup_left ((span_singleton_le_iff_mem _ _).2 ?_) + have h := sub_mem (mem_sup_right (mem_span_singleton_self (x + w)) : x + w ∈ S ⊔ K ∙ (x + w)) + (mem_sup_left hw : w ∈ S ⊔ K ∙ (x + w)) + simpa using h + +/-- A loss of rank: CLEAR or COPY (onto a different source) of a row that is not in the span of +the other rows at that instant. -/ +def Lossy (s : St K Reg C) : Ev K Reg C → Prop + | .clear i _ => s.row i ∉ Oth s i + | .copy i j _ => i ≠ j ∧ s.row i ∉ Oth s i + | _ => False + +/-- A loss somewhere along the run. -/ +def Loss : St K Reg C → List (Ev K Reg C) → Prop + | _, [] => False + | s, e :: es => Lossy s e ∨ Loss (step s e) es + +/-- Every SCALE factor is nonzero (a SCALE by 0 is a CLEAR). -/ +def NZ : Ev K Reg C → Prop + | .scale _ u _ => u ≠ 0 + | _ => True + +/-- Tokens: registers present at the start plus registers born so far. -/ +def tokStep (T : Finset Reg) : Ev K Reg C → Finset Reg + | .born i _ => insert i T + | _ => T + +def tokRun (T : Finset Reg) : List (Ev K Reg C) → Finset Reg + | [] => T + | e :: es => tokRun (tokStep T e) es + +/-- Token span. -/ +abbrev TS (T : Finset Reg) : Submodule K (Reg → K) := + span K ((fun r => (Pi.single r (1 : K) : Reg → K)) '' (T : Set Reg)) + +theorem finrank_TS (T : Finset Reg) : finrank K (TS (K := K) T) = T.card := by + let b : T → Reg → K := fun r => Pi.single (r : Reg) (1 : K) + have hb : LinearIndependent K b := by + have := (Pi.basisFun K Reg).linearIndependent.comp (Subtype.val : T → Reg) Subtype.val_injective + convert this using 1; funext r; simp [b, Pi.basisFun_apply] + have hr : Set.range b = (fun r => (Pi.single r (1 : K) : Reg → K)) '' (T : Set Reg) := by + ext x; simp [b] + have := finrank_span_eq_card hb + rw [hr] at this + rw [this, Fintype.card_coe] + +variable (z V : C) + +/-- Bookkeeping invariant: absent registers have row 0; tokens are present registers. -/ +def Good (s : St K Reg C) (T : Finset Reg) : Prop := + (∀ r, s.loc r = none → s.row r = 0) ∧ (∀ r ∈ T, s.loc r ≠ none) + +theorem good_step (s : St K Reg C) (T : Finset Reg) (e : Ev K Reg C) + (hL : LegalEv z V s e) (hG : Good s T) : Good (step s e) (tokStep T e) := by + obtain ⟨h1, h2⟩ := hG + cases e with + | born i c => + refine ⟨fun r hr => ?_, fun r hr => ?_⟩ + · by_cases hri : r = i + · subst hri; simp [step] at hr + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact h1 r hr + · by_cases hri : r = i + · subst hri; simp [step] + · simp only [tokStep, Finset.mem_insert, hri, false_or] at hr + simp only [step, Function.update_of_ne hri]; exact h2 r hr + | init i c => + refine ⟨fun r hr => ?_, fun r hr => ?_⟩ + · by_cases hri : r = i + · subst hri; simp [step] + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact h1 r hr + · by_cases hri : r = i + · subst hri; simp [step] + · simp only [step, Function.update_of_ne hri]; exact h2 r hr + | move i c => + refine ⟨fun r hr => ?_, fun r hr => ?_⟩ + · by_cases hri : r = i + · subst hri; simp [step] at hr + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact h1 r hr + · by_cases hri : r = i + · subst hri; simp [step] + · simp only [step, Function.update_of_ne hri]; exact h2 r hr + | add i j a c => + obtain ⟨-, hi, -⟩ := hL + refine ⟨fun r hr => ?_, h2⟩ + by_cases hri : r = i + · subst hri; simp [step, hi] at hr + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact h1 r hr + | scale i u c => + have hi : s.loc i = some c := hL + refine ⟨fun r hr => ?_, h2⟩ + by_cases hri : r = i + · subst hri; simp only [step] at hr; rw [hi] at hr; exact absurd hr (by simp) + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact h1 r hr + | clear i c => + refine ⟨fun r hr => ?_, h2⟩ + by_cases hri : r = i + · subst hri; simp [step] + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact h1 r hr + | copy i j c => + obtain ⟨hi, -⟩ := hL + refine ⟨fun r hr => ?_, h2⟩ + by_cases hri : r = i + · subst hri; simp [step, hi] at hr + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact h1 r hr + +theorem Sp_eq_oth (s : St K Reg C) (i : Reg) : Sp s = Oth s i ⊔ K ∙ s.row i := + span_range_eq s.row i + +theorem Sp_update (s : St K Reg C) (i : Reg) (v : Reg → K) (l : Reg → Option C) : + Sp (⟨Function.update s.row i v, l⟩ : St K Reg C) = Oth s i ⊔ K ∙ v := + span_range_update s.row i v + +theorem mem_oth (s : St K Reg C) {i j : Reg} (h : j ≠ i) : s.row j ∈ Oth s i := + subset_span ⟨j, h, rfl⟩ + +/-- **Only CLEAR (and COPY) can lose rank.** Every non-birth op keeps the row span inside the +old one. -/ +theorem Sp_step_le (s : St K Reg C) (T : Finset Reg) (e : Ev K Reg C) (hb : ∀ i c, e ≠ .born i c) + (hL : LegalEv z V s e) (hG : Good s T) : Sp (step s e) ≤ Sp s := by + cases e with + | born i c => exact absurd rfl (hb i c) + | init i c => + have h0 : s.row i = 0 := hG.1 i hL + simp only [step]; rw [Sp_update, Sp_eq_oth s i, h0] + | move i c => exact le_rfl + | add i j a c => + simp only [step]; rw [Sp_update, Sp_eq_oth s i, + sup_singleton_add _ _ _ (smul_mem _ _ (mem_oth s (Ne.symm hL.1)))] + | scale i u c => + simp only [step]; rw [Sp_update, Sp_eq_oth s i] + exact sup_le_sup_left ((span_singleton_le_iff_mem _ _).2 + (smul_mem _ _ (mem_span_singleton_self _))) _ + | clear i c => + simp only [step]; rw [Sp_update, Sp_eq_oth s i, span_singleton_eq_bot.2 rfl, sup_bot_eq] + exact le_sup_left + | copy i j c => + simp only [step]; rw [Sp_update, Sp_eq_oth s i] + by_cases hij : j = i + · subst hij; exact le_rfl + · exact sup_le le_sup_left (le_trans ((span_singleton_le_iff_mem _ _).2 (mem_oth s hij)) + le_sup_left) + +theorem TS_insert (T : Finset Reg) (i : Reg) : + TS (K := K) (insert i T) = TS (K := K) T ⊔ K ∙ (Pi.single i (1 : K) : Reg → K) := by + simp only [TS, Finset.coe_insert, Set.image_insert_eq, span_insert]; exact sup_comm _ _ + +/-- A non-lossy step keeps the row span equal to the token span (SCALE factors nonzero). -/ +theorem Sp_step_noloss (s : St K Reg C) (T : Finset Reg) (e : Ev K Reg C) + (hL : LegalEv z V s e) (hN : NZ e) (hG : Good s T) (hS : Sp s = TS T) (hl : ¬ Lossy s e) : + Sp (step s e) = TS (tokStep T e) := by + cases e with + | born i c => + have h0 : s.row i = 0 := hG.1 i hL + have : Sp s = Oth s i := by rw [Sp_eq_oth s i, h0, span_singleton_eq_bot.2 rfl, sup_bot_eq] + simp only [step, tokStep]; rw [Sp_update, TS_insert, ← hS, this] + | init i c => + have h0 : s.row i = 0 := hG.1 i hL + simp only [step, tokStep]; rw [Sp_update, ← hS, Sp_eq_oth s i, h0] + | move i c => exact hS + | add i j a c => + simp only [step, tokStep]; rw [Sp_update, ← hS, Sp_eq_oth s i, + sup_singleton_add _ _ _ (smul_mem _ _ (mem_oth s (Ne.symm hL.1)))] + | scale i u c => + simp only [step, tokStep]; rw [Sp_update, ← hS, Sp_eq_oth s i, + span_singleton_smul_eq (IsUnit.mk0 _ hN)] + | clear i c => + have hm : s.row i ∈ Oth s i := not_not.1 hl + simp only [step, tokStep]; rw [Sp_update, ← hS, Sp_eq_oth s i, span_singleton_eq_bot.2 rfl, + sup_bot_eq, sup_eq_left.2 ((span_singleton_le_iff_mem _ _).2 hm)] + | copy i j c => + simp only [step, tokStep] + by_cases hij : j = i + · subst hij; simpa using hS + · have hm : s.row i ∈ Oth s i := by + by_contra h; exact hl ⟨Ne.symm hij, h⟩ + rw [Sp_update, ← hS, Sp_eq_oth s i, sup_eq_left.2 ((span_singleton_le_iff_mem _ _).2 hm), + sup_eq_left.2 ((span_singleton_le_iff_mem _ _).2 (mem_oth s hij))] + +open Classical in +/-- Rank bookkeeping for one step: rank + tokens never gains, and a lossy step loses one. -/ +theorem rank_step (s : St K Reg C) (T : Finset Reg) (e : Ev K Reg C) + (hL : LegalEv z V s e) (hG : Good s T) : + finrank K (Sp (step s e)) + T.card + (if Lossy s e then 1 else 0) ≤ + finrank K (Sp s) + (tokStep T e).card := by + classical + by_cases hb : ∃ i c, e = .born i c + · obtain ⟨i, c, rfl⟩ := hb + have hloc : s.loc i = none := hL + have h0 : s.row i = 0 := hG.1 i hloc + have hiT : i ∉ T := fun h => hG.2 i h hloc + have hl : ¬ Lossy s (.born i c : Ev K Reg C) := id + simp only [hl, if_false, add_zero, tokStep, Finset.card_insert_of_notMem hiT] + have hS : Sp s = Oth s i := by rw [Sp_eq_oth s i, h0, span_singleton_eq_bot.2 rfl, sup_bot_eq] + have hE : Sp (step s (.born i c)) = Oth s i ⊔ K ∙ (Pi.single i (1:K) : Reg → K) := by + simp only [step]; rw [Sp_update] + have e1 := congrArg (fun S : Submodule K (Reg → K) => finrank K S) hE + have e2 := congrArg (fun S : Submodule K (Reg → K) => finrank K S) hS + have := Submodule.finrank_add_le_finrank_add_finrank (Oth s i) (K ∙ (Pi.single i (1:K) : Reg → K)) + have hv : (Pi.single i (1:K) : Reg → K) ≠ 0 := fun h => by simpa using congrFun h i + have h1 := finrank_span_singleton (K := K) hv + omega + · push Not at hb + have hle := Sp_step_le z V s T e hb hL hG + have hT : tokStep T e = T := by cases e <;> simp_all [tokStep] + rw [hT] + by_cases hl : Lossy s e + · simp only [hl, if_true] + have hlt : Sp (step s e) < Sp s := by + refine lt_of_le_of_ne hle (fun heq => ?_) + cases e with + | clear i c => + apply hl + have : s.row i ∈ Sp s := subset_span ⟨i, rfl⟩ + rw [← heq] at this; simp only [step] at this + rw [Sp_update, span_singleton_eq_bot.2 rfl, sup_bot_eq] at this; exact this + | copy i j c => + apply hl.2 + have : s.row i ∈ Sp s := subset_span ⟨i, rfl⟩ + rw [← heq] at this; simp only [step] at this + rwa [Sp_update, sup_eq_left.2 ((span_singleton_le_iff_mem _ _).2 (mem_oth s hl.1.symm))] + at this + | _ => exact hl.elim + have := Submodule.finrank_lt_finrank_of_lt hlt + omega + · simp only [hl, if_false] + have := Submodule.finrank_mono hle + omega + +/-- No loss along a legal run (SCALE factors nonzero): the final row span is the token span. -/ +theorem span_run (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (hl : ¬ Loss s evs) : Sp (run s evs) = TS (tokRun T evs) := by + induction evs generalizing s T with + | nil => exact hS + | cons e es ih => + simp only [Loss, not_or] at hl + exact ih (step s e) (tokStep T e) hL.2 (fun e' he' => hN e' (List.mem_cons_of_mem _ he')) + (good_step z V s T e hL.1 hG) + (Sp_step_noloss z V s T e hL.1 (hN e List.mem_cons_self) hG hS hl.1) hl.2 + +/-- Rank bookkeeping along a legal run: any slack m is kept, and a loss adds one more unit. -/ +theorem rank_run (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hG : Good s T) (m : ℕ) (hm : finrank K (Sp s) + m ≤ T.card) : + finrank K (Sp (run s evs)) + m ≤ (tokRun T evs).card ∧ + (Loss s evs → finrank K (Sp (run s evs)) + m + 1 ≤ (tokRun T evs).card) := by + induction evs generalizing s T m with + | nil => exact ⟨hm, fun h => h.elim⟩ + | cons e es ih => + simp only [run, tokRun] + have hst := rank_step z V s T e hL.1 hG + have hG' := good_step z V s T e hL.1 hG + by_cases hl : Lossy s e + · simp only [hl, if_true] at hst + have := (ih (step s e) (tokStep T e) hL.2 hG' (m + 1) (by omega)).1 + exact ⟨le_trans (Nat.le_succ _) this, fun _ => this⟩ + · simp only [hl, if_false, add_zero] at hst + have := ih (step s e) (tokStep T e) hL.2 hG' m (by omega) + refine ⟨this.1, fun hlo => ?_⟩ + simp only [Loss, hl, false_or] at hlo + exact this.2 hlo + +/-- **Rank is lost exactly at lossy CLEAR/COPY.** For a legal run from a state whose rows span its +tokens (all SCALE factors nonzero), the final row span equals the final token span iff the run +contains no lossy event. -/ +theorem full_rank_iff_noloss (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) : + Sp (run s evs) = TS (tokRun T evs) ↔ ¬ Loss s evs := by + refine ⟨fun h hl => ?_, span_run z V s T evs hL hN hG hS⟩ + have h0 : finrank K (Sp s) + 0 ≤ T.card := by + rw [hS, finrank_TS]; simp + have := (rank_run z V s T evs hL hG 0 h0).2 hl + have e := congrArg (fun S : Submodule K (Reg → K) => finrank K S) h + rw [e, finrank_TS] at this + omega + +/-- Cancellation: two subspaces of `U` with the same sum against a complement-to-`U` piece agree. -/ +theorem eq_of_sup_eq {M : Type*} [AddCommGroup M] [Module K M] (A B N U : Submodule K M) + (hA : A ≤ U) (hB : B ≤ U) (hUN : U ⊓ N = ⊥) (h : A ⊔ N = B ⊔ N) : A = B := by + have key : ∀ A B : Submodule K M, A ≤ U → B ≤ U → A ⊔ N = B ⊔ N → A ≤ B := by + intro A B hA hB h x hx + have : x ∈ B ⊔ N := h ▸ mem_sup_left hx + obtain ⟨b, hb, n, hn, rfl⟩ := mem_sup.1 this + have hnU : n ∈ U := by + have := sub_mem (hA hx) (hB hb); simpa using this + have : n ∈ U ⊓ N := ⟨hnU, hn⟩ + rw [hUN, mem_bot] at this; subst this; simpa using hb + exact le_antisymm (key A B hA hB h) (key B A hB hA h.symm) + +theorem span_range_split (f : Reg → Reg → K) (G1 : Finset Reg) : + span K (Set.range f) = span K (f '' (G1 : Set Reg)) ⊔ span K (f '' (G1 : Set Reg)ᶜ) := by + rw [← span_union, ← Set.image_union, Set.union_compl_self, Set.image_univ] + +theorem range_restrict (f : Reg → Reg → K) (G1 : Finset Reg) : + Set.range (Matrix.of fun g : G1 => f g).row = f '' (G1 : Set Reg) := by + ext x; constructor + · rintro ⟨g, rfl⟩; exact ⟨g, g.2, rfl⟩ + · rintro ⟨g, hg, rfl⟩; exact ⟨⟨g, hg⟩, rfl⟩ + +/-- The V mix of a run: an invertible `C` over the registers `G1` that end at V with +`C · X[G1] = Rf[G1]`, where `X` are the end rows of the run (all V-hub ops deleted). -/ +def VMix (X Rf : Reg → Reg → K) (G1 : Finset Reg) : Prop := + VMixM (Matrix.of fun g : G1 => X g) (Matrix.of fun g : G1 => Rf g) + +/-- **RANK law (internal notes).** Run a legal word (V-hub ops deleted, SCALE factors +nonzero) from a state whose rows span its tokens. Let `G1` end at V; assume every other register +already ends at its target (`hNon`), and the target end state has full token rank (`hTgt`). +Let `U` be the "zero-W0" subspace (T_X + tokens): it contains the V targets (`hRU`) and meets the +span of the non-V targets only in 0 (`hUN`). Then a V mix exists iff +(i) no CLEAR/COPY loses rank and (ii) every V-ender row lies in `U`. -/ +theorem rank_law (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (Rf : Reg → Reg → K) (G1 : Finset Reg) (U : Submodule K (Reg → K)) + (hNon : ∀ r ∉ G1, (run s evs).row r = Rf r) + (hTgt : span K (Set.range Rf) = TS (tokRun T evs)) + (hRU : ∀ g ∈ G1, Rf g ∈ U) + (hUN : U ⊓ span K (Rf '' (G1 : Set Reg)ᶜ) = ⊥) : + VMix (run s evs).row Rf G1 ↔ ¬ Loss s evs ∧ ∀ g ∈ G1, (run s evs).row g ∈ U := by + set X := (run s evs).row with hXdef + have hNim : X '' (G1 : Set Reg)ᶜ = Rf '' (G1 : Set Reg)ᶜ := + Set.image_congr (fun r hr => hNon r (by simpa using hr)) + have hBU : span K (Rf '' (G1 : Set Reg)) ≤ U := + span_le.2 (by rintro _ ⟨g, hg, rfl⟩; exact hRU g hg) + unfold VMix + rw [vmixM_iff_span, range_restrict, range_restrict] + constructor + · intro hAB + have hfull : Sp (run s evs) = TS (tokRun T evs) := by + rw [← hTgt, Sp, ← hXdef, span_range_split X G1, span_range_split Rf G1, hAB, hNim] + refine ⟨(full_rank_iff_noloss z V s T evs hL hN hG hS).1 hfull, fun g hg => ?_⟩ + exact hBU (hAB ▸ subset_span ⟨g, hg, rfl⟩) + · rintro ⟨hl, hU⟩ + have hfull := span_run z V s T evs hL hN hG hS hl + have hsum : span K (X '' (G1 : Set Reg)) ⊔ span K (Rf '' (G1 : Set Reg)ᶜ) = + span K (Rf '' (G1 : Set Reg)) ⊔ span K (Rf '' (G1 : Set Reg)ᶜ) := by + rw [← hNim, ← span_range_split X G1, hNim, ← span_range_split Rf G1, hTgt]; exact hfull + exact eq_of_sup_eq _ _ _ U (span_le.2 (by rintro _ ⟨g, hg, rfl⟩; exact hU g hg)) hBU hUN hsum + +/-- ADD and SCALE (nonzero) are invertible ops: an inverse op restores the state exactly. -/ +theorem add_inverse (s : St K Reg C) (i j : Reg) (a : K) (c : C) (hij : i ≠ j) : + step (step s (.add i j a c)) (.add i j (-a) c) = s := by + obtain ⟨row, loc⟩ := s + simp only [step, St.mk.injEq, and_true] + funext r; by_cases hr : r = i + · subst hr; simp [Function.update_of_ne (Ne.symm hij)] + · simp [Function.update_of_ne hr] + +theorem scale_inverse (s : St K Reg C) (i : Reg) (u : K) (c : C) (hu : u ≠ 0) : + step (step s (.scale i u c)) (.scale i u⁻¹ c) = s := by + obtain ⟨row, loc⟩ := s + simp only [step, St.mk.injEq, and_true] + funext r; by_cases hr : r = i + · subst hr; simp [smul_smul, inv_mul_cancel₀ hu] + · simp [Function.update_of_ne hr] + +/-- The canonical start: present registers carry their own coordinate, absent ones 0. -/ +def start (l : Reg → Option C) : St K Reg C := + ⟨fun r => if l r = none then 0 else Pi.single r 1, l⟩ + +def startTok (l : Reg → Option C) : Finset Reg := Finset.univ.filter fun r => l r ≠ none + +theorem start_good (l : Reg → Option C) : Good (start (K := K) l) (startTok l) := + ⟨fun r hr => by simp only [start] at hr ⊢; simp [hr], fun r hr => by simpa [start, startTok] using hr⟩ + +theorem start_span (l : Reg → Option C) : Sp (start (K := K) l) = TS (startTok l) := by + apply le_antisymm + · refine span_le.2 ?_ + rintro _ ⟨r, rfl⟩ + by_cases hr : l r = none + · simp [start, hr] + · simp only [start, hr, if_false] + exact subset_span ⟨r, by simpa [startTok] using hr, rfl⟩ + · refine span_le.2 ?_ + rintro _ ⟨r, hr, rfl⟩ + have hr' : l r ≠ none := by simpa [startTok] using hr + exact subset_span ⟨r, by simp [start, hr']⟩ + +/-- **Finding: COPY is not invertible either.** The prose lists CLEAR as the only rank-losing op; +in the op model with COPY (i := j's row), COPY onto a row outside the others' span loses rank. -/ +theorem copy_lossy_example : + Lossy (start (K := ℚ) (C := Unit) (fun _ : Fin 2 => some ())) (.copy 0 1 ()) := by + refine ⟨by decide, fun h => ?_⟩ + have himg : (start (K := ℚ) (C := Unit) (fun _ : Fin 2 => some ())).row '' {r | r ≠ 0} = + {Pi.single 1 1} := by + ext x; simp only [Set.mem_image, Set.mem_ofPred_eq, Set.mem_singleton_iff, start] + constructor + · rintro ⟨r, hr, rfl⟩ + have : r = 1 := by fin_cases r <;> simp_all + subst this; simp + · rintro rfl; exact ⟨1, by decide, by simp⟩ + rw [Oth, himg, mem_span_singleton] at h + obtain ⟨a, ha⟩ := h + have := congrFun ha 0 + simp [start] at this + +end Run + +end RankLaw + +#print axioms RankLaw.rank_law +#print axioms RankLaw.full_rank_iff_noloss +#print axioms RankLaw.vmixM_iff_span +#print axioms RankLaw.vmixM_fill +#print axioms RankLaw.vmix_ops +#print axioms RankLaw.vmixM_unique +#print axioms RankLaw.vmixM_indep +#print axioms RankLaw.copy_lossy_example +#print axioms RankLaw.add_inverse +#print axioms RankLaw.scale_inverse +#print axioms RankLaw.start_span diff --git a/research/p104-native-ceiling/lean/Nov15/RankLaw.md b/research/p104-native-ceiling/lean/Nov15/RankLaw.md new file mode 100644 index 0000000000..fbd610a6ce --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/RankLaw.md @@ -0,0 +1,48 @@ +# RankLaw.lean: rebuild's RANK law (RESULT §7, internal log CORE r2). No sorry, ~7 s, 2.2 GB RSS +Source: internal notes §7 and the CORE r2 line in internal log.md. +Axioms: [propext, Classical.choice, Quot.sound]. + +Build (imports the TokenCancel olean): + lake env lean -o .lake/build/lib/lean/Nov15/TokenCancel.olean Nov15/TokenCancel.lean + lake env lean -o .lake/build/lib/lean/Nov15/RankLaw.olean Nov15/RankLaw.lean + +**Model.** TokenCancel's op model and legality (born/init/move/add/scale/clear/copy, co-presence; z, V arbitrary). +- Tokens = registers present at the start plus births so far (`tokRun`). Token span `TS T` = span of the e_r, r ∈ T, with `finrank_TS` = |T|. +- `Good`: absent registers have row 0 and tokens are present. `start l` (own coordinate if present, 0 if absent) satisfies `Good`, and its rows span its tokens (`start_good`, `start_span`). +- `Lossy s e`: a CLEAR of i, or a COPY into i from j ≠ i, while row i ∉ span(other rows) at that instant. `Loss` = some lossy event in the run. `NZ`: SCALE factor ≠ 0. + +**The V-mix target (a linear system).** `VMixM X R` := ∃ C, det C a unit, C·X = R. X = end rows of the V-enders G1 after a run with the V-hub ops deleted, R = their targets. +- `vmixM_iff_span`: solvable iff rowspan X = rowspan R. Built on `exists_equiv_comp`: two maps with equal range differ by an automorphism. +- `vmix_ops`: every such C is a product transvections · diag(D) · transvections with all D ≠ 0, i.e. V-hub ADDs and nonzero SCALEs (Mathlib Pivot). +- `vmixM_indep`: independent targets imply independent end rows. `vmixM_unique`: independent end rows make C unique. + +**Only CLEAR (and COPY) lose rank.** +- `add_inverse` and `scale_inverse` (u ≠ 0): the inverse op restores the state exactly. +- `Sp_step_le`: no non-birth op enlarges the row span. +- `rank_step`, `rank_run`: (row rank) + (slack) never exceeds |tokens|, and a lossy step costs one unit for good. +- `span_run`: with no loss, end row span = token span. +- `full_rank_iff_noloss`: end row span = token span ⟺ no lossy CLEAR/COPY. + +**`rank_law` (the iff).** Assume: +- a legal run with NZ, from a state whose rows span its tokens; +- non-V registers already end on their targets (`hNon`); +- the target end state spans the final tokens (`hTgt`; true when the target is the end of any loss-free legal word with the same births, by `span_run`); +- U ⊇ V targets (`hRU`), and U ∩ span(non-V targets) = 0 (`hUN`). + +Then: V mix exists ⟺ (i) no lossy CLEAR/COPY and (ii) every V-ender end row ∈ U. + +**Token order** (`vmixM_fill` + the shape of `rank_law`). +- Neither existence statement has an order hypothesis, so correctness never depends on the LATE order. +- An order b only shapes C: if X = T·R with T block-triangular for b and invertible, then the V mix C = T⁻¹ is block-triangular. No fill outside the triangle. + +**Findings (prose statements false or underspecified as written).** +1. **"Every op except CLEAR is invertible" is false with COPY.** `copy_lossy_example` (over ℚ, 2 registers): COPY 0←1 is lossy. + - Also SCALE by 0 is a CLEAR. + - Minimal fix: "every op except CLEAR, COPY-over-a-live-row and SCALE 0", or treat COPY as CLEAR + ADD. The law then holds verbatim with Lossy covering COPY. + - #7623 behaviour is unaffected if its words contain no such COPY. Not checked here. +2. **(ii) "zero W0 part" is only the right criterion relative to a U that meets the span of the non-V targets trivially (`hUN`).** Without that, the iff fails. + - Hand example: G1 = {g}, N = {n}, Rf g = e1, Rf n = e2, U = everything, X g = e1 + e2. There is no loss and X g ∈ U, but X g ∉ span{e1}. + - The "only if" of (i) also needs `hTgt`, the target state's full token rank. +3. "The V mix is unique" needs independent end rows. rank X[G1] = |G1| was checked [C] on #7623. + +**Scope.** "Owned" is not used; the law holds for any register. The W0/T_X split enters only through U. diff --git a/research/p104-native-ceiling/lean/Nov15/RankLawC.lean b/research/p104-native-ceiling/lean/Nov15/RankLawC.lean new file mode 100644 index 0000000000..5c72771505 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/RankLawC.lean @@ -0,0 +1,167 @@ +/- +RankLaw (c) fix, See RankLawC.md. + +`rank_law` needs U ⊓ span(non-V targets) = ⊥. This file drops that hypothesis: +* `rank_law_gen`: with no U at all, V mix ⟺ no loss ∧ every V-ender row ∈ B ∧ B ⊓ N ≤ A + (B = span V targets, N = span non-V targets, A = span V-ender rows). +* `rank_law_proj`: for any U ⊇ B and any linear π vanishing on B and injective on U ⊓ N, + condition (ii) becomes "row ∈ U and π(row) = 0" (the (U ⊓ N)-component vanishes). +* `rank_law_indep`: if B ⊓ N = ⊥ (independent targets) the third clause disappears. +* `rank_law_of_gen`: the original `rank_law` is the case π = 0. + +Build (imports the RankLaw olean, itself built on TokenCancel): + lake env lean -o .lake/build/lib/lean/Nov15/TokenCancel.olean Nov15/TokenCancel.lean + lake env lean -o .lake/build/lib/lean/Nov15/RankLaw.olean Nov15/RankLaw.lean + lake env lean -o .lake/build/lib/lean/Nov15/RankLawC.olean Nov15/RankLawC.lean +-/ +import Nov15.RankLaw + +set_option linter.unusedSectionVars false + +namespace RankLawC +open Submodule Module TokenCancel RankLaw + +section Lat +variable {K M : Type*} [Field K] [AddCommGroup M] [Module K M] + +/-- Cancellation without a complement: given A ⊔ N = B ⊔ N, A = B iff A ≤ B and B ⊓ N ≤ A. -/ +theorem eq_iff_of_sup_eq (A B N : Submodule K M) (h : A ⊔ N = B ⊔ N) : + A = B ↔ A ≤ B ∧ B ⊓ N ≤ A := by + constructor + · rintro rfl; exact ⟨le_rfl, inf_le_left⟩ + · rintro ⟨hAB, hBN⟩ + refine le_antisymm hAB fun b hb => ?_ + have : b ∈ A ⊔ N := h ▸ mem_sup_left hb + obtain ⟨a, ha, n, hn, rfl⟩ := mem_sup.1 this + have hnB : n ∈ B := by + have := sub_mem hb (hAB ha); simpa using this + exact add_mem ha (hBN ⟨hnB, hn⟩) + +/-- The (U ⊓ N)-component test: if B ≤ U, x ∈ U ⊓ (B ⊔ N), π vanishes on B and is injective on U ⊓ N, +then x ∈ B ⟺ π x = 0. -/ +theorem mem_iff_proj {M' : Type*} [AddCommGroup M'] [Module K M'] (B N U : Submodule K M) + (π : M →ₗ[K] M') (hBU : B ≤ U) (hπB : ∀ b ∈ B, π b = 0) + (hπ : LinearMap.ker π ⊓ (U ⊓ N) = ⊥) (x : M) (hxU : x ∈ U) (hx : x ∈ B ⊔ N) : + x ∈ B ↔ π x = 0 := by + refine ⟨hπB x, fun h0 => ?_⟩ + obtain ⟨b, hb, n, hn, rfl⟩ := mem_sup.1 hx + have hnU : n ∈ U := by + have := sub_mem hxU (hBU hb); simpa using this + have hπn : π n = 0 := by rw [map_add, hπB b hb, zero_add] at h0; exact h0 + have : n ∈ LinearMap.ker π ⊓ (U ⊓ N) := ⟨hπn, hnU, hn⟩ + rw [hπ, mem_bot] at this + subst this; simpa using hb + +end Lat + +section Run +variable {K Reg C : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] [DecidableEq C] +variable (z V : C) + +/-- With no loss (and the RankLaw hypotheses), A ⊔ N = B ⊔ N. -/ +theorem sup_eq_of_noloss (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (Rf : Reg → Reg → K) (G1 : Finset Reg) + (hNon : ∀ r ∉ G1, (run s evs).row r = Rf r) + (hTgt : span K (Set.range Rf) = TS (tokRun T evs)) (hl : ¬ Loss s evs) : + span K ((run s evs).row '' (G1 : Set Reg)) ⊔ span K (Rf '' (G1 : Set Reg)ᶜ) = + span K (Rf '' (G1 : Set Reg)) ⊔ span K (Rf '' (G1 : Set Reg)ᶜ) := by + set X := (run s evs).row with hXdef + have hNim : X '' (G1 : Set Reg)ᶜ = Rf '' (G1 : Set Reg)ᶜ := + Set.image_congr (fun r hr => hNon r (by simpa using hr)) + have hfull := span_run z V s T evs hL hN hG hS hl + rw [← hNim, ← span_range_split X G1, hNim, ← span_range_split Rf G1, hTgt]; exact hfull + +/-- **RankLaw, general form (no U).** Same hypotheses as `RankLaw.rank_law` minus `hRU`/`hUN`. +B = span V targets, N = span non-V targets, A = span V-ender end rows. -/ +theorem rank_law_gen (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (Rf : Reg → Reg → K) (G1 : Finset Reg) + (hNon : ∀ r ∉ G1, (run s evs).row r = Rf r) + (hTgt : span K (Set.range Rf) = TS (tokRun T evs)) : + VMix (run s evs).row Rf G1 ↔ ¬ Loss s evs ∧ + (∀ g ∈ G1, (run s evs).row g ∈ span K (Rf '' (G1 : Set Reg))) ∧ + span K (Rf '' (G1 : Set Reg)) ⊓ span K (Rf '' (G1 : Set Reg)ᶜ) ≤ + span K ((run s evs).row '' (G1 : Set Reg)) := by + set X := (run s evs).row with hXdef + have hNim : X '' (G1 : Set Reg)ᶜ = Rf '' (G1 : Set Reg)ᶜ := + Set.image_congr (fun r hr => hNon r (by simpa using hr)) + unfold VMix + rw [vmixM_iff_span, range_restrict, range_restrict] + have hAle : (∀ g ∈ G1, X g ∈ span K (Rf '' (G1 : Set Reg))) ↔ + span K (X '' (G1 : Set Reg)) ≤ span K (Rf '' (G1 : Set Reg)) := + ⟨fun h => span_le.2 (by rintro _ ⟨g, hg, rfl⟩; exact h g hg), + fun h g hg => h (subset_span ⟨g, hg, rfl⟩)⟩ + constructor + · intro hAB + have hfull : Sp (run s evs) = TS (tokRun T evs) := by + rw [← hTgt, Sp, ← hXdef, span_range_split X G1, span_range_split Rf G1, hAB, hNim] + refine ⟨(full_rank_iff_noloss z V s T evs hL hN hG hS).1 hfull, hAle.2 hAB.le, ?_⟩ + rw [hAB]; exact inf_le_left + · rintro ⟨hl, hB, hBN⟩ + have hsum := sup_eq_of_noloss z V s T evs hL hN hG hS Rf G1 hNon hTgt hl + exact (eq_iff_of_sup_eq _ _ _ hsum).2 ⟨hAle.1 hB, hBN⟩ + +/-- **Corrected condition (ii) relative to an arbitrary U ⊇ V targets.** π is any linear map that +vanishes on the V targets and is injective on U ⊓ N (it reads the "(U ⊓ N)-component"). -/ +theorem rank_law_proj {M' : Type*} [AddCommGroup M'] [Module K M'] + (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (Rf : Reg → Reg → K) (G1 : Finset Reg) (U : Submodule K (Reg → K)) (π : (Reg → K) →ₗ[K] M') + (hNon : ∀ r ∉ G1, (run s evs).row r = Rf r) + (hTgt : span K (Set.range Rf) = TS (tokRun T evs)) + (hRU : ∀ g ∈ G1, Rf g ∈ U) (hπR : ∀ g ∈ G1, π (Rf g) = 0) + (hπ : LinearMap.ker π ⊓ (U ⊓ span K (Rf '' (G1 : Set Reg)ᶜ)) = ⊥) : + VMix (run s evs).row Rf G1 ↔ ¬ Loss s evs ∧ + (∀ g ∈ G1, (run s evs).row g ∈ U ∧ π ((run s evs).row g) = 0) ∧ + span K (Rf '' (G1 : Set Reg)) ⊓ span K (Rf '' (G1 : Set Reg)ᶜ) ≤ + span K ((run s evs).row '' (G1 : Set Reg)) := by + set B := span K (Rf '' (G1 : Set Reg)) + have hBU : B ≤ U := span_le.2 (by rintro _ ⟨g, hg, rfl⟩; exact hRU g hg) + have hπB : ∀ b ∈ B, π b = 0 := by + intro b hb + have : B ≤ LinearMap.ker π := span_le.2 (by rintro _ ⟨g, hg, rfl⟩; exact hπR g hg) + exact this hb + rw [rank_law_gen z V s T evs hL hN hG hS Rf G1 hNon hTgt] + constructor + · rintro ⟨hl, hB, h3⟩ + exact ⟨hl, fun g hg => ⟨hBU (hB g hg), hπB _ (hB g hg)⟩, h3⟩ + · rintro ⟨hl, hU, h3⟩ + have hsum := sup_eq_of_noloss z V s T evs hL hN hG hS Rf G1 hNon hTgt hl + refine ⟨hl, fun g hg => ?_, h3⟩ + have hx : (run s evs).row g ∈ B ⊔ span K (Rf '' (G1 : Set Reg)ᶜ) := + hsum ▸ mem_sup_left (subset_span ⟨g, hg, rfl⟩) + exact (mem_iff_proj B _ U π hBU hπB hπ _ (hU g hg).1 hx).2 (hU g hg).2 + +/-- Independent targets (B ⊓ N = ⊥; true on #7623, whose 1501 public target rows have rank 1501): +the third clause is vacuous, and (ii) is "every V-ender row lies in the span of the V targets". -/ +theorem rank_law_indep (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (Rf : Reg → Reg → K) (G1 : Finset Reg) + (hNon : ∀ r ∉ G1, (run s evs).row r = Rf r) + (hTgt : span K (Set.range Rf) = TS (tokRun T evs)) + (hBN : span K (Rf '' (G1 : Set Reg)) ⊓ span K (Rf '' (G1 : Set Reg)ᶜ) = ⊥) : + VMix (run s evs).row Rf G1 ↔ ¬ Loss s evs ∧ + ∀ g ∈ G1, (run s evs).row g ∈ span K (Rf '' (G1 : Set Reg)) := by + rw [rank_law_gen z V s T evs hL hN hG hS Rf G1 hNon hTgt, hBN] + simp + +/-- Consistency: the original `rank_law` (U ⊓ N = ⊥) is `rank_law_proj` with π = 0. -/ +theorem rank_law_of_gen (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (Rf : Reg → Reg → K) (G1 : Finset Reg) (U : Submodule K (Reg → K)) + (hNon : ∀ r ∉ G1, (run s evs).row r = Rf r) + (hTgt : span K (Set.range Rf) = TS (tokRun T evs)) + (hRU : ∀ g ∈ G1, Rf g ∈ U) + (hUN : U ⊓ span K (Rf '' (G1 : Set Reg)ᶜ) = ⊥) : + VMix (run s evs).row Rf G1 ↔ ¬ Loss s evs ∧ ∀ g ∈ G1, (run s evs).row g ∈ U := by + have hBU : span K (Rf '' (G1 : Set Reg)) ≤ U := + span_le.2 (by rintro _ ⟨g, hg, rfl⟩; exact hRU g hg) + have hBN : span K (Rf '' (G1 : Set Reg)) ⊓ span K (Rf '' (G1 : Set Reg)ᶜ) = ⊥ := + eq_bot_iff.2 (fun x hx => hUN ▸ ⟨hBU hx.1, hx.2⟩) + rw [rank_law_proj (M' := K) z V s T evs hL hN hG hS Rf G1 U 0 hNon hTgt hRU (by simp) + (by simp [hUN]), hBN] + simp + +end Run +end RankLawC diff --git a/research/p104-native-ceiling/lean/Nov15/RankLawC.md b/research/p104-native-ceiling/lean/Nov15/RankLawC.md new file mode 100644 index 0000000000..8559526b12 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/RankLawC.md @@ -0,0 +1,30 @@ +# RankLawC.lean: RankLaw condition (ii) when U meets span(non-V targets). No sorry, ~15 s, < 2.2 GB RSS +Imports the RankLaw olean (header has the build chain). Axioms: [propext, Classical.choice, Quot.sound]. + +Notation (end rows of the run with the V-hub ops deleted): +- X = those end rows; +- A = span X[G1]; +- B = span of the V targets Rf[G1]; +- N = span of the non-V targets. + +Hypotheses are those of `RankLaw.rank_law` (legal, NZ, Good, token span, hNon, hTgt), with no hUN. + +- `eq_iff_of_sup_eq`: if A ⊔ N = B ⊔ N, then A = B ⟺ A ≤ B ∧ B ⊓ N ≤ A. +- `rank_law_gen` (no U at all): V mix ⟺ (i) no lossy CLEAR/COPY ∧ (ii) every X g ∈ B ∧ (iii) B ⊓ N ≤ A. +- **`rank_law_proj` (the corrected (ii) for any U ⊇ B).** Let π be any linear map with π = 0 on the V targets and ker π ⊓ (U ⊓ N) = ⊥ (π reads the (U ⊓ N)-component). + Then V mix ⟺ (i) ∧ (ii') every X g ∈ U **and π(X g) = 0** ∧ (iii). + - So "zero W0 part" must be strengthened to "zero W0 part and zero (U ⊓ N)-component". +- `rank_law_indep`: if B ⊓ N = ⊥, (iii) is vacuous and (ii) reads "X g ∈ span V targets". + - This holds on #7623: the 1501 public target rows have rank 1501 (CopyCheck.md), and owned targets are 0. +- `rank_law_of_gen`: the original `rank_law` is `rank_law_proj` with π = 0. + - When U ⊓ N = ⊥, (iii) is automatic because B ⊓ N ≤ U ⊓ N = ⊥. + +Hand examples (why each extra clause is needed): +- **(ii').** RankLaw finding 2: G1 = {g}, N = {n}, Rf g = e1, Rf n = e2, U = everything, X g = e1 + e2. + - Here X g ∈ U but π(X g) ≠ 0 for π = e2-coordinate, and there is no V mix. +- **(iii).** One token e1; Rf g = Rf n = e1; X n = e1, X g = 0; empty run, so no loss. + - X g ∈ B, but A = 0 ≠ B. + - Only possible with dependent targets. + +**Finding.** RankLaw's prose "(ii) zero W0 part" is false when U ⊓ N ≠ 0, which is the natural case U = T_X + tokens: helper tokens e_h are non-V targets. +- Minimal fix: "(ii) every V-ender row is in U and has zero (U ⊓ N)-component"; with dependent targets, add (iii). diff --git a/research/p104-native-ceiling/lean/Nov15/RelaySandwich.lean b/research/p104-native-ceiling/lean/Nov15/RelaySandwich.lean new file mode 100644 index 0000000000..e3ad3667c8 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/RelaySandwich.lean @@ -0,0 +1,157 @@ +/- +RELAY-SANDWICH law (NEWNATIVE R4 sec 3), See RelaySandwich.md. +Abstract: charts form a lattice; resident i of a relay chart c arrives from chart p i and departs to n i +(p i ≤ c ≤ n i, public steps ascend). Pinned: c = ⨆ p = ⨅ n. Then any chart c' that keeps every +resident's route ascending equals c. Bridge to FrameSep.Route (frames = submodules) included. +Also the cost identity for a 0 -> e helper with k evenly spaced stops: e * ln (k+1) (e = 9: 9 ln (k+1)). +-/ +import Nov15.FrameSep +import Nov15.JunkLB2 + +namespace RelaySandwich + +section Lattice +variable {L ι : Type*} [CompleteLattice L] + +/-- c is pinned by residents with arrival charts p and departure charts n. -/ +structure Pinned (p n : ι → L) (c : L) : Prop where + arrive : ∀ i, p i ≤ c + depart : ∀ i, c ≤ n i + join : c = ⨆ i, p i + meet : c = ⨅ i, n i + +/-- Admissible replacement of the stop: every resident's route stays ascending through c'. -/ +def Admissible (p n : ι → L) (c' : L) : Prop := ∀ i, p i ≤ c' ∧ c' ≤ n i + +/-- **RELAY-SANDWICH**: the only admissible stop chart is c itself. -/ +theorem admissible_unique {p n : ι → L} {c : L} (h : Pinned p n c) {c' : L} + (hc : Admissible p n c') : c' = c := by + apply le_antisymm + · rw [h.meet]; exact le_iInf fun i => (hc i).2 + · rw [h.join]; exact iSup_le fun i => (hc i).1 + +theorem admissible_iff {p n : ι → L} {c : L} (h : Pinned p n c) (c' : L) : + Admissible p n c' ↔ c' = c := + ⟨admissible_unique h, fun e => e ▸ fun i => ⟨h.arrive i, h.depart i⟩⟩ + +/-- Collapse onto a neighbour chart (some resident's previous or next chart d) is impossible +when no neighbour chart equals c. -/ +theorem no_neighbour_collapse {p n : ι → L} {c : L} (h : Pinned p n c) + (hp : ∀ i, p i ≠ c) (hn : ∀ i, n i ≠ c) (j : ι) : + ¬ Admissible p n (p j) ∧ ¬ Admissible p n (n j) := + ⟨fun a => hp j (admissible_unique h a), fun a => hn j (admissible_unique h a)⟩ + +/-- Non-degenerate pinned relay needs two residents (indeed no single resident's chart is c). -/ +theorem pinned_nontrivial {p n : ι → L} {c : L} (h : Pinned p n c) + (hp : ∀ i, p i ≠ c) [Nonempty ι] : ¬ Subsingleton ι := by + intro hs + obtain ⟨i⟩ := ‹Nonempty ι› + apply hp i + rw [h.join] + apply le_antisymm + · exact le_iSup p i + · exact iSup_le fun j => by rw [Subsingleton.elim j i] + +/-- The non-equality hypotheses are not redundant (degenerate resident with p = n = c): the +"neighbour" chart p 0 is admissible, but it equals c, so nothing is collapsed. -/ +example : ∃ (p n : Fin 1 → Prop) (c : Prop), Pinned p n c ∧ Admissible p n (p 0) ∧ p 0 = c := + ⟨fun _ => False, fun _ => False, False, + ⟨fun _ => le_rfl, fun _ => le_rfl, by simp, by simp⟩, fun _ => ⟨le_rfl, le_rfl⟩, rfl⟩ + +end Lattice + +section Route +open FrameSep +variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V] + +/-- Replace the frame at time t+1 by c'. -/ +def restop (R : Route K V) (t : ℕ) (c' : Submodule K V) : ℕ → Submodule K V := + Function.update R.f (t + 1) c' + +/-- If steps t and t+1 are public, the stop-replaced frame sequence has every step ascending +iff c' sits between the frames at t and t+2 (the route-ordering side of a collapse). -/ +theorem restop_valid_iff (R : Route K V) (t : ℕ) (h0 : ¬ R.owned t) (h1 : ¬ R.owned (t + 1)) + (c' : Submodule K V) : + (∀ s, ¬ R.owned s → restop R t c' s ≤ restop R t c' (s + 1)) ↔ + (R.f t ≤ c' ∧ c' ≤ R.f (t + 2)) := by + constructor + · intro h + have a := h t h0 + have b := h (t + 1) h1 + simp only [restop, Function.update_self, Function.update_of_ne (show t ≠ t + 1 by omega), + Function.update_of_ne (show t + 2 ≠ t + 1 by omega)] at a b + exact ⟨a, b⟩ + · rintro ⟨a, b⟩ s hs + by_cases e1 : s = t + · subst e1; simpa [restop] using a + by_cases e2 : s = t + 1 + · subst e2; simpa [restop] using b + have n1 : s ≠ t + 1 := e2 + have n2 : s + 1 ≠ t + 1 := fun h => e1 (by omega) + simpa [restop, Function.update_of_ne n1, Function.update_of_ne n2] using R.pub s hs + +/-- **Frame form.** Residents i with routes R i, each with public steps t i, t i + 1 and +frame c at time t i + 1; pinned by their frames at t i and t i + 2. If every resident's +stop-replaced route (stop chart c') is valid, c' = c. -/ +theorem route_collapse {ι : Type*} (R : ι → Route K V) (t : ι → ℕ) + (h0 : ∀ i, ¬ (R i).owned (t i)) (h1 : ∀ i, ¬ (R i).owned (t i + 1)) + {c : Submodule K V} + (hp : Pinned (fun i => (R i).f (t i)) (fun i => (R i).f (t i + 2)) c) + {c' : Submodule K V} + (hv : ∀ i, ∀ s, ¬ (R i).owned s → restop (R i) (t i) c' s ≤ restop (R i) (t i) c' (s + 1)) : + c' = c := + admissible_unique hp fun i => (restop_valid_iff (R i) (t i) (h0 i) (h1 i) c').1 (hv i) + +end Route + +section Cost +open JunkLB2 + +/-- Cost of a helper going 0 -> e in k+1 equal moves (k stops), per-stay accounting: +D0 = f(e) - Σ f(gap) over the k+1 moves. -/ +noncomputable def stopCost (f : ℝ → ℝ) (e : ℝ) (k : ℕ) : ℝ := + f e - ((List.replicate (k + 1) (f (e / (k + 1)))).sum) + +theorem stopCost_eq (f : ℝ → ℝ) (e : ℝ) (k : ℕ) : + stopCost f e k = f e - (k + 1) * f (e / (k + 1)) := by + simp [stopCost, List.sum_replicate, nsmul_eq_mul] + +/-- For f(r) = r ln r the cost is e ln (k+1). -/ +theorem stopCost_fL (e : ℝ) (k : ℕ) : stopCost fL e k = e * Real.log (k + 1) := by + have hk : (0 : ℝ) < (k : ℝ) + 1 := by positivity + rw [stopCost_eq] + unfold fL + by_cases he : e = 0 + · simp [he] + have hd : e / ((k : ℝ) + 1) ≠ 0 := div_ne_zero he hk.ne' + rw [Real.log_div he hk.ne'] + field_simp + ring + +/-- The 0 -> 9 helper: 9 ln (k+1). -/ +theorem stopCost_nine (k : ℕ) : stopCost fL 9 k = 9 * Real.log (k + 1) := stopCost_fL 9 k + +/-- Integer-gap cases (gap 9/(k+1) integral): k = 0, 2, 8 give 0, 9 ln 3, 9 ln 9 = 18 ln 3. -/ +theorem stopCost_k2 : stopCost fL 9 2 = 9 * Real.log 3 := by + rw [stopCost_nine]; norm_num + +/-- Stops are paid: cost is strictly increasing in k (convexity not needed for f = r ln r). -/ +theorem stopCost_strictMono {k m : ℕ} (h : k < m) : stopCost fL 9 k < stopCost fL 9 m := by + rw [stopCost_nine, stopCost_nine] + have : Real.log ((k : ℝ) + 1) < Real.log ((m : ℝ) + 1) := + Real.log_lt_log (by positivity) (by exact_mod_cast Nat.add_lt_add_right h 1) + linarith + +end Cost + +#print axioms admissible_unique +#print axioms no_neighbour_collapse +#print axioms pinned_nontrivial +#print axioms restop_valid_iff +#print axioms route_collapse +#print axioms stopCost_fL +#print axioms stopCost_nine +#print axioms stopCost_k2 +#print axioms stopCost_strictMono + +end RelaySandwich diff --git a/research/p104-native-ceiling/lean/Nov15/SwapNull.lean b/research/p104-native-ceiling/lean/Nov15/SwapNull.lean new file mode 100644 index 0000000000..c106f29bce --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/SwapNull.lean @@ -0,0 +1,732 @@ +/- +SwapNull, See SwapNull.md. +Formalises LAWBUILD M3's law SWAP-NULL (internal notes). + +Part A (op level, TokenCancel's model): the 4-op swap gadget + add h1 h2 (+1); add h2 h1 (-1); add h1 h2 (+1); scale h2 (-1) (3 ADD + SCALE -1, all at chart c) +exchanges the rows of h1 and h2. Tail swap = gadget, then every later event renamed h1<->h2: +the final state is the unswapped final state with the rows of h1, h2 exchanged (`tail_run`). +Head swap = earlier events renamed, then gadget: every final row has its h1/h2 COORDINATES +exchanged (`head_run`). +Part B (hub model, matrix level): only a V mix L (acts on V-ender rows) or a {0}-prefix M (acts on +G0 columns) can undo that; exact statements `tail_iff`, `head_iff`, `undo_one_iff`. +Part C (ladder): per-helper cost f(e-b) - sum f(gaps) (RelaySandwich.stopCost); the swap leaves the +stay multiset unchanged and changes the span terms by a rectangle difference, which is 0 iff the +ends agree or the births agree (`delta_eq`, `delta_zero_end`, `delta_zero_birth`). +Part D: law bundle and a concrete witness. +-/ +import Nov15.TokenCancel +import Nov15.RelaySandwich +import Nov15.SwapWord +import Mathlib.Data.Matrix.Mul +import Mathlib.LinearAlgebra.Matrix.ToLin + +set_option linter.unusedSectionVars false + +namespace SwapNull +open TokenCancel + +/-! ### Part A: the gadget and the two renamings -/ +section Op +variable {K Reg C : Type*} [Field K] [DecidableEq Reg] [DecidableEq C] + +/-- The 4-op swap gadget at chart `c`. -/ +def gadget (h1 h2 : Reg) (c : C) : List (Ev K Reg C) := + [.add h1 h2 1 c, .add h2 h1 (-1) c, .add h1 h2 1 c, .scale h2 (-1) c] + +theorem gadget_legal (h1 h2 : Reg) (hne : h1 ≠ h2) (c : C) (z V : C) (s : St K Reg C) + (a : s.loc h1 = some c) (b : s.loc h2 = some c) : + Legal z V s (gadget h1 h2 c) := by + simp [gadget, Legal, LegalEv, step, hne, hne.symm, a, b] + +/-- Rows and locations read through a register permutation. -/ +def permSt (σ : Equiv.Perm Reg) (s : St K Reg C) : St K Reg C := + ⟨fun r => s.row (σ r), fun r => s.loc (σ r)⟩ + +/-- Rows with their coordinates read through σ. -/ +def cpermSt (σ : Equiv.Perm Reg) (s : St K Reg C) : St K Reg C := + ⟨fun r => fun k => s.row r (σ k), s.loc⟩ + +def ren (σ : Equiv.Perm Reg) : Ev K Reg C → Ev K Reg C + | .born i c => .born (σ i) c + | .init i c => .init (σ i) c + | .move i c => .move (σ i) c + | .add i j a c => .add (σ i) (σ j) a c + | .scale i u c => .scale (σ i) u c + | .clear i c => .clear (σ i) c + | .copy i j c => .copy (σ i) (σ j) c + +theorem gadget_run (h1 h2 : Reg) (hne : h1 ≠ h2) (c : C) (s : St K Reg C) : + (run s (gadget h1 h2 c)).row = (fun r => s.row (Equiv.swap h1 h2 r)) ∧ + (run s (gadget h1 h2 c)).loc = s.loc := by + refine ⟨?_, ?_⟩ + · funext r + by_cases r1 : r = h1 + · subst r1 + simp [gadget, run, step, hne, hne.symm] + · by_cases r2 : r = h2 + · subst r2 + simp [gadget, run, step, hne, hne.symm, Function.update_apply] + · simp [gadget, run, step, r1, r2, Function.update_apply, Equiv.swap_apply_of_ne_of_ne] + · simp [gadget, run, step] + +lemma upd_perm {β : Type*} (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (f : Reg → β) + (i : Reg) (v : β) : + (fun r => Function.update f i v (σ r)) = Function.update (fun r => f (σ r)) (σ i) v := by + funext r + simp only [Function.update_apply] + have : σ r = i ↔ r = σ i := ⟨fun h => by rw [← h, hσ], fun h => by rw [h, hσ]⟩ + simp only [this] + +theorem step_permSt (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (s : St K Reg C) + (e : Ev K Reg C) (hb : ∀ i c, e = .born i c → σ i = i) : + step (permSt σ s) (ren σ e) = permSt σ (step s e) := by + cases e with + | born i c => + have hi := hb i c rfl + simp only [step, ren, permSt, St.mk.injEq] + rw [upd_perm σ hσ, upd_perm σ hσ, hi] + simp + | init i c => + simp only [step, ren, permSt, St.mk.injEq] + rw [upd_perm σ hσ, upd_perm σ hσ] + simp + | move i c => + simp only [step, ren, permSt, St.mk.injEq] + rw [upd_perm σ hσ] + simp + | add i j a c => + simp only [step, ren, permSt, St.mk.injEq] + rw [upd_perm σ hσ] + simp [hσ] + | scale i u c => + simp only [step, ren, permSt, St.mk.injEq] + rw [upd_perm σ hσ] + simp [hσ] + | clear i c => + simp only [step, ren, permSt, St.mk.injEq] + rw [upd_perm σ hσ] + simp + | copy i j a => + simp only [step, ren, permSt, St.mk.injEq] + rw [upd_perm σ hσ] + simp [hσ] + +theorem run_permSt (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (evs : List (Ev K Reg C)) + (hb : ∀ e ∈ evs, ∀ i c, e = .born i c → σ i = i) (s : St K Reg C) : + run (permSt σ s) (evs.map (ren σ)) = permSt σ (run s evs) := by + induction evs generalizing s with + | nil => rfl + | cons e es ih => + simp only [List.map_cons, run] + rw [step_permSt σ hσ s e (hb e (by simp)), ih (fun e' he' => hb e' (by simp [he']))] + +/-- Tail swap: gadget at the shared chart, then every later event renamed h1 <-> h2. +Final rows = unswapped final rows with h1, h2 exchanged; locations unchanged. -/ +theorem tail_run (h1 h2 : Reg) (hne : h1 ≠ h2) (c : C) (s : St K Reg C) + (a : s.loc h1 = some c) (b : s.loc h2 = some c) (evs : List (Ev K Reg C)) + (hb : ∀ e ∈ evs, ∀ i c, e = .born i c → i ≠ h1 ∧ i ≠ h2) : + run s (gadget h1 h2 c ++ evs.map (ren (Equiv.swap h1 h2))) = + permSt (Equiv.swap h1 h2) (run s evs) := by + have hσ : ∀ r, Equiv.swap h1 h2 (Equiv.swap h1 h2 r) = r := fun r => Equiv.swap_apply_self _ _ _ + have hg := gadget_run h1 h2 hne c s + have hs : run s (gadget h1 h2 c) = permSt (Equiv.swap h1 h2) s := by + have hloc : ∀ r, s.loc (Equiv.swap h1 h2 r) = s.loc r := by + intro r + by_cases r1 : r = h1 + · subst r1; simp [a, b] + · by_cases r2 : r = h2 + · subst r2; simp [a, b] + · rw [Equiv.swap_apply_of_ne_of_ne r1 r2] + cases hr : run s (gadget h1 h2 c) with + | mk row loc => + rw [hr] at hg + simp only [permSt, St.mk.injEq] + obtain ⟨hg1, hg2⟩ := hg + simp only at hg1 hg2 + refine ⟨hg1, ?_⟩ + rw [hg2]; funext r; exact (hloc r).symm + rw [SwapWord.run_append, hs] + exact run_permSt _ hσ evs (fun e he i c h => by + obtain ⟨x, y⟩ := hb e he i c h + exact Equiv.swap_apply_of_ne_of_ne x y) s + +/-- Registers and coordinates both read through σ (the state of a run whose events were renamed). -/ +def bothSt (σ : Equiv.Perm Reg) (s : St K Reg C) : St K Reg C := + ⟨fun r k => s.row (σ r) (σ k), fun r => s.loc (σ r)⟩ + +lemma upd_both (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (f : Reg → Reg → K) + (i : Reg) (v : Reg → K) : + (fun r k => Function.update f i v (σ r) (σ k)) = + Function.update (fun r k => f (σ r) (σ k)) (σ i) (fun k => v (σ k)) := by + funext r k + have : σ r = i ↔ r = σ i := ⟨fun h => by rw [← h, hσ], fun h => by rw [h, hσ]⟩ + by_cases h : r = σ i + · subst h + simp [Function.update_apply, hσ] + · have h' : ¬ σ r = i := fun x => h (this.1 x) + simp [Function.update_apply, h, h'] + +theorem step_bothSt (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (s : St K Reg C) + (e : Ev K Reg C) : + step (bothSt σ s) (ren σ e) = bothSt σ (step s e) := by + cases e with + | born i c => + simp only [step, ren, bothSt, St.mk.injEq] + rw [upd_both σ hσ, upd_perm σ hσ] + have : (fun k => (Pi.single i (1 : K) : Reg → K) (σ k)) = Pi.single (σ i) 1 := by + funext k + have : σ k = i ↔ k = σ i := ⟨fun h => by rw [← h, hσ], fun h => by rw [h, hσ]⟩ + by_cases h : k = σ i + · simp [Pi.single_apply, h, this.2 h, hσ] + · have hn : ¬ σ k = i := fun x => h (this.1 x) + simp [Pi.single_apply, h, hn] + rw [this]; simp + | init i c => + simp only [step, ren, bothSt, St.mk.injEq] + rw [upd_both σ hσ, upd_perm σ hσ]; simp; congr 1 + | move i c => + simp only [step, ren, bothSt, St.mk.injEq] + rw [upd_perm σ hσ]; simp + | add i j a c => + simp only [step, ren, bothSt, St.mk.injEq] + rw [upd_both σ hσ]; simp [hσ]; congr 1 + | scale i u c => + simp only [step, ren, bothSt, St.mk.injEq] + rw [upd_both σ hσ]; simp [hσ]; congr 1 + | clear i c => + simp only [step, ren, bothSt, St.mk.injEq] + rw [upd_both σ hσ]; simp; congr 1 + | copy i j c => + simp only [step, ren, bothSt, St.mk.injEq] + rw [upd_both σ hσ]; simp [hσ] + +theorem run_bothSt (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (evs : List (Ev K Reg C)) + (s : St K Reg C) : + run (bothSt σ s) (evs.map (ren σ)) = bothSt σ (run s evs) := by + induction evs generalizing s with + | nil => rfl + | cons e es ih => + simp only [List.map_cons, run] + rw [step_bothSt σ hσ s e, ih] + +theorem step_cpermSt (σ : Equiv.Perm Reg) (s : St K Reg C) + (e : Ev K Reg C) (hσ : ∀ r, σ (σ r) = r) (hb : ∀ i c, e = .born i c → σ i = i) : + step (cpermSt σ s) e = cpermSt σ (step s e) := by + cases e with + | born i c => + have hi := hb i c rfl + simp only [step, cpermSt] + congr 1 + funext r k + by_cases h : r = i + · subst h + have : σ k = r ↔ k = r := ⟨fun h => by rw [← hi, ← h, hσ], fun h => by rw [h, hi]⟩ + by_cases hk : k = r + · simp [Pi.single_apply, hk, hi] + · have hn : ¬ σ k = r := fun x => hk (this.1 x) + simp [Pi.single_apply, hk, hn] + · simp [Function.update_apply, h] + | init i c => + simp only [step, cpermSt] + congr 1 + funext r k; by_cases h : r = i <;> simp [Function.update_apply, h] + | move i c => simp [step, cpermSt] + | add i j a c => + simp only [step, cpermSt] + congr 1 + funext r k; by_cases h : r = i <;> simp [Function.update_apply, h] + | scale i u c => + simp only [step, cpermSt] + congr 1 + funext r k; by_cases h : r = i <;> simp [Function.update_apply, h] + | clear i c => + simp only [step, cpermSt] + congr 1 + funext r k; by_cases h : r = i <;> simp [Function.update_apply, h] + | copy i j c => + simp only [step, cpermSt] + congr 1 + funext r k; by_cases h : r = i <;> simp [Function.update_apply, h] + +theorem run_cpermSt (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (evs : List (Ev K Reg C)) + (hb : ∀ e ∈ evs, ∀ i c, e = .born i c → σ i = i) (s : St K Reg C) : + run (cpermSt σ s) evs = cpermSt σ (run s evs) := by + induction evs generalizing s with + | nil => rfl + | cons e es ih => + simp only [run] + rw [step_cpermSt σ s e hσ (hb e (by simp)), ih (fun e' he' => hb e' (by simp [he']))] + +/-- Head swap: earlier events (`pre`) renamed h1 <-> h2, then the gadget at the shared chart, then the +original later events (`post`, no births of h1, h2). If the start state is σ-symmetric, every +final row has its h1/h2 coordinates exchanged; locations are unchanged. -/ +theorem head_run (h1 h2 : Reg) (hne : h1 ≠ h2) (c : C) (s0 : St K Reg C) + (hs0 : bothSt (Equiv.swap h1 h2) s0 = s0) + (pre post : List (Ev K Reg C)) + (a : (run s0 pre).loc h1 = some c) (b : (run s0 pre).loc h2 = some c) + (hb : ∀ e ∈ post, ∀ i c, e = .born i c → i ≠ h1 ∧ i ≠ h2) : + run s0 (pre.map (ren (Equiv.swap h1 h2)) ++ gadget h1 h2 c ++ post) = + cpermSt (Equiv.swap h1 h2) (run s0 (pre ++ post)) := by + have hσ : ∀ r, Equiv.swap h1 h2 (Equiv.swap h1 h2 r) = r := fun r => Equiv.swap_apply_self _ _ _ + set σ := Equiv.swap h1 h2 with hσdef + set t := run s0 pre with ht + have h1' : run s0 (pre.map (ren σ)) = bothSt σ t := by + conv_lhs => rw [← hs0] + exact run_bothSt σ hσ pre s0 + have hg := gadget_run h1 h2 hne c (bothSt σ t) + have hloc : ∀ r, t.loc (σ r) = t.loc r := by + intro r + by_cases r1 : r = h1 + · subst r1; simp [σ, a, b] + · by_cases r2 : r = h2 + · subst r2; simp [σ, a, b] + · rw [Equiv.swap_apply_of_ne_of_ne r1 r2] + have hs : run (bothSt σ t) (gadget h1 h2 c) = cpermSt σ t := by + cases hr : run (bothSt σ t) (gadget h1 h2 c) with + | mk row loc => + rw [hr] at hg + obtain ⟨hg1, hg2⟩ := hg + simp only [bothSt] at hg1 hg2 + simp only [cpermSt, St.mk.injEq] + refine ⟨?_, ?_⟩ + · rw [hg1]; funext r k; exact congrArg (fun x => t.row x (σ k)) (hσ r) + · rw [hg2]; funext r; exact hloc r + rw [SwapWord.run_append, SwapWord.run_append, h1', hs, + run_cpermSt σ hσ post (fun e he i c h => by + obtain ⟨x, y⟩ := hb e he i c h + exact Equiv.swap_apply_of_ne_of_ne x y), SwapWord.run_append s0 pre post] + +end Op + +/-! ### Part B: what the hubs can undo (matrix level; HubSettle's V mix and {0}-prefix) -/ +section Hub +variable {K Reg : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] + +/-- `A` is the identity outside the `S × S` block (a hub op acts only inside its own block). -/ +def Blk (S : Reg → Prop) (A : Matrix Reg Reg K) : Prop := + ∀ i k, ¬ (S i ∧ S k) → A i k = (1 : Matrix Reg Reg K) i k + +/-- F' can be restored to F by a V mix `L` (block on V-enders, acts on rows) and a {0}-prefix `M` +(block on G0 columns, right multiplication). Invertibility is not demanded (strengthens the +only-if directions); the witnesses used for the if directions are permutation matrices. -/ +def Undo (V G0 : Reg → Prop) (F F' : Matrix Reg Reg K) : Prop := + ∃ L M : Matrix Reg Reg K, Blk V L ∧ Blk G0 M ∧ L * F' * M = F + +/-- Tail swap of the final matrix: rows h1,h2 exchanged. -/ +def rowSw (σ : Equiv.Perm Reg) (F : Matrix Reg Reg K) : Matrix Reg Reg K := + Matrix.of fun i k => F (σ i) k +/-- Head swap of the final matrix: coordinates h1,h2 exchanged. -/ +def colSw (σ : Equiv.Perm Reg) (F : Matrix Reg Reg K) : Matrix Reg Reg K := + Matrix.of fun i k => F i (σ k) + +def swapMat (σ : Equiv.Perm Reg) : Matrix Reg Reg K := + Matrix.of fun i k => if k = σ i then 1 else 0 + +lemma blk_one (S : Reg → Prop) : Blk S (1 : Matrix Reg Reg K) := fun _ _ _ => rfl + +lemma swapMat_mul (σ : Equiv.Perm Reg) (A : Matrix Reg Reg K) : swapMat σ * A = rowSw σ A := by + ext i k + simp [Matrix.mul_apply, swapMat, rowSw] + +lemma mul_swapMat (σ : Equiv.Perm Reg) (hσ : ∀ r, σ (σ r) = r) (A : Matrix Reg Reg K) : + A * swapMat σ = colSw σ A := by + ext i k + simp only [Matrix.mul_apply, swapMat, colSw, Matrix.of_apply] + have : ∀ j, (k = σ j) ↔ (j = σ k) := fun j => ⟨fun h => by rw [h, hσ], fun h => by rw [h, hσ]⟩ + simp [this] + +lemma swapMat_blk (h1 h2 : Reg) (S : Reg → Prop) (a : S h1) (b : S h2) : + Blk S (swapMat (Equiv.swap h1 h2) : Matrix Reg Reg K) := by + intro i k hik + simp only [swapMat, Matrix.of_apply, Matrix.one_apply] + have hk1 : ∀ x, S x → ¬ S k → x ≠ k := fun x hx hk h => hk (h ▸ hx) + by_cases i1 : i = h1 + · subst i1 + have hk : ¬ S k := fun h => hik ⟨a, h⟩ + simp [hk1 _ a hk, hk1 _ b hk, (hk1 _ a hk).symm, (hk1 _ b hk).symm] + · by_cases i2 : i = h2 + · subst i2 + have hk : ¬ S k := fun h => hik ⟨b, h⟩ + simp [hk1 _ a hk, hk1 _ b hk, (hk1 _ a hk).symm, (hk1 _ b hk).symm] + · rw [Equiv.swap_apply_of_ne_of_ne i1 i2] + simp [eq_comm] + +lemma blk_row {V : Reg → Prop} {L : Matrix Reg Reg K} (hL : Blk V L) {x : Reg} (hx : ¬ V x) + (Y : Matrix Reg Reg K) : (L * Y) x = Y x := by + funext k + have : ∀ m, L x m = if x = m then 1 else 0 := fun m => by + simpa [Matrix.one_apply] using hL x m (fun h => hx h.1) + simp [Matrix.mul_apply, this] + +lemma mul_blk_col {G0 : Reg → Prop} {M : Matrix Reg Reg K} (hM : Blk G0 M) {a : Reg} + (ha : ¬ G0 a) (Y : Matrix Reg Reg K) (i : Reg) : (Y * M) i a = Y i a := by + have : ∀ j, M j a = if j = a then 1 else 0 := fun j => by + simpa [Matrix.one_apply] using hM j a (fun h => ha h.2) + simp [Matrix.mul_apply, this] + +lemma row_eq {V : Reg → Prop} {F F' L M : Matrix Reg Reg K} (hL : Blk V L) + (h : L * F' * M = F) {x : Reg} (hx : ¬ V x) : (F' * M) x = F x := by + rw [Matrix.mul_assoc] at h + have := blk_row hL hx (F' * M) + rw [h] at this + exact this.symm + +section Swap +variable (h1 h2 : Reg) + +local notation "σ" => Equiv.swap h1 h2 + +lemma swap_inv (r : Reg) : σ (σ r) = r := Equiv.swap_apply_self _ _ _ + +/-- Both helpers end in V: the V mix undoes the tail swap. -/ +theorem tail_if (V G0 : Reg → Prop) (F : Matrix Reg Reg K) (a : V h1) (b : V h2) : + Undo V G0 F (rowSw σ F) := by + refine ⟨swapMat σ, 1, swapMat_blk h1 h2 V a b, blk_one _, ?_⟩ + rw [Matrix.mul_one, swapMat_mul] + ext i k + simp [rowSw, swap_inv] + +/-- Both helpers born in {0}: the {0}-prefix undoes the head swap. -/ +theorem head_if (V G0 : Reg → Prop) (F : Matrix Reg Reg K) (a : G0 h1) (b : G0 h2) : + Undo V G0 F (colSw σ F) := by + refine ⟨1, swapMat σ, blk_one _, swapMat_blk h1 h2 G0 a b, ?_⟩ + rw [Matrix.one_mul, mul_swapMat σ (swap_inv h1 h2)] + ext i k + simp [colSw, swap_inv] + +lemma ab_cases (a : Reg) (ha : a = h1 ∨ a = h2) (hne : h1 ≠ h2) : + (a = h1 ∧ σ a = h2) ∨ (a = h2 ∧ σ a = h1) := by + rcases ha with rfl | rfl + · left; simp + · right; simp + +/-- Tail swap, only-if. `hrig`: the unchanged non-V rows pin every {0}-prefix to the identity +(`rigid_of_span` gives this from a spanning condition). Then a tail swap is undone only if both +helpers end in V. -/ +theorem tail_only_if (V G0 : Reg → Prop) (hne : h1 ≠ h2) (F : Matrix Reg Reg K) + (hF1 : F h1 = Pi.single h1 1) (hF2 : F h2 = Pi.single h2 1) + (hrig : ∀ M : Matrix Reg Reg K, Blk G0 M → + (∀ x, x ≠ h1 → x ≠ h2 → ¬ V x → (F * M) x = F x) → M = 1) : + Undo V G0 F (rowSw σ F) → V h1 ∧ V h2 := by + rintro ⟨L, M, hL, hM, h⟩ + by_contra hn + obtain ⟨a, ha, haV⟩ : ∃ a, (a = h1 ∨ a = h2) ∧ ¬ V a := by + by_cases v1 : V h1 + · exact ⟨h2, Or.inr rfl, fun v2 => hn ⟨v1, v2⟩⟩ + · exact ⟨h1, Or.inl rfl, v1⟩ + have key : ∀ x, ¬ V x → (rowSw σ F * M) x = F x := fun x hx => row_eq hL h hx + have hM1 : M = 1 := by + refine hrig M hM (fun x hx1 hx2 hxV => ?_) + have := key x hxV + have hsx : σ x = x := Equiv.swap_apply_of_ne_of_ne hx1 hx2 + funext k + have := congrFun this k + simpa [rowSw, Matrix.mul_apply, hsx] using this + subst hM1 + have e : F (σ a) = F a := by + have := key a haV + rw [Matrix.mul_one] at this + exact this + rcases ab_cases h1 h2 a ha hne with ⟨rfl, h'⟩ | ⟨rfl, h'⟩ + · rw [h', hF1, hF2] at e + have := congrFun e a + simp [Pi.single_apply, hne.symm] at this + · rw [h', hF1, hF2] at e + have := congrFun e a + simp [Pi.single_apply, hne] at this + +/-- Head swap, only-if: if some non-V row distinguishes the h1 and h2 coordinates, the swap is +undone only if both helpers are born in {0}. -/ +theorem head_only_if (V G0 : Reg → Prop) (hne : h1 ≠ h2) (F : Matrix Reg Reg K) + (hw : ∃ x, ¬ V x ∧ F x h1 ≠ F x h2) : + Undo V G0 F (colSw σ F) → G0 h1 ∧ G0 h2 := by + rintro ⟨L, M, hL, hM, h⟩ + obtain ⟨x, hxV, hxne⟩ := hw + by_contra hn + obtain ⟨a, ha, haG⟩ : ∃ a, (a = h1 ∨ a = h2) ∧ ¬ G0 a := by + by_cases v1 : G0 h1 + · exact ⟨h2, Or.inr rfl, fun v2 => hn ⟨v1, v2⟩⟩ + · exact ⟨h1, Or.inl rfl, v1⟩ + have e := congrFun (row_eq hL h hxV) a + rw [mul_blk_col hM haG] at e + simp only [colSw, Matrix.of_apply] at e + rcases ab_cases h1 h2 a ha hne with ⟨rfl, h'⟩ | ⟨rfl, h'⟩ + · rw [h'] at e; exact hxne e.symm + · rw [h'] at e; exact hxne e + +/-- Identity-final case: the swap matrix is the same for both kinds; it is undone iff both +helpers end in V or both are born in {0}. -/ +theorem undo_one_iff (V G0 : Reg → Prop) (hne : h1 ≠ h2) : + Undo V G0 (1 : Matrix Reg Reg K) (rowSw σ 1) ↔ (V h1 ∧ V h2) ∨ (G0 h1 ∧ G0 h2) := by + constructor + · rintro ⟨L, M, hL, hM, h⟩ + by_cases hv : V h1 ∧ V h2 + · exact Or.inl hv + right + obtain ⟨a, ha, haV⟩ : ∃ a, (a = h1 ∨ a = h2) ∧ ¬ V a := by + by_cases v1 : V h1 + · exact ⟨h2, Or.inr rfl, fun v2 => hv ⟨v1, v2⟩⟩ + · exact ⟨h1, Or.inl rfl, v1⟩ + have e := congrFun (row_eq hL h haV) a + have hMa : M (σ a) a = 1 := by + have : (rowSw σ (1 : Matrix Reg Reg K) * M) a a = M (σ a) a := by + simp [rowSw, Matrix.mul_apply, Matrix.one_apply] + rw [this] at e + simpa using e + have hG : G0 (σ a) ∧ G0 a := by + by_contra hc + have := hM (σ a) a hc + rw [hMa] at this + have hn : σ a ≠ a := by + rcases ab_cases h1 h2 a ha hne with ⟨rfl, h'⟩ | ⟨rfl, h'⟩ + · rw [h']; exact hne.symm + · rw [h']; exact hne + simp [Matrix.one_apply, hn] at this + rcases ab_cases h1 h2 a ha hne with ⟨rfl, h'⟩ | ⟨rfl, h'⟩ + · rw [h'] at hG; exact ⟨hG.2, hG.1⟩ + · rw [h'] at hG; exact hG + · rintro (⟨a, b⟩ | ⟨a, b⟩) + · exact tail_if h1 h2 V G0 1 a b + · have := head_if h1 h2 V G0 (1 : Matrix Reg Reg K) a b + have e : colSw σ (1 : Matrix Reg Reg K) = rowSw σ 1 := by + ext i k + have : (σ i = k) ↔ (i = σ k) := + ⟨fun h => by rw [← h, swap_inv], fun h => by rw [h, swap_inv]⟩ + simp [colSw, rowSw, Matrix.one_apply, this] + rwa [e] at this + +end Swap + +end Hub + +section Rigid +variable {K Reg : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] + +lemma single_vecMul (M : Matrix Reg Reg K) (i : Reg) : + Matrix.vecMul (Pi.single i (1 : K) : Reg → K) M = M i := by + funext j + simp [Matrix.vecMul, dotProduct, Pi.single_apply] + +/-- A spanning condition forces rigidity: if the (unchanged, non-V) rows of F together with the unit +vectors of the non-G0 coordinates span everything, then a G0-block prefix that fixes those rows is 1. -/ +theorem rigid_of_span (G0 : Reg → Prop) (T : Set Reg) (F : Matrix Reg Reg K) + (hspan : Submodule.span K ((fun x => F x) '' T ∪ + Set.range (fun k : {k // ¬ G0 k} => (Pi.single k.1 (1 : K) : Reg → K))) = ⊤) + (M : Matrix Reg Reg K) (hM : Blk G0 M) (hfix : ∀ x ∈ T, (F * M) x = F x) : M = 1 := by + let φ : (Reg → K) →ₗ[K] (Reg → K) := Matrix.vecMulLinear M - LinearMap.id + have hle : Submodule.span K ((fun x => F x) '' T ∪ + Set.range (fun k : {k // ¬ G0 k} => (Pi.single k.1 (1 : K) : Reg → K))) ≤ + LinearMap.ker φ := by + rw [Submodule.span_le] + rintro v (⟨x, hx, rfl⟩ | ⟨k, rfl⟩) + · have := hfix x hx + simp only [SetLike.mem_coe, LinearMap.mem_ker, φ, LinearMap.sub_apply, + Matrix.vecMulLinear_apply, LinearMap.id_apply, sub_eq_zero] + funext j + have := congrFun this j + simpa [Matrix.mul_apply, Matrix.vecMul, dotProduct] using this + · simp only [SetLike.mem_coe, LinearMap.mem_ker, φ, LinearMap.sub_apply, + Matrix.vecMulLinear_apply, LinearMap.id_apply, sub_eq_zero] + rw [single_vecMul] + funext j + have := hM k.1 j (fun h => k.2 h.1) + simp only [Matrix.one_apply] at this + rw [this] + simp [Pi.single_apply, eq_comm] + have hall : ∀ v, φ v = 0 := fun v => hle (by rw [hspan]; trivial) + ext i k + have := congrFun (hall (Pi.single i 1)) k + simp only [φ, LinearMap.sub_apply, Matrix.vecMulLinear_apply, LinearMap.id_apply, + Pi.sub_apply, single_vecMul] at this + simp only [Matrix.one_apply] + simp only [Pi.zero_apply, Pi.single_apply] at this + have h3 := sub_eq_zero.1 this + rw [h3]; simp [eq_comm] + +end Rigid + +section Iff +variable {K Reg : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] (h1 h2 : Reg) +local notation "σ" => Equiv.swap h1 h2 + +/-- (1), tail swap: undone iff both helpers end in V (under rigidity of the {0}-prefix). -/ +theorem tail_iff (V G0 : Reg → Prop) (hne : h1 ≠ h2) (F : Matrix Reg Reg K) + (hF1 : F h1 = Pi.single h1 1) (hF2 : F h2 = Pi.single h2 1) + (hrig : ∀ M : Matrix Reg Reg K, Blk G0 M → + (∀ x, x ≠ h1 → x ≠ h2 → ¬ V x → (F * M) x = F x) → M = 1) : + Undo V G0 F (rowSw σ F) ↔ V h1 ∧ V h2 := + ⟨tail_only_if h1 h2 V G0 hne F hF1 hF2 hrig, fun ⟨a, b⟩ => tail_if h1 h2 V G0 F a b⟩ + +/-- (1), head swap: undone iff both helpers are born in {0} (when some non-V row separates h1, h2). -/ +theorem head_iff (V G0 : Reg → Prop) (hne : h1 ≠ h2) (F : Matrix Reg Reg K) + (hw : ∃ x, ¬ V x ∧ F x h1 ≠ F x h2) : + Undo V G0 F (colSw σ F) ↔ G0 h1 ∧ G0 h2 := + ⟨head_only_if h1 h2 V G0 hne F hw, fun ⟨a, b⟩ => head_if h1 h2 V G0 F a b⟩ + +/-- Tail swap, spanning form of the rigidity hypothesis. -/ +theorem tail_iff_span (V G0 : Reg → Prop) (hne : h1 ≠ h2) (F : Matrix Reg Reg K) + (hF1 : F h1 = Pi.single h1 1) (hF2 : F h2 = Pi.single h2 1) + (hspan : Submodule.span K ((fun x => F x) '' {x | x ≠ h1 ∧ x ≠ h2 ∧ ¬ V x} ∪ + Set.range (fun k : {k // ¬ G0 k} => (Pi.single k.1 (1 : K) : Reg → K))) = ⊤) : + Undo V G0 F (rowSw σ F) ↔ V h1 ∧ V h2 := + tail_iff h1 h2 V G0 hne F hF1 hF2 fun M hM hfix => + rigid_of_span G0 _ F hspan M hM fun x hx => hfix x hx.1 hx.2.1 hx.2.2 + +lemma colSw_one (V : Reg → Prop) : colSw σ (1 : Matrix Reg Reg K) = rowSw σ 1 := by + ext i k + have : (σ i = k) ↔ (i = σ k) := + ⟨fun h => by rw [← h, swap_inv], fun h => by rw [h, swap_inv]⟩ + simp [colSw, rowSw, Matrix.one_apply, this] + +end Iff + +/-! ### Part C: ladder cost -/ +section Ladder +open JunkLB2 RelaySandwich + +/-- A helper's trajectory: birth dim `b`, end dim `e`, stay gaps before (`pre`) and after (`suf`) the +shared chart. -/ +structure Traj where + b : ℝ + e : ℝ + pre : List ℝ + suf : List ℝ + +/-- Per-helper ladder cost: span term minus the sum over stays (RelaySandwich.stopCost's accounting). -/ +noncomputable def Traj.cost (f : ℝ → ℝ) (t : Traj) : ℝ := + f (t.e - t.b) - ((t.pre ++ t.suf).map f).sum + +/-- Both helpers sit at the shared chart (dim `s`) and their gaps add up. -/ +def Traj.Wf (s : ℝ) (t : Traj) : Prop := t.b + t.pre.sum = s ∧ s + t.suf.sum = t.e + +/-- The swap (tail or head: same pair of trajectories, only the names differ). -/ +def Traj.swap (t1 t2 : Traj) : Traj × Traj := + (⟨t1.b, t2.e, t1.pre, t2.suf⟩, ⟨t2.b, t1.e, t2.pre, t1.suf⟩) + +theorem swap_wf (s : ℝ) (t1 t2 : Traj) (a : t1.Wf s) (b : t2.Wf s) : + (Traj.swap t1 t2).1.Wf s ∧ (Traj.swap t1 t2).2.Wf s := + ⟨⟨a.1, b.2⟩, ⟨b.1, a.2⟩⟩ + +/-- The multiset of stays is unchanged. -/ +theorem stays_multiset (t1 t2 : Traj) : + ((↑((Traj.swap t1 t2).1.pre ++ (Traj.swap t1 t2).1.suf ++ + ((Traj.swap t1 t2).2.pre ++ (Traj.swap t1 t2).2.suf)) : Multiset ℝ)) = + ↑(t1.pre ++ t1.suf ++ (t2.pre ++ t2.suf)) := by + simp only [Traj.swap, ← Multiset.coe_add] + abel + +theorem cost_stopCost (f : ℝ → ℝ) (e : ℝ) (k : ℕ) : + Traj.cost f ⟨0, e, List.replicate (k + 1) (e / (k + 1)), []⟩ = stopCost f e k := by + simp [Traj.cost, stopCost, List.map_replicate] + +/-- (2): the ladder change is exactly the rectangle difference of the span terms. -/ +theorem delta_eq (f : ℝ → ℝ) (t1 t2 : Traj) : + (Traj.swap t1 t2).1.cost f + (Traj.swap t1 t2).2.cost f - (t1.cost f + t2.cost f) = + (f (t2.e - t1.b) + f (t1.e - t2.b)) - (f (t1.e - t1.b) + f (t2.e - t2.b)) := by + simp only [Traj.cost, Traj.swap, List.map_append, List.sum_append] + ring + +/-- Both helpers end in V (same dim): ladder change 0. -/ +theorem delta_zero_end (f : ℝ → ℝ) (t1 t2 : Traj) (h : t1.e = t2.e) : + (Traj.swap t1 t2).1.cost f + (Traj.swap t1 t2).2.cost f - (t1.cost f + t2.cost f) = 0 := by + rw [delta_eq, h]; ring + +/-- Both helpers born in {0} (same dim 0): ladder change 0. -/ +theorem delta_zero_birth (f : ℝ → ℝ) (t1 t2 : Traj) (h : t1.b = t2.b) : + (Traj.swap t1 t2).1.cost f + (Traj.swap t1 t2).2.cost f - (t1.cost f + t2.cost f) = 0 := by + rw [delta_eq, h]; ring + +end Ladder + +/-! ### Part D: the law and the converse witness -/ +section Law +open JunkLB2 + +variable {K Reg : Type*} [Field K] [Fintype Reg] [DecidableEq Reg] (h1 h2 : Reg) +local notation "σ" => Equiv.swap h1 h2 + +/-- SWAP-NULL: a legal (hub-undoable) swap has ladder change 0 (ends of V-enders share the dim of V, +{0}-born helpers share dim 0). -/ +theorem swap_null (f : ℝ → ℝ) (V G0 : Reg → Prop) (dV : ℝ) (t1 t2 : Traj) (hne : h1 ≠ h2) + (hV1 : V h1 → t1.e = dV) (hV2 : V h2 → t2.e = dV) + (hG1 : G0 h1 → t1.b = 0) (hG2 : G0 h2 → t2.b = 0) + (hu : Undo V G0 (1 : Matrix Reg Reg K) (rowSw σ 1)) : + (Traj.swap t1 t2).1.cost f + (Traj.swap t1 t2).2.cost f - (t1.cost f + t2.cost f) = 0 := by + rcases (undo_one_iff h1 h2 V G0 hne).1 hu with ⟨a, b⟩ | ⟨a, b⟩ + · exact delta_zero_end f t1 t2 ((hV1 a).trans (hV2 b).symm) + · exact delta_zero_birth f t1 t2 ((hG1 a).trans (hG2 b).symm) + +/-- (3), contrapositive: a nonzero ladder change cannot be hub-undone. -/ +theorem nonzero_not_undoable (f : ℝ → ℝ) (V G0 : Reg → Prop) (dV : ℝ) (t1 t2 : Traj) + (hne : h1 ≠ h2) + (hV1 : V h1 → t1.e = dV) (hV2 : V h2 → t2.e = dV) + (hG1 : G0 h1 → t1.b = 0) (hG2 : G0 h2 → t2.b = 0) + (hd : (Traj.swap t1 t2).1.cost f + (Traj.swap t1 t2).2.cost f - (t1.cost f + t2.cost f) ≠ 0) : + ¬ Undo V G0 (1 : Matrix Reg Reg K) (rowSw σ 1) := + fun hu => hd (swap_null (K := K) h1 h2 f V G0 dV t1 t2 hne hV1 hV2 hG1 hG2 hu) + +/-- The numerical core: 7 ln 7 + 4 ln 4 < 2 ln 2 + 9 ln 9. -/ +theorem witness_num : fL (9 - 5) + fL (7 - 0) - (fL (7 - 5) + fL (9 - 0)) < 0 := by + have h : (7 : ℝ) * Real.log 7 + 6 * Real.log 2 < 18 * Real.log 3 := by + have := Real.log_lt_log (by positivity : (0 : ℝ) < 7 ^ 7 * 2 ^ 6) (by norm_num : (7 : ℝ) ^ 7 * 2 ^ 6 < 3 ^ 18) + rw [Real.log_mul (by positivity) (by positivity), Real.log_pow, Real.log_pow, Real.log_pow] at this + push_cast at this + exact this + have h4 : Real.log 4 = 2 * Real.log 2 := by + rw [show (4 : ℝ) = 2 ^ 2 by norm_num, Real.log_pow]; norm_num + have h9 : Real.log 9 = 2 * Real.log 3 := by + rw [show (9 : ℝ) = 3 ^ 2 by norm_num, Real.log_pow]; norm_num + unfold fL + norm_num + rw [h4, h9] + linarith + +end Law + +/-- Concrete witness (Reg = Fin 2; helper 0 born dim 5, ends dim 7, in neither hub; helper 1 born {0}, +ends in V of dim 9; shared chart dim 6). Its ladder change is strictly negative (f = r ln r, about +-1.995), and the swap, tail or head, cannot be undone by any V mix and {0}-prefix. -/ +theorem converse_witness : + let t1 : Traj := ⟨5, 7, [1], [1]⟩ + let t2 : Traj := ⟨0, 9, [6], [3]⟩ + t1.Wf 6 ∧ t2.Wf 6 ∧ + ((Traj.swap t1 t2).1.cost JunkLB2.fL + (Traj.swap t1 t2).2.cost JunkLB2.fL + - (t1.cost JunkLB2.fL + t2.cost JunkLB2.fL) < 0) ∧ + ¬ Undo (fun r : Fin 2 => r = 1) (fun r : Fin 2 => r = 1) (1 : Matrix (Fin 2) (Fin 2) ℚ) + (rowSw (Equiv.swap 0 1) 1) ∧ + ¬ Undo (fun r : Fin 2 => r = 1) (fun r : Fin 2 => r = 1) (1 : Matrix (Fin 2) (Fin 2) ℚ) + (colSw (Equiv.swap 0 1) 1) := by + intro t1 t2 + have hne : (0 : Fin 2) ≠ 1 := by decide + have hn : ¬ Undo (fun r : Fin 2 => r = 1) (fun r : Fin 2 => r = 1) (1 : Matrix (Fin 2) (Fin 2) ℚ) + (rowSw (Equiv.swap 0 1) 1) := by + rw [undo_one_iff 0 1 _ _ hne]; decide + refine ⟨by norm_num [Traj.Wf, t1], by norm_num [Traj.Wf, t2], ?_, hn, ?_⟩ + · rw [delta_eq] + simpa [t1, t2] using witness_num + · rw [colSw_one 0 1 (fun r : Fin 2 => r = 1)]; exact hn + +/-- Scope of the per-kind iff: with identity finals and both helpers in G0 but not in V, the TAIL +swap IS undone (by the prefix), so "tail swap legal iff both end in V" needs the rigidity hypothesis. -/ +theorem tail_prefix_counterexample : + Undo (fun _ : Fin 2 => False) (fun _ : Fin 2 => True) (1 : Matrix (Fin 2) (Fin 2) ℚ) + (rowSw (Equiv.swap 0 1) 1) ∧ ¬ (False ∧ False) := by + refine ⟨?_, by simp⟩ + rw [undo_one_iff 0 1 _ _ (by decide)]; simp + +#print axioms tail_run +#print axioms head_run +#print axioms gadget_legal +#print axioms tail_iff +#print axioms tail_iff_span +#print axioms head_iff +#print axioms undo_one_iff +#print axioms delta_eq +#print axioms swap_null +#print axioms converse_witness +#print axioms tail_prefix_counterexample +#print axioms stays_multiset +#print axioms cost_stopCost + +end SwapNull diff --git a/research/p104-native-ceiling/lean/Nov15/SwapNull.md b/research/p104-native-ceiling/lean/Nov15/SwapNull.md new file mode 100644 index 0000000000..c8950480ee --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/SwapNull.md @@ -0,0 +1,24 @@ +# SwapNull.lean: LAWBUILD M3 law SWAP-NULL. No sorry, 8 s, 2.45 GB RSS +Nov 17. Imports TokenCancel (op model), SwapWord (`run_append`), RelaySandwich (`stopCost`, `fL` via JunkLB2). Axioms: [propext, Classical.choice, Quot.sound]. +Source: (internal notes) HubSettle's V mix and {0}-prefix are modelled as `Blk V` / `Blk G0` matrices (left / right multiplication). + +**Gadget (4 ops, at the shared chart c):** `add h1 h2 (+1); add h2 h1 (-1); add h1 h2 (+1); scale h2 (-1)`. `gadget_run`: rows of h1,h2 exchanged, nothing else changes; `gadget_legal`. +- `tail_run`: gadget, then every later event renamed h1<->h2 => final state = unswapped final with rows h1,h2 exchanged (F' = P F). +- `head_run`: earlier events renamed, gadget, original later events (sigma-symmetric start) => every final row has its h1/h2 coordinates exchanged (F' = F P). + +**(1) legality.** `Undo V G0 F F'` := exists V mix L (identity off V x V) and prefix M (identity off G0 x G0) with L F' M = F. +- `tail_if`/`head_if`: both in V (tail) / both in G0 (head) => undone (L = P, resp. M = P). +- `undo_one_iff` (identity finals, no other hypothesis): undone iff (both V) or (both G0). +- `tail_iff`, `tail_iff_span`: tail swap undone iff both V, GIVEN rigidity of the prefix (the unchanged non-V rows pin M = 1; `rigid_of_span` derives it from a spanning condition). +- `head_iff`: head swap undone iff both G0, GIVEN a non-V row with F x h1 != F x h2. + +**(2) ladder.** `Traj.cost f t = f(e-b) - sum f(gaps)` (`cost_stopCost`: equals RelaySandwich.stopCost on the equal-move ladder). `Traj.swap`: (b1,e2,pre1++suf2), (b2,e1,pre2++suf1). +- `stays_multiset`: the multiset of stays is unchanged; `swap_wf`: swapped trajectories are again consistent. +- `delta_eq`: change = f(e2-b1)+f(e1-b2)-f(e1-b1)-f(e2-b2). +- `delta_zero_end` (e1 = e2, both end in V), `delta_zero_birth` (b1 = b2 = 0), `swap_null`: hub-undoable => ladder change 0. + +**(3) converse.** `nonzero_not_undoable`: nonzero change => not undoable. `converse_witness` (concrete): helper 0 born dim 5 ends 7 (no hub), helper 1 born {0} ends V (dim 9): f = r ln r change = 7 ln 7 + 4 ln 4 - 2 ln 2 - 9 ln 9 ~ -1.995 < 0 (`witness_num`, 7^7 2^6 < 3^18), and neither the tail nor the head swap is undone by any L, M. + +**Finding (M3 wording needs scope).** "tswap legal iff both end in V; hswap iff both born in {0}" is true only with a hypothesis: `tail_prefix_counterexample` (identity finals, both helpers in G0, none in V) is a tail swap undone by the prefix alone. Corrected statement: for identity-final helpers the swap is undone iff (both V) or (both G0) (`undo_one_iff`); the per-kind iff needs prefix rigidity (tail) / a separating non-V row (head). In the real word the non-V rows do pin the prefix (M3's controls XT/XH fail at settle3), but that is an input [C], not a consequence. + +**Scope.** Matrix-level model: L, M are not required invertible (strengthens only-if). The M3 census numbers (8,282 pairs, 7,390 absorbable) are data, not re-proved. Mixed gadget placement (swap back later) is not modelled. diff --git a/research/p104-native-ceiling/lean/Nov15/SwapWord.lean b/research/p104-native-ceiling/lean/Nov15/SwapWord.lean new file mode 100644 index 0000000000..49dfdcbae8 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/SwapWord.lean @@ -0,0 +1,181 @@ +/- +SwapWord, See SwapWord.md. + +The SWAPBUILD edit (internal notes, from BIG/TOKENRANK TR2): at a moment when helper h's row +is exactly e_h, inject `j += c·h` (data: c = −1, just before the native's own `h += j`, so the pair is +the swap `j -= h; h += j`). General facts in TokenCancel's op model: +* `run_diff`: the run is affine in the rows; the difference of two runs with equal locations is the + run of the difference with births read as INITs. +* `inject`: the injection changes the final rows ONLY in column h: final' r = final r + δ r • e_h. +* `inject_two`: two injections (457 → 242, 461 → X10) change the final rows only in columns h1, h2. +* `inject_col`: every final row is unchanged on every column k ≠ h, for every register (non-V-enders included). +* `absorb`: the debt is absorbed by the V mix: if e_h lies in the span of the V targets (h ends at V + with target e_h), the non-V-enders end on target, the original V-ender rows lie in that span and + targets are independent, then the edited run has a V mix iff it is loss-free. + +Build (imports the RankLawC olean; see RankLawC.lean for the chain): + lake env lean -o .lake/build/lib/lean/Nov15/RankLawC.olean Nov15/RankLawC.lean + lake env lean Nov15/SwapWord.lean +-/ +import Nov15.RankLawC + +set_option linter.unusedSectionVars false + +namespace SwapWord +open Submodule Module TokenCancel RankLaw + +variable {K Reg C : Type*} [Field K] [DecidableEq Reg] [DecidableEq C] + +/-- Births read as INITs (a birth writes the same e_i in both runs, so the difference row is 0). -/ +def unborn : Ev K Reg C → Ev K Reg C + | .born i c => .init i c + | e => e + +theorem run_append (s : St K Reg C) (p q : List (Ev K Reg C)) : + run s (p ++ q) = run (run s p) q := by + induction p generalizing s with + | nil => rfl + | cons e p ih => exact ih (step s e) + +lemma upd_sub (f g : Reg → Reg → K) (i : Reg) (a b : Reg → K) : + Function.update f i a - Function.update g i b = Function.update (f - g) i (a - b) := by + funext k; by_cases hk : k = i + · subst hk; simp + · simp [Function.update_of_ne hk] + +/-- One step of the difference. -/ +theorem step_diff (s t : St K Reg C) (hl : s.loc = t.loc) (e : Ev K Reg C) : + (step t e).loc = (step s e).loc ∧ + (step t e).row - (step s e).row = (step ⟨t.row - s.row, s.loc⟩ (unborn e)).row := by + cases e with + | born i c => exact ⟨by simp [step, hl], by simp [step, unborn, upd_sub]⟩ + | init i c => exact ⟨by simp [step, hl], by simp [step, unborn, upd_sub]⟩ + | move i c => exact ⟨by simp [step, hl], by simp [step, unborn]⟩ + | add i j a c => + refine ⟨by simp [step, hl], ?_⟩ + simp only [step, unborn, upd_sub, Pi.sub_apply] + congr 1; rw [smul_sub]; abel + | scale i u c => exact ⟨by simp [step, hl], by simp [step, unborn, upd_sub, smul_sub]⟩ + | clear i c => exact ⟨by simp [step, hl], by simp [step, unborn, upd_sub]⟩ + | copy i j c => exact ⟨by simp [step, hl], by simp [step, unborn, upd_sub]⟩ + +/-- **Difference law.** Two runs of the same events from states with equal locations differ by the +run of the difference state (births read as INITs). -/ +theorem run_diff : ∀ (evs : List (Ev K Reg C)) (s t : St K Reg C), s.loc = t.loc → + (run t evs).loc = (run s evs).loc ∧ + (run t evs).row - (run s evs).row = (run ⟨t.row - s.row, s.loc⟩ (evs.map unborn)).row + | [], s, t, hl => ⟨hl.symm, rfl⟩ + | e :: es, s, t, hl => by + obtain ⟨h1, h2⟩ := step_diff s t hl e + have ih := run_diff es (step s e) (step t e) h1.symm + refine ⟨ih.1, ?_⟩ + simp only [run, List.map_cons] + rw [ih.2] + have hst : (⟨(step t e).row - (step s e).row, (step s e).loc⟩ : St K Reg C) = + step ⟨t.row - s.row, s.loc⟩ (unborn e) := by + cases e <;> simp only [step, unborn] at h2 ⊢ <;> rw [h2] + rw [hst] + +/-- With no births, every op keeps all rows inside a fixed subspace P. -/ +theorem rows_in_run (P : Submodule K (Reg → K)) : + ∀ (evs : List (Ev K Reg C)) (d : St K Reg C), (∀ r, d.row r ∈ P) → + ∀ r, (run d (evs.map unborn)).row r ∈ P + | [], d, hd => hd + | e :: es, d, hd => by + simp only [List.map_cons, run] + refine rows_in_run P es _ (fun r => ?_) + by_cases hr : r = (match e with + | .born i _ | .init i _ | .move i _ | .add i _ _ _ | .scale i _ _ | .clear i _ | .copy i _ _ => i) + · cases e <;> simp only [step, unborn] at hr ⊢ <;> subst hr <;> + simp [P.zero_mem, P.add_mem, P.smul_mem, hd] + · cases e <;> simp only [step, unborn] at hr ⊢ <;> simp [Function.update_of_ne hr, hd] + +/-- **Injection law.** If h's row is exactly e_h after the prefix p, injecting `j += c·h` there +changes the final rows only by multiples of e_h. -/ +theorem inject (s : St K Reg C) (p q : List (Ev K Reg C)) (h j : Reg) (c : K) (ch : C) + (hrow : (run s p).row h = Pi.single h 1) : + ∃ δ : Reg → K, ∀ r, (run s (p ++ .add j h c ch :: q)).row r = + (run s (p ++ q)).row r + δ r • (Pi.single h 1 : Reg → K) := by + set s0 := run s p + set t := step s0 (.add j h c ch) + have hl : s0.loc = t.loc := rfl + obtain ⟨-, hd⟩ := run_diff q s0 t hl + have hin : ∀ r, (t.row - s0.row) r ∈ K ∙ (Pi.single h 1 : Reg → K) := by + intro r + by_cases hr : r = j + · subst hr; simp [t, step, hrow, mem_span_singleton] + · simp [t, step, Function.update_of_ne hr] + have hall := rows_in_run (K ∙ (Pi.single h 1 : Reg → K)) q ⟨t.row - s0.row, s0.loc⟩ hin + have : ∀ r, ∃ a : K, a • (Pi.single h 1 : Reg → K) = + (run t q).row r - (run s0 q).row r := by + intro r + have e := congrFun hd r + rw [Pi.sub_apply] at e + rw [e]; exact mem_span_singleton.1 (hall r) + choose δ hδ using this + refine ⟨δ, fun r => ?_⟩ + rw [run_append, run_append] + change (run t q).row r = _ + rw [← sub_add_cancel ((run t q).row r) ((run s0 q).row r), ← hδ r, add_comm] + +/-- Column form: every final row (non-V-enders included) is unchanged on every column k ≠ h. -/ +theorem inject_col (s : St K Reg C) (p q : List (Ev K Reg C)) (h j : Reg) (c : K) (ch : C) + (hrow : (run s p).row h = Pi.single h 1) (r k : Reg) (hk : k ≠ h) : + (run s (p ++ .add j h c ch :: q)).row r k = (run s (p ++ q)).row r k := by + obtain ⟨δ, hδ⟩ := inject s p q h j c ch hrow + rw [hδ r]; simp [hk] + +/-- **Two injections** (the SWAPBUILD "both" word: 457 → 242, then 461 → X10). Hypotheses: h1 = e_h1 +at the first point of the unedited prefix, and h2 = e_h2 at the second point of the once-edited word. -/ +theorem inject_two (s : St K Reg C) (p1 q1 q2 : List (Ev K Reg C)) (h1 j1 h2 j2 : Reg) (c1 c2 : K) + (ch1 ch2 : C) + (hrow1 : (run s p1).row h1 = Pi.single h1 1) + (hrow2 : (run s (p1 ++ .add j1 h1 c1 ch1 :: q1)).row h2 = Pi.single h2 1) : + ∃ δ1 δ2 : Reg → K, ∀ r, + (run s (p1 ++ .add j1 h1 c1 ch1 :: q1 ++ .add j2 h2 c2 ch2 :: q2)).row r = + (run s (p1 ++ q1 ++ q2)).row r + δ1 r • (Pi.single h1 1 : Reg → K) + + δ2 r • (Pi.single h2 1 : Reg → K) := by + obtain ⟨δ2, hδ2⟩ := inject s (p1 ++ .add j1 h1 c1 ch1 :: q1) q2 h2 j2 c2 ch2 hrow2 + obtain ⟨δ1, hδ1⟩ := inject s p1 (q1 ++ q2) h1 j1 c1 ch1 hrow1 + refine ⟨δ1, δ2, fun r => ?_⟩ + rw [hδ2 r] + have e1 : p1 ++ Ev.add j1 h1 c1 ch1 :: q1 ++ q2 = p1 ++ Ev.add j1 h1 c1 ch1 :: (q1 ++ q2) := by simp + rw [e1, hδ1 r, List.append_assoc] + +/-- Two-column form: every final row is unchanged on every column outside {h1, h2}. -/ +theorem inject_two_col (s : St K Reg C) (p1 q1 q2 : List (Ev K Reg C)) (h1 j1 h2 j2 : Reg) + (c1 c2 : K) (ch1 ch2 : C) + (hrow1 : (run s p1).row h1 = Pi.single h1 1) + (hrow2 : (run s (p1 ++ .add j1 h1 c1 ch1 :: q1)).row h2 = Pi.single h2 1) + (r k : Reg) (hk1 : k ≠ h1) (hk2 : k ≠ h2) : + (run s (p1 ++ .add j1 h1 c1 ch1 :: q1 ++ .add j2 h2 c2 ch2 :: q2)).row r k = + (run s (p1 ++ q1 ++ q2)).row r k := by + obtain ⟨δ1, δ2, hδ⟩ := inject_two s p1 q1 q2 h1 j1 h2 j2 c1 c2 ch1 ch2 hrow1 hrow2 + rw [hδ r]; simp [hk1, hk2] + +/-- **The debt is absorbed by the V mix.** Let `evs` be the edited (hub-deleted) word and `X0` the +unedited end rows. Suppose the edited end rows differ from X0 only along e_h (`inject`), the +non-V-enders end on target (the TR2 column condition, data), the unedited V-ender rows lie in +B = span V targets, e_h ∈ B (h ends at V with target e_h) and B ⊓ N = ⊥. Then the edited run has a +V mix iff it is loss-free. -/ +theorem absorb [Fintype Reg] (z V : C) (s : St K Reg C) (T : Finset Reg) (evs : List (Ev K Reg C)) + (hL : Legal z V s evs) (hN : ∀ e ∈ evs, NZ e) (hG : Good s T) (hS : Sp s = TS T) + (Rf : Reg → Reg → K) (G1 : Finset Reg) (h : Reg) (X0 : Reg → Reg → K) (δ : Reg → K) + (hX : ∀ r, (run s evs).row r = X0 r + δ r • (Pi.single h 1 : Reg → K)) + (hNon : ∀ r ∉ G1, (run s evs).row r = Rf r) + (hTgt : span K (Set.range Rf) = TS (tokRun T evs)) + (hX0 : ∀ g ∈ G1, X0 g ∈ span K (Rf '' (G1 : Set Reg))) + (he : (Pi.single h 1 : Reg → K) ∈ span K (Rf '' (G1 : Set Reg))) + (hBN : span K (Rf '' (G1 : Set Reg)) ⊓ span K (Rf '' (G1 : Set Reg)ᶜ) = ⊥) : + VMix (run s evs).row Rf G1 ↔ ¬ Loss s evs := by + rw [RankLawC.rank_law_indep z V s T evs hL hN hG hS Rf G1 hNon hTgt hBN] + refine ⟨And.left, fun hl => ⟨hl, fun g hg => ?_⟩⟩ + rw [hX g]; exact add_mem (hX0 g hg) (smul_mem _ _ he) + +end SwapWord + +#print axioms SwapWord.absorb +#print axioms SwapWord.inject_two_col +#print axioms SwapWord.inject_col +#print axioms RankLawC.rank_law_proj +#print axioms RankLawC.rank_law_of_gen diff --git a/research/p104-native-ceiling/lean/Nov15/TokenCancel.lean b/research/p104-native-ceiling/lean/Nov15/TokenCancel.lean new file mode 100644 index 0000000000..5686668ec3 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/TokenCancel.lean @@ -0,0 +1,452 @@ +/- +BIG-TOKENCANCEL T1 (hub blindness) and T2 (difference lemma), Source: internal notes See TokenCancel.md. + +Op model: registers `Reg`, charts `C` with two hubs `z` (= {0}) and `V`; rows in initial-row +coordinates `Reg → K`. Events carry their chart. Legal = co-presence plus the two [C] facts of +T1(a)/(b): no MOVE enters z and no MOVE leaves V. +-/ +import Mathlib.LinearAlgebra.Span.Basic +import Mathlib.LinearAlgebra.Pi +import Mathlib.Tactic.Abel +import Mathlib.Algebra.BigOperators.Fin + +set_option linter.unusedSectionVars false + +namespace TokenCancel + +inductive Ev (K Reg C : Type*) + | born (i : Reg) (c : C) + | init (i : Reg) (c : C) + | move (i : Reg) (c : C) + | add (i j : Reg) (a : K) (c : C) + | scale (i : Reg) (u : K) (c : C) + | clear (i : Reg) (c : C) + | copy (i j : Reg) (c : C) + +structure St (K Reg C : Type*) where + row : Reg → Reg → K + loc : Reg → Option C + +variable {K Reg C : Type*} [Field K] [DecidableEq Reg] [DecidableEq C] + +def step (s : St K Reg C) : Ev K Reg C → St K Reg C + | .born i c => ⟨Function.update s.row i (Pi.single i 1), Function.update s.loc i (some c)⟩ + | .init i c => ⟨Function.update s.row i 0, Function.update s.loc i (some c)⟩ + | .move i c => ⟨s.row, Function.update s.loc i (some c)⟩ + | .add i j a _ => ⟨Function.update s.row i (s.row i + a • s.row j), s.loc⟩ + | .scale i u _ => ⟨Function.update s.row i (u • s.row i), s.loc⟩ + | .clear i _ => ⟨Function.update s.row i 0, s.loc⟩ + | .copy i j _ => ⟨Function.update s.row i (s.row j), s.loc⟩ + +def run (s : St K Reg C) : List (Ev K Reg C) → St K Reg C + | [] => s + | e :: es => run (step s e) es + +variable (z V : C) + +/-- Legality: co-presence at the event's chart; births/INITs of absent registers; +MOVEs never enter `z` and never leave `V` (T1(a), T1(b), checked [C] on #7623). -/ +def LegalEv (s : St K Reg C) : Ev K Reg C → Prop + | .born i _ => s.loc i = none + | .init i _ => s.loc i = none + | .move i c => ∃ c0, s.loc i = some c0 ∧ c0 ≠ V ∧ c ≠ z + | .add i j _ c => i ≠ j ∧ s.loc i = some c ∧ s.loc j = some c + | .scale i _ c => s.loc i = some c + | .clear i c => s.loc i = some c + | .copy i j c => s.loc i = some c ∧ s.loc j = some c + +def Legal : St K Reg C → List (Ev K Reg C) → Prop + | _, [] => True + | s, e :: es => LegalEv z V s e ∧ Legal (step s e) es + +/-- An op (not a birth/INIT/MOVE) at a hub. -/ +def hubOp : Ev K Reg C → Prop + | .add _ _ _ c | .scale _ _ c | .clear _ c | .copy _ _ c => c = z ∨ c = V + | _ => False + +instance (e : Ev K Reg C) : Decidable (hubOp z V e) := by + cases e <;> simp only [hubOp] <;> infer_instance + +variable (h : Reg) + +/-- The interior coefficient program: tracks the e_h-coefficient, ignoring every hub op. -/ +def sig (σ : Reg → K) : Ev K Reg C → Reg → K + | .born i _ => Function.update σ i (if i = h then 1 else 0) + | .init i _ => Function.update σ i 0 + | .move _ _ => σ + | .add i j a c => if c = z ∨ c = V then σ else Function.update σ i (σ i + a * σ j) + | .scale i u c => if c = z ∨ c = V then σ else Function.update σ i (u * σ i) + | .clear i c => if c = z ∨ c = V then σ else Function.update σ i 0 + | .copy i j c => if c = z ∨ c = V then σ else Function.update σ i (σ j) + +def sigRun (σ : Reg → K) : List (Ev K Reg C) → Reg → K + | [] => σ + | e :: es => sigRun (sig z V h σ e) es + +/-- The program is blind to hub ops: it equals the program run on the interior subsequence. -/ +theorem sigRun_filter (σ : Reg → K) (evs : List (Ev K Reg C)) : + sigRun z V h σ evs = sigRun z V h σ (evs.filter fun e => ¬ hubOp z V e) := by + induction evs generalizing σ with + | nil => rfl + | cons e es ih => + by_cases he : hubOp z V e + · have : sig z V h σ e = σ := by + cases e <;> simp_all [hubOp, sig] + simp [sigRun, he, this, ih] + · simp [sigRun, he, ih] + +/-- Invariant: rows not at V carry the program's e_h-coefficient; rows at z carry 0. -/ +def Inv (s : St K Reg C) (σ : Reg → K) : Prop := + (∀ r, s.loc r ≠ some V → s.row r h = σ r) ∧ (∀ r, s.loc r = some z → s.row r h = 0) + +lemma inv_update (s : St K Reg C) (σ σ' : Reg → K) (i : Reg) (nr : Reg → K) + (hI : Inv z V h s σ) (hσ : ∀ r, r ≠ i → σ' r = σ r) + (hnew : s.loc i ≠ some V → nr h = σ' i) (hz : s.loc i = some z → nr h = 0) : + Inv z V h ⟨Function.update s.row i nr, s.loc⟩ σ' := by + refine ⟨fun r hr => ?_, fun r hr => ?_⟩ + · by_cases hri : r = i + · subst hri; simpa using hnew hr + · simp only [Function.update_of_ne hri]; rw [hσ r hri]; exact hI.1 r hr + · by_cases hri : r = i + · subst hri; simpa using hz hr + · simp only [Function.update_of_ne hri]; exact hI.2 r hr + +theorem inv_step (s : St K Reg C) (σ : Reg → K) (e : Ev K Reg C) + (hI : Inv z V h s σ) (hL : LegalEv z V s e) (hb : ∀ c, e = .born h c → c ≠ z) : + Inv z V h (step s e) (sig z V h σ e) := by + have hI1 := hI.1 + have hI2 := hI.2 + -- coefficient of a register present at chart c + have atz : ∀ i c, s.loc i = some c → c = z → s.row i h = 0 := fun i c hi hc => + hI2 i (hc ▸ hi) + have notV : ∀ i c, s.loc i = some c → c ≠ V → s.row i h = σ i := fun i c hi hc => + hI1 i (by rw [hi]; simpa using hc) + cases e with + | born i c => + refine ⟨fun r _ => ?_, fun r hr => ?_⟩ + · by_cases hri : r = i + · subst hri; simp [step, sig, Pi.single_apply, eq_comm] + · simp only [step, sig, Function.update_of_ne hri] at * + exact hI1 r (by simpa [step, Function.update_of_ne hri] using ‹_›) + · by_cases hri : r = i + · subst hri + simp only [step, Function.update_self, Option.some.injEq] at hr + have : r ≠ h := fun hrh => hb c (by rw [hrh]) hr + simp [step, this.symm] + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact hI2 r hr + | init i c => + refine ⟨fun r hr => ?_, fun r hr => ?_⟩ + · by_cases hri : r = i + · subst hri; simp [step, sig] + · simp only [step, sig, Function.update_of_ne hri] at hr ⊢; exact hI1 r hr + · by_cases hri : r = i + · subst hri; simp [step] + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact hI2 r hr + | move i c => + obtain ⟨c0, hc0, hc0V, hcz⟩ := hL + refine ⟨fun r hr => ?_, fun r hr => ?_⟩ + · by_cases hri : r = i + · subst hri; exact hI1 r (by rw [hc0]; simpa using hc0V) + · simp only [step, sig, Function.update_of_ne hri] at hr ⊢; exact hI1 r hr + · by_cases hri : r = i + · subst hri; simp [step] at hr; exact absurd hr hcz + · simp only [step, Function.update_of_ne hri] at hr ⊢; exact hI2 r hr + | add i j a c => + obtain ⟨hij, hi, hj⟩ := hL + by_cases hc : c = z ∨ c = V + · have hs : sig z V h σ (.add i j a c) = σ := by simp [sig, hc] + rw [hs] + apply inv_update z V h s σ σ i _ hI (fun _ _ => rfl) + · intro hiV + have hcV : c ≠ V := fun h' => hiV (h' ▸ hi) + have hcz : c = z := hc.resolve_right hcV + simp [atz i c hi hcz, atz j c hj hcz, ← notV i c hi hcV] + · intro hiz + have hcz : c = z := by rw [hi] at hiz; exact Option.some.inj hiz + simp [atz i c hi hcz, atz j c hj hcz] + · push Not at hc + have hs : sig z V h σ (.add i j a c) = Function.update σ i (σ i + a * σ j) := by + simp [sig, hc] + rw [hs] + apply inv_update z V h s σ _ i _ hI (fun r hr => Function.update_of_ne hr _ _) + · intro _; simp [notV i c hi hc.2, notV j c hj hc.2] + · intro hiz; rw [hi] at hiz; exact absurd (Option.some.inj hiz) hc.1 + | scale i u c => + have hi : s.loc i = some c := hL + by_cases hc : c = z ∨ c = V + · have hs : sig z V h σ (.scale i u c) = σ := by simp [sig, hc] + rw [hs] + apply inv_update z V h s σ σ i _ hI (fun _ _ => rfl) + · intro hiV + have hcV : c ≠ V := fun h' => hiV (h' ▸ hi) + have hcz : c = z := hc.resolve_right hcV + simp [atz i c hi hcz, ← notV i c hi hcV] + · intro hiz + have hcz : c = z := by rw [hi] at hiz; exact Option.some.inj hiz + simp [atz i c hi hcz] + · push Not at hc + have hs : sig z V h σ (.scale i u c) = Function.update σ i (u * σ i) := by + simp [sig, hc] + rw [hs] + apply inv_update z V h s σ _ i _ hI (fun r hr => Function.update_of_ne hr _ _) + · intro _; simp [notV i c hi hc.2] + · intro hiz; rw [hi] at hiz; exact absurd (Option.some.inj hiz) hc.1 + | clear i c => + have hi : s.loc i = some c := hL + by_cases hc : c = z ∨ c = V + · have hs : sig z V h σ (.clear i c) = σ := by simp [sig, hc] + rw [hs] + apply inv_update z V h s σ σ i _ hI (fun _ _ => rfl) + · intro hiV + have hcV : c ≠ V := fun h' => hiV (h' ▸ hi) + have hcz : c = z := hc.resolve_right hcV + simp [← notV i c hi hcV, atz i c hi hcz] + · intro _; simp + · push Not at hc + have hs : sig z V h σ (.clear i c) = Function.update σ i 0 := by simp [sig, hc] + rw [hs] + apply inv_update z V h s σ _ i _ hI (fun r hr => Function.update_of_ne hr _ _) + · intro _; simp + · intro _; simp + | copy i j c => + obtain ⟨hi, hj⟩ := hL + by_cases hc : c = z ∨ c = V + · have hs : sig z V h σ (.copy i j c) = σ := by simp [sig, hc] + rw [hs] + apply inv_update z V h s σ σ i _ hI (fun _ _ => rfl) + · intro hiV + have hcV : c ≠ V := fun h' => hiV (h' ▸ hi) + have hcz : c = z := hc.resolve_right hcV + simp [atz j c hj hcz, ← notV i c hi hcV, atz i c hi hcz] + · intro hiz + have hcz : c = z := by rw [hi] at hiz; exact Option.some.inj hiz + simp [atz j c hj hcz] + · push Not at hc + have hs : sig z V h σ (.copy i j c) = Function.update σ i (σ j) := by simp [sig, hc] + rw [hs] + apply inv_update z V h s σ _ i _ hI (fun r hr => Function.update_of_ne hr _ _) + · intro _; simp [notV j c hj hc.2] + · intro hiz; rw [hi] at hiz; exact absurd (Option.some.inj hiz) hc.1 + +def start : St K Reg C := ⟨fun _ => 0, fun _ => none⟩ + +theorem inv_run : ∀ (s : St K Reg C) (σ : Reg → K) (evs : List (Ev K Reg C)), + Inv z V h s σ → Legal z V s evs → (∀ c, Ev.born h c ∈ evs → c ≠ z) → + Inv z V h (run s evs) (sigRun z V h σ evs) + | _, _, [], hI, _, _ => hI + | s, σ, e :: es, hI, ⟨hL, hLs⟩, hb => + inv_run (step s e) (sig z V h σ e) es + (inv_step z V h s σ e hI hL (fun c he => hb c (by simp [he]))) + hLs (fun c hc => hb c (by simp [hc])) + +/-- **T1 (hub blindness).** In a legal run from the empty state in which `h` is not born at the +hub z (h off-hub born), every register r not at V at the end has e_h-coefficient equal to the +interior program's value: hub ops never enter it. -/ +theorem T1_hub_blind (evs : List (Ev K Reg C)) (hL : Legal z V start evs) + (hb : ∀ c, Ev.born h c ∈ evs → c ≠ z) (r : Reg) (hr : (run start evs).loc r ≠ some V) : + (run start evs).row r h = sigRun z V h (fun _ => 0) (evs.filter fun e => ¬ hubOp z V e) r := by + have hI : Inv z V h (start : St K Reg C) (fun _ => 0) := + ⟨fun _ _ => rfl, fun r hr => by simp [start] at hr⟩ + rw [(inv_run z V h start _ evs hI hL hb).1 r hr, sigRun_filter] + +/-- **T1, two-run form.** Two legal runs with the same interior subsequence give every register +that is not at V at the end of both the same e_h-coefficient. -/ +theorem T1_two_runs (evs evs' : List (Ev K Reg C)) + (hL : Legal z V start evs) (hL' : Legal z V start evs') + (hb : ∀ c, Ev.born h c ∈ evs → c ≠ z) (hb' : ∀ c, Ev.born h c ∈ evs' → c ≠ z) + (hfil : evs.filter (fun e => ¬ hubOp z V e) = evs'.filter (fun e => ¬ hubOp z V e)) + (r : Reg) (hr : (run start evs).loc r ≠ some V) (hr' : (run start evs').loc r ≠ some V) : + (run start evs).row r h = (run start evs').row r h := by + rw [T1_hub_blind z V h evs hL hb r hr, T1_hub_blind z V h evs' hL' hb' r hr', hfil] + +/-! ## T2 difference lemma (direct carrier) + +y's row evolves only by: `addK a r` (y += a·row_k, with row_k's e_k-coefficient 1), `addO w` +(y += w with w's e_k-coefficient 0) and `scale u` (prose leaves SCALE of y unstated; it is allowed). +`recv` tracks the net receipt from k, `A` the accumulated e_k-coefficient. -/ + +inductive YOp (K Reg : Type*) + | addK (a : K) (r : Reg → K) + | addO (w : Reg → K) + | scale (u : K) + +/-- (y, receipt from k, effective coefficient sum). -/ +def yStep : (Reg → K) × (Reg → K) × K → YOp K Reg → (Reg → K) × (Reg → K) × K + | (y, R, A), .addK a r => (y + a • r, R + a • r, A + a) + | (y, R, A), .addO w => (y + w, R, A) + | (y, R, A), .scale u => (u • y, u • R, u * A) + +def yRun (st : (Reg → K) × (Reg → K) × K) : List (YOp K Reg) → (Reg → K) × (Reg → K) × K + | [] => st + | o :: os => yRun (yStep st o) os + +/-- Invariant of the y-replay: y's e_k-coefficient equals the accumulated coefficient A, and +R − A·r1 stays in any submodule N containing every (row_k at a contact) − r1. -/ +theorem T2_inv (k : Reg) (r1 : Reg → K) (N : Submodule K (Reg → K)) : + ∀ (ops : List (YOp K Reg)) (y R : Reg → K) (A : K), + (∀ a r, YOp.addK a r ∈ ops → r k = 1 ∧ r - r1 ∈ N) → (∀ w, YOp.addO w ∈ ops → w k = 0) → + y k = A → R - A • r1 ∈ N → + (yRun (y, R, A) ops).1 k = (yRun (y, R, A) ops).2.2 ∧ + (yRun (y, R, A) ops).2.1 - (yRun (y, R, A) ops).2.2 • r1 ∈ N + | [], _, _, _, _, _, hy, hR => ⟨hy, hR⟩ + | o :: os, y, R, A, hK, hO, hy, hR => by + have hK' : ∀ a r, YOp.addK a r ∈ os → r k = 1 ∧ r - r1 ∈ N := + fun a r h => hK a r (List.mem_cons_of_mem _ h) + have hO' : ∀ w, YOp.addO w ∈ os → w k = 0 := fun w h => hO w (List.mem_cons_of_mem _ h) + cases o with + | addK a r => + obtain ⟨hrk, hrN⟩ := hK a r List.mem_cons_self + apply T2_inv k r1 N os (y + a • r) (R + a • r) (A + a) hK' hO' + · simp [hy, hrk] + · have : R + a • r - (A + a) • r1 = (R - A • r1) + a • (r - r1) := by + rw [add_smul, smul_sub]; abel + rw [this]; exact N.add_mem hR (N.smul_mem a hrN) + | addO w => + have hwk := hO w List.mem_cons_self + apply T2_inv k r1 N os (y + w) R A hK' hO' + · simp [hy, hwk] + · exact hR + | scale u => + apply T2_inv k r1 N os (u • y) (u • R) (u * A) hK' hO' + · simp [hy] + · have : u • R - (u * A) • r1 = u • (R - A • r1) := by rw [smul_sub, mul_smul] + rw [this]; exact N.smul_mem u hR + +/-- **T2 (difference lemma, direct carrier).** y starts with e_k-coefficient 0 and its row changes +only through `ops`: contacts y += a·row_k(t) (row_k(t) has e_k-coefficient 1), additions of rows +free of e_k, and SCALEs of y. If y's final e_k-coefficient is 0 (its SPEC final row has no helper +coordinate; T1: no hub op can fix it), then +* the effective coefficients sum to 0, and +* the net receipt from k lies in span{row_k(t_i) − row_k(t_1)}: what k carried into its first + contact with y never reaches y net (any reference row r1, in particular row_k at the first contact). -/ +theorem T2_difference (k : Reg) (r1 : Reg → K) (ops : List (YOp K Reg)) (y0 : Reg → K) + (hy0 : y0 k = 0) + (hK : ∀ a r, YOp.addK a r ∈ ops → r k = 1) (hO : ∀ w, YOp.addO w ∈ ops → w k = 0) + (hfin : (yRun (y0, 0, 0) ops).1 k = 0) : + (yRun (y0, 0, 0) ops).2.2 = 0 ∧ + (yRun (y0, 0, 0) ops).2.1 ∈ + Submodule.span K {x | ∃ a r, YOp.addK a r ∈ ops ∧ x = r - r1} := by + set N := Submodule.span K {x | ∃ a r, YOp.addK a r ∈ ops ∧ x = r - r1} + have := T2_inv k r1 N ops y0 0 0 + (fun a r h => ⟨hK a r h, Submodule.subset_span ⟨a, r, h, rfl⟩⟩) hO hy0 (by simp) + have hA : (yRun (y0, 0, 0) ops).2.2 = 0 := by rw [← this.1, hfin] + refine ⟨hA, ?_⟩ + have h2 := this.2 + rwa [hA, zero_smul, sub_zero] at h2 + +/-- The receipt bookkeeping is faithful: the final row is y0 scaled, plus the receipt from k, plus +the other additions (scaled by later SCALEs). Here only the e_k-coordinate part matters, so we +record the coefficient identity: final e_k-coefficient = (Π scales)·y0_k + A. With y0_k = 0 this is A. -/ +theorem T2_coeff (k : Reg) : ∀ (ops : List (YOp K Reg)) (y R : Reg → K) (A : K), + (∀ a r, YOp.addK a r ∈ ops → r k = 1) → (∀ w, YOp.addO w ∈ ops → w k = 0) → + y k = A → (yRun (y, R, A) ops).1 k = (yRun (y, R, A) ops).2.2 := by + intro ops y R A hK hO hy + exact (T2_inv k 0 ⊤ ops y R A (fun a r h => ⟨hK a r h, Submodule.mem_top⟩) hO hy + Submodule.mem_top).1 + +/-! ## T2, corrected Σ statement + +The literal "Σ a_i = 0" is false once y is SCALEd between contacts (`T2_literal_false`). The +correct statement uses EFFECTIVE coefficients: contact i contributes a_i · Π(scales of y after it). +`scl ops` = product of all SCALE factors of y in `ops`; `contacts ops` = (effective coefficient, +row_k at the contact) for each contact, in order. -/ + +/-- product of the SCALE factors of y in `ops`. -/ +def scl : List (YOp K Reg) → K + | [] => 1 + | .scale u :: os => u * scl os + | .addK _ _ :: os => scl os + | .addO _ :: os => scl os + +/-- contacts with their effective coefficients a_i · Π(later scales). -/ +def contacts : List (YOp K Reg) → List (K × (Reg → K)) + | [] => [] + | .addK a r :: os => (a * scl os, r) :: contacts os + | .addO _ :: os => contacts os + | .scale _ :: os => contacts os + +/-- Closed form of the coefficient and receipt trackers. -/ +theorem yRun_closed : ∀ (ops : List (YOp K Reg)) (y R : Reg → K) (A : K), + (yRun (y, R, A) ops).2.2 = scl ops * A + ((contacts ops).map Prod.fst).sum ∧ + (yRun (y, R, A) ops).2.1 = scl ops • R + ((contacts ops).map (fun p => p.1 • p.2)).sum + | [], y, R, A => by simp [yRun, scl, contacts] + | o :: os, y, R, A => by + cases o with + | addK a r => + obtain ⟨h1, h2⟩ := yRun_closed os (y + a • r) (R + a • r) (A + a) + simp only [yRun, yStep, scl, contacts, List.map_cons, List.sum_cons] + refine ⟨by rw [h1]; ring, ?_⟩ + rw [h2, smul_add, smul_smul, mul_comm (scl os) a]; abel + | addO w => + obtain ⟨h1, h2⟩ := yRun_closed os (y + w) R A + simpa only [yRun, yStep, scl, contacts] using ⟨h1, h2⟩ + | scale u => + obtain ⟨h1, h2⟩ := yRun_closed os (u • y) (u • R) (u * A) + simp only [yRun, yStep, scl, contacts] + refine ⟨by rw [h1]; ring, ?_⟩ + rw [h2, smul_smul, mul_comm (scl os) u] + +/-- **T2, corrected.** Hypotheses as in `T2_difference`. Then +* Σ (effective coefficients a_i · Π later scales of y) = 0; +* the net receipt from k is Σ eff_i · row_k(t_i) = Σ eff_i · (row_k(t_i) − r1) for ANY r1, in + particular r1 = row_k(t_1): content k carried into its first contact never reaches y net. -/ +theorem T2_corrected (k : Reg) (ops : List (YOp K Reg)) (y0 : Reg → K) + (hy0 : y0 k = 0) + (hK : ∀ a r, YOp.addK a r ∈ ops → r k = 1) (hO : ∀ w, YOp.addO w ∈ ops → w k = 0) + (hfin : (yRun (y0, 0, 0) ops).1 k = 0) (r1 : Reg → K) : + ((contacts ops).map Prod.fst).sum = 0 ∧ + (yRun (y0, 0, 0) ops).2.1 = ((contacts ops).map (fun p => p.1 • p.2)).sum ∧ + (yRun (y0, 0, 0) ops).2.1 = ((contacts ops).map (fun p => p.1 • (p.2 - r1))).sum := by + obtain ⟨h1, h2⟩ := yRun_closed ops y0 0 0 + have hA := (T2_difference k r1 ops y0 hy0 hK hO hfin).1 + rw [h1, mul_zero, zero_add] at hA + have hrec : (yRun (y0, 0, 0) ops).2.1 = ((contacts ops).map (fun p => p.1 • p.2)).sum := by + rw [h2, smul_zero, zero_add] + refine ⟨hA, hrec, ?_⟩ + have hsplit : ∀ l : List (K × (Reg → K)), + (l.map (fun p => p.1 • (p.2 - r1))).sum + = (l.map (fun p => p.1 • p.2)).sum - (l.map Prod.fst).sum • r1 := by + intro l; induction l with + | nil => simp + | cons p l ih => + simp only [List.map_cons, List.sum_cons]; rw [ih, add_smul, smul_sub]; abel + rw [hsplit, hA, zero_smul, sub_zero, hrec] + +/-- Without SCALEs of y the effective coefficients are the literal a_i, so the prose "Σ a_i = 0" +holds verbatim. -/ +theorem contacts_noscale : ∀ (ops : List (YOp K Reg)), (∀ u, YOp.scale u ∉ ops) → + (contacts ops).map Prod.fst = ops.filterMap (fun o => match o with + | .addK a _ => some a | _ => none) + | [], _ => rfl + | o :: os, h => by + have h' : ∀ u, YOp.scale u ∉ os := fun u hu => h u (List.mem_cons_of_mem _ hu) + have hs : scl os = 1 := by + clear h; induction os with + | nil => rfl + | cons o' os' ih => + cases o' with + | scale u => exact absurd List.mem_cons_self (h' u) + | addK a r => exact ih (fun u hu => h' u (List.mem_cons_of_mem _ hu)) + | addO w => exact ih (fun u hu => h' u (List.mem_cons_of_mem _ hu)) + cases o with + | addK a r => simp [contacts, hs, contacts_noscale os h'] + | addO w => simpa [contacts] using contacts_noscale os h' + | scale u => exact absurd List.mem_cons_self (h u) + +/-- The finding, formal: y += k, y *= 2, y += (−2)·k. Final e_k-coefficient 0, literal Σ a = −1, +effective Σ = 1·2 + (−2) = 0. Over ℚ with one register. -/ +theorem T2_literal_false : + let ek : Unit → ℚ := fun _ => 1 + let ops : List (YOp ℚ Unit) := [.addK 1 ek, .scale 2, .addK (-2) ek] + (yRun ((0 : Unit → ℚ), 0, 0) ops).1 () = 0 ∧ (1 : ℚ) + (-2) ≠ 0 ∧ + ((contacts ops).map Prod.fst).sum = 0 := by + refine ⟨?_, by norm_num, ?_⟩ <;> simp [yRun, yStep, contacts, scl] + +end TokenCancel + +#print axioms TokenCancel.T1_hub_blind +#print axioms TokenCancel.T1_two_runs +#print axioms TokenCancel.T2_difference +#print axioms TokenCancel.T2_corrected +#print axioms TokenCancel.contacts_noscale +#print axioms TokenCancel.T2_literal_false diff --git a/research/p104-native-ceiling/lean/Nov15/WholeFloorCover.lean b/research/p104-native-ceiling/lean/Nov15/WholeFloorCover.lean new file mode 100644 index 0000000000..7c04dd9336 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/WholeFloorCover.lean @@ -0,0 +1,24 @@ +import Nov15.WholeFloorCoverData +import Nov15.JointCeiling + +/-! WholeFloorCover : the cover F < 0 on [.0204110964, 1] for (caller 6 7) + 17 * natFloor; data in WholeFloorCoverData. -/ +namespace WholeFloorCover +open NumCertK JointCeiling CallerCost + +theorem invoice_eq_Fc (s : ℝ) : Finv s (invoice (caller 6 7) natFloor 17) = Fc cfW s := by + simp only [Finv, Fh, invoice, caller, callerT, callerP, armT, armP, natFloor, scale, Fc, cfW, + List.range_succ, List.range_zero] + norm_num + ring + +/-- **the cover**: F < 0 on [.0204110964, 1] (t = 1 - s) for the floor-native invoice. -/ +theorem cover (t : ℝ) (ht : (204110965 : ℝ) / 10 ^ 10 ≤ t) (ht1 : t ≤ 1) : + Finv (1 - t) (invoice (caller 6 7) natFloor 17) < 0 := by + rw [invoice_eq_Fc] + apply cfW_neg _ (by linarith) + push_cast + linarith + +end WholeFloorCover + +#print axioms WholeFloorCover.cover diff --git a/research/p104-native-ceiling/lean/Nov15/WholeFloorCoverData.lean b/research/p104-native-ceiling/lean/Nov15/WholeFloorCoverData.lean new file mode 100644 index 0000000000..8d59602eab --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/WholeFloorCoverData.lean @@ -0,0 +1,47 @@ +import Nov15.WholeFloorCoverData1 + +namespace WholeFloorCover +open NumCertK + +theorem cfW_p6 : Fup cfW (763/1000) (163/200) < 0 := by decide +kernel +theorem cfW_p7 : Fup cfW (163/200) (851/1000) < 0 := by decide +kernel +theorem cfW_p8 : Fup cfW (851/1000) (879/1000) < 0 := by decide +kernel +theorem cfW_p9 : Fup cfW (879/1000) (901/1000) < 0 := by decide +kernel +theorem cfW_p10 : Fup cfW (901/1000) (459/500) < 0 := by decide +kernel +theorem cfW_p11 : Fup cfW (459/500) (93/100) < 0 := by decide +kernel +theorem cfW_d : 0 < dLo cfW (93/100) (9795889035/10^10) := by decide +kernel +theorem cfW_end : Fup cfW (9795889035/10^10) (9795889035/10^10) < 0 := by decide +kernel + +theorem cfW_neg (s : ℝ) (h0 : 0 ≤ s) (hs : s ≤ ((9795889035 / 10 ^ 10 : ℚ) : ℝ)) : Fc cfW s < 0 := by + have o := cfW_ok + by_cases a1 : s ≤ (((73/250) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o 0 (73/250) (le_refl _) (by norm_num) cfW_p1 s (by simpa using h0) a1 + by_cases a2 : s ≤ (((59/125) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (73/250) (59/125) (by norm_num) (by norm_num) cfW_p2 s (by push_neg at a1; exact a1.le) a2 + by_cases a3 : s ≤ (((301/500) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (59/125) (301/500) (by norm_num) (by norm_num) cfW_p3 s (by push_neg at a2; exact a2.le) a3 + by_cases a4 : s ≤ (((87/125) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (301/500) (87/125) (by norm_num) (by norm_num) cfW_p4 s (by push_neg at a3; exact a3.le) a4 + by_cases a5 : s ≤ (((763/1000) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (87/125) (763/1000) (by norm_num) (by norm_num) cfW_p5 s (by push_neg at a4; exact a4.le) a5 + by_cases a6 : s ≤ (((163/200) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (763/1000) (163/200) (by norm_num) (by norm_num) cfW_p6 s (by push_neg at a5; exact a5.le) a6 + by_cases a7 : s ≤ (((851/1000) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (163/200) (851/1000) (by norm_num) (by norm_num) cfW_p7 s (by push_neg at a6; exact a6.le) a7 + by_cases a8 : s ≤ (((879/1000) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (851/1000) (879/1000) (by norm_num) (by norm_num) cfW_p8 s (by push_neg at a7; exact a7.le) a8 + by_cases a9 : s ≤ (((901/1000) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (879/1000) (901/1000) (by norm_num) (by norm_num) cfW_p9 s (by push_neg at a8; exact a8.le) a9 + by_cases a10 : s ≤ (((459/500) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (901/1000) (459/500) (by norm_num) (by norm_num) cfW_p10 s (by push_neg at a9; exact a9.le) a10 + by_cases a11 : s ≤ (((93/100) : ℚ) : ℝ) + · exact Fc_neg_piece cfW o (459/500) (93/100) (by norm_num) (by norm_num) cfW_p11 s (by push_neg at a10; exact a10.le) a11 + have h1 := Fc_mono cfW o (93/100) (9795889035/10^10) (by norm_num) (by norm_num) cfW_d s + (by push_neg at a11; exact a11.le) hs + have h2 := Fc_neg_piece cfW o (9795889035/10^10) (9795889035/10^10) (by norm_num) (by norm_num) cfW_end + ((9795889035/10^10 : ℚ) : ℝ) (le_refl _) (le_refl _) + linarith + +end WholeFloorCover + +#print axioms WholeFloorCover.cfW_neg diff --git a/research/p104-native-ceiling/lean/Nov15/WholeFloorCoverData1.lean b/research/p104-native-ceiling/lean/Nov15/WholeFloorCoverData1.lean new file mode 100644 index 0000000000..097aac7ee4 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/WholeFloorCoverData1.lean @@ -0,0 +1,23 @@ +import Nov15.NumCertK + +/-! +WholeFloorCoverData1 : discharges the interval-cover hypothesis of WholeFloorNest.kappa_whole_floor_nested +with kernel interval library (NumCertK): the fixed #7113 caller C(8|9) = caller 6 7 at 17 calls on the +floor native `natFloor` has F(s) < 0 for every s in [0, 1 - .0204110964]. Kernel only; no native_decide. +-/ +namespace WholeFloorCover +open NumCertK + +/-- F of (caller 6 7) + 17 * natFloor, merged by rank. -/ +def cfW : CF := [(1, -3648), (2, 1496), (8, -7456), (9, 384), + (16, -416), (17, 416), (24, -416), (25, 416), (32, -416), (33, 416), (40, -416), (41, 416), (48, -416), + (49, 416), (56, -416), (57, 416), (64, -208), (65, 416), (73, 208), (137, 208)] + +theorem cfW_ok : okR cfW := by decide +kernel +theorem cfW_p1 : Fup cfW 0 (73/250) < 0 := by decide +kernel +theorem cfW_p2 : Fup cfW (73/250) (59/125) < 0 := by decide +kernel +theorem cfW_p3 : Fup cfW (59/125) (301/500) < 0 := by decide +kernel +theorem cfW_p4 : Fup cfW (301/500) (87/125) < 0 := by decide +kernel +theorem cfW_p5 : Fup cfW (87/125) (763/1000) < 0 := by decide +kernel + +end WholeFloorCover diff --git a/research/p104-native-ceiling/lean/Nov15/WordDuality.lean b/research/p104-native-ceiling/lean/Nov15/WordDuality.lean new file mode 100644 index 0000000000..166ddb4d93 --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/WordDuality.lean @@ -0,0 +1,451 @@ +/- +WordDuality . See WordDuality.md. Source: internal notes + +D = sigma . perp . time-reversal . transpose. +Model: charts `C` with an involution `perp` (dim (perp c) = N - dim c, perp z = V), registers `Reg`, a word = initial chart of every +register + a list of events (MOVE a->b, ADD, SCALE, COPY, INIT, CLEAR). Legality = co-presence + hub rules (no MOVE leaves V, +none enters z) + a move relation R (ascent / owned descent) closed under (a,b) -> (perp b, perp a). + Part 1 legal words go to legal words, boundaries swap (`dual_run`). + Part 2 matrices (ADD / SCALE / MOVE): M(D l) = sigma-relabel of (M l)^T (`Mrec_dual`). + Part 3 invoice: helper (b,e,steps) -> (N-e, N-b, reversed swapped steps); Theorem K invoice (FibreK) unchanged (`dualH_invoice`). + Part 4 P104 boundary data under sigma: X_p, Y_p exchange (`selfdual_boundary`); 2x2 contract blocks (`hosted_block`, `nonhosted_block`). + Part 5 caveat: COPY does not dualise to an ADD at matrix level (`copy_not_add`). +Kernel only. +-/ +import Nov15.FibreK +import Mathlib.Data.Matrix.Basis +import Mathlib.Data.Matrix.Mul + +set_option linter.unusedSectionVars false +set_option linter.unusedVariables false + +namespace WordDuality +open FibreK CallerCost Matrix + +structure Charts (C : Type*) (N : ℕ) where + perp : C → C + perp_perp : ∀ c, perp (perp c) = c + dim : C → ℕ + dim_le : ∀ c, dim c ≤ N + dim_perp : ∀ c, dim (perp c) = N - dim c + z : C + V : C + perp_z : perp z = V + +namespace Charts +variable {C : Type*} {N : ℕ} (X : Charts C N) +theorem perp_V : X.perp X.V = X.z := by rw [← X.perp_z, X.perp_perp] +theorem ne_V_perp {a : C} (h : a ≠ X.V) : X.perp a ≠ X.z := by + intro h'; apply h; rw [← X.perp_perp a, h', X.perp_z] +theorem ne_z_perp {b : C} (h : b ≠ X.z) : X.perp b ≠ X.V := by + intro h'; apply h; rw [← X.perp_perp b, h', X.perp_V] +end Charts + +inductive Ev (K Reg C : Type*) + | move (i : Reg) (a b : C) + | add (i j : Reg) (q : K) (c : C) + | scale (i : Reg) (u : K) (c : C) + | copy (i j : Reg) (c : C) + | init (i : Reg) (c : C) + | clear (i : Reg) (c : C) + +variable {K Reg C : Type*} {N : ℕ} + +section Words +variable [DecidableEq Reg] + +def stepL (ℓ : Reg → C) : Ev K Reg C → (Reg → C) + | .move i _ b => Function.update ℓ i b + | _ => ℓ + +def runL (ℓ : Reg → C) : List (Ev K Reg C) → (Reg → C) + | [] => ℓ + | e :: es => runL (stepL ℓ e) es + +theorem runL_append (ℓ : Reg → C) (l1 l2 : List (Ev K Reg C)) : + runL ℓ (l1 ++ l2) = runL (runL ℓ l1) l2 := by + induction l1 generalizing ℓ with + | nil => rfl + | cons e es ih => simp [runL, ih] + +def LegalEv (X : Charts C N) (R : C → C → Prop) (ℓ : Reg → C) : Ev K Reg C → Prop + | .move i a b => ℓ i = a ∧ a ≠ X.V ∧ b ≠ X.z ∧ R a b + | .add i j _ c => i ≠ j ∧ ℓ i = c ∧ ℓ j = c + | .scale i _ c => ℓ i = c + | .copy i j c => i ≠ j ∧ ℓ i = c ∧ ℓ j = c + | .init i c => ℓ i = c + | .clear i c => ℓ i = c + +def LegalL (X : Charts C N) (R : C → C → Prop) : (Reg → C) → List (Ev K Reg C) → Prop + | _, [] => True + | ℓ, e :: es => LegalEv X R ℓ e ∧ LegalL X R (stepL ℓ e) es + +theorem LegalL_append (X : Charts C N) (R : C → C → Prop) (ℓ : Reg → C) (l1 l2 : List (Ev K Reg C)) : + LegalL X R ℓ (l1 ++ l2) ↔ LegalL X R ℓ l1 ∧ LegalL X R (runL ℓ l1) l2 := by + induction l1 generalizing ℓ with + | nil => simp [LegalL, runL] + | cons e es ih => simp [LegalL, runL, ih, and_assoc] + +variable [One K] + +/-- the dual of one event. COPY becomes ADD (valid on a clean target only; see `copy_not_add`). -/ +def dualEv (X : Charts C N) (σ : Reg ≃ Reg) : Ev K Reg C → Ev K Reg C + | .move i a b => .move (σ i) (X.perp b) (X.perp a) + | .add i j q c => .add (σ j) (σ i) q (X.perp c) + | .scale i u c => .scale (σ i) u (X.perp c) + | .copy i j c => .add (σ j) (σ i) 1 (X.perp c) + | .init i c => .clear (σ i) (X.perp c) + | .clear i c => .init (σ i) (X.perp c) + +/-- time reversal of the dualised events. -/ +def dualList (X : Charts C N) (σ : Reg ≃ Reg) (l : List (Ev K Reg C)) : List (Ev K Reg C) := + (l.map (dualEv X σ)).reverse + +theorem dualList_cons (X : Charts C N) (σ : Reg ≃ Reg) (e : Ev K Reg C) (l : List (Ev K Reg C)) : + dualList X σ (e :: l) = dualList X σ l ++ [dualEv X σ e] := by + simp [dualList] + +/-- PART 1. A legal word dualises to a legal word; the dual starts at perp of the final charts and ends at perp of the initial +charts (births and ends exchange). -/ +theorem dual_run (X : Charts C N) (R : C → C → Prop) (hR : ∀ a b, R a b → R (X.perp b) (X.perp a)) + (σ : Reg ≃ Reg) : + ∀ (l : List (Ev K Reg C)) (ℓ : Reg → C), LegalL X R ℓ l → + runL (fun r => X.perp (runL ℓ l (σ.symm r))) (dualList X σ l) = (fun r => X.perp (ℓ (σ.symm r))) ∧ + LegalL X R (fun r => X.perp (runL ℓ l (σ.symm r))) (dualList X σ l) := by + intro l + induction l with + | nil => intro ℓ _; exact ⟨rfl, trivial⟩ + | cons e es ih => + intro ℓ h + obtain ⟨he, hes⟩ := h + obtain ⟨A, B⟩ := ih (stepL ℓ e) hes + have hS : (fun r => X.perp (runL ℓ (e :: es) (σ.symm r))) = + (fun r => X.perp (runL (stepL ℓ e) es (σ.symm r))) := rfl + rw [hS, dualList_cons, runL_append, LegalL_append, A] + -- the last event + cases e with + | move i a b => + obtain ⟨h1, h2, h3, h4⟩ := he + subst h1 + refine ⟨?_, B, ?_⟩ + · simp only [runL, dualEv, stepL] + funext r + by_cases hr : r = σ i + · subst hr; simp + · have : σ.symm r ≠ i := by + intro h; apply hr; rw [← h]; simp + simp [Function.update_of_ne hr, Function.update_of_ne this] + · exact ⟨⟨by simp [stepL], X.ne_z_perp h3, X.ne_V_perp h2, hR _ _ h4⟩, trivial⟩ + | add i j q c => + obtain ⟨h1, h2, h3⟩ := he + refine ⟨?_, B, ?_⟩ + · simp [runL, dualEv, stepL] + · simp [LegalL, LegalEv, runL, dualEv, stepL, A, h2, h3] + exact fun h => h1 h.symm + | scale i u c => + refine ⟨?_, B, ?_⟩ + · simp [runL, dualEv, stepL] + · simp [LegalL, LegalEv, runL, dualEv, stepL, A]; simp [LegalEv] at he; simp [he] + | copy i j c => + obtain ⟨h1, h2, h3⟩ := he + refine ⟨?_, B, ?_⟩ + · simp [runL, dualEv, stepL] + · simp [LegalL, LegalEv, runL, dualEv, stepL, A, h2, h3] + exact fun h => h1 h.symm + | init i c => + refine ⟨?_, B, ?_⟩ + · simp [runL, dualEv, stepL] + · simp [LegalL, LegalEv, runL, dualEv, stepL, A]; simp [LegalEv] at he; simp [he] + | clear i c => + refine ⟨?_, B, ?_⟩ + · simp [runL, dualEv, stepL] + · simp [LegalL, LegalEv, runL, dualEv, stepL, A]; simp [LegalEv] at he; simp [he] + +/-- ascent and descent both survive: (a,b) ascending (dim a ≤ dim b) gives (perp b, perp a) ascending. -/ +theorem ascent_dual (X : Charts C N) : ∀ a b, X.dim a ≤ X.dim b → X.dim (X.perp b) ≤ X.dim (X.perp a) := by + intro a b h; rw [X.dim_perp, X.dim_perp]; have := X.dim_le a; have := X.dim_le b; omega + +theorem descent_dual (X : Charts C N) : ∀ a b, X.dim b ≤ X.dim a → X.dim (X.perp b) ≥ X.dim (X.perp a) := by + intro a b h; rw [X.dim_perp, X.dim_perp]; have := X.dim_le a; have := X.dim_le b; omega + +/-! ### words, boundaries -/ + +structure Word (K Reg C : Type*) where + init0 : Reg → C + evs : List (Ev K Reg C) + +def Word.fin (w : Word K Reg C) : Reg → C := runL w.init0 w.evs + +def dualWord (X : Charts C N) (σ : Reg ≃ Reg) (w : Word K Reg C) : Word K Reg C := + ⟨fun r => X.perp (w.fin (σ.symm r)), dualList X σ w.evs⟩ + +theorem dual_legal (X : Charts C N) (R : C → C → Prop) (hR : ∀ a b, R a b → R (X.perp b) (X.perp a)) + (σ : Reg ≃ Reg) (w : Word K Reg C) (h : LegalL X R w.init0 w.evs) : + LegalL X R (dualWord X σ w).init0 (dualWord X σ w).evs := (dual_run X R hR σ w.evs w.init0 h).2 + +/-- births of the dual are perp of the ends; ends of the dual are perp of the births. -/ +theorem dual_boundary (X : Charts C N) (R : C → C → Prop) (hR : ∀ a b, R a b → R (X.perp b) (X.perp a)) + (σ : Reg ≃ Reg) (w : Word K Reg C) (h : LegalL X R w.init0 w.evs) (r : Reg) : + (dualWord X σ w).init0 (σ r) = X.perp (w.fin r) ∧ (dualWord X σ w).fin (σ r) = X.perp (w.init0 r) := by + constructor + · simp [dualWord] + · have := congrFun (dual_run X R hR σ w.evs w.init0 h).1 (σ r) + simpa [Word.fin, dualWord] using this + +theorem dual_dim_boundary (X : Charts C N) (R : C → C → Prop) (hR : ∀ a b, R a b → R (X.perp b) (X.perp a)) + (σ : Reg ≃ Reg) (w : Word K Reg C) (h : LegalL X R w.init0 w.evs) (r : Reg) : + X.dim ((dualWord X σ w).init0 (σ r)) = N - X.dim (w.fin r) ∧ + X.dim ((dualWord X σ w).fin (σ r)) = N - X.dim (w.init0 r) := by + obtain ⟨a, b⟩ := dual_boundary X R hR σ w h r + rw [a, b, X.dim_perp, X.dim_perp]; exact ⟨rfl, rfl⟩ + +end Words + +/-! ### Part 2: matrices -/ +section Mat +variable [Fintype Reg] [DecidableEq Reg] [CommRing K] + +def evMat : Ev K Reg C → Matrix Reg Reg K + | .add i j q _ => 1 + Matrix.single i j q + | .scale i u _ => Matrix.diagonal (Function.update (1 : Reg → K) i u) + | _ => 1 + +/-- events with a matrix semantics (MOVE only changes location). -/ +def Lin : Ev K Reg C → Prop + | .move .. => True + | .add .. => True + | .scale .. => True + | _ => False + +/-- total matrix of a word in initial-row coordinates: later events multiply on the left. -/ +def Mrec : List (Ev K Reg C) → Matrix Reg Reg K + | [] => 1 + | e :: es => Mrec es * evMat e + +theorem Mrec_append (l1 l2 : List (Ev K Reg C)) : Mrec (l1 ++ l2) = Mrec l2 * Mrec l1 := by + induction l1 with + | nil => simp [Mrec] + | cons e es ih => simp [Mrec, ih, Matrix.mul_assoc] + +theorem evMat_dual (X : Charts C N) (σ : Reg ≃ Reg) (e : Ev K Reg C) (he : Lin e) : + evMat (dualEv X σ e) = (evMat e)ᵀ.submatrix σ.symm σ.symm := by + cases e with + | move i a b => simp [evMat, dualEv] + | add i j q c => + ext a b + simp [evMat, dualEv, Matrix.single_apply, Matrix.one_apply, Matrix.transpose_apply, Matrix.submatrix_apply, Equiv.eq_symm_apply] + | scale i u c => + ext a b + simp [evMat, dualEv, Matrix.diagonal_apply, Function.update_apply, Equiv.symm_apply_eq] + | copy _ _ _ => exact absurd he (by simp [Lin]) + | init _ _ => exact absurd he (by simp [Lin]) + | clear _ _ => exact absurd he (by simp [Lin]) + +/-- PART 2. M(D l) is the sigma-relabel of the transpose of M(l). -/ +theorem Mrec_dual (X : Charts C N) (σ : Reg ≃ Reg) : + ∀ l : List (Ev K Reg C), (∀ e ∈ l, Lin e) → Mrec (dualList X σ l) = (Mrec l)ᵀ.submatrix σ.symm σ.symm := by + intro l + induction l with + | nil => intro _; simp [dualList, Mrec] + | cons e es ih => + intro h + have he := h e (by simp) + have hes := ih (fun x hx => h x (by simp [hx])) + rw [dualList_cons, Mrec_append, hes] + simp only [Mrec, Matrix.one_mul, Matrix.transpose_mul] + rw [evMat_dual X σ e he, Matrix.submatrix_mul_equiv] + +end Mat + +/-! ### Part 3: the Theorem-K invoice is unchanged -/ +section Invoice +variable [DecidableEq Reg] + +/-- the MOVE steps (source dim, target dim) of register `r`. -/ +def regSteps (X : Charts C N) (r : Reg) (l : List (Ev K Reg C)) : List (ℕ × ℕ) := + l.filterMap fun e => match e with + | .move i a b => if i = r then some (X.dim a, X.dim b) else none + | _ => none + +def swapN (N : ℕ) (s : ℕ × ℕ) : ℕ × ℕ := (N - s.2, N - s.1) + +/-- register `r` as a FibreK helper: birth dim, end dim, steps. -/ +def helperOf (X : Charts C N) (w : Word K Reg C) (r : Reg) : Helper := + ⟨X.dim (w.init0 r), X.dim (w.fin r), regSteps X r w.evs⟩ + +/-- a helper b -> e becomes (N-e) -> (N-b), with reversed swapped steps. -/ +def dualH (N : ℕ) (h : Helper) : Helper := ⟨N - h.e, N - h.b, (h.steps.map (swapN N)).reverse⟩ + +variable [One K] + +theorem regSteps_dual (X : Charts C N) (σ : Reg ≃ Reg) (r : Reg) : + ∀ l : List (Ev K Reg C), regSteps X (σ r) (dualList X σ l) = ((regSteps X r l).map (swapN N)).reverse := by + intro l + induction l with + | nil => simp [dualList, regSteps] + | cons e es ih => + rw [dualList_cons] + have : regSteps X (σ r) (dualList X σ es ++ [dualEv X σ e]) = + regSteps X (σ r) (dualList X σ es) ++ regSteps X (σ r) [dualEv X σ e] := by + simp [regSteps, List.filterMap_append] + rw [this, ih] + cases e with + | move i a b => + by_cases h : i = r + · subst h; simp [regSteps, dualEv, swapN, X.dim_perp] + · simp [regSteps, dualEv, h] + | add i j q c => simp [regSteps, dualEv] + | scale i u c => simp [regSteps, dualEv] + | copy i j c => simp [regSteps, dualEv] + | init i c => simp [regSteps, dualEv] + | clear i c => simp [regSteps, dualEv] + +/-- PART 3a. The dual word's register `sigma r` is the dual helper of `r` (b,e) -> (N-e, N-b). -/ +theorem helperOf_dual (X : Charts C N) (R : C → C → Prop) (hR : ∀ a b, R a b → R (X.perp b) (X.perp a)) + (σ : Reg ≃ Reg) (w : Word K Reg C) (h : LegalL X R w.init0 w.evs) (r : Reg) : + helperOf X (dualWord X σ w) (σ r) = dualH N (helperOf X w r) := by + obtain ⟨b1, b2⟩ := dual_dim_boundary X R hR σ w h r + simp only [helperOf, dualH, dualWord, b1, b2] + simp only [dualWord] at b1 b2 + rw [b1, b2] + simp [regSteps_dual X σ r] + +theorem gap_swapN (N : ℕ) (s : ℕ × ℕ) (h1 : s.1 ≤ N) (h2 : s.2 ≤ N) : gap (swapN N s) = gap s := by + simp only [gap, swapN]; omega + +/-- PART 3b. Dualising a helper list leaves FibreK's invoice (Theorem K) unchanged: +births/ends (b,e) -> (N-e,N-b) keep the climb, every MOVE keeps its |Δdim|. -/ +theorem dualH_invoice (E : Inv) (tb : Table) (H : List Helper) + (hN : ∀ h ∈ H, h.b ≤ h.e ∧ h.e ≤ N ∧ ∀ s ∈ h.steps, s.1 ≤ N ∧ s.2 ≤ N) (t : ℝ) : + Fi (nativeInv E tb (H.map (dualH N))) t = Fi (nativeInv E tb H) t := by + rw [K_word, K_word] + unfold FK + have hP : PiW (H.map (dualH N)) = PiW H := by + unfold PiW + congr 1 + rw [List.map_map] + apply List.map_congr_left + intro h hh + obtain ⟨a, b, _⟩ := hN h hh + simp only [Function.comp, dualH]; omega + have hS : (((Ssum (H.map (dualH N))).map fun s => Fh (tb.tP (gap s)) t).sum) = + ((Ssum H).map fun s => Fh (tb.tP (gap s)) t).sum := by + simp only [Ssum, Multiset.map_coe, Multiset.sum_coe] + rw [sum_flatMap_map, sum_flatMap_map, List.map_map] + congr 1 + apply List.map_congr_left + intro h hh + obtain ⟨_, _, c⟩ := hN h hh + simp only [Function.comp, dualH, List.map_reverse, List.sum_reverse, List.map_map] + congr 1 + apply List.map_congr_left + intro s hs + obtain ⟨c1, c2⟩ := c s hs + simp only [Function.comp, gap_swapN N s c1 c2] + rw [hP, hS] + +theorem dualH_root (c E : Inv) (tb : Table) (H : List Helper) (L : ℕ) + (hN : ∀ h ∈ H, h.b ≤ h.e ∧ h.e ≤ N ∧ ∀ s ∈ h.steps, s.1 ≤ N ∧ s.2 ≤ N) (κ : ℝ) : + IsRoot (Fi (invoice c (nativeInv E tb (H.map (dualH N))) L)) κ ↔ + IsRoot (Fi (invoice c (nativeInv E tb H) L)) κ := by + unfold IsRoot + rw [Fi_invoice, Fi_invoice, dualH_invoice E tb H hN κ] + +/-- PART 3c, word level: the helpers of `D w` (registers `sigma r`) have the same invoice as those of `w`. +Hypothesis: the listed registers climb (birth dim <= end dim), as helpers do. -/ +theorem word_invoice (X : Charts C N) (R : C → C → Prop) (hR : ∀ a b, R a b → R (X.perp b) (X.perp a)) + (σ : Reg ≃ Reg) (w : Word K Reg C) (h : LegalL X R w.init0 w.evs) (rs : List Reg) + (hc : ∀ r ∈ rs, X.dim (w.init0 r) ≤ X.dim (w.fin r)) (E : Inv) (tb : Table) (t : ℝ) : + Fi (nativeInv E tb ((rs.map σ).map (helperOf X (dualWord X σ w)))) t = + Fi (nativeInv E tb (rs.map (helperOf X w))) t := by + have : (rs.map σ).map (helperOf X (dualWord X σ w)) = (rs.map (helperOf X w)).map (dualH N) := by + rw [List.map_map, List.map_map] + apply List.map_congr_left + intro r _ + exact helperOf_dual X R hR σ w h r + rw [this] + apply dualH_invoice + intro h' hh' + obtain ⟨r, hr, rfl⟩ := List.mem_map.mp hh' + refine ⟨hc r hr, X.dim_le _, ?_⟩ + intro s hs + simp only [helperOf, regSteps, List.mem_filterMap] at hs + obtain ⟨e, _, he⟩ := hs + cases e <;> simp at he + obtain ⟨_, rfl⟩ := he + exact ⟨X.dim_le _, X.dim_le _⟩ + +end Invoice + +/-! ### Part 4: P104 boundary data -/ +section P104 +variable [DecidableEq Reg] [One K] {ι : Type*} + +/-- hypotheses (from DU1 section 1): X_p runs

-> V, Y_p runs {0} -> p^perp, sigma swaps X_p, Y_p, perp

= p^perp. +The dual word has the same register boundaries (g = id): the problem is self-dual. -/ +theorem selfdual_boundary (X : Charts C N) (R : C → C → Prop) (hR : ∀ a b, R a b → R (X.perp b) (X.perp a)) + (σ : Reg ≃ Reg) (w : Word K Reg C) (h : LegalL X R w.init0 w.evs) + (Xr Yr : ι → Reg) (line hyp : ι → C) + (hσX : ∀ p, σ (Xr p) = Yr p) (hσY : ∀ p, σ (Yr p) = Xr p) (hperp : ∀ p, X.perp (line p) = hyp p) + (hX : ∀ p, w.init0 (Xr p) = line p ∧ w.fin (Xr p) = X.V) + (hY : ∀ p, w.init0 (Yr p) = X.z ∧ w.fin (Yr p) = hyp p) (p : ι) : + ((dualWord X σ w).init0 (Xr p) = line p ∧ (dualWord X σ w).fin (Xr p) = X.V) ∧ + ((dualWord X σ w).init0 (Yr p) = X.z ∧ (dualWord X σ w).fin (Yr p) = hyp p) := by + have hl : ∀ p, X.perp (hyp p) = line p := fun p => by rw [← hperp, X.perp_perp] + obtain ⟨a1, a2⟩ := dual_boundary X R hR σ w h (Yr p) + obtain ⟨b1, b2⟩ := dual_boundary X R hR σ w h (Xr p) + rw [hσY] at a1 a2 + rw [hσX] at b1 b2 + refine ⟨⟨?_, ?_⟩, ⟨?_, ?_⟩⟩ + · rw [a1, (hY p).2, hl] + · rw [a2, (hY p).1, X.perp_z] + · rw [b1, (hX p).2, X.perp_V] + · rw [b2, (hX p).1, hperp] + +end P104 + +/-! ### contract blocks (from DU1.md; the non-hosted block is reconstructed from the card's dual [[1/2,-1],[1/2,1]]) -/ +section Blocks +def sw : Equiv.Perm (Fin 2) := Equiv.swap 0 1 + +/-- hosted block [[1,0],[1,1]] is invariant under transpose + sigma. -/ +theorem hosted_block : + (!![1, 0; 1, 1] : Matrix (Fin 2) (Fin 2) ℚ)ᵀ.submatrix sw.symm sw.symm = !![1, 0; 1, 1] := by + ext i j; fin_cases i <;> fin_cases j <;> simp [sw, Equiv.swap_apply_def] + +/-- non-hosted block F = [[1,-1],[1/2,1/2]]: D(F) = [[1/2,-1],[1/2,1]] and diag(1,1/2) D(F) diag(2,1) = F +(one SCALE 2 and one SCALE 1/2, unpriced). -/ +theorem nonhosted_block : + (!![1, -1; 1/2, 1/2] : Matrix (Fin 2) (Fin 2) ℚ)ᵀ.submatrix sw.symm sw.symm = !![1/2, -1; 1/2, 1] ∧ + Matrix.diagonal ![1, 1/2] * (!![1/2, -1; 1/2, 1] : Matrix (Fin 2) (Fin 2) ℚ) * Matrix.diagonal ![2, 1] = + !![1, -1; 1/2, 1/2] := by + constructor + · ext i j; fin_cases i <;> fin_cases j <;> simp [sw, Equiv.swap_apply_def] + · ext i j; fin_cases i <;> fin_cases j <;> simp [Matrix.mul_apply, Fin.sum_univ_two] <;> norm_num + +end Blocks + +/-! ### Part 5: caveat, COPY does not dualise to an ADD at matrix level -/ +section Caveat +/-- COPY 0 <- 1 on two registers has matrix [[0,1],[0,1]]; its transpose is [[0,0],[1,1]], which is not an ADD matrix +1 + q e_ab (a != b: every ADD matrix has diagonal 1). DU1's "COPY becomes ADD" holds only for a clean target. -/ +theorem copy_not_add (a b : Fin 2) (hab : a ≠ b) (q : ℚ) : + (!![0, 1; 0, 1] : Matrix (Fin 2) (Fin 2) ℚ)ᵀ ≠ 1 + Matrix.single a b q := by + intro h + have := congrFun (congrFun h 0) 0 + simp [Matrix.single_apply] at this + by_cases h0 : a = 0 ∧ b = 0 + · exact hab (h0.1.trans h0.2.symm) + · simp [h0] at this + +end Caveat + +end WordDuality + +#print axioms WordDuality.dual_run +#print axioms WordDuality.Mrec_dual +#print axioms WordDuality.dualH_invoice +#print axioms WordDuality.word_invoice +#print axioms WordDuality.selfdual_boundary +#print axioms WordDuality.nonhosted_block +#print axioms WordDuality.copy_not_add diff --git a/research/p104-native-ceiling/lean/Nov15/WordDuality.md b/research/p104-native-ceiling/lean/Nov15/WordDuality.md new file mode 100644 index 0000000000..4459df8d1c --- /dev/null +++ b/research/p104-native-ceiling/lean/Nov15/WordDuality.md @@ -0,0 +1,12 @@ +# WordDuality : DU1's D = sigma . perp . reversal . transpose in Lean + +`Nov15/WordDuality.lean`, kernel only: no `sorry`, no `native_decide`; axioms within `[propext, Classical.choice, Quot.sound]`. Builds in 11 s / 2.9 GB. Reuses `FibreK` (Table, Helper, nativeInv, K_word, FK) and `CallerCost`. +Model (problem data as hypotheses): `Charts C N` = charts with an involution `perp`, `dim (perp c) = N - dim c`, hubs z, V, `perp z = V` (P104: N = 9). Registers `Reg`, a word = initial chart of each register + a list of events (MOVE a→b, ADD, SCALE, COPY, INIT, CLEAR). Legal = co-presence at the event chart, no MOVE leaves V, none enters z (T1), and a move relation R (public ascent / owned descent) with R a b → R (perp b) (perp a). +1. `dual_run`, `dual_legal`: if w is legal then D w (events reversed, MOVE a→b ↦ perp b→perp a, ADD r += q s @U ↦ ADD s += q r @U^perp, SCALE kept, INIT ↔ CLEAR, COPY ↦ ADD) is legal, starts at perp of w's final charts and ends at perp of w's initial charts (`dual_boundary`; dims: `dual_dim_boundary`). Hub rules swap (z ↔ V), ascent stays ascent (`ascent_dual`) and descent stays descent (`descent_dual`). +2. `Mrec_dual`: for words of MOVE/ADD/SCALE, the product matrix of D l is the σ-relabelled transpose of that of l (K a commutative ring). +3. Invoice: `helperOf_dual`: register σ r of D w is the dual helper (b,e,steps) ↦ (N−e, N−b, reversed swapped steps) of r. `dualH_invoice`: FibreK's Theorem-K invoice Fi(nativeInv E tb H) is unchanged (hypotheses b ≤ e ≤ N, step dims ≤ N), `dualH_root`: same roots of the caller invoice (κ-neutral), `word_invoice` at word level (listed registers climb). Births/ends (b,e) ↦ (N−e,N−b), climb e−b and every MOVE |Δdim| preserved. +4. `selfdual_boundary`: with σ swapping X_p ↔ Y_p, X_p: ⟨p⟩ → V, Y_p: {0} → p^perp, perp ⟨p⟩ = p^perp: D w has exactly the same register boundaries (g = id). `hosted_block`: [[1,0],[1,1]] is invariant under transpose + swap; `nonhosted_block`: with F = [[1,−1],[1/2,1/2]] (reconstructed from DU1's dual [[1/2,−1],[1/2,1]]), D(F) = [[1/2,−1],[1/2,1]] and diag(1,1/2)·D(F)·diag(2,1) = F. + +## Correction to DU1 wording (stated at once) +DU1: "COPY becomes ADD". As matrices this is false: `copy_not_add` (COPY 0←1 has matrix [[0,1],[0,1]], whose transpose [[0,0],[1,1]] is not 1 + q·e_ab for any a ≠ b, ADD matrices have diagonal 1). The dual of a COPY is an ADD only on a clean target (the usual INIT-then-COPY use) and must carry the dual of the target's INIT (a CLEAR). `dualEv` sends COPY ↦ ADD for legality only; matrix semantics (`Mrec_dual`) is restricted to MOVE/ADD/SCALE. +Not formalised: the P104 chart/physical check (DU1 caveat 2), the 271 missing perp frames, and the palindromic construction W = D(A).A. diff --git a/research/p104-native-ceiling/lean/lake-manifest.json b/research/p104-native-ceiling/lean/lake-manifest.json new file mode 100644 index 0000000000..e4290db056 --- /dev/null +++ b/research/p104-native-ceiling/lean/lake-manifest.json @@ -0,0 +1,117 @@ +{ + "version": "1.2.0", + "packagesDir": ".lake/packages", + "packages": [ + { + "url": "https://github.com/leanprover-community/mathlib4.git", + "type": "git", + "subDir": null, + "scope": "", + "rev": "55b7917b472489c7c56a0fa6393af05cfd536599", + "name": "mathlib", + "manifestFile": "lake-manifest.json", + "inputRev": "55b7917b472489c7c56a0fa6393af05cfd536599", + "inherited": false, + "configFile": "lakefile.lean" + }, + { + "url": "https://github.com/leanprover-community/plausible", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "b1c4a69a7e247ab7df20460212001673d74f08c0", + "name": "plausible", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml" + }, + { + "url": "https://github.com/leanprover-community/LeanSearchClient", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "0498c7c070c143a3bf7379f4d99a2c63bb9d9715", + "name": "LeanSearchClient", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml" + }, + { + "url": "https://github.com/leanprover-community/import-graph", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "18a90119a5d316358fde6c86e0ca24e59212e32c", + "name": "importGraph", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml" + }, + { + "url": "https://github.com/leanprover-community/ProofWidgets4", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "b1436dc749e722c9920036b52cdc43b3451d0b69", + "name": "proofwidgets", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.lean" + }, + { + "url": "https://github.com/leanprover-community/aesop", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "57d3325be72a842920813bcb40f96a6f7393c185", + "name": "aesop", + "manifestFile": "lake-manifest.json", + "inputRev": "master", + "inherited": true, + "configFile": "lakefile.toml" + }, + { + "url": "https://github.com/leanprover-community/quote4", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "ee41917ae11d38479fb8fb24745f7ca4bf0a784d", + "name": "Qq", + "manifestFile": "lake-manifest.json", + "inputRev": "master", + "inherited": true, + "configFile": "lakefile.toml" + }, + { + "url": "https://github.com/leanprover-community/batteries", + "type": "git", + "subDir": null, + "scope": "leanprover-community", + "rev": "2c810760f0a0c4536b397dbe30ca9b2f2f467366", + "name": "batteries", + "manifestFile": "lake-manifest.json", + "inputRev": "main", + "inherited": true, + "configFile": "lakefile.toml" + }, + { + "url": "https://github.com/leanprover/lean4-cli", + "type": "git", + "subDir": null, + "scope": "leanprover", + "rev": "da07ca808b6718cb2aed14dba154e5a08b8f8ecf", + "name": "Cli", + "manifestFile": "lake-manifest.json", + "inputRev": "v4.33.0-rc1", + "inherited": true, + "configFile": "lakefile.toml" + } + ], + "name": "Nov16Core", + "lakeDir": ".lake", + "fixedToolchain": false +} diff --git a/research/p104-native-ceiling/lean/lakefile.toml b/research/p104-native-ceiling/lean/lakefile.toml new file mode 100644 index 0000000000..a5692331ac --- /dev/null +++ b/research/p104-native-ceiling/lean/lakefile.toml @@ -0,0 +1,12 @@ +name = "NativeCeiling" +defaultTargets = ["Nov15"] + +[[require]] +name = "mathlib" +git = "https://github.com/leanprover-community/mathlib4.git" +# pinned to the exact commit used for every check in this package (same as lake-manifest.json) +rev = "55b7917b472489c7c56a0fa6393af05cfd536599" + +[[lean_lib]] +name = "Nov15" +globs = ["Nov15.+"] diff --git a/research/p104-native-ceiling/lean/lean-toolchain b/research/p104-native-ceiling/lean/lean-toolchain new file mode 100644 index 0000000000..fd85b262bf --- /dev/null +++ b/research/p104-native-ceiling/lean/lean-toolchain @@ -0,0 +1 @@ +leanprover/lean4:v4.33.0-rc1