Constant width examples and amb library - #17
Merged
Conversation
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>
Bugbot couldn't run - usage limit reachedBugbot 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Need help on this PR? Tag
@codesmith-botwith 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 packageIronKernel.Amb.constant-width.ikris a CPS backtracking port of the connected-figure search (CLIn k w, defaults5 4 2).constant-width-amb.ikrsolves the same problem in direct style with inlineshift/resetamb, pluggablecollect/first-ofstrategies, 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.Ambpackage generalizes the example’samblayer (amb,require,fail,amb-bracket/amb-bracket-range,emit,collect/first-of/count-of/search) withtest/amb_test.ikr(unit checks and a short n-queens integration).Examples/README.mdand the rootREADME.mdindex the new examples and documentlib/and this package.Reviewed by Cursor Bugbot for commit edc4851. Bugbot is set up for automated code reviews on this repo. Configure here.