/usr/share/doc/libghc-djinn-lib-doc/html/src/Djinn-LJT.html is in libghc-djinn-lib-doc 0.0.1.2-8build1.
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 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | <?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>src/Djinn/LJT.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>--</span>
<a name="line-2"></a><span class='hs-comment'>-- Copyright (c) 2005, 2008 Lennart Augustsson</span>
<a name="line-3"></a><span class='hs-comment'>-- See LICENSE for licensing details.</span>
<a name="line-4"></a><span class='hs-comment'>--</span>
<a name="line-5"></a><span class='hs-comment'>-- Intuitionistic theorem prover</span>
<a name="line-6"></a><span class='hs-comment'>-- Written by Roy Dyckhoff, Summer 1991</span>
<a name="line-7"></a><span class='hs-comment'>-- Modified to use the LWB syntax Summer 1997</span>
<a name="line-8"></a><span class='hs-comment'>-- and simplified in various ways...</span>
<a name="line-9"></a><span class='hs-comment'>--</span>
<a name="line-10"></a><span class='hs-comment'>-- Translated to Haskell by Lennart Augustsson December 2005</span>
<a name="line-11"></a><span class='hs-comment'>--</span>
<a name="line-12"></a><span class='hs-comment'>-- Incorporates the Vorob'ev-Hudelmaier etc calculus (I call it LJT)</span>
<a name="line-13"></a><span class='hs-comment'>-- See RD's paper in JSL 1992:</span>
<a name="line-14"></a><span class='hs-comment'>-- "Contraction-free calculi for intuitionistic logic"</span>
<a name="line-15"></a><span class='hs-comment'>--</span>
<a name="line-16"></a><span class='hs-comment'>-- Torkel Franzen (at SICS) gave me good ideas about how to write this</span>
<a name="line-17"></a><span class='hs-comment'>-- properly, taking account of first-argument indexing,</span>
<a name="line-18"></a><span class='hs-comment'>-- and I learnt a trick or two from Neil Tennant's "Autologic" book.</span>
<a name="line-19"></a>
<a name="line-20"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Djinn</span><span class='hs-varop'>.</span><span class='hs-conid'>LJT</span> <span class='hs-layout'>(</span>
<a name="line-21"></a> <span class='hs-keyword'>module</span> <span class='hs-conid'>Djinn</span><span class='hs-varop'>.</span><span class='hs-conid'>LJTFormula</span><span class='hs-layout'>,</span>
<a name="line-22"></a> <span class='hs-varid'>provable</span><span class='hs-layout'>,</span>
<a name="line-23"></a> <span class='hs-varid'>prove</span><span class='hs-layout'>,</span>
<a name="line-24"></a> <span class='hs-conid'>Proof</span><span class='hs-layout'>,</span>
<a name="line-25"></a> <span class='hs-conid'>MoreSolutions</span>
<a name="line-26"></a><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-27"></a>
<a name="line-28"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Applicative</span> <span class='hs-layout'>(</span><span class='hs-conid'>Applicative</span><span class='hs-layout'>,</span> <span class='hs-conid'>Alternative</span><span class='hs-layout'>,</span> <span class='hs-varid'>pure</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> <span class='hs-varid'>empty</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-29"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span>
<a name="line-30"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>List</span> <span class='hs-layout'>(</span><span class='hs-varid'>partition</span><span class='hs-layout'>)</span>
<a name="line-31"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Debug</span><span class='hs-varop'>.</span><span class='hs-conid'>Trace</span>
<a name="line-32"></a>
<a name="line-33"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Djinn</span><span class='hs-varop'>.</span><span class='hs-conid'>LJTFormula</span>
<a name="line-34"></a>
<a name="line-35"></a><a name="mtrace"></a><span class='hs-definition'>mtrace</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>String</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span>
<a name="line-36"></a><span class='hs-definition'>mtrace</span> <span class='hs-varid'>m</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>debug</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>trace</span> <span class='hs-varid'>m</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>x</span>
<a name="line-37"></a><a name="wrapM"></a><span class='hs-comment'>-- wrap :: (Show a, Show b) => String -> a -> b -> b</span>
<a name="line-38"></a><span class='hs-comment'>-- wrap fun args ret = mtrace (fun ++ ": " ++ show args) $</span>
<a name="line-39"></a><span class='hs-comment'>-- let o = show ret in seq o $</span>
<a name="line-40"></a><span class='hs-comment'>-- mtrace (fun ++ " returns: " ++ o) ret</span>
<a name="line-41"></a><span class='hs-definition'>wrapM</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-conid'>Show</span> <span class='hs-varid'>a</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'>Monad</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>String</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-varid'>b</span>
<a name="line-42"></a><span class='hs-definition'>wrapM</span> <span class='hs-varid'>fun</span> <span class='hs-varid'>args</span> <span class='hs-varid'>mret</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-43"></a> <span class='hs-conid'>()</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mtrace</span> <span class='hs-layout'>(</span><span class='hs-varid'>fun</span> <span class='hs-varop'>++</span> <span class='hs-str'>": "</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>args</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-44"></a> <span class='hs-varid'>ret</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mret</span>
<a name="line-45"></a> <span class='hs-conid'>()</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mtrace</span> <span class='hs-layout'>(</span><span class='hs-varid'>fun</span> <span class='hs-varop'>++</span> <span class='hs-str'>" returns: "</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>ret</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-46"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>ret</span>
<a name="line-47"></a>
<a name="line-48"></a><a name="debug"></a><span class='hs-definition'>debug</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Bool</span>
<a name="line-49"></a><span class='hs-definition'>debug</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
<a name="line-50"></a>
<a name="line-51"></a><a name="MoreSolutions"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>MoreSolutions</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Bool</span>
<a name="line-52"></a>
<a name="line-53"></a><a name="provable"></a><span class='hs-definition'>provable</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-54"></a><span class='hs-definition'>provable</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>not</span> <span class='hs-varop'>$</span> <span class='hs-varid'>null</span> <span class='hs-varop'>$</span> <span class='hs-varid'>prove</span> <span class='hs-conid'>False</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>a</span>
<a name="line-55"></a>
<a name="line-56"></a><a name="prove"></a><span class='hs-definition'>prove</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MoreSolutions</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-conid'>Symbol</span><span class='hs-layout'>,</span> <span class='hs-conid'>Formula</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Proof</span><span class='hs-keyglyph'>]</span>
<a name="line-57"></a><span class='hs-definition'>prove</span> <span class='hs-varid'>more</span> <span class='hs-varid'>env</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>runP</span> <span class='hs-varop'>$</span> <span class='hs-varid'>redtop</span> <span class='hs-varid'>more</span> <span class='hs-varid'>env</span> <span class='hs-varid'>a</span>
<a name="line-58"></a>
<a name="line-59"></a><a name="redtop"></a><span class='hs-definition'>redtop</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MoreSolutions</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-conid'>Symbol</span><span class='hs-layout'>,</span> <span class='hs-conid'>Formula</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-60"></a><span class='hs-definition'>redtop</span> <span class='hs-varid'>more</span> <span class='hs-varid'>ifs</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-61"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>form</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>foldr</span> <span class='hs-layout'>(</span><span class='hs-conop'>:-></span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>snd</span> <span class='hs-varid'>ifs</span><span class='hs-layout'>)</span>
<a name="line-62"></a> <span class='hs-varid'>p</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant</span> <span class='hs-varid'>more</span> <span class='hs-conid'>[]</span> <span class='hs-conid'>[]</span> <span class='hs-conid'>[]</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>form</span>
<a name="line-63"></a> <span class='hs-varid'>nf</span> <span class='hs-layout'>(</span><span class='hs-varid'>foldl</span> <span class='hs-conid'>Apply</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varop'>.</span> <span class='hs-varid'>fst</span><span class='hs-layout'>)</span> <span class='hs-varid'>ifs</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-64"></a>
<a name="line-65"></a><a name="Proof"></a><span class='hs-comment'>------------------------------</span>
<a name="line-66"></a><a name="Proof"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>Proof</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Term</span>
<a name="line-67"></a>
<a name="line-68"></a><a name="subst"></a><span class='hs-definition'>subst</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Term</span>
<a name="line-69"></a><span class='hs-definition'>subst</span> <span class='hs-varid'>b</span> <span class='hs-varid'>x</span> <span class='hs-varid'>term</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>sub</span> <span class='hs-varid'>term</span>
<a name="line-70"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>sub</span> <span class='hs-varid'>t</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>s'</span><span class='hs-layout'>)</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'>s'</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>copy</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>b</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-varid'>t</span>
<a name="line-71"></a> <span class='hs-varid'>sub</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>liftM</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>sub</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span>
<a name="line-72"></a> <span class='hs-varid'>sub</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-varid'>t1</span> <span class='hs-varid'>t2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>liftM2</span> <span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-varid'>sub</span> <span class='hs-varid'>t1</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>sub</span> <span class='hs-varid'>t2</span><span class='hs-layout'>)</span>
<a name="line-73"></a> <span class='hs-varid'>sub</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-varid'>t</span>
<a name="line-74"></a>
<a name="line-75"></a><a name="copy"></a><span class='hs-definition'>copy</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-conid'>Symbol</span><span class='hs-layout'>,</span> <span class='hs-conid'>Symbol</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Term</span>
<a name="line-76"></a><span class='hs-definition'>copy</span> <span class='hs-varid'>r</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Var</span> <span class='hs-varop'>$</span> <span class='hs-varid'>maybe</span> <span class='hs-varid'>s</span> <span class='hs-varid'>id</span> <span class='hs-varop'>$</span> <span class='hs-varid'>lookup</span> <span class='hs-varid'>s</span> <span class='hs-varid'>r</span>
<a name="line-77"></a><span class='hs-definition'>copy</span> <span class='hs-varid'>r</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>s</span> <span class='hs-varid'>t</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-78"></a> <span class='hs-varid'>s'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"c"</span>
<a name="line-79"></a> <span class='hs-varid'>liftM</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>s'</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>copy</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span> <span class='hs-varid'>s'</span><span class='hs-layout'>)</span><span class='hs-conop'>:</span><span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-varid'>t</span>
<a name="line-80"></a><span class='hs-definition'>copy</span> <span class='hs-varid'>r</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-varid'>t1</span> <span class='hs-varid'>t2</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>liftM2</span> <span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-varid'>copy</span> <span class='hs-varid'>r</span> <span class='hs-varid'>t1</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>copy</span> <span class='hs-varid'>r</span> <span class='hs-varid'>t2</span><span class='hs-layout'>)</span>
<a name="line-81"></a><span class='hs-definition'>copy</span> <span class='hs-sel'>_r</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-varid'>t</span>
<a name="line-82"></a>
<a name="line-83"></a><span class='hs-comment'>------------------------------</span>
<a name="line-84"></a>
<a name="line-85"></a><span class='hs-comment'>-- XXX The symbols used in the functions below must not clash</span>
<a name="line-86"></a><span class='hs-comment'>-- XXX with any symbols from newSym.</span>
<a name="line-87"></a>
<a name="line-88"></a><a name="applyAtom"></a><span class='hs-definition'>applyAtom</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span>
<a name="line-89"></a><span class='hs-definition'>applyAtom</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Apply</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span>
<a name="line-90"></a>
<a name="line-91"></a><a name="curryt"></a><span class='hs-definition'>curryt</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span>
<a name="line-92"></a><span class='hs-definition'>curryt</span> <span class='hs-varid'>n</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>foldr</span> <span class='hs-conid'>Lam</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-varid'>applys</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ctuple</span> <span class='hs-varid'>n</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-conid'>Var</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>xs</span>
<a name="line-93"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-conid'>Symbol</span> <span class='hs-layout'>(</span><span class='hs-str'>"x_"</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>i</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'>0</span> <span class='hs-keyglyph'>..</span> <span class='hs-varid'>n</span><span class='hs-comment'>-</span><span class='hs-num'>1</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span>
<a name="line-94"></a>
<a name="line-95"></a><a name="inj"></a><span class='hs-definition'>inj</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ConsDesc</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span>
<a name="line-96"></a><span class='hs-definition'>inj</span> <span class='hs-varid'>cd</span> <span class='hs-varid'>i</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>x</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Apply</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-conid'>Cinj</span> <span class='hs-varid'>cd</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-97"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Symbol</span> <span class='hs-str'>"x"</span>
<a name="line-98"></a>
<a name="line-99"></a><a name="applyImp"></a><span class='hs-definition'>applyImp</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span>
<a name="line-100"></a><span class='hs-definition'>applyImp</span> <span class='hs-varid'>p</span> <span class='hs-varid'>q</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Apply</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-varid'>q</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>y</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Apply</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>x</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-101"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Symbol</span> <span class='hs-str'>"x"</span>
<a name="line-102"></a> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Symbol</span> <span class='hs-str'>"y"</span>
<a name="line-103"></a>
<a name="line-104"></a><a name="cImpDImpFalse"></a><span class='hs-comment'>-- ((c->d)->false) -> ((c->false)->false, d->false)</span>
<a name="line-105"></a><span class='hs-comment'>-- p : (c->d)->false)</span>
<a name="line-106"></a><span class='hs-comment'>-- replace p1 and p2 with the components of the pair</span>
<a name="line-107"></a><span class='hs-definition'>cImpDImpFalse</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Term</span>
<a name="line-108"></a><span class='hs-definition'>cImpDImpFalse</span> <span class='hs-varid'>p1</span> <span class='hs-varid'>p2</span> <span class='hs-varid'>cdf</span> <span class='hs-varid'>gp</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-109"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>p1b</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>cf</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Apply</span> <span class='hs-varid'>cdf</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>x</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ccases</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>cf</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
<a name="line-110"></a> <span class='hs-varid'>p2b</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>d</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Apply</span> <span class='hs-varid'>cdf</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>c</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Var</span> <span class='hs-varid'>d</span>
<a name="line-111"></a> <span class='hs-varid'>cf</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Symbol</span> <span class='hs-str'>"cf"</span>
<a name="line-112"></a> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Symbol</span> <span class='hs-str'>"x"</span>
<a name="line-113"></a> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Symbol</span> <span class='hs-str'>"d"</span>
<a name="line-114"></a> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Symbol</span> <span class='hs-str'>"c"</span>
<a name="line-115"></a> <span class='hs-varid'>subst</span> <span class='hs-varid'>p1b</span> <span class='hs-varid'>p1</span> <span class='hs-varid'>gp</span> <span class='hs-varop'>>>=</span> <span class='hs-varid'>subst</span> <span class='hs-varid'>p2b</span> <span class='hs-varid'>p2</span>
<a name="line-116"></a>
<a name="line-117"></a><span class='hs-comment'>------------------------------</span>
<a name="line-118"></a>
<a name="line-119"></a><span class='hs-comment'>-- More simplifications:</span>
<a name="line-120"></a><span class='hs-comment'>-- split where no variables used can be removed</span>
<a name="line-121"></a><span class='hs-comment'>-- either with equal RHS can me merged.</span>
<a name="line-122"></a>
<a name="line-123"></a><a name="nf"></a><span class='hs-comment'>-- Compute the normal form</span>
<a name="line-124"></a><span class='hs-definition'>nf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Term</span>
<a name="line-125"></a><span class='hs-definition'>nf</span> <span class='hs-varid'>ee</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>spine</span> <span class='hs-varid'>ee</span> <span class='hs-conid'>[]</span>
<a name="line-126"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyword'>as</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span> <span class='hs-varid'>a'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>nf</span> <span class='hs-varid'>a</span><span class='hs-layout'>;</span> <span class='hs-varid'>spine</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-varid'>a'</span> <span class='hs-conop'>:</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span>
<a name="line-127"></a> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>s</span> <span class='hs-varid'>e</span><span class='hs-layout'>)</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>liftM</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>nf</span> <span class='hs-varid'>e</span><span class='hs-layout'>)</span>
<a name="line-128"></a> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>s</span> <span class='hs-varid'>e</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-conop'>:</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span> <span class='hs-varid'>e'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>subst</span> <span class='hs-varid'>a</span> <span class='hs-varid'>s</span> <span class='hs-varid'>e</span><span class='hs-layout'>;</span> <span class='hs-varid'>spine</span> <span class='hs-varid'>e'</span> <span class='hs-keyword'>as</span>
<a name="line-129"></a> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-conid'>Csplit</span> <span class='hs-varid'>n</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span> <span class='hs-conop'>:</span> <span class='hs-varid'>tup</span> <span class='hs-conop'>:</span> <span class='hs-varid'>args</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>istup</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>n</span> <span class='hs-varop'><=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-varid'>applys</span> <span class='hs-varid'>b</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-varid'>args</span>
<a name="line-130"></a> <span class='hs-keyword'>where</span> <span class='hs-layout'>(</span><span class='hs-varid'>istup</span><span class='hs-layout'>,</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>getTup</span> <span class='hs-varid'>tup</span>
<a name="line-131"></a> <span class='hs-varid'>getTup</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ctuple</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conid'>True</span><span class='hs-layout'>,</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span>
<a name="line-132"></a> <span class='hs-varid'>getTup</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>tf</span><span class='hs-layout'>,</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>getTup</span> <span class='hs-varid'>f</span> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>tf</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span><span class='hs-conop'>:</span><span class='hs-keyword'>as</span><span class='hs-layout'>)</span>
<a name="line-133"></a> <span class='hs-varid'>getTup</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-conid'>False</span><span class='hs-layout'>,</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span>
<a name="line-134"></a> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ccases</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>e</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ccases</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>spine</span> <span class='hs-varid'>e</span> <span class='hs-keyword'>as</span>
<a name="line-135"></a> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ccases</span> <span class='hs-varid'>cds</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-conid'>Cinj</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-conop'>:</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>length</span> <span class='hs-keyword'>as</span> <span class='hs-varop'>>=</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>spine</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-layout'>(</span><span class='hs-keyword'>as</span><span class='hs-varop'>!!</span><span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>drop</span> <span class='hs-varid'>n</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span>
<a name="line-136"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>n</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>cds</span>
<a name="line-137"></a> <span class='hs-varid'>spine</span> <span class='hs-varid'>f</span> <span class='hs-keyword'>as</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>applys</span> <span class='hs-varid'>f</span> <span class='hs-keyword'>as</span>
<a name="line-138"></a>
<a name="line-139"></a>
<a name="line-140"></a><span class='hs-comment'>------------------------------</span>
<a name="line-141"></a><span class='hs-comment'>----- Our Proof monad, P, a monad with state and multiple results</span>
<a name="line-142"></a>
<a name="line-143"></a><a name="P"></a><span class='hs-comment'>-- Note, this is the non-standard way to combine state with multiple</span>
<a name="line-144"></a><a name="P"></a><span class='hs-comment'>-- results. But this is much better for backtracking.</span>
<a name="line-145"></a><a name="P"></a><span class='hs-keyword'>newtype</span> <span class='hs-conid'>P</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-layout'>{</span> <span class='hs-varid'>unP</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>PS</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-conid'>PS</span><span class='hs-layout'>,</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span> <span class='hs-layout'>}</span>
<a name="line-146"></a>
<a name="line-147"></a><a name="instance%20Applicative%20P"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Applicative</span> <span class='hs-conid'>P</span> <span class='hs-keyword'>where</span>
<a name="line-148"></a> <span class='hs-varid'>pure</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span>
<a name="line-149"></a> <span class='hs-layout'>(</span><span class='hs-varop'><*></span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>ap</span>
<a name="line-150"></a>
<a name="line-151"></a><a name="instance%20Monad%20P"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Monad</span> <span class='hs-conid'>P</span> <span class='hs-keyword'>where</span>
<a name="line-152"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span>
<a name="line-153"></a> <span class='hs-conid'>P</span> <span class='hs-varid'>m</span> <span class='hs-varop'>>>=</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-varid'>s'</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'>m</span> <span class='hs-varid'>s</span><span class='hs-layout'>,</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>unP</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varid'>s'</span> <span class='hs-keyglyph'>]</span>
<a name="line-154"></a>
<a name="line-155"></a><a name="instance%20Functor%20P"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Functor</span> <span class='hs-conid'>P</span> <span class='hs-keyword'>where</span>
<a name="line-156"></a> <span class='hs-varid'>fmap</span> <span class='hs-varid'>f</span> <span class='hs-layout'>(</span><span class='hs-conid'>P</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span> <span class='hs-layout'>(</span><span class='hs-varid'>s'</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-layout'>(</span><span class='hs-varid'>s'</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'>m</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>]</span>
<a name="line-157"></a>
<a name="line-158"></a><a name="instance%20Alternative%20P"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Alternative</span> <span class='hs-conid'>P</span> <span class='hs-keyword'>where</span>
<a name="line-159"></a> <span class='hs-varid'>empty</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mzero</span>
<a name="line-160"></a> <span class='hs-layout'>(</span><span class='hs-varop'><|></span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mplus</span>
<a name="line-161"></a>
<a name="line-162"></a><a name="instance%20MonadPlus%20P"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>MonadPlus</span> <span class='hs-conid'>P</span> <span class='hs-keyword'>where</span>
<a name="line-163"></a> <span class='hs-varid'>mzero</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-sel'>_s</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>[]</span>
<a name="line-164"></a> <span class='hs-conid'>P</span> <span class='hs-varid'>fxs</span> <span class='hs-varop'>`mplus`</span> <span class='hs-conid'>P</span> <span class='hs-varid'>fys</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>fxs</span> <span class='hs-varid'>s</span> <span class='hs-varop'>++</span> <span class='hs-varid'>fys</span> <span class='hs-varid'>s</span>
<a name="line-165"></a>
<a name="line-166"></a><a name="PS"></a><span class='hs-comment'>-- The state, just an integer for generating new variables</span>
<a name="line-167"></a><a name="PS"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>PS</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>PS</span> <span class='hs-varop'>!</span><span class='hs-conid'>Integer</span>
<a name="line-168"></a>
<a name="line-169"></a><a name="startPS"></a><span class='hs-definition'>startPS</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>PS</span>
<a name="line-170"></a><span class='hs-definition'>startPS</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>PS</span> <span class='hs-num'>1</span>
<a name="line-171"></a>
<a name="line-172"></a><a name="nextInt"></a><span class='hs-definition'>nextInt</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>P</span> <span class='hs-conid'>Integer</span>
<a name="line-173"></a><span class='hs-definition'>nextInt</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-layout'>(</span><span class='hs-conid'>PS</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-conid'>PS</span> <span class='hs-layout'>(</span><span class='hs-varid'>i</span><span class='hs-varop'>+</span><span class='hs-num'>1</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span>
<a name="line-174"></a>
<a name="line-175"></a><a name="none"></a><span class='hs-definition'>none</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>P</span> <span class='hs-varid'>a</span>
<a name="line-176"></a><span class='hs-definition'>none</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mzero</span>
<a name="line-177"></a>
<a name="line-178"></a><a name="many"></a><span class='hs-definition'>many</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-conid'>P</span> <span class='hs-varid'>a</span>
<a name="line-179"></a><span class='hs-definition'>many</span> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>zip</span> <span class='hs-layout'>(</span><span class='hs-varid'>repeat</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>xs</span>
<a name="line-180"></a>
<a name="line-181"></a><a name="atMostOne"></a><span class='hs-definition'>atMostOne</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>P</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-varid'>a</span>
<a name="line-182"></a><span class='hs-definition'>atMostOne</span> <span class='hs-layout'>(</span><span class='hs-conid'>P</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>P</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>take</span> <span class='hs-num'>1</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span>
<a name="line-183"></a>
<a name="line-184"></a><a name="runP"></a><span class='hs-definition'>runP</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>P</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span>
<a name="line-185"></a><span class='hs-definition'>runP</span> <span class='hs-layout'>(</span><span class='hs-conid'>P</span> <span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>map</span> <span class='hs-varid'>snd</span> <span class='hs-layout'>(</span><span class='hs-varid'>m</span> <span class='hs-varid'>startPS</span><span class='hs-layout'>)</span>
<a name="line-186"></a>
<a name="line-187"></a>
<a name="line-188"></a><span class='hs-comment'>------------------------------</span>
<a name="line-189"></a><span class='hs-comment'>----- Atomic formulae</span>
<a name="line-190"></a>
<a name="line-191"></a><a name="AtomF"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>AtomF</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>AtomF</span> <span class='hs-conid'>Term</span> <span class='hs-conid'>Symbol</span>
<a name="line-192"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span><span class='hs-layout'>)</span>
<a name="line-193"></a>
<a name="line-194"></a><a name="instance%20Show%20AtomF"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Show</span> <span class='hs-conid'>AtomF</span> <span class='hs-keyword'>where</span>
<a name="line-195"></a> <span class='hs-varid'>show</span> <span class='hs-layout'>(</span><span class='hs-conid'>AtomF</span> <span class='hs-varid'>p</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>show</span> <span class='hs-varid'>p</span> <span class='hs-varop'>++</span> <span class='hs-str'>":"</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>s</span>
<a name="line-196"></a>
<a name="line-197"></a><a name="AtomFs"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>AtomFs</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>AtomF</span><span class='hs-keyglyph'>]</span>
<a name="line-198"></a>
<a name="line-199"></a><a name="findAtoms"></a><span class='hs-definition'>findAtoms</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomFs</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Term</span><span class='hs-keyglyph'>]</span>
<a name="line-200"></a><span class='hs-definition'>findAtoms</span> <span class='hs-varid'>s</span> <span class='hs-varid'>atoms</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>AtomF</span> <span class='hs-varid'>p</span> <span class='hs-varid'>s'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>atoms</span><span class='hs-layout'>,</span> <span class='hs-varid'>s</span> <span class='hs-varop'>==</span> <span class='hs-varid'>s'</span> <span class='hs-keyglyph'>]</span>
<a name="line-201"></a>
<a name="line-202"></a><span class='hs-comment'>--removeAtom :: Symbol -> AtomFs -> AtomFs</span>
<a name="line-203"></a><span class='hs-comment'>--removeAtom s atoms = [ a | a@(AtomF _ s') <- atoms, s /= s' ]</span>
<a name="line-204"></a>
<a name="line-205"></a><a name="addAtom"></a><span class='hs-definition'>addAtom</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>AtomF</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomFs</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomFs</span>
<a name="line-206"></a><span class='hs-definition'>addAtom</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>as</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>a</span> <span class='hs-varop'>`elem`</span> <span class='hs-keyword'>as</span> <span class='hs-keyword'>then</span> <span class='hs-keyword'>as</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>a</span> <span class='hs-conop'>:</span> <span class='hs-keyword'>as</span>
<a name="line-207"></a>
<a name="line-208"></a><span class='hs-comment'>------------------------------</span>
<a name="line-209"></a><span class='hs-comment'>----- Implications of one atom</span>
<a name="line-210"></a>
<a name="line-211"></a><a name="AtomImp"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>AtomImp</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>AtomImp</span> <span class='hs-conid'>Symbol</span> <span class='hs-conid'>Antecedents</span>
<a name="line-212"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Show</span><span class='hs-layout'>)</span>
<a name="line-213"></a><a name="AtomImps"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>AtomImps</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>AtomImp</span><span class='hs-keyglyph'>]</span>
<a name="line-214"></a>
<a name="line-215"></a><a name="extract"></a><span class='hs-definition'>extract</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>AtomImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>Antecedent</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>,</span> <span class='hs-conid'>AtomImps</span><span class='hs-layout'>)</span>
<a name="line-216"></a><span class='hs-definition'>extract</span> <span class='hs-varid'>aatomImps</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-varid'>atomImp</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>AtomImp</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span> <span class='hs-varid'>atomImps</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=</span>
<a name="line-217"></a> <span class='hs-keyword'>case</span> <span class='hs-varid'>compare</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a'</span> <span class='hs-keyword'>of</span>
<a name="line-218"></a> <span class='hs-conid'>GT</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>rbs</span><span class='hs-layout'>,</span> <span class='hs-varid'>restImps</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>extract</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>rbs</span><span class='hs-layout'>,</span> <span class='hs-varid'>atomImp</span> <span class='hs-conop'>:</span> <span class='hs-varid'>restImps</span><span class='hs-layout'>)</span>
<a name="line-219"></a> <span class='hs-conid'>EQ</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>bs</span><span class='hs-layout'>,</span> <span class='hs-varid'>atomImps</span><span class='hs-layout'>)</span>
<a name="line-220"></a> <span class='hs-conid'>LT</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>[]</span><span class='hs-layout'>,</span> <span class='hs-varid'>aatomImps</span><span class='hs-layout'>)</span>
<a name="line-221"></a><span class='hs-definition'>extract</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</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>
<a name="line-222"></a>
<a name="line-223"></a><a name="insert"></a><span class='hs-definition'>insert</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>AtomImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomImp</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomImps</span>
<a name="line-224"></a><span class='hs-definition'>insert</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>ai</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>ai</span> <span class='hs-keyglyph'>]</span>
<a name="line-225"></a><span class='hs-definition'>insert</span> <span class='hs-varid'>aatomImps</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-varid'>atomImp</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>AtomImp</span> <span class='hs-varid'>a'</span> <span class='hs-varid'>bs'</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span> <span class='hs-varid'>atomImps</span><span class='hs-layout'>)</span> <span class='hs-varid'>ai</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>AtomImp</span> <span class='hs-varid'>a</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-226"></a> <span class='hs-keyword'>case</span> <span class='hs-varid'>compare</span> <span class='hs-varid'>a</span> <span class='hs-varid'>a'</span> <span class='hs-keyword'>of</span>
<a name="line-227"></a> <span class='hs-conid'>GT</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>atomImp</span> <span class='hs-conop'>:</span> <span class='hs-varid'>insert</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>ai</span>
<a name="line-228"></a> <span class='hs-conid'>EQ</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomImp</span> <span class='hs-varid'>a</span> <span class='hs-layout'>(</span><span class='hs-varid'>bs</span> <span class='hs-varop'>++</span> <span class='hs-varid'>bs'</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span> <span class='hs-varid'>atomImps</span>
<a name="line-229"></a> <span class='hs-conid'>LT</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>ai</span> <span class='hs-conop'>:</span> <span class='hs-varid'>aatomImps</span>
<a name="line-230"></a>
<a name="line-231"></a><span class='hs-comment'>------------------------------</span>
<a name="line-232"></a><span class='hs-comment'>----- Nested implications, (a -> b) -> c</span>
<a name="line-233"></a>
<a name="line-234"></a><a name="NestImp"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>NestImp</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>NestImp</span> <span class='hs-conid'>Term</span> <span class='hs-conid'>Formula</span> <span class='hs-conid'>Formula</span> <span class='hs-conid'>Formula</span> <span class='hs-comment'>-- NestImp a b c represents (a :-> b) :-> c</span>
<a name="line-235"></a> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Eq</span><span class='hs-layout'>)</span>
<a name="line-236"></a>
<a name="line-237"></a><a name="instance%20Show%20NestImp"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Show</span> <span class='hs-conid'>NestImp</span> <span class='hs-keyword'>where</span>
<a name="line-238"></a> <span class='hs-varid'>show</span> <span class='hs-layout'>(</span><span class='hs-conid'>NestImp</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>show</span> <span class='hs-varop'>$</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>c</span>
<a name="line-239"></a>
<a name="line-240"></a><a name="NestImps"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>NestImps</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>NestImp</span><span class='hs-keyglyph'>]</span>
<a name="line-241"></a>
<a name="line-242"></a><a name="addNestImp"></a><span class='hs-definition'>addNestImp</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>NestImp</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>NestImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>NestImps</span>
<a name="line-243"></a><span class='hs-definition'>addNestImp</span> <span class='hs-varid'>n</span> <span class='hs-varid'>ns</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>n</span> <span class='hs-varop'>`elem`</span> <span class='hs-varid'>ns</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>ns</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>n</span> <span class='hs-conop'>:</span> <span class='hs-varid'>ns</span>
<a name="line-244"></a>
<a name="line-245"></a><a name="heuristics"></a><span class='hs-comment'>------------------------------</span>
<a name="line-246"></a><span class='hs-comment'>----- Ordering of nested implications</span>
<a name="line-247"></a><span class='hs-definition'>heuristics</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Bool</span>
<a name="line-248"></a><span class='hs-definition'>heuristics</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>True</span>
<a name="line-249"></a>
<a name="line-250"></a><a name="order"></a><span class='hs-definition'>order</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>NestImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>NestImps</span>
<a name="line-251"></a><span class='hs-definition'>order</span> <span class='hs-varid'>nestImps</span> <span class='hs-varid'>g</span> <span class='hs-varid'>atomImps</span> <span class='hs-keyglyph'>=</span>
<a name="line-252"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>heuristics</span>
<a name="line-253"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>nestImps</span>
<a name="line-254"></a> <span class='hs-keyword'>else</span> <span class='hs-keyword'>let</span> <span class='hs-varid'>good_for</span> <span class='hs-layout'>(</span><span class='hs-conid'>NestImp</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-layout'>(</span><span class='hs-conid'>Disj</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>True</span>
<a name="line-255"></a> <span class='hs-varid'>good_for</span> <span class='hs-layout'>(</span><span class='hs-conid'>NestImp</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>g'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>g</span> <span class='hs-varop'>==</span> <span class='hs-varid'>g'</span>
<a name="line-256"></a> <span class='hs-varid'>nice_for</span> <span class='hs-layout'>(</span><span class='hs-conid'>NestImp</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-layout'>(</span><span class='hs-conid'>PVar</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-257"></a> <span class='hs-keyword'>case</span> <span class='hs-varid'>extract</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>s</span> <span class='hs-keyword'>of</span>
<a name="line-258"></a> <span class='hs-layout'>(</span><span class='hs-varid'>bs'</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>let</span> <span class='hs-varid'>bs</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-conid'>A</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>bs'</span><span class='hs-keyglyph'>]</span> <span class='hs-keyword'>in</span> <span class='hs-varid'>g</span> <span class='hs-varop'>`elem`</span> <span class='hs-varid'>bs</span> <span class='hs-varop'>||</span> <span class='hs-varid'>false</span> <span class='hs-varop'>`elem`</span> <span class='hs-varid'>bs</span>
<a name="line-259"></a> <span class='hs-varid'>nice_for</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>False</span>
<a name="line-260"></a> <span class='hs-layout'>(</span><span class='hs-varid'>good</span><span class='hs-layout'>,</span> <span class='hs-varid'>ok</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>partition</span> <span class='hs-varid'>good_for</span> <span class='hs-varid'>nestImps</span>
<a name="line-261"></a> <span class='hs-layout'>(</span><span class='hs-varid'>nice</span><span class='hs-layout'>,</span> <span class='hs-varid'>bad</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>partition</span> <span class='hs-varid'>nice_for</span> <span class='hs-varid'>ok</span>
<a name="line-262"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>good</span> <span class='hs-varop'>++</span> <span class='hs-varid'>nice</span> <span class='hs-varop'>++</span> <span class='hs-varid'>bad</span>
<a name="line-263"></a>
<a name="line-264"></a><a name="newSym"></a><span class='hs-comment'>------------------------------</span>
<a name="line-265"></a><span class='hs-comment'>----- Generate a new unique variable</span>
<a name="line-266"></a><span class='hs-definition'>newSym</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>String</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Symbol</span>
<a name="line-267"></a><span class='hs-definition'>newSym</span> <span class='hs-varid'>pre</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-268"></a> <span class='hs-varid'>i</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>nextInt</span>
<a name="line-269"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Symbol</span> <span class='hs-varop'>$</span> <span class='hs-varid'>pre</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>i</span>
<a name="line-270"></a>
<a name="line-271"></a><a name="select"></a><span class='hs-comment'>------------------------------</span>
<a name="line-272"></a><span class='hs-comment'>----- Generate all ways to select one element of a list</span>
<a name="line-273"></a><span class='hs-definition'>select</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-conid'>P</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span><span class='hs-layout'>,</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-274"></a><span class='hs-definition'>select</span> <span class='hs-varid'>zs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>many</span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>del</span> <span class='hs-varid'>n</span> <span class='hs-varid'>zs</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-num'>0</span> <span class='hs-keyglyph'>..</span> <span class='hs-varid'>length</span> <span class='hs-varid'>zs</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>]</span>
<a name="line-275"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>del</span> <span class='hs-num'>0</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-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span>
<a name="line-276"></a> <span class='hs-varid'>del</span> <span class='hs-varid'>n</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-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>ys</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>del</span> <span class='hs-layout'>(</span><span class='hs-varid'>n</span><span class='hs-comment'>-</span><span class='hs-num'>1</span><span class='hs-layout'>)</span> <span class='hs-varid'>xs</span> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span> <span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-varid'>ys</span><span class='hs-layout'>)</span>
<a name="line-277"></a> <span class='hs-varid'>del</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"select"</span>
<a name="line-278"></a>
<a name="line-279"></a><span class='hs-comment'>------------------------------</span>
<a name="line-280"></a><span class='hs-comment'>-----</span>
<a name="line-281"></a>
<a name="line-282"></a><a name="Antecedent"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>Antecedent</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>A</span> <span class='hs-conid'>Term</span> <span class='hs-conid'>Formula</span> <span class='hs-keyword'>deriving</span> <span class='hs-layout'>(</span><span class='hs-conid'>Show</span><span class='hs-layout'>)</span>
<a name="line-283"></a><a name="Antecedents"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Antecedent</span><span class='hs-keyglyph'>]</span>
<a name="line-284"></a>
<a name="line-285"></a><a name="Goal"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Formula</span>
<a name="line-286"></a>
<a name="line-287"></a><a name="redant"></a><span class='hs-comment'>--</span>
<a name="line-288"></a><span class='hs-comment'>-- This is the main loop of the proof search.</span>
<a name="line-289"></a><span class='hs-comment'>--</span>
<a name="line-290"></a><span class='hs-comment'>-- The redant functions reduce antecedents and the redsucc</span>
<a name="line-291"></a><span class='hs-comment'>-- function reduces the goal (succedent).</span>
<a name="line-292"></a><span class='hs-comment'>--</span>
<a name="line-293"></a><span class='hs-comment'>-- The antecedents are kept in four groups: Antecedents, AtomImps, NestImps, AtomFs</span>
<a name="line-294"></a><span class='hs-comment'>-- Antecedents contains as yet unclassified antecedents; the redant functions</span>
<a name="line-295"></a><span class='hs-comment'>-- go through them one by one and reduces and classifies them.</span>
<a name="line-296"></a><span class='hs-comment'>-- AtomImps contains implications of the form (a -> b), where `a' is an atom.</span>
<a name="line-297"></a><span class='hs-comment'>-- To speed up the processing it is stored as a map from the `a' to all the</span>
<a name="line-298"></a><span class='hs-comment'>-- formulae it implies.</span>
<a name="line-299"></a><span class='hs-comment'>-- NestImps contains implications of the form ((b -> c) -> d)</span>
<a name="line-300"></a><span class='hs-comment'>-- AtomFs contains atomic formulae.</span>
<a name="line-301"></a><span class='hs-comment'>--</span>
<a name="line-302"></a><span class='hs-comment'>-- There is also a proof object associated with each antecedent.</span>
<a name="line-303"></a><span class='hs-comment'>--</span>
<a name="line-304"></a><span class='hs-definition'>redant</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MoreSolutions</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>NestImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomFs</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-305"></a><span class='hs-definition'>redant</span> <span class='hs-varid'>more</span> <span class='hs-varid'>antes</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>nestImps</span> <span class='hs-varid'>atoms</span> <span class='hs-varid'>goal</span> <span class='hs-keyglyph'>=</span>
<a name="line-306"></a> <span class='hs-varid'>wrapM</span> <span class='hs-str'>"redant"</span> <span class='hs-layout'>(</span><span class='hs-varid'>antes</span><span class='hs-layout'>,</span> <span class='hs-varid'>atomImps</span><span class='hs-layout'>,</span> <span class='hs-varid'>nestImps</span><span class='hs-layout'>,</span> <span class='hs-varid'>atoms</span><span class='hs-layout'>,</span> <span class='hs-varid'>goal</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-307"></a> <span class='hs-keyword'>case</span> <span class='hs-varid'>antes</span> <span class='hs-keyword'>of</span>
<a name="line-308"></a> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>redsucc</span> <span class='hs-varid'>goal</span>
<a name="line-309"></a> <span class='hs-varid'>a</span><span class='hs-conop'>:</span><span class='hs-varid'>l</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>redant1</span> <span class='hs-varid'>a</span> <span class='hs-varid'>l</span> <span class='hs-varid'>goal</span>
<a name="line-310"></a> <span class='hs-keyword'>where</span> <span class='hs-varid'>redant0</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>redant</span> <span class='hs-varid'>more</span> <span class='hs-varid'>l</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>nestImps</span> <span class='hs-varid'>atoms</span> <span class='hs-varid'>g</span>
<a name="line-311"></a> <span class='hs-varid'>redant1</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Antecedent</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-312"></a> <span class='hs-varid'>redant1</span> <span class='hs-varid'>a</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-varid'>p</span> <span class='hs-varid'>f</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-313"></a> <span class='hs-varid'>wrapM</span> <span class='hs-str'>"redant1"</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'>l</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>atomImps</span><span class='hs-layout'>,</span> <span class='hs-varid'>nestImps</span><span class='hs-layout'>,</span> <span class='hs-varid'>atoms</span><span class='hs-layout'>,</span> <span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-314"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>f</span> <span class='hs-varop'>==</span> <span class='hs-varid'>g</span>
<a name="line-315"></a> <span class='hs-keyword'>then</span> <span class='hs-comment'>-- The goal is the antecedent, we're done.</span>
<a name="line-316"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>more</span>
<a name="line-317"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>return</span> <span class='hs-varid'>p</span> <span class='hs-varop'>`mplus`</span> <span class='hs-varid'>redant1'</span> <span class='hs-varid'>a</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-318"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-varid'>p</span>
<a name="line-319"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>redant1'</span> <span class='hs-varid'>a</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-320"></a>
<a name="line-321"></a> <span class='hs-comment'>-- Reduce the first antecedent</span>
<a name="line-322"></a> <span class='hs-varid'>redant1'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Antecedent</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-323"></a> <span class='hs-varid'>redant1'</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>PVar</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-324"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>af</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>AtomF</span> <span class='hs-varid'>p</span> <span class='hs-varid'>s</span>
<a name="line-325"></a> <span class='hs-layout'>(</span><span class='hs-varid'>bs</span><span class='hs-layout'>,</span> <span class='hs-varid'>restAtomImps</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>extract</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>s</span>
<a name="line-326"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>redant</span> <span class='hs-varid'>more</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Apply</span> <span class='hs-varid'>f</span> <span class='hs-varid'>p</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>A</span> <span class='hs-varid'>f</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>bs</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>++</span> <span class='hs-varid'>l</span><span class='hs-layout'>)</span> <span class='hs-varid'>restAtomImps</span> <span class='hs-varid'>nestImps</span> <span class='hs-layout'>(</span><span class='hs-varid'>addAtom</span> <span class='hs-varid'>af</span> <span class='hs-varid'>atoms</span><span class='hs-layout'>)</span> <span class='hs-varid'>g</span>
<a name="line-327"></a> <span class='hs-varid'>redant1'</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Conj</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-328"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mapM</span> <span class='hs-layout'>(</span><span class='hs-varid'>const</span> <span class='hs-layout'>(</span><span class='hs-varid'>newSym</span> <span class='hs-str'>"v"</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>bs</span>
<a name="line-329"></a> <span class='hs-varid'>gp</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant0</span> <span class='hs-layout'>(</span><span class='hs-varid'>zipWith</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span> <span class='hs-varid'>v</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>bs</span> <span class='hs-varop'>++</span> <span class='hs-varid'>l</span><span class='hs-layout'>)</span> <span class='hs-varid'>g</span>
<a name="line-330"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>applys</span> <span class='hs-layout'>(</span><span class='hs-conid'>Csplit</span> <span class='hs-layout'>(</span><span class='hs-varid'>length</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>foldr</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>gp</span> <span class='hs-varid'>vs</span><span class='hs-layout'>,</span> <span class='hs-varid'>p</span><span class='hs-keyglyph'>]</span>
<a name="line-331"></a> <span class='hs-varid'>redant1'</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Disj</span> <span class='hs-varid'>ds</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-332"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mapM</span> <span class='hs-layout'>(</span><span class='hs-varid'>const</span> <span class='hs-layout'>(</span><span class='hs-varid'>newSym</span> <span class='hs-str'>"d"</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>ds</span>
<a name="line-333"></a> <span class='hs-varid'>ps</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mapM</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</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-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>redant1</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>zip</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>ds</span><span class='hs-layout'>)</span>
<a name="line-334"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>null</span> <span class='hs-varid'>ds</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>g</span> <span class='hs-varop'>==</span> <span class='hs-conid'>Disj</span> <span class='hs-conid'>[]</span>
<a name="line-335"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>return</span> <span class='hs-varid'>p</span>
<a name="line-336"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>applys</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ccases</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>fst</span> <span class='hs-varid'>ds</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span> <span class='hs-conop'>:</span> <span class='hs-varid'>zipWith</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>ps</span><span class='hs-layout'>)</span>
<a name="line-337"></a> <span class='hs-varid'>redant1'</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>redantimp</span> <span class='hs-varid'>p</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-338"></a>
<a name="line-339"></a> <span class='hs-varid'>redantimp</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-340"></a> <span class='hs-varid'>redantimp</span> <span class='hs-varid'>t</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>a</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-341"></a> <span class='hs-varid'>wrapM</span> <span class='hs-str'>"redantimp"</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span><span class='hs-layout'>,</span><span class='hs-varid'>d</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-342"></a> <span class='hs-varid'>redantimp'</span> <span class='hs-varid'>t</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>a</span> <span class='hs-varid'>g</span>
<a name="line-343"></a>
<a name="line-344"></a> <span class='hs-comment'>-- Reduce an implication antecedent</span>
<a name="line-345"></a> <span class='hs-varid'>redantimp'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-346"></a> <span class='hs-comment'>-- p : PVar s -> b</span>
<a name="line-347"></a> <span class='hs-varid'>redantimp'</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>PVar</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>redantimpatom</span> <span class='hs-varid'>p</span> <span class='hs-varid'>s</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-348"></a> <span class='hs-comment'>-- p : (c & d) -> b</span>
<a name="line-349"></a> <span class='hs-varid'>redantimp'</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Conj</span> <span class='hs-varid'>cs</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-350"></a> <span class='hs-varid'>x</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"x"</span>
<a name="line-351"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>imp</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>foldr</span> <span class='hs-layout'>(</span><span class='hs-conop'>:-></span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-varid'>cs</span>
<a name="line-352"></a> <span class='hs-varid'>gp</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant1</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varid'>imp</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-353"></a> <span class='hs-varid'>subst</span> <span class='hs-layout'>(</span><span class='hs-varid'>curryt</span> <span class='hs-layout'>(</span><span class='hs-varid'>length</span> <span class='hs-varid'>cs</span><span class='hs-layout'>)</span> <span class='hs-varid'>p</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-varid'>gp</span>
<a name="line-354"></a> <span class='hs-comment'>-- p : (c | d) -> b</span>
<a name="line-355"></a> <span class='hs-varid'>redantimp'</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Disj</span> <span class='hs-varid'>ds</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-356"></a> <span class='hs-varid'>vs</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mapM</span> <span class='hs-layout'>(</span><span class='hs-varid'>const</span> <span class='hs-layout'>(</span><span class='hs-varid'>newSym</span> <span class='hs-str'>"d"</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>ds</span>
<a name="line-357"></a> <span class='hs-varid'>gp</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant0</span> <span class='hs-layout'>(</span><span class='hs-varid'>zipWith</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span> <span class='hs-varid'>v</span> <span class='hs-layout'>(</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>d</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>ds</span> <span class='hs-varop'>++</span> <span class='hs-varid'>l</span><span class='hs-layout'>)</span> <span class='hs-varid'>g</span>
<a name="line-358"></a> <span class='hs-varid'>foldM</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span> <span class='hs-varid'>r</span> <span class='hs-layout'>(</span><span class='hs-varid'>i</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-varid'>cd</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>subst</span> <span class='hs-layout'>(</span><span class='hs-varid'>inj</span> <span class='hs-varid'>cd</span> <span class='hs-varid'>i</span> <span class='hs-varid'>p</span><span class='hs-layout'>)</span> <span class='hs-varid'>v</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span> <span class='hs-varid'>gp</span> <span class='hs-layout'>(</span><span class='hs-varid'>zip3</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0</span><span class='hs-keyglyph'>..</span><span class='hs-keyglyph'>]</span> <span class='hs-varid'>vs</span> <span class='hs-varid'>ds</span><span class='hs-layout'>)</span>
<a name="line-359"></a> <span class='hs-comment'>-- p : (c -> d) -> b</span>
<a name="line-360"></a> <span class='hs-varid'>redantimp'</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>redantimpimp</span> <span class='hs-varid'>p</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-361"></a>
<a name="line-362"></a> <span class='hs-varid'>redantimpimp</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-363"></a> <span class='hs-varid'>redantimpimp</span> <span class='hs-varid'>f</span> <span class='hs-varid'>b</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>a</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-364"></a> <span class='hs-varid'>wrapM</span> <span class='hs-str'>"redantimpimp"</span> <span class='hs-layout'>(</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span><span class='hs-varid'>c</span><span class='hs-layout'>,</span><span class='hs-varid'>d</span><span class='hs-layout'>,</span><span class='hs-varid'>a</span><span class='hs-layout'>,</span><span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-365"></a> <span class='hs-varid'>redantimpimp'</span> <span class='hs-varid'>f</span> <span class='hs-varid'>b</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>a</span> <span class='hs-varid'>g</span>
<a name="line-366"></a>
<a name="line-367"></a> <span class='hs-comment'>-- Reduce a double implication antecedent</span>
<a name="line-368"></a> <span class='hs-varid'>redantimpimp'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-369"></a> <span class='hs-comment'>-- next clause exploits ~(C->D) <=> (~~C & ~D)</span>
<a name="line-370"></a> <span class='hs-comment'>-- which isn't helpful when D = false</span>
<a name="line-371"></a> <span class='hs-varid'>redantimpimp'</span> <span class='hs-varid'>p</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-layout'>(</span><span class='hs-conid'>Disj</span> <span class='hs-conid'>[]</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>d</span> <span class='hs-varop'>/=</span> <span class='hs-varid'>false</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-372"></a> <span class='hs-varid'>x</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"x"</span>
<a name="line-373"></a> <span class='hs-varid'>y</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"y"</span>
<a name="line-374"></a> <span class='hs-varid'>gp</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redantimpimp</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varid'>c</span> <span class='hs-varid'>false</span> <span class='hs-varid'>false</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>d</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>false</span><span class='hs-layout'>)</span> <span class='hs-conop'>:</span> <span class='hs-varid'>l</span><span class='hs-layout'>)</span> <span class='hs-varid'>g</span>
<a name="line-375"></a> <span class='hs-varid'>cImpDImpFalse</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-varid'>p</span> <span class='hs-varid'>gp</span>
<a name="line-376"></a> <span class='hs-comment'>-- p : (c -> d) -> b</span>
<a name="line-377"></a> <span class='hs-varid'>redantimpimp'</span> <span class='hs-varid'>p</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>redant</span> <span class='hs-varid'>more</span> <span class='hs-varid'>l</span> <span class='hs-varid'>atomImps</span> <span class='hs-layout'>(</span><span class='hs-varid'>addNestImp</span> <span class='hs-layout'>(</span><span class='hs-conid'>NestImp</span> <span class='hs-varid'>p</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varid'>nestImps</span><span class='hs-layout'>)</span> <span class='hs-varid'>atoms</span> <span class='hs-varid'>g</span>
<a name="line-378"></a>
<a name="line-379"></a> <span class='hs-comment'>-- Reduce an atomic implication</span>
<a name="line-380"></a> <span class='hs-varid'>redantimpatom</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-381"></a> <span class='hs-varid'>redantimpatom</span> <span class='hs-varid'>p</span> <span class='hs-varid'>s</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-382"></a> <span class='hs-varid'>wrapM</span> <span class='hs-str'>"redantimpatom"</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>,</span><span class='hs-varid'>l</span><span class='hs-layout'>,</span><span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-383"></a> <span class='hs-varid'>redantimpatom'</span> <span class='hs-varid'>p</span> <span class='hs-varid'>s</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-384"></a>
<a name="line-385"></a> <span class='hs-varid'>redantimpatom'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Term</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Antecedents</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-386"></a> <span class='hs-varid'>redantimpatom'</span> <span class='hs-varid'>p</span> <span class='hs-varid'>s</span> <span class='hs-varid'>b</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-387"></a> <span class='hs-keyword'>do</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>cutSearch</span> <span class='hs-varid'>more</span> <span class='hs-varop'>$</span> <span class='hs-varid'>many</span> <span class='hs-layout'>(</span><span class='hs-varid'>findAtoms</span> <span class='hs-varid'>s</span> <span class='hs-varid'>atoms</span><span class='hs-layout'>)</span>
<a name="line-388"></a> <span class='hs-varid'>x</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"x"</span>
<a name="line-389"></a> <span class='hs-varid'>gp</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant1</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-varid'>l</span> <span class='hs-varid'>g</span>
<a name="line-390"></a> <span class='hs-varid'>mtrace</span> <span class='hs-str'>"redantimpatom: LLL"</span> <span class='hs-varop'>$</span> <span class='hs-varid'>subst</span> <span class='hs-layout'>(</span><span class='hs-varid'>applyAtom</span> <span class='hs-varid'>p</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-varid'>gp</span>
<a name="line-391"></a> <span class='hs-varop'>`mplus`</span>
<a name="line-392"></a> <span class='hs-layout'>(</span><span class='hs-varid'>mtrace</span> <span class='hs-str'>"redantimpatom: RRR"</span> <span class='hs-varop'>$</span>
<a name="line-393"></a> <span class='hs-varid'>redant</span> <span class='hs-varid'>more</span> <span class='hs-varid'>l</span> <span class='hs-layout'>(</span><span class='hs-varid'>insert</span> <span class='hs-varid'>atomImps</span> <span class='hs-layout'>(</span><span class='hs-conid'>AtomImp</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>A</span> <span class='hs-varid'>p</span> <span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>nestImps</span> <span class='hs-varid'>atoms</span> <span class='hs-varid'>g</span><span class='hs-layout'>)</span>
<a name="line-394"></a>
<a name="line-395"></a> <span class='hs-comment'>-- Reduce the goal, with all antecedents already being classified</span>
<a name="line-396"></a> <span class='hs-varid'>redsucc</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-397"></a> <span class='hs-varid'>redsucc</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-398"></a> <span class='hs-varid'>wrapM</span> <span class='hs-str'>"redsucc"</span> <span class='hs-layout'>(</span><span class='hs-varid'>g</span><span class='hs-layout'>,</span> <span class='hs-varid'>atomImps</span><span class='hs-layout'>,</span> <span class='hs-varid'>nestImps</span><span class='hs-layout'>,</span> <span class='hs-varid'>atoms</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-399"></a> <span class='hs-varid'>redsucc'</span> <span class='hs-varid'>g</span>
<a name="line-400"></a>
<a name="line-401"></a> <span class='hs-varid'>redsucc'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-402"></a> <span class='hs-varid'>redsucc'</span> <span class='hs-varid'>a</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-conid'>PVar</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-403"></a> <span class='hs-layout'>(</span><span class='hs-varid'>cutSearch</span> <span class='hs-varid'>more</span> <span class='hs-varop'>$</span> <span class='hs-varid'>many</span> <span class='hs-layout'>(</span><span class='hs-varid'>findAtoms</span> <span class='hs-varid'>s</span> <span class='hs-varid'>atoms</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-404"></a> <span class='hs-varop'>`mplus`</span>
<a name="line-405"></a> <span class='hs-comment'>-- The posin check is an optimization. It gets a little slower without the test.</span>
<a name="line-406"></a> <span class='hs-layout'>(</span><span class='hs-keyword'>if</span> <span class='hs-varid'>posin</span> <span class='hs-varid'>s</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>nestImps</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>redsucc_choice</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>none</span><span class='hs-layout'>)</span>
<a name="line-407"></a> <span class='hs-varid'>redsucc'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Conj</span> <span class='hs-varid'>cs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-408"></a> <span class='hs-varid'>ps</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mapM</span> <span class='hs-varid'>redsucc</span> <span class='hs-varid'>cs</span>
<a name="line-409"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>applys</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ctuple</span> <span class='hs-layout'>(</span><span class='hs-varid'>length</span> <span class='hs-varid'>cs</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>ps</span>
<a name="line-410"></a> <span class='hs-comment'>-- next clause deals with succedent (A v B) by pushing the</span>
<a name="line-411"></a> <span class='hs-comment'>-- non-determinism into the treatment of implication on the left</span>
<a name="line-412"></a> <span class='hs-varid'>redsucc'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Disj</span> <span class='hs-varid'>ds</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-413"></a> <span class='hs-varid'>s1</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"_"</span>
<a name="line-414"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>v</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>PVar</span> <span class='hs-varid'>s1</span>
<a name="line-415"></a> <span class='hs-varid'>redant0</span> <span class='hs-keyglyph'>[</span> <span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Cinj</span> <span class='hs-varid'>cd</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>d</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>v</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-layout'>(</span><span class='hs-varid'>cd</span><span class='hs-layout'>,</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>zip</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0</span><span class='hs-keyglyph'>..</span><span class='hs-keyglyph'>]</span> <span class='hs-varid'>ds</span> <span class='hs-keyglyph'>]</span> <span class='hs-varid'>v</span>
<a name="line-416"></a> <span class='hs-varid'>redsucc'</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-417"></a> <span class='hs-varid'>s</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"x"</span>
<a name="line-418"></a> <span class='hs-varid'>p</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant1</span> <span class='hs-layout'>(</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-conid'>[]</span> <span class='hs-varid'>b</span>
<a name="line-419"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Lam</span> <span class='hs-varid'>s</span> <span class='hs-varid'>p</span>
<a name="line-420"></a>
<a name="line-421"></a> <span class='hs-comment'>-- Now we have the hard part; maybe lots of formulae</span>
<a name="line-422"></a> <span class='hs-comment'>-- of form (C->D)->B in nestImps to choose from!</span>
<a name="line-423"></a> <span class='hs-comment'>-- Which one to take first? We use the order heuristic.</span>
<a name="line-424"></a> <span class='hs-varid'>redsucc_choice</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-425"></a> <span class='hs-varid'>redsucc_choice</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span>
<a name="line-426"></a> <span class='hs-varid'>wrapM</span> <span class='hs-str'>"redsucc_choice"</span> <span class='hs-varid'>g</span> <span class='hs-varop'>$</span>
<a name="line-427"></a> <span class='hs-varid'>redsucc_choice'</span> <span class='hs-varid'>g</span>
<a name="line-428"></a>
<a name="line-429"></a> <span class='hs-varid'>redsucc_choice'</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Goal</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-conid'>Proof</span>
<a name="line-430"></a> <span class='hs-varid'>redsucc_choice'</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-431"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>ordImps</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>order</span> <span class='hs-varid'>nestImps</span> <span class='hs-varid'>g</span> <span class='hs-varid'>atomImps</span>
<a name="line-432"></a> <span class='hs-layout'>(</span><span class='hs-conid'>NestImp</span> <span class='hs-varid'>p</span> <span class='hs-varid'>c</span> <span class='hs-varid'>d</span> <span class='hs-varid'>b</span><span class='hs-layout'>,</span> <span class='hs-varid'>restImps</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span>
<a name="line-433"></a> <span class='hs-varid'>mtrace</span> <span class='hs-layout'>(</span><span class='hs-str'>"redsucc_choice: order="</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>ordImps</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-434"></a> <span class='hs-varid'>select</span> <span class='hs-varid'>ordImps</span>
<a name="line-435"></a> <span class='hs-varid'>x</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"x"</span>
<a name="line-436"></a> <span class='hs-varid'>z</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>newSym</span> <span class='hs-str'>"z"</span>
<a name="line-437"></a> <span class='hs-varid'>qz</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant</span> <span class='hs-varid'>more</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>z</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>d</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>restImps</span> <span class='hs-varid'>atoms</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-438"></a> <span class='hs-varid'>gp</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>redant</span> <span class='hs-varid'>more</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>A</span> <span class='hs-layout'>(</span><span class='hs-conid'>Var</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varid'>b</span><span class='hs-keyglyph'>]</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>restImps</span> <span class='hs-varid'>atoms</span> <span class='hs-varid'>g</span>
<a name="line-439"></a> <span class='hs-varid'>subst</span> <span class='hs-layout'>(</span><span class='hs-varid'>applyImp</span> <span class='hs-varid'>p</span> <span class='hs-layout'>(</span><span class='hs-conid'>Lam</span> <span class='hs-varid'>z</span> <span class='hs-varid'>qz</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>x</span> <span class='hs-varid'>gp</span>
<a name="line-440"></a>
<a name="line-441"></a><a name="posin"></a><span class='hs-definition'>posin</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>NestImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-442"></a><span class='hs-definition'>posin</span> <span class='hs-varid'>g</span> <span class='hs-varid'>atomImps</span> <span class='hs-varid'>nestImps</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>posin1</span> <span class='hs-varid'>g</span> <span class='hs-varid'>atomImps</span> <span class='hs-varop'>||</span> <span class='hs-varid'>posin2</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>[</span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>NestImp</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>nestImps</span> <span class='hs-keyglyph'>]</span>
<a name="line-443"></a>
<a name="line-444"></a><a name="posin1"></a><span class='hs-definition'>posin1</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>AtomImps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-445"></a><span class='hs-definition'>posin1</span> <span class='hs-varid'>g</span> <span class='hs-varid'>atomImps</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-layout'>(</span><span class='hs-conid'>AtomImp</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>bs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>posin2</span> <span class='hs-varid'>g</span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>A</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>bs</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-varid'>atomImps</span>
<a name="line-446"></a>
<a name="line-447"></a><a name="posin2"></a><span class='hs-definition'>posin2</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Formula</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-448"></a><span class='hs-definition'>posin2</span> <span class='hs-varid'>g</span> <span class='hs-varid'>bs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>any</span> <span class='hs-layout'>(</span><span class='hs-varid'>posin3</span> <span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-varid'>bs</span>
<a name="line-449"></a>
<a name="line-450"></a><a name="posin3"></a><span class='hs-definition'>posin3</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Symbol</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Formula</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span>
<a name="line-451"></a><span class='hs-definition'>posin3</span> <span class='hs-varid'>g</span> <span class='hs-layout'>(</span><span class='hs-conid'>Disj</span> <span class='hs-keyword'>as</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-varid'>posin3</span> <span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>map</span> <span class='hs-varid'>snd</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span>
<a name="line-452"></a><span class='hs-definition'>posin3</span> <span class='hs-varid'>g</span> <span class='hs-layout'>(</span><span class='hs-conid'>Conj</span> <span class='hs-keyword'>as</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>any</span> <span class='hs-layout'>(</span><span class='hs-varid'>posin3</span> <span class='hs-varid'>g</span><span class='hs-layout'>)</span> <span class='hs-keyword'>as</span>
<a name="line-453"></a><span class='hs-definition'>posin3</span> <span class='hs-varid'>g</span> <span class='hs-layout'>(</span><span class='hs-keyword'>_</span> <span class='hs-conop'>:-></span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>posin3</span> <span class='hs-varid'>g</span> <span class='hs-varid'>b</span>
<a name="line-454"></a><span class='hs-definition'>posin3</span> <span class='hs-varid'>s</span> <span class='hs-layout'>(</span><span class='hs-conid'>PVar</span> <span class='hs-varid'>s'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>s</span> <span class='hs-varop'>==</span> <span class='hs-varid'>s'</span>
<a name="line-455"></a>
<a name="line-456"></a><a name="cutSearch"></a><span class='hs-definition'>cutSearch</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MoreSolutions</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>P</span> <span class='hs-varid'>a</span>
<a name="line-457"></a><span class='hs-definition'>cutSearch</span> <span class='hs-conid'>False</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>atMostOne</span> <span class='hs-varid'>p</span>
<a name="line-458"></a><span class='hs-definition'>cutSearch</span> <span class='hs-conid'>True</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>p</span>
<a name="line-459"></a>
<a name="line-460"></a><span class='hs-comment'>---------------------------</span>
</pre></body>
</html>
|