(* Afriat's Efficiency Index *) rdEMatrix[p_, x_, e_] := Module[{i, j, n}, n = Length[p]; Table[ If[(e p[[i]].x[[i]] >= p[[i]].x[[j]]) || i == j, 1, 0], {i, 1, n}, {j, 1, n}]] tClosure[m_] := Sign[MatrixPower[m, Length[m]]] GARPOK[p_, x_, m_, e_] := Module[{i, j, n}, n = Length[m]; Table[ If[m[[i, j]] == 1 && (e p[[j]].x[[j]] > p[[j]].x[[i]]), False, True], {j, 1, n}, {i, 1, n}]] ViolationList[p_, x_, e_] := Module[{m}, m = tClosure[rdEMatrix[p, x, e]]; Union[Flatten[Position[GARPOK[p, x, m, e], False]]]] NumberViolations[p_, x_, e_] := Length[ViolationList[p, x, e]] p = {{1., 2.}, {2., 1.}}; x = {{1., 2.}, {2., 1.}}; MatrixForm[GARPOK[p, x, tClosure[rdEMatrix[p, x, .81]], .81]] MatrixForm[GARPOK[p, x, tClosure[rdEMatrix[p, x, .79]], .79]] AfriatEfficiency[p_, x_, maxSteps_] := Module[{step, e}, e = 1/2; For[step = 1, step <= maxSteps, step++, If[NumberViolations[p, x, e] > 0, e = e - 2^(-(step + 1)), e = e + 2^(-(step + 1))]; Print[N[e]]]]