Graph theory

Planarity

A graph is planar when it can be drawn in the plane without crossings. Kuratowski's theorem says the only obstructions are subdivisions of K5K_5 and K3,3K_{3,3}, so every answer here comes with evidence: faces for yes, one of those two subgraphs for no.

Yes, with faces

import { complete, planarity, isPlanar, hypercube, platonic } from "@ratmath/discrete";

planarity(complete(4));
// { planar: true, faces: [[[3,1,4], [4,3,2], [1,4,2], [2,3,1]]], edges: 6, vertices: 4 }
isPlanar(platonic("icosahedron"));   // true
isPlanar(hypercube(4));              // false

Each 2-connected block is embedded by the Demoucron–Malgrange–Pertuiset algorithm: start from a cycle, and repeatedly route a piece of the remaining graph through a face that holds all its attachment points, choosing a piece that fits in the fewest faces first. Faces are listed per block. Euler's formula is the check on every block:

V−E+F=2. V - E + F = 2.

For K4K_4: 4−6+4=24 - 6 + 4 = 2.

No, with a Kuratowski subgraph

import { petersen, checkKuratowski } from "@ratmath/discrete";
const r = planarity(petersen());
r.kuratowski.kind;     // "K3,3"
r.kuratowski.branch;   // the six branch vertices
r.kuratowski.paths;    // nine paths joining them, internally disjoint
checkKuratowski(petersen(), r.kuratowski).ok;   // true

When the embedding fails, edges are deleted one at a time while the graph stays non-planar. What is left is edge-minimal non-planar, and by Kuratowski's theorem it is a subdivision of K5K_5 or K3,3K_{3,3}: the vertices of degree three or four are the branch vertices and the rest lie on paths between them. checkKuratowski confirms the paths use real edges, are disjoint apart from their ends, and join the right pairs.

Quick counting arguments

A simple planar graph with V≥3V \ge 3 has E≤3V−6E \le 3V - 6, since every face has at least three edges and each edge borders two faces. Without triangles it is E≤2V−4E \le 2V - 4. So K5K_5 (10 > 9) and K3,3K_{3,3} (9 > 8) are out at once; Petersen has 15 edges, within both bounds, and needs the search.

Not planar: how many handles?

A graph that cannot be drawn on the sphere can be drawn on a sphere with enough handles. The genus of a graph is the least number of handles needed: 0 for planar graphs, 1 for graphs that fit on a torus, and so on.

Drawings on orientable surfaces can be listed without any geometry. A rotation system gives each vertex a cyclic order of its neighbours. Walk along an edge into a vertex and leave by the neighbour that comes next in that vertex's order: the walks close up into the faces of a drawing, and with FF faces Euler's formula

V−E+F=2−2g V - E + F = 2 - 2g

gives the genus gg of the surface. Every drawing without crossings comes from a rotation system, so the genus of the graph is the least gg over all of them, a finite search.

const t = genus(complete(5));
t.genus;                 // 1: the torus
t.blocks[0].rotation;    // { 1: [5, 4, 3, 2], 2: [5, 4, 3, 1], … }  an embedding
t.blocks[0].faces;       // its 5 faces: 5 − 10 + 5 = 0 = 2 − 2·1
embeddingGenus(complete(5), t.blocks[0].rotation).genus;   // 1, traced again from the rotation alone

Two bounds make the answer a proof. From below: a planar graph has genus 0, and otherwise every face has at least as many sides as the girth γ\gamma, so F≤2E/γF \le 2E/\gamma and g≥⌈(E(1−2/γ)−V+2)/2⌉g \ge \lceil (E(1 - 2/\gamma) - V + 2)/2 \rceil, at least 1. From above: the genus of an embedding actually found, returned with its rotation system so that it can be checked. A small block is searched completely (K5K_5 has 65=77766^5 = 7776 rotation systems once the first neighbour is fixed), stopping early if the lower bound is met. A larger one is searched by exchanging two neighbours at a time, and then proven is true only when the bounds meet; otherwise genus is null and the bounds are what is known, as for K8K_8 (genus 2, where the search here finds 3). The genus of a graph is the sum over its blocks, so each block is treated separately.

Try itEdit the code and run it with @ratmath/discrete and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs