|
| 1 | +//! D-DRMC-2: deliberately small, independent FINITE POPULATION audit oracle. |
| 2 | +//! |
| 3 | +//! NOT a physical runtime executor, graph engine, statistical test, proof of |
| 4 | +//! causality, or independent authentication of supplied source data. Reads |
| 5 | +//! one 64x64 QR focus to find concrete counterexamples before a law is admitted. |
| 6 | +//! Hot production folds remain existing Quack/R2IL/mask-risc/native SIMD. |
| 7 | +use crate::{BoundDr64, FrameStore, Truth}; |
| 8 | + |
| 9 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 10 | +pub struct PopulationReport { |
| 11 | + /// Pairs selected by Gamma within this concrete 64x64 focus. |
| 12 | + pub eligible: u32, |
| 13 | + /// Eligible positions with an observed TRUE/valid relationship. |
| 14 | + pub true_pairs: u32, |
| 15 | + /// Eligible positions observed FALSE (counterexamples). |
| 16 | + pub false_pairs: u32, |
| 17 | + /// Eligible positions without a known TRUE/FALSE observation. |
| 18 | + pub unknown_pairs: u32, |
| 19 | +} |
| 20 | + |
| 21 | +impl PopulationReport { |
| 22 | + pub const fn checked(self) -> u32 { |
| 23 | + self.true_pairs + self.false_pairs |
| 24 | + } |
| 25 | + /// Finite-focus only: no statement about unobserved people or any theorem |
| 26 | + /// over every possible population. |
| 27 | + pub fn universal_on_focus(self) -> Result<Self, ClaimRefusal> { |
| 28 | + // Refuted beats unknown (certain-answer semantics): one observed |
| 29 | + // counterexample refutes the claim whatever the unknown pairs hold, |
| 30 | + // so it is reported first and never hidden behind `Unknown`. |
| 31 | + if self.eligible == 0 { |
| 32 | + return Err(ClaimRefusal::Vacuous); |
| 33 | + } |
| 34 | + if self.false_pairs != 0 { |
| 35 | + return Err(ClaimRefusal::Counterexamples(self.false_pairs)); |
| 36 | + } |
| 37 | + if self.unknown_pairs != 0 { |
| 38 | + return Err(ClaimRefusal::Unknown(self.unknown_pairs)); |
| 39 | + } |
| 40 | + Ok(self) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 45 | +pub enum ClaimRefusal { |
| 46 | + DifferentAxes, |
| 47 | + /// The selection is three-valued; Gamma selects or it does not. |
| 48 | + SelectionNotTwoValued, |
| 49 | + /// Gamma and R were not bound to the same issue of the same frame. |
| 50 | + DifferentFrame, |
| 51 | + /// The frame they share is no longer the store's current seal. |
| 52 | + StaleFrame, |
| 53 | + /// Gamma and R read different windows of the frame. |
| 54 | + DifferentFocus, |
| 55 | + Vacuous, |
| 56 | + Unknown(u32), |
| 57 | + Counterexamples(u32), |
| 58 | +} |
| 59 | + |
| 60 | +/// Reference checker over the selection Gamma and the relation R: |
| 61 | +/// 1. Gamma: which DR pairs satisfy the candidate constraints (two-valued); |
| 62 | +/// 2. R: which DR pairs satisfy the proposed relational law, with R's own |
| 63 | +/// validity bits when R's method is three-valued. UNKNOWN is never FALSE. |
| 64 | +/// |
| 65 | +/// It compares the bound axes, that both operands share one current frame |
| 66 | +/// issue and one focus. It does not verify that the source exists or that its |
| 67 | +/// relation facts are true. |
| 68 | +pub fn observe_focus( |
| 69 | + store: &FrameStore, |
| 70 | + gamma: &BoundDr64<'_>, |
| 71 | + relation: &BoundDr64<'_>, |
| 72 | +) -> Result<PopulationReport, ClaimRefusal> { |
| 73 | + if (gamma.method.row, gamma.method.column) != (relation.method.row, relation.method.column) { |
| 74 | + return Err(ClaimRefusal::DifferentAxes); |
| 75 | + } |
| 76 | + if gamma.method.truth != Truth::TwoValued { |
| 77 | + return Err(ClaimRefusal::SelectionNotTwoValued); |
| 78 | + } |
| 79 | + if !gamma.frame.same_issue(&relation.frame) { |
| 80 | + return Err(ClaimRefusal::DifferentFrame); |
| 81 | + } |
| 82 | + if store.check(&gamma.frame).is_err() { |
| 83 | + return Err(ClaimRefusal::StaleFrame); |
| 84 | + } |
| 85 | + if gamma.focus != relation.focus { |
| 86 | + return Err(ClaimRefusal::DifferentFocus); |
| 87 | + } |
| 88 | + let mut report = PopulationReport { |
| 89 | + eligible: 0, |
| 90 | + true_pairs: 0, |
| 91 | + false_pairs: 0, |
| 92 | + unknown_pairs: 0, |
| 93 | + }; |
| 94 | + for i in 0..64 { |
| 95 | + let focus = gamma.rows[i]; |
| 96 | + let known = relation.validity.map_or(u64::MAX, |v| v[i]); |
| 97 | + let positive = focus & relation.rows[i] & known; |
| 98 | + let negative = focus & !relation.rows[i] & known; |
| 99 | + let unknown = focus & !known; |
| 100 | + report.eligible += focus.count_ones(); |
| 101 | + report.true_pairs += positive.count_ones(); |
| 102 | + report.false_pairs += negative.count_ones(); |
| 103 | + report.unknown_pairs += unknown.count_ones(); |
| 104 | + } |
| 105 | + debug_assert_eq!( |
| 106 | + report.eligible, |
| 107 | + report.true_pairs + report.false_pairs + report.unknown_pairs |
| 108 | + ); |
| 109 | + Ok(report) |
| 110 | +} |
0 commit comments