-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathHypergraphUnifications.wlt
136 lines (113 loc) · 3.73 KB
/
HypergraphUnifications.wlt
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<|
"HypergraphUnifications" -> <|
"init" -> (
Attributes[Global`testUnevaluated] = Attributes[Global`testSymbolLeak] = {HoldAll};
Global`testUnevaluated[args___] := SetReplace`PackageScope`testUnevaluated[VerificationTest, args];
Global`testSymbolLeak[args___] := SetReplace`PackageScope`testSymbolLeak[VerificationTest, args];
correctOverlapQ[e1_, e2_, unifyingHypergraph_, match1_, match2_] := And @@ MapThread[
DuplicateFreeQ[First /@ Union[Thread[Catenate[#1] -> Catenate[#2]]]] &,
{{e1, e2}, (unifyingHypergraph[[Values[#]]] &) /@ {match1, match2}}]
),
"tests" -> {
testSymbolLeak[
HypergraphUnifications[{{1, 2}, {2, 3}, {3, 4, 5}}, {{a, b}, {b, c}, {c, d, e}}]
],
testUnevaluated[
HypergraphUnifications[],
{HypergraphUnifications::argrx}
],
testUnevaluated[
HypergraphUnifications[1],
{HypergraphUnifications::argr}
],
testUnevaluated[
HypergraphUnifications[1, 2, 3],
{HypergraphUnifications::argrx}
],
testUnevaluated[
HypergraphUnifications[{1}, 2],
{HypergraphUnifications::hypergraphNotList}
],
testUnevaluated[
HypergraphUnifications[1, {2}],
{HypergraphUnifications::hypergraphNotList}
],
testUnevaluated[
HypergraphUnifications[{1}, {2}],
{HypergraphUnifications::edgeNotList}
],
testUnevaluated[
HypergraphUnifications[{{1}}, {2}],
{HypergraphUnifications::edgeNotList}
],
testUnevaluated[
HypergraphUnifications[{1}, {{2}}],
{HypergraphUnifications::edgeNotList}
],
VerificationTest[
HypergraphUnifications[{{1}}, {{2}}],
{{{{1}}, <|1 -> 1|>, <|1 -> 1|>}}
],
VerificationTest[
HypergraphUnifications[{{1, 2}}, {{1, 2}}],
{{{{1, 2}}, <|1 -> 1|>, <|1 -> 1|>}}
],
VerificationTest[
Sort @ HypergraphUnifications[{{1, 2}, {3, 4}}, {{1, 2}}][[All, 2]],
{<|1 -> 1, 2 -> 2|>, <|1 -> 2, 2 -> 1|>}
],
VerificationTest[
Length[HypergraphUnifications[{{1, 2}, {2, 3}, {3, 4}}, {{a, b}, {b, c}, {c, d}}]],
33
],
VerificationTest[
Length[HypergraphUnifications[{{1, 1}, {1, 1}, {1, 1}}, {{1, 1}, {1, 1}, {1, 1}}]],
33
],
VerificationTest[
Length[HypergraphUnifications[{{1, 2}, {2, 3}, {3, 4, 5}}, {{1, 2}, {2, 3}, {3, 4, 5}}]],
13
],
VerificationTest[
Length[HypergraphUnifications[{{1, 2}, {2, 3, 4}}, {{1, 2}, {2, 3, 4}}]],
3
],
VerificationTest[
Length[HypergraphUnifications[{{1, 2}, {2, 3}, {3, 4}}, {{a, b}, {b, c}, {c, d}}]],
33
],
Function[{e1, e2},
VerificationTest[
And @@ (correctOverlapQ[e1, e2, ##] & @@@ HypergraphUnifications[e1, e2])
]
] @@@ {
ConstantArray[{{1, 2}}, 2],
ConstantArray[{{1, 2}, {2, 3}}, 2],
ConstantArray[{{1, 2}, {2, 3}, {3, 4, 5}}, 2],
ConstantArray[{{1, 2}, {3, 4}, {5, 6, 7}}, 2],
ConstantArray[{{1, 2, 3}, {4, 5, 6}, {1, 4}}, 2],
{{{1, 2}, {2, 3}, {3, 4, 5}}, {{1, 2}, {3, 4}, {5, 6, 7}}},
{{{1, 2}, {2, 1}}, {{a, b}, {b, c}, {c, d, e}}},
{{{1, 2}}, {{a, b}, {b, c}, {c, d, e}}},
ConstantArray[{{1, 1}, {1, 1}, {1, 1}}, 2]
},
(* #220 *)
VerificationTest[
HypergraphUnifications[{}, {}],
{}
],
VerificationTest[
HypergraphUnifications[{{1}}, {}],
{}
],
VerificationTest[
HypergraphUnifications[{}, {{1}}],
{}
],
VerificationTest[
HypergraphUnifications[{{1, 2}}, {{1, 2, 3}}],
{}
]
}
|>
|>