Well, suppose that I have a set of functional definitions (with a syntax tree) in church encoding :
true : λx -> λy -> x
false : λx -> λy -> y
Giving the definition λx -> λy -> y, it is very clear how to return the named definition, applying a matching with alpha-equivalence will be enough.
α true λx -> λy -> y = false
α false λx -> λy -> y = true
But consider the example below:
0 : λf λz -> x
succ : λn λf λx -> f (n f x)
3 : succ (succ (succ 0)))
So, when 3 suffers from beta-reduction it will unfold to some definition like :
3_unfolded : (λf -> (λx -> (f (f (f x))))) : (A -> A) -> A -> A
You can see the term can get bigger easily, of course, it is not a good way to represent pure data, because of the size of the term. So, I want to know if there is an algorithm able efficiently to rename again every definition after suffering evaluation. Them 3_unfolded will become (succ (succ (succ 0))) again by giving the set of definitions of natural church encoding (0, and succ only).
I know there are some side effects, like ambiguous representations, but let's ignore that (if you expand the same definition of succ and rename to succ_2, for example).