← Project overview

Forward and inverse programs

Each question world has a forward program, which computes the answer from the scene specification, and an inverse program, which derives the answer from the rendered image alone. A world is accepted only when the two answers agree.

This page shows examples of both programs, an error that an inverse program caught, the image-replacement test, and what inverse programs compute.

Examples

Three worlds. Select one to see its forward program and its inverse program.

Count the guitar strings

Count the guitar strings: recorded instance 1
Instance 1 · recorded answer 6
Count the guitar strings: recorded instance 2
Instance 2 · recorded answer 7
Count the guitar strings: recorded instance 3
Instance 3 · recorded answer 8
Original question

How many dark strings visibly run from the guitar's headstock, along the neck, and across its body? Count each continuous thin path once. Answer 4, 5, 6, 7, or 8.

Forward program · scene → answer

Read the number of strings specified in the scene.

def analytic_gold(scene: dict) -> str:
    return str(int(scene["string_count"]))
Read full renderer and forward source ↗

Inverse program · image → answer

Locate the bright bridge in the image, identify narrow dark runs across it, and count them. Three adjacent rows must agree.

    # Take a three-row vote. Each qualifying string is a narrow dark run wholly
    # inside the recovered bridge extent; body edges and sound hole lie outside.
    counts = []
    for y in range(y0 - 1, y0 + 2):
        strip = rgb[y, xlo:xhi+1]
        dark = strip.mean(axis=1) < 105
        runs = [(a, b) for a, b in _runs(dark) if 1 <= b-a <= 7 and a > 2 and b < len(dark)-2]
        counts.append(len(runs))
    count = int(np.median(counts))
    if count not in {4, 5, 6, 7, 8} or max(counts) != min(counts):
        raise ValueError(f"ambiguous string runs: {counts}")
    return str(count)
Read full inverse source ↗

The code is quoted from the generated source files; the full files are linked under each excerpt.

An error caught by the inverse program

During generation, the inverse program frequently caught real errors. For 29% of the worlds, the inverse program flagged an error at least once and the agent fixed its code before submitting. In 49% of these repairs, the agent changed the renderer or sampler, meaning the image or the question itself was wrong. The example below is one such case.

“How many separate raised black keys are visible above the seven white keys?”

  1. Rendered piano image with five black keysRendered image
  2. Black pixels kept by the inverse program1Keep black pixels
  3. Five connected regions, each in its own color2Group connected regions
  4. Five regions numbered one to five3Count separate keys

Forward 4≠Inverse 5Self-check fails

Agent repairs the renderer

Repaired piano image with four black keysRepaired image

Forward 4=Inverse 4Checks pass

Given a rendered piano octave, the inverse program processes the image deterministically and arrives at the answer 5. This does not match the forward program’s answer of 4, revealing a bug in the renderer. The mismatch is feedback that helps the agent repair the renderer (right). Without the inverse program, this world would have recorded the wrong answer 4 for an image with five black keys. Steps 1–3 are the inverse program’s own outputs on the faulty image.

“How many straight sides does the red STOP sign’s outer boundary have?”

  1. STOP sign with ten straight sidesInput image
  2. Saturated red pixels kept by the inverse program1Keep saturated red pixels
  3. Outer boundary of the red region and its center2Get boundary and its center
  4. Distance from the center to the boundary at each angle3Boundary distance from center by angle
  5. Fit error of regular polygons with 6 to 10 sides; 10 fits best4Fit error of regular 6–10-gons; 10 fits best

Forward 10=Inverse 10Checks pass

The agent writes an inverse program to measure the stop sign’s outline from the image alone and recover its number of sides, matching the forward program’s answer of 10.

The error. The question asks how many black keys are visible. The renderer was meant to leave out one of the five black keys, but in this scene it left out none. The scene specification still recorded four black keys, so the forward program answered four.

The catch. The inverse program kept the black pixels, grouped them into connected regions, and counted five. The two answers did not match, so the check failed. The agent repaired the renderer, and on the repaired image both programs answer four.

Image-replacement test

We keep the scene specification and the forward answer fixed, and replace the rendered image. If the replacement shows a different answer, the inverse program should disagree with the forward program.

Intended stovetop image with three burners

Intended image

Forward: 3 · Inverse: 3

Answers agree
Different stovetop image with three burners

Different image, same answer

Forward: 3 · Inverse: 3

Answers agree
Substituted stovetop image with four burners

Image with a different answer

Forward: 3 · Inverse: 4

Disagreement detected
Original images from the paper’s image-substitution test. The question concerns the burner count; the intended forward answer remains three in all three conditions.
The inverse program rejected 100% of the replacements that changed the answer and accepted all replacements that did not.

The test covers 100 worlds with three trials each (300 trials).

What inverse programs compute

Most inverse programs combine standard image processing, such as picking pixels by color and grouping them into connected regions, with steps specific to the question, such as rebuilding a graph before tracing a path.

In a review of the source of 225 worlds, every inverse program takes only an image as input, and none reads the scene specification or imports the forward program.

Steps found in the 225 inverse programs

Five inverse programs, step by step

Each example shows the image, the steps of the inverse program, and a link to its full source.

01

Measure a colored curve

Separate the four colors, then measure the tallest vertical segment.

All four colored step curves have the same total vertical decline. Which curve has the largest single vertical drop between adjacent horizontal plateaus? Answer red, blue, green, or orange.
Original instance · Try this question ↗
Question and recorded answer

All four colored step curves have the same total vertical decline. Which curve has the largest single vertical drop between adjacent horizontal plateaus? Answer red, blue, green, or orange.

Recorded answer: green

Color masks → column spans → largest drop

For each curve color, the program selects nearby RGB values. In every occupied column it measures the distance between the first and last selected pixel, then takes the largest span.

Simplified pseudocode · helpers summarize pixel processing

for color in curve_colors:
    mask = pixels_close_to(color)
    score[color] = largest_column_span(mask)
return largest_score_color(score)

Evidence checks. Rejects missing curves and a winning margin smaller than two pixels.

Read the complete original Python program ↗
02

Fit a circle through fragments

Fit one circle through the arcs, then find the dot nearest its center.

All four dots are candidates. The disconnected dark arcs are pieces of one circle. Which colored dot is at that circle's center? Answer red, blue, green, or orange.
Original instance · Try this question ↗
Question and recorded answer

All four dots are candidates. The disconnected dark arcs are pieces of one circle. Which colored dot is at that circle's center? Answer red, blue, green, or orange.

Recorded answer: green

Dark pixels → least-squares circle → nearest dot

The program selects dark contour pixels and fits x² + y² = 2cx·x + 2cy·y + c by least squares. It estimates each colored dot’s center by averaging its pixel coordinates.

Simplified pseudocode · helpers summarize pixel processing

arcs = select_dark_pixels(image)
center = fit_circle_least_squares(arcs)
dots = measure_colored_dot_centers(image)
return nearest_dot(dots, center)

Evidence checks. Checks fit error, coverage around the circle, marker sizes, and separation between the nearest two dots.

Read the complete original Python program ↗
03

Find a shared room

Paint each room a temporary color. Do both gates touch the same room?

Do the green and purple gates border at least one same enclosed white chamber? A chamber is a side-connected white region completely surrounded by the dark wall network; touching only at a corner does not connect regions. Answer yes or no.
Original instance · Try this question ↗
Question and recorded answer

Do the green and purple gates border at least one same enclosed white chamber? A chamber is a side-connected white region completely surrounded by the dark wall network; touching only at a corner does not connect regions. Answer yes or no.

Recorded answer: yes

White pixels → connected rooms → shared neighbor

A flood fill groups white pixels connected through horizontal or vertical neighbors. Regions touching the image boundary are exterior space. The program samples beside the long edges of both gates and compares their enclosed-room labels. It labels regions at a conservative four-pixel scale.

Simplified pseudocode · helpers summarize pixel processing

rooms = label_connected_white_regions(image)
rooms = remove_exterior_regions(rooms)
a = rooms_beside(green_gate)
b = rooms_beside(purple_gate)
return bool(a & b)

Evidence checks. Checks image dimensions and gate geometry; rejects gates with no resolved enclosed neighbor.

Read the complete original Python program ↗
04

Transform a grid and match a glyph

Read the squares, rotate a copy, subtract, and recognize what remains.

Inside the cyan frame, rotate a copy of the 11-by-11 tile mosaic by half a turn (180 degrees) about the gold center dot. Keep a result cell dark only when that cell is dark in the original and light in the rotated copy. Keep the original orientation. Which glyph appears: fork, hook, stair, or rake?
Original instance · Try this question ↗
Question and recorded answer

Inside the cyan frame, rotate a copy of the 11-by-11 tile mosaic by half a turn (180 degrees) about the gold center dot. Keep a result cell dark only when that cell is dark in the original and light in the rotated copy. Keep the original orientation. Which glyph appears: fork, hook, stair, or rake?

Recorded answer: stair

Cell brightness → rotation and subtraction → template match

The cyan frame locates an 11 × 11 grid. Brightness inside each cell determines whether it is dark. The program removes cells that are also dark in a half-turned copy, then compares the remaining set with four stored glyph patterns across possible placements.

Simplified pseudocode · helpers summarize pixel processing

dark = read_dark_grid_cells(image)
rotated = {(10-r, 10-c) for r, c in dark}
remaining = dark - rotated
return closest_glyph_template(remaining)

Evidence checks. Rejects ambiguous cells, implausible counts, excessive template mismatch, and close matches.

Read the complete original Python program ↗
05

Read arrows and update a counter

Read the starting level and arrows, then keep the counter between zero and four.

The gauge starts with the shown number of filled steps. Read the eight triangle cards from left to right: an up-pointing triangle adds one step unless the gauge is already full, and a down-pointing triangle removes one step unless it is already empty. What level remains? Answer 0, 1, 2, 3, or 4.
Original instance · Try this question ↗
Question and recorded answer

The gauge starts with the shown number of filled steps. Read the eight triangle cards from left to right: an up-pointing triangle adds one step unless the gauge is already full, and a down-pointing triangle removes one step unless it is already empty. What level remains? Answer 0, 1, 2, 3, or 4.

Recorded answer: 2

Colored objects → ordered commands → bounded counter

Connected colored pixels form objects. Proportions and filled area distinguish gauge blocks from triangles. A triangle’s center of mass relative to its bounding box determines its direction. The program orders commands from left to right and updates the level.

Simplified pseudocode · helpers summarize pixel processing

level = count_gauge_blocks(image)
for op in read_arrows_left_to_right(image):
    if op == "up":
        level = min(4, level + 1)
    else:
        level = max(0, level - 1)
return level

Evidence checks. Requires eight recognizable commands with enough horizontal separation and at most four starting blocks.

Read the complete original Python program ↗