“…: string->int (txt) = match (''abaa",0,4) (txt,0,length(txt)) match (''abaa",0,4) : string*int*int->int (txt,k,lt) = if k=lt then -1 else compare (''abaa",0,4) (txt,k,lt) compare (''abaa",0,4) : string*int*int->int (txt,k,lt) = if 'a'=ref(txt,k) then match (''abaa",1,4) (txt,k+1,lt) else match (''abaa",0,4) (txt,k+1,lt) match (''abaa", 1,4) : string*int*int->int (txt,k,lt) = if k=lt then -1 else compare (''abaa",1,4) (txt,k,lt) compare (''abaa",1,4) : string*int*int->int (txt,k,lt) = if 'b'=ref(txt,k) then match (''abaa",2,4) (txt,k+1,lt) else compare (''abaa",0,4) (txt,k,lt) match (''abaa",2,4) : string*int*int->int (txt,k,lt) = if k=lt then -1 else compare (''abaa",2,4) (txt,k,lt) compare (''abaa",2,4) : string*int*int->int (txt,k,lt) = if 'a'=ref(txt,k) then match (''abaa",3,4) (txt,k+1,lt) else match (''abaa",0,4) (txt,k+1,lt) match (''abaa", 3,4) : string*int*int->int (txt,k,lt) = if k=lt then -1 else compare (''abaa",3,4) (txt,k,lt) compare (''abaa", 3,4) : string*int*int->int (txt,k,lt) = if 'a'=ref(txt,k) then match (''abaa",4,4) (txt,k+1,lt) else compare (''abaa",1,4) (txt,k,lt) match (''abaa",4,4) : string*int*int->int (txt,k,lt) = k-4 in main (''abaa") We will now show that for all patterns, our polyvariant specializer transforms the inefficient string matcher, STAGED, into a program with the above structure. The proof consists of two parts: termination of the specializer and properties of the residual programs.…”