> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brik64.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PCD Tutorial

> Write a BRIK64 Program Circuit Description from a bounded requirement.

PCD means Program Circuit Description. A PCD is not a general script; it is a circuit blueprint for bounded logic.

This tutorial builds an `order_risk` circuit.

## 1. Start With A Bounded Requirement

Do not start from implementation. Start from behavior:

```text theme={null}
Approve an order only when:
- amount is positive
- limit is positive
- amount does not exceed limit

Otherwise block the order.
```

## 2. Declare Inputs And Output

```text theme={null}
inputs:
- amount
- limit

output:
- 1 means approve
- 0 means block
```

## 3. Declare Fail-Closed Behavior

```text theme={null}
amount <= 0 -> 0
limit <= 0 -> 0
amount > limit -> 0
otherwise -> 1
```

This is the circuit contract an agent must preserve.

## 4. Write The PCD

```pcd theme={null}
PC order_risk {
    fn evaluate(amount, limit) {
        if (amount <= 0) {
            return 0;
        }

        if (limit <= 0) {
            return 0;
        }

        if (amount > limit) {
            return 0;
        }

        return 1;
    }
}
```

The structure matters:

* every branch returns a defined value;
* negative or zero inputs block;
* the approval path is the final path;
* no external state is required.

## 5. Generate The Starter Candidate

`brik64 pcd generate order-risk` is available only in generation-capable builds.
For the current public CLI beta, create or review a `.pcd` file manually unless
`brik64 help` lists the generation command.

Review generated output before composing it into a Polymer. Generation is not a substitute for reviewing the declared inputs, outputs and fail-closed behavior.

## 6. Use Supported Numeric Monomers When The Operation Is Atomic

For public CLI Beta14.1 PCD files, direct monomer calls are limited to the
numeric parser profile: `MC_00.ADD8`, `MC_01.SUB8`, `MC_02.MUL8`,
`MC_03.DIV8`, and `MC_04.MOD8`.

```pcd theme={null}
PC add8_gate {
    fn add8_gate(a: i64, b: i64) -> i64 {
        return MC_00.ADD8(a, b);
    }
}
```

String and extended monomer helpers remain SDK-level examples or roadmap syntax
until the PCD parser exposes those operations publicly.

## 7. Agent Checklist

* The requirement is restated in bounded form.
* Inputs and output are named.
* Fail-closed behavior is explicit.
* Every branch returns a value.
* Monomers are selected from the catalog.
* Extended or external behavior is identified before composition.
* The PCD can be reviewed without hidden source context.
