python 에서의 monoid

in #python7 years ago (edited)

우선 monoid 의 수학적 정의를 살펴보자.
아래의 3가지를 모두 만족 한다면 '집합 S 를 항등원이 e 인 ⊗ 연산에 대해서 monoid' 라고 한다.

1. 집합 S 에 속한 모든 a 와 b 에 대해 a ⊗ b 가 정의되고 이 결과 또한 집합 S 에 속한다.
2. 집합 S 에 속한 모든 a 와 b, c 에 대해 (a ⊗ b) ⊗ c = a ⊗ (b ⊗ c) 가 성립한다. (결합 법칙)
3. 집합 S 에 속한 원소 e 에 대해 집합 S 에 속한 모든 a 는 a ⊗ e = e ⊗ a = a 가 성립한다.

따라서 monoid 라면 대(big) operator 개념을 생각해볼 수 있다.

이걸 응용한 python 시퀀스에 대한 대(big) operator 구현이
map / filter / functools.reduce 등등이다.


my_sum = lambda S: functools.reduce(lambda x, y: x + y, S, 0)
my_product = lambda S: functools.reduce(lambda x, y: x * y, S, 1)
my_cat = lambda S: functools.reduce(lambda x, y: x + y, S, "")
Sort:  

첫 글이, 파이썬의 monoid를 설명하시는 거라니... 독특하시네요ㅋㅋ 뉴비 소개글 부터 쓰시면 사람들이 반겨 줄거에요~!

조언 고맙습니다 ㅎㅎ 다음에 소개글도 올려볼께요

Welcome to the real world!!!

환영 감사해요 ㅎㅎ

가상화폐 평가에서 스팀이 B-래요! (5위)
^^
좋은 컨텐츠가 즐거운 스티밋을 만드는거 아시죠?

네 저도 코인 관심있습니다!

도움이 되었습니다, Follow 하고 갑니다 :D

프로그래밍에 관심 있으신거 같네요 감사해요 ㅎㅎ

Congratulations @limseok! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @limseok! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!