Function Repository Resource:

CanonicalWolframModelRule

Source Notebook

Attempt to find a canonical representation for a Wolfram model

Contributed by: Ed Pegg

ResourceFunction["CanonicalWolframModelRule"][rule]

attempts to find a canonical version of the specified Wolfram model rule.

ResourceFunction["CanonicalWolframModelRule"][rule,"Letter"]

produces a canonical letter form of the specified Wolfram model rule.

Details and Options

The canonicalization follows several rules:
1.Tuples are sorted by length, with longest tuples occurring first
2.Tuples of the same length on the same side of a rule are considered a rule part
3.A rule part with 3 tuples of length 2 has signature 32
4.Rule parts are ordered so that new alphabet terms are introduced with maximal frugality
ResourceFunction["CanonicalWolframModelRule"] uses a heuristic method and may not give a complete canonical form in all cases.

Examples

Basic Examples (3) 

Rename nodes and re-sort rules to find a canonical form:

In[1]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{2, 3, 3}} -> {{3, 2, 2}, {2, 1, 1}}]
Out[1]=
In[2]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{2, 3, 3}} -> {{3, 2, 2}, {2, 1, 1}}, "Letter"]
Out[2]=
In[3]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{{2, 3, 3}} -> {{3, 2, 2}, {2, 1, 1}}, {{a, e, d}, {d, c}, {c, b}, {b, a}} -> {{}}}]
Out[3]=
In[4]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{{2, 3, 3}} -> {{3, 2, 2}, {2, 1, 1}}, {{a, e, d}, {d, c}, {c, b}, {b, a}} -> {{}}}, "Letter"]
Out[4]=

A slightly more complicated case:

In[5]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{0, 1}, {0, 2}, {0, 3}} -> {{4, 5}, {5,
     4}, {4, 6}, {6, 4}, {5, 6}, {6, 5}, {4, 1}, {5, 2}, {6, 3}, {1, 6}, {3, 4}}]
Out[5]=
In[6]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{0, 1}, {0, 2}, {0, 3}} -> {{4, 5}, {5,
     4}, {4, 6}, {6, 4}, {5, 6}, {6, 5}, {4, 1}, {5, 2}, {6, 3}, {1, 6}, {3, 4}}, "Letter"]
Out[6]=

CanonicalWolframModelRule can handle any names for elements:

In[7]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{a, e, d}, {d, c}, {c, b}, {b, a}} -> {{}}]
Out[7]=
In[8]:=
ResourceFunction[
 "CanonicalWolframModelRule"][{{a, e, d}, {d, c}, {c, b}, {b, a}} -> {{}}, "Letter"]
Out[8]=

Some difficult cases:

In[9]:=
ResourceFunction["CanonicalWolframModelRule"][hardrule]
Out[9]=
In[10]:=
ResourceFunction["CanonicalWolframModelRule"][hardrule, "Letter"]
Out[10]=
In[11]:=
ResourceFunction["CanonicalWolframModelRule"][difficult]
Out[11]=
In[12]:=
ResourceFunction["CanonicalWolframModelRule"][difficult, "Letter"]
Out[12]=

Version History

  • 2.0.0 – 24 March 2020
  • 1.0.0 – 09 March 2020

Related Resources

License Information