Skip to main content

qualia_core_db/governance/webizen/
opcode.rs

1/// The Opcodes for the Lightweight Warren Abstract Machine (WAM) variant.
2/// `f64` parameters require `PartialEq` only — `Eq` is not derived.
3#[derive(Debug, Clone, Copy, PartialEq)]
4pub enum SlgOpcode {
5    // ── Core WAM ─────────────────────────────────────────────────────────────
6    CheckTable,
7    CheckDefeaters,
8    CheckSubsumption,
9    BranchWorld,
10    /// Deprecated — use `CheckMinInclusive`.
11    CheckThreshold,
12    ConsumeFact,
13    /// Linear-logic **zero-knowledge–gated** resource exhaustion: like `ConsumeFact`, but the
14    /// cryptographic-token resource `(subject_reg, predicate_reg, object_reg)` is spent **only**
15    /// if a verified zk-entitlement marker `(subject_reg, q42:zkVerified, q42:true)` is live in
16    /// the arena. Absent the proof, or if the token is already spent, the frame fails (`None`).
17    /// Delegates to `modalities::linear::zk_gated_consume`.
18    ZkConsumeFact,
19    Unify,
20    Call,
21    Return,
22    ApplyTaxSchema,
23    Halt,
24    /// sh:Warning terminal — emits diagnostic but does not halt ingestion.
25    WarnOnly,
26
27    // ── Standard SHACL numeric range ─────────────────────────────────────────
28    CheckMinInclusive(f64),
29    CheckMaxInclusive(f64),
30    CheckMinExclusive(f64),
31    CheckMaxExclusive(f64),
32
33    // ── Standard SHACL cardinality ────────────────────────────────────────────
34    CheckMinCount(u32),
35    CheckMaxCount(u32),
36
37    // ── Standard SHACL string ─────────────────────────────────────────────────
38    CheckMinLength(u32),
39    CheckMaxLength(u32),
40    /// Pattern stored as q_hash of the regex string; compared against literal hash.
41    CheckPattern(u64),
42
43    // ── Standard SHACL value constraints ──────────────────────────────────────
44    /// q_hash of the single expected value.
45    CheckHasValue(u64),
46    /// q_hash of a referenced node-shape IRI.
47    CheckNodeShape(u64),
48    /// Negation: passes only if the referenced shape would FAIL.
49    CheckNotShape(u64),
50    /// OR-branch: records a passing `rdf:type` match without failing the frame.
51    SoftCheckNodeShape(u64),
52    /// Fails unless at least one preceding `SoftCheckNodeShape` matched.
53    RequireAnyShape,
54    /// Validates inline literal tag on `object_reg` (0=IRI, 1=int, 2=decimal, 3=bool).
55    CheckObjectDatatype(u8),
56
57    // ── Native: physics ───────────────────────────────────────────────────────
58    NativeThermodynamics,
59    NativeOdeSolver,
60    /// RK4 ODE time-stepper with chaining support
61    /// Parameters packed: step_size (lower 32 bits) | num_steps (upper 32 bits)
62    NativeRk4Step(u64),
63    NativeQuantumDft,
64    /// `qualia:predictReceptorBinding` — PINN binding affinity.
65    NativeReceptorBinding,
66    /// Compile semantic constraints into blind QUBO matrix (Core 2).
67    NativeQuboCompile,
68    /// Emit linear QUBO bias: (var_index, f32_bits).
69    NativeQuboEmitLinear(u8, u32),
70    /// Emit quadratic coupler: (var_a, var_b, f32_bits).
71    NativeQuboEmitCoupler(u8, u8, u32),
72    /// Egress to remote QPU: 0=annealer, 1=gate-model. Yields frame to Core 3.
73    NativeQuantumEgress(u8),
74    /// Ingress: collapse provider JSON into provenance Quins.
75    NativeQuantumIngress,
76
77    // ── Native: biosciences ───────────────────────────────────────────────────
78    /// `qualia:alignNucleotideSequence` — Smith-Waterman with BLAST nucleotide matrix.
79    NativeNucleotideAlign,
80    /// Deprecated form — routes to `NativeNucleotideAlign`.
81    NativeBioinformatics,
82    /// `qualia:alignProteinSequence` — BLOSUM62 (0) or PAM250 (1).
83    NativeProteinAlign(u8),
84    /// `qualia:computeKmerFrequency` — k-mer size embedded as parameter.
85    NativeKmerFrequency(u8),
86    /// `qualia:validateFastaRecord`.
87    NativeFastaValidation,
88    /// `qualia:evaluateGeneExpression`.
89    NativeGeneExpression,
90    /// `qualia:computeMetaboliteSimilarity` — Tanimoto fingerprint check.
91    NativeMetaboliteSimilarity,
92
93    // ── Native: biomedical ────────────────────────────────────────────────────
94    /// `qualia:computeRiskScore` — 0=Framingham, 1=CHA₂DS₂-VASc, 2=SCORE2.
95    NativeClinicalRisk(u8),
96    /// `qualia:evaluateLongitudinalTrend` — sliding window in days.
97    NativeLongitudinalTrend(u32),
98    /// `qualia:evaluateDrugInteraction`.
99    NativeDrugInteraction,
100    /// `qualia:checkContraindication`.
101    NativeContraindication,
102    /// `qualia:validateFhirObservation` — LOINC code hash.
103    NativeFhirObservation(u64),
104
105    // ── Native: economics ─────────────────────────────────────────────────────
106    NativeEconomics,
107
108    // ── Native: organic chemistry ─────────────────────────────────────────────
109    /// `qualia:validateSmiles` — structural SMILES validity.
110    NativeSmilesValidation,
111    /// `qualia:validateInchi` — InChI / InChIKey format check.
112    NativeInchiValidation,
113    /// `qualia:computeMolecularWeight` — exact MW from SMILES; param = max allowed Da (bits of f64).
114    NativeMolecularWeight(u64),
115    /// `qualia:computeLogP` — Crippen LogP; param = max allowed × 100 as i32 (stored as u32 bits).
116    NativeLogP(u32),
117    /// `qualia:computeTPSA` — Ertl TPSA; param = max Ų (as u32).
118    NativeTPSA(u32),
119    /// `qualia:evaluateLipinski` — Rule-of-Five drug-likeness filter.
120    NativeLipinskiFilter,
121    /// `qualia:evaluateVeber` — Veber oral-bioavailability filter.
122    NativeVeberFilter,
123    /// `qualia:evaluateGhose` — Ghose drug-likeness filter.
124    NativeGhoseFilter,
125    /// `qualia:evaluateEgan` — Egan passive-absorption filter.
126    NativeEganFilter,
127    /// `qualia:detectFunctionalGroups` — returns set of detected functional group hashes.
128    NativeFunctionalGroups,
129    /// `qualia:computePka` — functional-group-based pKa estimation.
130    NativePkaEstimate,
131    /// `qualia:computeChiralCenters` — count sp3 C with 4 distinct substituents.
132    NativeChiralCenters,
133    /// `qualia:generateCircularFingerprint` — Morgan fingerprint; param = radius.
134    NativeCircularFingerprint(u8),
135    /// `qualia:computeArrheniusRate` — k = A·exp(−Ea/RT); param encodes temperature K as u32.
136    NativeArrhenius(u32),
137    /// `qualia:computeGibbsEnergy` — ΔG = ΔH − TΔS.
138    NativeGibbsEnergy,
139    /// `qualia:computeEquilibrium` — K = exp(−ΔG°/RT).
140    NativeEquilibrium,
141    /// `qualia:computeHendersonHasselbalch` — pH from pKa + concentration ratio.
142    NativeHendersonHasselbalch,
143    /// `qualia:computeAtomEconomy` — Trost 1991 green metric.
144    NativeAtomEconomy,
145    /// `qualia:computeEFactor` — Sheldon waste-per-product metric.
146    NativeEFactor,
147    /// `qualia:computeGreenMetrics` — full suite: AE, E-factor, PMI, RME, CE.
148    NativeGreenMetrics,
149
150    // ── Native: Phase 5 Scientific ────────────────────────────────────────────
151    NativeComputeCrcl,
152    NativeComputeEgfr,
153    NativeEvaluatePkModel,
154    NativeComputeSofaScore,
155    NativeTranslateDna,
156    NativeIsoelectricPoint,
157    NativePeptideCleavage,
158    NativeBbbPermeation,
159    NativeLigandEfficiency,
160    NativeLLE,
161    NativeIsotopeDistribution,
162
163    // ── Native: deontic and epistemic ─────────────────────────────────────────
164    NativeDeonticEval,
165    NativeEpistemicEval(u8),
166
167    // ── Native: advanced logics ───────────────────────────────────────────────
168    NativeLinearConsume,
169    NativeAspStableModels,
170    NativeParaconsistentIsolate,
171    NativeDialecticalSynthesis,
172    /// Probabilistic gate: the goal quin's f32 belief weight (in `metadata`) must
173    /// be ≥ the threshold (param = `f32::to_bits`).
174    NativeProbabilisticThreshold(u32),
175    /// Description-logic gate: `frame.subject_reg ⊑ frame.object_reg` over the arena
176    /// TBox (transitive `rdfs:subClassOf` closure).
177    NativeDlSubsumption,
178    /// Argumentation gate (Dung grounded semantics): the goal argument
179    /// (`frame.subject_reg`) must be justified — in the grounded extension built
180    /// from `arg:asserts` / `arg:attacks` quins in the arena.
181    NativeArgumentationGrounded,
182    /// Metric-temporal gate (MTL "within"): `target` (`frame.object_reg`) must
183    /// occur within the param window of the earliest `trigger` (`frame.predicate_reg`);
184    /// event timestamps are in each quin's `metadata`.
185    NativeMtlWithin(u32),
186    /// Contrary-to-duty gate (dyadic deontic): if the party (`frame.subject_reg`)
187    /// breached the primary obligation (`frame.predicate_reg`), the reparation
188    /// (`frame.object_reg`) must be fulfilled.
189    NativeContraryToDuty,
190    /// Causal-necessity gate (but-for): `frame.subject_reg` must be a necessary
191    /// cause of `frame.object_reg` from origin `frame.context_reg`.
192    NativeCausalNecessary,
193    /// Abductive gate: the observation (`frame.object_reg`) must have an explanatory
194    /// hypothesis (backward `abduces:explains` chain) in the arena.
195    NativeAbduce,
196    /// Closed-world / negation-as-failure gate: passes iff the frame goal is ABSENT
197    /// from the arena (its negation holds by default).
198    NativeClosedWorld,
199    /// Fuzzy-conjunction gate: the Gödel t-norm (min) of the truth degrees of all
200    /// quins with predicate `frame.predicate_reg` must be ≥ the param threshold.
201    NativeFuzzyConjunction(u32),
202    /// CTL EF gate: from `frame.subject_reg`, SOME path reaches a state satisfying
203    /// `frame.object_reg` (branching-time reachability over `ctl:next`/`ctl:holds`).
204    NativeCtlExistsFinally,
205    /// CTL AG gate: EVERY state reachable from `frame.subject_reg` satisfies the
206    /// invariant `frame.object_reg`.
207    NativeCtlAlwaysGlobally,
208    /// Modal □ gate: `frame.object_reg` holds in ALL worlds accessible from
209    /// `frame.subject_reg` (`modal:accesses`/`modal:holds`).
210    NativeModalNecessary,
211    /// Modal ◇ gate: `frame.object_reg` holds in SOME world accessible from
212    /// `frame.subject_reg`.
213    NativeModalPossible,
214    /// RCC-8 spatial gate: the topological relation between region `frame.subject_reg`
215    /// and region `frame.object_reg` (each = boundary-point quins) must equal the
216    /// param (0=DC,1=EC,2=PO,3=TPP,4=TPPi,5=NTPP,6=NTPPi,7=EQ).
217    NativeRcc8(u8),
218    /// RCC-8 fact-emitting assertion: if the relation holds, asserts a derived fact.
219    NativeRcc8Assert(u8),
220    /// Fact-emitting temporal interval relation assertion.
221    NativeAllenIntervalAssert(u8),
222    /// qapp-facing dynamic N3 rule registration
223    NativeRegisterRule,
224    /// M-of-N steward quorum gate
225    NativeStewardQuorum(u8),
226    /// Governed canvas placement gate
227    NativeCanvasPlacement,
228
229    // ── Native: cognitive ai (ACT-R) ──────────────────────────────────────────
230    NativeRetrieveByActivation,
231    NativeDecayMetadata,
232    NativeUnless,
233
234    // ── Native: temporal logic (LTL) ──────────────────────────────────────────
235    NativeLtlGlobally,
236    NativeLtlFinally,
237    NativeLtlNext,
238    NativeLtlUntil,
239    NativeLtlRelease,
240    /// Evaluate a threshold proposition projected from chronological 10D
241    /// manifold states through the existing LTL evaluator.
242    ///
243    /// `mode`: 0=Globally, 1=Finally, 2=Next.
244    /// `dimension`: [`manifold::ManifoldDimension`] discriminant.
245    /// `threshold_bits`: IEEE-754 f32 threshold.
246    /// `at_least`: true for >=, false for <=.
247    NativeManifoldLtl {
248        mode: u8,
249        dimension: u8,
250        threshold_bits: u32,
251        at_least: bool,
252    },
253    /// Derive topology facts from 10D states and execute the bounded real ASP
254    /// stable-model evaluator. The selected model bitset is bound to object_reg.
255    NativeManifoldAsp,
256
257    // ── Native: spatio-temporal (Allen Interval) ──────────────────────────────
258    NativeAllenInterval(u8),
259
260    // ── Native: geometric and spatial topology ────────────────────────────────
261    NativeLorentzDistance,
262    NativeTropicalDistance,
263    NativeVerifyProofOfLocation,
264
265    // ── Native: calculus modality ──────────────────────────────────────────────
266    /// `calc:SimpsonsIntegration` — CPU-based Simpson's rule (start_bits, end_bits, step_size_bits, kahan_bits)
267    NativeCalcSimpsons(u64, u64, u32, u32),
268    /// `calc:TrapezoidalIntegration` — CPU-based trapezoidal rule (start_bits, end_bits, step_size_bits, kahan_bits)
269    NativeCalcTrapezoidal(u64, u64, u32, u32),
270    /// `calc:GpuIntegration` — GPU-accelerated integration via WebGPU (start_bits, end_bits, step_size_bits, kahan_bits)
271    NativeCalcGpu(u64, u64, u32, u32),
272}