Five Gates, Five Complexity Classes

Five Gates, Five Complexity Classes

One small boolean circuit, asked five questions. Each question climbs one rung of the complexity ladder, from P to EXPSPACE.

The indexAll (5)
N°ClassQuestion about the circuitAlgorithm hereComplete problem
1PDoes this input light the lamp?Evaluate the gates in orderCircuit ValueView 2NPDoes some input light it?Guess an input, then check it in PCircuit SAT3-SATView 3PSPACETwo players take turns setting the inputs. Can the one who wants the lamp lit always win?Depth-first over the game treeTQBFGeographyView 4EXPTIMECan you win a game with no move limit?Label all 2 × 2n positions backwardsFormula gamesn×n chessView 5EXPSPACEA circle of lamps updates itself by the circuit’s rule. Do all the lamps eventually go out?Simulate with cycle detection2n-space acceptanceRegex with squaringView

P

Given the circuit and a setting of a, b, c, d, does the lamp light?

Work through the gates in order. Each gate reads wires that are already settled, so one pass does it: five gates, five steps. Double the circuit and you double the work.

    Circuit Value is P-complete. Any polynomial-time program, unrolled over its running time, becomes a circuit like this one, so a fast parallel algorithm for this problem would give one for everything in P.

    Time
    one step per gate: O(size)
    Space
    one bit per wire
    Complete problem
    Circuit Value (CVP)

    NP

    Is there any setting of a, b, c, d that lights the lamp?

    Nobody hands you the input now. If someone proposes one, checking it is the P problem above. Finding one is another matter: the best known general methods still try exponentially many of the 2n settings in the worst case. Click any setting to check it, or let the search run.

    Each check costs 5 gate evaluations. The search may cost up to 16 checks.

    Inputs nSettings 2nCheck oneTry all, at 109/s
    4 (this circuit)165 gates16 ns
    401.1 × 1012~ size18 minutes
    601.2 × 1018~ size37 years
    1001.3 × 1030~ size4 × 1013 years
    Check
    polynomial, given the certificate
    Find
    2n tries by brute force
    Complete problem
    Circuit SAT

    PSPACE

    Two players take turns setting a, b, c, d. Can the player who wants the lamp lit always win?

    The quantifiers say who sets each input. ∃ (“there exists”) marks an input chosen by the player who wants the lamp lit. ∀ (“for all”) marks an input chosen by the player who wants it dark. They move in order a, b, c, d, and each sees the earlier moves.

    So ∃a ∀b ∃c ∀d reads: there is a choice of a such that, whatever b is, there is a choice of c such that, whatever d is, the lamp lights. That is the same as saying the lit player has a strategy that wins against every reply. Click a quantifier to hand that input to the other player.

    Call stack
      Cost so far

      Leaves visited: 0 of 16
      Deepest stack: 0 frames

      The tree has 2n leaves, so the walk can take exponential time. But a depth-first walk only ever holds one path from root to leaf: n frames. When one branch already settles a node, the walk skips the other (dashed). The same memory gets reused for every path, which is why the whole class is about space.

      Time
      up to 2n leaves
      Space
      n stack frames
      Complete problem
      Quantified SAT (TQBF)

      EXPTIME

      In a game with no move limit, can you force the lamp to light?

      You own a and b. Your opponent owns c and d. On each turn the player to move must flip one of their own bits, and whoever's flip lights the lamp wins. Positions can repeat, so play can go on forever. Depth-first search no longer works, because a path can be endless.

      Instead, label every position, working backwards from the lit ones. First mark the positions where you can light the lamp now. Then mark those where every opponent reply leads into an already-marked position. Repeat until nothing changes. Whatever stays unmarked is a draw.

      You to move
      Opponent to move
      Lamp lit W n: you win within n moves L n: you lose within n D: endless with best play

      Rows are ab and columns are cd, in Gray-code order like a Karnaugh map, so neighboring cells differ by one flip.

      Play it

      Solve first, then click any unlit square in “You to move” to start there. The opponent plays perfectly from the table.

        Time
        polynomial in 2 × 2n positions
        Space
        a label for every position
        Complete problem
        Formula games (Stockmeyer–Chandra), generalized chess

        EXPSPACE

        Put 2k lamps in a circle. Every tick, the circuit sets each lamp from itself and its neighbors. Do all the lamps eventually go out?

        Each lamp is on or off. On every tick, all lamps update at once. Each lamp feeds four values into the circuit: the lamp to its left as a, itself as b, the lamp to its right as c, and the one after that as d. The circuit’s output is the lamp’s new state. In the diagram below, the top row is the starting circle cut open and laid flat, and each row under it is the next tick.

        Why this is a step up: the question only takes the circuit and the number k to write down, but the circle has 2k lamps, so just holding its current state takes exponential memory. There are 22k possible on/off patterns, so the lamps can keep changing for an enormous time before any pattern repeats. The decider keeps two copies of the circle and watches for a repeat. Either every lamp goes out, or an earlier pattern comes back, which means the circle loops forever and never goes dark. Click a cell in the diagram to load its four inputs into the circuit.

        Number of lamps
        Starting lamps · click to toggle
        Lamps
        32
        Decider memory
        64 bits
        Possible patterns
        232
        Ticks to answer
        –

        On/off lamps with a fixed four-lamp neighborhood are a toy. Give each lamp a few more states and the rule a bigger circuit, and the circle can simulate any machine with 2k memory cells. That makes the general question EXPSPACE-complete. With k lamps instead of 2k, the same question is PSPACE-complete.

        Time
        up to 22k ticks
        Space
        two copies of the circle: 2 × 2k bits
        Complete problem
        Acceptance by 2n-space machines; regex equivalence with squaring
        What is known

        What is proven

        P ⊆ NP ⊆ PSPACE ⊆ EXPTIME ⊆ EXPSPACE. The hierarchy theorems separate two pairs: P ≠ EXPTIME (more time solves more) and PSPACE ≠ EXPSPACE (more space solves more).

        What is open

        Every single step on the ladder. At least one of P ≠ NP, NP ≠ PSPACE, PSPACE ≠ EXPTIME must hold, because P ≠ EXPTIME. Nobody knows which.

        Why one circuit works

        Time and space are measured against how long the question is to write down. The lever each rung pulls is making something exponential relative to that: the search, the game tree, the table of positions, or the state.