/usr/share/doc/libghc-maths-doc/html/src/Math-Combinatorics-Hypergraph.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 | <?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/Combinatorics/Hypergraph.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) 2009, David Amos. All rights reserved.</span>
<a name="line-2"></a>
<a name="line-3"></a><span class='hs-comment'>-- |A module defining a type for hypergraphs.</span>
<a name="line-4"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Combinatorics</span><span class='hs-varop'>.</span><span class='hs-conid'>Hypergraph</span> <span class='hs-keyword'>where</span>
<a name="line-5"></a>
<a name="line-6"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>List</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>L</span>
<a name="line-7"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Common</span><span class='hs-varop'>.</span><span class='hs-conid'>ListSet</span>
<a name="line-8"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Core</span><span class='hs-varop'>.</span><span class='hs-conid'>Utils</span> <span class='hs-layout'>(</span><span class='hs-varid'>combinationsOf</span><span class='hs-layout'>)</span>
<a name="line-9"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Combinatorics</span><span class='hs-varop'>.</span><span class='hs-conid'>Graph</span> <span class='hs-varid'>hiding</span> <span class='hs-layout'>(</span><span class='hs-varid'>incidenceMatrix</span><span class='hs-layout'>)</span>
<a name="line-10"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Algebra</span><span class='hs-varop'>.</span><span class='hs-conid'>Group</span><span class='hs-varop'>.</span><span class='hs-conid'>PermutationGroup</span> <span class='hs-layout'>(</span><span class='hs-varid'>orbitB</span><span class='hs-layout'>,</span> <span class='hs-varid'>p</span><span class='hs-layout'>)</span> <span class='hs-comment'>-- needed for construction of Coxeter group</span>
<a name="line-11"></a>
<a name="line-12"></a><span class='hs-comment'>-- not used in this module, only in GHCi</span>
<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'>Algebra</span><span class='hs-varop'>.</span><span class='hs-conid'>Field</span><span class='hs-varop'>.</span><span class='hs-conid'>Base</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'>Algebra</span><span class='hs-varop'>.</span><span class='hs-conid'>Field</span><span class='hs-varop'>.</span><span class='hs-conid'>Extension</span>
<a name="line-15"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Math</span><span class='hs-varop'>.</span><span class='hs-conid'>Combinatorics</span><span class='hs-varop'>.</span><span class='hs-conid'>Design</span> <span class='hs-varid'>hiding</span> <span class='hs-layout'>(</span><span class='hs-varid'>incidenceMatrix</span><span class='hs-layout'>,</span> <span class='hs-varid'>incidenceGraph</span><span class='hs-layout'>,</span> <span class='hs-varid'>dual</span><span class='hs-layout'>,</span> <span class='hs-varid'>isSubset</span><span class='hs-layout'>,</span> <span class='hs-varid'>fanoPlane</span><span class='hs-layout'>)</span>
<a name="line-16"></a>
<a name="line-17"></a>
<a name="line-18"></a><a name="Hypergraph"></a><span class='hs-comment'>-- set system or hypergraph</span>
<a name="line-19"></a><a name="Hypergraph"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</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-20"></a>
<a name="line-21"></a><a name="hypergraph"></a><span class='hs-definition'>hypergraph</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>isSetSystem</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span>
<a name="line-22"></a>
<a name="line-23"></a><a name="toHypergraph"></a><span class='hs-definition'>toHypergraph</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>xs'</span> <span class='hs-varid'>bs'</span> <span class='hs-keyword'>where</span>
<a name="line-24"></a> <span class='hs-varid'>xs'</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-varid'>xs</span>
<a name="line-25"></a> <span class='hs-varid'>bs'</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-varop'>$</span> <span class='hs-varid'>map</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-varid'>bs</span>
<a name="line-26"></a><span class='hs-comment'>-- this still doesn't guarantee that all bs are subset of xs</span>
<a name="line-27"></a>
<a name="line-28"></a>
<a name="line-29"></a><a name="isUniform"></a><span class='hs-comment'>-- |Is this hypergraph uniform - meaning that all blocks are of the same size</span>
<a name="line-30"></a><span class='hs-definition'>isUniform</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-31"></a><span class='hs-definition'>isUniform</span> <span class='hs-varid'>h</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>isSetSystem</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>same</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>length</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span>
<a name="line-32"></a>
<a name="line-33"></a><a name="same"></a><span class='hs-definition'>same</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>all</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span><span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varid'>xs</span>
<a name="line-34"></a><span class='hs-definition'>same</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>True</span>
<a name="line-35"></a>
<a name="line-36"></a>
<a name="line-37"></a>
<a name="line-38"></a><a name="fromGraph"></a><span class='hs-definition'>fromGraph</span> <span class='hs-layout'>(</span><span class='hs-conid'>G</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>es</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>es</span>
<a name="line-39"></a><a name="fromDesign"></a><span class='hs-definition'>fromDesign</span> <span class='hs-layout'>(</span><span class='hs-conid'>D</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>xs</span> <span class='hs-layout'>(</span><span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span>
<a name="line-40"></a><span class='hs-comment'>-- !! should insist that designs have blocks in order</span>
<a name="line-41"></a><span class='hs-comment'>-- !! dual probably doesn't guarantee this at present</span>
<a name="line-42"></a>
<a name="line-43"></a><span class='hs-comment'>{-
<a name="line-44"></a>dual (H xs bs) = toHypergraph (bs, map beta xs) where
<a name="line-45"></a> beta x = filter (x `elem`) bs
<a name="line-46"></a>-}</span>
<a name="line-47"></a>
<a name="line-48"></a>
<a name="line-49"></a>
<a name="line-50"></a><span class='hs-comment'>-- INCIDENCE GRAPH</span>
<a name="line-51"></a>
<a name="line-52"></a><span class='hs-comment'>-- data Incidence a = P a | B [a] deriving (Eq, Ord, Show)</span>
<a name="line-53"></a>
<a name="line-54"></a><span class='hs-comment'>-- compare Design, where we just use Left, Right</span>
<a name="line-55"></a>
<a name="line-56"></a><a name="incidenceGraph"></a><span class='hs-comment'>-- Also called the Levi graph</span>
<a name="line-57"></a><span class='hs-definition'>incidenceGraph</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Graph</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-58"></a><span class='hs-definition'>incidenceGraph</span> <span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>G</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>es</span> <span class='hs-keyword'>where</span>
<a name="line-59"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>map</span> <span class='hs-conid'>Left</span> <span class='hs-varid'>xs</span> <span class='hs-varop'>++</span> <span class='hs-varid'>map</span> <span class='hs-conid'>Right</span> <span class='hs-varid'>bs</span>
<a name="line-60"></a> <span class='hs-varid'>es</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-keyglyph'>[</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Left</span> <span class='hs-varid'>x</span><span class='hs-layout'>,</span> <span class='hs-conid'>Right</span> <span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>bs</span><span class='hs-layout'>,</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span>
<a name="line-61"></a>
<a name="line-62"></a>
<a name="line-63"></a><span class='hs-comment'>-- INCIDENCE MATRIX</span>
<a name="line-64"></a>
<a name="line-65"></a><span class='hs-comment'>-- !! why are we doing this the other way round to the literature ??</span>
<a name="line-66"></a>
<a name="line-67"></a>
<a name="line-68"></a><a name="incidenceMatrix"></a><span class='hs-comment'>-- incidence matrix of a hypergraph</span>
<a name="line-69"></a><span class='hs-comment'>-- (rows and columns indexed by edges and vertices respectively)</span>
<a name="line-70"></a><span class='hs-comment'>-- (warning: in the literature it is often the other way round)</span>
<a name="line-71"></a><span class='hs-definition'>incidenceMatrix</span> <span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>es</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-keyglyph'>[</span><span class='hs-keyword'>if</span> <span class='hs-varid'>v</span> <span class='hs-varop'>`elem`</span> <span class='hs-varid'>e</span> <span class='hs-keyword'>then</span> <span class='hs-num'>1</span> <span class='hs-keyword'>else</span> <span class='hs-num'>0</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>vs</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>es</span><span class='hs-keyglyph'>]</span>
<a name="line-72"></a>
<a name="line-73"></a><a name="fromIncidenceMatrix"></a><span class='hs-definition'>fromIncidenceMatrix</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>es</span> <span class='hs-keyword'>where</span>
<a name="line-74"></a> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>genericLength</span> <span class='hs-varop'>$</span> <span class='hs-varid'>head</span> <span class='hs-varid'>m</span>
<a name="line-75"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-varid'>n</span><span class='hs-keyglyph'>]</span>
<a name="line-76"></a> <span class='hs-varid'>es</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-varop'>$</span> <span class='hs-varid'>map</span> <span class='hs-varid'>edge</span> <span class='hs-varid'>m</span>
<a name="line-77"></a> <span class='hs-varid'>edge</span> <span class='hs-varid'>row</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>v</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-num'>1</span><span class='hs-layout'>,</span><span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>zip</span> <span class='hs-varid'>row</span> <span class='hs-varid'>vs</span><span class='hs-keyglyph'>]</span>
<a name="line-78"></a>
<a name="line-79"></a>
<a name="line-80"></a>
<a name="line-81"></a>
<a name="line-82"></a><span class='hs-comment'>-- isTwoGraph</span>
<a name="line-83"></a>
<a name="line-84"></a>
<a name="line-85"></a><span class='hs-comment'>-- We can represent various incidence structures as hypergraphs,</span>
<a name="line-86"></a><span class='hs-comment'>-- by identifying the lines with the sets of points that they contain</span>
<a name="line-87"></a>
<a name="line-88"></a><a name="isPartialLinearSpace"></a><span class='hs-definition'>isPartialLinearSpace</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-89"></a><span class='hs-definition'>isPartialLinearSpace</span> <span class='hs-varid'>h</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-90"></a> <span class='hs-varid'>isSetSystem</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span> <span class='hs-varop'>&&</span>
<a name="line-91"></a> <span class='hs-varid'>all</span> <span class='hs-layout'>(</span> <span class='hs-layout'>(</span><span class='hs-varop'><=</span><span class='hs-num'>1</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-varid'>length</span> <span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>filter</span> <span class='hs-layout'>(</span><span class='hs-varid'>pair</span> <span class='hs-varop'>`isSubset`</span><span class='hs-layout'>)</span> <span class='hs-varid'>ls</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>pair</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>2</span> <span class='hs-varid'>ps</span><span class='hs-keyglyph'>]</span>
<a name="line-92"></a> <span class='hs-comment'>-- any two points are incident with at most one line</span>
<a name="line-93"></a>
<a name="line-94"></a><a name="isProjectivePlane"></a><span class='hs-comment'>-- Godsil & Royle, p79</span>
<a name="line-95"></a><span class='hs-comment'>-- |Is this hypergraph a projective plane - meaning that any two lines meet in a unique point,</span>
<a name="line-96"></a><span class='hs-comment'>-- and any two points lie on a unique line</span>
<a name="line-97"></a><span class='hs-definition'>isProjectivePlane</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-98"></a><span class='hs-definition'>isProjectivePlane</span> <span class='hs-varid'>h</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-99"></a> <span class='hs-varid'>isSetSystem</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span> <span class='hs-varop'>&&</span>
<a name="line-100"></a> <span class='hs-varid'>all</span> <span class='hs-layout'>(</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span><span class='hs-num'>1</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-varid'>length</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>intersect</span> <span class='hs-varid'>l1</span> <span class='hs-varid'>l2</span> <span class='hs-keyglyph'>|</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>l1</span><span class='hs-layout'>,</span><span class='hs-varid'>l2</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>2</span> <span class='hs-varid'>ls</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>&&</span> <span class='hs-comment'>-- any two lines meet in a unique point</span>
<a name="line-101"></a> <span class='hs-varid'>all</span> <span class='hs-layout'>(</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span><span class='hs-num'>1</span><span class='hs-layout'>)</span> <span class='hs-varop'>.</span> <span class='hs-varid'>length</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>filter</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-varid'>p1</span><span class='hs-layout'>,</span><span class='hs-varid'>p2</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>`isSubset`</span><span class='hs-layout'>)</span> <span class='hs-varid'>ls</span> <span class='hs-keyglyph'>|</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>p1</span><span class='hs-layout'>,</span><span class='hs-varid'>p2</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>2</span> <span class='hs-varid'>ps</span><span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- any two points lie in a unique line</span>
<a name="line-102"></a>
<a name="line-103"></a><a name="isProjectivePlaneTri"></a><span class='hs-comment'>-- |Is this hypergraph a projective plane with a triangle.</span>
<a name="line-104"></a><span class='hs-comment'>-- This is a weak non-degeneracy condition, which eliminates all points on the same line, or all lines through the same point.</span>
<a name="line-105"></a><span class='hs-definition'>isProjectivePlaneTri</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-106"></a><span class='hs-definition'>isProjectivePlaneTri</span> <span class='hs-varid'>h</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-107"></a> <span class='hs-varid'>isProjectivePlane</span> <span class='hs-varid'>h</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>any</span> <span class='hs-varid'>triangle</span> <span class='hs-layout'>(</span><span class='hs-varid'>combinationsOf</span> <span class='hs-num'>3</span> <span class='hs-varid'>ps</span><span class='hs-layout'>)</span>
<a name="line-108"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>triangle</span> <span class='hs-varid'>t</span><span class='hs-keyglyph'>@</span><span class='hs-keyglyph'>[</span><span class='hs-varid'>p1</span><span class='hs-layout'>,</span><span class='hs-varid'>p2</span><span class='hs-layout'>,</span><span class='hs-varid'>p3</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>=</span>
<a name="line-109"></a> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>null</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>l</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ls</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>p1</span><span class='hs-layout'>,</span><span class='hs-varid'>p2</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>`isSubset`</span> <span class='hs-varid'>l</span><span class='hs-layout'>,</span> <span class='hs-varid'>p3</span> <span class='hs-varop'>`notElem`</span> <span class='hs-varid'>l</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>&&</span> <span class='hs-comment'>-- there is a line containing p1,p2 but not p3</span>
<a name="line-110"></a> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>null</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>l</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ls</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>p1</span><span class='hs-layout'>,</span><span class='hs-varid'>p3</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>`isSubset`</span> <span class='hs-varid'>l</span><span class='hs-layout'>,</span> <span class='hs-varid'>p2</span> <span class='hs-varop'>`notElem`</span> <span class='hs-varid'>l</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>&&</span>
<a name="line-111"></a> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>null</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>l</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ls</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>p2</span><span class='hs-layout'>,</span><span class='hs-varid'>p3</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>`isSubset`</span> <span class='hs-varid'>l</span><span class='hs-layout'>,</span> <span class='hs-varid'>p1</span> <span class='hs-varop'>`notElem`</span> <span class='hs-varid'>l</span><span class='hs-keyglyph'>]</span>
<a name="line-112"></a>
<a name="line-113"></a><a name="isProjectivePlaneQuad"></a><span class='hs-comment'>-- |Is this hypergraph a projective plane with a quadrangle.</span>
<a name="line-114"></a><span class='hs-comment'>-- This is a stronger non-degeneracy condition.</span>
<a name="line-115"></a><span class='hs-definition'>isProjectivePlaneQuad</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-116"></a><span class='hs-definition'>isProjectivePlaneQuad</span> <span class='hs-varid'>h</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-117"></a> <span class='hs-varid'>isProjectivePlane</span> <span class='hs-varid'>h</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>any</span> <span class='hs-varid'>quadrangle</span> <span class='hs-layout'>(</span><span class='hs-varid'>combinationsOf</span> <span class='hs-num'>4</span> <span class='hs-varid'>ps</span><span class='hs-layout'>)</span>
<a name="line-118"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>quadrangle</span> <span class='hs-varid'>q</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>all</span> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>collinear</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>combinationsOf</span> <span class='hs-num'>3</span> <span class='hs-varid'>q</span><span class='hs-layout'>)</span> <span class='hs-comment'>-- no three points collinear</span>
<a name="line-119"></a> <span class='hs-varid'>collinear</span> <span class='hs-varid'>ps</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>any</span> <span class='hs-layout'>(</span><span class='hs-varid'>ps</span> <span class='hs-varop'>`isSubset`</span><span class='hs-layout'>)</span> <span class='hs-varid'>ls</span>
<a name="line-120"></a>
<a name="line-121"></a>
<a name="line-122"></a><span class='hs-comment'>-- > isProjectivePlaneQuad $ fromDesign $ pg2 f2</span>
<a name="line-123"></a><span class='hs-comment'>-- True</span>
<a name="line-124"></a>
<a name="line-125"></a>
<a name="line-126"></a><span class='hs-comment'>-- GENERALIZED QUADRANGLES</span>
<a name="line-127"></a>
<a name="line-128"></a><a name="isGeneralizedQuadrangle"></a><span class='hs-comment'>-- Godsil & Royle p81</span>
<a name="line-129"></a><span class='hs-definition'>isGeneralizedQuadrangle</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-130"></a><span class='hs-definition'>isGeneralizedQuadrangle</span> <span class='hs-varid'>h</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-131"></a> <span class='hs-varid'>isPartialLinearSpace</span> <span class='hs-varid'>h</span> <span class='hs-varop'>&&</span>
<a name="line-132"></a> <span class='hs-varid'>all</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>l</span><span class='hs-layout'>,</span><span class='hs-varid'>p</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>unique</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>p'</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>p'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>l</span><span class='hs-layout'>,</span> <span class='hs-varid'>collinear</span> <span class='hs-layout'>(</span><span class='hs-varid'>pair</span> <span class='hs-varid'>p</span> <span class='hs-varid'>p'</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-varid'>l</span><span class='hs-layout'>,</span><span class='hs-varid'>p</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>l</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ls</span><span class='hs-layout'>,</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ps</span><span class='hs-layout'>,</span> <span class='hs-varid'>p</span> <span class='hs-varop'>`notElem`</span> <span class='hs-varid'>l</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>&&</span>
<a name="line-133"></a> <span class='hs-comment'>-- given any line l and point p not on l, there is a unique point p' on l with p and p' collinear</span>
<a name="line-134"></a> <span class='hs-varid'>any</span> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>collinear</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>powerset</span> <span class='hs-varid'>ps</span><span class='hs-layout'>)</span> <span class='hs-varop'>&&</span> <span class='hs-comment'>-- there are non collinear points</span>
<a name="line-135"></a> <span class='hs-varid'>any</span> <span class='hs-layout'>(</span><span class='hs-varid'>not</span> <span class='hs-varop'>.</span> <span class='hs-varid'>concurrent</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>powerset</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-comment'>-- there are non concurrent lines</span>
<a name="line-136"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>unique</span> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>xs</span> <span class='hs-varop'>==</span> <span class='hs-num'>1</span>
<a name="line-137"></a> <span class='hs-varid'>pair</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>x</span> <span class='hs-varop'><</span> <span class='hs-varid'>y</span> <span class='hs-keyword'>then</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-keyglyph'>]</span> <span class='hs-keyword'>else</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>x</span><span class='hs-keyglyph'>]</span>
<a name="line-138"></a> <span class='hs-varid'>collinear</span> <span class='hs-varid'>ps</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>any</span> <span class='hs-layout'>(</span><span class='hs-varid'>ps</span> <span class='hs-varop'>`isSubset`</span><span class='hs-layout'>)</span> <span class='hs-varid'>ls</span>
<a name="line-139"></a> <span class='hs-varid'>concurrent</span> <span class='hs-varid'>ls</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>any</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>p</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>all</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span> <span class='hs-varop'>`elem`</span><span class='hs-layout'>)</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-varid'>ps</span>
<a name="line-140"></a>
<a name="line-141"></a>
<a name="line-142"></a><a name="grid"></a><span class='hs-definition'>grid</span> <span class='hs-varid'>m</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span> <span class='hs-keyword'>where</span>
<a name="line-143"></a> <span class='hs-varid'>ps</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-varid'>i</span><span class='hs-layout'>,</span><span class='hs-varid'>j</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>i</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</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'>j</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-varid'>n</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span>
<a name="line-144"></a> <span class='hs-varid'>ls</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>[</span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-varid'>i</span><span class='hs-layout'>,</span><span class='hs-varid'>j</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>i</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-varid'>m</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>j</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-varid'>n</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- horizontal lines</span>
<a name="line-145"></a> <span class='hs-varop'>++</span> <span class='hs-keyglyph'>[</span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-varid'>i</span><span class='hs-layout'>,</span><span class='hs-varid'>j</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>j</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-varid'>n</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>i</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-varid'>m</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- vertical lines</span>
<a name="line-146"></a>
<a name="line-147"></a><a name="dualGrid"></a><span class='hs-definition'>dualGrid</span> <span class='hs-varid'>m</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fromGraph</span> <span class='hs-varop'>$</span> <span class='hs-varid'>kb</span> <span class='hs-varid'>m</span> <span class='hs-varid'>n</span>
<a name="line-148"></a><span class='hs-comment'>-- the lines of the grid are the points of the dual, and the points of the grid are the lines of the dual</span>
<a name="line-149"></a>
<a name="line-150"></a><a name="isGenQuadrangle'"></a><span class='hs-definition'>isGenQuadrangle'</span> <span class='hs-varid'>h</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>diameter</span> <span class='hs-varid'>g</span> <span class='hs-varop'>==</span> <span class='hs-num'>4</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>girth</span> <span class='hs-varid'>g</span> <span class='hs-varop'>==</span> <span class='hs-num'>8</span> <span class='hs-comment'>-- !! plus non-degeneracy conditions</span>
<a name="line-151"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>incidenceGraph</span> <span class='hs-varid'>h</span>
<a name="line-152"></a>
<a name="line-153"></a>
<a name="line-154"></a><span class='hs-comment'>-- CONFIGURATIONS</span>
<a name="line-155"></a>
<a name="line-156"></a><a name="isConfiguration"></a><span class='hs-comment'>-- <a href="http://en.wikipedia.org/wiki/Projective_configuration">http://en.wikipedia.org/wiki/Projective_configuration</a></span>
<a name="line-157"></a><span class='hs-comment'>-- |Is this hypergraph a (projective) configuration.</span>
<a name="line-158"></a><span class='hs-definition'>isConfiguration</span> <span class='hs-keyglyph'>::</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-keyglyph'>=></span> <span class='hs-conid'>Hypergraph</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-159"></a><span class='hs-definition'>isConfiguration</span> <span class='hs-varid'>h</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>ps</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-160"></a> <span class='hs-varid'>isUniform</span> <span class='hs-varid'>h</span> <span class='hs-varop'>&&</span> <span class='hs-comment'>-- a set system, with each line incident with the same number of points</span>
<a name="line-161"></a> <span class='hs-varid'>same</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>length</span> <span class='hs-layout'>(</span><span class='hs-varid'>filter</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span> <span class='hs-varop'>`elem`</span><span class='hs-layout'>)</span> <span class='hs-varid'>ls</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>ps</span><span class='hs-keyglyph'>]</span> <span class='hs-comment'>-- each point is incident with the same number of lines</span>
<a name="line-162"></a>
<a name="line-163"></a>
<a name="line-164"></a><a name="fanoPlane"></a><span class='hs-definition'>fanoPlane</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Hypergraph</span> <span class='hs-conid'>Integer</span>
<a name="line-165"></a><span class='hs-definition'>fanoPlane</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toHypergraph</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-layout'>,</span><span class='hs-num'>2</span><span class='hs-layout'>,</span><span class='hs-num'>4</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>2</span><span class='hs-layout'>,</span><span class='hs-num'>3</span><span class='hs-layout'>,</span><span class='hs-num'>5</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>3</span><span class='hs-layout'>,</span><span class='hs-num'>4</span><span class='hs-layout'>,</span><span class='hs-num'>6</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>4</span><span class='hs-layout'>,</span><span class='hs-num'>5</span><span class='hs-layout'>,</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>5</span><span class='hs-layout'>,</span><span class='hs-num'>6</span><span class='hs-layout'>,</span><span class='hs-num'>1</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>6</span><span class='hs-layout'>,</span><span class='hs-num'>7</span><span class='hs-layout'>,</span><span class='hs-num'>2</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>7</span><span class='hs-layout'>,</span><span class='hs-num'>1</span><span class='hs-layout'>,</span><span class='hs-num'>3</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span>
<a name="line-166"></a>
<a name="line-167"></a><a name="heawoodGraph"></a><span class='hs-comment'>-- |The Heawood graph is the incidence graph of the Fano plane</span>
<a name="line-168"></a><span class='hs-definition'>heawoodGraph</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Graph</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-conid'>Integer</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-169"></a><span class='hs-definition'>heawoodGraph</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>incidenceGraph</span> <span class='hs-varid'>fanoPlane</span>
<a name="line-170"></a>
<a name="line-171"></a>
<a name="line-172"></a><a name="desarguesConfiguration"></a><span class='hs-definition'>desarguesConfiguration</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Hypergraph</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span>
<a name="line-173"></a><span class='hs-definition'>desarguesConfiguration</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span> <span class='hs-keyword'>where</span>
<a name="line-174"></a> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>2</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-num'>5</span><span class='hs-keyglyph'>]</span>
<a name="line-175"></a> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>xs</span><span class='hs-layout'>,</span> <span class='hs-varid'>x</span> <span class='hs-varop'>`isSubset`</span> <span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>3</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-num'>5</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span>
<a name="line-176"></a>
<a name="line-177"></a><a name="desarguesGraph"></a><span class='hs-definition'>desarguesGraph</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Graph</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-178"></a><span class='hs-definition'>desarguesGraph</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>incidenceGraph</span> <span class='hs-varid'>desarguesConfiguration</span>
<a name="line-179"></a>
<a name="line-180"></a>
<a name="line-181"></a><a name="pappusConfiguration"></a><span class='hs-definition'>pappusConfiguration</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Hypergraph</span> <span class='hs-conid'>Integer</span>
<a name="line-182"></a><span class='hs-definition'>pappusConfiguration</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>H</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span> <span class='hs-keyword'>where</span>
<a name="line-183"></a> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-num'>9</span><span class='hs-keyglyph'>]</span>
<a name="line-184"></a> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-keyglyph'>[</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-layout'>,</span><span class='hs-num'>2</span><span class='hs-layout'>,</span><span class='hs-num'>3</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>4</span><span class='hs-layout'>,</span><span class='hs-num'>5</span><span class='hs-layout'>,</span><span class='hs-num'>6</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>7</span><span class='hs-layout'>,</span><span class='hs-num'>8</span><span class='hs-layout'>,</span><span class='hs-num'>9</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-layout'>,</span><span class='hs-num'>5</span><span class='hs-layout'>,</span><span class='hs-num'>9</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-layout'>,</span><span class='hs-num'>6</span><span class='hs-layout'>,</span><span class='hs-num'>8</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>2</span><span class='hs-layout'>,</span><span class='hs-num'>4</span><span class='hs-layout'>,</span><span class='hs-num'>9</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>3</span><span class='hs-layout'>,</span><span class='hs-num'>4</span><span class='hs-layout'>,</span><span class='hs-num'>8</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>2</span><span class='hs-layout'>,</span><span class='hs-num'>6</span><span class='hs-layout'>,</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>3</span><span class='hs-layout'>,</span><span class='hs-num'>5</span><span class='hs-layout'>,</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span>
<a name="line-185"></a>
<a name="line-186"></a><a name="pappusGraph"></a><span class='hs-definition'>pappusGraph</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Graph</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-conid'>Integer</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-187"></a><span class='hs-definition'>pappusGraph</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>incidenceGraph</span> <span class='hs-varid'>pappusConfiguration</span>
<a name="line-188"></a>
<a name="line-189"></a>
<a name="line-190"></a>
<a name="line-191"></a><a name="coxeterGraph"></a><span class='hs-comment'>-- !! no particular reason why the following is here rather than elsewhere</span>
<a name="line-192"></a><span class='hs-comment'>{-
<a name="line-193"></a>triples = combinationsOf 3 [1..7]
<a name="line-194"></a>
<a name="line-195"></a>heptads = [ [a,b,c,d,e,f,g] | a <- triples,
<a name="line-196"></a> b <- triples, a < b, meetOne b a,
<a name="line-197"></a> c <- triples, b < c, all (meetOne c) [a,b],
<a name="line-198"></a> d <- triples, c < d, all (meetOne d) [a,b,c],
<a name="line-199"></a> e <- triples, d < e, all (meetOne e) [a,b,c,d],
<a name="line-200"></a> f <- triples, e < f, all (meetOne f) [a,b,c,d,e],
<a name="line-201"></a> g <- triples, f < g, all (meetOne g) [a,b,c,d,e,f],
<a name="line-202"></a> foldl intersect [1..7] [a,b,c,d,e,f,g] == [] ]
<a name="line-203"></a> where meetOne x y = length (intersect x y) == 1
<a name="line-204"></a> -- each pair of triples meet in exactly one point, and there is no point in all of them - Godsil & Royle p69
<a name="line-205"></a> -- (so these are the projective planes over 7 points)
<a name="line-206"></a>-}</span>
<a name="line-207"></a><span class='hs-comment'>-- Godsil & Royle p69</span>
<a name="line-208"></a><span class='hs-definition'>coxeterGraph</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Graph</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span>
<a name="line-209"></a><span class='hs-definition'>coxeterGraph</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>G</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>es</span> <span class='hs-keyword'>where</span>
<a name="line-210"></a> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>[</span><span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span>
<a name="line-211"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>L</span><span class='hs-varop'>.</span><span class='hs-varid'>sort</span> <span class='hs-varop'>$</span> <span class='hs-varid'>concatMap</span> <span class='hs-layout'>(</span><span class='hs-varid'>orbitB</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>g</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-layout'>,</span><span class='hs-num'>2</span><span class='hs-layout'>,</span><span class='hs-num'>4</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>3</span><span class='hs-layout'>,</span><span class='hs-num'>5</span><span class='hs-layout'>,</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>3</span><span class='hs-layout'>,</span><span class='hs-num'>6</span><span class='hs-layout'>,</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span><span class='hs-keyglyph'>[</span><span class='hs-num'>5</span><span class='hs-layout'>,</span><span class='hs-num'>6</span><span class='hs-layout'>,</span><span class='hs-num'>7</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span>
<a name="line-212"></a> <span class='hs-varid'>es</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>e</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>e</span><span class='hs-keyglyph'>@</span><span class='hs-keyglyph'>[</span><span class='hs-varid'>v1</span><span class='hs-layout'>,</span><span class='hs-varid'>v2</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>2</span> <span class='hs-varid'>vs</span><span class='hs-layout'>,</span> <span class='hs-varid'>disjoint</span> <span class='hs-varid'>v1</span> <span class='hs-varid'>v2</span><span class='hs-keyglyph'>]</span>
<a name="line-213"></a>
<a name="line-214"></a><span class='hs-comment'>-- is this the incidence graph of a hypergraph involving heptads over triples?</span>
<a name="line-215"></a>
<a name="line-216"></a>
<a name="line-217"></a><a name="duads"></a><span class='hs-comment'>-- edges of K6</span>
<a name="line-218"></a><span class='hs-definition'>duads</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>2</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>1</span><span class='hs-keyglyph'>..</span><span class='hs-num'>6</span><span class='hs-keyglyph'>]</span>
<a name="line-219"></a>
<a name="line-220"></a><a name="synthemes"></a><span class='hs-comment'>-- 1-factors of K6</span>
<a name="line-221"></a><span class='hs-comment'>-- 15 different ways to pick three disjoint duads from [1..6]</span>
<a name="line-222"></a><span class='hs-definition'>synthemes</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>d1</span><span class='hs-layout'>,</span><span class='hs-varid'>d2</span><span class='hs-layout'>,</span><span class='hs-varid'>d3</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>d1</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>duads</span><span class='hs-layout'>,</span>
<a name="line-223"></a> <span class='hs-varid'>d2</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>duads</span><span class='hs-layout'>,</span> <span class='hs-varid'>d2</span> <span class='hs-varop'>></span> <span class='hs-varid'>d1</span><span class='hs-layout'>,</span> <span class='hs-varid'>disjoint</span> <span class='hs-varid'>d1</span> <span class='hs-varid'>d2</span><span class='hs-layout'>,</span>
<a name="line-224"></a> <span class='hs-varid'>d3</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>duads</span><span class='hs-layout'>,</span> <span class='hs-varid'>d3</span> <span class='hs-varop'>></span> <span class='hs-varid'>d2</span><span class='hs-layout'>,</span> <span class='hs-varid'>disjoint</span> <span class='hs-varid'>d1</span> <span class='hs-varid'>d3</span><span class='hs-layout'>,</span> <span class='hs-varid'>disjoint</span> <span class='hs-varid'>d2</span> <span class='hs-varid'>d3</span> <span class='hs-keyglyph'>]</span>
<a name="line-225"></a>
<a name="line-226"></a><a name="tutteCoxeterGraph"></a><span class='hs-comment'>-- |The Tutte-Coxeter graph, also called the Tutte 8-cage</span>
<a name="line-227"></a><span class='hs-definition'>tutteCoxeterGraph</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Graph</span> <span class='hs-layout'>(</span><span class='hs-conid'>Either</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>[</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>Integer</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span>
<a name="line-228"></a><span class='hs-definition'>tutteCoxeterGraph</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>incidenceGraph</span> <span class='hs-varop'>$</span> <span class='hs-conid'>H</span> <span class='hs-varid'>duads</span> <span class='hs-varid'>synthemes</span>
<a name="line-229"></a>
<a name="line-230"></a>
<a name="line-231"></a><a name="intersectionGraph"></a><span class='hs-comment'>-- Also known as line graph</span>
<a name="line-232"></a><span class='hs-definition'>intersectionGraph</span> <span class='hs-layout'>(</span><span class='hs-conid'>H</span> <span class='hs-varid'>xs</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>G</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>es</span> <span class='hs-keyword'>where</span>
<a name="line-233"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>bs</span>
<a name="line-234"></a> <span class='hs-varid'>es</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>pair</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>pair</span><span class='hs-keyglyph'>@</span><span class='hs-keyglyph'>[</span><span class='hs-varid'>b1</span><span class='hs-layout'>,</span><span class='hs-varid'>b2</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>combinationsOf</span> <span class='hs-num'>2</span> <span class='hs-varid'>bs</span><span class='hs-layout'>,</span> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-varid'>disjoint</span> <span class='hs-varid'>b1</span> <span class='hs-varid'>b2</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span>
</pre></body>
</html>
|