| name | reversible-computing |
| description | Janus and reversible languages: run programs backwards, time-symmetric computation. |
| version | 1.0.0 |
Reversible Computing Skill
"Every computation can be undone. Time flows both ways."
Core Concept
Reversible computing ensures:
- Bijective โ every state has exactly one predecessor AND successor
- No information loss โ can always recover input from output
- Time-symmetric โ run program forwards or backwards
- Landauer limit โ theoretical minimum energy (no erasure = no heat)
forward
Input โโโโโโโโโโโโโโถ Output
โโโโโโโโโโโโโโ
backward
Why It's Strange
- No destructive updates โ
x = 5 is illegal (loses old value)
- No
if without fi โ conditionals must be invertible
- No garbage โ all temporary values must be "uncomputed"
- Quantum-ready โ unitary operations are reversible
Janus Language
procedure swap(int x, int y)
x ^= y // x' = x โ y
y ^= x // y' = y โ (x โ y) = x
x ^= y // x'' = (x โ y) โ x = y
// Running BACKWARDS automatically inverts!
// uncall swap(a, b) โ swaps back
Reversible Conditionals
// Forward: if-then-else-fi
if x = 0 then
x += 1
else
x += 2
fi x = 1 // <-- ASSERTION: must be true after forward
// Backward: uses fi-assertion to know which branch was taken
Reversible Loops
// Forward: from-do-loop-until
from x = 0 do
x += 1
loop
y += x
until x = 10
// Backward: runs until x = 0, undoing each iteration
Bennett's Trick
How to make irreversible computation reversible:
1. Compute f(x) โ y, keeping all intermediate garbage g
2. Copy y to output
3. UNCOMPUTE: run step 1 backwards to clean up g
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ x โโโถ COMPUTE โโโถ (y,g) โโโถ COPY โ
โ โ โ โ
โ โผ โผ โ
โ UNCOMPUTE y_out โ
โ โ โ
โ โผ โ
โ (x,0) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Space: O(T) โ O(T log T) with checkpointing
Implementation
class ReversibleMachine:
def __init__(self):
self.tape = {}
self.history = []
def xor_assign(self, var, value):
"""x ^= value (self-inverse!)"""
old = self.tape.get(var, 0)
self.tape[var] = old ^ value
self.history.append(('xor', var, value))
def add_assign(self, var, value):
"""x += value"""
old = self.tape.get(var, 0)
self.tape[var] = old + value
self.history.append(('add', var, value))
def sub_assign(self, var, value):
"""x -= value (inverse of add)"""
old = self.tape.get(var, 0)
self.tape[var] = old - value
self.history.append(('sub', var, value))
def reverse_step(self):
"""Undo last operation."""
if not self.history:
return False
op, var, value = .history.pop()
op == :
.tape[var] ^= value
op == :
.tape[var] -= value
op == :
.tape[var] += value
():
.reverse_step():
Reversible Gates (Hardware)
Fredkin Gate (CSWAP): Toffoli Gate (CCNOT):
a โโโโโโโโโโโ a a โโโโโโโโโโโ a
โ โ
b โโโโฌโโผโโฌโโโ b' b โโโโโโโโโโโ b
โ โ โ โ
c โโโโดโโโโดโโโ c' c โโโโโโโโโโโ c โ (a โง b)
If a=1: swap b,c If a=b=1: flip c
If a=0: pass through Otherwise: pass through
Both are universal for reversible classical computation.
GF(3) Integration
# Reversible operations on GF(3)
# x โโ y = (x + y) mod 3 is reversible (inverse: x โโ y)
function gf3_add!(state, var, value)
state[var] = (state[var] + value) % 3
# Inverse: gf3_sub!(state, var, value)
end
function gf3_sub!(state, var, value)
state[var] = (state[var] - value + 3) % 3
end
# Trit-preserving swap
function trit_swap!(state, a, b)
# XOR doesn't work in GF(3), use:
state[a], state[b] = state[b], state[a]
# Self-inverse: swap is its own reverse
end
Quantum Connection
All quantum gates are unitary โ reversible:
โโโโโ
|ฯโฉ โโโโโค U โโโโโ U|ฯโฉ
โโโโโ
โโโโโโ
U|ฯโฉ โโโโค Uโ โโโโ |ฯโฉ (Uโ = inverse)
โโโโโโ
Irreversible measurement "collapses" superposition โ information loss.
Energy and Landauer's Principle
Irreversible: Erase 1 bit โ kT ln(2) energy released as heat
โ 2.8 ร 10โปยฒยน J at room temperature
Reversible: No erasure โ no theoretical minimum energy
(practical limits remain)
Languages & Tools
| Language | Description |
|---|
| Janus | First reversible imperative language |
| RFUN | Reversible functional |
| SyReC | Reversible circuit synthesis |
| Quipper | Quantum (inherently reversible) |
| Theseus | Type-safe reversible |
Example: Reversible Fibonacci
procedure fib(int n, int x1, int x2)
from x1 = 1 โง x2 = 0 do
x1 += x2
x1 <=> x2 // swap
n -= 1
until n = 0
// call fib(10, x1, x2) โ x1 = 55, x2 = 89
// uncall fib(10, x1, x2) โ x1 = 1, x2 = 0
Literature
- Landauer (1961) - "Irreversibility and Heat Generation"
- Bennett (1973) - "Logical Reversibility of Computation"
- Yokoyama & Glรผck (2007) - "A Reversible Programming Language"
- Fredkin & Toffoli (1982) - "Conservative Logic"
Related Skills
quantum-computing - Unitary = reversible
thermodynamics - Landauer limit
bidirectional-programming - Lenses
interaction-nets - Reduction is reversible
Scientific Skill Interleaving
This skill connects to the K-Dense-AI/claude-scientific-skills ecosystem:
Graph Theory
- networkx [โ] via bicomodule
Bibliography References
general: 734 citations in bib.duckdb
SDF Interleaving
This skill connects to Software Design for Flexibility (Hanson & Sussman, 2021):
Primary Chapter: 6. Layering
Concepts: layered data, metadata, provenance, units
GF(3) Balanced Triad
reversible-computing (+) + SDF.Ch6 (+) + [balancer] (+) = 0
Skill Trit: 1 (PLUS - generation)
Secondary Chapters
- Ch1: Flexibility through Abstraction
- Ch2: Domain-Specific Languages
- Ch7: Propagators
Connection Pattern
Layering adds metadata. This skill tracks provenance or annotations.
Cat# Integration
This skill maps to Cat# = Comod(P) as a bicomodule in the equipment structure:
Trit: 0 (ERGODIC)
Home: Prof
Poly Op: โ
Kan Role: Adj
Color: #26D826
GF(3) Naturality
The skill participates in triads satisfying:
(-1) + (0) + (+1) โก 0 (mod 3)
This ensures compositional coherence in the Cat# equipment structure.