Implementing Gray system function.