-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathSetReplaceAll.m
More file actions
43 lines (34 loc) · 1.63 KB
/
Copy pathSetReplaceAll.m
File metadata and controls
43 lines (34 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Package["SetReplace`"]
PackageImport["GeneralUtilities`"]
PackageExport["SetReplaceAll"]
(* The idea for SetReplaceAll is to keep performing SetReplace on the graph until no replacement can be done without
touching the same edge twice.
Note, it's not doing replacement until all edges are touched at least once. That may not always be possible. We just
don't want to touch edges twice in a single step. *)
SetUsage @ "
SetReplaceAll[set$, rules$] performs SetReplace[set$, rules$] as many times as it takes until no \
replacement can be done without touching the same expression twice.
SetReplaceAll[set$, rules$, generationCount$] performes the same operation generationCount$ times, i.e., any edge will \
at most be replaced generationCount$ times.
";
Options[SetReplaceAll] = {
Method -> Automatic,
TimeConstraint -> Infinity,
"EventOrderingFunction" -> Automatic};
SyntaxInformation[SetReplaceAll] = {
"ArgumentsPattern" -> {set_, rules_, generationCount_., OptionsPattern[]},
"OptionNames" -> Options[SetReplaceAll][[All, 1]]};
SetReplaceAll[args___] := 0 /;
!Developer`CheckArgumentCount[SetReplaceAll[args], 2, 3] && False;
(* We just run SetSubstitutionSystem for the specified number of generations, and take the last set. *)
expr : SetReplaceAll[
set_, rules_, generationCount : Except[_ ? OptionQ] : 1, o : OptionsPattern[]] /;
recognizedOptionsQ[expr, SetReplaceAll, {o}] :=
ModuleScope[
result = Check[
setSubstitutionSystem[rules, set, <|$maxGenerationsLocal -> generationCount|>, SetReplaceAll, False, o]
,
$Failed
];
If[result === $Aborted, result, result[-1]] /; result =!= $Failed
];