canonical
canonical, function
def process canonical(old: text, new: text): text
Returns the canonical replacement for each old value by following the edges
(old, new) until a terminal replacement is reached.
old: source code for each edge.new: replacement code for each edge.
Examples
Without grouping, the graph is treated as a single set of edges.
table Edges = with
[| as Old, as New |]
[| "x-00", "ax-00" |]
[| "x-01", "ax-01" |]
[| "ax-00", "ax-03" |]
Edges.Canon = canonical(Edges.Old, Edges.New)
show table "Canonical" with
Edges.Old
Edges.New
Edges.Canon
This produces the following table:
| Old | New | Canon |
|---|---|---|
| x-00 | ax-00 | ax-03 |
| x-01 | ax-01 | ax-01 |
| ax-00 | ax-03 | ax-03 |
With by, the canonical replacement is computed independently per group.
table Edges = with
[| as Old, as New, as Group |]
[| "x-00", "ax-00", "A" |]
[| "x-01", "ax-01", "A" |]
[| "ax-00", "ax-03", "A" |]
[| "b-01", "b-02", "B" |]
[| "b-02", "b-02", "B" |]
Edges.Canon = canonical(Edges.Old, Edges.New) by Edges.Group
show table "Canonical" with
Edges.Group
Edges.Old
Edges.New
Edges.Canon
This produces the following table:
| Group | Old | New | Canon |
|---|---|---|---|
| A | x-00 | ax-00 | ax-03 |
| A | x-01 | ax-01 | ax-01 |
| A | ax-00 | ax-03 | ax-03 |
| B | b-01 | b-02 | b-02 |
| B | b-02 | b-02 | b-02 |
Remarks
canonical expects each old value to have one terminal replacement. Cycles or
branching paths can prevent a canonical replacement from being defined; use
noncanonical to filter out problematic edges before calling canonical.
Use by to compute canonical replacements independently per group. Omitting
by treats all edges as part of the same graph.