Motivated by @gallais's solution, I think there is a more natural solution:
We can prove contraposition first, which is (A → B) → (¬ B → ¬ A)
. Then we prove x ≡ y → f x ≥ f y
, which is the contrapositive of original proposition. Finally, we apply contraposition to the contrapositive. Here is my code
open import Data.Nat using (ℕ; zero; suc; _<_; _≥_)
open import Data.Nat.Properties using (≤-reflexive; <⇒≱)
open import Relation.Nullary using (¬_)
contraposition : ∀ {A B : Set} → (A → B) → (¬ B → ¬ A)
contraposition f ¬b a = ¬b (f a)
=≥ : {x y : ℕ} → x ≡ y → f x ≥ f y
=≥ x=y = ≤-reflexive (cong f (sym x=y))
anti-cong : {x y : ℕ} → f x < f y → x ≢ y
anti-cong {x} {y} fx<fy = contraposition (=≥ {x} {y}) (<⇒≱ fx<fy)