Zulip Chat Archive

Stream: general

Topic: list.rotate


Bolton Bailey (Sep 17 2022 at 21:38):

It seems we have a list.rotate to rotate a list to the left by a certain number, I might like to fill out the API by making a function to rotate to the right, or also rotate by an arbitrary integer. How should I go about this?

Bolton Bailey (Sep 17 2022 at 21:39):

/poll <Rotate options>
Don't change anything
Change list.rotate to take an integer, refactor other appearances to use this
Make three functions named rotate, rotate_left, rotate_right
Make three functions named rotate_int, rotate, rotate_right
Make three functions named rotate, rotatel, rotater

Yaël Dillies (Sep 17 2022 at 22:23):

Probably a bad idea, but you could go so far as declaring a mul_action int (list a) instance!

Eric Rodriguez (Sep 17 2022 at 22:32):

do we have a mul_action a $ list a instance?

Eric Rodriguez (Sep 17 2022 at 22:33):

I feel like it'd be weird because the more natural smul instance is the nat instance, and I know those can coexist but imagine seeing 2 smul l in the infoview and not knowing which it was

Eric Wieser (Sep 17 2022 at 22:35):

Since when was rotating by 1 the identity @Yaël Dillies?

Kevin Buzzard (Sep 17 2022 at 22:46):

What about mul_action (multiplicative int) (list a) then? Given that multiplicative int seems to be the canonical infinite cyclic group in mathlib...

Kevin Buzzard (Sep 17 2022 at 22:47):

Or add_action int (list a) which I (edit: incorrectly) presume doesn't exist

Eric Wieser (Sep 17 2022 at 22:53):

docs#add_action would work fine, but I don't think it's a particularly sensible use of the typeclass here; not every α →+ additive (End β) is canonical enough to get a typeclass instance

Yaël Dillies (Sep 18 2022 at 04:24):

Yes sorry I meant add_action indeed!

Chris Hughes (Dec 13 2022 at 21:06):

Yaël Dillies said:

Probably a bad idea, but you could go so far as declaring a mul_action int (list a) instance!

I think this is why I introduced list.rotate. It was something to do with Sylow theorems.

Kevin Buzzard (Dec 13 2022 at 21:21):

For Sylow you need an element of order p in a group whose order is a multiple of p to start the induction off, and one way to get it is by looking at all lists of length p the product of whose elements is 1 and then observing that rotation must have at least p fixed points because it has one fixed point and the number is congruent to 0 mod p


Last updated: Dec 20 2023 at 11:08 UTC