CDSLab Recipes - A repository for all sorts of problems with solutions Jekyll 2021-09-18T14:33:50-05:00 https://www.cdslab.org/recipes/ Amir Shahmoradi https://www.cdslab.org/recipes/ shahmoradi@utexas.edu <![CDATA[Visualizing the average precipitation among the US states]]> https://www.cdslab.org/recipes/programming/visualization-avg-precipitation-choropleth/visualization-avg-precipitation-choropleth 2021-09-19T00:00:00-05:00 2019-07-04T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>Consider the following <a href="precipitation.csv" target="_blank">dataset</a> containing the average annual precipitation in the US states between 1971-2000. Make a choropleth visualization of this precipitation data (either using the SI or the US-British units). Do not forget to add a color-bar to your visualization.</p> <p><a href="https://www.cdslab.org/recipes/programming/visualization-avg-precipitation-choropleth/visualization-avg-precipitation-choropleth">Visualizing the average precipitation among the US states</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on September 19, 2021.</p> <![CDATA[Computing the first four moments of a sample]]> https://www.cdslab.org/recipes/programming/stat-sample-mean-variance-skewness-kurtosis/stat-sample-mean-variance-skewness-kurtosis 2021-09-03T00:00:00-05:00 2021-09-07T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>Consider <a href="gamrnd.txt" target="blank">this dataset</a> comprised of $1000$ observations (tuples). Compute the first four standardized moments of this sample (mean, standard deviation, skewness, kurtosis).</p> <p><a href="https://www.cdslab.org/recipes/programming/stat-sample-mean-variance-skewness-kurtosis/stat-sample-mean-variance-skewness-kurtosis">Computing the first four moments of a sample</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on September 03, 2021.</p> <![CDATA[An experimental proof of Chebyshev's inequality]]> https://www.cdslab.org/recipes/programming/stat-sample-chebyshev-inequality/stat-sample-chebyshev-inequality 2021-09-03T00:00:00-05:00 2021-09-07T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>The Chebyshev Inequality states that no more than $1/k^2$ of an attribute values of a given sample can be $k$ or more standard deviations away from the attribute mean. Provide an experimental proof of this theorem by generating a sample of 10000 uniformly-distributed random numbers between 0 and 1 and computing the fractions of points that lie at larger distances than $[1\sigma, 1.5\sigma, 2\sigma, 2.5\sigma, 3\sigma, 3.5\sigma, 4\sigma]$ is less than or equal to $[1, 1/1.5^2, 1/2^2, 1/2.5^2, 1/3^2, 1/3.5^2, 1/4^2]$.</p> <p><a href="https://www.cdslab.org/recipes/programming/stat-sample-chebyshev-inequality/stat-sample-chebyshev-inequality">An experimental proof of Chebyshev's inequality</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on September 03, 2021.</p> <![CDATA[Computing the mean of a weighted data]]> https://www.cdslab.org/recipes/programming/stat-mean-weighted/stat-mean-weighted 2021-09-03T00:00:00-05:00 2019-07-04T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>Consider <a href="weightedDataMVN.txt" target="blank">this weighted dataset</a> comprised of $500$ observations (tuples) each of which is described by $5$ attributes. Note that the last column of data is the weight of each tuple. Compute the weighted mean of this sample.</p> <p><a href="https://www.cdslab.org/recipes/programming/stat-mean-weighted/stat-mean-weighted">Computing the mean of a weighted data</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on September 03, 2021.</p> <![CDATA[Monte Carlo approximation of the number Pi]]> https://www.cdslab.org/recipes/programming/monte-carlo-quadratic-integration-rejection-sampling/monte-carlo-quadratic-integration-rejection-sampling 2021-07-06T00:00:00-05:00 2019-07-04T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>Compute the following 10-dimensional integral via Monte Carlo Rejection sampling method,</p> $I = \int_{x_1 = 0}^{x_1 = 1} dx_1 \cdots \int_{x_{10} = 0}^{x_{10} = 1} dx_{10} \bigg(\sum_{i=1}^{i=10} ~ x_i ~ \bigg) ~,$ <p>Ensure the accuracy of your integration result is better than $0.00001$ by progressively comparing the integral with actual integration result $I = 155 / 6$.</p> <p><a href="https://www.cdslab.org/recipes/programming/monte-carlo-quadratic-integration-rejection-sampling/monte-carlo-quadratic-integration-rejection-sampling">Monte Carlo approximation of the number Pi</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on July 06, 2021.</p> <![CDATA[Monte Carlo approximation of the number Pi using a full circle]]> https://www.cdslab.org/recipes/programming/monte-carlo-approximation-of-pi-full-circle/monte-carlo-approximation-of-pi-full-circle 2021-05-03T00:00:00-05:00 2021-05-03T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>Suppose we did not know the value of $\pi$ and we wanted to estimate its value using Monte Carlo methods. One practical approach is to draw a square sides equal to $a = 2$, with its diagonal opposite corners extending from the coordinates origin $(-1,-1)$ to $(1,1)$. Now we try to simulate uniform random points from inside of this square by generating uniform random points along the $X$ and $Y$ axes, i.e., by generating two random uniform numbers (x,y) from the range $[-1,1]$.</p> <p>The generated random point $P$ has the coordinate $(x,y)$, so we can calculate its distance from the coordinate origin. Now, suppose we also draw a unit-radius ($r = 1$) inside of this square with its center at the origin $(0,0)$. The ratio of the area of this circle, $S_C$ to the area of the square enclosing it, $S_S$ is,</p> $\frac{S_C}{S_S} = \frac{\pi r^2}{a^2} = \frac{1}{4}\pi$ <p>This is because the area of the square with sides $a = 2$ is just 4. Therefore, if we can somehow measure the area of the circle $S_C$, then we can use the following equation, to get an estimate of $\pi$,</p> $\pi = 4S_C$ <p>To obtain, $S_C$, we are going to throw random points in the square, just as described above, and then find the fraction of points, $f=n_C/n_{\rm total}$, that fall inside this circle. This fraction is related to the area of the circle and square by the following equation,</p> $f=\frac{n_C}{n_{\rm total}} = \frac{S_C}{S_S}$ <p>Therefore, one can obtain an estimate of $\pi$ using this fraction,</p> $\pi \approx 4\frac{n_C}{n_{\rm total}}$ <p>Now, write a script that takes in the number of points to be simulated, and then calculates an approximate value for $\pi$ based on the Monte Carlo algorithm described above. Write a second function that plot the estimate of $\pi$ versus the number of points stimulated, like the following,</p> <figure> <img src="approximatePI.png" /> </figure> <p><a href="https://www.cdslab.org/recipes/programming/monte-carlo-approximation-of-pi-full-circle/monte-carlo-approximation-of-pi-full-circle">Monte Carlo approximation of the number Pi using a full circle</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on May 03, 2021.</p> <![CDATA[Monte Carlo approximation of the area of heart]]> https://www.cdslab.org/recipes/programming/monte-carlo-approximation-of-heart-area/monte-carlo-approximation-of-heart-area 2021-05-03T00:00:00-05:00 2021-05-03T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>A popular mathematical equation for 2D heart is the following,</p> $f(x,y) = (x^2 + y^2 - 1)^3 - x^2 y^3 = 0$ <p>Any $(x,y)$ values that result in $f(x,y) &lt; 0$ represent the coordinates of a point that falls inside the heart shape. Write a script that generates a heart shape via a set of random points uniformly distributed inside the heart shape. Estimate the area of the heart by drawing an appropriate box around the heart and sampling points randomly uniformly from this box and counting those that fall inside the heart. Here is a plot of the heart,</p> <figure> <img src="heart.png" /> </figure> <p><a href="https://www.cdslab.org/recipes/programming/monte-carlo-approximation-of-heart-area/monte-carlo-approximation-of-heart-area">Monte Carlo approximation of the area of heart</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on May 03, 2021.</p> <![CDATA[Parsing data from the World Wide Web]]> https://www.cdslab.org/recipes/programming/parsing-data-from-web/parsing-data-from-web 2021-04-12T00:00:00-05:00 2021-04-12T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Consider the following web-page address <a href="https://cdslaborg.github.io/DataRepos_SwiftBat/index.html" target="_blank">https://cdslaborg.github.io/DataRepos_SwiftBat/index.html</a>. This is a data table in HTML language containing data from the <a href="https://www.nasa.gov/mission_pages/swift/main" target="_blank">NASA Swift satellite</a>. Each row in this table represents information about a <a href="https://en.wikipedia.org/wiki/Gamma-ray_burst" target="_blank">Gamma-Ray Burst (GRB)</a> detection that Swift has made in the past years.</p> <p>Each event is labeled by an ID that appears in the first column of the table named <code>GRB (Trig#)</code>. Write a code that (downloads) and reads this HTML page from the web, then extracts the IDs of GRB events from the first column (IDs are the numbers that appear in parentheses in the first column). Then, writes the extracted IDs to an external output file on your system with the name <code>nasa.swift.grb.ids.txt</code>.</p> <p>Note that the IDs must be outputted as strings to preserve the preceding zeros. Each ID must appear on a separate line in the output file.</p> <p><a href="https://www.cdslab.org/recipes/programming/parsing-data-from-web/parsing-data-from-web">Parsing data from the World Wide Web</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on April 12, 2021.</p> <![CDATA[Data transfer: Converting formatted input to Comma-Separated-Values (CSV) output]]> https://www.cdslab.org/recipes/programming/formatted-input-to-csv-output/formatted-input-to-csv-output 2021-04-12T00:00:00-05:00 2021-04-12T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>Consider this formatted data file: <a href="data.in" target="_blank">data.in</a>. Write a simple script named <code>formatted2csv</code> that takes two input arguments representing the input and output file names. Then, the script writes the same input float data to the output file <code>data.out</code> <strong>in a comma-separated (CSV) style</strong>, like this <a href="data.python.out" target="_blank">example output file</a>.</p> <div style="text-align:center;margin-top:4rem;margin-bottom:1rem;"> <figure> <a href="#solution-python" id="solution-python"> <img src="https://www.cdslab.org/recipes/images/Python.png" width="75px" /> </a> <figcaption> <a href="https://en.wikipedia.org/wiki/Python_(programming_language)" target="_blank"> Python </a> </figcaption> </figure> </div> <p>Write your Python script in such a way that it takes the input and output file names from the Bash command line arguments, like the following,</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>python formatted2csv.py data.in data.out </code></pre></div></div> <div style="text-align:center;margin-top:4rem;margin-bottom:1rem;"> <figure> <a href="#solution-matlab" id="solution-matlab"> <img src="https://www.cdslab.org/recipes/images/MATLAB.png" width="75px" /> </a> <figcaption> <a href="https://en.wikipedia.org/wiki/MATLAB" target="_blank"> MATLAB </a> </figcaption> </figure> </div> <p>Write your MATLAB script as a function that takes the input and output file names as input arguments to a function named <code>formatted2csv</code>, so that it can be called like the following from the MATLAB command line.</p> <div class="language-matlab highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">formatted2csv</span><span class="p">(</span><span class="s1">'data.in'</span><span class="p">,</span><span class="s1">'data.matlab.out'</span><span class="p">)</span> </code></pre></div></div> <p><a href="https://www.cdslab.org/recipes/programming/formatted-input-to-csv-output/formatted-input-to-csv-output">Data transfer: Converting formatted input to Comma-Separated-Values (CSV) output</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on April 12, 2021.</p> <![CDATA[Command line input option-value pairs]]> https://www.cdslab.org/recipes/programming/command-line-input-option-value/command-line-input-option-value 2021-04-05T00:00:00-05:00 2021-04-05T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <div style="text-align:center;margin-top:4rem;margin-bottom:1rem;"> <figure> <a href="#problem-python" id="problem-python"> <img src="https://www.cdslab.org/recipes/images/Python.png" width="75px" /> </a> <figcaption> <a href="https://en.wikipedia.org/wiki/Python_(programming_language)" target="_blank"> Python </a> </figcaption> </figure> </div> <p>Suppose we want to write a program that takes in three input parameters: the initial height ($y_0$) <code>initHeight</code>, the initial velocity ($v_0$) <code>initVelocity</code>, the time after which we want to know how much a projectile has moved in the vertical direction from the initial height ($y_0$), and the gravity constant ($g$) <code>gravityConstant</code>. Write the program such that it takes these three parameters as pairs of option (keyword) and values plus an additional option <code>unit</code> which can have either <code>SI</code> or <code>English</code> values. Then it computes and prints the final height <code>finalHeight</code> via the following equation,</p> $y(t) = y_0 + v_0\times t + \frac{1}{2}g\times t^2 ~~,$ <p>or in scripting terms,</p> <div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">finalHeight</span> <span class="o">=</span> <span class="n">initHeight</span> <span class="o">+</span> <span class="n">initVelocity</span> <span class="o">*</span> <span class="n">time</span> <span class="o">+</span> <span class="n">gravityConstant</span> <span class="o">*</span> <span class="n">time</span><span class="o">**</span><span class="mi">2</span> </code></pre></div></div> <p><strong>(A)</strong> Write your code such that it works with the following example input option-value pair,</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>python getHeight.py unit SI initHeight 0 initVelocity 0 <span class="nb">time </span>3 gravityConstant <span class="nt">-10</span> </code></pre></div></div> <p>Compute the height for the same input values as in the above, but for the gravity constant of the Moon $g \sim 1.62 ms^{-2}$. How does it compare to Earth?</p> <p><strong>(B)</strong> Rewrite your program such that the missing option value pairs from the input are assigned proper values. For example, if <code>initHeight</code> is missing, it should be assigned a value of <code>0</code>. If <code>initVelocity</code> is missing, it should be assigned a value of <code>0</code>. If <code>gravityConstant</code> is missing, it should be assigned a value of <code>-10</code> $m/s^2$ if the input <code>unit</code> is <code>SI</code>, otherwise it should be assigned <code>-32.17405</code> $ft/s^2$. If the <code>unit</code> is missing, it should be assigned <code>SI</code> as the default value.</p> <p><strong>(C)</strong> Now rewrite your program such that the missing option value pairs would be read from an input file, if the <code>file path_to_file</code> is given as option value pair. For example, your code should be able to parse the contents of these two example input files: <a href="input.1.txt" target="_blank">input.1.txt</a> or <a href="input.2.txt" target="_blank">input.2.txt</a>, when called with the <code>file</code> command-line option (and it should ignore any other input command-line option other than <code>file</code> and its value.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>python getHeight.py file <span class="s2">"input.1.txt"</span> </code></pre></div></div> <pre><code>Final Height = -45.0 in SI units. </code></pre> <p><a href="https://www.cdslab.org/recipes/programming/command-line-input-option-value/command-line-input-option-value">Command line input option-value pairs</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on April 05, 2021.</p> <![CDATA[Python modules and packaging]]> https://www.cdslab.org/recipes/programming/python-packaging/python-packaging 2021-03-31T00:00:00-05:00 2021-03-31T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <div style="text-align:center;margin-top:3rem;margin-bottom:2rem;"> <a href="#problem" style="display:inline-block;"> <h2 id="problem" style="color:red;"> Problem </h2> </a> </div> <p>Consider the following codes that compute the Fibonacci sequence using two different methods: <a href="fib_recursive.py" target="_blank">fib_recursive.py</a> and <a href="fib_loop.py" target="_blank">fib_loop.py</a>.</p> <ol> <li>Put these two functions in a folder named <code>fib</code> such that they can be imported as a Python package to your Python environment.</li> <li>Rewrite these scripts such that they are imported as Python packages without being executed, while the functions are called if the scripts are executed as standalone Python code.</li> </ol> <p><a href="https://www.cdslab.org/recipes/programming/python-packaging/python-packaging">Python modules and packaging</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on March 31, 2021.</p> <![CDATA[Logic NAND equivalence]]> https://www.cdslab.org/recipes/programming/logic-a-nand-equivalence/logic/logic-a-nand-equivalence 2020-11-01T00:00:00-05:00 2020-11-01T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>We have learned that,</p> $\begin{eqnarray} \bar{A} &amp;=&amp; A \uparrow A ~, \nonumber \\ AB &amp;=&amp; (A \uparrow B) \uparrow (A \uparrow B) ~, \nonumber \\ A + B &amp;=&amp; (A \uparrow A) \uparrow (B \uparrow B) ~, \nonumber \end{eqnarray}$ <p>Now, using the above expressions, show that,</p> $(A \uparrow A) \uparrow ( ((A \uparrow B) \uparrow (A \uparrow B)) \uparrow ((A \uparrow B) \uparrow (A \uparrow B)) ) = A ~, \nonumber$ <p><a href="https://www.cdslab.org/recipes/programming/logic-a-nand-equivalence/logic/logic-a-nand-equivalence">Logic NAND equivalence</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on November 01, 2020.</p> <![CDATA[The major schools of thought in Probability Theory]]> https://www.cdslab.org/recipes/programming/probability-schools-of-thought/probability-schools-of-thought 2020-10-21T00:00:00-05:00 2020-10-21T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Name four major schools of Probability Theory.</p> <p><a href="https://www.cdslab.org/recipes/programming/probability-schools-of-thought/probability-schools-of-thought">The major schools of thought in Probability Theory</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p> <![CDATA[The fundamental desiderata of Probability Theory]]> https://www.cdslab.org/recipes/programming/probability-desiderata/probability-desiderata 2020-10-21T00:00:00-05:00 2020-10-21T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Name the three fundamental desiderata of Probability Theory.</p> <p><a href="https://www.cdslab.org/recipes/programming/probability-desiderata/probability-desiderata">The fundamental desiderata of Probability Theory</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p> <![CDATA[Probability Theory: correspondence with commonsense]]> https://www.cdslab.org/recipes/programming/probability-correspondence-with-common-sense/probability-correspondence-with-common-sense 2020-10-21T00:00:00-05:00 2020-10-21T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Show via an example Venn diagram that if,</p> <figure><img src="commonsense.png" width="200" /></figure> <p>holds, then,</p> <figure><img src="result.png" width="200" /></figure> <p>also holds.</p> <p><a href="https://www.cdslab.org/recipes/programming/probability-correspondence-with-common-sense/probability-correspondence-with-common-sense">Probability Theory: correspondence with commonsense</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p> <![CDATA[The proof of Bayes' Rule via Venn diagram]]> https://www.cdslab.org/recipes/programming/probability-bayes-rule-proof-venn-disgram/probability-bayes-rule-proof-venn-disgram 2020-10-21T00:00:00-05:00 2020-09-30T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Prove the Bayes’s rule via Venn diagrams,</p> $\pi(B|A) = \frac{ \pi(A|B) ~ \pi(B) } { \pi(A) } ~.$ <p><a href="https://www.cdslab.org/recipes/programming/probability-bayes-rule-proof-venn-disgram/probability-bayes-rule-proof-venn-disgram">The proof of Bayes' Rule via Venn diagram</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p> <![CDATA[The fundamental logical operators]]> https://www.cdslab.org/recipes/programming/logic-fundamental-operations/logic-fundamental-operations 2020-10-21T00:00:00-05:00 2020-10-21T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Show that the following identities hold,</p> <figure><img src="threeFundamentals.png" width="250" /></figure> <p>where the two arrow-up and arrow-down symbols represent the fundamental NAND and NOR operators,</p> <figure><img src="nand_nor.png" width="200" /></figure> <p><a href="https://www.cdslab.org/recipes/programming/logic-fundamental-operations/logic-fundamental-operations">The fundamental logical operators</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p> <![CDATA[Logic functions in terms of logic functions]]> https://www.cdslab.org/recipes/programming/logic-functions-operations/logic-functions-operations 2020-10-21T00:00:00-05:00 2020-10-21T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Show that the following functions,</p> <figure><img src="truthTable.png" width="350" /></figure> <p>can be written as,</p> <figure><img src="operations.png" width="400" /></figure> <p>where the basis logic functions have the following truth table,</p> <figure><img src="basisTruthTable.png" width="350" /></figure> <p><a href="https://www.cdslab.org/recipes/programming/logic-functions-operations/logic-functions-operations">Logic functions in terms of logic functions</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p> <![CDATA[Logic functions with 2 input]]> https://www.cdslab.org/recipes/programming/logic-functions-2d/logic-functions-2d 2020-10-21T00:00:00-05:00 2020-10-21T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Consider the following special functions that are TRUE only at specific points within the logical sample space:</p> <figure><img src="truthTable.png" width="350" /></figure> <p><br /></p> <p>Show that the above truth table is equivalent to the following logical operations.</p> <figure><img src="logicalOperators.png" width="170" /></figure> <p><br /></p> <p><a href="https://www.cdslab.org/recipes/programming/logic-functions-2d/logic-functions-2d">Logic functions with 2 input</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p> <![CDATA[Logic functions with 1 input]]> https://www.cdslab.org/recipes/programming/logic-functions-1d/logic-functions-1d 2020-10-21T00:00:00-05:00 2020-10-21T00:00:00-00:00 Amir Shahmoradi https://www.cdslab.org/recipes shahmoradi@utexas.edu <p>Consider a set of logic functions $$\{ f_1(A), f_2(A), f_3(A), f_4(A)\}$$ that take a proposition ($$A$$) as input which is either True or False. These functions map the truth value of the input proposition to either True or False according to some unknown rules. We want to discover these rules. Given the following truth table, we want to show that,</p> <figure><img src="truthTable.png" width="300" /></figure> <p><br /></p> <p>necessitates the equivalence of our four logic functions with the following logical operators. To do so, you can draw the truth table corresponding to these logical operations to show that they have same values as their corresponding logic functions in the truth table in the above.</p> <figure><img src="logicalOperators.png" width="300" /></figure> <p><br /></p> <p><a href="https://www.cdslab.org/recipes/programming/logic-functions-1d/logic-functions-1d">Logic functions with 1 input</a> was originally published by Amir Shahmoradi at <a href="https://www.cdslab.org/recipes">CDSLab Recipes - A repository for all sorts of problems with solutions</a> on October 21, 2020.</p>