The QRL Book

From Quantum Foundations to Causal Structure as a Programming Primitive

Author

David Coldeira

Published

July 10, 2026

Welcome

This book has one destination: understanding why the quantum switch has a type.

That sentence will not make sense yet. By Chapter 15, it will be the most natural thing in the world.


The idea in one paragraph

Every quantum programming language you have heard of — Qiskit, Cirq, Q#, QWIRE, even the most mathematically sophisticated typed quantum languages — shares one hidden assumption: operations happen in a fixed order. A comes before B, or B comes before A, and this is decided before the program runs. Quantum mechanics does not require this. There exist physical processes in which the causal order of operations is itself in quantum superposition — genuinely indefinite, not just unknown. No existing language can represent these processes, because none have a type for causal structure. QRL does.

The central result of this book is the QuantumSwitch Soundness Theorem: any well-typed switch(f, g, c) expression in QRL denotes a causally nonseparable process matrix. The type system statically guarantees a property of physical reality. That is what types are for.


What you will learn

This book builds the result from scratch, in four parts:

Part I — Quantum Foundations (Chapters 1–3) Qubits, entanglement, and n-qubit systems. The mathematical toolkit: state vectors, density matrices, tensor products, measurement. You need this before everything else.

Part II — Measurement-Based Quantum Computing (Chapters 4–6) Cluster states, graph states, measurement patterns. This is how QRL compiles to photonic hardware. It is also the layer that sits below causal structure — understanding it makes the causal layer’s position in the architecture clear.

Part III — QRL Programming (Chapters 7–12) Hands-on: Bell states, GHZ states, graph extraction, pattern generation, adaptive corrections, circuit compilation. You will write real QRL programs and run them.

Part IV — Causal Structure as a Programming Primitive (Chapters 13–15) The destination. Process matrices, the OCB causal game, the type hierarchy, and finally the Soundness Theorem with a full proof walkthrough. By Chapter 15 you will understand not just what the theorem says but why it holds and why no other language can even state it.


Prerequisites

  • Mathematics: Linear algebra (vectors, matrices, eigenvalues), complex numbers, basic probability
  • Programming: Python basics — QRL is implemented in Python
  • Physics: Helpful but not required — quantum mechanics is developed from scratch in Part I

How to use this book

If you want the full arc: read linearly. Each part builds on the previous one.

If you already know quantum mechanics: start at Chapter 4 (MBQC Foundations) or Chapter 7 (first QRL program).

If you want to go straight to the result: read the paper first (arXiv), then use this book to understand the implementation and the mathematics behind the theorem.


The code

All code examples run against the QRL implementation:

pip install qrl

The implementation is ~13,600 lines of Python with 896 passing tests. Everything shown in this book is tested against that implementation.

Source: github.com/entangledcode/qrl


About the author

David Coldeira is an independent researcher and scientific software engineer with a BSc in Physics. QRL is his primary research project — a quantum programming language in which causal structure is a first-class type-level primitive.

  • Email: dcoldeira@gmail.com
  • GitHub: dcoldeira

Let’s begin.