Your Messy Code Goes In. Clean, Verified Code Comes Out.
The PCD Roundtrip — extract the computational essence of messy code, verify it mathematically, and recompile into clean code with auto-generated tests.
The PCD Roundtrip — The Feature That Changes Everything
The Problem Nobody Talks About
Every codebase starts clean. Six months later: patches on patches, edge cases nobody documented, functions that "work" but nobody knows why. Tests? Some. Documentation? Outdated. Confidence? Zero.
You know the feeling. You open a file and see a function with a comment that says // TODO: fix this later — dated three years ago. The function has been modified by four different developers. There are no tests. There is no specification. There is only the code, and the code is the only truth — except nobody is sure what truth it is telling.
Rewriting from scratch takes months and usually fails. Refactoring is lipstick on a pig — you reorganize the mess without ever proving it was correct in the first place. What if there was a third option?
What if you could extract the computational essence of your messy code, verify it mathematically, and recompile it into clean code — with auto-generated tests, in any language you want?
The Roundtrip
Your messy JS → brikc lift → PCD blueprint → brikc build --target js → Clean JS + testsThis is the PCD Roundtrip. It is not transpilation. It is not refactoring. It is not a linter with opinions. It is something fundamentally different:
Extract the computational essence. Verify it formally. Recompile from the specification.
What goes in: spaghetti code with no tests, inconsistent naming, undocumented edge cases, magic numbers, and functions that "probably work."
What comes out:
Clean code — regenerated from the mathematical specification, not from your formatting preferences
Auto-generated tests — derived from the formal verification, not from a developer guessing what to test
The PCD blueprint — a permanent, language-independent specification of what your code actually does
The blueprint is the product. The clean code is a side effect.
A Real Example
Here is a function that exists in thousands of codebases right now. A pricing calculation written under deadline pressure, modified twice, never tested:
// TODO: fix this later
function calcPrice(qty, price, tax, disc) {
var total = qty * price
if(disc > 0) total = total - (total * disc / 100)
total = total + (total * tax / 100)
return Math.round(total * 100) / 100 // cents hack
}No types. No validation. A comment that says "fix this later." A rounding trick labeled "cents hack." The variable disc could be a percentage or a decimal — nobody documented it. Does tax apply before or after the discount? You have to read the code to find out. And if you read the code wrong, you bill customers wrong.
Step 1: Lift
$ brikc lift pricing.js
[LIFT] pricing.js
Found: calcPrice (4 params, 1 return)
Liftability: 0.92 (pure arithmetic, no side effects)
Monomers: 4 (arithmetic family)
Status: CORE (Φ_c = 1)
Output: pricing.pcdThe Lifter reads your JavaScript function and identifies the computational essence. It does not care about your variable names, your formatting, or your comments. It sees: multiplication, conditional subtraction, addition, division. Pure arithmetic. Liftability score: 0.92 — nearly perfect. The 0.08 deduction is for the Math.round rounding behavior that maps to a specific monomer.
Step 2: The PCD Blueprint
PC calcPrice {
let qty = 0;
let price = 0;
let tax = 0;
let disc = 0;
let subtotal = qty * price;
let after_discount = subtotal - (subtotal * disc / 100);
let with_tax = after_discount + (after_discount * tax / 100);
OUTPUT with_tax;
}Read this. Even if you have never seen PCD before, you know exactly what this function does. The inputs are explicit. The computation is step-by-step. There are no tricks, no hacks, no "TODO" comments. This is the mathematical specification of your pricing logic.
The TCE certifies Φc = 1: the circuit is closed. Every input produces a deterministic output. Every operation is formally verified. The blueprint is the truth — and the truth is readable.
Step 3: Build
$ brikc build calcPrice.pcd --target js
[BUILD] calcPrice.pcd → calcPrice.js
Target: JavaScript (ES2020)
Monomers: 4 (arithmetic family)
Tests: 12 generated
Status: CERTIFIED (Φ_c = 1)
Output: calcPrice.js, calcPrice.test.jsThe emitted JavaScript is clean, typed, and structured. But the real magic is calcPrice.test.js — twelve tests auto-generated from the formal verification. Not random inputs. Not edge cases a developer guessed. Tests derived from the mathematical properties of the circuit: boundary conditions, zero inputs, maximum values, the discount-before-tax ordering.
Step 4: The Auto-Generated Tests
// Auto-generated from PCD certification (Φ_c = 1)
// calcPrice: 4 inputs → 1 output, 4 monomers
test('zero quantity returns zero', () => {
expect(calcPrice(0, 100, 10, 5)).toBe(0);
});
test('zero discount applies full price', () => {
expect(calcPrice(10, 50, 10, 0)).toBe(550);
});
test('discount applies before tax', () => {
const withDisc = calcPrice(1, 100, 10, 20);
const withoutDisc = calcPrice(1, 100, 10, 0);
expect(withDisc).toBeLessThan(withoutDisc);
});
test('100% discount results in tax on zero', () => {
expect(calcPrice(10, 50, 10, 100)).toBe(0);
});
// ... 8 more tests covering all monomer boundariesThese tests are not opinions. They are consequences of the mathematical specification. The PCD blueprint defines the function. The tests prove the emitted code matches the blueprint. This is not "we think it works" — this is "the math says it works."
But Wait — Export to ANY Language
The PCD blueprint is language-independent. It describes computation, not syntax. From the same calcPrice.pcd blueprint:
brikc build calcPrice.pcd --target rust # Rust with ownership semantics
brikc build calcPrice.pcd --target python # Python with type hints
brikc build calcPrice.pcd --target go # Go with error handling
brikc build calcPrice.pcd --target c # C with headers
brikc build calcPrice.pcd --target cobol # Yes, even COBOLSame logic. Same verification. Same auto-generated tests adapted to each language's testing framework. Five languages from one blueprint. The PCD does not care what language you started with or what language you are going to. It cares about what your code does.
Your CTO says "we are migrating to Rust"? You do not rewrite 500,000 lines of JavaScript. You lift, verify, and emit. The blueprint guarantees behavioral equivalence. The tests prove it. The migration that would take two years takes two weeks.
The Two-Tier Certification
"But my code has API calls. It reads from databases. It writes to the filesystem. You can't formally verify fetch."
Correct. And BRIK-64 does not pretend to. Instead, it uses a two-tier certification system that handles real-world code honestly:
CORE (Φc = 1): Pure logic — arithmetic, string manipulation, control flow, data transformation. These operations are mathematically proven correct. The circuit is closed. The verification is absolute.
CONTRACT (Φc = CONTRACT): Side effects — fetch, console.log, filesystem operations, database queries, async operations. These are mapped to extended monomers. The contract says: "this operation performs X." The verification proves that all the logic surrounding the side effect is correct.
Think of it this way: BRIK-64 cannot prove that your API will return a 200. But it can prove that when the API returns a 200, your code processes the response correctly. And when it returns a 500, your error handling does the right thing. The pure logic is certified. The side effects are contracted. Together, they cover your entire application.
Your React app with fetch calls? Liftable. Your Node.js API with database queries? Liftable. Your Python data pipeline with file I/O? Liftable. The two-tier system means real-world code — not just textbook examples — gets the roundtrip treatment.
The Blueprint Is the Product
Most developers think the clean code is the output. It is not. The PCD blueprint is the output. The clean code is just one possible rendering of that blueprint.
Here is why the blueprint matters more than the code:
1. Single source of truth. The PCD defines what your code does, mathematically. Not what a developer intended. Not what a test suite covers. What the code actually computes.
2. Language-independent. Change your stack without rewriting logic. The blueprint persists across every language migration, every framework change, every platform shift.
3. Self-documenting. The blueprint IS the documentation. Read the PCD and you know exactly what the function does. No Javadoc. No JSDoc. No "see README for details." The specification is the documentation.
4. Permanently verifiable. Run brikc check anytime to re-verify. The blueprint does not rot. It does not become outdated. It is mathematically true today and mathematically true in ten years.
5. Composable. Combine certified circuits from the BRIK-64 registry. Build complex systems from verified building blocks. Every connection is type-checked. Every composition is certified.
The Business Case
The Roundtrip — Business Impact
──────────────────────────────────────────────────
PROBLEM PCD ROUNDTRIP
──────────────────────────────────────────────────
"Big rewrite" (2 years, fails) Lift incrementally, one function at a time
"Add tests later" (never) Tests auto-generated from specification
"Only Bob knows this code" Blueprint explains it — Bob can retire
"Can't switch to Rust" (500K JS) Emit to Rust from the same blueprints
"Docs are outdated" Blueprint IS the documentation
"How do we prove compliance?" Φ_c = 1 is the proof — auditable, permanent
──────────────────────────────────────────────────The roundtrip does not just improve your code. It changes the economics of software maintenance. Every function you lift becomes a function that any developer can understand, any language can render, and any auditor can verify. The cost of understanding code drops to zero — because the blueprint is the understanding.
What This Is Not
Let us be precise about what the PCD Roundtrip is not:
It is not transpilation. Transpilers convert syntax. They turn your messy JavaScript into messy TypeScript with the same structure and the same bugs. The roundtrip extracts the computation, verifies it, and regenerates from the specification. The output is not a translation — it is a recompilation from truth.
It is not a linter. Linters enforce style. They tell you to use const instead of var and add semicolons. The roundtrip does not care about your style. It cares about what your code computes — and whether that computation is correct.
It is not AI-powered refactoring. AI refactoring tools guess what your code should look like. The roundtrip does not guess. It extracts, verifies mathematically, and regenerates deterministically. Same input, same output, every time. No hallucinations. No "it looks right."
It is not magic. Code with side effects gets CONTRACT certification, not CORE. Functions with deeply dynamic behavior may have lower liftability scores. The Lifter tells you exactly what it can and cannot verify — honestly, with a number between 0.0 and 1.0.
Getting Started
# Install the BRIK-64 toolchain
curl -fsSL https://brik64.dev/install | bash
# Lift your code
brikc lift your_app.js --output lifted/
# Check the blueprints
for f in lifted/*.pcd; do brikc check "$f"; done
# Export back to clean JS (or Rust, Python, Go, C...)
for f in lifted/*.pcd; do brikc build "$f" --target js --output clean/; done
# Run the auto-generated tests
cd clean/ && npm testStart with the function your team dreads touching. The one with no tests, no documentation, and a comment that says "don't change this." Lift it. Read the blueprint. For the first time, you will see what that function actually does — not what someone intended, not what the tests cover, but what the code computes, expressed as a formal circuit.
Then emit it back. Clean code. Auto-generated tests. A permanent specification. Do it for one function. Then do it for ten. Then do it for the entire module.
Your codebase is not broken. It is undocumented, unverified, and locked into one language. The roundtrip fixes all three — permanently.
The Messy Code Goes In. The Blueprint Comes Out.
Your code already works. Probably. But can you prove it? Can you export it to another language in one command? Can you auto-generate tests from a mathematical specification? Can you hand the specification to a new developer and have them understand the entire system in an afternoon?
Now you can. The messy code goes in. The blueprint comes out. And from the blueprint, clean code in any language — with tests, with verification, with certainty.
That is not refactoring. That is not transpilation. That is recompilation from truth.