APSP in word-RAM steps
ProvedTrulySubcubicAPSP.apsp_bound_299791For every fixed , there exist one finite deterministic word-RAM program , one natural constant , and one step-bound function that work for every input size , including , and for every word width . All encoded input numbers have absolute value at most . The run must halt with the specified verdict and output within steps.
For a directed -vertex graph with integer weights and no negative-weight closed walk, accept and compute every exact shortest-path distance in
Each ordered vertex pair receives a flag and a distance. Reachable pairs have flag one and an attained minimum path weight; unreachable pairs have flag zero and an unconstrained distance slot. Negative edge weights and missing edges are permitted. Empty paths give diagonal distance zero. No assumptions about other algorithms appear in the theorem.
Establish this bound using the shared APSP and word-RAM definitions of the foundation mission.
/- Copyright (c) 2026 Anthropic, PBC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. SPDX-License-Identifier: Apache-2.0 -/ import Definitions.Def_TrulySubcubicAPSP_Problems set_option autoImplicit false set_option relaxedAutoImplicit false
theorem TrulySubcubicAPSP.apsp_bound_299791 :
TrulySubcubicAPSP.APSP.SolvedInTime 2.99791 := by sorryRead-back
What the Lean code literally says, in plain math · claude-opus-5-5
Read-back of TrulySubcubicAPSP.apsp_bound_299791. The theorem has no hypotheses or parameters. It says that the problem (defined below) is solved in time exponent , where is the exact rational number (already in lowest terms). It does this on the specific word-RAM model defined below. Written out in full, it asserts the following.
Statement. For every natural number (the bound on the size of input numbers), there exist
- a program , which is a finite list of instructions,
- a natural number (the word-size multiplier), and
- a function (the time bound),
such that the following hold:
- Time bound. There is a natural number with
This is the same as . Nothing is required of or . 2. Correctness. Take any and any APSP instance on vertices whose input list (described below) has every entry satisfying . Then for every word length with
the program , run on with -bit words, halts within steps, accepts, and writes a correct output. Here is taken to be , so for the condition is just . The program , the multiplier and the function may depend on . They may not depend on , or . In particular, the step bound is the same for every allowed .
The APSP instances. An instance on vertices is a function that assigns to each ordered pair of vertices in either "no edge" or an edge with an integer weight . The graph is directed. Self-loops are allowed, and weights may be negative or zero.
A path from to of weight is defined as follows:
- the empty path from to has weight ;
- if there is an edge of weight and a path from to of weight , then there is a path from to of weight .
So paths are arbitrary finite walks, and they may repeat vertices and edges. An instance must satisfy one side condition: every closed walk from a vertex back to has total weight . In other words, there is no negative-weight cycle, and in particular every self-loop has weight . The machine does not receive this condition; it only receives the input list.
Input encoding. The input list has length and consists of two parts, in this order:
- the adjacency matrix in row-major order (entry iff there is an edge );
- the weight matrix in row-major order, with written for every absent edge.
The size hypothesis therefore bounds every edge weight by in absolute value. For example, when or , every weight must lie in . When the input is empty, so the hypothesis holds vacuously.
Required behaviour. The APSP problem has no yes/no condition, so the verdict must always be "accept". Index the cells after the input by , so that output cell is memory cell . Each such cell is read as a signed -bit integer. For every ordered pair , let
Then exactly one of the following must hold:
- , there is a path from to of weight exactly , and every path from to has weight ; or
- , and there is no path from to .
Because the empty path exists, the diagonal pairs must have and . The value must equal the true distance as an integer, after being read back as a signed -bit number.
The machine model. Memory is a function from all integers (including negative addresses) to -bit words. At the start:
- cell holds ;
- cells hold the input list;
- every other cell, including all negative ones, holds .
Every value is stored after reduction modulo (two's-complement encoding). Execution starts at instruction position . Every executed instruction, including the halting one, costs one step. The instruction set is listed below; denotes the word in cell , and the cell indices are fixed integer constants written into the program.
- (the only constant available);
- , , , all computed modulo ;
- load: ;
- store: , where an address read from a word is interpreted as a signed integer;
- conditional jump: go to position if is negative as a signed word, and otherwise continue with the next instruction;
- accept;
- reject.
Running past the end of the program counts as a reject. The machine has no division, shifts, bitwise operations or comparison other than the sign test. "Halts within steps" means that an accept or a reject is executed within the first instructions; the verdict and the final memory are the ones at that moment. If the program does not halt within steps, the run does not count as solving the instance.
The imported file also defines Exact Triangle, the min-plus product and the constant . The theorem does not use any of them.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.