Skip to content

Commit 9104073

Browse files
authored
Enrich paper with examples, figures, and algorithm citations (#111)
* update paper writing * update * update * update writing
1 parent 1901a5f commit 9104073

9 files changed

Lines changed: 1288 additions & 156 deletions

File tree

.claude/CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Rust library for NP-hard problem reductions. Implements computational problems w
99
- [add-rule](skills/add-rule/SKILL.md) -- Add a new reduction rule. Can be used standalone (brainstorms with user) or called from `issue-to-pr`.
1010
- [review-implementation](skills/review-implementation/SKILL.md) -- Review implementation completeness by dispatching parallel subagents (structural + quality) with fresh context. Auto-detects new models/rules from git diff. Called automatically at the end of `add-model`/`add-rule`, after each `executing-plans` batch, or standalone via `/review-implementation`.
1111
- [fix-pr](skills/fix-pr/SKILL.md) -- Resolve PR review comments (user + Copilot), fix CI failures, and address codecov coverage gaps. Uses `gh api` for codecov (not local `cargo-llvm-cov`).
12+
- [write-model-in-paper](skills/write-model-in-paper/SKILL.md) -- Write or improve a problem-def entry in the Typst paper. Covers formal definition, background, example with visualization, and algorithm list.
13+
- [write-rule-in-paper](skills/write-rule-in-paper/SKILL.md) -- Write or improve a reduction-rule entry in the Typst paper. Covers complexity citation, self-contained proof, detailed example, and verification.
1214
- [release](skills/release/SKILL.md) -- Create a new crate release. Determines version bump from diff, verifies tests/clippy, then runs `make release`.
1315

1416
## Commands

.claude/skills/add-model/SKILL.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ Link the test file via `#[cfg(test)] #[path = "..."] mod tests;` at the bottom o
120120

121121
## Step 6: Document in paper
122122

123-
Update `docs/paper/reductions.typ`:
124-
- Add to the `display-name` dictionary: `"ProblemName": [Display Name],`
125-
- Add a `#problem-def("ProblemName")[...]` block with the mathematical definition
123+
Invoke the `/write-model-in-paper` skill to write the problem-def entry in `docs/paper/reductions.typ`. That skill covers the full authoring process: formal definition, background, example with visualization, algorithm list, and verification checklist.
126124

127125
## Step 7: Verify
128126

.claude/skills/add-rule/SKILL.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,7 @@ example_fn!(test_<source>_to_<target>, reduction_<source>_to_<target>);
129129

130130
## Step 5: Document in paper
131131

132-
Update `docs/paper/reductions.typ`:
133-
134-
```typst
135-
#reduction-rule("Source", "Target",
136-
example: true,
137-
example-caption: [Caption text],
138-
)[
139-
Reduction rule statement...
140-
][
141-
Proof sketch...
142-
]
143-
```
144-
145-
Present the example in tutorial style with clear intuition. Reference the KColoring -> QUBO section for style guidance.
132+
Invoke the `/write-rule-in-paper` skill to write the reduction-rule entry in `docs/paper/reductions.typ`. That skill covers the full authoring process: complexity citation, self-contained proof, detailed worked example, and verification checklist.
146133

147134
## Step 6: Regenerate graph and verify
148135

.claude/skills/fix-pr/SKILL.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ Three sources of feedback to check:
2323

2424
```bash
2525
# Copilot and user inline review comments (on code lines)
26-
gh api repos/{owner}/{repo}/pulls/$PR/comments --jq '.[] | "[\(.user.login)] \(.path):\(.line // .original_line) — \(.body)"'
26+
gh api repos/{owner}/{repo}/pulls/$PR/comments --jq '.[] | "[" + .user.login + "] " + .path + ":" + ((.line // .original_line) | tostring) + " — " + .body'
2727

2828
# Review-level comments (top-level review body)
29-
gh api repos/{owner}/{repo}/pulls/$PR/reviews --jq '.[] | select(.body != "") | "[\(.user.login)] \(.state): \(.body)"'
29+
gh api repos/{owner}/{repo}/pulls/$PR/reviews --jq '.[] | select(.body != "") | "[" + .user.login + "] " + .state + ": " + .body'
3030

3131
# Issue-level comments (general discussion)
32-
gh api repos/{owner}/{repo}/issues/$PR/comments --jq '.[] | select(.user.login | test("codecov|copilot") | not) | "[\(.user.login)] \(.body)"'
32+
gh api repos/{owner}/{repo}/issues/$PR/comments --jq '.[] | select(.user.login | test("codecov|copilot") | not) | "[" + .user.login + "] " + .body'
3333
```
3434

3535
### 1b. Check CI Status
3636

3737
```bash
3838
# All check runs on the PR head
3939
gh api repos/{owner}/{repo}/commits/$HEAD_SHA/check-runs \
40-
--jq '.check_runs[] | "\(.name): \(.conclusion // .status)"'
40+
--jq '.check_runs[] | .name + ": " + (.conclusion // .status)'
4141
```
4242

4343
### 1c. Check Codecov Report
@@ -104,7 +104,7 @@ For detailed line-by-line coverage, use the Codecov API:
104104
# Get file-level coverage for the PR
105105
gh api repos/{owner}/{repo}/pulls/$PR/comments \
106106
--jq '.[] | select(.user.login == "codecov[bot]") | .body' \
107-
| grep -oP 'filepath=\K[^&]+'
107+
| sed -n 's/.*filepath=\([^&]*\).*/\1/p'
108108
```
109109

110110
Then read the source files and identify which new/changed lines lack test coverage.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
name: write-model-in-paper
3+
description: Use when writing or improving a problem-def entry in the Typst paper (docs/paper/reductions.typ)
4+
---
5+
6+
# Write Problem Model in Paper
7+
8+
Full authoring guide for writing a `problem-def` entry in `docs/paper/reductions.typ`. Covers formal definition, background, examples with visualization, and verification.
9+
10+
## Prerequisites
11+
12+
Before using this skill, ensure:
13+
- The problem model is implemented (`src/models/<category>/<name>.rs`)
14+
- The problem is registered with schema and variant metadata
15+
- JSON exports are up to date (`make rust-export && make export-schemas`)
16+
17+
## Reference Example
18+
19+
**MaximumIndependentSet** in `docs/paper/reductions.typ` is the gold-standard model example. Search for `problem-def("MaximumIndependentSet")` to see the complete entry. Use it as a template for style, depth, and structure.
20+
21+
## The `problem-def` Function
22+
23+
```typst
24+
#problem-def("ProblemName")[
25+
Formal definition... // parameter 1: def
26+
][
27+
Background, example, figure... // parameter 2: body
28+
]
29+
```
30+
31+
**Three parameters:**
32+
- `name` (string) — problem name matching `display-name` dictionary key
33+
- `def` (content) — formal mathematical definition
34+
- `body` (content) — background, examples, figures, algorithm list
35+
36+
**Auto-generated between `def` and `body`:**
37+
- Variant complexity table (from Rust `declare_variants!` metadata)
38+
- Reduction links (from reduction graph JSON)
39+
- Schema field table (from problem schema JSON)
40+
41+
## Step 1: Register Display Name
42+
43+
Add to the `display-name` dictionary near the top of `reductions.typ`:
44+
45+
```typst
46+
"ProblemName": [Display Name],
47+
```
48+
49+
## Step 2: Write the Formal Definition (`def` parameter)
50+
51+
One self-contained sentence or short paragraph. Requirements:
52+
53+
1. **Introduce all inputs first** — graph, weights, sets, variables with their domains
54+
2. **State the objective or constraint** — what is being optimized or satisfied
55+
3. **Define all notation before use** — every symbol must be introduced before it appears
56+
57+
### Pattern for optimization problems
58+
59+
```typst
60+
Given [inputs with domains], find [solution variable] [maximizing/minimizing] [objective] such that [constraints].
61+
```
62+
63+
### Pattern for satisfaction problems
64+
65+
```typst
66+
Given [inputs with domains], find [solution variable] such that [constraints].
67+
```
68+
69+
### Example (MIS)
70+
71+
```typst
72+
Given $G = (V, E)$ with vertex weights $w: V -> RR$, find $S subset.eq V$
73+
maximizing $sum_(v in S) w(v)$ such that no two vertices in $S$ are
74+
adjacent: $forall u, v in S: (u, v) in.not E$.
75+
```
76+
77+
## Step 3: Write the Body
78+
79+
The body goes AFTER the auto-generated sections (complexity, reductions, schema). It contains four parts in order:
80+
81+
### 3a. Background & Motivation
82+
83+
1-3 sentences covering:
84+
- Historical context (e.g., "One of Karp's 21 NP-complete problems")
85+
- Applications (e.g., "appears in wireless network scheduling, register allocation")
86+
- Notable structural properties (e.g., "Solvable in polynomial time on bipartite graphs, interval graphs, chordal graphs")
87+
88+
If the user provides specific justification or motivation, incorporate it here.
89+
90+
### 3b. Best Known Algorithms
91+
92+
Must clearly state which algorithm gives the best complexity and cite reference. Add a warning as footnote if no reliable reference is found.
93+
94+
Integrate algorithm complexity naturally into the background prose — do NOT append a terse "Best known: $O^*(...)$" at the end:
95+
96+
```typst
97+
% Good: names the algorithm, cites reference
98+
The best known algorithm runs in $O^*(1.1996^n)$ time via measure-and-conquer
99+
branching @xiao2017.
100+
101+
% Good: brute-force with footnote when no better algorithm is known
102+
The best known algorithm runs in $O^*(2^n)$ by brute-force
103+
enumeration#footnote[No algorithm improving on brute-force is known for ...].
104+
105+
% Bad: terse appendage, no algorithm name, no reference
106+
Best known: $O^*(2^n)$.
107+
```
108+
109+
For problems with multiple notable algorithms or special cases, weave them into the text:
110+
```typst
111+
Solvable in $O(n+m)$ for $k=2$ via bipartiteness testing. For $k=3$, the best
112+
known algorithm runs in $O^*(1.3289^n)$ @beigel2005; in general, inclusion-exclusion
113+
achieves $O^*(2^n)$ @bjorklund2009.
114+
```
115+
116+
**Citation rules:**
117+
- Every complexity claim MUST have a citation (`@key`) identifying the algorithm
118+
- If the best known is brute-force enumeration with no specialized algorithm, add footnote: `#footnote[No algorithm improving on brute-force enumeration is known for ...]`
119+
- If a reference exists but has not been independently verified, add footnote: `#footnote[Complexity not independently verified from literature.]`
120+
- Include approximation results where relevant (e.g., "0.878-approximation @goemans1995")
121+
122+
**Consistency note:** The auto-generated complexity table (from `declare_variants!`) also shows complexity per variant. The written text and the auto-generated table may overlap. Keep both — the written text provides references and context; the auto-generated table provides per-variant detail. A future verification step will check consistency between them.
123+
124+
### 3c. Example with Visualization
125+
126+
A concrete small instance that illustrates the problem. Requirements:
127+
128+
1. **Small enough to verify by hand** — readers should be able to check the solution
129+
2. **Include a diagram/graph** using the paper's visualization helpers
130+
3. **Show a valid/optimal solution** and explain why it is valid/optimal
131+
4. **Walk through evaluation** — show how the objective/verifier computes the solution value
132+
133+
Structure:
134+
135+
```typst
136+
*Example.* Consider [instance description with concrete numbers].
137+
[Describe the solution and why it's valid/optimal].
138+
139+
#figure({
140+
// visualization code — see MaximumIndependentSet for graph rendering pattern
141+
},
142+
caption: [Caption describing the figure with key parameters],
143+
) <fig:problem-example>
144+
```
145+
146+
**For graph problems**, use the paper's existing graph helpers:
147+
- `petersen-graph()`, `house-graph()` or define custom vertex/edge lists
148+
- `canvas(length: ..., { ... })` with `g-node()` and `g-edge()`
149+
- Highlight solution elements with `graph-colors.at(0)` (blue) and use `white` fill for non-solution
150+
151+
Refer to the **MaximumIndependentSet** entry for the complete graph rendering pattern. Adapt it to your problem.
152+
153+
### 3d. Evaluation Explanation
154+
155+
Explain how a configuration is evaluated — this maps to the Rust `evaluate()` method:
156+
- For optimization: show the cost function computation on the example solution
157+
- For satisfaction: show the verifier check on the example solution
158+
159+
This can be woven into the example text (as MIS does: "$w(S) = sum_(v in S) w(v) = 4 = alpha(G)$").
160+
161+
## Step 4: Build and Verify
162+
163+
```bash
164+
# Regenerate exports (if not already done)
165+
make rust-export && make export-schemas
166+
167+
# Build the paper
168+
make paper
169+
```
170+
171+
### Verification Checklist
172+
173+
- [ ] **Display name registered**: entry exists in `display-name` dictionary
174+
- [ ] **Notation self-contained**: every symbol in `def` is defined before first use
175+
- [ ] **Background present**: historical context, applications, or structural properties
176+
- [ ] **Algorithms cited**: every complexity claim has `@citation` or footnote warning
177+
- [ ] **Example present**: concrete small instance with visualization
178+
- [ ] **Evaluation shown**: objective/verifier computed on the example solution
179+
- [ ] **Diagram included**: figure with caption and label for graph/matrix/set visualization
180+
- [ ] **Paper compiles**: `make paper` succeeds without errors
181+
- [ ] **Complexity consistency**: written complexity and auto-generated variant table are compatible (note any discrepancies for later review)

0 commit comments

Comments
 (0)