Category theory

1.

对于Category theory,自然有更多的书籍和文章,我们不可能全部学,毕竟我们就讲究用的.但是如果你有时间阅读更是好了,毕竟学科知识是彼此渗透的,例如高数,线性等看似对生活没什么作用,但这些至少开拓了你的大脑(被开拓的大脑能否装得下更多的信息量呢?哈哈...不扯)

 

2.

这里转载一篇文章,可大致知道什么Category theory

 

 

The most accessible category theory book I’ve come across is Lawvere and Schanuel’s Conceptual Mathematics: A First Introduction to Categories 2nd ed. The book mixes Articles, which is written like a normal textbook; and Sessions, which is kind of written like a recitation class.

 

Even in the Article section, CM uses many pages to go over the basic concept compared to other books, which is good for self learners.

Sets, arrows, composition 

 

CM:

Before giving a precise definition of ‘category’, we should become familiar with one example, the category of finite sets and maps. An object in this category is a finite set or collection. … You are probably familiar with some notations for finite sets:

{ John, Mary, Sam }

 

There are two ways that I can think of to express this in Scala. One is by using a value a: Set[Person]:

scala> :paste

sealed trait Person {}
case object John extends Person {}
case object Mary extends Person {}
case object Sam extends Person {}

val a: Set[Person] = Set[Person](John, Mary, Sam)

// Exiting paste mode, now interpreting.

 

Another way of looking at it, is that Person as the type is a finite set already without SetNote: In CM, Lawvere and Schanuel use the term “map”, but I’m going to change to arrow like Mac Lane and other books.

arrow f in this cateogry consists of three things:

  1. a set A, called the domain of the arrow,
  2. a set B, called the codomain of the arrow,
  3. a rule assigning to each element a in the domain, an element b in the codomain. This b is denoted by f ∘ a (or sometimes ’f(a)‘), read ’f of a‘.

(Other words for arrow are ‘function’, ‘transformation’, ‘operator’, ‘map’, and ‘morphism’.)

 

Let’s try implementing the favorite breakfast arrow.

scala> :paste

sealed trait Breakfast {}
case object Eggs extends Breakfast {}
case object Oatmeal extends Breakfast {}
case object Toast extends Breakfast {}
case object Coffee extends Breakfast {}

val favoriteBreakfast: Person => Breakfast = {
  case John => Eggs
  case Mary => Coffee
  case Sam  => Coffee
}

// Exiting paste mode, now interpreting.

favoriteBreakfast: Person => Breakfast = <function1>

 

Note here that an “object” in this category is Set[Person] or Person, but the “arrow” favoriteBreakfast accepts a value whose type isPerson. Here’s the internal diagram of the arrow. 
favorite breakfast

The important thing is: For each dot in the domain, we have exactly one arrow leaving, and the arrow arrives at some dot in the codomain.

 

I get that a map can be more general than Function1[A, B] but it’s ok for this category. Here’s the implementation of favoritePerson:

scala> val favoritePerson: Person => Person = {
         case John => Mary
         case Mary => John
         case Sam  => Mary
       }
favoritePerson: Person => Person = <function1>

An arrow in which the domain and codomain are the same object is called an endomorphism.

 

favorite person

An arrow, in which the domain and codomain are the same set A, and for each of a in Af(a) = a, is called an identity arrow.

 

The “identity arrow on A” is denoted as 1A
identity arrow

 

Again, identity is an arrow, so it works on an element in the set, not the set itself. So in this case we can just use scala.Predef.identity.

scala> identity(John)
res0: John.type = John

 

Here are the external diagrams corresponding to the three internal diagrams from the above. 
external diagrams

 

This reiterates the point that in the category of finite sets, the “objects” translate to types like Person and Breakfast, and arrows translate to functions like Person => Person. The external diagram looks a lot like the type-level signatures like Person => Person.

The final basic ingredient, which is what lends all the dynamics to the notion of category is composition of arrows, by which two arrows are combined to obtain a third arrow.

 

We can do this in scala using scala.Function1’s andThen or compose.

scala> val favoritePersonsBreakfast = favoriteBreakfast compose favoritePerson
favoritePersonsBreakfast: Person => Breakfast = <function1>

 

Here’s the internal diagram: 
composition of maps

 

and the external diagram: 
external diagram: composition of maps

 

After composition the external diagram becomes as follows: 
external diagram: f of g

f ∘ g’ is read ’f following g‘, or sometimes ’f of g‘.

 

Data for a category consists of the four ingredients:

  • objects: ABC, …
  • arrows: f: A => B
  • identity arrows: 1A: A => A
  • composition of arrows

 

These data must satisfy the following rules:

 

The identity laws:

  • If 1A: A => A, g: A => B, then g ∘ 1A = g
  • If f: A => B, 1B: B => B, then 1A ∘ f = f

 

The associative law:

  • If f: A => B, g: B => C, h: C => D, then h ∘ (g ∘ f) = (h ∘ g) ∘ f

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值