forked from CalculusWithJulia/CalculusWithJulia.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logical_expressions.html
823 lines (664 loc) · 34.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
rel="stylesheet">
<style>
.julia {font-family: "Source Code Pro";
color:#0033CC;
}
body { padding-top: 60px; }
h5:before {content:"\2746\ ";}
h6:before {content:"\2742\ ";}
pre {display: block;}
</style>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- .julia:before {content: "julia> "} -->
<style></style>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script>
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ["\$","\$"], ["\\(","\\)"]]
},
displayAlign: "left",
displayIndent: "5%"
});
</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>
<a class="navbar-brand" href="../toc.html">Calculus with Julia</a>
</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="container-fluid">
<div class="span10 offset1">
<h1>Inequalities, Logical expressions</h1><p>In mathematics it is common to test if an expression is true or false. For example, is the point $(1,2)$ inside the disc $x^2 + y^2 \leq 1$? We would check this by substituting $1$ for $x$ and $2$ for $y$, evaluating both sides of the inequality and then assessing of the relationship is true or false. In this case, we end up with a comparison of $5 \leq 1$, 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="sourceCode julia">x, y = 1, 2
x^2 + y^2 <= 1</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><p>The use of <code>==</code> is necessary, as <code>=</code> is used for assignment.</p><p>The <code>!</code> operator takes a boolean value and negates it. It uses prefix notation:</p><pre class="sourceCode julia">!true</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 $a < b$ then for any $c$ it is also true that $a + c < b + c$.</p><p>We can't "prove" this through examples, but we can investigate it by the choice of various values of $a$, $b$, and $c$. For example:</p><pre class="sourceCode julia">a,b,c = 1,2,3
a < b, a + c < b + c</pre>
<pre class="output">
(true,true)</pre>
<p>Or in reverse:</p><pre class="sourceCode julia">a,b,c = 3,2,1
a < b, a + c < b + c</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 $a < b$ and $c > 0$. Then $ca < cb$. Here we investigate using 3 random values (which will be positive):</p><pre class="sourceCode julia">a,b,c = rand(3) # 3 random numbers in (0,1)
a < b, c*a < c*b</pre>
<pre class="output">
(true,true)</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 $c > 0$ is needed. For example, if $c = -1$, then we have $a < b$ if and only if $-a > -b$. That is the inequality is "flipped."</p><pre class="sourceCode julia">a,b = rand(2)
a < b, -a > -b</pre>
<pre class="output">
(true,true)</pre>
<p>Again, whenever this is run, the two logical values should be the same. The values $a$ and $-a$ are the same distance from $0$, but on opposite sides. Hence if $0 < a < b$, then $b$ is farther from $0$ than $a$, so $-b$ will be farther from $0$ than $-a$, which in this case says $-b < -a$, as expected.</p><p>Finally, we have the case of division. The relation of $x$ and $1/x$ (for $x > 0$) is that the farther $x$ is from $0$, the closer $1/x$ is to $0$. So large values of $x$ make small values of $1/x$. This leads to this fact for $a,b > 0$: $a < b$ if and only if $1/a > 1/b$.</p><p>We can check with random values again:</p><pre class="sourceCode julia">a,b = rand(2)
a < b, 1/a > 1/b</pre>
<pre class="output">
(true,true)</pre>
<p>In summary we verified numerically that the following hold:</p><ul>
<li><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>.</li>
</ul><ul>
<li><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>.</li>
</ul><ul>
<li><code>a < b</code> if and only if <code>-a > -b</code> for all finite <code>a</code> and <code>b</code>.</li>
</ul><ul>
<li><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>.</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 $\exp(x) \geq 1 + x$ by showing it is true for three different values of $x$. We pick $x=-1$, $0$, and $1$:</p><pre class="sourceCode julia">x = -1; exp(x) >= 1 + x
x = 0; exp(x) >= 1 + x
x = 1; exp(x) >= 1 + x</pre>
<pre class="output">
true</pre>
<p>Now, let's investigate that for any distinct real numbers, $a$ and $b$ that</p>$$~
\frac{e^b - e^a}{b - a} > e^{(a+b)/2}
~$$<p>For this, we use <code>rand(2)</code> to generate two random numbers in $(0,1)$:</p><pre class="sourceCode julia">a, b = rand(2)
(exp(b) - exp(a)) / (b-a) > exp((a+b)/2)</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, $2/(1/a + 1/b)$ is less than or equal to the geometric mean, $\sqrt{ab}$, which is less than or equal to the quadratic mean, $\sqrt{a^2 + b^2}/\sqrt{2}$, using two randomly chosen values:</p><pre class="sourceCode julia">a, b = rand(2)
h = 2 / (1/a + 1/b)
g = (a * b) ^ (1 / 2)
q = sqrt((a^2 + b^2) / 2)
h <= g, g <= q</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>$$~
\lvert x\rvert = \begin{cases}
x & x \geq 0\\
-x & \text{otherwise}.
\end{cases}
~$$<p>The interpretation of $\lvert x\rvert$, as the distance on the number line of $x$ from $0$, means that many relationships are naturally expressed in terms of absolute values. For example, a simple shift: $\lvert x -c\rvert$ is related to the distance $x$ is from the number $c$. As common as they are, the concept can still be confusing when inequalities are involved.</p><p>For example, the expression $\lvert x - 5\rvert < 7$ has solutions which are all values of $x$ within $7$ units of $5$. This would be the values $-2 < x < 12$. If this isn't immediately intuited, then formally $\lvert x - 5 \rvert < 7$ is a compact representation of a chain of inequalities: $-7 < x - 5 < 7$. (Which is really two combined inequalities: $-7 < x-5$ <em>and</em> $x - 5 < 7$.) We can "add" 5 to each side to get $-2 < x < 12$, 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="sourceCode julia">x = 18
abs(x - 5) < 7</pre>
<pre class="output">
false</pre>
<p>This is to be expected, but we could also have written:</p><pre class="sourceCode julia">-7 < x - 5 < 7</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 $\lvert x - 5\rvert > 7$ 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 $-7 < x-5 < 7$ as</p><pre class="sourceCode julia">(-7 < x - 5) & (x - 5 < 7)</pre>
<pre class="output">
false</pre>
<p>and could write $\lvert x-5\rvert > 7$ as</p><pre class="sourceCode julia">(x - 5 < -7) | (x - 5 > 7)</pre>
<pre class="output">
true</pre>
<p>(The first expression is false for $x-18$ and the second expression true.)</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="sourceCode julia">A,B = true, false ## also true, true; false, true; and false, false
!(A & B) == !A | !B</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="sourceCode julia">(x - 5 < -7) | (x - 5 > 7)</pre>
<pre class="output">
true</pre>
<p>To represent $\lvert x-5\rvert > 7$. Were the parentheses necessary? Let's just check. </p><pre class="sourceCode julia">x - 5 < -7 | x - 5 > 7</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="sourceCode julia">(x - 5 < ( (-7 | x) - 5)) > 7</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 $0$ and true $1$. For example, both these expressions make sense:</p><pre class="sourceCode julia">true + true + false, false * 1000</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, this expression returns <code>x</code> when it is positive and $0$ otherwise:</p><pre class="sourceCode julia">(x > 0) * x</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 $-10$ and $10$ and otherwise $-10$ or $10$ depending on whether $x$ is negative or positive.</p><pre class="sourceCode julia">(x < -10)*(-10) + (x >= -10)*(x < 10) * x + (x>=10)*10</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="B4yi3oY7" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_B4yi3oY7" value="1"><div class="markdown"><p><code>e^pi</code> is equal to <code>pi^e</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_B4yi3oY7" 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_B4yi3oY7" value="3"><div class="markdown"><p><code>e^pi</code> is less than <code>pi^e</code></p>
</div>
</label>
</div>
<div id="B4yi3oY7_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_B4yi3oY7']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#B4yi3oY7_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#B4yi3oY7_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>Is sin(1000) positive?</p><form name="WeaveQuestion" data-id="T9K99qDe" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_T9K99qDe" value="1"><div class="markdown"><p>Yes</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_T9K99qDe" value="2"><div class="markdown"><p>No</p>
</div>
</label>
</div>
<div id="T9K99qDe_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_T9K99qDe']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#T9K99qDe_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#T9K99qDe_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>Suppose you know $0 < a < b$. What can you say about the relationship between $-1/a$ and $-1/b$?</p><form name="WeaveQuestion" data-id="T44FVKRE" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_T44FVKRE" value="1"><div class="markdown">$-1/a > -1/b$
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_T44FVKRE" value="2"><div class="markdown">$-1/a < -1/b$
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_T44FVKRE" value="3"><div class="markdown">$-1/a \geq -1/b$
</div>
</label>
</div>
<div id="T44FVKRE_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_T44FVKRE']").on("change", function() {
correct = this.value == 3;
if(correct) {
$("#T44FVKRE_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#T44FVKRE_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Suppose you know $a < 0 < b$, is it true that $1/a > 1/b$?</h6><form name="WeaveQuestion" data-id="KuoGSNiy" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_KuoGSNiy" 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_KuoGSNiy" 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_KuoGSNiy" value="3"><div class="markdown"><p>Yes, it is always true.</p>
</div>
</label>
</div>
<div id="KuoGSNiy_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_KuoGSNiy']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#KuoGSNiy_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#KuoGSNiy_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>The <code>airy</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. It is known that it is always positive for $x > 0$, though not so for negative values of $x$. Which of these indicates the first negative value : <code>airy(-1)<0</code>, <code>airy(-2)<0</code>, ... <code>airy(-5) < 0</code>?</p><form name="WeaveQuestion" data-id="Vzp4ilcC" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_Vzp4ilcC" value="1"><div class="markdown"><p><code>airy(-1) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_Vzp4ilcC" value="2"><div class="markdown"><p><code>airy(-2) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_Vzp4ilcC" value="3"><div class="markdown"><p><code>airy(-3) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_Vzp4ilcC" value="4"><div class="markdown"><p><code>airy(-4) < 0</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_Vzp4ilcC" value="5"><div class="markdown"><p><code>airy(-5) < 0</code></p>
</div>
</label>
</div>
<div id="Vzp4ilcC_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_Vzp4ilcC']").on("change", function() {
correct = this.value == 3;
if(correct) {
$("#Vzp4ilcC_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#Vzp4ilcC_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 $x > 0$ which of these could possibly be always true:</p><form name="WeaveQuestion" data-id="FnXDZhv4" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_FnXDZhv4" 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_FnXDZhv4" 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_FnXDZhv4" value="3"><div class="markdown"><p><code>x^x <= (1/e)^(1/e)</code></p>
</div>
</label>
</div>
<div id="FnXDZhv4_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_FnXDZhv4']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#FnXDZhv4_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#FnXDZhv4_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>Student logic says $(x+y)^p = x^p + y^p$. Of course, this isn't correct for all $p$ and $x$. By trying a few points, which is true when $x,y > 0$ and $0 < p < 1$:</p><form name="WeaveQuestion" data-id="hh3m9iH6" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_hh3m9iH6" 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_hh3m9iH6" 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_hh3m9iH6" value="3"><div class="markdown"><p><code>(x+y)^p < x^p + y^p</code></p>
</div>
</label>
</div>
<div id="hh3m9iH6_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_hh3m9iH6']").on("change", function() {
correct = this.value == 3;
if(correct) {
$("#hh3m9iH6_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#hh3m9iH6_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 $a, b > 0$ (as proved by I. Ilani in JSTOR,AMM,Vol.97,No.1,1990). Which one?</p><form name="WeaveQuestion" data-id="DGB6awdq" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_DGB6awdq" 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_DGB6awdq" 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_DGB6awdq" value="3"><div class="markdown"><p><code>a^b + b^a <= 1</code></p>
</div>
</label>
</div>
<div id="DGB6awdq_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_DGB6awdq']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#DGB6awdq_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#DGB6awdq_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>Is $3$ in the set $\lvert x - 2\rvert < 1/2$?</p><form name="WeaveQuestion" data-id="1rbmWmeR" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_1rbmWmeR" value="1"><div class="markdown"><p>Yes</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_1rbmWmeR" value="2"><div class="markdown"><p>No</p>
</div>
</label>
</div>
<div id="1rbmWmeR_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_1rbmWmeR']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#1rbmWmeR_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#1rbmWmeR_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 $\lvert x - a\rvert > b$:</p><form name="WeaveQuestion" data-id="6Cqs1xKr" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_6Cqs1xKr" value="1"><div class="markdown"><p>$ x - a < -b \text{ or } x - a > b$</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_6Cqs1xKr" 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_6Cqs1xKr" value="3"><div class="markdown">$-b < x - a < b$
</div>
</label>
</div>
<div id="6Cqs1xKr_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_6Cqs1xKr']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#6Cqs1xKr_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#6Cqs1xKr_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>If $\lvert x - \pi\rvert < 1/10$ is $\lvert \sin(x) - \sin(\pi)\rvert < 1/10$?</p><p>Guess an answer based on a few runs of</p><pre class="sourceCode julia">x = pi + 0.2 * rand()
abs(x - pi) < 1/10, abs(sin(x) - sin(pi)) < 1/10
</pre><form name="WeaveQuestion" data-id="cX3nswQP" data-controltype="radio">
<div class="form-group ">
<div class="radio inline">
<label>
<input type="radio" name="radio_cX3nswQP" value="1"><div class="markdown"><p>true</p>
</div>
</label>
</div>
<div class="radio inline">
<label>
<input type="radio" name="radio_cX3nswQP" value="2"><div class="markdown"><p>false</p>
</div>
</label>
</div>
<div id="cX3nswQP_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_cX3nswQP']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#cX3nswQP_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#cX3nswQP_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 $\lvert x - 3\rvert + \lvert x-9\rvert > 12$?</p><form name="WeaveQuestion" data-id="EcDTiOry" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_EcDTiOry" value="1"><div class="markdown"><p>Yes</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_EcDTiOry" value="2"><div class="markdown"><p>No</p>
</div>
</label>
</div>
<div id="EcDTiOry_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_EcDTiOry']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#EcDTiOry_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#EcDTiOry_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>Which of these will show DeMorgan's law holds when both values are <code>false</code>:</p><form name="WeaveQuestion" data-id="5T3X6Dwc" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_5T3X6Dwc" value="1"><div class="markdown"><p><code>!(false & false) == !false | !false</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_5T3X6Dwc" value="2"><div class="markdown"><p><code>!(false & false) == !false & !false</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_5T3X6Dwc" value="3"><div class="markdown"><p><code>!(false & false) == false !& false</code></p>
</div>
</label>
</div>
<div id="5T3X6Dwc_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_5T3X6Dwc']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#5T3X6Dwc_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#5T3X6Dwc_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>For floating point numbers there are two special values <code>Inf</code> and <code>NaN</code>. For which of these is the answer always <code>false</code>:</p><form name="WeaveQuestion" data-id="iVGO41jA" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_iVGO41jA" value="1"><div class="markdown"><p><code>Inf < 3.0</code> and <code>3.0 <= Inf</code></p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_iVGO41jA" value="2"><div class="markdown"><p><code>NaN < 3.0</code> and <code>3.0 <= NaN</code></p>
</div>
</label>
</div>
<div id="iVGO41jA_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_iVGO41jA']").on("change", function() {
correct = this.value == 2;
if(correct) {
$("#iVGO41jA_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#iVGO41jA_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
<h6>Question</h6><p>The IEEE 754 standard is about floating point numbers, for which there are the special values <code>Inf</code>, <code>-Inf</code>, <code>NaN</code>, and (surprisingly <code>-0</code>. Here are 4 facts that seem reasonable:</p><ul>
<li>Positive zero is equal but not greater than negative zero.</li>
</ul><ul>
<li><code>Inf</code> is equal to itself and greater than everything else except <code>NaN</code>.</li>
</ul><ul>
<li><code>-Inf</code> is equal to itself and less then everything else except <code>NaN</code>.</li>
</ul><ul>
<li><code>NaN</code> is not equal to, not less than, and not greater than anything, including itself.</li>
</ul><p>Do all four seem to be the case within <code>Julia</code>? Find your answer by trial and error.</p><form name="WeaveQuestion" data-id="HiJ05MGX" data-controltype="radio">
<div class="form-group ">
<div class="radio">
<label>
<input type="radio" name="radio_HiJ05MGX" value="1"><div class="markdown"><p>Yes</p>
</div>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio_HiJ05MGX" value="2"><div class="markdown"><p>No</p>
</div>
</label>
</div>
<div id="HiJ05MGX_message"></div>
</div>
</form>
<script text="text/javascript">
$("input:radio[name='radio_HiJ05MGX']").on("change", function() {
correct = this.value == 1;
if(correct) {
$("#HiJ05MGX_message").html("<div class='alert alert-success'><span class='glyphicon glyphicon-thumbs-up'> Correct</span></div>");
} else {
$("#HiJ05MGX_message").html("<div class='alert alert-warning'><span class='glyphicon glyphicon-thumbs-down'> Incorrect</span></div>");
}
});
</script>
</div>
</div>
</body>
</html>