> For the complete documentation index, see [llms.txt](https://docs.talus.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.talus.network/talus-docs-v2.1.0/reference/move/nexus_policy/automaton.md).

# nexus\_policy::automaton

* [Struct `DeterministicAutomaton`](#struct-deterministicautomaton)
* [Struct `ConfiguredAutomaton`](#struct-configuredautomaton)
* [Struct `TransitionKey`](#struct-transitionkey)
* [Struct `TransitionConfigKey`](#struct-transitionconfigkey)
* [Constants](#constants)
* [Function `new`](#function-new)
* [Function `states`](#function-states)
* [Function `alphabet`](#function-alphabet)
* [Function `start_state`](#function-start_state)
* [Function `start_index`](#function-start_index)
* [Function `state_at`](#function-state_at)
* [Function `delta`](#function-delta)
* [Function `delta_indexed`](#function-delta_indexed)
* [Function `run`](#function-run)
* [Function `run_from`](#function-run_from)
* [Function `is_accepting`](#function-is_accepting)
* [Function `accepts`](#function-accepts)
* [Function `set_transition`](#function-set_transition)
* [Function `set_transition_indexed`](#function-set_transition_indexed)
* [Function `add_symbol`](#function-add_symbol)
* [Function `add_state`](#function-add_state)
* [Function `set_accepting_state`](#function-set_accepting_state)
* [Function `symbol_index_of`](#function-symbol_index_of)
* [Function `expect_symbol_index_of`](#function-expect_symbol_index_of)
* [Function `expect_state_index_of`](#function-expect_state_index_of)
* [Function `new_configured`](#function-new_configured)
* [Function `borrow_core`](#function-borrow_core)
* [Function `borrow_core_mut`](#function-borrow_core_mut)
* [Function `register_symbol_config`](#function-register_symbol_config)
* [Function `register_transition_config`](#function-register_transition_config)
* [Function `borrow_transition_config`](#function-borrow_transition_config)
* [Function `borrow_mut_transition_config`](#function-borrow_mut_transition_config)
* [Function `has_symbol_config`](#function-has_symbol_config)
* [Function `borrow_symbol_config`](#function-borrow_symbol_config)
* [Function `borrow_mut_symbol_config`](#function-borrow_mut_symbol_config)
* [Function `remove_symbol_config`](#function-remove_symbol_config)
* [Function `remove_transition_config`](#function-remove_transition_config)

### Struct `DeterministicAutomaton`

Deterministic automaton with states `State` and alphabet `Symbol`.

The structure mirrors the mathematical definition:

* [`states`](#nexus_policy_automaton_states): ordered basis of states used to compute stable indices.
* [`alphabet`](#nexus_policy_automaton_alphabet): ordered basis of symbols.
* `transition`: `|States| × |Alphabet|` matrix of successor state indices.
* `accepting`: bitmap marking accepting states inside the basis.
* `start`: index of the distinguished start state.

```move
public struct DeterministicAutomaton<phantom State: copy, drop, store, phantom Symbol: copy, drop, store> has store
```

<details>

<summary>Fields</summary>

[`states`](#nexus_policy_automaton_states)`: sui::table_vec::TableVec<State>`[`alphabet`](#nexus_policy_automaton_alphabet)`: sui::table_vec::TableVec<Symbol>transition: sui::table_vec::TableVec<sui::table_vec::TableVec<u64>>accepting: sui::table_vec::TableVec<bool>start: u64`

</details>

#### Struct `ConfiguredAutomaton`

DFA bundled with transition scoped metadata stored as dynamic fields.

Callers can attach arbitrary `Config` payloads keyed by `(state, symbol, Config)` and fetch them later when evaluating transitions.

```move
public struct ConfiguredAutomaton<phantom State: copy, drop, store, phantom Symbol: copy, drop, store> has key, store
```

<details>

<summary>Fields</summary>

`id: sui::object::UIDdfa:` [`nexus_policy::automaton::DeterministicAutomaton`](#nexus_policy_automaton_DeterministicAutomaton)`<State, Symbol>`

</details>

#### Struct `TransitionKey`

Key for transition metadata. `state = none()` denotes a wildcard over all states for the given symbol.

```move
public struct TransitionKey<State: copy, drop, store, Symbol: copy, drop, store> has copy, drop, store
```

<details>

<summary>Fields</summary>

`state: std::option::Option<State>symbol: Symbol`

</details>

#### Struct `TransitionConfigKey`

Key for a specific transition metadata type.

```move
public struct TransitionConfigKey<State: copy, drop, store, Symbol: copy, drop, store> has copy, drop, store
```

<details>

<summary>Fields</summary>

`transition:` [`nexus_policy::automaton::TransitionKey`](#nexus_policy_automaton_TransitionKey)`<State, Symbol>config: std::type_name::TypeName`

</details>

#### Constants

Error: DFA must contain at least one state.

```move
#[error]
const EStatesEmpty: vector<u8> = b"deterministic automaton needs at least one state";
```

Error: referenced state is not in the basis.

```move
#[error]
const EStateNotInBasis: vector<u8> = b"state not contained in the chosen basis";
```

Error: referenced symbol is not in the alphabet.

```move
#[error]
const ESymbolNotInAlphabet: vector<u8> = b"symbol not contained in the alphabet";
```

Error: states must be unique.

```move
#[error]
const EStateDuplicate: vector<u8> = b"duplicate state in automaton basis";
```

Error: symbols must be unique.

```move
#[error]
const ESymbolDuplicate: vector<u8> = b"duplicate symbol in alphabet";
```

Error: transition rows or columns do not match the expected matrix shape.

```move
#[error]
const ETransitionShape: vector<u8> = b"transition table must be |States| by |Alphabet|";
```

Error: supplied transitions have a different length than the automaton basis.

```move
#[error]
const ETransitionLengthMismatch: vector<u8> = b"transition length does not match automaton basis";
```

Error: attempted to register a state already present in the basis.

```move
#[error]
const EStateAlreadyExists: vector<u8> = b"state already registered in automaton";
```

Error: attempted to register a symbol already present in the alphabet.

```move
#[error]
const ESymbolAlreadyExists: vector<u8> = b"symbol already registered in alphabet";
```

Error: duplicate metadata registration for a transition/config pair.

```move
#[error]
const ETransitionConfigAlreadyRegistered: vector<u8> = b"transition config already registered";
```

Error: expected metadata for a transition/config pair is missing.

```move
#[error]
const ETransitionConfigMissing: vector<u8> = b"transition config missing";
```

#### Function `new`

Build the automaton from its canonical data `(`[`states`](#nexus_policy_automaton_states)`,` [`alphabet`](#nexus_policy_automaton_alphabet)`, transition, start, accepting)`.

`transitions[i][j]` represents `δ(`[`states`](#nexus_policy_automaton_states)`[i],` [`alphabet`](#nexus_policy_automaton_alphabet)`[j])` as a state value. The accepting set is provided as a list (duplicates are ignored). Inputs are normalized into index based matrices and bitmaps to avoid repeated lookups later.

```move
public fun new<State: copy, drop, store, Symbol: copy, drop, store>(states: sui::table_vec::TableVec<State>, alphabet: sui::table_vec::TableVec<Symbol>, start: State, accepting: sui::table_vec::TableVec<State>, transitions: sui::table_vec::TableVec<sui::table_vec::TableVec<State>>, ctx: &mut sui::tx_context::TxContext): nexus_policy::automaton::DeterministicAutomaton<State, Symbol>
```

#### Function `states`

Underlying basis States.

```move
public fun states<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>): &sui::table_vec::TableVec<State>
```

#### Function `alphabet`

Alphabet Symbols.

```move
public fun alphabet<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>): &sui::table_vec::TableVec<Symbol>
```

#### Function `start_state`

Distinguished start state.

```move
public fun start_state<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>): State
```

#### Function `start_index`

Distinguished start state index inside the basis.

```move
public fun start_index<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>): u64
```

#### Function `state_at`

Borrow the state value located at a basis index.

```move
public fun state_at<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, index: u64): State
```

#### Function `delta`

Evaluate transition function on a single symbol using values.

Aborts if either the state or symbol is outside the basis.

```move
public fun delta<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state: &State, symbol: &Symbol): State
```

#### Function `delta_indexed`

Evaluate transition function using basis indices.

```move
public fun delta_indexed<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state_index: u64, symbol_index: u64): u64
```

#### Function `run`

Extend transition function to words starting from the start state.

Example:

```move
let final = automaton::run(&dfa, &word);
let accepted = automaton::is_accepting(&dfa, &final);
```

```move
public fun run<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, word: &sui::table_vec::TableVec<Symbol>): State
```

#### Function `run_from`

Extend transition function to words from an arbitrary starting state.

```move
public fun run_from<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state: &State, word: &sui::table_vec::TableVec<Symbol>): State
```

#### Function `is_accepting`

Membership in the accepting set Accepting.

```move
public fun is_accepting<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state: &State): bool
```

#### Function `accepts`

Decide whether a word is accepted.

```move
public fun accepts<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, word: &sui::table_vec::TableVec<Symbol>): bool
```

#### Function `set_transition`

Mutate transition function on a single `(state, symbol)` pair.

The successor is stored canonically as an index.

```move
public fun set_transition<State: copy, drop, store, Symbol: copy, drop, store>(self: &mut nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state: &State, symbol: &Symbol, next: State)
```

#### Function `set_transition_indexed`

Mutate transition function using basis indices.

```move
public fun set_transition_indexed<State: copy, drop, store, Symbol: copy, drop, store>(self: &mut nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state_index: u64, symbol_index: u64, next_index: u64)
```

#### Function `add_symbol`

Extend the alphabet with a new symbol and associated transitions.

```move
public fun add_symbol<State: copy, drop, store, Symbol: copy, drop, store>(self: &mut nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, symbol: Symbol, transitions: &sui::table_vec::TableVec<State>): u64
```

#### Function `add_state`

Register a new state together with its outgoing transitions and acceptance flag.

```move
public fun add_state<State: copy, drop, store, Symbol: copy, drop, store>(self: &mut nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state: State, accepting: bool, transitions: &sui::table_vec::TableVec<State>, ctx: &mut sui::tx_context::TxContext): u64
```

#### Function `set_accepting_state`

Update whether a state is accepting.

```move
public fun set_accepting_state<State: copy, drop, store, Symbol: copy, drop, store>(self: &mut nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state: &State, accepting: bool)
```

#### Function `symbol_index_of`

Locate the index of a symbol inside the alphabet.

```move
public fun symbol_index_of<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, symbol: &Symbol): std::option::Option<u64>
```

#### Function `expect_symbol_index_of`

Resolve the index of a symbol or abort if it is not part of the alphabet.

```move
public fun expect_symbol_index_of<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, symbol: &Symbol): u64
```

#### Function `expect_state_index_of`

Resolve the index of a state or abort if it is not part of the basis.

```move
public fun expect_state_index_of<State: copy, drop, store, Symbol: copy, drop, store>(self: &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, state: &State): u64
```

#### Function `new_configured`

Configure a DFA with transition metadata keyed by `(state, symbol)`.

```move
public fun new_configured<State: copy, drop, store, Symbol: copy, drop, store>(dfa: nexus_policy::automaton::DeterministicAutomaton<State, Symbol>, ctx: &mut sui::tx_context::TxContext): nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>
```

#### Function `borrow_core`

Borrow the underlying DFA.

```move
public fun borrow_core<State: copy, drop, store, Symbol: copy, drop, store>(configured: &nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>): &nexus_policy::automaton::DeterministicAutomaton<State, Symbol>
```

#### Function `borrow_core_mut`

Borrow the underlying DFA mutably.

```move
public fun borrow_core_mut<State: copy, drop, store, Symbol: copy, drop, store>(configured: &mut nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>): &mut nexus_policy::automaton::DeterministicAutomaton<State, Symbol>
```

#### Function `register_symbol_config`

Register a config for the wildcard `(*, symbol)` transition.

```move
public fun register_symbol_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &mut nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, symbol: Symbol, config: Config)
```

#### Function `register_transition_config`

Register a config scoped to `(state, symbol)`.

```move
public fun register_transition_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &mut nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, state: State, symbol: Symbol, config: Config)
```

#### Function `borrow_transition_config`

Borrow a config for `(state, symbol)`, falling back to wildcard.

```move
public fun borrow_transition_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, state: State, symbol: Symbol): &Config
```

#### Function `borrow_mut_transition_config`

Borrow a mutable config for `(state, symbol)`, falling back to wildcard.

```move
public fun borrow_mut_transition_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &mut nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, state: State, symbol: Symbol): &mut Config
```

#### Function `has_symbol_config`

Returns true if a wildcard config exists for `symbol`.

```move
public fun has_symbol_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, symbol: Symbol): bool
```

#### Function `borrow_symbol_config`

Borrow the wildcard config for `(*, symbol)`.

```move
public fun borrow_symbol_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, symbol: Symbol): &Config
```

#### Function `borrow_mut_symbol_config`

Borrow the wildcard config for `(*, symbol)` mutably.

```move
public fun borrow_mut_symbol_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &mut nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, symbol: Symbol): &mut Config
```

#### Function `remove_symbol_config`

Removes metadata for every state transition on one symbol.

```move
public fun remove_symbol_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &mut nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, symbol: Symbol): Config
```

#### Function `remove_transition_config`

Removes metadata for one state and symbol transition.

```move
public fun remove_transition_config<State: copy, drop, store, Symbol: copy, drop, store, Config: store>(configured: &mut nexus_policy::automaton::ConfiguredAutomaton<State, Symbol>, state: State, symbol: Symbol): Config
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.talus.network/talus-docs-v2.1.0/reference/move/nexus_policy/automaton.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
