I am currently trying to prove an exercise from Sheaves in Geometry and Logic: A First Introduction to Topos Theory by Mac Lane and Moerdijk about natural numbers objects.
First, we have the following definition:
Definition. A natural numbers object in a topos $\mathcal E$ is an object $N$ with arrows $$ 1\overset 0 \longrightarrow N \overset s \longrightarrow N $$ such that for any object $X$ of $\mathcal E$ with arrows $x$ and $f$, as below, there is a unique arrow $h$ which makes the following diagram commute: $$ \begin{array}{cclcl} 1 & \overset 0 \longrightarrow & N & \overset s \longrightarrow & N \\ || & & \downarrow h & & \downarrow h \\ 1 & \underset x \longrightarrow & X & \underset f \longrightarrow & X. \end{array} $$
Next, the exercise in question is as follows:
Exercise. Let $N$, with arrows $0:1\to N$ and $s:N\to N$, be a natural numbers object in a topos $\mathcal E$. Prove that the following form of recursion "in a parameter": for objects $X$ and $Y$ of $\mathcal E$ and maps $g:X\to Y$ and $h:Y\times X\to Y$, there is a unique $f:N\times X\to Y$ such that the following diagrams commute: $$ \begin{array}{ccccclcc} \phantom{\cong}1\times X & \overset{0\times\mathrm{id}}\longrightarrow & N\times X\phantom{f} & & \phantom{(f,\pi_2)}N\times X & \overset{s\times\mathrm{id}}\longrightarrow & N\times X \\ \cong\downarrow & & \downarrow f && (f,\pi_2)\downarrow && \downarrow f \\ \phantom{\cong}X & \underset g \longrightarrow & Y \phantom{f!} && \phantom{(f,\pi_2)}Y\times X & \underset h \longrightarrow & Y. \phantom{f} \end{array} $$ [In $\mathbf{Sets}$, this would mean that $f$ is the function defined by $f(0,x)=g(x)$, $f(n+1,x)=h(f(n,x),x)$.]
Now, the proof is very straightforward in $\mathbf{Sets}$, but I can't figure it out for a general topos. It seems like there should be some sort of exponential/adjunction argument, but I'm not getting it. I hope I'm not missing anything obvious!
I'm looking forward to peoples' responses. Thanks in advance!
Edit (2013-03-24): For completeness, I decided to include my proof of the exercise that works in $\mathbf{Sets}$.
Proof. Let $N$ be a natural numbers object in $\mathbf{Sets}$ (with the necessary functions $0:1\to N$ and $s:N\to N$), let $X$ and $Y$ be sets, and let $$ g: X \to Y \qquad\text{and}\qquad h : Y \times X \to Y $$ be functions. We wish to show that there exists a unique function $f:N\times X\to Y$ such that $$ f(0,x) = g(x) \qquad\text{and}\qquad f(n+1,x) = h(f(n,x),x) $$ for all $n\in N$ and $x\in X$.
Given $x\in X$, define $h_x:Y\to Y$ by $h_x(y)=h(y,x)$ (this implicitly uses the $$ \mathrm{Hom}_{\mathbf{Sets}}(Y\times X,Y) \cong \mathrm{Hom}_{\mathbf{Sets}}(X, Y^Y) $$ adjunction). Then for each $x\in X$ we have a diagram $$ 1 \overset{g(x)} \longrightarrow Y \overset{h_x} \longrightarrow Y $$ which induces a unique arrow $f_x:N\to Y$ such that the following diagram commutes: $$ \begin{array}{cclcl} 1 & \overset 0 \longrightarrow & N & \overset s \longrightarrow & N \\ || & & \downarrow f_x & & \downarrow f_x \\ 1 & \underset{g(x)} \longrightarrow & Y & \underset {h_x} \longrightarrow & Y. \end{array} $$ Then we define $f:N\times X\to Y$ by $f(n,x)=f_x(n)$, and it is easy to see that this $f$ satisfies the desired properties and is unique.
This is the proof that I am struggling to generalize. Maybe this is the wrong approach altogether for a general proof, although I feel like it should generalize. Any help would be greatly appreciated.