The following term (using bruijn-indexes):
BADTERM = λ((0 λλλλ((((3 λλ(((0 3) 4) (1 λλ0))) λλ(((0 4) 3) (1 0))) λ1) λλ1)) λλλ(2 (2 (2 (2 (2 (2 (2 (2 0)))))))))
When applied to a church number N
evaluates to normal form quickly in several existing evaluators, including naive ones. Yet, if you encode that term to interaction nets and evaluate it using Lamping's Abstract Algorithm, it takes an exponential numbers of beta-reductions in relation to N
. On Optlam, specifically:
N interactions(betas) (BADTERM N)
1 129(72) λλλ(1 (2 (2 (2 (2 (2 (2 (2 0))))))))
2 437(205) λλλ(2 (1 (2 (2 (2 (2 (2 (2 0))))))))
3 976(510) λλλ(1 (1 (2 (2 (2 (2 (2 (2 0))))))))
4 1836(1080) λλλ(2 (2 (1 (2 (2 (2 (2 (2 0))))))))
5 3448(2241) λλλ(1 (2 (1 (2 (2 (2 (2 (2 0))))))))
6 6355(4537) λλλ(2 (1 (1 (2 (2 (2 (2 (2 0))))))))
7 11888(9181) λλλ(1 (1 (1 (2 (2 (2 (2 (2 0))))))))
8 22590(18388) λλλ(2 (2 (2 (1 (2 (2 (2 (2 0))))))))
9 43833(36830) λλλ(1 (2 (2 (1 (2 (2 (2 (2 0))))))))
10 85799(73666) λλλ(2 (1 (2 (1 (2 (2 (2 (2 0))))))))
11 169287(147420) λλλ(1 (1 (2 (1 (2 (2 (2 (2 0))))))))
12 335692(294885) λλλ(2 (2 (1 (1 (2 (2 (2 (2 0))))))))
13 668091(589821) λλλ(1 (2 (1 (1 (2 (2 (2 (2 0))))))))
14 1332241(1179619) λλλ(2 (1 (1 (1 (2 (2 (2 (2 0))))))))
15 2659977(2359329) λλλ(1 (1 (1 (1 (2 (2 (2 (2 0))))))))
On similar evaluators such as BOHM, it takes much less beta steps, but more interactions. If optimal evaluators are optimal, how can they evaluate terms asymptotically slower than existing evaluators?
This link has an explanation about the origin of the term, as well as an implementation of the same function that behaves the opposite, almost bizarrely so: it should run in exponential time - it does run in exponential time in most evaluators - yet, optimal evaluators normalize it in linear time!