#import "@local/MetaNote:0.0.1" : *

#let detm = math.mat.with(delim: "|")

#show: doc => MetaNote(
  title: [
    Functional Programming with Abstract Algebra,
  ],
  authors: (
    (
      name: "timetraveler314",
      affiliation: "University of Genshin",
      email: "<EMAIL>",
    ),
  ),
  doc,
)

#let opl = math.plus.circle
#let ip(x,y) = $lr(angle.l #x, #y angle.r)$
#let ip3(x,y,z) = $lr(angle.l #x, #y, #z angle.r)$
#let comp = math.circle.small

=

== Basic Structures

#definition("(Left) Semigroup Action")[
  Let $angle.l M, opl angle.r $ be a semigroup and $S$ be a set. A (left) semigroup action of $M$ on $S$ is a function $dot : M times S -> S$ such that for all $m, n in M$ and $s in S$,

  $
  (m opl n) dot s = m dot (n dot s)
  $

  #example[
    Consider the semigroup $ip(RR, +)$ and the vector set $RR^2$. The function $arrow.ccw : RR times RR^2 -> RR^2$ defined by a counter-clockwise rotation of $s$ by angle $m$ is a semigroup action.

    $
    (alpha + beta) arrow.ccw s = alpha arrow.ccw (beta arrow.ccw s)
    $
  ]
]

Extending actions to monoids is straightforward by adding the requirement that $
epsilon dot s = s.
$

== Monoid Constructions

How to construct a monoid out of a given monoid, a type and the arrow constructor?

#definition("Pointwise Monoid")[
  Let $M$ be a monoid and $S$ be a set. The pointwise monoid of $M$ and $S$ is the set of all functions $S -> M$ with the operation of pointwise multiplication.

  $
  (f opl g)(s) = f(s) opl g(s), \
  epsilon(s) = epsilon
  $
]

How to upgrade a semigroup to a monoid?

#example("Free Monoid from Semigroup")[
  Use ```hs Maybe```. ```hs Maybe M``` is a monoid with ```hs Nothing``` as the identity element and ```hs Just m``` as the non-identity element.
]

==== Cayley Representation

```hs
rep :: [a] -> ([a] -> [a])
rep xs = (xs ++)

abs :: ([a] -> [a]) -> [a]
abs f = f []
```

$
ip3([A], ++, []) <->
ip3([A]->[A], comp, id)
$

The idea works for any monoid.

#definition("Cayley Representation")[
  Let $M$ be a monoid. The Cayley representation of $M$ is the set of all functions $M -> M$ with the operation of function composition.

  $
  (f comp g)(m) = f(g(m)), \
  id(m) = m
  $
]

#definition("Free Monoid")[
  Let $S$ be a set. The free monoid generated by $S$ is the set of all finite sequences of elements of $S$ with the operation of concatenation.
]

= Day 2 : Automatic Differentiation

== Structures

=== Semiring Module ("Scalar Product")

```hs
class (Semiring d, Monoid e) 
    => Module d e | e -> d where
    (.*.) :: d -> e -> e
```

= Day 3 : PLP/Graded Monoids 

= Day 4 : 