forked from maxitg/SetReplace
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSetReplaceFixedPoint.m
68 lines (39 loc) · 1.42 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(* ::Package:: *)
(* ::Title:: *)
(*SetReplaceFixedPoint*)
(* ::Text:: *)
(*Same as SetReplace, but automatically stops replacing when the set no longer changes.*)
Package["SetReplace`"]
PackageExport["SetReplaceFixedPoint"]
(* ::Section:: *)
(*Documentation*)
SetReplaceFixedPoint::usage = usageString[
"SetReplaceFixedPoint[`s`, {\!\(\*SubscriptBox[\(`i`\), \(`1`\)]\) \[Rule] ",
"\!\(\*SubscriptBox[\(`o`\), \(`1`\)]\), ",
"\!\(\*SubscriptBox[\(`i`\), \(`2`\)]\) \[Rule] ",
"\!\(\*SubscriptBox[\(`o`\), \(`2`\)]\), \[Ellipsis]}] performs SetReplace repeatedly ",
"until no further events can be matched, and returns the final set.",
"\n",
"Will go into infinite loop if fixed point does not exist."];
(* ::Section:: *)
(*Syntax Information*)
SyntaxInformation[SetReplaceFixedPoint] =
{"ArgumentsPattern" -> {_, _, OptionsPattern[]}};
(* ::Section:: *)
(*Argument Checks*)
(* ::Subsection:: *)
(*Argument count*)
SetReplaceFixedPoint[args___] := 0 /;
!Developer`CheckArgumentCount[SetReplaceFixedPoint[args], 2, 2] && False
(* ::Section:: *)
(*Options*)
Options[SetReplaceFixedPoint] := Options[setSubstitutionSystem]
(* ::Section:: *)
(*Implementation*)
SetReplaceFixedPoint[set_, rules_, o : OptionsPattern[]] := Module[{result},
result = Check[
setSubstitutionSystem[
rules, set, <||>, SetReplaceFixedPoint, False, o],
$Failed];
If[result === $Aborted, result, result[-1]] /; result =!= $Failed
]