Refocusing (semantics)

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

  1. locating the smallest potentially reducible term (potential redex) using a given reduction strategy, if this potential redex exists in (otherwise is irreducible); and
  2. contracting this potential redex using given contraction rules if it is an actual one (otherwise is stuck).

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

  1. is first decomposed into the context and a potential redex ,
  2. is contracted into the contractum ,
  3. is then recomposed around and then decomposed into the context and a potential redex ,
  4. etc.

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.

  1. ^ Danvy, Olivier; Nielsen, Lasse R. (2001). Syntactic theories in practice. Second International Workshop on Rule-Based Programming (RULE 2001). Vol. 59. Electronic Notes in Theoretical Computer Science. doi:10.7146/brics.v9i4.21721.
  2. ^ Danvy, Olivier; Nielsen, Lasse R. (2004). Refocusing in reduction semantics (Technical report). BRICS. doi:10.7146/brics.v11i26.21851. RS-04-26.