Skip to content

Commit c400651

Browse files
GiggleLiuclaude
andauthored
docs: replace Rust code with JSON schema tables in paper (#38)
* docs: replace Rust code with JSON schema tables in reductions.typ 1. Replace render-struct (Rust code blocks) with render-schema (JSON field tables from problem_schemas.json) — more useful for interop users. 2. Classify reduction references as "Reduces to" / "Reduces from" instead of flat "Implemented reductions" lists. 3. Remove all Rust code blocks and "See ... .rs" links from the paper. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * update * refactor: add reduction-rule function for unified theorem rendering Add `reduction-rule(source, target, ...)` Typst function that: - Auto-generates theorem labels (<thm:source-to-target>) - Auto-generates bold header (Source → Target) with display names - Auto-generates [Problems: Definition X, Definition Y] links - Renders proof and optional example with custom extra content - Supports bidirectional (↔), display name overrides Converts all 28 reduction theorems to use the new function, eliminating repeated boilerplate (manual labels, problem links, header formatting). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: correct overhead formulas and add Display for polynomials - Fix Monomial/Polynomial Display to use `*` between terms - Add num_literals to Satisfiability::problem_size() - Fix 6 incorrect overhead polynomials: SAT→DS, SAT→IS, SAT→Coloring, SAT→kSAT, Factoring→Circuit, Coloring→QUBO - Add poly!(a * b) macro variant for variable products - Export overhead data in reduction_graph.json - Simplify coloring_ilp.rs to use poly! macro Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: show reduction overhead in theorem statements Add auto-generated overhead line to each reduction theorem by looking up the edge data from reduction_graph.json. Format: field = formula pairs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add edge click and hover handlers to mdBook reduction graph - Add edge hover tooltip showing source→target and overhead formulas - Add edge click handler to highlight edge and show overhead info - Add cursor:pointer to edges for visual feedback - Sync reduction_graph.json with overhead data Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * save * refactor: rename 7 problem types with Maximum/Minimum prefix, improve paper and perf Problem type renames for clarity: - Clique → MaximumClique - IndependentSet → MaximumIndependentSet - Matching → MaximumMatching - VertexCovering → MinimumVertexCover - DominatingSet → MinimumDominatingSet - SetPacking → MaximumSetPacking - SetCovering → MinimumSetCovering Renamed all source files, test files, rule files, example files, and test data across 118 files. Updated all references in code, docs, benchmarks, and the Typst paper. Typst paper improvements: - Removed name-abbrev and def-label-map dictionaries; use full names - Added problem-def() wrapper for programmatic definition labels - Added completeness warnings for missing models/rules vs JSON graph - Made reduction-rule use context+query for resilient label references - Swapped MVC↔MIS and MSP↔MIS theorem directions to match JSON edges - Deleted redundant examples/qubo_reductions.rs (already split) Performance: - Added Auto variant to PathDecompositionMethod (now default) - Auto uses exact branch-and-bound for ≤30 vertices, greedy for larger - Fixes slow unit disk mapping tests on larger graphs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add edge doc links and compound variant nodes to reduction graph Edge documentation: - Add module_path field to ReductionEntry, populated via module_path!() in the proc macro and 3 manual inventory::submit! calls - Add doc_path to EdgeJson, computed from module_path - Add edge double-click handler to navigate to reduction module rustdoc Compound variant nodes: - Replace base-node-only filtering with compound parent + variant children - Parent nodes show problem name with dashed border, children show variant (Unweighted/Weighted/etc.) - Edges connect variant nodes directly, preserving full reduction detail - Update all event handlers (tooltip, path selection, edge click) Also fix problem-def Typst function to accept (name, title, body) matching all 16 call sites, and update CLAUDE.md/rules documentation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: use flat nodes with variant placement in reduction graph Replace compound node grouping with flat nodes where variant nodes are placed physically near their parent problem. Base variants sit at the cose-computed position labeled with the problem name; non-base variants are offset below labeled like "ProblemName (Weighted)". Edge double-click now navigates to GitHub source. Also: remove mermaid dependency, enable previously ignored tests, simplify paper problem-def signatures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: add design plan for improving example instances Replace trivial P4/K3/C4 instances across 30 examples with Petersen graph (canonical), Octahedron (clique), random 3-SAT(5,7), and other non-trivial instances sized 6-10 variables. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: add implementation plan for improving example instances 13 tasks covering all 30 example files: Petersen graph for graph problems, octahedron for clique, 5-var 3-SAT, Petersen SpinGlass, full adder circuit, 6-var knapsack ILP, and factor 35=5x7. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: use lower(ProblemName) convention for all example filenames Rename example files to strictly follow lower(ProblemName) convention (sat→satisfiability, circuit→circuitsat, coloring→kcoloring). Replace hardcoded write_example names with env!("CARGO_BIN_NAME") and auto-derive Typst example references from source/target. Also fix PR review comments: doubled words, stale headers, coverage gaps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: remove unused import in polynomial tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d6e82e3 commit c400651

151 files changed

Lines changed: 3972 additions & 2625 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/CLAUDE.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ make mdbook # Build and serve mdBook with live reload
1616
make paper # Build Typst paper (runs examples + exports first)
1717
make coverage # Generate coverage report (>95% required)
1818
make check # Quick pre-commit check (fmt + clippy + test)
19-
make export-graph # Regenerate reduction graph JSON
19+
make rust-export # Generate Rust mapping JSON exports
2020
make export-schemas # Regenerate problem schemas JSON
2121
make qubo-testdata # Regenerate QUBO ground truth JSON
2222
make clean # Clean build artifacts
2323
```
2424

2525
## Verify Changes
2626
```bash
27-
make test clippy export-graph # Must pass before PR
27+
make test clippy # Must pass before PR
2828
```
2929

3030
## Architecture
@@ -47,7 +47,7 @@ make test clippy export-graph # Must pass before PR
4747
```
4848
Problem (core trait - all problems must implement)
4949
50-
├── const NAME: &'static str // Problem name, e.g., "IndependentSet"
50+
├── const NAME: &'static str // Problem name, e.g., "MaximumIndependentSet"
5151
├── type GraphType: GraphMarker // Graph topology marker
5252
├── type Weight: NumericWeight // Weight type (i32, f64, Unweighted)
5353
├── type Size // Objective value type
@@ -75,20 +75,33 @@ ConstraintSatisfactionProblem : Problem (extension for CSPs)
7575
- Graph types: SimpleGraph, GridGraph, UnitDiskGraph, Hypergraph
7676
- Weight types: `Unweighted` (marker), `i32`, `f64`
7777

78+
### Problem Names
79+
Problem types use explicit optimization prefixes:
80+
- `MaximumIndependentSet`, `MaximumClique`, `MaximumMatching`, `MaximumSetPacking`
81+
- `MinimumVertexCover`, `MinimumDominatingSet`, `MinimumSetCovering`
82+
- No prefix: `MaxCut`, `SpinGlass`, `QUBO`, `ILP`, `Satisfiability`, `KSatisfiability`, `CircuitSAT`, `Factoring`, `MaximalIS`
83+
7884
### Problem Variant IDs
7985
Reduction graph nodes use variant IDs: `ProblemName[/GraphType][/Weighted]`
80-
- Base: `IndependentSet` (SimpleGraph, unweighted)
81-
- Graph variant: `IndependentSet/GridGraph`
82-
- Weighted variant: `IndependentSet/Weighted`
83-
- Both: `IndependentSet/GridGraph/Weighted`
86+
- Base: `MaximumIndependentSet` (SimpleGraph, unweighted)
87+
- Graph variant: `MaximumIndependentSet/GridGraph`
88+
- Weighted variant: `MaximumIndependentSet/Weighted`
89+
- Both: `MaximumIndependentSet/GridGraph/Weighted`
8490

8591
## Conventions
8692

8793
### File Naming
88-
- Reduction files: `src/rules/<source>_<target>.rs`
89-
- Model files: `src/models/<category>/<name>.rs`
94+
- Reduction files: `src/rules/<source>_<target>.rs` (e.g., `maximumindependentset_qubo.rs`)
95+
- Model files: `src/models/<category>/<name>.rs` (e.g., `maximum_independent_set.rs`)
96+
- Example files: `examples/reduction_<source>_to_<target>.rs`
9097
- Test naming: `test_<source>_to_<target>_closed_loop`
9198

99+
### Paper (docs/paper/reductions.typ)
100+
- `problem-def(name, title, body)` — defines a problem with auto-generated schema, reductions list, and label `<def:ProblemName>`
101+
- `reduction-rule(source, target, ...)` — generates a theorem with label `<thm:Source-to-Target>` and registers in `covered-rules` state
102+
- Completeness warnings auto-check that all JSON graph nodes/edges are covered in the paper
103+
- `display-name` dict maps `ProblemName` to display text
104+
92105
## Contributing
93106
See `.claude/rules/` for detailed guides:
94107
- `adding-reductions.md` - How to add reduction rules

.claude/rules/adding-models.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub use my_problem::MyProblem;
3636

3737
## 3. Categories
3838
Place models in appropriate category:
39-
- `src/models/satisfiability/` - SAT, K-SAT, CircuitSAT
40-
- `src/models/graph/` - IndependentSet, VertexCovering, Coloring, etc.
41-
- `src/models/set/` - SetCovering, SetPacking
39+
- `src/models/satisfiability/` - Satisfiability, KSatisfiability, CircuitSAT
40+
- `src/models/graph/` - MaximumIndependentSet, MinimumVertexCover, KColoring, etc.
41+
- `src/models/set/` - MinimumSetCovering, MaximumSetPacking
4242
- `src/models/optimization/` - SpinGlass, QUBO, ILP
4343

4444
## 4. Required Traits
@@ -47,8 +47,11 @@ Place models in appropriate category:
4747
- `Problem` - Core trait with `num_variables()`, `problem_size()`, `is_valid_solution()`
4848
- Consider `ConstraintSatisfactionProblem` if applicable
4949

50-
## 5. Documentation
51-
Document in `docs/paper/reductions.typ`
50+
## 5. Naming
51+
Use explicit optimization prefixes: `Maximum` for maximization, `Minimum` for minimization (e.g., `MaximumIndependentSet`, `MinimumVertexCover`).
52+
53+
## 6. Documentation
54+
Document in `docs/paper/reductions.typ` using `#problem-def("ProblemName", "Display Title")[...]`
5255

5356
## Anti-patterns
5457
- Don't create models without JSON serialization support

.claude/rules/adding-reductions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Before writing any Rust code, follow this workflow:
2020
# Example: generate QUBO test data
2121
cd scripts && uv run python generate_qubo_tests.py
2222
```
23-
3. **Create a practical example** — design a small, explainable instance for `examples/` (e.g., "wireless tower placement" for IndependentSet, "map coloring" for Coloring). This example will also appear in the `docs/paper/reductions.typ`.
23+
3. **Create a practical example** — design a small, explainable instance for `examples/` (e.g., "wireless tower placement" for MaximumIndependentSet, "map coloring" for KColoring). This example will also appear in the `docs/paper/reductions.typ`.
2424
4. **Write the implementation plan** — save to `docs/plans/` using `superpowers:writing-plans`. The plan must include implementation details from the brainstorming session (formulas, penalty terms, matrix construction, variable indexing).
2525

2626
## 1. Implementation
@@ -84,9 +84,9 @@ Add a round-trip demo to `examples/` showing a practical, explainable instance:
8484
## 4. Documentation
8585

8686
Update `docs/paper/reductions.typ` (see `rules/documentation.md` for the pattern):
87-
- Add theorem + proof sketch
87+
- Add `reduction-rule("Source", "Target", ...)` theorem with proof sketch
8888
- Add Rust code example from the example program
89-
- Add to summary table with overhead and citation
89+
- Add `display-name` entry if the problem is new
9090

9191
The goal is to 1. prove the correctness of the reduction to human beings. 2. provide a minimal working example to the readers.
9292

.claude/rules/documentation.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,48 @@ paths:
77

88
The technical paper (`docs/paper/reductions.typ`) must include:
99

10-
1. **Table of Contents** - Auto-generated outline of all sections
11-
2. **Problem Data Structures** - Rust struct with fields in a code block
12-
3. **Reduction Examples** - Minimal working example showing reduce → solve → extract
10+
1. **Problem Definitions** — using `problem-def` wrapper
11+
2. **Reduction Theorems** — using `reduction-rule` function
12+
3. **Reduction Examples** — minimal working example showing reduce → solve → extract
1313

14-
## Pattern
14+
## Adding a Problem Definition
1515

1616
```typst
17-
#definition("Problem Name")[
17+
#problem-def("MaximumIndependentSet", "Maximum Independent Set (MIS)")[
1818
Mathematical definition...
1919
]
20+
```
2021

21-
// Rust data structure
22-
```rust
23-
pub struct ProblemName<W = i32> {
24-
field1: Type1,
25-
field2: Type2,
26-
}
27-
`` `
22+
This auto-generates:
23+
- A label `<def:MaximumIndependentSet>` for cross-references
24+
- The problem's schema (fields from Rust struct)
25+
- The list of available reductions
2826

29-
#theorem[
30-
*(Source → Target)* Reduction description...
31-
]
27+
Also add an entry to the `display-name` dictionary:
28+
```typst
29+
"MaximumIndependentSet": "MIS",
30+
```
31+
32+
## Adding a Reduction Theorem
3233

33-
// Minimal working example from closed-loop tests
34-
```rust
35-
let source = SourceProblem::new(...);
36-
let reduction = ReduceTo::<TargetProblem>::reduce_to(&source);
37-
let target = reduction.target_problem();
38-
// ... solve and extract
39-
`` `
34+
```typst
35+
#reduction-rule(
36+
"MaximumIndependentSet", "QUBO",
37+
example: "maximumindependentset_to_qubo",
38+
overhead: (n: 0, m: 1),
39+
)[
40+
Proof sketch...
41+
]
4042
```
43+
44+
This auto-generates:
45+
- A theorem label `<thm:MaximumIndependentSet-to-QUBO>`
46+
- References to source/target problem definitions (if they exist)
47+
- Registration in `covered-rules` state for completeness checking
48+
- The example code block from `examples/reduction_<example>.rs`
49+
50+
## Completeness Warnings
51+
52+
The paper auto-checks completeness:
53+
- After Problem Definitions: warns if JSON graph nodes are missing from `display-name`
54+
- After Reductions section: warns if JSON graph edges are missing from `covered-rules`

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ doc:
5151
rm -rf docs/book/api
5252
cp -r target/doc docs/book/api
5353

54-
# Build and serve mdBook with live reload
54+
# Build and serve mdBook with API docs
5555
mdbook:
5656
cargo run --example export_graph
5757
cp docs/paper/reduction_graph.json docs/src/reductions/
5858
cargo doc --all-features --no-deps
59-
rm -rf docs/book/api
60-
cp -r target/doc docs/book/api
61-
mdbook serve docs --open
59+
mdbook build
60+
rm -rf book/api
61+
cp -r target/doc book/api
62+
@-fuser -k 3001/tcp 2>/dev/null || true
63+
@echo "Serving at http://localhost:3001"
64+
python3 -m http.server 3001 -d book &
65+
@sleep 1 && xdg-open http://localhost:3001
6266

6367
# Generate all example JSON files for the paper
6468
REDUCTION_EXAMPLES := $(patsubst examples/%.rs,%,$(wildcard examples/reduction_*.rs))

benches/solver_benchmarks.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use problemreductions::models::set::*;
99
use problemreductions::models::specialized::*;
1010
use problemreductions::prelude::*;
1111

12-
/// Benchmark IndependentSet on graphs of varying sizes.
12+
/// Benchmark MaximumIndependentSet on graphs of varying sizes.
1313
fn bench_independent_set(c: &mut Criterion) {
14-
let mut group = c.benchmark_group("IndependentSet");
14+
let mut group = c.benchmark_group("MaximumIndependentSet");
1515

1616
for n in [4, 6, 8, 10].iter() {
1717
// Create a path graph with n vertices
1818
let edges: Vec<(usize, usize)> = (0..*n - 1).map(|i| (i, i + 1)).collect();
19-
let problem = IndependentSet::<SimpleGraph, i32>::new(*n, edges);
19+
let problem = MaximumIndependentSet::<SimpleGraph, i32>::new(*n, edges);
2020
let solver = BruteForce::new();
2121

2222
group.bench_with_input(BenchmarkId::new("path", n), n, |b, _| {
@@ -27,13 +27,13 @@ fn bench_independent_set(c: &mut Criterion) {
2727
group.finish();
2828
}
2929

30-
/// Benchmark VertexCovering on graphs of varying sizes.
30+
/// Benchmark MinimumVertexCover on graphs of varying sizes.
3131
fn bench_vertex_covering(c: &mut Criterion) {
32-
let mut group = c.benchmark_group("VertexCovering");
32+
let mut group = c.benchmark_group("MinimumVertexCover");
3333

3434
for n in [4, 6, 8, 10].iter() {
3535
let edges: Vec<(usize, usize)> = (0..*n - 1).map(|i| (i, i + 1)).collect();
36-
let problem = VertexCovering::<SimpleGraph, i32>::new(*n, edges);
36+
let problem = MinimumVertexCover::<SimpleGraph, i32>::new(*n, edges);
3737
let solver = BruteForce::new();
3838

3939
group.bench_with_input(BenchmarkId::new("path", n), n, |b, _| {
@@ -109,16 +109,16 @@ fn bench_spin_glass(c: &mut Criterion) {
109109
group.finish();
110110
}
111111

112-
/// Benchmark SetCovering on varying sizes.
112+
/// Benchmark MinimumSetCovering on varying sizes.
113113
fn bench_set_covering(c: &mut Criterion) {
114-
let mut group = c.benchmark_group("SetCovering");
114+
let mut group = c.benchmark_group("MinimumSetCovering");
115115

116116
for num_sets in [4, 6, 8, 10].iter() {
117117
// Create overlapping sets
118118
let sets: Vec<Vec<usize>> = (0..*num_sets)
119119
.map(|i| vec![i, (i + 1) % *num_sets, (i + 2) % *num_sets])
120120
.collect();
121-
let problem = SetCovering::<i32>::new(*num_sets, sets);
121+
let problem = MinimumSetCovering::<i32>::new(*num_sets, sets);
122122
let solver = BruteForce::new();
123123

124124
group.bench_with_input(
@@ -154,7 +154,7 @@ fn bench_matching(c: &mut Criterion) {
154154

155155
for n in [4, 6, 8, 10].iter() {
156156
let edges: Vec<(usize, usize, i32)> = (0..*n - 1).map(|i| (i, i + 1, 1)).collect();
157-
let problem = Matching::new(*n, edges);
157+
let problem = MaximumMatching::new(*n, edges);
158158
let solver = BruteForce::new();
159159

160160
group.bench_with_input(BenchmarkId::new("path", n), n, |b, _| {
@@ -192,9 +192,9 @@ fn bench_comparison(c: &mut Criterion) {
192192

193193
let solver = BruteForce::new();
194194

195-
// IndependentSet with 8 vertices
196-
let is_problem = IndependentSet::<SimpleGraph, i32>::new(8, vec![(0, 1), (2, 3), (4, 5), (6, 7)]);
197-
group.bench_function("IndependentSet", |b| {
195+
// MaximumIndependentSet with 8 vertices
196+
let is_problem = MaximumIndependentSet::<SimpleGraph, i32>::new(8, vec![(0, 1), (2, 3), (4, 5), (6, 7)]);
197+
group.bench_function("MaximumIndependentSet", |b| {
198198
b.iter(|| solver.find_best(black_box(&is_problem)))
199199
});
200200

book.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ description = "A Rust library for reducing NP-hard problems"
55
language = "en"
66
src = "docs/src"
77

8-
[preprocessor.mermaid]
9-
command = "mdbook-mermaid"
10-
118
[output.html]
12-
default-theme = "rust"
9+
default-theme = "navy"
1310
git-repository-url = "https://github.com/CodingThrust/problem-reductions"
1411
edit-url-template = "https://github.com/CodingThrust/problem-reductions/edit/main/{path}"
1512
additional-css = []

0 commit comments

Comments
 (0)