@@ -38,6 +38,7 @@ def assertEquivalent(bs: List[Constructor], as: List[Constructor]): Unit / { For
3838 case (Superposer(Pos(i1), out1, label1), Superposer(Pos(i2), out2, label2)) =>
3939 assertEqual(out1.size, out2.size)
4040 assertEqual(label1, label2)
41+ case (Initiator(Neg(k1)), Initiator(Neg(k2))) => ()
4142 case (_, _) => assertEqual(as, bs) // will fail, but we'll see why
4243 }
4344 assertEqual(as.size, bs.size)
@@ -60,7 +61,8 @@ def tests() = suite("└ ruler tests") {
6061 val (normalized, steps) = normalize(program, redexes, 10)
6162 assertEqual(steps, 1)
6263 assertEquivalent(list::collect[Constructor] { normalized() }, [
63- Abstractor(Pos("xSym3"), Neg("xSym3"), Pos("xSym1"))
64+ Abstractor(Pos("xSym3"), Neg("xSym3"), Pos("xSym1")),
65+ Initiator(Neg("xSym1"))
6466 ])
6567 }
6668
@@ -75,7 +77,8 @@ def tests() = suite("└ ruler tests") {
7577 val (normalized, steps) = normalize(program, redexes, 10)
7678 assertEqual(steps, 4)
7779 assertEquivalent(list::collect[Constructor] { normalized() }, [
78- Abstractor(Pos("xSym6_1_1"), Neg("xSym6_1_1"), Pos("xSym6_0_0"))
80+ Abstractor(Pos("xSym6_1_1"), Neg("xSym6_1_1"), Pos("xSym6_0_0")),
81+ Initiator(Neg("xSym6_0_0"))
7982 ])
8083 }
8184
@@ -90,7 +93,8 @@ def tests() = suite("└ ruler tests") {
9093 val (normalized, steps) = normalize(program, redexes, 10)
9194 assertEqual(steps, 5)
9295 assertEquivalent(list::collect[Constructor] { normalized() }, [
93- Abstractor(Pos("xSym9_1_1"), Neg("xSym9_1_1"), Pos("xSym9_0_0"))
96+ Abstractor(Pos("xSym9_1_1"), Neg("xSym9_1_1"), Pos("xSym9_0_0")),
97+ Initiator(Neg("xSym9_0_0"))
9498 ])
9599 }
96100
@@ -105,7 +109,8 @@ def tests() = suite("└ ruler tests") {
105109 val (normalized, steps) = normalize(program, redexes, 20)
106110 assertEqual(steps, 11)
107111 assertEquivalent(list::collect[Constructor] { normalized() }, [
108- Abstractor(Pos("xSym20_8_8"), Neg("xSym20_8_8"), Pos("xSym20_7_7"))
112+ Abstractor(Pos("xSym20_8_8"), Neg("xSym20_8_8"), Pos("xSym20_7_7")),
113+ Initiator(Neg("xSym20_7_7"))
109114 ])
110115 }
111116
@@ -120,7 +125,8 @@ def tests() = suite("└ ruler tests") {
120125 val (normalized, steps) = normalize(program, redexes, 20)
121126 assertEqual(steps, 9)
122127 assertEquivalent(list::collect[Constructor] { normalized() }, [
123- Abstractor(Pos("xSym9_1_1"), Neg("xSym9_1_1"), Pos("kAbs6"))
128+ Abstractor(Pos("xSym9_1_1"), Neg("xSym9_1_1"), Pos("kAbs6")),
129+ Initiator(Neg("kAbs6"))
124130 ])
125131 }
126132
@@ -137,7 +143,8 @@ def tests() = suite("└ ruler tests") {
137143 assertEquivalent(list::collect[Constructor] { normalized() }, [ // x => y => (x y)
138144 Applicator(Neg("xSym17_5_5"), Neg("ySym18_17_5"), Pos("kApp19_19_1")), // (x y)
139145 Abstractor(Pos("ySym18_17_5"), Neg("kApp19_19_1"), Pos("kAbs20_6_0")), // y =>
140- Abstractor(Pos("xSym17_5_5"), Neg("kAbs20_6_0"), Pos("kAbs14")) // x =>
146+ Abstractor(Pos("xSym17_5_5"), Neg("kAbs20_6_0"), Pos("kAbs14")), // x =>
147+ Initiator(Neg("kAbs14"))
141148 ])
142149 }
143150
@@ -156,7 +163,8 @@ def tests() = suite("└ ruler tests") {
156163 Duplicator(Neg("yEra11_5_1"), Nil(), 1),
157164 Abstractor(Pos("yEra11_4_0"), Neg("xSym9_0_0"), Pos("kAbs10_2_0")), // y11_4 =>
158165 Abstractor(Pos("yEra11_5_1"), Neg("xSym9_1_1"), Pos("xSym9_0_0")), // y11_5 =>
159- Abstractor(Pos("xSym9_1_1"), Neg("kAbs10_2_0"), Pos("kAbs6")) // x9 =>
166+ Abstractor(Pos("xSym9_1_1"), Neg("kAbs10_2_0"), Pos("kAbs6")), // x9 =>
167+ Initiator(Neg("kAbs6"))
160168 ])
161169 }
162170
@@ -171,7 +179,8 @@ def tests() = suite("└ ruler tests") {
171179 val (normalized, steps) = normalize(program, redexes, 20)
172180 assertEqual(steps, 11)
173181 assertEquivalent(list::collect[Constructor] { normalized() }, [
174- Abstractor(Pos("ySym1"), Neg("ySym1"), Pos("kAbs2"))
182+ Abstractor(Pos("ySym1"), Neg("ySym1"), Pos("kAbs2")),
183+ Initiator(Neg("kAbs2"))
175184 ])
176185 }
177186
@@ -188,7 +197,8 @@ def tests() = suite("└ ruler tests") {
188197 assertEquivalent(list::collect[Constructor] { normalized() }, [
189198 Duplicator(Neg("zSym5"), Nil(), 1),
190199 Duplicator(Neg("zDup9"), [Pos("zSym2"), Pos("zSym5")], 0),
191- Abstractor(Pos("zDup9"), Neg("zSym2"), Pos("kAbs8"))
200+ Abstractor(Pos("zDup9"), Neg("zSym2"), Pos("kAbs8")),
201+ Initiator(Neg("kAbs8"))
192202 ])
193203 }
194204
@@ -207,7 +217,26 @@ def tests() = suite("└ ruler tests") {
207217 assertEquivalent(list::collect[Constructor] { normalized() }, [
208218 Duplicator(Neg("zDup29"), [Pos("zSym22"), Pos("zSym25")], 2),
209219 Abstractor(Pos("zDup29"), Neg("zSym22"), Pos("kAbs28")),
210- Duplicator(Neg("zSym25"), [], 2)
220+ Duplicator(Neg("zSym25"), [], 2),
221+ Initiator(Neg("kAbs28"))
222+ ])
223+ }
224+
225+ test("normalization: iota iota iota iota") {
226+ with confluence
227+ val program: Program = collect {
228+ with assertNoThrow[WrongFormat]
229+ with source[Char] { s"(${iota} (${iota} (${iota} ${iota})))".each }
230+ compile!()
231+ }
232+ val redexes = box { program.redexes() }
233+ val (normalized, steps) = normalize(program, redexes, 70)
234+ assertEqual(steps, 63)
235+ assertEquivalent(list::collect[Constructor] { normalized() }, [
236+ Duplicator(Neg("38"), Nil(), 1),
237+ Abstractor(Pos("38"), Neg("34"), Pos("36")), // y => x
238+ Abstractor(Pos("34"), Neg("36"), Pos("32_0")), // x =>
239+ Initiator(Neg("32_0"))
211240 ])
212241 }
213242}
0 commit comments