Zulip Chat Archive
Stream: mathlib4
Topic: calc indentation: style guide?
Yury G. Kudryashov (Feb 19 2024 at 09:06):
I see different styles of indentation with calc
in the library. Should we have a style guide or allow all of them?
-- as a closing tactic-1
calc
first_term ≤ mid_term := by
sorry
_ = last_term := _
-- as a closing tactic-2
calc first_term
≤ mid_term := by
sorry
= last_term := _
-- to prove a `have`
have H : a = b :=
-- newline, then one of 2 styles above
-- to prove a `have`
have H : a = b := calc
a = c := _
_ = b := _
Sébastien Gouëzel (Feb 19 2024 at 09:10):
Another one:
calc
a long first term
_ ≤ middle term := by
sorry
_ ≤ last term := by
sorry
Yaël Dillies (Feb 19 2024 at 09:12):
I personally prefer
have : a = b :=
calc
_ = c := _
_ = _ := _
Yury G. Kudryashov (Feb 19 2024 at 09:12):
This way a reader can't see the first term
Yaël Dillies (Feb 19 2024 at 09:13):
Yeah but that's fine because it's usually in the statement
Yury G. Kudryashov (Feb 19 2024 at 09:15):
Not if you had some simp
s, rw
s or apply
s before.
Yaël Dillies (Feb 19 2024 at 09:18):
Emphasis on "usually"
Yury G. Kudryashov (Feb 19 2024 at 09:19):
Then please fix your example to include surrounding code that contains the first and the last terms.
Emilie (Shad Amethyst) (Feb 19 2024 at 12:47):
You could always have a show a = b
before the calc
Richard Osborn (Feb 19 2024 at 13:37):
Your second example is missing an _
before the =
.
I personally don't like the first term being omitted as it should never increase the number of lines nor ruin the formatting if it is written next to calc
. If calc first_term
is longer than a single line, there may be other problems with the proof. To keep formatting as consistent as possible the following seems like the most robust and readable.
calc first_term
_ ≤ mid_term := by
sorry
_ = last_term := _
Geoffrey Irving (Feb 19 2024 at 13:46):
^ I also like first_term
on the calc
line, FWIW. It’s uniform, since then each change corresponds to a further line.
Ruben Van de Velde (Feb 19 2024 at 13:58):
It depends on the length of the expressions for me - putting the first expression on a separate line makes it much easier to pick out the structure than if you have to scan for a symbol somewhere in the middle of a long line
Jireh Loreaux (Feb 19 2024 at 14:16):
I disagree about putting the first expression on the calc line. Indeed, the calc
keyword will often appear at the end of the preceding line. In such situations it would be weird if the first expression were on that line.
Eric Wieser (Feb 19 2024 at 14:24):
I think that only happens in the case when Yael's suggestion above can take over, and _
on the first line is fine
Last updated: May 02 2025 at 03:31 UTC