 TUPLE: insert item ;
 
 <PRIVATE
+
 TUPLE: trace-state old new table i j ;
 
 : old-nth ( state -- elt )
-    [ i>> 1 - ] [ old>> ] bi nth ;
+    [ i>> 1 - ] [ old>> ] bi nth-unsafe ;
 
 : new-nth ( state -- elt )
-    [ j>> 1 - ] [ new>> ] bi nth ;
+    [ j>> 1 - ] [ new>> ] bi nth-unsafe ;
 
 : top-beats-side? ( state -- ? )
-    [ [ i>> ] [ j>> 1 - ] [ table>> ] tri nth nth ]
-    [ [ i>> 1 - ] [ j>> ] [ table>> ] tri nth nth ] bi > ;
+    [ [ i>> ] [ j>> 1 - ] [ table>> ] tri nth-unsafe nth-unsafe ]
+    [ [ i>> 1 - ] [ j>> ] [ table>> ] tri nth-unsafe nth-unsafe ] bi > ;
 
 : retained? ( state -- ? )
     {


: trace-diff ( old new table -- diff )
    [ ] [ first length 1 - ] [ length 1 - ] tri trace-state boa
    [ (trace-diff) ] { } make reverse ;
PRIVATE>

: diff ( old new -- diff )

:: run-lcs ( old new init step -- matrix )
    old length 1 + new length 1 + init call :> matrix
    old length iota [| i |
        new length iota [| j |
            i j matrix old new step loop-step
        ] each
    ] each matrix ; inline

PRIVATE>

: levenshtein ( old new -- n )
