{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Proof\n\nWe argue by contradiction, with the [[pigeonhole principle|0HGVCWQGY3]].\n\n1. Let $r, s \\ge 1$ be integers, let $N = (r - 1)(s - 1) + 1$, and let $a_1, \\dots, a_N$ be distinct real numbers.\n2. A subsequence of length $m$ is given by indices $i_1 \u003c i_2 \u003c \\dots \u003c i_m$. It is increasing if $a_{i_1} \u003c \\dots \u003c a_{i_m}$, and decreasing if $a_{i_1} \u003e \\dots \u003e a_{i_m}$. It ends at $a_{i_m}$.\n3. For each index $i$, let $x_i$ be the largest length of an increasing subsequence that ends at $a_i$. Let $y_i$ be the largest length of a decreasing subsequence that ends at $a_i$.\n4. These maxima exist, because lengths are at most $N$. Also $x_i \\ge 1$ and $y_i \\ge 1$, because the single term $a_i$ is both increasing and decreasing.\n5. Let $i \u003c j$. We claim that $(x_i, y_i) \\ne (x_j, y_j)$. Since the terms are distinct, either $a_i \u003c a_j$ or $a_i \u003e a_j$.\n6. If $a_i \u003c a_j$, take an increasing subsequence of length $x_i$ that ends at $a_i$. Appending $a_j$ gives an increasing subsequence of length $x_i + 1$ that ends at $a_j$. So $x_j \\ge x_i + 1$.\n7. If $a_i \u003e a_j$, the same argument with a decreasing subsequence gives $y_j \\ge y_i + 1$.\n8. In both cases the pairs differ. So the map $g : i \\mapsto (x_i, y_i)$ on $\\set{1, \\dots, N}$ is injective.\n9. Suppose, for a contradiction, that there is no increasing subsequence of length $r$ and no decreasing subsequence of length $s$.\n10. Then $x_i \\le r - 1$ for all $i$. Otherwise an increasing subsequence of length $x_i \\ge r$ exists, and its last $r$ terms form one of length $r$.\n11. In the same way, $y_i \\le s - 1$ for all $i$.\n12. By steps 4, 10 and 11, $g$ maps $\\set{1, \\dots, N}$ into $P = \\set{1, \\dots, r - 1} \\times \\set{1, \\dots, s - 1}$.\n13. By the [[rule of product|0VPK4X73Q0]], $|P| = (r - 1)(s - 1) \u003c N$.\n14. By the pigeonhole principle, $g$ is not injective. This contradicts step 8.\n15. Hence the sequence has an increasing subsequence of length $r$ or a decreasing subsequence of length $s$.\n\n## Idea\n\nLabel each term by the lengths of the longest increasing and decreasing runs that end there. A later term always improves one of the two labels, so all labels differ. If both kinds of subsequence were short, there would be too few labels for $N$ terms.\n",
  "commit": "68a8c3dc73fd55004b2796431c607c30960d1a85",
  "front": {
    "kind": "proof",
    "msc": [
      "05A05"
    ],
    "name": "Proof of the Erdős–Szekeres theorem by the pigeonhole principle",
    "proves": "0SNJM8HSD3",
    "sources": [
      {
        "locator": "Proofs, Pigeonhole principle",
        "url": "https://en.wikipedia.org/wiki/Erdős–Szekeres_theorem"
      }
    ],
    "tag": "22G1VPJW6Y",
    "uses": [
      "0HGVCWQGY3",
      "0VPK4X73Q0"
    ]
  },
  "kind": "proof",
  "link": "https://math2.tamnd.com/node/22G1VPJW6Y/",
  "links": [
    {
      "field": "proves",
      "target": "0SNJM8HSD3"
    },
    {
      "field": "uses",
      "target": "0HGVCWQGY3"
    },
    {
      "field": "uses",
      "target": "0VPK4X73Q0"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/22G1VPJW6Y.md",
  "msc": [
    "05A05"
  ],
  "name": "Proof of the Erdős–Szekeres theorem by the pigeonhole principle",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/22G/22G1VPJW6Y.md",
  "status": null,
  "tag": "22G1VPJW6Y",
  "uri": "m2://22G1VPJW6Y",
  "url": "https://math2.tamnd.com/wiki/proof-of-the-erdos-szekeres-theorem-by-the-pigeonhole-principle/",
  "writing": {
    "tag": "22G1VPJW6Y",
    "kind": "proof",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
