From 0d266f862ff6676bb79b42cc41e91517cbcd3563 Mon Sep 17 00:00:00 2001 From: Yann Esposito Date: Thu, 11 Oct 2012 16:14:46 +0200 Subject: [PATCH] better graphs --- 00_Introduction.lhs | 164 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 134 insertions(+), 30 deletions(-) diff --git a/00_Introduction.lhs b/00_Introduction.lhs index 9e8ec9c..b4720ad 100644 --- a/00_Introduction.lhs +++ b/00_Introduction.lhs @@ -71,6 +71,21 @@ And will discuss about some categories. > - for all triplet of morphisms \\(h:A->B\\), \\(g:B->C\\) and \\(f:C->D\\) > \\( (f∘g)∘h = f∘(g∘h) \\) + +A -> A [label="idA"] +B -> B [label="idB"] +A -> B [label="f∘idA=f=idB∘f"] + + + +A -> B [label="f"] +B -> C [label="g"] +C -> D [label="h"] +A -> C [label="g∘f",style="bold",fontcolor="cyan",color="cyan"] +B -> D [label="h∘g",style="bold",fontcolor="yellow",color="yellow"] +A -> D [label="(h∘g)∘f=h∘(g∘f)",style="bold",color="red",fontcolor="red"] + + ### Representation of Category Representing Category is not just a game. @@ -121,9 +136,9 @@ g -> C fg [label="", fixedsize="false", width=0,height=0,shape=none]; AC [label="", fixedsize="false", width=0,height=0,shape=none]; -f -> fg [color="#b58900",style=dashed,arrowhead=None] -fg -> g [color="#b58900",style=dashed,arrowhead=None] -fg -> AC [label="h=g∘f",colorlabel="#b58900",color="#b58900",style=bold] +f -> fg [color="red",style=dashed,arrowhead=None] +fg -> g [color="red",style=dashed,arrowhead=None] +fg -> AC [label="h=g∘f",fontcolor="red",color="red",style=bold] A -> AC [label="h",arrowhead=None] AC -> C @@ -140,44 +155,47 @@ we just double the number morphisms between different objects. -f[label="", fixedsize="false", width=0,height=0,shape=none]; +A[pos="0,0!"] +B[pos="4,0!"] +C[pos="8,0!"] +f[pos="2,1!",label="", fixedsize="false", width=0,height=0,shape=none]; A -> f[label="f", arrowhead=None] f -> B -fp[label="", fixedsize="false", width=0,height=0,shape=none]; +fp[pos="2,0.5!",label="", fixedsize="false", width=0,height=0,shape=none]; A -> fp[label="f'", arrowhead=None] fp -> B -g[label="", fixedsize="false", width=0,height=0,shape=none]; +g[pos="6,0.5!",label="", fixedsize="false", width=0,height=0,shape=none]; B -> g[label="g", arrowhead=None] g -> C -gp[label="", fixedsize="false", width=0,height=0,shape=none]; +gp[pos="6,1!",label="", fixedsize="false", width=0,height=0,shape=none]; B -> gp[label="g'", arrowhead=None] gp -> C -fg[label="", fixedsize="false", width=0,height=0,shape=none]; -fpg[label="", fixedsize="false", width=0,height=0,shape=none]; -fgp[label="", fixedsize="false", width=0,height=0,shape=none]; -fpgp[label="", fixedsize="false", width=0,height=0,shape=none]; -AC[label="", fixedsize="false", width=0,height=0,shape=none]; -ApCp[label="", fixedsize="false", width=0,height=0,shape=none]; +fg[pos="6,0!",label="", fixedsize="false", width=0,height=0,shape=none]; +fpg[pos="2.5,-1.5!",label="", fixedsize="false", width=0,height=0,shape=none]; +fgp[pos="5.5,-1.5!",label="", fixedsize="false", width=0,height=0,shape=none]; +fpgp[pos="2,0!",label="", fixedsize="false", width=0,height=0,shape=none]; +AC[pos="4,-1!",label="", fixedsize="false", width=0,height=0,shape=none]; +ApCp[pos="4,-3!",label="", fixedsize="false", width=0,height=0,shape=none]; -f -> fg [color="#b58900",style=dashed,arrowhead=None] -fg -> g [color="#b58900",style=dashed,arrowhead=None] -fg -> AC [color="#b58900",style=bold,label="h=g∘f"] +f -> fg [color="red",style=dashed,arrowhead=None] +fg -> g [color="red",style=dashed,arrowhead=None] +fg -> AC [color="red",style=bold,fontcolor="red",label="h=g∘f"] -fp -> fpgp [color="#d33682",style=dashed,arrowhead=None] -fpgp -> gp [color="#d33682",style=dashed,arrowhead=None] -fpgp -> AC [color="#d33682",style=bold,label="h=g'∘f'"] +fp -> fpgp [color="yellow",style=dashed,arrowhead=None] +fpgp -> gp [color="yellow",style=dashed,arrowhead=None] +fpgp -> AC [color="yellow",style=bold,fontcolor="yellow",label="h=g'∘f'"] -fp -> fpg [color="#dc322f",style=dashed,arrowhead=None] -fpg -> g [color="#dc322f",style=dashed,arrowhead=None] -fpg -> ApCp [color="#dc322f",style=bold,label="h'=g∘f'"] +fp -> fpg [color="blue",style=dashed,arrowhead=None] +fpg -> g [color="blue",style=dashed,arrowhead=None] +fpg -> ApCp [color="blue",style=bold,fontcolor="blue",label="h'=g∘f'"] -f -> fgp [color="#268bd2",style=dashed,arrowhead=None] -fgp -> gp [color="#268bd2",style=dashed,arrowhead=None] -fgp -> ApCp [color="#268bd2",style=bold,label="h'=g'∘f"] +f -> fgp [color="violet",style=dashed,arrowhead=None] +fgp -> gp [color="violet",style=dashed,arrowhead=None] +fgp -> ApCp [color="violet",style=bold,fontcolor="violet",label="h'=g'∘f"] A -> AC [label="h",arrowhead=None] AC -> C @@ -188,16 +206,102 @@ ApCp -> C -In fact we could have made something equivalent and far easier to read. -But the ∘ relation will be more hidden. +By removing the graphical representation of ∘ we could create a more readable representation. - + A -> B[label="f"] A -> B[label="f'"] B -> C[label="g"] B -> C[label="g'"] -A -> C [label="h=g∘f=g'∘f'"] -A -> C [label="h'=g'∘f=g∘f'"] +A -> C [label="h\n=g∘f\n=g'∘f'"] +A -> C [label="h'\n=g'∘f\n=g∘f'"] + + + + ### Examples + +Which can be a valid category by choosing ∘ appropriately? + + +A[label="★"] +B[label="★"] +C[label="★"] +A -> B +B -> C +A -> C [constraint=false] + + + +A[label="★"] +B[label="★"] +C[label="★"] +A -> B[label="f"] +B -> C[label="g"] + + + +A[label="★",pos="0,50"] +B[label="★",pos="50,50"] +C[label="★",pos="25,0"] +A -> B +B -> A +B -> C +A -> C + + + +A -> B [constraint=false] +B -> C [constraint=false] +B -> A +C -> A + + + +A -> B[label="g"] +B -> A[label="f"] +B -> A[label="h"] + + +To continue to gain some intuition I will give some degenerated Category examples. + + ### Monoids + +What are Monoids? +Things that you can operate a list of in any evaluation order and obtain the same result. + +More precisely; let `l` be a list of elements of the monoid. +then + + +foldl (<>) e l = foldr (<>) e l + + +Where `(<>)` is the monoid operation. +And `e` is the neutral element of the monoid. +Equivalently: + + +((e <> x) <> y) <> z = x <> ( y <> ( z <> e) ) + + +Or another way of saying it is that `x <> y <> z` doesn't need any parenthesis. +Because whatever the order of evaluation the result will be the same. + +Typical examples: + +- `String` with `(++)` and `""` +- `Lists` with `(++)` and `[]` +- `Data.Text` with `append` and `empty` +- `Integer` with `(+)` and `0` +- `Integer` with `(*)` and `1` +- Generalized by `Monoid a` with `(<>)` and `mempty` + + + +★ -> ★[label="e"] +★ -> ★[label="x"] +★ -> ★[label="y"] +★ -> ★[label="..."]