File size: 7,559 Bytes
225e16e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "marimo",
# ]
# ///

import marimo

__generated_with = "0.10.17"
app = marimo.App()


@app.cell(hide_code=True)
def _(mo):
    mo.md(
        """
        # ๐ŸŽฏ Set Theory: The Building Blocks of Probability

        Welcome to the magical world of sets! Think of sets as the LEGOยฎ blocks of probability - 
        they're the fundamental pieces we use to build more complex concepts.

        ## What is a Set? 

        A set is a collection of distinct objects, called elements or members. 

        For example:

        - ๐ŸŽจ Colors = {red, blue, green}

        - ๐Ÿ”ข Even numbers under 10 = {2, 4, 6, 8}

        - ๐Ÿพ Pets = {dog, cat, hamster, fish}
        """
    )
    return


@app.cell
def _(elements):
    elements
    return


@app.cell(hide_code=True)
def _(mo):
    # interactive set creator
    elements = mo.ui.text(
        value="๐Ÿถ,๐Ÿฑ,๐Ÿน",
        label="Create your own set (use commas to separate elements)"
    )
    return (elements,)


@app.cell(hide_code=True)
def _(elements, mo):
    user_set = set(elements.value.split(','))

    mo.md(f"""
    ### Your Custom Set:

    ${{{', '.join(user_set)}}}$

    Number of elements: {len(user_set)}
    """)
    return (user_set,)


@app.cell(hide_code=True)
def _(mo):
    mo.md(
        """
        ## ๐ŸŽฎ Set Operations Playground

        Let's explore the three fundamental set operations:

        - Union (โˆช): Combining sets

        - Intersection (โˆฉ): Finding common elements

        - Difference (-): What's unique to one set

        Try creating two sets below!
        """
    )
    return


@app.cell
def _(operation):
    operation
    return


@app.cell(hide_code=True)
def _(mo):
    set_a = mo.ui.text(value="๐Ÿ•,๐Ÿ”,๐ŸŒญ,๐ŸŸ", label="Set A (Fast Food)")
    set_b = mo.ui.text(value="๐Ÿ•,๐Ÿฅ—,๐Ÿฅ™,๐ŸŸ", label="Set B (Healthy-ish Food)")

    operation = mo.ui.dropdown(
        options=["Union", "Intersection", "Difference"],
        value="Union",
        label="Choose Operation"
    )
    return operation, set_a, set_b


@app.cell
def _(mo, operation, set_a, set_b):
    A = set(set_a.value.split(','))
    B = set(set_b.value.split(','))

    results = {
        "Union": (A | B, "โˆช", "Everything from both sets"),
        "Intersection": (A & B, "โˆฉ", "Common elements"),
        "Difference": (A - B, "-", "In A but not in B")
    }

    _result, symbol, description = results[operation.value]

    mo.md(f"""
    ### Set Operation Result

    $A {symbol} B = {{{', '.join(_result)}}}$

    **What this means**: {description}

    **Set A**: {', '.join(A)}
    **Set B**: {', '.join(B)}
    """)
    return A, B, description, results, symbol


@app.cell(hide_code=True)
def _(mo):
    mo.md(
        """
        ## ๐ŸŽฌ Netflix Shows Example

        Let's use set theory to understand content recommendations!
        """
    )
    return


@app.cell
def _(viewer_type):
    viewer_type
    return


@app.cell
def _(mo):
    # Netflix genres example
    action_fans = {"Stranger Things", "The Witcher", "Money Heist"}
    drama_fans = {"The Crown", "Money Heist", "Bridgerton"}

    viewer_type = mo.ui.radio(
        options=["New Viewer", "Action Fan", "Drama Fan"],
        value="New Viewer",
        label="Select Viewer Type"
    )
    return action_fans, drama_fans, viewer_type


@app.cell
def _(action_fans, drama_fans, mo, viewer_type):
    recommendations = {
        "New Viewer": action_fans | drama_fans,  # Union for new viewers
        "Action Fan": action_fans - drama_fans,  # Unique action shows
        "Drama Fan": drama_fans - action_fans    # Unique drama shows
    }

    result = recommendations[viewer_type.value]

    explanation = {
        "New Viewer": "You get everything to explore!",
        "Action Fan": "Pure action, no drama!",
        "Drama Fan": "Drama-focused selections!"
    }

    mo.md(f"""
    ### ๐ŸŽฌ Recommended Shows

    Based on your preference for **{viewer_type.value}**, we recommend:

    {', '.join(result)}

    **Why these shows?** 
    {explanation[viewer_type.value]}
    """)
    return explanation, recommendations, result


@app.cell(hide_code=True)
def _(mo):
    mo.md(
        """
        ## ๐Ÿงฎ Set Properties

        Important properties of sets:

        1. **Commutative**: A โˆช B = B โˆช A
        2. **Associative**: (A โˆช B) โˆช C = A โˆช (B โˆช C)
        3. **Distributive**: A โˆช (B โˆฉ C) = (A โˆช B) โˆฉ (A โˆช C)

        Let's verify these with a fun exercise!
        """
    )
    return


@app.cell
def _(mo, property_check, set_size):
    mo.hstack([property_check, set_size])
    return


@app.cell
def _(mo):
    # Interactive property verifier
    property_check = mo.ui.dropdown(
        options=[
            "Commutative (Union)",
            "Commutative (Intersection)",
            "Associative (Union)"
        ],
        value="Commutative (Union)",
        label="Select Property to Verify"
    )

    set_size = mo.ui.slider(
        value=3,
        start=2,
        stop=5,
        label="Set Size for Testing"
    )
    return property_check, set_size


@app.cell
def _(mo, property_check, set_size):
    import random

    # Create random emoji sets for verification
    emojis = ["๐Ÿ˜€", "๐Ÿ˜Ž", "๐Ÿค“", "๐Ÿค ", "๐Ÿ˜ด", "๐Ÿคฏ", "๐Ÿคช", "๐Ÿ˜‡"]

    set1 = set(random.sample(emojis, set_size.value))
    set2 = set(random.sample(emojis, set_size.value))

    operations = {
        "Commutative (Union)": (
            set1 | set2,
            set2 | set1,
            "A โˆช B = B โˆช A"
        ),
        "Commutative (Intersection)": (
            set1 & set2,
            set2 & set1,
            "A โˆฉ B = B โˆฉ A"
        ),
        "Associative (Union)": (
            (set1 | set2) | set(random.sample(emojis, set_size.value)),
            set1 | (set2 | set(random.sample(emojis, set_size.value))),
            "(A โˆช B) โˆช C = A โˆช (B โˆช C)"
        )
    }

    result1, result2, formula = operations[property_check.value]

    mo.md(f"""
    ### Property Verification

    **Testing**: {formula}

    Set A: {', '.join(set1)}
    Set B: {', '.join(set2)}

    **Left Side**: {', '.join(result1)}
    **Right Side**: {', '.join(result2)}

    **Property holds**: {'โœ…' if result1 == result2 else 'โŒ'}
    """)
    return emojis, formula, operations, random, result1, result2, set1, set2


@app.cell(hide_code=True)
def _(mo):
    quiz = mo.md("""
    ## ๐ŸŽฏ Quick Challenge

    Given these sets:

    - A = {๐ŸŽฎ, ๐Ÿ“ฑ, ๐Ÿ’ป}

    - B = {๐Ÿ“ฑ, ๐Ÿ’ป, ๐Ÿ–จ๏ธ}

    - C = {๐Ÿ’ป, ๐Ÿ–จ๏ธ, โŒจ๏ธ}

    Can you:

    1. Find all elements that are in either A or B

    2. Find elements common to all three sets

    3. Find elements in A that aren't in C

    <details>

    <summary>Check your answers!</summary>

    1. A โˆช B = {๐ŸŽฎ, ๐Ÿ“ฑ, ๐Ÿ’ป, ๐Ÿ–จ๏ธ}<br>
    2. A โˆฉ B โˆฉ C = {๐Ÿ’ป}<br>
    3. A - C = {๐ŸŽฎ, ๐Ÿ“ฑ}

    </details>
    """)

    mo.callout(quiz, kind="info")
    return (quiz,)


@app.cell(hide_code=True)
def _(mo):
    callout_text = mo.md("""
    ## ๐ŸŽฏ Set Theory Master in Training!

    You've learned:

    - Basic set operations

    - Set properties

    - Real-world applications

    Coming up next: Axiomatic Probability! ๐ŸŽฒโœจ

    Remember: In probability, every event is a set, and every set can be an event!
    """)

    mo.callout(callout_text, kind="success")
    return (callout_text,)


@app.cell
def _():
    import marimo as mo
    return (mo,)


if __name__ == "__main__":
    app.run()