Zulip Chat Archive

Stream: Is there code for X?

Topic: monoid instance on self maps


Oliver Nash (May 04 2021 at 20:19):

I cannot seem to find this:

import algebra.default

instance function.monoid {α : Type*} : monoid (α  α) := infer_instance --fails

Is this really missing or am I missing the obvious?

Eric Wieser (May 04 2021 at 20:23):

We have docs#pi.monoid

Eric Wieser (May 04 2021 at 20:23):

I don't think it has the multiplication you want though

Oliver Nash (May 04 2021 at 20:23):

But that's different, right? I'm talking about composing functions.

Eric Wieser (May 04 2021 at 20:24):

That would have to be a type alias then

Oliver Nash (May 04 2021 at 20:24):

As in:

instance function.monoid {α : Type*} : monoid (α  α) :=
{ mul        := function.comp,
  mul_assoc  := function.comp.assoc,
  one        := id,
  one_mul    := λ f, by simp,
  mul_one    := λ f, by simp,

Oliver Nash (May 04 2021 at 20:24):

or even:

instance function.monoid {α : Type*} : monoid (α  α) :=
{ mul        := function.comp,
  mul_assoc  := function.comp.assoc,
  one        := id,
  one_mul    := λ f, by simp,
  mul_one    := λ f, by simp,
  npow       := λ n f, f^[n],
  npow_zero' := λ f, rfl,
  npow_succ' := λ n f, by simpa only [function.iterate_succ'], }

which leads me to my second question:

Oliver Nash (May 04 2021 at 20:25):

couldn't we use the above together with monoid.has_pow instead of nat.iterate?

Oliver Nash (May 04 2021 at 20:26):

Eric Wieser said:

That would have to be a type alias then

Sorry I was too busy pasting in code and I missed this. I don't follow your point here. What does this mean?

Kevin Buzzard (May 04 2021 at 20:27):

If alpha is something like a monoid then probably alpha -> alpha inherits a pointwise monoid structure which is not what you want.

Oliver Nash (May 04 2021 at 20:28):

Oh right I see. Thanks.

Kevin Buzzard (May 04 2021 at 20:28):

Yeah,

import algebra.direct_sum_graded

example (α : Type) [monoid α] : monoid (α  α) := infer_instance

and it's not what you want

Kevin Buzzard (May 04 2021 at 20:29):

PS do you have to fill in npow? Hopefully it happens by magic if you just leave it out.

Eric Wieser (May 04 2021 at 20:29):

Like docs#monoid.End.monoid

Oliver Nash (May 04 2021 at 20:30):

Kevin Buzzard said:

PS do you have to fill in npow? Hopefully it happens by magic if you just leave it out.

You don't have to fill it in. My second snippet (above the words "or even") omitted this.

Kevin Buzzard (May 04 2021 at 20:31):

I would check but my lightbulb is broken :-( :cry:

Oliver Nash (May 04 2021 at 20:31):

I saw that. No ideas I'm afraid.

Eric Wieser (May 04 2021 at 20:33):

Vs docs#monoid_hom.comm_monoid, which is elementwise

Eric Wieser (May 04 2021 at 20:33):

So I guess you need function.End to exist

Oliver Nash (May 04 2021 at 20:40):

Gotcha

David Wärn (May 04 2021 at 21:44):

import category_theory.types
import category_theory.single_obj

variable {α : Type*}
@[derive monoid]
def foo := category_theory.End α
#check (rfl : foo = (α  α))

Eric Wieser (May 04 2021 at 21:54):

docs#category_theory.End

Thomas Browning (Aug 08 2023 at 21:21):

Would it not be possible to have this instance at a lower instance priority? Would this allow you to define Nat.iterate and Function.Commute in terms of pow and Commute?

Eric Wieser (Aug 08 2023 at 22:23):

Note that docs#instMonoidEnd exists

Eric Wieser (Aug 08 2023 at 22:24):

Instance priorities are a bad tool for everything except performance optimization

Thomas Browning (Aug 08 2023 at 23:04):

Yes, it just feels a bit weird to have Function.Commute be a special case of Commute with duplicated API. But maybe there's no better way.

Yury G. Kudryashov (Aug 09 2023 at 05:18):

Note that docs#Function.Semiconj is not a docs#SemiconjBy for some M

Anatole Dedecker (Aug 09 2023 at 09:15):

(deleted)

Anatole Dedecker (Aug 09 2023 at 09:16):

Really the correct generalization is semiconjugacy in a monoid-oid, aka a category :grinning_face_with_smiling_eyes:

Yury G. Kudryashov (Aug 09 2023 at 14:30):

But semiconjugacy in a category is not universe polymorphic...


Last updated: Dec 20 2023 at 11:08 UTC