Help us shape the future of Go! Take the 2026 Go Developer Survey

oracle

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package oracle implements the differential oracle and invariant checks of the eval layer (SPEC §4, SPEC-ADDITIONS §18): two independently written implementations of the same match rules grade each other, and a planted-defect self-test proves the oracle rejects a known regression. It is a two-dimensional port of evals-differential-oracle: on a board of gems every maximal horizontal or vertical run of length >= 3 clears, and a run of length >= 4 awards one special gem.

Two nets cover two failure modes. The differential net (React vs Native) uses independent run-enumeration strategies, so an enumeration bug in one surfaces as a disagreement. The invariant net recomputes the rule (special only for a run of >= 4) directly, so a rule bug is convicted even when both resolvers agree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InvariantsHold

func InvariantsHold(board Board, result Result) bool

InvariantsHold checks the governing rules directly, recomputing the runs itself and applying the special rule independently of any resolver, so it can convict a result both implementations agree on. It asserts three rules (a port of evals-differential-oracle's check_all): a special is awarded only by a run of length >= 4, the cleared set equals the union of runs of length >= 3, and the special count stays within [0, number of runs].

func SelfTest

func SelfTest(seed uint64) error

SelfTest proves the oracle has teeth (SPEC-ADDITIONS §18.4 negative control): the differential oracle and the invariant checker must both catch the planted Buggy resolver. It returns nil when both nets catch it, else an EINTERNAL error naming the net that failed.

Types

type Board

type Board [][]int

Board is a grid of gems: 0 is empty, 1..k are colors. Boards are rectangular.

func Diverges

func Diverges(a, b Resolver, boards []Board) Board

Diverges runs both resolvers over the boards and returns the first board on which they disagree, or nil if they agree everywhere.

func GenerateBoards

func GenerateBoards(seed uint64, count, maxRows, maxCols, colors int) []Board

GenerateBoards produces a deterministic set of rectangular boards for a seed, so the oracle runs the same corpus every time without a clock or ambient randomness.

type Cell

type Cell struct {
	Row int
	Col int
}

Cell is a board coordinate, used as the cleared-set key.

type CommandDivergence

type CommandDivergence struct {
	Line      int
	Reference string
	Candidate string
}

CommandDivergence is the first line at which two command outputs differ (§2.1): the 1-based line number and both sides' text. It is the general form of the board oracle's divergence — two implementations that should agree are each other's oracle, so any difference convicts one of them.

func DiffOutputs

func DiffOutputs(reference, candidate string) *CommandDivergence

DiffOutputs compares two command outputs line by line and returns the first divergence, or nil when they match (§2.1): the pure core of the command-level differential oracle. A line present on only one side diverges against the empty string; trailing newlines are ignored so a command that adds one still matches. It is pure — the caller runs the commands and captures their output.

type Report

type Report struct {
	Boards    int
	Divergent Board
}

Report summarizes a differential run for display.

func (Report) String

func (r Report) String() string

String renders a differential report.

type Resolver

type Resolver func(board Board) Result

Resolver reduces a board to a Result.

type Result

type Result struct {
	Cleared  map[Cell]bool
	Specials int
}

Result is a resolved board: the cleared cells and the special-gem count.

func Buggy

func Buggy(board Board) Result

Buggy is a deliberately wrong resolver used only by the self-test: it awards a special for any run of length >= 3 (the rule is >= 4). Both nets must catch it.

func Native

func Native(board Board) Result

Native resolves by an independent algorithm: it starts a run only at a cell whose left (or upper) neighbor differs, then extends. It must always agree with React.

func React

func React(board Board) Result

React resolves by a while-scan over rows then columns, awarding a special for a run of length >= 4 (the real rule).

func (Result) Equal

func (r Result) Equal(other Result) bool

Equal reports whether two results are identical — the exact match the differential oracle leans on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL