# `ReductionBounds.Protocol`
[🔗](https://github.com/zacky1972/reduction_bounds/blob/v0.1.0/lib/reduction_bounds/protocol.ex#L1)

Finite communication models shared by Port and request/response analyses.

Each registered work event has exactly one owner and one cost unit. An
environment event has neither; its occurrence describes an observation,
not a bound on the environment's work. Participants may use different units.
No cross-participant sum or numeric cost is computed here.

Contracts declare states, terminal states, event metadata, and transitions.
`check_trace/2` checks supplied model events, including unfinished prefixes.
It does not inspect target code, prove progress, or establish runtime charges.
Cycles permit retry and inspection traces; count bounds belong to later
analysis. An accepted finite trace does not establish a bound for every run.

## Example

    iex> alias ReductionBounds.{PortProtocol, Protocol}
    iex> {:ok, contract} = PortProtocol.new()
    iex> {:ok, prepare} = Protocol.event(contract, :prepare)
    iex> {:ok, trace} = Protocol.check_trace(contract, [prepare])
    iex> {trace.final, trace.terminal?}
    {:prepared, false}

# `check_trace`

```elixir
@spec check_trace(ReductionBounds.Protocol.Contract.t(), [
  ReductionBounds.Protocol.Event.t()
]) ::
  {:ok, ReductionBounds.Protocol.Trace.t()} | {:error, term()}
```

Checks a finite trace. Event diagnostics contain a zero-based occurrence index.

# `event`

```elixir
@spec event(ReductionBounds.Protocol.Contract.t(), atom()) ::
  {:ok, ReductionBounds.Protocol.Event.t()} | {:error, term()}
```

Constructs an event with the contract's declared ownership and unit.

# `events_for`

```elixir
@spec events_for(ReductionBounds.Protocol.Trace.t(), atom()) :: [
  ReductionBounds.Protocol.Event.t()
]
```

Selects event occurrences assigned to one participant without combining units.

# `new`

```elixir
@spec new(keyword()) ::
  {:ok, ReductionBounds.Protocol.Contract.t()} | {:error, term()}
```

Builds and validates a finite protocol contract.

# `validate`

```elixir
@spec validate(term()) :: :ok | {:error, term()}
```

Validates contracts, including directly constructed structs.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
