xlog-solve 0.9.2

Solver services used by XLOG exact inference and verification layers
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
//! Proof artifacts and solve results for SAT/MaxSAT solving.
//!
//! This module provides types for representing solver outputs:
//! - [`SolveProof`]: Proof artifacts with checksums for verification
//! - [`SolveStatus`]: Result status (SAT, UNSAT, Unknown, Optimal)
//! - [`SolveStats`]: Solver statistics (iterations, timing, memory)
//! - [`SolveResult`]: Complete solver result combining status, proof, and stats
//!
//! # Proof Checksums
//!
//! Satisfying assignments include FNV-1a checksums to enable lightweight verification
//! that an assignment hasn't been corrupted during transfer or storage. This is
//! particularly useful for GPU-based solving where results are transferred across
//! memory boundaries.
//!
//! # Example
//!
//! ```
//! use xlog_solve::{SolveResult, SolveStatus, SolveStats};
//!
//! // Create a satisfying result
//! let result = SolveResult::satisfiable(vec![true, false, true]);
//! assert!(result.is_sat());
//!
//! // Add statistics
//! let stats = SolveStats::new(100, 5000, 1024);
//! let result = result.with_stats(stats);
//! assert_eq!(result.stats.iterations, 100);
//! ```

// =============================================================================
// FNV-1a Checksum Helper
// =============================================================================

/// Computes an FNV-1a checksum for a boolean assignment.
///
/// FNV-1a (Fowler-Noll-Vo) is a fast, non-cryptographic hash function
/// suitable for integrity verification. The implementation incorporates
/// both the index and value to ensure position-sensitivity.
///
/// # Arguments
///
/// * `assignment` - The boolean assignment to checksum
///
/// # Returns
///
/// A 64-bit FNV-1a hash of the assignment.
///
/// # Example
///
/// ```ignore
/// let checksum = compute_checksum(&[true, false, true]);
/// assert_ne!(checksum, 0);
/// ```
#[inline]
pub fn compute_checksum(assignment: &[bool]) -> u64 {
    // FNV-1a constants for 64-bit hash
    const FNV_OFFSET_BASIS: u64 = 0xcbf29ce484222325;
    const FNV_PRIME: u64 = 0x100000001b3;

    let mut hash = FNV_OFFSET_BASIS;
    for (i, &val) in assignment.iter().enumerate() {
        // Combine index (upper 32 bits) and value (lower bit) for position-sensitivity
        hash ^= (i as u64) << 32 | (val as u64);
        hash = hash.wrapping_mul(FNV_PRIME);
    }
    hash
}

// =============================================================================
// SolveProof - Proof artifact from solver
// =============================================================================

/// Proof artifact from a SAT/MaxSAT solver.
///
/// Proofs provide evidence of the solver's conclusion. For satisfiable instances,
/// this includes the satisfying assignment with a checksum for verification.
/// For unsatisfiable instances, a proof of unsatisfiability is included.
///
/// # Variants
///
/// - [`Satisfying`](SolveProof::Satisfying): Contains a satisfying assignment with checksum
/// - [`Unsatisfiable`](SolveProof::Unsatisfiable): Proof that no satisfying assignment exists
/// - [`Approximate`](SolveProof::Approximate): Best-effort assignment that may not satisfy all clauses
/// - [`None`](SolveProof::None): No proof available (e.g., timeout before any result)
///
/// # Checksums
///
/// The checksum field uses FNV-1a hashing to enable lightweight verification that
/// an assignment hasn't been corrupted. This is particularly useful for:
/// - Verifying GPU-to-CPU transfers
/// - Detecting memory corruption
/// - Validating serialized/deserialized results
///
/// # Example
///
/// ```
/// use xlog_solve::SolveProof;
///
/// // Create a satisfying proof with automatic checksum
/// let proof = SolveProof::satisfying(vec![true, false, true]);
/// assert!(proof.is_satisfying());
///
/// // Extract the assignment
/// if let Some(assignment) = proof.assignment() {
///     assert_eq!(assignment, &[true, false, true]);
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum SolveProof {
    /// The instance is satisfiable with the given assignment.
    ///
    /// The checksum can be used to verify the assignment's integrity.
    Satisfying {
        /// The satisfying assignment (one boolean per variable).
        assignment: Vec<bool>,
        /// FNV-1a checksum of the assignment for integrity verification.
        checksum: u64,
    },

    /// The instance is unsatisfiable.
    ///
    /// The checksum can be used to verify the proof's integrity
    /// (e.g., if the solver produces resolution proofs).
    Unsatisfiable {
        /// Checksum for proof integrity verification.
        checksum: u64,
    },

    /// An approximate solution from an incomplete solver.
    ///
    /// This is typically produced by local search or heuristic solvers
    /// that may not find a complete satisfying assignment.
    Approximate {
        /// The best assignment found.
        assignment: Vec<bool>,
        /// Number of clauses satisfied by this assignment.
        satisfied_clauses: u32,
        /// Total number of clauses in the instance.
        total_clauses: u32,
        /// Number of solver iterations performed.
        iterations: u32,
    },

    /// No proof available.
    ///
    /// This occurs when the solver times out or is interrupted
    /// before producing any meaningful result.
    #[default]
    None,
}

impl SolveProof {
    /// Creates a satisfying proof with automatic checksum computation.
    ///
    /// # Arguments
    ///
    /// * `assignment` - The satisfying assignment
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// let proof = SolveProof::satisfying(vec![true, false, true]);
    /// assert!(proof.is_satisfying());
    /// ```
    #[inline]
    pub fn satisfying(assignment: Vec<bool>) -> Self {
        let checksum = compute_checksum(&assignment);
        Self::Satisfying {
            assignment,
            checksum,
        }
    }

    /// Creates an unsatisfiability proof.
    ///
    /// The checksum is computed as a sentinel value for the empty proof.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// let proof = SolveProof::unsatisfiable();
    /// assert!(!proof.is_satisfying());
    /// ```
    #[inline]
    pub fn unsatisfiable() -> Self {
        // Use a sentinel value indicating UNSAT - we compute checksum of empty
        // assignment and XOR with a sentinel to distinguish from SAT with empty formula
        let checksum = compute_checksum(&[]).wrapping_mul(0xDEADBEEFCAFEBABE);
        Self::Unsatisfiable { checksum }
    }

    /// Creates an approximate solution proof.
    ///
    /// This is typically used by incomplete solvers (like local search)
    /// that may not find a fully satisfying assignment.
    ///
    /// # Arguments
    ///
    /// * `assignment` - The best assignment found
    /// * `satisfied_clauses` - Number of clauses satisfied
    /// * `total_clauses` - Total number of clauses
    /// * `iterations` - Number of solver iterations performed
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// let proof = SolveProof::approximate(vec![true, false], 8, 10, 1000);
    /// if let SolveProof::Approximate { satisfied_clauses, total_clauses, .. } = proof {
    ///     assert_eq!(satisfied_clauses, 8);
    ///     assert_eq!(total_clauses, 10);
    /// }
    /// ```
    #[inline]
    pub fn approximate(
        assignment: Vec<bool>,
        satisfied_clauses: u32,
        total_clauses: u32,
        iterations: u32,
    ) -> Self {
        Self::Approximate {
            assignment,
            satisfied_clauses,
            total_clauses,
            iterations,
        }
    }

    /// Returns true if this is a satisfying proof.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// assert!(SolveProof::satisfying(vec![true]).is_satisfying());
    /// assert!(!SolveProof::unsatisfiable().is_satisfying());
    /// ```
    #[inline]
    pub fn is_satisfying(&self) -> bool {
        matches!(self, Self::Satisfying { .. })
    }

    /// Returns the assignment if this proof contains one.
    ///
    /// Returns `Some` for [`Satisfying`](SolveProof::Satisfying) and
    /// [`Approximate`](SolveProof::Approximate) variants, `None` otherwise.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// let proof = SolveProof::satisfying(vec![true, false]);
    /// assert_eq!(proof.assignment(), Some(&[true, false][..]));
    ///
    /// let unsat = SolveProof::unsatisfiable();
    /// assert_eq!(unsat.assignment(), None);
    /// ```
    #[inline]
    pub fn assignment(&self) -> Option<&[bool]> {
        match self {
            Self::Satisfying { assignment, .. } => Some(assignment),
            Self::Approximate { assignment, .. } => Some(assignment),
            Self::Unsatisfiable { .. } | Self::None => None,
        }
    }

    /// Returns the checksum if this proof has one.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// let proof = SolveProof::satisfying(vec![true]);
    /// assert!(proof.checksum().is_some());
    /// ```
    #[inline]
    pub fn checksum(&self) -> Option<u64> {
        match self {
            Self::Satisfying { checksum, .. } => Some(*checksum),
            Self::Unsatisfiable { checksum } => Some(*checksum),
            Self::Approximate { .. } | Self::None => None,
        }
    }

    /// Verifies the integrity of a satisfying assignment by recomputing its checksum.
    ///
    /// Returns `true` if the checksum matches, `false` if corrupted.
    /// Returns `None` for non-satisfying proofs.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// let proof = SolveProof::satisfying(vec![true, false]);
    /// assert_eq!(proof.verify_checksum(), Some(true));
    /// ```
    #[inline]
    pub fn verify_checksum(&self) -> Option<bool> {
        match self {
            Self::Satisfying {
                assignment,
                checksum,
            } => Some(compute_checksum(assignment) == *checksum),
            _ => None,
        }
    }

    /// Returns the satisfaction ratio for approximate proofs.
    ///
    /// Returns `Some(ratio)` for [`Approximate`](SolveProof::Approximate) where
    /// ratio = satisfied_clauses / total_clauses. Returns `None` for other variants.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveProof;
    ///
    /// let proof = SolveProof::approximate(vec![true], 8, 10, 100);
    /// assert_eq!(proof.satisfaction_ratio(), Some(0.8));
    /// ```
    #[inline]
    pub fn satisfaction_ratio(&self) -> Option<f64> {
        match self {
            Self::Approximate {
                satisfied_clauses,
                total_clauses,
                ..
            } => {
                if *total_clauses == 0 {
                    Some(0.0)
                } else {
                    Some(*satisfied_clauses as f64 / *total_clauses as f64)
                }
            }
            _ => None,
        }
    }
}

// =============================================================================
// SolveStatus - Result status from solver
// =============================================================================

/// Status of a solve operation.
///
/// Represents the outcome of a SAT/MaxSAT solver execution.
///
/// # Variants
///
/// - [`Sat`](SolveStatus::Sat): Instance is satisfiable
/// - [`Unsat`](SolveStatus::Unsat): Instance is unsatisfiable
/// - [`Unknown`](SolveStatus::Unknown): Could not determine (timeout/resource limit)
/// - [`Optimal`](SolveStatus::Optimal): Found optimal solution with given value (MaxSAT)
///
/// # Example
///
/// ```
/// use xlog_solve::SolveStatus;
///
/// let status = SolveStatus::Sat;
/// assert!(status.is_satisfiable());
/// assert!(status.is_determined());
///
/// let optimal = SolveStatus::Optimal(42);
/// assert_eq!(optimal.optimal_value(), Some(42));
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum SolveStatus {
    /// Instance is satisfiable.
    ///
    /// A satisfying assignment exists and should be available in the proof.
    Sat,

    /// Instance is unsatisfiable.
    ///
    /// No assignment can satisfy all clauses.
    Unsat,

    /// Could not determine satisfiability.
    ///
    /// The solver did not reach a definitive conclusion, typically due to:
    /// - Timeout
    /// - Memory limit
    /// - Iteration limit
    /// - Incomplete search (for approximate solvers)
    #[default]
    Unknown,

    /// Found optimal solution with given value.
    ///
    /// For MaxSAT problems, this indicates the optimal objective value
    /// (e.g., maximum number of satisfied clauses or weighted sum).
    Optimal(u64),
}

impl SolveStatus {
    /// Returns true if the status indicates satisfiability.
    ///
    /// Returns `true` for [`Sat`](SolveStatus::Sat) and [`Optimal`](SolveStatus::Optimal).
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStatus;
    ///
    /// assert!(SolveStatus::Sat.is_satisfiable());
    /// assert!(SolveStatus::Optimal(5).is_satisfiable());
    /// assert!(!SolveStatus::Unsat.is_satisfiable());
    /// ```
    #[inline]
    pub fn is_satisfiable(&self) -> bool {
        matches!(self, Self::Sat | Self::Optimal(_))
    }

    /// Returns true if the status indicates unsatisfiability.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStatus;
    ///
    /// assert!(SolveStatus::Unsat.is_unsatisfiable());
    /// assert!(!SolveStatus::Sat.is_unsatisfiable());
    /// ```
    #[inline]
    pub fn is_unsatisfiable(&self) -> bool {
        matches!(self, Self::Unsat)
    }

    /// Returns true if the solver reached a definitive conclusion.
    ///
    /// Returns `true` for all variants except [`Unknown`](SolveStatus::Unknown).
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStatus;
    ///
    /// assert!(SolveStatus::Sat.is_determined());
    /// assert!(SolveStatus::Unsat.is_determined());
    /// assert!(SolveStatus::Optimal(5).is_determined());
    /// assert!(!SolveStatus::Unknown.is_determined());
    /// ```
    #[inline]
    pub fn is_determined(&self) -> bool {
        !matches!(self, Self::Unknown)
    }

    /// Returns the optimal value if this is an [`Optimal`](SolveStatus::Optimal) status.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStatus;
    ///
    /// assert_eq!(SolveStatus::Optimal(42).optimal_value(), Some(42));
    /// assert_eq!(SolveStatus::Sat.optimal_value(), None);
    /// ```
    #[inline]
    pub fn optimal_value(&self) -> Option<u64> {
        match self {
            Self::Optimal(v) => Some(*v),
            _ => None,
        }
    }
}

// =============================================================================
// SolveStats - Statistics from solving
// =============================================================================

/// Statistics from a solve operation.
///
/// Tracks performance metrics from solver execution including
/// iteration count, timing, and memory usage.
///
/// # Builder Pattern
///
/// `SolveStats` supports a builder pattern for convenient construction:
///
/// ```
/// use xlog_solve::SolveStats;
///
/// let stats = SolveStats::default()
///     .with_iterations(100)
///     .with_duration_us(5000)
///     .with_peak_memory(1024);
///
/// assert_eq!(stats.iterations, 100);
/// assert_eq!(stats.duration_us, 5000);
/// assert_eq!(stats.peak_memory, 1024);
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct SolveStats {
    /// Number of iterations performed by the solver.
    ///
    /// For iterative solvers (like CLS), this is the number of
    /// gradient descent steps. For CDCL solvers, this might be
    /// the number of decisions or conflicts.
    pub iterations: u32,

    /// Wall-clock time spent solving, in microseconds.
    ///
    /// This includes all solver operations but typically excludes
    /// instance setup and result extraction.
    pub duration_us: u64,

    /// Peak memory usage during solving, in bytes.
    ///
    /// This tracks the maximum memory allocated by the solver,
    /// useful for profiling and resource management.
    pub peak_memory: u64,
}

impl SolveStats {
    /// Creates new statistics with all fields specified.
    ///
    /// # Arguments
    ///
    /// * `iterations` - Number of solver iterations
    /// * `duration_us` - Solve time in microseconds
    /// * `peak_memory` - Peak memory usage in bytes
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStats;
    ///
    /// let stats = SolveStats::new(100, 5000, 1024);
    /// assert_eq!(stats.iterations, 100);
    /// ```
    #[inline]
    pub const fn new(iterations: u32, duration_us: u64, peak_memory: u64) -> Self {
        Self {
            iterations,
            duration_us,
            peak_memory,
        }
    }

    /// Sets the iteration count, consuming and returning self.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStats;
    ///
    /// let stats = SolveStats::default().with_iterations(100);
    /// assert_eq!(stats.iterations, 100);
    /// ```
    #[inline]
    pub const fn with_iterations(mut self, iterations: u32) -> Self {
        self.iterations = iterations;
        self
    }

    /// Sets the duration in microseconds, consuming and returning self.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStats;
    ///
    /// let stats = SolveStats::default().with_duration_us(5000);
    /// assert_eq!(stats.duration_us, 5000);
    /// ```
    #[inline]
    pub const fn with_duration_us(mut self, duration_us: u64) -> Self {
        self.duration_us = duration_us;
        self
    }

    /// Sets the peak memory usage in bytes, consuming and returning self.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStats;
    ///
    /// let stats = SolveStats::default().with_peak_memory(1024);
    /// assert_eq!(stats.peak_memory, 1024);
    /// ```
    #[inline]
    pub const fn with_peak_memory(mut self, peak_memory: u64) -> Self {
        self.peak_memory = peak_memory;
        self
    }

    /// Returns the duration in milliseconds (rounded down).
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStats;
    ///
    /// let stats = SolveStats::new(0, 5500, 0);
    /// assert_eq!(stats.duration_ms(), 5);
    /// ```
    #[inline]
    pub const fn duration_ms(&self) -> u64 {
        self.duration_us / 1000
    }

    /// Returns the duration in seconds as a floating-point value.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStats;
    ///
    /// let stats = SolveStats::new(0, 1_500_000, 0);
    /// assert_eq!(stats.duration_secs(), 1.5);
    /// ```
    #[inline]
    pub fn duration_secs(&self) -> f64 {
        self.duration_us as f64 / 1_000_000.0
    }

    /// Returns iterations per second (throughput).
    ///
    /// Returns 0.0 if duration is zero.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveStats;
    ///
    /// let stats = SolveStats::new(1000, 1_000_000, 0);
    /// assert_eq!(stats.iterations_per_sec(), 1000.0);
    /// ```
    #[inline]
    pub fn iterations_per_sec(&self) -> f64 {
        if self.duration_us == 0 {
            0.0
        } else {
            (self.iterations as f64 * 1_000_000.0) / self.duration_us as f64
        }
    }
}

// =============================================================================
// SolveResult - Complete solver result
// =============================================================================

/// Complete result from a solve operation.
///
/// Combines the solve status, proof artifact, and statistics into
/// a single comprehensive result structure.
///
/// # Construction
///
/// Use the constructor methods for common result types:
///
/// ```
/// use xlog_solve::{SolveResult, SolveStats};
///
/// // Satisfiable result
/// let sat = SolveResult::satisfiable(vec![true, false, true]);
/// assert!(sat.is_sat());
///
/// // Unsatisfiable result
/// let unsat = SolveResult::unsatisfiable();
/// assert!(unsat.is_unsat());
///
/// // Unknown result (e.g., timeout)
/// let unknown = SolveResult::unknown(1000);
/// assert!(!unknown.is_sat());
///
/// // With custom statistics
/// let stats = SolveStats::new(100, 5000, 1024);
/// let result = SolveResult::satisfiable(vec![true]).with_stats(stats);
/// ```
///
/// # Example
///
/// ```
/// use xlog_solve::SolveResult;
///
/// let result = SolveResult::satisfiable(vec![true, false]);
///
/// if result.is_sat() {
///     if let Some(assignment) = result.assignment() {
///         println!("Found assignment: {:?}", assignment);
///     }
/// }
/// ```
#[derive(Debug, Clone)]
pub struct SolveResult {
    /// The solve status (SAT, UNSAT, Unknown, Optimal).
    pub status: SolveStatus,

    /// The proof artifact from solving.
    pub proof: SolveProof,

    /// Statistics from the solve operation.
    pub stats: SolveStats,
}

impl SolveResult {
    /// Creates a satisfiable result with the given assignment.
    ///
    /// Automatically computes a checksum for the assignment.
    ///
    /// # Arguments
    ///
    /// * `assignment` - The satisfying assignment
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// let result = SolveResult::satisfiable(vec![true, false, true]);
    /// assert!(result.is_sat());
    /// ```
    #[inline]
    pub fn satisfiable(assignment: Vec<bool>) -> Self {
        Self {
            status: SolveStatus::Sat,
            proof: SolveProof::satisfying(assignment),
            stats: SolveStats::default(),
        }
    }

    /// Creates an unsatisfiable result.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// let result = SolveResult::unsatisfiable();
    /// assert!(result.is_unsat());
    /// ```
    #[inline]
    pub fn unsatisfiable() -> Self {
        Self {
            status: SolveStatus::Unsat,
            proof: SolveProof::unsatisfiable(),
            stats: SolveStats::default(),
        }
    }

    /// Creates an unknown result (e.g., timeout).
    ///
    /// # Arguments
    ///
    /// * `iterations` - Number of iterations performed before giving up
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// let result = SolveResult::unknown(1000);
    /// assert!(!result.is_sat());
    /// assert!(!result.is_unsat());
    /// ```
    #[inline]
    pub fn unknown(iterations: u32) -> Self {
        Self {
            status: SolveStatus::Unknown,
            proof: SolveProof::None,
            stats: SolveStats::default().with_iterations(iterations),
        }
    }

    /// Creates an optimal result (for MaxSAT).
    ///
    /// # Arguments
    ///
    /// * `assignment` - The optimal assignment
    /// * `optimal_value` - The optimal objective value
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::{SolveResult, SolveStatus};
    ///
    /// let result = SolveResult::optimal(vec![true, false], 42);
    /// assert!(matches!(result.status, SolveStatus::Optimal(42)));
    /// ```
    #[inline]
    pub fn optimal(assignment: Vec<bool>, optimal_value: u64) -> Self {
        Self {
            status: SolveStatus::Optimal(optimal_value),
            proof: SolveProof::satisfying(assignment),
            stats: SolveStats::default(),
        }
    }

    /// Creates an approximate result from an incomplete solver.
    ///
    /// # Arguments
    ///
    /// * `assignment` - The best assignment found
    /// * `satisfied_clauses` - Number of satisfied clauses
    /// * `total_clauses` - Total number of clauses
    /// * `iterations` - Number of solver iterations
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// let result = SolveResult::approximate(vec![true, false], 8, 10, 1000);
    /// assert!(!result.is_sat());  // Not definitively SAT
    /// ```
    #[inline]
    pub fn approximate(
        assignment: Vec<bool>,
        satisfied_clauses: u32,
        total_clauses: u32,
        iterations: u32,
    ) -> Self {
        Self {
            status: SolveStatus::Unknown,
            proof: SolveProof::approximate(
                assignment,
                satisfied_clauses,
                total_clauses,
                iterations,
            ),
            stats: SolveStats::default().with_iterations(iterations),
        }
    }

    /// Updates the statistics, consuming and returning self.
    ///
    /// # Arguments
    ///
    /// * `stats` - The new statistics
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::{SolveResult, SolveStats};
    ///
    /// let stats = SolveStats::new(100, 5000, 1024);
    /// let result = SolveResult::satisfiable(vec![true]).with_stats(stats);
    /// assert_eq!(result.stats.iterations, 100);
    /// ```
    #[inline]
    pub fn with_stats(mut self, stats: SolveStats) -> Self {
        self.stats = stats;
        self
    }

    /// Returns true if the result is satisfiable.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// assert!(SolveResult::satisfiable(vec![true]).is_sat());
    /// assert!(!SolveResult::unsatisfiable().is_sat());
    /// ```
    #[inline]
    pub fn is_sat(&self) -> bool {
        self.status.is_satisfiable()
    }

    /// Returns true if the result is unsatisfiable.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// assert!(SolveResult::unsatisfiable().is_unsat());
    /// assert!(!SolveResult::satisfiable(vec![true]).is_unsat());
    /// ```
    #[inline]
    pub fn is_unsat(&self) -> bool {
        self.status.is_unsatisfiable()
    }

    /// Returns the assignment if one is available.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// let result = SolveResult::satisfiable(vec![true, false]);
    /// assert_eq!(result.assignment(), Some(&[true, false][..]));
    /// ```
    #[inline]
    pub fn assignment(&self) -> Option<&[bool]> {
        self.proof.assignment()
    }

    /// Returns the optimal value if this is a MaxSAT result.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// let result = SolveResult::optimal(vec![true], 42);
    /// assert_eq!(result.optimal_value(), Some(42));
    /// ```
    #[inline]
    pub fn optimal_value(&self) -> Option<u64> {
        self.status.optimal_value()
    }

    /// Verifies the integrity of the proof checksum.
    ///
    /// Returns `Some(true)` if the checksum is valid, `Some(false)` if corrupted,
    /// or `None` if verification is not applicable.
    ///
    /// # Example
    ///
    /// ```
    /// use xlog_solve::SolveResult;
    ///
    /// let result = SolveResult::satisfiable(vec![true, false]);
    /// assert_eq!(result.verify_proof(), Some(true));
    /// ```
    #[inline]
    pub fn verify_proof(&self) -> Option<bool> {
        self.proof.verify_checksum()
    }
}

impl Default for SolveResult {
    fn default() -> Self {
        Self {
            status: SolveStatus::Unknown,
            proof: SolveProof::None,
            stats: SolveStats::default(),
        }
    }
}

// =============================================================================
// Tests
// =============================================================================

#[cfg(test)]
mod tests {
    use super::*;

    // ==========================================================================
    // SolveProof Tests
    // ==========================================================================

    #[test]
    fn test_solve_proof_satisfying() {
        let assignment = vec![true, false, true];
        let proof = SolveProof::satisfying(assignment.clone());
        match proof {
            SolveProof::Satisfying {
                assignment: a,
                checksum,
            } => {
                assert_eq!(a, assignment);
                assert_ne!(checksum, 0); // Checksum should be computed
            }
            _ => panic!("Expected Satisfying proof"),
        }
    }

    #[test]
    fn test_solve_proof_unsatisfiable() {
        let proof = SolveProof::unsatisfiable();
        match proof {
            SolveProof::Unsatisfiable { checksum } => {
                // Checksum for empty unsatisfiability proof should be consistent
                assert_ne!(checksum, 0);
            }
            _ => panic!("Expected Unsatisfiable proof"),
        }
    }

    #[test]
    fn test_solve_proof_approximate() {
        let assignment = vec![true, false];
        let proof = SolveProof::approximate(assignment.clone(), 5, 10, 100);
        match proof {
            SolveProof::Approximate {
                assignment: a,
                satisfied_clauses,
                total_clauses,
                iterations,
            } => {
                assert_eq!(a, assignment);
                assert_eq!(satisfied_clauses, 5);
                assert_eq!(total_clauses, 10);
                assert_eq!(iterations, 100);
            }
            _ => panic!("Expected Approximate proof"),
        }
    }

    #[test]
    fn test_solve_proof_none() {
        let proof = SolveProof::None;
        assert!(matches!(proof, SolveProof::None));
    }

    #[test]
    fn test_solve_proof_checksum_deterministic() {
        // Same assignment should produce same checksum
        let assignment = vec![true, false, true, false];
        let proof1 = SolveProof::satisfying(assignment.clone());
        let proof2 = SolveProof::satisfying(assignment);

        let checksum1 = match proof1 {
            SolveProof::Satisfying { checksum, .. } => checksum,
            _ => panic!("Expected Satisfying"),
        };
        let checksum2 = match proof2 {
            SolveProof::Satisfying { checksum, .. } => checksum,
            _ => panic!("Expected Satisfying"),
        };

        assert_eq!(checksum1, checksum2);
    }

    #[test]
    fn test_solve_proof_checksum_different_assignments() {
        // Different assignments should produce different checksums
        let proof1 = SolveProof::satisfying(vec![true, false]);
        let proof2 = SolveProof::satisfying(vec![false, true]);

        let checksum1 = match proof1 {
            SolveProof::Satisfying { checksum, .. } => checksum,
            _ => panic!("Expected Satisfying"),
        };
        let checksum2 = match proof2 {
            SolveProof::Satisfying { checksum, .. } => checksum,
            _ => panic!("Expected Satisfying"),
        };

        assert_ne!(checksum1, checksum2);
    }

    #[test]
    fn test_solve_proof_checksum() {
        // Test from the task spec
        let proof = SolveProof::Satisfying {
            assignment: vec![true, false],
            checksum: 12345,
        };
        match proof {
            SolveProof::Satisfying { checksum, .. } => {
                assert_eq!(checksum, 12345);
            }
            _ => panic!("Wrong proof type"),
        }
    }

    #[test]
    fn test_solve_proof_is_satisfying() {
        let sat_proof = SolveProof::satisfying(vec![true]);
        assert!(sat_proof.is_satisfying());

        let unsat_proof = SolveProof::unsatisfiable();
        assert!(!unsat_proof.is_satisfying());

        let approx_proof = SolveProof::approximate(vec![true], 1, 1, 1);
        assert!(!approx_proof.is_satisfying());

        assert!(!SolveProof::None.is_satisfying());
    }

    #[test]
    fn test_solve_proof_assignment() {
        let assignment = vec![true, false, true];
        let sat_proof = SolveProof::satisfying(assignment.clone());
        assert_eq!(sat_proof.assignment(), Some(&assignment[..]));

        let approx_proof = SolveProof::approximate(assignment.clone(), 2, 3, 10);
        assert_eq!(approx_proof.assignment(), Some(&assignment[..]));

        let unsat_proof = SolveProof::unsatisfiable();
        assert_eq!(unsat_proof.assignment(), None);

        assert_eq!(SolveProof::None.assignment(), None);
    }

    #[test]
    fn test_solve_proof_verify_checksum() {
        let proof = SolveProof::satisfying(vec![true, false, true]);
        assert_eq!(proof.verify_checksum(), Some(true));

        // Manually create a corrupted proof
        let corrupted = SolveProof::Satisfying {
            assignment: vec![true, false, true],
            checksum: 12345, // Wrong checksum
        };
        assert_eq!(corrupted.verify_checksum(), Some(false));
    }

    #[test]
    fn test_solve_proof_satisfaction_ratio() {
        let proof = SolveProof::approximate(vec![true], 8, 10, 100);
        assert_eq!(proof.satisfaction_ratio(), Some(0.8));

        let full = SolveProof::approximate(vec![true], 10, 10, 100);
        assert_eq!(full.satisfaction_ratio(), Some(1.0));

        let empty = SolveProof::approximate(vec![], 0, 0, 100);
        assert_eq!(empty.satisfaction_ratio(), Some(0.0));

        assert_eq!(
            SolveProof::satisfying(vec![true]).satisfaction_ratio(),
            None
        );
    }

    #[test]
    fn test_solve_proof_default() {
        let proof = SolveProof::default();
        assert!(matches!(proof, SolveProof::None));
    }

    // ==========================================================================
    // SolveStatus Tests
    // ==========================================================================

    #[test]
    fn test_solve_status_sat() {
        let status = SolveStatus::Sat;
        assert!(status.is_satisfiable());
        assert!(!status.is_unsatisfiable());
        assert!(status.is_determined());
    }

    #[test]
    fn test_solve_status_unsat() {
        let status = SolveStatus::Unsat;
        assert!(!status.is_satisfiable());
        assert!(status.is_unsatisfiable());
        assert!(status.is_determined());
    }

    #[test]
    fn test_solve_status_unknown() {
        let status = SolveStatus::Unknown;
        assert!(!status.is_satisfiable());
        assert!(!status.is_unsatisfiable());
        assert!(!status.is_determined());
    }

    #[test]
    fn test_solve_status_optimal() {
        let status = SolveStatus::Optimal(42);
        assert!(status.is_satisfiable());
        assert!(!status.is_unsatisfiable());
        assert!(status.is_determined());
        assert_eq!(status.optimal_value(), Some(42));
    }

    #[test]
    fn test_solve_status_optimal_value() {
        assert_eq!(SolveStatus::Sat.optimal_value(), None);
        assert_eq!(SolveStatus::Unsat.optimal_value(), None);
        assert_eq!(SolveStatus::Unknown.optimal_value(), None);
        assert_eq!(SolveStatus::Optimal(100).optimal_value(), Some(100));
    }

    #[test]
    fn test_solve_status_eq() {
        assert_eq!(SolveStatus::Sat, SolveStatus::Sat);
        assert_eq!(SolveStatus::Unsat, SolveStatus::Unsat);
        assert_eq!(SolveStatus::Unknown, SolveStatus::Unknown);
        assert_eq!(SolveStatus::Optimal(5), SolveStatus::Optimal(5));
        assert_ne!(SolveStatus::Optimal(5), SolveStatus::Optimal(6));
        assert_ne!(SolveStatus::Sat, SolveStatus::Unsat);
    }

    #[test]
    fn test_solve_status_default() {
        let status = SolveStatus::default();
        assert!(matches!(status, SolveStatus::Unknown));
    }

    // ==========================================================================
    // SolveStats Tests
    // ==========================================================================

    #[test]
    fn test_solve_stats_default() {
        let stats = SolveStats::default();
        assert_eq!(stats.iterations, 0);
        assert_eq!(stats.duration_us, 0);
        assert_eq!(stats.peak_memory, 0);
    }

    #[test]
    fn test_solve_stats_new() {
        let stats = SolveStats::new(100, 5000, 1024);
        assert_eq!(stats.iterations, 100);
        assert_eq!(stats.duration_us, 5000);
        assert_eq!(stats.peak_memory, 1024);
    }

    #[test]
    fn test_solve_stats_with_iterations() {
        let stats = SolveStats::default().with_iterations(500);
        assert_eq!(stats.iterations, 500);
        assert_eq!(stats.duration_us, 0);
        assert_eq!(stats.peak_memory, 0);
    }

    #[test]
    fn test_solve_stats_with_duration_us() {
        let stats = SolveStats::default().with_duration_us(10000);
        assert_eq!(stats.iterations, 0);
        assert_eq!(stats.duration_us, 10000);
        assert_eq!(stats.peak_memory, 0);
    }

    #[test]
    fn test_solve_stats_with_peak_memory() {
        let stats = SolveStats::default().with_peak_memory(2048);
        assert_eq!(stats.iterations, 0);
        assert_eq!(stats.duration_us, 0);
        assert_eq!(stats.peak_memory, 2048);
    }

    #[test]
    fn test_solve_stats_chained_builders() {
        let stats = SolveStats::default()
            .with_iterations(100)
            .with_duration_us(5000)
            .with_peak_memory(1024);
        assert_eq!(stats.iterations, 100);
        assert_eq!(stats.duration_us, 5000);
        assert_eq!(stats.peak_memory, 1024);
    }

    #[test]
    fn test_solve_stats_duration_ms() {
        let stats = SolveStats::new(0, 5500, 0);
        assert_eq!(stats.duration_ms(), 5);
    }

    #[test]
    fn test_solve_stats_duration_secs() {
        let stats = SolveStats::new(0, 1_500_000, 0);
        assert_eq!(stats.duration_secs(), 1.5);
    }

    #[test]
    fn test_solve_stats_iterations_per_sec() {
        let stats = SolveStats::new(1000, 1_000_000, 0);
        assert_eq!(stats.iterations_per_sec(), 1000.0);

        let zero = SolveStats::new(1000, 0, 0);
        assert_eq!(zero.iterations_per_sec(), 0.0);
    }

    // ==========================================================================
    // SolveResult Tests
    // ==========================================================================

    #[test]
    fn test_solve_result_sat() {
        let result = SolveResult::satisfiable(vec![true, false, true]);
        assert!(matches!(result.status, SolveStatus::Sat));
        assert!(result.proof.is_satisfying());
    }

    #[test]
    fn test_solve_result_unsat() {
        let result = SolveResult::unsatisfiable();
        assert!(matches!(result.status, SolveStatus::Unsat));
        assert!(matches!(result.proof, SolveProof::Unsatisfiable { .. }));
    }

    #[test]
    fn test_solve_result_unknown() {
        let result = SolveResult::unknown(500);
        assert!(matches!(result.status, SolveStatus::Unknown));
        assert_eq!(result.stats.iterations, 500);
    }

    #[test]
    fn test_solve_result_optimal() {
        let result = SolveResult::optimal(vec![true, false], 42);
        assert!(matches!(result.status, SolveStatus::Optimal(42)));
        assert!(result.proof.is_satisfying());
    }

    #[test]
    fn test_solve_result_with_stats() {
        let stats = SolveStats::new(100, 5000, 1024);
        let result = SolveResult::satisfiable(vec![true]).with_stats(stats);
        assert_eq!(result.stats.iterations, 100);
        assert_eq!(result.stats.duration_us, 5000);
        assert_eq!(result.stats.peak_memory, 1024);
    }

    #[test]
    fn test_solve_result_is_sat() {
        assert!(SolveResult::satisfiable(vec![true]).is_sat());
        assert!(!SolveResult::unsatisfiable().is_sat());
        assert!(!SolveResult::unknown(0).is_sat());
        assert!(SolveResult::optimal(vec![true], 5).is_sat());
    }

    #[test]
    fn test_solve_result_is_unsat() {
        assert!(!SolveResult::satisfiable(vec![true]).is_unsat());
        assert!(SolveResult::unsatisfiable().is_unsat());
        assert!(!SolveResult::unknown(0).is_unsat());
        assert!(!SolveResult::optimal(vec![true], 5).is_unsat());
    }

    #[test]
    fn test_solve_result_assignment() {
        let assignment = vec![true, false, true];
        let sat_result = SolveResult::satisfiable(assignment.clone());
        assert_eq!(sat_result.assignment(), Some(&assignment[..]));

        let unsat_result = SolveResult::unsatisfiable();
        assert_eq!(unsat_result.assignment(), None);
    }

    #[test]
    fn test_solve_result_approximate() {
        let result = SolveResult::approximate(vec![true, false], 8, 10, 1000);
        assert!(matches!(result.status, SolveStatus::Unknown));
        match &result.proof {
            SolveProof::Approximate {
                satisfied_clauses,
                total_clauses,
                iterations,
                ..
            } => {
                assert_eq!(*satisfied_clauses, 8);
                assert_eq!(*total_clauses, 10);
                assert_eq!(*iterations, 1000);
            }
            _ => panic!("Expected Approximate proof"),
        }
    }

    #[test]
    fn test_solve_result_optimal_value() {
        let result = SolveResult::optimal(vec![true], 42);
        assert_eq!(result.optimal_value(), Some(42));

        let sat = SolveResult::satisfiable(vec![true]);
        assert_eq!(sat.optimal_value(), None);
    }

    #[test]
    fn test_solve_result_verify_proof() {
        let result = SolveResult::satisfiable(vec![true, false]);
        assert_eq!(result.verify_proof(), Some(true));
    }

    #[test]
    fn test_solve_result_default() {
        let result = SolveResult::default();
        assert!(matches!(result.status, SolveStatus::Unknown));
        assert!(matches!(result.proof, SolveProof::None));
    }

    // ==========================================================================
    // FNV-1a Checksum Tests
    // ==========================================================================

    #[test]
    fn test_compute_checksum_empty() {
        let checksum = compute_checksum(&[]);
        // FNV-1a offset basis
        assert_eq!(checksum, 0xcbf29ce484222325);
    }

    #[test]
    fn test_compute_checksum_single() {
        let checksum_true = compute_checksum(&[true]);
        let checksum_false = compute_checksum(&[false]);
        assert_ne!(checksum_true, checksum_false);
    }

    #[test]
    fn test_compute_checksum_deterministic() {
        let assignment = vec![true, false, true, false, true];
        let c1 = compute_checksum(&assignment);
        let c2 = compute_checksum(&assignment);
        assert_eq!(c1, c2);
    }

    #[test]
    fn test_compute_checksum_order_sensitive() {
        // Different order should produce different checksum
        let c1 = compute_checksum(&[true, false]);
        let c2 = compute_checksum(&[false, true]);
        assert_ne!(c1, c2);
    }
}