Skip to content

Comments

doc(Tactic/Translate/ToDual): add deployment guide for @[to_dual]#35216

Open
kim-em wants to merge 5 commits intoleanprover-community:masterfrom
kim-em:kim/to-dual-docs
Open

doc(Tactic/Translate/ToDual): add deployment guide for @[to_dual]#35216
kim-em wants to merge 5 commits intoleanprover-community:masterfrom
kim-em:kim/to-dual-docs

Conversation

@kim-em
Copy link
Contributor

@kim-em kim-em commented Feb 12, 2026

This PR expands the documentation for @[to_dual] with practical advice for deploying it to existing code.

Module docstring (Mathlib/Tactic/Translate/ToDual.lean): adds a "Deploying @[to_dual] to existing code" section covering name agreement, attribute propagation, docstring syntax ordering, declaration order dependencies, and known structural mismatches (conjunct reordering, type class gaps, interval argument swapping).

Attribute docstring: adds a note that @[simp] is not auto-copied (must use (attr := simp)), and shows the correct ordering when combining (attr := ...) with docstrings.

Agent skill (.claude/skills/to_dual/SKILL.md): detailed step-by-step instructions for an AI agent deploying @[to_dual], including how to identify candidates, common patterns, and debugging.

🤖 Prepared with Claude Code

@github-actions
Copy link

github-actions bot commented Feb 12, 2026

PR summary 3efa02168f

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ OrderBot.bddBelow
+ isGLB_lt_iff
+ lowerBounds_empty
+ lt_isGLB_iff
+ lt_isLUB_iff
++ isLUB_lt_iff
+++ OrderTop.bddAbove
++++++ upperBounds_empty
- min_self

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for scripts/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions
Copy link

github-actions bot commented Feb 12, 2026

✅ PR Title Formatted Correctly

The title of this PR has been updated to match our commit style conventions.
Thank you!

Expand the module docstring in ToDual.lean with practical advice for
deploying @[to_dual] to existing code: name agreement, attribute
propagation, docstring syntax, declaration ordering, and known
structural mismatches.

Also add a note to the attribute docstring about (attr := ...) syntax
ordering with docstrings.

Add .claude/skills/to_dual/SKILL.md with detailed agent instructions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kim-em kim-em changed the title docs: add deployment guide for @[to_dual] doc(Tactic/Translate/ToDual): add deployment guide for @[to_dual] Feb 12, 2026
@vihdzp
Copy link
Collaborator

vihdzp commented Feb 13, 2026

As for the claude stuff, have we come to a consensus on whether this belongs on the Mathlib repo or on users' config files? I recall the last time something like this got brought up, the consensus was the latter.

@JovanGerb
Copy link
Contributor

The claude file doesn't mention anything about to_dual self, to_dual none or to_dual existing, and also nothing about (reorder := ...).

When a theorem has hypotheses or parameters as explicit arguments that appear in a different order in the dual declaration, it is important to use the (reorder := ...) option to reorder them. For example

@[to_dual (reorder := hx hy)]
lemma unbot_le_unbot_iff (hx : x ≠ ⊥) (hy : y ≠ ⊥) : x.unbot hx ≤ y.unbot hy ↔ x ≤ y := by simp

kim-em and others added 2 commits February 14, 2026 13:28
- Fix "swapping ≤/≥" → "reversing the order of inequalities"
- Remove incorrect claims about directed/codirected, intervals, Heyting
- Remove bot-oriented "Build and test" section
- Add `to_dual none` mention for conjunct reordering
- Show name positioning in syntax examples (attr, name, docstring order)
- Remove .claude/skills/to_dual/SKILL.md (belongs in user config)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Restore the SKILL.md that was incorrectly removed, and update it:
- Remove incorrect claims about intervals and directed/codirected
- Add to_dual_insert_cast documentation
- Add to_dual self/existing/none and (reorder := ...) documentation
- Add critical rule about only preserving existing docstrings
- Fix syntax ordering (attr, name, docstring)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kim-em
Copy link
Contributor Author

kim-em commented Feb 14, 2026

The claude file doesn't mention anything about to_dual self, to_dual none or to_dual existing, and also nothing about (reorder := ...).

When a theorem has hypotheses or parameters as explicit arguments that appear in a different order in the dual declaration, it is important to use the (reorder := ...) option to reorder them. For example

@[to_dual (reorder := hx hy)]
lemma unbot_le_unbot_iff (hx : x ≠ ⊥) (hy : y ≠ ⊥) : x.unbot hx ≤ y.unbot hy ↔ x ≤ y := by simp

Added in 2e25372.

@kim-em
Copy link
Contributor Author

kim-em commented Feb 14, 2026

As for the claude stuff, have we come to a consensus on whether this belongs on the Mathlib repo or on users' config files? I recall the last time something like this got brought up, the consensus was the latter.

At this point, a repository without a .claude seems sort of mean. :-) How are your assistants meant to find their way around. It means people reduplicate work explaining things work. It's just an essential facet of modern documentation!

@kim-em
Copy link
Contributor Author

kim-em commented Feb 14, 2026

Thanks, @vihdzp and @JovanGerb for your helpful and patient corrections! I hope this will be a good experiment in writing more detailed docs, eventually. I think I've addressed your comments above.

Copy link
Contributor

@JovanGerb JovanGerb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, a repository without a .claude seems sort of mean. :-)

I honestly can't tell if this was written by Claude lol

kim-em and others added 2 commits February 15, 2026 13:44
Co-authored-by: Jovan Gerbscheid <56355248+JovanGerb@users.noreply.github.com>
Use the actual source code pattern instead of made-up `ofMapLEIff`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MichaelStollBayreuth MichaelStollBayreuth added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 19, 2026
@MichaelStollBayreuth
Copy link
Contributor

This had no labels, which usually leads to a wrong person to be assigned by the bot. Assigning @JovanGerb instead.

Copy link
Contributor

@JovanGerb JovanGerb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added explanation in the ToDual module docstring seems reasonable. Though I don't know why we would have a separate documentation in the module docstring from the docstring on the to_dual attribute itself, it seems a bit inefficient like this.

I have more trouble with the .claude folder. If I understand it correctly, this adds a pay-walled feature to mathlib that users need to pay for if they want to use it. This seems undesirable to me. So you'd have to find another reviewer to approve this.


`@[to_dual]` translates a declaration by:
1. Dualizing the proof term (reversing the order of inequalities, swapping `⊔`/`⊓`, `⊤`/`⊥`, etc.)
2. Guessing the dual declaration's name using `nameDict` below
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Guessing the dual declaration's name using `nameDict` below
2. Guessing the dual declaration's name using `nameDict` and `abbreviationDict` below

@JovanGerb JovanGerb added the awaiting-author A reviewer has asked the author a question or requested changes. label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author A reviewer has asked the author a question or requested changes. documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants