Skip to main content

qualia_core_db/modalities/
evidential_etau.rs

1//! Paraconsistent Eτ Evidential Logic & W3C VCs — plan §7.3 A7.
2//!
3//! Extends the existing paraconsistent logic (`paraconsistent.rs`) with
4//! evidential (μ, λ) packing and W3C Verifiable Credential artifact outputs.
5//!
6//! ## Evidential (μ, λ) packing
7//!
8//! Per plan review note 1, evidential data is packed as two f16 values into
9//! the NQuin metadata modality payload area [0..31] (16 bits each = 32 bits),
10//! preserving the Lamport clock [32..60] and routing lane [61..62].
11//!
12//! - **μ (mu)**: evidential support — degree of positive evidence [0, 1].
13//! - **λ (lambda)**: evidential refutation — degree of negative evidence [0, 1].
14//! - **G (combined)**: paraconsistent truth value = μ - λ, in [-1, 1].
15//!   G ≥ 0.5 → route to quarantine (contradiction), G ≤ -0.5 → reject.
16//!
17//! ## Opcodes
18//!
19//! Extends the paraconsistent opcode range (0x30-0x32 in `paraconsistent.rs`):
20//! - `OP_EVIDENTIAL_PACK` (0x33): pack (μ, λ) into a Quin's metadata.
21//! - `OP_EVIDENTIAL_SCORE` (0x34): compute G from a Quin's packed (μ, λ).
22//! - `OP_EVIDENTIAL_VC` (0x35): emit a W3C Verifiable Credential artifact
23//!   containing the evidential claim.
24//!
25//! ## W3C VC integration
26//!
27//! Evidential claims can be sealed into `crypto::verifiable_credential::Credential`
28//! artifacts, providing tamper-evident attestation of evidential assessments.
29
30use crate::modalities::paraconsistent::{global_saturation, is_saturated, Belnap};
31use crate::NQuin;
32
33// ── Opcodes ────────────────────────────────────────────────────────────────
34
35/// Pack (μ, λ) evidential values into a Quin's metadata.
36pub const OP_EVIDENTIAL_PACK: u8 = 0x33;
37/// Compute the evidential score G from packed (μ, λ).
38pub const OP_EVIDENTIAL_SCORE: u8 = 0x34;
39/// Emit a W3C Verifiable Credential artifact for an evidential claim.
40pub const OP_EVIDENTIAL_VC: u8 = 0x35;
41
42// ── f16 conversion ─────────────────────────────────────────────────────────
43
44/// Convert an f32 to a 16-bit half-precision float (IEEE 754 binary16).
45/// This is a pure-Rust implementation with no external dependency.
46pub fn f32_to_f16(f: f32) -> u16 {
47    let bits = f.to_bits();
48    let sign = ((bits >> 16) & 0x8000) as u16;
49    let exp = ((bits >> 23) & 0xFF) as i32;
50    let mant = bits & 0x7FFFFF;
51
52    if exp == 0xFF {
53        // Inf or NaN
54        if mant == 0 {
55            return sign | 0x7C00; // Inf
56        }
57        return sign | 0x7C00 | ((mant >> 13) as u16 | 0x0200); // NaN
58    }
59
60    let new_exp = exp - 127 + 15;
61    if new_exp >= 0x1F {
62        // Overflow → Inf
63        return sign | 0x7C00;
64    }
65    if new_exp <= 0 {
66        // Subnormal or zero
67        if new_exp < -10 {
68            return sign; // Too small → zero
69        }
70        let mant = mant | 0x800000;
71        let shift = 14 - new_exp;
72        let hmant = (mant >> shift) as u16;
73        // Round to nearest even
74        let rem = mant & ((1 << shift) - 1);
75        let half = 1 << (shift - 1);
76        if rem > half || (rem == half && hmant & 1 != 0) {
77            return sign | (hmant + 1);
78        }
79        return sign | hmant;
80    }
81
82    // Normalized
83    let hmant = (mant >> 13) as u16;
84    let rem = mant & 0x1FFF;
85    let half = 0x1000;
86    if rem > half || (rem == half && hmant & 1 != 0) {
87        let rounded = hmant + 1;
88        if rounded >= 0x400 {
89            // Rounding caused mantissa overflow → exp++
90            return sign | (((new_exp as u16) + 1) << 10);
91        }
92        return sign | ((new_exp as u16) << 10) | rounded;
93    }
94    sign | ((new_exp as u16) << 10) | hmant
95}
96
97/// Convert a 16-bit half-precision float to f32.
98pub fn f16_to_f32(h: u16) -> f32 {
99    let sign = ((h & 0x8000) as u32) << 16;
100    let exp = ((h >> 10) & 0x1F) as i32;
101    let mant = (h & 0x3FF) as u32;
102
103    if exp == 0 {
104        if mant == 0 {
105            return f32::from_bits(sign);
106        }
107        // Subnormal
108        let mut e = -1;
109        let mut m = mant;
110        while m & 0x400 == 0 {
111            m <<= 1;
112            e -= 1;
113        }
114        m &= 0x3FF;
115        let new_exp = (127 + e - 14) as u32;
116        return f32::from_bits(sign | (new_exp << 23) | (m << 13));
117    }
118
119    if exp == 0x1F {
120        if mant == 0 {
121            return f32::from_bits(sign | 0x7F800000); // Inf
122        }
123        return f32::from_bits(sign | 0x7F800000 | (mant << 13)); // NaN
124    }
125
126    let new_exp = (exp + 127 - 15) as u32;
127    f32::from_bits(sign | (new_exp << 23) | (mant << 13))
128}
129
130// ── Evidential values ──────────────────────────────────────────────────────
131
132/// Evidential (μ, λ) pair — support and refutation degrees.
133#[derive(Debug, Clone, Copy, PartialEq)]
134pub struct EvidentialPair {
135    /// μ (mu) — degree of positive evidence [0, 1].
136    pub mu: f32,
137    /// λ (lambda) — degree of negative evidence [0, 1].
138    pub lambda: f32,
139}
140
141impl EvidentialPair {
142    /// Create a pair with `mu`/`lambda` clamped into `[0, 1]` — inputs
143    /// outside the unit interval saturate rather than error.
144    pub fn new(mu: f32, lambda: f32) -> Self {
145        Self {
146            mu: mu.clamp(0.0, 1.0),
147            lambda: lambda.clamp(0.0, 1.0),
148        }
149    }
150
151    /// Combined evidential score G = μ - λ, in [-1, 1].
152    pub fn g(&self) -> f32 {
153        self.mu - self.lambda
154    }
155
156    /// Is this a strong positive claim? (G ≥ 0.5)
157    pub fn is_strong_positive(&self) -> bool {
158        self.g() >= 0.5
159    }
160
161    /// Is this a strong negative claim? (G ≤ -0.5)
162    pub fn is_strong_negative(&self) -> bool {
163        self.g() <= -0.5
164    }
165
166    /// Is this a contradiction? (both μ ≥ 0.5 and λ ≥ 0.5)
167    pub fn is_contradiction(&self) -> bool {
168        self.mu >= 0.5 && self.lambda >= 0.5
169    }
170
171    /// Convert to Belnap four-valued logic.
172    pub fn to_belnap(&self) -> Belnap {
173        Belnap::from_evidence(self.mu >= 0.5, self.lambda >= 0.5)
174    }
175
176    /// Pack into 32 bits: μ as f16 in [0..15], λ as f16 in [16..31].
177    pub fn pack(&self) -> u32 {
178        let mu_h = f32_to_f16(self.mu) as u32;
179        let lambda_h = f32_to_f16(self.lambda) as u32;
180        mu_h | (lambda_h << 16)
181    }
182
183    /// Unpack from 32 bits: μ from [0..15], λ from [16..31].
184    pub fn unpack(packed: u32) -> Self {
185        let mu = f16_to_f32((packed & 0xFFFF) as u16);
186        let lambda = f16_to_f32((packed >> 16) as u16);
187        Self { mu, lambda }
188    }
189
190    /// Pack into an NQuin's metadata modality payload area [0..31],
191    /// preserving the Lamport clock [32..60] and routing lane [61..62].
192    pub fn pack_into_metadata(&self, metadata: u64) -> u64 {
193        let packed = self.pack() as u64;
194        (metadata & !0xFFFFFFFF) | packed
195    }
196
197    /// Unpack from an NQuin's metadata modality payload area [0..31].
198    pub fn unpack_from_metadata(metadata: u64) -> Self {
199        Self::unpack((metadata & 0xFFFFFFFF) as u32)
200    }
201}
202
203impl Default for EvidentialPair {
204    /// The empty-evidence pair (`μ = 0, λ = 0` — neither supported nor
205    /// refuted).
206    fn default() -> Self {
207        Self {
208            mu: 0.0,
209            lambda: 0.0,
210        }
211    }
212}
213
214// ── Evidential Quin operations ─────────────────────────────────────────────
215
216/// Pack (μ, λ) evidential values into a Quin's metadata.
217/// The opcode is set in the predicate's low byte.
218pub fn pack_evidential(mut quin: NQuin, mu: f32, lambda: f32) -> NQuin {
219    let pair = EvidentialPair::new(mu, lambda);
220    quin.metadata = pair.pack_into_metadata(quin.metadata);
221    // Set the opcode in the predicate's low byte.
222    quin.predicate = (quin.predicate & !0xFF) | OP_EVIDENTIAL_PACK as u64;
223    // Recompute parity.
224    quin.parity = quin.subject ^ quin.predicate ^ quin.object ^ quin.context ^ quin.metadata;
225    quin
226}
227
228/// Extract the evidential (μ, λ) pair from a Quin's metadata.
229pub fn extract_evidential(quin: &NQuin) -> EvidentialPair {
230    EvidentialPair::unpack_from_metadata(quin.metadata)
231}
232
233/// Compute the evidential score G from a Quin's packed (μ, λ).
234pub fn evidential_score(quin: &NQuin) -> f32 {
235    extract_evidential(quin).g()
236}
237
238/// Route an evidential Quin based on its G score:
239/// - G ≥ 0.5 → quarantine (strong positive, needs verification)
240/// - G ≤ -0.5 → reject (strong negative)
241/// - |G| < 0.5 → normal (insufficient evidence either way)
242/// - μ ≥ 0.5 and λ ≥ 0.5 → contradiction (route to isolated context)
243#[derive(Debug, Clone, Copy, PartialEq, Eq)]
244pub enum EvidentialRoute {
245    /// Normal — insufficient evidence either way.
246    Normal,
247    /// Quarantine — strong positive claim, needs verification.
248    Quarantine,
249    /// Reject — strong negative claim.
250    Reject,
251    /// Contradiction — both positive and negative evidence ≥ 0.5.
252    Contradiction,
253}
254
255/// Determine the routing for an evidential Quin.
256pub fn route_evidential(quin: &NQuin) -> EvidentialRoute {
257    let pair = extract_evidential(quin);
258    if pair.is_contradiction() {
259        EvidentialRoute::Contradiction
260    } else if pair.is_strong_positive() {
261        EvidentialRoute::Quarantine
262    } else if pair.is_strong_negative() {
263        EvidentialRoute::Reject
264    } else {
265        EvidentialRoute::Normal
266    }
267}
268
269/// Route a batch of evidential Quins into normal, quarantine, reject, and
270/// contradiction buckets. Returns counts for each.
271pub fn route_evidential_batch(
272    quins: &[NQuin],
273    out_normal: &mut [NQuin],
274    out_quarantine: &mut [NQuin],
275    out_reject: &mut [NQuin],
276    out_contradiction: &mut [NQuin],
277) -> Result<(usize, usize, usize, usize), EvidentialError> {
278    let mut n = 0;
279    let mut q = 0;
280    let mut r = 0;
281    let mut c = 0;
282    for quin in quins {
283        match route_evidential(quin) {
284            EvidentialRoute::Normal => {
285                if n >= out_normal.len() {
286                    return Err(EvidentialError::BufferOverflow);
287                }
288                out_normal[n] = *quin;
289                n += 1;
290            }
291            EvidentialRoute::Quarantine => {
292                if q >= out_quarantine.len() {
293                    return Err(EvidentialError::BufferOverflow);
294                }
295                out_quarantine[q] = *quin;
296                q += 1;
297            }
298            EvidentialRoute::Reject => {
299                if r >= out_reject.len() {
300                    return Err(EvidentialError::BufferOverflow);
301                }
302                out_reject[r] = *quin;
303                r += 1;
304            }
305            EvidentialRoute::Contradiction => {
306                if c >= out_contradiction.len() {
307                    return Err(EvidentialError::BufferOverflow);
308                }
309                out_contradiction[c] = *quin;
310                c += 1;
311            }
312        }
313    }
314    Ok((n, q, r, c))
315}
316
317#[derive(Debug)]
318pub enum EvidentialError {
319    BufferOverflow,
320}
321
322// ── Evidential saturation ──────────────────────────────────────────────────
323
324/// Evidential saturation: the fraction of Quins that are contradictions
325/// or in quarantine. Uses the existing `global_saturation` function.
326pub fn evidential_saturation(normal: usize, flagged: usize) -> f32 {
327    global_saturation(normal, flagged)
328}
329
330/// Check if evidential saturation exceeds a threshold.
331pub fn is_evidentially_saturated(normal: usize, flagged: usize, threshold: f32) -> bool {
332    is_saturated(evidential_saturation(normal, flagged), threshold)
333}
334
335// ── W3C VC integration ─────────────────────────────────────────────────────
336
337/// An evidential claim suitable for sealing into a W3C Verifiable Credential.
338#[derive(Debug, Clone, PartialEq)]
339pub struct EvidentialClaim {
340    /// The subject of the claim (agent/entity DID hash).
341    pub subject: u64,
342    /// The predicate (property) being attested.
343    pub predicate: u64,
344    /// The object (value) being attested.
345    pub object: u64,
346    /// The context (graph) of the claim.
347    pub context: u64,
348    /// The evidential (μ, λ) pair.
349    pub evidence: EvidentialPair,
350    /// The route determined for this claim.
351    pub route: EvidentialRoute,
352}
353
354impl EvidentialClaim {
355    /// Create an evidential claim from a Quin.
356    pub fn from_quin(quin: &NQuin) -> Self {
357        let evidence = extract_evidential(quin);
358        let route = route_evidential(quin);
359        Self {
360            subject: quin.subject,
361            predicate: quin.predicate >> 8, // Strip opcode
362            object: quin.object,
363            context: quin.context,
364            evidence,
365            route,
366        }
367    }
368
369    /// Convert to an NQuin suitable for inclusion in a Credential's claims.
370    pub fn to_claim_quin(&self) -> NQuin {
371        let mut q = NQuin {
372            subject: self.subject,
373            predicate: (self.predicate << 8) | OP_EVIDENTIAL_VC as u64,
374            object: self.object,
375            context: self.context,
376            metadata: self.evidence.pack_into_metadata(0),
377            parity: 0,
378        };
379        q.parity = q.subject ^ q.predicate ^ q.object ^ q.context ^ q.metadata;
380        q
381    }
382
383    /// Human-readable description.
384    pub fn describe(&self) -> String {
385        let route_str = match self.route {
386            EvidentialRoute::Normal => "normal",
387            EvidentialRoute::Quarantine => "quarantine",
388            EvidentialRoute::Reject => "reject",
389            EvidentialRoute::Contradiction => "contradiction",
390        };
391        format!(
392            "evidential claim: subject={} pred={} obj={} ctx={} μ={:.3} λ={:.3} G={:.3} route={}",
393            self.subject,
394            self.predicate,
395            self.object,
396            self.context,
397            self.evidence.mu,
398            self.evidence.lambda,
399            self.evidence.g(),
400            route_str
401        )
402    }
403}
404
405// ── Tests ──────────────────────────────────────────────────────────────────
406
407#[cfg(test)]
408mod tests {
409    use super::*;
410
411    #[test]
412    fn f16_roundtrip_zero() {
413        assert_eq!(f16_to_f32(f32_to_f16(0.0)), 0.0);
414        assert_eq!(f16_to_f32(f32_to_f16(-0.0)), -0.0);
415    }
416
417    #[test]
418    fn f16_roundtrip_one() {
419        let h = f32_to_f16(1.0);
420        let f = f16_to_f32(h);
421        assert!((f - 1.0).abs() < 1e-6);
422    }
423
424    #[test]
425    fn f16_roundtrip_half() {
426        let h = f32_to_f16(0.5);
427        let f = f16_to_f32(h);
428        assert!((f - 0.5).abs() < 1e-6);
429    }
430
431    #[test]
432    fn f16_roundtrip_small() {
433        let h = f32_to_f16(0.001);
434        let f = f16_to_f32(h);
435        assert!((f - 0.001).abs() < 0.0001, "f16 roundtrip 0.001: got {f}");
436    }
437
438    #[test]
439    fn f16_inf_and_nan() {
440        let inf_h = f32_to_f16(f32::INFINITY);
441        assert_eq!(f16_to_f32(inf_h), f32::INFINITY);
442        let neg_inf_h = f32_to_f16(f32::NEG_INFINITY);
443        assert_eq!(f16_to_f32(neg_inf_h), f32::NEG_INFINITY);
444        let nan_h = f32_to_f16(f32::NAN);
445        assert!(f16_to_f32(nan_h).is_nan());
446    }
447
448    #[test]
449    fn evidential_pair_basic() {
450        let p = EvidentialPair::new(0.8, 0.2);
451        assert!((p.g() - 0.6).abs() < 1e-6);
452        assert!(p.is_strong_positive());
453        assert!(!p.is_strong_negative());
454        assert!(!p.is_contradiction());
455    }
456
457    #[test]
458    fn evidential_pair_contradiction() {
459        let p = EvidentialPair::new(0.7, 0.6);
460        assert!(p.is_contradiction());
461        assert!(p.to_belnap().is_contradiction());
462    }
463
464    #[test]
465    fn evidential_pair_strong_negative() {
466        let p = EvidentialPair::new(0.1, 0.8);
467        assert!(p.is_strong_negative());
468        assert!(!p.is_strong_positive());
469    }
470
471    #[test]
472    fn evidential_pair_clamp() {
473        let p = EvidentialPair::new(1.5, -0.3);
474        assert_eq!(p.mu, 1.0);
475        assert_eq!(p.lambda, 0.0);
476    }
477
478    #[test]
479    fn evidential_pack_unpack() {
480        let p = EvidentialPair::new(0.75, 0.25);
481        let packed = p.pack();
482        let unpacked = EvidentialPair::unpack(packed);
483        assert!((unpacked.mu - 0.75).abs() < 0.01);
484        assert!((unpacked.lambda - 0.25).abs() < 0.01);
485    }
486
487    #[test]
488    fn evidential_pack_into_metadata_preserves_lamport() {
489        // metadata with Lamport clock in [32..60] = 12345
490        let metadata: u64 = (12345u64 << 32) | 0b11 << 61;
491        let p = EvidentialPair::new(0.8, 0.3);
492        let packed = p.pack_into_metadata(metadata);
493        // Lamport clock should be preserved.
494        let lamport = (packed >> 32) & 0x7FFFFFF;
495        assert_eq!(lamport, 12345);
496        // Routing lane should be preserved.
497        let lane = (packed >> 61) & 0b11;
498        assert_eq!(lane, 0b11);
499        // Evidential data should be in [0..31].
500        let unpacked = EvidentialPair::unpack_from_metadata(packed);
501        assert!((unpacked.mu - 0.8).abs() < 0.01);
502        assert!((unpacked.lambda - 0.3).abs() < 0.01);
503    }
504
505    #[test]
506    fn pack_evidential_into_quin() {
507        let q = NQuin {
508            subject: 1,
509            predicate: 2,
510            object: 3,
511            context: 4,
512            metadata: 0,
513            parity: 0,
514        };
515        let packed = pack_evidential(q, 0.9, 0.1);
516        // Opcode should be set.
517        assert_eq!((packed.predicate & 0xFF) as u8, OP_EVIDENTIAL_PACK);
518        // Evidential data should be extractable.
519        let ev = extract_evidential(&packed);
520        assert!((ev.mu - 0.9).abs() < 0.01);
521        assert!((ev.lambda - 0.1).abs() < 0.01);
522    }
523
524    #[test]
525    fn evidential_score_from_quin() {
526        let q = NQuin {
527            subject: 1,
528            predicate: 2,
529            object: 3,
530            context: 4,
531            metadata: 0,
532            parity: 0,
533        };
534        let packed = pack_evidential(q, 0.8, 0.2);
535        let g = evidential_score(&packed);
536        assert!((g - 0.6).abs() < 0.01);
537    }
538
539    #[test]
540    fn route_evidential_normal() {
541        let q = pack_evidential(NQuin::default(), 0.3, 0.2);
542        assert_eq!(route_evidential(&q), EvidentialRoute::Normal);
543    }
544
545    #[test]
546    fn route_evidential_quarantine() {
547        let q = pack_evidential(NQuin::default(), 0.8, 0.1);
548        assert_eq!(route_evidential(&q), EvidentialRoute::Quarantine);
549    }
550
551    #[test]
552    fn route_evidential_reject() {
553        let q = pack_evidential(NQuin::default(), 0.1, 0.9);
554        assert_eq!(route_evidential(&q), EvidentialRoute::Reject);
555    }
556
557    #[test]
558    fn route_evidential_contradiction() {
559        let q = pack_evidential(NQuin::default(), 0.7, 0.6);
560        assert_eq!(route_evidential(&q), EvidentialRoute::Contradiction);
561    }
562
563    #[test]
564    fn route_evidential_batch_all_four() {
565        let normal = pack_evidential(
566            NQuin {
567                subject: 1,
568                ..Default::default()
569            },
570            0.3,
571            0.2,
572        );
573        let quarantine = pack_evidential(
574            NQuin {
575                subject: 2,
576                ..Default::default()
577            },
578            0.9,
579            0.1,
580        );
581        let reject = pack_evidential(
582            NQuin {
583                subject: 3,
584                ..Default::default()
585            },
586            0.1,
587            0.8,
588        );
589        let contradiction = pack_evidential(
590            NQuin {
591                subject: 4,
592                ..Default::default()
593            },
594            0.7,
595            0.6,
596        );
597        let quins = vec![normal, quarantine, reject, contradiction];
598        let mut out_n = [NQuin::default(); 10];
599        let mut out_q = [NQuin::default(); 10];
600        let mut out_r = [NQuin::default(); 10];
601        let mut out_c = [NQuin::default(); 10];
602        let (n, q, r, c) =
603            route_evidential_batch(&quins, &mut out_n, &mut out_q, &mut out_r, &mut out_c).unwrap();
604        assert_eq!((n, q, r, c), (1, 1, 1, 1));
605        assert_eq!(out_n[0].subject, 1);
606        assert_eq!(out_q[0].subject, 2);
607        assert_eq!(out_r[0].subject, 3);
608        assert_eq!(out_c[0].subject, 4);
609    }
610
611    #[test]
612    fn evidential_saturation_check() {
613        // global_saturation(consistent, isolated) = isolated / (consistent + isolated)
614        let s = evidential_saturation(80, 20);
615        assert!((s - 0.2).abs() < 1e-6);
616        assert!(is_evidentially_saturated(80, 20, 0.15));
617        assert!(!is_evidentially_saturated(80, 20, 0.5));
618    }
619
620    #[test]
621    fn evidential_claim_from_quin() {
622        // NQuin predicate: [8..62]=property-path hash, [0..7]=opcode.
623        // So predicate 100 must be stored as 100 << 8.
624        let q = pack_evidential(
625            NQuin {
626                subject: 42,
627                predicate: 100 << 8,
628                object: 200,
629                context: 300,
630                metadata: 0,
631                parity: 0,
632            },
633            0.85,
634            0.15,
635        );
636        let claim = EvidentialClaim::from_quin(&q);
637        assert_eq!(claim.subject, 42);
638        assert_eq!(claim.predicate, 100); // opcode stripped by >> 8
639        assert_eq!(claim.object, 200);
640        assert_eq!(claim.context, 300);
641        assert!((claim.evidence.mu - 0.85).abs() < 0.01);
642        assert_eq!(claim.route, EvidentialRoute::Quarantine);
643    }
644
645    #[test]
646    fn evidential_claim_to_quin_roundtrip() {
647        let original = pack_evidential(
648            NQuin {
649                subject: 1,
650                predicate: 2 << 8,
651                object: 3,
652                context: 4,
653                metadata: 0,
654                parity: 0,
655            },
656            0.6,
657            0.4,
658        );
659        let claim = EvidentialClaim::from_quin(&original);
660        let claim_quin = claim.to_claim_quin();
661        // The claim quin should have the evidential VC opcode.
662        assert_eq!((claim_quin.predicate & 0xFF) as u8, OP_EVIDENTIAL_VC);
663        // The evidential data should be preserved.
664        let ev = extract_evidential(&claim_quin);
665        assert!((ev.mu - 0.6).abs() < 0.01);
666        assert!((ev.lambda - 0.4).abs() < 0.01);
667    }
668
669    #[test]
670    fn evidential_claim_describe() {
671        let q = pack_evidential(
672            NQuin {
673                subject: 1,
674                predicate: 2,
675                object: 3,
676                context: 4,
677                metadata: 0,
678                parity: 0,
679            },
680            0.8,
681            0.1,
682        );
683        let claim = EvidentialClaim::from_quin(&q);
684        let desc = claim.describe();
685        assert!(desc.contains("μ=0.8"));
686        assert!(desc.contains("λ=0.1"));
687        assert!(desc.contains("route=quarantine"));
688    }
689
690    #[test]
691    fn evidential_to_belnap() {
692        assert_eq!(EvidentialPair::new(0.8, 0.1).to_belnap(), Belnap::True);
693        assert_eq!(EvidentialPair::new(0.1, 0.8).to_belnap(), Belnap::False);
694        assert_eq!(EvidentialPair::new(0.1, 0.1).to_belnap(), Belnap::Neither);
695        assert_eq!(EvidentialPair::new(0.7, 0.6).to_belnap(), Belnap::Both);
696    }
697}