In computer science, refocusing is a program transformation used to implement a reduction semantics—i.e., a small-step operational semantics with an explicit representation of the reduction context—more efficiently. It is a step towards implementing a deterministic semantics as a deterministic abstract machine.
A small-step operational semantics defines the meaning of a given program as a sequence of one-step reductions that starts with and continues with a sequence of reducts , where :
A one-step reduction from to is achieved by
A reduction semantics is a small-step operational semantics with an explicit representation of the context of each potential redex.
Writing for such context, the sequence of one-step reductions above reads:
where
This succession of decompositions, contractions, and recomposition is depicted as follows:
contract contract contract o--------->o o--------->o o--------->o / \ / \ / \ / recompose \ / recompose \ / recompose \ / \ / \ / \ / decompose \ / decompose \ / decompose \ / \ / \ / \ o--------------------->o--------------------->o--------------------->o reduce reduce reduce
Refocusing is a deforestation of the successive reducts:[1][2]
contract refocus contract refocus contract o--------->o---------->o--------->o---------->o--------->o------ / \ / \ / \ / recompose \ / recompose \ / recompose \ / \ / \ / \ / decompose \ / decompose \ / decompose \ / \ / \ / \ o o o o
After the initial decomposition, the succession of contractions and refocusings has the structure of a deterministic abstract machine.