ReductionBounds.Protocol (ReductionBounds v0.1.0)

Copy Markdown View Source

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}

Summary

Functions

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

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

Selects event occurrences assigned to one participant without combining units.

Builds and validates a finite protocol contract.

Validates contracts, including directly constructed structs.

Functions

check_trace(contract, input)

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

event(contract, name)

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

events_for(trace, owner)

Selects event occurrences assigned to one participant without combining units.

new(options)

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

Builds and validates a finite protocol contract.

validate(contract)

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

Validates contracts, including directly constructed structs.