{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Statement\n\nLet $\\sigma$ be a finite relational signature.\nLet $\\mathcal K$ be a class of finite $\\sigma$-[[structures|983GZBQYT4]] that is closed under isomorphism.\nThen the following are equivalent.\n\n1. The class $\\mathcal K$ is in NP: some nondeterministic [[Turing machine|758EYCN27B]] decides, in time polynomial in the size of a finite $\\sigma$-structure $A$, whether $A \\in \\mathcal K$.\n2. There is an existential [[second-order|G6X7SZSNC5]] [[sentence|DKFGQTRYZE]] $\\exists R_1 \\cdots \\exists R_k \\, \\varphi$ such that a finite $\\sigma$-structure belongs to $\\mathcal K$ if and only if it satisfies this sentence.\n\nHere $R_1, \\ldots, R_k$ are relation variables, and $\\varphi$ is a first-order sentence in the signature $\\sigma \\cup \\set{R_1, \\ldots, R_k}$.\n\n## Remarks\n\nFrom 2 to 1: a machine guesses the relations $R_1, \\ldots, R_k$ on the finite universe, which takes polynomially many bits.\nIt then checks the first-order sentence $\\varphi$, which takes polynomial time for a fixed $\\varphi$.\nFrom 1 to 2: the sentence guesses a linear order of the universe and relations that encode an accepting computation of the machine.\nThe computation of length $n^c$ is coded with tuples of length $c$, and $\\varphi$ checks that each step follows the transition rules.\n\nExample: the class of finite graphs that admit a proper colouring with three colours is in NP.\nIt is defined by the sentence $\\exists R \\, \\exists G \\, \\exists B \\, \\varphi$.\nHere $\\varphi$ says that each vertex lies in $R$, $G$ or $B$, and that no edge joins two vertices in the same set.\n\n## Explanations\n\n### L1 human\n\nThe theorem matches a kind of computing problem with a kind of logical description.\nA problem is in NP when a proposed solution can be checked quickly.\nFagin's theorem says these are exactly the properties of finite structures of the form \"there exist some relations such that a first-order condition holds\".\nThe relations play the role of the solution that is guessed.\n\n### L2 human\n\nFagin's theorem started descriptive complexity, which characterises complexity classes by logics without any reference to machines.\nIt shows that NP is closed under complement if and only if existential second-order logic has the same power as universal second-order logic on finite structures.\nOther results of this kind characterise P on ordered finite structures by first-order logic with a least fixed point operator.\nThe theorem belongs to [[finite model theory|4XRVJE0KAN]], where classical tools such as compactness are not available.\n",
  "commit": "547b6eddb8f2feb8d579f2d633d22a27b7e132fc",
  "front": {
    "about": [
      "4XRVJE0KAN"
    ],
    "kind": "statement",
    "msc": [
      "03C13",
      "68Q19",
      "68Q15"
    ],
    "name": "Fagin's theorem",
    "role": "theorem",
    "same_as": {
      "wikidata": "Q2226670",
      "wikipedia": "Fagin's theorem"
    },
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Fagin's_theorem"
      }
    ],
    "tag": "BG8Q0BYSQ3",
    "uses": [
      "983GZBQYT4",
      "G6X7SZSNC5",
      "DKFGQTRYZE",
      "758EYCN27B"
    ]
  },
  "kind": "statement",
  "link": "https://math2.tamnd.com/node/BG8Q0BYSQ3/",
  "links": [
    {
      "field": "about",
      "target": "4XRVJE0KAN"
    },
    {
      "field": "uses",
      "target": "983GZBQYT4"
    },
    {
      "field": "uses",
      "target": "G6X7SZSNC5"
    },
    {
      "field": "uses",
      "target": "DKFGQTRYZE"
    },
    {
      "field": "uses",
      "target": "758EYCN27B"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/BG8Q0BYSQ3.md",
  "msc": [
    "03C13",
    "68Q19",
    "68Q15"
  ],
  "name": "Fagin's theorem",
  "prov": null,
  "role": "theorem",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/BG8/BG8Q0BYSQ3.md",
  "status": null,
  "tag": "BG8Q0BYSQ3",
  "uri": "m2://BG8Q0BYSQ3",
  "url": "https://math2.tamnd.com/wiki/fagins-theorem/",
  "writing": {
    "tag": "BG8Q0BYSQ3",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      },
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
