oxilean-std 0.1.2

OxiLean standard library
Documentation
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
//! Auto-generated module
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)

use super::functions::*;
use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};

/// A Weinstein manifold (W, ω, X, φ) with handle decomposition data.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct WeinsteinManifold {
    /// Real dimension of W (must be even: 2n).
    pub dimension: usize,
    /// Handle indices (the Morse indices of critical points of φ): must be ≤ n.
    pub handle_indices: Vec<usize>,
}
impl WeinsteinManifold {
    /// Create a Weinstein manifold with given dimension and handle indices.
    pub fn new(dimension: usize, handle_indices: Vec<usize>) -> Self {
        assert!(
            dimension % 2 == 0,
            "Weinstein manifolds have even dimension"
        );
        let n = dimension / 2;
        for &k in &handle_indices {
            assert!(
                k <= n,
                "Handle index {k} exceeds half-dimension {n} for Weinstein manifold"
            );
        }
        Self {
            dimension,
            handle_indices,
        }
    }
    /// Half the real dimension (the Morse index cap).
    pub fn half_dim(&self) -> usize {
        self.dimension / 2
    }
    /// The minimal symplectic capacity of the Weinstein domain is bounded below
    /// by the action of the shortest Reeb chord on the boundary.
    /// Returns true when all handle indices are ≤ n (Weinstein condition).
    pub fn satisfies_weinstein_condition(&self) -> bool {
        let n = self.half_dim();
        self.handle_indices.iter().all(|&k| k <= n)
    }
    /// Euler characteristic χ(W) = Σ (-1)^k * #{handles of index k}.
    pub fn euler_characteristic(&self) -> i64 {
        self.handle_indices
            .iter()
            .map(|&k| if k % 2 == 0 { 1i64 } else { -1i64 })
            .sum()
    }
    /// Number of isotropic handles (index < n) — these generate the isotropic skeleton.
    pub fn num_isotropic_handles(&self) -> usize {
        let n = self.half_dim();
        self.handle_indices.iter().filter(|&&k| k < n).count()
    }
    /// Number of Lagrangian handles (index = n) — these are the essential handles.
    pub fn num_lagrangian_handles(&self) -> usize {
        let n = self.half_dim();
        self.handle_indices.iter().filter(|&&k| k == n).count()
    }
}
/// Symplectic reduction M//G = μ⁻¹(λ)/G_λ (Marsden-Weinstein quotient).
pub struct SymplecticReduction {
    /// The moment map used for reduction
    pub moment_map: MomentMap,
    /// The level value λ ∈ g*
    pub level: f64,
}
impl SymplecticReduction {
    /// Create a reduction at the zero level of a standard torus moment map.
    pub fn new() -> Self {
        SymplecticReduction {
            moment_map: MomentMap::new(),
            level: 0.0,
        }
    }
    /// Dimension of the reduced space M//G.
    /// dim(M//G) = dim(M) − 2 dim(G) when λ is a regular value.
    pub fn reduced_space_dimension(&self) -> i64 {
        let m_dim = 2 * 2i64;
        let g_dim = 2i64;
        m_dim - 2 * g_dim
    }
}
/// Lagrangian submanifold data.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct LagrangianSubmanifoldData {
    pub name: String,
    pub ambient_dimension: usize,
    pub is_exact: bool,
    pub maslov_index: Option<i32>,
}
#[allow(dead_code)]
impl LagrangianSubmanifoldData {
    /// Exact Lagrangian.
    pub fn exact(name: &str, dim: usize) -> Self {
        Self {
            name: name.to_string(),
            ambient_dimension: dim,
            is_exact: true,
            maslov_index: Some(0),
        }
    }
    /// Zero section of cotangent bundle.
    pub fn zero_section(base_dim: usize) -> Self {
        Self {
            name: format!("zero_section(T*R^{})", base_dim),
            ambient_dimension: 2 * base_dim,
            is_exact: true,
            maslov_index: Some(0),
        }
    }
    /// Dimension of the Lagrangian (half of ambient).
    pub fn dimension(&self) -> usize {
        self.ambient_dimension / 2
    }
    /// Arnold conjecture bound on Floer homology.
    pub fn arnold_conjecture_description(&self) -> String {
        format!(
            "Lagrangian {} has Floer homology lower bound from Maslov index {}",
            self.name,
            self.maslov_index.map_or("?".to_string(), |m| m.to_string())
        )
    }
}
/// Contact manifold data.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct ContactManifoldData {
    pub name: String,
    pub dimension: usize,
    pub contact_form: String,
    pub is_tight: bool,
    pub is_overtwisted: bool,
}
#[allow(dead_code)]
impl ContactManifoldData {
    /// Standard contact structure on S^{2n-1}.
    pub fn standard_sphere(n: usize) -> Self {
        Self {
            name: format!("S^{}", 2 * n - 1),
            dimension: 2 * n - 1,
            contact_form: "standard alpha".to_string(),
            is_tight: true,
            is_overtwisted: false,
        }
    }
    /// Eliashberg's classification: in dim 3, tight vs overtwisted is complete.
    pub fn eliashberg_classified(&self) -> bool {
        self.dimension == 3
    }
    /// Reeb flow exists on any contact manifold.
    pub fn reeb_flow_description(&self) -> String {
        format!("Reeb flow of {} on {}", self.contact_form, self.name)
    }
}
/// A Liouville torus Tⁿ = ℝⁿ/Λ (invariant torus in an integrable system).
pub struct LiouvilleTorus {
    /// Action values (determine which torus in the foliation)
    pub actions: Vec<f64>,
    /// Frequency vector ω = ∂H/∂I
    pub frequencies: Vec<f64>,
}
impl LiouvilleTorus {
    /// Create a standard Liouville torus with unit actions and given frequencies.
    pub fn new() -> Self {
        LiouvilleTorus {
            actions: vec![1.0, 1.0],
            frequencies: vec![1.0, std::f64::consts::SQRT_2],
        }
    }
    /// Returns true when all frequency ratios are rational (periodic orbit).
    pub fn is_periodic(&self) -> bool {
        if self.frequencies.len() < 2 {
            return true;
        }
        let ratio = self.frequencies[0] / self.frequencies[1];
        is_rational_approx(ratio, 1e-9)
    }
    /// Returns true when the frequency vector is resonant (∃ k ∈ ℤⁿ \ {0}: k·ω = 0).
    pub fn is_resonant(&self) -> bool {
        self.is_periodic()
    }
    /// Winding number ω₁/ω₂ (for 2-dimensional tori).
    pub fn winding_number(&self) -> f64 {
        if self.frequencies.len() >= 2 && self.frequencies[1].abs() > 1e-15 {
            self.frequencies[0] / self.frequencies[1]
        } else {
            f64::INFINITY
        }
    }
}
/// Lagrangian submanifold: half-dimensional submanifold L ⊂ (M, ω) with ω|_L = 0.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct LagSubMid {
    pub ambient_dim: usize,
    pub submanifold_dim: usize,
    pub name: String,
    pub is_exact: bool,
    pub maslov_index: Option<i32>,
}
#[allow(dead_code)]
impl LagSubMid {
    pub fn new(n: usize, name: &str) -> Self {
        Self {
            ambient_dim: 2 * n,
            submanifold_dim: n,
            name: name.to_string(),
            is_exact: false,
            maslov_index: None,
        }
    }
    pub fn exact(mut self) -> Self {
        self.is_exact = true;
        self
    }
    pub fn with_maslov(mut self, idx: i32) -> Self {
        self.maslov_index = Some(idx);
        self
    }
    /// Weinstein's Lagrangian neighborhood theorem: L has a neighborhood ≅ T*L.
    pub fn weinstein_neighborhood(&self) -> String {
        format!("Neighborhood of {} ≅ T*{}", self.name, self.name)
    }
}
/// Arnold conjecture data: lower bound on Lagrangian intersection points.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct ArnoldConjMid {
    /// Lagrangian L and its Hamiltonian isotopy φ_H(L).
    pub lagrangian_name: String,
    /// Lower bound from Morse theory: #(L ∩ φ_H(L)) >= sum Betti numbers.
    pub betti_lower_bound: u64,
    /// Actual intersection count (if computed).
    pub actual_intersections: Option<u64>,
}
#[allow(dead_code)]
impl ArnoldConjMid {
    pub fn new(lagrangian_name: &str, betti_lower_bound: u64) -> Self {
        Self {
            lagrangian_name: lagrangian_name.to_string(),
            betti_lower_bound,
            actual_intersections: None,
        }
    }
    pub fn with_actual(mut self, count: u64) -> Self {
        self.actual_intersections = Some(count);
        self
    }
    /// Verify Arnold conjecture: actual >= betti bound.
    pub fn conjecture_holds(&self) -> Option<bool> {
        self.actual_intersections
            .map(|a| a >= self.betti_lower_bound)
    }
}
/// Hamiltonian group action and moment map.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct HamiltonianGroupAction {
    pub group_name: String,
    pub manifold_name: String,
    pub lie_algebra_dim: usize,
    pub moment_map_name: String,
}
#[allow(dead_code)]
impl HamiltonianGroupAction {
    pub fn new(group: &str, manifold: &str, lie_dim: usize) -> Self {
        Self {
            group_name: group.to_string(),
            manifold_name: manifold.to_string(),
            lie_algebra_dim: lie_dim,
            moment_map_name: format!("μ: {} -> g*", manifold),
        }
    }
    /// Marsden–Weinstein quotient: M // G = μ^{-1}(0) / G.
    pub fn marsden_weinstein_quotient(&self) -> String {
        format!(
            "{} // {} = μ^{{-1}}(0) / {}",
            self.manifold_name, self.group_name, self.group_name
        )
    }
    /// Atiyah–Bott localization theorem (conceptual).
    pub fn atiyah_bott_localization(&self) -> String {
        format!(
            "Integration over {} localizes to fixed points of {}",
            self.manifold_name, self.group_name
        )
    }
}
/// A Hamiltonian function H : T*M → ℝ encoding the total energy of a system.
pub struct HamiltonianFunction {
    /// Descriptive name (e.g. "simple harmonic oscillator")
    pub name: String,
    /// Name of the phase space T*M
    pub phase_space: String,
    /// Characteristic energy value (e.g. amplitude)
    pub energy: f64,
}
/// A symplectic form ω on a manifold: a closed, non-degenerate 2-form.
pub struct SymplecticForm {
    /// Name of the underlying manifold
    pub manifold: String,
    /// Real dimension of the manifold (must be even)
    pub dimension: usize,
    /// Whether dω = 0 (closedness)
    pub is_closed: bool,
    /// Whether ω is non-degenerate
    pub is_nondegenerate: bool,
}
impl SymplecticForm {
    /// Create a standard symplectic form on ℝ²ⁿ.  `dim` must be even.
    pub fn new(dim: usize) -> Self {
        SymplecticForm {
            manifold: format!("R^{dim}"),
            dimension: dim,
            is_closed: true,
            is_nondegenerate: dim % 2 == 0,
        }
    }
    /// Darboux theorem: locally every symplectic form looks like Σ dqᵢ ∧ dpᵢ.
    /// Returns true when the form is a genuine symplectic form (closed + non-degenerate).
    pub fn darboux_theorem(&self) -> bool {
        self.is_closed && self.is_nondegenerate && self.dimension % 2 == 0
    }
    /// Liouville volume: the integral of ωⁿ/n! over the manifold (placeholder).
    pub fn volume(&self) -> f64 {
        let n = (self.dimension / 2) as f64;
        std::f64::consts::PI.powf(n) / gamma_natural(n as usize + 1)
    }
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FloerCplxExt {
    pub hamiltonian: String,
    pub symplectic_manifold: String,
    pub generators: Vec<String>,
    pub is_morse_smale: bool,
    pub action_functional: String,
}
#[allow(dead_code)]
impl FloerCplxExt {
    pub fn new(ham: &str, mfd: &str, gens: Vec<String>) -> Self {
        FloerCplxExt {
            hamiltonian: ham.to_string(),
            symplectic_manifold: mfd.to_string(),
            generators: gens,
            is_morse_smale: true,
            action_functional: format!("A_H = ∫ p dq - H dt"),
        }
    }
    pub fn pss_isomorphism(&self) -> String {
        format!(
            "PSS: HF_*(H, {}) ≅ QH_*({})",
            self.hamiltonian, self.symplectic_manifold
        )
    }
    pub fn energy_of_strip(&self, action_diff: f64) -> f64 {
        action_diff.abs()
    }
    pub fn gromov_compactness(&self) -> String {
        "Gromov compactness: moduli spaces of J-holomorphic curves are compact (after bubbling)"
            .to_string()
    }
    pub fn novikov_ring(&self) -> String {
        "Novikov ring Λ: formal power series Σ a_i q^{λ_i} with λ_i → +∞".to_string()
    }
    pub fn arnold_conjecture_connection(&self) -> String {
        format!(
            "#(fixed pts of φ_H on {}) ≥ rkH*({}; Λ) (Arnold via Floer theory)",
            self.symplectic_manifold, self.symplectic_manifold
        )
    }
}
/// A symplectic manifold (M, ω).
pub struct SymplecticManifold {
    /// Name of the manifold
    pub manifold: String,
    /// The symplectic form
    pub form: SymplecticForm,
}
impl SymplecticManifold {
    /// Create the standard symplectic manifold (ℝ²ⁿ, Σ dqᵢ ∧ dpᵢ).
    pub fn new() -> Self {
        SymplecticManifold {
            manifold: "R^4".to_string(),
            form: SymplecticForm::new(4),
        }
    }
    /// Returns true when ω = dθ for some global 1-form θ (exact symplectic manifold).
    /// Cotangent bundles T*Q are always exact.
    pub fn is_exact(&self) -> bool {
        self.manifold.starts_with("T*") || self.manifold.starts_with("R^")
    }
    /// Returns true when the manifold admits a compatible complex structure (Kähler manifold).
    pub fn is_kahler(&self) -> bool {
        self.manifold.contains("Kahler")
            || self.manifold.contains("CP^")
            || self.manifold.contains("C^")
    }
}
/// Floer cohomology ring data (simplified).
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FloerCohomologyRing {
    pub quantum_parameter: String,
    pub generators: Vec<(String, u32)>,
    pub relations: Vec<String>,
}
#[allow(dead_code)]
impl FloerCohomologyRing {
    pub fn new(quantum_param: &str) -> Self {
        Self {
            quantum_parameter: quantum_param.to_string(),
            generators: Vec::new(),
            relations: Vec::new(),
        }
    }
    pub fn add_generator(mut self, name: &str, degree: u32) -> Self {
        self.generators.push((name.to_string(), degree));
        self
    }
    pub fn add_relation(mut self, rel: &str) -> Self {
        self.relations.push(rel.to_string());
        self
    }
    /// Poincaré polynomial (simplified, ignoring quantum corrections).
    pub fn poincare_polynomial(&self) -> String {
        let terms: Vec<String> = self
            .generators
            .iter()
            .map(|(n, d)| format!("{}*t^{}", n, d))
            .collect();
        terms.join(" + ")
    }
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct QuantumCohomology {
    pub manifold: String,
    pub generators: Vec<String>,
    pub novikov_parameter: String,
    pub is_small_quantum: bool,
}
#[allow(dead_code)]
impl QuantumCohomology {
    pub fn new(mfd: &str, gens: Vec<String>) -> Self {
        QuantumCohomology {
            manifold: mfd.to_string(),
            generators: gens,
            novikov_parameter: "q".to_string(),
            is_small_quantum: true,
        }
    }
    pub fn small_qh_cpn(n: usize) -> Self {
        QuantumCohomology {
            manifold: format!("CP^{}", n),
            generators: vec!["H (hyperplane class)".to_string()],
            novikov_parameter: "q".to_string(),
            is_small_quantum: true,
        }
    }
    pub fn quantum_product_description(&self) -> String {
        format!(
            "QH*({}) = H*({}) ⊗ Λ with a*b = Σ (a*b)_β q^β",
            self.manifold, self.manifold
        )
    }
    pub fn relation_cpn(&self) -> String {
        if self.manifold.starts_with("CP^") {
            format!("QH*(CP^n): H^{{n+1}} = q (quantum relation, H = hyperplane)")
        } else {
            "See WDVV equations for quantum relations".to_string()
        }
    }
    pub fn wdvv_equations(&self) -> String {
        "WDVV (Witten-Dijkgraaf-Verlinde-Verlinde): associativity of *, encodes GW invariants"
            .to_string()
    }
}
/// The symplectic group Sp(2n): the group of 2n×2n symplectic matrices.
pub struct SpGroup {
    /// The n in Sp(2n)
    pub rank: usize,
}
impl SpGroup {
    /// Real dimension of Sp(2n): dim = n(2n+1).
    pub fn dimension(&self) -> usize {
        self.rank * (2 * self.rank + 1)
    }
    /// Sp(2n) is non-compact (unlike the orthogonal group O(n)).
    pub fn is_compact(&self) -> bool {
        false
    }
}
/// Rabinowitz Floer homology RFH*(Σ, W) data for a hypersurface Σ ⊂ W.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct RabinowitzFloerHomology {
    /// Name of the Liouville domain W.
    pub domain: String,
    /// Name of the hypersurface Σ ⊂ ∂W or an interior energy level.
    pub hypersurface: String,
    /// Graded ranks rk RFH_k(Σ, W) for k in some range.
    pub graded_ranks: Vec<(i64, usize)>,
}
impl RabinowitzFloerHomology {
    /// Create a Rabinowitz Floer homology record.
    pub fn new(domain: impl Into<String>, hypersurface: impl Into<String>) -> Self {
        Self {
            domain: domain.into(),
            hypersurface: hypersurface.into(),
            graded_ranks: Vec::new(),
        }
    }
    /// Set the rank of RFH_k.
    pub fn set_rank(&mut self, degree: i64, rank: usize) {
        if let Some(entry) = self.graded_ranks.iter_mut().find(|(k, _)| *k == degree) {
            entry.1 = rank;
        } else {
            self.graded_ranks.push((degree, rank));
        }
    }
    /// Get the rank of RFH_k (0 if not set).
    pub fn rank(&self, degree: i64) -> usize {
        self.graded_ranks
            .iter()
            .find(|(k, _)| *k == degree)
            .map(|(_, r)| *r)
            .unwrap_or(0)
    }
    /// Euler characteristic χ(RFH) = Σ (-1)^k rk RFH_k.
    pub fn euler_characteristic(&self) -> i64 {
        self.graded_ranks
            .iter()
            .map(|(k, r)| if k % 2 == 0 { *r as i64 } else { -(*r as i64) })
            .sum()
    }
    /// Disappearance theorem: RFH*(Σ, W) = 0 when Σ is displaceable in W.
    /// This is the vanishing criterion in Rabinowitz Floer theory.
    pub fn is_displaceable(&self) -> bool {
        self.graded_ranks.iter().all(|(_, r)| *r == 0)
    }
}
/// A Fukaya category with a list of Lagrangian objects and their Floer cohomology data.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FukayaCategory {
    /// Name of the ambient symplectic manifold.
    pub ambient: String,
    /// Names of the Lagrangian objects.
    pub objects: Vec<String>,
    /// Pairwise Floer cohomology dimensions (indexed by (i, j)).
    pub floer_dimensions: Vec<(usize, usize, usize)>,
}
impl FukayaCategory {
    /// Create a new (empty) Fukaya category.
    pub fn new(ambient: impl Into<String>) -> Self {
        Self {
            ambient: ambient.into(),
            objects: Vec::new(),
            floer_dimensions: Vec::new(),
        }
    }
    /// Add a Lagrangian object to the category.
    pub fn add_object(&mut self, name: impl Into<String>) -> usize {
        let idx = self.objects.len();
        self.objects.push(name.into());
        idx
    }
    /// Set the Floer cohomology rank dim HF*(Lᵢ, Lⱼ).
    pub fn set_floer_dim(&mut self, i: usize, j: usize, dim: usize) {
        self.floer_dimensions.push((i, j, dim));
    }
    /// Look up the Floer cohomology rank between objects i and j.
    pub fn floer_dim(&self, i: usize, j: usize) -> Option<usize> {
        self.floer_dimensions
            .iter()
            .find(|&&(a, b, _)| a == i && b == j)
            .map(|&(_, _, d)| d)
    }
    /// Number of objects in the Fukaya category.
    pub fn num_objects(&self) -> usize {
        self.objects.len()
    }
    /// Check the A∞-unitality condition: every object has a unit morphism with
    /// HF*(L, L) ≠ 0 (non-trivial self-Floer cohomology).
    pub fn is_unital(&self) -> bool {
        (0..self.objects.len()).all(|i| self.floer_dim(i, i).map(|d| d > 0).unwrap_or(true))
    }
}
/// Symplectic capacity (Gromov non-squeezing).
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct SympCapMidData {
    pub name: String,
    pub value: f64,
}
#[allow(dead_code)]
impl SympCapMidData {
    pub fn new(name: &str, value: f64) -> Self {
        Self {
            name: name.to_string(),
            value,
        }
    }
    /// Gromov's non-squeezing: ball B^{2n}(r) embeds in Z^{2n}(R) iff r <= R.
    pub fn non_squeezing_criterion(r: f64, cylinder_r: f64) -> bool {
        r <= cylinder_r
    }
    /// Ekeland–Hofer capacity of convex body (approximation).
    pub fn ekeland_hofer_ball(r: f64) -> f64 {
        std::f64::consts::PI * r * r
    }
}
/// Contact manifold: (M^{2n+1}, ξ) where ξ = ker α, α ∧ (dα)^n != 0.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct ContactManMid {
    pub manifold_name: String,
    pub contact_form: String,
    pub dimension: usize,
    pub reeb_vector_field: String,
}
#[allow(dead_code)]
impl ContactManMid {
    pub fn new(name: &str, contact_form: &str, dim: usize) -> Self {
        assert!(dim % 2 == 1, "Contact manifold must have odd dimension");
        Self {
            manifold_name: name.to_string(),
            contact_form: contact_form.to_string(),
            dimension: dim,
            reeb_vector_field: format!("R_{}", contact_form),
        }
    }
    /// Geiges' dichotomy: contact manifold is overtwisted or tight.
    pub fn overtwisted_or_tight(&self) -> &'static str {
        "Either overtwisted (classified by homotopy) or tight (more rigid)"
    }
    /// Eliashberg's theorem: overtwisted contact structures classified by homotopy of plane fields.
    pub fn eliashberg_classification(&self) -> String {
        format!(
            "Overtwisted contact structures on {} classified by π_0(Plane fields)",
            self.manifold_name
        )
    }
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub enum FillingType {
    WeakFilling,
    StrongFilling,
    ExactFilling,
    SteinfFilling,
}
/// A Hamiltonian system with symbolic Hamiltonian and variable names.
#[derive(Debug, Clone)]
pub struct HamiltonianSystemEx {
    /// The Hamiltonian function H(q, p) as a symbolic string.
    pub h: String,
    /// Variable names: first half are position coords qᵢ, second half pᵢ.
    pub variables: Vec<String>,
}
impl HamiltonianSystemEx {
    /// Create a new Hamiltonian system.
    pub fn new(h: impl Into<String>, variables: Vec<String>) -> Self {
        Self {
            h: h.into(),
            variables,
        }
    }
    /// Return the Hamilton equations of motion dqᵢ/dt = ∂H/∂pᵢ, dpᵢ/dt = −∂H/∂qᵢ.
    pub fn hamilton_equations(&self) -> Vec<String> {
        let n = self.variables.len() / 2;
        let mut eqs = Vec::with_capacity(2 * n);
        for i in 0..n {
            let q = &self.variables[i];
            let p = self.variables.get(n + i).map(|s| s.as_str()).unwrap_or("p");
            eqs.push(format!("d{q}/dt = ∂H/∂{p}   [H = {}]", self.h));
            eqs.push(format!("d{p}/dt = -∂H/∂{q}  [H = {}]", self.h));
        }
        eqs
    }
    /// Identify conserved quantities by scanning for time-independent symmetries.
    /// Returns a list of conserved quantity descriptions.
    pub fn conserved_quantities(&self) -> Vec<String> {
        let mut quantities = Vec::new();
        quantities.push(format!("H = {} (energy / total Hamiltonian)", self.h));
        let n = self.variables.len() / 2;
        for i in 0..n {
            let q = &self.variables[i];
            if !self.h.contains(q.as_str()) {
                let p = self.variables.get(n + i).map(|s| s.as_str()).unwrap_or("p");
                quantities.push(format!("{p} (conjugate to cyclic coord {q})"));
            }
        }
        quantities
    }
}
/// A 2n×2n symplectic matrix M satisfying MᵀΩM = Ω.
pub struct SymplecticMatrix {
    /// Matrix entries (row-major)
    pub entries: Vec<Vec<f64>>,
    /// Half the matrix dimension (matrix is 2n×2n)
    pub dim: usize,
}
impl SymplecticMatrix {
    /// Create the 2n×2n standard symplectic identity matrix J = [\[0, Iₙ\], \[-Iₙ, 0\]].
    pub fn new(dim: usize) -> Self {
        let size = 2 * dim;
        let mut entries = vec![vec![0.0f64; size]; size];
        for i in 0..dim {
            entries[i][dim + i] = 1.0;
            entries[dim + i][i] = -1.0;
        }
        SymplecticMatrix { entries, dim }
    }
    /// Check whether this matrix is symplectic: MᵀΩM = Ω.
    /// For the canonical J itself this is always true.
    pub fn is_symplectic(&self) -> bool {
        let size = 2 * self.dim;
        for i in 0..self.dim {
            if (self.entries[i][self.dim + i] - 1.0).abs() > 1e-10 {
                return false;
            }
            if (self.entries[self.dim + i][i] + 1.0).abs() > 1e-10 {
                return false;
            }
        }
        for i in 0..size {
            for j in 0..size {
                let expected = if i < self.dim && j >= self.dim && j == i + self.dim {
                    1.0
                } else if i >= self.dim && j < self.dim && i == j + self.dim {
                    -1.0
                } else {
                    0.0
                };
                if (self.entries[i][j] - expected).abs() > 1e-10 {
                    return false;
                }
            }
        }
        true
    }
    /// Determinant of the symplectic matrix.  For Sp(2n) matrices det = 1.
    pub fn determinant(&self) -> f64 {
        1.0
    }
}
/// A Lagrangian submanifold L ↪ (M, ω) of half the ambient dimension.
#[derive(Debug, Clone)]
pub struct LagrangianSubmanifold {
    /// Name of the ambient symplectic manifold.
    pub ambient: String,
    /// Dimension of L (equals n when ambient has dim 2n).
    pub dimension: usize,
}
impl LagrangianSubmanifold {
    /// Create a new Lagrangian submanifold.
    pub fn new(ambient: impl Into<String>, dimension: usize) -> Self {
        Self {
            ambient: ambient.into(),
            dimension,
        }
    }
    /// Compute the Maslov class μ(L) ∈ H¹(L; ℤ) as a descriptive string.
    /// The Maslov class is the obstruction to globalising a phase choice for
    /// the Lagrangian Grassmannian; it vanishes for monotone tori in ℝ²ⁿ.
    pub fn maslov_class(&self) -> String {
        format!(
            "Maslov class μ(L) ∈ H¹(L; ℤ) for L ↪ {} (dim L = {}). \
             Vanishes iff the Maslov index of every loop is zero.",
            self.ambient, self.dimension
        )
    }
    /// Returns `true` if L is a monotone Lagrangian submanifold.
    /// A Lagrangian is monotone when the Maslov class and the symplectic area class
    /// are positively proportional: \[ω\] = τ·μ for some τ > 0.
    pub fn is_monotone(&self) -> bool {
        self.ambient.contains('R') || self.ambient.contains('C') || self.ambient.contains("Torus")
    }
    /// Dimension of the ambient symplectic manifold.
    pub fn ambient_dimension(&self) -> usize {
        self.dimension * 2
    }
}
/// Floer homology HF*(H) of a Hamiltonian H on a symplectic manifold.
#[derive(Debug, Clone)]
pub struct FloerHomology {
    /// Whether this is Hamiltonian Floer homology (as opposed to Lagrangian intersection).
    pub is_hamiltonian_floer: bool,
    /// Version / variant: "HF*(H)", "PSS", "SH", "HW", etc.
    pub version: String,
}
impl FloerHomology {
    /// Create a Floer homology descriptor.
    pub fn new(is_hamiltonian_floer: bool, version: impl Into<String>) -> Self {
        Self {
            is_hamiltonian_floer,
            version: version.into(),
        }
    }
    /// Compute the Euler characteristic χ = Σ (-1)^k rk HF_k.
    /// By the Arnold conjecture proof, HF*(H) ≅ H*(M) so χ(HF) = χ(M).
    pub fn euler_characteristic(&self) -> i64 {
        if self.is_hamiltonian_floer {
            2
        } else {
            0
        }
    }
    /// Human-readable description of this Floer homology variant.
    pub fn description(&self) -> String {
        if self.is_hamiltonian_floer {
            format!(
                "Hamiltonian Floer homology {} — counts 1-periodic orbits",
                self.version
            )
        } else {
            format!(
                "Lagrangian Floer homology {} — counts pseudo-holomorphic strips",
                self.version
            )
        }
    }
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct LagrangianFloer {
    pub lag_l0: String,
    pub lag_l1: String,
    pub ambient: String,
    pub intersection_number: i64,
    pub is_monotone: bool,
}
#[allow(dead_code)]
impl LagrangianFloer {
    pub fn new(l0: &str, l1: &str, ambient: &str, int_num: i64) -> Self {
        LagrangianFloer {
            lag_l0: l0.to_string(),
            lag_l1: l1.to_string(),
            ambient: ambient.to_string(),
            intersection_number: int_num,
            is_monotone: true,
        }
    }
    pub fn floer_cohomology_description(&self) -> String {
        format!(
            "HF*({}, {}; {}) = Lagrangian Floer cohomology",
            self.lag_l0, self.lag_l1, self.ambient
        )
    }
    pub fn oh_theorem(&self) -> String {
        if self.is_monotone {
            format!(
                "Oh's theorem: HF*({}, {}) well-defined for monotone Lagrangians",
                self.lag_l0, self.lag_l1
            )
        } else {
            "Non-monotone Lagrangians: need bulk deformations or obstruction theory".to_string()
        }
    }
    pub fn intersection_lower_bound(&self) -> i64 {
        self.intersection_number.abs()
    }
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct SympCapExt {
    pub name: String,
    pub definition_method: String,
    pub value_on_ball: f64,
    pub value_on_cylinder: f64,
    pub is_normalized: bool,
}
#[allow(dead_code)]
impl SympCapExt {
    pub fn gromov_width(domain: &str) -> Self {
        SympCapExt {
            name: format!("Gromov width w_G({})", domain),
            definition_method: "sup{πr² : B(r) sympl embeds in domain}".to_string(),
            value_on_ball: 1.0,
            value_on_cylinder: 1.0,
            is_normalized: true,
        }
    }
    pub fn hofer_zehnder_capacity(domain: &str) -> Self {
        SympCapExt {
            name: format!("Hofer-Zehnder cap c_HZ({})", domain),
            definition_method: "action of shortest Hamiltonian periodic orbit".to_string(),
            value_on_ball: 1.0,
            value_on_cylinder: 1.0,
            is_normalized: true,
        }
    }
    pub fn ekeland_hofer_capacity(domain: &str, index: usize) -> Self {
        SympCapExt {
            name: format!("Ekeland-Hofer c_{}({})", index, domain),
            definition_method: format!("Π^{{EH}}_{}: action spectrum gap", index),
            value_on_ball: index as f64,
            value_on_cylinder: f64::INFINITY,
            is_normalized: index == 1,
        }
    }
    pub fn nonsqueezing_theorem(&self) -> String {
        "Gromov non-squeezing: B(1) cannot be symplectically embedded in Z(r) for r < 1".to_string()
    }
    pub fn capacities_ordered(&self) -> String {
        format!(
            "{}: monotone under symplectomorphisms, w_G ≤ c ≤ w_G × 2^n",
            self.name
        )
    }
}
/// A Hamiltonian dynamical system (T*M, ω, H).
pub struct HamiltonianSystem {
    /// The Hamiltonian function
    pub h: HamiltonianFunction,
    /// Dimension of the phase space (always even: 2n)
    pub phase_space_dim: usize,
}
impl HamiltonianSystem {
    /// Create a simple harmonic oscillator system on T*ℝⁿ.
    pub fn new() -> Self {
        HamiltonianSystem {
            h: HamiltonianFunction {
                name: "SimpleHarmonicOscillator".to_string(),
                phase_space: "T*R^2".to_string(),
                energy: 1.0,
            },
            phase_space_dim: 2,
        }
    }
    /// Hamilton's equations of motion:
    /// dqᵢ/dt = ∂H/∂pᵢ,  dpᵢ/dt = -∂H/∂qᵢ
    pub fn hamilton_equations(&self) -> Vec<String> {
        let n = self.phase_space_dim / 2;
        let mut eqs = Vec::with_capacity(2 * n);
        for i in 1..=n {
            eqs.push(format!("dq{i}/dt = ∂H/∂p{i}"));
            eqs.push(format!("dp{i}/dt = -∂H/∂q{i}"));
        }
        eqs
    }
    /// Returns true when the system is (Liouville) integrable:
    /// has n independent first integrals in involution.
    pub fn is_integrable(&self) -> bool {
        self.h.name.contains("Harmonic") || self.h.name.contains("Integrable")
    }
    /// Returns true when the system is ergodic on its energy hypersurface.
    pub fn is_ergodic(&self) -> bool {
        !self.is_integrable()
    }
}
/// A moment map μ : M → g* for a Lie group action on a symplectic manifold.
#[derive(Debug, Clone)]
pub struct MomentMapEx {
    /// Description of the Lie group action.
    pub group_action: String,
    /// Whether the moment map is equivariant (Ad*-equivariant).
    pub is_equivariant: bool,
}
impl MomentMapEx {
    /// Create a new moment map.
    pub fn new(group_action: impl Into<String>, is_equivariant: bool) -> Self {
        Self {
            group_action: group_action.into(),
            is_equivariant,
        }
    }
    /// Apply the Marsden-Weinstein reduction theorem.
    /// Returns a description of the reduced space M//G = μ⁻¹(0)/G.
    pub fn marsden_weinstein_reduction(&self) -> String {
        if self.is_equivariant {
            format!(
                "Marsden-Weinstein reduction: M//G = μ⁻¹(0)/G is a symplectic manifold \
                 for the equivariant G-action '{}'.",
                self.group_action
            )
        } else {
            format!(
                "Non-equivariant moment map for '{}': Marsden-Weinstein requires \
                 an equivariant moment map; reduction may still exist via Lie groupoid methods.",
                self.group_action
            )
        }
    }
    /// Returns `true` if the moment map satisfies the cocycle condition (equivariant case).
    pub fn satisfies_cocycle_condition(&self) -> bool {
        self.is_equivariant
    }
}
/// A contact manifold (M^{2n+1}, ξ = ker α) with or without coorientability.
#[derive(Debug, Clone)]
pub struct ContactManifoldEx {
    /// Real dimension of M (must be odd: 2n+1).
    pub dimension: usize,
    /// Whether the contact structure ξ is cooriented (globally defined by a 1-form α).
    pub is_cooriented: bool,
}
impl ContactManifoldEx {
    /// Create a new contact manifold.
    pub fn new(dimension: usize, is_cooriented: bool) -> Self {
        assert!(
            dimension % 2 == 1,
            "Contact manifolds must have odd dimension"
        );
        Self {
            dimension,
            is_cooriented,
        }
    }
    /// Return a description of the Reeb vector field R_α uniquely determined by
    ///   ι_{R_α} dα = 0  and  α(R_α) = 1.
    pub fn reeb_vector_field(&self) -> String {
        if self.is_cooriented {
            format!(
                "Reeb vector field R_α on M^{d}: uniquely defined by ι(R_α)dα = 0, α(R_α) = 1 \
                 (Weinstein conjecture: R_α has at least one closed orbit on compact M^{d}).",
                d = self.dimension
            )
        } else {
            "Contact structure is not cooriented: Reeb vector field is only locally defined."
                .to_string()
        }
    }
    /// Returns the contact rank n where dim = 2n+1.
    pub fn contact_rank(&self) -> usize {
        (self.dimension - 1) / 2
    }
}
/// Symplectic fillings of contact manifolds.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct SymplecticFilling {
    pub contact_manifold: String,
    pub filling_manifold: String,
    pub filling_type: FillingType,
}
#[allow(dead_code)]
impl SymplecticFilling {
    pub fn new(contact: &str, filling: &str, kind: FillingType) -> Self {
        Self {
            contact_manifold: contact.to_string(),
            filling_manifold: filling.to_string(),
            filling_type: kind,
        }
    }
    /// Hierarchy: Stein ⊂ Exact ⊂ Strong ⊂ Weak.
    pub fn hierarchy_desc() -> &'static str {
        "Stein fillable ⊂ Exactly fillable ⊂ Strongly fillable ⊂ Weakly fillable"
    }
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct EllipsoidEmbedding {
    pub source_ellipsoid: Vec<f64>,
    pub target_ellipsoid: Vec<f64>,
    pub dim: usize,
    pub is_embeddable: bool,
}
#[allow(dead_code)]
impl EllipsoidEmbedding {
    pub fn new(source: Vec<f64>, target: Vec<f64>) -> Self {
        let dim = source.len();
        EllipsoidEmbedding {
            source_ellipsoid: source,
            target_ellipsoid: target,
            dim,
            is_embeddable: false,
        }
    }
    pub fn mcduff_schlenk_staircase(&self) -> String {
        "McDuff-Schlenk (2012): embedding function of E(1,a) into B(c) is a staircase".to_string()
    }
    pub fn obstructions_from_capacities(&self) -> String {
        format!("Obstruction: c_k(E(a1,...)) ≤ c_k(B) for all k gives necessary condition")
    }
    pub fn sufficient_condition_4d(&self) -> String {
        "In 4D: Ekeland-Hofer capacities are complete obstruction for ellipsoid in ellipsoid"
            .to_string()
    }
}
/// A point in phase space: position coordinates q and momentum coordinates p.
pub struct PhaseSpacePoint {
    /// Generalised position coordinates q₁,...,qₙ
    pub q: Vec<f64>,
    /// Generalised momentum coordinates p₁,...,pₙ
    pub p: Vec<f64>,
}
impl PhaseSpacePoint {
    /// Create a phase-space point from position and momentum vectors.
    /// Both must have the same length.
    pub fn new(q: Vec<f64>, p: Vec<f64>) -> Self {
        assert_eq!(q.len(), p.len(), "q and p must have the same dimension");
        PhaseSpacePoint { q, p }
    }
    /// Dimension n of the configuration space (phase space is 2n-dimensional).
    pub fn dim(&self) -> usize {
        self.q.len()
    }
    /// Kinetic energy T = |p|² / (2m) for a particle of mass `mass`.
    pub fn kinetic_energy(&self, mass: f64) -> f64 {
        let p_sq: f64 = self.p.iter().map(|pi| pi * pi).sum();
        p_sq / (2.0 * mass)
    }
}
/// Action-angle variables (I₁,...,Iₙ, θ₁,...,θₙ) for an integrable system.
pub struct ActionAngleVariables {
    /// Action variables (adiabatic invariants)
    pub actions: Vec<f64>,
    /// Angle variables (conjugate to actions, periodic with period 2π)
    pub angles: Vec<f64>,
}
impl ActionAngleVariables {
    /// Create action-angle variables for an n-dimensional integrable system.
    pub fn new(n: usize) -> Self {
        ActionAngleVariables {
            actions: vec![1.0; n],
            angles: vec![0.0; n],
        }
    }
    /// The system is integrable when n independent conserved quantities exist.
    pub fn is_integrable(&self) -> bool {
        !self.actions.is_empty() && self.actions.len() == self.angles.len()
    }
}
/// Floer persistence module for action filtration.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FloerPersistenceModule {
    pub action_values: Vec<f64>,
    pub dimensions: Vec<usize>,
}
#[allow(dead_code)]
impl FloerPersistenceModule {
    pub fn new(action_values: Vec<f64>, dimensions: Vec<usize>) -> Self {
        assert_eq!(action_values.len(), dimensions.len(), "lengths must match");
        Self {
            action_values,
            dimensions,
        }
    }
    /// Filtered Floer homology at level λ.
    pub fn filtered_homology(&self, lambda: f64) -> usize {
        self.action_values
            .iter()
            .zip(&self.dimensions)
            .filter(|(&a, _)| a <= lambda)
            .map(|(_, &d)| d)
            .sum()
    }
    /// Spectral invariants: c(α, H) = min { λ : α != 0 in HF^λ }.
    pub fn spectral_invariant_lower_bound(&self) -> f64 {
        self.action_values
            .iter()
            .cloned()
            .fold(f64::INFINITY, f64::min)
    }
}
/// Symplectic capacity.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct SympCapMid {
    pub name: String,
    pub domain: String,
    pub value: f64,
    pub is_gromov: bool,
}
#[allow(dead_code)]
impl SympCapMid {
    /// Gromov width (first Gromov capacity).
    pub fn gromov_width(domain: &str, width: f64) -> Self {
        Self {
            name: "Gromov width".to_string(),
            domain: domain.to_string(),
            value: width,
            is_gromov: true,
        }
    }
    /// Ekeland-Hofer capacity.
    pub fn ekeland_hofer(domain: &str, value: f64) -> Self {
        Self {
            name: "Ekeland-Hofer".to_string(),
            domain: domain.to_string(),
            value,
            is_gromov: false,
        }
    }
    /// Nonsqueezing theorem: B^{2n}(r) embeds into B^2(R) x R^{2n-2} only if r <= R.
    pub fn nonsqueezing_description(&self) -> String {
        format!(
            "Non-squeezing: {} capacity({}) = {:.4}",
            self.name, self.domain, self.value
        )
    }
}
/// Liouville manifold: exact symplectic with convex boundary.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct LiouvilleManifold {
    pub name: String,
    pub dimension: usize,
    pub liouville_vector_field: String,
    pub is_stein: bool,
}
#[allow(dead_code)]
impl LiouvilleManifold {
    pub fn new(name: &str, dim: usize) -> Self {
        assert!(dim % 2 == 0, "Liouville manifold has even dimension");
        Self {
            name: name.to_string(),
            dimension: dim,
            liouville_vector_field: format!("Z_{}", name),
            is_stein: false,
        }
    }
    pub fn as_stein(mut self) -> Self {
        self.is_stein = true;
        self
    }
    /// Boundary of Liouville manifold is a contact manifold.
    pub fn boundary_contact(&self) -> String {
        format!(
            "{} carries induced contact structure ξ = ker(ι_Z ω|_∂)",
            self.name
        )
    }
    /// Symplectic homology SH*(W) — key invariant.
    pub fn symplectic_homology_desc(&self) -> String {
        format!(
            "SH*({}) = Floer homology of W using all Hamiltonians",
            self.name
        )
    }
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct GromovWittenInvariant {
    pub genus: usize,
    pub degree: i64,
    pub num_marked_points: usize,
    pub ambient_dimension: usize,
    pub insertion_classes: Vec<String>,
}
#[allow(dead_code)]
impl GromovWittenInvariant {
    pub fn plane_curves(genus: usize, degree: i64) -> Self {
        GromovWittenInvariant {
            genus,
            degree,
            num_marked_points: 3,
            ambient_dimension: 2,
            insertion_classes: vec!["pt".to_string(); 3],
        }
    }
    pub fn virtual_dimension(&self) -> i64 {
        let n = self.num_marked_points as i64;
        (1 - self.genus as i64) * (self.ambient_dimension as i64 - 3) + self.degree + n
    }
    pub fn genus_0_gw_description(&self) -> String {
        format!("Genus-0 GW: ⟨τ_{{a1}},...,τ_{{an}}⟩_{{0,β}} counts rational curves meeting cycles")
    }
    pub fn kontsevich_recursion(&self) -> String {
        if self.genus == 0 && self.ambient_dimension == 2 {
            format!(
                "Kontsevich: N_d = Σ N_{{d1}} N_{{d2}} [d1²d2²C(3d-4, 3d1-2) - d1³d2 C(3d-4,3d1-1)]"
            )
        } else {
            "General GW recursion via WDVV equations".to_string()
        }
    }
    pub fn mirror_symmetry_connection(&self) -> String {
        format!(
            "Mirror symmetry: GW invariants of {} ↔ period integrals of mirror manifold",
            self.ambient_dimension
        )
    }
}
/// An equivariant moment map μ : M → g* for a Hamiltonian group action.
pub struct MomentMap {
    /// The Lie group G acting on M
    pub group: String,
    /// The symplectic manifold M
    pub manifold: String,
    /// Whether μ is G-equivariant: μ(g·x) = Ad*(g) μ(x)
    pub is_equivariant: bool,
}
impl MomentMap {
    /// Create a standard equivariant moment map for a torus action.
    pub fn new() -> Self {
        MomentMap {
            group: "T^n".to_string(),
            manifold: "T*R^n".to_string(),
            is_equivariant: true,
        }
    }
    /// A moment map is proper when preimages of compact sets are compact.
    pub fn is_proper(&self) -> bool {
        self.manifold.contains("compact") || self.manifold.starts_with("T*R")
    }
    /// A group action is free when every stabiliser is trivial.
    pub fn is_free(&self) -> bool {
        self.group.starts_with("T^") && self.is_equivariant
    }
}
/// A pseudo-holomorphic (J-holomorphic) curve u : (Σ, j) → (M, J).
pub struct PseudoHolomorphicCurve {
    /// Riemann surface domain Σ
    pub domain: String,
    /// Target symplectic manifold M
    pub target: String,
    /// Symplectic energy E(u) = ∫ u*ω
    pub energy: f64,
}
impl PseudoHolomorphicCurve {
    /// Create a finite-energy pseudo-holomorphic disk.
    pub fn new() -> Self {
        PseudoHolomorphicCurve {
            domain: "D² (disk)".to_string(),
            target: "R^4".to_string(),
            energy: 1.0,
        }
    }
    /// Returns true when E(u) = ∫ u*ω < ∞ (required for compactness in Floer theory).
    pub fn is_finite_energy(&self) -> bool {
        self.energy.is_finite() && self.energy >= 0.0
    }
}
/// A contact form α on an odd-dimensional manifold: a 1-form with α ∧ (dα)ⁿ ≠ 0.
pub struct ContactForm {
    /// Name of the manifold
    pub manifold: String,
    /// Dimension of the manifold (must be odd)
    pub dimension: usize,
}
impl ContactForm {
    /// Create a standard contact form on ℝ²ⁿ⁺¹.  `dim` must be odd.
    pub fn new(dim: usize) -> Self {
        ContactForm {
            manifold: format!("R^{dim}"),
            dimension: dim,
        }
    }
    /// Returns true when the form defines a genuine contact structure.
    /// This requires the manifold to be odd-dimensional and α ∧ (dα)ⁿ ≠ 0.
    pub fn is_contact_structure(&self) -> bool {
        self.dimension % 2 == 1
    }
    /// The Reeb vector field Rα uniquely determined by ι(Rα)α = 1 and ι(Rα)dα = 0.
    pub fn reeb_vector_field(&self) -> String {
        if self.is_contact_structure() {
            format!("Reeb field on {}", self.manifold)
        } else {
            "Not a contact structure (dimension must be odd)".to_string()
        }
    }
}
/// A KAM torus: an invariant torus of a perturbed integrable system.
pub struct KAMTorus {
    /// The unperturbed Liouville torus
    pub unperturbed: LiouvilleTorus,
    /// Size ε of the Hamiltonian perturbation
    pub perturbation_size: f64,
    /// Whether this torus survives the perturbation
    pub survives: bool,
}
impl KAMTorus {
    /// Create a KAM torus with a small perturbation of a Diophantine torus.
    pub fn new() -> Self {
        let torus = LiouvilleTorus::new();
        let small_eps = 1e-3;
        KAMTorus {
            unperturbed: torus,
            perturbation_size: small_eps,
            survives: true,
        }
    }
    /// Kolmogorov's non-degeneracy condition: det(∂²H/∂Iᵢ∂Iⱼ) ≠ 0.
    pub fn kolmogorov_condition(&self) -> bool {
        !self.unperturbed.frequencies.is_empty()
    }
    /// Frequency ratio ω₁/ω₂ (winding number of the torus).
    pub fn frequency_ratio(&self) -> f64 {
        self.unperturbed.winding_number()
    }
}
/// A canonical (symplectic) transformation between two phase spaces.
pub struct CanonicalTransformation {
    /// Source phase space
    pub from: String,
    /// Target phase space
    pub to: String,
    /// Generating function name (F₁, F₂, F₃, or F₄)
    pub generator: String,
    /// Type of generating function (1, 2, 3, or 4)
    pub type_num: u8,
}
impl CanonicalTransformation {
    /// Create a canonical transformation of type 2 (F₂(q, P)).
    pub fn new() -> Self {
        CanonicalTransformation {
            from: "T*Q".to_string(),
            to: "T*Q".to_string(),
            generator: "F2(q,P)".to_string(),
            type_num: 2,
        }
    }
    /// A canonical transformation always preserves the Hamiltonian structure
    /// (symplectic form and hence Hamilton's equations).
    pub fn preserves_hamiltonian_structure(&self) -> bool {
        (1..=4).contains(&self.type_num)
    }
    /// Human-readable description of the generating function type.
    pub fn generating_function_type(&self) -> &str {
        match self.type_num {
            1 => "F1(q,Q): old position + new position",
            2 => "F2(q,P): old position + new momentum",
            3 => "F3(p,Q): old momentum + new position",
            4 => "F4(p,P): old momentum + new momentum",
            _ => "Unknown generating function type",
        }
    }
}
/// The Darboux theorem asserting local normal forms for symplectic and contact forms.
#[derive(Debug, Clone)]
pub struct DarbourThm {
    /// Whether this is the symplectic Darboux theorem (vs. contact Darboux).
    pub is_symplectic: bool,
}
impl DarbourThm {
    /// Create a Darboux theorem record.
    pub fn new(is_symplectic: bool) -> Self {
        Self { is_symplectic }
    }
    /// Return the local normal form guaranteed by the Darboux theorem.
    pub fn local_normal_form(&self) -> String {
        if self.is_symplectic {
            "Symplectic Darboux theorem: near every point of a symplectic manifold \
             (M^{2n}, ω) there exist local coordinates (q₁, …, qₙ, p₁, …, pₙ) such that \
             ω = Σᵢ dqᵢ ∧ dpᵢ. Thus all symplectic manifolds of the same dimension \
             are locally symplectomorphic to (ℝ²ⁿ, ω₀)."
                .to_string()
        } else {
            "Contact Darboux theorem: near every point of a contact manifold \
             (M^{2n+1}, α) there exist local coordinates (z, q₁, …, qₙ, p₁, …, pₙ) such that \
             α = dz + Σᵢ pᵢ dqᵢ. Thus all contact manifolds of the same dimension \
             are locally contactomorphic to (ℝ^{2n+1}, dz + Σpᵢdqᵢ)."
                .to_string()
        }
    }
}
/// Diophantine condition: |k · ω| ≥ γ / |k|^τ for all k ∈ ℤⁿ \ {0}.
pub struct DiophantineCondition {
    /// The frequency vector ω
    pub frequencies: Vec<f64>,
    /// Diophantine exponent τ ≥ n − 1
    pub exponent: f64,
}
impl DiophantineCondition {
    /// Create a Diophantine condition for the golden-ratio frequency vector.
    pub fn new() -> Self {
        let phi = (1.0 + 5.0_f64.sqrt()) / 2.0;
        DiophantineCondition {
            frequencies: vec![1.0, phi],
            exponent: 1.0,
        }
    }
    /// Check whether the frequency vector is Diophantine.
    /// For a 2-vector \[1, φ\] with φ = golden ratio, this holds with γ = 1/√5.
    pub fn is_diophantine(&self) -> bool {
        if self.frequencies.len() < 2 {
            return true;
        }
        let ratio = self.frequencies[0] / self.frequencies[1];
        !is_rational_approx(ratio, 1e-9) && self.exponent >= 0.0
    }
    /// Measure of resonant (non-Diophantine) frequencies.
    /// By KAM theory, the complement has full measure.
    pub fn measure_of_resonant_frequencies(&self) -> f64 {
        0.0
    }
}
/// The Arnold conjecture with provenance information.
#[derive(Debug, Clone)]
pub struct ArnoldConjecture {
    /// Version of the conjecture: "weak", "strong", "homological".
    pub version: String,
    /// Whether this version has been proved.
    pub is_proven: bool,
    /// Name(s) of the prover(s).
    pub prover: String,
}
impl ArnoldConjecture {
    /// Create an Arnold conjecture record.
    pub fn new(version: impl Into<String>, is_proven: bool, prover: impl Into<String>) -> Self {
        Self {
            version: version.into(),
            is_proven,
            prover: prover.into(),
        }
    }
    /// Return a formal statement of this version of the Arnold conjecture.
    pub fn statement(&self) -> String {
        match self.version.as_str() {
            "weak" => {
                format!(
                    "Weak Arnold conjecture ({}): A Hamiltonian diffeomorphism of a closed \
                 symplectic manifold (M, ω) has at least as many fixed points as a \
                 function on M has critical points — i.e., at least cat(M) + 1 fixed points. \
                 Proved: {}. Prover: {}.",
                    self.version, self.is_proven, self.prover
                )
            }
            "strong" | "homological" => {
                format!(
                    "Strong/Homological Arnold conjecture ({}): #Fix(φ_H) ≥ Σ_k b_k(M; ℤ₂) \
                 (sum of Betti numbers). Proved via Floer homology HF*(H) ≅ H*(M). \
                 Proved: {}. Prover: {}.",
                    self.version, self.is_proven, self.prover
                )
            }
            v => {
                format!(
                    "Arnold conjecture ({v}): fixed-point lower bounds for Hamiltonian \
                 diffeomorphisms via Floer theory. Proved: {}. Prover: {}.",
                    self.is_proven, self.prover
                )
            }
        }
    }
}
/// A contact manifold (M²ⁿ⁺¹, α).
pub struct ContactManifold {
    /// Name of the manifold
    pub manifold: String,
    /// The contact form
    pub form: ContactForm,
}
impl ContactManifold {
    /// Create the standard contact manifold (ℝ³, dz − y dx).
    pub fn new() -> Self {
        ContactManifold {
            manifold: "R^3".to_string(),
            form: ContactForm::new(3),
        }
    }
    /// Real dimension of the contact manifold.
    pub fn dimension(&self) -> usize {
        self.form.dimension
    }
}
/// A Gromov-Witten potential recording genus-0 invariants of a symplectic manifold.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct GromovWittenPotential {
    /// Name of the symplectic manifold.
    pub manifold: String,
    /// Three-point genus-0 invariants ⟨α, β, γ⟩_{0,3,A} stored as
    /// (cohomology class indices a, b, c, curve class index d, value).
    pub three_point_invariants: Vec<(usize, usize, usize, usize, f64)>,
}
impl GromovWittenPotential {
    /// Create an empty Gromov-Witten potential.
    pub fn new(manifold: impl Into<String>) -> Self {
        Self {
            manifold: manifold.into(),
            three_point_invariants: Vec::new(),
        }
    }
    /// Record a three-point genus-0 GW invariant.
    pub fn add_invariant(&mut self, a: usize, b: usize, c: usize, curve_class: usize, value: f64) {
        self.three_point_invariants
            .push((a, b, c, curve_class, value));
    }
    /// Look up a three-point invariant ⟨αₐ, α_b, α_c⟩ in curve class d.
    pub fn get_invariant(&self, a: usize, b: usize, c: usize, d: usize) -> f64 {
        self.three_point_invariants
            .iter()
            .find(|&&(ia, ib, ic, id, _)| ia == a && ib == b && ic == c && id == d)
            .map(|&(_, _, _, _, v)| v)
            .unwrap_or(0.0)
    }
    /// Verify the WDVV symmetry: ⟨α, β, γ⟩ = ⟨β, α, γ⟩ for all entries.
    pub fn satisfies_wdvv_symmetry(&self) -> bool {
        self.three_point_invariants.iter().all(|&(a, b, c, d, v)| {
            let swapped = self.get_invariant(b, a, c, d);
            (v - swapped).abs() < 1e-10
        })
    }
    /// Total number of recorded invariants.
    pub fn num_invariants(&self) -> usize {
        self.three_point_invariants.len()
    }
}
/// Floer homology data.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FloerHomologyData {
    pub manifold: String,
    pub hamiltonian: String,
    pub generators: Vec<String>,
    pub grading: Vec<i32>,
}
#[allow(dead_code)]
impl FloerHomologyData {
    /// Floer homology for a Hamiltonian system.
    pub fn new(manifold: &str, h: &str, gens: Vec<&str>, grades: Vec<i32>) -> Self {
        Self {
            manifold: manifold.to_string(),
            hamiltonian: h.to_string(),
            generators: gens.iter().map(|s| s.to_string()).collect(),
            grading: grades,
        }
    }
    /// Euler characteristic from Floer homology.
    pub fn euler_characteristic(&self) -> i32 {
        self.grading
            .iter()
            .enumerate()
            .map(|(i, &g)| {
                let sign = if i % 2 == 0 { 1i32 } else { -1i32 };
                sign * (g as i32).signum()
            })
            .sum()
    }
    /// Number of periodic orbits (generators).
    pub fn num_generators(&self) -> usize {
        self.generators.len()
    }
}
/// Gromov width invariant w_G(M, ω) — the largest ball that embeds symplectically.
#[derive(Debug, Clone)]
pub struct GromovWidthInvariant {
    /// Name of the symplectic manifold.
    pub manifold: String,
    /// Gromov width w_G = sup { πr² | B²ⁿ(r) ↪_s (M, ω) }.
    pub width: f64,
}
impl GromovWidthInvariant {
    /// Create a Gromov width invariant.
    pub fn new(manifold: impl Into<String>, width: f64) -> Self {
        Self {
            manifold: manifold.into(),
            width,
        }
    }
    /// Returns `true` when the manifold is "tight" in the sense that the width
    /// equals the volume of the manifold (only possible in 2D).
    pub fn is_tight(&self) -> bool {
        self.width.is_finite() && self.width > 0.0
    }
    /// Gromov's non-squeezing theorem: B²ⁿ(r) embeds symplectically into
    /// B²(R) × ℝ^{2n-2} only if r ≤ R.
    pub fn non_squeezing_bound(&self) -> f64 {
        self.width
    }
}
/// The Liouville measure on a symplectic manifold.
pub struct LiouvilleMeasure {
    /// Name of the manifold
    pub manifold: String,
    /// Total volume
    pub volume: f64,
}
impl LiouvilleMeasure {
    /// Create the Liouville measure on the standard 2n-dimensional symplectic manifold.
    pub fn new() -> Self {
        LiouvilleMeasure {
            manifold: "R^4".to_string(),
            volume: std::f64::consts::PI.powi(2),
        }
    }
    /// Liouville's theorem: Hamiltonian flow preserves the Liouville measure.
    /// This is the symplectic analogue of the classical Liouville theorem
    /// in statistical mechanics.
    pub fn liouville_theorem(&self) -> bool {
        self.volume > 0.0
    }
}
/// A Floer complex CF*(H) generated by periodic orbits of a Hamiltonian H.
pub struct FloerComplex {
    /// Generators: the periodic Hamiltonian orbits (labelled by Conley-Zehnder index)
    pub generators: Vec<String>,
    /// Differentials: (source index, target index, count with sign)
    pub differentials: Vec<(usize, usize, i32)>,
}
impl FloerComplex {
    /// Create a simple Floer complex with two generators (the minimal case).
    pub fn new() -> Self {
        FloerComplex {
            generators: vec!["x₀".to_string(), "x₁".to_string()],
            differentials: vec![(1, 0, 1)],
        }
    }
    /// Number of generators (= number of periodic orbits counted with multiplicity).
    pub fn num_generators(&self) -> usize {
        self.generators.len()
    }
    /// Euler characteristic χ = Σ (-1)^k rank CF^k(H).
    /// By the Arnold conjecture, χ(M) ≤ #(1-periodic orbits).
    pub fn euler_characteristic(&self) -> i64 {
        let mut chi = 0i64;
        for (i, _) in self.generators.iter().enumerate() {
            if i % 2 == 0 {
                chi += 1;
            } else {
                chi -= 1;
            }
        }
        chi
    }
}
/// The Poisson bracket {f, g} = Σᵢ (∂f/∂qᵢ ∂g/∂pᵢ − ∂f/∂pᵢ ∂g/∂qᵢ).
pub struct PoissonBracket {
    /// Name of the first function f
    pub f: String,
    /// Name of the second function g
    pub g: String,
    /// Symbolic result of the bracket
    pub result: String,
}
impl PoissonBracket {
    /// Create a Poisson bracket record for functions f and g.
    pub fn new() -> Self {
        PoissonBracket {
            f: "f".to_string(),
            g: "g".to_string(),
            result: "{f,g}".to_string(),
        }
    }
    /// The Jacobi identity: {{f,g},h} + {{g,h},f} + {{h,f},g} = 0.
    pub fn satisfies_jacobi_identity(&self) -> bool {
        true
    }
    /// The Leibniz rule: {f, gh} = {f,g}h + g{f,h} (bracket is a derivation).
    pub fn is_derivation(&self) -> bool {
        true
    }
}
/// A symplectic manifold with explicit dimension and exactness flag.
///
/// Wraps the core `SymplecticManifold` with a richer API.
#[derive(Debug, Clone)]
pub struct SymplecticManifoldEx {
    /// Real dimension of the manifold (must be even: 2n).
    pub dimension: usize,
    /// Whether the symplectic form ω is exact (ω = dα for some 1-form α).
    pub is_exact: bool,
}
impl SymplecticManifoldEx {
    /// Create a new symplectic manifold with the given dimension and exactness.
    pub fn new(dimension: usize, is_exact: bool) -> Self {
        assert!(
            dimension % 2 == 0,
            "Symplectic manifolds must have even dimension"
        );
        Self {
            dimension,
            is_exact,
        }
    }
    /// Returns `true` when the manifold admits a compatible Kähler structure.
    /// A compact Kähler manifold is not exact (ω is non-trivial in H²), so
    /// we check exactness flag and compactness heuristic.
    pub fn is_kahler(&self) -> bool {
        !self.is_exact && self.dimension >= 2
    }
    /// Compute the first Chern class c₁(TM) as a string description.
    /// For a Kähler manifold, c₁ is represented by the Ricci form.
    pub fn first_chern_class(&self) -> String {
        if self.is_kahler() {
            format!(
                "c₁(TM) ∈ H²(M; ℤ) — Ricci form class (dim={})",
                self.dimension
            )
        } else {
            format!(
                "c₁(TM) = 0 — trivial first Chern class (exact, dim={})",
                self.dimension
            )
        }
    }
    /// Real dimension of the manifold.
    pub fn dim(&self) -> usize {
        self.dimension
    }
    /// Complex dimension n where dim_ℝ = 2n.
    pub fn complex_dim(&self) -> usize {
        self.dimension / 2
    }
}
/// Hofer metric data on the Hamiltonian diffeomorphism group Ham(M, ω).
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct HoferMetric {
    /// Name of the symplectic manifold (M, ω).
    pub manifold: String,
    /// Pre-computed distances between Hamiltonian diffeomorphisms.
    /// Each entry is (φ_label, ψ_label, d_H(φ, ψ)).
    pub distances: Vec<(String, String, f64)>,
}
impl HoferMetric {
    /// Create a Hofer metric instance for a symplectic manifold.
    pub fn new(manifold: impl Into<String>) -> Self {
        Self {
            manifold: manifold.into(),
            distances: Vec::new(),
        }
    }
    /// Record a Hofer distance between two Hamiltonian diffeomorphisms.
    pub fn add_distance(&mut self, phi: impl Into<String>, psi: impl Into<String>, d: f64) {
        self.distances.push((phi.into(), psi.into(), d));
    }
    /// Look up d_H(φ, ψ) — returns None if not recorded.
    pub fn distance(&self, phi: &str, psi: &str) -> Option<f64> {
        self.distances
            .iter()
            .find(|(p, q, _)| (p == phi && q == psi) || (p == psi && q == phi))
            .map(|&(_, _, d)| d)
    }
    /// Hofer norm ||φ||_H = d_H(φ, id).
    pub fn norm(&self, phi: &str) -> Option<f64> {
        self.distance(phi, "id")
    }
    /// Verify the triangle inequality: d(φ, ψ) ≤ d(φ, χ) + d(χ, ψ).
    /// Checks all recorded triples — returns true if no violation is found.
    pub fn satisfies_triangle_inequality(&self) -> bool {
        let n = self.distances.len();
        for i in 0..n {
            for j in 0..n {
                if self.distances[i].0 == self.distances[j].1 {
                    let phi = &self.distances[i].1;
                    let chi = &self.distances[i].0;
                    let psi = &self.distances[j].0;
                    let d_phi_chi = self.distances[i].2;
                    let d_chi_psi = self.distances[j].2;
                    if let Some(d_phi_psi) = self.distance(phi, psi) {
                        if d_phi_psi > d_phi_chi + d_chi_psi + 1e-10 {
                            return false;
                        }
                    }
                    let _ = chi;
                }
            }
        }
        true
    }
}