# Monoid and monoid laws

Monoid is an important algebraic structure in category theory. A monoid M is a set M equipped with a binary operation ⊙ and a special element I, denoted 3-tuple (M, ⊙, I), where

• M is a set of elements
• ⊙ is a binary operator called multiplication, so that M ⊙ M → M, which means the multiplication of 2 elements in set M always results an element in set M. This operation is also denoted μ, so that μ(M, M) ≡ M ⊙ M.
• I is a special unit element (aka neutral element, or identity element) in set M

And the binary operator and the unit element must satisfy the following monoid laws:

• associative law αX, Y, Z: (X ⊙ Y) ⊙ Z ≡ X ⊙ (Y ⊙ Z), where X ∈ M, Y ∈ M, Z ∈ M
• left unit law λX: I ⊙ X ≡ X, where X ∈ M; and right unit law ρX: X ≡ X ⊙ I, where X ∈ M

so that:

• the triangle identity commutes:
• and the pentagon identity commutes::

In C#, the monoid definition can be represented as:

```public interface IMonoid<T>
{
static abstract T Multiply(T value1, T value2);

static abstract T Unit { get; }
}```

An intuitive example is the set ℤ of all integers, with binary operator + and unit element 0. The addition of 2 integers always results another integer; Also for integers x, y ,z, there is (x + y) + z ≡ x + (y + z) and 0 + x ≡ x ≡ x + 0 (ℤ, +, 0), so that (ℤ, +, 0) is monoid. Apparently (ℤ, *, 1) is monoid too.

```public class Int32SumMonoid : IMonoid<int>
{
public static int Multiply(int value1, int value2) => value1 + value2;

public static int Unit => GenericIndirection.AdditiveUnit<int>(); // 0.
}

public class Int32ProductMonoid : IMonoid<int>
{
public static int Multiply(int value1, int value2) => value1 * value2;

public static int Unit => GenericIndirection.MultiplicativeUnit<int>(); // 1.
}

public static class GenericIndirection
{

public static T MultiplicativeUnit<T>() where T : IMultiplicativeIdentity<T, T> => T.MultiplicativeIdentity;
}```

Another monoid example is (string, string.Concat, string.Empty):

```public class StringConcatMonoid : IMonoid<string>
{
public static string Multiply(string value1, string value2) => string.Concat(value1, value2);

public static string Unit => string.Empty;
}```

Here string can be viewed as a sequence of char, and the unit string is an empty sequence. Generally, (IEnumerable<T>, Enumerable.Concat<T>, Enumerable.Empty<T>()) is a monoid:

```public class EnumerableConcatMonoid<T> : IMonoid<IEnumerable<T>>
{
public static IEnumerable<T> Multiply(IEnumerable<T> value1, IEnumerable<T> value2) => value1.Concat(value2);

public static IEnumerable<T> Unit => Enumerable.Empty<T>();
}```

The set of Boolean values { true, false }, with binary operator && and unit element true, is a monoid with only 2 element: ({true, false}, &&, true); And so is ({ true, false }, ||, false):

```public class BooleanAndMonoid : IMonoid<bool>
{
public static bool Multiply(bool value1, bool value2) => value1 && value2;

public static bool Unit => true;
}

public class BooleanOrMonoid : IMonoid<bool>
{
public static bool Multiply(bool value1, bool value2) => value1 || value2;

public static bool Unit => false;
}```

A monoid with 1 single element can be defined with the special type void (System.Void):

```namespace System
{
[ComVisible(true)]
[Serializable]
[StructLayout(LayoutKind.Sequential, Size = 1)]
public struct Void
{
}
}```

The set { default(void) } with the following operator and unit is a monoid:

```public class VoidMonoid : IMonoid<void>
{
public void Multiply(void value1, void value2) => default;

public void Unit() => default;
}```

However, C# compiler does not allow void keyword or System.Void type to be used in this way, so here System.Void can be replaced with its equivalency in F#, the Microsoft.FSharp.Core.Unit type:

```namespace Microsoft.FSharp.Core
{
[CompilationMapping(SourceConstructFlags.ObjectType)]
[Serializable]
public sealed class Unit : IComparable
{
internal Unit() { }

public override int GetHashCode() => 0;

public override bool Equals(object obj) =>
obj == null || LanguagePrimitives.IntrinsicFunctions.TypeTestGeneric<Unit>(obj);

int IComparable.CompareTo(object obj) => 0;
}
}```

With an internal constructor, Unit cannot be instantiated, a Unit variable can only be default(Unit), which is null. So similarly, set { default(Unit) } with the following operator and unit element is monoid:

```public class UnitMonoid : IMonoid<Unit>
{
public static Unit Multiply(Unit value1, Unit value2) => default;

public static Unit Unit => default;
}```

# Monoid as category

An individual monoid (M, ⊙, I) can be a category C with 1 single object M, where:

• The collection of objects ob(C) is { M }, which means, category C has 1 single object, that is M.
• The collection of orphisms hom(C) is set M itself, which mean, each elements in set M is a morphism in category C.
• The composition operation ∘ of C is ⊙: since each morphism in C is each element in M, the composition of morphisms is just the multiplication of elements.
• The identity morphism id of C is unit element I: the identity morphism in C is the unit element in M

In this way, since M, ⊙, I satisfies the monoid laws, apparently the category laws are satisfied. In C#, this singleton category can be represented as:

```public class MonoidCategory<T, TMonoid> : ICategory<Type, T> where TMonoid : IMonoid<T>
{
public static IEnumerable<Type> Objects { get { yield return typeof(TMonoid); } }

public static T Compose(T morphism2, T morphism1) => TMonoid.Multiply(morphism1, morphism2);

public static T Id(Type @object) => TMonoid.Unit;
}```

• Your fancy words and crazy symbols are completely undecipherable to me, but the code is crystal clear. :)

• Amazon.com/mytv - enter the 6 digit amazon mytv code you receive at screen at www.amazon.com/mytv to regiter your device. contact amazon support for hel

• یک روسری و شال را می توان در تمام فصول استفاده کرد. مثلا در زمستان، اگر نمی خواهید یک ژاکت سنگین و یک کلاه سنگین استفاده کنید (که مدل موی شما خراب شود)، انتخاب و خرید شال زیبا یا یک روسری انتخاب بسیار مناسبی است.

• موسسات تشریفات عروسی مکان هایی هستند که با یک کادر مجرب و حرفه ای راهنمای خوبی برای شما هستند تا یک جشن با شکوه را برگزار نمایید.

• داشتن ظاهری زیباتر و جوانتر هم مو جب خرسندی و رضایت خود فرد می شود و هم باعث موفقیت او در امور شخصی، خانوادگی و اجتماعی نیز می شود. مر کز زیبایی دکتر مهدیانی فوق تخصص جراحی پلاستیک و زیبایی به عنوان بهترین مراکز جراحی پلاستیک و زیبایی در تهران کلیه خدمات زیبایی و جوانسازی را با بهترین کیفیت و مناسب ترین قیمت به شما عزیزان ارائه می کند.
https://drmahdiani.com/

• کلینیک لیزر شفا به عنوان بهترین مرکز درمان بیماری های گوارشی و نشیمن گاهی با مدیریت دکتر داود تاج بخش در رابطه با بیماریهای ناحیه مقعد خدماتی از جمله درمان بیماری هایی مثل هموروئید، فیستول، شقاق ارائه می دهد. کلینیک لیزر شفا فقط و فقط بر روی بیماری های مقعدی تمرکز داشته و تمامی متخصصین در این رابطه دور هم گرد آورده است.
https://laser-doc.com/

• در حال حاضر یکی از بهترین سقف های با کیفیت برای نصب در خانه سقف کناف است که شما می توانید برای مشاهده تمامی سقف های کناف و خرید آن به سایت ما مراجعه فرمایید.

• If you are looking for an online pet shop, you can visit our site and do the necessary work for your pet.

• If you are looking to buy Perfect Money voucher, you can refer to our site.

• کلینیک لیزر شفا به عنوان بهترین مرکز درمان بیماری های گوارشی و نشیمن گاهی با مدیریت دکتر داود تاج بخش در رابطه با بیماریهای ناحیه مقعد خدماتی از جمله درمان بیماری هایی مثل هموروئید، فیستول، شقاق ارائه می دهد. کلینیک لیزر شفا فقط و فقط بر روی بیماری های مقعدی تمرکز داشته و تمامی متخصصین در این رابطه دور هم گرد آورده است.

• Very interesting topic will bookmark your site to check if you Post more about in the future.

• Great Post !! Very interesting topic will bookmark your site to check if you write more about in the future.

• Really nice style and perfectly written content material in this. Material on this page is very efficient I’ve ever had. We do not need anything else. Thank you so much for the information.

• Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing...

• Great Article it its really informative and innovative keep us posted with new updates. its was really valuable.

• Thanks for sharing.I found a lot of interesting information here. A really good post, very thankful and hopeful that you will write many more

• This post is really astounding one! I was delighted to read this, very much useful. Many thanks

• awesome post. I’m a normal visitor of your web site and appreciate you taking the time to maintain the nice site. I’ll be a frequent visitor for a long time.

• Great article with excellent idea! I have bookmarked your site since this site contains important data in it.

• شرکت ارمغان تجارت رهسام با مقصود تامین نیازهای گسترده جامعه مهندسی و صنعت تاسیسات کشور در زمینه طراحی، مهندسی و مستند سازی تجهیزات تنظیم هوا مشغول به فعالیت می باشد. برای اطلاعات بیشتر و آشنایی با محصولات شرکت رهسام می توانید به وبسایت شرکت رهسام مراجعه کنید.

• https://ma-study.blogspot.com/

• بهترین قیمت تور چابهار را از آژانس هواپیمایی رویای زندگی در کرج تهیه نمایید

• وب سایتی که از ادغام خلاقیت و کارایی ساخته شده باشد، می تواند چهره اینترنتی شما را به شدت تقویت کند. وب سایت هایی که به خوبی طراحی شده اند، می توانند فرایند دسترسی اطلاعات، آشنایی با وب سایت ، و مبادلات اینترنتی را ساده تر نمایند. این امر به نوبه خود منجر به بازگشت سریع تر هزینه مصرف شده برای طراحی و توسعه وب سایت خواهد شد.

خدمات توسعه وب نویا سیستم تکنولوژی، بر پایه نیازهای مشتریان و اهداف تجاری آنها می باشد. با استفاده صحیح از تکنولوژی های مدرن نظیر PHP، ASP.net، Ajax، Flash، ...، نویا سیستم تکنولوژی زیر بنای تجارت اینترنتی شما را با چهره ای مدرن آراسته خواهد کرد. به کمک طراحی نرم افزارهای توسعه تحت وب ، نه تنها وب سایت تان به راحتی بر پا خواهد شد و کاربران به راحتی با آن در تعامل خواهند بود، بلکه وب سایت شما به یکی از رهبران صنعتی تبدیل خواهد شد.

• HI, THIS IS WAS A VERY GOOD POST INDEED. WE WILL SURELY COME AND VISIT THIS BLOG MORE OFTEN.

• HELLO, THANKS FOR YOUR POST, HAVE A GREAT AND WONDERFUL DAY TO EVERYONE!

• GOOD DAY! I AM VERY THANKFUL FOR THIS, THANK YOU FOR SHARING THIS.
HAVE A GREAT DAY!

• HELLO, WHAT A VERY NICE AND WONDERFUL POST THAT I READ FOR TODAY, THIS IS SO VERY GREAT, THANKS!

• مشاهده و خرید لاک ژل میکس کوکو در رنگبندی متنوع و جذاب با قیمتی باور نکردنی در فروشگاه اینترنتی گلارا

• The desert in Dubai usually includes a number of fun activities, such as camel rides and dune bashing. We are the best desert safari tour operator in Dubai. For Desert Safari Dubai visit: https://desertsafarisdubai.ae/

• I'm writing on this topic these days, Keo nha cai but I have stopped writing because there is no reference material. Then I accidentally found your article. I can refer to a variety of materials, so I think the work I was preparing will work! Thank you for your efforts.

• I have been looking for articles on these topics for a long time. casino online
I don't know how grateful you are for posting on this topic. Thank you for the numerous articles on this site, I will subscribe to those links in my bookmarks and visit them often. Have a nice day

• I'm writing on this topic these days, Keonhacai but I have stopped writing because there is no reference material. Then I accidentally found your article. I can refer to a variety of materials, so I think the work I was preparing will work! Thank you for your efforts.

• As I am looking at your writing, slotsite I regret being unable to do outdoor activities due to Corona 19, and I miss my old daily life. If you also miss the daily life of those days, would you please visit my site once? My site is a site where I post about photos and daily life when I was free.

• The 60-day game time is currently the only game time provided by the Blizzard company for the players of the game, Word of Warcraft. In the past, game times such as 30 days and 180 days were also available, but due to the new policies of this company and the policy it has considered, the only game time that is currently available for dear gamers is Game Time 60. It is fasting. In the following, we have collected interesting explanations about Game Time for you, which are worth reading.

Game time application for two months

Currently, 2-month game time is used in all areas of World of Warcraft. But if you want to experience a series of interesting and new experiences, you should buy this game time. These experiences include:
Using new extensions
Play on new maps
Lollup in a new style
Change in the shape of the game
Obtaining all products from the Jet Game site and quickly providing the product code in the shortest possible time

• great post.

• very nice post.

• very nice post.

• very great post.

• very nice post.

• در صورتی که قصد شرکت در این دوره های تخصصی و فنی­مهندسی را دارید؛ برای کسب اطلاعات بیشتر در مورد هر یک از دوره های تاسیسات مکانیکی ساختمان، وارد صفحات مربوطه شوید.

• The most complete database in the field of electrical and mechanical building design training

• this company use ASP.net framework for developing website. MVC design pattern also use for better performance..

• web design company with ASP.net and MVC
<a href="https://www.avinapardaz.com/" rel="nofollow">طراحی سایت</a>

• Howdy fantastic website! Does running a blog such as this require a lot of work? I have absolutely no understanding of programming but I was hoping to start my own blog soon.

• I am genuinely saying that you are posting meaningful and well written content on this website.

• This was an excellent post. Thank you for sharing it.

• I've been following a lot of articles. until I came across your results It has the knowledge I need, thank you very much. from start to finish I read all your articles. It's really unbelievable.

• خرید دراگون فلایت دنیای این گیم بیشتر آشنا کنیم. با انتشار آخرین بسته این گیم که نام دارد، بلیزارد  بار دیگر ثابت کرد که می‌تواند همه را راضی نگه دارد. همراهمان باشید تا به آموزش برای تازه واردان بپردازیم.

• This was an excellent post. Thank you for sharing it.

• great post.

• great post.

• Now click on the Create Account Button. This will create an account on Disney Plus Begin, and you can access Disney Plus free shows.

https://www.marcellusmatters.psu.edu/?URL=https://start.me/p/p1g5aG/
https://www.marcellusmatters.psu.edu/?URL=https://start.me/p/wMno27/
https://www.sgvavia.ru/go?https://start.me/p/p1g5aG/
https://www.sgvavia.ru/go?https://start.me/p/wMno27/
https://www.taker.im/go/?u=https://start.me/p/p1g5aG/
https://www.taker.im/go/?u=https://start.me/p/wMno27/
https://www.usich.gov/?URL=https://start.me/p/p1g5aG/
https://www.usich.gov/?URL=https://start.me/p/wMno27/
https://www.youa.eu/r.php?u=https://start.me/p/p1g5aG/
https://www.youa.eu/r.php?u=https://start.me/p/wMno27/
https://telegra.ph/%EC%9C%A0%ED%88%AC%EB%B8%8C%EC%B6%94%EC%B2%9C%EC%8A%AC%EB%A1%AF-07-18
https://telegra.ph/asi-07-19
https://telegra.ph/bank-07-19-2
https://telegra.ph/wev-07-19
https://telegra.ph/e-book-07-19
https://telegra.ph/aaaa-07-19-3

• این محصول علاوه بر کاهش میزان هزینه های اقتصادی، سرعت انجام پروژه را نیز افزایش خواهد داد.
ویژگی عایق الاستومری
از مقاومت بالایی در مقابل ضربات احتمالی خارجی و همچنین لرزش های ساختمانی برخوردار است.
امکان ترمیم و تعمیر این عایق به راحتی وجود دارد.
استفاده از این عایق بر روی سقف، مانع از ایجاد پوسیدگی در آن خواهد شد.
بر روی سطوح فلزی، آلومینیومی، سنگی و غیره دارای قدرت چسبندگی بالایی است.
همچنین این محصول مقاومت فوق العاده ای در مقابل اشعه UV و نور مستقیم خورشید دارد.
طراحی و تولید عایق الاستومری بر اساس به روزترین تکنولوژی های دنیا و مطابق با استانداردهای جهانی صورت می گیرد.
عایق الاستومری از انعطاف پذیری بالایی برخوردار بوده و در ابعاد و رنگ های مختلف تولید می شود.
از دیگر مشخصات عایق الاستومری می توان به استحکام و طول عمر بالای آنها اشاره کرد.

• nice post.

• Tak mungkin kamu menemukan situs terbaik selain di <a href="https://bursa188.pro/"rel="dofollow">BURSA188</a> <a href="https://bursa188.store/"rel="dofollow">BURSA188</a>

• Thank you very much for providing valuable content

• great

• great

• great

• great

• great

• Everything you put into this article. It has amazing knowledge. I don't think you can figure it out, you're very talented.

• Time to talk about it I feel learned more from what you said

• C# is still one of the best programming languages in the world...

• When I read an article on this topic, <a href="https://images.google.ws/url?sa=t&url=https%3A%2F%2Fwww.mtclean.blog/">baccarat online</a> the first thought was profound and difficult, and I wondered if others could understand.. My site has a discussion board for articles and photos similar to this topic. Could you please visit me when you have time to discuss this topic?

• Your writing is perfect and complete. <a href="https://images.google.vu/url?sa=t&url=https%3A%2F%2Fwww.mtclean.blog/">casinosite</a> However, I think it will be more wonderful if your post includes additional topics that I am thinking of. I have a lot of posts on my site similar to your topic. Would you like to visit once?

• As I am looking at your writing, <a href="https://images.google.vg/url?sa=t&url=https%3A%2F%2Fwww.mtclean.blog/">baccaratsite</a> I regret being unable to do outdoor activities due to Corona 19, and I miss my old daily life. If you also miss the daily life of those days, would you please visit my site once? My site is a site where I post about photos and daily life when I was free.

• Looking at this article, I miss the time when I didn't wear a mask. <a href="https://images.google.tt/url?sa=t&url=https%3A%2F%2Fwww.mtclean.blog/">slotsite</a> Hopefully this corona will end soon. My blog is a blog that mainly posts pictures of daily life before Corona and landscapes at that time. If you want to remember that time again, please visit us.

• As a newer blogger this is such a great post that is so incredibly helpful. Thank you for taking the time to share.

• goode

• Your article was really great and thank you very much for your time. I hope our adhesives are suitable for your work.
https://bazarganiarta.com/

• Really, your post is informative, thanks a lot for sharing this post that is very useful for us.

• thanks for mice suggestion that you have provided us. we are glad to be here to read this.

• Hi there, I check your blog like every week. Your story-telling style is awesome, keep it up!

• Innovative techniques with great selection of sentences summarizing the title in a best means. Happy to read it.

• I am grateful for the clarity and insight your article has provided.

• I think your website has a lot of useful knowledge. I’m so thankful for this website.

• واقعا پست شما آموزنده است، خیلی ممنون از به اشتراک گذاری این پست که برای ما بسیار مفید است.

• با تشکر از پیشنهاد موش که در اختیار ما قرار دادید. خوشحالیم که برای خواندن این اینجا هستیم.

• It’s the same topic , but I was quite surprised to see the opinions I didn’t think of. My blog also has articles on these topics, so I look forward to your visit:

• This was really an interesting topic and I kinda agree with what you have mentioned here!

• Nice post. I learn something new and challenging on site

• tanks this post and sharing my web

• I think the admin of this site is in fact working hard in favor of his web site

• That is a really well written article. Thanks you a for sharing

• Every piece of content I've come across in your article is perfect. I have new ideas based on your article.

• I look forward to reading more of your work in the future.

• Discover the Best Slot Sites to play online. Get welcome offers and bonuses & read the latest slots reviews and demo play before signing up.

• We provide a safe Toto site. You can use the safety playground and major site.

• orihinalidad. Magaling na pagtatangka sa pagdala ng bago sa internet!<a href="https://www.casinoplus.com.ph/">casino plus</a>

• We specialize in offering comprehensive rankings and recommendations for the top 15 private Toto sites in Korea for the first half of 2024. Our goal is to help you find the safest and most reliable options for online betting.