/usr/share/doc/libghc-maths-doc/html/src/Math-Algebras-Structures.html is in libghc-maths-doc 0.4.8-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>Math/Algebras/Structures.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>-- Copyright (c) David Amos, 2010-2015. All rights reserved.</span>
<a name="line-2"></a>
<a name="line-3"></a><span class='hs-comment'>{-# LANGUAGE MultiParamTypeClasses, NoMonomorphismRestriction #-}</span>
<a name="line-4"></a><span class='hs-comment'>{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}</span>
<a name="line-5"></a><span class='hs-comment'>{-# LANGUAGE IncoherentInstances #-}</span>
<a name="line-6"></a>
<a name="line-7"></a><span class='hs-comment'>-- |A module defining various algebraic structures that can be defined on vector spaces</span>
<a name="line-8"></a><span class='hs-comment'>-- - specifically algebra, coalgebra, bialgebra, Hopf algebra, module, comodule</span>
<a name="line-9"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Algebras</span><span class='hs-varop'>.</span><span class='hs-conid'>Structures</span> <span class='hs-keyword'>where</span>
<a name="line-10"></a>
<a name="line-11"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Prelude</span> <span class='hs-varid'>hiding</span> <span class='hs-layout'>(</span> <span class='hs-layout'>(</span><span class='hs-varop'>*></span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span>
<a name="line-12"></a>
<a name="line-13"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Algebras</span><span class='hs-varop'>.</span><span class='hs-conid'>VectorSpace</span>
<a name="line-14"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Algebras</span><span class='hs-varop'>.</span><span class='hs-conid'>TensorProduct</span>
<a name="line-15"></a>
<a name="line-16"></a>
<a name="line-17"></a><span class='hs-comment'>-- MONOID</span>
<a name="line-18"></a>
<a name="line-19"></a><a name="Vect"></a><span class='hs-comment'>-- |Monoid</span>
<a name="line-20"></a><a name="Vect"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Mon</span> <span class='hs-varid'>m</span> <span class='hs-keyword'>where</span>
<a name="line-21"></a> <span class='hs-varid'>munit</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>m</span>
<a name="line-22"></a> <span class='hs-varid'>mmult</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span>
<a name="line-23"></a>
<a name="line-24"></a>
<a name="line-25"></a><span class='hs-comment'>-- ALGEBRAS, COALGEBRAS, BIALGEBRAS, HOPF ALGEBRAS</span>
<a name="line-26"></a>
<a name="line-27"></a><a name="Vect"></a><span class='hs-comment'>-- |Caution: If we declare an instance Algebra k b, then we are saying that the vector space Vect k b is a k-algebra.</span>
<a name="line-28"></a><a name="Vect"></a><span class='hs-comment'>-- In other words, we are saying that b is the basis for a k-algebra. So a more accurate name for this class</span>
<a name="line-29"></a><a name="Vect"></a><span class='hs-comment'>-- would have been AlgebraBasis.</span>
<a name="line-30"></a><a name="Vect"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyword'>where</span>
<a name="line-31"></a> <span class='hs-varid'>unit</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>k</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span>
<a name="line-32"></a> <span class='hs-varid'>mult</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>b</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span>
<a name="line-33"></a>
<a name="line-34"></a><a name="unit'"></a><span class='hs-comment'>-- |Sometimes it is more convenient to work with this version of unit.</span>
<a name="line-35"></a><span class='hs-definition'>unit'</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-conid'>()</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span>
<a name="line-36"></a><span class='hs-definition'>unit'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unit</span> <span class='hs-varop'>.</span> <span class='hs-varid'>unwrap</span> <span class='hs-comment'>-- where unwrap = counit :: Num k => Trivial k -> k</span>
<a name="line-37"></a>
<a name="line-38"></a><a name="Vect"></a><span class='hs-comment'>-- |An instance declaration for Coalgebra k b is saying that the vector space Vect k b is a k-coalgebra.</span>
<a name="line-39"></a><a name="Vect"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyword'>where</span>
<a name="line-40"></a> <span class='hs-varid'>counit</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>k</span>
<a name="line-41"></a> <span class='hs-varid'>comult</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>b</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span>
<a name="line-42"></a>
<a name="line-43"></a><a name="counit'"></a><span class='hs-comment'>-- |Sometimes it is more convenient to work with this version of counit.</span>
<a name="line-44"></a><span class='hs-definition'>counit'</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-conid'>()</span>
<a name="line-45"></a><span class='hs-definition'>counit'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>wrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>counit</span> <span class='hs-comment'>-- where wrap = unit :: Num k => k -> Trivial k</span>
<a name="line-46"></a>
<a name="line-47"></a><span class='hs-comment'>-- unit' and counit' enable us to form tensors of these functions</span>
<a name="line-48"></a>
<a name="line-49"></a><a name="Bialgebra"></a><span class='hs-comment'>-- |A bialgebra is an algebra which is also a coalgebra, subject to the compatibility conditions</span>
<a name="line-50"></a><a name="Bialgebra"></a><span class='hs-comment'>-- that counit and comult must be algebra morphisms (or equivalently, that unit and mult must be coalgebra morphisms)</span>
<a name="line-51"></a><a name="Bialgebra"></a><span class='hs-keyword'>class</span> <span class='hs-layout'>(</span><span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Bialgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyword'>where</span> <span class='hs-layout'>{</span><span class='hs-layout'>}</span>
<a name="line-52"></a>
<a name="line-53"></a><a name="HopfAlgebra"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Bialgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>HopfAlgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyword'>where</span>
<a name="line-54"></a> <span class='hs-varid'>antipode</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span>
<a name="line-55"></a>
<a name="line-56"></a>
<a name="line-57"></a><a name="instance%20Num%20(Vect%20k%20b)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Eq</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Show</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Num</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-58"></a> <span class='hs-varid'>x</span><span class='hs-varop'>+</span><span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>x</span> <span class='hs-varop'><+></span> <span class='hs-varid'>y</span>
<a name="line-59"></a> <span class='hs-varid'>negate</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>negatev</span> <span class='hs-varid'>x</span>
<a name="line-60"></a> <span class='hs-comment'>-- negate (V ts) = V $ map (\(b,x) -> (b, negate x)) ts</span>
<a name="line-61"></a> <span class='hs-varid'>x</span><span class='hs-varop'>*</span><span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mult</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span> <span class='hs-varop'>`te`</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-62"></a> <span class='hs-varid'>fromInteger</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unit</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromInteger</span> <span class='hs-varid'>n</span><span class='hs-layout'>)</span>
<a name="line-63"></a> <span class='hs-varid'>abs</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"Prelude.Num.abs: inappropriate abstraction"</span>
<a name="line-64"></a> <span class='hs-varid'>signum</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"Prelude.Num.signum: inappropriate abstraction"</span>
<a name="line-65"></a>
<a name="line-66"></a>
<a name="line-67"></a><span class='hs-comment'>-- This is the Frobenius form, provided some conditions are met</span>
<a name="line-68"></a><span class='hs-comment'>-- pairing = counit . mult</span>
<a name="line-69"></a>
<a name="line-70"></a><span class='hs-comment'>{-
<a name="line-71"></a>-- A class to be used to declare that a type b should be given the set coalgebra structure
<a name="line-72"></a>class SetCoalgebra b where {}
<a name="line-73"></a>
<a name="line-74"></a>instance (Num k, SetCoalgebra b) => Coalgebra k b where
<a name="line-75"></a> counit (V ts) = sum [x | (m,x) <- ts] -- trace
<a name="line-76"></a> comult = fmap (\m -> T m m) -- diagonal
<a name="line-77"></a>-}</span>
<a name="line-78"></a>
<a name="line-79"></a>
<a name="line-80"></a><a name="instance%20Algebra%20k%20()"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-conid'>()</span> <span class='hs-keyword'>where</span>
<a name="line-81"></a> <span class='hs-varid'>unit</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>wrap</span>
<a name="line-82"></a> <span class='hs-comment'>-- unit 0 = zero -- V []</span>
<a name="line-83"></a> <span class='hs-comment'>-- unit x = V [( (),x)]</span>
<a name="line-84"></a> <span class='hs-varid'>mult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-conid'>()</span><span class='hs-layout'>,</span><span class='hs-conid'>()</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>-></span><span class='hs-conid'>()</span><span class='hs-layout'>)</span>
<a name="line-85"></a> <span class='hs-comment'>-- mult = linear mult' where mult' ((),()) = return ()</span>
<a name="line-86"></a> <span class='hs-comment'>-- mult (V [( ((),()), x)]) = V [( (),x)]</span>
<a name="line-87"></a> <span class='hs-comment'>-- mult (V []) = zerov</span>
<a name="line-88"></a>
<a name="line-89"></a><a name="instance%20Coalgebra%20k%20()"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-conid'>()</span> <span class='hs-keyword'>where</span>
<a name="line-90"></a> <span class='hs-varid'>counit</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unwrap</span>
<a name="line-91"></a> <span class='hs-comment'>-- counit (V []) = 0</span>
<a name="line-92"></a> <span class='hs-comment'>-- counit (V [( (),x)]) = x</span>
<a name="line-93"></a> <span class='hs-varid'>comult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-conid'>()</span><span class='hs-keyglyph'>-></span><span class='hs-layout'>(</span><span class='hs-conid'>()</span><span class='hs-layout'>,</span><span class='hs-conid'>()</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-94"></a> <span class='hs-comment'>-- comult = linear comult' where comult' () = return ((),())</span>
<a name="line-95"></a> <span class='hs-comment'>-- comult (V [( (),x)]) = V [( ((),()), x)]</span>
<a name="line-96"></a> <span class='hs-comment'>-- comult (V []) = zerov</span>
<a name="line-97"></a>
<a name="line-98"></a>
<a name="line-99"></a><a name="instance%20Algebra%20k%20(DSum%20a%20b)"></a><span class='hs-comment'>-- Kassel p4</span>
<a name="line-100"></a><a name="instance%20Algebra%20k%20(DSum%20a%20b)"></a><span class='hs-comment'>-- |The direct sum of k-algebras can itself be given the structure of a k-algebra.</span>
<a name="line-101"></a><a name="instance%20Algebra%20k%20(DSum%20a%20b)"></a><span class='hs-comment'>-- This is the product object in the category of k-algebras.</span>
<a name="line-102"></a><a name="instance%20Algebra%20k%20(DSum%20a%20b)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>DSum</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-103"></a> <span class='hs-varid'>unit</span> <span class='hs-varid'>k</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>i1</span> <span class='hs-layout'>(</span><span class='hs-varid'>unit</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-varop'><+></span> <span class='hs-varid'>i2</span> <span class='hs-layout'>(</span><span class='hs-varid'>unit</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span>
<a name="line-104"></a> <span class='hs-comment'>-- unit == (i1 . unit) <<+>> (i2 . unit)</span>
<a name="line-105"></a> <span class='hs-varid'>mult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>linear</span> <span class='hs-varid'>mult'</span>
<a name="line-106"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>mult'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Left</span> <span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-conid'>Left</span> <span class='hs-varid'>a2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>i1</span> <span class='hs-varop'>$</span> <span class='hs-varid'>mult</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span><span class='hs-varid'>a2</span><span class='hs-layout'>)</span>
<a name="line-107"></a> <span class='hs-varid'>mult'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Right</span> <span class='hs-varid'>b1</span><span class='hs-layout'>,</span> <span class='hs-conid'>Right</span> <span class='hs-varid'>b2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>i2</span> <span class='hs-varop'>$</span> <span class='hs-varid'>mult</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>b1</span><span class='hs-layout'>,</span><span class='hs-varid'>b2</span><span class='hs-layout'>)</span>
<a name="line-108"></a> <span class='hs-varid'>mult'</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>zerov</span>
<a name="line-109"></a><span class='hs-comment'>-- This is the product algebra, which is the product in the category of algebras</span>
<a name="line-110"></a><span class='hs-comment'>-- 1 = (1,1)</span>
<a name="line-111"></a><span class='hs-comment'>-- (a1,b1) * (a2,b2) = (a1*a2, b1*b2)</span>
<a name="line-112"></a><span class='hs-comment'>-- It's not a coproduct, because i1, i2 aren't algebra morphisms (they violate Unit axiom)</span>
<a name="line-113"></a>
<a name="line-114"></a><a name="instance%20Coalgebra%20k%20(DSum%20a%20b)"></a><span class='hs-comment'>-- |The direct sum of k-coalgebras can itself be given the structure of a k-coalgebra.</span>
<a name="line-115"></a><a name="instance%20Coalgebra%20k%20(DSum%20a%20b)"></a><span class='hs-comment'>-- This is the coproduct object in the category of k-coalgebras.</span>
<a name="line-116"></a><a name="instance%20Coalgebra%20k%20(DSum%20a%20b)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>DSum</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-117"></a> <span class='hs-varid'>counit</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unwrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>linear</span> <span class='hs-varid'>counit'</span>
<a name="line-118"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>counit'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Left</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>wrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>counit</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>return</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span>
<a name="line-119"></a> <span class='hs-varid'>counit'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Right</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>wrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>counit</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>return</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span>
<a name="line-120"></a> <span class='hs-comment'>-- counit = counit . p1 <<+>> counit . p2</span>
<a name="line-121"></a> <span class='hs-varid'>comult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>linear</span> <span class='hs-varid'>comult'</span> <span class='hs-keyword'>where</span>
<a name="line-122"></a> <span class='hs-varid'>comult'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Left</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>a1</span><span class='hs-layout'>,</span><span class='hs-varid'>a2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>Left</span> <span class='hs-varid'>a1</span><span class='hs-layout'>,</span> <span class='hs-conid'>Left</span> <span class='hs-varid'>a2</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>comult</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-varid'>a</span>
<a name="line-123"></a> <span class='hs-varid'>comult'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Right</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>b1</span><span class='hs-layout'>,</span><span class='hs-varid'>b2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>Right</span> <span class='hs-varid'>b1</span><span class='hs-layout'>,</span> <span class='hs-conid'>Right</span> <span class='hs-varid'>b2</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>comult</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-varid'>b</span>
<a name="line-124"></a> <span class='hs-comment'>-- comult = ( (i1 `tf` i1) . comult . p1 ) <<+>> ( (i2 `tf` i2) . comult . p2 )</span>
<a name="line-125"></a>
<a name="line-126"></a>
<a name="line-127"></a>
<a name="line-128"></a>
<a name="line-129"></a><a name="instance%20Algebra%20k%20(Tensor%20a%20b)"></a><span class='hs-comment'>-- Kassel p32</span>
<a name="line-130"></a><a name="instance%20Algebra%20k%20(Tensor%20a%20b)"></a><span class='hs-comment'>-- |The tensor product of k-algebras can itself be given the structure of a k-algebra</span>
<a name="line-131"></a><a name="instance%20Algebra%20k%20(Tensor%20a%20b)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-132"></a> <span class='hs-comment'>-- unit 0 = V []</span>
<a name="line-133"></a> <span class='hs-varid'>unit</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>x</span> <span class='hs-varop'>*></span> <span class='hs-layout'>(</span><span class='hs-varid'>unit</span> <span class='hs-num'>1</span> <span class='hs-varop'>`te`</span> <span class='hs-varid'>unit</span> <span class='hs-num'>1</span><span class='hs-layout'>)</span>
<a name="line-134"></a> <span class='hs-varid'>mult</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>mult</span> <span class='hs-varop'>`tf`</span> <span class='hs-varid'>mult</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span><span class='hs-varid'>b'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a'</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span><span class='hs-varid'>b'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span>
<a name="line-135"></a> <span class='hs-comment'>-- mult = linear m where</span>
<a name="line-136"></a> <span class='hs-comment'>-- m ((a,b),(a',b')) = (mult $ return (a,a')) `te` (mult $ return (b,b'))</span>
<a name="line-137"></a>
<a name="line-138"></a><a name="instance%20Coalgebra%20k%20(Tensor%20a%20b)"></a><span class='hs-comment'>-- Kassel p42</span>
<a name="line-139"></a><a name="instance%20Coalgebra%20k%20(Tensor%20a%20b)"></a><span class='hs-comment'>-- |The tensor product of k-coalgebras can itself be given the structure of a k-coalgebra</span>
<a name="line-140"></a><a name="instance%20Coalgebra%20k%20(Tensor%20a%20b)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-141"></a> <span class='hs-varid'>counit</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unwrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>linear</span> <span class='hs-varid'>counit'</span>
<a name="line-142"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>counit'</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>wrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>counit</span> <span class='hs-varop'>.</span> <span class='hs-varid'>return</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-varop'>*</span> <span class='hs-layout'>(</span><span class='hs-varid'>wrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>counit</span> <span class='hs-varop'>.</span> <span class='hs-varid'>return</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-comment'>-- (*) taking place in Vect k ()</span>
<a name="line-143"></a> <span class='hs-comment'>-- what this really says is that counit (a `tensor` b) = counit a * counit b</span>
<a name="line-144"></a> <span class='hs-comment'>-- counit = counit . linear (\(x,y) -> counit' (return x) * counit' (return y))</span>
<a name="line-145"></a> <span class='hs-varid'>comult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>nf</span> <span class='hs-varop'>.</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a'</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span><span class='hs-varid'>b'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span><span class='hs-varid'>b'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-varid'>comult</span> <span class='hs-varop'>`tf`</span> <span class='hs-varid'>comult</span><span class='hs-layout'>)</span>
<a name="line-146"></a> <span class='hs-comment'>-- comult = assocL . (id `tf` assocR) . (id `tf` (twist `tf` id))</span>
<a name="line-147"></a> <span class='hs-comment'>-- . (id `tf` assocL) . assocR . (comult `tf` comult)</span>
<a name="line-148"></a>
<a name="line-149"></a>
<a name="line-150"></a><a name="instance%20Coalgebra%20k%20EBasis"></a><span class='hs-comment'>-- The set coalgebra - can be defined on any set</span>
<a name="line-151"></a><a name="instance%20Coalgebra%20k%20EBasis"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-conid'>EBasis</span> <span class='hs-keyword'>where</span>
<a name="line-152"></a> <span class='hs-varid'>counit</span> <span class='hs-layout'>(</span><span class='hs-conid'>V</span> <span class='hs-varid'>ts</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>sum</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-varid'>ei</span><span class='hs-layout'>,</span><span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ts</span><span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- trace</span>
<a name="line-153"></a> <span class='hs-varid'>comult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ei</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>ei</span><span class='hs-layout'>,</span><span class='hs-varid'>ei</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span> <span class='hs-comment'>-- diagonal</span>
<a name="line-154"></a>
<a name="line-155"></a><a name="SetCoalgebra"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>SetCoalgebra</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>SC</span> <span class='hs-varid'>b</span> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span><span class='hs-layout'>,</span><span class='hs-conid'>Ord</span><span class='hs-layout'>,</span><span class='hs-conid'>Show</span><span class='hs-layout'>)</span>
<a name="line-156"></a>
<a name="line-157"></a><a name="instance%20Coalgebra%20k%20(SetCoalgebra%20b)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>SetCoalgebra</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-158"></a> <span class='hs-varid'>counit</span> <span class='hs-layout'>(</span><span class='hs-conid'>V</span> <span class='hs-varid'>ts</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>sum</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span><span class='hs-layout'>,</span><span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ts</span><span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- trace</span>
<a name="line-159"></a> <span class='hs-varid'>comult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>m</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span><span class='hs-layout'>,</span><span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span> <span class='hs-comment'>-- diagonal</span>
<a name="line-160"></a>
<a name="line-161"></a>
<a name="line-162"></a><a name="MonoidCoalgebra"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>MonoidCoalgebra</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>MC</span> <span class='hs-varid'>m</span> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span><span class='hs-layout'>,</span><span class='hs-conid'>Ord</span><span class='hs-layout'>,</span><span class='hs-conid'>Show</span><span class='hs-layout'>)</span>
<a name="line-163"></a>
<a name="line-164"></a><a name="instance%20Coalgebra%20k%20(MonoidCoalgebra%20m)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>Mon</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>MonoidCoalgebra</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-165"></a> <span class='hs-varid'>counit</span> <span class='hs-layout'>(</span><span class='hs-conid'>V</span> <span class='hs-varid'>ts</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>sum</span> <span class='hs-keyglyph'>[</span><span class='hs-keyword'>if</span> <span class='hs-varid'>m</span> <span class='hs-varop'>==</span> <span class='hs-conid'>MC</span> <span class='hs-varid'>munit</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>else</span> <span class='hs-num'>0</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span><span class='hs-layout'>,</span><span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ts</span><span class='hs-keyglyph'>]</span>
<a name="line-166"></a> <span class='hs-varid'>comult</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>linear</span> <span class='hs-varid'>cm</span>
<a name="line-167"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>cm</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>m</span> <span class='hs-varop'>==</span> <span class='hs-conid'>MC</span> <span class='hs-varid'>munit</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span><span class='hs-layout'>,</span><span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>MC</span> <span class='hs-varid'>munit</span><span class='hs-layout'>)</span> <span class='hs-varop'><+></span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-conid'>MC</span> <span class='hs-varid'>munit</span><span class='hs-layout'>,</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span>
<a name="line-168"></a><span class='hs-comment'>-- Brzezinski and Wisbauer, Corings and Comodules, p5</span>
<a name="line-169"></a>
<a name="line-170"></a><span class='hs-comment'>-- Both of the above can be used to define coalgebra structure on polynomial algebras</span>
<a name="line-171"></a><span class='hs-comment'>-- by using the definitions above on the generators (ie the indeterminates) and then extending multiplicatively</span>
<a name="line-172"></a><span class='hs-comment'>-- They are then guaranteed to be algebra morphisms?</span>
<a name="line-173"></a>
<a name="line-174"></a>
<a name="line-175"></a><span class='hs-comment'>-- MODULES AND COMODULES</span>
<a name="line-176"></a>
<a name="line-177"></a><a name="Module"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>m</span> <span class='hs-keyword'>where</span>
<a name="line-178"></a> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>a</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>m</span>
<a name="line-179"></a>
<a name="line-180"></a><a name="*."></a><span class='hs-definition'>r</span> <span class='hs-varop'>*.</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>action</span> <span class='hs-layout'>(</span><span class='hs-varid'>r</span> <span class='hs-varop'>`te`</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span>
<a name="line-181"></a>
<a name="line-182"></a><a name="Comodule"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Comodule</span> <span class='hs-varid'>k</span> <span class='hs-varid'>c</span> <span class='hs-varid'>n</span> <span class='hs-keyword'>where</span>
<a name="line-183"></a> <span class='hs-varid'>coaction</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>c</span> <span class='hs-varid'>n</span><span class='hs-layout'>)</span>
<a name="line-184"></a>
<a name="line-185"></a>
<a name="line-186"></a><a name="instance%20Module%20k%20a%20a"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>where</span>
<a name="line-187"></a> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mult</span>
<a name="line-188"></a>
<a name="line-189"></a><a name="instance%20Comodule%20k%20c%20c"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Coalgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Comodule</span> <span class='hs-varid'>k</span> <span class='hs-varid'>c</span> <span class='hs-varid'>c</span> <span class='hs-keyword'>where</span>
<a name="line-190"></a> <span class='hs-varid'>coaction</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>comult</span>
<a name="line-191"></a>
<a name="line-192"></a><span class='hs-comment'>-- module and comodule instances for tensor products</span>
<a name="line-193"></a>
<a name="line-194"></a><span class='hs-comment'>-- Kassel p57-8</span>
<a name="line-195"></a>
<a name="line-196"></a><a name="instance%20Module%20k%20(Tensor%20a%20a)%20(Tensor%20u%20v)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>u</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>v</span><span class='hs-layout'>,</span> <span class='hs-conid'>Algebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>u</span><span class='hs-layout'>,</span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-197"></a> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>u</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-198"></a> <span class='hs-comment'>-- action x = nf $ x >>= action'</span>
<a name="line-199"></a> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>linear</span> <span class='hs-varid'>action'</span>
<a name="line-200"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>action'</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>a'</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varid'>u</span><span class='hs-layout'>,</span><span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>action</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>u</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varop'>`te`</span> <span class='hs-layout'>(</span><span class='hs-varid'>action</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span><span class='hs-layout'>,</span><span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-201"></a>
<a name="line-202"></a><a name="instance%20Module%20k%20a%20(Tensor%20u%20v)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>u</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>v</span><span class='hs-layout'>,</span> <span class='hs-conid'>Bialgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>u</span><span class='hs-layout'>,</span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-203"></a> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Module</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>u</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-204"></a> <span class='hs-comment'>-- action x = nf $ x >>= action'</span>
<a name="line-205"></a> <span class='hs-varid'>action</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>linear</span> <span class='hs-varid'>action'</span>
<a name="line-206"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>action'</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-layout'>(</span><span class='hs-varid'>u</span><span class='hs-layout'>,</span><span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>action</span> <span class='hs-varop'>$</span> <span class='hs-layout'>(</span><span class='hs-varid'>comult</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varop'>`te`</span> <span class='hs-layout'>(</span><span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>u</span><span class='hs-layout'>,</span><span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-207"></a><span class='hs-comment'>-- !! Overlapping instances</span>
<a name="line-208"></a><span class='hs-comment'>-- If a == Tensor b b, then we have overlapping instance with the previous definition</span>
<a name="line-209"></a><span class='hs-comment'>-- On the other hand, if a == Tensor u v, then we have overlapping instance with the earlier instance</span>
<a name="line-210"></a>
<a name="line-211"></a><a name="instance%20Comodule%20k%20a%20(Tensor%20m%20n)"></a><span class='hs-comment'>-- Kassel p63</span>
<a name="line-212"></a><a name="instance%20Comodule%20k%20a%20(Tensor%20m%20n)"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>Ord</span> <span class='hs-varid'>n</span><span class='hs-layout'>,</span> <span class='hs-conid'>Bialgebra</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-conid'>Comodule</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>Comodule</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-varid'>n</span><span class='hs-layout'>)</span>
<a name="line-213"></a> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Comodule</span> <span class='hs-varid'>k</span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>m</span> <span class='hs-varid'>n</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-214"></a> <span class='hs-varid'>coaction</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>mult</span> <span class='hs-varop'>`tf`</span> <span class='hs-varid'>id</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-varid'>twistm</span> <span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-varid'>coaction</span> <span class='hs-varop'>`tf`</span> <span class='hs-varid'>coaction</span><span class='hs-layout'>)</span>
<a name="line-215"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>twistm</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>nf</span> <span class='hs-varop'>$</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span> <span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>h</span><span class='hs-layout'>,</span><span class='hs-varid'>m</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varid'>h'</span><span class='hs-layout'>,</span><span class='hs-varid'>n</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>h</span><span class='hs-layout'>,</span><span class='hs-varid'>h'</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span><span class='hs-layout'>,</span><span class='hs-varid'>n</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span> <span class='hs-varid'>x</span>
<a name="line-216"></a>
<a name="line-217"></a>
<a name="line-218"></a><span class='hs-comment'>-- PAIRINGS</span>
<a name="line-219"></a>
<a name="line-220"></a><a name="Vect"></a><span class='hs-comment'>-- |A pairing is a non-degenerate bilinear form U x V -> k.</span>
<a name="line-221"></a><a name="Vect"></a><span class='hs-comment'>-- We are typically interested in pairings having additional properties. For example:</span>
<a name="line-222"></a><a name="Vect"></a><span class='hs-comment'>--</span>
<a name="line-223"></a><a name="Vect"></a><span class='hs-comment'>-- * A bialgebra pairing is a pairing between bialgebras A and B such that the mult in A is adjoint to the comult in B, and vice versa, and the unit in A is adjoint to the counit in B, and vice versa.</span>
<a name="line-224"></a><a name="Vect"></a><span class='hs-comment'>--</span>
<a name="line-225"></a><a name="Vect"></a><span class='hs-comment'>-- * A Hopf pairing is a bialgebra pairing between Hopf algebras A and B such that the antipodes in A and B are adjoint.</span>
<a name="line-226"></a><a name="Vect"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>HasPairing</span> <span class='hs-varid'>k</span> <span class='hs-varid'>u</span> <span class='hs-varid'>v</span> <span class='hs-keyword'>where</span>
<a name="line-227"></a> <span class='hs-varid'>pairing</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>u</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-conid'>()</span>
<a name="line-228"></a>
<a name="line-229"></a><a name="pairing'"></a><span class='hs-comment'>-- |The pairing function with a more Haskellish type signature</span>
<a name="line-230"></a><span class='hs-definition'>pairing'</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>HasPairing</span> <span class='hs-varid'>k</span> <span class='hs-varid'>u</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>u</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Vect</span> <span class='hs-varid'>k</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>k</span>
<a name="line-231"></a><span class='hs-definition'>pairing'</span> <span class='hs-varid'>u</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unwrap</span> <span class='hs-layout'>(</span><span class='hs-varid'>pairing</span> <span class='hs-layout'>(</span><span class='hs-varid'>u</span> <span class='hs-varop'>`te`</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-232"></a>
<a name="line-233"></a><a name="instance%20HasPairing%20k%20()%20()"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>HasPairing</span> <span class='hs-varid'>k</span> <span class='hs-conid'>()</span> <span class='hs-conid'>()</span> <span class='hs-keyword'>where</span>
<a name="line-234"></a> <span class='hs-varid'>pairing</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mult</span>
<a name="line-235"></a>
<a name="line-236"></a><a name="instance%20HasPairing%20k%20(Tensor%20u%20u')%20(Tensor%20v%20v')"></a><span class='hs-keyword'>instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>Num</span> <span class='hs-varid'>k</span><span class='hs-layout'>,</span> <span class='hs-conid'>HasPairing</span> <span class='hs-varid'>k</span> <span class='hs-varid'>u</span> <span class='hs-varid'>v</span><span class='hs-layout'>,</span> <span class='hs-conid'>HasPairing</span> <span class='hs-varid'>k</span> <span class='hs-varid'>u'</span> <span class='hs-varid'>v'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>HasPairing</span> <span class='hs-varid'>k</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>u</span> <span class='hs-varid'>u'</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Tensor</span> <span class='hs-varid'>v</span> <span class='hs-varid'>v'</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-237"></a> <span class='hs-varid'>pairing</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mult</span> <span class='hs-varop'>.</span> <span class='hs-layout'>(</span><span class='hs-varid'>pairing</span> <span class='hs-varop'>`tf`</span> <span class='hs-varid'>pairing</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>u</span><span class='hs-layout'>,</span><span class='hs-varid'>u'</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-layout'>(</span><span class='hs-varid'>v</span><span class='hs-layout'>,</span><span class='hs-varid'>v'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>u</span><span class='hs-layout'>,</span><span class='hs-varid'>v</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-layout'>(</span><span class='hs-varid'>u'</span><span class='hs-layout'>,</span><span class='hs-varid'>v'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-238"></a> <span class='hs-comment'>-- pairing = fmap (\((),()) -> ()) . (pairing `tf` pairing) . fmap (\((u,u'),(v,v')) -> ((u,v),(u',v')))</span>
<a name="line-239"></a>
</pre></body>
</html>
|