forked from liontiger23/presentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonoids.lhs
More file actions
232 lines (166 loc) · 3.65 KB
/
monoids.lhs
File metadata and controls
232 lines (166 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
---
title: Semigroups and monoids
subtitle: Functional abstractions
---
Algebraic structures
====================
\ignore{
> import Prelude hiding (Semigroup, Semigroup(..), Monoid, Monoid(..))
> import Data.List.NonEmpty
}
```{=latex}
\centering
\begin{quote}
```
Functional abstractions start with algebra
```{=latex}
\end{quote}
```
. . .
::: columns
:::: {.column width=50%}
```{=latex}
\begin{minipage}[c][.65\textheight][c]{\linewidth}
\centering
```
. . .
:::::: block
Semigroup $\langle S, \cdot \rangle$
---------
- Set $S$
- Binary operation
$\cdot: (S \times S) \rightarrow S$
- *Associativity*
$\forall a,b,c \in S : (a \cdot b) \cdot c = a \cdot (b \cdot c)$
::::::
. . .
:::::: block
Monoid $\langle S, \cdot, e \rangle$
------
- Semigroup $\langle S, \cdot \rangle$
- *Identity element* $e \in S$
$\forall a \in S : e \cdot a = a \cdot e = a$
::::::
```{=latex}
\end{minipage}
```
::::
:::: {.column width=50%}
```{=latex}
\onslide<2->
```
```{=latex}
\begin{minipage}[c][.65\textheight][c]{\linewidth}
\centering
```
{width=80%}
<https://en.wikipedia.org/wiki/Semigroup>
```{=latex}
\end{minipage}
```
::::
:::
Examples {.fragile}
========
::: columns
:::: {.column width=50%}
```{=latex}
\begin{minipage}[c][.8\textheight][t]{\linewidth}
\centering
```
. . .
:::::: block
Semigroup $\langle S, \cdot \rangle$ \centering
---------
::::: incremental
- *Associativity*
$\forall a,b,c \in S : (a \cdot b) \cdot c = a \cdot (b \cdot c)$
- Integers $\mathbb{Z}$
- $\langle \mathbb{Z}, + \text{ or } \cdot \rangle$
- $\langle \mathbb{Z}, min \text{ or } max \rangle$
- Power set of $S$
- $\langle 2^S, \cup \text{ or } \cap \rangle$
- Any semilattice $\langle L, \wedge \rangle$
- Strings
- $\langle \texttt{String}, \texttt{(++)} \rangle$
- Lists
- Pairs
- Functions
:::::
::::::
```{=latex}
\end{minipage}
```
::::
:::: {.column width=50%}
. . .
```{=latex}
\begin{minipage}[c][.8\textheight][t]{\linewidth}
\centering
```
```{=latex}
\renewcommand\hl[1]{\textcolor{CtpGreen}{#1}}
```
:::::: block
Monoid $\langle S, \cdot, \hl{e} \rangle$ \centering
---------
::::: incremental
- *Identity element* \hl{$e \in S$}
$\forall a \in S : e \cdot a = a \cdot e = a$
- Integers $\mathbb{Z}$
- $\langle \mathbb{Z}, + \text{ or } \cdot, \hl{0 \text{ or } 1} \rangle$
- $\langle \mathbb{Z} \hl{\cup \{ -\infty \text{ or } \infty \}},
min \text{ or } max, \hl{-\infty \text{ or } \infty} \rangle$
- Power set of $S$
- $\langle 2^S, \cup \text{ or } \cap, \hl{\emptyset \text{ or } S} \rangle$
- Any semilattice $\langle L, \wedge \rangle$ \hl{with $\top$}
- Strings
- $\langle \texttt{String}, \texttt{(++)}, \hl{\texttt{""}} \rangle$
- Lists
- Pairs
- Functions
:::::
::::::
```{=latex}
\end{minipage}
```
::::
:::
Haskell
=======
::: columns
:::: {.column width=50%}
[Data.Semigroup](https://hackage.haskell.org/package/base/docs/Data-Semigroup.html) \centering
----------------
> class Semigroup a where
> (<>) :: a -> a -> a
> sconcat :: NonEmpty a -> a
> stimes :: Integral b => b -> a -> a
Minimal complete definition \centering
---------------------------
\centering
`(<>)` | `sconcat`
. . .
::::
:::: {.column width=50%}
[Data.Monoid](https://hackage.haskell.org/package/base/docs/Data-Monoid.html) \phantom{g} \centering
----------------
> class Semigroup a => Monoid a where
> mempty :: a
> mappend :: a -> a -> a
> mconcat :: [a] -> a
Minimal complete definition \centering
---------------------------
\centering
`mempty` | `mconcat`
::::
:::
{.plain}
========
\centering
```{=latex}
{\fontsize{48pt}{7.2}\selectfont Q\&A }
```
\ignore{
> main = pure ()
}