Let us consider again the summation of the elements of a matrix.
The corresponding system is:
x[i,j] =
case
i,j | i=1, j=1 : a[i,j] ;
i,j | 2<=i<=n, j=1 : x[i-1,n] + a[i,j] ;
i,j | 1<=i<=n, 2<=j<=n : x[i,j-1] + a[i,j] ;
esac ;
Pattern matching is applied for the detection of scans at pseudo-depth
1. A closed form is introduced for the clause x.2:
x[i,j] =
case
i,j | i=1, j=1 : a[i,j] ;
i,j | 2<=i<=n, j=1 : x[i-1,n] + a[i,j] ;
i,j | 1<=i<=n, 2<=j<=n :
Scan( i',j' | 1<=i'<=n, 1<=j'<=n,
([0 1]), +, a[i',j'], x[i',j'] );
esac ;
Removing inter-components references leads to the inclusion of the clauses
x.0 and x.1 into the initial value of the Scan operator.
x[i,j] =
case
i,j | 1<=i<=n, 2<=j<=n :
Scan( i',j' | 1<=i'<=n, 1<=j'<=n,
([0 1]), +, a[i',j'],
case
k,l | k=1, l=1 :
a[1,1] ;
k,l | 2<=k<=n, l=1 :
x[k-1,n] + a[k,l] ;
esac ; )
esac ;
Since this system is already normalized for pseudo-depth 0, a
pattern-matching can be applied. No new uni-directional scan can be
detected. But we can try to add a direction to the previously detected
scan. Two necessary conditions for scan enhancement are fulfilled: the
scan is the clause expression, and the second clause of the
initial value is referencing x.0 at pseudo-depth 0 using the
scan binary operation (here an addition).
Now, a new direction e0 must be extracted. The direction must verify
that for k in {2,...,n} the point
(k , 1)
has for predecessor in scan order defined by e0 and
e1 the point
(k-1 , n)
.
A solution is the integer vector
(1 , 0)
.
The scan enhancement is successful, we obtain a two-directional
scan:
x[i,j] =
case
i,j | 1<=i<=n, 2<=j<=n :
Scan( i',j' | 1<=i'<=n, 1<=j'<=n,
([1 0] [0 1]), +,
a[i',j'], a[1,1] ) ;
esac ;