CalculusWithJuliaNotes.jl/quarto/308797b5/precalc/logical_expressions.html

2222 lines
121 KiB
HTML
Raw Normal View History

2022-08-11 19:00:43 +02:00
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.0.32">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Calculus with Julia - 4&nbsp; Inequalities, Logical expressions</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
<script src="../site_libs/clipboard/clipboard.min.js"></script>
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="../site_libs/quarto-search/fuse.min.js"></script>
<script src="../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../">
<link href="../precalc/vectors.html" rel="next">
<link href="../precalc/numbers_types.html" rel="prev">
<script src="../site_libs/quarto-html/quarto.js"></script>
<script src="../site_libs/quarto-html/popper.min.js"></script>
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../site_libs/quarto-html/anchor.min.js"></script>
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit"
}
}</script>
<script async="" src="https://hypothes.is/embed.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<script type="application/javascript">define('jquery', [],function() {return window.jQuery;})</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
</head>
<body class="nav-sidebar floating nav-fixed">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="navbar navbar-expand-lg navbar-dark ">
<div class="navbar-container container-fluid">
<a class="navbar-brand" href="../index.html">
<img src="../logo.png" alt="">
<span class="navbar-title">Calculus with Julia</span>
</a>
<div id="quarto-search" class="" title="Search"></div>
</div> <!-- /container-fluid -->
</nav>
<nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<div class="container-fluid d-flex justify-content-between">
<h1 class="quarto-secondary-nav-title"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></h1>
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
<i class="bi bi-chevron-right"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../index.html" class="sidebar-item-text sidebar-link">Preface</a>
</div>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">Precalculus Concepts</a>
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="true">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/calculator.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">From calculator to computer</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/variables.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Variables</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/numbers_types.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Number systems</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/logical_expressions.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Vectors</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/ranges.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Ranges and Sets</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">The Graph of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Function manipulations</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/inversefunctions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">The Inverse of a Function</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Polynomials</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomial_roots.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Roots of a polynomial</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/polynomials_package.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">13</span>&nbsp; <span class="chapter-title">The Polynomials package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/rational_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span>&nbsp; <span class="chapter-title">Rational functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/exp_log_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span>&nbsp; <span class="chapter-title">Exponential and logarithmic functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/trig_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span>&nbsp; <span class="chapter-title">Trigonometric functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../precalc/julia_overview.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span>&nbsp; <span class="chapter-title">Overview of Julia commands</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">Limits</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span>&nbsp; <span class="chapter-title">Limits</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/limits_extensions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span>&nbsp; <span class="chapter-title">Limits, issues, extensions of the concept</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/continuity.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span>&nbsp; <span class="chapter-title">Continuity</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../limits/intermediate_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span>&nbsp; <span class="chapter-title">Implications of continuity</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">Derivatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span>&nbsp; <span class="chapter-title">Derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/numeric_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span>&nbsp; <span class="chapter-title">Numeric derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/symbolic_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span>&nbsp; <span class="chapter-title">Symbolic derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">25</span>&nbsp; <span class="chapter-title">The mean value theorem for differentiable functions.</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/optimization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span>&nbsp; <span class="chapter-title">Optimization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/first_second_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span>&nbsp; <span class="chapter-title">The first and second derivatives</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/curve_sketching.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span>&nbsp; <span class="chapter-title">Curve Sketching</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/linearization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span>&nbsp; <span class="chapter-title">Linearization</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/newtons_method.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span>&nbsp; <span class="chapter-title">Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/more_zeros.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">31</span>&nbsp; <span class="chapter-title">Derivative-free alternatives to Newtons method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/lhospitals_rule.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">32</span>&nbsp; <span class="chapter-title">LHospitals Rule</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/implicit_differentiation.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">33</span>&nbsp; <span class="chapter-title">Implicit Differentiation</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/related_rates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">34</span>&nbsp; <span class="chapter-title">Related rates</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../derivatives/taylor_series_polynomials.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">35</span>&nbsp; <span class="chapter-title">Taylor Polynomials and other Approximating Polynomials</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">Integrals</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-4" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">36</span>&nbsp; <span class="chapter-title">Area under a curve</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/ftc.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">37</span>&nbsp; <span class="chapter-title">Fundamental Theorem or Calculus</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/substitution.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">38</span>&nbsp; <span class="chapter-title">Substitution</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/integration_by_parts.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">39</span>&nbsp; <span class="chapter-title">Integration By Parts</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/partial_fractions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">40</span>&nbsp; <span class="chapter-title">Partial Fractions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/improper_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">41</span>&nbsp; <span class="chapter-title">Improper Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">42</span>&nbsp; <span class="chapter-title">Mean value theorem for integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/area_between_curves.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">43</span>&nbsp; <span class="chapter-title">Area between two curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/center_of_mass.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">44</span>&nbsp; <span class="chapter-title">Center of Mass</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/volumes_slice.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">45</span>&nbsp; <span class="chapter-title">Volumes by slicing</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/arc_length.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">46</span>&nbsp; <span class="chapter-title">Arc length</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integrals/surface_area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">47</span>&nbsp; <span class="chapter-title">Surface Area</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">ODEs</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-5" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/odes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">48</span>&nbsp; <span class="chapter-title">ODEs</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/euler.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">49</span>&nbsp; <span class="chapter-title">Eulers method</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/solve.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">50</span>&nbsp; <span class="chapter-title">The problem-algorithm-solve interface</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../ODEs/differential_equations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">51</span>&nbsp; <span class="chapter-title">The <code>DifferentialEquations</code> suite</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">Differential vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/polar_coordinates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">52</span>&nbsp; <span class="chapter-title">Polar Coordinates and Curves</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">53</span>&nbsp; <span class="chapter-title">Vectors and matrices</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">54</span>&nbsp; <span class="chapter-title">Vector-valued functions, <span class="math inline">\(f:R \rightarrow R^n\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">55</span>&nbsp; <span class="chapter-title">Scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/scalar_functions_applications.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">56</span>&nbsp; <span class="chapter-title">Applications with scalar functions</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/vector_fields.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">57</span>&nbsp; <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../differentiable_vector_calculus/plots_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">58</span>&nbsp; <span class="chapter-title">2D and 3D plots in Julia with Plots</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">Integral vector calculus</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-7" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/double_triple_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">59</span>&nbsp; <span class="chapter-title">Multi-dimensional integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/line_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">60</span>&nbsp; <span class="chapter-title">Line and Surface Integrals</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/div_grad_curl.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">61</span>&nbsp; <span class="chapter-title">The Gradient, Divergence, and Curl</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/stokes_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">62</span>&nbsp; <span class="chapter-title">Greens Theorem, Stokes Theorem, and the Divergence Theorem</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../integral_vector_calculus/review.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">63</span>&nbsp; <span class="chapter-title">Quick Review of Vector Calculus</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">Alternatives</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-8" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/plotly_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">64</span>&nbsp; <span class="chapter-title">JavaScript based plotting libraries</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../alternatives/makie_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">65</span>&nbsp; <span class="chapter-title">Calculus plots with Makie</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item sidebar-item-section">
<div class="sidebar-item-container">
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">Appendices</a>
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">
<i class="bi bi-chevron-right ms-2"></i>
</a>
</div>
<ul id="quarto-sidebar-section-9" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/getting_started_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">66</span>&nbsp; <span class="chapter-title">Getting started with Julia</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/julia_interfaces.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">67</span>&nbsp; <span class="chapter-title">Julia interfaces</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/calculus_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">68</span>&nbsp; <span class="chapter-title">The <code>CalculusWithJulia</code> package</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/unicode.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">69</span>&nbsp; <span class="chapter-title">Usages of Unicode symbols</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../misc/quick_notes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">70</span>&nbsp; <span class="chapter-title">Quick introduction to Calculus with Julia</span></a>
</div>
</li>
</ul>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../references.html" class="sidebar-item-text sidebar-link">References</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#boolean-values" id="toc-boolean-values" class="nav-link active" data-scroll-target="#boolean-values"> <span class="header-section-number">4.1</span> Boolean values</a></li>
<li><a href="#algebra-of-inequalities" id="toc-algebra-of-inequalities" class="nav-link" data-scroll-target="#algebra-of-inequalities"> <span class="header-section-number">4.2</span> Algebra of inequalities</a>
<ul class="collapse">
<li><a href="#examples" id="toc-examples" class="nav-link" data-scroll-target="#examples"> <span class="header-section-number">4.2.1</span> Examples</a></li>
</ul></li>
<li><a href="#chaining-combining-expressions-absolute-values" id="toc-chaining-combining-expressions-absolute-values" class="nav-link" data-scroll-target="#chaining-combining-expressions-absolute-values"> <span class="header-section-number">4.3</span> Chaining, combining expressions: absolute values</a></li>
<li><a href="#precedence" id="toc-precedence" class="nav-link" data-scroll-target="#precedence"> <span class="header-section-number">4.4</span> Precedence</a></li>
<li><a href="#arithmetic-with" id="toc-arithmetic-with" class="nav-link" data-scroll-target="#arithmetic-with"> <span class="header-section-number">4.5</span> Arithmetic with</a></li>
<li><a href="#questions" id="toc-questions" class="nav-link" data-scroll-target="#questions"> <span class="header-section-number">4.6</span> Questions</a></li>
</ul>
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/main/quarto/precalc/logical_expressions.qmd" class="toc-action">Edit this page</a></p><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/issues/new" class="toc-action">Report an issue</a></p></div></div></nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title d-none d-lg-block"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Inequalities, Logical expressions</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<p>In this section we use the following package:</p>
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">CalculusWithJulia </span><span class="co"># loads the `SpecialFunctions` package</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<section id="boolean-values" class="level2" data-number="4.1">
<h2 data-number="4.1" class="anchored" data-anchor-id="boolean-values"><span class="header-section-number">4.1</span> 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 inline">\((1,2)\)</span> inside the disc <span class="math inline">\(x^2 + y^2 \leq 1\)</span>? We would check this by substituting <span class="math inline">\(1\)</span> for <span class="math inline">\(x\)</span> and <span class="math inline">\(2\)</span> for <span class="math inline">\(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 inline">\(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>
<div class="cell" data-hold="true" data-execution_count="4">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>x, y <span class="op">=</span> <span class="fl">1</span>, <span class="fl">2</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">&lt;=</span> <span class="fl">1</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<pre><code>false</code></pre>
</div>
</div>
<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>&lt;</code>, <code>&lt;=</code>, <code>==</code>, <code>&gt;=</code>, <code>&gt;</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="callout-warning callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Warning
</div>
</div>
<div class="callout-body-container callout-body">
<p>The use of <code>==</code> is necessary, as <code>=</code> is used for assignment and mutation.”)</p>
</div>
</div>
<p>The <code>!</code> operator takes a boolean value and negates it. It uses prefix notation:</p>
<div class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>!<span class="cn">true</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="6">
<pre><code>false</code></pre>
</div>
</div>
<p>For convenience, <code>a != b</code> can be used in place of <code>!(a == b)</code>.</p>
</section>
<section id="algebra-of-inequalities" class="level2" data-number="4.2">
<h2 data-number="4.2" class="anchored" data-anchor-id="algebra-of-inequalities"><span class="header-section-number">4.2</span> Algebra of inequalities</h2>
<p>To illustrate, lets see that the algebra of expressions works as expected.</p>
<p>For example, if <span class="math inline">\(a &lt; b\)</span> then for any <span class="math inline">\(c\)</span> it is also true that <span class="math inline">\(a + c &lt; b + c\)</span>.</p>
<p>We cant “prove” this through examples, but we can investigate it by the choice of various values of <span class="math inline">\(a\)</span>, <span class="math inline">\(b\)</span>, and <span class="math inline">\(c\)</span>. For example:</p>
<div class="cell" data-hold="true" data-execution_count="6">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>a,b,c <span class="op">=</span> <span class="fl">1</span>,<span class="fl">2</span>,<span class="fl">3</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>a <span class="op">&lt;</span> b, a <span class="op">+</span> c <span class="op">&lt;</span> b <span class="op">+</span> c</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>(true, true)</code></pre>
</div>
</div>
<p>Or in reverse:</p>
<div class="cell" data-hold="true" data-execution_count="7">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>a,b,c <span class="op">=</span> <span class="fl">3</span>,<span class="fl">2</span>,<span class="fl">1</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>a <span class="op">&lt;</span> b, a <span class="op">+</span> c <span class="op">&lt;</span> b <span class="op">+</span> c</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="8">
<pre><code>(false, false)</code></pre>
</div>
</div>
<p>Trying other choices will show that the two answers are either both <code>false</code> or both <code>true</code>.</p>
<div class="callout-warning callout callout-style-default callout-captioned">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-caption-container flex-fill">
Warning
</div>
</div>
<div class="callout-body-container callout-body">
<p>Well, almost… When <code>Inf</code> or <code>NaN</code> are involved, this may not hold, for example <code>1 + Inf &lt; 2 + Inf</code> is actually <code>false</code>. As would be <code>1 + (typemax(1)-1) &lt; 2 + (typemax(1)-1)</code>.</p>
</div>
</div>
<p>So adding or subtracting most 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 inline">\(a &lt; b\)</span> and <span class="math inline">\(c &gt; 0\)</span>. Then <span class="math inline">\(ca &lt; cb\)</span>. Here we investigate using <span class="math inline">\(3\)</span> random values (which will be positive):</p>
<div class="cell" data-hold="true" data-execution_count="8">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>a,b,c <span class="op">=</span> <span class="fu">rand</span>(<span class="fl">3</span>) <span class="co"># 3 random numbers in [0,1)</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>a <span class="op">&lt;</span> b, c<span class="op">*</span>a <span class="op">&lt;</span> c<span class="op">*</span>b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<pre><code>(true, true)</code></pre>
</div>
</div>
<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 inline">\(c &gt; 0\)</span> is needed. For example, if <span class="math inline">\(c = -1\)</span>, then we have <span class="math inline">\(a &lt; b\)</span> if and only if <span class="math inline">\(-a &gt; -b\)</span>. That is the inequality is “flipped.”</p>
<div class="cell" data-hold="true" data-execution_count="9">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>a,b <span class="op">=</span> <span class="fu">rand</span>(<span class="fl">2</span>)</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>a <span class="op">&lt;</span> b, <span class="op">-</span>a <span class="op">&gt;</span> <span class="op">-</span>b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="10">
<pre><code>(false, false)</code></pre>
</div>
</div>
<p>Again, whenever this is run, the two logical values should be the same. The values <span class="math inline">\(a\)</span> and <span class="math inline">\(-a\)</span> are the same distance from <span class="math inline">\(0\)</span>, but on opposite sides. Hence if <span class="math inline">\(0 &lt; a &lt; b\)</span>, then <span class="math inline">\(b\)</span> is farther from <span class="math inline">\(0\)</span> than <span class="math inline">\(a\)</span>, so <span class="math inline">\(-b\)</span> will be farther from <span class="math inline">\(0\)</span> than <span class="math inline">\(-a\)</span>, which in this case says <span class="math inline">\(-b &lt; -a\)</span>, as expected.</p>
<p>Finally, we have the case of division. The relation of <span class="math inline">\(x\)</span> and <span class="math inline">\(1/x\)</span> (for <span class="math inline">\(x &gt; 0\)</span>) is that the farther <span class="math inline">\(x\)</span> is from <span class="math inline">\(0\)</span>, the closer <span class="math inline">\(1/x\)</span> is to <span class="math inline">\(0\)</span>. So large values of <span class="math inline">\(x\)</span> make small values of <span class="math inline">\(1/x\)</span>. This leads to this fact for <span class="math inline">\(a,b &gt; 0\)</span>: <span class="math inline">\(a &lt; b\)</span> if and only if <span class="math inline">\(1/a &gt; 1/b\)</span>.</p>
<p>We can check with random values again:</p>
<div class="cell" data-hold="true" data-execution_count="10">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>a,b <span class="op">=</span> <span class="fu">rand</span>(<span class="fl">2</span>)</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>a <span class="op">&lt;</span> b, <span class="fl">1</span><span class="op">/</span>a <span class="op">&gt;</span> <span class="fl">1</span><span class="op">/</span>b</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<pre><code>(true, true)</code></pre>
</div>
</div>
<p>In summary we investigated numerically that the following hold:</p>
<ul>
<li><code>a &lt; b</code> if and only if <code>a + c &lt; b + c</code> for all finite <code>a</code>, <code>b</code>, and <code>c</code>.</li>
<li><code>a &lt; b</code> if and only if <code>c*a &lt; c*b</code> for all finite <code>a</code> and <code>b</code>, and finite, positive <code>c</code>.</li>
<li><code>a &lt; b</code> if and only if <code>-a &gt; -b</code> for all finite <code>a</code> and <code>b</code>.</li>
<li><code>a &lt; b</code> if and only if <code>1/a &gt; 1/b</code> for all finite, positive <code>a</code> and <code>b</code>.</li>
</ul>
<section id="examples" class="level3" data-number="4.2.1">
<h3 data-number="4.2.1" class="anchored" data-anchor-id="examples"><span class="header-section-number">4.2.1</span> Examples</h3>
<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 inline">\(e^x \geq 1 + x\)</span> by showing it is true for three different values of <span class="math inline">\(x\)</span>. We pick <span class="math inline">\(x=-1\)</span>, <span class="math inline">\(0\)</span>, and <span class="math inline">\(1\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="11">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="op">-</span><span class="fl">1</span>; <span class="fu">exp</span>(x) <span class="op">&gt;=</span> <span class="fl">1</span> <span class="op">+</span> x</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fl">0</span>; <span class="fu">exp</span>(x) <span class="op">&gt;=</span> <span class="fl">1</span> <span class="op">+</span> x</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fl">1</span>; <span class="fu">exp</span>(x) <span class="op">&gt;=</span> <span class="fl">1</span> <span class="op">+</span> x</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<pre><code>true</code></pre>
</div>
</div>
<p>Now, lets investigate that for any distinct real numbers, <span class="math inline">\(a\)</span> and <span class="math inline">\(b\)</span>, that</p>
<p><span class="math display">\[
\frac{e^b - e^a}{b - a} &gt; e^{(a+b)/2}
\]</span></p>
<p>For this, we use <code>rand(2)</code> to generate two random numbers in <span class="math inline">\([0,1)\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="12">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>a, b <span class="op">=</span> <span class="fu">rand</span>(<span class="fl">2</span>)</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>(<span class="fu">exp</span>(b) <span class="op">-</span> <span class="fu">exp</span>(a)) <span class="op">/</span> (b<span class="op">-</span>a) <span class="op">&gt;</span> <span class="fu">exp</span>((a<span class="op">+</span>b)<span class="op">/</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<pre><code>true</code></pre>
</div>
</div>
<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, lets investigate the fact that the harmonic mean, <span class="math inline">\(2/(1/a + 1/b)\)</span> is less than or equal to the geometric mean, <span class="math inline">\(\sqrt{ab}\)</span>, which is less than or equal to the quadratic mean, <span class="math inline">\(\sqrt{a^2 + b^2}/\sqrt{2}\)</span>, using two randomly chosen values:</p>
<div class="cell" data-hold="true" data-execution_count="13">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>a, b <span class="op">=</span> <span class="fu">rand</span>(<span class="fl">2</span>)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>h <span class="op">=</span> <span class="fl">2</span> <span class="op">/</span> (<span class="fl">1</span><span class="op">/</span>a <span class="op">+</span> <span class="fl">1</span><span class="op">/</span>b)</span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a>g <span class="op">=</span> (a <span class="op">*</span> b) <span class="op">^</span> (<span class="fl">1</span> <span class="op">/</span> <span class="fl">2</span>)</span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>q <span class="op">=</span> <span class="fu">sqrt</span>((a<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">^</span><span class="fl">2</span>) <span class="op">/</span> <span class="fl">2</span>)</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>h <span class="op">&lt;=</span> g, g <span class="op">&lt;=</span> q</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="14">
<pre><code>(true, true)</code></pre>
</div>
</div>
</section>
</section>
<section id="chaining-combining-expressions-absolute-values" class="level2" data-number="4.3">
<h2 data-number="4.3" class="anchored" data-anchor-id="chaining-combining-expressions-absolute-values"><span class="header-section-number">4.3</span> Chaining, combining expressions: absolute values</h2>
<p>The absolute value notation can be defined through cases:</p>
<p><span class="math display">\[
\lvert x\rvert = \begin{cases}
x &amp; x \geq 0\\
-x &amp; \text{otherwise}.
\end{cases}
\]</span></p>
<p>The interpretation of <span class="math inline">\(\lvert x\rvert\)</span>, as the distance on the number line of <span class="math inline">\(x\)</span> from <span class="math inline">\(0\)</span>, means that many relationships are naturally expressed in terms of absolute values. For example, a simple shift: <span class="math inline">\(\lvert x -c\rvert\)</span> is related to the distance <span class="math inline">\(x\)</span> is from the number <span class="math inline">\(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 inline">\(\lvert x - 5\rvert &lt; 7\)</span> has solutions which are all values of <span class="math inline">\(x\)</span> within <span class="math inline">\(7\)</span> units of <span class="math inline">\(5\)</span>. This would be the values <span class="math inline">\(-2&lt; x &lt; 12\)</span>. If this isnt immediately intuited, then formally <span class="math inline">\(\lvert x - 5\rvert &lt;7\)</span> is a compact representation of a chain of inequalities: <span class="math inline">\(-7 &lt; x-5 &lt; 7\)</span>. (Which is really two combined inequalities: <span class="math inline">\(-7 &lt; x-5\)</span> <em>and</em> <span class="math inline">\(x-5 &lt; 7\)</span>.) We can “add” <span class="math inline">\(5\)</span> to each side to get <span class="math inline">\(-2 &lt; x &lt; 12\)</span>, using the fact that adding by a finite number does not change the inequality sign.</p>
<p>Julias precedence for logical expressions, allows such statements to mirror the mathematical notation:</p>
<div class="cell" data-execution_count="14">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="fl">18</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a><span class="fu">abs</span>(x <span class="op">-</span> <span class="fl">5</span>) <span class="op">&lt;</span> <span class="fl">7</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>false</code></pre>
</div>
</div>
<p>This is to be expected, but we could also have written:</p>
<div class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="op">-</span><span class="fl">7</span> <span class="op">&lt;</span> x <span class="op">-</span> <span class="fl">5</span> <span class="op">&lt;</span> <span class="fl">7</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="16">
<pre><code>false</code></pre>
</div>
</div>
<p>Read aloud this would be “minus <span class="math inline">\(7\)</span> is less than <span class="math inline">\(x\)</span> minus <span class="math inline">\(5\)</span> <strong>and</strong> <span class="math inline">\(x\)</span> minus <span class="math inline">\(5\)</span> is less than <span class="math inline">\(7\)</span>”.</p>
<p>The “and” equations can be combined as above with a natural notation. However, an equation like <span class="math inline">\(\lvert x - 5\rvert &gt; 7\)</span> would emphasize an <strong>or</strong> and be “<span class="math inline">\(x\)</span> minus <span class="math inline">\(5\)</span> less than minus <span class="math inline">\(7\)</span> <strong>or</strong> <span class="math inline">\(x\)</span> minus <span class="math inline">\(5\)</span> greater than <span class="math inline">\(7\)</span>”. Expressing this requires some new notation.</p>
<p>The <em>boolean shortcut operators</em> <code>&amp;&amp;</code> and <code>||</code> implement “and” and “or.” (There are also <em>bitwise</em> boolean operators <code>&amp;</code> and <code>|</code>, but we only describe the former.)</p>
<p>Thus we could write <span class="math inline">\(-7 &lt; x-5 &lt; 7\)</span> as</p>
<div class="cell" data-execution_count="16">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>(<span class="op">-</span><span class="fl">7</span> <span class="op">&lt;</span> x <span class="op">-</span> <span class="fl">5</span>) <span class="op">&amp;&amp;</span> (x <span class="op">-</span> <span class="fl">5</span> <span class="op">&lt;</span> <span class="fl">7</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="17">
<pre><code>false</code></pre>
</div>
</div>
<p>and could write <span class="math inline">\(\lvert x-5\rvert &gt; 7\)</span> as</p>
<div class="cell" data-execution_count="17">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>(x <span class="op">-</span> <span class="fl">5</span> <span class="op">&lt;</span> <span class="op">-</span><span class="fl">7</span>) <span class="op">||</span> (x <span class="op">-</span> <span class="fl">5</span> <span class="op">&gt;</span> <span class="fl">7</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="18">
<pre><code>true</code></pre>
</div>
</div>
<p>(The first expression is false for <span class="math inline">\(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>
<section id="example" class="level5">
<h5 class="anchored" data-anchor-id="example">Example</h5>
<p>One of <a href="http://en.wikipedia.org/wiki/De_Morgan%27s_laws">DeMorgans 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 <span class="math inline">\(1\)</span> of the <span class="math inline">\(4\)</span> possible cases for the pair <code>A</code>, <code>B</code> to take:</p>
<div class="cell" data-execution_count="18">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a>A,B <span class="op">=</span> <span class="cn">true</span>, <span class="cn">false</span> <span class="co">## also true, true; false, true; and false, false</span></span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a>!(A <span class="op">&amp;&amp;</span> B) <span class="op">==</span> !A <span class="op">||</span> !B</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="19">
<pre><code>true</code></pre>
</div>
</div>
</section>
</section>
<section id="precedence" class="level2" data-number="4.4">
<h2 data-number="4.4" class="anchored" data-anchor-id="precedence"><span class="header-section-number">4.4</span> 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>
<div class="cell" data-execution_count="19">
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>(x <span class="op">-</span> <span class="fl">5</span> <span class="op">&lt;</span> <span class="op">-</span><span class="fl">7</span>) <span class="op">||</span> (x <span class="op">-</span> <span class="fl">5</span> <span class="op">&gt;</span> <span class="fl">7</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="20">
<pre><code>true</code></pre>
</div>
</div>
<p>To represent <span class="math inline">\(\lvert x-5\rvert &gt; 7\)</span>. Were the parentheses necessary? Lets just check.</p>
<div class="cell" data-execution_count="20">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">-</span> <span class="fl">5</span> <span class="op">&lt;</span> <span class="op">-</span><span class="fl">7</span> <span class="op">||</span> x <span class="op">-</span> <span class="fl">5</span> <span class="op">&gt;</span> <span class="fl">7</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="21">
<pre><code>true</code></pre>
</div>
</div>
<p>So no, they were not in this case.</p>
<p>An operator (such as <code>&lt;</code>, <code>&gt;</code>, <code>||</code> above) has an associated associativity and precedence. The associativity is whether an expression like <code>a - b - c</code> is <code>(a-b) - c</code> or <code>a - (b-c)</code>. The former being left associative, the latter right. Of issue here is <em>precedence</em>, as in with two or more different operations, which happens first, second, <span class="math inline">\(\dots\)</span>.</p>
<p>The table in the manual on <a href="https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity">operator precedence and associativity</a> shows that for these operations “control flow” (the <code>&amp;&amp;</code> above) is lower than “comparisons” (the <code>&lt;</code>, <code>&gt;</code>), which are lower than “Addition” (the <code>-</code> above). So the expression without parentheses would be equivalent to:</p>
<div class="cell" data-execution_count="21">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a>((x<span class="op">-</span><span class="fl">5</span>) <span class="op">&lt;</span> <span class="op">-</span><span class="fl">7</span>) <span class="op">&amp;&amp;</span> ((x<span class="op">-</span><span class="fl">5</span>) <span class="op">&gt;</span> <span class="fl">7</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="22">
<pre><code>false</code></pre>
</div>
</div>
<p>(This is different than the precedence of the bitwise boolean operators, which have <code>&amp;</code> with “Multiplication” and <code>|</code> with “Addition”, so <code>x-5 &lt; 7 | x - 5 &gt; 7</code> would need parentheses.)</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>
</section>
<section id="arithmetic-with" class="level2" data-number="4.5">
<h2 data-number="4.5" class="anchored" data-anchor-id="arithmetic-with"><span class="header-section-number">4.5</span> Arithmetic with</h2>
<p>For convenience, basic arithmetic can be performed with Boolean values, <code>false</code> becomes <span class="math inline">\(0\)</span> and true <span class="math inline">\(1\)</span>. For example, both these expressions make sense:</p>
<div class="cell" data-execution_count="22">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="cn">true</span> <span class="op">+</span> <span class="cn">true</span> <span class="op">+</span> <span class="cn">false</span>, <span class="cn">false</span> <span class="op">*</span> <span class="fl">1000</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="23">
<pre><code>(2, 0)</code></pre>
</div>
</div>
<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 inline">\(0\)</span> otherwise:</p>
<div class="cell" data-execution_count="23">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a>(x <span class="op">&gt;</span> <span class="fl">0</span>) <span class="op">*</span> x</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="24">
<pre><code>18</code></pre>
</div>
</div>
<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 inline">\(-10\)</span> and <span class="math inline">\(10\)</span> and otherwise <span class="math inline">\(-10\)</span> or <span class="math inline">\(10\)</span> depending on whether <span class="math inline">\(x\)</span> is negative or positive.</p>
<div class="cell" data-execution_count="24">
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a>(x <span class="op">&lt;</span> <span class="op">-</span><span class="fl">10</span>)<span class="fu">*</span>(<span class="op">-</span><span class="fl">10</span>) <span class="op">+</span> (x <span class="op">&gt;=</span> <span class="op">-</span><span class="fl">10</span>)<span class="fu">*</span>(x <span class="op">&lt;</span> <span class="fl">10</span>) <span class="op">*</span> x <span class="op">+</span> (x<span class="op">&gt;=</span><span class="fl">10</span>)<span class="op">*</span><span class="fl">10</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="25">
<pre><code>10</code></pre>
</div>
</div>
<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>
</section>
<section id="questions" class="level2" data-number="4.6">
<h2 data-number="4.6" class="anchored" data-anchor-id="questions"><span class="header-section-number">4.6</span> Questions</h2>
<section id="question" class="level6">
<h6 class="anchored" data-anchor-id="question">Question</h6>
<p>Is <code>e^pi</code> or <code>pi^e</code> greater?</p>
<div class="cell" data-hold="true" data-execution_count="25">
<div class="cell-output cell-output-display" data-execution_count="26">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12435863512260717783" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12435863512260717783">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12435863512260717783_1">
<input class="form-check-input" type="radio" name="radio_12435863512260717783" id="radio_12435863512260717783_1" value="1">
<span class="label-body px-1">
<code>e^pi</code> is less than <code>pi^e</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12435863512260717783_2">
<input class="form-check-input" type="radio" name="radio_12435863512260717783" id="radio_12435863512260717783_2" value="2">
<span class="label-body px-1">
<code>e^pi</code> is greater than <code>pi^e</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12435863512260717783_3">
<input class="form-check-input" type="radio" name="radio_12435863512260717783" id="radio_12435863512260717783_3" value="3">
<span class="label-body px-1">
<code>e^pi</code> is equal to <code>pi^e</code>
</span>
</label>
</div>
</div>
</div>
<div id="12435863512260717783_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12435863512260717783"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('12435863512260717783_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12435863512260717783")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_12435863512260717783")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-1" class="level6">
<h6 class="anchored" data-anchor-id="question-1">Question</h6>
<p>Is <span class="math inline">\(\sin(1000)\)</span> positive?</p>
<div class="cell" data-hold="true" data-execution_count="26">
<div class="cell-output cell-output-display" data-execution_count="27">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="15126470855430621859" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_15126470855430621859">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_15126470855430621859_1">
<input class="form-check-input" type="radio" name="radio_15126470855430621859" id="radio_15126470855430621859_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_15126470855430621859_2">
<input class="form-check-input" type="radio" name="radio_15126470855430621859" id="radio_15126470855430621859_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="15126470855430621859_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_15126470855430621859"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('15126470855430621859_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_15126470855430621859")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_15126470855430621859")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-2" class="level6">
<h6 class="anchored" data-anchor-id="question-2">Question</h6>
<p>Suppose you know <span class="math inline">\(0 &lt; a &lt; b\)</span>. What can you say about the relationship between <span class="math inline">\(-1/a\)</span> and <span class="math inline">\(-1/b\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="27">
<div class="cell-output cell-output-display" data-execution_count="28">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="643755062490906878" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_643755062490906878">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_643755062490906878_1">
<input class="form-check-input" type="radio" name="radio_643755062490906878" id="radio_643755062490906878_1" value="1">
<span class="label-body px-1">
\(-1/a &gt; -1/b\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_643755062490906878_2">
<input class="form-check-input" type="radio" name="radio_643755062490906878" id="radio_643755062490906878_2" value="2">
<span class="label-body px-1">
\(-1/a \geq -1/b\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_643755062490906878_3">
<input class="form-check-input" type="radio" name="radio_643755062490906878" id="radio_643755062490906878_3" value="3">
<span class="label-body px-1">
\(-1/a &lt; -1/b\)
</span>
</label>
</div>
</div>
</div>
<div id="643755062490906878_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_643755062490906878"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('643755062490906878_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_643755062490906878")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_643755062490906878")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-3" class="level6">
<h6 class="anchored" data-anchor-id="question-3">Question</h6>
<p>Suppose you know <span class="math inline">\(a &lt; 0 &lt; b\)</span>, is it true that <span class="math inline">\(1/a &gt; 1/b\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="28">
<div class="cell-output cell-output-display" data-execution_count="29">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="11561031098290764792" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_11561031098290764792">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_11561031098290764792_1">
<input class="form-check-input" type="radio" name="radio_11561031098290764792" id="radio_11561031098290764792_1" value="1">
<span class="label-body px-1">
Yes, it is always true.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11561031098290764792_2">
<input class="form-check-input" type="radio" name="radio_11561031098290764792" id="radio_11561031098290764792_2" value="2">
<span class="label-body px-1">
It is never true, as \(1/a\) is negative and \(1/b\) is positive
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_11561031098290764792_3">
<input class="form-check-input" type="radio" name="radio_11561031098290764792" id="radio_11561031098290764792_3" value="3">
<span class="label-body px-1">
It can sometimes be true, though not always.
</span>
</label>
</div>
</div>
</div>
<div id="11561031098290764792_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_11561031098290764792"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('11561031098290764792_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_11561031098290764792")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_11561031098290764792")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-4" class="level6">
<h6 class="anchored" data-anchor-id="question-4">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 functions 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>
<div class="cell" data-execution_count="29">
<div class="sourceCode cell-code" id="cb44"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb44-1"><a href="#cb44-1" aria-hidden="true" tabindex="-1"></a><span class="fu">airyai</span>(<span class="fl">0</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="30">
<pre><code>0.3550280538878172</code></pre>
</div>
</div>
<p>It is known that this function is always positive for <span class="math inline">\(x &gt; 0\)</span>, though not so for negative values of <span class="math inline">\(x\)</span>. Which of these indicates the first negative value : <code>airyai(-1) &lt;0</code>, <code>airyai(-2) &lt; 0</code>, …, or <code>airyai(-5) &lt; 0</code>?</p>
<div class="cell" data-hold="true" data-execution_count="30">
<div class="cell-output cell-output-display" data-execution_count="31">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="8682726149193280043" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_8682726149193280043">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_8682726149193280043_1">
<input class="form-check-input" type="radio" name="radio_8682726149193280043" id="radio_8682726149193280043_1" value="1">
<span class="label-body px-1">
<code>airyai(-1) &lt; 0</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8682726149193280043_2">
<input class="form-check-input" type="radio" name="radio_8682726149193280043" id="radio_8682726149193280043_2" value="2">
<span class="label-body px-1">
<code>airyai(-2) &lt; 0</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8682726149193280043_3">
<input class="form-check-input" type="radio" name="radio_8682726149193280043" id="radio_8682726149193280043_3" value="3">
<span class="label-body px-1">
<code>airyai(-3) &lt; 0</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8682726149193280043_4">
<input class="form-check-input" type="radio" name="radio_8682726149193280043" id="radio_8682726149193280043_4" value="4">
<span class="label-body px-1">
<code>airyai(-4) &lt; 0</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_8682726149193280043_5">
<input class="form-check-input" type="radio" name="radio_8682726149193280043" id="radio_8682726149193280043_5" value="5">
<span class="label-body px-1">
<code>airyai(-5) &lt; 0</code>
</span>
</label>
</div>
</div>
</div>
<div id="8682726149193280043_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_8682726149193280043"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('8682726149193280043_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_8682726149193280043")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_8682726149193280043")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-5" class="level6">
<h6 class="anchored" data-anchor-id="question-5">Question</h6>
<p>By trying three different values of <span class="math inline">\(x &gt; 0\)</span> which of these could possibly be always true:</p>
<div class="cell" data-hold="true" data-execution_count="31">
<div class="cell-output cell-output-display" data-execution_count="32">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="6418524494982079587" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_6418524494982079587">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_6418524494982079587_1">
<input class="form-check-input" type="radio" name="radio_6418524494982079587" id="radio_6418524494982079587_1" value="1">
<span class="label-body px-1">
<code>x^x &lt;= (1/e)^(1/e)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6418524494982079587_2">
<input class="form-check-input" type="radio" name="radio_6418524494982079587" id="radio_6418524494982079587_2" value="2">
<span class="label-body px-1">
<code>x^x &gt;= (1/e)^(1/e)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_6418524494982079587_3">
<input class="form-check-input" type="radio" name="radio_6418524494982079587" id="radio_6418524494982079587_3" value="3">
<span class="label-body px-1">
<code>x^x == (1/e)^(1/e)</code>
</span>
</label>
</div>
</div>
</div>
<div id="6418524494982079587_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_6418524494982079587"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('6418524494982079587_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_6418524494982079587")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_6418524494982079587")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-6" class="level6">
<h6 class="anchored" data-anchor-id="question-6">Question</h6>
<p>Student logic says <span class="math inline">\((x+y)^p = x^p + y^p\)</span>. Of course, this isnt correct for all <span class="math inline">\(p\)</span> and <span class="math inline">\(x\)</span>. By trying a few points, which is true when <span class="math inline">\(x,y &gt; 0\)</span> and <span class="math inline">\(0 &lt; p &lt; 1\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="32">
<div class="cell-output cell-output-display" data-execution_count="33">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="18410968165218510230" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_18410968165218510230">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_18410968165218510230_1">
<input class="form-check-input" type="radio" name="radio_18410968165218510230" id="radio_18410968165218510230_1" value="1">
<span class="label-body px-1">
<code>(x+y)^p &gt; x^p + y^p</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18410968165218510230_2">
<input class="form-check-input" type="radio" name="radio_18410968165218510230" id="radio_18410968165218510230_2" value="2">
<span class="label-body px-1">
<code>(x+y)^p &lt; x^p + y^p</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18410968165218510230_3">
<input class="form-check-input" type="radio" name="radio_18410968165218510230" id="radio_18410968165218510230_3" value="3">
<span class="label-body px-1">
<code>(x+y)^p == x^p + y^p</code>
</span>
</label>
</div>
</div>
</div>
<div id="18410968165218510230_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_18410968165218510230"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('18410968165218510230_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_18410968165218510230")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_18410968165218510230")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-7" class="level6">
<h6 class="anchored" data-anchor-id="question-7">Question</h6>
<p>According to Wikipedia, one of the following inequalities is always true for <span class="math inline">\(a, b &gt; 0\)</span> (as proved by I. Ilani in JSTOR, AMM, Vol.97, No.1, 1990). Which one?</p>
<div class="cell" data-hold="true" data-execution_count="33">
<div class="cell-output cell-output-display" data-execution_count="34">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="18073418486523180786" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_18073418486523180786">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_18073418486523180786_1">
<input class="form-check-input" type="radio" name="radio_18073418486523180786" id="radio_18073418486523180786_1" value="1">
<span class="label-body px-1">
<code>a^b + b^a &lt;= 1</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18073418486523180786_2">
<input class="form-check-input" type="radio" name="radio_18073418486523180786" id="radio_18073418486523180786_2" value="2">
<span class="label-body px-1">
<code>a^a + b^b &lt;= a^b + b^a</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18073418486523180786_3">
<input class="form-check-input" type="radio" name="radio_18073418486523180786" id="radio_18073418486523180786_3" value="3">
<span class="label-body px-1">
<code>a^a + b^b &gt;= a^b + b^a</code>
</span>
</label>
</div>
</div>
</div>
<div id="18073418486523180786_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_18073418486523180786"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('18073418486523180786_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_18073418486523180786")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_18073418486523180786")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-8" class="level6">
<h6 class="anchored" data-anchor-id="question-8">Question</h6>
<p>Is <span class="math inline">\(3\)</span> in the set <span class="math inline">\(\lvert x - 2\rvert &lt; 1/2\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="34">
<div class="cell-output cell-output-display" data-execution_count="35">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12528338007097546375" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12528338007097546375">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12528338007097546375_1">
<input class="form-check-input" type="radio" name="radio_12528338007097546375" id="radio_12528338007097546375_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12528338007097546375_2">
<input class="form-check-input" type="radio" name="radio_12528338007097546375" id="radio_12528338007097546375_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="12528338007097546375_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12528338007097546375"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('12528338007097546375_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12528338007097546375")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_12528338007097546375")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-9" class="level6">
<h6 class="anchored" data-anchor-id="question-9">Question</h6>
<p>Which of the following is equivalent to <span class="math inline">\(\lvert x - a\rvert &gt; b\)</span>:</p>
<div class="cell" data-hold="true" data-execution_count="35">
<div class="cell-output cell-output-display" data-execution_count="36">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="18360175618415997205" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_18360175618415997205">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_18360175618415997205_1">
<input class="form-check-input" type="radio" name="radio_18360175618415997205" id="radio_18360175618415997205_1" value="1">
<span class="label-body px-1">
\(-b &lt; x - a &lt; b\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18360175618415997205_2">
<input class="form-check-input" type="radio" name="radio_18360175618415997205" id="radio_18360175618415997205_2" value="2">
<span class="label-body px-1">
\(-b &lt; x-a \text{ and } x - a &lt; b\)
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_18360175618415997205_3">
<input class="form-check-input" type="radio" name="radio_18360175618415997205" id="radio_18360175618415997205_3" value="3">
<span class="label-body px-1">
\(x - a &lt; -b \text{ or } x - a &gt; b\)
</span>
</label>
</div>
</div>
</div>
<div id="18360175618415997205_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_18360175618415997205"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 3;
var msgBox = document.getElementById('18360175618415997205_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_18360175618415997205")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_18360175618415997205")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-10" class="level6">
<h6 class="anchored" data-anchor-id="question-10">Question</h6>
<p>If <span class="math inline">\(\lvert x - \pi\rvert &lt; 1/10\)</span> is <span class="math inline">\(\lvert \sin(x) - \sin(\pi)\rvert &lt; 1/10\)</span>?</p>
<p>Guess an answer based on a few runs of</p>
<div class="sourceCode cell-code" id="cb46"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb46-1"><a href="#cb46-1" aria-hidden="true" tabindex="-1"></a>x <span class="op">=</span> <span class="cn">pi</span> <span class="op">+</span> <span class="fl">1</span><span class="op">/</span><span class="fl">10</span> <span class="op">*</span> (<span class="fl">2</span><span class="fu">rand</span>()<span class="op">-</span><span class="fl">1</span>)</span>
<span id="cb46-2"><a href="#cb46-2" aria-hidden="true" tabindex="-1"></a><span class="fu">abs</span>(x <span class="op">-</span> <span class="cn">pi</span>) <span class="op">&lt;</span> <span class="fl">1</span><span class="op">/</span><span class="fl">10</span>, <span class="fu">abs</span>(<span class="fu">sin</span>(x) <span class="op">-</span> <span class="fu">sin</span>(<span class="cn">pi</span>)) <span class="op">&lt;</span> <span class="fl">1</span><span class="op">/</span><span class="fl">10</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell" data-hold="true" data-execution_count="37">
<div class="cell-output cell-output-display" data-execution_count="37">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4048552582332687781" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4048552582332687781">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4048552582332687781_1">
<input class="form-check-input" type="radio" name="radio_4048552582332687781" id="radio_4048552582332687781_1" value="1">
<span class="label-body px-1">
true
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4048552582332687781_2">
<input class="form-check-input" type="radio" name="radio_4048552582332687781" id="radio_4048552582332687781_2" value="2">
<span class="label-body px-1">
false
</span>
</label>
</div>
</div>
</div>
<div id="4048552582332687781_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4048552582332687781"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('4048552582332687781_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4048552582332687781")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_4048552582332687781")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-11" class="level6">
<h6 class="anchored" data-anchor-id="question-11">Question</h6>
<p>Does <code>12</code> satisfy <span class="math inline">\(\lvert x - 3\rvert + \lvert x-9\rvert &gt; 12\)</span>?</p>
<div class="cell" data-hold="true" data-execution_count="38">
<div class="cell-output cell-output-display" data-execution_count="38">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="5241220318146713321" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_5241220318146713321">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_5241220318146713321_1">
<input class="form-check-input" type="radio" name="radio_5241220318146713321" id="radio_5241220318146713321_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_5241220318146713321_2">
<input class="form-check-input" type="radio" name="radio_5241220318146713321" id="radio_5241220318146713321_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="5241220318146713321_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_5241220318146713321"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('5241220318146713321_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_5241220318146713321")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_5241220318146713321")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-12" class="level6">
<h6 class="anchored" data-anchor-id="question-12">Question</h6>
<p>Which of these will show DeMorgans law holds when both values are <code>false</code>:</p>
<div class="cell" data-hold="true" data-execution_count="39">
<div class="cell-output cell-output-display" data-execution_count="39">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="1229196818275069853" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_1229196818275069853">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_1229196818275069853_1">
<input class="form-check-input" type="radio" name="radio_1229196818275069853" id="radio_1229196818275069853_1" value="1">
<span class="label-body px-1">
<code>!(false &amp;&amp; false) == (false || false)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1229196818275069853_2">
<input class="form-check-input" type="radio" name="radio_1229196818275069853" id="radio_1229196818275069853_2" value="2">
<span class="label-body px-1">
<code>!(false &amp;&amp; false) == (!false || !false)</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_1229196818275069853_3">
<input class="form-check-input" type="radio" name="radio_1229196818275069853" id="radio_1229196818275069853_3" value="3">
<span class="label-body px-1">
<code>!(false &amp;&amp; false) == (!false &amp;&amp; !false)</code>
</span>
</label>
</div>
</div>
</div>
<div id="1229196818275069853_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_1229196818275069853"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('1229196818275069853_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_1229196818275069853")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_1229196818275069853")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-13" class="level6">
<h6 class="anchored" data-anchor-id="question-13">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>
<div class="cell" data-hold="true" data-execution_count="40">
<div class="cell-output cell-output-display" data-execution_count="40">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="4352975797473589501" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_4352975797473589501">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_4352975797473589501_1">
<input class="form-check-input" type="radio" name="radio_4352975797473589501" id="radio_4352975797473589501_1" value="1">
<span class="label-body px-1">
<code>NaN &lt; 3.0</code> and <code>3.0 &lt;= NaN</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_4352975797473589501_2">
<input class="form-check-input" type="radio" name="radio_4352975797473589501" id="radio_4352975797473589501_2" value="2">
<span class="label-body px-1">
<code>Inf &lt; 3.0</code> and <code>3.0 &lt;= Inf</code>
</span>
</label>
</div>
</div>
</div>
<div id="4352975797473589501_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_4352975797473589501"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('4352975797473589501_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_4352975797473589501")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_4352975797473589501")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-14" class="level6">
<h6 class="anchored" data-anchor-id="question-14">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.0</code> (as a floating point number and not <code>-0</code>, an integer). Here are 4 facts that seem reasonable:</p>
<ul>
<li>Positive zero is equal but not greater than negative zero.</li>
<li><code>Inf</code> is equal to itself and greater than everything else except <code>NaN</code>.</li>
<li><code>-Inf</code> is equal to itself and less then everything else except <code>NaN</code>.</li>
<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>
<div class="cell" data-hold="true" data-execution_count="41">
<div class="cell-output cell-output-display" data-execution_count="41">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12689194611054504382" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12689194611054504382">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12689194611054504382_1">
<input class="form-check-input" type="radio" name="radio_12689194611054504382" id="radio_12689194611054504382_1" value="1">
<span class="label-body px-1">
Yes
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12689194611054504382_2">
<input class="form-check-input" type="radio" name="radio_12689194611054504382" id="radio_12689194611054504382_2" value="2">
<span class="label-body px-1">
No
</span>
</label>
</div>
</div>
</div>
<div id="12689194611054504382_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12689194611054504382"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('12689194611054504382_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12689194611054504382")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_12689194611054504382")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
<section id="question-15" class="level6">
<h6 class="anchored" data-anchor-id="question-15">Question</h6>
<p>The <code>NaN</code> value is meant to signal an error in computation. <code>Julia</code> has value to indicate some data is missing or unavailable. This is <code>missing</code>. For <code>missing</code> values we have these computations:</p>
<div class="cell" data-execution_count="42">
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a><span class="cn">true</span> <span class="op">&amp;&amp;</span> <span class="cn">missing</span>, <span class="cn">true</span> <span class="op">||</span> <span class="cn">missing</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display" data-execution_count="42">
<pre><code>(missing, true)</code></pre>
</div>
</div>
<p>We see the value of <code>true || missing</code> is <code>true</code>. Why?</p>
<div class="cell" data-hold="true" data-execution_count="43">
<div class="cell-output cell-output-display" data-execution_count="43">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="12647630933029730517" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_12647630933029730517">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_12647630933029730517_1">
<input class="form-check-input" type="radio" name="radio_12647630933029730517" id="radio_12647630933029730517_1" value="1">
<span class="label-body px-1">
Since the second value is "<code>missing</code>", only the first is used. So <code>false || missing</code> would also be <code>false</code>
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_12647630933029730517_2">
<input class="form-check-input" type="radio" name="radio_12647630933029730517" id="radio_12647630933029730517_2" value="2">
<span class="label-body px-1">
In the manual we can read that "In the expression <code>a || b</code>, the subexpression <code>b</code> is only evaluated if <code>a</code> evaluates to false." In this case <code>a</code> is <code>true</code> and so <code>a</code> is returned.
</span>
</label>
</div>
</div>
</div>
<div id="12647630933029730517_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_12647630933029730517"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 2;
var msgBox = document.getElementById('12647630933029730517_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_12647630933029730517")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_12647630933029730517")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
<p>The value for <code>true &amp;&amp; missing</code> is <code>missing</code>, not a boolean value. What happens?</p>
<div class="cell" data-hold="true" data-execution_count="44">
<div class="cell-output cell-output-display" data-execution_count="44">
<form class="mx-2 my-3 mw-100" name="WeaveQuestion" data-id="14167251986912622960" data-controltype="">
<div class="form-group ">
<div class="controls">
<div class="form" id="controls_14167251986912622960">
<div style="padding-top: 5px">
<div class="form-check">
<label class="form-check-label" for="radio_14167251986912622960_1">
<input class="form-check-input" type="radio" name="radio_14167251986912622960" id="radio_14167251986912622960_1" value="1">
<span class="label-body px-1">
In the manual we can read that "In the expression <code>a &amp;&amp; b</code>, the subexpression <code>b</code> is only evaluated if <code>a</code> evaluates to true." In this case, <code>a</code> is <code>false</code> so <code>b</code> is evaluated and returned. As <code>b</code> is just <code>missing</code> that is the return value.
</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" for="radio_14167251986912622960_2">
<input class="form-check-input" type="radio" name="radio_14167251986912622960" id="radio_14167251986912622960_2" value="2">
<span class="label-body px-1">
Since the second value is "<code>missing</code>" all such answers would be missing.
</span>
</label>
</div>
</div>
</div>
<div id="14167251986912622960_message" style="padding-bottom: 15px"></div>
</div>
</div>
</form>
<script text="text/javascript">
document.querySelectorAll('input[name="radio_14167251986912622960"]').forEach(function(rb) {
rb.addEventListener("change", function() {
var correct = rb.value == 1;
var msgBox = document.getElementById('14167251986912622960_message');
if(correct) {
msgBox.innerHTML = "<div class='pluto-output admonition note alert alert-success'><span> 👍&nbsp; Correct </span></div>";
var explanation = document.getElementById("explanation_14167251986912622960")
if (explanation != null) {
explanation.style.display = "none";
}
} else {
msgBox.innerHTML = "<div class='pluto-output admonition alert alert-danger'><span>👎&nbsp; Incorrect </span></div>";
var explanation = document.getElementById("explanation_14167251986912622960")
if (explanation != null) {
explanation.style.display = "block";
}
}
})});
</script>
</div>
</div>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
setTimeout(function() {
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
let href = ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
tippyHover(ref, function() {
var popup = window.document.createElement('div');
cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// target, if specified
link.setAttribute("target", "_blank");
}
}
});
</script>
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="../precalc/numbers_types.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Number systems</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../precalc/vectors.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Vectors</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav>
</div> <!-- /content -->
<footer class="footer">
<div class="nav-footer">
<div class="nav-footer-center">Copyright 2022, John Verzani</div>
</div>
</footer>
</body></html>