> For AI agents: the complete documentation index is available at /Prism/llms.txt, the full documentation bundle is available at /Prism/llms-full.txt.

# Math & Table Audit + One-Click Toy Reproduction Lab (`.ipynb`)

Reading quantitative papers critically means never taking headline numbers or equations on faith. Prism combines two tight, verifiable workflows right inside your Zotero chat sidebar:

1. **`/audit-numbers` — Math & Table Audit:** Audits reported table averages, relative vs. absolute percentage gains, dataset split totals (`train + val + test = N`), and rates/proportions using provider **Code Execution** (when permitted) plus Prism's **deterministic local arithmetic verifier**, outputting a filterable **Quantitative Audit Card** with clickable **`[p. N]`** PDF jump chips.
2. **`/toy-repro` — One-Click Toy Reproduction Lab (`.ipynb`):** Synthesizes a strictly valid `nbformat: 4` **Jupyter Notebook (`.ipynb`)** implementing the paper's core equation, loss function, or algorithm on deterministic synthetic data, automatically test-running it inside Code Execution when available, capturing inline sanity-check plots, and attaching it to Zotero atomically (`Preview → Approve → Commit` + Undo).

:::tip Privacy-First & Fail-Closed Guardrail
When a paper matches your **Local-Only Privacy Guardrail** (e.g., `unpublished`, `confidential`, or a protected collection), Prism blocks cloud uploads **before** reading the PDF and **explicitly disables cloud Code Execution**. You can retry in 1 click with a local provider (e.g., Ollama) to run Prism's offline deterministic arithmetic verifier and generate self-contained local `.py` / `.ipynb` deliverables without any byte leaving your machine.
:::

## 1. Ways to Launch

| Workflow                            | Entry Points                                                                                                                                                                                                                                                                                                                                                    |
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Math & Table Audit**              | Type **`/audit-numbers`** in the `/` command picker (with an optional focus hint such as `/audit-numbers Focus on Table 3`), open **`⌘K` / `Ctrl+K` Command Palette → Math & Table Audit**, or right-click a paper in Zotero Library → **`Prism Actions ▸ Audit Paper Math & Tables`**                                                                          |
| **Toy Reproduction Lab (`.ipynb`)** | Type **`/toy-repro`** in the `/` command picker (e.g., `/toy-repro Implement Eq. (4) KL-regularized loss`), open **`⌘K` / `Ctrl+K` Command Palette → Toy Reproduction Lab (.ipynb)**, right-click a paper → **`Prism Actions ▸ Toy Reproduction Lab (.ipynb)`**, or click **`Toy Repro (.ipynb)`** directly from any **X-Ray Lens Card** or **Math Audit Card** |

## 2. Quantitative Math & Table Audit (`/audit-numbers`)

Prism prioritizes quantitative PDF pages (tables, results, datasets, and equations) and verifies claims through two complementary layers:

- **Cloud Code Execution Sandbox (when available & permitted):** On OpenAI (`code_interpreter`), Anthropic Claude (`code_execution`), and Google Gemini (`code_execution`) models, Prism instructs the sandbox to execute a Python verification script and captures `stdout`, `stderr`, and exit status directly.
- **Deterministic Local Arithmetic Cross-Checker (always on):** Every extracted numerical assertion is independently verified in TypeScript with exact floating-point math — even catching arithmetic errors a smaller local LLM might overlook:
  - **Table Column & Row Averages:** Respects published rounding precision (e.g., `±0.05` on 1-decimal tables) while flagging genuine mean mismatches.
  - **Relative vs. Absolute Percentage Gains:** Explicitly catches the classic paper error of claiming e.g. `+4.2% relative gain` on `71.2 → 73.5` when actual relative gain is `+3.23%` (and absolute gain is `+2.3 pts`), or labeling absolute percentage points as relative `%`.
  - **Sample Split Sums:** Verifies `train + val + test == N` and subgroup percentages summing to `100%`.
  - **Proportions, Rates & F1 Scores:** Recomputes `numerator / denominator` against reported percentages or ratios and cross-checks Precision/Recall/F1 harmonic mean (`2PR / (P + R)`).

### Interactive Quantitative Audit Card

Math & Table Audit (/audit-numbers)

![Interactive Quantitative Audit Card displaying Sandbox Verified status, clickable 3-column KPI scoreboard (Discrepancies, Warnings, Verified), adaptive Reported vs. Computed comparison rows, and verified [p. N] PDF jump chips.](/Prism/images/math-audit-card.png)

Interactive Quantitative Audit Card displaying Sandbox Verified status, clickable 3-column KPI scoreboard (Discrepancies, Warnings, Verified), adaptive Reported vs. Computed comparison rows, and verified [p. N] PDF jump chips.

- **Live 5-Stage Progress Indicator:** While auditing, Prism displays an animated 5-stage progress card with an elapsed timer and one-click **Cancel** so you can track PDF context gathering, arithmetic verification, and sandbox execution smoothly.
- **Interactive 3-Column KPI Scoreboard:** Inspect counts for **`Discrepancies`** (red), **`Warnings`** (amber), and **`Verified`** (green) at a glance—click any KPI tile to filter checks immediately (click again to return to **`All`**), or toggle **`Compact passed`** / **`Expand all details`** to focus on flagged anomalies first.
- **Adaptive `Reported → Computed` Comparison Rows:** Compares the paper's claimed figure against the recomputed value, delta summary, formula, and verification source badge (`Sandbox`, `Deterministic`, or `LLM`)—laying out compact numbers side-by-side and automatically stacking longer analytical expressions cleanly without text wrapping glitches.
- **Verified PDF Anchor Telemetry & Jumps:** Displays verified PDF grounding counts (`N/M PDF anchors verified`) and pairs each finding with a clickable **`[p. N]`** badge matched against the paper's real PDF text layer to jump and highlight directly in Zotero Reader.
- **Verification Script, Regenerate Branching & Exports:** Expand the collapsible **Verification Python Script (`.py`)** or **Sandbox stdout/stderr**, re-run via native **Regenerate** branching without losing prior runs, export the full audit to **Markdown (`.md`)** or **Python (`.py`)**, or click **`Toy Repro Lab (.ipynb)`** to jump straight into reproduction.

## 3. One-Click Toy Reproduction Lab (`/toy-repro`)

Turn passive reading of a dense method section or X-Ray'd equation into an executable learning artifact:

1. **Structured Paper-to-Code Synthesis:** Prism generates 4–8 alternating **Markdown cells** (with KaTeX equations and explicit `Eq. (X)` / `Algorithm 1` / `[p. N]` provenance) and self-contained **Python 3 code cells** using only `numpy` and `matplotlib` on fixed-seed synthetic data (`np.random.default_rng(42)`) — zero external dataset downloads, zero CUDA dependencies, and sub-3-second execution.
2. **Automatic Sandbox Validation, Auto-Repair & Embedded Plots:** When running on a cloud provider with native Code Execution (and the paper is not Privacy-Guardrail-protected), Prism automatically runs the generated script in the sandbox (`exit code 0`), applies a single automatic repair pass if any runtime bug occurs, embeds verified `stdout` and generated matplotlib PNG sanity-check plots (`display_data`) directly into the `.ipynb` outputs, and renders those plots inline inside the chat card (click to inspect full-size).
3. **Strict `nbformat: 4` (`.ipynb`) Packaging:** Prism serializes and validates every notebook against the Jupyter `nbformat: 4` (`nbformat_minor: 5`) specification (`kernelspec`, `language_info`, unique cell IDs, `\n`-terminated `source` line arrays, `execution_count`, and `outputs`) so it opens cleanly in **JupyterLab**, **Jupyter Notebook**, **VS Code**, and **Google Colab**.

### Interactive File Card Actions

One-Click Toy Reproduction Lab (/toy-repro .ipynb)

![Toy Reproduction Lab card showing Sandbox Verified · Exit 0 status, nbformat v4 .ipynb file actions (Preview, Save .ipynb, Copy .py, Save to Zotero), inline matplotlib sanity-check plots, and verified sandbox stdout.](/Prism/images/toy-repro-lab.png)

Toy Reproduction Lab card showing Sandbox Verified · Exit 0 status, nbformat v4 .ipynb file actions (Preview, Save .ipynb, Copy .py, Save to Zotero), inline matplotlib sanity-check plots, and verified sandbox stdout.

- **`Preview` (`All Cells` / `Code Only`):** Expand a cell-by-cell Jupyter preview right inside the chat card with an **`All Cells` / `Code Only`** filter bar, rendered KaTeX Markdown, Python code blocks with Jupyter `In [N]` / `Out [N]` sandbox stdout, per-cell copy buttons, and clickable **`[p. N]`** PDF jumps.
- **`Save .ipynb`:** Export the validated `<paper-slug>-toy-repro.ipynb` (including embedded outputs and PNG plots) via Zotero's native save dialog.
- **`Copy .py` / `.py`:** Copy or save a clean `# %%` percent-format Python script runnable directly via `python3` or interactively in VS Code / Spyder.
- **`Save to Zotero` & Native Regenerate:** Stage attaching `<paper-slug>-toy-repro.ipynb` (tagged `Prism Toy Lab`) directly under the active Zotero paper behind Prism's atomic **`Preview → Approve → Commit` + Undo** Approval Card, or click **Regenerate** to iterate on a new branch while preserving prior notebooks.
