Discrete Melnikov functions