marimo-learn / _site /probability /03_probability_of_or.html
Haleshot's picture
changes
5d38ada unverified
raw
history blame
21.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="./favicon.ico" />
<!-- Preload is necessary because we show these images when we disconnect from the server,
but at that point we cannot load these images from the server -->
<link rel="preload" href="./assets/gradient-yHQUC_QB.png" as="image" />
<link rel="preload" href="./assets/noise-60BoTA8O.png" as="image" />
<!-- Preload the fonts -->
<link rel="preload" href="./assets/Lora-VariableFont_wght-B2ootaw-.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/PTSans-Regular-CxL0S8W7.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/PTSans-Bold-D9fedIX3.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/FiraMono-Regular-BTCkDNvf.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/FiraMono-Medium-DU3aDxX5.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/FiraMono-Bold-CLVRCuM9.ttf" as="font" crossorigin="anonymous" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="a marimo app" />
<link rel="apple-touch-icon" href="./apple-touch-icon.png" />
<link rel="manifest" href="./manifest.json" />
<script data-marimo="true">
function __resizeIframe(obj) {
var scrollbarHeight = 20; // Max between windows, mac, and linux
function setHeight() {
var element = obj.contentWindow.document.documentElement;
// If there is no vertical scrollbar, we don't need to resize the iframe
if (element.scrollHeight === element.clientHeight) {
return;
}
// Create a new height that includes the scrollbar height if it's visible
var hasHorizontalScrollbar = element.scrollWidth > element.clientWidth;
var newHeight = element.scrollHeight + (hasHorizontalScrollbar ? scrollbarHeight : 0);
// Only update the height if it's different from the current height
if (obj.style.height !== `${newHeight}px`) {
obj.style.height = `${newHeight}px`;
}
}
// Resize the iframe to the height of the content and bottom scrollbar height
setHeight();
// Resize the iframe when the content changes
const resizeObserver = new ResizeObserver((entries) => {
setHeight();
});
resizeObserver.observe(obj.contentWindow.document.body);
}
</script>
<marimo-filename hidden>notebook.py</marimo-filename>
<marimo-mode data-mode='edit' hidden></marimo-mode>
<marimo-version data-version='0.11.9' hidden></marimo-version>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"default_width": "medium", "cell_output": "above", "theme": "light", "dataframes": "rich", "code_editor_font_size": 14}, "formatting": {"line_length": 79}, "keymap": {"preset": "default", "overrides": {}}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun", "watcher_on_save": "lazy", "output_max_bytes": 8000000, "std_stream_max_bytes": 1000000}, "save": {"autosave": "off", "autosave_delay": 1000, "format_on_save": false}, "package_management": {"manager": "pip"}, "server": {"browser": "default", "follow_symlink": false}, "snippets": {"custom_paths": [], "include_default_snippets": true}}' data-overrides='{}' hidden></marimo-user-config>
<marimo-app-config data-config='{"width": "medium"}' hidden></marimo-app-config>
<marimo-server-token data-token='123' hidden></marimo-server-token>
<title>03 probability of or</title>
<script type="module" crossorigin src="./assets/index-BiV-b1K2.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-DkqMrX_B.css">
<marimo-wasm hidden=""></marimo-wasm>
<script>
if (window.location.protocol === 'file:') {
alert('Warning: This file must be served by an HTTP server to function correctly.');
}
</script>
<style>
#save-button {
display: none !important;
}
#filename-input {
display: none !important;
}
</style>
<marimo-code hidden="" data-show-code="false">import%20marimo%0A%0A__generated_with%20%3D%20%220.11.9%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20matplotlib_venn%20import%20venn2%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20return%20np%2C%20plt%2C%20venn2%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%20Probability%20of%20Or%0A%0A%20%20%20%20%20%20%20%20When%20calculating%20the%20probability%20of%20either%20one%20event%20_or_%20another%20occurring%2C%20we%20need%20to%20be%20careful%20about%20how%20we%20combine%20probabilities.%20The%20method%20depends%20on%20whether%20the%20events%20can%20happen%20together%5B%3Csup%3E1%3C%2Fsup%3E%5D(https%3A%2F%2Fchrispiech.github.io%2FprobabilityForComputerScientists%2Fen%2Fpart1%2Fprob_or%2F).%0A%0A%20%20%20%20%20%20%20%20Let's%20explore%20how%20to%20calculate%20%24P(E%20%5Ccup%20F)%24%2C%20i.e.%20%24P(E%20%5Ctext%7B%20or%20%7D%20F)%24%2C%20in%20different%20scenarios.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Mutually%20Exclusive%20Events%0A%0A%20%20%20%20%20%20%20%20Two%20events%20%24E%24%20and%20%24F%24%20are%20**mutually%20exclusive**%20if%20they%20cannot%20occur%20simultaneously.%20%0A%20%20%20%20%20%20%20%20In%20set%20notation%2C%20this%20means%3A%0A%0A%20%20%20%20%20%20%20%20%24E%20%5Ccap%20F%20%3D%20%5Cemptyset%24%0A%0A%20%20%20%20%20%20%20%20For%20example%3A%0A%0A%20%20%20%20%20%20%20%20-%20Rolling%20an%20even%20number%20(2%2C4%2C6)%20vs%20rolling%20an%20odd%20number%20(1%2C3%2C5)%0A%20%20%20%20%20%20%20%20-%20Drawing%20a%20heart%20vs%20drawing%20a%20spade%20from%20a%20deck%0A%20%20%20%20%20%20%20%20-%20Passing%20vs%20failing%20a%20test%0A%0A%20%20%20%20%20%20%20%20Here's%20a%20Python%20function%20to%20check%20if%20two%20sets%20of%20outcomes%20are%20mutually%20exclusive%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20are_mutually_exclusive(event1%2C%20event2)%3A%0A%20%20%20%20%20%20%20%20return%20len(event1.intersection(event2))%20%3D%3D%200%0A%0A%20%20%20%20%23%20Example%20with%20dice%20rolls%0A%20%20%20%20even_numbers%20%3D%20%7B2%2C%204%2C%206%7D%0A%20%20%20%20odd_numbers%20%3D%20%7B1%2C%203%2C%205%7D%0A%20%20%20%20prime_numbers%20%3D%20%7B2%2C%203%2C%205%2C%207%7D%0A%20%20%20%20return%20are_mutually_exclusive%2C%20even_numbers%2C%20odd_numbers%2C%20prime_numbers%0A%0A%0A%40app.cell%0Adef%20_(are_mutually_exclusive%2C%20even_numbers%2C%20odd_numbers)%3A%0A%20%20%20%20are_mutually_exclusive(even_numbers%2C%20odd_numbers)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(are_mutually_exclusive%2C%20even_numbers%2C%20prime_numbers)%3A%0A%20%20%20%20are_mutually_exclusive(even_numbers%2C%20prime_numbers)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Or%20with%20Mutually%20Exclusive%20Events%0A%0A%20%20%20%20%20%20%20%20For%20mutually%20exclusive%20events%2C%20the%20probability%20of%20either%20event%20occurring%20is%20simply%20the%20sum%20of%20their%20individual%20probabilities%3A%0A%0A%20%20%20%20%20%20%20%20%24P(E%20%5Ccup%20F)%20%3D%20P(E)%20%2B%20P(F)%24%0A%0A%20%20%20%20%20%20%20%20This%20extends%20to%20multiple%20events.%20For%20%24n%24%20mutually%20exclusive%20events%20%24E_1%2C%20E_2%2C%20%5Cldots%2C%20E_n%24%3A%0A%0A%20%20%20%20%20%20%20%20%24P(E_1%20%5Ccup%20E_2%20%5Ccup%20%5Ccdots%20%5Ccup%20E_n)%20%3D%20%5Csum_%7Bi%3D1%7D%5En%20P(E_i)%24%0A%0A%20%20%20%20%20%20%20%20Let's%20implement%20this%20calculation%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20prob_union_mutually_exclusive(probabilities)%3A%0A%20%20%20%20%20%20%20%20return%20sum(probabilities)%0A%0A%20%20%20%20%23%20Example%3A%20Rolling%20a%20die%0A%20%20%20%20%23%20P(even)%20%3D%20P(2)%20%2B%20P(4)%20%2B%20P(6)%0A%20%20%20%20p_even_mutually_exclusive%20%3D%20prob_union_mutually_exclusive(%5B1%2F6%2C%201%2F6%2C%201%2F6%5D)%0A%20%20%20%20print(f%22P(rolling%20an%20even%20number)%20%3D%20%7Bp_even_mutually_exclusive%7D%22)%0A%0A%20%20%20%20%23%20P(prime)%20%3D%20P(2)%20%2B%20P(3)%20%2B%20P(5)%0A%20%20%20%20p_prime_mutually_exclusive%20%3D%20prob_union_mutually_exclusive(%5B1%2F6%2C%201%2F6%2C%201%2F6%5D)%0A%20%20%20%20print(f%22P(rolling%20a%20prime%20number)%20%3D%20%7Bp_prime_mutually_exclusive%7D%22)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20p_even_mutually_exclusive%2C%0A%20%20%20%20%20%20%20%20p_prime_mutually_exclusive%2C%0A%20%20%20%20%20%20%20%20prob_union_mutually_exclusive%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Or%20with%20Non-Mutually%20Exclusive%20Events%0A%0A%20%20%20%20%20%20%20%20When%20events%20can%20occur%20together%2C%20we%20need%20to%20use%20the%20**inclusion-exclusion%20principle**%3A%0A%0A%20%20%20%20%20%20%20%20%24P(E%20%5Ccup%20F)%20%3D%20P(E)%20%2B%20P(F)%20-%20P(E%20%5Ccap%20F)%24%0A%0A%20%20%20%20%20%20%20%20Why%20subtract%20%24P(E%20%5Ccap%20F)%24%3F%20Because%20when%20we%20add%20%24P(E)%24%20and%20%24P(F)%24%2C%20we%20count%20the%20overlap%20twice!%0A%0A%20%20%20%20%20%20%20%20For%20example%2C%20consider%20calculating%20%24P(%5Ctext%7Bprime%20or%20even%7D)%24%20when%20rolling%20a%20die%3A%0A%0A%20%20%20%20%20%20%20%20-%20Prime%20numbers%3A%20%7B2%2C%203%2C%205%7D%0A%20%20%20%20%20%20%20%20-%20Even%20numbers%3A%20%7B2%2C%204%2C%206%7D%0A%20%20%20%20%20%20%20%20-%20The%20number%202%20is%20counted%20twice%20unless%20we%20subtract%20its%20probability%0A%0A%20%20%20%20%20%20%20%20Here's%20how%20to%20implement%20this%20calculation%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20prob_union_general(p_a%2C%20p_b%2C%20p_intersection)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Calculate%20probability%20of%20union%20for%20any%20two%20events%22%22%22%0A%20%20%20%20%20%20%20%20return%20p_a%20%2B%20p_b%20-%20p_intersection%0A%0A%20%20%20%20%23%20Example%3A%20Rolling%20a%20die%0A%20%20%20%20%23%20P(prime%20or%20even)%0A%20%20%20%20p_prime_general%20%3D%203%2F6%20%20%20%20%23%20P(prime)%20%3D%20P(2%2C3%2C5)%0A%20%20%20%20p_even_general%20%3D%203%2F6%20%20%20%20%20%23%20P(even)%20%3D%20P(2%2C4%2C6)%0A%20%20%20%20p_intersection%20%3D%201%2F6%20%20%20%20%20%23%20P(intersection)%20%3D%20P(2)%0A%0A%20%20%20%20result%20%3D%20prob_union_general(p_prime_general%2C%20p_even_general%2C%20p_intersection)%0A%20%20%20%20print(f%22P(prime%20or%20even)%20%3D%20%7Bp_prime_general%7D%20%2B%20%7Bp_even_general%7D%20-%20%7Bp_intersection%7D%20%3D%20%7Bresult%7D%22)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20p_even_general%2C%0A%20%20%20%20%20%20%20%20p_intersection%2C%0A%20%20%20%20%20%20%20%20p_prime_general%2C%0A%20%20%20%20%20%20%20%20prob_union_general%2C%0A%20%20%20%20%20%20%20%20result%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%23%20Extension%20to%20Three%20Events%0A%0A%20%20%20%20%20%20%20%20For%20three%20events%2C%20the%20inclusion-exclusion%20principle%20becomes%3A%0A%0A%20%20%20%20%20%20%20%20%24P(E_1%20%5Ccup%20E_2%20%5Ccup%20E_3)%20%3D%20P(E_1)%20%2B%20P(E_2)%20%2B%20P(E_3)%24%0A%20%20%20%20%20%20%20%20%24-%20P(E_1%20%5Ccap%20E_2)%20-%20P(E_1%20%5Ccap%20E_3)%20-%20P(E_2%20%5Ccap%20E_3)%24%0A%20%20%20%20%20%20%20%20%24%2B%20P(E_1%20%5Ccap%20E_2%20%5Ccap%20E_3)%24%0A%0A%20%20%20%20%20%20%20%20The%20pattern%20is%3A%0A%0A%20%20%20%20%20%20%20%201.%20Add%20individual%20probabilities%0A%20%20%20%20%20%20%20%202.%20Subtract%20probabilities%20of%20pairs%0A%20%20%20%20%20%20%20%203.%20Add%20probability%20of%20triple%20intersection%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Interactive%20example%3A%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(event_type)%3A%0A%20%20%20%20event_type%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Create%20a%20dropdown%20to%20select%20the%20type%20of%20events%20to%20visualize%0A%20%20%20%20event_type%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Mutually%20Exclusive%20Events%20(Rolling%20Odd%20vs%20Even)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Non-Mutually%20Exclusive%20Events%20(Prime%20vs%20Even)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Three%20Events%20(Less%20than%203%2C%20Even%2C%20Prime)%22%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20value%3D%22Mutually%20Exclusive%20Events%20(Rolling%20Odd%20vs%20Even)%22%2C%0A%20%20%20%20%20%20%20%20label%3D%22Select%20Event%20Type%22%0A%20%20%20%20)%0A%20%20%20%20return%20(event_type%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(event_type%2C%20mo%2C%20plt%2C%20venn2)%3A%0A%20%20%20%20%23%20Define%20the%20events%20and%20their%20probabilities%0A%20%20%20%20events_data%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22Mutually%20Exclusive%20Events%20(Rolling%20Odd%20vs%20Even)%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22sets%22%3A%20(round(3%2F6%2C%202)%2C%20round(3%2F6%2C%202)%2C%200)%2C%20%20%23%20(odd%2C%20even%2C%20intersection)%0A%20%20%20%20%20%20%20%20%20%20%20%20%22labels%22%3A%20(%22Odd%5Cn%7B1%2C3%2C5%7D%22%2C%20%22Even%5Cn%7B2%2C4%2C6%7D%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Mutually%20Exclusive%20Events%3A%20Odd%20vs%20Even%20Numbers%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22explanation%22%3A%20r%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%23%23%20Mutually%20Exclusive%20Events%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BOdd%7D)%20%3D%20%5Cfrac%7B3%7D%7B6%7D%20%3D%200.5%24%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BEven%7D)%20%3D%20%5Cfrac%7B3%7D%7B6%7D%20%3D%200.5%24%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BOdd%7D%20%5Ccap%20%5Ctext%7BEven%7D)%20%3D%200%24%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BOdd%7D%20%5Ccup%20%5Ctext%7BEven%7D)%20%3D%20P(%5Ctext%7BOdd%7D)%20%2B%20P(%5Ctext%7BEven%7D)%20%3D%201%24%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20These%20events%20are%20mutually%20exclusive%20because%20a%20number%20cannot%20be%20both%20odd%20and%20even.%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22Non-Mutually%20Exclusive%20Events%20(Prime%20vs%20Even)%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22sets%22%3A%20(round(2%2F6%2C%202)%2C%20round(2%2F6%2C%202)%2C%20round(1%2F6%2C%202))%2C%20%20%23%20(prime-only%2C%20even-only%2C%20intersection)%0A%20%20%20%20%20%20%20%20%20%20%20%20%22labels%22%3A%20(%22Prime%5Cn%7B3%2C5%7D%22%2C%20%22Even%5Cn%7B4%2C6%7D%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Non-Mutually%20Exclusive%3A%20Prime%20vs%20Even%20Numbers%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22explanation%22%3A%20r%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%23%23%20Non-Mutually%20Exclusive%20Events%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BPrime%7D)%20%3D%20%5Cfrac%7B3%7D%7B6%7D%20%3D%200.5%24%20(2%2C3%2C5)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BEven%7D)%20%3D%20%5Cfrac%7B3%7D%7B6%7D%20%3D%200.5%24%20(2%2C4%2C6)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BPrime%7D%20%5Ccap%20%5Ctext%7BEven%7D)%20%3D%20%5Cfrac%7B1%7D%7B6%7D%24%20(2)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BPrime%7D%20%5Ccup%20%5Ctext%7BEven%7D)%20%3D%20%5Cfrac%7B3%7D%7B6%7D%20%2B%20%5Cfrac%7B3%7D%7B6%7D%20-%20%5Cfrac%7B1%7D%7B6%7D%20%3D%20%5Cfrac%7B5%7D%7B6%7D%24%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20These%20events%20overlap%20because%202%20is%20both%20prime%20and%20even.%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22Three%20Events%20(Less%20than%203%2C%20Even%2C%20Prime)%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22sets%22%3A%20(round(1%2F6%2C%202)%2C%20round(2%2F6%2C%202)%2C%20round(1%2F6%2C%202))%2C%20%20%23%20(less%20than%203%2C%20even%2C%20intersection)%0A%20%20%20%20%20%20%20%20%20%20%20%20%22labels%22%3A%20(%22%3C3%5Cn%7B1%2C2%7D%22%2C%20%22Even%5Cn%7B2%2C4%2C6%7D%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Complex%20Example%3A%20Numbers%20%3C%203%20and%20Even%20Numbers%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22explanation%22%3A%20r%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%23%23%20Complex%20Event%20Interaction%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(x%20%3C%203)%20%3D%20%5Cfrac%7B2%7D%7B6%7D%24%20(1%2C2)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(%5Ctext%7BEven%7D)%20%3D%20%5Cfrac%7B3%7D%7B6%7D%24%20(2%2C4%2C6)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(x%20%3C%203%20%5Ccap%20%5Ctext%7BEven%7D)%20%3D%20%5Cfrac%7B1%7D%7B6%7D%24%20(2)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%24P(x%20%3C%203%20%5Ccup%20%5Ctext%7BEven%7D)%20%3D%20%5Cfrac%7B2%7D%7B6%7D%20%2B%20%5Cfrac%7B3%7D%7B6%7D%20-%20%5Cfrac%7B1%7D%7B6%7D%20%3D%20%5Cfrac%7B4%7D%7B6%7D%24%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20The%20number%202%20belongs%20to%20both%20sets%2C%20requiring%20the%20inclusion-exclusion%20principle.%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%0A%20%20%20%20%23%20Get%20data%20for%20selected%20event%20type%0A%20%20%20%20data%20%3D%20events_data%5Bevent_type.value%5D%0A%0A%20%20%20%20%23%20Create%20visualization%0A%20%20%20%20plt.figure(figsize%3D(10%2C%205))%0A%20%20%20%20v%20%3D%20venn2(subsets%3Ddata%5B%22sets%22%5D%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20set_labels%3Ddata%5B%22labels%22%5D)%0A%20%20%20%20plt.title(data%5B%22title%22%5D)%0A%0A%20%20%20%20%23%20Display%20explanation%20alongside%20visualization%0A%20%20%20%20mo.hstack(%5B%0A%20%20%20%20%20%20%20%20plt.gcf()%2C%0A%20%20%20%20%20%20%20%20mo.md(data%5B%22explanation%22%5D)%0A%20%20%20%20%5D)%0A%20%20%20%20return%20data%2C%20events_data%2C%20v%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20%F0%9F%A4%94%20Test%20Your%20Understanding%0A%0A%20%20%20%20%20%20%20%20Consider%20rolling%20a%20six-sided%20die.%20Which%20of%20these%20statements%20are%20true%3F%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3E1.%20P(even%20or%20less%20than%203)%20%3D%20P(even)%20%2B%20P(less%20than%203)%3C%2Fsummary%3E%0A%0A%20%20%20%20%20%20%20%20%E2%9D%8C%20Incorrect!%20These%20events%20are%20not%20mutually%20exclusive%20(2%20is%20both%20even%20and%20less%20than%203).%0A%20%20%20%20%20%20%20%20We%20need%20to%20use%20the%20inclusion-exclusion%20principle.%0A%20%20%20%20%20%20%20%20%3C%2Fdetails%3E%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3E2.%20P(even%20or%20greater%20than%204)%20%3D%204%2F6%3C%2Fsummary%3E%0A%0A%20%20%20%20%20%20%20%20%E2%9C%85%20Correct!%20%7B2%2C4%2C6%7D%20%E2%88%AA%20%7B5%2C6%7D%20%3D%20%7B2%2C4%2C5%2C6%7D%2C%20so%20probability%20is%204%2F6.%0A%20%20%20%20%20%20%20%20%3C%2Fdetails%3E%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3E3.%20P(prime%20or%20odd)%20%3D%205%2F6%3C%2Fsummary%3E%0A%0A%20%20%20%20%20%20%20%20%E2%9C%85%20Correct!%20%7B2%2C3%2C5%7D%20%E2%88%AA%20%7B1%2C3%2C5%7D%20%3D%20%7B1%2C2%2C3%2C5%7D%2C%20so%20probability%20is%205%2F6.%0A%20%20%20%20%20%20%20%20%3C%2Fdetails%3E%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20%20%20%20%20You've%20learned%3A%0A%0A%20%20%20%20%20%20%20%20-%20How%20to%20identify%20mutually%20exclusive%20events%0A%20%20%20%20%20%20%20%20-%20The%20addition%20rule%20for%20mutually%20exclusive%20events%0A%20%20%20%20%20%20%20%20-%20The%20inclusion-exclusion%20principle%20for%20overlapping%20events%0A%20%20%20%20%20%20%20%20-%20How%20to%20extend%20these%20concepts%20to%20multiple%20events%0A%0A%20%20%20%20%20%20%20%20In%20the%20next%20lesson%2C%20we'll%20explore%20**conditional%20probability**%20-%20how%20the%20probability%20%0A%20%20%20%20%20%20%20%20of%20one%20event%20changes%20when%20we%20know%20another%20event%20has%20occurred.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A</marimo-code></head>
<body>
<div id="root"></div>
</body>
</html>