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}}"
Summary
Functions
Parses a rule string in the Wolfram notation "LHS -> RHS" and returns a
rule map with :pattern, :replacement, and :name set to "parsed".
Formats a rule as a Wolfram-notation string.
Types
@type rule() :: WolframModel.rule()
Functions
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.
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}}"