TITLE: Prove that if $A ≠ \emptyset$ and $f: A \rightarrow A$ and for all $g: A \rightarrow A$, $f \circ g = f$, then $f$ is a constant function.
QUESTION [0 upvotes]: Proposition:

Suppose $A ≠ \emptyset$ and $f: A \rightarrow A$. Suppose that for all $g: A \rightarrow A$, $f \circ g = f$. Prove that
  $f$ is a constant function.

My attempt:
Definitions:

If $f$ is a constant function, then exists some $a \in A$ such that 

$$\forall x \in A (f(x) = a)$$

Composition of functions 
$$f \circ g = \{(a,b) \in A \times A \mid \exists c \in A \bigl((a,c) \in g \land (c,b) \in f\bigr)\}$$

By contrapositive.
Suppose $f$ is not a constant function. 
Suppose $g$ is a constant function.
Then exists some $a \in A$, such that for arbitrary $x \in A$, $(x,a) \in g$.
Since $a \in A$, exists some $y \in A$ such that $(a,y) \in f$.
Since $f$ is not a constant function, there exist some $k_1,k_2 \in A$ such that $(k_1,k_2) \in f$ and $y ≠ k_2$.
Since $k_1 \in A$, we know that $(k_1,a) \in g$ and therefore $(k_1,y) \in f \circ g $. 
$f \circ g$ is a function, thus we can conclude that $(k_1,k_2) \notin f \circ g$
Hence $f ≠ f \circ g$. $\Box$
Is it correct?

My initial plan was to prove it directly, but after struggling for hours, I failed to find any way to do it. Can someone show me how to prove the proposition directly?

REPLY [0 votes]: You only need to prove that for any $x,y \in A$, $f(x) = f(y)$ holds. Let $x,y \in A$. Choose $g$ such that $g(x) = g(y)$, e.g. $g(z) = g(x)$ for all $z \in A$. Then $f(x) = f(g(x)) = f(g(y)) = f(y)$.
{"set_name": "stack_exchange", "score": 0, "question_id": 3421355}