summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-10-02 20:31:28 +0200
committerAlberto Ruiz <aruiz@um.es>2015-10-02 20:31:28 +0200
commit04ec1d6b547d6c48506d66298f7d09f7de22c96e (patch)
tree731f106b8ab889d6f89e8056afb87232f46d1529 /examples
parentf92699af9aa47eda9bd2c8a983487a706da75089 (diff)
bool
Diffstat (limited to 'examples')
-rw-r--r--examples/bool.hs46
-rw-r--r--examples/bool.ipynb1152
2 files changed, 1177 insertions, 21 deletions
diff --git a/examples/bool.hs b/examples/bool.hs
index 679b8bf..ee85523 100644
--- a/examples/bool.hs
+++ b/examples/bool.hs
@@ -1,17 +1,25 @@
1-- vectorized boolean operations defined in terms of step or cond 1-- vectorized boolean operations defined in terms of step or cond
2 2
3{-# LANGUAGE FlexibleContexts #-}
4
3import Numeric.LinearAlgebra 5import Numeric.LinearAlgebra
4 6
5infix 4 .==., ./=., .<., .<=., .>=., .>. 7infix 4 .==., ./=., .<., .<=., .>=., .>.
6infixr 3 .&&. 8infixr 3 .&&.
7infixr 2 .||. 9infixr 2 .||.
8 10
9a .<. b = step (b-a) 11-- specialized for Int result
10a .<=. b = cond a b 1 1 0 12cond'
11a .==. b = cond a b 0 1 0 13 :: (Element t, Ord t, Container c I, Container c t)
12a ./=. b = cond a b 1 0 1 14 => c t -> c t -> c I -> c I -> c I -> c I
13a .>=. b = cond a b 0 1 1 15cond' = cond
14a .>. b = step (a-b) 16
17a .<. b = cond' a b 1 0 0
18a .<=. b = cond' a b 1 1 0
19a .==. b = cond' a b 0 1 0
20a ./=. b = cond' a b 1 0 1
21a .>=. b = cond' a b 0 1 1
22a .>. b = cond' a b 0 0 1
15 23
16a .&&. b = step (a*b) 24a .&&. b = step (a*b)
17a .||. b = step (a+b) 25a .||. b = step (a+b)
@@ -29,26 +37,22 @@ maxEvery a b = cond a b b b a
29 37
30clip a b x = cond y b y y b where y = cond x a a x x 38clip a b x = cond y b y y b where y = cond x a a x x
31 39
32disp = putStr . dispf 3 40eye n = ident n :: Matrix R
33
34eye n = ident n :: Matrix Double
35row = asRow . fromList :: [Double] -> Matrix Double
36col = asColumn . fromList :: [Double] -> Matrix Double
37 41
38m = (3><4) [1..] :: Matrix Double 42m = (3><4) [1..] :: Matrix R
39 43
40p = row [0,0,1,1] 44p = fromList [0,0,1,1] :: Vector I
41q = row [0,1,0,1] 45q = fromList [0,1,0,1] :: Vector I
42 46
43main = do 47main = do
44 print $ find (>6) m 48 print $ find (>6) m
45 disp $ assoc (6,8) 7 $ zip (find (/=0) (eye 5)) [10..] 49 disp 3 $ assoc (6,8) 7 $ zip (find (/=0) (eye 5)) [10..]
46 disp $ accum (eye 5) (+) [((0,2),3), ((3,1),7), ((1,1),1)] 50 disp 3 $ accum (eye 5) (+) [((0,2),3), ((3,1),7), ((1,1),1)]
47 disp $ m .>=. 10 .||. m .<. 4 51 print $ m .>=. 10 .||. m .<. 4
48 (disp . fromColumns . map flatten) [p, q, p.&&.q, p .||.q, p `xor` q, p `equiv` q, p `imp` q] 52 (print . fromColumns) [p, q, p.&&.q, p .||.q, p `xor` q, p `equiv` q, p `imp` q]
49 print $ taut $ (p `imp` q ) `equiv` (no q `imp` no p) 53 print $ taut $ (p `imp` q ) `equiv` (no q `imp` no p)
50 print $ taut $ (xor p q) `equiv` (p .&&. no q .||. no p .&&. q) 54 print $ taut $ (xor p q) `equiv` (p .&&. no q .||. no p .&&. q)
51 disp $ clip 3 8 m 55 disp 3 $ clip 3 8 m
52 disp $ col [1..7] .<=. row [1..5] 56 print $ col [1..7] .<=. row [1..5]
53 disp $ cond (col [1..3]) (row [1..4]) m 50 (3*m) 57 print $ cond (col [1..3]) (row [1..4]) m 50 (3*m)
54 58
diff --git a/examples/bool.ipynb b/examples/bool.ipynb
new file mode 100644
index 0000000..abceeb4
--- /dev/null
+++ b/examples/bool.ipynb
@@ -0,0 +1,1152 @@
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# vectorized boolean operations"
8 ]
9 },
10 {
11 "cell_type": "code",
12 "execution_count": 1,
13 "metadata": {
14 "collapsed": true
15 },
16 "outputs": [],
17 "source": [
18 "import Numeric.LinearAlgebra\n",
19 ":ext FlexibleContexts"
20 ]
21 },
22 {
23 "cell_type": "markdown",
24 "metadata": {},
25 "source": [
26 "## pretty printing"
27 ]
28 },
29 {
30 "cell_type": "code",
31 "execution_count": 2,
32 "metadata": {
33 "collapsed": false,
34 "scrolled": true
35 },
36 "outputs": [],
37 "source": [
38 "import IHaskell.Display\n",
39 ":ext FlexibleInstances\n",
40 "\n",
41 "dec = 3\n",
42 "\n",
43 "dispBool = (\"\\n\"++) . format \" \" f\n",
44 " where\n",
45 " f 1 = \"\\\\top\"\n",
46 " f 0 = \"\\\\cdot\"\n",
47 "\n",
48 "instance IHaskellDisplay (Matrix I) where\n",
49 " display m = return $ Display [html (\"<p>$$\"++(latexFormat \"bmatrix\" . dispBool) m++\"$$</p>\")]\n",
50 "\n",
51 "instance IHaskellDisplay (Matrix C) where\n",
52 " display m = return $ Display [html (\"<p>$$\"++(latexFormat \"bmatrix\" . dispcf dec) m++\"$$</p>\")]\n",
53 "\n",
54 "instance IHaskellDisplay (Matrix R) where\n",
55 " display m = return $ Display [html (\"<p>$$\"++ (latexFormat \"bmatrix\" . dispf dec) m++\"$$</p>\")]"
56 ]
57 },
58 {
59 "cell_type": "markdown",
60 "metadata": {},
61 "source": [
62 "## definitions"
63 ]
64 },
65 {
66 "cell_type": "markdown",
67 "metadata": {},
68 "source": [
69 "vectorized operators defined in terms of `step` and `cond`"
70 ]
71 },
72 {
73 "cell_type": "code",
74 "execution_count": 3,
75 "metadata": {
76 "collapsed": false
77 },
78 "outputs": [],
79 "source": [
80 "-- specialized for Int result\n",
81 "cond'\n",
82 " :: (Element t, Ord t, Container c I, Container c t)\n",
83 " => c t -> c t -> c I -> c I -> c I -> c I\n",
84 "cond' = cond"
85 ]
86 },
87 {
88 "cell_type": "code",
89 "execution_count": 4,
90 "metadata": {
91 "collapsed": false
92 },
93 "outputs": [],
94 "source": [
95 "infix 4 .==., ./=., .<., .<=., .>=., .>.\n",
96 "infixr 3 .&&.\n",
97 "infixr 2 .||.\n",
98 "\n",
99 "a .<. b = cond' a b 1 0 0\n",
100 "a .<=. b = cond' a b 1 1 0\n",
101 "a .==. b = cond' a b 0 1 0\n",
102 "a ./=. b = cond' a b 1 0 1\n",
103 "a .>=. b = cond' a b 0 1 1\n",
104 "a .>. b = cond' a b 0 0 1\n",
105 "\n",
106 "a .&&. b = step (a*b)\n",
107 "a .||. b = step (a+b)\n",
108 "no a = 1-a\n",
109 "xor a b = a ./=. b\n",
110 "equiv a b = a .==. b\n",
111 "imp a b = no a .||. b"
112 ]
113 },
114 {
115 "cell_type": "markdown",
116 "metadata": {},
117 "source": [
118 "other useful functions"
119 ]
120 },
121 {
122 "cell_type": "code",
123 "execution_count": 5,
124 "metadata": {
125 "collapsed": true
126 },
127 "outputs": [],
128 "source": [
129 "taut x = minElement x == 1\n",
130 "\n",
131 "minEvery a b = cond a b a a b\n",
132 "maxEvery a b = cond a b b b a\n",
133 "\n",
134 "eye n = ident n :: Matrix R\n",
135 "\n",
136 "clip a b x = cond y b y y b\n",
137 " where\n",
138 " y = cond x a a x x"
139 ]
140 },
141 {
142 "cell_type": "markdown",
143 "metadata": {},
144 "source": [
145 "## examples"
146 ]
147 },
148 {
149 "cell_type": "code",
150 "execution_count": 6,
151 "metadata": {
152 "collapsed": false
153 },
154 "outputs": [
155 {
156 "data": {
157 "text/html": [
158 "<style>/*\n",
159 "Custom IHaskell CSS.\n",
160 "*/\n",
161 "\n",
162 "/* Styles used for the Hoogle display in the pager */\n",
163 ".hoogle-doc {\n",
164 " display: block;\n",
165 " padding-bottom: 1.3em;\n",
166 " padding-left: 0.4em;\n",
167 "}\n",
168 ".hoogle-code {\n",
169 " display: block;\n",
170 " font-family: monospace;\n",
171 " white-space: pre;\n",
172 "}\n",
173 ".hoogle-text {\n",
174 " display: block;\n",
175 "}\n",
176 ".hoogle-name {\n",
177 " color: green;\n",
178 " font-weight: bold;\n",
179 "}\n",
180 ".hoogle-head {\n",
181 " font-weight: bold;\n",
182 "}\n",
183 ".hoogle-sub {\n",
184 " display: block;\n",
185 " margin-left: 0.4em;\n",
186 "}\n",
187 ".hoogle-package {\n",
188 " font-weight: bold;\n",
189 " font-style: italic;\n",
190 "}\n",
191 ".hoogle-module {\n",
192 " font-weight: bold;\n",
193 "}\n",
194 ".hoogle-class {\n",
195 " font-weight: bold;\n",
196 "}\n",
197 "\n",
198 "/* Styles used for basic displays */\n",
199 ".get-type {\n",
200 " color: green;\n",
201 " font-weight: bold;\n",
202 " font-family: monospace;\n",
203 " display: block;\n",
204 " white-space: pre-wrap;\n",
205 "}\n",
206 "\n",
207 ".show-type {\n",
208 " color: green;\n",
209 " font-weight: bold;\n",
210 " font-family: monospace;\n",
211 " margin-left: 1em;\n",
212 "}\n",
213 "\n",
214 ".mono {\n",
215 " font-family: monospace;\n",
216 " display: block;\n",
217 "}\n",
218 "\n",
219 ".err-msg {\n",
220 " color: red;\n",
221 " font-style: italic;\n",
222 " font-family: monospace;\n",
223 " white-space: pre;\n",
224 " display: block;\n",
225 "}\n",
226 "\n",
227 "#unshowable {\n",
228 " color: red;\n",
229 " font-weight: bold;\n",
230 "}\n",
231 "\n",
232 ".err-msg.in.collapse {\n",
233 " padding-top: 0.7em;\n",
234 "}\n",
235 "\n",
236 "/* Code that will get highlighted before it is highlighted */\n",
237 ".highlight-code {\n",
238 " white-space: pre;\n",
239 " font-family: monospace;\n",
240 "}\n",
241 "\n",
242 "/* Hlint styles */\n",
243 ".suggestion-warning { \n",
244 " font-weight: bold;\n",
245 " color: rgb(200, 130, 0);\n",
246 "}\n",
247 ".suggestion-error { \n",
248 " font-weight: bold;\n",
249 " color: red;\n",
250 "}\n",
251 ".suggestion-name {\n",
252 " font-weight: bold;\n",
253 "}\n",
254 "</style><p>$$\\begin{bmatrix}\n",
255 "\\top & \\top & \\top & \\top & \\top\n",
256 "\\\\\n",
257 "\\cdot & \\top & \\top & \\top & \\top\n",
258 "\\\\\n",
259 "\\cdot & \\cdot & \\top & \\top & \\top\n",
260 "\\\\\n",
261 "\\cdot & \\cdot & \\cdot & \\top & \\top\n",
262 "\\\\\n",
263 "\\cdot & \\cdot & \\cdot & \\cdot & \\top\n",
264 "\\\\\n",
265 "\\cdot & \\cdot & \\cdot & \\cdot & \\cdot\n",
266 "\\\\\n",
267 "\\cdot & \\cdot & \\cdot & \\cdot & \\cdot\n",
268 "\\end{bmatrix}$$</p>"
269 ]
270 },
271 "metadata": {},
272 "output_type": "display_data"
273 }
274 ],
275 "source": [
276 "col [1..7] .<=. row [1..5]"
277 ]
278 },
279 {
280 "cell_type": "code",
281 "execution_count": 7,
282 "metadata": {
283 "collapsed": true
284 },
285 "outputs": [],
286 "source": [
287 "m = (3><4) [1..] :: Matrix R"
288 ]
289 },
290 {
291 "cell_type": "code",
292 "execution_count": 8,
293 "metadata": {
294 "collapsed": false
295 },
296 "outputs": [
297 {
298 "data": {
299 "text/html": [
300 "<style>/*\n",
301 "Custom IHaskell CSS.\n",
302 "*/\n",
303 "\n",
304 "/* Styles used for the Hoogle display in the pager */\n",
305 ".hoogle-doc {\n",
306 " display: block;\n",
307 " padding-bottom: 1.3em;\n",
308 " padding-left: 0.4em;\n",
309 "}\n",
310 ".hoogle-code {\n",
311 " display: block;\n",
312 " font-family: monospace;\n",
313 " white-space: pre;\n",
314 "}\n",
315 ".hoogle-text {\n",
316 " display: block;\n",
317 "}\n",
318 ".hoogle-name {\n",
319 " color: green;\n",
320 " font-weight: bold;\n",
321 "}\n",
322 ".hoogle-head {\n",
323 " font-weight: bold;\n",
324 "}\n",
325 ".hoogle-sub {\n",
326 " display: block;\n",
327 " margin-left: 0.4em;\n",
328 "}\n",
329 ".hoogle-package {\n",
330 " font-weight: bold;\n",
331 " font-style: italic;\n",
332 "}\n",
333 ".hoogle-module {\n",
334 " font-weight: bold;\n",
335 "}\n",
336 ".hoogle-class {\n",
337 " font-weight: bold;\n",
338 "}\n",
339 "\n",
340 "/* Styles used for basic displays */\n",
341 ".get-type {\n",
342 " color: green;\n",
343 " font-weight: bold;\n",
344 " font-family: monospace;\n",
345 " display: block;\n",
346 " white-space: pre-wrap;\n",
347 "}\n",
348 "\n",
349 ".show-type {\n",
350 " color: green;\n",
351 " font-weight: bold;\n",
352 " font-family: monospace;\n",
353 " margin-left: 1em;\n",
354 "}\n",
355 "\n",
356 ".mono {\n",
357 " font-family: monospace;\n",
358 " display: block;\n",
359 "}\n",
360 "\n",
361 ".err-msg {\n",
362 " color: red;\n",
363 " font-style: italic;\n",
364 " font-family: monospace;\n",
365 " white-space: pre;\n",
366 " display: block;\n",
367 "}\n",
368 "\n",
369 "#unshowable {\n",
370 " color: red;\n",
371 " font-weight: bold;\n",
372 "}\n",
373 "\n",
374 ".err-msg.in.collapse {\n",
375 " padding-top: 0.7em;\n",
376 "}\n",
377 "\n",
378 "/* Code that will get highlighted before it is highlighted */\n",
379 ".highlight-code {\n",
380 " white-space: pre;\n",
381 " font-family: monospace;\n",
382 "}\n",
383 "\n",
384 "/* Hlint styles */\n",
385 ".suggestion-warning { \n",
386 " font-weight: bold;\n",
387 " color: rgb(200, 130, 0);\n",
388 "}\n",
389 ".suggestion-error { \n",
390 " font-weight: bold;\n",
391 " color: red;\n",
392 "}\n",
393 ".suggestion-name {\n",
394 " font-weight: bold;\n",
395 "}\n",
396 "</style><p>$$\\begin{bmatrix}\n",
397 "1 & 2 & 3 & 4\n",
398 "\\\\\n",
399 "5 & 6 & 7 & 8\n",
400 "\\\\\n",
401 "9 & 10 & 11 & 12\n",
402 "\\end{bmatrix}$$</p>"
403 ]
404 },
405 "metadata": {},
406 "output_type": "display_data"
407 }
408 ],
409 "source": [
410 "m"
411 ]
412 },
413 {
414 "cell_type": "code",
415 "execution_count": 9,
416 "metadata": {
417 "collapsed": false
418 },
419 "outputs": [
420 {
421 "data": {
422 "text/html": [
423 "<style>/*\n",
424 "Custom IHaskell CSS.\n",
425 "*/\n",
426 "\n",
427 "/* Styles used for the Hoogle display in the pager */\n",
428 ".hoogle-doc {\n",
429 " display: block;\n",
430 " padding-bottom: 1.3em;\n",
431 " padding-left: 0.4em;\n",
432 "}\n",
433 ".hoogle-code {\n",
434 " display: block;\n",
435 " font-family: monospace;\n",
436 " white-space: pre;\n",
437 "}\n",
438 ".hoogle-text {\n",
439 " display: block;\n",
440 "}\n",
441 ".hoogle-name {\n",
442 " color: green;\n",
443 " font-weight: bold;\n",
444 "}\n",
445 ".hoogle-head {\n",
446 " font-weight: bold;\n",
447 "}\n",
448 ".hoogle-sub {\n",
449 " display: block;\n",
450 " margin-left: 0.4em;\n",
451 "}\n",
452 ".hoogle-package {\n",
453 " font-weight: bold;\n",
454 " font-style: italic;\n",
455 "}\n",
456 ".hoogle-module {\n",
457 " font-weight: bold;\n",
458 "}\n",
459 ".hoogle-class {\n",
460 " font-weight: bold;\n",
461 "}\n",
462 "\n",
463 "/* Styles used for basic displays */\n",
464 ".get-type {\n",
465 " color: green;\n",
466 " font-weight: bold;\n",
467 " font-family: monospace;\n",
468 " display: block;\n",
469 " white-space: pre-wrap;\n",
470 "}\n",
471 "\n",
472 ".show-type {\n",
473 " color: green;\n",
474 " font-weight: bold;\n",
475 " font-family: monospace;\n",
476 " margin-left: 1em;\n",
477 "}\n",
478 "\n",
479 ".mono {\n",
480 " font-family: monospace;\n",
481 " display: block;\n",
482 "}\n",
483 "\n",
484 ".err-msg {\n",
485 " color: red;\n",
486 " font-style: italic;\n",
487 " font-family: monospace;\n",
488 " white-space: pre;\n",
489 " display: block;\n",
490 "}\n",
491 "\n",
492 "#unshowable {\n",
493 " color: red;\n",
494 " font-weight: bold;\n",
495 "}\n",
496 "\n",
497 ".err-msg.in.collapse {\n",
498 " padding-top: 0.7em;\n",
499 "}\n",
500 "\n",
501 "/* Code that will get highlighted before it is highlighted */\n",
502 ".highlight-code {\n",
503 " white-space: pre;\n",
504 " font-family: monospace;\n",
505 "}\n",
506 "\n",
507 "/* Hlint styles */\n",
508 ".suggestion-warning { \n",
509 " font-weight: bold;\n",
510 " color: rgb(200, 130, 0);\n",
511 "}\n",
512 ".suggestion-error { \n",
513 " font-weight: bold;\n",
514 " color: red;\n",
515 "}\n",
516 ".suggestion-name {\n",
517 " font-weight: bold;\n",
518 "}\n",
519 "</style><p>$$\\begin{bmatrix}\n",
520 "3 & 3 & 3 & 4\n",
521 "\\\\\n",
522 "5 & 6 & 7 & 8\n",
523 "\\\\\n",
524 "8 & 8 & 8 & 8\n",
525 "\\end{bmatrix}$$</p>"
526 ]
527 },
528 "metadata": {},
529 "output_type": "display_data"
530 }
531 ],
532 "source": [
533 "clip 3 8 m"
534 ]
535 },
536 {
537 "cell_type": "code",
538 "execution_count": 10,
539 "metadata": {
540 "collapsed": false
541 },
542 "outputs": [
543 {
544 "data": {
545 "text/plain": [
546 "[(1,2),(1,3),(2,0),(2,1),(2,2),(2,3)]"
547 ]
548 },
549 "metadata": {},
550 "output_type": "display_data"
551 }
552 ],
553 "source": [
554 "find (>6) m"
555 ]
556 },
557 {
558 "cell_type": "code",
559 "execution_count": 11,
560 "metadata": {
561 "collapsed": false
562 },
563 "outputs": [
564 {
565 "data": {
566 "text/html": [
567 "<style>/*\n",
568 "Custom IHaskell CSS.\n",
569 "*/\n",
570 "\n",
571 "/* Styles used for the Hoogle display in the pager */\n",
572 ".hoogle-doc {\n",
573 " display: block;\n",
574 " padding-bottom: 1.3em;\n",
575 " padding-left: 0.4em;\n",
576 "}\n",
577 ".hoogle-code {\n",
578 " display: block;\n",
579 " font-family: monospace;\n",
580 " white-space: pre;\n",
581 "}\n",
582 ".hoogle-text {\n",
583 " display: block;\n",
584 "}\n",
585 ".hoogle-name {\n",
586 " color: green;\n",
587 " font-weight: bold;\n",
588 "}\n",
589 ".hoogle-head {\n",
590 " font-weight: bold;\n",
591 "}\n",
592 ".hoogle-sub {\n",
593 " display: block;\n",
594 " margin-left: 0.4em;\n",
595 "}\n",
596 ".hoogle-package {\n",
597 " font-weight: bold;\n",
598 " font-style: italic;\n",
599 "}\n",
600 ".hoogle-module {\n",
601 " font-weight: bold;\n",
602 "}\n",
603 ".hoogle-class {\n",
604 " font-weight: bold;\n",
605 "}\n",
606 "\n",
607 "/* Styles used for basic displays */\n",
608 ".get-type {\n",
609 " color: green;\n",
610 " font-weight: bold;\n",
611 " font-family: monospace;\n",
612 " display: block;\n",
613 " white-space: pre-wrap;\n",
614 "}\n",
615 "\n",
616 ".show-type {\n",
617 " color: green;\n",
618 " font-weight: bold;\n",
619 " font-family: monospace;\n",
620 " margin-left: 1em;\n",
621 "}\n",
622 "\n",
623 ".mono {\n",
624 " font-family: monospace;\n",
625 " display: block;\n",
626 "}\n",
627 "\n",
628 ".err-msg {\n",
629 " color: red;\n",
630 " font-style: italic;\n",
631 " font-family: monospace;\n",
632 " white-space: pre;\n",
633 " display: block;\n",
634 "}\n",
635 "\n",
636 "#unshowable {\n",
637 " color: red;\n",
638 " font-weight: bold;\n",
639 "}\n",
640 "\n",
641 ".err-msg.in.collapse {\n",
642 " padding-top: 0.7em;\n",
643 "}\n",
644 "\n",
645 "/* Code that will get highlighted before it is highlighted */\n",
646 ".highlight-code {\n",
647 " white-space: pre;\n",
648 " font-family: monospace;\n",
649 "}\n",
650 "\n",
651 "/* Hlint styles */\n",
652 ".suggestion-warning { \n",
653 " font-weight: bold;\n",
654 " color: rgb(200, 130, 0);\n",
655 "}\n",
656 ".suggestion-error { \n",
657 " font-weight: bold;\n",
658 " color: red;\n",
659 "}\n",
660 ".suggestion-name {\n",
661 " font-weight: bold;\n",
662 "}\n",
663 "</style><p>$$\\begin{bmatrix}\n",
664 "\\top & \\top & \\top & \\cdot\n",
665 "\\\\\n",
666 "\\cdot & \\cdot & \\cdot & \\cdot\n",
667 "\\\\\n",
668 "\\cdot & \\top & \\top & \\top\n",
669 "\\end{bmatrix}$$</p>"
670 ]
671 },
672 "metadata": {},
673 "output_type": "display_data"
674 }
675 ],
676 "source": [
677 "(m .>=. 10) .||. (m .<. 4)"
678 ]
679 },
680 {
681 "cell_type": "code",
682 "execution_count": 12,
683 "metadata": {
684 "collapsed": false
685 },
686 "outputs": [
687 {
688 "data": {
689 "text/html": [
690 "<style>/*\n",
691 "Custom IHaskell CSS.\n",
692 "*/\n",
693 "\n",
694 "/* Styles used for the Hoogle display in the pager */\n",
695 ".hoogle-doc {\n",
696 " display: block;\n",
697 " padding-bottom: 1.3em;\n",
698 " padding-left: 0.4em;\n",
699 "}\n",
700 ".hoogle-code {\n",
701 " display: block;\n",
702 " font-family: monospace;\n",
703 " white-space: pre;\n",
704 "}\n",
705 ".hoogle-text {\n",
706 " display: block;\n",
707 "}\n",
708 ".hoogle-name {\n",
709 " color: green;\n",
710 " font-weight: bold;\n",
711 "}\n",
712 ".hoogle-head {\n",
713 " font-weight: bold;\n",
714 "}\n",
715 ".hoogle-sub {\n",
716 " display: block;\n",
717 " margin-left: 0.4em;\n",
718 "}\n",
719 ".hoogle-package {\n",
720 " font-weight: bold;\n",
721 " font-style: italic;\n",
722 "}\n",
723 ".hoogle-module {\n",
724 " font-weight: bold;\n",
725 "}\n",
726 ".hoogle-class {\n",
727 " font-weight: bold;\n",
728 "}\n",
729 "\n",
730 "/* Styles used for basic displays */\n",
731 ".get-type {\n",
732 " color: green;\n",
733 " font-weight: bold;\n",
734 " font-family: monospace;\n",
735 " display: block;\n",
736 " white-space: pre-wrap;\n",
737 "}\n",
738 "\n",
739 ".show-type {\n",
740 " color: green;\n",
741 " font-weight: bold;\n",
742 " font-family: monospace;\n",
743 " margin-left: 1em;\n",
744 "}\n",
745 "\n",
746 ".mono {\n",
747 " font-family: monospace;\n",
748 " display: block;\n",
749 "}\n",
750 "\n",
751 ".err-msg {\n",
752 " color: red;\n",
753 " font-style: italic;\n",
754 " font-family: monospace;\n",
755 " white-space: pre;\n",
756 " display: block;\n",
757 "}\n",
758 "\n",
759 "#unshowable {\n",
760 " color: red;\n",
761 " font-weight: bold;\n",
762 "}\n",
763 "\n",
764 ".err-msg.in.collapse {\n",
765 " padding-top: 0.7em;\n",
766 "}\n",
767 "\n",
768 "/* Code that will get highlighted before it is highlighted */\n",
769 ".highlight-code {\n",
770 " white-space: pre;\n",
771 " font-family: monospace;\n",
772 "}\n",
773 "\n",
774 "/* Hlint styles */\n",
775 ".suggestion-warning { \n",
776 " font-weight: bold;\n",
777 " color: rgb(200, 130, 0);\n",
778 "}\n",
779 ".suggestion-error { \n",
780 " font-weight: bold;\n",
781 " color: red;\n",
782 "}\n",
783 ".suggestion-name {\n",
784 " font-weight: bold;\n",
785 "}\n",
786 "</style><p>$$\\begin{bmatrix}\n",
787 "50 & 2 & 3 & 4\n",
788 "\\\\\n",
789 "15 & 50 & 7 & 8\n",
790 "\\\\\n",
791 "27 & 30 & 50 & 12\n",
792 "\\end{bmatrix}$$</p>"
793 ]
794 },
795 "metadata": {},
796 "output_type": "display_data"
797 }
798 ],
799 "source": [
800 "cond (col [1..3]) (row [1..4]) m 50 (3*m)"
801 ]
802 },
803 {
804 "cell_type": "code",
805 "execution_count": 13,
806 "metadata": {
807 "collapsed": false
808 },
809 "outputs": [
810 {
811 "data": {
812 "text/plain": [
813 "(6><8)\n",
814 " [ 10, 7, 7, 7, 7, 7, 7, 7\n",
815 " , 7, 11, 7, 7, 7, 7, 7, 7\n",
816 " , 7, 7, 12, 7, 7, 7, 7, 7\n",
817 " , 7, 7, 7, 13, 7, 7, 7, 7\n",
818 " , 7, 7, 7, 7, 14, 7, 7, 7\n",
819 " , 7, 7, 7, 7, 7, 7, 7, 7 ]"
820 ]
821 },
822 "metadata": {},
823 "output_type": "display_data"
824 }
825 ],
826 "source": [
827 "assoc (6,8) 7 $ zip (find (/=0) (eye 5)) [10..] :: Matrix Z"
828 ]
829 },
830 {
831 "cell_type": "code",
832 "execution_count": 14,
833 "metadata": {
834 "collapsed": false
835 },
836 "outputs": [
837 {
838 "data": {
839 "text/html": [
840 "<style>/*\n",
841 "Custom IHaskell CSS.\n",
842 "*/\n",
843 "\n",
844 "/* Styles used for the Hoogle display in the pager */\n",
845 ".hoogle-doc {\n",
846 " display: block;\n",
847 " padding-bottom: 1.3em;\n",
848 " padding-left: 0.4em;\n",
849 "}\n",
850 ".hoogle-code {\n",
851 " display: block;\n",
852 " font-family: monospace;\n",
853 " white-space: pre;\n",
854 "}\n",
855 ".hoogle-text {\n",
856 " display: block;\n",
857 "}\n",
858 ".hoogle-name {\n",
859 " color: green;\n",
860 " font-weight: bold;\n",
861 "}\n",
862 ".hoogle-head {\n",
863 " font-weight: bold;\n",
864 "}\n",
865 ".hoogle-sub {\n",
866 " display: block;\n",
867 " margin-left: 0.4em;\n",
868 "}\n",
869 ".hoogle-package {\n",
870 " font-weight: bold;\n",
871 " font-style: italic;\n",
872 "}\n",
873 ".hoogle-module {\n",
874 " font-weight: bold;\n",
875 "}\n",
876 ".hoogle-class {\n",
877 " font-weight: bold;\n",
878 "}\n",
879 "\n",
880 "/* Styles used for basic displays */\n",
881 ".get-type {\n",
882 " color: green;\n",
883 " font-weight: bold;\n",
884 " font-family: monospace;\n",
885 " display: block;\n",
886 " white-space: pre-wrap;\n",
887 "}\n",
888 "\n",
889 ".show-type {\n",
890 " color: green;\n",
891 " font-weight: bold;\n",
892 " font-family: monospace;\n",
893 " margin-left: 1em;\n",
894 "}\n",
895 "\n",
896 ".mono {\n",
897 " font-family: monospace;\n",
898 " display: block;\n",
899 "}\n",
900 "\n",
901 ".err-msg {\n",
902 " color: red;\n",
903 " font-style: italic;\n",
904 " font-family: monospace;\n",
905 " white-space: pre;\n",
906 " display: block;\n",
907 "}\n",
908 "\n",
909 "#unshowable {\n",
910 " color: red;\n",
911 " font-weight: bold;\n",
912 "}\n",
913 "\n",
914 ".err-msg.in.collapse {\n",
915 " padding-top: 0.7em;\n",
916 "}\n",
917 "\n",
918 "/* Code that will get highlighted before it is highlighted */\n",
919 ".highlight-code {\n",
920 " white-space: pre;\n",
921 " font-family: monospace;\n",
922 "}\n",
923 "\n",
924 "/* Hlint styles */\n",
925 ".suggestion-warning { \n",
926 " font-weight: bold;\n",
927 " color: rgb(200, 130, 0);\n",
928 "}\n",
929 ".suggestion-error { \n",
930 " font-weight: bold;\n",
931 " color: red;\n",
932 "}\n",
933 ".suggestion-name {\n",
934 " font-weight: bold;\n",
935 "}\n",
936 "</style><p>$$\\begin{bmatrix}\n",
937 "1 & 0 & 3 & 0 & 0\n",
938 "\\\\\n",
939 "0 & 2 & 0 & 0 & 0\n",
940 "\\\\\n",
941 "0 & 0 & 1 & 0 & 0\n",
942 "\\\\\n",
943 "0 & 7 & 0 & 1 & 0\n",
944 "\\\\\n",
945 "0 & 0 & 0 & 0 & 1\n",
946 "\\end{bmatrix}$$</p>"
947 ]
948 },
949 "metadata": {},
950 "output_type": "display_data"
951 }
952 ],
953 "source": [
954 "accum (eye 5) (+) [((0,2),3), ((3,1),7), ((1,1),1)]"
955 ]
956 },
957 {
958 "cell_type": "code",
959 "execution_count": 15,
960 "metadata": {
961 "collapsed": true
962 },
963 "outputs": [],
964 "source": [
965 "p = fromList [0,0,1,1] :: Vector I\n",
966 "q = fromList [0,1,0,1] :: Vector I"
967 ]
968 },
969 {
970 "cell_type": "code",
971 "execution_count": 16,
972 "metadata": {
973 "collapsed": false
974 },
975 "outputs": [
976 {
977 "data": {
978 "text/html": [
979 "<style>/*\n",
980 "Custom IHaskell CSS.\n",
981 "*/\n",
982 "\n",
983 "/* Styles used for the Hoogle display in the pager */\n",
984 ".hoogle-doc {\n",
985 " display: block;\n",
986 " padding-bottom: 1.3em;\n",
987 " padding-left: 0.4em;\n",
988 "}\n",
989 ".hoogle-code {\n",
990 " display: block;\n",
991 " font-family: monospace;\n",
992 " white-space: pre;\n",
993 "}\n",
994 ".hoogle-text {\n",
995 " display: block;\n",
996 "}\n",
997 ".hoogle-name {\n",
998 " color: green;\n",
999 " font-weight: bold;\n",
1000 "}\n",
1001 ".hoogle-head {\n",
1002 " font-weight: bold;\n",
1003 "}\n",
1004 ".hoogle-sub {\n",
1005 " display: block;\n",
1006 " margin-left: 0.4em;\n",
1007 "}\n",
1008 ".hoogle-package {\n",
1009 " font-weight: bold;\n",
1010 " font-style: italic;\n",
1011 "}\n",
1012 ".hoogle-module {\n",
1013 " font-weight: bold;\n",
1014 "}\n",
1015 ".hoogle-class {\n",
1016 " font-weight: bold;\n",
1017 "}\n",
1018 "\n",
1019 "/* Styles used for basic displays */\n",
1020 ".get-type {\n",
1021 " color: green;\n",
1022 " font-weight: bold;\n",
1023 " font-family: monospace;\n",
1024 " display: block;\n",
1025 " white-space: pre-wrap;\n",
1026 "}\n",
1027 "\n",
1028 ".show-type {\n",
1029 " color: green;\n",
1030 " font-weight: bold;\n",
1031 " font-family: monospace;\n",
1032 " margin-left: 1em;\n",
1033 "}\n",
1034 "\n",
1035 ".mono {\n",
1036 " font-family: monospace;\n",
1037 " display: block;\n",
1038 "}\n",
1039 "\n",
1040 ".err-msg {\n",
1041 " color: red;\n",
1042 " font-style: italic;\n",
1043 " font-family: monospace;\n",
1044 " white-space: pre;\n",
1045 " display: block;\n",
1046 "}\n",
1047 "\n",
1048 "#unshowable {\n",
1049 " color: red;\n",
1050 " font-weight: bold;\n",
1051 "}\n",
1052 "\n",
1053 ".err-msg.in.collapse {\n",
1054 " padding-top: 0.7em;\n",
1055 "}\n",
1056 "\n",
1057 "/* Code that will get highlighted before it is highlighted */\n",
1058 ".highlight-code {\n",
1059 " white-space: pre;\n",
1060 " font-family: monospace;\n",
1061 "}\n",
1062 "\n",
1063 "/* Hlint styles */\n",
1064 ".suggestion-warning { \n",
1065 " font-weight: bold;\n",
1066 " color: rgb(200, 130, 0);\n",
1067 "}\n",
1068 ".suggestion-error { \n",
1069 " font-weight: bold;\n",
1070 " color: red;\n",
1071 "}\n",
1072 ".suggestion-name {\n",
1073 " font-weight: bold;\n",
1074 "}\n",
1075 "</style><p>$$\\begin{bmatrix}\n",
1076 "\\cdot & \\cdot & \\cdot & \\cdot & \\cdot & \\top & \\top\n",
1077 "\\\\\n",
1078 "\\cdot & \\top & \\cdot & \\top & \\top & \\cdot & \\top\n",
1079 "\\\\\n",
1080 "\\top & \\cdot & \\cdot & \\top & \\top & \\cdot & \\cdot\n",
1081 "\\\\\n",
1082 "\\top & \\top & \\top & \\top & \\cdot & \\top & \\top\n",
1083 "\\end{bmatrix}$$</p>"
1084 ]
1085 },
1086 "metadata": {},
1087 "output_type": "display_data"
1088 }
1089 ],
1090 "source": [
1091 "fromColumns [p, q, p.&&.q, p .||.q, p `xor` q, p `equiv` q, p `imp` q]"
1092 ]
1093 },
1094 {
1095 "cell_type": "code",
1096 "execution_count": 17,
1097 "metadata": {
1098 "collapsed": false
1099 },
1100 "outputs": [
1101 {
1102 "data": {
1103 "text/plain": [
1104 "True"
1105 ]
1106 },
1107 "metadata": {},
1108 "output_type": "display_data"
1109 }
1110 ],
1111 "source": [
1112 "taut $ (p `imp` q ) `equiv` (no q `imp` no p)"
1113 ]
1114 },
1115 {
1116 "cell_type": "code",
1117 "execution_count": 18,
1118 "metadata": {
1119 "collapsed": false
1120 },
1121 "outputs": [
1122 {
1123 "data": {
1124 "text/plain": [
1125 "False"
1126 ]
1127 },
1128 "metadata": {},
1129 "output_type": "display_data"
1130 }
1131 ],
1132 "source": [
1133 "taut $ xor p q `equiv` (p .&&. no q .||. no p .&&. q)"
1134 ]
1135 }
1136 ],
1137 "metadata": {
1138 "kernelspec": {
1139 "display_name": "Haskell",
1140 "language": "haskell",
1141 "name": "haskell"
1142 },
1143 "language_info": {
1144 "codemirror_mode": "ihaskell",
1145 "file_extension": ".hs",
1146 "name": "haskell",
1147 "version": "7.10.1"
1148 }
1149 },
1150 "nbformat": 4,
1151 "nbformat_minor": 0
1152}