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

Parser and printer for the canonical Wolfram rule notation.

Rules are written in the format used throughout the Wolfram Physics Project:

    {{x,y,z},{x,w}} -> {{y,w,z},{y,z},{x,y,w}}

Vertices are either integers (`1`, `2`, …) or symbolic names (`x`, `y`, `z`).
The notation maps directly to the `%{pattern: ..., replacement: ..., name: ...}`
maps consumed by `WolframModel`.

## Examples

    iex> WolframModel.Rule.parse("{{1,2},{1,3}} -> {{2,3},{1,4}}")
    %{pattern: [[1, 2], [1, 3]], replacement: [[2, 3], [1, 4]], name: "parsed"}

    iex> rule = %{pattern: [[1,2],[2,3]], replacement: [[1,3]], name: "join"}
    iex> WolframModel.Rule.to_string(rule)
    "{{1,2},{2,3}} -> {{1,3}}"

# `rule`

```elixir
@type rule() :: WolframModel.rule()
```

# `parse`

```elixir
@spec parse(String.t(), String.t()) :: rule()
```

Parses a rule string in the Wolfram notation `"LHS -> RHS"` and returns a
rule map with `:pattern`, `:replacement`, and `:name` set to `"parsed"`.

Vertices can be integers or symbolic names. Symbolic names become atoms.

Raises `ArgumentError` when the string cannot be parsed.

# `to_string`

```elixir
@spec to_string(rule()) :: String.t()
```

Formats a rule as a Wolfram-notation string.

    %{pattern: [[1,2],[2,3]], replacement: [[1,3]]} |> WolframModel.Rule.to_string()
    #=> "{{1,2},{2,3}} -> {{1,3}}"

---

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