expressability of finite and infinite ramsey theorems in Peano arithmetic Finite Ramsey theorem:
$
\def\nn{\mathbb{N}}
$

For any $e,k,r \in \nn$, there exists a least natural number $m=R(e,r,k)$ so that, for any set $M$ with cardinality at least $m$, with each of the $e$-sets of $M$ coloured with one of $r$ colours, there exists a subset $H$ of $M$ with cardinality $k$ so that all $e$-sets of $H$ are coloured with the same colour. (Here an $e$-set of $M$ is a subset of $M$ of size $e$.)

Infinite Ramsey theorem:

For any $e,r \in \nn$, and any infinite set $M$, with each of the $e$-sets of $M$ coloured with one of $r$ colours, there exists an infinite subset $H$ of $M$ so that all $e$-sets of $H$ are coloured with the same colour.

I read that the finite Ramsey theorem can be expressed in PA. I don't understand why, because the universal and existence quantifier are used over sets, not just over variables (not appropriate for a first-order theory). I have read somewhere that $R$ as above is a recursive function and those functions are representable in PA with a formula -- maybe that has something to do with it (but my professor thinks otherwise).
I am very sorry for not being precise, because I read about this a long time ago and I don't remember the source, but I have also read (if I remember correctly) that the infinite Ramsey theorem cannot even be expressed in PA (not just that it cannot be proved).
Is it that the notion of an 'arbitrary infinite set' is problematic?
I don't know generally how the notion of an 'arbitrary finite set' can be expressed in PA. I know about coding of the finite sets of natural numbers but I am not sure that enables the fact that the finite Ramsey theorem can be expressed in the language of PA.
 A: Yes, $PA$ can talk about finite sets (and sequences) of natural numbers. Given a finite set $F\subseteq \mathbb{N}$, there's a natural number $n_F$ coding $F$: namely, $$n_F=\prod_{1\le i\le \vert F\vert} p_i^{a_i},$$ where $p_k$ denotes the $k$th prime and $F=\{a_1, a_2, . . ., a_{\vert F\vert}\}$ with $a_1<a_2<...a_{\vert F\vert}$. For example, if $F=\{1, 3, 4\}$, then $n_F=2^1\cdot 3^3\cdot 5^4$.
(This isn't the only way to code finite sequences of course, but is in my opinion the simplest. That said, there are situations where a different choice of coding system is better, so we shouldn't be too wedded to the approach above.)
We can then translate properties about finite sets to properties of numbers coding them. For example, $F$ has size $k$ iff $n_F$ has $k$ many prime factors; and a natural number $n$ is the code of some finite set iff it satisfies the property "For each prime $p$ dividing $n$, all primes $<p$ also divide $n$." It turns out (this is highly nontrivial, and occupies a large chunk of Goedel's original paper on incompleteness) that $PA$ is strong enough to prove all the basic facts about coding that you need to develop a theory of finite sets. In particular, finite Ramsey's theorem can be converted into a statement about code numbers, and this statement can be proved in $PA$.
Infinite sets, on the other hand, cannot be so coded (there's just too many of them!); so while $PA$ can talk about some infinite sets (e.g. the set of even numbers - basically, $PA$ can talk about individual definable infinite sets), arbitrary infinite sets are not accessible to $PA$. So there is no good way to talk about infinite Ramsey's theorem in $PA$.
That said, all is not lost. Let's say that we have a statement $\varphi$ about infinite sets of natural numbers. $\varphi$ doesn't make sense in $PA$, even if we try some coding tricks; but we can express $\varphi$ in an expanded language $L$. Moreover, maybe there's a natural theory $T$ in the language $L$ which contains $PA$, but doesn't prove anything in the language of $PA$ that $PA$ doesn't already prove (that is, $T$ is a conservative extension of $L$). If $\varphi$ is provable in $T$, that suggests that $\varphi$ is "morally" provable in $PA$ - namely, all the consequences of $\varphi$ which are expressible in the language of $PA$, are already theorems of $PA$.
Indeed, this is the case for infinite Ramsey's theorem: the expanded language $L$ is the language of second-order arithmetic, and $T$ is the theory $ACA_0$. If you're interested in this sort of thing, and also in questions about what axioms are needed to prove what theorems - and what sort of arithmetic consequences various versions of Ramsey's theorem, finitary and infinitary, have - you may be interested in reverse mathematics.
A: $
\def\nn{\mathbb{N}}
\def\eq{\leftrightarrow}
$Basically, PA is able to manipulate arbitrary finite sequences of natural numbers encoded as single natural numbers. This can be done using Godel numbering. Because of that, we can write down an explicit algorithm that given as input any sentence $P$ over ZF about natural numbers and finite sets of natural numbers will produce as output an equivalent sentence $φ$ over PA, in the specific sense that $\text{ZF} \vdash P \eq ( \nn \vDash φ )$. One can consider this algorithm as a uniform translation. That is the precise meaning when people say that PA can state some apparently higher-order statements such as the finite Ramsey theorem (FRT) and the strengthened finite Ramsey theorem (SFRT).
$
\def\wi{\subseteq}
\def\lfrac#1#2{{\large\frac{#1}{#2}}}
\def\floor#1{\left\lfloor#1\right\rfloor}
\def\ceil#1{\left\lceil#1\right\rceil}
$
We can give a sharper statement for FRT; it is equivalent to a $Π_3$-sentence over PA. We need $\forall$ for $e,k,r$, and then $\exists$ for $m$, and then $\forall$ for $M$ (note that we can only translate the version involving a finite $M$!), and the rest can be done with bounded quantifiers. Also, if you had stated FRT where $M$ is simply $\{1..m\}$ (which is clearly equivalent to the original), then it translates to a $Π_2$-sentence. Likewise for SFRT, where instead of $\#(H) = k$ you need $\#(H) \ge \max(k,\min(H))$.
Note that it is not important to use ZF, since Godel numbering works in very weak meta-systems, and the uniformness of the translation is what makes it interesting. In the particular case of SFRT, in meta-systems like ZF the question becomes trivial because ZF proves SFRT and so proves that the trivial true sentence "$\top$" is equivalent to SFRT. Weaker systems than ZF may be strong enough to prove the uniform translation but not strong enough to prove SFRT. For example (as the linked Wikipedia article states), PA cannot prove SFRT, and so ACA0 (which is conservative over PA) cannot, even though ACA0 can prove the uniform translation.
Also, PA can actually prove the equivalent sentence to FRT! It is stated without proof in this book, and I could not find the proof anywhere online, so I shall give my own proof below. The basic idea is that we prove the 2-colour case first and then generalize, and for the 2-colour case we prove the general case where the desired size of the homogenous set depends on the colour. For simplicity let "$n$-set" denote a set of size $n$, and "$[S]^n$" denote the collection of all subsets of $S$ of size $n$.

Let $R(c,n,k)$ assert the Ramsey theorem for $c$-colourings of $n$-sets and desired size $k$, namely that there is some $m \in \nn$ such that, for every $c$-colouring $f$ of $[\{1..m\}]^n$, there is some set $S \wi \{1..m\}$ such that $\#(S) = k$ and all $n$-sets in $[S]^n$ have the same colour under $f$. Let $R_2(n,j,k)$ assert the Ramsey theorem for $2$-colourings of $n$-sets and desired sizes $j,k$ for the respective colours, namely that there is some $m \in \nn$ such that, for every black-white colouring $f$ of $[\{1..m\}]^n$, there is some set $S \wi \{1..m\}$ such that, either $\#(S) = j$ and all $n$-sets in $[S]^n$ are black under $f$, or $\#(S) = k$ and all $n$-sets in $[S]^n$ are white under $f$.
$R(1,n,k)$ is trivial for every $n,k \in \nn$. We will later prove that $R(2,n,k)$ holds for every $n,k \in \nn$. Take any $c \in \nn_{>1}$. Let $c' = \ceil{\lfrac{c}{2}}$. Then $c' < c$. Let $p$ witness $R(2,n,k)$ and $q$ witness $R(c',n,p)$ by induction. Take any $c$-colouring $f$ of $\{1..q\}^n$. Let $f'$ be $f$ but with the original colours paired and made the same in each pair, with at most one colour unpaired. Then $f'$ is a $c'$-colouring of $\{1..q\}^n$. Thus by choice of $q$ let $S \wi \{1..q\}$ such that $\#(S) = p$ and all $n$-sets in $[S]^n$ have the same colour under $f'$. Then all the $n$-sets in $[S]^n$ have only two colours under $f$. Thus by choice of $p$ (and via a bijection from $S$ to $\{1..p\}$) let $T \wi S$ such that all $n$-sets in $[T]^n$ have the same colour under $f$.
We shall now prove $R_2(n,k,k)$ for every $n,k \in \nn$. Take any $j,k \in \nn$. $R_2(n,j,k)$ is trivial if $j = 0$ or $k = 0$, and hence we can assume that $j,k > 0$. Let $p,q$ witness $R_2(n,j-1,k)$ and $R_2(j,k-1)$ respectively. Let $r$ witness $R_2(n-1,p,q)$. Take any $c$-colouring $f$ of $[\{0..r\}]^n$. Then by choice of $r$ let $S \wi \{1..r\}$ such that, letting $T = \{ \{0\} \cup t : t \in [S]^{n-1} \}$, either $\#(S) = p$ and all $n$-sets in $T$ are black under $f$, or $\#(S) = q$ and all $n$-sets in $T$ are white under $f$. By symmetry we can assume that the first case holds. By choice of $p$ let $U \wi S$ such that, either $\#(U) = j-1$ and all $n$-sets in $[U]^n$ are black under $f$, or $\#(U) = k$ and all $n$-sets in $[U]^n$ are white under $f$. In the latter case we are done. In the former case $\#(\{0\} \cup U) = j$ and all $n$-sets in $[\{0\} \cup U]^n$ are black under $f$, and hence we are also done.
It should be not too hard to see that the uniform translation of the above proof gives a proof over PA of the equivalent sentence to FRT.

Finally there is one way you can 'talk' about (quite) arbitrary sets of natural numbers in PA, simply by talking about the Godel encodings of $1$-parameter sentences over PA (where $φ$ is interpreted as $S_φ = \{ x : x \in \nn \land \nn \vDash φ(x) \}$ and "$x \in S_φ$" is translated as "$\text{Prov}_\text{PA}(φ(x))$"). However, I think that PA is unable to prove the infinite Ramsey theorem stated for such sets. ACA0 on the other hand has no trouble stating and proving the full infinite Ramsey theorem for $\nn$. ACA0 can also prove SFRT because it follows from the infinite Ramsey theorem by a compactness argument.
