grid1d 0.5.0

A mathematically rigorous, type-safe Rust library for 1D grid operations and interval partitions, supporting both native and arbitrary-precision numerics.
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
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
#![deny(rustdoc::broken_intra_doc_links)]

//! Traits that define the behaviour and capabilities of bound types.
//!
//! This module contains all trait definitions used in the bounds system.
//! Concrete implementations live in [`bounds.rs`](crate::bounds) (for
//! [`IntervalBound`]) and in
//! [`bounds/runtime.rs`](crate::bounds::runtime) (for
//! [`IntervalBoundRuntime`](crate::bounds::IntervalBoundRuntime)).
//!
//! ## Trait Overview
//!
//! ### Marker Traits (compile-time)
//!
//! | Trait | Purpose | Implementors |
//! |-------|---------|-------------|
//! | [`BoundSide`] | Distinguishes lower vs upper bounds | [`Lower`], [`Upper`] |
//! | [`BoundType`] | Distinguishes open vs closed bounds | [`Open`], [`Closed`] |
//!
//! ### Runtime Query Traits
//!
//! | Trait | Purpose | Key Methods |
//! |-------|---------|------------|
//! | [`BoundTypeChecks`] | Query open/closed inclusion | `includes_boundary()`, `is_open()`, `is_closed()` |
//! | [`BoundSideChecks`] | Query lower/upper side | `is_lower_bound()`, `is_upper_bound()` |
//! | [`BoundChecks`] | Combined type + side queries | supertrait of both above |
//! | [`ValueWithinBound`] | Test whether a value satisfies a bound | `value_within_bound(&T)` |
//!
//! ### Conversion Traits
//!
//! | Trait | Purpose |
//! |-------|--------|
//! | [`BoundTypeConversion`] | Convert a bound between `Open` and `Closed` |
//! | [`BoundSideConversion`] | Convert a bound between `Lower` and `Upper` |
//!
//! ## Example
//!
//! ```rust
//! use grid1d::bounds::*;
//! use grid1d::bounds::traits::{BoundTypeChecks, BoundSideChecks, ValueWithinBound};
//! use try_create::New;
//!
//! let b = LowerBoundClosed::new(5.0f64);
//! assert!(b.is_closed());
//! assert!(b.is_lower_bound());
//! assert!(b.value_within_bound(&5.0));  // 5 ≥ 5
//! assert!(!b.value_within_bound(&4.9)); // 4.9 < 5
//! ```

use crate::bounds::{Closed, IntervalBound, Lower, Open, Upper};
use num_valid::RealScalar;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;

//------------------------------------------------------------------------------------------------
/// Runtime queries for boundary inclusion semantics (open vs closed bounds).
///
/// [`BoundTypeChecks`] provides a unified interface for determining whether a bound includes
/// or excludes its boundary value at runtime. This trait enables generic programming over
/// different boundary inclusion semantics while maintaining mathematical correctness and type safety.
///
/// ## Design Philosophy
///
/// ### Runtime Type Detection
///
/// Unlike the compile-time [`BoundType`] trait that provides static type information,
/// [`BoundTypeChecks`] operates on bound instances to determine their inclusion semantics:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn analyze_bound_inclusion<B: BoundTypeChecks>(bound: &B) -> String {
///     if bound.is_closed() {
///         "This bound includes its boundary value".to_string()
///     } else {
///         "This bound excludes its boundary value".to_string()
///     }
/// }
///
/// let closed = LowerBoundClosed::new(0.0);
/// let open = UpperBoundOpen::new(10.0);
///
/// assert_eq!(analyze_bound_inclusion(&closed), "This bound includes its boundary value");
/// assert_eq!(analyze_bound_inclusion(&open), "This bound excludes its boundary value");
/// ```
///
/// ### Complement Relationship
///
/// The two derived methods in this trait are logical complements:
/// ```text
/// is_closed() == includes_boundary()
/// is_open() == !includes_boundary()
/// ```
///
/// This relationship is enforced by the default implementations of [`BoundTypeChecks::is_closed()`] and [`BoundTypeChecks::is_open()`],
/// ensuring mathematical consistency across all implementations.
///
/// ## Mathematical Semantics
///
/// ### Closed Bounds (Inclusive)
///
/// Closed bounds include their boundary values in the constraint:
///
/// | Bound Type | Mathematical Constraint | Notation | Meaning |
/// |------------|------------------------|----------|---------|
/// | [`LowerBoundClosed`](crate::bounds::LowerBoundClosed) | `x ≥ bound_value` | `[a` | Includes minimum |
/// | [`UpperBoundClosed`](crate::bounds::UpperBoundClosed) | `x ≤ bound_value` | `b]` | Includes maximum |
///
/// ### Open Bounds (Exclusive)
///
/// Open bounds exclude their boundary values from the constraint:
///
/// | Bound Type | Mathematical Constraint | Notation | Meaning |
/// |------------|------------------------|----------|---------|
/// | [`LowerBoundOpen`](crate::bounds::LowerBoundOpen) | `x > bound_value` | `(a` | Excludes minimum |
/// | [`UpperBoundOpen`](crate::bounds::UpperBoundOpen) | `x < bound_value` | `b)` | Excludes maximum |
///
/// ## Core Methods
///
/// ### [`BoundTypeChecks::includes_boundary()`]
///
/// The fundamental method that determines whether the boundary value is part of the constraint.
/// This is the only method implementors must provide:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let closed_lower = LowerBoundClosed::new(5.0);
/// let open_lower = LowerBoundOpen::new(5.0);
/// let closed_upper = UpperBoundClosed::new(10.0);
/// let open_upper = UpperBoundOpen::new(10.0);
///
/// // Closed bounds include their boundary
/// assert!(closed_lower.includes_boundary());
/// assert!(closed_upper.includes_boundary());
///
/// // Open bounds exclude their boundary
/// assert!(!open_lower.includes_boundary());
/// assert!(!open_upper.includes_boundary());
/// ```
///
/// ### [`BoundTypeChecks::is_closed()`]
///
/// Returns `true` if this bound includes its boundary value. This is a convenience method
/// that delegates to [`BoundTypeChecks::includes_boundary()`]:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// assert!(LowerBoundClosed::new(0.0).is_closed());
/// assert!(!LowerBoundClosed::new(1.0).is_open());
///
/// assert!(UpperBoundClosed::new(2.0).is_closed());
/// assert!(!UpperBoundClosed::new(3.0).is_open());
///
/// assert!(!LowerBoundOpen::new(4.0).is_closed());
/// assert!(LowerBoundOpen::new(5.0).is_open());
///
/// assert!(!UpperBoundOpen::new(6.0).is_closed());
/// assert!(UpperBoundOpen::new(7.0).is_open());
/// ```
///
/// ### [`BoundTypeChecks::is_open()`]
///
/// Returns `true` if this bound excludes its boundary value. This is implemented as
/// the logical negation of [`BoundTypeChecks::includes_boundary()`]:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let open_lower = LowerBoundOpen::new(1.0);
/// let open_upper = UpperBoundOpen::new(2.0);
/// let closed_lower = LowerBoundClosed::new(1.0);
/// let closed_upper = UpperBoundClosed::new(2.0);
///
/// // Open bounds return true
/// assert!(open_lower.is_open());
/// assert!(open_upper.is_open());
/// assert!(!open_lower.is_closed());
/// assert!(!open_upper.is_closed());
///
/// // Closed bounds return false
/// assert!(!closed_lower.is_open());
/// assert!(!closed_upper.is_open());
/// assert!(closed_lower.is_closed());
/// assert!(closed_upper.is_closed());
/// ```
///
/// ## Generic Programming Applications
///
/// ### Constraint Analysis
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn analyze_constraint_strictness<B: BoundTypeChecks + AsRef<f64>>(bounds: &[B]) -> (usize, usize) {
///     let (strict, inclusive): (Vec<_>, Vec<_>) = bounds.iter()
///         .partition(|bound| bound.is_open());
///     (strict.len(), inclusive.len())
/// }
///
/// let mixed_lower_bounds: Vec<LowerBoundRuntime<f64>> = vec![
///     LowerBoundClosed::new(0.0).into(),   // Inclusive
///     LowerBoundOpen::new(1.0).into(),     // Strict
/// ];
/// let mixed_upper_bounds: Vec<UpperBoundRuntime<f64>> = vec![
///     UpperBoundClosed::new(10.0).into(),  // Inclusive
///     UpperBoundOpen::new(9.0).into(),     // Strict
///     UpperBoundOpen::new(8.0).into(),     // Strict
/// ];
///
/// let (strict_count, inclusive_count) = analyze_constraint_strictness(&mixed_lower_bounds);
/// assert_eq!(strict_count, 1);     // One open bounds
/// assert_eq!(inclusive_count, 1);  // One closed bounds
///
/// let (strict_count, inclusive_count) = analyze_constraint_strictness(&mixed_upper_bounds);
/// assert_eq!(strict_count, 2);     // Two open bounds
/// assert_eq!(inclusive_count, 1);  // One closed bounds
/// ```
///
/// ### Boundary Behavior Validation
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn validate_boundary_consistency<B>(bound: &B, test_value: f64) -> bool
/// where
///     B: BoundTypeChecks + ValueWithinBound<RealType = f64> + AsRef<f64>,
/// {
///     let boundary_value = *bound.as_ref();
///     let at_boundary = (test_value - boundary_value).abs() < f64::EPSILON;
///     
///     if at_boundary {
///         // At the boundary, constraint should match inclusion semantics
///         bound.value_within_bound(&test_value) == bound.includes_boundary()
///     } else {
///         // Away from boundary, inclusion type shouldn't matter for this test
///         true
///     }
/// }
///
/// let closed_bound = LowerBoundClosed::new(5.0);
/// let open_bound = LowerBoundOpen::new(5.0);
///
/// // Test boundary value behavior
/// assert!(validate_boundary_consistency(&closed_bound, 5.0)); // Should include 5.0
/// assert!(validate_boundary_consistency(&open_bound, 5.0));   // Should exclude 5.0
///
/// // Test non-boundary values
/// assert!(validate_boundary_consistency(&closed_bound, 6.0)); // Both should include 6.0
/// assert!(validate_boundary_consistency(&open_bound, 6.0));
/// ```
///
/// ### Dynamic Interval Construction
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn describe_interval_boundary<L, U>(lower: &L, upper: &U) -> String
/// where
///     L: BoundTypeChecks + AsRef<f64>,
///     U: BoundTypeChecks + AsRef<f64>,
/// {
///     let left_bracket = if lower.is_closed() { "[" } else { "(" };
///     let right_bracket = if upper.is_closed() { "]" } else { ")" };
///     
///     format!("{}{}, {}{}",
///         left_bracket, lower.as_ref(),
///         upper.as_ref(), right_bracket)
/// }
///
/// let bounds_combinations: Vec<(LowerBoundRuntime<f64>, UpperBoundRuntime<f64>)> = vec![
///     (LowerBoundClosed::new(0.0).into(), UpperBoundClosed::new(1.0).into()),   // [0, 1]
///     (LowerBoundOpen::new(0.0).into(), UpperBoundOpen::new(1.0).into()),       // (0, 1)
///     (LowerBoundClosed::new(0.0).into(), UpperBoundOpen::new(1.0).into()),     // [0, 1)
///     (LowerBoundOpen::new(0.0).into(), UpperBoundClosed::new(1.0).into()),     // (0, 1]
/// ];
///
/// let descriptions: Vec<String> = bounds_combinations.iter()
///     .map(|(l, u)| describe_interval_boundary(l, u))
///     .collect();
///
/// assert_eq!(descriptions, vec!["[0, 1]", "(0, 1)", "[0, 1)", "(0, 1]"]);
/// ```
///
/// ## Integration with Runtime Bounds
///
/// The trait works seamlessly with runtime bound types:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn analyze_runtime_bound_types(
///     lower: &LowerBoundRuntime<f64>,
///     upper: &UpperBoundRuntime<f64>
/// ) -> String {
///     let lower_type = if lower.is_closed() { "closed" } else { "open" };
///     let upper_type = if upper.is_closed() { "closed" } else { "open" };
///     
///     format!("Lower: {} ({}), Upper: {} ({})",
///         lower.as_ref(), lower_type,
///         upper.as_ref(), upper_type)
/// }
///
/// let lower = IntervalBoundRuntime::Closed(LowerBoundClosed::new(0.0));
/// let upper = IntervalBoundRuntime::Open(UpperBoundOpen::new(1.0));
///
/// assert_eq!(
///     analyze_runtime_bound_types(&lower, &upper),
///     "Lower: 0 (closed), Upper: 1 (open)"
/// );
/// ```
///
/// ## Mathematical Invariant Verification
///
/// The trait enables runtime validation of mathematical properties:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn verify_inclusion_consistency<B: BoundTypeChecks>(bound: &B) -> bool {
///     // Verify the complement relationship holds
///     bound.is_closed() == bound.includes_boundary() &&
///     bound.is_open() == !bound.includes_boundary()
/// }
///
/// fn verify_boundary_semantics<B>(bound: &B, boundary_value: f64) -> Result<(), String>
/// where
///     B: BoundTypeChecks + ValueWithinBound<RealType = f64> + AsRef<f64>,
/// {
///     if !verify_inclusion_consistency(bound) {
///         return Err("Bound inclusion consistency check failed".to_string());
///     }
///     
///     // The boundary value itself should only satisfy the constraint if the bound is closed
///     let boundary_satisfies = bound.value_within_bound(&boundary_value);
///     if boundary_satisfies != bound.includes_boundary() {
///         return Err("Boundary constraint behavior inconsistent with inclusion type".to_string());
///     }
///     
///     Ok(())
/// }
///
/// let closed_bound = LowerBoundClosed::new(5.0);
/// let open_bound = LowerBoundOpen::new(5.0);
///
/// assert!(verify_boundary_semantics(&closed_bound, 5.0).is_ok());
/// assert!(verify_boundary_semantics(&open_bound, 5.0).is_ok());
/// ```
///
/// ## Performance Characteristics
///
/// ### Runtime Complexity
/// - **`includes_boundary()`**: O(1) - typically compiles to a constant or simple type check
/// - **`is_closed()`**: O(1) - delegates to `includes_boundary()`
/// - **`is_open()`**: O(1) - logical negation of `includes_boundary()`
/// - **Memory**: No additional storage overhead beyond the underlying bound
///
/// ### Optimization Notes
/// - All methods are marked `#[inline(always)]` for zero-cost abstractions
/// - The complement relationship enables compiler optimizations
/// - For compile-time bounds, inclusion information is known statically and optimized away
/// - Runtime bounds have small pattern matching overhead but maintain correctness
///
/// ## Implementation Requirements
///
/// Implementors must provide:
/// 1. **`includes_boundary()`**: Core method that determines boundary inclusion semantics
/// 2. **Consistency**: The method must return consistent results for the lifetime of the object
/// 3. **Mathematical Correctness**: Return `true` for closed bounds, `false` for open bounds
///
/// ### Example Implementation
///
/// ```rust
/// use grid1d::bounds::*;
///
/// struct CustomBound {
///     value: f64,
///     is_inclusive: bool,
/// }
///
/// impl BoundTypeChecks for CustomBound {
///     fn includes_boundary(&self) -> bool {
///         self.is_inclusive
///     }
/// }
///
/// let inclusive = CustomBound { value: 5.0, is_inclusive: true };
/// let exclusive = CustomBound { value: 5.0, is_inclusive: false };
///
/// assert!(inclusive.is_closed());
/// assert!(!inclusive.is_open());
/// assert!(inclusive.includes_boundary());
///
/// assert!(!exclusive.is_closed());
/// assert!(exclusive.is_open());
/// assert!(!exclusive.includes_boundary());
/// ```
///
/// ## Mathematical Guarantees
///
/// The [`BoundTypeChecks`] trait maintains mathematical correctness by:
///
/// - **Complement Relationship**: Ensuring exactly one of `is_open()` or `is_closed()` is true
/// - **Consistency**: Boundary inclusion semantics remain constant for the object's lifetime
/// - **Type Safety**: Preventing confusion between inclusive and exclusive constraints
/// - **Constraint Semantics**: Properly reflecting the mathematical meaning of open vs closed bounds
///
/// Use [`BoundTypeChecks`] when you need to determine boundary inclusion behavior at runtime
/// while maintaining mathematical correctness and type safety. For compile-time inclusion
/// information, prefer the static [`BoundType`] trait and its associated types ([`Open`], [`Closed`]).
pub trait BoundTypeChecks {
    /// Returns whether the boundary value is included in the interval
    fn includes_boundary(&self) -> bool;

    /// Returns whether this bound is open (excludes the boundary value)
    #[inline(always)]
    fn is_open(&self) -> bool {
        !self.is_closed()
    }

    /// Returns whether this bound is closed (includes the boundary value)
    #[inline(always)]
    fn is_closed(&self) -> bool {
        self.includes_boundary()
    }
}

/// Runtime queries for boundary side semantics (upper vs lower bounds).
///
/// [`BoundSideChecks`] provides a unified interface for determining whether a bound represents
/// an upper or lower constraint at runtime. This trait enables generic programming over
/// different boundary sides while maintaining mathematical correctness and type safety.
///
/// ## Design Philosophy
///
/// ### Runtime Side Detection
///
/// Unlike the compile-time [`BoundSide`] trait that provides static type information,
/// [`BoundSideChecks`] operates on bound instances to determine their side semantics:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn analyze_bound_side<B: BoundSideChecks>(bound: &B) -> String {
///     if bound.is_lower_bound() {
///         "This bound defines a minimum constraint".to_string()
///     } else {
///         "This bound defines a maximum constraint".to_string()
///     }
/// }
///
/// let lower = LowerBoundClosed::new(0.0);
/// let upper = UpperBoundOpen::new(10.0);
///
/// assert_eq!(analyze_bound_side(&lower), "This bound defines a minimum constraint");
/// assert_eq!(analyze_bound_side(&upper), "This bound defines a maximum constraint");
/// ```
///
/// ### Complement Relationship
///
/// The two methods in this trait are logical complements:
/// ```text
/// is_lower_bound() == !is_upper_bound()
/// is_upper_bound() == !is_lower_bound()
/// ```
///
/// This relationship is enforced by the default implementation of [`BoundSideChecks::is_lower_bound()`],
/// ensuring mathematical consistency across all implementations.
///
/// ## Mathematical Semantics
///
/// ### Lower Bounds (Minimum Constraints)
///
/// Lower bounds define minimum values for intervals and domains:
///
/// | Bound Type | Mathematical Constraint | Notation | Meaning |
/// |------------|------------------------|----------|---------|
/// | [`LowerBoundClosed`](crate::bounds::LowerBoundClosed) | `x ≥ lower_value` | `[a` | Includes minimum |
/// | [`LowerBoundOpen`](crate::bounds::LowerBoundOpen) | `x > lower_value` | `(a` | Excludes minimum |
///
/// ### Upper Bounds (Maximum Constraints)
///
/// Upper bounds define maximum values for intervals and domains:
///
/// | Bound Type | Mathematical Constraint | Notation | Meaning |
/// |------------|------------------------|----------|---------|
/// | [`UpperBoundClosed`](crate::bounds::UpperBoundClosed) | `x ≤ upper_value` | `b]` | Includes maximum |
/// | [`UpperBoundOpen`](crate::bounds::UpperBoundOpen) | `x < upper_value` | `b)` | Excludes maximum |
///
/// ## Core Methods
///
/// ### [`BoundSideChecks::is_upper_bound()`]
///
/// Returns `true` if this bound represents an upper (maximum) constraint:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let upper_closed = UpperBoundClosed::new(10.0);
/// let upper_open = UpperBoundOpen::new(10.0);
/// let lower_closed = LowerBoundClosed::new(0.0);
/// let lower_open = LowerBoundOpen::new(0.0);
///
/// // Upper bounds return true
/// assert!(upper_closed.is_upper_bound());
/// assert!(upper_open.is_upper_bound());
///
/// // Lower bounds return false
/// assert!(!lower_closed.is_upper_bound());
/// assert!(!lower_open.is_upper_bound());
/// ```
///
/// ### [`BoundSideChecks::is_lower_bound()`]
///
/// Returns `true` if this bound represents a lower (minimum) constraint:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let lower_closed = LowerBoundClosed::new(0.0);
/// let lower_open = LowerBoundOpen::new(0.0);
/// let upper_closed = UpperBoundClosed::new(10.0);
/// let upper_open = UpperBoundOpen::new(10.0);
///
/// // Lower bounds return true
/// assert!(lower_closed.is_lower_bound());
/// assert!(lower_open.is_lower_bound());
///
/// // Upper bounds return false
/// assert!(!upper_closed.is_lower_bound());
/// assert!(!upper_open.is_lower_bound());
/// ```
///
/// ## Generic Programming Applications
///
/// ### Bound Classification
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let bounds: Vec<Box<dyn BoundSideChecks>> = vec![
///     Box::new(LowerBoundClosed::new(0.0)),
///     Box::new(UpperBoundOpen::new(10.0)),
///     Box::new(LowerBoundOpen::new(1.0)),
///     Box::new(UpperBoundClosed::new(9.0)),
/// ];
///
/// let (lower_bounds, upper_bounds): (Vec<_>, Vec<_>) =
///     bounds.iter().partition(|bound| bound.is_lower_bound());
/// assert_eq!(lower_bounds.len(), 2); // Two lower bounds
/// assert_eq!(upper_bounds.len(), 2); // Two upper bounds
/// ```
///
/// ### Constraint Validation
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn validate_constraint_consistency<BL, BU>(lower: &BL, upper: &BU) -> Result<(), String>
/// where
///     BL: BoundSideChecks + AsRef<f64>,
///     BU: BoundSideChecks + AsRef<f64>,
/// {
///     if !lower.is_lower_bound() {
///         return Err("First argument must be a lower bound".to_string());
///     }
///     if !upper.is_upper_bound() {
///         return Err("Second argument must be an upper bound".to_string());
///     }
///     if lower.as_ref() >= upper.as_ref() {
///         return Err("Lower bound must be less than upper bound".to_string());
///     }
///     Ok(())
/// }
///
/// let lower = LowerBoundClosed::new(0.0);
/// let upper = UpperBoundOpen::new(10.0);
/// let wrong_lower = UpperBoundClosed::new(5.0);
///
/// assert!(validate_constraint_consistency(&lower, &upper).is_ok());
/// assert!(validate_constraint_consistency(&wrong_lower, &upper).is_err());
/// ```
///
/// ### Dynamic Bound Processing
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn process_bound<B>(bound: &B) -> String
/// where
///     B: BoundChecks + AsRef<f64>,
/// {
///     let side = if bound.is_lower_bound() { "Lower" } else { "Upper" };
///     let inclusion = if bound.is_closed() { "inclusive" } else { "exclusive" };
///     let value = bound.as_ref();
///     
///     format!("{} bound: {} ({})", side, value, inclusion)
/// }
///
///
/// let lower_bounds: Vec<LowerBoundRuntime<f64>> = vec![
///     LowerBoundClosed::new(0.0).into(),
///     LowerBoundOpen::new(1.0).into(),
/// ];
/// let upper_bounds: Vec<UpperBoundRuntime<f64>> = vec![
///     UpperBoundOpen::new(10.0).into(),
///     UpperBoundClosed::new(9.0).into(),
/// ];
///
/// for bound in &lower_bounds {
///     println!("{}", process_bound(bound));
/// }
/// // Output:
/// // Lower bound: 0 (inclusive)
/// // Lower bound: 1 (exclusive)
/// for bound in &upper_bounds {
///     println!("{}", process_bound(bound));
/// }
/// // Output:
/// // Upper bound: 10 (exclusive)
/// // Upper bound: 9 (inclusive)
/// // Upper bound: 9 (inclusive)
/// ```
///
/// ## Integration with Runtime Bounds
///
/// The trait works seamlessly with runtime bound types:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn analyze_runtime_bounds(
///     lower: &LowerBoundRuntime<f64>,
///     upper: &UpperBoundRuntime<f64>
/// ) -> String {
///     // These assertions are guaranteed by the type system
///     assert!(lower.is_lower_bound());
///     assert!(upper.is_upper_bound());
///     assert!(!lower.is_upper_bound());
///     assert!(!upper.is_lower_bound());
///     
///     format!(
///         "Interval from {} {} to {} {}",
///         if lower.is_closed() { "[" } else { "(" },
///         lower.as_ref(),
///         upper.as_ref(),
///         if upper.is_closed() { "]" } else { ")" }
///     )
/// }
///
/// let lower = IntervalBoundRuntime::Closed(LowerBoundClosed::new(0.0));
/// let upper = IntervalBoundRuntime::Open(UpperBoundOpen::new(1.0));
///
/// assert_eq!(analyze_runtime_bounds(&lower, &upper), "Interval from [ 0 to 1 )");
/// ```
///
/// ## Invariant Checking
///
/// The trait enables runtime validation of mathematical invariants:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn verify_bound_side_consistency<B: BoundSideChecks>(bound: &B) -> bool {
///     // Verify the complement relationship holds
///     bound.is_lower_bound() == !bound.is_upper_bound()
/// }
///
/// fn verify_interval_bounds<L, U>(lower: &L, upper: &U) -> Result<(), String>
/// where
///     L: BoundSideChecks + AsRef<f64>,
///     U: BoundSideChecks + AsRef<f64>,
/// {
///     if !verify_bound_side_consistency(lower) {
///         return Err("Lower bound side consistency check failed".to_string());
///     }
///     if !verify_bound_side_consistency(upper) {
///         return Err("Upper bound side consistency check failed".to_string());
///     }
///     if !lower.is_lower_bound() {
///         return Err("First argument is not a lower bound".to_string());
///     }
///     if !upper.is_upper_bound() {
///         return Err("Second argument is not an upper bound".to_string());
///     }
///     Ok(())
/// }
///
/// let lower = LowerBoundClosed::new(0.0);
/// let upper = UpperBoundOpen::new(1.0);
///
/// assert!(verify_interval_bounds(&lower, &upper).is_ok());
/// ```
///
/// ## Performance Characteristics
///
/// ### Runtime Complexity
/// - **`is_upper_bound()`**: O(1) - typically compiles to a constant or simple field access
/// - **`is_lower_bound()`**: O(1) - implemented as logical negation of `is_upper_bound()`
/// - **Memory**: No additional storage overhead beyond the underlying bound
///
/// ### Optimization Notes
/// - All methods are marked `#[inline(always)]` for zero-cost abstractions
/// - The complement relationship enables compiler optimizations
/// - For compile-time bounds, side information is known statically and optimized away
///
/// ## Implementation Requirements
///
/// Implementors must provide:
/// 1. **`is_upper_bound()`**: Core method that determines the bound's side
/// 2. **Consistency**: The method must return consistent results for the lifetime of the object
/// 3. **Complement Semantics**: `is_lower_bound()` is automatically derived as `!is_upper_bound()`
///
/// ### Example Implementation
///
/// ```rust
/// use grid1d::bounds::*;
///
/// struct CustomBound {
///     value: f64,
///     is_upper: bool,
/// }
///
/// impl BoundSideChecks for CustomBound {
///     fn is_upper_bound(&self) -> bool {
///         self.is_upper
///     }
/// }
///
/// let lower = CustomBound { value: 0.0, is_upper: false };
/// let upper = CustomBound { value: 10.0, is_upper: true };
///
/// assert!(lower.is_lower_bound());
/// assert!(!lower.is_upper_bound());
/// assert!(upper.is_upper_bound());
/// assert!(!upper.is_lower_bound());
/// ```
///
/// ## Mathematical Guarantees
///
/// The [`BoundSideChecks`] trait maintains mathematical correctness by:
///
/// - **Complement Relationship**: Ensuring exactly one of `is_lower_bound()` or `is_upper_bound()` is true
/// - **Consistency**: Bound side semantics remain constant for the object's lifetime
/// - **Type Safety**: Preventing confusion between minimum and maximum constraints
/// - **Generic Compatibility**: Enabling type-safe generic programming over bound sides
///
/// Use [`BoundSideChecks`] when you need to determine boundary side semantics at runtime
/// while maintaining mathematical correctness and type safety. For compile-time side
/// information, prefer the static [`BoundSide`] trait and its associated types.
pub trait BoundSideChecks {
    /// Returns whether this is an upper bound
    fn is_upper_bound(&self) -> bool;

    /// Returns whether this is a lower bound
    #[inline(always)]
    fn is_lower_bound(&self) -> bool {
        !self.is_upper_bound()
    }
}

/// Unified runtime queries for both boundary side and type semantics.
///
/// [`BoundChecks`] is a marker trait that combines [`BoundSideChecks`] and [`BoundTypeChecks`]
/// to provide a unified interface for querying all boundary properties at runtime. This trait
/// enables comprehensive generic programming over bounds while maintaining mathematical correctness
/// and type safety.
///
/// ## Design Philosophy
///
/// ### Unified Boundary Interface
///
/// Rather than requiring separate trait bounds for side and type checking, [`BoundChecks`]
/// provides a single trait that encompasses all boundary query capabilities:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Instead of requiring multiple trait bounds:
/// fn analyze_bound_verbose<B>(bound: &B) -> String
/// where
///     B: BoundSideChecks + BoundTypeChecks + AsRef<f64>,
/// {
///     // Implementation...
///     format!("Bound analysis")
/// }
///
/// // Use the unified BoundChecks trait:
/// fn analyze_bound_concise<B>(bound: &B) -> String
/// where
///     B: BoundChecks + AsRef<f64>,
/// {
///     let side = if bound.is_lower_bound() { "Lower" } else { "Upper" };
///     let inclusion = if bound.is_closed() { "closed" } else { "open" };
///     format!("{} {} bound: {}", side, inclusion, bound.as_ref())
/// }
///
/// let lower_closed = LowerBoundClosed::new(5.0);
/// let upper_open = UpperBoundOpen::new(10.0);
///
/// println!("{}", analyze_bound_concise(&lower_closed)); // "Lower closed bound: 5"
/// println!("{}", analyze_bound_concise(&upper_open));   // "Upper open bound: 10"
/// ```
///
/// ### Automatic Implementation
///
/// [`BoundChecks`] is automatically implemented for any type that implements both
/// [`BoundSideChecks`] and [`BoundTypeChecks`], requiring no additional implementation work:
///
/// ```rust
/// use grid1d::bounds::*;
///
/// // This automatically implements BoundChecks:
/// struct CustomBound {
///     value: f64,
///     is_upper: bool,
///     is_inclusive: bool,
/// }
///
/// impl BoundSideChecks for CustomBound {
///     fn is_upper_bound(&self) -> bool {
///         self.is_upper
///     }
/// }
///
/// impl BoundTypeChecks for CustomBound {
///     fn includes_boundary(&self) -> bool {
///         self.is_inclusive
///     }
/// }
///
/// // BoundChecks is now available automatically
/// let custom = CustomBound { value: 7.0, is_upper: false, is_inclusive: true };
/// assert!(custom.is_lower_bound()); // From BoundSideChecks
/// assert!(custom.is_closed());      // From BoundTypeChecks
/// ```
///
/// ## Available Methods
///
/// All methods from both constituent traits are available:
///
/// ### From [`BoundSideChecks`]
/// - [`is_upper_bound()`](BoundSideChecks::is_upper_bound) - Returns `true` for upper bounds
/// - [`is_lower_bound()`](BoundSideChecks::is_lower_bound) - Returns `true` for lower bounds
///
/// ### From [`BoundTypeChecks`]  
/// - [`includes_boundary()`](BoundTypeChecks::includes_boundary) - Returns `true` if boundary is included
/// - [`is_closed()`](BoundTypeChecks::is_closed) - Returns `true` for closed bounds
/// - [`is_open()`](BoundTypeChecks::is_open) - Returns `true` for open bounds
///
/// ## Generic Programming Applications
///
/// ### Interval Validation
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn validate_interval_bounds<L, U>(lower: &L, upper: &U) -> Result<(), String>
/// where
///     L: BoundChecks + AsRef<f64>,
///     U: BoundChecks + AsRef<f64>,
/// {
///     // Validate sides
///     if !lower.is_lower_bound() {
///         return Err("First argument must be a lower bound".to_string());
///     }
///     if !upper.is_upper_bound() {
///         return Err("Second argument must be an upper bound".to_string());
///     }
///     
///     // Validate ordering
///     if lower.as_ref() > upper.as_ref() {
///         return Err("Lower bound cannot exceed upper bound".to_string());
///     }
///     
///     // Check for degenerate cases
///     if lower.as_ref() == upper.as_ref() {
///         if lower.is_open() || upper.is_open() {
///             return Err("Empty interval: bounds equal but at least one is open".to_string());
///         }
///     }
///     
///     Ok(())
/// }
///
/// // Valid intervals
/// let lower_closed = LowerBoundClosed::new(0.0);
/// let upper_open = UpperBoundOpen::new(1.0);
/// assert!(validate_interval_bounds(&lower_closed, &upper_open).is_ok());
///
/// // Invalid: wrong sides
/// let upper_as_lower = UpperBoundClosed::new(0.0);
/// assert!(validate_interval_bounds(&upper_as_lower, &upper_open).is_err());
///
/// // Invalid: empty interval
/// let same_value_open = LowerBoundOpen::new(1.0);
/// let same_value_closed = UpperBoundClosed::new(1.0);
/// assert!(validate_interval_bounds(&same_value_open, &same_value_closed).is_err());
/// ```
///
/// ## Performance Characteristics
///
/// ### Runtime Complexity
/// - **All methods**: O(1) - direct delegation to constituent traits
/// - **Memory overhead**: Zero - marker trait with no additional storage
/// - **Generic dispatch**: Same as individual traits - optimizes to static dispatch when possible
///
/// ### Compilation Benefits
/// - **Trait bound simplification**: Reduces generic constraints from two traits to one
/// - **Code clarity**: More readable generic function signatures
/// - **Automatic availability**: No additional implementation required
///
/// ## Best Practices
///
/// ### 1. **Use for Generic Functions**
/// ```rust
/// use grid1d::bounds::*;
///
/// // ✅ GOOD: Use BoundChecks for comprehensive bound analysis
/// fn analyze_bound<B: BoundChecks + AsRef<f64>>(bound: &B) -> String {
///     // Can use all boundary query methods
///     format!("Analysis complete")
/// }
///
/// // ❌ AVOID: Separate trait bounds when you need both
/// fn analyze_bound_verbose<B>(bound: &B) -> String
/// where
///     B: BoundSideChecks + BoundTypeChecks + AsRef<f64>
/// {
///     format!("Analysis complete") // More verbose for same functionality
/// }
/// ```
///
/// ### 2. **Combine with Other Traits**
/// ```rust
/// use grid1d::bounds::*;
///
/// // Common pattern: BoundChecks + value access
/// fn process_bound<B>(bound: &B) -> String
/// where
///     B: BoundChecks + AsRef<f64>,
/// {
///     // Full bound analysis with value access
///     format!("Processed bound")
/// }
///
/// // For constraint checking
/// fn validate_constraint<B>(bound: &B, test_value: f64) -> bool
/// where
///     B: BoundChecks + ValueWithinBound<RealType = f64>,
/// {
///     bound.value_within_bound(&test_value)
/// }
/// ```
///
/// ### 3. **Leverage Automatic Implementation**
/// ```rust
/// use grid1d::bounds::*;
///
/// // ✅ GOOD: Implement constituent traits, get BoundChecks for free
/// struct MyBound {
///     value: f64,
///     properties: (bool, bool), // (is_upper, is_closed)
/// }
///
/// impl BoundSideChecks for MyBound {
///     fn is_upper_bound(&self) -> bool { self.properties.0 }
/// }
///
/// impl BoundTypeChecks for MyBound {
///     fn includes_boundary(&self) -> bool { self.properties.1 }
/// }
///
/// // BoundChecks is now automatically available
/// ```
///
/// ## Mathematical Guarantees
///
/// The [`BoundChecks`] trait maintains all mathematical guarantees from its constituent traits:
///
/// - **Side Semantics**: Exactly one of `is_lower_bound()` or `is_upper_bound()` returns `true`
/// - **Type Semantics**: Exactly one of `is_open()` or `is_closed()` returns `true`
/// - **Consistency**: All methods return consistent results for the object's lifetime
/// - **Logical Relationships**: Complement relationships are preserved (`is_open() == !is_closed()`)
///
/// Use [`BoundChecks`] when you need comprehensive runtime boundary analysis while maintaining
/// mathematical correctness and type safety. This trait provides the most convenient interface
/// for generic programming over bounds with complete boundary semantics access.
pub trait BoundChecks: BoundTypeChecks + BoundSideChecks {}
//------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------
/// Trait for bound side markers (Lower/Upper)
///
/// This trait distinguishes between lower and upper bounds in interval arithmetic.
/// The key feature is the [`Opposite`](BoundSide::Opposite) associated type, which
/// enables type-safe conversions between lower and upper bounds without requiring
/// explicit type annotations.
///
/// # Associated Types
///
/// - [`Opposite`](BoundSide::Opposite): The opposite bound side type
///   - For `Lower`, `Opposite = Upper`
///   - For `Upper`, `Opposite = Lower`
///   - The constraint `BoundSide<Opposite = Self>` ensures bidirectional conversion
///
/// # Examples
///
/// ```rust
/// use grid1d::bounds::*;
///
/// // The associated type enables clean API without turbofish syntax
/// let lower = LowerBoundRuntime::new_open(5.0);
/// let upper = lower.flip_bound_side(); // Type automatically inferred as UpperBoundRuntime
///
/// // Works in both directions
/// let back_to_lower = upper.flip_bound_side(); // Type automatically inferred as LowerBoundRuntime
/// ```
pub trait BoundSide: Debug + Clone + PartialEq + Eq + Serialize + for<'a> Deserialize<'a> {
    /// The opposite bound side (Lower ↔ Upper)
    ///
    /// This associated type enables [`flip_bound_side()`](crate::bounds::IntervalBoundRuntime::flip_bound_side)
    /// to automatically infer the return type without requiring turbofish syntax.
    ///
    /// # Type Relationships
    ///
    /// - `<Lower as BoundSide>::Opposite = Upper`
    /// - `<Upper as BoundSide>::Opposite = Lower`
    ///
    /// The constraint `BoundSide<Opposite = Self>` ensures that flipping twice
    /// returns to the original type: `Side::Opposite::Opposite = Side`
    type Opposite: BoundSide<Opposite = Self>;

    /// Returns true if this is an upper bound
    fn is_upper() -> bool;

    /// Returns true if this is a lower bound
    #[inline(always)]
    fn is_lower() -> bool {
        !Self::is_upper()
    }
}
//------------------------------------------------------------------------------------------------

/// Convert between lower and upper bounds while preserving boundary type and value.
///
/// [`BoundSideConversion`] provides a unified interface for converting interval bounds
/// between lower and upper sides while maintaining the same inclusion semantics (open/closed)
/// and scalar value. This trait enables flexible bound manipulation in interval arithmetic
/// and domain specification operations.
///
/// ## Design Philosophy
///
/// ### Semantic Preservation
///
/// Unlike value-changing transformations, [`BoundSideConversion`] preserves all properties
/// except the boundary side:
///
/// ```rust
/// use grid1d::{*, bounds::*};
/// use try_create::New;
///
/// let lower_closed = LowerBoundClosed::new(5.0);    // [5 (lower, closed)
/// let upper_closed = lower_closed.into_upper();     // 5] (upper, closed)
///
/// // Value and inclusion semantics preserved
/// assert_eq!(upper_closed.as_ref(), &5.0);         // Same value
/// assert!(upper_closed.is_closed());               // Same inclusion
/// assert!(upper_closed.is_upper_bound());          // Different side
/// ```
///
/// ### Type-Safe Conversions
///
/// All conversions are compile-time verified and zero-cost:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let open_lower = LowerBoundOpen::new(10.0);      // (10
/// let open_upper = open_lower.into_upper();        // 10)
///
/// // Type system ensures consistency
/// let _: UpperBoundOpen<f64> = open_upper;         // Compile-time verification
/// ```
///
/// ## Mathematical Semantics
///
/// ### Lower to Upper Conversion
///
/// Converting a lower bound to an upper bound changes the constraint direction
/// while preserving the boundary value and inclusion:
///
/// | Original Lower Bound | Mathematical Constraint | Converted Upper Bound | New Constraint |
/// |---------------------|------------------------|---------------------|----------------|
/// | `LowerBoundClosed` | `x ≥ value` | `UpperBoundClosed` | `x ≤ value` |
/// | `LowerBoundOpen` | `x > value` | `UpperBoundOpen` | `x < value` |
///
/// ### Upper to Lower Conversion
///
/// Converting an upper bound to a lower bound changes the constraint direction
/// while preserving the boundary value and inclusion:
///
/// | Original Upper Bound | Mathematical Constraint | Converted Lower Bound | New Constraint |
/// |---------------------|------------------------|---------------------|----------------|
/// | `UpperBoundClosed` | `x ≤ value` | `LowerBoundClosed` | `x ≥ value` |
/// | `UpperBoundOpen` | `x < value` | `LowerBoundOpen` | `x > value` |
///
/// ## Core Methods
///
/// ### [`BoundSideConversion::into_lower()`]
///
/// Converts any bound to a lower bound with the same value and inclusion semantics:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Upper bounds to lower bounds
/// let upper_closed = UpperBoundClosed::new(100.0);  // x ≤ 100
/// let lower_closed = upper_closed.into_lower();      // x ≥ 100
/// assert_eq!(lower_closed.as_ref(), &100.0);
/// assert!(lower_closed.is_closed());
/// assert!(lower_closed.is_lower_bound());
///
/// let upper_open = UpperBoundOpen::new(50.0);       // x < 50
/// let lower_open = upper_open.into_lower();          // x > 50
/// assert_eq!(lower_open.as_ref(), &50.0);
/// assert!(lower_open.is_open());
/// assert!(lower_open.is_lower_bound());
///
/// // Lower bounds (identity conversion)
/// let existing_lower = LowerBoundClosed::new(25.0);
/// let same_lower = existing_lower.into_lower();      // No change
/// assert_eq!(same_lower.as_ref(), &25.0);
/// ```
///
/// ### [`BoundSideConversion::into_upper()`]
///
/// Converts any bound to an upper bound with the same value and inclusion semantics:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Lower bounds to upper bounds
/// let lower_closed = LowerBoundClosed::new(0.0);    // x ≥ 0
/// let upper_closed = lower_closed.into_upper();      // x ≤ 0
/// assert_eq!(upper_closed.as_ref(), &0.0);
/// assert!(upper_closed.is_closed());
/// assert!(upper_closed.is_upper_bound());
///
/// let lower_open = LowerBoundOpen::new(-5.0);       // x > -5
/// let upper_open = lower_open.into_upper();          // x < -5
/// assert_eq!(upper_open.as_ref(), &-5.0);
/// assert!(upper_open.is_open());
/// assert!(upper_open.is_upper_bound());
///
/// // Upper bounds (identity conversion)
/// let existing_upper = UpperBoundOpen::new(10.0);
/// let same_upper = existing_upper.into_upper();      // No change
/// assert_eq!(same_upper.as_ref(), &10.0);
/// ```
///
/// ## Practical Usage Patterns
///
/// ### Interval Construction and Manipulation
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Create symmetric intervals from a single bound
/// fn create_symmetric_interval<T: BoundType>(
///     center: f64,
///     radius: f64
/// ) -> (LowerBound<f64, T>, UpperBound<f64, T>) {
///     let lower_bound = LowerBound::<f64, T>::new(center - radius);
///     let upper_bound = lower_bound.clone().into_upper().with_value(center + radius);
///     (lower_bound, upper_bound)
/// }
///
/// let (lower, upper) = create_symmetric_interval::<Closed>(5.0, 2.0);
/// assert_eq!(lower.as_ref(), &3.0);  // [3
/// assert_eq!(upper.as_ref(), &7.0);  // 7]
/// assert!(lower.is_closed());
/// assert!(upper.is_closed());
/// ```
///
/// ### Domain Transformations
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Transform constraint direction for mathematical operations
/// fn create_complementary_bounds(
///     original: LowerBoundClosed<f64>
/// ) -> (LowerBoundClosed<f64>, UpperBoundClosed<f64>) {
///     let complementary_upper = original.clone().into_upper();
///     (original, complementary_upper)
/// }
///
/// let lower = LowerBoundClosed::new(0.0);           // x ≥ 0
/// let (same_lower, upper) = create_complementary_bounds(lower);
///
/// // Now we have both x ≥ 0 and x ≤ 0, useful for equality constraints
/// assert!(same_lower.value_within_bound(&0.0));     // 0 ≥ 0 → true
/// assert!(upper.value_within_bound(&0.0));          // 0 ≤ 0 → true
/// assert!(!same_lower.value_within_bound(&-1.0));   // -1 ≥ 0 → false
/// assert!(!upper.value_within_bound(&1.0));         // 1 ≤ 0 → false
/// ```
///
/// ### Constraint Reversal
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Reverse constraint direction for optimization problems
/// fn reverse_constraint_direction<T: BoundType>(
///     lower: LowerBound<f64, T>
/// ) -> UpperBound<f64, T> {
///     lower.into_upper()
/// }
///
/// let min_constraint = LowerBoundOpen::new(0.0);    // x > 0 (minimum)
/// let max_constraint = reverse_constraint_direction(min_constraint);  // x < 0 (maximum)
///
/// // Useful for converting "at least" to "at most" constraints
/// assert!(max_constraint.is_upper_bound());
/// assert!(max_constraint.is_open());
/// assert_eq!(max_constraint.as_ref(), &0.0);
/// ```
///
/// ## Integration with Grid1D
///
/// ### Interval Boundary Specification
///
/// ```rust
/// use grid1d::{bounds::*, intervals::*};
/// use try_create::{New, IntoInner};
///
/// // Create intervals using bound conversion
/// fn create_interval_from_single_bound<T: BoundType>(
///     bound_value: f64,
///     width: f64
/// ) -> String
/// where
///     LowerBound<f64, T>: BoundSideConversion<f64, T>,
/// {
///     let lower = LowerBound::<f64, T>::new(bound_value);
///     let upper = lower.clone().into_upper().with_value(bound_value + width);
///     
///     let left = if T::is_closed() { "[" } else { "(" };
///     let right = if T::is_closed() { "]" } else { ")" };
///     format!("{}{}, {}{}", left, lower.as_ref(), upper.as_ref(), right)
/// }
///
/// let closed_interval = create_interval_from_single_bound::<Closed>(0.0, 1.0);
/// assert_eq!(closed_interval, "[0, 1]");
///
/// let open_interval = create_interval_from_single_bound::<Open>(0.0, 1.0);
/// assert_eq!(open_interval, "(0, 1)");
/// ```
///
/// ### Domain Analysis and Transformation
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Analyze and transform domain boundaries
/// fn analyze_domain_bounds<B>(bounds: &[B]) -> (f64, f64, usize, usize)
/// where
///     B: BoundSideConversion<f64, Closed> + AsRef<f64> + Clone,
/// {
///     let values: Vec<f64> = bounds.iter().map(|b| *b.as_ref()).collect();
///     let min_val = values.iter().fold(f64::INFINITY, |a, &b| a.min(b));
///     let max_val = values.iter().fold(f64::NEG_INFINITY, |a, &b| a.max(b));
///     
///     // Convert all to lower bounds for uniform analysis
///     let lower_bounds: Vec<_> = bounds.iter()
///         .map(|b| b.clone().into_lower())
///         .collect();
///     
///     let active_lower = lower_bounds.iter()
///         .filter(|b| b.value_within_bound(&min_val))
///         .count();
///     
///     let total_bounds = bounds.len();
///     (min_val, max_val, active_lower, total_bounds - active_lower)
/// }
/// ```
///
/// ## Performance Characteristics
///
/// ### Zero-Cost Abstractions
/// - **Memory**: No additional storage overhead (phantom type manipulation only)
/// - **Conversion**: Direct field copying with compile-time type transformation
/// - **Runtime**: All conversions compile to simple memory moves
///
/// ### Optimization Benefits
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // This entire conversion compiles to a no-op
/// fn efficient_conversion(bound: LowerBoundClosed<f64>) -> UpperBoundClosed<f64> {
///     bound.into_upper()  // Zero runtime cost
/// }
///
/// let lower = LowerBoundClosed::new(42.0);
/// let upper = efficient_conversion(lower);  // Optimized to direct assignment
/// assert_eq!(upper.as_ref(), &42.0);
/// ```
///
/// ## Type System Guarantees
///
/// ### Compile-Time Verification
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let open_lower = LowerBoundOpen::new(1.0);
/// let open_upper = open_lower.into_upper();
///
/// // Type system ensures correctness
/// let _: UpperBoundOpen<f64> = open_upper;        // ✅ Correct type
/// // let _: UpperBoundClosed<f64> = open_upper;   // ❌ Compile error
/// ```
///
/// ### Mathematical Consistency
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Value and inclusion properties are preserved
/// fn verify_conversion_consistency<T: BoundType>(value: f64)
/// where
///     LowerBound<f64, T>: BoundSideConversion<f64, T>,
/// {
///     let lower = LowerBound::<f64, T>::new(value);
///     let upper = lower.clone().into_upper();
///     let back_to_lower = upper.into_lower();
///     
///     // Value preservation
///     assert_eq!(lower.as_ref(), back_to_lower.as_ref());
///     
///     // Inclusion preservation
///     assert_eq!(lower.is_closed(), back_to_lower.is_closed());
///     assert_eq!(lower.is_open(), back_to_lower.is_open());
/// }
/// ```
///
/// ## Advanced Usage Patterns
///
/// ### Constraint System Building
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// struct ConstraintSystem {
///     lower_bounds: Vec<LowerBoundRuntime<f64>>,
///     upper_bounds: Vec<UpperBoundRuntime<f64>>,
/// }
///
/// impl ConstraintSystem {
///     fn add_lower_bound<B>(mut self, bound: B) -> Self
///     where
///         B: BoundSideConversion<f64, Closed> + Into<LowerBoundRuntime<f64>>,
///     {
///         self.lower_bounds.push(bound.into_lower().into());
///         self
///     }
///     
///     fn add_upper_bound<B>(mut self, bound: B) -> Self
///     where
///         B: BoundSideConversion<f64, Closed> + Into<UpperBoundRuntime<f64>>,
///     {
///         self.upper_bounds.push(bound.into_upper().into());
///         self
///     }
/// }
/// ```
///
/// ### Symmetric Domain Construction
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Build symmetric domains from a single specification
/// fn create_symmetric_domain<T: BoundType>(
///     center: f64,
///     half_width: f64
/// ) -> (LowerBound<f64, T>, UpperBound<f64, T>)
/// where
///     LowerBound<f64, T>: BoundSideConversion<f64, T>,
/// {
///     let lower = LowerBound::<f64, T>::new(center - half_width);
///     let upper = lower.clone().into_upper().with_value(center + half_width);
///     (lower, upper)
/// }
///
/// let (lower, upper) = create_symmetric_domain::<Closed>(0.0, 5.0);
/// assert_eq!(lower.as_ref(), &-5.0);  // [-5
/// assert_eq!(upper.as_ref(), &5.0);   // 5]
/// ```
///
/// ## Best Practices
///
/// ### 1. **Use for Semantic Transformations**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // ✅ GOOD: Converting constraint direction
/// fn convert_minimum_to_maximum(min_bound: LowerBoundClosed<f64>) -> UpperBoundClosed<f64> {
///     min_bound.into_upper()  // Clear semantic transformation
/// }
///
/// // ❌ AVOID: Using when side doesn't need to change
/// fn unnecessary_conversion(bound: LowerBoundClosed<f64>) -> LowerBoundClosed<f64> {
///     bound.into_upper().into_lower()  // Pointless round-trip
/// }
/// ```
///
/// ### 2. **Leverage Type System for Safety**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // ✅ GOOD: Type-guided API design
/// fn build_interval<T: BoundType>(
///     lower_val: f64,
///     upper_val: f64
/// ) -> (LowerBound<f64, T>, UpperBound<f64, T>)
/// where
///     LowerBound<f64, T>: BoundSideConversion<f64, T>,
/// {
///     let lower = LowerBound::<f64, T>::new(lower_val);
///     let upper = lower.clone().into_upper().with_value(upper_val);
///     (lower, upper)
/// }
/// ```
///
/// ### 3. **Combine with Other Bound Operations**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // ✅ GOOD: Chain operations for complex transformations
/// fn create_flipped_bound<T: BoundType, U: BoundType>(
///     original: LowerBound<f64, T>
/// ) -> UpperBound<f64, U>
/// where
///     LowerBound<f64, T>: BoundSideConversion<f64, T>,
///     IntervalBound<f64, Upper, T>: BoundTypeConversion<f64, Upper>,
/// {
///     original.into_upper().with_bound_type::<U>()
/// }
/// ```
///
/// ## Mathematical Guarantees
///
/// The [`BoundSideConversion`] trait maintains mathematical correctness by:
///
/// - **Value Preservation**: Boundary values remain unchanged during conversion
/// - **Inclusion Preservation**: Open/closed semantics are maintained
/// - **Type Safety**: Prevents invalid bound combinations at compile time
/// - **Reversibility**: Conversions are mathematically reversible
/// - **Zero-Cost**: Provides semantic transformations without runtime overhead
///
/// ## Relationship with `flip_bound_side()`
///
/// This trait provides a more ergonomic API compared to the lower-level
/// [`IntervalBound::flip_bound_side()`](IntervalBound::flip_bound_side) method:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let lower = LowerBoundClosed::new(5.0);
///
/// // BoundSideConversion: Target-oriented API
/// let upper = lower.into_upper();  // "I want Upper"
///
/// // flip_bound_side(): Transformation-oriented API  
/// let also_upper = LowerBoundClosed::new(5.0).flip_bound_side();  // "Toggle side"
/// ```
///
/// **Use `into_lower()`/`into_upper()` when**: You want to ensure a specific bound side
/// regardless of the current side (idempotent operations).
///
/// **Use `flip_bound_side()` when**: You explicitly want to toggle between Lower/Upper
/// and the current side matters for your logic.
///
/// Note: The implementations of `into_lower()` and `into_upper()` internally use
/// `flip_bound_side()` when conversion is needed, ensuring code reuse and consistency.
///
/// Use [`BoundSideConversion`] when you need to change constraint direction while
/// maintaining boundary values and inclusion semantics. This trait is essential for
/// interval manipulation, domain transformation, and constraint system construction.
pub trait BoundSideConversion<RealType: RealScalar, Type: BoundType>: Sized {
    /// Convert this bound into a lower bound with the same value and inclusion semantics.
    ///
    /// This method transforms any bound into a lower bound while preserving the scalar
    /// value and boundary inclusion behavior (open/closed). The conversion changes only
    /// the constraint direction.
    ///
    /// # Mathematical Semantics
    ///
    /// - **For upper bounds**: Changes `x ≤/< value` to `x ≥/> value`
    /// - **For lower bounds**: Returns the same bound unchanged (identity conversion)
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    /// use try_create::New;
    ///
    /// // Upper to lower conversion
    /// let upper_closed = UpperBoundClosed::new(10.0);   // x ≤ 10
    /// let lower_closed = upper_closed.into_lower();      // x ≥ 10
    /// assert!(lower_closed.is_lower_bound());
    /// assert!(lower_closed.is_closed());
    /// assert_eq!(lower_closed.as_ref(), &10.0);
    ///
    /// // Lower bound identity conversion
    /// let existing_lower = LowerBoundOpen::new(5.0);     // x > 5
    /// let same_lower = existing_lower.into_lower();       // x > 5 (unchanged)
    /// assert!(same_lower.is_lower_bound());
    /// assert!(same_lower.is_open());
    /// ```
    fn into_lower(self) -> IntervalBound<RealType, Lower, Type>;

    /// Convert this bound into an upper bound with the same value and inclusion semantics.
    ///
    /// This method transforms any bound into an upper bound while preserving the scalar
    /// value and boundary inclusion behavior (open/closed). The conversion changes only
    /// the constraint direction.
    ///
    /// # Mathematical Semantics
    ///
    /// - **For lower bounds**: Changes `x ≥/> value` to `x ≤/< value`
    /// - **For upper bounds**: Returns the same bound unchanged (identity conversion)
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    /// use try_create::New;
    ///
    /// // Lower to upper conversion
    /// let lower_open = LowerBoundOpen::new(0.0);         // x > 0
    /// let upper_open = lower_open.into_upper();           // x < 0
    /// assert!(upper_open.is_upper_bound());
    /// assert!(upper_open.is_open());
    /// assert_eq!(upper_open.as_ref(), &0.0);
    ///
    /// // Upper bound identity conversion
    /// let existing_upper = UpperBoundClosed::new(100.0); // x ≤ 100
    /// let same_upper = existing_upper.into_upper();       // x ≤ 100 (unchanged)
    /// assert!(same_upper.is_upper_bound());
    /// assert!(same_upper.is_closed());
    /// ```
    fn into_upper(self) -> IntervalBound<RealType, Upper, Type>;
}
//------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------
/// Compile-time boundary inclusion semantics for interval bounds.
///
/// [`BoundType`] is a marker trait that encodes whether a boundary includes or excludes
/// its boundary value at the type level. This enables compile-time verification of boundary
/// semantics and zero-cost abstractions for interval arithmetic operations.
///
/// ## Design Philosophy
///
/// ### Compile-Time Type Safety
///
/// Unlike runtime boundary checks, [`BoundType`] moves boundary inclusion semantics into
/// the type system, providing these advantages:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Type system prevents mixing incompatible boundary types
/// let closed_bound = LowerBoundClosed::new(0.0);  // Type: LowerBound<f64, Closed>
/// let open_bound = LowerBoundOpen::new(0.0);      // Type: LowerBound<f64, Open>
///
/// // This would be a compile error:
/// // assert_eq!(closed_bound, open_bound); // ← Cannot compare different BoundTypes
/// ```
///
/// ### Zero-Cost Abstractions
///
/// All methods compile to static constants, providing zero runtime overhead:
///
/// ```rust
/// use grid1d::bounds::*;
///
/// fn check_boundary_inclusion<T: BoundType>() -> &'static str {
///     if T::is_closed() {
///         "Boundary included"  // Optimized to constant at compile time
///     } else {
///         "Boundary excluded"  // Optimized to constant at compile time
///     }
/// }
///
/// assert_eq!(check_boundary_inclusion::<Closed>(), "Boundary included");
/// assert_eq!(check_boundary_inclusion::<Open>(), "Boundary excluded");
/// ```
///
/// ## Mathematical Semantics
///
/// ### Closed Boundaries ([`Closed`])
///
/// Closed boundaries include the boundary value in their constraint:
///
/// | Bound Type | Mathematical Constraint | Notation | Boundary Value |
/// |------------|------------------------|----------|----------------|
/// | `LowerBound<T, Closed>` | `x ≥ bound_value` | `[a` | **Included** |
/// | `UpperBound<T, Closed>` | `x ≤ bound_value` | `b]` | **Included** |
///
/// ### Open Boundaries ([`Open`])
///
/// Open boundaries exclude the boundary value from their constraint:
///
/// | Bound Type | Mathematical Constraint | Notation | Boundary Value |
/// |------------|------------------------|----------|----------------|
/// | `LowerBound<T, Open>` | `x > bound_value` | `(a` | **Excluded** |
/// | `UpperBound<T, Open>` | `x < bound_value` | `b)` | **Excluded** |
///
/// ## Core Methods
///
/// ### [`BoundType::includes_boundary()`]
///
/// The fundamental function that determines boundary inclusion:
///
/// ```rust
/// use grid1d::bounds::*;
///
/// let closed_includes = Closed::includes_boundary(); // true
/// let open_includes = Open::includes_boundary();     // false
///
/// assert!(closed_includes);
/// assert!(!open_includes);
/// ```
///
/// ### [`BoundType::is_open()`] and [`BoundType::is_closed()`]
///
/// Convenience methods that provide semantic clarity:
///
/// ```rust
/// use grid1d::bounds::*;
///
/// // Clear semantic meaning
/// assert!(Closed::is_closed());
/// assert!(!Closed::is_open());
/// assert!(Open::is_open());
/// assert!(!Open::is_closed());
///
/// // These compile to constants and have zero runtime cost
/// ```
///
/// ## Generic Programming Applications
///
/// ### Type-Parameterized Algorithms
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn create_strict_bound<T: BoundType>(value: f64) -> LowerBound<f64, T> {
///     LowerBound::new(value)
/// }
///
/// // Create different bound types from the same function
/// let closed: LowerBoundClosed<f64> = create_strict_bound::<Closed>(5.0);
/// let open: LowerBoundOpen<f64> = create_strict_bound::<Open>(5.0);
///
/// assert!(closed.is_closed());
/// assert!(open.is_open());
/// ```
///
/// ### Compile-Time Interval Construction
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn create_interval<LowerType: BoundType, UpperType: BoundType>(
///     lower: f64,
///     upper: f64
/// ) -> (LowerBound<f64, LowerType>, UpperBound<f64, UpperType>) {
///     (LowerBound::new(lower), UpperBound::new(upper))
/// }
///
/// // Different interval types from the same constructor
/// let (l, u) = create_interval::<Closed, Open>(0.0, 1.0);  // [0, 1)
/// let (l2, u2) = create_interval::<Open, Closed>(0.0, 1.0); // (0, 1]
/// ```
///
/// ### Constraint Optimization
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn optimize_constraint<T: BoundType>(bound: &LowerBound<f64, T>, value: f64) -> bool {
///     // Compile-time optimization based on boundary type
///     if T::is_open() {
///         value > *bound.as_ref()  // Direct comparison, no branching
///     } else {
///         value >= *bound.as_ref() // Direct comparison, no branching
///     }
/// }
///
/// let closed_bound = LowerBoundClosed::new(5.0);
/// let open_bound = LowerBoundOpen::new(5.0);
///
/// assert!(optimize_constraint(&closed_bound, 5.0));   // 5 >= 5 → true
/// assert!(!optimize_constraint(&open_bound, 5.0));    // 5 > 5 → false
/// ```
///
/// ## Trait Bounds and Constraints
///
/// ### Required Trait Implementations
///
/// All [`BoundType`] implementors must support:
/// - **Debug**: For diagnostic output and error messages
/// - **Clone**: For copying boundary type information
/// - **PartialEq + Eq**: For type equality comparisons
/// - **Serialize + Deserialize**: For boundary type serialization
///
/// ### Implementation Requirements
///
/// Implementors must provide only [`BoundType::includes_boundary()`]:
///
/// ```rust
/// use grid1d::bounds::*;
/// use serde::{Deserialize, Serialize};
///
/// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
/// struct CustomBoundType;
///
/// impl BoundType for CustomBoundType {
///     type Opposite = CustomBoundType;  // Self-opposite for demonstration
///
///     fn includes_boundary() -> bool {
///         true  // This is a closed boundary type
///     }
/// }
///
/// // All other methods are automatically provided
/// assert!(CustomBoundType::is_closed());
/// assert!(!CustomBoundType::is_open());
/// ```
///
/// ## Performance Characteristics
///
/// ### Compile-Time Optimization
/// - **Method calls**: All methods compile to constants at call sites
/// - **Memory**: No runtime storage, pure compile-time type information
/// - **Branching**: Type-based dispatch eliminates runtime branching
/// - **Inlining**: All operations are automatically inlined
///
/// ### Comparison with Runtime Checks
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Compile-time (zero cost)
/// fn compile_time_check<T: BoundType>(bound: &LowerBound<f64, T>, value: f64) -> bool {
///     if T::is_open() {
///         value > *bound.as_ref()  // No runtime branching
///     } else {
///         value >= *bound.as_ref() // No runtime branching
///     }
/// }
///
/// // Runtime (small cost)
/// fn runtime_check(bound: &LowerBoundRuntime<f64>, value: f64) -> bool {
///     if bound.is_open() {
///         value > *bound.as_ref()  // Runtime branch
///     } else {
///         value >= *bound.as_ref() // Runtime branch
///     }
/// }
/// ```
///
/// ## Integration with Grid1D
///
/// The [`BoundType`] trait integrates seamlessly with interval construction:
///
/// ```rust
/// use grid1d::{bounds::*, intervals::*};
/// use try_create::{IntoInner, New};
///
/// fn create_typed_interval<LT: BoundType, UT: BoundType>(
///     lower: LowerBound<f64, LT>,
///     upper: UpperBound<f64, UT>
/// ) -> String {
///     let left = if LT::is_closed() { "[" } else { "(" };
///     let right = if UT::is_closed() { "]" } else { ")" };
///     format!("{}{}, {}{}", left, lower.as_ref(), upper.as_ref(), right)
/// }
///
/// let closed_lower = LowerBoundClosed::new(0.0);
/// let open_upper = UpperBoundOpen::new(1.0);
/// assert_eq!(create_typed_interval(closed_lower, open_upper), "[0, 1)");
/// ```
///
/// ## Best Practices
///
/// ### 1. **Use Compile-Time Types When Possible**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // ✅ GOOD: Boundary type known at compile time
/// fn create_closed_constraint(value: f64) -> LowerBoundClosed<f64> {
///     LowerBoundClosed::new(value)
/// }
///
/// // ❌ AVOID: Using runtime types when compile-time is sufficient
/// fn create_runtime_constraint(value: f64) -> LowerBoundRuntime<f64> {
///     IntervalBoundRuntime::Closed(LowerBoundClosed::new(value))
/// }
/// ```
///
/// ### 2. **Leverage Type Parameters for Flexibility**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn create_flexible_bound<T: BoundType>(value: f64) -> LowerBound<f64, T> {
///     LowerBound::new(value)
/// }
///
/// // Caller specifies the exact boundary type needed
/// let closed = create_flexible_bound::<Closed>(5.0);
/// let open = create_flexible_bound::<Open>(5.0);
/// ```
///
/// ### 3. **Use for Generic Algorithm Implementation**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// fn boundary_constraint_message<S: BoundSide, T: BoundType>() -> String {
///     let side = if S::is_lower() { "lower" } else { "upper" };
///     let inclusion = if T::is_closed() { "inclusive" } else { "exclusive" };
///     format!("{} {} boundary", inclusion, side)
/// }
///
/// type ClosedLower = LowerBound<f64, Closed>;
/// type OpenUpper = UpperBound<f64, Open>;
///
/// assert_eq!(boundary_constraint_message::<Lower, Closed>(), "inclusive lower boundary");
/// assert_eq!(boundary_constraint_message::<Upper, Open>(), "exclusive upper boundary");
/// ```
///
/// ## Mathematical Guarantees
///
/// The [`BoundType`] trait maintains mathematical correctness by:
///
/// - **Semantic Consistency**: Methods accurately reflect mathematical boundary inclusion
/// - **Type Safety**: Prevents mixing incompatible boundary semantics at compile time
/// - **Optimization**: Enables compiler optimizations through compile-time constants
/// - **Composability**: Works seamlessly with other traits in the boundary system
///
/// Use [`BoundType`] when you need compile-time boundary semantics with zero runtime cost.
/// For runtime flexibility, use [`BoundTypeChecks`] with [`IntervalBoundRuntime`](crate::bounds::IntervalBoundRuntime).
pub trait BoundType: Debug + Clone + PartialEq + Eq + Serialize + for<'a> Deserialize<'a> {
    /// The opposite bound type (Open ↔ Closed)
    ///
    /// This associated type enables [`flip_bound_type()`](crate::bounds::IntervalBoundRuntime::flip_bound_type)
    /// to return the correct type at compile time without requiring turbofish syntax.
    ///
    /// # Type Relationships
    ///
    /// - `<Open as BoundType>::Opposite = Closed`
    /// - `<Closed as BoundType>::Opposite = Open`
    ///
    /// The constraint `BoundType<Opposite = Self>` ensures that flipping twice
    /// returns to the original type: `Type::Opposite::Opposite = Type`
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    ///
    /// // Open::Opposite is Closed
    /// fn assert_open_opposite_is_closed<T>()
    /// where
    ///     T: BoundType<Opposite = Closed>,
    /// {
    ///     // This function only compiles if T::Opposite = Closed
    /// }
    /// assert_open_opposite_is_closed::<Open>();
    ///
    /// // Closed::Opposite is Open
    /// fn assert_closed_opposite_is_open<T>()
    /// where
    ///     T: BoundType<Opposite = Open>,
    /// {
    ///     // This function only compiles if T::Opposite = Open
    /// }
    /// assert_closed_opposite_is_open::<Closed>();
    ///
    /// // Bidirectional: Type::Opposite::Opposite = Type
    /// fn assert_bidirectional<T>()
    /// where
    ///     T: BoundType,
    ///     T::Opposite: BoundType<Opposite = T>,
    /// {
    ///     // Flipping twice returns to original type
    /// }
    /// assert_bidirectional::<Open>();
    /// assert_bidirectional::<Closed>();
    /// ```
    type Opposite: BoundType<Opposite = Self>;

    /// Returns true if the boundary value is included in the constraint.
    ///
    /// This is the fundamental method that determines boundary inclusion semantics
    /// at compile time. It must return a consistent value for the entire lifetime
    /// of the type.
    ///
    /// # Mathematical Semantics
    ///
    /// - Returns `true` for closed boundaries: boundary value is **included**
    /// - Returns `false` for open boundaries: boundary value is **excluded**
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    ///
    /// // Compile-time constants
    /// assert!(Closed::includes_boundary());  // Closed boundaries include
    /// assert!(!Open::includes_boundary());   // Open boundaries exclude
    /// ```
    fn includes_boundary() -> bool;

    /// Returns true if the boundary value is excluded from the constraint.
    ///
    /// This method is automatically implemented as the logical negation of
    /// [`BoundType::includes_boundary()`], ensuring mathematical consistency.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    ///
    /// assert!(Open::is_open());      // Open boundaries exclude
    /// assert!(!Closed::is_open());   // Closed boundaries include
    /// ```
    #[inline(always)]
    fn is_open() -> bool {
        !Self::includes_boundary()
    }

    /// Returns true if the boundary value is included in the constraint.
    ///
    /// This method is automatically implemented as an alias for
    /// [`BoundType::includes_boundary()`], providing semantic clarity.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    ///
    /// assert!(Closed::is_closed());  // Closed boundaries include
    /// assert!(!Open::is_closed());   // Open boundaries exclude
    /// ```
    #[inline(always)]
    fn is_closed() -> bool {
        Self::includes_boundary()
    }
}
//------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------
/// Convert between open and closed bounds while preserving boundary side and value.
///
/// [`BoundTypeConversion`] provides a unified interface for converting interval bounds
/// between open and closed inclusion semantics while maintaining the same boundary side
/// (lower/upper) and scalar value. This trait enables flexible boundary inclusion manipulation
/// in interval arithmetic and constraint specification operations.
///
/// ## Design Philosophy
///
/// ### Inclusion Semantic Transformation
///
/// Unlike side-changing transformations, [`BoundTypeConversion`] preserves the boundary
/// side and value while changing only the inclusion behavior:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let closed_lower = LowerBoundClosed::new(5.0);    // [5 (lower, closed)
/// let open_lower = closed_lower.into_open();        // (5 (lower, open)
///
/// // Side and value preserved, inclusion changed
/// assert_eq!(open_lower.as_ref(), &5.0);           // Same value
/// assert!(open_lower.is_lower_bound());            // Same side
/// assert!(open_lower.is_open());                   // Different inclusion
/// ```
///
/// ### Type-Safe Inclusion Conversions
///
/// All conversions are compile-time verified and zero-cost:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let open_upper = UpperBoundOpen::new(10.0);      // 10)
/// let closed_upper = open_upper.into_closed();     // 10]
///
/// // Type system ensures consistency
/// let _: UpperBoundClosed<f64> = closed_upper;     // Compile-time verification
/// ```
///
/// ## Mathematical Semantics
///
/// ### Open to Closed Conversion
///
/// Converting an open bound to a closed bound changes the inclusion behavior
/// while preserving the boundary value and side:
///
/// | Original Open Bound | Mathematical Constraint | Converted Closed Bound | New Constraint |
/// |-------------------|------------------------|---------------------|----------------|
/// | `LowerBoundOpen` | `x > value` | `LowerBoundClosed` | `x ≥ value` |
/// | `UpperBoundOpen` | `x < value` | `UpperBoundClosed` | `x ≤ value` |
///
/// ### Closed to Open Conversion
///
/// Converting a closed bound to an open bound changes the inclusion behavior
/// while preserving the boundary value and side:
///
/// | Original Closed Bound | Mathematical Constraint | Converted Open Bound | New Constraint |
/// |---------------------|------------------------|-------------------|----------------|
/// | `LowerBoundClosed` | `x ≥ value` | `LowerBoundOpen` | `x > value` |
/// | `UpperBoundClosed` | `x ≤ value` | `UpperBoundOpen` | `x < value` |
///
/// ## Core Methods
///
/// ### [`BoundTypeConversion::into_open()`]
///
/// Converts any bound to an open bound with the same value and side:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Closed bounds to open bounds
/// let lower_closed = LowerBoundClosed::new(0.0);    // x ≥ 0
/// let lower_open = lower_closed.into_open();         // x > 0
/// assert_eq!(lower_open.as_ref(), &0.0);
/// assert!(lower_open.is_open());
/// assert!(lower_open.is_lower_bound());
///
/// let upper_closed = UpperBoundClosed::new(100.0);  // x ≤ 100
/// let upper_open = upper_closed.into_open();         // x < 100
/// assert_eq!(upper_open.as_ref(), &100.0);
/// assert!(upper_open.is_open());
/// assert!(upper_open.is_upper_bound());
///
/// // Open bounds (identity conversion)
/// let existing_open = LowerBoundOpen::new(25.0);
/// let same_open = existing_open.into_open();         // No change
/// assert_eq!(same_open.as_ref(), &25.0);
/// ```
///
/// ### [`BoundTypeConversion::into_closed()`]
///
/// Converts any bound to a closed bound with the same value and side:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Open bounds to closed bounds
/// let lower_open = LowerBoundOpen::new(5.0);        // x > 5
/// let lower_closed = lower_open.into_closed();       // x ≥ 5
/// assert_eq!(lower_closed.as_ref(), &5.0);
/// assert!(lower_closed.is_closed());
/// assert!(lower_closed.is_lower_bound());
///
/// let upper_open = UpperBoundOpen::new(50.0);       // x < 50
/// let upper_closed = upper_open.into_closed();       // x ≤ 50
/// assert_eq!(upper_closed.as_ref(), &50.0);
/// assert!(upper_closed.is_closed());
/// assert!(upper_closed.is_upper_bound());
///
/// // Closed bounds (identity conversion)
/// let existing_closed = UpperBoundClosed::new(10.0);
/// let same_closed = existing_closed.into_closed();   // No change
/// assert_eq!(same_closed.as_ref(), &10.0);
/// ```
///
/// ## Practical Usage Patterns
///
/// ### Constraint Tightening and Loosening
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Tighten constraints (closed → open)
/// fn make_constraint_stricter<S: BoundSide>(
///     loose_bound: IntervalBound<f64, S, Closed>
/// ) -> IntervalBound<f64, S, Open> {
///     loose_bound.into_open()
/// }
///
/// let loose_lower = LowerBoundClosed::new(0.0);     // x ≥ 0 (includes 0)
/// let strict_lower = make_constraint_stricter(loose_lower.clone()); // x > 0 (excludes 0)
///
/// assert!(loose_lower.value_within_bound(&0.0));    // 0 ≥ 0 → true
/// assert!(!strict_lower.value_within_bound(&0.0));  // 0 > 0 → false
///
/// // Loosen constraints (open → closed)
/// fn make_constraint_more_permissive<S: BoundSide>(
///     strict_bound: IntervalBound<f64, S, Open>
/// ) -> IntervalBound<f64, S, Closed> {
///     strict_bound.into_closed()
/// }
///
/// let strict_upper = UpperBoundOpen::new(10.0);     // x < 10 (excludes 10)
/// let loose_upper = make_constraint_more_permissive(strict_upper.clone()); // x ≤ 10 (includes 10)
///
/// assert!(!strict_upper.value_within_bound(&10.0)); // 10 < 10 → false
/// assert!(loose_upper.value_within_bound(&10.0));   // 10 ≤ 10 → true
/// ```
///
/// ### Dynamic Inclusion Policy
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Adjust inclusion based on numerical context
/// fn create_robust_bound(
///     value: f64,
///     include_boundary: bool
/// ) -> (LowerBoundRuntime<f64>, UpperBoundRuntime<f64>) {
///     let lower_closed = LowerBoundClosed::new(value);
///     let upper_closed = UpperBoundClosed::new(value);
///     
///     if include_boundary {
///         (
///             IntervalBoundRuntime::Closed(lower_closed),
///             IntervalBoundRuntime::Closed(upper_closed)
///         )
///     } else {
///         (
///             IntervalBoundRuntime::Open(lower_closed.into_open()),
///             IntervalBoundRuntime::Open(upper_closed.into_open())
///         )
///     }
/// }
///
/// let (inclusive_lower, inclusive_upper) = create_robust_bound(0.0, true);
/// let (exclusive_lower, exclusive_upper) = create_robust_bound(0.0, false);
///
/// assert!(inclusive_lower.includes_boundary());
/// assert!(!exclusive_lower.includes_boundary());
/// ```
///
/// ### Interval Boundary Adjustment
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Adjust interval boundaries for different mathematical contexts
/// fn adjust_interval_strictness<T: BoundType>(
///     lower: LowerBound<f64, T>,
///     upper: UpperBound<f64, T>,
///     make_strict: bool
/// ) -> (LowerBoundRuntime<f64>, UpperBoundRuntime<f64>)
/// where
///     LowerBound<f64, T>: BoundTypeConversion<f64, Lower>,
///     UpperBound<f64, T>: BoundTypeConversion<f64, Upper>,
/// {
///     if make_strict {
///         (
///             IntervalBoundRuntime::Open(lower.into_open()),
///             IntervalBoundRuntime::Open(upper.into_open())
///         )
///     } else {
///         (
///             IntervalBoundRuntime::Closed(lower.into_closed()),
///             IntervalBoundRuntime::Closed(upper.into_closed())
///         )
///     }
/// }
///
/// let lower = LowerBoundClosed::new(0.0);
/// let upper = UpperBoundClosed::new(1.0);
///
/// let (strict_lower, strict_upper) = adjust_interval_strictness(lower.clone(), upper.clone(), true);
/// let (loose_lower, loose_upper) = adjust_interval_strictness(lower, upper, false);
///
/// assert!(strict_lower.is_open());   // Strict: (0, 1)
/// assert!(loose_lower.is_closed());  // Loose: [0, 1]
/// ```
///
/// ## Integration with Grid1D
///
/// ### Constraint System Flexibility
///
/// ```rust
/// use grid1d::bounds::*;
/// use num_valid::RealScalar;
/// use try_create::New;
///
/// struct FlexibleConstraint<T: RealScalar> {
///     lower: LowerBoundRuntime<T>,
///     upper: UpperBoundRuntime<T>,
/// }
///
/// impl<T: RealScalar> FlexibleConstraint<T> {
///     fn make_inclusive(self) -> Self {
///         let lower = match self.lower {
///             IntervalBoundRuntime::Open(open) => IntervalBoundRuntime::Closed(open.into_closed()),
///             closed => closed,
///         };
///         let upper = match self.upper {
///             IntervalBoundRuntime::Open(open) => IntervalBoundRuntime::Closed(open.into_closed()),
///             closed => closed,
///         };
///         Self { lower, upper }
///     }
///     
///     fn make_exclusive(self) -> Self {
///         let lower = match self.lower {
///             IntervalBoundRuntime::Closed(closed) => IntervalBoundRuntime::Open(closed.into_open()),
///             open => open,
///         };
///         let upper = match self.upper {
///             IntervalBoundRuntime::Closed(closed) => IntervalBoundRuntime::Open(closed.into_open()),
///             open => open,
///         };
///         Self { lower, upper }
///     }
/// }
/// ```
///
/// ### Numerical Robustness
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Handle numerical edge cases with inclusion adjustment
/// fn create_numerically_robust_bounds(
///     value: f64,
///     tolerance: f64
/// ) -> (LowerBoundRuntime<f64>, UpperBoundRuntime<f64>) {
///     let is_zero = value.abs() < tolerance;
///     
///     let lower = LowerBoundClosed::new(value);
///     let upper = UpperBoundClosed::new(value);
///     
///     if is_zero {
///         // For zero, use inclusive bounds to avoid numerical issues
///         (
///             IntervalBoundRuntime::Closed(lower),
///             IntervalBoundRuntime::Closed(upper)
///         )
///     } else {
///         // For non-zero, use exclusive bounds for strict inequalities
///         (
///             IntervalBoundRuntime::Open(lower.into_open()),
///             IntervalBoundRuntime::Open(upper.into_open())
///         )
///     }
/// }
///
/// let (zero_lower, zero_upper) = create_numerically_robust_bounds(0.0, 1e-10);
/// let (nonzero_lower, nonzero_upper) = create_numerically_robust_bounds(1.0, 1e-10);
///
/// assert!(zero_lower.is_closed());    // Inclusive for zero
/// assert!(nonzero_lower.is_open());   // Exclusive for non-zero
/// ```
///
/// ## Performance Characteristics
///
/// ### Zero-Cost Abstractions
/// - **Memory**: No additional storage overhead (phantom type manipulation only)
/// - **Conversion**: Direct field copying with compile-time type transformation
/// - **Runtime**: All conversions compile to simple memory moves
///
/// ### Optimization Benefits
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // This entire conversion compiles to a no-op
/// fn efficient_inclusion_change(bound: LowerBoundOpen<f64>) -> LowerBoundClosed<f64> {
///     bound.into_closed()  // Zero runtime cost
/// }
///
/// let open = LowerBoundOpen::new(42.0);
/// let closed = efficient_inclusion_change(open);  // Optimized to direct assignment
/// assert_eq!(closed.as_ref(), &42.0);
/// ```
///
/// ## Advanced Usage Patterns
///
/// ### Constraint Relaxation Systems
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Progressive constraint relaxation for optimization
/// struct RelaxationSequence {
///     original_lower: LowerBoundClosed<f64>,
///     original_upper: UpperBoundClosed<f64>,
/// }
///
/// impl RelaxationSequence {
///     fn relax_step(&self, step: u32) -> (LowerBoundRuntime<f64>, UpperBoundRuntime<f64>) {
///         match step {
///             0 => (
///                 // Most restrictive: use open bounds
///                 IntervalBoundRuntime::Open(self.original_lower.clone().into_open()),
///                 IntervalBoundRuntime::Open(self.original_upper.clone().into_open())
///             ),
///             1 => (
///                 // Medium: mixed bounds
///                 IntervalBoundRuntime::Closed(self.original_lower.clone()),
///                 IntervalBoundRuntime::Open(self.original_upper.clone().into_open())
///             ),
///             _ => (
///                 // Most permissive: use closed bounds
///                 IntervalBoundRuntime::Closed(self.original_lower.clone()),
///                 IntervalBoundRuntime::Closed(self.original_upper.clone())
///             ),
///         }
///     }
/// }
/// ```
///
/// ### Interval Union and Intersection
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Combine bounds with appropriate inclusion semantics
/// fn combine_bounds_conservatively<S: BoundSide>(
///     bound1: IntervalBound<f64, S, Open>,
///     bound2: IntervalBound<f64, S, Closed>
/// ) -> IntervalBound<f64, S, Closed> {
///     // When combining bounds, choose more permissive inclusion
///     if bound1.as_ref() == bound2.as_ref() {
///         bound2  // Closed is more permissive
///     } else {
///         bound1.into_closed()  // Convert to consistent type
///     }
/// }
///
/// let open_bound = LowerBoundOpen::new(5.0);    // x > 5
/// let closed_bound = LowerBoundClosed::new(5.0); // x ≥ 5
/// let combined = combine_bounds_conservatively(open_bound, closed_bound);
///
/// assert!(combined.is_closed());  // More permissive inclusion chosen
/// assert!(combined.value_within_bound(&5.0));  // Includes boundary
/// ```
///
/// ### Generic Bound Processing
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Process bounds with configurable inclusion policy
/// fn process_bounds_with_policy<S: BoundSide, T: BoundType>(
///     bounds: Vec<IntervalBound<f64, S, T>>,
///     use_inclusive: bool
/// ) -> Vec<IntervalBound<f64, S, Closed>>
/// where
///     IntervalBound<f64, S, T>: BoundTypeConversion<f64, S>,
/// {
///     bounds.into_iter()
///         .map(|bound| {
///             if use_inclusive {
///                 bound.into_closed()
///             } else {
///                 bound.into_open().into_closed()  // Force consistency
///             }
///         })
///         .collect()
/// }
/// ```
///
/// ## Type System Guarantees
///
/// ### Compile-Time Verification
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let closed_lower = LowerBoundClosed::new(1.0);
/// let open_lower = closed_lower.into_open();
///
/// // Type system ensures correctness
/// let _: LowerBoundOpen<f64> = open_lower;        // ✅ Correct type
/// // let _: UpperBoundOpen<f64> = open_lower;     // ❌ Compile error
/// ```
///
/// ### Mathematical Consistency
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // Value and side properties are preserved
/// fn verify_conversion_consistency<S: BoundSide>(value: f64)
/// where
///     IntervalBound<f64, S, Open>: BoundTypeConversion<f64, S>,
/// {
///     let open = IntervalBound::<f64, S, Open>::new(value);
///     let closed = open.clone().into_closed();
///     let back_to_open = closed.into_open();
///     
///     // Value preservation
///     assert_eq!(open.as_ref(), back_to_open.as_ref());
///     
///     // Side preservation
///     assert_eq!(S::is_lower(), S::is_lower());  // Tautology showing consistency
/// }
/// ```
///
/// ## Best Practices
///
/// ### 1. **Use for Semantic Clarity**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // ✅ GOOD: Clear intention for inclusion change
/// fn make_strict_positive_constraint(bound: LowerBoundClosed<f64>) -> LowerBoundOpen<f64> {
///     bound.into_open()  // Clearly excludes zero
/// }
///
/// // ❌ AVOID: Unnecessary conversions
/// fn pointless_conversion(bound: LowerBoundOpen<f64>) -> LowerBoundOpen<f64> {
///     bound.into_closed().into_open()  // Wastes operations
/// }
/// ```
///
/// ### 2. **Combine with Other Transformations**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // ✅ GOOD: Chain operations for complex transformations
/// fn create_opposite_strict_bound(
///     original: LowerBoundClosed<f64>
/// ) -> UpperBoundOpen<f64> {
///     original.into_open()           // Make strict
///             .into_upper()          // Change side
/// }
/// ```
///
/// ### 3. **Consider Mathematical Implications**
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// // ✅ GOOD: Understand the mathematical meaning
/// fn relax_constraint_safely(strict_bound: LowerBoundOpen<f64>) -> LowerBoundClosed<f64> {
///     // Converting x > a to x ≥ a (more permissive)
///     strict_bound.into_closed()
/// }
///
/// fn tighten_constraint_carefully(loose_bound: LowerBoundClosed<f64>) -> LowerBoundOpen<f64> {
///     // Converting x ≥ a to x > a (more restrictive)
///     loose_bound.into_open()
/// }
/// ```
///
/// ## Mathematical Guarantees
///
/// The [`BoundTypeConversion`] trait maintains mathematical correctness by:
///
/// - **Value Preservation**: Boundary values remain unchanged during conversion
/// - **Side Preservation**: Lower/upper semantics are maintained
/// - **Type Safety**: Prevents invalid inclusion combinations at compile time
/// - **Reversibility**: Conversions are mathematically reversible
/// - **Zero-Cost**: Provides semantic transformations without runtime overhead
///
/// ## Relationship with `flip_bound_type()`
///
/// This trait provides a more ergonomic API compared to the lower-level
/// [`IntervalBound::flip_bound_type()`](IntervalBound::flip_bound_type) method:
///
/// ```rust
/// use grid1d::bounds::*;
/// use try_create::New;
///
/// let bound_open = LowerBoundOpen::new(5.0);
///
/// // BoundTypeConversion: Target-oriented API
/// let closed = bound_open.into_closed();  // "I want Closed"
///
/// // flip_bound_type(): Transformation-oriented API  
/// let also_closed = LowerBoundOpen::new(5.0).flip_bound_type();  // "Toggle type"
/// ```
///
/// **Use `into_open()`/`into_closed()` when**: You want to ensure a specific bound type
/// regardless of the current type (idempotent operations).
///
/// **Use `flip_bound_type()` when**: You explicitly want to toggle between Open/Closed
/// and the current type matters for your logic.
///
/// Note: The implementations of `into_open()` and `into_closed()` internally use
/// `flip_bound_type()` when conversion is needed, ensuring code reuse and consistency.
///
/// Use [`BoundTypeConversion`] when you need to change boundary inclusion semantics while
/// maintaining boundary values and sides. This trait is essential for constraint adjustment,
/// numerical robustness, and flexible interval specification systems.
pub trait BoundTypeConversion<RealType: RealScalar, Side: BoundSide>: Sized {
    /// Convert this bound into an open bound with the same side and value.
    ///
    /// This method transforms any bound into an open bound while preserving the scalar
    /// value and boundary side (lower/upper). The conversion changes only the inclusion
    /// behavior, making the constraint more restrictive by excluding the boundary value.
    ///
    /// # Mathematical Semantics
    ///
    /// - **For closed bounds**: Changes inclusion to exclusion (`≥/≤` becomes `>//<`)
    /// - **For open bounds**: Returns the same bound unchanged (identity conversion)
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    /// use try_create::New;
    ///
    /// // Closed to open conversion
    /// let lower_closed = LowerBoundClosed::new(5.0);     // x ≥ 5
    /// let lower_open = lower_closed.into_open();          // x > 5
    /// assert!(lower_open.is_open());
    /// assert!(lower_open.is_lower_bound());
    /// assert_eq!(lower_open.as_ref(), &5.0);
    ///
    /// // Open bound identity conversion
    /// let existing_open = UpperBoundOpen::new(10.0);     // x < 10
    /// let same_open = existing_open.into_open();          // x < 10 (unchanged)
    /// assert!(same_open.is_open());
    /// assert!(same_open.is_upper_bound());
    /// ```
    fn into_open(self) -> IntervalBound<RealType, Side, Open>;

    /// Convert this bound into a closed bound with the same side and value.
    ///
    /// This method transforms any bound into a closed bound while preserving the scalar
    /// value and boundary side (lower/upper). The conversion changes only the inclusion
    /// behavior, making the constraint more permissive by including the boundary value.
    ///
    /// # Mathematical Semantics
    ///
    /// - **For open bounds**: Changes exclusion to inclusion (`>//<` becomes `≥/≤`)
    /// - **For closed bounds**: Returns the same bound unchanged (identity conversion)
    ///
    /// # Examples
    ///
    /// ```rust
    /// use grid1d::bounds::*;
    /// use try_create::New;
    ///
    /// // Open to closed conversion
    /// let upper_open = UpperBoundOpen::new(100.0);       // x < 100
    /// let upper_closed = upper_open.into_closed();        // x ≤ 100
    /// assert!(upper_closed.is_closed());
    /// assert!(upper_closed.is_upper_bound());
    /// assert_eq!(upper_closed.as_ref(), &100.0);
    ///
    /// // Closed bound identity conversion
    /// let existing_closed = LowerBoundClosed::new(0.0);  // x ≥ 0
    /// let same_closed = existing_closed.into_closed();    // x ≥ 0 (unchanged)
    /// assert!(same_closed.is_closed());
    /// assert!(same_closed.is_lower_bound());
    /// ```
    fn into_closed(self) -> IntervalBound<RealType, Side, Closed>;
}
//------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------
/// Trait for testing if a value falls within the constraint defined by a bound
pub trait ValueWithinBound: Sized {
    /// The scalar type used for the bound value.
    type RealType: RealScalar;

    /// Test if a value falls within the bound's constraint
    ///
    /// Returns `true` if the value satisfies the bound's constraint:
    /// - For [`LowerBoundOpen`](crate::bounds::LowerBoundOpen): `value > bound_value`
    /// - For [`LowerBoundClosed`](crate::bounds::LowerBoundClosed): `value >= bound_value`
    /// - For [`UpperBoundOpen`](crate::bounds::UpperBoundOpen): `value < bound_value`
    /// - For [`UpperBoundClosed`](crate::bounds::UpperBoundClosed): `value <= bound_value`
    fn value_within_bound(&self, x: &Self::RealType) -> bool;
}
//------------------------------------------------------------------------------------------------