Zulip Chat Archive

Stream: mathlib4

Topic: Int.negOnePow vs (-1) ^ n


Yury G. Kudryashov (Feb 23 2026 at 16:18):

Do we have guidelines for using Int.negOnePow n vs (-1) ^ n? CC: @Johan Commelin #xy: which one should be used in #33972?

Violeta Hernández (Feb 23 2026 at 19:15):

What benefits does one have over the other? I imagine Int.negOnePow should work under much looser typeclass hypotheses, while (-1)^n comes with all the preexisting API for exponentiation.

Violeta Hernández (Feb 23 2026 at 19:16):

Maybe the rule should be that negOnePow n simps to (-1)^n over a group?

Weiyi Wang (Feb 23 2026 at 19:16):

I personally prefer (-1)^n when n is Nat, and Int.negOnePow when n is Int. (-1)^n is often easier to use, because e.g. ring tactic can handle it

Michael Stoll (Feb 23 2026 at 19:17):

docs#Int.negOnePow

Weiyi Wang (Feb 23 2026 at 19:17):

(I have #33143 that shows my preference)

Eric Wieser (Feb 23 2026 at 19:23):

Weiyi and Violeta; do you mean you prefer (-1 : ℤˣ) ^ n or (-1 : R) ^ n?

Weiyi Wang (Feb 23 2026 at 19:27):

I prefer the latter whenever it type-checks (unless the whole expression is in Z^x)

Violeta Hernández (Feb 23 2026 at 19:36):

I think I'd be inclined towards the former? But I don't have a strong preference here.

Michael Stoll (Feb 23 2026 at 19:43):

My totally uninformed take is that as a mathematician, I immediately understand what (-1) ^ n means, but parsing Int.negOnePow n or n.negOnePow takes a few seconds to process.

Yury G. Kudryashov (Feb 23 2026 at 19:43):

Let's wait for Johan. I don't see why Int.negOnePow is better than (-1 : ℤˣ) ^ n.

Eric Wieser (Feb 23 2026 at 19:45):

I think the idea of Int.negOnePow was to standardize on (-1 : ℤˣ) ^ n instead of (-1 : R) ^ n

Yury G. Kudryashov (Feb 23 2026 at 19:47):

I would use (-1 : R) ^ n for coercion (whenever it's defined).

Eric Wieser (Feb 23 2026 at 19:47):

By "for coercion" you mean "so as to avoid a coercion"?

Yury G. Kudryashov (Feb 23 2026 at 19:48):

I mean, instead of a coercion of Units Int to Int or other ring/field.

Johan Commelin (Feb 24 2026 at 04:00):

Sorry for my late response. I don't have a strong opinion on one or the other.
If I had one in the past, I should have documented it in the docstring on Int.negOnePow.

Eric Wieser (Feb 24 2026 at 04:15):

Perhaps the discussion on the original pr that added it has some context?

Yury G. Kudryashov (Feb 24 2026 at 05:17):

#6720

Joël Riou (Feb 24 2026 at 14:04):

As far as I can remember, I used Int.negOnePow in order to multiply certain morphisms in preadditive categories by signs as part of the formalization of homological algebra. There may have been issues with missing API regarding SMul ℤˣ M instances obtained from SMul ℤ M, but I do not remember the details. I would not mind if someone experimented making Int.negOnePow an abbrev (or removing it), while keeping certain lemmas (which may be generalized to other rings).


Last updated: Feb 28 2026 at 14:05 UTC