# RBE-Q: Fixed-Point Quantum Circuit Computing

## Result first

Version 0.3 turns Reality Bit Engine into a genuine quantum **circuit
simulator** and a small compilable circuit language. It computes accepted
quantum state-vector predictions, entanglement, interference, projective
measurement and several foundational algorithms entirely with deterministic
integer state transitions.

It is not a physical quantum processing unit. The PC still performs a classical
simulation and therefore pays exponential memory and runtime costs.

## 1. Computational state

An \(n\)-qubit pure state is

\[
|\psi\rangle=\sum_{j=0}^{2^n-1}\alpha_j|j\rangle,
\qquad
\sum_j|\alpha_j|^2=1.
\]

Each complex amplitude is stored as two signed Q1.30 integers:

\[
\alpha_j=2^{-30}(a_j+ib_j),
\qquad a_j,b_j\in\mathbb Z.
\]

Consequently,

\[
\operatorname{ULP}_{amplitude}=2^{-30},
\qquad
\operatorname{ULP}_{mass}=2^{-60}.
\]

Rotation angles use a 64-bit full-turn coordinate:

\[
\theta=2\pi p/2^{64},
\qquad
\operatorname{ULP}_{phase}=2\pi/2^{64}.
\]

Sine and cosine come from the existing 31-step integer CORDIC. Floating point
is used only to print approximations and inside independent test oracles.

## 2. Gates and universality

For a one-qubit matrix

\[
U=\begin{pmatrix}u_{00}&u_{01}\\u_{10}&u_{11}\end{pmatrix},
\]

the simulator updates cache-local amplitude pairs:

\[
\begin{pmatrix}\alpha_{j,0}'\\\alpha_{j,1}'\end{pmatrix}
=U
\begin{pmatrix}\alpha_{j,0}\\\alpha_{j,1}\end{pmatrix}.
\]

It directly implements:

| Class | Operations |
|---|---|
| Single-qubit Clifford | `h`, `x`, `y`, `z`, `s`, `sdg` |
| Non-Clifford | `t`, `tdg` |
| Arbitrary rotation | `rx`, `ry`, `rz` with Phase64 angle |
| Controlled | `cx`, `cz`, multi-controlled `mcx` |
| Routing | `swap` |
| Oracle/search | `phaseflip`, `diffuse` |

The Clifford gates plus `T`, with entangling `CNOT`, form an approximately
universal basis: arbitrary finite quantum circuits can be approximated to a
chosen accuracy. The engine also exposes direct arbitrary rotations so a user
does not first have to synthesize them from `H` and `T`.

## 3. Measurement without hidden floats

The exact stored weight of basis state \(j\) is

\[
w_j=a_j^2+b_j^2\in\mathbb N.
\]

The sampler draws an integer uniformly from

\[
\{0,\ldots,W-1\},\qquad W=\sum_jw_j,
\]

using rejection sampling to remove modulo bias, then locates the corresponding
cumulative weight interval. Thus

\[
P(j)=w_j/W
\]

without converting the probability to floating point.

A single-qubit measurement zeros the incompatible branch. It intentionally
does not multiply the surviving branch by a floating inverse square root.
Every later probability divides by the retained total mass, so the conditional
predictions are mathematically identical to explicitly renormalizing the
vector.

The pseudorandom generator makes local runs reproducible from a declared seed.
It is a simulation facility, not a claim of metaphysical or hardware quantum
randomness.

## 4. RBE-Q language

RBE-Q 0.1 is a line-oriented circuit input format. Qubit zero is the
least-significant bit of a displayed basis index. Blank lines and text after
`#` are ignored.

```text
qubits 3
shots 10000
seed 20260904

h 0
h 1
h 2
phaseflip 5
diffuse
phaseflip 5
diffuse
```

Directives and opcodes are:

```text
qubits N
shots N
seed N
h|x|y|z|s|sdg|t|tdg Q
rx|ry|rz Q PHASE64_TICKS
cx|cnot CONTROL TARGET
cz CONTROL TARGET
swap Q1 Q2
mcx TARGET CONTROL1 [CONTROL2 ...]
phaseflip BASIS_INDEX
diffuse
```

Compile and run a program with:

```text
reality-bit-engine qrun examples/grover-3q.rbeq
```

The parser rejects missing declarations, unknown operations, out-of-range
qubits, repeated controls and impossible state sizes with a source line number.

## 5. Verified programs

### Bell entanglement

The circuit

\[
|00\rangle\xrightarrow{H_0}\frac{|00\rangle+|01\rangle}{\sqrt2}
\xrightarrow{CNOT_{0,1}}
\frac{|00\rangle+|11\rangle}{\sqrt2}
\]

returns

\[
P(00)=P(11)=\tfrac12,
\qquad P(01)=P(10)=0.
\]

Each reduced one-qubit state has purity \(1/2\), while the joint state is pure.
That difference is the computed entanglement witness used here. IBM's quantum
information course identifies the same \(|\Phi^+\rangle\) state as the
archetypal Bell state:
[IBM Quantum, entanglement in action](https://quantum.cloud.ibm.com/learning/courses/basics-of-quantum-information/entanglement-in-action/introduction).

### CHSH

Four rotated correlations yield

\[
S=2.82842712477\approx2\sqrt2>2.
\]

This validates relative phase, entanglement, local rotations and correlation
expectations together. IBM documents the same Bell/CHSH construction and
rotation pattern in its executable course:
[IBM Quantum CHSH implementation](https://quantum.cloud.ibm.com/learning/courses/basics-of-quantum-information/entanglement-in-action/qiskit-implementation).

### Deutsch algorithm

All four one-bit Boolean oracles are tested. The circuit distinguishes constant
from balanced functions with one coherent oracle query and reports success
probability \(1\) for both classes.

### Grover search

For one marked state among eight candidates, two Grover iterations produce

\[
P(\text{target})=\frac{121}{128}=0.9453125
\]

analytically; the Q30 result is \(0.945312497206\). Grover amplitude
amplification is the standard unstructured-search procedure offering a
quadratic query improvement, not an \(O(1)\) search:
[IBM Quantum Grover tutorial](https://quantum.cloud.ibm.com/docs/en/tutorials/grovers-algorithm).

### Teleportation

The simulator prepares an arbitrary phase-bearing source qubit, an entangled
pair, and the standard controlled corrections. Using deferred measurement, the
destination fidelity is

\[
F=0.999999997206.
\]

The source does not remain an identical copy. This preserves the no-cloning
constraint. Teleportation transfers quantum information using shared
entanglement and two classical result bits; it does not move matter or enable
faster-than-light communication:
[IBM Quantum teleportation](https://quantum.cloud.ibm.com/learning/courses/basics-of-quantum-information/entanglement-in-action/quantum-teleportation).

### Bit-flip error correction

The program encodes one logical qubit into three correlated data qubits,
injects an `X` error into the middle qubit, extracts two syndrome bits, applies
a Toffoli correction and decodes. The recovered logical-state fidelity is \(1\)
at Q30 resolution for the tested state.

This is an ideal error-correction circuit. Version 0.3 does not yet model a
physical noise channel, faulty syndrome extraction or a fault-tolerance
threshold.

## 6. What this test says about the seven-layer language

A fixed 848-bit `State7` cannot losslessly store an arbitrary \(n\)-qubit state:
the quantum payload contains \(2^{n+1}\) signed Q30 components. Version 0.3
therefore corrects the schema into an envelope plus dynamic payload:

\[
Z_Q=(H_7,\Psi_n),
\qquad H_7\in\{0,1\}^{848},
\qquad \Psi_n\in(2^{-30}\mathbb Z[i])^{2^n}.
\]

`quantum_summary_to_state7` stores a deterministic payload fingerprint, qubit
count, branch count, gate count, measurement evidence and D7 norm constraint.
The fingerprint is deliberately non-injective: it detects state differences
but is not a substitute for the full state vector.

| Layer | Quantum-computing meaning |
|---|---|
| \(D_1\) | Declared computation and payload fingerprint |
| \(D_2\) | Qubit/register relationships and controls |
| \(D_3\) | Optional physical topology; absent in ideal simulation |
| \(D_4\) | Ordered gate sequence and circuit depth |
| \(D_5\) | Complex amplitude, relative phase and alternatives |
| \(D_6\) | Measurement basis, seed, shots and observed counts |
| \(D_7\) | Normalization, valid indices, unitary/duality constraints |

The useful result is not that quantum mechanics proves seven literal
dimensions. It is that the typed projection language can express which
information is global, relational, temporal, phase-sensitive, observed or
constraint-level without confusing those categories.

## 7. Scaling wall

Each complex amplitude occupies 16 bytes. State storage is therefore

\[
M(n)=16\cdot2^n\text{ bytes}.
\]

| Qubits | Amplitudes | Approximate payload |
|---:|---:|---:|
| 20 | 1,048,576 | 16 MiB |
| 22 | 4,194,304 | 64 MiB |
| 24 | 16,777,216 | 256 MiB |
| 30 | 1,073,741,824 | 16 GiB |
| 36 | 68,719,476,736 | 1 TiB |

The executable caps full-state simulation at 24 qubits to prevent accidental
unbounded allocation on a normal PC. IBM's basic state-vector simulator also
documents a 24-qubit limit, while its general state-vector documentation notes
the same \(2^n\) complex-value memory law:
[IBM BasicSimulator](https://quantum.cloud.ibm.com/docs/en/api/qiskit/dev/qiskit.providers.basic_provider.BasicSimulator),
[Qiskit Aer state-vector memory](https://qiskit.github.io/qiskit-aer/stubs/qiskit_aer.AerSimulator.html).

## 8. Scientific boundary and next target

This release demonstrates compatibility with accepted circuit-model quantum
mechanics. It does not establish:

- a new physical qubit technology;
- quantum speedup on the classical PC;
- that seven layers cause quantum behavior;
- a solution to every computational problem;
- a new prediction beyond ordinary quantum mechanics.

A physical quantum computer additionally requires controllable quantum degrees
of freedom, entangling interactions, initialization, readout, calibration,
noise characterization and error correction. The immediate research target for
this engine is therefore a noise/density-matrix backend and a falsifiable
seven-layer prediction that differs numerically from the standard model.
