I think you need something like the following to start this (I am assuming R is a binary relation):

Suppose that we number the elements of X, so X={x1, x2, ..., xn}

Lets suppose that the matrix A has 1 in position (i,j) if (xi,xj) is in R, and

0 otherwise.

R is a function iff for all (x,y) in R (x,z) => if (x,z) is in R then z=y, then we

may write r(x)=y.

Hence R is a function iff there is at most 1 "1" in each row of A.

So your algorithm has to check that each row of A contains no more than 1 "1"

and all other elements are 0.

RonL