File size: 130,663 Bytes
5d5048e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 | import Mathlib
import OAI.Combinatorics.KServer.Minimization
import OAI.Combinatorics.KServer.Simplex
namespace OAI
noncomputable section
open scoped BigOperators Topology
open Finset Set Filter MeasureTheory
/-! The exact source primitives installed in the actual affine minimizer
recursion. The coefficients use raw core flags; fine caps are deliberately
absent. The zero-potential cases do not evaluate the marked denominator. -/
namespace KServer.SimplexFamilies
open scoped BigOperators
open Finset Set MeasureTheory
open KServer.SimplexAnalytic KServer.AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
structure Data (J R : Type*) [Fintype J] where
active : Finset J
flags : J → R → Bool
F : J → ℝ → ℝ
eta : J → ℝ
base : J → ℝ
zeroPotential : Bool
measurable : ∀ i, Measurable (F i)
positive : ∀ i y, 0 ≤ y → 0 < F i y
integrable : ∀ i, IntervalIntegrable (singularKernel (F i)) volume 0 1
base_mem : ∀ i, base i ∈ Set.Icc 0 1
omit [DecidableEq J] [Fintype R] in
def K (d : Data J R) (a : J → ℝ) (i : J) : ℝ := ∫ s in d.base i..a i, kernel (d.F i) s
omit [DecidableEq J] [Fintype R] in
def Z (d : Data J R) (a : J → ℝ) (i : J) : ℝ := ∫ s in d.base i..a i, singularKernel (d.F i) s
def core (d : Data J R) (p : J × R → ℝ) (i : J) : ℝ := ∑ r, if d.flags i r then p (i,r) else 0
def potential (C ell : ℝ) (d : Data J R) (B a : J → ℝ) : ℝ :=
if d.zeroPotential then 0 else ∑ i, primitive (d.F i) C ell (d.eta i) (∑ j, B j) (B i) (d.base i) (a i)
def coefficient (C ell : ℝ) (d : Data J R) (a : J → ℝ) (ir : J × R) : ℝ :=
if d.zeroPotential then 0 else if d.flags ir.1 ir.2 then
C*ell*((∑ i, K d a i)-(1+d.eta ir.1)*Z d a ir.1) else 0
omit [DecidableEq J] [Fintype R] in
lemma K_continuous (d : Data J R) (i : J) :
ContinuousOn (fun a => K d a i) (ChangingDomains.simplex d.active) := by
have hi := kernel_intervalIntegrable (d.measurable i) (d.positive i) (d.integrable i)
have he : Set.uIcc (0:ℝ) 1=Set.Icc 0 1 := uIcc_of_le (by norm_num)
have hc := intervalIntegral.continuousOn_primitive_interval' hi (he.symm ▸ d.base_mem i)
rw [he] at hc
exact hc.comp (continuous_apply i).continuousOn (fun a ha => ChangingDomains.simplex_coordinate ha i)
omit [DecidableEq J] [Fintype R] in
lemma Z_continuous (d : Data J R) (i : J) :
ContinuousOn (fun a => Z d a i) (ChangingDomains.simplex d.active) := by
have he : Set.uIcc (0:ℝ) 1=Set.Icc 0 1 := uIcc_of_le (by norm_num)
have hc := intervalIntegral.continuousOn_primitive_interval' (d.integrable i) (he.symm ▸ d.base_mem i)
rw [he] at hc
exact hc.comp (continuous_apply i).continuousOn (fun a ha => ChangingDomains.simplex_coordinate ha i)
omit [DecidableEq J] [Fintype R] in
lemma coefficient_continuous (C ell : ℝ) (d : Data J R) (ir : J × R) :
ContinuousOn (fun a => coefficient C ell d a ir) (ChangingDomains.simplex d.active) := by
unfold coefficient
split_ifs
· exact continuousOn_const
· exact ((continuousOn_finsetSum _ fun i _ => K_continuous d i).sub
((Z_continuous d ir.1).const_mul _)).const_mul _
· exact continuousOn_const
def family (C ell : ℝ) : Family (Data J R) (J × R) J where
domain d := ChangingDomains.simplex d.active
compact d := ChangingDomains.simplex_compact d.active
seed d := ⟨ChangingDomains.canonical d.active,ChangingDomains.canonical_mem d.active⟩
offset _ _ := 0
coefficient := coefficient C ell
offset_continuous _ := continuousOn_const
coefficient_continuous := coefficient_continuous C ell
/-- Algebraic equality with the literal sum of the source's improper
integrals. In particular the family does not substitute another potential. -/
lemma value_eq (C ell : ℝ) (d : Data J R) (p : J × R → ℝ) (a : J → ℝ)
(ha : a ∈ ChangingDomains.simplex d.active) :
(family C ell).value d p a=potential C ell d (core d p) a := by
by_cases hz : d.zeroPotential=true
· simp [Family.value,family,coefficient,potential,hz]
· have hi : ∀ i, primitive (d.F i) C ell (d.eta i) (∑ j, core d p j) (core d p i) (d.base i) (a i)=
C*ell*((∑ j, core d p j)*K d a i-(1+d.eta i)*core d p i*Z d a i) := by
intro i
exact primitive_affine (d.measurable i) (d.positive i) (d.integrable i) C ell _ _ _
(d.base_mem i) (ChangingDomains.simplex_coordinate ha i)
simp only [Family.value,family,coefficient,potential,hz,Bool.false_eq_true,ite_false,zero_add]
rw [Fintype.sum_prod_type]
have hr (i : J) : (∑ r, (if d.flags i r=true then C*ell*((∑ j, K d a j)-(1+d.eta i)*Z d a i) else 0)*p (i,r))=
C*ell*((∑ j, K d a j)-(1+d.eta i)*Z d a i)*core d p i := by
rw [core,mul_sum]
exact sum_congr rfl fun r _ => by split_ifs <;> simp_all
simp_rw [hr,hi]
have heL (i : J) : C*ell*((∑ j, K d a j)-(1+d.eta i)*Z d a i)*core d p i =
(C*ell*(∑ j, K d a j))*core d p i-C*ell*((1+d.eta i)*core d p i*Z d a i) := by ring
have heR (i : J) : C*ell*((∑ j, core d p j)*K d a i-(1+d.eta i)*core d p i*Z d a i) =
(C*ell*(∑ j, core d p j))*K d a i-C*ell*((1+d.eta i)*core d p i*Z d a i) := by ring
simp_rw [heL,heR]
simp only [sum_sub_distrib,←mul_sum]
ring
/-- Uniform endpoint bound from the same dimension-free rank slopes; the
finite number of coordinates may occur only in this additive endpoint. -/
lemma value_bound (C ell : ℝ) (d : Data J R) (p : J × R → ℝ) (a : J → ℝ) {L : ℝ}
(hc : ∀ ir, |coefficient C ell d a ir| ≤ L) (hp : ∀ ir, p ir ∈ Set.Icc 0 1) :
|(family C ell).value d p a| ≤ L*Fintype.card (J × R) := by
change |0+∑ ir, coefficient C ell d a ir*p ir| ≤ _
rw [zero_add]
calc _ ≤ ∑ ir, |coefficient C ell d a ir*p ir| := abs_sum_le_sum_abs _ _
_ ≤ ∑ _ir : J × R, L := sum_le_sum fun ir _ => by
rw [abs_mul,abs_of_nonneg (hp ir).1]
exact (mul_le_mul_of_nonneg_left (hp ir).2 (abs_nonneg _)).trans (by simpa using hc ir)
_ = _ := by simp [mul_comm]
def regular (A : Finset J) (flags : J → R → Bool) (h eta : J → ℝ)
(hh : ∀ i, 1 ≤ h i) : Data J R where
active := A
flags := flags
F i := regularF (h i)
eta := eta
base _ := 0
zeroPotential := false
measurable i := by unfold regularF; fun_prop
positive i y hy := (show 0 < h i by linarith [hh i]).trans_le (regularF_lower (by linarith [hh i]) hy)
integrable i := regular_singular_intervalIntegrable (by linarith [hh i])
base_mem _ := ⟨le_rfl,by norm_num⟩
omit [DecidableEq J] [Fintype R] in
lemma regular_coefficient_bound (A : Finset J) (flags : J → R → Bool) (h eta : J → ℝ)
(hh : ∀ i, 1 ≤ h i) (heta : ∀ i, eta i ∈ Set.Icc 0 1)
{C ell : ℝ} (hC : 0 ≤ C) (hell : 0 ≤ ell) {a : J → ℝ}
(ha : a ∈ ChangingDomains.simplex A) (ir : J × R) :
|coefficient C ell (regular A flags h eta hh) a ir| ≤ 3*C*ell := by
have hai i := ChangingDomains.simplex_coordinate ha i
have hb i := regular_coefficients (hh i) (hai i)
have hs : (∑ i, K (regular A flags h eta hh) a i) ∈ Set.Icc 0 1 := by
constructor
· exact sum_nonneg fun i _ => (hb i).1.1
· have hm := sum_le_sum fun i (_ : i∈Finset.univ) => (hb i).1.2
change (∑ i, K (regular A flags h eta hh) a i) ≤ ∑ i, a i at hm
rw [ha.2.1] at hm
split_ifs at hm <;> linarith
change |if flags ir.1 ir.2=true then C*ell*((∑ i, K (regular A flags h eta hh) a i)-(1+eta ir.1)*Z (regular A flags h eta hh) a ir.1) else 0| ≤ _
split_ifs with hf
· rw [abs_mul,abs_of_nonneg (mul_nonneg hC hell)]
have hj : Z (regular A flags h eta hh) a ir.1 ∈ Set.Icc 0 1 := (hb ir.1).2
have hprod := mul_le_mul (show 1+eta ir.1 ≤ 2 by linarith [(heta ir.1).2]) hj.2 hj.1 (by norm_num : (0:ℝ)≤2)
have hprodn := mul_nonneg (show 0 ≤ 1+eta ir.1 by linarith [(heta ir.1).1]) hj.1
have hab : |(∑ i, K (regular A flags h eta hh) a i)-(1+eta ir.1)*Z (regular A flags h eta hh) a ir.1| ≤ 3 := by
rw [abs_le]
constructor <;> linarith [hs.1,hs.2]
nlinarith [mul_le_mul_of_nonneg_left hab (mul_nonneg hC hell)]
· simp only [abs_zero]; positivity
/-- The marked base point is exactly one; no value with `u=0` is accepted. -/
def marked (A : Finset J) (flags : J → R → Bool) (o : J) (h eta : J → ℝ)
(u : ℝ) (hu : 0 < u) (hu1 : u ≤ 1) (hh : ∀ i ≠ o, 1 ≤ h i) : Data J R where
active := A
flags := flags
F i := if i=o then markedF u (1+Real.log (1/u)) else regularF (h i)
eta := eta
base i := if i=o then 1 else 0
zeroPotential := false
measurable i := by
by_cases hi : i=o
· simpa only [ite_eq_left hi] using (show Measurable (markedF u (1+Real.log (1/u))) by unfold markedF; fun_prop)
· simpa only [ite_eq_right hi] using (show Measurable (regularF (h i)) by unfold regularF; fun_prop)
positive i y hy := by
split_ifs with hi
· apply marked_positive hu _ y hy
have := log_inverse_nonneg ⟨hu,hu1⟩
linarith
· exact (show 0 < h i by linarith [hh i hi]).trans_le
(regularF_lower (by linarith [hh i hi]) hy)
integrable i := by
split_ifs with hi
· apply marked_singular_intervalIntegrable hu
have := log_inverse_nonneg ⟨hu,hu1⟩
linarith
· exact regular_singular_intervalIntegrable (by linarith [hh i hi])
base_mem i := by split_ifs <;> constructor <;> norm_num
omit [Fintype R] in
lemma marked_coefficient_bound (A : Finset J) (flags : J → R → Bool) (o : J) (h eta : J → ℝ)
{u C ell : ℝ} (hu : 0 < u) (hu1 : u ≤ 1) (hh : ∀ i ≠ o, 1 ≤ h i)
(heta : ∀ i, eta i ∈ Set.Icc 0 1) (hC : 0 ≤ C) (hell : 0 ≤ ell) {a : J → ℝ}
(ha : a ∈ ChangingDomains.simplex A) (ir : J × R) :
|coefficient C ell (marked A flags o h eta u hu hu1 hh) a ir| ≤ 13*C*ell := by
let d := marked A flags o h eta u hu hu1 hh
have hai i := ChangingDomains.simplex_coordinate ha i
have hK (i : J) : |K d a i| ≤ a i+if i=o then 4 else 0 := by
by_cases hi : i=o
· subst i
simp only [K,d,marked,ite_true]
rw [intervalIntegral.integral_symm,abs_neg,
abs_of_nonneg (marked_coefficients hu hu1 rfl (hai o)).1.1]
linarith [(marked_coefficients hu hu1 rfl (hai o)).1.2,ha.1 o]
· simp only [K,d,marked,ite_eq_right hi,add_zero]
rw [abs_of_nonneg (regular_coefficients (hh i hi) (hai i)).1.1]
exact (regular_coefficients (hh i hi) (hai i)).1.2
have hs : |∑ i, K d a i| ≤ 5 := by
apply (abs_sum_le_sum_abs _ _).trans
have ht := sum_le_sum fun i (_ : i∈Finset.univ) => hK i
classical
have he : (∑ i : J, if i=o then (4:ℝ) else 0)=4 := by simp
rw [sum_add_distrib,he,ha.2.1] at ht
split_ifs at ht <;> linarith
have hZ (i : J) : |Z d a i| ≤ 4 := by
by_cases hi : i=o
· subst i
simp only [Z,d,marked,ite_true]
rw [intervalIntegral.integral_symm,abs_neg,
abs_of_nonneg (marked_coefficients hu hu1 rfl (hai o)).2.1]
exact (marked_coefficients hu hu1 rfl (hai o)).2.2
· simp only [Z,d,marked,ite_eq_right hi]
rw [abs_of_nonneg (regular_coefficients (hh i hi) (hai i)).2.1]
linarith [(regular_coefficients (hh i hi) (hai i)).2.2]
change |if flags ir.1 ir.2=true then C*ell*((∑ i, K d a i)-(1+eta ir.1)*Z d a ir.1) else 0| ≤ _
split_ifs
· rw [abs_mul,abs_of_nonneg (mul_nonneg hC hell)]
have hprod : |(1+eta ir.1)*Z d a ir.1| ≤ 8 := by
rw [abs_mul,abs_of_nonneg (show 0 ≤ 1+eta ir.1 by linarith [(heta ir.1).1])]
have := mul_le_mul (show 1+eta ir.1 ≤ 2 by linarith [(heta ir.1).2])
(hZ ir.1) (abs_nonneg _) (by norm_num : (0:ℝ)≤2)
linarith
have hab : |(∑ i, K d a i)-(1+eta ir.1)*Z d a ir.1| ≤ 13 :=
(abs_sub _ _).trans (by linarith)
nlinarith [mul_le_mul_of_nonneg_left hab (mul_nonneg hC hell)]
· simp only [abs_zero]; positivity
/-- The automatic empty/singleton rule is a genuine zero potential, not a
singular marked potential evaluated at a zero side parameter. -/
def automatic (A : Finset J) (flags : J → R → Bool) : Data J R :=
{regular A flags (fun _ => 1) (fun _ => 0) (fun _ => le_rfl) with zeroPotential := true}
lemma automatic_value (C ell : ℝ) (A : Finset J) (flags : J → R → Bool)
(p : J × R → ℝ) (a : J → ℝ) : (family C ell).value (automatic A flags) p a=0 := by
simp [Family.value,family,coefficient,automatic]
end KServer.SimplexFamilies
noncomputable section
open scoped BigOperators Topology
open Set Filter
namespace KServer.SimplexTracker
variable {ι : Type*} [Fintype ι]
def simplex : Set (ι → ℝ) := {a | (∀ i, 0 ≤ a i) ∧ ∑ i, a i = 1}
def potential (f : ι → ℝ → ℝ) (a : ι → ℝ) : ℝ := ∑ i, f i (a i)
def movement (a b : ι → ℝ) : ℝ := ∑ i, |a i - b i|
def objective (f : ι → ℝ → ℝ) (S : ℝ) (a₀ a : ι → ℝ) : ℝ :=
potential f a + S * movement a a₀
lemma max_coordinate {a : ι → ℝ} (ha : a ∈ simplex) (i : ι) : a i ≤ 1 := by
have h := Finset.single_le_sum (fun j _ => ha.1 j) (Finset.mem_univ i)
rwa [ha.2] at h
/-- Quantitative deficit from replacing alpha_i by alpha_i/(1+eta_i). -/
lemma weighted_deficit {a h η : ι → ℝ} {ct ell ηmax : ℝ}
(ha : a ∈ simplex) (hh : ∀ i, 0 ≤ h i) (hc : 0 < ct) (hl : 0 < ell)
(hη : ∀ i, η i = ct * h i / ell) (hmax : ∀ i, η i ≤ ηmax) :
∑ i, a i / (1 + η i) ≤
1 - ct / (ell * (1 + ηmax)) * ∑ i, a i * h i := by
by_cases he : IsEmpty ι
· let := he
have : (0 : ℝ) = 1 := by simpa using ha.2
norm_num at this
have : Nonempty ι := not_isEmpty_iff.mp he
have hη0 : ∀ i, 0 ≤ η i := fun i => by rw [hη i]; exact div_nonneg (mul_nonneg hc.le (hh i)) hl.le
have hmax0 : 0 ≤ ηmax := (hη0 (Classical.arbitrary ι)).trans (hmax _)
have hi : ∀ i, a i / (1 + η i) ≤
a i - ct / (ell * (1 + ηmax)) * (a i * h i) := by
intro i
have hden : 0 < 1 + η i := by linarith [hη0 i]
have hdm : 0 < 1 + ηmax := by linarith
have hle := mul_le_mul_of_nonneg_left (hmax i) (ha.1 i)
have hhi : ell * η i = ct * h i := by rw [hη i]; field_simp
apply (div_le_iff₀ hden).mpr
apply (mul_le_mul_iff_right₀ (mul_pos hl hdm)).mp
field_simp
rw [← hhi]
nlinarith [mul_nonneg (mul_nonneg (ha.1 i) hl.le)
(mul_nonneg (hη0 i) (sub_nonneg.mpr (hmax i)))]
have hs := Finset.sum_le_sum fun i (_ : i ∈ Finset.univ) => hi i
simpa only [Finset.sum_sub_distrib, ← Finset.mul_sum, ha.2] using hs
/-- The derivative contradiction in eq:alpha-derivative-contradiction,
with coefficients general enough to include the marked denominator. -/
lemma exists_negative_derivative {a h η F B γ : ι → ℝ}
{ct ell ηmax Cα CF S : ℝ}
(ha : a ∈ simplex) (hh : ∀ i, 0 ≤ h i) (hc : 0 < ct) (hl : 0 < ell)
(hη : ∀ i, η i = ct * h i / ell) (hmax : ∀ i, η i ≤ ηmax)
(hCa : 0 < Cα) (_hCF : 0 ≤ CF) (hS : 0 < S)
(hB : ∑ i, B i = S) (hF : ∀ i, 0 ≤ F i)
(hT : 0 < ∑ i, a i * h i)
(hden : ∑ i, a i * F i ≤ CF * ∑ i, a i * h i)
(hgap : 2 * CF * (1 + ηmax) < Cα * ct)
(hidentity : ∀ i, a i * F i / (1 + η i) * γ i =
Cα * ell * (S * (a i / (1 + η i)) - B i)) :
∃ i, γ i < -2 * S := by
have hη0 : ∀ i, 0 ≤ η i := fun i => by rw [hη i]; exact div_nonneg (mul_nonneg hc.le (hh i)) hl.le
have hdef := weighted_deficit ha hh hc hl hη hmax
by_contra hall
push Not at hall
have hlow : -2 * S * (CF * ∑ i, a i * h i) ≤
∑ i, a i * F i / (1 + η i) * γ i := by
calc
_ ≤ -2 * S * ∑ i, a i * F i :=
mul_le_mul_of_nonpos_left hden (by linarith)
_ ≤ ∑ i, a i * F i / (1 + η i) * γ i := by
rw [Finset.mul_sum]
apply Finset.sum_le_sum
intro i _
have hp : 0 ≤ a i * F i := mul_nonneg (ha.1 i) (hF i)
have hd : 0 < 1 + η i := by linarith [hη0 i]
have hdiv : a i * F i / (1 + η i) ≤ a i * F i := by
apply (div_le_iff₀ hd).mpr
nlinarith [mul_nonneg hp (hη0 i)]
have hmul := mul_le_mul_of_nonneg_left (hall i) (div_nonneg hp hd.le)
nlinarith
have heq : (∑ i, a i * F i / (1 + η i) * γ i) =
Cα * ell * (S * ∑ i, a i / (1 + η i) - S) := by
simp_rw [hidentity]
rw [← Finset.mul_sum, Finset.sum_sub_distrib, ← Finset.mul_sum, hB]
rw [heq] at hlow
have hnon : Nonempty ι := by
by_contra hn
have : IsEmpty ι := not_nonempty_iff.mp hn
simp at hT
let := hnon
have hmax0 : 0 ≤ ηmax := (hη0 (Classical.arbitrary ι)).trans (hmax _)
have hdm : 0 < ell * (1 + ηmax) := by positivity
have hup := mul_le_mul_of_nonneg_left hdef (show 0 ≤ Cα * ell * S by positivity)
have hstrict := mul_pos (sub_pos.mpr hgap) (mul_pos hS hT)
have hid : ell * (1 + ηmax) * (ct / (ell * (1 + ηmax))) = ct := by
field_simp
have hlow' := mul_le_mul_of_nonneg_right hlow (show 0 ≤ 1 + ηmax by linarith)
have hup' := mul_le_mul_of_nonneg_right hup (show 0 ≤ 1 + ηmax by linarith)
have hr : Cα * ell * S * (1 - ct / (ell * (1 + ηmax)) * ∑ i, a i * h i) *
(1 + ηmax) = Cα * ell * S * (1 + ηmax) - Cα * ct * S * ∑ i, a i * h i := by
field_simp
rw [hr] at hup'
nlinarith
lemma simplex_isCompact : IsCompact (simplex (ι := ι)) := by
have hc : IsClosed (simplex (ι := ι)) := by
change IsClosed ({a : ι → ℝ | ∀ i, 0 ≤ a i} ∩ {a : ι → ℝ | ∑ i, a i = 1})
apply IsClosed.inter
· simp only [ofPred_forall]
exact isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i)
· exact isClosed_eq (continuous_finsetSum _ fun i _ => continuous_apply i) continuous_const
apply (isCompact_pi_infinite fun _ : ι => isCompact_Icc (a := (0 : ℝ)) (b := 1)).of_isClosed_subset hc
intro a ha i
exact ⟨ha.1 i, max_coordinate ha i⟩
lemma objective_continuousOn {f : ι → ℝ → ℝ} (hf : ∀ i, ContinuousOn (f i) (Icc 0 1))
(S : ℝ) (a₀ : ι → ℝ) : ContinuousOn (objective f S a₀) simplex := by
apply ContinuousOn.add
· apply continuousOn_finsetSum _
intro i _
exact (hf i).comp (continuous_apply i).continuousOn
(fun a ha => ⟨ha.1 i, max_coordinate ha i⟩)
· apply ContinuousOn.const_mul
apply continuousOn_finsetSum _
intro i _
exact ((continuous_apply i).sub continuous_const).abs.continuousOn
lemma exists_minimizer {f : ι → ℝ → ℝ} {S : ℝ} {a₀ : ι → ℝ}
(hf : ∀ i, ContinuousOn (f i) (Icc 0 1)) (ha₀ : a₀ ∈ simplex) :
∃ a ∈ simplex, IsMinOn (objective f S a₀) simplex a :=
simplex_isCompact.exists_isMinOn ⟨a₀, ha₀⟩ (objective_continuousOn hf S a₀)
lemma minimizer_payment {f : ι → ℝ → ℝ} {S : ℝ} {a₀ a : ι → ℝ}
(ha₀ : a₀ ∈ simplex) (hm : IsMinOn (objective f S a₀) simplex a) :
S * movement a a₀ ≤ potential f a₀ - potential f a := by
have h := hm ha₀
change potential f a + S * movement a a₀ ≤ potential f a₀ + S * movement a₀ a₀ at h
have hz : movement a₀ a₀ = 0 := by simp [movement]
rw [hz, mul_zero, add_zero] at h
linarith
lemma sum_replace [DecidableEq ι] (f : ι → ℝ → ℝ) (w : ι → ℝ) (i : ι) (y : ℝ) :
(∑ j, f j (Function.update w i y j)) = (∑ j, f j (w j)) - f i (w i) + f i y := by
have he : (∑ j ∈ Finset.univ.erase i, f j (Function.update w i y j)) =
∑ j ∈ Finset.univ.erase i, f j (w j) := by
apply Finset.sum_congr rfl
intro j hj
simp [Function.update, (Finset.mem_erase.mp hj).1]
have h₁ := Finset.sum_erase_add Finset.univ (fun j => f j (Function.update w i y j))
(Finset.mem_univ i)
have h₂ := Finset.sum_erase_add Finset.univ (fun j => f j (w j)) (Finset.mem_univ i)
simp only [Function.update_self, he] at h₁
linarith
/-- Transfer epsilon from donor i to receiver j, exactly as in §04. -/
def transfer [DecidableEq ι] (a : ι → ℝ) (i j : ι) (ε : ℝ) : ι → ℝ :=
Function.update (Function.update a i (a i - ε)) j (a j + ε)
lemma sum_transfer [DecidableEq ι] (f : ι → ℝ → ℝ) (a : ι → ℝ) {i j : ι}
(hij : i ≠ j) (ε : ℝ) :
(∑ l, f l (transfer a i j ε l)) =
(∑ l, f l (a l)) - f i (a i) + f i (a i - ε) - f j (a j) + f j (a j + ε) := by
simp only [transfer, sum_replace, Function.update_of_ne hij.symm]
lemma transfer_mem_simplex [DecidableEq ι] {a : ι → ℝ} (ha : a ∈ simplex) {i j : ι}
(hij : i ≠ j) {ε : ℝ} (hε : ε ∈ Set.Icc 0 (a i)) : transfer a i j ε ∈ simplex := by
constructor
· intro l
by_cases hlj : l = j
· subst l; simp only [transfer, Function.update_self]; linarith [ha.1 j, hε.1]
by_cases hli : l = i
· subst l; simp [transfer, Function.update_of_ne hij, sub_nonneg.mpr hε.2]
· simpa [transfer, Function.update_of_ne hlj, Function.update_of_ne hli] using ha.1 l
· rw [sum_transfer (fun _ x => x) a hij ε, ha.2]
ring
lemma transfer_min_comparison [DecidableEq ι] {f : ι → ℝ → ℝ} {S : ℝ} {a₀ a : ι → ℝ}
(hS : 0 ≤ S) (ha : a ∈ simplex) (hm : IsMinOn (objective f S a₀) simplex a)
{i j : ι} (hij : i ≠ j) {ε : ℝ} (hε : ε ∈ Set.Icc 0 (a i)) :
f i (a i) + f j (a j) ≤ f i (a i - ε) + f j (a j + ε) + 2 * S * ε := by
have h := hm (transfer_mem_simplex ha hij hε)
change potential f a + S * movement a a₀ ≤ potential f (transfer a i j ε) +
S * movement (transfer a i j ε) a₀ at h
dsimp [potential, movement] at h
rw [sum_transfer f a hij ε, sum_transfer (fun l x => |x - a₀ l|) a hij ε] at h
have hi := abs_sub_le (a i - ε) (a i) (a₀ i)
have hj := abs_sub_le (a j + ε) (a j) (a₀ j)
have hei : |a i - ε - a i| = ε := by rw [show a i - ε - a i = -ε by ring, abs_neg, abs_of_nonneg hε.1]
have hej : |a j + ε - a j| = ε := by rw [show a j + ε - a j = ε by ring, abs_of_nonneg hε.1]
rw [hei] at hi
rw [hej] at hj
have hi' := mul_le_mul_of_nonneg_left hi hS
have hj' := mul_le_mul_of_nonneg_left hj hS
linarith
lemma minimizer_derivative_gap [DecidableEq ι] {f : ι → ℝ → ℝ} {S : ℝ} {a₀ a : ι → ℝ}
(hS : 0 ≤ S) (ha : a ∈ simplex) (hm : IsMinOn (objective f S a₀) simplex a)
{i j : ι} (hij : i ≠ j) (hi : 0 < a i) {di dj : ℝ}
(hdi : HasDerivAt (f i) di (a i)) (hdj : HasDerivAt (f j) dj (a j)) :
di ≤ dj + 2 * S := by
have hc : IsLocalMinOn (fun ε => f i (a i - ε) + f j (a j + ε) + 2 * S * ε)
(Icc 0 (a i)) 0 := by
apply IsMinOn.isLocalMinOn
intro ε hε
simpa using transfer_min_comparison hS ha hm hij hε
have hd : HasDerivAt (fun ε => f i (a i - ε) + f j (a j + ε) + 2 * S * ε)
(-di + dj + 2 * S) 0 := by
have hi' : HasDerivAt (fun ε => f i (a i - ε)) (-di) 0 := by
convert (hdi.comp_of_eq 0 ((hasDerivAt_id 0).const_sub (a i)) (by simp)) using 1 <;> first | rfl | simp
have hj' : HasDerivAt (fun ε => f j (a j + ε)) dj 0 := by
convert (hdj.comp_of_eq 0 ((hasDerivAt_id 0).const_add (a j)) (by simp)) using 1 <;> first | rfl | simp
convert (hi'.add hj').add ((hasDerivAt_id 0).const_mul (2 * S)) using 1 <;> first | rfl | simp
have ht : a i - 0 ∈ posTangentConeAt (Icc 0 (a i)) 0 :=
sub_mem_posTangentConeAt_of_segment_subset
((convex_Icc 0 (a i)).segment_subset ⟨le_rfl, hi.le⟩ ⟨hi.le, le_rfl⟩)
have h := hc.hasFDerivWithinAt_nonneg hd.hasFDerivAt.hasFDerivWithinAt ht
simp only [ContinuousLinearMap.toSpanSingleton_apply, smul_eq_mul, sub_zero] at h
nlinarith
/-- A singular inward slope cannot occur at a constrained global minimum:
there is always a positive donor in the unit simplex. -/
lemma minimizer_not_inward_atBot [DecidableEq ι] {f : ι → ℝ → ℝ} {S : ℝ} {a₀ a : ι → ℝ}
(hS : 0 ≤ S) (ha : a ∈ simplex) (hm : IsMinOn (objective f S a₀) simplex a)
(hderiv : ∀ i, 0 < a i → DifferentiableAt ℝ (f i) (a i))
{j : ι} (hj : a j = 0) :
¬ Tendsto (fun ε : ℝ => (f j ε - f j 0) / ε) (𝓝[>] 0) atBot := by
intro hsing
have hex : ∃ i, 0 < a i := by
by_contra hn
push Not at hn
have hsum : (∑ i, a i) ≤ 0 := Finset.sum_nonpos fun i _ => hn i
linarith [ha.2]
obtain ⟨i, hi⟩ := hex
have hij : i ≠ j := by intro he; subst i; linarith
have hdi := (hderiv i hi).hasDerivAt
have hd : HasDerivAt (fun ε : ℝ => f i (a i - ε)) (-deriv (f i) (a i)) 0 := by
convert hdi.comp_of_eq 0 ((hasDerivAt_id 0).const_sub (a i)) (by simp) using 1
all_goals first | rfl | simp
have hdl : Tendsto (fun ε : ℝ => (f i (a i - ε) - f i (a i)) / ε)
(𝓝[>] 0) (𝓝 (-deriv (f i) (a i))) := by
convert hd.tendsto_slope_zero_right using 1
simp [smul_eq_mul, div_eq_mul_inv, mul_comm]
have hbot := tendsto_atBot_add_const_right (𝓝[>] (0 : ℝ)) (2 * S) (hdl.add_atBot hsing)
have hev : ∀ᶠ ε : ℝ in 𝓝[>] 0,
0 < ε ∧ ε ≤ a i ∧
(f i (a i - ε) - f i (a i)) / ε + (f j ε - f j 0) / ε + 2 * S < 0 := by
filter_upwards [eventually_mem_nhdsWithin,
(eventually_le_nhds hi).filter_mono nhdsWithin_le_nhds,
hbot.eventually (eventually_lt_atBot 0)] with ε hε hεi hneg
exact ⟨hε, hεi, hneg⟩
obtain ⟨ε, hε, hεi, hneg⟩ := hev.exists
have h := transfer_min_comparison hS ha hm hij ⟨hε.le, hεi⟩
rw [hj, zero_add] at h
have hmul := mul_neg_of_neg_of_pos hneg hε
have hid : ((f i (a i - ε) - f i (a i)) / ε + (f j ε - f j 0) / ε + 2 * S) * ε =
f i (a i - ε) - f i (a i) + (f j ε - f j 0) + 2 * S * ε := by
field_simp
rw [hid] at hmul
linarith
/-- Complete minimizer feasibility reduction, using the genuine derivative and
singular endpoint properties of the source primitives. -/
lemma minimizer_feasible [DecidableEq ι]
{f : ι → ℝ → ℝ} {a₀ a h η F B : ι → ℝ} {ct ell ηmax Cα CF S : ℝ}
(ha : a ∈ simplex) (hm : IsMinOn (objective f S a₀) simplex a)
(hh : ∀ i, 0 ≤ h i) (hc : 0 < ct) (hl : 0 < ell)
(hη : ∀ i, η i = ct * h i / ell) (hmax : ∀ i, η i ≤ ηmax)
(hCa : 0 < Cα) (hCF : 0 ≤ CF) (hS : 0 < S)
(hB0 : ∀ i, 0 ≤ B i) (hB : ∑ i, B i = S)
(hF : ∀ i, 0 ≤ F i) (hFp : ∀ i, 0 < a i → 0 < F i)
(hT : 0 < ∑ i, a i * h i)
(hden : ∑ i, a i * F i ≤ CF * ∑ i, a i * h i)
(hgap : 2 * CF * (1 + ηmax) < Cα * ct)
(hderiv : ∀ i, 0 < a i → HasDerivAt (f i)
(Cα * ell * ((S - (1 + η i) * B i / a i) / F i)) (a i))
(hsing : ∀ i, a i = 0 → 0 < B i →
Tendsto (fun ε : ℝ => (f i ε - f i 0) / ε) (𝓝[>] 0) atBot) :
∀ i, S * a i ≤ (1 + η i) * B i := by
have hη0 : ∀ i, 0 ≤ η i := fun i => by
rw [hη i]; exact div_nonneg (mul_nonneg hc.le (hh i)) hl.le
have hz : ∀ i, a i = 0 → B i = 0 := by
intro i hi
by_contra hBi
have hp : 0 < B i := lt_of_le_of_ne (hB0 i) (Ne.symm hBi)
exact minimizer_not_inward_atBot hS.le ha hm
(fun j hj => (hderiv j hj).differentiableAt) hi (hsing i hi hp)
let γ : ι → ℝ := fun i => if 0 < a i then
Cα * ell * ((S - (1 + η i) * B i / a i) / F i) else 0
have hid : ∀ i, a i * F i / (1 + η i) * γ i =
Cα * ell * (S * (a i / (1 + η i)) - B i) := by
intro i
by_cases hi : 0 < a i
· have hηi : 1 + η i ≠ 0 := by linarith [hη0 i]
dsimp [γ]; rw [ite_eq_left hi]
field_simp [hi.ne', (hFp i hi).ne', hηi]
· have hzero : a i = 0 := le_antisymm (le_of_not_gt hi) (ha.1 i)
simp only [γ, ite_eq_right hi, hzero, hz i hzero, zero_mul, zero_div, mul_zero, sub_self]
obtain ⟨j, hj⟩ := exists_negative_derivative ha hh hc hl hη hmax hCa hCF hS hB hF hT hden hgap hid
have hjp : 0 < a j := by
by_contra hjp
simp only [γ, ite_eq_right hjp] at hj
linarith
intro i
by_contra hbad
have hbad' : (1 + η i) * B i < S * a i := lt_of_not_ge hbad
have hi : 0 < a i := by
have hp : 0 ≤ (1 + η i) * B i := mul_nonneg (by linarith [hη0 i]) (hB0 i)
nlinarith
have hγi : 0 < γ i := by
dsimp [γ]; rw [ite_eq_left hi]
apply mul_pos (mul_pos hCa hl)
apply div_pos _ (hFp i hi)
exact sub_pos.mpr ((div_lt_iff₀ hi).mpr hbad')
have hij : i ≠ j := by intro he; subst i; linarith
have h := minimizer_derivative_gap hS.le ha hm hij hi (hderiv i hi) (hderiv j hjp)
have hei : γ i = Cα * ell * ((S - (1 + η i) * B i / a i) / F i) := ite_eq_left hi
have hej : γ j = Cα * ell * ((S - (1 + η j) * B j / a j) / F j) := ite_eq_left hjp
rw [← hei, ← hej] at h
linarith
end KServer.SimplexTracker
namespace KServer.Allocation
open Set Filter
open scoped BigOperators Topology
open SimplexTracker SimplexAnalytic
variable {ι : Type*} [Fintype ι]
lemma simplex_weight_pos {a h : ι → ℝ} (ha : a ∈ simplex) (hh : ∀ i, 0 < h i) :
0 < ∑ i, a i * h i := by
have hex : ∃ i, 0 < a i := by
by_contra hn
push Not at hn
have : (∑ i, a i) ≤ 0 := Finset.sum_nonpos fun i _ => hn i
linarith [ha.2]
obtain ⟨i, hi⟩ := hex
exact lt_of_lt_of_le (mul_pos hi (hh i))
(Finset.single_le_sum (fun j _ => mul_nonneg (ha.1 j) (hh j).le) (Finset.mem_univ i))
lemma log_inverse_nonneg_closed {a : ℝ} (ha : a ∈ Set.Icc 0 1) : 0 ≤ Real.log (1 / a) := by
rcases eq_or_lt_of_le ha.1 with hz | hp
· subst a; simp
· exact log_inverse_nonneg ⟨hp, ha.2⟩
/-- The exact integral update, including compact existence, singular endpoint
exclusion, feasibility and payment. Its analytic premises are proved above for
both displayed denominator types; no convexity is presumed. -/
lemma exists_simplex_update [DecidableEq ι]
{F : ι → ℝ → ℝ} {a₀ h c B base : ι → ℝ} {ct ell ηmax Cα CF : ℝ}
(ha₀ : a₀ ∈ simplex) (hh : ∀ i, 0 < h i) (hc : 0 < ct) (hl : 0 < ell)
(hmax : ∀ i, ct * h i / ell ≤ ηmax)
(hCa : 0 < Cα) (hCF : 0 ≤ CF)
(hB0 : ∀ i, 0 ≤ B i) (hb : ∀ i, base i ∈ Set.Icc 0 1)
(hFc : ∀ i, Continuous (F i)) (hci : ∀ i, 0 < c i)
(hF : ∀ i y, 0 ≤ y → c i * (1 + y)^2 ≤ F i y)
(hdecay : ∀ i, Tendsto (fun s : ℝ => s * F i (Real.log (1 / s))) (𝓝[>] 0) (𝓝 0))
(hden : ∀ a ∈ simplex, ∑ i, a i * F i (Real.log (1 / a i)) ≤ CF * ∑ i, a i * h i)
(hgap : 2 * CF * (1 + ηmax) < Cα * ct) :
let S := ∑ i, B i
let f := fun i => primitive (F i) Cα ell (ct * h i / ell) S (B i) (base i)
∃ a ∈ simplex, (∀ i, S * a i ≤ (1 + ct * h i / ell) * B i) ∧
S * movement a a₀ ≤ potential f a₀ - potential f a ∧
IsMinOn (objective f S a₀) simplex a := by
dsimp only
let S := ∑ i, B i
let η := fun i => ct * h i / ell
let f := fun i => primitive (F i) Cα ell (η i) S (B i) (base i)
have hη : ∀ i, 0 ≤ η i := fun i => div_nonneg (mul_nonneg hc.le (hh i).le) hl.le
have hp : ∀ i y, 0 ≤ y → 0 < F i y := fun i y hy =>
(show 0 < c i * (1 + y)^2 by have := hci i; positivity).trans_le (hF i y hy)
have hint := fun i => singular_intervalIntegrable_of_quadratic (hFc i).measurable (hci i) (hF i)
have hfc : ∀ i, ContinuousOn (f i) (Icc 0 1) := fun i =>
primitive_continuousOn (hFc i).measurable (hp i) (hint i) Cα ell (η i) S (B i) (hb i)
obtain ⟨a, ha, hm⟩ := exists_minimizer hfc ha₀ (S := S)
refine ⟨a, ha, ?_, minimizer_payment ha₀ hm, hm⟩
have hS0 : 0 ≤ S := Finset.sum_nonneg fun i _ => hB0 i
rcases eq_or_lt_of_le hS0 with hS | hS
· intro i
change S * a i ≤ (1 + η i) * B i
rw [← hS, zero_mul]
exact mul_nonneg (by linarith [hη i]) (hB0 i)
have hF0 : ∀ i, 0 ≤ F i (Real.log (1 / a i)) := fun i =>
(hp i _ (log_inverse_nonneg_closed ⟨ha.1 i, max_coordinate ha i⟩)).le
apply minimizer_feasible ha hm (fun i => (hh i).le) hc hl (fun _ => rfl) hmax
hCa hCF hS hB0 rfl hF0
(fun i hi => hp i _ (log_inverse_nonneg ⟨hi, max_coordinate ha i⟩))
(simplex_weight_pos ha hh) (hden a ha) hgap
· intro i hi
exact primitive_derivative (hFc i) (hp i) (hint i) Cα ell (η i) S (B i)
(hb i) ⟨hi, max_coordinate ha i⟩
· intro i _ hBi
exact primitive_inward_atBot (hFc i) (hci i) (hF i) (hdecay i)
hCa hl (hη i) hBi S (hb i)
/-- Instantiation on a domain without a dominant child, with the manuscript's
regular denominators and base point zero, at all simplex points including zero. -/
lemma regular_simplex_update [DecidableEq ι]
{a₀ h B : ι → ℝ} {ct ell ηmax Cα Cexp : ℝ}
(ha₀ : a₀ ∈ simplex) (hh : ∀ i, 1 ≤ h i) (hc : 0 < ct) (hl : 0 < ell)
(hmax : ∀ i, ct * h i / ell ≤ ηmax) (hCa : 0 < Cα)
(hB0 : ∀ i, 0 ≤ B i) (hCexp : 0 ≤ Cexp)
(htail : ∑ i, Real.exp (-h i) ≤ Cexp)
(hgap : 2 * (25 + 32 * Cexp) * (1 + ηmax) < Cα * ct) :
let S := ∑ i, B i
let f := fun i => primitive (regularF (h i)) Cα ell (ct * h i / ell) S (B i) 0
∃ a ∈ simplex, (∀ i, S * a i ≤ (1 + ct * h i / ell) * B i) ∧
S * movement a a₀ ≤ potential f a₀ - potential f a ∧
IsMinOn (objective f S a₀) simplex a := by
apply exists_simplex_update (c := fun i => 1 / h i) (CF := 25 + 32 * Cexp)
ha₀ (fun i => by linarith [hh i]) hc hl hmax hCa (by positivity) hB0
(fun _ => ⟨le_rfl, by norm_num⟩)
(fun i => by unfold regularF; fun_prop)
(fun i => by have := hh i; positivity)
(fun i _ hy => regular_quadratic_lower (hh i) hy)
(fun i => regular_decay (h i))
· intro a ha
exact regular_denominator_sum ha.1 ha.2 hh htail
· exact hgap
/-- Marked-domain instantiation; the base point is one exactly on the marked
coordinate, preserving the source's cancellation under parameter changes. -/
lemma marked_simplex_update [DecidableEq ι]
{a₀ h B : ι → ℝ} {ct ell ηmax Cα Cexp c u H : ℝ} (o : ι)
(ha₀ : a₀ ∈ simplex) (hu : 0 < u) (hu1 : u ≤ 1)
(hH : H = 1 + Real.log (1 / u)) (ho : h o = u)
(hh : ∀ i ≠ o, 1 ≤ h i) (hc : 0 < ct) (hl : 0 < ell)
(hmax : ∀ i, ct * h i / ell ≤ ηmax) (hCa : 0 < Cα)
(hB0 : ∀ i, 0 ≤ B i) (hCexp : 0 ≤ Cexp)
(hsideC : 0 < c) (hsideC1 : c ≤ 1) (hside : ∀ i ≠ o, c * H ≤ h i)
(htail : ∑ i ∈ Finset.univ.erase o, Real.exp (-h i) ≤ Cexp * u)
(hgap : 2 * ((25 * c + 2 + 32 * Cexp) / c) * (1 + ηmax) < Cα * ct) :
let S := ∑ i, B i
let f := fun i => primitive (if i = o then markedF u H else regularF (h i))
Cα ell (ct * h i / ell) S (B i) (if i = o then 1 else 0)
∃ a ∈ simplex, (∀ i, S * a i ≤ (1 + ct * h i / ell) * B i) ∧
S * movement a a₀ ≤ potential f a₀ - potential f a ∧
IsMinOn (objective f S a₀) simplex a := by
have hH1 : 1 ≤ H := by
rw [hH]; linarith [log_inverse_nonneg ⟨hu, hu1⟩]
have hHp : 0 < H := by linarith
have hhp : ∀ i, 0 < h i := by
intro i
by_cases hi : i = o
· simpa [hi, ho] using hu
· linarith [hh i hi]
obtain ⟨cm, hcm, hFm⟩ := marked_lower_constant hu hHp
apply exists_simplex_update (c := fun i => if i = o then cm else 1 / h i)
(CF := (25 * c + 2 + 32 * Cexp) / c) ha₀ hhp hc hl hmax hCa
(by positivity) hB0
· intro i; split_ifs <;> norm_num
· intro i
split_ifs
· unfold markedF; fun_prop
· unfold regularF; fun_prop
· intro i
split_ifs
· exact hcm
· exact one_div_pos.mpr (hhp i)
· intro i y hy
by_cases hi : i = o
· simpa [hi] using hFm y hy
· simpa [hi] using regular_quadratic_lower (hh i hi) hy
· intro i
by_cases hi : i = o
· simpa [hi] using marked_decay u H
· simpa [hi] using regular_decay (h i)
· intro a ha
have hd := marked_denominator_sum o ha.1 ha.2 hu.le (hu1.trans hH1)
hsideC hsideC1 hh hside hCexp htail
rw [← Finset.add_sum_erase _ _ (Finset.mem_univ o)]
simp only [ite_true]
have hs : (∑ i ∈ Finset.univ.erase o,
a i * (if i = o then markedF u H else regularF (h i)) (Real.log (1 / a i))) =
∑ i ∈ Finset.univ.erase o, a i * regularF (h i) (Real.log (1 / a i)) := by
apply Finset.sum_congr rfl
intro i hi
rw [ite_eq_right (Finset.mem_erase.mp hi).1]
rw [hs]
have ht : (∑ i, a i * h i) = a o * u + ∑ i ∈ Finset.univ.erase o, a i * h i := by
rw [← Finset.add_sum_erase _ _ (Finset.mem_univ o), ho]
rw [ht]
exact hd
· exact hgap
end KServer.Allocation
namespace KServer.SupportedAllocation
open scoped BigOperators
open Finset
variable {J : Type*} [Fintype J] [DecidableEq J]
def restrict (A : Finset J) (a : J → ℝ) : A → ℝ := fun i => a i
def extend (A : Finset J) (a : A → ℝ) : J → ℝ := fun i => if hi : i∈A then a ⟨i,hi⟩ else 0
omit [Fintype J] in
lemma extend_apply_mem (A : Finset J) (a : A → ℝ) (i : A) : extend A a i=a i := by
simp [extend,i.property]
omit [Fintype J] in
lemma extend_apply_not_mem (A : Finset J) (a : A → ℝ) {i : J} (hi : i∉A) : extend A a i=0 := by
simp [extend,hi]
omit [Fintype J] in
lemma restrict_extend (A : Finset J) (a : A → ℝ) : restrict A (extend A a)=a := by
funext i; exact extend_apply_mem A a i
omit [Fintype J] in
lemma extend_restrict (A : Finset J) (a : J → ℝ) (ha : ∀ i∉A, a i=0) :
extend A (restrict A a)=a := by
funext i
by_cases hi : i∈A
· simp [extend,restrict,hi]
· simp [extend,hi,ha i hi]
omit [DecidableEq J] in
lemma sum_restrict (A : Finset J) (a : J → ℝ) (ha : ∀ i∉A, a i=0) :
(∑ i : A, a i)=∑ i, a i := by
rw [←Finset.sum_subtype A (fun _ => Iff.rfl)]
exact Finset.sum_subset (subset_univ A) fun i _ hi => ha i hi
lemma sum_extend (A : Finset J) (a : A → ℝ) : (∑ i, extend A a i)=∑ i, a i := by
have he := sum_restrict A (extend A a) (fun i hi => extend_apply_not_mem A a hi)
simpa only [extend_apply_mem] using he.symm
omit [DecidableEq J] in
lemma restrict_simplex {A : Finset J} (hA : A.Nonempty) {a : J → ℝ}
(ha : a ∈ ChangingDomains.simplex A) : restrict A a ∈ SimplexTracker.simplex := by
refine ⟨fun i => ha.1 i,?_⟩
change (∑ i : A, a i)=1
rw [sum_restrict A a ha.2.2,ha.2.1,ite_eq_left hA]
lemma extend_simplex {A : Finset J} (hA : A.Nonempty) {a : A → ℝ}
(ha : a ∈ SimplexTracker.simplex) : extend A a ∈ ChangingDomains.simplex A := by
refine ⟨?_,?_,fun i hi => extend_apply_not_mem A a hi⟩
· intro i
unfold extend
split_ifs with hi
· exact ha.1 ⟨i,hi⟩
· exact le_rfl
· rw [sum_extend,ite_eq_left hA]; exact ha.2
omit [DecidableEq J] in
lemma movement_restrict {A : Finset J} {a b : J → ℝ}
(ha : ∀ i∉A, a i=0) (hb : ∀ i∉A, b i=0) :
SimplexTracker.movement (restrict A a) (restrict A b)=ChangingDomains.variation a b := by
apply sum_restrict A (fun i => |a i-b i|)
intro i hi; simp [ha i hi,hb i hi]
lemma movement_extend {A : Finset J} (a b : A → ℝ) :
ChangingDomains.variation (extend A a) (extend A b)=SimplexTracker.movement a b := by
have h := movement_restrict (fun i hi => extend_apply_not_mem A a hi)
(fun i hi => extend_apply_not_mem A b hi)
simpa only [restrict_extend] using h.symm
omit [DecidableEq J] in
lemma potential_restrict {A : Finset J} {f : J → ℝ → ℝ} {a : J → ℝ}
(ha : ∀ i∉A, a i=0) (hf : ∀ i∉A, f i 0=0) :
SimplexTracker.potential (fun i : A => f i) (restrict A a)=∑ i, f i (a i) := by
apply sum_restrict A (fun i => f i (a i))
intro i hi; rw [ha i hi,hf i hi]
/-- Restriction is exact, including both the movement penalty and the literal
source potentials. No dummy inactive coordinate enters the denominator bound. -/
lemma restrict_isMin {A : Finset J} (hA : A.Nonempty) {f : J → ℝ → ℝ}
{S : ℝ} {a a₀ : J → ℝ} (ha : a ∈ ChangingDomains.simplex A)
(ha₀ : a₀ ∈ ChangingDomains.simplex A) (hf : ∀ i∉A, f i 0=0)
(hm : IsMinOn (fun b => (∑ i, f i (b i))+S*ChangingDomains.variation b a₀)
(ChangingDomains.simplex A) a) :
IsMinOn (SimplexTracker.objective (fun i : A => f i) S (restrict A a₀))
SimplexTracker.simplex (restrict A a) := by
intro b hb
have he := extend_simplex hA hb
have hh := hm he
change SimplexTracker.potential (fun i : A => f i) (restrict A a)+
S*SimplexTracker.movement (restrict A a) (restrict A a₀) ≤
SimplexTracker.potential (fun i : A => f i) b+S*SimplexTracker.movement b (restrict A a₀)
rw [potential_restrict ha.2.2 hf,movement_restrict ha.2.2 ha₀.2.2]
have hp := potential_restrict he.2.2 hf
have hmove := movement_restrict he.2.2 ha₀.2.2
rw [restrict_extend] at hp hmove
rw [hp,hmove]
exact hh
end KServer.SupportedAllocation
namespace KServer.Allocation
open Set Filter
open scoped BigOperators Topology
open SimplexTracker SimplexAnalytic
variable {ι : Type*} [Fintype ι] [DecidableEq ι]
/-- The feasibility argument holds for every attained minimizer, in particular
for the fixed noncomputable choice in the causal recurrence. -/
lemma every_simplex_minimizer_feasible
{F : ι → ℝ → ℝ} {a₀ a h c B base : ι → ℝ} {ct ell ηmax Cα CF : ℝ}
(ha : a ∈ simplex) (hh : ∀ i, 0 < h i) (hc : 0 < ct) (hl : 0 < ell)
(hmax : ∀ i, ct*h i/ell ≤ ηmax) (hCa : 0 < Cα) (hCF : 0 ≤ CF)
(hB0 : ∀ i, 0 ≤ B i) (hb : ∀ i, base i ∈ Set.Icc 0 1)
(hFc : ∀ i, Continuous (F i)) (hci : ∀ i, 0 < c i)
(hF : ∀ i y, 0 ≤ y → c i*(1+y)^2 ≤ F i y)
(hdecay : ∀ i, Tendsto (fun s : ℝ => s*F i (Real.log (1/s))) (𝓝[>] 0) (𝓝 0))
(hden : ∀ b ∈ simplex, ∑ i, b i*F i (Real.log (1/b i)) ≤ CF*∑ i, b i*h i)
(hgap : 2*CF*(1+ηmax) < Cα*ct)
(hm : IsMinOn (objective (fun i => primitive (F i) Cα ell (ct*h i/ell)
(∑ j, B j) (B i) (base i)) (∑ i, B i) a₀) simplex a) :
∀ i, (∑ j, B j)*a i ≤ (1+ct*h i/ell)*B i := by
let S := ∑ i, B i
let η := fun i => ct*h i/ell
have hη : ∀ i, 0 ≤ η i := fun i => div_nonneg (mul_nonneg hc.le (hh i).le) hl.le
have hp : ∀ i y, 0 ≤ y → 0 < F i y := fun i y hy =>
(show 0 < c i*(1+y)^2 by have := hci i; positivity).trans_le (hF i y hy)
have hint := fun i => singular_intervalIntegrable_of_quadratic (hFc i).measurable (hci i) (hF i)
have hS0 : 0 ≤ S := Finset.sum_nonneg fun i _ => hB0 i
rcases eq_or_lt_of_le hS0 with hS | hS
· intro i
change S*a i ≤ (1+η i)*B i
rw [←hS,zero_mul]
exact mul_nonneg (by linarith [hη i]) (hB0 i)
have hF0 : ∀ i, 0 ≤ F i (Real.log (1/a i)) := fun i =>
(hp i _ (log_inverse_nonneg_closed ⟨ha.1 i,max_coordinate ha i⟩)).le
apply minimizer_feasible ha hm (fun i => (hh i).le) hc hl (fun _ => rfl) hmax
hCa hCF hS hB0 rfl hF0
(fun i hi => hp i _ (log_inverse_nonneg ⟨hi,max_coordinate ha i⟩))
(simplex_weight_pos ha hh) (hden a ha) hgap
· intro i hi
exact primitive_derivative (hFc i) (hp i) (hint i) Cα ell (η i) S (B i)
(hb i) ⟨hi,max_coordinate ha i⟩
· intro i _ hBi
exact primitive_inward_atBot (hFc i) (hci i) (hF i) (hdecay i)
hCa hl (hη i) hBi S (hb i)
end KServer.Allocation
namespace KServer.Allocation
open Set Filter
open scoped BigOperators Topology
open SimplexTracker SimplexAnalytic
variable {ι : Type*} [Fintype ι] [DecidableEq ι]
lemma every_regular_minimizer_feasible
{a₀ a h B : ι → ℝ} {ct ell ηmax Cα Cexp : ℝ}
(ha : a ∈ simplex) (hh : ∀ i, 1≤h i) (hc : 0<ct) (hl : 0<ell)
(hmax : ∀ i, ct*h i/ell≤ηmax) (hCa : 0<Cα) (hB0 : ∀ i, 0≤B i)
(hCexp : 0≤Cexp) (htail : ∑ i, Real.exp (-h i)≤Cexp)
(hgap : 2*(25+32*Cexp)*(1+ηmax)<Cα*ct)
(hm : IsMinOn (objective (fun i => primitive (regularF (h i)) Cα ell (ct*h i/ell)
(∑ j, B j) (B i) 0) (∑ i, B i) a₀) simplex a) :
∀ i, (∑ j, B j)*a i≤(1+ct*h i/ell)*B i := by
apply every_simplex_minimizer_feasible (c := fun i => 1/h i) (CF := 25+32*Cexp)
ha (fun i => by linarith [hh i]) hc hl hmax hCa (by positivity) hB0
(fun _ => ⟨le_rfl,by norm_num⟩)
(fun i => by unfold regularF; fun_prop)
(fun i => by have := hh i; positivity)
(fun i _ hy => regular_quadratic_lower (hh i) hy)
(fun i => regular_decay (h i))
· intro b hb; exact regular_denominator_sum hb.1 hb.2 hh htail
· exact hgap
· exact hm
end KServer.Allocation
namespace KServer.SupportedAllocation
open scoped BigOperators
open SimplexTracker SimplexAnalytic
variable {J : Type*} [Fintype J] [DecidableEq J]
/-- Uniform feasibility on the changing active domain. Its exp-tail hypothesis
is a sum over active children only, exactly as in the source. -/
lemma regular_supported_minimizer_feasible {A : Finset J} (hA : A.Nonempty)
{a₀ a h B : J → ℝ} {ct ell ηmax Cα Cexp : ℝ}
(ha : a ∈ ChangingDomains.simplex A) (ha₀ : a₀ ∈ ChangingDomains.simplex A)
(hh : ∀ i∈A, 1≤h i) (hc : 0<ct) (hl : 0<ell)
(hmax : ∀ i∈A, ct*h i/ell≤ηmax) (hCa : 0<Cα) (hB0 : ∀ i, 0≤B i)
(hBout : ∀ i∉A, B i=0) (hCexp : 0≤Cexp) (htail : ∑ i∈A, Real.exp (-h i)≤Cexp)
(hgap : 2*(25+32*Cexp)*(1+ηmax)<Cα*ct)
(hm : IsMinOn (fun b => (∑ i, primitive (regularF (h i)) Cα ell (ct*h i/ell)
(∑ j, B j) (B i) 0 (b i))+(∑ i, B i)*ChangingDomains.variation b a₀)
(ChangingDomains.simplex A) a) :
∀ i, (∑ j, B j)*a i≤(1+ct*h i/ell)*B i := by
have hsum : (∑ j : A, B j)=∑ j, B j := sum_restrict A B hBout
have htail' : (∑ i : A, Real.exp (-h i))≤Cexp := by
rw [←Finset.sum_subtype A (fun _ => Iff.rfl) (fun i => Real.exp (-h i))]
exact htail
have hm' := restrict_isMin hA ha ha₀ (fun i _ => by simp [primitive]) hm
have he := Allocation.every_regular_minimizer_feasible
(a₀ := restrict A a₀) (a := restrict A a) (h := fun i : A => h i) (B := fun i : A => B i)
(restrict_simplex hA ha) (fun i => hh i i.property) hc hl (fun i => hmax i i.property)
hCa (fun i => hB0 i) hCexp htail' hgap
have hh' : ∀ i : A, (∑ j, B j)*a i≤(1+ct*h i/ell)*B i := by
have hm'' : IsMinOn (objective (fun i : A => primitive (regularF (h i)) Cα ell (ct*h i/ell)
(∑ j : A, B j) (B i) 0) (∑ i : A, B i) (restrict A a₀))
simplex (restrict A a) := by simpa only [hsum] using hm'
simpa only [hsum,restrict] using he hm''
intro i
by_cases hi : i∈A
· exact hh' ⟨i,hi⟩
· simp [ha.2.2 i hi,hBout i hi]
end KServer.SupportedAllocation
namespace KServer.Allocation
open Set Filter
open scoped BigOperators Topology
open SimplexTracker SimplexAnalytic
variable {ι : Type*} [Fintype ι] [DecidableEq ι]
lemma every_marked_minimizer_feasible
{a₀ a h B : ι → ℝ} {ct ell ηmax Cα Cexp c u H : ℝ} (o : ι)
(ha : a ∈ simplex) (hu : 0 < u) (hu1 : u ≤ 1)
(hH : H = 1 + Real.log (1 / u)) (ho : h o = u)
(hh : ∀ i ≠ o, 1 ≤ h i) (hc : 0 < ct) (hl : 0 < ell)
(hmax : ∀ i, ct * h i / ell ≤ ηmax) (hCa : 0 < Cα)
(hB0 : ∀ i, 0 ≤ B i) (hCexp : 0 ≤ Cexp)
(hsideC : 0 < c) (hsideC1 : c ≤ 1) (hside : ∀ i ≠ o, c * H ≤ h i)
(htail : ∑ i ∈ Finset.univ.erase o, Real.exp (-h i) ≤ Cexp * u)
(hgap : 2 * ((25 * c + 2 + 32 * Cexp) / c) * (1 + ηmax) < Cα * ct)
(hm : IsMinOn (objective (fun i => primitive (if i = o then markedF u H else regularF (h i))
Cα ell (ct*h i/ell) (∑ j, B j) (B i) (if i=o then 1 else 0))
(∑ j, B j) a₀) simplex a) :
∀ i, (∑ j, B j)*a i ≤ (1+ct*h i/ell)*B i := by
have hH1 : 1 ≤ H := by
rw [hH]; linarith [log_inverse_nonneg ⟨hu, hu1⟩]
have hHp : 0 < H := by linarith
have hhp : ∀ i, 0 < h i := by
intro i
by_cases hi : i = o
· simpa [hi, ho] using hu
· linarith [hh i hi]
obtain ⟨cm, hcm, hFm⟩ := marked_lower_constant hu hHp
apply every_simplex_minimizer_feasible
(F := fun i => if i=o then markedF u H else regularF (h i))
(base := fun i => if i=o then 1 else 0)
(c := fun i => if i = o then cm else 1 / h i)
(CF := (25 * c + 2 + 32 * Cexp) / c) ha hhp hc hl hmax hCa
(by positivity) hB0
· intro i; split_ifs <;> norm_num
· intro i
split_ifs
· unfold markedF; fun_prop
· unfold regularF; fun_prop
· intro i
split_ifs
· exact hcm
· exact one_div_pos.mpr (hhp i)
· intro i y hy
by_cases hi : i = o
· simpa [hi] using hFm y hy
· simpa [hi] using regular_quadratic_lower (hh i hi) hy
· intro i
by_cases hi : i = o
· simpa [hi] using marked_decay u H
· simpa [hi] using regular_decay (h i)
· intro a ha
have hd := marked_denominator_sum o ha.1 ha.2 hu.le (hu1.trans hH1)
hsideC hsideC1 hh hside hCexp htail
rw [← Finset.add_sum_erase _ _ (Finset.mem_univ o)]
simp only [ite_true]
have hs : (∑ i ∈ Finset.univ.erase o,
a i * (if i = o then markedF u H else regularF (h i)) (Real.log (1 / a i))) =
∑ i ∈ Finset.univ.erase o, a i * regularF (h i) (Real.log (1 / a i)) := by
apply Finset.sum_congr rfl
intro i hi
rw [ite_eq_right (Finset.mem_erase.mp hi).1]
rw [hs]
have ht : (∑ i, a i * h i) = a o * u + ∑ i ∈ Finset.univ.erase o, a i * h i := by
rw [← Finset.add_sum_erase _ _ (Finset.mem_univ o), ho]
rw [ht]
exact hd
· exact hgap
· exact hm
end KServer.Allocation
namespace KServer.SupportedAllocation
open SimplexTracker SimplexAnalytic
variable {J : Type*} [Fintype J] [DecidableEq J]
/-- Feasibility for the actual changing marked domain; inactive coordinates
are zero instead of being assigned a spurious positive denominator weight. -/
lemma marked_supported_minimizer_feasible {A : Finset J} {o : J} (hoA : o ∈ A)
{a₀ a h B : J → ℝ} {ct ell ηmax Cα Cexp c u H : ℝ}
(ha : a ∈ ChangingDomains.simplex A) (ha₀ : a₀ ∈ ChangingDomains.simplex A)
(hu : 0 < u) (hu1 : u ≤ 1) (hH : H = 1 + Real.log (1 / u)) (ho : h o = u)
(hh : ∀ i∈A, i ≠ o → 1 ≤ h i) (hc : 0<ct) (hl : 0<ell)
(hmax : ∀ i∈A, ct*h i/ell ≤ ηmax) (hCa : 0<Cα)
(hB0 : ∀ i, 0≤B i) (hBout : ∀ i∉A, B i=0) (hCexp : 0≤Cexp)
(hsideC : 0<c) (hsideC1 : c≤1) (hside : ∀ i∈A, i≠o → c*H≤h i)
(htail : ∑ i∈A.erase o, Real.exp (-h i) ≤ Cexp*u)
(hgap : 2*((25*c+2+32*Cexp)/c)*(1+ηmax)<Cα*ct)
(hm : IsMinOn (fun b => (∑ i, primitive (if i=o then markedF u H else regularF (h i))
Cα ell (ct*h i/ell) (∑ j, B j) (B i) (if i=o then 1 else 0) (b i))+
(∑ i, B i)*ChangingDomains.variation b a₀) (ChangingDomains.simplex A) a) :
∀ i, (∑ j, B j)*a i ≤ (1+ct*h i/ell)*B i := by
have hA : A.Nonempty := ⟨o,hoA⟩
let o' : A := ⟨o,hoA⟩
have hsum : (∑ j : A, B j)=∑ j, B j := sum_restrict A B hBout
have hcon (i : A) : (i=o') ↔ ((i : J)=o) := Subtype.ext_iff
have hm' := restrict_isMin hA ha ha₀
(fun i hi => by simp [ite_eq_right (show i≠o by intro he; exact hi (he ▸ hoA)), primitive]) hm
have htail' : (∑ i∈Finset.univ.erase o', Real.exp (-h (i : J))) ≤ Cexp*u := by
have he : (∑ i∈Finset.univ.erase o', Real.exp (-h (i : J))) =
∑ i∈A.erase o, Real.exp (-h i) := by
apply Finset.sum_bij (fun (i : A) (_ : i∈Finset.univ.erase o') => (i : J))
· intro i hi
exact Finset.mem_erase.mpr ⟨fun he => (Finset.mem_erase.mp hi).1
(Subtype.ext he), i.property⟩
· intro i _ j _ hij
exact Subtype.ext hij
· intro i hi
refine ⟨⟨i,(Finset.mem_erase.mp hi).2⟩, ?_,rfl⟩
exact Finset.mem_erase.mpr ⟨fun he => (Finset.mem_erase.mp hi).1
(congrArg Subtype.val he),Finset.mem_univ _⟩
· intro i _; rfl
rw [he]; exact htail
have hm'' : IsMinOn (objective (fun i : A => primitive
(if i=o' then markedF u H else regularF (h i)) Cα ell (ct*h i/ell)
(∑ j : A, B j) (B i) (if i=o' then 1 else 0))
(∑ i : A, B i) (restrict A a₀)) simplex (restrict A a) := by
simpa only [hcon,hsum] using hm'
have he := Allocation.every_marked_minimizer_feasible o'
(restrict_simplex hA ha) hu hu1 hH ho
(fun i hi => hh i i.property (fun he => hi (Subtype.ext he))) hc hl
(fun i => hmax i i.property) hCa (fun i => hB0 i) hCexp hsideC hsideC1
(fun i hi => hside i i.property (fun he => hi (Subtype.ext he))) htail' hgap hm''
intro i
by_cases hi : i∈A
· simpa only [hsum,restrict] using he ⟨i,hi⟩
· simp [ha.2.2 i hi,hBout i hi]
end KServer.SupportedAllocation
/-! The literal two-stage update of §04: prepare with the new core flags on
common coordinates, minimize on the old simplex, transpose at exactly zero
cost, then minimize on the new simplex. The bounds below calculate its edit
charge from the actual flags and held parameters, not from an assumed drift
or policy bound. -/
namespace KServer.AdaptiveAllocation
open Finset SimplexAnalytic SimplexFamilies AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
lemma update_isMin (C ell : ℝ) (d : Data J R) (p : J × R → ℝ) (c : ℝ) (a : J → ℝ) :
IsMinOn (fun b => potential C ell d (core d p) b+c*ChangingDomains.variation b a)
(ChangingDomains.simplex d.active) ((family C ell).update d p c a) := by
have hm := ((family C ell).exists_update d p c a).choose_spec
intro b hb
have hm' := hm.2 hb
change (family C ell).value d p ((family C ell).update d p c a)+c*movement ((family C ell).update d p c a) a ≤
(family C ell).value d p b+c*movement b a at hm'
rw [value_eq C ell d p ((family C ell).update d p c a)
((family C ell).update_mem d p c a), value_eq C ell d p b hb] at hm'
exact hm'
lemma regular_update_feasible {A : Finset J} (hA : A.Nonempty)
(f : J → R → Bool) (h : J → ℝ) (hh : ∀ i, 1≤h i)
{C ell ct ηmax Cexp : ℝ} (hC : 0<C) (hl : 0<ell) (hc : 0<ct)
(hmax : ∀ i∈A, ct*h i/ell≤ηmax) (hCexp : 0≤Cexp)
(htail : ∑ i∈A, Real.exp (-h i)≤Cexp)
(hgap : 2*(25+32*Cexp)*(1+ηmax)<C*ct)
(p : J × R → ℝ) (hp : ∀ ir, 0≤p ir) (hf : ∀ i∉A, ∀ r, f i r=false)
(a : J → ℝ) (ha : a∈ChangingDomains.simplex A) :
let d := regular A f h (fun i => ct*h i/ell) hh
let B := core d p
let a' := (family C ell).update d p (∑ i, B i) a
∀ i, (∑ j, B j)*a' i≤(1+ct*h i/ell)*B i := by
intro d B a'
have hB : ∀ i, 0≤B i := by
intro i
exact ChangingDomains.core_nonneg (fun i r => hp (i,r)) i
have hBz : ∀ i∉A, B i=0 := by
intro i hi
simp [B,core,d,regular,hf i hi]
apply SupportedAllocation.regular_supported_minimizer_feasible hA
((family C ell).update_mem d p (∑ i, B i) a) ha
(fun i _ => hh i) hc hl hmax hC hB hBz hCexp htail hgap
exact update_isMin C ell d p (∑ i, B i) a
omit [DecidableEq J] in
lemma core_eq (A : Finset J) (f : J → R → Bool) (h eta : J → ℝ)
(hh : ∀ i, 1≤h i) (p : J × R → ℝ) :
core (regular A f h eta hh) p = ChangingDomains.core f (fun i r => p (i,r)) := rfl
/-- The prepared input is concrete and uses only new flags on the common
old/new active domain, as in §04 (not intersection of old and new flags). -/
def preparedFlags (A B : Finset J) (g : J → R → Bool) : J → R → Bool :=
ChangingDomains.syntheticFlags A B g
def preparedInput (A B : Finset J) (g : J → R → Bool) (p : J × R → ℝ) : J → ℝ :=
ChangingDomains.core (preparedFlags A B g) (fun i r => p (i,r))
omit [Fintype J] [Fintype R] in
lemma prepared_flags_outside (A B : Finset J) (g : J → R → Bool) :
∀ i∉A, ∀ r, preparedFlags A B g i r=false := by
intro i hi r
simp [preparedFlags,ChangingDomains.syntheticFlags,hi]
omit [Fintype J] in
lemma prepared_input_outside (A B : Finset J) (g : J → R → Bool) (p : J × R → ℝ) :
∀ i∉B, preparedInput A B g p i=0 := by
intro i hi
simp [preparedInput,preparedFlags,ChangingDomains.core,ChangingDomains.syntheticFlags,hi]
omit [DecidableEq J] [Fintype R] in
lemma regular_potential_zero (A : Finset J) (f : J → R → Bool) (h eta : J → ℝ)
(hh : ∀ i, 1≤h i) (C ell : ℝ) (a : J → ℝ) :
potential C ell (regular A f h eta hh) (fun _ => 0) a=0 := by
simp [potential,regular,primitive]
omit [DecidableEq J] in
lemma nonneg_total_zero {B : J → ℝ} (hB : ∀ i, 0≤B i) (hS : (∑ i, B i)=0) :
B=(fun _ => 0) := by
funext i
exact le_antisymm (by simpa [hS] using (single_le_sum (fun j _ => hB j) (mem_univ i))) (hB i)
omit [Fintype R] in
lemma regular_transpose_value (A B : Finset J) (f : J → R → Bool) (h eta : J → ℝ)
(hh : ∀ i, 1≤h i) (C ell : ℝ) (v a : J → ℝ) (hv : ∀ i, 0≤v i) :
potential C ell (regular A f h eta hh) v
(ChangingDomains.transposeSimplex B (∑ i, v i) a)=
potential C ell (regular A f h eta hh) v a := by
by_cases hS : (∑ i, v i)=0
· rw [nonneg_total_zero hv hS]
simp only [regular_potential_zero]
· simp [ChangingDomains.transposeSimplex,hS]
end KServer.AdaptiveAllocation
namespace KServer.AdaptiveAllocation
open Finset SimplexAnalytic SimplexFamilies AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
omit [DecidableEq J] [Fintype R] in
lemma regular_input_bound (A : Finset J) (hA : A.Nonempty) (f : J → R → Bool)
(h eta : J → ℝ) (hh : ∀ i, 1≤h i) (he : ∀ i, eta i∈Set.Icc 0 1)
{C ell : ℝ} (hC : 0≤C) (hl : 0≤ell) {B B' a : J → ℝ}
(ha : a∈ChangingDomains.simplex A) :
|potential C ell (regular A f h eta hh) B a-
potential C ell (regular A f h eta hh) B' a| ≤
3*C*ell*ChangingDomains.variation B B' := by
have hs : (∑ i, a i)=1 := by simpa only [ite_eq_left hA] using ha.2.1
exact regular_input_slopes ha.1 hs hh (fun i => (he i).1) (fun i => (he i).2) hC hl
omit [DecidableEq J] [Fintype R] in
lemma regular_parameter_jump (A A' : Finset J) (f g : J → R → Bool)
(h h' eta eta' : J → ℝ) (hh : ∀ i, 1≤h i) (hh' : ∀ i, 1≤h' i)
(he : ∀ i, eta i∈Set.Icc 0 1) (he' : ∀ i, eta' i∈Set.Icc 0 1)
(heq : ∀ i, h i=h' i → eta i=eta' i)
{C ell : ℝ} (hC : 0≤C) (hl : 0≤ell) {B a : J → ℝ}
(hB : ∀ i, 0≤B i) (ha : ∀ i, a i∈Set.Icc 0 1)
(hcap : ∀ i, (∑ j, B j)*a i≤(1+eta i)*B i) :
|potential C ell (regular A' g h' eta' hh') B a-
potential C ell (regular A f h eta hh) B a| ≤
8*C*ell*(∑ i, if h i=h' i then 0 else B i) := by
have hS : 0≤∑ i, B i := sum_nonneg fun i _ => hB i
have hi (i : J) :
|primitive (regularF (h' i)) C ell (eta' i) (∑ j, B j) (B i) 0 (a i)-
primitive (regularF (h i)) C ell (eta i) (∑ j, B j) (B i) 0 (a i)| ≤
8*C*ell*(if h i=h' i then 0 else B i) := by
by_cases hhx : h i=h' i
· simp [hhx,heq i hhx]
· rw [ite_eq_right hhx]
have ho := regular_component_bound (hh i) (ha i) hC hl (he i).1 hS (hB i)
have hn := regular_component_bound (hh' i) (ha i) hC hl (he' i).1 hS (hB i)
have hep := mul_le_mul_of_nonneg_right (he i).2 (hB i)
have he'p := mul_le_mul_of_nonneg_right (he' i).2 (hB i)
have hc' := hcap i
have hlo : (∑ j, B j)*a i+(1+eta i)*B i≤4*B i := by nlinarith
have hln : (∑ j, B j)*a i+(1+eta' i)*B i≤4*B i := by nlinarith
have hco := mul_le_mul_of_nonneg_left hlo (mul_nonneg hC hl)
have hcn := mul_le_mul_of_nonneg_left hln (mul_nonneg hC hl)
have hab := abs_sub
(primitive (regularF (h' i)) C ell (eta' i) (∑ j, B j) (B i) 0 (a i))
(primitive (regularF (h i)) C ell (eta i) (∑ j, B j) (B i) 0 (a i))
nlinarith
change |(∑ i, primitive (regularF (h' i)) C ell (eta' i) (∑ j, B j) (B i) 0 (a i))-
∑ i, primitive (regularF (h i)) C ell (eta i) (∑ j, B j) (B i) 0 (a i)| ≤ _
rw [←sum_sub_distrib,mul_sum]
exact (abs_sum_le_sum_abs _ _).trans (sum_le_sum fun i _ => hi i)
omit [DecidableEq J] in
lemma total_variation_bound (B B' : J → ℝ) :
|(∑ i, B i)-(∑ i, B' i)|≤ChangingDomains.variation B B' := by
rw [←sum_sub_distrib]
exact abs_sum_le_sum_abs _ _
omit [Fintype J] in
lemma transpose_cap {B : Finset J} {S : ℝ} {a v gamma : J → ℝ}
(hv : ∀ i, 0≤v i) (hg : ∀ i, 0≤gamma i)
(hcap : ∀ i, S*a i≤gamma i*v i) :
∀ i, S*(ChangingDomains.transposeSimplex B S a) i≤gamma i*v i := by
intro i
by_cases hs : S=0
· simp only [hs,zero_mul]
exact mul_nonneg (hg i) (hv i)
· simpa [ChangingDomains.transposeSimplex,hs] using hcap i
/-- This is the prepared minimizer from the manuscript; no drift inequality
is an input to its definition. -/
def regularPrepare (C ell ct : ℝ) (A B : Finset J) (g : J → R → Bool)
(h : J → ℝ) (hh : ∀ i, 1≤h i) (p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
(family C ell).update (regular A (preparedFlags A B g) h (fun i => ct*h i/ell) hh)
p (∑ i, preparedInput A B g p i) a
/-- Delete and insert zero coordinates following the prepared minimizing
update, with a canonical simplex state only when its weight is exactly zero. -/
def regularTransport (C ell ct : ℝ) (A B : Finset J) (g : J → R → Bool)
(h : J → ℝ) (hh : ∀ i, 1≤h i) (p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
ChangingDomains.transposeSimplex B (∑ i, preparedInput A B g p i)
(regularPrepare C ell ct A B g h hh p a)
lemma regular_transport_mem {A B : Finset J} (hA : A.Nonempty) (hB : B.Nonempty)
(g : J → R → Bool) (h : J → ℝ) (hh : ∀ i, 1≤h i)
{C ell ct ηmax Cexp : ℝ} (hC : 0<C) (hl : 0<ell) (hc : 0<ct)
(hmax : ∀ i∈A, ct*h i/ell≤ηmax) (hCexp : 0≤Cexp)
(htail : ∑ i∈A, Real.exp (-h i)≤Cexp)
(hgap : 2*(25+32*Cexp)*(1+ηmax)<C*ct)
(p : J × R → ℝ) (hp : ∀ ir, 0≤p ir) (a : J → ℝ)
(ha : a∈ChangingDomains.simplex A) :
regularTransport C ell ct A B g h hh p a∈ChangingDomains.simplex B := by
have hp' : ∀ i r, 0≤p (i,r) := fun i r => hp (i,r)
have hcap := regular_update_feasible hA (preparedFlags A B g) h hh hC hl hc hmax
hCexp htail hgap p hp (prepared_flags_outside A B g) a ha
exact ChangingDomains.transposeSimplex_mem (v := preparedInput A B g p)
hA hB ((family C ell).update_mem _ _ _ _)
(sum_nonneg fun i _ => ChangingDomains.core_nonneg hp' i) hcap
(prepared_input_outside A B g p)
end KServer.AdaptiveAllocation
namespace KServer.AdaptiveAllocation
open Finset SimplexAnalytic SimplexFamilies AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
lemma literal_update_payment (C ell : ℝ) (d : Data J R) (p : J × R → ℝ) (c : ℝ)
{a : J → ℝ} (ha : a∈ChangingDomains.simplex d.active) :
c*ChangingDomains.variation ((family C ell).update d p c a) a ≤
potential C ell d (core d p) a-
potential C ell d (core d p) ((family C ell).update d p c a) := by
have hm := update_isMin C ell d p c a ha
change potential C ell d (core d p) ((family C ell).update d p c a)+
c*ChangingDomains.variation ((family C ell).update d p c a) a ≤
potential C ell d (core d p) a+c*ChangingDomains.variation a a at hm
rw [ChangingDomains.variation_self,mul_zero,add_zero] at hm
linarith
/-- The final update after genuine preparation and transport. -/
def regularStep (C ell ct : ℝ) (A B : Finset J) (g : J → R → Bool)
(h h' : J → ℝ) (hh : ∀ i, 1≤h i) (hh' : ∀ i, 1≤h' i)
(p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
(family C ell).update (regular B g h' (fun i => ct*h' i/ell) hh') p
(∑ i, ChangingDomains.core g (fun i r => p (i,r)) i)
(regularTransport C ell ct A B g h hh p a)
lemma regular_step_payment {A B : Finset J} (hA : A.Nonempty) (hB : B.Nonempty)
(f g : J → R → Bool) (h h' : J → ℝ)
(hh : ∀ i, 1≤h i) (hh' : ∀ i, 1≤h' i)
{C ell ct ηmax Cexp : ℝ} (hC : 0<C) (hl : 0<ell) (hc : 0<ct)
(he : ∀ i, ct*h i/ell∈Set.Icc 0 1) (he' : ∀ i, ct*h' i/ell∈Set.Icc 0 1)
(hmax : ∀ i∈A, ct*h i/ell≤ηmax) (hCexp : 0≤Cexp)
(htail : ∑ i∈A, Real.exp (-h i)≤Cexp)
(hgap : 2*(25+32*Cexp)*(1+ηmax)<C*ct)
(p : J × R → ℝ) (hp : ∀ ir, p ir∈Set.Icc 0 1)
(hf : ∀ i∉A, ∀ r, f i r=false) (hg : ∀ i∉B, ∀ r, g i r=false)
(a : J → ℝ) (ha : a∈ChangingDomains.simplex A) :
let d₀ := regular A f h (fun i => ct*h i/ell) hh
let d₃ := regular B g h' (fun i => ct*h' i/ell) hh'
let B₀ := core d₀ p
let B₃ := core d₃ p
let B₁ := preparedInput A B g p
let a₃ := regularStep C ell ct A B g h h' hh hh' p a
(∑ i, B₃ i)*ChangingDomains.variation a₃ a ≤
potential C ell d₀ B₀ a-potential C ell d₃ B₃ a₃+
(6*C*ell+4)*ChangingDomains.changedFlags f g+
8*C*ell*(∑ i, if h i=h' i then 0 else B₁ i) := by
intro d₀ d₃ B₀ B₃ B₁ a₃
let d₁ := regular A (preparedFlags A B g) h (fun i => ct*h i/ell) hh
let a₁ := regularPrepare C ell ct A B g h hh p a
let a₂ := regularTransport C ell ct A B g h hh p a
have hp₀ : ∀ ir, 0≤p ir := fun ir => (hp ir).1
have hp₀' : ∀ i r, 0≤p (i,r) := fun i r => (hp (i,r)).1
have hB₁ : ∀ i, 0≤B₁ i := fun i => ChangingDomains.core_nonneg hp₀' i
have hS₁ : 0≤∑ i, B₁ i := sum_nonneg fun i _ => hB₁ i
have ha₁ : a₁∈ChangingDomains.simplex A := (family C ell).update_mem _ _ _ _
have ha₂ : a₂∈ChangingDomains.simplex B :=
regular_transport_mem hA hB g h hh hC hl hc hmax hCexp htail hgap p hp₀ a ha
have hcap₁ : ∀ i, (∑ j, B₁ j)*a₁ i≤(1+ct*h i/ell)*B₁ i :=
regular_update_feasible hA (preparedFlags A B g) h hh hC hl hc hmax hCexp htail hgap
p hp₀ (prepared_flags_outside A B g) a ha
have hcap₂ : ∀ i, (∑ j, B₁ j)*a₂ i≤(1+ct*h i/ell)*B₁ i :=
transpose_cap hB₁ (fun i => by linarith [(he i).1]) hcap₁
have hin := ChangingDomains.synthetic_errors (fun i r => hp (i,r)) hf hg
have herr₀ : ChangingDomains.variation B₀ B₁≤ChangingDomains.changedFlags f g := hin.1
have herr₃ : ChangingDomains.variation B₃ B₁≤ChangingDomains.changedFlags f g := hin.2
have hST : (∑ i, B₁ i)≤∑ i, B₃ i :=
sub_nonneg.mp (ChangingDomains.synthetic_total (A := A) (B := B) (g := g) hp₀')
have hδ : (∑ i, B₃ i)-(∑ i, B₁ i)≤ChangingDomains.changedFlags f g :=
(le_abs_self _).trans ((total_variation_bound B₃ B₁).trans herr₃)
have him₀ := regular_input_bound A hA f h (fun i => ct*h i/ell) hh he hC.le hl.le
(B := B₀) (B' := B₁) ha
have him₃ := regular_input_bound B hB g h' (fun i => ct*h' i/ell) hh' he' hC.le hl.le
(B := B₃) (B' := B₁) ha₂
have ht := regular_parameter_jump A B f g h h' (fun i => ct*h i/ell)
(fun i => ct*h' i/ell) hh hh' he he' (fun i hi => by rw [hi]) hC.le hl.le
hB₁ (fun i => ChangingDomains.simplex_coordinate ha₂ i) hcap₂
have hpm₁ : (∑ i, B₁ i)*ChangingDomains.variation a₁ a ≤
potential C ell d₀ B₁ a-potential C ell d₀ B₁ a₁ :=
literal_update_payment C ell d₁ p (∑ i, B₁ i) ha
have hpm₃ : (∑ i, B₃ i)*ChangingDomains.variation a₃ a₂ ≤
potential C ell d₃ B₃ a₂-potential C ell d₃ B₃ a₃ :=
literal_update_payment C ell d₃ p (∑ i, B₃ i) ha₂
have htrans : potential C ell d₀ B₁ a₂=potential C ell d₀ B₁ a₁ :=
regular_transpose_value A B f h (fun i => ct*h i/ell) hh C ell B₁ a₁ hB₁
have hweight := ChangingDomains.prepared_weight_comparison ha ha₁ ha₂ hS₁ hST
(ChangingDomains.transposeSimplex_payment B (∑ i, B₁ i) a₁) (a₃ := a₃)
have hinput₀ := mul_le_mul_of_nonneg_left herr₀ (by positivity : 0≤3*C*ell)
have hinput₃ := mul_le_mul_of_nonneg_left herr₃ (by positivity : 0≤3*C*ell)
have he₀ := (neg_le_of_abs_le him₀)
have he₃ := (le_of_abs_le him₃)
have hep := le_of_abs_le ht
change _ ≤ 8*C*ell*(∑ i, if h i=h' i then 0 else B₁ i) at hep
change -(3*C*ell*ChangingDomains.variation B₀ B₁) ≤
potential C ell d₀ B₀ a-potential C ell d₀ B₁ a at he₀
change potential C ell d₃ B₃ a₂-potential C ell d₃ B₁ a₂ ≤
3*C*ell*ChangingDomains.variation B₃ B₁ at he₃
change potential C ell d₃ B₁ a₂-potential C ell d₀ B₁ a₂ ≤ _ at hep
nlinarith
end KServer.AdaptiveAllocation
namespace KServer.AdaptiveAllocation
open Finset SimplexAnalytic SimplexFamilies AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
lemma marked_update_feasible {A : Finset J} {o : J} (hoA : o∈A)
(f : J → R → Bool) (h : J → ℝ) {u : ℝ} (hu : 0<u) (hu1 : u≤1)
(ho : h o=u) (hh : ∀ i≠o, 1≤h i)
{C ell ct ηmax Cexp c : ℝ} (hC : 0<C) (hl : 0<ell) (hc : 0<ct)
(hmax : ∀ i∈A, ct*h i/ell≤ηmax) (hCexp : 0≤Cexp)
(hsideC : 0<c) (hsideC1 : c≤1)
(hside : ∀ i∈A, i≠o → c*(1+Real.log (1/u))≤h i)
(htail : ∑ i∈A.erase o, Real.exp (-h i)≤Cexp*u)
(hgap : 2*((25*c+2+32*Cexp)/c)*(1+ηmax)<C*ct)
(p : J × R → ℝ) (hp : ∀ ir, 0≤p ir) (hf : ∀ i∉A, ∀ r, f i r=false)
(a : J → ℝ) (ha : a∈ChangingDomains.simplex A) :
let d := marked A f o h (fun i => ct*h i/ell) u hu hu1 hh
let B := core d p
let a' := (family C ell).update d p (∑ i, B i) a
∀ i, (∑ j, B j)*a' i≤(1+ct*h i/ell)*B i := by
intro d B a'
have hB : ∀ i, 0≤B i := fun i => ChangingDomains.core_nonneg (fun i r => hp (i,r)) i
have hBz : ∀ i∉A, B i=0 := by
intro i hi
simp [B,core,d,marked,hf i hi]
apply SupportedAllocation.marked_supported_minimizer_feasible hoA
((family C ell).update_mem d p (∑ i, B i) a) ha hu hu1 rfl ho
(fun i _ hi => hh i hi) hc hl hmax hC hB hBz hCexp hsideC hsideC1 hside htail hgap
exact update_isMin C ell d p (∑ i, B i) a
omit [Fintype R] in
lemma marked_input_bound (A : Finset J) (hA : A.Nonempty) (f : J → R → Bool)
(o : J) (h eta : J → ℝ) {u : ℝ} (hu : 0<u) (hu1 : u≤1)
(hh : ∀ i≠o, 1≤h i) (he : ∀ i, eta i∈Set.Icc 0 1)
{C ell : ℝ} (hC : 0≤C) (hl : 0≤ell) {B B' a : J → ℝ}
(ha : a∈ChangingDomains.simplex A) :
|potential C ell (marked A f o h eta u hu hu1 hh) B a-
potential C ell (marked A f o h eta u hu hu1 hh) B' a| ≤
13*C*ell*ChangingDomains.variation B B' := by
have hs : (∑ i, a i)=1 := by simpa only [ite_eq_left hA] using ha.2.1
exact marked_input_slopes o ha.1 hs hh hu hu1 rfl (fun i => (he i).1)
(fun i => (he i).2) hC hl
omit [Fintype R] in
lemma marked_potential_zero (A : Finset J) (f : J → R → Bool) (o : J)
(h eta : J → ℝ) {u : ℝ} (hu : 0<u) (hu1 : u≤1) (hh : ∀ i≠o, 1≤h i)
(C ell : ℝ) (a : J → ℝ) :
potential C ell (marked A f o h eta u hu hu1 hh) (fun _ => 0) a=0 := by
simp [potential,marked,primitive]
omit [Fintype R] in
lemma marked_transpose_value (A B : Finset J) (f : J → R → Bool) (o : J)
(h eta : J → ℝ) {u : ℝ} (hu : 0<u) (hu1 : u≤1) (hh : ∀ i≠o, 1≤h i)
(C ell : ℝ) (v a : J → ℝ) (hv : ∀ i, 0≤v i) :
potential C ell (marked A f o h eta u hu hu1 hh) v
(ChangingDomains.transposeSimplex B (∑ i, v i) a)=
potential C ell (marked A f o h eta u hu hu1 hh) v a := by
by_cases hS : (∑ i, v i)=0
· rw [nonneg_total_zero hv hS]
simp only [marked_potential_zero]
· simp [ChangingDomains.transposeSimplex,hS]
lemma simplex_side_weight {A : Finset J} (hA : A.Nonempty) {a B eta : J → ℝ}
(ha : a∈ChangingDomains.simplex A) (hB : ∀ i, 0≤B i)
(he : ∀ i, eta i≤1) (hcap : ∀ i, (∑ j, B j)*a i≤(1+eta i)*B i) (o : J) :
(∑ j, B j)*(1-a o)≤2*(∑ i∈Finset.univ.erase o, B i) := by
have hs : (∑ i, a i)=1 := by simpa only [ite_eq_left hA] using ha.2.1
have hx : 1-a o=∑ i∈Finset.univ.erase o, a i := by
have ht := Finset.add_sum_erase Finset.univ (fun i => a i) (Finset.mem_univ o)
rw [hs] at ht
linarith
rw [hx,mul_sum,mul_sum]
exact sum_le_sum fun i _ => (hcap i).trans
(mul_le_mul_of_nonneg_right (by linarith [he i]) (hB i))
omit [Fintype R] in
/-- Marked parameter edits charge the dominant component only when `u`
changes, and charge it to the side total, not the dominant mass. -/
lemma marked_parameter_jump (A A' : Finset J) (hA' : A'.Nonempty)
(f g : J → R → Bool) (o : J) (h h' eta eta' : J → ℝ)
{u u' : ℝ} (hu : 0<u) (hu1 : u≤1) (hu' : 0<u') (hu1' : u'≤1)
(hh : ∀ i≠o, 1≤h i) (hh' : ∀ i≠o, 1≤h' i)
(he : ∀ i, eta i∈Set.Icc 0 1) (he' : ∀ i, eta' i∈Set.Icc 0 1)
(heq : ∀ i, h i=h' i → eta i=eta' i)
(heqo : u=u' → eta o=eta' o) (heo : eta o≤u) (heo' : eta' o≤u')
{C ell : ℝ} (hC : 0≤C) (hl : 0≤ell) {B a : J → ℝ}
(hB : ∀ i, 0≤B i) (ha : a∈ChangingDomains.simplex A')
(hcap : ∀ i, (∑ j, B j)*a i≤(1+eta i)*B i) :
|potential C ell (marked A' g o h' eta' u' hu' hu1' hh') B a-
potential C ell (marked A f o h eta u hu hu1 hh) B a| ≤
8*C*ell*(∑ i∈Finset.univ.erase o, if h i=h' i then 0 else B i)+
24*C*ell*(if u=u' then 0 else
(∑ i∈Finset.univ.erase o, B i)+(u+u')*(∑ i, B i)) := by
let d₀ := marked A f o h eta u hu hu1 hh
let d₁ := marked A' g o h' eta' u' hu' hu1' hh'
let term := fun i => primitive (d₁.F i) C ell (eta' i) (∑ j, B j) (B i) (d₁.base i) (a i)-
primitive (d₀.F i) C ell (eta i) (∑ j, B j) (B i) (d₀.base i) (a i)
have hS : 0≤∑ i, B i := sum_nonneg fun i _ => hB i
have hBs : 0≤∑ i∈Finset.univ.erase o, B i := sum_nonneg fun i _ => hB i
have hai := fun i => ChangingDomains.simplex_coordinate ha i
have hside := simplex_side_weight hA' ha hB (fun i => (he i).2) hcap o
have hSpr : (∑ j, B j)=B o+∑ i∈Finset.univ.erase o, B i :=
(Finset.add_sum_erase Finset.univ B (Finset.mem_univ o)).symm
have hregular (i : J) (hi : i∈Finset.univ.erase o) :
|term i|≤8*C*ell*(if h i=h' i then 0 else B i) := by
have hio : i≠o := (Finset.mem_erase.mp hi).1
change |primitive (if i=o then markedF u' (1+Real.log (1/u')) else regularF (h' i))
C ell (eta' i) (∑ j, B j) (B i) (if i=o then 1 else 0) (a i)-
primitive (if i=o then markedF u (1+Real.log (1/u)) else regularF (h i))
C ell (eta i) (∑ j, B j) (B i) (if i=o then 1 else 0) (a i)|≤_
simp only [ite_eq_right hio]
by_cases hx : h i=h' i
· simp [hx,heq i hx]
· rw [ite_eq_right hx]
have ho := regular_component_bound (hh i hio) (hai i) hC hl (he i).1 hS (hB i)
have hn := regular_component_bound (hh' i hio) (hai i) hC hl (he' i).1 hS (hB i)
have hep := mul_le_mul_of_nonneg_right (he i).2 (hB i)
have he'p := mul_le_mul_of_nonneg_right (he' i).2 (hB i)
have hlo : (∑ j, B j)*a i+(1+eta i)*B i≤4*B i := by nlinarith [hcap i]
have hln : (∑ j, B j)*a i+(1+eta' i)*B i≤4*B i := by nlinarith [hcap i]
have hco := mul_le_mul_of_nonneg_left hlo (mul_nonneg hC hl)
have hcn := mul_le_mul_of_nonneg_left hln (mul_nonneg hC hl)
have hab := abs_sub
(primitive (regularF (h' i)) C ell (eta' i) (∑ j, B j) (B i) 0 (a i))
(primitive (regularF (h i)) C ell (eta i) (∑ j, B j) (B i) 0 (a i))
nlinarith
have hmarked : |term o|≤24*C*ell*(if u=u' then 0 else
(∑ i∈Finset.univ.erase o, B i)+(u+u')*(∑ i, B i)) := by
change |primitive (if o=o then markedF u' (1+Real.log (1/u')) else regularF (h' o))
C ell (eta' o) (∑ j, B j) (B o) (if o=o then 1 else 0) (a o)-
primitive (if o=o then markedF u (1+Real.log (1/u)) else regularF (h o))
C ell (eta o) (∑ j, B j) (B o) (if o=o then 1 else 0) (a o)|≤_
simp only [ite_true]
by_cases hx : u=u'
· simp [hx,heqo hx]
· rw [ite_eq_right hx]
have ho := marked_component_bound hu hu1 rfl (hai o) hC hl (he o).1 heo (hB o) hBs hSpr
have hn := marked_component_bound hu' hu1' rfl (hai o) hC hl (he' o).1 heo' (hB o) hBs hSpr
have hab := abs_sub
(primitive (markedF u' (1+Real.log (1/u'))) C ell (eta' o) (∑ j, B j) (B o) 1 (a o))
(primitive (markedF u (1+Real.log (1/u))) C ell (eta o) (∑ j, B j) (B o) 1 (a o))
have hs := mul_le_mul_of_nonneg_left hside (by positivity : 0≤8*C*ell)
have hpos : 0≤C*ell*(u+u')*(∑ j, B j) := by positivity
nlinarith
change |(∑ i, primitive (d₁.F i) C ell (eta' i) (∑ j, B j) (B i) (d₁.base i) (a i))-
∑ i, primitive (d₀.F i) C ell (eta i) (∑ j, B j) (B i) (d₀.base i) (a i)|≤_
rw [←sum_sub_distrib]
change |∑ i, term i|≤_
have ht := (abs_sum_le_sum_abs term Finset.univ)
rw [←Finset.add_sum_erase Finset.univ (fun i => |term i|) (Finset.mem_univ o)] at ht
have hr := sum_le_sum hregular
rw [←mul_sum] at hr
linarith
end KServer.AdaptiveAllocation
namespace KServer.AdaptiveAllocation
open Finset SimplexAnalytic SimplexFamilies AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
def markedPrepare (C ell ct : ℝ) (A B : Finset J) (g : J → R → Bool)
(o : J) (h : J → ℝ) (u : ℝ) (hu : 0<u) (hu1 : u≤1)
(hh : ∀ i≠o, 1≤h i) (p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
(family C ell).update
(marked A (preparedFlags A B g) o h (fun i => ct*h i/ell) u hu hu1 hh)
p (∑ i, preparedInput A B g p i) a
def markedTransport (C ell ct : ℝ) (A B : Finset J) (g : J → R → Bool)
(o : J) (h : J → ℝ) (u : ℝ) (hu : 0<u) (hu1 : u≤1)
(hh : ∀ i≠o, 1≤h i) (p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
ChangingDomains.transposeSimplex B (∑ i, preparedInput A B g p i)
(markedPrepare C ell ct A B g o h u hu hu1 hh p a)
lemma marked_transport_mem {A B : Finset J} {o : J} (hoA : o∈A) (hB : B.Nonempty)
(g : J → R → Bool) (h : J → ℝ) {u : ℝ} (hu : 0<u) (hu1 : u≤1)
(ho : h o=u) (hh : ∀ i≠o, 1≤h i)
{C ell ct ηmax Cexp c : ℝ} (hC : 0<C) (hl : 0<ell) (hc : 0<ct)
(hmax : ∀ i∈A, ct*h i/ell≤ηmax) (hCexp : 0≤Cexp)
(hsideC : 0<c) (hsideC1 : c≤1)
(hside : ∀ i∈A, i≠o → c*(1+Real.log (1/u))≤h i)
(htail : ∑ i∈A.erase o, Real.exp (-h i)≤Cexp*u)
(hgap : 2*((25*c+2+32*Cexp)/c)*(1+ηmax)<C*ct)
(p : J × R → ℝ) (hp : ∀ ir, 0≤p ir) (a : J → ℝ)
(ha : a∈ChangingDomains.simplex A) :
markedTransport C ell ct A B g o h u hu hu1 hh p a∈ChangingDomains.simplex B := by
have hp' : ∀ i r, 0≤p (i,r) := fun i r => hp (i,r)
have hcap := marked_update_feasible hoA (preparedFlags A B g) h hu hu1 ho hh
hC hl hc hmax hCexp hsideC hsideC1 hside htail hgap p hp
(prepared_flags_outside A B g) a ha
exact ChangingDomains.transposeSimplex_mem (v := preparedInput A B g p)
⟨o,hoA⟩ hB ((family C ell).update_mem _ _ _ _)
(sum_nonneg fun i _ => ChangingDomains.core_nonneg hp' i) hcap
(prepared_input_outside A B g p)
def markedStep (C ell ct : ℝ) (A B : Finset J) (g : J → R → Bool)
(o : J) (h h' : J → ℝ) (u u' : ℝ) (hu : 0<u) (hu1 : u≤1)
(hu' : 0<u') (hu1' : u'≤1) (hh : ∀ i≠o, 1≤h i) (hh' : ∀ i≠o, 1≤h' i)
(p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
(family C ell).update (marked B g o h' (fun i => ct*h' i/ell) u' hu' hu1' hh') p
(∑ i, ChangingDomains.core g (fun i r => p (i,r)) i)
(markedTransport C ell ct A B g o h u hu hu1 hh p a)
lemma marked_step_payment {A B : Finset J} {o : J} (hoA : o∈A) (hB : B.Nonempty)
(f g : J → R → Bool) (h h' : J → ℝ) {u u' : ℝ}
(hu : 0<u) (hu1 : u≤1) (hu' : 0<u') (hu1' : u'≤1)
(ho : h o=u) (ho' : h' o=u') (hh : ∀ i≠o, 1≤h i) (hh' : ∀ i≠o, 1≤h' i)
{C ell ct ηmax Cexp c : ℝ} (hC : 0<C) (hl : 0<ell) (hc : 0<ct)
(he : ∀ i, ct*h i/ell∈Set.Icc 0 1) (he' : ∀ i, ct*h' i/ell∈Set.Icc 0 1)
(hoeta : ct*u/ell≤u) (hoeta' : ct*u'/ell≤u')
(hmax : ∀ i∈A, ct*h i/ell≤ηmax) (hCexp : 0≤Cexp)
(hsideC : 0<c) (hsideC1 : c≤1)
(hside : ∀ i∈A, i≠o → c*(1+Real.log (1/u))≤h i)
(htail : ∑ i∈A.erase o, Real.exp (-h i)≤Cexp*u)
(hgap : 2*((25*c+2+32*Cexp)/c)*(1+ηmax)<C*ct)
(p : J × R → ℝ) (hp : ∀ ir, p ir∈Set.Icc 0 1)
(hf : ∀ i∉A, ∀ r, f i r=false) (hg : ∀ i∉B, ∀ r, g i r=false)
(a : J → ℝ) (ha : a∈ChangingDomains.simplex A) :
let d₀ := marked A f o h (fun i => ct*h i/ell) u hu hu1 hh
let d₃ := marked B g o h' (fun i => ct*h' i/ell) u' hu' hu1' hh'
let B₀ := core d₀ p
let B₃ := core d₃ p
let B₁ := preparedInput A B g p
let a₃ := markedStep C ell ct A B g o h h' u u' hu hu1 hu' hu1' hh hh' p a
(∑ i, B₃ i)*ChangingDomains.variation a₃ a ≤
potential C ell d₀ B₀ a-potential C ell d₃ B₃ a₃+
(26*C*ell+4)*ChangingDomains.changedFlags f g+
8*C*ell*(∑ i∈Finset.univ.erase o, if h i=h' i then 0 else B₁ i)+
24*C*ell*(if u=u' then 0 else
(∑ i∈Finset.univ.erase o, B₁ i)+(u+u')*(∑ i, B₁ i)) := by
intro d₀ d₃ B₀ B₃ B₁ a₃
let d₁ := marked A (preparedFlags A B g) o h (fun i => ct*h i/ell) u hu hu1 hh
let a₁ := markedPrepare C ell ct A B g o h u hu hu1 hh p a
let a₂ := markedTransport C ell ct A B g o h u hu hu1 hh p a
have hA : A.Nonempty := ⟨o,hoA⟩
have hp₀ : ∀ ir, 0≤p ir := fun ir => (hp ir).1
have hp₀' : ∀ i r, 0≤p (i,r) := fun i r => (hp (i,r)).1
have hB₁ : ∀ i, 0≤B₁ i := fun i => ChangingDomains.core_nonneg hp₀' i
have hS₁ : 0≤∑ i, B₁ i := sum_nonneg fun i _ => hB₁ i
have ha₁ : a₁∈ChangingDomains.simplex A := (family C ell).update_mem _ _ _ _
have ha₂ : a₂∈ChangingDomains.simplex B :=
marked_transport_mem hoA hB g h hu hu1 ho hh hC hl hc hmax hCexp
hsideC hsideC1 hside htail hgap p hp₀ a ha
have hcap₁ : ∀ i, (∑ j, B₁ j)*a₁ i≤(1+ct*h i/ell)*B₁ i :=
marked_update_feasible hoA (preparedFlags A B g) h hu hu1 ho hh hC hl hc hmax hCexp
hsideC hsideC1 hside htail hgap p hp₀ (prepared_flags_outside A B g) a ha
have hcap₂ : ∀ i, (∑ j, B₁ j)*a₂ i≤(1+ct*h i/ell)*B₁ i :=
transpose_cap hB₁ (fun i => by linarith [(he i).1]) hcap₁
have hin := ChangingDomains.synthetic_errors (fun i r => hp (i,r)) hf hg
have herr₀ : ChangingDomains.variation B₀ B₁≤ChangingDomains.changedFlags f g := hin.1
have herr₃ : ChangingDomains.variation B₃ B₁≤ChangingDomains.changedFlags f g := hin.2
have hST : (∑ i, B₁ i)≤∑ i, B₃ i :=
sub_nonneg.mp (ChangingDomains.synthetic_total (A := A) (B := B) (g := g) hp₀')
have hδ : (∑ i, B₃ i)-(∑ i, B₁ i)≤ChangingDomains.changedFlags f g :=
(le_abs_self _).trans ((total_variation_bound B₃ B₁).trans herr₃)
have him₀ := marked_input_bound A hA f o h (fun i => ct*h i/ell) hu hu1 hh he
hC.le hl.le (B := B₀) (B' := B₁) ha
have him₃ := marked_input_bound B hB g o h' (fun i => ct*h' i/ell) hu' hu1' hh' he'
hC.le hl.le (B := B₃) (B' := B₁) ha₂
have ht := marked_parameter_jump A B hB f g o h h' (fun i => ct*h i/ell)
(fun i => ct*h' i/ell) hu hu1 hu' hu1' hh hh' he he'
(fun i hi => by rw [hi]) (fun hi => by rw [ho,ho',hi])
(by simpa [ho] using hoeta) (by simpa [ho'] using hoeta') hC.le hl.le hB₁ ha₂ hcap₂
have hpm₁ : (∑ i, B₁ i)*ChangingDomains.variation a₁ a ≤
potential C ell d₀ B₁ a-potential C ell d₀ B₁ a₁ :=
literal_update_payment C ell d₁ p (∑ i, B₁ i) ha
have hpm₃ : (∑ i, B₃ i)*ChangingDomains.variation a₃ a₂ ≤
potential C ell d₃ B₃ a₂-potential C ell d₃ B₃ a₃ :=
literal_update_payment C ell d₃ p (∑ i, B₃ i) ha₂
have htrans : potential C ell d₀ B₁ a₂=potential C ell d₀ B₁ a₁ :=
marked_transpose_value A B f o h (fun i => ct*h i/ell) hu hu1 hh C ell B₁ a₁ hB₁
have hweight := ChangingDomains.prepared_weight_comparison ha ha₁ ha₂ hS₁ hST
(ChangingDomains.transposeSimplex_payment B (∑ i, B₁ i) a₁) (a₃ := a₃)
have hinput₀ := mul_le_mul_of_nonneg_left herr₀ (by positivity : 0≤13*C*ell)
have hinput₃ := mul_le_mul_of_nonneg_left herr₃ (by positivity : 0≤13*C*ell)
have he₀ := neg_le_of_abs_le him₀
have he₃ := le_of_abs_le him₃
have hep := le_of_abs_le ht
change -(13*C*ell*ChangingDomains.variation B₀ B₁) ≤
potential C ell d₀ B₀ a-potential C ell d₀ B₁ a at he₀
change potential C ell d₃ B₃ a₂-potential C ell d₃ B₁ a₂ ≤
13*C*ell*ChangingDomains.variation B₃ B₁ at he₃
change potential C ell d₃ B₁ a₂-potential C ell d₀ B₁ a₂ ≤ _ at hep
nlinarith
end KServer.AdaptiveAllocation
/-! Exact side primitive and compact minimizing update of §04,
eq:side-primitive-explicit and lem:side-tracker. This is an allocation
dependency of the absent main, not a separately counted main theorem. -/
noncomputable section
open scoped BigOperators
open Set Filter
namespace KServer.SideTracker
/-- The explicit integral in eq:side-primitive-explicit. -/
def primitive (c b θ z B D w : ℝ) : ℝ :=
c * (D / θ * (w - z * Real.log (1 + w / z)) +
D * z * Real.log (1 + w / z) / 2 -
(b + θ / 2) * B * Real.log (1 + w / z) / θ)
lemma primitive_derivative {c b θ z B D w : ℝ} (hθ : 0 < θ) (hz : 0 < z)
(hw : 0 ≤ w) :
HasDerivAt (primitive c b θ z B D)
(c * (D * w - (b + θ / 2) * B + D * θ * z / 2) /
(θ * (w + z))) w := by
have hl : 0 < 1 + w / z := by positivity
have hd := (((hasDerivAt_id w).div_const z).const_add 1).log hl.ne'
have he : 1 / z / (1 + w / z) = 1 / (w + z) := by
field_simp
ring
simp only [id_eq] at hd
rw [he] at hd
have H := ((((hasDerivAt_id w).sub (hd.const_mul z)).const_mul (D / θ)).add
((hd.const_mul (D * z)).div_const 2)).sub
((hd.const_mul ((b + θ / 2) * B)).div_const θ)
have hwz : w + z ≠ 0 := by positivity
have he' : c * (D * w - (b + θ / 2) * B + D * θ * z / 2) / (θ * (w + z)) =
c * (D / θ * (1 - z * (1 / (w + z))) + D * z * (1 / (w + z)) / 2 -
(b + θ / 2) * B * (1 / (w + z)) / θ) := by
field_simp [hθ.ne', hwz]
ring
rw [he']
exact H.const_mul c
/-- One-sided necessary optimality, allowing a nondifferentiable movement cost. -/
lemma derivative_le_of_left_comparison {f : ℝ → ℝ} {f' D x : ℝ}
(hx : 0 < x) (hd : HasDerivAt f f' x)
(hc : ∀ y ∈ Set.Icc 0 x, f x ≤ f y + D * (x - y)) : f' ≤ D := by
have hm : IsLocalMinOn (fun y => f y - D * y) (Set.Icc 0 x) x := by
apply IsMinOn.isLocalMinOn
intro y hy
have h := hc y hy
change f x - D * x ≤ f y - D * y
linarith
have ht : 0 - x ∈ posTangentConeAt (Set.Icc 0 x) x :=
sub_mem_posTangentConeAt_of_segment_subset
((convex_Icc 0 x).segment_subset ⟨hx.le, le_rfl⟩ ⟨le_rfl, hx.le⟩)
have h := hm.hasFDerivWithinAt_nonneg
((hd.sub ((hasDerivAt_id x).const_mul D)).hasFDerivAt.hasFDerivWithinAt) ht
simp only [ContinuousLinearMap.toSpanSingleton_apply, smul_eq_mul] at h
nlinarith
lemma neg_derivative_le_of_right_comparison {f : ℝ → ℝ} {f' D x ε : ℝ}
(hε : 0 < ε) (hd : HasDerivAt f f' x)
(hc : ∀ y ∈ Set.Icc x (x + ε), f x ≤ f y + D * (y - x)) : -D ≤ f' := by
have hm : IsLocalMinOn (fun y => f y + D * y) (Set.Icc x (x + ε)) x := by
apply IsMinOn.isLocalMinOn
intro y hy
have h := hc y hy
change f x + D * x ≤ f y + D * y
linarith
have ht : (x + ε) - x ∈ posTangentConeAt (Set.Icc x (x + ε)) x :=
sub_mem_posTangentConeAt_of_segment_subset
((convex_Icc x (x + ε)).segment_subset ⟨le_rfl, by linarith⟩
⟨by linarith, le_rfl⟩)
have h := hm.hasFDerivWithinAt_nonneg
((hd.add ((hasDerivAt_id x).const_mul D)).hasFDerivAt.hasFDerivWithinAt) ht
simp only [ContinuousLinearMap.toSpanSingleton_apply, smul_eq_mul] at h
nlinarith
variable {ι : Type*} [Fintype ι]
def domain (Cw : ℝ) : Set (ι → ℝ) := {w | (∀ i, 0 ≤ w i) ∧ ∑ i, w i ≤ Cw}
def potential (c b : ℝ) (θ z B : ι → ℝ) (D : ℝ) (w : ι → ℝ) : ℝ :=
∑ i, primitive c b (θ i) (z i) (B i) D (w i)
def movement (w v : ι → ℝ) : ℝ := ∑ i, |w i - v i|
def objective (c b : ℝ) (θ z B : ι → ℝ) (D : ℝ) (w₀ w : ι → ℝ) : ℝ :=
potential c b θ z B D w + D * movement w w₀
lemma movement_self (w : ι → ℝ) : movement w w = 0 := by simp [movement]
lemma domain_isCompact (Cw : ℝ) : IsCompact (domain (ι := ι) Cw) := by
have hc : IsClosed (domain (ι := ι) Cw) := by
change IsClosed ({w : ι → ℝ | ∀ i, 0 ≤ w i} ∩ {w : ι → ℝ | ∑ i, w i ≤ Cw})
apply IsClosed.inter
· simp only [ofPred_forall]
exact isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i)
· exact isClosed_le (continuous_finsetSum _ fun i _ => continuous_apply i) continuous_const
apply (isCompact_pi_infinite fun _ : ι => isCompact_Icc (a := (0 : ℝ)) (b := Cw)).of_isClosed_subset hc
intro w hw i
exact ⟨hw.1 i, (Finset.single_le_sum (fun j _ => hw.1 j) (Finset.mem_univ i)).trans hw.2⟩
lemma primitive_continuousOn {c b θ z B D : ℝ} (hθ : 0 < θ) (hz : 0 < z) :
ContinuousOn (primitive c b θ z B D) (Ici 0) := by
intro w hw
exact (primitive_derivative hθ hz hw).continuousAt.continuousWithinAt
lemma objective_continuousOn (c b D Cw : ℝ) (θ z B w₀ : ι → ℝ)
(hθ : ∀ i, 0 < θ i) (hz : ∀ i, 0 < z i) :
ContinuousOn (objective c b θ z B D w₀) (domain Cw) := by
apply ContinuousOn.add
· apply continuousOn_finsetSum _
intro i _
exact (primitive_continuousOn (hθ i) (hz i)).comp
(continuous_apply i).continuousOn (fun _ hw => hw.1 i)
· apply ContinuousOn.const_mul
apply continuousOn_finsetSum _
intro i _
exact ((continuous_apply i).sub continuous_const).abs.continuousOn
lemma exists_minimizer {c b D Cw : ℝ} {θ z B w₀ : ι → ℝ}
(hθ : ∀ i, 0 < θ i) (hz : ∀ i, 0 < z i) (hw : w₀ ∈ domain Cw) :
∃ w ∈ domain Cw, IsMinOn (objective c b θ z B D w₀) (domain Cw) w :=
(domain_isCompact Cw).exists_isMinOn ⟨w₀, hw⟩
(objective_continuousOn c b D Cw θ z B w₀ hθ hz)
lemma minimizer_payment {c b D Cw : ℝ} {θ z B w₀ w : ι → ℝ}
(hw₀ : w₀ ∈ domain Cw)
(hm : IsMinOn (objective c b θ z B D w₀) (domain Cw) w) :
D * movement w w₀ ≤ potential c b θ z B D w₀ - potential c b θ z B D w := by
have h := hm hw₀
change potential c b θ z B D w + D * movement w w₀ ≤
potential c b θ z B D w₀ + D * movement w₀ w₀ at h
rw [movement_self, mul_zero, add_zero] at h
linarith
lemma sum_replace [DecidableEq ι] (f : ι → ℝ → ℝ) (w : ι → ℝ) (i : ι) (y : ℝ) :
(∑ j, f j (Function.update w i y j)) = (∑ j, f j (w j)) - f i (w i) + f i y := by
have he : (∑ j ∈ Finset.univ.erase i, f j (Function.update w i y j)) =
∑ j ∈ Finset.univ.erase i, f j (w j) := by
apply Finset.sum_congr rfl
intro j hj
simp [Function.update, (Finset.mem_erase.mp hj).1]
have h₁ := Finset.sum_erase_add Finset.univ (fun j => f j (Function.update w i y j))
(Finset.mem_univ i)
have h₂ := Finset.sum_erase_add Finset.univ (fun j => f j (w j)) (Finset.mem_univ i)
simp only [Function.update_self, he] at h₁
linarith
lemma replace_mem_domain [DecidableEq ι] {Cw : ℝ} {w : ι → ℝ}
(hw : w ∈ domain Cw) (i : ι) {y : ℝ} (hy : 0 ≤ y)
(hs : y ≤ w i + (Cw - ∑ j, w j)) : Function.update w i y ∈ domain Cw := by
constructor
· intro j
by_cases h : j = i
· subst j; simpa using hy
· simpa [Function.update, h] using hw.1 j
· rw [sum_replace (fun _ x => x)]
linarith
lemma coordinate_min_comparison [DecidableEq ι] {c b D Cw : ℝ} {θ z B w₀ w : ι → ℝ}
(hD : 0 ≤ D)
(hm : IsMinOn (objective c b θ z B D w₀) (domain Cw) w)
(i : ι) {y : ℝ} (hy : Function.update w i y ∈ domain Cw) :
primitive c b (θ i) (z i) (B i) D (w i) ≤
primitive c b (θ i) (z i) (B i) D y + D * |y - w i| := by
have h := hm hy
change potential c b θ z B D w + D * movement w w₀ ≤
potential c b θ z B D (Function.update w i y) +
D * movement (Function.update w i y) w₀ at h
dsimp [potential, movement] at h
rw [sum_replace (fun j x => primitive c b (θ j) (z j) (B j) D x),
sum_replace (fun j x => |x - w₀ j|)] at h
have ht := mul_le_mul_of_nonneg_left (abs_sub_le y (w i) (w₀ i)) hD
linarith
lemma derivative_upper_violation {M b θ z B D w : ℝ}
(hb : 1 ≤ b) (hθ : 0 < θ) (hz : 0 < z) (hB : 0 ≤ B)
(hD : 0 < D) (hw : 0 ≤ w) (hM : b + θ ≤ M)
(hv : (b + θ) * B < D * w) :
D < 8 * M * (D * w - (b + θ / 2) * B + D * θ * z / 2) / (θ * (w + z)) := by
let N := D * w - (b + θ / 2) * B + D * θ * z / 2
have hN : 0 < N := by
dsimp [N]
nlinarith [mul_nonneg hθ.le hB, mul_pos (mul_pos hD hθ) hz]
have h1 : D * θ * w + D * θ * (b + θ) * z < 2 * (b + θ) * N := by
have hh : 0 < (2 * b + θ) * (D * w - (b + θ) * B) :=
mul_pos (by linarith) (sub_pos.mpr hv)
dsimp [N]
nlinarith
have h2 : D * θ * (w + z) ≤ D * θ * w + D * θ * (b + θ) * z := by
have hh := mul_le_mul_of_nonneg_left (show 1 ≤ b + θ by linarith)
(mul_nonneg (mul_nonneg hD.le hθ.le) hz.le)
nlinarith
have h3 : 2 * (b + θ) * N ≤ 8 * M * N := by
have hh := mul_le_mul_of_nonneg_right hM hN.le
nlinarith [mul_pos (show 0 < M by linarith) hN]
apply (lt_div_iff₀ (mul_pos hθ (by linarith : 0 < w + z))).mpr
dsimp [N] at h2 h1 h3
nlinarith [h2.trans_lt (h1.trans_le h3)]
lemma derivative_lower_violation {M b θ z B D w : ℝ}
(hb : 1 ≤ b) (hθ : 0 < θ) (hz : 0 < z)
(hD : 0 < D) (hw : 0 ≤ w) (hM : b + θ ≤ M)
(hv : D * w < b * B - θ * z * D) :
8 * M * (D * w - (b + θ / 2) * B + D * θ * z / 2) / (θ * (w + z)) < -D := by
let N := D * w - (b + θ / 2) * B + D * θ * z / 2
have hB : 0 < B := by
have : 0 < b * B := by nlinarith [mul_nonneg hD.le hw, mul_pos (mul_pos hθ hz) hD]
exact (mul_pos_iff.mp this).resolve_right (by rintro ⟨h, _⟩; linarith) |>.2
have hN : N < 0 := by
dsimp [N]
nlinarith [mul_pos hθ hB, mul_pos (mul_pos hD hθ) hz]
have h1 : 2 * b * N < -(D * θ * w + D * θ * b * z) := by
have hh : 0 < (2 * b + θ) * (b * B - D * w - θ * z * D) :=
mul_pos (by linarith) (by linarith)
dsimp [N]
nlinarith [mul_pos (mul_pos (mul_pos hD hθ) hθ) hz]
have h2 : -(D * θ * w + D * θ * b * z) ≤ -(D * θ * (w + z)) := by
have hh := mul_le_mul_of_nonneg_left hb (mul_nonneg (mul_nonneg hD.le hθ.le) hz.le)
nlinarith
have h3 : 8 * M * N ≤ 2 * b * N := by
have hh := mul_le_mul_of_nonpos_right (show b ≤ M by linarith) hN.le
nlinarith [mul_neg_of_pos_of_neg (show 0 < M by linarith) hN]
apply (div_lt_iff₀ (mul_pos hθ (by linarith : 0 < w + z))).mpr
dsimp [N] at h1 h3
nlinarith [h3.trans_lt (h1.trans_le h2)]
/-- Every minimizing update has the source's upper side feasibility. -/
lemma minimizer_upper {M b D Cw : ℝ} {θ z B w₀ w : ι → ℝ}
(hb : 1 ≤ b) (hθ : ∀ i, 0 < θ i) (hz : ∀ i, 0 < z i)
(hB : ∀ i, 0 ≤ B i) (hD : 0 ≤ D) (hM : ∀ i, b + θ i ≤ M)
(hw : w ∈ domain Cw)
(hm : IsMinOn (objective (8 * M) b θ z B D w₀) (domain Cw) w) :
∀ i, D * w i ≤ (b + θ i) * B i := by
classical
intro i
by_cases hD0 : D = 0
· rw [hD0, zero_mul]
exact mul_nonneg (by linarith [hθ i]) (hB i)
have hDp : 0 < D := lt_of_le_of_ne hD (Ne.symm hD0)
by_contra h
have hv := lt_of_not_ge h
have hwi : 0 < w i := by
nlinarith [mul_nonneg (show 0 ≤ b + θ i by linarith [hθ i]) (hB i)]
have hc : ∀ y ∈ Set.Icc 0 (w i),
primitive (8 * M) b (θ i) (z i) (B i) D (w i) ≤
primitive (8 * M) b (θ i) (z i) (B i) D y + D * (w i - y) := by
intro y hy
have hh := coordinate_min_comparison hD hm i
(replace_mem_domain hw i hy.1 (by linarith [hw.2, hy.2]))
rw [abs_of_nonpos (sub_nonpos.mpr hy.2)] at hh
linarith
have hder := derivative_le_of_left_comparison hwi
(primitive_derivative (c := 8 * M) (b := b) (B := B i) (D := D)
(hθ i) (hz i) (hw.1 i)) hc
have hvder := derivative_upper_violation hb (hθ i) (hz i) (hB i) hDp
(hw.1 i) (hM i) hv
linarith
/-- The lower bound uses the slack proved from the upper bound, not a new
assumption that the simplex constraint is inactive. -/
lemma minimizer_lower {M b D Cw : ℝ} {θ z B w₀ w : ι → ℝ}
(hb : 1 ≤ b) (hθ : ∀ i, 0 < θ i) (hz : ∀ i, 0 < z i)
(hB : ∀ i, 0 ≤ B i) (hD : 0 ≤ D) (hM : ∀ i, b + θ i ≤ M)
(hCw : 2 * M < Cw) (hS : ∑ i, B i ≤ 2 * D)
(hw : w ∈ domain Cw)
(hm : IsMinOn (objective (8 * M) b θ z B D w₀) (domain Cw) w) :
∀ i, b * B i - θ i * z i * D ≤ D * w i := by
classical
intro i
by_cases hD0 : D = 0
· have hBi : B i = 0 := by
have hh := Finset.single_le_sum (fun j _ => hB j) (Finset.mem_univ i)
rw [hD0, mul_zero] at hS
linarith [hB i]
simp [hD0, hBi]
have hDp : 0 < D := lt_of_le_of_ne hD (Ne.symm hD0)
have hupper := minimizer_upper hb hθ hz hB hD hM hw hm
have hs : ∑ j, w j ≤ 2 * M := by
have hs₁ : D * ∑ j, w j ≤ M * ∑ j, B j := by
simp only [Finset.mul_sum]
exact Finset.sum_le_sum fun j _ => (hupper j).trans
(mul_le_mul_of_nonneg_right (hM j) (hB j))
have hMp : 0 ≤ M := by linarith [hM i, hθ i]
have hh := mul_le_mul_of_nonneg_left hS hMp
nlinarith
have hgap : 0 < Cw - ∑ j, w j := by linarith
have hc : ∀ y ∈ Set.Icc (w i) (w i + (Cw - ∑ j, w j)),
primitive (8 * M) b (θ i) (z i) (B i) D (w i) ≤
primitive (8 * M) b (θ i) (z i) (B i) D y + D * (y - w i) := by
intro y hy
have hh := coordinate_min_comparison hD hm i
(replace_mem_domain hw i ((hw.1 i).trans hy.1) hy.2)
rwa [abs_of_nonneg (sub_nonneg.mpr hy.1)] at hh
have hder := neg_derivative_le_of_right_comparison hgap
(primitive_derivative (c := 8 * M) (b := b) (B := B i) (D := D)
(hθ i) (hz i) (hw.1 i)) hc
by_contra h
have hvder := derivative_lower_violation hb (hθ i) (hz i) hDp
(hw.1 i) (hM i) (lt_of_not_ge h)
linarith
/-- Section 04, Lemma side-tracker, with the explicit sufficient multiplier
C'_w = 8M. No rank assumption or positivity assumption on D is added. -/
theorem side_update {M b D Cw : ℝ} {θ z B w₀ : ι → ℝ}
(hb : 1 ≤ b) (hθ : ∀ i, 0 < θ i) (hz : ∀ i, 0 < z i)
(hB : ∀ i, 0 ≤ B i) (hD : 0 ≤ D) (hM : ∀ i, b + θ i ≤ M)
(hCw : 2 * M < Cw) (hw₀ : w₀ ∈ domain Cw) :
∃ w ∈ domain Cw,
IsMinOn (objective (8 * M) b θ z B D w₀) (domain Cw) w ∧
(∀ i, D * w i ≤ (b + θ i) * B i) ∧
((∑ i, B i) ≤ 2 * D → ∀ i, b * B i - θ i * z i * D ≤ D * w i) ∧
D * movement w w₀ ≤ potential (8 * M) b θ z B D w₀ -
potential (8 * M) b θ z B D w := by
obtain ⟨w, hw, hm⟩ := exists_minimizer (c := 8 * M) (b := b) (B := B)
(D := D) hθ hz hw₀
exact ⟨w, hw, hm, minimizer_upper hb hθ hz hB hD hM hw hm,
fun hS => minimizer_lower hb hθ hz hB hD hM hCw hS hw hm,
minimizer_payment hw₀ hm⟩
/-- The logarithmic formula is exactly the source's interval integral. -/
lemma primitive_eq_integral {c b θ z B D w : ℝ} (hθ : 0 < θ) (hz : 0 < z)
(hw : 0 ≤ w) :
primitive c b θ z B D w =
c * ∫ s in (0 : ℝ)..w,
(D * s - (b + θ / 2) * B + D * θ * z / 2) / (θ * (s + z)) := by
have hc : ContinuousOn (fun s : ℝ =>
(D * s - (b + θ / 2) * B + D * θ * z / 2) / (θ * (s + z))) (Set.Icc 0 w) := by
apply ContinuousOn.div
· fun_prop
· fun_prop
· intro s hs
exact mul_ne_zero hθ.ne' (ne_of_gt (by linarith [hs.1]))
have hd : ∀ s ∈ uIcc (0 : ℝ) w,
HasDerivAt (primitive 1 b θ z B D)
((D * s - (b + θ / 2) * B + D * θ * z / 2) / (θ * (s + z))) s := by
intro s hs
rw [uIcc_of_le hw] at hs
simpa only [one_mul] using primitive_derivative (c := (1 : ℝ))
(b := b) (B := B) (D := D) hθ hz hs.1
have h := intervalIntegral.integral_eq_sub_of_hasDerivAt hd
((hc.mono (by rw [uIcc_of_le hw])).intervalIntegrable)
simp [primitive] at h
rw [h]
rfl
/-- Affinity in (B,D), used before every update decision in the all-step
filtering telescope. In particular the held-D part is constant. -/
lemma primitive_affine_inputs (c b θ z B₁ B₂ D₁ D₂ t w : ℝ) :
primitive c b θ z ((1 - t) * B₁ + t * B₂) ((1 - t) * D₁ + t * D₂) w =
(1 - t) * primitive c b θ z B₁ D₁ w + t * primitive c b θ z B₂ D₂ w := by
unfold primitive
ring
end KServer.SideTracker
namespace KServer.SideTracker
open scoped BigOperators
lemma log_factors {z w : ℝ} (hz : 0 < z) (hw : 0 ≤ w) :
0 ≤ Real.log (1 + w / z) ∧
0 ≤ z * Real.log (1 + w / z) ∧
z * Real.log (1 + w / z) ≤ w := by
have hq : 0 ≤ w / z := div_nonneg hw hz.le
have hl : 0 ≤ Real.log (1 + w / z) := Real.log_nonneg (by linarith)
refine ⟨hl, mul_nonneg hz.le hl, ?_⟩
have hh := Real.log_le_sub_one_of_pos (show 0 < 1 + w / z by positivity)
have hh' : Real.log (1 + w / z) ≤ w / z := by linarith
have := mul_le_mul_of_nonneg_left hh' hz.le
simpa [mul_div_cancel₀ _ hz.ne'] using this
lemma side_log_bound {h W w : ℝ} (hh : 1 ≤ h) (hW : 0 ≤ W)
(hw : w ∈ Set.Icc 0 W) :
Real.log (1 + w / (Real.exp (1 - h) / h)) ≤
(Real.log (1 + W) + 2) * h := by
have hp : 0 < h := lt_of_lt_of_le zero_lt_one hh
have hw0 : 0 ≤ w := hw.1
have he : 1 ≤ Real.exp (h - 1) := Real.one_le_exp (by linarith)
have hh' : h ≤ Real.exp (h - 1) := by
have := Real.add_one_le_exp (h - 1)
linarith
have hE := Real.exp_pos (h - 1)
have heq : 1 + w / (Real.exp (1 - h) / h) =
1 + w * h * Real.exp (h - 1) := by
have hn : 1 - h = -(h - 1) := by ring
rw [hn, Real.exp_neg]
field_simp
rw [heq]
have hmul : w * h * Real.exp (h - 1) ≤ W * Real.exp (h - 1) ^ 2 := by
nlinarith [mul_le_mul_of_nonneg_right hw.2 hp.le,
mul_le_mul_of_nonneg_left hh' hW,
mul_le_mul_of_nonneg_right
(mul_le_mul hw.2 hh' hp.le hW) hE.le]
have hs : 1 ≤ Real.exp (h - 1) ^ 2 := by nlinarith
have hbound : 1 + w * h * Real.exp (h - 1) ≤
(1 + W) * Real.exp (2 * (h - 1)) := by
rw [show 2 * (h - 1) = (h - 1) + (h - 1) by ring, Real.exp_add]
nlinarith
have hlog := Real.log_le_log (show 0 < 1 + w * h * Real.exp (h - 1) by positivity) hbound
rw [Real.log_mul (by positivity) (Real.exp_ne_zero _), Real.log_exp] at hlog
have hLW : 0 ≤ Real.log (1 + W) := Real.log_nonneg (by linarith)
nlinarith
/-- Coefficients of the actual primitive; all are nonnegative on the side
domain. Their estimates use size-derived logarithmic cancellation. -/
def Dcoef (c θ z w : ℝ) : ℝ :=
c * ((w - z * Real.log (1 + w / z)) / θ + z * Real.log (1 + w / z) / 2)
def Bcoef (c b θ z w : ℝ) : ℝ :=
c * (b + θ / 2) * Real.log (1 + w / z) / θ
lemma primitive_coefficients (c b θ z B D w : ℝ) :
primitive c b θ z B D w = Dcoef c θ z w * D - Bcoef c b θ z w * B := by
unfold primitive Dcoef Bcoef
ring
lemma coefficients_nonneg {c b θ z w : ℝ} (hc : 0 ≤ c) (hb : 0 ≤ b)
(hθ : 0 < θ) (hz : 0 < z) (hw : 0 ≤ w) :
0 ≤ Dcoef c θ z w ∧ 0 ≤ Bcoef c b θ z w := by
obtain ⟨hL, hzL, hLw⟩ := log_factors hz hw
constructor
· exact mul_nonneg hc (add_nonneg (div_nonneg (sub_nonneg.mpr hLw) hθ.le)
(by positivity))
· exact div_nonneg (mul_nonneg (mul_nonneg hc (by positivity)) hL) hθ.le
lemma Dcoef_bound {c θ z w cw ell h : ℝ} (hc : 0 ≤ c)
(hz : 0 < z) (hw : 0 ≤ w) (hcw : 0 < cw) (hell : 1 ≤ ell)
(hh : 1 ≤ h) (hθ : θ = cw * h / ell) :
Dcoef c θ z w ≤ c * (1 / cw + 1) * ell * w := by
have hellp : 0 < ell := lt_of_lt_of_le zero_lt_one hell
have hp : 0 < h := lt_of_lt_of_le zero_lt_one hh
have hθp : 0 < θ := by rw [hθ]; positivity
obtain ⟨hL, hzL, hLw⟩ := log_factors hz hw
have hi : 1 / θ ≤ ell / cw := by
rw [div_le_div_iff₀ hθp hcw]
rw [hθ]
have he : ell * (cw * h / ell) = cw * h := by field_simp
rw [he]
nlinarith
have ht : (w - z * Real.log (1 + w / z)) / θ ≤ w * (ell / cw) := by
calc
_ ≤ w / θ := div_le_div_of_nonneg_right (by linarith) hθp.le
_ = w * (1 / θ) := by ring
_ ≤ w * (ell / cw) := mul_le_mul_of_nonneg_left hi hw
have hq : z * Real.log (1 + w / z) / 2 ≤ ell * w := by nlinarith
unfold Dcoef
calc
_ ≤ c * (w * (ell / cw) + ell * w) :=
mul_le_mul_of_nonneg_left (add_le_add ht hq) hc
_ = c * (1 / cw + 1) * ell * w := by ring
lemma Bcoef_bound {c b θ z w cw ell h K M : ℝ} (hc : 0 ≤ c)
(hb : 0 ≤ b) (hz : 0 < z) (hw : 0 ≤ w) (hcw : 0 < cw)
(hell : 0 < ell) (hh : 0 < h) (hθ : θ = cw * h / ell)
(hBM : b + θ / 2 ≤ M)
(hLK : Real.log (1 + w / z) ≤ K * h) :
Bcoef c b θ z w ≤ c * M * K / cw * ell := by
have hθp : 0 < θ := by rw [hθ]; positivity
obtain ⟨hL, _, _⟩ := log_factors hz hw
have hM : 0 ≤ M := (by positivity : 0 ≤ b + θ / 2).trans hBM
unfold Bcoef
calc
_ ≤ c * M * (K * h) / θ := div_le_div_of_nonneg_right
(mul_le_mul (mul_le_mul_of_nonneg_left hBM hc) hLK hL (mul_nonneg hc hM)) hθp.le
_ = c * M * K / cw * ell := by rw [hθ]; field_simp
lemma primitive_component_bound {c b θ z w cw ell h K M B D : ℝ}
(hc : 0 ≤ c) (hb : 0 ≤ b) (hz : 0 < z) (hw : 0 ≤ w)
(hcw : 0 < cw) (hell : 1 ≤ ell) (hh : 1 ≤ h)
(hθ : θ = cw * h / ell) (hBM : b + θ / 2 ≤ M)
(hLK : Real.log (1 + w / z) ≤ K * h) (hB : 0 ≤ B) (hD : 0 ≤ D) :
|primitive c b θ z B D w| ≤
c * (1 / cw + 1) * ell * (D * w) + c * M * K / cw * ell * B := by
have he : 0 < ell := lt_of_lt_of_le zero_lt_one hell
have hp : 0 < h := lt_of_lt_of_le zero_lt_one hh
have hθp : 0 < θ := by rw [hθ]; positivity
have hn := coefficients_nonneg hc hb hθp hz hw
rw [primitive_coefficients]
calc
_ ≤ |Dcoef c θ z w * D| + |Bcoef c b θ z w * B| := abs_sub _ _
_ = Dcoef c θ z w * D + Bcoef c b θ z w * B := by
rw [abs_of_nonneg (mul_nonneg hn.1 hD), abs_of_nonneg (mul_nonneg hn.2 hB)]
_ ≤ (c * (1 / cw + 1) * ell * w) * D + (c * M * K / cw * ell) * B :=
add_le_add (mul_le_mul_of_nonneg_right (Dcoef_bound hc hz hw hcw hell hh hθ) hD)
(mul_le_mul_of_nonneg_right (Bcoef_bound hc hb hz hw hcw he hp hθ hBM hLK) hB)
_ = _ := by ring
lemma side_z_identity {a A : ℝ} (ha : 0 < a) (hA : 0 < A) :
a / (A * (1 + Real.log (A / a))) =
Real.exp (1 - (1 + Real.log (A / a))) / (1 + Real.log (A / a)) := by
rw [show 1 - (1 + Real.log (A / a)) = -Real.log (A / a) by ring,
Real.exp_neg, Real.exp_log (div_pos hA ha)]
field_simp
lemma potential_input_bound {ι : Type*} [Fintype ι]
{c b cw ell K M Cw : ℝ} {θ z h w : ι → ℝ}
(hc : 0 ≤ c) (hb : 0 ≤ b) (hcw : 0 < cw) (hell : 1 ≤ ell)
(hz : ∀ i, 0 < z i) (hh : ∀ i, 1 ≤ h i)
(hθ : ∀ i, θ i = cw * h i / ell)
(hBM : ∀ i, b + θ i / 2 ≤ M)
(hLK : ∀ i, Real.log (1 + w i / z i) ≤ K * h i)
(hw : w ∈ domain Cw) (B B' : ι → ℝ) (D D' : ℝ) :
|potential c b θ z B D w - potential c b θ z B' D' w| ≤
c * (1 / cw + 1) * ell * Cw * |D - D'| +
c * M * K / cw * ell * (∑ i, |B i - B' i|) := by
have he : 0 < ell := lt_of_lt_of_le zero_lt_one hell
have hdc (i) := Dcoef_bound hc (hz i) (hw.1 i) hcw hell (hh i) (hθ i)
have hbc (i) := Bcoef_bound hc hb (hz i) (hw.1 i) hcw he
(lt_of_lt_of_le zero_lt_one (hh i)) (hθ i) (hBM i) (hLK i)
have hnn (i) : 0 ≤ Dcoef c (θ i) (z i) (w i) ∧
0 ≤ Bcoef c b (θ i) (z i) (w i) :=
coefficients_nonneg hc hb (by rw [hθ i]; exact div_pos (mul_pos hcw (lt_of_lt_of_le zero_lt_one (hh i))) he) (hz i) (hw.1 i)
have hdiff (i) : primitive c b (θ i) (z i) (B i) D (w i) -
primitive c b (θ i) (z i) (B' i) D' (w i) =
Dcoef c (θ i) (z i) (w i) * (D - D') -
Bcoef c b (θ i) (z i) (w i) * (B i - B' i) := by
rw [primitive_coefficients, primitive_coefficients]
ring
have hpoint (i) : |primitive c b (θ i) (z i) (B i) D (w i) -
primitive c b (θ i) (z i) (B' i) D' (w i)| ≤
c * (1 / cw + 1) * ell * w i * |D - D'| +
c * M * K / cw * ell * |B i - B' i| := by
rw [hdiff]
calc
_ ≤ |Dcoef c (θ i) (z i) (w i) * (D - D')| +
|Bcoef c b (θ i) (z i) (w i) * (B i - B' i)| := abs_sub _ _
_ = Dcoef c (θ i) (z i) (w i) * |D - D'| +
Bcoef c b (θ i) (z i) (w i) * |B i - B' i| := by
rw [abs_mul, abs_mul, abs_of_nonneg (hnn i).1, abs_of_nonneg (hnn i).2]
_ ≤ _ := add_le_add (mul_le_mul_of_nonneg_right (hdc i) (abs_nonneg _))
(mul_le_mul_of_nonneg_right (hbc i) (abs_nonneg _))
unfold potential
rw [← Finset.sum_sub_distrib]
calc
_ ≤ ∑ i, |primitive c b (θ i) (z i) (B i) D (w i) -
primitive c b (θ i) (z i) (B' i) D' (w i)| := Finset.abs_sum_le_sum_abs _ _
_ ≤ ∑ i, (c * (1 / cw + 1) * ell * w i * |D - D'| +
c * M * K / cw * ell * |B i - B' i|) := Finset.sum_le_sum fun i _ => hpoint i
_ = c * (1 / cw + 1) * ell * (∑ i, w i) * |D - D'| +
c * M * K / cw * ell * (∑ i, |B i - B' i|) := by
simp only [Finset.sum_add_distrib, ← Finset.sum_mul, ← Finset.mul_sum]
_ ≤ _ := add_le_add (mul_le_mul_of_nonneg_right
(mul_le_mul_of_nonneg_left hw.2 (by positivity)) (abs_nonneg _)) le_rfl
end KServer.SideTracker
namespace KServer.SideSupported
open Finset
variable {J : Type*} [Fintype J] [DecidableEq J]
def restrict (A : Finset J) (a : J → ℝ) : A → ℝ := fun i => a i
def extend (A : Finset J) (a : A → ℝ) : J → ℝ := fun i => if hi : i∈A then a ⟨i,hi⟩ else 0
omit [Fintype J] in
lemma extend_apply_mem (A : Finset J) (a : A → ℝ) (i : A) : extend A a i=a i := by
simp [extend,i.property]
omit [Fintype J] in
lemma extend_apply_not_mem (A : Finset J) (a : A → ℝ) {i : J} (hi : i∉A) : extend A a i=0 := by
simp [extend,hi]
omit [Fintype J] in
lemma restrict_extend (A : Finset J) (a : A → ℝ) : restrict A (extend A a)=a := by
funext i; exact extend_apply_mem A a i
omit [Fintype J] in
lemma extend_restrict (A : Finset J) (a : J → ℝ) (ha : ∀ i∉A, a i=0) :
extend A (restrict A a)=a := by
funext i
by_cases hi : i∈A
· simp [extend,restrict,hi]
· simp [extend,hi,ha i hi]
omit [DecidableEq J] in
lemma sum_restrict (A : Finset J) (a : J → ℝ) (ha : ∀ i∉A, a i=0) :
(∑ i : A, a i)=∑ i, a i := by
rw [←Finset.sum_subtype A (fun _ => Iff.rfl)]
exact Finset.sum_subset (subset_univ A) fun i _ hi => ha i hi
lemma sum_extend (A : Finset J) (a : A → ℝ) : (∑ i, extend A a i)=∑ i, a i := by
have he := sum_restrict A (extend A a) (fun i hi => extend_apply_not_mem A a hi)
simpa only [extend_apply_mem] using he.symm
end KServer.SideSupported
namespace KServer.SideSupported
open Finset SideTracker
variable {J : Type*} [Fintype J] [DecidableEq J]
omit [DecidableEq J] in
lemma restrict_mem {A : Finset J} {W : ℝ} {a : J → ℝ}
(ha : a∈ChangingDomains.sideDomain A W) : restrict A a∈domain W := by
refine ⟨fun i => ha.1 i, ?_⟩
simpa only [restrict,sum_restrict A a ha.2.2] using ha.2.1
lemma extend_mem {A : Finset J} {W : ℝ} {a : A → ℝ}
(ha : a∈domain W) : extend A a∈ChangingDomains.sideDomain A W := by
refine ⟨?_,?_,?_⟩
· intro i
simp only [extend]
split_ifs with hi
· exact ha.1 ⟨i,hi⟩
· exact le_rfl
· simpa only [sum_extend] using ha.2
· exact fun i hi => extend_apply_not_mem A a hi
omit [DecidableEq J] in
lemma sideDomain_compact (A : Finset J) (W : ℝ) :
IsCompact (ChangingDomains.sideDomain A W) := by
have he : ChangingDomains.sideDomain A W=
(domain W)∩{a : J → ℝ | ∀ i∉A, a i=0} := by
ext a
simp only [ChangingDomains.sideDomain,domain,Set.mem_ofPred_eq,Set.mem_inter_iff]
tauto
rw [he]
apply IsCompact.inter_right (domain_isCompact W)
simp only [ofPred_forall]
exact isClosed_iInter fun i => isClosed_iInter fun _ => isClosed_eq (continuous_apply i) continuous_const
omit [DecidableEq J] in
lemma movement_restrict {A : Finset J} {a b : J → ℝ}
(ha : ∀ i∉A, a i=0) (hb : ∀ i∉A, b i=0) :
movement (restrict A a) (restrict A b)=ChangingDomains.variation a b := by
exact sum_restrict A (fun i => |a i-b i|) (fun i hi => by simp [ha i hi,hb i hi])
omit [DecidableEq J] in
lemma potential_restrict {A : Finset J} {c b D : ℝ} {θ z B a : J → ℝ}
(ha : ∀ i∉A, a i=0) :
potential c b (restrict A θ) (restrict A z) (restrict A B) D (restrict A a)=
potential c b θ z B D a := by
unfold potential restrict
exact sum_restrict A (fun i => primitive c b (θ i) (z i) (B i) D (a i))
(fun i hi => by simp [ha i hi,primitive])
lemma restrict_isMin {A : Finset J} {c b D W : ℝ} {θ z B a a₀ : J → ℝ}
(ha : a∈ChangingDomains.sideDomain A W) (ha₀ : a₀∈ChangingDomains.sideDomain A W)
(hm : IsMinOn (fun v => potential c b θ z B D v+D*ChangingDomains.variation v a₀)
(ChangingDomains.sideDomain A W) a) :
IsMinOn (objective c b (restrict A θ) (restrict A z) (restrict A B) D (restrict A a₀))
(domain W) (restrict A a) := by
intro v hv
have he := extend_mem hv
have hh := hm he
change potential c b (restrict A θ) (restrict A z) (restrict A B) D (restrict A a)+
D*movement (restrict A a) (restrict A a₀) ≤
potential c b (restrict A θ) (restrict A z) (restrict A B) D v+
D*movement v (restrict A a₀)
rw [potential_restrict ha.2.2,movement_restrict ha.2.2 ha₀.2.2]
have hp := potential_restrict (c := c) (b := b) (D := D) (θ := θ) (z := z) (B := B) he.2.2
have hmove := movement_restrict he.2.2 ha₀.2.2
rw [restrict_extend] at hp hmove
rw [hp,hmove]
exact hh
lemma supported_feasible {A : Finset J} {M b D W : ℝ} {θ z B a a₀ : J → ℝ}
(ha : a∈ChangingDomains.sideDomain A W) (ha₀ : a₀∈ChangingDomains.sideDomain A W)
(hb : 1≤b) (hθ : ∀ i, 0<θ i) (hz : ∀ i, 0<z i)
(hB : ∀ i, 0≤B i) (hBz : ∀ i∉A, B i=0) (hD : 0≤D)
(hM : ∀ i∈A, b+θ i≤M) (hW : 2*M<W)
(hm : IsMinOn (fun v => potential (8*M) b θ z B D v+D*ChangingDomains.variation v a₀)
(ChangingDomains.sideDomain A W) a) :
(∀ i, D*a i≤(b+θ i)*B i) ∧
((∑ i, B i)≤2*D → ∀ i, b*B i-θ i*z i*D≤D*a i) := by
have hm' := restrict_isMin ha ha₀ hm
have hupper := minimizer_upper hb (fun i : A => hθ i) (fun i : A => hz i)
(fun i : A => hB i) hD (fun i : A => hM i i.property) (restrict_mem ha) hm'
constructor
· intro i
by_cases hi : i∈A
· exact hupper ⟨i,hi⟩
· simp [ha.2.2 i hi,hBz i hi]
· intro hS
have hS' : (∑ i : A, B i)≤2*D := by simpa only [sum_restrict A B hBz] using hS
have hlower := minimizer_lower hb (fun i : A => hθ i) (fun i : A => hz i)
(fun i : A => hB i) hD (fun i : A => hM i i.property) hW hS' (restrict_mem ha) hm'
intro i
by_cases hi : i∈A
· exact hlower ⟨i,hi⟩
· simp only [ha.2.2 i hi,hBz i hi,mul_zero,zero_sub]
exact neg_nonpos.mpr (mul_nonneg (mul_nonneg (hθ i).le (hz i).le) hD)
end KServer.SideSupported
namespace KServer.SideFamilies
open Finset SideTracker AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
structure Data (J R : Type*) where
active : Finset J
flags : J → R → Bool
W : ℝ
b : ℝ
D : ℝ
θ : J → ℝ
z : J → ℝ
W_nonneg : 0≤W
θ_pos : ∀ i, 0<θ i
z_pos : ∀ i, 0<z i
def core (d : Data J R) (p : J × R → ℝ) (i : J) : ℝ :=
∑ r, if d.flags i r then p (i,r) else 0
def coefficient (c : ℝ) (d : Data J R) (a : J → ℝ) (ir : J × R) : ℝ :=
if d.flags ir.1 ir.2 then -Bcoef c d.b (d.θ ir.1) (d.z ir.1) (a ir.1) else 0
def offset (c : ℝ) (d : Data J R) (a : J → ℝ) : ℝ :=
d.D * ∑ i, Dcoef c (d.θ i) (d.z i) (a i)
lemma Dcoef_continuousOn {c θ z : ℝ} (hθ : 0<θ) (hz : 0<z) :
ContinuousOn (Dcoef c θ z) (Set.Ici 0) := by
have he : Dcoef c θ z=primitive c 0 θ z 0 1 := by
funext w
unfold Dcoef primitive
ring
rw [he]
exact primitive_continuousOn hθ hz
lemma Bcoef_continuousOn {c b θ z : ℝ} (hθ : 0<θ) (hz : 0<z) :
ContinuousOn (Bcoef c b θ z) (Set.Ici 0) := by
have he : Bcoef c b θ z=fun w => -primitive c b θ z 1 0 w := by
funext w
unfold Bcoef primitive
ring
rw [he]
exact (primitive_continuousOn hθ hz).neg
omit [DecidableEq J] [Fintype R] in
lemma coefficient_continuous (c : ℝ) (d : Data J R) (ir : J × R) :
ContinuousOn (fun a => coefficient c d a ir) (ChangingDomains.sideDomain d.active d.W) := by
unfold coefficient
split_ifs
· exact ((Bcoef_continuousOn (d.θ_pos ir.1) (d.z_pos ir.1)).comp
(continuous_apply ir.1).continuousOn (fun a ha => ha.1 ir.1)).neg
· exact continuousOn_const
omit [DecidableEq J] [Fintype R] in
lemma offset_continuous (c : ℝ) (d : Data J R) :
ContinuousOn (offset c d) (ChangingDomains.sideDomain d.active d.W) := by
unfold offset
apply ContinuousOn.const_mul
exact continuousOn_finsetSum _ fun i _ =>
(Dcoef_continuousOn (d.θ_pos i) (d.z_pos i)).comp
(continuous_apply i).continuousOn (fun a ha => ha.1 i)
def family (c : ℝ) : Family (Data J R) (J × R) J where
domain d := ChangingDomains.sideDomain d.active d.W
compact d := SideSupported.sideDomain_compact d.active d.W
seed d := ⟨fun _ => 0,by
refine ⟨fun _ => le_rfl,?_,fun _ _ => rfl⟩
simpa using d.W_nonneg⟩
offset := offset c
coefficient := coefficient c
offset_continuous := offset_continuous c
coefficient_continuous := coefficient_continuous c
omit [DecidableEq J] in
lemma value_eq (c : ℝ) (d : Data J R) (p : J × R → ℝ) (a : J → ℝ) :
(family c).value d p a=potential c d.b d.θ d.z (core d p) d.D a := by
simp only [Family.value,family,offset,coefficient,potential]
rw [Fintype.sum_prod_type]
have hi (i : J) : (∑ r, (if d.flags i r then -Bcoef c d.b (d.θ i) (d.z i) (a i) else 0)*p (i,r))=
-Bcoef c d.b (d.θ i) (d.z i) (a i)*core d p i := by
rw [core,mul_sum]
exact sum_congr rfl fun r _ => by split_ifs <;> simp_all
simp_rw [hi,primitive_coefficients]
rw [mul_sum,←sum_add_distrib]
exact sum_congr rfl fun i _ => by ring
lemma update_feasible (d : Data J R) {M : ℝ} (hb : 1≤d.b) (hD : 0≤d.D)
(hM : ∀ i∈d.active, d.b+d.θ i≤M) (hW : 2*M<d.W)
(p : J × R → ℝ) (hp : ∀ ir, 0≤p ir)
(hf : ∀ i∉d.active, ∀ r, d.flags i r=false)
(a : J → ℝ) (ha : a∈ChangingDomains.sideDomain d.active d.W) :
let a' := (family (8*M)).update d p d.D a
(∀ i, d.D*a' i≤(d.b+d.θ i)*core d p i) ∧
((∑ i, core d p i)≤2*d.D → ∀ i,
d.b*core d p i-d.θ i*d.z i*d.D≤d.D*a' i) := by
intro a'
have hB : ∀ i, 0≤core d p i := by
intro i
unfold core
apply sum_nonneg
intro r _
split_ifs
· exact hp (i,r)
· exact le_rfl
have hBz : ∀ i∉d.active, core d p i=0 := by
intro i hi
simp [core,hf i hi]
apply SideSupported.supported_feasible ((family (8*M)).update_mem _ _ _ _) ha hb
d.θ_pos d.z_pos hB hBz hD hM hW
intro v hv
have hm := ((family (8*M)).exists_update d p d.D a).choose_spec.2 hv
change (family (8*M)).value d p a'+d.D*AdaptiveMinimization.movement a' a ≤
(family (8*M)).value d p v+d.D*AdaptiveMinimization.movement v a at hm
simpa only [value_eq,AdaptiveMinimization.movement,ChangingDomains.variation, a', Set.mem_ofPred_eq] using hm
omit [DecidableEq J] in
lemma update_payment (c : ℝ) (d : Data J R) (p : J × R → ℝ) (a : J → ℝ)
(ha : a∈ChangingDomains.sideDomain d.active d.W) :
let a' := (family c).update d p d.D a
d.D*ChangingDomains.variation a' a≤
potential c d.b d.θ d.z (core d p) d.D a-
potential c d.b d.θ d.z (core d p) d.D a' := by
have hp := (family c).update_payment d p d.D ha
simpa only [value_eq,AdaptiveMinimization.movement,ChangingDomains.variation] using hp
end KServer.SideFamilies
namespace KServer.SideFamilies
open Finset SideTracker AdaptiveMinimization
variable {J R : Type*} [Fintype J] [DecidableEq J] [Fintype R]
omit [DecidableEq J] [Fintype R] in
lemma domain_coordinate {d : Data J R} {a : J → ℝ}
(ha : a∈ChangingDomains.sideDomain d.active d.W) (i : J) :
a i∈Set.Icc 0 d.W :=
⟨ha.1 i,(single_le_sum (fun j _ => ha.1 j) (mem_univ i)).trans ha.2.1⟩
/-- The exact side regularizers obtained from the stored log size. -/
def fromLog (A : Finset J) (f : J → R → Bool) (W b D cw ell : ℝ)
(h : J → ℝ) (hW : 0≤W) (hcw : 0<cw) (hell : 0<ell) (hh : ∀ i, 1≤h i) : Data J R where
active := A
flags := f
W := W
b := b
D := D
θ i := cw*h i/ell
z i := Real.exp (1-h i)/h i
W_nonneg := hW
θ_pos i := div_pos (mul_pos hcw (lt_of_lt_of_le zero_lt_one (hh i))) hell
z_pos i := div_pos (Real.exp_pos _) (lt_of_lt_of_le zero_lt_one (hh i))
omit [DecidableEq J] [Fintype R] in
lemma fromLog_input_bound {A : Finset J} (_flags : J → R → Bool)
{W b cw ell c M D D' : ℝ} (h : J → ℝ)
(hW : 0≤W) (hcw : 0<cw) (hell : 1≤ell) (hh : ∀ i, 1≤h i)
(hc : 0≤c) (hb : 0≤b) (hM : ∀ i, b+cw*h i/ell≤M)
{a B B' : J → ℝ} (ha : a∈ChangingDomains.sideDomain A W) :
|potential c b (fun i => cw*h i/ell) (fun i => Real.exp (1-h i)/h i) B D a-
potential c b (fun i => cw*h i/ell) (fun i => Real.exp (1-h i)/h i) B' D' a|≤
c*(1/cw+1)*ell*W*|D-D'|+
c*M*(Real.log (1+W)+2)/cw*ell*ChangingDomains.variation B B' := by
have hp : 0<ell := lt_of_lt_of_le zero_lt_one hell
apply potential_input_bound hc hb hcw hell
(fun i => div_pos (Real.exp_pos _) (lt_of_lt_of_le zero_lt_one (hh i))) hh
(fun _ => rfl)
· intro i
have ht : 0≤cw*h i/ell := div_nonneg (mul_nonneg hcw.le (le_trans zero_le_one (hh i))) hp.le
linarith [hM i]
· intro i
apply side_log_bound (hh i) hW
exact ⟨ha.1 i,(single_le_sum (fun j _ => ha.1 j) (mem_univ i)).trans ha.2.1⟩
· exact ⟨ha.1,ha.2.1⟩
omit [DecidableEq J] in
lemma parameter_jump {W b cw ell c M D : ℝ} {h h' B a : J → ℝ}
(hW : 0≤W) (hcw : 0<cw) (hell : 1≤ell)
(hh : ∀ i, 1≤h i) (hh' : ∀ i, 1≤h' i)
(hc : 0≤c) (hb : 0≤b) (hD : 0≤D) (hB : ∀ i, 0≤B i)
(hM : ∀ i, b+cw*h i/ell≤M) (hM' : ∀ i, b+cw*h' i/ell≤M)
(ha : a∈domain W) (hcap : ∀ i, D*a i≤M*B i) :
|potential c b (fun i => cw*h' i/ell) (fun i => Real.exp (1-h' i)/h' i) B D a-
potential c b (fun i => cw*h i/ell) (fun i => Real.exp (1-h i)/h i) B D a|≤
2*(c*(1/cw+1)*M+c*M*(Real.log (1+W)+2)/cw)*ell*
(∑ i, if h i=h' i then 0 else B i) := by
have hp : 0<ell := lt_of_lt_of_le zero_lt_one hell
have hw (i : J) : a i∈Set.Icc 0 W :=
⟨ha.1 i,(single_le_sum (fun j _ => ha.1 j) (mem_univ i)).trans ha.2⟩
have hbound (q : J → ℝ) (hq : ∀ i, 1≤q i) (hMq : ∀ i, b+cw*q i/ell≤M) (i : J) :
|primitive c b (cw*q i/ell) (Real.exp (1-q i)/q i) (B i) D (a i)|≤
(c*(1/cw+1)*M+c*M*(Real.log (1+W)+2)/cw)*ell*B i := by
have ht : 0≤cw*q i/ell := div_nonneg (mul_nonneg hcw.le (le_trans zero_le_one (hq i))) hp.le
have he := primitive_component_bound hc hb
(div_pos (Real.exp_pos _) (lt_of_lt_of_le zero_lt_one (hq i))) (ha.1 i)
hcw hell (hq i) rfl (show b+(cw*q i/ell)/2≤M by linarith [hMq i])
(side_log_bound (hq i) hW (hw i)) (hB i) hD
have hcap' := mul_le_mul_of_nonneg_left (hcap i)
(show 0≤c*(1/cw+1)*ell by positivity)
calc
_ ≤ c*(1/cw+1)*ell*(D*a i)+
c*M*(Real.log (1+W)+2)/cw*ell*B i := he
_ ≤ c*(1/cw+1)*ell*(M*B i)+
c*M*(Real.log (1+W)+2)/cw*ell*B i := add_le_add hcap' le_rfl
_ = _ := by ring
unfold potential
rw [←sum_sub_distrib,mul_sum]
apply (abs_sum_le_sum_abs _ _).trans
apply sum_le_sum
intro i _
by_cases hi : h i=h' i
· simp [hi]
· rw [ite_eq_right hi]
have ho := hbound h hh hM i
have hn := hbound h' hh' hM' i
exact (abs_sub _ _).trans (by linarith)
/-- Synthetic ranks use the new flags on the intersection of active sets. -/
def prepareData (old new : Data J R) : Data J R :=
{old with flags := ChangingDomains.syntheticFlags old.active new.active new.flags, D := new.D}
def prepare (c : ℝ) (old new : Data J R) (p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
(family c).update (prepareData old new) p new.D a
def transport (c : ℝ) (old new : Data J R) (p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
ChangingDomains.transposeSide new.active (prepare c old new p a)
def step (c : ℝ) (old new : Data J R) (p : J × R → ℝ) (a : J → ℝ) : J → ℝ :=
(family c).update new p new.D (transport c old new p a)
lemma prepare_mem (c : ℝ) (old new : Data J R) (p : J × R → ℝ) (a : J → ℝ) :
prepare c old new p a∈ChangingDomains.sideDomain old.active old.W :=
(family c).update_mem _ _ _ _
lemma transport_mem (c : ℝ) (old new : Data J R) (p : J × R → ℝ) (a : J → ℝ)
(hW : old.W=new.W) :
transport c old new p a∈ChangingDomains.sideDomain new.active new.W := by
rw [←hW]
exact ChangingDomains.transposeSide_mem (prepare_mem c old new p a)
lemma step_mem (c : ℝ) (old new : Data J R) (p : J × R → ℝ) (a : J → ℝ) :
step c old new p a∈ChangingDomains.sideDomain new.active new.W :=
(family c).update_mem _ _ _ _
omit [Fintype J] in
lemma prepared_core_zero (old new : Data J R) (p : J × R → ℝ)
{i : J} (hi : i∉old.active∩new.active) : core (prepareData old new) p i=0 := by
simp [core,prepareData,ChangingDomains.syntheticFlags,hi]
lemma transport_payment (old new : Data J R) {M : ℝ}
(hb : 1≤old.b) (hD : 0≤new.D)
(hM : ∀ i∈old.active, old.b+old.θ i≤M) (hW : 2*M<old.W)
(p : J × R → ℝ) (hp : ∀ ir, 0≤p ir)
(a : J → ℝ) (ha : a∈ChangingDomains.sideDomain old.active old.W) :
new.D*ChangingDomains.variation (transport (8*M) old new p a)
(prepare (8*M) old new p a)=0 := by
have hfeas := update_feasible (prepareData old new) hb hD hM hW p hp
(fun i hi r => by
change i∉old.active at hi
simp [prepareData,ChangingDomains.syntheticFlags,hi]) a ha
exact ChangingDomains.transposeSide_payment (prepare_mem (8*M) old new p a).1 hD
hfeas.1 (fun i hi => prepared_core_zero old new p (by simp [hi]))
lemma transport_value (c : ℝ) (old new : Data J R) (p : J × R → ℝ) (a : J → ℝ)
(hzero : new.D*ChangingDomains.variation (transport c old new p a)
(prepare c old new p a)=0) :
(family c).value (prepareData old new) p (transport c old new p a)=
(family c).value (prepareData old new) p (prepare c old new p a) := by
rw [value_eq,value_eq]
unfold potential
apply sum_congr rfl
intro i _
by_cases hi : i∈new.active
· simp [transport,ChangingDomains.transposeSide,hi]
· have hB : core (prepareData old new) p i=0 :=
prepared_core_zero old new p (by simp [hi])
by_cases hD : new.D=0
· rw [hB]
change primitive c old.b (old.θ i) (old.z i) 0 new.D _ =
primitive c old.b (old.θ i) (old.z i) 0 new.D _
simp [hD,primitive]
· have hvar : ChangingDomains.variation (transport c old new p a)
(prepare c old new p a)=0 := (mul_eq_zero.mp hzero).resolve_left hD
have hd := single_le_sum (s := univ)
(f := fun j => |transport c old new p a j-prepare c old new p a j|)
(fun j _ => abs_nonneg _) (mem_univ i)
change |transport c old new p a i-prepare c old new p a i|≤
ChangingDomains.variation (transport c old new p a) (prepare c old new p a) at hd
rw [hvar] at hd
have he := sub_eq_zero.mp (abs_nonpos_iff.mp hd)
rw [he]
/-- Local side edit payment for the actual two minimizers and deletion. The
potential discrepancy terms will be bounded with the literal log parameters. -/
lemma step_payment (old new : Data J R) {M : ℝ}
(hb : 1≤old.b) (hD : 0≤new.D)
(hM : ∀ i∈old.active, old.b+old.θ i≤M) (hW : 2*M<old.W)
(p : J × R → ℝ) (hp : ∀ ir, 0≤p ir)
(a : J → ℝ) (ha : a∈ChangingDomains.sideDomain old.active old.W)
(hWW : old.W=new.W) :
new.D*ChangingDomains.variation (step (8*M) old new p a) a ≤
(family (8*M)).value old p a-(family (8*M)).value new p (step (8*M) old new p a)+
|(family (8*M)).value (prepareData old new) p a-(family (8*M)).value old p a|+
|(family (8*M)).value new p (transport (8*M) old new p a)-
(family (8*M)).value (prepareData old new) p (transport (8*M) old new p a)| := by
have hz := transport_payment old new hb hD hM hW p hp a ha
have he := transport_value (8*M) old new p a hz
have h₁ := (family (8*M)).update_payment (prepareData old new) p new.D ha
have h₂ := (family (8*M)).update_payment new p new.D (transport_mem (8*M) old new p a hWW)
have hm₁ := ChangingDomains.variation_triangle (step (8*M) old new p a)
(transport (8*M) old new p a) a
have hm₂ := ChangingDomains.variation_triangle (transport (8*M) old new p a)
(prepare (8*M) old new p a) a
have hp₁ := mul_le_mul_of_nonneg_left hm₁ hD
have hp₂ := mul_le_mul_of_nonneg_left hm₂ hD
change new.D*ChangingDomains.variation (prepare (8*M) old new p a) a ≤
(family (8*M)).value (prepareData old new) p a-
(family (8*M)).value (prepareData old new) p (prepare (8*M) old new p a) at h₁
change new.D*ChangingDomains.variation (step (8*M) old new p a)
(transport (8*M) old new p a) ≤
(family (8*M)).value new p (transport (8*M) old new p a)-
(family (8*M)).value new p (step (8*M) old new p a) at h₂
have hab₁ := le_abs_self ((family (8*M)).value (prepareData old new) p a-(family (8*M)).value old p a)
have hab₂ := le_abs_self ((family (8*M)).value new p (transport (8*M) old new p a)-
(family (8*M)).value (prepareData old new) p (transport (8*M) old new p a))
nlinarith
end KServer.SideFamilies
end
end
end
end OAI
|