Skip to content

Walk sets of states instead of determinizing - #28

Open
alexvbrdn wants to merge 3 commits into
mainfrom
avoid-determinization
Open

alexvbrdn wants to merge 3 commits into
mainfrom
avoid-determinization

Conversation

@alexvbrdn

Copy link
Copy Markdown
Member

What this changes

equivalent, subset, cardinality and difference no longer determinize or complement their operands. Instead they work on the sets of states a word can reach in each automaton, and only build the sets that are actually reached. Determinizing first can produce exponentially many states, so these operations are now much faster on non-deterministic automata.

  • equivalent: bisimulation up to congruence (HKC, Bonchi & Pous, POPL 2013). Two deterministic automata are compared state by state with Hopcroft & Karp (1971), in close to linear time.
  • subset: antichains (De Wulf, Doyen, Henzinger & Raskin, CAV 2006), in the forward form.
  • cardinality: on a non-deterministic automaton with a finite language, strings are counted per set of states, so a string with several paths is counted once. It returns BigInteger as soon as one set's count overflows.
  • difference: each state of the result pairs a state of the minuend with the set of subtrahend states the same word reaches. Only the pairs the minuend reaches are built.

Also:

  • has_intersection no longer builds the intersection.
  • Term::is_finite looks for a cycle on an accepting path instead of counting strings.
  • Term::is_total uses subset instead of determinizing.
  • remove_state / remove_states no longer scan every state's transitions.
  • SharedSpanningSet replaces the spanning-set merge code that was duplicated across intersection, has_intersection and the new algorithms.
  • FastAutomaton::transitions_from now returns an iterator that can be cloned (+ Clone).

Behaviour change: when the execution profile disables implicit determinization, FastAutomaton::equivalent, subset, cardinality and difference now accept non-deterministic automata instead of returning EngineError::DeterministicAutomatonRequired. max_number_of_states caps the pairs or sets they visit. Only minimize and complement still determinize implicitly.

On the new benches in benches/operations.rs:

  • equivalent / subset: 2 to 20 times faster, and about 100 times faster where most pairs are skipped.
  • difference: up to 3 times faster, and about 170 times faster when the minuend reaches few of the subtrahend's sets.
  • has_intersection: about 3 times faster.
  • minimize: 17% faster on the large pattern.

Checklist

  • cargo fmt --all --check and cargo clippy --all-targets -- -D warnings pass
  • cargo test and cargo test --no-default-features pass
  • New public items are documented
  • A test covers the change
  • CHANGELOG.md is updated under ## [Unreleased]
  • The change builds on Rust 1.88, or the MSRV bump is intentional and noted

@alexvbrdn alexvbrdn self-assigned this Nov 19, 2026
equivalent, subset, cardinality and difference no longer determinize or
complement their operands: they walk the sets of states a word can reach
(bisimulation up to congruence for equivalent, antichains for subset).
Two deterministic automata are compared with Hopcroft & Karp.

has_intersection no longer builds the intersection, Term::is_finite looks
for a cycle instead of counting, Term::is_total uses subset, and
remove_state(s) no longer scan every state's transitions.
@alexvbrdn
alexvbrdn force-pushed the avoid-determinization branch from 2c16da9 to ea0e939 Compare November 19, 2026 18:21
Since #11, `union_mut_nondegenerate` checks the state limit with
`union_state_count_nondegenerate`, and only `test_heuristic` used
`union_state_count_heuristic`, which added the degenerate cases and was
kept in the `impl` behind `#[cfg(test)]`. It is now a helper of the
tests module, and the remaining count is `union_state_count`.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant