Skip to content

Constant width examples and amb library - #17

Merged
ademar merged 2 commits into
masterfrom
constant-width-examples-and-amb-library
Jul 25, 2026
Merged

Constant width examples and amb library#17
ademar merged 2 commits into
masterfrom
constant-width-examples-and-amb-library

Conversation

@ademar

@ademar ademar commented Jul 25, 2026

Copy link
Copy Markdown
Member

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
New examples and a self-contained library package only; no changes to the IronKernel runtime or toolchain in this diff.

Overview
Adds two constant-width chessboard figure examples and ships the nondeterminism layer as the first lib/ NuGet-style package IronKernel.Amb.

constant-width.ikr is a CPS backtracking port of the connected-figure search (CLI n k w, defaults 5 4 2). constant-width-amb.ikr solves the same problem in direct style with inline shift/reset amb, pluggable collect/first-of strategies, row-by-row search (including n-queens and disconnected figures), plus constructive Lemma 1 composition and transversal peeling for large widths without exhaustive search.

The IronKernel.Amb package generalizes the example’s amb layer (amb, require, fail, amb-bracket/amb-bracket-range, emit, collect/first-of/count-of/search) with test/amb_test.ikr (unit checks and a short n-queens integration). Examples/README.md and the root README.md index the new examples and document lib/ and this package.

Reviewed by Cursor Bugbot for commit edc4851. Bugbot is set up for automated code reviews on this repo. Configure here.

ademar and others added 2 commits July 25, 2026 12:16
Two takes on enumerating figures of constant width on an n x n board, the
problem from https://ademar.name/blog/2009/04/finding-figures-of-constant-wi.html
and Hernandez & Robert, American Mathematical Monthly 112 (2005) 42-50.

constant-width.ikr transcribes the original F# frontier search: per-line
remaining-capacity vectors and a hand-written CPS pipeline. It finds connected
figures only, so it cannot express the width-1 case.

constant-width-amb.ikr reformulates the search. Multi-shot shift/reset carry an
amb layer, so the solver is direct style with no explicit continuation
arguments and the undo of board state lives in the choice point. Search
strategies are vau operatives over an emit sink, so collect and first-of drive
the same solver. Deciding rows in order rather than growing from a seed gives
exact (n,k,w) semantics and admits disconnected figures, which makes n-queens
the w=1 case.

It also implements the paper's algebra -- composition and transversal deletion
over an encapsulated figure type -- which builds width 3, 4, 6 and 8 figures in
milliseconds where search needs weeks.

Counts agree with an independent exhaustive row-by-row search: 92 and 4 for 8-
and 6-queens, and 1, 5, 2, 24, 30 figures of type (4,4,2), (5,4,2), (6,6,2),
(7,6,2) and (8,8,2). Every constructed figure is checked by fig-type, which
shares no code with the searcher or the builders.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
First package under lib/, extracted from Examples/constant-width-amb.ikr.
An ordinary .ikproj built with ik test / ik pack; sources land at
ironkernel/src/ in the nupkg.

Choice points are ordinary expressions built on multi-shot, re-delimiting
shift/reset: amb, amb-range, require and fail. Search strategies are vau
operatives over an emit sink -- collect, first-of, count-of, and search for
callers supplying their own handler -- so the code doing the searching never
names a continuation and does not change when the strategy does.

amb-bracket and amb-bracket-range cover searches over mutable state. Undo
cannot sit at the call site, because by the time a choice expression returns
the rest of the search has already run inside the continuation; entering and
leaving therefore bracket the continuation from within the choice point.

The library performs no host I/O. Tests cover the choice points, the
strategies, nesting, state restoration, and n-queens as an integration case.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 25, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_95abe95d-3601-4242-ab49-52196f33b615)

@ademar
ademar merged commit 3bc0a66 into master Jul 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant