forked from CalculusWithJulia/CalculusWithJulia.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logical_expressions.html
1222 lines (916 loc) · 60.4 KB
/
logical_expressions.html
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
rel="stylesheet">
<style>
.julia {display: block; font-family: "Source Code Pro";
color:#0033CC;
}
.hljl {font-family: "Source Code Pro";
color:#0033CC;
}
body { padding-top: 60px; }
h5:before {content:"\2746\ ";}
h6:before {content:"\2742\ ";}
pre {display: block;}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
tr:hover {background-color: #f5f5f5;}
.admonition-title:before {content:"\2746\ ";}
.admonition-title { color:#0033CC}
</style>
<!-- .julia:before {content: "julia> "} -->
<style></style>
<script src="https://code.jquery.com/jquery.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ["\$","\$"], ["\\(","\\)"]]
},
displayAlign: "left",
displayIndent: "5%"
});
</script>
<!-- not TeX-AMS-MML_HTMLorMML-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
</script>
<script>
window.PlotlyConfig = {MathJaxConfig: 'local'}
</script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$("h1").each(function(index) {
var title = $( this ).text()
$("#page_title").html("<strong>" + title + "</strong>");
document.title = title
});
$( "h2" ).each(function( index ) {
var nm = $( this ).text();
var id = $.trim(nm).replace(/ /g,'');
this.id = id
$("#page_dropdown").append("<li><a href='#" + id + "'>" + nm + "</a></li>");
});
$('[data-toggle="popover"]').popover();
});
</script>
</head>
<body data-spy="scroll" >
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="#" id="page_title"></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Jump to... <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" id="page_dropdown"></ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<header>
</header>
<div class="title">
</div>
<div class="container-fluid">
<div class="span10 offset1">
<h1>Inequalities, Logical expressions</h1>
<h2>Boolean values</h2>
<p>In mathematics it is common to test if an expression is true or false. For example, is the point <span class="math">$(1,2)$</span> inside the disc <span class="math">$x^2 + y^2 \leq 1$</span>? We would check this by substituting <span class="math">$1$</span> for <span class="math">$x$</span> and <span class="math">$2$</span> for <span class="math">$y$</span>, evaluating both sides of the inequality and then assessing if the relationship is true or false. In this case, we end up with a comparison of <span class="math">$5 \leq 1$</span>, which we of course know is false.</p>
<p><code>Julia</code> provides numeric comparisons that allow this notation to be exactly mirrored:</p>
<pre class='hljl'>
<span class='hljl-n'>x</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>y</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-t'>
</span><span class='hljl-n'>x</span><span class='hljl-oB'>^</span><span class='hljl-ni'>2</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>y</span><span class='hljl-oB'>^</span><span class='hljl-ni'>2</span><span class='hljl-t'> </span><span class='hljl-oB'><=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span>
</pre>
<pre class="output">
false
</pre>
<p>The response is <code>false</code>, as expected. <code>Julia</code> provides <a href="http://en.wikipedia.org/wiki/Boolean_data_type">Boolean</a> values <code>true</code> and <code>false</code> for such questions. The same process is followed as was described mathematically.</p>
<p>The set of numeric comparisons is nearly the same as the mathematical counterparts: <code><</code>, <code><=</code>, <code>==</code>, <code>>=</code>, <code>></code>. The syntax for less than or equal can also be represented with the Unicode <code>≤</code> (generated by <code>\le[tab]</code>). Similarly, for greater than or equal, there is <code>\ge[tab]</code>.</p>
<div class="alert alert-success" role="alert">
<div class="markdown"><p>The use of <code>==</code> is necessary, as <code>=</code> is used for assignment.</p>
</div>
</div>
<p>The <code>!</code> operator takes a boolean value and negates it. It uses prefix notation:</p>
<pre class='hljl'>
<span class='hljl-oB'>!</span><span class='hljl-kc'>true</span>
</pre>
<pre class="output">
false
</pre>
<p>For convenience, <code>a != b</code> can be used in place of <code>!(a == b)</code>.</p>
<h2>Algebra of inequalities</h2>
<p>To illustrate, let's see that the algebra of expressions works as expected.</p>
<p>For example, if <span class="math">$a < b$</span> then for any <span class="math">$c$</span> it is also true that <span class="math">$a + c < b + c$</span>.</p>
<p>We can't "prove" this through examples, but we can investigate it by the choice of various values of <span class="math">$a$</span>, <span class="math">$b$</span>, and <span class="math">$c$</span>. For example:</p>
<pre class='hljl'>
<span class='hljl-n'>a</span><span class='hljl-p'>,</span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-n'>c</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-p'>,</span><span class='hljl-ni'>2</span><span class='hljl-p'>,</span><span class='hljl-ni'>3</span><span class='hljl-t'>
</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>c</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>c</span>
</pre>
<pre class="output">
(true, true)
</pre>
<p>Or in reverse:</p>
<pre class='hljl'>
<span class='hljl-n'>a</span><span class='hljl-p'>,</span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-n'>c</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>3</span><span class='hljl-p'>,</span><span class='hljl-ni'>2</span><span class='hljl-p'>,</span><span class='hljl-ni'>1</span><span class='hljl-t'>
</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>c</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>c</span>
</pre>
<pre class="output">
(false, false)
</pre>
<p>Trying other choices will show that the two answers are either both <code>false</code> or both <code>true</code>.</p>
<div class="alert alert-success" role="alert">
<div class="markdown"><p>Well, almost... When <code>Inf</code> or <code>NaN</code> are involved, this may not hold, for example <code>1 + Inf < 2 + Inf</code> is actually <code>false</code>. </p>
</div>
</div>
<p>So adding or subtracting any finite value from an inequality will preserve the inequality, just as it does for equations.</p>
<p>What about addition and multiplication?</p>
<p>Consider the case <span class="math">$a < b$</span> and <span class="math">$c > 0$</span>. Then <span class="math">$ca < cb$</span>. Here we investigate using 3 random values (which will be positive):</p>
<pre class='hljl'>
<span class='hljl-n'>a</span><span class='hljl-p'>,</span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-n'>c</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>rand</span><span class='hljl-p'>(</span><span class='hljl-ni'>3</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-cs'># 3 random numbers in (0,1)</span><span class='hljl-t'>
</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>c</span><span class='hljl-oB'>*</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>c</span><span class='hljl-oB'>*</span><span class='hljl-n'>b</span>
</pre>
<pre class="output">
(false, false)
</pre>
<p>Whenever these two commands are run, the two logical values should be identical, even though the specific values of <code>a</code>, <code>b</code>, and <code>c</code> will vary.</p>
<p>The restriction that <span class="math">$c > 0$</span> is needed. For example, if <span class="math">$c = -1$</span>, then we have <span class="math">$a < b$</span> if and only if <span class="math">$-a > -b$</span>. That is the inequality is "flipped."</p>
<pre class='hljl'>
<span class='hljl-n'>a</span><span class='hljl-p'>,</span><span class='hljl-n'>b</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>rand</span><span class='hljl-p'>(</span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-n'>b</span>
</pre>
<pre class="output">
(false, false)
</pre>
<p>Again, whenever this is run, the two logical values should be the same. The values <span class="math">$a$</span> and <span class="math">$-a$</span> are the same distance from <span class="math">$0$</span>, but on opposite sides. Hence if <span class="math">$0 < a < b$</span>, then <span class="math">$b$</span> is farther from <span class="math">$0$</span> than <span class="math">$a$</span>, so <span class="math">$-b$</span> will be farther from <span class="math">$0$</span> than <span class="math">$-a$</span>, which in this case says <span class="math">$-b < -a$</span>, as expected.</p>
<p>Finally, we have the case of division. The relation of <span class="math">$x$</span> and <span class="math">$1/x$</span> (for <span class="math">$x > 0$</span>) is that the farther <span class="math">$x$</span> is from <span class="math">$0$</span>, the closer <span class="math">$1/x$</span> is to <span class="math">$0$</span>. So large values of <span class="math">$x$</span> make small values of <span class="math">$1/x$</span>. This leads to this fact for <span class="math">$a,b > 0$</span>: <span class="math">$a < b$</span> if and only if <span class="math">$1/a > 1/b$</span>.</p>
<p>We can check with random values again:</p>
<pre class='hljl'>
<span class='hljl-n'>a</span><span class='hljl-p'>,</span><span class='hljl-n'>b</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>rand</span><span class='hljl-p'>(</span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-n'>b</span>
</pre>
<pre class="output">
(false, false)
</pre>
<p>In summary we investigated numerically that the following hold:</p>
<ul>
<li><p><code>a < b</code> if and only if <code>a + c < b + c</code> for all finite <code>a</code>, <code>b</code>, and <code>c</code>.</p>
</li>
<li><p><code>a < b</code> if and only if <code>c*a < c*b</code> for all finite <code>a</code> and <code>b</code>, and finite, positive <code>c</code>.</p>
</li>
<li><p><code>a < b</code> if and only if <code>-a > -b</code> for all finite <code>a</code> and <code>b</code>.</p>
</li>
<li><p><code>a < b</code> if and only if <code>1/a > 1/b</code> for all finite, positive <code>a</code> and <code>b</code>.</p>
</li>
</ul>
<h2>Some examples</h2>
<p>We now show some inequalities highlighted on this <a href="http://en.wikipedia.org/wiki/Inequality_%28mathematics%29">Wikipedia</a> page.</p>
<p>Numerically investigate the fact <span class="math">$e^x \geq 1 + x$</span> by showing it is true for three different values of <span class="math">$x$</span>. We pick <span class="math">$x=-1$</span>, <span class="math">$0$</span>, and <span class="math">$1$</span>:</p>
<pre class='hljl'>
<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-ni'>1</span><span class='hljl-p'>;</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-t'>
</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>0</span><span class='hljl-p'>;</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-t'>
</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-p'>;</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>>=</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>x</span>
</pre>
<p>Now, let's investigate that for any distinct real numbers, <span class="math">$a$</span> and <span class="math">$b$</span> that</p>
<p class="math">\[
~
\frac{e^b - e^a}{b - a} > e^{(a+b)/2}
~
\]</p>
<p>For this, we use <code>rand(2)</code> to generate two random numbers in <span class="math">$(0,1)$</span>:</p>
<pre class='hljl'>
<span class='hljl-n'>a</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>rand</span><span class='hljl-p'>(</span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-p'>(</span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>b</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>(</span><span class='hljl-n'>a</span><span class='hljl-p'>))</span><span class='hljl-t'> </span><span class='hljl-oB'>/</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-n'>b</span><span class='hljl-oB'>-</span><span class='hljl-n'>a</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-nf'>exp</span><span class='hljl-p'>((</span><span class='hljl-n'>a</span><span class='hljl-oB'>+</span><span class='hljl-n'>b</span><span class='hljl-p'>)</span><span class='hljl-oB'>/</span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
true
</pre>
<p>This should evaluate to <code>true</code> for any random choice of <code>a</code> and <code>b</code> returned by <code>rand(2)</code>.</p>
<p>Finally, let's investigate the fact that the harmonic mean, <span class="math">$2/(1/a + 1/b)$</span> is less than or equal to the geometric mean, <span class="math">$\sqrt{ab}$</span>, which is less than or equal to the quadratic mean, <span class="math">$\sqrt{a^2 + b^2}/\sqrt{2}$</span>, using two randomly chosen values:</p>
<pre class='hljl'>
<span class='hljl-n'>a</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>rand</span><span class='hljl-p'>(</span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>h</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-t'> </span><span class='hljl-oB'>/</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-n'>b</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>g</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-n'>a</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>^</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-ni'>1</span><span class='hljl-t'> </span><span class='hljl-oB'>/</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>q</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-nf'>sqrt</span><span class='hljl-p'>((</span><span class='hljl-n'>a</span><span class='hljl-oB'>^</span><span class='hljl-ni'>2</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-n'>b</span><span class='hljl-oB'>^</span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>/</span><span class='hljl-t'> </span><span class='hljl-ni'>2</span><span class='hljl-p'>)</span><span class='hljl-t'>
</span><span class='hljl-n'>h</span><span class='hljl-t'> </span><span class='hljl-oB'><=</span><span class='hljl-t'> </span><span class='hljl-n'>g</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-n'>g</span><span class='hljl-t'> </span><span class='hljl-oB'><=</span><span class='hljl-t'> </span><span class='hljl-n'>q</span>
</pre>
<pre class="output">
(true, true)
</pre>
<h2>Chaining, combining expressions: absolute values</h2>
<p>The absolute value notation can be defined through cases:</p>
<p class="math">\[
~
\lvert x\rvert = \begin{cases}
x & x \geq 0\\
-x & \text{otherwise}.
\end{cases}
~
\]</p>
<p>The interpretation of <span class="math">$\lvert x\rvert$</span>, as the distance on the number line of <span class="math">$x$</span> from <span class="math">$0$</span>, means that many relationships are naturally expressed in terms of absolute values. For example, a simple shift: <span class="math">$\lvert x -c\rvert$</span> is related to the distance <span class="math">$x$</span> is from the number <span class="math">$c$</span>. As common as they are, the concept can still be confusing when inequalities are involved.</p>
<p>For example, the expression <span class="math">$\lvert x - 5\rvert < 7$</span> has solutions which are all values of <span class="math">$x$</span> within <span class="math">$7$</span> units of <span class="math">$5$</span>. This would be the values <span class="math">$-2< x < 12$</span>. If this isn't immediately intuited, then formally <span class="math">$\lvert x - 5\rvert <7$</span> is a compact representation of a chain of inequalities: <span class="math">$-7 < x-5 < 7$</span>. (Which is really two combined inequalities: <span class="math">$-7 < x-5$</span> <em>and</em> <span class="math">$x-5 < 7$</span>.) We can "add" 5 to each side to get <span class="math">$-2 < x < 12$</span>, using the fact that adding by a finite number does not change the inequality sign.</p>
<p>Julia's precedence for logical expressions, allows such statements to mirror the mathematical notation:</p>
<pre class='hljl'>
<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-ni'>18</span><span class='hljl-t'>
</span><span class='hljl-nf'>abs</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-ni'>7</span>
</pre>
<pre class="output">
false
</pre>
<p>This is to be expected, but we could also have written:</p>
<pre class='hljl'>
<span class='hljl-oB'>-</span><span class='hljl-ni'>7</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-ni'>7</span>
</pre>
<pre class="output">
false
</pre>
<p>Read aloud this would be "minus 7 is less than x minus 5 <strong>and</strong> x minus 5 is less than 7".</p>
<p>The "and" equations can be combined as above with a natural notation. However, an equation like <span class="math">$\lvert x - 5\rvert > 7$</span> would emphasize an <strong>or</strong> and be "x minus 5 less than minus 7 <strong>or</strong> x minus 5 greater than 7". Expressing this requires some new notation.</p>
<p>The <em>boolean operators</em> <code>&</code> and <code>|</code> implement "and" and "or." Thus we could write <span class="math">$-7 < x-5 < 7$</span> as</p>
<pre class='hljl'>
<span class='hljl-p'>(</span><span class='hljl-oB'>-</span><span class='hljl-ni'>7</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>&</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-ni'>7</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
false
</pre>
<p>and could write <span class="math">$\lvert x-5\rvert > 7$</span> as</p>
<pre class='hljl'>
<span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-ni'>7</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>|</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-ni'>7</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
true
</pre>
<p>(The first expression is false for <span class="math">$x=18$</span> and the second expression true, so the "or"ed result is <code>true</code> and the "and" result if <code>false</code>.)</p>
<div class="alert alert-success" role="alert">
<div class="markdown"><p>The <a href="http://julia.readthedocs.org/en/latest/manual/control-flow/#man-short-circuit-evaluation">short circuit operators</a> are <code>&&</code> and <code>||</code>. For simple Boolean values, they perform a related task, though have a more general usage.</p>
</div>
</div>
<h5>Example</h5>
<p>One of <a href="http://en.wikipedia.org/wiki/De_Morgan%27s_laws">DeMorgan's Laws</a> states that "not (A and B)" is the same as "(not A) or (not B)". This is a kind of distributive law for "not", but note how the "and" changes to "or". We can verify this law systematically. For example, the following shows it true for 1 of the 4 possible cases for the pair <code>A</code>, <code>B</code> to take:</p>
<pre class='hljl'>
<span class='hljl-n'>A</span><span class='hljl-p'>,</span><span class='hljl-n'>B</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-kc'>true</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-kc'>false</span><span class='hljl-t'> </span><span class='hljl-cs'>## also true, true; false, true; and false, false</span><span class='hljl-t'>
</span><span class='hljl-oB'>!</span><span class='hljl-p'>(</span><span class='hljl-n'>A</span><span class='hljl-t'> </span><span class='hljl-oB'>&</span><span class='hljl-t'> </span><span class='hljl-n'>B</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>==</span><span class='hljl-t'> </span><span class='hljl-oB'>!</span><span class='hljl-n'>A</span><span class='hljl-t'> </span><span class='hljl-oB'>|</span><span class='hljl-t'> </span><span class='hljl-oB'>!</span><span class='hljl-n'>B</span>
</pre>
<pre class="output">
true
</pre>
<h2>Precedence</h2>
<p>The question of when parentheses are needed and when they are not is answered by the <a href="http://julia.readthedocs.org/en/latest/manual/mathematical-operations/#operator-precedence">precedence</a> rules implemented. Earlier, we wrote</p>
<pre class='hljl'>
<span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-ni'>7</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>|</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-ni'>7</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
true
</pre>
<p>To represent <span class="math">$\lvert x-5\rvert > 7$</span>. Were the parentheses necessary? Let's just check.</p>
<pre class='hljl'>
<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-ni'>7</span><span class='hljl-t'> </span><span class='hljl-oB'>|</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-ni'>7</span>
</pre>
<pre class="output">
false
</pre>
<p>So yes, they were. The precedence rules perform <code>|</code> before <code><</code> or <code>></code>, so without the extra pair of parentheses, we would have</p>
<pre class='hljl'>
<span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-oB'>-</span><span class='hljl-ni'>7</span><span class='hljl-t'> </span><span class='hljl-oB'>|</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-ni'>5</span><span class='hljl-p'>))</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-ni'>7</span>
</pre>
<pre class="output">
false
</pre>
<p>which is not what is desired at all. (The value of <code>-7 | x</code> is <code>-5</code> – as <code>|</code> does something completely different when the two arguments are not boolean.)</p>
<p>A thorough understanding of the precedence rules can help eliminate unnecessary parentheses, but in most cases it is easier just to put them in.</p>
<h2>Arithmetic with</h2>
<p>For convenience, basic arithmetic can be performed with Boolean values, <code>false</code> becomes <span class="math">$0$</span> and true <span class="math">$1$</span>. For example, both these expressions make sense:</p>
<pre class='hljl'>
<span class='hljl-kc'>true</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-kc'>true</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-kc'>false</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-kc'>false</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-ni'>1000</span>
</pre>
<pre class="output">
(2, 0)
</pre>
<p>The first example shows a common means used to count the number of <code>true</code> values in a collection of Boolean values – just add them.</p>
<p>This can be cleverly exploited. For example, the following expression returns <code>x</code> when it is positive and <span class="math">$0$</span> otherwise:</p>
<pre class='hljl'>
<span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>></span><span class='hljl-t'> </span><span class='hljl-ni'>0</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-n'>x</span>
</pre>
<pre class="output">
18
</pre>
<p>There is a built in function, <code>max</code> that can be used for this: <code>max(0, x)</code>.</p>
<p>This expression returns <code>x</code> if it is between <span class="math">$-10$</span> and <span class="math">$10$</span> and otherwise <span class="math">$-10$</span> or <span class="math">$10$</span> depending on whether <span class="math">$x$</span> is negative or positive.</p>
<pre class='hljl'>
<span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-ni'>10</span><span class='hljl-p'>)</span><span class='hljl-oB'>*</span><span class='hljl-p'>(</span><span class='hljl-oB'>-</span><span class='hljl-ni'>10</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>>=</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-ni'>10</span><span class='hljl-p'>)</span><span class='hljl-oB'>*</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-ni'>10</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-oB'>>=</span><span class='hljl-ni'>10</span><span class='hljl-p'>)</span><span class='hljl-oB'>*</span><span class='hljl-ni'>10</span>
</pre>
<pre class="output">
10
</pre>
<p>The <code>clamp(x, a, b)</code> performs this task more generally, and is used as in <code>clamp(x, -10, 10)</code>.</p>
<h2>Questions</h2>
<h6>Question</h6>
<p>Is <code>e^pi</code> or <code>pi^e</code> greater?</p>
<form name="WeaveQuestion" data-id="u0tbJ64D" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_u0tbJ64D" value="1"><div class="markdown"><p><code>e^pi</code> is less than <code>pi^e</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_u0tbJ64D" value="2"><div class="markdown"><p><code>e^pi</code> is greater than <code>pi^e</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_u0tbJ64D" value="3"><div class="markdown"><p><code>e^pi</code> is equal to <code>pi^e</code></p>
</div>
</label>
</div>
<div id="u0tbJ64D_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_u0tbJ64D']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#u0tbJ64D_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#u0tbJ64D_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>Is <span class="math">$\sin(1000)$</span> positive?</p>
<form name="WeaveQuestion" data-id="sdhlmAmt" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_sdhlmAmt" value="1"><div class="markdown"><p>Yes</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_sdhlmAmt" value="2"><div class="markdown"><p>No</p>
</div>
</label>
</div>
<div id="sdhlmAmt_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_sdhlmAmt']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#sdhlmAmt_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#sdhlmAmt_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>Suppose you know <span class="math">$0 < a < b$</span>. What can you say about the relationship between <span class="math">$-1/a$</span> and <span class="math">$-1/b$</span>?</p>
<form name="WeaveQuestion" data-id="ODtiEUjr" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_ODtiEUjr" value="1"><div class="markdown">$-1/a < -1/b$
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_ODtiEUjr" value="2"><div class="markdown">$-1/a > -1/b$
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_ODtiEUjr" value="3"><div class="markdown">$-1/a \geq -1/b$
</div>
</label>
</div>
<div id="ODtiEUjr_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_ODtiEUjr']").on("change", function() {
correct = this.value == 3;
if(correct) {
$("#ODtiEUjr_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#ODtiEUjr_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Suppose you know <span class="math">$a < 0 < b$</span>, is it true that <span class="math">$1/a > 1/b$</span>?</h6>
<form name="WeaveQuestion" data-id="e1FM4c5W" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_e1FM4c5W" value="1"><div class="markdown"><p>It is never true, as $1/a$ is negative and $1/b$ is positive</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_e1FM4c5W" value="2"><div class="markdown"><p>It can sometimes be true, though not always.</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_e1FM4c5W" value="3"><div class="markdown"><p>Yes, it is always true.</p>
</div>
</label>
</div>
<div id="e1FM4c5W_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_e1FM4c5W']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#e1FM4c5W_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#e1FM4c5W_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>The <code>airyai</code> <a href="http://en.wikipedia.org/wiki/Airy_function">function</a> is a special function named after a British Astronomer who realized the function's value in his studies of the rainbow. The <code>SpecialFunctions</code> package must be loaded to include this function, which is done with the accompanying package <code>CalculusWithJulia</code>:</p>
<pre class='hljl'>
<span class='hljl-k'>using</span><span class='hljl-t'> </span><span class='hljl-n'>CalculusWithJulia</span><span class='hljl-t'> </span><span class='hljl-cs'># loads the `SpecialFunctions` package</span><span class='hljl-t'>
</span><span class='hljl-nf'>airyai</span><span class='hljl-p'>(</span><span class='hljl-ni'>0</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
0.3550280538878172
</pre>
<p>It is known that this function is always positive for <span class="math">$x > 0$</span>, though not so for negative values of <span class="math">$x$</span>. Which of these indicates the first negative value : <code>airyai(-1) <0</code>, <code>airyai(-2) < 0</code>, ..., or <code>airyai(-5) < 0</code>?</p>
<form name="WeaveQuestion" data-id="PktkpI8y" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_PktkpI8y" value="1"><div class="markdown"><p><code>airyai(-1) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_PktkpI8y" value="2"><div class="markdown"><p><code>airyai(-2) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_PktkpI8y" value="3"><div class="markdown"><p><code>airyai(-3) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_PktkpI8y" value="4"><div class="markdown"><p><code>airyai(-4) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_PktkpI8y" value="5"><div class="markdown"><p><code>airyai(-5) < 0</code></p>
</div>
</label>
</div>
<div id="PktkpI8y_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_PktkpI8y']").on("change", function() {
correct = this.value == 3;
if(correct) {
$("#PktkpI8y_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#PktkpI8y_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>By trying three different values of <span class="math">$x > 0$</span> which of these could possibly be always true:</p>
<form name="WeaveQuestion" data-id="sJTDcdGU" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_sJTDcdGU" value="1"><div class="markdown"><p><code>x^x <= (1/e)^(1/e)</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_sJTDcdGU" value="2"><div class="markdown"><p><code>x^x >= (1/e)^(1/e)</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_sJTDcdGU" value="3"><div class="markdown"><p><code>x^x == (1/e)^(1/e)</code></p>
</div>
</label>
</div>
<div id="sJTDcdGU_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_sJTDcdGU']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#sJTDcdGU_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#sJTDcdGU_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>Student logic says <span class="math">$(x+y)^p = x^p + y^p$</span>. Of course, this isn't correct for all <span class="math">$p$</span> and <span class="math">$x$</span>. By trying a few points, which is true when <span class="math">$x,y > 0$</span> and <span class="math">$0 < p < 1$</span>:</p>
<form name="WeaveQuestion" data-id="PIwcvIdb" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_PIwcvIdb" value="1"><div class="markdown"><p><code>(x+y)^p == x^p + y^p</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_PIwcvIdb" value="2"><div class="markdown"><p><code>(x+y)^p < x^p + y^p</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_PIwcvIdb" value="3"><div class="markdown"><p><code>(x+y)^p > x^p + y^p</code></p>
</div>
</label>
</div>
<div id="PIwcvIdb_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_PIwcvIdb']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#PIwcvIdb_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#PIwcvIdb_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>According to Wikipedia, one of the following inequalities is always true for <span class="math">$a, b > 0$</span> (as proved by I. Ilani in JSTOR,AMM,Vol.97,No.1,1990). Which one?</p>
<form name="WeaveQuestion" data-id="u7OoONUv" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_u7OoONUv" value="1"><div class="markdown"><p><code>a^a + b^b <= a^b + b^a</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_u7OoONUv" value="2"><div class="markdown"><p><code>a^a + b^b >= a^b + b^a</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_u7OoONUv" value="3"><div class="markdown"><p><code>a^b + b^a <= 1</code></p>
</div>
</label>
</div>
<div id="u7OoONUv_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_u7OoONUv']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#u7OoONUv_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#u7OoONUv_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>Is <span class="math">$3$</span> in the set <span class="math">$\lvert x - 2\rvert < 1/2$</span>?</p>
<form name="WeaveQuestion" data-id="t0HNVKVm" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_t0HNVKVm" value="1"><div class="markdown"><p>Yes</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_t0HNVKVm" value="2"><div class="markdown"><p>No</p>
</div>
</label>
</div>
<div id="t0HNVKVm_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_t0HNVKVm']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#t0HNVKVm_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#t0HNVKVm_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>Which of the following is equivalent to <span class="math">$\lvert x - a\rvert > b$</span>:</p>
<form name="WeaveQuestion" data-id="JODsgxNF" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_JODsgxNF" value="1"><div class="markdown">$-b < x - a < b$
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_JODsgxNF" value="2"><div class="markdown"><p>$ -b < x-a \text{ and } x - a < b$</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_JODsgxNF" value="3"><div class="markdown"><p>$ x - a < -b \text{ or } x - a > b$</p>
</div>
</label>
</div>
<div id="JODsgxNF_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_JODsgxNF']").on("change", function() {
correct = this.value == 3;
if(correct) {
$("#JODsgxNF_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#JODsgxNF_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>If <span class="math">$\lvert x - \pi\rvert < 1/10$</span> is <span class="math">$\lvert \sin(x) - \sin(\pi)\rvert < 1/10$</span>?</p>
<p>Guess an answer based on a few runs of</p>
<pre class='hljl'>
<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-n'>pi</span><span class='hljl-t'> </span><span class='hljl-oB'>+</span><span class='hljl-t'> </span><span class='hljl-nfB'>0.2</span><span class='hljl-t'> </span><span class='hljl-oB'>*</span><span class='hljl-t'> </span><span class='hljl-nf'>rand</span><span class='hljl-p'>()</span><span class='hljl-t'>
</span><span class='hljl-nf'>abs</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-n'>pi</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-ni'>10</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-nf'>abs</span><span class='hljl-p'>(</span><span class='hljl-nf'>sin</span><span class='hljl-p'>(</span><span class='hljl-n'>x</span><span class='hljl-p'>)</span><span class='hljl-t'> </span><span class='hljl-oB'>-</span><span class='hljl-t'> </span><span class='hljl-nf'>sin</span><span class='hljl-p'>(</span><span class='hljl-n'>pi</span><span class='hljl-p'>))</span><span class='hljl-t'> </span><span class='hljl-oB'><</span><span class='hljl-t'> </span><span class='hljl-ni'>1</span><span class='hljl-oB'>/</span><span class='hljl-ni'>10</span>
</pre>
<form name="WeaveQuestion" data-id="JE9ASkl6" data-controltype="radio">
<div class="form-group ">
<div class="radio inline">
<label>
<input type="radio" name="radio_JE9ASkl6" value="1"><div class="markdown"><p>true</p>
</div>
</label>
</div>
<div class="radio inline">
<label>
<input type="radio" name="radio_JE9ASkl6" value="2"><div class="markdown"><p>false</p>
</div>
</label>
</div>
<div id="JE9ASkl6_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_JE9ASkl6']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#JE9ASkl6_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#JE9ASkl6_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6>
<p>Does <code>12</code> satisfy <span class="math">$\lvert x - 3\rvert + \lvert x-9\rvert > 12$</span>?</p>
<form name="WeaveQuestion" data-id="Bejy4w6T" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_Bejy4w6T" value="1"><div class="markdown"><p>Yes</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_Bejy4w6T" value="2"><div class="markdown"><p>No</p>
</div>
</label>
</div>
<div id="Bejy4w6T_message"></div>
</div>
</form>