Philip Wadler
2018-05-04 17:44:55 UTC
I have an Agda formalisation of reduction on raw terms (inspired by a
formalisation of McBride acting on a deBruijn representation). The
formalisation is here:
https://wenkokke.github.io/sf/TypedFresh
Although more elaborate than I would like in parts, at least I succeed in
proving progress and preservation for the system. Combining the two allows
me to write a function that computes the reduction sequence for a term
bounding by a given length. If the reduction sequence is longer than the
specified length n, it returns the sequence of length n with the indicator
"out of gas". I then tried to compute the reduction sequence for two plus
two.
Computing the first four reduction steps takes a couple of minutes rather
than a couple of seconds. Attempting to normalise the term fully (which
should take fourteen reduction steps) does not complete even if run
overnight!
{-
_ : normalise 4 â¢four â¡
out-of-gas
((`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (Ο-·â (β-Y Fun refl)) â©
(`λ 0 â
(`λ 1 â
`if0 ` 0 then ` 1 else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred ` 0)
· ` 1))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (β-â (Suc (Suc Zero))) â©
(`λ 0 â
`if0 `suc (`suc `zero) then ` 0 else
(`Y
(`λ 1 â
(`λ 2 â (`λ 3 â `if0 ` 2 then ` 3 else ` 1 · (`pred ` 2) · ` 3))))
· (`pred (`suc (`suc `zero)))
· ` 0)
· (`suc (`suc `zero))
â¶âš β-â (Suc (Suc Zero)) â©
`if0 `suc (`suc `zero) then `suc (`suc `zero) else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred (`suc (`suc `zero)))
· (`suc (`suc `zero))
â¶âš β-if0-suc (Suc Zero) â©
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred (`suc (`suc `zero)))
· (`suc (`suc `zero))
â)
_ = refl
-}
To try to uncover the problem, I attempted a single step at a time. The
first reduction step is fine.
{-
_ : normalise 1 â¢four â¡
out-of-gas
((`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (Ο-·â (β-Y Fun refl)) â©
(`λ 0 â
(`λ 1 â
`if0 ` 0 then ` 1 else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred ` 0)
· ` 1))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â)
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z)
(â¢Y
(â¢Î»
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S mâ¢n Z)) (Ax Z)
(Ax (S pâ¢n (S pâ¢m Z)) · â¢pred (Ax (S mâ¢n Z)) · Ax Z)))))
· â¢pred (Ax (S (fresh-lemma CollectionDec.here) Z))
· Ax Z)))
· â¢suc (â¢suc â¢zero)
· â¢suc (â¢suc â¢zero))
_ = refl
-}
The second reduction step yields a huge term. It contains the free variable
_x_1862 where I would have expected a fresh variable name to be computed.
Looking at the four-step reduction above we see the name computed properly,
but when going from the first step to the second it is not. The huge size
of the type derivation suggests why it did not terminate after one day.
Help! Why doesnât the term reduce? Is there some way to force it to reduce?
Cheers, -- P
{-
_ : normalise 1
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z)
(â¢Y
(â¢Î»
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S mâ¢n Z)) (Ax Z)
(Ax (S pâ¢n (S pâ¢m Z)) · â¢pred (Ax (S mâ¢n Z)) · Ax Z)))))
· â¢pred (Ax (S (fresh-lemma CollectionDec.here) Z))
· Ax Z)))
· â¢suc (â¢suc â¢zero)
· â¢suc (â¢suc â¢zero))
â¡
out-of-gas
((`λ _x_1862 â
(`λ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
`if0 ` _x_1862 then
` (suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)) else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred ` _x_1862)
· ` (suc _x_1862 â foldr _â_ 0 (map suc _xs_2005))))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (β-â (Suc (Suc Zero))) â©
(`λ
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))
â
`if0
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
_x_1862
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
then
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
(suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
| suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
else
(`Y
(`λ
suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))
â
(`λ
suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(`λ
suc
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
`if0
`
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
then
`
(suc
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc
_xs_1887))))))))
else
`
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
·
(`pred
`
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc
_xs_1887))))))))
·
`
(suc
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬?
(_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc
_xs_1887))))))))))))
·
(`pred
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
_x_1862
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
·
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
(suc _x_1862 â foldr _â_ 0 (map suc _xs_2005))
| suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
· (`suc (`suc `zero))
â)
(â¢Î»
(â¢if0
(.Typed.â¢Ïâ²
(λ {w} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| w â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016)
(CollectionDec.\\-to-â· â _â_ (λ {_} xâ â xâ) CollectionDec.here
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(S (fresh-lemma CollectionDec.here) Z)
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(.Typed.â¢Ïâ²
(λ {w} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| w â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016)
(CollectionDec.\\-to-â· â _â_ (λ {_} xâ â xâ)
(CollectionDec.there CollectionDec.here)
| suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
Z
| suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(â¢subst
(λ {w} wââ² {zâ} â
.Typed.Σâ²
(λ {wâ} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| wâ â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016) wââ²
| w â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(.Typed.â¢Ïâ²
(λ {w} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| w â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(λ {zâ} x â
CollectionDec.\\-to-â· â _â_ (λ {_} xâ â xâ)
(CollectionDec.there (CollectionDec.there x))
| zâ â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
_2016))
· â¢suc (â¢suc â¢zero))
-}
. \ Philip Wadler, Professor of Theoretical Computer Science,
. /\ School of Informatics, University of Edinburgh
. / \ and Senior Research Fellow, IOHK
. http://homepages.inf.ed.ac.uk/wadler/
formalisation of McBride acting on a deBruijn representation). The
formalisation is here:
https://wenkokke.github.io/sf/TypedFresh
Although more elaborate than I would like in parts, at least I succeed in
proving progress and preservation for the system. Combining the two allows
me to write a function that computes the reduction sequence for a term
bounding by a given length. If the reduction sequence is longer than the
specified length n, it returns the sequence of length n with the indicator
"out of gas". I then tried to compute the reduction sequence for two plus
two.
Computing the first four reduction steps takes a couple of minutes rather
than a couple of seconds. Attempting to normalise the term fully (which
should take fourteen reduction steps) does not complete even if run
overnight!
{-
_ : normalise 4 â¢four â¡
out-of-gas
((`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (Ο-·â (β-Y Fun refl)) â©
(`λ 0 â
(`λ 1 â
`if0 ` 0 then ` 1 else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred ` 0)
· ` 1))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (β-â (Suc (Suc Zero))) â©
(`λ 0 â
`if0 `suc (`suc `zero) then ` 0 else
(`Y
(`λ 1 â
(`λ 2 â (`λ 3 â `if0 ` 2 then ` 3 else ` 1 · (`pred ` 2) · ` 3))))
· (`pred (`suc (`suc `zero)))
· ` 0)
· (`suc (`suc `zero))
â¶âš β-â (Suc (Suc Zero)) â©
`if0 `suc (`suc `zero) then `suc (`suc `zero) else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred (`suc (`suc `zero)))
· (`suc (`suc `zero))
â¶âš β-if0-suc (Suc Zero) â©
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred (`suc (`suc `zero)))
· (`suc (`suc `zero))
â)
_ = refl
-}
To try to uncover the problem, I attempted a single step at a time. The
first reduction step is fine.
{-
_ : normalise 1 â¢four â¡
out-of-gas
((`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (Ο-·â (β-Y Fun refl)) â©
(`λ 0 â
(`λ 1 â
`if0 ` 0 then ` 1 else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred ` 0)
· ` 1))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â)
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z)
(â¢Y
(â¢Î»
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S mâ¢n Z)) (Ax Z)
(Ax (S pâ¢n (S pâ¢m Z)) · â¢pred (Ax (S mâ¢n Z)) · Ax Z)))))
· â¢pred (Ax (S (fresh-lemma CollectionDec.here) Z))
· Ax Z)))
· â¢suc (â¢suc â¢zero)
· â¢suc (â¢suc â¢zero))
_ = refl
-}
The second reduction step yields a huge term. It contains the free variable
_x_1862 where I would have expected a fresh variable name to be computed.
Looking at the four-step reduction above we see the name computed properly,
but when going from the first step to the second it is not. The huge size
of the type derivation suggests why it did not terminate after one day.
Help! Why doesnât the term reduce? Is there some way to force it to reduce?
Cheers, -- P
{-
_ : normalise 1
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z)
(â¢Y
(â¢Î»
(â¢Î»
(â¢Î»
(â¢if0 (Ax (S mâ¢n Z)) (Ax Z)
(Ax (S pâ¢n (S pâ¢m Z)) · â¢pred (Ax (S mâ¢n Z)) · Ax Z)))))
· â¢pred (Ax (S (fresh-lemma CollectionDec.here) Z))
· Ax Z)))
· â¢suc (â¢suc â¢zero)
· â¢suc (â¢suc â¢zero))
â¡
out-of-gas
((`λ _x_1862 â
(`λ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
`if0 ` _x_1862 then
` (suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)) else
(`Y
(`λ 0 â
(`λ 1 â (`λ 2 â `if0 ` 1 then ` 2 else ` 0 · (`pred ` 1) · ` 2))))
· (`pred ` _x_1862)
· ` (suc _x_1862 â foldr _â_ 0 (map suc _xs_2005))))
· (`suc (`suc `zero))
· (`suc (`suc `zero))
â¶âš Ο-·â (β-â (Suc (Suc Zero))) â©
(`λ
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))
â
`if0
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
_x_1862
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
then
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
(suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
| suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
else
(`Y
(`λ
suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))
â
(`λ
suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(`λ
suc
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
`if0
`
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
then
`
(suc
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc
_xs_1887))))))))
else
`
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
·
(`pred
`
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc
_xs_1887))))))))
·
`
(suc
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))))))
â
(suc
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
(suc
(foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
â
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬?
(_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc
_xs_1887))))))))))))
·
(`pred
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
_x_1862
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
·
(((λ w â
((λ x â ` x) , _x_1862 ⊠`suc (`suc `zero)) w | w â _x_1862)
, suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) âŠ
`
foldr _â_ 0
(map suc
(filter (λ x â ¬? (x â _x_1862))
(filter
(λ x â ¬? (x â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
(_x_1862 â·
[ suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) , _x_1862 ,
suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) ])
| ¬? (_x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))))))
(suc _x_1862 â foldr _â_ 0 (map suc _xs_2005))
| suc _x_1862 â foldr _â_ 0 (map suc _xs_2005) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887)))
· (`suc (`suc `zero))
â)
(â¢Î»
(â¢if0
(.Typed.â¢Ïâ²
(λ {w} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| w â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016)
(CollectionDec.\\-to-â· â _â_ (λ {_} xâ â xâ) CollectionDec.here
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(S (fresh-lemma CollectionDec.here) Z)
| _x_1862 â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(.Typed.â¢Ïâ²
(λ {w} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| w â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016)
(CollectionDec.\\-to-â· â _â_ (λ {_} xâ â xâ)
(CollectionDec.there CollectionDec.here)
| suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
Z
| suc _x_1862 â foldr _â_ 0 (map suc _xs_1887) â
suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(â¢subst
(λ {w} wââ² {zâ} â
.Typed.Σâ²
(λ {wâ} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| wâ â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016) wââ²
| w â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
(.Typed.â¢Ïâ²
(λ {w} wâ {zâ} yâ â
.Typed.Σ
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)) wâ yâ
| w â _x_1862)
(.Typed.â¢Ï
(â¢Î»
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(â¢suc (â¢suc â¢zero)))
(λ {_} xâ â xâ)
(â¢if0 (Ax (S (fresh-lemma CollectionDec.here) Z)) (Ax Z) _2016))
(λ {zâ} x â
CollectionDec.\\-to-â· â _â_ (λ {_} xâ â xâ)
(CollectionDec.there (CollectionDec.there x))
| zâ â suc _x_1862 â foldr _â_ 0 (map suc _xs_1887))
_2016))
· â¢suc (â¢suc â¢zero))
-}
. \ Philip Wadler, Professor of Theoretical Computer Science,
. /\ School of Informatics, University of Edinburgh
. / \ and Senior Research Fellow, IOHK
. http://homepages.inf.ed.ac.uk/wadler/