# `WolframModel.Matcher`
[🔗](https://github.com/sragli/wolfram_model/blob/main/lib/wolfram_model/matcher.ex#L1)

Deterministic pattern matcher for WolframModel.

Exposes a general `match/2` that handles rules with any number of pattern
hyperedges (1, 2, or N) via recursive backtracking. Patterns are matched
positionally: the element at position i in the pattern binds to the element
at position i in the matched hyperedge. Shared variables across patterns must
map to the same vertex in every matched hyperedge.

Hyperedges are ordered lists. Each pattern variable can be any term; atoms
and integers are treated as variable names to bind.

# `match_result`

```elixir
@type match_result() :: %{
  mapping: map(),
  matched_hyperedges: [Hypergraph.hyperedge()]
}
```

# `build_mapping_for_two`

```elixir
@spec build_mapping_for_two([term()], [term()], [term()], [term()]) :: map()
```

Builds a merged mapping from two (pattern, hyperedge) pairs.
Kept for backward compatibility.

# `match`

```elixir
@spec match([Hypergraph.hyperedge()], [Hypergraph.hyperedge()]) :: [match_result()]
```

Finds all ways to match `patterns` against `hyperedges` with consistent
variable bindings. Supports patterns of any length (1, 2, or N hyperedges).

Returns a list of `%{mapping: map(), matched_hyperedges: [hyperedge()]}`.
Each matched_hyperedges list has the same length as `patterns` and is in the
same order. Each distinct hyperedge in the graph may only be used once per
match (no self-overlap).

---

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