gpt4 book ai didi

scala - 到底什么是幺半群同态?

转载 作者:行者123 更新时间:2023-12-03 05:42:33 26 4
gpt4 key购买 nike

我从 Monoid Morphisms, Products, and Coproducts 读到了幺半群同态并且无法100%理解。

作者说(强调原创):

The length function maps from String to Int while preserving the monoid structure. Such a function, that maps from one monoid to another in such a preserving way, is called a monoid homomorphism. In general, for monoids M and N, a homomorphism f: M => N, and all values x:M, y:M, the following equations hold:

f(x |+| y) == (f(x) |+| f(y))

f(mzero[M]) == mzero[N]

他的意思是这样吗,因为数据类型 StringInt 是幺半群,并且函数 length 映射 String => Int 保留幺半群结构(Int 是一个幺半群),这就是所谓的幺半群同态,对吗?

最佳答案

Does he mean, the datatype String and Int are monoid.

,都没有String也不Int是幺半群。幺半群是一个三元组(S, ⊕, e),其中⊕是二元运算符⊕:S×S → S,这样对于所有元素 a, b, c∈S 则有 (a⊕b)⊕c=a⊕(b⊕c),且 e∈S 是“单位元”使得a⊕e=e⊕a=aStringInt是类型,所以基本上是值的集合,但不是三元组。

文章说:

Let's take the String concatenation and Int addition as example monoids that have a relationship.

因此,作者显然还提到了二元运算符(在 (++) 的情况下为 String ,在 (+) 的情况下为 Int )。身份(在 String 的情况下为空字符串,在 0 的情况下 Int )保持隐式;在非正式英语对话中,将身份留给读者作为练习是很常见的。

现在假设我们有两个幺半群结构(M, ⊕, em)(N, ⊗, en),函数 f : M → N (如 length )被称为 monoid homomorphism [wiki]鉴于它成立 f(m1⊕m2)=f(m1)⊗f(m2 ) 对于所有元素 m1, m2∈M 并且该映射还保留单位元素:< em>f(em)=en.

例如length :: String -> Int是幺半群同态,因为我们可以考虑幺半群 ( String , (++) , "" )( Int , (+) , 0 ) 。认为:

  1. length (s1 ++ s2) == length s1 + length s2 (对于所有 String s s1s2 );和
  2. length "" == 0 .

关于scala - 到底什么是幺半群同态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55993254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com