interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / research / atemporal / at0 / model / at0_conditional.c

59 lines · 2464 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* Conditional subsystem state: phi_k = (<t_k| (x) I) Psi, the clock
18 * probability w ||phi_k||^2 / ||Psi||^2 and rho_k = phi phi^dagger / ||phi||^2.
19 * Each label is computed from Psi alone; no state is carried between labels. */
20#include "at0_model.h"
21#include <math.h>
22#include <string.h>
23
24at0_status at0_conditional_compute(const at0_case *c, const at0_state *psi, double psi_norm2,
25 int k, at0_conditional *out)
26{
27 if (!c || !psi || !out || psi->clock_dim != c->clock_dim) return AT0_ERR_ARGUMENT;
28 if (!(psi_norm2 > 0.0) || !isfinite(psi_norm2)) return AT0_ERR_ARGUMENT;
29 if (k < 0 || k >= c->label_count) return AT0_ERR_ARGUMENT;
30 memset(out, 0, sizeof *out);
31 at0_clock_vec t;
32 at0_status st = at0_povm_clock_state(c, k, &t);
33 if (st != AT0_OK) return st;
34 for (int s = 0; s < AT0_SYSTEM_DIM; s++) {
35 double complex acc = 0.0;
36 for (int j = 0; j < c->clock_dim; j++) {
37 double complex a;
38 if ((st = at0_state_get(psi, j, s, &a)) != AT0_OK) return st;
39 acc += conj(t.v[j]) * a;
40 }
41 out->phi.v[s] = acc;
42 }
43 double n2 = 0.0;
44 for (int s = 0; s < AT0_SYSTEM_DIM; s++) {
45 double re = creal(out->phi.v[s]), im = cimag(out->phi.v[s]);
46 n2 += re * re + im * im;
47 }
48 if (!isfinite(n2)) return AT0_ERR_NONFINITE;
49 out->phi_norm2 = n2;
50 out->clock_probability = at0_rat_to_double(c->povm_weight) * n2 / psi_norm2;
51 if (!isfinite(out->clock_probability)) return AT0_ERR_NONFINITE;
52 out->defined_numeric = n2 > 0.0;
53 if (out->defined_numeric) {
54 for (int a = 0; a < AT0_SYSTEM_DIM; a++)
55 for (int b = 0; b < AT0_SYSTEM_DIM; b++)
56 out->rho.m[a][b] = out->phi.v[a] * conj(out->phi.v[b]) / n2;
57 }
58 return AT0_OK;
59}