We present an efficient algorithm for computing a function that minimizes the
number of critical points among all functions within a prescribed distance d
from a given input function. The result is achieved by establishing a
connection between discrete Morse theory and persistent homology. Our method
completely removes homological noise with persistence less than 2d,
constructively proving that the lower bound on the number of critical points
given by the stability theorem of persistent homology is tight in dimension two
for any input function.