implementation of gradient upper condition