-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathSetReplaceFixedPoint.m
35 lines (27 loc) · 1.15 KB
/
SetReplaceFixedPoint.m
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
Package["SetReplace`"]
PackageImport["GeneralUtilities`"]
PackageExport["SetReplaceFixedPoint"]
(* Same as SetReplace, but automatically stops replacing when the set no longer changes. *)
SetUsage @ "
SetReplaceFixedPoint[set$, {input$1 -> output$1, input$2 -> output$2, $$}] performs SetReplace repeatedly until \
no further events can be matched, and returns the final set.
It will go into an infinite loop if a fixed point does not exist.
";
Options[SetReplaceFixedPoint] = {
Method -> Automatic,
TimeConstraint -> Infinity,
"EventOrderingFunction" -> Automatic};
SyntaxInformation[SetReplaceFixedPoint] = {
"ArgumentsPattern" -> {set_, rules_, OptionsPattern[]},
"OptionNames" -> Options[SetReplaceFixedPoint][[All, 1]]};
SetReplaceFixedPoint[args___] := 0 /;
!Developer`CheckArgumentCount[SetReplaceFixedPoint[args], 2, 2] && False;
SetReplaceFixedPoint[set_, rules_, o : OptionsPattern[]] /;
recognizedOptionsQ[expr, SetReplaceFixedPoint, {o}] := ModuleScope[
result = Check[
setSubstitutionSystem[rules, set, <||>, SetReplaceFixedPoint, False, o]
,
$Failed
];
If[result === $Aborted, result, result[-1]] /; result =!= $Failed
];