Skip to content

Holes

opulse.solver.holes

Fill-in-the-blank problems and their reverse derivation.

A problem replaces one number of an evaluated expression by the unknown x: E(x) = R. Solutions are searched in a stated integer domain: by default the whole value domain [-B, B] with z3; when z3 cannot decide, by exhaustive evaluation over a small stated range. A problem is unique when exactly one x in its domain solves it; the domain is part of the problem, so "unique" is always a precise claim.

The reverse derivation peels operators from the outside: at an application f(..., s, ...) = R whose other arguments are known, solve for the value s of the sub-expression that contains x, then continue inside it. Every step lists all candidate values (non-injective operators can give several); every candidate is re-checked forward with the reference oracle.

HoleSolver

solve

solve(expression: Node, target) -> Solutions

All x with expression(x) equal to target (an int) or in it (a set of ints).

problem

problem(
    tree: Node, path: tuple, with_reverse: bool = True
) -> HoleProblem | None

Blank out the number at path; optionally defer its reverse derivation.

reverse

reverse(tree: Node, path: tuple) -> list[ReverseStep]

Outside-in derivation along path (the hole's position) of the original tree.

Step i solves f(..., s_i, ...) = t for every target t kept from step i-1. A step is complete only when its own enumeration is complete and so is every earlier step; the true intermediate value is always checked to be a candidate.

hole_paths

hole_paths(node: Node, path: tuple = ()) -> list[tuple]

Paths of every number leaf.