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 and , 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:
For : .
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 or : 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 has , since every face has at least three edges and each edge borders two faces. Without triangles it is . So (10 > 9) and (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 faces Euler's formula
gives the genus of the surface. Every drawing without crossings comes from a rotation system, so the genus of the graph is the least 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 , so and , 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 ( has 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 (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.
@ratmath/discrete and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.