rockycode 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rockycode/__init__.py +1 -0
- rockycode/banner.py +37 -0
- rockycode/cli.py +1386 -0
- rockycode/config.py +178 -0
- rockycode/dream/__init__.py +9 -0
- rockycode/dream/core.py +523 -0
- rockycode/dream/judge.py +134 -0
- rockycode/dream/mining.py +152 -0
- rockycode/dream/proposals.py +440 -0
- rockycode/engine/__init__.py +10 -0
- rockycode/engine/artifact.py +367 -0
- rockycode/engine/budget.py +90 -0
- rockycode/engine/checks.py +157 -0
- rockycode/engine/compaction.py +181 -0
- rockycode/engine/container.py +225 -0
- rockycode/engine/effort.py +46 -0
- rockycode/engine/events.py +101 -0
- rockycode/engine/explore.py +592 -0
- rockycode/engine/goal.py +541 -0
- rockycode/engine/goal_review.py +161 -0
- rockycode/engine/goal_session.py +259 -0
- rockycode/engine/headless.py +481 -0
- rockycode/engine/loop.py +711 -0
- rockycode/engine/lsp.py +473 -0
- rockycode/engine/mcp.py +364 -0
- rockycode/engine/modes.py +123 -0
- rockycode/engine/outcome.py +81 -0
- rockycode/engine/permission.py +198 -0
- rockycode/engine/planmode.py +249 -0
- rockycode/engine/providers.py +196 -0
- rockycode/engine/redact.py +83 -0
- rockycode/engine/safety.py +139 -0
- rockycode/engine/sandbox.py +219 -0
- rockycode/engine/server.py +431 -0
- rockycode/engine/skills.py +178 -0
- rockycode/engine/titler.py +46 -0
- rockycode/engine/tools.py +479 -0
- rockycode/engine/trajectory.py +131 -0
- rockycode/engine/web.py +431 -0
- rockycode/engine/worktree.py +128 -0
- rockycode/memory/__init__.py +7 -0
- rockycode/memory/index.py +260 -0
- rockycode/memory/store.py +331 -0
- rockycode/modes/learn/learn.md +46 -0
- rockycode/modes/research/deep-research.md +53 -0
- rockycode/modes/research/paper-reading.md +49 -0
- rockycode/modes/research/prove.md +60 -0
- rockycode/modes/research/whiteboard.md +64 -0
- rockycode/onboarding.py +332 -0
- rockycode/palette.py +15 -0
- rockycode/pricing.py +178 -0
- rockycode/prompts/__init__.py +0 -0
- rockycode/prompts/rocky.py +257 -0
- rockycode/routines.py +287 -0
- rockycode/runners/__init__.py +0 -0
- rockycode/runners/agent.py +273 -0
- rockycode/runners/data.py +61 -0
- rockycode/runners/raw.py +176 -0
- rockycode/score.py +114 -0
- rockycode/session.py +298 -0
- rockycode/skills/architecture-viz/SKILL.md +71 -0
- rockycode/skills/architecture-viz/template.html +87 -0
- rockycode/skills/lean-prover/SKILL.md +155 -0
- rockycode/skills/lean-prover/torchlean-api.md +85 -0
- rockycode/tui/__init__.py +1 -0
- rockycode/tui/app.py +2450 -0
- rockycode/tui/exitsheet.py +181 -0
- rockycode/tui/goal_screen.py +315 -0
- rockycode/tui/mdterm.py +232 -0
- rockycode/tui/mdview.py +99 -0
- rockycode/tui/modepicker.py +103 -0
- rockycode/tui/permission.py +154 -0
- rockycode/tui/plangate.py +110 -0
- rockycode/tui/prompt_history.py +77 -0
- rockycode/tui/proposalcard.py +126 -0
- rockycode/tui/resume.py +142 -0
- rockycode/tui/rocky_pet.py +96 -0
- rockycode/tui/routinecard.py +123 -0
- rockycode-0.1.0.dist-info/METADATA +488 -0
- rockycode-0.1.0.dist-info/RECORD +83 -0
- rockycode-0.1.0.dist-info/WHEEL +4 -0
- rockycode-0.1.0.dist-info/entry_points.txt +2 -0
- rockycode-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<!-- architecture-viz reference scaffold — COPY AND ADAPT.
|
|
2
|
+
This is create_artifact BODY content: NO <html>/<head>/<style> (rocky strips
|
|
3
|
+
<style> and applies its light theme). Style with INLINE style= only; the
|
|
4
|
+
<script> at the end survives and drives the cross-highlight. Self-contained,
|
|
5
|
+
no CDN. Example block = scaled dot-product attention; swap the diagram,
|
|
6
|
+
ribbon, and torch for the architecture you're visualizing. Keep the shared
|
|
7
|
+
data-step ids matched across all three panels — that IS the link. -->
|
|
8
|
+
|
|
9
|
+
<p style="color:#5a5e7a;max-width:70ch">The diagram you know from the papers, the
|
|
10
|
+
shape at every step, and the PyTorch that makes it — the same block three ways.
|
|
11
|
+
<b style="color:#7c5cba">Hover any box, shape, or line of code</b> and the matching
|
|
12
|
+
two light up.</p>
|
|
13
|
+
|
|
14
|
+
<!-- shape ribbon: how the tensor shape changes, the through-line -->
|
|
15
|
+
<div class="card" style="display:flex;align-items:center;gap:6px;flex-wrap:wrap;justify-content:center">
|
|
16
|
+
<div data-step="in" style="display:flex;flex-direction:column;align-items:center;padding:7px 12px;border:1px solid #ddd4ef;border-radius:9px;background:#fff"><span style="font-family:ui-monospace,Menlo,monospace;font-weight:700;color:#6a4ca3">(n, d)</span><span style="font-size:.72rem;color:#5a5e7a">tokens in</span></div>
|
|
17
|
+
<span style="color:#5a5e7a">→</span>
|
|
18
|
+
<div data-step="qkv" style="display:flex;flex-direction:column;align-items:center;padding:7px 12px;border:1px solid #ddd4ef;border-radius:9px;background:#fff"><span style="font-family:ui-monospace,Menlo,monospace;font-weight:700;color:#6a4ca3">(n, dₖ)×3</span><span style="font-size:.72rem;color:#5a5e7a">Q K V</span></div>
|
|
19
|
+
<span style="color:#5a5e7a">→</span>
|
|
20
|
+
<div data-step="scores" style="display:flex;flex-direction:column;align-items:center;padding:7px 12px;border:1px solid #ddd4ef;border-radius:9px;background:#fff"><span style="font-family:ui-monospace,Menlo,monospace;font-weight:700;color:#6a4ca3">(n, n)</span><span style="font-size:.72rem;color:#5a5e7a">scores</span></div>
|
|
21
|
+
<span style="color:#5a5e7a">→</span>
|
|
22
|
+
<div data-step="softmax" style="display:flex;flex-direction:column;align-items:center;padding:7px 12px;border:1px solid #ddd4ef;border-radius:9px;background:#fff"><span style="font-family:ui-monospace,Menlo,monospace;font-weight:700;color:#6a4ca3">(n, n)</span><span style="font-size:.72rem;color:#5a5e7a">weights A</span></div>
|
|
23
|
+
<span style="color:#5a5e7a">→</span>
|
|
24
|
+
<div data-step="out" style="display:flex;flex-direction:column;align-items:center;padding:7px 12px;border:1px solid #ddd4ef;border-radius:9px;background:#fff"><span style="font-family:ui-monospace,Menlo,monospace;font-weight:700;color:#6a4ca3">(n, dₖ)</span><span style="font-size:.72rem;color:#5a5e7a">output</span></div>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<div style="display:flex;gap:22px;flex-wrap:wrap;align-items:flex-start">
|
|
28
|
+
<!-- LEFT: the paper diagram (inline-styled SVG) -->
|
|
29
|
+
<div class="card" style="flex:1 1 240px">
|
|
30
|
+
<h2>the block (as the paper draws it)</h2>
|
|
31
|
+
<svg viewBox="0 0 240 430" width="240" style="max-width:100%;height:auto" role="img" aria-label="scaled dot-product attention">
|
|
32
|
+
<defs><marker id="af" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto"><path d="M0,0 L6,3 L0,6 Z" fill="#7c5cba"/></marker></defs>
|
|
33
|
+
<path stroke="#7c5cba" stroke-width="1.6" fill="none" marker-end="url(#af)" d="M120,372 L120,346"/>
|
|
34
|
+
<path stroke="#7c5cba" stroke-width="1.6" fill="none" marker-end="url(#af)" d="M120,320 L120,286"/>
|
|
35
|
+
<path stroke="#7c5cba" stroke-width="1.6" fill="none" marker-end="url(#af)" d="M120,260 L120,226"/>
|
|
36
|
+
<path stroke="#7c5cba" stroke-width="1.6" fill="none" marker-end="url(#af)" d="M120,200 L120,150"/>
|
|
37
|
+
<path stroke="#7c5cba" stroke-width="1.6" fill="none" marker-end="url(#af)" d="M120,124 L120,78"/>
|
|
38
|
+
<text x="88" y="418" fill="#6a4ca3" font-family="ui-monospace,Menlo,monospace" font-size="13" font-weight="700" text-anchor="middle">Q</text>
|
|
39
|
+
<text x="120" y="418" fill="#6a4ca3" font-family="ui-monospace,Menlo,monospace" font-size="13" font-weight="700" text-anchor="middle">K</text>
|
|
40
|
+
<text x="208" y="418" fill="#6a4ca3" font-family="ui-monospace,Menlo,monospace" font-size="13" font-weight="700" text-anchor="middle">V</text>
|
|
41
|
+
<path stroke="#7c5cba" stroke-width="1.6" fill="none" marker-end="url(#af)" d="M88,408 L88,398 Q88,388 102,388 L110,388"/>
|
|
42
|
+
<path stroke="#7c5cba" stroke-width="1.6" fill="none" marker-end="url(#af)" d="M120,408 L120,398"/>
|
|
43
|
+
<path stroke="#8a6fc0" stroke-width="1.6" stroke-dasharray="4 3" fill="none" marker-end="url(#af)" d="M208,408 L208,105 Q208,93 182,93 L158,93"/>
|
|
44
|
+
<g data-step="scores"><rect x="70" y="372" width="100" height="26" rx="6" style="fill:#efeafa;stroke:#9d7cd8;stroke-width:1.5"/><text x="120" y="389" fill="#2a2a38" font-size="12.5" font-weight="600" text-anchor="middle" style="pointer-events:none">MatMul QKᵀ</text></g>
|
|
45
|
+
<g data-step="scores"><rect x="70" y="320" width="100" height="26" rx="6" style="fill:#efeafa;stroke:#9d7cd8;stroke-width:1.5"/><text x="120" y="337" fill="#2a2a38" font-size="12.5" font-weight="600" text-anchor="middle" style="pointer-events:none">Scale ÷√dₖ</text></g>
|
|
46
|
+
<g data-step="mask"><rect x="70" y="260" width="100" height="26" rx="6" style="fill:#efeafa;stroke:#9d7cd8;stroke-width:1.5;stroke-dasharray:5 4"/><text x="120" y="277" fill="#2a2a38" font-size="12.5" font-weight="600" text-anchor="middle" style="pointer-events:none">Mask (opt.)</text></g>
|
|
47
|
+
<g data-step="softmax"><rect x="70" y="200" width="100" height="26" rx="6" style="fill:#efeafa;stroke:#9d7cd8;stroke-width:1.5"/><text x="120" y="217" fill="#2a2a38" font-size="12.5" font-weight="600" text-anchor="middle" style="pointer-events:none">SoftMax</text></g>
|
|
48
|
+
<g data-step="out"><rect x="70" y="124" width="100" height="26" rx="6" style="fill:#efeafa;stroke:#9d7cd8;stroke-width:1.5"/><text x="120" y="141" fill="#2a2a38" font-size="12.5" font-weight="600" text-anchor="middle" style="pointer-events:none">MatMul ·V</text></g>
|
|
49
|
+
<text x="120" y="64" fill="#6a4ca3" font-family="ui-monospace,Menlo,monospace" font-size="13" font-weight="700" text-anchor="middle">Output</text>
|
|
50
|
+
</svg>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<!-- RIGHT: the same block, in the language she writes -->
|
|
54
|
+
<div class="card" style="flex:1 1 300px">
|
|
55
|
+
<h2>the same block, in PyTorch</h2>
|
|
56
|
+
<pre style="white-space:pre;overflow-x:auto"><span data-step="in" style="display:block;padding:1px 8px;border-radius:6px;border-left:3px solid transparent"># x: your tokens (n, d)
|
|
57
|
+
x</span><span data-step="qkv" style="display:block;padding:1px 8px;border-radius:6px;border-left:3px solid transparent">Q, K, V = x@Wq, x@Wk, x@Wv # (n, dₖ) each</span><span data-step="scores" style="display:block;padding:1px 8px;border-radius:6px;border-left:3px solid transparent">scores = Q @ K.transpose(-2,-1) / dₖ**0.5 # (n, n)</span><span data-step="mask" style="display:block;padding:1px 8px;border-radius:6px;border-left:3px solid transparent">scores = scores.masked_fill(mask, -inf) # (n, n)</span><span data-step="softmax" style="display:block;padding:1px 8px;border-radius:6px;border-left:3px solid transparent">A = scores.softmax(dim=-1) # (n, n) rows→1</span><span data-step="out" style="display:block;padding:1px 8px;border-radius:6px;border-left:3px solid transparent">out = A @ V # (n, dₖ)</span></pre>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<p style="color:#5a5e7a;font-size:.9rem">
|
|
62
|
+
<span class="tag tag-purple">◆ derived</span> shapes & dataflow from the standard
|
|
63
|
+
attention definition · <span class="tag tag-amber">◇ illustrative</span> n·dₖ are
|
|
64
|
+
example sizes. Want a shape proven for every n? <code>/research prove</code>.</p>
|
|
65
|
+
|
|
66
|
+
<script>
|
|
67
|
+
(function(){
|
|
68
|
+
var els = Array.prototype.slice.call(document.querySelectorAll("[data-step]"));
|
|
69
|
+
function paint(step, on){
|
|
70
|
+
els.forEach(function(el){
|
|
71
|
+
if(el.getAttribute("data-step")!==step) return;
|
|
72
|
+
var rect = el.tagName.toLowerCase()==="g" ? el.querySelector("rect") : null;
|
|
73
|
+
if(rect){ rect.style.fill = on ? "#ede6fb" : "#efeafa"; rect.style.stroke = on ? "#7c5cba" : "#9d7cd8"; rect.style.strokeWidth = on ? "2.4" : "1.5"; }
|
|
74
|
+
else { el.style.background = on ? "#ede6fb" : ""; el.style.borderLeftColor = on ? "#7c5cba" : (el.tagName.toLowerCase()==="span" && el.style.borderLeft ? "transparent" : ""); if(el.style.border && el.tagName.toLowerCase()!=="span") el.style.borderColor = on ? "#7c5cba" : "#ddd4ef"; }
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
els.forEach(function(el){
|
|
78
|
+
var step = el.getAttribute("data-step");
|
|
79
|
+
el.style.cursor = "pointer";
|
|
80
|
+
el.addEventListener("mouseenter", function(){ paint(step, true); });
|
|
81
|
+
el.addEventListener("mouseleave", function(){ paint(step, false); });
|
|
82
|
+
el.setAttribute("tabindex","0");
|
|
83
|
+
el.addEventListener("focus", function(){ paint(step, true); });
|
|
84
|
+
el.addEventListener("blur", function(){ paint(step, false); });
|
|
85
|
+
});
|
|
86
|
+
})();
|
|
87
|
+
</script>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lean-prover
|
|
3
|
+
description: Formalize and machine-verify mathematics AND neural networks in Lean 4 — Mathlib proofs for the math, TorchLean for typed models and robustness certificates, honest green/amber/red verdicts, rendered as an artifact
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# lean-prover — machine-verified mathematics
|
|
7
|
+
|
|
8
|
+
The Lean compiler is ground truth. A theorem that compiles with zero `sorry`
|
|
9
|
+
is true — no judge, no vibes, no trust required. The corollary binds you:
|
|
10
|
+
**never say "proved" without a green compile you actually ran.** This is the
|
|
11
|
+
one domain where your output is machine-checkable; act like it.
|
|
12
|
+
|
|
13
|
+
## Two layers — say which one every claim lives in
|
|
14
|
+
|
|
15
|
+
- **Math layer (Mathlib)** — properties of the mathematics itself, exact reals,
|
|
16
|
+
all sizes at once: "softmax lands in the probability simplex, for every n."
|
|
17
|
+
Default layer; the pipeline below.
|
|
18
|
+
- **Model layer (TorchLean)** — properties of a concrete network in Lean's
|
|
19
|
+
typed tensor framework: shape guarantees by compilation, semantics lemmas,
|
|
20
|
+
robustness certificates over float32. Use when the user brings actual model
|
|
21
|
+
code or asks about a specific network. See "Model layer" below.
|
|
22
|
+
|
|
23
|
+
A claim proved about real-number math is not a claim about a float32 kernel,
|
|
24
|
+
and vice versa. Never let the two blur in a report.
|
|
25
|
+
|
|
26
|
+
## Verdicts — use exactly this vocabulary
|
|
27
|
+
|
|
28
|
+
- **green** — compiles; zero `sorry`/`admit`; no new `axiom`. Machine-verified.
|
|
29
|
+
- **amber** — the statement typechecks but some goals remain as explicit
|
|
30
|
+
`sorry`. Honest partial credit: a correctly formalized statement is real
|
|
31
|
+
value on its own. Always say how many `sorry` and which goals.
|
|
32
|
+
- **red** — does not compile. Say so plainly, with the first error.
|
|
33
|
+
|
|
34
|
+
Before claiming green, grep your own file: no `sorry`, no `admit`, no `axiom`
|
|
35
|
+
declarations. An axiom "proof" proves nothing — that is cheating, not amber.
|
|
36
|
+
|
|
37
|
+
## Preflight — is Lean installed? Never assume it is
|
|
38
|
+
|
|
39
|
+
Before formalizing anything, confirm Lean itself is present. In bash:
|
|
40
|
+
`command -v lake elan || ls ~/.elan/bin/lake 2>/dev/null` (elan/lake usually
|
|
41
|
+
live in `~/.elan/bin`; prepend it to PATH in your bash calls if needed).
|
|
42
|
+
|
|
43
|
+
If Lean is **not found**, STOP and hand the user the choice — never silently
|
|
44
|
+
install a toolchain, and never fabricate a verdict for code you couldn't run:
|
|
45
|
+
|
|
46
|
+
- **Install it** — `curl https://elan.lean-lang.org/elan-init.sh -sSf | sh`
|
|
47
|
+
installs elan + the Lean toolchain; then set up a workspace (below). Guided
|
|
48
|
+
path: https://leanprover-community.github.io/get_started.html . Best if they
|
|
49
|
+
want to keep proving locally.
|
|
50
|
+
- **Verify in the browser (no install)** — rocky writes the formalization; the
|
|
51
|
+
user pastes it into https://live.lean-lang.org and reads the goal state /
|
|
52
|
+
green there. rocky reports the source as **unverified** and asks them for the
|
|
53
|
+
compile result before ever calling it green.
|
|
54
|
+
- **Formalize only** — rocky produces the Lean statement + proof sketch as an
|
|
55
|
+
artifact, badged **unverified — Lean not installed, not compiled**. Useful to
|
|
56
|
+
review the formalization; it is NOT machine-checked, so it can never be green
|
|
57
|
+
or amber (both mean a compile ran) — it is its own "unverified" verdict.
|
|
58
|
+
|
|
59
|
+
Only once Lean is confirmed present do you enter the workspace + pipeline below.
|
|
60
|
+
|
|
61
|
+
## Workspace
|
|
62
|
+
|
|
63
|
+
Proving needs a Lake project with Mathlib **cache-built**. Find one, in order:
|
|
64
|
+
|
|
65
|
+
1. a `lakefile.toml` / `lakefile.lean` in the current folder (or one level down)
|
|
66
|
+
whose `lake-manifest.json` lists mathlib
|
|
67
|
+
2. `$ROCKYCODE_LEAN_WS`
|
|
68
|
+
3. a `lean_probe/` Lake project in the current directory
|
|
69
|
+
|
|
70
|
+
If none exists, stop and offer setup — do not silently install:
|
|
71
|
+
`lake new <name> math && cd <name> && lake exe cache get`
|
|
72
|
+
(warn: the Mathlib cache is a ~5 GB download, but without it the build takes
|
|
73
|
+
hours, not minutes).
|
|
74
|
+
|
|
75
|
+
## Pipeline
|
|
76
|
+
|
|
77
|
+
1. **Formalize.** Write ONE self-contained file at `<workspace>/Rocky/<Slug>.lean`
|
|
78
|
+
(create the folder if needed). Restate the user's informal claim as a comment
|
|
79
|
+
at the top, then the formal statement. Name theorems descriptively. If the
|
|
80
|
+
informal statement is ambiguous, ask before formalizing — a proof of the
|
|
81
|
+
wrong statement is worse than no proof.
|
|
82
|
+
2. **Compile.** `lake env lean Rocky/<Slug>.lean` with bash, cwd = workspace.
|
|
83
|
+
Compiles run ~10s on a warm cache; a `sorry` produces a *warning*, so check
|
|
84
|
+
the text, not just the exit code.
|
|
85
|
+
3. **Repair, up to 3 rounds.** Read the errors, fix, recompile. Fix the first
|
|
86
|
+
error first — later ones are often cascade.
|
|
87
|
+
4. **Escalate, up to 3 more rounds.** If unknown-identifier errors persist,
|
|
88
|
+
STOP guessing names and switch to searching (see name-grounding below).
|
|
89
|
+
5. **Amber fallback.** Past ~6 compile rounds without green: keep every goal
|
|
90
|
+
you closed, replace the stuck ones with `sorry`, and get *that* file to
|
|
91
|
+
compile — the statement itself is then certified well-formed. Report amber.
|
|
92
|
+
Do not grind past the budget; do not delete the file to hide the attempt.
|
|
93
|
+
6. **Report.** Verdict first, then the exact compile command you ran, the
|
|
94
|
+
theorem names, and (if amber) what remains. Render the artifact.
|
|
95
|
+
|
|
96
|
+
## Name-grounding — the known failure mode is hallucinated identifiers
|
|
97
|
+
|
|
98
|
+
Measured on this exact pipeline: proof *architecture* is nearly always right;
|
|
99
|
+
what fails is invented Mathlib names. Rules:
|
|
100
|
+
|
|
101
|
+
- `import Mathlib` — bare, nothing else. NEVER `import Mathlib.Some.Module`:
|
|
102
|
+
guessed module names kill the whole file at the header (the module split
|
|
103
|
+
changes between versions; the bare import always works on a cached build).
|
|
104
|
+
- On `unknown identifier`/`unknown constant`: do NOT retry a similar guess.
|
|
105
|
+
Search instead —
|
|
106
|
+
- put `exact?` (or `apply?`, `rw?`) at the stuck goal and compile: the
|
|
107
|
+
output's "Try this:" line is a *verified* lemma name;
|
|
108
|
+
- batch-check candidates cheaply in a scratch file: `#check @Filter.Tendsto`
|
|
109
|
+
lines, one compile validates them all;
|
|
110
|
+
- `open` the relevant namespace and retry `exact?` — suggestions improve.
|
|
111
|
+
- Prefer big hammer tactics you know exist (`simp`, `norm_num`, `nlinarith`,
|
|
112
|
+
`positivity`, `field_simp`, `ring`, `omega`, `fun_prop`, `measurability`)
|
|
113
|
+
before hunting for the perfectly named lemma.
|
|
114
|
+
|
|
115
|
+
## Model layer (TorchLean)
|
|
116
|
+
|
|
117
|
+
TorchLean (github.com/lean-dojo/TorchLean) formalizes neural networks in
|
|
118
|
+
Lean 4 — PyTorch-shaped API, shape-indexed tensors, IBP/CROWN certificates.
|
|
119
|
+
It is **newer than your pretraining: you have ZERO latent knowledge of it.**
|
|
120
|
+
Working rules, validated by probe (3/3 machine-verified this way):
|
|
121
|
+
|
|
122
|
+
- FIRST read `torchlean-api.md` in this skill's directory — it is the only
|
|
123
|
+
TorchLean API you may use. Do not invent names beyond it; when stuck, read
|
|
124
|
+
the repo's own `NN/Examples/` files instead of guessing.
|
|
125
|
+
- `import NN.API` then `open TorchLean` — the missing `open` is the #1 error.
|
|
126
|
+
- Workspace: a built TorchLean checkout. Look for `$ROCKYCODE_TORCHLEAN_WS`,
|
|
127
|
+
then a `torchlean_probe/` checkout in the current directory. If none exists, offer setup
|
|
128
|
+
(clone + `lake exe cache get && lake build`; warn: multi-GB, ~30 min) —
|
|
129
|
+
never silently install.
|
|
130
|
+
- Same compile loop, budgets, and verdicts as the math layer. For pure
|
|
131
|
+
shape/wiring claims, the file compiling IS the theorem — say so in the
|
|
132
|
+
report rather than inventing a redundant proposition.
|
|
133
|
+
- Translating user PyTorch code: restate the model in TorchLean's API
|
|
134
|
+
(layer list ↔ `nn.Sequential!`, input shape ↔ `Tensor.T … (shape![…])`),
|
|
135
|
+
and show the correspondence side by side. Semantic claims about training
|
|
136
|
+
or CUDA runtime behavior are runtime evidence, not Lean proof evidence —
|
|
137
|
+
TorchLean's own trust boundaries say so; repeat that honestly.
|
|
138
|
+
|
|
139
|
+
## Artifact
|
|
140
|
+
|
|
141
|
+
Render the result with `create_artifact`: the informal statement, the Lean
|
|
142
|
+
source in a code block, and the verdict up top (green/amber/red — amber lists
|
|
143
|
+
the remaining goals). One artifact per statement, updated in place on re-runs.
|
|
144
|
+
|
|
145
|
+
When the work spans both layers (user code + math + model), render the
|
|
146
|
+
**triptych**: the user's original code, the math-layer theorem(s), and the
|
|
147
|
+
model-layer result, each with its own verdict badge — three panels, one story,
|
|
148
|
+
every claim labeled with the layer it lives in.
|
|
149
|
+
|
|
150
|
+
## Honesty rules
|
|
151
|
+
|
|
152
|
+
- The report's verdict comes from the last compile you ran, nothing else.
|
|
153
|
+
- Quote compiler output when it disagrees with your expectation.
|
|
154
|
+
- If the user's claim is false, say so — a disproof or a counterexample
|
|
155
|
+
(`decide`, `norm_num`, or an explicit witness) is a fully valid green result.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# TorchLean API excerpt — the ONLY TorchLean names you may use
|
|
2
|
+
|
|
3
|
+
TorchLean (github.com/lean-dojo/TorchLean, arXiv 2602.22631) formalizes neural
|
|
4
|
+
networks in Lean 4. It is NEWER than your pretraining data: you have zero latent
|
|
5
|
+
knowledge of it. Everything below is verbatim from the repo and was validated by
|
|
6
|
+
compile on 2026-07-15 (probe: 3/3 machine-verified). Treat this file as the whole
|
|
7
|
+
API surface — if a name is not here and not suggested by a compiler error, do not
|
|
8
|
+
use it. Read the repo's own files (NN/Examples/) when you need more.
|
|
9
|
+
|
|
10
|
+
## Imports and namespace
|
|
11
|
+
|
|
12
|
+
```lean
|
|
13
|
+
import NN.API -- the public API (works from a plain, non-module file)
|
|
14
|
+
import NN.Proofs -- optional: proof helpers
|
|
15
|
+
import Mathlib -- optional: Mathlib is a TorchLean dependency, fully available
|
|
16
|
+
|
|
17
|
+
open TorchLean -- REQUIRED before nn./tensor!/shape! names resolve
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Missing `open TorchLean` is the #1 observed error (unknown identifier `nn.Linear`).
|
|
21
|
+
|
|
22
|
+
## Tensors (validated by compile)
|
|
23
|
+
|
|
24
|
+
```lean
|
|
25
|
+
-- element type = dtype (Float, ℚ, Int, ℝ)
|
|
26
|
+
def v := Tensor.vector (α := Float) [0.1, 0.2, 0.3, 0.4]
|
|
27
|
+
|
|
28
|
+
-- typed vector, shape in the type
|
|
29
|
+
def twoVector : Tensor.T Float (shape![2]) := tensor! [1.0, 2.0]
|
|
30
|
+
|
|
31
|
+
-- N-D from nested lists (row-major); explicit: Tensor.ofList [2,2,2] [1,...,8]
|
|
32
|
+
def x3 : Tensor.T Float (Shape.ofDims [2, 2, 2]) :=
|
|
33
|
+
tensor! [ [ [1, 2], [3, 4] ], [ [5, 6], [7, 8] ] ]
|
|
34
|
+
|
|
35
|
+
-- flat constructor with dims
|
|
36
|
+
def xs : Tensor.T Float (shape![4, 2]) :=
|
|
37
|
+
tensorOfList! [4, 2] [0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
ℝ-valued tensors are fine for proofs but are noncomputable — do not `Tensor.print` them.
|
|
41
|
+
|
|
42
|
+
## Models (validated by compile)
|
|
43
|
+
|
|
44
|
+
```lean
|
|
45
|
+
def model :=
|
|
46
|
+
nn.Sequential![
|
|
47
|
+
nn.Linear 2 8,
|
|
48
|
+
nn.ReLU,
|
|
49
|
+
nn.Linear 8 1
|
|
50
|
+
]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Shape-indexed types mean a shape-mismatched literal or layer stack fails to
|
|
54
|
+
compile — for pure wiring claims, the file compiling IS the theorem.
|
|
55
|
+
|
|
56
|
+
## Semantics lemmas (validated by compile)
|
|
57
|
+
|
|
58
|
+
```lean
|
|
59
|
+
theorem shape_roundtrip :
|
|
60
|
+
Shape.ofDims (Shape.toList (shape![2, 3])) = shape![2, 3] := by simp
|
|
61
|
+
|
|
62
|
+
-- TorchLean.Semantics.relu is real-valued; unfolds to max-style form
|
|
63
|
+
theorem relu_eq_self_of_nonnegative (x : ℝ) (hx : 0 ≤ x) :
|
|
64
|
+
TorchLean.Semantics.relu x = x := by
|
|
65
|
+
unfold TorchLean.Semantics.relu
|
|
66
|
+
exact max_eq_left hx
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Deeper proof libraries: `NN.Proofs.*`, `NN.Verification.*`, `NN.MLTheory.*`.
|
|
70
|
+
|
|
71
|
+
## From the README — NOT compile-validated here, verify before relying on it
|
|
72
|
+
|
|
73
|
+
```lean
|
|
74
|
+
def data : Trainer.Dataset (.dim 2 .scalar) (.dim 1 .scalar) := Data.tensorDataset xs ys
|
|
75
|
+
-- Trainer.new model { task := .regression, optimizer := optim.sgd { lr := 0.05 }, ... }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
CLI verification workflows: `lake exe verify --help`, `lake exe verify -- torchlean-ibp`
|
|
79
|
+
(IBP/CROWN robustness certificates). Examples live in NN/Examples/Verification/.
|
|
80
|
+
|
|
81
|
+
## Trust boundaries (from the repo's TRUST_BOUNDARIES.md)
|
|
82
|
+
|
|
83
|
+
TorchLean's executable float32 path and its ℝ semantics are different layers —
|
|
84
|
+
say which one a claim is about. CUDA/native-runtime results are runtime evidence,
|
|
85
|
+
not Lean proof evidence; the repo itself makes this distinction. So must you.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""rockycode TUI: a Textual front-end subscribing to engine events."""
|