'``scan`` performs a scanning process on the input ``word``.
It first locates the largest prefix ``s`` of ``word`` for which
`\alpha^s` is defined (i.e is not ``None``), ``s`` may be empty. Let
``word=sv``, let ``t`` be the longest suffix of ``v`` for which
`\alpha^{t^{-1}}` is defined, and let ``v=ut``. Then three
possibilities are there:
1. If ``t=v``, then we say that the scan completes, and if, in addition
`\alpha^s = \alpha^{t^{-1}}`, then we say that the scan completes
correctly.
2. It can also happen that scan does not complete, but `|u|=1`; that
is, the word ``u`` consists of a single generator `x \in A`. In that
case, if `\alpha^s = \beta` and `\alpha^{t^{-1}} = \gamma`, then we can
set `\beta^x = \gamma` and `\gamma^{x^{-1}} = \beta`. These assignments
are known as deductions and enable the scan to complete correctly.
3. See ``coicidence`` routine for explanation of third condition.
Notes
The code for the procedure of scanning `\alpha \in \Omega`
under `w \in A*` is defined on pg. 155 [1]
See Also
scan_c, scan_check, scan_and_fill, scan_and_fill_c'

def scan(self, alpha, word):

    A_dict = self.A_dict
    A_dict_inv = self.A_dict_inv
    table = self.table
    f = alpha
    i = 0
    r = len(word)
    b = alpha
    j = (r - 1)
    while ((i <= j) and (table[f][A_dict[word[i]]] is not None)):
        f = table[f][A_dict[word[i]]]
        i += 1
    if (i > j):
        if (f != b):
            self.coincidence(f, b)
        return
    while ((j >= i) and (table[b][A_dict_inv[word[j]]] is not None)):
        b = table[b][A_dict_inv[word[j]]]
        j -= 1
    if (j < i):
        self.coincidence(f, b)
    elif (j == i):
        table[f][A_dict[word[i]]] = b
        table[b][A_dict_inv[word[i]]] = f
