{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Example\n\nTo color a graph with three colors is to choose three sets of vertices, one for each color.\nSo a quantifier over sets of vertices can say that a coloring exists.\n\nA [[graph|00C0BR7D7H]] is a structure $(V, E)$ with a symmetric and irreflexive edge relation $E$.\nIt is [[3-colorable|0XHZW0VCPR]] when there is a map $c : V \\to \\set{1, 2, 3}$ with $c(u) \\neq c(v)$ for every edge $\\set{u, v}$.\nThe existential [[monadic second-order|3WHQFSHR58]] sentence $\\chi_3$ is this:\n$$\\exists R \\exists G \\exists B \\Bigl( \\forall x\\, (R(x) \\lor G(x) \\lor B(x)) \\land \\forall x \\forall y \\bigl( E(x, y) \\to \\neg (R(x) \\land R(y)) \\land \\neg (G(x) \\land G(y)) \\land \\neg (B(x) \\land B(y)) \\bigr) \\Bigr).$$\nWe show that a graph satisfies $\\chi_3$ if and only if it is 3-colorable.\n\n1. Let $c$ be a proper coloring with the colors $1, 2, 3$.\n   Put $R = c^{-1}(1)$, $G = c^{-1}(2)$ and $B = c^{-1}(3)$.\n2. Every vertex has a color, so every vertex lies in $R$, $G$ or $B$, and the first conjunct holds.\n3. If $E(u, v)$, then $c(u) \\neq c(v)$.\n   So $u$ and $v$ do not lie in the same one of the three sets, and the second conjunct holds.\n4. Conversely, let $R, G, B$ satisfy the matrix of $\\chi_3$.\n   The sets can overlap, so we put $c(v) = 1$ if $v \\in R$, $c(v) = 2$ if $v \\in G \\setminus R$, and $c(v) = 3$ otherwise.\n5. By the first conjunct, a vertex with $c(v) = 3$ lies in $B$.\n   So each vertex lies in the set that matches its color.\n6. If $E(u, v)$ and $c(u) = c(v)$, then $u$ and $v$ lie in the same set by step 5, and this contradicts the second conjunct.\n   So $c$ is proper.\n\n## Remarks\n\n### Two small graphs\n\nThe 5-cycle has the vertices $1, \\ldots, 5$ and the edges $12, 23, 34, 45, 51$.\nWe try these sets:\n$$R = \\set{1, 3}, \\qquad G = \\set{2, 4}, \\qquad B = \\set{5}.$$\nCheck: the edges join $R$ to $G$, $G$ to $R$, $R$ to $G$, $G$ to $B$ and $B$ to $R$.\nSo no edge stays inside one set.\nThe complete graph $K_4$ fails $\\chi_3$.\nEach of its four vertices lies in one of three sets.\nSo two of them share a set by the [[pigeonhole principle|0HGVCWQGY3]], and these two vertices are adjacent.\n\n### Where the sentence sits\n\nThe sentence has the form $\\exists X_1 \\cdots \\exists X_k\\, \\varphi$ with $\\varphi$ first-order, so it is in existential MSO (EMSO).\nIt quantifies only over sets of vertices, not over sets of edges, so it is an $\\mathrm{MSO}_1$ sentence.\n\n### More colors, and the cost of checking\n\nFor $k$ colors we use $k$ set variables and the same two conjuncts.\nFor $k = 2$ the sentence defines the bipartite graphs.\nA program decides 2-colorability in polynomial time, but 3-colorability is [[NP-complete|JGZWHWA8P8]].\nSo the evaluation of one fixed EMSO sentence on finite graphs can already be NP-complete.\nThis agrees with [[Fagin's theorem|BG8Q0BYSQ3]]: existential second-order logic defines exactly the properties in NP.\nOn graphs of bounded [[treewidth|CD2XB4Y1SF]], Courcelle's theorem decides $\\chi_3$ in linear time.\n\n## Explanations\n\n### L1 human\n\nA map is 3-colorable when we can paint each country red, green or blue, and neighbors always get different colors.\nThe logic says this directly: \"there is a red set, a green set and a blue set\".\nEvery country must be in one of the sets, and no two neighbors may be in the same set.\nA ring of five countries can be painted this way.\nFour countries that all touch each other cannot, because two of them would share a color.\n\n### L2 human\n\nWe check $\\chi_3$ on the wheel $W_5$.\nIt has a 5-cycle $1, 2, 3, 4, 5$ and a center $0$ that is joined to all five.\n\n1. In a proper coloring, the center is adjacent to every other vertex, so its color appears nowhere else.\n   Say the center has color $3$.\n2. Then the 5-cycle uses only the colors $1$ and $2$, so the colors must alternate along it.\n3. Going around from vertex $1$, the vertices $1, 3, 5$ get one color and the vertices $2, 4$ get the other.\n4. Then the edge $51$ joins two vertices of the same color.\n   So $W_5$ has no proper 3-coloring, and $W_5$ fails $\\chi_3$.\n\nCheck: a cycle with an odd number of vertices has no 2-coloring, and $5$ is odd.\nThe typical use of the sentence is to show that a graph property is in NP, or to apply Courcelle's theorem to it.\nWatch out: do not require in a proof that $R$, $G$ and $B$ are disjoint when the sentence does not say so.\nOur sentence allows overlaps, and step 4 of the example removes them.\n",
  "commit": "35d5da104f2b90e930cd762570f4d67e50027674",
  "front": {
    "audience": "grad",
    "instance_of": [
      "3WHQFSHR58"
    ],
    "kind": "example",
    "msc": [
      "03B16",
      "03C13",
      "05C15",
      "68Q19"
    ],
    "name": "Three-colorability in existential monadic second-order logic",
    "sources": [
      {
        "locator": "Vertex sets",
        "url": "https://en.wikipedia.org/wiki/Courcelle's_theorem"
      },
      {
        "locator": "Variants",
        "url": "https://en.wikipedia.org/wiki/Monadic_second-order_logic"
      }
    ],
    "tag": "EHH5XEB6BG",
    "topics": [
      "MDHDYV8QZW"
    ],
    "uses": [
      "3WHQFSHR58",
      "0XHZW0VCPR",
      "00C0BR7D7H",
      "BG8Q0BYSQ3"
    ]
  },
  "kind": "example",
  "link": "https://math2.tamnd.com/node/EHH5XEB6BG/",
  "links": [
    {
      "field": "instance_of",
      "target": "3WHQFSHR58"
    },
    {
      "field": "topics",
      "target": "MDHDYV8QZW"
    },
    {
      "field": "uses",
      "target": "3WHQFSHR58"
    },
    {
      "field": "uses",
      "target": "0XHZW0VCPR"
    },
    {
      "field": "uses",
      "target": "00C0BR7D7H"
    },
    {
      "field": "uses",
      "target": "BG8Q0BYSQ3"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/EHH5XEB6BG.md",
  "msc": [
    "03B16",
    "03C13",
    "05C15",
    "68Q19"
  ],
  "name": "Three-colorability in existential monadic second-order logic",
  "prov": {
    "log": "https://github.com/tamnd/math2/blob/main/prov/EHH/EHH5XEB6BG.jsonl",
    "quarantine": null,
    "unchecked": null
  },
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/EHH/EHH5XEB6BG.md",
  "status": null,
  "tag": "EHH5XEB6BG",
  "uri": "m2://EHH5XEB6BG",
  "url": "https://math2.tamnd.com/wiki/three-colorability-in-existential-monadic-second-order-logic/",
  "writing": {
    "tag": "EHH5XEB6BG",
    "kind": "example",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
