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

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

use super::types::{
    CaccioppoliSet, CoAreaComputer, CompactnessTheorem, DiscreteBVFunction, DiscreteDensityRatio,
    DiscreteSet2D, HausdorffContentEstimate, HausdorffMeasureEstimator, IntegralCurrent,
    IntegralCurrentNew, MarstrandProjection, MinimalSurfaceRelaxation, PerimeterApprox,
    PiecewiseLinearMap, PlateauProblem, RectifiabilityChecker, RectifiableSet,
};

pub fn app(f: Expr, a: Expr) -> Expr {
    Expr::App(Box::new(f), Box::new(a))
}
pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
    app(app(f, a), b)
}
pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
    app(app2(f, a, b), c)
}
pub fn cst(s: &str) -> Expr {
    Expr::Const(Name::str(s), vec![])
}
pub fn prop() -> Expr {
    Expr::Sort(Level::zero())
}
pub fn type0() -> Expr {
    Expr::Sort(Level::succ(Level::zero()))
}
pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
    Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
}
pub fn arrow(a: Expr, b: Expr) -> Expr {
    pi(BinderInfo::Default, "_", a, b)
}
pub fn bvar(n: u32) -> Expr {
    Expr::BVar(n)
}
pub fn nat_ty() -> Expr {
    cst("Nat")
}
pub fn real_ty() -> Expr {
    cst("Real")
}
pub fn bool_ty() -> Expr {
    cst("Bool")
}
pub fn list_ty(elem: Expr) -> Expr {
    app(cst("List"), elem)
}
/// `HausdorffMeasure : (s : Real) → (n : Nat) → Type`
///
/// The s-dimensional Hausdorff measure on ℝⁿ.
/// H^s(E) = lim_{δ→0} inf { Σ diam(Eᵢ)^s : E ⊆ ⋃Eᵢ, diam(Eᵢ) < δ }
pub fn hausdorff_measure_ty() -> Expr {
    arrow(real_ty(), arrow(nat_ty(), type0()))
}
/// `HausdorffDimension : (E : Set ℝⁿ) → Real`
///
/// The Hausdorff dimension of a set E: inf { s : H^s(E) = 0 }.
pub fn hausdorff_dimension_ty() -> Expr {
    arrow(arrow(nat_ty(), bool_ty()), real_ty())
}
/// `RectifiableSet : (k n : Nat) → Set ℝⁿ → Prop`
///
/// A k-rectifiable set: H^k-almost covered by countably many Lipschitz images of ℝᵏ.
pub fn rectifiable_set_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(arrow(nat_ty(), bool_ty()), prop()),
        ),
    )
}
/// `CountablyRectifiable : (k n : Nat) → Set ℝⁿ → Prop`
///
/// A countably k-rectifiable set: contained in a countable union of k-rectifiable sets.
pub fn countably_rectifiable_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        arrow(nat_ty(), arrow(arrow(nat_ty(), bool_ty()), prop())),
    )
}
/// `LipschitzMap : (m n : Nat) → Type`
///
/// A Lipschitz map f : ℝᵐ → ℝⁿ with Lipschitz constant Lip(f) < ∞.
pub fn lipschitz_map_ty() -> Expr {
    arrow(nat_ty(), arrow(nat_ty(), type0()))
}
/// `Varifold : (k n : Nat) → Type`
///
/// A k-varifold in ℝⁿ: a Radon measure on ℝⁿ × G(n,k) where G(n,k) is the
/// Grassmannian of k-planes in ℝⁿ.
pub fn varifold_ty() -> Expr {
    arrow(nat_ty(), arrow(nat_ty(), type0()))
}
/// `IntegralVarifold : (k n : Nat) → Varifold k n → Prop`
///
/// An integral varifold: a varifold arising from a rectifiable set with integer
/// multiplicities, carrying the tangent plane information.
pub fn integral_varifold_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Varifold"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `FirstVariationVarifold : (k n : Nat) → Varifold k n → Type`
///
/// The first variation δV of a varifold V: a vector-valued Radon measure encoding
/// how the weight measure changes under smooth deformations.
pub fn first_variation_varifold_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Varifold"), bvar(1), bvar(0)), type0()),
        ),
    )
}
/// `StationaryVarifold : (k n : Nat) → Varifold k n → Prop`
///
/// A stationary varifold: one with vanishing first variation δV = 0.
/// Stationary integral varifolds generalize minimal surfaces.
pub fn stationary_varifold_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Varifold"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `AllardRegularity : (V : IntegralVarifold k n) → Prop`
///
/// Allard's regularity theorem: if V is a stationary integral varifold with
/// unit density at a point, then V is smooth near that point.
pub fn allard_regularity_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("IntegralVarifold"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `Current : (k n : Nat) → Type`
///
/// A k-current in ℝⁿ: a continuous linear functional on the space of smooth
/// compactly supported k-forms. Generalizes oriented surfaces.
pub fn current_ty() -> Expr {
    arrow(nat_ty(), arrow(nat_ty(), type0()))
}
/// `BoundaryCurrent : (k n : Nat) → Current k n → Current (k-1) n`
///
/// The boundary operator ∂ on currents, satisfying ∂∘∂ = 0.
pub fn boundary_current_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("Current"), bvar(1), bvar(0)),
                app2(cst("Current"), bvar(2), bvar(1)),
            ),
        ),
    )
}
/// `RectifiableCurrent : (k n : Nat) → Current k n → Prop`
///
/// A rectifiable current: one representable as integration over an oriented
/// rectifiable set with integer multiplicities.
pub fn rectifiable_current_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Current"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `IntegralCurrent : (k n : Nat) → Current k n → Prop`
///
/// An integral current: a rectifiable current with rectifiable boundary.
pub fn integral_current_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Current"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `MassNorm : (k n : Nat) → Current k n → Real`
///
/// The mass norm M(T) of a current T: the total variation / weighted area.
pub fn mass_norm_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Current"), bvar(1), bvar(0)), real_ty()),
        ),
    )
}
/// `FlatNorm : (k n : Nat) → Current k n → Real`
///
/// The flat norm F(T) = inf { M(T - ∂S) + M(S) : S is a (k+1)-current }.
pub fn flat_norm_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Current"), bvar(1), bvar(0)), real_ty()),
        ),
    )
}
/// `FedererFlemingCompactness : Prop`
///
/// Federer-Fleming compactness theorem: a sequence of integral k-currents
/// with uniformly bounded mass and flat norm has a weakly convergent subsequence.
pub fn federer_fleming_compactness_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                arrow(nat_ty(), app2(cst("IntegralCurrent"), bvar(1), bvar(0))),
                prop(),
            ),
        ),
    )
}
/// `PlateauProblem : (k n : Nat) → Current (k-1) n → Prop`
///
/// The Plateau problem: existence of an area-minimizing integral current
/// with prescribed boundary Γ.
pub fn plateau_problem_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("IntegralCurrent"), bvar(2), bvar(1)), prop()),
        ),
    )
}
/// `AreaMinimizingCurrent : (k n : Nat) → Current k n → Prop`
///
/// An area-minimizing current: one with minimal mass among currents with the
/// same boundary.
pub fn area_minimizing_current_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Current"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `AreaFormula : (m n : Nat) → (f : LipschitzMap m n) → Prop`
///
/// Area formula: ∫_{ℝⁿ} N(f, y) dH^m(y) = ∫_{ℝᵐ} Jf(x) dH^m(x)
/// where N(f,y) = #f⁻¹(y) and Jf is the m-dimensional Jacobian.
pub fn area_formula_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "m",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("LipschitzMap"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `CoareaFormula : (m k n : Nat) → (f : LipschitzMap n k) → Prop`
///
/// Coarea formula (Federer): ∫_{ℝⁿ} g(x)|Jₖf(x)| dL^n(x) = ∫_{ℝᵏ} (∫_{f⁻¹(y)} g dH^{n-k}) dL^k(y)
pub fn coarea_formula_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "k",
            nat_ty(),
            arrow(app2(cst("LipschitzMap"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `Jacobian : (m n : Nat) → LipschitzMap m n → ℝⁿ → Real`
///
/// The m-dimensional Jacobian of a Lipschitz map f : ℝᵐ → ℝⁿ at a point x.
pub fn jacobian_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "m",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("LipschitzMap"), bvar(1), bvar(0)),
                arrow(list_ty(real_ty()), real_ty()),
            ),
        ),
    )
}
/// `BVFunction : (n : Nat) → Type`
///
/// A function of bounded variation on ℝⁿ: f ∈ L¹ with distributional gradient
/// Df being a vector-valued Radon measure with finite total variation |Df|(ℝⁿ) < ∞.
pub fn bv_function_ty() -> Expr {
    arrow(nat_ty(), type0())
}
/// `TotalVariation : (n : Nat) → BVFunction n → Real`
///
/// The total variation |Df|(ℝⁿ) of a BV function f.
pub fn total_variation_ty() -> Expr {
    arrow(nat_ty(), arrow(app(cst("BVFunction"), nat_ty()), real_ty()))
}
/// `SetFinitePerimeter : (n : Nat) → Set ℝⁿ → Prop`
///
/// A set of finite perimeter (Caccioppoli set): the characteristic function 1_E is BV.
/// Equivalently, the distributional divergence of 1_E is a finite measure.
pub fn set_finite_perimeter_ty() -> Expr {
    arrow(nat_ty(), arrow(arrow(nat_ty(), bool_ty()), prop()))
}
/// `ReducedBoundary : (n : Nat) → SetFinitePerimeter n → Set ℝⁿ`
///
/// The reduced boundary ∂*E of a set of finite perimeter E.
pub fn reduced_boundary_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(
            app(cst("SetFinitePerimeter"), bvar(0)),
            arrow(nat_ty(), bool_ty()),
        ),
    )
}
/// `DeGiorgiStructureTheorem : (n : Nat) → SetFinitePerimeter n → Prop`
///
/// De Giorgi's structure theorem: the reduced boundary ∂*E of a set of finite perimeter
/// is an (n-1)-rectifiable set with H^{n-1}(∂*E) = Per(E).
pub fn de_giorgi_structure_theorem_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(app(cst("SetFinitePerimeter"), bvar(0)), prop()),
    )
}
/// `IsoperimetricInequality : (n : Nat) → Prop`
///
/// Classical isoperimetric inequality: Per(E)^n ≥ n^n ω_n |E|^{n-1}
/// with equality iff E is a ball. Here ω_n = volume of unit ball in ℝⁿ.
pub fn isoperimetric_inequality_ty() -> Expr {
    arrow(nat_ty(), prop())
}
/// `QuantitativeIsoperimetric : (n : Nat) → Prop`
///
/// Quantitative isoperimetric inequality (Fusco-Maggi-Pratelli):
/// Per(E) - Per(B) ≥ c_n |E|^{(n-1)/n} A(E)²
/// where A(E) is the Fraenkel asymmetry.
pub fn quantitative_isoperimetric_ty() -> Expr {
    arrow(nat_ty(), prop())
}
/// `MonotonicityFormula : (k n : Nat) → StationaryVarifold k n → Prop`
///
/// Monotonicity formula for stationary varifolds: the density ratio
/// θ^k(V, x, r) = M(V ⌞ B(x,r)) / (ω_k r^k) is monotone nondecreasing in r.
pub fn monotonicity_formula_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("StationaryVarifold"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `DensityFunction : (k n : Nat) → Varifold k n → ℝⁿ → Real`
///
/// The k-density Θ^k(V, x) = lim_{r→0} M(V ⌞ B(x,r)) / (ω_k r^k).
pub fn density_function_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("Varifold"), bvar(1), bvar(0)),
                arrow(list_ty(real_ty()), real_ty()),
            ),
        ),
    )
}
/// `MinimalSurface : (k n : Nat) → Type`
///
/// A minimal surface: a k-dimensional submanifold of ℝⁿ with vanishing mean curvature,
/// equivalently a stationary varifold that is also a smooth manifold away from singularities.
pub fn minimal_surface_ty() -> Expr {
    arrow(nat_ty(), arrow(nat_ty(), type0()))
}
/// `BernsteinTheorem : Prop`
///
/// Bernstein's theorem: an entire minimal graph over ℝⁿ for n ≤ 7 must be a hyperplane.
pub fn bernstein_theorem_ty() -> Expr {
    prop()
}
/// `SimonsConjecture : Prop`
///
/// Simons' theorem: stable minimal hypersurfaces in ℝⁿ for n ≤ 7 are hyperplanes.
pub fn simons_cone_ty() -> Expr {
    prop()
}
/// `BVCompactness : (n : Nat) → Prop`
///
/// BV compactness theorem: a bounded sequence in BV(Ω) has a subsequence
/// converging strongly in L¹(Ω).
pub fn bv_compactness_ty() -> Expr {
    arrow(nat_ty(), prop())
}
/// `SlicingTheorem : (k n : Nat) → IntegralCurrent k n → Prop`
///
/// Slicing theorem for integral currents: the slices ⟨T, f, y⟩ of an integral
/// current by a Lipschitz function f are integral (k-m)-currents for a.e. y.
pub fn slicing_theorem_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("IntegralCurrent"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `PushforwardCurrent : (k m n : Nat) → LipschitzMap m n → Current k m → Current k n`
///
/// Pushforward f_♯T of a current T by a Lipschitz map f.
pub fn pushforward_current_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "m",
            nat_ty(),
            pi(
                BinderInfo::Default,
                "n",
                nat_ty(),
                arrow(
                    app2(cst("LipschitzMap"), bvar(1), bvar(0)),
                    arrow(
                        app2(cst("Current"), bvar(3), bvar(2)),
                        app2(cst("Current"), bvar(4), bvar(1)),
                    ),
                ),
            ),
        ),
    )
}
/// `PurelyUnrectifiable : (k n : Nat) → Set ℝⁿ → Prop`
///
/// A purely k-unrectifiable set: one that intersects every k-rectifiable set
/// in a set of H^k measure zero.
pub fn purely_unrectifiable_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(arrow(nat_ty(), bool_ty()), prop()),
        ),
    )
}
/// `HausdorffNRectifiable : (k n : Nat) → Set ℝⁿ → Prop`
///
/// A set E ⊆ ℝⁿ is H^k-n-rectifiable if H^k(E) < ∞ and E is k-rectifiable.
pub fn hausdorff_n_rectifiable_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(arrow(nat_ty(), bool_ty()), prop()),
        ),
    )
}
/// `TangentMeasureUniqueness : (k n : Nat) → Prop`
///
/// Marstrand–Mattila rectifiability criterion: E is k-rectifiable iff
/// the tangent measure at H^k-almost every point is a flat k-measure.
pub fn tangent_measure_uniqueness_ty() -> Expr {
    pi(BinderInfo::Default, "k", nat_ty(), arrow(nat_ty(), prop()))
}
/// `MarstrandDensityTheorem : (s n : Nat) → Prop`
///
/// Marstrand density theorem: if H^s(E) > 0 then the s-density
/// Θ^s(E, x) ∈ \[2^{-s}, 1\] for H^s-a.e. x ∈ E.
pub fn marstrand_density_theorem_ty() -> Expr {
    pi(BinderInfo::Default, "s", nat_ty(), arrow(nat_ty(), prop()))
}
/// `GeneralizedMeanCurvature : (k n : Nat) → IntegralVarifold k n → Type`
///
/// The generalized mean curvature vector H of an integral varifold V:
/// the Radon-Nikodym derivative dδV/d‖V‖.
pub fn generalized_mean_curvature_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("IntegralVarifold"), bvar(1), bvar(0)), type0()),
        ),
    )
}
/// `AllardBoundaryRegularity : (k n : Nat) → IntegralVarifold k n → Prop`
///
/// Allard's boundary regularity theorem: an integral varifold with bounded
/// generalized mean curvature is C^{1,α} near the boundary in appropriate sense.
pub fn allard_boundary_regularity_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("IntegralVarifold"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `AlmgrenFrequencyFunction : (k n : Nat) → IntegralVarifold k n → Real → Real`
///
/// Almgren's frequency function N(x, r) = r∫|∇u|² / ∫u² on B(x,r).
/// The key monotonicity tool in Almgren's Big Regularity Paper.
pub fn almgren_frequency_function_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("IntegralVarifold"), bvar(1), bvar(0)),
                arrow(real_ty(), real_ty()),
            ),
        ),
    )
}
/// `AlmgrenRegularity : (k n : Nat) → AreaMinimizingCurrent k n → Prop`
///
/// Almgren's regularity theorem (Big Regularity Paper):
/// area-minimizing currents in ℝⁿ are regular outside a singular set
/// of Hausdorff dimension at most k-2.
pub fn almgren_regularity_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("AreaMinimizingCurrent"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `UniqueContinuationPrinciple : (k n : Nat) → Prop`
///
/// Unique continuation for the frequency function:
/// if N(x, r) = 0 for some r > 0, then u ≡ 0 near x.
pub fn unique_continuation_principle_ty() -> Expr {
    pi(BinderInfo::Default, "k", nat_ty(), arrow(nat_ty(), prop()))
}
/// `NormalCurrent : (k n : Nat) → Current k n → Prop`
///
/// A normal current: finite mass and finite boundary mass (M(T) + M(∂T) < ∞).
pub fn normal_current_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("Current"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `IntegralFlatChain : (k n : Nat) → Type`
///
/// An integral flat chain: equivalence class of integral currents under
/// the flat norm topology, used for homological methods in GMT.
pub fn integral_flat_chain_ty() -> Expr {
    arrow(nat_ty(), arrow(nat_ty(), type0()))
}
/// `FlatChainHomotopy : (k n : Nat) → IntegralFlatChain k n → IntegralFlatChain k n → Prop`
///
/// Homotopy of flat chains: two flat chains are homotopic iff their difference
/// is the boundary of a flat chain.
pub fn flat_chain_homotopy_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("IntegralFlatChain"), bvar(1), bvar(0)),
                arrow(app2(cst("IntegralFlatChain"), bvar(2), bvar(1)), prop()),
            ),
        ),
    )
}
/// `DeformationTheorem : (k n : Nat) → NormalCurrent k n → Prop`
///
/// Federer's deformation theorem: every normal current can be deformed into
/// a polyhedral chain with controlled mass.
pub fn deformation_theorem_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("NormalCurrent"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `KirszbraunExtension : (m n : Nat) → LipschitzMap m n → Prop`
///
/// Kirszbraun's theorem: any Lipschitz map f : S → ℝⁿ (S ⊆ ℝᵐ) extends
/// to a Lipschitz map F : ℝᵐ → ℝⁿ with the same Lipschitz constant.
pub fn kirszbraun_extension_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "m",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("LipschitzMap"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `McShaneExtension : (n : Nat) → (f : Set ℝⁿ → Real) → Prop`
///
/// McShane's extension theorem: any real-valued Lipschitz function on a subset
/// of a metric space extends to the whole space with the same Lipschitz constant.
pub fn mcshane_extension_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(arrow(arrow(nat_ty(), bool_ty()), real_ty()), prop()),
    )
}
/// `RademacherTheorem : (m n : Nat) → LipschitzMap m n → Prop`
///
/// Rademacher's theorem: any Lipschitz map f : ℝᵐ → ℝⁿ is differentiable
/// at L^m-almost every point.
pub fn rademacher_theorem_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "m",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("LipschitzMap"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `LipschitzDifferential : (m n : Nat) → LipschitzMap m n → ℝᵐ → Type`
///
/// The differential df(x) of a Lipschitz map at an a.e.-differentiability point x.
pub fn lipschitz_differential_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "m",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("LipschitzMap"), bvar(1), bvar(0)),
                arrow(list_ty(real_ty()), type0()),
            ),
        ),
    )
}
/// `GammaConvergence : (n : Nat) → (F : Nat → BVFunction n → Real) → Prop`
///
/// Γ-convergence of a sequence of functionals F_ε to a limit functional F₀:
/// combines lower semicontinuity (lim inf) and recovery sequence (lim sup) conditions.
pub fn gamma_convergence_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(
            arrow(nat_ty(), arrow(app(cst("BVFunction"), bvar(0)), real_ty())),
            prop(),
        ),
    )
}
/// `AllenCahnFunctional : (n : Nat) → BVFunction n → Real → Real`
///
/// The Allen-Cahn functional E_ε(u) = ∫ (ε|∇u|² + W(u)/ε) dx,
/// which Γ-converges as ε→0 to a perimeter functional (σ Per(E)).
pub fn allen_cahn_functional_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(app(cst("BVFunction"), bvar(0)), arrow(real_ty(), real_ty())),
    )
}
/// `AllenCahnGammaLimit : (n : Nat) → Prop`
///
/// Modica-Mortola theorem: the Allen-Cahn functionals E_ε Γ-converge to
/// the perimeter functional (up to a factor σ = ∫W^{1/2}).
pub fn allen_cahn_gamma_limit_ty() -> Expr {
    arrow(nat_ty(), prop())
}
/// `MumfordShahFunctional : (n : Nat) → BVFunction n → Real`
///
/// The Mumford-Shah functional MS(u, K) = ∫_{Ω\K} |∇u|² + H^{n-1}(K).
/// A free-discontinuity functional in image segmentation.
pub fn mumford_shah_functional_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(app(cst("BVFunction"), bvar(0)), real_ty()),
    )
}
/// `BrakkeFlow : (k n : Nat) → Type`
///
/// A Brakke k-flow in ℝⁿ: a one-parameter family of integral varifolds
/// V(t) satisfying Brakke's inequality (weak formulation of mean curvature flow).
pub fn brakke_flow_ty() -> Expr {
    arrow(nat_ty(), arrow(nat_ty(), type0()))
}
/// `BrakkeInequality : (k n : Nat) → BrakkeFlow k n → Prop`
///
/// Brakke's inequality: d/dt ‖V(t)‖(φ) ≤ ∫(-H²φ + ∇φ·H) d‖V(t)‖
/// for all non-negative test functions φ.
pub fn brakke_inequality_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("BrakkeFlow"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `BrakkeExistence : (k n : Nat) → Prop`
///
/// Brakke's existence theorem: for any initial integral varifold V₀,
/// there exists a Brakke flow V(t) with V(0) = V₀.
pub fn brakke_existence_ty() -> Expr {
    pi(BinderInfo::Default, "k", nat_ty(), arrow(nat_ty(), prop()))
}
/// `HuiskenMonotonicity : (k n : Nat) → BrakkeFlow k n → Prop`
///
/// Huisken's monotonicity formula for mean curvature flow:
/// the Gaussian weighted area ∫ ρ_{x₀,t₀} d‖V(t)‖ is monotone nonincreasing.
pub fn huisken_monotonicity_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("BrakkeFlow"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `TangentCone : (k n : Nat) → MinimalSurface k n → ℝⁿ → Type`
///
/// The tangent cone C_x M at a point x of a minimal surface M:
/// the limit of blow-ups M_r = (M - x)/r as r → 0.
pub fn tangent_cone_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("MinimalSurface"), bvar(1), bvar(0)),
                arrow(list_ty(real_ty()), type0()),
            ),
        ),
    )
}
/// `SingularSetMinimal : (k n : Nat) → MinimalSurface k n → Set ℝⁿ`
///
/// The singular set Sing(M) of a minimal surface: points where M fails to be
/// a smooth submanifold.
pub fn singular_set_minimal_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(
                app2(cst("MinimalSurface"), bvar(1), bvar(0)),
                arrow(nat_ty(), bool_ty()),
            ),
        ),
    )
}
/// `StableMinimalHypersurface : (n : Nat) → MinimalSurface (n - 1) n → Prop`
///
/// A stable minimal hypersurface: one where the second variation of area
/// is non-negative for all compactly supported variations.
pub fn stable_minimal_hypersurface_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(app2(cst("MinimalSurface"), bvar(0), bvar(0)), prop()),
    )
}
/// `SecondFundamentalForm : (k n : Nat) → MinimalSurface k n → Type`
///
/// The second fundamental form A of a minimal surface: the tensor measuring
/// how the surface curves in the ambient space.
pub fn second_fundamental_form_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("MinimalSurface"), bvar(1), bvar(0)), type0()),
        ),
    )
}
/// `SchoenSimonYauEstimate : (n : Nat) → StableMinimalHypersurface n → Prop`
///
/// Schoen-Simon-Yau curvature estimate: for stable minimal hypersurfaces in ℝⁿ (n ≤ 6),
/// |A|² ≤ C/r² on B_r.
pub fn schoen_simon_yau_estimate_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(app(cst("StableMinimalHypersurface"), bvar(0)), prop()),
    )
}
/// `ExcessDecay : (k n : Nat) → IntegralVarifold k n → Prop`
///
/// Allard's excess decay lemma: the L²-excess E(V, B_r) = ∫_{B_r} sin²θ d‖V‖
/// decays like r^α as r → 0 when V is stationary and has small excess.
pub fn excess_decay_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "k",
        nat_ty(),
        pi(
            BinderInfo::Default,
            "n",
            nat_ty(),
            arrow(app2(cst("IntegralVarifold"), bvar(1), bvar(0)), prop()),
        ),
    )
}
/// `GaussBonnetFormula : (n : Nat) → MinimalSurface n n → Prop`
///
/// Gauss-Bonnet formula: ∫_M K dA = 2π χ(M) relating Gaussian curvature
/// to Euler characteristic for compact surfaces.
pub fn gauss_bonnet_formula_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(app2(cst("MinimalSurface"), bvar(0), bvar(0)), prop()),
    )
}
/// `WillmoreEnergy : (n : Nat) → MinimalSurface 2 n → Real`
///
/// The Willmore energy W(Σ) = ∫_Σ H² dA of a 2-surface Σ ⊆ ℝⁿ,
/// conformally invariant and minimized by round spheres.
pub fn willmore_energy_ty() -> Expr {
    pi(
        BinderInfo::Default,
        "n",
        nat_ty(),
        arrow(app2(cst("MinimalSurface"), nat_ty(), bvar(0)), real_ty()),
    )
}
/// Build the geometric measure theory kernel environment with all axiom declarations.
pub fn build_geometric_measure_theory_env(env: &mut Environment) {
    let axioms: &[(&str, Expr)] = &[
        ("HausdorffMeasure", hausdorff_measure_ty()),
        ("HausdorffDimension", hausdorff_dimension_ty()),
        ("RectifiableSet", rectifiable_set_ty()),
        ("CountablyRectifiable", countably_rectifiable_ty()),
        ("LipschitzMap", lipschitz_map_ty()),
        ("Varifold", varifold_ty()),
        ("IntegralVarifold", integral_varifold_ty()),
        ("FirstVariationVarifold", first_variation_varifold_ty()),
        ("StationaryVarifold", stationary_varifold_ty()),
        ("AllardRegularity", allard_regularity_ty()),
        ("Current", current_ty()),
        ("BoundaryCurrent", boundary_current_ty()),
        ("RectifiableCurrent", rectifiable_current_ty()),
        ("IntegralCurrent", integral_current_ty()),
        ("MassNorm", mass_norm_ty()),
        ("FlatNorm", flat_norm_ty()),
        (
            "FedererFlemingCompactness",
            federer_fleming_compactness_ty(),
        ),
        ("PlateauProblem", plateau_problem_ty()),
        ("AreaMinimizingCurrent", area_minimizing_current_ty()),
        ("AreaFormula", area_formula_ty()),
        ("CoareaFormula", coarea_formula_ty()),
        ("Jacobian", jacobian_ty()),
        ("BVFunction", bv_function_ty()),
        ("TotalVariation", total_variation_ty()),
        ("SetFinitePerimeter", set_finite_perimeter_ty()),
        ("ReducedBoundary", reduced_boundary_ty()),
        ("DeGiorgiStructureTheorem", de_giorgi_structure_theorem_ty()),
        ("IsoperimetricInequality", isoperimetric_inequality_ty()),
        ("QuantitativeIsoperimetric", quantitative_isoperimetric_ty()),
        ("MonotonicityFormula", monotonicity_formula_ty()),
        ("DensityFunction", density_function_ty()),
        ("MinimalSurface", minimal_surface_ty()),
        ("BernsteinTheorem", bernstein_theorem_ty()),
        ("SimonsCone", simons_cone_ty()),
        ("BVCompactness", bv_compactness_ty()),
        ("SlicingTheorem", slicing_theorem_ty()),
        ("PushforwardCurrent", pushforward_current_ty()),
        ("PurelyUnrectifiable", purely_unrectifiable_ty()),
        ("HausdorffNRectifiable", hausdorff_n_rectifiable_ty()),
        ("TangentMeasureUniqueness", tangent_measure_uniqueness_ty()),
        ("MarstrandDensityTheorem", marstrand_density_theorem_ty()),
        ("GeneralizedMeanCurvature", generalized_mean_curvature_ty()),
        ("AllardBoundaryRegularity", allard_boundary_regularity_ty()),
        ("AlmgrenFrequencyFunction", almgren_frequency_function_ty()),
        ("AlmgrenRegularity", almgren_regularity_ty()),
        (
            "UniqueContinuationPrinciple",
            unique_continuation_principle_ty(),
        ),
        ("NormalCurrent", normal_current_ty()),
        ("IntegralFlatChain", integral_flat_chain_ty()),
        ("FlatChainHomotopy", flat_chain_homotopy_ty()),
        ("DeformationTheorem", deformation_theorem_ty()),
        ("KirszbraunExtension", kirszbraun_extension_ty()),
        ("McShaneExtension", mcshane_extension_ty()),
        ("RademacherTheorem", rademacher_theorem_ty()),
        ("LipschitzDifferential", lipschitz_differential_ty()),
        ("GammaConvergence", gamma_convergence_ty()),
        ("AllenCahnFunctional", allen_cahn_functional_ty()),
        ("AllenCahnGammaLimit", allen_cahn_gamma_limit_ty()),
        ("MumfordShahFunctional", mumford_shah_functional_ty()),
        ("BrakkeFlow", brakke_flow_ty()),
        ("BrakkeInequality", brakke_inequality_ty()),
        ("BrakkeExistence", brakke_existence_ty()),
        ("HuiskenMonotonicity", huisken_monotonicity_ty()),
        ("TangentCone", tangent_cone_ty()),
        ("SingularSetMinimal", singular_set_minimal_ty()),
        (
            "StableMinimalHypersurface",
            stable_minimal_hypersurface_ty(),
        ),
        ("SecondFundamentalForm", second_fundamental_form_ty()),
        ("SchoenSimonYauEstimate", schoen_simon_yau_estimate_ty()),
        ("ExcessDecay", excess_decay_ty()),
        ("GaussBonnetFormula", gauss_bonnet_formula_ty()),
        ("WillmoreEnergy", willmore_energy_ty()),
        ("IsRectifiable", arrow(type0(), prop())),
        ("HasFinitePerimeter", arrow(type0(), prop())),
        ("IsAreaMinimizing", arrow(type0(), prop())),
        ("IsMinimalSurface", arrow(type0(), prop())),
        ("IsStableMinimal", arrow(type0(), prop())),
        ("HausdorffMeasurable", arrow(type0(), prop())),
        ("LocallyRectifiable", arrow(type0(), prop())),
        ("TangentPlane", arrow(type0(), arrow(nat_ty(), type0()))),
        ("MeanCurvature", arrow(type0(), arrow(nat_ty(), real_ty()))),
        ("Perimeter", arrow(arrow(nat_ty(), bool_ty()), real_ty())),
        (
            "FraenkelAsymmetry",
            arrow(arrow(nat_ty(), bool_ty()), real_ty()),
        ),
        (
            "GrassmannManifold",
            arrow(nat_ty(), arrow(nat_ty(), type0())),
        ),
        ("TangentMeasure", arrow(type0(), arrow(nat_ty(), type0()))),
        (
            "BoundaryBoundaryZero",
            pi(
                BinderInfo::Default,
                "k",
                nat_ty(),
                pi(
                    BinderInfo::Default,
                    "n",
                    nat_ty(),
                    arrow(app2(cst("Current"), bvar(1), bvar(0)), prop()),
                ),
            ),
        ),
    ];
    for (name, ty) in axioms {
        env.add(Declaration::Axiom {
            name: Name::str(*name),
            univ_params: vec![],
            ty: ty.clone(),
        })
        .ok();
    }
}
#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_hausdorff_content_empty() {
        let est = HausdorffContentEstimate::new(vec![], 0.1, 1.0);
        assert_eq!(est.content(), 0.0);
    }
    #[test]
    fn test_hausdorff_content_collinear() {
        let pts = vec![(0.0, 0.0), (0.25, 0.0), (0.5, 0.0), (0.75, 0.0), (1.0, 0.0)];
        let est = HausdorffContentEstimate::new(pts, 0.3, 1.0);
        let c = est.content();
        assert!(c > 0.0, "Content should be positive, got {}", c);
    }
    #[test]
    fn test_discrete_bv_total_variation() {
        let f = DiscreteBVFunction::new(vec![0.0, 1.0, 0.0, 1.0, 0.0]);
        assert!((f.total_variation() - 4.0).abs() < 1e-10);
        assert!(f.is_bv());
    }
    #[test]
    fn test_discrete_bv_constant() {
        let f = DiscreteBVFunction::new(vec![3.0; 10]);
        assert!((f.total_variation()).abs() < 1e-10);
        assert_eq!(f.distributional_derivative().len(), 9);
    }
    #[test]
    fn test_discrete_set_disk_perimeter() {
        let disk = DiscreteSet2D::disk(10, 4.5, 4.5, 3.0);
        assert!(disk.area() > 0);
        assert!(disk.perimeter() > 0);
        let ratio = disk.isoperimetric_ratio();
        assert!(ratio > 0.0, "Ratio should be positive, got {}", ratio);
    }
    #[test]
    fn test_discrete_set_invalid() {
        let result = DiscreteSet2D::new(3, vec![true; 8]);
        assert!(result.is_none());
    }
    #[test]
    fn test_piecewise_linear_map_identity() {
        let f = PiecewiseLinearMap::new(vec![0.0, 0.25, 0.5, 0.75, 1.0]);
        assert!((f.lipschitz_constant() - 1.0).abs() < 1e-10);
        assert!((f.discrete_area_formula() - 1.0).abs() < 1e-10);
    }
    #[test]
    fn test_density_ratio_monotone() {
        use std::f64::consts::PI;
        let pts: Vec<(f64, f64, f64)> = (0..16)
            .map(|i| {
                let theta = 2.0 * PI * i as f64 / 16.0;
                (theta.cos(), theta.sin(), 1.0)
            })
            .collect();
        let density = DiscreteDensityRatio::new(pts, (0.0, 0.0), 1.0);
        let radii = vec![0.5, 0.8, 1.0, 1.2, 1.5];
        let d05 = density.density_at_radius(0.5);
        let d12 = density.density_at_radius(1.2);
        assert_eq!(d05, 0.0, "No points within r=0.5 of unit circle origin");
        assert!(d12 > 0.0, "Some points within r=1.2, got {}", d12);
        let _ = radii;
    }
    #[test]
    fn test_build_geometric_measure_theory_env() {
        let mut env = Environment::new();
        build_geometric_measure_theory_env(&mut env);
        assert!(!env.is_empty());
    }
    #[test]
    fn test_new_axiom_builders_are_non_trivial() {
        let axioms: Vec<Expr> = vec![
            purely_unrectifiable_ty(),
            hausdorff_n_rectifiable_ty(),
            tangent_measure_uniqueness_ty(),
            marstrand_density_theorem_ty(),
            generalized_mean_curvature_ty(),
            allard_boundary_regularity_ty(),
            almgren_frequency_function_ty(),
            almgren_regularity_ty(),
            unique_continuation_principle_ty(),
            normal_current_ty(),
            integral_flat_chain_ty(),
            flat_chain_homotopy_ty(),
            deformation_theorem_ty(),
            kirszbraun_extension_ty(),
            mcshane_extension_ty(),
            rademacher_theorem_ty(),
            lipschitz_differential_ty(),
            gamma_convergence_ty(),
            allen_cahn_functional_ty(),
            allen_cahn_gamma_limit_ty(),
            mumford_shah_functional_ty(),
            brakke_flow_ty(),
            brakke_inequality_ty(),
            brakke_existence_ty(),
            huisken_monotonicity_ty(),
            tangent_cone_ty(),
            singular_set_minimal_ty(),
            stable_minimal_hypersurface_ty(),
            second_fundamental_form_ty(),
            schoen_simon_yau_estimate_ty(),
            excess_decay_ty(),
            gauss_bonnet_formula_ty(),
            willmore_energy_ty(),
        ];
        assert_eq!(axioms.len(), 33);
        for expr in &axioms {
            if let Expr::BVar(_) = expr {
                panic!("Axiom type must not be a bare BVar")
            }
        }
    }
    #[test]
    fn test_extended_env_has_new_axioms() {
        let mut env = Environment::new();
        build_geometric_measure_theory_env(&mut env);
        let new_names = [
            "PurelyUnrectifiable",
            "RademacherTheorem",
            "KirszbraunExtension",
            "BrakkeFlow",
            "HuiskenMonotonicity",
            "AlmgrenRegularity",
            "GammaConvergence",
            "WillmoreEnergy",
        ];
        for name in &new_names {
            let found = env.get(&Name::str(*name)).is_some();
            assert!(found, "Expected axiom '{}' in environment", name);
        }
    }
    #[test]
    fn test_hausdorff_estimator_empty() {
        let est = HausdorffMeasureEstimator::new(vec![]);
        assert_eq!(est.hausdorff_content(1.0, 0.1), 0.0);
        assert_eq!(est.estimate_dimension(0.1), 0.0);
    }
    #[test]
    fn test_hausdorff_estimator_collinear_points() {
        let pts: Vec<(f64, f64)> = (0..5).map(|i| (i as f64 * 0.25, 0.0)).collect();
        let est = HausdorffMeasureEstimator::new(pts);
        let content = est.hausdorff_content(1.0, 0.3);
        assert!(content > 0.0, "Content at s=1 should be positive");
        let dim = est.estimate_dimension(0.3);
        assert!(dim >= 0.0 && dim <= 2.0, "Dimension out of range: {}", dim);
    }
    #[test]
    fn test_hausdorff_estimator_measure_positive() {
        let pts: Vec<(f64, f64)> = (0..10)
            .flat_map(|i| (0..10).map(move |j| (i as f64 * 0.1, j as f64 * 0.1)))
            .collect();
        let est = HausdorffMeasureEstimator::new(pts);
        let measure = est.estimated_measure(0.15);
        assert!(
            measure > 0.0,
            "Measure should be positive for 2D point grid"
        );
    }
    #[test]
    fn test_perimeter_approx_disk() {
        let n = 20usize;
        let cx = n as f64 / 2.0;
        let r = n as f64 / 4.0;
        let values: Vec<f64> = (0..n)
            .flat_map(|i| {
                (0..n).map(move |j| {
                    let dx = i as f64 - cx;
                    let dy = j as f64 - cx;
                    r - (dx * dx + dy * dy).sqrt()
                })
            })
            .collect();
        let approx = PerimeterApprox::new(n, values).expect("Should construct");
        let vol = approx.volume();
        assert!(vol > 0.0, "Volume should be positive, got {}", vol);
        let perim = approx.perimeter(1.5);
        assert!(perim >= 0.0, "Perimeter should be non-negative");
    }
    #[test]
    fn test_perimeter_approx_invalid_size() {
        let result = PerimeterApprox::new(3, vec![0.0; 8]);
        assert!(result.is_none(), "Should fail if values.len() != n*n");
    }
    #[test]
    fn test_perimeter_approx_isoperimetric_deficit() {
        let n = 20usize;
        let cx = n as f64 / 2.0;
        let r = n as f64 / 4.0;
        let values: Vec<f64> = (0..n)
            .flat_map(|i| {
                (0..n).map(move |j| {
                    let dx = i as f64 - cx;
                    let dy = j as f64 - cx;
                    r - (dx * dx + dy * dy).sqrt()
                })
            })
            .collect();
        let approx = PerimeterApprox::new(n, values).expect("Should construct");
        let deficit = approx.isoperimetric_deficit(1.5);
        assert!(
            deficit >= -1.0,
            "Isoperimetric deficit too negative: {}",
            deficit
        );
    }
    #[test]
    fn test_minimal_surface_flat_boundary() {
        let n = 5usize;
        let boundary = vec![0.0f64; n * n];
        let mut solver =
            MinimalSurfaceRelaxation::new(n, boundary, 0.01).expect("Should construct");
        let area_before = solver.area();
        assert!(area_before > 0.0);
        let area_after = solver.relax(10);
        assert!(area_after > 0.0, "Area should be positive after relaxation");
    }
    #[test]
    fn test_minimal_surface_area_nonincreasing() {
        let n = 6usize;
        let mut boundary = vec![0.0f64; n * n];
        for j in 0..n {
            boundary[j] = 1.0;
            boundary[(n - 1) * n + j] = -1.0;
        }
        let mut solver =
            MinimalSurfaceRelaxation::new(n, boundary, 0.005).expect("Should construct");
        let area0 = solver.area();
        let area1 = solver.relax(5);
        assert!(
            area1 <= area0 * 1.5,
            "Area increased too much: {} -> {}",
            area0,
            area1
        );
    }
    #[test]
    fn test_minimal_surface_invalid_size() {
        let result = MinimalSurfaceRelaxation::new(3, vec![0.0; 8], 0.01);
        assert!(result.is_none());
    }
    #[test]
    fn test_rectifiability_checker_collinear() {
        let pts: Vec<(f64, f64)> = (0..20).map(|i| (i as f64 * 0.05, 0.0)).collect();
        let checker = RectifiabilityChecker::new(pts);
        let ratio = checker.linearity_ratio();
        assert!(
            ratio > 0.95,
            "Collinear points should have ratio > 0.95, got {}",
            ratio
        );
        assert!(checker.is_approximately_rectifiable(0.9));
    }
    #[test]
    fn test_rectifiability_checker_scattered() {
        let pts: Vec<(f64, f64)> = (0..5)
            .flat_map(|i| (0..5).map(move |j| (i as f64, j as f64)))
            .collect();
        let checker = RectifiabilityChecker::new(pts);
        let ratio = checker.linearity_ratio();
        assert!(
            ratio < 0.8,
            "Uniform grid should have ratio < 0.8, got {}",
            ratio
        );
    }
    #[test]
    fn test_rectifiability_checker_empty() {
        let checker = RectifiabilityChecker::new(vec![]);
        assert_eq!(checker.centroid(), (0.0, 0.0));
        assert_eq!(checker.linearity_ratio(), 0.0);
    }
    #[test]
    fn test_coarea_invalid_size() {
        let result = CoAreaComputer::new(3, vec![0.0; 9], vec![0.0; 8]);
        assert!(result.is_none());
    }
    #[test]
    fn test_coarea_lhs_non_negative() {
        let n = 10usize;
        let f_values: Vec<f64> = (0..n)
            .flat_map(|i| (0..n).map(move |_j| i as f64 / n as f64))
            .collect();
        let g_values = vec![1.0f64; n * n];
        let computer = CoAreaComputer::new(n, f_values, g_values).expect("Should construct");
        let lhs = computer.lhs_integral();
        assert!(
            lhs >= 0.0,
            "LHS integral should be non-negative, got {}",
            lhs
        );
        assert!(
            lhs > 0.0,
            "LHS should be positive for non-constant f, got {}",
            lhs
        );
    }
    #[test]
    fn test_coarea_rhs_non_negative() {
        let n = 8usize;
        let f_values: Vec<f64> = (0..n)
            .flat_map(|i| (0..n).map(move |j| (i as f64 + j as f64) / (2.0 * n as f64)))
            .collect();
        let g_values = vec![1.0f64; n * n];
        let computer = CoAreaComputer::new(n, f_values, g_values).expect("Should construct");
        let rhs = computer.rhs_integral(10);
        assert!(
            rhs >= 0.0,
            "RHS integral should be non-negative, got {}",
            rhs
        );
    }
    #[test]
    fn test_coarea_constant_f_gives_zero_lhs() {
        let n = 5usize;
        let f_values = vec![1.0f64; n * n];
        let g_values = vec![1.0f64; n * n];
        let computer = CoAreaComputer::new(n, f_values, g_values).expect("Should construct");
        let lhs = computer.lhs_integral();
        assert!(
            lhs.abs() < 1e-12,
            "Constant f should give zero LHS, got {}",
            lhs
        );
    }
}
/// Approximate gamma function for small positive values.
#[allow(dead_code)]
pub fn gamma_approx(x: f64) -> f64 {
    if x <= 0.0 {
        return f64::INFINITY;
    }
    // Use Lanczos approximation for better accuracy at small values
    // For half-integers and integers, use recurrence Gamma(x) = (x-1)*Gamma(x-1)
    if (x - 0.5).abs() < 1e-12 {
        return std::f64::consts::PI.sqrt(); // Gamma(1/2) = sqrt(pi)
    }
    if (x - 1.0).abs() < 1e-12 {
        return 1.0; // Gamma(1) = 0! = 1
    }
    if x < 1.5 {
        // Gamma(x) = Gamma(x+1) / x
        return gamma_approx(x + 1.0) / x;
    }
    if x < 7.0 {
        // Use recurrence to shift up: Gamma(x) = (x-1)*Gamma(x-1)
        return (x - 1.0) * gamma_approx(x - 1.0);
    }
    // Stirling approximation: good for x >= 7
    let two_pi = 2.0 * std::f64::consts::PI;
    (two_pi / x).sqrt() * (x / std::f64::consts::E).powf(x)
}
#[cfg(test)]
mod tests_gmt_extended {
    use super::*;
    #[test]
    fn test_caccioppoli_ball_isoperimetric() {
        let s = CaccioppoliSet::new(2, 2.0 * std::f64::consts::PI, std::f64::consts::PI);
        assert!(s.satisfies_isoperimetric());
    }
    #[test]
    fn test_integral_current_boundary_dim() {
        let current = IntegralCurrent::new(3, 2, 5.0, 1.0);
        assert_eq!(current.boundary_dimension(), 1);
    }
    #[test]
    fn test_integral_current_compactness() {
        let current = IntegralCurrent::new(3, 2, 10.0, 2.0);
        let bound = current.compactness_bound();
        assert!((bound - 12.0).abs() < 1e-10);
    }
    #[test]
    fn test_marstrand_positive_measure() {
        let m = MarstrandProjection::new(1.5, 2, 1);
        assert!(m.projection_has_positive_measure());
    }
    #[test]
    fn test_marstrand_no_positive_measure() {
        let m = MarstrandProjection::new(0.5, 2, 1);
        assert!(!m.projection_has_positive_measure());
    }
    #[test]
    fn test_slice_dimension() {
        let m = MarstrandProjection::new(2.5, 3, 1);
        assert!((m.typical_slice_dimension() - 0.5).abs() < 1e-10);
    }
}
#[cfg(test)]
mod tests_gmt_extra {
    use super::*;
    #[test]
    fn test_rectifiable_set() {
        let s = RectifiableSet::smooth_submanifold(2, 3, 4.0);
        assert_eq!(s.dimension, 2);
        assert!(s.is_integer_rectifiable());
        assert!((s.lower_density() - 1.0).abs() < 1e-9);
    }
    #[test]
    fn test_integral_current() {
        let c = IntegralCurrentNew::cycle(2, 5.0);
        assert!(c.is_closed);
        assert!(c.is_integer_multiplicity());
        assert!((c.flat_norm() - 5.0).abs() < 1e-9);
    }
    #[test]
    fn test_compactness() {
        let ct = CompactnessTheorem::new(3, 2, 10.0);
        assert!(ct.has_convergent_subsequence());
        assert!(ct.limit_is_integral_current());
    }
    #[test]
    fn test_plateau() {
        let pp = PlateauProblem::new("circle", 3);
        assert!(pp.solution_exists);
        assert!(!pp.solution_unique);
    }
}