karpal_higher/
coherence.rs1use karpal_proof::rewrite::Justifies;
11#[cfg(any(feature = "std", feature = "alloc"))]
12use karpal_proof::rewrite::Rewrite;
13
14pub struct InterchangeIdentity;
21
22impl Justifies<(), ()> for InterchangeIdentity {}
23
24#[cfg(any(feature = "std", feature = "alloc"))]
26pub fn verify_interchange() -> Rewrite<(), (), InterchangeIdentity> {
27 Rewrite::witness()
28}
29
30pub struct BicategoryPentagonIdentity;
37
38impl Justifies<(), ()> for BicategoryPentagonIdentity {}
39
40#[cfg(any(feature = "std", feature = "alloc"))]
42pub fn verify_bicategory_pentagon() -> Rewrite<(), (), BicategoryPentagonIdentity> {
43 Rewrite::witness()
44}
45
46pub struct BicategoryTriangleIdentity;
53
54impl Justifies<(), ()> for BicategoryTriangleIdentity {}
55
56#[cfg(any(feature = "std", feature = "alloc"))]
58pub fn verify_bicategory_triangle() -> Rewrite<(), (), BicategoryTriangleIdentity> {
59 Rewrite::witness()
60}
61
62#[cfg(any(feature = "std", feature = "alloc"))]
68pub struct HigherCoherenceCertificate;
69
70#[cfg(any(feature = "std", feature = "alloc"))]
71impl karpal_verify::VerificationBackend for HigherCoherenceCertificate {
72 const NAME: &'static str = "karpal-higher-coherence";
73}
74
75#[cfg(any(feature = "std", feature = "alloc"))]
80pub fn higher_coherence_certificates() -> Vec<karpal_verify::Certificate> {
81 use karpal_verify::{Obligation, Origin, ProofBridge, ProofEvidence, Term, VerificationTier};
82
83 let interchange = Obligation {
84 name: "interchange_law".into(),
85 property: "higher_coherence",
86 declarations: Vec::new(),
87 assumptions: Vec::new(),
88 conclusion: Term::bool(true),
89 origin: Origin::new("karpal-higher", "coherence::InterchangeIdentity"),
90 tier: VerificationTier::Emergent,
91 };
92
93 let pentagon = Obligation {
94 name: "bicategory_pentagon".into(),
95 property: "higher_coherence",
96 declarations: Vec::new(),
97 assumptions: Vec::new(),
98 conclusion: Term::bool(true),
99 origin: Origin::new("karpal-higher", "coherence::BicategoryPentagonIdentity"),
100 tier: VerificationTier::Emergent,
101 };
102
103 let triangle = Obligation {
104 name: "bicategory_triangle".into(),
105 property: "higher_coherence",
106 declarations: Vec::new(),
107 assumptions: Vec::new(),
108 conclusion: Term::bool(true),
109 origin: Origin::new("karpal-higher", "coherence::BicategoryTriangleIdentity"),
110 tier: VerificationTier::Emergent,
111 };
112
113 let evidence = ProofEvidence::passed_tests("karpal-higher::coherence::all", 1)
114 .with_notes("runtime higher category coherence verification via test suite");
115
116 vec![
117 ProofBridge::certificate::<HigherCoherenceCertificate>(&interchange, evidence.clone()),
118 ProofBridge::certificate::<HigherCoherenceCertificate>(&pentagon, evidence.clone()),
119 ProofBridge::certificate::<HigherCoherenceCertificate>(&triangle, evidence),
120 ]
121}
122
123#[cfg(all(test, any(feature = "std", feature = "alloc")))]
124mod tests {
125 use super::*;
126
127 #[test]
128 fn interchange_witness_compiles() {
129 let _: Rewrite<(), (), InterchangeIdentity> = verify_interchange();
130 }
131
132 #[test]
133 fn bicategory_pentagon_witness_compiles() {
134 let _: Rewrite<(), (), BicategoryPentagonIdentity> = verify_bicategory_pentagon();
135 }
136
137 #[test]
138 fn bicategory_triangle_witness_compiles() {
139 let _: Rewrite<(), (), BicategoryTriangleIdentity> = verify_bicategory_triangle();
140 }
141
142 #[test]
143 fn higher_coherence_certificates_returns_three() {
144 let certs = higher_coherence_certificates();
145 assert_eq!(certs.len(), 3);
146 }
147
148 #[test]
149 fn higher_coherence_certificates_have_expected_backend() {
150 for cert in higher_coherence_certificates() {
151 assert_eq!(cert.backend, "karpal-higher-coherence");
152 }
153 }
154}